tiny_mce_src.js 479 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769
  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.7',
  8. releaseDate : '2012-09-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;
  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. // Locate root span element and clone it since it would otherwise get merged by the "apple-style-span" on delete/backspace
  1048. if (blockElm) {
  1049. node = blockElm.firstChild;
  1050. // Ignore empty text nodes
  1051. while (node && node.nodeType == 3 && node.nodeValue.length === 0)
  1052. node = node.nextSibling;
  1053. if (node && node.nodeName === 'SPAN') {
  1054. clonedSpan = node.cloneNode(false);
  1055. }
  1056. }
  1057. // Do the backspace/delete action
  1058. editor.getDoc().execCommand(isDelete ? 'ForwardDelete' : 'Delete', false, null);
  1059. // Find all odd apple-style-spans
  1060. blockElm = dom.getParent(rng.startContainer, dom.isBlock);
  1061. tinymce.each(dom.select('span.Apple-style-span,font.Apple-style-span', blockElm), function(span) {
  1062. var bm = selection.getBookmark();
  1063. if (clonedSpan) {
  1064. dom.replace(clonedSpan.cloneNode(false), span, true);
  1065. } else {
  1066. dom.remove(span, true);
  1067. }
  1068. // Restore the selection
  1069. selection.moveToBookmark(bm);
  1070. });
  1071. };
  1072. editor.onKeyDown.add(function(editor, e) {
  1073. var isDelete;
  1074. isDelete = e.keyCode == DELETE;
  1075. if (!isDefaultPrevented(e) && (isDelete || e.keyCode == BACKSPACE) && !VK.modifierPressed(e)) {
  1076. e.preventDefault();
  1077. removeMergedFormatSpans(isDelete);
  1078. }
  1079. });
  1080. editor.addCommand('Delete', function() {removeMergedFormatSpans();});
  1081. };
  1082. function emptyEditorWhenDeleting() {
  1083. function serializeRng(rng) {
  1084. var body = dom.create("body");
  1085. var contents = rng.cloneContents();
  1086. body.appendChild(contents);
  1087. return selection.serializer.serialize(body, {format: 'html'});
  1088. }
  1089. function allContentsSelected(rng) {
  1090. var selection = serializeRng(rng);
  1091. var allRng = dom.createRng();
  1092. allRng.selectNode(editor.getBody());
  1093. var allSelection = serializeRng(allRng);
  1094. return selection === allSelection;
  1095. }
  1096. editor.onKeyDown.add(function(editor, e) {
  1097. var keyCode = e.keyCode, isCollapsed;
  1098. // Empty the editor if it's needed for example backspace at <p><b>|</b></p>
  1099. if (!isDefaultPrevented(e) && (keyCode == DELETE || keyCode == BACKSPACE)) {
  1100. isCollapsed = editor.selection.isCollapsed();
  1101. // Selection is collapsed but the editor isn't empty
  1102. if (isCollapsed && !dom.isEmpty(editor.getBody())) {
  1103. return;
  1104. }
  1105. // IE deletes all contents correctly when everything is selected
  1106. if (tinymce.isIE && !isCollapsed) {
  1107. return;
  1108. }
  1109. // Selection isn't collapsed but not all the contents is selected
  1110. if (!isCollapsed && !allContentsSelected(editor.selection.getRng())) {
  1111. return;
  1112. }
  1113. // Manually empty the editor
  1114. editor.setContent('');
  1115. editor.selection.setCursorLocation(editor.getBody(), 0);
  1116. editor.nodeChanged();
  1117. }
  1118. });
  1119. };
  1120. function selectAll() {
  1121. editor.onKeyDown.add(function(editor, e) {
  1122. if (!isDefaultPrevented(e) && e.keyCode == 65 && VK.metaKeyPressed(e)) {
  1123. e.preventDefault();
  1124. editor.execCommand('SelectAll');
  1125. }
  1126. });
  1127. };
  1128. function inputMethodFocus() {
  1129. if (!editor.settings.content_editable) {
  1130. // Case 1 IME doesn't initialize if you focus the document
  1131. dom.bind(editor.getDoc(), 'focusin', function(e) {
  1132. selection.setRng(selection.getRng());
  1133. });
  1134. // Case 2 IME doesn't initialize if you click the documentElement it also doesn't properly fire the focusin event
  1135. dom.bind(editor.getDoc(), 'mousedown', function(e) {
  1136. if (e.target == editor.getDoc().documentElement) {
  1137. editor.getWin().focus();
  1138. selection.setRng(selection.getRng());
  1139. }
  1140. });
  1141. }
  1142. };
  1143. function removeHrOnBackspace() {
  1144. editor.onKeyDown.add(function(editor, e) {
  1145. if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
  1146. if (selection.isCollapsed() && selection.getRng(true).startOffset === 0) {
  1147. var node = selection.getNode();
  1148. var previousSibling = node.previousSibling;
  1149. if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === "hr") {
  1150. dom.remove(previousSibling);
  1151. tinymce.dom.Event.cancel(e);
  1152. }
  1153. }
  1154. }
  1155. })
  1156. }
  1157. function focusBody() {
  1158. // Fix for a focus bug in FF 3.x where the body element
  1159. // wouldn't get proper focus if the user clicked on the HTML element
  1160. if (!Range.prototype.getClientRects) { // Detect getClientRects got introduced in FF 4
  1161. editor.onMouseDown.add(function(editor, e) {
  1162. if (!isDefaultPrevented(e) && e.target.nodeName === "HTML") {
  1163. var body = editor.getBody();
  1164. // Blur the body it's focused but not correctly focused
  1165. body.blur();
  1166. // Refocus the body after a little while
  1167. setTimeout(function() {
  1168. body.focus();
  1169. }, 0);
  1170. }
  1171. });
  1172. }
  1173. };
  1174. function selectControlElements() {
  1175. editor.onClick.add(function(editor, e) {
  1176. e = e.target;
  1177. // Workaround for bug, http://bugs.webkit.org/show_bug.cgi?id=12250
  1178. // WebKit can't even do simple things like selecting an image
  1179. // Needs tobe the setBaseAndExtend or it will fail to select floated images
  1180. if (/^(IMG|HR)$/.test(e.nodeName)) {
  1181. selection.getSel().setBaseAndExtent(e, 0, e, 1);
  1182. }
  1183. if (e.nodeName == 'A' && dom.hasClass(e, 'mceItemAnchor')) {
  1184. selection.select(e);
  1185. }
  1186. editor.nodeChanged();
  1187. });
  1188. };
  1189. function removeStylesWhenDeletingAccrossBlockElements() {
  1190. function getAttributeApplyFunction() {
  1191. var template = dom.getAttribs(selection.getStart().cloneNode(false));
  1192. return function() {
  1193. var target = selection.getStart();
  1194. if (target !== editor.getBody()) {
  1195. dom.setAttrib(target, "style", null);
  1196. tinymce.each(template, function(attr) {
  1197. target.setAttributeNode(attr.cloneNode(true));
  1198. });
  1199. }
  1200. };
  1201. }
  1202. function isSelectionAcrossElements() {
  1203. return !selection.isCollapsed() && dom.getParent(selection.getStart(), dom.isBlock) != dom.getParent(selection.getEnd(), dom.isBlock);
  1204. }
  1205. function blockEvent(editor, e) {
  1206. e.preventDefault();
  1207. return false;
  1208. }
  1209. editor.onKeyPress.add(function(editor, e) {
  1210. var applyAttributes;
  1211. if (!isDefaultPrevented(e) && (e.keyCode == 8 || e.keyCode == 46) && isSelectionAcrossElements()) {
  1212. applyAttributes = getAttributeApplyFunction();
  1213. editor.getDoc().execCommand('delete', false, null);
  1214. applyAttributes();
  1215. e.preventDefault();
  1216. return false;
  1217. }
  1218. });
  1219. dom.bind(editor.getDoc(), 'cut', function(e) {
  1220. var applyAttributes;
  1221. if (!isDefaultPrevented(e) && isSelectionAcrossElements()) {
  1222. applyAttributes = getAttributeApplyFunction();
  1223. editor.onKeyUp.addToTop(blockEvent);
  1224. setTimeout(function() {
  1225. applyAttributes();
  1226. editor.onKeyUp.remove(blockEvent);
  1227. }, 0);
  1228. }
  1229. });
  1230. }
  1231. function selectionChangeNodeChanged() {
  1232. var lastRng, selectionTimer;
  1233. dom.bind(editor.getDoc(), 'selectionchange', function() {
  1234. if (selectionTimer) {
  1235. clearTimeout(selectionTimer);
  1236. selectionTimer = 0;
  1237. }
  1238. selectionTimer = window.setTimeout(function() {
  1239. var rng = selection.getRng();
  1240. // Compare the ranges to see if it was a real change or not
  1241. if (!lastRng || !tinymce.dom.RangeUtils.compareRanges(rng, lastRng)) {
  1242. editor.nodeChanged();
  1243. lastRng = rng;
  1244. }
  1245. }, 50);
  1246. });
  1247. }
  1248. function ensureBodyHasRoleApplication() {
  1249. document.body.setAttribute("role", "application");
  1250. }
  1251. function disableBackspaceIntoATable() {
  1252. editor.onKeyDown.add(function(editor, e) {
  1253. if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
  1254. if (selection.isCollapsed() && selection.getRng(true).startOffset === 0) {
  1255. var previousSibling = selection.getNode().previousSibling;
  1256. if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === "table") {
  1257. return tinymce.dom.Event.cancel(e);
  1258. }
  1259. }
  1260. }
  1261. })
  1262. }
  1263. function addNewLinesBeforeBrInPre() {
  1264. // IE8+ rendering mode does the right thing with BR in PRE
  1265. if (getDocumentMode() > 7) {
  1266. return;
  1267. }
  1268. // Enable display: none in area and add a specific class that hides all BR elements in PRE to
  1269. // avoid the caret from getting stuck at the BR elements while pressing the right arrow key
  1270. setEditorCommandState('RespectVisibilityInDesign', true);
  1271. editor.contentStyles.push('.mceHideBrInPre pre br {display: none}');
  1272. dom.addClass(editor.getBody(), 'mceHideBrInPre');
  1273. // Adds a \n before all BR elements in PRE to get them visual
  1274. parser.addNodeFilter('pre', function(nodes, name) {
  1275. var i = nodes.length, brNodes, j, brElm, sibling;
  1276. while (i--) {
  1277. brNodes = nodes[i].getAll('br');
  1278. j = brNodes.length;
  1279. while (j--) {
  1280. brElm = brNodes[j];
  1281. // Add \n before BR in PRE elements on older IE:s so the new lines get rendered
  1282. sibling = brElm.prev;
  1283. if (sibling && sibling.type === 3 && sibling.value.charAt(sibling.value - 1) != '\n') {
  1284. sibling.value += '\n';
  1285. } else {
  1286. brElm.parent.insert(new tinymce.html.Node('#text', 3), brElm, true).value = '\n';
  1287. }
  1288. }
  1289. }
  1290. });
  1291. // Removes any \n before BR elements in PRE since other browsers and in contentEditable=false mode they will be visible
  1292. serializer.addNodeFilter('pre', function(nodes, name) {
  1293. var i = nodes.length, brNodes, j, brElm, sibling;
  1294. while (i--) {
  1295. brNodes = nodes[i].getAll('br');
  1296. j = brNodes.length;
  1297. while (j--) {
  1298. brElm = brNodes[j];
  1299. sibling = brElm.prev;
  1300. if (sibling && sibling.type == 3) {
  1301. sibling.value = sibling.value.replace(/\r?\n$/, '');
  1302. }
  1303. }
  1304. }
  1305. });
  1306. }
  1307. function removePreSerializedStylesWhenSelectingControls() {
  1308. dom.bind(editor.getBody(), 'mouseup', function(e) {
  1309. var value, node = selection.getNode();
  1310. // Moved styles to attributes on IMG eements
  1311. if (node.nodeName == 'IMG') {
  1312. // Convert style width to width attribute
  1313. if (value = dom.getStyle(node, 'width')) {
  1314. dom.setAttrib(node, 'width', value.replace(/[^0-9%]+/g, ''));
  1315. dom.setStyle(node, 'width', '');
  1316. }
  1317. // Convert style height to height attribute
  1318. if (value = dom.getStyle(node, 'height')) {
  1319. dom.setAttrib(node, 'height', value.replace(/[^0-9%]+/g, ''));
  1320. dom.setStyle(node, 'height', '');
  1321. }
  1322. }
  1323. });
  1324. }
  1325. function keepInlineElementOnDeleteBackspace() {
  1326. editor.onKeyDown.add(function(editor, e) {
  1327. var isDelete, rng, container, offset, brElm, sibling, collapsed;
  1328. isDelete = e.keyCode == DELETE;
  1329. if (!isDefaultPrevented(e) && (isDelete || e.keyCode == BACKSPACE) && !VK.modifierPressed(e)) {
  1330. rng = selection.getRng();
  1331. container = rng.startContainer;
  1332. offset = rng.startOffset;
  1333. collapsed = rng.collapsed;
  1334. // Override delete if the start container is a text node and is at the beginning of text or
  1335. // just before/after the last character to be deleted in collapsed mode
  1336. if (container.nodeType == 3 && container.nodeValue.length > 0 && ((offset === 0 && !collapsed) || (collapsed && offset === (isDelete ? 0 : 1)))) {
  1337. nonEmptyElements = editor.schema.getNonEmptyElements();
  1338. // Prevent default logic since it's broken
  1339. e.preventDefault();
  1340. // Insert a BR before the text node this will prevent the containing element from being deleted/converted
  1341. brElm = dom.create('br', {id: '__tmp'});
  1342. container.parentNode.insertBefore(brElm, container);
  1343. // Do the browser delete
  1344. editor.getDoc().execCommand(isDelete ? 'ForwardDelete' : 'Delete', false, null);
  1345. // Check if the previous sibling is empty after deleting for example: <p><b></b>|</p>
  1346. container = selection.getRng().startContainer;
  1347. sibling = container.previousSibling;
  1348. if (sibling && sibling.nodeType == 1 && !dom.isBlock(sibling) && dom.isEmpty(sibling) && !nonEmptyElements[sibling.nodeName.toLowerCase()]) {
  1349. dom.remove(sibling);
  1350. }
  1351. // Remove the temp element we inserted
  1352. dom.remove('__tmp');
  1353. }
  1354. }
  1355. });
  1356. }
  1357. function removeBlockQuoteOnBackSpace() {
  1358. // Add block quote deletion handler
  1359. editor.onKeyDown.add(function(editor, e) {
  1360. var rng, container, offset, root, parent;
  1361. if (isDefaultPrevented(e) || e.keyCode != VK.BACKSPACE) {
  1362. return;
  1363. }
  1364. rng = selection.getRng();
  1365. container = rng.startContainer;
  1366. offset = rng.startOffset;
  1367. root = dom.getRoot();
  1368. parent = container;
  1369. if (!rng.collapsed || offset !== 0) {
  1370. return;
  1371. }
  1372. while (parent && parent.parentNode && parent.parentNode.firstChild == parent && parent.parentNode != root) {
  1373. parent = parent.parentNode;
  1374. }
  1375. // Is the cursor at the beginning of a blockquote?
  1376. if (parent.tagName === 'BLOCKQUOTE') {
  1377. // Remove the blockquote
  1378. editor.formatter.toggle('blockquote', null, parent);
  1379. // Move the caret to the beginning of container
  1380. rng = dom.createRng();
  1381. rng.setStart(container, 0);
  1382. rng.setEnd(container, 0);
  1383. selection.setRng(rng);
  1384. }
  1385. });
  1386. };
  1387. function setGeckoEditingOptions() {
  1388. function setOpts() {
  1389. editor._refreshContentEditable();
  1390. setEditorCommandState("StyleWithCSS", false);
  1391. setEditorCommandState("enableInlineTableEditing", false);
  1392. if (!settings.object_resizing) {
  1393. setEditorCommandState("enableObjectResizing", false);
  1394. }
  1395. };
  1396. if (!settings.readonly) {
  1397. editor.onBeforeExecCommand.add(setOpts);
  1398. editor.onMouseDown.add(setOpts);
  1399. }
  1400. };
  1401. function addBrAfterLastLinks() {
  1402. function fixLinks(editor, o) {
  1403. tinymce.each(dom.select('a'), function(node) {
  1404. var parentNode = node.parentNode, root = dom.getRoot();
  1405. if (parentNode.lastChild === node) {
  1406. while (parentNode && !dom.isBlock(parentNode)) {
  1407. if (parentNode.parentNode.lastChild !== parentNode || parentNode === root) {
  1408. return;
  1409. }
  1410. parentNode = parentNode.parentNode;
  1411. }
  1412. dom.add(parentNode, 'br', {'data-mce-bogus' : 1});
  1413. }
  1414. });
  1415. };
  1416. editor.onExecCommand.add(function(editor, cmd) {
  1417. if (cmd === 'CreateLink') {
  1418. fixLinks(editor);
  1419. }
  1420. });
  1421. editor.onSetContent.add(selection.onSetContent.add(fixLinks));
  1422. };
  1423. function setDefaultBlockType() {
  1424. if (settings.forced_root_block) {
  1425. editor.onInit.add(function() {
  1426. setEditorCommandState('DefaultParagraphSeparator', settings.forced_root_block);
  1427. });
  1428. }
  1429. }
  1430. function removeGhostSelection() {
  1431. function repaint(sender, args) {
  1432. if (!sender || !args.initial) {
  1433. editor.execCommand('mceRepaint');
  1434. }
  1435. };
  1436. editor.onUndo.add(repaint);
  1437. editor.onRedo.add(repaint);
  1438. editor.onSetContent.add(repaint);
  1439. };
  1440. function deleteControlItemOnBackSpace() {
  1441. editor.onKeyDown.add(function(editor, e) {
  1442. var rng;
  1443. if (!isDefaultPrevented(e) && e.keyCode == BACKSPACE) {
  1444. rng = editor.getDoc().selection.createRange();
  1445. if (rng && rng.item) {
  1446. e.preventDefault();
  1447. editor.undoManager.beforeChange();
  1448. dom.remove(rng.item(0));
  1449. editor.undoManager.add();
  1450. }
  1451. }
  1452. });
  1453. };
  1454. function renderEmptyBlocksFix() {
  1455. var emptyBlocksCSS;
  1456. // IE10+
  1457. if (getDocumentMode() >= 10) {
  1458. emptyBlocksCSS = '';
  1459. tinymce.each('p div h1 h2 h3 h4 h5 h6'.split(' '), function(name, i) {
  1460. emptyBlocksCSS += (i > 0 ? ',' : '') + name + ':empty';
  1461. });
  1462. editor.contentStyles.push(emptyBlocksCSS + '{padding-right: 1px !important}');
  1463. }
  1464. };
  1465. function fakeImageResize() {
  1466. var selectedElmX, selectedElmY, selectedElm, selectedElmGhost, selectedHandle, startX, startY, startW, startH, ratio,
  1467. resizeHandles, width, height, rootDocument = document, editableDoc = editor.getDoc();
  1468. if (!settings.object_resizing || settings.webkit_fake_resize === false) {
  1469. return;
  1470. }
  1471. // Try disabling object resizing if WebKit implements resizing in the future
  1472. setEditorCommandState("enableObjectResizing", false);
  1473. // Details about each resize handle how to scale etc
  1474. resizeHandles = {
  1475. // Name: x multiplier, y multiplier, delta size x, delta size y
  1476. n: [.5, 0, 0, -1],
  1477. e: [1, .5, 1, 0],
  1478. s: [.5, 1, 0, 1],
  1479. w: [0, .5, -1, 0],
  1480. nw: [0, 0, -1, -1],
  1481. ne: [1, 0, 1, -1],
  1482. se: [1, 1, 1, 1],
  1483. sw : [0, 1, -1, 1]
  1484. };
  1485. function resizeElement(e) {
  1486. var deltaX, deltaY;
  1487. // Calc new width/height
  1488. deltaX = e.screenX - startX;
  1489. deltaY = e.screenY - startY;
  1490. // Calc new size
  1491. width = deltaX * selectedHandle[2] + startW;
  1492. height = deltaY * selectedHandle[3] + startH;
  1493. // Never scale down lower than 5 pixels
  1494. width = width < 5 ? 5 : width;
  1495. height = height < 5 ? 5 : height;
  1496. // Constrain proportions when modifier key is pressed or if the nw, ne, sw, se corners are moved on an image
  1497. if (VK.modifierPressed(e) || (selectedElm.nodeName == "IMG" && selectedHandle[2] * selectedHandle[3] !== 0)) {
  1498. width = Math.round(height / ratio);
  1499. height = Math.round(width * ratio);
  1500. }
  1501. // Update ghost size
  1502. dom.setStyles(selectedElmGhost, {
  1503. width: width,
  1504. height: height
  1505. });
  1506. // Update ghost X position if needed
  1507. if (selectedHandle[2] < 0 && selectedElmGhost.clientWidth <= width) {
  1508. dom.setStyle(selectedElmGhost, 'left', selectedElmX + (startW - width));
  1509. }
  1510. // Update ghost Y position if needed
  1511. if (selectedHandle[3] < 0 && selectedElmGhost.clientHeight <= height) {
  1512. dom.setStyle(selectedElmGhost, 'top', selectedElmY + (startH - height));
  1513. }
  1514. }
  1515. function endResize() {
  1516. function setSizeProp(name, value) {
  1517. if (value) {
  1518. // Resize by using style or attribute
  1519. if (selectedElm.style[name] || !editor.schema.isValid(selectedElm.nodeName.toLowerCase(), name)) {
  1520. dom.setStyle(selectedElm, name, value);
  1521. } else {
  1522. dom.setAttrib(selectedElm, name, value);
  1523. }
  1524. }
  1525. }
  1526. // Set width/height properties
  1527. setSizeProp('width', width);
  1528. setSizeProp('height', height);
  1529. dom.unbind(editableDoc, 'mousemove', resizeElement);
  1530. dom.unbind(editableDoc, 'mouseup', endResize);
  1531. if (rootDocument != editableDoc) {
  1532. dom.unbind(rootDocument, 'mousemove', resizeElement);
  1533. dom.unbind(rootDocument, 'mouseup', endResize);
  1534. }
  1535. // Remove ghost and update resize handle positions
  1536. dom.remove(selectedElmGhost);
  1537. showResizeRect(selectedElm);
  1538. }
  1539. function showResizeRect(targetElm) {
  1540. var position, targetWidth, targetHeight;
  1541. hideResizeRect();
  1542. // Get position and size of target
  1543. position = dom.getPos(targetElm);
  1544. selectedElmX = position.x;
  1545. selectedElmY = position.y;
  1546. targetWidth = targetElm.offsetWidth;
  1547. targetHeight = targetElm.offsetHeight;
  1548. // Reset width/height if user selects a new image/table
  1549. if (selectedElm != targetElm) {
  1550. selectedElm = targetElm;
  1551. width = height = 0;
  1552. }
  1553. tinymce.each(resizeHandles, function(handle, name) {
  1554. var handleElm;
  1555. // Get existing or render resize handle
  1556. handleElm = dom.get('mceResizeHandle' + name);
  1557. if (!handleElm) {
  1558. handleElm = dom.add(editableDoc.documentElement, 'div', {
  1559. id: 'mceResizeHandle' + name,
  1560. 'class': 'mceResizeHandle',
  1561. style: 'cursor:' + name + '-resize; margin:0; padding:0'
  1562. });
  1563. dom.bind(handleElm, 'mousedown', function(e) {
  1564. e.preventDefault();
  1565. endResize();
  1566. startX = e.screenX;
  1567. startY = e.screenY;
  1568. startW = selectedElm.clientWidth;
  1569. startH = selectedElm.clientHeight;
  1570. ratio = startH / startW;
  1571. selectedHandle = handle;
  1572. selectedElmGhost = selectedElm.cloneNode(true);
  1573. dom.addClass(selectedElmGhost, 'mceClonedResizable');
  1574. dom.setStyles(selectedElmGhost, {
  1575. left: selectedElmX,
  1576. top: selectedElmY,
  1577. margin: 0
  1578. });
  1579. editableDoc.documentElement.appendChild(selectedElmGhost);
  1580. dom.bind(editableDoc, 'mousemove', resizeElement);
  1581. dom.bind(editableDoc, 'mouseup', endResize);
  1582. if (rootDocument != editableDoc) {
  1583. dom.bind(rootDocument, 'mousemove', resizeElement);
  1584. dom.bind(rootDocument, 'mouseup', endResize);
  1585. }
  1586. });
  1587. } else {
  1588. dom.show(handleElm);
  1589. }
  1590. // Position element
  1591. dom.setStyles(handleElm, {
  1592. left: (targetWidth * handle[0] + selectedElmX) - (handleElm.offsetWidth / 2),
  1593. top: (targetHeight * handle[1] + selectedElmY) - (handleElm.offsetHeight / 2)
  1594. });
  1595. });
  1596. // Only add resize rectangle on WebKit and only on images
  1597. if (!tinymce.isOpera && selectedElm.nodeName == "IMG") {
  1598. selectedElm.setAttribute('data-mce-selected', '1');
  1599. }
  1600. }
  1601. function hideResizeRect() {
  1602. if (selectedElm) {
  1603. selectedElm.removeAttribute('data-mce-selected');
  1604. }
  1605. for (var name in resizeHandles) {
  1606. dom.hide('mceResizeHandle' + name);
  1607. }
  1608. }
  1609. // Add CSS for resize handles, cloned element and selected
  1610. editor.contentStyles.push(
  1611. '.mceResizeHandle {' +
  1612. 'position: absolute;' +
  1613. 'border: 1px solid black;' +
  1614. 'background: #FFF;' +
  1615. 'width: 5px;' +
  1616. 'height: 5px;' +
  1617. 'z-index: 10000' +
  1618. '}' +
  1619. '.mceResizeHandle:hover {' +
  1620. 'background: #000' +
  1621. '}' +
  1622. 'img[data-mce-selected] {' +
  1623. 'outline: 1px solid black' +
  1624. '}' +
  1625. 'img.mceClonedResizable, table.mceClonedResizable {' +
  1626. 'position: absolute;' +
  1627. 'outline: 1px dashed black;' +
  1628. 'opacity: .5;' +
  1629. 'z-index: 10000' +
  1630. '}'
  1631. );
  1632. function updateResizeRect() {
  1633. var controlElm = dom.getParent(selection.getNode(), 'table,img');
  1634. // Remove data-mce-selected from all elements since they might have been copied using Ctrl+c/v
  1635. tinymce.each(dom.select('img[data-mce-selected]'), function(img) {
  1636. img.removeAttribute('data-mce-selected');
  1637. });
  1638. if (controlElm) {
  1639. showResizeRect(controlElm);
  1640. } else {
  1641. hideResizeRect();
  1642. }
  1643. }
  1644. // Show/hide resize rect when image is selected
  1645. editor.onNodeChange.add(updateResizeRect);
  1646. // Fixes WebKit quirk where it returns IMG on getNode if caret is after last image in container
  1647. dom.bind(editableDoc, 'selectionchange', updateResizeRect);
  1648. // Remove the internal attribute when serializing the DOM
  1649. editor.serializer.addAttributeFilter('data-mce-selected', function(nodes, name) {
  1650. var i = nodes.length;
  1651. while (i--) {
  1652. nodes[i].attr(name, null);
  1653. }
  1654. });
  1655. }
  1656. function keepNoScriptContents() {
  1657. if (getDocumentMode() < 9) {
  1658. parser.addNodeFilter('noscript', function(nodes) {
  1659. var i = nodes.length, node, textNode;
  1660. while (i--) {
  1661. node = nodes[i];
  1662. textNode = node.firstChild;
  1663. if (textNode) {
  1664. node.attr('data-mce-innertext', textNode.value);
  1665. }
  1666. }
  1667. });
  1668. serializer.addNodeFilter('noscript', function(nodes) {
  1669. var i = nodes.length, node, textNode, value;
  1670. while (i--) {
  1671. node = nodes[i];
  1672. textNode = nodes[i].firstChild;
  1673. if (textNode) {
  1674. textNode.value = tinymce.html.Entities.decode(textNode.value);
  1675. } else {
  1676. // Old IE can't retain noscript value so an attribute is used to store it
  1677. value = node.attributes.map['data-mce-innertext'];
  1678. if (value) {
  1679. node.attr('data-mce-innertext', null);
  1680. textNode = new tinymce.html.Node('#text', 3);
  1681. textNode.value = value;
  1682. textNode.raw = true;
  1683. node.append(textNode);
  1684. }
  1685. }
  1686. }
  1687. });
  1688. }
  1689. }
  1690. // All browsers
  1691. disableBackspaceIntoATable();
  1692. removeBlockQuoteOnBackSpace();
  1693. emptyEditorWhenDeleting();
  1694. // WebKit
  1695. if (tinymce.isWebKit) {
  1696. keepInlineElementOnDeleteBackspace();
  1697. cleanupStylesWhenDeleting();
  1698. inputMethodFocus();
  1699. selectControlElements();
  1700. setDefaultBlockType();
  1701. // iOS
  1702. if (tinymce.isIDevice) {
  1703. selectionChangeNodeChanged();
  1704. } else {
  1705. fakeImageResize();
  1706. selectAll();
  1707. }
  1708. }
  1709. // IE
  1710. if (tinymce.isIE) {
  1711. removeHrOnBackspace();
  1712. ensureBodyHasRoleApplication();
  1713. addNewLinesBeforeBrInPre();
  1714. removePreSerializedStylesWhenSelectingControls();
  1715. deleteControlItemOnBackSpace();
  1716. renderEmptyBlocksFix();
  1717. keepNoScriptContents();
  1718. }
  1719. // Gecko
  1720. if (tinymce.isGecko) {
  1721. removeHrOnBackspace();
  1722. focusBody();
  1723. removeStylesWhenDeletingAccrossBlockElements();
  1724. setGeckoEditingOptions();
  1725. addBrAfterLastLinks();
  1726. removeGhostSelection();
  1727. }
  1728. // Opera
  1729. if (tinymce.isOpera) {
  1730. fakeImageResize();
  1731. }
  1732. };
  1733. (function(tinymce) {
  1734. var namedEntities, baseEntities, reverseEntities,
  1735. attrsCharsRegExp = /[&<>\"\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  1736. textCharsRegExp = /[<>&\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  1737. rawCharsRegExp = /[<>&\"\']/g,
  1738. entityRegExp = /&(#x|#)?([\w]+);/g,
  1739. asciiMap = {
  1740. 128 : "\u20AC", 130 : "\u201A", 131 : "\u0192", 132 : "\u201E", 133 : "\u2026", 134 : "\u2020",
  1741. 135 : "\u2021", 136 : "\u02C6", 137 : "\u2030", 138 : "\u0160", 139 : "\u2039", 140 : "\u0152",
  1742. 142 : "\u017D", 145 : "\u2018", 146 : "\u2019", 147 : "\u201C", 148 : "\u201D", 149 : "\u2022",
  1743. 150 : "\u2013", 151 : "\u2014", 152 : "\u02DC", 153 : "\u2122", 154 : "\u0161", 155 : "\u203A",
  1744. 156 : "\u0153", 158 : "\u017E", 159 : "\u0178"
  1745. };
  1746. // Raw entities
  1747. baseEntities = {
  1748. '\"' : '&quot;', // Needs to be escaped since the YUI compressor would otherwise break the code
  1749. "'" : '&#39;',
  1750. '<' : '&lt;',
  1751. '>' : '&gt;',
  1752. '&' : '&amp;'
  1753. };
  1754. // Reverse lookup table for raw entities
  1755. reverseEntities = {
  1756. '&lt;' : '<',
  1757. '&gt;' : '>',
  1758. '&amp;' : '&',
  1759. '&quot;' : '"',
  1760. '&apos;' : "'"
  1761. };
  1762. // Decodes text by using the browser
  1763. function nativeDecode(text) {
  1764. var elm;
  1765. elm = document.createElement("div");
  1766. elm.innerHTML = text;
  1767. return elm.textContent || elm.innerText || text;
  1768. };
  1769. // Build a two way lookup table for the entities
  1770. function buildEntitiesLookup(items, radix) {
  1771. var i, chr, entity, lookup = {};
  1772. if (items) {
  1773. items = items.split(',');
  1774. radix = radix || 10;
  1775. // Build entities lookup table
  1776. for (i = 0; i < items.length; i += 2) {
  1777. chr = String.fromCharCode(parseInt(items[i], radix));
  1778. // Only add non base entities
  1779. if (!baseEntities[chr]) {
  1780. entity = '&' + items[i + 1] + ';';
  1781. lookup[chr] = entity;
  1782. lookup[entity] = chr;
  1783. }
  1784. }
  1785. return lookup;
  1786. }
  1787. };
  1788. // Unpack entities lookup where the numbers are in radix 32 to reduce the size
  1789. namedEntities = buildEntitiesLookup(
  1790. '50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,' +
  1791. '5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,' +
  1792. '5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,' +
  1793. '5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,' +
  1794. '68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,' +
  1795. '6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,' +
  1796. '6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,' +
  1797. '75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,' +
  1798. '7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,' +
  1799. '7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,' +
  1800. 'sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,' +
  1801. 'st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,' +
  1802. 't9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,' +
  1803. 'tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,' +
  1804. 'u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,' +
  1805. '81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,' +
  1806. '8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,' +
  1807. '8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,' +
  1808. '8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,' +
  1809. '8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,' +
  1810. 'nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,' +
  1811. 'rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,' +
  1812. 'Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,' +
  1813. '80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,' +
  1814. '811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro', 32);
  1815. tinymce.html = tinymce.html || {};
  1816. tinymce.html.Entities = {
  1817. encodeRaw : function(text, attr) {
  1818. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1819. return baseEntities[chr] || chr;
  1820. });
  1821. },
  1822. encodeAllRaw : function(text) {
  1823. return ('' + text).replace(rawCharsRegExp, function(chr) {
  1824. return baseEntities[chr] || chr;
  1825. });
  1826. },
  1827. encodeNumeric : function(text, attr) {
  1828. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1829. // Multi byte sequence convert it to a single entity
  1830. if (chr.length > 1)
  1831. return '&#' + (((chr.charCodeAt(0) - 0xD800) * 0x400) + (chr.charCodeAt(1) - 0xDC00) + 0x10000) + ';';
  1832. return baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';';
  1833. });
  1834. },
  1835. encodeNamed : function(text, attr, entities) {
  1836. entities = entities || namedEntities;
  1837. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1838. return baseEntities[chr] || entities[chr] || chr;
  1839. });
  1840. },
  1841. getEncodeFunc : function(name, entities) {
  1842. var Entities = tinymce.html.Entities;
  1843. entities = buildEntitiesLookup(entities) || namedEntities;
  1844. function encodeNamedAndNumeric(text, attr) {
  1845. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1846. return baseEntities[chr] || entities[chr] || '&#' + chr.charCodeAt(0) + ';' || chr;
  1847. });
  1848. };
  1849. function encodeCustomNamed(text, attr) {
  1850. return Entities.encodeNamed(text, attr, entities);
  1851. };
  1852. // Replace + with , to be compatible with previous TinyMCE versions
  1853. name = tinymce.makeMap(name.replace(/\+/g, ','));
  1854. // Named and numeric encoder
  1855. if (name.named && name.numeric)
  1856. return encodeNamedAndNumeric;
  1857. // Named encoder
  1858. if (name.named) {
  1859. // Custom names
  1860. if (entities)
  1861. return encodeCustomNamed;
  1862. return Entities.encodeNamed;
  1863. }
  1864. // Numeric
  1865. if (name.numeric)
  1866. return Entities.encodeNumeric;
  1867. // Raw encoder
  1868. return Entities.encodeRaw;
  1869. },
  1870. decode : function(text) {
  1871. return text.replace(entityRegExp, function(all, numeric, value) {
  1872. if (numeric) {
  1873. value = parseInt(value, numeric.length === 2 ? 16 : 10);
  1874. // Support upper UTF
  1875. if (value > 0xFFFF) {
  1876. value -= 0x10000;
  1877. return String.fromCharCode(0xD800 + (value >> 10), 0xDC00 + (value & 0x3FF));
  1878. } else
  1879. return asciiMap[value] || String.fromCharCode(value);
  1880. }
  1881. return reverseEntities[all] || namedEntities[all] || nativeDecode(all);
  1882. });
  1883. }
  1884. };
  1885. })(tinymce);
  1886. tinymce.html.Styles = function(settings, schema) {
  1887. var rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi,
  1888. urlOrStrRegExp = /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi,
  1889. styleRegExp = /\s*([^:]+):\s*([^;]+);?/g,
  1890. trimRightRegExp = /\s+$/,
  1891. urlColorRegExp = /rgb/,
  1892. undef, i, encodingLookup = {}, encodingItems;
  1893. settings = settings || {};
  1894. encodingItems = '\\" \\\' \\; \\: ; : \uFEFF'.split(' ');
  1895. for (i = 0; i < encodingItems.length; i++) {
  1896. encodingLookup[encodingItems[i]] = '\uFEFF' + i;
  1897. encodingLookup['\uFEFF' + i] = encodingItems[i];
  1898. }
  1899. function toHex(match, r, g, b) {
  1900. function hex(val) {
  1901. val = parseInt(val).toString(16);
  1902. return val.length > 1 ? val : '0' + val; // 0 -> 00
  1903. };
  1904. return '#' + hex(r) + hex(g) + hex(b);
  1905. };
  1906. return {
  1907. toHex : function(color) {
  1908. return color.replace(rgbRegExp, toHex);
  1909. },
  1910. parse : function(css) {
  1911. var styles = {}, matches, name, value, isEncoded, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope || this;
  1912. function compress(prefix, suffix) {
  1913. var top, right, bottom, left;
  1914. // Get values and check it it needs compressing
  1915. top = styles[prefix + '-top' + suffix];
  1916. if (!top)
  1917. return;
  1918. right = styles[prefix + '-right' + suffix];
  1919. if (top != right)
  1920. return;
  1921. bottom = styles[prefix + '-bottom' + suffix];
  1922. if (right != bottom)
  1923. return;
  1924. left = styles[prefix + '-left' + suffix];
  1925. if (bottom != left)
  1926. return;
  1927. // Compress
  1928. styles[prefix + suffix] = left;
  1929. delete styles[prefix + '-top' + suffix];
  1930. delete styles[prefix + '-right' + suffix];
  1931. delete styles[prefix + '-bottom' + suffix];
  1932. delete styles[prefix + '-left' + suffix];
  1933. };
  1934. function canCompress(key) {
  1935. var value = styles[key], i;
  1936. if (!value || value.indexOf(' ') < 0)
  1937. return;
  1938. value = value.split(' ');
  1939. i = value.length;
  1940. while (i--) {
  1941. if (value[i] !== value[0])
  1942. return false;
  1943. }
  1944. styles[key] = value[0];
  1945. return true;
  1946. };
  1947. function compress2(target, a, b, c) {
  1948. if (!canCompress(a))
  1949. return;
  1950. if (!canCompress(b))
  1951. return;
  1952. if (!canCompress(c))
  1953. return;
  1954. // Compress
  1955. styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c];
  1956. delete styles[a];
  1957. delete styles[b];
  1958. delete styles[c];
  1959. };
  1960. // Encodes the specified string by replacing all \" \' ; : with _<num>
  1961. function encode(str) {
  1962. isEncoded = true;
  1963. return encodingLookup[str];
  1964. };
  1965. // Decodes the specified string by replacing all _<num> with it's original value \" \' etc
  1966. // It will also decode the \" \' if keep_slashes is set to fale or omitted
  1967. function decode(str, keep_slashes) {
  1968. if (isEncoded) {
  1969. str = str.replace(/\uFEFF[0-9]/g, function(str) {
  1970. return encodingLookup[str];
  1971. });
  1972. }
  1973. if (!keep_slashes)
  1974. str = str.replace(/\\([\'\";:])/g, "$1");
  1975. return str;
  1976. };
  1977. function processUrl(match, url, url2, url3, str, str2) {
  1978. str = str || str2;
  1979. if (str) {
  1980. str = decode(str);
  1981. // Force strings into single quote format
  1982. return "'" + str.replace(/\'/g, "\\'") + "'";
  1983. }
  1984. url = decode(url || url2 || url3);
  1985. // Convert the URL to relative/absolute depending on config
  1986. if (urlConverter)
  1987. url = urlConverter.call(urlConverterScope, url, 'style');
  1988. // Output new URL format
  1989. return "url('" + url.replace(/\'/g, "\\'") + "')";
  1990. };
  1991. if (css) {
  1992. // Encode \" \' % and ; and : inside strings so they don't interfere with the style parsing
  1993. css = css.replace(/\\[\"\';:\uFEFF]/g, encode).replace(/\"[^\"]+\"|\'[^\']+\'/g, function(str) {
  1994. return str.replace(/[;:]/g, encode);
  1995. });
  1996. // Parse styles
  1997. while (matches = styleRegExp.exec(css)) {
  1998. name = matches[1].replace(trimRightRegExp, '').toLowerCase();
  1999. value = matches[2].replace(trimRightRegExp, '');
  2000. if (name && value.length > 0) {
  2001. // Opera will produce 700 instead of bold in their style values
  2002. if (name === 'font-weight' && value === '700')
  2003. value = 'bold';
  2004. else if (name === 'color' || name === 'background-color') // Lowercase colors like RED
  2005. value = value.toLowerCase();
  2006. // Convert RGB colors to HEX
  2007. value = value.replace(rgbRegExp, toHex);
  2008. // Convert URLs and force them into url('value') format
  2009. value = value.replace(urlOrStrRegExp, processUrl);
  2010. styles[name] = isEncoded ? decode(value, true) : value;
  2011. }
  2012. styleRegExp.lastIndex = matches.index + matches[0].length;
  2013. }
  2014. // Compress the styles to reduce it's size for example IE will expand styles
  2015. compress("border", "");
  2016. compress("border", "-width");
  2017. compress("border", "-color");
  2018. compress("border", "-style");
  2019. compress("padding", "");
  2020. compress("margin", "");
  2021. compress2('border', 'border-width', 'border-style', 'border-color');
  2022. // Remove pointless border, IE produces these
  2023. if (styles.border === 'medium none')
  2024. delete styles.border;
  2025. }
  2026. return styles;
  2027. },
  2028. serialize : function(styles, element_name) {
  2029. var css = '', name, value;
  2030. function serializeStyles(name) {
  2031. var styleList, i, l, value;
  2032. styleList = schema.styles[name];
  2033. if (styleList) {
  2034. for (i = 0, l = styleList.length; i < l; i++) {
  2035. name = styleList[i];
  2036. value = styles[name];
  2037. if (value !== undef && value.length > 0)
  2038. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  2039. }
  2040. }
  2041. };
  2042. // Serialize styles according to schema
  2043. if (element_name && schema && schema.styles) {
  2044. // Serialize global styles and element specific styles
  2045. serializeStyles('*');
  2046. serializeStyles(element_name);
  2047. } else {
  2048. // Output the styles in the order they are inside the object
  2049. for (name in styles) {
  2050. value = styles[name];
  2051. if (value !== undef && value.length > 0)
  2052. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  2053. }
  2054. }
  2055. return css;
  2056. }
  2057. };
  2058. };
  2059. (function(tinymce) {
  2060. var mapCache = {}, makeMap = tinymce.makeMap, each = tinymce.each;
  2061. function split(str, delim) {
  2062. return str.split(delim || ',');
  2063. };
  2064. function unpack(lookup, data) {
  2065. var key, elements = {};
  2066. function replace(value) {
  2067. return value.replace(/[A-Z]+/g, function(key) {
  2068. return replace(lookup[key]);
  2069. });
  2070. };
  2071. // Unpack lookup
  2072. for (key in lookup) {
  2073. if (lookup.hasOwnProperty(key))
  2074. lookup[key] = replace(lookup[key]);
  2075. }
  2076. // Unpack and parse data into object map
  2077. replace(data).replace(/#/g, '#text').replace(/(\w+)\[([^\]]+)\]\[([^\]]*)\]/g, function(str, name, attributes, children) {
  2078. attributes = split(attributes, '|');
  2079. elements[name] = {
  2080. attributes : makeMap(attributes),
  2081. attributesOrder : attributes,
  2082. children : makeMap(children, '|', {'#comment' : {}})
  2083. }
  2084. });
  2085. return elements;
  2086. };
  2087. function getHTML5() {
  2088. var html5 = mapCache.html5;
  2089. if (!html5) {
  2090. html5 = mapCache.html5 = unpack({
  2091. A : 'id|accesskey|class|dir|draggable|item|hidden|itemprop|role|spellcheck|style|subject|title|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup',
  2092. 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|' +
  2093. 'meter|noscript|object|output|progress|q|ruby|samp|script|select|small|span|strong|sub|sup|svg|textarea|time|var|video|wbr',
  2094. 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|' +
  2095. '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|' +
  2096. 'p|pre|progress|q|ruby|samp|script|section|select|small|span|strong|style|sub|sup|svg|table|textarea|time|ul|var|video'
  2097. }, 'html[A|manifest][body|head]' +
  2098. 'head[A][base|command|link|meta|noscript|script|style|title]' +
  2099. 'title[A][#]' +
  2100. 'base[A|href|target][]' +
  2101. 'link[A|href|rel|media|type|sizes][]' +
  2102. 'meta[A|http-equiv|name|content|charset][]' +
  2103. 'style[A|type|media|scoped][#]' +
  2104. 'script[A|charset|type|src|defer|async][#]' +
  2105. 'noscript[A][C]' +
  2106. 'body[A][C]' +
  2107. 'section[A][C]' +
  2108. 'nav[A][C]' +
  2109. 'article[A][C]' +
  2110. 'aside[A][C]' +
  2111. 'h1[A][B]' +
  2112. 'h2[A][B]' +
  2113. 'h3[A][B]' +
  2114. 'h4[A][B]' +
  2115. 'h5[A][B]' +
  2116. 'h6[A][B]' +
  2117. 'hgroup[A][h1|h2|h3|h4|h5|h6]' +
  2118. 'header[A][C]' +
  2119. 'footer[A][C]' +
  2120. 'address[A][C]' +
  2121. 'p[A][B]' +
  2122. 'br[A][]' +
  2123. 'pre[A][B]' +
  2124. 'dialog[A][dd|dt]' +
  2125. 'blockquote[A|cite][C]' +
  2126. 'ol[A|start|reversed][li]' +
  2127. 'ul[A][li]' +
  2128. 'li[A|value][C]' +
  2129. 'dl[A][dd|dt]' +
  2130. 'dt[A][B]' +
  2131. 'dd[A][C]' +
  2132. 'a[A|href|target|ping|rel|media|type][B]' +
  2133. 'em[A][B]' +
  2134. 'strong[A][B]' +
  2135. 'small[A][B]' +
  2136. 'cite[A][B]' +
  2137. 'q[A|cite][B]' +
  2138. 'dfn[A][B]' +
  2139. 'abbr[A][B]' +
  2140. 'code[A][B]' +
  2141. 'var[A][B]' +
  2142. 'samp[A][B]' +
  2143. 'kbd[A][B]' +
  2144. 'sub[A][B]' +
  2145. 'sup[A][B]' +
  2146. 'i[A][B]' +
  2147. 'b[A][B]' +
  2148. 'mark[A][B]' +
  2149. 'progress[A|value|max][B]' +
  2150. 'meter[A|value|min|max|low|high|optimum][B]' +
  2151. 'time[A|datetime][B]' +
  2152. 'ruby[A][B|rt|rp]' +
  2153. 'rt[A][B]' +
  2154. 'rp[A][B]' +
  2155. 'bdo[A][B]' +
  2156. 'span[A][B]' +
  2157. 'ins[A|cite|datetime][B]' +
  2158. 'del[A|cite|datetime][B]' +
  2159. 'figure[A][C|legend|figcaption]' +
  2160. 'figcaption[A][C]' +
  2161. 'img[A|alt|src|height|width|usemap|ismap][]' +
  2162. 'iframe[A|name|src|height|width|sandbox|seamless][]' +
  2163. 'embed[A|src|height|width|type][]' +
  2164. 'object[A|data|type|height|width|usemap|name|form|classid][param]' +
  2165. 'param[A|name|value][]' +
  2166. 'details[A|open][C|legend]' +
  2167. 'command[A|type|label|icon|disabled|checked|radiogroup][]' +
  2168. 'menu[A|type|label][C|li]' +
  2169. 'legend[A][C|B]' +
  2170. 'div[A][C]' +
  2171. 'source[A|src|type|media][]' +
  2172. 'audio[A|src|autobuffer|autoplay|loop|controls][source]' +
  2173. 'video[A|src|autobuffer|autoplay|loop|controls|width|height|poster][source]' +
  2174. 'hr[A][]' +
  2175. 'form[A|accept-charset|action|autocomplete|enctype|method|name|novalidate|target][C]' +
  2176. 'fieldset[A|disabled|form|name][C|legend]' +
  2177. 'label[A|form|for][B]' +
  2178. 'input[A|type|accept|alt|autocomplete|autofocus|checked|disabled|form|formaction|formenctype|formmethod|formnovalidate|formtarget|height|list|max|maxlength|min|' +
  2179. 'multiple|pattern|placeholder|readonly|required|size|src|step|width|files|value|name][]' +
  2180. 'button[A|autofocus|disabled|form|formaction|formenctype|formmethod|formnovalidate|formtarget|name|value|type][B]' +
  2181. 'select[A|autofocus|disabled|form|multiple|name|size][option|optgroup]' +
  2182. 'datalist[A][B|option]' +
  2183. 'optgroup[A|disabled|label][option]' +
  2184. 'option[A|disabled|selected|label|value][]' +
  2185. 'textarea[A|autofocus|disabled|form|maxlength|name|placeholder|readonly|required|rows|cols|wrap][]' +
  2186. 'keygen[A|autofocus|challenge|disabled|form|keytype|name][]' +
  2187. 'output[A|for|form|name][B]' +
  2188. 'canvas[A|width|height][]' +
  2189. 'map[A|name][B|C]' +
  2190. 'area[A|shape|coords|href|alt|target|media|rel|ping|type][]' +
  2191. 'mathml[A][]' +
  2192. 'svg[A][]' +
  2193. 'table[A|border][caption|colgroup|thead|tfoot|tbody|tr]' +
  2194. 'caption[A][C]' +
  2195. 'colgroup[A|span][col]' +
  2196. 'col[A|span][]' +
  2197. 'thead[A][tr]' +
  2198. 'tfoot[A][tr]' +
  2199. 'tbody[A][tr]' +
  2200. 'tr[A][th|td]' +
  2201. 'th[A|headers|rowspan|colspan|scope][B]' +
  2202. 'td[A|headers|rowspan|colspan][C]' +
  2203. 'wbr[A][]'
  2204. );
  2205. }
  2206. return html5;
  2207. };
  2208. function getHTML4() {
  2209. var html4 = mapCache.html4;
  2210. if (!html4) {
  2211. // This is the XHTML 1.0 transitional elements with it's attributes and children packed to reduce it's size
  2212. html4 = mapCache.html4 = unpack({
  2213. Z : 'H|K|N|O|P',
  2214. Y : 'X|form|R|Q',
  2215. ZG : 'E|span|width|align|char|charoff|valign',
  2216. X : 'p|T|div|U|W|isindex|fieldset|table',
  2217. ZF : 'E|align|char|charoff|valign',
  2218. W : 'pre|hr|blockquote|address|center|noframes',
  2219. ZE : 'abbr|axis|headers|scope|rowspan|colspan|align|char|charoff|valign|nowrap|bgcolor|width|height',
  2220. ZD : '[E][S]',
  2221. U : 'ul|ol|dl|menu|dir',
  2222. ZC : 'p|Y|div|U|W|table|br|span|bdo|object|applet|img|map|K|N|Q',
  2223. T : 'h1|h2|h3|h4|h5|h6',
  2224. ZB : 'X|S|Q',
  2225. S : 'R|P',
  2226. ZA : 'a|G|J|M|O|P',
  2227. R : 'a|H|K|N|O',
  2228. Q : 'noscript|P',
  2229. P : 'ins|del|script',
  2230. O : 'input|select|textarea|label|button',
  2231. N : 'M|L',
  2232. M : 'em|strong|dfn|code|q|samp|kbd|var|cite|abbr|acronym',
  2233. L : 'sub|sup',
  2234. K : 'J|I',
  2235. J : 'tt|i|b|u|s|strike',
  2236. I : 'big|small|font|basefont',
  2237. H : 'G|F',
  2238. G : 'br|span|bdo',
  2239. F : 'object|applet|img|map|iframe',
  2240. E : 'A|B|C',
  2241. D : 'accesskey|tabindex|onfocus|onblur',
  2242. C : 'onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup',
  2243. B : 'lang|xml:lang|dir',
  2244. A : 'id|class|style|title'
  2245. }, 'script[id|charset|type|language|src|defer|xml:space][]' +
  2246. 'style[B|id|type|media|title|xml:space][]' +
  2247. 'object[E|declare|classid|codebase|data|type|codetype|archive|standby|width|height|usemap|name|tabindex|align|border|hspace|vspace][#|param|Y]' +
  2248. 'param[id|name|value|valuetype|type][]' +
  2249. 'p[E|align][#|S]' +
  2250. 'a[E|D|charset|type|name|href|hreflang|rel|rev|shape|coords|target][#|Z]' +
  2251. 'br[A|clear][]' +
  2252. 'span[E][#|S]' +
  2253. 'bdo[A|C|B][#|S]' +
  2254. 'applet[A|codebase|archive|code|object|alt|name|width|height|align|hspace|vspace][#|param|Y]' +
  2255. 'h1[E|align][#|S]' +
  2256. 'img[E|src|alt|name|longdesc|width|height|usemap|ismap|align|border|hspace|vspace][]' +
  2257. 'map[B|C|A|name][X|form|Q|area]' +
  2258. 'h2[E|align][#|S]' +
  2259. 'iframe[A|longdesc|name|src|frameborder|marginwidth|marginheight|scrolling|align|width|height][#|Y]' +
  2260. 'h3[E|align][#|S]' +
  2261. 'tt[E][#|S]' +
  2262. 'i[E][#|S]' +
  2263. 'b[E][#|S]' +
  2264. 'u[E][#|S]' +
  2265. 's[E][#|S]' +
  2266. 'strike[E][#|S]' +
  2267. 'big[E][#|S]' +
  2268. 'small[E][#|S]' +
  2269. 'font[A|B|size|color|face][#|S]' +
  2270. 'basefont[id|size|color|face][]' +
  2271. 'em[E][#|S]' +
  2272. 'strong[E][#|S]' +
  2273. 'dfn[E][#|S]' +
  2274. 'code[E][#|S]' +
  2275. 'q[E|cite][#|S]' +
  2276. 'samp[E][#|S]' +
  2277. 'kbd[E][#|S]' +
  2278. 'var[E][#|S]' +
  2279. 'cite[E][#|S]' +
  2280. 'abbr[E][#|S]' +
  2281. 'acronym[E][#|S]' +
  2282. 'sub[E][#|S]' +
  2283. 'sup[E][#|S]' +
  2284. 'input[E|D|type|name|value|checked|disabled|readonly|size|maxlength|src|alt|usemap|onselect|onchange|accept|align][]' +
  2285. 'select[E|name|size|multiple|disabled|tabindex|onfocus|onblur|onchange][optgroup|option]' +
  2286. 'optgroup[E|disabled|label][option]' +
  2287. 'option[E|selected|disabled|label|value][]' +
  2288. 'textarea[E|D|name|rows|cols|disabled|readonly|onselect|onchange][]' +
  2289. 'label[E|for|accesskey|onfocus|onblur][#|S]' +
  2290. 'button[E|D|name|value|type|disabled][#|p|T|div|U|W|table|G|object|applet|img|map|K|N|Q]' +
  2291. 'h4[E|align][#|S]' +
  2292. 'ins[E|cite|datetime][#|Y]' +
  2293. 'h5[E|align][#|S]' +
  2294. 'del[E|cite|datetime][#|Y]' +
  2295. 'h6[E|align][#|S]' +
  2296. 'div[E|align][#|Y]' +
  2297. 'ul[E|type|compact][li]' +
  2298. 'li[E|type|value][#|Y]' +
  2299. 'ol[E|type|compact|start][li]' +
  2300. 'dl[E|compact][dt|dd]' +
  2301. 'dt[E][#|S]' +
  2302. 'dd[E][#|Y]' +
  2303. 'menu[E|compact][li]' +
  2304. 'dir[E|compact][li]' +
  2305. 'pre[E|width|xml:space][#|ZA]' +
  2306. 'hr[E|align|noshade|size|width][]' +
  2307. 'blockquote[E|cite][#|Y]' +
  2308. 'address[E][#|S|p]' +
  2309. 'center[E][#|Y]' +
  2310. 'noframes[E][#|Y]' +
  2311. 'isindex[A|B|prompt][]' +
  2312. 'fieldset[E][#|legend|Y]' +
  2313. 'legend[E|accesskey|align][#|S]' +
  2314. 'table[E|summary|width|border|frame|rules|cellspacing|cellpadding|align|bgcolor][caption|col|colgroup|thead|tfoot|tbody|tr]' +
  2315. 'caption[E|align][#|S]' +
  2316. 'col[ZG][]' +
  2317. 'colgroup[ZG][col]' +
  2318. 'thead[ZF][tr]' +
  2319. 'tr[ZF|bgcolor][th|td]' +
  2320. 'th[E|ZE][#|Y]' +
  2321. 'form[E|action|method|name|enctype|onsubmit|onreset|accept|accept-charset|target][#|X|R|Q]' +
  2322. 'noscript[E][#|Y]' +
  2323. 'td[E|ZE][#|Y]' +
  2324. 'tfoot[ZF][tr]' +
  2325. 'tbody[ZF][tr]' +
  2326. 'area[E|D|shape|coords|href|nohref|alt|target][]' +
  2327. 'base[id|href|target][]' +
  2328. 'body[E|onload|onunload|background|bgcolor|text|link|vlink|alink][#|Y]'
  2329. );
  2330. }
  2331. return html4;
  2332. };
  2333. tinymce.html.Schema = function(settings) {
  2334. var self = this, elements = {}, children = {}, patternElements = [], validStyles, schemaItems;
  2335. var whiteSpaceElementsMap, selfClosingElementsMap, shortEndedElementsMap, boolAttrMap, blockElementsMap, nonEmptyElementsMap, customElementsMap = {};
  2336. // Creates an lookup table map object for the specified option or the default value
  2337. function createLookupTable(option, default_value, extend) {
  2338. var value = settings[option];
  2339. if (!value) {
  2340. // Get cached default map or make it if needed
  2341. value = mapCache[option];
  2342. if (!value) {
  2343. value = makeMap(default_value, ' ', makeMap(default_value.toUpperCase(), ' '));
  2344. value = tinymce.extend(value, extend);
  2345. mapCache[option] = value;
  2346. }
  2347. } else {
  2348. // Create custom map
  2349. value = makeMap(value, ',', makeMap(value.toUpperCase(), ' '));
  2350. }
  2351. return value;
  2352. };
  2353. settings = settings || {};
  2354. schemaItems = settings.schema == "html5" ? getHTML5() : getHTML4();
  2355. // Allow all elements and attributes if verify_html is set to false
  2356. if (settings.verify_html === false)
  2357. settings.valid_elements = '*[*]';
  2358. // Build styles list
  2359. if (settings.valid_styles) {
  2360. validStyles = {};
  2361. // Convert styles into a rule list
  2362. each(settings.valid_styles, function(value, key) {
  2363. validStyles[key] = tinymce.explode(value);
  2364. });
  2365. }
  2366. // Setup map objects
  2367. whiteSpaceElementsMap = createLookupTable('whitespace_elements', 'pre script noscript style textarea');
  2368. selfClosingElementsMap = createLookupTable('self_closing_elements', 'colgroup dd dt li option p td tfoot th thead tr');
  2369. shortEndedElementsMap = createLookupTable('short_ended_elements', 'area base basefont br col frame hr img input isindex link meta param embed source wbr');
  2370. boolAttrMap = createLookupTable('boolean_attributes', 'checked compact declare defer disabled ismap multiple nohref noresize noshade nowrap readonly selected autoplay loop controls');
  2371. nonEmptyElementsMap = createLookupTable('non_empty_elements', 'td th iframe video audio object', shortEndedElementsMap);
  2372. textBlockElementsMap = createLookupTable('text_block_elements', 'h1 h2 h3 h4 h5 h6 p div address pre form ' +
  2373. 'blockquote center dir fieldset header footer article section hgroup aside nav figure');
  2374. blockElementsMap = createLookupTable('block_elements', 'hr table tbody thead tfoot ' +
  2375. 'th tr td li ol ul caption dl dt dd noscript menu isindex samp option datalist select optgroup', textBlockElementsMap);
  2376. // Converts a wildcard expression string to a regexp for example *a will become /.*a/.
  2377. function patternToRegExp(str) {
  2378. return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$');
  2379. };
  2380. // Parses the specified valid_elements string and adds to the current rules
  2381. // This function is a bit hard to read since it's heavily optimized for speed
  2382. function addValidElements(valid_elements) {
  2383. var ei, el, ai, al, yl, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder,
  2384. prefix, outputName, globalAttributes, globalAttributesOrder, transElement, key, childKey, value,
  2385. elementRuleRegExp = /^([#+\-])?([^\[\/]+)(?:\/([^\[]+))?(?:\[([^\]]+)\])?$/,
  2386. attrRuleRegExp = /^([!\-])?(\w+::\w+|[^=:<]+)?(?:([=:<])(.*))?$/,
  2387. hasPatternsRegExp = /[*?+]/;
  2388. if (valid_elements) {
  2389. // Split valid elements into an array with rules
  2390. valid_elements = split(valid_elements);
  2391. if (elements['@']) {
  2392. globalAttributes = elements['@'].attributes;
  2393. globalAttributesOrder = elements['@'].attributesOrder;
  2394. }
  2395. // Loop all rules
  2396. for (ei = 0, el = valid_elements.length; ei < el; ei++) {
  2397. // Parse element rule
  2398. matches = elementRuleRegExp.exec(valid_elements[ei]);
  2399. if (matches) {
  2400. // Setup local names for matches
  2401. prefix = matches[1];
  2402. elementName = matches[2];
  2403. outputName = matches[3];
  2404. attrData = matches[4];
  2405. // Create new attributes and attributesOrder
  2406. attributes = {};
  2407. attributesOrder = [];
  2408. // Create the new element
  2409. element = {
  2410. attributes : attributes,
  2411. attributesOrder : attributesOrder
  2412. };
  2413. // Padd empty elements prefix
  2414. if (prefix === '#')
  2415. element.paddEmpty = true;
  2416. // Remove empty elements prefix
  2417. if (prefix === '-')
  2418. element.removeEmpty = true;
  2419. // Copy attributes from global rule into current rule
  2420. if (globalAttributes) {
  2421. for (key in globalAttributes)
  2422. attributes[key] = globalAttributes[key];
  2423. attributesOrder.push.apply(attributesOrder, globalAttributesOrder);
  2424. }
  2425. // Attributes defined
  2426. if (attrData) {
  2427. attrData = split(attrData, '|');
  2428. for (ai = 0, al = attrData.length; ai < al; ai++) {
  2429. matches = attrRuleRegExp.exec(attrData[ai]);
  2430. if (matches) {
  2431. attr = {};
  2432. attrType = matches[1];
  2433. attrName = matches[2].replace(/::/g, ':');
  2434. prefix = matches[3];
  2435. value = matches[4];
  2436. // Required
  2437. if (attrType === '!') {
  2438. element.attributesRequired = element.attributesRequired || [];
  2439. element.attributesRequired.push(attrName);
  2440. attr.required = true;
  2441. }
  2442. // Denied from global
  2443. if (attrType === '-') {
  2444. delete attributes[attrName];
  2445. attributesOrder.splice(tinymce.inArray(attributesOrder, attrName), 1);
  2446. continue;
  2447. }
  2448. // Default value
  2449. if (prefix) {
  2450. // Default value
  2451. if (prefix === '=') {
  2452. element.attributesDefault = element.attributesDefault || [];
  2453. element.attributesDefault.push({name: attrName, value: value});
  2454. attr.defaultValue = value;
  2455. }
  2456. // Forced value
  2457. if (prefix === ':') {
  2458. element.attributesForced = element.attributesForced || [];
  2459. element.attributesForced.push({name: attrName, value: value});
  2460. attr.forcedValue = value;
  2461. }
  2462. // Required values
  2463. if (prefix === '<')
  2464. attr.validValues = makeMap(value, '?');
  2465. }
  2466. // Check for attribute patterns
  2467. if (hasPatternsRegExp.test(attrName)) {
  2468. element.attributePatterns = element.attributePatterns || [];
  2469. attr.pattern = patternToRegExp(attrName);
  2470. element.attributePatterns.push(attr);
  2471. } else {
  2472. // Add attribute to order list if it doesn't already exist
  2473. if (!attributes[attrName])
  2474. attributesOrder.push(attrName);
  2475. attributes[attrName] = attr;
  2476. }
  2477. }
  2478. }
  2479. }
  2480. // Global rule, store away these for later usage
  2481. if (!globalAttributes && elementName == '@') {
  2482. globalAttributes = attributes;
  2483. globalAttributesOrder = attributesOrder;
  2484. }
  2485. // Handle substitute elements such as b/strong
  2486. if (outputName) {
  2487. element.outputName = elementName;
  2488. elements[outputName] = element;
  2489. }
  2490. // Add pattern or exact element
  2491. if (hasPatternsRegExp.test(elementName)) {
  2492. element.pattern = patternToRegExp(elementName);
  2493. patternElements.push(element);
  2494. } else
  2495. elements[elementName] = element;
  2496. }
  2497. }
  2498. }
  2499. };
  2500. function setValidElements(valid_elements) {
  2501. elements = {};
  2502. patternElements = [];
  2503. addValidElements(valid_elements);
  2504. each(schemaItems, function(element, name) {
  2505. children[name] = element.children;
  2506. });
  2507. };
  2508. // Adds custom non HTML elements to the schema
  2509. function addCustomElements(custom_elements) {
  2510. var customElementRegExp = /^(~)?(.+)$/;
  2511. if (custom_elements) {
  2512. each(split(custom_elements), function(rule) {
  2513. var matches = customElementRegExp.exec(rule),
  2514. inline = matches[1] === '~',
  2515. cloneName = inline ? 'span' : 'div',
  2516. name = matches[2];
  2517. children[name] = children[cloneName];
  2518. customElementsMap[name] = cloneName;
  2519. // If it's not marked as inline then add it to valid block elements
  2520. if (!inline) {
  2521. blockElementsMap[name.toUpperCase()] = {};
  2522. blockElementsMap[name] = {};
  2523. }
  2524. // Add elements clone if needed
  2525. if (!elements[name]) {
  2526. elements[name] = elements[cloneName];
  2527. }
  2528. // Add custom elements at span/div positions
  2529. each(children, function(element, child) {
  2530. if (element[cloneName])
  2531. element[name] = element[cloneName];
  2532. });
  2533. });
  2534. }
  2535. };
  2536. // Adds valid children to the schema object
  2537. function addValidChildren(valid_children) {
  2538. var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/;
  2539. if (valid_children) {
  2540. each(split(valid_children), function(rule) {
  2541. var matches = childRuleRegExp.exec(rule), parent, prefix;
  2542. if (matches) {
  2543. prefix = matches[1];
  2544. // Add/remove items from default
  2545. if (prefix)
  2546. parent = children[matches[2]];
  2547. else
  2548. parent = children[matches[2]] = {'#comment' : {}};
  2549. parent = children[matches[2]];
  2550. each(split(matches[3], '|'), function(child) {
  2551. if (prefix === '-')
  2552. delete parent[child];
  2553. else
  2554. parent[child] = {};
  2555. });
  2556. }
  2557. });
  2558. }
  2559. };
  2560. function getElementRule(name) {
  2561. var element = elements[name], i;
  2562. // Exact match found
  2563. if (element)
  2564. return element;
  2565. // No exact match then try the patterns
  2566. i = patternElements.length;
  2567. while (i--) {
  2568. element = patternElements[i];
  2569. if (element.pattern.test(name))
  2570. return element;
  2571. }
  2572. };
  2573. if (!settings.valid_elements) {
  2574. // No valid elements defined then clone the elements from the schema spec
  2575. each(schemaItems, function(element, name) {
  2576. elements[name] = {
  2577. attributes : element.attributes,
  2578. attributesOrder : element.attributesOrder
  2579. };
  2580. children[name] = element.children;
  2581. });
  2582. // Switch these on HTML4
  2583. if (settings.schema != "html5") {
  2584. each(split('strong/b,em/i'), function(item) {
  2585. item = split(item, '/');
  2586. elements[item[1]].outputName = item[0];
  2587. });
  2588. }
  2589. // Add default alt attribute for images
  2590. elements.img.attributesDefault = [{name: 'alt', value: ''}];
  2591. // Remove these if they are empty by default
  2592. each(split('ol,ul,sub,sup,blockquote,span,font,a,table,tbody,tr,strong,em,b,i'), function(name) {
  2593. if (elements[name]) {
  2594. elements[name].removeEmpty = true;
  2595. }
  2596. });
  2597. // Padd these by default
  2598. each(split('p,h1,h2,h3,h4,h5,h6,th,td,pre,div,address,caption'), function(name) {
  2599. elements[name].paddEmpty = true;
  2600. });
  2601. } else
  2602. setValidElements(settings.valid_elements);
  2603. addCustomElements(settings.custom_elements);
  2604. addValidChildren(settings.valid_children);
  2605. addValidElements(settings.extended_valid_elements);
  2606. // Todo: Remove this when we fix list handling to be valid
  2607. addValidChildren('+ol[ul|ol],+ul[ul|ol]');
  2608. // Delete invalid elements
  2609. if (settings.invalid_elements) {
  2610. tinymce.each(tinymce.explode(settings.invalid_elements), function(item) {
  2611. if (elements[item])
  2612. delete elements[item];
  2613. });
  2614. }
  2615. // If the user didn't allow span only allow internal spans
  2616. if (!getElementRule('span'))
  2617. addValidElements('span[!data-mce-type|*]');
  2618. self.children = children;
  2619. self.styles = validStyles;
  2620. self.getBoolAttrs = function() {
  2621. return boolAttrMap;
  2622. };
  2623. self.getBlockElements = function() {
  2624. return blockElementsMap;
  2625. };
  2626. self.getTextBlockElements = function() {
  2627. return textBlockElementsMap;
  2628. };
  2629. self.getShortEndedElements = function() {
  2630. return shortEndedElementsMap;
  2631. };
  2632. self.getSelfClosingElements = function() {
  2633. return selfClosingElementsMap;
  2634. };
  2635. self.getNonEmptyElements = function() {
  2636. return nonEmptyElementsMap;
  2637. };
  2638. self.getWhiteSpaceElements = function() {
  2639. return whiteSpaceElementsMap;
  2640. };
  2641. self.isValidChild = function(name, child) {
  2642. var parent = children[name];
  2643. return !!(parent && parent[child]);
  2644. };
  2645. self.isValid = function(name, attr) {
  2646. var attrPatterns, i, rule = getElementRule(name);
  2647. // Check if it's a valid element
  2648. if (rule) {
  2649. if (attr) {
  2650. // Check if attribute name exists
  2651. if (rule.attributes[attr]) {
  2652. return true;
  2653. }
  2654. // Check if attribute matches a regexp pattern
  2655. attrPatterns = rule.attributePatterns;
  2656. if (attrPatterns) {
  2657. i = attrPatterns.length;
  2658. while (i--) {
  2659. if (attrPatterns[i].pattern.test(name)) {
  2660. return true;
  2661. }
  2662. }
  2663. }
  2664. } else {
  2665. return true;
  2666. }
  2667. }
  2668. // No match
  2669. return false;
  2670. };
  2671. self.getElementRule = getElementRule;
  2672. self.getCustomElements = function() {
  2673. return customElementsMap;
  2674. };
  2675. self.addValidElements = addValidElements;
  2676. self.setValidElements = setValidElements;
  2677. self.addCustomElements = addCustomElements;
  2678. self.addValidChildren = addValidChildren;
  2679. self.elements = elements;
  2680. };
  2681. })(tinymce);
  2682. (function(tinymce) {
  2683. tinymce.html.SaxParser = function(settings, schema) {
  2684. var self = this, noop = function() {};
  2685. settings = settings || {};
  2686. self.schema = schema = schema || new tinymce.html.Schema();
  2687. if (settings.fix_self_closing !== false)
  2688. settings.fix_self_closing = true;
  2689. // Add handler functions from settings and setup default handlers
  2690. tinymce.each('comment cdata text start end pi doctype'.split(' '), function(name) {
  2691. if (name)
  2692. self[name] = settings[name] || noop;
  2693. });
  2694. self.parse = function(html) {
  2695. var self = this, matches, index = 0, value, endRegExp, stack = [], attrList, i, text, name, isInternalElement, removeInternalElements,
  2696. shortEndedElements, fillAttrsMap, isShortEnded, validate, elementRule, isValidElement, attr, attribsValue, invalidPrefixRegExp,
  2697. validAttributesMap, validAttributePatterns, attributesRequired, attributesDefault, attributesForced, selfClosing,
  2698. tokenRegExp, attrRegExp, specialElements, attrValue, idCount = 0, decode = tinymce.html.Entities.decode, fixSelfClosing, isIE;
  2699. function processEndTag(name) {
  2700. var pos, i;
  2701. // Find position of parent of the same type
  2702. pos = stack.length;
  2703. while (pos--) {
  2704. if (stack[pos].name === name)
  2705. break;
  2706. }
  2707. // Found parent
  2708. if (pos >= 0) {
  2709. // Close all the open elements
  2710. for (i = stack.length - 1; i >= pos; i--) {
  2711. name = stack[i];
  2712. if (name.valid)
  2713. self.end(name.name);
  2714. }
  2715. // Remove the open elements from the stack
  2716. stack.length = pos;
  2717. }
  2718. };
  2719. function parseAttribute(match, name, value, val2, val3) {
  2720. var attrRule, i;
  2721. name = name.toLowerCase();
  2722. value = name in fillAttrsMap ? name : decode(value || val2 || val3 || ''); // Handle boolean attribute than value attribute
  2723. // Validate name and value
  2724. if (validate && !isInternalElement && name.indexOf('data-mce-') !== 0) {
  2725. attrRule = validAttributesMap[name];
  2726. // Find rule by pattern matching
  2727. if (!attrRule && validAttributePatterns) {
  2728. i = validAttributePatterns.length;
  2729. while (i--) {
  2730. attrRule = validAttributePatterns[i];
  2731. if (attrRule.pattern.test(name))
  2732. break;
  2733. }
  2734. // No rule matched
  2735. if (i === -1)
  2736. attrRule = null;
  2737. }
  2738. // No attribute rule found
  2739. if (!attrRule)
  2740. return;
  2741. // Validate value
  2742. if (attrRule.validValues && !(value in attrRule.validValues))
  2743. return;
  2744. }
  2745. // Add attribute to list and map
  2746. attrList.map[name] = value;
  2747. attrList.push({
  2748. name: name,
  2749. value: value
  2750. });
  2751. };
  2752. // Precompile RegExps and map objects
  2753. tokenRegExp = new RegExp('<(?:' +
  2754. '(?:!--([\\w\\W]*?)-->)|' + // Comment
  2755. '(?:!\\[CDATA\\[([\\w\\W]*?)\\]\\]>)|' + // CDATA
  2756. '(?:!DOCTYPE([\\w\\W]*?)>)|' + // DOCTYPE
  2757. '(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|' + // PI
  2758. '(?:\\/([^>]+)>)|' + // End element
  2759. '(?:([A-Za-z0-9\\-\\:\\.]+)((?:\\s+[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*|\\/|\\s+)>)' + // Start element
  2760. ')', 'g');
  2761. attrRegExp = /([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:[^\"])*)\")|(?:\'((?:[^\'])*)\')|([^>\s]+)))?/g;
  2762. specialElements = {
  2763. 'script' : /<\/script[^>]*>/gi,
  2764. 'style' : /<\/style[^>]*>/gi,
  2765. 'noscript' : /<\/noscript[^>]*>/gi
  2766. };
  2767. // Setup lookup tables for empty elements and boolean attributes
  2768. shortEndedElements = schema.getShortEndedElements();
  2769. selfClosing = settings.self_closing_elements || schema.getSelfClosingElements();
  2770. fillAttrsMap = schema.getBoolAttrs();
  2771. validate = settings.validate;
  2772. removeInternalElements = settings.remove_internals;
  2773. fixSelfClosing = settings.fix_self_closing;
  2774. isIE = tinymce.isIE;
  2775. invalidPrefixRegExp = /^:/;
  2776. while (matches = tokenRegExp.exec(html)) {
  2777. // Text
  2778. if (index < matches.index)
  2779. self.text(decode(html.substr(index, matches.index - index)));
  2780. if (value = matches[6]) { // End element
  2781. value = value.toLowerCase();
  2782. // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
  2783. if (isIE && invalidPrefixRegExp.test(value))
  2784. value = value.substr(1);
  2785. processEndTag(value);
  2786. } else if (value = matches[7]) { // Start element
  2787. value = value.toLowerCase();
  2788. // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
  2789. if (isIE && invalidPrefixRegExp.test(value))
  2790. value = value.substr(1);
  2791. isShortEnded = value in shortEndedElements;
  2792. // Is self closing tag for example an <li> after an open <li>
  2793. if (fixSelfClosing && selfClosing[value] && stack.length > 0 && stack[stack.length - 1].name === value)
  2794. processEndTag(value);
  2795. // Validate element
  2796. if (!validate || (elementRule = schema.getElementRule(value))) {
  2797. isValidElement = true;
  2798. // Grab attributes map and patters when validation is enabled
  2799. if (validate) {
  2800. validAttributesMap = elementRule.attributes;
  2801. validAttributePatterns = elementRule.attributePatterns;
  2802. }
  2803. // Parse attributes
  2804. if (attribsValue = matches[8]) {
  2805. isInternalElement = attribsValue.indexOf('data-mce-type') !== -1; // Check if the element is an internal element
  2806. // If the element has internal attributes then remove it if we are told to do so
  2807. if (isInternalElement && removeInternalElements)
  2808. isValidElement = false;
  2809. attrList = [];
  2810. attrList.map = {};
  2811. attribsValue.replace(attrRegExp, parseAttribute);
  2812. } else {
  2813. attrList = [];
  2814. attrList.map = {};
  2815. }
  2816. // Process attributes if validation is enabled
  2817. if (validate && !isInternalElement) {
  2818. attributesRequired = elementRule.attributesRequired;
  2819. attributesDefault = elementRule.attributesDefault;
  2820. attributesForced = elementRule.attributesForced;
  2821. // Handle forced attributes
  2822. if (attributesForced) {
  2823. i = attributesForced.length;
  2824. while (i--) {
  2825. attr = attributesForced[i];
  2826. name = attr.name;
  2827. attrValue = attr.value;
  2828. if (attrValue === '{$uid}')
  2829. attrValue = 'mce_' + idCount++;
  2830. attrList.map[name] = attrValue;
  2831. attrList.push({name: name, value: attrValue});
  2832. }
  2833. }
  2834. // Handle default attributes
  2835. if (attributesDefault) {
  2836. i = attributesDefault.length;
  2837. while (i--) {
  2838. attr = attributesDefault[i];
  2839. name = attr.name;
  2840. if (!(name in attrList.map)) {
  2841. attrValue = attr.value;
  2842. if (attrValue === '{$uid}')
  2843. attrValue = 'mce_' + idCount++;
  2844. attrList.map[name] = attrValue;
  2845. attrList.push({name: name, value: attrValue});
  2846. }
  2847. }
  2848. }
  2849. // Handle required attributes
  2850. if (attributesRequired) {
  2851. i = attributesRequired.length;
  2852. while (i--) {
  2853. if (attributesRequired[i] in attrList.map)
  2854. break;
  2855. }
  2856. // None of the required attributes where found
  2857. if (i === -1)
  2858. isValidElement = false;
  2859. }
  2860. // Invalidate element if it's marked as bogus
  2861. if (attrList.map['data-mce-bogus'])
  2862. isValidElement = false;
  2863. }
  2864. if (isValidElement)
  2865. self.start(value, attrList, isShortEnded);
  2866. } else
  2867. isValidElement = false;
  2868. // Treat script, noscript and style a bit different since they may include code that looks like elements
  2869. if (endRegExp = specialElements[value]) {
  2870. endRegExp.lastIndex = index = matches.index + matches[0].length;
  2871. if (matches = endRegExp.exec(html)) {
  2872. if (isValidElement)
  2873. text = html.substr(index, matches.index - index);
  2874. index = matches.index + matches[0].length;
  2875. } else {
  2876. text = html.substr(index);
  2877. index = html.length;
  2878. }
  2879. if (isValidElement && text.length > 0)
  2880. self.text(text, true);
  2881. if (isValidElement)
  2882. self.end(value);
  2883. tokenRegExp.lastIndex = index;
  2884. continue;
  2885. }
  2886. // Push value on to stack
  2887. if (!isShortEnded) {
  2888. if (!attribsValue || attribsValue.indexOf('/') != attribsValue.length - 1)
  2889. stack.push({name: value, valid: isValidElement});
  2890. else if (isValidElement)
  2891. self.end(value);
  2892. }
  2893. } else if (value = matches[1]) { // Comment
  2894. self.comment(value);
  2895. } else if (value = matches[2]) { // CDATA
  2896. self.cdata(value);
  2897. } else if (value = matches[3]) { // DOCTYPE
  2898. self.doctype(value);
  2899. } else if (value = matches[4]) { // PI
  2900. self.pi(value, matches[5]);
  2901. }
  2902. index = matches.index + matches[0].length;
  2903. }
  2904. // Text
  2905. if (index < html.length)
  2906. self.text(decode(html.substr(index)));
  2907. // Close any open elements
  2908. for (i = stack.length - 1; i >= 0; i--) {
  2909. value = stack[i];
  2910. if (value.valid)
  2911. self.end(value.name);
  2912. }
  2913. };
  2914. }
  2915. })(tinymce);
  2916. (function(tinymce) {
  2917. var whiteSpaceRegExp = /^[ \t\r\n]*$/, typeLookup = {
  2918. '#text' : 3,
  2919. '#comment' : 8,
  2920. '#cdata' : 4,
  2921. '#pi' : 7,
  2922. '#doctype' : 10,
  2923. '#document-fragment' : 11
  2924. };
  2925. // Walks the tree left/right
  2926. function walk(node, root_node, prev) {
  2927. var sibling, parent, startName = prev ? 'lastChild' : 'firstChild', siblingName = prev ? 'prev' : 'next';
  2928. // Walk into nodes if it has a start
  2929. if (node[startName])
  2930. return node[startName];
  2931. // Return the sibling if it has one
  2932. if (node !== root_node) {
  2933. sibling = node[siblingName];
  2934. if (sibling)
  2935. return sibling;
  2936. // Walk up the parents to look for siblings
  2937. for (parent = node.parent; parent && parent !== root_node; parent = parent.parent) {
  2938. sibling = parent[siblingName];
  2939. if (sibling)
  2940. return sibling;
  2941. }
  2942. }
  2943. };
  2944. function Node(name, type) {
  2945. this.name = name;
  2946. this.type = type;
  2947. if (type === 1) {
  2948. this.attributes = [];
  2949. this.attributes.map = {};
  2950. }
  2951. }
  2952. tinymce.extend(Node.prototype, {
  2953. replace : function(node) {
  2954. var self = this;
  2955. if (node.parent)
  2956. node.remove();
  2957. self.insert(node, self);
  2958. self.remove();
  2959. return self;
  2960. },
  2961. attr : function(name, value) {
  2962. var self = this, attrs, i, undef;
  2963. if (typeof name !== "string") {
  2964. for (i in name)
  2965. self.attr(i, name[i]);
  2966. return self;
  2967. }
  2968. if (attrs = self.attributes) {
  2969. if (value !== undef) {
  2970. // Remove attribute
  2971. if (value === null) {
  2972. if (name in attrs.map) {
  2973. delete attrs.map[name];
  2974. i = attrs.length;
  2975. while (i--) {
  2976. if (attrs[i].name === name) {
  2977. attrs = attrs.splice(i, 1);
  2978. return self;
  2979. }
  2980. }
  2981. }
  2982. return self;
  2983. }
  2984. // Set attribute
  2985. if (name in attrs.map) {
  2986. // Set attribute
  2987. i = attrs.length;
  2988. while (i--) {
  2989. if (attrs[i].name === name) {
  2990. attrs[i].value = value;
  2991. break;
  2992. }
  2993. }
  2994. } else
  2995. attrs.push({name: name, value: value});
  2996. attrs.map[name] = value;
  2997. return self;
  2998. } else {
  2999. return attrs.map[name];
  3000. }
  3001. }
  3002. },
  3003. clone : function() {
  3004. var self = this, clone = new Node(self.name, self.type), i, l, selfAttrs, selfAttr, cloneAttrs;
  3005. // Clone element attributes
  3006. if (selfAttrs = self.attributes) {
  3007. cloneAttrs = [];
  3008. cloneAttrs.map = {};
  3009. for (i = 0, l = selfAttrs.length; i < l; i++) {
  3010. selfAttr = selfAttrs[i];
  3011. // Clone everything except id
  3012. if (selfAttr.name !== 'id') {
  3013. cloneAttrs[cloneAttrs.length] = {name: selfAttr.name, value: selfAttr.value};
  3014. cloneAttrs.map[selfAttr.name] = selfAttr.value;
  3015. }
  3016. }
  3017. clone.attributes = cloneAttrs;
  3018. }
  3019. clone.value = self.value;
  3020. clone.shortEnded = self.shortEnded;
  3021. return clone;
  3022. },
  3023. wrap : function(wrapper) {
  3024. var self = this;
  3025. self.parent.insert(wrapper, self);
  3026. wrapper.append(self);
  3027. return self;
  3028. },
  3029. unwrap : function() {
  3030. var self = this, node, next;
  3031. for (node = self.firstChild; node; ) {
  3032. next = node.next;
  3033. self.insert(node, self, true);
  3034. node = next;
  3035. }
  3036. self.remove();
  3037. },
  3038. remove : function() {
  3039. var self = this, parent = self.parent, next = self.next, prev = self.prev;
  3040. if (parent) {
  3041. if (parent.firstChild === self) {
  3042. parent.firstChild = next;
  3043. if (next)
  3044. next.prev = null;
  3045. } else {
  3046. prev.next = next;
  3047. }
  3048. if (parent.lastChild === self) {
  3049. parent.lastChild = prev;
  3050. if (prev)
  3051. prev.next = null;
  3052. } else {
  3053. next.prev = prev;
  3054. }
  3055. self.parent = self.next = self.prev = null;
  3056. }
  3057. return self;
  3058. },
  3059. append : function(node) {
  3060. var self = this, last;
  3061. if (node.parent)
  3062. node.remove();
  3063. last = self.lastChild;
  3064. if (last) {
  3065. last.next = node;
  3066. node.prev = last;
  3067. self.lastChild = node;
  3068. } else
  3069. self.lastChild = self.firstChild = node;
  3070. node.parent = self;
  3071. return node;
  3072. },
  3073. insert : function(node, ref_node, before) {
  3074. var parent;
  3075. if (node.parent)
  3076. node.remove();
  3077. parent = ref_node.parent || this;
  3078. if (before) {
  3079. if (ref_node === parent.firstChild)
  3080. parent.firstChild = node;
  3081. else
  3082. ref_node.prev.next = node;
  3083. node.prev = ref_node.prev;
  3084. node.next = ref_node;
  3085. ref_node.prev = node;
  3086. } else {
  3087. if (ref_node === parent.lastChild)
  3088. parent.lastChild = node;
  3089. else
  3090. ref_node.next.prev = node;
  3091. node.next = ref_node.next;
  3092. node.prev = ref_node;
  3093. ref_node.next = node;
  3094. }
  3095. node.parent = parent;
  3096. return node;
  3097. },
  3098. getAll : function(name) {
  3099. var self = this, node, collection = [];
  3100. for (node = self.firstChild; node; node = walk(node, self)) {
  3101. if (node.name === name)
  3102. collection.push(node);
  3103. }
  3104. return collection;
  3105. },
  3106. empty : function() {
  3107. var self = this, nodes, i, node;
  3108. // Remove all children
  3109. if (self.firstChild) {
  3110. nodes = [];
  3111. // Collect the children
  3112. for (node = self.firstChild; node; node = walk(node, self))
  3113. nodes.push(node);
  3114. // Remove the children
  3115. i = nodes.length;
  3116. while (i--) {
  3117. node = nodes[i];
  3118. node.parent = node.firstChild = node.lastChild = node.next = node.prev = null;
  3119. }
  3120. }
  3121. self.firstChild = self.lastChild = null;
  3122. return self;
  3123. },
  3124. isEmpty : function(elements) {
  3125. var self = this, node = self.firstChild, i, name;
  3126. if (node) {
  3127. do {
  3128. if (node.type === 1) {
  3129. // Ignore bogus elements
  3130. if (node.attributes.map['data-mce-bogus'])
  3131. continue;
  3132. // Keep empty elements like <img />
  3133. if (elements[node.name])
  3134. return false;
  3135. // Keep elements with data attributes or name attribute like <a name="1"></a>
  3136. i = node.attributes.length;
  3137. while (i--) {
  3138. name = node.attributes[i].name;
  3139. if (name === "name" || name.indexOf('data-mce-') === 0)
  3140. return false;
  3141. }
  3142. }
  3143. // Keep comments
  3144. if (node.type === 8)
  3145. return false;
  3146. // Keep non whitespace text nodes
  3147. if ((node.type === 3 && !whiteSpaceRegExp.test(node.value)))
  3148. return false;
  3149. } while (node = walk(node, self));
  3150. }
  3151. return true;
  3152. },
  3153. walk : function(prev) {
  3154. return walk(this, null, prev);
  3155. }
  3156. });
  3157. tinymce.extend(Node, {
  3158. create : function(name, attrs) {
  3159. var node, attrName;
  3160. // Create node
  3161. node = new Node(name, typeLookup[name] || 1);
  3162. // Add attributes if needed
  3163. if (attrs) {
  3164. for (attrName in attrs)
  3165. node.attr(attrName, attrs[attrName]);
  3166. }
  3167. return node;
  3168. }
  3169. });
  3170. tinymce.html.Node = Node;
  3171. })(tinymce);
  3172. (function(tinymce) {
  3173. var Node = tinymce.html.Node;
  3174. tinymce.html.DomParser = function(settings, schema) {
  3175. var self = this, nodeFilters = {}, attributeFilters = [], matchedNodes = {}, matchedAttributes = {};
  3176. settings = settings || {};
  3177. settings.validate = "validate" in settings ? settings.validate : true;
  3178. settings.root_name = settings.root_name || 'body';
  3179. self.schema = schema = schema || new tinymce.html.Schema();
  3180. function fixInvalidChildren(nodes) {
  3181. var ni, node, parent, parents, newParent, currentNode, tempNode, childNode, i,
  3182. childClone, nonEmptyElements, nonSplitableElements, textBlockElements, sibling, nextNode;
  3183. nonSplitableElements = tinymce.makeMap('tr,td,th,tbody,thead,tfoot,table');
  3184. nonEmptyElements = schema.getNonEmptyElements();
  3185. textBlockElements = schema.getTextBlockElements();
  3186. for (ni = 0; ni < nodes.length; ni++) {
  3187. node = nodes[ni];
  3188. // Already removed or fixed
  3189. if (!node.parent || node.fixed)
  3190. continue;
  3191. // If the invalid element is a text block and the text block is within a parent LI element
  3192. // Then unwrap the first text block and convert other sibling text blocks to LI elements similar to Word/Open Office
  3193. if (textBlockElements[node.name] && node.parent.name == 'li') {
  3194. // Move sibling text blocks after LI element
  3195. sibling = node.next;
  3196. while (sibling) {
  3197. if (textBlockElements[sibling.name]) {
  3198. sibling.name = 'li';
  3199. sibling.fixed = true;
  3200. node.parent.insert(sibling, node.parent);
  3201. } else {
  3202. break;
  3203. }
  3204. sibling = sibling.next;
  3205. }
  3206. // Unwrap current text block
  3207. node.unwrap(node);
  3208. continue;
  3209. }
  3210. // Get list of all parent nodes until we find a valid parent to stick the child into
  3211. parents = [node];
  3212. for (parent = node.parent; parent && !schema.isValidChild(parent.name, node.name) && !nonSplitableElements[parent.name]; parent = parent.parent)
  3213. parents.push(parent);
  3214. // Found a suitable parent
  3215. if (parent && parents.length > 1) {
  3216. // Reverse the array since it makes looping easier
  3217. parents.reverse();
  3218. // Clone the related parent and insert that after the moved node
  3219. newParent = currentNode = self.filterNode(parents[0].clone());
  3220. // Start cloning and moving children on the left side of the target node
  3221. for (i = 0; i < parents.length - 1; i++) {
  3222. if (schema.isValidChild(currentNode.name, parents[i].name)) {
  3223. tempNode = self.filterNode(parents[i].clone());
  3224. currentNode.append(tempNode);
  3225. } else
  3226. tempNode = currentNode;
  3227. for (childNode = parents[i].firstChild; childNode && childNode != parents[i + 1]; ) {
  3228. nextNode = childNode.next;
  3229. tempNode.append(childNode);
  3230. childNode = nextNode;
  3231. }
  3232. currentNode = tempNode;
  3233. }
  3234. if (!newParent.isEmpty(nonEmptyElements)) {
  3235. parent.insert(newParent, parents[0], true);
  3236. parent.insert(node, newParent);
  3237. } else {
  3238. parent.insert(node, parents[0], true);
  3239. }
  3240. // Check if the element is empty by looking through it's contents and special treatment for <p><br /></p>
  3241. parent = parents[0];
  3242. if (parent.isEmpty(nonEmptyElements) || parent.firstChild === parent.lastChild && parent.firstChild.name === 'br') {
  3243. parent.empty().remove();
  3244. }
  3245. } else if (node.parent) {
  3246. // If it's an LI try to find a UL/OL for it or wrap it
  3247. if (node.name === 'li') {
  3248. sibling = node.prev;
  3249. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  3250. sibling.append(node);
  3251. continue;
  3252. }
  3253. sibling = node.next;
  3254. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  3255. sibling.insert(node, sibling.firstChild, true);
  3256. continue;
  3257. }
  3258. node.wrap(self.filterNode(new Node('ul', 1)));
  3259. continue;
  3260. }
  3261. // Try wrapping the element in a DIV
  3262. if (schema.isValidChild(node.parent.name, 'div') && schema.isValidChild('div', node.name)) {
  3263. node.wrap(self.filterNode(new Node('div', 1)));
  3264. } else {
  3265. // We failed wrapping it, then remove or unwrap it
  3266. if (node.name === 'style' || node.name === 'script')
  3267. node.empty().remove();
  3268. else
  3269. node.unwrap();
  3270. }
  3271. }
  3272. }
  3273. };
  3274. self.filterNode = function(node) {
  3275. var i, name, list;
  3276. // Run element filters
  3277. if (name in nodeFilters) {
  3278. list = matchedNodes[name];
  3279. if (list)
  3280. list.push(node);
  3281. else
  3282. matchedNodes[name] = [node];
  3283. }
  3284. // Run attribute filters
  3285. i = attributeFilters.length;
  3286. while (i--) {
  3287. name = attributeFilters[i].name;
  3288. if (name in node.attributes.map) {
  3289. list = matchedAttributes[name];
  3290. if (list)
  3291. list.push(node);
  3292. else
  3293. matchedAttributes[name] = [node];
  3294. }
  3295. }
  3296. return node;
  3297. };
  3298. self.addNodeFilter = function(name, callback) {
  3299. tinymce.each(tinymce.explode(name), function(name) {
  3300. var list = nodeFilters[name];
  3301. if (!list)
  3302. nodeFilters[name] = list = [];
  3303. list.push(callback);
  3304. });
  3305. };
  3306. self.addAttributeFilter = function(name, callback) {
  3307. tinymce.each(tinymce.explode(name), function(name) {
  3308. var i;
  3309. for (i = 0; i < attributeFilters.length; i++) {
  3310. if (attributeFilters[i].name === name) {
  3311. attributeFilters[i].callbacks.push(callback);
  3312. return;
  3313. }
  3314. }
  3315. attributeFilters.push({name: name, callbacks: [callback]});
  3316. });
  3317. };
  3318. self.parse = function(html, args) {
  3319. var parser, rootNode, node, nodes, i, l, fi, fl, list, name, validate,
  3320. blockElements, startWhiteSpaceRegExp, invalidChildren = [], isInWhiteSpacePreservedElement,
  3321. endWhiteSpaceRegExp, allWhiteSpaceRegExp, isAllWhiteSpaceRegExp, whiteSpaceElements, children, nonEmptyElements, rootBlockName;
  3322. args = args || {};
  3323. matchedNodes = {};
  3324. matchedAttributes = {};
  3325. blockElements = tinymce.extend(tinymce.makeMap('script,style,head,html,body,title,meta,param'), schema.getBlockElements());
  3326. nonEmptyElements = schema.getNonEmptyElements();
  3327. children = schema.children;
  3328. validate = settings.validate;
  3329. rootBlockName = "forced_root_block" in args ? args.forced_root_block : settings.forced_root_block;
  3330. whiteSpaceElements = schema.getWhiteSpaceElements();
  3331. startWhiteSpaceRegExp = /^[ \t\r\n]+/;
  3332. endWhiteSpaceRegExp = /[ \t\r\n]+$/;
  3333. allWhiteSpaceRegExp = /[ \t\r\n]+/g;
  3334. isAllWhiteSpaceRegExp = /^[ \t\r\n]+$/;
  3335. function addRootBlocks() {
  3336. var node = rootNode.firstChild, next, rootBlockNode;
  3337. while (node) {
  3338. next = node.next;
  3339. if (node.type == 3 || (node.type == 1 && node.name !== 'p' && !blockElements[node.name] && !node.attr('data-mce-type'))) {
  3340. if (!rootBlockNode) {
  3341. // Create a new root block element
  3342. rootBlockNode = createNode(rootBlockName, 1);
  3343. rootNode.insert(rootBlockNode, node);
  3344. rootBlockNode.append(node);
  3345. } else
  3346. rootBlockNode.append(node);
  3347. } else {
  3348. rootBlockNode = null;
  3349. }
  3350. node = next;
  3351. };
  3352. };
  3353. function createNode(name, type) {
  3354. var node = new Node(name, type), list;
  3355. if (name in nodeFilters) {
  3356. list = matchedNodes[name];
  3357. if (list)
  3358. list.push(node);
  3359. else
  3360. matchedNodes[name] = [node];
  3361. }
  3362. return node;
  3363. };
  3364. function removeWhitespaceBefore(node) {
  3365. var textNode, textVal, sibling;
  3366. for (textNode = node.prev; textNode && textNode.type === 3; ) {
  3367. textVal = textNode.value.replace(endWhiteSpaceRegExp, '');
  3368. if (textVal.length > 0) {
  3369. textNode.value = textVal;
  3370. textNode = textNode.prev;
  3371. } else {
  3372. sibling = textNode.prev;
  3373. textNode.remove();
  3374. textNode = sibling;
  3375. }
  3376. }
  3377. };
  3378. function cloneAndExcludeBlocks(input) {
  3379. var name, output = {};
  3380. for (name in input) {
  3381. if (name !== 'li' && name != 'p') {
  3382. output[name] = input[name];
  3383. }
  3384. }
  3385. return output;
  3386. };
  3387. parser = new tinymce.html.SaxParser({
  3388. validate : validate,
  3389. // Exclude P and LI from DOM parsing since it's treated better by the DOM parser
  3390. self_closing_elements: cloneAndExcludeBlocks(schema.getSelfClosingElements()),
  3391. cdata: function(text) {
  3392. node.append(createNode('#cdata', 4)).value = text;
  3393. },
  3394. text: function(text, raw) {
  3395. var textNode;
  3396. // Trim all redundant whitespace on non white space elements
  3397. if (!isInWhiteSpacePreservedElement) {
  3398. text = text.replace(allWhiteSpaceRegExp, ' ');
  3399. if (node.lastChild && blockElements[node.lastChild.name])
  3400. text = text.replace(startWhiteSpaceRegExp, '');
  3401. }
  3402. // Do we need to create the node
  3403. if (text.length !== 0) {
  3404. textNode = createNode('#text', 3);
  3405. textNode.raw = !!raw;
  3406. node.append(textNode).value = text;
  3407. }
  3408. },
  3409. comment: function(text) {
  3410. node.append(createNode('#comment', 8)).value = text;
  3411. },
  3412. pi: function(name, text) {
  3413. node.append(createNode(name, 7)).value = text;
  3414. removeWhitespaceBefore(node);
  3415. },
  3416. doctype: function(text) {
  3417. var newNode;
  3418. newNode = node.append(createNode('#doctype', 10));
  3419. newNode.value = text;
  3420. removeWhitespaceBefore(node);
  3421. },
  3422. start: function(name, attrs, empty) {
  3423. var newNode, attrFiltersLen, elementRule, textNode, attrName, text, sibling, parent;
  3424. elementRule = validate ? schema.getElementRule(name) : {};
  3425. if (elementRule) {
  3426. newNode = createNode(elementRule.outputName || name, 1);
  3427. newNode.attributes = attrs;
  3428. newNode.shortEnded = empty;
  3429. node.append(newNode);
  3430. // Check if node is valid child of the parent node is the child is
  3431. // unknown we don't collect it since it's probably a custom element
  3432. parent = children[node.name];
  3433. if (parent && children[newNode.name] && !parent[newNode.name])
  3434. invalidChildren.push(newNode);
  3435. attrFiltersLen = attributeFilters.length;
  3436. while (attrFiltersLen--) {
  3437. attrName = attributeFilters[attrFiltersLen].name;
  3438. if (attrName in attrs.map) {
  3439. list = matchedAttributes[attrName];
  3440. if (list)
  3441. list.push(newNode);
  3442. else
  3443. matchedAttributes[attrName] = [newNode];
  3444. }
  3445. }
  3446. // Trim whitespace before block
  3447. if (blockElements[name])
  3448. removeWhitespaceBefore(newNode);
  3449. // Change current node if the element wasn't empty i.e not <br /> or <img />
  3450. if (!empty)
  3451. node = newNode;
  3452. // Check if we are inside a whitespace preserved element
  3453. if (!isInWhiteSpacePreservedElement && whiteSpaceElements[name]) {
  3454. isInWhiteSpacePreservedElement = true;
  3455. }
  3456. }
  3457. },
  3458. end: function(name) {
  3459. var textNode, elementRule, text, sibling, tempNode;
  3460. elementRule = validate ? schema.getElementRule(name) : {};
  3461. if (elementRule) {
  3462. if (blockElements[name]) {
  3463. if (!isInWhiteSpacePreservedElement) {
  3464. // Trim whitespace of the first node in a block
  3465. textNode = node.firstChild;
  3466. if (textNode && textNode.type === 3) {
  3467. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  3468. // Any characters left after trim or should we remove it
  3469. if (text.length > 0) {
  3470. textNode.value = text;
  3471. textNode = textNode.next;
  3472. } else {
  3473. sibling = textNode.next;
  3474. textNode.remove();
  3475. textNode = sibling;
  3476. }
  3477. // Remove any pure whitespace siblings
  3478. while (textNode && textNode.type === 3) {
  3479. text = textNode.value;
  3480. sibling = textNode.next;
  3481. if (text.length === 0 || isAllWhiteSpaceRegExp.test(text)) {
  3482. textNode.remove();
  3483. textNode = sibling;
  3484. }
  3485. textNode = sibling;
  3486. }
  3487. }
  3488. // Trim whitespace of the last node in a block
  3489. textNode = node.lastChild;
  3490. if (textNode && textNode.type === 3) {
  3491. text = textNode.value.replace(endWhiteSpaceRegExp, '');
  3492. // Any characters left after trim or should we remove it
  3493. if (text.length > 0) {
  3494. textNode.value = text;
  3495. textNode = textNode.prev;
  3496. } else {
  3497. sibling = textNode.prev;
  3498. textNode.remove();
  3499. textNode = sibling;
  3500. }
  3501. // Remove any pure whitespace siblings
  3502. while (textNode && textNode.type === 3) {
  3503. text = textNode.value;
  3504. sibling = textNode.prev;
  3505. if (text.length === 0 || isAllWhiteSpaceRegExp.test(text)) {
  3506. textNode.remove();
  3507. textNode = sibling;
  3508. }
  3509. textNode = sibling;
  3510. }
  3511. }
  3512. }
  3513. // Trim start white space
  3514. // Removed due to: #5424
  3515. /*textNode = node.prev;
  3516. if (textNode && textNode.type === 3) {
  3517. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  3518. if (text.length > 0)
  3519. textNode.value = text;
  3520. else
  3521. textNode.remove();
  3522. }*/
  3523. }
  3524. // Check if we exited a whitespace preserved element
  3525. if (isInWhiteSpacePreservedElement && whiteSpaceElements[name]) {
  3526. isInWhiteSpacePreservedElement = false;
  3527. }
  3528. // Handle empty nodes
  3529. if (elementRule.removeEmpty || elementRule.paddEmpty) {
  3530. if (node.isEmpty(nonEmptyElements)) {
  3531. if (elementRule.paddEmpty)
  3532. node.empty().append(new Node('#text', '3')).value = '\u00a0';
  3533. else {
  3534. // Leave nodes that have a name like <a name="name">
  3535. if (!node.attributes.map.name && !node.attributes.map.id) {
  3536. tempNode = node.parent;
  3537. node.empty().remove();
  3538. node = tempNode;
  3539. return;
  3540. }
  3541. }
  3542. }
  3543. }
  3544. node = node.parent;
  3545. }
  3546. }
  3547. }, schema);
  3548. rootNode = node = new Node(args.context || settings.root_name, 11);
  3549. parser.parse(html);
  3550. // Fix invalid children or report invalid children in a contextual parsing
  3551. if (validate && invalidChildren.length) {
  3552. if (!args.context)
  3553. fixInvalidChildren(invalidChildren);
  3554. else
  3555. args.invalid = true;
  3556. }
  3557. // Wrap nodes in the root into block elements if the root is body
  3558. if (rootBlockName && rootNode.name == 'body')
  3559. addRootBlocks();
  3560. // Run filters only when the contents is valid
  3561. if (!args.invalid) {
  3562. // Run node filters
  3563. for (name in matchedNodes) {
  3564. list = nodeFilters[name];
  3565. nodes = matchedNodes[name];
  3566. // Remove already removed children
  3567. fi = nodes.length;
  3568. while (fi--) {
  3569. if (!nodes[fi].parent)
  3570. nodes.splice(fi, 1);
  3571. }
  3572. for (i = 0, l = list.length; i < l; i++)
  3573. list[i](nodes, name, args);
  3574. }
  3575. // Run attribute filters
  3576. for (i = 0, l = attributeFilters.length; i < l; i++) {
  3577. list = attributeFilters[i];
  3578. if (list.name in matchedAttributes) {
  3579. nodes = matchedAttributes[list.name];
  3580. // Remove already removed children
  3581. fi = nodes.length;
  3582. while (fi--) {
  3583. if (!nodes[fi].parent)
  3584. nodes.splice(fi, 1);
  3585. }
  3586. for (fi = 0, fl = list.callbacks.length; fi < fl; fi++)
  3587. list.callbacks[fi](nodes, list.name, args);
  3588. }
  3589. }
  3590. }
  3591. return rootNode;
  3592. };
  3593. // Remove <br> at end of block elements Gecko and WebKit injects BR elements to
  3594. // make it possible to place the caret inside empty blocks. This logic tries to remove
  3595. // these elements and keep br elements that where intended to be there intact
  3596. if (settings.remove_trailing_brs) {
  3597. self.addNodeFilter('br', function(nodes, name) {
  3598. var i, l = nodes.length, node, blockElements = tinymce.extend({}, schema.getBlockElements()),
  3599. nonEmptyElements = schema.getNonEmptyElements(), parent, lastParent, prev, prevName;
  3600. // Remove brs from body element as well
  3601. blockElements.body = 1;
  3602. // Must loop forwards since it will otherwise remove all brs in <p>a<br><br><br></p>
  3603. for (i = 0; i < l; i++) {
  3604. node = nodes[i];
  3605. parent = node.parent;
  3606. if (blockElements[node.parent.name] && node === parent.lastChild) {
  3607. // Loop all nodes to the left of the current node and check for other BR elements
  3608. // excluding bookmarks since they are invisible
  3609. prev = node.prev;
  3610. while (prev) {
  3611. prevName = prev.name;
  3612. // Ignore bookmarks
  3613. if (prevName !== "span" || prev.attr('data-mce-type') !== 'bookmark') {
  3614. // Found a non BR element
  3615. if (prevName !== "br")
  3616. break;
  3617. // Found another br it's a <br><br> structure then don't remove anything
  3618. if (prevName === 'br') {
  3619. node = null;
  3620. break;
  3621. }
  3622. }
  3623. prev = prev.prev;
  3624. }
  3625. if (node) {
  3626. node.remove();
  3627. // Is the parent to be considered empty after we removed the BR
  3628. if (parent.isEmpty(nonEmptyElements)) {
  3629. elementRule = schema.getElementRule(parent.name);
  3630. // Remove or padd the element depending on schema rule
  3631. if (elementRule) {
  3632. if (elementRule.removeEmpty)
  3633. parent.remove();
  3634. else if (elementRule.paddEmpty)
  3635. parent.empty().append(new tinymce.html.Node('#text', 3)).value = '\u00a0';
  3636. }
  3637. }
  3638. }
  3639. } else {
  3640. // Replaces BR elements inside inline elements like <p><b><i><br></i></b></p> so they become <p><b><i>&nbsp;</i></b></p>
  3641. lastParent = node;
  3642. while (parent.firstChild === lastParent && parent.lastChild === lastParent) {
  3643. lastParent = parent;
  3644. if (blockElements[parent.name]) {
  3645. break;
  3646. }
  3647. parent = parent.parent;
  3648. }
  3649. if (lastParent === parent) {
  3650. textNode = new tinymce.html.Node('#text', 3);
  3651. textNode.value = '\u00a0';
  3652. node.replace(textNode);
  3653. }
  3654. }
  3655. }
  3656. });
  3657. }
  3658. // Force anchor names closed, unless the setting "allow_html_in_named_anchor" is explicitly included.
  3659. if (!settings.allow_html_in_named_anchor) {
  3660. self.addAttributeFilter('id,name', function(nodes, name) {
  3661. var i = nodes.length, sibling, prevSibling, parent, node;
  3662. while (i--) {
  3663. node = nodes[i];
  3664. if (node.name === 'a' && node.firstChild && !node.attr('href')) {
  3665. parent = node.parent;
  3666. // Move children after current node
  3667. sibling = node.lastChild;
  3668. do {
  3669. prevSibling = sibling.prev;
  3670. parent.insert(sibling, node);
  3671. sibling = prevSibling;
  3672. } while (sibling);
  3673. }
  3674. }
  3675. });
  3676. }
  3677. }
  3678. })(tinymce);
  3679. tinymce.html.Writer = function(settings) {
  3680. var html = [], indent, indentBefore, indentAfter, encode, htmlOutput;
  3681. settings = settings || {};
  3682. indent = settings.indent;
  3683. indentBefore = tinymce.makeMap(settings.indent_before || '');
  3684. indentAfter = tinymce.makeMap(settings.indent_after || '');
  3685. encode = tinymce.html.Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities);
  3686. htmlOutput = settings.element_format == "html";
  3687. return {
  3688. start: function(name, attrs, empty) {
  3689. var i, l, attr, value;
  3690. if (indent && indentBefore[name] && html.length > 0) {
  3691. value = html[html.length - 1];
  3692. if (value.length > 0 && value !== '\n')
  3693. html.push('\n');
  3694. }
  3695. html.push('<', name);
  3696. if (attrs) {
  3697. for (i = 0, l = attrs.length; i < l; i++) {
  3698. attr = attrs[i];
  3699. html.push(' ', attr.name, '="', encode(attr.value, true), '"');
  3700. }
  3701. }
  3702. if (!empty || htmlOutput)
  3703. html[html.length] = '>';
  3704. else
  3705. html[html.length] = ' />';
  3706. if (empty && indent && indentAfter[name] && html.length > 0) {
  3707. value = html[html.length - 1];
  3708. if (value.length > 0 && value !== '\n')
  3709. html.push('\n');
  3710. }
  3711. },
  3712. end: function(name) {
  3713. var value;
  3714. /*if (indent && indentBefore[name] && html.length > 0) {
  3715. value = html[html.length - 1];
  3716. if (value.length > 0 && value !== '\n')
  3717. html.push('\n');
  3718. }*/
  3719. html.push('</', name, '>');
  3720. if (indent && indentAfter[name] && html.length > 0) {
  3721. value = html[html.length - 1];
  3722. if (value.length > 0 && value !== '\n')
  3723. html.push('\n');
  3724. }
  3725. },
  3726. text: function(text, raw) {
  3727. if (text.length > 0)
  3728. html[html.length] = raw ? text : encode(text);
  3729. },
  3730. cdata: function(text) {
  3731. html.push('<![CDATA[', text, ']]>');
  3732. },
  3733. comment: function(text) {
  3734. html.push('<!--', text, '-->');
  3735. },
  3736. pi: function(name, text) {
  3737. if (text)
  3738. html.push('<?', name, ' ', text, '?>');
  3739. else
  3740. html.push('<?', name, '?>');
  3741. if (indent)
  3742. html.push('\n');
  3743. },
  3744. doctype: function(text) {
  3745. html.push('<!DOCTYPE', text, '>', indent ? '\n' : '');
  3746. },
  3747. reset: function() {
  3748. html.length = 0;
  3749. },
  3750. getContent: function() {
  3751. return html.join('').replace(/\n$/, '');
  3752. }
  3753. };
  3754. };
  3755. (function(tinymce) {
  3756. tinymce.html.Serializer = function(settings, schema) {
  3757. var self = this, writer = new tinymce.html.Writer(settings);
  3758. settings = settings || {};
  3759. settings.validate = "validate" in settings ? settings.validate : true;
  3760. self.schema = schema = schema || new tinymce.html.Schema();
  3761. self.writer = writer;
  3762. self.serialize = function(node) {
  3763. var handlers, validate;
  3764. validate = settings.validate;
  3765. handlers = {
  3766. // #text
  3767. 3: function(node, raw) {
  3768. writer.text(node.value, node.raw);
  3769. },
  3770. // #comment
  3771. 8: function(node) {
  3772. writer.comment(node.value);
  3773. },
  3774. // Processing instruction
  3775. 7: function(node) {
  3776. writer.pi(node.name, node.value);
  3777. },
  3778. // Doctype
  3779. 10: function(node) {
  3780. writer.doctype(node.value);
  3781. },
  3782. // CDATA
  3783. 4: function(node) {
  3784. writer.cdata(node.value);
  3785. },
  3786. // Document fragment
  3787. 11: function(node) {
  3788. if ((node = node.firstChild)) {
  3789. do {
  3790. walk(node);
  3791. } while (node = node.next);
  3792. }
  3793. }
  3794. };
  3795. writer.reset();
  3796. function walk(node) {
  3797. var handler = handlers[node.type], name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule;
  3798. if (!handler) {
  3799. name = node.name;
  3800. isEmpty = node.shortEnded;
  3801. attrs = node.attributes;
  3802. // Sort attributes
  3803. if (validate && attrs && attrs.length > 1) {
  3804. sortedAttrs = [];
  3805. sortedAttrs.map = {};
  3806. elementRule = schema.getElementRule(node.name);
  3807. for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
  3808. attrName = elementRule.attributesOrder[i];
  3809. if (attrName in attrs.map) {
  3810. attrValue = attrs.map[attrName];
  3811. sortedAttrs.map[attrName] = attrValue;
  3812. sortedAttrs.push({name: attrName, value: attrValue});
  3813. }
  3814. }
  3815. for (i = 0, l = attrs.length; i < l; i++) {
  3816. attrName = attrs[i].name;
  3817. if (!(attrName in sortedAttrs.map)) {
  3818. attrValue = attrs.map[attrName];
  3819. sortedAttrs.map[attrName] = attrValue;
  3820. sortedAttrs.push({name: attrName, value: attrValue});
  3821. }
  3822. }
  3823. attrs = sortedAttrs;
  3824. }
  3825. writer.start(node.name, attrs, isEmpty);
  3826. if (!isEmpty) {
  3827. if ((node = node.firstChild)) {
  3828. do {
  3829. walk(node);
  3830. } while (node = node.next);
  3831. }
  3832. writer.end(name);
  3833. }
  3834. } else
  3835. handler(node);
  3836. }
  3837. // Serialize element and treat all non elements as fragments
  3838. if (node.type == 1 && !settings.inner)
  3839. walk(node);
  3840. else
  3841. handlers[11](node);
  3842. return writer.getContent();
  3843. };
  3844. }
  3845. })(tinymce);
  3846. // JSLint defined globals
  3847. /*global tinymce:false, window:false */
  3848. tinymce.dom = {};
  3849. (function(namespace, expando) {
  3850. var w3cEventModel = !!document.addEventListener;
  3851. function addEvent(target, name, callback, capture) {
  3852. if (target.addEventListener) {
  3853. target.addEventListener(name, callback, capture || false);
  3854. } else if (target.attachEvent) {
  3855. target.attachEvent('on' + name, callback);
  3856. }
  3857. }
  3858. function removeEvent(target, name, callback, capture) {
  3859. if (target.removeEventListener) {
  3860. target.removeEventListener(name, callback, capture || false);
  3861. } else if (target.detachEvent) {
  3862. target.detachEvent('on' + name, callback);
  3863. }
  3864. }
  3865. function fix(original_event, data) {
  3866. var name, event = data || {};
  3867. // Dummy function that gets replaced on the delegation state functions
  3868. function returnFalse() {
  3869. return false;
  3870. }
  3871. // Dummy function that gets replaced on the delegation state functions
  3872. function returnTrue() {
  3873. return true;
  3874. }
  3875. // Copy all properties from the original event
  3876. for (name in original_event) {
  3877. // layerX/layerY is deprecated in Chrome and produces a warning
  3878. if (name !== "layerX" && name !== "layerY") {
  3879. event[name] = original_event[name];
  3880. }
  3881. }
  3882. // Normalize target IE uses srcElement
  3883. if (!event.target) {
  3884. event.target = event.srcElement || document;
  3885. }
  3886. // Add preventDefault method
  3887. event.preventDefault = function() {
  3888. event.isDefaultPrevented = returnTrue;
  3889. // Execute preventDefault on the original event object
  3890. if (original_event) {
  3891. if (original_event.preventDefault) {
  3892. original_event.preventDefault();
  3893. } else {
  3894. original_event.returnValue = false; // IE
  3895. }
  3896. }
  3897. };
  3898. // Add stopPropagation
  3899. event.stopPropagation = function() {
  3900. event.isPropagationStopped = returnTrue;
  3901. // Execute stopPropagation on the original event object
  3902. if (original_event) {
  3903. if (original_event.stopPropagation) {
  3904. original_event.stopPropagation();
  3905. } else {
  3906. original_event.cancelBubble = true; // IE
  3907. }
  3908. }
  3909. };
  3910. // Add stopImmediatePropagation
  3911. event.stopImmediatePropagation = function() {
  3912. event.isImmediatePropagationStopped = returnTrue;
  3913. event.stopPropagation();
  3914. };
  3915. // Add event delegation states
  3916. if (!event.isDefaultPrevented) {
  3917. event.isDefaultPrevented = returnFalse;
  3918. event.isPropagationStopped = returnFalse;
  3919. event.isImmediatePropagationStopped = returnFalse;
  3920. }
  3921. return event;
  3922. }
  3923. function bindOnReady(win, callback, event_utils) {
  3924. var doc = win.document, event = {type: 'ready'};
  3925. // Gets called when the DOM is ready
  3926. function readyHandler() {
  3927. if (!event_utils.domLoaded) {
  3928. event_utils.domLoaded = true;
  3929. callback(event);
  3930. }
  3931. }
  3932. // Page already loaded then fire it directly
  3933. if (doc.readyState == "complete") {
  3934. readyHandler();
  3935. return;
  3936. }
  3937. // Use W3C method
  3938. if (w3cEventModel) {
  3939. addEvent(win, 'DOMContentLoaded', readyHandler);
  3940. } else {
  3941. // Use IE method
  3942. addEvent(doc, "readystatechange", function() {
  3943. if (doc.readyState === "complete") {
  3944. removeEvent(doc, "readystatechange", arguments.callee);
  3945. readyHandler();
  3946. }
  3947. });
  3948. // Wait until we can scroll, when we can the DOM is initialized
  3949. if (doc.documentElement.doScroll && win === win.top) {
  3950. (function() {
  3951. try {
  3952. // If IE is used, use the trick by Diego Perini licensed under MIT by request to the author.
  3953. // http://javascript.nwbox.com/IEContentLoaded/
  3954. doc.documentElement.doScroll("left");
  3955. } catch (ex) {
  3956. setTimeout(arguments.callee, 0);
  3957. return;
  3958. }
  3959. readyHandler();
  3960. })();
  3961. }
  3962. }
  3963. // Fallback if any of the above methods should fail for some odd reason
  3964. addEvent(win, 'load', readyHandler);
  3965. }
  3966. function EventUtils(proxy) {
  3967. var self = this, events = {}, count, isFocusBlurBound, hasFocusIn, hasMouseEnterLeave, mouseEnterLeave;
  3968. hasMouseEnterLeave = "onmouseenter" in document.documentElement;
  3969. hasFocusIn = "onfocusin" in document.documentElement;
  3970. mouseEnterLeave = {mouseenter: 'mouseover', mouseleave: 'mouseout'};
  3971. count = 1;
  3972. // State if the DOMContentLoaded was executed or not
  3973. self.domLoaded = false;
  3974. self.events = events;
  3975. function executeHandlers(evt, id) {
  3976. var callbackList, i, l, callback;
  3977. callbackList = events[id][evt.type];
  3978. if (callbackList) {
  3979. for (i = 0, l = callbackList.length; i < l; i++) {
  3980. callback = callbackList[i];
  3981. // Check if callback exists might be removed if a unbind is called inside the callback
  3982. if (callback && callback.func.call(callback.scope, evt) === false) {
  3983. evt.preventDefault();
  3984. }
  3985. // Should we stop propagation to immediate listeners
  3986. if (evt.isImmediatePropagationStopped()) {
  3987. return;
  3988. }
  3989. }
  3990. }
  3991. }
  3992. self.bind = function(target, names, callback, scope) {
  3993. var id, callbackList, i, name, fakeName, nativeHandler, capture, win = window;
  3994. // Native event handler function patches the event and executes the callbacks for the expando
  3995. function defaultNativeHandler(evt) {
  3996. executeHandlers(fix(evt || win.event), id);
  3997. }
  3998. // Don't bind to text nodes or comments
  3999. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4000. return;
  4001. }
  4002. // Create or get events id for the target
  4003. if (!target[expando]) {
  4004. id = count++;
  4005. target[expando] = id;
  4006. events[id] = {};
  4007. } else {
  4008. id = target[expando];
  4009. if (!events[id]) {
  4010. events[id] = {};
  4011. }
  4012. }
  4013. // Setup the specified scope or use the target as a default
  4014. scope = scope || target;
  4015. // Split names and bind each event, enables you to bind multiple events with one call
  4016. names = names.split(' ');
  4017. i = names.length;
  4018. while (i--) {
  4019. name = names[i];
  4020. nativeHandler = defaultNativeHandler;
  4021. fakeName = capture = false;
  4022. // Use ready instead of DOMContentLoaded
  4023. if (name === "DOMContentLoaded") {
  4024. name = "ready";
  4025. }
  4026. // DOM is already ready
  4027. if ((self.domLoaded || target.readyState == 'complete') && name === "ready") {
  4028. self.domLoaded = true;
  4029. callback.call(scope, fix({type: name}));
  4030. continue;
  4031. }
  4032. // Handle mouseenter/mouseleaver
  4033. if (!hasMouseEnterLeave) {
  4034. fakeName = mouseEnterLeave[name];
  4035. if (fakeName) {
  4036. nativeHandler = function(evt) {
  4037. var current, related;
  4038. current = evt.currentTarget;
  4039. related = evt.relatedTarget;
  4040. // 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
  4041. if (related && current.contains) {
  4042. // Use contains for performance
  4043. related = current.contains(related);
  4044. } else {
  4045. while (related && related !== current) {
  4046. related = related.parentNode;
  4047. }
  4048. }
  4049. // Fire fake event
  4050. if (!related) {
  4051. evt = fix(evt || win.event);
  4052. evt.type = evt.type === 'mouseout' ? 'mouseleave' : 'mouseenter';
  4053. evt.target = current;
  4054. executeHandlers(evt, id);
  4055. }
  4056. };
  4057. }
  4058. }
  4059. // Fake bubbeling of focusin/focusout
  4060. if (!hasFocusIn && (name === "focusin" || name === "focusout")) {
  4061. capture = true;
  4062. fakeName = name === "focusin" ? "focus" : "blur";
  4063. nativeHandler = function(evt) {
  4064. evt = fix(evt || win.event);
  4065. evt.type = evt.type === 'focus' ? 'focusin' : 'focusout';
  4066. executeHandlers(evt, id);
  4067. };
  4068. }
  4069. // Setup callback list and bind native event
  4070. callbackList = events[id][name];
  4071. if (!callbackList) {
  4072. events[id][name] = callbackList = [{func: callback, scope: scope}];
  4073. callbackList.fakeName = fakeName;
  4074. callbackList.capture = capture;
  4075. // Add the nativeHandler to the callback list so that we can later unbind it
  4076. callbackList.nativeHandler = nativeHandler;
  4077. if (!w3cEventModel) {
  4078. callbackList.proxyHandler = proxy(id);
  4079. }
  4080. // Check if the target has native events support
  4081. if (name === "ready") {
  4082. bindOnReady(target, nativeHandler, self);
  4083. } else {
  4084. addEvent(target, fakeName || name, w3cEventModel ? nativeHandler : callbackList.proxyHandler, capture);
  4085. }
  4086. } else {
  4087. // If it already has an native handler then just push the callback
  4088. callbackList.push({func: callback, scope: scope});
  4089. }
  4090. }
  4091. target = callbackList = 0; // Clean memory for IE
  4092. return callback;
  4093. };
  4094. self.unbind = function(target, names, callback) {
  4095. var id, callbackList, i, ci, name, eventMap;
  4096. // Don't bind to text nodes or comments
  4097. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4098. return self;
  4099. }
  4100. // Unbind event or events if the target has the expando
  4101. id = target[expando];
  4102. if (id) {
  4103. eventMap = events[id];
  4104. // Specific callback
  4105. if (names) {
  4106. names = names.split(' ');
  4107. i = names.length;
  4108. while (i--) {
  4109. name = names[i];
  4110. callbackList = eventMap[name];
  4111. // Unbind the event if it exists in the map
  4112. if (callbackList) {
  4113. // Remove specified callback
  4114. if (callback) {
  4115. ci = callbackList.length;
  4116. while (ci--) {
  4117. if (callbackList[ci].func === callback) {
  4118. callbackList.splice(ci, 1);
  4119. }
  4120. }
  4121. }
  4122. // Remove all callbacks if there isn't a specified callback or there is no callbacks left
  4123. if (!callback || callbackList.length === 0) {
  4124. delete eventMap[name];
  4125. removeEvent(target, callbackList.fakeName || name, w3cEventModel ? callbackList.nativeHandler : callbackList.proxyHandler, callbackList.capture);
  4126. }
  4127. }
  4128. }
  4129. } else {
  4130. // All events for a specific element
  4131. for (name in eventMap) {
  4132. callbackList = eventMap[name];
  4133. removeEvent(target, callbackList.fakeName || name, w3cEventModel ? callbackList.nativeHandler : callbackList.proxyHandler, callbackList.capture);
  4134. }
  4135. eventMap = {};
  4136. }
  4137. // Check if object is empty, if it isn't then we won't remove the expando map
  4138. for (name in eventMap) {
  4139. return self;
  4140. }
  4141. // Delete event object
  4142. delete events[id];
  4143. // Remove expando from target
  4144. try {
  4145. // IE will fail here since it can't delete properties from window
  4146. delete target[expando];
  4147. } catch (ex) {
  4148. // IE will set it to null
  4149. target[expando] = null;
  4150. }
  4151. }
  4152. return self;
  4153. };
  4154. self.fire = function(target, name, args) {
  4155. var id, event;
  4156. // Don't bind to text nodes or comments
  4157. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4158. return self;
  4159. }
  4160. // Build event object by patching the args
  4161. event = fix(null, args);
  4162. event.type = name;
  4163. do {
  4164. // Found an expando that means there is listeners to execute
  4165. id = target[expando];
  4166. if (id) {
  4167. executeHandlers(event, id);
  4168. }
  4169. // Walk up the DOM
  4170. target = target.parentNode || target.ownerDocument || target.defaultView || target.parentWindow;
  4171. } while (target && !event.isPropagationStopped());
  4172. return self;
  4173. };
  4174. self.clean = function(target) {
  4175. var i, children, unbind = self.unbind;
  4176. // Don't bind to text nodes or comments
  4177. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4178. return self;
  4179. }
  4180. // Unbind any element on the specificed target
  4181. if (target[expando]) {
  4182. unbind(target);
  4183. }
  4184. // Target doesn't have getElementsByTagName it's probably a window object then use it's document to find the children
  4185. if (!target.getElementsByTagName) {
  4186. target = target.document;
  4187. }
  4188. // Remove events from each child element
  4189. if (target && target.getElementsByTagName) {
  4190. unbind(target);
  4191. children = target.getElementsByTagName('*');
  4192. i = children.length;
  4193. while (i--) {
  4194. target = children[i];
  4195. if (target[expando]) {
  4196. unbind(target);
  4197. }
  4198. }
  4199. }
  4200. return self;
  4201. };
  4202. self.callNativeHandler = function(id, evt) {
  4203. if (events) {
  4204. events[id][evt.type].nativeHandler(evt);
  4205. }
  4206. };
  4207. self.destory = function() {
  4208. events = {};
  4209. };
  4210. // Legacy function calls
  4211. self.add = function(target, events, func, scope) {
  4212. // Old API supported direct ID assignment
  4213. if (typeof(target) === "string") {
  4214. target = document.getElementById(target);
  4215. }
  4216. // Old API supported multiple targets
  4217. if (target && target instanceof Array) {
  4218. var i = target.length;
  4219. while (i--) {
  4220. self.add(target[i], events, func, scope);
  4221. }
  4222. return;
  4223. }
  4224. // Old API called ready init
  4225. if (events === "init") {
  4226. events = "ready";
  4227. }
  4228. return self.bind(target, events instanceof Array ? events.join(' ') : events, func, scope);
  4229. };
  4230. self.remove = function(target, events, func, scope) {
  4231. if (!target) {
  4232. return self;
  4233. }
  4234. // Old API supported direct ID assignment
  4235. if (typeof(target) === "string") {
  4236. target = document.getElementById(target);
  4237. }
  4238. // Old API supported multiple targets
  4239. if (target instanceof Array) {
  4240. var i = target.length;
  4241. while (i--) {
  4242. self.remove(target[i], events, func, scope);
  4243. }
  4244. return self;
  4245. }
  4246. return self.unbind(target, events instanceof Array ? events.join(' ') : events, func);
  4247. };
  4248. self.clear = function(target) {
  4249. // Old API supported direct ID assignment
  4250. if (typeof(target) === "string") {
  4251. target = document.getElementById(target);
  4252. }
  4253. return self.clean(target);
  4254. };
  4255. self.cancel = function(e) {
  4256. if (e) {
  4257. self.prevent(e);
  4258. self.stop(e);
  4259. }
  4260. return false;
  4261. };
  4262. self.prevent = function(e) {
  4263. if (!e.preventDefault) {
  4264. e = fix(e);
  4265. }
  4266. e.preventDefault();
  4267. return false;
  4268. };
  4269. self.stop = function(e) {
  4270. if (!e.stopPropagation) {
  4271. e = fix(e);
  4272. }
  4273. e.stopPropagation();
  4274. return false;
  4275. };
  4276. }
  4277. namespace.EventUtils = EventUtils;
  4278. namespace.Event = new EventUtils(function(id) {
  4279. return function(evt) {
  4280. tinymce.dom.Event.callNativeHandler(id, evt);
  4281. };
  4282. });
  4283. // Bind ready event when tinymce script is loaded
  4284. namespace.Event.bind(window, 'ready', function() {});
  4285. namespace = 0;
  4286. })(tinymce.dom, 'data-mce-expando'); // Namespace and expando
  4287. tinymce.dom.TreeWalker = function(start_node, root_node) {
  4288. var node = start_node;
  4289. function findSibling(node, start_name, sibling_name, shallow) {
  4290. var sibling, parent;
  4291. if (node) {
  4292. // Walk into nodes if it has a start
  4293. if (!shallow && node[start_name])
  4294. return node[start_name];
  4295. // Return the sibling if it has one
  4296. if (node != root_node) {
  4297. sibling = node[sibling_name];
  4298. if (sibling)
  4299. return sibling;
  4300. // Walk up the parents to look for siblings
  4301. for (parent = node.parentNode; parent && parent != root_node; parent = parent.parentNode) {
  4302. sibling = parent[sibling_name];
  4303. if (sibling)
  4304. return sibling;
  4305. }
  4306. }
  4307. }
  4308. };
  4309. this.current = function() {
  4310. return node;
  4311. };
  4312. this.next = function(shallow) {
  4313. return (node = findSibling(node, 'firstChild', 'nextSibling', shallow));
  4314. };
  4315. this.prev = function(shallow) {
  4316. return (node = findSibling(node, 'lastChild', 'previousSibling', shallow));
  4317. };
  4318. };
  4319. (function(tinymce) {
  4320. // Shorten names
  4321. var each = tinymce.each,
  4322. is = tinymce.is,
  4323. isWebKit = tinymce.isWebKit,
  4324. isIE = tinymce.isIE,
  4325. Entities = tinymce.html.Entities,
  4326. simpleSelectorRe = /^([a-z0-9],?)+$/i,
  4327. whiteSpaceRegExp = /^[ \t\r\n]*$/;
  4328. tinymce.create('tinymce.dom.DOMUtils', {
  4329. doc : null,
  4330. root : null,
  4331. files : null,
  4332. pixelStyles : /^(top|left|bottom|right|width|height|borderWidth)$/,
  4333. props : {
  4334. "for" : "htmlFor",
  4335. "class" : "className",
  4336. className : "className",
  4337. checked : "checked",
  4338. disabled : "disabled",
  4339. maxlength : "maxLength",
  4340. readonly : "readOnly",
  4341. selected : "selected",
  4342. value : "value",
  4343. id : "id",
  4344. name : "name",
  4345. type : "type"
  4346. },
  4347. DOMUtils : function(d, s) {
  4348. var t = this, globalStyle, name, blockElementsMap;
  4349. t.doc = d;
  4350. t.win = window;
  4351. t.files = {};
  4352. t.cssFlicker = false;
  4353. t.counter = 0;
  4354. t.stdMode = !tinymce.isIE || d.documentMode >= 8;
  4355. t.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat" || t.stdMode;
  4356. t.hasOuterHTML = "outerHTML" in d.createElement("a");
  4357. t.settings = s = tinymce.extend({
  4358. keep_values : false,
  4359. hex_colors : 1
  4360. }, s);
  4361. t.schema = s.schema;
  4362. t.styles = new tinymce.html.Styles({
  4363. url_converter : s.url_converter,
  4364. url_converter_scope : s.url_converter_scope
  4365. }, s.schema);
  4366. // Fix IE6SP2 flicker and check it failed for pre SP2
  4367. if (tinymce.isIE6) {
  4368. try {
  4369. d.execCommand('BackgroundImageCache', false, true);
  4370. } catch (e) {
  4371. t.cssFlicker = true;
  4372. }
  4373. }
  4374. t.fixDoc(d);
  4375. t.events = s.ownEvents ? new tinymce.dom.EventUtils(s.proxy) : tinymce.dom.Event;
  4376. tinymce.addUnload(t.destroy, t);
  4377. blockElementsMap = s.schema ? s.schema.getBlockElements() : {};
  4378. t.isBlock = function(node) {
  4379. // This function is called in module pattern style since it might be executed with the wrong this scope
  4380. var type = node.nodeType;
  4381. // If it's a node then check the type and use the nodeName
  4382. if (type)
  4383. return !!(type === 1 && blockElementsMap[node.nodeName]);
  4384. return !!blockElementsMap[node];
  4385. };
  4386. },
  4387. fixDoc: function(doc) {
  4388. var settings = this.settings, name;
  4389. if (isIE && settings.schema) {
  4390. // Add missing HTML 4/5 elements to IE
  4391. ('abbr article aside audio canvas ' +
  4392. 'details figcaption figure footer ' +
  4393. 'header hgroup mark menu meter nav ' +
  4394. 'output progress section summary ' +
  4395. 'time video').replace(/\w+/g, function(name) {
  4396. doc.createElement(name);
  4397. });
  4398. // Create all custom elements
  4399. for (name in settings.schema.getCustomElements()) {
  4400. doc.createElement(name);
  4401. }
  4402. }
  4403. },
  4404. clone: function(node, deep) {
  4405. var self = this, clone, doc;
  4406. // TODO: Add feature detection here in the future
  4407. if (!isIE || node.nodeType !== 1 || deep) {
  4408. return node.cloneNode(deep);
  4409. }
  4410. doc = self.doc;
  4411. // Make a HTML5 safe shallow copy
  4412. if (!deep) {
  4413. clone = doc.createElement(node.nodeName);
  4414. // Copy attribs
  4415. each(self.getAttribs(node), function(attr) {
  4416. self.setAttrib(clone, attr.nodeName, self.getAttrib(node, attr.nodeName));
  4417. });
  4418. return clone;
  4419. }
  4420. /*
  4421. // Setup HTML5 patched document fragment
  4422. if (!self.frag) {
  4423. self.frag = doc.createDocumentFragment();
  4424. self.fixDoc(self.frag);
  4425. }
  4426. // Make a deep copy by adding it to the document fragment then removing it this removed the :section
  4427. clone = doc.createElement('div');
  4428. self.frag.appendChild(clone);
  4429. clone.innerHTML = node.outerHTML;
  4430. self.frag.removeChild(clone);
  4431. */
  4432. return clone.firstChild;
  4433. },
  4434. getRoot : function() {
  4435. var t = this, s = t.settings;
  4436. return (s && t.get(s.root_element)) || t.doc.body;
  4437. },
  4438. getViewPort : function(w) {
  4439. var d, b;
  4440. w = !w ? this.win : w;
  4441. d = w.document;
  4442. b = this.boxModel ? d.documentElement : d.body;
  4443. // Returns viewport size excluding scrollbars
  4444. return {
  4445. x : w.pageXOffset || b.scrollLeft,
  4446. y : w.pageYOffset || b.scrollTop,
  4447. w : w.innerWidth || b.clientWidth,
  4448. h : w.innerHeight || b.clientHeight
  4449. };
  4450. },
  4451. getRect : function(e) {
  4452. var p, t = this, sr;
  4453. e = t.get(e);
  4454. p = t.getPos(e);
  4455. sr = t.getSize(e);
  4456. return {
  4457. x : p.x,
  4458. y : p.y,
  4459. w : sr.w,
  4460. h : sr.h
  4461. };
  4462. },
  4463. getSize : function(e) {
  4464. var t = this, w, h;
  4465. e = t.get(e);
  4466. w = t.getStyle(e, 'width');
  4467. h = t.getStyle(e, 'height');
  4468. // Non pixel value, then force offset/clientWidth
  4469. if (w.indexOf('px') === -1)
  4470. w = 0;
  4471. // Non pixel value, then force offset/clientWidth
  4472. if (h.indexOf('px') === -1)
  4473. h = 0;
  4474. return {
  4475. w : parseInt(w, 10) || e.offsetWidth || e.clientWidth,
  4476. h : parseInt(h, 10) || e.offsetHeight || e.clientHeight
  4477. };
  4478. },
  4479. getParent : function(n, f, r) {
  4480. return this.getParents(n, f, r, false);
  4481. },
  4482. getParents : function(n, f, r, c) {
  4483. var t = this, na, se = t.settings, o = [];
  4484. n = t.get(n);
  4485. c = c === undefined;
  4486. if (se.strict_root)
  4487. r = r || t.getRoot();
  4488. // Wrap node name as func
  4489. if (is(f, 'string')) {
  4490. na = f;
  4491. if (f === '*') {
  4492. f = function(n) {return n.nodeType == 1;};
  4493. } else {
  4494. f = function(n) {
  4495. return t.is(n, na);
  4496. };
  4497. }
  4498. }
  4499. while (n) {
  4500. if (n == r || !n.nodeType || n.nodeType === 9)
  4501. break;
  4502. if (!f || f(n)) {
  4503. if (c)
  4504. o.push(n);
  4505. else
  4506. return n;
  4507. }
  4508. n = n.parentNode;
  4509. }
  4510. return c ? o : null;
  4511. },
  4512. get : function(e) {
  4513. var n;
  4514. if (e && this.doc && typeof(e) == 'string') {
  4515. n = e;
  4516. e = this.doc.getElementById(e);
  4517. // IE and Opera returns meta elements when they match the specified input ID, but getElementsByName seems to do the trick
  4518. if (e && e.id !== n)
  4519. return this.doc.getElementsByName(n)[1];
  4520. }
  4521. return e;
  4522. },
  4523. getNext : function(node, selector) {
  4524. return this._findSib(node, selector, 'nextSibling');
  4525. },
  4526. getPrev : function(node, selector) {
  4527. return this._findSib(node, selector, 'previousSibling');
  4528. },
  4529. add : function(p, n, a, h, c) {
  4530. var t = this;
  4531. return this.run(p, function(p) {
  4532. var e, k;
  4533. e = is(n, 'string') ? t.doc.createElement(n) : n;
  4534. t.setAttribs(e, a);
  4535. if (h) {
  4536. if (h.nodeType)
  4537. e.appendChild(h);
  4538. else
  4539. t.setHTML(e, h);
  4540. }
  4541. return !c ? p.appendChild(e) : e;
  4542. });
  4543. },
  4544. create : function(n, a, h) {
  4545. return this.add(this.doc.createElement(n), n, a, h, 1);
  4546. },
  4547. createHTML : function(n, a, h) {
  4548. var o = '', t = this, k;
  4549. o += '<' + n;
  4550. for (k in a) {
  4551. if (a.hasOwnProperty(k))
  4552. o += ' ' + k + '="' + t.encode(a[k]) + '"';
  4553. }
  4554. // A call to tinymce.is doesn't work for some odd reason on IE9 possible bug inside their JS runtime
  4555. if (typeof(h) != "undefined")
  4556. return o + '>' + h + '</' + n + '>';
  4557. return o + ' />';
  4558. },
  4559. remove : function(node, keep_children) {
  4560. return this.run(node, function(node) {
  4561. var child, parent = node.parentNode;
  4562. if (!parent)
  4563. return null;
  4564. if (keep_children) {
  4565. while (child = node.firstChild) {
  4566. // IE 8 will crash if you don't remove completely empty text nodes
  4567. if (!tinymce.isIE || child.nodeType !== 3 || child.nodeValue)
  4568. parent.insertBefore(child, node);
  4569. else
  4570. node.removeChild(child);
  4571. }
  4572. }
  4573. return parent.removeChild(node);
  4574. });
  4575. },
  4576. setStyle : function(n, na, v) {
  4577. var t = this;
  4578. return t.run(n, function(e) {
  4579. var s, i;
  4580. s = e.style;
  4581. // Camelcase it, if needed
  4582. na = na.replace(/-(\D)/g, function(a, b){
  4583. return b.toUpperCase();
  4584. });
  4585. // Default px suffix on these
  4586. if (t.pixelStyles.test(na) && (tinymce.is(v, 'number') || /^[\-0-9\.]+$/.test(v)))
  4587. v += 'px';
  4588. switch (na) {
  4589. case 'opacity':
  4590. // IE specific opacity
  4591. if (isIE) {
  4592. s.filter = v === '' ? '' : "alpha(opacity=" + (v * 100) + ")";
  4593. if (!n.currentStyle || !n.currentStyle.hasLayout)
  4594. s.display = 'inline-block';
  4595. }
  4596. // Fix for older browsers
  4597. s[na] = s['-moz-opacity'] = s['-khtml-opacity'] = v || '';
  4598. break;
  4599. case 'float':
  4600. isIE ? s.styleFloat = v : s.cssFloat = v;
  4601. break;
  4602. default:
  4603. s[na] = v || '';
  4604. }
  4605. // Force update of the style data
  4606. if (t.settings.update_styles)
  4607. t.setAttrib(e, 'data-mce-style');
  4608. });
  4609. },
  4610. getStyle : function(n, na, c) {
  4611. n = this.get(n);
  4612. if (!n)
  4613. return;
  4614. // Gecko
  4615. if (this.doc.defaultView && c) {
  4616. // Remove camelcase
  4617. na = na.replace(/[A-Z]/g, function(a){
  4618. return '-' + a;
  4619. });
  4620. try {
  4621. return this.doc.defaultView.getComputedStyle(n, null).getPropertyValue(na);
  4622. } catch (ex) {
  4623. // Old safari might fail
  4624. return null;
  4625. }
  4626. }
  4627. // Camelcase it, if needed
  4628. na = na.replace(/-(\D)/g, function(a, b){
  4629. return b.toUpperCase();
  4630. });
  4631. if (na == 'float')
  4632. na = isIE ? 'styleFloat' : 'cssFloat';
  4633. // IE & Opera
  4634. if (n.currentStyle && c)
  4635. return n.currentStyle[na];
  4636. return n.style ? n.style[na] : undefined;
  4637. },
  4638. setStyles : function(e, o) {
  4639. var t = this, s = t.settings, ol;
  4640. ol = s.update_styles;
  4641. s.update_styles = 0;
  4642. each(o, function(v, n) {
  4643. t.setStyle(e, n, v);
  4644. });
  4645. // Update style info
  4646. s.update_styles = ol;
  4647. if (s.update_styles)
  4648. t.setAttrib(e, s.cssText);
  4649. },
  4650. removeAllAttribs: function(e) {
  4651. return this.run(e, function(e) {
  4652. var i, attrs = e.attributes;
  4653. for (i = attrs.length - 1; i >= 0; i--) {
  4654. e.removeAttributeNode(attrs.item(i));
  4655. }
  4656. });
  4657. },
  4658. setAttrib : function(e, n, v) {
  4659. var t = this;
  4660. // Whats the point
  4661. if (!e || !n)
  4662. return;
  4663. // Strict XML mode
  4664. if (t.settings.strict)
  4665. n = n.toLowerCase();
  4666. return this.run(e, function(e) {
  4667. var s = t.settings;
  4668. var originalValue = e.getAttribute(n);
  4669. if (v !== null) {
  4670. switch (n) {
  4671. case "style":
  4672. if (!is(v, 'string')) {
  4673. each(v, function(v, n) {
  4674. t.setStyle(e, n, v);
  4675. });
  4676. return;
  4677. }
  4678. // No mce_style for elements with these since they might get resized by the user
  4679. if (s.keep_values) {
  4680. if (v && !t._isRes(v))
  4681. e.setAttribute('data-mce-style', v, 2);
  4682. else
  4683. e.removeAttribute('data-mce-style', 2);
  4684. }
  4685. e.style.cssText = v;
  4686. break;
  4687. case "class":
  4688. e.className = v || ''; // Fix IE null bug
  4689. break;
  4690. case "src":
  4691. case "href":
  4692. if (s.keep_values) {
  4693. if (s.url_converter)
  4694. v = s.url_converter.call(s.url_converter_scope || t, v, n, e);
  4695. t.setAttrib(e, 'data-mce-' + n, v, 2);
  4696. }
  4697. break;
  4698. case "shape":
  4699. e.setAttribute('data-mce-style', v);
  4700. break;
  4701. }
  4702. }
  4703. if (is(v) && v !== null && v.length !== 0)
  4704. e.setAttribute(n, '' + v, 2);
  4705. else
  4706. e.removeAttribute(n, 2);
  4707. // fire onChangeAttrib event for attributes that have changed
  4708. if (tinyMCE.activeEditor && originalValue != v) {
  4709. var ed = tinyMCE.activeEditor;
  4710. ed.onSetAttrib.dispatch(ed, e, n, v);
  4711. }
  4712. });
  4713. },
  4714. setAttribs : function(e, o) {
  4715. var t = this;
  4716. return this.run(e, function(e) {
  4717. each(o, function(v, n) {
  4718. t.setAttrib(e, n, v);
  4719. });
  4720. });
  4721. },
  4722. getAttrib : function(e, n, dv) {
  4723. var v, t = this, undef;
  4724. e = t.get(e);
  4725. if (!e || e.nodeType !== 1)
  4726. return dv === undef ? false : dv;
  4727. if (!is(dv))
  4728. dv = '';
  4729. // Try the mce variant for these
  4730. if (/^(src|href|style|coords|shape)$/.test(n)) {
  4731. v = e.getAttribute("data-mce-" + n);
  4732. if (v)
  4733. return v;
  4734. }
  4735. if (isIE && t.props[n]) {
  4736. v = e[t.props[n]];
  4737. v = v && v.nodeValue ? v.nodeValue : v;
  4738. }
  4739. if (!v)
  4740. v = e.getAttribute(n, 2);
  4741. // Check boolean attribs
  4742. if (/^(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)$/.test(n)) {
  4743. if (e[t.props[n]] === true && v === '')
  4744. return n;
  4745. return v ? n : '';
  4746. }
  4747. // Inner input elements will override attributes on form elements
  4748. if (e.nodeName === "FORM" && e.getAttributeNode(n))
  4749. return e.getAttributeNode(n).nodeValue;
  4750. if (n === 'style') {
  4751. v = v || e.style.cssText;
  4752. if (v) {
  4753. v = t.serializeStyle(t.parseStyle(v), e.nodeName);
  4754. if (t.settings.keep_values && !t._isRes(v))
  4755. e.setAttribute('data-mce-style', v);
  4756. }
  4757. }
  4758. // Remove Apple and WebKit stuff
  4759. if (isWebKit && n === "class" && v)
  4760. v = v.replace(/(apple|webkit)\-[a-z\-]+/gi, '');
  4761. // Handle IE issues
  4762. if (isIE) {
  4763. switch (n) {
  4764. case 'rowspan':
  4765. case 'colspan':
  4766. // IE returns 1 as default value
  4767. if (v === 1)
  4768. v = '';
  4769. break;
  4770. case 'size':
  4771. // IE returns +0 as default value for size
  4772. if (v === '+0' || v === 20 || v === 0)
  4773. v = '';
  4774. break;
  4775. case 'width':
  4776. case 'height':
  4777. case 'vspace':
  4778. case 'checked':
  4779. case 'disabled':
  4780. case 'readonly':
  4781. if (v === 0)
  4782. v = '';
  4783. break;
  4784. case 'hspace':
  4785. // IE returns -1 as default value
  4786. if (v === -1)
  4787. v = '';
  4788. break;
  4789. case 'maxlength':
  4790. case 'tabindex':
  4791. // IE returns default value
  4792. if (v === 32768 || v === 2147483647 || v === '32768')
  4793. v = '';
  4794. break;
  4795. case 'multiple':
  4796. case 'compact':
  4797. case 'noshade':
  4798. case 'nowrap':
  4799. if (v === 65535)
  4800. return n;
  4801. return dv;
  4802. case 'shape':
  4803. v = v.toLowerCase();
  4804. break;
  4805. default:
  4806. // IE has odd anonymous function for event attributes
  4807. if (n.indexOf('on') === 0 && v)
  4808. v = tinymce._replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1', '' + v);
  4809. }
  4810. }
  4811. return (v !== undef && v !== null && v !== '') ? '' + v : dv;
  4812. },
  4813. getPos : function(n, ro) {
  4814. var t = this, x = 0, y = 0, e, d = t.doc, r;
  4815. n = t.get(n);
  4816. ro = ro || d.body;
  4817. if (n) {
  4818. // Use getBoundingClientRect if it exists since it's faster than looping offset nodes
  4819. if (n.getBoundingClientRect) {
  4820. n = n.getBoundingClientRect();
  4821. e = t.boxModel ? d.documentElement : d.body;
  4822. // Add scroll offsets from documentElement or body since IE with the wrong box model will use d.body and so do WebKit
  4823. // Also remove the body/documentelement clientTop/clientLeft on IE 6, 7 since they offset the position
  4824. x = n.left + (d.documentElement.scrollLeft || d.body.scrollLeft) - e.clientTop;
  4825. y = n.top + (d.documentElement.scrollTop || d.body.scrollTop) - e.clientLeft;
  4826. return {x : x, y : y};
  4827. }
  4828. r = n;
  4829. while (r && r != ro && r.nodeType) {
  4830. x += r.offsetLeft || 0;
  4831. y += r.offsetTop || 0;
  4832. r = r.offsetParent;
  4833. }
  4834. r = n.parentNode;
  4835. while (r && r != ro && r.nodeType) {
  4836. x -= r.scrollLeft || 0;
  4837. y -= r.scrollTop || 0;
  4838. r = r.parentNode;
  4839. }
  4840. }
  4841. return {x : x, y : y};
  4842. },
  4843. parseStyle : function(st) {
  4844. return this.styles.parse(st);
  4845. },
  4846. serializeStyle : function(o, name) {
  4847. return this.styles.serialize(o, name);
  4848. },
  4849. addStyle: function(cssText) {
  4850. var doc = this.doc, head;
  4851. // Create style element if needed
  4852. styleElm = doc.getElementById('mceDefaultStyles');
  4853. if (!styleElm) {
  4854. styleElm = doc.createElement('style'),
  4855. styleElm.id = 'mceDefaultStyles';
  4856. styleElm.type = 'text/css';
  4857. head = doc.getElementsByTagName('head')[0];
  4858. if (head.firstChild) {
  4859. head.insertBefore(styleElm, head.firstChild);
  4860. } else {
  4861. head.appendChild(styleElm);
  4862. }
  4863. }
  4864. // Append style data to old or new style element
  4865. if (styleElm.styleSheet) {
  4866. styleElm.styleSheet.cssText += cssText;
  4867. } else {
  4868. styleElm.appendChild(doc.createTextNode(cssText));
  4869. }
  4870. },
  4871. loadCSS : function(u) {
  4872. var t = this, d = t.doc, head;
  4873. if (!u)
  4874. u = '';
  4875. head = d.getElementsByTagName('head')[0];
  4876. each(u.split(','), function(u) {
  4877. var link;
  4878. if (t.files[u])
  4879. return;
  4880. t.files[u] = true;
  4881. link = t.create('link', {rel : 'stylesheet', href : tinymce._addVer(u)});
  4882. // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug
  4883. // This fix seems to resolve that issue by realcing the document ones a stylesheet finishes loading
  4884. // It's ugly but it seems to work fine.
  4885. if (isIE && d.documentMode && d.recalc) {
  4886. link.onload = function() {
  4887. if (d.recalc)
  4888. d.recalc();
  4889. link.onload = null;
  4890. };
  4891. }
  4892. head.appendChild(link);
  4893. });
  4894. },
  4895. addClass : function(e, c) {
  4896. return this.run(e, function(e) {
  4897. var o;
  4898. if (!c)
  4899. return 0;
  4900. if (this.hasClass(e, c))
  4901. return e.className;
  4902. o = this.removeClass(e, c);
  4903. return e.className = (o != '' ? (o + ' ') : '') + c;
  4904. });
  4905. },
  4906. removeClass : function(e, c) {
  4907. var t = this, re;
  4908. return t.run(e, function(e) {
  4909. var v;
  4910. if (t.hasClass(e, c)) {
  4911. if (!re)
  4912. re = new RegExp("(^|\\s+)" + c + "(\\s+|$)", "g");
  4913. v = e.className.replace(re, ' ');
  4914. v = tinymce.trim(v != ' ' ? v : '');
  4915. e.className = v;
  4916. // Empty class attr
  4917. if (!v) {
  4918. e.removeAttribute('class');
  4919. e.removeAttribute('className');
  4920. }
  4921. return v;
  4922. }
  4923. return e.className;
  4924. });
  4925. },
  4926. hasClass : function(n, c) {
  4927. n = this.get(n);
  4928. if (!n || !c)
  4929. return false;
  4930. return (' ' + n.className + ' ').indexOf(' ' + c + ' ') !== -1;
  4931. },
  4932. show : function(e) {
  4933. return this.setStyle(e, 'display', 'block');
  4934. },
  4935. hide : function(e) {
  4936. return this.setStyle(e, 'display', 'none');
  4937. },
  4938. isHidden : function(e) {
  4939. e = this.get(e);
  4940. return !e || e.style.display == 'none' || this.getStyle(e, 'display') == 'none';
  4941. },
  4942. uniqueId : function(p) {
  4943. return (!p ? 'mce_' : p) + (this.counter++);
  4944. },
  4945. setHTML : function(element, html) {
  4946. var self = this;
  4947. return self.run(element, function(element) {
  4948. if (isIE) {
  4949. // Remove all child nodes, IE keeps empty text nodes in DOM
  4950. while (element.firstChild)
  4951. element.removeChild(element.firstChild);
  4952. try {
  4953. // IE will remove comments from the beginning
  4954. // unless you padd the contents with something
  4955. element.innerHTML = '<br />' + html;
  4956. element.removeChild(element.firstChild);
  4957. } catch (ex) {
  4958. // 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
  4959. // This seems to fix this problem
  4960. // Create new div with HTML contents and a BR infront to keep comments
  4961. var newElement = self.create('div');
  4962. newElement.innerHTML = '<br />' + html;
  4963. // Add all children from div to target
  4964. each (tinymce.grep(newElement.childNodes), function(node, i) {
  4965. // Skip br element
  4966. if (i && element.canHaveHTML)
  4967. element.appendChild(node);
  4968. });
  4969. }
  4970. } else
  4971. element.innerHTML = html;
  4972. return html;
  4973. });
  4974. },
  4975. getOuterHTML : function(elm) {
  4976. var doc, self = this;
  4977. elm = self.get(elm);
  4978. if (!elm)
  4979. return null;
  4980. if (elm.nodeType === 1 && self.hasOuterHTML)
  4981. return elm.outerHTML;
  4982. doc = (elm.ownerDocument || self.doc).createElement("body");
  4983. doc.appendChild(elm.cloneNode(true));
  4984. return doc.innerHTML;
  4985. },
  4986. setOuterHTML : function(e, h, d) {
  4987. var t = this;
  4988. function setHTML(e, h, d) {
  4989. var n, tp;
  4990. tp = d.createElement("body");
  4991. tp.innerHTML = h;
  4992. n = tp.lastChild;
  4993. while (n) {
  4994. t.insertAfter(n.cloneNode(true), e);
  4995. n = n.previousSibling;
  4996. }
  4997. t.remove(e);
  4998. };
  4999. return this.run(e, function(e) {
  5000. e = t.get(e);
  5001. // Only set HTML on elements
  5002. if (e.nodeType == 1) {
  5003. d = d || e.ownerDocument || t.doc;
  5004. if (isIE) {
  5005. try {
  5006. // Try outerHTML for IE it sometimes produces an unknown runtime error
  5007. if (isIE && e.nodeType == 1)
  5008. e.outerHTML = h;
  5009. else
  5010. setHTML(e, h, d);
  5011. } catch (ex) {
  5012. // Fix for unknown runtime error
  5013. setHTML(e, h, d);
  5014. }
  5015. } else
  5016. setHTML(e, h, d);
  5017. }
  5018. });
  5019. },
  5020. decode : Entities.decode,
  5021. encode : Entities.encodeAllRaw,
  5022. insertAfter : function(node, reference_node) {
  5023. reference_node = this.get(reference_node);
  5024. return this.run(node, function(node) {
  5025. var parent, nextSibling;
  5026. parent = reference_node.parentNode;
  5027. nextSibling = reference_node.nextSibling;
  5028. if (nextSibling)
  5029. parent.insertBefore(node, nextSibling);
  5030. else
  5031. parent.appendChild(node);
  5032. return node;
  5033. });
  5034. },
  5035. replace : function(n, o, k) {
  5036. var t = this;
  5037. if (is(o, 'array'))
  5038. n = n.cloneNode(true);
  5039. return t.run(o, function(o) {
  5040. if (k) {
  5041. each(tinymce.grep(o.childNodes), function(c) {
  5042. n.appendChild(c);
  5043. });
  5044. }
  5045. return o.parentNode.replaceChild(n, o);
  5046. });
  5047. },
  5048. rename : function(elm, name) {
  5049. var t = this, newElm;
  5050. if (elm.nodeName != name.toUpperCase()) {
  5051. // Rename block element
  5052. newElm = t.create(name);
  5053. // Copy attribs to new block
  5054. each(t.getAttribs(elm), function(attr_node) {
  5055. t.setAttrib(newElm, attr_node.nodeName, t.getAttrib(elm, attr_node.nodeName));
  5056. });
  5057. // Replace block
  5058. t.replace(newElm, elm, 1);
  5059. }
  5060. return newElm || elm;
  5061. },
  5062. findCommonAncestor : function(a, b) {
  5063. var ps = a, pe;
  5064. while (ps) {
  5065. pe = b;
  5066. while (pe && ps != pe)
  5067. pe = pe.parentNode;
  5068. if (ps == pe)
  5069. break;
  5070. ps = ps.parentNode;
  5071. }
  5072. if (!ps && a.ownerDocument)
  5073. return a.ownerDocument.documentElement;
  5074. return ps;
  5075. },
  5076. toHex : function(s) {
  5077. var c = /^\s*rgb\s*?\(\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?\)\s*$/i.exec(s);
  5078. function hex(s) {
  5079. s = parseInt(s, 10).toString(16);
  5080. return s.length > 1 ? s : '0' + s; // 0 -> 00
  5081. };
  5082. if (c) {
  5083. s = '#' + hex(c[1]) + hex(c[2]) + hex(c[3]);
  5084. return s;
  5085. }
  5086. return s;
  5087. },
  5088. getClasses : function() {
  5089. var t = this, cl = [], i, lo = {}, f = t.settings.class_filter, ov;
  5090. if (t.classes)
  5091. return t.classes;
  5092. function addClasses(s) {
  5093. // IE style imports
  5094. each(s.imports, function(r) {
  5095. addClasses(r);
  5096. });
  5097. each(s.cssRules || s.rules, function(r) {
  5098. // Real type or fake it on IE
  5099. switch (r.type || 1) {
  5100. // Rule
  5101. case 1:
  5102. if (r.selectorText) {
  5103. each(r.selectorText.split(','), function(v) {
  5104. v = v.replace(/^\s*|\s*$|^\s\./g, "");
  5105. // Is internal or it doesn't contain a class
  5106. if (/\.mce/.test(v) || !/\.[\w\-]+$/.test(v))
  5107. return;
  5108. // Remove everything but class name
  5109. ov = v;
  5110. v = tinymce._replace(/.*\.([a-z0-9_\-]+).*/i, '$1', v);
  5111. // Filter classes
  5112. if (f && !(v = f(v, ov)))
  5113. return;
  5114. if (!lo[v]) {
  5115. cl.push({'class' : v});
  5116. lo[v] = 1;
  5117. }
  5118. });
  5119. }
  5120. break;
  5121. // Import
  5122. case 3:
  5123. addClasses(r.styleSheet);
  5124. break;
  5125. }
  5126. });
  5127. };
  5128. try {
  5129. each(t.doc.styleSheets, addClasses);
  5130. } catch (ex) {
  5131. // Ignore
  5132. }
  5133. if (cl.length > 0)
  5134. t.classes = cl;
  5135. return cl;
  5136. },
  5137. run : function(e, f, s) {
  5138. var t = this, o;
  5139. if (t.doc && typeof(e) === 'string')
  5140. e = t.get(e);
  5141. if (!e)
  5142. return false;
  5143. s = s || this;
  5144. if (!e.nodeType && (e.length || e.length === 0)) {
  5145. o = [];
  5146. each(e, function(e, i) {
  5147. if (e) {
  5148. if (typeof(e) == 'string')
  5149. e = t.doc.getElementById(e);
  5150. o.push(f.call(s, e, i));
  5151. }
  5152. });
  5153. return o;
  5154. }
  5155. return f.call(s, e);
  5156. },
  5157. getAttribs : function(n) {
  5158. var o;
  5159. n = this.get(n);
  5160. if (!n)
  5161. return [];
  5162. if (isIE) {
  5163. o = [];
  5164. // Object will throw exception in IE
  5165. if (n.nodeName == 'OBJECT')
  5166. return n.attributes;
  5167. // IE doesn't keep the selected attribute if you clone option elements
  5168. if (n.nodeName === 'OPTION' && this.getAttrib(n, 'selected'))
  5169. o.push({specified : 1, nodeName : 'selected'});
  5170. // It's crazy that this is faster in IE but it's because it returns all attributes all the time
  5171. n.cloneNode(false).outerHTML.replace(/<\/?[\w:\-]+ ?|=[\"][^\"]+\"|=\'[^\']+\'|=[\w\-]+|>/gi, '').replace(/[\w:\-]+/gi, function(a) {
  5172. o.push({specified : 1, nodeName : a});
  5173. });
  5174. return o;
  5175. }
  5176. return n.attributes;
  5177. },
  5178. isEmpty : function(node, elements) {
  5179. var self = this, i, attributes, type, walker, name, brCount = 0;
  5180. node = node.firstChild;
  5181. if (node) {
  5182. walker = new tinymce.dom.TreeWalker(node, node.parentNode);
  5183. elements = elements || self.schema ? self.schema.getNonEmptyElements() : null;
  5184. do {
  5185. type = node.nodeType;
  5186. if (type === 1) {
  5187. // Ignore bogus elements
  5188. if (node.getAttribute('data-mce-bogus'))
  5189. continue;
  5190. // Keep empty elements like <img />
  5191. name = node.nodeName.toLowerCase();
  5192. if (elements && elements[name]) {
  5193. // Ignore single BR elements in blocks like <p><br /></p> or <p><span><br /></span></p>
  5194. if (name === 'br') {
  5195. brCount++;
  5196. continue;
  5197. }
  5198. return false;
  5199. }
  5200. // Keep elements with data-bookmark attributes or name attribute like <a name="1"></a>
  5201. attributes = self.getAttribs(node);
  5202. i = node.attributes.length;
  5203. while (i--) {
  5204. name = node.attributes[i].nodeName;
  5205. if (name === "name" || name === 'data-mce-bookmark')
  5206. return false;
  5207. }
  5208. }
  5209. // Keep comment nodes
  5210. if (type == 8)
  5211. return false;
  5212. // Keep non whitespace text nodes
  5213. if ((type === 3 && !whiteSpaceRegExp.test(node.nodeValue)))
  5214. return false;
  5215. } while (node = walker.next());
  5216. }
  5217. return brCount <= 1;
  5218. },
  5219. destroy : function(s) {
  5220. var t = this;
  5221. t.win = t.doc = t.root = t.events = t.frag = null;
  5222. // Manual destroy then remove unload handler
  5223. if (!s)
  5224. tinymce.removeUnload(t.destroy);
  5225. },
  5226. createRng : function() {
  5227. var d = this.doc;
  5228. return d.createRange ? d.createRange() : new tinymce.dom.Range(this);
  5229. },
  5230. nodeIndex : function(node, normalized) {
  5231. var idx = 0, lastNodeType, lastNode, nodeType;
  5232. if (node) {
  5233. for (lastNodeType = node.nodeType, node = node.previousSibling, lastNode = node; node; node = node.previousSibling) {
  5234. nodeType = node.nodeType;
  5235. // Normalize text nodes
  5236. if (normalized && nodeType == 3) {
  5237. if (nodeType == lastNodeType || !node.nodeValue.length)
  5238. continue;
  5239. }
  5240. idx++;
  5241. lastNodeType = nodeType;
  5242. }
  5243. }
  5244. return idx;
  5245. },
  5246. split : function(pe, e, re) {
  5247. var t = this, r = t.createRng(), bef, aft, pa;
  5248. // W3C valid browsers tend to leave empty nodes to the left/right side of the contents, this makes sense
  5249. // but we don't want that in our code since it serves no purpose for the end user
  5250. // For example if this is chopped:
  5251. // <p>text 1<span><b>CHOP</b></span>text 2</p>
  5252. // would produce:
  5253. // <p>text 1<span></span></p><b>CHOP</b><p><span></span>text 2</p>
  5254. // this function will then trim of empty edges and produce:
  5255. // <p>text 1</p><b>CHOP</b><p>text 2</p>
  5256. function trim(node) {
  5257. var i, children = node.childNodes, type = node.nodeType;
  5258. function surroundedBySpans(node) {
  5259. var previousIsSpan = node.previousSibling && node.previousSibling.nodeName == 'SPAN';
  5260. var nextIsSpan = node.nextSibling && node.nextSibling.nodeName == 'SPAN';
  5261. return previousIsSpan && nextIsSpan;
  5262. }
  5263. if (type == 1 && node.getAttribute('data-mce-type') == 'bookmark')
  5264. return;
  5265. for (i = children.length - 1; i >= 0; i--)
  5266. trim(children[i]);
  5267. if (type != 9) {
  5268. // Keep non whitespace text nodes
  5269. if (type == 3 && node.nodeValue.length > 0) {
  5270. // If parent element isn't a block or there isn't any useful contents for example "<p> </p>"
  5271. // Also keep text nodes with only spaces if surrounded by spans.
  5272. // eg. "<p><span>a</span> <span>b</span></p>" should keep space between a and b
  5273. var trimmedLength = tinymce.trim(node.nodeValue).length;
  5274. if (!t.isBlock(node.parentNode) || trimmedLength > 0 || trimmedLength === 0 && surroundedBySpans(node))
  5275. return;
  5276. } else if (type == 1) {
  5277. // If the only child is a bookmark then move it up
  5278. children = node.childNodes;
  5279. if (children.length == 1 && children[0] && children[0].nodeType == 1 && children[0].getAttribute('data-mce-type') == 'bookmark')
  5280. node.parentNode.insertBefore(children[0], node);
  5281. // Keep non empty elements or img, hr etc
  5282. if (children.length || /^(br|hr|input|img)$/i.test(node.nodeName))
  5283. return;
  5284. }
  5285. t.remove(node);
  5286. }
  5287. return node;
  5288. };
  5289. if (pe && e) {
  5290. // Get before chunk
  5291. r.setStart(pe.parentNode, t.nodeIndex(pe));
  5292. r.setEnd(e.parentNode, t.nodeIndex(e));
  5293. bef = r.extractContents();
  5294. // Get after chunk
  5295. r = t.createRng();
  5296. r.setStart(e.parentNode, t.nodeIndex(e) + 1);
  5297. r.setEnd(pe.parentNode, t.nodeIndex(pe) + 1);
  5298. aft = r.extractContents();
  5299. // Insert before chunk
  5300. pa = pe.parentNode;
  5301. pa.insertBefore(trim(bef), pe);
  5302. // Insert middle chunk
  5303. if (re)
  5304. pa.replaceChild(re, e);
  5305. else
  5306. pa.insertBefore(e, pe);
  5307. // Insert after chunk
  5308. pa.insertBefore(trim(aft), pe);
  5309. t.remove(pe);
  5310. return re || e;
  5311. }
  5312. },
  5313. bind : function(target, name, func, scope) {
  5314. return this.events.add(target, name, func, scope || this);
  5315. },
  5316. unbind : function(target, name, func) {
  5317. return this.events.remove(target, name, func);
  5318. },
  5319. fire : function(target, name, evt) {
  5320. return this.events.fire(target, name, evt);
  5321. },
  5322. // Returns the content editable state of a node
  5323. getContentEditable: function(node) {
  5324. var contentEditable;
  5325. // Check type
  5326. if (node.nodeType != 1) {
  5327. return null;
  5328. }
  5329. // Check for fake content editable
  5330. contentEditable = node.getAttribute("data-mce-contenteditable");
  5331. if (contentEditable && contentEditable !== "inherit") {
  5332. return contentEditable;
  5333. }
  5334. // Check for real content editable
  5335. return node.contentEditable !== "inherit" ? node.contentEditable : null;
  5336. },
  5337. _findSib : function(node, selector, name) {
  5338. var t = this, f = selector;
  5339. if (node) {
  5340. // If expression make a function of it using is
  5341. if (is(f, 'string')) {
  5342. f = function(node) {
  5343. return t.is(node, selector);
  5344. };
  5345. }
  5346. // Loop all siblings
  5347. for (node = node[name]; node; node = node[name]) {
  5348. if (f(node))
  5349. return node;
  5350. }
  5351. }
  5352. return null;
  5353. },
  5354. _isRes : function(c) {
  5355. // Is live resizble element
  5356. return /^(top|left|bottom|right|width|height)/i.test(c) || /;\s*(top|left|bottom|right|width|height)/i.test(c);
  5357. }
  5358. /*
  5359. walk : function(n, f, s) {
  5360. var d = this.doc, w;
  5361. if (d.createTreeWalker) {
  5362. w = d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false);
  5363. while ((n = w.nextNode()) != null)
  5364. f.call(s || this, n);
  5365. } else
  5366. tinymce.walk(n, f, 'childNodes', s);
  5367. }
  5368. */
  5369. /*
  5370. toRGB : function(s) {
  5371. var c = /^\s*?#([0-9A-F]{2})([0-9A-F]{1,2})([0-9A-F]{2})?\s*?$/.exec(s);
  5372. if (c) {
  5373. // #FFF -> #FFFFFF
  5374. if (!is(c[3]))
  5375. c[3] = c[2] = c[1];
  5376. return "rgb(" + parseInt(c[1], 16) + "," + parseInt(c[2], 16) + "," + parseInt(c[3], 16) + ")";
  5377. }
  5378. return s;
  5379. }
  5380. */
  5381. });
  5382. tinymce.DOM = new tinymce.dom.DOMUtils(document, {process_html : 0});
  5383. })(tinymce);
  5384. (function(ns) {
  5385. // Range constructor
  5386. function Range(dom) {
  5387. var t = this,
  5388. doc = dom.doc,
  5389. EXTRACT = 0,
  5390. CLONE = 1,
  5391. DELETE = 2,
  5392. TRUE = true,
  5393. FALSE = false,
  5394. START_OFFSET = 'startOffset',
  5395. START_CONTAINER = 'startContainer',
  5396. END_CONTAINER = 'endContainer',
  5397. END_OFFSET = 'endOffset',
  5398. extend = tinymce.extend,
  5399. nodeIndex = dom.nodeIndex;
  5400. extend(t, {
  5401. // Inital states
  5402. startContainer : doc,
  5403. startOffset : 0,
  5404. endContainer : doc,
  5405. endOffset : 0,
  5406. collapsed : TRUE,
  5407. commonAncestorContainer : doc,
  5408. // Range constants
  5409. START_TO_START : 0,
  5410. START_TO_END : 1,
  5411. END_TO_END : 2,
  5412. END_TO_START : 3,
  5413. // Public methods
  5414. setStart : setStart,
  5415. setEnd : setEnd,
  5416. setStartBefore : setStartBefore,
  5417. setStartAfter : setStartAfter,
  5418. setEndBefore : setEndBefore,
  5419. setEndAfter : setEndAfter,
  5420. collapse : collapse,
  5421. selectNode : selectNode,
  5422. selectNodeContents : selectNodeContents,
  5423. compareBoundaryPoints : compareBoundaryPoints,
  5424. deleteContents : deleteContents,
  5425. extractContents : extractContents,
  5426. cloneContents : cloneContents,
  5427. insertNode : insertNode,
  5428. surroundContents : surroundContents,
  5429. cloneRange : cloneRange,
  5430. toStringIE : toStringIE
  5431. });
  5432. function createDocumentFragment() {
  5433. return doc.createDocumentFragment();
  5434. };
  5435. function setStart(n, o) {
  5436. _setEndPoint(TRUE, n, o);
  5437. };
  5438. function setEnd(n, o) {
  5439. _setEndPoint(FALSE, n, o);
  5440. };
  5441. function setStartBefore(n) {
  5442. setStart(n.parentNode, nodeIndex(n));
  5443. };
  5444. function setStartAfter(n) {
  5445. setStart(n.parentNode, nodeIndex(n) + 1);
  5446. };
  5447. function setEndBefore(n) {
  5448. setEnd(n.parentNode, nodeIndex(n));
  5449. };
  5450. function setEndAfter(n) {
  5451. setEnd(n.parentNode, nodeIndex(n) + 1);
  5452. };
  5453. function collapse(ts) {
  5454. if (ts) {
  5455. t[END_CONTAINER] = t[START_CONTAINER];
  5456. t[END_OFFSET] = t[START_OFFSET];
  5457. } else {
  5458. t[START_CONTAINER] = t[END_CONTAINER];
  5459. t[START_OFFSET] = t[END_OFFSET];
  5460. }
  5461. t.collapsed = TRUE;
  5462. };
  5463. function selectNode(n) {
  5464. setStartBefore(n);
  5465. setEndAfter(n);
  5466. };
  5467. function selectNodeContents(n) {
  5468. setStart(n, 0);
  5469. setEnd(n, n.nodeType === 1 ? n.childNodes.length : n.nodeValue.length);
  5470. };
  5471. function compareBoundaryPoints(h, r) {
  5472. var sc = t[START_CONTAINER], so = t[START_OFFSET], ec = t[END_CONTAINER], eo = t[END_OFFSET],
  5473. rsc = r.startContainer, rso = r.startOffset, rec = r.endContainer, reo = r.endOffset;
  5474. // Check START_TO_START
  5475. if (h === 0)
  5476. return _compareBoundaryPoints(sc, so, rsc, rso);
  5477. // Check START_TO_END
  5478. if (h === 1)
  5479. return _compareBoundaryPoints(ec, eo, rsc, rso);
  5480. // Check END_TO_END
  5481. if (h === 2)
  5482. return _compareBoundaryPoints(ec, eo, rec, reo);
  5483. // Check END_TO_START
  5484. if (h === 3)
  5485. return _compareBoundaryPoints(sc, so, rec, reo);
  5486. };
  5487. function deleteContents() {
  5488. _traverse(DELETE);
  5489. };
  5490. function extractContents() {
  5491. return _traverse(EXTRACT);
  5492. };
  5493. function cloneContents() {
  5494. return _traverse(CLONE);
  5495. };
  5496. function insertNode(n) {
  5497. var startContainer = this[START_CONTAINER],
  5498. startOffset = this[START_OFFSET], nn, o;
  5499. // Node is TEXT_NODE or CDATA
  5500. if ((startContainer.nodeType === 3 || startContainer.nodeType === 4) && startContainer.nodeValue) {
  5501. if (!startOffset) {
  5502. // At the start of text
  5503. startContainer.parentNode.insertBefore(n, startContainer);
  5504. } else if (startOffset >= startContainer.nodeValue.length) {
  5505. // At the end of text
  5506. dom.insertAfter(n, startContainer);
  5507. } else {
  5508. // Middle, need to split
  5509. nn = startContainer.splitText(startOffset);
  5510. startContainer.parentNode.insertBefore(n, nn);
  5511. }
  5512. } else {
  5513. // Insert element node
  5514. if (startContainer.childNodes.length > 0)
  5515. o = startContainer.childNodes[startOffset];
  5516. if (o)
  5517. startContainer.insertBefore(n, o);
  5518. else
  5519. startContainer.appendChild(n);
  5520. }
  5521. };
  5522. function surroundContents(n) {
  5523. var f = t.extractContents();
  5524. t.insertNode(n);
  5525. n.appendChild(f);
  5526. t.selectNode(n);
  5527. };
  5528. function cloneRange() {
  5529. return extend(new Range(dom), {
  5530. startContainer : t[START_CONTAINER],
  5531. startOffset : t[START_OFFSET],
  5532. endContainer : t[END_CONTAINER],
  5533. endOffset : t[END_OFFSET],
  5534. collapsed : t.collapsed,
  5535. commonAncestorContainer : t.commonAncestorContainer
  5536. });
  5537. };
  5538. // Private methods
  5539. function _getSelectedNode(container, offset) {
  5540. var child;
  5541. if (container.nodeType == 3 /* TEXT_NODE */)
  5542. return container;
  5543. if (offset < 0)
  5544. return container;
  5545. child = container.firstChild;
  5546. while (child && offset > 0) {
  5547. --offset;
  5548. child = child.nextSibling;
  5549. }
  5550. if (child)
  5551. return child;
  5552. return container;
  5553. };
  5554. function _isCollapsed() {
  5555. return (t[START_CONTAINER] == t[END_CONTAINER] && t[START_OFFSET] == t[END_OFFSET]);
  5556. };
  5557. function _compareBoundaryPoints(containerA, offsetA, containerB, offsetB) {
  5558. var c, offsetC, n, cmnRoot, childA, childB;
  5559. // In the first case the boundary-points have the same container. A is before B
  5560. // if its offset is less than the offset of B, A is equal to B if its offset is
  5561. // equal to the offset of B, and A is after B if its offset is greater than the
  5562. // offset of B.
  5563. if (containerA == containerB) {
  5564. if (offsetA == offsetB)
  5565. return 0; // equal
  5566. if (offsetA < offsetB)
  5567. return -1; // before
  5568. return 1; // after
  5569. }
  5570. // In the second case a child node C of the container of A is an ancestor
  5571. // container of B. In this case, A is before B if the offset of A is less than or
  5572. // equal to the index of the child node C and A is after B otherwise.
  5573. c = containerB;
  5574. while (c && c.parentNode != containerA)
  5575. c = c.parentNode;
  5576. if (c) {
  5577. offsetC = 0;
  5578. n = containerA.firstChild;
  5579. while (n != c && offsetC < offsetA) {
  5580. offsetC++;
  5581. n = n.nextSibling;
  5582. }
  5583. if (offsetA <= offsetC)
  5584. return -1; // before
  5585. return 1; // after
  5586. }
  5587. // In the third case a child node C of the container of B is an ancestor container
  5588. // of A. In this case, A is before B if the index of the child node C is less than
  5589. // the offset of B and A is after B otherwise.
  5590. c = containerA;
  5591. while (c && c.parentNode != containerB) {
  5592. c = c.parentNode;
  5593. }
  5594. if (c) {
  5595. offsetC = 0;
  5596. n = containerB.firstChild;
  5597. while (n != c && offsetC < offsetB) {
  5598. offsetC++;
  5599. n = n.nextSibling;
  5600. }
  5601. if (offsetC < offsetB)
  5602. return -1; // before
  5603. return 1; // after
  5604. }
  5605. // In the fourth case, none of three other cases hold: the containers of A and B
  5606. // are siblings or descendants of sibling nodes. In this case, A is before B if
  5607. // the container of A is before the container of B in a pre-order traversal of the
  5608. // Ranges' context tree and A is after B otherwise.
  5609. cmnRoot = dom.findCommonAncestor(containerA, containerB);
  5610. childA = containerA;
  5611. while (childA && childA.parentNode != cmnRoot)
  5612. childA = childA.parentNode;
  5613. if (!childA)
  5614. childA = cmnRoot;
  5615. childB = containerB;
  5616. while (childB && childB.parentNode != cmnRoot)
  5617. childB = childB.parentNode;
  5618. if (!childB)
  5619. childB = cmnRoot;
  5620. if (childA == childB)
  5621. return 0; // equal
  5622. n = cmnRoot.firstChild;
  5623. while (n) {
  5624. if (n == childA)
  5625. return -1; // before
  5626. if (n == childB)
  5627. return 1; // after
  5628. n = n.nextSibling;
  5629. }
  5630. };
  5631. function _setEndPoint(st, n, o) {
  5632. var ec, sc;
  5633. if (st) {
  5634. t[START_CONTAINER] = n;
  5635. t[START_OFFSET] = o;
  5636. } else {
  5637. t[END_CONTAINER] = n;
  5638. t[END_OFFSET] = o;
  5639. }
  5640. // If one boundary-point of a Range is set to have a root container
  5641. // other than the current one for the Range, the Range is collapsed to
  5642. // the new position. This enforces the restriction that both boundary-
  5643. // points of a Range must have the same root container.
  5644. ec = t[END_CONTAINER];
  5645. while (ec.parentNode)
  5646. ec = ec.parentNode;
  5647. sc = t[START_CONTAINER];
  5648. while (sc.parentNode)
  5649. sc = sc.parentNode;
  5650. if (sc == ec) {
  5651. // The start position of a Range is guaranteed to never be after the
  5652. // end position. To enforce this restriction, if the start is set to
  5653. // be at a position after the end, the Range is collapsed to that
  5654. // position.
  5655. if (_compareBoundaryPoints(t[START_CONTAINER], t[START_OFFSET], t[END_CONTAINER], t[END_OFFSET]) > 0)
  5656. t.collapse(st);
  5657. } else
  5658. t.collapse(st);
  5659. t.collapsed = _isCollapsed();
  5660. t.commonAncestorContainer = dom.findCommonAncestor(t[START_CONTAINER], t[END_CONTAINER]);
  5661. };
  5662. function _traverse(how) {
  5663. var c, endContainerDepth = 0, startContainerDepth = 0, p, depthDiff, startNode, endNode, sp, ep;
  5664. if (t[START_CONTAINER] == t[END_CONTAINER])
  5665. return _traverseSameContainer(how);
  5666. for (c = t[END_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  5667. if (p == t[START_CONTAINER])
  5668. return _traverseCommonStartContainer(c, how);
  5669. ++endContainerDepth;
  5670. }
  5671. for (c = t[START_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  5672. if (p == t[END_CONTAINER])
  5673. return _traverseCommonEndContainer(c, how);
  5674. ++startContainerDepth;
  5675. }
  5676. depthDiff = startContainerDepth - endContainerDepth;
  5677. startNode = t[START_CONTAINER];
  5678. while (depthDiff > 0) {
  5679. startNode = startNode.parentNode;
  5680. depthDiff--;
  5681. }
  5682. endNode = t[END_CONTAINER];
  5683. while (depthDiff < 0) {
  5684. endNode = endNode.parentNode;
  5685. depthDiff++;
  5686. }
  5687. // ascend the ancestor hierarchy until we have a common parent.
  5688. for (sp = startNode.parentNode, ep = endNode.parentNode; sp != ep; sp = sp.parentNode, ep = ep.parentNode) {
  5689. startNode = sp;
  5690. endNode = ep;
  5691. }
  5692. return _traverseCommonAncestors(startNode, endNode, how);
  5693. };
  5694. function _traverseSameContainer(how) {
  5695. var frag, s, sub, n, cnt, sibling, xferNode, start, len;
  5696. if (how != DELETE)
  5697. frag = createDocumentFragment();
  5698. // If selection is empty, just return the fragment
  5699. if (t[START_OFFSET] == t[END_OFFSET])
  5700. return frag;
  5701. // Text node needs special case handling
  5702. if (t[START_CONTAINER].nodeType == 3 /* TEXT_NODE */) {
  5703. // get the substring
  5704. s = t[START_CONTAINER].nodeValue;
  5705. sub = s.substring(t[START_OFFSET], t[END_OFFSET]);
  5706. // set the original text node to its new value
  5707. if (how != CLONE) {
  5708. n = t[START_CONTAINER];
  5709. start = t[START_OFFSET];
  5710. len = t[END_OFFSET] - t[START_OFFSET];
  5711. if (start === 0 && len >= n.nodeValue.length - 1) {
  5712. n.parentNode.removeChild(n);
  5713. } else {
  5714. n.deleteData(start, len);
  5715. }
  5716. // Nothing is partially selected, so collapse to start point
  5717. t.collapse(TRUE);
  5718. }
  5719. if (how == DELETE)
  5720. return;
  5721. if (sub.length > 0) {
  5722. frag.appendChild(doc.createTextNode(sub));
  5723. }
  5724. return frag;
  5725. }
  5726. // Copy nodes between the start/end offsets.
  5727. n = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]);
  5728. cnt = t[END_OFFSET] - t[START_OFFSET];
  5729. while (n && cnt > 0) {
  5730. sibling = n.nextSibling;
  5731. xferNode = _traverseFullySelected(n, how);
  5732. if (frag)
  5733. frag.appendChild( xferNode );
  5734. --cnt;
  5735. n = sibling;
  5736. }
  5737. // Nothing is partially selected, so collapse to start point
  5738. if (how != CLONE)
  5739. t.collapse(TRUE);
  5740. return frag;
  5741. };
  5742. function _traverseCommonStartContainer(endAncestor, how) {
  5743. var frag, n, endIdx, cnt, sibling, xferNode;
  5744. if (how != DELETE)
  5745. frag = createDocumentFragment();
  5746. n = _traverseRightBoundary(endAncestor, how);
  5747. if (frag)
  5748. frag.appendChild(n);
  5749. endIdx = nodeIndex(endAncestor);
  5750. cnt = endIdx - t[START_OFFSET];
  5751. if (cnt <= 0) {
  5752. // Collapse to just before the endAncestor, which
  5753. // is partially selected.
  5754. if (how != CLONE) {
  5755. t.setEndBefore(endAncestor);
  5756. t.collapse(FALSE);
  5757. }
  5758. return frag;
  5759. }
  5760. n = endAncestor.previousSibling;
  5761. while (cnt > 0) {
  5762. sibling = n.previousSibling;
  5763. xferNode = _traverseFullySelected(n, how);
  5764. if (frag)
  5765. frag.insertBefore(xferNode, frag.firstChild);
  5766. --cnt;
  5767. n = sibling;
  5768. }
  5769. // Collapse to just before the endAncestor, which
  5770. // is partially selected.
  5771. if (how != CLONE) {
  5772. t.setEndBefore(endAncestor);
  5773. t.collapse(FALSE);
  5774. }
  5775. return frag;
  5776. };
  5777. function _traverseCommonEndContainer(startAncestor, how) {
  5778. var frag, startIdx, n, cnt, sibling, xferNode;
  5779. if (how != DELETE)
  5780. frag = createDocumentFragment();
  5781. n = _traverseLeftBoundary(startAncestor, how);
  5782. if (frag)
  5783. frag.appendChild(n);
  5784. startIdx = nodeIndex(startAncestor);
  5785. ++startIdx; // Because we already traversed it
  5786. cnt = t[END_OFFSET] - startIdx;
  5787. n = startAncestor.nextSibling;
  5788. while (n && cnt > 0) {
  5789. sibling = n.nextSibling;
  5790. xferNode = _traverseFullySelected(n, how);
  5791. if (frag)
  5792. frag.appendChild(xferNode);
  5793. --cnt;
  5794. n = sibling;
  5795. }
  5796. if (how != CLONE) {
  5797. t.setStartAfter(startAncestor);
  5798. t.collapse(TRUE);
  5799. }
  5800. return frag;
  5801. };
  5802. function _traverseCommonAncestors(startAncestor, endAncestor, how) {
  5803. var n, frag, commonParent, startOffset, endOffset, cnt, sibling, nextSibling;
  5804. if (how != DELETE)
  5805. frag = createDocumentFragment();
  5806. n = _traverseLeftBoundary(startAncestor, how);
  5807. if (frag)
  5808. frag.appendChild(n);
  5809. commonParent = startAncestor.parentNode;
  5810. startOffset = nodeIndex(startAncestor);
  5811. endOffset = nodeIndex(endAncestor);
  5812. ++startOffset;
  5813. cnt = endOffset - startOffset;
  5814. sibling = startAncestor.nextSibling;
  5815. while (cnt > 0) {
  5816. nextSibling = sibling.nextSibling;
  5817. n = _traverseFullySelected(sibling, how);
  5818. if (frag)
  5819. frag.appendChild(n);
  5820. sibling = nextSibling;
  5821. --cnt;
  5822. }
  5823. n = _traverseRightBoundary(endAncestor, how);
  5824. if (frag)
  5825. frag.appendChild(n);
  5826. if (how != CLONE) {
  5827. t.setStartAfter(startAncestor);
  5828. t.collapse(TRUE);
  5829. }
  5830. return frag;
  5831. };
  5832. function _traverseRightBoundary(root, how) {
  5833. var next = _getSelectedNode(t[END_CONTAINER], t[END_OFFSET] - 1), parent, clonedParent, prevSibling, clonedChild, clonedGrandParent, isFullySelected = next != t[END_CONTAINER];
  5834. if (next == root)
  5835. return _traverseNode(next, isFullySelected, FALSE, how);
  5836. parent = next.parentNode;
  5837. clonedParent = _traverseNode(parent, FALSE, FALSE, how);
  5838. while (parent) {
  5839. while (next) {
  5840. prevSibling = next.previousSibling;
  5841. clonedChild = _traverseNode(next, isFullySelected, FALSE, how);
  5842. if (how != DELETE)
  5843. clonedParent.insertBefore(clonedChild, clonedParent.firstChild);
  5844. isFullySelected = TRUE;
  5845. next = prevSibling;
  5846. }
  5847. if (parent == root)
  5848. return clonedParent;
  5849. next = parent.previousSibling;
  5850. parent = parent.parentNode;
  5851. clonedGrandParent = _traverseNode(parent, FALSE, FALSE, how);
  5852. if (how != DELETE)
  5853. clonedGrandParent.appendChild(clonedParent);
  5854. clonedParent = clonedGrandParent;
  5855. }
  5856. };
  5857. function _traverseLeftBoundary(root, how) {
  5858. var next = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]), isFullySelected = next != t[START_CONTAINER], parent, clonedParent, nextSibling, clonedChild, clonedGrandParent;
  5859. if (next == root)
  5860. return _traverseNode(next, isFullySelected, TRUE, how);
  5861. parent = next.parentNode;
  5862. clonedParent = _traverseNode(parent, FALSE, TRUE, how);
  5863. while (parent) {
  5864. while (next) {
  5865. nextSibling = next.nextSibling;
  5866. clonedChild = _traverseNode(next, isFullySelected, TRUE, how);
  5867. if (how != DELETE)
  5868. clonedParent.appendChild(clonedChild);
  5869. isFullySelected = TRUE;
  5870. next = nextSibling;
  5871. }
  5872. if (parent == root)
  5873. return clonedParent;
  5874. next = parent.nextSibling;
  5875. parent = parent.parentNode;
  5876. clonedGrandParent = _traverseNode(parent, FALSE, TRUE, how);
  5877. if (how != DELETE)
  5878. clonedGrandParent.appendChild(clonedParent);
  5879. clonedParent = clonedGrandParent;
  5880. }
  5881. };
  5882. function _traverseNode(n, isFullySelected, isLeft, how) {
  5883. var txtValue, newNodeValue, oldNodeValue, offset, newNode;
  5884. if (isFullySelected)
  5885. return _traverseFullySelected(n, how);
  5886. if (n.nodeType == 3 /* TEXT_NODE */) {
  5887. txtValue = n.nodeValue;
  5888. if (isLeft) {
  5889. offset = t[START_OFFSET];
  5890. newNodeValue = txtValue.substring(offset);
  5891. oldNodeValue = txtValue.substring(0, offset);
  5892. } else {
  5893. offset = t[END_OFFSET];
  5894. newNodeValue = txtValue.substring(0, offset);
  5895. oldNodeValue = txtValue.substring(offset);
  5896. }
  5897. if (how != CLONE)
  5898. n.nodeValue = oldNodeValue;
  5899. if (how == DELETE)
  5900. return;
  5901. newNode = dom.clone(n, FALSE);
  5902. newNode.nodeValue = newNodeValue;
  5903. return newNode;
  5904. }
  5905. if (how == DELETE)
  5906. return;
  5907. return dom.clone(n, FALSE);
  5908. };
  5909. function _traverseFullySelected(n, how) {
  5910. if (how != DELETE)
  5911. return how == CLONE ? dom.clone(n, TRUE) : n;
  5912. n.parentNode.removeChild(n);
  5913. };
  5914. function toStringIE() {
  5915. return dom.create('body', null, cloneContents()).outerText;
  5916. }
  5917. return t;
  5918. };
  5919. ns.Range = Range;
  5920. // Older IE versions doesn't let you override toString by it's constructor so we have to stick it in the prototype
  5921. Range.prototype.toString = function() {
  5922. return this.toStringIE();
  5923. };
  5924. })(tinymce.dom);
  5925. (function() {
  5926. function Selection(selection) {
  5927. var self = this, dom = selection.dom, TRUE = true, FALSE = false;
  5928. function getPosition(rng, start) {
  5929. var checkRng, startIndex = 0, endIndex, inside,
  5930. children, child, offset, index, position = -1, parent;
  5931. // Setup test range, collapse it and get the parent
  5932. checkRng = rng.duplicate();
  5933. checkRng.collapse(start);
  5934. parent = checkRng.parentElement();
  5935. // Check if the selection is within the right document
  5936. if (parent.ownerDocument !== selection.dom.doc)
  5937. return;
  5938. // IE will report non editable elements as it's parent so look for an editable one
  5939. while (parent.contentEditable === "false") {
  5940. parent = parent.parentNode;
  5941. }
  5942. // If parent doesn't have any children then return that we are inside the element
  5943. if (!parent.hasChildNodes()) {
  5944. return {node : parent, inside : 1};
  5945. }
  5946. // Setup node list and endIndex
  5947. children = parent.children;
  5948. endIndex = children.length - 1;
  5949. // Perform a binary search for the position
  5950. while (startIndex <= endIndex) {
  5951. index = Math.floor((startIndex + endIndex) / 2);
  5952. // Move selection to node and compare the ranges
  5953. child = children[index];
  5954. checkRng.moveToElementText(child);
  5955. position = checkRng.compareEndPoints(start ? 'StartToStart' : 'EndToEnd', rng);
  5956. // Before/after or an exact match
  5957. if (position > 0) {
  5958. endIndex = index - 1;
  5959. } else if (position < 0) {
  5960. startIndex = index + 1;
  5961. } else {
  5962. return {node : child};
  5963. }
  5964. }
  5965. // Check if child position is before or we didn't find a position
  5966. if (position < 0) {
  5967. // No element child was found use the parent element and the offset inside that
  5968. if (!child) {
  5969. checkRng.moveToElementText(parent);
  5970. checkRng.collapse(true);
  5971. child = parent;
  5972. inside = true;
  5973. } else
  5974. checkRng.collapse(false);
  5975. // 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
  5976. // We need to walk char by char since rng.text or rng.htmlText will trim line endings
  5977. offset = 0;
  5978. while (checkRng.compareEndPoints(start ? 'StartToStart' : 'StartToEnd', rng) !== 0) {
  5979. if (checkRng.move('character', 1) === 0 || parent != checkRng.parentElement()) {
  5980. break;
  5981. }
  5982. offset++;
  5983. }
  5984. } else {
  5985. // Child position is after the selection endpoint
  5986. checkRng.collapse(true);
  5987. // 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
  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. }
  5996. return {node : child, position : position, offset : offset, inside : inside};
  5997. };
  5998. // Returns a W3C DOM compatible range object by using the IE Range API
  5999. function getRange() {
  6000. var ieRange = selection.getRng(), domRange = dom.createRng(), element, collapsed, tmpRange, element2, bookmark, fail;
  6001. // If selection is outside the current document just return an empty range
  6002. element = ieRange.item ? ieRange.item(0) : ieRange.parentElement();
  6003. if (element.ownerDocument != dom.doc)
  6004. return domRange;
  6005. collapsed = selection.isCollapsed();
  6006. // Handle control selection
  6007. if (ieRange.item) {
  6008. domRange.setStart(element.parentNode, dom.nodeIndex(element));
  6009. domRange.setEnd(domRange.startContainer, domRange.startOffset + 1);
  6010. return domRange;
  6011. }
  6012. function findEndPoint(start) {
  6013. var endPoint = getPosition(ieRange, start), container, offset, textNodeOffset = 0, sibling, undef, nodeValue;
  6014. container = endPoint.node;
  6015. offset = endPoint.offset;
  6016. if (endPoint.inside && !container.hasChildNodes()) {
  6017. domRange[start ? 'setStart' : 'setEnd'](container, 0);
  6018. return;
  6019. }
  6020. if (offset === undef) {
  6021. domRange[start ? 'setStartBefore' : 'setEndAfter'](container);
  6022. return;
  6023. }
  6024. if (endPoint.position < 0) {
  6025. sibling = endPoint.inside ? container.firstChild : container.nextSibling;
  6026. if (!sibling) {
  6027. domRange[start ? 'setStartAfter' : 'setEndAfter'](container);
  6028. return;
  6029. }
  6030. if (!offset) {
  6031. if (sibling.nodeType == 3)
  6032. domRange[start ? 'setStart' : 'setEnd'](sibling, 0);
  6033. else
  6034. domRange[start ? 'setStartBefore' : 'setEndBefore'](sibling);
  6035. return;
  6036. }
  6037. // Find the text node and offset
  6038. while (sibling) {
  6039. nodeValue = sibling.nodeValue;
  6040. textNodeOffset += nodeValue.length;
  6041. // We are at or passed the position we where looking for
  6042. if (textNodeOffset >= offset) {
  6043. container = sibling;
  6044. textNodeOffset -= offset;
  6045. textNodeOffset = nodeValue.length - textNodeOffset;
  6046. break;
  6047. }
  6048. sibling = sibling.nextSibling;
  6049. }
  6050. } else {
  6051. // Find the text node and offset
  6052. sibling = container.previousSibling;
  6053. if (!sibling)
  6054. return domRange[start ? 'setStartBefore' : 'setEndBefore'](container);
  6055. // If there isn't any text to loop then use the first position
  6056. if (!offset) {
  6057. if (container.nodeType == 3)
  6058. domRange[start ? 'setStart' : 'setEnd'](sibling, container.nodeValue.length);
  6059. else
  6060. domRange[start ? 'setStartAfter' : 'setEndAfter'](sibling);
  6061. return;
  6062. }
  6063. while (sibling) {
  6064. textNodeOffset += sibling.nodeValue.length;
  6065. // We are at or passed the position we where looking for
  6066. if (textNodeOffset >= offset) {
  6067. container = sibling;
  6068. textNodeOffset -= offset;
  6069. break;
  6070. }
  6071. sibling = sibling.previousSibling;
  6072. }
  6073. }
  6074. domRange[start ? 'setStart' : 'setEnd'](container, textNodeOffset);
  6075. };
  6076. try {
  6077. // Find start point
  6078. findEndPoint(true);
  6079. // Find end point if needed
  6080. if (!collapsed)
  6081. findEndPoint();
  6082. } catch (ex) {
  6083. // IE has a nasty bug where text nodes might throw "invalid argument" when you
  6084. // access the nodeValue or other properties of text nodes. This seems to happend when
  6085. // text nodes are split into two nodes by a delete/backspace call. So lets detect it and try to fix it.
  6086. if (ex.number == -2147024809) {
  6087. // Get the current selection
  6088. bookmark = self.getBookmark(2);
  6089. // Get start element
  6090. tmpRange = ieRange.duplicate();
  6091. tmpRange.collapse(true);
  6092. element = tmpRange.parentElement();
  6093. // Get end element
  6094. if (!collapsed) {
  6095. tmpRange = ieRange.duplicate();
  6096. tmpRange.collapse(false);
  6097. element2 = tmpRange.parentElement();
  6098. element2.innerHTML = element2.innerHTML;
  6099. }
  6100. // Remove the broken elements
  6101. element.innerHTML = element.innerHTML;
  6102. // Restore the selection
  6103. self.moveToBookmark(bookmark);
  6104. // Since the range has moved we need to re-get it
  6105. ieRange = selection.getRng();
  6106. // Find start point
  6107. findEndPoint(true);
  6108. // Find end point if needed
  6109. if (!collapsed)
  6110. findEndPoint();
  6111. } else
  6112. throw ex; // Throw other errors
  6113. }
  6114. return domRange;
  6115. };
  6116. this.getBookmark = function(type) {
  6117. var rng = selection.getRng(), start, end, bookmark = {};
  6118. function getIndexes(node) {
  6119. var parent, root, children, i, indexes = [];
  6120. parent = node.parentNode;
  6121. root = dom.getRoot().parentNode;
  6122. while (parent != root && parent.nodeType !== 9) {
  6123. children = parent.children;
  6124. i = children.length;
  6125. while (i--) {
  6126. if (node === children[i]) {
  6127. indexes.push(i);
  6128. break;
  6129. }
  6130. }
  6131. node = parent;
  6132. parent = parent.parentNode;
  6133. }
  6134. return indexes;
  6135. };
  6136. function getBookmarkEndPoint(start) {
  6137. var position;
  6138. position = getPosition(rng, start);
  6139. if (position) {
  6140. return {
  6141. position : position.position,
  6142. offset : position.offset,
  6143. indexes : getIndexes(position.node),
  6144. inside : position.inside
  6145. };
  6146. }
  6147. };
  6148. // Non ubstructive bookmark
  6149. if (type === 2) {
  6150. // Handle text selection
  6151. if (!rng.item) {
  6152. bookmark.start = getBookmarkEndPoint(true);
  6153. if (!selection.isCollapsed())
  6154. bookmark.end = getBookmarkEndPoint();
  6155. } else
  6156. bookmark.start = {ctrl : true, indexes : getIndexes(rng.item(0))};
  6157. }
  6158. return bookmark;
  6159. };
  6160. this.moveToBookmark = function(bookmark) {
  6161. var rng, body = dom.doc.body;
  6162. function resolveIndexes(indexes) {
  6163. var node, i, idx, children;
  6164. node = dom.getRoot();
  6165. for (i = indexes.length - 1; i >= 0; i--) {
  6166. children = node.children;
  6167. idx = indexes[i];
  6168. if (idx <= children.length - 1) {
  6169. node = children[idx];
  6170. }
  6171. }
  6172. return node;
  6173. };
  6174. function setBookmarkEndPoint(start) {
  6175. var endPoint = bookmark[start ? 'start' : 'end'], moveLeft, moveRng, undef;
  6176. if (endPoint) {
  6177. moveLeft = endPoint.position > 0;
  6178. moveRng = body.createTextRange();
  6179. moveRng.moveToElementText(resolveIndexes(endPoint.indexes));
  6180. offset = endPoint.offset;
  6181. if (offset !== undef) {
  6182. moveRng.collapse(endPoint.inside || moveLeft);
  6183. moveRng.moveStart('character', moveLeft ? -offset : offset);
  6184. } else
  6185. moveRng.collapse(start);
  6186. rng.setEndPoint(start ? 'StartToStart' : 'EndToStart', moveRng);
  6187. if (start)
  6188. rng.collapse(true);
  6189. }
  6190. };
  6191. if (bookmark.start) {
  6192. if (bookmark.start.ctrl) {
  6193. rng = body.createControlRange();
  6194. rng.addElement(resolveIndexes(bookmark.start.indexes));
  6195. rng.select();
  6196. } else {
  6197. rng = body.createTextRange();
  6198. setBookmarkEndPoint(true);
  6199. setBookmarkEndPoint();
  6200. rng.select();
  6201. }
  6202. }
  6203. };
  6204. this.addRange = function(rng) {
  6205. var ieRng, ctrlRng, startContainer, startOffset, endContainer, endOffset, sibling,
  6206. doc = selection.dom.doc, body = doc.body, nativeRng, ctrlElm;
  6207. function setEndPoint(start) {
  6208. var container, offset, marker, tmpRng, nodes;
  6209. marker = dom.create('a');
  6210. container = start ? startContainer : endContainer;
  6211. offset = start ? startOffset : endOffset;
  6212. tmpRng = ieRng.duplicate();
  6213. if (container == doc || container == doc.documentElement) {
  6214. container = body;
  6215. offset = 0;
  6216. }
  6217. if (container.nodeType == 3) {
  6218. container.parentNode.insertBefore(marker, container);
  6219. tmpRng.moveToElementText(marker);
  6220. tmpRng.moveStart('character', offset);
  6221. dom.remove(marker);
  6222. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  6223. } else {
  6224. nodes = container.childNodes;
  6225. if (nodes.length) {
  6226. if (offset >= nodes.length) {
  6227. dom.insertAfter(marker, nodes[nodes.length - 1]);
  6228. } else {
  6229. container.insertBefore(marker, nodes[offset]);
  6230. }
  6231. tmpRng.moveToElementText(marker);
  6232. } else if (container.canHaveHTML) {
  6233. // Empty node selection for example <div>|</div>
  6234. // Setting innerHTML with a span marker then remove that marker seems to keep empty block elements open
  6235. container.innerHTML = '<span>\uFEFF</span>';
  6236. marker = container.firstChild;
  6237. tmpRng.moveToElementText(marker);
  6238. tmpRng.collapse(FALSE); // Collapse false works better than true for some odd reason
  6239. }
  6240. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  6241. dom.remove(marker);
  6242. }
  6243. }
  6244. // Setup some shorter versions
  6245. startContainer = rng.startContainer;
  6246. startOffset = rng.startOffset;
  6247. endContainer = rng.endContainer;
  6248. endOffset = rng.endOffset;
  6249. ieRng = body.createTextRange();
  6250. // If single element selection then try making a control selection out of it
  6251. if (startContainer == endContainer && startContainer.nodeType == 1) {
  6252. // Trick to place the caret inside an empty block element like <p></p>
  6253. if (startOffset == endOffset && !startContainer.hasChildNodes()) {
  6254. if (startContainer.canHaveHTML) {
  6255. // Check if previous sibling is an empty block if it is then we need to render it
  6256. // IE would otherwise move the caret into the sibling instead of the empty startContainer see: #5236
  6257. // Example this: <p></p><p>|</p> would become this: <p>|</p><p></p>
  6258. sibling = startContainer.previousSibling;
  6259. if (sibling && !sibling.hasChildNodes() && dom.isBlock(sibling)) {
  6260. sibling.innerHTML = '\uFEFF';
  6261. } else {
  6262. sibling = null;
  6263. }
  6264. startContainer.innerHTML = '<span>\uFEFF</span><span>\uFEFF</span>';
  6265. ieRng.moveToElementText(startContainer.lastChild);
  6266. ieRng.select();
  6267. dom.doc.selection.clear();
  6268. startContainer.innerHTML = '';
  6269. if (sibling) {
  6270. sibling.innerHTML = '';
  6271. }
  6272. return;
  6273. } else {
  6274. startOffset = dom.nodeIndex(startContainer);
  6275. startContainer = startContainer.parentNode;
  6276. }
  6277. }
  6278. if (startOffset == endOffset - 1) {
  6279. try {
  6280. ctrlElm = startContainer.childNodes[startOffset];
  6281. ctrlRng = body.createControlRange();
  6282. ctrlRng.addElement(ctrlElm);
  6283. ctrlRng.select();
  6284. // Check if the range produced is on the correct element and is a control range
  6285. // On IE 8 it will select the parent contentEditable container if you select an inner element see: #5398
  6286. nativeRng = selection.getRng();
  6287. if (nativeRng.item && ctrlElm === nativeRng.item(0)) {
  6288. return;
  6289. }
  6290. } catch (ex) {
  6291. // Ignore
  6292. }
  6293. }
  6294. }
  6295. // Set start/end point of selection
  6296. setEndPoint(true);
  6297. setEndPoint();
  6298. // Select the new range and scroll it into view
  6299. ieRng.select();
  6300. };
  6301. // Expose range method
  6302. this.getRangeAt = getRange;
  6303. };
  6304. // Expose the selection object
  6305. tinymce.dom.TridentSelection = Selection;
  6306. })();
  6307. (function(tinymce) {
  6308. tinymce.dom.Element = function(id, settings) {
  6309. var t = this, dom, el;
  6310. t.settings = settings = settings || {};
  6311. t.id = id;
  6312. t.dom = dom = settings.dom || tinymce.DOM;
  6313. // Only IE leaks DOM references, this is a lot faster
  6314. if (!tinymce.isIE)
  6315. el = dom.get(t.id);
  6316. tinymce.each(
  6317. ('getPos,getRect,getParent,add,setStyle,getStyle,setStyles,' +
  6318. 'setAttrib,setAttribs,getAttrib,addClass,removeClass,' +
  6319. 'hasClass,getOuterHTML,setOuterHTML,remove,show,hide,' +
  6320. 'isHidden,setHTML,get').split(/,/), function(k) {
  6321. t[k] = function() {
  6322. var a = [id], i;
  6323. for (i = 0; i < arguments.length; i++)
  6324. a.push(arguments[i]);
  6325. a = dom[k].apply(dom, a);
  6326. t.update(k);
  6327. return a;
  6328. };
  6329. }
  6330. );
  6331. tinymce.extend(t, {
  6332. on : function(n, f, s) {
  6333. return tinymce.dom.Event.add(t.id, n, f, s);
  6334. },
  6335. getXY : function() {
  6336. return {
  6337. x : parseInt(t.getStyle('left')),
  6338. y : parseInt(t.getStyle('top'))
  6339. };
  6340. },
  6341. getSize : function() {
  6342. var n = dom.get(t.id);
  6343. return {
  6344. w : parseInt(t.getStyle('width') || n.clientWidth),
  6345. h : parseInt(t.getStyle('height') || n.clientHeight)
  6346. };
  6347. },
  6348. moveTo : function(x, y) {
  6349. t.setStyles({left : x, top : y});
  6350. },
  6351. moveBy : function(x, y) {
  6352. var p = t.getXY();
  6353. t.moveTo(p.x + x, p.y + y);
  6354. },
  6355. resizeTo : function(w, h) {
  6356. t.setStyles({width : w, height : h});
  6357. },
  6358. resizeBy : function(w, h) {
  6359. var s = t.getSize();
  6360. t.resizeTo(s.w + w, s.h + h);
  6361. },
  6362. update : function(k) {
  6363. var b;
  6364. if (tinymce.isIE6 && settings.blocker) {
  6365. k = k || '';
  6366. // Ignore getters
  6367. if (k.indexOf('get') === 0 || k.indexOf('has') === 0 || k.indexOf('is') === 0)
  6368. return;
  6369. // Remove blocker on remove
  6370. if (k == 'remove') {
  6371. dom.remove(t.blocker);
  6372. return;
  6373. }
  6374. if (!t.blocker) {
  6375. t.blocker = dom.uniqueId();
  6376. b = dom.add(settings.container || dom.getRoot(), 'iframe', {id : t.blocker, style : 'position:absolute;', frameBorder : 0, src : 'javascript:""'});
  6377. dom.setStyle(b, 'opacity', 0);
  6378. } else
  6379. b = dom.get(t.blocker);
  6380. dom.setStyles(b, {
  6381. left : t.getStyle('left', 1),
  6382. top : t.getStyle('top', 1),
  6383. width : t.getStyle('width', 1),
  6384. height : t.getStyle('height', 1),
  6385. display : t.getStyle('display', 1),
  6386. zIndex : parseInt(t.getStyle('zIndex', 1) || 0) - 1
  6387. });
  6388. }
  6389. }
  6390. });
  6391. };
  6392. })(tinymce);
  6393. (function(tinymce) {
  6394. function trimNl(s) {
  6395. return s.replace(/[\n\r]+/g, '');
  6396. };
  6397. // Shorten names
  6398. var is = tinymce.is, isIE = tinymce.isIE, each = tinymce.each, TreeWalker = tinymce.dom.TreeWalker;
  6399. tinymce.create('tinymce.dom.Selection', {
  6400. Selection : function(dom, win, serializer, editor) {
  6401. var t = this;
  6402. t.dom = dom;
  6403. t.win = win;
  6404. t.serializer = serializer;
  6405. t.editor = editor;
  6406. // Add events
  6407. each([
  6408. 'onBeforeSetContent',
  6409. 'onBeforeGetContent',
  6410. 'onSetContent',
  6411. 'onGetContent'
  6412. ], function(e) {
  6413. t[e] = new tinymce.util.Dispatcher(t);
  6414. });
  6415. // No W3C Range support
  6416. if (!t.win.getSelection)
  6417. t.tridentSel = new tinymce.dom.TridentSelection(t);
  6418. if (tinymce.isIE && dom.boxModel)
  6419. this._fixIESelection();
  6420. // Prevent leaks
  6421. tinymce.addUnload(t.destroy, t);
  6422. },
  6423. setCursorLocation: function(node, offset) {
  6424. var t = this; var r = t.dom.createRng();
  6425. r.setStart(node, offset);
  6426. r.setEnd(node, offset);
  6427. t.setRng(r);
  6428. t.collapse(false);
  6429. },
  6430. getContent : function(s) {
  6431. var t = this, r = t.getRng(), e = t.dom.create("body"), se = t.getSel(), wb, wa, n;
  6432. s = s || {};
  6433. wb = wa = '';
  6434. s.get = true;
  6435. s.format = s.format || 'html';
  6436. s.forced_root_block = '';
  6437. t.onBeforeGetContent.dispatch(t, s);
  6438. if (s.format == 'text')
  6439. return t.isCollapsed() ? '' : (r.text || (se.toString ? se.toString() : ''));
  6440. if (r.cloneContents) {
  6441. n = r.cloneContents();
  6442. if (n)
  6443. e.appendChild(n);
  6444. } else if (is(r.item) || is(r.htmlText)) {
  6445. // IE will produce invalid markup if elements are present that
  6446. // it doesn't understand like custom elements or HTML5 elements.
  6447. // Adding a BR in front of the contents and then remoiving it seems to fix it though.
  6448. e.innerHTML = '<br>' + (r.item ? r.item(0).outerHTML : r.htmlText);
  6449. e.removeChild(e.firstChild);
  6450. } else
  6451. e.innerHTML = r.toString();
  6452. // Keep whitespace before and after
  6453. if (/^\s/.test(e.innerHTML))
  6454. wb = ' ';
  6455. if (/\s+$/.test(e.innerHTML))
  6456. wa = ' ';
  6457. s.getInner = true;
  6458. s.content = t.isCollapsed() ? '' : wb + t.serializer.serialize(e, s) + wa;
  6459. t.onGetContent.dispatch(t, s);
  6460. return s.content;
  6461. },
  6462. setContent : function(content, args) {
  6463. var self = this, rng = self.getRng(), caretNode, doc = self.win.document, frag, temp;
  6464. args = args || {format : 'html'};
  6465. args.set = true;
  6466. content = args.content = content;
  6467. // Dispatch before set content event
  6468. if (!args.no_events)
  6469. self.onBeforeSetContent.dispatch(self, args);
  6470. content = args.content;
  6471. if (rng.insertNode) {
  6472. // Make caret marker since insertNode places the caret in the beginning of text after insert
  6473. content += '<span id="__caret">_</span>';
  6474. // Delete and insert new node
  6475. if (rng.startContainer == doc && rng.endContainer == doc) {
  6476. // WebKit will fail if the body is empty since the range is then invalid and it can't insert contents
  6477. doc.body.innerHTML = content;
  6478. } else {
  6479. rng.deleteContents();
  6480. if (doc.body.childNodes.length === 0) {
  6481. doc.body.innerHTML = content;
  6482. } else {
  6483. // createContextualFragment doesn't exists in IE 9 DOMRanges
  6484. if (rng.createContextualFragment) {
  6485. rng.insertNode(rng.createContextualFragment(content));
  6486. } else {
  6487. // Fake createContextualFragment call in IE 9
  6488. frag = doc.createDocumentFragment();
  6489. temp = doc.createElement('div');
  6490. frag.appendChild(temp);
  6491. temp.outerHTML = content;
  6492. rng.insertNode(frag);
  6493. }
  6494. }
  6495. }
  6496. // Move to caret marker
  6497. caretNode = self.dom.get('__caret');
  6498. // Make sure we wrap it compleatly, Opera fails with a simple select call
  6499. rng = doc.createRange();
  6500. rng.setStartBefore(caretNode);
  6501. rng.setEndBefore(caretNode);
  6502. self.setRng(rng);
  6503. // Remove the caret position
  6504. self.dom.remove('__caret');
  6505. try {
  6506. self.setRng(rng);
  6507. } catch (ex) {
  6508. // Might fail on Opera for some odd reason
  6509. }
  6510. } else {
  6511. if (rng.item) {
  6512. // Delete content and get caret text selection
  6513. doc.execCommand('Delete', false, null);
  6514. rng = self.getRng();
  6515. }
  6516. // Explorer removes spaces from the beginning of pasted contents
  6517. if (/^\s+/.test(content)) {
  6518. rng.pasteHTML('<span id="__mce_tmp">_</span>' + content);
  6519. self.dom.remove('__mce_tmp');
  6520. } else
  6521. rng.pasteHTML(content);
  6522. }
  6523. // Dispatch set content event
  6524. if (!args.no_events)
  6525. self.onSetContent.dispatch(self, args);
  6526. },
  6527. getStart : function() {
  6528. var self = this, rng = self.getRng(), startElement, parentElement, checkRng, node;
  6529. if (rng.duplicate || rng.item) {
  6530. // Control selection, return first item
  6531. if (rng.item)
  6532. return rng.item(0);
  6533. // Get start element
  6534. checkRng = rng.duplicate();
  6535. checkRng.collapse(1);
  6536. startElement = checkRng.parentElement();
  6537. if (startElement.ownerDocument !== self.dom.doc) {
  6538. startElement = self.dom.getRoot();
  6539. }
  6540. // Check if range parent is inside the start element, then return the inner parent element
  6541. // This will fix issues when a single element is selected, IE would otherwise return the wrong start element
  6542. parentElement = node = rng.parentElement();
  6543. while (node = node.parentNode) {
  6544. if (node == startElement) {
  6545. startElement = parentElement;
  6546. break;
  6547. }
  6548. }
  6549. return startElement;
  6550. } else {
  6551. startElement = rng.startContainer;
  6552. if (startElement.nodeType == 1 && startElement.hasChildNodes())
  6553. startElement = startElement.childNodes[Math.min(startElement.childNodes.length - 1, rng.startOffset)];
  6554. if (startElement && startElement.nodeType == 3)
  6555. return startElement.parentNode;
  6556. return startElement;
  6557. }
  6558. },
  6559. getEnd : function() {
  6560. var self = this, rng = self.getRng(), endElement, endOffset;
  6561. if (rng.duplicate || rng.item) {
  6562. if (rng.item)
  6563. return rng.item(0);
  6564. rng = rng.duplicate();
  6565. rng.collapse(0);
  6566. endElement = rng.parentElement();
  6567. if (endElement.ownerDocument !== self.dom.doc) {
  6568. endElement = self.dom.getRoot();
  6569. }
  6570. if (endElement && endElement.nodeName == 'BODY')
  6571. return endElement.lastChild || endElement;
  6572. return endElement;
  6573. } else {
  6574. endElement = rng.endContainer;
  6575. endOffset = rng.endOffset;
  6576. if (endElement.nodeType == 1 && endElement.hasChildNodes())
  6577. endElement = endElement.childNodes[endOffset > 0 ? endOffset - 1 : endOffset];
  6578. if (endElement && endElement.nodeType == 3)
  6579. return endElement.parentNode;
  6580. return endElement;
  6581. }
  6582. },
  6583. getBookmark : function(type, normalized) {
  6584. var t = this, dom = t.dom, rng, rng2, id, collapsed, name, element, index, chr = '\uFEFF', styles;
  6585. function findIndex(name, element) {
  6586. var index = 0;
  6587. each(dom.select(name), function(node, i) {
  6588. if (node == element)
  6589. index = i;
  6590. });
  6591. return index;
  6592. };
  6593. function normalizeTableCellSelection(rng) {
  6594. function moveEndPoint(start) {
  6595. var container, offset, childNodes, prefix = start ? 'start' : 'end';
  6596. container = rng[prefix + 'Container'];
  6597. offset = rng[prefix + 'Offset'];
  6598. if (container.nodeType == 1 && container.nodeName == "TR") {
  6599. childNodes = container.childNodes;
  6600. container = childNodes[Math.min(start ? offset : offset - 1, childNodes.length - 1)];
  6601. if (container) {
  6602. offset = start ? 0 : container.childNodes.length;
  6603. rng['set' + (start ? 'Start' : 'End')](container, offset);
  6604. }
  6605. }
  6606. };
  6607. moveEndPoint(true);
  6608. moveEndPoint();
  6609. return rng;
  6610. };
  6611. function getLocation() {
  6612. var rng = t.getRng(true), root = dom.getRoot(), bookmark = {};
  6613. function getPoint(rng, start) {
  6614. var container = rng[start ? 'startContainer' : 'endContainer'],
  6615. offset = rng[start ? 'startOffset' : 'endOffset'], point = [], node, childNodes, after = 0;
  6616. if (container.nodeType == 3) {
  6617. if (normalized) {
  6618. for (node = container.previousSibling; node && node.nodeType == 3; node = node.previousSibling)
  6619. offset += node.nodeValue.length;
  6620. }
  6621. point.push(offset);
  6622. } else {
  6623. childNodes = container.childNodes;
  6624. if (offset >= childNodes.length && childNodes.length) {
  6625. after = 1;
  6626. offset = Math.max(0, childNodes.length - 1);
  6627. }
  6628. point.push(t.dom.nodeIndex(childNodes[offset], normalized) + after);
  6629. }
  6630. for (; container && container != root; container = container.parentNode)
  6631. point.push(t.dom.nodeIndex(container, normalized));
  6632. return point;
  6633. };
  6634. bookmark.start = getPoint(rng, true);
  6635. if (!t.isCollapsed())
  6636. bookmark.end = getPoint(rng);
  6637. return bookmark;
  6638. };
  6639. if (type == 2) {
  6640. if (t.tridentSel)
  6641. return t.tridentSel.getBookmark(type);
  6642. return getLocation();
  6643. }
  6644. // Handle simple range
  6645. if (type)
  6646. return {rng : t.getRng()};
  6647. rng = t.getRng();
  6648. id = dom.uniqueId();
  6649. collapsed = tinyMCE.activeEditor.selection.isCollapsed();
  6650. styles = 'overflow:hidden;line-height:0px';
  6651. // Explorer method
  6652. if (rng.duplicate || rng.item) {
  6653. // Text selection
  6654. if (!rng.item) {
  6655. rng2 = rng.duplicate();
  6656. try {
  6657. // Insert start marker
  6658. rng.collapse();
  6659. rng.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_start" style="' + styles + '">' + chr + '</span>');
  6660. // Insert end marker
  6661. if (!collapsed) {
  6662. rng2.collapse(false);
  6663. // Detect the empty space after block elements in IE and move the end back one character <p></p>] becomes <p>]</p>
  6664. rng.moveToElementText(rng2.parentElement());
  6665. if (rng.compareEndPoints('StartToEnd', rng2) === 0)
  6666. rng2.move('character', -1);
  6667. rng2.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_end" style="' + styles + '">' + chr + '</span>');
  6668. }
  6669. } catch (ex) {
  6670. // IE might throw unspecified error so lets ignore it
  6671. return null;
  6672. }
  6673. } else {
  6674. // Control selection
  6675. element = rng.item(0);
  6676. name = element.nodeName;
  6677. return {name : name, index : findIndex(name, element)};
  6678. }
  6679. } else {
  6680. element = t.getNode();
  6681. name = element.nodeName;
  6682. if (name == 'IMG')
  6683. return {name : name, index : findIndex(name, element)};
  6684. // W3C method
  6685. rng2 = normalizeTableCellSelection(rng.cloneRange());
  6686. // Insert end marker
  6687. if (!collapsed) {
  6688. rng2.collapse(false);
  6689. rng2.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_end', style : styles}, chr));
  6690. }
  6691. rng = normalizeTableCellSelection(rng);
  6692. rng.collapse(true);
  6693. rng.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_start', style : styles}, chr));
  6694. }
  6695. t.moveToBookmark({id : id, keep : 1});
  6696. return {id : id};
  6697. },
  6698. moveToBookmark : function(bookmark) {
  6699. var t = this, dom = t.dom, marker1, marker2, rng, root, startContainer, endContainer, startOffset, endOffset;
  6700. function setEndPoint(start) {
  6701. var point = bookmark[start ? 'start' : 'end'], i, node, offset, children;
  6702. if (point) {
  6703. offset = point[0];
  6704. // Find container node
  6705. for (node = root, i = point.length - 1; i >= 1; i--) {
  6706. children = node.childNodes;
  6707. if (point[i] > children.length - 1)
  6708. return;
  6709. node = children[point[i]];
  6710. }
  6711. // Move text offset to best suitable location
  6712. if (node.nodeType === 3)
  6713. offset = Math.min(point[0], node.nodeValue.length);
  6714. // Move element offset to best suitable location
  6715. if (node.nodeType === 1)
  6716. offset = Math.min(point[0], node.childNodes.length);
  6717. // Set offset within container node
  6718. if (start)
  6719. rng.setStart(node, offset);
  6720. else
  6721. rng.setEnd(node, offset);
  6722. }
  6723. return true;
  6724. };
  6725. function restoreEndPoint(suffix) {
  6726. var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev, keep = bookmark.keep;
  6727. if (marker) {
  6728. node = marker.parentNode;
  6729. if (suffix == 'start') {
  6730. if (!keep) {
  6731. idx = dom.nodeIndex(marker);
  6732. } else {
  6733. node = marker.firstChild;
  6734. idx = 1;
  6735. }
  6736. startContainer = endContainer = node;
  6737. startOffset = endOffset = idx;
  6738. } else {
  6739. if (!keep) {
  6740. idx = dom.nodeIndex(marker);
  6741. } else {
  6742. node = marker.firstChild;
  6743. idx = 1;
  6744. }
  6745. endContainer = node;
  6746. endOffset = idx;
  6747. }
  6748. if (!keep) {
  6749. prev = marker.previousSibling;
  6750. next = marker.nextSibling;
  6751. // Remove all marker text nodes
  6752. each(tinymce.grep(marker.childNodes), function(node) {
  6753. if (node.nodeType == 3)
  6754. node.nodeValue = node.nodeValue.replace(/\uFEFF/g, '');
  6755. });
  6756. // Remove marker but keep children if for example contents where inserted into the marker
  6757. // Also remove duplicated instances of the marker for example by a split operation or by WebKit auto split on paste feature
  6758. while (marker = dom.get(bookmark.id + '_' + suffix))
  6759. dom.remove(marker, 1);
  6760. // If siblings are text nodes then merge them unless it's Opera since it some how removes the node
  6761. // 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
  6762. if (prev && next && prev.nodeType == next.nodeType && prev.nodeType == 3 && !tinymce.isOpera) {
  6763. idx = prev.nodeValue.length;
  6764. prev.appendData(next.nodeValue);
  6765. dom.remove(next);
  6766. if (suffix == 'start') {
  6767. startContainer = endContainer = prev;
  6768. startOffset = endOffset = idx;
  6769. } else {
  6770. endContainer = prev;
  6771. endOffset = idx;
  6772. }
  6773. }
  6774. }
  6775. }
  6776. };
  6777. function addBogus(node) {
  6778. // Adds a bogus BR element for empty block elements
  6779. if (dom.isBlock(node) && !node.innerHTML && !isIE)
  6780. node.innerHTML = '<br data-mce-bogus="1" />';
  6781. return node;
  6782. };
  6783. if (bookmark) {
  6784. if (bookmark.start) {
  6785. rng = dom.createRng();
  6786. root = dom.getRoot();
  6787. if (t.tridentSel)
  6788. return t.tridentSel.moveToBookmark(bookmark);
  6789. if (setEndPoint(true) && setEndPoint()) {
  6790. t.setRng(rng);
  6791. }
  6792. } else if (bookmark.id) {
  6793. // Restore start/end points
  6794. restoreEndPoint('start');
  6795. restoreEndPoint('end');
  6796. if (startContainer) {
  6797. rng = dom.createRng();
  6798. rng.setStart(addBogus(startContainer), startOffset);
  6799. rng.setEnd(addBogus(endContainer), endOffset);
  6800. t.setRng(rng);
  6801. }
  6802. } else if (bookmark.name) {
  6803. t.select(dom.select(bookmark.name)[bookmark.index]);
  6804. } else if (bookmark.rng)
  6805. t.setRng(bookmark.rng);
  6806. }
  6807. },
  6808. select : function(node, content) {
  6809. var t = this, dom = t.dom, rng = dom.createRng(), idx;
  6810. function setPoint(node, start) {
  6811. var walker = new TreeWalker(node, node);
  6812. do {
  6813. // Text node
  6814. if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length !== 0) {
  6815. if (start)
  6816. rng.setStart(node, 0);
  6817. else
  6818. rng.setEnd(node, node.nodeValue.length);
  6819. return;
  6820. }
  6821. // BR element
  6822. if (node.nodeName == 'BR') {
  6823. if (start)
  6824. rng.setStartBefore(node);
  6825. else
  6826. rng.setEndBefore(node);
  6827. return;
  6828. }
  6829. } while (node = (start ? walker.next() : walker.prev()));
  6830. };
  6831. if (node) {
  6832. idx = dom.nodeIndex(node);
  6833. rng.setStart(node.parentNode, idx);
  6834. rng.setEnd(node.parentNode, idx + 1);
  6835. // Find first/last text node or BR element
  6836. if (content) {
  6837. setPoint(node, 1);
  6838. setPoint(node);
  6839. }
  6840. t.setRng(rng);
  6841. }
  6842. return node;
  6843. },
  6844. isCollapsed : function() {
  6845. var t = this, r = t.getRng(), s = t.getSel();
  6846. if (!r || r.item)
  6847. return false;
  6848. if (r.compareEndPoints)
  6849. return r.compareEndPoints('StartToEnd', r) === 0;
  6850. return !s || r.collapsed;
  6851. },
  6852. collapse : function(to_start) {
  6853. var self = this, rng = self.getRng(), node;
  6854. // Control range on IE
  6855. if (rng.item) {
  6856. node = rng.item(0);
  6857. rng = self.win.document.body.createTextRange();
  6858. rng.moveToElementText(node);
  6859. }
  6860. rng.collapse(!!to_start);
  6861. self.setRng(rng);
  6862. },
  6863. getSel : function() {
  6864. var t = this, w = this.win;
  6865. return w.getSelection ? w.getSelection() : w.document.selection;
  6866. },
  6867. getRng : function(w3c) {
  6868. var self = this, selection, rng, elm, doc = self.win.document;
  6869. // Found tridentSel object then we need to use that one
  6870. if (w3c && self.tridentSel) {
  6871. return self.tridentSel.getRangeAt(0);
  6872. }
  6873. try {
  6874. if (selection = self.getSel()) {
  6875. rng = selection.rangeCount > 0 ? selection.getRangeAt(0) : (selection.createRange ? selection.createRange() : doc.createRange());
  6876. }
  6877. } catch (ex) {
  6878. // IE throws unspecified error here if TinyMCE is placed in a frame/iframe
  6879. }
  6880. // We have W3C ranges and it's IE then fake control selection since IE9 doesn't handle that correctly yet
  6881. if (tinymce.isIE && rng && rng.setStart && doc.selection.createRange().item) {
  6882. elm = doc.selection.createRange().item(0);
  6883. rng = doc.createRange();
  6884. rng.setStartBefore(elm);
  6885. rng.setEndAfter(elm);
  6886. }
  6887. // No range found then create an empty one
  6888. // This can occur when the editor is placed in a hidden container element on Gecko
  6889. // Or on IE when there was an exception
  6890. if (!rng) {
  6891. rng = doc.createRange ? doc.createRange() : doc.body.createTextRange();
  6892. }
  6893. // If range is at start of document then move it to start of body
  6894. if (rng.setStart && rng.startContainer.nodeType === 9 && rng.collapsed) {
  6895. elm = self.dom.getRoot();
  6896. rng.setStart(elm, 0);
  6897. rng.setEnd(elm, 0);
  6898. }
  6899. if (self.selectedRange && self.explicitRange) {
  6900. if (rng.compareBoundaryPoints(rng.START_TO_START, self.selectedRange) === 0 && rng.compareBoundaryPoints(rng.END_TO_END, self.selectedRange) === 0) {
  6901. // Safari, Opera and Chrome only ever select text which causes the range to change.
  6902. // This lets us use the originally set range if the selection hasn't been changed by the user.
  6903. rng = self.explicitRange;
  6904. } else {
  6905. self.selectedRange = null;
  6906. self.explicitRange = null;
  6907. }
  6908. }
  6909. return rng;
  6910. },
  6911. setRng : function(r, forward) {
  6912. var s, t = this;
  6913. if (!t.tridentSel) {
  6914. s = t.getSel();
  6915. if (s) {
  6916. t.explicitRange = r;
  6917. try {
  6918. s.removeAllRanges();
  6919. } catch (ex) {
  6920. // IE9 might throw errors here don't know why
  6921. }
  6922. s.addRange(r);
  6923. // Forward is set to false and we have an extend function
  6924. if (forward === false && s.extend) {
  6925. s.collapse(r.endContainer, r.endOffset);
  6926. s.extend(r.startContainer, r.startOffset);
  6927. }
  6928. // adding range isn't always successful so we need to check range count otherwise an exception can occur
  6929. t.selectedRange = s.rangeCount > 0 ? s.getRangeAt(0) : null;
  6930. }
  6931. } else {
  6932. // Is W3C Range
  6933. if (r.cloneRange) {
  6934. try {
  6935. t.tridentSel.addRange(r);
  6936. return;
  6937. } catch (ex) {
  6938. //IE9 throws an error here if called before selection is placed in the editor
  6939. }
  6940. }
  6941. // Is IE specific range
  6942. try {
  6943. r.select();
  6944. } catch (ex) {
  6945. // Needed for some odd IE bug #1843306
  6946. }
  6947. }
  6948. },
  6949. setNode : function(n) {
  6950. var t = this;
  6951. t.setContent(t.dom.getOuterHTML(n));
  6952. return n;
  6953. },
  6954. getNode : function() {
  6955. var t = this, rng = t.getRng(), sel = t.getSel(), elm, start = rng.startContainer, end = rng.endContainer;
  6956. function skipEmptyTextNodes(n, forwards) {
  6957. var orig = n;
  6958. while (n && n.nodeType === 3 && n.length === 0) {
  6959. n = forwards ? n.nextSibling : n.previousSibling;
  6960. }
  6961. return n || orig;
  6962. };
  6963. // Range maybe lost after the editor is made visible again
  6964. if (!rng)
  6965. return t.dom.getRoot();
  6966. if (rng.setStart) {
  6967. elm = rng.commonAncestorContainer;
  6968. // Handle selection a image or other control like element such as anchors
  6969. if (!rng.collapsed) {
  6970. if (rng.startContainer == rng.endContainer) {
  6971. if (rng.endOffset - rng.startOffset < 2) {
  6972. if (rng.startContainer.hasChildNodes())
  6973. elm = rng.startContainer.childNodes[rng.startOffset];
  6974. }
  6975. }
  6976. // If the anchor node is a element instead of a text node then return this element
  6977. //if (tinymce.isWebKit && sel.anchorNode && sel.anchorNode.nodeType == 1)
  6978. // return sel.anchorNode.childNodes[sel.anchorOffset];
  6979. // Handle cases where the selection is immediately wrapped around a node and return that node instead of it's parent.
  6980. // This happens when you double click an underlined word in FireFox.
  6981. if (start.nodeType === 3 && end.nodeType === 3) {
  6982. if (start.length === rng.startOffset) {
  6983. start = skipEmptyTextNodes(start.nextSibling, true);
  6984. } else {
  6985. start = start.parentNode;
  6986. }
  6987. if (rng.endOffset === 0) {
  6988. end = skipEmptyTextNodes(end.previousSibling, false);
  6989. } else {
  6990. end = end.parentNode;
  6991. }
  6992. if (start && start === end)
  6993. return start;
  6994. }
  6995. }
  6996. if (elm && elm.nodeType == 3)
  6997. return elm.parentNode;
  6998. return elm;
  6999. }
  7000. return rng.item ? rng.item(0) : rng.parentElement();
  7001. },
  7002. getSelectedBlocks : function(st, en) {
  7003. var t = this, dom = t.dom, sb, eb, n, bl = [];
  7004. sb = dom.getParent(st || t.getStart(), dom.isBlock);
  7005. eb = dom.getParent(en || t.getEnd(), dom.isBlock);
  7006. if (sb)
  7007. bl.push(sb);
  7008. if (sb && eb && sb != eb) {
  7009. n = sb;
  7010. var walker = new TreeWalker(sb, dom.getRoot());
  7011. while ((n = walker.next()) && n != eb) {
  7012. if (dom.isBlock(n))
  7013. bl.push(n);
  7014. }
  7015. }
  7016. if (eb && sb != eb)
  7017. bl.push(eb);
  7018. return bl;
  7019. },
  7020. isForward: function(){
  7021. var dom = this.dom, sel = this.getSel(), anchorRange, focusRange;
  7022. // No support for selection direction then always return true
  7023. if (!sel || sel.anchorNode == null || sel.focusNode == null) {
  7024. return true;
  7025. }
  7026. anchorRange = dom.createRng();
  7027. anchorRange.setStart(sel.anchorNode, sel.anchorOffset);
  7028. anchorRange.collapse(true);
  7029. focusRange = dom.createRng();
  7030. focusRange.setStart(sel.focusNode, sel.focusOffset);
  7031. focusRange.collapse(true);
  7032. return anchorRange.compareBoundaryPoints(anchorRange.START_TO_START, focusRange) <= 0;
  7033. },
  7034. normalize : function() {
  7035. var self = this, rng, normalized, collapsed, node, sibling;
  7036. function normalizeEndPoint(start) {
  7037. var container, offset, walker, dom = self.dom, body = dom.getRoot(), node, nonEmptyElementsMap, nodeName;
  7038. function hasBrBeforeAfter(node, left) {
  7039. var walker = new TreeWalker(node, dom.getParent(node.parentNode, dom.isBlock) || body);
  7040. while (node = walker[left ? 'prev' : 'next']()) {
  7041. if (node.nodeName === "BR") {
  7042. return true;
  7043. }
  7044. }
  7045. };
  7046. // Walks the dom left/right to find a suitable text node to move the endpoint into
  7047. // It will only walk within the current parent block or body and will stop if it hits a block or a BR/IMG
  7048. function findTextNodeRelative(left, startNode) {
  7049. var walker, lastInlineElement;
  7050. startNode = startNode || container;
  7051. walker = new TreeWalker(startNode, dom.getParent(startNode.parentNode, dom.isBlock) || body);
  7052. // Walk left until we hit a text node we can move to or a block/br/img
  7053. while (node = walker[left ? 'prev' : 'next']()) {
  7054. // Found text node that has a length
  7055. if (node.nodeType === 3 && node.nodeValue.length > 0) {
  7056. container = node;
  7057. offset = left ? node.nodeValue.length : 0;
  7058. normalized = true;
  7059. return;
  7060. }
  7061. // Break if we find a block or a BR/IMG/INPUT etc
  7062. if (dom.isBlock(node) || nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  7063. return;
  7064. }
  7065. lastInlineElement = node;
  7066. }
  7067. // Only fetch the last inline element when in caret mode for now
  7068. if (collapsed && lastInlineElement) {
  7069. container = lastInlineElement;
  7070. normalized = true;
  7071. offset = 0;
  7072. }
  7073. };
  7074. container = rng[(start ? 'start' : 'end') + 'Container'];
  7075. offset = rng[(start ? 'start' : 'end') + 'Offset'];
  7076. nonEmptyElementsMap = dom.schema.getNonEmptyElements();
  7077. // If the container is a document move it to the body element
  7078. if (container.nodeType === 9) {
  7079. container = dom.getRoot();
  7080. offset = 0;
  7081. }
  7082. // If the container is body try move it into the closest text node or position
  7083. if (container === body) {
  7084. // If start is before/after a image, table etc
  7085. if (start) {
  7086. node = container.childNodes[offset > 0 ? offset - 1 : 0];
  7087. if (node) {
  7088. nodeName = node.nodeName.toLowerCase();
  7089. if (nonEmptyElementsMap[node.nodeName] || node.nodeName == "TABLE") {
  7090. return;
  7091. }
  7092. }
  7093. }
  7094. // Resolve the index
  7095. if (container.hasChildNodes()) {
  7096. container = container.childNodes[Math.min(!start && offset > 0 ? offset - 1 : offset, container.childNodes.length - 1)];
  7097. offset = 0;
  7098. // Don't walk into elements that doesn't have any child nodes like a IMG
  7099. if (container.hasChildNodes() && !/TABLE/.test(container.nodeName)) {
  7100. // Walk the DOM to find a text node to place the caret at or a BR
  7101. node = container;
  7102. walker = new TreeWalker(container, body);
  7103. do {
  7104. // Found a text node use that position
  7105. if (node.nodeType === 3 && node.nodeValue.length > 0) {
  7106. offset = start ? 0 : node.nodeValue.length;
  7107. container = node;
  7108. normalized = true;
  7109. break;
  7110. }
  7111. // Found a BR/IMG element that we can place the caret before
  7112. if (nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  7113. offset = dom.nodeIndex(node);
  7114. container = node.parentNode;
  7115. // Put caret after image when moving the end point
  7116. if (node.nodeName == "IMG" && !start) {
  7117. offset++;
  7118. }
  7119. normalized = true;
  7120. break;
  7121. }
  7122. } while (node = (start ? walker.next() : walker.prev()));
  7123. }
  7124. }
  7125. }
  7126. // Lean the caret to the left if possible
  7127. if (collapsed) {
  7128. // So this: <b>x</b><i>|x</i>
  7129. // Becomes: <b>x|</b><i>x</i>
  7130. // Seems that only gecko has issues with this
  7131. if (container.nodeType === 3 && offset === 0) {
  7132. findTextNodeRelative(true);
  7133. }
  7134. // Lean left into empty inline elements when the caret is before a BR
  7135. // So this: <i><b></b><i>|<br></i>
  7136. // Becomes: <i><b>|</b><i><br></i>
  7137. // Seems that only gecko has issues with this
  7138. if (container.nodeType === 1) {
  7139. node = container.childNodes[offset];
  7140. if(node && node.nodeName === 'BR' && !hasBrBeforeAfter(node) && !hasBrBeforeAfter(node, true)) {
  7141. findTextNodeRelative(true, container.childNodes[offset]);
  7142. }
  7143. }
  7144. }
  7145. // Lean the start of the selection right if possible
  7146. // So this: x[<b>x]</b>
  7147. // Becomes: x<b>[x]</b>
  7148. if (start && !collapsed && container.nodeType === 3 && offset === container.nodeValue.length) {
  7149. findTextNodeRelative(false);
  7150. }
  7151. // Set endpoint if it was normalized
  7152. if (normalized)
  7153. rng['set' + (start ? 'Start' : 'End')](container, offset);
  7154. };
  7155. // Normalize only on non IE browsers for now
  7156. if (tinymce.isIE)
  7157. return;
  7158. rng = self.getRng();
  7159. collapsed = rng.collapsed;
  7160. // Normalize the end points
  7161. normalizeEndPoint(true);
  7162. if (!collapsed)
  7163. normalizeEndPoint();
  7164. // Set the selection if it was normalized
  7165. if (normalized) {
  7166. // If it was collapsed then make sure it still is
  7167. if (collapsed) {
  7168. rng.collapse(true);
  7169. }
  7170. //console.log(self.dom.dumpRng(rng));
  7171. self.setRng(rng, self.isForward());
  7172. }
  7173. },
  7174. selectorChanged: function(selector, callback) {
  7175. var self = this, currentSelectors;
  7176. if (!self.selectorChangedData) {
  7177. self.selectorChangedData = {};
  7178. currentSelectors = {};
  7179. self.editor.onNodeChange.addToTop(function(ed, cm, node) {
  7180. var dom = self.dom, parents = dom.getParents(node, null, dom.getRoot()), matchedSelectors = {};
  7181. // Check for new matching selectors
  7182. each(self.selectorChangedData, function(callbacks, selector) {
  7183. each(parents, function(node) {
  7184. if (dom.is(node, selector)) {
  7185. if (!currentSelectors[selector]) {
  7186. // Execute callbacks
  7187. each(callbacks, function(callback) {
  7188. callback(true, {node: node, selector: selector, parents: parents});
  7189. });
  7190. currentSelectors[selector] = callbacks;
  7191. }
  7192. matchedSelectors[selector] = callbacks;
  7193. return false;
  7194. }
  7195. });
  7196. });
  7197. // Check if current selectors still match
  7198. each(currentSelectors, function(callbacks, selector) {
  7199. if (!matchedSelectors[selector]) {
  7200. delete currentSelectors[selector];
  7201. each(callbacks, function(callback) {
  7202. callback(false, {node: node, selector: selector, parents: parents});
  7203. });
  7204. }
  7205. });
  7206. });
  7207. }
  7208. // Add selector listeners
  7209. if (!self.selectorChangedData[selector]) {
  7210. self.selectorChangedData[selector] = [];
  7211. }
  7212. self.selectorChangedData[selector].push(callback);
  7213. return self;
  7214. },
  7215. destroy : function(manual) {
  7216. var self = this;
  7217. self.win = null;
  7218. // Manual destroy then remove unload handler
  7219. if (!manual)
  7220. tinymce.removeUnload(self.destroy);
  7221. },
  7222. // IE has an issue where you can't select/move the caret by clicking outside the body if the document is in standards mode
  7223. _fixIESelection : function() {
  7224. var dom = this.dom, doc = dom.doc, body = doc.body, started, startRng, htmlElm;
  7225. // Return range from point or null if it failed
  7226. function rngFromPoint(x, y) {
  7227. var rng = body.createTextRange();
  7228. try {
  7229. rng.moveToPoint(x, y);
  7230. } catch (ex) {
  7231. // IE sometimes throws and exception, so lets just ignore it
  7232. rng = null;
  7233. }
  7234. return rng;
  7235. };
  7236. // Fires while the selection is changing
  7237. function selectionChange(e) {
  7238. var pointRng;
  7239. // Check if the button is down or not
  7240. if (e.button) {
  7241. // Create range from mouse position
  7242. pointRng = rngFromPoint(e.x, e.y);
  7243. if (pointRng) {
  7244. // Check if pointRange is before/after selection then change the endPoint
  7245. if (pointRng.compareEndPoints('StartToStart', startRng) > 0)
  7246. pointRng.setEndPoint('StartToStart', startRng);
  7247. else
  7248. pointRng.setEndPoint('EndToEnd', startRng);
  7249. pointRng.select();
  7250. }
  7251. } else
  7252. endSelection();
  7253. }
  7254. // Removes listeners
  7255. function endSelection() {
  7256. var rng = doc.selection.createRange();
  7257. // If the range is collapsed then use the last start range
  7258. if (startRng && !rng.item && rng.compareEndPoints('StartToEnd', rng) === 0)
  7259. startRng.select();
  7260. dom.unbind(doc, 'mouseup', endSelection);
  7261. dom.unbind(doc, 'mousemove', selectionChange);
  7262. startRng = started = 0;
  7263. };
  7264. // Make HTML element unselectable since we are going to handle selection by hand
  7265. doc.documentElement.unselectable = true;
  7266. // Detect when user selects outside BODY
  7267. dom.bind(doc, ['mousedown', 'contextmenu'], function(e) {
  7268. if (e.target.nodeName === 'HTML') {
  7269. if (started)
  7270. endSelection();
  7271. // Detect vertical scrollbar, since IE will fire a mousedown on the scrollbar and have target set as HTML
  7272. htmlElm = doc.documentElement;
  7273. if (htmlElm.scrollHeight > htmlElm.clientHeight)
  7274. return;
  7275. started = 1;
  7276. // Setup start position
  7277. startRng = rngFromPoint(e.x, e.y);
  7278. if (startRng) {
  7279. // Listen for selection change events
  7280. dom.bind(doc, 'mouseup', endSelection);
  7281. dom.bind(doc, 'mousemove', selectionChange);
  7282. dom.win.focus();
  7283. startRng.select();
  7284. }
  7285. }
  7286. });
  7287. }
  7288. });
  7289. })(tinymce);
  7290. (function(tinymce) {
  7291. tinymce.dom.Serializer = function(settings, dom, schema) {
  7292. var onPreProcess, onPostProcess, isIE = tinymce.isIE, each = tinymce.each, htmlParser;
  7293. // Support the old apply_source_formatting option
  7294. if (!settings.apply_source_formatting)
  7295. settings.indent = false;
  7296. // Default DOM and Schema if they are undefined
  7297. dom = dom || tinymce.DOM;
  7298. schema = schema || new tinymce.html.Schema(settings);
  7299. settings.entity_encoding = settings.entity_encoding || 'named';
  7300. settings.remove_trailing_brs = "remove_trailing_brs" in settings ? settings.remove_trailing_brs : true;
  7301. onPreProcess = new tinymce.util.Dispatcher(self);
  7302. onPostProcess = new tinymce.util.Dispatcher(self);
  7303. htmlParser = new tinymce.html.DomParser(settings, schema);
  7304. // Convert move data-mce-src, data-mce-href and data-mce-style into nodes or process them if needed
  7305. htmlParser.addAttributeFilter('src,href,style', function(nodes, name) {
  7306. var i = nodes.length, node, value, internalName = 'data-mce-' + name, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope, undef;
  7307. while (i--) {
  7308. node = nodes[i];
  7309. value = node.attributes.map[internalName];
  7310. if (value !== undef) {
  7311. // Set external name to internal value and remove internal
  7312. node.attr(name, value.length > 0 ? value : null);
  7313. node.attr(internalName, null);
  7314. } else {
  7315. // No internal attribute found then convert the value we have in the DOM
  7316. value = node.attributes.map[name];
  7317. if (name === "style")
  7318. value = dom.serializeStyle(dom.parseStyle(value), node.name);
  7319. else if (urlConverter)
  7320. value = urlConverter.call(urlConverterScope, value, name, node.name);
  7321. node.attr(name, value.length > 0 ? value : null);
  7322. }
  7323. }
  7324. });
  7325. // Remove internal classes mceItem<..> or mceSelected
  7326. htmlParser.addAttributeFilter('class', function(nodes, name) {
  7327. var i = nodes.length, node, value;
  7328. while (i--) {
  7329. node = nodes[i];
  7330. value = node.attr('class').replace(/(?:^|\s)mce(Item\w+|Selected)(?!\S)/g, '');
  7331. node.attr('class', value.length > 0 ? value : null);
  7332. }
  7333. });
  7334. // Remove bookmark elements
  7335. htmlParser.addAttributeFilter('data-mce-type', function(nodes, name, args) {
  7336. var i = nodes.length, node;
  7337. while (i--) {
  7338. node = nodes[i];
  7339. if (node.attributes.map['data-mce-type'] === 'bookmark' && !args.cleanup)
  7340. node.remove();
  7341. }
  7342. });
  7343. // Remove expando attributes
  7344. htmlParser.addAttributeFilter('data-mce-expando', function(nodes, name, args) {
  7345. var i = nodes.length;
  7346. while (i--) {
  7347. nodes[i].attr(name, null);
  7348. }
  7349. });
  7350. htmlParser.addNodeFilter('noscript', function(nodes) {
  7351. var i = nodes.length, node;
  7352. while (i--) {
  7353. node = nodes[i].firstChild;
  7354. if (node) {
  7355. node.value = tinymce.html.Entities.decode(node.value);
  7356. }
  7357. }
  7358. });
  7359. // Force script into CDATA sections and remove the mce- prefix also add comments around styles
  7360. htmlParser.addNodeFilter('script,style', function(nodes, name) {
  7361. var i = nodes.length, node, value;
  7362. function trim(value) {
  7363. return value.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n')
  7364. .replace(/^[\r\n]*|[\r\n]*$/g, '')
  7365. .replace(/^\s*((<!--)?(\s*\/\/)?\s*<!\[CDATA\[|(<!--\s*)?\/\*\s*<!\[CDATA\[\s*\*\/|(\/\/)?\s*<!--|\/\*\s*<!--\s*\*\/)\s*[\r\n]*/gi, '')
  7366. .replace(/\s*(\/\*\s*\]\]>\s*\*\/(-->)?|\s*\/\/\s*\]\]>(-->)?|\/\/\s*(-->)?|\]\]>|\/\*\s*-->\s*\*\/|\s*-->\s*)\s*$/g, '');
  7367. };
  7368. while (i--) {
  7369. node = nodes[i];
  7370. value = node.firstChild ? node.firstChild.value : '';
  7371. if (name === "script") {
  7372. // Remove mce- prefix from script elements
  7373. node.attr('type', (node.attr('type') || 'text/javascript').replace(/^mce\-/, ''));
  7374. if (value.length > 0)
  7375. node.firstChild.value = '// <![CDATA[\n' + trim(value) + '\n// ]]>';
  7376. } else {
  7377. if (value.length > 0)
  7378. node.firstChild.value = '<!--\n' + trim(value) + '\n-->';
  7379. }
  7380. }
  7381. });
  7382. // Convert comments to cdata and handle protected comments
  7383. htmlParser.addNodeFilter('#comment', function(nodes, name) {
  7384. var i = nodes.length, node;
  7385. while (i--) {
  7386. node = nodes[i];
  7387. if (node.value.indexOf('[CDATA[') === 0) {
  7388. node.name = '#cdata';
  7389. node.type = 4;
  7390. node.value = node.value.replace(/^\[CDATA\[|\]\]$/g, '');
  7391. } else if (node.value.indexOf('mce:protected ') === 0) {
  7392. node.name = "#text";
  7393. node.type = 3;
  7394. node.raw = true;
  7395. node.value = unescape(node.value).substr(14);
  7396. }
  7397. }
  7398. });
  7399. htmlParser.addNodeFilter('xml:namespace,input', function(nodes, name) {
  7400. var i = nodes.length, node;
  7401. while (i--) {
  7402. node = nodes[i];
  7403. if (node.type === 7)
  7404. node.remove();
  7405. else if (node.type === 1) {
  7406. if (name === "input" && !("type" in node.attributes.map))
  7407. node.attr('type', 'text');
  7408. }
  7409. }
  7410. });
  7411. // Fix list elements, TODO: Replace this later
  7412. if (settings.fix_list_elements) {
  7413. htmlParser.addNodeFilter('ul,ol', function(nodes, name) {
  7414. var i = nodes.length, node, parentNode;
  7415. while (i--) {
  7416. node = nodes[i];
  7417. parentNode = node.parent;
  7418. if (parentNode.name === 'ul' || parentNode.name === 'ol') {
  7419. if (node.prev && node.prev.name === 'li') {
  7420. node.prev.append(node);
  7421. }
  7422. }
  7423. }
  7424. });
  7425. }
  7426. // Remove internal data attributes
  7427. htmlParser.addAttributeFilter('data-mce-src,data-mce-href,data-mce-style', function(nodes, name) {
  7428. var i = nodes.length;
  7429. while (i--) {
  7430. nodes[i].attr(name, null);
  7431. }
  7432. });
  7433. // Return public methods
  7434. return {
  7435. schema : schema,
  7436. addNodeFilter : htmlParser.addNodeFilter,
  7437. addAttributeFilter : htmlParser.addAttributeFilter,
  7438. onPreProcess : onPreProcess,
  7439. onPostProcess : onPostProcess,
  7440. serialize : function(node, args) {
  7441. var impl, doc, oldDoc, htmlSerializer, content;
  7442. // Explorer won't clone contents of script and style and the
  7443. // selected index of select elements are cleared on a clone operation.
  7444. if (isIE && dom.select('script,style,select,map').length > 0) {
  7445. content = node.innerHTML;
  7446. node = node.cloneNode(false);
  7447. dom.setHTML(node, content);
  7448. } else
  7449. node = node.cloneNode(true);
  7450. // Nodes needs to be attached to something in WebKit/Opera
  7451. // Older builds of Opera crashes if you attach the node to an document created dynamically
  7452. // and since we can't feature detect a crash we need to sniff the acutal build number
  7453. // This fix will make DOM ranges and make Sizzle happy!
  7454. impl = node.ownerDocument.implementation;
  7455. if (impl.createHTMLDocument) {
  7456. // Create an empty HTML document
  7457. doc = impl.createHTMLDocument("");
  7458. // Add the element or it's children if it's a body element to the new document
  7459. each(node.nodeName == 'BODY' ? node.childNodes : [node], function(node) {
  7460. doc.body.appendChild(doc.importNode(node, true));
  7461. });
  7462. // Grab first child or body element for serialization
  7463. if (node.nodeName != 'BODY')
  7464. node = doc.body.firstChild;
  7465. else
  7466. node = doc.body;
  7467. // set the new document in DOMUtils so createElement etc works
  7468. oldDoc = dom.doc;
  7469. dom.doc = doc;
  7470. }
  7471. args = args || {};
  7472. args.format = args.format || 'html';
  7473. // Pre process
  7474. if (!args.no_events) {
  7475. args.node = node;
  7476. onPreProcess.dispatch(self, args);
  7477. }
  7478. // Setup serializer
  7479. htmlSerializer = new tinymce.html.Serializer(settings, schema);
  7480. // Parse and serialize HTML
  7481. args.content = htmlSerializer.serialize(
  7482. htmlParser.parse(tinymce.trim(args.getInner ? node.innerHTML : dom.getOuterHTML(node)), args)
  7483. );
  7484. // Replace all BOM characters for now until we can find a better solution
  7485. if (!args.cleanup)
  7486. args.content = args.content.replace(/\uFEFF/g, '');
  7487. // Post process
  7488. if (!args.no_events)
  7489. onPostProcess.dispatch(self, args);
  7490. // Restore the old document if it was changed
  7491. if (oldDoc)
  7492. dom.doc = oldDoc;
  7493. args.node = null;
  7494. return args.content;
  7495. },
  7496. addRules : function(rules) {
  7497. schema.addValidElements(rules);
  7498. },
  7499. setRules : function(rules) {
  7500. schema.setValidElements(rules);
  7501. }
  7502. };
  7503. };
  7504. })(tinymce);
  7505. (function(tinymce) {
  7506. tinymce.dom.ScriptLoader = function(settings) {
  7507. var QUEUED = 0,
  7508. LOADING = 1,
  7509. LOADED = 2,
  7510. states = {},
  7511. queue = [],
  7512. scriptLoadedCallbacks = {},
  7513. queueLoadedCallbacks = [],
  7514. loading = 0,
  7515. undef;
  7516. function loadScript(url, callback) {
  7517. var t = this, dom = tinymce.DOM, elm, uri, loc, id;
  7518. // Execute callback when script is loaded
  7519. function done() {
  7520. dom.remove(id);
  7521. if (elm)
  7522. elm.onreadystatechange = elm.onload = elm = null;
  7523. callback();
  7524. };
  7525. function error() {
  7526. // Report the error so it's easier for people to spot loading errors
  7527. if (typeof(console) !== "undefined" && console.log)
  7528. console.log("Failed to load: " + url);
  7529. // We can't mark it as done if there is a load error since
  7530. // A) We don't want to produce 404 errors on the server and
  7531. // B) the onerror event won't fire on all browsers.
  7532. // done();
  7533. };
  7534. id = dom.uniqueId();
  7535. if (tinymce.isIE6) {
  7536. uri = new tinymce.util.URI(url);
  7537. loc = location;
  7538. // If script is from same domain and we
  7539. // use IE 6 then use XHR since it's more reliable
  7540. if (uri.host == loc.hostname && uri.port == loc.port && (uri.protocol + ':') == loc.protocol && uri.protocol.toLowerCase() != 'file') {
  7541. tinymce.util.XHR.send({
  7542. url : tinymce._addVer(uri.getURI()),
  7543. success : function(content) {
  7544. // Create new temp script element
  7545. var script = dom.create('script', {
  7546. type : 'text/javascript'
  7547. });
  7548. // Evaluate script in global scope
  7549. script.text = content;
  7550. document.getElementsByTagName('head')[0].appendChild(script);
  7551. dom.remove(script);
  7552. done();
  7553. },
  7554. error : error
  7555. });
  7556. return;
  7557. }
  7558. }
  7559. // Create new script element
  7560. elm = document.createElement('script');
  7561. elm.id = id;
  7562. elm.type = 'text/javascript';
  7563. elm.src = tinymce._addVer(url);
  7564. // Add onload listener for non IE browsers since IE9
  7565. // fires onload event before the script is parsed and executed
  7566. if (!tinymce.isIE)
  7567. elm.onload = done;
  7568. // Add onerror event will get fired on some browsers but not all of them
  7569. elm.onerror = error;
  7570. // Opera 9.60 doesn't seem to fire the onreadystate event at correctly
  7571. if (!tinymce.isOpera) {
  7572. elm.onreadystatechange = function() {
  7573. var state = elm.readyState;
  7574. // Loaded state is passed on IE 6 however there
  7575. // are known issues with this method but we can't use
  7576. // XHR in a cross domain loading
  7577. if (state == 'complete' || state == 'loaded')
  7578. done();
  7579. };
  7580. }
  7581. // Most browsers support this feature so we report errors
  7582. // for those at least to help users track their missing plugins etc
  7583. // todo: Removed since it produced error if the document is unloaded by navigating away, re-add it as an option
  7584. /*elm.onerror = function() {
  7585. alert('Failed to load: ' + url);
  7586. };*/
  7587. // Add script to document
  7588. (document.getElementsByTagName('head')[0] || document.body).appendChild(elm);
  7589. };
  7590. this.isDone = function(url) {
  7591. return states[url] == LOADED;
  7592. };
  7593. this.markDone = function(url) {
  7594. states[url] = LOADED;
  7595. };
  7596. this.add = this.load = function(url, callback, scope) {
  7597. var item, state = states[url];
  7598. // Add url to load queue
  7599. if (state == undef) {
  7600. queue.push(url);
  7601. states[url] = QUEUED;
  7602. }
  7603. if (callback) {
  7604. // Store away callback for later execution
  7605. if (!scriptLoadedCallbacks[url])
  7606. scriptLoadedCallbacks[url] = [];
  7607. scriptLoadedCallbacks[url].push({
  7608. func : callback,
  7609. scope : scope || this
  7610. });
  7611. }
  7612. };
  7613. this.loadQueue = function(callback, scope) {
  7614. this.loadScripts(queue, callback, scope);
  7615. };
  7616. this.loadScripts = function(scripts, callback, scope) {
  7617. var loadScripts;
  7618. function execScriptLoadedCallbacks(url) {
  7619. // Execute URL callback functions
  7620. tinymce.each(scriptLoadedCallbacks[url], function(callback) {
  7621. callback.func.call(callback.scope);
  7622. });
  7623. scriptLoadedCallbacks[url] = undef;
  7624. };
  7625. queueLoadedCallbacks.push({
  7626. func : callback,
  7627. scope : scope || this
  7628. });
  7629. loadScripts = function() {
  7630. var loadingScripts = tinymce.grep(scripts);
  7631. // Current scripts has been handled
  7632. scripts.length = 0;
  7633. // Load scripts that needs to be loaded
  7634. tinymce.each(loadingScripts, function(url) {
  7635. // Script is already loaded then execute script callbacks directly
  7636. if (states[url] == LOADED) {
  7637. execScriptLoadedCallbacks(url);
  7638. return;
  7639. }
  7640. // Is script not loading then start loading it
  7641. if (states[url] != LOADING) {
  7642. states[url] = LOADING;
  7643. loading++;
  7644. loadScript(url, function() {
  7645. states[url] = LOADED;
  7646. loading--;
  7647. execScriptLoadedCallbacks(url);
  7648. // Load more scripts if they where added by the recently loaded script
  7649. loadScripts();
  7650. });
  7651. }
  7652. });
  7653. // No scripts are currently loading then execute all pending queue loaded callbacks
  7654. if (!loading) {
  7655. tinymce.each(queueLoadedCallbacks, function(callback) {
  7656. callback.func.call(callback.scope);
  7657. });
  7658. queueLoadedCallbacks.length = 0;
  7659. }
  7660. };
  7661. loadScripts();
  7662. };
  7663. };
  7664. // Global script loader
  7665. tinymce.ScriptLoader = new tinymce.dom.ScriptLoader();
  7666. })(tinymce);
  7667. (function(tinymce) {
  7668. tinymce.dom.RangeUtils = function(dom) {
  7669. var INVISIBLE_CHAR = '\uFEFF';
  7670. this.walk = function(rng, callback) {
  7671. var startContainer = rng.startContainer,
  7672. startOffset = rng.startOffset,
  7673. endContainer = rng.endContainer,
  7674. endOffset = rng.endOffset,
  7675. ancestor, startPoint,
  7676. endPoint, node, parent, siblings, nodes;
  7677. // Handle table cell selection the table plugin enables
  7678. // you to fake select table cells and perform formatting actions on them
  7679. nodes = dom.select('td.mceSelected,th.mceSelected');
  7680. if (nodes.length > 0) {
  7681. tinymce.each(nodes, function(node) {
  7682. callback([node]);
  7683. });
  7684. return;
  7685. }
  7686. function exclude(nodes) {
  7687. var node;
  7688. // First node is excluded
  7689. node = nodes[0];
  7690. if (node.nodeType === 3 && node === startContainer && startOffset >= node.nodeValue.length) {
  7691. nodes.splice(0, 1);
  7692. }
  7693. // Last node is excluded
  7694. node = nodes[nodes.length - 1];
  7695. if (endOffset === 0 && nodes.length > 0 && node === endContainer && node.nodeType === 3) {
  7696. nodes.splice(nodes.length - 1, 1);
  7697. }
  7698. return nodes;
  7699. };
  7700. function collectSiblings(node, name, end_node) {
  7701. var siblings = [];
  7702. for (; node && node != end_node; node = node[name])
  7703. siblings.push(node);
  7704. return siblings;
  7705. };
  7706. function findEndPoint(node, root) {
  7707. do {
  7708. if (node.parentNode == root)
  7709. return node;
  7710. node = node.parentNode;
  7711. } while(node);
  7712. };
  7713. function walkBoundary(start_node, end_node, next) {
  7714. var siblingName = next ? 'nextSibling' : 'previousSibling';
  7715. for (node = start_node, parent = node.parentNode; node && node != end_node; node = parent) {
  7716. parent = node.parentNode;
  7717. siblings = collectSiblings(node == start_node ? node : node[siblingName], siblingName);
  7718. if (siblings.length) {
  7719. if (!next)
  7720. siblings.reverse();
  7721. callback(exclude(siblings));
  7722. }
  7723. }
  7724. };
  7725. // If index based start position then resolve it
  7726. if (startContainer.nodeType == 1 && startContainer.hasChildNodes())
  7727. startContainer = startContainer.childNodes[startOffset];
  7728. // If index based end position then resolve it
  7729. if (endContainer.nodeType == 1 && endContainer.hasChildNodes())
  7730. endContainer = endContainer.childNodes[Math.min(endOffset - 1, endContainer.childNodes.length - 1)];
  7731. // Same container
  7732. if (startContainer == endContainer)
  7733. return callback(exclude([startContainer]));
  7734. // Find common ancestor and end points
  7735. ancestor = dom.findCommonAncestor(startContainer, endContainer);
  7736. // Process left side
  7737. for (node = startContainer; node; node = node.parentNode) {
  7738. if (node === endContainer)
  7739. return walkBoundary(startContainer, ancestor, true);
  7740. if (node === ancestor)
  7741. break;
  7742. }
  7743. // Process right side
  7744. for (node = endContainer; node; node = node.parentNode) {
  7745. if (node === startContainer)
  7746. return walkBoundary(endContainer, ancestor);
  7747. if (node === ancestor)
  7748. break;
  7749. }
  7750. // Find start/end point
  7751. startPoint = findEndPoint(startContainer, ancestor) || startContainer;
  7752. endPoint = findEndPoint(endContainer, ancestor) || endContainer;
  7753. // Walk left leaf
  7754. walkBoundary(startContainer, startPoint, true);
  7755. // Walk the middle from start to end point
  7756. siblings = collectSiblings(
  7757. startPoint == startContainer ? startPoint : startPoint.nextSibling,
  7758. 'nextSibling',
  7759. endPoint == endContainer ? endPoint.nextSibling : endPoint
  7760. );
  7761. if (siblings.length)
  7762. callback(exclude(siblings));
  7763. // Walk right leaf
  7764. walkBoundary(endContainer, endPoint);
  7765. };
  7766. this.split = function(rng) {
  7767. var startContainer = rng.startContainer,
  7768. startOffset = rng.startOffset,
  7769. endContainer = rng.endContainer,
  7770. endOffset = rng.endOffset;
  7771. function splitText(node, offset) {
  7772. return node.splitText(offset);
  7773. };
  7774. // Handle single text node
  7775. if (startContainer == endContainer && startContainer.nodeType == 3) {
  7776. if (startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  7777. endContainer = splitText(startContainer, startOffset);
  7778. startContainer = endContainer.previousSibling;
  7779. if (endOffset > startOffset) {
  7780. endOffset = endOffset - startOffset;
  7781. startContainer = endContainer = splitText(endContainer, endOffset).previousSibling;
  7782. endOffset = endContainer.nodeValue.length;
  7783. startOffset = 0;
  7784. } else {
  7785. endOffset = 0;
  7786. }
  7787. }
  7788. } else {
  7789. // Split startContainer text node if needed
  7790. if (startContainer.nodeType == 3 && startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  7791. startContainer = splitText(startContainer, startOffset);
  7792. startOffset = 0;
  7793. }
  7794. // Split endContainer text node if needed
  7795. if (endContainer.nodeType == 3 && endOffset > 0 && endOffset < endContainer.nodeValue.length) {
  7796. endContainer = splitText(endContainer, endOffset).previousSibling;
  7797. endOffset = endContainer.nodeValue.length;
  7798. }
  7799. }
  7800. return {
  7801. startContainer : startContainer,
  7802. startOffset : startOffset,
  7803. endContainer : endContainer,
  7804. endOffset : endOffset
  7805. };
  7806. };
  7807. };
  7808. tinymce.dom.RangeUtils.compareRanges = function(rng1, rng2) {
  7809. if (rng1 && rng2) {
  7810. // Compare native IE ranges
  7811. if (rng1.item || rng1.duplicate) {
  7812. // Both are control ranges and the selected element matches
  7813. if (rng1.item && rng2.item && rng1.item(0) === rng2.item(0))
  7814. return true;
  7815. // Both are text ranges and the range matches
  7816. if (rng1.isEqual && rng2.isEqual && rng2.isEqual(rng1))
  7817. return true;
  7818. } else {
  7819. // Compare w3c ranges
  7820. return rng1.startContainer == rng2.startContainer && rng1.startOffset == rng2.startOffset;
  7821. }
  7822. }
  7823. return false;
  7824. };
  7825. })(tinymce);
  7826. (function(tinymce) {
  7827. var Event = tinymce.dom.Event, each = tinymce.each;
  7828. tinymce.create('tinymce.ui.KeyboardNavigation', {
  7829. KeyboardNavigation: function(settings, dom) {
  7830. var t = this, root = settings.root, items = settings.items,
  7831. enableUpDown = settings.enableUpDown, enableLeftRight = settings.enableLeftRight || !settings.enableUpDown,
  7832. excludeFromTabOrder = settings.excludeFromTabOrder,
  7833. itemFocussed, itemBlurred, rootKeydown, rootFocussed, focussedId;
  7834. dom = dom || tinymce.DOM;
  7835. itemFocussed = function(evt) {
  7836. focussedId = evt.target.id;
  7837. };
  7838. itemBlurred = function(evt) {
  7839. dom.setAttrib(evt.target.id, 'tabindex', '-1');
  7840. };
  7841. rootFocussed = function(evt) {
  7842. var item = dom.get(focussedId);
  7843. dom.setAttrib(item, 'tabindex', '0');
  7844. item.focus();
  7845. };
  7846. t.focus = function() {
  7847. dom.get(focussedId).focus();
  7848. };
  7849. t.destroy = function() {
  7850. each(items, function(item) {
  7851. var elm = dom.get(item.id);
  7852. dom.unbind(elm, 'focus', itemFocussed);
  7853. dom.unbind(elm, 'blur', itemBlurred);
  7854. });
  7855. var rootElm = dom.get(root);
  7856. dom.unbind(rootElm, 'focus', rootFocussed);
  7857. dom.unbind(rootElm, 'keydown', rootKeydown);
  7858. items = dom = root = t.focus = itemFocussed = itemBlurred = rootKeydown = rootFocussed = null;
  7859. t.destroy = function() {};
  7860. };
  7861. t.moveFocus = function(dir, evt) {
  7862. var idx = -1, controls = t.controls, newFocus;
  7863. if (!focussedId)
  7864. return;
  7865. each(items, function(item, index) {
  7866. if (item.id === focussedId) {
  7867. idx = index;
  7868. return false;
  7869. }
  7870. });
  7871. idx += dir;
  7872. if (idx < 0) {
  7873. idx = items.length - 1;
  7874. } else if (idx >= items.length) {
  7875. idx = 0;
  7876. }
  7877. newFocus = items[idx];
  7878. dom.setAttrib(focussedId, 'tabindex', '-1');
  7879. dom.setAttrib(newFocus.id, 'tabindex', '0');
  7880. dom.get(newFocus.id).focus();
  7881. if (settings.actOnFocus) {
  7882. settings.onAction(newFocus.id);
  7883. }
  7884. if (evt)
  7885. Event.cancel(evt);
  7886. };
  7887. rootKeydown = function(evt) {
  7888. 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;
  7889. switch (evt.keyCode) {
  7890. case DOM_VK_LEFT:
  7891. if (enableLeftRight) t.moveFocus(-1);
  7892. break;
  7893. case DOM_VK_RIGHT:
  7894. if (enableLeftRight) t.moveFocus(1);
  7895. break;
  7896. case DOM_VK_UP:
  7897. if (enableUpDown) t.moveFocus(-1);
  7898. break;
  7899. case DOM_VK_DOWN:
  7900. if (enableUpDown) t.moveFocus(1);
  7901. break;
  7902. case DOM_VK_ESCAPE:
  7903. if (settings.onCancel) {
  7904. settings.onCancel();
  7905. Event.cancel(evt);
  7906. }
  7907. break;
  7908. case DOM_VK_ENTER:
  7909. case DOM_VK_RETURN:
  7910. case DOM_VK_SPACE:
  7911. if (settings.onAction) {
  7912. settings.onAction(focussedId);
  7913. Event.cancel(evt);
  7914. }
  7915. break;
  7916. }
  7917. };
  7918. // Set up state and listeners for each item.
  7919. each(items, function(item, idx) {
  7920. var tabindex, elm;
  7921. if (!item.id) {
  7922. item.id = dom.uniqueId('_mce_item_');
  7923. }
  7924. elm = dom.get(item.id);
  7925. if (excludeFromTabOrder) {
  7926. dom.bind(elm, 'blur', itemBlurred);
  7927. tabindex = '-1';
  7928. } else {
  7929. tabindex = (idx === 0 ? '0' : '-1');
  7930. }
  7931. elm.setAttribute('tabindex', tabindex);
  7932. dom.bind(elm, 'focus', itemFocussed);
  7933. });
  7934. // Setup initial state for root element.
  7935. if (items[0]){
  7936. focussedId = items[0].id;
  7937. }
  7938. dom.setAttrib(root, 'tabindex', '-1');
  7939. // Setup listeners for root element.
  7940. var rootElm = dom.get(root);
  7941. dom.bind(rootElm, 'focus', rootFocussed);
  7942. dom.bind(rootElm, 'keydown', rootKeydown);
  7943. }
  7944. });
  7945. })(tinymce);
  7946. (function(tinymce) {
  7947. // Shorten class names
  7948. var DOM = tinymce.DOM, is = tinymce.is;
  7949. tinymce.create('tinymce.ui.Control', {
  7950. Control : function(id, s, editor) {
  7951. this.id = id;
  7952. this.settings = s = s || {};
  7953. this.rendered = false;
  7954. this.onRender = new tinymce.util.Dispatcher(this);
  7955. this.classPrefix = '';
  7956. this.scope = s.scope || this;
  7957. this.disabled = 0;
  7958. this.active = 0;
  7959. this.editor = editor;
  7960. },
  7961. setAriaProperty : function(property, value) {
  7962. var element = DOM.get(this.id + '_aria') || DOM.get(this.id);
  7963. if (element) {
  7964. DOM.setAttrib(element, 'aria-' + property, !!value);
  7965. }
  7966. },
  7967. focus : function() {
  7968. DOM.get(this.id).focus();
  7969. },
  7970. setDisabled : function(s) {
  7971. if (s != this.disabled) {
  7972. this.setAriaProperty('disabled', s);
  7973. this.setState('Disabled', s);
  7974. this.setState('Enabled', !s);
  7975. this.disabled = s;
  7976. }
  7977. },
  7978. isDisabled : function() {
  7979. return this.disabled;
  7980. },
  7981. setActive : function(s) {
  7982. if (s != this.active) {
  7983. this.setState('Active', s);
  7984. this.active = s;
  7985. this.setAriaProperty('pressed', s);
  7986. }
  7987. },
  7988. isActive : function() {
  7989. return this.active;
  7990. },
  7991. setState : function(c, s) {
  7992. var n = DOM.get(this.id);
  7993. c = this.classPrefix + c;
  7994. if (s)
  7995. DOM.addClass(n, c);
  7996. else
  7997. DOM.removeClass(n, c);
  7998. },
  7999. isRendered : function() {
  8000. return this.rendered;
  8001. },
  8002. renderHTML : function() {
  8003. },
  8004. renderTo : function(n) {
  8005. DOM.setHTML(n, this.renderHTML());
  8006. },
  8007. postRender : function() {
  8008. var t = this, b;
  8009. // Set pending states
  8010. if (is(t.disabled)) {
  8011. b = t.disabled;
  8012. t.disabled = -1;
  8013. t.setDisabled(b);
  8014. }
  8015. if (is(t.active)) {
  8016. b = t.active;
  8017. t.active = -1;
  8018. t.setActive(b);
  8019. }
  8020. },
  8021. remove : function() {
  8022. DOM.remove(this.id);
  8023. this.destroy();
  8024. },
  8025. destroy : function() {
  8026. tinymce.dom.Event.clear(this.id);
  8027. }
  8028. });
  8029. })(tinymce);
  8030. tinymce.create('tinymce.ui.Container:tinymce.ui.Control', {
  8031. Container : function(id, s, editor) {
  8032. this.parent(id, s, editor);
  8033. this.controls = [];
  8034. this.lookup = {};
  8035. },
  8036. add : function(c) {
  8037. this.lookup[c.id] = c;
  8038. this.controls.push(c);
  8039. return c;
  8040. },
  8041. get : function(n) {
  8042. return this.lookup[n];
  8043. }
  8044. });
  8045. tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', {
  8046. Separator : function(id, s) {
  8047. this.parent(id, s);
  8048. this.classPrefix = 'mceSeparator';
  8049. this.setDisabled(true);
  8050. },
  8051. renderHTML : function() {
  8052. return tinymce.DOM.createHTML('span', {'class' : this.classPrefix, role : 'separator', 'aria-orientation' : 'vertical', tabindex : '-1'});
  8053. }
  8054. });
  8055. (function(tinymce) {
  8056. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  8057. tinymce.create('tinymce.ui.MenuItem:tinymce.ui.Control', {
  8058. MenuItem : function(id, s) {
  8059. this.parent(id, s);
  8060. this.classPrefix = 'mceMenuItem';
  8061. },
  8062. setSelected : function(s) {
  8063. this.setState('Selected', s);
  8064. this.setAriaProperty('checked', !!s);
  8065. this.selected = s;
  8066. },
  8067. isSelected : function() {
  8068. return this.selected;
  8069. },
  8070. postRender : function() {
  8071. var t = this;
  8072. t.parent();
  8073. // Set pending state
  8074. if (is(t.selected))
  8075. t.setSelected(t.selected);
  8076. }
  8077. });
  8078. })(tinymce);
  8079. (function(tinymce) {
  8080. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  8081. tinymce.create('tinymce.ui.Menu:tinymce.ui.MenuItem', {
  8082. Menu : function(id, s) {
  8083. var t = this;
  8084. t.parent(id, s);
  8085. t.items = {};
  8086. t.collapsed = false;
  8087. t.menuCount = 0;
  8088. t.onAddItem = new tinymce.util.Dispatcher(this);
  8089. },
  8090. expand : function(d) {
  8091. var t = this;
  8092. if (d) {
  8093. walk(t, function(o) {
  8094. if (o.expand)
  8095. o.expand();
  8096. }, 'items', t);
  8097. }
  8098. t.collapsed = false;
  8099. },
  8100. collapse : function(d) {
  8101. var t = this;
  8102. if (d) {
  8103. walk(t, function(o) {
  8104. if (o.collapse)
  8105. o.collapse();
  8106. }, 'items', t);
  8107. }
  8108. t.collapsed = true;
  8109. },
  8110. isCollapsed : function() {
  8111. return this.collapsed;
  8112. },
  8113. add : function(o) {
  8114. if (!o.settings)
  8115. o = new tinymce.ui.MenuItem(o.id || DOM.uniqueId(), o);
  8116. this.onAddItem.dispatch(this, o);
  8117. return this.items[o.id] = o;
  8118. },
  8119. addSeparator : function() {
  8120. return this.add({separator : true});
  8121. },
  8122. addMenu : function(o) {
  8123. if (!o.collapse)
  8124. o = this.createMenu(o);
  8125. this.menuCount++;
  8126. return this.add(o);
  8127. },
  8128. hasMenus : function() {
  8129. return this.menuCount !== 0;
  8130. },
  8131. remove : function(o) {
  8132. delete this.items[o.id];
  8133. },
  8134. removeAll : function() {
  8135. var t = this;
  8136. walk(t, function(o) {
  8137. if (o.removeAll)
  8138. o.removeAll();
  8139. else
  8140. o.remove();
  8141. o.destroy();
  8142. }, 'items', t);
  8143. t.items = {};
  8144. },
  8145. createMenu : function(o) {
  8146. var m = new tinymce.ui.Menu(o.id || DOM.uniqueId(), o);
  8147. m.onAddItem.add(this.onAddItem.dispatch, this.onAddItem);
  8148. return m;
  8149. }
  8150. });
  8151. })(tinymce);
  8152. (function(tinymce) {
  8153. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event, Element = tinymce.dom.Element;
  8154. tinymce.create('tinymce.ui.DropMenu:tinymce.ui.Menu', {
  8155. DropMenu : function(id, s) {
  8156. s = s || {};
  8157. s.container = s.container || DOM.doc.body;
  8158. s.offset_x = s.offset_x || 0;
  8159. s.offset_y = s.offset_y || 0;
  8160. s.vp_offset_x = s.vp_offset_x || 0;
  8161. s.vp_offset_y = s.vp_offset_y || 0;
  8162. if (is(s.icons) && !s.icons)
  8163. s['class'] += ' mceNoIcons';
  8164. this.parent(id, s);
  8165. this.onShowMenu = new tinymce.util.Dispatcher(this);
  8166. this.onHideMenu = new tinymce.util.Dispatcher(this);
  8167. this.classPrefix = 'mceMenu';
  8168. },
  8169. createMenu : function(s) {
  8170. var t = this, cs = t.settings, m;
  8171. s.container = s.container || cs.container;
  8172. s.parent = t;
  8173. s.constrain = s.constrain || cs.constrain;
  8174. s['class'] = s['class'] || cs['class'];
  8175. s.vp_offset_x = s.vp_offset_x || cs.vp_offset_x;
  8176. s.vp_offset_y = s.vp_offset_y || cs.vp_offset_y;
  8177. s.keyboard_focus = cs.keyboard_focus;
  8178. m = new tinymce.ui.DropMenu(s.id || DOM.uniqueId(), s);
  8179. m.onAddItem.add(t.onAddItem.dispatch, t.onAddItem);
  8180. return m;
  8181. },
  8182. focus : function() {
  8183. var t = this;
  8184. if (t.keyboardNav) {
  8185. t.keyboardNav.focus();
  8186. }
  8187. },
  8188. update : function() {
  8189. var t = this, s = t.settings, tb = DOM.get('menu_' + t.id + '_tbl'), co = DOM.get('menu_' + t.id + '_co'), tw, th;
  8190. tw = s.max_width ? Math.min(tb.offsetWidth, s.max_width) : tb.offsetWidth;
  8191. th = s.max_height ? Math.min(tb.offsetHeight, s.max_height) : tb.offsetHeight;
  8192. if (!DOM.boxModel)
  8193. t.element.setStyles({width : tw + 2, height : th + 2});
  8194. else
  8195. t.element.setStyles({width : tw, height : th});
  8196. if (s.max_width)
  8197. DOM.setStyle(co, 'width', tw);
  8198. if (s.max_height) {
  8199. DOM.setStyle(co, 'height', th);
  8200. if (tb.clientHeight < s.max_height)
  8201. DOM.setStyle(co, 'overflow', 'hidden');
  8202. }
  8203. },
  8204. showMenu : function(x, y, px) {
  8205. var t = this, s = t.settings, co, vp = DOM.getViewPort(), w, h, mx, my, ot = 2, dm, tb, cp = t.classPrefix;
  8206. t.collapse(1);
  8207. if (t.isMenuVisible)
  8208. return;
  8209. if (!t.rendered) {
  8210. co = DOM.add(t.settings.container, t.renderNode());
  8211. each(t.items, function(o) {
  8212. o.postRender();
  8213. });
  8214. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  8215. } else
  8216. co = DOM.get('menu_' + t.id);
  8217. // Move layer out of sight unless it's Opera since it scrolls to top of page due to an bug
  8218. if (!tinymce.isOpera)
  8219. DOM.setStyles(co, {left : -0xFFFF , top : -0xFFFF});
  8220. DOM.show(co);
  8221. t.update();
  8222. x += s.offset_x || 0;
  8223. y += s.offset_y || 0;
  8224. vp.w -= 4;
  8225. vp.h -= 4;
  8226. // Move inside viewport if not submenu
  8227. if (s.constrain) {
  8228. w = co.clientWidth - ot;
  8229. h = co.clientHeight - ot;
  8230. mx = vp.x + vp.w;
  8231. my = vp.y + vp.h;
  8232. if ((x + s.vp_offset_x + w) > mx)
  8233. x = px ? px - w : Math.max(0, (mx - s.vp_offset_x) - w);
  8234. if ((y + s.vp_offset_y + h) > my)
  8235. y = Math.max(0, (my - s.vp_offset_y) - h);
  8236. }
  8237. DOM.setStyles(co, {left : x , top : y});
  8238. t.element.update();
  8239. t.isMenuVisible = 1;
  8240. t.mouseClickFunc = Event.add(co, 'click', function(e) {
  8241. var m;
  8242. e = e.target;
  8243. if (e && (e = DOM.getParent(e, 'tr')) && !DOM.hasClass(e, cp + 'ItemSub')) {
  8244. m = t.items[e.id];
  8245. if (m.isDisabled())
  8246. return;
  8247. dm = t;
  8248. while (dm) {
  8249. if (dm.hideMenu)
  8250. dm.hideMenu();
  8251. dm = dm.settings.parent;
  8252. }
  8253. if (m.settings.onclick)
  8254. m.settings.onclick(e);
  8255. return false; // Cancel to fix onbeforeunload problem
  8256. }
  8257. });
  8258. if (t.hasMenus()) {
  8259. t.mouseOverFunc = Event.add(co, 'mouseover', function(e) {
  8260. var m, r, mi;
  8261. e = e.target;
  8262. if (e && (e = DOM.getParent(e, 'tr'))) {
  8263. m = t.items[e.id];
  8264. if (t.lastMenu)
  8265. t.lastMenu.collapse(1);
  8266. if (m.isDisabled())
  8267. return;
  8268. if (e && DOM.hasClass(e, cp + 'ItemSub')) {
  8269. //p = DOM.getPos(s.container);
  8270. r = DOM.getRect(e);
  8271. m.showMenu((r.x + r.w - ot), r.y - ot, r.x);
  8272. t.lastMenu = m;
  8273. DOM.addClass(DOM.get(m.id).firstChild, cp + 'ItemActive');
  8274. }
  8275. }
  8276. });
  8277. }
  8278. Event.add(co, 'keydown', t._keyHandler, t);
  8279. t.onShowMenu.dispatch(t);
  8280. if (s.keyboard_focus) {
  8281. t._setupKeyboardNav();
  8282. }
  8283. },
  8284. hideMenu : function(c) {
  8285. var t = this, co = DOM.get('menu_' + t.id), e;
  8286. if (!t.isMenuVisible)
  8287. return;
  8288. if (t.keyboardNav) t.keyboardNav.destroy();
  8289. Event.remove(co, 'mouseover', t.mouseOverFunc);
  8290. Event.remove(co, 'click', t.mouseClickFunc);
  8291. Event.remove(co, 'keydown', t._keyHandler);
  8292. DOM.hide(co);
  8293. t.isMenuVisible = 0;
  8294. if (!c)
  8295. t.collapse(1);
  8296. if (t.element)
  8297. t.element.hide();
  8298. if (e = DOM.get(t.id))
  8299. DOM.removeClass(e.firstChild, t.classPrefix + 'ItemActive');
  8300. t.onHideMenu.dispatch(t);
  8301. },
  8302. add : function(o) {
  8303. var t = this, co;
  8304. o = t.parent(o);
  8305. if (t.isRendered && (co = DOM.get('menu_' + t.id)))
  8306. t._add(DOM.select('tbody', co)[0], o);
  8307. return o;
  8308. },
  8309. collapse : function(d) {
  8310. this.parent(d);
  8311. this.hideMenu(1);
  8312. },
  8313. remove : function(o) {
  8314. DOM.remove(o.id);
  8315. this.destroy();
  8316. return this.parent(o);
  8317. },
  8318. destroy : function() {
  8319. var t = this, co = DOM.get('menu_' + t.id);
  8320. if (t.keyboardNav) t.keyboardNav.destroy();
  8321. Event.remove(co, 'mouseover', t.mouseOverFunc);
  8322. Event.remove(DOM.select('a', co), 'focus', t.mouseOverFunc);
  8323. Event.remove(co, 'click', t.mouseClickFunc);
  8324. Event.remove(co, 'keydown', t._keyHandler);
  8325. if (t.element)
  8326. t.element.remove();
  8327. DOM.remove(co);
  8328. },
  8329. renderNode : function() {
  8330. var t = this, s = t.settings, n, tb, co, w;
  8331. 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'});
  8332. if (t.settings.parent) {
  8333. DOM.setAttrib(w, 'aria-parent', 'menu_' + t.settings.parent.id);
  8334. }
  8335. co = DOM.add(w, 'div', {role: 'presentation', id : 'menu_' + t.id + '_co', 'class' : t.classPrefix + (s['class'] ? ' ' + s['class'] : '')});
  8336. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  8337. if (s.menu_line)
  8338. DOM.add(co, 'span', {'class' : t.classPrefix + 'Line'});
  8339. // n = DOM.add(co, 'div', {id : 'menu_' + t.id + '_co', 'class' : 'mceMenuContainer'});
  8340. n = DOM.add(co, 'table', {role: 'presentation', id : 'menu_' + t.id + '_tbl', border : 0, cellPadding : 0, cellSpacing : 0});
  8341. tb = DOM.add(n, 'tbody');
  8342. each(t.items, function(o) {
  8343. t._add(tb, o);
  8344. });
  8345. t.rendered = true;
  8346. return w;
  8347. },
  8348. // Internal functions
  8349. _setupKeyboardNav : function(){
  8350. var contextMenu, menuItems, t=this;
  8351. contextMenu = DOM.get('menu_' + t.id);
  8352. menuItems = DOM.select('a[role=option]', 'menu_' + t.id);
  8353. menuItems.splice(0,0,contextMenu);
  8354. t.keyboardNav = new tinymce.ui.KeyboardNavigation({
  8355. root: 'menu_' + t.id,
  8356. items: menuItems,
  8357. onCancel: function() {
  8358. t.hideMenu();
  8359. },
  8360. enableUpDown: true
  8361. });
  8362. contextMenu.focus();
  8363. },
  8364. _keyHandler : function(evt) {
  8365. var t = this, e;
  8366. switch (evt.keyCode) {
  8367. case 37: // Left
  8368. if (t.settings.parent) {
  8369. t.hideMenu();
  8370. t.settings.parent.focus();
  8371. Event.cancel(evt);
  8372. }
  8373. break;
  8374. case 39: // Right
  8375. if (t.mouseOverFunc)
  8376. t.mouseOverFunc(evt);
  8377. break;
  8378. }
  8379. },
  8380. _add : function(tb, o) {
  8381. var n, s = o.settings, a, ro, it, cp = this.classPrefix, ic;
  8382. if (s.separator) {
  8383. ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'ItemSeparator'});
  8384. DOM.add(ro, 'td', {'class' : cp + 'ItemSeparator'});
  8385. if (n = ro.previousSibling)
  8386. DOM.addClass(n, 'mceLast');
  8387. return;
  8388. }
  8389. n = ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'Item ' + cp + 'ItemEnabled'});
  8390. n = it = DOM.add(n, s.titleItem ? 'th' : 'td');
  8391. n = a = DOM.add(n, 'a', {id: o.id + '_aria', role: s.titleItem ? 'presentation' : 'option', href : 'javascript:;', onclick : "return false;", onmousedown : 'return false;'});
  8392. if (s.parent) {
  8393. DOM.setAttrib(a, 'aria-haspopup', 'true');
  8394. DOM.setAttrib(a, 'aria-owns', 'menu_' + o.id);
  8395. }
  8396. DOM.addClass(it, s['class']);
  8397. // n = DOM.add(n, 'span', {'class' : 'item'});
  8398. ic = DOM.add(n, 'span', {'class' : 'mceIcon' + (s.icon ? ' mce_' + s.icon : '')});
  8399. if (s.icon_src)
  8400. DOM.add(ic, 'img', {src : s.icon_src});
  8401. n = DOM.add(n, s.element || 'span', {'class' : 'mceText', title : o.settings.title}, o.settings.title);
  8402. if (o.settings.style) {
  8403. if (typeof o.settings.style == "function")
  8404. o.settings.style = o.settings.style();
  8405. DOM.setAttrib(n, 'style', o.settings.style);
  8406. }
  8407. if (tb.childNodes.length == 1)
  8408. DOM.addClass(ro, 'mceFirst');
  8409. if ((n = ro.previousSibling) && DOM.hasClass(n, cp + 'ItemSeparator'))
  8410. DOM.addClass(ro, 'mceFirst');
  8411. if (o.collapse)
  8412. DOM.addClass(ro, cp + 'ItemSub');
  8413. if (n = ro.previousSibling)
  8414. DOM.removeClass(n, 'mceLast');
  8415. DOM.addClass(ro, 'mceLast');
  8416. }
  8417. });
  8418. })(tinymce);
  8419. (function(tinymce) {
  8420. var DOM = tinymce.DOM;
  8421. tinymce.create('tinymce.ui.Button:tinymce.ui.Control', {
  8422. Button : function(id, s, ed) {
  8423. this.parent(id, s, ed);
  8424. this.classPrefix = 'mceButton';
  8425. },
  8426. renderHTML : function() {
  8427. var cp = this.classPrefix, s = this.settings, h, l;
  8428. l = DOM.encode(s.label || '');
  8429. 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) + '">';
  8430. if (s.image && !(this.editor &&this.editor.forcedHighContrastMode) )
  8431. 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>' : '');
  8432. else
  8433. h += '<span class="mceIcon ' + s['class'] + '"></span>' + (l ? '<span class="' + cp + 'Label">' + l + '</span>' : '');
  8434. h += '<span class="mceVoiceLabel mceIconOnly" style="display: none;" id="' + this.id + '_voice">' + s.title + '</span>';
  8435. h += '</a>';
  8436. return h;
  8437. },
  8438. postRender : function() {
  8439. var t = this, s = t.settings, imgBookmark;
  8440. // In IE a large image that occupies the entire editor area will be deselected when a button is clicked, so
  8441. // need to keep the selection in case the selection is lost
  8442. if (tinymce.isIE && t.editor) {
  8443. tinymce.dom.Event.add(t.id, 'mousedown', function(e) {
  8444. var nodeName = t.editor.selection.getNode().nodeName;
  8445. imgBookmark = nodeName === 'IMG' ? t.editor.selection.getBookmark() : null;
  8446. });
  8447. }
  8448. tinymce.dom.Event.add(t.id, 'click', function(e) {
  8449. if (!t.isDisabled()) {
  8450. // restore the selection in case the selection is lost in IE
  8451. if (tinymce.isIE && t.editor && imgBookmark !== null) {
  8452. t.editor.selection.moveToBookmark(imgBookmark);
  8453. }
  8454. return s.onclick.call(s.scope, e);
  8455. }
  8456. });
  8457. tinymce.dom.Event.add(t.id, 'keyup', function(e) {
  8458. if (!t.isDisabled() && e.keyCode==tinymce.VK.SPACEBAR)
  8459. return s.onclick.call(s.scope, e);
  8460. });
  8461. }
  8462. });
  8463. })(tinymce);
  8464. (function(tinymce) {
  8465. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher, undef;
  8466. tinymce.create('tinymce.ui.ListBox:tinymce.ui.Control', {
  8467. ListBox : function(id, s, ed) {
  8468. var t = this;
  8469. t.parent(id, s, ed);
  8470. t.items = [];
  8471. t.onChange = new Dispatcher(t);
  8472. t.onPostRender = new Dispatcher(t);
  8473. t.onAdd = new Dispatcher(t);
  8474. t.onRenderMenu = new tinymce.util.Dispatcher(this);
  8475. t.classPrefix = 'mceListBox';
  8476. t.marked = {};
  8477. },
  8478. select : function(va) {
  8479. var t = this, fv, f;
  8480. t.marked = {};
  8481. if (va == undef)
  8482. return t.selectByIndex(-1);
  8483. // Is string or number make function selector
  8484. if (va && typeof(va)=="function")
  8485. f = va;
  8486. else {
  8487. f = function(v) {
  8488. return v == va;
  8489. };
  8490. }
  8491. // Do we need to do something?
  8492. if (va != t.selectedValue) {
  8493. // Find item
  8494. each(t.items, function(o, i) {
  8495. if (f(o.value)) {
  8496. fv = 1;
  8497. t.selectByIndex(i);
  8498. return false;
  8499. }
  8500. });
  8501. if (!fv)
  8502. t.selectByIndex(-1);
  8503. }
  8504. },
  8505. selectByIndex : function(idx) {
  8506. var t = this, e, o, label;
  8507. t.marked = {};
  8508. if (idx != t.selectedIndex) {
  8509. e = DOM.get(t.id + '_text');
  8510. label = DOM.get(t.id + '_voiceDesc');
  8511. o = t.items[idx];
  8512. if (o) {
  8513. t.selectedValue = o.value;
  8514. t.selectedIndex = idx;
  8515. DOM.setHTML(e, DOM.encode(o.title));
  8516. DOM.setHTML(label, t.settings.title + " - " + o.title);
  8517. DOM.removeClass(e, 'mceTitle');
  8518. DOM.setAttrib(t.id, 'aria-valuenow', o.title);
  8519. } else {
  8520. DOM.setHTML(e, DOM.encode(t.settings.title));
  8521. DOM.setHTML(label, DOM.encode(t.settings.title));
  8522. DOM.addClass(e, 'mceTitle');
  8523. t.selectedValue = t.selectedIndex = null;
  8524. DOM.setAttrib(t.id, 'aria-valuenow', t.settings.title);
  8525. }
  8526. e = 0;
  8527. }
  8528. },
  8529. mark : function(value) {
  8530. this.marked[value] = true;
  8531. },
  8532. add : function(n, v, o) {
  8533. var t = this;
  8534. o = o || {};
  8535. o = tinymce.extend(o, {
  8536. title : n,
  8537. value : v
  8538. });
  8539. t.items.push(o);
  8540. t.onAdd.dispatch(t, o);
  8541. },
  8542. getLength : function() {
  8543. return this.items.length;
  8544. },
  8545. renderHTML : function() {
  8546. var h = '', t = this, s = t.settings, cp = t.classPrefix;
  8547. 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>';
  8548. h += '<td>' + DOM.createHTML('span', {id: t.id + '_voiceDesc', 'class': 'voiceLabel', style:'display:none;'}, t.settings.title);
  8549. 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>';
  8550. 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>';
  8551. h += '</tr></tbody></table></span>';
  8552. return h;
  8553. },
  8554. showMenu : function() {
  8555. var t = this, p2, e = DOM.get(this.id), m;
  8556. if (t.isDisabled() || t.items.length === 0)
  8557. return;
  8558. if (t.menu && t.menu.isMenuVisible)
  8559. return t.hideMenu();
  8560. if (!t.isMenuRendered) {
  8561. t.renderMenu();
  8562. t.isMenuRendered = true;
  8563. }
  8564. p2 = DOM.getPos(e);
  8565. m = t.menu;
  8566. m.settings.offset_x = p2.x;
  8567. m.settings.offset_y = p2.y;
  8568. m.settings.keyboard_focus = !tinymce.isOpera; // Opera is buggy when it comes to auto focus
  8569. // Select in menu
  8570. each(t.items, function(o) {
  8571. if (m.items[o.id]) {
  8572. m.items[o.id].setSelected(0);
  8573. }
  8574. });
  8575. each(t.items, function(o) {
  8576. if (m.items[o.id] && t.marked[o.value]) {
  8577. m.items[o.id].setSelected(1);
  8578. }
  8579. if (o.value === t.selectedValue) {
  8580. m.items[o.id].setSelected(1);
  8581. }
  8582. });
  8583. m.showMenu(0, e.clientHeight);
  8584. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  8585. DOM.addClass(t.id, t.classPrefix + 'Selected');
  8586. //DOM.get(t.id + '_text').focus();
  8587. },
  8588. hideMenu : function(e) {
  8589. var t = this;
  8590. if (t.menu && t.menu.isMenuVisible) {
  8591. DOM.removeClass(t.id, t.classPrefix + 'Selected');
  8592. // Prevent double toogles by canceling the mouse click event to the button
  8593. if (e && e.type == "mousedown" && (e.target.id == t.id + '_text' || e.target.id == t.id + '_open'))
  8594. return;
  8595. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  8596. DOM.removeClass(t.id, t.classPrefix + 'Selected');
  8597. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  8598. t.menu.hideMenu();
  8599. }
  8600. }
  8601. },
  8602. renderMenu : function() {
  8603. var t = this, m;
  8604. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  8605. menu_line : 1,
  8606. 'class' : t.classPrefix + 'Menu mceNoIcons',
  8607. max_width : 250,
  8608. max_height : 150
  8609. });
  8610. m.onHideMenu.add(function() {
  8611. t.hideMenu();
  8612. t.focus();
  8613. });
  8614. m.add({
  8615. title : t.settings.title,
  8616. 'class' : 'mceMenuItemTitle',
  8617. onclick : function() {
  8618. if (t.settings.onselect('') !== false)
  8619. t.select(''); // Must be runned after
  8620. }
  8621. });
  8622. each(t.items, function(o) {
  8623. // No value then treat it as a title
  8624. if (o.value === undef) {
  8625. m.add({
  8626. title : o.title,
  8627. role : "option",
  8628. 'class' : 'mceMenuItemTitle',
  8629. onclick : function() {
  8630. if (t.settings.onselect('') !== false)
  8631. t.select(''); // Must be runned after
  8632. }
  8633. });
  8634. } else {
  8635. o.id = DOM.uniqueId();
  8636. o.role= "option";
  8637. o.onclick = function() {
  8638. if (t.settings.onselect(o.value) !== false)
  8639. t.select(o.value); // Must be runned after
  8640. };
  8641. m.add(o);
  8642. }
  8643. });
  8644. t.onRenderMenu.dispatch(t, m);
  8645. t.menu = m;
  8646. },
  8647. postRender : function() {
  8648. var t = this, cp = t.classPrefix;
  8649. Event.add(t.id, 'click', t.showMenu, t);
  8650. Event.add(t.id, 'keydown', function(evt) {
  8651. if (evt.keyCode == 32) { // Space
  8652. t.showMenu(evt);
  8653. Event.cancel(evt);
  8654. }
  8655. });
  8656. Event.add(t.id, 'focus', function() {
  8657. if (!t._focused) {
  8658. t.keyDownHandler = Event.add(t.id, 'keydown', function(e) {
  8659. if (e.keyCode == 40) {
  8660. t.showMenu();
  8661. Event.cancel(e);
  8662. }
  8663. });
  8664. t.keyPressHandler = Event.add(t.id, 'keypress', function(e) {
  8665. var v;
  8666. if (e.keyCode == 13) {
  8667. // Fake select on enter
  8668. v = t.selectedValue;
  8669. t.selectedValue = null; // Needs to be null to fake change
  8670. Event.cancel(e);
  8671. t.settings.onselect(v);
  8672. }
  8673. });
  8674. }
  8675. t._focused = 1;
  8676. });
  8677. Event.add(t.id, 'blur', function() {
  8678. Event.remove(t.id, 'keydown', t.keyDownHandler);
  8679. Event.remove(t.id, 'keypress', t.keyPressHandler);
  8680. t._focused = 0;
  8681. });
  8682. // Old IE doesn't have hover on all elements
  8683. if (tinymce.isIE6 || !DOM.boxModel) {
  8684. Event.add(t.id, 'mouseover', function() {
  8685. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  8686. DOM.addClass(t.id, cp + 'Hover');
  8687. });
  8688. Event.add(t.id, 'mouseout', function() {
  8689. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  8690. DOM.removeClass(t.id, cp + 'Hover');
  8691. });
  8692. }
  8693. t.onPostRender.dispatch(t, DOM.get(t.id));
  8694. },
  8695. destroy : function() {
  8696. this.parent();
  8697. Event.clear(this.id + '_text');
  8698. Event.clear(this.id + '_open');
  8699. }
  8700. });
  8701. })(tinymce);
  8702. (function(tinymce) {
  8703. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher, undef;
  8704. tinymce.create('tinymce.ui.NativeListBox:tinymce.ui.ListBox', {
  8705. NativeListBox : function(id, s) {
  8706. this.parent(id, s);
  8707. this.classPrefix = 'mceNativeListBox';
  8708. },
  8709. setDisabled : function(s) {
  8710. DOM.get(this.id).disabled = s;
  8711. this.setAriaProperty('disabled', s);
  8712. },
  8713. isDisabled : function() {
  8714. return DOM.get(this.id).disabled;
  8715. },
  8716. select : function(va) {
  8717. var t = this, fv, f;
  8718. if (va == undef)
  8719. return t.selectByIndex(-1);
  8720. // Is string or number make function selector
  8721. if (va && typeof(va)=="function")
  8722. f = va;
  8723. else {
  8724. f = function(v) {
  8725. return v == va;
  8726. };
  8727. }
  8728. // Do we need to do something?
  8729. if (va != t.selectedValue) {
  8730. // Find item
  8731. each(t.items, function(o, i) {
  8732. if (f(o.value)) {
  8733. fv = 1;
  8734. t.selectByIndex(i);
  8735. return false;
  8736. }
  8737. });
  8738. if (!fv)
  8739. t.selectByIndex(-1);
  8740. }
  8741. },
  8742. selectByIndex : function(idx) {
  8743. DOM.get(this.id).selectedIndex = idx + 1;
  8744. this.selectedValue = this.items[idx] ? this.items[idx].value : null;
  8745. },
  8746. add : function(n, v, a) {
  8747. var o, t = this;
  8748. a = a || {};
  8749. a.value = v;
  8750. if (t.isRendered())
  8751. DOM.add(DOM.get(this.id), 'option', a, n);
  8752. o = {
  8753. title : n,
  8754. value : v,
  8755. attribs : a
  8756. };
  8757. t.items.push(o);
  8758. t.onAdd.dispatch(t, o);
  8759. },
  8760. getLength : function() {
  8761. return this.items.length;
  8762. },
  8763. renderHTML : function() {
  8764. var h, t = this;
  8765. h = DOM.createHTML('option', {value : ''}, '-- ' + t.settings.title + ' --');
  8766. each(t.items, function(it) {
  8767. h += DOM.createHTML('option', {value : it.value}, it.title);
  8768. });
  8769. h = DOM.createHTML('select', {id : t.id, 'class' : 'mceNativeListBox', 'aria-labelledby': t.id + '_aria'}, h);
  8770. h += DOM.createHTML('span', {id : t.id + '_aria', 'style': 'display: none'}, t.settings.title);
  8771. return h;
  8772. },
  8773. postRender : function() {
  8774. var t = this, ch, changeListenerAdded = true;
  8775. t.rendered = true;
  8776. function onChange(e) {
  8777. var v = t.items[e.target.selectedIndex - 1];
  8778. if (v && (v = v.value)) {
  8779. t.onChange.dispatch(t, v);
  8780. if (t.settings.onselect)
  8781. t.settings.onselect(v);
  8782. }
  8783. };
  8784. Event.add(t.id, 'change', onChange);
  8785. // Accessibility keyhandler
  8786. Event.add(t.id, 'keydown', function(e) {
  8787. var bf;
  8788. Event.remove(t.id, 'change', ch);
  8789. changeListenerAdded = false;
  8790. bf = Event.add(t.id, 'blur', function() {
  8791. if (changeListenerAdded) return;
  8792. changeListenerAdded = true;
  8793. Event.add(t.id, 'change', onChange);
  8794. Event.remove(t.id, 'blur', bf);
  8795. });
  8796. //prevent default left and right keys on chrome - so that the keyboard navigation is used.
  8797. if (tinymce.isWebKit && (e.keyCode==37 ||e.keyCode==39)) {
  8798. return Event.prevent(e);
  8799. }
  8800. if (e.keyCode == 13 || e.keyCode == 32) {
  8801. onChange(e);
  8802. return Event.cancel(e);
  8803. }
  8804. });
  8805. t.onPostRender.dispatch(t, DOM.get(t.id));
  8806. }
  8807. });
  8808. })(tinymce);
  8809. (function(tinymce) {
  8810. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  8811. tinymce.create('tinymce.ui.MenuButton:tinymce.ui.Button', {
  8812. MenuButton : function(id, s, ed) {
  8813. this.parent(id, s, ed);
  8814. this.onRenderMenu = new tinymce.util.Dispatcher(this);
  8815. s.menu_container = s.menu_container || DOM.doc.body;
  8816. },
  8817. showMenu : function() {
  8818. var t = this, p1, p2, e = DOM.get(t.id), m;
  8819. if (t.isDisabled())
  8820. return;
  8821. if (!t.isMenuRendered) {
  8822. t.renderMenu();
  8823. t.isMenuRendered = true;
  8824. }
  8825. if (t.isMenuVisible)
  8826. return t.hideMenu();
  8827. p1 = DOM.getPos(t.settings.menu_container);
  8828. p2 = DOM.getPos(e);
  8829. m = t.menu;
  8830. m.settings.offset_x = p2.x;
  8831. m.settings.offset_y = p2.y;
  8832. m.settings.vp_offset_x = p2.x;
  8833. m.settings.vp_offset_y = p2.y;
  8834. m.settings.keyboard_focus = t._focused;
  8835. m.showMenu(0, e.firstChild.clientHeight);
  8836. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  8837. t.setState('Selected', 1);
  8838. t.isMenuVisible = 1;
  8839. },
  8840. renderMenu : function() {
  8841. var t = this, m;
  8842. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  8843. menu_line : 1,
  8844. 'class' : this.classPrefix + 'Menu',
  8845. icons : t.settings.icons
  8846. });
  8847. m.onHideMenu.add(function() {
  8848. t.hideMenu();
  8849. t.focus();
  8850. });
  8851. t.onRenderMenu.dispatch(t, m);
  8852. t.menu = m;
  8853. },
  8854. hideMenu : function(e) {
  8855. var t = this;
  8856. // Prevent double toogles by canceling the mouse click event to the button
  8857. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id || e.id === t.id + '_open';}))
  8858. return;
  8859. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  8860. t.setState('Selected', 0);
  8861. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  8862. if (t.menu)
  8863. t.menu.hideMenu();
  8864. }
  8865. t.isMenuVisible = 0;
  8866. },
  8867. postRender : function() {
  8868. var t = this, s = t.settings;
  8869. Event.add(t.id, 'click', function() {
  8870. if (!t.isDisabled()) {
  8871. if (s.onclick)
  8872. s.onclick(t.value);
  8873. t.showMenu();
  8874. }
  8875. });
  8876. }
  8877. });
  8878. })(tinymce);
  8879. (function(tinymce) {
  8880. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  8881. tinymce.create('tinymce.ui.SplitButton:tinymce.ui.MenuButton', {
  8882. SplitButton : function(id, s, ed) {
  8883. this.parent(id, s, ed);
  8884. this.classPrefix = 'mceSplitButton';
  8885. },
  8886. renderHTML : function() {
  8887. var h, t = this, s = t.settings, h1;
  8888. h = '<tbody><tr>';
  8889. if (s.image)
  8890. h1 = DOM.createHTML('img ', {src : s.image, role: 'presentation', 'class' : 'mceAction ' + s['class']});
  8891. else
  8892. h1 = DOM.createHTML('span', {'class' : 'mceAction ' + s['class']}, '');
  8893. h1 += DOM.createHTML('span', {'class': 'mceVoiceLabel mceIconOnly', id: t.id + '_voice', style: 'display:none;'}, s.title);
  8894. 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>';
  8895. h1 = DOM.createHTML('span', {'class' : 'mceOpen ' + s['class']}, '<span style="display:none;" class="mceIconOnly" aria-hidden="true">\u25BC</span>');
  8896. 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>';
  8897. h += '</tr></tbody>';
  8898. h = DOM.createHTML('table', { role: 'presentation', 'class' : 'mceSplitButton mceSplitButtonEnabled ' + s['class'], cellpadding : '0', cellspacing : '0', title : s.title}, h);
  8899. return DOM.createHTML('div', {id : t.id, role: 'button', tabindex: '0', 'aria-labelledby': t.id + '_voice', 'aria-haspopup': 'true'}, h);
  8900. },
  8901. postRender : function() {
  8902. var t = this, s = t.settings, activate;
  8903. if (s.onclick) {
  8904. activate = function(evt) {
  8905. if (!t.isDisabled()) {
  8906. s.onclick(t.value);
  8907. Event.cancel(evt);
  8908. }
  8909. };
  8910. Event.add(t.id + '_action', 'click', activate);
  8911. Event.add(t.id, ['click', 'keydown'], function(evt) {
  8912. var DOM_VK_SPACE = 32, DOM_VK_ENTER = 14, DOM_VK_RETURN = 13, DOM_VK_UP = 38, DOM_VK_DOWN = 40;
  8913. if ((evt.keyCode === 32 || evt.keyCode === 13 || evt.keyCode === 14) && !evt.altKey && !evt.ctrlKey && !evt.metaKey) {
  8914. activate();
  8915. Event.cancel(evt);
  8916. } else if (evt.type === 'click' || evt.keyCode === DOM_VK_DOWN) {
  8917. t.showMenu();
  8918. Event.cancel(evt);
  8919. }
  8920. });
  8921. }
  8922. Event.add(t.id + '_open', 'click', function (evt) {
  8923. t.showMenu();
  8924. Event.cancel(evt);
  8925. });
  8926. Event.add([t.id, t.id + '_open'], 'focus', function() {t._focused = 1;});
  8927. Event.add([t.id, t.id + '_open'], 'blur', function() {t._focused = 0;});
  8928. // Old IE doesn't have hover on all elements
  8929. if (tinymce.isIE6 || !DOM.boxModel) {
  8930. Event.add(t.id, 'mouseover', function() {
  8931. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  8932. DOM.addClass(t.id, 'mceSplitButtonHover');
  8933. });
  8934. Event.add(t.id, 'mouseout', function() {
  8935. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  8936. DOM.removeClass(t.id, 'mceSplitButtonHover');
  8937. });
  8938. }
  8939. },
  8940. destroy : function() {
  8941. this.parent();
  8942. Event.clear(this.id + '_action');
  8943. Event.clear(this.id + '_open');
  8944. Event.clear(this.id);
  8945. }
  8946. });
  8947. })(tinymce);
  8948. (function(tinymce) {
  8949. var DOM = tinymce.DOM, Event = tinymce.dom.Event, is = tinymce.is, each = tinymce.each;
  8950. tinymce.create('tinymce.ui.ColorSplitButton:tinymce.ui.SplitButton', {
  8951. ColorSplitButton : function(id, s, ed) {
  8952. var t = this;
  8953. t.parent(id, s, ed);
  8954. t.settings = s = tinymce.extend({
  8955. 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',
  8956. grid_width : 8,
  8957. default_color : '#888888'
  8958. }, t.settings);
  8959. t.onShowMenu = new tinymce.util.Dispatcher(t);
  8960. t.onHideMenu = new tinymce.util.Dispatcher(t);
  8961. t.value = s.default_color;
  8962. },
  8963. showMenu : function() {
  8964. var t = this, r, p, e, p2;
  8965. if (t.isDisabled())
  8966. return;
  8967. if (!t.isMenuRendered) {
  8968. t.renderMenu();
  8969. t.isMenuRendered = true;
  8970. }
  8971. if (t.isMenuVisible)
  8972. return t.hideMenu();
  8973. e = DOM.get(t.id);
  8974. DOM.show(t.id + '_menu');
  8975. DOM.addClass(e, 'mceSplitButtonSelected');
  8976. p2 = DOM.getPos(e);
  8977. DOM.setStyles(t.id + '_menu', {
  8978. left : p2.x,
  8979. top : p2.y + e.firstChild.clientHeight,
  8980. zIndex : 200000
  8981. });
  8982. e = 0;
  8983. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  8984. t.onShowMenu.dispatch(t);
  8985. if (t._focused) {
  8986. t._keyHandler = Event.add(t.id + '_menu', 'keydown', function(e) {
  8987. if (e.keyCode == 27)
  8988. t.hideMenu();
  8989. });
  8990. DOM.select('a', t.id + '_menu')[0].focus(); // Select first link
  8991. }
  8992. t.keyboardNav = new tinymce.ui.KeyboardNavigation({
  8993. root: t.id + '_menu',
  8994. items: DOM.select('a', t.id + '_menu'),
  8995. onCancel: function() {
  8996. t.hideMenu();
  8997. t.focus();
  8998. }
  8999. });
  9000. t.keyboardNav.focus();
  9001. t.isMenuVisible = 1;
  9002. },
  9003. hideMenu : function(e) {
  9004. var t = this;
  9005. if (t.isMenuVisible) {
  9006. // Prevent double toogles by canceling the mouse click event to the button
  9007. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id + '_open';}))
  9008. return;
  9009. if (!e || !DOM.getParent(e.target, '.mceSplitButtonMenu')) {
  9010. DOM.removeClass(t.id, 'mceSplitButtonSelected');
  9011. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  9012. Event.remove(t.id + '_menu', 'keydown', t._keyHandler);
  9013. DOM.hide(t.id + '_menu');
  9014. }
  9015. t.isMenuVisible = 0;
  9016. t.onHideMenu.dispatch();
  9017. t.keyboardNav.destroy();
  9018. }
  9019. },
  9020. renderMenu : function() {
  9021. var t = this, m, i = 0, s = t.settings, n, tb, tr, w, context;
  9022. 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;'});
  9023. m = DOM.add(w, 'div', {'class' : s['class'] + ' mceSplitButtonMenu'});
  9024. DOM.add(m, 'span', {'class' : 'mceMenuLine'});
  9025. n = DOM.add(m, 'table', {role: 'presentation', 'class' : 'mceColorSplitMenu'});
  9026. tb = DOM.add(n, 'tbody');
  9027. // Generate color grid
  9028. i = 0;
  9029. each(is(s.colors, 'array') ? s.colors : s.colors.split(','), function(c) {
  9030. c = c.replace(/^#/, '');
  9031. if (!i--) {
  9032. tr = DOM.add(tb, 'tr');
  9033. i = s.grid_width - 1;
  9034. }
  9035. n = DOM.add(tr, 'td');
  9036. var settings = {
  9037. href : 'javascript:;',
  9038. style : {
  9039. backgroundColor : '#' + c
  9040. },
  9041. 'title': t.editor.getLang('colors.' + c, c),
  9042. 'data-mce-color' : '#' + c
  9043. };
  9044. // adding a proper ARIA role = button causes JAWS to read things incorrectly on IE.
  9045. if (!tinymce.isIE ) {
  9046. settings.role = 'option';
  9047. }
  9048. n = DOM.add(n, 'a', settings);
  9049. if (t.editor.forcedHighContrastMode) {
  9050. n = DOM.add(n, 'canvas', { width: 16, height: 16, 'aria-hidden': 'true' });
  9051. if (n.getContext && (context = n.getContext("2d"))) {
  9052. context.fillStyle = '#' + c;
  9053. context.fillRect(0, 0, 16, 16);
  9054. } else {
  9055. // No point leaving a canvas element around if it's not supported for drawing on anyway.
  9056. DOM.remove(n);
  9057. }
  9058. }
  9059. });
  9060. if (s.more_colors_func) {
  9061. n = DOM.add(tb, 'tr');
  9062. n = DOM.add(n, 'td', {colspan : s.grid_width, 'class' : 'mceMoreColors'});
  9063. n = DOM.add(n, 'a', {role: 'option', id : t.id + '_more', href : 'javascript:;', onclick : 'return false;', 'class' : 'mceMoreColors'}, s.more_colors_title);
  9064. Event.add(n, 'click', function(e) {
  9065. s.more_colors_func.call(s.more_colors_scope || this);
  9066. return Event.cancel(e); // Cancel to fix onbeforeunload problem
  9067. });
  9068. }
  9069. DOM.addClass(m, 'mceColorSplitMenu');
  9070. // Prevent IE from scrolling and hindering click to occur #4019
  9071. Event.add(t.id + '_menu', 'mousedown', function(e) {return Event.cancel(e);});
  9072. Event.add(t.id + '_menu', 'click', function(e) {
  9073. var c;
  9074. e = DOM.getParent(e.target, 'a', tb);
  9075. if (e && e.nodeName.toLowerCase() == 'a' && (c = e.getAttribute('data-mce-color')))
  9076. t.setColor(c);
  9077. return false; // Prevent IE auto save warning
  9078. });
  9079. return w;
  9080. },
  9081. setColor : function(c) {
  9082. this.displayColor(c);
  9083. this.hideMenu();
  9084. this.settings.onselect(c);
  9085. },
  9086. displayColor : function(c) {
  9087. var t = this;
  9088. DOM.setStyle(t.id + '_preview', 'backgroundColor', c);
  9089. t.value = c;
  9090. },
  9091. postRender : function() {
  9092. var t = this, id = t.id;
  9093. t.parent();
  9094. DOM.add(id + '_action', 'div', {id : id + '_preview', 'class' : 'mceColorPreview'});
  9095. DOM.setStyle(t.id + '_preview', 'backgroundColor', t.value);
  9096. },
  9097. destroy : function() {
  9098. var self = this;
  9099. self.parent();
  9100. Event.clear(self.id + '_menu');
  9101. Event.clear(self.id + '_more');
  9102. DOM.remove(self.id + '_menu');
  9103. if (self.keyboardNav) {
  9104. self.keyboardNav.destroy();
  9105. }
  9106. }
  9107. });
  9108. })(tinymce);
  9109. (function(tinymce) {
  9110. // Shorten class names
  9111. var dom = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event;
  9112. tinymce.create('tinymce.ui.ToolbarGroup:tinymce.ui.Container', {
  9113. renderHTML : function() {
  9114. var t = this, h = [], controls = t.controls, each = tinymce.each, settings = t.settings;
  9115. h.push('<div id="' + t.id + '" role="group" aria-labelledby="' + t.id + '_voice">');
  9116. //TODO: ACC test this out - adding a role = application for getting the landmarks working well.
  9117. h.push("<span role='application'>");
  9118. h.push('<span id="' + t.id + '_voice" class="mceVoiceLabel" style="display:none;">' + dom.encode(settings.name) + '</span>');
  9119. each(controls, function(toolbar) {
  9120. h.push(toolbar.renderHTML());
  9121. });
  9122. h.push("</span>");
  9123. h.push('</div>');
  9124. return h.join('');
  9125. },
  9126. focus : function() {
  9127. var t = this;
  9128. dom.get(t.id).focus();
  9129. },
  9130. postRender : function() {
  9131. var t = this, items = [];
  9132. each(t.controls, function(toolbar) {
  9133. each (toolbar.controls, function(control) {
  9134. if (control.id) {
  9135. items.push(control);
  9136. }
  9137. });
  9138. });
  9139. t.keyNav = new tinymce.ui.KeyboardNavigation({
  9140. root: t.id,
  9141. items: items,
  9142. onCancel: function() {
  9143. //Move focus if webkit so that navigation back will read the item.
  9144. if (tinymce.isWebKit) {
  9145. dom.get(t.editor.id+"_ifr").focus();
  9146. }
  9147. t.editor.focus();
  9148. },
  9149. excludeFromTabOrder: !t.settings.tab_focus_toolbar
  9150. });
  9151. },
  9152. destroy : function() {
  9153. var self = this;
  9154. self.parent();
  9155. self.keyNav.destroy();
  9156. Event.clear(self.id);
  9157. }
  9158. });
  9159. })(tinymce);
  9160. (function(tinymce) {
  9161. // Shorten class names
  9162. var dom = tinymce.DOM, each = tinymce.each;
  9163. tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', {
  9164. renderHTML : function() {
  9165. var t = this, h = '', c, co, s = t.settings, i, pr, nx, cl;
  9166. cl = t.controls;
  9167. for (i=0; i<cl.length; i++) {
  9168. // Get current control, prev control, next control and if the control is a list box or not
  9169. co = cl[i];
  9170. pr = cl[i - 1];
  9171. nx = cl[i + 1];
  9172. // Add toolbar start
  9173. if (i === 0) {
  9174. c = 'mceToolbarStart';
  9175. if (co.Button)
  9176. c += ' mceToolbarStartButton';
  9177. else if (co.SplitButton)
  9178. c += ' mceToolbarStartSplitButton';
  9179. else if (co.ListBox)
  9180. c += ' mceToolbarStartListBox';
  9181. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  9182. }
  9183. // Add toolbar end before list box and after the previous button
  9184. // This is to fix the o2k7 editor skins
  9185. if (pr && co.ListBox) {
  9186. if (pr.Button || pr.SplitButton)
  9187. h += dom.createHTML('td', {'class' : 'mceToolbarEnd'}, dom.createHTML('span', null, '<!-- IE -->'));
  9188. }
  9189. // Render control HTML
  9190. // IE 8 quick fix, needed to propertly generate a hit area for anchors
  9191. if (dom.stdMode)
  9192. h += '<td style="position: relative">' + co.renderHTML() + '</td>';
  9193. else
  9194. h += '<td>' + co.renderHTML() + '</td>';
  9195. // Add toolbar start after list box and before the next button
  9196. // This is to fix the o2k7 editor skins
  9197. if (nx && co.ListBox) {
  9198. if (nx.Button || nx.SplitButton)
  9199. h += dom.createHTML('td', {'class' : 'mceToolbarStart'}, dom.createHTML('span', null, '<!-- IE -->'));
  9200. }
  9201. }
  9202. c = 'mceToolbarEnd';
  9203. if (co.Button)
  9204. c += ' mceToolbarEndButton';
  9205. else if (co.SplitButton)
  9206. c += ' mceToolbarEndSplitButton';
  9207. else if (co.ListBox)
  9208. c += ' mceToolbarEndListBox';
  9209. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  9210. 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>');
  9211. }
  9212. });
  9213. })(tinymce);
  9214. (function(tinymce) {
  9215. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each;
  9216. tinymce.create('tinymce.AddOnManager', {
  9217. AddOnManager : function() {
  9218. var self = this;
  9219. self.items = [];
  9220. self.urls = {};
  9221. self.lookup = {};
  9222. self.onAdd = new Dispatcher(self);
  9223. },
  9224. get : function(n) {
  9225. if (this.lookup[n]) {
  9226. return this.lookup[n].instance;
  9227. } else {
  9228. return undefined;
  9229. }
  9230. },
  9231. dependencies : function(n) {
  9232. var result;
  9233. if (this.lookup[n]) {
  9234. result = this.lookup[n].dependencies;
  9235. }
  9236. return result || [];
  9237. },
  9238. requireLangPack : function(n) {
  9239. var s = tinymce.settings;
  9240. if (s && s.language && s.language_load !== false)
  9241. tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js');
  9242. },
  9243. add : function(id, o, dependencies) {
  9244. this.items.push(o);
  9245. this.lookup[id] = {instance:o, dependencies:dependencies};
  9246. this.onAdd.dispatch(this, id, o);
  9247. return o;
  9248. },
  9249. createUrl: function(baseUrl, dep) {
  9250. if (typeof dep === "object") {
  9251. return dep
  9252. } else {
  9253. return {prefix: baseUrl.prefix, resource: dep, suffix: baseUrl.suffix};
  9254. }
  9255. },
  9256. addComponents: function(pluginName, scripts) {
  9257. var pluginUrl = this.urls[pluginName];
  9258. tinymce.each(scripts, function(script){
  9259. tinymce.ScriptLoader.add(pluginUrl+"/"+script);
  9260. });
  9261. },
  9262. load : function(n, u, cb, s) {
  9263. var t = this, url = u;
  9264. function loadDependencies() {
  9265. var dependencies = t.dependencies(n);
  9266. tinymce.each(dependencies, function(dep) {
  9267. var newUrl = t.createUrl(u, dep);
  9268. t.load(newUrl.resource, newUrl, undefined, undefined);
  9269. });
  9270. if (cb) {
  9271. if (s) {
  9272. cb.call(s);
  9273. } else {
  9274. cb.call(tinymce.ScriptLoader);
  9275. }
  9276. }
  9277. }
  9278. if (t.urls[n])
  9279. return;
  9280. if (typeof u === "object")
  9281. url = u.prefix + u.resource + u.suffix;
  9282. if (url.indexOf('/') !== 0 && url.indexOf('://') == -1)
  9283. url = tinymce.baseURL + '/' + url;
  9284. t.urls[n] = url.substring(0, url.lastIndexOf('/'));
  9285. if (t.lookup[n]) {
  9286. loadDependencies();
  9287. } else {
  9288. tinymce.ScriptLoader.add(url, loadDependencies, s);
  9289. }
  9290. }
  9291. });
  9292. // Create plugin and theme managers
  9293. tinymce.PluginManager = new tinymce.AddOnManager();
  9294. tinymce.ThemeManager = new tinymce.AddOnManager();
  9295. }(tinymce));
  9296. (function(tinymce) {
  9297. // Shorten names
  9298. var each = tinymce.each, extend = tinymce.extend,
  9299. DOM = tinymce.DOM, Event = tinymce.dom.Event,
  9300. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  9301. explode = tinymce.explode,
  9302. Dispatcher = tinymce.util.Dispatcher, undef, instanceCounter = 0;
  9303. // Setup some URLs where the editor API is located and where the document is
  9304. tinymce.documentBaseURL = window.location.href.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '');
  9305. if (!/[\/\\]$/.test(tinymce.documentBaseURL))
  9306. tinymce.documentBaseURL += '/';
  9307. tinymce.baseURL = new tinymce.util.URI(tinymce.documentBaseURL).toAbsolute(tinymce.baseURL);
  9308. tinymce.baseURI = new tinymce.util.URI(tinymce.baseURL);
  9309. // Add before unload listener
  9310. // This was required since IE was leaking memory if you added and removed beforeunload listeners
  9311. // with attachEvent/detatchEvent so this only adds one listener and instances can the attach to the onBeforeUnload event
  9312. tinymce.onBeforeUnload = new Dispatcher(tinymce);
  9313. // Must be on window or IE will leak if the editor is placed in frame or iframe
  9314. Event.add(window, 'beforeunload', function(e) {
  9315. tinymce.onBeforeUnload.dispatch(tinymce, e);
  9316. });
  9317. tinymce.onAddEditor = new Dispatcher(tinymce);
  9318. tinymce.onRemoveEditor = new Dispatcher(tinymce);
  9319. tinymce.EditorManager = extend(tinymce, {
  9320. editors : [],
  9321. i18n : {},
  9322. activeEditor : null,
  9323. init : function(s) {
  9324. var t = this, pl, sl = tinymce.ScriptLoader, e, el = [], ed;
  9325. function createId(elm) {
  9326. var id = elm.id;
  9327. // Use element id, or unique name or generate a unique id
  9328. if (!id) {
  9329. id = elm.name;
  9330. if (id && !DOM.get(id)) {
  9331. id = elm.name;
  9332. } else {
  9333. // Generate unique name
  9334. id = DOM.uniqueId();
  9335. }
  9336. elm.setAttribute('id', id);
  9337. }
  9338. return id;
  9339. };
  9340. function execCallback(se, n, s) {
  9341. var f = se[n];
  9342. if (!f)
  9343. return;
  9344. if (tinymce.is(f, 'string')) {
  9345. s = f.replace(/\.\w+$/, '');
  9346. s = s ? tinymce.resolve(s) : 0;
  9347. f = tinymce.resolve(f);
  9348. }
  9349. return f.apply(s || this, Array.prototype.slice.call(arguments, 2));
  9350. };
  9351. function hasClass(n, c) {
  9352. return c.constructor === RegExp ? c.test(n.className) : DOM.hasClass(n, c);
  9353. };
  9354. t.settings = s;
  9355. // Legacy call
  9356. Event.bind(window, 'ready', function() {
  9357. var l, co;
  9358. execCallback(s, 'onpageload');
  9359. switch (s.mode) {
  9360. case "exact":
  9361. l = s.elements || '';
  9362. if(l.length > 0) {
  9363. each(explode(l), function(v) {
  9364. if (DOM.get(v)) {
  9365. ed = new tinymce.Editor(v, s);
  9366. el.push(ed);
  9367. ed.render(1);
  9368. } else {
  9369. each(document.forms, function(f) {
  9370. each(f.elements, function(e) {
  9371. if (e.name === v) {
  9372. v = 'mce_editor_' + instanceCounter++;
  9373. DOM.setAttrib(e, 'id', v);
  9374. ed = new tinymce.Editor(v, s);
  9375. el.push(ed);
  9376. ed.render(1);
  9377. }
  9378. });
  9379. });
  9380. }
  9381. });
  9382. }
  9383. break;
  9384. case "textareas":
  9385. case "specific_textareas":
  9386. each(DOM.select('textarea'), function(elm) {
  9387. if (s.editor_deselector && hasClass(elm, s.editor_deselector))
  9388. return;
  9389. if (!s.editor_selector || hasClass(elm, s.editor_selector)) {
  9390. ed = new tinymce.Editor(createId(elm), s);
  9391. el.push(ed);
  9392. ed.render(1);
  9393. }
  9394. });
  9395. break;
  9396. default:
  9397. if (s.types) {
  9398. // Process type specific selector
  9399. each(s.types, function(type) {
  9400. each(DOM.select(type.selector), function(elm) {
  9401. var editor = new tinymce.Editor(createId(elm), tinymce.extend({}, s, type));
  9402. el.push(editor);
  9403. editor.render(1);
  9404. });
  9405. });
  9406. } else if (s.selector) {
  9407. // Process global selector
  9408. each(DOM.select(s.selector), function(elm) {
  9409. var editor = new tinymce.Editor(createId(elm), s);
  9410. el.push(editor);
  9411. editor.render(1);
  9412. });
  9413. }
  9414. }
  9415. // Call onInit when all editors are initialized
  9416. if (s.oninit) {
  9417. l = co = 0;
  9418. each(el, function(ed) {
  9419. co++;
  9420. if (!ed.initialized) {
  9421. // Wait for it
  9422. ed.onInit.add(function() {
  9423. l++;
  9424. // All done
  9425. if (l == co)
  9426. execCallback(s, 'oninit');
  9427. });
  9428. } else
  9429. l++;
  9430. // All done
  9431. if (l == co)
  9432. execCallback(s, 'oninit');
  9433. });
  9434. }
  9435. });
  9436. },
  9437. get : function(id) {
  9438. if (id === undef)
  9439. return this.editors;
  9440. if (!this.editors.hasOwnProperty(id))
  9441. return undef;
  9442. return this.editors[id];
  9443. },
  9444. getInstanceById : function(id) {
  9445. return this.get(id);
  9446. },
  9447. add : function(editor) {
  9448. var self = this, editors = self.editors;
  9449. // Add named and index editor instance
  9450. editors[editor.id] = editor;
  9451. editors.push(editor);
  9452. self._setActive(editor);
  9453. self.onAddEditor.dispatch(self, editor);
  9454. // Patch the tinymce.Editor instance with jQuery adapter logic
  9455. if (tinymce.adapter)
  9456. tinymce.adapter.patchEditor(editor);
  9457. return editor;
  9458. },
  9459. remove : function(editor) {
  9460. var t = this, i, editors = t.editors;
  9461. // Not in the collection
  9462. if (!editors[editor.id])
  9463. return null;
  9464. delete editors[editor.id];
  9465. for (i = 0; i < editors.length; i++) {
  9466. if (editors[i] == editor) {
  9467. editors.splice(i, 1);
  9468. break;
  9469. }
  9470. }
  9471. // Select another editor since the active one was removed
  9472. if (t.activeEditor == editor)
  9473. t._setActive(editors[0]);
  9474. editor.destroy();
  9475. t.onRemoveEditor.dispatch(t, editor);
  9476. return editor;
  9477. },
  9478. execCommand : function(c, u, v) {
  9479. var t = this, ed = t.get(v), w;
  9480. function clr() {
  9481. ed.destroy();
  9482. w.detachEvent('onunload', clr);
  9483. w = w.tinyMCE = w.tinymce = null; // IE leak
  9484. };
  9485. // Manager commands
  9486. switch (c) {
  9487. case "mceFocus":
  9488. ed.focus();
  9489. return true;
  9490. case "mceAddEditor":
  9491. case "mceAddControl":
  9492. if (!t.get(v))
  9493. new tinymce.Editor(v, t.settings).render();
  9494. return true;
  9495. case "mceAddFrameControl":
  9496. w = v.window;
  9497. // Add tinyMCE global instance and tinymce namespace to specified window
  9498. w.tinyMCE = tinyMCE;
  9499. w.tinymce = tinymce;
  9500. tinymce.DOM.doc = w.document;
  9501. tinymce.DOM.win = w;
  9502. ed = new tinymce.Editor(v.element_id, v);
  9503. ed.render();
  9504. // Fix IE memory leaks
  9505. if (tinymce.isIE) {
  9506. w.attachEvent('onunload', clr);
  9507. }
  9508. v.page_window = null;
  9509. return true;
  9510. case "mceRemoveEditor":
  9511. case "mceRemoveControl":
  9512. if (ed)
  9513. ed.remove();
  9514. return true;
  9515. case 'mceToggleEditor':
  9516. if (!ed) {
  9517. t.execCommand('mceAddControl', 0, v);
  9518. return true;
  9519. }
  9520. if (ed.isHidden())
  9521. ed.show();
  9522. else
  9523. ed.hide();
  9524. return true;
  9525. }
  9526. // Run command on active editor
  9527. if (t.activeEditor)
  9528. return t.activeEditor.execCommand(c, u, v);
  9529. return false;
  9530. },
  9531. execInstanceCommand : function(id, c, u, v) {
  9532. var ed = this.get(id);
  9533. if (ed)
  9534. return ed.execCommand(c, u, v);
  9535. return false;
  9536. },
  9537. triggerSave : function() {
  9538. each(this.editors, function(e) {
  9539. e.save();
  9540. });
  9541. },
  9542. addI18n : function(p, o) {
  9543. var lo, i18n = this.i18n;
  9544. if (!tinymce.is(p, 'string')) {
  9545. each(p, function(o, lc) {
  9546. each(o, function(o, g) {
  9547. each(o, function(o, k) {
  9548. if (g === 'common')
  9549. i18n[lc + '.' + k] = o;
  9550. else
  9551. i18n[lc + '.' + g + '.' + k] = o;
  9552. });
  9553. });
  9554. });
  9555. } else {
  9556. each(o, function(o, k) {
  9557. i18n[p + '.' + k] = o;
  9558. });
  9559. }
  9560. },
  9561. // Private methods
  9562. _setActive : function(editor) {
  9563. this.selectedInstance = this.activeEditor = editor;
  9564. }
  9565. });
  9566. })(tinymce);
  9567. (function(tinymce) {
  9568. // Shorten these names
  9569. var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend,
  9570. each = tinymce.each, isGecko = tinymce.isGecko,
  9571. isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, is = tinymce.is,
  9572. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  9573. explode = tinymce.explode;
  9574. tinymce.create('tinymce.Editor', {
  9575. Editor : function(id, settings) {
  9576. var self = this, TRUE = true;
  9577. self.settings = settings = extend({
  9578. id : id,
  9579. language : 'en',
  9580. theme : 'advanced',
  9581. skin : 'default',
  9582. delta_width : 0,
  9583. delta_height : 0,
  9584. popup_css : '',
  9585. plugins : '',
  9586. document_base_url : tinymce.documentBaseURL,
  9587. add_form_submit_trigger : TRUE,
  9588. submit_patch : TRUE,
  9589. add_unload_trigger : TRUE,
  9590. convert_urls : TRUE,
  9591. relative_urls : TRUE,
  9592. remove_script_host : TRUE,
  9593. table_inline_editing : false,
  9594. object_resizing : TRUE,
  9595. accessibility_focus : TRUE,
  9596. doctype : tinymce.isIE6 ? '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' : '<!DOCTYPE>', // Use old doctype on IE 6 to avoid horizontal scroll
  9597. visual : TRUE,
  9598. font_size_style_values : 'xx-small,x-small,small,medium,large,x-large,xx-large',
  9599. 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
  9600. apply_source_formatting : TRUE,
  9601. directionality : 'ltr',
  9602. forced_root_block : 'p',
  9603. hidden_input : TRUE,
  9604. padd_empty_editor : TRUE,
  9605. render_ui : TRUE,
  9606. indentation : '30px',
  9607. fix_table_elements : TRUE,
  9608. inline_styles : TRUE,
  9609. convert_fonts_to_spans : TRUE,
  9610. indent : 'simple',
  9611. 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',
  9612. 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',
  9613. validate : TRUE,
  9614. entity_encoding : 'named',
  9615. url_converter : self.convertURL,
  9616. url_converter_scope : self,
  9617. ie7_compat : TRUE
  9618. }, settings);
  9619. self.id = self.editorId = id;
  9620. self.isNotDirty = false;
  9621. self.plugins = {};
  9622. self.documentBaseURI = new tinymce.util.URI(settings.document_base_url || tinymce.documentBaseURL, {
  9623. base_uri : tinyMCE.baseURI
  9624. });
  9625. self.baseURI = tinymce.baseURI;
  9626. self.contentCSS = [];
  9627. self.contentStyles = [];
  9628. // Creates all events like onClick, onSetContent etc see Editor.Events.js for the actual logic
  9629. self.setupEvents();
  9630. // Internal command handler objects
  9631. self.execCommands = {};
  9632. self.queryStateCommands = {};
  9633. self.queryValueCommands = {};
  9634. // Call setup
  9635. self.execCallback('setup', self);
  9636. },
  9637. render : function(nst) {
  9638. var t = this, s = t.settings, id = t.id, sl = tinymce.ScriptLoader;
  9639. // Page is not loaded yet, wait for it
  9640. if (!Event.domLoaded) {
  9641. Event.add(window, 'ready', function() {
  9642. t.render();
  9643. });
  9644. return;
  9645. }
  9646. tinyMCE.settings = s;
  9647. // Element not found, then skip initialization
  9648. if (!t.getElement())
  9649. return;
  9650. // Is a iPad/iPhone and not on iOS5, then skip initialization. We need to sniff
  9651. // here since the browser says it has contentEditable support but there is no visible caret.
  9652. if (tinymce.isIDevice && !tinymce.isIOS5)
  9653. return;
  9654. // Add hidden input for non input elements inside form elements
  9655. if (!/TEXTAREA|INPUT/i.test(t.getElement().nodeName) && s.hidden_input && DOM.getParent(id, 'form'))
  9656. DOM.insertAfter(DOM.create('input', {type : 'hidden', name : id}), id);
  9657. // Hide target element early to prevent content flashing
  9658. if (!s.content_editable) {
  9659. t.orgVisibility = t.getElement().style.visibility;
  9660. t.getElement().style.visibility = 'hidden';
  9661. }
  9662. if (tinymce.WindowManager)
  9663. t.windowManager = new tinymce.WindowManager(t);
  9664. if (s.encoding == 'xml') {
  9665. t.onGetContent.add(function(ed, o) {
  9666. if (o.save)
  9667. o.content = DOM.encode(o.content);
  9668. });
  9669. }
  9670. if (s.add_form_submit_trigger) {
  9671. t.onSubmit.addToTop(function() {
  9672. if (t.initialized) {
  9673. t.save();
  9674. t.isNotDirty = 1;
  9675. }
  9676. });
  9677. }
  9678. if (s.add_unload_trigger) {
  9679. t._beforeUnload = tinyMCE.onBeforeUnload.add(function() {
  9680. if (t.initialized && !t.destroyed && !t.isHidden())
  9681. t.save({format : 'raw', no_events : true});
  9682. });
  9683. }
  9684. tinymce.addUnload(t.destroy, t);
  9685. if (s.submit_patch) {
  9686. t.onBeforeRenderUI.add(function() {
  9687. var n = t.getElement().form;
  9688. if (!n)
  9689. return;
  9690. // Already patched
  9691. if (n._mceOldSubmit)
  9692. return;
  9693. // Check page uses id="submit" or name="submit" for it's submit button
  9694. if (!n.submit.nodeType && !n.submit.length) {
  9695. t.formElement = n;
  9696. n._mceOldSubmit = n.submit;
  9697. n.submit = function() {
  9698. // Save all instances
  9699. tinymce.triggerSave();
  9700. t.isNotDirty = 1;
  9701. return t.formElement._mceOldSubmit(t.formElement);
  9702. };
  9703. }
  9704. n = null;
  9705. });
  9706. }
  9707. // Load scripts
  9708. function loadScripts() {
  9709. if (s.language && s.language_load !== false)
  9710. sl.add(tinymce.baseURL + '/langs/' + s.language + '.js');
  9711. if (s.theme && typeof s.theme != "function" && s.theme.charAt(0) != '-' && !ThemeManager.urls[s.theme])
  9712. ThemeManager.load(s.theme, 'themes/' + s.theme + '/editor_template' + tinymce.suffix + '.js');
  9713. each(explode(s.plugins), function(p) {
  9714. if (p &&!PluginManager.urls[p]) {
  9715. if (p.charAt(0) == '-') {
  9716. p = p.substr(1, p.length);
  9717. var dependencies = PluginManager.dependencies(p);
  9718. each(dependencies, function(dep) {
  9719. var defaultSettings = {prefix:'plugins/', resource: dep, suffix:'/editor_plugin' + tinymce.suffix + '.js'};
  9720. dep = PluginManager.createUrl(defaultSettings, dep);
  9721. PluginManager.load(dep.resource, dep);
  9722. });
  9723. } else {
  9724. // Skip safari plugin, since it is removed as of 3.3b1
  9725. if (p == 'safari') {
  9726. return;
  9727. }
  9728. PluginManager.load(p, {prefix:'plugins/', resource: p, suffix:'/editor_plugin' + tinymce.suffix + '.js'});
  9729. }
  9730. }
  9731. });
  9732. // Init when que is loaded
  9733. sl.loadQueue(function() {
  9734. if (!t.removed)
  9735. t.init();
  9736. });
  9737. };
  9738. loadScripts();
  9739. },
  9740. init : function() {
  9741. var n, t = this, s = t.settings, w, h, mh, e = t.getElement(), o, ti, u, bi, bc, re, i, initializedPlugins = [];
  9742. tinymce.add(t);
  9743. s.aria_label = s.aria_label || DOM.getAttrib(e, 'aria-label', t.getLang('aria.rich_text_area'));
  9744. if (s.theme) {
  9745. if (typeof s.theme != "function") {
  9746. s.theme = s.theme.replace(/-/, '');
  9747. o = ThemeManager.get(s.theme);
  9748. t.theme = new o();
  9749. if (t.theme.init)
  9750. t.theme.init(t, ThemeManager.urls[s.theme] || tinymce.documentBaseURL.replace(/\/$/, ''));
  9751. } else {
  9752. t.theme = s.theme;
  9753. }
  9754. }
  9755. function initPlugin(p) {
  9756. var c = PluginManager.get(p), u = PluginManager.urls[p] || tinymce.documentBaseURL.replace(/\/$/, ''), po;
  9757. if (c && tinymce.inArray(initializedPlugins,p) === -1) {
  9758. each(PluginManager.dependencies(p), function(dep){
  9759. initPlugin(dep);
  9760. });
  9761. po = new c(t, u);
  9762. t.plugins[p] = po;
  9763. if (po.init) {
  9764. po.init(t, u);
  9765. initializedPlugins.push(p);
  9766. }
  9767. }
  9768. }
  9769. // Create all plugins
  9770. each(explode(s.plugins.replace(/\-/g, '')), initPlugin);
  9771. // Setup popup CSS path(s)
  9772. if (s.popup_css !== false) {
  9773. if (s.popup_css)
  9774. s.popup_css = t.documentBaseURI.toAbsolute(s.popup_css);
  9775. else
  9776. s.popup_css = t.baseURI.toAbsolute("themes/" + s.theme + "/skins/" + s.skin + "/dialog.css");
  9777. }
  9778. if (s.popup_css_add)
  9779. s.popup_css += ',' + t.documentBaseURI.toAbsolute(s.popup_css_add);
  9780. t.controlManager = new tinymce.ControlManager(t);
  9781. // Enables users to override the control factory
  9782. t.onBeforeRenderUI.dispatch(t, t.controlManager);
  9783. // Measure box
  9784. if (s.render_ui && t.theme) {
  9785. t.orgDisplay = e.style.display;
  9786. if (typeof s.theme != "function") {
  9787. w = s.width || e.style.width || e.offsetWidth;
  9788. h = s.height || e.style.height || e.offsetHeight;
  9789. mh = s.min_height || 100;
  9790. re = /^[0-9\.]+(|px)$/i;
  9791. if (re.test('' + w))
  9792. w = Math.max(parseInt(w, 10) + (o.deltaWidth || 0), 100);
  9793. if (re.test('' + h))
  9794. h = Math.max(parseInt(h, 10) + (o.deltaHeight || 0), mh);
  9795. // Render UI
  9796. o = t.theme.renderUI({
  9797. targetNode : e,
  9798. width : w,
  9799. height : h,
  9800. deltaWidth : s.delta_width,
  9801. deltaHeight : s.delta_height
  9802. });
  9803. // Resize editor
  9804. DOM.setStyles(o.sizeContainer || o.editorContainer, {
  9805. width : w,
  9806. height : h
  9807. });
  9808. h = (o.iframeHeight || h) + (typeof(h) == 'number' ? (o.deltaHeight || 0) : '');
  9809. if (h < mh)
  9810. h = mh;
  9811. } else {
  9812. o = s.theme(t, e);
  9813. // Convert element type to id:s
  9814. if (o.editorContainer.nodeType) {
  9815. o.editorContainer = o.editorContainer.id = o.editorContainer.id || t.id + "_parent";
  9816. }
  9817. // Convert element type to id:s
  9818. if (o.iframeContainer.nodeType) {
  9819. o.iframeContainer = o.iframeContainer.id = o.iframeContainer.id || t.id + "_iframecontainer";
  9820. }
  9821. // Use specified iframe height or the targets offsetHeight
  9822. h = o.iframeHeight || e.offsetHeight;
  9823. // Store away the selection when it's changed to it can be restored later with a editor.focus() call
  9824. if (isIE) {
  9825. t.onInit.add(function(ed) {
  9826. ed.dom.bind(ed.getBody(), 'beforedeactivate keydown', function() {
  9827. ed.lastIERng = ed.selection.getRng();
  9828. });
  9829. });
  9830. }
  9831. }
  9832. t.editorContainer = o.editorContainer;
  9833. }
  9834. // Load specified content CSS last
  9835. if (s.content_css) {
  9836. each(explode(s.content_css), function(u) {
  9837. t.contentCSS.push(t.documentBaseURI.toAbsolute(u));
  9838. });
  9839. }
  9840. // Load specified content CSS last
  9841. if (s.content_style) {
  9842. t.contentStyles.push(s.content_style);
  9843. }
  9844. // Content editable mode ends here
  9845. if (s.content_editable) {
  9846. e = n = o = null; // Fix IE leak
  9847. return t.initContentBody();
  9848. }
  9849. // User specified a document.domain value
  9850. if (document.domain && location.hostname != document.domain)
  9851. tinymce.relaxedDomain = document.domain;
  9852. t.iframeHTML = s.doctype + '<html><head xmlns="http://www.w3.org/1999/xhtml">';
  9853. // We only need to override paths if we have to
  9854. // IE has a bug where it remove site absolute urls to relative ones if this is specified
  9855. if (s.document_base_url != tinymce.documentBaseURL)
  9856. t.iframeHTML += '<base href="' + t.documentBaseURI.getURI() + '" />';
  9857. // IE8 doesn't support carets behind images setting ie7_compat would force IE8+ to run in IE7 compat mode.
  9858. if (s.ie7_compat)
  9859. t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=7" />';
  9860. else
  9861. t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=edge" />';
  9862. t.iframeHTML += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
  9863. // Load the CSS by injecting them into the HTML this will reduce "flicker"
  9864. for (i = 0; i < t.contentCSS.length; i++) {
  9865. t.iframeHTML += '<link type="text/css" rel="stylesheet" href="' + t.contentCSS[i] + '" />';
  9866. }
  9867. t.contentCSS = [];
  9868. bi = s.body_id || 'tinymce';
  9869. if (bi.indexOf('=') != -1) {
  9870. bi = t.getParam('body_id', '', 'hash');
  9871. bi = bi[t.id] || bi;
  9872. }
  9873. bc = s.body_class || '';
  9874. if (bc.indexOf('=') != -1) {
  9875. bc = t.getParam('body_class', '', 'hash');
  9876. bc = bc[t.id] || '';
  9877. }
  9878. t.iframeHTML += '</head><body id="' + bi + '" class="mceContentBody ' + bc + '" onload="window.parent.tinyMCE.get(\'' + t.id + '\').onLoad.dispatch();"><br></body></html>';
  9879. // Domain relaxing enabled, then set document domain
  9880. if (tinymce.relaxedDomain && (isIE || (tinymce.isOpera && parseFloat(opera.version()) < 11))) {
  9881. // We need to write the contents here in IE since multiple writes messes up refresh button and back button
  9882. 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();})()';
  9883. }
  9884. // Create iframe
  9885. // TODO: ACC add the appropriate description on this.
  9886. n = DOM.add(o.iframeContainer, 'iframe', {
  9887. id : t.id + "_ifr",
  9888. src : u || 'javascript:""', // Workaround for HTTPS warning in IE6/7
  9889. frameBorder : '0',
  9890. allowTransparency : "true",
  9891. title : s.aria_label,
  9892. style : {
  9893. width : '100%',
  9894. height : h,
  9895. display : 'block' // Important for Gecko to render the iframe correctly
  9896. }
  9897. });
  9898. t.contentAreaContainer = o.iframeContainer;
  9899. if (o.editorContainer) {
  9900. DOM.get(o.editorContainer).style.display = t.orgDisplay;
  9901. }
  9902. // Restore visibility on target element
  9903. e.style.visibility = t.orgVisibility;
  9904. DOM.get(t.id).style.display = 'none';
  9905. DOM.setAttrib(t.id, 'aria-hidden', true);
  9906. if (!tinymce.relaxedDomain || !u)
  9907. t.initContentBody();
  9908. e = n = o = null; // Cleanup
  9909. },
  9910. initContentBody : function() {
  9911. var self = this, settings = self.settings, targetElm = DOM.get(self.id), doc = self.getDoc(), html, body, contentCssText;
  9912. // Setup iframe body
  9913. if ((!isIE || !tinymce.relaxedDomain) && !settings.content_editable) {
  9914. doc.open();
  9915. doc.write(self.iframeHTML);
  9916. doc.close();
  9917. if (tinymce.relaxedDomain)
  9918. doc.domain = tinymce.relaxedDomain;
  9919. }
  9920. if (settings.content_editable) {
  9921. DOM.addClass(targetElm, 'mceContentBody');
  9922. self.contentDocument = doc = settings.content_document || document;
  9923. self.contentWindow = settings.content_window || window;
  9924. self.bodyElement = targetElm;
  9925. // Prevent leak in IE
  9926. settings.content_document = settings.content_window = null;
  9927. }
  9928. // It will not steal focus while setting contentEditable
  9929. body = self.getBody();
  9930. body.disabled = true;
  9931. if (!settings.readonly)
  9932. body.contentEditable = self.getParam('content_editable_state', true);
  9933. body.disabled = false;
  9934. self.schema = new tinymce.html.Schema(settings);
  9935. self.dom = new tinymce.dom.DOMUtils(doc, {
  9936. keep_values : true,
  9937. url_converter : self.convertURL,
  9938. url_converter_scope : self,
  9939. hex_colors : settings.force_hex_style_colors,
  9940. class_filter : settings.class_filter,
  9941. update_styles : true,
  9942. root_element : settings.content_editable ? self.id : null,
  9943. schema : self.schema
  9944. });
  9945. self.parser = new tinymce.html.DomParser(settings, self.schema);
  9946. // Convert src and href into data-mce-src, data-mce-href and data-mce-style
  9947. self.parser.addAttributeFilter('src,href,style', function(nodes, name) {
  9948. var i = nodes.length, node, dom = self.dom, value, internalName;
  9949. while (i--) {
  9950. node = nodes[i];
  9951. value = node.attr(name);
  9952. internalName = 'data-mce-' + name;
  9953. // Add internal attribute if we need to we don't on a refresh of the document
  9954. if (!node.attributes.map[internalName]) {
  9955. if (name === "style")
  9956. node.attr(internalName, dom.serializeStyle(dom.parseStyle(value), node.name));
  9957. else
  9958. node.attr(internalName, self.convertURL(value, name, node.name));
  9959. }
  9960. }
  9961. });
  9962. // Keep scripts from executing
  9963. self.parser.addNodeFilter('script', function(nodes, name) {
  9964. var i = nodes.length, node;
  9965. while (i--) {
  9966. node = nodes[i];
  9967. node.attr('type', 'mce-' + (node.attr('type') || 'text/javascript'));
  9968. }
  9969. });
  9970. self.parser.addNodeFilter('#cdata', function(nodes, name) {
  9971. var i = nodes.length, node;
  9972. while (i--) {
  9973. node = nodes[i];
  9974. node.type = 8;
  9975. node.name = '#comment';
  9976. node.value = '[CDATA[' + node.value + ']]';
  9977. }
  9978. });
  9979. self.parser.addNodeFilter('p,h1,h2,h3,h4,h5,h6,div', function(nodes, name) {
  9980. var i = nodes.length, node, nonEmptyElements = self.schema.getNonEmptyElements();
  9981. while (i--) {
  9982. node = nodes[i];
  9983. if (node.isEmpty(nonEmptyElements))
  9984. node.empty().append(new tinymce.html.Node('br', 1)).shortEnded = true;
  9985. }
  9986. });
  9987. self.serializer = new tinymce.dom.Serializer(settings, self.dom, self.schema);
  9988. self.selection = new tinymce.dom.Selection(self.dom, self.getWin(), self.serializer, self);
  9989. self.formatter = new tinymce.Formatter(self);
  9990. self.undoManager = new tinymce.UndoManager(self);
  9991. self.forceBlocks = new tinymce.ForceBlocks(self);
  9992. self.enterKey = new tinymce.EnterKey(self);
  9993. self.editorCommands = new tinymce.EditorCommands(self);
  9994. self.onExecCommand.add(function(editor, command) {
  9995. // Don't refresh the select lists until caret move
  9996. if (!/^(FontName|FontSize)$/.test(command))
  9997. self.nodeChanged();
  9998. });
  9999. // Pass through
  10000. self.serializer.onPreProcess.add(function(se, o) {
  10001. return self.onPreProcess.dispatch(self, o, se);
  10002. });
  10003. self.serializer.onPostProcess.add(function(se, o) {
  10004. return self.onPostProcess.dispatch(self, o, se);
  10005. });
  10006. self.onPreInit.dispatch(self);
  10007. if (!settings.browser_spellcheck && !settings.gecko_spellcheck)
  10008. doc.body.spellcheck = false;
  10009. if (!settings.readonly) {
  10010. self.bindNativeEvents();
  10011. }
  10012. self.controlManager.onPostRender.dispatch(self, self.controlManager);
  10013. self.onPostRender.dispatch(self);
  10014. self.quirks = tinymce.util.Quirks(self);
  10015. if (settings.directionality)
  10016. body.dir = settings.directionality;
  10017. if (settings.nowrap)
  10018. body.style.whiteSpace = "nowrap";
  10019. if (settings.protect) {
  10020. self.onBeforeSetContent.add(function(ed, o) {
  10021. each(settings.protect, function(pattern) {
  10022. o.content = o.content.replace(pattern, function(str) {
  10023. return '<!--mce:protected ' + escape(str) + '-->';
  10024. });
  10025. });
  10026. });
  10027. }
  10028. // Add visual aids when new contents is added
  10029. self.onSetContent.add(function() {
  10030. self.addVisual(self.getBody());
  10031. });
  10032. // Remove empty contents
  10033. if (settings.padd_empty_editor) {
  10034. self.onPostProcess.add(function(ed, o) {
  10035. o.content = o.content.replace(/^(<p[^>]*>(&nbsp;|&#160;|\s|\u00a0|)<\/p>[\r\n]*|<br \/>[\r\n]*)$/, '');
  10036. });
  10037. }
  10038. self.load({initial : true, format : 'html'});
  10039. self.startContent = self.getContent({format : 'raw'});
  10040. self.initialized = true;
  10041. self.onInit.dispatch(self);
  10042. self.execCallback('setupcontent_callback', self.id, body, doc);
  10043. self.execCallback('init_instance_callback', self);
  10044. self.focus(true);
  10045. self.nodeChanged({initial : true});
  10046. // Add editor specific CSS styles
  10047. if (self.contentStyles.length > 0) {
  10048. contentCssText = '';
  10049. each(self.contentStyles, function(style) {
  10050. contentCssText += style + "\r\n";
  10051. });
  10052. self.dom.addStyle(contentCssText);
  10053. }
  10054. // Load specified content CSS last
  10055. each(self.contentCSS, function(url) {
  10056. self.dom.loadCSS(url);
  10057. });
  10058. // Handle auto focus
  10059. if (settings.auto_focus) {
  10060. setTimeout(function () {
  10061. var ed = tinymce.get(settings.auto_focus);
  10062. ed.selection.select(ed.getBody(), 1);
  10063. ed.selection.collapse(1);
  10064. ed.getBody().focus();
  10065. ed.getWin().focus();
  10066. }, 100);
  10067. }
  10068. // Clean up references for IE
  10069. targetElm = doc = body = null;
  10070. },
  10071. focus : function(skip_focus) {
  10072. var oed, self = this, selection = self.selection, contentEditable = self.settings.content_editable, ieRng, controlElm, doc = self.getDoc(), body;
  10073. if (!skip_focus) {
  10074. if (self.lastIERng) {
  10075. selection.setRng(self.lastIERng);
  10076. }
  10077. // Get selected control element
  10078. ieRng = selection.getRng();
  10079. if (ieRng.item) {
  10080. controlElm = ieRng.item(0);
  10081. }
  10082. self._refreshContentEditable();
  10083. // Focus the window iframe
  10084. if (!contentEditable) {
  10085. self.getWin().focus();
  10086. }
  10087. // Focus the body as well since it's contentEditable
  10088. if (tinymce.isGecko || contentEditable) {
  10089. body = self.getBody();
  10090. // Check for setActive since it doesn't scroll to the element
  10091. if (body.setActive) {
  10092. body.setActive();
  10093. } else {
  10094. body.focus();
  10095. }
  10096. if (contentEditable) {
  10097. selection.normalize();
  10098. }
  10099. }
  10100. // Restore selected control element
  10101. // This is needed when for example an image is selected within a
  10102. // layer a call to focus will then remove the control selection
  10103. if (controlElm && controlElm.ownerDocument == doc) {
  10104. ieRng = doc.body.createControlRange();
  10105. ieRng.addElement(controlElm);
  10106. ieRng.select();
  10107. }
  10108. }
  10109. if (tinymce.activeEditor != self) {
  10110. if ((oed = tinymce.activeEditor) != null)
  10111. oed.onDeactivate.dispatch(oed, self);
  10112. self.onActivate.dispatch(self, oed);
  10113. }
  10114. tinymce._setActive(self);
  10115. },
  10116. execCallback : function(n) {
  10117. var t = this, f = t.settings[n], s;
  10118. if (!f)
  10119. return;
  10120. // Look through lookup
  10121. if (t.callbackLookup && (s = t.callbackLookup[n])) {
  10122. f = s.func;
  10123. s = s.scope;
  10124. }
  10125. if (is(f, 'string')) {
  10126. s = f.replace(/\.\w+$/, '');
  10127. s = s ? tinymce.resolve(s) : 0;
  10128. f = tinymce.resolve(f);
  10129. t.callbackLookup = t.callbackLookup || {};
  10130. t.callbackLookup[n] = {func : f, scope : s};
  10131. }
  10132. return f.apply(s || t, Array.prototype.slice.call(arguments, 1));
  10133. },
  10134. translate : function(s) {
  10135. var c = this.settings.language || 'en', i18n = tinymce.i18n;
  10136. if (!s)
  10137. return '';
  10138. return i18n[c + '.' + s] || s.replace(/\{\#([^\}]+)\}/g, function(a, b) {
  10139. return i18n[c + '.' + b] || '{#' + b + '}';
  10140. });
  10141. },
  10142. getLang : function(n, dv) {
  10143. return tinymce.i18n[(this.settings.language || 'en') + '.' + n] || (is(dv) ? dv : '{#' + n + '}');
  10144. },
  10145. getParam : function(n, dv, ty) {
  10146. var tr = tinymce.trim, v = is(this.settings[n]) ? this.settings[n] : dv, o;
  10147. if (ty === 'hash') {
  10148. o = {};
  10149. if (is(v, 'string')) {
  10150. each(v.indexOf('=') > 0 ? v.split(/[;,](?![^=;,]*(?:[;,]|$))/) : v.split(','), function(v) {
  10151. v = v.split('=');
  10152. if (v.length > 1)
  10153. o[tr(v[0])] = tr(v[1]);
  10154. else
  10155. o[tr(v[0])] = tr(v);
  10156. });
  10157. } else
  10158. o = v;
  10159. return o;
  10160. }
  10161. return v;
  10162. },
  10163. nodeChanged : function(o) {
  10164. var self = this, selection = self.selection, node;
  10165. // Fix for bug #1896577 it seems that this can not be fired while the editor is loading
  10166. if (self.initialized) {
  10167. o = o || {};
  10168. // Get start node
  10169. node = selection.getStart() || self.getBody();
  10170. node = isIE && node.ownerDocument != self.getDoc() ? self.getBody() : node; // Fix for IE initial state
  10171. // Get parents and add them to object
  10172. o.parents = [];
  10173. self.dom.getParent(node, function(node) {
  10174. if (node.nodeName == 'BODY')
  10175. return true;
  10176. o.parents.push(node);
  10177. });
  10178. self.onNodeChange.dispatch(
  10179. self,
  10180. o ? o.controlManager || self.controlManager : self.controlManager,
  10181. node,
  10182. selection.isCollapsed(),
  10183. o
  10184. );
  10185. }
  10186. },
  10187. addButton : function(name, settings) {
  10188. var self = this;
  10189. self.buttons = self.buttons || {};
  10190. self.buttons[name] = settings;
  10191. },
  10192. addCommand : function(name, callback, scope) {
  10193. this.execCommands[name] = {func : callback, scope : scope || this};
  10194. },
  10195. addQueryStateHandler : function(name, callback, scope) {
  10196. this.queryStateCommands[name] = {func : callback, scope : scope || this};
  10197. },
  10198. addQueryValueHandler : function(name, callback, scope) {
  10199. this.queryValueCommands[name] = {func : callback, scope : scope || this};
  10200. },
  10201. addShortcut : function(pa, desc, cmd_func, sc) {
  10202. var t = this, c;
  10203. if (t.settings.custom_shortcuts === false)
  10204. return false;
  10205. t.shortcuts = t.shortcuts || {};
  10206. if (is(cmd_func, 'string')) {
  10207. c = cmd_func;
  10208. cmd_func = function() {
  10209. t.execCommand(c, false, null);
  10210. };
  10211. }
  10212. if (is(cmd_func, 'object')) {
  10213. c = cmd_func;
  10214. cmd_func = function() {
  10215. t.execCommand(c[0], c[1], c[2]);
  10216. };
  10217. }
  10218. each(explode(pa), function(pa) {
  10219. var o = {
  10220. func : cmd_func,
  10221. scope : sc || this,
  10222. desc : t.translate(desc),
  10223. alt : false,
  10224. ctrl : false,
  10225. shift : false
  10226. };
  10227. each(explode(pa, '+'), function(v) {
  10228. switch (v) {
  10229. case 'alt':
  10230. case 'ctrl':
  10231. case 'shift':
  10232. o[v] = true;
  10233. break;
  10234. default:
  10235. o.charCode = v.charCodeAt(0);
  10236. o.keyCode = v.toUpperCase().charCodeAt(0);
  10237. }
  10238. });
  10239. t.shortcuts[(o.ctrl ? 'ctrl' : '') + ',' + (o.alt ? 'alt' : '') + ',' + (o.shift ? 'shift' : '') + ',' + o.keyCode] = o;
  10240. });
  10241. return true;
  10242. },
  10243. execCommand : function(cmd, ui, val, a) {
  10244. var t = this, s = 0, o, st;
  10245. if (!/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint|SelectAll)$/.test(cmd) && (!a || !a.skip_focus))
  10246. t.focus();
  10247. a = extend({}, a);
  10248. t.onBeforeExecCommand.dispatch(t, cmd, ui, val, a);
  10249. if (a.terminate)
  10250. return false;
  10251. // Command callback
  10252. if (t.execCallback('execcommand_callback', t.id, t.selection.getNode(), cmd, ui, val)) {
  10253. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  10254. return true;
  10255. }
  10256. // Registred commands
  10257. if (o = t.execCommands[cmd]) {
  10258. st = o.func.call(o.scope, ui, val);
  10259. // Fall through on true
  10260. if (st !== true) {
  10261. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  10262. return st;
  10263. }
  10264. }
  10265. // Plugin commands
  10266. each(t.plugins, function(p) {
  10267. if (p.execCommand && p.execCommand(cmd, ui, val)) {
  10268. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  10269. s = 1;
  10270. return false;
  10271. }
  10272. });
  10273. if (s)
  10274. return true;
  10275. // Theme commands
  10276. if (t.theme && t.theme.execCommand && t.theme.execCommand(cmd, ui, val)) {
  10277. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  10278. return true;
  10279. }
  10280. // Editor commands
  10281. if (t.editorCommands.execCommand(cmd, ui, val)) {
  10282. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  10283. return true;
  10284. }
  10285. // Browser commands
  10286. t.getDoc().execCommand(cmd, ui, val);
  10287. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  10288. },
  10289. queryCommandState : function(cmd) {
  10290. var t = this, o, s;
  10291. // Is hidden then return undefined
  10292. if (t._isHidden())
  10293. return;
  10294. // Registred commands
  10295. if (o = t.queryStateCommands[cmd]) {
  10296. s = o.func.call(o.scope);
  10297. // Fall though on true
  10298. if (s !== true)
  10299. return s;
  10300. }
  10301. // Registred commands
  10302. o = t.editorCommands.queryCommandState(cmd);
  10303. if (o !== -1)
  10304. return o;
  10305. // Browser commands
  10306. try {
  10307. return this.getDoc().queryCommandState(cmd);
  10308. } catch (ex) {
  10309. // Fails sometimes see bug: 1896577
  10310. }
  10311. },
  10312. queryCommandValue : function(c) {
  10313. var t = this, o, s;
  10314. // Is hidden then return undefined
  10315. if (t._isHidden())
  10316. return;
  10317. // Registred commands
  10318. if (o = t.queryValueCommands[c]) {
  10319. s = o.func.call(o.scope);
  10320. // Fall though on true
  10321. if (s !== true)
  10322. return s;
  10323. }
  10324. // Registred commands
  10325. o = t.editorCommands.queryCommandValue(c);
  10326. if (is(o))
  10327. return o;
  10328. // Browser commands
  10329. try {
  10330. return this.getDoc().queryCommandValue(c);
  10331. } catch (ex) {
  10332. // Fails sometimes see bug: 1896577
  10333. }
  10334. },
  10335. show : function() {
  10336. var self = this;
  10337. DOM.show(self.getContainer());
  10338. DOM.hide(self.id);
  10339. self.load();
  10340. },
  10341. hide : function() {
  10342. var self = this, doc = self.getDoc();
  10343. // Fixed bug where IE has a blinking cursor left from the editor
  10344. if (isIE && doc)
  10345. doc.execCommand('SelectAll');
  10346. // We must save before we hide so Safari doesn't crash
  10347. self.save();
  10348. // defer the call to hide to prevent an IE9 crash #4921
  10349. setTimeout(function() {
  10350. DOM.hide(self.getContainer());
  10351. }, 1);
  10352. DOM.setStyle(self.id, 'display', self.orgDisplay);
  10353. },
  10354. isHidden : function() {
  10355. return !DOM.isHidden(this.id);
  10356. },
  10357. setProgressState : function(b, ti, o) {
  10358. this.onSetProgressState.dispatch(this, b, ti, o);
  10359. return b;
  10360. },
  10361. load : function(o) {
  10362. var t = this, e = t.getElement(), h;
  10363. if (e) {
  10364. o = o || {};
  10365. o.load = true;
  10366. // Double encode existing entities in the value
  10367. h = t.setContent(is(e.value) ? e.value : e.innerHTML, o);
  10368. o.element = e;
  10369. if (!o.no_events)
  10370. t.onLoadContent.dispatch(t, o);
  10371. o.element = e = null;
  10372. return h;
  10373. }
  10374. },
  10375. save : function(o) {
  10376. var t = this, e = t.getElement(), h, f;
  10377. if (!e || !t.initialized)
  10378. return;
  10379. o = o || {};
  10380. o.save = true;
  10381. o.element = e;
  10382. h = o.content = t.getContent(o);
  10383. if (!o.no_events)
  10384. t.onSaveContent.dispatch(t, o);
  10385. h = o.content;
  10386. if (!/TEXTAREA|INPUT/i.test(e.nodeName)) {
  10387. e.innerHTML = h;
  10388. // Update hidden form element
  10389. if (f = DOM.getParent(t.id, 'form')) {
  10390. each(f.elements, function(e) {
  10391. if (e.name == t.id) {
  10392. e.value = h;
  10393. return false;
  10394. }
  10395. });
  10396. }
  10397. } else
  10398. e.value = h;
  10399. o.element = e = null;
  10400. return h;
  10401. },
  10402. setContent : function(content, args) {
  10403. var self = this, rootNode, body = self.getBody(), forcedRootBlockName;
  10404. // Setup args object
  10405. args = args || {};
  10406. args.format = args.format || 'html';
  10407. args.set = true;
  10408. args.content = content;
  10409. // Do preprocessing
  10410. if (!args.no_events)
  10411. self.onBeforeSetContent.dispatch(self, args);
  10412. content = args.content;
  10413. // Padd empty content in Gecko and Safari. Commands will otherwise fail on the content
  10414. // It will also be impossible to place the caret in the editor unless there is a BR element present
  10415. if (!tinymce.isIE && (content.length === 0 || /^\s+$/.test(content))) {
  10416. forcedRootBlockName = self.settings.forced_root_block;
  10417. if (forcedRootBlockName)
  10418. content = '<' + forcedRootBlockName + '><br data-mce-bogus="1"></' + forcedRootBlockName + '>';
  10419. else
  10420. content = '<br data-mce-bogus="1">';
  10421. body.innerHTML = content;
  10422. self.selection.select(body, true);
  10423. self.selection.collapse(true);
  10424. return;
  10425. }
  10426. // Parse and serialize the html
  10427. if (args.format !== 'raw') {
  10428. content = new tinymce.html.Serializer({}, self.schema).serialize(
  10429. self.parser.parse(content)
  10430. );
  10431. }
  10432. // Set the new cleaned contents to the editor
  10433. args.content = tinymce.trim(content);
  10434. self.dom.setHTML(body, args.content);
  10435. // Do post processing
  10436. if (!args.no_events)
  10437. self.onSetContent.dispatch(self, args);
  10438. // Don't normalize selection if the focused element isn't the body in content editable mode since it will steal focus otherwise
  10439. if (!self.settings.content_editable || document.activeElement === self.getBody()) {
  10440. self.selection.normalize();
  10441. }
  10442. return args.content;
  10443. },
  10444. getContent : function(args) {
  10445. var self = this, content, body = self.getBody();
  10446. // Setup args object
  10447. args = args || {};
  10448. args.format = args.format || 'html';
  10449. args.get = true;
  10450. args.getInner = true;
  10451. // Do preprocessing
  10452. if (!args.no_events)
  10453. self.onBeforeGetContent.dispatch(self, args);
  10454. // Get raw contents or by default the cleaned contents
  10455. if (args.format == 'raw')
  10456. content = body.innerHTML;
  10457. else if (args.format == 'text')
  10458. content = body.innerText || body.textContent;
  10459. else
  10460. content = self.serializer.serialize(body, args);
  10461. // Trim whitespace in beginning/end of HTML
  10462. if (args.format != 'text') {
  10463. args.content = tinymce.trim(content);
  10464. } else {
  10465. args.content = content;
  10466. }
  10467. // Do post processing
  10468. if (!args.no_events)
  10469. self.onGetContent.dispatch(self, args);
  10470. return args.content;
  10471. },
  10472. isDirty : function() {
  10473. var self = this;
  10474. return tinymce.trim(self.startContent) != tinymce.trim(self.getContent({format : 'raw', no_events : 1})) && !self.isNotDirty;
  10475. },
  10476. getContainer : function() {
  10477. var self = this;
  10478. if (!self.container)
  10479. self.container = DOM.get(self.editorContainer || self.id + '_parent');
  10480. return self.container;
  10481. },
  10482. getContentAreaContainer : function() {
  10483. return this.contentAreaContainer;
  10484. },
  10485. getElement : function() {
  10486. return DOM.get(this.settings.content_element || this.id);
  10487. },
  10488. getWin : function() {
  10489. var self = this, elm;
  10490. if (!self.contentWindow) {
  10491. elm = DOM.get(self.id + "_ifr");
  10492. if (elm)
  10493. self.contentWindow = elm.contentWindow;
  10494. }
  10495. return self.contentWindow;
  10496. },
  10497. getDoc : function() {
  10498. var self = this, win;
  10499. if (!self.contentDocument) {
  10500. win = self.getWin();
  10501. if (win)
  10502. self.contentDocument = win.document;
  10503. }
  10504. return self.contentDocument;
  10505. },
  10506. getBody : function() {
  10507. return this.bodyElement || this.getDoc().body;
  10508. },
  10509. convertURL : function(url, name, elm) {
  10510. var self = this, settings = self.settings;
  10511. // Use callback instead
  10512. if (settings.urlconverter_callback)
  10513. return self.execCallback('urlconverter_callback', url, elm, true, name);
  10514. // Don't convert link href since thats the CSS files that gets loaded into the editor also skip local file URLs
  10515. if (!settings.convert_urls || (elm && elm.nodeName == 'LINK') || url.indexOf('file:') === 0)
  10516. return url;
  10517. // Convert to relative
  10518. if (settings.relative_urls)
  10519. return self.documentBaseURI.toRelative(url);
  10520. // Convert to absolute
  10521. url = self.documentBaseURI.toAbsolute(url, settings.remove_script_host);
  10522. return url;
  10523. },
  10524. addVisual : function(elm) {
  10525. var self = this, settings = self.settings, dom = self.dom, cls;
  10526. elm = elm || self.getBody();
  10527. if (!is(self.hasVisual))
  10528. self.hasVisual = settings.visual;
  10529. each(dom.select('table,a', elm), function(elm) {
  10530. var value;
  10531. switch (elm.nodeName) {
  10532. case 'TABLE':
  10533. cls = settings.visual_table_class || 'mceItemTable';
  10534. value = dom.getAttrib(elm, 'border');
  10535. if (!value || value == '0') {
  10536. if (self.hasVisual)
  10537. dom.addClass(elm, cls);
  10538. else
  10539. dom.removeClass(elm, cls);
  10540. }
  10541. return;
  10542. case 'A':
  10543. if (!dom.getAttrib(elm, 'href', false)) {
  10544. value = dom.getAttrib(elm, 'name') || elm.id;
  10545. cls = 'mceItemAnchor';
  10546. if (value) {
  10547. if (self.hasVisual)
  10548. dom.addClass(elm, cls);
  10549. else
  10550. dom.removeClass(elm, cls);
  10551. }
  10552. }
  10553. return;
  10554. }
  10555. });
  10556. self.onVisualAid.dispatch(self, elm, self.hasVisual);
  10557. },
  10558. remove : function() {
  10559. var self = this, elm = self.getContainer();
  10560. if (!self.removed) {
  10561. self.removed = 1; // Cancels post remove event execution
  10562. self.hide();
  10563. // Don't clear the window or document if content editable
  10564. // is enabled since other instances might still be present
  10565. if (!self.settings.content_editable) {
  10566. Event.unbind(self.getWin());
  10567. Event.unbind(self.getDoc());
  10568. }
  10569. Event.unbind(self.getBody());
  10570. Event.clear(elm);
  10571. self.execCallback('remove_instance_callback', self);
  10572. self.onRemove.dispatch(self);
  10573. // Clear all execCommand listeners this is required to avoid errors if the editor was removed inside another command
  10574. self.onExecCommand.listeners = [];
  10575. tinymce.remove(self);
  10576. DOM.remove(elm);
  10577. }
  10578. },
  10579. destroy : function(s) {
  10580. var t = this;
  10581. // One time is enough
  10582. if (t.destroyed)
  10583. return;
  10584. // We must unbind on Gecko since it would otherwise produce the pesky "attempt to run compile-and-go script on a cleared scope" message
  10585. if (isGecko) {
  10586. Event.unbind(t.getDoc());
  10587. Event.unbind(t.getWin());
  10588. Event.unbind(t.getBody());
  10589. }
  10590. if (!s) {
  10591. tinymce.removeUnload(t.destroy);
  10592. tinyMCE.onBeforeUnload.remove(t._beforeUnload);
  10593. // Manual destroy
  10594. if (t.theme && t.theme.destroy)
  10595. t.theme.destroy();
  10596. // Destroy controls, selection and dom
  10597. t.controlManager.destroy();
  10598. t.selection.destroy();
  10599. t.dom.destroy();
  10600. }
  10601. if (t.formElement) {
  10602. t.formElement.submit = t.formElement._mceOldSubmit;
  10603. t.formElement._mceOldSubmit = null;
  10604. }
  10605. t.contentAreaContainer = t.formElement = t.container = t.settings.content_element = t.bodyElement = t.contentDocument = t.contentWindow = null;
  10606. if (t.selection)
  10607. t.selection = t.selection.win = t.selection.dom = t.selection.dom.doc = null;
  10608. t.destroyed = 1;
  10609. },
  10610. // Internal functions
  10611. _refreshContentEditable : function() {
  10612. var self = this, body, parent;
  10613. // Check if the editor was hidden and the re-initalize contentEditable mode by removing and adding the body again
  10614. if (self._isHidden()) {
  10615. body = self.getBody();
  10616. parent = body.parentNode;
  10617. parent.removeChild(body);
  10618. parent.appendChild(body);
  10619. body.focus();
  10620. }
  10621. },
  10622. _isHidden : function() {
  10623. var s;
  10624. if (!isGecko)
  10625. return 0;
  10626. // Weird, wheres that cursor selection?
  10627. s = this.selection.getSel();
  10628. return (!s || !s.rangeCount || s.rangeCount === 0);
  10629. }
  10630. });
  10631. })(tinymce);
  10632. (function(tinymce) {
  10633. var each = tinymce.each;
  10634. tinymce.Editor.prototype.setupEvents = function() {
  10635. var self = this, settings = self.settings;
  10636. // Add events to the editor
  10637. each([
  10638. 'onPreInit',
  10639. 'onBeforeRenderUI',
  10640. 'onPostRender',
  10641. 'onLoad',
  10642. 'onInit',
  10643. 'onRemove',
  10644. 'onActivate',
  10645. 'onDeactivate',
  10646. 'onClick',
  10647. 'onEvent',
  10648. 'onMouseUp',
  10649. 'onMouseDown',
  10650. 'onDblClick',
  10651. 'onKeyDown',
  10652. 'onKeyUp',
  10653. 'onKeyPress',
  10654. 'onContextMenu',
  10655. 'onSubmit',
  10656. 'onReset',
  10657. 'onPaste',
  10658. 'onPreProcess',
  10659. 'onPostProcess',
  10660. 'onBeforeSetContent',
  10661. 'onBeforeGetContent',
  10662. 'onSetContent',
  10663. 'onGetContent',
  10664. 'onLoadContent',
  10665. 'onSaveContent',
  10666. 'onNodeChange',
  10667. 'onChange',
  10668. 'onBeforeExecCommand',
  10669. 'onExecCommand',
  10670. 'onUndo',
  10671. 'onRedo',
  10672. 'onVisualAid',
  10673. 'onSetProgressState',
  10674. 'onSetAttrib'
  10675. ], function(name) {
  10676. self[name] = new tinymce.util.Dispatcher(self);
  10677. });
  10678. // Handle legacy cleanup_callback option
  10679. if (settings.cleanup_callback) {
  10680. self.onBeforeSetContent.add(function(ed, o) {
  10681. o.content = ed.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  10682. });
  10683. self.onPreProcess.add(function(ed, o) {
  10684. if (o.set)
  10685. ed.execCallback('cleanup_callback', 'insert_to_editor_dom', o.node, o);
  10686. if (o.get)
  10687. ed.execCallback('cleanup_callback', 'get_from_editor_dom', o.node, o);
  10688. });
  10689. self.onPostProcess.add(function(ed, o) {
  10690. if (o.set)
  10691. o.content = ed.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  10692. if (o.get)
  10693. o.content = ed.execCallback('cleanup_callback', 'get_from_editor', o.content, o);
  10694. });
  10695. }
  10696. // Handle legacy save_callback option
  10697. if (settings.save_callback) {
  10698. self.onGetContent.add(function(ed, o) {
  10699. if (o.save)
  10700. o.content = ed.execCallback('save_callback', ed.id, o.content, ed.getBody());
  10701. });
  10702. }
  10703. // Handle legacy handle_event_callback option
  10704. if (settings.handle_event_callback) {
  10705. self.onEvent.add(function(ed, e, o) {
  10706. if (self.execCallback('handle_event_callback', e, ed, o) === false) {
  10707. e.preventDefault();
  10708. e.stopPropagation();
  10709. }
  10710. });
  10711. }
  10712. // Handle legacy handle_node_change_callback option
  10713. if (settings.handle_node_change_callback) {
  10714. self.onNodeChange.add(function(ed, cm, n) {
  10715. ed.execCallback('handle_node_change_callback', ed.id, n, -1, -1, true, ed.selection.isCollapsed());
  10716. });
  10717. }
  10718. // Handle legacy save_callback option
  10719. if (settings.save_callback) {
  10720. self.onSaveContent.add(function(ed, o) {
  10721. var h = ed.execCallback('save_callback', ed.id, o.content, ed.getBody());
  10722. if (h)
  10723. o.content = h;
  10724. });
  10725. }
  10726. // Handle legacy onchange_callback option
  10727. if (settings.onchange_callback) {
  10728. self.onChange.add(function(ed, l) {
  10729. ed.execCallback('onchange_callback', ed, l);
  10730. });
  10731. }
  10732. };
  10733. tinymce.Editor.prototype.bindNativeEvents = function() {
  10734. // 'focus', 'blur', 'dblclick', 'beforedeactivate', submit, reset
  10735. var self = this, i, settings = self.settings, dom = self.dom, nativeToDispatcherMap;
  10736. nativeToDispatcherMap = {
  10737. mouseup : 'onMouseUp',
  10738. mousedown : 'onMouseDown',
  10739. click : 'onClick',
  10740. keyup : 'onKeyUp',
  10741. keydown : 'onKeyDown',
  10742. keypress : 'onKeyPress',
  10743. submit : 'onSubmit',
  10744. reset : 'onReset',
  10745. contextmenu : 'onContextMenu',
  10746. dblclick : 'onDblClick',
  10747. paste : 'onPaste' // Doesn't work in all browsers yet
  10748. };
  10749. // Handler that takes a native event and sends it out to a dispatcher like onKeyDown
  10750. function eventHandler(evt, args) {
  10751. var type = evt.type;
  10752. // Don't fire events when it's removed
  10753. if (self.removed)
  10754. return;
  10755. // Sends the native event out to a global dispatcher then to the specific event dispatcher
  10756. if (self.onEvent.dispatch(self, evt, args) !== false) {
  10757. self[nativeToDispatcherMap[evt.fakeType || evt.type]].dispatch(self, evt, args);
  10758. }
  10759. };
  10760. // Opera doesn't support focus event for contentEditable elements so we need to fake it
  10761. function doOperaFocus(e) {
  10762. self.focus(true);
  10763. };
  10764. function nodeChanged(ed, e) {
  10765. // 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
  10766. if (e.keyCode != 65 || !tinymce.VK.metaKeyPressed(e)) {
  10767. self.selection.normalize();
  10768. }
  10769. self.nodeChanged();
  10770. }
  10771. // Add DOM events
  10772. each(nativeToDispatcherMap, function(dispatcherName, nativeName) {
  10773. var root = settings.content_editable ? self.getBody() : self.getDoc();
  10774. switch (nativeName) {
  10775. case 'contextmenu':
  10776. dom.bind(root, nativeName, eventHandler);
  10777. break;
  10778. case 'paste':
  10779. dom.bind(self.getBody(), nativeName, eventHandler);
  10780. break;
  10781. case 'submit':
  10782. case 'reset':
  10783. dom.bind(self.getElement().form || tinymce.DOM.getParent(self.id, 'form'), nativeName, eventHandler);
  10784. break;
  10785. default:
  10786. dom.bind(root, nativeName, eventHandler);
  10787. }
  10788. });
  10789. // Set the editor as active when focused
  10790. dom.bind(settings.content_editable ? self.getBody() : (tinymce.isGecko ? self.getDoc() : self.getWin()), 'focus', function(e) {
  10791. self.focus(true);
  10792. });
  10793. if (settings.content_editable && tinymce.isOpera) {
  10794. dom.bind(self.getBody(), 'click', doOperaFocus);
  10795. dom.bind(self.getBody(), 'keydown', doOperaFocus);
  10796. }
  10797. // Add node change handler
  10798. self.onMouseUp.add(nodeChanged);
  10799. self.onKeyUp.add(function(ed, e) {
  10800. var keyCode = e.keyCode;
  10801. 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)
  10802. nodeChanged(ed, e);
  10803. });
  10804. // Add reset handler
  10805. self.onReset.add(function() {
  10806. self.setContent(self.startContent, {format : 'raw'});
  10807. });
  10808. // Add shortcuts
  10809. function handleShortcut(e, execute) {
  10810. if (e.altKey || e.ctrlKey || e.metaKey) {
  10811. each(self.shortcuts, function(shortcut) {
  10812. var ctrlState = tinymce.isMac ? e.metaKey : e.ctrlKey;
  10813. if (shortcut.ctrl != ctrlState || shortcut.alt != e.altKey || shortcut.shift != e.shiftKey)
  10814. return;
  10815. if (e.keyCode == shortcut.keyCode || (e.charCode && e.charCode == shortcut.charCode)) {
  10816. e.preventDefault();
  10817. if (execute) {
  10818. shortcut.func.call(shortcut.scope);
  10819. }
  10820. return true;
  10821. }
  10822. });
  10823. }
  10824. };
  10825. self.onKeyUp.add(function(ed, e) {
  10826. handleShortcut(e);
  10827. });
  10828. self.onKeyPress.add(function(ed, e) {
  10829. handleShortcut(e);
  10830. });
  10831. self.onKeyDown.add(function(ed, e) {
  10832. handleShortcut(e, true);
  10833. });
  10834. if (tinymce.isOpera) {
  10835. self.onClick.add(function(ed, e) {
  10836. e.preventDefault();
  10837. });
  10838. }
  10839. };
  10840. })(tinymce);
  10841. (function(tinymce) {
  10842. // Added for compression purposes
  10843. var each = tinymce.each, undef, TRUE = true, FALSE = false;
  10844. tinymce.EditorCommands = function(editor) {
  10845. var dom = editor.dom,
  10846. selection = editor.selection,
  10847. commands = {state: {}, exec : {}, value : {}},
  10848. settings = editor.settings,
  10849. formatter = editor.formatter,
  10850. bookmark;
  10851. function execCommand(command, ui, value) {
  10852. var func;
  10853. command = command.toLowerCase();
  10854. if (func = commands.exec[command]) {
  10855. func(command, ui, value);
  10856. return TRUE;
  10857. }
  10858. return FALSE;
  10859. };
  10860. function queryCommandState(command) {
  10861. var func;
  10862. command = command.toLowerCase();
  10863. if (func = commands.state[command])
  10864. return func(command);
  10865. return -1;
  10866. };
  10867. function queryCommandValue(command) {
  10868. var func;
  10869. command = command.toLowerCase();
  10870. if (func = commands.value[command])
  10871. return func(command);
  10872. return FALSE;
  10873. };
  10874. function addCommands(command_list, type) {
  10875. type = type || 'exec';
  10876. each(command_list, function(callback, command) {
  10877. each(command.toLowerCase().split(','), function(command) {
  10878. commands[type][command] = callback;
  10879. });
  10880. });
  10881. };
  10882. // Expose public methods
  10883. tinymce.extend(this, {
  10884. execCommand : execCommand,
  10885. queryCommandState : queryCommandState,
  10886. queryCommandValue : queryCommandValue,
  10887. addCommands : addCommands
  10888. });
  10889. // Private methods
  10890. function execNativeCommand(command, ui, value) {
  10891. if (ui === undef)
  10892. ui = FALSE;
  10893. if (value === undef)
  10894. value = null;
  10895. return editor.getDoc().execCommand(command, ui, value);
  10896. };
  10897. function isFormatMatch(name) {
  10898. return formatter.match(name);
  10899. };
  10900. function toggleFormat(name, value) {
  10901. formatter.toggle(name, value ? {value : value} : undef);
  10902. };
  10903. function storeSelection(type) {
  10904. bookmark = selection.getBookmark(type);
  10905. };
  10906. function restoreSelection() {
  10907. selection.moveToBookmark(bookmark);
  10908. };
  10909. // Add execCommand overrides
  10910. addCommands({
  10911. // Ignore these, added for compatibility
  10912. 'mceResetDesignMode,mceBeginUndoLevel' : function() {},
  10913. // Add undo manager logic
  10914. 'mceEndUndoLevel,mceAddUndoLevel' : function() {
  10915. editor.undoManager.add();
  10916. },
  10917. 'Cut,Copy,Paste' : function(command) {
  10918. var doc = editor.getDoc(), failed;
  10919. // Try executing the native command
  10920. try {
  10921. execNativeCommand(command);
  10922. } catch (ex) {
  10923. // Command failed
  10924. failed = TRUE;
  10925. }
  10926. // Present alert message about clipboard access not being available
  10927. if (failed || !doc.queryCommandSupported(command)) {
  10928. if (tinymce.isGecko) {
  10929. editor.windowManager.confirm(editor.getLang('clipboard_msg'), function(state) {
  10930. if (state)
  10931. open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', '_blank');
  10932. });
  10933. } else
  10934. editor.windowManager.alert(editor.getLang('clipboard_no_support'));
  10935. }
  10936. },
  10937. // Override unlink command
  10938. unlink : function(command) {
  10939. if (selection.isCollapsed())
  10940. selection.select(selection.getNode());
  10941. execNativeCommand(command);
  10942. selection.collapse(FALSE);
  10943. },
  10944. // Override justify commands to use the text formatter engine
  10945. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  10946. var align = command.substring(7);
  10947. // Remove all other alignments first
  10948. each('left,center,right,full'.split(','), function(name) {
  10949. if (align != name)
  10950. formatter.remove('align' + name);
  10951. });
  10952. toggleFormat('align' + align);
  10953. execCommand('mceRepaint');
  10954. },
  10955. // Override list commands to fix WebKit bug
  10956. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  10957. var listElm, listParent;
  10958. execNativeCommand(command);
  10959. // WebKit produces lists within block elements so we need to split them
  10960. // we will replace the native list creation logic to custom logic later on
  10961. // TODO: Remove this when the list creation logic is removed
  10962. listElm = dom.getParent(selection.getNode(), 'ol,ul');
  10963. if (listElm) {
  10964. listParent = listElm.parentNode;
  10965. // If list is within a text block then split that block
  10966. if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) {
  10967. storeSelection();
  10968. dom.split(listParent, listElm);
  10969. restoreSelection();
  10970. }
  10971. }
  10972. },
  10973. // Override commands to use the text formatter engine
  10974. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
  10975. toggleFormat(command);
  10976. },
  10977. // Override commands to use the text formatter engine
  10978. 'ForeColor,HiliteColor,FontName' : function(command, ui, value) {
  10979. toggleFormat(command, value);
  10980. },
  10981. FontSize : function(command, ui, value) {
  10982. var fontClasses, fontSizes;
  10983. // Convert font size 1-7 to styles
  10984. if (value >= 1 && value <= 7) {
  10985. fontSizes = tinymce.explode(settings.font_size_style_values);
  10986. fontClasses = tinymce.explode(settings.font_size_classes);
  10987. if (fontClasses)
  10988. value = fontClasses[value - 1] || value;
  10989. else
  10990. value = fontSizes[value - 1] || value;
  10991. }
  10992. toggleFormat(command, value);
  10993. },
  10994. RemoveFormat : function(command) {
  10995. formatter.remove(command);
  10996. },
  10997. mceBlockQuote : function(command) {
  10998. toggleFormat('blockquote');
  10999. },
  11000. FormatBlock : function(command, ui, value) {
  11001. return toggleFormat(value || 'p');
  11002. },
  11003. mceCleanup : function() {
  11004. var bookmark = selection.getBookmark();
  11005. editor.setContent(editor.getContent({cleanup : TRUE}), {cleanup : TRUE});
  11006. selection.moveToBookmark(bookmark);
  11007. },
  11008. mceRemoveNode : function(command, ui, value) {
  11009. var node = value || selection.getNode();
  11010. // Make sure that the body node isn't removed
  11011. if (node != editor.getBody()) {
  11012. storeSelection();
  11013. editor.dom.remove(node, TRUE);
  11014. restoreSelection();
  11015. }
  11016. },
  11017. mceSelectNodeDepth : function(command, ui, value) {
  11018. var counter = 0;
  11019. dom.getParent(selection.getNode(), function(node) {
  11020. if (node.nodeType == 1 && counter++ == value) {
  11021. selection.select(node);
  11022. return FALSE;
  11023. }
  11024. }, editor.getBody());
  11025. },
  11026. mceSelectNode : function(command, ui, value) {
  11027. selection.select(value);
  11028. },
  11029. mceInsertContent : function(command, ui, value) {
  11030. var parser, serializer, parentNode, rootNode, fragment, args,
  11031. marker, nodeRect, viewPortRect, rng, node, node2, bookmarkHtml, viewportBodyElement;
  11032. //selection.normalize();
  11033. // Setup parser and serializer
  11034. parser = editor.parser;
  11035. serializer = new tinymce.html.Serializer({}, editor.schema);
  11036. bookmarkHtml = '<span id="mce_marker" data-mce-type="bookmark">\uFEFF</span>';
  11037. // Run beforeSetContent handlers on the HTML to be inserted
  11038. args = {content: value, format: 'html'};
  11039. selection.onBeforeSetContent.dispatch(selection, args);
  11040. value = args.content;
  11041. // Add caret at end of contents if it's missing
  11042. if (value.indexOf('{$caret}') == -1)
  11043. value += '{$caret}';
  11044. // Replace the caret marker with a span bookmark element
  11045. value = value.replace(/\{\$caret\}/, bookmarkHtml);
  11046. // Insert node maker where we will insert the new HTML and get it's parent
  11047. if (!selection.isCollapsed())
  11048. editor.getDoc().execCommand('Delete', false, null);
  11049. parentNode = selection.getNode();
  11050. // Parse the fragment within the context of the parent node
  11051. args = {context : parentNode.nodeName.toLowerCase()};
  11052. fragment = parser.parse(value, args);
  11053. // Move the caret to a more suitable location
  11054. node = fragment.lastChild;
  11055. if (node.attr('id') == 'mce_marker') {
  11056. marker = node;
  11057. for (node = node.prev; node; node = node.walk(true)) {
  11058. if (node.type == 3 || !dom.isBlock(node.name)) {
  11059. node.parent.insert(marker, node, node.name === 'br');
  11060. break;
  11061. }
  11062. }
  11063. }
  11064. // If parser says valid we can insert the contents into that parent
  11065. if (!args.invalid) {
  11066. value = serializer.serialize(fragment);
  11067. // Check if parent is empty or only has one BR element then set the innerHTML of that parent
  11068. node = parentNode.firstChild;
  11069. node2 = parentNode.lastChild;
  11070. if (!node || (node === node2 && node.nodeName === 'BR'))
  11071. dom.setHTML(parentNode, value);
  11072. else
  11073. selection.setContent(value);
  11074. } else {
  11075. // If the fragment was invalid within that context then we need
  11076. // to parse and process the parent it's inserted into
  11077. // Insert bookmark node and get the parent
  11078. selection.setContent(bookmarkHtml);
  11079. parentNode = selection.getNode();
  11080. rootNode = editor.getBody();
  11081. // Opera will return the document node when selection is in root
  11082. if (parentNode.nodeType == 9)
  11083. parentNode = node = rootNode;
  11084. else
  11085. node = parentNode;
  11086. // Find the ancestor just before the root element
  11087. while (node !== rootNode) {
  11088. parentNode = node;
  11089. node = node.parentNode;
  11090. }
  11091. // Get the outer/inner HTML depending on if we are in the root and parser and serialize that
  11092. value = parentNode == rootNode ? rootNode.innerHTML : dom.getOuterHTML(parentNode);
  11093. value = serializer.serialize(
  11094. parser.parse(
  11095. // Need to replace by using a function since $ in the contents would otherwise be a problem
  11096. value.replace(/<span (id="mce_marker"|id=mce_marker).+?<\/span>/i, function() {
  11097. return serializer.serialize(fragment);
  11098. })
  11099. )
  11100. );
  11101. // Set the inner/outer HTML depending on if we are in the root or not
  11102. if (parentNode == rootNode)
  11103. dom.setHTML(rootNode, value);
  11104. else
  11105. dom.setOuterHTML(parentNode, value);
  11106. }
  11107. marker = dom.get('mce_marker');
  11108. // Scroll range into view scrollIntoView on element can't be used since it will scroll the main view port as well
  11109. nodeRect = dom.getRect(marker);
  11110. viewPortRect = dom.getViewPort(editor.getWin());
  11111. // Check if node is out side the viewport if it is then scroll to it
  11112. if ((nodeRect.y + nodeRect.h > viewPortRect.y + viewPortRect.h || nodeRect.y < viewPortRect.y) ||
  11113. (nodeRect.x > viewPortRect.x + viewPortRect.w || nodeRect.x < viewPortRect.x)) {
  11114. viewportBodyElement = tinymce.isIE ? editor.getDoc().documentElement : editor.getBody();
  11115. viewportBodyElement.scrollLeft = nodeRect.x;
  11116. viewportBodyElement.scrollTop = nodeRect.y - viewPortRect.h + 25;
  11117. }
  11118. // Move selection before marker and remove it
  11119. rng = dom.createRng();
  11120. // If previous sibling is a text node set the selection to the end of that node
  11121. node = marker.previousSibling;
  11122. if (node && node.nodeType == 3) {
  11123. rng.setStart(node, node.nodeValue.length);
  11124. } else {
  11125. // If the previous sibling isn't a text node or doesn't exist set the selection before the marker node
  11126. rng.setStartBefore(marker);
  11127. rng.setEndBefore(marker);
  11128. }
  11129. // Remove the marker node and set the new range
  11130. dom.remove(marker);
  11131. selection.setRng(rng);
  11132. // Dispatch after event and add any visual elements needed
  11133. selection.onSetContent.dispatch(selection, args);
  11134. editor.addVisual();
  11135. },
  11136. mceInsertRawHTML : function(command, ui, value) {
  11137. selection.setContent('tiny_mce_marker');
  11138. editor.setContent(editor.getContent().replace(/tiny_mce_marker/g, function() { return value }));
  11139. },
  11140. mceToggleFormat : function(command, ui, value) {
  11141. toggleFormat(value);
  11142. },
  11143. mceSetContent : function(command, ui, value) {
  11144. editor.setContent(value);
  11145. },
  11146. 'Indent,Outdent' : function(command) {
  11147. var intentValue, indentUnit, value;
  11148. // Setup indent level
  11149. intentValue = settings.indentation;
  11150. indentUnit = /[a-z%]+$/i.exec(intentValue);
  11151. intentValue = parseInt(intentValue);
  11152. if (!queryCommandState('InsertUnorderedList') && !queryCommandState('InsertOrderedList')) {
  11153. // If forced_root_blocks is set to false we don't have a block to indent so lets create a div
  11154. if (!settings.forced_root_block && !dom.getParent(selection.getNode(), dom.isBlock)) {
  11155. formatter.apply('div');
  11156. }
  11157. each(selection.getSelectedBlocks(), function(element) {
  11158. if (command == 'outdent') {
  11159. value = Math.max(0, parseInt(element.style.paddingLeft || 0) - intentValue);
  11160. dom.setStyle(element, 'paddingLeft', value ? value + indentUnit : '');
  11161. } else
  11162. dom.setStyle(element, 'paddingLeft', (parseInt(element.style.paddingLeft || 0) + intentValue) + indentUnit);
  11163. });
  11164. } else
  11165. execNativeCommand(command);
  11166. },
  11167. mceRepaint : function() {
  11168. var bookmark;
  11169. if (tinymce.isGecko) {
  11170. try {
  11171. storeSelection(TRUE);
  11172. if (selection.getSel())
  11173. selection.getSel().selectAllChildren(editor.getBody());
  11174. selection.collapse(TRUE);
  11175. restoreSelection();
  11176. } catch (ex) {
  11177. // Ignore
  11178. }
  11179. }
  11180. },
  11181. mceToggleFormat : function(command, ui, value) {
  11182. formatter.toggle(value);
  11183. },
  11184. InsertHorizontalRule : function() {
  11185. editor.execCommand('mceInsertContent', false, '<hr />');
  11186. },
  11187. mceToggleVisualAid : function() {
  11188. editor.hasVisual = !editor.hasVisual;
  11189. editor.addVisual();
  11190. },
  11191. mceReplaceContent : function(command, ui, value) {
  11192. editor.execCommand('mceInsertContent', false, value.replace(/\{\$selection\}/g, selection.getContent({format : 'text'})));
  11193. },
  11194. mceInsertLink : function(command, ui, value) {
  11195. var anchor;
  11196. if (typeof(value) == 'string')
  11197. value = {href : value};
  11198. anchor = dom.getParent(selection.getNode(), 'a');
  11199. // Spaces are never valid in URLs and it's a very common mistake for people to make so we fix it here.
  11200. value.href = value.href.replace(' ', '%20');
  11201. // Remove existing links if there could be child links or that the href isn't specified
  11202. if (!anchor || !value.href) {
  11203. formatter.remove('link');
  11204. }
  11205. // Apply new link to selection
  11206. if (value.href) {
  11207. formatter.apply('link', value, anchor);
  11208. }
  11209. },
  11210. selectAll : function() {
  11211. var root = dom.getRoot(), rng = dom.createRng();
  11212. // Old IE does a better job with selectall than new versions
  11213. if (selection.getRng().setStart) {
  11214. rng.setStart(root, 0);
  11215. rng.setEnd(root, root.childNodes.length);
  11216. selection.setRng(rng);
  11217. } else {
  11218. execNativeCommand('SelectAll');
  11219. }
  11220. }
  11221. });
  11222. // Add queryCommandState overrides
  11223. addCommands({
  11224. // Override justify commands
  11225. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  11226. var name = 'align' + command.substring(7);
  11227. var nodes = selection.isCollapsed() ? [dom.getParent(selection.getNode(), dom.isBlock)] : selection.getSelectedBlocks();
  11228. var matches = tinymce.map(nodes, function(node) {
  11229. return !!formatter.matchNode(node, name);
  11230. });
  11231. return tinymce.inArray(matches, TRUE) !== -1;
  11232. },
  11233. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
  11234. return isFormatMatch(command);
  11235. },
  11236. mceBlockQuote : function() {
  11237. return isFormatMatch('blockquote');
  11238. },
  11239. Outdent : function() {
  11240. var node;
  11241. if (settings.inline_styles) {
  11242. if ((node = dom.getParent(selection.getStart(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  11243. return TRUE;
  11244. if ((node = dom.getParent(selection.getEnd(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  11245. return TRUE;
  11246. }
  11247. return queryCommandState('InsertUnorderedList') || queryCommandState('InsertOrderedList') || (!settings.inline_styles && !!dom.getParent(selection.getNode(), 'BLOCKQUOTE'));
  11248. },
  11249. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  11250. var list = dom.getParent(selection.getNode(), 'ul,ol');
  11251. return list &&
  11252. (command === 'insertunorderedlist' && list.tagName === 'UL'
  11253. || command === 'insertorderedlist' && list.tagName === 'OL');
  11254. }
  11255. }, 'state');
  11256. // Add queryCommandValue overrides
  11257. addCommands({
  11258. 'FontSize,FontName' : function(command) {
  11259. var value = 0, parent;
  11260. if (parent = dom.getParent(selection.getNode(), 'span')) {
  11261. if (command == 'fontsize')
  11262. value = parent.style.fontSize;
  11263. else
  11264. value = parent.style.fontFamily.replace(/, /g, ',').replace(/[\'\"]/g, '').toLowerCase();
  11265. }
  11266. return value;
  11267. }
  11268. }, 'value');
  11269. // Add undo manager logic
  11270. addCommands({
  11271. Undo : function() {
  11272. editor.undoManager.undo();
  11273. },
  11274. Redo : function() {
  11275. editor.undoManager.redo();
  11276. }
  11277. });
  11278. };
  11279. })(tinymce);
  11280. (function(tinymce) {
  11281. var Dispatcher = tinymce.util.Dispatcher;
  11282. tinymce.UndoManager = function(editor) {
  11283. var self, index = 0, data = [], beforeBookmark, onAdd, onUndo, onRedo;
  11284. function getContent() {
  11285. // Remove whitespace before/after and remove pure bogus nodes
  11286. return tinymce.trim(editor.getContent({format : 'raw', no_events : 1}).replace(/<span[^>]+data-mce-bogus[^>]+>[\u200B\uFEFF]+<\/span>/g, ''));
  11287. };
  11288. function addNonTypingUndoLevel() {
  11289. self.typing = false;
  11290. self.add();
  11291. };
  11292. // Create event instances
  11293. onBeforeAdd = new Dispatcher(self);
  11294. onAdd = new Dispatcher(self);
  11295. onUndo = new Dispatcher(self);
  11296. onRedo = new Dispatcher(self);
  11297. // Pass though onAdd event from UndoManager to Editor as onChange
  11298. onAdd.add(function(undoman, level) {
  11299. if (undoman.hasUndo())
  11300. return editor.onChange.dispatch(editor, level, undoman);
  11301. });
  11302. // Pass though onUndo event from UndoManager to Editor
  11303. onUndo.add(function(undoman, level) {
  11304. return editor.onUndo.dispatch(editor, level, undoman);
  11305. });
  11306. // Pass though onRedo event from UndoManager to Editor
  11307. onRedo.add(function(undoman, level) {
  11308. return editor.onRedo.dispatch(editor, level, undoman);
  11309. });
  11310. // Add initial undo level when the editor is initialized
  11311. editor.onInit.add(function() {
  11312. self.add();
  11313. });
  11314. // Get position before an execCommand is processed
  11315. editor.onBeforeExecCommand.add(function(ed, cmd, ui, val, args) {
  11316. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!args || !args.skip_undo)) {
  11317. self.beforeChange();
  11318. }
  11319. });
  11320. // Add undo level after an execCommand call was made
  11321. editor.onExecCommand.add(function(ed, cmd, ui, val, args) {
  11322. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!args || !args.skip_undo)) {
  11323. self.add();
  11324. }
  11325. });
  11326. // Add undo level on save contents, drag end and blur/focusout
  11327. editor.onSaveContent.add(addNonTypingUndoLevel);
  11328. editor.dom.bind(editor.dom.getRoot(), 'dragend', addNonTypingUndoLevel);
  11329. editor.dom.bind(editor.getDoc(), tinymce.isGecko ? 'blur' : 'focusout', function(e) {
  11330. if (!editor.removed && self.typing) {
  11331. addNonTypingUndoLevel();
  11332. }
  11333. });
  11334. editor.onKeyUp.add(function(editor, e) {
  11335. var keyCode = e.keyCode;
  11336. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 45 || keyCode == 13 || e.ctrlKey) {
  11337. addNonTypingUndoLevel();
  11338. }
  11339. });
  11340. editor.onKeyDown.add(function(editor, e) {
  11341. var keyCode = e.keyCode;
  11342. // Is caracter positon keys left,right,up,down,home,end,pgdown,pgup,enter
  11343. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 45) {
  11344. if (self.typing) {
  11345. addNonTypingUndoLevel();
  11346. }
  11347. return;
  11348. }
  11349. // If key isn't shift,ctrl,alt,capslock,metakey
  11350. if ((keyCode < 16 || keyCode > 20) && keyCode != 224 && keyCode != 91 && !self.typing) {
  11351. self.beforeChange();
  11352. self.typing = true;
  11353. self.add();
  11354. }
  11355. });
  11356. editor.onMouseDown.add(function(editor, e) {
  11357. if (self.typing) {
  11358. addNonTypingUndoLevel();
  11359. }
  11360. });
  11361. // Add keyboard shortcuts for undo/redo keys
  11362. editor.addShortcut('ctrl+z', 'undo_desc', 'Undo');
  11363. editor.addShortcut('ctrl+y', 'redo_desc', 'Redo');
  11364. self = {
  11365. // Explose for debugging reasons
  11366. data : data,
  11367. typing : false,
  11368. onBeforeAdd: onBeforeAdd,
  11369. onAdd : onAdd,
  11370. onUndo : onUndo,
  11371. onRedo : onRedo,
  11372. beforeChange : function() {
  11373. beforeBookmark = editor.selection.getBookmark(2, true);
  11374. },
  11375. add : function(level) {
  11376. var i, settings = editor.settings, lastLevel;
  11377. level = level || {};
  11378. level.content = getContent();
  11379. self.onBeforeAdd.dispatch(self, level);
  11380. // Add undo level if needed
  11381. lastLevel = data[index];
  11382. if (lastLevel && lastLevel.content == level.content)
  11383. return null;
  11384. // Set before bookmark on previous level
  11385. if (data[index])
  11386. data[index].beforeBookmark = beforeBookmark;
  11387. // Time to compress
  11388. if (settings.custom_undo_redo_levels) {
  11389. if (data.length > settings.custom_undo_redo_levels) {
  11390. for (i = 0; i < data.length - 1; i++)
  11391. data[i] = data[i + 1];
  11392. data.length--;
  11393. index = data.length;
  11394. }
  11395. }
  11396. // Get a non intrusive normalized bookmark
  11397. level.bookmark = editor.selection.getBookmark(2, true);
  11398. // Crop array if needed
  11399. if (index < data.length - 1)
  11400. data.length = index + 1;
  11401. data.push(level);
  11402. index = data.length - 1;
  11403. self.onAdd.dispatch(self, level);
  11404. editor.isNotDirty = 0;
  11405. return level;
  11406. },
  11407. undo : function() {
  11408. var level, i;
  11409. if (self.typing) {
  11410. self.add();
  11411. self.typing = false;
  11412. }
  11413. if (index > 0) {
  11414. level = data[--index];
  11415. editor.setContent(level.content, {format : 'raw'});
  11416. editor.selection.moveToBookmark(level.beforeBookmark);
  11417. self.onUndo.dispatch(self, level);
  11418. }
  11419. return level;
  11420. },
  11421. redo : function() {
  11422. var level;
  11423. if (index < data.length - 1) {
  11424. level = data[++index];
  11425. editor.setContent(level.content, {format : 'raw'});
  11426. editor.selection.moveToBookmark(level.bookmark);
  11427. self.onRedo.dispatch(self, level);
  11428. }
  11429. return level;
  11430. },
  11431. clear : function() {
  11432. data = [];
  11433. index = 0;
  11434. self.typing = false;
  11435. },
  11436. hasUndo : function() {
  11437. return index > 0 || this.typing;
  11438. },
  11439. hasRedo : function() {
  11440. return index < data.length - 1 && !this.typing;
  11441. }
  11442. };
  11443. return self;
  11444. };
  11445. })(tinymce);
  11446. tinymce.ForceBlocks = function(editor) {
  11447. var settings = editor.settings, dom = editor.dom, selection = editor.selection, blockElements = editor.schema.getBlockElements();
  11448. function addRootBlocks() {
  11449. var node = selection.getStart(), rootNode = editor.getBody(), rng, startContainer, startOffset, endContainer, endOffset, rootBlockNode, tempNode, offset = -0xFFFFFF, wrapped, isInEditorDocument;
  11450. if (!node || node.nodeType !== 1 || !settings.forced_root_block)
  11451. return;
  11452. // Check if node is wrapped in block
  11453. while (node && node != rootNode) {
  11454. if (blockElements[node.nodeName])
  11455. return;
  11456. node = node.parentNode;
  11457. }
  11458. // Get current selection
  11459. rng = selection.getRng();
  11460. if (rng.setStart) {
  11461. startContainer = rng.startContainer;
  11462. startOffset = rng.startOffset;
  11463. endContainer = rng.endContainer;
  11464. endOffset = rng.endOffset;
  11465. } else {
  11466. // Force control range into text range
  11467. if (rng.item) {
  11468. node = rng.item(0);
  11469. rng = editor.getDoc().body.createTextRange();
  11470. rng.moveToElementText(node);
  11471. }
  11472. isInEditorDocument = rng.parentElement().ownerDocument === editor.getDoc();
  11473. tmpRng = rng.duplicate();
  11474. tmpRng.collapse(true);
  11475. startOffset = tmpRng.move('character', offset) * -1;
  11476. if (!tmpRng.collapsed) {
  11477. tmpRng = rng.duplicate();
  11478. tmpRng.collapse(false);
  11479. endOffset = (tmpRng.move('character', offset) * -1) - startOffset;
  11480. }
  11481. }
  11482. // Wrap non block elements and text nodes
  11483. node = rootNode.firstChild;
  11484. while (node) {
  11485. if (node.nodeType === 3 || (node.nodeType == 1 && !blockElements[node.nodeName])) {
  11486. // Remove empty text nodes
  11487. if (node.nodeType === 3 && node.nodeValue.length == 0) {
  11488. tempNode = node;
  11489. node = node.nextSibling;
  11490. dom.remove(tempNode);
  11491. continue;
  11492. }
  11493. if (!rootBlockNode) {
  11494. rootBlockNode = dom.create(settings.forced_root_block);
  11495. node.parentNode.insertBefore(rootBlockNode, node);
  11496. wrapped = true;
  11497. }
  11498. tempNode = node;
  11499. node = node.nextSibling;
  11500. rootBlockNode.appendChild(tempNode);
  11501. } else {
  11502. rootBlockNode = null;
  11503. node = node.nextSibling;
  11504. }
  11505. }
  11506. if (wrapped) {
  11507. if (rng.setStart) {
  11508. rng.setStart(startContainer, startOffset);
  11509. rng.setEnd(endContainer, endOffset);
  11510. selection.setRng(rng);
  11511. } else {
  11512. // Only select if the previous selection was inside the document to prevent auto focus in quirks mode
  11513. if (isInEditorDocument) {
  11514. try {
  11515. rng = editor.getDoc().body.createTextRange();
  11516. rng.moveToElementText(rootNode);
  11517. rng.collapse(true);
  11518. rng.moveStart('character', startOffset);
  11519. if (endOffset > 0)
  11520. rng.moveEnd('character', endOffset);
  11521. rng.select();
  11522. } catch (ex) {
  11523. // Ignore
  11524. }
  11525. }
  11526. }
  11527. editor.nodeChanged();
  11528. }
  11529. };
  11530. // Force root blocks
  11531. if (settings.forced_root_block) {
  11532. editor.onKeyUp.add(addRootBlocks);
  11533. editor.onNodeChange.add(addRootBlocks);
  11534. }
  11535. };
  11536. (function(tinymce) {
  11537. // Shorten names
  11538. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, extend = tinymce.extend;
  11539. tinymce.create('tinymce.ControlManager', {
  11540. ControlManager : function(ed, s) {
  11541. var t = this, i;
  11542. s = s || {};
  11543. t.editor = ed;
  11544. t.controls = {};
  11545. t.onAdd = new tinymce.util.Dispatcher(t);
  11546. t.onPostRender = new tinymce.util.Dispatcher(t);
  11547. t.prefix = s.prefix || ed.id + '_';
  11548. t._cls = {};
  11549. t.onPostRender.add(function() {
  11550. each(t.controls, function(c) {
  11551. c.postRender();
  11552. });
  11553. });
  11554. },
  11555. get : function(id) {
  11556. return this.controls[this.prefix + id] || this.controls[id];
  11557. },
  11558. setActive : function(id, s) {
  11559. var c = null;
  11560. if (c = this.get(id))
  11561. c.setActive(s);
  11562. return c;
  11563. },
  11564. setDisabled : function(id, s) {
  11565. var c = null;
  11566. if (c = this.get(id))
  11567. c.setDisabled(s);
  11568. return c;
  11569. },
  11570. add : function(c) {
  11571. var t = this;
  11572. if (c) {
  11573. t.controls[c.id] = c;
  11574. t.onAdd.dispatch(c, t);
  11575. }
  11576. return c;
  11577. },
  11578. createControl : function(name) {
  11579. var ctrl, i, l, self = this, editor = self.editor, factories, ctrlName;
  11580. // Build control factory cache
  11581. if (!self.controlFactories) {
  11582. self.controlFactories = [];
  11583. each(editor.plugins, function(plugin) {
  11584. if (plugin.createControl) {
  11585. self.controlFactories.push(plugin);
  11586. }
  11587. });
  11588. }
  11589. // Create controls by asking cached factories
  11590. factories = self.controlFactories;
  11591. for (i = 0, l = factories.length; i < l; i++) {
  11592. ctrl = factories[i].createControl(name, self);
  11593. if (ctrl) {
  11594. return self.add(ctrl);
  11595. }
  11596. }
  11597. // Create sepearator
  11598. if (name === "|" || name === "separator") {
  11599. return self.createSeparator();
  11600. }
  11601. // Create control from button collection
  11602. if (editor.buttons && (ctrl = editor.buttons[name])) {
  11603. return self.createButton(name, ctrl);
  11604. }
  11605. return self.add(ctrl);
  11606. },
  11607. createDropMenu : function(id, s, cc) {
  11608. var t = this, ed = t.editor, c, bm, v, cls;
  11609. s = extend({
  11610. 'class' : 'mceDropDown',
  11611. constrain : ed.settings.constrain_menus
  11612. }, s);
  11613. s['class'] = s['class'] + ' ' + ed.getParam('skin') + 'Skin';
  11614. if (v = ed.getParam('skin_variant'))
  11615. s['class'] += ' ' + ed.getParam('skin') + 'Skin' + v.substring(0, 1).toUpperCase() + v.substring(1);
  11616. s['class'] += ed.settings.directionality == "rtl" ? ' mceRtl' : '';
  11617. id = t.prefix + id;
  11618. cls = cc || t._cls.dropmenu || tinymce.ui.DropMenu;
  11619. c = t.controls[id] = new cls(id, s);
  11620. c.onAddItem.add(function(c, o) {
  11621. var s = o.settings;
  11622. s.title = ed.getLang(s.title, s.title);
  11623. if (!s.onclick) {
  11624. s.onclick = function(v) {
  11625. if (s.cmd)
  11626. ed.execCommand(s.cmd, s.ui || false, s.value);
  11627. };
  11628. }
  11629. });
  11630. ed.onRemove.add(function() {
  11631. c.destroy();
  11632. });
  11633. // Fix for bug #1897785, #1898007
  11634. if (tinymce.isIE) {
  11635. c.onShowMenu.add(function() {
  11636. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  11637. ed.focus();
  11638. bm = ed.selection.getBookmark(1);
  11639. });
  11640. c.onHideMenu.add(function() {
  11641. if (bm) {
  11642. ed.selection.moveToBookmark(bm);
  11643. bm = 0;
  11644. }
  11645. });
  11646. }
  11647. return t.add(c);
  11648. },
  11649. createListBox : function(id, s, cc) {
  11650. var t = this, ed = t.editor, cmd, c, cls;
  11651. if (t.get(id))
  11652. return null;
  11653. s.title = ed.translate(s.title);
  11654. s.scope = s.scope || ed;
  11655. if (!s.onselect) {
  11656. s.onselect = function(v) {
  11657. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11658. };
  11659. }
  11660. s = extend({
  11661. title : s.title,
  11662. 'class' : 'mce_' + id,
  11663. scope : s.scope,
  11664. control_manager : t
  11665. }, s);
  11666. id = t.prefix + id;
  11667. function useNativeListForAccessibility(ed) {
  11668. return ed.settings.use_accessible_selects && !tinymce.isGecko
  11669. }
  11670. if (ed.settings.use_native_selects || useNativeListForAccessibility(ed))
  11671. c = new tinymce.ui.NativeListBox(id, s);
  11672. else {
  11673. cls = cc || t._cls.listbox || tinymce.ui.ListBox;
  11674. c = new cls(id, s, ed);
  11675. }
  11676. t.controls[id] = c;
  11677. // Fix focus problem in Safari
  11678. if (tinymce.isWebKit) {
  11679. c.onPostRender.add(function(c, n) {
  11680. // Store bookmark on mousedown
  11681. Event.add(n, 'mousedown', function() {
  11682. ed.bookmark = ed.selection.getBookmark(1);
  11683. });
  11684. // Restore on focus, since it might be lost
  11685. Event.add(n, 'focus', function() {
  11686. ed.selection.moveToBookmark(ed.bookmark);
  11687. ed.bookmark = null;
  11688. });
  11689. });
  11690. }
  11691. if (c.hideMenu)
  11692. ed.onMouseDown.add(c.hideMenu, c);
  11693. return t.add(c);
  11694. },
  11695. createButton : function(id, s, cc) {
  11696. var t = this, ed = t.editor, o, c, cls;
  11697. if (t.get(id))
  11698. return null;
  11699. s.title = ed.translate(s.title);
  11700. s.label = ed.translate(s.label);
  11701. s.scope = s.scope || ed;
  11702. if (!s.onclick && !s.menu_button) {
  11703. s.onclick = function() {
  11704. ed.execCommand(s.cmd, s.ui || false, s.value);
  11705. };
  11706. }
  11707. s = extend({
  11708. title : s.title,
  11709. 'class' : 'mce_' + id,
  11710. unavailable_prefix : ed.getLang('unavailable', ''),
  11711. scope : s.scope,
  11712. control_manager : t
  11713. }, s);
  11714. id = t.prefix + id;
  11715. if (s.menu_button) {
  11716. cls = cc || t._cls.menubutton || tinymce.ui.MenuButton;
  11717. c = new cls(id, s, ed);
  11718. ed.onMouseDown.add(c.hideMenu, c);
  11719. } else {
  11720. cls = t._cls.button || tinymce.ui.Button;
  11721. c = new cls(id, s, ed);
  11722. }
  11723. return t.add(c);
  11724. },
  11725. createMenuButton : function(id, s, cc) {
  11726. s = s || {};
  11727. s.menu_button = 1;
  11728. return this.createButton(id, s, cc);
  11729. },
  11730. createSplitButton : function(id, s, cc) {
  11731. var t = this, ed = t.editor, cmd, c, cls;
  11732. if (t.get(id))
  11733. return null;
  11734. s.title = ed.translate(s.title);
  11735. s.scope = s.scope || ed;
  11736. if (!s.onclick) {
  11737. s.onclick = function(v) {
  11738. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11739. };
  11740. }
  11741. if (!s.onselect) {
  11742. s.onselect = function(v) {
  11743. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11744. };
  11745. }
  11746. s = extend({
  11747. title : s.title,
  11748. 'class' : 'mce_' + id,
  11749. scope : s.scope,
  11750. control_manager : t
  11751. }, s);
  11752. id = t.prefix + id;
  11753. cls = cc || t._cls.splitbutton || tinymce.ui.SplitButton;
  11754. c = t.add(new cls(id, s, ed));
  11755. ed.onMouseDown.add(c.hideMenu, c);
  11756. return c;
  11757. },
  11758. createColorSplitButton : function(id, s, cc) {
  11759. var t = this, ed = t.editor, cmd, c, cls, bm;
  11760. if (t.get(id))
  11761. return null;
  11762. s.title = ed.translate(s.title);
  11763. s.scope = s.scope || ed;
  11764. if (!s.onclick) {
  11765. s.onclick = function(v) {
  11766. if (tinymce.isIE)
  11767. bm = ed.selection.getBookmark(1);
  11768. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11769. };
  11770. }
  11771. if (!s.onselect) {
  11772. s.onselect = function(v) {
  11773. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11774. };
  11775. }
  11776. s = extend({
  11777. title : s.title,
  11778. 'class' : 'mce_' + id,
  11779. 'menu_class' : ed.getParam('skin') + 'Skin',
  11780. scope : s.scope,
  11781. more_colors_title : ed.getLang('more_colors')
  11782. }, s);
  11783. id = t.prefix + id;
  11784. cls = cc || t._cls.colorsplitbutton || tinymce.ui.ColorSplitButton;
  11785. c = new cls(id, s, ed);
  11786. ed.onMouseDown.add(c.hideMenu, c);
  11787. // Remove the menu element when the editor is removed
  11788. ed.onRemove.add(function() {
  11789. c.destroy();
  11790. });
  11791. // Fix for bug #1897785, #1898007
  11792. if (tinymce.isIE) {
  11793. c.onShowMenu.add(function() {
  11794. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  11795. ed.focus();
  11796. bm = ed.selection.getBookmark(1);
  11797. });
  11798. c.onHideMenu.add(function() {
  11799. if (bm) {
  11800. ed.selection.moveToBookmark(bm);
  11801. bm = 0;
  11802. }
  11803. });
  11804. }
  11805. return t.add(c);
  11806. },
  11807. createToolbar : function(id, s, cc) {
  11808. var c, t = this, cls;
  11809. id = t.prefix + id;
  11810. cls = cc || t._cls.toolbar || tinymce.ui.Toolbar;
  11811. c = new cls(id, s, t.editor);
  11812. if (t.get(id))
  11813. return null;
  11814. return t.add(c);
  11815. },
  11816. createToolbarGroup : function(id, s, cc) {
  11817. var c, t = this, cls;
  11818. id = t.prefix + id;
  11819. cls = cc || this._cls.toolbarGroup || tinymce.ui.ToolbarGroup;
  11820. c = new cls(id, s, t.editor);
  11821. if (t.get(id))
  11822. return null;
  11823. return t.add(c);
  11824. },
  11825. createSeparator : function(cc) {
  11826. var cls = cc || this._cls.separator || tinymce.ui.Separator;
  11827. return new cls();
  11828. },
  11829. setControlType : function(n, c) {
  11830. return this._cls[n.toLowerCase()] = c;
  11831. },
  11832. destroy : function() {
  11833. each(this.controls, function(c) {
  11834. c.destroy();
  11835. });
  11836. this.controls = null;
  11837. }
  11838. });
  11839. })(tinymce);
  11840. (function(tinymce) {
  11841. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isIE = tinymce.isIE, isOpera = tinymce.isOpera;
  11842. tinymce.create('tinymce.WindowManager', {
  11843. WindowManager : function(ed) {
  11844. var t = this;
  11845. t.editor = ed;
  11846. t.onOpen = new Dispatcher(t);
  11847. t.onClose = new Dispatcher(t);
  11848. t.params = {};
  11849. t.features = {};
  11850. },
  11851. open : function(s, p) {
  11852. var t = this, f = '', x, y, mo = t.editor.settings.dialog_type == 'modal', w, sw, sh, vp = tinymce.DOM.getViewPort(), u;
  11853. // Default some options
  11854. s = s || {};
  11855. p = p || {};
  11856. sw = isOpera ? vp.w : screen.width; // Opera uses windows inside the Opera window
  11857. sh = isOpera ? vp.h : screen.height;
  11858. s.name = s.name || 'mc_' + new Date().getTime();
  11859. s.width = parseInt(s.width || 320);
  11860. s.height = parseInt(s.height || 240);
  11861. s.resizable = true;
  11862. s.left = s.left || parseInt(sw / 2.0) - (s.width / 2.0);
  11863. s.top = s.top || parseInt(sh / 2.0) - (s.height / 2.0);
  11864. p.inline = false;
  11865. p.mce_width = s.width;
  11866. p.mce_height = s.height;
  11867. p.mce_auto_focus = s.auto_focus;
  11868. if (mo) {
  11869. if (isIE) {
  11870. s.center = true;
  11871. s.help = false;
  11872. s.dialogWidth = s.width + 'px';
  11873. s.dialogHeight = s.height + 'px';
  11874. s.scroll = s.scrollbars || false;
  11875. }
  11876. }
  11877. // Build features string
  11878. each(s, function(v, k) {
  11879. if (tinymce.is(v, 'boolean'))
  11880. v = v ? 'yes' : 'no';
  11881. if (!/^(name|url)$/.test(k)) {
  11882. if (isIE && mo)
  11883. f += (f ? ';' : '') + k + ':' + v;
  11884. else
  11885. f += (f ? ',' : '') + k + '=' + v;
  11886. }
  11887. });
  11888. t.features = s;
  11889. t.params = p;
  11890. t.onOpen.dispatch(t, s, p);
  11891. u = s.url || s.file;
  11892. u = tinymce._addVer(u);
  11893. try {
  11894. if (isIE && mo) {
  11895. w = 1;
  11896. window.showModalDialog(u, window, f);
  11897. } else
  11898. w = window.open(u, s.name, f);
  11899. } catch (ex) {
  11900. // Ignore
  11901. }
  11902. if (!w)
  11903. alert(t.editor.getLang('popup_blocked'));
  11904. },
  11905. close : function(w) {
  11906. w.close();
  11907. this.onClose.dispatch(this);
  11908. },
  11909. createInstance : function(cl, a, b, c, d, e) {
  11910. var f = tinymce.resolve(cl);
  11911. return new f(a, b, c, d, e);
  11912. },
  11913. confirm : function(t, cb, s, w) {
  11914. w = w || window;
  11915. cb.call(s || this, w.confirm(this._decode(this.editor.getLang(t, t))));
  11916. },
  11917. alert : function(tx, cb, s, w) {
  11918. var t = this;
  11919. w = w || window;
  11920. w.alert(t._decode(t.editor.getLang(tx, tx)));
  11921. if (cb)
  11922. cb.call(s || t);
  11923. },
  11924. resizeBy : function(dw, dh, win) {
  11925. win.resizeBy(dw, dh);
  11926. },
  11927. // Internal functions
  11928. _decode : function(s) {
  11929. return tinymce.DOM.decode(s).replace(/\\n/g, '\n');
  11930. }
  11931. });
  11932. }(tinymce));
  11933. (function(tinymce) {
  11934. tinymce.Formatter = function(ed) {
  11935. var formats = {},
  11936. each = tinymce.each,
  11937. dom = ed.dom,
  11938. selection = ed.selection,
  11939. TreeWalker = tinymce.dom.TreeWalker,
  11940. rangeUtils = new tinymce.dom.RangeUtils(dom),
  11941. isValid = ed.schema.isValidChild,
  11942. isArray = tinymce.isArray,
  11943. isBlock = dom.isBlock,
  11944. forcedRootBlock = ed.settings.forced_root_block,
  11945. nodeIndex = dom.nodeIndex,
  11946. INVISIBLE_CHAR = '\uFEFF',
  11947. MCE_ATTR_RE = /^(src|href|style)$/,
  11948. FALSE = false,
  11949. TRUE = true,
  11950. formatChangeData,
  11951. undef,
  11952. getContentEditable = dom.getContentEditable;
  11953. function isTextBlock(name) {
  11954. return !!ed.schema.getTextBlocks()[name.toLowerCase()];
  11955. }
  11956. function getParents(node, selector) {
  11957. return dom.getParents(node, selector, dom.getRoot());
  11958. };
  11959. function isCaretNode(node) {
  11960. return node.nodeType === 1 && node.id === '_mce_caret';
  11961. };
  11962. function defaultFormats() {
  11963. register({
  11964. alignleft : [
  11965. {selector : 'figure,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}, defaultBlock: 'div'},
  11966. {selector : 'img,table', collapsed : false, styles : {'float' : 'left'}}
  11967. ],
  11968. aligncenter : [
  11969. {selector : 'figure,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}, defaultBlock: 'div'},
  11970. {selector : 'img', collapsed : false, styles : {display : 'block', marginLeft : 'auto', marginRight : 'auto'}},
  11971. {selector : 'table', collapsed : false, styles : {marginLeft : 'auto', marginRight : 'auto'}}
  11972. ],
  11973. alignright : [
  11974. {selector : 'figure,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}, defaultBlock: 'div'},
  11975. {selector : 'img,table', collapsed : false, styles : {'float' : 'right'}}
  11976. ],
  11977. alignfull : [
  11978. {selector : 'figure,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'justify'}, defaultBlock: 'div'}
  11979. ],
  11980. bold : [
  11981. {inline : 'strong', remove : 'all'},
  11982. {inline : 'span', styles : {fontWeight : 'bold'}},
  11983. {inline : 'b', remove : 'all'}
  11984. ],
  11985. italic : [
  11986. {inline : 'em', remove : 'all'},
  11987. {inline : 'span', styles : {fontStyle : 'italic'}},
  11988. {inline : 'i', remove : 'all'}
  11989. ],
  11990. underline : [
  11991. {inline : 'span', styles : {textDecoration : 'underline'}, exact : true},
  11992. {inline : 'u', remove : 'all'}
  11993. ],
  11994. strikethrough : [
  11995. {inline : 'span', styles : {textDecoration : 'line-through'}, exact : true},
  11996. {inline : 'strike', remove : 'all'}
  11997. ],
  11998. forecolor : {inline : 'span', styles : {color : '%value'}, wrap_links : false},
  11999. hilitecolor : {inline : 'span', styles : {backgroundColor : '%value'}, wrap_links : false},
  12000. fontname : {inline : 'span', styles : {fontFamily : '%value'}},
  12001. fontsize : {inline : 'span', styles : {fontSize : '%value'}},
  12002. fontsize_class : {inline : 'span', attributes : {'class' : '%value'}},
  12003. blockquote : {block : 'blockquote', wrapper : 1, remove : 'all'},
  12004. subscript : {inline : 'sub'},
  12005. superscript : {inline : 'sup'},
  12006. link : {inline : 'a', selector : 'a', remove : 'all', split : true, deep : true,
  12007. onmatch : function(node) {
  12008. return true;
  12009. },
  12010. onformat : function(elm, fmt, vars) {
  12011. each(vars, function(value, key) {
  12012. dom.setAttrib(elm, key, value);
  12013. });
  12014. }
  12015. },
  12016. removeformat : [
  12017. {selector : 'b,strong,em,i,font,u,strike', remove : 'all', split : true, expand : false, block_expand : true, deep : true},
  12018. {selector : 'span', attributes : ['style', 'class'], remove : 'empty', split : true, expand : false, deep : true},
  12019. {selector : '*', attributes : ['style', 'class'], split : false, expand : false, deep : true}
  12020. ]
  12021. });
  12022. // Register default block formats
  12023. each('p h1 h2 h3 h4 h5 h6 div address pre div code dt dd samp'.split(/\s/), function(name) {
  12024. register(name, {block : name, remove : 'all'});
  12025. });
  12026. // Register user defined formats
  12027. register(ed.settings.formats);
  12028. };
  12029. function addKeyboardShortcuts() {
  12030. // Add some inline shortcuts
  12031. ed.addShortcut('ctrl+b', 'bold_desc', 'Bold');
  12032. ed.addShortcut('ctrl+i', 'italic_desc', 'Italic');
  12033. ed.addShortcut('ctrl+u', 'underline_desc', 'Underline');
  12034. // BlockFormat shortcuts keys
  12035. for (var i = 1; i <= 6; i++) {
  12036. ed.addShortcut('ctrl+' + i, '', ['FormatBlock', false, 'h' + i]);
  12037. }
  12038. ed.addShortcut('ctrl+7', '', ['FormatBlock', false, 'p']);
  12039. ed.addShortcut('ctrl+8', '', ['FormatBlock', false, 'div']);
  12040. ed.addShortcut('ctrl+9', '', ['FormatBlock', false, 'address']);
  12041. };
  12042. // Public functions
  12043. function get(name) {
  12044. return name ? formats[name] : formats;
  12045. };
  12046. function register(name, format) {
  12047. if (name) {
  12048. if (typeof(name) !== 'string') {
  12049. each(name, function(format, name) {
  12050. register(name, format);
  12051. });
  12052. } else {
  12053. // Force format into array and add it to internal collection
  12054. format = format.length ? format : [format];
  12055. each(format, function(format) {
  12056. // Set deep to false by default on selector formats this to avoid removing
  12057. // alignment on images inside paragraphs when alignment is changed on paragraphs
  12058. if (format.deep === undef)
  12059. format.deep = !format.selector;
  12060. // Default to true
  12061. if (format.split === undef)
  12062. format.split = !format.selector || format.inline;
  12063. // Default to true
  12064. if (format.remove === undef && format.selector && !format.inline)
  12065. format.remove = 'none';
  12066. // Mark format as a mixed format inline + block level
  12067. if (format.selector && format.inline) {
  12068. format.mixed = true;
  12069. format.block_expand = true;
  12070. }
  12071. // Split classes if needed
  12072. if (typeof(format.classes) === 'string')
  12073. format.classes = format.classes.split(/\s+/);
  12074. });
  12075. formats[name] = format;
  12076. }
  12077. }
  12078. };
  12079. var getTextDecoration = function(node) {
  12080. var decoration;
  12081. ed.dom.getParent(node, function(n) {
  12082. decoration = ed.dom.getStyle(n, 'text-decoration');
  12083. return decoration && decoration !== 'none';
  12084. });
  12085. return decoration;
  12086. };
  12087. var processUnderlineAndColor = function(node) {
  12088. var textDecoration;
  12089. if (node.nodeType === 1 && node.parentNode && node.parentNode.nodeType === 1) {
  12090. textDecoration = getTextDecoration(node.parentNode);
  12091. if (ed.dom.getStyle(node, 'color') && textDecoration) {
  12092. ed.dom.setStyle(node, 'text-decoration', textDecoration);
  12093. } else if (ed.dom.getStyle(node, 'textdecoration') === textDecoration) {
  12094. ed.dom.setStyle(node, 'text-decoration', null);
  12095. }
  12096. }
  12097. };
  12098. function apply(name, vars, node) {
  12099. var formatList = get(name), format = formatList[0], bookmark, rng, i, isCollapsed = selection.isCollapsed();
  12100. function setElementFormat(elm, fmt) {
  12101. fmt = fmt || format;
  12102. if (elm) {
  12103. if (fmt.onformat) {
  12104. fmt.onformat(elm, fmt, vars, node);
  12105. }
  12106. each(fmt.styles, function(value, name) {
  12107. dom.setStyle(elm, name, replaceVars(value, vars));
  12108. });
  12109. each(fmt.attributes, function(value, name) {
  12110. dom.setAttrib(elm, name, replaceVars(value, vars));
  12111. });
  12112. each(fmt.classes, function(value) {
  12113. value = replaceVars(value, vars);
  12114. if (!dom.hasClass(elm, value))
  12115. dom.addClass(elm, value);
  12116. });
  12117. }
  12118. };
  12119. function adjustSelectionToVisibleSelection() {
  12120. function findSelectionEnd(start, end) {
  12121. var walker = new TreeWalker(end);
  12122. for (node = walker.current(); node; node = walker.prev()) {
  12123. if (node.childNodes.length > 1 || node == start || node.tagName == 'BR') {
  12124. return node;
  12125. }
  12126. }
  12127. };
  12128. // Adjust selection so that a end container with a end offset of zero is not included in the selection
  12129. // as this isn't visible to the user.
  12130. var rng = ed.selection.getRng();
  12131. var start = rng.startContainer;
  12132. var end = rng.endContainer;
  12133. if (start != end && rng.endOffset === 0) {
  12134. var newEnd = findSelectionEnd(start, end);
  12135. var endOffset = newEnd.nodeType == 3 ? newEnd.length : newEnd.childNodes.length;
  12136. rng.setEnd(newEnd, endOffset);
  12137. }
  12138. return rng;
  12139. }
  12140. function applyStyleToList(node, bookmark, wrapElm, newWrappers, process){
  12141. var nodes = [], listIndex = -1, list, startIndex = -1, endIndex = -1, currentWrapElm;
  12142. // find the index of the first child list.
  12143. each(node.childNodes, function(n, index) {
  12144. if (n.nodeName === "UL" || n.nodeName === "OL") {
  12145. listIndex = index;
  12146. list = n;
  12147. return false;
  12148. }
  12149. });
  12150. // get the index of the bookmarks
  12151. each(node.childNodes, function(n, index) {
  12152. if (n.nodeName === "SPAN" && dom.getAttrib(n, "data-mce-type") == "bookmark") {
  12153. if (n.id == bookmark.id + "_start") {
  12154. startIndex = index;
  12155. } else if (n.id == bookmark.id + "_end") {
  12156. endIndex = index;
  12157. }
  12158. }
  12159. });
  12160. // if the selection spans across an embedded list, or there isn't an embedded list - handle processing normally
  12161. if (listIndex <= 0 || (startIndex < listIndex && endIndex > listIndex)) {
  12162. each(tinymce.grep(node.childNodes), process);
  12163. return 0;
  12164. } else {
  12165. currentWrapElm = dom.clone(wrapElm, FALSE);
  12166. // create a list of the nodes on the same side of the list as the selection
  12167. each(tinymce.grep(node.childNodes), function(n, index) {
  12168. if ((startIndex < listIndex && index < listIndex) || (startIndex > listIndex && index > listIndex)) {
  12169. nodes.push(n);
  12170. n.parentNode.removeChild(n);
  12171. }
  12172. });
  12173. // insert the wrapping element either before or after the list.
  12174. if (startIndex < listIndex) {
  12175. node.insertBefore(currentWrapElm, list);
  12176. } else if (startIndex > listIndex) {
  12177. node.insertBefore(currentWrapElm, list.nextSibling);
  12178. }
  12179. // add the new nodes to the list.
  12180. newWrappers.push(currentWrapElm);
  12181. each(nodes, function(node) {
  12182. currentWrapElm.appendChild(node);
  12183. });
  12184. return currentWrapElm;
  12185. }
  12186. };
  12187. function applyRngStyle(rng, bookmark, node_specific) {
  12188. var newWrappers = [], wrapName, wrapElm, contentEditable = true;
  12189. // Setup wrapper element
  12190. wrapName = format.inline || format.block;
  12191. wrapElm = dom.create(wrapName);
  12192. setElementFormat(wrapElm);
  12193. rangeUtils.walk(rng, function(nodes) {
  12194. var currentWrapElm;
  12195. function process(node) {
  12196. var nodeName, parentName, found, hasContentEditableState, lastContentEditable;
  12197. lastContentEditable = contentEditable;
  12198. nodeName = node.nodeName.toLowerCase();
  12199. parentName = node.parentNode.nodeName.toLowerCase();
  12200. // Node has a contentEditable value
  12201. if (node.nodeType === 1 && getContentEditable(node)) {
  12202. lastContentEditable = contentEditable;
  12203. contentEditable = getContentEditable(node) === "true";
  12204. hasContentEditableState = true; // We don't want to wrap the container only it's children
  12205. }
  12206. // Stop wrapping on br elements
  12207. if (isEq(nodeName, 'br')) {
  12208. currentWrapElm = 0;
  12209. // Remove any br elements when we wrap things
  12210. if (format.block)
  12211. dom.remove(node);
  12212. return;
  12213. }
  12214. // If node is wrapper type
  12215. if (format.wrapper && matchNode(node, name, vars)) {
  12216. currentWrapElm = 0;
  12217. return;
  12218. }
  12219. // Can we rename the block
  12220. if (contentEditable && !hasContentEditableState && format.block && !format.wrapper && isTextBlock(nodeName)) {
  12221. node = dom.rename(node, wrapName);
  12222. setElementFormat(node);
  12223. newWrappers.push(node);
  12224. currentWrapElm = 0;
  12225. return;
  12226. }
  12227. // Handle selector patterns
  12228. if (format.selector) {
  12229. // Look for matching formats
  12230. each(formatList, function(format) {
  12231. // Check collapsed state if it exists
  12232. if ('collapsed' in format && format.collapsed !== isCollapsed) {
  12233. return;
  12234. }
  12235. if (dom.is(node, format.selector) && !isCaretNode(node)) {
  12236. setElementFormat(node, format);
  12237. found = true;
  12238. }
  12239. });
  12240. // Continue processing if a selector match wasn't found and a inline element is defined
  12241. if (!format.inline || found) {
  12242. currentWrapElm = 0;
  12243. return;
  12244. }
  12245. }
  12246. // Is it valid to wrap this item
  12247. if (contentEditable && !hasContentEditableState && isValid(wrapName, nodeName) && isValid(parentName, wrapName) &&
  12248. !(!node_specific && node.nodeType === 3 && node.nodeValue.length === 1 && node.nodeValue.charCodeAt(0) === 65279) && !isCaretNode(node)) {
  12249. // Start wrapping
  12250. if (!currentWrapElm) {
  12251. // Wrap the node
  12252. currentWrapElm = dom.clone(wrapElm, FALSE);
  12253. node.parentNode.insertBefore(currentWrapElm, node);
  12254. newWrappers.push(currentWrapElm);
  12255. }
  12256. currentWrapElm.appendChild(node);
  12257. } else if (nodeName == 'li' && bookmark) {
  12258. // Start wrapping - if we are in a list node and have a bookmark, then we will always begin by wrapping in a new element.
  12259. currentWrapElm = applyStyleToList(node, bookmark, wrapElm, newWrappers, process);
  12260. } else {
  12261. // Start a new wrapper for possible children
  12262. currentWrapElm = 0;
  12263. each(tinymce.grep(node.childNodes), process);
  12264. if (hasContentEditableState) {
  12265. contentEditable = lastContentEditable; // Restore last contentEditable state from stack
  12266. }
  12267. // End the last wrapper
  12268. currentWrapElm = 0;
  12269. }
  12270. };
  12271. // Process siblings from range
  12272. each(nodes, process);
  12273. });
  12274. // Wrap links inside as well, for example color inside a link when the wrapper is around the link
  12275. if (format.wrap_links === false) {
  12276. each(newWrappers, function(node) {
  12277. function process(node) {
  12278. var i, currentWrapElm, children;
  12279. if (node.nodeName === 'A') {
  12280. currentWrapElm = dom.clone(wrapElm, FALSE);
  12281. newWrappers.push(currentWrapElm);
  12282. children = tinymce.grep(node.childNodes);
  12283. for (i = 0; i < children.length; i++)
  12284. currentWrapElm.appendChild(children[i]);
  12285. node.appendChild(currentWrapElm);
  12286. }
  12287. each(tinymce.grep(node.childNodes), process);
  12288. };
  12289. process(node);
  12290. });
  12291. }
  12292. // Cleanup
  12293. each(newWrappers, function(node) {
  12294. var childCount;
  12295. function getChildCount(node) {
  12296. var count = 0;
  12297. each(node.childNodes, function(node) {
  12298. if (!isWhiteSpaceNode(node) && !isBookmarkNode(node))
  12299. count++;
  12300. });
  12301. return count;
  12302. };
  12303. function mergeStyles(node) {
  12304. var child, clone;
  12305. each(node.childNodes, function(node) {
  12306. if (node.nodeType == 1 && !isBookmarkNode(node) && !isCaretNode(node)) {
  12307. child = node;
  12308. return FALSE; // break loop
  12309. }
  12310. });
  12311. // If child was found and of the same type as the current node
  12312. if (child && matchName(child, format)) {
  12313. clone = dom.clone(child, FALSE);
  12314. setElementFormat(clone);
  12315. dom.replace(clone, node, TRUE);
  12316. dom.remove(child, 1);
  12317. }
  12318. return clone || node;
  12319. };
  12320. childCount = getChildCount(node);
  12321. // Remove empty nodes but only if there is multiple wrappers and they are not block
  12322. // elements so never remove single <h1></h1> since that would remove the currrent empty block element where the caret is at
  12323. if ((newWrappers.length > 1 || !isBlock(node)) && childCount === 0) {
  12324. dom.remove(node, 1);
  12325. return;
  12326. }
  12327. if (format.inline || format.wrapper) {
  12328. // Merges the current node with it's children of similar type to reduce the number of elements
  12329. if (!format.exact && childCount === 1)
  12330. node = mergeStyles(node);
  12331. // Remove/merge children
  12332. each(formatList, function(format) {
  12333. // Merge all children of similar type will move styles from child to parent
  12334. // this: <span style="color:red"><b><span style="color:red; font-size:10px">text</span></b></span>
  12335. // will become: <span style="color:red"><b><span style="font-size:10px">text</span></b></span>
  12336. each(dom.select(format.inline, node), function(child) {
  12337. var parent;
  12338. // When wrap_links is set to false we don't want
  12339. // to remove the format on children within links
  12340. if (format.wrap_links === false) {
  12341. parent = child.parentNode;
  12342. do {
  12343. if (parent.nodeName === 'A')
  12344. return;
  12345. } while (parent = parent.parentNode);
  12346. }
  12347. removeFormat(format, vars, child, format.exact ? child : null);
  12348. });
  12349. });
  12350. // Remove child if direct parent is of same type
  12351. if (matchNode(node.parentNode, name, vars)) {
  12352. dom.remove(node, 1);
  12353. node = 0;
  12354. return TRUE;
  12355. }
  12356. // Look for parent with similar style format
  12357. if (format.merge_with_parents) {
  12358. dom.getParent(node.parentNode, function(parent) {
  12359. if (matchNode(parent, name, vars)) {
  12360. dom.remove(node, 1);
  12361. node = 0;
  12362. return TRUE;
  12363. }
  12364. });
  12365. }
  12366. // Merge next and previous siblings if they are similar <b>text</b><b>text</b> becomes <b>texttext</b>
  12367. if (node && format.merge_siblings !== false) {
  12368. node = mergeSiblings(getNonWhiteSpaceSibling(node), node);
  12369. node = mergeSiblings(node, getNonWhiteSpaceSibling(node, TRUE));
  12370. }
  12371. }
  12372. });
  12373. };
  12374. if (format) {
  12375. if (node) {
  12376. if (node.nodeType) {
  12377. rng = dom.createRng();
  12378. rng.setStartBefore(node);
  12379. rng.setEndAfter(node);
  12380. applyRngStyle(expandRng(rng, formatList), null, true);
  12381. } else {
  12382. applyRngStyle(node, null, true);
  12383. }
  12384. } else {
  12385. if (!isCollapsed || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
  12386. // Obtain selection node before selection is unselected by applyRngStyle()
  12387. var curSelNode = ed.selection.getNode();
  12388. // 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
  12389. // It's kind of a hack but people should be using the default block type P since all desktop editors work that way
  12390. if (!forcedRootBlock && formatList[0].defaultBlock && !dom.getParent(curSelNode, dom.isBlock)) {
  12391. apply(formatList[0].defaultBlock);
  12392. }
  12393. // Apply formatting to selection
  12394. ed.selection.setRng(adjustSelectionToVisibleSelection());
  12395. bookmark = selection.getBookmark();
  12396. applyRngStyle(expandRng(selection.getRng(TRUE), formatList), bookmark);
  12397. // Colored nodes should be underlined so that the color of the underline matches the text color.
  12398. if (format.styles && (format.styles.color || format.styles.textDecoration)) {
  12399. tinymce.walk(curSelNode, processUnderlineAndColor, 'childNodes');
  12400. processUnderlineAndColor(curSelNode);
  12401. }
  12402. selection.moveToBookmark(bookmark);
  12403. moveStart(selection.getRng(TRUE));
  12404. ed.nodeChanged();
  12405. } else
  12406. performCaretAction('apply', name, vars);
  12407. }
  12408. }
  12409. };
  12410. function remove(name, vars, node) {
  12411. var formatList = get(name), format = formatList[0], bookmark, i, rng, contentEditable = true;
  12412. // Merges the styles for each node
  12413. function process(node) {
  12414. var children, i, l, localContentEditable, lastContentEditable, hasContentEditableState;
  12415. // Node has a contentEditable value
  12416. if (node.nodeType === 1 && getContentEditable(node)) {
  12417. lastContentEditable = contentEditable;
  12418. contentEditable = getContentEditable(node) === "true";
  12419. hasContentEditableState = true; // We don't want to wrap the container only it's children
  12420. }
  12421. // Grab the children first since the nodelist might be changed
  12422. children = tinymce.grep(node.childNodes);
  12423. // Process current node
  12424. if (contentEditable && !hasContentEditableState) {
  12425. for (i = 0, l = formatList.length; i < l; i++) {
  12426. if (removeFormat(formatList[i], vars, node, node))
  12427. break;
  12428. }
  12429. }
  12430. // Process the children
  12431. if (format.deep) {
  12432. if (children.length) {
  12433. for (i = 0, l = children.length; i < l; i++)
  12434. process(children[i]);
  12435. if (hasContentEditableState) {
  12436. contentEditable = lastContentEditable; // Restore last contentEditable state from stack
  12437. }
  12438. }
  12439. }
  12440. };
  12441. function findFormatRoot(container) {
  12442. var formatRoot;
  12443. // Find format root
  12444. each(getParents(container.parentNode).reverse(), function(parent) {
  12445. var format;
  12446. // Find format root element
  12447. if (!formatRoot && parent.id != '_start' && parent.id != '_end') {
  12448. // Is the node matching the format we are looking for
  12449. format = matchNode(parent, name, vars);
  12450. if (format && format.split !== false)
  12451. formatRoot = parent;
  12452. }
  12453. });
  12454. return formatRoot;
  12455. };
  12456. function wrapAndSplit(format_root, container, target, split) {
  12457. var parent, clone, lastClone, firstClone, i, formatRootParent;
  12458. // Format root found then clone formats and split it
  12459. if (format_root) {
  12460. formatRootParent = format_root.parentNode;
  12461. for (parent = container.parentNode; parent && parent != formatRootParent; parent = parent.parentNode) {
  12462. clone = dom.clone(parent, FALSE);
  12463. for (i = 0; i < formatList.length; i++) {
  12464. if (removeFormat(formatList[i], vars, clone, clone)) {
  12465. clone = 0;
  12466. break;
  12467. }
  12468. }
  12469. // Build wrapper node
  12470. if (clone) {
  12471. if (lastClone)
  12472. clone.appendChild(lastClone);
  12473. if (!firstClone)
  12474. firstClone = clone;
  12475. lastClone = clone;
  12476. }
  12477. }
  12478. // Never split block elements if the format is mixed
  12479. if (split && (!format.mixed || !isBlock(format_root)))
  12480. container = dom.split(format_root, container);
  12481. // Wrap container in cloned formats
  12482. if (lastClone) {
  12483. target.parentNode.insertBefore(lastClone, target);
  12484. firstClone.appendChild(target);
  12485. }
  12486. }
  12487. return container;
  12488. };
  12489. function splitToFormatRoot(container) {
  12490. return wrapAndSplit(findFormatRoot(container), container, container, true);
  12491. };
  12492. function unwrap(start) {
  12493. var node = dom.get(start ? '_start' : '_end'),
  12494. out = node[start ? 'firstChild' : 'lastChild'];
  12495. // If the end is placed within the start the result will be removed
  12496. // So this checks if the out node is a bookmark node if it is it
  12497. // checks for another more suitable node
  12498. if (isBookmarkNode(out))
  12499. out = out[start ? 'firstChild' : 'lastChild'];
  12500. dom.remove(node, true);
  12501. return out;
  12502. };
  12503. function removeRngStyle(rng) {
  12504. var startContainer, endContainer, node;
  12505. rng = expandRng(rng, formatList, TRUE);
  12506. if (format.split) {
  12507. startContainer = getContainer(rng, TRUE);
  12508. endContainer = getContainer(rng);
  12509. if (startContainer != endContainer) {
  12510. // 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
  12511. // This will happen if you tripple click a table cell and use remove formatting
  12512. if (/^(TR|TD)$/.test(startContainer.nodeName) && startContainer.firstChild) {
  12513. startContainer = (startContainer.nodeName == "TD" ? startContainer.firstChild : startContainer.firstChild.firstChild) || startContainer;
  12514. }
  12515. // Wrap start/end nodes in span element since these might be cloned/moved
  12516. startContainer = wrap(startContainer, 'span', {id : '_start', 'data-mce-type' : 'bookmark'});
  12517. endContainer = wrap(endContainer, 'span', {id : '_end', 'data-mce-type' : 'bookmark'});
  12518. // Split start/end
  12519. splitToFormatRoot(startContainer);
  12520. splitToFormatRoot(endContainer);
  12521. // Unwrap start/end to get real elements again
  12522. startContainer = unwrap(TRUE);
  12523. endContainer = unwrap();
  12524. } else
  12525. startContainer = endContainer = splitToFormatRoot(startContainer);
  12526. // Update range positions since they might have changed after the split operations
  12527. rng.startContainer = startContainer.parentNode;
  12528. rng.startOffset = nodeIndex(startContainer);
  12529. rng.endContainer = endContainer.parentNode;
  12530. rng.endOffset = nodeIndex(endContainer) + 1;
  12531. }
  12532. // Remove items between start/end
  12533. rangeUtils.walk(rng, function(nodes) {
  12534. each(nodes, function(node) {
  12535. process(node);
  12536. // Remove parent span if it only contains text-decoration: underline, yet a parent node is also underlined.
  12537. if (node.nodeType === 1 && ed.dom.getStyle(node, 'text-decoration') === 'underline' && node.parentNode && getTextDecoration(node.parentNode) === 'underline') {
  12538. removeFormat({'deep': false, 'exact': true, 'inline': 'span', 'styles': {'textDecoration' : 'underline'}}, null, node);
  12539. }
  12540. });
  12541. });
  12542. };
  12543. // Handle node
  12544. if (node) {
  12545. if (node.nodeType) {
  12546. rng = dom.createRng();
  12547. rng.setStartBefore(node);
  12548. rng.setEndAfter(node);
  12549. removeRngStyle(rng);
  12550. } else {
  12551. removeRngStyle(node);
  12552. }
  12553. return;
  12554. }
  12555. if (!selection.isCollapsed() || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
  12556. bookmark = selection.getBookmark();
  12557. removeRngStyle(selection.getRng(TRUE));
  12558. selection.moveToBookmark(bookmark);
  12559. // 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
  12560. if (format.inline && match(name, vars, selection.getStart())) {
  12561. moveStart(selection.getRng(true));
  12562. }
  12563. ed.nodeChanged();
  12564. } else
  12565. performCaretAction('remove', name, vars);
  12566. };
  12567. function toggle(name, vars, node) {
  12568. var fmt = get(name);
  12569. if (match(name, vars, node) && (!('toggle' in fmt[0]) || fmt[0].toggle))
  12570. remove(name, vars, node);
  12571. else
  12572. apply(name, vars, node);
  12573. };
  12574. function matchNode(node, name, vars, similar) {
  12575. var formatList = get(name), format, i, classes;
  12576. function matchItems(node, format, item_name) {
  12577. var key, value, items = format[item_name], i;
  12578. // Custom match
  12579. if (format.onmatch) {
  12580. return format.onmatch(node, format, item_name);
  12581. }
  12582. // Check all items
  12583. if (items) {
  12584. // Non indexed object
  12585. if (items.length === undef) {
  12586. for (key in items) {
  12587. if (items.hasOwnProperty(key)) {
  12588. if (item_name === 'attributes')
  12589. value = dom.getAttrib(node, key);
  12590. else
  12591. value = getStyle(node, key);
  12592. if (similar && !value && !format.exact)
  12593. return;
  12594. if ((!similar || format.exact) && !isEq(value, replaceVars(items[key], vars)))
  12595. return;
  12596. }
  12597. }
  12598. } else {
  12599. // Only one match needed for indexed arrays
  12600. for (i = 0; i < items.length; i++) {
  12601. if (item_name === 'attributes' ? dom.getAttrib(node, items[i]) : getStyle(node, items[i]))
  12602. return format;
  12603. }
  12604. }
  12605. }
  12606. return format;
  12607. };
  12608. if (formatList && node) {
  12609. // Check each format in list
  12610. for (i = 0; i < formatList.length; i++) {
  12611. format = formatList[i];
  12612. // Name name, attributes, styles and classes
  12613. if (matchName(node, format) && matchItems(node, format, 'attributes') && matchItems(node, format, 'styles')) {
  12614. // Match classes
  12615. if (classes = format.classes) {
  12616. for (i = 0; i < classes.length; i++) {
  12617. if (!dom.hasClass(node, classes[i]))
  12618. return;
  12619. }
  12620. }
  12621. return format;
  12622. }
  12623. }
  12624. }
  12625. };
  12626. function match(name, vars, node) {
  12627. var startNode;
  12628. function matchParents(node) {
  12629. // Find first node with similar format settings
  12630. node = dom.getParent(node, function(node) {
  12631. return !!matchNode(node, name, vars, true);
  12632. });
  12633. // Do an exact check on the similar format element
  12634. return matchNode(node, name, vars);
  12635. };
  12636. // Check specified node
  12637. if (node)
  12638. return matchParents(node);
  12639. // Check selected node
  12640. node = selection.getNode();
  12641. if (matchParents(node))
  12642. return TRUE;
  12643. // Check start node if it's different
  12644. startNode = selection.getStart();
  12645. if (startNode != node) {
  12646. if (matchParents(startNode))
  12647. return TRUE;
  12648. }
  12649. return FALSE;
  12650. };
  12651. function matchAll(names, vars) {
  12652. var startElement, matchedFormatNames = [], checkedMap = {}, i, ni, name;
  12653. // Check start of selection for formats
  12654. startElement = selection.getStart();
  12655. dom.getParent(startElement, function(node) {
  12656. var i, name;
  12657. for (i = 0; i < names.length; i++) {
  12658. name = names[i];
  12659. if (!checkedMap[name] && matchNode(node, name, vars)) {
  12660. checkedMap[name] = true;
  12661. matchedFormatNames.push(name);
  12662. }
  12663. }
  12664. }, dom.getRoot());
  12665. return matchedFormatNames;
  12666. };
  12667. function canApply(name) {
  12668. var formatList = get(name), startNode, parents, i, x, selector;
  12669. if (formatList) {
  12670. startNode = selection.getStart();
  12671. parents = getParents(startNode);
  12672. for (x = formatList.length - 1; x >= 0; x--) {
  12673. selector = formatList[x].selector;
  12674. // Format is not selector based, then always return TRUE
  12675. if (!selector)
  12676. return TRUE;
  12677. for (i = parents.length - 1; i >= 0; i--) {
  12678. if (dom.is(parents[i], selector))
  12679. return TRUE;
  12680. }
  12681. }
  12682. }
  12683. return FALSE;
  12684. };
  12685. function formatChanged(formats, callback, similar) {
  12686. var currentFormats;
  12687. // Setup format node change logic
  12688. if (!formatChangeData) {
  12689. formatChangeData = {};
  12690. currentFormats = {};
  12691. ed.onNodeChange.addToTop(function(ed, cm, node) {
  12692. var parents = getParents(node), matchedFormats = {};
  12693. // Check for new formats
  12694. each(formatChangeData, function(callbacks, format) {
  12695. each(parents, function(node) {
  12696. if (matchNode(node, format, {}, callbacks.similar)) {
  12697. if (!currentFormats[format]) {
  12698. // Execute callbacks
  12699. each(callbacks, function(callback) {
  12700. callback(true, {node: node, format: format, parents: parents});
  12701. });
  12702. currentFormats[format] = callbacks;
  12703. }
  12704. matchedFormats[format] = callbacks;
  12705. return false;
  12706. }
  12707. });
  12708. });
  12709. // Check if current formats still match
  12710. each(currentFormats, function(callbacks, format) {
  12711. if (!matchedFormats[format]) {
  12712. delete currentFormats[format];
  12713. each(callbacks, function(callback) {
  12714. callback(false, {node: node, format: format, parents: parents});
  12715. });
  12716. }
  12717. });
  12718. });
  12719. }
  12720. // Add format listeners
  12721. each(formats.split(','), function(format) {
  12722. if (!formatChangeData[format]) {
  12723. formatChangeData[format] = [];
  12724. formatChangeData[format].similar = similar;
  12725. }
  12726. formatChangeData[format].push(callback);
  12727. });
  12728. return this;
  12729. };
  12730. // Expose to public
  12731. tinymce.extend(this, {
  12732. get : get,
  12733. register : register,
  12734. apply : apply,
  12735. remove : remove,
  12736. toggle : toggle,
  12737. match : match,
  12738. matchAll : matchAll,
  12739. matchNode : matchNode,
  12740. canApply : canApply,
  12741. formatChanged: formatChanged
  12742. });
  12743. // Initialize
  12744. defaultFormats();
  12745. addKeyboardShortcuts();
  12746. // Private functions
  12747. function matchName(node, format) {
  12748. // Check for inline match
  12749. if (isEq(node, format.inline))
  12750. return TRUE;
  12751. // Check for block match
  12752. if (isEq(node, format.block))
  12753. return TRUE;
  12754. // Check for selector match
  12755. if (format.selector)
  12756. return dom.is(node, format.selector);
  12757. };
  12758. function isEq(str1, str2) {
  12759. str1 = str1 || '';
  12760. str2 = str2 || '';
  12761. str1 = '' + (str1.nodeName || str1);
  12762. str2 = '' + (str2.nodeName || str2);
  12763. return str1.toLowerCase() == str2.toLowerCase();
  12764. };
  12765. function getStyle(node, name) {
  12766. var styleVal = dom.getStyle(node, name);
  12767. // Force the format to hex
  12768. if (name == 'color' || name == 'backgroundColor')
  12769. styleVal = dom.toHex(styleVal);
  12770. // Opera will return bold as 700
  12771. if (name == 'fontWeight' && styleVal == 700)
  12772. styleVal = 'bold';
  12773. return '' + styleVal;
  12774. };
  12775. function replaceVars(value, vars) {
  12776. if (typeof(value) != "string")
  12777. value = value(vars);
  12778. else if (vars) {
  12779. value = value.replace(/%(\w+)/g, function(str, name) {
  12780. return vars[name] || str;
  12781. });
  12782. }
  12783. return value;
  12784. };
  12785. function isWhiteSpaceNode(node) {
  12786. return node && node.nodeType === 3 && /^([\t \r\n]+|)$/.test(node.nodeValue);
  12787. };
  12788. function wrap(node, name, attrs) {
  12789. var wrapper = dom.create(name, attrs);
  12790. node.parentNode.insertBefore(wrapper, node);
  12791. wrapper.appendChild(node);
  12792. return wrapper;
  12793. };
  12794. function expandRng(rng, format, remove) {
  12795. var sibling, lastIdx, leaf, endPoint,
  12796. startContainer = rng.startContainer,
  12797. startOffset = rng.startOffset,
  12798. endContainer = rng.endContainer,
  12799. endOffset = rng.endOffset;
  12800. // This function walks up the tree if there is no siblings before/after the node
  12801. function findParentContainer(start) {
  12802. var container, parent, child, sibling, siblingName, root;
  12803. container = parent = start ? startContainer : endContainer;
  12804. siblingName = start ? 'previousSibling' : 'nextSibling';
  12805. root = dom.getRoot();
  12806. function isBogusBr(node) {
  12807. return node.nodeName == "BR" && node.getAttribute('data-mce-bogus') && !node.nextSibling;
  12808. };
  12809. // If it's a text node and the offset is inside the text
  12810. if (container.nodeType == 3 && !isWhiteSpaceNode(container)) {
  12811. if (start ? startOffset > 0 : endOffset < container.nodeValue.length) {
  12812. return container;
  12813. }
  12814. }
  12815. for (;;) {
  12816. // Stop expanding on block elements
  12817. if (!format[0].block_expand && isBlock(parent))
  12818. return parent;
  12819. // Walk left/right
  12820. for (sibling = parent[siblingName]; sibling; sibling = sibling[siblingName]) {
  12821. if (!isBookmarkNode(sibling) && !isWhiteSpaceNode(sibling) && !isBogusBr(sibling)) {
  12822. return parent;
  12823. }
  12824. }
  12825. // Check if we can move up are we at root level or body level
  12826. if (parent.parentNode == root) {
  12827. container = parent;
  12828. break;
  12829. }
  12830. parent = parent.parentNode;
  12831. }
  12832. return container;
  12833. };
  12834. // This function walks down the tree to find the leaf at the selection.
  12835. // The offset is also returned as if node initially a leaf, the offset may be in the middle of the text node.
  12836. function findLeaf(node, offset) {
  12837. if (offset === undef)
  12838. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  12839. while (node && node.hasChildNodes()) {
  12840. node = node.childNodes[offset];
  12841. if (node)
  12842. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  12843. }
  12844. return { node: node, offset: offset };
  12845. }
  12846. // If index based start position then resolve it
  12847. if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) {
  12848. lastIdx = startContainer.childNodes.length - 1;
  12849. startContainer = startContainer.childNodes[startOffset > lastIdx ? lastIdx : startOffset];
  12850. if (startContainer.nodeType == 3)
  12851. startOffset = 0;
  12852. }
  12853. // If index based end position then resolve it
  12854. if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) {
  12855. lastIdx = endContainer.childNodes.length - 1;
  12856. endContainer = endContainer.childNodes[endOffset > lastIdx ? lastIdx : endOffset - 1];
  12857. if (endContainer.nodeType == 3)
  12858. endOffset = endContainer.nodeValue.length;
  12859. }
  12860. // Expands the node to the closes contentEditable false element if it exists
  12861. function findParentContentEditable(node) {
  12862. var parent = node;
  12863. while (parent) {
  12864. if (parent.nodeType === 1 && getContentEditable(parent)) {
  12865. return getContentEditable(parent) === "false" ? parent : node;
  12866. }
  12867. parent = parent.parentNode;
  12868. }
  12869. return node;
  12870. };
  12871. function findWordEndPoint(container, offset, start) {
  12872. var walker, node, pos, lastTextNode;
  12873. function findSpace(node, offset) {
  12874. var pos, pos2, str = node.nodeValue;
  12875. if (typeof(offset) == "undefined") {
  12876. offset = start ? str.length : 0;
  12877. }
  12878. if (start) {
  12879. pos = str.lastIndexOf(' ', offset);
  12880. pos2 = str.lastIndexOf('\u00a0', offset);
  12881. pos = pos > pos2 ? pos : pos2;
  12882. // Include the space on remove to avoid tag soup
  12883. if (pos !== -1 && !remove) {
  12884. pos++;
  12885. }
  12886. } else {
  12887. pos = str.indexOf(' ', offset);
  12888. pos2 = str.indexOf('\u00a0', offset);
  12889. pos = pos !== -1 && (pos2 === -1 || pos < pos2) ? pos : pos2;
  12890. }
  12891. return pos;
  12892. };
  12893. if (container.nodeType === 3) {
  12894. pos = findSpace(container, offset);
  12895. if (pos !== -1) {
  12896. return {container : container, offset : pos};
  12897. }
  12898. lastTextNode = container;
  12899. }
  12900. // Walk the nodes inside the block
  12901. walker = new TreeWalker(container, dom.getParent(container, isBlock) || ed.getBody());
  12902. while (node = walker[start ? 'prev' : 'next']()) {
  12903. if (node.nodeType === 3) {
  12904. lastTextNode = node;
  12905. pos = findSpace(node);
  12906. if (pos !== -1) {
  12907. return {container : node, offset : pos};
  12908. }
  12909. } else if (isBlock(node)) {
  12910. break;
  12911. }
  12912. }
  12913. if (lastTextNode) {
  12914. if (start) {
  12915. offset = 0;
  12916. } else {
  12917. offset = lastTextNode.length;
  12918. }
  12919. return {container: lastTextNode, offset: offset};
  12920. }
  12921. };
  12922. function findSelectorEndPoint(container, sibling_name) {
  12923. var parents, i, y, curFormat;
  12924. if (container.nodeType == 3 && container.nodeValue.length === 0 && container[sibling_name])
  12925. container = container[sibling_name];
  12926. parents = getParents(container);
  12927. for (i = 0; i < parents.length; i++) {
  12928. for (y = 0; y < format.length; y++) {
  12929. curFormat = format[y];
  12930. // If collapsed state is set then skip formats that doesn't match that
  12931. if ("collapsed" in curFormat && curFormat.collapsed !== rng.collapsed)
  12932. continue;
  12933. if (dom.is(parents[i], curFormat.selector))
  12934. return parents[i];
  12935. }
  12936. }
  12937. return container;
  12938. };
  12939. function findBlockEndPoint(container, sibling_name, sibling_name2) {
  12940. var node;
  12941. // Expand to block of similar type
  12942. if (!format[0].wrapper)
  12943. node = dom.getParent(container, format[0].block);
  12944. // Expand to first wrappable block element or any block element
  12945. if (!node)
  12946. node = dom.getParent(container.nodeType == 3 ? container.parentNode : container, isTextBlock);
  12947. // Exclude inner lists from wrapping
  12948. if (node && format[0].wrapper)
  12949. node = getParents(node, 'ul,ol').reverse()[0] || node;
  12950. // Didn't find a block element look for first/last wrappable element
  12951. if (!node) {
  12952. node = container;
  12953. while (node[sibling_name] && !isBlock(node[sibling_name])) {
  12954. node = node[sibling_name];
  12955. // Break on BR but include it will be removed later on
  12956. // we can't remove it now since we need to check if it can be wrapped
  12957. if (isEq(node, 'br'))
  12958. break;
  12959. }
  12960. }
  12961. return node || container;
  12962. };
  12963. // Expand to closest contentEditable element
  12964. startContainer = findParentContentEditable(startContainer);
  12965. endContainer = findParentContentEditable(endContainer);
  12966. // Exclude bookmark nodes if possible
  12967. if (isBookmarkNode(startContainer.parentNode) || isBookmarkNode(startContainer)) {
  12968. startContainer = isBookmarkNode(startContainer) ? startContainer : startContainer.parentNode;
  12969. startContainer = startContainer.nextSibling || startContainer;
  12970. if (startContainer.nodeType == 3)
  12971. startOffset = 0;
  12972. }
  12973. if (isBookmarkNode(endContainer.parentNode) || isBookmarkNode(endContainer)) {
  12974. endContainer = isBookmarkNode(endContainer) ? endContainer : endContainer.parentNode;
  12975. endContainer = endContainer.previousSibling || endContainer;
  12976. if (endContainer.nodeType == 3)
  12977. endOffset = endContainer.length;
  12978. }
  12979. if (format[0].inline) {
  12980. if (rng.collapsed) {
  12981. // Expand left to closest word boundery
  12982. endPoint = findWordEndPoint(startContainer, startOffset, true);
  12983. if (endPoint) {
  12984. startContainer = endPoint.container;
  12985. startOffset = endPoint.offset;
  12986. }
  12987. // Expand right to closest word boundery
  12988. endPoint = findWordEndPoint(endContainer, endOffset);
  12989. if (endPoint) {
  12990. endContainer = endPoint.container;
  12991. endOffset = endPoint.offset;
  12992. }
  12993. }
  12994. // Avoid applying formatting to a trailing space.
  12995. leaf = findLeaf(endContainer, endOffset);
  12996. if (leaf.node) {
  12997. while (leaf.node && leaf.offset === 0 && leaf.node.previousSibling)
  12998. leaf = findLeaf(leaf.node.previousSibling);
  12999. if (leaf.node && leaf.offset > 0 && leaf.node.nodeType === 3 &&
  13000. leaf.node.nodeValue.charAt(leaf.offset - 1) === ' ') {
  13001. if (leaf.offset > 1) {
  13002. endContainer = leaf.node;
  13003. endContainer.splitText(leaf.offset - 1);
  13004. }
  13005. }
  13006. }
  13007. }
  13008. // Move start/end point up the tree if the leaves are sharp and if we are in different containers
  13009. // Example * becomes !: !<p><b><i>*text</i><i>text*</i></b></p>!
  13010. // This will reduce the number of wrapper elements that needs to be created
  13011. // Move start point up the tree
  13012. if (format[0].inline || format[0].block_expand) {
  13013. if (!format[0].inline || (startContainer.nodeType != 3 || startOffset === 0)) {
  13014. startContainer = findParentContainer(true);
  13015. }
  13016. if (!format[0].inline || (endContainer.nodeType != 3 || endOffset === endContainer.nodeValue.length)) {
  13017. endContainer = findParentContainer();
  13018. }
  13019. }
  13020. // Expand start/end container to matching selector
  13021. if (format[0].selector && format[0].expand !== FALSE && !format[0].inline) {
  13022. // Find new startContainer/endContainer if there is better one
  13023. startContainer = findSelectorEndPoint(startContainer, 'previousSibling');
  13024. endContainer = findSelectorEndPoint(endContainer, 'nextSibling');
  13025. }
  13026. // Expand start/end container to matching block element or text node
  13027. if (format[0].block || format[0].selector) {
  13028. // Find new startContainer/endContainer if there is better one
  13029. startContainer = findBlockEndPoint(startContainer, 'previousSibling');
  13030. endContainer = findBlockEndPoint(endContainer, 'nextSibling');
  13031. // Non block element then try to expand up the leaf
  13032. if (format[0].block) {
  13033. if (!isBlock(startContainer))
  13034. startContainer = findParentContainer(true);
  13035. if (!isBlock(endContainer))
  13036. endContainer = findParentContainer();
  13037. }
  13038. }
  13039. // Setup index for startContainer
  13040. if (startContainer.nodeType == 1) {
  13041. startOffset = nodeIndex(startContainer);
  13042. startContainer = startContainer.parentNode;
  13043. }
  13044. // Setup index for endContainer
  13045. if (endContainer.nodeType == 1) {
  13046. endOffset = nodeIndex(endContainer) + 1;
  13047. endContainer = endContainer.parentNode;
  13048. }
  13049. // Return new range like object
  13050. return {
  13051. startContainer : startContainer,
  13052. startOffset : startOffset,
  13053. endContainer : endContainer,
  13054. endOffset : endOffset
  13055. };
  13056. }
  13057. function removeFormat(format, vars, node, compare_node) {
  13058. var i, attrs, stylesModified;
  13059. // Check if node matches format
  13060. if (!matchName(node, format))
  13061. return FALSE;
  13062. // Should we compare with format attribs and styles
  13063. if (format.remove != 'all') {
  13064. // Remove styles
  13065. each(format.styles, function(value, name) {
  13066. value = replaceVars(value, vars);
  13067. // Indexed array
  13068. if (typeof(name) === 'number') {
  13069. name = value;
  13070. compare_node = 0;
  13071. }
  13072. if (!compare_node || isEq(getStyle(compare_node, name), value))
  13073. dom.setStyle(node, name, '');
  13074. stylesModified = 1;
  13075. });
  13076. // Remove style attribute if it's empty
  13077. if (stylesModified && dom.getAttrib(node, 'style') == '') {
  13078. node.removeAttribute('style');
  13079. node.removeAttribute('data-mce-style');
  13080. }
  13081. // Remove attributes
  13082. each(format.attributes, function(value, name) {
  13083. var valueOut;
  13084. value = replaceVars(value, vars);
  13085. // Indexed array
  13086. if (typeof(name) === 'number') {
  13087. name = value;
  13088. compare_node = 0;
  13089. }
  13090. if (!compare_node || isEq(dom.getAttrib(compare_node, name), value)) {
  13091. // Keep internal classes
  13092. if (name == 'class') {
  13093. value = dom.getAttrib(node, name);
  13094. if (value) {
  13095. // Build new class value where everything is removed except the internal prefixed classes
  13096. valueOut = '';
  13097. each(value.split(/\s+/), function(cls) {
  13098. if (/mce\w+/.test(cls))
  13099. valueOut += (valueOut ? ' ' : '') + cls;
  13100. });
  13101. // We got some internal classes left
  13102. if (valueOut) {
  13103. dom.setAttrib(node, name, valueOut);
  13104. return;
  13105. }
  13106. }
  13107. }
  13108. // IE6 has a bug where the attribute doesn't get removed correctly
  13109. if (name == "class")
  13110. node.removeAttribute('className');
  13111. // Remove mce prefixed attributes
  13112. if (MCE_ATTR_RE.test(name))
  13113. node.removeAttribute('data-mce-' + name);
  13114. node.removeAttribute(name);
  13115. }
  13116. });
  13117. // Remove classes
  13118. each(format.classes, function(value) {
  13119. value = replaceVars(value, vars);
  13120. if (!compare_node || dom.hasClass(compare_node, value))
  13121. dom.removeClass(node, value);
  13122. });
  13123. // Check for non internal attributes
  13124. attrs = dom.getAttribs(node);
  13125. for (i = 0; i < attrs.length; i++) {
  13126. if (attrs[i].nodeName.indexOf('_') !== 0)
  13127. return FALSE;
  13128. }
  13129. }
  13130. // Remove the inline child if it's empty for example <b> or <span>
  13131. if (format.remove != 'none') {
  13132. removeNode(node, format);
  13133. return TRUE;
  13134. }
  13135. };
  13136. function removeNode(node, format) {
  13137. var parentNode = node.parentNode, rootBlockElm;
  13138. function find(node, next, inc) {
  13139. node = getNonWhiteSpaceSibling(node, next, inc);
  13140. return !node || (node.nodeName == 'BR' || isBlock(node));
  13141. };
  13142. if (format.block) {
  13143. if (!forcedRootBlock) {
  13144. // Append BR elements if needed before we remove the block
  13145. if (isBlock(node) && !isBlock(parentNode)) {
  13146. if (!find(node, FALSE) && !find(node.firstChild, TRUE, 1))
  13147. node.insertBefore(dom.create('br'), node.firstChild);
  13148. if (!find(node, TRUE) && !find(node.lastChild, FALSE, 1))
  13149. node.appendChild(dom.create('br'));
  13150. }
  13151. } else {
  13152. // Wrap the block in a forcedRootBlock if we are at the root of document
  13153. if (parentNode == dom.getRoot()) {
  13154. if (!format.list_block || !isEq(node, format.list_block)) {
  13155. each(tinymce.grep(node.childNodes), function(node) {
  13156. if (isValid(forcedRootBlock, node.nodeName.toLowerCase())) {
  13157. if (!rootBlockElm)
  13158. rootBlockElm = wrap(node, forcedRootBlock);
  13159. else
  13160. rootBlockElm.appendChild(node);
  13161. } else
  13162. rootBlockElm = 0;
  13163. });
  13164. }
  13165. }
  13166. }
  13167. }
  13168. // Never remove nodes that isn't the specified inline element if a selector is specified too
  13169. if (format.selector && format.inline && !isEq(format.inline, node))
  13170. return;
  13171. dom.remove(node, 1);
  13172. };
  13173. function getNonWhiteSpaceSibling(node, next, inc) {
  13174. if (node) {
  13175. next = next ? 'nextSibling' : 'previousSibling';
  13176. for (node = inc ? node : node[next]; node; node = node[next]) {
  13177. if (node.nodeType == 1 || !isWhiteSpaceNode(node))
  13178. return node;
  13179. }
  13180. }
  13181. };
  13182. function isBookmarkNode(node) {
  13183. return node && node.nodeType == 1 && node.getAttribute('data-mce-type') == 'bookmark';
  13184. };
  13185. function mergeSiblings(prev, next) {
  13186. var marker, sibling, tmpSibling;
  13187. function compareElements(node1, node2) {
  13188. // Not the same name
  13189. if (node1.nodeName != node2.nodeName)
  13190. return FALSE;
  13191. function getAttribs(node) {
  13192. var attribs = {};
  13193. each(dom.getAttribs(node), function(attr) {
  13194. var name = attr.nodeName.toLowerCase();
  13195. // Don't compare internal attributes or style
  13196. if (name.indexOf('_') !== 0 && name !== 'style')
  13197. attribs[name] = dom.getAttrib(node, name);
  13198. });
  13199. return attribs;
  13200. };
  13201. function compareObjects(obj1, obj2) {
  13202. var value, name;
  13203. for (name in obj1) {
  13204. // Obj1 has item obj2 doesn't have
  13205. if (obj1.hasOwnProperty(name)) {
  13206. value = obj2[name];
  13207. // Obj2 doesn't have obj1 item
  13208. if (value === undef)
  13209. return FALSE;
  13210. // Obj2 item has a different value
  13211. if (obj1[name] != value)
  13212. return FALSE;
  13213. // Delete similar value
  13214. delete obj2[name];
  13215. }
  13216. }
  13217. // Check if obj 2 has something obj 1 doesn't have
  13218. for (name in obj2) {
  13219. // Obj2 has item obj1 doesn't have
  13220. if (obj2.hasOwnProperty(name))
  13221. return FALSE;
  13222. }
  13223. return TRUE;
  13224. };
  13225. // Attribs are not the same
  13226. if (!compareObjects(getAttribs(node1), getAttribs(node2)))
  13227. return FALSE;
  13228. // Styles are not the same
  13229. if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style'))))
  13230. return FALSE;
  13231. return TRUE;
  13232. };
  13233. function findElementSibling(node, sibling_name) {
  13234. for (sibling = node; sibling; sibling = sibling[sibling_name]) {
  13235. if (sibling.nodeType == 3 && sibling.nodeValue.length !== 0)
  13236. return node;
  13237. if (sibling.nodeType == 1 && !isBookmarkNode(sibling))
  13238. return sibling;
  13239. }
  13240. return node;
  13241. };
  13242. // Check if next/prev exists and that they are elements
  13243. if (prev && next) {
  13244. // If previous sibling is empty then jump over it
  13245. prev = findElementSibling(prev, 'previousSibling');
  13246. next = findElementSibling(next, 'nextSibling');
  13247. // Compare next and previous nodes
  13248. if (compareElements(prev, next)) {
  13249. // Append nodes between
  13250. for (sibling = prev.nextSibling; sibling && sibling != next;) {
  13251. tmpSibling = sibling;
  13252. sibling = sibling.nextSibling;
  13253. prev.appendChild(tmpSibling);
  13254. }
  13255. // Remove next node
  13256. dom.remove(next);
  13257. // Move children into prev node
  13258. each(tinymce.grep(next.childNodes), function(node) {
  13259. prev.appendChild(node);
  13260. });
  13261. return prev;
  13262. }
  13263. }
  13264. return next;
  13265. };
  13266. function isTextBlock(name) {
  13267. return /^(h[1-6]|p|div|pre|address|dl|dt|dd)$/.test(name);
  13268. };
  13269. function getContainer(rng, start) {
  13270. var container, offset, lastIdx, walker;
  13271. container = rng[start ? 'startContainer' : 'endContainer'];
  13272. offset = rng[start ? 'startOffset' : 'endOffset'];
  13273. if (container.nodeType == 1) {
  13274. lastIdx = container.childNodes.length - 1;
  13275. if (!start && offset)
  13276. offset--;
  13277. container = container.childNodes[offset > lastIdx ? lastIdx : offset];
  13278. }
  13279. // If start text node is excluded then walk to the next node
  13280. if (container.nodeType === 3 && start && offset >= container.nodeValue.length) {
  13281. container = new TreeWalker(container, ed.getBody()).next() || container;
  13282. }
  13283. // If end text node is excluded then walk to the previous node
  13284. if (container.nodeType === 3 && !start && offset === 0) {
  13285. container = new TreeWalker(container, ed.getBody()).prev() || container;
  13286. }
  13287. return container;
  13288. };
  13289. function performCaretAction(type, name, vars) {
  13290. var caretContainerId = '_mce_caret', debug = ed.settings.caret_debug;
  13291. // Creates a caret container bogus element
  13292. function createCaretContainer(fill) {
  13293. var caretContainer = dom.create('span', {id: caretContainerId, 'data-mce-bogus': true, style: debug ? 'color:red' : ''});
  13294. if (fill) {
  13295. caretContainer.appendChild(ed.getDoc().createTextNode(INVISIBLE_CHAR));
  13296. }
  13297. return caretContainer;
  13298. };
  13299. function isCaretContainerEmpty(node, nodes) {
  13300. while (node) {
  13301. if ((node.nodeType === 3 && node.nodeValue !== INVISIBLE_CHAR) || node.childNodes.length > 1) {
  13302. return false;
  13303. }
  13304. // Collect nodes
  13305. if (nodes && node.nodeType === 1) {
  13306. nodes.push(node);
  13307. }
  13308. node = node.firstChild;
  13309. }
  13310. return true;
  13311. };
  13312. // Returns any parent caret container element
  13313. function getParentCaretContainer(node) {
  13314. while (node) {
  13315. if (node.id === caretContainerId) {
  13316. return node;
  13317. }
  13318. node = node.parentNode;
  13319. }
  13320. };
  13321. // Finds the first text node in the specified node
  13322. function findFirstTextNode(node) {
  13323. var walker;
  13324. if (node) {
  13325. walker = new TreeWalker(node, node);
  13326. for (node = walker.current(); node; node = walker.next()) {
  13327. if (node.nodeType === 3) {
  13328. return node;
  13329. }
  13330. }
  13331. }
  13332. };
  13333. // Removes the caret container for the specified node or all on the current document
  13334. function removeCaretContainer(node, move_caret) {
  13335. var child, rng;
  13336. if (!node) {
  13337. node = getParentCaretContainer(selection.getStart());
  13338. if (!node) {
  13339. while (node = dom.get(caretContainerId)) {
  13340. removeCaretContainer(node, false);
  13341. }
  13342. }
  13343. } else {
  13344. rng = selection.getRng(true);
  13345. if (isCaretContainerEmpty(node)) {
  13346. if (move_caret !== false) {
  13347. rng.setStartBefore(node);
  13348. rng.setEndBefore(node);
  13349. }
  13350. dom.remove(node);
  13351. } else {
  13352. child = findFirstTextNode(node);
  13353. if (child.nodeValue.charAt(0) === INVISIBLE_CHAR) {
  13354. child = child.deleteData(0, 1);
  13355. }
  13356. dom.remove(node, 1);
  13357. }
  13358. selection.setRng(rng);
  13359. }
  13360. };
  13361. // Applies formatting to the caret postion
  13362. function applyCaretFormat() {
  13363. var rng, caretContainer, textNode, offset, bookmark, container, text;
  13364. rng = selection.getRng(true);
  13365. offset = rng.startOffset;
  13366. container = rng.startContainer;
  13367. text = container.nodeValue;
  13368. caretContainer = getParentCaretContainer(selection.getStart());
  13369. if (caretContainer) {
  13370. textNode = findFirstTextNode(caretContainer);
  13371. }
  13372. // Expand to word is caret is in the middle of a text node and the char before/after is a alpha numeric character
  13373. if (text && offset > 0 && offset < text.length && /\w/.test(text.charAt(offset)) && /\w/.test(text.charAt(offset - 1))) {
  13374. // Get bookmark of caret position
  13375. bookmark = selection.getBookmark();
  13376. // Collapse bookmark range (WebKit)
  13377. rng.collapse(true);
  13378. // Expand the range to the closest word and split it at those points
  13379. rng = expandRng(rng, get(name));
  13380. rng = rangeUtils.split(rng);
  13381. // Apply the format to the range
  13382. apply(name, vars, rng);
  13383. // Move selection back to caret position
  13384. selection.moveToBookmark(bookmark);
  13385. } else {
  13386. if (!caretContainer || textNode.nodeValue !== INVISIBLE_CHAR) {
  13387. caretContainer = createCaretContainer(true);
  13388. textNode = caretContainer.firstChild;
  13389. rng.insertNode(caretContainer);
  13390. offset = 1;
  13391. apply(name, vars, caretContainer);
  13392. } else {
  13393. apply(name, vars, caretContainer);
  13394. }
  13395. // Move selection to text node
  13396. selection.setCursorLocation(textNode, offset);
  13397. }
  13398. };
  13399. function removeCaretFormat() {
  13400. var rng = selection.getRng(true), container, offset, bookmark,
  13401. hasContentAfter, node, formatNode, parents = [], i, caretContainer;
  13402. container = rng.startContainer;
  13403. offset = rng.startOffset;
  13404. node = container;
  13405. if (container.nodeType == 3) {
  13406. if (offset != container.nodeValue.length || container.nodeValue === INVISIBLE_CHAR) {
  13407. hasContentAfter = true;
  13408. }
  13409. node = node.parentNode;
  13410. }
  13411. while (node) {
  13412. if (matchNode(node, name, vars)) {
  13413. formatNode = node;
  13414. break;
  13415. }
  13416. if (node.nextSibling) {
  13417. hasContentAfter = true;
  13418. }
  13419. parents.push(node);
  13420. node = node.parentNode;
  13421. }
  13422. // Node doesn't have the specified format
  13423. if (!formatNode) {
  13424. return;
  13425. }
  13426. // Is there contents after the caret then remove the format on the element
  13427. if (hasContentAfter) {
  13428. // Get bookmark of caret position
  13429. bookmark = selection.getBookmark();
  13430. // Collapse bookmark range (WebKit)
  13431. rng.collapse(true);
  13432. // Expand the range to the closest word and split it at those points
  13433. rng = expandRng(rng, get(name), true);
  13434. rng = rangeUtils.split(rng);
  13435. // Remove the format from the range
  13436. remove(name, vars, rng);
  13437. // Move selection back to caret position
  13438. selection.moveToBookmark(bookmark);
  13439. } else {
  13440. caretContainer = createCaretContainer();
  13441. node = caretContainer;
  13442. for (i = parents.length - 1; i >= 0; i--) {
  13443. node.appendChild(dom.clone(parents[i], false));
  13444. node = node.firstChild;
  13445. }
  13446. // Insert invisible character into inner most format element
  13447. node.appendChild(dom.doc.createTextNode(INVISIBLE_CHAR));
  13448. node = node.firstChild;
  13449. // Insert caret container after the formated node
  13450. dom.insertAfter(caretContainer, formatNode);
  13451. // Move selection to text node
  13452. selection.setCursorLocation(node, 1);
  13453. }
  13454. };
  13455. // Checks if the parent caret container node isn't empty if that is the case it
  13456. // will remove the bogus state on all children that isn't empty
  13457. function unmarkBogusCaretParents() {
  13458. var i, caretContainer, node;
  13459. caretContainer = getParentCaretContainer(selection.getStart());
  13460. if (caretContainer && !dom.isEmpty(caretContainer)) {
  13461. tinymce.walk(caretContainer, function(node) {
  13462. if (node.nodeType == 1 && node.id !== caretContainerId && !dom.isEmpty(node)) {
  13463. dom.setAttrib(node, 'data-mce-bogus', null);
  13464. }
  13465. }, 'childNodes');
  13466. }
  13467. };
  13468. // Only bind the caret events once
  13469. if (!self._hasCaretEvents) {
  13470. // Mark current caret container elements as bogus when getting the contents so we don't end up with empty elements
  13471. ed.onBeforeGetContent.addToTop(function() {
  13472. var nodes = [], i;
  13473. if (isCaretContainerEmpty(getParentCaretContainer(selection.getStart()), nodes)) {
  13474. // Mark children
  13475. i = nodes.length;
  13476. while (i--) {
  13477. dom.setAttrib(nodes[i], 'data-mce-bogus', '1');
  13478. }
  13479. }
  13480. });
  13481. // Remove caret container on mouse up and on key up
  13482. tinymce.each('onMouseUp onKeyUp'.split(' '), function(name) {
  13483. ed[name].addToTop(function() {
  13484. removeCaretContainer();
  13485. unmarkBogusCaretParents();
  13486. });
  13487. });
  13488. // Remove caret container on keydown and it's a backspace, enter or left/right arrow keys
  13489. ed.onKeyDown.addToTop(function(ed, e) {
  13490. var keyCode = e.keyCode;
  13491. if (keyCode == 8 || keyCode == 37 || keyCode == 39) {
  13492. removeCaretContainer(getParentCaretContainer(selection.getStart()));
  13493. }
  13494. unmarkBogusCaretParents();
  13495. });
  13496. // Remove bogus state if they got filled by contents using editor.selection.setContent
  13497. selection.onSetContent.add(unmarkBogusCaretParents);
  13498. self._hasCaretEvents = true;
  13499. }
  13500. // Do apply or remove caret format
  13501. if (type == "apply") {
  13502. applyCaretFormat();
  13503. } else {
  13504. removeCaretFormat();
  13505. }
  13506. };
  13507. function moveStart(rng) {
  13508. var container = rng.startContainer,
  13509. offset = rng.startOffset, isAtEndOfText,
  13510. walker, node, nodes, tmpNode;
  13511. // Convert text node into index if possible
  13512. if (container.nodeType == 3 && offset >= container.nodeValue.length) {
  13513. // Get the parent container location and walk from there
  13514. offset = nodeIndex(container);
  13515. container = container.parentNode;
  13516. isAtEndOfText = true;
  13517. }
  13518. // Move startContainer/startOffset in to a suitable node
  13519. if (container.nodeType == 1) {
  13520. nodes = container.childNodes;
  13521. container = nodes[Math.min(offset, nodes.length - 1)];
  13522. walker = new TreeWalker(container, dom.getParent(container, dom.isBlock));
  13523. // If offset is at end of the parent node walk to the next one
  13524. if (offset > nodes.length - 1 || isAtEndOfText)
  13525. walker.next();
  13526. for (node = walker.current(); node; node = walker.next()) {
  13527. if (node.nodeType == 3 && !isWhiteSpaceNode(node)) {
  13528. // IE has a "neat" feature where it moves the start node into the closest element
  13529. // we can avoid this by inserting an element before it and then remove it after we set the selection
  13530. tmpNode = dom.create('a', null, INVISIBLE_CHAR);
  13531. node.parentNode.insertBefore(tmpNode, node);
  13532. // Set selection and remove tmpNode
  13533. rng.setStart(node, 0);
  13534. selection.setRng(rng);
  13535. dom.remove(tmpNode);
  13536. return;
  13537. }
  13538. }
  13539. }
  13540. };
  13541. };
  13542. })(tinymce);
  13543. tinymce.onAddEditor.add(function(tinymce, ed) {
  13544. var filters, fontSizes, dom, settings = ed.settings;
  13545. function replaceWithSpan(node, styles) {
  13546. tinymce.each(styles, function(value, name) {
  13547. if (value)
  13548. dom.setStyle(node, name, value);
  13549. });
  13550. dom.rename(node, 'span');
  13551. };
  13552. function convert(editor, params) {
  13553. dom = editor.dom;
  13554. if (settings.convert_fonts_to_spans) {
  13555. tinymce.each(dom.select('font,u,strike', params.node), function(node) {
  13556. filters[node.nodeName.toLowerCase()](ed.dom, node);
  13557. });
  13558. }
  13559. };
  13560. if (settings.inline_styles) {
  13561. fontSizes = tinymce.explode(settings.font_size_legacy_values);
  13562. filters = {
  13563. font : function(dom, node) {
  13564. replaceWithSpan(node, {
  13565. backgroundColor : node.style.backgroundColor,
  13566. color : node.color,
  13567. fontFamily : node.face,
  13568. fontSize : fontSizes[parseInt(node.size, 10) - 1]
  13569. });
  13570. },
  13571. u : function(dom, node) {
  13572. replaceWithSpan(node, {
  13573. textDecoration : 'underline'
  13574. });
  13575. },
  13576. strike : function(dom, node) {
  13577. replaceWithSpan(node, {
  13578. textDecoration : 'line-through'
  13579. });
  13580. }
  13581. };
  13582. ed.onPreProcess.add(convert);
  13583. ed.onSetContent.add(convert);
  13584. ed.onInit.add(function() {
  13585. ed.selection.onSetContent.add(convert);
  13586. });
  13587. }
  13588. });
  13589. (function(tinymce) {
  13590. var TreeWalker = tinymce.dom.TreeWalker;
  13591. tinymce.EnterKey = function(editor) {
  13592. var dom = editor.dom, selection = editor.selection, settings = editor.settings, undoManager = editor.undoManager, nonEmptyElementsMap = editor.schema.getNonEmptyElements();
  13593. function handleEnterKey(evt) {
  13594. var rng = selection.getRng(true), tmpRng, editableRoot, container, offset, parentBlock, documentMode, shiftKey,
  13595. newBlock, fragment, containerBlock, parentBlockName, containerBlockName, newBlockName, isAfterLastNodeInContainer;
  13596. // Returns true if the block can be split into two blocks or not
  13597. function canSplitBlock(node) {
  13598. return node &&
  13599. dom.isBlock(node) &&
  13600. !/^(TD|TH|CAPTION|FORM)$/.test(node.nodeName) &&
  13601. !/^(fixed|absolute)/i.test(node.style.position) &&
  13602. dom.getContentEditable(node) !== "true";
  13603. };
  13604. // Renders empty block on IE
  13605. function renderBlockOnIE(block) {
  13606. var oldRng;
  13607. if (tinymce.isIE && dom.isBlock(block)) {
  13608. oldRng = selection.getRng();
  13609. block.appendChild(dom.create('span', null, '\u00a0'));
  13610. selection.select(block);
  13611. block.lastChild.outerHTML = '';
  13612. selection.setRng(oldRng);
  13613. }
  13614. };
  13615. // Remove the first empty inline element of the block so this: <p><b><em></em></b>x</p> becomes this: <p>x</p>
  13616. function trimInlineElementsOnLeftSideOfBlock(block) {
  13617. var node = block, firstChilds = [], i;
  13618. // Find inner most first child ex: <p><i><b>*</b></i></p>
  13619. while (node = node.firstChild) {
  13620. if (dom.isBlock(node)) {
  13621. return;
  13622. }
  13623. if (node.nodeType == 1 && !nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  13624. firstChilds.push(node);
  13625. }
  13626. }
  13627. i = firstChilds.length;
  13628. while (i--) {
  13629. node = firstChilds[i];
  13630. if (!node.hasChildNodes() || (node.firstChild == node.lastChild && node.firstChild.nodeValue === '')) {
  13631. dom.remove(node);
  13632. } else {
  13633. // Remove <a> </a> see #5381
  13634. if (node.nodeName == "A" && (node.innerText || node.textContent) === ' ') {
  13635. dom.remove(node);
  13636. }
  13637. }
  13638. }
  13639. };
  13640. // Moves the caret to a suitable position within the root for example in the first non pure whitespace text node or before an image
  13641. function moveToCaretPosition(root) {
  13642. var walker, node, rng, y, viewPort, lastNode = root, tempElm;
  13643. rng = dom.createRng();
  13644. if (root.hasChildNodes()) {
  13645. walker = new TreeWalker(root, root);
  13646. while (node = walker.current()) {
  13647. if (node.nodeType == 3) {
  13648. rng.setStart(node, 0);
  13649. rng.setEnd(node, 0);
  13650. break;
  13651. }
  13652. if (nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  13653. rng.setStartBefore(node);
  13654. rng.setEndBefore(node);
  13655. break;
  13656. }
  13657. lastNode = node;
  13658. node = walker.next();
  13659. }
  13660. if (!node) {
  13661. rng.setStart(lastNode, 0);
  13662. rng.setEnd(lastNode, 0);
  13663. }
  13664. } else {
  13665. if (root.nodeName == 'BR') {
  13666. if (root.nextSibling && dom.isBlock(root.nextSibling)) {
  13667. // Trick on older IE versions to render the caret before the BR between two lists
  13668. if (!documentMode || documentMode < 9) {
  13669. tempElm = dom.create('br');
  13670. root.parentNode.insertBefore(tempElm, root);
  13671. }
  13672. rng.setStartBefore(root);
  13673. rng.setEndBefore(root);
  13674. } else {
  13675. rng.setStartAfter(root);
  13676. rng.setEndAfter(root);
  13677. }
  13678. } else {
  13679. rng.setStart(root, 0);
  13680. rng.setEnd(root, 0);
  13681. }
  13682. }
  13683. selection.setRng(rng);
  13684. // Remove tempElm created for old IE:s
  13685. dom.remove(tempElm);
  13686. viewPort = dom.getViewPort(editor.getWin());
  13687. // 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
  13688. y = dom.getPos(root).y;
  13689. if (y < viewPort.y || y + 25 > viewPort.y + viewPort.h) {
  13690. 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
  13691. }
  13692. };
  13693. // Creates a new block element by cloning the current one or creating a new one if the name is specified
  13694. // This function will also copy any text formatting from the parent block and add it to the new one
  13695. function createNewBlock(name) {
  13696. var node = container, block, clonedNode, caretNode;
  13697. block = name || parentBlockName == "TABLE" ? dom.create(name || newBlockName) : parentBlock.cloneNode(false);
  13698. caretNode = block;
  13699. // Clone any parent styles
  13700. if (settings.keep_styles !== false) {
  13701. do {
  13702. if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(node.nodeName)) {
  13703. // Never clone a caret containers
  13704. if (node.id == '_mce_caret') {
  13705. continue;
  13706. }
  13707. clonedNode = node.cloneNode(false);
  13708. dom.setAttrib(clonedNode, 'id', ''); // Remove ID since it needs to be document unique
  13709. if (block.hasChildNodes()) {
  13710. clonedNode.appendChild(block.firstChild);
  13711. block.appendChild(clonedNode);
  13712. } else {
  13713. caretNode = clonedNode;
  13714. block.appendChild(clonedNode);
  13715. }
  13716. }
  13717. } while (node = node.parentNode);
  13718. }
  13719. // BR is needed in empty blocks on non IE browsers
  13720. if (!tinymce.isIE) {
  13721. caretNode.innerHTML = '<br data-mce-bogus="1">';
  13722. }
  13723. return block;
  13724. };
  13725. // Returns true/false if the caret is at the start/end of the parent block element
  13726. function isCaretAtStartOrEndOfBlock(start) {
  13727. var walker, node, name;
  13728. // Caret is in the middle of a text node like "a|b"
  13729. if (container.nodeType == 3 && (start ? offset > 0 : offset < container.nodeValue.length)) {
  13730. return false;
  13731. }
  13732. // If after the last element in block node edge case for #5091
  13733. if (container.parentNode == parentBlock && isAfterLastNodeInContainer && !start) {
  13734. return true;
  13735. }
  13736. // If the caret if before the first element in parentBlock
  13737. if (start && container.nodeType == 1 && container == parentBlock.firstChild) {
  13738. return true;
  13739. }
  13740. // Caret can be before/after a table
  13741. if (container.nodeName === "TABLE" || (container.previousSibling && container.previousSibling.nodeName == "TABLE")) {
  13742. return (isAfterLastNodeInContainer && !start) || (!isAfterLastNodeInContainer && start);
  13743. }
  13744. // Walk the DOM and look for text nodes or non empty elements
  13745. walker = new TreeWalker(container, parentBlock);
  13746. // If caret is in beginning or end of a text block then jump to the next/previous node
  13747. if (container.nodeType == 3) {
  13748. if (start && offset == 0) {
  13749. walker.prev();
  13750. } else if (!start && offset == container.nodeValue.length) {
  13751. walker.next();
  13752. }
  13753. }
  13754. while (node = walker.current()) {
  13755. if (node.nodeType === 1) {
  13756. // Ignore bogus elements
  13757. if (!node.getAttribute('data-mce-bogus')) {
  13758. // Keep empty elements like <img /> <input /> but not trailing br:s like <p>text|<br></p>
  13759. name = node.nodeName.toLowerCase();
  13760. if (nonEmptyElementsMap[name] && name !== 'br') {
  13761. return false;
  13762. }
  13763. }
  13764. } else if (node.nodeType === 3 && !/^[ \t\r\n]*$/.test(node.nodeValue)) {
  13765. return false;
  13766. }
  13767. if (start) {
  13768. walker.prev();
  13769. } else {
  13770. walker.next();
  13771. }
  13772. }
  13773. return true;
  13774. };
  13775. // Wraps any text nodes or inline elements in the specified forced root block name
  13776. function wrapSelfAndSiblingsInDefaultBlock(container, offset) {
  13777. var newBlock, parentBlock, startNode, node, next, blockName = newBlockName || 'P';
  13778. // Not in a block element or in a table cell or caption
  13779. parentBlock = dom.getParent(container, dom.isBlock);
  13780. if (!parentBlock || !canSplitBlock(parentBlock)) {
  13781. parentBlock = parentBlock || editableRoot;
  13782. if (!parentBlock.hasChildNodes()) {
  13783. newBlock = dom.create(blockName);
  13784. parentBlock.appendChild(newBlock);
  13785. rng.setStart(newBlock, 0);
  13786. rng.setEnd(newBlock, 0);
  13787. return newBlock;
  13788. }
  13789. // Find parent that is the first child of parentBlock
  13790. node = container;
  13791. while (node.parentNode != parentBlock) {
  13792. node = node.parentNode;
  13793. }
  13794. // Loop left to find start node start wrapping at
  13795. while (node && !dom.isBlock(node)) {
  13796. startNode = node;
  13797. node = node.previousSibling;
  13798. }
  13799. if (startNode) {
  13800. newBlock = dom.create(blockName);
  13801. startNode.parentNode.insertBefore(newBlock, startNode);
  13802. // Start wrapping until we hit a block
  13803. node = startNode;
  13804. while (node && !dom.isBlock(node)) {
  13805. next = node.nextSibling;
  13806. newBlock.appendChild(node);
  13807. node = next;
  13808. }
  13809. // Restore range to it's past location
  13810. rng.setStart(container, offset);
  13811. rng.setEnd(container, offset);
  13812. }
  13813. }
  13814. return container;
  13815. };
  13816. // Inserts a block or br before/after or in the middle of a split list of the LI is empty
  13817. function handleEmptyListItem() {
  13818. function isFirstOrLastLi(first) {
  13819. var node = containerBlock[first ? 'firstChild' : 'lastChild'];
  13820. // Find first/last element since there might be whitespace there
  13821. while (node) {
  13822. if (node.nodeType == 1) {
  13823. break;
  13824. }
  13825. node = node[first ? 'nextSibling' : 'previousSibling'];
  13826. }
  13827. return node === parentBlock;
  13828. };
  13829. newBlock = newBlockName ? createNewBlock(newBlockName) : dom.create('BR');
  13830. if (isFirstOrLastLi(true) && isFirstOrLastLi()) {
  13831. // Is first and last list item then replace the OL/UL with a text block
  13832. dom.replace(newBlock, containerBlock);
  13833. } else if (isFirstOrLastLi(true)) {
  13834. // First LI in list then remove LI and add text block before list
  13835. containerBlock.parentNode.insertBefore(newBlock, containerBlock);
  13836. } else if (isFirstOrLastLi()) {
  13837. // Last LI in list then temove LI and add text block after list
  13838. dom.insertAfter(newBlock, containerBlock);
  13839. renderBlockOnIE(newBlock);
  13840. } else {
  13841. // Middle LI in list the split the list and insert a text block in the middle
  13842. // Extract after fragment and insert it after the current block
  13843. tmpRng = rng.cloneRange();
  13844. tmpRng.setStartAfter(parentBlock);
  13845. tmpRng.setEndAfter(containerBlock);
  13846. fragment = tmpRng.extractContents();
  13847. dom.insertAfter(fragment, containerBlock);
  13848. dom.insertAfter(newBlock, containerBlock);
  13849. }
  13850. dom.remove(parentBlock);
  13851. moveToCaretPosition(newBlock);
  13852. undoManager.add();
  13853. };
  13854. // Walks the parent block to the right and look for BR elements
  13855. function hasRightSideBr() {
  13856. var walker = new TreeWalker(container, parentBlock), node;
  13857. while (node = walker.current()) {
  13858. if (node.nodeName == 'BR') {
  13859. return true;
  13860. }
  13861. node = walker.next();
  13862. }
  13863. }
  13864. // Inserts a BR element if the forced_root_block option is set to false or empty string
  13865. function insertBr() {
  13866. var brElm, extraBr;
  13867. if (container && container.nodeType == 3 && offset >= container.nodeValue.length) {
  13868. // Insert extra BR element at the end block elements
  13869. if (!tinymce.isIE && !hasRightSideBr()) {
  13870. brElm = dom.create('br');
  13871. rng.insertNode(brElm);
  13872. rng.setStartAfter(brElm);
  13873. rng.setEndAfter(brElm);
  13874. extraBr = true;
  13875. }
  13876. }
  13877. brElm = dom.create('br');
  13878. rng.insertNode(brElm);
  13879. // Rendering modes below IE8 doesn't display BR elements in PRE unless we have a \n before it
  13880. if (tinymce.isIE && parentBlockName == 'PRE' && (!documentMode || documentMode < 8)) {
  13881. brElm.parentNode.insertBefore(dom.doc.createTextNode('\r'), brElm);
  13882. }
  13883. if (!extraBr) {
  13884. rng.setStartAfter(brElm);
  13885. rng.setEndAfter(brElm);
  13886. } else {
  13887. rng.setStartBefore(brElm);
  13888. rng.setEndBefore(brElm);
  13889. }
  13890. selection.setRng(rng);
  13891. undoManager.add();
  13892. };
  13893. // Trims any linebreaks at the beginning of node user for example when pressing enter in a PRE element
  13894. function trimLeadingLineBreaks(node) {
  13895. do {
  13896. if (node.nodeType === 3) {
  13897. node.nodeValue = node.nodeValue.replace(/^[\r\n]+/, '');
  13898. }
  13899. node = node.firstChild;
  13900. } while (node);
  13901. };
  13902. function getEditableRoot(node) {
  13903. var root = dom.getRoot(), parent, editableRoot;
  13904. // Get all parents until we hit a non editable parent or the root
  13905. parent = node;
  13906. while (parent !== root && dom.getContentEditable(parent) !== "false") {
  13907. if (dom.getContentEditable(parent) === "true") {
  13908. editableRoot = parent;
  13909. }
  13910. parent = parent.parentNode;
  13911. }
  13912. return parent !== root ? editableRoot : root;
  13913. };
  13914. // 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
  13915. function addBrToBlockIfNeeded(block) {
  13916. var lastChild;
  13917. // IE will render the blocks correctly other browsers needs a BR
  13918. if (!tinymce.isIE) {
  13919. block.normalize(); // Remove empty text nodes that got left behind by the extract
  13920. // Check if the block is empty or contains a floated last child
  13921. lastChild = block.lastChild;
  13922. if (!lastChild || (/^(left|right)$/gi.test(dom.getStyle(lastChild, 'float', true)))) {
  13923. dom.add(block, 'br');
  13924. }
  13925. }
  13926. };
  13927. // Delete any selected contents
  13928. if (!rng.collapsed) {
  13929. editor.execCommand('Delete');
  13930. return;
  13931. }
  13932. // Event is blocked by some other handler for example the lists plugin
  13933. if (evt.isDefaultPrevented()) {
  13934. return;
  13935. }
  13936. // Setup range items and newBlockName
  13937. container = rng.startContainer;
  13938. offset = rng.startOffset;
  13939. newBlockName = (settings.force_p_newlines ? 'p' : '') || settings.forced_root_block;
  13940. newBlockName = newBlockName ? newBlockName.toUpperCase() : '';
  13941. documentMode = dom.doc.documentMode;
  13942. shiftKey = evt.shiftKey;
  13943. // Resolve node index
  13944. if (container.nodeType == 1 && container.hasChildNodes()) {
  13945. isAfterLastNodeInContainer = offset > container.childNodes.length - 1;
  13946. container = container.childNodes[Math.min(offset, container.childNodes.length - 1)] || container;
  13947. if (isAfterLastNodeInContainer && container.nodeType == 3) {
  13948. offset = container.nodeValue.length;
  13949. } else {
  13950. offset = 0;
  13951. }
  13952. }
  13953. // Get editable root node normaly the body element but sometimes a div or span
  13954. editableRoot = getEditableRoot(container);
  13955. // If there is no editable root then enter is done inside a contentEditable false element
  13956. if (!editableRoot) {
  13957. return;
  13958. }
  13959. undoManager.beforeChange();
  13960. // If editable root isn't block nor the root of the editor
  13961. if (!dom.isBlock(editableRoot) && editableRoot != dom.getRoot()) {
  13962. if (!newBlockName || shiftKey) {
  13963. insertBr();
  13964. }
  13965. return;
  13966. }
  13967. // Wrap the current node and it's sibling in a default block if it's needed.
  13968. // for example this <td>text|<b>text2</b></td> will become this <td><p>text|<b>text2</p></b></td>
  13969. // This won't happen if root blocks are disabled or the shiftKey is pressed
  13970. if ((newBlockName && !shiftKey) || (!newBlockName && shiftKey)) {
  13971. container = wrapSelfAndSiblingsInDefaultBlock(container, offset);
  13972. }
  13973. // Find parent block and setup empty block paddings
  13974. parentBlock = dom.getParent(container, dom.isBlock);
  13975. containerBlock = parentBlock ? dom.getParent(parentBlock.parentNode, dom.isBlock) : null;
  13976. // Setup block names
  13977. parentBlockName = parentBlock ? parentBlock.nodeName.toUpperCase() : ''; // IE < 9 & HTML5
  13978. containerBlockName = containerBlock ? containerBlock.nodeName.toUpperCase() : ''; // IE < 9 & HTML5
  13979. // Enter inside block contained within a LI then split or insert before/after LI
  13980. if (containerBlockName == 'LI' && !evt.ctrlKey) {
  13981. parentBlock = containerBlock;
  13982. parentBlockName = containerBlockName;
  13983. }
  13984. // Handle enter in LI
  13985. if (parentBlockName == 'LI') {
  13986. if (!newBlockName && shiftKey) {
  13987. insertBr();
  13988. return;
  13989. }
  13990. // Handle enter inside an empty list item
  13991. if (dom.isEmpty(parentBlock)) {
  13992. // Let the list plugin or browser handle nested lists for now
  13993. if (/^(UL|OL|LI)$/.test(containerBlock.parentNode.nodeName)) {
  13994. return false;
  13995. }
  13996. handleEmptyListItem();
  13997. return;
  13998. }
  13999. }
  14000. // Don't split PRE tags but insert a BR instead easier when writing code samples etc
  14001. if (parentBlockName == 'PRE' && settings.br_in_pre !== false) {
  14002. if (!shiftKey) {
  14003. insertBr();
  14004. return;
  14005. }
  14006. } else {
  14007. // If no root block is configured then insert a BR by default or if the shiftKey is pressed
  14008. if ((!newBlockName && !shiftKey && parentBlockName != 'LI') || (newBlockName && shiftKey)) {
  14009. insertBr();
  14010. return;
  14011. }
  14012. }
  14013. // Default block name if it's not configured
  14014. newBlockName = newBlockName || 'P';
  14015. // Insert new block before/after the parent block depending on caret location
  14016. if (isCaretAtStartOrEndOfBlock()) {
  14017. // 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
  14018. if (/^(H[1-6]|PRE)$/.test(parentBlockName) && containerBlockName != 'HGROUP') {
  14019. newBlock = createNewBlock(newBlockName);
  14020. } else {
  14021. newBlock = createNewBlock();
  14022. }
  14023. // Split the current container block element if enter is pressed inside an empty inner block element
  14024. if (settings.end_container_on_empty_block && canSplitBlock(containerBlock) && dom.isEmpty(parentBlock)) {
  14025. // Split container block for example a BLOCKQUOTE at the current blockParent location for example a P
  14026. newBlock = dom.split(containerBlock, parentBlock);
  14027. } else {
  14028. dom.insertAfter(newBlock, parentBlock);
  14029. }
  14030. moveToCaretPosition(newBlock);
  14031. } else if (isCaretAtStartOrEndOfBlock(true)) {
  14032. // Insert new block before
  14033. newBlock = parentBlock.parentNode.insertBefore(createNewBlock(), parentBlock);
  14034. renderBlockOnIE(newBlock);
  14035. } else {
  14036. // Extract after fragment and insert it after the current block
  14037. tmpRng = rng.cloneRange();
  14038. tmpRng.setEndAfter(parentBlock);
  14039. fragment = tmpRng.extractContents();
  14040. trimLeadingLineBreaks(fragment);
  14041. newBlock = fragment.firstChild;
  14042. dom.insertAfter(fragment, parentBlock);
  14043. trimInlineElementsOnLeftSideOfBlock(newBlock);
  14044. addBrToBlockIfNeeded(parentBlock);
  14045. moveToCaretPosition(newBlock);
  14046. }
  14047. dom.setAttrib(newBlock, 'id', ''); // Remove ID since it needs to be document unique
  14048. undoManager.add();
  14049. }
  14050. editor.onKeyDown.add(function(ed, evt) {
  14051. if (evt.keyCode == 13) {
  14052. if (handleEnterKey(evt) !== false) {
  14053. evt.preventDefault();
  14054. }
  14055. }
  14056. });
  14057. };
  14058. })(tinymce);