tiny_mce_src.js 419 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979
  1. (function(win) {
  2. var whiteSpaceRe = /^\s*|\s*$/g,
  3. undefined, isRegExpBroken = 'B'.replace(/A(.)|B/, '$1') === '$1';
  4. var tinymce = {
  5. majorVersion : '3',
  6. minorVersion : '4.8',
  7. releaseDate : '2012-02-02',
  8. _init : function() {
  9. var t = this, d = document, na = navigator, ua = na.userAgent, i, nl, n, base, p, v;
  10. t.isOpera = win.opera && opera.buildNumber;
  11. t.isWebKit = /WebKit/.test(ua);
  12. t.isIE = !t.isWebKit && !t.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(na.appName);
  13. t.isIE6 = t.isIE && /MSIE [56]/.test(ua);
  14. t.isIE7 = t.isIE && /MSIE [7]/.test(ua);
  15. t.isIE8 = t.isIE && /MSIE [8]/.test(ua);
  16. t.isIE9 = t.isIE && /MSIE [9]/.test(ua);
  17. t.isGecko = !t.isWebKit && /Gecko/.test(ua);
  18. t.isMac = ua.indexOf('Mac') != -1;
  19. t.isAir = /adobeair/i.test(ua);
  20. t.isIDevice = /(iPad|iPhone)/.test(ua);
  21. t.isIOS5 = t.isIDevice && ua.match(/AppleWebKit\/(\d*)/)[1]>=534;
  22. // TinyMCE .NET webcontrol might be setting the values for TinyMCE
  23. if (win.tinyMCEPreInit) {
  24. t.suffix = tinyMCEPreInit.suffix;
  25. t.baseURL = tinyMCEPreInit.base;
  26. t.query = tinyMCEPreInit.query;
  27. return;
  28. }
  29. // Get suffix and base
  30. t.suffix = '';
  31. // If base element found, add that infront of baseURL
  32. nl = d.getElementsByTagName('base');
  33. for (i=0; i<nl.length; i++) {
  34. if (v = nl[i].href) {
  35. // Host only value like http://site.com or http://site.com:8008
  36. if (/^https?:\/\/[^\/]+$/.test(v))
  37. v += '/';
  38. base = v ? v.match(/.*\//)[0] : ''; // Get only directory
  39. }
  40. }
  41. function getBase(n) {
  42. if (n.src && /tiny_mce(|_gzip|_jquery|_prototype|_full)(_dev|_src)?.js/.test(n.src)) {
  43. if (/_(src|dev)\.js/g.test(n.src))
  44. t.suffix = '_src';
  45. if ((p = n.src.indexOf('?')) != -1)
  46. t.query = n.src.substring(p + 1);
  47. t.baseURL = n.src.substring(0, n.src.lastIndexOf('/'));
  48. // If path to script is relative and a base href was found add that one infront
  49. // the src property will always be an absolute one on non IE browsers and IE 8
  50. // so this logic will basically only be executed on older IE versions
  51. if (base && t.baseURL.indexOf('://') == -1 && t.baseURL.indexOf('/') !== 0)
  52. t.baseURL = base + t.baseURL;
  53. return t.baseURL;
  54. }
  55. return null;
  56. };
  57. // Check document
  58. nl = d.getElementsByTagName('script');
  59. for (i=0; i<nl.length; i++) {
  60. if (getBase(nl[i]))
  61. return;
  62. }
  63. // Check head
  64. n = d.getElementsByTagName('head')[0];
  65. if (n) {
  66. nl = n.getElementsByTagName('script');
  67. for (i=0; i<nl.length; i++) {
  68. if (getBase(nl[i]))
  69. return;
  70. }
  71. }
  72. return;
  73. },
  74. is : function(o, t) {
  75. if (!t)
  76. return o !== undefined;
  77. if (t == 'array' && (o.hasOwnProperty && o instanceof Array))
  78. return true;
  79. return typeof(o) == t;
  80. },
  81. makeMap : function(items, delim, map) {
  82. var i;
  83. items = items || [];
  84. delim = delim || ',';
  85. if (typeof(items) == "string")
  86. items = items.split(delim);
  87. map = map || {};
  88. i = items.length;
  89. while (i--)
  90. map[items[i]] = {};
  91. return map;
  92. },
  93. each : function(o, cb, s) {
  94. var n, l;
  95. if (!o)
  96. return 0;
  97. s = s || o;
  98. if (o.length !== undefined) {
  99. // Indexed arrays, needed for Safari
  100. for (n=0, l = o.length; n < l; n++) {
  101. if (cb.call(s, o[n], n, o) === false)
  102. return 0;
  103. }
  104. } else {
  105. // Hashtables
  106. for (n in o) {
  107. if (o.hasOwnProperty(n)) {
  108. if (cb.call(s, o[n], n, o) === false)
  109. return 0;
  110. }
  111. }
  112. }
  113. return 1;
  114. },
  115. trim : function(s) {
  116. return (s ? '' + s : '').replace(whiteSpaceRe, '');
  117. },
  118. create : function(s, p, root) {
  119. var t = this, sp, ns, cn, scn, c, de = 0;
  120. // Parse : <prefix> <class>:<super class>
  121. s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s);
  122. cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name
  123. // Create namespace for new class
  124. ns = t.createNS(s[3].replace(/\.\w+$/, ''), root);
  125. // Class already exists
  126. if (ns[cn])
  127. return;
  128. // Make pure static class
  129. if (s[2] == 'static') {
  130. ns[cn] = p;
  131. if (this.onCreate)
  132. this.onCreate(s[2], s[3], ns[cn]);
  133. return;
  134. }
  135. // Create default constructor
  136. if (!p[cn]) {
  137. p[cn] = function() {};
  138. de = 1;
  139. }
  140. // Add constructor and methods
  141. ns[cn] = p[cn];
  142. t.extend(ns[cn].prototype, p);
  143. // Extend
  144. if (s[5]) {
  145. sp = t.resolve(s[5]).prototype;
  146. scn = s[5].match(/\.(\w+)$/i)[1]; // Class name
  147. // Extend constructor
  148. c = ns[cn];
  149. if (de) {
  150. // Add passthrough constructor
  151. ns[cn] = function() {
  152. return sp[scn].apply(this, arguments);
  153. };
  154. } else {
  155. // Add inherit constructor
  156. ns[cn] = function() {
  157. this.parent = sp[scn];
  158. return c.apply(this, arguments);
  159. };
  160. }
  161. ns[cn].prototype[cn] = ns[cn];
  162. // Add super methods
  163. t.each(sp, function(f, n) {
  164. ns[cn].prototype[n] = sp[n];
  165. });
  166. // Add overridden methods
  167. t.each(p, function(f, n) {
  168. // Extend methods if needed
  169. if (sp[n]) {
  170. ns[cn].prototype[n] = function() {
  171. this.parent = sp[n];
  172. return f.apply(this, arguments);
  173. };
  174. } else {
  175. if (n != cn)
  176. ns[cn].prototype[n] = f;
  177. }
  178. });
  179. }
  180. // Add static methods
  181. t.each(p['static'], function(f, n) {
  182. ns[cn][n] = f;
  183. });
  184. if (this.onCreate)
  185. this.onCreate(s[2], s[3], ns[cn].prototype);
  186. },
  187. walk : function(o, f, n, s) {
  188. s = s || this;
  189. if (o) {
  190. if (n)
  191. o = o[n];
  192. tinymce.each(o, function(o, i) {
  193. if (f.call(s, o, i, n) === false)
  194. return false;
  195. tinymce.walk(o, f, n, s);
  196. });
  197. }
  198. },
  199. createNS : function(n, o) {
  200. var i, v;
  201. o = o || win;
  202. n = n.split('.');
  203. for (i=0; i<n.length; i++) {
  204. v = n[i];
  205. if (!o[v])
  206. o[v] = {};
  207. o = o[v];
  208. }
  209. return o;
  210. },
  211. resolve : function(n, o) {
  212. var i, l;
  213. o = o || win;
  214. n = n.split('.');
  215. for (i = 0, l = n.length; i < l; i++) {
  216. o = o[n[i]];
  217. if (!o)
  218. break;
  219. }
  220. return o;
  221. },
  222. addUnload : function(f, s) {
  223. var t = this;
  224. f = {func : f, scope : s || this};
  225. if (!t.unloads) {
  226. function unload() {
  227. var li = t.unloads, o, n;
  228. if (li) {
  229. // Call unload handlers
  230. for (n in li) {
  231. o = li[n];
  232. if (o && o.func)
  233. o.func.call(o.scope, 1); // Send in one arg to distinct unload and user destroy
  234. }
  235. // Detach unload function
  236. if (win.detachEvent) {
  237. win.detachEvent('onbeforeunload', fakeUnload);
  238. win.detachEvent('onunload', unload);
  239. } else if (win.removeEventListener)
  240. win.removeEventListener('unload', unload, false);
  241. // Destroy references
  242. t.unloads = o = li = w = unload = 0;
  243. // Run garbarge collector on IE
  244. if (win.CollectGarbage)
  245. CollectGarbage();
  246. }
  247. };
  248. function fakeUnload() {
  249. var d = document;
  250. // Is there things still loading, then do some magic
  251. if (d.readyState == 'interactive') {
  252. function stop() {
  253. // Prevent memory leak
  254. d.detachEvent('onstop', stop);
  255. // Call unload handler
  256. if (unload)
  257. unload();
  258. d = 0;
  259. };
  260. // Fire unload when the currently loading page is stopped
  261. if (d)
  262. d.attachEvent('onstop', stop);
  263. // Remove onstop listener after a while to prevent the unload function
  264. // to execute if the user presses cancel in an onbeforeunload
  265. // confirm dialog and then presses the browser stop button
  266. win.setTimeout(function() {
  267. if (d)
  268. d.detachEvent('onstop', stop);
  269. }, 0);
  270. }
  271. };
  272. // Attach unload handler
  273. if (win.attachEvent) {
  274. win.attachEvent('onunload', unload);
  275. win.attachEvent('onbeforeunload', fakeUnload);
  276. } else if (win.addEventListener)
  277. win.addEventListener('unload', unload, false);
  278. // Setup initial unload handler array
  279. t.unloads = [f];
  280. } else
  281. t.unloads.push(f);
  282. return f;
  283. },
  284. removeUnload : function(f) {
  285. var u = this.unloads, r = null;
  286. tinymce.each(u, function(o, i) {
  287. if (o && o.func == f) {
  288. u.splice(i, 1);
  289. r = f;
  290. return false;
  291. }
  292. });
  293. return r;
  294. },
  295. explode : function(s, d) {
  296. return s ? tinymce.map(s.split(d || ','), tinymce.trim) : s;
  297. },
  298. _addVer : function(u) {
  299. var v;
  300. if (!this.query)
  301. return u;
  302. v = (u.indexOf('?') == -1 ? '?' : '&') + this.query;
  303. if (u.indexOf('#') == -1)
  304. return u + v;
  305. return u.replace('#', v + '#');
  306. },
  307. // Fix function for IE 9 where regexps isn't working correctly
  308. // Todo: remove me once MS fixes the bug
  309. _replace : function(find, replace, str) {
  310. // On IE9 we have to fake $x replacement
  311. if (isRegExpBroken) {
  312. return str.replace(find, function() {
  313. var val = replace, args = arguments, i;
  314. for (i = 0; i < args.length - 2; i++) {
  315. if (args[i] === undefined) {
  316. val = val.replace(new RegExp('\\$' + i, 'g'), '');
  317. } else {
  318. val = val.replace(new RegExp('\\$' + i, 'g'), args[i]);
  319. }
  320. }
  321. return val;
  322. });
  323. }
  324. return str.replace(find, replace);
  325. }
  326. };
  327. // Initialize the API
  328. tinymce._init();
  329. // Expose tinymce namespace to the global namespace (window)
  330. win.tinymce = win.tinyMCE = tinymce;
  331. // Describe the different namespaces
  332. })(window);
  333. (function($, tinymce) {
  334. var is = tinymce.is, attrRegExp = /^(href|src|style)$/i, undefined;
  335. // jQuery is undefined
  336. if (!$ && window.console) {
  337. return console.log("Load jQuery first!");
  338. }
  339. // Stick jQuery into the tinymce namespace
  340. tinymce.$ = $;
  341. // Setup adapter
  342. tinymce.adapter = {
  343. patchEditor : function(editor) {
  344. var fn = $.fn;
  345. // Adapt the css function to make sure that the data-mce-style
  346. // attribute gets updated with the new style information
  347. function css(name, value) {
  348. var self = this;
  349. // Remove data-mce-style when set operation occurs
  350. if (value)
  351. self.removeAttr('data-mce-style');
  352. return fn.css.apply(self, arguments);
  353. };
  354. // Apapt the attr function to make sure that it uses the data-mce- prefixed variants
  355. function attr(name, value) {
  356. var self = this;
  357. // Update/retrive data-mce- attribute variants
  358. if (attrRegExp.test(name)) {
  359. if (value !== undefined) {
  360. // Use TinyMCE behavior when setting the specifc attributes
  361. self.each(function(i, node) {
  362. editor.dom.setAttrib(node, name, value);
  363. });
  364. return self;
  365. } else
  366. return self.attr('data-mce-' + name);
  367. }
  368. // Default behavior
  369. return fn.attr.apply(self, arguments);
  370. };
  371. function htmlPatchFunc(func) {
  372. // Returns a modified function that processes
  373. // the HTML before executing the action this makes sure
  374. // that href/src etc gets moved into the data-mce- variants
  375. return function(content) {
  376. if (content)
  377. content = editor.dom.processHTML(content);
  378. return func.call(this, content);
  379. };
  380. };
  381. // Patch various jQuery functions to handle tinymce specific attribute and content behavior
  382. // we don't patch the jQuery.fn directly since it will most likely break compatibility
  383. // with other jQuery logic on the page. Only instances created by TinyMCE should be patched.
  384. function patch(jq) {
  385. // Patch some functions, only patch the object once
  386. if (jq.css !== css) {
  387. // Patch css/attr to use the data-mce- prefixed attribute variants
  388. jq.css = css;
  389. jq.attr = attr;
  390. // Patch HTML functions to use the DOMUtils.processHTML filter logic
  391. jq.html = htmlPatchFunc(fn.html);
  392. jq.append = htmlPatchFunc(fn.append);
  393. jq.prepend = htmlPatchFunc(fn.prepend);
  394. jq.after = htmlPatchFunc(fn.after);
  395. jq.before = htmlPatchFunc(fn.before);
  396. jq.replaceWith = htmlPatchFunc(fn.replaceWith);
  397. jq.tinymce = editor;
  398. // Each pushed jQuery instance needs to be patched
  399. // as well for example when traversing the DOM
  400. jq.pushStack = function() {
  401. return patch(fn.pushStack.apply(this, arguments));
  402. };
  403. }
  404. return jq;
  405. };
  406. // Add a $ function on each editor instance this one is scoped for the editor document object
  407. // this way you can do chaining like this tinymce.get(0).$('p').append('text').css('color', 'red');
  408. editor.$ = function(selector, scope) {
  409. var doc = editor.getDoc();
  410. return patch($(selector || doc, doc || scope));
  411. };
  412. }
  413. };
  414. // Patch in core NS functions
  415. tinymce.extend = $.extend;
  416. tinymce.extend(tinymce, {
  417. map : $.map,
  418. grep : function(a, f) {return $.grep(a, f || function(){return 1;});},
  419. inArray : function(a, v) {return $.inArray(v, a || []);}
  420. /* Didn't iterate stylesheets
  421. each : function(o, cb, s) {
  422. if (!o)
  423. return 0;
  424. var r = 1;
  425. $.each(o, function(nr, el){
  426. if (cb.call(s, el, nr, o) === false) {
  427. r = 0;
  428. return false;
  429. }
  430. });
  431. return r;
  432. }*/
  433. });
  434. // Patch in functions in various clases
  435. // Add a "#ifndefjquery" statement around each core API function you add below
  436. var patches = {
  437. 'tinymce.dom.DOMUtils' : {
  438. /*
  439. addClass : function(e, c) {
  440. if (is(e, 'array') && is(e[0], 'string'))
  441. e = e.join(',#');
  442. return (e && $(is(e, 'string') ? '#' + e : e)
  443. .addClass(c)
  444. .attr('class')) || false;
  445. },
  446. hasClass : function(n, c) {
  447. return $(is(n, 'string') ? '#' + n : n).hasClass(c);
  448. },
  449. removeClass : function(e, c) {
  450. if (!e)
  451. return false;
  452. var r = [];
  453. $(is(e, 'string') ? '#' + e : e)
  454. .removeClass(c)
  455. .each(function(){
  456. r.push(this.className);
  457. });
  458. return r.length == 1 ? r[0] : r;
  459. },
  460. */
  461. select : function(pattern, scope) {
  462. var t = this;
  463. return $.find(pattern, t.get(scope) || t.get(t.settings.root_element) || t.doc, []);
  464. },
  465. is : function(n, patt) {
  466. return $(this.get(n)).is(patt);
  467. }
  468. /*
  469. show : function(e) {
  470. if (is(e, 'array') && is(e[0], 'string'))
  471. e = e.join(',#');
  472. $(is(e, 'string') ? '#' + e : e).css('display', 'block');
  473. },
  474. hide : function(e) {
  475. if (is(e, 'array') && is(e[0], 'string'))
  476. e = e.join(',#');
  477. $(is(e, 'string') ? '#' + e : e).css('display', 'none');
  478. },
  479. isHidden : function(e) {
  480. return $(is(e, 'string') ? '#' + e : e).is(':hidden');
  481. },
  482. insertAfter : function(n, e) {
  483. return $(is(e, 'string') ? '#' + e : e).after(n);
  484. },
  485. replace : function(o, n, k) {
  486. n = $(is(n, 'string') ? '#' + n : n);
  487. if (k)
  488. n.children().appendTo(o);
  489. n.replaceWith(o);
  490. },
  491. setStyle : function(n, na, v) {
  492. if (is(n, 'array') && is(n[0], 'string'))
  493. n = n.join(',#');
  494. $(is(n, 'string') ? '#' + n : n).css(na, v);
  495. },
  496. getStyle : function(n, na, c) {
  497. return $(is(n, 'string') ? '#' + n : n).css(na);
  498. },
  499. setStyles : function(e, o) {
  500. if (is(e, 'array') && is(e[0], 'string'))
  501. e = e.join(',#');
  502. $(is(e, 'string') ? '#' + e : e).css(o);
  503. },
  504. setAttrib : function(e, n, v) {
  505. var t = this, s = t.settings;
  506. if (is(e, 'array') && is(e[0], 'string'))
  507. e = e.join(',#');
  508. e = $(is(e, 'string') ? '#' + e : e);
  509. switch (n) {
  510. case "style":
  511. e.each(function(i, v){
  512. if (s.keep_values)
  513. $(v).attr('data-mce-style', v);
  514. v.style.cssText = v;
  515. });
  516. break;
  517. case "class":
  518. e.each(function(){
  519. this.className = v;
  520. });
  521. break;
  522. case "src":
  523. case "href":
  524. e.each(function(i, v){
  525. if (s.keep_values) {
  526. if (s.url_converter)
  527. v = s.url_converter.call(s.url_converter_scope || t, v, n, v);
  528. t.setAttrib(v, 'data-mce-' + n, v);
  529. }
  530. });
  531. break;
  532. }
  533. if (v !== null && v.length !== 0)
  534. e.attr(n, '' + v);
  535. else
  536. e.removeAttr(n);
  537. },
  538. setAttribs : function(e, o) {
  539. var t = this;
  540. $.each(o, function(n, v){
  541. t.setAttrib(e,n,v);
  542. });
  543. }
  544. */
  545. }
  546. /*
  547. 'tinymce.dom.Event' : {
  548. add : function (o, n, f, s) {
  549. var lo, cb;
  550. cb = function(e) {
  551. e.target = e.target || this;
  552. f.call(s || this, e);
  553. };
  554. if (is(o, 'array') && is(o[0], 'string'))
  555. o = o.join(',#');
  556. o = $(is(o, 'string') ? '#' + o : o);
  557. if (n == 'init') {
  558. o.ready(cb, s);
  559. } else {
  560. if (s) {
  561. o.bind(n, s, cb);
  562. } else {
  563. o.bind(n, cb);
  564. }
  565. }
  566. lo = this._jqLookup || (this._jqLookup = []);
  567. lo.push({func : f, cfunc : cb});
  568. return cb;
  569. },
  570. remove : function(o, n, f) {
  571. // Find cfunc
  572. $(this._jqLookup).each(function() {
  573. if (this.func === f)
  574. f = this.cfunc;
  575. });
  576. if (is(o, 'array') && is(o[0], 'string'))
  577. o = o.join(',#');
  578. $(is(o, 'string') ? '#' + o : o).unbind(n,f);
  579. return true;
  580. }
  581. }
  582. */
  583. };
  584. // Patch functions after a class is created
  585. tinymce.onCreate = function(ty, c, p) {
  586. tinymce.extend(p, patches[c]);
  587. };
  588. })(window.jQuery, tinymce);
  589. tinymce.create('tinymce.util.Dispatcher', {
  590. scope : null,
  591. listeners : null,
  592. Dispatcher : function(s) {
  593. this.scope = s || this;
  594. this.listeners = [];
  595. },
  596. add : function(cb, s) {
  597. this.listeners.push({cb : cb, scope : s || this.scope});
  598. return cb;
  599. },
  600. addToTop : function(cb, s) {
  601. this.listeners.unshift({cb : cb, scope : s || this.scope});
  602. return cb;
  603. },
  604. remove : function(cb) {
  605. var l = this.listeners, o = null;
  606. tinymce.each(l, function(c, i) {
  607. if (cb == c.cb) {
  608. o = cb;
  609. l.splice(i, 1);
  610. return false;
  611. }
  612. });
  613. return o;
  614. },
  615. dispatch : function() {
  616. var s, a = arguments, i, li = this.listeners, c;
  617. // Needs to be a real loop since the listener count might change while looping
  618. // And this is also more efficient
  619. for (i = 0; i<li.length; i++) {
  620. c = li[i];
  621. s = c.cb.apply(c.scope, a.length > 0 ? a : [c.scope]);
  622. if (s === false)
  623. break;
  624. }
  625. return s;
  626. }
  627. });
  628. (function() {
  629. var each = tinymce.each;
  630. tinymce.create('tinymce.util.URI', {
  631. URI : function(u, s) {
  632. var t = this, o, a, b, base_url;
  633. // Trim whitespace
  634. u = tinymce.trim(u);
  635. // Default settings
  636. s = t.settings = s || {};
  637. // Strange app protocol that isn't http/https or local anchor
  638. // For example: mailto,skype,tel etc.
  639. if (/^([\w\-]+):([^\/]{2})/i.test(u) || /^\s*#/.test(u)) {
  640. t.source = u;
  641. return;
  642. }
  643. // Absolute path with no host, fake host and protocol
  644. if (u.indexOf('/') === 0 && u.indexOf('//') !== 0)
  645. u = (s.base_uri ? s.base_uri.protocol || 'http' : 'http') + '://mce_host' + u;
  646. // Relative path http:// or protocol relative //path
  647. if (!/^[\w-]*:?\/\//.test(u)) {
  648. base_url = s.base_uri ? s.base_uri.path : new tinymce.util.URI(location.href).directory;
  649. u = ((s.base_uri && s.base_uri.protocol) || 'http') + '://mce_host' + t.toAbsPath(base_url, u);
  650. }
  651. // Parse URL (Credits goes to Steave, http://blog.stevenlevithan.com/archives/parseuri)
  652. u = u.replace(/@@/g, '(mce_at)'); // Zope 3 workaround, they use @@something
  653. u = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(u);
  654. each(["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], function(v, i) {
  655. var s = u[i];
  656. // Zope 3 workaround, they use @@something
  657. if (s)
  658. s = s.replace(/\(mce_at\)/g, '@@');
  659. t[v] = s;
  660. });
  661. if (b = s.base_uri) {
  662. if (!t.protocol)
  663. t.protocol = b.protocol;
  664. if (!t.userInfo)
  665. t.userInfo = b.userInfo;
  666. if (!t.port && t.host == 'mce_host')
  667. t.port = b.port;
  668. if (!t.host || t.host == 'mce_host')
  669. t.host = b.host;
  670. t.source = '';
  671. }
  672. //t.path = t.path || '/';
  673. },
  674. setPath : function(p) {
  675. var t = this;
  676. p = /^(.*?)\/?(\w+)?$/.exec(p);
  677. // Update path parts
  678. t.path = p[0];
  679. t.directory = p[1];
  680. t.file = p[2];
  681. // Rebuild source
  682. t.source = '';
  683. t.getURI();
  684. },
  685. toRelative : function(u) {
  686. var t = this, o;
  687. if (u === "./")
  688. return u;
  689. u = new tinymce.util.URI(u, {base_uri : t});
  690. // Not on same domain/port or protocol
  691. if ((u.host != 'mce_host' && t.host != u.host && u.host) || t.port != u.port || t.protocol != u.protocol)
  692. return u.getURI();
  693. o = t.toRelPath(t.path, u.path);
  694. // Add query
  695. if (u.query)
  696. o += '?' + u.query;
  697. // Add anchor
  698. if (u.anchor)
  699. o += '#' + u.anchor;
  700. return o;
  701. },
  702. toAbsolute : function(u, nh) {
  703. var u = new tinymce.util.URI(u, {base_uri : this});
  704. return u.getURI(this.host == u.host && this.protocol == u.protocol ? nh : 0);
  705. },
  706. toRelPath : function(base, path) {
  707. var items, bp = 0, out = '', i, l;
  708. // Split the paths
  709. base = base.substring(0, base.lastIndexOf('/'));
  710. base = base.split('/');
  711. items = path.split('/');
  712. if (base.length >= items.length) {
  713. for (i = 0, l = base.length; i < l; i++) {
  714. if (i >= items.length || base[i] != items[i]) {
  715. bp = i + 1;
  716. break;
  717. }
  718. }
  719. }
  720. if (base.length < items.length) {
  721. for (i = 0, l = items.length; i < l; i++) {
  722. if (i >= base.length || base[i] != items[i]) {
  723. bp = i + 1;
  724. break;
  725. }
  726. }
  727. }
  728. if (bp == 1)
  729. return path;
  730. for (i = 0, l = base.length - (bp - 1); i < l; i++)
  731. out += "../";
  732. for (i = bp - 1, l = items.length; i < l; i++) {
  733. if (i != bp - 1)
  734. out += "/" + items[i];
  735. else
  736. out += items[i];
  737. }
  738. return out;
  739. },
  740. toAbsPath : function(base, path) {
  741. var i, nb = 0, o = [], tr, outPath;
  742. // Split paths
  743. tr = /\/$/.test(path) ? '/' : '';
  744. base = base.split('/');
  745. path = path.split('/');
  746. // Remove empty chunks
  747. each(base, function(k) {
  748. if (k)
  749. o.push(k);
  750. });
  751. base = o;
  752. // Merge relURLParts chunks
  753. for (i = path.length - 1, o = []; i >= 0; i--) {
  754. // Ignore empty or .
  755. if (path[i].length == 0 || path[i] == ".")
  756. continue;
  757. // Is parent
  758. if (path[i] == '..') {
  759. nb++;
  760. continue;
  761. }
  762. // Move up
  763. if (nb > 0) {
  764. nb--;
  765. continue;
  766. }
  767. o.push(path[i]);
  768. }
  769. i = base.length - nb;
  770. // If /a/b/c or /
  771. if (i <= 0)
  772. outPath = o.reverse().join('/');
  773. else
  774. outPath = base.slice(0, i).join('/') + '/' + o.reverse().join('/');
  775. // Add front / if it's needed
  776. if (outPath.indexOf('/') !== 0)
  777. outPath = '/' + outPath;
  778. // Add traling / if it's needed
  779. if (tr && outPath.lastIndexOf('/') !== outPath.length - 1)
  780. outPath += tr;
  781. return outPath;
  782. },
  783. getURI : function(nh) {
  784. var s, t = this;
  785. // Rebuild source
  786. if (!t.source || nh) {
  787. s = '';
  788. if (!nh) {
  789. if (t.protocol)
  790. s += t.protocol + '://';
  791. if (t.userInfo)
  792. s += t.userInfo + '@';
  793. if (t.host)
  794. s += t.host;
  795. if (t.port)
  796. s += ':' + t.port;
  797. }
  798. if (t.path)
  799. s += t.path;
  800. if (t.query)
  801. s += '?' + t.query;
  802. if (t.anchor)
  803. s += '#' + t.anchor;
  804. t.source = s;
  805. }
  806. return t.source;
  807. }
  808. });
  809. })();
  810. (function() {
  811. var each = tinymce.each;
  812. tinymce.create('static tinymce.util.Cookie', {
  813. getHash : function(n) {
  814. var v = this.get(n), h;
  815. if (v) {
  816. each(v.split('&'), function(v) {
  817. v = v.split('=');
  818. h = h || {};
  819. h[unescape(v[0])] = unescape(v[1]);
  820. });
  821. }
  822. return h;
  823. },
  824. setHash : function(n, v, e, p, d, s) {
  825. var o = '';
  826. each(v, function(v, k) {
  827. o += (!o ? '' : '&') + escape(k) + '=' + escape(v);
  828. });
  829. this.set(n, o, e, p, d, s);
  830. },
  831. get : function(n) {
  832. var c = document.cookie, e, p = n + "=", b;
  833. // Strict mode
  834. if (!c)
  835. return;
  836. b = c.indexOf("; " + p);
  837. if (b == -1) {
  838. b = c.indexOf(p);
  839. if (b != 0)
  840. return null;
  841. } else
  842. b += 2;
  843. e = c.indexOf(";", b);
  844. if (e == -1)
  845. e = c.length;
  846. return unescape(c.substring(b + p.length, e));
  847. },
  848. set : function(n, v, e, p, d, s) {
  849. document.cookie = n + "=" + escape(v) +
  850. ((e) ? "; expires=" + e.toGMTString() : "") +
  851. ((p) ? "; path=" + escape(p) : "") +
  852. ((d) ? "; domain=" + d : "") +
  853. ((s) ? "; secure" : "");
  854. },
  855. remove : function(n, p) {
  856. var d = new Date();
  857. d.setTime(d.getTime() - 1000);
  858. this.set(n, '', d, p, d);
  859. }
  860. });
  861. })();
  862. (function() {
  863. function serialize(o, quote) {
  864. var i, v, t;
  865. quote = quote || '"';
  866. if (o == null)
  867. return 'null';
  868. t = typeof o;
  869. if (t == 'string') {
  870. v = '\bb\tt\nn\ff\rr\""\'\'\\\\';
  871. return quote + o.replace(/([\u0080-\uFFFF\x00-\x1f\"\'\\])/g, function(a, b) {
  872. // Make sure single quotes never get encoded inside double quotes for JSON compatibility
  873. if (quote === '"' && a === "'")
  874. return a;
  875. i = v.indexOf(b);
  876. if (i + 1)
  877. return '\\' + v.charAt(i + 1);
  878. a = b.charCodeAt().toString(16);
  879. return '\\u' + '0000'.substring(a.length) + a;
  880. }) + quote;
  881. }
  882. if (t == 'object') {
  883. if (o.hasOwnProperty && o instanceof Array) {
  884. for (i=0, v = '['; i<o.length; i++)
  885. v += (i > 0 ? ',' : '') + serialize(o[i], quote);
  886. return v + ']';
  887. }
  888. v = '{';
  889. for (i in o) {
  890. if (o.hasOwnProperty(i)) {
  891. v += typeof o[i] != 'function' ? (v.length > 1 ? ',' + quote : quote) + i + quote +':' + serialize(o[i], quote) : '';
  892. }
  893. }
  894. return v + '}';
  895. }
  896. return '' + o;
  897. };
  898. tinymce.util.JSON = {
  899. serialize: serialize,
  900. parse: function(s) {
  901. try {
  902. return eval('(' + s + ')');
  903. } catch (ex) {
  904. // Ignore
  905. }
  906. }
  907. };
  908. })();
  909. tinymce.create('static tinymce.util.XHR', {
  910. send : function(o) {
  911. var x, t, w = window, c = 0;
  912. // Default settings
  913. o.scope = o.scope || this;
  914. o.success_scope = o.success_scope || o.scope;
  915. o.error_scope = o.error_scope || o.scope;
  916. o.async = o.async === false ? false : true;
  917. o.data = o.data || '';
  918. function get(s) {
  919. x = 0;
  920. try {
  921. x = new ActiveXObject(s);
  922. } catch (ex) {
  923. }
  924. return x;
  925. };
  926. x = w.XMLHttpRequest ? new XMLHttpRequest() : get('Microsoft.XMLHTTP') || get('Msxml2.XMLHTTP');
  927. if (x) {
  928. if (x.overrideMimeType)
  929. x.overrideMimeType(o.content_type);
  930. x.open(o.type || (o.data ? 'POST' : 'GET'), o.url, o.async);
  931. if (o.content_type)
  932. x.setRequestHeader('Content-Type', o.content_type);
  933. x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  934. x.send(o.data);
  935. function ready() {
  936. if (!o.async || x.readyState == 4 || c++ > 10000) {
  937. if (o.success && c < 10000 && x.status == 200)
  938. o.success.call(o.success_scope, '' + x.responseText, x, o);
  939. else if (o.error)
  940. o.error.call(o.error_scope, c > 10000 ? 'TIMED_OUT' : 'GENERAL', x, o);
  941. x = null;
  942. } else
  943. w.setTimeout(ready, 10);
  944. };
  945. // Syncronous request
  946. if (!o.async)
  947. return ready();
  948. // Wait for response, onReadyStateChange can not be used since it leaks memory in IE
  949. t = w.setTimeout(ready, 10);
  950. }
  951. }
  952. });
  953. (function() {
  954. var extend = tinymce.extend, JSON = tinymce.util.JSON, XHR = tinymce.util.XHR;
  955. tinymce.create('tinymce.util.JSONRequest', {
  956. JSONRequest : function(s) {
  957. this.settings = extend({
  958. }, s);
  959. this.count = 0;
  960. },
  961. send : function(o) {
  962. var ecb = o.error, scb = o.success;
  963. o = extend(this.settings, o);
  964. o.success = function(c, x) {
  965. c = JSON.parse(c);
  966. if (typeof(c) == 'undefined') {
  967. c = {
  968. error : 'JSON Parse error.'
  969. };
  970. }
  971. if (c.error)
  972. ecb.call(o.error_scope || o.scope, c.error, x);
  973. else
  974. scb.call(o.success_scope || o.scope, c.result);
  975. };
  976. o.error = function(ty, x) {
  977. if (ecb)
  978. ecb.call(o.error_scope || o.scope, ty, x);
  979. };
  980. o.data = JSON.serialize({
  981. id : o.id || 'c' + (this.count++),
  982. method : o.method,
  983. params : o.params
  984. });
  985. // JSON content type for Ruby on rails. Bug: #1883287
  986. o.content_type = 'application/json';
  987. XHR.send(o);
  988. },
  989. 'static' : {
  990. sendRPC : function(o) {
  991. return new tinymce.util.JSONRequest().send(o);
  992. }
  993. }
  994. });
  995. }());
  996. (function(tinymce){
  997. tinymce.VK = {
  998. DELETE: 46,
  999. BACKSPACE: 8,
  1000. ENTER: 13,
  1001. TAB: 9,
  1002. SPACEBAR: 32,
  1003. UP: 38,
  1004. DOWN: 40,
  1005. modifierPressed: function (e) {
  1006. return e.shiftKey || e.ctrlKey || e.altKey;
  1007. }
  1008. }
  1009. })(tinymce);
  1010. (function(tinymce) {
  1011. var VK = tinymce.VK, BACKSPACE = VK.BACKSPACE, DELETE = VK.DELETE;
  1012. function cleanupStylesWhenDeleting(ed) {
  1013. var dom = ed.dom, selection = ed.selection;
  1014. ed.onKeyDown.add(function(ed, e) {
  1015. var rng, blockElm, node, clonedSpan, isDelete;
  1016. isDelete = e.keyCode == DELETE;
  1017. if ((isDelete || e.keyCode == BACKSPACE) && !VK.modifierPressed(e)) {
  1018. e.preventDefault();
  1019. rng = selection.getRng();
  1020. // Find root block
  1021. blockElm = dom.getParent(rng.startContainer, dom.isBlock);
  1022. // On delete clone the root span of the next block element
  1023. if (isDelete)
  1024. blockElm = dom.getNext(blockElm, dom.isBlock);
  1025. // Locate root span element and clone it since it would otherwise get merged by the "apple-style-span" on delete/backspace
  1026. if (blockElm) {
  1027. node = blockElm.firstChild;
  1028. // Ignore empty text nodes
  1029. while (node && node.nodeType == 3 && node.nodeValue.length == 0)
  1030. node = node.nextSibling;
  1031. if (node && node.nodeName === 'SPAN') {
  1032. clonedSpan = node.cloneNode(false);
  1033. }
  1034. }
  1035. // Do the backspace/delete actiopn
  1036. ed.getDoc().execCommand(isDelete ? 'ForwardDelete' : 'Delete', false, null);
  1037. // Find all odd apple-style-spans
  1038. blockElm = dom.getParent(rng.startContainer, dom.isBlock);
  1039. tinymce.each(dom.select('span.Apple-style-span,font.Apple-style-span', blockElm), function(span) {
  1040. var bm = selection.getBookmark();
  1041. if (clonedSpan) {
  1042. dom.replace(clonedSpan.cloneNode(false), span, true);
  1043. } else {
  1044. dom.remove(span, true);
  1045. }
  1046. // Restore the selection
  1047. selection.moveToBookmark(bm);
  1048. });
  1049. }
  1050. });
  1051. };
  1052. function emptyEditorWhenDeleting(ed) {
  1053. ed.onKeyUp.add(function(ed, e) {
  1054. var keyCode = e.keyCode;
  1055. if (keyCode == DELETE || keyCode == BACKSPACE) {
  1056. if (ed.dom.isEmpty(ed.getBody())) {
  1057. ed.setContent('', {format : 'raw'});
  1058. ed.nodeChanged();
  1059. return;
  1060. }
  1061. }
  1062. });
  1063. };
  1064. function inputMethodFocus(ed) {
  1065. ed.dom.bind(ed.getDoc(), 'focusin', function() {
  1066. ed.selection.setRng(ed.selection.getRng());
  1067. });
  1068. };
  1069. function removeHrOnBackspace(ed) {
  1070. ed.onKeyDown.add(function(ed, e) {
  1071. if (e.keyCode === BACKSPACE) {
  1072. if (ed.selection.isCollapsed() && ed.selection.getRng(true).startOffset === 0) {
  1073. var node = ed.selection.getNode();
  1074. var previousSibling = node.previousSibling;
  1075. if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === "hr") {
  1076. ed.dom.remove(previousSibling);
  1077. tinymce.dom.Event.cancel(e);
  1078. }
  1079. }
  1080. }
  1081. })
  1082. }
  1083. function focusBody(ed) {
  1084. // Fix for a focus bug in FF 3.x where the body element
  1085. // wouldn't get proper focus if the user clicked on the HTML element
  1086. if (!Range.prototype.getClientRects) { // Detect getClientRects got introduced in FF 4
  1087. ed.onMouseDown.add(function(ed, e) {
  1088. if (e.target.nodeName === "HTML") {
  1089. var body = ed.getBody();
  1090. // Blur the body it's focused but not correctly focused
  1091. body.blur();
  1092. // Refocus the body after a little while
  1093. setTimeout(function() {
  1094. body.focus();
  1095. }, 0);
  1096. }
  1097. });
  1098. }
  1099. };
  1100. function selectControlElements(ed) {
  1101. ed.onClick.add(function(ed, e) {
  1102. e = e.target;
  1103. // Workaround for bug, http://bugs.webkit.org/show_bug.cgi?id=12250
  1104. // WebKit can't even do simple things like selecting an image
  1105. // Needs tobe the setBaseAndExtend or it will fail to select floated images
  1106. if (/^(IMG|HR)$/.test(e.nodeName))
  1107. ed.selection.getSel().setBaseAndExtent(e, 0, e, 1);
  1108. if (e.nodeName == 'A' && ed.dom.hasClass(e, 'mceItemAnchor'))
  1109. ed.selection.select(e);
  1110. ed.nodeChanged();
  1111. });
  1112. };
  1113. function removeStylesOnPTagsInheritedFromHeadingTag(ed) {
  1114. ed.onKeyDown.add(function(ed, event) {
  1115. function checkInHeadingTag(ed) {
  1116. var currentNode = ed.selection.getNode();
  1117. var headingTags = 'h1,h2,h3,h4,h5,h6';
  1118. return ed.dom.is(currentNode, headingTags) || ed.dom.getParent(currentNode, headingTags) !== null;
  1119. }
  1120. if (event.keyCode === VK.ENTER && !VK.modifierPressed(event) && checkInHeadingTag(ed)) {
  1121. setTimeout(function() {
  1122. var currentNode = ed.selection.getNode();
  1123. if (ed.dom.is(currentNode, 'p')) {
  1124. ed.dom.setAttrib(currentNode, 'style', null);
  1125. // While tiny's content is correct after this method call, the content shown is not representative of it and needs to be 'repainted'
  1126. ed.execCommand('mceCleanup');
  1127. }
  1128. }, 0);
  1129. }
  1130. });
  1131. }
  1132. function selectionChangeNodeChanged(ed) {
  1133. var lastRng, selectionTimer;
  1134. ed.dom.bind(ed.getDoc(), 'selectionchange', function() {
  1135. if (selectionTimer) {
  1136. clearTimeout(selectionTimer);
  1137. selectionTimer = 0;
  1138. }
  1139. selectionTimer = window.setTimeout(function() {
  1140. var rng = ed.selection.getRng();
  1141. // Compare the ranges to see if it was a real change or not
  1142. if (!lastRng || !tinymce.dom.RangeUtils.compareRanges(rng, lastRng)) {
  1143. ed.nodeChanged();
  1144. lastRng = rng;
  1145. }
  1146. }, 50);
  1147. });
  1148. }
  1149. function ensureBodyHasRoleApplication(ed) {
  1150. document.body.setAttribute("role", "application");
  1151. }
  1152. tinymce.create('tinymce.util.Quirks', {
  1153. Quirks: function(ed) {
  1154. // WebKit
  1155. if (tinymce.isWebKit) {
  1156. cleanupStylesWhenDeleting(ed);
  1157. emptyEditorWhenDeleting(ed);
  1158. inputMethodFocus(ed);
  1159. selectControlElements(ed);
  1160. // iOS
  1161. if (tinymce.isIDevice) {
  1162. selectionChangeNodeChanged(ed);
  1163. }
  1164. }
  1165. // IE
  1166. if (tinymce.isIE) {
  1167. removeHrOnBackspace(ed);
  1168. emptyEditorWhenDeleting(ed);
  1169. ensureBodyHasRoleApplication(ed);
  1170. removeStylesOnPTagsInheritedFromHeadingTag(ed)
  1171. }
  1172. // Gecko
  1173. if (tinymce.isGecko) {
  1174. removeHrOnBackspace(ed);
  1175. focusBody(ed);
  1176. }
  1177. }
  1178. });
  1179. })(tinymce);
  1180. (function(tinymce) {
  1181. var namedEntities, baseEntities, reverseEntities,
  1182. attrsCharsRegExp = /[&<>\"\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  1183. textCharsRegExp = /[<>&\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  1184. rawCharsRegExp = /[<>&\"\']/g,
  1185. entityRegExp = /&(#x|#)?([\w]+);/g,
  1186. asciiMap = {
  1187. 128 : "\u20AC", 130 : "\u201A", 131 : "\u0192", 132 : "\u201E", 133 : "\u2026", 134 : "\u2020",
  1188. 135 : "\u2021", 136 : "\u02C6", 137 : "\u2030", 138 : "\u0160", 139 : "\u2039", 140 : "\u0152",
  1189. 142 : "\u017D", 145 : "\u2018", 146 : "\u2019", 147 : "\u201C", 148 : "\u201D", 149 : "\u2022",
  1190. 150 : "\u2013", 151 : "\u2014", 152 : "\u02DC", 153 : "\u2122", 154 : "\u0161", 155 : "\u203A",
  1191. 156 : "\u0153", 158 : "\u017E", 159 : "\u0178"
  1192. };
  1193. // Raw entities
  1194. baseEntities = {
  1195. '\"' : '&quot;', // Needs to be escaped since the YUI compressor would otherwise break the code
  1196. "'" : '&#39;',
  1197. '<' : '&lt;',
  1198. '>' : '&gt;',
  1199. '&' : '&amp;'
  1200. };
  1201. // Reverse lookup table for raw entities
  1202. reverseEntities = {
  1203. '&lt;' : '<',
  1204. '&gt;' : '>',
  1205. '&amp;' : '&',
  1206. '&quot;' : '"',
  1207. '&apos;' : "'"
  1208. };
  1209. // Decodes text by using the browser
  1210. function nativeDecode(text) {
  1211. var elm;
  1212. elm = document.createElement("div");
  1213. elm.innerHTML = text;
  1214. return elm.textContent || elm.innerText || text;
  1215. };
  1216. // Build a two way lookup table for the entities
  1217. function buildEntitiesLookup(items, radix) {
  1218. var i, chr, entity, lookup = {};
  1219. if (items) {
  1220. items = items.split(',');
  1221. radix = radix || 10;
  1222. // Build entities lookup table
  1223. for (i = 0; i < items.length; i += 2) {
  1224. chr = String.fromCharCode(parseInt(items[i], radix));
  1225. // Only add non base entities
  1226. if (!baseEntities[chr]) {
  1227. entity = '&' + items[i + 1] + ';';
  1228. lookup[chr] = entity;
  1229. lookup[entity] = chr;
  1230. }
  1231. }
  1232. return lookup;
  1233. }
  1234. };
  1235. // Unpack entities lookup where the numbers are in radix 32 to reduce the size
  1236. namedEntities = buildEntitiesLookup(
  1237. '50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,' +
  1238. '5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,' +
  1239. '5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,' +
  1240. '5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,' +
  1241. '68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,' +
  1242. '6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,' +
  1243. '6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,' +
  1244. '75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,' +
  1245. '7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,' +
  1246. '7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,' +
  1247. 'sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,' +
  1248. 'st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,' +
  1249. 't9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,' +
  1250. 'tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,' +
  1251. 'u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,' +
  1252. '81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,' +
  1253. '8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,' +
  1254. '8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,' +
  1255. '8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,' +
  1256. '8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,' +
  1257. 'nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,' +
  1258. 'rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,' +
  1259. 'Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,' +
  1260. '80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,' +
  1261. '811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro'
  1262. , 32);
  1263. tinymce.html = tinymce.html || {};
  1264. tinymce.html.Entities = {
  1265. encodeRaw : function(text, attr) {
  1266. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1267. return baseEntities[chr] || chr;
  1268. });
  1269. },
  1270. encodeAllRaw : function(text) {
  1271. return ('' + text).replace(rawCharsRegExp, function(chr) {
  1272. return baseEntities[chr] || chr;
  1273. });
  1274. },
  1275. encodeNumeric : function(text, attr) {
  1276. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1277. // Multi byte sequence convert it to a single entity
  1278. if (chr.length > 1)
  1279. return '&#' + (((chr.charCodeAt(0) - 0xD800) * 0x400) + (chr.charCodeAt(1) - 0xDC00) + 0x10000) + ';';
  1280. return baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';';
  1281. });
  1282. },
  1283. encodeNamed : function(text, attr, entities) {
  1284. entities = entities || namedEntities;
  1285. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1286. return baseEntities[chr] || entities[chr] || chr;
  1287. });
  1288. },
  1289. getEncodeFunc : function(name, entities) {
  1290. var Entities = tinymce.html.Entities;
  1291. entities = buildEntitiesLookup(entities) || namedEntities;
  1292. function encodeNamedAndNumeric(text, attr) {
  1293. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1294. return baseEntities[chr] || entities[chr] || '&#' + chr.charCodeAt(0) + ';' || chr;
  1295. });
  1296. };
  1297. function encodeCustomNamed(text, attr) {
  1298. return Entities.encodeNamed(text, attr, entities);
  1299. };
  1300. // Replace + with , to be compatible with previous TinyMCE versions
  1301. name = tinymce.makeMap(name.replace(/\+/g, ','));
  1302. // Named and numeric encoder
  1303. if (name.named && name.numeric)
  1304. return encodeNamedAndNumeric;
  1305. // Named encoder
  1306. if (name.named) {
  1307. // Custom names
  1308. if (entities)
  1309. return encodeCustomNamed;
  1310. return Entities.encodeNamed;
  1311. }
  1312. // Numeric
  1313. if (name.numeric)
  1314. return Entities.encodeNumeric;
  1315. // Raw encoder
  1316. return Entities.encodeRaw;
  1317. },
  1318. decode : function(text) {
  1319. return text.replace(entityRegExp, function(all, numeric, value) {
  1320. if (numeric) {
  1321. value = parseInt(value, numeric.length === 2 ? 16 : 10);
  1322. // Support upper UTF
  1323. if (value > 0xFFFF) {
  1324. value -= 0x10000;
  1325. return String.fromCharCode(0xD800 + (value >> 10), 0xDC00 + (value & 0x3FF));
  1326. } else
  1327. return asciiMap[value] || String.fromCharCode(value);
  1328. }
  1329. return reverseEntities[all] || namedEntities[all] || nativeDecode(all);
  1330. });
  1331. }
  1332. };
  1333. })(tinymce);
  1334. tinymce.html.Styles = function(settings, schema) {
  1335. var rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi,
  1336. urlOrStrRegExp = /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi,
  1337. styleRegExp = /\s*([^:]+):\s*([^;]+);?/g,
  1338. trimRightRegExp = /\s+$/,
  1339. urlColorRegExp = /rgb/,
  1340. undef, i, encodingLookup = {}, encodingItems;
  1341. settings = settings || {};
  1342. encodingItems = '\\" \\\' \\; \\: ; : \uFEFF'.split(' ');
  1343. for (i = 0; i < encodingItems.length; i++) {
  1344. encodingLookup[encodingItems[i]] = '\uFEFF' + i;
  1345. encodingLookup['\uFEFF' + i] = encodingItems[i];
  1346. }
  1347. function toHex(match, r, g, b) {
  1348. function hex(val) {
  1349. val = parseInt(val).toString(16);
  1350. return val.length > 1 ? val : '0' + val; // 0 -> 00
  1351. };
  1352. return '#' + hex(r) + hex(g) + hex(b);
  1353. };
  1354. return {
  1355. toHex : function(color) {
  1356. return color.replace(rgbRegExp, toHex);
  1357. },
  1358. parse : function(css) {
  1359. var styles = {}, matches, name, value, isEncoded, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope || this;
  1360. function compress(prefix, suffix) {
  1361. var top, right, bottom, left;
  1362. // Get values and check it it needs compressing
  1363. top = styles[prefix + '-top' + suffix];
  1364. if (!top)
  1365. return;
  1366. right = styles[prefix + '-right' + suffix];
  1367. if (top != right)
  1368. return;
  1369. bottom = styles[prefix + '-bottom' + suffix];
  1370. if (right != bottom)
  1371. return;
  1372. left = styles[prefix + '-left' + suffix];
  1373. if (bottom != left)
  1374. return;
  1375. // Compress
  1376. styles[prefix + suffix] = left;
  1377. delete styles[prefix + '-top' + suffix];
  1378. delete styles[prefix + '-right' + suffix];
  1379. delete styles[prefix + '-bottom' + suffix];
  1380. delete styles[prefix + '-left' + suffix];
  1381. };
  1382. function canCompress(key) {
  1383. var value = styles[key], i;
  1384. if (!value || value.indexOf(' ') < 0)
  1385. return;
  1386. value = value.split(' ');
  1387. i = value.length;
  1388. while (i--) {
  1389. if (value[i] !== value[0])
  1390. return false;
  1391. }
  1392. styles[key] = value[0];
  1393. return true;
  1394. };
  1395. function compress2(target, a, b, c) {
  1396. if (!canCompress(a))
  1397. return;
  1398. if (!canCompress(b))
  1399. return;
  1400. if (!canCompress(c))
  1401. return;
  1402. // Compress
  1403. styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c];
  1404. delete styles[a];
  1405. delete styles[b];
  1406. delete styles[c];
  1407. };
  1408. // Encodes the specified string by replacing all \" \' ; : with _<num>
  1409. function encode(str) {
  1410. isEncoded = true;
  1411. return encodingLookup[str];
  1412. };
  1413. // Decodes the specified string by replacing all _<num> with it's original value \" \' etc
  1414. // It will also decode the \" \' if keep_slashes is set to fale or omitted
  1415. function decode(str, keep_slashes) {
  1416. if (isEncoded) {
  1417. str = str.replace(/\uFEFF[0-9]/g, function(str) {
  1418. return encodingLookup[str];
  1419. });
  1420. }
  1421. if (!keep_slashes)
  1422. str = str.replace(/\\([\'\";:])/g, "$1");
  1423. return str;
  1424. }
  1425. if (css) {
  1426. // Encode \" \' % and ; and : inside strings so they don't interfere with the style parsing
  1427. css = css.replace(/\\[\"\';:\uFEFF]/g, encode).replace(/\"[^\"]+\"|\'[^\']+\'/g, function(str) {
  1428. return str.replace(/[;:]/g, encode);
  1429. });
  1430. // Parse styles
  1431. while (matches = styleRegExp.exec(css)) {
  1432. name = matches[1].replace(trimRightRegExp, '').toLowerCase();
  1433. value = matches[2].replace(trimRightRegExp, '');
  1434. if (name && value.length > 0) {
  1435. // Opera will produce 700 instead of bold in their style values
  1436. if (name === 'font-weight' && value === '700')
  1437. value = 'bold';
  1438. else if (name === 'color' || name === 'background-color') // Lowercase colors like RED
  1439. value = value.toLowerCase();
  1440. // Convert RGB colors to HEX
  1441. value = value.replace(rgbRegExp, toHex);
  1442. // Convert URLs and force them into url('value') format
  1443. value = value.replace(urlOrStrRegExp, function(match, url, url2, url3, str, str2) {
  1444. str = str || str2;
  1445. if (str) {
  1446. str = decode(str);
  1447. // Force strings into single quote format
  1448. return "'" + str.replace(/\'/g, "\\'") + "'";
  1449. }
  1450. url = decode(url || url2 || url3);
  1451. // Convert the URL to relative/absolute depending on config
  1452. if (urlConverter)
  1453. url = urlConverter.call(urlConverterScope, url, 'style');
  1454. // Output new URL format
  1455. return "url('" + url.replace(/\'/g, "\\'") + "')";
  1456. });
  1457. styles[name] = isEncoded ? decode(value, true) : value;
  1458. }
  1459. styleRegExp.lastIndex = matches.index + matches[0].length;
  1460. }
  1461. // Compress the styles to reduce it's size for example IE will expand styles
  1462. compress("border", "");
  1463. compress("border", "-width");
  1464. compress("border", "-color");
  1465. compress("border", "-style");
  1466. compress("padding", "");
  1467. compress("margin", "");
  1468. compress2('border', 'border-width', 'border-style', 'border-color');
  1469. // Remove pointless border, IE produces these
  1470. if (styles.border === 'medium none')
  1471. delete styles.border;
  1472. }
  1473. return styles;
  1474. },
  1475. serialize : function(styles, element_name) {
  1476. var css = '', name, value;
  1477. function serializeStyles(name) {
  1478. var styleList, i, l, value;
  1479. styleList = schema.styles[name];
  1480. if (styleList) {
  1481. for (i = 0, l = styleList.length; i < l; i++) {
  1482. name = styleList[i];
  1483. value = styles[name];
  1484. if (value !== undef && value.length > 0)
  1485. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  1486. }
  1487. }
  1488. };
  1489. // Serialize styles according to schema
  1490. if (element_name && schema && schema.styles) {
  1491. // Serialize global styles and element specific styles
  1492. serializeStyles('*');
  1493. serializeStyles(element_name);
  1494. } else {
  1495. // Output the styles in the order they are inside the object
  1496. for (name in styles) {
  1497. value = styles[name];
  1498. if (value !== undef && value.length > 0)
  1499. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  1500. }
  1501. }
  1502. return css;
  1503. }
  1504. };
  1505. };
  1506. (function(tinymce) {
  1507. var transitional = {}, boolAttrMap, blockElementsMap, shortEndedElementsMap, nonEmptyElementsMap, customElementsMap = {},
  1508. defaultWhiteSpaceElementsMap, selfClosingElementsMap, makeMap = tinymce.makeMap, each = tinymce.each;
  1509. function split(str, delim) {
  1510. return str.split(delim || ',');
  1511. };
  1512. function unpack(lookup, data) {
  1513. var key, elements = {};
  1514. function replace(value) {
  1515. return value.replace(/[A-Z]+/g, function(key) {
  1516. return replace(lookup[key]);
  1517. });
  1518. };
  1519. // Unpack lookup
  1520. for (key in lookup) {
  1521. if (lookup.hasOwnProperty(key))
  1522. lookup[key] = replace(lookup[key]);
  1523. }
  1524. // Unpack and parse data into object map
  1525. replace(data).replace(/#/g, '#text').replace(/(\w+)\[([^\]]+)\]\[([^\]]*)\]/g, function(str, name, attributes, children) {
  1526. attributes = split(attributes, '|');
  1527. elements[name] = {
  1528. attributes : makeMap(attributes),
  1529. attributesOrder : attributes,
  1530. children : makeMap(children, '|', {'#comment' : {}})
  1531. }
  1532. });
  1533. return elements;
  1534. };
  1535. // Build a lookup table for block elements both lowercase and uppercase
  1536. blockElementsMap = 'h1,h2,h3,h4,h5,h6,hr,p,div,address,pre,form,table,tbody,thead,tfoot,' +
  1537. 'th,tr,td,li,ol,ul,caption,blockquote,center,dl,dt,dd,dir,fieldset,' +
  1538. 'noscript,menu,isindex,samp,header,footer,article,section,hgroup';
  1539. blockElementsMap = makeMap(blockElementsMap, ',', makeMap(blockElementsMap.toUpperCase()));
  1540. // This is the XHTML 1.0 transitional elements with it's attributes and children packed to reduce it's size
  1541. transitional = unpack({
  1542. Z : 'H|K|N|O|P',
  1543. Y : 'X|form|R|Q',
  1544. ZG : 'E|span|width|align|char|charoff|valign',
  1545. X : 'p|T|div|U|W|isindex|fieldset|table',
  1546. ZF : 'E|align|char|charoff|valign',
  1547. W : 'pre|hr|blockquote|address|center|noframes',
  1548. ZE : 'abbr|axis|headers|scope|rowspan|colspan|align|char|charoff|valign|nowrap|bgcolor|width|height',
  1549. ZD : '[E][S]',
  1550. U : 'ul|ol|dl|menu|dir',
  1551. ZC : 'p|Y|div|U|W|table|br|span|bdo|object|applet|img|map|K|N|Q',
  1552. T : 'h1|h2|h3|h4|h5|h6',
  1553. ZB : 'X|S|Q',
  1554. S : 'R|P',
  1555. ZA : 'a|G|J|M|O|P',
  1556. R : 'a|H|K|N|O',
  1557. Q : 'noscript|P',
  1558. P : 'ins|del|script',
  1559. O : 'input|select|textarea|label|button',
  1560. N : 'M|L',
  1561. M : 'em|strong|dfn|code|q|samp|kbd|var|cite|abbr|acronym',
  1562. L : 'sub|sup',
  1563. K : 'J|I',
  1564. J : 'tt|i|b|u|s|strike',
  1565. I : 'big|small|font|basefont',
  1566. H : 'G|F',
  1567. G : 'br|span|bdo',
  1568. F : 'object|applet|img|map|iframe',
  1569. E : 'A|B|C',
  1570. D : 'accesskey|tabindex|onfocus|onblur',
  1571. C : 'onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup',
  1572. B : 'lang|xml:lang|dir',
  1573. A : 'id|class|style|title'
  1574. }, 'script[id|charset|type|language|src|defer|xml:space][]' +
  1575. 'style[B|id|type|media|title|xml:space][]' +
  1576. 'object[E|declare|classid|codebase|data|type|codetype|archive|standby|width|height|usemap|name|tabindex|align|border|hspace|vspace][#|param|Y]' +
  1577. 'param[id|name|value|valuetype|type][]' +
  1578. 'p[E|align][#|S]' +
  1579. 'a[E|D|charset|type|name|href|hreflang|rel|rev|shape|coords|target][#|Z]' +
  1580. 'br[A|clear][]' +
  1581. 'span[E][#|S]' +
  1582. 'bdo[A|C|B][#|S]' +
  1583. 'applet[A|codebase|archive|code|object|alt|name|width|height|align|hspace|vspace][#|param|Y]' +
  1584. 'h1[E|align][#|S]' +
  1585. 'img[E|src|alt|name|longdesc|width|height|usemap|ismap|align|border|hspace|vspace][]' +
  1586. 'map[B|C|A|name][X|form|Q|area]' +
  1587. 'h2[E|align][#|S]' +
  1588. 'iframe[A|longdesc|name|src|frameborder|marginwidth|marginheight|scrolling|align|width|height][#|Y]' +
  1589. 'h3[E|align][#|S]' +
  1590. 'tt[E][#|S]' +
  1591. 'i[E][#|S]' +
  1592. 'b[E][#|S]' +
  1593. 'u[E][#|S]' +
  1594. 's[E][#|S]' +
  1595. 'strike[E][#|S]' +
  1596. 'big[E][#|S]' +
  1597. 'small[E][#|S]' +
  1598. 'font[A|B|size|color|face][#|S]' +
  1599. 'basefont[id|size|color|face][]' +
  1600. 'em[E][#|S]' +
  1601. 'strong[E][#|S]' +
  1602. 'dfn[E][#|S]' +
  1603. 'code[E][#|S]' +
  1604. 'q[E|cite][#|S]' +
  1605. 'samp[E][#|S]' +
  1606. 'kbd[E][#|S]' +
  1607. 'var[E][#|S]' +
  1608. 'cite[E][#|S]' +
  1609. 'abbr[E][#|S]' +
  1610. 'acronym[E][#|S]' +
  1611. 'sub[E][#|S]' +
  1612. 'sup[E][#|S]' +
  1613. 'input[E|D|type|name|value|checked|disabled|readonly|size|maxlength|src|alt|usemap|onselect|onchange|accept|align][]' +
  1614. 'select[E|name|size|multiple|disabled|tabindex|onfocus|onblur|onchange][optgroup|option]' +
  1615. 'optgroup[E|disabled|label][option]' +
  1616. 'option[E|selected|disabled|label|value][]' +
  1617. 'textarea[E|D|name|rows|cols|disabled|readonly|onselect|onchange][]' +
  1618. 'label[E|for|accesskey|onfocus|onblur][#|S]' +
  1619. 'button[E|D|name|value|type|disabled][#|p|T|div|U|W|table|G|object|applet|img|map|K|N|Q]' +
  1620. 'h4[E|align][#|S]' +
  1621. 'ins[E|cite|datetime][#|Y]' +
  1622. 'h5[E|align][#|S]' +
  1623. 'del[E|cite|datetime][#|Y]' +
  1624. 'h6[E|align][#|S]' +
  1625. 'div[E|align][#|Y]' +
  1626. 'ul[E|type|compact][li]' +
  1627. 'li[E|type|value][#|Y]' +
  1628. 'ol[E|type|compact|start][li]' +
  1629. 'dl[E|compact][dt|dd]' +
  1630. 'dt[E][#|S]' +
  1631. 'dd[E][#|Y]' +
  1632. 'menu[E|compact][li]' +
  1633. 'dir[E|compact][li]' +
  1634. 'pre[E|width|xml:space][#|ZA]' +
  1635. 'hr[E|align|noshade|size|width][]' +
  1636. 'blockquote[E|cite][#|Y]' +
  1637. 'address[E][#|S|p]' +
  1638. 'center[E][#|Y]' +
  1639. 'noframes[E][#|Y]' +
  1640. 'isindex[A|B|prompt][]' +
  1641. 'fieldset[E][#|legend|Y]' +
  1642. 'legend[E|accesskey|align][#|S]' +
  1643. 'table[E|summary|width|border|frame|rules|cellspacing|cellpadding|align|bgcolor][caption|col|colgroup|thead|tfoot|tbody|tr]' +
  1644. 'caption[E|align][#|S]' +
  1645. 'col[ZG][]' +
  1646. 'colgroup[ZG][col]' +
  1647. 'thead[ZF][tr]' +
  1648. 'tr[ZF|bgcolor][th|td]' +
  1649. 'th[E|ZE][#|Y]' +
  1650. 'form[E|action|method|name|enctype|onsubmit|onreset|accept|accept-charset|target][#|X|R|Q]' +
  1651. 'noscript[E][#|Y]' +
  1652. 'td[E|ZE][#|Y]' +
  1653. 'tfoot[ZF][tr]' +
  1654. 'tbody[ZF][tr]' +
  1655. 'area[E|D|shape|coords|href|nohref|alt|target][]' +
  1656. 'base[id|href|target][]' +
  1657. 'body[E|onload|onunload|background|bgcolor|text|link|vlink|alink][#|Y]'
  1658. );
  1659. boolAttrMap = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected,autoplay,loop,controls');
  1660. shortEndedElementsMap = makeMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed,source');
  1661. nonEmptyElementsMap = tinymce.extend(makeMap('td,th,iframe,video,audio,object'), shortEndedElementsMap);
  1662. defaultWhiteSpaceElementsMap = makeMap('pre,script,style,textarea');
  1663. selfClosingElementsMap = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr');
  1664. tinymce.html.Schema = function(settings) {
  1665. var self = this, elements = {}, children = {}, patternElements = [], validStyles, whiteSpaceElementsMap;
  1666. settings = settings || {};
  1667. // Allow all elements and attributes if verify_html is set to false
  1668. if (settings.verify_html === false)
  1669. settings.valid_elements = '*[*]';
  1670. // Build styles list
  1671. if (settings.valid_styles) {
  1672. validStyles = {};
  1673. // Convert styles into a rule list
  1674. each(settings.valid_styles, function(value, key) {
  1675. validStyles[key] = tinymce.explode(value);
  1676. });
  1677. }
  1678. whiteSpaceElementsMap = settings.whitespace_elements ? makeMap(settings.whitespace_elements) : defaultWhiteSpaceElementsMap;
  1679. // Converts a wildcard expression string to a regexp for example *a will become /.*a/.
  1680. function patternToRegExp(str) {
  1681. return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$');
  1682. };
  1683. // Parses the specified valid_elements string and adds to the current rules
  1684. // This function is a bit hard to read since it's heavily optimized for speed
  1685. function addValidElements(valid_elements) {
  1686. var ei, el, ai, al, yl, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder,
  1687. prefix, outputName, globalAttributes, globalAttributesOrder, transElement, key, childKey, value,
  1688. elementRuleRegExp = /^([#+-])?([^\[\/]+)(?:\/([^\[]+))?(?:\[([^\]]+)\])?$/,
  1689. attrRuleRegExp = /^([!\-])?(\w+::\w+|[^=:<]+)?(?:([=:<])(.*))?$/,
  1690. hasPatternsRegExp = /[*?+]/;
  1691. if (valid_elements) {
  1692. // Split valid elements into an array with rules
  1693. valid_elements = split(valid_elements);
  1694. if (elements['@']) {
  1695. globalAttributes = elements['@'].attributes;
  1696. globalAttributesOrder = elements['@'].attributesOrder;
  1697. }
  1698. // Loop all rules
  1699. for (ei = 0, el = valid_elements.length; ei < el; ei++) {
  1700. // Parse element rule
  1701. matches = elementRuleRegExp.exec(valid_elements[ei]);
  1702. if (matches) {
  1703. // Setup local names for matches
  1704. prefix = matches[1];
  1705. elementName = matches[2];
  1706. outputName = matches[3];
  1707. attrData = matches[4];
  1708. // Create new attributes and attributesOrder
  1709. attributes = {};
  1710. attributesOrder = [];
  1711. // Create the new element
  1712. element = {
  1713. attributes : attributes,
  1714. attributesOrder : attributesOrder
  1715. };
  1716. // Padd empty elements prefix
  1717. if (prefix === '#')
  1718. element.paddEmpty = true;
  1719. // Remove empty elements prefix
  1720. if (prefix === '-')
  1721. element.removeEmpty = true;
  1722. // Copy attributes from global rule into current rule
  1723. if (globalAttributes) {
  1724. for (key in globalAttributes)
  1725. attributes[key] = globalAttributes[key];
  1726. attributesOrder.push.apply(attributesOrder, globalAttributesOrder);
  1727. }
  1728. // Attributes defined
  1729. if (attrData) {
  1730. attrData = split(attrData, '|');
  1731. for (ai = 0, al = attrData.length; ai < al; ai++) {
  1732. matches = attrRuleRegExp.exec(attrData[ai]);
  1733. if (matches) {
  1734. attr = {};
  1735. attrType = matches[1];
  1736. attrName = matches[2].replace(/::/g, ':');
  1737. prefix = matches[3];
  1738. value = matches[4];
  1739. // Required
  1740. if (attrType === '!') {
  1741. element.attributesRequired = element.attributesRequired || [];
  1742. element.attributesRequired.push(attrName);
  1743. attr.required = true;
  1744. }
  1745. // Denied from global
  1746. if (attrType === '-') {
  1747. delete attributes[attrName];
  1748. attributesOrder.splice(tinymce.inArray(attributesOrder, attrName), 1);
  1749. continue;
  1750. }
  1751. // Default value
  1752. if (prefix) {
  1753. // Default value
  1754. if (prefix === '=') {
  1755. element.attributesDefault = element.attributesDefault || [];
  1756. element.attributesDefault.push({name: attrName, value: value});
  1757. attr.defaultValue = value;
  1758. }
  1759. // Forced value
  1760. if (prefix === ':') {
  1761. element.attributesForced = element.attributesForced || [];
  1762. element.attributesForced.push({name: attrName, value: value});
  1763. attr.forcedValue = value;
  1764. }
  1765. // Required values
  1766. if (prefix === '<')
  1767. attr.validValues = makeMap(value, '?');
  1768. }
  1769. // Check for attribute patterns
  1770. if (hasPatternsRegExp.test(attrName)) {
  1771. element.attributePatterns = element.attributePatterns || [];
  1772. attr.pattern = patternToRegExp(attrName);
  1773. element.attributePatterns.push(attr);
  1774. } else {
  1775. // Add attribute to order list if it doesn't already exist
  1776. if (!attributes[attrName])
  1777. attributesOrder.push(attrName);
  1778. attributes[attrName] = attr;
  1779. }
  1780. }
  1781. }
  1782. }
  1783. // Global rule, store away these for later usage
  1784. if (!globalAttributes && elementName == '@') {
  1785. globalAttributes = attributes;
  1786. globalAttributesOrder = attributesOrder;
  1787. }
  1788. // Handle substitute elements such as b/strong
  1789. if (outputName) {
  1790. element.outputName = elementName;
  1791. elements[outputName] = element;
  1792. }
  1793. // Add pattern or exact element
  1794. if (hasPatternsRegExp.test(elementName)) {
  1795. element.pattern = patternToRegExp(elementName);
  1796. patternElements.push(element);
  1797. } else
  1798. elements[elementName] = element;
  1799. }
  1800. }
  1801. }
  1802. };
  1803. function setValidElements(valid_elements) {
  1804. elements = {};
  1805. patternElements = [];
  1806. addValidElements(valid_elements);
  1807. each(transitional, function(element, name) {
  1808. children[name] = element.children;
  1809. });
  1810. };
  1811. // Adds custom non HTML elements to the schema
  1812. function addCustomElements(custom_elements) {
  1813. var customElementRegExp = /^(~)?(.+)$/;
  1814. if (custom_elements) {
  1815. each(split(custom_elements), function(rule) {
  1816. var matches = customElementRegExp.exec(rule),
  1817. inline = matches[1] === '~',
  1818. cloneName = inline ? 'span' : 'div',
  1819. name = matches[2];
  1820. children[name] = children[cloneName];
  1821. customElementsMap[name] = cloneName;
  1822. // If it's not marked as inline then add it to valid block elements
  1823. if (!inline)
  1824. blockElementsMap[name] = {};
  1825. // Add custom elements at span/div positions
  1826. each(children, function(element, child) {
  1827. if (element[cloneName])
  1828. element[name] = element[cloneName];
  1829. });
  1830. });
  1831. }
  1832. };
  1833. // Adds valid children to the schema object
  1834. function addValidChildren(valid_children) {
  1835. var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/;
  1836. if (valid_children) {
  1837. each(split(valid_children), function(rule) {
  1838. var matches = childRuleRegExp.exec(rule), parent, prefix;
  1839. if (matches) {
  1840. prefix = matches[1];
  1841. // Add/remove items from default
  1842. if (prefix)
  1843. parent = children[matches[2]];
  1844. else
  1845. parent = children[matches[2]] = {'#comment' : {}};
  1846. parent = children[matches[2]];
  1847. each(split(matches[3], '|'), function(child) {
  1848. if (prefix === '-')
  1849. delete parent[child];
  1850. else
  1851. parent[child] = {};
  1852. });
  1853. }
  1854. });
  1855. }
  1856. };
  1857. function getElementRule(name) {
  1858. var element = elements[name], i;
  1859. // Exact match found
  1860. if (element)
  1861. return element;
  1862. // No exact match then try the patterns
  1863. i = patternElements.length;
  1864. while (i--) {
  1865. element = patternElements[i];
  1866. if (element.pattern.test(name))
  1867. return element;
  1868. }
  1869. };
  1870. if (!settings.valid_elements) {
  1871. // No valid elements defined then clone the elements from the transitional spec
  1872. each(transitional, function(element, name) {
  1873. elements[name] = {
  1874. attributes : element.attributes,
  1875. attributesOrder : element.attributesOrder
  1876. };
  1877. children[name] = element.children;
  1878. });
  1879. // Switch these
  1880. each(split('strong/b,em/i'), function(item) {
  1881. item = split(item, '/');
  1882. elements[item[1]].outputName = item[0];
  1883. });
  1884. // Add default alt attribute for images
  1885. elements.img.attributesDefault = [{name: 'alt', value: ''}];
  1886. // Remove these if they are empty by default
  1887. each(split('ol,ul,sub,sup,blockquote,span,font,a,table,tbody,tr'), function(name) {
  1888. elements[name].removeEmpty = true;
  1889. });
  1890. // Padd these by default
  1891. each(split('p,h1,h2,h3,h4,h5,h6,th,td,pre,div,address,caption'), function(name) {
  1892. elements[name].paddEmpty = true;
  1893. });
  1894. } else
  1895. setValidElements(settings.valid_elements);
  1896. addCustomElements(settings.custom_elements);
  1897. addValidChildren(settings.valid_children);
  1898. addValidElements(settings.extended_valid_elements);
  1899. // Todo: Remove this when we fix list handling to be valid
  1900. addValidChildren('+ol[ul|ol],+ul[ul|ol]');
  1901. // If the user didn't allow span only allow internal spans
  1902. if (!getElementRule('span'))
  1903. addValidElements('span[!data-mce-type|*]');
  1904. // Delete invalid elements
  1905. if (settings.invalid_elements) {
  1906. tinymce.each(tinymce.explode(settings.invalid_elements), function(item) {
  1907. if (elements[item])
  1908. delete elements[item];
  1909. });
  1910. }
  1911. self.children = children;
  1912. self.styles = validStyles;
  1913. self.getBoolAttrs = function() {
  1914. return boolAttrMap;
  1915. };
  1916. self.getBlockElements = function() {
  1917. return blockElementsMap;
  1918. };
  1919. self.getShortEndedElements = function() {
  1920. return shortEndedElementsMap;
  1921. };
  1922. self.getSelfClosingElements = function() {
  1923. return selfClosingElementsMap;
  1924. };
  1925. self.getNonEmptyElements = function() {
  1926. return nonEmptyElementsMap;
  1927. };
  1928. self.getWhiteSpaceElements = function() {
  1929. return whiteSpaceElementsMap;
  1930. };
  1931. self.isValidChild = function(name, child) {
  1932. var parent = children[name];
  1933. return !!(parent && parent[child]);
  1934. };
  1935. self.getElementRule = getElementRule;
  1936. self.getCustomElements = function() {
  1937. return customElementsMap;
  1938. };
  1939. self.addValidElements = addValidElements;
  1940. self.setValidElements = setValidElements;
  1941. self.addCustomElements = addCustomElements;
  1942. self.addValidChildren = addValidChildren;
  1943. };
  1944. // Expose boolMap and blockElementMap as static properties for usage in DOMUtils
  1945. tinymce.html.Schema.boolAttrMap = boolAttrMap;
  1946. tinymce.html.Schema.blockElementsMap = blockElementsMap;
  1947. })(tinymce);
  1948. (function(tinymce) {
  1949. tinymce.html.SaxParser = function(settings, schema) {
  1950. var self = this, noop = function() {};
  1951. settings = settings || {};
  1952. self.schema = schema = schema || new tinymce.html.Schema();
  1953. if (settings.fix_self_closing !== false)
  1954. settings.fix_self_closing = true;
  1955. // Add handler functions from settings and setup default handlers
  1956. tinymce.each('comment cdata text start end pi doctype'.split(' '), function(name) {
  1957. if (name)
  1958. self[name] = settings[name] || noop;
  1959. });
  1960. self.parse = function(html) {
  1961. var self = this, matches, index = 0, value, endRegExp, stack = [], attrList, i, text, name, isInternalElement, removeInternalElements,
  1962. shortEndedElements, fillAttrsMap, isShortEnded, validate, elementRule, isValidElement, attr, attribsValue, invalidPrefixRegExp,
  1963. validAttributesMap, validAttributePatterns, attributesRequired, attributesDefault, attributesForced, selfClosing,
  1964. tokenRegExp, attrRegExp, specialElements, attrValue, idCount = 0, decode = tinymce.html.Entities.decode, fixSelfClosing, isIE;
  1965. function processEndTag(name) {
  1966. var pos, i;
  1967. // Find position of parent of the same type
  1968. pos = stack.length;
  1969. while (pos--) {
  1970. if (stack[pos].name === name)
  1971. break;
  1972. }
  1973. // Found parent
  1974. if (pos >= 0) {
  1975. // Close all the open elements
  1976. for (i = stack.length - 1; i >= pos; i--) {
  1977. name = stack[i];
  1978. if (name.valid)
  1979. self.end(name.name);
  1980. }
  1981. // Remove the open elements from the stack
  1982. stack.length = pos;
  1983. }
  1984. };
  1985. // Precompile RegExps and map objects
  1986. tokenRegExp = new RegExp('<(?:' +
  1987. '(?:!--([\\w\\W]*?)-->)|' + // Comment
  1988. '(?:!\\[CDATA\\[([\\w\\W]*?)\\]\\]>)|' + // CDATA
  1989. '(?:!DOCTYPE([\\w\\W]*?)>)|' + // DOCTYPE
  1990. '(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|' + // PI
  1991. '(?:\\/([^>]+)>)|' + // End element
  1992. '(?:([^\\s\\/<>]+)((?:\\s+[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*|\\/)>)' + // Start element
  1993. ')', 'g');
  1994. attrRegExp = /([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:\\.|[^\"])*)\")|(?:\'((?:\\.|[^\'])*)\')|([^>\s]+)))?/g;
  1995. specialElements = {
  1996. 'script' : /<\/script[^>]*>/gi,
  1997. 'style' : /<\/style[^>]*>/gi,
  1998. 'noscript' : /<\/noscript[^>]*>/gi
  1999. };
  2000. // Setup lookup tables for empty elements and boolean attributes
  2001. shortEndedElements = schema.getShortEndedElements();
  2002. selfClosing = schema.getSelfClosingElements();
  2003. fillAttrsMap = schema.getBoolAttrs();
  2004. validate = settings.validate;
  2005. removeInternalElements = settings.remove_internals;
  2006. fixSelfClosing = settings.fix_self_closing;
  2007. isIE = tinymce.isIE;
  2008. invalidPrefixRegExp = /^:/;
  2009. while (matches = tokenRegExp.exec(html)) {
  2010. // Text
  2011. if (index < matches.index)
  2012. self.text(decode(html.substr(index, matches.index - index)));
  2013. if (value = matches[6]) { // End element
  2014. value = value.toLowerCase();
  2015. // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
  2016. if (isIE && invalidPrefixRegExp.test(value))
  2017. value = value.substr(1);
  2018. processEndTag(value);
  2019. } else if (value = matches[7]) { // Start element
  2020. value = value.toLowerCase();
  2021. // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
  2022. if (isIE && invalidPrefixRegExp.test(value))
  2023. value = value.substr(1);
  2024. isShortEnded = value in shortEndedElements;
  2025. // Is self closing tag for example an <li> after an open <li>
  2026. if (fixSelfClosing && selfClosing[value] && stack.length > 0 && stack[stack.length - 1].name === value)
  2027. processEndTag(value);
  2028. // Validate element
  2029. if (!validate || (elementRule = schema.getElementRule(value))) {
  2030. isValidElement = true;
  2031. // Grab attributes map and patters when validation is enabled
  2032. if (validate) {
  2033. validAttributesMap = elementRule.attributes;
  2034. validAttributePatterns = elementRule.attributePatterns;
  2035. }
  2036. // Parse attributes
  2037. if (attribsValue = matches[8]) {
  2038. isInternalElement = attribsValue.indexOf('data-mce-type') !== -1; // Check if the element is an internal element
  2039. // If the element has internal attributes then remove it if we are told to do so
  2040. if (isInternalElement && removeInternalElements)
  2041. isValidElement = false;
  2042. attrList = [];
  2043. attrList.map = {};
  2044. attribsValue.replace(attrRegExp, function(match, name, value, val2, val3) {
  2045. var attrRule, i;
  2046. name = name.toLowerCase();
  2047. value = name in fillAttrsMap ? name : decode(value || val2 || val3 || ''); // Handle boolean attribute than value attribute
  2048. // Validate name and value
  2049. if (validate && !isInternalElement && name.indexOf('data-') !== 0) {
  2050. attrRule = validAttributesMap[name];
  2051. // Find rule by pattern matching
  2052. if (!attrRule && validAttributePatterns) {
  2053. i = validAttributePatterns.length;
  2054. while (i--) {
  2055. attrRule = validAttributePatterns[i];
  2056. if (attrRule.pattern.test(name))
  2057. break;
  2058. }
  2059. // No rule matched
  2060. if (i === -1)
  2061. attrRule = null;
  2062. }
  2063. // No attribute rule found
  2064. if (!attrRule)
  2065. return;
  2066. // Validate value
  2067. if (attrRule.validValues && !(value in attrRule.validValues))
  2068. return;
  2069. }
  2070. // Add attribute to list and map
  2071. attrList.map[name] = value;
  2072. attrList.push({
  2073. name: name,
  2074. value: value
  2075. });
  2076. });
  2077. } else {
  2078. attrList = [];
  2079. attrList.map = {};
  2080. }
  2081. // Process attributes if validation is enabled
  2082. if (validate && !isInternalElement) {
  2083. attributesRequired = elementRule.attributesRequired;
  2084. attributesDefault = elementRule.attributesDefault;
  2085. attributesForced = elementRule.attributesForced;
  2086. // Handle forced attributes
  2087. if (attributesForced) {
  2088. i = attributesForced.length;
  2089. while (i--) {
  2090. attr = attributesForced[i];
  2091. name = attr.name;
  2092. attrValue = attr.value;
  2093. if (attrValue === '{$uid}')
  2094. attrValue = 'mce_' + idCount++;
  2095. attrList.map[name] = attrValue;
  2096. attrList.push({name: name, value: attrValue});
  2097. }
  2098. }
  2099. // Handle default attributes
  2100. if (attributesDefault) {
  2101. i = attributesDefault.length;
  2102. while (i--) {
  2103. attr = attributesDefault[i];
  2104. name = attr.name;
  2105. if (!(name in attrList.map)) {
  2106. attrValue = attr.value;
  2107. if (attrValue === '{$uid}')
  2108. attrValue = 'mce_' + idCount++;
  2109. attrList.map[name] = attrValue;
  2110. attrList.push({name: name, value: attrValue});
  2111. }
  2112. }
  2113. }
  2114. // Handle required attributes
  2115. if (attributesRequired) {
  2116. i = attributesRequired.length;
  2117. while (i--) {
  2118. if (attributesRequired[i] in attrList.map)
  2119. break;
  2120. }
  2121. // None of the required attributes where found
  2122. if (i === -1)
  2123. isValidElement = false;
  2124. }
  2125. // Invalidate element if it's marked as bogus
  2126. if (attrList.map['data-mce-bogus'])
  2127. isValidElement = false;
  2128. }
  2129. if (isValidElement)
  2130. self.start(value, attrList, isShortEnded);
  2131. } else
  2132. isValidElement = false;
  2133. // Treat script, noscript and style a bit different since they may include code that looks like elements
  2134. if (endRegExp = specialElements[value]) {
  2135. endRegExp.lastIndex = index = matches.index + matches[0].length;
  2136. if (matches = endRegExp.exec(html)) {
  2137. if (isValidElement)
  2138. text = html.substr(index, matches.index - index);
  2139. index = matches.index + matches[0].length;
  2140. } else {
  2141. text = html.substr(index);
  2142. index = html.length;
  2143. }
  2144. if (isValidElement && text.length > 0)
  2145. self.text(text, true);
  2146. if (isValidElement)
  2147. self.end(value);
  2148. tokenRegExp.lastIndex = index;
  2149. continue;
  2150. }
  2151. // Push value on to stack
  2152. if (!isShortEnded) {
  2153. if (!attribsValue || attribsValue.indexOf('/') != attribsValue.length - 1)
  2154. stack.push({name: value, valid: isValidElement});
  2155. else if (isValidElement)
  2156. self.end(value);
  2157. }
  2158. } else if (value = matches[1]) { // Comment
  2159. self.comment(value);
  2160. } else if (value = matches[2]) { // CDATA
  2161. self.cdata(value);
  2162. } else if (value = matches[3]) { // DOCTYPE
  2163. self.doctype(value);
  2164. } else if (value = matches[4]) { // PI
  2165. self.pi(value, matches[5]);
  2166. }
  2167. index = matches.index + matches[0].length;
  2168. }
  2169. // Text
  2170. if (index < html.length)
  2171. self.text(decode(html.substr(index)));
  2172. // Close any open elements
  2173. for (i = stack.length - 1; i >= 0; i--) {
  2174. value = stack[i];
  2175. if (value.valid)
  2176. self.end(value.name);
  2177. }
  2178. };
  2179. }
  2180. })(tinymce);
  2181. (function(tinymce) {
  2182. var whiteSpaceRegExp = /^[ \t\r\n]*$/, typeLookup = {
  2183. '#text' : 3,
  2184. '#comment' : 8,
  2185. '#cdata' : 4,
  2186. '#pi' : 7,
  2187. '#doctype' : 10,
  2188. '#document-fragment' : 11
  2189. };
  2190. // Walks the tree left/right
  2191. function walk(node, root_node, prev) {
  2192. var sibling, parent, startName = prev ? 'lastChild' : 'firstChild', siblingName = prev ? 'prev' : 'next';
  2193. // Walk into nodes if it has a start
  2194. if (node[startName])
  2195. return node[startName];
  2196. // Return the sibling if it has one
  2197. if (node !== root_node) {
  2198. sibling = node[siblingName];
  2199. if (sibling)
  2200. return sibling;
  2201. // Walk up the parents to look for siblings
  2202. for (parent = node.parent; parent && parent !== root_node; parent = parent.parent) {
  2203. sibling = parent[siblingName];
  2204. if (sibling)
  2205. return sibling;
  2206. }
  2207. }
  2208. };
  2209. function Node(name, type) {
  2210. this.name = name;
  2211. this.type = type;
  2212. if (type === 1) {
  2213. this.attributes = [];
  2214. this.attributes.map = {};
  2215. }
  2216. }
  2217. tinymce.extend(Node.prototype, {
  2218. replace : function(node) {
  2219. var self = this;
  2220. if (node.parent)
  2221. node.remove();
  2222. self.insert(node, self);
  2223. self.remove();
  2224. return self;
  2225. },
  2226. attr : function(name, value) {
  2227. var self = this, attrs, i, undef;
  2228. if (typeof name !== "string") {
  2229. for (i in name)
  2230. self.attr(i, name[i]);
  2231. return self;
  2232. }
  2233. if (attrs = self.attributes) {
  2234. if (value !== undef) {
  2235. // Remove attribute
  2236. if (value === null) {
  2237. if (name in attrs.map) {
  2238. delete attrs.map[name];
  2239. i = attrs.length;
  2240. while (i--) {
  2241. if (attrs[i].name === name) {
  2242. attrs = attrs.splice(i, 1);
  2243. return self;
  2244. }
  2245. }
  2246. }
  2247. return self;
  2248. }
  2249. // Set attribute
  2250. if (name in attrs.map) {
  2251. // Set attribute
  2252. i = attrs.length;
  2253. while (i--) {
  2254. if (attrs[i].name === name) {
  2255. attrs[i].value = value;
  2256. break;
  2257. }
  2258. }
  2259. } else
  2260. attrs.push({name: name, value: value});
  2261. attrs.map[name] = value;
  2262. return self;
  2263. } else {
  2264. return attrs.map[name];
  2265. }
  2266. }
  2267. },
  2268. clone : function() {
  2269. var self = this, clone = new Node(self.name, self.type), i, l, selfAttrs, selfAttr, cloneAttrs;
  2270. // Clone element attributes
  2271. if (selfAttrs = self.attributes) {
  2272. cloneAttrs = [];
  2273. cloneAttrs.map = {};
  2274. for (i = 0, l = selfAttrs.length; i < l; i++) {
  2275. selfAttr = selfAttrs[i];
  2276. // Clone everything except id
  2277. if (selfAttr.name !== 'id') {
  2278. cloneAttrs[cloneAttrs.length] = {name: selfAttr.name, value: selfAttr.value};
  2279. cloneAttrs.map[selfAttr.name] = selfAttr.value;
  2280. }
  2281. }
  2282. clone.attributes = cloneAttrs;
  2283. }
  2284. clone.value = self.value;
  2285. clone.shortEnded = self.shortEnded;
  2286. return clone;
  2287. },
  2288. wrap : function(wrapper) {
  2289. var self = this;
  2290. self.parent.insert(wrapper, self);
  2291. wrapper.append(self);
  2292. return self;
  2293. },
  2294. unwrap : function() {
  2295. var self = this, node, next;
  2296. for (node = self.firstChild; node; ) {
  2297. next = node.next;
  2298. self.insert(node, self, true);
  2299. node = next;
  2300. }
  2301. self.remove();
  2302. },
  2303. remove : function() {
  2304. var self = this, parent = self.parent, next = self.next, prev = self.prev;
  2305. if (parent) {
  2306. if (parent.firstChild === self) {
  2307. parent.firstChild = next;
  2308. if (next)
  2309. next.prev = null;
  2310. } else {
  2311. prev.next = next;
  2312. }
  2313. if (parent.lastChild === self) {
  2314. parent.lastChild = prev;
  2315. if (prev)
  2316. prev.next = null;
  2317. } else {
  2318. next.prev = prev;
  2319. }
  2320. self.parent = self.next = self.prev = null;
  2321. }
  2322. return self;
  2323. },
  2324. append : function(node) {
  2325. var self = this, last;
  2326. if (node.parent)
  2327. node.remove();
  2328. last = self.lastChild;
  2329. if (last) {
  2330. last.next = node;
  2331. node.prev = last;
  2332. self.lastChild = node;
  2333. } else
  2334. self.lastChild = self.firstChild = node;
  2335. node.parent = self;
  2336. return node;
  2337. },
  2338. insert : function(node, ref_node, before) {
  2339. var parent;
  2340. if (node.parent)
  2341. node.remove();
  2342. parent = ref_node.parent || this;
  2343. if (before) {
  2344. if (ref_node === parent.firstChild)
  2345. parent.firstChild = node;
  2346. else
  2347. ref_node.prev.next = node;
  2348. node.prev = ref_node.prev;
  2349. node.next = ref_node;
  2350. ref_node.prev = node;
  2351. } else {
  2352. if (ref_node === parent.lastChild)
  2353. parent.lastChild = node;
  2354. else
  2355. ref_node.next.prev = node;
  2356. node.next = ref_node.next;
  2357. node.prev = ref_node;
  2358. ref_node.next = node;
  2359. }
  2360. node.parent = parent;
  2361. return node;
  2362. },
  2363. getAll : function(name) {
  2364. var self = this, node, collection = [];
  2365. for (node = self.firstChild; node; node = walk(node, self)) {
  2366. if (node.name === name)
  2367. collection.push(node);
  2368. }
  2369. return collection;
  2370. },
  2371. empty : function() {
  2372. var self = this, nodes, i, node;
  2373. // Remove all children
  2374. if (self.firstChild) {
  2375. nodes = [];
  2376. // Collect the children
  2377. for (node = self.firstChild; node; node = walk(node, self))
  2378. nodes.push(node);
  2379. // Remove the children
  2380. i = nodes.length;
  2381. while (i--) {
  2382. node = nodes[i];
  2383. node.parent = node.firstChild = node.lastChild = node.next = node.prev = null;
  2384. }
  2385. }
  2386. self.firstChild = self.lastChild = null;
  2387. return self;
  2388. },
  2389. isEmpty : function(elements) {
  2390. var self = this, node = self.firstChild, i, name;
  2391. if (node) {
  2392. do {
  2393. if (node.type === 1) {
  2394. // Ignore bogus elements
  2395. if (node.attributes.map['data-mce-bogus'])
  2396. continue;
  2397. // Keep empty elements like <img />
  2398. if (elements[node.name])
  2399. return false;
  2400. // Keep elements with data attributes or name attribute like <a name="1"></a>
  2401. i = node.attributes.length;
  2402. while (i--) {
  2403. name = node.attributes[i].name;
  2404. if (name === "name" || name.indexOf('data-') === 0)
  2405. return false;
  2406. }
  2407. }
  2408. // Keep non whitespace text nodes
  2409. if ((node.type === 3 && !whiteSpaceRegExp.test(node.value)))
  2410. return false;
  2411. } while (node = walk(node, self));
  2412. }
  2413. return true;
  2414. },
  2415. walk : function(prev) {
  2416. return walk(this, null, prev);
  2417. }
  2418. });
  2419. tinymce.extend(Node, {
  2420. create : function(name, attrs) {
  2421. var node, attrName;
  2422. // Create node
  2423. node = new Node(name, typeLookup[name] || 1);
  2424. // Add attributes if needed
  2425. if (attrs) {
  2426. for (attrName in attrs)
  2427. node.attr(attrName, attrs[attrName]);
  2428. }
  2429. return node;
  2430. }
  2431. });
  2432. tinymce.html.Node = Node;
  2433. })(tinymce);
  2434. (function(tinymce) {
  2435. var Node = tinymce.html.Node;
  2436. tinymce.html.DomParser = function(settings, schema) {
  2437. var self = this, nodeFilters = {}, attributeFilters = [], matchedNodes = {}, matchedAttributes = {};
  2438. settings = settings || {};
  2439. settings.validate = "validate" in settings ? settings.validate : true;
  2440. settings.root_name = settings.root_name || 'body';
  2441. self.schema = schema = schema || new tinymce.html.Schema();
  2442. function fixInvalidChildren(nodes) {
  2443. var ni, node, parent, parents, newParent, currentNode, tempNode, childNode, i,
  2444. childClone, nonEmptyElements, nonSplitableElements, sibling, nextNode;
  2445. nonSplitableElements = tinymce.makeMap('tr,td,th,tbody,thead,tfoot,table');
  2446. nonEmptyElements = schema.getNonEmptyElements();
  2447. for (ni = 0; ni < nodes.length; ni++) {
  2448. node = nodes[ni];
  2449. // Already removed
  2450. if (!node.parent)
  2451. continue;
  2452. // Get list of all parent nodes until we find a valid parent to stick the child into
  2453. parents = [node];
  2454. for (parent = node.parent; parent && !schema.isValidChild(parent.name, node.name) && !nonSplitableElements[parent.name]; parent = parent.parent)
  2455. parents.push(parent);
  2456. // Found a suitable parent
  2457. if (parent && parents.length > 1) {
  2458. // Reverse the array since it makes looping easier
  2459. parents.reverse();
  2460. // Clone the related parent and insert that after the moved node
  2461. newParent = currentNode = self.filterNode(parents[0].clone());
  2462. // Start cloning and moving children on the left side of the target node
  2463. for (i = 0; i < parents.length - 1; i++) {
  2464. if (schema.isValidChild(currentNode.name, parents[i].name)) {
  2465. tempNode = self.filterNode(parents[i].clone());
  2466. currentNode.append(tempNode);
  2467. } else
  2468. tempNode = currentNode;
  2469. for (childNode = parents[i].firstChild; childNode && childNode != parents[i + 1]; ) {
  2470. nextNode = childNode.next;
  2471. tempNode.append(childNode);
  2472. childNode = nextNode;
  2473. }
  2474. currentNode = tempNode;
  2475. }
  2476. if (!newParent.isEmpty(nonEmptyElements)) {
  2477. parent.insert(newParent, parents[0], true);
  2478. parent.insert(node, newParent);
  2479. } else {
  2480. parent.insert(node, parents[0], true);
  2481. }
  2482. // Check if the element is empty by looking through it's contents and special treatment for <p><br /></p>
  2483. parent = parents[0];
  2484. if (parent.isEmpty(nonEmptyElements) || parent.firstChild === parent.lastChild && parent.firstChild.name === 'br') {
  2485. parent.empty().remove();
  2486. }
  2487. } else if (node.parent) {
  2488. // If it's an LI try to find a UL/OL for it or wrap it
  2489. if (node.name === 'li') {
  2490. sibling = node.prev;
  2491. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  2492. sibling.append(node);
  2493. continue;
  2494. }
  2495. sibling = node.next;
  2496. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  2497. sibling.insert(node, sibling.firstChild, true);
  2498. continue;
  2499. }
  2500. node.wrap(self.filterNode(new Node('ul', 1)));
  2501. continue;
  2502. }
  2503. // Try wrapping the element in a DIV
  2504. if (schema.isValidChild(node.parent.name, 'div') && schema.isValidChild('div', node.name)) {
  2505. node.wrap(self.filterNode(new Node('div', 1)));
  2506. } else {
  2507. // We failed wrapping it, then remove or unwrap it
  2508. if (node.name === 'style' || node.name === 'script')
  2509. node.empty().remove();
  2510. else
  2511. node.unwrap();
  2512. }
  2513. }
  2514. }
  2515. };
  2516. self.filterNode = function(node) {
  2517. var i, name, list;
  2518. // Run element filters
  2519. if (name in nodeFilters) {
  2520. list = matchedNodes[name];
  2521. if (list)
  2522. list.push(node);
  2523. else
  2524. matchedNodes[name] = [node];
  2525. }
  2526. // Run attribute filters
  2527. i = attributeFilters.length;
  2528. while (i--) {
  2529. name = attributeFilters[i].name;
  2530. if (name in node.attributes.map) {
  2531. list = matchedAttributes[name];
  2532. if (list)
  2533. list.push(node);
  2534. else
  2535. matchedAttributes[name] = [node];
  2536. }
  2537. }
  2538. return node;
  2539. };
  2540. self.addNodeFilter = function(name, callback) {
  2541. tinymce.each(tinymce.explode(name), function(name) {
  2542. var list = nodeFilters[name];
  2543. if (!list)
  2544. nodeFilters[name] = list = [];
  2545. list.push(callback);
  2546. });
  2547. };
  2548. self.addAttributeFilter = function(name, callback) {
  2549. tinymce.each(tinymce.explode(name), function(name) {
  2550. var i;
  2551. for (i = 0; i < attributeFilters.length; i++) {
  2552. if (attributeFilters[i].name === name) {
  2553. attributeFilters[i].callbacks.push(callback);
  2554. return;
  2555. }
  2556. }
  2557. attributeFilters.push({name: name, callbacks: [callback]});
  2558. });
  2559. };
  2560. self.parse = function(html, args) {
  2561. var parser, rootNode, node, nodes, i, l, fi, fl, list, name, validate,
  2562. blockElements, startWhiteSpaceRegExp, invalidChildren = [],
  2563. endWhiteSpaceRegExp, allWhiteSpaceRegExp, whiteSpaceElements, children, nonEmptyElements, rootBlockName;
  2564. args = args || {};
  2565. matchedNodes = {};
  2566. matchedAttributes = {};
  2567. blockElements = tinymce.extend(tinymce.makeMap('script,style,head,html,body,title,meta,param'), schema.getBlockElements());
  2568. nonEmptyElements = schema.getNonEmptyElements();
  2569. children = schema.children;
  2570. validate = settings.validate;
  2571. rootBlockName = "forced_root_block" in args ? args.forced_root_block : settings.forced_root_block;
  2572. whiteSpaceElements = schema.getWhiteSpaceElements();
  2573. startWhiteSpaceRegExp = /^[ \t\r\n]+/;
  2574. endWhiteSpaceRegExp = /[ \t\r\n]+$/;
  2575. allWhiteSpaceRegExp = /[ \t\r\n]+/g;
  2576. function addRootBlocks() {
  2577. var node = rootNode.firstChild, next, rootBlockNode;
  2578. while (node) {
  2579. next = node.next;
  2580. if (node.type == 3 || (node.type == 1 && node.name !== 'p' && !blockElements[node.name] && !node.attr('data-mce-type'))) {
  2581. if (!rootBlockNode) {
  2582. // Create a new root block element
  2583. rootBlockNode = createNode(rootBlockName, 1);
  2584. rootNode.insert(rootBlockNode, node);
  2585. rootBlockNode.append(node);
  2586. } else
  2587. rootBlockNode.append(node);
  2588. } else {
  2589. rootBlockNode = null;
  2590. }
  2591. node = next;
  2592. };
  2593. };
  2594. function createNode(name, type) {
  2595. var node = new Node(name, type), list;
  2596. if (name in nodeFilters) {
  2597. list = matchedNodes[name];
  2598. if (list)
  2599. list.push(node);
  2600. else
  2601. matchedNodes[name] = [node];
  2602. }
  2603. return node;
  2604. };
  2605. function removeWhitespaceBefore(node) {
  2606. var textNode, textVal, sibling;
  2607. for (textNode = node.prev; textNode && textNode.type === 3; ) {
  2608. textVal = textNode.value.replace(endWhiteSpaceRegExp, '');
  2609. if (textVal.length > 0) {
  2610. textNode.value = textVal;
  2611. textNode = textNode.prev;
  2612. } else {
  2613. sibling = textNode.prev;
  2614. textNode.remove();
  2615. textNode = sibling;
  2616. }
  2617. }
  2618. };
  2619. parser = new tinymce.html.SaxParser({
  2620. validate : validate,
  2621. fix_self_closing : !validate, // Let the DOM parser handle <li> in <li> or <p> in <p> for better results
  2622. cdata: function(text) {
  2623. node.append(createNode('#cdata', 4)).value = text;
  2624. },
  2625. text: function(text, raw) {
  2626. var textNode;
  2627. // Trim all redundant whitespace on non white space elements
  2628. if (!whiteSpaceElements[node.name]) {
  2629. text = text.replace(allWhiteSpaceRegExp, ' ');
  2630. if (node.lastChild && blockElements[node.lastChild.name])
  2631. text = text.replace(startWhiteSpaceRegExp, '');
  2632. }
  2633. // Do we need to create the node
  2634. if (text.length !== 0) {
  2635. textNode = createNode('#text', 3);
  2636. textNode.raw = !!raw;
  2637. node.append(textNode).value = text;
  2638. }
  2639. },
  2640. comment: function(text) {
  2641. node.append(createNode('#comment', 8)).value = text;
  2642. },
  2643. pi: function(name, text) {
  2644. node.append(createNode(name, 7)).value = text;
  2645. removeWhitespaceBefore(node);
  2646. },
  2647. doctype: function(text) {
  2648. var newNode;
  2649. newNode = node.append(createNode('#doctype', 10));
  2650. newNode.value = text;
  2651. removeWhitespaceBefore(node);
  2652. },
  2653. start: function(name, attrs, empty) {
  2654. var newNode, attrFiltersLen, elementRule, textNode, attrName, text, sibling, parent;
  2655. elementRule = validate ? schema.getElementRule(name) : {};
  2656. if (elementRule) {
  2657. newNode = createNode(elementRule.outputName || name, 1);
  2658. newNode.attributes = attrs;
  2659. newNode.shortEnded = empty;
  2660. node.append(newNode);
  2661. // Check if node is valid child of the parent node is the child is
  2662. // unknown we don't collect it since it's probably a custom element
  2663. parent = children[node.name];
  2664. if (parent && children[newNode.name] && !parent[newNode.name])
  2665. invalidChildren.push(newNode);
  2666. attrFiltersLen = attributeFilters.length;
  2667. while (attrFiltersLen--) {
  2668. attrName = attributeFilters[attrFiltersLen].name;
  2669. if (attrName in attrs.map) {
  2670. list = matchedAttributes[attrName];
  2671. if (list)
  2672. list.push(newNode);
  2673. else
  2674. matchedAttributes[attrName] = [newNode];
  2675. }
  2676. }
  2677. // Trim whitespace before block
  2678. if (blockElements[name])
  2679. removeWhitespaceBefore(newNode);
  2680. // Change current node if the element wasn't empty i.e not <br /> or <img />
  2681. if (!empty)
  2682. node = newNode;
  2683. }
  2684. },
  2685. end: function(name) {
  2686. var textNode, elementRule, text, sibling, tempNode;
  2687. elementRule = validate ? schema.getElementRule(name) : {};
  2688. if (elementRule) {
  2689. if (blockElements[name]) {
  2690. if (!whiteSpaceElements[node.name]) {
  2691. // Trim whitespace at beginning of block
  2692. for (textNode = node.firstChild; textNode && textNode.type === 3; ) {
  2693. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  2694. if (text.length > 0) {
  2695. textNode.value = text;
  2696. textNode = textNode.next;
  2697. } else {
  2698. sibling = textNode.next;
  2699. textNode.remove();
  2700. textNode = sibling;
  2701. }
  2702. }
  2703. // Trim whitespace at end of block
  2704. for (textNode = node.lastChild; textNode && textNode.type === 3; ) {
  2705. text = textNode.value.replace(endWhiteSpaceRegExp, '');
  2706. if (text.length > 0) {
  2707. textNode.value = text;
  2708. textNode = textNode.prev;
  2709. } else {
  2710. sibling = textNode.prev;
  2711. textNode.remove();
  2712. textNode = sibling;
  2713. }
  2714. }
  2715. }
  2716. // Trim start white space
  2717. textNode = node.prev;
  2718. if (textNode && textNode.type === 3) {
  2719. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  2720. if (text.length > 0)
  2721. textNode.value = text;
  2722. else
  2723. textNode.remove();
  2724. }
  2725. }
  2726. // Handle empty nodes
  2727. if (elementRule.removeEmpty || elementRule.paddEmpty) {
  2728. if (node.isEmpty(nonEmptyElements)) {
  2729. if (elementRule.paddEmpty)
  2730. node.empty().append(new Node('#text', '3')).value = '\u00a0';
  2731. else {
  2732. // Leave nodes that have a name like <a name="name">
  2733. if (!node.attributes.map.name) {
  2734. tempNode = node.parent;
  2735. node.empty().remove();
  2736. node = tempNode;
  2737. return;
  2738. }
  2739. }
  2740. }
  2741. }
  2742. node = node.parent;
  2743. }
  2744. }
  2745. }, schema);
  2746. rootNode = node = new Node(args.context || settings.root_name, 11);
  2747. parser.parse(html);
  2748. // Fix invalid children or report invalid children in a contextual parsing
  2749. if (validate && invalidChildren.length) {
  2750. if (!args.context)
  2751. fixInvalidChildren(invalidChildren);
  2752. else
  2753. args.invalid = true;
  2754. }
  2755. // Wrap nodes in the root into block elements if the root is body
  2756. if (rootBlockName && rootNode.name == 'body')
  2757. addRootBlocks();
  2758. // Run filters only when the contents is valid
  2759. if (!args.invalid) {
  2760. // Run node filters
  2761. for (name in matchedNodes) {
  2762. list = nodeFilters[name];
  2763. nodes = matchedNodes[name];
  2764. // Remove already removed children
  2765. fi = nodes.length;
  2766. while (fi--) {
  2767. if (!nodes[fi].parent)
  2768. nodes.splice(fi, 1);
  2769. }
  2770. for (i = 0, l = list.length; i < l; i++)
  2771. list[i](nodes, name, args);
  2772. }
  2773. // Run attribute filters
  2774. for (i = 0, l = attributeFilters.length; i < l; i++) {
  2775. list = attributeFilters[i];
  2776. if (list.name in matchedAttributes) {
  2777. nodes = matchedAttributes[list.name];
  2778. // Remove already removed children
  2779. fi = nodes.length;
  2780. while (fi--) {
  2781. if (!nodes[fi].parent)
  2782. nodes.splice(fi, 1);
  2783. }
  2784. for (fi = 0, fl = list.callbacks.length; fi < fl; fi++)
  2785. list.callbacks[fi](nodes, list.name, args);
  2786. }
  2787. }
  2788. }
  2789. return rootNode;
  2790. };
  2791. // Remove <br> at end of block elements Gecko and WebKit injects BR elements to
  2792. // make it possible to place the caret inside empty blocks. This logic tries to remove
  2793. // these elements and keep br elements that where intended to be there intact
  2794. if (settings.remove_trailing_brs) {
  2795. self.addNodeFilter('br', function(nodes, name) {
  2796. var i, l = nodes.length, node, blockElements = schema.getBlockElements(),
  2797. nonEmptyElements = schema.getNonEmptyElements(), parent, prev, prevName;
  2798. // Remove brs from body element as well
  2799. blockElements.body = 1;
  2800. // Must loop forwards since it will otherwise remove all brs in <p>a<br><br><br></p>
  2801. for (i = 0; i < l; i++) {
  2802. node = nodes[i];
  2803. parent = node.parent;
  2804. if (blockElements[node.parent.name] && node === parent.lastChild) {
  2805. // Loop all nodes to the right of the current node and check for other BR elements
  2806. // excluding bookmarks since they are invisible
  2807. prev = node.prev;
  2808. while (prev) {
  2809. prevName = prev.name;
  2810. // Ignore bookmarks
  2811. if (prevName !== "span" || prev.attr('data-mce-type') !== 'bookmark') {
  2812. // Found a non BR element
  2813. if (prevName !== "br")
  2814. break;
  2815. // Found another br it's a <br><br> structure then don't remove anything
  2816. if (prevName === 'br') {
  2817. node = null;
  2818. break;
  2819. }
  2820. }
  2821. prev = prev.prev;
  2822. }
  2823. if (node) {
  2824. node.remove();
  2825. // Is the parent to be considered empty after we removed the BR
  2826. if (parent.isEmpty(nonEmptyElements)) {
  2827. elementRule = schema.getElementRule(parent.name);
  2828. // Remove or padd the element depending on schema rule
  2829. if (elementRule) {
  2830. if (elementRule.removeEmpty)
  2831. parent.remove();
  2832. else if (elementRule.paddEmpty)
  2833. parent.empty().append(new tinymce.html.Node('#text', 3)).value = '\u00a0';
  2834. }
  2835. }
  2836. }
  2837. }
  2838. }
  2839. });
  2840. }
  2841. }
  2842. })(tinymce);
  2843. tinymce.html.Writer = function(settings) {
  2844. var html = [], indent, indentBefore, indentAfter, encode, htmlOutput;
  2845. settings = settings || {};
  2846. indent = settings.indent;
  2847. indentBefore = tinymce.makeMap(settings.indent_before || '');
  2848. indentAfter = tinymce.makeMap(settings.indent_after || '');
  2849. encode = tinymce.html.Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities);
  2850. htmlOutput = settings.element_format == "html";
  2851. return {
  2852. start: function(name, attrs, empty) {
  2853. var i, l, attr, value;
  2854. if (indent && indentBefore[name] && html.length > 0) {
  2855. value = html[html.length - 1];
  2856. if (value.length > 0 && value !== '\n')
  2857. html.push('\n');
  2858. }
  2859. html.push('<', name);
  2860. if (attrs) {
  2861. for (i = 0, l = attrs.length; i < l; i++) {
  2862. attr = attrs[i];
  2863. html.push(' ', attr.name, '="', encode(attr.value, true), '"');
  2864. }
  2865. }
  2866. if (!empty || htmlOutput)
  2867. html[html.length] = '>';
  2868. else
  2869. html[html.length] = ' />';
  2870. if (empty && indent && indentAfter[name] && html.length > 0) {
  2871. value = html[html.length - 1];
  2872. if (value.length > 0 && value !== '\n')
  2873. html.push('\n');
  2874. }
  2875. },
  2876. end: function(name) {
  2877. var value;
  2878. /*if (indent && indentBefore[name] && html.length > 0) {
  2879. value = html[html.length - 1];
  2880. if (value.length > 0 && value !== '\n')
  2881. html.push('\n');
  2882. }*/
  2883. html.push('</', name, '>');
  2884. if (indent && indentAfter[name] && html.length > 0) {
  2885. value = html[html.length - 1];
  2886. if (value.length > 0 && value !== '\n')
  2887. html.push('\n');
  2888. }
  2889. },
  2890. text: function(text, raw) {
  2891. if (text.length > 0)
  2892. html[html.length] = raw ? text : encode(text);
  2893. },
  2894. cdata: function(text) {
  2895. html.push('<![CDATA[', text, ']]>');
  2896. },
  2897. comment: function(text) {
  2898. html.push('<!--', text, '-->');
  2899. },
  2900. pi: function(name, text) {
  2901. if (text)
  2902. html.push('<?', name, ' ', text, '?>');
  2903. else
  2904. html.push('<?', name, '?>');
  2905. if (indent)
  2906. html.push('\n');
  2907. },
  2908. doctype: function(text) {
  2909. html.push('<!DOCTYPE', text, '>', indent ? '\n' : '');
  2910. },
  2911. reset: function() {
  2912. html.length = 0;
  2913. },
  2914. getContent: function() {
  2915. return html.join('').replace(/\n$/, '');
  2916. }
  2917. };
  2918. };
  2919. (function(tinymce) {
  2920. tinymce.html.Serializer = function(settings, schema) {
  2921. var self = this, writer = new tinymce.html.Writer(settings);
  2922. settings = settings || {};
  2923. settings.validate = "validate" in settings ? settings.validate : true;
  2924. self.schema = schema = schema || new tinymce.html.Schema();
  2925. self.writer = writer;
  2926. self.serialize = function(node) {
  2927. var handlers, validate;
  2928. validate = settings.validate;
  2929. handlers = {
  2930. // #text
  2931. 3: function(node, raw) {
  2932. writer.text(node.value, node.raw);
  2933. },
  2934. // #comment
  2935. 8: function(node) {
  2936. writer.comment(node.value);
  2937. },
  2938. // Processing instruction
  2939. 7: function(node) {
  2940. writer.pi(node.name, node.value);
  2941. },
  2942. // Doctype
  2943. 10: function(node) {
  2944. writer.doctype(node.value);
  2945. },
  2946. // CDATA
  2947. 4: function(node) {
  2948. writer.cdata(node.value);
  2949. },
  2950. // Document fragment
  2951. 11: function(node) {
  2952. if ((node = node.firstChild)) {
  2953. do {
  2954. walk(node);
  2955. } while (node = node.next);
  2956. }
  2957. }
  2958. };
  2959. writer.reset();
  2960. function walk(node) {
  2961. var handler = handlers[node.type], name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule;
  2962. if (!handler) {
  2963. name = node.name;
  2964. isEmpty = node.shortEnded;
  2965. attrs = node.attributes;
  2966. // Sort attributes
  2967. if (validate && attrs && attrs.length > 1) {
  2968. sortedAttrs = [];
  2969. sortedAttrs.map = {};
  2970. elementRule = schema.getElementRule(node.name);
  2971. for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
  2972. attrName = elementRule.attributesOrder[i];
  2973. if (attrName in attrs.map) {
  2974. attrValue = attrs.map[attrName];
  2975. sortedAttrs.map[attrName] = attrValue;
  2976. sortedAttrs.push({name: attrName, value: attrValue});
  2977. }
  2978. }
  2979. for (i = 0, l = attrs.length; i < l; i++) {
  2980. attrName = attrs[i].name;
  2981. if (!(attrName in sortedAttrs.map)) {
  2982. attrValue = attrs.map[attrName];
  2983. sortedAttrs.map[attrName] = attrValue;
  2984. sortedAttrs.push({name: attrName, value: attrValue});
  2985. }
  2986. }
  2987. attrs = sortedAttrs;
  2988. }
  2989. writer.start(node.name, attrs, isEmpty);
  2990. if (!isEmpty) {
  2991. if ((node = node.firstChild)) {
  2992. do {
  2993. walk(node);
  2994. } while (node = node.next);
  2995. }
  2996. writer.end(name);
  2997. }
  2998. } else
  2999. handler(node);
  3000. }
  3001. // Serialize element and treat all non elements as fragments
  3002. if (node.type == 1 && !settings.inner)
  3003. walk(node);
  3004. else
  3005. handlers[11](node);
  3006. return writer.getContent();
  3007. };
  3008. }
  3009. })(tinymce);
  3010. (function(tinymce) {
  3011. // Shorten names
  3012. var each = tinymce.each,
  3013. is = tinymce.is,
  3014. isWebKit = tinymce.isWebKit,
  3015. isIE = tinymce.isIE,
  3016. Entities = tinymce.html.Entities,
  3017. simpleSelectorRe = /^([a-z0-9],?)+$/i,
  3018. blockElementsMap = tinymce.html.Schema.blockElementsMap,
  3019. whiteSpaceRegExp = /^[ \t\r\n]*$/;
  3020. tinymce.create('tinymce.dom.DOMUtils', {
  3021. doc : null,
  3022. root : null,
  3023. files : null,
  3024. pixelStyles : /^(top|left|bottom|right|width|height|borderWidth)$/,
  3025. props : {
  3026. "for" : "htmlFor",
  3027. "class" : "className",
  3028. className : "className",
  3029. checked : "checked",
  3030. disabled : "disabled",
  3031. maxlength : "maxLength",
  3032. readonly : "readOnly",
  3033. selected : "selected",
  3034. value : "value",
  3035. id : "id",
  3036. name : "name",
  3037. type : "type"
  3038. },
  3039. DOMUtils : function(d, s) {
  3040. var t = this, globalStyle, name;
  3041. t.doc = d;
  3042. t.win = window;
  3043. t.files = {};
  3044. t.cssFlicker = false;
  3045. t.counter = 0;
  3046. t.stdMode = !tinymce.isIE || d.documentMode >= 8;
  3047. t.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat" || t.stdMode;
  3048. t.hasOuterHTML = "outerHTML" in d.createElement("a");
  3049. t.settings = s = tinymce.extend({
  3050. keep_values : false,
  3051. hex_colors : 1
  3052. }, s);
  3053. t.schema = s.schema;
  3054. t.styles = new tinymce.html.Styles({
  3055. url_converter : s.url_converter,
  3056. url_converter_scope : s.url_converter_scope
  3057. }, s.schema);
  3058. // Fix IE6SP2 flicker and check it failed for pre SP2
  3059. if (tinymce.isIE6) {
  3060. try {
  3061. d.execCommand('BackgroundImageCache', false, true);
  3062. } catch (e) {
  3063. t.cssFlicker = true;
  3064. }
  3065. }
  3066. if (isIE && s.schema) {
  3067. // Add missing HTML 4/5 elements to IE
  3068. ('abbr article aside audio canvas ' +
  3069. 'details figcaption figure footer ' +
  3070. 'header hgroup mark menu meter nav ' +
  3071. 'output progress section summary ' +
  3072. 'time video').replace(/\w+/g, function(name) {
  3073. d.createElement(name);
  3074. });
  3075. // Create all custom elements
  3076. for (name in s.schema.getCustomElements()) {
  3077. d.createElement(name);
  3078. }
  3079. }
  3080. tinymce.addUnload(t.destroy, t);
  3081. },
  3082. getRoot : function() {
  3083. var t = this, s = t.settings;
  3084. return (s && t.get(s.root_element)) || t.doc.body;
  3085. },
  3086. getViewPort : function(w) {
  3087. var d, b;
  3088. w = !w ? this.win : w;
  3089. d = w.document;
  3090. b = this.boxModel ? d.documentElement : d.body;
  3091. // Returns viewport size excluding scrollbars
  3092. return {
  3093. x : w.pageXOffset || b.scrollLeft,
  3094. y : w.pageYOffset || b.scrollTop,
  3095. w : w.innerWidth || b.clientWidth,
  3096. h : w.innerHeight || b.clientHeight
  3097. };
  3098. },
  3099. getRect : function(e) {
  3100. var p, t = this, sr;
  3101. e = t.get(e);
  3102. p = t.getPos(e);
  3103. sr = t.getSize(e);
  3104. return {
  3105. x : p.x,
  3106. y : p.y,
  3107. w : sr.w,
  3108. h : sr.h
  3109. };
  3110. },
  3111. getSize : function(e) {
  3112. var t = this, w, h;
  3113. e = t.get(e);
  3114. w = t.getStyle(e, 'width');
  3115. h = t.getStyle(e, 'height');
  3116. // Non pixel value, then force offset/clientWidth
  3117. if (w.indexOf('px') === -1)
  3118. w = 0;
  3119. // Non pixel value, then force offset/clientWidth
  3120. if (h.indexOf('px') === -1)
  3121. h = 0;
  3122. return {
  3123. w : parseInt(w) || e.offsetWidth || e.clientWidth,
  3124. h : parseInt(h) || e.offsetHeight || e.clientHeight
  3125. };
  3126. },
  3127. getParent : function(n, f, r) {
  3128. return this.getParents(n, f, r, false);
  3129. },
  3130. getParents : function(n, f, r, c) {
  3131. var t = this, na, se = t.settings, o = [];
  3132. n = t.get(n);
  3133. c = c === undefined;
  3134. if (se.strict_root)
  3135. r = r || t.getRoot();
  3136. // Wrap node name as func
  3137. if (is(f, 'string')) {
  3138. na = f;
  3139. if (f === '*') {
  3140. f = function(n) {return n.nodeType == 1;};
  3141. } else {
  3142. f = function(n) {
  3143. return t.is(n, na);
  3144. };
  3145. }
  3146. }
  3147. while (n) {
  3148. if (n == r || !n.nodeType || n.nodeType === 9)
  3149. break;
  3150. if (!f || f(n)) {
  3151. if (c)
  3152. o.push(n);
  3153. else
  3154. return n;
  3155. }
  3156. n = n.parentNode;
  3157. }
  3158. return c ? o : null;
  3159. },
  3160. get : function(e) {
  3161. var n;
  3162. if (e && this.doc && typeof(e) == 'string') {
  3163. n = e;
  3164. e = this.doc.getElementById(e);
  3165. // IE and Opera returns meta elements when they match the specified input ID, but getElementsByName seems to do the trick
  3166. if (e && e.id !== n)
  3167. return this.doc.getElementsByName(n)[1];
  3168. }
  3169. return e;
  3170. },
  3171. getNext : function(node, selector) {
  3172. return this._findSib(node, selector, 'nextSibling');
  3173. },
  3174. getPrev : function(node, selector) {
  3175. return this._findSib(node, selector, 'previousSibling');
  3176. },
  3177. add : function(p, n, a, h, c) {
  3178. var t = this;
  3179. return this.run(p, function(p) {
  3180. var e, k;
  3181. e = is(n, 'string') ? t.doc.createElement(n) : n;
  3182. t.setAttribs(e, a);
  3183. if (h) {
  3184. if (h.nodeType)
  3185. e.appendChild(h);
  3186. else
  3187. t.setHTML(e, h);
  3188. }
  3189. return !c ? p.appendChild(e) : e;
  3190. });
  3191. },
  3192. create : function(n, a, h) {
  3193. return this.add(this.doc.createElement(n), n, a, h, 1);
  3194. },
  3195. createHTML : function(n, a, h) {
  3196. var o = '', t = this, k;
  3197. o += '<' + n;
  3198. for (k in a) {
  3199. if (a.hasOwnProperty(k))
  3200. o += ' ' + k + '="' + t.encode(a[k]) + '"';
  3201. }
  3202. // A call to tinymce.is doesn't work for some odd reason on IE9 possible bug inside their JS runtime
  3203. if (typeof(h) != "undefined")
  3204. return o + '>' + h + '</' + n + '>';
  3205. return o + ' />';
  3206. },
  3207. remove : function(node, keep_children) {
  3208. return this.run(node, function(node) {
  3209. var child, parent = node.parentNode;
  3210. if (!parent)
  3211. return null;
  3212. if (keep_children) {
  3213. while (child = node.firstChild) {
  3214. // IE 8 will crash if you don't remove completely empty text nodes
  3215. if (!tinymce.isIE || child.nodeType !== 3 || child.nodeValue)
  3216. parent.insertBefore(child, node);
  3217. else
  3218. node.removeChild(child);
  3219. }
  3220. }
  3221. return parent.removeChild(node);
  3222. });
  3223. },
  3224. setStyle : function(n, na, v) {
  3225. var t = this;
  3226. return t.run(n, function(e) {
  3227. var s, i;
  3228. s = e.style;
  3229. // Camelcase it, if needed
  3230. na = na.replace(/-(\D)/g, function(a, b){
  3231. return b.toUpperCase();
  3232. });
  3233. // Default px suffix on these
  3234. if (t.pixelStyles.test(na) && (tinymce.is(v, 'number') || /^[\-0-9\.]+$/.test(v)))
  3235. v += 'px';
  3236. switch (na) {
  3237. case 'opacity':
  3238. // IE specific opacity
  3239. if (isIE) {
  3240. s.filter = v === '' ? '' : "alpha(opacity=" + (v * 100) + ")";
  3241. if (!n.currentStyle || !n.currentStyle.hasLayout)
  3242. s.display = 'inline-block';
  3243. }
  3244. // Fix for older browsers
  3245. s[na] = s['-moz-opacity'] = s['-khtml-opacity'] = v || '';
  3246. break;
  3247. case 'float':
  3248. isIE ? s.styleFloat = v : s.cssFloat = v;
  3249. break;
  3250. default:
  3251. s[na] = v || '';
  3252. }
  3253. // Force update of the style data
  3254. if (t.settings.update_styles)
  3255. t.setAttrib(e, 'data-mce-style');
  3256. });
  3257. },
  3258. getStyle : function(n, na, c) {
  3259. n = this.get(n);
  3260. if (!n)
  3261. return;
  3262. // Gecko
  3263. if (this.doc.defaultView && c) {
  3264. // Remove camelcase
  3265. na = na.replace(/[A-Z]/g, function(a){
  3266. return '-' + a;
  3267. });
  3268. try {
  3269. return this.doc.defaultView.getComputedStyle(n, null).getPropertyValue(na);
  3270. } catch (ex) {
  3271. // Old safari might fail
  3272. return null;
  3273. }
  3274. }
  3275. // Camelcase it, if needed
  3276. na = na.replace(/-(\D)/g, function(a, b){
  3277. return b.toUpperCase();
  3278. });
  3279. if (na == 'float')
  3280. na = isIE ? 'styleFloat' : 'cssFloat';
  3281. // IE & Opera
  3282. if (n.currentStyle && c)
  3283. return n.currentStyle[na];
  3284. return n.style ? n.style[na] : undefined;
  3285. },
  3286. setStyles : function(e, o) {
  3287. var t = this, s = t.settings, ol;
  3288. ol = s.update_styles;
  3289. s.update_styles = 0;
  3290. each(o, function(v, n) {
  3291. t.setStyle(e, n, v);
  3292. });
  3293. // Update style info
  3294. s.update_styles = ol;
  3295. if (s.update_styles)
  3296. t.setAttrib(e, s.cssText);
  3297. },
  3298. removeAllAttribs: function(e) {
  3299. return this.run(e, function(e) {
  3300. var i, attrs = e.attributes;
  3301. for (i = attrs.length - 1; i >= 0; i--) {
  3302. e.removeAttributeNode(attrs.item(i));
  3303. }
  3304. });
  3305. },
  3306. setAttrib : function(e, n, v) {
  3307. var t = this;
  3308. // Whats the point
  3309. if (!e || !n)
  3310. return;
  3311. // Strict XML mode
  3312. if (t.settings.strict)
  3313. n = n.toLowerCase();
  3314. return this.run(e, function(e) {
  3315. var s = t.settings;
  3316. var originalValue = e.getAttribute(n);
  3317. if (v !== null) {
  3318. switch (n) {
  3319. case "style":
  3320. if (!is(v, 'string')) {
  3321. each(v, function(v, n) {
  3322. t.setStyle(e, n, v);
  3323. });
  3324. return;
  3325. }
  3326. // No mce_style for elements with these since they might get resized by the user
  3327. if (s.keep_values) {
  3328. if (v && !t._isRes(v))
  3329. e.setAttribute('data-mce-style', v, 2);
  3330. else
  3331. e.removeAttribute('data-mce-style', 2);
  3332. }
  3333. e.style.cssText = v;
  3334. break;
  3335. case "class":
  3336. e.className = v || ''; // Fix IE null bug
  3337. break;
  3338. case "src":
  3339. case "href":
  3340. if (s.keep_values) {
  3341. if (s.url_converter)
  3342. v = s.url_converter.call(s.url_converter_scope || t, v, n, e);
  3343. t.setAttrib(e, 'data-mce-' + n, v, 2);
  3344. }
  3345. break;
  3346. case "shape":
  3347. e.setAttribute('data-mce-style', v);
  3348. break;
  3349. }
  3350. }
  3351. if (is(v) && v !== null && v.length !== 0)
  3352. e.setAttribute(n, '' + v, 2);
  3353. else
  3354. e.removeAttribute(n, 2);
  3355. // fire onChangeAttrib event for attributes that have changed
  3356. if (tinyMCE.activeEditor && originalValue != v) {
  3357. var ed = tinyMCE.activeEditor;
  3358. ed.onSetAttrib.dispatch(ed, e, n, v);
  3359. }
  3360. });
  3361. },
  3362. setAttribs : function(e, o) {
  3363. var t = this;
  3364. return this.run(e, function(e) {
  3365. each(o, function(v, n) {
  3366. t.setAttrib(e, n, v);
  3367. });
  3368. });
  3369. },
  3370. getAttrib : function(e, n, dv) {
  3371. var v, t = this, undef;
  3372. e = t.get(e);
  3373. if (!e || e.nodeType !== 1)
  3374. return dv === undef ? false : dv;
  3375. if (!is(dv))
  3376. dv = '';
  3377. // Try the mce variant for these
  3378. if (/^(src|href|style|coords|shape)$/.test(n)) {
  3379. v = e.getAttribute("data-mce-" + n);
  3380. if (v)
  3381. return v;
  3382. }
  3383. if (isIE && t.props[n]) {
  3384. v = e[t.props[n]];
  3385. v = v && v.nodeValue ? v.nodeValue : v;
  3386. }
  3387. if (!v)
  3388. v = e.getAttribute(n, 2);
  3389. // Check boolean attribs
  3390. if (/^(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)$/.test(n)) {
  3391. if (e[t.props[n]] === true && v === '')
  3392. return n;
  3393. return v ? n : '';
  3394. }
  3395. // Inner input elements will override attributes on form elements
  3396. if (e.nodeName === "FORM" && e.getAttributeNode(n))
  3397. return e.getAttributeNode(n).nodeValue;
  3398. if (n === 'style') {
  3399. v = v || e.style.cssText;
  3400. if (v) {
  3401. v = t.serializeStyle(t.parseStyle(v), e.nodeName);
  3402. if (t.settings.keep_values && !t._isRes(v))
  3403. e.setAttribute('data-mce-style', v);
  3404. }
  3405. }
  3406. // Remove Apple and WebKit stuff
  3407. if (isWebKit && n === "class" && v)
  3408. v = v.replace(/(apple|webkit)\-[a-z\-]+/gi, '');
  3409. // Handle IE issues
  3410. if (isIE) {
  3411. switch (n) {
  3412. case 'rowspan':
  3413. case 'colspan':
  3414. // IE returns 1 as default value
  3415. if (v === 1)
  3416. v = '';
  3417. break;
  3418. case 'size':
  3419. // IE returns +0 as default value for size
  3420. if (v === '+0' || v === 20 || v === 0)
  3421. v = '';
  3422. break;
  3423. case 'width':
  3424. case 'height':
  3425. case 'vspace':
  3426. case 'checked':
  3427. case 'disabled':
  3428. case 'readonly':
  3429. if (v === 0)
  3430. v = '';
  3431. break;
  3432. case 'hspace':
  3433. // IE returns -1 as default value
  3434. if (v === -1)
  3435. v = '';
  3436. break;
  3437. case 'maxlength':
  3438. case 'tabindex':
  3439. // IE returns default value
  3440. if (v === 32768 || v === 2147483647 || v === '32768')
  3441. v = '';
  3442. break;
  3443. case 'multiple':
  3444. case 'compact':
  3445. case 'noshade':
  3446. case 'nowrap':
  3447. if (v === 65535)
  3448. return n;
  3449. return dv;
  3450. case 'shape':
  3451. v = v.toLowerCase();
  3452. break;
  3453. default:
  3454. // IE has odd anonymous function for event attributes
  3455. if (n.indexOf('on') === 0 && v)
  3456. v = tinymce._replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1', '' + v);
  3457. }
  3458. }
  3459. return (v !== undef && v !== null && v !== '') ? '' + v : dv;
  3460. },
  3461. getPos : function(n, ro) {
  3462. var t = this, x = 0, y = 0, e, d = t.doc, r;
  3463. n = t.get(n);
  3464. ro = ro || d.body;
  3465. if (n) {
  3466. // Use getBoundingClientRect if it exists since it's faster than looping offset nodes
  3467. if (n.getBoundingClientRect) {
  3468. n = n.getBoundingClientRect();
  3469. e = t.boxModel ? d.documentElement : d.body;
  3470. // Add scroll offsets from documentElement or body since IE with the wrong box model will use d.body and so do WebKit
  3471. // Also remove the body/documentelement clientTop/clientLeft on IE 6, 7 since they offset the position
  3472. x = n.left + (d.documentElement.scrollLeft || d.body.scrollLeft) - e.clientTop;
  3473. y = n.top + (d.documentElement.scrollTop || d.body.scrollTop) - e.clientLeft;
  3474. return {x : x, y : y};
  3475. }
  3476. r = n;
  3477. while (r && r != ro && r.nodeType) {
  3478. x += r.offsetLeft || 0;
  3479. y += r.offsetTop || 0;
  3480. r = r.offsetParent;
  3481. }
  3482. r = n.parentNode;
  3483. while (r && r != ro && r.nodeType) {
  3484. x -= r.scrollLeft || 0;
  3485. y -= r.scrollTop || 0;
  3486. r = r.parentNode;
  3487. }
  3488. }
  3489. return {x : x, y : y};
  3490. },
  3491. parseStyle : function(st) {
  3492. return this.styles.parse(st);
  3493. },
  3494. serializeStyle : function(o, name) {
  3495. return this.styles.serialize(o, name);
  3496. },
  3497. loadCSS : function(u) {
  3498. var t = this, d = t.doc, head;
  3499. if (!u)
  3500. u = '';
  3501. head = t.select('head')[0];
  3502. each(u.split(','), function(u) {
  3503. var link;
  3504. if (t.files[u])
  3505. return;
  3506. t.files[u] = true;
  3507. link = t.create('link', {rel : 'stylesheet', href : tinymce._addVer(u)});
  3508. // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug
  3509. // This fix seems to resolve that issue by realcing the document ones a stylesheet finishes loading
  3510. // It's ugly but it seems to work fine.
  3511. if (isIE && d.documentMode && d.recalc) {
  3512. link.onload = function() {
  3513. if (d.recalc)
  3514. d.recalc();
  3515. link.onload = null;
  3516. };
  3517. }
  3518. head.appendChild(link);
  3519. });
  3520. },
  3521. addClass : function(e, c) {
  3522. return this.run(e, function(e) {
  3523. var o;
  3524. if (!c)
  3525. return 0;
  3526. if (this.hasClass(e, c))
  3527. return e.className;
  3528. o = this.removeClass(e, c);
  3529. return e.className = (o != '' ? (o + ' ') : '') + c;
  3530. });
  3531. },
  3532. removeClass : function(e, c) {
  3533. var t = this, re;
  3534. return t.run(e, function(e) {
  3535. var v;
  3536. if (t.hasClass(e, c)) {
  3537. if (!re)
  3538. re = new RegExp("(^|\\s+)" + c + "(\\s+|$)", "g");
  3539. v = e.className.replace(re, ' ');
  3540. v = tinymce.trim(v != ' ' ? v : '');
  3541. e.className = v;
  3542. // Empty class attr
  3543. if (!v) {
  3544. e.removeAttribute('class');
  3545. e.removeAttribute('className');
  3546. }
  3547. return v;
  3548. }
  3549. return e.className;
  3550. });
  3551. },
  3552. hasClass : function(n, c) {
  3553. n = this.get(n);
  3554. if (!n || !c)
  3555. return false;
  3556. return (' ' + n.className + ' ').indexOf(' ' + c + ' ') !== -1;
  3557. },
  3558. show : function(e) {
  3559. return this.setStyle(e, 'display', 'block');
  3560. },
  3561. hide : function(e) {
  3562. return this.setStyle(e, 'display', 'none');
  3563. },
  3564. isHidden : function(e) {
  3565. e = this.get(e);
  3566. return !e || e.style.display == 'none' || this.getStyle(e, 'display') == 'none';
  3567. },
  3568. uniqueId : function(p) {
  3569. return (!p ? 'mce_' : p) + (this.counter++);
  3570. },
  3571. setHTML : function(element, html) {
  3572. var self = this;
  3573. return self.run(element, function(element) {
  3574. if (isIE) {
  3575. // Remove all child nodes, IE keeps empty text nodes in DOM
  3576. while (element.firstChild)
  3577. element.removeChild(element.firstChild);
  3578. try {
  3579. // IE will remove comments from the beginning
  3580. // unless you padd the contents with something
  3581. element.innerHTML = '<br />' + html;
  3582. element.removeChild(element.firstChild);
  3583. } catch (ex) {
  3584. // 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
  3585. // This seems to fix this problem
  3586. // Create new div with HTML contents and a BR infront to keep comments
  3587. element = self.create('div');
  3588. element.innerHTML = '<br />' + html;
  3589. // Add all children from div to target
  3590. each (element.childNodes, function(node, i) {
  3591. // Skip br element
  3592. if (i)
  3593. element.appendChild(node);
  3594. });
  3595. }
  3596. } else
  3597. element.innerHTML = html;
  3598. return html;
  3599. });
  3600. },
  3601. getOuterHTML : function(elm) {
  3602. var doc, self = this;
  3603. elm = self.get(elm);
  3604. if (!elm)
  3605. return null;
  3606. if (elm.nodeType === 1 && self.hasOuterHTML)
  3607. return elm.outerHTML;
  3608. doc = (elm.ownerDocument || self.doc).createElement("body");
  3609. doc.appendChild(elm.cloneNode(true));
  3610. return doc.innerHTML;
  3611. },
  3612. setOuterHTML : function(e, h, d) {
  3613. var t = this;
  3614. function setHTML(e, h, d) {
  3615. var n, tp;
  3616. tp = d.createElement("body");
  3617. tp.innerHTML = h;
  3618. n = tp.lastChild;
  3619. while (n) {
  3620. t.insertAfter(n.cloneNode(true), e);
  3621. n = n.previousSibling;
  3622. }
  3623. t.remove(e);
  3624. };
  3625. return this.run(e, function(e) {
  3626. e = t.get(e);
  3627. // Only set HTML on elements
  3628. if (e.nodeType == 1) {
  3629. d = d || e.ownerDocument || t.doc;
  3630. if (isIE) {
  3631. try {
  3632. // Try outerHTML for IE it sometimes produces an unknown runtime error
  3633. if (isIE && e.nodeType == 1)
  3634. e.outerHTML = h;
  3635. else
  3636. setHTML(e, h, d);
  3637. } catch (ex) {
  3638. // Fix for unknown runtime error
  3639. setHTML(e, h, d);
  3640. }
  3641. } else
  3642. setHTML(e, h, d);
  3643. }
  3644. });
  3645. },
  3646. decode : Entities.decode,
  3647. encode : Entities.encodeAllRaw,
  3648. insertAfter : function(node, reference_node) {
  3649. reference_node = this.get(reference_node);
  3650. return this.run(node, function(node) {
  3651. var parent, nextSibling;
  3652. parent = reference_node.parentNode;
  3653. nextSibling = reference_node.nextSibling;
  3654. if (nextSibling)
  3655. parent.insertBefore(node, nextSibling);
  3656. else
  3657. parent.appendChild(node);
  3658. return node;
  3659. });
  3660. },
  3661. isBlock : function(node) {
  3662. var type = node.nodeType;
  3663. // If it's a node then check the type and use the nodeName
  3664. if (type)
  3665. return !!(type === 1 && blockElementsMap[node.nodeName]);
  3666. return !!blockElementsMap[node];
  3667. },
  3668. replace : function(n, o, k) {
  3669. var t = this;
  3670. if (is(o, 'array'))
  3671. n = n.cloneNode(true);
  3672. return t.run(o, function(o) {
  3673. if (k) {
  3674. each(tinymce.grep(o.childNodes), function(c) {
  3675. n.appendChild(c);
  3676. });
  3677. }
  3678. return o.parentNode.replaceChild(n, o);
  3679. });
  3680. },
  3681. rename : function(elm, name) {
  3682. var t = this, newElm;
  3683. if (elm.nodeName != name.toUpperCase()) {
  3684. // Rename block element
  3685. newElm = t.create(name);
  3686. // Copy attribs to new block
  3687. each(t.getAttribs(elm), function(attr_node) {
  3688. t.setAttrib(newElm, attr_node.nodeName, t.getAttrib(elm, attr_node.nodeName));
  3689. });
  3690. // Replace block
  3691. t.replace(newElm, elm, 1);
  3692. }
  3693. return newElm || elm;
  3694. },
  3695. findCommonAncestor : function(a, b) {
  3696. var ps = a, pe;
  3697. while (ps) {
  3698. pe = b;
  3699. while (pe && ps != pe)
  3700. pe = pe.parentNode;
  3701. if (ps == pe)
  3702. break;
  3703. ps = ps.parentNode;
  3704. }
  3705. if (!ps && a.ownerDocument)
  3706. return a.ownerDocument.documentElement;
  3707. return ps;
  3708. },
  3709. toHex : function(s) {
  3710. var c = /^\s*rgb\s*?\(\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?\)\s*$/i.exec(s);
  3711. function hex(s) {
  3712. s = parseInt(s).toString(16);
  3713. return s.length > 1 ? s : '0' + s; // 0 -> 00
  3714. };
  3715. if (c) {
  3716. s = '#' + hex(c[1]) + hex(c[2]) + hex(c[3]);
  3717. return s;
  3718. }
  3719. return s;
  3720. },
  3721. getClasses : function() {
  3722. var t = this, cl = [], i, lo = {}, f = t.settings.class_filter, ov;
  3723. if (t.classes)
  3724. return t.classes;
  3725. function addClasses(s) {
  3726. // IE style imports
  3727. each(s.imports, function(r) {
  3728. addClasses(r);
  3729. });
  3730. each(s.cssRules || s.rules, function(r) {
  3731. // Real type or fake it on IE
  3732. switch (r.type || 1) {
  3733. // Rule
  3734. case 1:
  3735. if (r.selectorText) {
  3736. each(r.selectorText.split(','), function(v) {
  3737. v = v.replace(/^\s*|\s*$|^\s\./g, "");
  3738. // Is internal or it doesn't contain a class
  3739. if (/\.mce/.test(v) || !/\.[\w\-]+$/.test(v))
  3740. return;
  3741. // Remove everything but class name
  3742. ov = v;
  3743. v = tinymce._replace(/.*\.([a-z0-9_\-]+).*/i, '$1', v);
  3744. // Filter classes
  3745. if (f && !(v = f(v, ov)))
  3746. return;
  3747. if (!lo[v]) {
  3748. cl.push({'class' : v});
  3749. lo[v] = 1;
  3750. }
  3751. });
  3752. }
  3753. break;
  3754. // Import
  3755. case 3:
  3756. addClasses(r.styleSheet);
  3757. break;
  3758. }
  3759. });
  3760. };
  3761. try {
  3762. each(t.doc.styleSheets, addClasses);
  3763. } catch (ex) {
  3764. // Ignore
  3765. }
  3766. if (cl.length > 0)
  3767. t.classes = cl;
  3768. return cl;
  3769. },
  3770. run : function(e, f, s) {
  3771. var t = this, o;
  3772. if (t.doc && typeof(e) === 'string')
  3773. e = t.get(e);
  3774. if (!e)
  3775. return false;
  3776. s = s || this;
  3777. if (!e.nodeType && (e.length || e.length === 0)) {
  3778. o = [];
  3779. each(e, function(e, i) {
  3780. if (e) {
  3781. if (typeof(e) == 'string')
  3782. e = t.doc.getElementById(e);
  3783. o.push(f.call(s, e, i));
  3784. }
  3785. });
  3786. return o;
  3787. }
  3788. return f.call(s, e);
  3789. },
  3790. getAttribs : function(n) {
  3791. var o;
  3792. n = this.get(n);
  3793. if (!n)
  3794. return [];
  3795. if (isIE) {
  3796. o = [];
  3797. // Object will throw exception in IE
  3798. if (n.nodeName == 'OBJECT')
  3799. return n.attributes;
  3800. // IE doesn't keep the selected attribute if you clone option elements
  3801. if (n.nodeName === 'OPTION' && this.getAttrib(n, 'selected'))
  3802. o.push({specified : 1, nodeName : 'selected'});
  3803. // It's crazy that this is faster in IE but it's because it returns all attributes all the time
  3804. n.cloneNode(false).outerHTML.replace(/<\/?[\w:\-]+ ?|=[\"][^\"]+\"|=\'[^\']+\'|=[\w\-]+|>/gi, '').replace(/[\w:\-]+/gi, function(a) {
  3805. o.push({specified : 1, nodeName : a});
  3806. });
  3807. return o;
  3808. }
  3809. return n.attributes;
  3810. },
  3811. isEmpty : function(node, elements) {
  3812. var self = this, i, attributes, type, walker, name, parentNode;
  3813. node = node.firstChild;
  3814. if (node) {
  3815. walker = new tinymce.dom.TreeWalker(node);
  3816. elements = elements || self.schema ? self.schema.getNonEmptyElements() : null;
  3817. do {
  3818. type = node.nodeType;
  3819. if (type === 1) {
  3820. // Ignore bogus elements
  3821. if (node.getAttribute('data-mce-bogus'))
  3822. continue;
  3823. // Keep empty elements like <img />
  3824. name = node.nodeName.toLowerCase();
  3825. if (elements && elements[name]) {
  3826. // Ignore single BR elements in blocks like <p><br /></p>
  3827. parentNode = node.parentNode;
  3828. if (name === 'br' && self.isBlock(parentNode) && parentNode.firstChild === node && parentNode.lastChild === node) {
  3829. continue;
  3830. }
  3831. return false;
  3832. }
  3833. // Keep elements with data-bookmark attributes or name attribute like <a name="1"></a>
  3834. attributes = self.getAttribs(node);
  3835. i = node.attributes.length;
  3836. while (i--) {
  3837. name = node.attributes[i].nodeName;
  3838. if (name === "name" || name === 'data-mce-bookmark')
  3839. return false;
  3840. }
  3841. }
  3842. // Keep non whitespace text nodes
  3843. if ((type === 3 && !whiteSpaceRegExp.test(node.nodeValue)))
  3844. return false;
  3845. } while (node = walker.next());
  3846. }
  3847. return true;
  3848. },
  3849. destroy : function(s) {
  3850. var t = this;
  3851. if (t.events)
  3852. t.events.destroy();
  3853. t.win = t.doc = t.root = t.events = null;
  3854. // Manual destroy then remove unload handler
  3855. if (!s)
  3856. tinymce.removeUnload(t.destroy);
  3857. },
  3858. createRng : function() {
  3859. var d = this.doc;
  3860. return d.createRange ? d.createRange() : new tinymce.dom.Range(this);
  3861. },
  3862. nodeIndex : function(node, normalized) {
  3863. var idx = 0, lastNodeType, lastNode, nodeType;
  3864. if (node) {
  3865. for (lastNodeType = node.nodeType, node = node.previousSibling, lastNode = node; node; node = node.previousSibling) {
  3866. nodeType = node.nodeType;
  3867. // Normalize text nodes
  3868. if (normalized && nodeType == 3) {
  3869. if (nodeType == lastNodeType || !node.nodeValue.length)
  3870. continue;
  3871. }
  3872. idx++;
  3873. lastNodeType = nodeType;
  3874. }
  3875. }
  3876. return idx;
  3877. },
  3878. split : function(pe, e, re) {
  3879. var t = this, r = t.createRng(), bef, aft, pa;
  3880. // W3C valid browsers tend to leave empty nodes to the left/right side of the contents, this makes sense
  3881. // but we don't want that in our code since it serves no purpose for the end user
  3882. // For example if this is chopped:
  3883. // <p>text 1<span><b>CHOP</b></span>text 2</p>
  3884. // would produce:
  3885. // <p>text 1<span></span></p><b>CHOP</b><p><span></span>text 2</p>
  3886. // this function will then trim of empty edges and produce:
  3887. // <p>text 1</p><b>CHOP</b><p>text 2</p>
  3888. function trim(node) {
  3889. var i, children = node.childNodes, type = node.nodeType;
  3890. function surroundedBySpans(node) {
  3891. var previousIsSpan = node.previousSibling && node.previousSibling.nodeName == 'SPAN';
  3892. var nextIsSpan = node.nextSibling && node.nextSibling.nodeName == 'SPAN';
  3893. return previousIsSpan && nextIsSpan;
  3894. }
  3895. if (type == 1 && node.getAttribute('data-mce-type') == 'bookmark')
  3896. return;
  3897. for (i = children.length - 1; i >= 0; i--)
  3898. trim(children[i]);
  3899. if (type != 9) {
  3900. // Keep non whitespace text nodes
  3901. if (type == 3 && node.nodeValue.length > 0) {
  3902. // If parent element isn't a block or there isn't any useful contents for example "<p> </p>"
  3903. // Also keep text nodes with only spaces if surrounded by spans.
  3904. // eg. "<p><span>a</span> <span>b</span></p>" should keep space between a and b
  3905. var trimmedLength = tinymce.trim(node.nodeValue).length;
  3906. if (!t.isBlock(node.parentNode) || trimmedLength > 0 || trimmedLength == 0 && surroundedBySpans(node))
  3907. return;
  3908. } else if (type == 1) {
  3909. // If the only child is a bookmark then move it up
  3910. children = node.childNodes;
  3911. if (children.length == 1 && children[0] && children[0].nodeType == 1 && children[0].getAttribute('data-mce-type') == 'bookmark')
  3912. node.parentNode.insertBefore(children[0], node);
  3913. // Keep non empty elements or img, hr etc
  3914. if (children.length || /^(br|hr|input|img)$/i.test(node.nodeName))
  3915. return;
  3916. }
  3917. t.remove(node);
  3918. }
  3919. return node;
  3920. };
  3921. if (pe && e) {
  3922. // Get before chunk
  3923. r.setStart(pe.parentNode, t.nodeIndex(pe));
  3924. r.setEnd(e.parentNode, t.nodeIndex(e));
  3925. bef = r.extractContents();
  3926. // Get after chunk
  3927. r = t.createRng();
  3928. r.setStart(e.parentNode, t.nodeIndex(e) + 1);
  3929. r.setEnd(pe.parentNode, t.nodeIndex(pe) + 1);
  3930. aft = r.extractContents();
  3931. // Insert before chunk
  3932. pa = pe.parentNode;
  3933. pa.insertBefore(trim(bef), pe);
  3934. // Insert middle chunk
  3935. if (re)
  3936. pa.replaceChild(re, e);
  3937. else
  3938. pa.insertBefore(e, pe);
  3939. // Insert after chunk
  3940. pa.insertBefore(trim(aft), pe);
  3941. t.remove(pe);
  3942. return re || e;
  3943. }
  3944. },
  3945. bind : function(target, name, func, scope) {
  3946. var t = this;
  3947. if (!t.events)
  3948. t.events = new tinymce.dom.EventUtils();
  3949. return t.events.add(target, name, func, scope || this);
  3950. },
  3951. unbind : function(target, name, func) {
  3952. var t = this;
  3953. if (!t.events)
  3954. t.events = new tinymce.dom.EventUtils();
  3955. return t.events.remove(target, name, func);
  3956. },
  3957. _findSib : function(node, selector, name) {
  3958. var t = this, f = selector;
  3959. if (node) {
  3960. // If expression make a function of it using is
  3961. if (is(f, 'string')) {
  3962. f = function(node) {
  3963. return t.is(node, selector);
  3964. };
  3965. }
  3966. // Loop all siblings
  3967. for (node = node[name]; node; node = node[name]) {
  3968. if (f(node))
  3969. return node;
  3970. }
  3971. }
  3972. return null;
  3973. },
  3974. _isRes : function(c) {
  3975. // Is live resizble element
  3976. return /^(top|left|bottom|right|width|height)/i.test(c) || /;\s*(top|left|bottom|right|width|height)/i.test(c);
  3977. }
  3978. /*
  3979. walk : function(n, f, s) {
  3980. var d = this.doc, w;
  3981. if (d.createTreeWalker) {
  3982. w = d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false);
  3983. while ((n = w.nextNode()) != null)
  3984. f.call(s || this, n);
  3985. } else
  3986. tinymce.walk(n, f, 'childNodes', s);
  3987. }
  3988. */
  3989. /*
  3990. toRGB : function(s) {
  3991. var c = /^\s*?#([0-9A-F]{2})([0-9A-F]{1,2})([0-9A-F]{2})?\s*?$/.exec(s);
  3992. if (c) {
  3993. // #FFF -> #FFFFFF
  3994. if (!is(c[3]))
  3995. c[3] = c[2] = c[1];
  3996. return "rgb(" + parseInt(c[1], 16) + "," + parseInt(c[2], 16) + "," + parseInt(c[3], 16) + ")";
  3997. }
  3998. return s;
  3999. }
  4000. */
  4001. });
  4002. tinymce.DOM = new tinymce.dom.DOMUtils(document, {process_html : 0});
  4003. })(tinymce);
  4004. (function(ns) {
  4005. // Range constructor
  4006. function Range(dom) {
  4007. var t = this,
  4008. doc = dom.doc,
  4009. EXTRACT = 0,
  4010. CLONE = 1,
  4011. DELETE = 2,
  4012. TRUE = true,
  4013. FALSE = false,
  4014. START_OFFSET = 'startOffset',
  4015. START_CONTAINER = 'startContainer',
  4016. END_CONTAINER = 'endContainer',
  4017. END_OFFSET = 'endOffset',
  4018. extend = tinymce.extend,
  4019. nodeIndex = dom.nodeIndex;
  4020. extend(t, {
  4021. // Inital states
  4022. startContainer : doc,
  4023. startOffset : 0,
  4024. endContainer : doc,
  4025. endOffset : 0,
  4026. collapsed : TRUE,
  4027. commonAncestorContainer : doc,
  4028. // Range constants
  4029. START_TO_START : 0,
  4030. START_TO_END : 1,
  4031. END_TO_END : 2,
  4032. END_TO_START : 3,
  4033. // Public methods
  4034. setStart : setStart,
  4035. setEnd : setEnd,
  4036. setStartBefore : setStartBefore,
  4037. setStartAfter : setStartAfter,
  4038. setEndBefore : setEndBefore,
  4039. setEndAfter : setEndAfter,
  4040. collapse : collapse,
  4041. selectNode : selectNode,
  4042. selectNodeContents : selectNodeContents,
  4043. compareBoundaryPoints : compareBoundaryPoints,
  4044. deleteContents : deleteContents,
  4045. extractContents : extractContents,
  4046. cloneContents : cloneContents,
  4047. insertNode : insertNode,
  4048. surroundContents : surroundContents,
  4049. cloneRange : cloneRange
  4050. });
  4051. function setStart(n, o) {
  4052. _setEndPoint(TRUE, n, o);
  4053. };
  4054. function setEnd(n, o) {
  4055. _setEndPoint(FALSE, n, o);
  4056. };
  4057. function setStartBefore(n) {
  4058. setStart(n.parentNode, nodeIndex(n));
  4059. };
  4060. function setStartAfter(n) {
  4061. setStart(n.parentNode, nodeIndex(n) + 1);
  4062. };
  4063. function setEndBefore(n) {
  4064. setEnd(n.parentNode, nodeIndex(n));
  4065. };
  4066. function setEndAfter(n) {
  4067. setEnd(n.parentNode, nodeIndex(n) + 1);
  4068. };
  4069. function collapse(ts) {
  4070. if (ts) {
  4071. t[END_CONTAINER] = t[START_CONTAINER];
  4072. t[END_OFFSET] = t[START_OFFSET];
  4073. } else {
  4074. t[START_CONTAINER] = t[END_CONTAINER];
  4075. t[START_OFFSET] = t[END_OFFSET];
  4076. }
  4077. t.collapsed = TRUE;
  4078. };
  4079. function selectNode(n) {
  4080. setStartBefore(n);
  4081. setEndAfter(n);
  4082. };
  4083. function selectNodeContents(n) {
  4084. setStart(n, 0);
  4085. setEnd(n, n.nodeType === 1 ? n.childNodes.length : n.nodeValue.length);
  4086. };
  4087. function compareBoundaryPoints(h, r) {
  4088. var sc = t[START_CONTAINER], so = t[START_OFFSET], ec = t[END_CONTAINER], eo = t[END_OFFSET],
  4089. rsc = r.startContainer, rso = r.startOffset, rec = r.endContainer, reo = r.endOffset;
  4090. // Check START_TO_START
  4091. if (h === 0)
  4092. return _compareBoundaryPoints(sc, so, rsc, rso);
  4093. // Check START_TO_END
  4094. if (h === 1)
  4095. return _compareBoundaryPoints(ec, eo, rsc, rso);
  4096. // Check END_TO_END
  4097. if (h === 2)
  4098. return _compareBoundaryPoints(ec, eo, rec, reo);
  4099. // Check END_TO_START
  4100. if (h === 3)
  4101. return _compareBoundaryPoints(sc, so, rec, reo);
  4102. };
  4103. function deleteContents() {
  4104. _traverse(DELETE);
  4105. };
  4106. function extractContents() {
  4107. return _traverse(EXTRACT);
  4108. };
  4109. function cloneContents() {
  4110. return _traverse(CLONE);
  4111. };
  4112. function insertNode(n) {
  4113. var startContainer = this[START_CONTAINER],
  4114. startOffset = this[START_OFFSET], nn, o;
  4115. // Node is TEXT_NODE or CDATA
  4116. if ((startContainer.nodeType === 3 || startContainer.nodeType === 4) && startContainer.nodeValue) {
  4117. if (!startOffset) {
  4118. // At the start of text
  4119. startContainer.parentNode.insertBefore(n, startContainer);
  4120. } else if (startOffset >= startContainer.nodeValue.length) {
  4121. // At the end of text
  4122. dom.insertAfter(n, startContainer);
  4123. } else {
  4124. // Middle, need to split
  4125. nn = startContainer.splitText(startOffset);
  4126. startContainer.parentNode.insertBefore(n, nn);
  4127. }
  4128. } else {
  4129. // Insert element node
  4130. if (startContainer.childNodes.length > 0)
  4131. o = startContainer.childNodes[startOffset];
  4132. if (o)
  4133. startContainer.insertBefore(n, o);
  4134. else
  4135. startContainer.appendChild(n);
  4136. }
  4137. };
  4138. function surroundContents(n) {
  4139. var f = t.extractContents();
  4140. t.insertNode(n);
  4141. n.appendChild(f);
  4142. t.selectNode(n);
  4143. };
  4144. function cloneRange() {
  4145. return extend(new Range(dom), {
  4146. startContainer : t[START_CONTAINER],
  4147. startOffset : t[START_OFFSET],
  4148. endContainer : t[END_CONTAINER],
  4149. endOffset : t[END_OFFSET],
  4150. collapsed : t.collapsed,
  4151. commonAncestorContainer : t.commonAncestorContainer
  4152. });
  4153. };
  4154. // Private methods
  4155. function _getSelectedNode(container, offset) {
  4156. var child;
  4157. if (container.nodeType == 3 /* TEXT_NODE */)
  4158. return container;
  4159. if (offset < 0)
  4160. return container;
  4161. child = container.firstChild;
  4162. while (child && offset > 0) {
  4163. --offset;
  4164. child = child.nextSibling;
  4165. }
  4166. if (child)
  4167. return child;
  4168. return container;
  4169. };
  4170. function _isCollapsed() {
  4171. return (t[START_CONTAINER] == t[END_CONTAINER] && t[START_OFFSET] == t[END_OFFSET]);
  4172. };
  4173. function _compareBoundaryPoints(containerA, offsetA, containerB, offsetB) {
  4174. var c, offsetC, n, cmnRoot, childA, childB;
  4175. // In the first case the boundary-points have the same container. A is before B
  4176. // if its offset is less than the offset of B, A is equal to B if its offset is
  4177. // equal to the offset of B, and A is after B if its offset is greater than the
  4178. // offset of B.
  4179. if (containerA == containerB) {
  4180. if (offsetA == offsetB)
  4181. return 0; // equal
  4182. if (offsetA < offsetB)
  4183. return -1; // before
  4184. return 1; // after
  4185. }
  4186. // In the second case a child node C of the container of A is an ancestor
  4187. // container of B. In this case, A is before B if the offset of A is less than or
  4188. // equal to the index of the child node C and A is after B otherwise.
  4189. c = containerB;
  4190. while (c && c.parentNode != containerA)
  4191. c = c.parentNode;
  4192. if (c) {
  4193. offsetC = 0;
  4194. n = containerA.firstChild;
  4195. while (n != c && offsetC < offsetA) {
  4196. offsetC++;
  4197. n = n.nextSibling;
  4198. }
  4199. if (offsetA <= offsetC)
  4200. return -1; // before
  4201. return 1; // after
  4202. }
  4203. // In the third case a child node C of the container of B is an ancestor container
  4204. // of A. In this case, A is before B if the index of the child node C is less than
  4205. // the offset of B and A is after B otherwise.
  4206. c = containerA;
  4207. while (c && c.parentNode != containerB) {
  4208. c = c.parentNode;
  4209. }
  4210. if (c) {
  4211. offsetC = 0;
  4212. n = containerB.firstChild;
  4213. while (n != c && offsetC < offsetB) {
  4214. offsetC++;
  4215. n = n.nextSibling;
  4216. }
  4217. if (offsetC < offsetB)
  4218. return -1; // before
  4219. return 1; // after
  4220. }
  4221. // In the fourth case, none of three other cases hold: the containers of A and B
  4222. // are siblings or descendants of sibling nodes. In this case, A is before B if
  4223. // the container of A is before the container of B in a pre-order traversal of the
  4224. // Ranges' context tree and A is after B otherwise.
  4225. cmnRoot = dom.findCommonAncestor(containerA, containerB);
  4226. childA = containerA;
  4227. while (childA && childA.parentNode != cmnRoot)
  4228. childA = childA.parentNode;
  4229. if (!childA)
  4230. childA = cmnRoot;
  4231. childB = containerB;
  4232. while (childB && childB.parentNode != cmnRoot)
  4233. childB = childB.parentNode;
  4234. if (!childB)
  4235. childB = cmnRoot;
  4236. if (childA == childB)
  4237. return 0; // equal
  4238. n = cmnRoot.firstChild;
  4239. while (n) {
  4240. if (n == childA)
  4241. return -1; // before
  4242. if (n == childB)
  4243. return 1; // after
  4244. n = n.nextSibling;
  4245. }
  4246. };
  4247. function _setEndPoint(st, n, o) {
  4248. var ec, sc;
  4249. if (st) {
  4250. t[START_CONTAINER] = n;
  4251. t[START_OFFSET] = o;
  4252. } else {
  4253. t[END_CONTAINER] = n;
  4254. t[END_OFFSET] = o;
  4255. }
  4256. // If one boundary-point of a Range is set to have a root container
  4257. // other than the current one for the Range, the Range is collapsed to
  4258. // the new position. This enforces the restriction that both boundary-
  4259. // points of a Range must have the same root container.
  4260. ec = t[END_CONTAINER];
  4261. while (ec.parentNode)
  4262. ec = ec.parentNode;
  4263. sc = t[START_CONTAINER];
  4264. while (sc.parentNode)
  4265. sc = sc.parentNode;
  4266. if (sc == ec) {
  4267. // The start position of a Range is guaranteed to never be after the
  4268. // end position. To enforce this restriction, if the start is set to
  4269. // be at a position after the end, the Range is collapsed to that
  4270. // position.
  4271. if (_compareBoundaryPoints(t[START_CONTAINER], t[START_OFFSET], t[END_CONTAINER], t[END_OFFSET]) > 0)
  4272. t.collapse(st);
  4273. } else
  4274. t.collapse(st);
  4275. t.collapsed = _isCollapsed();
  4276. t.commonAncestorContainer = dom.findCommonAncestor(t[START_CONTAINER], t[END_CONTAINER]);
  4277. };
  4278. function _traverse(how) {
  4279. var c, endContainerDepth = 0, startContainerDepth = 0, p, depthDiff, startNode, endNode, sp, ep;
  4280. if (t[START_CONTAINER] == t[END_CONTAINER])
  4281. return _traverseSameContainer(how);
  4282. for (c = t[END_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  4283. if (p == t[START_CONTAINER])
  4284. return _traverseCommonStartContainer(c, how);
  4285. ++endContainerDepth;
  4286. }
  4287. for (c = t[START_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  4288. if (p == t[END_CONTAINER])
  4289. return _traverseCommonEndContainer(c, how);
  4290. ++startContainerDepth;
  4291. }
  4292. depthDiff = startContainerDepth - endContainerDepth;
  4293. startNode = t[START_CONTAINER];
  4294. while (depthDiff > 0) {
  4295. startNode = startNode.parentNode;
  4296. depthDiff--;
  4297. }
  4298. endNode = t[END_CONTAINER];
  4299. while (depthDiff < 0) {
  4300. endNode = endNode.parentNode;
  4301. depthDiff++;
  4302. }
  4303. // ascend the ancestor hierarchy until we have a common parent.
  4304. for (sp = startNode.parentNode, ep = endNode.parentNode; sp != ep; sp = sp.parentNode, ep = ep.parentNode) {
  4305. startNode = sp;
  4306. endNode = ep;
  4307. }
  4308. return _traverseCommonAncestors(startNode, endNode, how);
  4309. };
  4310. function _traverseSameContainer(how) {
  4311. var frag, s, sub, n, cnt, sibling, xferNode;
  4312. if (how != DELETE)
  4313. frag = doc.createDocumentFragment();
  4314. // If selection is empty, just return the fragment
  4315. if (t[START_OFFSET] == t[END_OFFSET])
  4316. return frag;
  4317. // Text node needs special case handling
  4318. if (t[START_CONTAINER].nodeType == 3 /* TEXT_NODE */) {
  4319. // get the substring
  4320. s = t[START_CONTAINER].nodeValue;
  4321. sub = s.substring(t[START_OFFSET], t[END_OFFSET]);
  4322. // set the original text node to its new value
  4323. if (how != CLONE) {
  4324. t[START_CONTAINER].deleteData(t[START_OFFSET], t[END_OFFSET] - t[START_OFFSET]);
  4325. // Nothing is partially selected, so collapse to start point
  4326. t.collapse(TRUE);
  4327. }
  4328. if (how == DELETE)
  4329. return;
  4330. frag.appendChild(doc.createTextNode(sub));
  4331. return frag;
  4332. }
  4333. // Copy nodes between the start/end offsets.
  4334. n = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]);
  4335. cnt = t[END_OFFSET] - t[START_OFFSET];
  4336. while (cnt > 0) {
  4337. sibling = n.nextSibling;
  4338. xferNode = _traverseFullySelected(n, how);
  4339. if (frag)
  4340. frag.appendChild( xferNode );
  4341. --cnt;
  4342. n = sibling;
  4343. }
  4344. // Nothing is partially selected, so collapse to start point
  4345. if (how != CLONE)
  4346. t.collapse(TRUE);
  4347. return frag;
  4348. };
  4349. function _traverseCommonStartContainer(endAncestor, how) {
  4350. var frag, n, endIdx, cnt, sibling, xferNode;
  4351. if (how != DELETE)
  4352. frag = doc.createDocumentFragment();
  4353. n = _traverseRightBoundary(endAncestor, how);
  4354. if (frag)
  4355. frag.appendChild(n);
  4356. endIdx = nodeIndex(endAncestor);
  4357. cnt = endIdx - t[START_OFFSET];
  4358. if (cnt <= 0) {
  4359. // Collapse to just before the endAncestor, which
  4360. // is partially selected.
  4361. if (how != CLONE) {
  4362. t.setEndBefore(endAncestor);
  4363. t.collapse(FALSE);
  4364. }
  4365. return frag;
  4366. }
  4367. n = endAncestor.previousSibling;
  4368. while (cnt > 0) {
  4369. sibling = n.previousSibling;
  4370. xferNode = _traverseFullySelected(n, how);
  4371. if (frag)
  4372. frag.insertBefore(xferNode, frag.firstChild);
  4373. --cnt;
  4374. n = sibling;
  4375. }
  4376. // Collapse to just before the endAncestor, which
  4377. // is partially selected.
  4378. if (how != CLONE) {
  4379. t.setEndBefore(endAncestor);
  4380. t.collapse(FALSE);
  4381. }
  4382. return frag;
  4383. };
  4384. function _traverseCommonEndContainer(startAncestor, how) {
  4385. var frag, startIdx, n, cnt, sibling, xferNode;
  4386. if (how != DELETE)
  4387. frag = doc.createDocumentFragment();
  4388. n = _traverseLeftBoundary(startAncestor, how);
  4389. if (frag)
  4390. frag.appendChild(n);
  4391. startIdx = nodeIndex(startAncestor);
  4392. ++startIdx; // Because we already traversed it
  4393. cnt = t[END_OFFSET] - startIdx;
  4394. n = startAncestor.nextSibling;
  4395. while (cnt > 0) {
  4396. sibling = n.nextSibling;
  4397. xferNode = _traverseFullySelected(n, how);
  4398. if (frag)
  4399. frag.appendChild(xferNode);
  4400. --cnt;
  4401. n = sibling;
  4402. }
  4403. if (how != CLONE) {
  4404. t.setStartAfter(startAncestor);
  4405. t.collapse(TRUE);
  4406. }
  4407. return frag;
  4408. };
  4409. function _traverseCommonAncestors(startAncestor, endAncestor, how) {
  4410. var n, frag, commonParent, startOffset, endOffset, cnt, sibling, nextSibling;
  4411. if (how != DELETE)
  4412. frag = doc.createDocumentFragment();
  4413. n = _traverseLeftBoundary(startAncestor, how);
  4414. if (frag)
  4415. frag.appendChild(n);
  4416. commonParent = startAncestor.parentNode;
  4417. startOffset = nodeIndex(startAncestor);
  4418. endOffset = nodeIndex(endAncestor);
  4419. ++startOffset;
  4420. cnt = endOffset - startOffset;
  4421. sibling = startAncestor.nextSibling;
  4422. while (cnt > 0) {
  4423. nextSibling = sibling.nextSibling;
  4424. n = _traverseFullySelected(sibling, how);
  4425. if (frag)
  4426. frag.appendChild(n);
  4427. sibling = nextSibling;
  4428. --cnt;
  4429. }
  4430. n = _traverseRightBoundary(endAncestor, how);
  4431. if (frag)
  4432. frag.appendChild(n);
  4433. if (how != CLONE) {
  4434. t.setStartAfter(startAncestor);
  4435. t.collapse(TRUE);
  4436. }
  4437. return frag;
  4438. };
  4439. function _traverseRightBoundary(root, how) {
  4440. var next = _getSelectedNode(t[END_CONTAINER], t[END_OFFSET] - 1), parent, clonedParent, prevSibling, clonedChild, clonedGrandParent, isFullySelected = next != t[END_CONTAINER];
  4441. if (next == root)
  4442. return _traverseNode(next, isFullySelected, FALSE, how);
  4443. parent = next.parentNode;
  4444. clonedParent = _traverseNode(parent, FALSE, FALSE, how);
  4445. while (parent) {
  4446. while (next) {
  4447. prevSibling = next.previousSibling;
  4448. clonedChild = _traverseNode(next, isFullySelected, FALSE, how);
  4449. if (how != DELETE)
  4450. clonedParent.insertBefore(clonedChild, clonedParent.firstChild);
  4451. isFullySelected = TRUE;
  4452. next = prevSibling;
  4453. }
  4454. if (parent == root)
  4455. return clonedParent;
  4456. next = parent.previousSibling;
  4457. parent = parent.parentNode;
  4458. clonedGrandParent = _traverseNode(parent, FALSE, FALSE, how);
  4459. if (how != DELETE)
  4460. clonedGrandParent.appendChild(clonedParent);
  4461. clonedParent = clonedGrandParent;
  4462. }
  4463. };
  4464. function _traverseLeftBoundary(root, how) {
  4465. var next = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]), isFullySelected = next != t[START_CONTAINER], parent, clonedParent, nextSibling, clonedChild, clonedGrandParent;
  4466. if (next == root)
  4467. return _traverseNode(next, isFullySelected, TRUE, how);
  4468. parent = next.parentNode;
  4469. clonedParent = _traverseNode(parent, FALSE, TRUE, how);
  4470. while (parent) {
  4471. while (next) {
  4472. nextSibling = next.nextSibling;
  4473. clonedChild = _traverseNode(next, isFullySelected, TRUE, how);
  4474. if (how != DELETE)
  4475. clonedParent.appendChild(clonedChild);
  4476. isFullySelected = TRUE;
  4477. next = nextSibling;
  4478. }
  4479. if (parent == root)
  4480. return clonedParent;
  4481. next = parent.nextSibling;
  4482. parent = parent.parentNode;
  4483. clonedGrandParent = _traverseNode(parent, FALSE, TRUE, how);
  4484. if (how != DELETE)
  4485. clonedGrandParent.appendChild(clonedParent);
  4486. clonedParent = clonedGrandParent;
  4487. }
  4488. };
  4489. function _traverseNode(n, isFullySelected, isLeft, how) {
  4490. var txtValue, newNodeValue, oldNodeValue, offset, newNode;
  4491. if (isFullySelected)
  4492. return _traverseFullySelected(n, how);
  4493. if (n.nodeType == 3 /* TEXT_NODE */) {
  4494. txtValue = n.nodeValue;
  4495. if (isLeft) {
  4496. offset = t[START_OFFSET];
  4497. newNodeValue = txtValue.substring(offset);
  4498. oldNodeValue = txtValue.substring(0, offset);
  4499. } else {
  4500. offset = t[END_OFFSET];
  4501. newNodeValue = txtValue.substring(0, offset);
  4502. oldNodeValue = txtValue.substring(offset);
  4503. }
  4504. if (how != CLONE)
  4505. n.nodeValue = oldNodeValue;
  4506. if (how == DELETE)
  4507. return;
  4508. newNode = n.cloneNode(FALSE);
  4509. newNode.nodeValue = newNodeValue;
  4510. return newNode;
  4511. }
  4512. if (how == DELETE)
  4513. return;
  4514. return n.cloneNode(FALSE);
  4515. };
  4516. function _traverseFullySelected(n, how) {
  4517. if (how != DELETE)
  4518. return how == CLONE ? n.cloneNode(TRUE) : n;
  4519. n.parentNode.removeChild(n);
  4520. };
  4521. };
  4522. ns.Range = Range;
  4523. })(tinymce.dom);
  4524. (function() {
  4525. function Selection(selection) {
  4526. var self = this, dom = selection.dom, TRUE = true, FALSE = false;
  4527. function getPosition(rng, start) {
  4528. var checkRng, startIndex = 0, endIndex, inside,
  4529. children, child, offset, index, position = -1, parent;
  4530. // Setup test range, collapse it and get the parent
  4531. checkRng = rng.duplicate();
  4532. checkRng.collapse(start);
  4533. parent = checkRng.parentElement();
  4534. // Check if the selection is within the right document
  4535. if (parent.ownerDocument !== selection.dom.doc)
  4536. return;
  4537. // IE will report non editable elements as it's parent so look for an editable one
  4538. while (parent.contentEditable === "false") {
  4539. parent = parent.parentNode;
  4540. }
  4541. // If parent doesn't have any children then return that we are inside the element
  4542. if (!parent.hasChildNodes()) {
  4543. return {node : parent, inside : 1};
  4544. }
  4545. // Setup node list and endIndex
  4546. children = parent.children;
  4547. endIndex = children.length - 1;
  4548. // Perform a binary search for the position
  4549. while (startIndex <= endIndex) {
  4550. index = Math.floor((startIndex + endIndex) / 2);
  4551. // Move selection to node and compare the ranges
  4552. child = children[index];
  4553. checkRng.moveToElementText(child);
  4554. position = checkRng.compareEndPoints(start ? 'StartToStart' : 'EndToEnd', rng);
  4555. // Before/after or an exact match
  4556. if (position > 0) {
  4557. endIndex = index - 1;
  4558. } else if (position < 0) {
  4559. startIndex = index + 1;
  4560. } else {
  4561. return {node : child};
  4562. }
  4563. }
  4564. // Check if child position is before or we didn't find a position
  4565. if (position < 0) {
  4566. // No element child was found use the parent element and the offset inside that
  4567. if (!child) {
  4568. checkRng.moveToElementText(parent);
  4569. checkRng.collapse(true);
  4570. child = parent;
  4571. inside = true;
  4572. } else
  4573. checkRng.collapse(false);
  4574. checkRng.setEndPoint(start ? 'EndToStart' : 'EndToEnd', rng);
  4575. // Fix for edge case: <div style="width: 100px; height:100px;"><table>..</table>ab|c</div>
  4576. if (checkRng.compareEndPoints(start ? 'StartToStart' : 'StartToEnd', rng) > 0) {
  4577. checkRng = rng.duplicate();
  4578. checkRng.collapse(start);
  4579. offset = -1;
  4580. while (parent == checkRng.parentElement()) {
  4581. if (checkRng.move('character', -1) == 0)
  4582. break;
  4583. offset++;
  4584. }
  4585. }
  4586. offset = offset || checkRng.text.replace('\r\n', ' ').length;
  4587. } else {
  4588. // Child position is after the selection endpoint
  4589. checkRng.collapse(true);
  4590. checkRng.setEndPoint(start ? 'StartToStart' : 'StartToEnd', rng);
  4591. // Get the length of the text to find where the endpoint is relative to it's container
  4592. offset = checkRng.text.replace('\r\n', ' ').length;
  4593. }
  4594. return {node : child, position : position, offset : offset, inside : inside};
  4595. };
  4596. // Returns a W3C DOM compatible range object by using the IE Range API
  4597. function getRange() {
  4598. var ieRange = selection.getRng(), domRange = dom.createRng(), element, collapsed, tmpRange, element2, bookmark, fail;
  4599. // If selection is outside the current document just return an empty range
  4600. element = ieRange.item ? ieRange.item(0) : ieRange.parentElement();
  4601. if (element.ownerDocument != dom.doc)
  4602. return domRange;
  4603. collapsed = selection.isCollapsed();
  4604. // Handle control selection
  4605. if (ieRange.item) {
  4606. domRange.setStart(element.parentNode, dom.nodeIndex(element));
  4607. domRange.setEnd(domRange.startContainer, domRange.startOffset + 1);
  4608. return domRange;
  4609. }
  4610. function findEndPoint(start) {
  4611. var endPoint = getPosition(ieRange, start), container, offset, textNodeOffset = 0, sibling, undef, nodeValue;
  4612. container = endPoint.node;
  4613. offset = endPoint.offset;
  4614. if (endPoint.inside && !container.hasChildNodes()) {
  4615. domRange[start ? 'setStart' : 'setEnd'](container, 0);
  4616. return;
  4617. }
  4618. if (offset === undef) {
  4619. domRange[start ? 'setStartBefore' : 'setEndAfter'](container);
  4620. return;
  4621. }
  4622. if (endPoint.position < 0) {
  4623. sibling = endPoint.inside ? container.firstChild : container.nextSibling;
  4624. if (!sibling) {
  4625. domRange[start ? 'setStartAfter' : 'setEndAfter'](container);
  4626. return;
  4627. }
  4628. if (!offset) {
  4629. if (sibling.nodeType == 3)
  4630. domRange[start ? 'setStart' : 'setEnd'](sibling, 0);
  4631. else
  4632. domRange[start ? 'setStartBefore' : 'setEndBefore'](sibling);
  4633. return;
  4634. }
  4635. // Find the text node and offset
  4636. while (sibling) {
  4637. nodeValue = sibling.nodeValue;
  4638. textNodeOffset += nodeValue.length;
  4639. // We are at or passed the position we where looking for
  4640. if (textNodeOffset >= offset) {
  4641. container = sibling;
  4642. textNodeOffset -= offset;
  4643. textNodeOffset = nodeValue.length - textNodeOffset;
  4644. break;
  4645. }
  4646. sibling = sibling.nextSibling;
  4647. }
  4648. } else {
  4649. // Find the text node and offset
  4650. sibling = container.previousSibling;
  4651. if (!sibling)
  4652. return domRange[start ? 'setStartBefore' : 'setEndBefore'](container);
  4653. // If there isn't any text to loop then use the first position
  4654. if (!offset) {
  4655. if (container.nodeType == 3)
  4656. domRange[start ? 'setStart' : 'setEnd'](sibling, container.nodeValue.length);
  4657. else
  4658. domRange[start ? 'setStartAfter' : 'setEndAfter'](sibling);
  4659. return;
  4660. }
  4661. while (sibling) {
  4662. textNodeOffset += sibling.nodeValue.length;
  4663. // We are at or passed the position we where looking for
  4664. if (textNodeOffset >= offset) {
  4665. container = sibling;
  4666. textNodeOffset -= offset;
  4667. break;
  4668. }
  4669. sibling = sibling.previousSibling;
  4670. }
  4671. }
  4672. domRange[start ? 'setStart' : 'setEnd'](container, textNodeOffset);
  4673. };
  4674. try {
  4675. // Find start point
  4676. findEndPoint(true);
  4677. // Find end point if needed
  4678. if (!collapsed)
  4679. findEndPoint();
  4680. } catch (ex) {
  4681. // IE has a nasty bug where text nodes might throw "invalid argument" when you
  4682. // access the nodeValue or other properties of text nodes. This seems to happend when
  4683. // text nodes are split into two nodes by a delete/backspace call. So lets detect it and try to fix it.
  4684. if (ex.number == -2147024809) {
  4685. // Get the current selection
  4686. bookmark = self.getBookmark(2);
  4687. // Get start element
  4688. tmpRange = ieRange.duplicate();
  4689. tmpRange.collapse(true);
  4690. element = tmpRange.parentElement();
  4691. // Get end element
  4692. if (!collapsed) {
  4693. tmpRange = ieRange.duplicate();
  4694. tmpRange.collapse(false);
  4695. element2 = tmpRange.parentElement();
  4696. element2.innerHTML = element2.innerHTML;
  4697. }
  4698. // Remove the broken elements
  4699. element.innerHTML = element.innerHTML;
  4700. // Restore the selection
  4701. self.moveToBookmark(bookmark);
  4702. // Since the range has moved we need to re-get it
  4703. ieRange = selection.getRng();
  4704. // Find start point
  4705. findEndPoint(true);
  4706. // Find end point if needed
  4707. if (!collapsed)
  4708. findEndPoint();
  4709. } else
  4710. throw ex; // Throw other errors
  4711. }
  4712. return domRange;
  4713. };
  4714. this.getBookmark = function(type) {
  4715. var rng = selection.getRng(), start, end, bookmark = {};
  4716. function getIndexes(node) {
  4717. var node, parent, root, children, i, indexes = [];
  4718. parent = node.parentNode;
  4719. root = dom.getRoot().parentNode;
  4720. while (parent != root && parent.nodeType !== 9) {
  4721. children = parent.children;
  4722. i = children.length;
  4723. while (i--) {
  4724. if (node === children[i]) {
  4725. indexes.push(i);
  4726. break;
  4727. }
  4728. }
  4729. node = parent;
  4730. parent = parent.parentNode;
  4731. }
  4732. return indexes;
  4733. };
  4734. function getBookmarkEndPoint(start) {
  4735. var position;
  4736. position = getPosition(rng, start);
  4737. if (position) {
  4738. return {
  4739. position : position.position,
  4740. offset : position.offset,
  4741. indexes : getIndexes(position.node),
  4742. inside : position.inside
  4743. };
  4744. }
  4745. };
  4746. // Non ubstructive bookmark
  4747. if (type === 2) {
  4748. // Handle text selection
  4749. if (!rng.item) {
  4750. bookmark.start = getBookmarkEndPoint(true);
  4751. if (!selection.isCollapsed())
  4752. bookmark.end = getBookmarkEndPoint();
  4753. } else
  4754. bookmark.start = {ctrl : true, indexes : getIndexes(rng.item(0))};
  4755. }
  4756. return bookmark;
  4757. };
  4758. this.moveToBookmark = function(bookmark) {
  4759. var rng, body = dom.doc.body;
  4760. function resolveIndexes(indexes) {
  4761. var node, i, idx, children;
  4762. node = dom.getRoot();
  4763. for (i = indexes.length - 1; i >= 0; i--) {
  4764. children = node.children;
  4765. idx = indexes[i];
  4766. if (idx <= children.length - 1) {
  4767. node = children[idx];
  4768. }
  4769. }
  4770. return node;
  4771. };
  4772. function setBookmarkEndPoint(start) {
  4773. var endPoint = bookmark[start ? 'start' : 'end'], moveLeft, moveRng, undef;
  4774. if (endPoint) {
  4775. moveLeft = endPoint.position > 0;
  4776. moveRng = body.createTextRange();
  4777. moveRng.moveToElementText(resolveIndexes(endPoint.indexes));
  4778. offset = endPoint.offset;
  4779. if (offset !== undef) {
  4780. moveRng.collapse(endPoint.inside || moveLeft);
  4781. moveRng.moveStart('character', moveLeft ? -offset : offset);
  4782. } else
  4783. moveRng.collapse(start);
  4784. rng.setEndPoint(start ? 'StartToStart' : 'EndToStart', moveRng);
  4785. if (start)
  4786. rng.collapse(true);
  4787. }
  4788. };
  4789. if (bookmark.start) {
  4790. if (bookmark.start.ctrl) {
  4791. rng = body.createControlRange();
  4792. rng.addElement(resolveIndexes(bookmark.start.indexes));
  4793. rng.select();
  4794. } else {
  4795. rng = body.createTextRange();
  4796. setBookmarkEndPoint(true);
  4797. setBookmarkEndPoint();
  4798. rng.select();
  4799. }
  4800. }
  4801. };
  4802. this.addRange = function(rng) {
  4803. var ieRng, ctrlRng, startContainer, startOffset, endContainer, endOffset, doc = selection.dom.doc, body = doc.body;
  4804. function setEndPoint(start) {
  4805. var container, offset, marker, tmpRng, nodes;
  4806. marker = dom.create('a');
  4807. container = start ? startContainer : endContainer;
  4808. offset = start ? startOffset : endOffset;
  4809. tmpRng = ieRng.duplicate();
  4810. if (container == doc || container == doc.documentElement) {
  4811. container = body;
  4812. offset = 0;
  4813. }
  4814. if (container.nodeType == 3) {
  4815. container.parentNode.insertBefore(marker, container);
  4816. tmpRng.moveToElementText(marker);
  4817. tmpRng.moveStart('character', offset);
  4818. dom.remove(marker);
  4819. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  4820. } else {
  4821. nodes = container.childNodes;
  4822. if (nodes.length) {
  4823. if (offset >= nodes.length) {
  4824. dom.insertAfter(marker, nodes[nodes.length - 1]);
  4825. } else {
  4826. container.insertBefore(marker, nodes[offset]);
  4827. }
  4828. tmpRng.moveToElementText(marker);
  4829. } else {
  4830. // Empty node selection for example <div>|</div>
  4831. marker = doc.createTextNode('\uFEFF');
  4832. container.appendChild(marker);
  4833. tmpRng.moveToElementText(marker.parentNode);
  4834. tmpRng.collapse(TRUE);
  4835. }
  4836. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  4837. dom.remove(marker);
  4838. }
  4839. }
  4840. // Setup some shorter versions
  4841. startContainer = rng.startContainer;
  4842. startOffset = rng.startOffset;
  4843. endContainer = rng.endContainer;
  4844. endOffset = rng.endOffset;
  4845. ieRng = body.createTextRange();
  4846. // If single element selection then try making a control selection out of it
  4847. if (startContainer == endContainer && startContainer.nodeType == 1 && startOffset == endOffset - 1) {
  4848. if (startOffset == endOffset - 1) {
  4849. try {
  4850. ctrlRng = body.createControlRange();
  4851. ctrlRng.addElement(startContainer.childNodes[startOffset]);
  4852. ctrlRng.select();
  4853. return;
  4854. } catch (ex) {
  4855. // Ignore
  4856. }
  4857. }
  4858. }
  4859. // Set start/end point of selection
  4860. setEndPoint(true);
  4861. setEndPoint();
  4862. // Select the new range and scroll it into view
  4863. ieRng.select();
  4864. };
  4865. // Expose range method
  4866. this.getRangeAt = getRange;
  4867. };
  4868. // Expose the selection object
  4869. tinymce.dom.TridentSelection = Selection;
  4870. })();
  4871. (function(tinymce) {
  4872. // Shorten names
  4873. var each = tinymce.each, DOM = tinymce.DOM, isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, Event;
  4874. tinymce.create('tinymce.dom.EventUtils', {
  4875. EventUtils : function() {
  4876. this.inits = [];
  4877. this.events = [];
  4878. },
  4879. add : function(o, n, f, s) {
  4880. var cb, t = this, el = t.events, r;
  4881. if (n instanceof Array) {
  4882. r = [];
  4883. each(n, function(n) {
  4884. r.push(t.add(o, n, f, s));
  4885. });
  4886. return r;
  4887. }
  4888. // Handle array
  4889. if (o && o.hasOwnProperty && o instanceof Array) {
  4890. r = [];
  4891. each(o, function(o) {
  4892. o = DOM.get(o);
  4893. r.push(t.add(o, n, f, s));
  4894. });
  4895. return r;
  4896. }
  4897. o = DOM.get(o);
  4898. if (!o)
  4899. return;
  4900. // Setup event callback
  4901. cb = function(e) {
  4902. // Is all events disabled
  4903. if (t.disabled)
  4904. return;
  4905. e = e || window.event;
  4906. // Patch in target, preventDefault and stopPropagation in IE it's W3C valid
  4907. if (e && isIE) {
  4908. if (!e.target)
  4909. e.target = e.srcElement;
  4910. // Patch in preventDefault, stopPropagation methods for W3C compatibility
  4911. tinymce.extend(e, t._stoppers);
  4912. }
  4913. if (!s)
  4914. return f(e);
  4915. return f.call(s, e);
  4916. };
  4917. if (n == 'unload') {
  4918. tinymce.unloads.unshift({func : cb});
  4919. return cb;
  4920. }
  4921. if (n == 'init') {
  4922. if (t.domLoaded)
  4923. cb();
  4924. else
  4925. t.inits.push(cb);
  4926. return cb;
  4927. }
  4928. // Store away listener reference
  4929. el.push({
  4930. obj : o,
  4931. name : n,
  4932. func : f,
  4933. cfunc : cb,
  4934. scope : s
  4935. });
  4936. t._add(o, n, cb);
  4937. return f;
  4938. },
  4939. remove : function(o, n, f) {
  4940. var t = this, a = t.events, s = false, r;
  4941. // Handle array
  4942. if (o && o.hasOwnProperty && o instanceof Array) {
  4943. r = [];
  4944. each(o, function(o) {
  4945. o = DOM.get(o);
  4946. r.push(t.remove(o, n, f));
  4947. });
  4948. return r;
  4949. }
  4950. o = DOM.get(o);
  4951. each(a, function(e, i) {
  4952. if (e.obj == o && e.name == n && (!f || (e.func == f || e.cfunc == f))) {
  4953. a.splice(i, 1);
  4954. t._remove(o, n, e.cfunc);
  4955. s = true;
  4956. return false;
  4957. }
  4958. });
  4959. return s;
  4960. },
  4961. clear : function(o) {
  4962. var t = this, a = t.events, i, e;
  4963. if (o) {
  4964. o = DOM.get(o);
  4965. for (i = a.length - 1; i >= 0; i--) {
  4966. e = a[i];
  4967. if (e.obj === o) {
  4968. t._remove(e.obj, e.name, e.cfunc);
  4969. e.obj = e.cfunc = null;
  4970. a.splice(i, 1);
  4971. }
  4972. }
  4973. }
  4974. },
  4975. cancel : function(e) {
  4976. if (!e)
  4977. return false;
  4978. this.stop(e);
  4979. return this.prevent(e);
  4980. },
  4981. stop : function(e) {
  4982. if (e.stopPropagation)
  4983. e.stopPropagation();
  4984. else
  4985. e.cancelBubble = true;
  4986. return false;
  4987. },
  4988. prevent : function(e) {
  4989. if (e.preventDefault)
  4990. e.preventDefault();
  4991. else
  4992. e.returnValue = false;
  4993. return false;
  4994. },
  4995. destroy : function() {
  4996. var t = this;
  4997. each(t.events, function(e, i) {
  4998. t._remove(e.obj, e.name, e.cfunc);
  4999. e.obj = e.cfunc = null;
  5000. });
  5001. t.events = [];
  5002. t = null;
  5003. },
  5004. _add : function(o, n, f) {
  5005. if (o.attachEvent)
  5006. o.attachEvent('on' + n, f);
  5007. else if (o.addEventListener)
  5008. o.addEventListener(n, f, false);
  5009. else
  5010. o['on' + n] = f;
  5011. },
  5012. _remove : function(o, n, f) {
  5013. if (o) {
  5014. try {
  5015. if (o.detachEvent)
  5016. o.detachEvent('on' + n, f);
  5017. else if (o.removeEventListener)
  5018. o.removeEventListener(n, f, false);
  5019. else
  5020. o['on' + n] = null;
  5021. } catch (ex) {
  5022. // Might fail with permission denined on IE so we just ignore that
  5023. }
  5024. }
  5025. },
  5026. _pageInit : function(win) {
  5027. var t = this;
  5028. // Keep it from running more than once
  5029. if (t.domLoaded)
  5030. return;
  5031. t.domLoaded = true;
  5032. each(t.inits, function(c) {
  5033. c();
  5034. });
  5035. t.inits = [];
  5036. },
  5037. _wait : function(win) {
  5038. var t = this, doc = win.document;
  5039. // No need since the document is already loaded
  5040. if (win.tinyMCE_GZ && tinyMCE_GZ.loaded) {
  5041. t.domLoaded = 1;
  5042. return;
  5043. }
  5044. // Use IE method
  5045. if (doc.attachEvent) {
  5046. doc.attachEvent("onreadystatechange", function() {
  5047. if (doc.readyState === "complete") {
  5048. doc.detachEvent("onreadystatechange", arguments.callee);
  5049. t._pageInit(win);
  5050. }
  5051. });
  5052. if (doc.documentElement.doScroll && win == win.top) {
  5053. (function() {
  5054. if (t.domLoaded)
  5055. return;
  5056. try {
  5057. // If IE is used, use the trick by Diego Perini licensed under MIT by request to the author.
  5058. // http://javascript.nwbox.com/IEContentLoaded/
  5059. doc.documentElement.doScroll("left");
  5060. } catch (ex) {
  5061. setTimeout(arguments.callee, 0);
  5062. return;
  5063. }
  5064. t._pageInit(win);
  5065. })();
  5066. }
  5067. } else if (doc.addEventListener) {
  5068. t._add(win, 'DOMContentLoaded', function() {
  5069. t._pageInit(win);
  5070. });
  5071. }
  5072. t._add(win, 'load', function() {
  5073. t._pageInit(win);
  5074. });
  5075. },
  5076. _stoppers : {
  5077. preventDefault : function() {
  5078. this.returnValue = false;
  5079. },
  5080. stopPropagation : function() {
  5081. this.cancelBubble = true;
  5082. }
  5083. }
  5084. });
  5085. Event = tinymce.dom.Event = new tinymce.dom.EventUtils();
  5086. // Dispatch DOM content loaded event for IE and Safari
  5087. Event._wait(window);
  5088. tinymce.addUnload(function() {
  5089. Event.destroy();
  5090. });
  5091. })(tinymce);
  5092. (function(tinymce) {
  5093. tinymce.dom.Element = function(id, settings) {
  5094. var t = this, dom, el;
  5095. t.settings = settings = settings || {};
  5096. t.id = id;
  5097. t.dom = dom = settings.dom || tinymce.DOM;
  5098. // Only IE leaks DOM references, this is a lot faster
  5099. if (!tinymce.isIE)
  5100. el = dom.get(t.id);
  5101. tinymce.each(
  5102. ('getPos,getRect,getParent,add,setStyle,getStyle,setStyles,' +
  5103. 'setAttrib,setAttribs,getAttrib,addClass,removeClass,' +
  5104. 'hasClass,getOuterHTML,setOuterHTML,remove,show,hide,' +
  5105. 'isHidden,setHTML,get').split(/,/)
  5106. , function(k) {
  5107. t[k] = function() {
  5108. var a = [id], i;
  5109. for (i = 0; i < arguments.length; i++)
  5110. a.push(arguments[i]);
  5111. a = dom[k].apply(dom, a);
  5112. t.update(k);
  5113. return a;
  5114. };
  5115. });
  5116. tinymce.extend(t, {
  5117. on : function(n, f, s) {
  5118. return tinymce.dom.Event.add(t.id, n, f, s);
  5119. },
  5120. getXY : function() {
  5121. return {
  5122. x : parseInt(t.getStyle('left')),
  5123. y : parseInt(t.getStyle('top'))
  5124. };
  5125. },
  5126. getSize : function() {
  5127. var n = dom.get(t.id);
  5128. return {
  5129. w : parseInt(t.getStyle('width') || n.clientWidth),
  5130. h : parseInt(t.getStyle('height') || n.clientHeight)
  5131. };
  5132. },
  5133. moveTo : function(x, y) {
  5134. t.setStyles({left : x, top : y});
  5135. },
  5136. moveBy : function(x, y) {
  5137. var p = t.getXY();
  5138. t.moveTo(p.x + x, p.y + y);
  5139. },
  5140. resizeTo : function(w, h) {
  5141. t.setStyles({width : w, height : h});
  5142. },
  5143. resizeBy : function(w, h) {
  5144. var s = t.getSize();
  5145. t.resizeTo(s.w + w, s.h + h);
  5146. },
  5147. update : function(k) {
  5148. var b;
  5149. if (tinymce.isIE6 && settings.blocker) {
  5150. k = k || '';
  5151. // Ignore getters
  5152. if (k.indexOf('get') === 0 || k.indexOf('has') === 0 || k.indexOf('is') === 0)
  5153. return;
  5154. // Remove blocker on remove
  5155. if (k == 'remove') {
  5156. dom.remove(t.blocker);
  5157. return;
  5158. }
  5159. if (!t.blocker) {
  5160. t.blocker = dom.uniqueId();
  5161. b = dom.add(settings.container || dom.getRoot(), 'iframe', {id : t.blocker, style : 'position:absolute;', frameBorder : 0, src : 'javascript:""'});
  5162. dom.setStyle(b, 'opacity', 0);
  5163. } else
  5164. b = dom.get(t.blocker);
  5165. dom.setStyles(b, {
  5166. left : t.getStyle('left', 1),
  5167. top : t.getStyle('top', 1),
  5168. width : t.getStyle('width', 1),
  5169. height : t.getStyle('height', 1),
  5170. display : t.getStyle('display', 1),
  5171. zIndex : parseInt(t.getStyle('zIndex', 1) || 0) - 1
  5172. });
  5173. }
  5174. }
  5175. });
  5176. };
  5177. })(tinymce);
  5178. (function(tinymce) {
  5179. function trimNl(s) {
  5180. return s.replace(/[\n\r]+/g, '');
  5181. };
  5182. // Shorten names
  5183. var is = tinymce.is, isIE = tinymce.isIE, each = tinymce.each;
  5184. tinymce.create('tinymce.dom.Selection', {
  5185. Selection : function(dom, win, serializer) {
  5186. var t = this;
  5187. t.dom = dom;
  5188. t.win = win;
  5189. t.serializer = serializer;
  5190. // Add events
  5191. each([
  5192. 'onBeforeSetContent',
  5193. 'onBeforeGetContent',
  5194. 'onSetContent',
  5195. 'onGetContent'
  5196. ], function(e) {
  5197. t[e] = new tinymce.util.Dispatcher(t);
  5198. });
  5199. // No W3C Range support
  5200. if (!t.win.getSelection)
  5201. t.tridentSel = new tinymce.dom.TridentSelection(t);
  5202. if (tinymce.isIE && dom.boxModel)
  5203. this._fixIESelection();
  5204. // Prevent leaks
  5205. tinymce.addUnload(t.destroy, t);
  5206. },
  5207. setCursorLocation: function(node, offset) {
  5208. var t = this; var r = t.dom.createRng();
  5209. r.setStart(node, offset);
  5210. r.setEnd(node, offset);
  5211. t.setRng(r);
  5212. t.collapse(false);
  5213. },
  5214. getContent : function(s) {
  5215. var t = this, r = t.getRng(), e = t.dom.create("body"), se = t.getSel(), wb, wa, n;
  5216. s = s || {};
  5217. wb = wa = '';
  5218. s.get = true;
  5219. s.format = s.format || 'html';
  5220. s.forced_root_block = '';
  5221. t.onBeforeGetContent.dispatch(t, s);
  5222. if (s.format == 'text')
  5223. return t.isCollapsed() ? '' : (r.text || (se.toString ? se.toString() : ''));
  5224. if (r.cloneContents) {
  5225. n = r.cloneContents();
  5226. if (n)
  5227. e.appendChild(n);
  5228. } else if (is(r.item) || is(r.htmlText)) {
  5229. // IE will produce invalid markup if elements are present that
  5230. // it doesn't understand like custom elements or HTML5 elements.
  5231. // Adding a BR in front of the contents and then remoiving it seems to fix it though.
  5232. e.innerHTML = '<br>' + (r.item ? r.item(0).outerHTML : r.htmlText);
  5233. e.removeChild(e.firstChild);
  5234. } else
  5235. e.innerHTML = r.toString();
  5236. // Keep whitespace before and after
  5237. if (/^\s/.test(e.innerHTML))
  5238. wb = ' ';
  5239. if (/\s+$/.test(e.innerHTML))
  5240. wa = ' ';
  5241. s.getInner = true;
  5242. s.content = t.isCollapsed() ? '' : wb + t.serializer.serialize(e, s) + wa;
  5243. t.onGetContent.dispatch(t, s);
  5244. return s.content;
  5245. },
  5246. setContent : function(content, args) {
  5247. var self = this, rng = self.getRng(), caretNode, doc = self.win.document, frag, temp;
  5248. args = args || {format : 'html'};
  5249. args.set = true;
  5250. content = args.content = content;
  5251. // Dispatch before set content event
  5252. if (!args.no_events)
  5253. self.onBeforeSetContent.dispatch(self, args);
  5254. content = args.content;
  5255. if (rng.insertNode) {
  5256. // Make caret marker since insertNode places the caret in the beginning of text after insert
  5257. content += '<span id="__caret">_</span>';
  5258. // Delete and insert new node
  5259. if (rng.startContainer == doc && rng.endContainer == doc) {
  5260. // WebKit will fail if the body is empty since the range is then invalid and it can't insert contents
  5261. doc.body.innerHTML = content;
  5262. } else {
  5263. rng.deleteContents();
  5264. if (doc.body.childNodes.length == 0) {
  5265. doc.body.innerHTML = content;
  5266. } else {
  5267. // createContextualFragment doesn't exists in IE 9 DOMRanges
  5268. if (rng.createContextualFragment) {
  5269. rng.insertNode(rng.createContextualFragment(content));
  5270. } else {
  5271. // Fake createContextualFragment call in IE 9
  5272. frag = doc.createDocumentFragment();
  5273. temp = doc.createElement('div');
  5274. frag.appendChild(temp);
  5275. temp.outerHTML = content;
  5276. rng.insertNode(frag);
  5277. }
  5278. }
  5279. }
  5280. // Move to caret marker
  5281. caretNode = self.dom.get('__caret');
  5282. // Make sure we wrap it compleatly, Opera fails with a simple select call
  5283. rng = doc.createRange();
  5284. rng.setStartBefore(caretNode);
  5285. rng.setEndBefore(caretNode);
  5286. self.setRng(rng);
  5287. // Remove the caret position
  5288. self.dom.remove('__caret');
  5289. try {
  5290. self.setRng(rng);
  5291. } catch (ex) {
  5292. // Might fail on Opera for some odd reason
  5293. }
  5294. } else {
  5295. if (rng.item) {
  5296. // Delete content and get caret text selection
  5297. doc.execCommand('Delete', false, null);
  5298. rng = self.getRng();
  5299. }
  5300. // Explorer removes spaces from the beginning of pasted contents
  5301. if (/^\s+/.test(content)) {
  5302. rng.pasteHTML('<span id="__mce_tmp">_</span>' + content);
  5303. self.dom.remove('__mce_tmp');
  5304. } else
  5305. rng.pasteHTML(content);
  5306. }
  5307. // Dispatch set content event
  5308. if (!args.no_events)
  5309. self.onSetContent.dispatch(self, args);
  5310. },
  5311. getStart : function() {
  5312. var rng = this.getRng(), startElement, parentElement, checkRng, node;
  5313. if (rng.duplicate || rng.item) {
  5314. // Control selection, return first item
  5315. if (rng.item)
  5316. return rng.item(0);
  5317. // Get start element
  5318. checkRng = rng.duplicate();
  5319. checkRng.collapse(1);
  5320. startElement = checkRng.parentElement();
  5321. // Check if range parent is inside the start element, then return the inner parent element
  5322. // This will fix issues when a single element is selected, IE would otherwise return the wrong start element
  5323. parentElement = node = rng.parentElement();
  5324. while (node = node.parentNode) {
  5325. if (node == startElement) {
  5326. startElement = parentElement;
  5327. break;
  5328. }
  5329. }
  5330. return startElement;
  5331. } else {
  5332. startElement = rng.startContainer;
  5333. if (startElement.nodeType == 1 && startElement.hasChildNodes())
  5334. startElement = startElement.childNodes[Math.min(startElement.childNodes.length - 1, rng.startOffset)];
  5335. if (startElement && startElement.nodeType == 3)
  5336. return startElement.parentNode;
  5337. return startElement;
  5338. }
  5339. },
  5340. getEnd : function() {
  5341. var t = this, r = t.getRng(), e, eo;
  5342. if (r.duplicate || r.item) {
  5343. if (r.item)
  5344. return r.item(0);
  5345. r = r.duplicate();
  5346. r.collapse(0);
  5347. e = r.parentElement();
  5348. if (e && e.nodeName == 'BODY')
  5349. return e.lastChild || e;
  5350. return e;
  5351. } else {
  5352. e = r.endContainer;
  5353. eo = r.endOffset;
  5354. if (e.nodeType == 1 && e.hasChildNodes())
  5355. e = e.childNodes[eo > 0 ? eo - 1 : eo];
  5356. if (e && e.nodeType == 3)
  5357. return e.parentNode;
  5358. return e;
  5359. }
  5360. },
  5361. getBookmark : function(type, normalized) {
  5362. var t = this, dom = t.dom, rng, rng2, id, collapsed, name, element, index, chr = '\uFEFF', styles;
  5363. function findIndex(name, element) {
  5364. var index = 0;
  5365. each(dom.select(name), function(node, i) {
  5366. if (node == element)
  5367. index = i;
  5368. });
  5369. return index;
  5370. };
  5371. if (type == 2) {
  5372. function getLocation() {
  5373. var rng = t.getRng(true), root = dom.getRoot(), bookmark = {};
  5374. function getPoint(rng, start) {
  5375. var container = rng[start ? 'startContainer' : 'endContainer'],
  5376. offset = rng[start ? 'startOffset' : 'endOffset'], point = [], node, childNodes, after = 0;
  5377. if (container.nodeType == 3) {
  5378. if (normalized) {
  5379. for (node = container.previousSibling; node && node.nodeType == 3; node = node.previousSibling)
  5380. offset += node.nodeValue.length;
  5381. }
  5382. point.push(offset);
  5383. } else {
  5384. childNodes = container.childNodes;
  5385. if (offset >= childNodes.length && childNodes.length) {
  5386. after = 1;
  5387. offset = Math.max(0, childNodes.length - 1);
  5388. }
  5389. point.push(t.dom.nodeIndex(childNodes[offset], normalized) + after);
  5390. }
  5391. for (; container && container != root; container = container.parentNode)
  5392. point.push(t.dom.nodeIndex(container, normalized));
  5393. return point;
  5394. };
  5395. bookmark.start = getPoint(rng, true);
  5396. if (!t.isCollapsed())
  5397. bookmark.end = getPoint(rng);
  5398. return bookmark;
  5399. };
  5400. if (t.tridentSel)
  5401. return t.tridentSel.getBookmark(type);
  5402. return getLocation();
  5403. }
  5404. // Handle simple range
  5405. if (type)
  5406. return {rng : t.getRng()};
  5407. rng = t.getRng();
  5408. id = dom.uniqueId();
  5409. collapsed = tinyMCE.activeEditor.selection.isCollapsed();
  5410. styles = 'overflow:hidden;line-height:0px';
  5411. // Explorer method
  5412. if (rng.duplicate || rng.item) {
  5413. // Text selection
  5414. if (!rng.item) {
  5415. rng2 = rng.duplicate();
  5416. try {
  5417. // Insert start marker
  5418. rng.collapse();
  5419. rng.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_start" style="' + styles + '">' + chr + '</span>');
  5420. // Insert end marker
  5421. if (!collapsed) {
  5422. rng2.collapse(false);
  5423. // Detect the empty space after block elements in IE and move the end back one character <p></p>] becomes <p>]</p>
  5424. rng.moveToElementText(rng2.parentElement());
  5425. if (rng.compareEndPoints('StartToEnd', rng2) == 0)
  5426. rng2.move('character', -1);
  5427. rng2.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_end" style="' + styles + '">' + chr + '</span>');
  5428. }
  5429. } catch (ex) {
  5430. // IE might throw unspecified error so lets ignore it
  5431. return null;
  5432. }
  5433. } else {
  5434. // Control selection
  5435. element = rng.item(0);
  5436. name = element.nodeName;
  5437. return {name : name, index : findIndex(name, element)};
  5438. }
  5439. } else {
  5440. element = t.getNode();
  5441. name = element.nodeName;
  5442. if (name == 'IMG')
  5443. return {name : name, index : findIndex(name, element)};
  5444. // W3C method
  5445. rng2 = rng.cloneRange();
  5446. // Insert end marker
  5447. if (!collapsed) {
  5448. rng2.collapse(false);
  5449. rng2.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_end', style : styles}, chr));
  5450. }
  5451. rng.collapse(true);
  5452. rng.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_start', style : styles}, chr));
  5453. }
  5454. t.moveToBookmark({id : id, keep : 1});
  5455. return {id : id};
  5456. },
  5457. moveToBookmark : function(bookmark) {
  5458. var t = this, dom = t.dom, marker1, marker2, rng, root, startContainer, endContainer, startOffset, endOffset;
  5459. if (bookmark) {
  5460. if (bookmark.start) {
  5461. rng = dom.createRng();
  5462. root = dom.getRoot();
  5463. function setEndPoint(start) {
  5464. var point = bookmark[start ? 'start' : 'end'], i, node, offset, children;
  5465. if (point) {
  5466. offset = point[0];
  5467. // Find container node
  5468. for (node = root, i = point.length - 1; i >= 1; i--) {
  5469. children = node.childNodes;
  5470. if (point[i] > children.length - 1)
  5471. return;
  5472. node = children[point[i]];
  5473. }
  5474. // Move text offset to best suitable location
  5475. if (node.nodeType === 3)
  5476. offset = Math.min(point[0], node.nodeValue.length);
  5477. // Move element offset to best suitable location
  5478. if (node.nodeType === 1)
  5479. offset = Math.min(point[0], node.childNodes.length);
  5480. // Set offset within container node
  5481. if (start)
  5482. rng.setStart(node, offset);
  5483. else
  5484. rng.setEnd(node, offset);
  5485. }
  5486. return true;
  5487. };
  5488. if (t.tridentSel)
  5489. return t.tridentSel.moveToBookmark(bookmark);
  5490. if (setEndPoint(true) && setEndPoint()) {
  5491. t.setRng(rng);
  5492. }
  5493. } else if (bookmark.id) {
  5494. function restoreEndPoint(suffix) {
  5495. var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev, keep = bookmark.keep;
  5496. if (marker) {
  5497. node = marker.parentNode;
  5498. if (suffix == 'start') {
  5499. if (!keep) {
  5500. idx = dom.nodeIndex(marker);
  5501. } else {
  5502. node = marker.firstChild;
  5503. idx = 1;
  5504. }
  5505. startContainer = endContainer = node;
  5506. startOffset = endOffset = idx;
  5507. } else {
  5508. if (!keep) {
  5509. idx = dom.nodeIndex(marker);
  5510. } else {
  5511. node = marker.firstChild;
  5512. idx = 1;
  5513. }
  5514. endContainer = node;
  5515. endOffset = idx;
  5516. }
  5517. if (!keep) {
  5518. prev = marker.previousSibling;
  5519. next = marker.nextSibling;
  5520. // Remove all marker text nodes
  5521. each(tinymce.grep(marker.childNodes), function(node) {
  5522. if (node.nodeType == 3)
  5523. node.nodeValue = node.nodeValue.replace(/\uFEFF/g, '');
  5524. });
  5525. // Remove marker but keep children if for example contents where inserted into the marker
  5526. // Also remove duplicated instances of the marker for example by a split operation or by WebKit auto split on paste feature
  5527. while (marker = dom.get(bookmark.id + '_' + suffix))
  5528. dom.remove(marker, 1);
  5529. // If siblings are text nodes then merge them unless it's Opera since it some how removes the node
  5530. // 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
  5531. if (prev && next && prev.nodeType == next.nodeType && prev.nodeType == 3 && !tinymce.isOpera) {
  5532. idx = prev.nodeValue.length;
  5533. prev.appendData(next.nodeValue);
  5534. dom.remove(next);
  5535. if (suffix == 'start') {
  5536. startContainer = endContainer = prev;
  5537. startOffset = endOffset = idx;
  5538. } else {
  5539. endContainer = prev;
  5540. endOffset = idx;
  5541. }
  5542. }
  5543. }
  5544. }
  5545. };
  5546. function addBogus(node) {
  5547. // Adds a bogus BR element for empty block elements or just a space on IE since it renders BR elements incorrectly
  5548. if (dom.isBlock(node) && !node.innerHTML)
  5549. node.innerHTML = !isIE ? '<br data-mce-bogus="1" />' : ' ';
  5550. return node;
  5551. };
  5552. // Restore start/end points
  5553. restoreEndPoint('start');
  5554. restoreEndPoint('end');
  5555. if (startContainer) {
  5556. rng = dom.createRng();
  5557. rng.setStart(addBogus(startContainer), startOffset);
  5558. rng.setEnd(addBogus(endContainer), endOffset);
  5559. t.setRng(rng);
  5560. }
  5561. } else if (bookmark.name) {
  5562. t.select(dom.select(bookmark.name)[bookmark.index]);
  5563. } else if (bookmark.rng)
  5564. t.setRng(bookmark.rng);
  5565. }
  5566. },
  5567. select : function(node, content) {
  5568. var t = this, dom = t.dom, rng = dom.createRng(), idx;
  5569. if (node) {
  5570. idx = dom.nodeIndex(node);
  5571. rng.setStart(node.parentNode, idx);
  5572. rng.setEnd(node.parentNode, idx + 1);
  5573. // Find first/last text node or BR element
  5574. if (content) {
  5575. function setPoint(node, start) {
  5576. var walker = new tinymce.dom.TreeWalker(node, node);
  5577. do {
  5578. // Text node
  5579. if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length != 0) {
  5580. if (start)
  5581. rng.setStart(node, 0);
  5582. else
  5583. rng.setEnd(node, node.nodeValue.length);
  5584. return;
  5585. }
  5586. // BR element
  5587. if (node.nodeName == 'BR') {
  5588. if (start)
  5589. rng.setStartBefore(node);
  5590. else
  5591. rng.setEndBefore(node);
  5592. return;
  5593. }
  5594. } while (node = (start ? walker.next() : walker.prev()));
  5595. };
  5596. setPoint(node, 1);
  5597. setPoint(node);
  5598. }
  5599. t.setRng(rng);
  5600. }
  5601. return node;
  5602. },
  5603. isCollapsed : function() {
  5604. var t = this, r = t.getRng(), s = t.getSel();
  5605. if (!r || r.item)
  5606. return false;
  5607. if (r.compareEndPoints)
  5608. return r.compareEndPoints('StartToEnd', r) === 0;
  5609. return !s || r.collapsed;
  5610. },
  5611. collapse : function(to_start) {
  5612. var self = this, rng = self.getRng(), node;
  5613. // Control range on IE
  5614. if (rng.item) {
  5615. node = rng.item(0);
  5616. rng = self.win.document.body.createTextRange();
  5617. rng.moveToElementText(node);
  5618. }
  5619. rng.collapse(!!to_start);
  5620. self.setRng(rng);
  5621. },
  5622. getSel : function() {
  5623. var t = this, w = this.win;
  5624. return w.getSelection ? w.getSelection() : w.document.selection;
  5625. },
  5626. getRng : function(w3c) {
  5627. var t = this, s, r, elm, doc = t.win.document;
  5628. // Found tridentSel object then we need to use that one
  5629. if (w3c && t.tridentSel)
  5630. return t.tridentSel.getRangeAt(0);
  5631. try {
  5632. if (s = t.getSel())
  5633. r = s.rangeCount > 0 ? s.getRangeAt(0) : (s.createRange ? s.createRange() : doc.createRange());
  5634. } catch (ex) {
  5635. // IE throws unspecified error here if TinyMCE is placed in a frame/iframe
  5636. }
  5637. // We have W3C ranges and it's IE then fake control selection since IE9 doesn't handle that correctly yet
  5638. if (tinymce.isIE && r && r.setStart && doc.selection.createRange().item) {
  5639. elm = doc.selection.createRange().item(0);
  5640. r = doc.createRange();
  5641. r.setStartBefore(elm);
  5642. r.setEndAfter(elm);
  5643. }
  5644. // No range found then create an empty one
  5645. // This can occur when the editor is placed in a hidden container element on Gecko
  5646. // Or on IE when there was an exception
  5647. if (!r)
  5648. r = doc.createRange ? doc.createRange() : doc.body.createTextRange();
  5649. if (t.selectedRange && t.explicitRange) {
  5650. if (r.compareBoundaryPoints(r.START_TO_START, t.selectedRange) === 0 && r.compareBoundaryPoints(r.END_TO_END, t.selectedRange) === 0) {
  5651. // Safari, Opera and Chrome only ever select text which causes the range to change.
  5652. // This lets us use the originally set range if the selection hasn't been changed by the user.
  5653. r = t.explicitRange;
  5654. } else {
  5655. t.selectedRange = null;
  5656. t.explicitRange = null;
  5657. }
  5658. }
  5659. return r;
  5660. },
  5661. setRng : function(r) {
  5662. var s, t = this;
  5663. if (!t.tridentSel) {
  5664. s = t.getSel();
  5665. if (s) {
  5666. t.explicitRange = r;
  5667. try {
  5668. s.removeAllRanges();
  5669. } catch (ex) {
  5670. // IE9 might throw errors here don't know why
  5671. }
  5672. s.addRange(r);
  5673. // adding range isn't always successful so we need to check range count otherwise an exception can occur
  5674. t.selectedRange = s.rangeCount > 0 ? s.getRangeAt(0) : null;
  5675. }
  5676. } else {
  5677. // Is W3C Range
  5678. if (r.cloneRange) {
  5679. t.tridentSel.addRange(r);
  5680. return;
  5681. }
  5682. // Is IE specific range
  5683. try {
  5684. r.select();
  5685. } catch (ex) {
  5686. // Needed for some odd IE bug #1843306
  5687. }
  5688. }
  5689. },
  5690. setNode : function(n) {
  5691. var t = this;
  5692. t.setContent(t.dom.getOuterHTML(n));
  5693. return n;
  5694. },
  5695. getNode : function() {
  5696. var t = this, rng = t.getRng(), sel = t.getSel(), elm, start = rng.startContainer, end = rng.endContainer;
  5697. // Range maybe lost after the editor is made visible again
  5698. if (!rng)
  5699. return t.dom.getRoot();
  5700. if (rng.setStart) {
  5701. elm = rng.commonAncestorContainer;
  5702. // Handle selection a image or other control like element such as anchors
  5703. if (!rng.collapsed) {
  5704. if (rng.startContainer == rng.endContainer) {
  5705. if (rng.endOffset - rng.startOffset < 2) {
  5706. if (rng.startContainer.hasChildNodes())
  5707. elm = rng.startContainer.childNodes[rng.startOffset];
  5708. }
  5709. }
  5710. // If the anchor node is a element instead of a text node then return this element
  5711. //if (tinymce.isWebKit && sel.anchorNode && sel.anchorNode.nodeType == 1)
  5712. // return sel.anchorNode.childNodes[sel.anchorOffset];
  5713. // Handle cases where the selection is immediately wrapped around a node and return that node instead of it's parent.
  5714. // This happens when you double click an underlined word in FireFox.
  5715. if (start.nodeType === 3 && end.nodeType === 3) {
  5716. function skipEmptyTextNodes(n, forwards) {
  5717. var orig = n;
  5718. while (n && n.nodeType === 3 && n.length === 0) {
  5719. n = forwards ? n.nextSibling : n.previousSibling;
  5720. }
  5721. return n || orig;
  5722. }
  5723. if (start.length === rng.startOffset) {
  5724. start = skipEmptyTextNodes(start.nextSibling, true);
  5725. } else {
  5726. start = start.parentNode;
  5727. }
  5728. if (rng.endOffset === 0) {
  5729. end = skipEmptyTextNodes(end.previousSibling, false);
  5730. } else {
  5731. end = end.parentNode;
  5732. }
  5733. if (start && start === end)
  5734. return start;
  5735. }
  5736. }
  5737. if (elm && elm.nodeType == 3)
  5738. return elm.parentNode;
  5739. return elm;
  5740. }
  5741. return rng.item ? rng.item(0) : rng.parentElement();
  5742. },
  5743. getSelectedBlocks : function(st, en) {
  5744. var t = this, dom = t.dom, sb, eb, n, bl = [];
  5745. sb = dom.getParent(st || t.getStart(), dom.isBlock);
  5746. eb = dom.getParent(en || t.getEnd(), dom.isBlock);
  5747. if (sb)
  5748. bl.push(sb);
  5749. if (sb && eb && sb != eb) {
  5750. n = sb;
  5751. var walker = new tinymce.dom.TreeWalker(sb, dom.getRoot());
  5752. while ((n = walker.next()) && n != eb) {
  5753. if (dom.isBlock(n))
  5754. bl.push(n);
  5755. }
  5756. }
  5757. if (eb && sb != eb)
  5758. bl.push(eb);
  5759. return bl;
  5760. },
  5761. normalize : function() {
  5762. var self = this, rng, normalized;
  5763. // TODO:
  5764. // Retain selection direction.
  5765. // Lean left/right on Gecko for inline elements.
  5766. // Run this on mouse up/key up when the user manually moves the selection
  5767. // Normalize only on non IE browsers for now
  5768. if (tinymce.isIE)
  5769. return;
  5770. function normalizeEndPoint(start) {
  5771. var container, offset, walker, dom = self.dom, body = dom.getRoot(), node;
  5772. container = rng[(start ? 'start' : 'end') + 'Container'];
  5773. offset = rng[(start ? 'start' : 'end') + 'Offset'];
  5774. // If the container is a document move it to the body element
  5775. if (container.nodeType === 9) {
  5776. container = container.body;
  5777. offset = 0;
  5778. }
  5779. // If the container is body try move it into the closest text node or position
  5780. // TODO: Add more logic here to handle element selection cases
  5781. if (container === body) {
  5782. // Resolve the index
  5783. if (container.hasChildNodes()) {
  5784. container = container.childNodes[Math.min(!start && offset > 0 ? offset - 1 : offset, container.childNodes.length - 1)];
  5785. offset = 0;
  5786. // Don't walk into elements that doesn't have any child nodes like a IMG
  5787. if (container.hasChildNodes()) {
  5788. // Walk the DOM to find a text node to place the caret at or a BR
  5789. node = container;
  5790. walker = new tinymce.dom.TreeWalker(container, body);
  5791. do {
  5792. // Found a text node use that position
  5793. if (node.nodeType === 3) {
  5794. offset = start ? 0 : node.nodeValue.length - 1;
  5795. container = node;
  5796. normalized = true;
  5797. break;
  5798. }
  5799. // Found a BR/IMG element that we can place the caret before
  5800. if (/^(BR|IMG)$/.test(node.nodeName)) {
  5801. offset = dom.nodeIndex(node);
  5802. container = node.parentNode;
  5803. // Put caret after image when moving the end point
  5804. if (node.nodeName == "IMG" && !start) {
  5805. offset++;
  5806. }
  5807. normalized = true;
  5808. break;
  5809. }
  5810. } while (node = (start ? walker.next() : walker.prev()));
  5811. }
  5812. }
  5813. }
  5814. // Set endpoint if it was normalized
  5815. if (normalized)
  5816. rng['set' + (start ? 'Start' : 'End')](container, offset);
  5817. };
  5818. rng = self.getRng();
  5819. // Normalize the end points
  5820. normalizeEndPoint(true);
  5821. if (!rng.collapsed)
  5822. normalizeEndPoint();
  5823. // Set the selection if it was normalized
  5824. if (normalized) {
  5825. //console.log(self.dom.dumpRng(rng));
  5826. self.setRng(rng);
  5827. }
  5828. },
  5829. destroy : function(s) {
  5830. var t = this;
  5831. t.win = null;
  5832. // Manual destroy then remove unload handler
  5833. if (!s)
  5834. tinymce.removeUnload(t.destroy);
  5835. },
  5836. // IE has an issue where you can't select/move the caret by clicking outside the body if the document is in standards mode
  5837. _fixIESelection : function() {
  5838. var dom = this.dom, doc = dom.doc, body = doc.body, started, startRng, htmlElm;
  5839. // Make HTML element unselectable since we are going to handle selection by hand
  5840. doc.documentElement.unselectable = true;
  5841. // Return range from point or null if it failed
  5842. function rngFromPoint(x, y) {
  5843. var rng = body.createTextRange();
  5844. try {
  5845. rng.moveToPoint(x, y);
  5846. } catch (ex) {
  5847. // IE sometimes throws and exception, so lets just ignore it
  5848. rng = null;
  5849. }
  5850. return rng;
  5851. };
  5852. // Fires while the selection is changing
  5853. function selectionChange(e) {
  5854. var pointRng;
  5855. // Check if the button is down or not
  5856. if (e.button) {
  5857. // Create range from mouse position
  5858. pointRng = rngFromPoint(e.x, e.y);
  5859. if (pointRng) {
  5860. // Check if pointRange is before/after selection then change the endPoint
  5861. if (pointRng.compareEndPoints('StartToStart', startRng) > 0)
  5862. pointRng.setEndPoint('StartToStart', startRng);
  5863. else
  5864. pointRng.setEndPoint('EndToEnd', startRng);
  5865. pointRng.select();
  5866. }
  5867. } else
  5868. endSelection();
  5869. }
  5870. // Removes listeners
  5871. function endSelection() {
  5872. var rng = doc.selection.createRange();
  5873. // If the range is collapsed then use the last start range
  5874. if (startRng && !rng.item && rng.compareEndPoints('StartToEnd', rng) === 0)
  5875. startRng.select();
  5876. dom.unbind(doc, 'mouseup', endSelection);
  5877. dom.unbind(doc, 'mousemove', selectionChange);
  5878. startRng = started = 0;
  5879. };
  5880. // Detect when user selects outside BODY
  5881. dom.bind(doc, ['mousedown', 'contextmenu'], function(e) {
  5882. if (e.target.nodeName === 'HTML') {
  5883. if (started)
  5884. endSelection();
  5885. // Detect vertical scrollbar, since IE will fire a mousedown on the scrollbar and have target set as HTML
  5886. htmlElm = doc.documentElement;
  5887. if (htmlElm.scrollHeight > htmlElm.clientHeight)
  5888. return;
  5889. started = 1;
  5890. // Setup start position
  5891. startRng = rngFromPoint(e.x, e.y);
  5892. if (startRng) {
  5893. // Listen for selection change events
  5894. dom.bind(doc, 'mouseup', endSelection);
  5895. dom.bind(doc, 'mousemove', selectionChange);
  5896. dom.win.focus();
  5897. startRng.select();
  5898. }
  5899. }
  5900. });
  5901. }
  5902. });
  5903. })(tinymce);
  5904. (function(tinymce) {
  5905. tinymce.dom.Serializer = function(settings, dom, schema) {
  5906. var onPreProcess, onPostProcess, isIE = tinymce.isIE, each = tinymce.each, htmlParser;
  5907. // Support the old apply_source_formatting option
  5908. if (!settings.apply_source_formatting)
  5909. settings.indent = false;
  5910. // Default DOM and Schema if they are undefined
  5911. dom = dom || tinymce.DOM;
  5912. schema = schema || new tinymce.html.Schema(settings);
  5913. settings.entity_encoding = settings.entity_encoding || 'named';
  5914. settings.remove_trailing_brs = "remove_trailing_brs" in settings ? settings.remove_trailing_brs : true;
  5915. onPreProcess = new tinymce.util.Dispatcher(self);
  5916. onPostProcess = new tinymce.util.Dispatcher(self);
  5917. htmlParser = new tinymce.html.DomParser(settings, schema);
  5918. // Convert move data-mce-src, data-mce-href and data-mce-style into nodes or process them if needed
  5919. htmlParser.addAttributeFilter('src,href,style', function(nodes, name) {
  5920. var i = nodes.length, node, value, internalName = 'data-mce-' + name, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope, undef;
  5921. while (i--) {
  5922. node = nodes[i];
  5923. value = node.attributes.map[internalName];
  5924. if (value !== undef) {
  5925. // Set external name to internal value and remove internal
  5926. node.attr(name, value.length > 0 ? value : null);
  5927. node.attr(internalName, null);
  5928. } else {
  5929. // No internal attribute found then convert the value we have in the DOM
  5930. value = node.attributes.map[name];
  5931. if (name === "style")
  5932. value = dom.serializeStyle(dom.parseStyle(value), node.name);
  5933. else if (urlConverter)
  5934. value = urlConverter.call(urlConverterScope, value, name, node.name);
  5935. node.attr(name, value.length > 0 ? value : null);
  5936. }
  5937. }
  5938. });
  5939. // Remove internal classes mceItem<..>
  5940. htmlParser.addAttributeFilter('class', function(nodes, name) {
  5941. var i = nodes.length, node, value;
  5942. while (i--) {
  5943. node = nodes[i];
  5944. value = node.attr('class').replace(/\s*mce(Item\w+|Selected)\s*/g, '');
  5945. node.attr('class', value.length > 0 ? value : null);
  5946. }
  5947. });
  5948. // Remove bookmark elements
  5949. htmlParser.addAttributeFilter('data-mce-type', function(nodes, name, args) {
  5950. var i = nodes.length, node;
  5951. while (i--) {
  5952. node = nodes[i];
  5953. if (node.attributes.map['data-mce-type'] === 'bookmark' && !args.cleanup)
  5954. node.remove();
  5955. }
  5956. });
  5957. // Force script into CDATA sections and remove the mce- prefix also add comments around styles
  5958. htmlParser.addNodeFilter('script,style', function(nodes, name) {
  5959. var i = nodes.length, node, value;
  5960. function trim(value) {
  5961. return value.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n')
  5962. .replace(/^[\r\n]*|[\r\n]*$/g, '')
  5963. .replace(/^\s*((<!--)?(\s*\/\/)?\s*<!\[CDATA\[|(<!--\s*)?\/\*\s*<!\[CDATA\[\s*\*\/|(\/\/)?\s*<!--|\/\*\s*<!--\s*\*\/)\s*[\r\n]*/gi, '')
  5964. .replace(/\s*(\/\*\s*\]\]>\s*\*\/(-->)?|\s*\/\/\s*\]\]>(-->)?|\/\/\s*(-->)?|\]\]>|\/\*\s*-->\s*\*\/|\s*-->\s*)\s*$/g, '');
  5965. };
  5966. while (i--) {
  5967. node = nodes[i];
  5968. value = node.firstChild ? node.firstChild.value : '';
  5969. if (name === "script") {
  5970. // Remove mce- prefix from script elements
  5971. node.attr('type', (node.attr('type') || 'text/javascript').replace(/^mce\-/, ''));
  5972. if (value.length > 0)
  5973. node.firstChild.value = '// <![CDATA[\n' + trim(value) + '\n// ]]>';
  5974. } else {
  5975. if (value.length > 0)
  5976. node.firstChild.value = '<!--\n' + trim(value) + '\n-->';
  5977. }
  5978. }
  5979. });
  5980. // Convert comments to cdata and handle protected comments
  5981. htmlParser.addNodeFilter('#comment', function(nodes, name) {
  5982. var i = nodes.length, node;
  5983. while (i--) {
  5984. node = nodes[i];
  5985. if (node.value.indexOf('[CDATA[') === 0) {
  5986. node.name = '#cdata';
  5987. node.type = 4;
  5988. node.value = node.value.replace(/^\[CDATA\[|\]\]$/g, '');
  5989. } else if (node.value.indexOf('mce:protected ') === 0) {
  5990. node.name = "#text";
  5991. node.type = 3;
  5992. node.raw = true;
  5993. node.value = unescape(node.value).substr(14);
  5994. }
  5995. }
  5996. });
  5997. htmlParser.addNodeFilter('xml:namespace,input', function(nodes, name) {
  5998. var i = nodes.length, node;
  5999. while (i--) {
  6000. node = nodes[i];
  6001. if (node.type === 7)
  6002. node.remove();
  6003. else if (node.type === 1) {
  6004. if (name === "input" && !("type" in node.attributes.map))
  6005. node.attr('type', 'text');
  6006. }
  6007. }
  6008. });
  6009. // Fix list elements, TODO: Replace this later
  6010. if (settings.fix_list_elements) {
  6011. htmlParser.addNodeFilter('ul,ol', function(nodes, name) {
  6012. var i = nodes.length, node, parentNode;
  6013. while (i--) {
  6014. node = nodes[i];
  6015. parentNode = node.parent;
  6016. if (parentNode.name === 'ul' || parentNode.name === 'ol') {
  6017. if (node.prev && node.prev.name === 'li') {
  6018. node.prev.append(node);
  6019. }
  6020. }
  6021. }
  6022. });
  6023. }
  6024. // Remove internal data attributes
  6025. htmlParser.addAttributeFilter('data-mce-src,data-mce-href,data-mce-style', function(nodes, name) {
  6026. var i = nodes.length;
  6027. while (i--) {
  6028. nodes[i].attr(name, null);
  6029. }
  6030. });
  6031. // Return public methods
  6032. return {
  6033. schema : schema,
  6034. addNodeFilter : htmlParser.addNodeFilter,
  6035. addAttributeFilter : htmlParser.addAttributeFilter,
  6036. onPreProcess : onPreProcess,
  6037. onPostProcess : onPostProcess,
  6038. serialize : function(node, args) {
  6039. var impl, doc, oldDoc, htmlSerializer, content;
  6040. // Explorer won't clone contents of script and style and the
  6041. // selected index of select elements are cleared on a clone operation.
  6042. if (isIE && dom.select('script,style,select,map').length > 0) {
  6043. content = node.innerHTML;
  6044. node = node.cloneNode(false);
  6045. dom.setHTML(node, content);
  6046. } else
  6047. node = node.cloneNode(true);
  6048. // Nodes needs to be attached to something in WebKit/Opera
  6049. // Older builds of Opera crashes if you attach the node to an document created dynamically
  6050. // and since we can't feature detect a crash we need to sniff the acutal build number
  6051. // This fix will make DOM ranges and make Sizzle happy!
  6052. impl = node.ownerDocument.implementation;
  6053. if (impl.createHTMLDocument) {
  6054. // Create an empty HTML document
  6055. doc = impl.createHTMLDocument("");
  6056. // Add the element or it's children if it's a body element to the new document
  6057. each(node.nodeName == 'BODY' ? node.childNodes : [node], function(node) {
  6058. doc.body.appendChild(doc.importNode(node, true));
  6059. });
  6060. // Grab first child or body element for serialization
  6061. if (node.nodeName != 'BODY')
  6062. node = doc.body.firstChild;
  6063. else
  6064. node = doc.body;
  6065. // set the new document in DOMUtils so createElement etc works
  6066. oldDoc = dom.doc;
  6067. dom.doc = doc;
  6068. }
  6069. args = args || {};
  6070. args.format = args.format || 'html';
  6071. // Pre process
  6072. if (!args.no_events) {
  6073. args.node = node;
  6074. onPreProcess.dispatch(self, args);
  6075. }
  6076. // Setup serializer
  6077. htmlSerializer = new tinymce.html.Serializer(settings, schema);
  6078. // Parse and serialize HTML
  6079. args.content = htmlSerializer.serialize(
  6080. htmlParser.parse(args.getInner ? node.innerHTML : tinymce.trim(dom.getOuterHTML(node), args), args)
  6081. );
  6082. // Replace all BOM characters for now until we can find a better solution
  6083. if (!args.cleanup)
  6084. args.content = args.content.replace(/\uFEFF|\u200B/g, '');
  6085. // Post process
  6086. if (!args.no_events)
  6087. onPostProcess.dispatch(self, args);
  6088. // Restore the old document if it was changed
  6089. if (oldDoc)
  6090. dom.doc = oldDoc;
  6091. args.node = null;
  6092. return args.content;
  6093. },
  6094. addRules : function(rules) {
  6095. schema.addValidElements(rules);
  6096. },
  6097. setRules : function(rules) {
  6098. schema.setValidElements(rules);
  6099. }
  6100. };
  6101. };
  6102. })(tinymce);
  6103. (function(tinymce) {
  6104. tinymce.dom.ScriptLoader = function(settings) {
  6105. var QUEUED = 0,
  6106. LOADING = 1,
  6107. LOADED = 2,
  6108. states = {},
  6109. queue = [],
  6110. scriptLoadedCallbacks = {},
  6111. queueLoadedCallbacks = [],
  6112. loading = 0,
  6113. undefined;
  6114. function loadScript(url, callback) {
  6115. var t = this, dom = tinymce.DOM, elm, uri, loc, id;
  6116. // Execute callback when script is loaded
  6117. function done() {
  6118. dom.remove(id);
  6119. if (elm)
  6120. elm.onreadystatechange = elm.onload = elm = null;
  6121. callback();
  6122. };
  6123. function error() {
  6124. // Report the error so it's easier for people to spot loading errors
  6125. if (typeof(console) !== "undefined" && console.log)
  6126. console.log("Failed to load: " + url);
  6127. // We can't mark it as done if there is a load error since
  6128. // A) We don't want to produce 404 errors on the server and
  6129. // B) the onerror event won't fire on all browsers.
  6130. // done();
  6131. };
  6132. id = dom.uniqueId();
  6133. if (tinymce.isIE6) {
  6134. uri = new tinymce.util.URI(url);
  6135. loc = location;
  6136. // If script is from same domain and we
  6137. // use IE 6 then use XHR since it's more reliable
  6138. if (uri.host == loc.hostname && uri.port == loc.port && (uri.protocol + ':') == loc.protocol && uri.protocol.toLowerCase() != 'file') {
  6139. tinymce.util.XHR.send({
  6140. url : tinymce._addVer(uri.getURI()),
  6141. success : function(content) {
  6142. // Create new temp script element
  6143. var script = dom.create('script', {
  6144. type : 'text/javascript'
  6145. });
  6146. // Evaluate script in global scope
  6147. script.text = content;
  6148. document.getElementsByTagName('head')[0].appendChild(script);
  6149. dom.remove(script);
  6150. done();
  6151. },
  6152. error : error
  6153. });
  6154. return;
  6155. }
  6156. }
  6157. // Create new script element
  6158. elm = dom.create('script', {
  6159. id : id,
  6160. type : 'text/javascript',
  6161. src : tinymce._addVer(url)
  6162. });
  6163. // Add onload listener for non IE browsers since IE9
  6164. // fires onload event before the script is parsed and executed
  6165. if (!tinymce.isIE)
  6166. elm.onload = done;
  6167. // Add onerror event will get fired on some browsers but not all of them
  6168. elm.onerror = error;
  6169. // Opera 9.60 doesn't seem to fire the onreadystate event at correctly
  6170. if (!tinymce.isOpera) {
  6171. elm.onreadystatechange = function() {
  6172. var state = elm.readyState;
  6173. // Loaded state is passed on IE 6 however there
  6174. // are known issues with this method but we can't use
  6175. // XHR in a cross domain loading
  6176. if (state == 'complete' || state == 'loaded')
  6177. done();
  6178. };
  6179. }
  6180. // Most browsers support this feature so we report errors
  6181. // for those at least to help users track their missing plugins etc
  6182. // todo: Removed since it produced error if the document is unloaded by navigating away, re-add it as an option
  6183. /*elm.onerror = function() {
  6184. alert('Failed to load: ' + url);
  6185. };*/
  6186. // Add script to document
  6187. (document.getElementsByTagName('head')[0] || document.body).appendChild(elm);
  6188. };
  6189. this.isDone = function(url) {
  6190. return states[url] == LOADED;
  6191. };
  6192. this.markDone = function(url) {
  6193. states[url] = LOADED;
  6194. };
  6195. this.add = this.load = function(url, callback, scope) {
  6196. var item, state = states[url];
  6197. // Add url to load queue
  6198. if (state == undefined) {
  6199. queue.push(url);
  6200. states[url] = QUEUED;
  6201. }
  6202. if (callback) {
  6203. // Store away callback for later execution
  6204. if (!scriptLoadedCallbacks[url])
  6205. scriptLoadedCallbacks[url] = [];
  6206. scriptLoadedCallbacks[url].push({
  6207. func : callback,
  6208. scope : scope || this
  6209. });
  6210. }
  6211. };
  6212. this.loadQueue = function(callback, scope) {
  6213. this.loadScripts(queue, callback, scope);
  6214. };
  6215. this.loadScripts = function(scripts, callback, scope) {
  6216. var loadScripts;
  6217. function execScriptLoadedCallbacks(url) {
  6218. // Execute URL callback functions
  6219. tinymce.each(scriptLoadedCallbacks[url], function(callback) {
  6220. callback.func.call(callback.scope);
  6221. });
  6222. scriptLoadedCallbacks[url] = undefined;
  6223. };
  6224. queueLoadedCallbacks.push({
  6225. func : callback,
  6226. scope : scope || this
  6227. });
  6228. loadScripts = function() {
  6229. var loadingScripts = tinymce.grep(scripts);
  6230. // Current scripts has been handled
  6231. scripts.length = 0;
  6232. // Load scripts that needs to be loaded
  6233. tinymce.each(loadingScripts, function(url) {
  6234. // Script is already loaded then execute script callbacks directly
  6235. if (states[url] == LOADED) {
  6236. execScriptLoadedCallbacks(url);
  6237. return;
  6238. }
  6239. // Is script not loading then start loading it
  6240. if (states[url] != LOADING) {
  6241. states[url] = LOADING;
  6242. loading++;
  6243. loadScript(url, function() {
  6244. states[url] = LOADED;
  6245. loading--;
  6246. execScriptLoadedCallbacks(url);
  6247. // Load more scripts if they where added by the recently loaded script
  6248. loadScripts();
  6249. });
  6250. }
  6251. });
  6252. // No scripts are currently loading then execute all pending queue loaded callbacks
  6253. if (!loading) {
  6254. tinymce.each(queueLoadedCallbacks, function(callback) {
  6255. callback.func.call(callback.scope);
  6256. });
  6257. queueLoadedCallbacks.length = 0;
  6258. }
  6259. };
  6260. loadScripts();
  6261. };
  6262. };
  6263. // Global script loader
  6264. tinymce.ScriptLoader = new tinymce.dom.ScriptLoader();
  6265. })(tinymce);
  6266. tinymce.dom.TreeWalker = function(start_node, root_node) {
  6267. var node = start_node;
  6268. function findSibling(node, start_name, sibling_name, shallow) {
  6269. var sibling, parent;
  6270. if (node) {
  6271. // Walk into nodes if it has a start
  6272. if (!shallow && node[start_name])
  6273. return node[start_name];
  6274. // Return the sibling if it has one
  6275. if (node != root_node) {
  6276. sibling = node[sibling_name];
  6277. if (sibling)
  6278. return sibling;
  6279. // Walk up the parents to look for siblings
  6280. for (parent = node.parentNode; parent && parent != root_node; parent = parent.parentNode) {
  6281. sibling = parent[sibling_name];
  6282. if (sibling)
  6283. return sibling;
  6284. }
  6285. }
  6286. }
  6287. };
  6288. this.current = function() {
  6289. return node;
  6290. };
  6291. this.next = function(shallow) {
  6292. return (node = findSibling(node, 'firstChild', 'nextSibling', shallow));
  6293. };
  6294. this.prev = function(shallow) {
  6295. return (node = findSibling(node, 'lastChild', 'previousSibling', shallow));
  6296. };
  6297. };
  6298. (function(tinymce) {
  6299. tinymce.dom.RangeUtils = function(dom) {
  6300. var INVISIBLE_CHAR = '\uFEFF';
  6301. this.walk = function(rng, callback) {
  6302. var startContainer = rng.startContainer,
  6303. startOffset = rng.startOffset,
  6304. endContainer = rng.endContainer,
  6305. endOffset = rng.endOffset,
  6306. ancestor, startPoint,
  6307. endPoint, node, parent, siblings, nodes;
  6308. // Handle table cell selection the table plugin enables
  6309. // you to fake select table cells and perform formatting actions on them
  6310. nodes = dom.select('td.mceSelected,th.mceSelected');
  6311. if (nodes.length > 0) {
  6312. tinymce.each(nodes, function(node) {
  6313. callback([node]);
  6314. });
  6315. return;
  6316. }
  6317. function exclude(nodes) {
  6318. var node;
  6319. // First node is excluded
  6320. node = nodes[0];
  6321. if (node.nodeType === 3 && node === startContainer && startOffset >= node.nodeValue.length) {
  6322. nodes.splice(0, 1);
  6323. }
  6324. // Last node is excluded
  6325. node = nodes[nodes.length - 1];
  6326. if (endOffset === 0 && nodes.length > 0 && node === endContainer && node.nodeType === 3) {
  6327. nodes.splice(nodes.length - 1, 1);
  6328. }
  6329. return nodes;
  6330. };
  6331. function collectSiblings(node, name, end_node) {
  6332. var siblings = [];
  6333. for (; node && node != end_node; node = node[name])
  6334. siblings.push(node);
  6335. return siblings;
  6336. };
  6337. function findEndPoint(node, root) {
  6338. do {
  6339. if (node.parentNode == root)
  6340. return node;
  6341. node = node.parentNode;
  6342. } while(node);
  6343. };
  6344. function walkBoundary(start_node, end_node, next) {
  6345. var siblingName = next ? 'nextSibling' : 'previousSibling';
  6346. for (node = start_node, parent = node.parentNode; node && node != end_node; node = parent) {
  6347. parent = node.parentNode;
  6348. siblings = collectSiblings(node == start_node ? node : node[siblingName], siblingName);
  6349. if (siblings.length) {
  6350. if (!next)
  6351. siblings.reverse();
  6352. callback(exclude(siblings));
  6353. }
  6354. }
  6355. };
  6356. // If index based start position then resolve it
  6357. if (startContainer.nodeType == 1 && startContainer.hasChildNodes())
  6358. startContainer = startContainer.childNodes[startOffset];
  6359. // If index based end position then resolve it
  6360. if (endContainer.nodeType == 1 && endContainer.hasChildNodes())
  6361. endContainer = endContainer.childNodes[Math.min(endOffset - 1, endContainer.childNodes.length - 1)];
  6362. // Same container
  6363. if (startContainer == endContainer)
  6364. return callback(exclude([startContainer]));
  6365. // Find common ancestor and end points
  6366. ancestor = dom.findCommonAncestor(startContainer, endContainer);
  6367. // Process left side
  6368. for (node = startContainer; node; node = node.parentNode) {
  6369. if (node === endContainer)
  6370. return walkBoundary(startContainer, ancestor, true);
  6371. if (node === ancestor)
  6372. break;
  6373. }
  6374. // Process right side
  6375. for (node = endContainer; node; node = node.parentNode) {
  6376. if (node === startContainer)
  6377. return walkBoundary(endContainer, ancestor);
  6378. if (node === ancestor)
  6379. break;
  6380. }
  6381. // Find start/end point
  6382. startPoint = findEndPoint(startContainer, ancestor) || startContainer;
  6383. endPoint = findEndPoint(endContainer, ancestor) || endContainer;
  6384. // Walk left leaf
  6385. walkBoundary(startContainer, startPoint, true);
  6386. // Walk the middle from start to end point
  6387. siblings = collectSiblings(
  6388. startPoint == startContainer ? startPoint : startPoint.nextSibling,
  6389. 'nextSibling',
  6390. endPoint == endContainer ? endPoint.nextSibling : endPoint
  6391. );
  6392. if (siblings.length)
  6393. callback(exclude(siblings));
  6394. // Walk right leaf
  6395. walkBoundary(endContainer, endPoint);
  6396. };
  6397. this.split = function(rng) {
  6398. var startContainer = rng.startContainer,
  6399. startOffset = rng.startOffset,
  6400. endContainer = rng.endContainer,
  6401. endOffset = rng.endOffset;
  6402. function splitText(node, offset) {
  6403. return node.splitText(offset);
  6404. };
  6405. // Handle single text node
  6406. if (startContainer == endContainer && startContainer.nodeType == 3) {
  6407. if (startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  6408. endContainer = splitText(startContainer, startOffset);
  6409. startContainer = endContainer.previousSibling;
  6410. if (endOffset > startOffset) {
  6411. endOffset = endOffset - startOffset;
  6412. startContainer = endContainer = splitText(endContainer, endOffset).previousSibling;
  6413. endOffset = endContainer.nodeValue.length;
  6414. startOffset = 0;
  6415. } else {
  6416. endOffset = 0;
  6417. }
  6418. }
  6419. } else {
  6420. // Split startContainer text node if needed
  6421. if (startContainer.nodeType == 3 && startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  6422. startContainer = splitText(startContainer, startOffset);
  6423. startOffset = 0;
  6424. }
  6425. // Split endContainer text node if needed
  6426. if (endContainer.nodeType == 3 && endOffset > 0 && endOffset < endContainer.nodeValue.length) {
  6427. endContainer = splitText(endContainer, endOffset).previousSibling;
  6428. endOffset = endContainer.nodeValue.length;
  6429. }
  6430. }
  6431. return {
  6432. startContainer : startContainer,
  6433. startOffset : startOffset,
  6434. endContainer : endContainer,
  6435. endOffset : endOffset
  6436. };
  6437. };
  6438. };
  6439. tinymce.dom.RangeUtils.compareRanges = function(rng1, rng2) {
  6440. if (rng1 && rng2) {
  6441. // Compare native IE ranges
  6442. if (rng1.item || rng1.duplicate) {
  6443. // Both are control ranges and the selected element matches
  6444. if (rng1.item && rng2.item && rng1.item(0) === rng2.item(0))
  6445. return true;
  6446. // Both are text ranges and the range matches
  6447. if (rng1.isEqual && rng2.isEqual && rng2.isEqual(rng1))
  6448. return true;
  6449. } else {
  6450. // Compare w3c ranges
  6451. return rng1.startContainer == rng2.startContainer && rng1.startOffset == rng2.startOffset;
  6452. }
  6453. }
  6454. return false;
  6455. };
  6456. })(tinymce);
  6457. (function(tinymce) {
  6458. var Event = tinymce.dom.Event, each = tinymce.each;
  6459. tinymce.create('tinymce.ui.KeyboardNavigation', {
  6460. KeyboardNavigation: function(settings, dom) {
  6461. var t = this, root = settings.root, items = settings.items,
  6462. enableUpDown = settings.enableUpDown, enableLeftRight = settings.enableLeftRight || !settings.enableUpDown,
  6463. excludeFromTabOrder = settings.excludeFromTabOrder,
  6464. itemFocussed, itemBlurred, rootKeydown, rootFocussed, focussedId;
  6465. dom = dom || tinymce.DOM;
  6466. itemFocussed = function(evt) {
  6467. focussedId = evt.target.id;
  6468. };
  6469. itemBlurred = function(evt) {
  6470. dom.setAttrib(evt.target.id, 'tabindex', '-1');
  6471. };
  6472. rootFocussed = function(evt) {
  6473. var item = dom.get(focussedId);
  6474. dom.setAttrib(item, 'tabindex', '0');
  6475. item.focus();
  6476. };
  6477. t.focus = function() {
  6478. dom.get(focussedId).focus();
  6479. };
  6480. t.destroy = function() {
  6481. each(items, function(item) {
  6482. dom.unbind(dom.get(item.id), 'focus', itemFocussed);
  6483. dom.unbind(dom.get(item.id), 'blur', itemBlurred);
  6484. });
  6485. dom.unbind(dom.get(root), 'focus', rootFocussed);
  6486. dom.unbind(dom.get(root), 'keydown', rootKeydown);
  6487. items = dom = root = t.focus = itemFocussed = itemBlurred = rootKeydown = rootFocussed = null;
  6488. t.destroy = function() {};
  6489. };
  6490. t.moveFocus = function(dir, evt) {
  6491. var idx = -1, controls = t.controls, newFocus;
  6492. if (!focussedId)
  6493. return;
  6494. each(items, function(item, index) {
  6495. if (item.id === focussedId) {
  6496. idx = index;
  6497. return false;
  6498. }
  6499. });
  6500. idx += dir;
  6501. if (idx < 0) {
  6502. idx = items.length - 1;
  6503. } else if (idx >= items.length) {
  6504. idx = 0;
  6505. }
  6506. newFocus = items[idx];
  6507. dom.setAttrib(focussedId, 'tabindex', '-1');
  6508. dom.setAttrib(newFocus.id, 'tabindex', '0');
  6509. dom.get(newFocus.id).focus();
  6510. if (settings.actOnFocus) {
  6511. settings.onAction(newFocus.id);
  6512. }
  6513. if (evt)
  6514. Event.cancel(evt);
  6515. };
  6516. rootKeydown = function(evt) {
  6517. 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;
  6518. switch (evt.keyCode) {
  6519. case DOM_VK_LEFT:
  6520. if (enableLeftRight) t.moveFocus(-1);
  6521. break;
  6522. case DOM_VK_RIGHT:
  6523. if (enableLeftRight) t.moveFocus(1);
  6524. break;
  6525. case DOM_VK_UP:
  6526. if (enableUpDown) t.moveFocus(-1);
  6527. break;
  6528. case DOM_VK_DOWN:
  6529. if (enableUpDown) t.moveFocus(1);
  6530. break;
  6531. case DOM_VK_ESCAPE:
  6532. if (settings.onCancel) {
  6533. settings.onCancel();
  6534. Event.cancel(evt);
  6535. }
  6536. break;
  6537. case DOM_VK_ENTER:
  6538. case DOM_VK_RETURN:
  6539. case DOM_VK_SPACE:
  6540. if (settings.onAction) {
  6541. settings.onAction(focussedId);
  6542. Event.cancel(evt);
  6543. }
  6544. break;
  6545. }
  6546. };
  6547. // Set up state and listeners for each item.
  6548. each(items, function(item, idx) {
  6549. var tabindex;
  6550. if (!item.id) {
  6551. item.id = dom.uniqueId('_mce_item_');
  6552. }
  6553. if (excludeFromTabOrder) {
  6554. dom.bind(item.id, 'blur', itemBlurred);
  6555. tabindex = '-1';
  6556. } else {
  6557. tabindex = (idx === 0 ? '0' : '-1');
  6558. }
  6559. dom.setAttrib(item.id, 'tabindex', tabindex);
  6560. dom.bind(dom.get(item.id), 'focus', itemFocussed);
  6561. });
  6562. // Setup initial state for root element.
  6563. if (items[0]){
  6564. focussedId = items[0].id;
  6565. }
  6566. dom.setAttrib(root, 'tabindex', '-1');
  6567. // Setup listeners for root element.
  6568. dom.bind(dom.get(root), 'focus', rootFocussed);
  6569. dom.bind(dom.get(root), 'keydown', rootKeydown);
  6570. }
  6571. });
  6572. })(tinymce);
  6573. (function(tinymce) {
  6574. // Shorten class names
  6575. var DOM = tinymce.DOM, is = tinymce.is;
  6576. tinymce.create('tinymce.ui.Control', {
  6577. Control : function(id, s, editor) {
  6578. this.id = id;
  6579. this.settings = s = s || {};
  6580. this.rendered = false;
  6581. this.onRender = new tinymce.util.Dispatcher(this);
  6582. this.classPrefix = '';
  6583. this.scope = s.scope || this;
  6584. this.disabled = 0;
  6585. this.active = 0;
  6586. this.editor = editor;
  6587. },
  6588. setAriaProperty : function(property, value) {
  6589. var element = DOM.get(this.id + '_aria') || DOM.get(this.id);
  6590. if (element) {
  6591. DOM.setAttrib(element, 'aria-' + property, !!value);
  6592. }
  6593. },
  6594. focus : function() {
  6595. DOM.get(this.id).focus();
  6596. },
  6597. setDisabled : function(s) {
  6598. if (s != this.disabled) {
  6599. this.setAriaProperty('disabled', s);
  6600. this.setState('Disabled', s);
  6601. this.setState('Enabled', !s);
  6602. this.disabled = s;
  6603. }
  6604. },
  6605. isDisabled : function() {
  6606. return this.disabled;
  6607. },
  6608. setActive : function(s) {
  6609. if (s != this.active) {
  6610. this.setState('Active', s);
  6611. this.active = s;
  6612. this.setAriaProperty('pressed', s);
  6613. }
  6614. },
  6615. isActive : function() {
  6616. return this.active;
  6617. },
  6618. setState : function(c, s) {
  6619. var n = DOM.get(this.id);
  6620. c = this.classPrefix + c;
  6621. if (s)
  6622. DOM.addClass(n, c);
  6623. else
  6624. DOM.removeClass(n, c);
  6625. },
  6626. isRendered : function() {
  6627. return this.rendered;
  6628. },
  6629. renderHTML : function() {
  6630. },
  6631. renderTo : function(n) {
  6632. DOM.setHTML(n, this.renderHTML());
  6633. },
  6634. postRender : function() {
  6635. var t = this, b;
  6636. // Set pending states
  6637. if (is(t.disabled)) {
  6638. b = t.disabled;
  6639. t.disabled = -1;
  6640. t.setDisabled(b);
  6641. }
  6642. if (is(t.active)) {
  6643. b = t.active;
  6644. t.active = -1;
  6645. t.setActive(b);
  6646. }
  6647. },
  6648. remove : function() {
  6649. DOM.remove(this.id);
  6650. this.destroy();
  6651. },
  6652. destroy : function() {
  6653. tinymce.dom.Event.clear(this.id);
  6654. }
  6655. });
  6656. })(tinymce);
  6657. tinymce.create('tinymce.ui.Container:tinymce.ui.Control', {
  6658. Container : function(id, s, editor) {
  6659. this.parent(id, s, editor);
  6660. this.controls = [];
  6661. this.lookup = {};
  6662. },
  6663. add : function(c) {
  6664. this.lookup[c.id] = c;
  6665. this.controls.push(c);
  6666. return c;
  6667. },
  6668. get : function(n) {
  6669. return this.lookup[n];
  6670. }
  6671. });
  6672. tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', {
  6673. Separator : function(id, s) {
  6674. this.parent(id, s);
  6675. this.classPrefix = 'mceSeparator';
  6676. this.setDisabled(true);
  6677. },
  6678. renderHTML : function() {
  6679. return tinymce.DOM.createHTML('span', {'class' : this.classPrefix, role : 'separator', 'aria-orientation' : 'vertical', tabindex : '-1'});
  6680. }
  6681. });
  6682. (function(tinymce) {
  6683. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  6684. tinymce.create('tinymce.ui.MenuItem:tinymce.ui.Control', {
  6685. MenuItem : function(id, s) {
  6686. this.parent(id, s);
  6687. this.classPrefix = 'mceMenuItem';
  6688. },
  6689. setSelected : function(s) {
  6690. this.setState('Selected', s);
  6691. this.setAriaProperty('checked', !!s);
  6692. this.selected = s;
  6693. },
  6694. isSelected : function() {
  6695. return this.selected;
  6696. },
  6697. postRender : function() {
  6698. var t = this;
  6699. t.parent();
  6700. // Set pending state
  6701. if (is(t.selected))
  6702. t.setSelected(t.selected);
  6703. }
  6704. });
  6705. })(tinymce);
  6706. (function(tinymce) {
  6707. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  6708. tinymce.create('tinymce.ui.Menu:tinymce.ui.MenuItem', {
  6709. Menu : function(id, s) {
  6710. var t = this;
  6711. t.parent(id, s);
  6712. t.items = {};
  6713. t.collapsed = false;
  6714. t.menuCount = 0;
  6715. t.onAddItem = new tinymce.util.Dispatcher(this);
  6716. },
  6717. expand : function(d) {
  6718. var t = this;
  6719. if (d) {
  6720. walk(t, function(o) {
  6721. if (o.expand)
  6722. o.expand();
  6723. }, 'items', t);
  6724. }
  6725. t.collapsed = false;
  6726. },
  6727. collapse : function(d) {
  6728. var t = this;
  6729. if (d) {
  6730. walk(t, function(o) {
  6731. if (o.collapse)
  6732. o.collapse();
  6733. }, 'items', t);
  6734. }
  6735. t.collapsed = true;
  6736. },
  6737. isCollapsed : function() {
  6738. return this.collapsed;
  6739. },
  6740. add : function(o) {
  6741. if (!o.settings)
  6742. o = new tinymce.ui.MenuItem(o.id || DOM.uniqueId(), o);
  6743. this.onAddItem.dispatch(this, o);
  6744. return this.items[o.id] = o;
  6745. },
  6746. addSeparator : function() {
  6747. return this.add({separator : true});
  6748. },
  6749. addMenu : function(o) {
  6750. if (!o.collapse)
  6751. o = this.createMenu(o);
  6752. this.menuCount++;
  6753. return this.add(o);
  6754. },
  6755. hasMenus : function() {
  6756. return this.menuCount !== 0;
  6757. },
  6758. remove : function(o) {
  6759. delete this.items[o.id];
  6760. },
  6761. removeAll : function() {
  6762. var t = this;
  6763. walk(t, function(o) {
  6764. if (o.removeAll)
  6765. o.removeAll();
  6766. else
  6767. o.remove();
  6768. o.destroy();
  6769. }, 'items', t);
  6770. t.items = {};
  6771. },
  6772. createMenu : function(o) {
  6773. var m = new tinymce.ui.Menu(o.id || DOM.uniqueId(), o);
  6774. m.onAddItem.add(this.onAddItem.dispatch, this.onAddItem);
  6775. return m;
  6776. }
  6777. });
  6778. })(tinymce);
  6779. (function(tinymce) {
  6780. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event, Element = tinymce.dom.Element;
  6781. tinymce.create('tinymce.ui.DropMenu:tinymce.ui.Menu', {
  6782. DropMenu : function(id, s) {
  6783. s = s || {};
  6784. s.container = s.container || DOM.doc.body;
  6785. s.offset_x = s.offset_x || 0;
  6786. s.offset_y = s.offset_y || 0;
  6787. s.vp_offset_x = s.vp_offset_x || 0;
  6788. s.vp_offset_y = s.vp_offset_y || 0;
  6789. if (is(s.icons) && !s.icons)
  6790. s['class'] += ' mceNoIcons';
  6791. this.parent(id, s);
  6792. this.onShowMenu = new tinymce.util.Dispatcher(this);
  6793. this.onHideMenu = new tinymce.util.Dispatcher(this);
  6794. this.classPrefix = 'mceMenu';
  6795. },
  6796. createMenu : function(s) {
  6797. var t = this, cs = t.settings, m;
  6798. s.container = s.container || cs.container;
  6799. s.parent = t;
  6800. s.constrain = s.constrain || cs.constrain;
  6801. s['class'] = s['class'] || cs['class'];
  6802. s.vp_offset_x = s.vp_offset_x || cs.vp_offset_x;
  6803. s.vp_offset_y = s.vp_offset_y || cs.vp_offset_y;
  6804. s.keyboard_focus = cs.keyboard_focus;
  6805. m = new tinymce.ui.DropMenu(s.id || DOM.uniqueId(), s);
  6806. m.onAddItem.add(t.onAddItem.dispatch, t.onAddItem);
  6807. return m;
  6808. },
  6809. focus : function() {
  6810. var t = this;
  6811. if (t.keyboardNav) {
  6812. t.keyboardNav.focus();
  6813. }
  6814. },
  6815. update : function() {
  6816. var t = this, s = t.settings, tb = DOM.get('menu_' + t.id + '_tbl'), co = DOM.get('menu_' + t.id + '_co'), tw, th;
  6817. tw = s.max_width ? Math.min(tb.clientWidth, s.max_width) : tb.clientWidth;
  6818. th = s.max_height ? Math.min(tb.clientHeight, s.max_height) : tb.clientHeight;
  6819. if (!DOM.boxModel)
  6820. t.element.setStyles({width : tw + 2, height : th + 2});
  6821. else
  6822. t.element.setStyles({width : tw, height : th});
  6823. if (s.max_width)
  6824. DOM.setStyle(co, 'width', tw);
  6825. if (s.max_height) {
  6826. DOM.setStyle(co, 'height', th);
  6827. if (tb.clientHeight < s.max_height)
  6828. DOM.setStyle(co, 'overflow', 'hidden');
  6829. }
  6830. },
  6831. showMenu : function(x, y, px) {
  6832. var t = this, s = t.settings, co, vp = DOM.getViewPort(), w, h, mx, my, ot = 2, dm, tb, cp = t.classPrefix;
  6833. t.collapse(1);
  6834. if (t.isMenuVisible)
  6835. return;
  6836. if (!t.rendered) {
  6837. co = DOM.add(t.settings.container, t.renderNode());
  6838. each(t.items, function(o) {
  6839. o.postRender();
  6840. });
  6841. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  6842. } else
  6843. co = DOM.get('menu_' + t.id);
  6844. // Move layer out of sight unless it's Opera since it scrolls to top of page due to an bug
  6845. if (!tinymce.isOpera)
  6846. DOM.setStyles(co, {left : -0xFFFF , top : -0xFFFF});
  6847. DOM.show(co);
  6848. t.update();
  6849. x += s.offset_x || 0;
  6850. y += s.offset_y || 0;
  6851. vp.w -= 4;
  6852. vp.h -= 4;
  6853. // Move inside viewport if not submenu
  6854. if (s.constrain) {
  6855. w = co.clientWidth - ot;
  6856. h = co.clientHeight - ot;
  6857. mx = vp.x + vp.w;
  6858. my = vp.y + vp.h;
  6859. if ((x + s.vp_offset_x + w) > mx)
  6860. x = px ? px - w : Math.max(0, (mx - s.vp_offset_x) - w);
  6861. if ((y + s.vp_offset_y + h) > my)
  6862. y = Math.max(0, (my - s.vp_offset_y) - h);
  6863. }
  6864. DOM.setStyles(co, {left : x , top : y});
  6865. t.element.update();
  6866. t.isMenuVisible = 1;
  6867. t.mouseClickFunc = Event.add(co, 'click', function(e) {
  6868. var m;
  6869. e = e.target;
  6870. if (e && (e = DOM.getParent(e, 'tr')) && !DOM.hasClass(e, cp + 'ItemSub')) {
  6871. m = t.items[e.id];
  6872. if (m.isDisabled())
  6873. return;
  6874. dm = t;
  6875. while (dm) {
  6876. if (dm.hideMenu)
  6877. dm.hideMenu();
  6878. dm = dm.settings.parent;
  6879. }
  6880. if (m.settings.onclick)
  6881. m.settings.onclick(e);
  6882. return Event.cancel(e); // Cancel to fix onbeforeunload problem
  6883. }
  6884. });
  6885. if (t.hasMenus()) {
  6886. t.mouseOverFunc = Event.add(co, 'mouseover', function(e) {
  6887. var m, r, mi;
  6888. e = e.target;
  6889. if (e && (e = DOM.getParent(e, 'tr'))) {
  6890. m = t.items[e.id];
  6891. if (t.lastMenu)
  6892. t.lastMenu.collapse(1);
  6893. if (m.isDisabled())
  6894. return;
  6895. if (e && DOM.hasClass(e, cp + 'ItemSub')) {
  6896. //p = DOM.getPos(s.container);
  6897. r = DOM.getRect(e);
  6898. m.showMenu((r.x + r.w - ot), r.y - ot, r.x);
  6899. t.lastMenu = m;
  6900. DOM.addClass(DOM.get(m.id).firstChild, cp + 'ItemActive');
  6901. }
  6902. }
  6903. });
  6904. }
  6905. Event.add(co, 'keydown', t._keyHandler, t);
  6906. t.onShowMenu.dispatch(t);
  6907. if (s.keyboard_focus) {
  6908. t._setupKeyboardNav();
  6909. }
  6910. },
  6911. hideMenu : function(c) {
  6912. var t = this, co = DOM.get('menu_' + t.id), e;
  6913. if (!t.isMenuVisible)
  6914. return;
  6915. if (t.keyboardNav) t.keyboardNav.destroy();
  6916. Event.remove(co, 'mouseover', t.mouseOverFunc);
  6917. Event.remove(co, 'click', t.mouseClickFunc);
  6918. Event.remove(co, 'keydown', t._keyHandler);
  6919. DOM.hide(co);
  6920. t.isMenuVisible = 0;
  6921. if (!c)
  6922. t.collapse(1);
  6923. if (t.element)
  6924. t.element.hide();
  6925. if (e = DOM.get(t.id))
  6926. DOM.removeClass(e.firstChild, t.classPrefix + 'ItemActive');
  6927. t.onHideMenu.dispatch(t);
  6928. },
  6929. add : function(o) {
  6930. var t = this, co;
  6931. o = t.parent(o);
  6932. if (t.isRendered && (co = DOM.get('menu_' + t.id)))
  6933. t._add(DOM.select('tbody', co)[0], o);
  6934. return o;
  6935. },
  6936. collapse : function(d) {
  6937. this.parent(d);
  6938. this.hideMenu(1);
  6939. },
  6940. remove : function(o) {
  6941. DOM.remove(o.id);
  6942. this.destroy();
  6943. return this.parent(o);
  6944. },
  6945. destroy : function() {
  6946. var t = this, co = DOM.get('menu_' + t.id);
  6947. if (t.keyboardNav) t.keyboardNav.destroy();
  6948. Event.remove(co, 'mouseover', t.mouseOverFunc);
  6949. Event.remove(DOM.select('a', co), 'focus', t.mouseOverFunc);
  6950. Event.remove(co, 'click', t.mouseClickFunc);
  6951. Event.remove(co, 'keydown', t._keyHandler);
  6952. if (t.element)
  6953. t.element.remove();
  6954. DOM.remove(co);
  6955. },
  6956. renderNode : function() {
  6957. var t = this, s = t.settings, n, tb, co, w;
  6958. 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'});
  6959. if (t.settings.parent) {
  6960. DOM.setAttrib(w, 'aria-parent', 'menu_' + t.settings.parent.id);
  6961. }
  6962. co = DOM.add(w, 'div', {role: 'presentation', id : 'menu_' + t.id + '_co', 'class' : t.classPrefix + (s['class'] ? ' ' + s['class'] : '')});
  6963. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  6964. if (s.menu_line)
  6965. DOM.add(co, 'span', {'class' : t.classPrefix + 'Line'});
  6966. // n = DOM.add(co, 'div', {id : 'menu_' + t.id + '_co', 'class' : 'mceMenuContainer'});
  6967. n = DOM.add(co, 'table', {role: 'presentation', id : 'menu_' + t.id + '_tbl', border : 0, cellPadding : 0, cellSpacing : 0});
  6968. tb = DOM.add(n, 'tbody');
  6969. each(t.items, function(o) {
  6970. t._add(tb, o);
  6971. });
  6972. t.rendered = true;
  6973. return w;
  6974. },
  6975. // Internal functions
  6976. _setupKeyboardNav : function(){
  6977. var contextMenu, menuItems, t=this;
  6978. contextMenu = DOM.get('menu_' + t.id);
  6979. menuItems = DOM.select('a[role=option]', 'menu_' + t.id);
  6980. menuItems.splice(0,0,contextMenu);
  6981. t.keyboardNav = new tinymce.ui.KeyboardNavigation({
  6982. root: 'menu_' + t.id,
  6983. items: menuItems,
  6984. onCancel: function() {
  6985. t.hideMenu();
  6986. },
  6987. enableUpDown: true
  6988. });
  6989. contextMenu.focus();
  6990. },
  6991. _keyHandler : function(evt) {
  6992. var t = this, e;
  6993. switch (evt.keyCode) {
  6994. case 37: // Left
  6995. if (t.settings.parent) {
  6996. t.hideMenu();
  6997. t.settings.parent.focus();
  6998. Event.cancel(evt);
  6999. }
  7000. break;
  7001. case 39: // Right
  7002. if (t.mouseOverFunc)
  7003. t.mouseOverFunc(evt);
  7004. break;
  7005. }
  7006. },
  7007. _add : function(tb, o) {
  7008. var n, s = o.settings, a, ro, it, cp = this.classPrefix, ic;
  7009. if (s.separator) {
  7010. ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'ItemSeparator'});
  7011. DOM.add(ro, 'td', {'class' : cp + 'ItemSeparator'});
  7012. if (n = ro.previousSibling)
  7013. DOM.addClass(n, 'mceLast');
  7014. return;
  7015. }
  7016. n = ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'Item ' + cp + 'ItemEnabled'});
  7017. n = it = DOM.add(n, s.titleItem ? 'th' : 'td');
  7018. n = a = DOM.add(n, 'a', {id: o.id + '_aria', role: s.titleItem ? 'presentation' : 'option', href : 'javascript:;', onclick : "return false;", onmousedown : 'return false;'});
  7019. if (s.parent) {
  7020. DOM.setAttrib(a, 'aria-haspopup', 'true');
  7021. DOM.setAttrib(a, 'aria-owns', 'menu_' + o.id);
  7022. }
  7023. DOM.addClass(it, s['class']);
  7024. // n = DOM.add(n, 'span', {'class' : 'item'});
  7025. ic = DOM.add(n, 'span', {'class' : 'mceIcon' + (s.icon ? ' mce_' + s.icon : '')});
  7026. if (s.icon_src)
  7027. DOM.add(ic, 'img', {src : s.icon_src});
  7028. n = DOM.add(n, s.element || 'span', {'class' : 'mceText', title : o.settings.title}, o.settings.title);
  7029. if (o.settings.style)
  7030. DOM.setAttrib(n, 'style', o.settings.style);
  7031. if (tb.childNodes.length == 1)
  7032. DOM.addClass(ro, 'mceFirst');
  7033. if ((n = ro.previousSibling) && DOM.hasClass(n, cp + 'ItemSeparator'))
  7034. DOM.addClass(ro, 'mceFirst');
  7035. if (o.collapse)
  7036. DOM.addClass(ro, cp + 'ItemSub');
  7037. if (n = ro.previousSibling)
  7038. DOM.removeClass(n, 'mceLast');
  7039. DOM.addClass(ro, 'mceLast');
  7040. }
  7041. });
  7042. })(tinymce);
  7043. (function(tinymce) {
  7044. var DOM = tinymce.DOM;
  7045. tinymce.create('tinymce.ui.Button:tinymce.ui.Control', {
  7046. Button : function(id, s, ed) {
  7047. this.parent(id, s, ed);
  7048. this.classPrefix = 'mceButton';
  7049. },
  7050. renderHTML : function() {
  7051. var cp = this.classPrefix, s = this.settings, h, l;
  7052. l = DOM.encode(s.label || '');
  7053. 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) + '">';
  7054. if (s.image && !(this.editor &&this.editor.forcedHighContrastMode) )
  7055. h += '<img class="mceIcon" src="' + s.image + '" alt="' + DOM.encode(s.title) + '" />' + l;
  7056. else
  7057. h += '<span class="mceIcon ' + s['class'] + '"></span>' + (l ? '<span class="' + cp + 'Label">' + l + '</span>' : '');
  7058. h += '<span class="mceVoiceLabel mceIconOnly" style="display: none;" id="' + this.id + '_voice">' + s.title + '</span>';
  7059. h += '</a>';
  7060. return h;
  7061. },
  7062. postRender : function() {
  7063. var t = this, s = t.settings, bookmark;
  7064. // In IE a large image that occupies the entire editor area will be deselected when a button is clicked, so
  7065. // need to keep the selection in case the selection is lost
  7066. if (tinymce.isIE && t.editor) {
  7067. tinymce.dom.Event.add(t.id, 'mousedown', function(e) {
  7068. bookmark = t.editor.selection.getBookmark();
  7069. });
  7070. }
  7071. tinymce.dom.Event.add(t.id, 'click', function(e) {
  7072. if (!t.isDisabled()) {
  7073. // restore the selection in case the selection is lost in IE
  7074. if (tinymce.isIE && t.editor && bookmark) {
  7075. tinymce.activeEditor.selection.moveToBookmark(bookmark);
  7076. }
  7077. return s.onclick.call(s.scope, e);
  7078. }
  7079. });
  7080. tinymce.dom.Event.add(t.id, 'keyup', function(e) {
  7081. if (!t.isDisabled() && e.keyCode==tinymce.VK.SPACEBAR)
  7082. return s.onclick.call(s.scope, e);
  7083. });
  7084. }
  7085. });
  7086. })(tinymce);
  7087. (function(tinymce) {
  7088. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher;
  7089. tinymce.create('tinymce.ui.ListBox:tinymce.ui.Control', {
  7090. ListBox : function(id, s, ed) {
  7091. var t = this;
  7092. t.parent(id, s, ed);
  7093. t.items = [];
  7094. t.onChange = new Dispatcher(t);
  7095. t.onPostRender = new Dispatcher(t);
  7096. t.onAdd = new Dispatcher(t);
  7097. t.onRenderMenu = new tinymce.util.Dispatcher(this);
  7098. t.classPrefix = 'mceListBox';
  7099. },
  7100. select : function(va) {
  7101. var t = this, fv, f;
  7102. if (va == undefined)
  7103. return t.selectByIndex(-1);
  7104. // Is string or number make function selector
  7105. if (va && va.call)
  7106. f = va;
  7107. else {
  7108. f = function(v) {
  7109. return v == va;
  7110. };
  7111. }
  7112. // Do we need to do something?
  7113. if (va != t.selectedValue) {
  7114. // Find item
  7115. each(t.items, function(o, i) {
  7116. if (f(o.value)) {
  7117. fv = 1;
  7118. t.selectByIndex(i);
  7119. return false;
  7120. }
  7121. });
  7122. if (!fv)
  7123. t.selectByIndex(-1);
  7124. }
  7125. },
  7126. selectByIndex : function(idx) {
  7127. var t = this, e, o, label;
  7128. if (idx != t.selectedIndex) {
  7129. e = DOM.get(t.id + '_text');
  7130. label = DOM.get(t.id + '_voiceDesc');
  7131. o = t.items[idx];
  7132. if (o) {
  7133. t.selectedValue = o.value;
  7134. t.selectedIndex = idx;
  7135. DOM.setHTML(e, DOM.encode(o.title));
  7136. DOM.setHTML(label, t.settings.title + " - " + o.title);
  7137. DOM.removeClass(e, 'mceTitle');
  7138. DOM.setAttrib(t.id, 'aria-valuenow', o.title);
  7139. } else {
  7140. DOM.setHTML(e, DOM.encode(t.settings.title));
  7141. DOM.setHTML(label, DOM.encode(t.settings.title));
  7142. DOM.addClass(e, 'mceTitle');
  7143. t.selectedValue = t.selectedIndex = null;
  7144. DOM.setAttrib(t.id, 'aria-valuenow', t.settings.title);
  7145. }
  7146. e = 0;
  7147. }
  7148. },
  7149. add : function(n, v, o) {
  7150. var t = this;
  7151. o = o || {};
  7152. o = tinymce.extend(o, {
  7153. title : n,
  7154. value : v
  7155. });
  7156. t.items.push(o);
  7157. t.onAdd.dispatch(t, o);
  7158. },
  7159. getLength : function() {
  7160. return this.items.length;
  7161. },
  7162. renderHTML : function() {
  7163. var h = '', t = this, s = t.settings, cp = t.classPrefix;
  7164. 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>';
  7165. h += '<td>' + DOM.createHTML('span', {id: t.id + '_voiceDesc', 'class': 'voiceLabel', style:'display:none;'}, t.settings.title);
  7166. 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>';
  7167. 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>';
  7168. h += '</tr></tbody></table></span>';
  7169. return h;
  7170. },
  7171. showMenu : function() {
  7172. var t = this, p2, e = DOM.get(this.id), m;
  7173. if (t.isDisabled() || t.items.length == 0)
  7174. return;
  7175. if (t.menu && t.menu.isMenuVisible)
  7176. return t.hideMenu();
  7177. if (!t.isMenuRendered) {
  7178. t.renderMenu();
  7179. t.isMenuRendered = true;
  7180. }
  7181. p2 = DOM.getPos(e);
  7182. m = t.menu;
  7183. m.settings.offset_x = p2.x;
  7184. m.settings.offset_y = p2.y;
  7185. m.settings.keyboard_focus = !tinymce.isOpera; // Opera is buggy when it comes to auto focus
  7186. // Select in menu
  7187. if (t.oldID)
  7188. m.items[t.oldID].setSelected(0);
  7189. each(t.items, function(o) {
  7190. if (o.value === t.selectedValue) {
  7191. m.items[o.id].setSelected(1);
  7192. t.oldID = o.id;
  7193. }
  7194. });
  7195. m.showMenu(0, e.clientHeight);
  7196. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  7197. DOM.addClass(t.id, t.classPrefix + 'Selected');
  7198. //DOM.get(t.id + '_text').focus();
  7199. },
  7200. hideMenu : function(e) {
  7201. var t = this;
  7202. if (t.menu && t.menu.isMenuVisible) {
  7203. DOM.removeClass(t.id, t.classPrefix + 'Selected');
  7204. // Prevent double toogles by canceling the mouse click event to the button
  7205. if (e && e.type == "mousedown" && (e.target.id == t.id + '_text' || e.target.id == t.id + '_open'))
  7206. return;
  7207. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  7208. DOM.removeClass(t.id, t.classPrefix + 'Selected');
  7209. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  7210. t.menu.hideMenu();
  7211. }
  7212. }
  7213. },
  7214. renderMenu : function() {
  7215. var t = this, m;
  7216. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  7217. menu_line : 1,
  7218. 'class' : t.classPrefix + 'Menu mceNoIcons',
  7219. max_width : 150,
  7220. max_height : 150
  7221. });
  7222. m.onHideMenu.add(function() {
  7223. t.hideMenu();
  7224. t.focus();
  7225. });
  7226. m.add({
  7227. title : t.settings.title,
  7228. 'class' : 'mceMenuItemTitle',
  7229. onclick : function() {
  7230. if (t.settings.onselect('') !== false)
  7231. t.select(''); // Must be runned after
  7232. }
  7233. });
  7234. each(t.items, function(o) {
  7235. // No value then treat it as a title
  7236. if (o.value === undefined) {
  7237. m.add({
  7238. title : o.title,
  7239. role : "option",
  7240. 'class' : 'mceMenuItemTitle',
  7241. onclick : function() {
  7242. if (t.settings.onselect('') !== false)
  7243. t.select(''); // Must be runned after
  7244. }
  7245. });
  7246. } else {
  7247. o.id = DOM.uniqueId();
  7248. o.role= "option";
  7249. o.onclick = function() {
  7250. if (t.settings.onselect(o.value) !== false)
  7251. t.select(o.value); // Must be runned after
  7252. };
  7253. m.add(o);
  7254. }
  7255. });
  7256. t.onRenderMenu.dispatch(t, m);
  7257. t.menu = m;
  7258. },
  7259. postRender : function() {
  7260. var t = this, cp = t.classPrefix;
  7261. Event.add(t.id, 'click', t.showMenu, t);
  7262. Event.add(t.id, 'keydown', function(evt) {
  7263. if (evt.keyCode == 32) { // Space
  7264. t.showMenu(evt);
  7265. Event.cancel(evt);
  7266. }
  7267. });
  7268. Event.add(t.id, 'focus', function() {
  7269. if (!t._focused) {
  7270. t.keyDownHandler = Event.add(t.id, 'keydown', function(e) {
  7271. if (e.keyCode == 40) {
  7272. t.showMenu();
  7273. Event.cancel(e);
  7274. }
  7275. });
  7276. t.keyPressHandler = Event.add(t.id, 'keypress', function(e) {
  7277. var v;
  7278. if (e.keyCode == 13) {
  7279. // Fake select on enter
  7280. v = t.selectedValue;
  7281. t.selectedValue = null; // Needs to be null to fake change
  7282. Event.cancel(e);
  7283. t.settings.onselect(v);
  7284. }
  7285. });
  7286. }
  7287. t._focused = 1;
  7288. });
  7289. Event.add(t.id, 'blur', function() {
  7290. Event.remove(t.id, 'keydown', t.keyDownHandler);
  7291. Event.remove(t.id, 'keypress', t.keyPressHandler);
  7292. t._focused = 0;
  7293. });
  7294. // Old IE doesn't have hover on all elements
  7295. if (tinymce.isIE6 || !DOM.boxModel) {
  7296. Event.add(t.id, 'mouseover', function() {
  7297. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  7298. DOM.addClass(t.id, cp + 'Hover');
  7299. });
  7300. Event.add(t.id, 'mouseout', function() {
  7301. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  7302. DOM.removeClass(t.id, cp + 'Hover');
  7303. });
  7304. }
  7305. t.onPostRender.dispatch(t, DOM.get(t.id));
  7306. },
  7307. destroy : function() {
  7308. this.parent();
  7309. Event.clear(this.id + '_text');
  7310. Event.clear(this.id + '_open');
  7311. }
  7312. });
  7313. })(tinymce);
  7314. (function(tinymce) {
  7315. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher;
  7316. tinymce.create('tinymce.ui.NativeListBox:tinymce.ui.ListBox', {
  7317. NativeListBox : function(id, s) {
  7318. this.parent(id, s);
  7319. this.classPrefix = 'mceNativeListBox';
  7320. },
  7321. setDisabled : function(s) {
  7322. DOM.get(this.id).disabled = s;
  7323. this.setAriaProperty('disabled', s);
  7324. },
  7325. isDisabled : function() {
  7326. return DOM.get(this.id).disabled;
  7327. },
  7328. select : function(va) {
  7329. var t = this, fv, f;
  7330. if (va == undefined)
  7331. return t.selectByIndex(-1);
  7332. // Is string or number make function selector
  7333. if (va && va.call)
  7334. f = va;
  7335. else {
  7336. f = function(v) {
  7337. return v == va;
  7338. };
  7339. }
  7340. // Do we need to do something?
  7341. if (va != t.selectedValue) {
  7342. // Find item
  7343. each(t.items, function(o, i) {
  7344. if (f(o.value)) {
  7345. fv = 1;
  7346. t.selectByIndex(i);
  7347. return false;
  7348. }
  7349. });
  7350. if (!fv)
  7351. t.selectByIndex(-1);
  7352. }
  7353. },
  7354. selectByIndex : function(idx) {
  7355. DOM.get(this.id).selectedIndex = idx + 1;
  7356. this.selectedValue = this.items[idx] ? this.items[idx].value : null;
  7357. },
  7358. add : function(n, v, a) {
  7359. var o, t = this;
  7360. a = a || {};
  7361. a.value = v;
  7362. if (t.isRendered())
  7363. DOM.add(DOM.get(this.id), 'option', a, n);
  7364. o = {
  7365. title : n,
  7366. value : v,
  7367. attribs : a
  7368. };
  7369. t.items.push(o);
  7370. t.onAdd.dispatch(t, o);
  7371. },
  7372. getLength : function() {
  7373. return this.items.length;
  7374. },
  7375. renderHTML : function() {
  7376. var h, t = this;
  7377. h = DOM.createHTML('option', {value : ''}, '-- ' + t.settings.title + ' --');
  7378. each(t.items, function(it) {
  7379. h += DOM.createHTML('option', {value : it.value}, it.title);
  7380. });
  7381. h = DOM.createHTML('select', {id : t.id, 'class' : 'mceNativeListBox', 'aria-labelledby': t.id + '_aria'}, h);
  7382. h += DOM.createHTML('span', {id : t.id + '_aria', 'style': 'display: none'}, t.settings.title);
  7383. return h;
  7384. },
  7385. postRender : function() {
  7386. var t = this, ch, changeListenerAdded = true;
  7387. t.rendered = true;
  7388. function onChange(e) {
  7389. var v = t.items[e.target.selectedIndex - 1];
  7390. if (v && (v = v.value)) {
  7391. t.onChange.dispatch(t, v);
  7392. if (t.settings.onselect)
  7393. t.settings.onselect(v);
  7394. }
  7395. };
  7396. Event.add(t.id, 'change', onChange);
  7397. // Accessibility keyhandler
  7398. Event.add(t.id, 'keydown', function(e) {
  7399. var bf;
  7400. Event.remove(t.id, 'change', ch);
  7401. changeListenerAdded = false;
  7402. bf = Event.add(t.id, 'blur', function() {
  7403. if (changeListenerAdded) return;
  7404. changeListenerAdded = true;
  7405. Event.add(t.id, 'change', onChange);
  7406. Event.remove(t.id, 'blur', bf);
  7407. });
  7408. //prevent default left and right keys on chrome - so that the keyboard navigation is used.
  7409. if (tinymce.isWebKit && (e.keyCode==37 ||e.keyCode==39)) {
  7410. return Event.prevent(e);
  7411. }
  7412. if (e.keyCode == 13 || e.keyCode == 32) {
  7413. onChange(e);
  7414. return Event.cancel(e);
  7415. }
  7416. });
  7417. t.onPostRender.dispatch(t, DOM.get(t.id));
  7418. }
  7419. });
  7420. })(tinymce);
  7421. (function(tinymce) {
  7422. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  7423. tinymce.create('tinymce.ui.MenuButton:tinymce.ui.Button', {
  7424. MenuButton : function(id, s, ed) {
  7425. this.parent(id, s, ed);
  7426. this.onRenderMenu = new tinymce.util.Dispatcher(this);
  7427. s.menu_container = s.menu_container || DOM.doc.body;
  7428. },
  7429. showMenu : function() {
  7430. var t = this, p1, p2, e = DOM.get(t.id), m;
  7431. if (t.isDisabled())
  7432. return;
  7433. if (!t.isMenuRendered) {
  7434. t.renderMenu();
  7435. t.isMenuRendered = true;
  7436. }
  7437. if (t.isMenuVisible)
  7438. return t.hideMenu();
  7439. p1 = DOM.getPos(t.settings.menu_container);
  7440. p2 = DOM.getPos(e);
  7441. m = t.menu;
  7442. m.settings.offset_x = p2.x;
  7443. m.settings.offset_y = p2.y;
  7444. m.settings.vp_offset_x = p2.x;
  7445. m.settings.vp_offset_y = p2.y;
  7446. m.settings.keyboard_focus = t._focused;
  7447. m.showMenu(0, e.clientHeight);
  7448. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  7449. t.setState('Selected', 1);
  7450. t.isMenuVisible = 1;
  7451. },
  7452. renderMenu : function() {
  7453. var t = this, m;
  7454. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  7455. menu_line : 1,
  7456. 'class' : this.classPrefix + 'Menu',
  7457. icons : t.settings.icons
  7458. });
  7459. m.onHideMenu.add(function() {
  7460. t.hideMenu();
  7461. t.focus();
  7462. });
  7463. t.onRenderMenu.dispatch(t, m);
  7464. t.menu = m;
  7465. },
  7466. hideMenu : function(e) {
  7467. var t = this;
  7468. // Prevent double toogles by canceling the mouse click event to the button
  7469. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id || e.id === t.id + '_open';}))
  7470. return;
  7471. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  7472. t.setState('Selected', 0);
  7473. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  7474. if (t.menu)
  7475. t.menu.hideMenu();
  7476. }
  7477. t.isMenuVisible = 0;
  7478. },
  7479. postRender : function() {
  7480. var t = this, s = t.settings;
  7481. Event.add(t.id, 'click', function() {
  7482. if (!t.isDisabled()) {
  7483. if (s.onclick)
  7484. s.onclick(t.value);
  7485. t.showMenu();
  7486. }
  7487. });
  7488. }
  7489. });
  7490. })(tinymce);
  7491. (function(tinymce) {
  7492. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  7493. tinymce.create('tinymce.ui.SplitButton:tinymce.ui.MenuButton', {
  7494. SplitButton : function(id, s, ed) {
  7495. this.parent(id, s, ed);
  7496. this.classPrefix = 'mceSplitButton';
  7497. },
  7498. renderHTML : function() {
  7499. var h, t = this, s = t.settings, h1;
  7500. h = '<tbody><tr>';
  7501. if (s.image)
  7502. h1 = DOM.createHTML('img ', {src : s.image, role: 'presentation', 'class' : 'mceAction ' + s['class']});
  7503. else
  7504. h1 = DOM.createHTML('span', {'class' : 'mceAction ' + s['class']}, '');
  7505. h1 += DOM.createHTML('span', {'class': 'mceVoiceLabel mceIconOnly', id: t.id + '_voice', style: 'display:none;'}, s.title);
  7506. 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>';
  7507. h1 = DOM.createHTML('span', {'class' : 'mceOpen ' + s['class']}, '<span style="display:none;" class="mceIconOnly" aria-hidden="true">\u25BC</span>');
  7508. 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>';
  7509. h += '</tr></tbody>';
  7510. h = DOM.createHTML('table', { role: 'presentation', 'class' : 'mceSplitButton mceSplitButtonEnabled ' + s['class'], cellpadding : '0', cellspacing : '0', title : s.title}, h);
  7511. return DOM.createHTML('div', {id : t.id, role: 'button', tabindex: '0', 'aria-labelledby': t.id + '_voice', 'aria-haspopup': 'true'}, h);
  7512. },
  7513. postRender : function() {
  7514. var t = this, s = t.settings, activate;
  7515. if (s.onclick) {
  7516. activate = function(evt) {
  7517. if (!t.isDisabled()) {
  7518. s.onclick(t.value);
  7519. Event.cancel(evt);
  7520. }
  7521. };
  7522. Event.add(t.id + '_action', 'click', activate);
  7523. Event.add(t.id, ['click', 'keydown'], function(evt) {
  7524. var DOM_VK_SPACE = 32, DOM_VK_ENTER = 14, DOM_VK_RETURN = 13, DOM_VK_UP = 38, DOM_VK_DOWN = 40;
  7525. if ((evt.keyCode === 32 || evt.keyCode === 13 || evt.keyCode === 14) && !evt.altKey && !evt.ctrlKey && !evt.metaKey) {
  7526. activate();
  7527. Event.cancel(evt);
  7528. } else if (evt.type === 'click' || evt.keyCode === DOM_VK_DOWN) {
  7529. t.showMenu();
  7530. Event.cancel(evt);
  7531. }
  7532. });
  7533. }
  7534. Event.add(t.id + '_open', 'click', function (evt) {
  7535. t.showMenu();
  7536. Event.cancel(evt);
  7537. });
  7538. Event.add([t.id, t.id + '_open'], 'focus', function() {t._focused = 1;});
  7539. Event.add([t.id, t.id + '_open'], 'blur', function() {t._focused = 0;});
  7540. // Old IE doesn't have hover on all elements
  7541. if (tinymce.isIE6 || !DOM.boxModel) {
  7542. Event.add(t.id, 'mouseover', function() {
  7543. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  7544. DOM.addClass(t.id, 'mceSplitButtonHover');
  7545. });
  7546. Event.add(t.id, 'mouseout', function() {
  7547. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  7548. DOM.removeClass(t.id, 'mceSplitButtonHover');
  7549. });
  7550. }
  7551. },
  7552. destroy : function() {
  7553. this.parent();
  7554. Event.clear(this.id + '_action');
  7555. Event.clear(this.id + '_open');
  7556. Event.clear(this.id);
  7557. }
  7558. });
  7559. })(tinymce);
  7560. (function(tinymce) {
  7561. var DOM = tinymce.DOM, Event = tinymce.dom.Event, is = tinymce.is, each = tinymce.each;
  7562. tinymce.create('tinymce.ui.ColorSplitButton:tinymce.ui.SplitButton', {
  7563. ColorSplitButton : function(id, s, ed) {
  7564. var t = this;
  7565. t.parent(id, s, ed);
  7566. t.settings = s = tinymce.extend({
  7567. 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',
  7568. grid_width : 8,
  7569. default_color : '#888888'
  7570. }, t.settings);
  7571. t.onShowMenu = new tinymce.util.Dispatcher(t);
  7572. t.onHideMenu = new tinymce.util.Dispatcher(t);
  7573. t.value = s.default_color;
  7574. },
  7575. showMenu : function() {
  7576. var t = this, r, p, e, p2;
  7577. if (t.isDisabled())
  7578. return;
  7579. if (!t.isMenuRendered) {
  7580. t.renderMenu();
  7581. t.isMenuRendered = true;
  7582. }
  7583. if (t.isMenuVisible)
  7584. return t.hideMenu();
  7585. e = DOM.get(t.id);
  7586. DOM.show(t.id + '_menu');
  7587. DOM.addClass(e, 'mceSplitButtonSelected');
  7588. p2 = DOM.getPos(e);
  7589. DOM.setStyles(t.id + '_menu', {
  7590. left : p2.x,
  7591. top : p2.y + e.clientHeight,
  7592. zIndex : 200000
  7593. });
  7594. e = 0;
  7595. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  7596. t.onShowMenu.dispatch(t);
  7597. if (t._focused) {
  7598. t._keyHandler = Event.add(t.id + '_menu', 'keydown', function(e) {
  7599. if (e.keyCode == 27)
  7600. t.hideMenu();
  7601. });
  7602. DOM.select('a', t.id + '_menu')[0].focus(); // Select first link
  7603. }
  7604. t.isMenuVisible = 1;
  7605. },
  7606. hideMenu : function(e) {
  7607. var t = this;
  7608. if (t.isMenuVisible) {
  7609. // Prevent double toogles by canceling the mouse click event to the button
  7610. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id + '_open';}))
  7611. return;
  7612. if (!e || !DOM.getParent(e.target, '.mceSplitButtonMenu')) {
  7613. DOM.removeClass(t.id, 'mceSplitButtonSelected');
  7614. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  7615. Event.remove(t.id + '_menu', 'keydown', t._keyHandler);
  7616. DOM.hide(t.id + '_menu');
  7617. }
  7618. t.isMenuVisible = 0;
  7619. t.onHideMenu.dispatch();
  7620. }
  7621. },
  7622. renderMenu : function() {
  7623. var t = this, m, i = 0, s = t.settings, n, tb, tr, w, context;
  7624. 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;'});
  7625. m = DOM.add(w, 'div', {'class' : s['class'] + ' mceSplitButtonMenu'});
  7626. DOM.add(m, 'span', {'class' : 'mceMenuLine'});
  7627. n = DOM.add(m, 'table', {role: 'presentation', 'class' : 'mceColorSplitMenu'});
  7628. tb = DOM.add(n, 'tbody');
  7629. // Generate color grid
  7630. i = 0;
  7631. each(is(s.colors, 'array') ? s.colors : s.colors.split(','), function(c) {
  7632. c = c.replace(/^#/, '');
  7633. if (!i--) {
  7634. tr = DOM.add(tb, 'tr');
  7635. i = s.grid_width - 1;
  7636. }
  7637. n = DOM.add(tr, 'td');
  7638. var settings = {
  7639. href : 'javascript:;',
  7640. style : {
  7641. backgroundColor : '#' + c
  7642. },
  7643. 'title': t.editor.getLang('colors.' + c, c),
  7644. 'data-mce-color' : '#' + c
  7645. };
  7646. // adding a proper ARIA role = button causes JAWS to read things incorrectly on IE.
  7647. if (!tinymce.isIE ) {
  7648. settings['role']= 'option';
  7649. }
  7650. n = DOM.add(n, 'a', settings);
  7651. if (t.editor.forcedHighContrastMode) {
  7652. n = DOM.add(n, 'canvas', { width: 16, height: 16, 'aria-hidden': 'true' });
  7653. if (n.getContext && (context = n.getContext("2d"))) {
  7654. context.fillStyle = '#' + c;
  7655. context.fillRect(0, 0, 16, 16);
  7656. } else {
  7657. // No point leaving a canvas element around if it's not supported for drawing on anyway.
  7658. DOM.remove(n);
  7659. }
  7660. }
  7661. });
  7662. if (s.more_colors_func) {
  7663. n = DOM.add(tb, 'tr');
  7664. n = DOM.add(n, 'td', {colspan : s.grid_width, 'class' : 'mceMoreColors'});
  7665. n = DOM.add(n, 'a', {role: 'option', id : t.id + '_more', href : 'javascript:;', onclick : 'return false;', 'class' : 'mceMoreColors'}, s.more_colors_title);
  7666. Event.add(n, 'click', function(e) {
  7667. s.more_colors_func.call(s.more_colors_scope || this);
  7668. return Event.cancel(e); // Cancel to fix onbeforeunload problem
  7669. });
  7670. }
  7671. DOM.addClass(m, 'mceColorSplitMenu');
  7672. new tinymce.ui.KeyboardNavigation({
  7673. root: t.id + '_menu',
  7674. items: DOM.select('a', t.id + '_menu'),
  7675. onCancel: function() {
  7676. t.hideMenu();
  7677. t.focus();
  7678. }
  7679. });
  7680. // Prevent IE from scrolling and hindering click to occur #4019
  7681. Event.add(t.id + '_menu', 'mousedown', function(e) {return Event.cancel(e);});
  7682. Event.add(t.id + '_menu', 'click', function(e) {
  7683. var c;
  7684. e = DOM.getParent(e.target, 'a', tb);
  7685. if (e && e.nodeName.toLowerCase() == 'a' && (c = e.getAttribute('data-mce-color')))
  7686. t.setColor(c);
  7687. return Event.cancel(e); // Prevent IE auto save warning
  7688. });
  7689. return w;
  7690. },
  7691. setColor : function(c) {
  7692. this.displayColor(c);
  7693. this.hideMenu();
  7694. this.settings.onselect(c);
  7695. },
  7696. displayColor : function(c) {
  7697. var t = this;
  7698. DOM.setStyle(t.id + '_preview', 'backgroundColor', c);
  7699. t.value = c;
  7700. },
  7701. postRender : function() {
  7702. var t = this, id = t.id;
  7703. t.parent();
  7704. DOM.add(id + '_action', 'div', {id : id + '_preview', 'class' : 'mceColorPreview'});
  7705. DOM.setStyle(t.id + '_preview', 'backgroundColor', t.value);
  7706. },
  7707. destroy : function() {
  7708. this.parent();
  7709. Event.clear(this.id + '_menu');
  7710. Event.clear(this.id + '_more');
  7711. DOM.remove(this.id + '_menu');
  7712. }
  7713. });
  7714. })(tinymce);
  7715. (function(tinymce) {
  7716. // Shorten class names
  7717. var dom = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event;
  7718. tinymce.create('tinymce.ui.ToolbarGroup:tinymce.ui.Container', {
  7719. renderHTML : function() {
  7720. var t = this, h = [], controls = t.controls, each = tinymce.each, settings = t.settings;
  7721. h.push('<div id="' + t.id + '" role="group" aria-labelledby="' + t.id + '_voice">');
  7722. //TODO: ACC test this out - adding a role = application for getting the landmarks working well.
  7723. h.push("<span role='application'>");
  7724. h.push('<span id="' + t.id + '_voice" class="mceVoiceLabel" style="display:none;">' + dom.encode(settings.name) + '</span>');
  7725. each(controls, function(toolbar) {
  7726. h.push(toolbar.renderHTML());
  7727. });
  7728. h.push("</span>");
  7729. h.push('</div>');
  7730. return h.join('');
  7731. },
  7732. focus : function() {
  7733. var t = this;
  7734. dom.get(t.id).focus();
  7735. },
  7736. postRender : function() {
  7737. var t = this, items = [];
  7738. each(t.controls, function(toolbar) {
  7739. each (toolbar.controls, function(control) {
  7740. if (control.id) {
  7741. items.push(control);
  7742. }
  7743. });
  7744. });
  7745. t.keyNav = new tinymce.ui.KeyboardNavigation({
  7746. root: t.id,
  7747. items: items,
  7748. onCancel: function() {
  7749. //Move focus if webkit so that navigation back will read the item.
  7750. if (tinymce.isWebKit) {
  7751. dom.get(t.editor.id+"_ifr").focus();
  7752. }
  7753. t.editor.focus();
  7754. },
  7755. excludeFromTabOrder: !t.settings.tab_focus_toolbar
  7756. });
  7757. },
  7758. destroy : function() {
  7759. var self = this;
  7760. self.parent();
  7761. self.keyNav.destroy();
  7762. Event.clear(self.id);
  7763. }
  7764. });
  7765. })(tinymce);
  7766. (function(tinymce) {
  7767. // Shorten class names
  7768. var dom = tinymce.DOM, each = tinymce.each;
  7769. tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', {
  7770. renderHTML : function() {
  7771. var t = this, h = '', c, co, s = t.settings, i, pr, nx, cl;
  7772. cl = t.controls;
  7773. for (i=0; i<cl.length; i++) {
  7774. // Get current control, prev control, next control and if the control is a list box or not
  7775. co = cl[i];
  7776. pr = cl[i - 1];
  7777. nx = cl[i + 1];
  7778. // Add toolbar start
  7779. if (i === 0) {
  7780. c = 'mceToolbarStart';
  7781. if (co.Button)
  7782. c += ' mceToolbarStartButton';
  7783. else if (co.SplitButton)
  7784. c += ' mceToolbarStartSplitButton';
  7785. else if (co.ListBox)
  7786. c += ' mceToolbarStartListBox';
  7787. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  7788. }
  7789. // Add toolbar end before list box and after the previous button
  7790. // This is to fix the o2k7 editor skins
  7791. if (pr && co.ListBox) {
  7792. if (pr.Button || pr.SplitButton)
  7793. h += dom.createHTML('td', {'class' : 'mceToolbarEnd'}, dom.createHTML('span', null, '<!-- IE -->'));
  7794. }
  7795. // Render control HTML
  7796. // IE 8 quick fix, needed to propertly generate a hit area for anchors
  7797. if (dom.stdMode)
  7798. h += '<td style="position: relative">' + co.renderHTML() + '</td>';
  7799. else
  7800. h += '<td>' + co.renderHTML() + '</td>';
  7801. // Add toolbar start after list box and before the next button
  7802. // This is to fix the o2k7 editor skins
  7803. if (nx && co.ListBox) {
  7804. if (nx.Button || nx.SplitButton)
  7805. h += dom.createHTML('td', {'class' : 'mceToolbarStart'}, dom.createHTML('span', null, '<!-- IE -->'));
  7806. }
  7807. }
  7808. c = 'mceToolbarEnd';
  7809. if (co.Button)
  7810. c += ' mceToolbarEndButton';
  7811. else if (co.SplitButton)
  7812. c += ' mceToolbarEndSplitButton';
  7813. else if (co.ListBox)
  7814. c += ' mceToolbarEndListBox';
  7815. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  7816. 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>');
  7817. }
  7818. });
  7819. })(tinymce);
  7820. (function(tinymce) {
  7821. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each;
  7822. tinymce.create('tinymce.AddOnManager', {
  7823. AddOnManager : function() {
  7824. var self = this;
  7825. self.items = [];
  7826. self.urls = {};
  7827. self.lookup = {};
  7828. self.onAdd = new Dispatcher(self);
  7829. },
  7830. get : function(n) {
  7831. if (this.lookup[n]) {
  7832. return this.lookup[n].instance;
  7833. } else {
  7834. return undefined;
  7835. }
  7836. },
  7837. dependencies : function(n) {
  7838. var result;
  7839. if (this.lookup[n]) {
  7840. result = this.lookup[n].dependencies;
  7841. }
  7842. return result || [];
  7843. },
  7844. requireLangPack : function(n) {
  7845. var s = tinymce.settings;
  7846. if (s && s.language && s.language_load !== false)
  7847. tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js');
  7848. },
  7849. add : function(id, o, dependencies) {
  7850. this.items.push(o);
  7851. this.lookup[id] = {instance:o, dependencies:dependencies};
  7852. this.onAdd.dispatch(this, id, o);
  7853. return o;
  7854. },
  7855. createUrl: function(baseUrl, dep) {
  7856. if (typeof dep === "object") {
  7857. return dep
  7858. } else {
  7859. return {prefix: baseUrl.prefix, resource: dep, suffix: baseUrl.suffix};
  7860. }
  7861. },
  7862. addComponents: function(pluginName, scripts) {
  7863. var pluginUrl = this.urls[pluginName];
  7864. tinymce.each(scripts, function(script){
  7865. tinymce.ScriptLoader.add(pluginUrl+"/"+script);
  7866. });
  7867. },
  7868. load : function(n, u, cb, s) {
  7869. var t = this, url = u;
  7870. function loadDependencies() {
  7871. var dependencies = t.dependencies(n);
  7872. tinymce.each(dependencies, function(dep) {
  7873. var newUrl = t.createUrl(u, dep);
  7874. t.load(newUrl.resource, newUrl, undefined, undefined);
  7875. });
  7876. if (cb) {
  7877. if (s) {
  7878. cb.call(s);
  7879. } else {
  7880. cb.call(tinymce.ScriptLoader);
  7881. }
  7882. }
  7883. }
  7884. if (t.urls[n])
  7885. return;
  7886. if (typeof u === "object")
  7887. url = u.prefix + u.resource + u.suffix;
  7888. if (url.indexOf('/') != 0 && url.indexOf('://') == -1)
  7889. url = tinymce.baseURL + '/' + url;
  7890. t.urls[n] = url.substring(0, url.lastIndexOf('/'));
  7891. if (t.lookup[n]) {
  7892. loadDependencies();
  7893. } else {
  7894. tinymce.ScriptLoader.add(url, loadDependencies, s);
  7895. }
  7896. }
  7897. });
  7898. // Create plugin and theme managers
  7899. tinymce.PluginManager = new tinymce.AddOnManager();
  7900. tinymce.ThemeManager = new tinymce.AddOnManager();
  7901. }(tinymce));
  7902. (function(tinymce) {
  7903. // Shorten names
  7904. var each = tinymce.each, extend = tinymce.extend,
  7905. DOM = tinymce.DOM, Event = tinymce.dom.Event,
  7906. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  7907. explode = tinymce.explode,
  7908. Dispatcher = tinymce.util.Dispatcher, undefined, instanceCounter = 0;
  7909. // Setup some URLs where the editor API is located and where the document is
  7910. tinymce.documentBaseURL = window.location.href.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '');
  7911. if (!/[\/\\]$/.test(tinymce.documentBaseURL))
  7912. tinymce.documentBaseURL += '/';
  7913. tinymce.baseURL = new tinymce.util.URI(tinymce.documentBaseURL).toAbsolute(tinymce.baseURL);
  7914. tinymce.baseURI = new tinymce.util.URI(tinymce.baseURL);
  7915. // Add before unload listener
  7916. // This was required since IE was leaking memory if you added and removed beforeunload listeners
  7917. // with attachEvent/detatchEvent so this only adds one listener and instances can the attach to the onBeforeUnload event
  7918. tinymce.onBeforeUnload = new Dispatcher(tinymce);
  7919. // Must be on window or IE will leak if the editor is placed in frame or iframe
  7920. Event.add(window, 'beforeunload', function(e) {
  7921. tinymce.onBeforeUnload.dispatch(tinymce, e);
  7922. });
  7923. tinymce.onAddEditor = new Dispatcher(tinymce);
  7924. tinymce.onRemoveEditor = new Dispatcher(tinymce);
  7925. tinymce.EditorManager = extend(tinymce, {
  7926. editors : [],
  7927. i18n : {},
  7928. activeEditor : null,
  7929. init : function(s) {
  7930. var t = this, pl, sl = tinymce.ScriptLoader, e, el = [], ed;
  7931. function execCallback(se, n, s) {
  7932. var f = se[n];
  7933. if (!f)
  7934. return;
  7935. if (tinymce.is(f, 'string')) {
  7936. s = f.replace(/\.\w+$/, '');
  7937. s = s ? tinymce.resolve(s) : 0;
  7938. f = tinymce.resolve(f);
  7939. }
  7940. return f.apply(s || this, Array.prototype.slice.call(arguments, 2));
  7941. };
  7942. s = extend({
  7943. theme : "simple",
  7944. language : "en"
  7945. }, s);
  7946. t.settings = s;
  7947. // Legacy call
  7948. Event.add(document, 'init', function() {
  7949. var l, co;
  7950. execCallback(s, 'onpageload');
  7951. switch (s.mode) {
  7952. case "exact":
  7953. l = s.elements || '';
  7954. if(l.length > 0) {
  7955. each(explode(l), function(v) {
  7956. if (DOM.get(v)) {
  7957. ed = new tinymce.Editor(v, s);
  7958. el.push(ed);
  7959. ed.render(1);
  7960. } else {
  7961. each(document.forms, function(f) {
  7962. each(f.elements, function(e) {
  7963. if (e.name === v) {
  7964. v = 'mce_editor_' + instanceCounter++;
  7965. DOM.setAttrib(e, 'id', v);
  7966. ed = new tinymce.Editor(v, s);
  7967. el.push(ed);
  7968. ed.render(1);
  7969. }
  7970. });
  7971. });
  7972. }
  7973. });
  7974. }
  7975. break;
  7976. case "textareas":
  7977. case "specific_textareas":
  7978. function hasClass(n, c) {
  7979. return c.constructor === RegExp ? c.test(n.className) : DOM.hasClass(n, c);
  7980. };
  7981. each(DOM.select('textarea'), function(v) {
  7982. if (s.editor_deselector && hasClass(v, s.editor_deselector))
  7983. return;
  7984. if (!s.editor_selector || hasClass(v, s.editor_selector)) {
  7985. // Can we use the name
  7986. e = DOM.get(v.name);
  7987. if (!v.id && !e)
  7988. v.id = v.name;
  7989. // Generate unique name if missing or already exists
  7990. if (!v.id || t.get(v.id))
  7991. v.id = DOM.uniqueId();
  7992. ed = new tinymce.Editor(v.id, s);
  7993. el.push(ed);
  7994. ed.render(1);
  7995. }
  7996. });
  7997. break;
  7998. }
  7999. // Call onInit when all editors are initialized
  8000. if (s.oninit) {
  8001. l = co = 0;
  8002. each(el, function(ed) {
  8003. co++;
  8004. if (!ed.initialized) {
  8005. // Wait for it
  8006. ed.onInit.add(function() {
  8007. l++;
  8008. // All done
  8009. if (l == co)
  8010. execCallback(s, 'oninit');
  8011. });
  8012. } else
  8013. l++;
  8014. // All done
  8015. if (l == co)
  8016. execCallback(s, 'oninit');
  8017. });
  8018. }
  8019. });
  8020. },
  8021. get : function(id) {
  8022. if (id === undefined)
  8023. return this.editors;
  8024. return this.editors[id];
  8025. },
  8026. getInstanceById : function(id) {
  8027. return this.get(id);
  8028. },
  8029. add : function(editor) {
  8030. var self = this, editors = self.editors;
  8031. // Add named and index editor instance
  8032. editors[editor.id] = editor;
  8033. editors.push(editor);
  8034. self._setActive(editor);
  8035. self.onAddEditor.dispatch(self, editor);
  8036. // Patch the tinymce.Editor instance with jQuery adapter logic
  8037. if (tinymce.adapter)
  8038. tinymce.adapter.patchEditor(editor);
  8039. return editor;
  8040. },
  8041. remove : function(editor) {
  8042. var t = this, i, editors = t.editors;
  8043. // Not in the collection
  8044. if (!editors[editor.id])
  8045. return null;
  8046. delete editors[editor.id];
  8047. for (i = 0; i < editors.length; i++) {
  8048. if (editors[i] == editor) {
  8049. editors.splice(i, 1);
  8050. break;
  8051. }
  8052. }
  8053. // Select another editor since the active one was removed
  8054. if (t.activeEditor == editor)
  8055. t._setActive(editors[0]);
  8056. editor.destroy();
  8057. t.onRemoveEditor.dispatch(t, editor);
  8058. return editor;
  8059. },
  8060. execCommand : function(c, u, v) {
  8061. var t = this, ed = t.get(v), w;
  8062. // Manager commands
  8063. switch (c) {
  8064. case "mceFocus":
  8065. ed.focus();
  8066. return true;
  8067. case "mceAddEditor":
  8068. case "mceAddControl":
  8069. if (!t.get(v))
  8070. new tinymce.Editor(v, t.settings).render();
  8071. return true;
  8072. case "mceAddFrameControl":
  8073. w = v.window;
  8074. // Add tinyMCE global instance and tinymce namespace to specified window
  8075. w.tinyMCE = tinyMCE;
  8076. w.tinymce = tinymce;
  8077. tinymce.DOM.doc = w.document;
  8078. tinymce.DOM.win = w;
  8079. ed = new tinymce.Editor(v.element_id, v);
  8080. ed.render();
  8081. // Fix IE memory leaks
  8082. if (tinymce.isIE) {
  8083. function clr() {
  8084. ed.destroy();
  8085. w.detachEvent('onunload', clr);
  8086. w = w.tinyMCE = w.tinymce = null; // IE leak
  8087. };
  8088. w.attachEvent('onunload', clr);
  8089. }
  8090. v.page_window = null;
  8091. return true;
  8092. case "mceRemoveEditor":
  8093. case "mceRemoveControl":
  8094. if (ed)
  8095. ed.remove();
  8096. return true;
  8097. case 'mceToggleEditor':
  8098. if (!ed) {
  8099. t.execCommand('mceAddControl', 0, v);
  8100. return true;
  8101. }
  8102. if (ed.isHidden())
  8103. ed.show();
  8104. else
  8105. ed.hide();
  8106. return true;
  8107. }
  8108. // Run command on active editor
  8109. if (t.activeEditor)
  8110. return t.activeEditor.execCommand(c, u, v);
  8111. return false;
  8112. },
  8113. execInstanceCommand : function(id, c, u, v) {
  8114. var ed = this.get(id);
  8115. if (ed)
  8116. return ed.execCommand(c, u, v);
  8117. return false;
  8118. },
  8119. triggerSave : function() {
  8120. each(this.editors, function(e) {
  8121. e.save();
  8122. });
  8123. },
  8124. addI18n : function(p, o) {
  8125. var lo, i18n = this.i18n;
  8126. if (!tinymce.is(p, 'string')) {
  8127. each(p, function(o, lc) {
  8128. each(o, function(o, g) {
  8129. each(o, function(o, k) {
  8130. if (g === 'common')
  8131. i18n[lc + '.' + k] = o;
  8132. else
  8133. i18n[lc + '.' + g + '.' + k] = o;
  8134. });
  8135. });
  8136. });
  8137. } else {
  8138. each(o, function(o, k) {
  8139. i18n[p + '.' + k] = o;
  8140. });
  8141. }
  8142. },
  8143. // Private methods
  8144. _setActive : function(editor) {
  8145. this.selectedInstance = this.activeEditor = editor;
  8146. }
  8147. });
  8148. })(tinymce);
  8149. (function(tinymce) {
  8150. // Shorten these names
  8151. var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend,
  8152. Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isGecko = tinymce.isGecko,
  8153. isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, is = tinymce.is,
  8154. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  8155. inArray = tinymce.inArray, grep = tinymce.grep, explode = tinymce.explode, VK = tinymce.VK;
  8156. tinymce.create('tinymce.Editor', {
  8157. Editor : function(id, s) {
  8158. var t = this;
  8159. t.id = t.editorId = id;
  8160. t.execCommands = {};
  8161. t.queryStateCommands = {};
  8162. t.queryValueCommands = {};
  8163. t.isNotDirty = false;
  8164. t.plugins = {};
  8165. // Add events to the editor
  8166. each([
  8167. 'onPreInit',
  8168. 'onBeforeRenderUI',
  8169. 'onPostRender',
  8170. 'onLoad',
  8171. 'onInit',
  8172. 'onRemove',
  8173. 'onActivate',
  8174. 'onDeactivate',
  8175. 'onClick',
  8176. 'onEvent',
  8177. 'onMouseUp',
  8178. 'onMouseDown',
  8179. 'onDblClick',
  8180. 'onKeyDown',
  8181. 'onKeyUp',
  8182. 'onKeyPress',
  8183. 'onContextMenu',
  8184. 'onSubmit',
  8185. 'onReset',
  8186. 'onPaste',
  8187. 'onPreProcess',
  8188. 'onPostProcess',
  8189. 'onBeforeSetContent',
  8190. 'onBeforeGetContent',
  8191. 'onSetContent',
  8192. 'onGetContent',
  8193. 'onLoadContent',
  8194. 'onSaveContent',
  8195. 'onNodeChange',
  8196. 'onChange',
  8197. 'onBeforeExecCommand',
  8198. 'onExecCommand',
  8199. 'onUndo',
  8200. 'onRedo',
  8201. 'onVisualAid',
  8202. 'onSetProgressState',
  8203. 'onSetAttrib'
  8204. ], function(e) {
  8205. t[e] = new Dispatcher(t);
  8206. });
  8207. t.settings = s = extend({
  8208. id : id,
  8209. language : 'en',
  8210. docs_language : 'en',
  8211. theme : 'simple',
  8212. skin : 'default',
  8213. delta_width : 0,
  8214. delta_height : 0,
  8215. popup_css : '',
  8216. plugins : '',
  8217. document_base_url : tinymce.documentBaseURL,
  8218. add_form_submit_trigger : 1,
  8219. submit_patch : 1,
  8220. add_unload_trigger : 1,
  8221. convert_urls : 1,
  8222. relative_urls : 1,
  8223. remove_script_host : 1,
  8224. table_inline_editing : 0,
  8225. object_resizing : 1,
  8226. cleanup : 1,
  8227. accessibility_focus : 1,
  8228. custom_shortcuts : 1,
  8229. custom_undo_redo_keyboard_shortcuts : 1,
  8230. custom_undo_redo_restore_selection : 1,
  8231. custom_undo_redo : 1,
  8232. doctype : tinymce.isIE6 ? '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' : '<!DOCTYPE>', // Use old doctype on IE 6 to avoid horizontal scroll
  8233. visual_table_class : 'mceItemTable',
  8234. visual : 1,
  8235. font_size_style_values : 'xx-small,x-small,small,medium,large,x-large,xx-large',
  8236. 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
  8237. apply_source_formatting : 1,
  8238. directionality : 'ltr',
  8239. forced_root_block : 'p',
  8240. hidden_input : 1,
  8241. padd_empty_editor : 1,
  8242. render_ui : 1,
  8243. init_theme : 1,
  8244. force_p_newlines : 1,
  8245. indentation : '30px',
  8246. keep_styles : 1,
  8247. fix_table_elements : 1,
  8248. inline_styles : 1,
  8249. convert_fonts_to_spans : true,
  8250. indent : 'simple',
  8251. indent_before : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr',
  8252. indent_after : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr',
  8253. validate : true,
  8254. entity_encoding : 'named',
  8255. url_converter : t.convertURL,
  8256. url_converter_scope : t,
  8257. ie7_compat : true
  8258. }, s);
  8259. t.documentBaseURI = new tinymce.util.URI(s.document_base_url || tinymce.documentBaseURL, {
  8260. base_uri : tinyMCE.baseURI
  8261. });
  8262. t.baseURI = tinymce.baseURI;
  8263. t.contentCSS = [];
  8264. // Call setup
  8265. t.execCallback('setup', t);
  8266. },
  8267. render : function(nst) {
  8268. var t = this, s = t.settings, id = t.id, sl = tinymce.ScriptLoader;
  8269. // Page is not loaded yet, wait for it
  8270. if (!Event.domLoaded) {
  8271. Event.add(document, 'init', function() {
  8272. t.render();
  8273. });
  8274. return;
  8275. }
  8276. tinyMCE.settings = s;
  8277. // Element not found, then skip initialization
  8278. if (!t.getElement())
  8279. return;
  8280. // Is a iPad/iPhone and not on iOS5, then skip initialization. We need to sniff
  8281. // here since the browser says it has contentEditable support but there is no visible
  8282. // caret We will remove this check ones Apple implements full contentEditable support
  8283. if (tinymce.isIDevice && !tinymce.isIOS5)
  8284. return;
  8285. // Add hidden input for non input elements inside form elements
  8286. if (!/TEXTAREA|INPUT/i.test(t.getElement().nodeName) && s.hidden_input && DOM.getParent(id, 'form'))
  8287. DOM.insertAfter(DOM.create('input', {type : 'hidden', name : id}), id);
  8288. if (tinymce.WindowManager)
  8289. t.windowManager = new tinymce.WindowManager(t);
  8290. if (s.encoding == 'xml') {
  8291. t.onGetContent.add(function(ed, o) {
  8292. if (o.save)
  8293. o.content = DOM.encode(o.content);
  8294. });
  8295. }
  8296. if (s.add_form_submit_trigger) {
  8297. t.onSubmit.addToTop(function() {
  8298. if (t.initialized) {
  8299. t.save();
  8300. t.isNotDirty = 1;
  8301. }
  8302. });
  8303. }
  8304. if (s.add_unload_trigger) {
  8305. t._beforeUnload = tinyMCE.onBeforeUnload.add(function() {
  8306. if (t.initialized && !t.destroyed && !t.isHidden())
  8307. t.save({format : 'raw', no_events : true});
  8308. });
  8309. }
  8310. tinymce.addUnload(t.destroy, t);
  8311. if (s.submit_patch) {
  8312. t.onBeforeRenderUI.add(function() {
  8313. var n = t.getElement().form;
  8314. if (!n)
  8315. return;
  8316. // Already patched
  8317. if (n._mceOldSubmit)
  8318. return;
  8319. // Check page uses id="submit" or name="submit" for it's submit button
  8320. if (!n.submit.nodeType && !n.submit.length) {
  8321. t.formElement = n;
  8322. n._mceOldSubmit = n.submit;
  8323. n.submit = function() {
  8324. // Save all instances
  8325. tinymce.triggerSave();
  8326. t.isNotDirty = 1;
  8327. return t.formElement._mceOldSubmit(t.formElement);
  8328. };
  8329. }
  8330. n = null;
  8331. });
  8332. }
  8333. // Load scripts
  8334. function loadScripts() {
  8335. if (s.language && s.language_load !== false)
  8336. sl.add(tinymce.baseURL + '/langs/' + s.language + '.js');
  8337. if (s.theme && s.theme.charAt(0) != '-' && !ThemeManager.urls[s.theme])
  8338. ThemeManager.load(s.theme, 'themes/' + s.theme + '/editor_template' + tinymce.suffix + '.js');
  8339. each(explode(s.plugins), function(p) {
  8340. if (p &&!PluginManager.urls[p]) {
  8341. if (p.charAt(0) == '-') {
  8342. p = p.substr(1, p.length);
  8343. var dependencies = PluginManager.dependencies(p);
  8344. each(dependencies, function(dep) {
  8345. var defaultSettings = {prefix:'plugins/', resource: dep, suffix:'/editor_plugin' + tinymce.suffix + '.js'};
  8346. var dep = PluginManager.createUrl(defaultSettings, dep);
  8347. PluginManager.load(dep.resource, dep);
  8348. });
  8349. } else {
  8350. // Skip safari plugin, since it is removed as of 3.3b1
  8351. if (p == 'safari') {
  8352. return;
  8353. }
  8354. PluginManager.load(p, {prefix:'plugins/', resource: p, suffix:'/editor_plugin' + tinymce.suffix + '.js'});
  8355. }
  8356. }
  8357. });
  8358. // Init when que is loaded
  8359. sl.loadQueue(function() {
  8360. if (!t.removed)
  8361. t.init();
  8362. });
  8363. };
  8364. loadScripts();
  8365. },
  8366. init : function() {
  8367. var n, t = this, s = t.settings, w, h, e = t.getElement(), o, ti, u, bi, bc, re, i, initializedPlugins = [];
  8368. tinymce.add(t);
  8369. s.aria_label = s.aria_label || DOM.getAttrib(e, 'aria-label', t.getLang('aria.rich_text_area'));
  8370. if (s.theme) {
  8371. s.theme = s.theme.replace(/-/, '');
  8372. o = ThemeManager.get(s.theme);
  8373. t.theme = new o();
  8374. if (t.theme.init && s.init_theme)
  8375. t.theme.init(t, ThemeManager.urls[s.theme] || tinymce.documentBaseURL.replace(/\/$/, ''));
  8376. }
  8377. function initPlugin(p) {
  8378. var c = PluginManager.get(p), u = PluginManager.urls[p] || tinymce.documentBaseURL.replace(/\/$/, ''), po;
  8379. if (c && tinymce.inArray(initializedPlugins,p) === -1) {
  8380. each(PluginManager.dependencies(p), function(dep){
  8381. initPlugin(dep);
  8382. });
  8383. po = new c(t, u);
  8384. t.plugins[p] = po;
  8385. if (po.init) {
  8386. po.init(t, u);
  8387. initializedPlugins.push(p);
  8388. }
  8389. }
  8390. }
  8391. // Create all plugins
  8392. each(explode(s.plugins.replace(/\-/g, '')), initPlugin);
  8393. // Setup popup CSS path(s)
  8394. if (s.popup_css !== false) {
  8395. if (s.popup_css)
  8396. s.popup_css = t.documentBaseURI.toAbsolute(s.popup_css);
  8397. else
  8398. s.popup_css = t.baseURI.toAbsolute("themes/" + s.theme + "/skins/" + s.skin + "/dialog.css");
  8399. }
  8400. if (s.popup_css_add)
  8401. s.popup_css += ',' + t.documentBaseURI.toAbsolute(s.popup_css_add);
  8402. t.controlManager = new tinymce.ControlManager(t);
  8403. if (s.custom_undo_redo) {
  8404. t.onBeforeExecCommand.add(function(ed, cmd, ui, val, a) {
  8405. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo))
  8406. t.undoManager.beforeChange();
  8407. });
  8408. t.onExecCommand.add(function(ed, cmd, ui, val, a) {
  8409. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo))
  8410. t.undoManager.add();
  8411. });
  8412. }
  8413. t.onExecCommand.add(function(ed, c) {
  8414. // Don't refresh the select lists until caret move
  8415. if (!/^(FontName|FontSize)$/.test(c))
  8416. t.nodeChanged();
  8417. });
  8418. // Remove ghost selections on images and tables in Gecko
  8419. if (isGecko) {
  8420. function repaint(a, o) {
  8421. if (!o || !o.initial)
  8422. t.execCommand('mceRepaint');
  8423. };
  8424. t.onUndo.add(repaint);
  8425. t.onRedo.add(repaint);
  8426. t.onSetContent.add(repaint);
  8427. }
  8428. // Enables users to override the control factory
  8429. t.onBeforeRenderUI.dispatch(t, t.controlManager);
  8430. // Measure box
  8431. if (s.render_ui) {
  8432. w = s.width || e.style.width || e.offsetWidth;
  8433. h = s.height || e.style.height || e.offsetHeight;
  8434. t.orgDisplay = e.style.display;
  8435. re = /^[0-9\.]+(|px)$/i;
  8436. if (re.test('' + w))
  8437. w = Math.max(parseInt(w) + (o.deltaWidth || 0), 100);
  8438. if (re.test('' + h))
  8439. h = Math.max(parseInt(h) + (o.deltaHeight || 0), 100);
  8440. // Render UI
  8441. o = t.theme.renderUI({
  8442. targetNode : e,
  8443. width : w,
  8444. height : h,
  8445. deltaWidth : s.delta_width,
  8446. deltaHeight : s.delta_height
  8447. });
  8448. t.editorContainer = o.editorContainer;
  8449. }
  8450. // User specified a document.domain value
  8451. if (document.domain && location.hostname != document.domain)
  8452. tinymce.relaxedDomain = document.domain;
  8453. // Resize editor
  8454. DOM.setStyles(o.sizeContainer || o.editorContainer, {
  8455. width : w,
  8456. height : h
  8457. });
  8458. // Load specified content CSS last
  8459. if (s.content_css) {
  8460. tinymce.each(explode(s.content_css), function(u) {
  8461. t.contentCSS.push(t.documentBaseURI.toAbsolute(u));
  8462. });
  8463. }
  8464. h = (o.iframeHeight || h) + (typeof(h) == 'number' ? (o.deltaHeight || 0) : '');
  8465. if (h < 100)
  8466. h = 100;
  8467. t.iframeHTML = s.doctype + '<html><head xmlns="http://www.w3.org/1999/xhtml">';
  8468. // We only need to override paths if we have to
  8469. // IE has a bug where it remove site absolute urls to relative ones if this is specified
  8470. if (s.document_base_url != tinymce.documentBaseURL)
  8471. t.iframeHTML += '<base href="' + t.documentBaseURI.getURI() + '" />';
  8472. // IE8 doesn't support carets behind images setting ie7_compat would force IE8+ to run in IE7 compat mode.
  8473. if (s.ie7_compat)
  8474. t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=7" />';
  8475. else
  8476. t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=edge" />';
  8477. t.iframeHTML += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
  8478. // Load the CSS by injecting them into the HTML this will reduce "flicker"
  8479. for (i = 0; i < t.contentCSS.length; i++) {
  8480. t.iframeHTML += '<link type="text/css" rel="stylesheet" href="' + t.contentCSS[i] + '" />';
  8481. }
  8482. bi = s.body_id || 'tinymce';
  8483. if (bi.indexOf('=') != -1) {
  8484. bi = t.getParam('body_id', '', 'hash');
  8485. bi = bi[t.id] || bi;
  8486. }
  8487. bc = s.body_class || '';
  8488. if (bc.indexOf('=') != -1) {
  8489. bc = t.getParam('body_class', '', 'hash');
  8490. bc = bc[t.id] || '';
  8491. }
  8492. t.iframeHTML += '</head><body id="' + bi + '" class="mceContentBody ' + bc + '" onload="window.parent.tinyMCE.get(\'' + t.id + '\').onLoad.dispatch();"><br></body></html>';
  8493. // Domain relaxing enabled, then set document domain
  8494. if (tinymce.relaxedDomain && (isIE || (tinymce.isOpera && parseFloat(opera.version()) < 11))) {
  8495. // We need to write the contents here in IE since multiple writes messes up refresh button and back button
  8496. u = 'javascript:(function(){document.open();document.domain="' + document.domain + '";var ed = window.parent.tinyMCE.get("' + t.id + '");document.write(ed.iframeHTML);document.close();ed.setupIframe();})()';
  8497. }
  8498. // Create iframe
  8499. // TODO: ACC add the appropriate description on this.
  8500. n = DOM.add(o.iframeContainer, 'iframe', {
  8501. id : t.id + "_ifr",
  8502. src : u || 'javascript:""', // Workaround for HTTPS warning in IE6/7
  8503. frameBorder : '0',
  8504. allowTransparency : "true",
  8505. title : s.aria_label,
  8506. style : {
  8507. width : '100%',
  8508. height : h,
  8509. display : 'block' // Important for Gecko to render the iframe correctly
  8510. }
  8511. });
  8512. t.contentAreaContainer = o.iframeContainer;
  8513. DOM.get(o.editorContainer).style.display = t.orgDisplay;
  8514. DOM.get(t.id).style.display = 'none';
  8515. DOM.setAttrib(t.id, 'aria-hidden', true);
  8516. if (!tinymce.relaxedDomain || !u)
  8517. t.setupIframe();
  8518. e = n = o = null; // Cleanup
  8519. },
  8520. setupIframe : function() {
  8521. var t = this, s = t.settings, e = DOM.get(t.id), d = t.getDoc(), h, b;
  8522. // Setup iframe body
  8523. if (!isIE || !tinymce.relaxedDomain) {
  8524. d.open();
  8525. d.write(t.iframeHTML);
  8526. d.close();
  8527. if (tinymce.relaxedDomain)
  8528. d.domain = tinymce.relaxedDomain;
  8529. }
  8530. // It will not steal focus while setting contentEditable
  8531. b = t.getBody();
  8532. b.disabled = true;
  8533. if (!s.readonly)
  8534. b.contentEditable = true;
  8535. b.disabled = false;
  8536. t.schema = new tinymce.html.Schema(s);
  8537. t.dom = new tinymce.dom.DOMUtils(t.getDoc(), {
  8538. keep_values : true,
  8539. url_converter : t.convertURL,
  8540. url_converter_scope : t,
  8541. hex_colors : s.force_hex_style_colors,
  8542. class_filter : s.class_filter,
  8543. update_styles : 1,
  8544. fix_ie_paragraphs : 1,
  8545. schema : t.schema
  8546. });
  8547. t.parser = new tinymce.html.DomParser(s, t.schema);
  8548. // Force anchor names closed, unless the setting "allow_html_in_named_anchor" is explicitly included.
  8549. if (!t.settings.allow_html_in_named_anchor) {
  8550. t.parser.addAttributeFilter('name', function(nodes, name) {
  8551. var i = nodes.length, sibling, prevSibling, parent, node;
  8552. while (i--) {
  8553. node = nodes[i];
  8554. if (node.name === 'a' && node.firstChild) {
  8555. parent = node.parent;
  8556. // Move children after current node
  8557. sibling = node.lastChild;
  8558. do {
  8559. prevSibling = sibling.prev;
  8560. parent.insert(sibling, node);
  8561. sibling = prevSibling;
  8562. } while (sibling);
  8563. }
  8564. }
  8565. });
  8566. }
  8567. // Convert src and href into data-mce-src, data-mce-href and data-mce-style
  8568. t.parser.addAttributeFilter('src,href,style', function(nodes, name) {
  8569. var i = nodes.length, node, dom = t.dom, value, internalName;
  8570. while (i--) {
  8571. node = nodes[i];
  8572. value = node.attr(name);
  8573. internalName = 'data-mce-' + name;
  8574. // Add internal attribute if we need to we don't on a refresh of the document
  8575. if (!node.attributes.map[internalName]) {
  8576. if (name === "style")
  8577. node.attr(internalName, dom.serializeStyle(dom.parseStyle(value), node.name));
  8578. else
  8579. node.attr(internalName, t.convertURL(value, name, node.name));
  8580. }
  8581. }
  8582. });
  8583. // Keep scripts from executing
  8584. t.parser.addNodeFilter('script', function(nodes, name) {
  8585. var i = nodes.length, node;
  8586. while (i--) {
  8587. node = nodes[i];
  8588. node.attr('type', 'mce-' + (node.attr('type') || 'text/javascript'));
  8589. }
  8590. });
  8591. t.parser.addNodeFilter('#cdata', function(nodes, name) {
  8592. var i = nodes.length, node;
  8593. while (i--) {
  8594. node = nodes[i];
  8595. node.type = 8;
  8596. node.name = '#comment';
  8597. node.value = '[CDATA[' + node.value + ']]';
  8598. }
  8599. });
  8600. t.parser.addNodeFilter('p,h1,h2,h3,h4,h5,h6,div', function(nodes, name) {
  8601. var i = nodes.length, node, nonEmptyElements = t.schema.getNonEmptyElements();
  8602. while (i--) {
  8603. node = nodes[i];
  8604. if (node.isEmpty(nonEmptyElements))
  8605. node.empty().append(new tinymce.html.Node('br', 1)).shortEnded = true;
  8606. }
  8607. });
  8608. t.serializer = new tinymce.dom.Serializer(s, t.dom, t.schema);
  8609. t.selection = new tinymce.dom.Selection(t.dom, t.getWin(), t.serializer);
  8610. t.formatter = new tinymce.Formatter(this);
  8611. // Register default formats
  8612. t.formatter.register({
  8613. alignleft : [
  8614. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}},
  8615. {selector : 'img,table', collapsed : false, styles : {'float' : 'left'}}
  8616. ],
  8617. aligncenter : [
  8618. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}},
  8619. {selector : 'img', collapsed : false, styles : {display : 'block', marginLeft : 'auto', marginRight : 'auto'}},
  8620. {selector : 'table', collapsed : false, styles : {marginLeft : 'auto', marginRight : 'auto'}}
  8621. ],
  8622. alignright : [
  8623. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}},
  8624. {selector : 'img,table', collapsed : false, styles : {'float' : 'right'}}
  8625. ],
  8626. alignfull : [
  8627. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'justify'}}
  8628. ],
  8629. bold : [
  8630. {inline : 'strong', remove : 'all'},
  8631. {inline : 'span', styles : {fontWeight : 'bold'}},
  8632. {inline : 'b', remove : 'all'}
  8633. ],
  8634. italic : [
  8635. {inline : 'em', remove : 'all'},
  8636. {inline : 'span', styles : {fontStyle : 'italic'}},
  8637. {inline : 'i', remove : 'all'}
  8638. ],
  8639. underline : [
  8640. {inline : 'span', styles : {textDecoration : 'underline'}, exact : true},
  8641. {inline : 'u', remove : 'all'}
  8642. ],
  8643. strikethrough : [
  8644. {inline : 'span', styles : {textDecoration : 'line-through'}, exact : true},
  8645. {inline : 'strike', remove : 'all'}
  8646. ],
  8647. forecolor : {inline : 'span', styles : {color : '%value'}, wrap_links : false},
  8648. hilitecolor : {inline : 'span', styles : {backgroundColor : '%value'}, wrap_links : false},
  8649. fontname : {inline : 'span', styles : {fontFamily : '%value'}},
  8650. fontsize : {inline : 'span', styles : {fontSize : '%value'}},
  8651. fontsize_class : {inline : 'span', attributes : {'class' : '%value'}},
  8652. blockquote : {block : 'blockquote', wrapper : 1, remove : 'all'},
  8653. subscript : {inline : 'sub'},
  8654. superscript : {inline : 'sup'},
  8655. link : {inline : 'a', selector : 'a', remove : 'all', split : true, deep : true,
  8656. onmatch : function(node) {
  8657. return true;
  8658. },
  8659. onformat : function(elm, fmt, vars) {
  8660. each(vars, function(value, key) {
  8661. t.dom.setAttrib(elm, key, value);
  8662. });
  8663. }
  8664. },
  8665. removeformat : [
  8666. {selector : 'b,strong,em,i,font,u,strike', remove : 'all', split : true, expand : false, block_expand : true, deep : true},
  8667. {selector : 'span', attributes : ['style', 'class'], remove : 'empty', split : true, expand : false, deep : true},
  8668. {selector : '*', attributes : ['style', 'class'], split : false, expand : false, deep : true}
  8669. ]
  8670. });
  8671. // Register default block formats
  8672. each('p h1 h2 h3 h4 h5 h6 div address pre div code dt dd samp'.split(/\s/), function(name) {
  8673. t.formatter.register(name, {block : name, remove : 'all'});
  8674. });
  8675. // Register user defined formats
  8676. t.formatter.register(t.settings.formats);
  8677. t.undoManager = new tinymce.UndoManager(t);
  8678. // Pass through
  8679. t.undoManager.onAdd.add(function(um, l) {
  8680. if (um.hasUndo())
  8681. return t.onChange.dispatch(t, l, um);
  8682. });
  8683. t.undoManager.onUndo.add(function(um, l) {
  8684. return t.onUndo.dispatch(t, l, um);
  8685. });
  8686. t.undoManager.onRedo.add(function(um, l) {
  8687. return t.onRedo.dispatch(t, l, um);
  8688. });
  8689. t.forceBlocks = new tinymce.ForceBlocks(t, {
  8690. forced_root_block : s.forced_root_block
  8691. });
  8692. t.editorCommands = new tinymce.EditorCommands(t);
  8693. // Pass through
  8694. t.serializer.onPreProcess.add(function(se, o) {
  8695. return t.onPreProcess.dispatch(t, o, se);
  8696. });
  8697. t.serializer.onPostProcess.add(function(se, o) {
  8698. return t.onPostProcess.dispatch(t, o, se);
  8699. });
  8700. t.onPreInit.dispatch(t);
  8701. if (!s.gecko_spellcheck)
  8702. t.getBody().spellcheck = 0;
  8703. if (!s.readonly)
  8704. t._addEvents();
  8705. t.controlManager.onPostRender.dispatch(t, t.controlManager);
  8706. t.onPostRender.dispatch(t);
  8707. t.quirks = new tinymce.util.Quirks(this);
  8708. if (s.directionality)
  8709. t.getBody().dir = s.directionality;
  8710. if (s.nowrap)
  8711. t.getBody().style.whiteSpace = "nowrap";
  8712. if (s.handle_node_change_callback) {
  8713. t.onNodeChange.add(function(ed, cm, n) {
  8714. t.execCallback('handle_node_change_callback', t.id, n, -1, -1, true, t.selection.isCollapsed());
  8715. });
  8716. }
  8717. if (s.save_callback) {
  8718. t.onSaveContent.add(function(ed, o) {
  8719. var h = t.execCallback('save_callback', t.id, o.content, t.getBody());
  8720. if (h)
  8721. o.content = h;
  8722. });
  8723. }
  8724. if (s.onchange_callback) {
  8725. t.onChange.add(function(ed, l) {
  8726. t.execCallback('onchange_callback', t, l);
  8727. });
  8728. }
  8729. if (s.protect) {
  8730. t.onBeforeSetContent.add(function(ed, o) {
  8731. if (s.protect) {
  8732. each(s.protect, function(pattern) {
  8733. o.content = o.content.replace(pattern, function(str) {
  8734. return '<!--mce:protected ' + escape(str) + '-->';
  8735. });
  8736. });
  8737. }
  8738. });
  8739. }
  8740. if (s.convert_newlines_to_brs) {
  8741. t.onBeforeSetContent.add(function(ed, o) {
  8742. if (o.initial)
  8743. o.content = o.content.replace(/\r?\n/g, '<br />');
  8744. });
  8745. }
  8746. if (s.preformatted) {
  8747. t.onPostProcess.add(function(ed, o) {
  8748. o.content = o.content.replace(/^\s*<pre.*?>/, '');
  8749. o.content = o.content.replace(/<\/pre>\s*$/, '');
  8750. if (o.set)
  8751. o.content = '<pre class="mceItemHidden">' + o.content + '</pre>';
  8752. });
  8753. }
  8754. if (s.verify_css_classes) {
  8755. t.serializer.attribValueFilter = function(n, v) {
  8756. var s, cl;
  8757. if (n == 'class') {
  8758. // Build regexp for classes
  8759. if (!t.classesRE) {
  8760. cl = t.dom.getClasses();
  8761. if (cl.length > 0) {
  8762. s = '';
  8763. each (cl, function(o) {
  8764. s += (s ? '|' : '') + o['class'];
  8765. });
  8766. t.classesRE = new RegExp('(' + s + ')', 'gi');
  8767. }
  8768. }
  8769. return !t.classesRE || /(\bmceItem\w+\b|\bmceTemp\w+\b)/g.test(v) || t.classesRE.test(v) ? v : '';
  8770. }
  8771. return v;
  8772. };
  8773. }
  8774. if (s.cleanup_callback) {
  8775. t.onBeforeSetContent.add(function(ed, o) {
  8776. o.content = t.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  8777. });
  8778. t.onPreProcess.add(function(ed, o) {
  8779. if (o.set)
  8780. t.execCallback('cleanup_callback', 'insert_to_editor_dom', o.node, o);
  8781. if (o.get)
  8782. t.execCallback('cleanup_callback', 'get_from_editor_dom', o.node, o);
  8783. });
  8784. t.onPostProcess.add(function(ed, o) {
  8785. if (o.set)
  8786. o.content = t.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  8787. if (o.get)
  8788. o.content = t.execCallback('cleanup_callback', 'get_from_editor', o.content, o);
  8789. });
  8790. }
  8791. if (s.save_callback) {
  8792. t.onGetContent.add(function(ed, o) {
  8793. if (o.save)
  8794. o.content = t.execCallback('save_callback', t.id, o.content, t.getBody());
  8795. });
  8796. }
  8797. if (s.handle_event_callback) {
  8798. t.onEvent.add(function(ed, e, o) {
  8799. if (t.execCallback('handle_event_callback', e, ed, o) === false)
  8800. Event.cancel(e);
  8801. });
  8802. }
  8803. // Add visual aids when new contents is added
  8804. t.onSetContent.add(function() {
  8805. t.addVisual(t.getBody());
  8806. });
  8807. // Remove empty contents
  8808. if (s.padd_empty_editor) {
  8809. t.onPostProcess.add(function(ed, o) {
  8810. o.content = o.content.replace(/^(<p[^>]*>(&nbsp;|&#160;|\s|\u00a0|)<\/p>[\r\n]*|<br \/>[\r\n]*)$/, '');
  8811. });
  8812. }
  8813. if (isGecko) {
  8814. // Fix gecko link bug, when a link is placed at the end of block elements there is
  8815. // no way to move the caret behind the link. This fix adds a bogus br element after the link
  8816. function fixLinks(ed, o) {
  8817. each(ed.dom.select('a'), function(n) {
  8818. var pn = n.parentNode;
  8819. if (ed.dom.isBlock(pn) && pn.lastChild === n)
  8820. ed.dom.add(pn, 'br', {'data-mce-bogus' : 1});
  8821. });
  8822. };
  8823. t.onExecCommand.add(function(ed, cmd) {
  8824. if (cmd === 'CreateLink')
  8825. fixLinks(ed);
  8826. });
  8827. t.onSetContent.add(t.selection.onSetContent.add(fixLinks));
  8828. }
  8829. t.load({initial : true, format : 'html'});
  8830. t.startContent = t.getContent({format : 'raw'});
  8831. t.undoManager.add();
  8832. t.initialized = true;
  8833. t.onInit.dispatch(t);
  8834. t.execCallback('setupcontent_callback', t.id, t.getBody(), t.getDoc());
  8835. t.execCallback('init_instance_callback', t);
  8836. t.focus(true);
  8837. t.nodeChanged({initial : 1});
  8838. // Load specified content CSS last
  8839. each(t.contentCSS, function(u) {
  8840. t.dom.loadCSS(u);
  8841. });
  8842. // Handle auto focus
  8843. if (s.auto_focus) {
  8844. setTimeout(function () {
  8845. var ed = tinymce.get(s.auto_focus);
  8846. ed.selection.select(ed.getBody(), 1);
  8847. ed.selection.collapse(1);
  8848. ed.getBody().focus();
  8849. ed.getWin().focus();
  8850. }, 100);
  8851. }
  8852. e = null;
  8853. },
  8854. focus : function(sf) {
  8855. var oed, t = this, selection = t.selection, ce = t.settings.content_editable, ieRng, controlElm, doc = t.getDoc();
  8856. if (!sf) {
  8857. // Get selected control element
  8858. ieRng = selection.getRng();
  8859. if (ieRng.item) {
  8860. controlElm = ieRng.item(0);
  8861. }
  8862. t._refreshContentEditable();
  8863. // Is not content editable
  8864. if (!ce)
  8865. t.getWin().focus();
  8866. // Focus the body as well since it's contentEditable
  8867. if (tinymce.isGecko) {
  8868. t.getBody().focus();
  8869. }
  8870. // Restore selected control element
  8871. // This is needed when for example an image is selected within a
  8872. // layer a call to focus will then remove the control selection
  8873. if (controlElm && controlElm.ownerDocument == doc) {
  8874. ieRng = doc.body.createControlRange();
  8875. ieRng.addElement(controlElm);
  8876. ieRng.select();
  8877. }
  8878. }
  8879. if (tinymce.activeEditor != t) {
  8880. if ((oed = tinymce.activeEditor) != null)
  8881. oed.onDeactivate.dispatch(oed, t);
  8882. t.onActivate.dispatch(t, oed);
  8883. }
  8884. tinymce._setActive(t);
  8885. },
  8886. execCallback : function(n) {
  8887. var t = this, f = t.settings[n], s;
  8888. if (!f)
  8889. return;
  8890. // Look through lookup
  8891. if (t.callbackLookup && (s = t.callbackLookup[n])) {
  8892. f = s.func;
  8893. s = s.scope;
  8894. }
  8895. if (is(f, 'string')) {
  8896. s = f.replace(/\.\w+$/, '');
  8897. s = s ? tinymce.resolve(s) : 0;
  8898. f = tinymce.resolve(f);
  8899. t.callbackLookup = t.callbackLookup || {};
  8900. t.callbackLookup[n] = {func : f, scope : s};
  8901. }
  8902. return f.apply(s || t, Array.prototype.slice.call(arguments, 1));
  8903. },
  8904. translate : function(s) {
  8905. var c = this.settings.language || 'en', i18n = tinymce.i18n;
  8906. if (!s)
  8907. return '';
  8908. return i18n[c + '.' + s] || s.replace(/{\#([^}]+)\}/g, function(a, b) {
  8909. return i18n[c + '.' + b] || '{#' + b + '}';
  8910. });
  8911. },
  8912. getLang : function(n, dv) {
  8913. return tinymce.i18n[(this.settings.language || 'en') + '.' + n] || (is(dv) ? dv : '{#' + n + '}');
  8914. },
  8915. getParam : function(n, dv, ty) {
  8916. var tr = tinymce.trim, v = is(this.settings[n]) ? this.settings[n] : dv, o;
  8917. if (ty === 'hash') {
  8918. o = {};
  8919. if (is(v, 'string')) {
  8920. each(v.indexOf('=') > 0 ? v.split(/[;,](?![^=;,]*(?:[;,]|$))/) : v.split(','), function(v) {
  8921. v = v.split('=');
  8922. if (v.length > 1)
  8923. o[tr(v[0])] = tr(v[1]);
  8924. else
  8925. o[tr(v[0])] = tr(v);
  8926. });
  8927. } else
  8928. o = v;
  8929. return o;
  8930. }
  8931. return v;
  8932. },
  8933. nodeChanged : function(o) {
  8934. var t = this, s = t.selection, n = s.getStart() || t.getBody();
  8935. // Fix for bug #1896577 it seems that this can not be fired while the editor is loading
  8936. if (t.initialized) {
  8937. o = o || {};
  8938. n = isIE && n.ownerDocument != t.getDoc() ? t.getBody() : n; // Fix for IE initial state
  8939. // Get parents and add them to object
  8940. o.parents = [];
  8941. t.dom.getParent(n, function(node) {
  8942. if (node.nodeName == 'BODY')
  8943. return true;
  8944. o.parents.push(node);
  8945. });
  8946. t.onNodeChange.dispatch(
  8947. t,
  8948. o ? o.controlManager || t.controlManager : t.controlManager,
  8949. n,
  8950. s.isCollapsed(),
  8951. o
  8952. );
  8953. }
  8954. },
  8955. addButton : function(n, s) {
  8956. var t = this;
  8957. t.buttons = t.buttons || {};
  8958. t.buttons[n] = s;
  8959. },
  8960. addCommand : function(name, callback, scope) {
  8961. this.execCommands[name] = {func : callback, scope : scope || this};
  8962. },
  8963. addQueryStateHandler : function(name, callback, scope) {
  8964. this.queryStateCommands[name] = {func : callback, scope : scope || this};
  8965. },
  8966. addQueryValueHandler : function(name, callback, scope) {
  8967. this.queryValueCommands[name] = {func : callback, scope : scope || this};
  8968. },
  8969. addShortcut : function(pa, desc, cmd_func, sc) {
  8970. var t = this, c;
  8971. if (!t.settings.custom_shortcuts)
  8972. return false;
  8973. t.shortcuts = t.shortcuts || {};
  8974. if (is(cmd_func, 'string')) {
  8975. c = cmd_func;
  8976. cmd_func = function() {
  8977. t.execCommand(c, false, null);
  8978. };
  8979. }
  8980. if (is(cmd_func, 'object')) {
  8981. c = cmd_func;
  8982. cmd_func = function() {
  8983. t.execCommand(c[0], c[1], c[2]);
  8984. };
  8985. }
  8986. each(explode(pa), function(pa) {
  8987. var o = {
  8988. func : cmd_func,
  8989. scope : sc || this,
  8990. desc : desc,
  8991. alt : false,
  8992. ctrl : false,
  8993. shift : false
  8994. };
  8995. each(explode(pa, '+'), function(v) {
  8996. switch (v) {
  8997. case 'alt':
  8998. case 'ctrl':
  8999. case 'shift':
  9000. o[v] = true;
  9001. break;
  9002. default:
  9003. o.charCode = v.charCodeAt(0);
  9004. o.keyCode = v.toUpperCase().charCodeAt(0);
  9005. }
  9006. });
  9007. t.shortcuts[(o.ctrl ? 'ctrl' : '') + ',' + (o.alt ? 'alt' : '') + ',' + (o.shift ? 'shift' : '') + ',' + o.keyCode] = o;
  9008. });
  9009. return true;
  9010. },
  9011. execCommand : function(cmd, ui, val, a) {
  9012. var t = this, s = 0, o, st;
  9013. if (!/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint|SelectAll)$/.test(cmd) && (!a || !a.skip_focus))
  9014. t.focus();
  9015. o = {};
  9016. t.onBeforeExecCommand.dispatch(t, cmd, ui, val, o);
  9017. if (o.terminate)
  9018. return false;
  9019. // Command callback
  9020. if (t.execCallback('execcommand_callback', t.id, t.selection.getNode(), cmd, ui, val)) {
  9021. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9022. return true;
  9023. }
  9024. // Registred commands
  9025. if (o = t.execCommands[cmd]) {
  9026. st = o.func.call(o.scope, ui, val);
  9027. // Fall through on true
  9028. if (st !== true) {
  9029. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9030. return st;
  9031. }
  9032. }
  9033. // Plugin commands
  9034. each(t.plugins, function(p) {
  9035. if (p.execCommand && p.execCommand(cmd, ui, val)) {
  9036. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9037. s = 1;
  9038. return false;
  9039. }
  9040. });
  9041. if (s)
  9042. return true;
  9043. // Theme commands
  9044. if (t.theme && t.theme.execCommand && t.theme.execCommand(cmd, ui, val)) {
  9045. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9046. return true;
  9047. }
  9048. // Editor commands
  9049. if (t.editorCommands.execCommand(cmd, ui, val)) {
  9050. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9051. return true;
  9052. }
  9053. // Browser commands
  9054. t.getDoc().execCommand(cmd, ui, val);
  9055. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9056. },
  9057. queryCommandState : function(cmd) {
  9058. var t = this, o, s;
  9059. // Is hidden then return undefined
  9060. if (t._isHidden())
  9061. return;
  9062. // Registred commands
  9063. if (o = t.queryStateCommands[cmd]) {
  9064. s = o.func.call(o.scope);
  9065. // Fall though on true
  9066. if (s !== true)
  9067. return s;
  9068. }
  9069. // Registred commands
  9070. o = t.editorCommands.queryCommandState(cmd);
  9071. if (o !== -1)
  9072. return o;
  9073. // Browser commands
  9074. try {
  9075. return this.getDoc().queryCommandState(cmd);
  9076. } catch (ex) {
  9077. // Fails sometimes see bug: 1896577
  9078. }
  9079. },
  9080. queryCommandValue : function(c) {
  9081. var t = this, o, s;
  9082. // Is hidden then return undefined
  9083. if (t._isHidden())
  9084. return;
  9085. // Registred commands
  9086. if (o = t.queryValueCommands[c]) {
  9087. s = o.func.call(o.scope);
  9088. // Fall though on true
  9089. if (s !== true)
  9090. return s;
  9091. }
  9092. // Registred commands
  9093. o = t.editorCommands.queryCommandValue(c);
  9094. if (is(o))
  9095. return o;
  9096. // Browser commands
  9097. try {
  9098. return this.getDoc().queryCommandValue(c);
  9099. } catch (ex) {
  9100. // Fails sometimes see bug: 1896577
  9101. }
  9102. },
  9103. show : function() {
  9104. var t = this;
  9105. DOM.show(t.getContainer());
  9106. DOM.hide(t.id);
  9107. t.load();
  9108. },
  9109. hide : function() {
  9110. var t = this, d = t.getDoc();
  9111. // Fixed bug where IE has a blinking cursor left from the editor
  9112. if (isIE && d)
  9113. d.execCommand('SelectAll');
  9114. // We must save before we hide so Safari doesn't crash
  9115. t.save();
  9116. DOM.hide(t.getContainer());
  9117. DOM.setStyle(t.id, 'display', t.orgDisplay);
  9118. },
  9119. isHidden : function() {
  9120. return !DOM.isHidden(this.id);
  9121. },
  9122. setProgressState : function(b, ti, o) {
  9123. this.onSetProgressState.dispatch(this, b, ti, o);
  9124. return b;
  9125. },
  9126. load : function(o) {
  9127. var t = this, e = t.getElement(), h;
  9128. if (e) {
  9129. o = o || {};
  9130. o.load = true;
  9131. // Double encode existing entities in the value
  9132. h = t.setContent(is(e.value) ? e.value : e.innerHTML, o);
  9133. o.element = e;
  9134. if (!o.no_events)
  9135. t.onLoadContent.dispatch(t, o);
  9136. o.element = e = null;
  9137. return h;
  9138. }
  9139. },
  9140. save : function(o) {
  9141. var t = this, e = t.getElement(), h, f;
  9142. if (!e || !t.initialized)
  9143. return;
  9144. o = o || {};
  9145. o.save = true;
  9146. // Add undo level will trigger onchange event
  9147. if (!o.no_events) {
  9148. t.undoManager.typing = false;
  9149. t.undoManager.add();
  9150. }
  9151. o.element = e;
  9152. h = o.content = t.getContent(o);
  9153. if (!o.no_events)
  9154. t.onSaveContent.dispatch(t, o);
  9155. h = o.content;
  9156. if (!/TEXTAREA|INPUT/i.test(e.nodeName)) {
  9157. e.innerHTML = h;
  9158. // Update hidden form element
  9159. if (f = DOM.getParent(t.id, 'form')) {
  9160. each(f.elements, function(e) {
  9161. if (e.name == t.id) {
  9162. e.value = h;
  9163. return false;
  9164. }
  9165. });
  9166. }
  9167. } else
  9168. e.value = h;
  9169. o.element = e = null;
  9170. return h;
  9171. },
  9172. setContent : function(content, args) {
  9173. var self = this, rootNode, body = self.getBody(), forcedRootBlockName;
  9174. // Setup args object
  9175. args = args || {};
  9176. args.format = args.format || 'html';
  9177. args.set = true;
  9178. args.content = content;
  9179. // Do preprocessing
  9180. if (!args.no_events)
  9181. self.onBeforeSetContent.dispatch(self, args);
  9182. content = args.content;
  9183. // Padd empty content in Gecko and Safari. Commands will otherwise fail on the content
  9184. // It will also be impossible to place the caret in the editor unless there is a BR element present
  9185. if (!tinymce.isIE && (content.length === 0 || /^\s+$/.test(content))) {
  9186. forcedRootBlockName = self.settings.forced_root_block;
  9187. if (forcedRootBlockName)
  9188. content = '<' + forcedRootBlockName + '><br data-mce-bogus="1"></' + forcedRootBlockName + '>';
  9189. else
  9190. content = '<br data-mce-bogus="1">';
  9191. body.innerHTML = content;
  9192. self.selection.select(body, true);
  9193. self.selection.collapse(true);
  9194. return;
  9195. }
  9196. // Parse and serialize the html
  9197. if (args.format !== 'raw') {
  9198. content = new tinymce.html.Serializer({}, self.schema).serialize(
  9199. self.parser.parse(content)
  9200. );
  9201. }
  9202. // Set the new cleaned contents to the editor
  9203. args.content = tinymce.trim(content);
  9204. self.dom.setHTML(body, args.content);
  9205. // Do post processing
  9206. if (!args.no_events)
  9207. self.onSetContent.dispatch(self, args);
  9208. self.selection.normalize();
  9209. return args.content;
  9210. },
  9211. getContent : function(args) {
  9212. var self = this, content;
  9213. // Setup args object
  9214. args = args || {};
  9215. args.format = args.format || 'html';
  9216. args.get = true;
  9217. // Do preprocessing
  9218. if (!args.no_events)
  9219. self.onBeforeGetContent.dispatch(self, args);
  9220. // Get raw contents or by default the cleaned contents
  9221. if (args.format == 'raw')
  9222. content = self.getBody().innerHTML;
  9223. else
  9224. content = self.serializer.serialize(self.getBody(), args);
  9225. args.content = tinymce.trim(content);
  9226. // Do post processing
  9227. if (!args.no_events)
  9228. self.onGetContent.dispatch(self, args);
  9229. return args.content;
  9230. },
  9231. isDirty : function() {
  9232. var self = this;
  9233. return tinymce.trim(self.startContent) != tinymce.trim(self.getContent({format : 'raw', no_events : 1})) && !self.isNotDirty;
  9234. },
  9235. getContainer : function() {
  9236. var t = this;
  9237. if (!t.container)
  9238. t.container = DOM.get(t.editorContainer || t.id + '_parent');
  9239. return t.container;
  9240. },
  9241. getContentAreaContainer : function() {
  9242. return this.contentAreaContainer;
  9243. },
  9244. getElement : function() {
  9245. return DOM.get(this.settings.content_element || this.id);
  9246. },
  9247. getWin : function() {
  9248. var t = this, e;
  9249. if (!t.contentWindow) {
  9250. e = DOM.get(t.id + "_ifr");
  9251. if (e)
  9252. t.contentWindow = e.contentWindow;
  9253. }
  9254. return t.contentWindow;
  9255. },
  9256. getDoc : function() {
  9257. var t = this, w;
  9258. if (!t.contentDocument) {
  9259. w = t.getWin();
  9260. if (w)
  9261. t.contentDocument = w.document;
  9262. }
  9263. return t.contentDocument;
  9264. },
  9265. getBody : function() {
  9266. return this.bodyElement || this.getDoc().body;
  9267. },
  9268. convertURL : function(u, n, e) {
  9269. var t = this, s = t.settings;
  9270. // Use callback instead
  9271. if (s.urlconverter_callback)
  9272. return t.execCallback('urlconverter_callback', u, e, true, n);
  9273. // Don't convert link href since thats the CSS files that gets loaded into the editor also skip local file URLs
  9274. if (!s.convert_urls || (e && e.nodeName == 'LINK') || u.indexOf('file:') === 0)
  9275. return u;
  9276. // Convert to relative
  9277. if (s.relative_urls)
  9278. return t.documentBaseURI.toRelative(u);
  9279. // Convert to absolute
  9280. u = t.documentBaseURI.toAbsolute(u, s.remove_script_host);
  9281. return u;
  9282. },
  9283. addVisual : function(e) {
  9284. var t = this, s = t.settings;
  9285. e = e || t.getBody();
  9286. if (!is(t.hasVisual))
  9287. t.hasVisual = s.visual;
  9288. each(t.dom.select('table,a', e), function(e) {
  9289. var v;
  9290. switch (e.nodeName) {
  9291. case 'TABLE':
  9292. v = t.dom.getAttrib(e, 'border');
  9293. if (!v || v == '0') {
  9294. if (t.hasVisual)
  9295. t.dom.addClass(e, s.visual_table_class);
  9296. else
  9297. t.dom.removeClass(e, s.visual_table_class);
  9298. }
  9299. return;
  9300. case 'A':
  9301. v = t.dom.getAttrib(e, 'name');
  9302. if (v) {
  9303. if (t.hasVisual)
  9304. t.dom.addClass(e, 'mceItemAnchor');
  9305. else
  9306. t.dom.removeClass(e, 'mceItemAnchor');
  9307. }
  9308. return;
  9309. }
  9310. });
  9311. t.onVisualAid.dispatch(t, e, t.hasVisual);
  9312. },
  9313. remove : function() {
  9314. var t = this, e = t.getContainer();
  9315. t.removed = 1; // Cancels post remove event execution
  9316. t.hide();
  9317. t.execCallback('remove_instance_callback', t);
  9318. t.onRemove.dispatch(t);
  9319. // Clear all execCommand listeners this is required to avoid errors if the editor was removed inside another command
  9320. t.onExecCommand.listeners = [];
  9321. tinymce.remove(t);
  9322. DOM.remove(e);
  9323. },
  9324. destroy : function(s) {
  9325. var t = this;
  9326. // One time is enough
  9327. if (t.destroyed)
  9328. return;
  9329. if (!s) {
  9330. tinymce.removeUnload(t.destroy);
  9331. tinyMCE.onBeforeUnload.remove(t._beforeUnload);
  9332. // Manual destroy
  9333. if (t.theme && t.theme.destroy)
  9334. t.theme.destroy();
  9335. // Destroy controls, selection and dom
  9336. t.controlManager.destroy();
  9337. t.selection.destroy();
  9338. t.dom.destroy();
  9339. // Remove all events
  9340. // Don't clear the window or document if content editable
  9341. // is enabled since other instances might still be present
  9342. if (!t.settings.content_editable) {
  9343. Event.clear(t.getWin());
  9344. Event.clear(t.getDoc());
  9345. }
  9346. Event.clear(t.getBody());
  9347. Event.clear(t.formElement);
  9348. }
  9349. if (t.formElement) {
  9350. t.formElement.submit = t.formElement._mceOldSubmit;
  9351. t.formElement._mceOldSubmit = null;
  9352. }
  9353. t.contentAreaContainer = t.formElement = t.container = t.settings.content_element = t.bodyElement = t.contentDocument = t.contentWindow = null;
  9354. if (t.selection)
  9355. t.selection = t.selection.win = t.selection.dom = t.selection.dom.doc = null;
  9356. t.destroyed = 1;
  9357. },
  9358. // Internal functions
  9359. _addEvents : function() {
  9360. // 'focus', 'blur', 'dblclick', 'beforedeactivate', submit, reset
  9361. var t = this, i, s = t.settings, dom = t.dom, lo = {
  9362. mouseup : 'onMouseUp',
  9363. mousedown : 'onMouseDown',
  9364. click : 'onClick',
  9365. keyup : 'onKeyUp',
  9366. keydown : 'onKeyDown',
  9367. keypress : 'onKeyPress',
  9368. submit : 'onSubmit',
  9369. reset : 'onReset',
  9370. contextmenu : 'onContextMenu',
  9371. dblclick : 'onDblClick',
  9372. paste : 'onPaste' // Doesn't work in all browsers yet
  9373. };
  9374. function eventHandler(e, o) {
  9375. var ty = e.type;
  9376. // Don't fire events when it's removed
  9377. if (t.removed)
  9378. return;
  9379. // Generic event handler
  9380. if (t.onEvent.dispatch(t, e, o) !== false) {
  9381. // Specific event handler
  9382. t[lo[e.fakeType || e.type]].dispatch(t, e, o);
  9383. }
  9384. };
  9385. // Add DOM events
  9386. each(lo, function(v, k) {
  9387. switch (k) {
  9388. case 'contextmenu':
  9389. dom.bind(t.getDoc(), k, eventHandler);
  9390. break;
  9391. case 'paste':
  9392. dom.bind(t.getBody(), k, function(e) {
  9393. eventHandler(e);
  9394. });
  9395. break;
  9396. case 'submit':
  9397. case 'reset':
  9398. dom.bind(t.getElement().form || DOM.getParent(t.id, 'form'), k, eventHandler);
  9399. break;
  9400. default:
  9401. dom.bind(s.content_editable ? t.getBody() : t.getDoc(), k, eventHandler);
  9402. }
  9403. });
  9404. dom.bind(s.content_editable ? t.getBody() : (isGecko ? t.getDoc() : t.getWin()), 'focus', function(e) {
  9405. t.focus(true);
  9406. });
  9407. // Fixes bug where a specified document_base_uri could result in broken images
  9408. // This will also fix drag drop of images in Gecko
  9409. if (tinymce.isGecko) {
  9410. dom.bind(t.getDoc(), 'DOMNodeInserted', function(e) {
  9411. var v;
  9412. e = e.target;
  9413. if (e.nodeType === 1 && e.nodeName === 'IMG' && (v = e.getAttribute('data-mce-src')))
  9414. e.src = t.documentBaseURI.toAbsolute(v);
  9415. });
  9416. }
  9417. // Set various midas options in Gecko
  9418. if (isGecko) {
  9419. function setOpts() {
  9420. var t = this, d = t.getDoc(), s = t.settings;
  9421. if (isGecko && !s.readonly) {
  9422. t._refreshContentEditable();
  9423. try {
  9424. // Try new Gecko method
  9425. d.execCommand("styleWithCSS", 0, false);
  9426. } catch (ex) {
  9427. // Use old method
  9428. if (!t._isHidden())
  9429. try {d.execCommand("useCSS", 0, true);} catch (ex) {}
  9430. }
  9431. if (!s.table_inline_editing)
  9432. try {d.execCommand('enableInlineTableEditing', false, false);} catch (ex) {}
  9433. if (!s.object_resizing)
  9434. try {d.execCommand('enableObjectResizing', false, false);} catch (ex) {}
  9435. }
  9436. };
  9437. t.onBeforeExecCommand.add(setOpts);
  9438. t.onMouseDown.add(setOpts);
  9439. }
  9440. // Add node change handlers
  9441. t.onMouseUp.add(t.nodeChanged);
  9442. //t.onClick.add(t.nodeChanged);
  9443. t.onKeyUp.add(function(ed, e) {
  9444. var c = e.keyCode;
  9445. if ((c >= 33 && c <= 36) || (c >= 37 && c <= 40) || c == 13 || c == 45 || c == 46 || c == 8 || (tinymce.isMac && (c == 91 || c == 93)) || e.ctrlKey)
  9446. t.nodeChanged();
  9447. });
  9448. // Add block quote deletion handler
  9449. t.onKeyDown.add(function(ed, e) {
  9450. if (e.keyCode != VK.BACKSPACE)
  9451. return;
  9452. var rng = ed.selection.getRng();
  9453. if (!rng.collapsed)
  9454. return;
  9455. var n = rng.startContainer;
  9456. var offset = rng.startOffset;
  9457. while (n && n.nodeType && n.nodeType != 1 && n.parentNode)
  9458. n = n.parentNode;
  9459. // Is the cursor at the beginning of a blockquote?
  9460. if (n && n.parentNode && n.parentNode.tagName === 'BLOCKQUOTE' && n.parentNode.firstChild == n && offset == 0) {
  9461. // Remove the blockquote
  9462. ed.formatter.toggle('blockquote', null, n.parentNode);
  9463. // Move the caret to the beginning of n
  9464. rng.setStart(n, 0);
  9465. rng.setEnd(n, 0);
  9466. ed.selection.setRng(rng);
  9467. ed.selection.collapse(false);
  9468. }
  9469. });
  9470. // Add reset handler
  9471. t.onReset.add(function() {
  9472. t.setContent(t.startContent, {format : 'raw'});
  9473. });
  9474. // Add shortcuts
  9475. if (s.custom_shortcuts) {
  9476. if (s.custom_undo_redo_keyboard_shortcuts) {
  9477. t.addShortcut('ctrl+z', t.getLang('undo_desc'), 'Undo');
  9478. t.addShortcut('ctrl+y', t.getLang('redo_desc'), 'Redo');
  9479. }
  9480. // Add default shortcuts for gecko
  9481. t.addShortcut('ctrl+b', t.getLang('bold_desc'), 'Bold');
  9482. t.addShortcut('ctrl+i', t.getLang('italic_desc'), 'Italic');
  9483. t.addShortcut('ctrl+u', t.getLang('underline_desc'), 'Underline');
  9484. // BlockFormat shortcuts keys
  9485. for (i=1; i<=6; i++)
  9486. t.addShortcut('ctrl+' + i, '', ['FormatBlock', false, 'h' + i]);
  9487. t.addShortcut('ctrl+7', '', ['FormatBlock', false, 'p']);
  9488. t.addShortcut('ctrl+8', '', ['FormatBlock', false, 'div']);
  9489. t.addShortcut('ctrl+9', '', ['FormatBlock', false, 'address']);
  9490. function find(e) {
  9491. var v = null;
  9492. if (!e.altKey && !e.ctrlKey && !e.metaKey)
  9493. return v;
  9494. each(t.shortcuts, function(o) {
  9495. if (tinymce.isMac && o.ctrl != e.metaKey)
  9496. return;
  9497. else if (!tinymce.isMac && o.ctrl != e.ctrlKey)
  9498. return;
  9499. if (o.alt != e.altKey)
  9500. return;
  9501. if (o.shift != e.shiftKey)
  9502. return;
  9503. if (e.keyCode == o.keyCode || (e.charCode && e.charCode == o.charCode)) {
  9504. v = o;
  9505. return false;
  9506. }
  9507. });
  9508. return v;
  9509. };
  9510. t.onKeyUp.add(function(ed, e) {
  9511. var o = find(e);
  9512. if (o)
  9513. return Event.cancel(e);
  9514. });
  9515. t.onKeyPress.add(function(ed, e) {
  9516. var o = find(e);
  9517. if (o)
  9518. return Event.cancel(e);
  9519. });
  9520. t.onKeyDown.add(function(ed, e) {
  9521. var o = find(e);
  9522. if (o) {
  9523. o.func.call(o.scope);
  9524. return Event.cancel(e);
  9525. }
  9526. });
  9527. }
  9528. if (tinymce.isIE) {
  9529. // Fix so resize will only update the width and height attributes not the styles of an image
  9530. // It will also block mceItemNoResize items
  9531. dom.bind(t.getDoc(), 'controlselect', function(e) {
  9532. var re = t.resizeInfo, cb;
  9533. e = e.target;
  9534. // Don't do this action for non image elements
  9535. if (e.nodeName !== 'IMG')
  9536. return;
  9537. if (re)
  9538. dom.unbind(re.node, re.ev, re.cb);
  9539. if (!dom.hasClass(e, 'mceItemNoResize')) {
  9540. ev = 'resizeend';
  9541. cb = dom.bind(e, ev, function(e) {
  9542. var v;
  9543. e = e.target;
  9544. if (v = dom.getStyle(e, 'width')) {
  9545. dom.setAttrib(e, 'width', v.replace(/[^0-9%]+/g, ''));
  9546. dom.setStyle(e, 'width', '');
  9547. }
  9548. if (v = dom.getStyle(e, 'height')) {
  9549. dom.setAttrib(e, 'height', v.replace(/[^0-9%]+/g, ''));
  9550. dom.setStyle(e, 'height', '');
  9551. }
  9552. });
  9553. } else {
  9554. ev = 'resizestart';
  9555. cb = dom.bind(e, 'resizestart', Event.cancel, Event);
  9556. }
  9557. re = t.resizeInfo = {
  9558. node : e,
  9559. ev : ev,
  9560. cb : cb
  9561. };
  9562. });
  9563. }
  9564. if (tinymce.isOpera) {
  9565. t.onClick.add(function(ed, e) {
  9566. Event.prevent(e);
  9567. });
  9568. }
  9569. // Add custom undo/redo handlers
  9570. if (s.custom_undo_redo) {
  9571. function addUndo() {
  9572. t.undoManager.typing = false;
  9573. t.undoManager.add();
  9574. };
  9575. dom.bind(t.getDoc(), 'focusout', function(e) {
  9576. if (!t.removed && t.undoManager.typing)
  9577. addUndo();
  9578. });
  9579. // Add undo level when contents is drag/dropped within the editor
  9580. t.dom.bind(t.dom.getRoot(), 'dragend', function(e) {
  9581. addUndo();
  9582. });
  9583. t.onKeyUp.add(function(ed, e) {
  9584. var keyCode = e.keyCode;
  9585. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 13 || keyCode == 45 || e.ctrlKey)
  9586. addUndo();
  9587. });
  9588. t.onKeyDown.add(function(ed, e) {
  9589. var keyCode = e.keyCode, sel;
  9590. if (keyCode == 8) {
  9591. sel = t.getDoc().selection;
  9592. // Fix IE control + backspace browser bug
  9593. if (sel && sel.createRange && sel.createRange().item) {
  9594. t.undoManager.beforeChange();
  9595. ed.dom.remove(sel.createRange().item(0));
  9596. addUndo();
  9597. return Event.cancel(e);
  9598. }
  9599. }
  9600. // Is caracter positon keys left,right,up,down,home,end,pgdown,pgup,enter
  9601. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 13 || keyCode == 45) {
  9602. // Add position before enter key is pressed, used by IE since it still uses the default browser behavior
  9603. // Todo: Remove this once we normalize enter behavior on IE
  9604. if (tinymce.isIE && keyCode == 13)
  9605. t.undoManager.beforeChange();
  9606. if (t.undoManager.typing)
  9607. addUndo();
  9608. return;
  9609. }
  9610. // If key isn't shift,ctrl,alt,capslock,metakey
  9611. if ((keyCode < 16 || keyCode > 20) && keyCode != 224 && keyCode != 91 && !t.undoManager.typing) {
  9612. t.undoManager.beforeChange();
  9613. t.undoManager.typing = true;
  9614. t.undoManager.add();
  9615. }
  9616. });
  9617. t.onMouseDown.add(function() {
  9618. if (t.undoManager.typing)
  9619. addUndo();
  9620. });
  9621. }
  9622. // Bug fix for FireFox keeping styles from end of selection instead of start.
  9623. if (tinymce.isGecko) {
  9624. function getAttributeApplyFunction() {
  9625. var template = t.dom.getAttribs(t.selection.getStart().cloneNode(false));
  9626. return function() {
  9627. var target = t.selection.getStart();
  9628. if (target !== t.getBody()) {
  9629. t.dom.setAttrib(target, "style", null);
  9630. each(template, function(attr) {
  9631. target.setAttributeNode(attr.cloneNode(true));
  9632. });
  9633. }
  9634. };
  9635. }
  9636. function isSelectionAcrossElements() {
  9637. var s = t.selection;
  9638. return !s.isCollapsed() && s.getStart() != s.getEnd();
  9639. }
  9640. t.onKeyPress.add(function(ed, e) {
  9641. var applyAttributes;
  9642. if ((e.keyCode == 8 || e.keyCode == 46) && isSelectionAcrossElements()) {
  9643. applyAttributes = getAttributeApplyFunction();
  9644. t.getDoc().execCommand('delete', false, null);
  9645. applyAttributes();
  9646. return Event.cancel(e);
  9647. }
  9648. });
  9649. t.dom.bind(t.getDoc(), 'cut', function(e) {
  9650. var applyAttributes;
  9651. if (isSelectionAcrossElements()) {
  9652. applyAttributes = getAttributeApplyFunction();
  9653. t.onKeyUp.addToTop(Event.cancel, Event);
  9654. setTimeout(function() {
  9655. applyAttributes();
  9656. t.onKeyUp.remove(Event.cancel, Event);
  9657. }, 0);
  9658. }
  9659. });
  9660. }
  9661. },
  9662. _refreshContentEditable : function() {
  9663. var self = this, body, parent;
  9664. // Check if the editor was hidden and the re-initalize contentEditable mode by removing and adding the body again
  9665. if (self._isHidden()) {
  9666. body = self.getBody();
  9667. parent = body.parentNode;
  9668. parent.removeChild(body);
  9669. parent.appendChild(body);
  9670. body.focus();
  9671. }
  9672. },
  9673. _isHidden : function() {
  9674. var s;
  9675. if (!isGecko)
  9676. return 0;
  9677. // Weird, wheres that cursor selection?
  9678. s = this.selection.getSel();
  9679. return (!s || !s.rangeCount || s.rangeCount == 0);
  9680. }
  9681. });
  9682. })(tinymce);
  9683. (function(tinymce) {
  9684. // Added for compression purposes
  9685. var each = tinymce.each, undefined, TRUE = true, FALSE = false;
  9686. tinymce.EditorCommands = function(editor) {
  9687. var dom = editor.dom,
  9688. selection = editor.selection,
  9689. commands = {state: {}, exec : {}, value : {}},
  9690. settings = editor.settings,
  9691. formatter = editor.formatter,
  9692. bookmark;
  9693. function execCommand(command, ui, value) {
  9694. var func;
  9695. command = command.toLowerCase();
  9696. if (func = commands.exec[command]) {
  9697. func(command, ui, value);
  9698. return TRUE;
  9699. }
  9700. return FALSE;
  9701. };
  9702. function queryCommandState(command) {
  9703. var func;
  9704. command = command.toLowerCase();
  9705. if (func = commands.state[command])
  9706. return func(command);
  9707. return -1;
  9708. };
  9709. function queryCommandValue(command) {
  9710. var func;
  9711. command = command.toLowerCase();
  9712. if (func = commands.value[command])
  9713. return func(command);
  9714. return FALSE;
  9715. };
  9716. function addCommands(command_list, type) {
  9717. type = type || 'exec';
  9718. each(command_list, function(callback, command) {
  9719. each(command.toLowerCase().split(','), function(command) {
  9720. commands[type][command] = callback;
  9721. });
  9722. });
  9723. };
  9724. // Expose public methods
  9725. tinymce.extend(this, {
  9726. execCommand : execCommand,
  9727. queryCommandState : queryCommandState,
  9728. queryCommandValue : queryCommandValue,
  9729. addCommands : addCommands
  9730. });
  9731. // Private methods
  9732. function execNativeCommand(command, ui, value) {
  9733. if (ui === undefined)
  9734. ui = FALSE;
  9735. if (value === undefined)
  9736. value = null;
  9737. return editor.getDoc().execCommand(command, ui, value);
  9738. };
  9739. function isFormatMatch(name) {
  9740. return formatter.match(name);
  9741. };
  9742. function toggleFormat(name, value) {
  9743. formatter.toggle(name, value ? {value : value} : undefined);
  9744. };
  9745. function storeSelection(type) {
  9746. bookmark = selection.getBookmark(type);
  9747. };
  9748. function restoreSelection() {
  9749. selection.moveToBookmark(bookmark);
  9750. };
  9751. // Add execCommand overrides
  9752. addCommands({
  9753. // Ignore these, added for compatibility
  9754. 'mceResetDesignMode,mceBeginUndoLevel' : function() {},
  9755. // Add undo manager logic
  9756. 'mceEndUndoLevel,mceAddUndoLevel' : function() {
  9757. editor.undoManager.add();
  9758. },
  9759. 'Cut,Copy,Paste' : function(command) {
  9760. var doc = editor.getDoc(), failed;
  9761. // Try executing the native command
  9762. try {
  9763. execNativeCommand(command);
  9764. } catch (ex) {
  9765. // Command failed
  9766. failed = TRUE;
  9767. }
  9768. // Present alert message about clipboard access not being available
  9769. if (failed || !doc.queryCommandSupported(command)) {
  9770. if (tinymce.isGecko) {
  9771. editor.windowManager.confirm(editor.getLang('clipboard_msg'), function(state) {
  9772. if (state)
  9773. open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', '_blank');
  9774. });
  9775. } else
  9776. editor.windowManager.alert(editor.getLang('clipboard_no_support'));
  9777. }
  9778. },
  9779. // Override unlink command
  9780. unlink : function(command) {
  9781. if (selection.isCollapsed())
  9782. selection.select(selection.getNode());
  9783. execNativeCommand(command);
  9784. selection.collapse(FALSE);
  9785. },
  9786. // Override justify commands to use the text formatter engine
  9787. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  9788. var align = command.substring(7);
  9789. // Remove all other alignments first
  9790. each('left,center,right,full'.split(','), function(name) {
  9791. if (align != name)
  9792. formatter.remove('align' + name);
  9793. });
  9794. toggleFormat('align' + align);
  9795. execCommand('mceRepaint');
  9796. },
  9797. // Override list commands to fix WebKit bug
  9798. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  9799. var listElm, listParent;
  9800. execNativeCommand(command);
  9801. // WebKit produces lists within block elements so we need to split them
  9802. // we will replace the native list creation logic to custom logic later on
  9803. // TODO: Remove this when the list creation logic is removed
  9804. listElm = dom.getParent(selection.getNode(), 'ol,ul');
  9805. if (listElm) {
  9806. listParent = listElm.parentNode;
  9807. // If list is within a text block then split that block
  9808. if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) {
  9809. storeSelection();
  9810. dom.split(listParent, listElm);
  9811. restoreSelection();
  9812. }
  9813. }
  9814. },
  9815. // Override commands to use the text formatter engine
  9816. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
  9817. toggleFormat(command);
  9818. },
  9819. // Override commands to use the text formatter engine
  9820. 'ForeColor,HiliteColor,FontName' : function(command, ui, value) {
  9821. toggleFormat(command, value);
  9822. },
  9823. FontSize : function(command, ui, value) {
  9824. var fontClasses, fontSizes;
  9825. // Convert font size 1-7 to styles
  9826. if (value >= 1 && value <= 7) {
  9827. fontSizes = tinymce.explode(settings.font_size_style_values);
  9828. fontClasses = tinymce.explode(settings.font_size_classes);
  9829. if (fontClasses)
  9830. value = fontClasses[value - 1] || value;
  9831. else
  9832. value = fontSizes[value - 1] || value;
  9833. }
  9834. toggleFormat(command, value);
  9835. },
  9836. RemoveFormat : function(command) {
  9837. formatter.remove(command);
  9838. },
  9839. mceBlockQuote : function(command) {
  9840. toggleFormat('blockquote');
  9841. },
  9842. FormatBlock : function(command, ui, value) {
  9843. return toggleFormat(value || 'p');
  9844. },
  9845. mceCleanup : function() {
  9846. var bookmark = selection.getBookmark();
  9847. editor.setContent(editor.getContent({cleanup : TRUE}), {cleanup : TRUE});
  9848. selection.moveToBookmark(bookmark);
  9849. },
  9850. mceRemoveNode : function(command, ui, value) {
  9851. var node = value || selection.getNode();
  9852. // Make sure that the body node isn't removed
  9853. if (node != editor.getBody()) {
  9854. storeSelection();
  9855. editor.dom.remove(node, TRUE);
  9856. restoreSelection();
  9857. }
  9858. },
  9859. mceSelectNodeDepth : function(command, ui, value) {
  9860. var counter = 0;
  9861. dom.getParent(selection.getNode(), function(node) {
  9862. if (node.nodeType == 1 && counter++ == value) {
  9863. selection.select(node);
  9864. return FALSE;
  9865. }
  9866. }, editor.getBody());
  9867. },
  9868. mceSelectNode : function(command, ui, value) {
  9869. selection.select(value);
  9870. },
  9871. mceInsertContent : function(command, ui, value) {
  9872. var parser, serializer, parentNode, rootNode, fragment, args,
  9873. marker, nodeRect, viewPortRect, rng, node, node2, bookmarkHtml, viewportBodyElement;
  9874. //selection.normalize();
  9875. // Setup parser and serializer
  9876. parser = editor.parser;
  9877. serializer = new tinymce.html.Serializer({}, editor.schema);
  9878. bookmarkHtml = '<span id="mce_marker" data-mce-type="bookmark">\uFEFF</span>';
  9879. // Run beforeSetContent handlers on the HTML to be inserted
  9880. args = {content: value, format: 'html'};
  9881. selection.onBeforeSetContent.dispatch(selection, args);
  9882. value = args.content;
  9883. // Add caret at end of contents if it's missing
  9884. if (value.indexOf('{$caret}') == -1)
  9885. value += '{$caret}';
  9886. // Replace the caret marker with a span bookmark element
  9887. value = value.replace(/\{\$caret\}/, bookmarkHtml);
  9888. // Insert node maker where we will insert the new HTML and get it's parent
  9889. if (!selection.isCollapsed())
  9890. editor.getDoc().execCommand('Delete', false, null);
  9891. parentNode = selection.getNode();
  9892. // Parse the fragment within the context of the parent node
  9893. args = {context : parentNode.nodeName.toLowerCase()};
  9894. fragment = parser.parse(value, args);
  9895. // Move the caret to a more suitable location
  9896. node = fragment.lastChild;
  9897. if (node.attr('id') == 'mce_marker') {
  9898. marker = node;
  9899. for (node = node.prev; node; node = node.walk(true)) {
  9900. if (node.type == 3 || !dom.isBlock(node.name)) {
  9901. node.parent.insert(marker, node, node.name === 'br');
  9902. break;
  9903. }
  9904. }
  9905. }
  9906. // If parser says valid we can insert the contents into that parent
  9907. if (!args.invalid) {
  9908. value = serializer.serialize(fragment);
  9909. // Check if parent is empty or only has one BR element then set the innerHTML of that parent
  9910. node = parentNode.firstChild;
  9911. node2 = parentNode.lastChild;
  9912. if (!node || (node === node2 && node.nodeName === 'BR'))
  9913. dom.setHTML(parentNode, value);
  9914. else
  9915. selection.setContent(value);
  9916. } else {
  9917. // If the fragment was invalid within that context then we need
  9918. // to parse and process the parent it's inserted into
  9919. // Insert bookmark node and get the parent
  9920. selection.setContent(bookmarkHtml);
  9921. parentNode = editor.selection.getNode();
  9922. rootNode = editor.getBody();
  9923. // Opera will return the document node when selection is in root
  9924. if (parentNode.nodeType == 9)
  9925. parentNode = node = rootNode;
  9926. else
  9927. node = parentNode;
  9928. // Find the ancestor just before the root element
  9929. while (node !== rootNode) {
  9930. parentNode = node;
  9931. node = node.parentNode;
  9932. }
  9933. // Get the outer/inner HTML depending on if we are in the root and parser and serialize that
  9934. value = parentNode == rootNode ? rootNode.innerHTML : dom.getOuterHTML(parentNode);
  9935. value = serializer.serialize(
  9936. parser.parse(
  9937. // Need to replace by using a function since $ in the contents would otherwise be a problem
  9938. value.replace(/<span (id="mce_marker"|id=mce_marker).+?<\/span>/i, function() {
  9939. return serializer.serialize(fragment);
  9940. })
  9941. )
  9942. );
  9943. // Set the inner/outer HTML depending on if we are in the root or not
  9944. if (parentNode == rootNode)
  9945. dom.setHTML(rootNode, value);
  9946. else
  9947. dom.setOuterHTML(parentNode, value);
  9948. }
  9949. marker = dom.get('mce_marker');
  9950. // Scroll range into view scrollIntoView on element can't be used since it will scroll the main view port as well
  9951. nodeRect = dom.getRect(marker);
  9952. viewPortRect = dom.getViewPort(editor.getWin());
  9953. // Check if node is out side the viewport if it is then scroll to it
  9954. if ((nodeRect.y + nodeRect.h > viewPortRect.y + viewPortRect.h || nodeRect.y < viewPortRect.y) ||
  9955. (nodeRect.x > viewPortRect.x + viewPortRect.w || nodeRect.x < viewPortRect.x)) {
  9956. viewportBodyElement = tinymce.isIE ? editor.getDoc().documentElement : editor.getBody();
  9957. viewportBodyElement.scrollLeft = nodeRect.x;
  9958. viewportBodyElement.scrollTop = nodeRect.y - viewPortRect.h + 25;
  9959. }
  9960. // Move selection before marker and remove it
  9961. rng = dom.createRng();
  9962. // If previous sibling is a text node set the selection to the end of that node
  9963. node = marker.previousSibling;
  9964. if (node && node.nodeType == 3) {
  9965. rng.setStart(node, node.nodeValue.length);
  9966. } else {
  9967. // If the previous sibling isn't a text node or doesn't exist set the selection before the marker node
  9968. rng.setStartBefore(marker);
  9969. rng.setEndBefore(marker);
  9970. }
  9971. // Remove the marker node and set the new range
  9972. dom.remove(marker);
  9973. selection.setRng(rng);
  9974. // Dispatch after event and add any visual elements needed
  9975. selection.onSetContent.dispatch(selection, args);
  9976. editor.addVisual();
  9977. },
  9978. mceInsertRawHTML : function(command, ui, value) {
  9979. selection.setContent('tiny_mce_marker');
  9980. editor.setContent(editor.getContent().replace(/tiny_mce_marker/g, function() { return value }));
  9981. },
  9982. mceSetContent : function(command, ui, value) {
  9983. editor.setContent(value);
  9984. },
  9985. 'Indent,Outdent' : function(command) {
  9986. var intentValue, indentUnit, value;
  9987. // Setup indent level
  9988. intentValue = settings.indentation;
  9989. indentUnit = /[a-z%]+$/i.exec(intentValue);
  9990. intentValue = parseInt(intentValue);
  9991. if (!queryCommandState('InsertUnorderedList') && !queryCommandState('InsertOrderedList')) {
  9992. each(selection.getSelectedBlocks(), function(element) {
  9993. if (command == 'outdent') {
  9994. value = Math.max(0, parseInt(element.style.paddingLeft || 0) - intentValue);
  9995. dom.setStyle(element, 'paddingLeft', value ? value + indentUnit : '');
  9996. } else
  9997. dom.setStyle(element, 'paddingLeft', (parseInt(element.style.paddingLeft || 0) + intentValue) + indentUnit);
  9998. });
  9999. } else
  10000. execNativeCommand(command);
  10001. },
  10002. mceRepaint : function() {
  10003. var bookmark;
  10004. if (tinymce.isGecko) {
  10005. try {
  10006. storeSelection(TRUE);
  10007. if (selection.getSel())
  10008. selection.getSel().selectAllChildren(editor.getBody());
  10009. selection.collapse(TRUE);
  10010. restoreSelection();
  10011. } catch (ex) {
  10012. // Ignore
  10013. }
  10014. }
  10015. },
  10016. mceToggleFormat : function(command, ui, value) {
  10017. formatter.toggle(value);
  10018. },
  10019. InsertHorizontalRule : function() {
  10020. editor.execCommand('mceInsertContent', false, '<hr />');
  10021. },
  10022. mceToggleVisualAid : function() {
  10023. editor.hasVisual = !editor.hasVisual;
  10024. editor.addVisual();
  10025. },
  10026. mceReplaceContent : function(command, ui, value) {
  10027. editor.execCommand('mceInsertContent', false, value.replace(/\{\$selection\}/g, selection.getContent({format : 'text'})));
  10028. },
  10029. mceInsertLink : function(command, ui, value) {
  10030. var anchor;
  10031. if (typeof(value) == 'string')
  10032. value = {href : value};
  10033. anchor = dom.getParent(selection.getNode(), 'a');
  10034. // Spaces are never valid in URLs and it's a very common mistake for people to make so we fix it here.
  10035. value.href = value.href.replace(' ', '%20');
  10036. // Remove existing links if there could be child links or that the href isn't specified
  10037. if (!anchor || !value.href) {
  10038. formatter.remove('link');
  10039. }
  10040. // Apply new link to selection
  10041. if (value.href) {
  10042. formatter.apply('link', value, anchor);
  10043. }
  10044. },
  10045. selectAll : function() {
  10046. var root = dom.getRoot(), rng = dom.createRng();
  10047. rng.setStart(root, 0);
  10048. rng.setEnd(root, root.childNodes.length);
  10049. editor.selection.setRng(rng);
  10050. }
  10051. });
  10052. // Add queryCommandState overrides
  10053. addCommands({
  10054. // Override justify commands
  10055. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  10056. var name = 'align' + command.substring(7);
  10057. // Use Formatter.matchNode instead of Formatter.match so that we don't match on parent node. This fixes bug where for both left
  10058. // and right align buttons can be active. This could occur when selected nodes have align right and the parent has align left.
  10059. var nodes = selection.isCollapsed() ? [selection.getNode()] : selection.getSelectedBlocks();
  10060. var matches = tinymce.map(nodes, function(node) {
  10061. return !!formatter.matchNode(node, name);
  10062. });
  10063. return tinymce.inArray(matches, TRUE) !== -1;
  10064. },
  10065. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
  10066. return isFormatMatch(command);
  10067. },
  10068. mceBlockQuote : function() {
  10069. return isFormatMatch('blockquote');
  10070. },
  10071. Outdent : function() {
  10072. var node;
  10073. if (settings.inline_styles) {
  10074. if ((node = dom.getParent(selection.getStart(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  10075. return TRUE;
  10076. if ((node = dom.getParent(selection.getEnd(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  10077. return TRUE;
  10078. }
  10079. return queryCommandState('InsertUnorderedList') || queryCommandState('InsertOrderedList') || (!settings.inline_styles && !!dom.getParent(selection.getNode(), 'BLOCKQUOTE'));
  10080. },
  10081. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  10082. return dom.getParent(selection.getNode(), command == 'insertunorderedlist' ? 'UL' : 'OL');
  10083. }
  10084. }, 'state');
  10085. // Add queryCommandValue overrides
  10086. addCommands({
  10087. 'FontSize,FontName' : function(command) {
  10088. var value = 0, parent;
  10089. if (parent = dom.getParent(selection.getNode(), 'span')) {
  10090. if (command == 'fontsize')
  10091. value = parent.style.fontSize;
  10092. else
  10093. value = parent.style.fontFamily.replace(/, /g, ',').replace(/[\'\"]/g, '').toLowerCase();
  10094. }
  10095. return value;
  10096. }
  10097. }, 'value');
  10098. // Add undo manager logic
  10099. if (settings.custom_undo_redo) {
  10100. addCommands({
  10101. Undo : function() {
  10102. editor.undoManager.undo();
  10103. },
  10104. Redo : function() {
  10105. editor.undoManager.redo();
  10106. }
  10107. });
  10108. }
  10109. };
  10110. })(tinymce);
  10111. (function(tinymce) {
  10112. var Dispatcher = tinymce.util.Dispatcher;
  10113. tinymce.UndoManager = function(editor) {
  10114. var self, index = 0, data = [], beforeBookmark;
  10115. function getContent() {
  10116. return tinymce.trim(editor.getContent({format : 'raw', no_events : 1}));
  10117. };
  10118. return self = {
  10119. typing : false,
  10120. onAdd : new Dispatcher(self),
  10121. onUndo : new Dispatcher(self),
  10122. onRedo : new Dispatcher(self),
  10123. beforeChange : function() {
  10124. beforeBookmark = editor.selection.getBookmark(2, true);
  10125. },
  10126. add : function(level) {
  10127. var i, settings = editor.settings, lastLevel;
  10128. level = level || {};
  10129. level.content = getContent();
  10130. // Add undo level if needed
  10131. lastLevel = data[index];
  10132. if (lastLevel && lastLevel.content == level.content)
  10133. return null;
  10134. // Set before bookmark on previous level
  10135. if (data[index])
  10136. data[index].beforeBookmark = beforeBookmark;
  10137. // Time to compress
  10138. if (settings.custom_undo_redo_levels) {
  10139. if (data.length > settings.custom_undo_redo_levels) {
  10140. for (i = 0; i < data.length - 1; i++)
  10141. data[i] = data[i + 1];
  10142. data.length--;
  10143. index = data.length;
  10144. }
  10145. }
  10146. // Get a non intrusive normalized bookmark
  10147. level.bookmark = editor.selection.getBookmark(2, true);
  10148. // Crop array if needed
  10149. if (index < data.length - 1)
  10150. data.length = index + 1;
  10151. data.push(level);
  10152. index = data.length - 1;
  10153. self.onAdd.dispatch(self, level);
  10154. editor.isNotDirty = 0;
  10155. return level;
  10156. },
  10157. undo : function() {
  10158. var level, i;
  10159. if (self.typing) {
  10160. self.add();
  10161. self.typing = false;
  10162. }
  10163. if (index > 0) {
  10164. level = data[--index];
  10165. editor.setContent(level.content, {format : 'raw'});
  10166. editor.selection.moveToBookmark(level.beforeBookmark);
  10167. self.onUndo.dispatch(self, level);
  10168. }
  10169. return level;
  10170. },
  10171. redo : function() {
  10172. var level;
  10173. if (index < data.length - 1) {
  10174. level = data[++index];
  10175. editor.setContent(level.content, {format : 'raw'});
  10176. editor.selection.moveToBookmark(level.bookmark);
  10177. self.onRedo.dispatch(self, level);
  10178. }
  10179. return level;
  10180. },
  10181. clear : function() {
  10182. data = [];
  10183. index = 0;
  10184. self.typing = false;
  10185. },
  10186. hasUndo : function() {
  10187. return index > 0 || this.typing;
  10188. },
  10189. hasRedo : function() {
  10190. return index < data.length - 1 && !this.typing;
  10191. }
  10192. };
  10193. };
  10194. })(tinymce);
  10195. (function(tinymce) {
  10196. // Shorten names
  10197. var Event = tinymce.dom.Event,
  10198. isIE = tinymce.isIE,
  10199. isGecko = tinymce.isGecko,
  10200. isOpera = tinymce.isOpera,
  10201. each = tinymce.each,
  10202. extend = tinymce.extend,
  10203. TRUE = true,
  10204. FALSE = false;
  10205. function cloneFormats(node) {
  10206. var clone, temp, inner;
  10207. do {
  10208. if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(node.nodeName)) {
  10209. if (clone) {
  10210. temp = node.cloneNode(false);
  10211. temp.appendChild(clone);
  10212. clone = temp;
  10213. } else {
  10214. clone = inner = node.cloneNode(false);
  10215. }
  10216. clone.removeAttribute('id');
  10217. }
  10218. } while (node = node.parentNode);
  10219. if (clone)
  10220. return {wrapper : clone, inner : inner};
  10221. };
  10222. // Checks if the selection/caret is at the end of the specified block element
  10223. function isAtEnd(rng, par) {
  10224. var rng2 = par.ownerDocument.createRange();
  10225. rng2.setStart(rng.endContainer, rng.endOffset);
  10226. rng2.setEndAfter(par);
  10227. // Get number of characters to the right of the cursor if it's zero then we are at the end and need to merge the next block element
  10228. return rng2.cloneContents().textContent.length == 0;
  10229. };
  10230. function splitList(selection, dom, li) {
  10231. var listBlock, block;
  10232. if (dom.isEmpty(li)) {
  10233. listBlock = dom.getParent(li, 'ul,ol');
  10234. if (!dom.getParent(listBlock.parentNode, 'ul,ol')) {
  10235. dom.split(listBlock, li);
  10236. block = dom.create('p', 0, '<br data-mce-bogus="1" />');
  10237. dom.replace(block, li);
  10238. selection.select(block, 1);
  10239. }
  10240. return FALSE;
  10241. }
  10242. return TRUE;
  10243. };
  10244. tinymce.create('tinymce.ForceBlocks', {
  10245. ForceBlocks : function(ed) {
  10246. var t = this, s = ed.settings, elm;
  10247. t.editor = ed;
  10248. t.dom = ed.dom;
  10249. elm = (s.forced_root_block || 'p').toLowerCase();
  10250. s.element = elm.toUpperCase();
  10251. ed.onPreInit.add(t.setup, t);
  10252. },
  10253. setup : function() {
  10254. var t = this, ed = t.editor, s = ed.settings, dom = ed.dom, selection = ed.selection, blockElements = ed.schema.getBlockElements();
  10255. // Force root blocks
  10256. if (s.forced_root_block) {
  10257. function addRootBlocks() {
  10258. var node = selection.getStart(), rootNode = ed.getBody(), rng, startContainer, startOffset, endContainer, endOffset, rootBlockNode, tempNode, offset = -0xFFFFFF;
  10259. if (!node || node.nodeType !== 1)
  10260. return;
  10261. // Check if node is wrapped in block
  10262. while (node != rootNode) {
  10263. if (blockElements[node.nodeName])
  10264. return;
  10265. node = node.parentNode;
  10266. }
  10267. // Get current selection
  10268. rng = selection.getRng();
  10269. if (rng.setStart) {
  10270. startContainer = rng.startContainer;
  10271. startOffset = rng.startOffset;
  10272. endContainer = rng.endContainer;
  10273. endOffset = rng.endOffset;
  10274. } else {
  10275. // Force control range into text range
  10276. if (rng.item) {
  10277. rng = ed.getDoc().body.createTextRange();
  10278. rng.moveToElementText(rng.item(0));
  10279. }
  10280. tmpRng = rng.duplicate();
  10281. tmpRng.collapse(true);
  10282. startOffset = tmpRng.move('character', offset) * -1;
  10283. if (!tmpRng.collapsed) {
  10284. tmpRng = rng.duplicate();
  10285. tmpRng.collapse(false);
  10286. endOffset = (tmpRng.move('character', offset) * -1) - startOffset;
  10287. }
  10288. }
  10289. // Wrap non block elements and text nodes
  10290. for (node = rootNode.firstChild; node; node) {
  10291. if (node.nodeType === 3 || (node.nodeType == 1 && !blockElements[node.nodeName])) {
  10292. if (!rootBlockNode) {
  10293. rootBlockNode = dom.create(s.forced_root_block);
  10294. node.parentNode.insertBefore(rootBlockNode, node);
  10295. }
  10296. tempNode = node;
  10297. node = node.nextSibling;
  10298. rootBlockNode.appendChild(tempNode);
  10299. } else {
  10300. rootBlockNode = null;
  10301. node = node.nextSibling;
  10302. }
  10303. }
  10304. if (rng.setStart) {
  10305. rng.setStart(startContainer, startOffset);
  10306. rng.setEnd(endContainer, endOffset);
  10307. selection.setRng(rng);
  10308. } else {
  10309. try {
  10310. rng = ed.getDoc().body.createTextRange();
  10311. rng.moveToElementText(rootNode);
  10312. rng.collapse(true);
  10313. rng.moveStart('character', startOffset);
  10314. if (endOffset > 0)
  10315. rng.moveEnd('character', endOffset);
  10316. rng.select();
  10317. } catch (ex) {
  10318. // Ignore
  10319. }
  10320. }
  10321. ed.nodeChanged();
  10322. };
  10323. ed.onKeyUp.add(addRootBlocks);
  10324. ed.onClick.add(addRootBlocks);
  10325. }
  10326. if (s.force_br_newlines) {
  10327. // Force IE to produce BRs on enter
  10328. if (isIE) {
  10329. ed.onKeyPress.add(function(ed, e) {
  10330. var n;
  10331. if (e.keyCode == 13 && selection.getNode().nodeName != 'LI') {
  10332. selection.setContent('<br id="__" /> ', {format : 'raw'});
  10333. n = dom.get('__');
  10334. n.removeAttribute('id');
  10335. selection.select(n);
  10336. selection.collapse();
  10337. return Event.cancel(e);
  10338. }
  10339. });
  10340. }
  10341. }
  10342. if (s.force_p_newlines) {
  10343. if (!isIE) {
  10344. ed.onKeyPress.add(function(ed, e) {
  10345. if (e.keyCode == 13 && !e.shiftKey && !t.insertPara(e))
  10346. Event.cancel(e);
  10347. });
  10348. } else {
  10349. // Ungly hack to for IE to preserve the formatting when you press
  10350. // enter at the end of a block element with formatted contents
  10351. // This logic overrides the browsers default logic with
  10352. // custom logic that enables us to control the output
  10353. tinymce.addUnload(function() {
  10354. t._previousFormats = 0; // Fix IE leak
  10355. });
  10356. ed.onKeyPress.add(function(ed, e) {
  10357. t._previousFormats = 0;
  10358. // Clone the current formats, this will later be applied to the new block contents
  10359. if (e.keyCode == 13 && !e.shiftKey && ed.selection.isCollapsed() && s.keep_styles)
  10360. t._previousFormats = cloneFormats(ed.selection.getStart());
  10361. });
  10362. ed.onKeyUp.add(function(ed, e) {
  10363. // Let IE break the element and the wrap the new caret location in the previous formats
  10364. if (e.keyCode == 13 && !e.shiftKey) {
  10365. var parent = ed.selection.getStart(), fmt = t._previousFormats;
  10366. // Parent is an empty block
  10367. if (!parent.hasChildNodes() && fmt) {
  10368. parent = dom.getParent(parent, dom.isBlock);
  10369. if (parent && parent.nodeName != 'LI') {
  10370. parent.innerHTML = '';
  10371. if (t._previousFormats) {
  10372. parent.appendChild(fmt.wrapper);
  10373. fmt.inner.innerHTML = '\uFEFF';
  10374. } else
  10375. parent.innerHTML = '\uFEFF';
  10376. selection.select(parent, 1);
  10377. selection.collapse(true);
  10378. ed.getDoc().execCommand('Delete', false, null);
  10379. t._previousFormats = 0;
  10380. }
  10381. }
  10382. }
  10383. });
  10384. }
  10385. if (isGecko) {
  10386. ed.onKeyDown.add(function(ed, e) {
  10387. if ((e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey)
  10388. t.backspaceDelete(e, e.keyCode == 8);
  10389. });
  10390. }
  10391. }
  10392. // Workaround for missing shift+enter support, http://bugs.webkit.org/show_bug.cgi?id=16973
  10393. if (tinymce.isWebKit) {
  10394. function insertBr(ed) {
  10395. var rng = selection.getRng(), br, div = dom.create('div', null, ' '), divYPos, vpHeight = dom.getViewPort(ed.getWin()).h;
  10396. // Insert BR element
  10397. rng.insertNode(br = dom.create('br'));
  10398. // Place caret after BR
  10399. rng.setStartAfter(br);
  10400. rng.setEndAfter(br);
  10401. selection.setRng(rng);
  10402. // Could not place caret after BR then insert an nbsp entity and move the caret
  10403. if (selection.getSel().focusNode == br.previousSibling) {
  10404. selection.select(dom.insertAfter(dom.doc.createTextNode('\u00a0'), br));
  10405. selection.collapse(TRUE);
  10406. }
  10407. // Create a temporary DIV after the BR and get the position as it
  10408. // seems like getPos() returns 0 for text nodes and BR elements.
  10409. dom.insertAfter(div, br);
  10410. divYPos = dom.getPos(div).y;
  10411. dom.remove(div);
  10412. // Scroll to new position, scrollIntoView can't be used due to bug: http://bugs.webkit.org/show_bug.cgi?id=16117
  10413. if (divYPos > vpHeight) // It is not necessary to scroll if the DIV is inside the view port.
  10414. ed.getWin().scrollTo(0, divYPos);
  10415. };
  10416. ed.onKeyPress.add(function(ed, e) {
  10417. if (e.keyCode == 13 && (e.shiftKey || (s.force_br_newlines && !dom.getParent(selection.getNode(), 'h1,h2,h3,h4,h5,h6,ol,ul')))) {
  10418. insertBr(ed);
  10419. Event.cancel(e);
  10420. }
  10421. });
  10422. }
  10423. // IE specific fixes
  10424. if (isIE) {
  10425. // Replaces IE:s auto generated paragraphs with the specified element name
  10426. if (s.element != 'P') {
  10427. ed.onKeyPress.add(function(ed, e) {
  10428. t.lastElm = selection.getNode().nodeName;
  10429. });
  10430. ed.onKeyUp.add(function(ed, e) {
  10431. var bl, n = selection.getNode(), b = ed.getBody();
  10432. if (b.childNodes.length === 1 && n.nodeName == 'P') {
  10433. n = dom.rename(n, s.element);
  10434. selection.select(n);
  10435. selection.collapse();
  10436. ed.nodeChanged();
  10437. } else if (e.keyCode == 13 && !e.shiftKey && t.lastElm != 'P') {
  10438. bl = dom.getParent(n, 'p');
  10439. if (bl) {
  10440. dom.rename(bl, s.element);
  10441. ed.nodeChanged();
  10442. }
  10443. }
  10444. });
  10445. }
  10446. }
  10447. },
  10448. getParentBlock : function(n) {
  10449. var d = this.dom;
  10450. return d.getParent(n, d.isBlock);
  10451. },
  10452. insertPara : function(e) {
  10453. var t = this, ed = t.editor, dom = ed.dom, d = ed.getDoc(), se = ed.settings, s = ed.selection.getSel(), r = s.getRangeAt(0), b = d.body;
  10454. var rb, ra, dir, sn, so, en, eo, sb, eb, bn, bef, aft, sc, ec, n, vp = dom.getViewPort(ed.getWin()), y, ch, car;
  10455. ed.undoManager.beforeChange();
  10456. // If root blocks are forced then use Operas default behavior since it's really good
  10457. // Removed due to bug: #1853816
  10458. // if (se.forced_root_block && isOpera)
  10459. // return TRUE;
  10460. // Setup before range
  10461. rb = d.createRange();
  10462. // If is before the first block element and in body, then move it into first block element
  10463. rb.setStart(s.anchorNode, s.anchorOffset);
  10464. rb.collapse(TRUE);
  10465. // Setup after range
  10466. ra = d.createRange();
  10467. // If is before the first block element and in body, then move it into first block element
  10468. ra.setStart(s.focusNode, s.focusOffset);
  10469. ra.collapse(TRUE);
  10470. // Setup start/end points
  10471. dir = rb.compareBoundaryPoints(rb.START_TO_END, ra) < 0;
  10472. sn = dir ? s.anchorNode : s.focusNode;
  10473. so = dir ? s.anchorOffset : s.focusOffset;
  10474. en = dir ? s.focusNode : s.anchorNode;
  10475. eo = dir ? s.focusOffset : s.anchorOffset;
  10476. // If selection is in empty table cell
  10477. if (sn === en && /^(TD|TH)$/.test(sn.nodeName)) {
  10478. if (sn.firstChild.nodeName == 'BR')
  10479. dom.remove(sn.firstChild); // Remove BR
  10480. // Create two new block elements
  10481. if (sn.childNodes.length == 0) {
  10482. ed.dom.add(sn, se.element, null, '<br />');
  10483. aft = ed.dom.add(sn, se.element, null, '<br />');
  10484. } else {
  10485. n = sn.innerHTML;
  10486. sn.innerHTML = '';
  10487. ed.dom.add(sn, se.element, null, n);
  10488. aft = ed.dom.add(sn, se.element, null, '<br />');
  10489. }
  10490. // Move caret into the last one
  10491. r = d.createRange();
  10492. r.selectNodeContents(aft);
  10493. r.collapse(1);
  10494. ed.selection.setRng(r);
  10495. return FALSE;
  10496. }
  10497. // If the caret is in an invalid location in FF we need to move it into the first block
  10498. if (sn == b && en == b && b.firstChild && ed.dom.isBlock(b.firstChild)) {
  10499. sn = en = sn.firstChild;
  10500. so = eo = 0;
  10501. rb = d.createRange();
  10502. rb.setStart(sn, 0);
  10503. ra = d.createRange();
  10504. ra.setStart(en, 0);
  10505. }
  10506. // If the body is totally empty add a BR element this might happen on webkit
  10507. if (!d.body.hasChildNodes()) {
  10508. d.body.appendChild(dom.create('br'));
  10509. }
  10510. // Never use body as start or end node
  10511. sn = sn.nodeName == "HTML" ? d.body : sn; // Fix for Opera bug: https://bugs.opera.com/show_bug.cgi?id=273224&comments=yes
  10512. sn = sn.nodeName == "BODY" ? sn.firstChild : sn;
  10513. en = en.nodeName == "HTML" ? d.body : en; // Fix for Opera bug: https://bugs.opera.com/show_bug.cgi?id=273224&comments=yes
  10514. en = en.nodeName == "BODY" ? en.firstChild : en;
  10515. // Get start and end blocks
  10516. sb = t.getParentBlock(sn);
  10517. eb = t.getParentBlock(en);
  10518. bn = sb ? sb.nodeName : se.element; // Get block name to create
  10519. // Return inside list use default browser behavior
  10520. if (n = t.dom.getParent(sb, 'li,pre')) {
  10521. if (n.nodeName == 'LI')
  10522. return splitList(ed.selection, t.dom, n);
  10523. return TRUE;
  10524. }
  10525. // If caption or absolute layers then always generate new blocks within
  10526. if (sb && (sb.nodeName == 'CAPTION' || /absolute|relative|fixed/gi.test(dom.getStyle(sb, 'position', 1)))) {
  10527. bn = se.element;
  10528. sb = null;
  10529. }
  10530. // If caption or absolute layers then always generate new blocks within
  10531. if (eb && (eb.nodeName == 'CAPTION' || /absolute|relative|fixed/gi.test(dom.getStyle(sb, 'position', 1)))) {
  10532. bn = se.element;
  10533. eb = null;
  10534. }
  10535. // Use P instead
  10536. if (/(TD|TABLE|TH|CAPTION)/.test(bn) || (sb && bn == "DIV" && /left|right/gi.test(dom.getStyle(sb, 'float', 1)))) {
  10537. bn = se.element;
  10538. sb = eb = null;
  10539. }
  10540. // Setup new before and after blocks
  10541. bef = (sb && sb.nodeName == bn) ? sb.cloneNode(0) : ed.dom.create(bn);
  10542. aft = (eb && eb.nodeName == bn) ? eb.cloneNode(0) : ed.dom.create(bn);
  10543. // Remove id from after clone
  10544. aft.removeAttribute('id');
  10545. // Is header and cursor is at the end, then force paragraph under
  10546. if (/^(H[1-6])$/.test(bn) && isAtEnd(r, sb))
  10547. aft = ed.dom.create(se.element);
  10548. // Find start chop node
  10549. n = sc = sn;
  10550. do {
  10551. if (n == b || n.nodeType == 9 || t.dom.isBlock(n) || /(TD|TABLE|TH|CAPTION)/.test(n.nodeName))
  10552. break;
  10553. sc = n;
  10554. } while ((n = n.previousSibling ? n.previousSibling : n.parentNode));
  10555. // Find end chop node
  10556. n = ec = en;
  10557. do {
  10558. if (n == b || n.nodeType == 9 || t.dom.isBlock(n) || /(TD|TABLE|TH|CAPTION)/.test(n.nodeName))
  10559. break;
  10560. ec = n;
  10561. } while ((n = n.nextSibling ? n.nextSibling : n.parentNode));
  10562. // Place first chop part into before block element
  10563. if (sc.nodeName == bn)
  10564. rb.setStart(sc, 0);
  10565. else
  10566. rb.setStartBefore(sc);
  10567. rb.setEnd(sn, so);
  10568. bef.appendChild(rb.cloneContents() || d.createTextNode('')); // Empty text node needed for Safari
  10569. // Place secnd chop part within new block element
  10570. try {
  10571. ra.setEndAfter(ec);
  10572. } catch(ex) {
  10573. //console.debug(s.focusNode, s.focusOffset);
  10574. }
  10575. ra.setStart(en, eo);
  10576. aft.appendChild(ra.cloneContents() || d.createTextNode('')); // Empty text node needed for Safari
  10577. // Create range around everything
  10578. r = d.createRange();
  10579. if (!sc.previousSibling && sc.parentNode.nodeName == bn) {
  10580. r.setStartBefore(sc.parentNode);
  10581. } else {
  10582. if (rb.startContainer.nodeName == bn && rb.startOffset == 0)
  10583. r.setStartBefore(rb.startContainer);
  10584. else
  10585. r.setStart(rb.startContainer, rb.startOffset);
  10586. }
  10587. if (!ec.nextSibling && ec.parentNode.nodeName == bn)
  10588. r.setEndAfter(ec.parentNode);
  10589. else
  10590. r.setEnd(ra.endContainer, ra.endOffset);
  10591. // Delete and replace it with new block elements
  10592. r.deleteContents();
  10593. if (isOpera)
  10594. ed.getWin().scrollTo(0, vp.y);
  10595. // Never wrap blocks in blocks
  10596. if (bef.firstChild && bef.firstChild.nodeName == bn)
  10597. bef.innerHTML = bef.firstChild.innerHTML;
  10598. if (aft.firstChild && aft.firstChild.nodeName == bn)
  10599. aft.innerHTML = aft.firstChild.innerHTML;
  10600. function appendStyles(e, en) {
  10601. var nl = [], nn, n, i;
  10602. e.innerHTML = '';
  10603. // Make clones of style elements
  10604. if (se.keep_styles) {
  10605. n = en;
  10606. do {
  10607. // We only want style specific elements
  10608. if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(n.nodeName)) {
  10609. nn = n.cloneNode(FALSE);
  10610. dom.setAttrib(nn, 'id', ''); // Remove ID since it needs to be unique
  10611. nl.push(nn);
  10612. }
  10613. } while (n = n.parentNode);
  10614. }
  10615. // Append style elements to aft
  10616. if (nl.length > 0) {
  10617. for (i = nl.length - 1, nn = e; i >= 0; i--)
  10618. nn = nn.appendChild(nl[i]);
  10619. // Padd most inner style element
  10620. nl[0].innerHTML = isOpera ? '\u00a0' : '<br />'; // Extra space for Opera so that the caret can move there
  10621. return nl[0]; // Move caret to most inner element
  10622. } else
  10623. e.innerHTML = isOpera ? '\u00a0' : '<br />'; // Extra space for Opera so that the caret can move there
  10624. };
  10625. // Padd empty blocks
  10626. if (dom.isEmpty(bef))
  10627. appendStyles(bef, sn);
  10628. // Fill empty afterblook with current style
  10629. if (dom.isEmpty(aft))
  10630. car = appendStyles(aft, en);
  10631. // Opera needs this one backwards for older versions
  10632. if (isOpera && parseFloat(opera.version()) < 9.5) {
  10633. r.insertNode(bef);
  10634. r.insertNode(aft);
  10635. } else {
  10636. r.insertNode(aft);
  10637. r.insertNode(bef);
  10638. }
  10639. // Normalize
  10640. aft.normalize();
  10641. bef.normalize();
  10642. // Move cursor and scroll into view
  10643. ed.selection.select(aft, true);
  10644. ed.selection.collapse(true);
  10645. // 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
  10646. y = ed.dom.getPos(aft).y;
  10647. //ch = aft.clientHeight;
  10648. // Is element within viewport
  10649. if (y < vp.y || y + 25 > vp.y + vp.h) {
  10650. ed.getWin().scrollTo(0, y < vp.y ? y : y - vp.h + 25); // Needs to be hardcoded to roughly one line of text if a huge text block is broken into two blocks
  10651. /*console.debug(
  10652. 'Element: y=' + y + ', h=' + ch + ', ' +
  10653. 'Viewport: y=' + vp.y + ", h=" + vp.h + ', bottom=' + (vp.y + vp.h)
  10654. );*/
  10655. }
  10656. ed.undoManager.add();
  10657. return FALSE;
  10658. },
  10659. backspaceDelete : function(e, bs) {
  10660. var t = this, ed = t.editor, b = ed.getBody(), dom = ed.dom, n, se = ed.selection, r = se.getRng(), sc = r.startContainer, n, w, tn, walker;
  10661. // Delete when caret is behind a element doesn't work correctly on Gecko see #3011651
  10662. if (!bs && r.collapsed && sc.nodeType == 1 && r.startOffset == sc.childNodes.length) {
  10663. walker = new tinymce.dom.TreeWalker(sc.lastChild, sc);
  10664. // Walk the dom backwards until we find a text node
  10665. for (n = sc.lastChild; n; n = walker.prev()) {
  10666. if (n.nodeType == 3) {
  10667. r.setStart(n, n.nodeValue.length);
  10668. r.collapse(true);
  10669. se.setRng(r);
  10670. return;
  10671. }
  10672. }
  10673. }
  10674. // The caret sometimes gets stuck in Gecko if you delete empty paragraphs
  10675. // This workaround removes the element by hand and moves the caret to the previous element
  10676. if (sc && ed.dom.isBlock(sc) && !/^(TD|TH)$/.test(sc.nodeName) && bs) {
  10677. if (sc.childNodes.length == 0 || (sc.childNodes.length == 1 && sc.firstChild.nodeName == 'BR')) {
  10678. // Find previous block element
  10679. n = sc;
  10680. while ((n = n.previousSibling) && !ed.dom.isBlock(n)) ;
  10681. if (n) {
  10682. if (sc != b.firstChild) {
  10683. // Find last text node
  10684. w = ed.dom.doc.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, FALSE);
  10685. while (tn = w.nextNode())
  10686. n = tn;
  10687. // Place caret at the end of last text node
  10688. r = ed.getDoc().createRange();
  10689. r.setStart(n, n.nodeValue ? n.nodeValue.length : 0);
  10690. r.setEnd(n, n.nodeValue ? n.nodeValue.length : 0);
  10691. se.setRng(r);
  10692. // Remove the target container
  10693. ed.dom.remove(sc);
  10694. }
  10695. return Event.cancel(e);
  10696. }
  10697. }
  10698. }
  10699. }
  10700. });
  10701. })(tinymce);
  10702. (function(tinymce) {
  10703. // Shorten names
  10704. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, extend = tinymce.extend;
  10705. tinymce.create('tinymce.ControlManager', {
  10706. ControlManager : function(ed, s) {
  10707. var t = this, i;
  10708. s = s || {};
  10709. t.editor = ed;
  10710. t.controls = {};
  10711. t.onAdd = new tinymce.util.Dispatcher(t);
  10712. t.onPostRender = new tinymce.util.Dispatcher(t);
  10713. t.prefix = s.prefix || ed.id + '_';
  10714. t._cls = {};
  10715. t.onPostRender.add(function() {
  10716. each(t.controls, function(c) {
  10717. c.postRender();
  10718. });
  10719. });
  10720. },
  10721. get : function(id) {
  10722. return this.controls[this.prefix + id] || this.controls[id];
  10723. },
  10724. setActive : function(id, s) {
  10725. var c = null;
  10726. if (c = this.get(id))
  10727. c.setActive(s);
  10728. return c;
  10729. },
  10730. setDisabled : function(id, s) {
  10731. var c = null;
  10732. if (c = this.get(id))
  10733. c.setDisabled(s);
  10734. return c;
  10735. },
  10736. add : function(c) {
  10737. var t = this;
  10738. if (c) {
  10739. t.controls[c.id] = c;
  10740. t.onAdd.dispatch(c, t);
  10741. }
  10742. return c;
  10743. },
  10744. createControl : function(n) {
  10745. var c, t = this, ed = t.editor;
  10746. each(ed.plugins, function(p) {
  10747. if (p.createControl) {
  10748. c = p.createControl(n, t);
  10749. if (c)
  10750. return false;
  10751. }
  10752. });
  10753. switch (n) {
  10754. case "|":
  10755. case "separator":
  10756. return t.createSeparator();
  10757. }
  10758. if (!c && ed.buttons && (c = ed.buttons[n]))
  10759. return t.createButton(n, c);
  10760. return t.add(c);
  10761. },
  10762. createDropMenu : function(id, s, cc) {
  10763. var t = this, ed = t.editor, c, bm, v, cls;
  10764. s = extend({
  10765. 'class' : 'mceDropDown',
  10766. constrain : ed.settings.constrain_menus
  10767. }, s);
  10768. s['class'] = s['class'] + ' ' + ed.getParam('skin') + 'Skin';
  10769. if (v = ed.getParam('skin_variant'))
  10770. s['class'] += ' ' + ed.getParam('skin') + 'Skin' + v.substring(0, 1).toUpperCase() + v.substring(1);
  10771. id = t.prefix + id;
  10772. cls = cc || t._cls.dropmenu || tinymce.ui.DropMenu;
  10773. c = t.controls[id] = new cls(id, s);
  10774. c.onAddItem.add(function(c, o) {
  10775. var s = o.settings;
  10776. s.title = ed.getLang(s.title, s.title);
  10777. if (!s.onclick) {
  10778. s.onclick = function(v) {
  10779. if (s.cmd)
  10780. ed.execCommand(s.cmd, s.ui || false, s.value);
  10781. };
  10782. }
  10783. });
  10784. ed.onRemove.add(function() {
  10785. c.destroy();
  10786. });
  10787. // Fix for bug #1897785, #1898007
  10788. if (tinymce.isIE) {
  10789. c.onShowMenu.add(function() {
  10790. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  10791. ed.focus();
  10792. bm = ed.selection.getBookmark(1);
  10793. });
  10794. c.onHideMenu.add(function() {
  10795. if (bm) {
  10796. ed.selection.moveToBookmark(bm);
  10797. bm = 0;
  10798. }
  10799. });
  10800. }
  10801. return t.add(c);
  10802. },
  10803. createListBox : function(id, s, cc) {
  10804. var t = this, ed = t.editor, cmd, c, cls;
  10805. if (t.get(id))
  10806. return null;
  10807. s.title = ed.translate(s.title);
  10808. s.scope = s.scope || ed;
  10809. if (!s.onselect) {
  10810. s.onselect = function(v) {
  10811. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  10812. };
  10813. }
  10814. s = extend({
  10815. title : s.title,
  10816. 'class' : 'mce_' + id,
  10817. scope : s.scope,
  10818. control_manager : t
  10819. }, s);
  10820. id = t.prefix + id;
  10821. function useNativeListForAccessibility(ed) {
  10822. return ed.settings.use_accessible_selects && !tinymce.isGecko
  10823. }
  10824. if (ed.settings.use_native_selects || useNativeListForAccessibility(ed))
  10825. c = new tinymce.ui.NativeListBox(id, s);
  10826. else {
  10827. cls = cc || t._cls.listbox || tinymce.ui.ListBox;
  10828. c = new cls(id, s, ed);
  10829. }
  10830. t.controls[id] = c;
  10831. // Fix focus problem in Safari
  10832. if (tinymce.isWebKit) {
  10833. c.onPostRender.add(function(c, n) {
  10834. // Store bookmark on mousedown
  10835. Event.add(n, 'mousedown', function() {
  10836. ed.bookmark = ed.selection.getBookmark(1);
  10837. });
  10838. // Restore on focus, since it might be lost
  10839. Event.add(n, 'focus', function() {
  10840. ed.selection.moveToBookmark(ed.bookmark);
  10841. ed.bookmark = null;
  10842. });
  10843. });
  10844. }
  10845. if (c.hideMenu)
  10846. ed.onMouseDown.add(c.hideMenu, c);
  10847. return t.add(c);
  10848. },
  10849. createButton : function(id, s, cc) {
  10850. var t = this, ed = t.editor, o, c, cls;
  10851. if (t.get(id))
  10852. return null;
  10853. s.title = ed.translate(s.title);
  10854. s.label = ed.translate(s.label);
  10855. s.scope = s.scope || ed;
  10856. if (!s.onclick && !s.menu_button) {
  10857. s.onclick = function() {
  10858. ed.execCommand(s.cmd, s.ui || false, s.value);
  10859. };
  10860. }
  10861. s = extend({
  10862. title : s.title,
  10863. 'class' : 'mce_' + id,
  10864. unavailable_prefix : ed.getLang('unavailable', ''),
  10865. scope : s.scope,
  10866. control_manager : t
  10867. }, s);
  10868. id = t.prefix + id;
  10869. if (s.menu_button) {
  10870. cls = cc || t._cls.menubutton || tinymce.ui.MenuButton;
  10871. c = new cls(id, s, ed);
  10872. ed.onMouseDown.add(c.hideMenu, c);
  10873. } else {
  10874. cls = t._cls.button || tinymce.ui.Button;
  10875. c = new cls(id, s, ed);
  10876. }
  10877. return t.add(c);
  10878. },
  10879. createMenuButton : function(id, s, cc) {
  10880. s = s || {};
  10881. s.menu_button = 1;
  10882. return this.createButton(id, s, cc);
  10883. },
  10884. createSplitButton : function(id, s, cc) {
  10885. var t = this, ed = t.editor, cmd, c, cls;
  10886. if (t.get(id))
  10887. return null;
  10888. s.title = ed.translate(s.title);
  10889. s.scope = s.scope || ed;
  10890. if (!s.onclick) {
  10891. s.onclick = function(v) {
  10892. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  10893. };
  10894. }
  10895. if (!s.onselect) {
  10896. s.onselect = function(v) {
  10897. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  10898. };
  10899. }
  10900. s = extend({
  10901. title : s.title,
  10902. 'class' : 'mce_' + id,
  10903. scope : s.scope,
  10904. control_manager : t
  10905. }, s);
  10906. id = t.prefix + id;
  10907. cls = cc || t._cls.splitbutton || tinymce.ui.SplitButton;
  10908. c = t.add(new cls(id, s, ed));
  10909. ed.onMouseDown.add(c.hideMenu, c);
  10910. return c;
  10911. },
  10912. createColorSplitButton : function(id, s, cc) {
  10913. var t = this, ed = t.editor, cmd, c, cls, bm;
  10914. if (t.get(id))
  10915. return null;
  10916. s.title = ed.translate(s.title);
  10917. s.scope = s.scope || ed;
  10918. if (!s.onclick) {
  10919. s.onclick = function(v) {
  10920. if (tinymce.isIE)
  10921. bm = ed.selection.getBookmark(1);
  10922. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  10923. };
  10924. }
  10925. if (!s.onselect) {
  10926. s.onselect = function(v) {
  10927. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  10928. };
  10929. }
  10930. s = extend({
  10931. title : s.title,
  10932. 'class' : 'mce_' + id,
  10933. 'menu_class' : ed.getParam('skin') + 'Skin',
  10934. scope : s.scope,
  10935. more_colors_title : ed.getLang('more_colors')
  10936. }, s);
  10937. id = t.prefix + id;
  10938. cls = cc || t._cls.colorsplitbutton || tinymce.ui.ColorSplitButton;
  10939. c = new cls(id, s, ed);
  10940. ed.onMouseDown.add(c.hideMenu, c);
  10941. // Remove the menu element when the editor is removed
  10942. ed.onRemove.add(function() {
  10943. c.destroy();
  10944. });
  10945. // Fix for bug #1897785, #1898007
  10946. if (tinymce.isIE) {
  10947. c.onShowMenu.add(function() {
  10948. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  10949. ed.focus();
  10950. bm = ed.selection.getBookmark(1);
  10951. });
  10952. c.onHideMenu.add(function() {
  10953. if (bm) {
  10954. ed.selection.moveToBookmark(bm);
  10955. bm = 0;
  10956. }
  10957. });
  10958. }
  10959. return t.add(c);
  10960. },
  10961. createToolbar : function(id, s, cc) {
  10962. var c, t = this, cls;
  10963. id = t.prefix + id;
  10964. cls = cc || t._cls.toolbar || tinymce.ui.Toolbar;
  10965. c = new cls(id, s, t.editor);
  10966. if (t.get(id))
  10967. return null;
  10968. return t.add(c);
  10969. },
  10970. createToolbarGroup : function(id, s, cc) {
  10971. var c, t = this, cls;
  10972. id = t.prefix + id;
  10973. cls = cc || this._cls.toolbarGroup || tinymce.ui.ToolbarGroup;
  10974. c = new cls(id, s, t.editor);
  10975. if (t.get(id))
  10976. return null;
  10977. return t.add(c);
  10978. },
  10979. createSeparator : function(cc) {
  10980. var cls = cc || this._cls.separator || tinymce.ui.Separator;
  10981. return new cls();
  10982. },
  10983. setControlType : function(n, c) {
  10984. return this._cls[n.toLowerCase()] = c;
  10985. },
  10986. destroy : function() {
  10987. each(this.controls, function(c) {
  10988. c.destroy();
  10989. });
  10990. this.controls = null;
  10991. }
  10992. });
  10993. })(tinymce);
  10994. (function(tinymce) {
  10995. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isIE = tinymce.isIE, isOpera = tinymce.isOpera;
  10996. tinymce.create('tinymce.WindowManager', {
  10997. WindowManager : function(ed) {
  10998. var t = this;
  10999. t.editor = ed;
  11000. t.onOpen = new Dispatcher(t);
  11001. t.onClose = new Dispatcher(t);
  11002. t.params = {};
  11003. t.features = {};
  11004. },
  11005. open : function(s, p) {
  11006. var t = this, f = '', x, y, mo = t.editor.settings.dialog_type == 'modal', w, sw, sh, vp = tinymce.DOM.getViewPort(), u;
  11007. // Default some options
  11008. s = s || {};
  11009. p = p || {};
  11010. sw = isOpera ? vp.w : screen.width; // Opera uses windows inside the Opera window
  11011. sh = isOpera ? vp.h : screen.height;
  11012. s.name = s.name || 'mc_' + new Date().getTime();
  11013. s.width = parseInt(s.width || 320);
  11014. s.height = parseInt(s.height || 240);
  11015. s.resizable = true;
  11016. s.left = s.left || parseInt(sw / 2.0) - (s.width / 2.0);
  11017. s.top = s.top || parseInt(sh / 2.0) - (s.height / 2.0);
  11018. p.inline = false;
  11019. p.mce_width = s.width;
  11020. p.mce_height = s.height;
  11021. p.mce_auto_focus = s.auto_focus;
  11022. if (mo) {
  11023. if (isIE) {
  11024. s.center = true;
  11025. s.help = false;
  11026. s.dialogWidth = s.width + 'px';
  11027. s.dialogHeight = s.height + 'px';
  11028. s.scroll = s.scrollbars || false;
  11029. }
  11030. }
  11031. // Build features string
  11032. each(s, function(v, k) {
  11033. if (tinymce.is(v, 'boolean'))
  11034. v = v ? 'yes' : 'no';
  11035. if (!/^(name|url)$/.test(k)) {
  11036. if (isIE && mo)
  11037. f += (f ? ';' : '') + k + ':' + v;
  11038. else
  11039. f += (f ? ',' : '') + k + '=' + v;
  11040. }
  11041. });
  11042. t.features = s;
  11043. t.params = p;
  11044. t.onOpen.dispatch(t, s, p);
  11045. u = s.url || s.file;
  11046. u = tinymce._addVer(u);
  11047. try {
  11048. if (isIE && mo) {
  11049. w = 1;
  11050. window.showModalDialog(u, window, f);
  11051. } else
  11052. w = window.open(u, s.name, f);
  11053. } catch (ex) {
  11054. // Ignore
  11055. }
  11056. if (!w)
  11057. alert(t.editor.getLang('popup_blocked'));
  11058. },
  11059. close : function(w) {
  11060. w.close();
  11061. this.onClose.dispatch(this);
  11062. },
  11063. createInstance : function(cl, a, b, c, d, e) {
  11064. var f = tinymce.resolve(cl);
  11065. return new f(a, b, c, d, e);
  11066. },
  11067. confirm : function(t, cb, s, w) {
  11068. w = w || window;
  11069. cb.call(s || this, w.confirm(this._decode(this.editor.getLang(t, t))));
  11070. },
  11071. alert : function(tx, cb, s, w) {
  11072. var t = this;
  11073. w = w || window;
  11074. w.alert(t._decode(t.editor.getLang(tx, tx)));
  11075. if (cb)
  11076. cb.call(s || t);
  11077. },
  11078. resizeBy : function(dw, dh, win) {
  11079. win.resizeBy(dw, dh);
  11080. },
  11081. // Internal functions
  11082. _decode : function(s) {
  11083. return tinymce.DOM.decode(s).replace(/\\n/g, '\n');
  11084. }
  11085. });
  11086. }(tinymce));
  11087. (function(tinymce) {
  11088. tinymce.Formatter = function(ed) {
  11089. var formats = {},
  11090. each = tinymce.each,
  11091. dom = ed.dom,
  11092. selection = ed.selection,
  11093. TreeWalker = tinymce.dom.TreeWalker,
  11094. rangeUtils = new tinymce.dom.RangeUtils(dom),
  11095. isValid = ed.schema.isValidChild,
  11096. isBlock = dom.isBlock,
  11097. forcedRootBlock = ed.settings.forced_root_block,
  11098. nodeIndex = dom.nodeIndex,
  11099. INVISIBLE_CHAR = '\uFEFF',
  11100. MCE_ATTR_RE = /^(src|href|style)$/,
  11101. FALSE = false,
  11102. TRUE = true,
  11103. undefined;
  11104. function isArray(obj) {
  11105. return obj instanceof Array;
  11106. };
  11107. function getParents(node, selector) {
  11108. return dom.getParents(node, selector, dom.getRoot());
  11109. };
  11110. function isCaretNode(node) {
  11111. return node.nodeType === 1 && (node.face === 'mceinline' || node.style.fontFamily === 'mceinline');
  11112. };
  11113. // Public functions
  11114. function get(name) {
  11115. return name ? formats[name] : formats;
  11116. };
  11117. function register(name, format) {
  11118. if (name) {
  11119. if (typeof(name) !== 'string') {
  11120. each(name, function(format, name) {
  11121. register(name, format);
  11122. });
  11123. } else {
  11124. // Force format into array and add it to internal collection
  11125. format = format.length ? format : [format];
  11126. each(format, function(format) {
  11127. // Set deep to false by default on selector formats this to avoid removing
  11128. // alignment on images inside paragraphs when alignment is changed on paragraphs
  11129. if (format.deep === undefined)
  11130. format.deep = !format.selector;
  11131. // Default to true
  11132. if (format.split === undefined)
  11133. format.split = !format.selector || format.inline;
  11134. // Default to true
  11135. if (format.remove === undefined && format.selector && !format.inline)
  11136. format.remove = 'none';
  11137. // Mark format as a mixed format inline + block level
  11138. if (format.selector && format.inline) {
  11139. format.mixed = true;
  11140. format.block_expand = true;
  11141. }
  11142. // Split classes if needed
  11143. if (typeof(format.classes) === 'string')
  11144. format.classes = format.classes.split(/\s+/);
  11145. });
  11146. formats[name] = format;
  11147. }
  11148. }
  11149. };
  11150. var getTextDecoration = function(node) {
  11151. var decoration;
  11152. ed.dom.getParent(node, function(n) {
  11153. decoration = ed.dom.getStyle(n, 'text-decoration');
  11154. return decoration && decoration !== 'none';
  11155. });
  11156. return decoration;
  11157. };
  11158. var processUnderlineAndColor = function(node) {
  11159. var textDecoration;
  11160. if (node.nodeType === 1 && node.parentNode && node.parentNode.nodeType === 1) {
  11161. textDecoration = getTextDecoration(node.parentNode);
  11162. if (ed.dom.getStyle(node, 'color') && textDecoration) {
  11163. ed.dom.setStyle(node, 'text-decoration', textDecoration);
  11164. } else if (ed.dom.getStyle(node, 'textdecoration') === textDecoration) {
  11165. ed.dom.setStyle(node, 'text-decoration', null);
  11166. }
  11167. }
  11168. };
  11169. function apply(name, vars, node) {
  11170. var formatList = get(name), format = formatList[0], bookmark, rng, i, isCollapsed = selection.isCollapsed();
  11171. function setElementFormat(elm, fmt) {
  11172. fmt = fmt || format;
  11173. if (elm) {
  11174. if (fmt.onformat) {
  11175. fmt.onformat(elm, fmt, vars, node);
  11176. }
  11177. each(fmt.styles, function(value, name) {
  11178. dom.setStyle(elm, name, replaceVars(value, vars));
  11179. });
  11180. each(fmt.attributes, function(value, name) {
  11181. dom.setAttrib(elm, name, replaceVars(value, vars));
  11182. });
  11183. each(fmt.classes, function(value) {
  11184. value = replaceVars(value, vars);
  11185. if (!dom.hasClass(elm, value))
  11186. dom.addClass(elm, value);
  11187. });
  11188. }
  11189. };
  11190. function adjustSelectionToVisibleSelection() {
  11191. function findSelectionEnd(start, end) {
  11192. var walker = new TreeWalker(end);
  11193. for (node = walker.current(); node; node = walker.prev()) {
  11194. if (node.childNodes.length > 1 || node == start) {
  11195. return node;
  11196. }
  11197. }
  11198. };
  11199. // Adjust selection so that a end container with a end offset of zero is not included in the selection
  11200. // as this isn't visible to the user.
  11201. var rng = ed.selection.getRng();
  11202. var start = rng.startContainer;
  11203. var end = rng.endContainer;
  11204. if (start != end && rng.endOffset == 0) {
  11205. var newEnd = findSelectionEnd(start, end);
  11206. var endOffset = newEnd.nodeType == 3 ? newEnd.length : newEnd.childNodes.length;
  11207. rng.setEnd(newEnd, endOffset);
  11208. }
  11209. return rng;
  11210. }
  11211. function applyStyleToList(node, bookmark, wrapElm, newWrappers, process){
  11212. var nodes = [], listIndex = -1, list, startIndex = -1, endIndex = -1, currentWrapElm;
  11213. // find the index of the first child list.
  11214. each(node.childNodes, function(n, index) {
  11215. if (n.nodeName === "UL" || n.nodeName === "OL") {
  11216. listIndex = index;
  11217. list = n;
  11218. return false;
  11219. }
  11220. });
  11221. // get the index of the bookmarks
  11222. each(node.childNodes, function(n, index) {
  11223. if (n.nodeName === "SPAN" && dom.getAttrib(n, "data-mce-type") == "bookmark") {
  11224. if (n.id == bookmark.id + "_start") {
  11225. startIndex = index;
  11226. } else if (n.id == bookmark.id + "_end") {
  11227. endIndex = index;
  11228. }
  11229. }
  11230. });
  11231. // if the selection spans across an embedded list, or there isn't an embedded list - handle processing normally
  11232. if (listIndex <= 0 || (startIndex < listIndex && endIndex > listIndex)) {
  11233. each(tinymce.grep(node.childNodes), process);
  11234. return 0;
  11235. } else {
  11236. currentWrapElm = wrapElm.cloneNode(FALSE);
  11237. // create a list of the nodes on the same side of the list as the selection
  11238. each(tinymce.grep(node.childNodes), function(n, index) {
  11239. if ((startIndex < listIndex && index < listIndex) || (startIndex > listIndex && index > listIndex)) {
  11240. nodes.push(n);
  11241. n.parentNode.removeChild(n);
  11242. }
  11243. });
  11244. // insert the wrapping element either before or after the list.
  11245. if (startIndex < listIndex) {
  11246. node.insertBefore(currentWrapElm, list);
  11247. } else if (startIndex > listIndex) {
  11248. node.insertBefore(currentWrapElm, list.nextSibling);
  11249. }
  11250. // add the new nodes to the list.
  11251. newWrappers.push(currentWrapElm);
  11252. each(nodes, function(node) {
  11253. currentWrapElm.appendChild(node);
  11254. });
  11255. return currentWrapElm;
  11256. }
  11257. };
  11258. function applyRngStyle(rng, bookmark, node_specific) {
  11259. var newWrappers = [], wrapName, wrapElm;
  11260. // Setup wrapper element
  11261. wrapName = format.inline || format.block;
  11262. wrapElm = dom.create(wrapName);
  11263. setElementFormat(wrapElm);
  11264. rangeUtils.walk(rng, function(nodes) {
  11265. var currentWrapElm;
  11266. function process(node) {
  11267. var nodeName = node.nodeName.toLowerCase(), parentName = node.parentNode.nodeName.toLowerCase(), found;
  11268. // Stop wrapping on br elements
  11269. if (isEq(nodeName, 'br')) {
  11270. currentWrapElm = 0;
  11271. // Remove any br elements when we wrap things
  11272. if (format.block)
  11273. dom.remove(node);
  11274. return;
  11275. }
  11276. // If node is wrapper type
  11277. if (format.wrapper && matchNode(node, name, vars)) {
  11278. currentWrapElm = 0;
  11279. return;
  11280. }
  11281. // Can we rename the block
  11282. if (format.block && !format.wrapper && isTextBlock(nodeName)) {
  11283. node = dom.rename(node, wrapName);
  11284. setElementFormat(node);
  11285. newWrappers.push(node);
  11286. currentWrapElm = 0;
  11287. return;
  11288. }
  11289. // Handle selector patterns
  11290. if (format.selector) {
  11291. // Look for matching formats
  11292. each(formatList, function(format) {
  11293. // Check collapsed state if it exists
  11294. if ('collapsed' in format && format.collapsed !== isCollapsed) {
  11295. return;
  11296. }
  11297. if (dom.is(node, format.selector) && !isCaretNode(node)) {
  11298. setElementFormat(node, format);
  11299. found = true;
  11300. }
  11301. });
  11302. // Continue processing if a selector match wasn't found and a inline element is defined
  11303. if (!format.inline || found) {
  11304. currentWrapElm = 0;
  11305. return;
  11306. }
  11307. }
  11308. // Is it valid to wrap this item
  11309. if (isValid(wrapName, nodeName) && isValid(parentName, wrapName) &&
  11310. !(!node_specific && node.nodeType === 3 && node.nodeValue.length === 1 && node.nodeValue.charCodeAt(0) === 65279) && node.id !== '_mce_caret') {
  11311. // Start wrapping
  11312. if (!currentWrapElm) {
  11313. // Wrap the node
  11314. currentWrapElm = wrapElm.cloneNode(FALSE);
  11315. node.parentNode.insertBefore(currentWrapElm, node);
  11316. newWrappers.push(currentWrapElm);
  11317. }
  11318. currentWrapElm.appendChild(node);
  11319. } else if (nodeName == 'li' && bookmark) {
  11320. // Start wrapping - if we are in a list node and have a bookmark, then we will always begin by wrapping in a new element.
  11321. currentWrapElm = applyStyleToList(node, bookmark, wrapElm, newWrappers, process);
  11322. } else {
  11323. // Start a new wrapper for possible children
  11324. currentWrapElm = 0;
  11325. each(tinymce.grep(node.childNodes), process);
  11326. // End the last wrapper
  11327. currentWrapElm = 0;
  11328. }
  11329. };
  11330. // Process siblings from range
  11331. each(nodes, process);
  11332. });
  11333. // Wrap links inside as well, for example color inside a link when the wrapper is around the link
  11334. if (format.wrap_links === false) {
  11335. each(newWrappers, function(node) {
  11336. function process(node) {
  11337. var i, currentWrapElm, children;
  11338. if (node.nodeName === 'A') {
  11339. currentWrapElm = wrapElm.cloneNode(FALSE);
  11340. newWrappers.push(currentWrapElm);
  11341. children = tinymce.grep(node.childNodes);
  11342. for (i = 0; i < children.length; i++)
  11343. currentWrapElm.appendChild(children[i]);
  11344. node.appendChild(currentWrapElm);
  11345. }
  11346. each(tinymce.grep(node.childNodes), process);
  11347. };
  11348. process(node);
  11349. });
  11350. }
  11351. // Cleanup
  11352. each(newWrappers, function(node) {
  11353. var childCount;
  11354. function getChildCount(node) {
  11355. var count = 0;
  11356. each(node.childNodes, function(node) {
  11357. if (!isWhiteSpaceNode(node) && !isBookmarkNode(node))
  11358. count++;
  11359. });
  11360. return count;
  11361. };
  11362. function mergeStyles(node) {
  11363. var child, clone;
  11364. each(node.childNodes, function(node) {
  11365. if (node.nodeType == 1 && !isBookmarkNode(node) && !isCaretNode(node)) {
  11366. child = node;
  11367. return FALSE; // break loop
  11368. }
  11369. });
  11370. // If child was found and of the same type as the current node
  11371. if (child && matchName(child, format)) {
  11372. clone = child.cloneNode(FALSE);
  11373. setElementFormat(clone);
  11374. dom.replace(clone, node, TRUE);
  11375. dom.remove(child, 1);
  11376. }
  11377. return clone || node;
  11378. };
  11379. childCount = getChildCount(node);
  11380. // Remove empty nodes but only if there is multiple wrappers and they are not block
  11381. // elements so never remove single <h1></h1> since that would remove the currrent empty block element where the caret is at
  11382. if ((newWrappers.length > 1 || !isBlock(node)) && childCount === 0) {
  11383. dom.remove(node, 1);
  11384. return;
  11385. }
  11386. if (format.inline || format.wrapper) {
  11387. // Merges the current node with it's children of similar type to reduce the number of elements
  11388. if (!format.exact && childCount === 1)
  11389. node = mergeStyles(node);
  11390. // Remove/merge children
  11391. each(formatList, function(format) {
  11392. // Merge all children of similar type will move styles from child to parent
  11393. // this: <span style="color:red"><b><span style="color:red; font-size:10px">text</span></b></span>
  11394. // will become: <span style="color:red"><b><span style="font-size:10px">text</span></b></span>
  11395. each(dom.select(format.inline, node), function(child) {
  11396. var parent;
  11397. // When wrap_links is set to false we don't want
  11398. // to remove the format on children within links
  11399. if (format.wrap_links === false) {
  11400. parent = child.parentNode;
  11401. do {
  11402. if (parent.nodeName === 'A')
  11403. return;
  11404. } while (parent = parent.parentNode);
  11405. }
  11406. removeFormat(format, vars, child, format.exact ? child : null);
  11407. });
  11408. });
  11409. // Remove child if direct parent is of same type
  11410. if (matchNode(node.parentNode, name, vars)) {
  11411. dom.remove(node, 1);
  11412. node = 0;
  11413. return TRUE;
  11414. }
  11415. // Look for parent with similar style format
  11416. if (format.merge_with_parents) {
  11417. dom.getParent(node.parentNode, function(parent) {
  11418. if (matchNode(parent, name, vars)) {
  11419. dom.remove(node, 1);
  11420. node = 0;
  11421. return TRUE;
  11422. }
  11423. });
  11424. }
  11425. // Merge next and previous siblings if they are similar <b>text</b><b>text</b> becomes <b>texttext</b>
  11426. if (node && format.merge_siblings !== false) {
  11427. node = mergeSiblings(getNonWhiteSpaceSibling(node), node);
  11428. node = mergeSiblings(node, getNonWhiteSpaceSibling(node, TRUE));
  11429. }
  11430. }
  11431. });
  11432. };
  11433. if (format) {
  11434. if (node) {
  11435. if (node.nodeType) {
  11436. rng = dom.createRng();
  11437. rng.setStartBefore(node);
  11438. rng.setEndAfter(node);
  11439. applyRngStyle(expandRng(rng, formatList), null, true);
  11440. } else {
  11441. applyRngStyle(node, null, true);
  11442. }
  11443. } else {
  11444. if (!isCollapsed || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
  11445. // Obtain selection node before selection is unselected by applyRngStyle()
  11446. var curSelNode = ed.selection.getNode();
  11447. // Apply formatting to selection
  11448. ed.selection.setRng(adjustSelectionToVisibleSelection());
  11449. bookmark = selection.getBookmark();
  11450. applyRngStyle(expandRng(selection.getRng(TRUE), formatList), bookmark);
  11451. // Colored nodes should be underlined so that the color of the underline matches the text color.
  11452. if (format.styles && (format.styles.color || format.styles.textDecoration)) {
  11453. tinymce.walk(curSelNode, processUnderlineAndColor, 'childNodes');
  11454. processUnderlineAndColor(curSelNode);
  11455. }
  11456. selection.moveToBookmark(bookmark);
  11457. moveStart(selection.getRng(TRUE));
  11458. ed.nodeChanged();
  11459. } else
  11460. performCaretAction('apply', name, vars);
  11461. }
  11462. }
  11463. };
  11464. function remove(name, vars, node) {
  11465. var formatList = get(name), format = formatList[0], bookmark, i, rng;
  11466. // Merges the styles for each node
  11467. function process(node) {
  11468. var children, i, l;
  11469. // Grab the children first since the nodelist might be changed
  11470. children = tinymce.grep(node.childNodes);
  11471. // Process current node
  11472. for (i = 0, l = formatList.length; i < l; i++) {
  11473. if (removeFormat(formatList[i], vars, node, node))
  11474. break;
  11475. }
  11476. // Process the children
  11477. if (format.deep) {
  11478. for (i = 0, l = children.length; i < l; i++)
  11479. process(children[i]);
  11480. }
  11481. };
  11482. function findFormatRoot(container) {
  11483. var formatRoot;
  11484. // Find format root
  11485. each(getParents(container.parentNode).reverse(), function(parent) {
  11486. var format;
  11487. // Find format root element
  11488. if (!formatRoot && parent.id != '_start' && parent.id != '_end') {
  11489. // Is the node matching the format we are looking for
  11490. format = matchNode(parent, name, vars);
  11491. if (format && format.split !== false)
  11492. formatRoot = parent;
  11493. }
  11494. });
  11495. return formatRoot;
  11496. };
  11497. function wrapAndSplit(format_root, container, target, split) {
  11498. var parent, clone, lastClone, firstClone, i, formatRootParent;
  11499. // Format root found then clone formats and split it
  11500. if (format_root) {
  11501. formatRootParent = format_root.parentNode;
  11502. for (parent = container.parentNode; parent && parent != formatRootParent; parent = parent.parentNode) {
  11503. clone = parent.cloneNode(FALSE);
  11504. for (i = 0; i < formatList.length; i++) {
  11505. if (removeFormat(formatList[i], vars, clone, clone)) {
  11506. clone = 0;
  11507. break;
  11508. }
  11509. }
  11510. // Build wrapper node
  11511. if (clone) {
  11512. if (lastClone)
  11513. clone.appendChild(lastClone);
  11514. if (!firstClone)
  11515. firstClone = clone;
  11516. lastClone = clone;
  11517. }
  11518. }
  11519. // Never split block elements if the format is mixed
  11520. if (split && (!format.mixed || !isBlock(format_root)))
  11521. container = dom.split(format_root, container);
  11522. // Wrap container in cloned formats
  11523. if (lastClone) {
  11524. target.parentNode.insertBefore(lastClone, target);
  11525. firstClone.appendChild(target);
  11526. }
  11527. }
  11528. return container;
  11529. };
  11530. function splitToFormatRoot(container) {
  11531. return wrapAndSplit(findFormatRoot(container), container, container, true);
  11532. };
  11533. function unwrap(start) {
  11534. var node = dom.get(start ? '_start' : '_end'),
  11535. out = node[start ? 'firstChild' : 'lastChild'];
  11536. // If the end is placed within the start the result will be removed
  11537. // So this checks if the out node is a bookmark node if it is it
  11538. // checks for another more suitable node
  11539. if (isBookmarkNode(out))
  11540. out = out[start ? 'firstChild' : 'lastChild'];
  11541. dom.remove(node, true);
  11542. return out;
  11543. };
  11544. function removeRngStyle(rng) {
  11545. var startContainer, endContainer;
  11546. rng = expandRng(rng, formatList, TRUE);
  11547. if (format.split) {
  11548. startContainer = getContainer(rng, TRUE);
  11549. endContainer = getContainer(rng);
  11550. if (startContainer != endContainer) {
  11551. // Wrap start/end nodes in span element since these might be cloned/moved
  11552. startContainer = wrap(startContainer, 'span', {id : '_start', 'data-mce-type' : 'bookmark'});
  11553. endContainer = wrap(endContainer, 'span', {id : '_end', 'data-mce-type' : 'bookmark'});
  11554. // Split start/end
  11555. splitToFormatRoot(startContainer);
  11556. splitToFormatRoot(endContainer);
  11557. // Unwrap start/end to get real elements again
  11558. startContainer = unwrap(TRUE);
  11559. endContainer = unwrap();
  11560. } else
  11561. startContainer = endContainer = splitToFormatRoot(startContainer);
  11562. // Update range positions since they might have changed after the split operations
  11563. rng.startContainer = startContainer.parentNode;
  11564. rng.startOffset = nodeIndex(startContainer);
  11565. rng.endContainer = endContainer.parentNode;
  11566. rng.endOffset = nodeIndex(endContainer) + 1;
  11567. }
  11568. // Remove items between start/end
  11569. rangeUtils.walk(rng, function(nodes) {
  11570. each(nodes, function(node) {
  11571. process(node);
  11572. // Remove parent span if it only contains text-decoration: underline, yet a parent node is also underlined.
  11573. if (node.nodeType === 1 && ed.dom.getStyle(node, 'text-decoration') === 'underline' && node.parentNode && getTextDecoration(node.parentNode) === 'underline') {
  11574. removeFormat({'deep': false, 'exact': true, 'inline': 'span', 'styles': {'textDecoration' : 'underline'}}, null, node);
  11575. }
  11576. });
  11577. });
  11578. };
  11579. // Handle node
  11580. if (node) {
  11581. if (node.nodeType) {
  11582. rng = dom.createRng();
  11583. rng.setStartBefore(node);
  11584. rng.setEndAfter(node);
  11585. removeRngStyle(rng);
  11586. } else {
  11587. removeRngStyle(node);
  11588. }
  11589. return;
  11590. }
  11591. if (!selection.isCollapsed() || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
  11592. bookmark = selection.getBookmark();
  11593. removeRngStyle(selection.getRng(TRUE));
  11594. selection.moveToBookmark(bookmark);
  11595. // 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
  11596. if (format.inline && match(name, vars, selection.getStart())) {
  11597. moveStart(selection.getRng(true));
  11598. }
  11599. ed.nodeChanged();
  11600. } else
  11601. performCaretAction('remove', name, vars);
  11602. // When you remove formatting from a table cell in WebKit (cell, not the contents of a cell) there is a rendering issue with column width
  11603. if (tinymce.isWebKit) {
  11604. ed.execCommand('mceCleanup');
  11605. }
  11606. };
  11607. function toggle(name, vars, node) {
  11608. var fmt = get(name);
  11609. if (match(name, vars, node) && (!('toggle' in fmt[0]) || fmt[0]['toggle']))
  11610. remove(name, vars, node);
  11611. else
  11612. apply(name, vars, node);
  11613. };
  11614. function matchNode(node, name, vars, similar) {
  11615. var formatList = get(name), format, i, classes;
  11616. function matchItems(node, format, item_name) {
  11617. var key, value, items = format[item_name], i;
  11618. // Custom match
  11619. if (format.onmatch) {
  11620. return format.onmatch(node, format, item_name);
  11621. }
  11622. // Check all items
  11623. if (items) {
  11624. // Non indexed object
  11625. if (items.length === undefined) {
  11626. for (key in items) {
  11627. if (items.hasOwnProperty(key)) {
  11628. if (item_name === 'attributes')
  11629. value = dom.getAttrib(node, key);
  11630. else
  11631. value = getStyle(node, key);
  11632. if (similar && !value && !format.exact)
  11633. return;
  11634. if ((!similar || format.exact) && !isEq(value, replaceVars(items[key], vars)))
  11635. return;
  11636. }
  11637. }
  11638. } else {
  11639. // Only one match needed for indexed arrays
  11640. for (i = 0; i < items.length; i++) {
  11641. if (item_name === 'attributes' ? dom.getAttrib(node, items[i]) : getStyle(node, items[i]))
  11642. return format;
  11643. }
  11644. }
  11645. }
  11646. return format;
  11647. };
  11648. if (formatList && node) {
  11649. // Check each format in list
  11650. for (i = 0; i < formatList.length; i++) {
  11651. format = formatList[i];
  11652. // Name name, attributes, styles and classes
  11653. if (matchName(node, format) && matchItems(node, format, 'attributes') && matchItems(node, format, 'styles')) {
  11654. // Match classes
  11655. if (classes = format.classes) {
  11656. for (i = 0; i < classes.length; i++) {
  11657. if (!dom.hasClass(node, classes[i]))
  11658. return;
  11659. }
  11660. }
  11661. return format;
  11662. }
  11663. }
  11664. }
  11665. };
  11666. function match(name, vars, node) {
  11667. var startNode;
  11668. function matchParents(node) {
  11669. // Find first node with similar format settings
  11670. node = dom.getParent(node, function(node) {
  11671. return !!matchNode(node, name, vars, true);
  11672. });
  11673. // Do an exact check on the similar format element
  11674. return matchNode(node, name, vars);
  11675. };
  11676. // Check specified node
  11677. if (node)
  11678. return matchParents(node);
  11679. // Check selected node
  11680. node = selection.getNode();
  11681. if (matchParents(node))
  11682. return TRUE;
  11683. // Check start node if it's different
  11684. startNode = selection.getStart();
  11685. if (startNode != node) {
  11686. if (matchParents(startNode))
  11687. return TRUE;
  11688. }
  11689. return FALSE;
  11690. };
  11691. function matchAll(names, vars) {
  11692. var startElement, matchedFormatNames = [], checkedMap = {}, i, ni, name;
  11693. // Check start of selection for formats
  11694. startElement = selection.getStart();
  11695. dom.getParent(startElement, function(node) {
  11696. var i, name;
  11697. for (i = 0; i < names.length; i++) {
  11698. name = names[i];
  11699. if (!checkedMap[name] && matchNode(node, name, vars)) {
  11700. checkedMap[name] = true;
  11701. matchedFormatNames.push(name);
  11702. }
  11703. }
  11704. });
  11705. return matchedFormatNames;
  11706. };
  11707. function canApply(name) {
  11708. var formatList = get(name), startNode, parents, i, x, selector;
  11709. if (formatList) {
  11710. startNode = selection.getStart();
  11711. parents = getParents(startNode);
  11712. for (x = formatList.length - 1; x >= 0; x--) {
  11713. selector = formatList[x].selector;
  11714. // Format is not selector based, then always return TRUE
  11715. if (!selector)
  11716. return TRUE;
  11717. for (i = parents.length - 1; i >= 0; i--) {
  11718. if (dom.is(parents[i], selector))
  11719. return TRUE;
  11720. }
  11721. }
  11722. }
  11723. return FALSE;
  11724. };
  11725. // Expose to public
  11726. tinymce.extend(this, {
  11727. get : get,
  11728. register : register,
  11729. apply : apply,
  11730. remove : remove,
  11731. toggle : toggle,
  11732. match : match,
  11733. matchAll : matchAll,
  11734. matchNode : matchNode,
  11735. canApply : canApply
  11736. });
  11737. // Private functions
  11738. function matchName(node, format) {
  11739. // Check for inline match
  11740. if (isEq(node, format.inline))
  11741. return TRUE;
  11742. // Check for block match
  11743. if (isEq(node, format.block))
  11744. return TRUE;
  11745. // Check for selector match
  11746. if (format.selector)
  11747. return dom.is(node, format.selector);
  11748. };
  11749. function isEq(str1, str2) {
  11750. str1 = str1 || '';
  11751. str2 = str2 || '';
  11752. str1 = '' + (str1.nodeName || str1);
  11753. str2 = '' + (str2.nodeName || str2);
  11754. return str1.toLowerCase() == str2.toLowerCase();
  11755. };
  11756. function getStyle(node, name) {
  11757. var styleVal = dom.getStyle(node, name);
  11758. // Force the format to hex
  11759. if (name == 'color' || name == 'backgroundColor')
  11760. styleVal = dom.toHex(styleVal);
  11761. // Opera will return bold as 700
  11762. if (name == 'fontWeight' && styleVal == 700)
  11763. styleVal = 'bold';
  11764. return '' + styleVal;
  11765. };
  11766. function replaceVars(value, vars) {
  11767. if (typeof(value) != "string")
  11768. value = value(vars);
  11769. else if (vars) {
  11770. value = value.replace(/%(\w+)/g, function(str, name) {
  11771. return vars[name] || str;
  11772. });
  11773. }
  11774. return value;
  11775. };
  11776. function isWhiteSpaceNode(node) {
  11777. return node && node.nodeType === 3 && /^([\t \r\n]+|)$/.test(node.nodeValue);
  11778. };
  11779. function wrap(node, name, attrs) {
  11780. var wrapper = dom.create(name, attrs);
  11781. node.parentNode.insertBefore(wrapper, node);
  11782. wrapper.appendChild(node);
  11783. return wrapper;
  11784. };
  11785. function expandRng(rng, format, remove) {
  11786. var startContainer = rng.startContainer,
  11787. startOffset = rng.startOffset,
  11788. endContainer = rng.endContainer,
  11789. endOffset = rng.endOffset, sibling, lastIdx, leaf, endPoint;
  11790. // This function walks up the tree if there is no siblings before/after the node
  11791. function findParentContainer(start) {
  11792. var container, parent, child, sibling, siblingName;
  11793. container = parent = start ? startContainer : endContainer;
  11794. siblingName = start ? 'previousSibling' : 'nextSibling';
  11795. root = dom.getRoot();
  11796. // If it's a text node and the offset is inside the text
  11797. if (container.nodeType == 3 && !isWhiteSpaceNode(container)) {
  11798. if (start ? startOffset > 0 : endOffset < container.nodeValue.length) {
  11799. return container;
  11800. }
  11801. }
  11802. for (;;) {
  11803. // Stop expanding on block elements or root depending on format
  11804. if (parent == root || (!format[0].block_expand && isBlock(parent)))
  11805. return parent;
  11806. // Walk left/right
  11807. for (sibling = parent[siblingName]; sibling; sibling = sibling[siblingName]) {
  11808. if (!isBookmarkNode(sibling) && !isWhiteSpaceNode(sibling)) {
  11809. return parent;
  11810. }
  11811. }
  11812. // Check if we can move up are we at root level or body level
  11813. parent = parent.parentNode;
  11814. }
  11815. return container;
  11816. };
  11817. // This function walks down the tree to find the leaf at the selection.
  11818. // The offset is also returned as if node initially a leaf, the offset may be in the middle of the text node.
  11819. function findLeaf(node, offset) {
  11820. if (offset === undefined)
  11821. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  11822. while (node && node.hasChildNodes()) {
  11823. node = node.childNodes[offset];
  11824. if (node)
  11825. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  11826. }
  11827. return { node: node, offset: offset };
  11828. }
  11829. // If index based start position then resolve it
  11830. if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) {
  11831. lastIdx = startContainer.childNodes.length - 1;
  11832. startContainer = startContainer.childNodes[startOffset > lastIdx ? lastIdx : startOffset];
  11833. if (startContainer.nodeType == 3)
  11834. startOffset = 0;
  11835. }
  11836. // If index based end position then resolve it
  11837. if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) {
  11838. lastIdx = endContainer.childNodes.length - 1;
  11839. endContainer = endContainer.childNodes[endOffset > lastIdx ? lastIdx : endOffset - 1];
  11840. if (endContainer.nodeType == 3)
  11841. endOffset = endContainer.nodeValue.length;
  11842. }
  11843. // Exclude bookmark nodes if possible
  11844. if (isBookmarkNode(startContainer.parentNode) || isBookmarkNode(startContainer)) {
  11845. startContainer = isBookmarkNode(startContainer) ? startContainer : startContainer.parentNode;
  11846. startContainer = startContainer.nextSibling || startContainer;
  11847. if (startContainer.nodeType == 3)
  11848. startOffset = 0;
  11849. }
  11850. if (isBookmarkNode(endContainer.parentNode) || isBookmarkNode(endContainer)) {
  11851. endContainer = isBookmarkNode(endContainer) ? endContainer : endContainer.parentNode;
  11852. endContainer = endContainer.previousSibling || endContainer;
  11853. if (endContainer.nodeType == 3)
  11854. endOffset = endContainer.length;
  11855. }
  11856. if (format[0].inline) {
  11857. if (rng.collapsed) {
  11858. function findWordEndPoint(container, offset, start) {
  11859. var walker, node, pos, lastTextNode;
  11860. function findSpace(node, offset) {
  11861. var pos, pos2, str = node.nodeValue;
  11862. if (typeof(offset) == "undefined") {
  11863. offset = start ? str.length : 0;
  11864. }
  11865. if (start) {
  11866. pos = str.lastIndexOf(' ', offset);
  11867. pos2 = str.lastIndexOf('\u00a0', offset);
  11868. pos = pos > pos2 ? pos : pos2;
  11869. // Include the space on remove to avoid tag soup
  11870. if (pos !== -1 && !remove) {
  11871. pos++;
  11872. }
  11873. } else {
  11874. pos = str.indexOf(' ', offset);
  11875. pos2 = str.indexOf('\u00a0', offset);
  11876. pos = pos !== -1 && (pos2 === -1 || pos < pos2) ? pos : pos2;
  11877. }
  11878. return pos;
  11879. };
  11880. if (container.nodeType === 3) {
  11881. pos = findSpace(container, offset);
  11882. if (pos !== -1) {
  11883. return {container : container, offset : pos};
  11884. }
  11885. lastTextNode = container;
  11886. }
  11887. // Walk the nodes inside the block
  11888. walker = new TreeWalker(container, dom.getParent(container, isBlock) || ed.getBody());
  11889. while (node = walker[start ? 'prev' : 'next']()) {
  11890. if (node.nodeType === 3) {
  11891. lastTextNode = node;
  11892. pos = findSpace(node);
  11893. if (pos !== -1) {
  11894. return {container : node, offset : pos};
  11895. }
  11896. } else if (isBlock(node)) {
  11897. break;
  11898. }
  11899. }
  11900. if (lastTextNode) {
  11901. if (start) {
  11902. offset = 0;
  11903. } else {
  11904. offset = lastTextNode.length;
  11905. }
  11906. return {container: lastTextNode, offset: offset};
  11907. }
  11908. }
  11909. // Expand left to closest word boundery
  11910. endPoint = findWordEndPoint(startContainer, startOffset, true);
  11911. if (endPoint) {
  11912. startContainer = endPoint.container;
  11913. startOffset = endPoint.offset;
  11914. }
  11915. // Expand right to closest word boundery
  11916. endPoint = findWordEndPoint(endContainer, endOffset);
  11917. if (endPoint) {
  11918. endContainer = endPoint.container;
  11919. endOffset = endPoint.offset;
  11920. }
  11921. }
  11922. // Avoid applying formatting to a trailing space.
  11923. leaf = findLeaf(endContainer, endOffset);
  11924. if (leaf.node) {
  11925. while (leaf.node && leaf.offset === 0 && leaf.node.previousSibling)
  11926. leaf = findLeaf(leaf.node.previousSibling);
  11927. if (leaf.node && leaf.offset > 0 && leaf.node.nodeType === 3 &&
  11928. leaf.node.nodeValue.charAt(leaf.offset - 1) === ' ') {
  11929. if (leaf.offset > 1) {
  11930. endContainer = leaf.node;
  11931. endContainer.splitText(leaf.offset - 1);
  11932. } else if (leaf.node.previousSibling) {
  11933. // TODO: Figure out why this is in here
  11934. //endContainer = leaf.node.previousSibling;
  11935. }
  11936. }
  11937. }
  11938. }
  11939. // Move start/end point up the tree if the leaves are sharp and if we are in different containers
  11940. // Example * becomes !: !<p><b><i>*text</i><i>text*</i></b></p>!
  11941. // This will reduce the number of wrapper elements that needs to be created
  11942. // Move start point up the tree
  11943. if (format[0].inline || format[0].block_expand) {
  11944. if (!format[0].inline || (startContainer.nodeType != 3 || startOffset === 0)) {
  11945. startContainer = findParentContainer(true);
  11946. }
  11947. if (!format[0].inline || (endContainer.nodeType != 3 || endOffset === endContainer.nodeValue.length)) {
  11948. endContainer = findParentContainer();
  11949. }
  11950. }
  11951. // Expand start/end container to matching selector
  11952. if (format[0].selector && format[0].expand !== FALSE && !format[0].inline) {
  11953. function findSelectorEndPoint(container, sibling_name) {
  11954. var parents, i, y, curFormat;
  11955. if (container.nodeType == 3 && container.nodeValue.length == 0 && container[sibling_name])
  11956. container = container[sibling_name];
  11957. parents = getParents(container);
  11958. for (i = 0; i < parents.length; i++) {
  11959. for (y = 0; y < format.length; y++) {
  11960. curFormat = format[y];
  11961. // If collapsed state is set then skip formats that doesn't match that
  11962. if ("collapsed" in curFormat && curFormat.collapsed !== rng.collapsed)
  11963. continue;
  11964. if (dom.is(parents[i], curFormat.selector))
  11965. return parents[i];
  11966. }
  11967. }
  11968. return container;
  11969. };
  11970. // Find new startContainer/endContainer if there is better one
  11971. startContainer = findSelectorEndPoint(startContainer, 'previousSibling');
  11972. endContainer = findSelectorEndPoint(endContainer, 'nextSibling');
  11973. }
  11974. // Expand start/end container to matching block element or text node
  11975. if (format[0].block || format[0].selector) {
  11976. function findBlockEndPoint(container, sibling_name, sibling_name2) {
  11977. var node;
  11978. // Expand to block of similar type
  11979. if (!format[0].wrapper)
  11980. node = dom.getParent(container, format[0].block);
  11981. // Expand to first wrappable block element or any block element
  11982. if (!node)
  11983. node = dom.getParent(container.nodeType == 3 ? container.parentNode : container, isBlock);
  11984. // Exclude inner lists from wrapping
  11985. if (node && format[0].wrapper)
  11986. node = getParents(node, 'ul,ol').reverse()[0] || node;
  11987. // Didn't find a block element look for first/last wrappable element
  11988. if (!node) {
  11989. node = container;
  11990. while (node[sibling_name] && !isBlock(node[sibling_name])) {
  11991. node = node[sibling_name];
  11992. // Break on BR but include it will be removed later on
  11993. // we can't remove it now since we need to check if it can be wrapped
  11994. if (isEq(node, 'br'))
  11995. break;
  11996. }
  11997. }
  11998. return node || container;
  11999. };
  12000. // Find new startContainer/endContainer if there is better one
  12001. startContainer = findBlockEndPoint(startContainer, 'previousSibling');
  12002. endContainer = findBlockEndPoint(endContainer, 'nextSibling');
  12003. // Non block element then try to expand up the leaf
  12004. if (format[0].block) {
  12005. if (!isBlock(startContainer))
  12006. startContainer = findParentContainer(true);
  12007. if (!isBlock(endContainer))
  12008. endContainer = findParentContainer();
  12009. }
  12010. }
  12011. // Setup index for startContainer
  12012. if (startContainer.nodeType == 1) {
  12013. startOffset = nodeIndex(startContainer);
  12014. startContainer = startContainer.parentNode;
  12015. }
  12016. // Setup index for endContainer
  12017. if (endContainer.nodeType == 1) {
  12018. endOffset = nodeIndex(endContainer) + 1;
  12019. endContainer = endContainer.parentNode;
  12020. }
  12021. // Return new range like object
  12022. return {
  12023. startContainer : startContainer,
  12024. startOffset : startOffset,
  12025. endContainer : endContainer,
  12026. endOffset : endOffset
  12027. };
  12028. }
  12029. function removeFormat(format, vars, node, compare_node) {
  12030. var i, attrs, stylesModified;
  12031. // Check if node matches format
  12032. if (!matchName(node, format))
  12033. return FALSE;
  12034. // Should we compare with format attribs and styles
  12035. if (format.remove != 'all') {
  12036. // Remove styles
  12037. each(format.styles, function(value, name) {
  12038. value = replaceVars(value, vars);
  12039. // Indexed array
  12040. if (typeof(name) === 'number') {
  12041. name = value;
  12042. compare_node = 0;
  12043. }
  12044. if (!compare_node || isEq(getStyle(compare_node, name), value))
  12045. dom.setStyle(node, name, '');
  12046. stylesModified = 1;
  12047. });
  12048. // Remove style attribute if it's empty
  12049. if (stylesModified && dom.getAttrib(node, 'style') == '') {
  12050. node.removeAttribute('style');
  12051. node.removeAttribute('data-mce-style');
  12052. }
  12053. // Remove attributes
  12054. each(format.attributes, function(value, name) {
  12055. var valueOut;
  12056. value = replaceVars(value, vars);
  12057. // Indexed array
  12058. if (typeof(name) === 'number') {
  12059. name = value;
  12060. compare_node = 0;
  12061. }
  12062. if (!compare_node || isEq(dom.getAttrib(compare_node, name), value)) {
  12063. // Keep internal classes
  12064. if (name == 'class') {
  12065. value = dom.getAttrib(node, name);
  12066. if (value) {
  12067. // Build new class value where everything is removed except the internal prefixed classes
  12068. valueOut = '';
  12069. each(value.split(/\s+/), function(cls) {
  12070. if (/mce\w+/.test(cls))
  12071. valueOut += (valueOut ? ' ' : '') + cls;
  12072. });
  12073. // We got some internal classes left
  12074. if (valueOut) {
  12075. dom.setAttrib(node, name, valueOut);
  12076. return;
  12077. }
  12078. }
  12079. }
  12080. // IE6 has a bug where the attribute doesn't get removed correctly
  12081. if (name == "class")
  12082. node.removeAttribute('className');
  12083. // Remove mce prefixed attributes
  12084. if (MCE_ATTR_RE.test(name))
  12085. node.removeAttribute('data-mce-' + name);
  12086. node.removeAttribute(name);
  12087. }
  12088. });
  12089. // Remove classes
  12090. each(format.classes, function(value) {
  12091. value = replaceVars(value, vars);
  12092. if (!compare_node || dom.hasClass(compare_node, value))
  12093. dom.removeClass(node, value);
  12094. });
  12095. // Check for non internal attributes
  12096. attrs = dom.getAttribs(node);
  12097. for (i = 0; i < attrs.length; i++) {
  12098. if (attrs[i].nodeName.indexOf('_') !== 0)
  12099. return FALSE;
  12100. }
  12101. }
  12102. // Remove the inline child if it's empty for example <b> or <span>
  12103. if (format.remove != 'none') {
  12104. removeNode(node, format);
  12105. return TRUE;
  12106. }
  12107. };
  12108. function removeNode(node, format) {
  12109. var parentNode = node.parentNode, rootBlockElm;
  12110. if (format.block) {
  12111. if (!forcedRootBlock) {
  12112. function find(node, next, inc) {
  12113. node = getNonWhiteSpaceSibling(node, next, inc);
  12114. return !node || (node.nodeName == 'BR' || isBlock(node));
  12115. };
  12116. // Append BR elements if needed before we remove the block
  12117. if (isBlock(node) && !isBlock(parentNode)) {
  12118. if (!find(node, FALSE) && !find(node.firstChild, TRUE, 1))
  12119. node.insertBefore(dom.create('br'), node.firstChild);
  12120. if (!find(node, TRUE) && !find(node.lastChild, FALSE, 1))
  12121. node.appendChild(dom.create('br'));
  12122. }
  12123. } else {
  12124. // Wrap the block in a forcedRootBlock if we are at the root of document
  12125. if (parentNode == dom.getRoot()) {
  12126. if (!format.list_block || !isEq(node, format.list_block)) {
  12127. each(tinymce.grep(node.childNodes), function(node) {
  12128. if (isValid(forcedRootBlock, node.nodeName.toLowerCase())) {
  12129. if (!rootBlockElm)
  12130. rootBlockElm = wrap(node, forcedRootBlock);
  12131. else
  12132. rootBlockElm.appendChild(node);
  12133. } else
  12134. rootBlockElm = 0;
  12135. });
  12136. }
  12137. }
  12138. }
  12139. }
  12140. // Never remove nodes that isn't the specified inline element if a selector is specified too
  12141. if (format.selector && format.inline && !isEq(format.inline, node))
  12142. return;
  12143. dom.remove(node, 1);
  12144. };
  12145. function getNonWhiteSpaceSibling(node, next, inc) {
  12146. if (node) {
  12147. next = next ? 'nextSibling' : 'previousSibling';
  12148. for (node = inc ? node : node[next]; node; node = node[next]) {
  12149. if (node.nodeType == 1 || !isWhiteSpaceNode(node))
  12150. return node;
  12151. }
  12152. }
  12153. };
  12154. function isBookmarkNode(node) {
  12155. return node && node.nodeType == 1 && node.getAttribute('data-mce-type') == 'bookmark';
  12156. };
  12157. function mergeSiblings(prev, next) {
  12158. var marker, sibling, tmpSibling;
  12159. function compareElements(node1, node2) {
  12160. // Not the same name
  12161. if (node1.nodeName != node2.nodeName)
  12162. return FALSE;
  12163. function getAttribs(node) {
  12164. var attribs = {};
  12165. each(dom.getAttribs(node), function(attr) {
  12166. var name = attr.nodeName.toLowerCase();
  12167. // Don't compare internal attributes or style
  12168. if (name.indexOf('_') !== 0 && name !== 'style')
  12169. attribs[name] = dom.getAttrib(node, name);
  12170. });
  12171. return attribs;
  12172. };
  12173. function compareObjects(obj1, obj2) {
  12174. var value, name;
  12175. for (name in obj1) {
  12176. // Obj1 has item obj2 doesn't have
  12177. if (obj1.hasOwnProperty(name)) {
  12178. value = obj2[name];
  12179. // Obj2 doesn't have obj1 item
  12180. if (value === undefined)
  12181. return FALSE;
  12182. // Obj2 item has a different value
  12183. if (obj1[name] != value)
  12184. return FALSE;
  12185. // Delete similar value
  12186. delete obj2[name];
  12187. }
  12188. }
  12189. // Check if obj 2 has something obj 1 doesn't have
  12190. for (name in obj2) {
  12191. // Obj2 has item obj1 doesn't have
  12192. if (obj2.hasOwnProperty(name))
  12193. return FALSE;
  12194. }
  12195. return TRUE;
  12196. };
  12197. // Attribs are not the same
  12198. if (!compareObjects(getAttribs(node1), getAttribs(node2)))
  12199. return FALSE;
  12200. // Styles are not the same
  12201. if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style'))))
  12202. return FALSE;
  12203. return TRUE;
  12204. };
  12205. // Check if next/prev exists and that they are elements
  12206. if (prev && next) {
  12207. function findElementSibling(node, sibling_name) {
  12208. for (sibling = node; sibling; sibling = sibling[sibling_name]) {
  12209. if (sibling.nodeType == 3 && sibling.nodeValue.length !== 0)
  12210. return node;
  12211. if (sibling.nodeType == 1 && !isBookmarkNode(sibling))
  12212. return sibling;
  12213. }
  12214. return node;
  12215. };
  12216. // If previous sibling is empty then jump over it
  12217. prev = findElementSibling(prev, 'previousSibling');
  12218. next = findElementSibling(next, 'nextSibling');
  12219. // Compare next and previous nodes
  12220. if (compareElements(prev, next)) {
  12221. // Append nodes between
  12222. for (sibling = prev.nextSibling; sibling && sibling != next;) {
  12223. tmpSibling = sibling;
  12224. sibling = sibling.nextSibling;
  12225. prev.appendChild(tmpSibling);
  12226. }
  12227. // Remove next node
  12228. dom.remove(next);
  12229. // Move children into prev node
  12230. each(tinymce.grep(next.childNodes), function(node) {
  12231. prev.appendChild(node);
  12232. });
  12233. return prev;
  12234. }
  12235. }
  12236. return next;
  12237. };
  12238. function isTextBlock(name) {
  12239. return /^(h[1-6]|p|div|pre|address|dl|dt|dd)$/.test(name);
  12240. };
  12241. function getContainer(rng, start) {
  12242. var container, offset, lastIdx, walker;
  12243. container = rng[start ? 'startContainer' : 'endContainer'];
  12244. offset = rng[start ? 'startOffset' : 'endOffset'];
  12245. if (container.nodeType == 1) {
  12246. lastIdx = container.childNodes.length - 1;
  12247. if (!start && offset)
  12248. offset--;
  12249. container = container.childNodes[offset > lastIdx ? lastIdx : offset];
  12250. }
  12251. // If start text node is excluded then walk to the next node
  12252. if (container.nodeType === 3 && start && offset >= container.nodeValue.length) {
  12253. container = new TreeWalker(container, ed.getBody()).next() || container;
  12254. }
  12255. // If end text node is excluded then walk to the previous node
  12256. if (container.nodeType === 3 && !start && offset == 0) {
  12257. container = new TreeWalker(container, ed.getBody()).prev() || container;
  12258. }
  12259. return container;
  12260. };
  12261. function performCaretAction(type, name, vars) {
  12262. var invisibleChar, caretContainerId = '_mce_caret', debug = ed.settings.caret_debug;
  12263. // Setup invisible character use zero width space on Gecko since it doesn't change the heigt of the container
  12264. invisibleChar = tinymce.isGecko ? '\u200B' : INVISIBLE_CHAR;
  12265. // Creates a caret container bogus element
  12266. function createCaretContainer(fill) {
  12267. var caretContainer = dom.create('span', {id: caretContainerId, 'data-mce-bogus': true, style: debug ? 'color:red' : ''});
  12268. if (fill) {
  12269. caretContainer.appendChild(ed.getDoc().createTextNode(invisibleChar));
  12270. }
  12271. return caretContainer;
  12272. };
  12273. function isCaretContainerEmpty(node, nodes) {
  12274. while (node) {
  12275. if ((node.nodeType === 3 && node.nodeValue !== invisibleChar) || node.childNodes.length > 1) {
  12276. return false;
  12277. }
  12278. // Collect nodes
  12279. if (nodes && node.nodeType === 1) {
  12280. nodes.push(node);
  12281. }
  12282. node = node.firstChild;
  12283. }
  12284. return true;
  12285. };
  12286. // Returns any parent caret container element
  12287. function getParentCaretContainer(node) {
  12288. while (node) {
  12289. if (node.id === caretContainerId) {
  12290. return node;
  12291. }
  12292. node = node.parentNode;
  12293. }
  12294. };
  12295. // Finds the first text node in the specified node
  12296. function findFirstTextNode(node) {
  12297. var walker;
  12298. if (node) {
  12299. walker = new TreeWalker(node, node);
  12300. for (node = walker.current(); node; node = walker.next()) {
  12301. if (node.nodeType === 3) {
  12302. return node;
  12303. }
  12304. }
  12305. }
  12306. };
  12307. // Removes the caret container for the specified node or all on the current document
  12308. function removeCaretContainer(node, move_caret) {
  12309. var child, rng;
  12310. if (!node) {
  12311. node = getParentCaretContainer(selection.getStart());
  12312. if (!node) {
  12313. while (node = dom.get(caretContainerId)) {
  12314. removeCaretContainer(node, false);
  12315. }
  12316. }
  12317. } else {
  12318. rng = selection.getRng(true);
  12319. if (isCaretContainerEmpty(node)) {
  12320. if (move_caret !== false) {
  12321. rng.setStartBefore(node);
  12322. rng.setEndBefore(node);
  12323. }
  12324. dom.remove(node);
  12325. } else {
  12326. child = findFirstTextNode(node);
  12327. if (child.nodeValue.charAt(0) === INVISIBLE_CHAR) {
  12328. child = child.deleteData(0, 1);
  12329. }
  12330. dom.remove(node, 1);
  12331. }
  12332. selection.setRng(rng);
  12333. }
  12334. };
  12335. // Applies formatting to the caret postion
  12336. function applyCaretFormat() {
  12337. var rng, caretContainer, textNode, offset, bookmark, container, text;
  12338. rng = selection.getRng(true);
  12339. offset = rng.startOffset;
  12340. container = rng.startContainer;
  12341. text = container.nodeValue;
  12342. caretContainer = getParentCaretContainer(selection.getStart());
  12343. if (caretContainer) {
  12344. textNode = findFirstTextNode(caretContainer);
  12345. }
  12346. // Expand to word is caret is in the middle of a text node and the char before/after is a alpha numeric character
  12347. if (text && offset > 0 && offset < text.length && /\w/.test(text.charAt(offset)) && /\w/.test(text.charAt(offset - 1))) {
  12348. // Get bookmark of caret position
  12349. bookmark = selection.getBookmark();
  12350. // Collapse bookmark range (WebKit)
  12351. rng.collapse(true);
  12352. // Expand the range to the closest word and split it at those points
  12353. rng = expandRng(rng, get(name));
  12354. rng = rangeUtils.split(rng);
  12355. // Apply the format to the range
  12356. apply(name, vars, rng);
  12357. // Move selection back to caret position
  12358. selection.moveToBookmark(bookmark);
  12359. } else {
  12360. if (!caretContainer || textNode.nodeValue !== invisibleChar) {
  12361. caretContainer = createCaretContainer(true);
  12362. textNode = caretContainer.firstChild;
  12363. rng.insertNode(caretContainer);
  12364. offset = 1;
  12365. apply(name, vars, caretContainer);
  12366. } else {
  12367. apply(name, vars, caretContainer);
  12368. }
  12369. // Move selection to text node
  12370. selection.setCursorLocation(textNode, offset);
  12371. }
  12372. };
  12373. function removeCaretFormat() {
  12374. var rng = selection.getRng(true), container, offset, bookmark,
  12375. hasContentAfter, node, formatNode, parents = [], i, caretContainer;
  12376. container = rng.startContainer;
  12377. offset = rng.startOffset;
  12378. node = container;
  12379. if (container.nodeType == 3) {
  12380. if (offset != container.nodeValue.length || container.nodeValue === invisibleChar) {
  12381. hasContentAfter = true;
  12382. }
  12383. node = node.parentNode;
  12384. }
  12385. while (node) {
  12386. if (matchNode(node, name, vars)) {
  12387. formatNode = node;
  12388. break;
  12389. }
  12390. if (node.nextSibling) {
  12391. hasContentAfter = true;
  12392. }
  12393. parents.push(node);
  12394. node = node.parentNode;
  12395. }
  12396. // Node doesn't have the specified format
  12397. if (!formatNode) {
  12398. return;
  12399. }
  12400. // Is there contents after the caret then remove the format on the element
  12401. if (hasContentAfter) {
  12402. // Get bookmark of caret position
  12403. bookmark = selection.getBookmark();
  12404. // Collapse bookmark range (WebKit)
  12405. rng.collapse(true);
  12406. // Expand the range to the closest word and split it at those points
  12407. rng = expandRng(rng, get(name), true);
  12408. rng = rangeUtils.split(rng);
  12409. // Remove the format from the range
  12410. remove(name, vars, rng);
  12411. // Move selection back to caret position
  12412. selection.moveToBookmark(bookmark);
  12413. } else {
  12414. caretContainer = createCaretContainer();
  12415. node = caretContainer;
  12416. for (i = parents.length - 1; i >= 0; i--) {
  12417. node.appendChild(parents[i].cloneNode(false));
  12418. node = node.firstChild;
  12419. }
  12420. // Insert invisible character into inner most format element
  12421. node.appendChild(dom.doc.createTextNode(invisibleChar));
  12422. node = node.firstChild;
  12423. // Insert caret container after the formated node
  12424. dom.insertAfter(caretContainer, formatNode);
  12425. // Move selection to text node
  12426. selection.setCursorLocation(node, 1);
  12427. }
  12428. };
  12429. // Only bind the caret events once
  12430. if (!self._hasCaretEvents) {
  12431. // Mark current caret container elements as bogus when getting the contents so we don't end up with empty elements
  12432. ed.onBeforeGetContent.addToTop(function() {
  12433. var nodes = [], i;
  12434. if (isCaretContainerEmpty(getParentCaretContainer(selection.getStart()), nodes)) {
  12435. // Mark children
  12436. i = nodes.length;
  12437. while (i--) {
  12438. dom.setAttrib(nodes[i], 'data-mce-bogus', '1');
  12439. }
  12440. }
  12441. });
  12442. // Remove caret container on mouse up and on key up
  12443. tinymce.each('onMouseUp onKeyUp'.split(' '), function(name) {
  12444. ed[name].addToTop(function() {
  12445. removeCaretContainer();
  12446. });
  12447. });
  12448. // Remove caret container on keydown and it's a backspace, enter or left/right arrow keys
  12449. ed.onKeyDown.addToTop(function(ed, e) {
  12450. var keyCode = e.keyCode;
  12451. if (keyCode == 8 || keyCode == 37 || keyCode == 39) {
  12452. removeCaretContainer(getParentCaretContainer(selection.getStart()));
  12453. }
  12454. });
  12455. self._hasCaretEvents = true;
  12456. }
  12457. // Do apply or remove caret format
  12458. if (type == "apply") {
  12459. applyCaretFormat();
  12460. } else {
  12461. removeCaretFormat();
  12462. }
  12463. };
  12464. function moveStart(rng) {
  12465. var container = rng.startContainer,
  12466. offset = rng.startOffset,
  12467. walker, node, nodes, tmpNode;
  12468. // Convert text node into index if possible
  12469. if (container.nodeType == 3 && offset >= container.nodeValue.length - 1) {
  12470. container = container.parentNode;
  12471. offset = nodeIndex(container) + 1;
  12472. }
  12473. // Move startContainer/startOffset in to a suitable node
  12474. if (container.nodeType == 1) {
  12475. nodes = container.childNodes;
  12476. container = nodes[Math.min(offset, nodes.length - 1)];
  12477. walker = new TreeWalker(container);
  12478. // If offset is at end of the parent node walk to the next one
  12479. if (offset > nodes.length - 1)
  12480. walker.next();
  12481. for (node = walker.current(); node; node = walker.next()) {
  12482. if (node.nodeType == 3 && !isWhiteSpaceNode(node)) {
  12483. // IE has a "neat" feature where it moves the start node into the closest element
  12484. // we can avoid this by inserting an element before it and then remove it after we set the selection
  12485. tmpNode = dom.create('a', null, INVISIBLE_CHAR);
  12486. node.parentNode.insertBefore(tmpNode, node);
  12487. // Set selection and remove tmpNode
  12488. rng.setStart(node, 0);
  12489. selection.setRng(rng);
  12490. dom.remove(tmpNode);
  12491. return;
  12492. }
  12493. }
  12494. }
  12495. };
  12496. };
  12497. })(tinymce);
  12498. tinymce.onAddEditor.add(function(tinymce, ed) {
  12499. var filters, fontSizes, dom, settings = ed.settings;
  12500. if (settings.inline_styles) {
  12501. fontSizes = tinymce.explode(settings.font_size_legacy_values);
  12502. function replaceWithSpan(node, styles) {
  12503. tinymce.each(styles, function(value, name) {
  12504. if (value)
  12505. dom.setStyle(node, name, value);
  12506. });
  12507. dom.rename(node, 'span');
  12508. };
  12509. filters = {
  12510. font : function(dom, node) {
  12511. replaceWithSpan(node, {
  12512. backgroundColor : node.style.backgroundColor,
  12513. color : node.color,
  12514. fontFamily : node.face,
  12515. fontSize : fontSizes[parseInt(node.size) - 1]
  12516. });
  12517. },
  12518. u : function(dom, node) {
  12519. replaceWithSpan(node, {
  12520. textDecoration : 'underline'
  12521. });
  12522. },
  12523. strike : function(dom, node) {
  12524. replaceWithSpan(node, {
  12525. textDecoration : 'line-through'
  12526. });
  12527. }
  12528. };
  12529. function convert(editor, params) {
  12530. dom = editor.dom;
  12531. if (settings.convert_fonts_to_spans) {
  12532. tinymce.each(dom.select('font,u,strike', params.node), function(node) {
  12533. filters[node.nodeName.toLowerCase()](ed.dom, node);
  12534. });
  12535. }
  12536. };
  12537. ed.onPreProcess.add(convert);
  12538. ed.onSetContent.add(convert);
  12539. ed.onInit.add(function() {
  12540. ed.selection.onSetContent.add(convert);
  12541. });
  12542. }
  12543. });