No Description

tiny_mce_src.js 509KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035
  1. // FILE IS GENERATED BY COMBINING THE SOURCES IN THE "classes" DIRECTORY SO DON'T MODIFY THIS FILE DIRECTLY
  2. (function(win) {
  3. var whiteSpaceRe = /^\s*|\s*$/g,
  4. undef, isRegExpBroken = 'B'.replace(/A(.)|B/, '$1') === '$1';
  5. var tinymce = {
  6. majorVersion : '3',
  7. minorVersion : '5.8',
  8. releaseDate : '2012-11-20',
  9. _init : function() {
  10. var t = this, d = document, na = navigator, ua = na.userAgent, i, nl, n, base, p, v;
  11. t.isOpera = win.opera && opera.buildNumber;
  12. t.isWebKit = /WebKit/.test(ua);
  13. t.isIE = !t.isWebKit && !t.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(na.appName);
  14. t.isIE6 = t.isIE && /MSIE [56]/.test(ua);
  15. t.isIE7 = t.isIE && /MSIE [7]/.test(ua);
  16. t.isIE8 = t.isIE && /MSIE [8]/.test(ua);
  17. t.isIE9 = t.isIE && /MSIE [9]/.test(ua);
  18. t.isGecko = !t.isWebKit && /Gecko/.test(ua);
  19. t.isMac = ua.indexOf('Mac') != -1;
  20. t.isAir = /adobeair/i.test(ua);
  21. t.isIDevice = /(iPad|iPhone)/.test(ua);
  22. t.isIOS5 = t.isIDevice && ua.match(/AppleWebKit\/(\d*)/)[1]>=534;
  23. // TinyMCE .NET webcontrol might be setting the values for TinyMCE
  24. if (win.tinyMCEPreInit) {
  25. t.suffix = tinyMCEPreInit.suffix;
  26. t.baseURL = tinyMCEPreInit.base;
  27. t.query = tinyMCEPreInit.query;
  28. return;
  29. }
  30. // Get suffix and base
  31. t.suffix = '';
  32. // If base element found, add that infront of baseURL
  33. nl = d.getElementsByTagName('base');
  34. for (i=0; i<nl.length; i++) {
  35. v = nl[i].href;
  36. if (v) {
  37. // Host only value like http://site.com or http://site.com:8008
  38. if (/^https?:\/\/[^\/]+$/.test(v))
  39. v += '/';
  40. base = v ? v.match(/.*\//)[0] : ''; // Get only directory
  41. }
  42. }
  43. function getBase(n) {
  44. if (n.src && /tiny_mce(|_gzip|_jquery|_prototype|_full)(_dev|_src)?.js/.test(n.src)) {
  45. if (/_(src|dev)\.js/g.test(n.src))
  46. t.suffix = '_src';
  47. if ((p = n.src.indexOf('?')) != -1)
  48. t.query = n.src.substring(p + 1);
  49. t.baseURL = n.src.substring(0, n.src.lastIndexOf('/'));
  50. // If path to script is relative and a base href was found add that one infront
  51. // the src property will always be an absolute one on non IE browsers and IE 8
  52. // so this logic will basically only be executed on older IE versions
  53. if (base && t.baseURL.indexOf('://') == -1 && t.baseURL.indexOf('/') !== 0)
  54. t.baseURL = base + t.baseURL;
  55. return t.baseURL;
  56. }
  57. return null;
  58. };
  59. // Check document
  60. nl = d.getElementsByTagName('script');
  61. for (i=0; i<nl.length; i++) {
  62. if (getBase(nl[i]))
  63. return;
  64. }
  65. // Check head
  66. n = d.getElementsByTagName('head')[0];
  67. if (n) {
  68. nl = n.getElementsByTagName('script');
  69. for (i=0; i<nl.length; i++) {
  70. if (getBase(nl[i]))
  71. return;
  72. }
  73. }
  74. return;
  75. },
  76. is : function(o, t) {
  77. if (!t)
  78. return o !== undef;
  79. if (t == 'array' && tinymce.isArray(o))
  80. return true;
  81. return typeof(o) == t;
  82. },
  83. isArray: Array.isArray || function(obj) {
  84. return Object.prototype.toString.call(obj) === "[object Array]";
  85. },
  86. makeMap : function(items, delim, map) {
  87. var i;
  88. items = items || [];
  89. delim = delim || ',';
  90. if (typeof(items) == "string")
  91. items = items.split(delim);
  92. map = map || {};
  93. i = items.length;
  94. while (i--)
  95. map[items[i]] = {};
  96. return map;
  97. },
  98. each : function(o, cb, s) {
  99. var n, l;
  100. if (!o)
  101. return 0;
  102. s = s || o;
  103. if (o.length !== undef) {
  104. // Indexed arrays, needed for Safari
  105. for (n=0, l = o.length; n < l; n++) {
  106. if (cb.call(s, o[n], n, o) === false)
  107. return 0;
  108. }
  109. } else {
  110. // Hashtables
  111. for (n in o) {
  112. if (o.hasOwnProperty(n)) {
  113. if (cb.call(s, o[n], n, o) === false)
  114. return 0;
  115. }
  116. }
  117. }
  118. return 1;
  119. },
  120. map : function(a, f) {
  121. var o = [];
  122. tinymce.each(a, function(v) {
  123. o.push(f(v));
  124. });
  125. return o;
  126. },
  127. grep : function(a, f) {
  128. var o = [];
  129. tinymce.each(a, function(v) {
  130. if (!f || f(v))
  131. o.push(v);
  132. });
  133. return o;
  134. },
  135. inArray : function(a, v) {
  136. var i, l;
  137. if (a) {
  138. for (i = 0, l = a.length; i < l; i++) {
  139. if (a[i] === v)
  140. return i;
  141. }
  142. }
  143. return -1;
  144. },
  145. extend : function(obj, ext) {
  146. var i, l, name, args = arguments, value;
  147. for (i = 1, l = args.length; i < l; i++) {
  148. ext = args[i];
  149. for (name in ext) {
  150. if (ext.hasOwnProperty(name)) {
  151. value = ext[name];
  152. if (value !== undef) {
  153. obj[name] = value;
  154. }
  155. }
  156. }
  157. }
  158. return obj;
  159. },
  160. trim : function(s) {
  161. return (s ? '' + s : '').replace(whiteSpaceRe, '');
  162. },
  163. create : function(s, p, root) {
  164. var t = this, sp, ns, cn, scn, c, de = 0;
  165. // Parse : <prefix> <class>:<super class>
  166. s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s);
  167. cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name
  168. // Create namespace for new class
  169. ns = t.createNS(s[3].replace(/\.\w+$/, ''), root);
  170. // Class already exists
  171. if (ns[cn])
  172. return;
  173. // Make pure static class
  174. if (s[2] == 'static') {
  175. ns[cn] = p;
  176. if (this.onCreate)
  177. this.onCreate(s[2], s[3], ns[cn]);
  178. return;
  179. }
  180. // Create default constructor
  181. if (!p[cn]) {
  182. p[cn] = function() {};
  183. de = 1;
  184. }
  185. // Add constructor and methods
  186. ns[cn] = p[cn];
  187. t.extend(ns[cn].prototype, p);
  188. // Extend
  189. if (s[5]) {
  190. sp = t.resolve(s[5]).prototype;
  191. scn = s[5].match(/\.(\w+)$/i)[1]; // Class name
  192. // Extend constructor
  193. c = ns[cn];
  194. if (de) {
  195. // Add passthrough constructor
  196. ns[cn] = function() {
  197. return sp[scn].apply(this, arguments);
  198. };
  199. } else {
  200. // Add inherit constructor
  201. ns[cn] = function() {
  202. this.parent = sp[scn];
  203. return c.apply(this, arguments);
  204. };
  205. }
  206. ns[cn].prototype[cn] = ns[cn];
  207. // Add super methods
  208. t.each(sp, function(f, n) {
  209. ns[cn].prototype[n] = sp[n];
  210. });
  211. // Add overridden methods
  212. t.each(p, function(f, n) {
  213. // Extend methods if needed
  214. if (sp[n]) {
  215. ns[cn].prototype[n] = function() {
  216. this.parent = sp[n];
  217. return f.apply(this, arguments);
  218. };
  219. } else {
  220. if (n != cn)
  221. ns[cn].prototype[n] = f;
  222. }
  223. });
  224. }
  225. // Add static methods
  226. t.each(p['static'], function(f, n) {
  227. ns[cn][n] = f;
  228. });
  229. if (this.onCreate)
  230. this.onCreate(s[2], s[3], ns[cn].prototype);
  231. },
  232. walk : function(o, f, n, s) {
  233. s = s || this;
  234. if (o) {
  235. if (n)
  236. o = o[n];
  237. tinymce.each(o, function(o, i) {
  238. if (f.call(s, o, i, n) === false)
  239. return false;
  240. tinymce.walk(o, f, n, s);
  241. });
  242. }
  243. },
  244. createNS : function(n, o) {
  245. var i, v;
  246. o = o || win;
  247. n = n.split('.');
  248. for (i=0; i<n.length; i++) {
  249. v = n[i];
  250. if (!o[v])
  251. o[v] = {};
  252. o = o[v];
  253. }
  254. return o;
  255. },
  256. resolve : function(n, o) {
  257. var i, l;
  258. o = o || win;
  259. n = n.split('.');
  260. for (i = 0, l = n.length; i < l; i++) {
  261. o = o[n[i]];
  262. if (!o)
  263. break;
  264. }
  265. return o;
  266. },
  267. addUnload : function(f, s) {
  268. var t = this, unload;
  269. unload = function() {
  270. var li = t.unloads, o, n;
  271. if (li) {
  272. // Call unload handlers
  273. for (n in li) {
  274. o = li[n];
  275. if (o && o.func)
  276. o.func.call(o.scope, 1); // Send in one arg to distinct unload and user destroy
  277. }
  278. // Detach unload function
  279. if (win.detachEvent) {
  280. win.detachEvent('onbeforeunload', fakeUnload);
  281. win.detachEvent('onunload', unload);
  282. } else if (win.removeEventListener)
  283. win.removeEventListener('unload', unload, false);
  284. // Destroy references
  285. t.unloads = o = li = w = unload = 0;
  286. // Run garbarge collector on IE
  287. if (win.CollectGarbage)
  288. CollectGarbage();
  289. }
  290. };
  291. function fakeUnload() {
  292. var d = document;
  293. function stop() {
  294. // Prevent memory leak
  295. d.detachEvent('onstop', stop);
  296. // Call unload handler
  297. if (unload)
  298. unload();
  299. d = 0;
  300. };
  301. // Is there things still loading, then do some magic
  302. if (d.readyState == 'interactive') {
  303. // Fire unload when the currently loading page is stopped
  304. if (d)
  305. d.attachEvent('onstop', stop);
  306. // Remove onstop listener after a while to prevent the unload function
  307. // to execute if the user presses cancel in an onbeforeunload
  308. // confirm dialog and then presses the browser stop button
  309. win.setTimeout(function() {
  310. if (d)
  311. d.detachEvent('onstop', stop);
  312. }, 0);
  313. }
  314. };
  315. f = {func : f, scope : s || this};
  316. if (!t.unloads) {
  317. // Attach unload handler
  318. if (win.attachEvent) {
  319. win.attachEvent('onunload', unload);
  320. win.attachEvent('onbeforeunload', fakeUnload);
  321. } else if (win.addEventListener)
  322. win.addEventListener('unload', unload, false);
  323. // Setup initial unload handler array
  324. t.unloads = [f];
  325. } else
  326. t.unloads.push(f);
  327. return f;
  328. },
  329. removeUnload : function(f) {
  330. var u = this.unloads, r = null;
  331. tinymce.each(u, function(o, i) {
  332. if (o && o.func == f) {
  333. u.splice(i, 1);
  334. r = f;
  335. return false;
  336. }
  337. });
  338. return r;
  339. },
  340. explode : function(s, d) {
  341. if (!s || tinymce.is(s, 'array')) {
  342. return s;
  343. }
  344. return tinymce.map(s.split(d || ','), tinymce.trim);
  345. },
  346. _addVer : function(u) {
  347. var v;
  348. if (!this.query)
  349. return u;
  350. v = (u.indexOf('?') == -1 ? '?' : '&') + this.query;
  351. if (u.indexOf('#') == -1)
  352. return u + v;
  353. return u.replace('#', v + '#');
  354. },
  355. // Fix function for IE 9 where regexps isn't working correctly
  356. // Todo: remove me once MS fixes the bug
  357. _replace : function(find, replace, str) {
  358. // On IE9 we have to fake $x replacement
  359. if (isRegExpBroken) {
  360. return str.replace(find, function() {
  361. var val = replace, args = arguments, i;
  362. for (i = 0; i < args.length - 2; i++) {
  363. if (args[i] === undef) {
  364. val = val.replace(new RegExp('\\$' + i, 'g'), '');
  365. } else {
  366. val = val.replace(new RegExp('\\$' + i, 'g'), args[i]);
  367. }
  368. }
  369. return val;
  370. });
  371. }
  372. return str.replace(find, replace);
  373. }
  374. };
  375. // Initialize the API
  376. tinymce._init();
  377. // Expose tinymce namespace to the global namespace (window)
  378. win.tinymce = win.tinyMCE = tinymce;
  379. // Describe the different namespaces
  380. })(window);
  381. tinymce.create('tinymce.util.Dispatcher', {
  382. scope : null,
  383. listeners : null,
  384. inDispatch: false,
  385. Dispatcher : function(scope) {
  386. this.scope = scope || this;
  387. this.listeners = [];
  388. },
  389. add : function(callback, scope) {
  390. this.listeners.push({cb : callback, scope : scope || this.scope});
  391. return callback;
  392. },
  393. addToTop : function(callback, scope) {
  394. var self = this, listener = {cb : callback, scope : scope || self.scope};
  395. // Create new listeners if addToTop is executed in a dispatch loop
  396. if (self.inDispatch) {
  397. self.listeners = [listener].concat(self.listeners);
  398. } else {
  399. self.listeners.unshift(listener);
  400. }
  401. return callback;
  402. },
  403. remove : function(callback) {
  404. var listeners = this.listeners, output = null;
  405. tinymce.each(listeners, function(listener, i) {
  406. if (callback == listener.cb) {
  407. output = listener;
  408. listeners.splice(i, 1);
  409. return false;
  410. }
  411. });
  412. return output;
  413. },
  414. dispatch : function() {
  415. var self = this, returnValue, args = arguments, i, listeners = self.listeners, listener;
  416. self.inDispatch = true;
  417. // Needs to be a real loop since the listener count might change while looping
  418. // And this is also more efficient
  419. for (i = 0; i < listeners.length; i++) {
  420. listener = listeners[i];
  421. returnValue = listener.cb.apply(listener.scope, args.length > 0 ? args : [listener.scope]);
  422. if (returnValue === false)
  423. break;
  424. }
  425. self.inDispatch = false;
  426. return returnValue;
  427. }
  428. });
  429. (function() {
  430. var each = tinymce.each;
  431. tinymce.create('tinymce.util.URI', {
  432. URI : function(u, s) {
  433. var t = this, o, a, b, base_url;
  434. // Trim whitespace
  435. u = tinymce.trim(u);
  436. // Default settings
  437. s = t.settings = s || {};
  438. // Strange app protocol that isn't http/https or local anchor
  439. // For example: mailto,skype,tel etc.
  440. if (/^([\w\-]+):([^\/]{2})/i.test(u) || /^\s*#/.test(u)) {
  441. t.source = u;
  442. return;
  443. }
  444. // Absolute path with no host, fake host and protocol
  445. if (u.indexOf('/') === 0 && u.indexOf('//') !== 0)
  446. u = (s.base_uri ? s.base_uri.protocol || 'http' : 'http') + '://mce_host' + u;
  447. // Relative path http:// or protocol relative //path
  448. if (!/^[\w\-]*:?\/\//.test(u)) {
  449. base_url = s.base_uri ? s.base_uri.path : new tinymce.util.URI(location.href).directory;
  450. u = ((s.base_uri && s.base_uri.protocol) || 'http') + '://mce_host' + t.toAbsPath(base_url, u);
  451. }
  452. // Parse URL (Credits goes to Steave, http://blog.stevenlevithan.com/archives/parseuri)
  453. u = u.replace(/@@/g, '(mce_at)'); // Zope 3 workaround, they use @@something
  454. u = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(u);
  455. each(["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], function(v, i) {
  456. var s = u[i];
  457. // Zope 3 workaround, they use @@something
  458. if (s)
  459. s = s.replace(/\(mce_at\)/g, '@@');
  460. t[v] = s;
  461. });
  462. b = s.base_uri;
  463. if (b) {
  464. if (!t.protocol)
  465. t.protocol = b.protocol;
  466. if (!t.userInfo)
  467. t.userInfo = b.userInfo;
  468. if (!t.port && t.host === 'mce_host')
  469. t.port = b.port;
  470. if (!t.host || t.host === 'mce_host')
  471. t.host = b.host;
  472. t.source = '';
  473. }
  474. //t.path = t.path || '/';
  475. },
  476. setPath : function(p) {
  477. var t = this;
  478. p = /^(.*?)\/?(\w+)?$/.exec(p);
  479. // Update path parts
  480. t.path = p[0];
  481. t.directory = p[1];
  482. t.file = p[2];
  483. // Rebuild source
  484. t.source = '';
  485. t.getURI();
  486. },
  487. toRelative : function(u) {
  488. var t = this, o;
  489. if (u === "./")
  490. return u;
  491. u = new tinymce.util.URI(u, {base_uri : t});
  492. // Not on same domain/port or protocol
  493. if ((u.host != 'mce_host' && t.host != u.host && u.host) || t.port != u.port || t.protocol != u.protocol)
  494. return u.getURI();
  495. var tu = t.getURI(), uu = u.getURI();
  496. // Allow usage of the base_uri when relative_urls = true
  497. if(tu == uu || (tu.charAt(tu.length - 1) == "/" && tu.substr(0, tu.length - 1) == uu))
  498. return tu;
  499. o = t.toRelPath(t.path, u.path);
  500. // Add query
  501. if (u.query)
  502. o += '?' + u.query;
  503. // Add anchor
  504. if (u.anchor)
  505. o += '#' + u.anchor;
  506. return o;
  507. },
  508. toAbsolute : function(u, nh) {
  509. u = new tinymce.util.URI(u, {base_uri : this});
  510. return u.getURI(this.host == u.host && this.protocol == u.protocol ? nh : 0);
  511. },
  512. toRelPath : function(base, path) {
  513. var items, bp = 0, out = '', i, l;
  514. // Split the paths
  515. base = base.substring(0, base.lastIndexOf('/'));
  516. base = base.split('/');
  517. items = path.split('/');
  518. if (base.length >= items.length) {
  519. for (i = 0, l = base.length; i < l; i++) {
  520. if (i >= items.length || base[i] != items[i]) {
  521. bp = i + 1;
  522. break;
  523. }
  524. }
  525. }
  526. if (base.length < items.length) {
  527. for (i = 0, l = items.length; i < l; i++) {
  528. if (i >= base.length || base[i] != items[i]) {
  529. bp = i + 1;
  530. break;
  531. }
  532. }
  533. }
  534. if (bp === 1)
  535. return path;
  536. for (i = 0, l = base.length - (bp - 1); i < l; i++)
  537. out += "../";
  538. for (i = bp - 1, l = items.length; i < l; i++) {
  539. if (i != bp - 1)
  540. out += "/" + items[i];
  541. else
  542. out += items[i];
  543. }
  544. return out;
  545. },
  546. toAbsPath : function(base, path) {
  547. var i, nb = 0, o = [], tr, outPath;
  548. // Split paths
  549. tr = /\/$/.test(path) ? '/' : '';
  550. base = base.split('/');
  551. path = path.split('/');
  552. // Remove empty chunks
  553. each(base, function(k) {
  554. if (k)
  555. o.push(k);
  556. });
  557. base = o;
  558. // Merge relURLParts chunks
  559. for (i = path.length - 1, o = []; i >= 0; i--) {
  560. // Ignore empty or .
  561. if (path[i].length === 0 || path[i] === ".")
  562. continue;
  563. // Is parent
  564. if (path[i] === '..') {
  565. nb++;
  566. continue;
  567. }
  568. // Move up
  569. if (nb > 0) {
  570. nb--;
  571. continue;
  572. }
  573. o.push(path[i]);
  574. }
  575. i = base.length - nb;
  576. // If /a/b/c or /
  577. if (i <= 0)
  578. outPath = o.reverse().join('/');
  579. else
  580. outPath = base.slice(0, i).join('/') + '/' + o.reverse().join('/');
  581. // Add front / if it's needed
  582. if (outPath.indexOf('/') !== 0)
  583. outPath = '/' + outPath;
  584. // Add traling / if it's needed
  585. if (tr && outPath.lastIndexOf('/') !== outPath.length - 1)
  586. outPath += tr;
  587. return outPath;
  588. },
  589. getURI : function(nh) {
  590. var s, t = this;
  591. // Rebuild source
  592. if (!t.source || nh) {
  593. s = '';
  594. if (!nh) {
  595. if (t.protocol)
  596. s += t.protocol + '://';
  597. if (t.userInfo)
  598. s += t.userInfo + '@';
  599. if (t.host)
  600. s += t.host;
  601. if (t.port)
  602. s += ':' + t.port;
  603. }
  604. if (t.path)
  605. s += t.path;
  606. if (t.query)
  607. s += '?' + t.query;
  608. if (t.anchor)
  609. s += '#' + t.anchor;
  610. t.source = s;
  611. }
  612. return t.source;
  613. }
  614. });
  615. })();
  616. (function() {
  617. var each = tinymce.each;
  618. tinymce.create('static tinymce.util.Cookie', {
  619. getHash : function(n) {
  620. var v = this.get(n), h;
  621. if (v) {
  622. each(v.split('&'), function(v) {
  623. v = v.split('=');
  624. h = h || {};
  625. h[unescape(v[0])] = unescape(v[1]);
  626. });
  627. }
  628. return h;
  629. },
  630. setHash : function(n, v, e, p, d, s) {
  631. var o = '';
  632. each(v, function(v, k) {
  633. o += (!o ? '' : '&') + escape(k) + '=' + escape(v);
  634. });
  635. this.set(n, o, e, p, d, s);
  636. },
  637. get : function(n) {
  638. var c = document.cookie, e, p = n + "=", b;
  639. // Strict mode
  640. if (!c)
  641. return;
  642. b = c.indexOf("; " + p);
  643. if (b == -1) {
  644. b = c.indexOf(p);
  645. if (b !== 0)
  646. return null;
  647. } else
  648. b += 2;
  649. e = c.indexOf(";", b);
  650. if (e == -1)
  651. e = c.length;
  652. return unescape(c.substring(b + p.length, e));
  653. },
  654. set : function(n, v, e, p, d, s) {
  655. document.cookie = n + "=" + escape(v) +
  656. ((e) ? "; expires=" + e.toGMTString() : "") +
  657. ((p) ? "; path=" + escape(p) : "") +
  658. ((d) ? "; domain=" + d : "") +
  659. ((s) ? "; secure" : "");
  660. },
  661. remove : function(name, path, domain) {
  662. var date = new Date();
  663. date.setTime(date.getTime() - 1000);
  664. this.set(name, '', date, path, domain);
  665. }
  666. });
  667. })();
  668. (function() {
  669. function serialize(o, quote) {
  670. var i, v, t, name;
  671. quote = quote || '"';
  672. if (o == null)
  673. return 'null';
  674. t = typeof o;
  675. if (t == 'string') {
  676. v = '\bb\tt\nn\ff\rr\""\'\'\\\\';
  677. return quote + o.replace(/([\u0080-\uFFFF\x00-\x1f\"\'\\])/g, function(a, b) {
  678. // Make sure single quotes never get encoded inside double quotes for JSON compatibility
  679. if (quote === '"' && a === "'")
  680. return a;
  681. i = v.indexOf(b);
  682. if (i + 1)
  683. return '\\' + v.charAt(i + 1);
  684. a = b.charCodeAt().toString(16);
  685. return '\\u' + '0000'.substring(a.length) + a;
  686. }) + quote;
  687. }
  688. if (t == 'object') {
  689. if (o.hasOwnProperty && Object.prototype.toString.call(o) === '[object Array]') {
  690. for (i=0, v = '['; i<o.length; i++)
  691. v += (i > 0 ? ',' : '') + serialize(o[i], quote);
  692. return v + ']';
  693. }
  694. v = '{';
  695. for (name in o) {
  696. if (o.hasOwnProperty(name)) {
  697. v += typeof o[name] != 'function' ? (v.length > 1 ? ',' + quote : quote) + name + quote +':' + serialize(o[name], quote) : '';
  698. }
  699. }
  700. return v + '}';
  701. }
  702. return '' + o;
  703. };
  704. tinymce.util.JSON = {
  705. serialize: serialize,
  706. parse: function(s) {
  707. try {
  708. return eval('(' + s + ')');
  709. } catch (ex) {
  710. // Ignore
  711. }
  712. }
  713. };
  714. })();
  715. tinymce.create('static tinymce.util.XHR', {
  716. send : function(o) {
  717. var x, t, w = window, c = 0;
  718. function ready() {
  719. if (!o.async || x.readyState == 4 || c++ > 10000) {
  720. if (o.success && c < 10000 && x.status == 200)
  721. o.success.call(o.success_scope, '' + x.responseText, x, o);
  722. else if (o.error)
  723. o.error.call(o.error_scope, c > 10000 ? 'TIMED_OUT' : 'GENERAL', x, o);
  724. x = null;
  725. } else
  726. w.setTimeout(ready, 10);
  727. };
  728. // Default settings
  729. o.scope = o.scope || this;
  730. o.success_scope = o.success_scope || o.scope;
  731. o.error_scope = o.error_scope || o.scope;
  732. o.async = o.async === false ? false : true;
  733. o.data = o.data || '';
  734. function get(s) {
  735. x = 0;
  736. try {
  737. x = new ActiveXObject(s);
  738. } catch (ex) {
  739. }
  740. return x;
  741. };
  742. x = w.XMLHttpRequest ? new XMLHttpRequest() : get('Microsoft.XMLHTTP') || get('Msxml2.XMLHTTP');
  743. if (x) {
  744. if (x.overrideMimeType)
  745. x.overrideMimeType(o.content_type);
  746. x.open(o.type || (o.data ? 'POST' : 'GET'), o.url, o.async);
  747. if (o.content_type)
  748. x.setRequestHeader('Content-Type', o.content_type);
  749. x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  750. x.send(o.data);
  751. // Syncronous request
  752. if (!o.async)
  753. return ready();
  754. // Wait for response, onReadyStateChange can not be used since it leaks memory in IE
  755. t = w.setTimeout(ready, 10);
  756. }
  757. }
  758. });
  759. (function() {
  760. var extend = tinymce.extend, JSON = tinymce.util.JSON, XHR = tinymce.util.XHR;
  761. tinymce.create('tinymce.util.JSONRequest', {
  762. JSONRequest : function(s) {
  763. this.settings = extend({
  764. }, s);
  765. this.count = 0;
  766. },
  767. send : function(o) {
  768. var ecb = o.error, scb = o.success;
  769. o = extend(this.settings, o);
  770. o.success = function(c, x) {
  771. c = JSON.parse(c);
  772. if (typeof(c) == 'undefined') {
  773. c = {
  774. error : 'JSON Parse error.'
  775. };
  776. }
  777. if (c.error)
  778. ecb.call(o.error_scope || o.scope, c.error, x);
  779. else
  780. scb.call(o.success_scope || o.scope, c.result);
  781. };
  782. o.error = function(ty, x) {
  783. if (ecb)
  784. ecb.call(o.error_scope || o.scope, ty, x);
  785. };
  786. o.data = JSON.serialize({
  787. id : o.id || 'c' + (this.count++),
  788. method : o.method,
  789. params : o.params
  790. });
  791. // JSON content type for Ruby on rails. Bug: #1883287
  792. o.content_type = 'application/json';
  793. XHR.send(o);
  794. },
  795. 'static' : {
  796. sendRPC : function(o) {
  797. return new tinymce.util.JSONRequest().send(o);
  798. }
  799. }
  800. });
  801. }());
  802. (function(tinymce){
  803. tinymce.VK = {
  804. BACKSPACE: 8,
  805. DELETE: 46,
  806. DOWN: 40,
  807. ENTER: 13,
  808. LEFT: 37,
  809. RIGHT: 39,
  810. SPACEBAR: 32,
  811. TAB: 9,
  812. UP: 38,
  813. modifierPressed: function (e) {
  814. return e.shiftKey || e.ctrlKey || e.altKey;
  815. },
  816. metaKeyPressed: function(e) {
  817. // Check if ctrl or meta key is pressed also check if alt is false for Polish users
  818. return tinymce.isMac ? e.metaKey : e.ctrlKey && !e.altKey;
  819. }
  820. };
  821. })(tinymce);
  822. tinymce.util.Quirks = function(editor) {
  823. var VK = tinymce.VK, BACKSPACE = VK.BACKSPACE, DELETE = VK.DELETE, dom = editor.dom, selection = editor.selection,
  824. settings = editor.settings, parser = editor.parser, serializer = editor.serializer, each = tinymce.each;
  825. function setEditorCommandState(cmd, state) {
  826. try {
  827. editor.getDoc().execCommand(cmd, false, state);
  828. } catch (ex) {
  829. // Ignore
  830. }
  831. }
  832. function getDocumentMode() {
  833. var documentMode = editor.getDoc().documentMode;
  834. return documentMode ? documentMode : 6;
  835. };
  836. function isDefaultPrevented(e) {
  837. return e.isDefaultPrevented();
  838. };
  839. function cleanupStylesWhenDeleting() {
  840. function removeMergedFormatSpans(isDelete) {
  841. var rng, blockElm, node, clonedSpan;
  842. rng = selection.getRng();
  843. // Find root block
  844. blockElm = dom.getParent(rng.startContainer, dom.isBlock);
  845. // On delete clone the root span of the next block element
  846. if (isDelete) {
  847. blockElm = dom.getNext(blockElm, dom.isBlock);
  848. }
  849. // Locate root span element and clone it since it would otherwise get merged by the "apple-style-span" on delete/backspace
  850. if (blockElm) {
  851. node = blockElm.firstChild;
  852. // Ignore empty text nodes
  853. while (node && node.nodeType == 3 && node.nodeValue.length === 0) {
  854. node = node.nextSibling;
  855. }
  856. if (node && node.nodeName === 'SPAN') {
  857. clonedSpan = node.cloneNode(false);
  858. }
  859. }
  860. each(dom.select('span', blockElm), function(span) {
  861. span.setAttribute('data-mce-mark', '1');
  862. });
  863. // Do the backspace/delete action
  864. editor.getDoc().execCommand(isDelete ? 'ForwardDelete' : 'Delete', false, null);
  865. // Find all odd apple-style-spans
  866. blockElm = dom.getParent(rng.startContainer, dom.isBlock);
  867. each(dom.select('span', blockElm), function(span) {
  868. var bm = selection.getBookmark();
  869. if (clonedSpan) {
  870. dom.replace(clonedSpan.cloneNode(false), span, true);
  871. } else if (!span.getAttribute('data-mce-mark')) {
  872. dom.remove(span, true);
  873. } else {
  874. span.removeAttribute('data-mce-mark');
  875. }
  876. // Restore the selection
  877. selection.moveToBookmark(bm);
  878. });
  879. }
  880. editor.onKeyDown.add(function(editor, e) {
  881. var isDelete;
  882. isDelete = e.keyCode == DELETE;
  883. if (!isDefaultPrevented(e) && (isDelete || e.keyCode == BACKSPACE) && !VK.modifierPressed(e)) {
  884. e.preventDefault();
  885. removeMergedFormatSpans(isDelete);
  886. }
  887. });
  888. editor.addCommand('Delete', function() {removeMergedFormatSpans();});
  889. };
  890. function emptyEditorWhenDeleting() {
  891. function serializeRng(rng) {
  892. var body = dom.create("body");
  893. var contents = rng.cloneContents();
  894. body.appendChild(contents);
  895. return selection.serializer.serialize(body, {format: 'html'});
  896. }
  897. function allContentsSelected(rng) {
  898. var selection = serializeRng(rng);
  899. var allRng = dom.createRng();
  900. allRng.selectNode(editor.getBody());
  901. var allSelection = serializeRng(allRng);
  902. return selection === allSelection;
  903. }
  904. editor.onKeyDown.add(function(editor, e) {
  905. var keyCode = e.keyCode, isCollapsed;
  906. // Empty the editor if it's needed for example backspace at <p><b>|</b></p>
  907. if (!isDefaultPrevented(e) && (keyCode == DELETE || keyCode == BACKSPACE)) {
  908. isCollapsed = editor.selection.isCollapsed();
  909. // Selection is collapsed but the editor isn't empty
  910. if (isCollapsed && !dom.isEmpty(editor.getBody())) {
  911. return;
  912. }
  913. // IE deletes all contents correctly when everything is selected
  914. if (tinymce.isIE && !isCollapsed) {
  915. return;
  916. }
  917. // Selection isn't collapsed but not all the contents is selected
  918. if (!isCollapsed && !allContentsSelected(editor.selection.getRng())) {
  919. return;
  920. }
  921. // Manually empty the editor
  922. editor.setContent('');
  923. editor.selection.setCursorLocation(editor.getBody(), 0);
  924. editor.nodeChanged();
  925. }
  926. });
  927. };
  928. function selectAll() {
  929. editor.onKeyDown.add(function(editor, e) {
  930. if (!isDefaultPrevented(e) && e.keyCode == 65 && VK.metaKeyPressed(e)) {
  931. e.preventDefault();
  932. editor.execCommand('SelectAll');
  933. }
  934. });
  935. };
  936. function inputMethodFocus() {
  937. if (!editor.settings.content_editable) {
  938. // Case 1 IME doesn't initialize if you focus the document
  939. dom.bind(editor.getDoc(), 'focusin', function(e) {
  940. selection.setRng(selection.getRng());
  941. });
  942. // Case 2 IME doesn't initialize if you click the documentElement it also doesn't properly fire the focusin event
  943. dom.bind(editor.getDoc(), 'mousedown', function(e) {
  944. if (e.target == editor.getDoc().documentElement) {
  945. editor.getWin().focus();
  946. selection.setRng(selection.getRng());
  947. }
  948. });
  949. }
  950. };
  951. function removeHrOnBackspace() {
  952. editor.onKeyDown.add(function(editor, e) {
  953. if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
  954. if (selection.isCollapsed() && selection.getRng(true).startOffset === 0) {
  955. var node = selection.getNode();
  956. var previousSibling = node.previousSibling;
  957. if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === "hr") {
  958. dom.remove(previousSibling);
  959. tinymce.dom.Event.cancel(e);
  960. }
  961. }
  962. }
  963. })
  964. }
  965. function focusBody() {
  966. // Fix for a focus bug in FF 3.x where the body element
  967. // wouldn't get proper focus if the user clicked on the HTML element
  968. if (!Range.prototype.getClientRects) { // Detect getClientRects got introduced in FF 4
  969. editor.onMouseDown.add(function(editor, e) {
  970. if (!isDefaultPrevented(e) && e.target.nodeName === "HTML") {
  971. var body = editor.getBody();
  972. // Blur the body it's focused but not correctly focused
  973. body.blur();
  974. // Refocus the body after a little while
  975. setTimeout(function() {
  976. body.focus();
  977. }, 0);
  978. }
  979. });
  980. }
  981. };
  982. function selectControlElements() {
  983. editor.onClick.add(function(editor, e) {
  984. e = e.target;
  985. // Workaround for bug, http://bugs.webkit.org/show_bug.cgi?id=12250
  986. // WebKit can't even do simple things like selecting an image
  987. // Needs tobe the setBaseAndExtend or it will fail to select floated images
  988. if (/^(IMG|HR)$/.test(e.nodeName)) {
  989. selection.getSel().setBaseAndExtent(e, 0, e, 1);
  990. }
  991. if (e.nodeName == 'A' && dom.hasClass(e, 'mceItemAnchor')) {
  992. selection.select(e);
  993. }
  994. editor.nodeChanged();
  995. });
  996. };
  997. function removeStylesWhenDeletingAccrossBlockElements() {
  998. function getAttributeApplyFunction() {
  999. var template = dom.getAttribs(selection.getStart().cloneNode(false));
  1000. return function() {
  1001. var target = selection.getStart();
  1002. if (target !== editor.getBody()) {
  1003. dom.setAttrib(target, "style", null);
  1004. each(template, function(attr) {
  1005. target.setAttributeNode(attr.cloneNode(true));
  1006. });
  1007. }
  1008. };
  1009. }
  1010. function isSelectionAcrossElements() {
  1011. return !selection.isCollapsed() && dom.getParent(selection.getStart(), dom.isBlock) != dom.getParent(selection.getEnd(), dom.isBlock);
  1012. }
  1013. function blockEvent(editor, e) {
  1014. e.preventDefault();
  1015. return false;
  1016. }
  1017. editor.onKeyPress.add(function(editor, e) {
  1018. var applyAttributes;
  1019. if (!isDefaultPrevented(e) && (e.keyCode == 8 || e.keyCode == 46) && isSelectionAcrossElements()) {
  1020. applyAttributes = getAttributeApplyFunction();
  1021. editor.getDoc().execCommand('delete', false, null);
  1022. applyAttributes();
  1023. e.preventDefault();
  1024. return false;
  1025. }
  1026. });
  1027. dom.bind(editor.getDoc(), 'cut', function(e) {
  1028. var applyAttributes;
  1029. if (!isDefaultPrevented(e) && isSelectionAcrossElements()) {
  1030. applyAttributes = getAttributeApplyFunction();
  1031. editor.onKeyUp.addToTop(blockEvent);
  1032. setTimeout(function() {
  1033. applyAttributes();
  1034. editor.onKeyUp.remove(blockEvent);
  1035. }, 0);
  1036. }
  1037. });
  1038. }
  1039. function selectionChangeNodeChanged() {
  1040. var lastRng, selectionTimer;
  1041. dom.bind(editor.getDoc(), 'selectionchange', function() {
  1042. if (selectionTimer) {
  1043. clearTimeout(selectionTimer);
  1044. selectionTimer = 0;
  1045. }
  1046. selectionTimer = window.setTimeout(function() {
  1047. var rng = selection.getRng();
  1048. // Compare the ranges to see if it was a real change or not
  1049. if (!lastRng || !tinymce.dom.RangeUtils.compareRanges(rng, lastRng)) {
  1050. editor.nodeChanged();
  1051. lastRng = rng;
  1052. }
  1053. }, 50);
  1054. });
  1055. }
  1056. function ensureBodyHasRoleApplication() {
  1057. document.body.setAttribute("role", "application");
  1058. }
  1059. function disableBackspaceIntoATable() {
  1060. editor.onKeyDown.add(function(editor, e) {
  1061. if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
  1062. if (selection.isCollapsed() && selection.getRng(true).startOffset === 0) {
  1063. var previousSibling = selection.getNode().previousSibling;
  1064. if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === "table") {
  1065. return tinymce.dom.Event.cancel(e);
  1066. }
  1067. }
  1068. }
  1069. })
  1070. }
  1071. function addNewLinesBeforeBrInPre() {
  1072. // IE8+ rendering mode does the right thing with BR in PRE
  1073. if (getDocumentMode() > 7) {
  1074. return;
  1075. }
  1076. // Enable display: none in area and add a specific class that hides all BR elements in PRE to
  1077. // avoid the caret from getting stuck at the BR elements while pressing the right arrow key
  1078. setEditorCommandState('RespectVisibilityInDesign', true);
  1079. editor.contentStyles.push('.mceHideBrInPre pre br {display: none}');
  1080. dom.addClass(editor.getBody(), 'mceHideBrInPre');
  1081. // Adds a \n before all BR elements in PRE to get them visual
  1082. parser.addNodeFilter('pre', function(nodes, name) {
  1083. var i = nodes.length, brNodes, j, brElm, sibling;
  1084. while (i--) {
  1085. brNodes = nodes[i].getAll('br');
  1086. j = brNodes.length;
  1087. while (j--) {
  1088. brElm = brNodes[j];
  1089. // Add \n before BR in PRE elements on older IE:s so the new lines get rendered
  1090. sibling = brElm.prev;
  1091. if (sibling && sibling.type === 3 && sibling.value.charAt(sibling.value - 1) != '\n') {
  1092. sibling.value += '\n';
  1093. } else {
  1094. brElm.parent.insert(new tinymce.html.Node('#text', 3), brElm, true).value = '\n';
  1095. }
  1096. }
  1097. }
  1098. });
  1099. // Removes any \n before BR elements in PRE since other browsers and in contentEditable=false mode they will be visible
  1100. serializer.addNodeFilter('pre', function(nodes, name) {
  1101. var i = nodes.length, brNodes, j, brElm, sibling;
  1102. while (i--) {
  1103. brNodes = nodes[i].getAll('br');
  1104. j = brNodes.length;
  1105. while (j--) {
  1106. brElm = brNodes[j];
  1107. sibling = brElm.prev;
  1108. if (sibling && sibling.type == 3) {
  1109. sibling.value = sibling.value.replace(/\r?\n$/, '');
  1110. }
  1111. }
  1112. }
  1113. });
  1114. }
  1115. function removePreSerializedStylesWhenSelectingControls() {
  1116. dom.bind(editor.getBody(), 'mouseup', function(e) {
  1117. var value, node = selection.getNode();
  1118. // Moved styles to attributes on IMG eements
  1119. if (node.nodeName == 'IMG') {
  1120. // Convert style width to width attribute
  1121. if (value = dom.getStyle(node, 'width')) {
  1122. dom.setAttrib(node, 'width', value.replace(/[^0-9%]+/g, ''));
  1123. dom.setStyle(node, 'width', '');
  1124. }
  1125. // Convert style height to height attribute
  1126. if (value = dom.getStyle(node, 'height')) {
  1127. dom.setAttrib(node, 'height', value.replace(/[^0-9%]+/g, ''));
  1128. dom.setStyle(node, 'height', '');
  1129. }
  1130. }
  1131. });
  1132. }
  1133. function keepInlineElementOnDeleteBackspace() {
  1134. editor.onKeyDown.add(function(editor, e) {
  1135. var isDelete, rng, container, offset, brElm, sibling, collapsed;
  1136. isDelete = e.keyCode == DELETE;
  1137. if (!isDefaultPrevented(e) && (isDelete || e.keyCode == BACKSPACE) && !VK.modifierPressed(e)) {
  1138. rng = selection.getRng();
  1139. container = rng.startContainer;
  1140. offset = rng.startOffset;
  1141. collapsed = rng.collapsed;
  1142. // Override delete if the start container is a text node and is at the beginning of text or
  1143. // just before/after the last character to be deleted in collapsed mode
  1144. if (container.nodeType == 3 && container.nodeValue.length > 0 && ((offset === 0 && !collapsed) || (collapsed && offset === (isDelete ? 0 : 1)))) {
  1145. nonEmptyElements = editor.schema.getNonEmptyElements();
  1146. // Prevent default logic since it's broken
  1147. e.preventDefault();
  1148. // Insert a BR before the text node this will prevent the containing element from being deleted/converted
  1149. brElm = dom.create('br', {id: '__tmp'});
  1150. container.parentNode.insertBefore(brElm, container);
  1151. // Do the browser delete
  1152. editor.getDoc().execCommand(isDelete ? 'ForwardDelete' : 'Delete', false, null);
  1153. // Check if the previous sibling is empty after deleting for example: <p><b></b>|</p>
  1154. container = selection.getRng().startContainer;
  1155. sibling = container.previousSibling;
  1156. if (sibling && sibling.nodeType == 1 && !dom.isBlock(sibling) && dom.isEmpty(sibling) && !nonEmptyElements[sibling.nodeName.toLowerCase()]) {
  1157. dom.remove(sibling);
  1158. }
  1159. // Remove the temp element we inserted
  1160. dom.remove('__tmp');
  1161. }
  1162. }
  1163. });
  1164. }
  1165. function removeBlockQuoteOnBackSpace() {
  1166. // Add block quote deletion handler
  1167. editor.onKeyDown.add(function(editor, e) {
  1168. var rng, container, offset, root, parent;
  1169. if (isDefaultPrevented(e) || e.keyCode != VK.BACKSPACE) {
  1170. return;
  1171. }
  1172. rng = selection.getRng();
  1173. container = rng.startContainer;
  1174. offset = rng.startOffset;
  1175. root = dom.getRoot();
  1176. parent = container;
  1177. if (!rng.collapsed || offset !== 0) {
  1178. return;
  1179. }
  1180. while (parent && parent.parentNode && parent.parentNode.firstChild == parent && parent.parentNode != root) {
  1181. parent = parent.parentNode;
  1182. }
  1183. // Is the cursor at the beginning of a blockquote?
  1184. if (parent.tagName === 'BLOCKQUOTE') {
  1185. // Remove the blockquote
  1186. editor.formatter.toggle('blockquote', null, parent);
  1187. // Move the caret to the beginning of container
  1188. rng = dom.createRng();
  1189. rng.setStart(container, 0);
  1190. rng.setEnd(container, 0);
  1191. selection.setRng(rng);
  1192. }
  1193. });
  1194. };
  1195. function setGeckoEditingOptions() {
  1196. function setOpts() {
  1197. editor._refreshContentEditable();
  1198. setEditorCommandState("StyleWithCSS", false);
  1199. setEditorCommandState("enableInlineTableEditing", false);
  1200. if (!settings.object_resizing) {
  1201. setEditorCommandState("enableObjectResizing", false);
  1202. }
  1203. };
  1204. if (!settings.readonly) {
  1205. editor.onBeforeExecCommand.add(setOpts);
  1206. editor.onMouseDown.add(setOpts);
  1207. }
  1208. };
  1209. function addBrAfterLastLinks() {
  1210. function fixLinks(editor, o) {
  1211. each(dom.select('a'), function(node) {
  1212. var parentNode = node.parentNode, root = dom.getRoot();
  1213. if (parentNode.lastChild === node) {
  1214. while (parentNode && !dom.isBlock(parentNode)) {
  1215. if (parentNode.parentNode.lastChild !== parentNode || parentNode === root) {
  1216. return;
  1217. }
  1218. parentNode = parentNode.parentNode;
  1219. }
  1220. dom.add(parentNode, 'br', {'data-mce-bogus' : 1});
  1221. }
  1222. });
  1223. };
  1224. editor.onExecCommand.add(function(editor, cmd) {
  1225. if (cmd === 'CreateLink') {
  1226. fixLinks(editor);
  1227. }
  1228. });
  1229. editor.onSetContent.add(selection.onSetContent.add(fixLinks));
  1230. };
  1231. function setDefaultBlockType() {
  1232. if (settings.forced_root_block) {
  1233. editor.onInit.add(function() {
  1234. setEditorCommandState('DefaultParagraphSeparator', settings.forced_root_block);
  1235. });
  1236. }
  1237. }
  1238. function removeGhostSelection() {
  1239. function repaint(sender, args) {
  1240. if (!sender || !args.initial) {
  1241. editor.execCommand('mceRepaint');
  1242. }
  1243. };
  1244. editor.onUndo.add(repaint);
  1245. editor.onRedo.add(repaint);
  1246. editor.onSetContent.add(repaint);
  1247. };
  1248. function deleteControlItemOnBackSpace() {
  1249. editor.onKeyDown.add(function(editor, e) {
  1250. var rng;
  1251. if (!isDefaultPrevented(e) && e.keyCode == BACKSPACE) {
  1252. rng = editor.getDoc().selection.createRange();
  1253. if (rng && rng.item) {
  1254. e.preventDefault();
  1255. editor.undoManager.beforeChange();
  1256. dom.remove(rng.item(0));
  1257. editor.undoManager.add();
  1258. }
  1259. }
  1260. });
  1261. };
  1262. function renderEmptyBlocksFix() {
  1263. var emptyBlocksCSS;
  1264. // IE10+
  1265. if (getDocumentMode() >= 10) {
  1266. emptyBlocksCSS = '';
  1267. each('p div h1 h2 h3 h4 h5 h6'.split(' '), function(name, i) {
  1268. emptyBlocksCSS += (i > 0 ? ',' : '') + name + ':empty';
  1269. });
  1270. editor.contentStyles.push(emptyBlocksCSS + '{padding-right: 1px !important}');
  1271. }
  1272. };
  1273. function fakeImageResize() {
  1274. var selectedElmX, selectedElmY, selectedElm, selectedElmGhost, selectedHandle, startX, startY, startW, startH, ratio,
  1275. resizeHandles, width, height, rootDocument = document, editableDoc = editor.getDoc();
  1276. if (!settings.object_resizing || settings.webkit_fake_resize === false) {
  1277. return;
  1278. }
  1279. // Try disabling object resizing if WebKit implements resizing in the future
  1280. setEditorCommandState("enableObjectResizing", false);
  1281. // Details about each resize handle how to scale etc
  1282. resizeHandles = {
  1283. // Name: x multiplier, y multiplier, delta size x, delta size y
  1284. n: [.5, 0, 0, -1],
  1285. e: [1, .5, 1, 0],
  1286. s: [.5, 1, 0, 1],
  1287. w: [0, .5, -1, 0],
  1288. nw: [0, 0, -1, -1],
  1289. ne: [1, 0, 1, -1],
  1290. se: [1, 1, 1, 1],
  1291. sw : [0, 1, -1, 1]
  1292. };
  1293. function resizeElement(e) {
  1294. var deltaX, deltaY;
  1295. // Calc new width/height
  1296. deltaX = e.screenX - startX;
  1297. deltaY = e.screenY - startY;
  1298. // Calc new size
  1299. width = deltaX * selectedHandle[2] + startW;
  1300. height = deltaY * selectedHandle[3] + startH;
  1301. // Never scale down lower than 5 pixels
  1302. width = width < 5 ? 5 : width;
  1303. height = height < 5 ? 5 : height;
  1304. // Constrain proportions when modifier key is pressed or if the nw, ne, sw, se corners are moved on an image
  1305. if (VK.modifierPressed(e) || (selectedElm.nodeName == "IMG" && selectedHandle[2] * selectedHandle[3] !== 0)) {
  1306. width = Math.round(height / ratio);
  1307. height = Math.round(width * ratio);
  1308. }
  1309. // Update ghost size
  1310. dom.setStyles(selectedElmGhost, {
  1311. width: width,
  1312. height: height
  1313. });
  1314. // Update ghost X position if needed
  1315. if (selectedHandle[2] < 0 && selectedElmGhost.clientWidth <= width) {
  1316. dom.setStyle(selectedElmGhost, 'left', selectedElmX + (startW - width));
  1317. }
  1318. // Update ghost Y position if needed
  1319. if (selectedHandle[3] < 0 && selectedElmGhost.clientHeight <= height) {
  1320. dom.setStyle(selectedElmGhost, 'top', selectedElmY + (startH - height));
  1321. }
  1322. }
  1323. function endResize() {
  1324. function setSizeProp(name, value) {
  1325. if (value) {
  1326. // Resize by using style or attribute
  1327. if (selectedElm.style[name] || !editor.schema.isValid(selectedElm.nodeName.toLowerCase(), name)) {
  1328. dom.setStyle(selectedElm, name, value);
  1329. } else {
  1330. dom.setAttrib(selectedElm, name, value);
  1331. }
  1332. }
  1333. }
  1334. // Set width/height properties
  1335. setSizeProp('width', width);
  1336. setSizeProp('height', height);
  1337. dom.unbind(editableDoc, 'mousemove', resizeElement);
  1338. dom.unbind(editableDoc, 'mouseup', endResize);
  1339. if (rootDocument != editableDoc) {
  1340. dom.unbind(rootDocument, 'mousemove', resizeElement);
  1341. dom.unbind(rootDocument, 'mouseup', endResize);
  1342. }
  1343. // Remove ghost and update resize handle positions
  1344. dom.remove(selectedElmGhost);
  1345. showResizeRect(selectedElm);
  1346. }
  1347. function showResizeRect(targetElm) {
  1348. var position, targetWidth, targetHeight;
  1349. hideResizeRect();
  1350. // Get position and size of target
  1351. position = dom.getPos(targetElm);
  1352. selectedElmX = position.x;
  1353. selectedElmY = position.y;
  1354. targetWidth = targetElm.offsetWidth;
  1355. targetHeight = targetElm.offsetHeight;
  1356. // Reset width/height if user selects a new image/table
  1357. if (selectedElm != targetElm) {
  1358. selectedElm = targetElm;
  1359. width = height = 0;
  1360. }
  1361. each(resizeHandles, function(handle, name) {
  1362. var handleElm;
  1363. // Get existing or render resize handle
  1364. handleElm = dom.get('mceResizeHandle' + name);
  1365. if (!handleElm) {
  1366. handleElm = dom.add(editableDoc.documentElement, 'div', {
  1367. id: 'mceResizeHandle' + name,
  1368. 'class': 'mceResizeHandle',
  1369. style: 'cursor:' + name + '-resize; margin:0; padding:0'
  1370. });
  1371. dom.bind(handleElm, 'mousedown', function(e) {
  1372. e.preventDefault();
  1373. endResize();
  1374. startX = e.screenX;
  1375. startY = e.screenY;
  1376. startW = selectedElm.clientWidth;
  1377. startH = selectedElm.clientHeight;
  1378. ratio = startH / startW;
  1379. selectedHandle = handle;
  1380. selectedElmGhost = selectedElm.cloneNode(true);
  1381. dom.addClass(selectedElmGhost, 'mceClonedResizable');
  1382. dom.setStyles(selectedElmGhost, {
  1383. left: selectedElmX,
  1384. top: selectedElmY,
  1385. margin: 0
  1386. });
  1387. editableDoc.documentElement.appendChild(selectedElmGhost);
  1388. dom.bind(editableDoc, 'mousemove', resizeElement);
  1389. dom.bind(editableDoc, 'mouseup', endResize);
  1390. if (rootDocument != editableDoc) {
  1391. dom.bind(rootDocument, 'mousemove', resizeElement);
  1392. dom.bind(rootDocument, 'mouseup', endResize);
  1393. }
  1394. });
  1395. } else {
  1396. dom.show(handleElm);
  1397. }
  1398. // Position element
  1399. dom.setStyles(handleElm, {
  1400. left: (targetWidth * handle[0] + selectedElmX) - (handleElm.offsetWidth / 2),
  1401. top: (targetHeight * handle[1] + selectedElmY) - (handleElm.offsetHeight / 2)
  1402. });
  1403. });
  1404. // Only add resize rectangle on WebKit and only on images
  1405. if (!tinymce.isOpera && selectedElm.nodeName == "IMG") {
  1406. selectedElm.setAttribute('data-mce-selected', '1');
  1407. }
  1408. }
  1409. function hideResizeRect() {
  1410. if (selectedElm) {
  1411. selectedElm.removeAttribute('data-mce-selected');
  1412. }
  1413. for (var name in resizeHandles) {
  1414. dom.hide('mceResizeHandle' + name);
  1415. }
  1416. }
  1417. // Add CSS for resize handles, cloned element and selected
  1418. editor.contentStyles.push(
  1419. '.mceResizeHandle {' +
  1420. 'position: absolute;' +
  1421. 'border: 1px solid black;' +
  1422. 'background: #FFF;' +
  1423. 'width: 5px;' +
  1424. 'height: 5px;' +
  1425. 'z-index: 10000' +
  1426. '}' +
  1427. '.mceResizeHandle:hover {' +
  1428. 'background: #000' +
  1429. '}' +
  1430. 'img[data-mce-selected] {' +
  1431. 'outline: 1px solid black' +
  1432. '}' +
  1433. 'img.mceClonedResizable, table.mceClonedResizable {' +
  1434. 'position: absolute;' +
  1435. 'outline: 1px dashed black;' +
  1436. 'opacity: .5;' +
  1437. 'z-index: 10000' +
  1438. '}'
  1439. );
  1440. function updateResizeRect() {
  1441. var controlElm = dom.getParent(selection.getNode(), 'table,img');
  1442. // Remove data-mce-selected from all elements since they might have been copied using Ctrl+c/v
  1443. each(dom.select('img[data-mce-selected]'), function(img) {
  1444. img.removeAttribute('data-mce-selected');
  1445. });
  1446. if (controlElm) {
  1447. showResizeRect(controlElm);
  1448. } else {
  1449. hideResizeRect();
  1450. }
  1451. }
  1452. // Show/hide resize rect when image is selected
  1453. editor.onNodeChange.add(updateResizeRect);
  1454. // Fixes WebKit quirk where it returns IMG on getNode if caret is after last image in container
  1455. dom.bind(editableDoc, 'selectionchange', updateResizeRect);
  1456. // Remove the internal attribute when serializing the DOM
  1457. editor.serializer.addAttributeFilter('data-mce-selected', function(nodes, name) {
  1458. var i = nodes.length;
  1459. while (i--) {
  1460. nodes[i].attr(name, null);
  1461. }
  1462. });
  1463. }
  1464. function keepNoScriptContents() {
  1465. if (getDocumentMode() < 9) {
  1466. parser.addNodeFilter('noscript', function(nodes) {
  1467. var i = nodes.length, node, textNode;
  1468. while (i--) {
  1469. node = nodes[i];
  1470. textNode = node.firstChild;
  1471. if (textNode) {
  1472. node.attr('data-mce-innertext', textNode.value);
  1473. }
  1474. }
  1475. });
  1476. serializer.addNodeFilter('noscript', function(nodes) {
  1477. var i = nodes.length, node, textNode, value;
  1478. while (i--) {
  1479. node = nodes[i];
  1480. textNode = nodes[i].firstChild;
  1481. if (textNode) {
  1482. textNode.value = tinymce.html.Entities.decode(textNode.value);
  1483. } else {
  1484. // Old IE can't retain noscript value so an attribute is used to store it
  1485. value = node.attributes.map['data-mce-innertext'];
  1486. if (value) {
  1487. node.attr('data-mce-innertext', null);
  1488. textNode = new tinymce.html.Node('#text', 3);
  1489. textNode.value = value;
  1490. textNode.raw = true;
  1491. node.append(textNode);
  1492. }
  1493. }
  1494. }
  1495. });
  1496. }
  1497. }
  1498. // All browsers
  1499. disableBackspaceIntoATable();
  1500. removeBlockQuoteOnBackSpace();
  1501. emptyEditorWhenDeleting();
  1502. // WebKit
  1503. if (tinymce.isWebKit) {
  1504. keepInlineElementOnDeleteBackspace();
  1505. cleanupStylesWhenDeleting();
  1506. inputMethodFocus();
  1507. selectControlElements();
  1508. setDefaultBlockType();
  1509. // iOS
  1510. if (tinymce.isIDevice) {
  1511. selectionChangeNodeChanged();
  1512. } else {
  1513. fakeImageResize();
  1514. selectAll();
  1515. }
  1516. }
  1517. // IE
  1518. if (tinymce.isIE) {
  1519. removeHrOnBackspace();
  1520. ensureBodyHasRoleApplication();
  1521. addNewLinesBeforeBrInPre();
  1522. removePreSerializedStylesWhenSelectingControls();
  1523. deleteControlItemOnBackSpace();
  1524. renderEmptyBlocksFix();
  1525. keepNoScriptContents();
  1526. }
  1527. // Gecko
  1528. if (tinymce.isGecko) {
  1529. removeHrOnBackspace();
  1530. focusBody();
  1531. removeStylesWhenDeletingAccrossBlockElements();
  1532. setGeckoEditingOptions();
  1533. addBrAfterLastLinks();
  1534. removeGhostSelection();
  1535. }
  1536. // Opera
  1537. if (tinymce.isOpera) {
  1538. fakeImageResize();
  1539. }
  1540. };
  1541. (function(tinymce) {
  1542. var namedEntities, baseEntities, reverseEntities,
  1543. attrsCharsRegExp = /[&<>\"\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  1544. textCharsRegExp = /[<>&\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  1545. rawCharsRegExp = /[<>&\"\']/g,
  1546. entityRegExp = /&(#x|#)?([\w]+);/g,
  1547. asciiMap = {
  1548. 128 : "\u20AC", 130 : "\u201A", 131 : "\u0192", 132 : "\u201E", 133 : "\u2026", 134 : "\u2020",
  1549. 135 : "\u2021", 136 : "\u02C6", 137 : "\u2030", 138 : "\u0160", 139 : "\u2039", 140 : "\u0152",
  1550. 142 : "\u017D", 145 : "\u2018", 146 : "\u2019", 147 : "\u201C", 148 : "\u201D", 149 : "\u2022",
  1551. 150 : "\u2013", 151 : "\u2014", 152 : "\u02DC", 153 : "\u2122", 154 : "\u0161", 155 : "\u203A",
  1552. 156 : "\u0153", 158 : "\u017E", 159 : "\u0178"
  1553. };
  1554. // Raw entities
  1555. baseEntities = {
  1556. '\"' : '&quot;', // Needs to be escaped since the YUI compressor would otherwise break the code
  1557. "'" : '&#39;',
  1558. '<' : '&lt;',
  1559. '>' : '&gt;',
  1560. '&' : '&amp;'
  1561. };
  1562. // Reverse lookup table for raw entities
  1563. reverseEntities = {
  1564. '&lt;' : '<',
  1565. '&gt;' : '>',
  1566. '&amp;' : '&',
  1567. '&quot;' : '"',
  1568. '&apos;' : "'"
  1569. };
  1570. // Decodes text by using the browser
  1571. function nativeDecode(text) {
  1572. var elm;
  1573. elm = document.createElement("div");
  1574. elm.innerHTML = text;
  1575. return elm.textContent || elm.innerText || text;
  1576. };
  1577. // Build a two way lookup table for the entities
  1578. function buildEntitiesLookup(items, radix) {
  1579. var i, chr, entity, lookup = {};
  1580. if (items) {
  1581. items = items.split(',');
  1582. radix = radix || 10;
  1583. // Build entities lookup table
  1584. for (i = 0; i < items.length; i += 2) {
  1585. chr = String.fromCharCode(parseInt(items[i], radix));
  1586. // Only add non base entities
  1587. if (!baseEntities[chr]) {
  1588. entity = '&' + items[i + 1] + ';';
  1589. lookup[chr] = entity;
  1590. lookup[entity] = chr;
  1591. }
  1592. }
  1593. return lookup;
  1594. }
  1595. };
  1596. // Unpack entities lookup where the numbers are in radix 32 to reduce the size
  1597. namedEntities = buildEntitiesLookup(
  1598. '50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,' +
  1599. '5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,' +
  1600. '5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,' +
  1601. '5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,' +
  1602. '68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,' +
  1603. '6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,' +
  1604. '6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,' +
  1605. '75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,' +
  1606. '7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,' +
  1607. '7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,' +
  1608. 'sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,' +
  1609. 'st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,' +
  1610. 't9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,' +
  1611. 'tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,' +
  1612. 'u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,' +
  1613. '81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,' +
  1614. '8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,' +
  1615. '8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,' +
  1616. '8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,' +
  1617. '8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,' +
  1618. 'nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,' +
  1619. 'rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,' +
  1620. 'Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,' +
  1621. '80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,' +
  1622. '811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro', 32);
  1623. tinymce.html = tinymce.html || {};
  1624. tinymce.html.Entities = {
  1625. encodeRaw : function(text, attr) {
  1626. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1627. return baseEntities[chr] || chr;
  1628. });
  1629. },
  1630. encodeAllRaw : function(text) {
  1631. return ('' + text).replace(rawCharsRegExp, function(chr) {
  1632. return baseEntities[chr] || chr;
  1633. });
  1634. },
  1635. encodeNumeric : function(text, attr) {
  1636. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1637. // Multi byte sequence convert it to a single entity
  1638. if (chr.length > 1)
  1639. return '&#' + (((chr.charCodeAt(0) - 0xD800) * 0x400) + (chr.charCodeAt(1) - 0xDC00) + 0x10000) + ';';
  1640. return baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';';
  1641. });
  1642. },
  1643. encodeNamed : function(text, attr, entities) {
  1644. entities = entities || namedEntities;
  1645. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1646. return baseEntities[chr] || entities[chr] || chr;
  1647. });
  1648. },
  1649. getEncodeFunc : function(name, entities) {
  1650. var Entities = tinymce.html.Entities;
  1651. entities = buildEntitiesLookup(entities) || namedEntities;
  1652. function encodeNamedAndNumeric(text, attr) {
  1653. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1654. return baseEntities[chr] || entities[chr] || '&#' + chr.charCodeAt(0) + ';' || chr;
  1655. });
  1656. };
  1657. function encodeCustomNamed(text, attr) {
  1658. return Entities.encodeNamed(text, attr, entities);
  1659. };
  1660. // Replace + with , to be compatible with previous TinyMCE versions
  1661. name = tinymce.makeMap(name.replace(/\+/g, ','));
  1662. // Named and numeric encoder
  1663. if (name.named && name.numeric)
  1664. return encodeNamedAndNumeric;
  1665. // Named encoder
  1666. if (name.named) {
  1667. // Custom names
  1668. if (entities)
  1669. return encodeCustomNamed;
  1670. return Entities.encodeNamed;
  1671. }
  1672. // Numeric
  1673. if (name.numeric)
  1674. return Entities.encodeNumeric;
  1675. // Raw encoder
  1676. return Entities.encodeRaw;
  1677. },
  1678. decode : function(text) {
  1679. return text.replace(entityRegExp, function(all, numeric, value) {
  1680. if (numeric) {
  1681. value = parseInt(value, numeric.length === 2 ? 16 : 10);
  1682. // Support upper UTF
  1683. if (value > 0xFFFF) {
  1684. value -= 0x10000;
  1685. return String.fromCharCode(0xD800 + (value >> 10), 0xDC00 + (value & 0x3FF));
  1686. } else
  1687. return asciiMap[value] || String.fromCharCode(value);
  1688. }
  1689. return reverseEntities[all] || namedEntities[all] || nativeDecode(all);
  1690. });
  1691. }
  1692. };
  1693. })(tinymce);
  1694. tinymce.html.Styles = function(settings, schema) {
  1695. var rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi,
  1696. urlOrStrRegExp = /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi,
  1697. styleRegExp = /\s*([^:]+):\s*([^;]+);?/g,
  1698. trimRightRegExp = /\s+$/,
  1699. urlColorRegExp = /rgb/,
  1700. undef, i, encodingLookup = {}, encodingItems;
  1701. settings = settings || {};
  1702. encodingItems = '\\" \\\' \\; \\: ; : \uFEFF'.split(' ');
  1703. for (i = 0; i < encodingItems.length; i++) {
  1704. encodingLookup[encodingItems[i]] = '\uFEFF' + i;
  1705. encodingLookup['\uFEFF' + i] = encodingItems[i];
  1706. }
  1707. function toHex(match, r, g, b) {
  1708. function hex(val) {
  1709. val = parseInt(val).toString(16);
  1710. return val.length > 1 ? val : '0' + val; // 0 -> 00
  1711. };
  1712. return '#' + hex(r) + hex(g) + hex(b);
  1713. };
  1714. return {
  1715. toHex : function(color) {
  1716. return color.replace(rgbRegExp, toHex);
  1717. },
  1718. parse : function(css) {
  1719. var styles = {}, matches, name, value, isEncoded, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope || this;
  1720. function compress(prefix, suffix) {
  1721. var top, right, bottom, left;
  1722. // Get values and check it it needs compressing
  1723. top = styles[prefix + '-top' + suffix];
  1724. if (!top)
  1725. return;
  1726. right = styles[prefix + '-right' + suffix];
  1727. if (top != right)
  1728. return;
  1729. bottom = styles[prefix + '-bottom' + suffix];
  1730. if (right != bottom)
  1731. return;
  1732. left = styles[prefix + '-left' + suffix];
  1733. if (bottom != left)
  1734. return;
  1735. // Compress
  1736. styles[prefix + suffix] = left;
  1737. delete styles[prefix + '-top' + suffix];
  1738. delete styles[prefix + '-right' + suffix];
  1739. delete styles[prefix + '-bottom' + suffix];
  1740. delete styles[prefix + '-left' + suffix];
  1741. };
  1742. function canCompress(key) {
  1743. var value = styles[key], i;
  1744. if (!value || value.indexOf(' ') < 0)
  1745. return;
  1746. value = value.split(' ');
  1747. i = value.length;
  1748. while (i--) {
  1749. if (value[i] !== value[0])
  1750. return false;
  1751. }
  1752. styles[key] = value[0];
  1753. return true;
  1754. };
  1755. function compress2(target, a, b, c) {
  1756. if (!canCompress(a))
  1757. return;
  1758. if (!canCompress(b))
  1759. return;
  1760. if (!canCompress(c))
  1761. return;
  1762. // Compress
  1763. styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c];
  1764. delete styles[a];
  1765. delete styles[b];
  1766. delete styles[c];
  1767. };
  1768. // Encodes the specified string by replacing all \" \' ; : with _<num>
  1769. function encode(str) {
  1770. isEncoded = true;
  1771. return encodingLookup[str];
  1772. };
  1773. // Decodes the specified string by replacing all _<num> with it's original value \" \' etc
  1774. // It will also decode the \" \' if keep_slashes is set to fale or omitted
  1775. function decode(str, keep_slashes) {
  1776. if (isEncoded) {
  1777. str = str.replace(/\uFEFF[0-9]/g, function(str) {
  1778. return encodingLookup[str];
  1779. });
  1780. }
  1781. if (!keep_slashes)
  1782. str = str.replace(/\\([\'\";:])/g, "$1");
  1783. return str;
  1784. };
  1785. function processUrl(match, url, url2, url3, str, str2) {
  1786. str = str || str2;
  1787. if (str) {
  1788. str = decode(str);
  1789. // Force strings into single quote format
  1790. return "'" + str.replace(/\'/g, "\\'") + "'";
  1791. }
  1792. url = decode(url || url2 || url3);
  1793. // Convert the URL to relative/absolute depending on config
  1794. if (urlConverter)
  1795. url = urlConverter.call(urlConverterScope, url, 'style');
  1796. // Output new URL format
  1797. return "url('" + url.replace(/\'/g, "\\'") + "')";
  1798. };
  1799. if (css) {
  1800. // Encode \" \' % and ; and : inside strings so they don't interfere with the style parsing
  1801. css = css.replace(/\\[\"\';:\uFEFF]/g, encode).replace(/\"[^\"]+\"|\'[^\']+\'/g, function(str) {
  1802. return str.replace(/[;:]/g, encode);
  1803. });
  1804. // Parse styles
  1805. while (matches = styleRegExp.exec(css)) {
  1806. name = matches[1].replace(trimRightRegExp, '').toLowerCase();
  1807. value = matches[2].replace(trimRightRegExp, '');
  1808. if (name && value.length > 0) {
  1809. // Opera will produce 700 instead of bold in their style values
  1810. if (name === 'font-weight' && value === '700')
  1811. value = 'bold';
  1812. else if (name === 'color' || name === 'background-color') // Lowercase colors like RED
  1813. value = value.toLowerCase();
  1814. // Convert RGB colors to HEX
  1815. value = value.replace(rgbRegExp, toHex);
  1816. // Convert URLs and force them into url('value') format
  1817. value = value.replace(urlOrStrRegExp, processUrl);
  1818. styles[name] = isEncoded ? decode(value, true) : value;
  1819. }
  1820. styleRegExp.lastIndex = matches.index + matches[0].length;
  1821. }
  1822. // Compress the styles to reduce it's size for example IE will expand styles
  1823. compress("border", "");
  1824. compress("border", "-width");
  1825. compress("border", "-color");
  1826. compress("border", "-style");
  1827. compress("padding", "");
  1828. compress("margin", "");
  1829. compress2('border', 'border-width', 'border-style', 'border-color');
  1830. // Remove pointless border, IE produces these
  1831. if (styles.border === 'medium none')
  1832. delete styles.border;
  1833. }
  1834. return styles;
  1835. },
  1836. serialize : function(styles, element_name) {
  1837. var css = '', name, value;
  1838. function serializeStyles(name) {
  1839. var styleList, i, l, value;
  1840. styleList = schema.styles[name];
  1841. if (styleList) {
  1842. for (i = 0, l = styleList.length; i < l; i++) {
  1843. name = styleList[i];
  1844. value = styles[name];
  1845. if (value !== undef && value.length > 0)
  1846. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  1847. }
  1848. }
  1849. };
  1850. // Serialize styles according to schema
  1851. if (element_name && schema && schema.styles) {
  1852. // Serialize global styles and element specific styles
  1853. serializeStyles('*');
  1854. serializeStyles(element_name);
  1855. } else {
  1856. // Output the styles in the order they are inside the object
  1857. for (name in styles) {
  1858. value = styles[name];
  1859. if (value !== undef && value.length > 0)
  1860. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  1861. }
  1862. }
  1863. return css;
  1864. }
  1865. };
  1866. };
  1867. (function(tinymce) {
  1868. var mapCache = {}, makeMap = tinymce.makeMap, each = tinymce.each;
  1869. function split(str, delim) {
  1870. return str.split(delim || ',');
  1871. };
  1872. function unpack(lookup, data) {
  1873. var key, elements = {};
  1874. function replace(value) {
  1875. return value.replace(/[A-Z]+/g, function(key) {
  1876. return replace(lookup[key]);
  1877. });
  1878. };
  1879. // Unpack lookup
  1880. for (key in lookup) {
  1881. if (lookup.hasOwnProperty(key))
  1882. lookup[key] = replace(lookup[key]);
  1883. }
  1884. // Unpack and parse data into object map
  1885. replace(data).replace(/#/g, '#text').replace(/(\w+)\[([^\]]+)\]\[([^\]]*)\]/g, function(str, name, attributes, children) {
  1886. attributes = split(attributes, '|');
  1887. elements[name] = {
  1888. attributes : makeMap(attributes),
  1889. attributesOrder : attributes,
  1890. children : makeMap(children, '|', {'#comment' : {}})
  1891. }
  1892. });
  1893. return elements;
  1894. };
  1895. function getHTML5() {
  1896. var html5 = mapCache.html5;
  1897. if (!html5) {
  1898. html5 = mapCache.html5 = unpack({
  1899. A : 'id|accesskey|class|dir|draggable|item|hidden|itemprop|role|spellcheck|style|subject|title|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup',
  1900. B : '#|a|abbr|area|audio|b|bdo|br|button|canvas|cite|code|command|datalist|del|dfn|em|embed|i|iframe|img|input|ins|kbd|keygen|label|link|map|mark|meta|' +
  1901. 'meter|noscript|object|output|progress|q|ruby|samp|script|select|small|span|strong|sub|sup|svg|textarea|time|var|video|wbr',
  1902. C : '#|a|abbr|area|address|article|aside|audio|b|bdo|blockquote|br|button|canvas|cite|code|command|datalist|del|details|dfn|dialog|div|dl|em|embed|fieldset|' +
  1903. 'figure|footer|form|h1|h2|h3|h4|h5|h6|header|hgroup|hr|i|iframe|img|input|ins|kbd|keygen|label|link|map|mark|menu|meta|meter|nav|noscript|ol|object|output|' +
  1904. 'p|pre|progress|q|ruby|samp|script|section|select|small|span|strong|style|sub|sup|svg|table|textarea|time|ul|var|video'
  1905. }, 'html[A|manifest][body|head]' +
  1906. 'head[A][base|command|link|meta|noscript|script|style|title]' +
  1907. 'title[A][#]' +
  1908. 'base[A|href|target][]' +
  1909. 'link[A|href|rel|media|type|sizes][]' +
  1910. 'meta[A|http-equiv|name|content|charset][]' +
  1911. 'style[A|type|media|scoped][#]' +
  1912. 'script[A|charset|type|src|defer|async][#]' +
  1913. 'noscript[A][C]' +
  1914. 'body[A][C]' +
  1915. 'section[A][C]' +
  1916. 'nav[A][C]' +
  1917. 'article[A][C]' +
  1918. 'aside[A][C]' +
  1919. 'h1[A][B]' +
  1920. 'h2[A][B]' +
  1921. 'h3[A][B]' +
  1922. 'h4[A][B]' +
  1923. 'h5[A][B]' +
  1924. 'h6[A][B]' +
  1925. 'hgroup[A][h1|h2|h3|h4|h5|h6]' +
  1926. 'header[A][C]' +
  1927. 'footer[A][C]' +
  1928. 'address[A][C]' +
  1929. 'p[A][B]' +
  1930. 'br[A][]' +
  1931. 'pre[A][B]' +
  1932. 'dialog[A][dd|dt]' +
  1933. 'blockquote[A|cite][C]' +
  1934. 'ol[A|start|reversed][li]' +
  1935. 'ul[A][li]' +
  1936. 'li[A|value][C]' +
  1937. 'dl[A][dd|dt]' +
  1938. 'dt[A][B]' +
  1939. 'dd[A][C]' +
  1940. 'a[A|href|target|ping|rel|media|type][B]' +
  1941. 'em[A][B]' +
  1942. 'strong[A][B]' +
  1943. 'small[A][B]' +
  1944. 'cite[A][B]' +
  1945. 'q[A|cite][B]' +
  1946. 'dfn[A][B]' +
  1947. 'abbr[A][B]' +
  1948. 'code[A][B]' +
  1949. 'var[A][B]' +
  1950. 'samp[A][B]' +
  1951. 'kbd[A][B]' +
  1952. 'sub[A][B]' +
  1953. 'sup[A][B]' +
  1954. 'i[A][B]' +
  1955. 'b[A][B]' +
  1956. 'mark[A][B]' +
  1957. 'progress[A|value|max][B]' +
  1958. 'meter[A|value|min|max|low|high|optimum][B]' +
  1959. 'time[A|datetime][B]' +
  1960. 'ruby[A][B|rt|rp]' +
  1961. 'rt[A][B]' +
  1962. 'rp[A][B]' +
  1963. 'bdo[A][B]' +
  1964. 'span[A][B]' +
  1965. 'ins[A|cite|datetime][B]' +
  1966. 'del[A|cite|datetime][B]' +
  1967. 'figure[A][C|legend|figcaption]' +
  1968. 'figcaption[A][C]' +
  1969. 'img[A|alt|src|height|width|usemap|ismap][]' +
  1970. 'iframe[A|name|src|height|width|sandbox|seamless][]' +
  1971. 'embed[A|src|height|width|type][]' +
  1972. 'object[A|data|type|height|width|usemap|name|form|classid][param]' +
  1973. 'param[A|name|value][]' +
  1974. 'details[A|open][C|legend]' +
  1975. 'command[A|type|label|icon|disabled|checked|radiogroup][]' +
  1976. 'menu[A|type|label][C|li]' +
  1977. 'legend[A][C|B]' +
  1978. 'div[A][C]' +
  1979. 'source[A|src|type|media][]' +
  1980. 'audio[A|src|autobuffer|autoplay|loop|controls][source]' +
  1981. 'video[A|src|autobuffer|autoplay|loop|controls|width|height|poster][source]' +
  1982. 'hr[A][]' +
  1983. 'form[A|accept-charset|action|autocomplete|enctype|method|name|novalidate|target][C]' +
  1984. 'fieldset[A|disabled|form|name][C|legend]' +
  1985. 'label[A|form|for][B]' +
  1986. 'input[A|type|accept|alt|autocomplete|autofocus|checked|disabled|form|formaction|formenctype|formmethod|formnovalidate|formtarget|height|list|max|maxlength|min|' +
  1987. 'multiple|pattern|placeholder|readonly|required|size|src|step|width|files|value|name][]' +
  1988. 'button[A|autofocus|disabled|form|formaction|formenctype|formmethod|formnovalidate|formtarget|name|value|type][B]' +
  1989. 'select[A|autofocus|disabled|form|multiple|name|size][option|optgroup]' +
  1990. 'datalist[A][B|option]' +
  1991. 'optgroup[A|disabled|label][option]' +
  1992. 'option[A|disabled|selected|label|value][]' +
  1993. 'textarea[A|autofocus|disabled|form|maxlength|name|placeholder|readonly|required|rows|cols|wrap][]' +
  1994. 'keygen[A|autofocus|challenge|disabled|form|keytype|name][]' +
  1995. 'output[A|for|form|name][B]' +
  1996. 'canvas[A|width|height][]' +
  1997. 'map[A|name][B|C]' +
  1998. 'area[A|shape|coords|href|alt|target|media|rel|ping|type][]' +
  1999. 'mathml[A][]' +
  2000. 'svg[A][]' +
  2001. 'table[A|border][caption|colgroup|thead|tfoot|tbody|tr]' +
  2002. 'caption[A][C]' +
  2003. 'colgroup[A|span][col]' +
  2004. 'col[A|span][]' +
  2005. 'thead[A][tr]' +
  2006. 'tfoot[A][tr]' +
  2007. 'tbody[A][tr]' +
  2008. 'tr[A][th|td]' +
  2009. 'th[A|headers|rowspan|colspan|scope][B]' +
  2010. 'td[A|headers|rowspan|colspan][C]' +
  2011. 'wbr[A][]'
  2012. );
  2013. }
  2014. return html5;
  2015. };
  2016. function getHTML4() {
  2017. var html4 = mapCache.html4;
  2018. if (!html4) {
  2019. // This is the XHTML 1.0 transitional elements with it's attributes and children packed to reduce it's size
  2020. html4 = mapCache.html4 = unpack({
  2021. Z : 'H|K|N|O|P',
  2022. Y : 'X|form|R|Q',
  2023. ZG : 'E|span|width|align|char|charoff|valign',
  2024. X : 'p|T|div|U|W|isindex|fieldset|table',
  2025. ZF : 'E|align|char|charoff|valign',
  2026. W : 'pre|hr|blockquote|address|center|noframes',
  2027. ZE : 'abbr|axis|headers|scope|rowspan|colspan|align|char|charoff|valign|nowrap|bgcolor|width|height',
  2028. ZD : '[E][S]',
  2029. U : 'ul|ol|dl|menu|dir',
  2030. ZC : 'p|Y|div|U|W|table|br|span|bdo|object|applet|img|map|K|N|Q',
  2031. T : 'h1|h2|h3|h4|h5|h6',
  2032. ZB : 'X|S|Q',
  2033. S : 'R|P',
  2034. ZA : 'a|G|J|M|O|P',
  2035. R : 'a|H|K|N|O',
  2036. Q : 'noscript|P',
  2037. P : 'ins|del|script',
  2038. O : 'input|select|textarea|label|button',
  2039. N : 'M|L',
  2040. M : 'em|strong|dfn|code|q|samp|kbd|var|cite|abbr|acronym',
  2041. L : 'sub|sup',
  2042. K : 'J|I',
  2043. J : 'tt|i|b|u|s|strike',
  2044. I : 'big|small|font|basefont',
  2045. H : 'G|F',
  2046. G : 'br|span|bdo',
  2047. F : 'object|applet|img|map|iframe',
  2048. E : 'A|B|C',
  2049. D : 'accesskey|tabindex|onfocus|onblur',
  2050. C : 'onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup',
  2051. B : 'lang|xml:lang|dir',
  2052. A : 'id|class|style|title'
  2053. }, 'script[id|charset|type|language|src|defer|xml:space][]' +
  2054. 'style[B|id|type|media|title|xml:space][]' +
  2055. 'object[E|declare|classid|codebase|data|type|codetype|archive|standby|width|height|usemap|name|tabindex|align|border|hspace|vspace][#|param|Y]' +
  2056. 'param[id|name|value|valuetype|type][]' +
  2057. 'p[E|align][#|S]' +
  2058. 'a[E|D|charset|type|name|href|hreflang|rel|rev|shape|coords|target][#|Z]' +
  2059. 'br[A|clear][]' +
  2060. 'span[E][#|S]' +
  2061. 'bdo[A|C|B][#|S]' +
  2062. 'applet[A|codebase|archive|code|object|alt|name|width|height|align|hspace|vspace][#|param|Y]' +
  2063. 'h1[E|align][#|S]' +
  2064. 'img[E|src|alt|name|longdesc|width|height|usemap|ismap|align|border|hspace|vspace][]' +
  2065. 'map[B|C|A|name][X|form|Q|area]' +
  2066. 'h2[E|align][#|S]' +
  2067. 'iframe[A|longdesc|name|src|frameborder|marginwidth|marginheight|scrolling|align|width|height][#|Y]' +
  2068. 'h3[E|align][#|S]' +
  2069. 'tt[E][#|S]' +
  2070. 'i[E][#|S]' +
  2071. 'b[E][#|S]' +
  2072. 'u[E][#|S]' +
  2073. 's[E][#|S]' +
  2074. 'strike[E][#|S]' +
  2075. 'big[E][#|S]' +
  2076. 'small[E][#|S]' +
  2077. 'font[A|B|size|color|face][#|S]' +
  2078. 'basefont[id|size|color|face][]' +
  2079. 'em[E][#|S]' +
  2080. 'strong[E][#|S]' +
  2081. 'dfn[E][#|S]' +
  2082. 'code[E][#|S]' +
  2083. 'q[E|cite][#|S]' +
  2084. 'samp[E][#|S]' +
  2085. 'kbd[E][#|S]' +
  2086. 'var[E][#|S]' +
  2087. 'cite[E][#|S]' +
  2088. 'abbr[E][#|S]' +
  2089. 'acronym[E][#|S]' +
  2090. 'sub[E][#|S]' +
  2091. 'sup[E][#|S]' +
  2092. 'input[E|D|type|name|value|checked|disabled|readonly|size|maxlength|src|alt|usemap|onselect|onchange|accept|align][]' +
  2093. 'select[E|name|size|multiple|disabled|tabindex|onfocus|onblur|onchange][optgroup|option]' +
  2094. 'optgroup[E|disabled|label][option]' +
  2095. 'option[E|selected|disabled|label|value][]' +
  2096. 'textarea[E|D|name|rows|cols|disabled|readonly|onselect|onchange][]' +
  2097. 'label[E|for|accesskey|onfocus|onblur][#|S]' +
  2098. 'button[E|D|name|value|type|disabled][#|p|T|div|U|W|table|G|object|applet|img|map|K|N|Q]' +
  2099. 'h4[E|align][#|S]' +
  2100. 'ins[E|cite|datetime][#|Y]' +
  2101. 'h5[E|align][#|S]' +
  2102. 'del[E|cite|datetime][#|Y]' +
  2103. 'h6[E|align][#|S]' +
  2104. 'div[E|align][#|Y]' +
  2105. 'ul[E|type|compact][li]' +
  2106. 'li[E|type|value][#|Y]' +
  2107. 'ol[E|type|compact|start][li]' +
  2108. 'dl[E|compact][dt|dd]' +
  2109. 'dt[E][#|S]' +
  2110. 'dd[E][#|Y]' +
  2111. 'menu[E|compact][li]' +
  2112. 'dir[E|compact][li]' +
  2113. 'pre[E|width|xml:space][#|ZA]' +
  2114. 'hr[E|align|noshade|size|width][]' +
  2115. 'blockquote[E|cite][#|Y]' +
  2116. 'address[E][#|S|p]' +
  2117. 'center[E][#|Y]' +
  2118. 'noframes[E][#|Y]' +
  2119. 'isindex[A|B|prompt][]' +
  2120. 'fieldset[E][#|legend|Y]' +
  2121. 'legend[E|accesskey|align][#|S]' +
  2122. 'table[E|summary|width|border|frame|rules|cellspacing|cellpadding|align|bgcolor][caption|col|colgroup|thead|tfoot|tbody|tr]' +
  2123. 'caption[E|align][#|S]' +
  2124. 'col[ZG][]' +
  2125. 'colgroup[ZG][col]' +
  2126. 'thead[ZF][tr]' +
  2127. 'tr[ZF|bgcolor][th|td]' +
  2128. 'th[E|ZE][#|Y]' +
  2129. 'form[E|action|method|name|enctype|onsubmit|onreset|accept|accept-charset|target][#|X|R|Q]' +
  2130. 'noscript[E][#|Y]' +
  2131. 'td[E|ZE][#|Y]' +
  2132. 'tfoot[ZF][tr]' +
  2133. 'tbody[ZF][tr]' +
  2134. 'area[E|D|shape|coords|href|nohref|alt|target][]' +
  2135. 'base[id|href|target][]' +
  2136. 'body[E|onload|onunload|background|bgcolor|text|link|vlink|alink][#|Y]'
  2137. );
  2138. }
  2139. return html4;
  2140. };
  2141. tinymce.html.Schema = function(settings) {
  2142. var self = this, elements = {}, children = {}, patternElements = [], validStyles, schemaItems;
  2143. var whiteSpaceElementsMap, selfClosingElementsMap, shortEndedElementsMap, boolAttrMap, blockElementsMap, nonEmptyElementsMap, customElementsMap = {};
  2144. // Creates an lookup table map object for the specified option or the default value
  2145. function createLookupTable(option, default_value, extend) {
  2146. var value = settings[option];
  2147. if (!value) {
  2148. // Get cached default map or make it if needed
  2149. value = mapCache[option];
  2150. if (!value) {
  2151. value = makeMap(default_value, ' ', makeMap(default_value.toUpperCase(), ' '));
  2152. value = tinymce.extend(value, extend);
  2153. mapCache[option] = value;
  2154. }
  2155. } else {
  2156. // Create custom map
  2157. value = makeMap(value, ',', makeMap(value.toUpperCase(), ' '));
  2158. }
  2159. return value;
  2160. };
  2161. settings = settings || {};
  2162. schemaItems = settings.schema == "html5" ? getHTML5() : getHTML4();
  2163. // Allow all elements and attributes if verify_html is set to false
  2164. if (settings.verify_html === false)
  2165. settings.valid_elements = '*[*]';
  2166. // Build styles list
  2167. if (settings.valid_styles) {
  2168. validStyles = {};
  2169. // Convert styles into a rule list
  2170. each(settings.valid_styles, function(value, key) {
  2171. validStyles[key] = tinymce.explode(value);
  2172. });
  2173. }
  2174. // Setup map objects
  2175. whiteSpaceElementsMap = createLookupTable('whitespace_elements', 'pre script noscript style textarea');
  2176. selfClosingElementsMap = createLookupTable('self_closing_elements', 'colgroup dd dt li option p td tfoot th thead tr');
  2177. shortEndedElementsMap = createLookupTable('short_ended_elements', 'area base basefont br col frame hr img input isindex link meta param embed source wbr');
  2178. boolAttrMap = createLookupTable('boolean_attributes', 'checked compact declare defer disabled ismap multiple nohref noresize noshade nowrap readonly selected autoplay loop controls');
  2179. nonEmptyElementsMap = createLookupTable('non_empty_elements', 'td th iframe video audio object', shortEndedElementsMap);
  2180. textBlockElementsMap = createLookupTable('text_block_elements', 'h1 h2 h3 h4 h5 h6 p div address pre form ' +
  2181. 'blockquote center dir fieldset header footer article section hgroup aside nav figure');
  2182. blockElementsMap = createLookupTable('block_elements', 'hr table tbody thead tfoot ' +
  2183. 'th tr td li ol ul caption dl dt dd noscript menu isindex samp option datalist select optgroup', textBlockElementsMap);
  2184. // Converts a wildcard expression string to a regexp for example *a will become /.*a/.
  2185. function patternToRegExp(str) {
  2186. return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$');
  2187. };
  2188. // Parses the specified valid_elements string and adds to the current rules
  2189. // This function is a bit hard to read since it's heavily optimized for speed
  2190. function addValidElements(valid_elements) {
  2191. var ei, el, ai, al, yl, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder,
  2192. prefix, outputName, globalAttributes, globalAttributesOrder, transElement, key, childKey, value,
  2193. elementRuleRegExp = /^([#+\-])?([^\[\/]+)(?:\/([^\[]+))?(?:\[([^\]]+)\])?$/,
  2194. attrRuleRegExp = /^([!\-])?(\w+::\w+|[^=:<]+)?(?:([=:<])(.*))?$/,
  2195. hasPatternsRegExp = /[*?+]/;
  2196. if (valid_elements) {
  2197. // Split valid elements into an array with rules
  2198. valid_elements = split(valid_elements);
  2199. if (elements['@']) {
  2200. globalAttributes = elements['@'].attributes;
  2201. globalAttributesOrder = elements['@'].attributesOrder;
  2202. }
  2203. // Loop all rules
  2204. for (ei = 0, el = valid_elements.length; ei < el; ei++) {
  2205. // Parse element rule
  2206. matches = elementRuleRegExp.exec(valid_elements[ei]);
  2207. if (matches) {
  2208. // Setup local names for matches
  2209. prefix = matches[1];
  2210. elementName = matches[2];
  2211. outputName = matches[3];
  2212. attrData = matches[4];
  2213. // Create new attributes and attributesOrder
  2214. attributes = {};
  2215. attributesOrder = [];
  2216. // Create the new element
  2217. element = {
  2218. attributes : attributes,
  2219. attributesOrder : attributesOrder
  2220. };
  2221. // Padd empty elements prefix
  2222. if (prefix === '#')
  2223. element.paddEmpty = true;
  2224. // Remove empty elements prefix
  2225. if (prefix === '-')
  2226. element.removeEmpty = true;
  2227. // Copy attributes from global rule into current rule
  2228. if (globalAttributes) {
  2229. for (key in globalAttributes)
  2230. attributes[key] = globalAttributes[key];
  2231. attributesOrder.push.apply(attributesOrder, globalAttributesOrder);
  2232. }
  2233. // Attributes defined
  2234. if (attrData) {
  2235. attrData = split(attrData, '|');
  2236. for (ai = 0, al = attrData.length; ai < al; ai++) {
  2237. matches = attrRuleRegExp.exec(attrData[ai]);
  2238. if (matches) {
  2239. attr = {};
  2240. attrType = matches[1];
  2241. attrName = matches[2].replace(/::/g, ':');
  2242. prefix = matches[3];
  2243. value = matches[4];
  2244. // Required
  2245. if (attrType === '!') {
  2246. element.attributesRequired = element.attributesRequired || [];
  2247. element.attributesRequired.push(attrName);
  2248. attr.required = true;
  2249. }
  2250. // Denied from global
  2251. if (attrType === '-') {
  2252. delete attributes[attrName];
  2253. attributesOrder.splice(tinymce.inArray(attributesOrder, attrName), 1);
  2254. continue;
  2255. }
  2256. // Default value
  2257. if (prefix) {
  2258. // Default value
  2259. if (prefix === '=') {
  2260. element.attributesDefault = element.attributesDefault || [];
  2261. element.attributesDefault.push({name: attrName, value: value});
  2262. attr.defaultValue = value;
  2263. }
  2264. // Forced value
  2265. if (prefix === ':') {
  2266. element.attributesForced = element.attributesForced || [];
  2267. element.attributesForced.push({name: attrName, value: value});
  2268. attr.forcedValue = value;
  2269. }
  2270. // Required values
  2271. if (prefix === '<')
  2272. attr.validValues = makeMap(value, '?');
  2273. }
  2274. // Check for attribute patterns
  2275. if (hasPatternsRegExp.test(attrName)) {
  2276. element.attributePatterns = element.attributePatterns || [];
  2277. attr.pattern = patternToRegExp(attrName);
  2278. element.attributePatterns.push(attr);
  2279. } else {
  2280. // Add attribute to order list if it doesn't already exist
  2281. if (!attributes[attrName])
  2282. attributesOrder.push(attrName);
  2283. attributes[attrName] = attr;
  2284. }
  2285. }
  2286. }
  2287. }
  2288. // Global rule, store away these for later usage
  2289. if (!globalAttributes && elementName == '@') {
  2290. globalAttributes = attributes;
  2291. globalAttributesOrder = attributesOrder;
  2292. }
  2293. // Handle substitute elements such as b/strong
  2294. if (outputName) {
  2295. element.outputName = elementName;
  2296. elements[outputName] = element;
  2297. }
  2298. // Add pattern or exact element
  2299. if (hasPatternsRegExp.test(elementName)) {
  2300. element.pattern = patternToRegExp(elementName);
  2301. patternElements.push(element);
  2302. } else
  2303. elements[elementName] = element;
  2304. }
  2305. }
  2306. }
  2307. };
  2308. function setValidElements(valid_elements) {
  2309. elements = {};
  2310. patternElements = [];
  2311. addValidElements(valid_elements);
  2312. each(schemaItems, function(element, name) {
  2313. children[name] = element.children;
  2314. });
  2315. };
  2316. // Adds custom non HTML elements to the schema
  2317. function addCustomElements(custom_elements) {
  2318. var customElementRegExp = /^(~)?(.+)$/;
  2319. if (custom_elements) {
  2320. each(split(custom_elements), function(rule) {
  2321. var matches = customElementRegExp.exec(rule),
  2322. inline = matches[1] === '~',
  2323. cloneName = inline ? 'span' : 'div',
  2324. name = matches[2];
  2325. children[name] = children[cloneName];
  2326. customElementsMap[name] = cloneName;
  2327. // If it's not marked as inline then add it to valid block elements
  2328. if (!inline) {
  2329. blockElementsMap[name.toUpperCase()] = {};
  2330. blockElementsMap[name] = {};
  2331. }
  2332. // Add elements clone if needed
  2333. if (!elements[name]) {
  2334. elements[name] = elements[cloneName];
  2335. }
  2336. // Add custom elements at span/div positions
  2337. each(children, function(element, child) {
  2338. if (element[cloneName])
  2339. element[name] = element[cloneName];
  2340. });
  2341. });
  2342. }
  2343. };
  2344. // Adds valid children to the schema object
  2345. function addValidChildren(valid_children) {
  2346. var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/;
  2347. if (valid_children) {
  2348. each(split(valid_children), function(rule) {
  2349. var matches = childRuleRegExp.exec(rule), parent, prefix;
  2350. if (matches) {
  2351. prefix = matches[1];
  2352. // Add/remove items from default
  2353. if (prefix)
  2354. parent = children[matches[2]];
  2355. else
  2356. parent = children[matches[2]] = {'#comment' : {}};
  2357. parent = children[matches[2]];
  2358. each(split(matches[3], '|'), function(child) {
  2359. if (prefix === '-')
  2360. delete parent[child];
  2361. else
  2362. parent[child] = {};
  2363. });
  2364. }
  2365. });
  2366. }
  2367. };
  2368. function getElementRule(name) {
  2369. var element = elements[name], i;
  2370. // Exact match found
  2371. if (element)
  2372. return element;
  2373. // No exact match then try the patterns
  2374. i = patternElements.length;
  2375. while (i--) {
  2376. element = patternElements[i];
  2377. if (element.pattern.test(name))
  2378. return element;
  2379. }
  2380. };
  2381. if (!settings.valid_elements) {
  2382. // No valid elements defined then clone the elements from the schema spec
  2383. each(schemaItems, function(element, name) {
  2384. elements[name] = {
  2385. attributes : element.attributes,
  2386. attributesOrder : element.attributesOrder
  2387. };
  2388. children[name] = element.children;
  2389. });
  2390. // Switch these on HTML4
  2391. if (settings.schema != "html5") {
  2392. each(split('strong/b,em/i'), function(item) {
  2393. item = split(item, '/');
  2394. elements[item[1]].outputName = item[0];
  2395. });
  2396. }
  2397. // Add default alt attribute for images
  2398. elements.img.attributesDefault = [{name: 'alt', value: ''}];
  2399. // Remove these if they are empty by default
  2400. each(split('ol,ul,sub,sup,blockquote,span,font,a,table,tbody,tr,strong,em,b,i'), function(name) {
  2401. if (elements[name]) {
  2402. elements[name].removeEmpty = true;
  2403. }
  2404. });
  2405. // Padd these by default
  2406. each(split('p,h1,h2,h3,h4,h5,h6,th,td,pre,div,address,caption'), function(name) {
  2407. elements[name].paddEmpty = true;
  2408. });
  2409. } else
  2410. setValidElements(settings.valid_elements);
  2411. addCustomElements(settings.custom_elements);
  2412. addValidChildren(settings.valid_children);
  2413. addValidElements(settings.extended_valid_elements);
  2414. // Todo: Remove this when we fix list handling to be valid
  2415. addValidChildren('+ol[ul|ol],+ul[ul|ol]');
  2416. // Delete invalid elements
  2417. if (settings.invalid_elements) {
  2418. tinymce.each(tinymce.explode(settings.invalid_elements), function(item) {
  2419. if (elements[item])
  2420. delete elements[item];
  2421. });
  2422. }
  2423. // If the user didn't allow span only allow internal spans
  2424. if (!getElementRule('span'))
  2425. addValidElements('span[!data-mce-type|*]');
  2426. self.children = children;
  2427. self.styles = validStyles;
  2428. self.getBoolAttrs = function() {
  2429. return boolAttrMap;
  2430. };
  2431. self.getBlockElements = function() {
  2432. return blockElementsMap;
  2433. };
  2434. self.getTextBlockElements = function() {
  2435. return textBlockElementsMap;
  2436. };
  2437. self.getShortEndedElements = function() {
  2438. return shortEndedElementsMap;
  2439. };
  2440. self.getSelfClosingElements = function() {
  2441. return selfClosingElementsMap;
  2442. };
  2443. self.getNonEmptyElements = function() {
  2444. return nonEmptyElementsMap;
  2445. };
  2446. self.getWhiteSpaceElements = function() {
  2447. return whiteSpaceElementsMap;
  2448. };
  2449. self.isValidChild = function(name, child) {
  2450. var parent = children[name];
  2451. return !!(parent && parent[child]);
  2452. };
  2453. self.isValid = function(name, attr) {
  2454. var attrPatterns, i, rule = getElementRule(name);
  2455. // Check if it's a valid element
  2456. if (rule) {
  2457. if (attr) {
  2458. // Check if attribute name exists
  2459. if (rule.attributes[attr]) {
  2460. return true;
  2461. }
  2462. // Check if attribute matches a regexp pattern
  2463. attrPatterns = rule.attributePatterns;
  2464. if (attrPatterns) {
  2465. i = attrPatterns.length;
  2466. while (i--) {
  2467. if (attrPatterns[i].pattern.test(name)) {
  2468. return true;
  2469. }
  2470. }
  2471. }
  2472. } else {
  2473. return true;
  2474. }
  2475. }
  2476. // No match
  2477. return false;
  2478. };
  2479. self.getElementRule = getElementRule;
  2480. self.getCustomElements = function() {
  2481. return customElementsMap;
  2482. };
  2483. self.addValidElements = addValidElements;
  2484. self.setValidElements = setValidElements;
  2485. self.addCustomElements = addCustomElements;
  2486. self.addValidChildren = addValidChildren;
  2487. self.elements = elements;
  2488. };
  2489. })(tinymce);
  2490. (function(tinymce) {
  2491. tinymce.html.SaxParser = function(settings, schema) {
  2492. var self = this, noop = function() {};
  2493. settings = settings || {};
  2494. self.schema = schema = schema || new tinymce.html.Schema();
  2495. if (settings.fix_self_closing !== false)
  2496. settings.fix_self_closing = true;
  2497. // Add handler functions from settings and setup default handlers
  2498. tinymce.each('comment cdata text start end pi doctype'.split(' '), function(name) {
  2499. if (name)
  2500. self[name] = settings[name] || noop;
  2501. });
  2502. self.parse = function(html) {
  2503. var self = this, matches, index = 0, value, endRegExp, stack = [], attrList, i, text, name, isInternalElement, removeInternalElements,
  2504. shortEndedElements, fillAttrsMap, isShortEnded, validate, elementRule, isValidElement, attr, attribsValue, invalidPrefixRegExp,
  2505. validAttributesMap, validAttributePatterns, attributesRequired, attributesDefault, attributesForced, selfClosing,
  2506. tokenRegExp, attrRegExp, specialElements, attrValue, idCount = 0, decode = tinymce.html.Entities.decode, fixSelfClosing, isIE;
  2507. function processEndTag(name) {
  2508. var pos, i;
  2509. // Find position of parent of the same type
  2510. pos = stack.length;
  2511. while (pos--) {
  2512. if (stack[pos].name === name)
  2513. break;
  2514. }
  2515. // Found parent
  2516. if (pos >= 0) {
  2517. // Close all the open elements
  2518. for (i = stack.length - 1; i >= pos; i--) {
  2519. name = stack[i];
  2520. if (name.valid)
  2521. self.end(name.name);
  2522. }
  2523. // Remove the open elements from the stack
  2524. stack.length = pos;
  2525. }
  2526. };
  2527. function parseAttribute(match, name, value, val2, val3) {
  2528. var attrRule, i;
  2529. name = name.toLowerCase();
  2530. value = name in fillAttrsMap ? name : decode(value || val2 || val3 || ''); // Handle boolean attribute than value attribute
  2531. // Validate name and value
  2532. if (validate && !isInternalElement && name.indexOf('data-') !== 0) {
  2533. attrRule = validAttributesMap[name];
  2534. // Find rule by pattern matching
  2535. if (!attrRule && validAttributePatterns) {
  2536. i = validAttributePatterns.length;
  2537. while (i--) {
  2538. attrRule = validAttributePatterns[i];
  2539. if (attrRule.pattern.test(name))
  2540. break;
  2541. }
  2542. // No rule matched
  2543. if (i === -1)
  2544. attrRule = null;
  2545. }
  2546. // No attribute rule found
  2547. if (!attrRule)
  2548. return;
  2549. // Validate value
  2550. if (attrRule.validValues && !(value in attrRule.validValues))
  2551. return;
  2552. }
  2553. // Add attribute to list and map
  2554. attrList.map[name] = value;
  2555. attrList.push({
  2556. name: name,
  2557. value: value
  2558. });
  2559. };
  2560. // Precompile RegExps and map objects
  2561. tokenRegExp = new RegExp('<(?:' +
  2562. '(?:!--([\\w\\W]*?)-->)|' + // Comment
  2563. '(?:!\\[CDATA\\[([\\w\\W]*?)\\]\\]>)|' + // CDATA
  2564. '(?:!DOCTYPE([\\w\\W]*?)>)|' + // DOCTYPE
  2565. '(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|' + // PI
  2566. '(?:\\/([^>]+)>)|' + // End element
  2567. '(?:([A-Za-z0-9\\-\\:\\.]+)((?:\\s+[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*|\\/|\\s+)>)' + // Start element
  2568. ')', 'g');
  2569. attrRegExp = /([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:[^\"])*)\")|(?:\'((?:[^\'])*)\')|([^>\s]+)))?/g;
  2570. specialElements = {
  2571. 'script' : /<\/script[^>]*>/gi,
  2572. 'style' : /<\/style[^>]*>/gi,
  2573. 'noscript' : /<\/noscript[^>]*>/gi
  2574. };
  2575. // Setup lookup tables for empty elements and boolean attributes
  2576. shortEndedElements = schema.getShortEndedElements();
  2577. selfClosing = settings.self_closing_elements || schema.getSelfClosingElements();
  2578. fillAttrsMap = schema.getBoolAttrs();
  2579. validate = settings.validate;
  2580. removeInternalElements = settings.remove_internals;
  2581. fixSelfClosing = settings.fix_self_closing;
  2582. isIE = tinymce.isIE;
  2583. invalidPrefixRegExp = /^:/;
  2584. while (matches = tokenRegExp.exec(html)) {
  2585. // Text
  2586. if (index < matches.index)
  2587. self.text(decode(html.substr(index, matches.index - index)));
  2588. if (value = matches[6]) { // End element
  2589. value = value.toLowerCase();
  2590. // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
  2591. if (isIE && invalidPrefixRegExp.test(value))
  2592. value = value.substr(1);
  2593. processEndTag(value);
  2594. } else if (value = matches[7]) { // Start element
  2595. value = value.toLowerCase();
  2596. // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
  2597. if (isIE && invalidPrefixRegExp.test(value))
  2598. value = value.substr(1);
  2599. isShortEnded = value in shortEndedElements;
  2600. // Is self closing tag for example an <li> after an open <li>
  2601. if (fixSelfClosing && selfClosing[value] && stack.length > 0 && stack[stack.length - 1].name === value)
  2602. processEndTag(value);
  2603. // Validate element
  2604. if (!validate || (elementRule = schema.getElementRule(value))) {
  2605. isValidElement = true;
  2606. // Grab attributes map and patters when validation is enabled
  2607. if (validate) {
  2608. validAttributesMap = elementRule.attributes;
  2609. validAttributePatterns = elementRule.attributePatterns;
  2610. }
  2611. // Parse attributes
  2612. if (attribsValue = matches[8]) {
  2613. isInternalElement = attribsValue.indexOf('data-mce-type') !== -1; // Check if the element is an internal element
  2614. // If the element has internal attributes then remove it if we are told to do so
  2615. if (isInternalElement && removeInternalElements)
  2616. isValidElement = false;
  2617. attrList = [];
  2618. attrList.map = {};
  2619. attribsValue.replace(attrRegExp, parseAttribute);
  2620. } else {
  2621. attrList = [];
  2622. attrList.map = {};
  2623. }
  2624. // Process attributes if validation is enabled
  2625. if (validate && !isInternalElement) {
  2626. attributesRequired = elementRule.attributesRequired;
  2627. attributesDefault = elementRule.attributesDefault;
  2628. attributesForced = elementRule.attributesForced;
  2629. // Handle forced attributes
  2630. if (attributesForced) {
  2631. i = attributesForced.length;
  2632. while (i--) {
  2633. attr = attributesForced[i];
  2634. name = attr.name;
  2635. attrValue = attr.value;
  2636. if (attrValue === '{$uid}')
  2637. attrValue = 'mce_' + idCount++;
  2638. attrList.map[name] = attrValue;
  2639. attrList.push({name: name, value: attrValue});
  2640. }
  2641. }
  2642. // Handle default attributes
  2643. if (attributesDefault) {
  2644. i = attributesDefault.length;
  2645. while (i--) {
  2646. attr = attributesDefault[i];
  2647. name = attr.name;
  2648. if (!(name in attrList.map)) {
  2649. attrValue = attr.value;
  2650. if (attrValue === '{$uid}')
  2651. attrValue = 'mce_' + idCount++;
  2652. attrList.map[name] = attrValue;
  2653. attrList.push({name: name, value: attrValue});
  2654. }
  2655. }
  2656. }
  2657. // Handle required attributes
  2658. if (attributesRequired) {
  2659. i = attributesRequired.length;
  2660. while (i--) {
  2661. if (attributesRequired[i] in attrList.map)
  2662. break;
  2663. }
  2664. // None of the required attributes where found
  2665. if (i === -1)
  2666. isValidElement = false;
  2667. }
  2668. // Invalidate element if it's marked as bogus
  2669. if (attrList.map['data-mce-bogus'])
  2670. isValidElement = false;
  2671. }
  2672. if (isValidElement)
  2673. self.start(value, attrList, isShortEnded);
  2674. } else
  2675. isValidElement = false;
  2676. // Treat script, noscript and style a bit different since they may include code that looks like elements
  2677. if (endRegExp = specialElements[value]) {
  2678. endRegExp.lastIndex = index = matches.index + matches[0].length;
  2679. if (matches = endRegExp.exec(html)) {
  2680. if (isValidElement)
  2681. text = html.substr(index, matches.index - index);
  2682. index = matches.index + matches[0].length;
  2683. } else {
  2684. text = html.substr(index);
  2685. index = html.length;
  2686. }
  2687. if (isValidElement && text.length > 0)
  2688. self.text(text, true);
  2689. if (isValidElement)
  2690. self.end(value);
  2691. tokenRegExp.lastIndex = index;
  2692. continue;
  2693. }
  2694. // Push value on to stack
  2695. if (!isShortEnded) {
  2696. if (!attribsValue || attribsValue.indexOf('/') != attribsValue.length - 1)
  2697. stack.push({name: value, valid: isValidElement});
  2698. else if (isValidElement)
  2699. self.end(value);
  2700. }
  2701. } else if (value = matches[1]) { // Comment
  2702. self.comment(value);
  2703. } else if (value = matches[2]) { // CDATA
  2704. self.cdata(value);
  2705. } else if (value = matches[3]) { // DOCTYPE
  2706. self.doctype(value);
  2707. } else if (value = matches[4]) { // PI
  2708. self.pi(value, matches[5]);
  2709. }
  2710. index = matches.index + matches[0].length;
  2711. }
  2712. // Text
  2713. if (index < html.length)
  2714. self.text(decode(html.substr(index)));
  2715. // Close any open elements
  2716. for (i = stack.length - 1; i >= 0; i--) {
  2717. value = stack[i];
  2718. if (value.valid)
  2719. self.end(value.name);
  2720. }
  2721. };
  2722. }
  2723. })(tinymce);
  2724. (function(tinymce) {
  2725. var whiteSpaceRegExp = /^[ \t\r\n]*$/, typeLookup = {
  2726. '#text' : 3,
  2727. '#comment' : 8,
  2728. '#cdata' : 4,
  2729. '#pi' : 7,
  2730. '#doctype' : 10,
  2731. '#document-fragment' : 11
  2732. };
  2733. // Walks the tree left/right
  2734. function walk(node, root_node, prev) {
  2735. var sibling, parent, startName = prev ? 'lastChild' : 'firstChild', siblingName = prev ? 'prev' : 'next';
  2736. // Walk into nodes if it has a start
  2737. if (node[startName])
  2738. return node[startName];
  2739. // Return the sibling if it has one
  2740. if (node !== root_node) {
  2741. sibling = node[siblingName];
  2742. if (sibling)
  2743. return sibling;
  2744. // Walk up the parents to look for siblings
  2745. for (parent = node.parent; parent && parent !== root_node; parent = parent.parent) {
  2746. sibling = parent[siblingName];
  2747. if (sibling)
  2748. return sibling;
  2749. }
  2750. }
  2751. };
  2752. function Node(name, type) {
  2753. this.name = name;
  2754. this.type = type;
  2755. if (type === 1) {
  2756. this.attributes = [];
  2757. this.attributes.map = {};
  2758. }
  2759. }
  2760. tinymce.extend(Node.prototype, {
  2761. replace : function(node) {
  2762. var self = this;
  2763. if (node.parent)
  2764. node.remove();
  2765. self.insert(node, self);
  2766. self.remove();
  2767. return self;
  2768. },
  2769. attr : function(name, value) {
  2770. var self = this, attrs, i, undef;
  2771. if (typeof name !== "string") {
  2772. for (i in name)
  2773. self.attr(i, name[i]);
  2774. return self;
  2775. }
  2776. if (attrs = self.attributes) {
  2777. if (value !== undef) {
  2778. // Remove attribute
  2779. if (value === null) {
  2780. if (name in attrs.map) {
  2781. delete attrs.map[name];
  2782. i = attrs.length;
  2783. while (i--) {
  2784. if (attrs[i].name === name) {
  2785. attrs = attrs.splice(i, 1);
  2786. return self;
  2787. }
  2788. }
  2789. }
  2790. return self;
  2791. }
  2792. // Set attribute
  2793. if (name in attrs.map) {
  2794. // Set attribute
  2795. i = attrs.length;
  2796. while (i--) {
  2797. if (attrs[i].name === name) {
  2798. attrs[i].value = value;
  2799. break;
  2800. }
  2801. }
  2802. } else
  2803. attrs.push({name: name, value: value});
  2804. attrs.map[name] = value;
  2805. return self;
  2806. } else {
  2807. return attrs.map[name];
  2808. }
  2809. }
  2810. },
  2811. clone : function() {
  2812. var self = this, clone = new Node(self.name, self.type), i, l, selfAttrs, selfAttr, cloneAttrs;
  2813. // Clone element attributes
  2814. if (selfAttrs = self.attributes) {
  2815. cloneAttrs = [];
  2816. cloneAttrs.map = {};
  2817. for (i = 0, l = selfAttrs.length; i < l; i++) {
  2818. selfAttr = selfAttrs[i];
  2819. // Clone everything except id
  2820. if (selfAttr.name !== 'id') {
  2821. cloneAttrs[cloneAttrs.length] = {name: selfAttr.name, value: selfAttr.value};
  2822. cloneAttrs.map[selfAttr.name] = selfAttr.value;
  2823. }
  2824. }
  2825. clone.attributes = cloneAttrs;
  2826. }
  2827. clone.value = self.value;
  2828. clone.shortEnded = self.shortEnded;
  2829. return clone;
  2830. },
  2831. wrap : function(wrapper) {
  2832. var self = this;
  2833. self.parent.insert(wrapper, self);
  2834. wrapper.append(self);
  2835. return self;
  2836. },
  2837. unwrap : function() {
  2838. var self = this, node, next;
  2839. for (node = self.firstChild; node; ) {
  2840. next = node.next;
  2841. self.insert(node, self, true);
  2842. node = next;
  2843. }
  2844. self.remove();
  2845. },
  2846. remove : function() {
  2847. var self = this, parent = self.parent, next = self.next, prev = self.prev;
  2848. if (parent) {
  2849. if (parent.firstChild === self) {
  2850. parent.firstChild = next;
  2851. if (next)
  2852. next.prev = null;
  2853. } else {
  2854. prev.next = next;
  2855. }
  2856. if (parent.lastChild === self) {
  2857. parent.lastChild = prev;
  2858. if (prev)
  2859. prev.next = null;
  2860. } else {
  2861. next.prev = prev;
  2862. }
  2863. self.parent = self.next = self.prev = null;
  2864. }
  2865. return self;
  2866. },
  2867. append : function(node) {
  2868. var self = this, last;
  2869. if (node.parent)
  2870. node.remove();
  2871. last = self.lastChild;
  2872. if (last) {
  2873. last.next = node;
  2874. node.prev = last;
  2875. self.lastChild = node;
  2876. } else
  2877. self.lastChild = self.firstChild = node;
  2878. node.parent = self;
  2879. return node;
  2880. },
  2881. insert : function(node, ref_node, before) {
  2882. var parent;
  2883. if (node.parent)
  2884. node.remove();
  2885. parent = ref_node.parent || this;
  2886. if (before) {
  2887. if (ref_node === parent.firstChild)
  2888. parent.firstChild = node;
  2889. else
  2890. ref_node.prev.next = node;
  2891. node.prev = ref_node.prev;
  2892. node.next = ref_node;
  2893. ref_node.prev = node;
  2894. } else {
  2895. if (ref_node === parent.lastChild)
  2896. parent.lastChild = node;
  2897. else
  2898. ref_node.next.prev = node;
  2899. node.next = ref_node.next;
  2900. node.prev = ref_node;
  2901. ref_node.next = node;
  2902. }
  2903. node.parent = parent;
  2904. return node;
  2905. },
  2906. getAll : function(name) {
  2907. var self = this, node, collection = [];
  2908. for (node = self.firstChild; node; node = walk(node, self)) {
  2909. if (node.name === name)
  2910. collection.push(node);
  2911. }
  2912. return collection;
  2913. },
  2914. empty : function() {
  2915. var self = this, nodes, i, node;
  2916. // Remove all children
  2917. if (self.firstChild) {
  2918. nodes = [];
  2919. // Collect the children
  2920. for (node = self.firstChild; node; node = walk(node, self))
  2921. nodes.push(node);
  2922. // Remove the children
  2923. i = nodes.length;
  2924. while (i--) {
  2925. node = nodes[i];
  2926. node.parent = node.firstChild = node.lastChild = node.next = node.prev = null;
  2927. }
  2928. }
  2929. self.firstChild = self.lastChild = null;
  2930. return self;
  2931. },
  2932. isEmpty : function(elements) {
  2933. var self = this, node = self.firstChild, i, name;
  2934. if (node) {
  2935. do {
  2936. if (node.type === 1) {
  2937. // Ignore bogus elements
  2938. if (node.attributes.map['data-mce-bogus'])
  2939. continue;
  2940. // Keep empty elements like <img />
  2941. if (elements[node.name])
  2942. return false;
  2943. // Keep elements with data attributes or name attribute like <a name="1"></a>
  2944. i = node.attributes.length;
  2945. while (i--) {
  2946. name = node.attributes[i].name;
  2947. if (name === "name" || name.indexOf('data-mce-') === 0)
  2948. return false;
  2949. }
  2950. }
  2951. // Keep comments
  2952. if (node.type === 8)
  2953. return false;
  2954. // Keep non whitespace text nodes
  2955. if ((node.type === 3 && !whiteSpaceRegExp.test(node.value)))
  2956. return false;
  2957. } while (node = walk(node, self));
  2958. }
  2959. return true;
  2960. },
  2961. walk : function(prev) {
  2962. return walk(this, null, prev);
  2963. }
  2964. });
  2965. tinymce.extend(Node, {
  2966. create : function(name, attrs) {
  2967. var node, attrName;
  2968. // Create node
  2969. node = new Node(name, typeLookup[name] || 1);
  2970. // Add attributes if needed
  2971. if (attrs) {
  2972. for (attrName in attrs)
  2973. node.attr(attrName, attrs[attrName]);
  2974. }
  2975. return node;
  2976. }
  2977. });
  2978. tinymce.html.Node = Node;
  2979. })(tinymce);
  2980. (function(tinymce) {
  2981. var Node = tinymce.html.Node;
  2982. tinymce.html.DomParser = function(settings, schema) {
  2983. var self = this, nodeFilters = {}, attributeFilters = [], matchedNodes = {}, matchedAttributes = {};
  2984. settings = settings || {};
  2985. settings.validate = "validate" in settings ? settings.validate : true;
  2986. settings.root_name = settings.root_name || 'body';
  2987. self.schema = schema = schema || new tinymce.html.Schema();
  2988. function fixInvalidChildren(nodes) {
  2989. var ni, node, parent, parents, newParent, currentNode, tempNode, childNode, i,
  2990. childClone, nonEmptyElements, nonSplitableElements, textBlockElements, sibling, nextNode;
  2991. nonSplitableElements = tinymce.makeMap('tr,td,th,tbody,thead,tfoot,table');
  2992. nonEmptyElements = schema.getNonEmptyElements();
  2993. textBlockElements = schema.getTextBlockElements();
  2994. for (ni = 0; ni < nodes.length; ni++) {
  2995. node = nodes[ni];
  2996. // Already removed or fixed
  2997. if (!node.parent || node.fixed)
  2998. continue;
  2999. // If the invalid element is a text block and the text block is within a parent LI element
  3000. // Then unwrap the first text block and convert other sibling text blocks to LI elements similar to Word/Open Office
  3001. if (textBlockElements[node.name] && node.parent.name == 'li') {
  3002. // Move sibling text blocks after LI element
  3003. sibling = node.next;
  3004. while (sibling) {
  3005. if (textBlockElements[sibling.name]) {
  3006. sibling.name = 'li';
  3007. sibling.fixed = true;
  3008. node.parent.insert(sibling, node.parent);
  3009. } else {
  3010. break;
  3011. }
  3012. sibling = sibling.next;
  3013. }
  3014. // Unwrap current text block
  3015. node.unwrap(node);
  3016. continue;
  3017. }
  3018. // Get list of all parent nodes until we find a valid parent to stick the child into
  3019. parents = [node];
  3020. for (parent = node.parent; parent && !schema.isValidChild(parent.name, node.name) && !nonSplitableElements[parent.name]; parent = parent.parent)
  3021. parents.push(parent);
  3022. // Found a suitable parent
  3023. if (parent && parents.length > 1) {
  3024. // Reverse the array since it makes looping easier
  3025. parents.reverse();
  3026. // Clone the related parent and insert that after the moved node
  3027. newParent = currentNode = self.filterNode(parents[0].clone());
  3028. // Start cloning and moving children on the left side of the target node
  3029. for (i = 0; i < parents.length - 1; i++) {
  3030. if (schema.isValidChild(currentNode.name, parents[i].name)) {
  3031. tempNode = self.filterNode(parents[i].clone());
  3032. currentNode.append(tempNode);
  3033. } else
  3034. tempNode = currentNode;
  3035. for (childNode = parents[i].firstChild; childNode && childNode != parents[i + 1]; ) {
  3036. nextNode = childNode.next;
  3037. tempNode.append(childNode);
  3038. childNode = nextNode;
  3039. }
  3040. currentNode = tempNode;
  3041. }
  3042. if (!newParent.isEmpty(nonEmptyElements)) {
  3043. parent.insert(newParent, parents[0], true);
  3044. parent.insert(node, newParent);
  3045. } else {
  3046. parent.insert(node, parents[0], true);
  3047. }
  3048. // Check if the element is empty by looking through it's contents and special treatment for <p><br /></p>
  3049. parent = parents[0];
  3050. if (parent.isEmpty(nonEmptyElements) || parent.firstChild === parent.lastChild && parent.firstChild.name === 'br') {
  3051. parent.empty().remove();
  3052. }
  3053. } else if (node.parent) {
  3054. // If it's an LI try to find a UL/OL for it or wrap it
  3055. if (node.name === 'li') {
  3056. sibling = node.prev;
  3057. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  3058. sibling.append(node);
  3059. continue;
  3060. }
  3061. sibling = node.next;
  3062. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  3063. sibling.insert(node, sibling.firstChild, true);
  3064. continue;
  3065. }
  3066. node.wrap(self.filterNode(new Node('ul', 1)));
  3067. continue;
  3068. }
  3069. // Try wrapping the element in a DIV
  3070. if (schema.isValidChild(node.parent.name, 'div') && schema.isValidChild('div', node.name)) {
  3071. node.wrap(self.filterNode(new Node('div', 1)));
  3072. } else {
  3073. // We failed wrapping it, then remove or unwrap it
  3074. if (node.name === 'style' || node.name === 'script')
  3075. node.empty().remove();
  3076. else
  3077. node.unwrap();
  3078. }
  3079. }
  3080. }
  3081. };
  3082. self.filterNode = function(node) {
  3083. var i, name, list;
  3084. // Run element filters
  3085. if (name in nodeFilters) {
  3086. list = matchedNodes[name];
  3087. if (list)
  3088. list.push(node);
  3089. else
  3090. matchedNodes[name] = [node];
  3091. }
  3092. // Run attribute filters
  3093. i = attributeFilters.length;
  3094. while (i--) {
  3095. name = attributeFilters[i].name;
  3096. if (name in node.attributes.map) {
  3097. list = matchedAttributes[name];
  3098. if (list)
  3099. list.push(node);
  3100. else
  3101. matchedAttributes[name] = [node];
  3102. }
  3103. }
  3104. return node;
  3105. };
  3106. self.addNodeFilter = function(name, callback) {
  3107. tinymce.each(tinymce.explode(name), function(name) {
  3108. var list = nodeFilters[name];
  3109. if (!list)
  3110. nodeFilters[name] = list = [];
  3111. list.push(callback);
  3112. });
  3113. };
  3114. self.addAttributeFilter = function(name, callback) {
  3115. tinymce.each(tinymce.explode(name), function(name) {
  3116. var i;
  3117. for (i = 0; i < attributeFilters.length; i++) {
  3118. if (attributeFilters[i].name === name) {
  3119. attributeFilters[i].callbacks.push(callback);
  3120. return;
  3121. }
  3122. }
  3123. attributeFilters.push({name: name, callbacks: [callback]});
  3124. });
  3125. };
  3126. self.parse = function(html, args) {
  3127. var parser, rootNode, node, nodes, i, l, fi, fl, list, name, validate,
  3128. blockElements, startWhiteSpaceRegExp, invalidChildren = [], isInWhiteSpacePreservedElement,
  3129. endWhiteSpaceRegExp, allWhiteSpaceRegExp, isAllWhiteSpaceRegExp, whiteSpaceElements, children, nonEmptyElements, rootBlockName;
  3130. args = args || {};
  3131. matchedNodes = {};
  3132. matchedAttributes = {};
  3133. blockElements = tinymce.extend(tinymce.makeMap('script,style,head,html,body,title,meta,param'), schema.getBlockElements());
  3134. nonEmptyElements = schema.getNonEmptyElements();
  3135. children = schema.children;
  3136. validate = settings.validate;
  3137. rootBlockName = "forced_root_block" in args ? args.forced_root_block : settings.forced_root_block;
  3138. whiteSpaceElements = schema.getWhiteSpaceElements();
  3139. startWhiteSpaceRegExp = /^[ \t\r\n]+/;
  3140. endWhiteSpaceRegExp = /[ \t\r\n]+$/;
  3141. allWhiteSpaceRegExp = /[ \t\r\n]+/g;
  3142. isAllWhiteSpaceRegExp = /^[ \t\r\n]+$/;
  3143. function addRootBlocks() {
  3144. var node = rootNode.firstChild, next, rootBlockNode;
  3145. while (node) {
  3146. next = node.next;
  3147. if (node.type == 3 || (node.type == 1 && node.name !== 'p' && !blockElements[node.name] && !node.attr('data-mce-type'))) {
  3148. if (!rootBlockNode) {
  3149. // Create a new root block element
  3150. rootBlockNode = createNode(rootBlockName, 1);
  3151. rootNode.insert(rootBlockNode, node);
  3152. rootBlockNode.append(node);
  3153. } else
  3154. rootBlockNode.append(node);
  3155. } else {
  3156. rootBlockNode = null;
  3157. }
  3158. node = next;
  3159. };
  3160. };
  3161. function createNode(name, type) {
  3162. var node = new Node(name, type), list;
  3163. if (name in nodeFilters) {
  3164. list = matchedNodes[name];
  3165. if (list)
  3166. list.push(node);
  3167. else
  3168. matchedNodes[name] = [node];
  3169. }
  3170. return node;
  3171. };
  3172. function removeWhitespaceBefore(node) {
  3173. var textNode, textVal, sibling;
  3174. for (textNode = node.prev; textNode && textNode.type === 3; ) {
  3175. textVal = textNode.value.replace(endWhiteSpaceRegExp, '');
  3176. if (textVal.length > 0) {
  3177. textNode.value = textVal;
  3178. textNode = textNode.prev;
  3179. } else {
  3180. sibling = textNode.prev;
  3181. textNode.remove();
  3182. textNode = sibling;
  3183. }
  3184. }
  3185. };
  3186. function cloneAndExcludeBlocks(input) {
  3187. var name, output = {};
  3188. for (name in input) {
  3189. if (name !== 'li' && name != 'p') {
  3190. output[name] = input[name];
  3191. }
  3192. }
  3193. return output;
  3194. };
  3195. parser = new tinymce.html.SaxParser({
  3196. validate : validate,
  3197. // Exclude P and LI from DOM parsing since it's treated better by the DOM parser
  3198. self_closing_elements: cloneAndExcludeBlocks(schema.getSelfClosingElements()),
  3199. cdata: function(text) {
  3200. node.append(createNode('#cdata', 4)).value = text;
  3201. },
  3202. text: function(text, raw) {
  3203. var textNode;
  3204. // Trim all redundant whitespace on non white space elements
  3205. if (!isInWhiteSpacePreservedElement) {
  3206. text = text.replace(allWhiteSpaceRegExp, ' ');
  3207. if (node.lastChild && blockElements[node.lastChild.name])
  3208. text = text.replace(startWhiteSpaceRegExp, '');
  3209. }
  3210. // Do we need to create the node
  3211. if (text.length !== 0) {
  3212. textNode = createNode('#text', 3);
  3213. textNode.raw = !!raw;
  3214. node.append(textNode).value = text;
  3215. }
  3216. },
  3217. comment: function(text) {
  3218. node.append(createNode('#comment', 8)).value = text;
  3219. },
  3220. pi: function(name, text) {
  3221. node.append(createNode(name, 7)).value = text;
  3222. removeWhitespaceBefore(node);
  3223. },
  3224. doctype: function(text) {
  3225. var newNode;
  3226. newNode = node.append(createNode('#doctype', 10));
  3227. newNode.value = text;
  3228. removeWhitespaceBefore(node);
  3229. },
  3230. start: function(name, attrs, empty) {
  3231. var newNode, attrFiltersLen, elementRule, textNode, attrName, text, sibling, parent;
  3232. elementRule = validate ? schema.getElementRule(name) : {};
  3233. if (elementRule) {
  3234. newNode = createNode(elementRule.outputName || name, 1);
  3235. newNode.attributes = attrs;
  3236. newNode.shortEnded = empty;
  3237. node.append(newNode);
  3238. // Check if node is valid child of the parent node is the child is
  3239. // unknown we don't collect it since it's probably a custom element
  3240. parent = children[node.name];
  3241. if (parent && children[newNode.name] && !parent[newNode.name])
  3242. invalidChildren.push(newNode);
  3243. attrFiltersLen = attributeFilters.length;
  3244. while (attrFiltersLen--) {
  3245. attrName = attributeFilters[attrFiltersLen].name;
  3246. if (attrName in attrs.map) {
  3247. list = matchedAttributes[attrName];
  3248. if (list)
  3249. list.push(newNode);
  3250. else
  3251. matchedAttributes[attrName] = [newNode];
  3252. }
  3253. }
  3254. // Trim whitespace before block
  3255. if (blockElements[name])
  3256. removeWhitespaceBefore(newNode);
  3257. // Change current node if the element wasn't empty i.e not <br /> or <img />
  3258. if (!empty)
  3259. node = newNode;
  3260. // Check if we are inside a whitespace preserved element
  3261. if (!isInWhiteSpacePreservedElement && whiteSpaceElements[name]) {
  3262. isInWhiteSpacePreservedElement = true;
  3263. }
  3264. }
  3265. },
  3266. end: function(name) {
  3267. var textNode, elementRule, text, sibling, tempNode;
  3268. elementRule = validate ? schema.getElementRule(name) : {};
  3269. if (elementRule) {
  3270. if (blockElements[name]) {
  3271. if (!isInWhiteSpacePreservedElement) {
  3272. // Trim whitespace of the first node in a block
  3273. textNode = node.firstChild;
  3274. if (textNode && textNode.type === 3) {
  3275. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  3276. // Any characters left after trim or should we remove it
  3277. if (text.length > 0) {
  3278. textNode.value = text;
  3279. textNode = textNode.next;
  3280. } else {
  3281. sibling = textNode.next;
  3282. textNode.remove();
  3283. textNode = sibling;
  3284. }
  3285. // Remove any pure whitespace siblings
  3286. while (textNode && textNode.type === 3) {
  3287. text = textNode.value;
  3288. sibling = textNode.next;
  3289. if (text.length === 0 || isAllWhiteSpaceRegExp.test(text)) {
  3290. textNode.remove();
  3291. textNode = sibling;
  3292. }
  3293. textNode = sibling;
  3294. }
  3295. }
  3296. // Trim whitespace of the last node in a block
  3297. textNode = node.lastChild;
  3298. if (textNode && textNode.type === 3) {
  3299. text = textNode.value.replace(endWhiteSpaceRegExp, '');
  3300. // Any characters left after trim or should we remove it
  3301. if (text.length > 0) {
  3302. textNode.value = text;
  3303. textNode = textNode.prev;
  3304. } else {
  3305. sibling = textNode.prev;
  3306. textNode.remove();
  3307. textNode = sibling;
  3308. }
  3309. // Remove any pure whitespace siblings
  3310. while (textNode && textNode.type === 3) {
  3311. text = textNode.value;
  3312. sibling = textNode.prev;
  3313. if (text.length === 0 || isAllWhiteSpaceRegExp.test(text)) {
  3314. textNode.remove();
  3315. textNode = sibling;
  3316. }
  3317. textNode = sibling;
  3318. }
  3319. }
  3320. }
  3321. // Trim start white space
  3322. // Removed due to: #5424
  3323. /*textNode = node.prev;
  3324. if (textNode && textNode.type === 3) {
  3325. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  3326. if (text.length > 0)
  3327. textNode.value = text;
  3328. else
  3329. textNode.remove();
  3330. }*/
  3331. }
  3332. // Check if we exited a whitespace preserved element
  3333. if (isInWhiteSpacePreservedElement && whiteSpaceElements[name]) {
  3334. isInWhiteSpacePreservedElement = false;
  3335. }
  3336. // Handle empty nodes
  3337. if (elementRule.removeEmpty || elementRule.paddEmpty) {
  3338. if (node.isEmpty(nonEmptyElements)) {
  3339. if (elementRule.paddEmpty)
  3340. node.empty().append(new Node('#text', '3')).value = '\u00a0';
  3341. else {
  3342. // Leave nodes that have a name like <a name="name">
  3343. if (!node.attributes.map.name && !node.attributes.map.id) {
  3344. tempNode = node.parent;
  3345. node.empty().remove();
  3346. node = tempNode;
  3347. return;
  3348. }
  3349. }
  3350. }
  3351. }
  3352. node = node.parent;
  3353. }
  3354. }
  3355. }, schema);
  3356. rootNode = node = new Node(args.context || settings.root_name, 11);
  3357. parser.parse(html);
  3358. // Fix invalid children or report invalid children in a contextual parsing
  3359. if (validate && invalidChildren.length) {
  3360. if (!args.context)
  3361. fixInvalidChildren(invalidChildren);
  3362. else
  3363. args.invalid = true;
  3364. }
  3365. // Wrap nodes in the root into block elements if the root is body
  3366. if (rootBlockName && rootNode.name == 'body')
  3367. addRootBlocks();
  3368. // Run filters only when the contents is valid
  3369. if (!args.invalid) {
  3370. // Run node filters
  3371. for (name in matchedNodes) {
  3372. list = nodeFilters[name];
  3373. nodes = matchedNodes[name];
  3374. // Remove already removed children
  3375. fi = nodes.length;
  3376. while (fi--) {
  3377. if (!nodes[fi].parent)
  3378. nodes.splice(fi, 1);
  3379. }
  3380. for (i = 0, l = list.length; i < l; i++)
  3381. list[i](nodes, name, args);
  3382. }
  3383. // Run attribute filters
  3384. for (i = 0, l = attributeFilters.length; i < l; i++) {
  3385. list = attributeFilters[i];
  3386. if (list.name in matchedAttributes) {
  3387. nodes = matchedAttributes[list.name];
  3388. // Remove already removed children
  3389. fi = nodes.length;
  3390. while (fi--) {
  3391. if (!nodes[fi].parent)
  3392. nodes.splice(fi, 1);
  3393. }
  3394. for (fi = 0, fl = list.callbacks.length; fi < fl; fi++)
  3395. list.callbacks[fi](nodes, list.name, args);
  3396. }
  3397. }
  3398. }
  3399. return rootNode;
  3400. };
  3401. // Remove <br> at end of block elements Gecko and WebKit injects BR elements to
  3402. // make it possible to place the caret inside empty blocks. This logic tries to remove
  3403. // these elements and keep br elements that where intended to be there intact
  3404. if (settings.remove_trailing_brs) {
  3405. self.addNodeFilter('br', function(nodes, name) {
  3406. var i, l = nodes.length, node, blockElements = tinymce.extend({}, schema.getBlockElements()),
  3407. nonEmptyElements = schema.getNonEmptyElements(), parent, lastParent, prev, prevName;
  3408. // Remove brs from body element as well
  3409. blockElements.body = 1;
  3410. // Must loop forwards since it will otherwise remove all brs in <p>a<br><br><br></p>
  3411. for (i = 0; i < l; i++) {
  3412. node = nodes[i];
  3413. parent = node.parent;
  3414. if (blockElements[node.parent.name] && node === parent.lastChild) {
  3415. // Loop all nodes to the left of the current node and check for other BR elements
  3416. // excluding bookmarks since they are invisible
  3417. prev = node.prev;
  3418. while (prev) {
  3419. prevName = prev.name;
  3420. // Ignore bookmarks
  3421. if (prevName !== "span" || prev.attr('data-mce-type') !== 'bookmark') {
  3422. // Found a non BR element
  3423. if (prevName !== "br")
  3424. break;
  3425. // Found another br it's a <br><br> structure then don't remove anything
  3426. if (prevName === 'br') {
  3427. node = null;
  3428. break;
  3429. }
  3430. }
  3431. prev = prev.prev;
  3432. }
  3433. if (node) {
  3434. node.remove();
  3435. // Is the parent to be considered empty after we removed the BR
  3436. if (parent.isEmpty(nonEmptyElements)) {
  3437. elementRule = schema.getElementRule(parent.name);
  3438. // Remove or padd the element depending on schema rule
  3439. if (elementRule) {
  3440. if (elementRule.removeEmpty)
  3441. parent.remove();
  3442. else if (elementRule.paddEmpty)
  3443. parent.empty().append(new tinymce.html.Node('#text', 3)).value = '\u00a0';
  3444. }
  3445. }
  3446. }
  3447. } else {
  3448. // Replaces BR elements inside inline elements like <p><b><i><br></i></b></p> so they become <p><b><i>&nbsp;</i></b></p>
  3449. lastParent = node;
  3450. while (parent.firstChild === lastParent && parent.lastChild === lastParent) {
  3451. lastParent = parent;
  3452. if (blockElements[parent.name]) {
  3453. break;
  3454. }
  3455. parent = parent.parent;
  3456. }
  3457. if (lastParent === parent) {
  3458. textNode = new tinymce.html.Node('#text', 3);
  3459. textNode.value = '\u00a0';
  3460. node.replace(textNode);
  3461. }
  3462. }
  3463. }
  3464. });
  3465. }
  3466. // Force anchor names closed, unless the setting "allow_html_in_named_anchor" is explicitly included.
  3467. if (!settings.allow_html_in_named_anchor) {
  3468. self.addAttributeFilter('id,name', function(nodes, name) {
  3469. var i = nodes.length, sibling, prevSibling, parent, node;
  3470. while (i--) {
  3471. node = nodes[i];
  3472. if (node.name === 'a' && node.firstChild && !node.attr('href')) {
  3473. parent = node.parent;
  3474. // Move children after current node
  3475. sibling = node.lastChild;
  3476. do {
  3477. prevSibling = sibling.prev;
  3478. parent.insert(sibling, node);
  3479. sibling = prevSibling;
  3480. } while (sibling);
  3481. }
  3482. }
  3483. });
  3484. }
  3485. }
  3486. })(tinymce);
  3487. tinymce.html.Writer = function(settings) {
  3488. var html = [], indent, indentBefore, indentAfter, encode, htmlOutput;
  3489. settings = settings || {};
  3490. indent = settings.indent;
  3491. indentBefore = tinymce.makeMap(settings.indent_before || '');
  3492. indentAfter = tinymce.makeMap(settings.indent_after || '');
  3493. encode = tinymce.html.Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities);
  3494. htmlOutput = settings.element_format == "html";
  3495. return {
  3496. start: function(name, attrs, empty) {
  3497. var i, l, attr, value;
  3498. if (indent && indentBefore[name] && html.length > 0) {
  3499. value = html[html.length - 1];
  3500. if (value.length > 0 && value !== '\n')
  3501. html.push('\n');
  3502. }
  3503. html.push('<', name);
  3504. if (attrs) {
  3505. for (i = 0, l = attrs.length; i < l; i++) {
  3506. attr = attrs[i];
  3507. html.push(' ', attr.name, '="', encode(attr.value, true), '"');
  3508. }
  3509. }
  3510. if (!empty || htmlOutput)
  3511. html[html.length] = '>';
  3512. else
  3513. html[html.length] = ' />';
  3514. if (empty && indent && indentAfter[name] && html.length > 0) {
  3515. value = html[html.length - 1];
  3516. if (value.length > 0 && value !== '\n')
  3517. html.push('\n');
  3518. }
  3519. },
  3520. end: function(name) {
  3521. var value;
  3522. /*if (indent && indentBefore[name] && html.length > 0) {
  3523. value = html[html.length - 1];
  3524. if (value.length > 0 && value !== '\n')
  3525. html.push('\n');
  3526. }*/
  3527. html.push('</', name, '>');
  3528. if (indent && indentAfter[name] && html.length > 0) {
  3529. value = html[html.length - 1];
  3530. if (value.length > 0 && value !== '\n')
  3531. html.push('\n');
  3532. }
  3533. },
  3534. text: function(text, raw) {
  3535. if (text.length > 0)
  3536. html[html.length] = raw ? text : encode(text);
  3537. },
  3538. cdata: function(text) {
  3539. html.push('<![CDATA[', text, ']]>');
  3540. },
  3541. comment: function(text) {
  3542. html.push('<!--', text, '-->');
  3543. },
  3544. pi: function(name, text) {
  3545. if (text)
  3546. html.push('<?', name, ' ', text, '?>');
  3547. else
  3548. html.push('<?', name, '?>');
  3549. if (indent)
  3550. html.push('\n');
  3551. },
  3552. doctype: function(text) {
  3553. html.push('<!DOCTYPE', text, '>', indent ? '\n' : '');
  3554. },
  3555. reset: function() {
  3556. html.length = 0;
  3557. },
  3558. getContent: function() {
  3559. return html.join('').replace(/\n$/, '');
  3560. }
  3561. };
  3562. };
  3563. (function(tinymce) {
  3564. tinymce.html.Serializer = function(settings, schema) {
  3565. var self = this, writer = new tinymce.html.Writer(settings);
  3566. settings = settings || {};
  3567. settings.validate = "validate" in settings ? settings.validate : true;
  3568. self.schema = schema = schema || new tinymce.html.Schema();
  3569. self.writer = writer;
  3570. self.serialize = function(node) {
  3571. var handlers, validate;
  3572. validate = settings.validate;
  3573. handlers = {
  3574. // #text
  3575. 3: function(node, raw) {
  3576. writer.text(node.value, node.raw);
  3577. },
  3578. // #comment
  3579. 8: function(node) {
  3580. writer.comment(node.value);
  3581. },
  3582. // Processing instruction
  3583. 7: function(node) {
  3584. writer.pi(node.name, node.value);
  3585. },
  3586. // Doctype
  3587. 10: function(node) {
  3588. writer.doctype(node.value);
  3589. },
  3590. // CDATA
  3591. 4: function(node) {
  3592. writer.cdata(node.value);
  3593. },
  3594. // Document fragment
  3595. 11: function(node) {
  3596. if ((node = node.firstChild)) {
  3597. do {
  3598. walk(node);
  3599. } while (node = node.next);
  3600. }
  3601. }
  3602. };
  3603. writer.reset();
  3604. function walk(node) {
  3605. var handler = handlers[node.type], name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule;
  3606. if (!handler) {
  3607. name = node.name;
  3608. isEmpty = node.shortEnded;
  3609. attrs = node.attributes;
  3610. // Sort attributes
  3611. if (validate && attrs && attrs.length > 1) {
  3612. sortedAttrs = [];
  3613. sortedAttrs.map = {};
  3614. elementRule = schema.getElementRule(node.name);
  3615. for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
  3616. attrName = elementRule.attributesOrder[i];
  3617. if (attrName in attrs.map) {
  3618. attrValue = attrs.map[attrName];
  3619. sortedAttrs.map[attrName] = attrValue;
  3620. sortedAttrs.push({name: attrName, value: attrValue});
  3621. }
  3622. }
  3623. for (i = 0, l = attrs.length; i < l; i++) {
  3624. attrName = attrs[i].name;
  3625. if (!(attrName in sortedAttrs.map)) {
  3626. attrValue = attrs.map[attrName];
  3627. sortedAttrs.map[attrName] = attrValue;
  3628. sortedAttrs.push({name: attrName, value: attrValue});
  3629. }
  3630. }
  3631. attrs = sortedAttrs;
  3632. }
  3633. writer.start(node.name, attrs, isEmpty);
  3634. if (!isEmpty) {
  3635. if ((node = node.firstChild)) {
  3636. do {
  3637. walk(node);
  3638. } while (node = node.next);
  3639. }
  3640. writer.end(name);
  3641. }
  3642. } else
  3643. handler(node);
  3644. }
  3645. // Serialize element and treat all non elements as fragments
  3646. if (node.type == 1 && !settings.inner)
  3647. walk(node);
  3648. else
  3649. handlers[11](node);
  3650. return writer.getContent();
  3651. };
  3652. }
  3653. })(tinymce);
  3654. // JSLint defined globals
  3655. /*global tinymce:false, window:false */
  3656. tinymce.dom = {};
  3657. (function(namespace, expando) {
  3658. var w3cEventModel = !!document.addEventListener;
  3659. function addEvent(target, name, callback, capture) {
  3660. if (target.addEventListener) {
  3661. target.addEventListener(name, callback, capture || false);
  3662. } else if (target.attachEvent) {
  3663. target.attachEvent('on' + name, callback);
  3664. }
  3665. }
  3666. function removeEvent(target, name, callback, capture) {
  3667. if (target.removeEventListener) {
  3668. target.removeEventListener(name, callback, capture || false);
  3669. } else if (target.detachEvent) {
  3670. target.detachEvent('on' + name, callback);
  3671. }
  3672. }
  3673. function fix(original_event, data) {
  3674. var name, event = data || {};
  3675. // Dummy function that gets replaced on the delegation state functions
  3676. function returnFalse() {
  3677. return false;
  3678. }
  3679. // Dummy function that gets replaced on the delegation state functions
  3680. function returnTrue() {
  3681. return true;
  3682. }
  3683. // Copy all properties from the original event
  3684. for (name in original_event) {
  3685. // layerX/layerY is deprecated in Chrome and produces a warning
  3686. if (name !== "layerX" && name !== "layerY") {
  3687. event[name] = original_event[name];
  3688. }
  3689. }
  3690. // Normalize target IE uses srcElement
  3691. if (!event.target) {
  3692. event.target = event.srcElement || document;
  3693. }
  3694. // Add preventDefault method
  3695. event.preventDefault = function() {
  3696. event.isDefaultPrevented = returnTrue;
  3697. // Execute preventDefault on the original event object
  3698. if (original_event) {
  3699. if (original_event.preventDefault) {
  3700. original_event.preventDefault();
  3701. } else {
  3702. original_event.returnValue = false; // IE
  3703. }
  3704. }
  3705. };
  3706. // Add stopPropagation
  3707. event.stopPropagation = function() {
  3708. event.isPropagationStopped = returnTrue;
  3709. // Execute stopPropagation on the original event object
  3710. if (original_event) {
  3711. if (original_event.stopPropagation) {
  3712. original_event.stopPropagation();
  3713. } else {
  3714. original_event.cancelBubble = true; // IE
  3715. }
  3716. }
  3717. };
  3718. // Add stopImmediatePropagation
  3719. event.stopImmediatePropagation = function() {
  3720. event.isImmediatePropagationStopped = returnTrue;
  3721. event.stopPropagation();
  3722. };
  3723. // Add event delegation states
  3724. if (!event.isDefaultPrevented) {
  3725. event.isDefaultPrevented = returnFalse;
  3726. event.isPropagationStopped = returnFalse;
  3727. event.isImmediatePropagationStopped = returnFalse;
  3728. }
  3729. return event;
  3730. }
  3731. function bindOnReady(win, callback, event_utils) {
  3732. var doc = win.document, event = {type: 'ready'};
  3733. // Gets called when the DOM is ready
  3734. function readyHandler() {
  3735. if (!event_utils.domLoaded) {
  3736. event_utils.domLoaded = true;
  3737. callback(event);
  3738. }
  3739. }
  3740. // Page already loaded then fire it directly
  3741. if (doc.readyState == "complete") {
  3742. readyHandler();
  3743. return;
  3744. }
  3745. // Use W3C method
  3746. if (w3cEventModel) {
  3747. addEvent(win, 'DOMContentLoaded', readyHandler);
  3748. } else {
  3749. // Use IE method
  3750. addEvent(doc, "readystatechange", function() {
  3751. if (doc.readyState === "complete") {
  3752. removeEvent(doc, "readystatechange", arguments.callee);
  3753. readyHandler();
  3754. }
  3755. });
  3756. // Wait until we can scroll, when we can the DOM is initialized
  3757. if (doc.documentElement.doScroll && win === win.top) {
  3758. (function() {
  3759. try {
  3760. // If IE is used, use the trick by Diego Perini licensed under MIT by request to the author.
  3761. // http://javascript.nwbox.com/IEContentLoaded/
  3762. doc.documentElement.doScroll("left");
  3763. } catch (ex) {
  3764. setTimeout(arguments.callee, 0);
  3765. return;
  3766. }
  3767. readyHandler();
  3768. })();
  3769. }
  3770. }
  3771. // Fallback if any of the above methods should fail for some odd reason
  3772. addEvent(win, 'load', readyHandler);
  3773. }
  3774. function EventUtils(proxy) {
  3775. var self = this, events = {}, count, isFocusBlurBound, hasFocusIn, hasMouseEnterLeave, mouseEnterLeave;
  3776. hasMouseEnterLeave = "onmouseenter" in document.documentElement;
  3777. hasFocusIn = "onfocusin" in document.documentElement;
  3778. mouseEnterLeave = {mouseenter: 'mouseover', mouseleave: 'mouseout'};
  3779. count = 1;
  3780. // State if the DOMContentLoaded was executed or not
  3781. self.domLoaded = false;
  3782. self.events = events;
  3783. function executeHandlers(evt, id) {
  3784. var callbackList, i, l, callback;
  3785. callbackList = events[id][evt.type];
  3786. if (callbackList) {
  3787. for (i = 0, l = callbackList.length; i < l; i++) {
  3788. callback = callbackList[i];
  3789. // Check if callback exists might be removed if a unbind is called inside the callback
  3790. if (callback && callback.func.call(callback.scope, evt) === false) {
  3791. evt.preventDefault();
  3792. }
  3793. // Should we stop propagation to immediate listeners
  3794. if (evt.isImmediatePropagationStopped()) {
  3795. return;
  3796. }
  3797. }
  3798. }
  3799. }
  3800. self.bind = function(target, names, callback, scope) {
  3801. var id, callbackList, i, name, fakeName, nativeHandler, capture, win = window;
  3802. // Native event handler function patches the event and executes the callbacks for the expando
  3803. function defaultNativeHandler(evt) {
  3804. executeHandlers(fix(evt || win.event), id);
  3805. }
  3806. // Don't bind to text nodes or comments
  3807. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  3808. return;
  3809. }
  3810. // Create or get events id for the target
  3811. if (!target[expando]) {
  3812. id = count++;
  3813. target[expando] = id;
  3814. events[id] = {};
  3815. } else {
  3816. id = target[expando];
  3817. if (!events[id]) {
  3818. events[id] = {};
  3819. }
  3820. }
  3821. // Setup the specified scope or use the target as a default
  3822. scope = scope || target;
  3823. // Split names and bind each event, enables you to bind multiple events with one call
  3824. names = names.split(' ');
  3825. i = names.length;
  3826. while (i--) {
  3827. name = names[i];
  3828. nativeHandler = defaultNativeHandler;
  3829. fakeName = capture = false;
  3830. // Use ready instead of DOMContentLoaded
  3831. if (name === "DOMContentLoaded") {
  3832. name = "ready";
  3833. }
  3834. // DOM is already ready
  3835. if ((self.domLoaded || target.readyState == 'complete') && name === "ready") {
  3836. self.domLoaded = true;
  3837. callback.call(scope, fix({type: name}));
  3838. continue;
  3839. }
  3840. // Handle mouseenter/mouseleaver
  3841. if (!hasMouseEnterLeave) {
  3842. fakeName = mouseEnterLeave[name];
  3843. if (fakeName) {
  3844. nativeHandler = function(evt) {
  3845. var current, related;
  3846. current = evt.currentTarget;
  3847. related = evt.relatedTarget;
  3848. // Check if related is inside the current target if it's not then the event should be ignored since it's a mouseover/mouseout inside the element
  3849. if (related && current.contains) {
  3850. // Use contains for performance
  3851. related = current.contains(related);
  3852. } else {
  3853. while (related && related !== current) {
  3854. related = related.parentNode;
  3855. }
  3856. }
  3857. // Fire fake event
  3858. if (!related) {
  3859. evt = fix(evt || win.event);
  3860. evt.type = evt.type === 'mouseout' ? 'mouseleave' : 'mouseenter';
  3861. evt.target = current;
  3862. executeHandlers(evt, id);
  3863. }
  3864. };
  3865. }
  3866. }
  3867. // Fake bubbeling of focusin/focusout
  3868. if (!hasFocusIn && (name === "focusin" || name === "focusout")) {
  3869. capture = true;
  3870. fakeName = name === "focusin" ? "focus" : "blur";
  3871. nativeHandler = function(evt) {
  3872. evt = fix(evt || win.event);
  3873. evt.type = evt.type === 'focus' ? 'focusin' : 'focusout';
  3874. executeHandlers(evt, id);
  3875. };
  3876. }
  3877. // Setup callback list and bind native event
  3878. callbackList = events[id][name];
  3879. if (!callbackList) {
  3880. events[id][name] = callbackList = [{func: callback, scope: scope}];
  3881. callbackList.fakeName = fakeName;
  3882. callbackList.capture = capture;
  3883. // Add the nativeHandler to the callback list so that we can later unbind it
  3884. callbackList.nativeHandler = nativeHandler;
  3885. if (!w3cEventModel) {
  3886. callbackList.proxyHandler = proxy(id);
  3887. }
  3888. // Check if the target has native events support
  3889. if (name === "ready") {
  3890. bindOnReady(target, nativeHandler, self);
  3891. } else {
  3892. addEvent(target, fakeName || name, w3cEventModel ? nativeHandler : callbackList.proxyHandler, capture);
  3893. }
  3894. } else {
  3895. // If it already has an native handler then just push the callback
  3896. callbackList.push({func: callback, scope: scope});
  3897. }
  3898. }
  3899. target = callbackList = 0; // Clean memory for IE
  3900. return callback;
  3901. };
  3902. self.unbind = function(target, names, callback) {
  3903. var id, callbackList, i, ci, name, eventMap;
  3904. // Don't bind to text nodes or comments
  3905. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  3906. return self;
  3907. }
  3908. // Unbind event or events if the target has the expando
  3909. id = target[expando];
  3910. if (id) {
  3911. eventMap = events[id];
  3912. // Specific callback
  3913. if (names) {
  3914. names = names.split(' ');
  3915. i = names.length;
  3916. while (i--) {
  3917. name = names[i];
  3918. callbackList = eventMap[name];
  3919. // Unbind the event if it exists in the map
  3920. if (callbackList) {
  3921. // Remove specified callback
  3922. if (callback) {
  3923. ci = callbackList.length;
  3924. while (ci--) {
  3925. if (callbackList[ci].func === callback) {
  3926. callbackList.splice(ci, 1);
  3927. }
  3928. }
  3929. }
  3930. // Remove all callbacks if there isn't a specified callback or there is no callbacks left
  3931. if (!callback || callbackList.length === 0) {
  3932. delete eventMap[name];
  3933. removeEvent(target, callbackList.fakeName || name, w3cEventModel ? callbackList.nativeHandler : callbackList.proxyHandler, callbackList.capture);
  3934. }
  3935. }
  3936. }
  3937. } else {
  3938. // All events for a specific element
  3939. for (name in eventMap) {
  3940. callbackList = eventMap[name];
  3941. removeEvent(target, callbackList.fakeName || name, w3cEventModel ? callbackList.nativeHandler : callbackList.proxyHandler, callbackList.capture);
  3942. }
  3943. eventMap = {};
  3944. }
  3945. // Check if object is empty, if it isn't then we won't remove the expando map
  3946. for (name in eventMap) {
  3947. return self;
  3948. }
  3949. // Delete event object
  3950. delete events[id];
  3951. // Remove expando from target
  3952. try {
  3953. // IE will fail here since it can't delete properties from window
  3954. delete target[expando];
  3955. } catch (ex) {
  3956. // IE will set it to null
  3957. target[expando] = null;
  3958. }
  3959. }
  3960. return self;
  3961. };
  3962. self.fire = function(target, name, args) {
  3963. var id, event;
  3964. // Don't bind to text nodes or comments
  3965. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  3966. return self;
  3967. }
  3968. // Build event object by patching the args
  3969. event = fix(null, args);
  3970. event.type = name;
  3971. do {
  3972. // Found an expando that means there is listeners to execute
  3973. id = target[expando];
  3974. if (id) {
  3975. executeHandlers(event, id);
  3976. }
  3977. // Walk up the DOM
  3978. target = target.parentNode || target.ownerDocument || target.defaultView || target.parentWindow;
  3979. } while (target && !event.isPropagationStopped());
  3980. return self;
  3981. };
  3982. self.clean = function(target) {
  3983. var i, children, unbind = self.unbind;
  3984. // Don't bind to text nodes or comments
  3985. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  3986. return self;
  3987. }
  3988. // Unbind any element on the specificed target
  3989. if (target[expando]) {
  3990. unbind(target);
  3991. }
  3992. // Target doesn't have getElementsByTagName it's probably a window object then use it's document to find the children
  3993. if (!target.getElementsByTagName) {
  3994. target = target.document;
  3995. }
  3996. // Remove events from each child element
  3997. if (target && target.getElementsByTagName) {
  3998. unbind(target);
  3999. children = target.getElementsByTagName('*');
  4000. i = children.length;
  4001. while (i--) {
  4002. target = children[i];
  4003. if (target[expando]) {
  4004. unbind(target);
  4005. }
  4006. }
  4007. }
  4008. return self;
  4009. };
  4010. self.callNativeHandler = function(id, evt) {
  4011. if (events) {
  4012. events[id][evt.type].nativeHandler(evt);
  4013. }
  4014. };
  4015. self.destory = function() {
  4016. events = {};
  4017. };
  4018. // Legacy function calls
  4019. self.add = function(target, events, func, scope) {
  4020. // Old API supported direct ID assignment
  4021. if (typeof(target) === "string") {
  4022. target = document.getElementById(target);
  4023. }
  4024. // Old API supported multiple targets
  4025. if (target && target instanceof Array) {
  4026. var i = target.length;
  4027. while (i--) {
  4028. self.add(target[i], events, func, scope);
  4029. }
  4030. return;
  4031. }
  4032. // Old API called ready init
  4033. if (events === "init") {
  4034. events = "ready";
  4035. }
  4036. return self.bind(target, events instanceof Array ? events.join(' ') : events, func, scope);
  4037. };
  4038. self.remove = function(target, events, func, scope) {
  4039. if (!target) {
  4040. return self;
  4041. }
  4042. // Old API supported direct ID assignment
  4043. if (typeof(target) === "string") {
  4044. target = document.getElementById(target);
  4045. }
  4046. // Old API supported multiple targets
  4047. if (target instanceof Array) {
  4048. var i = target.length;
  4049. while (i--) {
  4050. self.remove(target[i], events, func, scope);
  4051. }
  4052. return self;
  4053. }
  4054. return self.unbind(target, events instanceof Array ? events.join(' ') : events, func);
  4055. };
  4056. self.clear = function(target) {
  4057. // Old API supported direct ID assignment
  4058. if (typeof(target) === "string") {
  4059. target = document.getElementById(target);
  4060. }
  4061. return self.clean(target);
  4062. };
  4063. self.cancel = function(e) {
  4064. if (e) {
  4065. self.prevent(e);
  4066. self.stop(e);
  4067. }
  4068. return false;
  4069. };
  4070. self.prevent = function(e) {
  4071. if (!e.preventDefault) {
  4072. e = fix(e);
  4073. }
  4074. e.preventDefault();
  4075. return false;
  4076. };
  4077. self.stop = function(e) {
  4078. if (!e.stopPropagation) {
  4079. e = fix(e);
  4080. }
  4081. e.stopPropagation();
  4082. return false;
  4083. };
  4084. }
  4085. namespace.EventUtils = EventUtils;
  4086. namespace.Event = new EventUtils(function(id) {
  4087. return function(evt) {
  4088. tinymce.dom.Event.callNativeHandler(id, evt);
  4089. };
  4090. });
  4091. // Bind ready event when tinymce script is loaded
  4092. namespace.Event.bind(window, 'ready', function() {});
  4093. namespace = 0;
  4094. })(tinymce.dom, 'data-mce-expando'); // Namespace and expando
  4095. tinymce.dom.TreeWalker = function(start_node, root_node) {
  4096. var node = start_node;
  4097. function findSibling(node, start_name, sibling_name, shallow) {
  4098. var sibling, parent;
  4099. if (node) {
  4100. // Walk into nodes if it has a start
  4101. if (!shallow && node[start_name])
  4102. return node[start_name];
  4103. // Return the sibling if it has one
  4104. if (node != root_node) {
  4105. sibling = node[sibling_name];
  4106. if (sibling)
  4107. return sibling;
  4108. // Walk up the parents to look for siblings
  4109. for (parent = node.parentNode; parent && parent != root_node; parent = parent.parentNode) {
  4110. sibling = parent[sibling_name];
  4111. if (sibling)
  4112. return sibling;
  4113. }
  4114. }
  4115. }
  4116. };
  4117. this.current = function() {
  4118. return node;
  4119. };
  4120. this.next = function(shallow) {
  4121. return (node = findSibling(node, 'firstChild', 'nextSibling', shallow));
  4122. };
  4123. this.prev = function(shallow) {
  4124. return (node = findSibling(node, 'lastChild', 'previousSibling', shallow));
  4125. };
  4126. };
  4127. (function(tinymce) {
  4128. // Shorten names
  4129. var each = tinymce.each,
  4130. is = tinymce.is,
  4131. isWebKit = tinymce.isWebKit,
  4132. isIE = tinymce.isIE,
  4133. Entities = tinymce.html.Entities,
  4134. simpleSelectorRe = /^([a-z0-9],?)+$/i,
  4135. whiteSpaceRegExp = /^[ \t\r\n]*$/;
  4136. tinymce.create('tinymce.dom.DOMUtils', {
  4137. doc : null,
  4138. root : null,
  4139. files : null,
  4140. pixelStyles : /^(top|left|bottom|right|width|height|borderWidth)$/,
  4141. props : {
  4142. "for" : "htmlFor",
  4143. "class" : "className",
  4144. className : "className",
  4145. checked : "checked",
  4146. disabled : "disabled",
  4147. maxlength : "maxLength",
  4148. readonly : "readOnly",
  4149. selected : "selected",
  4150. value : "value",
  4151. id : "id",
  4152. name : "name",
  4153. type : "type"
  4154. },
  4155. DOMUtils : function(d, s) {
  4156. var t = this, globalStyle, name, blockElementsMap;
  4157. t.doc = d;
  4158. t.win = window;
  4159. t.files = {};
  4160. t.cssFlicker = false;
  4161. t.counter = 0;
  4162. t.stdMode = !tinymce.isIE || d.documentMode >= 8;
  4163. t.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat" || t.stdMode;
  4164. t.hasOuterHTML = "outerHTML" in d.createElement("a");
  4165. t.settings = s = tinymce.extend({
  4166. keep_values : false,
  4167. hex_colors : 1
  4168. }, s);
  4169. t.schema = s.schema;
  4170. t.styles = new tinymce.html.Styles({
  4171. url_converter : s.url_converter,
  4172. url_converter_scope : s.url_converter_scope
  4173. }, s.schema);
  4174. // Fix IE6SP2 flicker and check it failed for pre SP2
  4175. if (tinymce.isIE6) {
  4176. try {
  4177. d.execCommand('BackgroundImageCache', false, true);
  4178. } catch (e) {
  4179. t.cssFlicker = true;
  4180. }
  4181. }
  4182. t.fixDoc(d);
  4183. t.events = s.ownEvents ? new tinymce.dom.EventUtils(s.proxy) : tinymce.dom.Event;
  4184. tinymce.addUnload(t.destroy, t);
  4185. blockElementsMap = s.schema ? s.schema.getBlockElements() : {};
  4186. t.isBlock = function(node) {
  4187. // Fix for #5446
  4188. if (!node) {
  4189. return false;
  4190. }
  4191. // This function is called in module pattern style since it might be executed with the wrong this scope
  4192. var type = node.nodeType;
  4193. // If it's a node then check the type and use the nodeName
  4194. if (type)
  4195. return !!(type === 1 && blockElementsMap[node.nodeName]);
  4196. return !!blockElementsMap[node];
  4197. };
  4198. },
  4199. fixDoc: function(doc) {
  4200. var settings = this.settings, name;
  4201. if (isIE && settings.schema) {
  4202. // Add missing HTML 4/5 elements to IE
  4203. ('abbr article aside audio canvas ' +
  4204. 'details figcaption figure footer ' +
  4205. 'header hgroup mark menu meter nav ' +
  4206. 'output progress section summary ' +
  4207. 'time video').replace(/\w+/g, function(name) {
  4208. doc.createElement(name);
  4209. });
  4210. // Create all custom elements
  4211. for (name in settings.schema.getCustomElements()) {
  4212. doc.createElement(name);
  4213. }
  4214. }
  4215. },
  4216. clone: function(node, deep) {
  4217. var self = this, clone, doc;
  4218. // TODO: Add feature detection here in the future
  4219. if (!isIE || node.nodeType !== 1 || deep) {
  4220. return node.cloneNode(deep);
  4221. }
  4222. doc = self.doc;
  4223. // Make a HTML5 safe shallow copy
  4224. if (!deep) {
  4225. clone = doc.createElement(node.nodeName);
  4226. // Copy attribs
  4227. each(self.getAttribs(node), function(attr) {
  4228. self.setAttrib(clone, attr.nodeName, self.getAttrib(node, attr.nodeName));
  4229. });
  4230. return clone;
  4231. }
  4232. /*
  4233. // Setup HTML5 patched document fragment
  4234. if (!self.frag) {
  4235. self.frag = doc.createDocumentFragment();
  4236. self.fixDoc(self.frag);
  4237. }
  4238. // Make a deep copy by adding it to the document fragment then removing it this removed the :section
  4239. clone = doc.createElement('div');
  4240. self.frag.appendChild(clone);
  4241. clone.innerHTML = node.outerHTML;
  4242. self.frag.removeChild(clone);
  4243. */
  4244. return clone.firstChild;
  4245. },
  4246. getRoot : function() {
  4247. var t = this, s = t.settings;
  4248. return (s && t.get(s.root_element)) || t.doc.body;
  4249. },
  4250. getViewPort : function(w) {
  4251. var d, b;
  4252. w = !w ? this.win : w;
  4253. d = w.document;
  4254. b = this.boxModel ? d.documentElement : d.body;
  4255. // Returns viewport size excluding scrollbars
  4256. return {
  4257. x : w.pageXOffset || b.scrollLeft,
  4258. y : w.pageYOffset || b.scrollTop,
  4259. w : w.innerWidth || b.clientWidth,
  4260. h : w.innerHeight || b.clientHeight
  4261. };
  4262. },
  4263. getRect : function(e) {
  4264. var p, t = this, sr;
  4265. e = t.get(e);
  4266. p = t.getPos(e);
  4267. sr = t.getSize(e);
  4268. return {
  4269. x : p.x,
  4270. y : p.y,
  4271. w : sr.w,
  4272. h : sr.h
  4273. };
  4274. },
  4275. getSize : function(e) {
  4276. var t = this, w, h;
  4277. e = t.get(e);
  4278. w = t.getStyle(e, 'width');
  4279. h = t.getStyle(e, 'height');
  4280. // Non pixel value, then force offset/clientWidth
  4281. if (w.indexOf('px') === -1)
  4282. w = 0;
  4283. // Non pixel value, then force offset/clientWidth
  4284. if (h.indexOf('px') === -1)
  4285. h = 0;
  4286. return {
  4287. w : parseInt(w, 10) || e.offsetWidth || e.clientWidth,
  4288. h : parseInt(h, 10) || e.offsetHeight || e.clientHeight
  4289. };
  4290. },
  4291. getParent : function(n, f, r) {
  4292. return this.getParents(n, f, r, false);
  4293. },
  4294. getParents : function(n, f, r, c) {
  4295. var t = this, na, se = t.settings, o = [];
  4296. n = t.get(n);
  4297. c = c === undefined;
  4298. if (se.strict_root)
  4299. r = r || t.getRoot();
  4300. // Wrap node name as func
  4301. if (is(f, 'string')) {
  4302. na = f;
  4303. if (f === '*') {
  4304. f = function(n) {return n.nodeType == 1;};
  4305. } else {
  4306. f = function(n) {
  4307. return t.is(n, na);
  4308. };
  4309. }
  4310. }
  4311. while (n) {
  4312. if (n == r || !n.nodeType || n.nodeType === 9)
  4313. break;
  4314. if (!f || f(n)) {
  4315. if (c)
  4316. o.push(n);
  4317. else
  4318. return n;
  4319. }
  4320. n = n.parentNode;
  4321. }
  4322. return c ? o : null;
  4323. },
  4324. get : function(e) {
  4325. var n;
  4326. if (e && this.doc && typeof(e) == 'string') {
  4327. n = e;
  4328. e = this.doc.getElementById(e);
  4329. // IE and Opera returns meta elements when they match the specified input ID, but getElementsByName seems to do the trick
  4330. if (e && e.id !== n)
  4331. return this.doc.getElementsByName(n)[1];
  4332. }
  4333. return e;
  4334. },
  4335. getNext : function(node, selector) {
  4336. return this._findSib(node, selector, 'nextSibling');
  4337. },
  4338. getPrev : function(node, selector) {
  4339. return this._findSib(node, selector, 'previousSibling');
  4340. },
  4341. select : function(pa, s) {
  4342. var t = this;
  4343. return tinymce.dom.Sizzle(pa, t.get(s) || t.get(t.settings.root_element) || t.doc, []);
  4344. },
  4345. is : function(n, selector) {
  4346. var i;
  4347. // If it isn't an array then try to do some simple selectors instead of Sizzle for to boost performance
  4348. if (n.length === undefined) {
  4349. // Simple all selector
  4350. if (selector === '*')
  4351. return n.nodeType == 1;
  4352. // Simple selector just elements
  4353. if (simpleSelectorRe.test(selector)) {
  4354. selector = selector.toLowerCase().split(/,/);
  4355. n = n.nodeName.toLowerCase();
  4356. for (i = selector.length - 1; i >= 0; i--) {
  4357. if (selector[i] == n)
  4358. return true;
  4359. }
  4360. return false;
  4361. }
  4362. }
  4363. return tinymce.dom.Sizzle.matches(selector, n.nodeType ? [n] : n).length > 0;
  4364. },
  4365. add : function(p, n, a, h, c) {
  4366. var t = this;
  4367. return this.run(p, function(p) {
  4368. var e, k;
  4369. e = is(n, 'string') ? t.doc.createElement(n) : n;
  4370. t.setAttribs(e, a);
  4371. if (h) {
  4372. if (h.nodeType)
  4373. e.appendChild(h);
  4374. else
  4375. t.setHTML(e, h);
  4376. }
  4377. return !c ? p.appendChild(e) : e;
  4378. });
  4379. },
  4380. create : function(n, a, h) {
  4381. return this.add(this.doc.createElement(n), n, a, h, 1);
  4382. },
  4383. createHTML : function(n, a, h) {
  4384. var o = '', t = this, k;
  4385. o += '<' + n;
  4386. for (k in a) {
  4387. if (a.hasOwnProperty(k))
  4388. o += ' ' + k + '="' + t.encode(a[k]) + '"';
  4389. }
  4390. // A call to tinymce.is doesn't work for some odd reason on IE9 possible bug inside their JS runtime
  4391. if (typeof(h) != "undefined")
  4392. return o + '>' + h + '</' + n + '>';
  4393. return o + ' />';
  4394. },
  4395. remove : function(node, keep_children) {
  4396. return this.run(node, function(node) {
  4397. var child, parent = node.parentNode;
  4398. if (!parent)
  4399. return null;
  4400. if (keep_children) {
  4401. while (child = node.firstChild) {
  4402. // IE 8 will crash if you don't remove completely empty text nodes
  4403. if (!tinymce.isIE || child.nodeType !== 3 || child.nodeValue)
  4404. parent.insertBefore(child, node);
  4405. else
  4406. node.removeChild(child);
  4407. }
  4408. }
  4409. return parent.removeChild(node);
  4410. });
  4411. },
  4412. setStyle : function(n, na, v) {
  4413. var t = this;
  4414. return t.run(n, function(e) {
  4415. var s, i;
  4416. s = e.style;
  4417. // Camelcase it, if needed
  4418. na = na.replace(/-(\D)/g, function(a, b){
  4419. return b.toUpperCase();
  4420. });
  4421. // Default px suffix on these
  4422. if (t.pixelStyles.test(na) && (tinymce.is(v, 'number') || /^[\-0-9\.]+$/.test(v)))
  4423. v += 'px';
  4424. switch (na) {
  4425. case 'opacity':
  4426. // IE specific opacity
  4427. if (isIE) {
  4428. s.filter = v === '' ? '' : "alpha(opacity=" + (v * 100) + ")";
  4429. if (!n.currentStyle || !n.currentStyle.hasLayout)
  4430. s.display = 'inline-block';
  4431. }
  4432. // Fix for older browsers
  4433. s[na] = s['-moz-opacity'] = s['-khtml-opacity'] = v || '';
  4434. break;
  4435. case 'float':
  4436. isIE ? s.styleFloat = v : s.cssFloat = v;
  4437. break;
  4438. default:
  4439. s[na] = v || '';
  4440. }
  4441. // Force update of the style data
  4442. if (t.settings.update_styles)
  4443. t.setAttrib(e, 'data-mce-style');
  4444. });
  4445. },
  4446. getStyle : function(n, na, c) {
  4447. n = this.get(n);
  4448. if (!n)
  4449. return;
  4450. // Gecko
  4451. if (this.doc.defaultView && c) {
  4452. // Remove camelcase
  4453. na = na.replace(/[A-Z]/g, function(a){
  4454. return '-' + a;
  4455. });
  4456. try {
  4457. return this.doc.defaultView.getComputedStyle(n, null).getPropertyValue(na);
  4458. } catch (ex) {
  4459. // Old safari might fail
  4460. return null;
  4461. }
  4462. }
  4463. // Camelcase it, if needed
  4464. na = na.replace(/-(\D)/g, function(a, b){
  4465. return b.toUpperCase();
  4466. });
  4467. if (na == 'float')
  4468. na = isIE ? 'styleFloat' : 'cssFloat';
  4469. // IE & Opera
  4470. if (n.currentStyle && c)
  4471. return n.currentStyle[na];
  4472. return n.style ? n.style[na] : undefined;
  4473. },
  4474. setStyles : function(e, o) {
  4475. var t = this, s = t.settings, ol;
  4476. ol = s.update_styles;
  4477. s.update_styles = 0;
  4478. each(o, function(v, n) {
  4479. t.setStyle(e, n, v);
  4480. });
  4481. // Update style info
  4482. s.update_styles = ol;
  4483. if (s.update_styles)
  4484. t.setAttrib(e, s.cssText);
  4485. },
  4486. removeAllAttribs: function(e) {
  4487. return this.run(e, function(e) {
  4488. var i, attrs = e.attributes;
  4489. for (i = attrs.length - 1; i >= 0; i--) {
  4490. e.removeAttributeNode(attrs.item(i));
  4491. }
  4492. });
  4493. },
  4494. setAttrib : function(e, n, v) {
  4495. var t = this;
  4496. // Whats the point
  4497. if (!e || !n)
  4498. return;
  4499. // Strict XML mode
  4500. if (t.settings.strict)
  4501. n = n.toLowerCase();
  4502. return this.run(e, function(e) {
  4503. var s = t.settings;
  4504. var originalValue = e.getAttribute(n);
  4505. if (v !== null) {
  4506. switch (n) {
  4507. case "style":
  4508. if (!is(v, 'string')) {
  4509. each(v, function(v, n) {
  4510. t.setStyle(e, n, v);
  4511. });
  4512. return;
  4513. }
  4514. // No mce_style for elements with these since they might get resized by the user
  4515. if (s.keep_values) {
  4516. if (v && !t._isRes(v))
  4517. e.setAttribute('data-mce-style', v, 2);
  4518. else
  4519. e.removeAttribute('data-mce-style', 2);
  4520. }
  4521. e.style.cssText = v;
  4522. break;
  4523. case "class":
  4524. e.className = v || ''; // Fix IE null bug
  4525. break;
  4526. case "src":
  4527. case "href":
  4528. if (s.keep_values) {
  4529. if (s.url_converter)
  4530. v = s.url_converter.call(s.url_converter_scope || t, v, n, e);
  4531. t.setAttrib(e, 'data-mce-' + n, v, 2);
  4532. }
  4533. break;
  4534. case "shape":
  4535. e.setAttribute('data-mce-style', v);
  4536. break;
  4537. }
  4538. }
  4539. if (is(v) && v !== null && v.length !== 0)
  4540. e.setAttribute(n, '' + v, 2);
  4541. else
  4542. e.removeAttribute(n, 2);
  4543. // fire onChangeAttrib event for attributes that have changed
  4544. if (tinyMCE.activeEditor && originalValue != v) {
  4545. var ed = tinyMCE.activeEditor;
  4546. ed.onSetAttrib.dispatch(ed, e, n, v);
  4547. }
  4548. });
  4549. },
  4550. setAttribs : function(e, o) {
  4551. var t = this;
  4552. return this.run(e, function(e) {
  4553. each(o, function(v, n) {
  4554. t.setAttrib(e, n, v);
  4555. });
  4556. });
  4557. },
  4558. getAttrib : function(e, n, dv) {
  4559. var v, t = this, undef;
  4560. e = t.get(e);
  4561. if (!e || e.nodeType !== 1)
  4562. return dv === undef ? false : dv;
  4563. if (!is(dv))
  4564. dv = '';
  4565. // Try the mce variant for these
  4566. if (/^(src|href|style|coords|shape)$/.test(n)) {
  4567. v = e.getAttribute("data-mce-" + n);
  4568. if (v)
  4569. return v;
  4570. }
  4571. if (isIE && t.props[n]) {
  4572. v = e[t.props[n]];
  4573. v = v && v.nodeValue ? v.nodeValue : v;
  4574. }
  4575. if (!v)
  4576. v = e.getAttribute(n, 2);
  4577. // Check boolean attribs
  4578. if (/^(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)$/.test(n)) {
  4579. if (e[t.props[n]] === true && v === '')
  4580. return n;
  4581. return v ? n : '';
  4582. }
  4583. // Inner input elements will override attributes on form elements
  4584. if (e.nodeName === "FORM" && e.getAttributeNode(n))
  4585. return e.getAttributeNode(n).nodeValue;
  4586. if (n === 'style') {
  4587. v = v || e.style.cssText;
  4588. if (v) {
  4589. v = t.serializeStyle(t.parseStyle(v), e.nodeName);
  4590. if (t.settings.keep_values && !t._isRes(v))
  4591. e.setAttribute('data-mce-style', v);
  4592. }
  4593. }
  4594. // Remove Apple and WebKit stuff
  4595. if (isWebKit && n === "class" && v)
  4596. v = v.replace(/(apple|webkit)\-[a-z\-]+/gi, '');
  4597. // Handle IE issues
  4598. if (isIE) {
  4599. switch (n) {
  4600. case 'rowspan':
  4601. case 'colspan':
  4602. // IE returns 1 as default value
  4603. if (v === 1)
  4604. v = '';
  4605. break;
  4606. case 'size':
  4607. // IE returns +0 as default value for size
  4608. if (v === '+0' || v === 20 || v === 0)
  4609. v = '';
  4610. break;
  4611. case 'width':
  4612. case 'height':
  4613. case 'vspace':
  4614. case 'checked':
  4615. case 'disabled':
  4616. case 'readonly':
  4617. if (v === 0)
  4618. v = '';
  4619. break;
  4620. case 'hspace':
  4621. // IE returns -1 as default value
  4622. if (v === -1)
  4623. v = '';
  4624. break;
  4625. case 'maxlength':
  4626. case 'tabindex':
  4627. // IE returns default value
  4628. if (v === 32768 || v === 2147483647 || v === '32768')
  4629. v = '';
  4630. break;
  4631. case 'multiple':
  4632. case 'compact':
  4633. case 'noshade':
  4634. case 'nowrap':
  4635. if (v === 65535)
  4636. return n;
  4637. return dv;
  4638. case 'shape':
  4639. v = v.toLowerCase();
  4640. break;
  4641. default:
  4642. // IE has odd anonymous function for event attributes
  4643. if (n.indexOf('on') === 0 && v)
  4644. v = tinymce._replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1', '' + v);
  4645. }
  4646. }
  4647. return (v !== undef && v !== null && v !== '') ? '' + v : dv;
  4648. },
  4649. getPos : function(n, ro) {
  4650. var t = this, x = 0, y = 0, e, d = t.doc, r;
  4651. n = t.get(n);
  4652. ro = ro || d.body;
  4653. if (n) {
  4654. // Use getBoundingClientRect if it exists since it's faster than looping offset nodes
  4655. if (n.getBoundingClientRect) {
  4656. n = n.getBoundingClientRect();
  4657. e = t.boxModel ? d.documentElement : d.body;
  4658. // Add scroll offsets from documentElement or body since IE with the wrong box model will use d.body and so do WebKit
  4659. // Also remove the body/documentelement clientTop/clientLeft on IE 6, 7 since they offset the position
  4660. x = n.left + (d.documentElement.scrollLeft || d.body.scrollLeft) - e.clientTop;
  4661. y = n.top + (d.documentElement.scrollTop || d.body.scrollTop) - e.clientLeft;
  4662. return {x : x, y : y};
  4663. }
  4664. r = n;
  4665. while (r && r != ro && r.nodeType) {
  4666. x += r.offsetLeft || 0;
  4667. y += r.offsetTop || 0;
  4668. r = r.offsetParent;
  4669. }
  4670. r = n.parentNode;
  4671. while (r && r != ro && r.nodeType) {
  4672. x -= r.scrollLeft || 0;
  4673. y -= r.scrollTop || 0;
  4674. r = r.parentNode;
  4675. }
  4676. }
  4677. return {x : x, y : y};
  4678. },
  4679. parseStyle : function(st) {
  4680. return this.styles.parse(st);
  4681. },
  4682. serializeStyle : function(o, name) {
  4683. return this.styles.serialize(o, name);
  4684. },
  4685. addStyle: function(cssText) {
  4686. var doc = this.doc, head;
  4687. // Create style element if needed
  4688. styleElm = doc.getElementById('mceDefaultStyles');
  4689. if (!styleElm) {
  4690. styleElm = doc.createElement('style'),
  4691. styleElm.id = 'mceDefaultStyles';
  4692. styleElm.type = 'text/css';
  4693. head = doc.getElementsByTagName('head')[0];
  4694. if (head.firstChild) {
  4695. head.insertBefore(styleElm, head.firstChild);
  4696. } else {
  4697. head.appendChild(styleElm);
  4698. }
  4699. }
  4700. // Append style data to old or new style element
  4701. if (styleElm.styleSheet) {
  4702. styleElm.styleSheet.cssText += cssText;
  4703. } else {
  4704. styleElm.appendChild(doc.createTextNode(cssText));
  4705. }
  4706. },
  4707. loadCSS : function(u) {
  4708. var t = this, d = t.doc, head;
  4709. if (!u)
  4710. u = '';
  4711. head = d.getElementsByTagName('head')[0];
  4712. each(u.split(','), function(u) {
  4713. var link;
  4714. if (t.files[u])
  4715. return;
  4716. t.files[u] = true;
  4717. link = t.create('link', {rel : 'stylesheet', href : tinymce._addVer(u)});
  4718. // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug
  4719. // This fix seems to resolve that issue by realcing the document ones a stylesheet finishes loading
  4720. // It's ugly but it seems to work fine.
  4721. if (isIE && d.documentMode && d.recalc) {
  4722. link.onload = function() {
  4723. if (d.recalc)
  4724. d.recalc();
  4725. link.onload = null;
  4726. };
  4727. }
  4728. head.appendChild(link);
  4729. });
  4730. },
  4731. addClass : function(e, c) {
  4732. return this.run(e, function(e) {
  4733. var o;
  4734. if (!c)
  4735. return 0;
  4736. if (this.hasClass(e, c))
  4737. return e.className;
  4738. o = this.removeClass(e, c);
  4739. return e.className = (o != '' ? (o + ' ') : '') + c;
  4740. });
  4741. },
  4742. removeClass : function(e, c) {
  4743. var t = this, re;
  4744. return t.run(e, function(e) {
  4745. var v;
  4746. if (t.hasClass(e, c)) {
  4747. if (!re)
  4748. re = new RegExp("(^|\\s+)" + c + "(\\s+|$)", "g");
  4749. v = e.className.replace(re, ' ');
  4750. v = tinymce.trim(v != ' ' ? v : '');
  4751. e.className = v;
  4752. // Empty class attr
  4753. if (!v) {
  4754. e.removeAttribute('class');
  4755. e.removeAttribute('className');
  4756. }
  4757. return v;
  4758. }
  4759. return e.className;
  4760. });
  4761. },
  4762. hasClass : function(n, c) {
  4763. n = this.get(n);
  4764. if (!n || !c)
  4765. return false;
  4766. return (' ' + n.className + ' ').indexOf(' ' + c + ' ') !== -1;
  4767. },
  4768. show : function(e) {
  4769. return this.setStyle(e, 'display', 'block');
  4770. },
  4771. hide : function(e) {
  4772. return this.setStyle(e, 'display', 'none');
  4773. },
  4774. isHidden : function(e) {
  4775. e = this.get(e);
  4776. return !e || e.style.display == 'none' || this.getStyle(e, 'display') == 'none';
  4777. },
  4778. uniqueId : function(p) {
  4779. return (!p ? 'mce_' : p) + (this.counter++);
  4780. },
  4781. setHTML : function(element, html) {
  4782. var self = this;
  4783. return self.run(element, function(element) {
  4784. if (isIE) {
  4785. // Remove all child nodes, IE keeps empty text nodes in DOM
  4786. while (element.firstChild)
  4787. element.removeChild(element.firstChild);
  4788. try {
  4789. // IE will remove comments from the beginning
  4790. // unless you padd the contents with something
  4791. element.innerHTML = '<br />' + html;
  4792. element.removeChild(element.firstChild);
  4793. } catch (ex) {
  4794. // 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
  4795. // This seems to fix this problem
  4796. // Create new div with HTML contents and a BR infront to keep comments
  4797. var newElement = self.create('div');
  4798. newElement.innerHTML = '<br />' + html;
  4799. // Add all children from div to target
  4800. each (tinymce.grep(newElement.childNodes), function(node, i) {
  4801. // Skip br element
  4802. if (i && element.canHaveHTML)
  4803. element.appendChild(node);
  4804. });
  4805. }
  4806. } else
  4807. element.innerHTML = html;
  4808. return html;
  4809. });
  4810. },
  4811. getOuterHTML : function(elm) {
  4812. var doc, self = this;
  4813. elm = self.get(elm);
  4814. if (!elm)
  4815. return null;
  4816. if (elm.nodeType === 1 && self.hasOuterHTML)
  4817. return elm.outerHTML;
  4818. doc = (elm.ownerDocument || self.doc).createElement("body");
  4819. doc.appendChild(elm.cloneNode(true));
  4820. return doc.innerHTML;
  4821. },
  4822. setOuterHTML : function(e, h, d) {
  4823. var t = this;
  4824. function setHTML(e, h, d) {
  4825. var n, tp;
  4826. tp = d.createElement("body");
  4827. tp.innerHTML = h;
  4828. n = tp.lastChild;
  4829. while (n) {
  4830. t.insertAfter(n.cloneNode(true), e);
  4831. n = n.previousSibling;
  4832. }
  4833. t.remove(e);
  4834. };
  4835. return this.run(e, function(e) {
  4836. e = t.get(e);
  4837. // Only set HTML on elements
  4838. if (e.nodeType == 1) {
  4839. d = d || e.ownerDocument || t.doc;
  4840. if (isIE) {
  4841. try {
  4842. // Try outerHTML for IE it sometimes produces an unknown runtime error
  4843. if (isIE && e.nodeType == 1)
  4844. e.outerHTML = h;
  4845. else
  4846. setHTML(e, h, d);
  4847. } catch (ex) {
  4848. // Fix for unknown runtime error
  4849. setHTML(e, h, d);
  4850. }
  4851. } else
  4852. setHTML(e, h, d);
  4853. }
  4854. });
  4855. },
  4856. decode : Entities.decode,
  4857. encode : Entities.encodeAllRaw,
  4858. insertAfter : function(node, reference_node) {
  4859. reference_node = this.get(reference_node);
  4860. return this.run(node, function(node) {
  4861. var parent, nextSibling;
  4862. parent = reference_node.parentNode;
  4863. nextSibling = reference_node.nextSibling;
  4864. if (nextSibling)
  4865. parent.insertBefore(node, nextSibling);
  4866. else
  4867. parent.appendChild(node);
  4868. return node;
  4869. });
  4870. },
  4871. replace : function(n, o, k) {
  4872. var t = this;
  4873. if (is(o, 'array'))
  4874. n = n.cloneNode(true);
  4875. return t.run(o, function(o) {
  4876. if (k) {
  4877. each(tinymce.grep(o.childNodes), function(c) {
  4878. n.appendChild(c);
  4879. });
  4880. }
  4881. return o.parentNode.replaceChild(n, o);
  4882. });
  4883. },
  4884. rename : function(elm, name) {
  4885. var t = this, newElm;
  4886. if (elm.nodeName != name.toUpperCase()) {
  4887. // Rename block element
  4888. newElm = t.create(name);
  4889. // Copy attribs to new block
  4890. each(t.getAttribs(elm), function(attr_node) {
  4891. t.setAttrib(newElm, attr_node.nodeName, t.getAttrib(elm, attr_node.nodeName));
  4892. });
  4893. // Replace block
  4894. t.replace(newElm, elm, 1);
  4895. }
  4896. return newElm || elm;
  4897. },
  4898. findCommonAncestor : function(a, b) {
  4899. var ps = a, pe;
  4900. while (ps) {
  4901. pe = b;
  4902. while (pe && ps != pe)
  4903. pe = pe.parentNode;
  4904. if (ps == pe)
  4905. break;
  4906. ps = ps.parentNode;
  4907. }
  4908. if (!ps && a.ownerDocument)
  4909. return a.ownerDocument.documentElement;
  4910. return ps;
  4911. },
  4912. toHex : function(s) {
  4913. var c = /^\s*rgb\s*?\(\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?\)\s*$/i.exec(s);
  4914. function hex(s) {
  4915. s = parseInt(s, 10).toString(16);
  4916. return s.length > 1 ? s : '0' + s; // 0 -> 00
  4917. };
  4918. if (c) {
  4919. s = '#' + hex(c[1]) + hex(c[2]) + hex(c[3]);
  4920. return s;
  4921. }
  4922. return s;
  4923. },
  4924. getClasses : function() {
  4925. var t = this, cl = [], i, lo = {}, f = t.settings.class_filter, ov;
  4926. if (t.classes)
  4927. return t.classes;
  4928. function addClasses(s) {
  4929. // IE style imports
  4930. each(s.imports, function(r) {
  4931. addClasses(r);
  4932. });
  4933. each(s.cssRules || s.rules, function(r) {
  4934. // Real type or fake it on IE
  4935. switch (r.type || 1) {
  4936. // Rule
  4937. case 1:
  4938. if (r.selectorText) {
  4939. each(r.selectorText.split(','), function(v) {
  4940. v = v.replace(/^\s*|\s*$|^\s\./g, "");
  4941. // Is internal or it doesn't contain a class
  4942. if (/\.mce/.test(v) || !/\.[\w\-]+$/.test(v))
  4943. return;
  4944. // Remove everything but class name
  4945. ov = v;
  4946. v = tinymce._replace(/.*\.([a-z0-9_\-]+).*/i, '$1', v);
  4947. // Filter classes
  4948. if (f && !(v = f(v, ov)))
  4949. return;
  4950. if (!lo[v]) {
  4951. cl.push({'class' : v});
  4952. lo[v] = 1;
  4953. }
  4954. });
  4955. }
  4956. break;
  4957. // Import
  4958. case 3:
  4959. addClasses(r.styleSheet);
  4960. break;
  4961. }
  4962. });
  4963. };
  4964. try {
  4965. each(t.doc.styleSheets, addClasses);
  4966. } catch (ex) {
  4967. // Ignore
  4968. }
  4969. if (cl.length > 0)
  4970. t.classes = cl;
  4971. return cl;
  4972. },
  4973. run : function(e, f, s) {
  4974. var t = this, o;
  4975. if (t.doc && typeof(e) === 'string')
  4976. e = t.get(e);
  4977. if (!e)
  4978. return false;
  4979. s = s || this;
  4980. if (!e.nodeType && (e.length || e.length === 0)) {
  4981. o = [];
  4982. each(e, function(e, i) {
  4983. if (e) {
  4984. if (typeof(e) == 'string')
  4985. e = t.doc.getElementById(e);
  4986. o.push(f.call(s, e, i));
  4987. }
  4988. });
  4989. return o;
  4990. }
  4991. return f.call(s, e);
  4992. },
  4993. getAttribs : function(n) {
  4994. var o;
  4995. n = this.get(n);
  4996. if (!n)
  4997. return [];
  4998. if (isIE) {
  4999. o = [];
  5000. // Object will throw exception in IE
  5001. if (n.nodeName == 'OBJECT')
  5002. return n.attributes;
  5003. // IE doesn't keep the selected attribute if you clone option elements
  5004. if (n.nodeName === 'OPTION' && this.getAttrib(n, 'selected'))
  5005. o.push({specified : 1, nodeName : 'selected'});
  5006. // It's crazy that this is faster in IE but it's because it returns all attributes all the time
  5007. n.cloneNode(false).outerHTML.replace(/<\/?[\w:\-]+ ?|=[\"][^\"]+\"|=\'[^\']+\'|=[\w\-]+|>/gi, '').replace(/[\w:\-]+/gi, function(a) {
  5008. o.push({specified : 1, nodeName : a});
  5009. });
  5010. return o;
  5011. }
  5012. return n.attributes;
  5013. },
  5014. isEmpty : function(node, elements) {
  5015. var self = this, i, attributes, type, walker, name, brCount = 0;
  5016. node = node.firstChild;
  5017. if (node) {
  5018. walker = new tinymce.dom.TreeWalker(node, node.parentNode);
  5019. elements = elements || self.schema ? self.schema.getNonEmptyElements() : null;
  5020. do {
  5021. type = node.nodeType;
  5022. if (type === 1) {
  5023. // Ignore bogus elements
  5024. if (node.getAttribute('data-mce-bogus'))
  5025. continue;
  5026. // Keep empty elements like <img />
  5027. name = node.nodeName.toLowerCase();
  5028. if (elements && elements[name]) {
  5029. // Ignore single BR elements in blocks like <p><br /></p> or <p><span><br /></span></p>
  5030. if (name === 'br') {
  5031. brCount++;
  5032. continue;
  5033. }
  5034. return false;
  5035. }
  5036. // Keep elements with data-bookmark attributes or name attribute like <a name="1"></a>
  5037. attributes = self.getAttribs(node);
  5038. i = node.attributes.length;
  5039. while (i--) {
  5040. name = node.attributes[i].nodeName;
  5041. if (name === "name" || name === 'data-mce-bookmark')
  5042. return false;
  5043. }
  5044. }
  5045. // Keep comment nodes
  5046. if (type == 8)
  5047. return false;
  5048. // Keep non whitespace text nodes
  5049. if ((type === 3 && !whiteSpaceRegExp.test(node.nodeValue)))
  5050. return false;
  5051. } while (node = walker.next());
  5052. }
  5053. return brCount <= 1;
  5054. },
  5055. destroy : function(s) {
  5056. var t = this;
  5057. t.win = t.doc = t.root = t.events = t.frag = null;
  5058. // Manual destroy then remove unload handler
  5059. if (!s)
  5060. tinymce.removeUnload(t.destroy);
  5061. },
  5062. createRng : function() {
  5063. var d = this.doc;
  5064. return d.createRange ? d.createRange() : new tinymce.dom.Range(this);
  5065. },
  5066. nodeIndex : function(node, normalized) {
  5067. var idx = 0, lastNodeType, lastNode, nodeType;
  5068. if (node) {
  5069. for (lastNodeType = node.nodeType, node = node.previousSibling, lastNode = node; node; node = node.previousSibling) {
  5070. nodeType = node.nodeType;
  5071. // Normalize text nodes
  5072. if (normalized && nodeType == 3) {
  5073. if (nodeType == lastNodeType || !node.nodeValue.length)
  5074. continue;
  5075. }
  5076. idx++;
  5077. lastNodeType = nodeType;
  5078. }
  5079. }
  5080. return idx;
  5081. },
  5082. split : function(pe, e, re) {
  5083. var t = this, r = t.createRng(), bef, aft, pa;
  5084. // W3C valid browsers tend to leave empty nodes to the left/right side of the contents, this makes sense
  5085. // but we don't want that in our code since it serves no purpose for the end user
  5086. // For example if this is chopped:
  5087. // <p>text 1<span><b>CHOP</b></span>text 2</p>
  5088. // would produce:
  5089. // <p>text 1<span></span></p><b>CHOP</b><p><span></span>text 2</p>
  5090. // this function will then trim of empty edges and produce:
  5091. // <p>text 1</p><b>CHOP</b><p>text 2</p>
  5092. function trim(node) {
  5093. var i, children = node.childNodes, type = node.nodeType;
  5094. function surroundedBySpans(node) {
  5095. var previousIsSpan = node.previousSibling && node.previousSibling.nodeName == 'SPAN';
  5096. var nextIsSpan = node.nextSibling && node.nextSibling.nodeName == 'SPAN';
  5097. return previousIsSpan && nextIsSpan;
  5098. }
  5099. if (type == 1 && node.getAttribute('data-mce-type') == 'bookmark')
  5100. return;
  5101. for (i = children.length - 1; i >= 0; i--)
  5102. trim(children[i]);
  5103. if (type != 9) {
  5104. // Keep non whitespace text nodes
  5105. if (type == 3 && node.nodeValue.length > 0) {
  5106. // If parent element isn't a block or there isn't any useful contents for example "<p> </p>"
  5107. // Also keep text nodes with only spaces if surrounded by spans.
  5108. // eg. "<p><span>a</span> <span>b</span></p>" should keep space between a and b
  5109. var trimmedLength = tinymce.trim(node.nodeValue).length;
  5110. if (!t.isBlock(node.parentNode) || trimmedLength > 0 || trimmedLength === 0 && surroundedBySpans(node))
  5111. return;
  5112. } else if (type == 1) {
  5113. // If the only child is a bookmark then move it up
  5114. children = node.childNodes;
  5115. if (children.length == 1 && children[0] && children[0].nodeType == 1 && children[0].getAttribute('data-mce-type') == 'bookmark')
  5116. node.parentNode.insertBefore(children[0], node);
  5117. // Keep non empty elements or img, hr etc
  5118. if (children.length || /^(br|hr|input|img)$/i.test(node.nodeName))
  5119. return;
  5120. }
  5121. t.remove(node);
  5122. }
  5123. return node;
  5124. };
  5125. if (pe && e) {
  5126. // Get before chunk
  5127. r.setStart(pe.parentNode, t.nodeIndex(pe));
  5128. r.setEnd(e.parentNode, t.nodeIndex(e));
  5129. bef = r.extractContents();
  5130. // Get after chunk
  5131. r = t.createRng();
  5132. r.setStart(e.parentNode, t.nodeIndex(e) + 1);
  5133. r.setEnd(pe.parentNode, t.nodeIndex(pe) + 1);
  5134. aft = r.extractContents();
  5135. // Insert before chunk
  5136. pa = pe.parentNode;
  5137. pa.insertBefore(trim(bef), pe);
  5138. // Insert middle chunk
  5139. if (re)
  5140. pa.replaceChild(re, e);
  5141. else
  5142. pa.insertBefore(e, pe);
  5143. // Insert after chunk
  5144. pa.insertBefore(trim(aft), pe);
  5145. t.remove(pe);
  5146. return re || e;
  5147. }
  5148. },
  5149. bind : function(target, name, func, scope) {
  5150. return this.events.add(target, name, func, scope || this);
  5151. },
  5152. unbind : function(target, name, func) {
  5153. return this.events.remove(target, name, func);
  5154. },
  5155. fire : function(target, name, evt) {
  5156. return this.events.fire(target, name, evt);
  5157. },
  5158. // Returns the content editable state of a node
  5159. getContentEditable: function(node) {
  5160. var contentEditable;
  5161. // Check type
  5162. if (node.nodeType != 1) {
  5163. return null;
  5164. }
  5165. // Check for fake content editable
  5166. contentEditable = node.getAttribute("data-mce-contenteditable");
  5167. if (contentEditable && contentEditable !== "inherit") {
  5168. return contentEditable;
  5169. }
  5170. // Check for real content editable
  5171. return node.contentEditable !== "inherit" ? node.contentEditable : null;
  5172. },
  5173. _findSib : function(node, selector, name) {
  5174. var t = this, f = selector;
  5175. if (node) {
  5176. // If expression make a function of it using is
  5177. if (is(f, 'string')) {
  5178. f = function(node) {
  5179. return t.is(node, selector);
  5180. };
  5181. }
  5182. // Loop all siblings
  5183. for (node = node[name]; node; node = node[name]) {
  5184. if (f(node))
  5185. return node;
  5186. }
  5187. }
  5188. return null;
  5189. },
  5190. _isRes : function(c) {
  5191. // Is live resizble element
  5192. return /^(top|left|bottom|right|width|height)/i.test(c) || /;\s*(top|left|bottom|right|width|height)/i.test(c);
  5193. }
  5194. /*
  5195. walk : function(n, f, s) {
  5196. var d = this.doc, w;
  5197. if (d.createTreeWalker) {
  5198. w = d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false);
  5199. while ((n = w.nextNode()) != null)
  5200. f.call(s || this, n);
  5201. } else
  5202. tinymce.walk(n, f, 'childNodes', s);
  5203. }
  5204. */
  5205. /*
  5206. toRGB : function(s) {
  5207. var c = /^\s*?#([0-9A-F]{2})([0-9A-F]{1,2})([0-9A-F]{2})?\s*?$/.exec(s);
  5208. if (c) {
  5209. // #FFF -> #FFFFFF
  5210. if (!is(c[3]))
  5211. c[3] = c[2] = c[1];
  5212. return "rgb(" + parseInt(c[1], 16) + "," + parseInt(c[2], 16) + "," + parseInt(c[3], 16) + ")";
  5213. }
  5214. return s;
  5215. }
  5216. */
  5217. });
  5218. tinymce.DOM = new tinymce.dom.DOMUtils(document, {process_html : 0});
  5219. })(tinymce);
  5220. (function(ns) {
  5221. // Range constructor
  5222. function Range(dom) {
  5223. var t = this,
  5224. doc = dom.doc,
  5225. EXTRACT = 0,
  5226. CLONE = 1,
  5227. DELETE = 2,
  5228. TRUE = true,
  5229. FALSE = false,
  5230. START_OFFSET = 'startOffset',
  5231. START_CONTAINER = 'startContainer',
  5232. END_CONTAINER = 'endContainer',
  5233. END_OFFSET = 'endOffset',
  5234. extend = tinymce.extend,
  5235. nodeIndex = dom.nodeIndex;
  5236. extend(t, {
  5237. // Inital states
  5238. startContainer : doc,
  5239. startOffset : 0,
  5240. endContainer : doc,
  5241. endOffset : 0,
  5242. collapsed : TRUE,
  5243. commonAncestorContainer : doc,
  5244. // Range constants
  5245. START_TO_START : 0,
  5246. START_TO_END : 1,
  5247. END_TO_END : 2,
  5248. END_TO_START : 3,
  5249. // Public methods
  5250. setStart : setStart,
  5251. setEnd : setEnd,
  5252. setStartBefore : setStartBefore,
  5253. setStartAfter : setStartAfter,
  5254. setEndBefore : setEndBefore,
  5255. setEndAfter : setEndAfter,
  5256. collapse : collapse,
  5257. selectNode : selectNode,
  5258. selectNodeContents : selectNodeContents,
  5259. compareBoundaryPoints : compareBoundaryPoints,
  5260. deleteContents : deleteContents,
  5261. extractContents : extractContents,
  5262. cloneContents : cloneContents,
  5263. insertNode : insertNode,
  5264. surroundContents : surroundContents,
  5265. cloneRange : cloneRange,
  5266. toStringIE : toStringIE
  5267. });
  5268. function createDocumentFragment() {
  5269. return doc.createDocumentFragment();
  5270. };
  5271. function setStart(n, o) {
  5272. _setEndPoint(TRUE, n, o);
  5273. };
  5274. function setEnd(n, o) {
  5275. _setEndPoint(FALSE, n, o);
  5276. };
  5277. function setStartBefore(n) {
  5278. setStart(n.parentNode, nodeIndex(n));
  5279. };
  5280. function setStartAfter(n) {
  5281. setStart(n.parentNode, nodeIndex(n) + 1);
  5282. };
  5283. function setEndBefore(n) {
  5284. setEnd(n.parentNode, nodeIndex(n));
  5285. };
  5286. function setEndAfter(n) {
  5287. setEnd(n.parentNode, nodeIndex(n) + 1);
  5288. };
  5289. function collapse(ts) {
  5290. if (ts) {
  5291. t[END_CONTAINER] = t[START_CONTAINER];
  5292. t[END_OFFSET] = t[START_OFFSET];
  5293. } else {
  5294. t[START_CONTAINER] = t[END_CONTAINER];
  5295. t[START_OFFSET] = t[END_OFFSET];
  5296. }
  5297. t.collapsed = TRUE;
  5298. };
  5299. function selectNode(n) {
  5300. setStartBefore(n);
  5301. setEndAfter(n);
  5302. };
  5303. function selectNodeContents(n) {
  5304. setStart(n, 0);
  5305. setEnd(n, n.nodeType === 1 ? n.childNodes.length : n.nodeValue.length);
  5306. };
  5307. function compareBoundaryPoints(h, r) {
  5308. var sc = t[START_CONTAINER], so = t[START_OFFSET], ec = t[END_CONTAINER], eo = t[END_OFFSET],
  5309. rsc = r.startContainer, rso = r.startOffset, rec = r.endContainer, reo = r.endOffset;
  5310. // Check START_TO_START
  5311. if (h === 0)
  5312. return _compareBoundaryPoints(sc, so, rsc, rso);
  5313. // Check START_TO_END
  5314. if (h === 1)
  5315. return _compareBoundaryPoints(ec, eo, rsc, rso);
  5316. // Check END_TO_END
  5317. if (h === 2)
  5318. return _compareBoundaryPoints(ec, eo, rec, reo);
  5319. // Check END_TO_START
  5320. if (h === 3)
  5321. return _compareBoundaryPoints(sc, so, rec, reo);
  5322. };
  5323. function deleteContents() {
  5324. _traverse(DELETE);
  5325. };
  5326. function extractContents() {
  5327. return _traverse(EXTRACT);
  5328. };
  5329. function cloneContents() {
  5330. return _traverse(CLONE);
  5331. };
  5332. function insertNode(n) {
  5333. var startContainer = this[START_CONTAINER],
  5334. startOffset = this[START_OFFSET], nn, o;
  5335. // Node is TEXT_NODE or CDATA
  5336. if ((startContainer.nodeType === 3 || startContainer.nodeType === 4) && startContainer.nodeValue) {
  5337. if (!startOffset) {
  5338. // At the start of text
  5339. startContainer.parentNode.insertBefore(n, startContainer);
  5340. } else if (startOffset >= startContainer.nodeValue.length) {
  5341. // At the end of text
  5342. dom.insertAfter(n, startContainer);
  5343. } else {
  5344. // Middle, need to split
  5345. nn = startContainer.splitText(startOffset);
  5346. startContainer.parentNode.insertBefore(n, nn);
  5347. }
  5348. } else {
  5349. // Insert element node
  5350. if (startContainer.childNodes.length > 0)
  5351. o = startContainer.childNodes[startOffset];
  5352. if (o)
  5353. startContainer.insertBefore(n, o);
  5354. else
  5355. startContainer.appendChild(n);
  5356. }
  5357. };
  5358. function surroundContents(n) {
  5359. var f = t.extractContents();
  5360. t.insertNode(n);
  5361. n.appendChild(f);
  5362. t.selectNode(n);
  5363. };
  5364. function cloneRange() {
  5365. return extend(new Range(dom), {
  5366. startContainer : t[START_CONTAINER],
  5367. startOffset : t[START_OFFSET],
  5368. endContainer : t[END_CONTAINER],
  5369. endOffset : t[END_OFFSET],
  5370. collapsed : t.collapsed,
  5371. commonAncestorContainer : t.commonAncestorContainer
  5372. });
  5373. };
  5374. // Private methods
  5375. function _getSelectedNode(container, offset) {
  5376. var child;
  5377. if (container.nodeType == 3 /* TEXT_NODE */)
  5378. return container;
  5379. if (offset < 0)
  5380. return container;
  5381. child = container.firstChild;
  5382. while (child && offset > 0) {
  5383. --offset;
  5384. child = child.nextSibling;
  5385. }
  5386. if (child)
  5387. return child;
  5388. return container;
  5389. };
  5390. function _isCollapsed() {
  5391. return (t[START_CONTAINER] == t[END_CONTAINER] && t[START_OFFSET] == t[END_OFFSET]);
  5392. };
  5393. function _compareBoundaryPoints(containerA, offsetA, containerB, offsetB) {
  5394. var c, offsetC, n, cmnRoot, childA, childB;
  5395. // In the first case the boundary-points have the same container. A is before B
  5396. // if its offset is less than the offset of B, A is equal to B if its offset is
  5397. // equal to the offset of B, and A is after B if its offset is greater than the
  5398. // offset of B.
  5399. if (containerA == containerB) {
  5400. if (offsetA == offsetB)
  5401. return 0; // equal
  5402. if (offsetA < offsetB)
  5403. return -1; // before
  5404. return 1; // after
  5405. }
  5406. // In the second case a child node C of the container of A is an ancestor
  5407. // container of B. In this case, A is before B if the offset of A is less than or
  5408. // equal to the index of the child node C and A is after B otherwise.
  5409. c = containerB;
  5410. while (c && c.parentNode != containerA)
  5411. c = c.parentNode;
  5412. if (c) {
  5413. offsetC = 0;
  5414. n = containerA.firstChild;
  5415. while (n != c && offsetC < offsetA) {
  5416. offsetC++;
  5417. n = n.nextSibling;
  5418. }
  5419. if (offsetA <= offsetC)
  5420. return -1; // before
  5421. return 1; // after
  5422. }
  5423. // In the third case a child node C of the container of B is an ancestor container
  5424. // of A. In this case, A is before B if the index of the child node C is less than
  5425. // the offset of B and A is after B otherwise.
  5426. c = containerA;
  5427. while (c && c.parentNode != containerB) {
  5428. c = c.parentNode;
  5429. }
  5430. if (c) {
  5431. offsetC = 0;
  5432. n = containerB.firstChild;
  5433. while (n != c && offsetC < offsetB) {
  5434. offsetC++;
  5435. n = n.nextSibling;
  5436. }
  5437. if (offsetC < offsetB)
  5438. return -1; // before
  5439. return 1; // after
  5440. }
  5441. // In the fourth case, none of three other cases hold: the containers of A and B
  5442. // are siblings or descendants of sibling nodes. In this case, A is before B if
  5443. // the container of A is before the container of B in a pre-order traversal of the
  5444. // Ranges' context tree and A is after B otherwise.
  5445. cmnRoot = dom.findCommonAncestor(containerA, containerB);
  5446. childA = containerA;
  5447. while (childA && childA.parentNode != cmnRoot)
  5448. childA = childA.parentNode;
  5449. if (!childA)
  5450. childA = cmnRoot;
  5451. childB = containerB;
  5452. while (childB && childB.parentNode != cmnRoot)
  5453. childB = childB.parentNode;
  5454. if (!childB)
  5455. childB = cmnRoot;
  5456. if (childA == childB)
  5457. return 0; // equal
  5458. n = cmnRoot.firstChild;
  5459. while (n) {
  5460. if (n == childA)
  5461. return -1; // before
  5462. if (n == childB)
  5463. return 1; // after
  5464. n = n.nextSibling;
  5465. }
  5466. };
  5467. function _setEndPoint(st, n, o) {
  5468. var ec, sc;
  5469. if (st) {
  5470. t[START_CONTAINER] = n;
  5471. t[START_OFFSET] = o;
  5472. } else {
  5473. t[END_CONTAINER] = n;
  5474. t[END_OFFSET] = o;
  5475. }
  5476. // If one boundary-point of a Range is set to have a root container
  5477. // other than the current one for the Range, the Range is collapsed to
  5478. // the new position. This enforces the restriction that both boundary-
  5479. // points of a Range must have the same root container.
  5480. ec = t[END_CONTAINER];
  5481. while (ec.parentNode)
  5482. ec = ec.parentNode;
  5483. sc = t[START_CONTAINER];
  5484. while (sc.parentNode)
  5485. sc = sc.parentNode;
  5486. if (sc == ec) {
  5487. // The start position of a Range is guaranteed to never be after the
  5488. // end position. To enforce this restriction, if the start is set to
  5489. // be at a position after the end, the Range is collapsed to that
  5490. // position.
  5491. if (_compareBoundaryPoints(t[START_CONTAINER], t[START_OFFSET], t[END_CONTAINER], t[END_OFFSET]) > 0)
  5492. t.collapse(st);
  5493. } else
  5494. t.collapse(st);
  5495. t.collapsed = _isCollapsed();
  5496. t.commonAncestorContainer = dom.findCommonAncestor(t[START_CONTAINER], t[END_CONTAINER]);
  5497. };
  5498. function _traverse(how) {
  5499. var c, endContainerDepth = 0, startContainerDepth = 0, p, depthDiff, startNode, endNode, sp, ep;
  5500. if (t[START_CONTAINER] == t[END_CONTAINER])
  5501. return _traverseSameContainer(how);
  5502. for (c = t[END_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  5503. if (p == t[START_CONTAINER])
  5504. return _traverseCommonStartContainer(c, how);
  5505. ++endContainerDepth;
  5506. }
  5507. for (c = t[START_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  5508. if (p == t[END_CONTAINER])
  5509. return _traverseCommonEndContainer(c, how);
  5510. ++startContainerDepth;
  5511. }
  5512. depthDiff = startContainerDepth - endContainerDepth;
  5513. startNode = t[START_CONTAINER];
  5514. while (depthDiff > 0) {
  5515. startNode = startNode.parentNode;
  5516. depthDiff--;
  5517. }
  5518. endNode = t[END_CONTAINER];
  5519. while (depthDiff < 0) {
  5520. endNode = endNode.parentNode;
  5521. depthDiff++;
  5522. }
  5523. // ascend the ancestor hierarchy until we have a common parent.
  5524. for (sp = startNode.parentNode, ep = endNode.parentNode; sp != ep; sp = sp.parentNode, ep = ep.parentNode) {
  5525. startNode = sp;
  5526. endNode = ep;
  5527. }
  5528. return _traverseCommonAncestors(startNode, endNode, how);
  5529. };
  5530. function _traverseSameContainer(how) {
  5531. var frag, s, sub, n, cnt, sibling, xferNode, start, len;
  5532. if (how != DELETE)
  5533. frag = createDocumentFragment();
  5534. // If selection is empty, just return the fragment
  5535. if (t[START_OFFSET] == t[END_OFFSET])
  5536. return frag;
  5537. // Text node needs special case handling
  5538. if (t[START_CONTAINER].nodeType == 3 /* TEXT_NODE */) {
  5539. // get the substring
  5540. s = t[START_CONTAINER].nodeValue;
  5541. sub = s.substring(t[START_OFFSET], t[END_OFFSET]);
  5542. // set the original text node to its new value
  5543. if (how != CLONE) {
  5544. n = t[START_CONTAINER];
  5545. start = t[START_OFFSET];
  5546. len = t[END_OFFSET] - t[START_OFFSET];
  5547. if (start === 0 && len >= n.nodeValue.length - 1) {
  5548. n.parentNode.removeChild(n);
  5549. } else {
  5550. n.deleteData(start, len);
  5551. }
  5552. // Nothing is partially selected, so collapse to start point
  5553. t.collapse(TRUE);
  5554. }
  5555. if (how == DELETE)
  5556. return;
  5557. if (sub.length > 0) {
  5558. frag.appendChild(doc.createTextNode(sub));
  5559. }
  5560. return frag;
  5561. }
  5562. // Copy nodes between the start/end offsets.
  5563. n = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]);
  5564. cnt = t[END_OFFSET] - t[START_OFFSET];
  5565. while (n && cnt > 0) {
  5566. sibling = n.nextSibling;
  5567. xferNode = _traverseFullySelected(n, how);
  5568. if (frag)
  5569. frag.appendChild( xferNode );
  5570. --cnt;
  5571. n = sibling;
  5572. }
  5573. // Nothing is partially selected, so collapse to start point
  5574. if (how != CLONE)
  5575. t.collapse(TRUE);
  5576. return frag;
  5577. };
  5578. function _traverseCommonStartContainer(endAncestor, how) {
  5579. var frag, n, endIdx, cnt, sibling, xferNode;
  5580. if (how != DELETE)
  5581. frag = createDocumentFragment();
  5582. n = _traverseRightBoundary(endAncestor, how);
  5583. if (frag)
  5584. frag.appendChild(n);
  5585. endIdx = nodeIndex(endAncestor);
  5586. cnt = endIdx - t[START_OFFSET];
  5587. if (cnt <= 0) {
  5588. // Collapse to just before the endAncestor, which
  5589. // is partially selected.
  5590. if (how != CLONE) {
  5591. t.setEndBefore(endAncestor);
  5592. t.collapse(FALSE);
  5593. }
  5594. return frag;
  5595. }
  5596. n = endAncestor.previousSibling;
  5597. while (cnt > 0) {
  5598. sibling = n.previousSibling;
  5599. xferNode = _traverseFullySelected(n, how);
  5600. if (frag)
  5601. frag.insertBefore(xferNode, frag.firstChild);
  5602. --cnt;
  5603. n = sibling;
  5604. }
  5605. // Collapse to just before the endAncestor, which
  5606. // is partially selected.
  5607. if (how != CLONE) {
  5608. t.setEndBefore(endAncestor);
  5609. t.collapse(FALSE);
  5610. }
  5611. return frag;
  5612. };
  5613. function _traverseCommonEndContainer(startAncestor, how) {
  5614. var frag, startIdx, n, cnt, sibling, xferNode;
  5615. if (how != DELETE)
  5616. frag = createDocumentFragment();
  5617. n = _traverseLeftBoundary(startAncestor, how);
  5618. if (frag)
  5619. frag.appendChild(n);
  5620. startIdx = nodeIndex(startAncestor);
  5621. ++startIdx; // Because we already traversed it
  5622. cnt = t[END_OFFSET] - startIdx;
  5623. n = startAncestor.nextSibling;
  5624. while (n && cnt > 0) {
  5625. sibling = n.nextSibling;
  5626. xferNode = _traverseFullySelected(n, how);
  5627. if (frag)
  5628. frag.appendChild(xferNode);
  5629. --cnt;
  5630. n = sibling;
  5631. }
  5632. if (how != CLONE) {
  5633. t.setStartAfter(startAncestor);
  5634. t.collapse(TRUE);
  5635. }
  5636. return frag;
  5637. };
  5638. function _traverseCommonAncestors(startAncestor, endAncestor, how) {
  5639. var n, frag, commonParent, startOffset, endOffset, cnt, sibling, nextSibling;
  5640. if (how != DELETE)
  5641. frag = createDocumentFragment();
  5642. n = _traverseLeftBoundary(startAncestor, how);
  5643. if (frag)
  5644. frag.appendChild(n);
  5645. commonParent = startAncestor.parentNode;
  5646. startOffset = nodeIndex(startAncestor);
  5647. endOffset = nodeIndex(endAncestor);
  5648. ++startOffset;
  5649. cnt = endOffset - startOffset;
  5650. sibling = startAncestor.nextSibling;
  5651. while (cnt > 0) {
  5652. nextSibling = sibling.nextSibling;
  5653. n = _traverseFullySelected(sibling, how);
  5654. if (frag)
  5655. frag.appendChild(n);
  5656. sibling = nextSibling;
  5657. --cnt;
  5658. }
  5659. n = _traverseRightBoundary(endAncestor, how);
  5660. if (frag)
  5661. frag.appendChild(n);
  5662. if (how != CLONE) {
  5663. t.setStartAfter(startAncestor);
  5664. t.collapse(TRUE);
  5665. }
  5666. return frag;
  5667. };
  5668. function _traverseRightBoundary(root, how) {
  5669. var next = _getSelectedNode(t[END_CONTAINER], t[END_OFFSET] - 1), parent, clonedParent, prevSibling, clonedChild, clonedGrandParent, isFullySelected = next != t[END_CONTAINER];
  5670. if (next == root)
  5671. return _traverseNode(next, isFullySelected, FALSE, how);
  5672. parent = next.parentNode;
  5673. clonedParent = _traverseNode(parent, FALSE, FALSE, how);
  5674. while (parent) {
  5675. while (next) {
  5676. prevSibling = next.previousSibling;
  5677. clonedChild = _traverseNode(next, isFullySelected, FALSE, how);
  5678. if (how != DELETE)
  5679. clonedParent.insertBefore(clonedChild, clonedParent.firstChild);
  5680. isFullySelected = TRUE;
  5681. next = prevSibling;
  5682. }
  5683. if (parent == root)
  5684. return clonedParent;
  5685. next = parent.previousSibling;
  5686. parent = parent.parentNode;
  5687. clonedGrandParent = _traverseNode(parent, FALSE, FALSE, how);
  5688. if (how != DELETE)
  5689. clonedGrandParent.appendChild(clonedParent);
  5690. clonedParent = clonedGrandParent;
  5691. }
  5692. };
  5693. function _traverseLeftBoundary(root, how) {
  5694. var next = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]), isFullySelected = next != t[START_CONTAINER], parent, clonedParent, nextSibling, clonedChild, clonedGrandParent;
  5695. if (next == root)
  5696. return _traverseNode(next, isFullySelected, TRUE, how);
  5697. parent = next.parentNode;
  5698. clonedParent = _traverseNode(parent, FALSE, TRUE, how);
  5699. while (parent) {
  5700. while (next) {
  5701. nextSibling = next.nextSibling;
  5702. clonedChild = _traverseNode(next, isFullySelected, TRUE, how);
  5703. if (how != DELETE)
  5704. clonedParent.appendChild(clonedChild);
  5705. isFullySelected = TRUE;
  5706. next = nextSibling;
  5707. }
  5708. if (parent == root)
  5709. return clonedParent;
  5710. next = parent.nextSibling;
  5711. parent = parent.parentNode;
  5712. clonedGrandParent = _traverseNode(parent, FALSE, TRUE, how);
  5713. if (how != DELETE)
  5714. clonedGrandParent.appendChild(clonedParent);
  5715. clonedParent = clonedGrandParent;
  5716. }
  5717. };
  5718. function _traverseNode(n, isFullySelected, isLeft, how) {
  5719. var txtValue, newNodeValue, oldNodeValue, offset, newNode;
  5720. if (isFullySelected)
  5721. return _traverseFullySelected(n, how);
  5722. if (n.nodeType == 3 /* TEXT_NODE */) {
  5723. txtValue = n.nodeValue;
  5724. if (isLeft) {
  5725. offset = t[START_OFFSET];
  5726. newNodeValue = txtValue.substring(offset);
  5727. oldNodeValue = txtValue.substring(0, offset);
  5728. } else {
  5729. offset = t[END_OFFSET];
  5730. newNodeValue = txtValue.substring(0, offset);
  5731. oldNodeValue = txtValue.substring(offset);
  5732. }
  5733. if (how != CLONE)
  5734. n.nodeValue = oldNodeValue;
  5735. if (how == DELETE)
  5736. return;
  5737. newNode = dom.clone(n, FALSE);
  5738. newNode.nodeValue = newNodeValue;
  5739. return newNode;
  5740. }
  5741. if (how == DELETE)
  5742. return;
  5743. return dom.clone(n, FALSE);
  5744. };
  5745. function _traverseFullySelected(n, how) {
  5746. if (how != DELETE)
  5747. return how == CLONE ? dom.clone(n, TRUE) : n;
  5748. n.parentNode.removeChild(n);
  5749. };
  5750. function toStringIE() {
  5751. return dom.create('body', null, cloneContents()).outerText;
  5752. }
  5753. return t;
  5754. };
  5755. ns.Range = Range;
  5756. // Older IE versions doesn't let you override toString by it's constructor so we have to stick it in the prototype
  5757. Range.prototype.toString = function() {
  5758. return this.toStringIE();
  5759. };
  5760. })(tinymce.dom);
  5761. (function() {
  5762. function Selection(selection) {
  5763. var self = this, dom = selection.dom, TRUE = true, FALSE = false;
  5764. function getPosition(rng, start) {
  5765. var checkRng, startIndex = 0, endIndex, inside,
  5766. children, child, offset, index, position = -1, parent;
  5767. // Setup test range, collapse it and get the parent
  5768. checkRng = rng.duplicate();
  5769. checkRng.collapse(start);
  5770. parent = checkRng.parentElement();
  5771. // Check if the selection is within the right document
  5772. if (parent.ownerDocument !== selection.dom.doc)
  5773. return;
  5774. // IE will report non editable elements as it's parent so look for an editable one
  5775. while (parent.contentEditable === "false") {
  5776. parent = parent.parentNode;
  5777. }
  5778. // If parent doesn't have any children then return that we are inside the element
  5779. if (!parent.hasChildNodes()) {
  5780. return {node : parent, inside : 1};
  5781. }
  5782. // Setup node list and endIndex
  5783. children = parent.children;
  5784. endIndex = children.length - 1;
  5785. // Perform a binary search for the position
  5786. while (startIndex <= endIndex) {
  5787. index = Math.floor((startIndex + endIndex) / 2);
  5788. // Move selection to node and compare the ranges
  5789. child = children[index];
  5790. checkRng.moveToElementText(child);
  5791. position = checkRng.compareEndPoints(start ? 'StartToStart' : 'EndToEnd', rng);
  5792. // Before/after or an exact match
  5793. if (position > 0) {
  5794. endIndex = index - 1;
  5795. } else if (position < 0) {
  5796. startIndex = index + 1;
  5797. } else {
  5798. return {node : child};
  5799. }
  5800. }
  5801. // Check if child position is before or we didn't find a position
  5802. if (position < 0) {
  5803. // No element child was found use the parent element and the offset inside that
  5804. if (!child) {
  5805. checkRng.moveToElementText(parent);
  5806. checkRng.collapse(true);
  5807. child = parent;
  5808. inside = true;
  5809. } else
  5810. checkRng.collapse(false);
  5811. // Walk character by character in text node until we hit the selected range endpoint, hit the end of document or parent isn't the right one
  5812. // We need to walk char by char since rng.text or rng.htmlText will trim line endings
  5813. offset = 0;
  5814. while (checkRng.compareEndPoints(start ? 'StartToStart' : 'StartToEnd', rng) !== 0) {
  5815. if (checkRng.move('character', 1) === 0 || parent != checkRng.parentElement()) {
  5816. break;
  5817. }
  5818. offset++;
  5819. }
  5820. } else {
  5821. // Child position is after the selection endpoint
  5822. checkRng.collapse(true);
  5823. // Walk character by character in text node until we hit the selected range endpoint, hit the end of document or parent isn't the right one
  5824. offset = 0;
  5825. while (checkRng.compareEndPoints(start ? 'StartToStart' : 'StartToEnd', rng) !== 0) {
  5826. if (checkRng.move('character', -1) === 0 || parent != checkRng.parentElement()) {
  5827. break;
  5828. }
  5829. offset++;
  5830. }
  5831. }
  5832. return {node : child, position : position, offset : offset, inside : inside};
  5833. };
  5834. // Returns a W3C DOM compatible range object by using the IE Range API
  5835. function getRange() {
  5836. var ieRange = selection.getRng(), domRange = dom.createRng(), element, collapsed, tmpRange, element2, bookmark, fail;
  5837. // If selection is outside the current document just return an empty range
  5838. element = ieRange.item ? ieRange.item(0) : ieRange.parentElement();
  5839. if (element.ownerDocument != dom.doc)
  5840. return domRange;
  5841. collapsed = selection.isCollapsed();
  5842. // Handle control selection
  5843. if (ieRange.item) {
  5844. domRange.setStart(element.parentNode, dom.nodeIndex(element));
  5845. domRange.setEnd(domRange.startContainer, domRange.startOffset + 1);
  5846. return domRange;
  5847. }
  5848. function findEndPoint(start) {
  5849. var endPoint = getPosition(ieRange, start), container, offset, textNodeOffset = 0, sibling, undef, nodeValue;
  5850. container = endPoint.node;
  5851. offset = endPoint.offset;
  5852. if (endPoint.inside && !container.hasChildNodes()) {
  5853. domRange[start ? 'setStart' : 'setEnd'](container, 0);
  5854. return;
  5855. }
  5856. if (offset === undef) {
  5857. domRange[start ? 'setStartBefore' : 'setEndAfter'](container);
  5858. return;
  5859. }
  5860. if (endPoint.position < 0) {
  5861. sibling = endPoint.inside ? container.firstChild : container.nextSibling;
  5862. if (!sibling) {
  5863. domRange[start ? 'setStartAfter' : 'setEndAfter'](container);
  5864. return;
  5865. }
  5866. if (!offset) {
  5867. if (sibling.nodeType == 3)
  5868. domRange[start ? 'setStart' : 'setEnd'](sibling, 0);
  5869. else
  5870. domRange[start ? 'setStartBefore' : 'setEndBefore'](sibling);
  5871. return;
  5872. }
  5873. // Find the text node and offset
  5874. while (sibling) {
  5875. nodeValue = sibling.nodeValue;
  5876. textNodeOffset += nodeValue.length;
  5877. // We are at or passed the position we where looking for
  5878. if (textNodeOffset >= offset) {
  5879. container = sibling;
  5880. textNodeOffset -= offset;
  5881. textNodeOffset = nodeValue.length - textNodeOffset;
  5882. break;
  5883. }
  5884. sibling = sibling.nextSibling;
  5885. }
  5886. } else {
  5887. // Find the text node and offset
  5888. sibling = container.previousSibling;
  5889. if (!sibling)
  5890. return domRange[start ? 'setStartBefore' : 'setEndBefore'](container);
  5891. // If there isn't any text to loop then use the first position
  5892. if (!offset) {
  5893. if (container.nodeType == 3)
  5894. domRange[start ? 'setStart' : 'setEnd'](sibling, container.nodeValue.length);
  5895. else
  5896. domRange[start ? 'setStartAfter' : 'setEndAfter'](sibling);
  5897. return;
  5898. }
  5899. while (sibling) {
  5900. textNodeOffset += sibling.nodeValue.length;
  5901. // We are at or passed the position we where looking for
  5902. if (textNodeOffset >= offset) {
  5903. container = sibling;
  5904. textNodeOffset -= offset;
  5905. break;
  5906. }
  5907. sibling = sibling.previousSibling;
  5908. }
  5909. }
  5910. domRange[start ? 'setStart' : 'setEnd'](container, textNodeOffset);
  5911. };
  5912. try {
  5913. // Find start point
  5914. findEndPoint(true);
  5915. // Find end point if needed
  5916. if (!collapsed)
  5917. findEndPoint();
  5918. } catch (ex) {
  5919. // IE has a nasty bug where text nodes might throw "invalid argument" when you
  5920. // access the nodeValue or other properties of text nodes. This seems to happend when
  5921. // text nodes are split into two nodes by a delete/backspace call. So lets detect it and try to fix it.
  5922. if (ex.number == -2147024809) {
  5923. // Get the current selection
  5924. bookmark = self.getBookmark(2);
  5925. // Get start element
  5926. tmpRange = ieRange.duplicate();
  5927. tmpRange.collapse(true);
  5928. element = tmpRange.parentElement();
  5929. // Get end element
  5930. if (!collapsed) {
  5931. tmpRange = ieRange.duplicate();
  5932. tmpRange.collapse(false);
  5933. element2 = tmpRange.parentElement();
  5934. element2.innerHTML = element2.innerHTML;
  5935. }
  5936. // Remove the broken elements
  5937. element.innerHTML = element.innerHTML;
  5938. // Restore the selection
  5939. self.moveToBookmark(bookmark);
  5940. // Since the range has moved we need to re-get it
  5941. ieRange = selection.getRng();
  5942. // Find start point
  5943. findEndPoint(true);
  5944. // Find end point if needed
  5945. if (!collapsed)
  5946. findEndPoint();
  5947. } else
  5948. throw ex; // Throw other errors
  5949. }
  5950. return domRange;
  5951. };
  5952. this.getBookmark = function(type) {
  5953. var rng = selection.getRng(), start, end, bookmark = {};
  5954. function getIndexes(node) {
  5955. var parent, root, children, i, indexes = [];
  5956. parent = node.parentNode;
  5957. root = dom.getRoot().parentNode;
  5958. while (parent != root && parent.nodeType !== 9) {
  5959. children = parent.children;
  5960. i = children.length;
  5961. while (i--) {
  5962. if (node === children[i]) {
  5963. indexes.push(i);
  5964. break;
  5965. }
  5966. }
  5967. node = parent;
  5968. parent = parent.parentNode;
  5969. }
  5970. return indexes;
  5971. };
  5972. function getBookmarkEndPoint(start) {
  5973. var position;
  5974. position = getPosition(rng, start);
  5975. if (position) {
  5976. return {
  5977. position : position.position,
  5978. offset : position.offset,
  5979. indexes : getIndexes(position.node),
  5980. inside : position.inside
  5981. };
  5982. }
  5983. };
  5984. // Non ubstructive bookmark
  5985. if (type === 2) {
  5986. // Handle text selection
  5987. if (!rng.item) {
  5988. bookmark.start = getBookmarkEndPoint(true);
  5989. if (!selection.isCollapsed())
  5990. bookmark.end = getBookmarkEndPoint();
  5991. } else
  5992. bookmark.start = {ctrl : true, indexes : getIndexes(rng.item(0))};
  5993. }
  5994. return bookmark;
  5995. };
  5996. this.moveToBookmark = function(bookmark) {
  5997. var rng, body = dom.doc.body;
  5998. function resolveIndexes(indexes) {
  5999. var node, i, idx, children;
  6000. node = dom.getRoot();
  6001. for (i = indexes.length - 1; i >= 0; i--) {
  6002. children = node.children;
  6003. idx = indexes[i];
  6004. if (idx <= children.length - 1) {
  6005. node = children[idx];
  6006. }
  6007. }
  6008. return node;
  6009. };
  6010. function setBookmarkEndPoint(start) {
  6011. var endPoint = bookmark[start ? 'start' : 'end'], moveLeft, moveRng, undef;
  6012. if (endPoint) {
  6013. moveLeft = endPoint.position > 0;
  6014. moveRng = body.createTextRange();
  6015. moveRng.moveToElementText(resolveIndexes(endPoint.indexes));
  6016. offset = endPoint.offset;
  6017. if (offset !== undef) {
  6018. moveRng.collapse(endPoint.inside || moveLeft);
  6019. moveRng.moveStart('character', moveLeft ? -offset : offset);
  6020. } else
  6021. moveRng.collapse(start);
  6022. rng.setEndPoint(start ? 'StartToStart' : 'EndToStart', moveRng);
  6023. if (start)
  6024. rng.collapse(true);
  6025. }
  6026. };
  6027. if (bookmark.start) {
  6028. if (bookmark.start.ctrl) {
  6029. rng = body.createControlRange();
  6030. rng.addElement(resolveIndexes(bookmark.start.indexes));
  6031. rng.select();
  6032. } else {
  6033. rng = body.createTextRange();
  6034. setBookmarkEndPoint(true);
  6035. setBookmarkEndPoint();
  6036. rng.select();
  6037. }
  6038. }
  6039. };
  6040. this.addRange = function(rng) {
  6041. var ieRng, ctrlRng, startContainer, startOffset, endContainer, endOffset, sibling,
  6042. doc = selection.dom.doc, body = doc.body, nativeRng, ctrlElm;
  6043. function setEndPoint(start) {
  6044. var container, offset, marker, tmpRng, nodes;
  6045. marker = dom.create('a');
  6046. container = start ? startContainer : endContainer;
  6047. offset = start ? startOffset : endOffset;
  6048. tmpRng = ieRng.duplicate();
  6049. if (container == doc || container == doc.documentElement) {
  6050. container = body;
  6051. offset = 0;
  6052. }
  6053. if (container.nodeType == 3) {
  6054. container.parentNode.insertBefore(marker, container);
  6055. tmpRng.moveToElementText(marker);
  6056. tmpRng.moveStart('character', offset);
  6057. dom.remove(marker);
  6058. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  6059. } else {
  6060. nodes = container.childNodes;
  6061. if (nodes.length) {
  6062. if (offset >= nodes.length) {
  6063. dom.insertAfter(marker, nodes[nodes.length - 1]);
  6064. } else {
  6065. container.insertBefore(marker, nodes[offset]);
  6066. }
  6067. tmpRng.moveToElementText(marker);
  6068. } else if (container.canHaveHTML) {
  6069. // Empty node selection for example <div>|</div>
  6070. // Setting innerHTML with a span marker then remove that marker seems to keep empty block elements open
  6071. container.innerHTML = '<span>\uFEFF</span>';
  6072. marker = container.firstChild;
  6073. tmpRng.moveToElementText(marker);
  6074. tmpRng.collapse(FALSE); // Collapse false works better than true for some odd reason
  6075. }
  6076. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  6077. dom.remove(marker);
  6078. }
  6079. }
  6080. // Setup some shorter versions
  6081. startContainer = rng.startContainer;
  6082. startOffset = rng.startOffset;
  6083. endContainer = rng.endContainer;
  6084. endOffset = rng.endOffset;
  6085. ieRng = body.createTextRange();
  6086. // If single element selection then try making a control selection out of it
  6087. if (startContainer == endContainer && startContainer.nodeType == 1) {
  6088. // Trick to place the caret inside an empty block element like <p></p>
  6089. if (startOffset == endOffset && !startContainer.hasChildNodes()) {
  6090. if (startContainer.canHaveHTML) {
  6091. // Check if previous sibling is an empty block if it is then we need to render it
  6092. // IE would otherwise move the caret into the sibling instead of the empty startContainer see: #5236
  6093. // Example this: <p></p><p>|</p> would become this: <p>|</p><p></p>
  6094. sibling = startContainer.previousSibling;
  6095. if (sibling && !sibling.hasChildNodes() && dom.isBlock(sibling)) {
  6096. sibling.innerHTML = '\uFEFF';
  6097. } else {
  6098. sibling = null;
  6099. }
  6100. startContainer.innerHTML = '<span>\uFEFF</span><span>\uFEFF</span>';
  6101. ieRng.moveToElementText(startContainer.lastChild);
  6102. ieRng.select();
  6103. dom.doc.selection.clear();
  6104. startContainer.innerHTML = '';
  6105. if (sibling) {
  6106. sibling.innerHTML = '';
  6107. }
  6108. return;
  6109. } else {
  6110. startOffset = dom.nodeIndex(startContainer);
  6111. startContainer = startContainer.parentNode;
  6112. }
  6113. }
  6114. if (startOffset == endOffset - 1) {
  6115. try {
  6116. ctrlElm = startContainer.childNodes[startOffset];
  6117. ctrlRng = body.createControlRange();
  6118. ctrlRng.addElement(ctrlElm);
  6119. ctrlRng.select();
  6120. // Check if the range produced is on the correct element and is a control range
  6121. // On IE 8 it will select the parent contentEditable container if you select an inner element see: #5398
  6122. nativeRng = selection.getRng();
  6123. if (nativeRng.item && ctrlElm === nativeRng.item(0)) {
  6124. return;
  6125. }
  6126. } catch (ex) {
  6127. // Ignore
  6128. }
  6129. }
  6130. }
  6131. // Set start/end point of selection
  6132. setEndPoint(true);
  6133. setEndPoint();
  6134. // Select the new range and scroll it into view
  6135. ieRng.select();
  6136. };
  6137. // Expose range method
  6138. this.getRangeAt = getRange;
  6139. };
  6140. // Expose the selection object
  6141. tinymce.dom.TridentSelection = Selection;
  6142. })();
  6143. /*
  6144. * Sizzle CSS Selector Engine
  6145. * Copyright, The Dojo Foundation
  6146. * Released under the MIT, BSD, and GPL Licenses.
  6147. * More information: http://sizzlejs.com/
  6148. */
  6149. (function(){
  6150. var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
  6151. expando = "sizcache",
  6152. done = 0,
  6153. toString = Object.prototype.toString,
  6154. hasDuplicate = false,
  6155. baseHasDuplicate = true,
  6156. rBackslash = /\\/g,
  6157. rReturn = /\r\n/g,
  6158. rNonWord = /\W/;
  6159. // Here we check if the JavaScript engine is using some sort of
  6160. // optimization where it does not always call our comparision
  6161. // function. If that is the case, discard the hasDuplicate value.
  6162. // Thus far that includes Google Chrome.
  6163. [0, 0].sort(function() {
  6164. baseHasDuplicate = false;
  6165. return 0;
  6166. });
  6167. var Sizzle = function( selector, context, results, seed ) {
  6168. results = results || [];
  6169. context = context || document;
  6170. var origContext = context;
  6171. if ( context.nodeType !== 1 && context.nodeType !== 9 ) {
  6172. return [];
  6173. }
  6174. if ( !selector || typeof selector !== "string" ) {
  6175. return results;
  6176. }
  6177. var m, set, checkSet, extra, ret, cur, pop, i,
  6178. prune = true,
  6179. contextXML = Sizzle.isXML( context ),
  6180. parts = [],
  6181. soFar = selector;
  6182. // Reset the position of the chunker regexp (start from head)
  6183. do {
  6184. chunker.exec( "" );
  6185. m = chunker.exec( soFar );
  6186. if ( m ) {
  6187. soFar = m[3];
  6188. parts.push( m[1] );
  6189. if ( m[2] ) {
  6190. extra = m[3];
  6191. break;
  6192. }
  6193. }
  6194. } while ( m );
  6195. if ( parts.length > 1 && origPOS.exec( selector ) ) {
  6196. if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {
  6197. set = posProcess( parts[0] + parts[1], context, seed );
  6198. } else {
  6199. set = Expr.relative[ parts[0] ] ?
  6200. [ context ] :
  6201. Sizzle( parts.shift(), context );
  6202. while ( parts.length ) {
  6203. selector = parts.shift();
  6204. if ( Expr.relative[ selector ] ) {
  6205. selector += parts.shift();
  6206. }
  6207. set = posProcess( selector, set, seed );
  6208. }
  6209. }
  6210. } else {
  6211. // Take a shortcut and set the context if the root selector is an ID
  6212. // (but not if it'll be faster if the inner selector is an ID)
  6213. if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML &&
  6214. Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) {
  6215. ret = Sizzle.find( parts.shift(), context, contextXML );
  6216. context = ret.expr ?
  6217. Sizzle.filter( ret.expr, ret.set )[0] :
  6218. ret.set[0];
  6219. }
  6220. if ( context ) {
  6221. ret = seed ?
  6222. { expr: parts.pop(), set: makeArray(seed) } :
  6223. Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML );
  6224. set = ret.expr ?
  6225. Sizzle.filter( ret.expr, ret.set ) :
  6226. ret.set;
  6227. if ( parts.length > 0 ) {
  6228. checkSet = makeArray( set );
  6229. } else {
  6230. prune = false;
  6231. }
  6232. while ( parts.length ) {
  6233. cur = parts.pop();
  6234. pop = cur;
  6235. if ( !Expr.relative[ cur ] ) {
  6236. cur = "";
  6237. } else {
  6238. pop = parts.pop();
  6239. }
  6240. if ( pop == null ) {
  6241. pop = context;
  6242. }
  6243. Expr.relative[ cur ]( checkSet, pop, contextXML );
  6244. }
  6245. } else {
  6246. checkSet = parts = [];
  6247. }
  6248. }
  6249. if ( !checkSet ) {
  6250. checkSet = set;
  6251. }
  6252. if ( !checkSet ) {
  6253. Sizzle.error( cur || selector );
  6254. }
  6255. if ( toString.call(checkSet) === "[object Array]" ) {
  6256. if ( !prune ) {
  6257. results.push.apply( results, checkSet );
  6258. } else if ( context && context.nodeType === 1 ) {
  6259. for ( i = 0; checkSet[i] != null; i++ ) {
  6260. if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && Sizzle.contains(context, checkSet[i])) ) {
  6261. results.push( set[i] );
  6262. }
  6263. }
  6264. } else {
  6265. for ( i = 0; checkSet[i] != null; i++ ) {
  6266. if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
  6267. results.push( set[i] );
  6268. }
  6269. }
  6270. }
  6271. } else {
  6272. makeArray( checkSet, results );
  6273. }
  6274. if ( extra ) {
  6275. Sizzle( extra, origContext, results, seed );
  6276. Sizzle.uniqueSort( results );
  6277. }
  6278. return results;
  6279. };
  6280. Sizzle.uniqueSort = function( results ) {
  6281. if ( sortOrder ) {
  6282. hasDuplicate = baseHasDuplicate;
  6283. results.sort( sortOrder );
  6284. if ( hasDuplicate ) {
  6285. for ( var i = 1; i < results.length; i++ ) {
  6286. if ( results[i] === results[ i - 1 ] ) {
  6287. results.splice( i--, 1 );
  6288. }
  6289. }
  6290. }
  6291. }
  6292. return results;
  6293. };
  6294. Sizzle.matches = function( expr, set ) {
  6295. return Sizzle( expr, null, null, set );
  6296. };
  6297. Sizzle.matchesSelector = function( node, expr ) {
  6298. return Sizzle( expr, null, null, [node] ).length > 0;
  6299. };
  6300. Sizzle.find = function( expr, context, isXML ) {
  6301. var set, i, len, match, type, left;
  6302. if ( !expr ) {
  6303. return [];
  6304. }
  6305. for ( i = 0, len = Expr.order.length; i < len; i++ ) {
  6306. type = Expr.order[i];
  6307. if ( (match = Expr.leftMatch[ type ].exec( expr )) ) {
  6308. left = match[1];
  6309. match.splice( 1, 1 );
  6310. if ( left.substr( left.length - 1 ) !== "\\" ) {
  6311. match[1] = (match[1] || "").replace( rBackslash, "" );
  6312. set = Expr.find[ type ]( match, context, isXML );
  6313. if ( set != null ) {
  6314. expr = expr.replace( Expr.match[ type ], "" );
  6315. break;
  6316. }
  6317. }
  6318. }
  6319. }
  6320. if ( !set ) {
  6321. set = typeof context.getElementsByTagName !== "undefined" ?
  6322. context.getElementsByTagName( "*" ) :
  6323. [];
  6324. }
  6325. return { set: set, expr: expr };
  6326. };
  6327. Sizzle.filter = function( expr, set, inplace, not ) {
  6328. var match, anyFound,
  6329. type, found, item, filter, left,
  6330. i, pass,
  6331. old = expr,
  6332. result = [],
  6333. curLoop = set,
  6334. isXMLFilter = set && set[0] && Sizzle.isXML( set[0] );
  6335. while ( expr && set.length ) {
  6336. for ( type in Expr.filter ) {
  6337. if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {
  6338. filter = Expr.filter[ type ];
  6339. left = match[1];
  6340. anyFound = false;
  6341. match.splice(1,1);
  6342. if ( left.substr( left.length - 1 ) === "\\" ) {
  6343. continue;
  6344. }
  6345. if ( curLoop === result ) {
  6346. result = [];
  6347. }
  6348. if ( Expr.preFilter[ type ] ) {
  6349. match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter );
  6350. if ( !match ) {
  6351. anyFound = found = true;
  6352. } else if ( match === true ) {
  6353. continue;
  6354. }
  6355. }
  6356. if ( match ) {
  6357. for ( i = 0; (item = curLoop[i]) != null; i++ ) {
  6358. if ( item ) {
  6359. found = filter( item, match, i, curLoop );
  6360. pass = not ^ found;
  6361. if ( inplace && found != null ) {
  6362. if ( pass ) {
  6363. anyFound = true;
  6364. } else {
  6365. curLoop[i] = false;
  6366. }
  6367. } else if ( pass ) {
  6368. result.push( item );
  6369. anyFound = true;
  6370. }
  6371. }
  6372. }
  6373. }
  6374. if ( found !== undefined ) {
  6375. if ( !inplace ) {
  6376. curLoop = result;
  6377. }
  6378. expr = expr.replace( Expr.match[ type ], "" );
  6379. if ( !anyFound ) {
  6380. return [];
  6381. }
  6382. break;
  6383. }
  6384. }
  6385. }
  6386. // Improper expression
  6387. if ( expr === old ) {
  6388. if ( anyFound == null ) {
  6389. Sizzle.error( expr );
  6390. } else {
  6391. break;
  6392. }
  6393. }
  6394. old = expr;
  6395. }
  6396. return curLoop;
  6397. };
  6398. Sizzle.error = function( msg ) {
  6399. throw new Error( "Syntax error, unrecognized expression: " + msg );
  6400. };
  6401. var getText = Sizzle.getText = function( elem ) {
  6402. var i, node,
  6403. nodeType = elem.nodeType,
  6404. ret = "";
  6405. if ( nodeType ) {
  6406. if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
  6407. // Use textContent || innerText for elements
  6408. if ( typeof elem.textContent === 'string' ) {
  6409. return elem.textContent;
  6410. } else if ( typeof elem.innerText === 'string' ) {
  6411. // Replace IE's carriage returns
  6412. return elem.innerText.replace( rReturn, '' );
  6413. } else {
  6414. // Traverse it's children
  6415. for ( elem = elem.firstChild; elem; elem = elem.nextSibling) {
  6416. ret += getText( elem );
  6417. }
  6418. }
  6419. } else if ( nodeType === 3 || nodeType === 4 ) {
  6420. return elem.nodeValue;
  6421. }
  6422. } else {
  6423. // If no nodeType, this is expected to be an array
  6424. for ( i = 0; (node = elem[i]); i++ ) {
  6425. // Do not traverse comment nodes
  6426. if ( node.nodeType !== 8 ) {
  6427. ret += getText( node );
  6428. }
  6429. }
  6430. }
  6431. return ret;
  6432. };
  6433. var Expr = Sizzle.selectors = {
  6434. order: [ "ID", "NAME", "TAG" ],
  6435. match: {
  6436. ID: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
  6437. CLASS: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
  6438. NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,
  6439. ATTR: /\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/,
  6440. TAG: /^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,
  6441. CHILD: /:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/,
  6442. POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,
  6443. PSEUDO: /:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/
  6444. },
  6445. leftMatch: {},
  6446. attrMap: {
  6447. "class": "className",
  6448. "for": "htmlFor"
  6449. },
  6450. attrHandle: {
  6451. href: function( elem ) {
  6452. return elem.getAttribute( "href" );
  6453. },
  6454. type: function( elem ) {
  6455. return elem.getAttribute( "type" );
  6456. }
  6457. },
  6458. relative: {
  6459. "+": function(checkSet, part){
  6460. var isPartStr = typeof part === "string",
  6461. isTag = isPartStr && !rNonWord.test( part ),
  6462. isPartStrNotTag = isPartStr && !isTag;
  6463. if ( isTag ) {
  6464. part = part.toLowerCase();
  6465. }
  6466. for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) {
  6467. if ( (elem = checkSet[i]) ) {
  6468. while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}
  6469. checkSet[i] = isPartStrNotTag || elem && elem.nodeName.toLowerCase() === part ?
  6470. elem || false :
  6471. elem === part;
  6472. }
  6473. }
  6474. if ( isPartStrNotTag ) {
  6475. Sizzle.filter( part, checkSet, true );
  6476. }
  6477. },
  6478. ">": function( checkSet, part ) {
  6479. var elem,
  6480. isPartStr = typeof part === "string",
  6481. i = 0,
  6482. l = checkSet.length;
  6483. if ( isPartStr && !rNonWord.test( part ) ) {
  6484. part = part.toLowerCase();
  6485. for ( ; i < l; i++ ) {
  6486. elem = checkSet[i];
  6487. if ( elem ) {
  6488. var parent = elem.parentNode;
  6489. checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false;
  6490. }
  6491. }
  6492. } else {
  6493. for ( ; i < l; i++ ) {
  6494. elem = checkSet[i];
  6495. if ( elem ) {
  6496. checkSet[i] = isPartStr ?
  6497. elem.parentNode :
  6498. elem.parentNode === part;
  6499. }
  6500. }
  6501. if ( isPartStr ) {
  6502. Sizzle.filter( part, checkSet, true );
  6503. }
  6504. }
  6505. },
  6506. "": function(checkSet, part, isXML){
  6507. var nodeCheck,
  6508. doneName = done++,
  6509. checkFn = dirCheck;
  6510. if ( typeof part === "string" && !rNonWord.test( part ) ) {
  6511. part = part.toLowerCase();
  6512. nodeCheck = part;
  6513. checkFn = dirNodeCheck;
  6514. }
  6515. checkFn( "parentNode", part, doneName, checkSet, nodeCheck, isXML );
  6516. },
  6517. "~": function( checkSet, part, isXML ) {
  6518. var nodeCheck,
  6519. doneName = done++,
  6520. checkFn = dirCheck;
  6521. if ( typeof part === "string" && !rNonWord.test( part ) ) {
  6522. part = part.toLowerCase();
  6523. nodeCheck = part;
  6524. checkFn = dirNodeCheck;
  6525. }
  6526. checkFn( "previousSibling", part, doneName, checkSet, nodeCheck, isXML );
  6527. }
  6528. },
  6529. find: {
  6530. ID: function( match, context, isXML ) {
  6531. if ( typeof context.getElementById !== "undefined" && !isXML ) {
  6532. var m = context.getElementById(match[1]);
  6533. // Check parentNode to catch when Blackberry 4.6 returns
  6534. // nodes that are no longer in the document #6963
  6535. return m && m.parentNode ? [m] : [];
  6536. }
  6537. },
  6538. NAME: function( match, context ) {
  6539. if ( typeof context.getElementsByName !== "undefined" ) {
  6540. var ret = [],
  6541. results = context.getElementsByName( match[1] );
  6542. for ( var i = 0, l = results.length; i < l; i++ ) {
  6543. if ( results[i].getAttribute("name") === match[1] ) {
  6544. ret.push( results[i] );
  6545. }
  6546. }
  6547. return ret.length === 0 ? null : ret;
  6548. }
  6549. },
  6550. TAG: function( match, context ) {
  6551. if ( typeof context.getElementsByTagName !== "undefined" ) {
  6552. return context.getElementsByTagName( match[1] );
  6553. }
  6554. }
  6555. },
  6556. preFilter: {
  6557. CLASS: function( match, curLoop, inplace, result, not, isXML ) {
  6558. match = " " + match[1].replace( rBackslash, "" ) + " ";
  6559. if ( isXML ) {
  6560. return match;
  6561. }
  6562. for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) {
  6563. if ( elem ) {
  6564. if ( not ^ (elem.className && (" " + elem.className + " ").replace(/[\t\n\r]/g, " ").indexOf(match) >= 0) ) {
  6565. if ( !inplace ) {
  6566. result.push( elem );
  6567. }
  6568. } else if ( inplace ) {
  6569. curLoop[i] = false;
  6570. }
  6571. }
  6572. }
  6573. return false;
  6574. },
  6575. ID: function( match ) {
  6576. return match[1].replace( rBackslash, "" );
  6577. },
  6578. TAG: function( match, curLoop ) {
  6579. return match[1].replace( rBackslash, "" ).toLowerCase();
  6580. },
  6581. CHILD: function( match ) {
  6582. if ( match[1] === "nth" ) {
  6583. if ( !match[2] ) {
  6584. Sizzle.error( match[0] );
  6585. }
  6586. match[2] = match[2].replace(/^\+|\s*/g, '');
  6587. // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
  6588. var test = /(-?)(\d*)(?:n([+\-]?\d*))?/.exec(
  6589. match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" ||
  6590. !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);
  6591. // calculate the numbers (first)n+(last) including if they are negative
  6592. match[2] = (test[1] + (test[2] || 1)) - 0;
  6593. match[3] = test[3] - 0;
  6594. }
  6595. else if ( match[2] ) {
  6596. Sizzle.error( match[0] );
  6597. }
  6598. // TODO: Move to normal caching system
  6599. match[0] = done++;
  6600. return match;
  6601. },
  6602. ATTR: function( match, curLoop, inplace, result, not, isXML ) {
  6603. var name = match[1] = match[1].replace( rBackslash, "" );
  6604. if ( !isXML && Expr.attrMap[name] ) {
  6605. match[1] = Expr.attrMap[name];
  6606. }
  6607. // Handle if an un-quoted value was used
  6608. match[4] = ( match[4] || match[5] || "" ).replace( rBackslash, "" );
  6609. if ( match[2] === "~=" ) {
  6610. match[4] = " " + match[4] + " ";
  6611. }
  6612. return match;
  6613. },
  6614. PSEUDO: function( match, curLoop, inplace, result, not ) {
  6615. if ( match[1] === "not" ) {
  6616. // If we're dealing with a complex expression, or a simple one
  6617. if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) {
  6618. match[3] = Sizzle(match[3], null, null, curLoop);
  6619. } else {
  6620. var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
  6621. if ( !inplace ) {
  6622. result.push.apply( result, ret );
  6623. }
  6624. return false;
  6625. }
  6626. } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
  6627. return true;
  6628. }
  6629. return match;
  6630. },
  6631. POS: function( match ) {
  6632. match.unshift( true );
  6633. return match;
  6634. }
  6635. },
  6636. filters: {
  6637. enabled: function( elem ) {
  6638. return elem.disabled === false && elem.type !== "hidden";
  6639. },
  6640. disabled: function( elem ) {
  6641. return elem.disabled === true;
  6642. },
  6643. checked: function( elem ) {
  6644. return elem.checked === true;
  6645. },
  6646. selected: function( elem ) {
  6647. // Accessing this property makes selected-by-default
  6648. // options in Safari work properly
  6649. if ( elem.parentNode ) {
  6650. elem.parentNode.selectedIndex;
  6651. }
  6652. return elem.selected === true;
  6653. },
  6654. parent: function( elem ) {
  6655. return !!elem.firstChild;
  6656. },
  6657. empty: function( elem ) {
  6658. return !elem.firstChild;
  6659. },
  6660. has: function( elem, i, match ) {
  6661. return !!Sizzle( match[3], elem ).length;
  6662. },
  6663. header: function( elem ) {
  6664. return (/h\d/i).test( elem.nodeName );
  6665. },
  6666. text: function( elem ) {
  6667. var attr = elem.getAttribute( "type" ), type = elem.type;
  6668. // IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc)
  6669. // use getAttribute instead to test this case
  6670. return elem.nodeName.toLowerCase() === "input" && "text" === type && ( attr === type || attr === null );
  6671. },
  6672. radio: function( elem ) {
  6673. return elem.nodeName.toLowerCase() === "input" && "radio" === elem.type;
  6674. },
  6675. checkbox: function( elem ) {
  6676. return elem.nodeName.toLowerCase() === "input" && "checkbox" === elem.type;
  6677. },
  6678. file: function( elem ) {
  6679. return elem.nodeName.toLowerCase() === "input" && "file" === elem.type;
  6680. },
  6681. password: function( elem ) {
  6682. return elem.nodeName.toLowerCase() === "input" && "password" === elem.type;
  6683. },
  6684. submit: function( elem ) {
  6685. var name = elem.nodeName.toLowerCase();
  6686. return (name === "input" || name === "button") && "submit" === elem.type;
  6687. },
  6688. image: function( elem ) {
  6689. return elem.nodeName.toLowerCase() === "input" && "image" === elem.type;
  6690. },
  6691. reset: function( elem ) {
  6692. var name = elem.nodeName.toLowerCase();
  6693. return (name === "input" || name === "button") && "reset" === elem.type;
  6694. },
  6695. button: function( elem ) {
  6696. var name = elem.nodeName.toLowerCase();
  6697. return name === "input" && "button" === elem.type || name === "button";
  6698. },
  6699. input: function( elem ) {
  6700. return (/input|select|textarea|button/i).test( elem.nodeName );
  6701. },
  6702. focus: function( elem ) {
  6703. return elem === elem.ownerDocument.activeElement;
  6704. }
  6705. },
  6706. setFilters: {
  6707. first: function( elem, i ) {
  6708. return i === 0;
  6709. },
  6710. last: function( elem, i, match, array ) {
  6711. return i === array.length - 1;
  6712. },
  6713. even: function( elem, i ) {
  6714. return i % 2 === 0;
  6715. },
  6716. odd: function( elem, i ) {
  6717. return i % 2 === 1;
  6718. },
  6719. lt: function( elem, i, match ) {
  6720. return i < match[3] - 0;
  6721. },
  6722. gt: function( elem, i, match ) {
  6723. return i > match[3] - 0;
  6724. },
  6725. nth: function( elem, i, match ) {
  6726. return match[3] - 0 === i;
  6727. },
  6728. eq: function( elem, i, match ) {
  6729. return match[3] - 0 === i;
  6730. }
  6731. },
  6732. filter: {
  6733. PSEUDO: function( elem, match, i, array ) {
  6734. var name = match[1],
  6735. filter = Expr.filters[ name ];
  6736. if ( filter ) {
  6737. return filter( elem, i, match, array );
  6738. } else if ( name === "contains" ) {
  6739. return (elem.textContent || elem.innerText || getText([ elem ]) || "").indexOf(match[3]) >= 0;
  6740. } else if ( name === "not" ) {
  6741. var not = match[3];
  6742. for ( var j = 0, l = not.length; j < l; j++ ) {
  6743. if ( not[j] === elem ) {
  6744. return false;
  6745. }
  6746. }
  6747. return true;
  6748. } else {
  6749. Sizzle.error( name );
  6750. }
  6751. },
  6752. CHILD: function( elem, match ) {
  6753. var first, last,
  6754. doneName, parent, cache,
  6755. count, diff,
  6756. type = match[1],
  6757. node = elem;
  6758. switch ( type ) {
  6759. case "only":
  6760. case "first":
  6761. while ( (node = node.previousSibling) ) {
  6762. if ( node.nodeType === 1 ) {
  6763. return false;
  6764. }
  6765. }
  6766. if ( type === "first" ) {
  6767. return true;
  6768. }
  6769. node = elem;
  6770. /* falls through */
  6771. case "last":
  6772. while ( (node = node.nextSibling) ) {
  6773. if ( node.nodeType === 1 ) {
  6774. return false;
  6775. }
  6776. }
  6777. return true;
  6778. case "nth":
  6779. first = match[2];
  6780. last = match[3];
  6781. if ( first === 1 && last === 0 ) {
  6782. return true;
  6783. }
  6784. doneName = match[0];
  6785. parent = elem.parentNode;
  6786. if ( parent && (parent[ expando ] !== doneName || !elem.nodeIndex) ) {
  6787. count = 0;
  6788. for ( node = parent.firstChild; node; node = node.nextSibling ) {
  6789. if ( node.nodeType === 1 ) {
  6790. node.nodeIndex = ++count;
  6791. }
  6792. }
  6793. parent[ expando ] = doneName;
  6794. }
  6795. diff = elem.nodeIndex - last;
  6796. if ( first === 0 ) {
  6797. return diff === 0;
  6798. } else {
  6799. return ( diff % first === 0 && diff / first >= 0 );
  6800. }
  6801. }
  6802. },
  6803. ID: function( elem, match ) {
  6804. return elem.nodeType === 1 && elem.getAttribute("id") === match;
  6805. },
  6806. TAG: function( elem, match ) {
  6807. return (match === "*" && elem.nodeType === 1) || !!elem.nodeName && elem.nodeName.toLowerCase() === match;
  6808. },
  6809. CLASS: function( elem, match ) {
  6810. return (" " + (elem.className || elem.getAttribute("class")) + " ")
  6811. .indexOf( match ) > -1;
  6812. },
  6813. ATTR: function( elem, match ) {
  6814. var name = match[1],
  6815. result = Sizzle.attr ?
  6816. Sizzle.attr( elem, name ) :
  6817. Expr.attrHandle[ name ] ?
  6818. Expr.attrHandle[ name ]( elem ) :
  6819. elem[ name ] != null ?
  6820. elem[ name ] :
  6821. elem.getAttribute( name ),
  6822. value = result + "",
  6823. type = match[2],
  6824. check = match[4];
  6825. return result == null ?
  6826. type === "!=" :
  6827. !type && Sizzle.attr ?
  6828. result != null :
  6829. type === "=" ?
  6830. value === check :
  6831. type === "*=" ?
  6832. value.indexOf(check) >= 0 :
  6833. type === "~=" ?
  6834. (" " + value + " ").indexOf(check) >= 0 :
  6835. !check ?
  6836. value && result !== false :
  6837. type === "!=" ?
  6838. value !== check :
  6839. type === "^=" ?
  6840. value.indexOf(check) === 0 :
  6841. type === "$=" ?
  6842. value.substr(value.length - check.length) === check :
  6843. type === "|=" ?
  6844. value === check || value.substr(0, check.length + 1) === check + "-" :
  6845. false;
  6846. },
  6847. POS: function( elem, match, i, array ) {
  6848. var name = match[2],
  6849. filter = Expr.setFilters[ name ];
  6850. if ( filter ) {
  6851. return filter( elem, i, match, array );
  6852. }
  6853. }
  6854. }
  6855. };
  6856. var origPOS = Expr.match.POS,
  6857. fescape = function(all, num){
  6858. return "\\" + (num - 0 + 1);
  6859. };
  6860. for ( var type in Expr.match ) {
  6861. Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) );
  6862. Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) );
  6863. }
  6864. // Expose origPOS
  6865. // "global" as in regardless of relation to brackets/parens
  6866. Expr.match.globalPOS = origPOS;
  6867. var makeArray = function( array, results ) {
  6868. array = Array.prototype.slice.call( array, 0 );
  6869. if ( results ) {
  6870. results.push.apply( results, array );
  6871. return results;
  6872. }
  6873. return array;
  6874. };
  6875. // Perform a simple check to determine if the browser is capable of
  6876. // converting a NodeList to an array using builtin methods.
  6877. // Also verifies that the returned array holds DOM nodes
  6878. // (which is not the case in the Blackberry browser)
  6879. try {
  6880. Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType;
  6881. // Provide a fallback method if it does not work
  6882. } catch( e ) {
  6883. makeArray = function( array, results ) {
  6884. var i = 0,
  6885. ret = results || [];
  6886. if ( toString.call(array) === "[object Array]" ) {
  6887. Array.prototype.push.apply( ret, array );
  6888. } else {
  6889. if ( typeof array.length === "number" ) {
  6890. for ( var l = array.length; i < l; i++ ) {
  6891. ret.push( array[i] );
  6892. }
  6893. } else {
  6894. for ( ; array[i]; i++ ) {
  6895. ret.push( array[i] );
  6896. }
  6897. }
  6898. }
  6899. return ret;
  6900. };
  6901. }
  6902. var sortOrder, siblingCheck;
  6903. if ( document.documentElement.compareDocumentPosition ) {
  6904. sortOrder = function( a, b ) {
  6905. if ( a === b ) {
  6906. hasDuplicate = true;
  6907. return 0;
  6908. }
  6909. if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) {
  6910. return a.compareDocumentPosition ? -1 : 1;
  6911. }
  6912. return a.compareDocumentPosition(b) & 4 ? -1 : 1;
  6913. };
  6914. } else {
  6915. sortOrder = function( a, b ) {
  6916. // The nodes are identical, we can exit early
  6917. if ( a === b ) {
  6918. hasDuplicate = true;
  6919. return 0;
  6920. // Fallback to using sourceIndex (in IE) if it's available on both nodes
  6921. } else if ( a.sourceIndex && b.sourceIndex ) {
  6922. return a.sourceIndex - b.sourceIndex;
  6923. }
  6924. var al, bl,
  6925. ap = [],
  6926. bp = [],
  6927. aup = a.parentNode,
  6928. bup = b.parentNode,
  6929. cur = aup;
  6930. // If the nodes are siblings (or identical) we can do a quick check
  6931. if ( aup === bup ) {
  6932. return siblingCheck( a, b );
  6933. // If no parents were found then the nodes are disconnected
  6934. } else if ( !aup ) {
  6935. return -1;
  6936. } else if ( !bup ) {
  6937. return 1;
  6938. }
  6939. // Otherwise they're somewhere else in the tree so we need
  6940. // to build up a full list of the parentNodes for comparison
  6941. while ( cur ) {
  6942. ap.unshift( cur );
  6943. cur = cur.parentNode;
  6944. }
  6945. cur = bup;
  6946. while ( cur ) {
  6947. bp.unshift( cur );
  6948. cur = cur.parentNode;
  6949. }
  6950. al = ap.length;
  6951. bl = bp.length;
  6952. // Start walking down the tree looking for a discrepancy
  6953. for ( var i = 0; i < al && i < bl; i++ ) {
  6954. if ( ap[i] !== bp[i] ) {
  6955. return siblingCheck( ap[i], bp[i] );
  6956. }
  6957. }
  6958. // We ended someplace up the tree so do a sibling check
  6959. return i === al ?
  6960. siblingCheck( a, bp[i], -1 ) :
  6961. siblingCheck( ap[i], b, 1 );
  6962. };
  6963. siblingCheck = function( a, b, ret ) {
  6964. if ( a === b ) {
  6965. return ret;
  6966. }
  6967. var cur = a.nextSibling;
  6968. while ( cur ) {
  6969. if ( cur === b ) {
  6970. return -1;
  6971. }
  6972. cur = cur.nextSibling;
  6973. }
  6974. return 1;
  6975. };
  6976. }
  6977. // Check to see if the browser returns elements by name when
  6978. // querying by getElementById (and provide a workaround)
  6979. (function(){
  6980. // We're going to inject a fake input element with a specified name
  6981. var form = document.createElement("div"),
  6982. id = "script" + (new Date()).getTime(),
  6983. root = document.documentElement;
  6984. form.innerHTML = "<a name='" + id + "'/>";
  6985. // Inject it into the root element, check its status, and remove it quickly
  6986. root.insertBefore( form, root.firstChild );
  6987. // The workaround has to do additional checks after a getElementById
  6988. // Which slows things down for other browsers (hence the branching)
  6989. if ( document.getElementById( id ) ) {
  6990. Expr.find.ID = function( match, context, isXML ) {
  6991. if ( typeof context.getElementById !== "undefined" && !isXML ) {
  6992. var m = context.getElementById(match[1]);
  6993. return m ?
  6994. m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ?
  6995. [m] :
  6996. undefined :
  6997. [];
  6998. }
  6999. };
  7000. Expr.filter.ID = function( elem, match ) {
  7001. var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
  7002. return elem.nodeType === 1 && node && node.nodeValue === match;
  7003. };
  7004. }
  7005. root.removeChild( form );
  7006. // release memory in IE
  7007. root = form = null;
  7008. })();
  7009. (function(){
  7010. // Check to see if the browser returns only elements
  7011. // when doing getElementsByTagName("*")
  7012. // Create a fake element
  7013. var div = document.createElement("div");
  7014. div.appendChild( document.createComment("") );
  7015. // Make sure no comments are found
  7016. if ( div.getElementsByTagName("*").length > 0 ) {
  7017. Expr.find.TAG = function( match, context ) {
  7018. var results = context.getElementsByTagName( match[1] );
  7019. // Filter out possible comments
  7020. if ( match[1] === "*" ) {
  7021. var tmp = [];
  7022. for ( var i = 0; results[i]; i++ ) {
  7023. if ( results[i].nodeType === 1 ) {
  7024. tmp.push( results[i] );
  7025. }
  7026. }
  7027. results = tmp;
  7028. }
  7029. return results;
  7030. };
  7031. }
  7032. // Check to see if an attribute returns normalized href attributes
  7033. div.innerHTML = "<a href='#'></a>";
  7034. if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" &&
  7035. div.firstChild.getAttribute("href") !== "#" ) {
  7036. Expr.attrHandle.href = function( elem ) {
  7037. return elem.getAttribute( "href", 2 );
  7038. };
  7039. }
  7040. // release memory in IE
  7041. div = null;
  7042. })();
  7043. if ( document.querySelectorAll ) {
  7044. (function(){
  7045. var oldSizzle = Sizzle,
  7046. div = document.createElement("div"),
  7047. id = "__sizzle__";
  7048. div.innerHTML = "<p class='TEST'></p>";
  7049. // Safari can't handle uppercase or unicode characters when
  7050. // in quirks mode.
  7051. if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {
  7052. return;
  7053. }
  7054. Sizzle = function( query, context, extra, seed ) {
  7055. context = context || document;
  7056. // Only use querySelectorAll on non-XML documents
  7057. // (ID selectors don't work in non-HTML documents)
  7058. if ( !seed && !Sizzle.isXML(context) ) {
  7059. // See if we find a selector to speed up
  7060. var match = /^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec( query );
  7061. if ( match && (context.nodeType === 1 || context.nodeType === 9) ) {
  7062. // Speed-up: Sizzle("TAG")
  7063. if ( match[1] ) {
  7064. return makeArray( context.getElementsByTagName( query ), extra );
  7065. // Speed-up: Sizzle(".CLASS")
  7066. } else if ( match[2] && Expr.find.CLASS && context.getElementsByClassName ) {
  7067. return makeArray( context.getElementsByClassName( match[2] ), extra );
  7068. }
  7069. }
  7070. if ( context.nodeType === 9 ) {
  7071. // Speed-up: Sizzle("body")
  7072. // The body element only exists once, optimize finding it
  7073. if ( query === "body" && context.body ) {
  7074. return makeArray( [ context.body ], extra );
  7075. // Speed-up: Sizzle("#ID")
  7076. } else if ( match && match[3] ) {
  7077. var elem = context.getElementById( match[3] );
  7078. // Check parentNode to catch when Blackberry 4.6 returns
  7079. // nodes that are no longer in the document #6963
  7080. if ( elem && elem.parentNode ) {
  7081. // Handle the case where IE and Opera return items
  7082. // by name instead of ID
  7083. if ( elem.id === match[3] ) {
  7084. return makeArray( [ elem ], extra );
  7085. }
  7086. } else {
  7087. return makeArray( [], extra );
  7088. }
  7089. }
  7090. try {
  7091. return makeArray( context.querySelectorAll(query), extra );
  7092. } catch(qsaError) {}
  7093. // qSA works strangely on Element-rooted queries
  7094. // We can work around this by specifying an extra ID on the root
  7095. // and working up from there (Thanks to Andrew Dupont for the technique)
  7096. // IE 8 doesn't work on object elements
  7097. } else if ( context.nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
  7098. var oldContext = context,
  7099. old = context.getAttribute( "id" ),
  7100. nid = old || id,
  7101. hasParent = context.parentNode,
  7102. relativeHierarchySelector = /^\s*[+~]/.test( query );
  7103. if ( !old ) {
  7104. context.setAttribute( "id", nid );
  7105. } else {
  7106. nid = nid.replace( /'/g, "\\$&" );
  7107. }
  7108. if ( relativeHierarchySelector && hasParent ) {
  7109. context = context.parentNode;
  7110. }
  7111. try {
  7112. if ( !relativeHierarchySelector || hasParent ) {
  7113. return makeArray( context.querySelectorAll( "[id='" + nid + "'] " + query ), extra );
  7114. }
  7115. } catch(pseudoError) {
  7116. } finally {
  7117. if ( !old ) {
  7118. oldContext.removeAttribute( "id" );
  7119. }
  7120. }
  7121. }
  7122. }
  7123. return oldSizzle(query, context, extra, seed);
  7124. };
  7125. for ( var prop in oldSizzle ) {
  7126. Sizzle[ prop ] = oldSizzle[ prop ];
  7127. }
  7128. // release memory in IE
  7129. div = null;
  7130. })();
  7131. }
  7132. (function(){
  7133. var html = document.documentElement,
  7134. matches = html.matchesSelector || html.mozMatchesSelector || html.webkitMatchesSelector || html.msMatchesSelector;
  7135. if ( matches ) {
  7136. // Check to see if it's possible to do matchesSelector
  7137. // on a disconnected node (IE 9 fails this)
  7138. var disconnectedMatch = !matches.call( document.createElement( "div" ), "div" ),
  7139. pseudoWorks = false;
  7140. try {
  7141. // This should fail with an exception
  7142. // Gecko does not error, returns false instead
  7143. matches.call( document.documentElement, "[test!='']:sizzle" );
  7144. } catch( pseudoError ) {
  7145. pseudoWorks = true;
  7146. }
  7147. Sizzle.matchesSelector = function( node, expr ) {
  7148. // Make sure that attribute selectors are quoted
  7149. expr = expr.replace(/\=\s*([^'"\]]*)\s*\]/g, "='$1']");
  7150. if ( !Sizzle.isXML( node ) ) {
  7151. try {
  7152. if ( pseudoWorks || !Expr.match.PSEUDO.test( expr ) && !/!=/.test( expr ) ) {
  7153. var ret = matches.call( node, expr );
  7154. // IE 9's matchesSelector returns false on disconnected nodes
  7155. if ( ret || !disconnectedMatch ||
  7156. // As well, disconnected nodes are said to be in a document
  7157. // fragment in IE 9, so check for that
  7158. node.document && node.document.nodeType !== 11 ) {
  7159. return ret;
  7160. }
  7161. }
  7162. } catch(e) {}
  7163. }
  7164. return Sizzle(expr, null, null, [node]).length > 0;
  7165. };
  7166. }
  7167. })();
  7168. (function(){
  7169. var div = document.createElement("div");
  7170. div.innerHTML = "<div class='test e'></div><div class='test'></div>";
  7171. // Opera can't find a second classname (in 9.6)
  7172. // Also, make sure that getElementsByClassName actually exists
  7173. if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) {
  7174. return;
  7175. }
  7176. // Safari caches class attributes, doesn't catch changes (in 3.2)
  7177. div.lastChild.className = "e";
  7178. if ( div.getElementsByClassName("e").length === 1 ) {
  7179. return;
  7180. }
  7181. Expr.order.splice(1, 0, "CLASS");
  7182. Expr.find.CLASS = function( match, context, isXML ) {
  7183. if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {
  7184. return context.getElementsByClassName(match[1]);
  7185. }
  7186. };
  7187. // release memory in IE
  7188. div = null;
  7189. })();
  7190. function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
  7191. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  7192. var elem = checkSet[i];
  7193. if ( elem ) {
  7194. var match = false;
  7195. elem = elem[dir];
  7196. while ( elem ) {
  7197. if ( elem[ expando ] === doneName ) {
  7198. match = checkSet[elem.sizset];
  7199. break;
  7200. }
  7201. if ( elem.nodeType === 1 && !isXML ){
  7202. elem[ expando ] = doneName;
  7203. elem.sizset = i;
  7204. }
  7205. if ( elem.nodeName.toLowerCase() === cur ) {
  7206. match = elem;
  7207. break;
  7208. }
  7209. elem = elem[dir];
  7210. }
  7211. checkSet[i] = match;
  7212. }
  7213. }
  7214. }
  7215. function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
  7216. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  7217. var elem = checkSet[i];
  7218. if ( elem ) {
  7219. var match = false;
  7220. elem = elem[dir];
  7221. while ( elem ) {
  7222. if ( elem[ expando ] === doneName ) {
  7223. match = checkSet[elem.sizset];
  7224. break;
  7225. }
  7226. if ( elem.nodeType === 1 ) {
  7227. if ( !isXML ) {
  7228. elem[ expando ] = doneName;
  7229. elem.sizset = i;
  7230. }
  7231. if ( typeof cur !== "string" ) {
  7232. if ( elem === cur ) {
  7233. match = true;
  7234. break;
  7235. }
  7236. } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
  7237. match = elem;
  7238. break;
  7239. }
  7240. }
  7241. elem = elem[dir];
  7242. }
  7243. checkSet[i] = match;
  7244. }
  7245. }
  7246. }
  7247. if ( document.documentElement.contains ) {
  7248. Sizzle.contains = function( a, b ) {
  7249. return a !== b && (a.contains ? a.contains(b) : true);
  7250. };
  7251. } else if ( document.documentElement.compareDocumentPosition ) {
  7252. Sizzle.contains = function( a, b ) {
  7253. return !!(a.compareDocumentPosition(b) & 16);
  7254. };
  7255. } else {
  7256. Sizzle.contains = function() {
  7257. return false;
  7258. };
  7259. }
  7260. Sizzle.isXML = function( elem ) {
  7261. // documentElement is verified for cases where it doesn't yet exist
  7262. // (such as loading iframes in IE - #4833)
  7263. var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement;
  7264. return documentElement ? documentElement.nodeName !== "HTML" : false;
  7265. };
  7266. var posProcess = function( selector, context, seed ) {
  7267. var match,
  7268. tmpSet = [],
  7269. later = "",
  7270. root = context.nodeType ? [context] : context;
  7271. // Position selectors must be done after the filter
  7272. // And so must :not(positional) so we move all PSEUDOs to the end
  7273. while ( (match = Expr.match.PSEUDO.exec( selector )) ) {
  7274. later += match[0];
  7275. selector = selector.replace( Expr.match.PSEUDO, "" );
  7276. }
  7277. selector = Expr.relative[selector] ? selector + "*" : selector;
  7278. for ( var i = 0, l = root.length; i < l; i++ ) {
  7279. Sizzle( selector, root[i], tmpSet, seed );
  7280. }
  7281. return Sizzle.filter( later, tmpSet );
  7282. };
  7283. // EXPOSE
  7284. window.tinymce.dom.Sizzle = Sizzle;
  7285. })();
  7286. (function(tinymce) {
  7287. tinymce.dom.Element = function(id, settings) {
  7288. var t = this, dom, el;
  7289. t.settings = settings = settings || {};
  7290. t.id = id;
  7291. t.dom = dom = settings.dom || tinymce.DOM;
  7292. // Only IE leaks DOM references, this is a lot faster
  7293. if (!tinymce.isIE)
  7294. el = dom.get(t.id);
  7295. tinymce.each(
  7296. ('getPos,getRect,getParent,add,setStyle,getStyle,setStyles,' +
  7297. 'setAttrib,setAttribs,getAttrib,addClass,removeClass,' +
  7298. 'hasClass,getOuterHTML,setOuterHTML,remove,show,hide,' +
  7299. 'isHidden,setHTML,get').split(/,/), function(k) {
  7300. t[k] = function() {
  7301. var a = [id], i;
  7302. for (i = 0; i < arguments.length; i++)
  7303. a.push(arguments[i]);
  7304. a = dom[k].apply(dom, a);
  7305. t.update(k);
  7306. return a;
  7307. };
  7308. }
  7309. );
  7310. tinymce.extend(t, {
  7311. on : function(n, f, s) {
  7312. return tinymce.dom.Event.add(t.id, n, f, s);
  7313. },
  7314. getXY : function() {
  7315. return {
  7316. x : parseInt(t.getStyle('left')),
  7317. y : parseInt(t.getStyle('top'))
  7318. };
  7319. },
  7320. getSize : function() {
  7321. var n = dom.get(t.id);
  7322. return {
  7323. w : parseInt(t.getStyle('width') || n.clientWidth),
  7324. h : parseInt(t.getStyle('height') || n.clientHeight)
  7325. };
  7326. },
  7327. moveTo : function(x, y) {
  7328. t.setStyles({left : x, top : y});
  7329. },
  7330. moveBy : function(x, y) {
  7331. var p = t.getXY();
  7332. t.moveTo(p.x + x, p.y + y);
  7333. },
  7334. resizeTo : function(w, h) {
  7335. t.setStyles({width : w, height : h});
  7336. },
  7337. resizeBy : function(w, h) {
  7338. var s = t.getSize();
  7339. t.resizeTo(s.w + w, s.h + h);
  7340. },
  7341. update : function(k) {
  7342. var b;
  7343. if (tinymce.isIE6 && settings.blocker) {
  7344. k = k || '';
  7345. // Ignore getters
  7346. if (k.indexOf('get') === 0 || k.indexOf('has') === 0 || k.indexOf('is') === 0)
  7347. return;
  7348. // Remove blocker on remove
  7349. if (k == 'remove') {
  7350. dom.remove(t.blocker);
  7351. return;
  7352. }
  7353. if (!t.blocker) {
  7354. t.blocker = dom.uniqueId();
  7355. b = dom.add(settings.container || dom.getRoot(), 'iframe', {id : t.blocker, style : 'position:absolute;', frameBorder : 0, src : 'javascript:""'});
  7356. dom.setStyle(b, 'opacity', 0);
  7357. } else
  7358. b = dom.get(t.blocker);
  7359. dom.setStyles(b, {
  7360. left : t.getStyle('left', 1),
  7361. top : t.getStyle('top', 1),
  7362. width : t.getStyle('width', 1),
  7363. height : t.getStyle('height', 1),
  7364. display : t.getStyle('display', 1),
  7365. zIndex : parseInt(t.getStyle('zIndex', 1) || 0) - 1
  7366. });
  7367. }
  7368. }
  7369. });
  7370. };
  7371. })(tinymce);
  7372. (function(tinymce) {
  7373. function trimNl(s) {
  7374. return s.replace(/[\n\r]+/g, '');
  7375. };
  7376. // Shorten names
  7377. var is = tinymce.is, isIE = tinymce.isIE, each = tinymce.each, TreeWalker = tinymce.dom.TreeWalker;
  7378. tinymce.create('tinymce.dom.Selection', {
  7379. Selection : function(dom, win, serializer, editor) {
  7380. var t = this;
  7381. t.dom = dom;
  7382. t.win = win;
  7383. t.serializer = serializer;
  7384. t.editor = editor;
  7385. // Add events
  7386. each([
  7387. 'onBeforeSetContent',
  7388. 'onBeforeGetContent',
  7389. 'onSetContent',
  7390. 'onGetContent'
  7391. ], function(e) {
  7392. t[e] = new tinymce.util.Dispatcher(t);
  7393. });
  7394. // No W3C Range support
  7395. if (!t.win.getSelection)
  7396. t.tridentSel = new tinymce.dom.TridentSelection(t);
  7397. if (tinymce.isIE && dom.boxModel)
  7398. this._fixIESelection();
  7399. // Prevent leaks
  7400. tinymce.addUnload(t.destroy, t);
  7401. },
  7402. setCursorLocation: function(node, offset) {
  7403. var t = this; var r = t.dom.createRng();
  7404. r.setStart(node, offset);
  7405. r.setEnd(node, offset);
  7406. t.setRng(r);
  7407. t.collapse(false);
  7408. },
  7409. getContent : function(s) {
  7410. var t = this, r = t.getRng(), e = t.dom.create("body"), se = t.getSel(), wb, wa, n;
  7411. s = s || {};
  7412. wb = wa = '';
  7413. s.get = true;
  7414. s.format = s.format || 'html';
  7415. s.forced_root_block = '';
  7416. t.onBeforeGetContent.dispatch(t, s);
  7417. if (s.format == 'text')
  7418. return t.isCollapsed() ? '' : (r.text || (se.toString ? se.toString() : ''));
  7419. if (r.cloneContents) {
  7420. n = r.cloneContents();
  7421. if (n)
  7422. e.appendChild(n);
  7423. } else if (is(r.item) || is(r.htmlText)) {
  7424. // IE will produce invalid markup if elements are present that
  7425. // it doesn't understand like custom elements or HTML5 elements.
  7426. // Adding a BR in front of the contents and then remoiving it seems to fix it though.
  7427. e.innerHTML = '<br>' + (r.item ? r.item(0).outerHTML : r.htmlText);
  7428. e.removeChild(e.firstChild);
  7429. } else
  7430. e.innerHTML = r.toString();
  7431. // Keep whitespace before and after
  7432. if (/^\s/.test(e.innerHTML))
  7433. wb = ' ';
  7434. if (/\s+$/.test(e.innerHTML))
  7435. wa = ' ';
  7436. s.getInner = true;
  7437. s.content = t.isCollapsed() ? '' : wb + t.serializer.serialize(e, s) + wa;
  7438. t.onGetContent.dispatch(t, s);
  7439. return s.content;
  7440. },
  7441. setContent : function(content, args) {
  7442. var self = this, rng = self.getRng(), caretNode, doc = self.win.document, frag, temp;
  7443. args = args || {format : 'html'};
  7444. args.set = true;
  7445. content = args.content = content;
  7446. // Dispatch before set content event
  7447. if (!args.no_events)
  7448. self.onBeforeSetContent.dispatch(self, args);
  7449. content = args.content;
  7450. if (rng.insertNode) {
  7451. // Make caret marker since insertNode places the caret in the beginning of text after insert
  7452. content += '<span id="__caret">_</span>';
  7453. // Delete and insert new node
  7454. if (rng.startContainer == doc && rng.endContainer == doc) {
  7455. // WebKit will fail if the body is empty since the range is then invalid and it can't insert contents
  7456. doc.body.innerHTML = content;
  7457. } else {
  7458. rng.deleteContents();
  7459. if (doc.body.childNodes.length === 0) {
  7460. doc.body.innerHTML = content;
  7461. } else {
  7462. // createContextualFragment doesn't exists in IE 9 DOMRanges
  7463. if (rng.createContextualFragment) {
  7464. rng.insertNode(rng.createContextualFragment(content));
  7465. } else {
  7466. // Fake createContextualFragment call in IE 9
  7467. frag = doc.createDocumentFragment();
  7468. temp = doc.createElement('div');
  7469. frag.appendChild(temp);
  7470. temp.outerHTML = content;
  7471. rng.insertNode(frag);
  7472. }
  7473. }
  7474. }
  7475. // Move to caret marker
  7476. caretNode = self.dom.get('__caret');
  7477. // Make sure we wrap it compleatly, Opera fails with a simple select call
  7478. rng = doc.createRange();
  7479. rng.setStartBefore(caretNode);
  7480. rng.setEndBefore(caretNode);
  7481. self.setRng(rng);
  7482. // Remove the caret position
  7483. self.dom.remove('__caret');
  7484. try {
  7485. self.setRng(rng);
  7486. } catch (ex) {
  7487. // Might fail on Opera for some odd reason
  7488. }
  7489. } else {
  7490. if (rng.item) {
  7491. // Delete content and get caret text selection
  7492. doc.execCommand('Delete', false, null);
  7493. rng = self.getRng();
  7494. }
  7495. // Explorer removes spaces from the beginning of pasted contents
  7496. if (/^\s+/.test(content)) {
  7497. rng.pasteHTML('<span id="__mce_tmp">_</span>' + content);
  7498. self.dom.remove('__mce_tmp');
  7499. } else
  7500. rng.pasteHTML(content);
  7501. }
  7502. // Dispatch set content event
  7503. if (!args.no_events)
  7504. self.onSetContent.dispatch(self, args);
  7505. },
  7506. getStart : function() {
  7507. var self = this, rng = self.getRng(), startElement, parentElement, checkRng, node;
  7508. if (rng.duplicate || rng.item) {
  7509. // Control selection, return first item
  7510. if (rng.item)
  7511. return rng.item(0);
  7512. // Get start element
  7513. checkRng = rng.duplicate();
  7514. checkRng.collapse(1);
  7515. startElement = checkRng.parentElement();
  7516. if (startElement.ownerDocument !== self.dom.doc) {
  7517. startElement = self.dom.getRoot();
  7518. }
  7519. // Check if range parent is inside the start element, then return the inner parent element
  7520. // This will fix issues when a single element is selected, IE would otherwise return the wrong start element
  7521. parentElement = node = rng.parentElement();
  7522. while (node = node.parentNode) {
  7523. if (node == startElement) {
  7524. startElement = parentElement;
  7525. break;
  7526. }
  7527. }
  7528. return startElement;
  7529. } else {
  7530. startElement = rng.startContainer;
  7531. if (startElement.nodeType == 1 && startElement.hasChildNodes())
  7532. startElement = startElement.childNodes[Math.min(startElement.childNodes.length - 1, rng.startOffset)];
  7533. if (startElement && startElement.nodeType == 3)
  7534. return startElement.parentNode;
  7535. return startElement;
  7536. }
  7537. },
  7538. getEnd : function() {
  7539. var self = this, rng = self.getRng(), endElement, endOffset;
  7540. if (rng.duplicate || rng.item) {
  7541. if (rng.item)
  7542. return rng.item(0);
  7543. rng = rng.duplicate();
  7544. rng.collapse(0);
  7545. endElement = rng.parentElement();
  7546. if (endElement.ownerDocument !== self.dom.doc) {
  7547. endElement = self.dom.getRoot();
  7548. }
  7549. if (endElement && endElement.nodeName == 'BODY')
  7550. return endElement.lastChild || endElement;
  7551. return endElement;
  7552. } else {
  7553. endElement = rng.endContainer;
  7554. endOffset = rng.endOffset;
  7555. if (endElement.nodeType == 1 && endElement.hasChildNodes())
  7556. endElement = endElement.childNodes[endOffset > 0 ? endOffset - 1 : endOffset];
  7557. if (endElement && endElement.nodeType == 3)
  7558. return endElement.parentNode;
  7559. return endElement;
  7560. }
  7561. },
  7562. getBookmark : function(type, normalized) {
  7563. var t = this, dom = t.dom, rng, rng2, id, collapsed, name, element, index, chr = '\uFEFF', styles;
  7564. function findIndex(name, element) {
  7565. var index = 0;
  7566. each(dom.select(name), function(node, i) {
  7567. if (node == element)
  7568. index = i;
  7569. });
  7570. return index;
  7571. };
  7572. function normalizeTableCellSelection(rng) {
  7573. function moveEndPoint(start) {
  7574. var container, offset, childNodes, prefix = start ? 'start' : 'end';
  7575. container = rng[prefix + 'Container'];
  7576. offset = rng[prefix + 'Offset'];
  7577. if (container.nodeType == 1 && container.nodeName == "TR") {
  7578. childNodes = container.childNodes;
  7579. container = childNodes[Math.min(start ? offset : offset - 1, childNodes.length - 1)];
  7580. if (container) {
  7581. offset = start ? 0 : container.childNodes.length;
  7582. rng['set' + (start ? 'Start' : 'End')](container, offset);
  7583. }
  7584. }
  7585. };
  7586. moveEndPoint(true);
  7587. moveEndPoint();
  7588. return rng;
  7589. };
  7590. function getLocation() {
  7591. var rng = t.getRng(true), root = dom.getRoot(), bookmark = {};
  7592. function getPoint(rng, start) {
  7593. var container = rng[start ? 'startContainer' : 'endContainer'],
  7594. offset = rng[start ? 'startOffset' : 'endOffset'], point = [], node, childNodes, after = 0;
  7595. if (container.nodeType == 3) {
  7596. if (normalized) {
  7597. for (node = container.previousSibling; node && node.nodeType == 3; node = node.previousSibling)
  7598. offset += node.nodeValue.length;
  7599. }
  7600. point.push(offset);
  7601. } else {
  7602. childNodes = container.childNodes;
  7603. if (offset >= childNodes.length && childNodes.length) {
  7604. after = 1;
  7605. offset = Math.max(0, childNodes.length - 1);
  7606. }
  7607. point.push(t.dom.nodeIndex(childNodes[offset], normalized) + after);
  7608. }
  7609. for (; container && container != root; container = container.parentNode)
  7610. point.push(t.dom.nodeIndex(container, normalized));
  7611. return point;
  7612. };
  7613. bookmark.start = getPoint(rng, true);
  7614. if (!t.isCollapsed())
  7615. bookmark.end = getPoint(rng);
  7616. return bookmark;
  7617. };
  7618. if (type == 2) {
  7619. if (t.tridentSel)
  7620. return t.tridentSel.getBookmark(type);
  7621. return getLocation();
  7622. }
  7623. // Handle simple range
  7624. if (type)
  7625. return {rng : t.getRng()};
  7626. rng = t.getRng();
  7627. id = dom.uniqueId();
  7628. collapsed = tinyMCE.activeEditor.selection.isCollapsed();
  7629. styles = 'overflow:hidden;line-height:0px';
  7630. // Explorer method
  7631. if (rng.duplicate || rng.item) {
  7632. // Text selection
  7633. if (!rng.item) {
  7634. rng2 = rng.duplicate();
  7635. try {
  7636. // Insert start marker
  7637. rng.collapse();
  7638. rng.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_start" style="' + styles + '">' + chr + '</span>');
  7639. // Insert end marker
  7640. if (!collapsed) {
  7641. rng2.collapse(false);
  7642. // Detect the empty space after block elements in IE and move the end back one character <p></p>] becomes <p>]</p>
  7643. rng.moveToElementText(rng2.parentElement());
  7644. if (rng.compareEndPoints('StartToEnd', rng2) === 0)
  7645. rng2.move('character', -1);
  7646. rng2.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_end" style="' + styles + '">' + chr + '</span>');
  7647. }
  7648. } catch (ex) {
  7649. // IE might throw unspecified error so lets ignore it
  7650. return null;
  7651. }
  7652. } else {
  7653. // Control selection
  7654. element = rng.item(0);
  7655. name = element.nodeName;
  7656. return {name : name, index : findIndex(name, element)};
  7657. }
  7658. } else {
  7659. element = t.getNode();
  7660. name = element.nodeName;
  7661. if (name == 'IMG')
  7662. return {name : name, index : findIndex(name, element)};
  7663. // W3C method
  7664. rng2 = normalizeTableCellSelection(rng.cloneRange());
  7665. // Insert end marker
  7666. if (!collapsed) {
  7667. rng2.collapse(false);
  7668. rng2.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_end', style : styles}, chr));
  7669. }
  7670. rng = normalizeTableCellSelection(rng);
  7671. rng.collapse(true);
  7672. rng.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_start', style : styles}, chr));
  7673. }
  7674. t.moveToBookmark({id : id, keep : 1});
  7675. return {id : id};
  7676. },
  7677. moveToBookmark : function(bookmark) {
  7678. var t = this, dom = t.dom, marker1, marker2, rng, root, startContainer, endContainer, startOffset, endOffset;
  7679. function setEndPoint(start) {
  7680. var point = bookmark[start ? 'start' : 'end'], i, node, offset, children;
  7681. if (point) {
  7682. offset = point[0];
  7683. // Find container node
  7684. for (node = root, i = point.length - 1; i >= 1; i--) {
  7685. children = node.childNodes;
  7686. if (point[i] > children.length - 1)
  7687. return;
  7688. node = children[point[i]];
  7689. }
  7690. // Move text offset to best suitable location
  7691. if (node.nodeType === 3)
  7692. offset = Math.min(point[0], node.nodeValue.length);
  7693. // Move element offset to best suitable location
  7694. if (node.nodeType === 1)
  7695. offset = Math.min(point[0], node.childNodes.length);
  7696. // Set offset within container node
  7697. if (start)
  7698. rng.setStart(node, offset);
  7699. else
  7700. rng.setEnd(node, offset);
  7701. }
  7702. return true;
  7703. };
  7704. function restoreEndPoint(suffix) {
  7705. var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev, keep = bookmark.keep;
  7706. if (marker) {
  7707. node = marker.parentNode;
  7708. if (suffix == 'start') {
  7709. if (!keep) {
  7710. idx = dom.nodeIndex(marker);
  7711. } else {
  7712. node = marker.firstChild;
  7713. idx = 1;
  7714. }
  7715. startContainer = endContainer = node;
  7716. startOffset = endOffset = idx;
  7717. } else {
  7718. if (!keep) {
  7719. idx = dom.nodeIndex(marker);
  7720. } else {
  7721. node = marker.firstChild;
  7722. idx = 1;
  7723. }
  7724. endContainer = node;
  7725. endOffset = idx;
  7726. }
  7727. if (!keep) {
  7728. prev = marker.previousSibling;
  7729. next = marker.nextSibling;
  7730. // Remove all marker text nodes
  7731. each(tinymce.grep(marker.childNodes), function(node) {
  7732. if (node.nodeType == 3)
  7733. node.nodeValue = node.nodeValue.replace(/\uFEFF/g, '');
  7734. });
  7735. // Remove marker but keep children if for example contents where inserted into the marker
  7736. // Also remove duplicated instances of the marker for example by a split operation or by WebKit auto split on paste feature
  7737. while (marker = dom.get(bookmark.id + '_' + suffix))
  7738. dom.remove(marker, 1);
  7739. // If siblings are text nodes then merge them unless it's Opera since it some how removes the node
  7740. // 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
  7741. if (prev && next && prev.nodeType == next.nodeType && prev.nodeType == 3 && !tinymce.isOpera) {
  7742. idx = prev.nodeValue.length;
  7743. prev.appendData(next.nodeValue);
  7744. dom.remove(next);
  7745. if (suffix == 'start') {
  7746. startContainer = endContainer = prev;
  7747. startOffset = endOffset = idx;
  7748. } else {
  7749. endContainer = prev;
  7750. endOffset = idx;
  7751. }
  7752. }
  7753. }
  7754. }
  7755. };
  7756. function addBogus(node) {
  7757. // Adds a bogus BR element for empty block elements
  7758. if (dom.isBlock(node) && !node.innerHTML && !isIE)
  7759. node.innerHTML = '<br data-mce-bogus="1" />';
  7760. return node;
  7761. };
  7762. if (bookmark) {
  7763. if (bookmark.start) {
  7764. rng = dom.createRng();
  7765. root = dom.getRoot();
  7766. if (t.tridentSel)
  7767. return t.tridentSel.moveToBookmark(bookmark);
  7768. if (setEndPoint(true) && setEndPoint()) {
  7769. t.setRng(rng);
  7770. }
  7771. } else if (bookmark.id) {
  7772. // Restore start/end points
  7773. restoreEndPoint('start');
  7774. restoreEndPoint('end');
  7775. if (startContainer) {
  7776. rng = dom.createRng();
  7777. rng.setStart(addBogus(startContainer), startOffset);
  7778. rng.setEnd(addBogus(endContainer), endOffset);
  7779. t.setRng(rng);
  7780. }
  7781. } else if (bookmark.name) {
  7782. t.select(dom.select(bookmark.name)[bookmark.index]);
  7783. } else if (bookmark.rng)
  7784. t.setRng(bookmark.rng);
  7785. }
  7786. },
  7787. select : function(node, content) {
  7788. var t = this, dom = t.dom, rng = dom.createRng(), idx;
  7789. function setPoint(node, start) {
  7790. var walker = new TreeWalker(node, node);
  7791. do {
  7792. // Text node
  7793. if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length !== 0) {
  7794. if (start)
  7795. rng.setStart(node, 0);
  7796. else
  7797. rng.setEnd(node, node.nodeValue.length);
  7798. return;
  7799. }
  7800. // BR element
  7801. if (node.nodeName == 'BR') {
  7802. if (start)
  7803. rng.setStartBefore(node);
  7804. else
  7805. rng.setEndBefore(node);
  7806. return;
  7807. }
  7808. } while (node = (start ? walker.next() : walker.prev()));
  7809. };
  7810. if (node) {
  7811. idx = dom.nodeIndex(node);
  7812. rng.setStart(node.parentNode, idx);
  7813. rng.setEnd(node.parentNode, idx + 1);
  7814. // Find first/last text node or BR element
  7815. if (content) {
  7816. setPoint(node, 1);
  7817. setPoint(node);
  7818. }
  7819. t.setRng(rng);
  7820. }
  7821. return node;
  7822. },
  7823. isCollapsed : function() {
  7824. var t = this, r = t.getRng(), s = t.getSel();
  7825. if (!r || r.item)
  7826. return false;
  7827. if (r.compareEndPoints)
  7828. return r.compareEndPoints('StartToEnd', r) === 0;
  7829. return !s || r.collapsed;
  7830. },
  7831. collapse : function(to_start) {
  7832. var self = this, rng = self.getRng(), node;
  7833. // Control range on IE
  7834. if (rng.item) {
  7835. node = rng.item(0);
  7836. rng = self.win.document.body.createTextRange();
  7837. rng.moveToElementText(node);
  7838. }
  7839. rng.collapse(!!to_start);
  7840. self.setRng(rng);
  7841. },
  7842. getSel : function() {
  7843. var t = this, w = this.win;
  7844. return w.getSelection ? w.getSelection() : w.document.selection;
  7845. },
  7846. getRng : function(w3c) {
  7847. var self = this, selection, rng, elm, doc = self.win.document;
  7848. // Found tridentSel object then we need to use that one
  7849. if (w3c && self.tridentSel) {
  7850. return self.tridentSel.getRangeAt(0);
  7851. }
  7852. try {
  7853. if (selection = self.getSel()) {
  7854. rng = selection.rangeCount > 0 ? selection.getRangeAt(0) : (selection.createRange ? selection.createRange() : doc.createRange());
  7855. }
  7856. } catch (ex) {
  7857. // IE throws unspecified error here if TinyMCE is placed in a frame/iframe
  7858. }
  7859. // We have W3C ranges and it's IE then fake control selection since IE9 doesn't handle that correctly yet
  7860. if (tinymce.isIE && rng && rng.setStart && doc.selection.createRange().item) {
  7861. elm = doc.selection.createRange().item(0);
  7862. rng = doc.createRange();
  7863. rng.setStartBefore(elm);
  7864. rng.setEndAfter(elm);
  7865. }
  7866. // No range found then create an empty one
  7867. // This can occur when the editor is placed in a hidden container element on Gecko
  7868. // Or on IE when there was an exception
  7869. if (!rng) {
  7870. rng = doc.createRange ? doc.createRange() : doc.body.createTextRange();
  7871. }
  7872. // If range is at start of document then move it to start of body
  7873. if (rng.setStart && rng.startContainer.nodeType === 9 && rng.collapsed) {
  7874. elm = self.dom.getRoot();
  7875. rng.setStart(elm, 0);
  7876. rng.setEnd(elm, 0);
  7877. }
  7878. if (self.selectedRange && self.explicitRange) {
  7879. if (rng.compareBoundaryPoints(rng.START_TO_START, self.selectedRange) === 0 && rng.compareBoundaryPoints(rng.END_TO_END, self.selectedRange) === 0) {
  7880. // Safari, Opera and Chrome only ever select text which causes the range to change.
  7881. // This lets us use the originally set range if the selection hasn't been changed by the user.
  7882. rng = self.explicitRange;
  7883. } else {
  7884. self.selectedRange = null;
  7885. self.explicitRange = null;
  7886. }
  7887. }
  7888. return rng;
  7889. },
  7890. setRng : function(r, forward) {
  7891. var s, t = this;
  7892. if (!t.tridentSel) {
  7893. s = t.getSel();
  7894. if (s) {
  7895. t.explicitRange = r;
  7896. try {
  7897. s.removeAllRanges();
  7898. } catch (ex) {
  7899. // IE9 might throw errors here don't know why
  7900. }
  7901. s.addRange(r);
  7902. // Forward is set to false and we have an extend function
  7903. if (forward === false && s.extend) {
  7904. s.collapse(r.endContainer, r.endOffset);
  7905. s.extend(r.startContainer, r.startOffset);
  7906. }
  7907. // adding range isn't always successful so we need to check range count otherwise an exception can occur
  7908. t.selectedRange = s.rangeCount > 0 ? s.getRangeAt(0) : null;
  7909. }
  7910. } else {
  7911. // Is W3C Range
  7912. if (r.cloneRange) {
  7913. try {
  7914. t.tridentSel.addRange(r);
  7915. return;
  7916. } catch (ex) {
  7917. //IE9 throws an error here if called before selection is placed in the editor
  7918. }
  7919. }
  7920. // Is IE specific range
  7921. try {
  7922. r.select();
  7923. } catch (ex) {
  7924. // Needed for some odd IE bug #1843306
  7925. }
  7926. }
  7927. },
  7928. setNode : function(n) {
  7929. var t = this;
  7930. t.setContent(t.dom.getOuterHTML(n));
  7931. return n;
  7932. },
  7933. getNode : function() {
  7934. var t = this, rng = t.getRng(), sel = t.getSel(), elm, start = rng.startContainer, end = rng.endContainer;
  7935. function skipEmptyTextNodes(n, forwards) {
  7936. var orig = n;
  7937. while (n && n.nodeType === 3 && n.length === 0) {
  7938. n = forwards ? n.nextSibling : n.previousSibling;
  7939. }
  7940. return n || orig;
  7941. };
  7942. // Range maybe lost after the editor is made visible again
  7943. if (!rng)
  7944. return t.dom.getRoot();
  7945. if (rng.setStart) {
  7946. elm = rng.commonAncestorContainer;
  7947. // Handle selection a image or other control like element such as anchors
  7948. if (!rng.collapsed) {
  7949. if (rng.startContainer == rng.endContainer) {
  7950. if (rng.endOffset - rng.startOffset < 2) {
  7951. if (rng.startContainer.hasChildNodes())
  7952. elm = rng.startContainer.childNodes[rng.startOffset];
  7953. }
  7954. }
  7955. // If the anchor node is a element instead of a text node then return this element
  7956. //if (tinymce.isWebKit && sel.anchorNode && sel.anchorNode.nodeType == 1)
  7957. // return sel.anchorNode.childNodes[sel.anchorOffset];
  7958. // Handle cases where the selection is immediately wrapped around a node and return that node instead of it's parent.
  7959. // This happens when you double click an underlined word in FireFox.
  7960. if (start.nodeType === 3 && end.nodeType === 3) {
  7961. if (start.length === rng.startOffset) {
  7962. start = skipEmptyTextNodes(start.nextSibling, true);
  7963. } else {
  7964. start = start.parentNode;
  7965. }
  7966. if (rng.endOffset === 0) {
  7967. end = skipEmptyTextNodes(end.previousSibling, false);
  7968. } else {
  7969. end = end.parentNode;
  7970. }
  7971. if (start && start === end)
  7972. return start;
  7973. }
  7974. }
  7975. if (elm && elm.nodeType == 3)
  7976. return elm.parentNode;
  7977. return elm;
  7978. }
  7979. return rng.item ? rng.item(0) : rng.parentElement();
  7980. },
  7981. getSelectedBlocks : function(st, en) {
  7982. var t = this, dom = t.dom, sb, eb, n, bl = [];
  7983. sb = dom.getParent(st || t.getStart(), dom.isBlock);
  7984. eb = dom.getParent(en || t.getEnd(), dom.isBlock);
  7985. if (sb)
  7986. bl.push(sb);
  7987. if (sb && eb && sb != eb) {
  7988. n = sb;
  7989. var walker = new TreeWalker(sb, dom.getRoot());
  7990. while ((n = walker.next()) && n != eb) {
  7991. if (dom.isBlock(n))
  7992. bl.push(n);
  7993. }
  7994. }
  7995. if (eb && sb != eb)
  7996. bl.push(eb);
  7997. return bl;
  7998. },
  7999. isForward: function(){
  8000. var dom = this.dom, sel = this.getSel(), anchorRange, focusRange;
  8001. // No support for selection direction then always return true
  8002. if (!sel || sel.anchorNode == null || sel.focusNode == null) {
  8003. return true;
  8004. }
  8005. anchorRange = dom.createRng();
  8006. anchorRange.setStart(sel.anchorNode, sel.anchorOffset);
  8007. anchorRange.collapse(true);
  8008. focusRange = dom.createRng();
  8009. focusRange.setStart(sel.focusNode, sel.focusOffset);
  8010. focusRange.collapse(true);
  8011. return anchorRange.compareBoundaryPoints(anchorRange.START_TO_START, focusRange) <= 0;
  8012. },
  8013. normalize : function() {
  8014. var self = this, rng, normalized, collapsed, node, sibling;
  8015. function normalizeEndPoint(start) {
  8016. var container, offset, walker, dom = self.dom, body = dom.getRoot(), node, nonEmptyElementsMap, nodeName;
  8017. function hasBrBeforeAfter(node, left) {
  8018. var walker = new TreeWalker(node, dom.getParent(node.parentNode, dom.isBlock) || body);
  8019. while (node = walker[left ? 'prev' : 'next']()) {
  8020. if (node.nodeName === "BR") {
  8021. return true;
  8022. }
  8023. }
  8024. };
  8025. // Walks the dom left/right to find a suitable text node to move the endpoint into
  8026. // It will only walk within the current parent block or body and will stop if it hits a block or a BR/IMG
  8027. function findTextNodeRelative(left, startNode) {
  8028. var walker, lastInlineElement;
  8029. startNode = startNode || container;
  8030. walker = new TreeWalker(startNode, dom.getParent(startNode.parentNode, dom.isBlock) || body);
  8031. // Walk left until we hit a text node we can move to or a block/br/img
  8032. while (node = walker[left ? 'prev' : 'next']()) {
  8033. // Found text node that has a length
  8034. if (node.nodeType === 3 && node.nodeValue.length > 0) {
  8035. container = node;
  8036. offset = left ? node.nodeValue.length : 0;
  8037. normalized = true;
  8038. return;
  8039. }
  8040. // Break if we find a block or a BR/IMG/INPUT etc
  8041. if (dom.isBlock(node) || nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  8042. return;
  8043. }
  8044. lastInlineElement = node;
  8045. }
  8046. // Only fetch the last inline element when in caret mode for now
  8047. if (collapsed && lastInlineElement) {
  8048. container = lastInlineElement;
  8049. normalized = true;
  8050. offset = 0;
  8051. }
  8052. };
  8053. container = rng[(start ? 'start' : 'end') + 'Container'];
  8054. offset = rng[(start ? 'start' : 'end') + 'Offset'];
  8055. nonEmptyElementsMap = dom.schema.getNonEmptyElements();
  8056. // If the container is a document move it to the body element
  8057. if (container.nodeType === 9) {
  8058. container = dom.getRoot();
  8059. offset = 0;
  8060. }
  8061. // If the container is body try move it into the closest text node or position
  8062. if (container === body) {
  8063. // If start is before/after a image, table etc
  8064. if (start) {
  8065. node = container.childNodes[offset > 0 ? offset - 1 : 0];
  8066. if (node) {
  8067. nodeName = node.nodeName.toLowerCase();
  8068. if (nonEmptyElementsMap[node.nodeName] || node.nodeName == "TABLE") {
  8069. return;
  8070. }
  8071. }
  8072. }
  8073. // Resolve the index
  8074. if (container.hasChildNodes()) {
  8075. container = container.childNodes[Math.min(!start && offset > 0 ? offset - 1 : offset, container.childNodes.length - 1)];
  8076. offset = 0;
  8077. // Don't walk into elements that doesn't have any child nodes like a IMG
  8078. if (container.hasChildNodes() && !/TABLE/.test(container.nodeName)) {
  8079. // Walk the DOM to find a text node to place the caret at or a BR
  8080. node = container;
  8081. walker = new TreeWalker(container, body);
  8082. do {
  8083. // Found a text node use that position
  8084. if (node.nodeType === 3 && node.nodeValue.length > 0) {
  8085. offset = start ? 0 : node.nodeValue.length;
  8086. container = node;
  8087. normalized = true;
  8088. break;
  8089. }
  8090. // Found a BR/IMG element that we can place the caret before
  8091. if (nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  8092. offset = dom.nodeIndex(node);
  8093. container = node.parentNode;
  8094. // Put caret after image when moving the end point
  8095. if (node.nodeName == "IMG" && !start) {
  8096. offset++;
  8097. }
  8098. normalized = true;
  8099. break;
  8100. }
  8101. } while (node = (start ? walker.next() : walker.prev()));
  8102. }
  8103. }
  8104. }
  8105. // Lean the caret to the left if possible
  8106. if (collapsed) {
  8107. // So this: <b>x</b><i>|x</i>
  8108. // Becomes: <b>x|</b><i>x</i>
  8109. // Seems that only gecko has issues with this
  8110. if (container.nodeType === 3 && offset === 0) {
  8111. findTextNodeRelative(true);
  8112. }
  8113. // Lean left into empty inline elements when the caret is before a BR
  8114. // So this: <i><b></b><i>|<br></i>
  8115. // Becomes: <i><b>|</b><i><br></i>
  8116. // Seems that only gecko has issues with this
  8117. if (container.nodeType === 1) {
  8118. node = container.childNodes[offset];
  8119. if(node && node.nodeName === 'BR' && !hasBrBeforeAfter(node) && !hasBrBeforeAfter(node, true)) {
  8120. findTextNodeRelative(true, container.childNodes[offset]);
  8121. }
  8122. }
  8123. }
  8124. // Lean the start of the selection right if possible
  8125. // So this: x[<b>x]</b>
  8126. // Becomes: x<b>[x]</b>
  8127. if (start && !collapsed && container.nodeType === 3 && offset === container.nodeValue.length) {
  8128. findTextNodeRelative(false);
  8129. }
  8130. // Set endpoint if it was normalized
  8131. if (normalized)
  8132. rng['set' + (start ? 'Start' : 'End')](container, offset);
  8133. };
  8134. // Normalize only on non IE browsers for now
  8135. if (tinymce.isIE)
  8136. return;
  8137. rng = self.getRng();
  8138. collapsed = rng.collapsed;
  8139. // Normalize the end points
  8140. normalizeEndPoint(true);
  8141. if (!collapsed)
  8142. normalizeEndPoint();
  8143. // Set the selection if it was normalized
  8144. if (normalized) {
  8145. // If it was collapsed then make sure it still is
  8146. if (collapsed) {
  8147. rng.collapse(true);
  8148. }
  8149. //console.log(self.dom.dumpRng(rng));
  8150. self.setRng(rng, self.isForward());
  8151. }
  8152. },
  8153. selectorChanged: function(selector, callback) {
  8154. var self = this, currentSelectors;
  8155. if (!self.selectorChangedData) {
  8156. self.selectorChangedData = {};
  8157. currentSelectors = {};
  8158. self.editor.onNodeChange.addToTop(function(ed, cm, node) {
  8159. var dom = self.dom, parents = dom.getParents(node, null, dom.getRoot()), matchedSelectors = {};
  8160. // Check for new matching selectors
  8161. each(self.selectorChangedData, function(callbacks, selector) {
  8162. each(parents, function(node) {
  8163. if (dom.is(node, selector)) {
  8164. if (!currentSelectors[selector]) {
  8165. // Execute callbacks
  8166. each(callbacks, function(callback) {
  8167. callback(true, {node: node, selector: selector, parents: parents});
  8168. });
  8169. currentSelectors[selector] = callbacks;
  8170. }
  8171. matchedSelectors[selector] = callbacks;
  8172. return false;
  8173. }
  8174. });
  8175. });
  8176. // Check if current selectors still match
  8177. each(currentSelectors, function(callbacks, selector) {
  8178. if (!matchedSelectors[selector]) {
  8179. delete currentSelectors[selector];
  8180. each(callbacks, function(callback) {
  8181. callback(false, {node: node, selector: selector, parents: parents});
  8182. });
  8183. }
  8184. });
  8185. });
  8186. }
  8187. // Add selector listeners
  8188. if (!self.selectorChangedData[selector]) {
  8189. self.selectorChangedData[selector] = [];
  8190. }
  8191. self.selectorChangedData[selector].push(callback);
  8192. return self;
  8193. },
  8194. scrollIntoView: function(elm) {
  8195. var y, viewPort, self = this, dom = self.dom;
  8196. viewPort = dom.getViewPort(self.editor.getWin());
  8197. y = dom.getPos(elm).y;
  8198. if (y < viewPort.y || y + 25 > viewPort.y + viewPort.h) {
  8199. self.editor.getWin().scrollTo(0, y < viewPort.y ? y : y - viewPort.h + 25);
  8200. }
  8201. },
  8202. destroy : function(manual) {
  8203. var self = this;
  8204. self.win = null;
  8205. // Manual destroy then remove unload handler
  8206. if (!manual)
  8207. tinymce.removeUnload(self.destroy);
  8208. },
  8209. // IE has an issue where you can't select/move the caret by clicking outside the body if the document is in standards mode
  8210. _fixIESelection : function() {
  8211. var dom = this.dom, doc = dom.doc, body = doc.body, started, startRng, htmlElm;
  8212. // Return range from point or null if it failed
  8213. function rngFromPoint(x, y) {
  8214. var rng = body.createTextRange();
  8215. try {
  8216. rng.moveToPoint(x, y);
  8217. } catch (ex) {
  8218. // IE sometimes throws and exception, so lets just ignore it
  8219. rng = null;
  8220. }
  8221. return rng;
  8222. };
  8223. // Fires while the selection is changing
  8224. function selectionChange(e) {
  8225. var pointRng;
  8226. // Check if the button is down or not
  8227. if (e.button) {
  8228. // Create range from mouse position
  8229. pointRng = rngFromPoint(e.x, e.y);
  8230. if (pointRng) {
  8231. // Check if pointRange is before/after selection then change the endPoint
  8232. if (pointRng.compareEndPoints('StartToStart', startRng) > 0)
  8233. pointRng.setEndPoint('StartToStart', startRng);
  8234. else
  8235. pointRng.setEndPoint('EndToEnd', startRng);
  8236. pointRng.select();
  8237. }
  8238. } else
  8239. endSelection();
  8240. }
  8241. // Removes listeners
  8242. function endSelection() {
  8243. var rng = doc.selection.createRange();
  8244. // If the range is collapsed then use the last start range
  8245. if (startRng && !rng.item && rng.compareEndPoints('StartToEnd', rng) === 0)
  8246. startRng.select();
  8247. dom.unbind(doc, 'mouseup', endSelection);
  8248. dom.unbind(doc, 'mousemove', selectionChange);
  8249. startRng = started = 0;
  8250. };
  8251. // Make HTML element unselectable since we are going to handle selection by hand
  8252. doc.documentElement.unselectable = true;
  8253. // Detect when user selects outside BODY
  8254. dom.bind(doc, ['mousedown', 'contextmenu'], function(e) {
  8255. if (e.target.nodeName === 'HTML') {
  8256. if (started)
  8257. endSelection();
  8258. // Detect vertical scrollbar, since IE will fire a mousedown on the scrollbar and have target set as HTML
  8259. htmlElm = doc.documentElement;
  8260. if (htmlElm.scrollHeight > htmlElm.clientHeight)
  8261. return;
  8262. started = 1;
  8263. // Setup start position
  8264. startRng = rngFromPoint(e.x, e.y);
  8265. if (startRng) {
  8266. // Listen for selection change events
  8267. dom.bind(doc, 'mouseup', endSelection);
  8268. dom.bind(doc, 'mousemove', selectionChange);
  8269. dom.win.focus();
  8270. startRng.select();
  8271. }
  8272. }
  8273. });
  8274. }
  8275. });
  8276. })(tinymce);
  8277. (function(tinymce) {
  8278. tinymce.dom.Serializer = function(settings, dom, schema) {
  8279. var onPreProcess, onPostProcess, isIE = tinymce.isIE, each = tinymce.each, htmlParser;
  8280. // Support the old apply_source_formatting option
  8281. if (!settings.apply_source_formatting)
  8282. settings.indent = false;
  8283. // Default DOM and Schema if they are undefined
  8284. dom = dom || tinymce.DOM;
  8285. schema = schema || new tinymce.html.Schema(settings);
  8286. settings.entity_encoding = settings.entity_encoding || 'named';
  8287. settings.remove_trailing_brs = "remove_trailing_brs" in settings ? settings.remove_trailing_brs : true;
  8288. onPreProcess = new tinymce.util.Dispatcher(self);
  8289. onPostProcess = new tinymce.util.Dispatcher(self);
  8290. htmlParser = new tinymce.html.DomParser(settings, schema);
  8291. // Convert move data-mce-src, data-mce-href and data-mce-style into nodes or process them if needed
  8292. htmlParser.addAttributeFilter('src,href,style', function(nodes, name) {
  8293. var i = nodes.length, node, value, internalName = 'data-mce-' + name, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope, undef;
  8294. while (i--) {
  8295. node = nodes[i];
  8296. value = node.attributes.map[internalName];
  8297. if (value !== undef) {
  8298. // Set external name to internal value and remove internal
  8299. node.attr(name, value.length > 0 ? value : null);
  8300. node.attr(internalName, null);
  8301. } else {
  8302. // No internal attribute found then convert the value we have in the DOM
  8303. value = node.attributes.map[name];
  8304. if (name === "style")
  8305. value = dom.serializeStyle(dom.parseStyle(value), node.name);
  8306. else if (urlConverter)
  8307. value = urlConverter.call(urlConverterScope, value, name, node.name);
  8308. node.attr(name, value.length > 0 ? value : null);
  8309. }
  8310. }
  8311. });
  8312. // Remove internal classes mceItem<..> or mceSelected
  8313. htmlParser.addAttributeFilter('class', function(nodes, name) {
  8314. var i = nodes.length, node, value;
  8315. while (i--) {
  8316. node = nodes[i];
  8317. value = node.attr('class').replace(/(?:^|\s)mce(Item\w+|Selected)(?!\S)/g, '');
  8318. node.attr('class', value.length > 0 ? value : null);
  8319. }
  8320. });
  8321. // Remove bookmark elements
  8322. htmlParser.addAttributeFilter('data-mce-type', function(nodes, name, args) {
  8323. var i = nodes.length, node;
  8324. while (i--) {
  8325. node = nodes[i];
  8326. if (node.attributes.map['data-mce-type'] === 'bookmark' && !args.cleanup)
  8327. node.remove();
  8328. }
  8329. });
  8330. // Remove expando attributes
  8331. htmlParser.addAttributeFilter('data-mce-expando', function(nodes, name, args) {
  8332. var i = nodes.length;
  8333. while (i--) {
  8334. nodes[i].attr(name, null);
  8335. }
  8336. });
  8337. htmlParser.addNodeFilter('noscript', function(nodes) {
  8338. var i = nodes.length, node;
  8339. while (i--) {
  8340. node = nodes[i].firstChild;
  8341. if (node) {
  8342. node.value = tinymce.html.Entities.decode(node.value);
  8343. }
  8344. }
  8345. });
  8346. // Force script into CDATA sections and remove the mce- prefix also add comments around styles
  8347. htmlParser.addNodeFilter('script,style', function(nodes, name) {
  8348. var i = nodes.length, node, value;
  8349. function trim(value) {
  8350. return value.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n')
  8351. .replace(/^[\r\n]*|[\r\n]*$/g, '')
  8352. .replace(/^\s*((<!--)?(\s*\/\/)?\s*<!\[CDATA\[|(<!--\s*)?\/\*\s*<!\[CDATA\[\s*\*\/|(\/\/)?\s*<!--|\/\*\s*<!--\s*\*\/)\s*[\r\n]*/gi, '')
  8353. .replace(/\s*(\/\*\s*\]\]>\s*\*\/(-->)?|\s*\/\/\s*\]\]>(-->)?|\/\/\s*(-->)?|\]\]>|\/\*\s*-->\s*\*\/|\s*-->\s*)\s*$/g, '');
  8354. };
  8355. while (i--) {
  8356. node = nodes[i];
  8357. value = node.firstChild ? node.firstChild.value : '';
  8358. if (name === "script") {
  8359. // Remove mce- prefix from script elements
  8360. node.attr('type', (node.attr('type') || 'text/javascript').replace(/^mce\-/, ''));
  8361. if (value.length > 0)
  8362. node.firstChild.value = '// <![CDATA[\n' + trim(value) + '\n// ]]>';
  8363. } else {
  8364. if (value.length > 0)
  8365. node.firstChild.value = '<!--\n' + trim(value) + '\n-->';
  8366. }
  8367. }
  8368. });
  8369. // Convert comments to cdata and handle protected comments
  8370. htmlParser.addNodeFilter('#comment', function(nodes, name) {
  8371. var i = nodes.length, node;
  8372. while (i--) {
  8373. node = nodes[i];
  8374. if (node.value.indexOf('[CDATA[') === 0) {
  8375. node.name = '#cdata';
  8376. node.type = 4;
  8377. node.value = node.value.replace(/^\[CDATA\[|\]\]$/g, '');
  8378. } else if (node.value.indexOf('mce:protected ') === 0) {
  8379. node.name = "#text";
  8380. node.type = 3;
  8381. node.raw = true;
  8382. node.value = unescape(node.value).substr(14);
  8383. }
  8384. }
  8385. });
  8386. htmlParser.addNodeFilter('xml:namespace,input', function(nodes, name) {
  8387. var i = nodes.length, node;
  8388. while (i--) {
  8389. node = nodes[i];
  8390. if (node.type === 7)
  8391. node.remove();
  8392. else if (node.type === 1) {
  8393. if (name === "input" && !("type" in node.attributes.map))
  8394. node.attr('type', 'text');
  8395. }
  8396. }
  8397. });
  8398. // Fix list elements, TODO: Replace this later
  8399. if (settings.fix_list_elements) {
  8400. htmlParser.addNodeFilter('ul,ol', function(nodes, name) {
  8401. var i = nodes.length, node, parentNode;
  8402. while (i--) {
  8403. node = nodes[i];
  8404. parentNode = node.parent;
  8405. if (parentNode.name === 'ul' || parentNode.name === 'ol') {
  8406. if (node.prev && node.prev.name === 'li') {
  8407. node.prev.append(node);
  8408. }
  8409. }
  8410. }
  8411. });
  8412. }
  8413. // Remove internal data attributes
  8414. htmlParser.addAttributeFilter('data-mce-src,data-mce-href,data-mce-style', function(nodes, name) {
  8415. var i = nodes.length;
  8416. while (i--) {
  8417. nodes[i].attr(name, null);
  8418. }
  8419. });
  8420. // Return public methods
  8421. return {
  8422. schema : schema,
  8423. addNodeFilter : htmlParser.addNodeFilter,
  8424. addAttributeFilter : htmlParser.addAttributeFilter,
  8425. onPreProcess : onPreProcess,
  8426. onPostProcess : onPostProcess,
  8427. serialize : function(node, args) {
  8428. var impl, doc, oldDoc, htmlSerializer, content;
  8429. // Explorer won't clone contents of script and style and the
  8430. // selected index of select elements are cleared on a clone operation.
  8431. if (isIE && dom.select('script,style,select,map').length > 0) {
  8432. content = node.innerHTML;
  8433. node = node.cloneNode(false);
  8434. dom.setHTML(node, content);
  8435. } else
  8436. node = node.cloneNode(true);
  8437. // Nodes needs to be attached to something in WebKit/Opera
  8438. // Older builds of Opera crashes if you attach the node to an document created dynamically
  8439. // and since we can't feature detect a crash we need to sniff the acutal build number
  8440. // This fix will make DOM ranges and make Sizzle happy!
  8441. impl = node.ownerDocument.implementation;
  8442. if (impl.createHTMLDocument) {
  8443. // Create an empty HTML document
  8444. doc = impl.createHTMLDocument("");
  8445. // Add the element or it's children if it's a body element to the new document
  8446. each(node.nodeName == 'BODY' ? node.childNodes : [node], function(node) {
  8447. doc.body.appendChild(doc.importNode(node, true));
  8448. });
  8449. // Grab first child or body element for serialization
  8450. if (node.nodeName != 'BODY')
  8451. node = doc.body.firstChild;
  8452. else
  8453. node = doc.body;
  8454. // set the new document in DOMUtils so createElement etc works
  8455. oldDoc = dom.doc;
  8456. dom.doc = doc;
  8457. }
  8458. args = args || {};
  8459. args.format = args.format || 'html';
  8460. // Pre process
  8461. if (!args.no_events) {
  8462. args.node = node;
  8463. onPreProcess.dispatch(self, args);
  8464. }
  8465. // Setup serializer
  8466. htmlSerializer = new tinymce.html.Serializer(settings, schema);
  8467. // Parse and serialize HTML
  8468. args.content = htmlSerializer.serialize(
  8469. htmlParser.parse(tinymce.trim(args.getInner ? node.innerHTML : dom.getOuterHTML(node)), args)
  8470. );
  8471. // Replace all BOM characters for now until we can find a better solution
  8472. if (!args.cleanup)
  8473. args.content = args.content.replace(/\uFEFF/g, '');
  8474. // Post process
  8475. if (!args.no_events)
  8476. onPostProcess.dispatch(self, args);
  8477. // Restore the old document if it was changed
  8478. if (oldDoc)
  8479. dom.doc = oldDoc;
  8480. args.node = null;
  8481. return args.content;
  8482. },
  8483. addRules : function(rules) {
  8484. schema.addValidElements(rules);
  8485. },
  8486. setRules : function(rules) {
  8487. schema.setValidElements(rules);
  8488. }
  8489. };
  8490. };
  8491. })(tinymce);
  8492. (function(tinymce) {
  8493. tinymce.dom.ScriptLoader = function(settings) {
  8494. var QUEUED = 0,
  8495. LOADING = 1,
  8496. LOADED = 2,
  8497. states = {},
  8498. queue = [],
  8499. scriptLoadedCallbacks = {},
  8500. queueLoadedCallbacks = [],
  8501. loading = 0,
  8502. undef;
  8503. function loadScript(url, callback) {
  8504. var t = this, dom = tinymce.DOM, elm, uri, loc, id;
  8505. // Execute callback when script is loaded
  8506. function done() {
  8507. dom.remove(id);
  8508. if (elm)
  8509. elm.onreadystatechange = elm.onload = elm = null;
  8510. callback();
  8511. };
  8512. function error() {
  8513. // Report the error so it's easier for people to spot loading errors
  8514. if (typeof(console) !== "undefined" && console.log)
  8515. console.log("Failed to load: " + url);
  8516. // We can't mark it as done if there is a load error since
  8517. // A) We don't want to produce 404 errors on the server and
  8518. // B) the onerror event won't fire on all browsers.
  8519. // done();
  8520. };
  8521. id = dom.uniqueId();
  8522. if (tinymce.isIE6) {
  8523. uri = new tinymce.util.URI(url);
  8524. loc = location;
  8525. // If script is from same domain and we
  8526. // use IE 6 then use XHR since it's more reliable
  8527. if (uri.host == loc.hostname && uri.port == loc.port && (uri.protocol + ':') == loc.protocol && uri.protocol.toLowerCase() != 'file') {
  8528. tinymce.util.XHR.send({
  8529. url : tinymce._addVer(uri.getURI()),
  8530. success : function(content) {
  8531. // Create new temp script element
  8532. var script = dom.create('script', {
  8533. type : 'text/javascript'
  8534. });
  8535. // Evaluate script in global scope
  8536. script.text = content;
  8537. document.getElementsByTagName('head')[0].appendChild(script);
  8538. dom.remove(script);
  8539. done();
  8540. },
  8541. error : error
  8542. });
  8543. return;
  8544. }
  8545. }
  8546. // Create new script element
  8547. elm = document.createElement('script');
  8548. elm.id = id;
  8549. elm.type = 'text/javascript';
  8550. elm.src = tinymce._addVer(url);
  8551. // Add onload listener for non IE browsers since IE9
  8552. // fires onload event before the script is parsed and executed
  8553. if (!tinymce.isIE)
  8554. elm.onload = done;
  8555. // Add onerror event will get fired on some browsers but not all of them
  8556. elm.onerror = error;
  8557. // Opera 9.60 doesn't seem to fire the onreadystate event at correctly
  8558. if (!tinymce.isOpera) {
  8559. elm.onreadystatechange = function() {
  8560. var state = elm.readyState;
  8561. // Loaded state is passed on IE 6 however there
  8562. // are known issues with this method but we can't use
  8563. // XHR in a cross domain loading
  8564. if (state == 'complete' || state == 'loaded')
  8565. done();
  8566. };
  8567. }
  8568. // Most browsers support this feature so we report errors
  8569. // for those at least to help users track their missing plugins etc
  8570. // todo: Removed since it produced error if the document is unloaded by navigating away, re-add it as an option
  8571. /*elm.onerror = function() {
  8572. alert('Failed to load: ' + url);
  8573. };*/
  8574. // Add script to document
  8575. (document.getElementsByTagName('head')[0] || document.body).appendChild(elm);
  8576. };
  8577. this.isDone = function(url) {
  8578. return states[url] == LOADED;
  8579. };
  8580. this.markDone = function(url) {
  8581. states[url] = LOADED;
  8582. };
  8583. this.add = this.load = function(url, callback, scope) {
  8584. var item, state = states[url];
  8585. // Add url to load queue
  8586. if (state == undef) {
  8587. queue.push(url);
  8588. states[url] = QUEUED;
  8589. }
  8590. if (callback) {
  8591. // Store away callback for later execution
  8592. if (!scriptLoadedCallbacks[url])
  8593. scriptLoadedCallbacks[url] = [];
  8594. scriptLoadedCallbacks[url].push({
  8595. func : callback,
  8596. scope : scope || this
  8597. });
  8598. }
  8599. };
  8600. this.loadQueue = function(callback, scope) {
  8601. this.loadScripts(queue, callback, scope);
  8602. };
  8603. this.loadScripts = function(scripts, callback, scope) {
  8604. var loadScripts;
  8605. function execScriptLoadedCallbacks(url) {
  8606. // Execute URL callback functions
  8607. tinymce.each(scriptLoadedCallbacks[url], function(callback) {
  8608. callback.func.call(callback.scope);
  8609. });
  8610. scriptLoadedCallbacks[url] = undef;
  8611. };
  8612. queueLoadedCallbacks.push({
  8613. func : callback,
  8614. scope : scope || this
  8615. });
  8616. loadScripts = function() {
  8617. var loadingScripts = tinymce.grep(scripts);
  8618. // Current scripts has been handled
  8619. scripts.length = 0;
  8620. // Load scripts that needs to be loaded
  8621. tinymce.each(loadingScripts, function(url) {
  8622. // Script is already loaded then execute script callbacks directly
  8623. if (states[url] == LOADED) {
  8624. execScriptLoadedCallbacks(url);
  8625. return;
  8626. }
  8627. // Is script not loading then start loading it
  8628. if (states[url] != LOADING) {
  8629. states[url] = LOADING;
  8630. loading++;
  8631. loadScript(url, function() {
  8632. states[url] = LOADED;
  8633. loading--;
  8634. execScriptLoadedCallbacks(url);
  8635. // Load more scripts if they where added by the recently loaded script
  8636. loadScripts();
  8637. });
  8638. }
  8639. });
  8640. // No scripts are currently loading then execute all pending queue loaded callbacks
  8641. if (!loading) {
  8642. tinymce.each(queueLoadedCallbacks, function(callback) {
  8643. callback.func.call(callback.scope);
  8644. });
  8645. queueLoadedCallbacks.length = 0;
  8646. }
  8647. };
  8648. loadScripts();
  8649. };
  8650. };
  8651. // Global script loader
  8652. tinymce.ScriptLoader = new tinymce.dom.ScriptLoader();
  8653. })(tinymce);
  8654. (function(tinymce) {
  8655. tinymce.dom.RangeUtils = function(dom) {
  8656. var INVISIBLE_CHAR = '\uFEFF';
  8657. this.walk = function(rng, callback) {
  8658. var startContainer = rng.startContainer,
  8659. startOffset = rng.startOffset,
  8660. endContainer = rng.endContainer,
  8661. endOffset = rng.endOffset,
  8662. ancestor, startPoint,
  8663. endPoint, node, parent, siblings, nodes;
  8664. // Handle table cell selection the table plugin enables
  8665. // you to fake select table cells and perform formatting actions on them
  8666. nodes = dom.select('td.mceSelected,th.mceSelected');
  8667. if (nodes.length > 0) {
  8668. tinymce.each(nodes, function(node) {
  8669. callback([node]);
  8670. });
  8671. return;
  8672. }
  8673. function exclude(nodes) {
  8674. var node;
  8675. // First node is excluded
  8676. node = nodes[0];
  8677. if (node.nodeType === 3 && node === startContainer && startOffset >= node.nodeValue.length) {
  8678. nodes.splice(0, 1);
  8679. }
  8680. // Last node is excluded
  8681. node = nodes[nodes.length - 1];
  8682. if (endOffset === 0 && nodes.length > 0 && node === endContainer && node.nodeType === 3) {
  8683. nodes.splice(nodes.length - 1, 1);
  8684. }
  8685. return nodes;
  8686. };
  8687. function collectSiblings(node, name, end_node) {
  8688. var siblings = [];
  8689. for (; node && node != end_node; node = node[name])
  8690. siblings.push(node);
  8691. return siblings;
  8692. };
  8693. function findEndPoint(node, root) {
  8694. do {
  8695. if (node.parentNode == root)
  8696. return node;
  8697. node = node.parentNode;
  8698. } while(node);
  8699. };
  8700. function walkBoundary(start_node, end_node, next) {
  8701. var siblingName = next ? 'nextSibling' : 'previousSibling';
  8702. for (node = start_node, parent = node.parentNode; node && node != end_node; node = parent) {
  8703. parent = node.parentNode;
  8704. siblings = collectSiblings(node == start_node ? node : node[siblingName], siblingName);
  8705. if (siblings.length) {
  8706. if (!next)
  8707. siblings.reverse();
  8708. callback(exclude(siblings));
  8709. }
  8710. }
  8711. };
  8712. // If index based start position then resolve it
  8713. if (startContainer.nodeType == 1 && startContainer.hasChildNodes())
  8714. startContainer = startContainer.childNodes[startOffset];
  8715. // If index based end position then resolve it
  8716. if (endContainer.nodeType == 1 && endContainer.hasChildNodes())
  8717. endContainer = endContainer.childNodes[Math.min(endOffset - 1, endContainer.childNodes.length - 1)];
  8718. // Same container
  8719. if (startContainer == endContainer)
  8720. return callback(exclude([startContainer]));
  8721. // Find common ancestor and end points
  8722. ancestor = dom.findCommonAncestor(startContainer, endContainer);
  8723. // Process left side
  8724. for (node = startContainer; node; node = node.parentNode) {
  8725. if (node === endContainer)
  8726. return walkBoundary(startContainer, ancestor, true);
  8727. if (node === ancestor)
  8728. break;
  8729. }
  8730. // Process right side
  8731. for (node = endContainer; node; node = node.parentNode) {
  8732. if (node === startContainer)
  8733. return walkBoundary(endContainer, ancestor);
  8734. if (node === ancestor)
  8735. break;
  8736. }
  8737. // Find start/end point
  8738. startPoint = findEndPoint(startContainer, ancestor) || startContainer;
  8739. endPoint = findEndPoint(endContainer, ancestor) || endContainer;
  8740. // Walk left leaf
  8741. walkBoundary(startContainer, startPoint, true);
  8742. // Walk the middle from start to end point
  8743. siblings = collectSiblings(
  8744. startPoint == startContainer ? startPoint : startPoint.nextSibling,
  8745. 'nextSibling',
  8746. endPoint == endContainer ? endPoint.nextSibling : endPoint
  8747. );
  8748. if (siblings.length)
  8749. callback(exclude(siblings));
  8750. // Walk right leaf
  8751. walkBoundary(endContainer, endPoint);
  8752. };
  8753. this.split = function(rng) {
  8754. var startContainer = rng.startContainer,
  8755. startOffset = rng.startOffset,
  8756. endContainer = rng.endContainer,
  8757. endOffset = rng.endOffset;
  8758. function splitText(node, offset) {
  8759. return node.splitText(offset);
  8760. };
  8761. // Handle single text node
  8762. if (startContainer == endContainer && startContainer.nodeType == 3) {
  8763. if (startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  8764. endContainer = splitText(startContainer, startOffset);
  8765. startContainer = endContainer.previousSibling;
  8766. if (endOffset > startOffset) {
  8767. endOffset = endOffset - startOffset;
  8768. startContainer = endContainer = splitText(endContainer, endOffset).previousSibling;
  8769. endOffset = endContainer.nodeValue.length;
  8770. startOffset = 0;
  8771. } else {
  8772. endOffset = 0;
  8773. }
  8774. }
  8775. } else {
  8776. // Split startContainer text node if needed
  8777. if (startContainer.nodeType == 3 && startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  8778. startContainer = splitText(startContainer, startOffset);
  8779. startOffset = 0;
  8780. }
  8781. // Split endContainer text node if needed
  8782. if (endContainer.nodeType == 3 && endOffset > 0 && endOffset < endContainer.nodeValue.length) {
  8783. endContainer = splitText(endContainer, endOffset).previousSibling;
  8784. endOffset = endContainer.nodeValue.length;
  8785. }
  8786. }
  8787. return {
  8788. startContainer : startContainer,
  8789. startOffset : startOffset,
  8790. endContainer : endContainer,
  8791. endOffset : endOffset
  8792. };
  8793. };
  8794. };
  8795. tinymce.dom.RangeUtils.compareRanges = function(rng1, rng2) {
  8796. if (rng1 && rng2) {
  8797. // Compare native IE ranges
  8798. if (rng1.item || rng1.duplicate) {
  8799. // Both are control ranges and the selected element matches
  8800. if (rng1.item && rng2.item && rng1.item(0) === rng2.item(0))
  8801. return true;
  8802. // Both are text ranges and the range matches
  8803. if (rng1.isEqual && rng2.isEqual && rng2.isEqual(rng1))
  8804. return true;
  8805. } else {
  8806. // Compare w3c ranges
  8807. return rng1.startContainer == rng2.startContainer && rng1.startOffset == rng2.startOffset;
  8808. }
  8809. }
  8810. return false;
  8811. };
  8812. })(tinymce);
  8813. (function(tinymce) {
  8814. var Event = tinymce.dom.Event, each = tinymce.each;
  8815. tinymce.create('tinymce.ui.KeyboardNavigation', {
  8816. KeyboardNavigation: function(settings, dom) {
  8817. var t = this, root = settings.root, items = settings.items,
  8818. enableUpDown = settings.enableUpDown, enableLeftRight = settings.enableLeftRight || !settings.enableUpDown,
  8819. excludeFromTabOrder = settings.excludeFromTabOrder,
  8820. itemFocussed, itemBlurred, rootKeydown, rootFocussed, focussedId;
  8821. dom = dom || tinymce.DOM;
  8822. itemFocussed = function(evt) {
  8823. focussedId = evt.target.id;
  8824. };
  8825. itemBlurred = function(evt) {
  8826. dom.setAttrib(evt.target.id, 'tabindex', '-1');
  8827. };
  8828. rootFocussed = function(evt) {
  8829. var item = dom.get(focussedId);
  8830. dom.setAttrib(item, 'tabindex', '0');
  8831. item.focus();
  8832. };
  8833. t.focus = function() {
  8834. dom.get(focussedId).focus();
  8835. };
  8836. t.destroy = function() {
  8837. each(items, function(item) {
  8838. var elm = dom.get(item.id);
  8839. dom.unbind(elm, 'focus', itemFocussed);
  8840. dom.unbind(elm, 'blur', itemBlurred);
  8841. });
  8842. var rootElm = dom.get(root);
  8843. dom.unbind(rootElm, 'focus', rootFocussed);
  8844. dom.unbind(rootElm, 'keydown', rootKeydown);
  8845. items = dom = root = t.focus = itemFocussed = itemBlurred = rootKeydown = rootFocussed = null;
  8846. t.destroy = function() {};
  8847. };
  8848. t.moveFocus = function(dir, evt) {
  8849. var idx = -1, controls = t.controls, newFocus;
  8850. if (!focussedId)
  8851. return;
  8852. each(items, function(item, index) {
  8853. if (item.id === focussedId) {
  8854. idx = index;
  8855. return false;
  8856. }
  8857. });
  8858. idx += dir;
  8859. if (idx < 0) {
  8860. idx = items.length - 1;
  8861. } else if (idx >= items.length) {
  8862. idx = 0;
  8863. }
  8864. newFocus = items[idx];
  8865. dom.setAttrib(focussedId, 'tabindex', '-1');
  8866. dom.setAttrib(newFocus.id, 'tabindex', '0');
  8867. dom.get(newFocus.id).focus();
  8868. if (settings.actOnFocus) {
  8869. settings.onAction(newFocus.id);
  8870. }
  8871. if (evt)
  8872. Event.cancel(evt);
  8873. };
  8874. rootKeydown = function(evt) {
  8875. 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;
  8876. switch (evt.keyCode) {
  8877. case DOM_VK_LEFT:
  8878. if (enableLeftRight) t.moveFocus(-1);
  8879. break;
  8880. case DOM_VK_RIGHT:
  8881. if (enableLeftRight) t.moveFocus(1);
  8882. break;
  8883. case DOM_VK_UP:
  8884. if (enableUpDown) t.moveFocus(-1);
  8885. break;
  8886. case DOM_VK_DOWN:
  8887. if (enableUpDown) t.moveFocus(1);
  8888. break;
  8889. case DOM_VK_ESCAPE:
  8890. if (settings.onCancel) {
  8891. settings.onCancel();
  8892. Event.cancel(evt);
  8893. }
  8894. break;
  8895. case DOM_VK_ENTER:
  8896. case DOM_VK_RETURN:
  8897. case DOM_VK_SPACE:
  8898. if (settings.onAction) {
  8899. settings.onAction(focussedId);
  8900. Event.cancel(evt);
  8901. }
  8902. break;
  8903. }
  8904. };
  8905. // Set up state and listeners for each item.
  8906. each(items, function(item, idx) {
  8907. var tabindex, elm;
  8908. if (!item.id) {
  8909. item.id = dom.uniqueId('_mce_item_');
  8910. }
  8911. elm = dom.get(item.id);
  8912. if (excludeFromTabOrder) {
  8913. dom.bind(elm, 'blur', itemBlurred);
  8914. tabindex = '-1';
  8915. } else {
  8916. tabindex = (idx === 0 ? '0' : '-1');
  8917. }
  8918. elm.setAttribute('tabindex', tabindex);
  8919. dom.bind(elm, 'focus', itemFocussed);
  8920. });
  8921. // Setup initial state for root element.
  8922. if (items[0]){
  8923. focussedId = items[0].id;
  8924. }
  8925. dom.setAttrib(root, 'tabindex', '-1');
  8926. // Setup listeners for root element.
  8927. var rootElm = dom.get(root);
  8928. dom.bind(rootElm, 'focus', rootFocussed);
  8929. dom.bind(rootElm, 'keydown', rootKeydown);
  8930. }
  8931. });
  8932. })(tinymce);
  8933. (function(tinymce) {
  8934. // Shorten class names
  8935. var DOM = tinymce.DOM, is = tinymce.is;
  8936. tinymce.create('tinymce.ui.Control', {
  8937. Control : function(id, s, editor) {
  8938. this.id = id;
  8939. this.settings = s = s || {};
  8940. this.rendered = false;
  8941. this.onRender = new tinymce.util.Dispatcher(this);
  8942. this.classPrefix = '';
  8943. this.scope = s.scope || this;
  8944. this.disabled = 0;
  8945. this.active = 0;
  8946. this.editor = editor;
  8947. },
  8948. setAriaProperty : function(property, value) {
  8949. var element = DOM.get(this.id + '_aria') || DOM.get(this.id);
  8950. if (element) {
  8951. DOM.setAttrib(element, 'aria-' + property, !!value);
  8952. }
  8953. },
  8954. focus : function() {
  8955. DOM.get(this.id).focus();
  8956. },
  8957. setDisabled : function(s) {
  8958. if (s != this.disabled) {
  8959. this.setAriaProperty('disabled', s);
  8960. this.setState('Disabled', s);
  8961. this.setState('Enabled', !s);
  8962. this.disabled = s;
  8963. }
  8964. },
  8965. isDisabled : function() {
  8966. return this.disabled;
  8967. },
  8968. setActive : function(s) {
  8969. if (s != this.active) {
  8970. this.setState('Active', s);
  8971. this.active = s;
  8972. this.setAriaProperty('pressed', s);
  8973. }
  8974. },
  8975. isActive : function() {
  8976. return this.active;
  8977. },
  8978. setState : function(c, s) {
  8979. var n = DOM.get(this.id);
  8980. c = this.classPrefix + c;
  8981. if (s)
  8982. DOM.addClass(n, c);
  8983. else
  8984. DOM.removeClass(n, c);
  8985. },
  8986. isRendered : function() {
  8987. return this.rendered;
  8988. },
  8989. renderHTML : function() {
  8990. },
  8991. renderTo : function(n) {
  8992. DOM.setHTML(n, this.renderHTML());
  8993. },
  8994. postRender : function() {
  8995. var t = this, b;
  8996. // Set pending states
  8997. if (is(t.disabled)) {
  8998. b = t.disabled;
  8999. t.disabled = -1;
  9000. t.setDisabled(b);
  9001. }
  9002. if (is(t.active)) {
  9003. b = t.active;
  9004. t.active = -1;
  9005. t.setActive(b);
  9006. }
  9007. },
  9008. remove : function() {
  9009. DOM.remove(this.id);
  9010. this.destroy();
  9011. },
  9012. destroy : function() {
  9013. tinymce.dom.Event.clear(this.id);
  9014. }
  9015. });
  9016. })(tinymce);
  9017. tinymce.create('tinymce.ui.Container:tinymce.ui.Control', {
  9018. Container : function(id, s, editor) {
  9019. this.parent(id, s, editor);
  9020. this.controls = [];
  9021. this.lookup = {};
  9022. },
  9023. add : function(c) {
  9024. this.lookup[c.id] = c;
  9025. this.controls.push(c);
  9026. return c;
  9027. },
  9028. get : function(n) {
  9029. return this.lookup[n];
  9030. }
  9031. });
  9032. tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', {
  9033. Separator : function(id, s) {
  9034. this.parent(id, s);
  9035. this.classPrefix = 'mceSeparator';
  9036. this.setDisabled(true);
  9037. },
  9038. renderHTML : function() {
  9039. return tinymce.DOM.createHTML('span', {'class' : this.classPrefix, role : 'separator', 'aria-orientation' : 'vertical', tabindex : '-1'});
  9040. }
  9041. });
  9042. (function(tinymce) {
  9043. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  9044. tinymce.create('tinymce.ui.MenuItem:tinymce.ui.Control', {
  9045. MenuItem : function(id, s) {
  9046. this.parent(id, s);
  9047. this.classPrefix = 'mceMenuItem';
  9048. },
  9049. setSelected : function(s) {
  9050. this.setState('Selected', s);
  9051. this.setAriaProperty('checked', !!s);
  9052. this.selected = s;
  9053. },
  9054. isSelected : function() {
  9055. return this.selected;
  9056. },
  9057. postRender : function() {
  9058. var t = this;
  9059. t.parent();
  9060. // Set pending state
  9061. if (is(t.selected))
  9062. t.setSelected(t.selected);
  9063. }
  9064. });
  9065. })(tinymce);
  9066. (function(tinymce) {
  9067. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  9068. tinymce.create('tinymce.ui.Menu:tinymce.ui.MenuItem', {
  9069. Menu : function(id, s) {
  9070. var t = this;
  9071. t.parent(id, s);
  9072. t.items = {};
  9073. t.collapsed = false;
  9074. t.menuCount = 0;
  9075. t.onAddItem = new tinymce.util.Dispatcher(this);
  9076. },
  9077. expand : function(d) {
  9078. var t = this;
  9079. if (d) {
  9080. walk(t, function(o) {
  9081. if (o.expand)
  9082. o.expand();
  9083. }, 'items', t);
  9084. }
  9085. t.collapsed = false;
  9086. },
  9087. collapse : function(d) {
  9088. var t = this;
  9089. if (d) {
  9090. walk(t, function(o) {
  9091. if (o.collapse)
  9092. o.collapse();
  9093. }, 'items', t);
  9094. }
  9095. t.collapsed = true;
  9096. },
  9097. isCollapsed : function() {
  9098. return this.collapsed;
  9099. },
  9100. add : function(o) {
  9101. if (!o.settings)
  9102. o = new tinymce.ui.MenuItem(o.id || DOM.uniqueId(), o);
  9103. this.onAddItem.dispatch(this, o);
  9104. return this.items[o.id] = o;
  9105. },
  9106. addSeparator : function() {
  9107. return this.add({separator : true});
  9108. },
  9109. addMenu : function(o) {
  9110. if (!o.collapse)
  9111. o = this.createMenu(o);
  9112. this.menuCount++;
  9113. return this.add(o);
  9114. },
  9115. hasMenus : function() {
  9116. return this.menuCount !== 0;
  9117. },
  9118. remove : function(o) {
  9119. delete this.items[o.id];
  9120. },
  9121. removeAll : function() {
  9122. var t = this;
  9123. walk(t, function(o) {
  9124. if (o.removeAll)
  9125. o.removeAll();
  9126. else
  9127. o.remove();
  9128. o.destroy();
  9129. }, 'items', t);
  9130. t.items = {};
  9131. },
  9132. createMenu : function(o) {
  9133. var m = new tinymce.ui.Menu(o.id || DOM.uniqueId(), o);
  9134. m.onAddItem.add(this.onAddItem.dispatch, this.onAddItem);
  9135. return m;
  9136. }
  9137. });
  9138. })(tinymce);
  9139. (function(tinymce) {
  9140. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event, Element = tinymce.dom.Element;
  9141. tinymce.create('tinymce.ui.DropMenu:tinymce.ui.Menu', {
  9142. DropMenu : function(id, s) {
  9143. s = s || {};
  9144. s.container = s.container || DOM.doc.body;
  9145. s.offset_x = s.offset_x || 0;
  9146. s.offset_y = s.offset_y || 0;
  9147. s.vp_offset_x = s.vp_offset_x || 0;
  9148. s.vp_offset_y = s.vp_offset_y || 0;
  9149. if (is(s.icons) && !s.icons)
  9150. s['class'] += ' mceNoIcons';
  9151. this.parent(id, s);
  9152. this.onShowMenu = new tinymce.util.Dispatcher(this);
  9153. this.onHideMenu = new tinymce.util.Dispatcher(this);
  9154. this.classPrefix = 'mceMenu';
  9155. },
  9156. createMenu : function(s) {
  9157. var t = this, cs = t.settings, m;
  9158. s.container = s.container || cs.container;
  9159. s.parent = t;
  9160. s.constrain = s.constrain || cs.constrain;
  9161. s['class'] = s['class'] || cs['class'];
  9162. s.vp_offset_x = s.vp_offset_x || cs.vp_offset_x;
  9163. s.vp_offset_y = s.vp_offset_y || cs.vp_offset_y;
  9164. s.keyboard_focus = cs.keyboard_focus;
  9165. m = new tinymce.ui.DropMenu(s.id || DOM.uniqueId(), s);
  9166. m.onAddItem.add(t.onAddItem.dispatch, t.onAddItem);
  9167. return m;
  9168. },
  9169. focus : function() {
  9170. var t = this;
  9171. if (t.keyboardNav) {
  9172. t.keyboardNav.focus();
  9173. }
  9174. },
  9175. update : function() {
  9176. var t = this, s = t.settings, tb = DOM.get('menu_' + t.id + '_tbl'), co = DOM.get('menu_' + t.id + '_co'), tw, th;
  9177. tw = s.max_width ? Math.min(tb.offsetWidth, s.max_width) : tb.offsetWidth;
  9178. th = s.max_height ? Math.min(tb.offsetHeight, s.max_height) : tb.offsetHeight;
  9179. if (!DOM.boxModel)
  9180. t.element.setStyles({width : tw + 2, height : th + 2});
  9181. else
  9182. t.element.setStyles({width : tw, height : th});
  9183. if (s.max_width)
  9184. DOM.setStyle(co, 'width', tw);
  9185. if (s.max_height) {
  9186. DOM.setStyle(co, 'height', th);
  9187. if (tb.clientHeight < s.max_height)
  9188. DOM.setStyle(co, 'overflow', 'hidden');
  9189. }
  9190. },
  9191. showMenu : function(x, y, px) {
  9192. var t = this, s = t.settings, co, vp = DOM.getViewPort(), w, h, mx, my, ot = 2, dm, tb, cp = t.classPrefix;
  9193. t.collapse(1);
  9194. if (t.isMenuVisible)
  9195. return;
  9196. if (!t.rendered) {
  9197. co = DOM.add(t.settings.container, t.renderNode());
  9198. each(t.items, function(o) {
  9199. o.postRender();
  9200. });
  9201. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  9202. } else
  9203. co = DOM.get('menu_' + t.id);
  9204. // Move layer out of sight unless it's Opera since it scrolls to top of page due to an bug
  9205. if (!tinymce.isOpera)
  9206. DOM.setStyles(co, {left : -0xFFFF , top : -0xFFFF});
  9207. DOM.show(co);
  9208. t.update();
  9209. x += s.offset_x || 0;
  9210. y += s.offset_y || 0;
  9211. vp.w -= 4;
  9212. vp.h -= 4;
  9213. // Move inside viewport if not submenu
  9214. if (s.constrain) {
  9215. w = co.clientWidth - ot;
  9216. h = co.clientHeight - ot;
  9217. mx = vp.x + vp.w;
  9218. my = vp.y + vp.h;
  9219. if ((x + s.vp_offset_x + w) > mx)
  9220. x = px ? px - w : Math.max(0, (mx - s.vp_offset_x) - w);
  9221. if ((y + s.vp_offset_y + h) > my)
  9222. y = Math.max(0, (my - s.vp_offset_y) - h);
  9223. }
  9224. DOM.setStyles(co, {left : x , top : y});
  9225. t.element.update();
  9226. t.isMenuVisible = 1;
  9227. t.mouseClickFunc = Event.add(co, 'click', function(e) {
  9228. var m;
  9229. e = e.target;
  9230. if (e && (e = DOM.getParent(e, 'tr')) && !DOM.hasClass(e, cp + 'ItemSub')) {
  9231. m = t.items[e.id];
  9232. if (m.isDisabled())
  9233. return;
  9234. dm = t;
  9235. while (dm) {
  9236. if (dm.hideMenu)
  9237. dm.hideMenu();
  9238. dm = dm.settings.parent;
  9239. }
  9240. if (m.settings.onclick)
  9241. m.settings.onclick(e);
  9242. return false; // Cancel to fix onbeforeunload problem
  9243. }
  9244. });
  9245. if (t.hasMenus()) {
  9246. t.mouseOverFunc = Event.add(co, 'mouseover', function(e) {
  9247. var m, r, mi;
  9248. e = e.target;
  9249. if (e && (e = DOM.getParent(e, 'tr'))) {
  9250. m = t.items[e.id];
  9251. if (t.lastMenu)
  9252. t.lastMenu.collapse(1);
  9253. if (m.isDisabled())
  9254. return;
  9255. if (e && DOM.hasClass(e, cp + 'ItemSub')) {
  9256. //p = DOM.getPos(s.container);
  9257. r = DOM.getRect(e);
  9258. m.showMenu((r.x + r.w - ot), r.y - ot, r.x);
  9259. t.lastMenu = m;
  9260. DOM.addClass(DOM.get(m.id).firstChild, cp + 'ItemActive');
  9261. }
  9262. }
  9263. });
  9264. }
  9265. Event.add(co, 'keydown', t._keyHandler, t);
  9266. t.onShowMenu.dispatch(t);
  9267. if (s.keyboard_focus) {
  9268. t._setupKeyboardNav();
  9269. }
  9270. },
  9271. hideMenu : function(c) {
  9272. var t = this, co = DOM.get('menu_' + t.id), e;
  9273. if (!t.isMenuVisible)
  9274. return;
  9275. if (t.keyboardNav) t.keyboardNav.destroy();
  9276. Event.remove(co, 'mouseover', t.mouseOverFunc);
  9277. Event.remove(co, 'click', t.mouseClickFunc);
  9278. Event.remove(co, 'keydown', t._keyHandler);
  9279. DOM.hide(co);
  9280. t.isMenuVisible = 0;
  9281. if (!c)
  9282. t.collapse(1);
  9283. if (t.element)
  9284. t.element.hide();
  9285. if (e = DOM.get(t.id))
  9286. DOM.removeClass(e.firstChild, t.classPrefix + 'ItemActive');
  9287. t.onHideMenu.dispatch(t);
  9288. },
  9289. add : function(o) {
  9290. var t = this, co;
  9291. o = t.parent(o);
  9292. if (t.isRendered && (co = DOM.get('menu_' + t.id)))
  9293. t._add(DOM.select('tbody', co)[0], o);
  9294. return o;
  9295. },
  9296. collapse : function(d) {
  9297. this.parent(d);
  9298. this.hideMenu(1);
  9299. },
  9300. remove : function(o) {
  9301. DOM.remove(o.id);
  9302. this.destroy();
  9303. return this.parent(o);
  9304. },
  9305. destroy : function() {
  9306. var t = this, co = DOM.get('menu_' + t.id);
  9307. if (t.keyboardNav) t.keyboardNav.destroy();
  9308. Event.remove(co, 'mouseover', t.mouseOverFunc);
  9309. Event.remove(DOM.select('a', co), 'focus', t.mouseOverFunc);
  9310. Event.remove(co, 'click', t.mouseClickFunc);
  9311. Event.remove(co, 'keydown', t._keyHandler);
  9312. if (t.element)
  9313. t.element.remove();
  9314. DOM.remove(co);
  9315. },
  9316. renderNode : function() {
  9317. var t = this, s = t.settings, n, tb, co, w;
  9318. 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'});
  9319. if (t.settings.parent) {
  9320. DOM.setAttrib(w, 'aria-parent', 'menu_' + t.settings.parent.id);
  9321. }
  9322. co = DOM.add(w, 'div', {role: 'presentation', id : 'menu_' + t.id + '_co', 'class' : t.classPrefix + (s['class'] ? ' ' + s['class'] : '')});
  9323. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  9324. if (s.menu_line)
  9325. DOM.add(co, 'span', {'class' : t.classPrefix + 'Line'});
  9326. // n = DOM.add(co, 'div', {id : 'menu_' + t.id + '_co', 'class' : 'mceMenuContainer'});
  9327. n = DOM.add(co, 'table', {role: 'presentation', id : 'menu_' + t.id + '_tbl', border : 0, cellPadding : 0, cellSpacing : 0});
  9328. tb = DOM.add(n, 'tbody');
  9329. each(t.items, function(o) {
  9330. t._add(tb, o);
  9331. });
  9332. t.rendered = true;
  9333. return w;
  9334. },
  9335. // Internal functions
  9336. _setupKeyboardNav : function(){
  9337. var contextMenu, menuItems, t=this;
  9338. contextMenu = DOM.get('menu_' + t.id);
  9339. menuItems = DOM.select('a[role=option]', 'menu_' + t.id);
  9340. menuItems.splice(0,0,contextMenu);
  9341. t.keyboardNav = new tinymce.ui.KeyboardNavigation({
  9342. root: 'menu_' + t.id,
  9343. items: menuItems,
  9344. onCancel: function() {
  9345. t.hideMenu();
  9346. },
  9347. enableUpDown: true
  9348. });
  9349. contextMenu.focus();
  9350. },
  9351. _keyHandler : function(evt) {
  9352. var t = this, e;
  9353. switch (evt.keyCode) {
  9354. case 37: // Left
  9355. if (t.settings.parent) {
  9356. t.hideMenu();
  9357. t.settings.parent.focus();
  9358. Event.cancel(evt);
  9359. }
  9360. break;
  9361. case 39: // Right
  9362. if (t.mouseOverFunc)
  9363. t.mouseOverFunc(evt);
  9364. break;
  9365. }
  9366. },
  9367. _add : function(tb, o) {
  9368. var n, s = o.settings, a, ro, it, cp = this.classPrefix, ic;
  9369. if (s.separator) {
  9370. ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'ItemSeparator'});
  9371. DOM.add(ro, 'td', {'class' : cp + 'ItemSeparator'});
  9372. if (n = ro.previousSibling)
  9373. DOM.addClass(n, 'mceLast');
  9374. return;
  9375. }
  9376. n = ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'Item ' + cp + 'ItemEnabled'});
  9377. n = it = DOM.add(n, s.titleItem ? 'th' : 'td');
  9378. n = a = DOM.add(n, 'a', {id: o.id + '_aria', role: s.titleItem ? 'presentation' : 'option', href : 'javascript:;', onclick : "return false;", onmousedown : 'return false;'});
  9379. if (s.parent) {
  9380. DOM.setAttrib(a, 'aria-haspopup', 'true');
  9381. DOM.setAttrib(a, 'aria-owns', 'menu_' + o.id);
  9382. }
  9383. DOM.addClass(it, s['class']);
  9384. // n = DOM.add(n, 'span', {'class' : 'item'});
  9385. ic = DOM.add(n, 'span', {'class' : 'mceIcon' + (s.icon ? ' mce_' + s.icon : '')});
  9386. if (s.icon_src)
  9387. DOM.add(ic, 'img', {src : s.icon_src});
  9388. n = DOM.add(n, s.element || 'span', {'class' : 'mceText', title : o.settings.title}, o.settings.title);
  9389. if (o.settings.style) {
  9390. if (typeof o.settings.style == "function")
  9391. o.settings.style = o.settings.style();
  9392. DOM.setAttrib(n, 'style', o.settings.style);
  9393. }
  9394. if (tb.childNodes.length == 1)
  9395. DOM.addClass(ro, 'mceFirst');
  9396. if ((n = ro.previousSibling) && DOM.hasClass(n, cp + 'ItemSeparator'))
  9397. DOM.addClass(ro, 'mceFirst');
  9398. if (o.collapse)
  9399. DOM.addClass(ro, cp + 'ItemSub');
  9400. if (n = ro.previousSibling)
  9401. DOM.removeClass(n, 'mceLast');
  9402. DOM.addClass(ro, 'mceLast');
  9403. }
  9404. });
  9405. })(tinymce);
  9406. (function(tinymce) {
  9407. var DOM = tinymce.DOM;
  9408. tinymce.create('tinymce.ui.Button:tinymce.ui.Control', {
  9409. Button : function(id, s, ed) {
  9410. this.parent(id, s, ed);
  9411. this.classPrefix = 'mceButton';
  9412. },
  9413. renderHTML : function() {
  9414. var cp = this.classPrefix, s = this.settings, h, l;
  9415. l = DOM.encode(s.label || '');
  9416. 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) + '">';
  9417. if (s.image && !(this.editor &&this.editor.forcedHighContrastMode) )
  9418. h += '<span class="mceIcon ' + s['class'] + '"><img class="mceIcon" src="' + s.image + '" alt="' + DOM.encode(s.title) + '" /></span>' + (l ? '<span class="' + cp + 'Label">' + l + '</span>' : '');
  9419. else
  9420. h += '<span class="mceIcon ' + s['class'] + '"></span>' + (l ? '<span class="' + cp + 'Label">' + l + '</span>' : '');
  9421. h += '<span class="mceVoiceLabel mceIconOnly" style="display: none;" id="' + this.id + '_voice">' + s.title + '</span>';
  9422. h += '</a>';
  9423. return h;
  9424. },
  9425. postRender : function() {
  9426. var t = this, s = t.settings, imgBookmark;
  9427. // In IE a large image that occupies the entire editor area will be deselected when a button is clicked, so
  9428. // need to keep the selection in case the selection is lost
  9429. if (tinymce.isIE && t.editor) {
  9430. tinymce.dom.Event.add(t.id, 'mousedown', function(e) {
  9431. var nodeName = t.editor.selection.getNode().nodeName;
  9432. imgBookmark = nodeName === 'IMG' ? t.editor.selection.getBookmark() : null;
  9433. });
  9434. }
  9435. tinymce.dom.Event.add(t.id, 'click', function(e) {
  9436. if (!t.isDisabled()) {
  9437. // restore the selection in case the selection is lost in IE
  9438. if (tinymce.isIE && t.editor && imgBookmark !== null) {
  9439. t.editor.selection.moveToBookmark(imgBookmark);
  9440. }
  9441. return s.onclick.call(s.scope, e);
  9442. }
  9443. });
  9444. tinymce.dom.Event.add(t.id, 'keyup', function(e) {
  9445. if (!t.isDisabled() && e.keyCode==tinymce.VK.SPACEBAR)
  9446. return s.onclick.call(s.scope, e);
  9447. });
  9448. }
  9449. });
  9450. })(tinymce);
  9451. (function(tinymce) {
  9452. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher, undef;
  9453. tinymce.create('tinymce.ui.ListBox:tinymce.ui.Control', {
  9454. ListBox : function(id, s, ed) {
  9455. var t = this;
  9456. t.parent(id, s, ed);
  9457. t.items = [];
  9458. t.onChange = new Dispatcher(t);
  9459. t.onPostRender = new Dispatcher(t);
  9460. t.onAdd = new Dispatcher(t);
  9461. t.onRenderMenu = new tinymce.util.Dispatcher(this);
  9462. t.classPrefix = 'mceListBox';
  9463. t.marked = {};
  9464. },
  9465. select : function(va) {
  9466. var t = this, fv, f;
  9467. t.marked = {};
  9468. if (va == undef)
  9469. return t.selectByIndex(-1);
  9470. // Is string or number make function selector
  9471. if (va && typeof(va)=="function")
  9472. f = va;
  9473. else {
  9474. f = function(v) {
  9475. return v == va;
  9476. };
  9477. }
  9478. // Do we need to do something?
  9479. if (va != t.selectedValue) {
  9480. // Find item
  9481. each(t.items, function(o, i) {
  9482. if (f(o.value)) {
  9483. fv = 1;
  9484. t.selectByIndex(i);
  9485. return false;
  9486. }
  9487. });
  9488. if (!fv)
  9489. t.selectByIndex(-1);
  9490. }
  9491. },
  9492. selectByIndex : function(idx) {
  9493. var t = this, e, o, label;
  9494. t.marked = {};
  9495. if (idx != t.selectedIndex) {
  9496. e = DOM.get(t.id + '_text');
  9497. label = DOM.get(t.id + '_voiceDesc');
  9498. o = t.items[idx];
  9499. if (o) {
  9500. t.selectedValue = o.value;
  9501. t.selectedIndex = idx;
  9502. DOM.setHTML(e, DOM.encode(o.title));
  9503. DOM.setHTML(label, t.settings.title + " - " + o.title);
  9504. DOM.removeClass(e, 'mceTitle');
  9505. DOM.setAttrib(t.id, 'aria-valuenow', o.title);
  9506. } else {
  9507. DOM.setHTML(e, DOM.encode(t.settings.title));
  9508. DOM.setHTML(label, DOM.encode(t.settings.title));
  9509. DOM.addClass(e, 'mceTitle');
  9510. t.selectedValue = t.selectedIndex = null;
  9511. DOM.setAttrib(t.id, 'aria-valuenow', t.settings.title);
  9512. }
  9513. e = 0;
  9514. }
  9515. },
  9516. mark : function(value) {
  9517. this.marked[value] = true;
  9518. },
  9519. add : function(n, v, o) {
  9520. var t = this;
  9521. o = o || {};
  9522. o = tinymce.extend(o, {
  9523. title : n,
  9524. value : v
  9525. });
  9526. t.items.push(o);
  9527. t.onAdd.dispatch(t, o);
  9528. },
  9529. getLength : function() {
  9530. return this.items.length;
  9531. },
  9532. renderHTML : function() {
  9533. var h = '', t = this, s = t.settings, cp = t.classPrefix;
  9534. 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>';
  9535. h += '<td>' + DOM.createHTML('span', {id: t.id + '_voiceDesc', 'class': 'voiceLabel', style:'display:none;'}, t.settings.title);
  9536. 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>';
  9537. 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>';
  9538. h += '</tr></tbody></table></span>';
  9539. return h;
  9540. },
  9541. showMenu : function() {
  9542. var t = this, p2, e = DOM.get(this.id), m;
  9543. if (t.isDisabled() || t.items.length === 0)
  9544. return;
  9545. if (t.menu && t.menu.isMenuVisible)
  9546. return t.hideMenu();
  9547. if (!t.isMenuRendered) {
  9548. t.renderMenu();
  9549. t.isMenuRendered = true;
  9550. }
  9551. p2 = DOM.getPos(e);
  9552. m = t.menu;
  9553. m.settings.offset_x = p2.x;
  9554. m.settings.offset_y = p2.y;
  9555. m.settings.keyboard_focus = !tinymce.isOpera; // Opera is buggy when it comes to auto focus
  9556. // Select in menu
  9557. each(t.items, function(o) {
  9558. if (m.items[o.id]) {
  9559. m.items[o.id].setSelected(0);
  9560. }
  9561. });
  9562. each(t.items, function(o) {
  9563. if (m.items[o.id] && t.marked[o.value]) {
  9564. m.items[o.id].setSelected(1);
  9565. }
  9566. if (o.value === t.selectedValue) {
  9567. m.items[o.id].setSelected(1);
  9568. }
  9569. });
  9570. m.showMenu(0, e.clientHeight);
  9571. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  9572. DOM.addClass(t.id, t.classPrefix + 'Selected');
  9573. //DOM.get(t.id + '_text').focus();
  9574. },
  9575. hideMenu : function(e) {
  9576. var t = this;
  9577. if (t.menu && t.menu.isMenuVisible) {
  9578. DOM.removeClass(t.id, t.classPrefix + 'Selected');
  9579. // Prevent double toogles by canceling the mouse click event to the button
  9580. if (e && e.type == "mousedown" && (e.target.id == t.id + '_text' || e.target.id == t.id + '_open'))
  9581. return;
  9582. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  9583. DOM.removeClass(t.id, t.classPrefix + 'Selected');
  9584. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  9585. t.menu.hideMenu();
  9586. }
  9587. }
  9588. },
  9589. renderMenu : function() {
  9590. var t = this, m;
  9591. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  9592. menu_line : 1,
  9593. 'class' : t.classPrefix + 'Menu mceNoIcons',
  9594. max_width : 250,
  9595. max_height : 150
  9596. });
  9597. m.onHideMenu.add(function() {
  9598. t.hideMenu();
  9599. t.focus();
  9600. });
  9601. m.add({
  9602. title : t.settings.title,
  9603. 'class' : 'mceMenuItemTitle',
  9604. onclick : function() {
  9605. if (t.settings.onselect('') !== false)
  9606. t.select(''); // Must be runned after
  9607. }
  9608. });
  9609. each(t.items, function(o) {
  9610. // No value then treat it as a title
  9611. if (o.value === undef) {
  9612. m.add({
  9613. title : o.title,
  9614. role : "option",
  9615. 'class' : 'mceMenuItemTitle',
  9616. onclick : function() {
  9617. if (t.settings.onselect('') !== false)
  9618. t.select(''); // Must be runned after
  9619. }
  9620. });
  9621. } else {
  9622. o.id = DOM.uniqueId();
  9623. o.role= "option";
  9624. o.onclick = function() {
  9625. if (t.settings.onselect(o.value) !== false)
  9626. t.select(o.value); // Must be runned after
  9627. };
  9628. m.add(o);
  9629. }
  9630. });
  9631. t.onRenderMenu.dispatch(t, m);
  9632. t.menu = m;
  9633. },
  9634. postRender : function() {
  9635. var t = this, cp = t.classPrefix;
  9636. Event.add(t.id, 'click', t.showMenu, t);
  9637. Event.add(t.id, 'keydown', function(evt) {
  9638. if (evt.keyCode == 32) { // Space
  9639. t.showMenu(evt);
  9640. Event.cancel(evt);
  9641. }
  9642. });
  9643. Event.add(t.id, 'focus', function() {
  9644. if (!t._focused) {
  9645. t.keyDownHandler = Event.add(t.id, 'keydown', function(e) {
  9646. if (e.keyCode == 40) {
  9647. t.showMenu();
  9648. Event.cancel(e);
  9649. }
  9650. });
  9651. t.keyPressHandler = Event.add(t.id, 'keypress', function(e) {
  9652. var v;
  9653. if (e.keyCode == 13) {
  9654. // Fake select on enter
  9655. v = t.selectedValue;
  9656. t.selectedValue = null; // Needs to be null to fake change
  9657. Event.cancel(e);
  9658. t.settings.onselect(v);
  9659. }
  9660. });
  9661. }
  9662. t._focused = 1;
  9663. });
  9664. Event.add(t.id, 'blur', function() {
  9665. Event.remove(t.id, 'keydown', t.keyDownHandler);
  9666. Event.remove(t.id, 'keypress', t.keyPressHandler);
  9667. t._focused = 0;
  9668. });
  9669. // Old IE doesn't have hover on all elements
  9670. if (tinymce.isIE6 || !DOM.boxModel) {
  9671. Event.add(t.id, 'mouseover', function() {
  9672. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  9673. DOM.addClass(t.id, cp + 'Hover');
  9674. });
  9675. Event.add(t.id, 'mouseout', function() {
  9676. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  9677. DOM.removeClass(t.id, cp + 'Hover');
  9678. });
  9679. }
  9680. t.onPostRender.dispatch(t, DOM.get(t.id));
  9681. },
  9682. destroy : function() {
  9683. this.parent();
  9684. Event.clear(this.id + '_text');
  9685. Event.clear(this.id + '_open');
  9686. }
  9687. });
  9688. })(tinymce);
  9689. (function(tinymce) {
  9690. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher, undef;
  9691. tinymce.create('tinymce.ui.NativeListBox:tinymce.ui.ListBox', {
  9692. NativeListBox : function(id, s) {
  9693. this.parent(id, s);
  9694. this.classPrefix = 'mceNativeListBox';
  9695. },
  9696. setDisabled : function(s) {
  9697. DOM.get(this.id).disabled = s;
  9698. this.setAriaProperty('disabled', s);
  9699. },
  9700. isDisabled : function() {
  9701. return DOM.get(this.id).disabled;
  9702. },
  9703. select : function(va) {
  9704. var t = this, fv, f;
  9705. if (va == undef)
  9706. return t.selectByIndex(-1);
  9707. // Is string or number make function selector
  9708. if (va && typeof(va)=="function")
  9709. f = va;
  9710. else {
  9711. f = function(v) {
  9712. return v == va;
  9713. };
  9714. }
  9715. // Do we need to do something?
  9716. if (va != t.selectedValue) {
  9717. // Find item
  9718. each(t.items, function(o, i) {
  9719. if (f(o.value)) {
  9720. fv = 1;
  9721. t.selectByIndex(i);
  9722. return false;
  9723. }
  9724. });
  9725. if (!fv)
  9726. t.selectByIndex(-1);
  9727. }
  9728. },
  9729. selectByIndex : function(idx) {
  9730. DOM.get(this.id).selectedIndex = idx + 1;
  9731. this.selectedValue = this.items[idx] ? this.items[idx].value : null;
  9732. },
  9733. add : function(n, v, a) {
  9734. var o, t = this;
  9735. a = a || {};
  9736. a.value = v;
  9737. if (t.isRendered())
  9738. DOM.add(DOM.get(this.id), 'option', a, n);
  9739. o = {
  9740. title : n,
  9741. value : v,
  9742. attribs : a
  9743. };
  9744. t.items.push(o);
  9745. t.onAdd.dispatch(t, o);
  9746. },
  9747. getLength : function() {
  9748. return this.items.length;
  9749. },
  9750. renderHTML : function() {
  9751. var h, t = this;
  9752. h = DOM.createHTML('option', {value : ''}, '-- ' + t.settings.title + ' --');
  9753. each(t.items, function(it) {
  9754. h += DOM.createHTML('option', {value : it.value}, it.title);
  9755. });
  9756. h = DOM.createHTML('select', {id : t.id, 'class' : 'mceNativeListBox', 'aria-labelledby': t.id + '_aria'}, h);
  9757. h += DOM.createHTML('span', {id : t.id + '_aria', 'style': 'display: none'}, t.settings.title);
  9758. return h;
  9759. },
  9760. postRender : function() {
  9761. var t = this, ch, changeListenerAdded = true;
  9762. t.rendered = true;
  9763. function onChange(e) {
  9764. var v = t.items[e.target.selectedIndex - 1];
  9765. if (v && (v = v.value)) {
  9766. t.onChange.dispatch(t, v);
  9767. if (t.settings.onselect)
  9768. t.settings.onselect(v);
  9769. }
  9770. };
  9771. Event.add(t.id, 'change', onChange);
  9772. // Accessibility keyhandler
  9773. Event.add(t.id, 'keydown', function(e) {
  9774. var bf;
  9775. Event.remove(t.id, 'change', ch);
  9776. changeListenerAdded = false;
  9777. bf = Event.add(t.id, 'blur', function() {
  9778. if (changeListenerAdded) return;
  9779. changeListenerAdded = true;
  9780. Event.add(t.id, 'change', onChange);
  9781. Event.remove(t.id, 'blur', bf);
  9782. });
  9783. //prevent default left and right keys on chrome - so that the keyboard navigation is used.
  9784. if (tinymce.isWebKit && (e.keyCode==37 ||e.keyCode==39)) {
  9785. return Event.prevent(e);
  9786. }
  9787. if (e.keyCode == 13 || e.keyCode == 32) {
  9788. onChange(e);
  9789. return Event.cancel(e);
  9790. }
  9791. });
  9792. t.onPostRender.dispatch(t, DOM.get(t.id));
  9793. }
  9794. });
  9795. })(tinymce);
  9796. (function(tinymce) {
  9797. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  9798. tinymce.create('tinymce.ui.MenuButton:tinymce.ui.Button', {
  9799. MenuButton : function(id, s, ed) {
  9800. this.parent(id, s, ed);
  9801. this.onRenderMenu = new tinymce.util.Dispatcher(this);
  9802. s.menu_container = s.menu_container || DOM.doc.body;
  9803. },
  9804. showMenu : function() {
  9805. var t = this, p1, p2, e = DOM.get(t.id), m;
  9806. if (t.isDisabled())
  9807. return;
  9808. if (!t.isMenuRendered) {
  9809. t.renderMenu();
  9810. t.isMenuRendered = true;
  9811. }
  9812. if (t.isMenuVisible)
  9813. return t.hideMenu();
  9814. p1 = DOM.getPos(t.settings.menu_container);
  9815. p2 = DOM.getPos(e);
  9816. m = t.menu;
  9817. m.settings.offset_x = p2.x;
  9818. m.settings.offset_y = p2.y;
  9819. m.settings.vp_offset_x = p2.x;
  9820. m.settings.vp_offset_y = p2.y;
  9821. m.settings.keyboard_focus = t._focused;
  9822. m.showMenu(0, e.firstChild.clientHeight);
  9823. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  9824. t.setState('Selected', 1);
  9825. t.isMenuVisible = 1;
  9826. },
  9827. renderMenu : function() {
  9828. var t = this, m;
  9829. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  9830. menu_line : 1,
  9831. 'class' : this.classPrefix + 'Menu',
  9832. icons : t.settings.icons
  9833. });
  9834. m.onHideMenu.add(function() {
  9835. t.hideMenu();
  9836. t.focus();
  9837. });
  9838. t.onRenderMenu.dispatch(t, m);
  9839. t.menu = m;
  9840. },
  9841. hideMenu : function(e) {
  9842. var t = this;
  9843. // Prevent double toogles by canceling the mouse click event to the button
  9844. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id || e.id === t.id + '_open';}))
  9845. return;
  9846. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  9847. t.setState('Selected', 0);
  9848. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  9849. if (t.menu)
  9850. t.menu.hideMenu();
  9851. }
  9852. t.isMenuVisible = 0;
  9853. },
  9854. postRender : function() {
  9855. var t = this, s = t.settings;
  9856. Event.add(t.id, 'click', function() {
  9857. if (!t.isDisabled()) {
  9858. if (s.onclick)
  9859. s.onclick(t.value);
  9860. t.showMenu();
  9861. }
  9862. });
  9863. }
  9864. });
  9865. })(tinymce);
  9866. (function(tinymce) {
  9867. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  9868. tinymce.create('tinymce.ui.SplitButton:tinymce.ui.MenuButton', {
  9869. SplitButton : function(id, s, ed) {
  9870. this.parent(id, s, ed);
  9871. this.classPrefix = 'mceSplitButton';
  9872. },
  9873. renderHTML : function() {
  9874. var h, t = this, s = t.settings, h1;
  9875. h = '<tbody><tr>';
  9876. if (s.image)
  9877. h1 = DOM.createHTML('img ', {src : s.image, role: 'presentation', 'class' : 'mceAction ' + s['class']});
  9878. else
  9879. h1 = DOM.createHTML('span', {'class' : 'mceAction ' + s['class']}, '');
  9880. h1 += DOM.createHTML('span', {'class': 'mceVoiceLabel mceIconOnly', id: t.id + '_voice', style: 'display:none;'}, s.title);
  9881. 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>';
  9882. h1 = DOM.createHTML('span', {'class' : 'mceOpen ' + s['class']}, '<span style="display:none;" class="mceIconOnly" aria-hidden="true">\u25BC</span>');
  9883. 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>';
  9884. h += '</tr></tbody>';
  9885. h = DOM.createHTML('table', { role: 'presentation', 'class' : 'mceSplitButton mceSplitButtonEnabled ' + s['class'], cellpadding : '0', cellspacing : '0', title : s.title}, h);
  9886. return DOM.createHTML('div', {id : t.id, role: 'button', tabindex: '0', 'aria-labelledby': t.id + '_voice', 'aria-haspopup': 'true'}, h);
  9887. },
  9888. postRender : function() {
  9889. var t = this, s = t.settings, activate;
  9890. if (s.onclick) {
  9891. activate = function(evt) {
  9892. if (!t.isDisabled()) {
  9893. s.onclick(t.value);
  9894. Event.cancel(evt);
  9895. }
  9896. };
  9897. Event.add(t.id + '_action', 'click', activate);
  9898. Event.add(t.id, ['click', 'keydown'], function(evt) {
  9899. var DOM_VK_SPACE = 32, DOM_VK_ENTER = 14, DOM_VK_RETURN = 13, DOM_VK_UP = 38, DOM_VK_DOWN = 40;
  9900. if ((evt.keyCode === 32 || evt.keyCode === 13 || evt.keyCode === 14) && !evt.altKey && !evt.ctrlKey && !evt.metaKey) {
  9901. activate();
  9902. Event.cancel(evt);
  9903. } else if (evt.type === 'click' || evt.keyCode === DOM_VK_DOWN) {
  9904. t.showMenu();
  9905. Event.cancel(evt);
  9906. }
  9907. });
  9908. }
  9909. Event.add(t.id + '_open', 'click', function (evt) {
  9910. t.showMenu();
  9911. Event.cancel(evt);
  9912. });
  9913. Event.add([t.id, t.id + '_open'], 'focus', function() {t._focused = 1;});
  9914. Event.add([t.id, t.id + '_open'], 'blur', function() {t._focused = 0;});
  9915. // Old IE doesn't have hover on all elements
  9916. if (tinymce.isIE6 || !DOM.boxModel) {
  9917. Event.add(t.id, 'mouseover', function() {
  9918. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  9919. DOM.addClass(t.id, 'mceSplitButtonHover');
  9920. });
  9921. Event.add(t.id, 'mouseout', function() {
  9922. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  9923. DOM.removeClass(t.id, 'mceSplitButtonHover');
  9924. });
  9925. }
  9926. },
  9927. destroy : function() {
  9928. this.parent();
  9929. Event.clear(this.id + '_action');
  9930. Event.clear(this.id + '_open');
  9931. Event.clear(this.id);
  9932. }
  9933. });
  9934. })(tinymce);
  9935. (function(tinymce) {
  9936. var DOM = tinymce.DOM, Event = tinymce.dom.Event, is = tinymce.is, each = tinymce.each;
  9937. tinymce.create('tinymce.ui.ColorSplitButton:tinymce.ui.SplitButton', {
  9938. ColorSplitButton : function(id, s, ed) {
  9939. var t = this;
  9940. t.parent(id, s, ed);
  9941. t.settings = s = tinymce.extend({
  9942. 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',
  9943. grid_width : 8,
  9944. default_color : '#888888'
  9945. }, t.settings);
  9946. t.onShowMenu = new tinymce.util.Dispatcher(t);
  9947. t.onHideMenu = new tinymce.util.Dispatcher(t);
  9948. t.value = s.default_color;
  9949. },
  9950. showMenu : function() {
  9951. var t = this, r, p, e, p2;
  9952. if (t.isDisabled())
  9953. return;
  9954. if (!t.isMenuRendered) {
  9955. t.renderMenu();
  9956. t.isMenuRendered = true;
  9957. }
  9958. if (t.isMenuVisible)
  9959. return t.hideMenu();
  9960. e = DOM.get(t.id);
  9961. DOM.show(t.id + '_menu');
  9962. DOM.addClass(e, 'mceSplitButtonSelected');
  9963. p2 = DOM.getPos(e);
  9964. DOM.setStyles(t.id + '_menu', {
  9965. left : p2.x,
  9966. top : p2.y + e.firstChild.clientHeight,
  9967. zIndex : 200000
  9968. });
  9969. e = 0;
  9970. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  9971. t.onShowMenu.dispatch(t);
  9972. if (t._focused) {
  9973. t._keyHandler = Event.add(t.id + '_menu', 'keydown', function(e) {
  9974. if (e.keyCode == 27)
  9975. t.hideMenu();
  9976. });
  9977. DOM.select('a', t.id + '_menu')[0].focus(); // Select first link
  9978. }
  9979. t.keyboardNav = new tinymce.ui.KeyboardNavigation({
  9980. root: t.id + '_menu',
  9981. items: DOM.select('a', t.id + '_menu'),
  9982. onCancel: function() {
  9983. t.hideMenu();
  9984. t.focus();
  9985. }
  9986. });
  9987. t.keyboardNav.focus();
  9988. t.isMenuVisible = 1;
  9989. },
  9990. hideMenu : function(e) {
  9991. var t = this;
  9992. if (t.isMenuVisible) {
  9993. // Prevent double toogles by canceling the mouse click event to the button
  9994. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id + '_open';}))
  9995. return;
  9996. if (!e || !DOM.getParent(e.target, '.mceSplitButtonMenu')) {
  9997. DOM.removeClass(t.id, 'mceSplitButtonSelected');
  9998. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  9999. Event.remove(t.id + '_menu', 'keydown', t._keyHandler);
  10000. DOM.hide(t.id + '_menu');
  10001. }
  10002. t.isMenuVisible = 0;
  10003. t.onHideMenu.dispatch();
  10004. t.keyboardNav.destroy();
  10005. }
  10006. },
  10007. renderMenu : function() {
  10008. var t = this, m, i = 0, s = t.settings, n, tb, tr, w, context;
  10009. 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;'});
  10010. m = DOM.add(w, 'div', {'class' : s['class'] + ' mceSplitButtonMenu'});
  10011. DOM.add(m, 'span', {'class' : 'mceMenuLine'});
  10012. n = DOM.add(m, 'table', {role: 'presentation', 'class' : 'mceColorSplitMenu'});
  10013. tb = DOM.add(n, 'tbody');
  10014. // Generate color grid
  10015. i = 0;
  10016. each(is(s.colors, 'array') ? s.colors : s.colors.split(','), function(c) {
  10017. c = c.replace(/^#/, '');
  10018. if (!i--) {
  10019. tr = DOM.add(tb, 'tr');
  10020. i = s.grid_width - 1;
  10021. }
  10022. n = DOM.add(tr, 'td');
  10023. var settings = {
  10024. href : 'javascript:;',
  10025. style : {
  10026. backgroundColor : '#' + c
  10027. },
  10028. 'title': t.editor.getLang('colors.' + c, c),
  10029. 'data-mce-color' : '#' + c
  10030. };
  10031. // adding a proper ARIA role = button causes JAWS to read things incorrectly on IE.
  10032. if (!tinymce.isIE ) {
  10033. settings.role = 'option';
  10034. }
  10035. n = DOM.add(n, 'a', settings);
  10036. if (t.editor.forcedHighContrastMode) {
  10037. n = DOM.add(n, 'canvas', { width: 16, height: 16, 'aria-hidden': 'true' });
  10038. if (n.getContext && (context = n.getContext("2d"))) {
  10039. context.fillStyle = '#' + c;
  10040. context.fillRect(0, 0, 16, 16);
  10041. } else {
  10042. // No point leaving a canvas element around if it's not supported for drawing on anyway.
  10043. DOM.remove(n);
  10044. }
  10045. }
  10046. });
  10047. if (s.more_colors_func) {
  10048. n = DOM.add(tb, 'tr');
  10049. n = DOM.add(n, 'td', {colspan : s.grid_width, 'class' : 'mceMoreColors'});
  10050. n = DOM.add(n, 'a', {role: 'option', id : t.id + '_more', href : 'javascript:;', onclick : 'return false;', 'class' : 'mceMoreColors'}, s.more_colors_title);
  10051. Event.add(n, 'click', function(e) {
  10052. s.more_colors_func.call(s.more_colors_scope || this);
  10053. return Event.cancel(e); // Cancel to fix onbeforeunload problem
  10054. });
  10055. }
  10056. DOM.addClass(m, 'mceColorSplitMenu');
  10057. // Prevent IE from scrolling and hindering click to occur #4019
  10058. Event.add(t.id + '_menu', 'mousedown', function(e) {return Event.cancel(e);});
  10059. Event.add(t.id + '_menu', 'click', function(e) {
  10060. var c;
  10061. e = DOM.getParent(e.target, 'a', tb);
  10062. if (e && e.nodeName.toLowerCase() == 'a' && (c = e.getAttribute('data-mce-color')))
  10063. t.setColor(c);
  10064. return false; // Prevent IE auto save warning
  10065. });
  10066. return w;
  10067. },
  10068. setColor : function(c) {
  10069. this.displayColor(c);
  10070. this.hideMenu();
  10071. this.settings.onselect(c);
  10072. },
  10073. displayColor : function(c) {
  10074. var t = this;
  10075. DOM.setStyle(t.id + '_preview', 'backgroundColor', c);
  10076. t.value = c;
  10077. },
  10078. postRender : function() {
  10079. var t = this, id = t.id;
  10080. t.parent();
  10081. DOM.add(id + '_action', 'div', {id : id + '_preview', 'class' : 'mceColorPreview'});
  10082. DOM.setStyle(t.id + '_preview', 'backgroundColor', t.value);
  10083. },
  10084. destroy : function() {
  10085. var self = this;
  10086. self.parent();
  10087. Event.clear(self.id + '_menu');
  10088. Event.clear(self.id + '_more');
  10089. DOM.remove(self.id + '_menu');
  10090. if (self.keyboardNav) {
  10091. self.keyboardNav.destroy();
  10092. }
  10093. }
  10094. });
  10095. })(tinymce);
  10096. (function(tinymce) {
  10097. // Shorten class names
  10098. var dom = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event;
  10099. tinymce.create('tinymce.ui.ToolbarGroup:tinymce.ui.Container', {
  10100. renderHTML : function() {
  10101. var t = this, h = [], controls = t.controls, each = tinymce.each, settings = t.settings;
  10102. h.push('<div id="' + t.id + '" role="group" aria-labelledby="' + t.id + '_voice">');
  10103. //TODO: ACC test this out - adding a role = application for getting the landmarks working well.
  10104. h.push("<span role='application'>");
  10105. h.push('<span id="' + t.id + '_voice" class="mceVoiceLabel" style="display:none;">' + dom.encode(settings.name) + '</span>');
  10106. each(controls, function(toolbar) {
  10107. h.push(toolbar.renderHTML());
  10108. });
  10109. h.push("</span>");
  10110. h.push('</div>');
  10111. return h.join('');
  10112. },
  10113. focus : function() {
  10114. var t = this;
  10115. dom.get(t.id).focus();
  10116. },
  10117. postRender : function() {
  10118. var t = this, items = [];
  10119. each(t.controls, function(toolbar) {
  10120. each (toolbar.controls, function(control) {
  10121. if (control.id) {
  10122. items.push(control);
  10123. }
  10124. });
  10125. });
  10126. t.keyNav = new tinymce.ui.KeyboardNavigation({
  10127. root: t.id,
  10128. items: items,
  10129. onCancel: function() {
  10130. //Move focus if webkit so that navigation back will read the item.
  10131. if (tinymce.isWebKit) {
  10132. dom.get(t.editor.id+"_ifr").focus();
  10133. }
  10134. t.editor.focus();
  10135. },
  10136. excludeFromTabOrder: !t.settings.tab_focus_toolbar
  10137. });
  10138. },
  10139. destroy : function() {
  10140. var self = this;
  10141. self.parent();
  10142. self.keyNav.destroy();
  10143. Event.clear(self.id);
  10144. }
  10145. });
  10146. })(tinymce);
  10147. (function(tinymce) {
  10148. // Shorten class names
  10149. var dom = tinymce.DOM, each = tinymce.each;
  10150. tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', {
  10151. renderHTML : function() {
  10152. var t = this, h = '', c, co, s = t.settings, i, pr, nx, cl;
  10153. cl = t.controls;
  10154. for (i=0; i<cl.length; i++) {
  10155. // Get current control, prev control, next control and if the control is a list box or not
  10156. co = cl[i];
  10157. pr = cl[i - 1];
  10158. nx = cl[i + 1];
  10159. // Add toolbar start
  10160. if (i === 0) {
  10161. c = 'mceToolbarStart';
  10162. if (co.Button)
  10163. c += ' mceToolbarStartButton';
  10164. else if (co.SplitButton)
  10165. c += ' mceToolbarStartSplitButton';
  10166. else if (co.ListBox)
  10167. c += ' mceToolbarStartListBox';
  10168. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  10169. }
  10170. // Add toolbar end before list box and after the previous button
  10171. // This is to fix the o2k7 editor skins
  10172. if (pr && co.ListBox) {
  10173. if (pr.Button || pr.SplitButton)
  10174. h += dom.createHTML('td', {'class' : 'mceToolbarEnd'}, dom.createHTML('span', null, '<!-- IE -->'));
  10175. }
  10176. // Render control HTML
  10177. // IE 8 quick fix, needed to propertly generate a hit area for anchors
  10178. if (dom.stdMode)
  10179. h += '<td style="position: relative">' + co.renderHTML() + '</td>';
  10180. else
  10181. h += '<td>' + co.renderHTML() + '</td>';
  10182. // Add toolbar start after list box and before the next button
  10183. // This is to fix the o2k7 editor skins
  10184. if (nx && co.ListBox) {
  10185. if (nx.Button || nx.SplitButton)
  10186. h += dom.createHTML('td', {'class' : 'mceToolbarStart'}, dom.createHTML('span', null, '<!-- IE -->'));
  10187. }
  10188. }
  10189. c = 'mceToolbarEnd';
  10190. if (co.Button)
  10191. c += ' mceToolbarEndButton';
  10192. else if (co.SplitButton)
  10193. c += ' mceToolbarEndSplitButton';
  10194. else if (co.ListBox)
  10195. c += ' mceToolbarEndListBox';
  10196. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  10197. 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>');
  10198. }
  10199. });
  10200. })(tinymce);
  10201. (function(tinymce) {
  10202. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each;
  10203. tinymce.create('tinymce.AddOnManager', {
  10204. AddOnManager : function() {
  10205. var self = this;
  10206. self.items = [];
  10207. self.urls = {};
  10208. self.lookup = {};
  10209. self.onAdd = new Dispatcher(self);
  10210. },
  10211. get : function(n) {
  10212. if (this.lookup[n]) {
  10213. return this.lookup[n].instance;
  10214. } else {
  10215. return undefined;
  10216. }
  10217. },
  10218. dependencies : function(n) {
  10219. var result;
  10220. if (this.lookup[n]) {
  10221. result = this.lookup[n].dependencies;
  10222. }
  10223. return result || [];
  10224. },
  10225. requireLangPack : function(n) {
  10226. var s = tinymce.settings;
  10227. if (s && s.language && s.language_load !== false)
  10228. tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js');
  10229. },
  10230. add : function(id, o, dependencies) {
  10231. this.items.push(o);
  10232. this.lookup[id] = {instance:o, dependencies:dependencies};
  10233. this.onAdd.dispatch(this, id, o);
  10234. return o;
  10235. },
  10236. createUrl: function(baseUrl, dep) {
  10237. if (typeof dep === "object") {
  10238. return dep
  10239. } else {
  10240. return {prefix: baseUrl.prefix, resource: dep, suffix: baseUrl.suffix};
  10241. }
  10242. },
  10243. addComponents: function(pluginName, scripts) {
  10244. var pluginUrl = this.urls[pluginName];
  10245. tinymce.each(scripts, function(script){
  10246. tinymce.ScriptLoader.add(pluginUrl+"/"+script);
  10247. });
  10248. },
  10249. load : function(n, u, cb, s) {
  10250. var t = this, url = u;
  10251. function loadDependencies() {
  10252. var dependencies = t.dependencies(n);
  10253. tinymce.each(dependencies, function(dep) {
  10254. var newUrl = t.createUrl(u, dep);
  10255. t.load(newUrl.resource, newUrl, undefined, undefined);
  10256. });
  10257. if (cb) {
  10258. if (s) {
  10259. cb.call(s);
  10260. } else {
  10261. cb.call(tinymce.ScriptLoader);
  10262. }
  10263. }
  10264. }
  10265. if (t.urls[n])
  10266. return;
  10267. if (typeof u === "object")
  10268. url = u.prefix + u.resource + u.suffix;
  10269. if (url.indexOf('/') !== 0 && url.indexOf('://') == -1)
  10270. url = tinymce.baseURL + '/' + url;
  10271. t.urls[n] = url.substring(0, url.lastIndexOf('/'));
  10272. if (t.lookup[n]) {
  10273. loadDependencies();
  10274. } else {
  10275. tinymce.ScriptLoader.add(url, loadDependencies, s);
  10276. }
  10277. }
  10278. });
  10279. // Create plugin and theme managers
  10280. tinymce.PluginManager = new tinymce.AddOnManager();
  10281. tinymce.ThemeManager = new tinymce.AddOnManager();
  10282. }(tinymce));
  10283. (function(tinymce) {
  10284. // Shorten names
  10285. var each = tinymce.each, extend = tinymce.extend,
  10286. DOM = tinymce.DOM, Event = tinymce.dom.Event,
  10287. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  10288. explode = tinymce.explode,
  10289. Dispatcher = tinymce.util.Dispatcher, undef, instanceCounter = 0;
  10290. // Setup some URLs where the editor API is located and where the document is
  10291. tinymce.documentBaseURL = window.location.href.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '');
  10292. if (!/[\/\\]$/.test(tinymce.documentBaseURL))
  10293. tinymce.documentBaseURL += '/';
  10294. tinymce.baseURL = new tinymce.util.URI(tinymce.documentBaseURL).toAbsolute(tinymce.baseURL);
  10295. tinymce.baseURI = new tinymce.util.URI(tinymce.baseURL);
  10296. // Add before unload listener
  10297. // This was required since IE was leaking memory if you added and removed beforeunload listeners
  10298. // with attachEvent/detatchEvent so this only adds one listener and instances can the attach to the onBeforeUnload event
  10299. tinymce.onBeforeUnload = new Dispatcher(tinymce);
  10300. // Must be on window or IE will leak if the editor is placed in frame or iframe
  10301. Event.add(window, 'beforeunload', function(e) {
  10302. tinymce.onBeforeUnload.dispatch(tinymce, e);
  10303. });
  10304. tinymce.onAddEditor = new Dispatcher(tinymce);
  10305. tinymce.onRemoveEditor = new Dispatcher(tinymce);
  10306. tinymce.EditorManager = extend(tinymce, {
  10307. editors : [],
  10308. i18n : {},
  10309. activeEditor : null,
  10310. init : function(s) {
  10311. var t = this, pl, sl = tinymce.ScriptLoader, e, el = [], ed;
  10312. function createId(elm) {
  10313. var id = elm.id;
  10314. // Use element id, or unique name or generate a unique id
  10315. if (!id) {
  10316. id = elm.name;
  10317. if (id && !DOM.get(id)) {
  10318. id = elm.name;
  10319. } else {
  10320. // Generate unique name
  10321. id = DOM.uniqueId();
  10322. }
  10323. elm.setAttribute('id', id);
  10324. }
  10325. return id;
  10326. };
  10327. function execCallback(se, n, s) {
  10328. var f = se[n];
  10329. if (!f)
  10330. return;
  10331. if (tinymce.is(f, 'string')) {
  10332. s = f.replace(/\.\w+$/, '');
  10333. s = s ? tinymce.resolve(s) : 0;
  10334. f = tinymce.resolve(f);
  10335. }
  10336. return f.apply(s || this, Array.prototype.slice.call(arguments, 2));
  10337. };
  10338. function hasClass(n, c) {
  10339. return c.constructor === RegExp ? c.test(n.className) : DOM.hasClass(n, c);
  10340. };
  10341. t.settings = s;
  10342. // Legacy call
  10343. Event.bind(window, 'ready', function() {
  10344. var l, co;
  10345. execCallback(s, 'onpageload');
  10346. switch (s.mode) {
  10347. case "exact":
  10348. l = s.elements || '';
  10349. if(l.length > 0) {
  10350. each(explode(l), function(v) {
  10351. if (DOM.get(v)) {
  10352. ed = new tinymce.Editor(v, s);
  10353. el.push(ed);
  10354. ed.render(1);
  10355. } else {
  10356. each(document.forms, function(f) {
  10357. each(f.elements, function(e) {
  10358. if (e.name === v) {
  10359. v = 'mce_editor_' + instanceCounter++;
  10360. DOM.setAttrib(e, 'id', v);
  10361. ed = new tinymce.Editor(v, s);
  10362. el.push(ed);
  10363. ed.render(1);
  10364. }
  10365. });
  10366. });
  10367. }
  10368. });
  10369. }
  10370. break;
  10371. case "textareas":
  10372. case "specific_textareas":
  10373. each(DOM.select('textarea'), function(elm) {
  10374. if (s.editor_deselector && hasClass(elm, s.editor_deselector))
  10375. return;
  10376. if (!s.editor_selector || hasClass(elm, s.editor_selector)) {
  10377. ed = new tinymce.Editor(createId(elm), s);
  10378. el.push(ed);
  10379. ed.render(1);
  10380. }
  10381. });
  10382. break;
  10383. default:
  10384. if (s.types) {
  10385. // Process type specific selector
  10386. each(s.types, function(type) {
  10387. each(DOM.select(type.selector), function(elm) {
  10388. var editor = new tinymce.Editor(createId(elm), tinymce.extend({}, s, type));
  10389. el.push(editor);
  10390. editor.render(1);
  10391. });
  10392. });
  10393. } else if (s.selector) {
  10394. // Process global selector
  10395. each(DOM.select(s.selector), function(elm) {
  10396. var editor = new tinymce.Editor(createId(elm), s);
  10397. el.push(editor);
  10398. editor.render(1);
  10399. });
  10400. }
  10401. }
  10402. // Call onInit when all editors are initialized
  10403. if (s.oninit) {
  10404. l = co = 0;
  10405. each(el, function(ed) {
  10406. co++;
  10407. if (!ed.initialized) {
  10408. // Wait for it
  10409. ed.onInit.add(function() {
  10410. l++;
  10411. // All done
  10412. if (l == co)
  10413. execCallback(s, 'oninit');
  10414. });
  10415. } else
  10416. l++;
  10417. // All done
  10418. if (l == co)
  10419. execCallback(s, 'oninit');
  10420. });
  10421. }
  10422. });
  10423. },
  10424. get : function(id) {
  10425. if (id === undef)
  10426. return this.editors;
  10427. if (!this.editors.hasOwnProperty(id))
  10428. return undef;
  10429. return this.editors[id];
  10430. },
  10431. getInstanceById : function(id) {
  10432. return this.get(id);
  10433. },
  10434. add : function(editor) {
  10435. var self = this, editors = self.editors;
  10436. // Add named and index editor instance
  10437. editors[editor.id] = editor;
  10438. editors.push(editor);
  10439. self._setActive(editor);
  10440. self.onAddEditor.dispatch(self, editor);
  10441. return editor;
  10442. },
  10443. remove : function(editor) {
  10444. var t = this, i, editors = t.editors;
  10445. // Not in the collection
  10446. if (!editors[editor.id])
  10447. return null;
  10448. delete editors[editor.id];
  10449. for (i = 0; i < editors.length; i++) {
  10450. if (editors[i] == editor) {
  10451. editors.splice(i, 1);
  10452. break;
  10453. }
  10454. }
  10455. // Select another editor since the active one was removed
  10456. if (t.activeEditor == editor)
  10457. t._setActive(editors[0]);
  10458. editor.destroy();
  10459. t.onRemoveEditor.dispatch(t, editor);
  10460. return editor;
  10461. },
  10462. execCommand : function(c, u, v) {
  10463. var t = this, ed = t.get(v), w;
  10464. function clr() {
  10465. ed.destroy();
  10466. w.detachEvent('onunload', clr);
  10467. w = w.tinyMCE = w.tinymce = null; // IE leak
  10468. };
  10469. // Manager commands
  10470. switch (c) {
  10471. case "mceFocus":
  10472. ed.focus();
  10473. return true;
  10474. case "mceAddEditor":
  10475. case "mceAddControl":
  10476. if (!t.get(v))
  10477. new tinymce.Editor(v, t.settings).render();
  10478. return true;
  10479. case "mceAddFrameControl":
  10480. w = v.window;
  10481. // Add tinyMCE global instance and tinymce namespace to specified window
  10482. w.tinyMCE = tinyMCE;
  10483. w.tinymce = tinymce;
  10484. tinymce.DOM.doc = w.document;
  10485. tinymce.DOM.win = w;
  10486. ed = new tinymce.Editor(v.element_id, v);
  10487. ed.render();
  10488. // Fix IE memory leaks
  10489. if (tinymce.isIE) {
  10490. w.attachEvent('onunload', clr);
  10491. }
  10492. v.page_window = null;
  10493. return true;
  10494. case "mceRemoveEditor":
  10495. case "mceRemoveControl":
  10496. if (ed)
  10497. ed.remove();
  10498. return true;
  10499. case 'mceToggleEditor':
  10500. if (!ed) {
  10501. t.execCommand('mceAddControl', 0, v);
  10502. return true;
  10503. }
  10504. if (ed.isHidden())
  10505. ed.show();
  10506. else
  10507. ed.hide();
  10508. return true;
  10509. }
  10510. // Run command on active editor
  10511. if (t.activeEditor)
  10512. return t.activeEditor.execCommand(c, u, v);
  10513. return false;
  10514. },
  10515. execInstanceCommand : function(id, c, u, v) {
  10516. var ed = this.get(id);
  10517. if (ed)
  10518. return ed.execCommand(c, u, v);
  10519. return false;
  10520. },
  10521. triggerSave : function() {
  10522. each(this.editors, function(e) {
  10523. e.save();
  10524. });
  10525. },
  10526. addI18n : function(p, o) {
  10527. var lo, i18n = this.i18n;
  10528. if (!tinymce.is(p, 'string')) {
  10529. each(p, function(o, lc) {
  10530. each(o, function(o, g) {
  10531. each(o, function(o, k) {
  10532. if (g === 'common')
  10533. i18n[lc + '.' + k] = o;
  10534. else
  10535. i18n[lc + '.' + g + '.' + k] = o;
  10536. });
  10537. });
  10538. });
  10539. } else {
  10540. each(o, function(o, k) {
  10541. i18n[p + '.' + k] = o;
  10542. });
  10543. }
  10544. },
  10545. // Private methods
  10546. _setActive : function(editor) {
  10547. this.selectedInstance = this.activeEditor = editor;
  10548. }
  10549. });
  10550. })(tinymce);
  10551. (function(tinymce) {
  10552. // Shorten these names
  10553. var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend,
  10554. each = tinymce.each, isGecko = tinymce.isGecko,
  10555. isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, is = tinymce.is,
  10556. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  10557. explode = tinymce.explode;
  10558. tinymce.create('tinymce.Editor', {
  10559. Editor : function(id, settings) {
  10560. var self = this, TRUE = true;
  10561. self.settings = settings = extend({
  10562. id : id,
  10563. language : 'en',
  10564. theme : 'advanced',
  10565. skin : 'default',
  10566. delta_width : 0,
  10567. delta_height : 0,
  10568. popup_css : '',
  10569. plugins : '',
  10570. document_base_url : tinymce.documentBaseURL,
  10571. add_form_submit_trigger : TRUE,
  10572. submit_patch : TRUE,
  10573. add_unload_trigger : TRUE,
  10574. convert_urls : TRUE,
  10575. relative_urls : TRUE,
  10576. remove_script_host : TRUE,
  10577. table_inline_editing : false,
  10578. object_resizing : TRUE,
  10579. accessibility_focus : TRUE,
  10580. doctype : tinymce.isIE6 ? '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' : '<!DOCTYPE>', // Use old doctype on IE 6 to avoid horizontal scroll
  10581. visual : TRUE,
  10582. font_size_style_values : 'xx-small,x-small,small,medium,large,x-large,xx-large',
  10583. 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
  10584. apply_source_formatting : TRUE,
  10585. directionality : 'ltr',
  10586. forced_root_block : 'p',
  10587. hidden_input : TRUE,
  10588. padd_empty_editor : TRUE,
  10589. render_ui : TRUE,
  10590. indentation : '30px',
  10591. fix_table_elements : TRUE,
  10592. inline_styles : TRUE,
  10593. convert_fonts_to_spans : TRUE,
  10594. indent : 'simple',
  10595. indent_before : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr,section,article,hgroup,aside,figure,option,optgroup,datalist',
  10596. indent_after : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr,section,article,hgroup,aside,figure,option,optgroup,datalist',
  10597. validate : TRUE,
  10598. entity_encoding : 'named',
  10599. url_converter : self.convertURL,
  10600. url_converter_scope : self,
  10601. ie7_compat : TRUE
  10602. }, settings);
  10603. self.id = self.editorId = id;
  10604. self.isNotDirty = false;
  10605. self.plugins = {};
  10606. self.documentBaseURI = new tinymce.util.URI(settings.document_base_url || tinymce.documentBaseURL, {
  10607. base_uri : tinyMCE.baseURI
  10608. });
  10609. self.baseURI = tinymce.baseURI;
  10610. self.contentCSS = [];
  10611. self.contentStyles = [];
  10612. // Creates all events like onClick, onSetContent etc see Editor.Events.js for the actual logic
  10613. self.setupEvents();
  10614. // Internal command handler objects
  10615. self.execCommands = {};
  10616. self.queryStateCommands = {};
  10617. self.queryValueCommands = {};
  10618. // Call setup
  10619. self.execCallback('setup', self);
  10620. },
  10621. render : function(nst) {
  10622. var t = this, s = t.settings, id = t.id, sl = tinymce.ScriptLoader;
  10623. // Page is not loaded yet, wait for it
  10624. if (!Event.domLoaded) {
  10625. Event.add(window, 'ready', function() {
  10626. t.render();
  10627. });
  10628. return;
  10629. }
  10630. tinyMCE.settings = s;
  10631. // Element not found, then skip initialization
  10632. if (!t.getElement())
  10633. return;
  10634. // Is a iPad/iPhone and not on iOS5, then skip initialization. We need to sniff
  10635. // here since the browser says it has contentEditable support but there is no visible caret.
  10636. if (tinymce.isIDevice && !tinymce.isIOS5)
  10637. return;
  10638. // Add hidden input for non input elements inside form elements
  10639. if (!/TEXTAREA|INPUT/i.test(t.getElement().nodeName) && s.hidden_input && DOM.getParent(id, 'form'))
  10640. DOM.insertAfter(DOM.create('input', {type : 'hidden', name : id}), id);
  10641. // Hide target element early to prevent content flashing
  10642. if (!s.content_editable) {
  10643. t.orgVisibility = t.getElement().style.visibility;
  10644. t.getElement().style.visibility = 'hidden';
  10645. }
  10646. if (tinymce.WindowManager)
  10647. t.windowManager = new tinymce.WindowManager(t);
  10648. if (s.encoding == 'xml') {
  10649. t.onGetContent.add(function(ed, o) {
  10650. if (o.save)
  10651. o.content = DOM.encode(o.content);
  10652. });
  10653. }
  10654. if (s.add_form_submit_trigger) {
  10655. t.onSubmit.addToTop(function() {
  10656. if (t.initialized) {
  10657. t.save();
  10658. t.isNotDirty = 1;
  10659. }
  10660. });
  10661. }
  10662. if (s.add_unload_trigger) {
  10663. t._beforeUnload = tinyMCE.onBeforeUnload.add(function() {
  10664. if (t.initialized && !t.destroyed && !t.isHidden())
  10665. t.save({format : 'raw', no_events : true});
  10666. });
  10667. }
  10668. tinymce.addUnload(t.destroy, t);
  10669. if (s.submit_patch) {
  10670. t.onBeforeRenderUI.add(function() {
  10671. var n = t.getElement().form;
  10672. if (!n)
  10673. return;
  10674. // Already patched
  10675. if (n._mceOldSubmit)
  10676. return;
  10677. // Check page uses id="submit" or name="submit" for it's submit button
  10678. if (!n.submit.nodeType && !n.submit.length) {
  10679. t.formElement = n;
  10680. n._mceOldSubmit = n.submit;
  10681. n.submit = function() {
  10682. // Save all instances
  10683. tinymce.triggerSave();
  10684. t.isNotDirty = 1;
  10685. return t.formElement._mceOldSubmit(t.formElement);
  10686. };
  10687. }
  10688. n = null;
  10689. });
  10690. }
  10691. // Load scripts
  10692. function loadScripts() {
  10693. if (s.language && s.language_load !== false)
  10694. sl.add(tinymce.baseURL + '/langs/' + s.language + '.js');
  10695. if (s.theme && typeof s.theme != "function" && s.theme.charAt(0) != '-' && !ThemeManager.urls[s.theme])
  10696. ThemeManager.load(s.theme, 'themes/' + s.theme + '/editor_template' + tinymce.suffix + '.js');
  10697. each(explode(s.plugins), function(p) {
  10698. if (p &&!PluginManager.urls[p]) {
  10699. if (p.charAt(0) == '-') {
  10700. p = p.substr(1, p.length);
  10701. var dependencies = PluginManager.dependencies(p);
  10702. each(dependencies, function(dep) {
  10703. var defaultSettings = {prefix:'plugins/', resource: dep, suffix:'/editor_plugin' + tinymce.suffix + '.js'};
  10704. dep = PluginManager.createUrl(defaultSettings, dep);
  10705. PluginManager.load(dep.resource, dep);
  10706. });
  10707. } else {
  10708. // Skip safari plugin, since it is removed as of 3.3b1
  10709. if (p == 'safari') {
  10710. return;
  10711. }
  10712. PluginManager.load(p, {prefix:'plugins/', resource: p, suffix:'/editor_plugin' + tinymce.suffix + '.js'});
  10713. }
  10714. }
  10715. });
  10716. // Init when que is loaded
  10717. sl.loadQueue(function() {
  10718. if (!t.removed)
  10719. t.init();
  10720. });
  10721. };
  10722. loadScripts();
  10723. },
  10724. init : function() {
  10725. var n, t = this, s = t.settings, w, h, mh, e = t.getElement(), o, ti, u, bi, bc, re, i, initializedPlugins = [];
  10726. tinymce.add(t);
  10727. s.aria_label = s.aria_label || DOM.getAttrib(e, 'aria-label', t.getLang('aria.rich_text_area'));
  10728. if (s.theme) {
  10729. if (typeof s.theme != "function") {
  10730. s.theme = s.theme.replace(/-/, '');
  10731. o = ThemeManager.get(s.theme);
  10732. t.theme = new o();
  10733. if (t.theme.init)
  10734. t.theme.init(t, ThemeManager.urls[s.theme] || tinymce.documentBaseURL.replace(/\/$/, ''));
  10735. } else {
  10736. t.theme = s.theme;
  10737. }
  10738. }
  10739. function initPlugin(p) {
  10740. var c = PluginManager.get(p), u = PluginManager.urls[p] || tinymce.documentBaseURL.replace(/\/$/, ''), po;
  10741. if (c && tinymce.inArray(initializedPlugins,p) === -1) {
  10742. each(PluginManager.dependencies(p), function(dep){
  10743. initPlugin(dep);
  10744. });
  10745. po = new c(t, u);
  10746. t.plugins[p] = po;
  10747. if (po.init) {
  10748. po.init(t, u);
  10749. initializedPlugins.push(p);
  10750. }
  10751. }
  10752. }
  10753. // Create all plugins
  10754. each(explode(s.plugins.replace(/\-/g, '')), initPlugin);
  10755. // Setup popup CSS path(s)
  10756. if (s.popup_css !== false) {
  10757. if (s.popup_css)
  10758. s.popup_css = t.documentBaseURI.toAbsolute(s.popup_css);
  10759. else
  10760. s.popup_css = t.baseURI.toAbsolute("themes/" + s.theme + "/skins/" + s.skin + "/dialog.css");
  10761. }
  10762. if (s.popup_css_add)
  10763. s.popup_css += ',' + t.documentBaseURI.toAbsolute(s.popup_css_add);
  10764. t.controlManager = new tinymce.ControlManager(t);
  10765. // Enables users to override the control factory
  10766. t.onBeforeRenderUI.dispatch(t, t.controlManager);
  10767. // Measure box
  10768. if (s.render_ui && t.theme) {
  10769. t.orgDisplay = e.style.display;
  10770. if (typeof s.theme != "function") {
  10771. w = s.width || e.style.width || e.offsetWidth;
  10772. h = s.height || e.style.height || e.offsetHeight;
  10773. mh = s.min_height || 100;
  10774. re = /^[0-9\.]+(|px)$/i;
  10775. if (re.test('' + w))
  10776. w = Math.max(parseInt(w, 10) + (o.deltaWidth || 0), 100);
  10777. if (re.test('' + h))
  10778. h = Math.max(parseInt(h, 10) + (o.deltaHeight || 0), mh);
  10779. // Render UI
  10780. o = t.theme.renderUI({
  10781. targetNode : e,
  10782. width : w,
  10783. height : h,
  10784. deltaWidth : s.delta_width,
  10785. deltaHeight : s.delta_height
  10786. });
  10787. // Resize editor
  10788. DOM.setStyles(o.sizeContainer || o.editorContainer, {
  10789. width : w,
  10790. height : h
  10791. });
  10792. h = (o.iframeHeight || h) + (typeof(h) == 'number' ? (o.deltaHeight || 0) : '');
  10793. if (h < mh)
  10794. h = mh;
  10795. } else {
  10796. o = s.theme(t, e);
  10797. // Convert element type to id:s
  10798. if (o.editorContainer.nodeType) {
  10799. o.editorContainer = o.editorContainer.id = o.editorContainer.id || t.id + "_parent";
  10800. }
  10801. // Convert element type to id:s
  10802. if (o.iframeContainer.nodeType) {
  10803. o.iframeContainer = o.iframeContainer.id = o.iframeContainer.id || t.id + "_iframecontainer";
  10804. }
  10805. // Use specified iframe height or the targets offsetHeight
  10806. h = o.iframeHeight || e.offsetHeight;
  10807. // Store away the selection when it's changed to it can be restored later with a editor.focus() call
  10808. if (isIE) {
  10809. t.onInit.add(function(ed) {
  10810. ed.dom.bind(ed.getBody(), 'beforedeactivate keydown', function() {
  10811. ed.lastIERng = ed.selection.getRng();
  10812. });
  10813. });
  10814. }
  10815. }
  10816. t.editorContainer = o.editorContainer;
  10817. }
  10818. // Load specified content CSS last
  10819. if (s.content_css) {
  10820. each(explode(s.content_css), function(u) {
  10821. t.contentCSS.push(t.documentBaseURI.toAbsolute(u));
  10822. });
  10823. }
  10824. // Load specified content CSS last
  10825. if (s.content_style) {
  10826. t.contentStyles.push(s.content_style);
  10827. }
  10828. // Content editable mode ends here
  10829. if (s.content_editable) {
  10830. e = n = o = null; // Fix IE leak
  10831. return t.initContentBody();
  10832. }
  10833. // User specified a document.domain value
  10834. if (document.domain && location.hostname != document.domain)
  10835. tinymce.relaxedDomain = document.domain;
  10836. t.iframeHTML = s.doctype + '<html><head xmlns="http://www.w3.org/1999/xhtml">';
  10837. // We only need to override paths if we have to
  10838. // IE has a bug where it remove site absolute urls to relative ones if this is specified
  10839. if (s.document_base_url != tinymce.documentBaseURL)
  10840. t.iframeHTML += '<base href="' + t.documentBaseURI.getURI() + '" />';
  10841. // IE8 doesn't support carets behind images setting ie7_compat would force IE8+ to run in IE7 compat mode.
  10842. if (tinymce.isIE8) {
  10843. if (s.ie7_compat)
  10844. t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=7" />';
  10845. else
  10846. t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=edge" />';
  10847. }
  10848. t.iframeHTML += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
  10849. // Load the CSS by injecting them into the HTML this will reduce "flicker"
  10850. for (i = 0; i < t.contentCSS.length; i++) {
  10851. t.iframeHTML += '<link type="text/css" rel="stylesheet" href="' + t.contentCSS[i] + '" />';
  10852. }
  10853. t.contentCSS = [];
  10854. bi = s.body_id || 'tinymce';
  10855. if (bi.indexOf('=') != -1) {
  10856. bi = t.getParam('body_id', '', 'hash');
  10857. bi = bi[t.id] || bi;
  10858. }
  10859. bc = s.body_class || '';
  10860. if (bc.indexOf('=') != -1) {
  10861. bc = t.getParam('body_class', '', 'hash');
  10862. bc = bc[t.id] || '';
  10863. }
  10864. t.iframeHTML += '</head><body id="' + bi + '" class="mceContentBody ' + bc + '" onload="window.parent.tinyMCE.get(\'' + t.id + '\').onLoad.dispatch();"><br></body></html>';
  10865. // Domain relaxing enabled, then set document domain
  10866. if (tinymce.relaxedDomain && (isIE || (tinymce.isOpera && parseFloat(opera.version()) < 11))) {
  10867. // We need to write the contents here in IE since multiple writes messes up refresh button and back button
  10868. u = 'javascript:(function(){document.open();document.domain="' + document.domain + '";var ed = window.parent.tinyMCE.get("' + t.id + '");document.write(ed.iframeHTML);document.close();ed.initContentBody();})()';
  10869. }
  10870. // Create iframe
  10871. // TODO: ACC add the appropriate description on this.
  10872. n = DOM.add(o.iframeContainer, 'iframe', {
  10873. id : t.id + "_ifr",
  10874. src : u || 'javascript:""', // Workaround for HTTPS warning in IE6/7
  10875. frameBorder : '0',
  10876. allowTransparency : "true",
  10877. title : s.aria_label,
  10878. style : {
  10879. width : '100%',
  10880. height : h,
  10881. display : 'block' // Important for Gecko to render the iframe correctly
  10882. }
  10883. });
  10884. t.contentAreaContainer = o.iframeContainer;
  10885. if (o.editorContainer) {
  10886. DOM.get(o.editorContainer).style.display = t.orgDisplay;
  10887. }
  10888. // Restore visibility on target element
  10889. e.style.visibility = t.orgVisibility;
  10890. DOM.get(t.id).style.display = 'none';
  10891. DOM.setAttrib(t.id, 'aria-hidden', true);
  10892. if (!tinymce.relaxedDomain || !u)
  10893. t.initContentBody();
  10894. e = n = o = null; // Cleanup
  10895. },
  10896. initContentBody : function() {
  10897. var self = this, settings = self.settings, targetElm = DOM.get(self.id), doc = self.getDoc(), html, body, contentCssText;
  10898. // Setup iframe body
  10899. if ((!isIE || !tinymce.relaxedDomain) && !settings.content_editable) {
  10900. doc.open();
  10901. doc.write(self.iframeHTML);
  10902. doc.close();
  10903. if (tinymce.relaxedDomain)
  10904. doc.domain = tinymce.relaxedDomain;
  10905. }
  10906. if (settings.content_editable) {
  10907. DOM.addClass(targetElm, 'mceContentBody');
  10908. self.contentDocument = doc = settings.content_document || document;
  10909. self.contentWindow = settings.content_window || window;
  10910. self.bodyElement = targetElm;
  10911. // Prevent leak in IE
  10912. settings.content_document = settings.content_window = null;
  10913. }
  10914. // It will not steal focus while setting contentEditable
  10915. body = self.getBody();
  10916. body.disabled = true;
  10917. if (!settings.readonly)
  10918. body.contentEditable = self.getParam('content_editable_state', true);
  10919. body.disabled = false;
  10920. self.schema = new tinymce.html.Schema(settings);
  10921. self.dom = new tinymce.dom.DOMUtils(doc, {
  10922. keep_values : true,
  10923. url_converter : self.convertURL,
  10924. url_converter_scope : self,
  10925. hex_colors : settings.force_hex_style_colors,
  10926. class_filter : settings.class_filter,
  10927. update_styles : true,
  10928. root_element : settings.content_editable ? self.id : null,
  10929. schema : self.schema
  10930. });
  10931. self.parser = new tinymce.html.DomParser(settings, self.schema);
  10932. // Convert src and href into data-mce-src, data-mce-href and data-mce-style
  10933. self.parser.addAttributeFilter('src,href,style', function(nodes, name) {
  10934. var i = nodes.length, node, dom = self.dom, value, internalName;
  10935. while (i--) {
  10936. node = nodes[i];
  10937. value = node.attr(name);
  10938. internalName = 'data-mce-' + name;
  10939. // Add internal attribute if we need to we don't on a refresh of the document
  10940. if (!node.attributes.map[internalName]) {
  10941. if (name === "style")
  10942. node.attr(internalName, dom.serializeStyle(dom.parseStyle(value), node.name));
  10943. else
  10944. node.attr(internalName, self.convertURL(value, name, node.name));
  10945. }
  10946. }
  10947. });
  10948. // Keep scripts from executing
  10949. self.parser.addNodeFilter('script', function(nodes, name) {
  10950. var i = nodes.length, node;
  10951. while (i--) {
  10952. node = nodes[i];
  10953. node.attr('type', 'mce-' + (node.attr('type') || 'text/javascript'));
  10954. }
  10955. });
  10956. self.parser.addNodeFilter('#cdata', function(nodes, name) {
  10957. var i = nodes.length, node;
  10958. while (i--) {
  10959. node = nodes[i];
  10960. node.type = 8;
  10961. node.name = '#comment';
  10962. node.value = '[CDATA[' + node.value + ']]';
  10963. }
  10964. });
  10965. self.parser.addNodeFilter('p,h1,h2,h3,h4,h5,h6,div', function(nodes, name) {
  10966. var i = nodes.length, node, nonEmptyElements = self.schema.getNonEmptyElements();
  10967. while (i--) {
  10968. node = nodes[i];
  10969. if (node.isEmpty(nonEmptyElements))
  10970. node.empty().append(new tinymce.html.Node('br', 1)).shortEnded = true;
  10971. }
  10972. });
  10973. self.serializer = new tinymce.dom.Serializer(settings, self.dom, self.schema);
  10974. self.selection = new tinymce.dom.Selection(self.dom, self.getWin(), self.serializer, self);
  10975. self.formatter = new tinymce.Formatter(self);
  10976. self.undoManager = new tinymce.UndoManager(self);
  10977. self.forceBlocks = new tinymce.ForceBlocks(self);
  10978. self.enterKey = new tinymce.EnterKey(self);
  10979. self.editorCommands = new tinymce.EditorCommands(self);
  10980. self.onExecCommand.add(function(editor, command) {
  10981. // Don't refresh the select lists until caret move
  10982. if (!/^(FontName|FontSize)$/.test(command))
  10983. self.nodeChanged();
  10984. });
  10985. // Pass through
  10986. self.serializer.onPreProcess.add(function(se, o) {
  10987. return self.onPreProcess.dispatch(self, o, se);
  10988. });
  10989. self.serializer.onPostProcess.add(function(se, o) {
  10990. return self.onPostProcess.dispatch(self, o, se);
  10991. });
  10992. self.onPreInit.dispatch(self);
  10993. if (!settings.browser_spellcheck && !settings.gecko_spellcheck)
  10994. doc.body.spellcheck = false;
  10995. if (!settings.readonly) {
  10996. self.bindNativeEvents();
  10997. }
  10998. self.controlManager.onPostRender.dispatch(self, self.controlManager);
  10999. self.onPostRender.dispatch(self);
  11000. self.quirks = tinymce.util.Quirks(self);
  11001. if (settings.directionality)
  11002. body.dir = settings.directionality;
  11003. if (settings.nowrap)
  11004. body.style.whiteSpace = "nowrap";
  11005. if (settings.protect) {
  11006. self.onBeforeSetContent.add(function(ed, o) {
  11007. each(settings.protect, function(pattern) {
  11008. o.content = o.content.replace(pattern, function(str) {
  11009. return '<!--mce:protected ' + escape(str) + '-->';
  11010. });
  11011. });
  11012. });
  11013. }
  11014. // Add visual aids when new contents is added
  11015. self.onSetContent.add(function() {
  11016. self.addVisual(self.getBody());
  11017. });
  11018. // Remove empty contents
  11019. if (settings.padd_empty_editor) {
  11020. self.onPostProcess.add(function(ed, o) {
  11021. o.content = o.content.replace(/^(<p[^>]*>(&nbsp;|&#160;|\s|\u00a0|)<\/p>[\r\n]*|<br \/>[\r\n]*)$/, '');
  11022. });
  11023. }
  11024. self.load({initial : true, format : 'html'});
  11025. self.startContent = self.getContent({format : 'raw'});
  11026. self.initialized = true;
  11027. self.onInit.dispatch(self);
  11028. self.execCallback('setupcontent_callback', self.id, body, doc);
  11029. self.execCallback('init_instance_callback', self);
  11030. self.focus(true);
  11031. self.nodeChanged({initial : true});
  11032. // Add editor specific CSS styles
  11033. if (self.contentStyles.length > 0) {
  11034. contentCssText = '';
  11035. each(self.contentStyles, function(style) {
  11036. contentCssText += style + "\r\n";
  11037. });
  11038. self.dom.addStyle(contentCssText);
  11039. }
  11040. // Load specified content CSS last
  11041. each(self.contentCSS, function(url) {
  11042. self.dom.loadCSS(url);
  11043. });
  11044. // Handle auto focus
  11045. if (settings.auto_focus) {
  11046. setTimeout(function () {
  11047. var ed = tinymce.get(settings.auto_focus);
  11048. ed.selection.select(ed.getBody(), 1);
  11049. ed.selection.collapse(1);
  11050. ed.getBody().focus();
  11051. ed.getWin().focus();
  11052. }, 100);
  11053. }
  11054. // Clean up references for IE
  11055. targetElm = doc = body = null;
  11056. },
  11057. focus : function(skip_focus) {
  11058. var oed, self = this, selection = self.selection, contentEditable = self.settings.content_editable, ieRng, controlElm, doc = self.getDoc(), body;
  11059. if (!skip_focus) {
  11060. if (self.lastIERng) {
  11061. selection.setRng(self.lastIERng);
  11062. }
  11063. // Get selected control element
  11064. ieRng = selection.getRng();
  11065. if (ieRng.item) {
  11066. controlElm = ieRng.item(0);
  11067. }
  11068. self._refreshContentEditable();
  11069. // Focus the window iframe
  11070. if (!contentEditable) {
  11071. self.getWin().focus();
  11072. }
  11073. // Focus the body as well since it's contentEditable
  11074. if (tinymce.isGecko || contentEditable) {
  11075. body = self.getBody();
  11076. // Check for setActive since it doesn't scroll to the element
  11077. if (body.setActive) {
  11078. body.setActive();
  11079. } else {
  11080. body.focus();
  11081. }
  11082. if (contentEditable) {
  11083. selection.normalize();
  11084. }
  11085. }
  11086. // Restore selected control element
  11087. // This is needed when for example an image is selected within a
  11088. // layer a call to focus will then remove the control selection
  11089. if (controlElm && controlElm.ownerDocument == doc) {
  11090. ieRng = doc.body.createControlRange();
  11091. ieRng.addElement(controlElm);
  11092. ieRng.select();
  11093. }
  11094. }
  11095. if (tinymce.activeEditor != self) {
  11096. if ((oed = tinymce.activeEditor) != null)
  11097. oed.onDeactivate.dispatch(oed, self);
  11098. self.onActivate.dispatch(self, oed);
  11099. }
  11100. tinymce._setActive(self);
  11101. },
  11102. execCallback : function(n) {
  11103. var t = this, f = t.settings[n], s;
  11104. if (!f)
  11105. return;
  11106. // Look through lookup
  11107. if (t.callbackLookup && (s = t.callbackLookup[n])) {
  11108. f = s.func;
  11109. s = s.scope;
  11110. }
  11111. if (is(f, 'string')) {
  11112. s = f.replace(/\.\w+$/, '');
  11113. s = s ? tinymce.resolve(s) : 0;
  11114. f = tinymce.resolve(f);
  11115. t.callbackLookup = t.callbackLookup || {};
  11116. t.callbackLookup[n] = {func : f, scope : s};
  11117. }
  11118. return f.apply(s || t, Array.prototype.slice.call(arguments, 1));
  11119. },
  11120. translate : function(s) {
  11121. var c = this.settings.language || 'en', i18n = tinymce.i18n;
  11122. if (!s)
  11123. return '';
  11124. return i18n[c + '.' + s] || s.replace(/\{\#([^\}]+)\}/g, function(a, b) {
  11125. return i18n[c + '.' + b] || '{#' + b + '}';
  11126. });
  11127. },
  11128. getLang : function(n, dv) {
  11129. return tinymce.i18n[(this.settings.language || 'en') + '.' + n] || (is(dv) ? dv : '{#' + n + '}');
  11130. },
  11131. getParam : function(n, dv, ty) {
  11132. var tr = tinymce.trim, v = is(this.settings[n]) ? this.settings[n] : dv, o;
  11133. if (ty === 'hash') {
  11134. o = {};
  11135. if (is(v, 'string')) {
  11136. each(v.indexOf('=') > 0 ? v.split(/[;,](?![^=;,]*(?:[;,]|$))/) : v.split(','), function(v) {
  11137. v = v.split('=');
  11138. if (v.length > 1)
  11139. o[tr(v[0])] = tr(v[1]);
  11140. else
  11141. o[tr(v[0])] = tr(v);
  11142. });
  11143. } else
  11144. o = v;
  11145. return o;
  11146. }
  11147. return v;
  11148. },
  11149. nodeChanged : function(o) {
  11150. var self = this, selection = self.selection, node;
  11151. // Fix for bug #1896577 it seems that this can not be fired while the editor is loading
  11152. if (self.initialized) {
  11153. o = o || {};
  11154. // Get start node
  11155. node = selection.getStart() || self.getBody();
  11156. node = isIE && node.ownerDocument != self.getDoc() ? self.getBody() : node; // Fix for IE initial state
  11157. // Get parents and add them to object
  11158. o.parents = [];
  11159. self.dom.getParent(node, function(node) {
  11160. if (node.nodeName == 'BODY')
  11161. return true;
  11162. o.parents.push(node);
  11163. });
  11164. self.onNodeChange.dispatch(
  11165. self,
  11166. o ? o.controlManager || self.controlManager : self.controlManager,
  11167. node,
  11168. selection.isCollapsed(),
  11169. o
  11170. );
  11171. }
  11172. },
  11173. addButton : function(name, settings) {
  11174. var self = this;
  11175. self.buttons = self.buttons || {};
  11176. self.buttons[name] = settings;
  11177. },
  11178. addCommand : function(name, callback, scope) {
  11179. this.execCommands[name] = {func : callback, scope : scope || this};
  11180. },
  11181. addQueryStateHandler : function(name, callback, scope) {
  11182. this.queryStateCommands[name] = {func : callback, scope : scope || this};
  11183. },
  11184. addQueryValueHandler : function(name, callback, scope) {
  11185. this.queryValueCommands[name] = {func : callback, scope : scope || this};
  11186. },
  11187. addShortcut : function(pa, desc, cmd_func, sc) {
  11188. var t = this, c;
  11189. if (t.settings.custom_shortcuts === false)
  11190. return false;
  11191. t.shortcuts = t.shortcuts || {};
  11192. if (is(cmd_func, 'string')) {
  11193. c = cmd_func;
  11194. cmd_func = function() {
  11195. t.execCommand(c, false, null);
  11196. };
  11197. }
  11198. if (is(cmd_func, 'object')) {
  11199. c = cmd_func;
  11200. cmd_func = function() {
  11201. t.execCommand(c[0], c[1], c[2]);
  11202. };
  11203. }
  11204. each(explode(pa), function(pa) {
  11205. var o = {
  11206. func : cmd_func,
  11207. scope : sc || this,
  11208. desc : t.translate(desc),
  11209. alt : false,
  11210. ctrl : false,
  11211. shift : false
  11212. };
  11213. each(explode(pa, '+'), function(v) {
  11214. switch (v) {
  11215. case 'alt':
  11216. case 'ctrl':
  11217. case 'shift':
  11218. o[v] = true;
  11219. break;
  11220. default:
  11221. o.charCode = v.charCodeAt(0);
  11222. o.keyCode = v.toUpperCase().charCodeAt(0);
  11223. }
  11224. });
  11225. t.shortcuts[(o.ctrl ? 'ctrl' : '') + ',' + (o.alt ? 'alt' : '') + ',' + (o.shift ? 'shift' : '') + ',' + o.keyCode] = o;
  11226. });
  11227. return true;
  11228. },
  11229. execCommand : function(cmd, ui, val, a) {
  11230. var t = this, s = 0, o, st;
  11231. if (!/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint|SelectAll)$/.test(cmd) && (!a || !a.skip_focus))
  11232. t.focus();
  11233. a = extend({}, a);
  11234. t.onBeforeExecCommand.dispatch(t, cmd, ui, val, a);
  11235. if (a.terminate)
  11236. return false;
  11237. // Command callback
  11238. if (t.execCallback('execcommand_callback', t.id, t.selection.getNode(), cmd, ui, val)) {
  11239. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  11240. return true;
  11241. }
  11242. // Registred commands
  11243. if (o = t.execCommands[cmd]) {
  11244. st = o.func.call(o.scope, ui, val);
  11245. // Fall through on true
  11246. if (st !== true) {
  11247. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  11248. return st;
  11249. }
  11250. }
  11251. // Plugin commands
  11252. each(t.plugins, function(p) {
  11253. if (p.execCommand && p.execCommand(cmd, ui, val)) {
  11254. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  11255. s = 1;
  11256. return false;
  11257. }
  11258. });
  11259. if (s)
  11260. return true;
  11261. // Theme commands
  11262. if (t.theme && t.theme.execCommand && t.theme.execCommand(cmd, ui, val)) {
  11263. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  11264. return true;
  11265. }
  11266. // Editor commands
  11267. if (t.editorCommands.execCommand(cmd, ui, val)) {
  11268. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  11269. return true;
  11270. }
  11271. // Browser commands
  11272. t.getDoc().execCommand(cmd, ui, val);
  11273. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  11274. },
  11275. queryCommandState : function(cmd) {
  11276. var t = this, o, s;
  11277. // Is hidden then return undefined
  11278. if (t._isHidden())
  11279. return;
  11280. // Registred commands
  11281. if (o = t.queryStateCommands[cmd]) {
  11282. s = o.func.call(o.scope);
  11283. // Fall though on true
  11284. if (s !== true)
  11285. return s;
  11286. }
  11287. // Registred commands
  11288. o = t.editorCommands.queryCommandState(cmd);
  11289. if (o !== -1)
  11290. return o;
  11291. // Browser commands
  11292. try {
  11293. return this.getDoc().queryCommandState(cmd);
  11294. } catch (ex) {
  11295. // Fails sometimes see bug: 1896577
  11296. }
  11297. },
  11298. queryCommandValue : function(c) {
  11299. var t = this, o, s;
  11300. // Is hidden then return undefined
  11301. if (t._isHidden())
  11302. return;
  11303. // Registred commands
  11304. if (o = t.queryValueCommands[c]) {
  11305. s = o.func.call(o.scope);
  11306. // Fall though on true
  11307. if (s !== true)
  11308. return s;
  11309. }
  11310. // Registred commands
  11311. o = t.editorCommands.queryCommandValue(c);
  11312. if (is(o))
  11313. return o;
  11314. // Browser commands
  11315. try {
  11316. return this.getDoc().queryCommandValue(c);
  11317. } catch (ex) {
  11318. // Fails sometimes see bug: 1896577
  11319. }
  11320. },
  11321. show : function() {
  11322. var self = this;
  11323. DOM.show(self.getContainer());
  11324. DOM.hide(self.id);
  11325. self.load();
  11326. },
  11327. hide : function() {
  11328. var self = this, doc = self.getDoc();
  11329. // Fixed bug where IE has a blinking cursor left from the editor
  11330. if (isIE && doc)
  11331. doc.execCommand('SelectAll');
  11332. // We must save before we hide so Safari doesn't crash
  11333. self.save();
  11334. // defer the call to hide to prevent an IE9 crash #4921
  11335. DOM.hide(self.getContainer());
  11336. DOM.setStyle(self.id, 'display', self.orgDisplay);
  11337. },
  11338. isHidden : function() {
  11339. return !DOM.isHidden(this.id);
  11340. },
  11341. setProgressState : function(b, ti, o) {
  11342. this.onSetProgressState.dispatch(this, b, ti, o);
  11343. return b;
  11344. },
  11345. load : function(o) {
  11346. var t = this, e = t.getElement(), h;
  11347. if (e) {
  11348. o = o || {};
  11349. o.load = true;
  11350. // Double encode existing entities in the value
  11351. h = t.setContent(is(e.value) ? e.value : e.innerHTML, o);
  11352. o.element = e;
  11353. if (!o.no_events)
  11354. t.onLoadContent.dispatch(t, o);
  11355. o.element = e = null;
  11356. return h;
  11357. }
  11358. },
  11359. save : function(o) {
  11360. var t = this, e = t.getElement(), h, f;
  11361. if (!e || !t.initialized)
  11362. return;
  11363. o = o || {};
  11364. o.save = true;
  11365. o.element = e;
  11366. h = o.content = t.getContent(o);
  11367. if (!o.no_events)
  11368. t.onSaveContent.dispatch(t, o);
  11369. h = o.content;
  11370. if (!/TEXTAREA|INPUT/i.test(e.nodeName)) {
  11371. e.innerHTML = h;
  11372. // Update hidden form element
  11373. if (f = DOM.getParent(t.id, 'form')) {
  11374. each(f.elements, function(e) {
  11375. if (e.name == t.id) {
  11376. e.value = h;
  11377. return false;
  11378. }
  11379. });
  11380. }
  11381. } else
  11382. e.value = h;
  11383. o.element = e = null;
  11384. return h;
  11385. },
  11386. setContent : function(content, args) {
  11387. var self = this, rootNode, body = self.getBody(), forcedRootBlockName;
  11388. // Setup args object
  11389. args = args || {};
  11390. args.format = args.format || 'html';
  11391. args.set = true;
  11392. args.content = content;
  11393. // Do preprocessing
  11394. if (!args.no_events)
  11395. self.onBeforeSetContent.dispatch(self, args);
  11396. content = args.content;
  11397. // Padd empty content in Gecko and Safari. Commands will otherwise fail on the content
  11398. // It will also be impossible to place the caret in the editor unless there is a BR element present
  11399. if (!tinymce.isIE && (content.length === 0 || /^\s+$/.test(content))) {
  11400. forcedRootBlockName = self.settings.forced_root_block;
  11401. if (forcedRootBlockName)
  11402. content = '<' + forcedRootBlockName + '><br data-mce-bogus="1"></' + forcedRootBlockName + '>';
  11403. else
  11404. content = '<br data-mce-bogus="1">';
  11405. body.innerHTML = content;
  11406. self.selection.select(body, true);
  11407. self.selection.collapse(true);
  11408. return;
  11409. }
  11410. // Parse and serialize the html
  11411. if (args.format !== 'raw') {
  11412. content = new tinymce.html.Serializer({}, self.schema).serialize(
  11413. self.parser.parse(content)
  11414. );
  11415. }
  11416. // Set the new cleaned contents to the editor
  11417. args.content = tinymce.trim(content);
  11418. self.dom.setHTML(body, args.content);
  11419. // Do post processing
  11420. if (!args.no_events)
  11421. self.onSetContent.dispatch(self, args);
  11422. // Don't normalize selection if the focused element isn't the body in content editable mode since it will steal focus otherwise
  11423. if (!self.settings.content_editable || document.activeElement === self.getBody()) {
  11424. self.selection.normalize();
  11425. }
  11426. return args.content;
  11427. },
  11428. getContent : function(args) {
  11429. var self = this, content, body = self.getBody();
  11430. // Setup args object
  11431. args = args || {};
  11432. args.format = args.format || 'html';
  11433. args.get = true;
  11434. args.getInner = true;
  11435. // Do preprocessing
  11436. if (!args.no_events)
  11437. self.onBeforeGetContent.dispatch(self, args);
  11438. // Get raw contents or by default the cleaned contents
  11439. if (args.format == 'raw')
  11440. content = body.innerHTML;
  11441. else if (args.format == 'text')
  11442. content = body.innerText || body.textContent;
  11443. else
  11444. content = self.serializer.serialize(body, args);
  11445. // Trim whitespace in beginning/end of HTML
  11446. if (args.format != 'text') {
  11447. args.content = tinymce.trim(content);
  11448. } else {
  11449. args.content = content;
  11450. }
  11451. // Do post processing
  11452. if (!args.no_events)
  11453. self.onGetContent.dispatch(self, args);
  11454. return args.content;
  11455. },
  11456. isDirty : function() {
  11457. var self = this;
  11458. return tinymce.trim(self.startContent) != tinymce.trim(self.getContent({format : 'raw', no_events : 1})) && !self.isNotDirty;
  11459. },
  11460. getContainer : function() {
  11461. var self = this;
  11462. if (!self.container)
  11463. self.container = DOM.get(self.editorContainer || self.id + '_parent');
  11464. return self.container;
  11465. },
  11466. getContentAreaContainer : function() {
  11467. return this.contentAreaContainer;
  11468. },
  11469. getElement : function() {
  11470. return DOM.get(this.settings.content_element || this.id);
  11471. },
  11472. getWin : function() {
  11473. var self = this, elm;
  11474. if (!self.contentWindow) {
  11475. elm = DOM.get(self.id + "_ifr");
  11476. if (elm)
  11477. self.contentWindow = elm.contentWindow;
  11478. }
  11479. return self.contentWindow;
  11480. },
  11481. getDoc : function() {
  11482. var self = this, win;
  11483. if (!self.contentDocument) {
  11484. win = self.getWin();
  11485. if (win)
  11486. self.contentDocument = win.document;
  11487. }
  11488. return self.contentDocument;
  11489. },
  11490. getBody : function() {
  11491. return this.bodyElement || this.getDoc().body;
  11492. },
  11493. convertURL : function(url, name, elm) {
  11494. var self = this, settings = self.settings;
  11495. // Use callback instead
  11496. if (settings.urlconverter_callback)
  11497. return self.execCallback('urlconverter_callback', url, elm, true, name);
  11498. // Don't convert link href since thats the CSS files that gets loaded into the editor also skip local file URLs
  11499. if (!settings.convert_urls || (elm && elm.nodeName == 'LINK') || url.indexOf('file:') === 0)
  11500. return url;
  11501. // Convert to relative
  11502. if (settings.relative_urls)
  11503. return self.documentBaseURI.toRelative(url);
  11504. // Convert to absolute
  11505. url = self.documentBaseURI.toAbsolute(url, settings.remove_script_host);
  11506. return url;
  11507. },
  11508. addVisual : function(elm) {
  11509. var self = this, settings = self.settings, dom = self.dom, cls;
  11510. elm = elm || self.getBody();
  11511. if (!is(self.hasVisual))
  11512. self.hasVisual = settings.visual;
  11513. each(dom.select('table,a', elm), function(elm) {
  11514. var value;
  11515. switch (elm.nodeName) {
  11516. case 'TABLE':
  11517. cls = settings.visual_table_class || 'mceItemTable';
  11518. value = dom.getAttrib(elm, 'border');
  11519. if (!value || value == '0') {
  11520. if (self.hasVisual)
  11521. dom.addClass(elm, cls);
  11522. else
  11523. dom.removeClass(elm, cls);
  11524. }
  11525. return;
  11526. case 'A':
  11527. if (!dom.getAttrib(elm, 'href', false)) {
  11528. value = dom.getAttrib(elm, 'name') || elm.id;
  11529. cls = 'mceItemAnchor';
  11530. if (value) {
  11531. if (self.hasVisual)
  11532. dom.addClass(elm, cls);
  11533. else
  11534. dom.removeClass(elm, cls);
  11535. }
  11536. }
  11537. return;
  11538. }
  11539. });
  11540. self.onVisualAid.dispatch(self, elm, self.hasVisual);
  11541. },
  11542. remove : function() {
  11543. var self = this, elm = self.getContainer(), doc = self.getDoc();
  11544. if (!self.removed) {
  11545. self.removed = 1; // Cancels post remove event execution
  11546. // Fixed bug where IE has a blinking cursor left from the editor
  11547. if (isIE && doc)
  11548. doc.execCommand('SelectAll');
  11549. // We must save before we hide so Safari doesn't crash
  11550. self.save();
  11551. DOM.setStyle(self.id, 'display', self.orgDisplay);
  11552. // Don't clear the window or document if content editable
  11553. // is enabled since other instances might still be present
  11554. if (!self.settings.content_editable) {
  11555. Event.unbind(self.getWin());
  11556. Event.unbind(self.getDoc());
  11557. }
  11558. Event.unbind(self.getBody());
  11559. Event.clear(elm);
  11560. self.execCallback('remove_instance_callback', self);
  11561. self.onRemove.dispatch(self);
  11562. // Clear all execCommand listeners this is required to avoid errors if the editor was removed inside another command
  11563. self.onExecCommand.listeners = [];
  11564. tinymce.remove(self);
  11565. DOM.remove(elm);
  11566. }
  11567. },
  11568. destroy : function(s) {
  11569. var t = this;
  11570. // One time is enough
  11571. if (t.destroyed)
  11572. return;
  11573. // We must unbind on Gecko since it would otherwise produce the pesky "attempt to run compile-and-go script on a cleared scope" message
  11574. if (isGecko) {
  11575. Event.unbind(t.getDoc());
  11576. Event.unbind(t.getWin());
  11577. Event.unbind(t.getBody());
  11578. }
  11579. if (!s) {
  11580. tinymce.removeUnload(t.destroy);
  11581. tinyMCE.onBeforeUnload.remove(t._beforeUnload);
  11582. // Manual destroy
  11583. if (t.theme && t.theme.destroy)
  11584. t.theme.destroy();
  11585. // Destroy controls, selection and dom
  11586. t.controlManager.destroy();
  11587. t.selection.destroy();
  11588. t.dom.destroy();
  11589. }
  11590. if (t.formElement) {
  11591. t.formElement.submit = t.formElement._mceOldSubmit;
  11592. t.formElement._mceOldSubmit = null;
  11593. }
  11594. t.contentAreaContainer = t.formElement = t.container = t.settings.content_element = t.bodyElement = t.contentDocument = t.contentWindow = null;
  11595. if (t.selection)
  11596. t.selection = t.selection.win = t.selection.dom = t.selection.dom.doc = null;
  11597. t.destroyed = 1;
  11598. },
  11599. // Internal functions
  11600. _refreshContentEditable : function() {
  11601. var self = this, body, parent;
  11602. // Check if the editor was hidden and the re-initalize contentEditable mode by removing and adding the body again
  11603. if (self._isHidden()) {
  11604. body = self.getBody();
  11605. parent = body.parentNode;
  11606. parent.removeChild(body);
  11607. parent.appendChild(body);
  11608. body.focus();
  11609. }
  11610. },
  11611. _isHidden : function() {
  11612. var s;
  11613. if (!isGecko)
  11614. return 0;
  11615. // Weird, wheres that cursor selection?
  11616. s = this.selection.getSel();
  11617. return (!s || !s.rangeCount || s.rangeCount === 0);
  11618. }
  11619. });
  11620. })(tinymce);
  11621. (function(tinymce) {
  11622. var each = tinymce.each;
  11623. tinymce.Editor.prototype.setupEvents = function() {
  11624. var self = this, settings = self.settings;
  11625. // Add events to the editor
  11626. each([
  11627. 'onPreInit',
  11628. 'onBeforeRenderUI',
  11629. 'onPostRender',
  11630. 'onLoad',
  11631. 'onInit',
  11632. 'onRemove',
  11633. 'onActivate',
  11634. 'onDeactivate',
  11635. 'onClick',
  11636. 'onEvent',
  11637. 'onMouseUp',
  11638. 'onMouseDown',
  11639. 'onDblClick',
  11640. 'onKeyDown',
  11641. 'onKeyUp',
  11642. 'onKeyPress',
  11643. 'onContextMenu',
  11644. 'onSubmit',
  11645. 'onReset',
  11646. 'onPaste',
  11647. 'onPreProcess',
  11648. 'onPostProcess',
  11649. 'onBeforeSetContent',
  11650. 'onBeforeGetContent',
  11651. 'onSetContent',
  11652. 'onGetContent',
  11653. 'onLoadContent',
  11654. 'onSaveContent',
  11655. 'onNodeChange',
  11656. 'onChange',
  11657. 'onBeforeExecCommand',
  11658. 'onExecCommand',
  11659. 'onUndo',
  11660. 'onRedo',
  11661. 'onVisualAid',
  11662. 'onSetProgressState',
  11663. 'onSetAttrib'
  11664. ], function(name) {
  11665. self[name] = new tinymce.util.Dispatcher(self);
  11666. });
  11667. // Handle legacy cleanup_callback option
  11668. if (settings.cleanup_callback) {
  11669. self.onBeforeSetContent.add(function(ed, o) {
  11670. o.content = ed.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  11671. });
  11672. self.onPreProcess.add(function(ed, o) {
  11673. if (o.set)
  11674. ed.execCallback('cleanup_callback', 'insert_to_editor_dom', o.node, o);
  11675. if (o.get)
  11676. ed.execCallback('cleanup_callback', 'get_from_editor_dom', o.node, o);
  11677. });
  11678. self.onPostProcess.add(function(ed, o) {
  11679. if (o.set)
  11680. o.content = ed.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  11681. if (o.get)
  11682. o.content = ed.execCallback('cleanup_callback', 'get_from_editor', o.content, o);
  11683. });
  11684. }
  11685. // Handle legacy save_callback option
  11686. if (settings.save_callback) {
  11687. self.onGetContent.add(function(ed, o) {
  11688. if (o.save)
  11689. o.content = ed.execCallback('save_callback', ed.id, o.content, ed.getBody());
  11690. });
  11691. }
  11692. // Handle legacy handle_event_callback option
  11693. if (settings.handle_event_callback) {
  11694. self.onEvent.add(function(ed, e, o) {
  11695. if (self.execCallback('handle_event_callback', e, ed, o) === false) {
  11696. e.preventDefault();
  11697. e.stopPropagation();
  11698. }
  11699. });
  11700. }
  11701. // Handle legacy handle_node_change_callback option
  11702. if (settings.handle_node_change_callback) {
  11703. self.onNodeChange.add(function(ed, cm, n) {
  11704. ed.execCallback('handle_node_change_callback', ed.id, n, -1, -1, true, ed.selection.isCollapsed());
  11705. });
  11706. }
  11707. // Handle legacy save_callback option
  11708. if (settings.save_callback) {
  11709. self.onSaveContent.add(function(ed, o) {
  11710. var h = ed.execCallback('save_callback', ed.id, o.content, ed.getBody());
  11711. if (h)
  11712. o.content = h;
  11713. });
  11714. }
  11715. // Handle legacy onchange_callback option
  11716. if (settings.onchange_callback) {
  11717. self.onChange.add(function(ed, l) {
  11718. ed.execCallback('onchange_callback', ed, l);
  11719. });
  11720. }
  11721. };
  11722. tinymce.Editor.prototype.bindNativeEvents = function() {
  11723. // 'focus', 'blur', 'dblclick', 'beforedeactivate', submit, reset
  11724. var self = this, i, settings = self.settings, dom = self.dom, nativeToDispatcherMap;
  11725. nativeToDispatcherMap = {
  11726. mouseup : 'onMouseUp',
  11727. mousedown : 'onMouseDown',
  11728. click : 'onClick',
  11729. keyup : 'onKeyUp',
  11730. keydown : 'onKeyDown',
  11731. keypress : 'onKeyPress',
  11732. submit : 'onSubmit',
  11733. reset : 'onReset',
  11734. contextmenu : 'onContextMenu',
  11735. dblclick : 'onDblClick',
  11736. paste : 'onPaste' // Doesn't work in all browsers yet
  11737. };
  11738. // Handler that takes a native event and sends it out to a dispatcher like onKeyDown
  11739. function eventHandler(evt, args) {
  11740. var type = evt.type;
  11741. // Don't fire events when it's removed
  11742. if (self.removed)
  11743. return;
  11744. // Sends the native event out to a global dispatcher then to the specific event dispatcher
  11745. if (self.onEvent.dispatch(self, evt, args) !== false) {
  11746. self[nativeToDispatcherMap[evt.fakeType || evt.type]].dispatch(self, evt, args);
  11747. }
  11748. };
  11749. // Opera doesn't support focus event for contentEditable elements so we need to fake it
  11750. function doOperaFocus(e) {
  11751. self.focus(true);
  11752. };
  11753. function nodeChanged(ed, e) {
  11754. // Normalize selection for example <b>a</b><i>|a</i> becomes <b>a|</b><i>a</i> except for Ctrl+A since it selects everything
  11755. if (e.keyCode != 65 || !tinymce.VK.metaKeyPressed(e)) {
  11756. self.selection.normalize();
  11757. }
  11758. self.nodeChanged();
  11759. }
  11760. // Add DOM events
  11761. each(nativeToDispatcherMap, function(dispatcherName, nativeName) {
  11762. var root = settings.content_editable ? self.getBody() : self.getDoc();
  11763. switch (nativeName) {
  11764. case 'contextmenu':
  11765. dom.bind(root, nativeName, eventHandler);
  11766. break;
  11767. case 'paste':
  11768. dom.bind(self.getBody(), nativeName, eventHandler);
  11769. break;
  11770. case 'submit':
  11771. case 'reset':
  11772. dom.bind(self.getElement().form || tinymce.DOM.getParent(self.id, 'form'), nativeName, eventHandler);
  11773. break;
  11774. default:
  11775. dom.bind(root, nativeName, eventHandler);
  11776. }
  11777. });
  11778. // Set the editor as active when focused
  11779. dom.bind(settings.content_editable ? self.getBody() : (tinymce.isGecko ? self.getDoc() : self.getWin()), 'focus', function(e) {
  11780. self.focus(true);
  11781. });
  11782. if (settings.content_editable && tinymce.isOpera) {
  11783. dom.bind(self.getBody(), 'click', doOperaFocus);
  11784. dom.bind(self.getBody(), 'keydown', doOperaFocus);
  11785. }
  11786. // Add node change handler
  11787. self.onMouseUp.add(nodeChanged);
  11788. self.onKeyUp.add(function(ed, e) {
  11789. var keyCode = e.keyCode;
  11790. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 13 || keyCode == 45 || keyCode == 46 || keyCode == 8 || (tinymce.isMac && (keyCode == 91 || keyCode == 93)) || e.ctrlKey)
  11791. nodeChanged(ed, e);
  11792. });
  11793. // Add reset handler
  11794. self.onReset.add(function() {
  11795. self.setContent(self.startContent, {format : 'raw'});
  11796. });
  11797. // Add shortcuts
  11798. function handleShortcut(e, execute) {
  11799. if (e.altKey || e.ctrlKey || e.metaKey) {
  11800. each(self.shortcuts, function(shortcut) {
  11801. var ctrlState = tinymce.isMac ? e.metaKey : e.ctrlKey;
  11802. if (shortcut.ctrl != ctrlState || shortcut.alt != e.altKey || shortcut.shift != e.shiftKey)
  11803. return;
  11804. if (e.keyCode == shortcut.keyCode || (e.charCode && e.charCode == shortcut.charCode)) {
  11805. e.preventDefault();
  11806. if (execute) {
  11807. shortcut.func.call(shortcut.scope);
  11808. }
  11809. return true;
  11810. }
  11811. });
  11812. }
  11813. };
  11814. self.onKeyUp.add(function(ed, e) {
  11815. handleShortcut(e);
  11816. });
  11817. self.onKeyPress.add(function(ed, e) {
  11818. handleShortcut(e);
  11819. });
  11820. self.onKeyDown.add(function(ed, e) {
  11821. handleShortcut(e, true);
  11822. });
  11823. if (tinymce.isOpera) {
  11824. self.onClick.add(function(ed, e) {
  11825. e.preventDefault();
  11826. });
  11827. }
  11828. };
  11829. })(tinymce);
  11830. (function(tinymce) {
  11831. // Added for compression purposes
  11832. var each = tinymce.each, undef, TRUE = true, FALSE = false;
  11833. tinymce.EditorCommands = function(editor) {
  11834. var dom = editor.dom,
  11835. selection = editor.selection,
  11836. commands = {state: {}, exec : {}, value : {}},
  11837. settings = editor.settings,
  11838. formatter = editor.formatter,
  11839. bookmark;
  11840. function execCommand(command, ui, value) {
  11841. var func;
  11842. command = command.toLowerCase();
  11843. if (func = commands.exec[command]) {
  11844. func(command, ui, value);
  11845. return TRUE;
  11846. }
  11847. return FALSE;
  11848. };
  11849. function queryCommandState(command) {
  11850. var func;
  11851. command = command.toLowerCase();
  11852. if (func = commands.state[command])
  11853. return func(command);
  11854. return -1;
  11855. };
  11856. function queryCommandValue(command) {
  11857. var func;
  11858. command = command.toLowerCase();
  11859. if (func = commands.value[command])
  11860. return func(command);
  11861. return FALSE;
  11862. };
  11863. function addCommands(command_list, type) {
  11864. type = type || 'exec';
  11865. each(command_list, function(callback, command) {
  11866. each(command.toLowerCase().split(','), function(command) {
  11867. commands[type][command] = callback;
  11868. });
  11869. });
  11870. };
  11871. // Expose public methods
  11872. tinymce.extend(this, {
  11873. execCommand : execCommand,
  11874. queryCommandState : queryCommandState,
  11875. queryCommandValue : queryCommandValue,
  11876. addCommands : addCommands
  11877. });
  11878. // Private methods
  11879. function execNativeCommand(command, ui, value) {
  11880. if (ui === undef)
  11881. ui = FALSE;
  11882. if (value === undef)
  11883. value = null;
  11884. return editor.getDoc().execCommand(command, ui, value);
  11885. };
  11886. function isFormatMatch(name) {
  11887. return formatter.match(name);
  11888. };
  11889. function toggleFormat(name, value) {
  11890. formatter.toggle(name, value ? {value : value} : undef);
  11891. };
  11892. function storeSelection(type) {
  11893. bookmark = selection.getBookmark(type);
  11894. };
  11895. function restoreSelection() {
  11896. selection.moveToBookmark(bookmark);
  11897. };
  11898. // Add execCommand overrides
  11899. addCommands({
  11900. // Ignore these, added for compatibility
  11901. 'mceResetDesignMode,mceBeginUndoLevel' : function() {},
  11902. // Add undo manager logic
  11903. 'mceEndUndoLevel,mceAddUndoLevel' : function() {
  11904. editor.undoManager.add();
  11905. },
  11906. 'Cut,Copy,Paste' : function(command) {
  11907. var doc = editor.getDoc(), failed;
  11908. // Try executing the native command
  11909. try {
  11910. execNativeCommand(command);
  11911. } catch (ex) {
  11912. // Command failed
  11913. failed = TRUE;
  11914. }
  11915. // Present alert message about clipboard access not being available
  11916. if (failed || !doc.queryCommandSupported(command)) {
  11917. if (tinymce.isGecko) {
  11918. editor.windowManager.confirm(editor.getLang('clipboard_msg'), function(state) {
  11919. if (state)
  11920. open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', '_blank');
  11921. });
  11922. } else
  11923. editor.windowManager.alert(editor.getLang('clipboard_no_support'));
  11924. }
  11925. },
  11926. // Override unlink command
  11927. unlink : function(command) {
  11928. if (selection.isCollapsed())
  11929. selection.select(selection.getNode());
  11930. execNativeCommand(command);
  11931. selection.collapse(FALSE);
  11932. },
  11933. // Override justify commands to use the text formatter engine
  11934. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  11935. var align = command.substring(7);
  11936. // Remove all other alignments first
  11937. each('left,center,right,full'.split(','), function(name) {
  11938. if (align != name)
  11939. formatter.remove('align' + name);
  11940. });
  11941. toggleFormat('align' + align);
  11942. execCommand('mceRepaint');
  11943. },
  11944. // Override list commands to fix WebKit bug
  11945. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  11946. var listElm, listParent;
  11947. execNativeCommand(command);
  11948. // WebKit produces lists within block elements so we need to split them
  11949. // we will replace the native list creation logic to custom logic later on
  11950. // TODO: Remove this when the list creation logic is removed
  11951. listElm = dom.getParent(selection.getNode(), 'ol,ul');
  11952. if (listElm) {
  11953. listParent = listElm.parentNode;
  11954. // If list is within a text block then split that block
  11955. if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) {
  11956. storeSelection();
  11957. dom.split(listParent, listElm);
  11958. restoreSelection();
  11959. }
  11960. }
  11961. },
  11962. // Override commands to use the text formatter engine
  11963. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
  11964. toggleFormat(command);
  11965. },
  11966. // Override commands to use the text formatter engine
  11967. 'ForeColor,HiliteColor,FontName' : function(command, ui, value) {
  11968. toggleFormat(command, value);
  11969. },
  11970. FontSize : function(command, ui, value) {
  11971. var fontClasses, fontSizes;
  11972. // Convert font size 1-7 to styles
  11973. if (value >= 1 && value <= 7) {
  11974. fontSizes = tinymce.explode(settings.font_size_style_values);
  11975. fontClasses = tinymce.explode(settings.font_size_classes);
  11976. if (fontClasses)
  11977. value = fontClasses[value - 1] || value;
  11978. else
  11979. value = fontSizes[value - 1] || value;
  11980. }
  11981. toggleFormat(command, value);
  11982. },
  11983. RemoveFormat : function(command) {
  11984. formatter.remove(command);
  11985. },
  11986. mceBlockQuote : function(command) {
  11987. toggleFormat('blockquote');
  11988. },
  11989. FormatBlock : function(command, ui, value) {
  11990. return toggleFormat(value || 'p');
  11991. },
  11992. mceCleanup : function() {
  11993. var bookmark = selection.getBookmark();
  11994. editor.setContent(editor.getContent({cleanup : TRUE}), {cleanup : TRUE});
  11995. selection.moveToBookmark(bookmark);
  11996. },
  11997. mceRemoveNode : function(command, ui, value) {
  11998. var node = value || selection.getNode();
  11999. // Make sure that the body node isn't removed
  12000. if (node != editor.getBody()) {
  12001. storeSelection();
  12002. editor.dom.remove(node, TRUE);
  12003. restoreSelection();
  12004. }
  12005. },
  12006. mceSelectNodeDepth : function(command, ui, value) {
  12007. var counter = 0;
  12008. dom.getParent(selection.getNode(), function(node) {
  12009. if (node.nodeType == 1 && counter++ == value) {
  12010. selection.select(node);
  12011. return FALSE;
  12012. }
  12013. }, editor.getBody());
  12014. },
  12015. mceSelectNode : function(command, ui, value) {
  12016. selection.select(value);
  12017. },
  12018. mceInsertContent : function(command, ui, value) {
  12019. var parser, serializer, parentNode, rootNode, fragment, args,
  12020. marker, nodeRect, viewPortRect, rng, node, node2, bookmarkHtml, viewportBodyElement;
  12021. //selection.normalize();
  12022. // Setup parser and serializer
  12023. parser = editor.parser;
  12024. serializer = new tinymce.html.Serializer({}, editor.schema);
  12025. bookmarkHtml = '<span id="mce_marker" data-mce-type="bookmark">\uFEFF</span>';
  12026. // Run beforeSetContent handlers on the HTML to be inserted
  12027. args = {content: value, format: 'html'};
  12028. selection.onBeforeSetContent.dispatch(selection, args);
  12029. value = args.content;
  12030. // Add caret at end of contents if it's missing
  12031. if (value.indexOf('{$caret}') == -1)
  12032. value += '{$caret}';
  12033. // Replace the caret marker with a span bookmark element
  12034. value = value.replace(/\{\$caret\}/, bookmarkHtml);
  12035. // Insert node maker where we will insert the new HTML and get it's parent
  12036. if (!selection.isCollapsed())
  12037. editor.getDoc().execCommand('Delete', false, null);
  12038. parentNode = selection.getNode();
  12039. // Parse the fragment within the context of the parent node
  12040. args = {context : parentNode.nodeName.toLowerCase()};
  12041. fragment = parser.parse(value, args);
  12042. // Move the caret to a more suitable location
  12043. node = fragment.lastChild;
  12044. if (node.attr('id') == 'mce_marker') {
  12045. marker = node;
  12046. for (node = node.prev; node; node = node.walk(true)) {
  12047. if (node.type == 3 || !dom.isBlock(node.name)) {
  12048. node.parent.insert(marker, node, node.name === 'br');
  12049. break;
  12050. }
  12051. }
  12052. }
  12053. // If parser says valid we can insert the contents into that parent
  12054. if (!args.invalid) {
  12055. value = serializer.serialize(fragment);
  12056. // Check if parent is empty or only has one BR element then set the innerHTML of that parent
  12057. node = parentNode.firstChild;
  12058. node2 = parentNode.lastChild;
  12059. if (!node || (node === node2 && node.nodeName === 'BR'))
  12060. dom.setHTML(parentNode, value);
  12061. else
  12062. selection.setContent(value);
  12063. } else {
  12064. // If the fragment was invalid within that context then we need
  12065. // to parse and process the parent it's inserted into
  12066. // Insert bookmark node and get the parent
  12067. selection.setContent(bookmarkHtml);
  12068. parentNode = selection.getNode();
  12069. rootNode = editor.getBody();
  12070. // Opera will return the document node when selection is in root
  12071. if (parentNode.nodeType == 9)
  12072. parentNode = node = rootNode;
  12073. else
  12074. node = parentNode;
  12075. // Find the ancestor just before the root element
  12076. while (node !== rootNode) {
  12077. parentNode = node;
  12078. node = node.parentNode;
  12079. }
  12080. // Get the outer/inner HTML depending on if we are in the root and parser and serialize that
  12081. value = parentNode == rootNode ? rootNode.innerHTML : dom.getOuterHTML(parentNode);
  12082. value = serializer.serialize(
  12083. parser.parse(
  12084. // Need to replace by using a function since $ in the contents would otherwise be a problem
  12085. value.replace(/<span (id="mce_marker"|id=mce_marker).+?<\/span>/i, function() {
  12086. return serializer.serialize(fragment);
  12087. })
  12088. )
  12089. );
  12090. // Set the inner/outer HTML depending on if we are in the root or not
  12091. if (parentNode == rootNode)
  12092. dom.setHTML(rootNode, value);
  12093. else
  12094. dom.setOuterHTML(parentNode, value);
  12095. }
  12096. marker = dom.get('mce_marker');
  12097. // Scroll range into view scrollIntoView on element can't be used since it will scroll the main view port as well
  12098. nodeRect = dom.getRect(marker);
  12099. viewPortRect = dom.getViewPort(editor.getWin());
  12100. // Check if node is out side the viewport if it is then scroll to it
  12101. if ((nodeRect.y + nodeRect.h > viewPortRect.y + viewPortRect.h || nodeRect.y < viewPortRect.y) ||
  12102. (nodeRect.x > viewPortRect.x + viewPortRect.w || nodeRect.x < viewPortRect.x)) {
  12103. viewportBodyElement = tinymce.isIE ? editor.getDoc().documentElement : editor.getBody();
  12104. viewportBodyElement.scrollLeft = nodeRect.x;
  12105. viewportBodyElement.scrollTop = nodeRect.y - viewPortRect.h + 25;
  12106. }
  12107. // Move selection before marker and remove it
  12108. rng = dom.createRng();
  12109. // If previous sibling is a text node set the selection to the end of that node
  12110. node = marker.previousSibling;
  12111. if (node && node.nodeType == 3) {
  12112. rng.setStart(node, node.nodeValue.length);
  12113. } else {
  12114. // If the previous sibling isn't a text node or doesn't exist set the selection before the marker node
  12115. rng.setStartBefore(marker);
  12116. rng.setEndBefore(marker);
  12117. }
  12118. // Remove the marker node and set the new range
  12119. dom.remove(marker);
  12120. selection.setRng(rng);
  12121. // Dispatch after event and add any visual elements needed
  12122. selection.onSetContent.dispatch(selection, args);
  12123. editor.addVisual();
  12124. },
  12125. mceInsertRawHTML : function(command, ui, value) {
  12126. selection.setContent('tiny_mce_marker');
  12127. editor.setContent(editor.getContent().replace(/tiny_mce_marker/g, function() { return value }));
  12128. },
  12129. mceToggleFormat : function(command, ui, value) {
  12130. toggleFormat(value);
  12131. },
  12132. mceSetContent : function(command, ui, value) {
  12133. editor.setContent(value);
  12134. },
  12135. 'Indent,Outdent' : function(command) {
  12136. var intentValue, indentUnit, value;
  12137. // Setup indent level
  12138. intentValue = settings.indentation;
  12139. indentUnit = /[a-z%]+$/i.exec(intentValue);
  12140. intentValue = parseInt(intentValue);
  12141. if (!queryCommandState('InsertUnorderedList') && !queryCommandState('InsertOrderedList')) {
  12142. // If forced_root_blocks is set to false we don't have a block to indent so lets create a div
  12143. if (!settings.forced_root_block && !dom.getParent(selection.getNode(), dom.isBlock)) {
  12144. formatter.apply('div');
  12145. }
  12146. each(selection.getSelectedBlocks(), function(element) {
  12147. if (command == 'outdent') {
  12148. value = Math.max(0, parseInt(element.style.paddingLeft || 0) - intentValue);
  12149. dom.setStyle(element, 'paddingLeft', value ? value + indentUnit : '');
  12150. } else
  12151. dom.setStyle(element, 'paddingLeft', (parseInt(element.style.paddingLeft || 0) + intentValue) + indentUnit);
  12152. });
  12153. } else
  12154. execNativeCommand(command);
  12155. },
  12156. mceRepaint : function() {
  12157. var bookmark;
  12158. if (tinymce.isGecko) {
  12159. try {
  12160. storeSelection(TRUE);
  12161. if (selection.getSel())
  12162. selection.getSel().selectAllChildren(editor.getBody());
  12163. selection.collapse(TRUE);
  12164. restoreSelection();
  12165. } catch (ex) {
  12166. // Ignore
  12167. }
  12168. }
  12169. },
  12170. mceToggleFormat : function(command, ui, value) {
  12171. formatter.toggle(value);
  12172. },
  12173. InsertHorizontalRule : function() {
  12174. editor.execCommand('mceInsertContent', false, '<hr />');
  12175. },
  12176. mceToggleVisualAid : function() {
  12177. editor.hasVisual = !editor.hasVisual;
  12178. editor.addVisual();
  12179. },
  12180. mceReplaceContent : function(command, ui, value) {
  12181. editor.execCommand('mceInsertContent', false, value.replace(/\{\$selection\}/g, selection.getContent({format : 'text'})));
  12182. },
  12183. mceInsertLink : function(command, ui, value) {
  12184. var anchor;
  12185. if (typeof(value) == 'string')
  12186. value = {href : value};
  12187. anchor = dom.getParent(selection.getNode(), 'a');
  12188. // Spaces are never valid in URLs and it's a very common mistake for people to make so we fix it here.
  12189. value.href = value.href.replace(' ', '%20');
  12190. // Remove existing links if there could be child links or that the href isn't specified
  12191. if (!anchor || !value.href) {
  12192. formatter.remove('link');
  12193. }
  12194. // Apply new link to selection
  12195. if (value.href) {
  12196. formatter.apply('link', value, anchor);
  12197. }
  12198. },
  12199. selectAll : function() {
  12200. var root = dom.getRoot(), rng = dom.createRng();
  12201. // Old IE does a better job with selectall than new versions
  12202. if (selection.getRng().setStart) {
  12203. rng.setStart(root, 0);
  12204. rng.setEnd(root, root.childNodes.length);
  12205. selection.setRng(rng);
  12206. } else {
  12207. execNativeCommand('SelectAll');
  12208. }
  12209. }
  12210. });
  12211. // Add queryCommandState overrides
  12212. addCommands({
  12213. // Override justify commands
  12214. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  12215. var name = 'align' + command.substring(7);
  12216. var nodes = selection.isCollapsed() ? [dom.getParent(selection.getNode(), dom.isBlock)] : selection.getSelectedBlocks();
  12217. var matches = tinymce.map(nodes, function(node) {
  12218. return !!formatter.matchNode(node, name);
  12219. });
  12220. return tinymce.inArray(matches, TRUE) !== -1;
  12221. },
  12222. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
  12223. return isFormatMatch(command);
  12224. },
  12225. mceBlockQuote : function() {
  12226. return isFormatMatch('blockquote');
  12227. },
  12228. Outdent : function() {
  12229. var node;
  12230. if (settings.inline_styles) {
  12231. if ((node = dom.getParent(selection.getStart(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  12232. return TRUE;
  12233. if ((node = dom.getParent(selection.getEnd(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  12234. return TRUE;
  12235. }
  12236. return queryCommandState('InsertUnorderedList') || queryCommandState('InsertOrderedList') || (!settings.inline_styles && !!dom.getParent(selection.getNode(), 'BLOCKQUOTE'));
  12237. },
  12238. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  12239. var list = dom.getParent(selection.getNode(), 'ul,ol');
  12240. return list &&
  12241. (command === 'insertunorderedlist' && list.tagName === 'UL'
  12242. || command === 'insertorderedlist' && list.tagName === 'OL');
  12243. }
  12244. }, 'state');
  12245. // Add queryCommandValue overrides
  12246. addCommands({
  12247. 'FontSize,FontName' : function(command) {
  12248. var value = 0, parent;
  12249. if (parent = dom.getParent(selection.getNode(), 'span')) {
  12250. if (command == 'fontsize')
  12251. value = parent.style.fontSize;
  12252. else
  12253. value = parent.style.fontFamily.replace(/, /g, ',').replace(/[\'\"]/g, '').toLowerCase();
  12254. }
  12255. return value;
  12256. }
  12257. }, 'value');
  12258. // Add undo manager logic
  12259. addCommands({
  12260. Undo : function() {
  12261. editor.undoManager.undo();
  12262. },
  12263. Redo : function() {
  12264. editor.undoManager.redo();
  12265. }
  12266. });
  12267. };
  12268. })(tinymce);
  12269. (function(tinymce) {
  12270. var Dispatcher = tinymce.util.Dispatcher;
  12271. tinymce.UndoManager = function(editor) {
  12272. var self, index = 0, data = [], beforeBookmark, onAdd, onUndo, onRedo;
  12273. function getContent() {
  12274. // Remove whitespace before/after and remove pure bogus nodes
  12275. return tinymce.trim(editor.getContent({format : 'raw', no_events : 1}).replace(/<span[^>]+data-mce-bogus[^>]+>[\u200B\uFEFF]+<\/span>/g, ''));
  12276. };
  12277. function addNonTypingUndoLevel() {
  12278. self.typing = false;
  12279. self.add();
  12280. };
  12281. // Create event instances
  12282. onBeforeAdd = new Dispatcher(self);
  12283. onAdd = new Dispatcher(self);
  12284. onUndo = new Dispatcher(self);
  12285. onRedo = new Dispatcher(self);
  12286. // Pass though onAdd event from UndoManager to Editor as onChange
  12287. onAdd.add(function(undoman, level) {
  12288. if (undoman.hasUndo())
  12289. return editor.onChange.dispatch(editor, level, undoman);
  12290. });
  12291. // Pass though onUndo event from UndoManager to Editor
  12292. onUndo.add(function(undoman, level) {
  12293. return editor.onUndo.dispatch(editor, level, undoman);
  12294. });
  12295. // Pass though onRedo event from UndoManager to Editor
  12296. onRedo.add(function(undoman, level) {
  12297. return editor.onRedo.dispatch(editor, level, undoman);
  12298. });
  12299. // Add initial undo level when the editor is initialized
  12300. editor.onInit.add(function() {
  12301. self.add();
  12302. });
  12303. // Get position before an execCommand is processed
  12304. editor.onBeforeExecCommand.add(function(ed, cmd, ui, val, args) {
  12305. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!args || !args.skip_undo)) {
  12306. self.beforeChange();
  12307. }
  12308. });
  12309. // Add undo level after an execCommand call was made
  12310. editor.onExecCommand.add(function(ed, cmd, ui, val, args) {
  12311. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!args || !args.skip_undo)) {
  12312. self.add();
  12313. }
  12314. });
  12315. // Add undo level on save contents, drag end and blur/focusout
  12316. editor.onSaveContent.add(addNonTypingUndoLevel);
  12317. editor.dom.bind(editor.dom.getRoot(), 'dragend', addNonTypingUndoLevel);
  12318. editor.dom.bind(editor.getBody(), 'focusout', function(e) {
  12319. if (!editor.removed && self.typing) {
  12320. addNonTypingUndoLevel();
  12321. }
  12322. });
  12323. editor.onKeyUp.add(function(editor, e) {
  12324. var keyCode = e.keyCode;
  12325. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 45 || keyCode == 13 || e.ctrlKey) {
  12326. addNonTypingUndoLevel();
  12327. }
  12328. });
  12329. editor.onKeyDown.add(function(editor, e) {
  12330. var keyCode = e.keyCode;
  12331. // Is caracter positon keys left,right,up,down,home,end,pgdown,pgup,enter
  12332. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 45) {
  12333. if (self.typing) {
  12334. addNonTypingUndoLevel();
  12335. }
  12336. return;
  12337. }
  12338. // If key isn't shift,ctrl,alt,capslock,metakey
  12339. if ((keyCode < 16 || keyCode > 20) && keyCode != 224 && keyCode != 91 && !self.typing) {
  12340. self.beforeChange();
  12341. self.typing = true;
  12342. self.add();
  12343. }
  12344. });
  12345. editor.onMouseDown.add(function(editor, e) {
  12346. if (self.typing) {
  12347. addNonTypingUndoLevel();
  12348. }
  12349. });
  12350. // Add keyboard shortcuts for undo/redo keys
  12351. editor.addShortcut('ctrl+z', 'undo_desc', 'Undo');
  12352. editor.addShortcut('ctrl+y', 'redo_desc', 'Redo');
  12353. self = {
  12354. // Explose for debugging reasons
  12355. data : data,
  12356. typing : false,
  12357. onBeforeAdd: onBeforeAdd,
  12358. onAdd : onAdd,
  12359. onUndo : onUndo,
  12360. onRedo : onRedo,
  12361. beforeChange : function() {
  12362. beforeBookmark = editor.selection.getBookmark(2, true);
  12363. },
  12364. add : function(level) {
  12365. var i, settings = editor.settings, lastLevel;
  12366. level = level || {};
  12367. level.content = getContent();
  12368. self.onBeforeAdd.dispatch(self, level);
  12369. // Add undo level if needed
  12370. lastLevel = data[index];
  12371. if (lastLevel && lastLevel.content == level.content)
  12372. return null;
  12373. // Set before bookmark on previous level
  12374. if (data[index])
  12375. data[index].beforeBookmark = beforeBookmark;
  12376. // Time to compress
  12377. if (settings.custom_undo_redo_levels) {
  12378. if (data.length > settings.custom_undo_redo_levels) {
  12379. for (i = 0; i < data.length - 1; i++)
  12380. data[i] = data[i + 1];
  12381. data.length--;
  12382. index = data.length;
  12383. }
  12384. }
  12385. // Get a non intrusive normalized bookmark
  12386. level.bookmark = editor.selection.getBookmark(2, true);
  12387. // Crop array if needed
  12388. if (index < data.length - 1)
  12389. data.length = index + 1;
  12390. data.push(level);
  12391. index = data.length - 1;
  12392. self.onAdd.dispatch(self, level);
  12393. editor.isNotDirty = 0;
  12394. return level;
  12395. },
  12396. undo : function() {
  12397. var level, i;
  12398. if (self.typing) {
  12399. self.add();
  12400. self.typing = false;
  12401. }
  12402. if (index > 0) {
  12403. level = data[--index];
  12404. editor.setContent(level.content, {format : 'raw'});
  12405. editor.selection.moveToBookmark(level.beforeBookmark);
  12406. self.onUndo.dispatch(self, level);
  12407. }
  12408. return level;
  12409. },
  12410. redo : function() {
  12411. var level;
  12412. if (index < data.length - 1) {
  12413. level = data[++index];
  12414. editor.setContent(level.content, {format : 'raw'});
  12415. editor.selection.moveToBookmark(level.bookmark);
  12416. self.onRedo.dispatch(self, level);
  12417. }
  12418. return level;
  12419. },
  12420. clear : function() {
  12421. data = [];
  12422. index = 0;
  12423. self.typing = false;
  12424. },
  12425. hasUndo : function() {
  12426. return index > 0 || this.typing;
  12427. },
  12428. hasRedo : function() {
  12429. return index < data.length - 1 && !this.typing;
  12430. }
  12431. };
  12432. return self;
  12433. };
  12434. })(tinymce);
  12435. tinymce.ForceBlocks = function(editor) {
  12436. var settings = editor.settings, dom = editor.dom, selection = editor.selection, blockElements = editor.schema.getBlockElements();
  12437. function addRootBlocks() {
  12438. var node = selection.getStart(), rootNode = editor.getBody(), rng, startContainer, startOffset, endContainer, endOffset, rootBlockNode, tempNode, offset = -0xFFFFFF, wrapped, isInEditorDocument;
  12439. if (!node || node.nodeType !== 1 || !settings.forced_root_block)
  12440. return;
  12441. // Check if node is wrapped in block
  12442. while (node && node != rootNode) {
  12443. if (blockElements[node.nodeName])
  12444. return;
  12445. node = node.parentNode;
  12446. }
  12447. // Get current selection
  12448. rng = selection.getRng();
  12449. if (rng.setStart) {
  12450. startContainer = rng.startContainer;
  12451. startOffset = rng.startOffset;
  12452. endContainer = rng.endContainer;
  12453. endOffset = rng.endOffset;
  12454. } else {
  12455. // Force control range into text range
  12456. if (rng.item) {
  12457. node = rng.item(0);
  12458. rng = editor.getDoc().body.createTextRange();
  12459. rng.moveToElementText(node);
  12460. }
  12461. isInEditorDocument = rng.parentElement().ownerDocument === editor.getDoc();
  12462. tmpRng = rng.duplicate();
  12463. tmpRng.collapse(true);
  12464. startOffset = tmpRng.move('character', offset) * -1;
  12465. if (!tmpRng.collapsed) {
  12466. tmpRng = rng.duplicate();
  12467. tmpRng.collapse(false);
  12468. endOffset = (tmpRng.move('character', offset) * -1) - startOffset;
  12469. }
  12470. }
  12471. // Wrap non block elements and text nodes
  12472. node = rootNode.firstChild;
  12473. while (node) {
  12474. if (node.nodeType === 3 || (node.nodeType == 1 && !blockElements[node.nodeName])) {
  12475. // Remove empty text nodes
  12476. if (node.nodeType === 3 && node.nodeValue.length == 0) {
  12477. tempNode = node;
  12478. node = node.nextSibling;
  12479. dom.remove(tempNode);
  12480. continue;
  12481. }
  12482. if (!rootBlockNode) {
  12483. rootBlockNode = dom.create(settings.forced_root_block);
  12484. node.parentNode.insertBefore(rootBlockNode, node);
  12485. wrapped = true;
  12486. }
  12487. tempNode = node;
  12488. node = node.nextSibling;
  12489. rootBlockNode.appendChild(tempNode);
  12490. } else {
  12491. rootBlockNode = null;
  12492. node = node.nextSibling;
  12493. }
  12494. }
  12495. if (wrapped) {
  12496. if (rng.setStart) {
  12497. rng.setStart(startContainer, startOffset);
  12498. rng.setEnd(endContainer, endOffset);
  12499. selection.setRng(rng);
  12500. } else {
  12501. // Only select if the previous selection was inside the document to prevent auto focus in quirks mode
  12502. if (isInEditorDocument) {
  12503. try {
  12504. rng = editor.getDoc().body.createTextRange();
  12505. rng.moveToElementText(rootNode);
  12506. rng.collapse(true);
  12507. rng.moveStart('character', startOffset);
  12508. if (endOffset > 0)
  12509. rng.moveEnd('character', endOffset);
  12510. rng.select();
  12511. } catch (ex) {
  12512. // Ignore
  12513. }
  12514. }
  12515. }
  12516. editor.nodeChanged();
  12517. }
  12518. };
  12519. // Force root blocks
  12520. if (settings.forced_root_block) {
  12521. editor.onKeyUp.add(addRootBlocks);
  12522. editor.onNodeChange.add(addRootBlocks);
  12523. }
  12524. };
  12525. (function(tinymce) {
  12526. // Shorten names
  12527. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, extend = tinymce.extend;
  12528. tinymce.create('tinymce.ControlManager', {
  12529. ControlManager : function(ed, s) {
  12530. var t = this, i;
  12531. s = s || {};
  12532. t.editor = ed;
  12533. t.controls = {};
  12534. t.onAdd = new tinymce.util.Dispatcher(t);
  12535. t.onPostRender = new tinymce.util.Dispatcher(t);
  12536. t.prefix = s.prefix || ed.id + '_';
  12537. t._cls = {};
  12538. t.onPostRender.add(function() {
  12539. each(t.controls, function(c) {
  12540. c.postRender();
  12541. });
  12542. });
  12543. },
  12544. get : function(id) {
  12545. return this.controls[this.prefix + id] || this.controls[id];
  12546. },
  12547. setActive : function(id, s) {
  12548. var c = null;
  12549. if (c = this.get(id))
  12550. c.setActive(s);
  12551. return c;
  12552. },
  12553. setDisabled : function(id, s) {
  12554. var c = null;
  12555. if (c = this.get(id))
  12556. c.setDisabled(s);
  12557. return c;
  12558. },
  12559. add : function(c) {
  12560. var t = this;
  12561. if (c) {
  12562. t.controls[c.id] = c;
  12563. t.onAdd.dispatch(c, t);
  12564. }
  12565. return c;
  12566. },
  12567. createControl : function(name) {
  12568. var ctrl, i, l, self = this, editor = self.editor, factories, ctrlName;
  12569. // Build control factory cache
  12570. if (!self.controlFactories) {
  12571. self.controlFactories = [];
  12572. each(editor.plugins, function(plugin) {
  12573. if (plugin.createControl) {
  12574. self.controlFactories.push(plugin);
  12575. }
  12576. });
  12577. }
  12578. // Create controls by asking cached factories
  12579. factories = self.controlFactories;
  12580. for (i = 0, l = factories.length; i < l; i++) {
  12581. ctrl = factories[i].createControl(name, self);
  12582. if (ctrl) {
  12583. return self.add(ctrl);
  12584. }
  12585. }
  12586. // Create sepearator
  12587. if (name === "|" || name === "separator") {
  12588. return self.createSeparator();
  12589. }
  12590. // Create control from button collection
  12591. if (editor.buttons && (ctrl = editor.buttons[name])) {
  12592. return self.createButton(name, ctrl);
  12593. }
  12594. return self.add(ctrl);
  12595. },
  12596. createDropMenu : function(id, s, cc) {
  12597. var t = this, ed = t.editor, c, bm, v, cls;
  12598. s = extend({
  12599. 'class' : 'mceDropDown',
  12600. constrain : ed.settings.constrain_menus
  12601. }, s);
  12602. s['class'] = s['class'] + ' ' + ed.getParam('skin') + 'Skin';
  12603. if (v = ed.getParam('skin_variant'))
  12604. s['class'] += ' ' + ed.getParam('skin') + 'Skin' + v.substring(0, 1).toUpperCase() + v.substring(1);
  12605. s['class'] += ed.settings.directionality == "rtl" ? ' mceRtl' : '';
  12606. id = t.prefix + id;
  12607. cls = cc || t._cls.dropmenu || tinymce.ui.DropMenu;
  12608. c = t.controls[id] = new cls(id, s);
  12609. c.onAddItem.add(function(c, o) {
  12610. var s = o.settings;
  12611. s.title = ed.getLang(s.title, s.title);
  12612. if (!s.onclick) {
  12613. s.onclick = function(v) {
  12614. if (s.cmd)
  12615. ed.execCommand(s.cmd, s.ui || false, s.value);
  12616. };
  12617. }
  12618. });
  12619. ed.onRemove.add(function() {
  12620. c.destroy();
  12621. });
  12622. // Fix for bug #1897785, #1898007
  12623. if (tinymce.isIE) {
  12624. c.onShowMenu.add(function() {
  12625. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  12626. ed.focus();
  12627. bm = ed.selection.getBookmark(1);
  12628. });
  12629. c.onHideMenu.add(function() {
  12630. if (bm) {
  12631. ed.selection.moveToBookmark(bm);
  12632. bm = 0;
  12633. }
  12634. });
  12635. }
  12636. return t.add(c);
  12637. },
  12638. createListBox : function(id, s, cc) {
  12639. var t = this, ed = t.editor, cmd, c, cls;
  12640. if (t.get(id))
  12641. return null;
  12642. s.title = ed.translate(s.title);
  12643. s.scope = s.scope || ed;
  12644. if (!s.onselect) {
  12645. s.onselect = function(v) {
  12646. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  12647. };
  12648. }
  12649. s = extend({
  12650. title : s.title,
  12651. 'class' : 'mce_' + id,
  12652. scope : s.scope,
  12653. control_manager : t
  12654. }, s);
  12655. id = t.prefix + id;
  12656. function useNativeListForAccessibility(ed) {
  12657. return ed.settings.use_accessible_selects && !tinymce.isGecko
  12658. }
  12659. if (ed.settings.use_native_selects || useNativeListForAccessibility(ed))
  12660. c = new tinymce.ui.NativeListBox(id, s);
  12661. else {
  12662. cls = cc || t._cls.listbox || tinymce.ui.ListBox;
  12663. c = new cls(id, s, ed);
  12664. }
  12665. t.controls[id] = c;
  12666. // Fix focus problem in Safari
  12667. if (tinymce.isWebKit) {
  12668. c.onPostRender.add(function(c, n) {
  12669. // Store bookmark on mousedown
  12670. Event.add(n, 'mousedown', function() {
  12671. ed.bookmark = ed.selection.getBookmark(1);
  12672. });
  12673. // Restore on focus, since it might be lost
  12674. Event.add(n, 'focus', function() {
  12675. ed.selection.moveToBookmark(ed.bookmark);
  12676. ed.bookmark = null;
  12677. });
  12678. });
  12679. }
  12680. if (c.hideMenu)
  12681. ed.onMouseDown.add(c.hideMenu, c);
  12682. return t.add(c);
  12683. },
  12684. createButton : function(id, s, cc) {
  12685. var t = this, ed = t.editor, o, c, cls;
  12686. if (t.get(id))
  12687. return null;
  12688. s.title = ed.translate(s.title);
  12689. s.label = ed.translate(s.label);
  12690. s.scope = s.scope || ed;
  12691. if (!s.onclick && !s.menu_button) {
  12692. s.onclick = function() {
  12693. ed.execCommand(s.cmd, s.ui || false, s.value);
  12694. };
  12695. }
  12696. s = extend({
  12697. title : s.title,
  12698. 'class' : 'mce_' + id,
  12699. unavailable_prefix : ed.getLang('unavailable', ''),
  12700. scope : s.scope,
  12701. control_manager : t
  12702. }, s);
  12703. id = t.prefix + id;
  12704. if (s.menu_button) {
  12705. cls = cc || t._cls.menubutton || tinymce.ui.MenuButton;
  12706. c = new cls(id, s, ed);
  12707. ed.onMouseDown.add(c.hideMenu, c);
  12708. } else {
  12709. cls = t._cls.button || tinymce.ui.Button;
  12710. c = new cls(id, s, ed);
  12711. }
  12712. return t.add(c);
  12713. },
  12714. createMenuButton : function(id, s, cc) {
  12715. s = s || {};
  12716. s.menu_button = 1;
  12717. return this.createButton(id, s, cc);
  12718. },
  12719. createSplitButton : function(id, s, cc) {
  12720. var t = this, ed = t.editor, cmd, c, cls;
  12721. if (t.get(id))
  12722. return null;
  12723. s.title = ed.translate(s.title);
  12724. s.scope = s.scope || ed;
  12725. if (!s.onclick) {
  12726. s.onclick = function(v) {
  12727. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  12728. };
  12729. }
  12730. if (!s.onselect) {
  12731. s.onselect = function(v) {
  12732. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  12733. };
  12734. }
  12735. s = extend({
  12736. title : s.title,
  12737. 'class' : 'mce_' + id,
  12738. scope : s.scope,
  12739. control_manager : t
  12740. }, s);
  12741. id = t.prefix + id;
  12742. cls = cc || t._cls.splitbutton || tinymce.ui.SplitButton;
  12743. c = t.add(new cls(id, s, ed));
  12744. ed.onMouseDown.add(c.hideMenu, c);
  12745. return c;
  12746. },
  12747. createColorSplitButton : function(id, s, cc) {
  12748. var t = this, ed = t.editor, cmd, c, cls, bm;
  12749. if (t.get(id))
  12750. return null;
  12751. s.title = ed.translate(s.title);
  12752. s.scope = s.scope || ed;
  12753. if (!s.onclick) {
  12754. s.onclick = function(v) {
  12755. if (tinymce.isIE)
  12756. bm = ed.selection.getBookmark(1);
  12757. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  12758. };
  12759. }
  12760. if (!s.onselect) {
  12761. s.onselect = function(v) {
  12762. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  12763. };
  12764. }
  12765. s = extend({
  12766. title : s.title,
  12767. 'class' : 'mce_' + id,
  12768. 'menu_class' : ed.getParam('skin') + 'Skin',
  12769. scope : s.scope,
  12770. more_colors_title : ed.getLang('more_colors')
  12771. }, s);
  12772. id = t.prefix + id;
  12773. cls = cc || t._cls.colorsplitbutton || tinymce.ui.ColorSplitButton;
  12774. c = new cls(id, s, ed);
  12775. ed.onMouseDown.add(c.hideMenu, c);
  12776. // Remove the menu element when the editor is removed
  12777. ed.onRemove.add(function() {
  12778. c.destroy();
  12779. });
  12780. // Fix for bug #1897785, #1898007
  12781. if (tinymce.isIE) {
  12782. c.onShowMenu.add(function() {
  12783. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  12784. ed.focus();
  12785. bm = ed.selection.getBookmark(1);
  12786. });
  12787. c.onHideMenu.add(function() {
  12788. if (bm) {
  12789. ed.selection.moveToBookmark(bm);
  12790. bm = 0;
  12791. }
  12792. });
  12793. }
  12794. return t.add(c);
  12795. },
  12796. createToolbar : function(id, s, cc) {
  12797. var c, t = this, cls;
  12798. id = t.prefix + id;
  12799. cls = cc || t._cls.toolbar || tinymce.ui.Toolbar;
  12800. c = new cls(id, s, t.editor);
  12801. if (t.get(id))
  12802. return null;
  12803. return t.add(c);
  12804. },
  12805. createToolbarGroup : function(id, s, cc) {
  12806. var c, t = this, cls;
  12807. id = t.prefix + id;
  12808. cls = cc || this._cls.toolbarGroup || tinymce.ui.ToolbarGroup;
  12809. c = new cls(id, s, t.editor);
  12810. if (t.get(id))
  12811. return null;
  12812. return t.add(c);
  12813. },
  12814. createSeparator : function(cc) {
  12815. var cls = cc || this._cls.separator || tinymce.ui.Separator;
  12816. return new cls();
  12817. },
  12818. setControlType : function(n, c) {
  12819. return this._cls[n.toLowerCase()] = c;
  12820. },
  12821. destroy : function() {
  12822. each(this.controls, function(c) {
  12823. c.destroy();
  12824. });
  12825. this.controls = null;
  12826. }
  12827. });
  12828. })(tinymce);
  12829. (function(tinymce) {
  12830. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isIE = tinymce.isIE, isOpera = tinymce.isOpera;
  12831. tinymce.create('tinymce.WindowManager', {
  12832. WindowManager : function(ed) {
  12833. var t = this;
  12834. t.editor = ed;
  12835. t.onOpen = new Dispatcher(t);
  12836. t.onClose = new Dispatcher(t);
  12837. t.params = {};
  12838. t.features = {};
  12839. },
  12840. open : function(s, p) {
  12841. var t = this, f = '', x, y, mo = t.editor.settings.dialog_type == 'modal', w, sw, sh, vp = tinymce.DOM.getViewPort(), u;
  12842. // Default some options
  12843. s = s || {};
  12844. p = p || {};
  12845. sw = isOpera ? vp.w : screen.width; // Opera uses windows inside the Opera window
  12846. sh = isOpera ? vp.h : screen.height;
  12847. s.name = s.name || 'mc_' + new Date().getTime();
  12848. s.width = parseInt(s.width || 320);
  12849. s.height = parseInt(s.height || 240);
  12850. s.resizable = true;
  12851. s.left = s.left || parseInt(sw / 2.0) - (s.width / 2.0);
  12852. s.top = s.top || parseInt(sh / 2.0) - (s.height / 2.0);
  12853. p.inline = false;
  12854. p.mce_width = s.width;
  12855. p.mce_height = s.height;
  12856. p.mce_auto_focus = s.auto_focus;
  12857. if (mo) {
  12858. if (isIE) {
  12859. s.center = true;
  12860. s.help = false;
  12861. s.dialogWidth = s.width + 'px';
  12862. s.dialogHeight = s.height + 'px';
  12863. s.scroll = s.scrollbars || false;
  12864. }
  12865. }
  12866. // Build features string
  12867. each(s, function(v, k) {
  12868. if (tinymce.is(v, 'boolean'))
  12869. v = v ? 'yes' : 'no';
  12870. if (!/^(name|url)$/.test(k)) {
  12871. if (isIE && mo)
  12872. f += (f ? ';' : '') + k + ':' + v;
  12873. else
  12874. f += (f ? ',' : '') + k + '=' + v;
  12875. }
  12876. });
  12877. t.features = s;
  12878. t.params = p;
  12879. t.onOpen.dispatch(t, s, p);
  12880. u = s.url || s.file;
  12881. u = tinymce._addVer(u);
  12882. try {
  12883. if (isIE && mo) {
  12884. w = 1;
  12885. window.showModalDialog(u, window, f);
  12886. } else
  12887. w = window.open(u, s.name, f);
  12888. } catch (ex) {
  12889. // Ignore
  12890. }
  12891. if (!w)
  12892. alert(t.editor.getLang('popup_blocked'));
  12893. },
  12894. close : function(w) {
  12895. w.close();
  12896. this.onClose.dispatch(this);
  12897. },
  12898. createInstance : function(cl, a, b, c, d, e) {
  12899. var f = tinymce.resolve(cl);
  12900. return new f(a, b, c, d, e);
  12901. },
  12902. confirm : function(t, cb, s, w) {
  12903. w = w || window;
  12904. cb.call(s || this, w.confirm(this._decode(this.editor.getLang(t, t))));
  12905. },
  12906. alert : function(tx, cb, s, w) {
  12907. var t = this;
  12908. w = w || window;
  12909. w.alert(t._decode(t.editor.getLang(tx, tx)));
  12910. if (cb)
  12911. cb.call(s || t);
  12912. },
  12913. resizeBy : function(dw, dh, win) {
  12914. if (dw < 0)
  12915. dw = 0;
  12916. if (dh < 0)
  12917. dh = 0;
  12918. win.resizeBy(dw, dh);
  12919. },
  12920. // Internal functions
  12921. _decode : function(s) {
  12922. return tinymce.DOM.decode(s).replace(/\\n/g, '\n');
  12923. }
  12924. });
  12925. }(tinymce));
  12926. (function(tinymce) {
  12927. tinymce.Formatter = function(ed) {
  12928. var formats = {},
  12929. each = tinymce.each,
  12930. dom = ed.dom,
  12931. selection = ed.selection,
  12932. TreeWalker = tinymce.dom.TreeWalker,
  12933. rangeUtils = new tinymce.dom.RangeUtils(dom),
  12934. isValid = ed.schema.isValidChild,
  12935. isArray = tinymce.isArray,
  12936. isBlock = dom.isBlock,
  12937. forcedRootBlock = ed.settings.forced_root_block,
  12938. nodeIndex = dom.nodeIndex,
  12939. INVISIBLE_CHAR = '\uFEFF',
  12940. MCE_ATTR_RE = /^(src|href|style)$/,
  12941. FALSE = false,
  12942. TRUE = true,
  12943. formatChangeData,
  12944. undef,
  12945. getContentEditable = dom.getContentEditable;
  12946. function isTextBlock(name) {
  12947. return !!ed.schema.getTextBlocks()[name.toLowerCase()];
  12948. }
  12949. function getParents(node, selector) {
  12950. return dom.getParents(node, selector, dom.getRoot());
  12951. };
  12952. function isCaretNode(node) {
  12953. return node.nodeType === 1 && node.id === '_mce_caret';
  12954. };
  12955. function defaultFormats() {
  12956. register({
  12957. alignleft : [
  12958. {selector : 'figure,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}, defaultBlock: 'div'},
  12959. {selector : 'img,table', collapsed : false, styles : {'float' : 'left'}}
  12960. ],
  12961. aligncenter : [
  12962. {selector : 'figure,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}, defaultBlock: 'div'},
  12963. {selector : 'img', collapsed : false, styles : {display : 'block', marginLeft : 'auto', marginRight : 'auto'}},
  12964. {selector : 'table', collapsed : false, styles : {marginLeft : 'auto', marginRight : 'auto'}}
  12965. ],
  12966. alignright : [
  12967. {selector : 'figure,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}, defaultBlock: 'div'},
  12968. {selector : 'img,table', collapsed : false, styles : {'float' : 'right'}}
  12969. ],
  12970. alignfull : [
  12971. {selector : 'figure,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'justify'}, defaultBlock: 'div'}
  12972. ],
  12973. bold : [
  12974. {inline : 'strong', remove : 'all'},
  12975. {inline : 'span', styles : {fontWeight : 'bold'}},
  12976. {inline : 'b', remove : 'all'}
  12977. ],
  12978. italic : [
  12979. {inline : 'em', remove : 'all'},
  12980. {inline : 'span', styles : {fontStyle : 'italic'}},
  12981. {inline : 'i', remove : 'all'}
  12982. ],
  12983. underline : [
  12984. {inline : 'span', styles : {textDecoration : 'underline'}, exact : true},
  12985. {inline : 'u', remove : 'all'}
  12986. ],
  12987. strikethrough : [
  12988. {inline : 'span', styles : {textDecoration : 'line-through'}, exact : true},
  12989. {inline : 'strike', remove : 'all'}
  12990. ],
  12991. forecolor : {inline : 'span', styles : {color : '%value'}, wrap_links : false},
  12992. hilitecolor : {inline : 'span', styles : {backgroundColor : '%value'}, wrap_links : false},
  12993. fontname : {inline : 'span', styles : {fontFamily : '%value'}},
  12994. fontsize : {inline : 'span', styles : {fontSize : '%value'}},
  12995. fontsize_class : {inline : 'span', attributes : {'class' : '%value'}},
  12996. blockquote : {block : 'blockquote', wrapper : 1, remove : 'all'},
  12997. subscript : {inline : 'sub'},
  12998. superscript : {inline : 'sup'},
  12999. link : {inline : 'a', selector : 'a', remove : 'all', split : true, deep : true,
  13000. onmatch : function(node) {
  13001. return true;
  13002. },
  13003. onformat : function(elm, fmt, vars) {
  13004. each(vars, function(value, key) {
  13005. dom.setAttrib(elm, key, value);
  13006. });
  13007. }
  13008. },
  13009. removeformat : [
  13010. {selector : 'b,strong,em,i,font,u,strike', remove : 'all', split : true, expand : false, block_expand : true, deep : true},
  13011. {selector : 'span', attributes : ['style', 'class'], remove : 'empty', split : true, expand : false, deep : true},
  13012. {selector : '*', attributes : ['style', 'class'], split : false, expand : false, deep : true}
  13013. ]
  13014. });
  13015. // Register default block formats
  13016. each('p h1 h2 h3 h4 h5 h6 div address pre div code dt dd samp'.split(/\s/), function(name) {
  13017. register(name, {block : name, remove : 'all'});
  13018. });
  13019. // Register user defined formats
  13020. register(ed.settings.formats);
  13021. };
  13022. function addKeyboardShortcuts() {
  13023. // Add some inline shortcuts
  13024. ed.addShortcut('ctrl+b', 'bold_desc', 'Bold');
  13025. ed.addShortcut('ctrl+i', 'italic_desc', 'Italic');
  13026. ed.addShortcut('ctrl+u', 'underline_desc', 'Underline');
  13027. // BlockFormat shortcuts keys
  13028. for (var i = 1; i <= 6; i++) {
  13029. ed.addShortcut('ctrl+' + i, '', ['FormatBlock', false, 'h' + i]);
  13030. }
  13031. ed.addShortcut('ctrl+7', '', ['FormatBlock', false, 'p']);
  13032. ed.addShortcut('ctrl+8', '', ['FormatBlock', false, 'div']);
  13033. ed.addShortcut('ctrl+9', '', ['FormatBlock', false, 'address']);
  13034. };
  13035. // Public functions
  13036. function get(name) {
  13037. return name ? formats[name] : formats;
  13038. };
  13039. function register(name, format) {
  13040. if (name) {
  13041. if (typeof(name) !== 'string') {
  13042. each(name, function(format, name) {
  13043. register(name, format);
  13044. });
  13045. } else {
  13046. // Force format into array and add it to internal collection
  13047. format = format.length ? format : [format];
  13048. each(format, function(format) {
  13049. // Set deep to false by default on selector formats this to avoid removing
  13050. // alignment on images inside paragraphs when alignment is changed on paragraphs
  13051. if (format.deep === undef)
  13052. format.deep = !format.selector;
  13053. // Default to true
  13054. if (format.split === undef)
  13055. format.split = !format.selector || format.inline;
  13056. // Default to true
  13057. if (format.remove === undef && format.selector && !format.inline)
  13058. format.remove = 'none';
  13059. // Mark format as a mixed format inline + block level
  13060. if (format.selector && format.inline) {
  13061. format.mixed = true;
  13062. format.block_expand = true;
  13063. }
  13064. // Split classes if needed
  13065. if (typeof(format.classes) === 'string')
  13066. format.classes = format.classes.split(/\s+/);
  13067. });
  13068. formats[name] = format;
  13069. }
  13070. }
  13071. };
  13072. var getTextDecoration = function(node) {
  13073. var decoration;
  13074. ed.dom.getParent(node, function(n) {
  13075. decoration = ed.dom.getStyle(n, 'text-decoration');
  13076. return decoration && decoration !== 'none';
  13077. });
  13078. return decoration;
  13079. };
  13080. var processUnderlineAndColor = function(node) {
  13081. var textDecoration;
  13082. if (node.nodeType === 1 && node.parentNode && node.parentNode.nodeType === 1) {
  13083. textDecoration = getTextDecoration(node.parentNode);
  13084. if (ed.dom.getStyle(node, 'color') && textDecoration) {
  13085. ed.dom.setStyle(node, 'text-decoration', textDecoration);
  13086. } else if (ed.dom.getStyle(node, 'textdecoration') === textDecoration) {
  13087. ed.dom.setStyle(node, 'text-decoration', null);
  13088. }
  13089. }
  13090. };
  13091. function apply(name, vars, node) {
  13092. var formatList = get(name), format = formatList[0], bookmark, rng, i, isCollapsed = selection.isCollapsed();
  13093. function setElementFormat(elm, fmt) {
  13094. fmt = fmt || format;
  13095. if (elm) {
  13096. if (fmt.onformat) {
  13097. fmt.onformat(elm, fmt, vars, node);
  13098. }
  13099. each(fmt.styles, function(value, name) {
  13100. dom.setStyle(elm, name, replaceVars(value, vars));
  13101. });
  13102. each(fmt.attributes, function(value, name) {
  13103. dom.setAttrib(elm, name, replaceVars(value, vars));
  13104. });
  13105. each(fmt.classes, function(value) {
  13106. value = replaceVars(value, vars);
  13107. if (!dom.hasClass(elm, value))
  13108. dom.addClass(elm, value);
  13109. });
  13110. }
  13111. };
  13112. function adjustSelectionToVisibleSelection() {
  13113. function findSelectionEnd(start, end) {
  13114. var walker = new TreeWalker(end);
  13115. for (node = walker.current(); node; node = walker.prev()) {
  13116. if (node.childNodes.length > 1 || node == start || node.tagName == 'BR') {
  13117. return node;
  13118. }
  13119. }
  13120. };
  13121. // Adjust selection so that a end container with a end offset of zero is not included in the selection
  13122. // as this isn't visible to the user.
  13123. var rng = ed.selection.getRng();
  13124. var start = rng.startContainer;
  13125. var end = rng.endContainer;
  13126. if (start != end && rng.endOffset === 0) {
  13127. var newEnd = findSelectionEnd(start, end);
  13128. var endOffset = newEnd.nodeType == 3 ? newEnd.length : newEnd.childNodes.length;
  13129. rng.setEnd(newEnd, endOffset);
  13130. }
  13131. return rng;
  13132. }
  13133. function applyStyleToList(node, bookmark, wrapElm, newWrappers, process){
  13134. var nodes = [], listIndex = -1, list, startIndex = -1, endIndex = -1, currentWrapElm;
  13135. // find the index of the first child list.
  13136. each(node.childNodes, function(n, index) {
  13137. if (n.nodeName === "UL" || n.nodeName === "OL") {
  13138. listIndex = index;
  13139. list = n;
  13140. return false;
  13141. }
  13142. });
  13143. // get the index of the bookmarks
  13144. each(node.childNodes, function(n, index) {
  13145. if (n.nodeName === "SPAN" && dom.getAttrib(n, "data-mce-type") == "bookmark") {
  13146. if (n.id == bookmark.id + "_start") {
  13147. startIndex = index;
  13148. } else if (n.id == bookmark.id + "_end") {
  13149. endIndex = index;
  13150. }
  13151. }
  13152. });
  13153. // if the selection spans across an embedded list, or there isn't an embedded list - handle processing normally
  13154. if (listIndex <= 0 || (startIndex < listIndex && endIndex > listIndex)) {
  13155. each(tinymce.grep(node.childNodes), process);
  13156. return 0;
  13157. } else {
  13158. currentWrapElm = dom.clone(wrapElm, FALSE);
  13159. // create a list of the nodes on the same side of the list as the selection
  13160. each(tinymce.grep(node.childNodes), function(n, index) {
  13161. if ((startIndex < listIndex && index < listIndex) || (startIndex > listIndex && index > listIndex)) {
  13162. nodes.push(n);
  13163. n.parentNode.removeChild(n);
  13164. }
  13165. });
  13166. // insert the wrapping element either before or after the list.
  13167. if (startIndex < listIndex) {
  13168. node.insertBefore(currentWrapElm, list);
  13169. } else if (startIndex > listIndex) {
  13170. node.insertBefore(currentWrapElm, list.nextSibling);
  13171. }
  13172. // add the new nodes to the list.
  13173. newWrappers.push(currentWrapElm);
  13174. each(nodes, function(node) {
  13175. currentWrapElm.appendChild(node);
  13176. });
  13177. return currentWrapElm;
  13178. }
  13179. };
  13180. function applyRngStyle(rng, bookmark, node_specific) {
  13181. var newWrappers = [], wrapName, wrapElm, contentEditable = true;
  13182. // Setup wrapper element
  13183. wrapName = format.inline || format.block;
  13184. wrapElm = dom.create(wrapName);
  13185. setElementFormat(wrapElm);
  13186. rangeUtils.walk(rng, function(nodes) {
  13187. var currentWrapElm;
  13188. function process(node) {
  13189. var nodeName, parentName, found, hasContentEditableState, lastContentEditable;
  13190. lastContentEditable = contentEditable;
  13191. nodeName = node.nodeName.toLowerCase();
  13192. parentName = node.parentNode.nodeName.toLowerCase();
  13193. // Node has a contentEditable value
  13194. if (node.nodeType === 1 && getContentEditable(node)) {
  13195. lastContentEditable = contentEditable;
  13196. contentEditable = getContentEditable(node) === "true";
  13197. hasContentEditableState = true; // We don't want to wrap the container only it's children
  13198. }
  13199. // Stop wrapping on br elements
  13200. if (isEq(nodeName, 'br')) {
  13201. currentWrapElm = 0;
  13202. // Remove any br elements when we wrap things
  13203. if (format.block)
  13204. dom.remove(node);
  13205. return;
  13206. }
  13207. // If node is wrapper type
  13208. if (format.wrapper && matchNode(node, name, vars)) {
  13209. currentWrapElm = 0;
  13210. return;
  13211. }
  13212. // Can we rename the block
  13213. if (contentEditable && !hasContentEditableState && format.block && !format.wrapper && isTextBlock(nodeName)) {
  13214. node = dom.rename(node, wrapName);
  13215. setElementFormat(node);
  13216. newWrappers.push(node);
  13217. currentWrapElm = 0;
  13218. return;
  13219. }
  13220. // Handle selector patterns
  13221. if (format.selector) {
  13222. // Look for matching formats
  13223. each(formatList, function(format) {
  13224. // Check collapsed state if it exists
  13225. if ('collapsed' in format && format.collapsed !== isCollapsed) {
  13226. return;
  13227. }
  13228. if (dom.is(node, format.selector) && !isCaretNode(node)) {
  13229. setElementFormat(node, format);
  13230. found = true;
  13231. }
  13232. });
  13233. // Continue processing if a selector match wasn't found and a inline element is defined
  13234. if (!format.inline || found) {
  13235. currentWrapElm = 0;
  13236. return;
  13237. }
  13238. }
  13239. // Is it valid to wrap this item
  13240. if (contentEditable && !hasContentEditableState && isValid(wrapName, nodeName) && isValid(parentName, wrapName) &&
  13241. !(!node_specific && node.nodeType === 3 && node.nodeValue.length === 1 && node.nodeValue.charCodeAt(0) === 65279) && !isCaretNode(node)) {
  13242. // Start wrapping
  13243. if (!currentWrapElm) {
  13244. // Wrap the node
  13245. currentWrapElm = dom.clone(wrapElm, FALSE);
  13246. node.parentNode.insertBefore(currentWrapElm, node);
  13247. newWrappers.push(currentWrapElm);
  13248. }
  13249. currentWrapElm.appendChild(node);
  13250. } else if (nodeName == 'li' && bookmark) {
  13251. // Start wrapping - if we are in a list node and have a bookmark, then we will always begin by wrapping in a new element.
  13252. currentWrapElm = applyStyleToList(node, bookmark, wrapElm, newWrappers, process);
  13253. } else {
  13254. // Start a new wrapper for possible children
  13255. currentWrapElm = 0;
  13256. each(tinymce.grep(node.childNodes), process);
  13257. if (hasContentEditableState) {
  13258. contentEditable = lastContentEditable; // Restore last contentEditable state from stack
  13259. }
  13260. // End the last wrapper
  13261. currentWrapElm = 0;
  13262. }
  13263. };
  13264. // Process siblings from range
  13265. each(nodes, process);
  13266. });
  13267. // Wrap links inside as well, for example color inside a link when the wrapper is around the link
  13268. if (format.wrap_links === false) {
  13269. each(newWrappers, function(node) {
  13270. function process(node) {
  13271. var i, currentWrapElm, children;
  13272. if (node.nodeName === 'A') {
  13273. currentWrapElm = dom.clone(wrapElm, FALSE);
  13274. newWrappers.push(currentWrapElm);
  13275. children = tinymce.grep(node.childNodes);
  13276. for (i = 0; i < children.length; i++)
  13277. currentWrapElm.appendChild(children[i]);
  13278. node.appendChild(currentWrapElm);
  13279. }
  13280. each(tinymce.grep(node.childNodes), process);
  13281. };
  13282. process(node);
  13283. });
  13284. }
  13285. // Cleanup
  13286. each(newWrappers, function(node) {
  13287. var childCount;
  13288. function getChildCount(node) {
  13289. var count = 0;
  13290. each(node.childNodes, function(node) {
  13291. if (!isWhiteSpaceNode(node) && !isBookmarkNode(node))
  13292. count++;
  13293. });
  13294. return count;
  13295. };
  13296. function mergeStyles(node) {
  13297. var child, clone;
  13298. each(node.childNodes, function(node) {
  13299. if (node.nodeType == 1 && !isBookmarkNode(node) && !isCaretNode(node)) {
  13300. child = node;
  13301. return FALSE; // break loop
  13302. }
  13303. });
  13304. // If child was found and of the same type as the current node
  13305. if (child && matchName(child, format)) {
  13306. clone = dom.clone(child, FALSE);
  13307. setElementFormat(clone);
  13308. dom.replace(clone, node, TRUE);
  13309. dom.remove(child, 1);
  13310. }
  13311. return clone || node;
  13312. };
  13313. childCount = getChildCount(node);
  13314. // Remove empty nodes but only if there is multiple wrappers and they are not block
  13315. // elements so never remove single <h1></h1> since that would remove the currrent empty block element where the caret is at
  13316. if ((newWrappers.length > 1 || !isBlock(node)) && childCount === 0) {
  13317. dom.remove(node, 1);
  13318. return;
  13319. }
  13320. if (format.inline || format.wrapper) {
  13321. // Merges the current node with it's children of similar type to reduce the number of elements
  13322. if (!format.exact && childCount === 1)
  13323. node = mergeStyles(node);
  13324. // Remove/merge children
  13325. each(formatList, function(format) {
  13326. // Merge all children of similar type will move styles from child to parent
  13327. // this: <span style="color:red"><b><span style="color:red; font-size:10px">text</span></b></span>
  13328. // will become: <span style="color:red"><b><span style="font-size:10px">text</span></b></span>
  13329. each(dom.select(format.inline, node), function(child) {
  13330. var parent;
  13331. // When wrap_links is set to false we don't want
  13332. // to remove the format on children within links
  13333. if (format.wrap_links === false) {
  13334. parent = child.parentNode;
  13335. do {
  13336. if (parent.nodeName === 'A')
  13337. return;
  13338. } while (parent = parent.parentNode);
  13339. }
  13340. removeFormat(format, vars, child, format.exact ? child : null);
  13341. });
  13342. });
  13343. // Remove child if direct parent is of same type
  13344. if (matchNode(node.parentNode, name, vars)) {
  13345. dom.remove(node, 1);
  13346. node = 0;
  13347. return TRUE;
  13348. }
  13349. // Look for parent with similar style format
  13350. if (format.merge_with_parents) {
  13351. dom.getParent(node.parentNode, function(parent) {
  13352. if (matchNode(parent, name, vars)) {
  13353. dom.remove(node, 1);
  13354. node = 0;
  13355. return TRUE;
  13356. }
  13357. });
  13358. }
  13359. // Merge next and previous siblings if they are similar <b>text</b><b>text</b> becomes <b>texttext</b>
  13360. if (node && format.merge_siblings !== false) {
  13361. node = mergeSiblings(getNonWhiteSpaceSibling(node), node);
  13362. node = mergeSiblings(node, getNonWhiteSpaceSibling(node, TRUE));
  13363. }
  13364. }
  13365. });
  13366. };
  13367. if (format) {
  13368. if (node) {
  13369. if (node.nodeType) {
  13370. rng = dom.createRng();
  13371. rng.setStartBefore(node);
  13372. rng.setEndAfter(node);
  13373. applyRngStyle(expandRng(rng, formatList), null, true);
  13374. } else {
  13375. applyRngStyle(node, null, true);
  13376. }
  13377. } else {
  13378. if (!isCollapsed || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
  13379. // Obtain selection node before selection is unselected by applyRngStyle()
  13380. var curSelNode = ed.selection.getNode();
  13381. // If the formats have a default block and we can't find a parent block then start wrapping it with a DIV this is for forced_root_blocks: false
  13382. // It's kind of a hack but people should be using the default block type P since all desktop editors work that way
  13383. if (!forcedRootBlock && formatList[0].defaultBlock && !dom.getParent(curSelNode, dom.isBlock)) {
  13384. apply(formatList[0].defaultBlock);
  13385. }
  13386. // Apply formatting to selection
  13387. ed.selection.setRng(adjustSelectionToVisibleSelection());
  13388. bookmark = selection.getBookmark();
  13389. applyRngStyle(expandRng(selection.getRng(TRUE), formatList), bookmark);
  13390. // Colored nodes should be underlined so that the color of the underline matches the text color.
  13391. if (format.styles && (format.styles.color || format.styles.textDecoration)) {
  13392. tinymce.walk(curSelNode, processUnderlineAndColor, 'childNodes');
  13393. processUnderlineAndColor(curSelNode);
  13394. }
  13395. selection.moveToBookmark(bookmark);
  13396. moveStart(selection.getRng(TRUE));
  13397. ed.nodeChanged();
  13398. } else
  13399. performCaretAction('apply', name, vars);
  13400. }
  13401. }
  13402. };
  13403. function remove(name, vars, node) {
  13404. var formatList = get(name), format = formatList[0], bookmark, i, rng, contentEditable = true;
  13405. // Merges the styles for each node
  13406. function process(node) {
  13407. var children, i, l, localContentEditable, lastContentEditable, hasContentEditableState;
  13408. // Skip on text nodes as they have neither format to remove nor children
  13409. if (node.nodeType === 3) {
  13410. return;
  13411. }
  13412. // Node has a contentEditable value
  13413. if (node.nodeType === 1 && getContentEditable(node)) {
  13414. lastContentEditable = contentEditable;
  13415. contentEditable = getContentEditable(node) === "true";
  13416. hasContentEditableState = true; // We don't want to wrap the container only it's children
  13417. }
  13418. // Grab the children first since the nodelist might be changed
  13419. children = tinymce.grep(node.childNodes);
  13420. // Process current node
  13421. if (contentEditable && !hasContentEditableState) {
  13422. for (i = 0, l = formatList.length; i < l; i++) {
  13423. if (removeFormat(formatList[i], vars, node, node))
  13424. break;
  13425. }
  13426. }
  13427. // Process the children
  13428. if (format.deep) {
  13429. if (children.length) {
  13430. for (i = 0, l = children.length; i < l; i++)
  13431. process(children[i]);
  13432. if (hasContentEditableState) {
  13433. contentEditable = lastContentEditable; // Restore last contentEditable state from stack
  13434. }
  13435. }
  13436. }
  13437. };
  13438. function findFormatRoot(container) {
  13439. var formatRoot;
  13440. // Find format root
  13441. each(getParents(container.parentNode).reverse(), function(parent) {
  13442. var format;
  13443. // Find format root element
  13444. if (!formatRoot && parent.id != '_start' && parent.id != '_end') {
  13445. // Is the node matching the format we are looking for
  13446. format = matchNode(parent, name, vars);
  13447. if (format && format.split !== false)
  13448. formatRoot = parent;
  13449. }
  13450. });
  13451. return formatRoot;
  13452. };
  13453. function wrapAndSplit(format_root, container, target, split) {
  13454. var parent, clone, lastClone, firstClone, i, formatRootParent;
  13455. // Format root found then clone formats and split it
  13456. if (format_root) {
  13457. formatRootParent = format_root.parentNode;
  13458. for (parent = container.parentNode; parent && parent != formatRootParent; parent = parent.parentNode) {
  13459. clone = dom.clone(parent, FALSE);
  13460. for (i = 0; i < formatList.length; i++) {
  13461. if (removeFormat(formatList[i], vars, clone, clone)) {
  13462. clone = 0;
  13463. break;
  13464. }
  13465. }
  13466. // Build wrapper node
  13467. if (clone) {
  13468. if (lastClone)
  13469. clone.appendChild(lastClone);
  13470. if (!firstClone)
  13471. firstClone = clone;
  13472. lastClone = clone;
  13473. }
  13474. }
  13475. // Never split block elements if the format is mixed
  13476. if (split && (!format.mixed || !isBlock(format_root)))
  13477. container = dom.split(format_root, container);
  13478. // Wrap container in cloned formats
  13479. if (lastClone) {
  13480. target.parentNode.insertBefore(lastClone, target);
  13481. firstClone.appendChild(target);
  13482. }
  13483. }
  13484. return container;
  13485. };
  13486. function splitToFormatRoot(container) {
  13487. return wrapAndSplit(findFormatRoot(container), container, container, true);
  13488. };
  13489. function unwrap(start) {
  13490. var node = dom.get(start ? '_start' : '_end'),
  13491. out = node[start ? 'firstChild' : 'lastChild'];
  13492. // If the end is placed within the start the result will be removed
  13493. // So this checks if the out node is a bookmark node if it is it
  13494. // checks for another more suitable node
  13495. if (isBookmarkNode(out))
  13496. out = out[start ? 'firstChild' : 'lastChild'];
  13497. dom.remove(node, true);
  13498. return out;
  13499. };
  13500. function removeRngStyle(rng) {
  13501. var startContainer, endContainer, node;
  13502. rng = expandRng(rng, formatList, TRUE);
  13503. if (format.split) {
  13504. startContainer = getContainer(rng, TRUE);
  13505. endContainer = getContainer(rng);
  13506. if (startContainer != endContainer) {
  13507. // WebKit will render the table incorrectly if we wrap a TD in a SPAN so lets see if the can use the first child instead
  13508. // This will happen if you tripple click a table cell and use remove formatting
  13509. if (/^(TR|TD)$/.test(startContainer.nodeName) && startContainer.firstChild) {
  13510. startContainer = (startContainer.nodeName == "TD" ? startContainer.firstChild : startContainer.firstChild.firstChild) || startContainer;
  13511. }
  13512. // Wrap start/end nodes in span element since these might be cloned/moved
  13513. startContainer = wrap(startContainer, 'span', {id : '_start', 'data-mce-type' : 'bookmark'});
  13514. endContainer = wrap(endContainer, 'span', {id : '_end', 'data-mce-type' : 'bookmark'});
  13515. // Split start/end
  13516. splitToFormatRoot(startContainer);
  13517. splitToFormatRoot(endContainer);
  13518. // Unwrap start/end to get real elements again
  13519. startContainer = unwrap(TRUE);
  13520. endContainer = unwrap();
  13521. } else
  13522. startContainer = endContainer = splitToFormatRoot(startContainer);
  13523. // Update range positions since they might have changed after the split operations
  13524. rng.startContainer = startContainer.parentNode;
  13525. rng.startOffset = nodeIndex(startContainer);
  13526. rng.endContainer = endContainer.parentNode;
  13527. rng.endOffset = nodeIndex(endContainer) + 1;
  13528. }
  13529. // Remove items between start/end
  13530. rangeUtils.walk(rng, function(nodes) {
  13531. each(nodes, function(node) {
  13532. process(node);
  13533. // Remove parent span if it only contains text-decoration: underline, yet a parent node is also underlined.
  13534. if (node.nodeType === 1 && ed.dom.getStyle(node, 'text-decoration') === 'underline' && node.parentNode && getTextDecoration(node.parentNode) === 'underline') {
  13535. removeFormat({'deep': false, 'exact': true, 'inline': 'span', 'styles': {'textDecoration' : 'underline'}}, null, node);
  13536. }
  13537. });
  13538. });
  13539. };
  13540. // Handle node
  13541. if (node) {
  13542. if (node.nodeType) {
  13543. rng = dom.createRng();
  13544. rng.setStartBefore(node);
  13545. rng.setEndAfter(node);
  13546. removeRngStyle(rng);
  13547. } else {
  13548. removeRngStyle(node);
  13549. }
  13550. return;
  13551. }
  13552. if (!selection.isCollapsed() || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
  13553. bookmark = selection.getBookmark();
  13554. removeRngStyle(selection.getRng(TRUE));
  13555. selection.moveToBookmark(bookmark);
  13556. // 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
  13557. if (format.inline && match(name, vars, selection.getStart())) {
  13558. moveStart(selection.getRng(true));
  13559. }
  13560. ed.nodeChanged();
  13561. } else
  13562. performCaretAction('remove', name, vars);
  13563. };
  13564. function toggle(name, vars, node) {
  13565. var fmt = get(name);
  13566. if (match(name, vars, node) && (!('toggle' in fmt[0]) || fmt[0].toggle))
  13567. remove(name, vars, node);
  13568. else
  13569. apply(name, vars, node);
  13570. };
  13571. function matchNode(node, name, vars, similar) {
  13572. var formatList = get(name), format, i, classes;
  13573. function matchItems(node, format, item_name) {
  13574. var key, value, items = format[item_name], i;
  13575. // Custom match
  13576. if (format.onmatch) {
  13577. return format.onmatch(node, format, item_name);
  13578. }
  13579. // Check all items
  13580. if (items) {
  13581. // Non indexed object
  13582. if (items.length === undef) {
  13583. for (key in items) {
  13584. if (items.hasOwnProperty(key)) {
  13585. if (item_name === 'attributes')
  13586. value = dom.getAttrib(node, key);
  13587. else
  13588. value = getStyle(node, key);
  13589. if (similar && !value && !format.exact)
  13590. return;
  13591. if ((!similar || format.exact) && !isEq(value, replaceVars(items[key], vars)))
  13592. return;
  13593. }
  13594. }
  13595. } else {
  13596. // Only one match needed for indexed arrays
  13597. for (i = 0; i < items.length; i++) {
  13598. if (item_name === 'attributes' ? dom.getAttrib(node, items[i]) : getStyle(node, items[i]))
  13599. return format;
  13600. }
  13601. }
  13602. }
  13603. return format;
  13604. };
  13605. if (formatList && node) {
  13606. // Check each format in list
  13607. for (i = 0; i < formatList.length; i++) {
  13608. format = formatList[i];
  13609. // Name name, attributes, styles and classes
  13610. if (matchName(node, format) && matchItems(node, format, 'attributes') && matchItems(node, format, 'styles')) {
  13611. // Match classes
  13612. if (classes = format.classes) {
  13613. for (i = 0; i < classes.length; i++) {
  13614. if (!dom.hasClass(node, classes[i]))
  13615. return;
  13616. }
  13617. }
  13618. return format;
  13619. }
  13620. }
  13621. }
  13622. };
  13623. function match(name, vars, node) {
  13624. var startNode;
  13625. function matchParents(node) {
  13626. // Find first node with similar format settings
  13627. node = dom.getParent(node, function(node) {
  13628. return !!matchNode(node, name, vars, true);
  13629. });
  13630. // Do an exact check on the similar format element
  13631. return matchNode(node, name, vars);
  13632. };
  13633. // Check specified node
  13634. if (node)
  13635. return matchParents(node);
  13636. // Check selected node
  13637. node = selection.getNode();
  13638. if (matchParents(node))
  13639. return TRUE;
  13640. // Check start node if it's different
  13641. startNode = selection.getStart();
  13642. if (startNode != node) {
  13643. if (matchParents(startNode))
  13644. return TRUE;
  13645. }
  13646. return FALSE;
  13647. };
  13648. function matchAll(names, vars) {
  13649. var startElement, matchedFormatNames = [], checkedMap = {}, i, ni, name;
  13650. // Check start of selection for formats
  13651. startElement = selection.getStart();
  13652. dom.getParent(startElement, function(node) {
  13653. var i, name;
  13654. for (i = 0; i < names.length; i++) {
  13655. name = names[i];
  13656. if (!checkedMap[name] && matchNode(node, name, vars)) {
  13657. checkedMap[name] = true;
  13658. matchedFormatNames.push(name);
  13659. }
  13660. }
  13661. }, dom.getRoot());
  13662. return matchedFormatNames;
  13663. };
  13664. function canApply(name) {
  13665. var formatList = get(name), startNode, parents, i, x, selector;
  13666. if (formatList) {
  13667. startNode = selection.getStart();
  13668. parents = getParents(startNode);
  13669. for (x = formatList.length - 1; x >= 0; x--) {
  13670. selector = formatList[x].selector;
  13671. // Format is not selector based, then always return TRUE
  13672. if (!selector)
  13673. return TRUE;
  13674. for (i = parents.length - 1; i >= 0; i--) {
  13675. if (dom.is(parents[i], selector))
  13676. return TRUE;
  13677. }
  13678. }
  13679. }
  13680. return FALSE;
  13681. };
  13682. function formatChanged(formats, callback, similar) {
  13683. var currentFormats;
  13684. // Setup format node change logic
  13685. if (!formatChangeData) {
  13686. formatChangeData = {};
  13687. currentFormats = {};
  13688. ed.onNodeChange.addToTop(function(ed, cm, node) {
  13689. var parents = getParents(node), matchedFormats = {};
  13690. // Check for new formats
  13691. each(formatChangeData, function(callbacks, format) {
  13692. each(parents, function(node) {
  13693. if (matchNode(node, format, {}, callbacks.similar)) {
  13694. if (!currentFormats[format]) {
  13695. // Execute callbacks
  13696. each(callbacks, function(callback) {
  13697. callback(true, {node: node, format: format, parents: parents});
  13698. });
  13699. currentFormats[format] = callbacks;
  13700. }
  13701. matchedFormats[format] = callbacks;
  13702. return false;
  13703. }
  13704. });
  13705. });
  13706. // Check if current formats still match
  13707. each(currentFormats, function(callbacks, format) {
  13708. if (!matchedFormats[format]) {
  13709. delete currentFormats[format];
  13710. each(callbacks, function(callback) {
  13711. callback(false, {node: node, format: format, parents: parents});
  13712. });
  13713. }
  13714. });
  13715. });
  13716. }
  13717. // Add format listeners
  13718. each(formats.split(','), function(format) {
  13719. if (!formatChangeData[format]) {
  13720. formatChangeData[format] = [];
  13721. formatChangeData[format].similar = similar;
  13722. }
  13723. formatChangeData[format].push(callback);
  13724. });
  13725. return this;
  13726. };
  13727. // Expose to public
  13728. tinymce.extend(this, {
  13729. get : get,
  13730. register : register,
  13731. apply : apply,
  13732. remove : remove,
  13733. toggle : toggle,
  13734. match : match,
  13735. matchAll : matchAll,
  13736. matchNode : matchNode,
  13737. canApply : canApply,
  13738. formatChanged: formatChanged
  13739. });
  13740. // Initialize
  13741. defaultFormats();
  13742. addKeyboardShortcuts();
  13743. // Private functions
  13744. function matchName(node, format) {
  13745. // Check for inline match
  13746. if (isEq(node, format.inline))
  13747. return TRUE;
  13748. // Check for block match
  13749. if (isEq(node, format.block))
  13750. return TRUE;
  13751. // Check for selector match
  13752. if (format.selector)
  13753. return dom.is(node, format.selector);
  13754. };
  13755. function isEq(str1, str2) {
  13756. str1 = str1 || '';
  13757. str2 = str2 || '';
  13758. str1 = '' + (str1.nodeName || str1);
  13759. str2 = '' + (str2.nodeName || str2);
  13760. return str1.toLowerCase() == str2.toLowerCase();
  13761. };
  13762. function getStyle(node, name) {
  13763. var styleVal = dom.getStyle(node, name);
  13764. // Force the format to hex
  13765. if (name == 'color' || name == 'backgroundColor')
  13766. styleVal = dom.toHex(styleVal);
  13767. // Opera will return bold as 700
  13768. if (name == 'fontWeight' && styleVal == 700)
  13769. styleVal = 'bold';
  13770. return '' + styleVal;
  13771. };
  13772. function replaceVars(value, vars) {
  13773. if (typeof(value) != "string")
  13774. value = value(vars);
  13775. else if (vars) {
  13776. value = value.replace(/%(\w+)/g, function(str, name) {
  13777. return vars[name] || str;
  13778. });
  13779. }
  13780. return value;
  13781. };
  13782. function isWhiteSpaceNode(node) {
  13783. return node && node.nodeType === 3 && /^([\t \r\n]+|)$/.test(node.nodeValue);
  13784. };
  13785. function wrap(node, name, attrs) {
  13786. var wrapper = dom.create(name, attrs);
  13787. node.parentNode.insertBefore(wrapper, node);
  13788. wrapper.appendChild(node);
  13789. return wrapper;
  13790. };
  13791. function expandRng(rng, format, remove) {
  13792. var sibling, lastIdx, leaf, endPoint,
  13793. startContainer = rng.startContainer,
  13794. startOffset = rng.startOffset,
  13795. endContainer = rng.endContainer,
  13796. endOffset = rng.endOffset;
  13797. // This function walks up the tree if there is no siblings before/after the node
  13798. function findParentContainer(start) {
  13799. var container, parent, child, sibling, siblingName, root;
  13800. container = parent = start ? startContainer : endContainer;
  13801. siblingName = start ? 'previousSibling' : 'nextSibling';
  13802. root = dom.getRoot();
  13803. function isBogusBr(node) {
  13804. return node.nodeName == "BR" && node.getAttribute('data-mce-bogus') && !node.nextSibling;
  13805. };
  13806. // If it's a text node and the offset is inside the text
  13807. if (container.nodeType == 3 && !isWhiteSpaceNode(container)) {
  13808. if (start ? startOffset > 0 : endOffset < container.nodeValue.length) {
  13809. return container;
  13810. }
  13811. }
  13812. for (;;) {
  13813. // Stop expanding on block elements
  13814. if (!format[0].block_expand && isBlock(parent))
  13815. return parent;
  13816. // Walk left/right
  13817. for (sibling = parent[siblingName]; sibling; sibling = sibling[siblingName]) {
  13818. if (!isBookmarkNode(sibling) && !isWhiteSpaceNode(sibling) && !isBogusBr(sibling)) {
  13819. return parent;
  13820. }
  13821. }
  13822. // Check if we can move up are we at root level or body level
  13823. if (parent.parentNode == root) {
  13824. container = parent;
  13825. break;
  13826. }
  13827. parent = parent.parentNode;
  13828. }
  13829. return container;
  13830. };
  13831. // This function walks down the tree to find the leaf at the selection.
  13832. // The offset is also returned as if node initially a leaf, the offset may be in the middle of the text node.
  13833. function findLeaf(node, offset) {
  13834. if (offset === undef)
  13835. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  13836. while (node && node.hasChildNodes()) {
  13837. node = node.childNodes[offset];
  13838. if (node)
  13839. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  13840. }
  13841. return { node: node, offset: offset };
  13842. }
  13843. // If index based start position then resolve it
  13844. if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) {
  13845. lastIdx = startContainer.childNodes.length - 1;
  13846. startContainer = startContainer.childNodes[startOffset > lastIdx ? lastIdx : startOffset];
  13847. if (startContainer.nodeType == 3)
  13848. startOffset = 0;
  13849. }
  13850. // If index based end position then resolve it
  13851. if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) {
  13852. lastIdx = endContainer.childNodes.length - 1;
  13853. endContainer = endContainer.childNodes[endOffset > lastIdx ? lastIdx : endOffset - 1];
  13854. if (endContainer.nodeType == 3)
  13855. endOffset = endContainer.nodeValue.length;
  13856. }
  13857. // Expands the node to the closes contentEditable false element if it exists
  13858. function findParentContentEditable(node) {
  13859. var parent = node;
  13860. while (parent) {
  13861. if (parent.nodeType === 1 && getContentEditable(parent)) {
  13862. return getContentEditable(parent) === "false" ? parent : node;
  13863. }
  13864. parent = parent.parentNode;
  13865. }
  13866. return node;
  13867. };
  13868. function findWordEndPoint(container, offset, start) {
  13869. var walker, node, pos, lastTextNode;
  13870. function findSpace(node, offset) {
  13871. var pos, pos2, str = node.nodeValue;
  13872. if (typeof(offset) == "undefined") {
  13873. offset = start ? str.length : 0;
  13874. }
  13875. if (start) {
  13876. pos = str.lastIndexOf(' ', offset);
  13877. pos2 = str.lastIndexOf('\u00a0', offset);
  13878. pos = pos > pos2 ? pos : pos2;
  13879. // Include the space on remove to avoid tag soup
  13880. if (pos !== -1 && !remove) {
  13881. pos++;
  13882. }
  13883. } else {
  13884. pos = str.indexOf(' ', offset);
  13885. pos2 = str.indexOf('\u00a0', offset);
  13886. pos = pos !== -1 && (pos2 === -1 || pos < pos2) ? pos : pos2;
  13887. }
  13888. return pos;
  13889. };
  13890. if (container.nodeType === 3) {
  13891. pos = findSpace(container, offset);
  13892. if (pos !== -1) {
  13893. return {container : container, offset : pos};
  13894. }
  13895. lastTextNode = container;
  13896. }
  13897. // Walk the nodes inside the block
  13898. walker = new TreeWalker(container, dom.getParent(container, isBlock) || ed.getBody());
  13899. while (node = walker[start ? 'prev' : 'next']()) {
  13900. if (node.nodeType === 3) {
  13901. lastTextNode = node;
  13902. pos = findSpace(node);
  13903. if (pos !== -1) {
  13904. return {container : node, offset : pos};
  13905. }
  13906. } else if (isBlock(node)) {
  13907. break;
  13908. }
  13909. }
  13910. if (lastTextNode) {
  13911. if (start) {
  13912. offset = 0;
  13913. } else {
  13914. offset = lastTextNode.length;
  13915. }
  13916. return {container: lastTextNode, offset: offset};
  13917. }
  13918. };
  13919. function findSelectorEndPoint(container, sibling_name) {
  13920. var parents, i, y, curFormat;
  13921. if (container.nodeType == 3 && container.nodeValue.length === 0 && container[sibling_name])
  13922. container = container[sibling_name];
  13923. parents = getParents(container);
  13924. for (i = 0; i < parents.length; i++) {
  13925. for (y = 0; y < format.length; y++) {
  13926. curFormat = format[y];
  13927. // If collapsed state is set then skip formats that doesn't match that
  13928. if ("collapsed" in curFormat && curFormat.collapsed !== rng.collapsed)
  13929. continue;
  13930. if (dom.is(parents[i], curFormat.selector))
  13931. return parents[i];
  13932. }
  13933. }
  13934. return container;
  13935. };
  13936. function findBlockEndPoint(container, sibling_name, sibling_name2) {
  13937. var node;
  13938. // Expand to block of similar type
  13939. if (!format[0].wrapper)
  13940. node = dom.getParent(container, format[0].block);
  13941. // Expand to first wrappable block element or any block element
  13942. if (!node)
  13943. node = dom.getParent(container.nodeType == 3 ? container.parentNode : container, isTextBlock);
  13944. // Exclude inner lists from wrapping
  13945. if (node && format[0].wrapper)
  13946. node = getParents(node, 'ul,ol').reverse()[0] || node;
  13947. // Didn't find a block element look for first/last wrappable element
  13948. if (!node) {
  13949. node = container;
  13950. while (node[sibling_name] && !isBlock(node[sibling_name])) {
  13951. node = node[sibling_name];
  13952. // Break on BR but include it will be removed later on
  13953. // we can't remove it now since we need to check if it can be wrapped
  13954. if (isEq(node, 'br'))
  13955. break;
  13956. }
  13957. }
  13958. return node || container;
  13959. };
  13960. // Expand to closest contentEditable element
  13961. startContainer = findParentContentEditable(startContainer);
  13962. endContainer = findParentContentEditable(endContainer);
  13963. // Exclude bookmark nodes if possible
  13964. if (isBookmarkNode(startContainer.parentNode) || isBookmarkNode(startContainer)) {
  13965. startContainer = isBookmarkNode(startContainer) ? startContainer : startContainer.parentNode;
  13966. startContainer = startContainer.nextSibling || startContainer;
  13967. if (startContainer.nodeType == 3)
  13968. startOffset = 0;
  13969. }
  13970. if (isBookmarkNode(endContainer.parentNode) || isBookmarkNode(endContainer)) {
  13971. endContainer = isBookmarkNode(endContainer) ? endContainer : endContainer.parentNode;
  13972. endContainer = endContainer.previousSibling || endContainer;
  13973. if (endContainer.nodeType == 3)
  13974. endOffset = endContainer.length;
  13975. }
  13976. if (format[0].inline) {
  13977. if (rng.collapsed) {
  13978. // Expand left to closest word boundery
  13979. endPoint = findWordEndPoint(startContainer, startOffset, true);
  13980. if (endPoint) {
  13981. startContainer = endPoint.container;
  13982. startOffset = endPoint.offset;
  13983. }
  13984. // Expand right to closest word boundery
  13985. endPoint = findWordEndPoint(endContainer, endOffset);
  13986. if (endPoint) {
  13987. endContainer = endPoint.container;
  13988. endOffset = endPoint.offset;
  13989. }
  13990. }
  13991. // Avoid applying formatting to a trailing space.
  13992. leaf = findLeaf(endContainer, endOffset);
  13993. if (leaf.node) {
  13994. while (leaf.node && leaf.offset === 0 && leaf.node.previousSibling)
  13995. leaf = findLeaf(leaf.node.previousSibling);
  13996. if (leaf.node && leaf.offset > 0 && leaf.node.nodeType === 3 &&
  13997. leaf.node.nodeValue.charAt(leaf.offset - 1) === ' ') {
  13998. if (leaf.offset > 1) {
  13999. endContainer = leaf.node;
  14000. endContainer.splitText(leaf.offset - 1);
  14001. }
  14002. }
  14003. }
  14004. }
  14005. // Move start/end point up the tree if the leaves are sharp and if we are in different containers
  14006. // Example * becomes !: !<p><b><i>*text</i><i>text*</i></b></p>!
  14007. // This will reduce the number of wrapper elements that needs to be created
  14008. // Move start point up the tree
  14009. if (format[0].inline || format[0].block_expand) {
  14010. if (!format[0].inline || (startContainer.nodeType != 3 || startOffset === 0)) {
  14011. startContainer = findParentContainer(true);
  14012. }
  14013. if (!format[0].inline || (endContainer.nodeType != 3 || endOffset === endContainer.nodeValue.length)) {
  14014. endContainer = findParentContainer();
  14015. }
  14016. }
  14017. // Expand start/end container to matching selector
  14018. if (format[0].selector && format[0].expand !== FALSE && !format[0].inline) {
  14019. // Find new startContainer/endContainer if there is better one
  14020. startContainer = findSelectorEndPoint(startContainer, 'previousSibling');
  14021. endContainer = findSelectorEndPoint(endContainer, 'nextSibling');
  14022. }
  14023. // Expand start/end container to matching block element or text node
  14024. if (format[0].block || format[0].selector) {
  14025. // Find new startContainer/endContainer if there is better one
  14026. startContainer = findBlockEndPoint(startContainer, 'previousSibling');
  14027. endContainer = findBlockEndPoint(endContainer, 'nextSibling');
  14028. // Non block element then try to expand up the leaf
  14029. if (format[0].block) {
  14030. if (!isBlock(startContainer))
  14031. startContainer = findParentContainer(true);
  14032. if (!isBlock(endContainer))
  14033. endContainer = findParentContainer();
  14034. }
  14035. }
  14036. // Setup index for startContainer
  14037. if (startContainer.nodeType == 1) {
  14038. startOffset = nodeIndex(startContainer);
  14039. startContainer = startContainer.parentNode;
  14040. }
  14041. // Setup index for endContainer
  14042. if (endContainer.nodeType == 1) {
  14043. endOffset = nodeIndex(endContainer) + 1;
  14044. endContainer = endContainer.parentNode;
  14045. }
  14046. // Return new range like object
  14047. return {
  14048. startContainer : startContainer,
  14049. startOffset : startOffset,
  14050. endContainer : endContainer,
  14051. endOffset : endOffset
  14052. };
  14053. }
  14054. function removeFormat(format, vars, node, compare_node) {
  14055. var i, attrs, stylesModified;
  14056. // Check if node matches format
  14057. if (!matchName(node, format))
  14058. return FALSE;
  14059. // Should we compare with format attribs and styles
  14060. if (format.remove != 'all') {
  14061. // Remove styles
  14062. each(format.styles, function(value, name) {
  14063. value = replaceVars(value, vars);
  14064. // Indexed array
  14065. if (typeof(name) === 'number') {
  14066. name = value;
  14067. compare_node = 0;
  14068. }
  14069. if (!compare_node || isEq(getStyle(compare_node, name), value))
  14070. dom.setStyle(node, name, '');
  14071. stylesModified = 1;
  14072. });
  14073. // Remove style attribute if it's empty
  14074. if (stylesModified && dom.getAttrib(node, 'style') == '') {
  14075. node.removeAttribute('style');
  14076. node.removeAttribute('data-mce-style');
  14077. }
  14078. // Remove attributes
  14079. each(format.attributes, function(value, name) {
  14080. var valueOut;
  14081. value = replaceVars(value, vars);
  14082. // Indexed array
  14083. if (typeof(name) === 'number') {
  14084. name = value;
  14085. compare_node = 0;
  14086. }
  14087. if (!compare_node || isEq(dom.getAttrib(compare_node, name), value)) {
  14088. // Keep internal classes
  14089. if (name == 'class') {
  14090. value = dom.getAttrib(node, name);
  14091. if (value) {
  14092. // Build new class value where everything is removed except the internal prefixed classes
  14093. valueOut = '';
  14094. each(value.split(/\s+/), function(cls) {
  14095. if (/mce\w+/.test(cls))
  14096. valueOut += (valueOut ? ' ' : '') + cls;
  14097. });
  14098. // We got some internal classes left
  14099. if (valueOut) {
  14100. dom.setAttrib(node, name, valueOut);
  14101. return;
  14102. }
  14103. }
  14104. }
  14105. // IE6 has a bug where the attribute doesn't get removed correctly
  14106. if (name == "class")
  14107. node.removeAttribute('className');
  14108. // Remove mce prefixed attributes
  14109. if (MCE_ATTR_RE.test(name))
  14110. node.removeAttribute('data-mce-' + name);
  14111. node.removeAttribute(name);
  14112. }
  14113. });
  14114. // Remove classes
  14115. each(format.classes, function(value) {
  14116. value = replaceVars(value, vars);
  14117. if (!compare_node || dom.hasClass(compare_node, value))
  14118. dom.removeClass(node, value);
  14119. });
  14120. // Check for non internal attributes
  14121. attrs = dom.getAttribs(node);
  14122. for (i = 0; i < attrs.length; i++) {
  14123. if (attrs[i].nodeName.indexOf('_') !== 0)
  14124. return FALSE;
  14125. }
  14126. }
  14127. // Remove the inline child if it's empty for example <b> or <span>
  14128. if (format.remove != 'none') {
  14129. removeNode(node, format);
  14130. return TRUE;
  14131. }
  14132. };
  14133. function removeNode(node, format) {
  14134. var parentNode = node.parentNode, rootBlockElm;
  14135. function find(node, next, inc) {
  14136. node = getNonWhiteSpaceSibling(node, next, inc);
  14137. return !node || (node.nodeName == 'BR' || isBlock(node));
  14138. };
  14139. if (format.block) {
  14140. if (!forcedRootBlock) {
  14141. // Append BR elements if needed before we remove the block
  14142. if (isBlock(node) && !isBlock(parentNode)) {
  14143. if (!find(node, FALSE) && !find(node.firstChild, TRUE, 1))
  14144. node.insertBefore(dom.create('br'), node.firstChild);
  14145. if (!find(node, TRUE) && !find(node.lastChild, FALSE, 1))
  14146. node.appendChild(dom.create('br'));
  14147. }
  14148. } else {
  14149. // Wrap the block in a forcedRootBlock if we are at the root of document
  14150. if (parentNode == dom.getRoot()) {
  14151. if (!format.list_block || !isEq(node, format.list_block)) {
  14152. each(tinymce.grep(node.childNodes), function(node) {
  14153. if (isValid(forcedRootBlock, node.nodeName.toLowerCase())) {
  14154. if (!rootBlockElm)
  14155. rootBlockElm = wrap(node, forcedRootBlock);
  14156. else
  14157. rootBlockElm.appendChild(node);
  14158. } else
  14159. rootBlockElm = 0;
  14160. });
  14161. }
  14162. }
  14163. }
  14164. }
  14165. // Never remove nodes that isn't the specified inline element if a selector is specified too
  14166. if (format.selector && format.inline && !isEq(format.inline, node))
  14167. return;
  14168. dom.remove(node, 1);
  14169. };
  14170. function getNonWhiteSpaceSibling(node, next, inc) {
  14171. if (node) {
  14172. next = next ? 'nextSibling' : 'previousSibling';
  14173. for (node = inc ? node : node[next]; node; node = node[next]) {
  14174. if (node.nodeType == 1 || !isWhiteSpaceNode(node))
  14175. return node;
  14176. }
  14177. }
  14178. };
  14179. function isBookmarkNode(node) {
  14180. return node && node.nodeType == 1 && node.getAttribute('data-mce-type') == 'bookmark';
  14181. };
  14182. function mergeSiblings(prev, next) {
  14183. var marker, sibling, tmpSibling;
  14184. function compareElements(node1, node2) {
  14185. // Not the same name
  14186. if (node1.nodeName != node2.nodeName)
  14187. return FALSE;
  14188. function getAttribs(node) {
  14189. var attribs = {};
  14190. each(dom.getAttribs(node), function(attr) {
  14191. var name = attr.nodeName.toLowerCase();
  14192. // Don't compare internal attributes or style
  14193. if (name.indexOf('_') !== 0 && name !== 'style')
  14194. attribs[name] = dom.getAttrib(node, name);
  14195. });
  14196. return attribs;
  14197. };
  14198. function compareObjects(obj1, obj2) {
  14199. var value, name;
  14200. for (name in obj1) {
  14201. // Obj1 has item obj2 doesn't have
  14202. if (obj1.hasOwnProperty(name)) {
  14203. value = obj2[name];
  14204. // Obj2 doesn't have obj1 item
  14205. if (value === undef)
  14206. return FALSE;
  14207. // Obj2 item has a different value
  14208. if (obj1[name] != value)
  14209. return FALSE;
  14210. // Delete similar value
  14211. delete obj2[name];
  14212. }
  14213. }
  14214. // Check if obj 2 has something obj 1 doesn't have
  14215. for (name in obj2) {
  14216. // Obj2 has item obj1 doesn't have
  14217. if (obj2.hasOwnProperty(name))
  14218. return FALSE;
  14219. }
  14220. return TRUE;
  14221. };
  14222. // Attribs are not the same
  14223. if (!compareObjects(getAttribs(node1), getAttribs(node2)))
  14224. return FALSE;
  14225. // Styles are not the same
  14226. if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style'))))
  14227. return FALSE;
  14228. return TRUE;
  14229. };
  14230. function findElementSibling(node, sibling_name) {
  14231. for (sibling = node; sibling; sibling = sibling[sibling_name]) {
  14232. if (sibling.nodeType == 3 && sibling.nodeValue.length !== 0)
  14233. return node;
  14234. if (sibling.nodeType == 1 && !isBookmarkNode(sibling))
  14235. return sibling;
  14236. }
  14237. return node;
  14238. };
  14239. // Check if next/prev exists and that they are elements
  14240. if (prev && next) {
  14241. // If previous sibling is empty then jump over it
  14242. prev = findElementSibling(prev, 'previousSibling');
  14243. next = findElementSibling(next, 'nextSibling');
  14244. // Compare next and previous nodes
  14245. if (compareElements(prev, next)) {
  14246. // Append nodes between
  14247. for (sibling = prev.nextSibling; sibling && sibling != next;) {
  14248. tmpSibling = sibling;
  14249. sibling = sibling.nextSibling;
  14250. prev.appendChild(tmpSibling);
  14251. }
  14252. // Remove next node
  14253. dom.remove(next);
  14254. // Move children into prev node
  14255. each(tinymce.grep(next.childNodes), function(node) {
  14256. prev.appendChild(node);
  14257. });
  14258. return prev;
  14259. }
  14260. }
  14261. return next;
  14262. };
  14263. function isTextBlock(name) {
  14264. return /^(h[1-6]|p|div|pre|address|dl|dt|dd)$/.test(name);
  14265. };
  14266. function getContainer(rng, start) {
  14267. var container, offset, lastIdx, walker;
  14268. container = rng[start ? 'startContainer' : 'endContainer'];
  14269. offset = rng[start ? 'startOffset' : 'endOffset'];
  14270. if (container.nodeType == 1) {
  14271. lastIdx = container.childNodes.length - 1;
  14272. if (!start && offset)
  14273. offset--;
  14274. container = container.childNodes[offset > lastIdx ? lastIdx : offset];
  14275. }
  14276. // If start text node is excluded then walk to the next node
  14277. if (container.nodeType === 3 && start && offset >= container.nodeValue.length) {
  14278. container = new TreeWalker(container, ed.getBody()).next() || container;
  14279. }
  14280. // If end text node is excluded then walk to the previous node
  14281. if (container.nodeType === 3 && !start && offset === 0) {
  14282. container = new TreeWalker(container, ed.getBody()).prev() || container;
  14283. }
  14284. return container;
  14285. };
  14286. function performCaretAction(type, name, vars) {
  14287. var caretContainerId = '_mce_caret', debug = ed.settings.caret_debug;
  14288. // Creates a caret container bogus element
  14289. function createCaretContainer(fill) {
  14290. var caretContainer = dom.create('span', {id: caretContainerId, 'data-mce-bogus': true, style: debug ? 'color:red' : ''});
  14291. if (fill) {
  14292. caretContainer.appendChild(ed.getDoc().createTextNode(INVISIBLE_CHAR));
  14293. }
  14294. return caretContainer;
  14295. };
  14296. function isCaretContainerEmpty(node, nodes) {
  14297. while (node) {
  14298. if ((node.nodeType === 3 && node.nodeValue !== INVISIBLE_CHAR) || node.childNodes.length > 1) {
  14299. return false;
  14300. }
  14301. // Collect nodes
  14302. if (nodes && node.nodeType === 1) {
  14303. nodes.push(node);
  14304. }
  14305. node = node.firstChild;
  14306. }
  14307. return true;
  14308. };
  14309. // Returns any parent caret container element
  14310. function getParentCaretContainer(node) {
  14311. while (node) {
  14312. if (node.id === caretContainerId) {
  14313. return node;
  14314. }
  14315. node = node.parentNode;
  14316. }
  14317. };
  14318. // Finds the first text node in the specified node
  14319. function findFirstTextNode(node) {
  14320. var walker;
  14321. if (node) {
  14322. walker = new TreeWalker(node, node);
  14323. for (node = walker.current(); node; node = walker.next()) {
  14324. if (node.nodeType === 3) {
  14325. return node;
  14326. }
  14327. }
  14328. }
  14329. };
  14330. // Removes the caret container for the specified node or all on the current document
  14331. function removeCaretContainer(node, move_caret) {
  14332. var child, rng;
  14333. if (!node) {
  14334. node = getParentCaretContainer(selection.getStart());
  14335. if (!node) {
  14336. while (node = dom.get(caretContainerId)) {
  14337. removeCaretContainer(node, false);
  14338. }
  14339. }
  14340. } else {
  14341. rng = selection.getRng(true);
  14342. if (isCaretContainerEmpty(node)) {
  14343. if (move_caret !== false) {
  14344. rng.setStartBefore(node);
  14345. rng.setEndBefore(node);
  14346. }
  14347. dom.remove(node);
  14348. } else {
  14349. child = findFirstTextNode(node);
  14350. if (child.nodeValue.charAt(0) === INVISIBLE_CHAR) {
  14351. child = child.deleteData(0, 1);
  14352. }
  14353. dom.remove(node, 1);
  14354. }
  14355. selection.setRng(rng);
  14356. }
  14357. };
  14358. // Applies formatting to the caret postion
  14359. function applyCaretFormat() {
  14360. var rng, caretContainer, textNode, offset, bookmark, container, text;
  14361. rng = selection.getRng(true);
  14362. offset = rng.startOffset;
  14363. container = rng.startContainer;
  14364. text = container.nodeValue;
  14365. caretContainer = getParentCaretContainer(selection.getStart());
  14366. if (caretContainer) {
  14367. textNode = findFirstTextNode(caretContainer);
  14368. }
  14369. // Expand to word is caret is in the middle of a text node and the char before/after is a alpha numeric character
  14370. if (text && offset > 0 && offset < text.length && /\w/.test(text.charAt(offset)) && /\w/.test(text.charAt(offset - 1))) {
  14371. // Get bookmark of caret position
  14372. bookmark = selection.getBookmark();
  14373. // Collapse bookmark range (WebKit)
  14374. rng.collapse(true);
  14375. // Expand the range to the closest word and split it at those points
  14376. rng = expandRng(rng, get(name));
  14377. rng = rangeUtils.split(rng);
  14378. // Apply the format to the range
  14379. apply(name, vars, rng);
  14380. // Move selection back to caret position
  14381. selection.moveToBookmark(bookmark);
  14382. } else {
  14383. if (!caretContainer || textNode.nodeValue !== INVISIBLE_CHAR) {
  14384. caretContainer = createCaretContainer(true);
  14385. textNode = caretContainer.firstChild;
  14386. rng.insertNode(caretContainer);
  14387. offset = 1;
  14388. apply(name, vars, caretContainer);
  14389. } else {
  14390. apply(name, vars, caretContainer);
  14391. }
  14392. // Move selection to text node
  14393. selection.setCursorLocation(textNode, offset);
  14394. }
  14395. };
  14396. function removeCaretFormat() {
  14397. var rng = selection.getRng(true), container, offset, bookmark,
  14398. hasContentAfter, node, formatNode, parents = [], i, caretContainer;
  14399. container = rng.startContainer;
  14400. offset = rng.startOffset;
  14401. node = container;
  14402. if (container.nodeType == 3) {
  14403. if (offset != container.nodeValue.length || container.nodeValue === INVISIBLE_CHAR) {
  14404. hasContentAfter = true;
  14405. }
  14406. node = node.parentNode;
  14407. }
  14408. while (node) {
  14409. if (matchNode(node, name, vars)) {
  14410. formatNode = node;
  14411. break;
  14412. }
  14413. if (node.nextSibling) {
  14414. hasContentAfter = true;
  14415. }
  14416. parents.push(node);
  14417. node = node.parentNode;
  14418. }
  14419. // Node doesn't have the specified format
  14420. if (!formatNode) {
  14421. return;
  14422. }
  14423. // Is there contents after the caret then remove the format on the element
  14424. if (hasContentAfter) {
  14425. // Get bookmark of caret position
  14426. bookmark = selection.getBookmark();
  14427. // Collapse bookmark range (WebKit)
  14428. rng.collapse(true);
  14429. // Expand the range to the closest word and split it at those points
  14430. rng = expandRng(rng, get(name), true);
  14431. rng = rangeUtils.split(rng);
  14432. // Remove the format from the range
  14433. remove(name, vars, rng);
  14434. // Move selection back to caret position
  14435. selection.moveToBookmark(bookmark);
  14436. } else {
  14437. caretContainer = createCaretContainer();
  14438. node = caretContainer;
  14439. for (i = parents.length - 1; i >= 0; i--) {
  14440. node.appendChild(dom.clone(parents[i], false));
  14441. node = node.firstChild;
  14442. }
  14443. // Insert invisible character into inner most format element
  14444. node.appendChild(dom.doc.createTextNode(INVISIBLE_CHAR));
  14445. node = node.firstChild;
  14446. // Insert caret container after the formated node
  14447. dom.insertAfter(caretContainer, formatNode);
  14448. // Move selection to text node
  14449. selection.setCursorLocation(node, 1);
  14450. }
  14451. };
  14452. // Checks if the parent caret container node isn't empty if that is the case it
  14453. // will remove the bogus state on all children that isn't empty
  14454. function unmarkBogusCaretParents() {
  14455. var i, caretContainer, node;
  14456. caretContainer = getParentCaretContainer(selection.getStart());
  14457. if (caretContainer && !dom.isEmpty(caretContainer)) {
  14458. tinymce.walk(caretContainer, function(node) {
  14459. if (node.nodeType == 1 && node.id !== caretContainerId && !dom.isEmpty(node)) {
  14460. dom.setAttrib(node, 'data-mce-bogus', null);
  14461. }
  14462. }, 'childNodes');
  14463. }
  14464. };
  14465. // Only bind the caret events once
  14466. if (!self._hasCaretEvents) {
  14467. // Mark current caret container elements as bogus when getting the contents so we don't end up with empty elements
  14468. ed.onBeforeGetContent.addToTop(function() {
  14469. var nodes = [], i;
  14470. if (isCaretContainerEmpty(getParentCaretContainer(selection.getStart()), nodes)) {
  14471. // Mark children
  14472. i = nodes.length;
  14473. while (i--) {
  14474. dom.setAttrib(nodes[i], 'data-mce-bogus', '1');
  14475. }
  14476. }
  14477. });
  14478. // Remove caret container on mouse up and on key up
  14479. tinymce.each('onMouseUp onKeyUp'.split(' '), function(name) {
  14480. ed[name].addToTop(function() {
  14481. removeCaretContainer();
  14482. unmarkBogusCaretParents();
  14483. });
  14484. });
  14485. // Remove caret container on keydown and it's a backspace, enter or left/right arrow keys
  14486. ed.onKeyDown.addToTop(function(ed, e) {
  14487. var keyCode = e.keyCode;
  14488. if (keyCode == 8 || keyCode == 37 || keyCode == 39) {
  14489. removeCaretContainer(getParentCaretContainer(selection.getStart()));
  14490. }
  14491. unmarkBogusCaretParents();
  14492. });
  14493. // Remove bogus state if they got filled by contents using editor.selection.setContent
  14494. selection.onSetContent.add(unmarkBogusCaretParents);
  14495. self._hasCaretEvents = true;
  14496. }
  14497. // Do apply or remove caret format
  14498. if (type == "apply") {
  14499. applyCaretFormat();
  14500. } else {
  14501. removeCaretFormat();
  14502. }
  14503. };
  14504. function moveStart(rng) {
  14505. var container = rng.startContainer,
  14506. offset = rng.startOffset, isAtEndOfText,
  14507. walker, node, nodes, tmpNode;
  14508. // Convert text node into index if possible
  14509. if (container.nodeType == 3 && offset >= container.nodeValue.length) {
  14510. // Get the parent container location and walk from there
  14511. offset = nodeIndex(container);
  14512. container = container.parentNode;
  14513. isAtEndOfText = true;
  14514. }
  14515. // Move startContainer/startOffset in to a suitable node
  14516. if (container.nodeType == 1) {
  14517. nodes = container.childNodes;
  14518. container = nodes[Math.min(offset, nodes.length - 1)];
  14519. walker = new TreeWalker(container, dom.getParent(container, dom.isBlock));
  14520. // If offset is at end of the parent node walk to the next one
  14521. if (offset > nodes.length - 1 || isAtEndOfText)
  14522. walker.next();
  14523. for (node = walker.current(); node; node = walker.next()) {
  14524. if (node.nodeType == 3 && !isWhiteSpaceNode(node)) {
  14525. // IE has a "neat" feature where it moves the start node into the closest element
  14526. // we can avoid this by inserting an element before it and then remove it after we set the selection
  14527. tmpNode = dom.create('a', null, INVISIBLE_CHAR);
  14528. node.parentNode.insertBefore(tmpNode, node);
  14529. // Set selection and remove tmpNode
  14530. rng.setStart(node, 0);
  14531. selection.setRng(rng);
  14532. dom.remove(tmpNode);
  14533. return;
  14534. }
  14535. }
  14536. }
  14537. };
  14538. };
  14539. })(tinymce);
  14540. tinymce.onAddEditor.add(function(tinymce, ed) {
  14541. var filters, fontSizes, dom, settings = ed.settings;
  14542. function replaceWithSpan(node, styles) {
  14543. tinymce.each(styles, function(value, name) {
  14544. if (value)
  14545. dom.setStyle(node, name, value);
  14546. });
  14547. dom.rename(node, 'span');
  14548. };
  14549. function convert(editor, params) {
  14550. dom = editor.dom;
  14551. if (settings.convert_fonts_to_spans) {
  14552. tinymce.each(dom.select('font,u,strike', params.node), function(node) {
  14553. filters[node.nodeName.toLowerCase()](ed.dom, node);
  14554. });
  14555. }
  14556. };
  14557. if (settings.inline_styles) {
  14558. fontSizes = tinymce.explode(settings.font_size_legacy_values);
  14559. filters = {
  14560. font : function(dom, node) {
  14561. replaceWithSpan(node, {
  14562. backgroundColor : node.style.backgroundColor,
  14563. color : node.color,
  14564. fontFamily : node.face,
  14565. fontSize : fontSizes[parseInt(node.size, 10) - 1]
  14566. });
  14567. },
  14568. u : function(dom, node) {
  14569. replaceWithSpan(node, {
  14570. textDecoration : 'underline'
  14571. });
  14572. },
  14573. strike : function(dom, node) {
  14574. replaceWithSpan(node, {
  14575. textDecoration : 'line-through'
  14576. });
  14577. }
  14578. };
  14579. ed.onPreProcess.add(convert);
  14580. ed.onSetContent.add(convert);
  14581. ed.onInit.add(function() {
  14582. ed.selection.onSetContent.add(convert);
  14583. });
  14584. }
  14585. });
  14586. (function(tinymce) {
  14587. var TreeWalker = tinymce.dom.TreeWalker;
  14588. tinymce.EnterKey = function(editor) {
  14589. var dom = editor.dom, selection = editor.selection, settings = editor.settings, undoManager = editor.undoManager, nonEmptyElementsMap = editor.schema.getNonEmptyElements();
  14590. function handleEnterKey(evt) {
  14591. var rng = selection.getRng(true), tmpRng, editableRoot, container, offset, parentBlock, documentMode, shiftKey,
  14592. newBlock, fragment, containerBlock, parentBlockName, containerBlockName, newBlockName, isAfterLastNodeInContainer;
  14593. // Returns true if the block can be split into two blocks or not
  14594. function canSplitBlock(node) {
  14595. return node &&
  14596. dom.isBlock(node) &&
  14597. !/^(TD|TH|CAPTION|FORM)$/.test(node.nodeName) &&
  14598. !/^(fixed|absolute)/i.test(node.style.position) &&
  14599. dom.getContentEditable(node) !== "true";
  14600. };
  14601. // Renders empty block on IE
  14602. function renderBlockOnIE(block) {
  14603. var oldRng;
  14604. if (tinymce.isIE && dom.isBlock(block)) {
  14605. oldRng = selection.getRng();
  14606. block.appendChild(dom.create('span', null, '\u00a0'));
  14607. selection.select(block);
  14608. block.lastChild.outerHTML = '';
  14609. selection.setRng(oldRng);
  14610. }
  14611. };
  14612. // Remove the first empty inline element of the block so this: <p><b><em></em></b>x</p> becomes this: <p>x</p>
  14613. function trimInlineElementsOnLeftSideOfBlock(block) {
  14614. var node = block, firstChilds = [], i;
  14615. // Find inner most first child ex: <p><i><b>*</b></i></p>
  14616. while (node = node.firstChild) {
  14617. if (dom.isBlock(node)) {
  14618. return;
  14619. }
  14620. if (node.nodeType == 1 && !nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  14621. firstChilds.push(node);
  14622. }
  14623. }
  14624. i = firstChilds.length;
  14625. while (i--) {
  14626. node = firstChilds[i];
  14627. if (!node.hasChildNodes() || (node.firstChild == node.lastChild && node.firstChild.nodeValue === '')) {
  14628. dom.remove(node);
  14629. } else {
  14630. // Remove <a> </a> see #5381
  14631. if (node.nodeName == "A" && (node.innerText || node.textContent) === ' ') {
  14632. dom.remove(node);
  14633. }
  14634. }
  14635. }
  14636. };
  14637. // Moves the caret to a suitable position within the root for example in the first non pure whitespace text node or before an image
  14638. function moveToCaretPosition(root) {
  14639. var walker, node, rng, y, viewPort, lastNode = root, tempElm;
  14640. rng = dom.createRng();
  14641. if (root.hasChildNodes()) {
  14642. walker = new TreeWalker(root, root);
  14643. while (node = walker.current()) {
  14644. if (node.nodeType == 3) {
  14645. rng.setStart(node, 0);
  14646. rng.setEnd(node, 0);
  14647. break;
  14648. }
  14649. if (nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  14650. rng.setStartBefore(node);
  14651. rng.setEndBefore(node);
  14652. break;
  14653. }
  14654. lastNode = node;
  14655. node = walker.next();
  14656. }
  14657. if (!node) {
  14658. rng.setStart(lastNode, 0);
  14659. rng.setEnd(lastNode, 0);
  14660. }
  14661. } else {
  14662. if (root.nodeName == 'BR') {
  14663. if (root.nextSibling && dom.isBlock(root.nextSibling)) {
  14664. // Trick on older IE versions to render the caret before the BR between two lists
  14665. if (!documentMode || documentMode < 9) {
  14666. tempElm = dom.create('br');
  14667. root.parentNode.insertBefore(tempElm, root);
  14668. }
  14669. rng.setStartBefore(root);
  14670. rng.setEndBefore(root);
  14671. } else {
  14672. rng.setStartAfter(root);
  14673. rng.setEndAfter(root);
  14674. }
  14675. } else {
  14676. rng.setStart(root, 0);
  14677. rng.setEnd(root, 0);
  14678. }
  14679. }
  14680. selection.setRng(rng);
  14681. // Remove tempElm created for old IE:s
  14682. dom.remove(tempElm);
  14683. viewPort = dom.getViewPort(editor.getWin());
  14684. // 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
  14685. y = dom.getPos(root).y;
  14686. if (y < viewPort.y || y + 25 > viewPort.y + viewPort.h) {
  14687. editor.getWin().scrollTo(0, y < viewPort.y ? y : y - viewPort.h + 25); // Needs to be hardcoded to roughly one line of text if a huge text block is broken into two blocks
  14688. }
  14689. };
  14690. // Creates a new block element by cloning the current one or creating a new one if the name is specified
  14691. // This function will also copy any text formatting from the parent block and add it to the new one
  14692. function createNewBlock(name) {
  14693. var node = container, block, clonedNode, caretNode;
  14694. block = name || parentBlockName == "TABLE" ? dom.create(name || newBlockName) : parentBlock.cloneNode(false);
  14695. caretNode = block;
  14696. // Clone any parent styles
  14697. if (settings.keep_styles !== false) {
  14698. do {
  14699. if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(node.nodeName)) {
  14700. // Never clone a caret containers
  14701. if (node.id == '_mce_caret') {
  14702. continue;
  14703. }
  14704. clonedNode = node.cloneNode(false);
  14705. dom.setAttrib(clonedNode, 'id', ''); // Remove ID since it needs to be document unique
  14706. if (block.hasChildNodes()) {
  14707. clonedNode.appendChild(block.firstChild);
  14708. block.appendChild(clonedNode);
  14709. } else {
  14710. caretNode = clonedNode;
  14711. block.appendChild(clonedNode);
  14712. }
  14713. }
  14714. } while (node = node.parentNode);
  14715. }
  14716. // BR is needed in empty blocks on non IE browsers
  14717. if (!tinymce.isIE) {
  14718. caretNode.innerHTML = '<br data-mce-bogus="1">';
  14719. }
  14720. return block;
  14721. };
  14722. // Returns true/false if the caret is at the start/end of the parent block element
  14723. function isCaretAtStartOrEndOfBlock(start) {
  14724. var walker, node, name;
  14725. // Caret is in the middle of a text node like "a|b"
  14726. if (container.nodeType == 3 && (start ? offset > 0 : offset < container.nodeValue.length)) {
  14727. return false;
  14728. }
  14729. // If after the last element in block node edge case for #5091
  14730. if (container.parentNode == parentBlock && isAfterLastNodeInContainer && !start) {
  14731. return true;
  14732. }
  14733. // If the caret if before the first element in parentBlock
  14734. if (start && container.nodeType == 1 && container == parentBlock.firstChild) {
  14735. return true;
  14736. }
  14737. // Caret can be before/after a table
  14738. if (container.nodeName === "TABLE" || (container.previousSibling && container.previousSibling.nodeName == "TABLE")) {
  14739. return (isAfterLastNodeInContainer && !start) || (!isAfterLastNodeInContainer && start);
  14740. }
  14741. // Walk the DOM and look for text nodes or non empty elements
  14742. walker = new TreeWalker(container, parentBlock);
  14743. // If caret is in beginning or end of a text block then jump to the next/previous node
  14744. if (container.nodeType == 3) {
  14745. if (start && offset == 0) {
  14746. walker.prev();
  14747. } else if (!start && offset == container.nodeValue.length) {
  14748. walker.next();
  14749. }
  14750. }
  14751. while (node = walker.current()) {
  14752. if (node.nodeType === 1) {
  14753. // Ignore bogus elements
  14754. if (!node.getAttribute('data-mce-bogus')) {
  14755. // Keep empty elements like <img /> <input /> but not trailing br:s like <p>text|<br></p>
  14756. name = node.nodeName.toLowerCase();
  14757. if (nonEmptyElementsMap[name] && name !== 'br') {
  14758. return false;
  14759. }
  14760. }
  14761. } else if (node.nodeType === 3 && !/^[ \t\r\n]*$/.test(node.nodeValue)) {
  14762. return false;
  14763. }
  14764. if (start) {
  14765. walker.prev();
  14766. } else {
  14767. walker.next();
  14768. }
  14769. }
  14770. return true;
  14771. };
  14772. // Wraps any text nodes or inline elements in the specified forced root block name
  14773. function wrapSelfAndSiblingsInDefaultBlock(container, offset) {
  14774. var newBlock, parentBlock, startNode, node, next, blockName = newBlockName || 'P';
  14775. // Not in a block element or in a table cell or caption
  14776. parentBlock = dom.getParent(container, dom.isBlock);
  14777. if (!parentBlock || !canSplitBlock(parentBlock)) {
  14778. parentBlock = parentBlock || editableRoot;
  14779. if (!parentBlock.hasChildNodes()) {
  14780. newBlock = dom.create(blockName);
  14781. parentBlock.appendChild(newBlock);
  14782. rng.setStart(newBlock, 0);
  14783. rng.setEnd(newBlock, 0);
  14784. return newBlock;
  14785. }
  14786. // Find parent that is the first child of parentBlock
  14787. node = container;
  14788. while (node.parentNode != parentBlock) {
  14789. node = node.parentNode;
  14790. }
  14791. // Loop left to find start node start wrapping at
  14792. while (node && !dom.isBlock(node)) {
  14793. startNode = node;
  14794. node = node.previousSibling;
  14795. }
  14796. if (startNode) {
  14797. newBlock = dom.create(blockName);
  14798. startNode.parentNode.insertBefore(newBlock, startNode);
  14799. // Start wrapping until we hit a block
  14800. node = startNode;
  14801. while (node && !dom.isBlock(node)) {
  14802. next = node.nextSibling;
  14803. newBlock.appendChild(node);
  14804. node = next;
  14805. }
  14806. // Restore range to it's past location
  14807. rng.setStart(container, offset);
  14808. rng.setEnd(container, offset);
  14809. }
  14810. }
  14811. return container;
  14812. };
  14813. // Inserts a block or br before/after or in the middle of a split list of the LI is empty
  14814. function handleEmptyListItem() {
  14815. function isFirstOrLastLi(first) {
  14816. var node = containerBlock[first ? 'firstChild' : 'lastChild'];
  14817. // Find first/last element since there might be whitespace there
  14818. while (node) {
  14819. if (node.nodeType == 1) {
  14820. break;
  14821. }
  14822. node = node[first ? 'nextSibling' : 'previousSibling'];
  14823. }
  14824. return node === parentBlock;
  14825. };
  14826. newBlock = newBlockName ? createNewBlock(newBlockName) : dom.create('BR');
  14827. if (isFirstOrLastLi(true) && isFirstOrLastLi()) {
  14828. // Is first and last list item then replace the OL/UL with a text block
  14829. dom.replace(newBlock, containerBlock);
  14830. } else if (isFirstOrLastLi(true)) {
  14831. // First LI in list then remove LI and add text block before list
  14832. containerBlock.parentNode.insertBefore(newBlock, containerBlock);
  14833. } else if (isFirstOrLastLi()) {
  14834. // Last LI in list then temove LI and add text block after list
  14835. dom.insertAfter(newBlock, containerBlock);
  14836. renderBlockOnIE(newBlock);
  14837. } else {
  14838. // Middle LI in list the split the list and insert a text block in the middle
  14839. // Extract after fragment and insert it after the current block
  14840. tmpRng = rng.cloneRange();
  14841. tmpRng.setStartAfter(parentBlock);
  14842. tmpRng.setEndAfter(containerBlock);
  14843. fragment = tmpRng.extractContents();
  14844. dom.insertAfter(fragment, containerBlock);
  14845. dom.insertAfter(newBlock, containerBlock);
  14846. }
  14847. dom.remove(parentBlock);
  14848. moveToCaretPosition(newBlock);
  14849. undoManager.add();
  14850. };
  14851. // Walks the parent block to the right and look for BR elements
  14852. function hasRightSideBr() {
  14853. var walker = new TreeWalker(container, parentBlock), node;
  14854. while (node = walker.current()) {
  14855. if (node.nodeName == 'BR') {
  14856. return true;
  14857. }
  14858. node = walker.next();
  14859. }
  14860. }
  14861. // Inserts a BR element if the forced_root_block option is set to false or empty string
  14862. function insertBr() {
  14863. var brElm, extraBr, marker;
  14864. if (container && container.nodeType == 3 && offset >= container.nodeValue.length) {
  14865. // Insert extra BR element at the end block elements
  14866. if (!tinymce.isIE && !hasRightSideBr()) {
  14867. brElm = dom.create('br');
  14868. rng.insertNode(brElm);
  14869. rng.setStartAfter(brElm);
  14870. rng.setEndAfter(brElm);
  14871. extraBr = true;
  14872. }
  14873. }
  14874. brElm = dom.create('br');
  14875. rng.insertNode(brElm);
  14876. // Rendering modes below IE8 doesn't display BR elements in PRE unless we have a \n before it
  14877. if (tinymce.isIE && parentBlockName == 'PRE' && (!documentMode || documentMode < 8)) {
  14878. brElm.parentNode.insertBefore(dom.doc.createTextNode('\r'), brElm);
  14879. }
  14880. // Insert temp marker and scroll to that
  14881. marker = dom.create('span', {}, '&nbsp;');
  14882. brElm.parentNode.insertBefore(marker, brElm);
  14883. selection.scrollIntoView(marker);
  14884. dom.remove(marker);
  14885. if (!extraBr) {
  14886. rng.setStartAfter(brElm);
  14887. rng.setEndAfter(brElm);
  14888. } else {
  14889. rng.setStartBefore(brElm);
  14890. rng.setEndBefore(brElm);
  14891. }
  14892. selection.setRng(rng);
  14893. undoManager.add();
  14894. };
  14895. // Trims any linebreaks at the beginning of node user for example when pressing enter in a PRE element
  14896. function trimLeadingLineBreaks(node) {
  14897. do {
  14898. if (node.nodeType === 3) {
  14899. node.nodeValue = node.nodeValue.replace(/^[\r\n]+/, '');
  14900. }
  14901. node = node.firstChild;
  14902. } while (node);
  14903. };
  14904. function getEditableRoot(node) {
  14905. var root = dom.getRoot(), parent, editableRoot;
  14906. // Get all parents until we hit a non editable parent or the root
  14907. parent = node;
  14908. while (parent !== root && dom.getContentEditable(parent) !== "false") {
  14909. if (dom.getContentEditable(parent) === "true") {
  14910. editableRoot = parent;
  14911. }
  14912. parent = parent.parentNode;
  14913. }
  14914. return parent !== root ? editableRoot : root;
  14915. };
  14916. // Adds a BR at the end of blocks that only contains an IMG or INPUT since these might be floated and then they won't expand the block
  14917. function addBrToBlockIfNeeded(block) {
  14918. var lastChild;
  14919. // IE will render the blocks correctly other browsers needs a BR
  14920. if (!tinymce.isIE) {
  14921. block.normalize(); // Remove empty text nodes that got left behind by the extract
  14922. // Check if the block is empty or contains a floated last child
  14923. lastChild = block.lastChild;
  14924. if (!lastChild || (/^(left|right)$/gi.test(dom.getStyle(lastChild, 'float', true)))) {
  14925. dom.add(block, 'br');
  14926. }
  14927. }
  14928. };
  14929. // Delete any selected contents
  14930. if (!rng.collapsed) {
  14931. editor.execCommand('Delete');
  14932. return;
  14933. }
  14934. // Event is blocked by some other handler for example the lists plugin
  14935. if (evt.isDefaultPrevented()) {
  14936. return;
  14937. }
  14938. // Setup range items and newBlockName
  14939. container = rng.startContainer;
  14940. offset = rng.startOffset;
  14941. newBlockName = (settings.force_p_newlines ? 'p' : '') || settings.forced_root_block;
  14942. newBlockName = newBlockName ? newBlockName.toUpperCase() : '';
  14943. documentMode = dom.doc.documentMode;
  14944. shiftKey = evt.shiftKey;
  14945. // Resolve node index
  14946. if (container.nodeType == 1 && container.hasChildNodes()) {
  14947. isAfterLastNodeInContainer = offset > container.childNodes.length - 1;
  14948. container = container.childNodes[Math.min(offset, container.childNodes.length - 1)] || container;
  14949. if (isAfterLastNodeInContainer && container.nodeType == 3) {
  14950. offset = container.nodeValue.length;
  14951. } else {
  14952. offset = 0;
  14953. }
  14954. }
  14955. // Get editable root node normaly the body element but sometimes a div or span
  14956. editableRoot = getEditableRoot(container);
  14957. // If there is no editable root then enter is done inside a contentEditable false element
  14958. if (!editableRoot) {
  14959. return;
  14960. }
  14961. undoManager.beforeChange();
  14962. // If editable root isn't block nor the root of the editor
  14963. if (!dom.isBlock(editableRoot) && editableRoot != dom.getRoot()) {
  14964. if (!newBlockName || shiftKey) {
  14965. insertBr();
  14966. }
  14967. return;
  14968. }
  14969. // Wrap the current node and it's sibling in a default block if it's needed.
  14970. // for example this <td>text|<b>text2</b></td> will become this <td><p>text|<b>text2</p></b></td>
  14971. // This won't happen if root blocks are disabled or the shiftKey is pressed
  14972. if ((newBlockName && !shiftKey) || (!newBlockName && shiftKey)) {
  14973. container = wrapSelfAndSiblingsInDefaultBlock(container, offset);
  14974. }
  14975. // Find parent block and setup empty block paddings
  14976. parentBlock = dom.getParent(container, dom.isBlock);
  14977. containerBlock = parentBlock ? dom.getParent(parentBlock.parentNode, dom.isBlock) : null;
  14978. // Setup block names
  14979. parentBlockName = parentBlock ? parentBlock.nodeName.toUpperCase() : ''; // IE < 9 & HTML5
  14980. containerBlockName = containerBlock ? containerBlock.nodeName.toUpperCase() : ''; // IE < 9 & HTML5
  14981. // Enter inside block contained within a LI then split or insert before/after LI
  14982. if (containerBlockName == 'LI' && !evt.ctrlKey) {
  14983. parentBlock = containerBlock;
  14984. parentBlockName = containerBlockName;
  14985. }
  14986. // Handle enter in LI
  14987. if (parentBlockName == 'LI') {
  14988. if (!newBlockName && shiftKey) {
  14989. insertBr();
  14990. return;
  14991. }
  14992. // Handle enter inside an empty list item
  14993. if (dom.isEmpty(parentBlock)) {
  14994. // Let the list plugin or browser handle nested lists for now
  14995. if (/^(UL|OL|LI)$/.test(containerBlock.parentNode.nodeName)) {
  14996. return false;
  14997. }
  14998. handleEmptyListItem();
  14999. return;
  15000. }
  15001. }
  15002. // Don't split PRE tags but insert a BR instead easier when writing code samples etc
  15003. if (parentBlockName == 'PRE' && settings.br_in_pre !== false) {
  15004. if (!shiftKey) {
  15005. insertBr();
  15006. return;
  15007. }
  15008. } else {
  15009. // If no root block is configured then insert a BR by default or if the shiftKey is pressed
  15010. if ((!newBlockName && !shiftKey && parentBlockName != 'LI') || (newBlockName && shiftKey)) {
  15011. insertBr();
  15012. return;
  15013. }
  15014. }
  15015. // Default block name if it's not configured
  15016. newBlockName = newBlockName || 'P';
  15017. // Insert new block before/after the parent block depending on caret location
  15018. if (isCaretAtStartOrEndOfBlock()) {
  15019. // If the caret is at the end of a header we produce a P tag after it similar to Word unless we are in a hgroup
  15020. if (/^(H[1-6]|PRE)$/.test(parentBlockName) && containerBlockName != 'HGROUP') {
  15021. newBlock = createNewBlock(newBlockName);
  15022. } else {
  15023. newBlock = createNewBlock();
  15024. }
  15025. // Split the current container block element if enter is pressed inside an empty inner block element
  15026. if (settings.end_container_on_empty_block && canSplitBlock(containerBlock) && dom.isEmpty(parentBlock)) {
  15027. // Split container block for example a BLOCKQUOTE at the current blockParent location for example a P
  15028. newBlock = dom.split(containerBlock, parentBlock);
  15029. } else {
  15030. dom.insertAfter(newBlock, parentBlock);
  15031. }
  15032. moveToCaretPosition(newBlock);
  15033. } else if (isCaretAtStartOrEndOfBlock(true)) {
  15034. // Insert new block before
  15035. newBlock = parentBlock.parentNode.insertBefore(createNewBlock(), parentBlock);
  15036. renderBlockOnIE(newBlock);
  15037. } else {
  15038. // Extract after fragment and insert it after the current block
  15039. tmpRng = rng.cloneRange();
  15040. tmpRng.setEndAfter(parentBlock);
  15041. fragment = tmpRng.extractContents();
  15042. trimLeadingLineBreaks(fragment);
  15043. newBlock = fragment.firstChild;
  15044. dom.insertAfter(fragment, parentBlock);
  15045. trimInlineElementsOnLeftSideOfBlock(newBlock);
  15046. addBrToBlockIfNeeded(parentBlock);
  15047. moveToCaretPosition(newBlock);
  15048. }
  15049. dom.setAttrib(newBlock, 'id', ''); // Remove ID since it needs to be document unique
  15050. undoManager.add();
  15051. }
  15052. editor.onKeyDown.add(function(ed, evt) {
  15053. if (evt.keyCode == 13) {
  15054. if (handleEnterKey(evt) !== false) {
  15055. evt.preventDefault();
  15056. }
  15057. }
  15058. });
  15059. };
  15060. })(tinymce);