tiny_mce_src.js 498 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642
  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.4.1',
  8. releaseDate : '2012-06-24',
  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' && (o.hasOwnProperty && o instanceof Array))
  80. return true;
  81. return typeof(o) == t;
  82. },
  83. makeMap : function(items, delim, map) {
  84. var i;
  85. items = items || [];
  86. delim = delim || ',';
  87. if (typeof(items) == "string")
  88. items = items.split(delim);
  89. map = map || {};
  90. i = items.length;
  91. while (i--)
  92. map[items[i]] = {};
  93. return map;
  94. },
  95. each : function(o, cb, s) {
  96. var n, l;
  97. if (!o)
  98. return 0;
  99. s = s || o;
  100. if (o.length !== undef) {
  101. // Indexed arrays, needed for Safari
  102. for (n=0, l = o.length; n < l; n++) {
  103. if (cb.call(s, o[n], n, o) === false)
  104. return 0;
  105. }
  106. } else {
  107. // Hashtables
  108. for (n in o) {
  109. if (o.hasOwnProperty(n)) {
  110. if (cb.call(s, o[n], n, o) === false)
  111. return 0;
  112. }
  113. }
  114. }
  115. return 1;
  116. },
  117. map : function(a, f) {
  118. var o = [];
  119. tinymce.each(a, function(v) {
  120. o.push(f(v));
  121. });
  122. return o;
  123. },
  124. grep : function(a, f) {
  125. var o = [];
  126. tinymce.each(a, function(v) {
  127. if (!f || f(v))
  128. o.push(v);
  129. });
  130. return o;
  131. },
  132. inArray : function(a, v) {
  133. var i, l;
  134. if (a) {
  135. for (i = 0, l = a.length; i < l; i++) {
  136. if (a[i] === v)
  137. return i;
  138. }
  139. }
  140. return -1;
  141. },
  142. extend : function(obj, ext) {
  143. var i, l, name, args = arguments, value;
  144. for (i = 1, l = args.length; i < l; i++) {
  145. ext = args[i];
  146. for (name in ext) {
  147. if (ext.hasOwnProperty(name)) {
  148. value = ext[name];
  149. if (value !== undef) {
  150. obj[name] = value;
  151. }
  152. }
  153. }
  154. }
  155. return obj;
  156. },
  157. trim : function(s) {
  158. return (s ? '' + s : '').replace(whiteSpaceRe, '');
  159. },
  160. create : function(s, p, root) {
  161. var t = this, sp, ns, cn, scn, c, de = 0;
  162. // Parse : <prefix> <class>:<super class>
  163. s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s);
  164. cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name
  165. // Create namespace for new class
  166. ns = t.createNS(s[3].replace(/\.\w+$/, ''), root);
  167. // Class already exists
  168. if (ns[cn])
  169. return;
  170. // Make pure static class
  171. if (s[2] == 'static') {
  172. ns[cn] = p;
  173. if (this.onCreate)
  174. this.onCreate(s[2], s[3], ns[cn]);
  175. return;
  176. }
  177. // Create default constructor
  178. if (!p[cn]) {
  179. p[cn] = function() {};
  180. de = 1;
  181. }
  182. // Add constructor and methods
  183. ns[cn] = p[cn];
  184. t.extend(ns[cn].prototype, p);
  185. // Extend
  186. if (s[5]) {
  187. sp = t.resolve(s[5]).prototype;
  188. scn = s[5].match(/\.(\w+)$/i)[1]; // Class name
  189. // Extend constructor
  190. c = ns[cn];
  191. if (de) {
  192. // Add passthrough constructor
  193. ns[cn] = function() {
  194. return sp[scn].apply(this, arguments);
  195. };
  196. } else {
  197. // Add inherit constructor
  198. ns[cn] = function() {
  199. this.parent = sp[scn];
  200. return c.apply(this, arguments);
  201. };
  202. }
  203. ns[cn].prototype[cn] = ns[cn];
  204. // Add super methods
  205. t.each(sp, function(f, n) {
  206. ns[cn].prototype[n] = sp[n];
  207. });
  208. // Add overridden methods
  209. t.each(p, function(f, n) {
  210. // Extend methods if needed
  211. if (sp[n]) {
  212. ns[cn].prototype[n] = function() {
  213. this.parent = sp[n];
  214. return f.apply(this, arguments);
  215. };
  216. } else {
  217. if (n != cn)
  218. ns[cn].prototype[n] = f;
  219. }
  220. });
  221. }
  222. // Add static methods
  223. t.each(p['static'], function(f, n) {
  224. ns[cn][n] = f;
  225. });
  226. if (this.onCreate)
  227. this.onCreate(s[2], s[3], ns[cn].prototype);
  228. },
  229. walk : function(o, f, n, s) {
  230. s = s || this;
  231. if (o) {
  232. if (n)
  233. o = o[n];
  234. tinymce.each(o, function(o, i) {
  235. if (f.call(s, o, i, n) === false)
  236. return false;
  237. tinymce.walk(o, f, n, s);
  238. });
  239. }
  240. },
  241. createNS : function(n, o) {
  242. var i, v;
  243. o = o || win;
  244. n = n.split('.');
  245. for (i=0; i<n.length; i++) {
  246. v = n[i];
  247. if (!o[v])
  248. o[v] = {};
  249. o = o[v];
  250. }
  251. return o;
  252. },
  253. resolve : function(n, o) {
  254. var i, l;
  255. o = o || win;
  256. n = n.split('.');
  257. for (i = 0, l = n.length; i < l; i++) {
  258. o = o[n[i]];
  259. if (!o)
  260. break;
  261. }
  262. return o;
  263. },
  264. addUnload : function(f, s) {
  265. var t = this, unload;
  266. unload = function() {
  267. var li = t.unloads, o, n;
  268. if (li) {
  269. // Call unload handlers
  270. for (n in li) {
  271. o = li[n];
  272. if (o && o.func)
  273. o.func.call(o.scope, 1); // Send in one arg to distinct unload and user destroy
  274. }
  275. // Detach unload function
  276. if (win.detachEvent) {
  277. win.detachEvent('onbeforeunload', fakeUnload);
  278. win.detachEvent('onunload', unload);
  279. } else if (win.removeEventListener)
  280. win.removeEventListener('unload', unload, false);
  281. // Destroy references
  282. t.unloads = o = li = w = unload = 0;
  283. // Run garbarge collector on IE
  284. if (win.CollectGarbage)
  285. CollectGarbage();
  286. }
  287. };
  288. function fakeUnload() {
  289. var d = document;
  290. function stop() {
  291. // Prevent memory leak
  292. d.detachEvent('onstop', stop);
  293. // Call unload handler
  294. if (unload)
  295. unload();
  296. d = 0;
  297. };
  298. // Is there things still loading, then do some magic
  299. if (d.readyState == 'interactive') {
  300. // Fire unload when the currently loading page is stopped
  301. if (d)
  302. d.attachEvent('onstop', stop);
  303. // Remove onstop listener after a while to prevent the unload function
  304. // to execute if the user presses cancel in an onbeforeunload
  305. // confirm dialog and then presses the browser stop button
  306. win.setTimeout(function() {
  307. if (d)
  308. d.detachEvent('onstop', stop);
  309. }, 0);
  310. }
  311. };
  312. f = {func : f, scope : s || this};
  313. if (!t.unloads) {
  314. // Attach unload handler
  315. if (win.attachEvent) {
  316. win.attachEvent('onunload', unload);
  317. win.attachEvent('onbeforeunload', fakeUnload);
  318. } else if (win.addEventListener)
  319. win.addEventListener('unload', unload, false);
  320. // Setup initial unload handler array
  321. t.unloads = [f];
  322. } else
  323. t.unloads.push(f);
  324. return f;
  325. },
  326. removeUnload : function(f) {
  327. var u = this.unloads, r = null;
  328. tinymce.each(u, function(o, i) {
  329. if (o && o.func == f) {
  330. u.splice(i, 1);
  331. r = f;
  332. return false;
  333. }
  334. });
  335. return r;
  336. },
  337. explode : function(s, d) {
  338. if (!s || tinymce.is(s, 'array')) {
  339. return s;
  340. }
  341. return tinymce.map(s.split(d || ','), tinymce.trim);
  342. },
  343. _addVer : function(u) {
  344. var v;
  345. if (!this.query)
  346. return u;
  347. v = (u.indexOf('?') == -1 ? '?' : '&') + this.query;
  348. if (u.indexOf('#') == -1)
  349. return u + v;
  350. return u.replace('#', v + '#');
  351. },
  352. // Fix function for IE 9 where regexps isn't working correctly
  353. // Todo: remove me once MS fixes the bug
  354. _replace : function(find, replace, str) {
  355. // On IE9 we have to fake $x replacement
  356. if (isRegExpBroken) {
  357. return str.replace(find, function() {
  358. var val = replace, args = arguments, i;
  359. for (i = 0; i < args.length - 2; i++) {
  360. if (args[i] === undef) {
  361. val = val.replace(new RegExp('\\$' + i, 'g'), '');
  362. } else {
  363. val = val.replace(new RegExp('\\$' + i, 'g'), args[i]);
  364. }
  365. }
  366. return val;
  367. });
  368. }
  369. return str.replace(find, replace);
  370. }
  371. };
  372. // Initialize the API
  373. tinymce._init();
  374. // Expose tinymce namespace to the global namespace (window)
  375. win.tinymce = win.tinyMCE = tinymce;
  376. // Describe the different namespaces
  377. })(window);
  378. tinymce.create('tinymce.util.Dispatcher', {
  379. scope : null,
  380. listeners : null,
  381. inDispatch: false,
  382. Dispatcher : function(scope) {
  383. this.scope = scope || this;
  384. this.listeners = [];
  385. },
  386. add : function(callback, scope) {
  387. this.listeners.push({cb : callback, scope : scope || this.scope});
  388. return callback;
  389. },
  390. addToTop : function(callback, scope) {
  391. var self = this, listener = {cb : callback, scope : scope || self.scope};
  392. // Create new listeners if addToTop is executed in a dispatch loop
  393. if (self.inDispatch) {
  394. self.listeners = [listener].concat(self.listeners);
  395. } else {
  396. self.listeners.unshift(listener);
  397. }
  398. return callback;
  399. },
  400. remove : function(callback) {
  401. var listeners = this.listeners, output = null;
  402. tinymce.each(listeners, function(listener, i) {
  403. if (callback == listener.cb) {
  404. output = listener;
  405. listeners.splice(i, 1);
  406. return false;
  407. }
  408. });
  409. return output;
  410. },
  411. dispatch : function() {
  412. var self = this, returnValue, args = arguments, i, listeners = self.listeners, listener;
  413. self.inDispatch = true;
  414. // Needs to be a real loop since the listener count might change while looping
  415. // And this is also more efficient
  416. for (i = 0; i < listeners.length; i++) {
  417. listener = listeners[i];
  418. returnValue = listener.cb.apply(listener.scope, args.length > 0 ? args : [listener.scope]);
  419. if (returnValue === false)
  420. break;
  421. }
  422. self.inDispatch = false;
  423. return returnValue;
  424. }
  425. });
  426. (function() {
  427. var each = tinymce.each;
  428. tinymce.create('tinymce.util.URI', {
  429. URI : function(u, s) {
  430. var t = this, o, a, b, base_url;
  431. // Trim whitespace
  432. u = tinymce.trim(u);
  433. // Default settings
  434. s = t.settings = s || {};
  435. // Strange app protocol that isn't http/https or local anchor
  436. // For example: mailto,skype,tel etc.
  437. if (/^([\w\-]+):([^\/]{2})/i.test(u) || /^\s*#/.test(u)) {
  438. t.source = u;
  439. return;
  440. }
  441. // Absolute path with no host, fake host and protocol
  442. if (u.indexOf('/') === 0 && u.indexOf('//') !== 0)
  443. u = (s.base_uri ? s.base_uri.protocol || 'http' : 'http') + '://mce_host' + u;
  444. // Relative path http:// or protocol relative //path
  445. if (!/^[\w\-]*:?\/\//.test(u)) {
  446. base_url = s.base_uri ? s.base_uri.path : new tinymce.util.URI(location.href).directory;
  447. u = ((s.base_uri && s.base_uri.protocol) || 'http') + '://mce_host' + t.toAbsPath(base_url, u);
  448. }
  449. // Parse URL (Credits goes to Steave, http://blog.stevenlevithan.com/archives/parseuri)
  450. u = u.replace(/@@/g, '(mce_at)'); // Zope 3 workaround, they use @@something
  451. u = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(u);
  452. each(["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], function(v, i) {
  453. var s = u[i];
  454. // Zope 3 workaround, they use @@something
  455. if (s)
  456. s = s.replace(/\(mce_at\)/g, '@@');
  457. t[v] = s;
  458. });
  459. b = s.base_uri;
  460. if (b) {
  461. if (!t.protocol)
  462. t.protocol = b.protocol;
  463. if (!t.userInfo)
  464. t.userInfo = b.userInfo;
  465. if (!t.port && t.host === 'mce_host')
  466. t.port = b.port;
  467. if (!t.host || t.host === 'mce_host')
  468. t.host = b.host;
  469. t.source = '';
  470. }
  471. //t.path = t.path || '/';
  472. },
  473. setPath : function(p) {
  474. var t = this;
  475. p = /^(.*?)\/?(\w+)?$/.exec(p);
  476. // Update path parts
  477. t.path = p[0];
  478. t.directory = p[1];
  479. t.file = p[2];
  480. // Rebuild source
  481. t.source = '';
  482. t.getURI();
  483. },
  484. toRelative : function(u) {
  485. var t = this, o;
  486. if (u === "./")
  487. return u;
  488. u = new tinymce.util.URI(u, {base_uri : t});
  489. // Not on same domain/port or protocol
  490. if ((u.host != 'mce_host' && t.host != u.host && u.host) || t.port != u.port || t.protocol != u.protocol)
  491. return u.getURI();
  492. var tu = t.getURI(), uu = u.getURI();
  493. // Allow usage of the base_uri when relative_urls = true
  494. if(tu == uu || (tu.charAt(tu.length - 1) == "/" && tu.substr(0, tu.length - 1) == uu))
  495. return tu;
  496. o = t.toRelPath(t.path, u.path);
  497. // Add query
  498. if (u.query)
  499. o += '?' + u.query;
  500. // Add anchor
  501. if (u.anchor)
  502. o += '#' + u.anchor;
  503. return o;
  504. },
  505. toAbsolute : function(u, nh) {
  506. u = new tinymce.util.URI(u, {base_uri : this});
  507. return u.getURI(this.host == u.host && this.protocol == u.protocol ? nh : 0);
  508. },
  509. toRelPath : function(base, path) {
  510. var items, bp = 0, out = '', i, l;
  511. // Split the paths
  512. base = base.substring(0, base.lastIndexOf('/'));
  513. base = base.split('/');
  514. items = path.split('/');
  515. if (base.length >= items.length) {
  516. for (i = 0, l = base.length; i < l; i++) {
  517. if (i >= items.length || base[i] != items[i]) {
  518. bp = i + 1;
  519. break;
  520. }
  521. }
  522. }
  523. if (base.length < items.length) {
  524. for (i = 0, l = items.length; i < l; i++) {
  525. if (i >= base.length || base[i] != items[i]) {
  526. bp = i + 1;
  527. break;
  528. }
  529. }
  530. }
  531. if (bp === 1)
  532. return path;
  533. for (i = 0, l = base.length - (bp - 1); i < l; i++)
  534. out += "../";
  535. for (i = bp - 1, l = items.length; i < l; i++) {
  536. if (i != bp - 1)
  537. out += "/" + items[i];
  538. else
  539. out += items[i];
  540. }
  541. return out;
  542. },
  543. toAbsPath : function(base, path) {
  544. var i, nb = 0, o = [], tr, outPath;
  545. // Split paths
  546. tr = /\/$/.test(path) ? '/' : '';
  547. base = base.split('/');
  548. path = path.split('/');
  549. // Remove empty chunks
  550. each(base, function(k) {
  551. if (k)
  552. o.push(k);
  553. });
  554. base = o;
  555. // Merge relURLParts chunks
  556. for (i = path.length - 1, o = []; i >= 0; i--) {
  557. // Ignore empty or .
  558. if (path[i].length === 0 || path[i] === ".")
  559. continue;
  560. // Is parent
  561. if (path[i] === '..') {
  562. nb++;
  563. continue;
  564. }
  565. // Move up
  566. if (nb > 0) {
  567. nb--;
  568. continue;
  569. }
  570. o.push(path[i]);
  571. }
  572. i = base.length - nb;
  573. // If /a/b/c or /
  574. if (i <= 0)
  575. outPath = o.reverse().join('/');
  576. else
  577. outPath = base.slice(0, i).join('/') + '/' + o.reverse().join('/');
  578. // Add front / if it's needed
  579. if (outPath.indexOf('/') !== 0)
  580. outPath = '/' + outPath;
  581. // Add traling / if it's needed
  582. if (tr && outPath.lastIndexOf('/') !== outPath.length - 1)
  583. outPath += tr;
  584. return outPath;
  585. },
  586. getURI : function(nh) {
  587. var s, t = this;
  588. // Rebuild source
  589. if (!t.source || nh) {
  590. s = '';
  591. if (!nh) {
  592. if (t.protocol)
  593. s += t.protocol + '://';
  594. if (t.userInfo)
  595. s += t.userInfo + '@';
  596. if (t.host)
  597. s += t.host;
  598. if (t.port)
  599. s += ':' + t.port;
  600. }
  601. if (t.path)
  602. s += t.path;
  603. if (t.query)
  604. s += '?' + t.query;
  605. if (t.anchor)
  606. s += '#' + t.anchor;
  607. t.source = s;
  608. }
  609. return t.source;
  610. }
  611. });
  612. })();
  613. (function() {
  614. var each = tinymce.each;
  615. tinymce.create('static tinymce.util.Cookie', {
  616. getHash : function(n) {
  617. var v = this.get(n), h;
  618. if (v) {
  619. each(v.split('&'), function(v) {
  620. v = v.split('=');
  621. h = h || {};
  622. h[unescape(v[0])] = unescape(v[1]);
  623. });
  624. }
  625. return h;
  626. },
  627. setHash : function(n, v, e, p, d, s) {
  628. var o = '';
  629. each(v, function(v, k) {
  630. o += (!o ? '' : '&') + escape(k) + '=' + escape(v);
  631. });
  632. this.set(n, o, e, p, d, s);
  633. },
  634. get : function(n) {
  635. var c = document.cookie, e, p = n + "=", b;
  636. // Strict mode
  637. if (!c)
  638. return;
  639. b = c.indexOf("; " + p);
  640. if (b == -1) {
  641. b = c.indexOf(p);
  642. if (b !== 0)
  643. return null;
  644. } else
  645. b += 2;
  646. e = c.indexOf(";", b);
  647. if (e == -1)
  648. e = c.length;
  649. return unescape(c.substring(b + p.length, e));
  650. },
  651. set : function(n, v, e, p, d, s) {
  652. document.cookie = n + "=" + escape(v) +
  653. ((e) ? "; expires=" + e.toGMTString() : "") +
  654. ((p) ? "; path=" + escape(p) : "") +
  655. ((d) ? "; domain=" + d : "") +
  656. ((s) ? "; secure" : "");
  657. },
  658. remove : function(name, path, domain) {
  659. var date = new Date();
  660. date.setTime(date.getTime() - 1000);
  661. this.set(name, '', date, path, domain);
  662. }
  663. });
  664. })();
  665. (function() {
  666. function serialize(o, quote) {
  667. var i, v, t, name;
  668. quote = quote || '"';
  669. if (o == null)
  670. return 'null';
  671. t = typeof o;
  672. if (t == 'string') {
  673. v = '\bb\tt\nn\ff\rr\""\'\'\\\\';
  674. return quote + o.replace(/([\u0080-\uFFFF\x00-\x1f\"\'\\])/g, function(a, b) {
  675. // Make sure single quotes never get encoded inside double quotes for JSON compatibility
  676. if (quote === '"' && a === "'")
  677. return a;
  678. i = v.indexOf(b);
  679. if (i + 1)
  680. return '\\' + v.charAt(i + 1);
  681. a = b.charCodeAt().toString(16);
  682. return '\\u' + '0000'.substring(a.length) + a;
  683. }) + quote;
  684. }
  685. if (t == 'object') {
  686. if (o.hasOwnProperty && o instanceof Array) {
  687. for (i=0, v = '['; i<o.length; i++)
  688. v += (i > 0 ? ',' : '') + serialize(o[i], quote);
  689. return v + ']';
  690. }
  691. v = '{';
  692. for (name in o) {
  693. if (o.hasOwnProperty(name)) {
  694. v += typeof o[name] != 'function' ? (v.length > 1 ? ',' + quote : quote) + name + quote +':' + serialize(o[name], quote) : '';
  695. }
  696. }
  697. return v + '}';
  698. }
  699. return '' + o;
  700. };
  701. tinymce.util.JSON = {
  702. serialize: serialize,
  703. parse: function(s) {
  704. try {
  705. return eval('(' + s + ')');
  706. } catch (ex) {
  707. // Ignore
  708. }
  709. }
  710. };
  711. })();
  712. tinymce.create('static tinymce.util.XHR', {
  713. send : function(o) {
  714. var x, t, w = window, c = 0;
  715. function ready() {
  716. if (!o.async || x.readyState == 4 || c++ > 10000) {
  717. if (o.success && c < 10000 && x.status == 200)
  718. o.success.call(o.success_scope, '' + x.responseText, x, o);
  719. else if (o.error)
  720. o.error.call(o.error_scope, c > 10000 ? 'TIMED_OUT' : 'GENERAL', x, o);
  721. x = null;
  722. } else
  723. w.setTimeout(ready, 10);
  724. };
  725. // Default settings
  726. o.scope = o.scope || this;
  727. o.success_scope = o.success_scope || o.scope;
  728. o.error_scope = o.error_scope || o.scope;
  729. o.async = o.async === false ? false : true;
  730. o.data = o.data || '';
  731. function get(s) {
  732. x = 0;
  733. try {
  734. x = new ActiveXObject(s);
  735. } catch (ex) {
  736. }
  737. return x;
  738. };
  739. x = w.XMLHttpRequest ? new XMLHttpRequest() : get('Microsoft.XMLHTTP') || get('Msxml2.XMLHTTP');
  740. if (x) {
  741. if (x.overrideMimeType)
  742. x.overrideMimeType(o.content_type);
  743. x.open(o.type || (o.data ? 'POST' : 'GET'), o.url, o.async);
  744. if (o.content_type)
  745. x.setRequestHeader('Content-Type', o.content_type);
  746. x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  747. x.send(o.data);
  748. // Syncronous request
  749. if (!o.async)
  750. return ready();
  751. // Wait for response, onReadyStateChange can not be used since it leaks memory in IE
  752. t = w.setTimeout(ready, 10);
  753. }
  754. }
  755. });
  756. (function() {
  757. var extend = tinymce.extend, JSON = tinymce.util.JSON, XHR = tinymce.util.XHR;
  758. tinymce.create('tinymce.util.JSONRequest', {
  759. JSONRequest : function(s) {
  760. this.settings = extend({
  761. }, s);
  762. this.count = 0;
  763. },
  764. send : function(o) {
  765. var ecb = o.error, scb = o.success;
  766. o = extend(this.settings, o);
  767. o.success = function(c, x) {
  768. c = JSON.parse(c);
  769. if (typeof(c) == 'undefined') {
  770. c = {
  771. error : 'JSON Parse error.'
  772. };
  773. }
  774. if (c.error)
  775. ecb.call(o.error_scope || o.scope, c.error, x);
  776. else
  777. scb.call(o.success_scope || o.scope, c.result);
  778. };
  779. o.error = function(ty, x) {
  780. if (ecb)
  781. ecb.call(o.error_scope || o.scope, ty, x);
  782. };
  783. o.data = JSON.serialize({
  784. id : o.id || 'c' + (this.count++),
  785. method : o.method,
  786. params : o.params
  787. });
  788. // JSON content type for Ruby on rails. Bug: #1883287
  789. o.content_type = 'application/json';
  790. XHR.send(o);
  791. },
  792. 'static' : {
  793. sendRPC : function(o) {
  794. return new tinymce.util.JSONRequest().send(o);
  795. }
  796. }
  797. });
  798. }());
  799. (function(tinymce){
  800. tinymce.VK = {
  801. BACKSPACE: 8,
  802. DELETE: 46,
  803. DOWN: 40,
  804. ENTER: 13,
  805. LEFT: 37,
  806. RIGHT: 39,
  807. SPACEBAR: 32,
  808. TAB: 9,
  809. UP: 38,
  810. modifierPressed: function (e) {
  811. return e.shiftKey || e.ctrlKey || e.altKey;
  812. },
  813. metaKeyPressed: function(e) {
  814. return tinymce.isMac ? e.metaKey : e.ctrlKey;
  815. }
  816. };
  817. })(tinymce);
  818. tinymce.util.Quirks = function(editor) {
  819. var VK = tinymce.VK, BACKSPACE = VK.BACKSPACE, DELETE = VK.DELETE, dom = editor.dom, selection = editor.selection, settings = editor.settings;
  820. function setEditorCommandState(cmd, state) {
  821. try {
  822. editor.getDoc().execCommand(cmd, false, state);
  823. } catch (ex) {
  824. // Ignore
  825. }
  826. }
  827. function getDocumentMode() {
  828. var documentMode = editor.getDoc().documentMode;
  829. return documentMode ? documentMode : 6;
  830. };
  831. function cleanupStylesWhenDeleting() {
  832. function removeMergedFormatSpans(isDelete) {
  833. var rng, blockElm, node, clonedSpan;
  834. rng = selection.getRng();
  835. // Find root block
  836. blockElm = dom.getParent(rng.startContainer, dom.isBlock);
  837. // On delete clone the root span of the next block element
  838. if (isDelete)
  839. blockElm = dom.getNext(blockElm, dom.isBlock);
  840. // Locate root span element and clone it since it would otherwise get merged by the "apple-style-span" on delete/backspace
  841. if (blockElm) {
  842. node = blockElm.firstChild;
  843. // Ignore empty text nodes
  844. while (node && node.nodeType == 3 && node.nodeValue.length === 0)
  845. node = node.nextSibling;
  846. if (node && node.nodeName === 'SPAN') {
  847. clonedSpan = node.cloneNode(false);
  848. }
  849. }
  850. // Do the backspace/delete action
  851. editor.getDoc().execCommand(isDelete ? 'ForwardDelete' : 'Delete', false, null);
  852. // Find all odd apple-style-spans
  853. blockElm = dom.getParent(rng.startContainer, dom.isBlock);
  854. tinymce.each(dom.select('span.Apple-style-span,font.Apple-style-span', blockElm), function(span) {
  855. var bm = selection.getBookmark();
  856. if (clonedSpan) {
  857. dom.replace(clonedSpan.cloneNode(false), span, true);
  858. } else {
  859. dom.remove(span, true);
  860. }
  861. // Restore the selection
  862. selection.moveToBookmark(bm);
  863. });
  864. };
  865. editor.onKeyDown.add(function(editor, e) {
  866. var isDelete;
  867. isDelete = e.keyCode == DELETE;
  868. if (!e.isDefaultPrevented() && (isDelete || e.keyCode == BACKSPACE) && !VK.modifierPressed(e)) {
  869. e.preventDefault();
  870. removeMergedFormatSpans(isDelete);
  871. }
  872. });
  873. editor.addCommand('Delete', function() {removeMergedFormatSpans();});
  874. };
  875. function emptyEditorWhenDeleting() {
  876. function serializeRng(rng) {
  877. var body = dom.create("body");
  878. var contents = rng.cloneContents();
  879. body.appendChild(contents);
  880. return selection.serializer.serialize(body, {format: 'html'});
  881. }
  882. function allContentsSelected(rng) {
  883. var selection = serializeRng(rng);
  884. var allRng = dom.createRng();
  885. allRng.selectNode(editor.getBody());
  886. var allSelection = serializeRng(allRng);//console.log(selection, "----", allSelection);
  887. return selection === allSelection;
  888. }
  889. editor.onKeyDown.add(function(editor, e) {
  890. var keyCode = e.keyCode, isCollapsed;
  891. // Empty the editor if it's needed for example backspace at <p><b>|</b></p>
  892. if (!e.isDefaultPrevented() && (keyCode == DELETE || keyCode == BACKSPACE)) {
  893. isCollapsed = editor.selection.isCollapsed();
  894. // Selection is collapsed but the editor isn't empty
  895. if (isCollapsed && !dom.isEmpty(editor.getBody())) {
  896. return;
  897. }
  898. // IE deletes all contents correctly when everything is selected
  899. if (tinymce.isIE && !isCollapsed) {
  900. return;
  901. }
  902. // Selection isn't collapsed but not all the contents is selected
  903. if (!isCollapsed && !allContentsSelected(editor.selection.getRng())) {
  904. return;
  905. }
  906. // Manually empty the editor
  907. editor.setContent('');
  908. editor.selection.setCursorLocation(editor.getBody(), 0);
  909. editor.nodeChanged();
  910. }
  911. });
  912. };
  913. function selectAll() {
  914. editor.onKeyDown.add(function(editor, e) {
  915. if (e.keyCode == 65 && VK.metaKeyPressed(e)) {
  916. e.preventDefault();
  917. editor.execCommand('SelectAll');
  918. }
  919. });
  920. };
  921. function inputMethodFocus() {
  922. if (!editor.settings.content_editable) {
  923. // Case 1 IME doesn't initialize if you focus the document
  924. dom.bind(editor.getDoc(), 'focusin', function(e) {
  925. selection.setRng(selection.getRng());
  926. });
  927. // Case 2 IME doesn't initialize if you click the documentElement it also doesn't properly fire the focusin event
  928. dom.bind(editor.getDoc(), 'mousedown', function(e) {
  929. if (e.target == editor.getDoc().documentElement) {
  930. editor.getWin().focus();
  931. selection.setRng(selection.getRng());
  932. }
  933. });
  934. }
  935. };
  936. function removeHrOnBackspace() {
  937. editor.onKeyDown.add(function(editor, e) {
  938. if (!e.isDefaultPrevented() && e.keyCode === BACKSPACE) {
  939. if (selection.isCollapsed() && selection.getRng(true).startOffset === 0) {
  940. var node = selection.getNode();
  941. var previousSibling = node.previousSibling;
  942. if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === "hr") {
  943. dom.remove(previousSibling);
  944. tinymce.dom.Event.cancel(e);
  945. }
  946. }
  947. }
  948. })
  949. }
  950. function focusBody() {
  951. // Fix for a focus bug in FF 3.x where the body element
  952. // wouldn't get proper focus if the user clicked on the HTML element
  953. if (!Range.prototype.getClientRects) { // Detect getClientRects got introduced in FF 4
  954. editor.onMouseDown.add(function(editor, e) {
  955. if (e.target.nodeName === "HTML") {
  956. var body = editor.getBody();
  957. // Blur the body it's focused but not correctly focused
  958. body.blur();
  959. // Refocus the body after a little while
  960. setTimeout(function() {
  961. body.focus();
  962. }, 0);
  963. }
  964. });
  965. }
  966. };
  967. function selectControlElements() {
  968. editor.onClick.add(function(editor, e) {
  969. e = e.target;
  970. // Workaround for bug, http://bugs.webkit.org/show_bug.cgi?id=12250
  971. // WebKit can't even do simple things like selecting an image
  972. // Needs tobe the setBaseAndExtend or it will fail to select floated images
  973. if (/^(IMG|HR)$/.test(e.nodeName)) {
  974. selection.getSel().setBaseAndExtent(e, 0, e, 1);
  975. }
  976. if (e.nodeName == 'A' && dom.hasClass(e, 'mceItemAnchor')) {
  977. selection.select(e);
  978. }
  979. editor.nodeChanged();
  980. });
  981. };
  982. function removeStylesWhenDeletingAccrossBlockElements() {
  983. function getAttributeApplyFunction() {
  984. var template = dom.getAttribs(selection.getStart().cloneNode(false));
  985. return function() {
  986. var target = selection.getStart();
  987. if (target !== editor.getBody()) {
  988. dom.setAttrib(target, "style", null);
  989. tinymce.each(template, function(attr) {
  990. target.setAttributeNode(attr.cloneNode(true));
  991. });
  992. }
  993. };
  994. }
  995. function isSelectionAcrossElements() {
  996. return !selection.isCollapsed() && selection.getStart() != selection.getEnd();
  997. }
  998. function blockEvent(editor, e) {
  999. e.preventDefault();
  1000. return false;
  1001. }
  1002. editor.onKeyPress.add(function(editor, e) {
  1003. var applyAttributes;
  1004. if ((e.keyCode == 8 || e.keyCode == 46) && isSelectionAcrossElements()) {
  1005. applyAttributes = getAttributeApplyFunction();
  1006. editor.getDoc().execCommand('delete', false, null);
  1007. applyAttributes();
  1008. e.preventDefault();
  1009. return false;
  1010. }
  1011. });
  1012. dom.bind(editor.getDoc(), 'cut', function(e) {
  1013. var applyAttributes;
  1014. if (isSelectionAcrossElements()) {
  1015. applyAttributes = getAttributeApplyFunction();
  1016. editor.onKeyUp.addToTop(blockEvent);
  1017. setTimeout(function() {
  1018. applyAttributes();
  1019. editor.onKeyUp.remove(blockEvent);
  1020. }, 0);
  1021. }
  1022. });
  1023. }
  1024. function selectionChangeNodeChanged() {
  1025. var lastRng, selectionTimer;
  1026. dom.bind(editor.getDoc(), 'selectionchange', function() {
  1027. if (selectionTimer) {
  1028. clearTimeout(selectionTimer);
  1029. selectionTimer = 0;
  1030. }
  1031. selectionTimer = window.setTimeout(function() {
  1032. var rng = selection.getRng();
  1033. // Compare the ranges to see if it was a real change or not
  1034. if (!lastRng || !tinymce.dom.RangeUtils.compareRanges(rng, lastRng)) {
  1035. editor.nodeChanged();
  1036. lastRng = rng;
  1037. }
  1038. }, 50);
  1039. });
  1040. }
  1041. function ensureBodyHasRoleApplication() {
  1042. document.body.setAttribute("role", "application");
  1043. }
  1044. function disableBackspaceIntoATable() {
  1045. editor.onKeyDown.add(function(editor, e) {
  1046. if (!e.isDefaultPrevented() && e.keyCode === BACKSPACE) {
  1047. if (selection.isCollapsed() && selection.getRng(true).startOffset === 0) {
  1048. var previousSibling = selection.getNode().previousSibling;
  1049. if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === "table") {
  1050. return tinymce.dom.Event.cancel(e);
  1051. }
  1052. }
  1053. }
  1054. })
  1055. }
  1056. function addNewLinesBeforeBrInPre() {
  1057. // IE8+ rendering mode does the right thing with BR in PRE
  1058. if (getDocumentMode() > 7) {
  1059. return;
  1060. }
  1061. // Enable display: none in area and add a specific class that hides all BR elements in PRE to
  1062. // avoid the caret from getting stuck at the BR elements while pressing the right arrow key
  1063. setEditorCommandState('RespectVisibilityInDesign', true);
  1064. editor.contentStyles.push('.mceHideBrInPre pre br {display: none}');
  1065. dom.addClass(editor.getBody(), 'mceHideBrInPre');
  1066. // Adds a \n before all BR elements in PRE to get them visual
  1067. editor.parser.addNodeFilter('pre', function(nodes, name) {
  1068. var i = nodes.length, brNodes, j, brElm, sibling;
  1069. while (i--) {
  1070. brNodes = nodes[i].getAll('br');
  1071. j = brNodes.length;
  1072. while (j--) {
  1073. brElm = brNodes[j];
  1074. // Add \n before BR in PRE elements on older IE:s so the new lines get rendered
  1075. sibling = brElm.prev;
  1076. if (sibling && sibling.type === 3 && sibling.value.charAt(sibling.value - 1) != '\n') {
  1077. sibling.value += '\n';
  1078. } else {
  1079. brElm.parent.insert(new tinymce.html.Node('#text', 3), brElm, true).value = '\n';
  1080. }
  1081. }
  1082. }
  1083. });
  1084. // Removes any \n before BR elements in PRE since other browsers and in contentEditable=false mode they will be visible
  1085. editor.serializer.addNodeFilter('pre', function(nodes, name) {
  1086. var i = nodes.length, brNodes, j, brElm, sibling;
  1087. while (i--) {
  1088. brNodes = nodes[i].getAll('br');
  1089. j = brNodes.length;
  1090. while (j--) {
  1091. brElm = brNodes[j];
  1092. sibling = brElm.prev;
  1093. if (sibling && sibling.type == 3) {
  1094. sibling.value = sibling.value.replace(/\r?\n$/, '');
  1095. }
  1096. }
  1097. }
  1098. });
  1099. }
  1100. function removePreSerializedStylesWhenSelectingControls() {
  1101. dom.bind(editor.getBody(), 'mouseup', function(e) {
  1102. var value, node = selection.getNode();
  1103. // Moved styles to attributes on IMG eements
  1104. if (node.nodeName == 'IMG') {
  1105. // Convert style width to width attribute
  1106. if (value = dom.getStyle(node, 'width')) {
  1107. dom.setAttrib(node, 'width', value.replace(/[^0-9%]+/g, ''));
  1108. dom.setStyle(node, 'width', '');
  1109. }
  1110. // Convert style height to height attribute
  1111. if (value = dom.getStyle(node, 'height')) {
  1112. dom.setAttrib(node, 'height', value.replace(/[^0-9%]+/g, ''));
  1113. dom.setStyle(node, 'height', '');
  1114. }
  1115. }
  1116. });
  1117. }
  1118. function keepInlineElementOnDeleteBackspace() {
  1119. editor.onKeyDown.add(function(editor, e) {
  1120. var isDelete, rng, container, offset, brElm, sibling, collapsed;
  1121. isDelete = e.keyCode == DELETE;
  1122. if (!e.isDefaultPrevented() && (isDelete || e.keyCode == BACKSPACE) && !VK.modifierPressed(e)) {
  1123. rng = selection.getRng();
  1124. container = rng.startContainer;
  1125. offset = rng.startOffset;
  1126. collapsed = rng.collapsed;
  1127. // Override delete if the start container is a text node and is at the beginning of text or
  1128. // just before/after the last character to be deleted in collapsed mode
  1129. if (container.nodeType == 3 && container.nodeValue.length > 0 && ((offset === 0 && !collapsed) || (collapsed && offset === (isDelete ? 0 : 1)))) {
  1130. nonEmptyElements = editor.schema.getNonEmptyElements();
  1131. // Prevent default logic since it's broken
  1132. e.preventDefault();
  1133. // Insert a BR before the text node this will prevent the containing element from being deleted/converted
  1134. brElm = dom.create('br', {id: '__tmp'});
  1135. container.parentNode.insertBefore(brElm, container);
  1136. // Do the browser delete
  1137. editor.getDoc().execCommand(isDelete ? 'ForwardDelete' : 'Delete', false, null);
  1138. // Check if the previous sibling is empty after deleting for example: <p><b></b>|</p>
  1139. container = selection.getRng().startContainer;
  1140. sibling = container.previousSibling;
  1141. if (sibling && sibling.nodeType == 1 && !dom.isBlock(sibling) && dom.isEmpty(sibling) && !nonEmptyElements[sibling.nodeName.toLowerCase()]) {
  1142. dom.remove(sibling);
  1143. }
  1144. // Remove the temp element we inserted
  1145. dom.remove('__tmp');
  1146. }
  1147. }
  1148. });
  1149. }
  1150. function removeBlockQuoteOnBackSpace() {
  1151. // Add block quote deletion handler
  1152. editor.onKeyDown.add(function(editor, e) {
  1153. var rng, container, offset, root, parent;
  1154. if (e.isDefaultPrevented() || e.keyCode != VK.BACKSPACE) {
  1155. return;
  1156. }
  1157. rng = selection.getRng();
  1158. container = rng.startContainer;
  1159. offset = rng.startOffset;
  1160. root = dom.getRoot();
  1161. parent = container;
  1162. if (!rng.collapsed || offset !== 0) {
  1163. return;
  1164. }
  1165. while (parent && parent.parentNode && parent.parentNode.firstChild == parent && parent.parentNode != root) {
  1166. parent = parent.parentNode;
  1167. }
  1168. // Is the cursor at the beginning of a blockquote?
  1169. if (parent.tagName === 'BLOCKQUOTE') {
  1170. // Remove the blockquote
  1171. editor.formatter.toggle('blockquote', null, parent);
  1172. // Move the caret to the beginning of container
  1173. rng.setStart(container, 0);
  1174. rng.setEnd(container, 0);
  1175. selection.setRng(rng);
  1176. selection.collapse(false);
  1177. }
  1178. });
  1179. };
  1180. function setGeckoEditingOptions() {
  1181. function setOpts() {
  1182. editor._refreshContentEditable();
  1183. setEditorCommandState("StyleWithCSS", false);
  1184. setEditorCommandState("enableInlineTableEditing", false);
  1185. if (!settings.object_resizing) {
  1186. setEditorCommandState("enableObjectResizing", false);
  1187. }
  1188. };
  1189. if (!settings.readonly) {
  1190. editor.onBeforeExecCommand.add(setOpts);
  1191. editor.onMouseDown.add(setOpts);
  1192. }
  1193. };
  1194. function addBrAfterLastLinks() {
  1195. function fixLinks(editor, o) {
  1196. tinymce.each(dom.select('a'), function(node) {
  1197. var parentNode = node.parentNode, root = dom.getRoot();
  1198. if (parentNode.lastChild === node) {
  1199. while (parentNode && !dom.isBlock(parentNode)) {
  1200. if (parentNode.parentNode.lastChild !== parentNode || parentNode === root) {
  1201. return;
  1202. }
  1203. parentNode = parentNode.parentNode;
  1204. }
  1205. dom.add(parentNode, 'br', {'data-mce-bogus' : 1});
  1206. }
  1207. });
  1208. };
  1209. editor.onExecCommand.add(function(editor, cmd) {
  1210. if (cmd === 'CreateLink') {
  1211. fixLinks(editor);
  1212. }
  1213. });
  1214. editor.onSetContent.add(selection.onSetContent.add(fixLinks));
  1215. };
  1216. function setDefaultBlockType() {
  1217. if (settings.forced_root_block) {
  1218. editor.onInit.add(function() {
  1219. setEditorCommandState('DefaultParagraphSeparator', settings.forced_root_block);
  1220. });
  1221. }
  1222. }
  1223. function removeGhostSelection() {
  1224. function repaint(sender, args) {
  1225. if (!sender || !args.initial) {
  1226. editor.execCommand('mceRepaint');
  1227. }
  1228. };
  1229. editor.onUndo.add(repaint);
  1230. editor.onRedo.add(repaint);
  1231. editor.onSetContent.add(repaint);
  1232. };
  1233. function deleteControlItemOnBackSpace() {
  1234. editor.onKeyDown.add(function(editor, e) {
  1235. var rng;
  1236. if (!e.isDefaultPrevented() && e.keyCode == BACKSPACE) {
  1237. rng = editor.getDoc().selection.createRange();
  1238. if (rng && rng.item) {
  1239. e.preventDefault();
  1240. editor.undoManager.beforeChange();
  1241. dom.remove(rng.item(0));
  1242. editor.undoManager.add();
  1243. }
  1244. }
  1245. });
  1246. };
  1247. function renderEmptyBlocksFix() {
  1248. var emptyBlocksCSS;
  1249. // IE10+
  1250. if (getDocumentMode() >= 10) {
  1251. emptyBlocksCSS = '';
  1252. tinymce.each('p div h1 h2 h3 h4 h5 h6'.split(' '), function(name, i) {
  1253. emptyBlocksCSS += (i > 0 ? ',' : '') + name + ':empty';
  1254. });
  1255. editor.contentStyles.push(emptyBlocksCSS + '{padding-right: 1px !important}');
  1256. }
  1257. };
  1258. function fakeImageResize() {
  1259. var mouseDownImg, startX, startY, startW, startH;
  1260. if (!settings.object_resizing || settings.webkit_fake_resize === false) {
  1261. return;
  1262. }
  1263. editor.contentStyles.push('.mceResizeImages img {cursor: se-resize !important}');
  1264. function resizeImage(e) {
  1265. var deltaX, deltaY, ratio, width, height;
  1266. if (mouseDownImg) {
  1267. deltaX = e.screenX - startX;
  1268. deltaY = e.screenY - startY;
  1269. ratio = Math.max((startW + deltaX) / startW, (startH + deltaY) / startH);
  1270. // Only update styles if the user draged one pixel or more
  1271. if (Math.abs(deltaX) > 1 || Math.abs(deltaY) > 1) {
  1272. // Constrain proportions
  1273. width = Math.round(startW * ratio);
  1274. height = Math.round(startH * ratio);
  1275. // Resize by using style or attribute
  1276. if (mouseDownImg.style.width) {
  1277. dom.setStyle(mouseDownImg, 'width', width);
  1278. } else {
  1279. dom.setAttrib(mouseDownImg, 'width', width);
  1280. }
  1281. // Resize by using style or attribute
  1282. if (mouseDownImg.style.height) {
  1283. dom.setStyle(mouseDownImg, 'height', height);
  1284. } else {
  1285. dom.setAttrib(mouseDownImg, 'height', height);
  1286. }
  1287. if (!dom.hasClass(editor.getBody(), 'mceResizeImages')) {
  1288. dom.addClass(editor.getBody(), 'mceResizeImages');
  1289. }
  1290. }
  1291. }
  1292. };
  1293. editor.onMouseDown.add(function(editor, e) {
  1294. var target = e.target;
  1295. if (target.nodeName == "IMG") {
  1296. mouseDownImg = target;
  1297. startX = e.screenX;
  1298. startY = e.screenY;
  1299. startW = mouseDownImg.clientWidth;
  1300. startH = mouseDownImg.clientHeight;
  1301. dom.bind(editor.getDoc(), 'mousemove', resizeImage);
  1302. e.preventDefault();
  1303. }
  1304. });
  1305. // Unbind events on node change and restore resize cursor
  1306. editor.onNodeChange.add(function() {
  1307. if (mouseDownImg) {
  1308. mouseDownImg = null;
  1309. dom.unbind(editor.getDoc(), 'mousemove', resizeImage);
  1310. }
  1311. if (selection.getNode().nodeName == "IMG") {
  1312. dom.addClass(editor.getBody(), 'mceResizeImages');
  1313. } else {
  1314. dom.removeClass(editor.getBody(), 'mceResizeImages');
  1315. }
  1316. });
  1317. };
  1318. // All browsers
  1319. disableBackspaceIntoATable();
  1320. removeBlockQuoteOnBackSpace();
  1321. emptyEditorWhenDeleting();
  1322. // WebKit
  1323. if (tinymce.isWebKit) {
  1324. keepInlineElementOnDeleteBackspace();
  1325. cleanupStylesWhenDeleting();
  1326. inputMethodFocus();
  1327. selectControlElements();
  1328. setDefaultBlockType();
  1329. // iOS
  1330. if (tinymce.isIDevice) {
  1331. selectionChangeNodeChanged();
  1332. } else {
  1333. fakeImageResize();
  1334. selectAll();
  1335. }
  1336. }
  1337. // IE
  1338. if (tinymce.isIE) {
  1339. removeHrOnBackspace();
  1340. ensureBodyHasRoleApplication();
  1341. addNewLinesBeforeBrInPre();
  1342. removePreSerializedStylesWhenSelectingControls();
  1343. deleteControlItemOnBackSpace();
  1344. renderEmptyBlocksFix();
  1345. }
  1346. // Gecko
  1347. if (tinymce.isGecko) {
  1348. removeHrOnBackspace();
  1349. focusBody();
  1350. removeStylesWhenDeletingAccrossBlockElements();
  1351. setGeckoEditingOptions();
  1352. addBrAfterLastLinks();
  1353. removeGhostSelection();
  1354. }
  1355. };
  1356. (function(tinymce) {
  1357. var namedEntities, baseEntities, reverseEntities,
  1358. attrsCharsRegExp = /[&<>\"\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  1359. textCharsRegExp = /[<>&\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  1360. rawCharsRegExp = /[<>&\"\']/g,
  1361. entityRegExp = /&(#x|#)?([\w]+);/g,
  1362. asciiMap = {
  1363. 128 : "\u20AC", 130 : "\u201A", 131 : "\u0192", 132 : "\u201E", 133 : "\u2026", 134 : "\u2020",
  1364. 135 : "\u2021", 136 : "\u02C6", 137 : "\u2030", 138 : "\u0160", 139 : "\u2039", 140 : "\u0152",
  1365. 142 : "\u017D", 145 : "\u2018", 146 : "\u2019", 147 : "\u201C", 148 : "\u201D", 149 : "\u2022",
  1366. 150 : "\u2013", 151 : "\u2014", 152 : "\u02DC", 153 : "\u2122", 154 : "\u0161", 155 : "\u203A",
  1367. 156 : "\u0153", 158 : "\u017E", 159 : "\u0178"
  1368. };
  1369. // Raw entities
  1370. baseEntities = {
  1371. '\"' : '&quot;', // Needs to be escaped since the YUI compressor would otherwise break the code
  1372. "'" : '&#39;',
  1373. '<' : '&lt;',
  1374. '>' : '&gt;',
  1375. '&' : '&amp;'
  1376. };
  1377. // Reverse lookup table for raw entities
  1378. reverseEntities = {
  1379. '&lt;' : '<',
  1380. '&gt;' : '>',
  1381. '&amp;' : '&',
  1382. '&quot;' : '"',
  1383. '&apos;' : "'"
  1384. };
  1385. // Decodes text by using the browser
  1386. function nativeDecode(text) {
  1387. var elm;
  1388. elm = document.createElement("div");
  1389. elm.innerHTML = text;
  1390. return elm.textContent || elm.innerText || text;
  1391. };
  1392. // Build a two way lookup table for the entities
  1393. function buildEntitiesLookup(items, radix) {
  1394. var i, chr, entity, lookup = {};
  1395. if (items) {
  1396. items = items.split(',');
  1397. radix = radix || 10;
  1398. // Build entities lookup table
  1399. for (i = 0; i < items.length; i += 2) {
  1400. chr = String.fromCharCode(parseInt(items[i], radix));
  1401. // Only add non base entities
  1402. if (!baseEntities[chr]) {
  1403. entity = '&' + items[i + 1] + ';';
  1404. lookup[chr] = entity;
  1405. lookup[entity] = chr;
  1406. }
  1407. }
  1408. return lookup;
  1409. }
  1410. };
  1411. // Unpack entities lookup where the numbers are in radix 32 to reduce the size
  1412. namedEntities = buildEntitiesLookup(
  1413. '50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,' +
  1414. '5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,' +
  1415. '5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,' +
  1416. '5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,' +
  1417. '68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,' +
  1418. '6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,' +
  1419. '6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,' +
  1420. '75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,' +
  1421. '7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,' +
  1422. '7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,' +
  1423. 'sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,' +
  1424. 'st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,' +
  1425. 't9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,' +
  1426. 'tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,' +
  1427. 'u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,' +
  1428. '81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,' +
  1429. '8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,' +
  1430. '8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,' +
  1431. '8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,' +
  1432. '8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,' +
  1433. 'nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,' +
  1434. 'rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,' +
  1435. 'Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,' +
  1436. '80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,' +
  1437. '811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro', 32);
  1438. tinymce.html = tinymce.html || {};
  1439. tinymce.html.Entities = {
  1440. encodeRaw : function(text, attr) {
  1441. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1442. return baseEntities[chr] || chr;
  1443. });
  1444. },
  1445. encodeAllRaw : function(text) {
  1446. return ('' + text).replace(rawCharsRegExp, function(chr) {
  1447. return baseEntities[chr] || chr;
  1448. });
  1449. },
  1450. encodeNumeric : function(text, attr) {
  1451. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1452. // Multi byte sequence convert it to a single entity
  1453. if (chr.length > 1)
  1454. return '&#' + (((chr.charCodeAt(0) - 0xD800) * 0x400) + (chr.charCodeAt(1) - 0xDC00) + 0x10000) + ';';
  1455. return baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';';
  1456. });
  1457. },
  1458. encodeNamed : function(text, attr, entities) {
  1459. entities = entities || namedEntities;
  1460. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1461. return baseEntities[chr] || entities[chr] || chr;
  1462. });
  1463. },
  1464. getEncodeFunc : function(name, entities) {
  1465. var Entities = tinymce.html.Entities;
  1466. entities = buildEntitiesLookup(entities) || namedEntities;
  1467. function encodeNamedAndNumeric(text, attr) {
  1468. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1469. return baseEntities[chr] || entities[chr] || '&#' + chr.charCodeAt(0) + ';' || chr;
  1470. });
  1471. };
  1472. function encodeCustomNamed(text, attr) {
  1473. return Entities.encodeNamed(text, attr, entities);
  1474. };
  1475. // Replace + with , to be compatible with previous TinyMCE versions
  1476. name = tinymce.makeMap(name.replace(/\+/g, ','));
  1477. // Named and numeric encoder
  1478. if (name.named && name.numeric)
  1479. return encodeNamedAndNumeric;
  1480. // Named encoder
  1481. if (name.named) {
  1482. // Custom names
  1483. if (entities)
  1484. return encodeCustomNamed;
  1485. return Entities.encodeNamed;
  1486. }
  1487. // Numeric
  1488. if (name.numeric)
  1489. return Entities.encodeNumeric;
  1490. // Raw encoder
  1491. return Entities.encodeRaw;
  1492. },
  1493. decode : function(text) {
  1494. return text.replace(entityRegExp, function(all, numeric, value) {
  1495. if (numeric) {
  1496. value = parseInt(value, numeric.length === 2 ? 16 : 10);
  1497. // Support upper UTF
  1498. if (value > 0xFFFF) {
  1499. value -= 0x10000;
  1500. return String.fromCharCode(0xD800 + (value >> 10), 0xDC00 + (value & 0x3FF));
  1501. } else
  1502. return asciiMap[value] || String.fromCharCode(value);
  1503. }
  1504. return reverseEntities[all] || namedEntities[all] || nativeDecode(all);
  1505. });
  1506. }
  1507. };
  1508. })(tinymce);
  1509. tinymce.html.Styles = function(settings, schema) {
  1510. var rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi,
  1511. urlOrStrRegExp = /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi,
  1512. styleRegExp = /\s*([^:]+):\s*([^;]+);?/g,
  1513. trimRightRegExp = /\s+$/,
  1514. urlColorRegExp = /rgb/,
  1515. undef, i, encodingLookup = {}, encodingItems;
  1516. settings = settings || {};
  1517. encodingItems = '\\" \\\' \\; \\: ; : \uFEFF'.split(' ');
  1518. for (i = 0; i < encodingItems.length; i++) {
  1519. encodingLookup[encodingItems[i]] = '\uFEFF' + i;
  1520. encodingLookup['\uFEFF' + i] = encodingItems[i];
  1521. }
  1522. function toHex(match, r, g, b) {
  1523. function hex(val) {
  1524. val = parseInt(val).toString(16);
  1525. return val.length > 1 ? val : '0' + val; // 0 -> 00
  1526. };
  1527. return '#' + hex(r) + hex(g) + hex(b);
  1528. };
  1529. return {
  1530. toHex : function(color) {
  1531. return color.replace(rgbRegExp, toHex);
  1532. },
  1533. parse : function(css) {
  1534. var styles = {}, matches, name, value, isEncoded, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope || this;
  1535. function compress(prefix, suffix) {
  1536. var top, right, bottom, left;
  1537. // Get values and check it it needs compressing
  1538. top = styles[prefix + '-top' + suffix];
  1539. if (!top)
  1540. return;
  1541. right = styles[prefix + '-right' + suffix];
  1542. if (top != right)
  1543. return;
  1544. bottom = styles[prefix + '-bottom' + suffix];
  1545. if (right != bottom)
  1546. return;
  1547. left = styles[prefix + '-left' + suffix];
  1548. if (bottom != left)
  1549. return;
  1550. // Compress
  1551. styles[prefix + suffix] = left;
  1552. delete styles[prefix + '-top' + suffix];
  1553. delete styles[prefix + '-right' + suffix];
  1554. delete styles[prefix + '-bottom' + suffix];
  1555. delete styles[prefix + '-left' + suffix];
  1556. };
  1557. function canCompress(key) {
  1558. var value = styles[key], i;
  1559. if (!value || value.indexOf(' ') < 0)
  1560. return;
  1561. value = value.split(' ');
  1562. i = value.length;
  1563. while (i--) {
  1564. if (value[i] !== value[0])
  1565. return false;
  1566. }
  1567. styles[key] = value[0];
  1568. return true;
  1569. };
  1570. function compress2(target, a, b, c) {
  1571. if (!canCompress(a))
  1572. return;
  1573. if (!canCompress(b))
  1574. return;
  1575. if (!canCompress(c))
  1576. return;
  1577. // Compress
  1578. styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c];
  1579. delete styles[a];
  1580. delete styles[b];
  1581. delete styles[c];
  1582. };
  1583. // Encodes the specified string by replacing all \" \' ; : with _<num>
  1584. function encode(str) {
  1585. isEncoded = true;
  1586. return encodingLookup[str];
  1587. };
  1588. // Decodes the specified string by replacing all _<num> with it's original value \" \' etc
  1589. // It will also decode the \" \' if keep_slashes is set to fale or omitted
  1590. function decode(str, keep_slashes) {
  1591. if (isEncoded) {
  1592. str = str.replace(/\uFEFF[0-9]/g, function(str) {
  1593. return encodingLookup[str];
  1594. });
  1595. }
  1596. if (!keep_slashes)
  1597. str = str.replace(/\\([\'\";:])/g, "$1");
  1598. return str;
  1599. };
  1600. function processUrl(match, url, url2, url3, str, str2) {
  1601. str = str || str2;
  1602. if (str) {
  1603. str = decode(str);
  1604. // Force strings into single quote format
  1605. return "'" + str.replace(/\'/g, "\\'") + "'";
  1606. }
  1607. url = decode(url || url2 || url3);
  1608. // Convert the URL to relative/absolute depending on config
  1609. if (urlConverter)
  1610. url = urlConverter.call(urlConverterScope, url, 'style');
  1611. // Output new URL format
  1612. return "url('" + url.replace(/\'/g, "\\'") + "')";
  1613. };
  1614. if (css) {
  1615. // Encode \" \' % and ; and : inside strings so they don't interfere with the style parsing
  1616. css = css.replace(/\\[\"\';:\uFEFF]/g, encode).replace(/\"[^\"]+\"|\'[^\']+\'/g, function(str) {
  1617. return str.replace(/[;:]/g, encode);
  1618. });
  1619. // Parse styles
  1620. while (matches = styleRegExp.exec(css)) {
  1621. name = matches[1].replace(trimRightRegExp, '').toLowerCase();
  1622. value = matches[2].replace(trimRightRegExp, '');
  1623. if (name && value.length > 0) {
  1624. // Opera will produce 700 instead of bold in their style values
  1625. if (name === 'font-weight' && value === '700')
  1626. value = 'bold';
  1627. else if (name === 'color' || name === 'background-color') // Lowercase colors like RED
  1628. value = value.toLowerCase();
  1629. // Convert RGB colors to HEX
  1630. value = value.replace(rgbRegExp, toHex);
  1631. // Convert URLs and force them into url('value') format
  1632. value = value.replace(urlOrStrRegExp, processUrl);
  1633. styles[name] = isEncoded ? decode(value, true) : value;
  1634. }
  1635. styleRegExp.lastIndex = matches.index + matches[0].length;
  1636. }
  1637. // Compress the styles to reduce it's size for example IE will expand styles
  1638. compress("border", "");
  1639. compress("border", "-width");
  1640. compress("border", "-color");
  1641. compress("border", "-style");
  1642. compress("padding", "");
  1643. compress("margin", "");
  1644. compress2('border', 'border-width', 'border-style', 'border-color');
  1645. // Remove pointless border, IE produces these
  1646. if (styles.border === 'medium none')
  1647. delete styles.border;
  1648. }
  1649. return styles;
  1650. },
  1651. serialize : function(styles, element_name) {
  1652. var css = '', name, value;
  1653. function serializeStyles(name) {
  1654. var styleList, i, l, value;
  1655. styleList = schema.styles[name];
  1656. if (styleList) {
  1657. for (i = 0, l = styleList.length; i < l; i++) {
  1658. name = styleList[i];
  1659. value = styles[name];
  1660. if (value !== undef && value.length > 0)
  1661. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  1662. }
  1663. }
  1664. };
  1665. // Serialize styles according to schema
  1666. if (element_name && schema && schema.styles) {
  1667. // Serialize global styles and element specific styles
  1668. serializeStyles('*');
  1669. serializeStyles(element_name);
  1670. } else {
  1671. // Output the styles in the order they are inside the object
  1672. for (name in styles) {
  1673. value = styles[name];
  1674. if (value !== undef && value.length > 0)
  1675. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  1676. }
  1677. }
  1678. return css;
  1679. }
  1680. };
  1681. };
  1682. (function(tinymce) {
  1683. var mapCache = {}, makeMap = tinymce.makeMap, each = tinymce.each;
  1684. function split(str, delim) {
  1685. return str.split(delim || ',');
  1686. };
  1687. function unpack(lookup, data) {
  1688. var key, elements = {};
  1689. function replace(value) {
  1690. return value.replace(/[A-Z]+/g, function(key) {
  1691. return replace(lookup[key]);
  1692. });
  1693. };
  1694. // Unpack lookup
  1695. for (key in lookup) {
  1696. if (lookup.hasOwnProperty(key))
  1697. lookup[key] = replace(lookup[key]);
  1698. }
  1699. // Unpack and parse data into object map
  1700. replace(data).replace(/#/g, '#text').replace(/(\w+)\[([^\]]+)\]\[([^\]]*)\]/g, function(str, name, attributes, children) {
  1701. attributes = split(attributes, '|');
  1702. elements[name] = {
  1703. attributes : makeMap(attributes),
  1704. attributesOrder : attributes,
  1705. children : makeMap(children, '|', {'#comment' : {}})
  1706. }
  1707. });
  1708. return elements;
  1709. };
  1710. function getHTML5() {
  1711. var html5 = mapCache.html5;
  1712. if (!html5) {
  1713. html5 = mapCache.html5 = unpack({
  1714. A : 'id|accesskey|class|dir|draggable|item|hidden|itemprop|role|spellcheck|style|subject|title|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup',
  1715. 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|' +
  1716. 'meter|noscript|object|output|progress|q|ruby|samp|script|select|small|span|strong|sub|sup|svg|textarea|time|var|video|wbr',
  1717. 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|' +
  1718. '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|' +
  1719. 'p|pre|progress|q|ruby|samp|script|section|select|small|span|strong|style|sub|sup|svg|table|textarea|time|ul|var|video'
  1720. }, 'html[A|manifest][body|head]' +
  1721. 'head[A][base|command|link|meta|noscript|script|style|title]' +
  1722. 'title[A][#]' +
  1723. 'base[A|href|target][]' +
  1724. 'link[A|href|rel|media|type|sizes][]' +
  1725. 'meta[A|http-equiv|name|content|charset][]' +
  1726. 'style[A|type|media|scoped][#]' +
  1727. 'script[A|charset|type|src|defer|async][#]' +
  1728. 'noscript[A][C]' +
  1729. 'body[A][C]' +
  1730. 'section[A][C]' +
  1731. 'nav[A][C]' +
  1732. 'article[A][C]' +
  1733. 'aside[A][C]' +
  1734. 'h1[A][B]' +
  1735. 'h2[A][B]' +
  1736. 'h3[A][B]' +
  1737. 'h4[A][B]' +
  1738. 'h5[A][B]' +
  1739. 'h6[A][B]' +
  1740. 'hgroup[A][h1|h2|h3|h4|h5|h6]' +
  1741. 'header[A][C]' +
  1742. 'footer[A][C]' +
  1743. 'address[A][C]' +
  1744. 'p[A][B]' +
  1745. 'br[A][]' +
  1746. 'pre[A][B]' +
  1747. 'dialog[A][dd|dt]' +
  1748. 'blockquote[A|cite][C]' +
  1749. 'ol[A|start|reversed][li]' +
  1750. 'ul[A][li]' +
  1751. 'li[A|value][C]' +
  1752. 'dl[A][dd|dt]' +
  1753. 'dt[A][B]' +
  1754. 'dd[A][C]' +
  1755. 'a[A|href|target|ping|rel|media|type][B]' +
  1756. 'em[A][B]' +
  1757. 'strong[A][B]' +
  1758. 'small[A][B]' +
  1759. 'cite[A][B]' +
  1760. 'q[A|cite][B]' +
  1761. 'dfn[A][B]' +
  1762. 'abbr[A][B]' +
  1763. 'code[A][B]' +
  1764. 'var[A][B]' +
  1765. 'samp[A][B]' +
  1766. 'kbd[A][B]' +
  1767. 'sub[A][B]' +
  1768. 'sup[A][B]' +
  1769. 'i[A][B]' +
  1770. 'b[A][B]' +
  1771. 'mark[A][B]' +
  1772. 'progress[A|value|max][B]' +
  1773. 'meter[A|value|min|max|low|high|optimum][B]' +
  1774. 'time[A|datetime][B]' +
  1775. 'ruby[A][B|rt|rp]' +
  1776. 'rt[A][B]' +
  1777. 'rp[A][B]' +
  1778. 'bdo[A][B]' +
  1779. 'span[A][B]' +
  1780. 'ins[A|cite|datetime][B]' +
  1781. 'del[A|cite|datetime][B]' +
  1782. 'figure[A][C|legend|figcaption]' +
  1783. 'figcaption[A][C]' +
  1784. 'img[A|alt|src|height|width|usemap|ismap][]' +
  1785. 'iframe[A|name|src|height|width|sandbox|seamless][]' +
  1786. 'embed[A|src|height|width|type][]' +
  1787. 'object[A|data|type|height|width|usemap|name|form|classid][param]' +
  1788. 'param[A|name|value][]' +
  1789. 'details[A|open][C|legend]' +
  1790. 'command[A|type|label|icon|disabled|checked|radiogroup][]' +
  1791. 'menu[A|type|label][C|li]' +
  1792. 'legend[A][C|B]' +
  1793. 'div[A][C]' +
  1794. 'source[A|src|type|media][]' +
  1795. 'audio[A|src|autobuffer|autoplay|loop|controls][source]' +
  1796. 'video[A|src|autobuffer|autoplay|loop|controls|width|height|poster][source]' +
  1797. 'hr[A][]' +
  1798. 'form[A|accept-charset|action|autocomplete|enctype|method|name|novalidate|target][C]' +
  1799. 'fieldset[A|disabled|form|name][C|legend]' +
  1800. 'label[A|form|for][B]' +
  1801. 'input[A|type|accept|alt|autocomplete|checked|disabled|form|formaction|formenctype|formmethod|formnovalidate|formtarget|height|list|max|maxlength|min|' +
  1802. 'multiple|pattern|placeholder|readonly|required|size|src|step|width|files|value|name][]' +
  1803. 'button[A|autofocus|disabled|form|formaction|formenctype|formmethod|formnovalidate|formtarget|name|value|type][B]' +
  1804. 'select[A|autofocus|disabled|form|multiple|name|size][option|optgroup]' +
  1805. 'datalist[A][B|option]' +
  1806. 'optgroup[A|disabled|label][option]' +
  1807. 'option[A|disabled|selected|label|value][]' +
  1808. 'textarea[A|autofocus|disabled|form|maxlength|name|placeholder|readonly|required|rows|cols|wrap][]' +
  1809. 'keygen[A|autofocus|challenge|disabled|form|keytype|name][]' +
  1810. 'output[A|for|form|name][B]' +
  1811. 'canvas[A|width|height][]' +
  1812. 'map[A|name][B|C]' +
  1813. 'area[A|shape|coords|href|alt|target|media|rel|ping|type][]' +
  1814. 'mathml[A][]' +
  1815. 'svg[A][]' +
  1816. 'table[A|border][caption|colgroup|thead|tfoot|tbody|tr]' +
  1817. 'caption[A][C]' +
  1818. 'colgroup[A|span][col]' +
  1819. 'col[A|span][]' +
  1820. 'thead[A][tr]' +
  1821. 'tfoot[A][tr]' +
  1822. 'tbody[A][tr]' +
  1823. 'tr[A][th|td]' +
  1824. 'th[A|headers|rowspan|colspan|scope][B]' +
  1825. 'td[A|headers|rowspan|colspan][C]' +
  1826. 'wbr[A][]'
  1827. );
  1828. }
  1829. return html5;
  1830. };
  1831. function getHTML4() {
  1832. var html4 = mapCache.html4;
  1833. if (!html4) {
  1834. // This is the XHTML 1.0 transitional elements with it's attributes and children packed to reduce it's size
  1835. html4 = mapCache.html4 = unpack({
  1836. Z : 'H|K|N|O|P',
  1837. Y : 'X|form|R|Q',
  1838. ZG : 'E|span|width|align|char|charoff|valign',
  1839. X : 'p|T|div|U|W|isindex|fieldset|table',
  1840. ZF : 'E|align|char|charoff|valign',
  1841. W : 'pre|hr|blockquote|address|center|noframes',
  1842. ZE : 'abbr|axis|headers|scope|rowspan|colspan|align|char|charoff|valign|nowrap|bgcolor|width|height',
  1843. ZD : '[E][S]',
  1844. U : 'ul|ol|dl|menu|dir',
  1845. ZC : 'p|Y|div|U|W|table|br|span|bdo|object|applet|img|map|K|N|Q',
  1846. T : 'h1|h2|h3|h4|h5|h6',
  1847. ZB : 'X|S|Q',
  1848. S : 'R|P',
  1849. ZA : 'a|G|J|M|O|P',
  1850. R : 'a|H|K|N|O',
  1851. Q : 'noscript|P',
  1852. P : 'ins|del|script',
  1853. O : 'input|select|textarea|label|button',
  1854. N : 'M|L',
  1855. M : 'em|strong|dfn|code|q|samp|kbd|var|cite|abbr|acronym',
  1856. L : 'sub|sup',
  1857. K : 'J|I',
  1858. J : 'tt|i|b|u|s|strike',
  1859. I : 'big|small|font|basefont',
  1860. H : 'G|F',
  1861. G : 'br|span|bdo',
  1862. F : 'object|applet|img|map|iframe',
  1863. E : 'A|B|C',
  1864. D : 'accesskey|tabindex|onfocus|onblur',
  1865. C : 'onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup',
  1866. B : 'lang|xml:lang|dir',
  1867. A : 'id|class|style|title'
  1868. }, 'script[id|charset|type|language|src|defer|xml:space][]' +
  1869. 'style[B|id|type|media|title|xml:space][]' +
  1870. 'object[E|declare|classid|codebase|data|type|codetype|archive|standby|width|height|usemap|name|tabindex|align|border|hspace|vspace][#|param|Y]' +
  1871. 'param[id|name|value|valuetype|type][]' +
  1872. 'p[E|align][#|S]' +
  1873. 'a[E|D|charset|type|name|href|hreflang|rel|rev|shape|coords|target][#|Z]' +
  1874. 'br[A|clear][]' +
  1875. 'span[E][#|S]' +
  1876. 'bdo[A|C|B][#|S]' +
  1877. 'applet[A|codebase|archive|code|object|alt|name|width|height|align|hspace|vspace][#|param|Y]' +
  1878. 'h1[E|align][#|S]' +
  1879. 'img[E|src|alt|name|longdesc|width|height|usemap|ismap|align|border|hspace|vspace][]' +
  1880. 'map[B|C|A|name][X|form|Q|area]' +
  1881. 'h2[E|align][#|S]' +
  1882. 'iframe[A|longdesc|name|src|frameborder|marginwidth|marginheight|scrolling|align|width|height][#|Y]' +
  1883. 'h3[E|align][#|S]' +
  1884. 'tt[E][#|S]' +
  1885. 'i[E][#|S]' +
  1886. 'b[E][#|S]' +
  1887. 'u[E][#|S]' +
  1888. 's[E][#|S]' +
  1889. 'strike[E][#|S]' +
  1890. 'big[E][#|S]' +
  1891. 'small[E][#|S]' +
  1892. 'font[A|B|size|color|face][#|S]' +
  1893. 'basefont[id|size|color|face][]' +
  1894. 'em[E][#|S]' +
  1895. 'strong[E][#|S]' +
  1896. 'dfn[E][#|S]' +
  1897. 'code[E][#|S]' +
  1898. 'q[E|cite][#|S]' +
  1899. 'samp[E][#|S]' +
  1900. 'kbd[E][#|S]' +
  1901. 'var[E][#|S]' +
  1902. 'cite[E][#|S]' +
  1903. 'abbr[E][#|S]' +
  1904. 'acronym[E][#|S]' +
  1905. 'sub[E][#|S]' +
  1906. 'sup[E][#|S]' +
  1907. 'input[E|D|type|name|value|checked|disabled|readonly|size|maxlength|src|alt|usemap|onselect|onchange|accept|align][]' +
  1908. 'select[E|name|size|multiple|disabled|tabindex|onfocus|onblur|onchange][optgroup|option]' +
  1909. 'optgroup[E|disabled|label][option]' +
  1910. 'option[E|selected|disabled|label|value][]' +
  1911. 'textarea[E|D|name|rows|cols|disabled|readonly|onselect|onchange][]' +
  1912. 'label[E|for|accesskey|onfocus|onblur][#|S]' +
  1913. 'button[E|D|name|value|type|disabled][#|p|T|div|U|W|table|G|object|applet|img|map|K|N|Q]' +
  1914. 'h4[E|align][#|S]' +
  1915. 'ins[E|cite|datetime][#|Y]' +
  1916. 'h5[E|align][#|S]' +
  1917. 'del[E|cite|datetime][#|Y]' +
  1918. 'h6[E|align][#|S]' +
  1919. 'div[E|align][#|Y]' +
  1920. 'ul[E|type|compact][li]' +
  1921. 'li[E|type|value][#|Y]' +
  1922. 'ol[E|type|compact|start][li]' +
  1923. 'dl[E|compact][dt|dd]' +
  1924. 'dt[E][#|S]' +
  1925. 'dd[E][#|Y]' +
  1926. 'menu[E|compact][li]' +
  1927. 'dir[E|compact][li]' +
  1928. 'pre[E|width|xml:space][#|ZA]' +
  1929. 'hr[E|align|noshade|size|width][]' +
  1930. 'blockquote[E|cite][#|Y]' +
  1931. 'address[E][#|S|p]' +
  1932. 'center[E][#|Y]' +
  1933. 'noframes[E][#|Y]' +
  1934. 'isindex[A|B|prompt][]' +
  1935. 'fieldset[E][#|legend|Y]' +
  1936. 'legend[E|accesskey|align][#|S]' +
  1937. 'table[E|summary|width|border|frame|rules|cellspacing|cellpadding|align|bgcolor][caption|col|colgroup|thead|tfoot|tbody|tr]' +
  1938. 'caption[E|align][#|S]' +
  1939. 'col[ZG][]' +
  1940. 'colgroup[ZG][col]' +
  1941. 'thead[ZF][tr]' +
  1942. 'tr[ZF|bgcolor][th|td]' +
  1943. 'th[E|ZE][#|Y]' +
  1944. 'form[E|action|method|name|enctype|onsubmit|onreset|accept|accept-charset|target][#|X|R|Q]' +
  1945. 'noscript[E][#|Y]' +
  1946. 'td[E|ZE][#|Y]' +
  1947. 'tfoot[ZF][tr]' +
  1948. 'tbody[ZF][tr]' +
  1949. 'area[E|D|shape|coords|href|nohref|alt|target][]' +
  1950. 'base[id|href|target][]' +
  1951. 'body[E|onload|onunload|background|bgcolor|text|link|vlink|alink][#|Y]'
  1952. );
  1953. }
  1954. return html4;
  1955. };
  1956. tinymce.html.Schema = function(settings) {
  1957. var self = this, elements = {}, children = {}, patternElements = [], validStyles, schemaItems;
  1958. var whiteSpaceElementsMap, selfClosingElementsMap, shortEndedElementsMap, boolAttrMap, blockElementsMap, nonEmptyElementsMap, customElementsMap = {};
  1959. // Creates an lookup table map object for the specified option or the default value
  1960. function createLookupTable(option, default_value, extend) {
  1961. var value = settings[option];
  1962. if (!value) {
  1963. // Get cached default map or make it if needed
  1964. value = mapCache[option];
  1965. if (!value) {
  1966. value = makeMap(default_value, ' ', makeMap(default_value.toUpperCase(), ' '));
  1967. value = tinymce.extend(value, extend);
  1968. mapCache[option] = value;
  1969. }
  1970. } else {
  1971. // Create custom map
  1972. value = makeMap(value, ',', makeMap(value.toUpperCase(), ' '));
  1973. }
  1974. return value;
  1975. };
  1976. settings = settings || {};
  1977. schemaItems = settings.schema == "html5" ? getHTML5() : getHTML4();
  1978. // Allow all elements and attributes if verify_html is set to false
  1979. if (settings.verify_html === false)
  1980. settings.valid_elements = '*[*]';
  1981. // Build styles list
  1982. if (settings.valid_styles) {
  1983. validStyles = {};
  1984. // Convert styles into a rule list
  1985. each(settings.valid_styles, function(value, key) {
  1986. validStyles[key] = tinymce.explode(value);
  1987. });
  1988. }
  1989. // Setup map objects
  1990. whiteSpaceElementsMap = createLookupTable('whitespace_elements', 'pre script style textarea');
  1991. selfClosingElementsMap = createLookupTable('self_closing_elements', 'colgroup dd dt li option p td tfoot th thead tr');
  1992. shortEndedElementsMap = createLookupTable('short_ended_elements', 'area base basefont br col frame hr img input isindex link meta param embed source wbr');
  1993. boolAttrMap = createLookupTable('boolean_attributes', 'checked compact declare defer disabled ismap multiple nohref noresize noshade nowrap readonly selected autoplay loop controls');
  1994. nonEmptyElementsMap = createLookupTable('non_empty_elements', 'td th iframe video audio object', shortEndedElementsMap);
  1995. blockElementsMap = createLookupTable('block_elements', 'h1 h2 h3 h4 h5 h6 hr p div address pre form table tbody thead tfoot ' +
  1996. 'th tr td li ol ul caption blockquote center dl dt dd dir fieldset ' +
  1997. 'noscript menu isindex samp header footer article section hgroup aside nav figure option datalist select optgroup');
  1998. // Converts a wildcard expression string to a regexp for example *a will become /.*a/.
  1999. function patternToRegExp(str) {
  2000. return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$');
  2001. };
  2002. // Parses the specified valid_elements string and adds to the current rules
  2003. // This function is a bit hard to read since it's heavily optimized for speed
  2004. function addValidElements(valid_elements) {
  2005. var ei, el, ai, al, yl, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder,
  2006. prefix, outputName, globalAttributes, globalAttributesOrder, transElement, key, childKey, value,
  2007. elementRuleRegExp = /^([#+\-])?([^\[\/]+)(?:\/([^\[]+))?(?:\[([^\]]+)\])?$/,
  2008. attrRuleRegExp = /^([!\-])?(\w+::\w+|[^=:<]+)?(?:([=:<])(.*))?$/,
  2009. hasPatternsRegExp = /[*?+]/;
  2010. if (valid_elements) {
  2011. // Split valid elements into an array with rules
  2012. valid_elements = split(valid_elements);
  2013. if (elements['@']) {
  2014. globalAttributes = elements['@'].attributes;
  2015. globalAttributesOrder = elements['@'].attributesOrder;
  2016. }
  2017. // Loop all rules
  2018. for (ei = 0, el = valid_elements.length; ei < el; ei++) {
  2019. // Parse element rule
  2020. matches = elementRuleRegExp.exec(valid_elements[ei]);
  2021. if (matches) {
  2022. // Setup local names for matches
  2023. prefix = matches[1];
  2024. elementName = matches[2];
  2025. outputName = matches[3];
  2026. attrData = matches[4];
  2027. // Create new attributes and attributesOrder
  2028. attributes = {};
  2029. attributesOrder = [];
  2030. // Create the new element
  2031. element = {
  2032. attributes : attributes,
  2033. attributesOrder : attributesOrder
  2034. };
  2035. // Padd empty elements prefix
  2036. if (prefix === '#')
  2037. element.paddEmpty = true;
  2038. // Remove empty elements prefix
  2039. if (prefix === '-')
  2040. element.removeEmpty = true;
  2041. // Copy attributes from global rule into current rule
  2042. if (globalAttributes) {
  2043. for (key in globalAttributes)
  2044. attributes[key] = globalAttributes[key];
  2045. attributesOrder.push.apply(attributesOrder, globalAttributesOrder);
  2046. }
  2047. // Attributes defined
  2048. if (attrData) {
  2049. attrData = split(attrData, '|');
  2050. for (ai = 0, al = attrData.length; ai < al; ai++) {
  2051. matches = attrRuleRegExp.exec(attrData[ai]);
  2052. if (matches) {
  2053. attr = {};
  2054. attrType = matches[1];
  2055. attrName = matches[2].replace(/::/g, ':');
  2056. prefix = matches[3];
  2057. value = matches[4];
  2058. // Required
  2059. if (attrType === '!') {
  2060. element.attributesRequired = element.attributesRequired || [];
  2061. element.attributesRequired.push(attrName);
  2062. attr.required = true;
  2063. }
  2064. // Denied from global
  2065. if (attrType === '-') {
  2066. delete attributes[attrName];
  2067. attributesOrder.splice(tinymce.inArray(attributesOrder, attrName), 1);
  2068. continue;
  2069. }
  2070. // Default value
  2071. if (prefix) {
  2072. // Default value
  2073. if (prefix === '=') {
  2074. element.attributesDefault = element.attributesDefault || [];
  2075. element.attributesDefault.push({name: attrName, value: value});
  2076. attr.defaultValue = value;
  2077. }
  2078. // Forced value
  2079. if (prefix === ':') {
  2080. element.attributesForced = element.attributesForced || [];
  2081. element.attributesForced.push({name: attrName, value: value});
  2082. attr.forcedValue = value;
  2083. }
  2084. // Required values
  2085. if (prefix === '<')
  2086. attr.validValues = makeMap(value, '?');
  2087. }
  2088. // Check for attribute patterns
  2089. if (hasPatternsRegExp.test(attrName)) {
  2090. element.attributePatterns = element.attributePatterns || [];
  2091. attr.pattern = patternToRegExp(attrName);
  2092. element.attributePatterns.push(attr);
  2093. } else {
  2094. // Add attribute to order list if it doesn't already exist
  2095. if (!attributes[attrName])
  2096. attributesOrder.push(attrName);
  2097. attributes[attrName] = attr;
  2098. }
  2099. }
  2100. }
  2101. }
  2102. // Global rule, store away these for later usage
  2103. if (!globalAttributes && elementName == '@') {
  2104. globalAttributes = attributes;
  2105. globalAttributesOrder = attributesOrder;
  2106. }
  2107. // Handle substitute elements such as b/strong
  2108. if (outputName) {
  2109. element.outputName = elementName;
  2110. elements[outputName] = element;
  2111. }
  2112. // Add pattern or exact element
  2113. if (hasPatternsRegExp.test(elementName)) {
  2114. element.pattern = patternToRegExp(elementName);
  2115. patternElements.push(element);
  2116. } else
  2117. elements[elementName] = element;
  2118. }
  2119. }
  2120. }
  2121. };
  2122. function setValidElements(valid_elements) {
  2123. elements = {};
  2124. patternElements = [];
  2125. addValidElements(valid_elements);
  2126. each(schemaItems, function(element, name) {
  2127. children[name] = element.children;
  2128. });
  2129. };
  2130. // Adds custom non HTML elements to the schema
  2131. function addCustomElements(custom_elements) {
  2132. var customElementRegExp = /^(~)?(.+)$/;
  2133. if (custom_elements) {
  2134. each(split(custom_elements), function(rule) {
  2135. var matches = customElementRegExp.exec(rule),
  2136. inline = matches[1] === '~',
  2137. cloneName = inline ? 'span' : 'div',
  2138. name = matches[2];
  2139. children[name] = children[cloneName];
  2140. customElementsMap[name] = cloneName;
  2141. // If it's not marked as inline then add it to valid block elements
  2142. if (!inline)
  2143. blockElementsMap[name] = {};
  2144. // Add custom elements at span/div positions
  2145. each(children, function(element, child) {
  2146. if (element[cloneName])
  2147. element[name] = element[cloneName];
  2148. });
  2149. });
  2150. }
  2151. };
  2152. // Adds valid children to the schema object
  2153. function addValidChildren(valid_children) {
  2154. var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/;
  2155. if (valid_children) {
  2156. each(split(valid_children), function(rule) {
  2157. var matches = childRuleRegExp.exec(rule), parent, prefix;
  2158. if (matches) {
  2159. prefix = matches[1];
  2160. // Add/remove items from default
  2161. if (prefix)
  2162. parent = children[matches[2]];
  2163. else
  2164. parent = children[matches[2]] = {'#comment' : {}};
  2165. parent = children[matches[2]];
  2166. each(split(matches[3], '|'), function(child) {
  2167. if (prefix === '-')
  2168. delete parent[child];
  2169. else
  2170. parent[child] = {};
  2171. });
  2172. }
  2173. });
  2174. }
  2175. };
  2176. function getElementRule(name) {
  2177. var element = elements[name], i;
  2178. // Exact match found
  2179. if (element)
  2180. return element;
  2181. // No exact match then try the patterns
  2182. i = patternElements.length;
  2183. while (i--) {
  2184. element = patternElements[i];
  2185. if (element.pattern.test(name))
  2186. return element;
  2187. }
  2188. };
  2189. if (!settings.valid_elements) {
  2190. // No valid elements defined then clone the elements from the schema spec
  2191. each(schemaItems, function(element, name) {
  2192. elements[name] = {
  2193. attributes : element.attributes,
  2194. attributesOrder : element.attributesOrder
  2195. };
  2196. children[name] = element.children;
  2197. });
  2198. // Switch these on HTML4
  2199. if (settings.schema != "html5") {
  2200. each(split('strong/b,em/i'), function(item) {
  2201. item = split(item, '/');
  2202. elements[item[1]].outputName = item[0];
  2203. });
  2204. }
  2205. // Add default alt attribute for images
  2206. elements.img.attributesDefault = [{name: 'alt', value: ''}];
  2207. // Remove these if they are empty by default
  2208. each(split('ol,ul,sub,sup,blockquote,span,font,a,table,tbody,tr,strong,em,b,i'), function(name) {
  2209. if (elements[name]) {
  2210. elements[name].removeEmpty = true;
  2211. }
  2212. });
  2213. // Padd these by default
  2214. each(split('p,h1,h2,h3,h4,h5,h6,th,td,pre,div,address,caption'), function(name) {
  2215. elements[name].paddEmpty = true;
  2216. });
  2217. } else
  2218. setValidElements(settings.valid_elements);
  2219. addCustomElements(settings.custom_elements);
  2220. addValidChildren(settings.valid_children);
  2221. addValidElements(settings.extended_valid_elements);
  2222. // Todo: Remove this when we fix list handling to be valid
  2223. addValidChildren('+ol[ul|ol],+ul[ul|ol]');
  2224. // Delete invalid elements
  2225. if (settings.invalid_elements) {
  2226. tinymce.each(tinymce.explode(settings.invalid_elements), function(item) {
  2227. if (elements[item])
  2228. delete elements[item];
  2229. });
  2230. }
  2231. // If the user didn't allow span only allow internal spans
  2232. if (!getElementRule('span'))
  2233. addValidElements('span[!data-mce-type|*]');
  2234. self.children = children;
  2235. self.styles = validStyles;
  2236. self.getBoolAttrs = function() {
  2237. return boolAttrMap;
  2238. };
  2239. self.getBlockElements = function() {
  2240. return blockElementsMap;
  2241. };
  2242. self.getShortEndedElements = function() {
  2243. return shortEndedElementsMap;
  2244. };
  2245. self.getSelfClosingElements = function() {
  2246. return selfClosingElementsMap;
  2247. };
  2248. self.getNonEmptyElements = function() {
  2249. return nonEmptyElementsMap;
  2250. };
  2251. self.getWhiteSpaceElements = function() {
  2252. return whiteSpaceElementsMap;
  2253. };
  2254. self.isValidChild = function(name, child) {
  2255. var parent = children[name];
  2256. return !!(parent && parent[child]);
  2257. };
  2258. self.isValid = function(name, attr) {
  2259. var attrPatterns, i, rule = getElementRule(name);
  2260. // Check if it's a valid element
  2261. if (rule) {
  2262. if (attr) {
  2263. // Check if attribute name exists
  2264. if (rule.attributes[attr]) {
  2265. return true;
  2266. }
  2267. // Check if attribute matches a regexp pattern
  2268. attrPatterns = rule.attributePatterns;
  2269. if (attrPatterns) {
  2270. i = attrPatterns.length;
  2271. while (i--) {
  2272. if (attrPatterns[i].pattern.test(name)) {
  2273. return true;
  2274. }
  2275. }
  2276. }
  2277. } else {
  2278. return true;
  2279. }
  2280. }
  2281. // No match
  2282. return false;
  2283. };
  2284. self.getElementRule = getElementRule;
  2285. self.getCustomElements = function() {
  2286. return customElementsMap;
  2287. };
  2288. self.addValidElements = addValidElements;
  2289. self.setValidElements = setValidElements;
  2290. self.addCustomElements = addCustomElements;
  2291. self.addValidChildren = addValidChildren;
  2292. };
  2293. })(tinymce);
  2294. (function(tinymce) {
  2295. tinymce.html.SaxParser = function(settings, schema) {
  2296. var self = this, noop = function() {};
  2297. settings = settings || {};
  2298. self.schema = schema = schema || new tinymce.html.Schema();
  2299. if (settings.fix_self_closing !== false)
  2300. settings.fix_self_closing = true;
  2301. // Add handler functions from settings and setup default handlers
  2302. tinymce.each('comment cdata text start end pi doctype'.split(' '), function(name) {
  2303. if (name)
  2304. self[name] = settings[name] || noop;
  2305. });
  2306. self.parse = function(html) {
  2307. var self = this, matches, index = 0, value, endRegExp, stack = [], attrList, i, text, name, isInternalElement, removeInternalElements,
  2308. shortEndedElements, fillAttrsMap, isShortEnded, validate, elementRule, isValidElement, attr, attribsValue, invalidPrefixRegExp,
  2309. validAttributesMap, validAttributePatterns, attributesRequired, attributesDefault, attributesForced, selfClosing,
  2310. tokenRegExp, attrRegExp, specialElements, attrValue, idCount = 0, decode = tinymce.html.Entities.decode, fixSelfClosing, isIE;
  2311. function processEndTag(name) {
  2312. var pos, i;
  2313. // Find position of parent of the same type
  2314. pos = stack.length;
  2315. while (pos--) {
  2316. if (stack[pos].name === name)
  2317. break;
  2318. }
  2319. // Found parent
  2320. if (pos >= 0) {
  2321. // Close all the open elements
  2322. for (i = stack.length - 1; i >= pos; i--) {
  2323. name = stack[i];
  2324. if (name.valid)
  2325. self.end(name.name);
  2326. }
  2327. // Remove the open elements from the stack
  2328. stack.length = pos;
  2329. }
  2330. };
  2331. function parseAttribute(match, name, value, val2, val3) {
  2332. var attrRule, i;
  2333. name = name.toLowerCase();
  2334. value = name in fillAttrsMap ? name : decode(value || val2 || val3 || ''); // Handle boolean attribute than value attribute
  2335. // Validate name and value
  2336. if (validate && !isInternalElement && name.indexOf('data-') !== 0) {
  2337. attrRule = validAttributesMap[name];
  2338. // Find rule by pattern matching
  2339. if (!attrRule && validAttributePatterns) {
  2340. i = validAttributePatterns.length;
  2341. while (i--) {
  2342. attrRule = validAttributePatterns[i];
  2343. if (attrRule.pattern.test(name))
  2344. break;
  2345. }
  2346. // No rule matched
  2347. if (i === -1)
  2348. attrRule = null;
  2349. }
  2350. // No attribute rule found
  2351. if (!attrRule)
  2352. return;
  2353. // Validate value
  2354. if (attrRule.validValues && !(value in attrRule.validValues))
  2355. return;
  2356. }
  2357. // Add attribute to list and map
  2358. attrList.map[name] = value;
  2359. attrList.push({
  2360. name: name,
  2361. value: value
  2362. });
  2363. };
  2364. // Precompile RegExps and map objects
  2365. tokenRegExp = new RegExp('<(?:' +
  2366. '(?:!--([\\w\\W]*?)-->)|' + // Comment
  2367. '(?:!\\[CDATA\\[([\\w\\W]*?)\\]\\]>)|' + // CDATA
  2368. '(?:!DOCTYPE([\\w\\W]*?)>)|' + // DOCTYPE
  2369. '(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|' + // PI
  2370. '(?:\\/([^>]+)>)|' + // End element
  2371. '(?:([A-Za-z0-9\\-\\:]+)((?:\\s+[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*|\\/|\\s+)>)' + // Start element
  2372. ')', 'g');
  2373. attrRegExp = /([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:\\.|[^\"])*)\")|(?:\'((?:\\.|[^\'])*)\')|([^>\s]+)))?/g;
  2374. specialElements = {
  2375. 'script' : /<\/script[^>]*>/gi,
  2376. 'style' : /<\/style[^>]*>/gi,
  2377. 'noscript' : /<\/noscript[^>]*>/gi
  2378. };
  2379. // Setup lookup tables for empty elements and boolean attributes
  2380. shortEndedElements = schema.getShortEndedElements();
  2381. selfClosing = settings.self_closing_elements || schema.getSelfClosingElements();
  2382. fillAttrsMap = schema.getBoolAttrs();
  2383. validate = settings.validate;
  2384. removeInternalElements = settings.remove_internals;
  2385. fixSelfClosing = settings.fix_self_closing;
  2386. isIE = tinymce.isIE;
  2387. invalidPrefixRegExp = /^:/;
  2388. while (matches = tokenRegExp.exec(html)) {
  2389. // Text
  2390. if (index < matches.index)
  2391. self.text(decode(html.substr(index, matches.index - index)));
  2392. if (value = matches[6]) { // End element
  2393. value = value.toLowerCase();
  2394. // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
  2395. if (isIE && invalidPrefixRegExp.test(value))
  2396. value = value.substr(1);
  2397. processEndTag(value);
  2398. } else if (value = matches[7]) { // Start element
  2399. value = value.toLowerCase();
  2400. // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
  2401. if (isIE && invalidPrefixRegExp.test(value))
  2402. value = value.substr(1);
  2403. isShortEnded = value in shortEndedElements;
  2404. // Is self closing tag for example an <li> after an open <li>
  2405. if (fixSelfClosing && selfClosing[value] && stack.length > 0 && stack[stack.length - 1].name === value)
  2406. processEndTag(value);
  2407. // Validate element
  2408. if (!validate || (elementRule = schema.getElementRule(value))) {
  2409. isValidElement = true;
  2410. // Grab attributes map and patters when validation is enabled
  2411. if (validate) {
  2412. validAttributesMap = elementRule.attributes;
  2413. validAttributePatterns = elementRule.attributePatterns;
  2414. }
  2415. // Parse attributes
  2416. if (attribsValue = matches[8]) {
  2417. isInternalElement = attribsValue.indexOf('data-mce-type') !== -1; // Check if the element is an internal element
  2418. // If the element has internal attributes then remove it if we are told to do so
  2419. if (isInternalElement && removeInternalElements)
  2420. isValidElement = false;
  2421. attrList = [];
  2422. attrList.map = {};
  2423. attribsValue.replace(attrRegExp, parseAttribute);
  2424. } else {
  2425. attrList = [];
  2426. attrList.map = {};
  2427. }
  2428. // Process attributes if validation is enabled
  2429. if (validate && !isInternalElement) {
  2430. attributesRequired = elementRule.attributesRequired;
  2431. attributesDefault = elementRule.attributesDefault;
  2432. attributesForced = elementRule.attributesForced;
  2433. // Handle forced attributes
  2434. if (attributesForced) {
  2435. i = attributesForced.length;
  2436. while (i--) {
  2437. attr = attributesForced[i];
  2438. name = attr.name;
  2439. attrValue = attr.value;
  2440. if (attrValue === '{$uid}')
  2441. attrValue = 'mce_' + idCount++;
  2442. attrList.map[name] = attrValue;
  2443. attrList.push({name: name, value: attrValue});
  2444. }
  2445. }
  2446. // Handle default attributes
  2447. if (attributesDefault) {
  2448. i = attributesDefault.length;
  2449. while (i--) {
  2450. attr = attributesDefault[i];
  2451. name = attr.name;
  2452. if (!(name in attrList.map)) {
  2453. attrValue = attr.value;
  2454. if (attrValue === '{$uid}')
  2455. attrValue = 'mce_' + idCount++;
  2456. attrList.map[name] = attrValue;
  2457. attrList.push({name: name, value: attrValue});
  2458. }
  2459. }
  2460. }
  2461. // Handle required attributes
  2462. if (attributesRequired) {
  2463. i = attributesRequired.length;
  2464. while (i--) {
  2465. if (attributesRequired[i] in attrList.map)
  2466. break;
  2467. }
  2468. // None of the required attributes where found
  2469. if (i === -1)
  2470. isValidElement = false;
  2471. }
  2472. // Invalidate element if it's marked as bogus
  2473. if (attrList.map['data-mce-bogus'])
  2474. isValidElement = false;
  2475. }
  2476. if (isValidElement)
  2477. self.start(value, attrList, isShortEnded);
  2478. } else
  2479. isValidElement = false;
  2480. // Treat script, noscript and style a bit different since they may include code that looks like elements
  2481. if (endRegExp = specialElements[value]) {
  2482. endRegExp.lastIndex = index = matches.index + matches[0].length;
  2483. if (matches = endRegExp.exec(html)) {
  2484. if (isValidElement)
  2485. text = html.substr(index, matches.index - index);
  2486. index = matches.index + matches[0].length;
  2487. } else {
  2488. text = html.substr(index);
  2489. index = html.length;
  2490. }
  2491. if (isValidElement && text.length > 0)
  2492. self.text(text, true);
  2493. if (isValidElement)
  2494. self.end(value);
  2495. tokenRegExp.lastIndex = index;
  2496. continue;
  2497. }
  2498. // Push value on to stack
  2499. if (!isShortEnded) {
  2500. if (!attribsValue || attribsValue.indexOf('/') != attribsValue.length - 1)
  2501. stack.push({name: value, valid: isValidElement});
  2502. else if (isValidElement)
  2503. self.end(value);
  2504. }
  2505. } else if (value = matches[1]) { // Comment
  2506. self.comment(value);
  2507. } else if (value = matches[2]) { // CDATA
  2508. self.cdata(value);
  2509. } else if (value = matches[3]) { // DOCTYPE
  2510. self.doctype(value);
  2511. } else if (value = matches[4]) { // PI
  2512. self.pi(value, matches[5]);
  2513. }
  2514. index = matches.index + matches[0].length;
  2515. }
  2516. // Text
  2517. if (index < html.length)
  2518. self.text(decode(html.substr(index)));
  2519. // Close any open elements
  2520. for (i = stack.length - 1; i >= 0; i--) {
  2521. value = stack[i];
  2522. if (value.valid)
  2523. self.end(value.name);
  2524. }
  2525. };
  2526. }
  2527. })(tinymce);
  2528. (function(tinymce) {
  2529. var whiteSpaceRegExp = /^[ \t\r\n]*$/, typeLookup = {
  2530. '#text' : 3,
  2531. '#comment' : 8,
  2532. '#cdata' : 4,
  2533. '#pi' : 7,
  2534. '#doctype' : 10,
  2535. '#document-fragment' : 11
  2536. };
  2537. // Walks the tree left/right
  2538. function walk(node, root_node, prev) {
  2539. var sibling, parent, startName = prev ? 'lastChild' : 'firstChild', siblingName = prev ? 'prev' : 'next';
  2540. // Walk into nodes if it has a start
  2541. if (node[startName])
  2542. return node[startName];
  2543. // Return the sibling if it has one
  2544. if (node !== root_node) {
  2545. sibling = node[siblingName];
  2546. if (sibling)
  2547. return sibling;
  2548. // Walk up the parents to look for siblings
  2549. for (parent = node.parent; parent && parent !== root_node; parent = parent.parent) {
  2550. sibling = parent[siblingName];
  2551. if (sibling)
  2552. return sibling;
  2553. }
  2554. }
  2555. };
  2556. function Node(name, type) {
  2557. this.name = name;
  2558. this.type = type;
  2559. if (type === 1) {
  2560. this.attributes = [];
  2561. this.attributes.map = {};
  2562. }
  2563. }
  2564. tinymce.extend(Node.prototype, {
  2565. replace : function(node) {
  2566. var self = this;
  2567. if (node.parent)
  2568. node.remove();
  2569. self.insert(node, self);
  2570. self.remove();
  2571. return self;
  2572. },
  2573. attr : function(name, value) {
  2574. var self = this, attrs, i, undef;
  2575. if (typeof name !== "string") {
  2576. for (i in name)
  2577. self.attr(i, name[i]);
  2578. return self;
  2579. }
  2580. if (attrs = self.attributes) {
  2581. if (value !== undef) {
  2582. // Remove attribute
  2583. if (value === null) {
  2584. if (name in attrs.map) {
  2585. delete attrs.map[name];
  2586. i = attrs.length;
  2587. while (i--) {
  2588. if (attrs[i].name === name) {
  2589. attrs = attrs.splice(i, 1);
  2590. return self;
  2591. }
  2592. }
  2593. }
  2594. return self;
  2595. }
  2596. // Set attribute
  2597. if (name in attrs.map) {
  2598. // Set attribute
  2599. i = attrs.length;
  2600. while (i--) {
  2601. if (attrs[i].name === name) {
  2602. attrs[i].value = value;
  2603. break;
  2604. }
  2605. }
  2606. } else
  2607. attrs.push({name: name, value: value});
  2608. attrs.map[name] = value;
  2609. return self;
  2610. } else {
  2611. return attrs.map[name];
  2612. }
  2613. }
  2614. },
  2615. clone : function() {
  2616. var self = this, clone = new Node(self.name, self.type), i, l, selfAttrs, selfAttr, cloneAttrs;
  2617. // Clone element attributes
  2618. if (selfAttrs = self.attributes) {
  2619. cloneAttrs = [];
  2620. cloneAttrs.map = {};
  2621. for (i = 0, l = selfAttrs.length; i < l; i++) {
  2622. selfAttr = selfAttrs[i];
  2623. // Clone everything except id
  2624. if (selfAttr.name !== 'id') {
  2625. cloneAttrs[cloneAttrs.length] = {name: selfAttr.name, value: selfAttr.value};
  2626. cloneAttrs.map[selfAttr.name] = selfAttr.value;
  2627. }
  2628. }
  2629. clone.attributes = cloneAttrs;
  2630. }
  2631. clone.value = self.value;
  2632. clone.shortEnded = self.shortEnded;
  2633. return clone;
  2634. },
  2635. wrap : function(wrapper) {
  2636. var self = this;
  2637. self.parent.insert(wrapper, self);
  2638. wrapper.append(self);
  2639. return self;
  2640. },
  2641. unwrap : function() {
  2642. var self = this, node, next;
  2643. for (node = self.firstChild; node; ) {
  2644. next = node.next;
  2645. self.insert(node, self, true);
  2646. node = next;
  2647. }
  2648. self.remove();
  2649. },
  2650. remove : function() {
  2651. var self = this, parent = self.parent, next = self.next, prev = self.prev;
  2652. if (parent) {
  2653. if (parent.firstChild === self) {
  2654. parent.firstChild = next;
  2655. if (next)
  2656. next.prev = null;
  2657. } else {
  2658. prev.next = next;
  2659. }
  2660. if (parent.lastChild === self) {
  2661. parent.lastChild = prev;
  2662. if (prev)
  2663. prev.next = null;
  2664. } else {
  2665. next.prev = prev;
  2666. }
  2667. self.parent = self.next = self.prev = null;
  2668. }
  2669. return self;
  2670. },
  2671. append : function(node) {
  2672. var self = this, last;
  2673. if (node.parent)
  2674. node.remove();
  2675. last = self.lastChild;
  2676. if (last) {
  2677. last.next = node;
  2678. node.prev = last;
  2679. self.lastChild = node;
  2680. } else
  2681. self.lastChild = self.firstChild = node;
  2682. node.parent = self;
  2683. return node;
  2684. },
  2685. insert : function(node, ref_node, before) {
  2686. var parent;
  2687. if (node.parent)
  2688. node.remove();
  2689. parent = ref_node.parent || this;
  2690. if (before) {
  2691. if (ref_node === parent.firstChild)
  2692. parent.firstChild = node;
  2693. else
  2694. ref_node.prev.next = node;
  2695. node.prev = ref_node.prev;
  2696. node.next = ref_node;
  2697. ref_node.prev = node;
  2698. } else {
  2699. if (ref_node === parent.lastChild)
  2700. parent.lastChild = node;
  2701. else
  2702. ref_node.next.prev = node;
  2703. node.next = ref_node.next;
  2704. node.prev = ref_node;
  2705. ref_node.next = node;
  2706. }
  2707. node.parent = parent;
  2708. return node;
  2709. },
  2710. getAll : function(name) {
  2711. var self = this, node, collection = [];
  2712. for (node = self.firstChild; node; node = walk(node, self)) {
  2713. if (node.name === name)
  2714. collection.push(node);
  2715. }
  2716. return collection;
  2717. },
  2718. empty : function() {
  2719. var self = this, nodes, i, node;
  2720. // Remove all children
  2721. if (self.firstChild) {
  2722. nodes = [];
  2723. // Collect the children
  2724. for (node = self.firstChild; node; node = walk(node, self))
  2725. nodes.push(node);
  2726. // Remove the children
  2727. i = nodes.length;
  2728. while (i--) {
  2729. node = nodes[i];
  2730. node.parent = node.firstChild = node.lastChild = node.next = node.prev = null;
  2731. }
  2732. }
  2733. self.firstChild = self.lastChild = null;
  2734. return self;
  2735. },
  2736. isEmpty : function(elements) {
  2737. var self = this, node = self.firstChild, i, name;
  2738. if (node) {
  2739. do {
  2740. if (node.type === 1) {
  2741. // Ignore bogus elements
  2742. if (node.attributes.map['data-mce-bogus'])
  2743. continue;
  2744. // Keep empty elements like <img />
  2745. if (elements[node.name])
  2746. return false;
  2747. // Keep elements with data attributes or name attribute like <a name="1"></a>
  2748. i = node.attributes.length;
  2749. while (i--) {
  2750. name = node.attributes[i].name;
  2751. if (name === "name" || name.indexOf('data-') === 0)
  2752. return false;
  2753. }
  2754. }
  2755. // Keep comments
  2756. if (node.type === 8)
  2757. return false;
  2758. // Keep non whitespace text nodes
  2759. if ((node.type === 3 && !whiteSpaceRegExp.test(node.value)))
  2760. return false;
  2761. } while (node = walk(node, self));
  2762. }
  2763. return true;
  2764. },
  2765. walk : function(prev) {
  2766. return walk(this, null, prev);
  2767. }
  2768. });
  2769. tinymce.extend(Node, {
  2770. create : function(name, attrs) {
  2771. var node, attrName;
  2772. // Create node
  2773. node = new Node(name, typeLookup[name] || 1);
  2774. // Add attributes if needed
  2775. if (attrs) {
  2776. for (attrName in attrs)
  2777. node.attr(attrName, attrs[attrName]);
  2778. }
  2779. return node;
  2780. }
  2781. });
  2782. tinymce.html.Node = Node;
  2783. })(tinymce);
  2784. (function(tinymce) {
  2785. var Node = tinymce.html.Node;
  2786. tinymce.html.DomParser = function(settings, schema) {
  2787. var self = this, nodeFilters = {}, attributeFilters = [], matchedNodes = {}, matchedAttributes = {};
  2788. settings = settings || {};
  2789. settings.validate = "validate" in settings ? settings.validate : true;
  2790. settings.root_name = settings.root_name || 'body';
  2791. self.schema = schema = schema || new tinymce.html.Schema();
  2792. function fixInvalidChildren(nodes) {
  2793. var ni, node, parent, parents, newParent, currentNode, tempNode, childNode, i,
  2794. childClone, nonEmptyElements, nonSplitableElements, sibling, nextNode;
  2795. nonSplitableElements = tinymce.makeMap('tr,td,th,tbody,thead,tfoot,table');
  2796. nonEmptyElements = schema.getNonEmptyElements();
  2797. for (ni = 0; ni < nodes.length; ni++) {
  2798. node = nodes[ni];
  2799. // Already removed
  2800. if (!node.parent)
  2801. continue;
  2802. // Get list of all parent nodes until we find a valid parent to stick the child into
  2803. parents = [node];
  2804. for (parent = node.parent; parent && !schema.isValidChild(parent.name, node.name) && !nonSplitableElements[parent.name]; parent = parent.parent)
  2805. parents.push(parent);
  2806. // Found a suitable parent
  2807. if (parent && parents.length > 1) {
  2808. // Reverse the array since it makes looping easier
  2809. parents.reverse();
  2810. // Clone the related parent and insert that after the moved node
  2811. newParent = currentNode = self.filterNode(parents[0].clone());
  2812. // Start cloning and moving children on the left side of the target node
  2813. for (i = 0; i < parents.length - 1; i++) {
  2814. if (schema.isValidChild(currentNode.name, parents[i].name)) {
  2815. tempNode = self.filterNode(parents[i].clone());
  2816. currentNode.append(tempNode);
  2817. } else
  2818. tempNode = currentNode;
  2819. for (childNode = parents[i].firstChild; childNode && childNode != parents[i + 1]; ) {
  2820. nextNode = childNode.next;
  2821. tempNode.append(childNode);
  2822. childNode = nextNode;
  2823. }
  2824. currentNode = tempNode;
  2825. }
  2826. if (!newParent.isEmpty(nonEmptyElements)) {
  2827. parent.insert(newParent, parents[0], true);
  2828. parent.insert(node, newParent);
  2829. } else {
  2830. parent.insert(node, parents[0], true);
  2831. }
  2832. // Check if the element is empty by looking through it's contents and special treatment for <p><br /></p>
  2833. parent = parents[0];
  2834. if (parent.isEmpty(nonEmptyElements) || parent.firstChild === parent.lastChild && parent.firstChild.name === 'br') {
  2835. parent.empty().remove();
  2836. }
  2837. } else if (node.parent) {
  2838. // If it's an LI try to find a UL/OL for it or wrap it
  2839. if (node.name === 'li') {
  2840. sibling = node.prev;
  2841. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  2842. sibling.append(node);
  2843. continue;
  2844. }
  2845. sibling = node.next;
  2846. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  2847. sibling.insert(node, sibling.firstChild, true);
  2848. continue;
  2849. }
  2850. node.wrap(self.filterNode(new Node('ul', 1)));
  2851. continue;
  2852. }
  2853. // Try wrapping the element in a DIV
  2854. if (schema.isValidChild(node.parent.name, 'div') && schema.isValidChild('div', node.name)) {
  2855. node.wrap(self.filterNode(new Node('div', 1)));
  2856. } else {
  2857. // We failed wrapping it, then remove or unwrap it
  2858. if (node.name === 'style' || node.name === 'script')
  2859. node.empty().remove();
  2860. else
  2861. node.unwrap();
  2862. }
  2863. }
  2864. }
  2865. };
  2866. self.filterNode = function(node) {
  2867. var i, name, list;
  2868. // Run element filters
  2869. if (name in nodeFilters) {
  2870. list = matchedNodes[name];
  2871. if (list)
  2872. list.push(node);
  2873. else
  2874. matchedNodes[name] = [node];
  2875. }
  2876. // Run attribute filters
  2877. i = attributeFilters.length;
  2878. while (i--) {
  2879. name = attributeFilters[i].name;
  2880. if (name in node.attributes.map) {
  2881. list = matchedAttributes[name];
  2882. if (list)
  2883. list.push(node);
  2884. else
  2885. matchedAttributes[name] = [node];
  2886. }
  2887. }
  2888. return node;
  2889. };
  2890. self.addNodeFilter = function(name, callback) {
  2891. tinymce.each(tinymce.explode(name), function(name) {
  2892. var list = nodeFilters[name];
  2893. if (!list)
  2894. nodeFilters[name] = list = [];
  2895. list.push(callback);
  2896. });
  2897. };
  2898. self.addAttributeFilter = function(name, callback) {
  2899. tinymce.each(tinymce.explode(name), function(name) {
  2900. var i;
  2901. for (i = 0; i < attributeFilters.length; i++) {
  2902. if (attributeFilters[i].name === name) {
  2903. attributeFilters[i].callbacks.push(callback);
  2904. return;
  2905. }
  2906. }
  2907. attributeFilters.push({name: name, callbacks: [callback]});
  2908. });
  2909. };
  2910. self.parse = function(html, args) {
  2911. var parser, rootNode, node, nodes, i, l, fi, fl, list, name, validate,
  2912. blockElements, startWhiteSpaceRegExp, invalidChildren = [], isInWhiteSpacePreservedElement,
  2913. endWhiteSpaceRegExp, allWhiteSpaceRegExp, isAllWhiteSpaceRegExp, whiteSpaceElements, children, nonEmptyElements, rootBlockName;
  2914. args = args || {};
  2915. matchedNodes = {};
  2916. matchedAttributes = {};
  2917. blockElements = tinymce.extend(tinymce.makeMap('script,style,head,html,body,title,meta,param'), schema.getBlockElements());
  2918. nonEmptyElements = schema.getNonEmptyElements();
  2919. children = schema.children;
  2920. validate = settings.validate;
  2921. rootBlockName = "forced_root_block" in args ? args.forced_root_block : settings.forced_root_block;
  2922. whiteSpaceElements = schema.getWhiteSpaceElements();
  2923. startWhiteSpaceRegExp = /^[ \t\r\n]+/;
  2924. endWhiteSpaceRegExp = /[ \t\r\n]+$/;
  2925. allWhiteSpaceRegExp = /[ \t\r\n]+/g;
  2926. isAllWhiteSpaceRegExp = /^[ \t\r\n]+$/;
  2927. function addRootBlocks() {
  2928. var node = rootNode.firstChild, next, rootBlockNode;
  2929. while (node) {
  2930. next = node.next;
  2931. if (node.type == 3 || (node.type == 1 && node.name !== 'p' && !blockElements[node.name] && !node.attr('data-mce-type'))) {
  2932. if (!rootBlockNode) {
  2933. // Create a new root block element
  2934. rootBlockNode = createNode(rootBlockName, 1);
  2935. rootNode.insert(rootBlockNode, node);
  2936. rootBlockNode.append(node);
  2937. } else
  2938. rootBlockNode.append(node);
  2939. } else {
  2940. rootBlockNode = null;
  2941. }
  2942. node = next;
  2943. };
  2944. };
  2945. function createNode(name, type) {
  2946. var node = new Node(name, type), list;
  2947. if (name in nodeFilters) {
  2948. list = matchedNodes[name];
  2949. if (list)
  2950. list.push(node);
  2951. else
  2952. matchedNodes[name] = [node];
  2953. }
  2954. return node;
  2955. };
  2956. function removeWhitespaceBefore(node) {
  2957. var textNode, textVal, sibling;
  2958. for (textNode = node.prev; textNode && textNode.type === 3; ) {
  2959. textVal = textNode.value.replace(endWhiteSpaceRegExp, '');
  2960. if (textVal.length > 0) {
  2961. textNode.value = textVal;
  2962. textNode = textNode.prev;
  2963. } else {
  2964. sibling = textNode.prev;
  2965. textNode.remove();
  2966. textNode = sibling;
  2967. }
  2968. }
  2969. };
  2970. function cloneAndExcludeBlocks(input) {
  2971. var name, output = {};
  2972. for (name in input) {
  2973. if (name !== 'li' && name != 'p') {
  2974. output[name] = input[name];
  2975. }
  2976. }
  2977. return output;
  2978. };
  2979. parser = new tinymce.html.SaxParser({
  2980. validate : validate,
  2981. // Exclude P and LI from DOM parsing since it's treated better by the DOM parser
  2982. self_closing_elements: cloneAndExcludeBlocks(schema.getSelfClosingElements()),
  2983. cdata: function(text) {
  2984. node.append(createNode('#cdata', 4)).value = text;
  2985. },
  2986. text: function(text, raw) {
  2987. var textNode;
  2988. // Trim all redundant whitespace on non white space elements
  2989. if (!isInWhiteSpacePreservedElement) {
  2990. text = text.replace(allWhiteSpaceRegExp, ' ');
  2991. if (node.lastChild && blockElements[node.lastChild.name])
  2992. text = text.replace(startWhiteSpaceRegExp, '');
  2993. }
  2994. // Do we need to create the node
  2995. if (text.length !== 0) {
  2996. textNode = createNode('#text', 3);
  2997. textNode.raw = !!raw;
  2998. node.append(textNode).value = text;
  2999. }
  3000. },
  3001. comment: function(text) {
  3002. node.append(createNode('#comment', 8)).value = text;
  3003. },
  3004. pi: function(name, text) {
  3005. node.append(createNode(name, 7)).value = text;
  3006. removeWhitespaceBefore(node);
  3007. },
  3008. doctype: function(text) {
  3009. var newNode;
  3010. newNode = node.append(createNode('#doctype', 10));
  3011. newNode.value = text;
  3012. removeWhitespaceBefore(node);
  3013. },
  3014. start: function(name, attrs, empty) {
  3015. var newNode, attrFiltersLen, elementRule, textNode, attrName, text, sibling, parent;
  3016. elementRule = validate ? schema.getElementRule(name) : {};
  3017. if (elementRule) {
  3018. newNode = createNode(elementRule.outputName || name, 1);
  3019. newNode.attributes = attrs;
  3020. newNode.shortEnded = empty;
  3021. node.append(newNode);
  3022. // Check if node is valid child of the parent node is the child is
  3023. // unknown we don't collect it since it's probably a custom element
  3024. parent = children[node.name];
  3025. if (parent && children[newNode.name] && !parent[newNode.name])
  3026. invalidChildren.push(newNode);
  3027. attrFiltersLen = attributeFilters.length;
  3028. while (attrFiltersLen--) {
  3029. attrName = attributeFilters[attrFiltersLen].name;
  3030. if (attrName in attrs.map) {
  3031. list = matchedAttributes[attrName];
  3032. if (list)
  3033. list.push(newNode);
  3034. else
  3035. matchedAttributes[attrName] = [newNode];
  3036. }
  3037. }
  3038. // Trim whitespace before block
  3039. if (blockElements[name])
  3040. removeWhitespaceBefore(newNode);
  3041. // Change current node if the element wasn't empty i.e not <br /> or <img />
  3042. if (!empty)
  3043. node = newNode;
  3044. // Check if we are inside a whitespace preserved element
  3045. if (!isInWhiteSpacePreservedElement && whiteSpaceElements[name]) {
  3046. isInWhiteSpacePreservedElement = true;
  3047. }
  3048. }
  3049. },
  3050. end: function(name) {
  3051. var textNode, elementRule, text, sibling, tempNode;
  3052. elementRule = validate ? schema.getElementRule(name) : {};
  3053. if (elementRule) {
  3054. if (blockElements[name]) {
  3055. if (!isInWhiteSpacePreservedElement) {
  3056. // Trim whitespace of the first node in a block
  3057. textNode = node.firstChild;
  3058. if (textNode && textNode.type === 3) {
  3059. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  3060. // Any characters left after trim or should we remove it
  3061. if (text.length > 0) {
  3062. textNode.value = text;
  3063. textNode = textNode.next;
  3064. } else {
  3065. sibling = textNode.next;
  3066. textNode.remove();
  3067. textNode = sibling;
  3068. }
  3069. // Remove any pure whitespace siblings
  3070. while (textNode && textNode.type === 3) {
  3071. text = textNode.value;
  3072. sibling = textNode.next;
  3073. if (text.length === 0 || isAllWhiteSpaceRegExp.test(text)) {
  3074. textNode.remove();
  3075. textNode = sibling;
  3076. }
  3077. textNode = sibling;
  3078. }
  3079. }
  3080. // Trim whitespace of the last node in a block
  3081. textNode = node.lastChild;
  3082. if (textNode && textNode.type === 3) {
  3083. text = textNode.value.replace(endWhiteSpaceRegExp, '');
  3084. // Any characters left after trim or should we remove it
  3085. if (text.length > 0) {
  3086. textNode.value = text;
  3087. textNode = textNode.prev;
  3088. } else {
  3089. sibling = textNode.prev;
  3090. textNode.remove();
  3091. textNode = sibling;
  3092. }
  3093. // Remove any pure whitespace siblings
  3094. while (textNode && textNode.type === 3) {
  3095. text = textNode.value;
  3096. sibling = textNode.prev;
  3097. if (text.length === 0 || isAllWhiteSpaceRegExp.test(text)) {
  3098. textNode.remove();
  3099. textNode = sibling;
  3100. }
  3101. textNode = sibling;
  3102. }
  3103. }
  3104. }
  3105. // Trim start white space
  3106. textNode = node.prev;
  3107. if (textNode && textNode.type === 3) {
  3108. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  3109. if (text.length > 0)
  3110. textNode.value = text;
  3111. else
  3112. textNode.remove();
  3113. }
  3114. }
  3115. // Check if we exited a whitespace preserved element
  3116. if (isInWhiteSpacePreservedElement && whiteSpaceElements[name]) {
  3117. isInWhiteSpacePreservedElement = false;
  3118. }
  3119. // Handle empty nodes
  3120. if (elementRule.removeEmpty || elementRule.paddEmpty) {
  3121. if (node.isEmpty(nonEmptyElements)) {
  3122. if (elementRule.paddEmpty)
  3123. node.empty().append(new Node('#text', '3')).value = '\u00a0';
  3124. else {
  3125. // Leave nodes that have a name like <a name="name">
  3126. if (!node.attributes.map.name && !node.attributes.map.id) {
  3127. tempNode = node.parent;
  3128. node.empty().remove();
  3129. node = tempNode;
  3130. return;
  3131. }
  3132. }
  3133. }
  3134. }
  3135. node = node.parent;
  3136. }
  3137. }
  3138. }, schema);
  3139. rootNode = node = new Node(args.context || settings.root_name, 11);
  3140. parser.parse(html);
  3141. // Fix invalid children or report invalid children in a contextual parsing
  3142. if (validate && invalidChildren.length) {
  3143. if (!args.context)
  3144. fixInvalidChildren(invalidChildren);
  3145. else
  3146. args.invalid = true;
  3147. }
  3148. // Wrap nodes in the root into block elements if the root is body
  3149. if (rootBlockName && rootNode.name == 'body')
  3150. addRootBlocks();
  3151. // Run filters only when the contents is valid
  3152. if (!args.invalid) {
  3153. // Run node filters
  3154. for (name in matchedNodes) {
  3155. list = nodeFilters[name];
  3156. nodes = matchedNodes[name];
  3157. // Remove already removed children
  3158. fi = nodes.length;
  3159. while (fi--) {
  3160. if (!nodes[fi].parent)
  3161. nodes.splice(fi, 1);
  3162. }
  3163. for (i = 0, l = list.length; i < l; i++)
  3164. list[i](nodes, name, args);
  3165. }
  3166. // Run attribute filters
  3167. for (i = 0, l = attributeFilters.length; i < l; i++) {
  3168. list = attributeFilters[i];
  3169. if (list.name in matchedAttributes) {
  3170. nodes = matchedAttributes[list.name];
  3171. // Remove already removed children
  3172. fi = nodes.length;
  3173. while (fi--) {
  3174. if (!nodes[fi].parent)
  3175. nodes.splice(fi, 1);
  3176. }
  3177. for (fi = 0, fl = list.callbacks.length; fi < fl; fi++)
  3178. list.callbacks[fi](nodes, list.name, args);
  3179. }
  3180. }
  3181. }
  3182. return rootNode;
  3183. };
  3184. // Remove <br> at end of block elements Gecko and WebKit injects BR elements to
  3185. // make it possible to place the caret inside empty blocks. This logic tries to remove
  3186. // these elements and keep br elements that where intended to be there intact
  3187. if (settings.remove_trailing_brs) {
  3188. self.addNodeFilter('br', function(nodes, name) {
  3189. var i, l = nodes.length, node, blockElements = tinymce.extend({}, schema.getBlockElements()),
  3190. nonEmptyElements = schema.getNonEmptyElements(), parent, lastParent, prev, prevName;
  3191. // Remove brs from body element as well
  3192. blockElements.body = 1;
  3193. // Must loop forwards since it will otherwise remove all brs in <p>a<br><br><br></p>
  3194. for (i = 0; i < l; i++) {
  3195. node = nodes[i];
  3196. parent = node.parent;
  3197. if (blockElements[node.parent.name] && node === parent.lastChild) {
  3198. // Loop all nodes to the left of the current node and check for other BR elements
  3199. // excluding bookmarks since they are invisible
  3200. prev = node.prev;
  3201. while (prev) {
  3202. prevName = prev.name;
  3203. // Ignore bookmarks
  3204. if (prevName !== "span" || prev.attr('data-mce-type') !== 'bookmark') {
  3205. // Found a non BR element
  3206. if (prevName !== "br")
  3207. break;
  3208. // Found another br it's a <br><br> structure then don't remove anything
  3209. if (prevName === 'br') {
  3210. node = null;
  3211. break;
  3212. }
  3213. }
  3214. prev = prev.prev;
  3215. }
  3216. if (node) {
  3217. node.remove();
  3218. // Is the parent to be considered empty after we removed the BR
  3219. if (parent.isEmpty(nonEmptyElements)) {
  3220. elementRule = schema.getElementRule(parent.name);
  3221. // Remove or padd the element depending on schema rule
  3222. if (elementRule) {
  3223. if (elementRule.removeEmpty)
  3224. parent.remove();
  3225. else if (elementRule.paddEmpty)
  3226. parent.empty().append(new tinymce.html.Node('#text', 3)).value = '\u00a0';
  3227. }
  3228. }
  3229. }
  3230. } else {
  3231. // Replaces BR elements inside inline elements like <p><b><i><br></i></b></p> so they become <p><b><i>&nbsp;</i></b></p>
  3232. lastParent = node;
  3233. while (parent.firstChild === lastParent && parent.lastChild === lastParent) {
  3234. lastParent = parent;
  3235. if (blockElements[parent.name]) {
  3236. break;
  3237. }
  3238. parent = parent.parent;
  3239. }
  3240. if (lastParent === parent) {
  3241. textNode = new tinymce.html.Node('#text', 3);
  3242. textNode.value = '\u00a0';
  3243. node.replace(textNode);
  3244. }
  3245. }
  3246. }
  3247. });
  3248. }
  3249. // Force anchor names closed, unless the setting "allow_html_in_named_anchor" is explicitly included.
  3250. if (!settings.allow_html_in_named_anchor) {
  3251. self.addAttributeFilter('id,name', function(nodes, name) {
  3252. var i = nodes.length, sibling, prevSibling, parent, node;
  3253. while (i--) {
  3254. node = nodes[i];
  3255. if (node.name === 'a' && node.firstChild && !node.attr('href')) {
  3256. parent = node.parent;
  3257. // Move children after current node
  3258. sibling = node.lastChild;
  3259. do {
  3260. prevSibling = sibling.prev;
  3261. parent.insert(sibling, node);
  3262. sibling = prevSibling;
  3263. } while (sibling);
  3264. }
  3265. }
  3266. });
  3267. }
  3268. }
  3269. })(tinymce);
  3270. tinymce.html.Writer = function(settings) {
  3271. var html = [], indent, indentBefore, indentAfter, encode, htmlOutput;
  3272. settings = settings || {};
  3273. indent = settings.indent;
  3274. indentBefore = tinymce.makeMap(settings.indent_before || '');
  3275. indentAfter = tinymce.makeMap(settings.indent_after || '');
  3276. encode = tinymce.html.Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities);
  3277. htmlOutput = settings.element_format == "html";
  3278. return {
  3279. start: function(name, attrs, empty) {
  3280. var i, l, attr, value;
  3281. if (indent && indentBefore[name] && html.length > 0) {
  3282. value = html[html.length - 1];
  3283. if (value.length > 0 && value !== '\n')
  3284. html.push('\n');
  3285. }
  3286. html.push('<', name);
  3287. if (attrs) {
  3288. for (i = 0, l = attrs.length; i < l; i++) {
  3289. attr = attrs[i];
  3290. html.push(' ', attr.name, '="', encode(attr.value, true), '"');
  3291. }
  3292. }
  3293. if (!empty || htmlOutput)
  3294. html[html.length] = '>';
  3295. else
  3296. html[html.length] = ' />';
  3297. if (empty && indent && indentAfter[name] && html.length > 0) {
  3298. value = html[html.length - 1];
  3299. if (value.length > 0 && value !== '\n')
  3300. html.push('\n');
  3301. }
  3302. },
  3303. end: function(name) {
  3304. var value;
  3305. /*if (indent && indentBefore[name] && html.length > 0) {
  3306. value = html[html.length - 1];
  3307. if (value.length > 0 && value !== '\n')
  3308. html.push('\n');
  3309. }*/
  3310. html.push('</', name, '>');
  3311. if (indent && indentAfter[name] && html.length > 0) {
  3312. value = html[html.length - 1];
  3313. if (value.length > 0 && value !== '\n')
  3314. html.push('\n');
  3315. }
  3316. },
  3317. text: function(text, raw) {
  3318. if (text.length > 0)
  3319. html[html.length] = raw ? text : encode(text);
  3320. },
  3321. cdata: function(text) {
  3322. html.push('<![CDATA[', text, ']]>');
  3323. },
  3324. comment: function(text) {
  3325. html.push('<!--', text, '-->');
  3326. },
  3327. pi: function(name, text) {
  3328. if (text)
  3329. html.push('<?', name, ' ', text, '?>');
  3330. else
  3331. html.push('<?', name, '?>');
  3332. if (indent)
  3333. html.push('\n');
  3334. },
  3335. doctype: function(text) {
  3336. html.push('<!DOCTYPE', text, '>', indent ? '\n' : '');
  3337. },
  3338. reset: function() {
  3339. html.length = 0;
  3340. },
  3341. getContent: function() {
  3342. return html.join('').replace(/\n$/, '');
  3343. }
  3344. };
  3345. };
  3346. (function(tinymce) {
  3347. tinymce.html.Serializer = function(settings, schema) {
  3348. var self = this, writer = new tinymce.html.Writer(settings);
  3349. settings = settings || {};
  3350. settings.validate = "validate" in settings ? settings.validate : true;
  3351. self.schema = schema = schema || new tinymce.html.Schema();
  3352. self.writer = writer;
  3353. self.serialize = function(node) {
  3354. var handlers, validate;
  3355. validate = settings.validate;
  3356. handlers = {
  3357. // #text
  3358. 3: function(node, raw) {
  3359. writer.text(node.value, node.raw);
  3360. },
  3361. // #comment
  3362. 8: function(node) {
  3363. writer.comment(node.value);
  3364. },
  3365. // Processing instruction
  3366. 7: function(node) {
  3367. writer.pi(node.name, node.value);
  3368. },
  3369. // Doctype
  3370. 10: function(node) {
  3371. writer.doctype(node.value);
  3372. },
  3373. // CDATA
  3374. 4: function(node) {
  3375. writer.cdata(node.value);
  3376. },
  3377. // Document fragment
  3378. 11: function(node) {
  3379. if ((node = node.firstChild)) {
  3380. do {
  3381. walk(node);
  3382. } while (node = node.next);
  3383. }
  3384. }
  3385. };
  3386. writer.reset();
  3387. function walk(node) {
  3388. var handler = handlers[node.type], name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule;
  3389. if (!handler) {
  3390. name = node.name;
  3391. isEmpty = node.shortEnded;
  3392. attrs = node.attributes;
  3393. // Sort attributes
  3394. if (validate && attrs && attrs.length > 1) {
  3395. sortedAttrs = [];
  3396. sortedAttrs.map = {};
  3397. elementRule = schema.getElementRule(node.name);
  3398. for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
  3399. attrName = elementRule.attributesOrder[i];
  3400. if (attrName in attrs.map) {
  3401. attrValue = attrs.map[attrName];
  3402. sortedAttrs.map[attrName] = attrValue;
  3403. sortedAttrs.push({name: attrName, value: attrValue});
  3404. }
  3405. }
  3406. for (i = 0, l = attrs.length; i < l; i++) {
  3407. attrName = attrs[i].name;
  3408. if (!(attrName in sortedAttrs.map)) {
  3409. attrValue = attrs.map[attrName];
  3410. sortedAttrs.map[attrName] = attrValue;
  3411. sortedAttrs.push({name: attrName, value: attrValue});
  3412. }
  3413. }
  3414. attrs = sortedAttrs;
  3415. }
  3416. writer.start(node.name, attrs, isEmpty);
  3417. if (!isEmpty) {
  3418. if ((node = node.firstChild)) {
  3419. do {
  3420. walk(node);
  3421. } while (node = node.next);
  3422. }
  3423. writer.end(name);
  3424. }
  3425. } else
  3426. handler(node);
  3427. }
  3428. // Serialize element and treat all non elements as fragments
  3429. if (node.type == 1 && !settings.inner)
  3430. walk(node);
  3431. else
  3432. handlers[11](node);
  3433. return writer.getContent();
  3434. };
  3435. }
  3436. })(tinymce);
  3437. // JSLint defined globals
  3438. /*global tinymce:false, window:false */
  3439. tinymce.dom = {};
  3440. (function(namespace, expando) {
  3441. var w3cEventModel = !!document.addEventListener;
  3442. function addEvent(target, name, callback, capture) {
  3443. if (target.addEventListener) {
  3444. target.addEventListener(name, callback, capture || false);
  3445. } else if (target.attachEvent) {
  3446. target.attachEvent('on' + name, callback);
  3447. }
  3448. }
  3449. function removeEvent(target, name, callback, capture) {
  3450. if (target.removeEventListener) {
  3451. target.removeEventListener(name, callback, capture || false);
  3452. } else if (target.detachEvent) {
  3453. target.detachEvent('on' + name, callback);
  3454. }
  3455. }
  3456. function fix(original_event, data) {
  3457. var name, event = data || {};
  3458. // Dummy function that gets replaced on the delegation state functions
  3459. function returnFalse() {
  3460. return false;
  3461. }
  3462. // Dummy function that gets replaced on the delegation state functions
  3463. function returnTrue() {
  3464. return true;
  3465. }
  3466. // Copy all properties from the original event
  3467. for (name in original_event) {
  3468. // layerX/layerY is deprecated in Chrome and produces a warning
  3469. if (name !== "layerX" && name !== "layerY") {
  3470. event[name] = original_event[name];
  3471. }
  3472. }
  3473. // Normalize target IE uses srcElement
  3474. if (!event.target) {
  3475. event.target = event.srcElement || document;
  3476. }
  3477. // Add preventDefault method
  3478. event.preventDefault = function() {
  3479. event.isDefaultPrevented = returnTrue;
  3480. // Execute preventDefault on the original event object
  3481. if (original_event) {
  3482. if (original_event.preventDefault) {
  3483. original_event.preventDefault();
  3484. } else {
  3485. original_event.returnValue = false; // IE
  3486. }
  3487. }
  3488. };
  3489. // Add stopPropagation
  3490. event.stopPropagation = function() {
  3491. event.isPropagationStopped = returnTrue;
  3492. // Execute stopPropagation on the original event object
  3493. if (original_event) {
  3494. if (original_event.stopPropagation) {
  3495. original_event.stopPropagation();
  3496. } else {
  3497. original_event.cancelBubble = true; // IE
  3498. }
  3499. }
  3500. };
  3501. // Add stopImmediatePropagation
  3502. event.stopImmediatePropagation = function() {
  3503. event.isImmediatePropagationStopped = returnTrue;
  3504. event.stopPropagation();
  3505. };
  3506. // Add event delegation states
  3507. if (!event.isDefaultPrevented) {
  3508. event.isDefaultPrevented = returnFalse;
  3509. event.isPropagationStopped = returnFalse;
  3510. event.isImmediatePropagationStopped = returnFalse;
  3511. }
  3512. return event;
  3513. }
  3514. function bindOnReady(win, callback, event_utils) {
  3515. var doc = win.document, event = {type: 'ready'};
  3516. // Gets called when the DOM is ready
  3517. function readyHandler() {
  3518. if (!event_utils.domLoaded) {
  3519. event_utils.domLoaded = true;
  3520. callback(event);
  3521. }
  3522. }
  3523. // Use W3C method
  3524. if (w3cEventModel) {
  3525. addEvent(win, 'DOMContentLoaded', readyHandler);
  3526. } else {
  3527. // Use IE method
  3528. addEvent(doc, "readystatechange", function() {
  3529. if (doc.readyState === "complete") {
  3530. removeEvent(doc, "readystatechange", arguments.callee);
  3531. readyHandler();
  3532. }
  3533. });
  3534. // Wait until we can scroll, when we can the DOM is initialized
  3535. if (doc.documentElement.doScroll && win === win.top) {
  3536. (function() {
  3537. try {
  3538. // If IE is used, use the trick by Diego Perini licensed under MIT by request to the author.
  3539. // http://javascript.nwbox.com/IEContentLoaded/
  3540. doc.documentElement.doScroll("left");
  3541. } catch (ex) {
  3542. setTimeout(arguments.callee, 0);
  3543. return;
  3544. }
  3545. readyHandler();
  3546. })();
  3547. }
  3548. }
  3549. // Fallback if any of the above methods should fail for some odd reason
  3550. addEvent(win, 'load', readyHandler);
  3551. }
  3552. function EventUtils(proxy) {
  3553. var self = this, events = {}, count, isFocusBlurBound, hasFocusIn, hasMouseEnterLeave, mouseEnterLeave;
  3554. hasMouseEnterLeave = "onmouseenter" in document.documentElement;
  3555. hasFocusIn = "onfocusin" in document.documentElement;
  3556. mouseEnterLeave = {mouseenter: 'mouseover', mouseleave: 'mouseout'};
  3557. count = 1;
  3558. // State if the DOMContentLoaded was executed or not
  3559. self.domLoaded = false;
  3560. self.events = events;
  3561. function executeHandlers(evt, id) {
  3562. var callbackList, i, l, callback;
  3563. callbackList = events[id][evt.type];
  3564. if (callbackList) {
  3565. for (i = 0, l = callbackList.length; i < l; i++) {
  3566. callback = callbackList[i];
  3567. // Check if callback exists might be removed if a unbind is called inside the callback
  3568. if (callback && callback.func.call(callback.scope, evt) === false) {
  3569. evt.preventDefault();
  3570. }
  3571. // Should we stop propagation to immediate listeners
  3572. if (evt.isImmediatePropagationStopped()) {
  3573. return;
  3574. }
  3575. }
  3576. }
  3577. }
  3578. self.bind = function(target, names, callback, scope) {
  3579. var id, callbackList, i, name, fakeName, nativeHandler, capture, win = window;
  3580. // Native event handler function patches the event and executes the callbacks for the expando
  3581. function defaultNativeHandler(evt) {
  3582. executeHandlers(fix(evt || win.event), id);
  3583. }
  3584. // Don't bind to text nodes or comments
  3585. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  3586. return;
  3587. }
  3588. // Create or get events id for the target
  3589. if (!target[expando]) {
  3590. id = count++;
  3591. target[expando] = id;
  3592. events[id] = {};
  3593. } else {
  3594. id = target[expando];
  3595. if (!events[id]) {
  3596. events[id] = {};
  3597. }
  3598. }
  3599. // Setup the specified scope or use the target as a default
  3600. scope = scope || target;
  3601. // Split names and bind each event, enables you to bind multiple events with one call
  3602. names = names.split(' ');
  3603. i = names.length;
  3604. while (i--) {
  3605. name = names[i];
  3606. nativeHandler = defaultNativeHandler;
  3607. fakeName = capture = false;
  3608. // Use ready instead of DOMContentLoaded
  3609. if (name === "DOMContentLoaded") {
  3610. name = "ready";
  3611. }
  3612. // DOM is already ready
  3613. if ((self.domLoaded || target.readyState == 'complete') && name === "ready") {
  3614. self.domLoaded = true;
  3615. callback.call(scope, fix({type: name}));
  3616. continue;
  3617. }
  3618. // Handle mouseenter/mouseleaver
  3619. if (!hasMouseEnterLeave) {
  3620. fakeName = mouseEnterLeave[name];
  3621. if (fakeName) {
  3622. nativeHandler = function(evt) {
  3623. var current, related;
  3624. current = evt.currentTarget;
  3625. related = evt.relatedTarget;
  3626. // 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
  3627. if (related && current.contains) {
  3628. // Use contains for performance
  3629. related = current.contains(related);
  3630. } else {
  3631. while (related && related !== current) {
  3632. related = related.parentNode;
  3633. }
  3634. }
  3635. // Fire fake event
  3636. if (!related) {
  3637. evt = fix(evt || win.event);
  3638. evt.type = evt.type === 'mouseout' ? 'mouseleave' : 'mouseenter';
  3639. evt.target = current;
  3640. executeHandlers(evt, id);
  3641. }
  3642. };
  3643. }
  3644. }
  3645. // Fake bubbeling of focusin/focusout
  3646. if (!hasFocusIn && (name === "focusin" || name === "focusout")) {
  3647. capture = true;
  3648. fakeName = name === "focusin" ? "focus" : "blur";
  3649. nativeHandler = function(evt) {
  3650. evt = fix(evt || win.event);
  3651. evt.type = evt.type === 'focus' ? 'focusin' : 'focusout';
  3652. executeHandlers(evt, id);
  3653. };
  3654. }
  3655. // Setup callback list and bind native event
  3656. callbackList = events[id][name];
  3657. if (!callbackList) {
  3658. events[id][name] = callbackList = [{func: callback, scope: scope}];
  3659. callbackList.fakeName = fakeName;
  3660. callbackList.capture = capture;
  3661. // Add the nativeHandler to the callback list so that we can later unbind it
  3662. callbackList.nativeHandler = nativeHandler;
  3663. if (!w3cEventModel) {
  3664. callbackList.proxyHandler = proxy(id);
  3665. }
  3666. // Check if the target has native events support
  3667. if (name === "ready") {
  3668. bindOnReady(target, nativeHandler, self);
  3669. } else {
  3670. addEvent(target, fakeName || name, w3cEventModel ? nativeHandler : callbackList.proxyHandler, capture);
  3671. }
  3672. } else {
  3673. // If it already has an native handler then just push the callback
  3674. callbackList.push({func: callback, scope: scope});
  3675. }
  3676. }
  3677. target = callbackList = 0; // Clean memory for IE
  3678. return callback;
  3679. };
  3680. self.unbind = function(target, names, callback) {
  3681. var id, callbackList, i, ci, name, eventMap;
  3682. // Don't bind to text nodes or comments
  3683. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  3684. return self;
  3685. }
  3686. // Unbind event or events if the target has the expando
  3687. id = target[expando];
  3688. if (id) {
  3689. eventMap = events[id];
  3690. // Specific callback
  3691. if (names) {
  3692. names = names.split(' ');
  3693. i = names.length;
  3694. while (i--) {
  3695. name = names[i];
  3696. callbackList = eventMap[name];
  3697. // Unbind the event if it exists in the map
  3698. if (callbackList) {
  3699. // Remove specified callback
  3700. if (callback) {
  3701. ci = callbackList.length;
  3702. while (ci--) {
  3703. if (callbackList[ci].func === callback) {
  3704. callbackList.splice(ci, 1);
  3705. }
  3706. }
  3707. }
  3708. // Remove all callbacks if there isn't a specified callback or there is no callbacks left
  3709. if (!callback || callbackList.length === 0) {
  3710. delete eventMap[name];
  3711. removeEvent(target, callbackList.fakeName || name, w3cEventModel ? callbackList.nativeHandler : callbackList.proxyHandler, callbackList.capture);
  3712. }
  3713. }
  3714. }
  3715. } else {
  3716. // All events for a specific element
  3717. for (name in eventMap) {
  3718. callbackList = eventMap[name];
  3719. removeEvent(target, callbackList.fakeName || name, w3cEventModel ? callbackList.nativeHandler : callbackList.proxyHandler, callbackList.capture);
  3720. }
  3721. eventMap = {};
  3722. }
  3723. // Check if object is empty, if it isn't then we won't remove the expando map
  3724. for (name in eventMap) {
  3725. return self;
  3726. }
  3727. // Delete event object
  3728. delete events[id];
  3729. // Remove expando from target
  3730. try {
  3731. // IE will fail here since it can't delete properties from window
  3732. delete target[expando];
  3733. } catch (ex) {
  3734. // IE will set it to null
  3735. target[expando] = null;
  3736. }
  3737. }
  3738. return self;
  3739. };
  3740. self.fire = function(target, name, args) {
  3741. var id, event;
  3742. // Don't bind to text nodes or comments
  3743. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  3744. return self;
  3745. }
  3746. // Build event object by patching the args
  3747. event = fix(null, args);
  3748. event.type = name;
  3749. do {
  3750. // Found an expando that means there is listeners to execute
  3751. id = target[expando];
  3752. if (id) {
  3753. executeHandlers(event, id);
  3754. }
  3755. // Walk up the DOM
  3756. target = target.parentNode || target.ownerDocument || target.defaultView || target.parentWindow;
  3757. } while (target && !event.isPropagationStopped());
  3758. return self;
  3759. };
  3760. self.clean = function(target) {
  3761. var i, children, unbind = self.unbind;
  3762. // Don't bind to text nodes or comments
  3763. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  3764. return self;
  3765. }
  3766. // Unbind any element on the specificed target
  3767. if (target[expando]) {
  3768. unbind(target);
  3769. }
  3770. // Target doesn't have getElementsByTagName it's probably a window object then use it's document to find the children
  3771. if (!target.getElementsByTagName) {
  3772. target = target.document;
  3773. }
  3774. // Remove events from each child element
  3775. if (target && target.getElementsByTagName) {
  3776. unbind(target);
  3777. children = target.getElementsByTagName('*');
  3778. i = children.length;
  3779. while (i--) {
  3780. target = children[i];
  3781. if (target[expando]) {
  3782. unbind(target);
  3783. }
  3784. }
  3785. }
  3786. return self;
  3787. };
  3788. self.callNativeHandler = function(id, evt) {
  3789. if (events) {
  3790. events[id][evt.type].nativeHandler(evt);
  3791. }
  3792. };
  3793. self.destory = function() {
  3794. events = {};
  3795. };
  3796. // Legacy function calls
  3797. self.add = function(target, events, func, scope) {
  3798. // Old API supported direct ID assignment
  3799. if (typeof(target) === "string") {
  3800. target = document.getElementById(target);
  3801. }
  3802. // Old API supported multiple targets
  3803. if (target && target instanceof Array) {
  3804. var i = target.length;
  3805. while (i--) {
  3806. self.add(target[i], events, func, scope);
  3807. }
  3808. return;
  3809. }
  3810. // Old API called ready init
  3811. if (events === "init") {
  3812. events = "ready";
  3813. }
  3814. return self.bind(target, events instanceof Array ? events.join(' ') : events, func, scope);
  3815. };
  3816. self.remove = function(target, events, func, scope) {
  3817. if (!target) {
  3818. return self;
  3819. }
  3820. // Old API supported direct ID assignment
  3821. if (typeof(target) === "string") {
  3822. target = document.getElementById(target);
  3823. }
  3824. // Old API supported multiple targets
  3825. if (target instanceof Array) {
  3826. var i = target.length;
  3827. while (i--) {
  3828. self.remove(target[i], events, func, scope);
  3829. }
  3830. return self;
  3831. }
  3832. return self.unbind(target, events instanceof Array ? events.join(' ') : events, func);
  3833. };
  3834. self.clear = function(target) {
  3835. // Old API supported direct ID assignment
  3836. if (typeof(target) === "string") {
  3837. target = document.getElementById(target);
  3838. }
  3839. return self.clean(target);
  3840. };
  3841. self.cancel = function(e) {
  3842. if (e) {
  3843. self.prevent(e);
  3844. self.stop(e);
  3845. }
  3846. return false;
  3847. };
  3848. self.prevent = function(e) {
  3849. if (!e.preventDefault) {
  3850. e = fix(e);
  3851. }
  3852. e.preventDefault();
  3853. return false;
  3854. };
  3855. self.stop = function(e) {
  3856. if (!e.stopPropagation) {
  3857. e = fix(e);
  3858. }
  3859. e.stopPropagation();
  3860. return false;
  3861. };
  3862. }
  3863. namespace.EventUtils = EventUtils;
  3864. namespace.Event = new EventUtils(function(id) {
  3865. return function(evt) {
  3866. tinymce.dom.Event.callNativeHandler(id, evt);
  3867. };
  3868. });
  3869. // Bind ready event when tinymce script is loaded
  3870. namespace.Event.bind(window, 'ready', function() {});
  3871. namespace = 0;
  3872. })(tinymce.dom, 'data-mce-expando'); // Namespace and expando
  3873. tinymce.dom.TreeWalker = function(start_node, root_node) {
  3874. var node = start_node;
  3875. function findSibling(node, start_name, sibling_name, shallow) {
  3876. var sibling, parent;
  3877. if (node) {
  3878. // Walk into nodes if it has a start
  3879. if (!shallow && node[start_name])
  3880. return node[start_name];
  3881. // Return the sibling if it has one
  3882. if (node != root_node) {
  3883. sibling = node[sibling_name];
  3884. if (sibling)
  3885. return sibling;
  3886. // Walk up the parents to look for siblings
  3887. for (parent = node.parentNode; parent && parent != root_node; parent = parent.parentNode) {
  3888. sibling = parent[sibling_name];
  3889. if (sibling)
  3890. return sibling;
  3891. }
  3892. }
  3893. }
  3894. };
  3895. this.current = function() {
  3896. return node;
  3897. };
  3898. this.next = function(shallow) {
  3899. return (node = findSibling(node, 'firstChild', 'nextSibling', shallow));
  3900. };
  3901. this.prev = function(shallow) {
  3902. return (node = findSibling(node, 'lastChild', 'previousSibling', shallow));
  3903. };
  3904. };
  3905. (function(tinymce) {
  3906. // Shorten names
  3907. var each = tinymce.each,
  3908. is = tinymce.is,
  3909. isWebKit = tinymce.isWebKit,
  3910. isIE = tinymce.isIE,
  3911. Entities = tinymce.html.Entities,
  3912. simpleSelectorRe = /^([a-z0-9],?)+$/i,
  3913. whiteSpaceRegExp = /^[ \t\r\n]*$/;
  3914. tinymce.create('tinymce.dom.DOMUtils', {
  3915. doc : null,
  3916. root : null,
  3917. files : null,
  3918. pixelStyles : /^(top|left|bottom|right|width|height|borderWidth)$/,
  3919. props : {
  3920. "for" : "htmlFor",
  3921. "class" : "className",
  3922. className : "className",
  3923. checked : "checked",
  3924. disabled : "disabled",
  3925. maxlength : "maxLength",
  3926. readonly : "readOnly",
  3927. selected : "selected",
  3928. value : "value",
  3929. id : "id",
  3930. name : "name",
  3931. type : "type"
  3932. },
  3933. DOMUtils : function(d, s) {
  3934. var t = this, globalStyle, name, blockElementsMap;
  3935. t.doc = d;
  3936. t.win = window;
  3937. t.files = {};
  3938. t.cssFlicker = false;
  3939. t.counter = 0;
  3940. t.stdMode = !tinymce.isIE || d.documentMode >= 8;
  3941. t.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat" || t.stdMode;
  3942. t.hasOuterHTML = "outerHTML" in d.createElement("a");
  3943. t.settings = s = tinymce.extend({
  3944. keep_values : false,
  3945. hex_colors : 1
  3946. }, s);
  3947. t.schema = s.schema;
  3948. t.styles = new tinymce.html.Styles({
  3949. url_converter : s.url_converter,
  3950. url_converter_scope : s.url_converter_scope
  3951. }, s.schema);
  3952. // Fix IE6SP2 flicker and check it failed for pre SP2
  3953. if (tinymce.isIE6) {
  3954. try {
  3955. d.execCommand('BackgroundImageCache', false, true);
  3956. } catch (e) {
  3957. t.cssFlicker = true;
  3958. }
  3959. }
  3960. t.fixDoc(d);
  3961. t.events = s.ownEvents ? new tinymce.dom.EventUtils(s.proxy) : tinymce.dom.Event;
  3962. tinymce.addUnload(t.destroy, t);
  3963. blockElementsMap = s.schema ? s.schema.getBlockElements() : {};
  3964. t.isBlock = function(node) {
  3965. // This function is called in module pattern style since it might be executed with the wrong this scope
  3966. var type = node.nodeType;
  3967. // If it's a node then check the type and use the nodeName
  3968. if (type)
  3969. return !!(type === 1 && blockElementsMap[node.nodeName]);
  3970. return !!blockElementsMap[node];
  3971. };
  3972. },
  3973. fixDoc: function(doc) {
  3974. var settings = this.settings, name;
  3975. if (isIE && settings.schema) {
  3976. // Add missing HTML 4/5 elements to IE
  3977. ('abbr article aside audio canvas ' +
  3978. 'details figcaption figure footer ' +
  3979. 'header hgroup mark menu meter nav ' +
  3980. 'output progress section summary ' +
  3981. 'time video').replace(/\w+/g, function(name) {
  3982. doc.createElement(name);
  3983. });
  3984. // Create all custom elements
  3985. for (name in settings.schema.getCustomElements()) {
  3986. doc.createElement(name);
  3987. }
  3988. }
  3989. },
  3990. clone: function(node, deep) {
  3991. var self = this, clone, doc;
  3992. // TODO: Add feature detection here in the future
  3993. if (!isIE || node.nodeType !== 1 || deep) {
  3994. return node.cloneNode(deep);
  3995. }
  3996. doc = self.doc;
  3997. // Make a HTML5 safe shallow copy
  3998. if (!deep) {
  3999. clone = doc.createElement(node.nodeName);
  4000. // Copy attribs
  4001. each(self.getAttribs(node), function(attr) {
  4002. self.setAttrib(clone, attr.nodeName, self.getAttrib(node, attr.nodeName));
  4003. });
  4004. return clone;
  4005. }
  4006. /*
  4007. // Setup HTML5 patched document fragment
  4008. if (!self.frag) {
  4009. self.frag = doc.createDocumentFragment();
  4010. self.fixDoc(self.frag);
  4011. }
  4012. // Make a deep copy by adding it to the document fragment then removing it this removed the :section
  4013. clone = doc.createElement('div');
  4014. self.frag.appendChild(clone);
  4015. clone.innerHTML = node.outerHTML;
  4016. self.frag.removeChild(clone);
  4017. */
  4018. return clone.firstChild;
  4019. },
  4020. getRoot : function() {
  4021. var t = this, s = t.settings;
  4022. return (s && t.get(s.root_element)) || t.doc.body;
  4023. },
  4024. getViewPort : function(w) {
  4025. var d, b;
  4026. w = !w ? this.win : w;
  4027. d = w.document;
  4028. b = this.boxModel ? d.documentElement : d.body;
  4029. // Returns viewport size excluding scrollbars
  4030. return {
  4031. x : w.pageXOffset || b.scrollLeft,
  4032. y : w.pageYOffset || b.scrollTop,
  4033. w : w.innerWidth || b.clientWidth,
  4034. h : w.innerHeight || b.clientHeight
  4035. };
  4036. },
  4037. getRect : function(e) {
  4038. var p, t = this, sr;
  4039. e = t.get(e);
  4040. p = t.getPos(e);
  4041. sr = t.getSize(e);
  4042. return {
  4043. x : p.x,
  4044. y : p.y,
  4045. w : sr.w,
  4046. h : sr.h
  4047. };
  4048. },
  4049. getSize : function(e) {
  4050. var t = this, w, h;
  4051. e = t.get(e);
  4052. w = t.getStyle(e, 'width');
  4053. h = t.getStyle(e, 'height');
  4054. // Non pixel value, then force offset/clientWidth
  4055. if (w.indexOf('px') === -1)
  4056. w = 0;
  4057. // Non pixel value, then force offset/clientWidth
  4058. if (h.indexOf('px') === -1)
  4059. h = 0;
  4060. return {
  4061. w : parseInt(w, 10) || e.offsetWidth || e.clientWidth,
  4062. h : parseInt(h, 10) || e.offsetHeight || e.clientHeight
  4063. };
  4064. },
  4065. getParent : function(n, f, r) {
  4066. return this.getParents(n, f, r, false);
  4067. },
  4068. getParents : function(n, f, r, c) {
  4069. var t = this, na, se = t.settings, o = [];
  4070. n = t.get(n);
  4071. c = c === undefined;
  4072. if (se.strict_root)
  4073. r = r || t.getRoot();
  4074. // Wrap node name as func
  4075. if (is(f, 'string')) {
  4076. na = f;
  4077. if (f === '*') {
  4078. f = function(n) {return n.nodeType == 1;};
  4079. } else {
  4080. f = function(n) {
  4081. return t.is(n, na);
  4082. };
  4083. }
  4084. }
  4085. while (n) {
  4086. if (n == r || !n.nodeType || n.nodeType === 9)
  4087. break;
  4088. if (!f || f(n)) {
  4089. if (c)
  4090. o.push(n);
  4091. else
  4092. return n;
  4093. }
  4094. n = n.parentNode;
  4095. }
  4096. return c ? o : null;
  4097. },
  4098. get : function(e) {
  4099. var n;
  4100. if (e && this.doc && typeof(e) == 'string') {
  4101. n = e;
  4102. e = this.doc.getElementById(e);
  4103. // IE and Opera returns meta elements when they match the specified input ID, but getElementsByName seems to do the trick
  4104. if (e && e.id !== n)
  4105. return this.doc.getElementsByName(n)[1];
  4106. }
  4107. return e;
  4108. },
  4109. getNext : function(node, selector) {
  4110. return this._findSib(node, selector, 'nextSibling');
  4111. },
  4112. getPrev : function(node, selector) {
  4113. return this._findSib(node, selector, 'previousSibling');
  4114. },
  4115. select : function(pa, s) {
  4116. var t = this;
  4117. return tinymce.dom.Sizzle(pa, t.get(s) || t.get(t.settings.root_element) || t.doc, []);
  4118. },
  4119. is : function(n, selector) {
  4120. var i;
  4121. // If it isn't an array then try to do some simple selectors instead of Sizzle for to boost performance
  4122. if (n.length === undefined) {
  4123. // Simple all selector
  4124. if (selector === '*')
  4125. return n.nodeType == 1;
  4126. // Simple selector just elements
  4127. if (simpleSelectorRe.test(selector)) {
  4128. selector = selector.toLowerCase().split(/,/);
  4129. n = n.nodeName.toLowerCase();
  4130. for (i = selector.length - 1; i >= 0; i--) {
  4131. if (selector[i] == n)
  4132. return true;
  4133. }
  4134. return false;
  4135. }
  4136. }
  4137. return tinymce.dom.Sizzle.matches(selector, n.nodeType ? [n] : n).length > 0;
  4138. },
  4139. add : function(p, n, a, h, c) {
  4140. var t = this;
  4141. return this.run(p, function(p) {
  4142. var e, k;
  4143. e = is(n, 'string') ? t.doc.createElement(n) : n;
  4144. t.setAttribs(e, a);
  4145. if (h) {
  4146. if (h.nodeType)
  4147. e.appendChild(h);
  4148. else
  4149. t.setHTML(e, h);
  4150. }
  4151. return !c ? p.appendChild(e) : e;
  4152. });
  4153. },
  4154. create : function(n, a, h) {
  4155. return this.add(this.doc.createElement(n), n, a, h, 1);
  4156. },
  4157. createHTML : function(n, a, h) {
  4158. var o = '', t = this, k;
  4159. o += '<' + n;
  4160. for (k in a) {
  4161. if (a.hasOwnProperty(k))
  4162. o += ' ' + k + '="' + t.encode(a[k]) + '"';
  4163. }
  4164. // A call to tinymce.is doesn't work for some odd reason on IE9 possible bug inside their JS runtime
  4165. if (typeof(h) != "undefined")
  4166. return o + '>' + h + '</' + n + '>';
  4167. return o + ' />';
  4168. },
  4169. remove : function(node, keep_children) {
  4170. return this.run(node, function(node) {
  4171. var child, parent = node.parentNode;
  4172. if (!parent)
  4173. return null;
  4174. if (keep_children) {
  4175. while (child = node.firstChild) {
  4176. // IE 8 will crash if you don't remove completely empty text nodes
  4177. if (!tinymce.isIE || child.nodeType !== 3 || child.nodeValue)
  4178. parent.insertBefore(child, node);
  4179. else
  4180. node.removeChild(child);
  4181. }
  4182. }
  4183. return parent.removeChild(node);
  4184. });
  4185. },
  4186. setStyle : function(n, na, v) {
  4187. var t = this;
  4188. return t.run(n, function(e) {
  4189. var s, i;
  4190. s = e.style;
  4191. // Camelcase it, if needed
  4192. na = na.replace(/-(\D)/g, function(a, b){
  4193. return b.toUpperCase();
  4194. });
  4195. // Default px suffix on these
  4196. if (t.pixelStyles.test(na) && (tinymce.is(v, 'number') || /^[\-0-9\.]+$/.test(v)))
  4197. v += 'px';
  4198. switch (na) {
  4199. case 'opacity':
  4200. // IE specific opacity
  4201. if (isIE) {
  4202. s.filter = v === '' ? '' : "alpha(opacity=" + (v * 100) + ")";
  4203. if (!n.currentStyle || !n.currentStyle.hasLayout)
  4204. s.display = 'inline-block';
  4205. }
  4206. // Fix for older browsers
  4207. s[na] = s['-moz-opacity'] = s['-khtml-opacity'] = v || '';
  4208. break;
  4209. case 'float':
  4210. isIE ? s.styleFloat = v : s.cssFloat = v;
  4211. break;
  4212. default:
  4213. s[na] = v || '';
  4214. }
  4215. // Force update of the style data
  4216. if (t.settings.update_styles)
  4217. t.setAttrib(e, 'data-mce-style');
  4218. });
  4219. },
  4220. getStyle : function(n, na, c) {
  4221. n = this.get(n);
  4222. if (!n)
  4223. return;
  4224. // Gecko
  4225. if (this.doc.defaultView && c) {
  4226. // Remove camelcase
  4227. na = na.replace(/[A-Z]/g, function(a){
  4228. return '-' + a;
  4229. });
  4230. try {
  4231. return this.doc.defaultView.getComputedStyle(n, null).getPropertyValue(na);
  4232. } catch (ex) {
  4233. // Old safari might fail
  4234. return null;
  4235. }
  4236. }
  4237. // Camelcase it, if needed
  4238. na = na.replace(/-(\D)/g, function(a, b){
  4239. return b.toUpperCase();
  4240. });
  4241. if (na == 'float')
  4242. na = isIE ? 'styleFloat' : 'cssFloat';
  4243. // IE & Opera
  4244. if (n.currentStyle && c)
  4245. return n.currentStyle[na];
  4246. return n.style ? n.style[na] : undefined;
  4247. },
  4248. setStyles : function(e, o) {
  4249. var t = this, s = t.settings, ol;
  4250. ol = s.update_styles;
  4251. s.update_styles = 0;
  4252. each(o, function(v, n) {
  4253. t.setStyle(e, n, v);
  4254. });
  4255. // Update style info
  4256. s.update_styles = ol;
  4257. if (s.update_styles)
  4258. t.setAttrib(e, s.cssText);
  4259. },
  4260. removeAllAttribs: function(e) {
  4261. return this.run(e, function(e) {
  4262. var i, attrs = e.attributes;
  4263. for (i = attrs.length - 1; i >= 0; i--) {
  4264. e.removeAttributeNode(attrs.item(i));
  4265. }
  4266. });
  4267. },
  4268. setAttrib : function(e, n, v) {
  4269. var t = this;
  4270. // Whats the point
  4271. if (!e || !n)
  4272. return;
  4273. // Strict XML mode
  4274. if (t.settings.strict)
  4275. n = n.toLowerCase();
  4276. return this.run(e, function(e) {
  4277. var s = t.settings;
  4278. var originalValue = e.getAttribute(n);
  4279. if (v !== null) {
  4280. switch (n) {
  4281. case "style":
  4282. if (!is(v, 'string')) {
  4283. each(v, function(v, n) {
  4284. t.setStyle(e, n, v);
  4285. });
  4286. return;
  4287. }
  4288. // No mce_style for elements with these since they might get resized by the user
  4289. if (s.keep_values) {
  4290. if (v && !t._isRes(v))
  4291. e.setAttribute('data-mce-style', v, 2);
  4292. else
  4293. e.removeAttribute('data-mce-style', 2);
  4294. }
  4295. e.style.cssText = v;
  4296. break;
  4297. case "class":
  4298. e.className = v || ''; // Fix IE null bug
  4299. break;
  4300. case "src":
  4301. case "href":
  4302. if (s.keep_values) {
  4303. if (s.url_converter)
  4304. v = s.url_converter.call(s.url_converter_scope || t, v, n, e);
  4305. t.setAttrib(e, 'data-mce-' + n, v, 2);
  4306. }
  4307. break;
  4308. case "shape":
  4309. e.setAttribute('data-mce-style', v);
  4310. break;
  4311. }
  4312. }
  4313. if (is(v) && v !== null && v.length !== 0)
  4314. e.setAttribute(n, '' + v, 2);
  4315. else
  4316. e.removeAttribute(n, 2);
  4317. // fire onChangeAttrib event for attributes that have changed
  4318. if (tinyMCE.activeEditor && originalValue != v) {
  4319. var ed = tinyMCE.activeEditor;
  4320. ed.onSetAttrib.dispatch(ed, e, n, v);
  4321. }
  4322. });
  4323. },
  4324. setAttribs : function(e, o) {
  4325. var t = this;
  4326. return this.run(e, function(e) {
  4327. each(o, function(v, n) {
  4328. t.setAttrib(e, n, v);
  4329. });
  4330. });
  4331. },
  4332. getAttrib : function(e, n, dv) {
  4333. var v, t = this, undef;
  4334. e = t.get(e);
  4335. if (!e || e.nodeType !== 1)
  4336. return dv === undef ? false : dv;
  4337. if (!is(dv))
  4338. dv = '';
  4339. // Try the mce variant for these
  4340. if (/^(src|href|style|coords|shape)$/.test(n)) {
  4341. v = e.getAttribute("data-mce-" + n);
  4342. if (v)
  4343. return v;
  4344. }
  4345. if (isIE && t.props[n]) {
  4346. v = e[t.props[n]];
  4347. v = v && v.nodeValue ? v.nodeValue : v;
  4348. }
  4349. if (!v)
  4350. v = e.getAttribute(n, 2);
  4351. // Check boolean attribs
  4352. if (/^(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)$/.test(n)) {
  4353. if (e[t.props[n]] === true && v === '')
  4354. return n;
  4355. return v ? n : '';
  4356. }
  4357. // Inner input elements will override attributes on form elements
  4358. if (e.nodeName === "FORM" && e.getAttributeNode(n))
  4359. return e.getAttributeNode(n).nodeValue;
  4360. if (n === 'style') {
  4361. v = v || e.style.cssText;
  4362. if (v) {
  4363. v = t.serializeStyle(t.parseStyle(v), e.nodeName);
  4364. if (t.settings.keep_values && !t._isRes(v))
  4365. e.setAttribute('data-mce-style', v);
  4366. }
  4367. }
  4368. // Remove Apple and WebKit stuff
  4369. if (isWebKit && n === "class" && v)
  4370. v = v.replace(/(apple|webkit)\-[a-z\-]+/gi, '');
  4371. // Handle IE issues
  4372. if (isIE) {
  4373. switch (n) {
  4374. case 'rowspan':
  4375. case 'colspan':
  4376. // IE returns 1 as default value
  4377. if (v === 1)
  4378. v = '';
  4379. break;
  4380. case 'size':
  4381. // IE returns +0 as default value for size
  4382. if (v === '+0' || v === 20 || v === 0)
  4383. v = '';
  4384. break;
  4385. case 'width':
  4386. case 'height':
  4387. case 'vspace':
  4388. case 'checked':
  4389. case 'disabled':
  4390. case 'readonly':
  4391. if (v === 0)
  4392. v = '';
  4393. break;
  4394. case 'hspace':
  4395. // IE returns -1 as default value
  4396. if (v === -1)
  4397. v = '';
  4398. break;
  4399. case 'maxlength':
  4400. case 'tabindex':
  4401. // IE returns default value
  4402. if (v === 32768 || v === 2147483647 || v === '32768')
  4403. v = '';
  4404. break;
  4405. case 'multiple':
  4406. case 'compact':
  4407. case 'noshade':
  4408. case 'nowrap':
  4409. if (v === 65535)
  4410. return n;
  4411. return dv;
  4412. case 'shape':
  4413. v = v.toLowerCase();
  4414. break;
  4415. default:
  4416. // IE has odd anonymous function for event attributes
  4417. if (n.indexOf('on') === 0 && v)
  4418. v = tinymce._replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1', '' + v);
  4419. }
  4420. }
  4421. return (v !== undef && v !== null && v !== '') ? '' + v : dv;
  4422. },
  4423. getPos : function(n, ro) {
  4424. var t = this, x = 0, y = 0, e, d = t.doc, r;
  4425. n = t.get(n);
  4426. ro = ro || d.body;
  4427. if (n) {
  4428. // Use getBoundingClientRect if it exists since it's faster than looping offset nodes
  4429. if (n.getBoundingClientRect) {
  4430. n = n.getBoundingClientRect();
  4431. e = t.boxModel ? d.documentElement : d.body;
  4432. // Add scroll offsets from documentElement or body since IE with the wrong box model will use d.body and so do WebKit
  4433. // Also remove the body/documentelement clientTop/clientLeft on IE 6, 7 since they offset the position
  4434. x = n.left + (d.documentElement.scrollLeft || d.body.scrollLeft) - e.clientTop;
  4435. y = n.top + (d.documentElement.scrollTop || d.body.scrollTop) - e.clientLeft;
  4436. return {x : x, y : y};
  4437. }
  4438. r = n;
  4439. while (r && r != ro && r.nodeType) {
  4440. x += r.offsetLeft || 0;
  4441. y += r.offsetTop || 0;
  4442. r = r.offsetParent;
  4443. }
  4444. r = n.parentNode;
  4445. while (r && r != ro && r.nodeType) {
  4446. x -= r.scrollLeft || 0;
  4447. y -= r.scrollTop || 0;
  4448. r = r.parentNode;
  4449. }
  4450. }
  4451. return {x : x, y : y};
  4452. },
  4453. parseStyle : function(st) {
  4454. return this.styles.parse(st);
  4455. },
  4456. serializeStyle : function(o, name) {
  4457. return this.styles.serialize(o, name);
  4458. },
  4459. addStyle: function(cssText) {
  4460. var doc = this.doc, head;
  4461. // Create style element if needed
  4462. styleElm = doc.getElementById('mceDefaultStyles');
  4463. if (!styleElm) {
  4464. styleElm = doc.createElement('style'),
  4465. styleElm.id = 'mceDefaultStyles';
  4466. styleElm.type = 'text/css';
  4467. head = doc.getElementsByTagName('head')[0]
  4468. if (head.firstChild) {
  4469. head.insertBefore(styleElm, head.firstChild);
  4470. } else {
  4471. head.appendChild(styleElm);
  4472. }
  4473. }
  4474. // Append style data to old or new style element
  4475. if (styleElm.styleSheet) {
  4476. styleElm.styleSheet.cssText += cssText;
  4477. } else {
  4478. styleElm.appendChild(doc.createTextNode(cssText));
  4479. }
  4480. },
  4481. loadCSS : function(u) {
  4482. var t = this, d = t.doc, head;
  4483. if (!u)
  4484. u = '';
  4485. head = d.getElementsByTagName('head')[0];
  4486. each(u.split(','), function(u) {
  4487. var link;
  4488. if (t.files[u])
  4489. return;
  4490. t.files[u] = true;
  4491. link = t.create('link', {rel : 'stylesheet', href : tinymce._addVer(u)});
  4492. // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug
  4493. // This fix seems to resolve that issue by realcing the document ones a stylesheet finishes loading
  4494. // It's ugly but it seems to work fine.
  4495. if (isIE && d.documentMode && d.recalc) {
  4496. link.onload = function() {
  4497. if (d.recalc)
  4498. d.recalc();
  4499. link.onload = null;
  4500. };
  4501. }
  4502. head.appendChild(link);
  4503. });
  4504. },
  4505. addClass : function(e, c) {
  4506. return this.run(e, function(e) {
  4507. var o;
  4508. if (!c)
  4509. return 0;
  4510. if (this.hasClass(e, c))
  4511. return e.className;
  4512. o = this.removeClass(e, c);
  4513. return e.className = (o != '' ? (o + ' ') : '') + c;
  4514. });
  4515. },
  4516. removeClass : function(e, c) {
  4517. var t = this, re;
  4518. return t.run(e, function(e) {
  4519. var v;
  4520. if (t.hasClass(e, c)) {
  4521. if (!re)
  4522. re = new RegExp("(^|\\s+)" + c + "(\\s+|$)", "g");
  4523. v = e.className.replace(re, ' ');
  4524. v = tinymce.trim(v != ' ' ? v : '');
  4525. e.className = v;
  4526. // Empty class attr
  4527. if (!v) {
  4528. e.removeAttribute('class');
  4529. e.removeAttribute('className');
  4530. }
  4531. return v;
  4532. }
  4533. return e.className;
  4534. });
  4535. },
  4536. hasClass : function(n, c) {
  4537. n = this.get(n);
  4538. if (!n || !c)
  4539. return false;
  4540. return (' ' + n.className + ' ').indexOf(' ' + c + ' ') !== -1;
  4541. },
  4542. show : function(e) {
  4543. return this.setStyle(e, 'display', 'block');
  4544. },
  4545. hide : function(e) {
  4546. return this.setStyle(e, 'display', 'none');
  4547. },
  4548. isHidden : function(e) {
  4549. e = this.get(e);
  4550. return !e || e.style.display == 'none' || this.getStyle(e, 'display') == 'none';
  4551. },
  4552. uniqueId : function(p) {
  4553. return (!p ? 'mce_' : p) + (this.counter++);
  4554. },
  4555. setHTML : function(element, html) {
  4556. var self = this;
  4557. return self.run(element, function(element) {
  4558. if (isIE) {
  4559. // Remove all child nodes, IE keeps empty text nodes in DOM
  4560. while (element.firstChild)
  4561. element.removeChild(element.firstChild);
  4562. try {
  4563. // IE will remove comments from the beginning
  4564. // unless you padd the contents with something
  4565. element.innerHTML = '<br />' + html;
  4566. element.removeChild(element.firstChild);
  4567. } catch (ex) {
  4568. // 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
  4569. // This seems to fix this problem
  4570. // Create new div with HTML contents and a BR infront to keep comments
  4571. var newElement = self.create('div');
  4572. newElement.innerHTML = '<br />' + html;
  4573. // Add all children from div to target
  4574. each (tinymce.grep(newElement.childNodes), function(node, i) {
  4575. // Skip br element
  4576. if (i && element.canHaveHTML)
  4577. element.appendChild(node);
  4578. });
  4579. }
  4580. } else
  4581. element.innerHTML = html;
  4582. return html;
  4583. });
  4584. },
  4585. getOuterHTML : function(elm) {
  4586. var doc, self = this;
  4587. elm = self.get(elm);
  4588. if (!elm)
  4589. return null;
  4590. if (elm.nodeType === 1 && self.hasOuterHTML)
  4591. return elm.outerHTML;
  4592. doc = (elm.ownerDocument || self.doc).createElement("body");
  4593. doc.appendChild(elm.cloneNode(true));
  4594. return doc.innerHTML;
  4595. },
  4596. setOuterHTML : function(e, h, d) {
  4597. var t = this;
  4598. function setHTML(e, h, d) {
  4599. var n, tp;
  4600. tp = d.createElement("body");
  4601. tp.innerHTML = h;
  4602. n = tp.lastChild;
  4603. while (n) {
  4604. t.insertAfter(n.cloneNode(true), e);
  4605. n = n.previousSibling;
  4606. }
  4607. t.remove(e);
  4608. };
  4609. return this.run(e, function(e) {
  4610. e = t.get(e);
  4611. // Only set HTML on elements
  4612. if (e.nodeType == 1) {
  4613. d = d || e.ownerDocument || t.doc;
  4614. if (isIE) {
  4615. try {
  4616. // Try outerHTML for IE it sometimes produces an unknown runtime error
  4617. if (isIE && e.nodeType == 1)
  4618. e.outerHTML = h;
  4619. else
  4620. setHTML(e, h, d);
  4621. } catch (ex) {
  4622. // Fix for unknown runtime error
  4623. setHTML(e, h, d);
  4624. }
  4625. } else
  4626. setHTML(e, h, d);
  4627. }
  4628. });
  4629. },
  4630. decode : Entities.decode,
  4631. encode : Entities.encodeAllRaw,
  4632. insertAfter : function(node, reference_node) {
  4633. reference_node = this.get(reference_node);
  4634. return this.run(node, function(node) {
  4635. var parent, nextSibling;
  4636. parent = reference_node.parentNode;
  4637. nextSibling = reference_node.nextSibling;
  4638. if (nextSibling)
  4639. parent.insertBefore(node, nextSibling);
  4640. else
  4641. parent.appendChild(node);
  4642. return node;
  4643. });
  4644. },
  4645. replace : function(n, o, k) {
  4646. var t = this;
  4647. if (is(o, 'array'))
  4648. n = n.cloneNode(true);
  4649. return t.run(o, function(o) {
  4650. if (k) {
  4651. each(tinymce.grep(o.childNodes), function(c) {
  4652. n.appendChild(c);
  4653. });
  4654. }
  4655. return o.parentNode.replaceChild(n, o);
  4656. });
  4657. },
  4658. rename : function(elm, name) {
  4659. var t = this, newElm;
  4660. if (elm.nodeName != name.toUpperCase()) {
  4661. // Rename block element
  4662. newElm = t.create(name);
  4663. // Copy attribs to new block
  4664. each(t.getAttribs(elm), function(attr_node) {
  4665. t.setAttrib(newElm, attr_node.nodeName, t.getAttrib(elm, attr_node.nodeName));
  4666. });
  4667. // Replace block
  4668. t.replace(newElm, elm, 1);
  4669. }
  4670. return newElm || elm;
  4671. },
  4672. findCommonAncestor : function(a, b) {
  4673. var ps = a, pe;
  4674. while (ps) {
  4675. pe = b;
  4676. while (pe && ps != pe)
  4677. pe = pe.parentNode;
  4678. if (ps == pe)
  4679. break;
  4680. ps = ps.parentNode;
  4681. }
  4682. if (!ps && a.ownerDocument)
  4683. return a.ownerDocument.documentElement;
  4684. return ps;
  4685. },
  4686. toHex : function(s) {
  4687. var c = /^\s*rgb\s*?\(\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?\)\s*$/i.exec(s);
  4688. function hex(s) {
  4689. s = parseInt(s, 10).toString(16);
  4690. return s.length > 1 ? s : '0' + s; // 0 -> 00
  4691. };
  4692. if (c) {
  4693. s = '#' + hex(c[1]) + hex(c[2]) + hex(c[3]);
  4694. return s;
  4695. }
  4696. return s;
  4697. },
  4698. getClasses : function() {
  4699. var t = this, cl = [], i, lo = {}, f = t.settings.class_filter, ov;
  4700. if (t.classes)
  4701. return t.classes;
  4702. function addClasses(s) {
  4703. // IE style imports
  4704. each(s.imports, function(r) {
  4705. addClasses(r);
  4706. });
  4707. each(s.cssRules || s.rules, function(r) {
  4708. // Real type or fake it on IE
  4709. switch (r.type || 1) {
  4710. // Rule
  4711. case 1:
  4712. if (r.selectorText) {
  4713. each(r.selectorText.split(','), function(v) {
  4714. v = v.replace(/^\s*|\s*$|^\s\./g, "");
  4715. // Is internal or it doesn't contain a class
  4716. if (/\.mce/.test(v) || !/\.[\w\-]+$/.test(v))
  4717. return;
  4718. // Remove everything but class name
  4719. ov = v;
  4720. v = tinymce._replace(/.*\.([a-z0-9_\-]+).*/i, '$1', v);
  4721. // Filter classes
  4722. if (f && !(v = f(v, ov)))
  4723. return;
  4724. if (!lo[v]) {
  4725. cl.push({'class' : v});
  4726. lo[v] = 1;
  4727. }
  4728. });
  4729. }
  4730. break;
  4731. // Import
  4732. case 3:
  4733. addClasses(r.styleSheet);
  4734. break;
  4735. }
  4736. });
  4737. };
  4738. try {
  4739. each(t.doc.styleSheets, addClasses);
  4740. } catch (ex) {
  4741. // Ignore
  4742. }
  4743. if (cl.length > 0)
  4744. t.classes = cl;
  4745. return cl;
  4746. },
  4747. run : function(e, f, s) {
  4748. var t = this, o;
  4749. if (t.doc && typeof(e) === 'string')
  4750. e = t.get(e);
  4751. if (!e)
  4752. return false;
  4753. s = s || this;
  4754. if (!e.nodeType && (e.length || e.length === 0)) {
  4755. o = [];
  4756. each(e, function(e, i) {
  4757. if (e) {
  4758. if (typeof(e) == 'string')
  4759. e = t.doc.getElementById(e);
  4760. o.push(f.call(s, e, i));
  4761. }
  4762. });
  4763. return o;
  4764. }
  4765. return f.call(s, e);
  4766. },
  4767. getAttribs : function(n) {
  4768. var o;
  4769. n = this.get(n);
  4770. if (!n)
  4771. return [];
  4772. if (isIE) {
  4773. o = [];
  4774. // Object will throw exception in IE
  4775. if (n.nodeName == 'OBJECT')
  4776. return n.attributes;
  4777. // IE doesn't keep the selected attribute if you clone option elements
  4778. if (n.nodeName === 'OPTION' && this.getAttrib(n, 'selected'))
  4779. o.push({specified : 1, nodeName : 'selected'});
  4780. // It's crazy that this is faster in IE but it's because it returns all attributes all the time
  4781. n.cloneNode(false).outerHTML.replace(/<\/?[\w:\-]+ ?|=[\"][^\"]+\"|=\'[^\']+\'|=[\w\-]+|>/gi, '').replace(/[\w:\-]+/gi, function(a) {
  4782. o.push({specified : 1, nodeName : a});
  4783. });
  4784. return o;
  4785. }
  4786. return n.attributes;
  4787. },
  4788. isEmpty : function(node, elements) {
  4789. var self = this, i, attributes, type, walker, name, brCount = 0;
  4790. node = node.firstChild;
  4791. if (node) {
  4792. walker = new tinymce.dom.TreeWalker(node, node.parentNode);
  4793. elements = elements || self.schema ? self.schema.getNonEmptyElements() : null;
  4794. do {
  4795. type = node.nodeType;
  4796. if (type === 1) {
  4797. // Ignore bogus elements
  4798. if (node.getAttribute('data-mce-bogus'))
  4799. continue;
  4800. // Keep empty elements like <img />
  4801. name = node.nodeName.toLowerCase();
  4802. if (elements && elements[name]) {
  4803. // Ignore single BR elements in blocks like <p><br /></p> or <p><span><br /></span></p>
  4804. if (name === 'br') {
  4805. brCount++;
  4806. continue;
  4807. }
  4808. return false;
  4809. }
  4810. // Keep elements with data-bookmark attributes or name attribute like <a name="1"></a>
  4811. attributes = self.getAttribs(node);
  4812. i = node.attributes.length;
  4813. while (i--) {
  4814. name = node.attributes[i].nodeName;
  4815. if (name === "name" || name === 'data-mce-bookmark')
  4816. return false;
  4817. }
  4818. }
  4819. // Keep comment nodes
  4820. if (type == 8)
  4821. return false;
  4822. // Keep non whitespace text nodes
  4823. if ((type === 3 && !whiteSpaceRegExp.test(node.nodeValue)))
  4824. return false;
  4825. } while (node = walker.next());
  4826. }
  4827. return brCount <= 1;
  4828. },
  4829. destroy : function(s) {
  4830. var t = this;
  4831. t.win = t.doc = t.root = t.events = t.frag = null;
  4832. // Manual destroy then remove unload handler
  4833. if (!s)
  4834. tinymce.removeUnload(t.destroy);
  4835. },
  4836. createRng : function() {
  4837. var d = this.doc;
  4838. return d.createRange ? d.createRange() : new tinymce.dom.Range(this);
  4839. },
  4840. nodeIndex : function(node, normalized) {
  4841. var idx = 0, lastNodeType, lastNode, nodeType;
  4842. if (node) {
  4843. for (lastNodeType = node.nodeType, node = node.previousSibling, lastNode = node; node; node = node.previousSibling) {
  4844. nodeType = node.nodeType;
  4845. // Normalize text nodes
  4846. if (normalized && nodeType == 3) {
  4847. if (nodeType == lastNodeType || !node.nodeValue.length)
  4848. continue;
  4849. }
  4850. idx++;
  4851. lastNodeType = nodeType;
  4852. }
  4853. }
  4854. return idx;
  4855. },
  4856. split : function(pe, e, re) {
  4857. var t = this, r = t.createRng(), bef, aft, pa;
  4858. // W3C valid browsers tend to leave empty nodes to the left/right side of the contents, this makes sense
  4859. // but we don't want that in our code since it serves no purpose for the end user
  4860. // For example if this is chopped:
  4861. // <p>text 1<span><b>CHOP</b></span>text 2</p>
  4862. // would produce:
  4863. // <p>text 1<span></span></p><b>CHOP</b><p><span></span>text 2</p>
  4864. // this function will then trim of empty edges and produce:
  4865. // <p>text 1</p><b>CHOP</b><p>text 2</p>
  4866. function trim(node) {
  4867. var i, children = node.childNodes, type = node.nodeType;
  4868. function surroundedBySpans(node) {
  4869. var previousIsSpan = node.previousSibling && node.previousSibling.nodeName == 'SPAN';
  4870. var nextIsSpan = node.nextSibling && node.nextSibling.nodeName == 'SPAN';
  4871. return previousIsSpan && nextIsSpan;
  4872. }
  4873. if (type == 1 && node.getAttribute('data-mce-type') == 'bookmark')
  4874. return;
  4875. for (i = children.length - 1; i >= 0; i--)
  4876. trim(children[i]);
  4877. if (type != 9) {
  4878. // Keep non whitespace text nodes
  4879. if (type == 3 && node.nodeValue.length > 0) {
  4880. // If parent element isn't a block or there isn't any useful contents for example "<p> </p>"
  4881. // Also keep text nodes with only spaces if surrounded by spans.
  4882. // eg. "<p><span>a</span> <span>b</span></p>" should keep space between a and b
  4883. var trimmedLength = tinymce.trim(node.nodeValue).length;
  4884. if (!t.isBlock(node.parentNode) || trimmedLength > 0 || trimmedLength === 0 && surroundedBySpans(node))
  4885. return;
  4886. } else if (type == 1) {
  4887. // If the only child is a bookmark then move it up
  4888. children = node.childNodes;
  4889. if (children.length == 1 && children[0] && children[0].nodeType == 1 && children[0].getAttribute('data-mce-type') == 'bookmark')
  4890. node.parentNode.insertBefore(children[0], node);
  4891. // Keep non empty elements or img, hr etc
  4892. if (children.length || /^(br|hr|input|img)$/i.test(node.nodeName))
  4893. return;
  4894. }
  4895. t.remove(node);
  4896. }
  4897. return node;
  4898. };
  4899. if (pe && e) {
  4900. // Get before chunk
  4901. r.setStart(pe.parentNode, t.nodeIndex(pe));
  4902. r.setEnd(e.parentNode, t.nodeIndex(e));
  4903. bef = r.extractContents();
  4904. // Get after chunk
  4905. r = t.createRng();
  4906. r.setStart(e.parentNode, t.nodeIndex(e) + 1);
  4907. r.setEnd(pe.parentNode, t.nodeIndex(pe) + 1);
  4908. aft = r.extractContents();
  4909. // Insert before chunk
  4910. pa = pe.parentNode;
  4911. pa.insertBefore(trim(bef), pe);
  4912. // Insert middle chunk
  4913. if (re)
  4914. pa.replaceChild(re, e);
  4915. else
  4916. pa.insertBefore(e, pe);
  4917. // Insert after chunk
  4918. pa.insertBefore(trim(aft), pe);
  4919. t.remove(pe);
  4920. return re || e;
  4921. }
  4922. },
  4923. bind : function(target, name, func, scope) {
  4924. return this.events.add(target, name, func, scope || this);
  4925. },
  4926. unbind : function(target, name, func) {
  4927. return this.events.remove(target, name, func);
  4928. },
  4929. fire : function(target, name, evt) {
  4930. return this.events.fire(target, name, evt);
  4931. },
  4932. // Returns the content editable state of a node
  4933. getContentEditable: function(node) {
  4934. var contentEditable;
  4935. // Check type
  4936. if (node.nodeType != 1) {
  4937. return null;
  4938. }
  4939. // Check for fake content editable
  4940. contentEditable = node.getAttribute("data-mce-contenteditable");
  4941. if (contentEditable && contentEditable !== "inherit") {
  4942. return contentEditable;
  4943. }
  4944. // Check for real content editable
  4945. return node.contentEditable !== "inherit" ? node.contentEditable : null;
  4946. },
  4947. _findSib : function(node, selector, name) {
  4948. var t = this, f = selector;
  4949. if (node) {
  4950. // If expression make a function of it using is
  4951. if (is(f, 'string')) {
  4952. f = function(node) {
  4953. return t.is(node, selector);
  4954. };
  4955. }
  4956. // Loop all siblings
  4957. for (node = node[name]; node; node = node[name]) {
  4958. if (f(node))
  4959. return node;
  4960. }
  4961. }
  4962. return null;
  4963. },
  4964. _isRes : function(c) {
  4965. // Is live resizble element
  4966. return /^(top|left|bottom|right|width|height)/i.test(c) || /;\s*(top|left|bottom|right|width|height)/i.test(c);
  4967. }
  4968. /*
  4969. walk : function(n, f, s) {
  4970. var d = this.doc, w;
  4971. if (d.createTreeWalker) {
  4972. w = d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false);
  4973. while ((n = w.nextNode()) != null)
  4974. f.call(s || this, n);
  4975. } else
  4976. tinymce.walk(n, f, 'childNodes', s);
  4977. }
  4978. */
  4979. /*
  4980. toRGB : function(s) {
  4981. var c = /^\s*?#([0-9A-F]{2})([0-9A-F]{1,2})([0-9A-F]{2})?\s*?$/.exec(s);
  4982. if (c) {
  4983. // #FFF -> #FFFFFF
  4984. if (!is(c[3]))
  4985. c[3] = c[2] = c[1];
  4986. return "rgb(" + parseInt(c[1], 16) + "," + parseInt(c[2], 16) + "," + parseInt(c[3], 16) + ")";
  4987. }
  4988. return s;
  4989. }
  4990. */
  4991. });
  4992. tinymce.DOM = new tinymce.dom.DOMUtils(document, {process_html : 0});
  4993. })(tinymce);
  4994. (function(ns) {
  4995. // Range constructor
  4996. function Range(dom) {
  4997. var t = this,
  4998. doc = dom.doc,
  4999. EXTRACT = 0,
  5000. CLONE = 1,
  5001. DELETE = 2,
  5002. TRUE = true,
  5003. FALSE = false,
  5004. START_OFFSET = 'startOffset',
  5005. START_CONTAINER = 'startContainer',
  5006. END_CONTAINER = 'endContainer',
  5007. END_OFFSET = 'endOffset',
  5008. extend = tinymce.extend,
  5009. nodeIndex = dom.nodeIndex;
  5010. extend(t, {
  5011. // Inital states
  5012. startContainer : doc,
  5013. startOffset : 0,
  5014. endContainer : doc,
  5015. endOffset : 0,
  5016. collapsed : TRUE,
  5017. commonAncestorContainer : doc,
  5018. // Range constants
  5019. START_TO_START : 0,
  5020. START_TO_END : 1,
  5021. END_TO_END : 2,
  5022. END_TO_START : 3,
  5023. // Public methods
  5024. setStart : setStart,
  5025. setEnd : setEnd,
  5026. setStartBefore : setStartBefore,
  5027. setStartAfter : setStartAfter,
  5028. setEndBefore : setEndBefore,
  5029. setEndAfter : setEndAfter,
  5030. collapse : collapse,
  5031. selectNode : selectNode,
  5032. selectNodeContents : selectNodeContents,
  5033. compareBoundaryPoints : compareBoundaryPoints,
  5034. deleteContents : deleteContents,
  5035. extractContents : extractContents,
  5036. cloneContents : cloneContents,
  5037. insertNode : insertNode,
  5038. surroundContents : surroundContents,
  5039. cloneRange : cloneRange,
  5040. toStringIE : toStringIE
  5041. });
  5042. function createDocumentFragment() {
  5043. return doc.createDocumentFragment();
  5044. };
  5045. function setStart(n, o) {
  5046. _setEndPoint(TRUE, n, o);
  5047. };
  5048. function setEnd(n, o) {
  5049. _setEndPoint(FALSE, n, o);
  5050. };
  5051. function setStartBefore(n) {
  5052. setStart(n.parentNode, nodeIndex(n));
  5053. };
  5054. function setStartAfter(n) {
  5055. setStart(n.parentNode, nodeIndex(n) + 1);
  5056. };
  5057. function setEndBefore(n) {
  5058. setEnd(n.parentNode, nodeIndex(n));
  5059. };
  5060. function setEndAfter(n) {
  5061. setEnd(n.parentNode, nodeIndex(n) + 1);
  5062. };
  5063. function collapse(ts) {
  5064. if (ts) {
  5065. t[END_CONTAINER] = t[START_CONTAINER];
  5066. t[END_OFFSET] = t[START_OFFSET];
  5067. } else {
  5068. t[START_CONTAINER] = t[END_CONTAINER];
  5069. t[START_OFFSET] = t[END_OFFSET];
  5070. }
  5071. t.collapsed = TRUE;
  5072. };
  5073. function selectNode(n) {
  5074. setStartBefore(n);
  5075. setEndAfter(n);
  5076. };
  5077. function selectNodeContents(n) {
  5078. setStart(n, 0);
  5079. setEnd(n, n.nodeType === 1 ? n.childNodes.length : n.nodeValue.length);
  5080. };
  5081. function compareBoundaryPoints(h, r) {
  5082. var sc = t[START_CONTAINER], so = t[START_OFFSET], ec = t[END_CONTAINER], eo = t[END_OFFSET],
  5083. rsc = r.startContainer, rso = r.startOffset, rec = r.endContainer, reo = r.endOffset;
  5084. // Check START_TO_START
  5085. if (h === 0)
  5086. return _compareBoundaryPoints(sc, so, rsc, rso);
  5087. // Check START_TO_END
  5088. if (h === 1)
  5089. return _compareBoundaryPoints(ec, eo, rsc, rso);
  5090. // Check END_TO_END
  5091. if (h === 2)
  5092. return _compareBoundaryPoints(ec, eo, rec, reo);
  5093. // Check END_TO_START
  5094. if (h === 3)
  5095. return _compareBoundaryPoints(sc, so, rec, reo);
  5096. };
  5097. function deleteContents() {
  5098. _traverse(DELETE);
  5099. };
  5100. function extractContents() {
  5101. return _traverse(EXTRACT);
  5102. };
  5103. function cloneContents() {
  5104. return _traverse(CLONE);
  5105. };
  5106. function insertNode(n) {
  5107. var startContainer = this[START_CONTAINER],
  5108. startOffset = this[START_OFFSET], nn, o;
  5109. // Node is TEXT_NODE or CDATA
  5110. if ((startContainer.nodeType === 3 || startContainer.nodeType === 4) && startContainer.nodeValue) {
  5111. if (!startOffset) {
  5112. // At the start of text
  5113. startContainer.parentNode.insertBefore(n, startContainer);
  5114. } else if (startOffset >= startContainer.nodeValue.length) {
  5115. // At the end of text
  5116. dom.insertAfter(n, startContainer);
  5117. } else {
  5118. // Middle, need to split
  5119. nn = startContainer.splitText(startOffset);
  5120. startContainer.parentNode.insertBefore(n, nn);
  5121. }
  5122. } else {
  5123. // Insert element node
  5124. if (startContainer.childNodes.length > 0)
  5125. o = startContainer.childNodes[startOffset];
  5126. if (o)
  5127. startContainer.insertBefore(n, o);
  5128. else
  5129. startContainer.appendChild(n);
  5130. }
  5131. };
  5132. function surroundContents(n) {
  5133. var f = t.extractContents();
  5134. t.insertNode(n);
  5135. n.appendChild(f);
  5136. t.selectNode(n);
  5137. };
  5138. function cloneRange() {
  5139. return extend(new Range(dom), {
  5140. startContainer : t[START_CONTAINER],
  5141. startOffset : t[START_OFFSET],
  5142. endContainer : t[END_CONTAINER],
  5143. endOffset : t[END_OFFSET],
  5144. collapsed : t.collapsed,
  5145. commonAncestorContainer : t.commonAncestorContainer
  5146. });
  5147. };
  5148. // Private methods
  5149. function _getSelectedNode(container, offset) {
  5150. var child;
  5151. if (container.nodeType == 3 /* TEXT_NODE */)
  5152. return container;
  5153. if (offset < 0)
  5154. return container;
  5155. child = container.firstChild;
  5156. while (child && offset > 0) {
  5157. --offset;
  5158. child = child.nextSibling;
  5159. }
  5160. if (child)
  5161. return child;
  5162. return container;
  5163. };
  5164. function _isCollapsed() {
  5165. return (t[START_CONTAINER] == t[END_CONTAINER] && t[START_OFFSET] == t[END_OFFSET]);
  5166. };
  5167. function _compareBoundaryPoints(containerA, offsetA, containerB, offsetB) {
  5168. var c, offsetC, n, cmnRoot, childA, childB;
  5169. // In the first case the boundary-points have the same container. A is before B
  5170. // if its offset is less than the offset of B, A is equal to B if its offset is
  5171. // equal to the offset of B, and A is after B if its offset is greater than the
  5172. // offset of B.
  5173. if (containerA == containerB) {
  5174. if (offsetA == offsetB)
  5175. return 0; // equal
  5176. if (offsetA < offsetB)
  5177. return -1; // before
  5178. return 1; // after
  5179. }
  5180. // In the second case a child node C of the container of A is an ancestor
  5181. // container of B. In this case, A is before B if the offset of A is less than or
  5182. // equal to the index of the child node C and A is after B otherwise.
  5183. c = containerB;
  5184. while (c && c.parentNode != containerA)
  5185. c = c.parentNode;
  5186. if (c) {
  5187. offsetC = 0;
  5188. n = containerA.firstChild;
  5189. while (n != c && offsetC < offsetA) {
  5190. offsetC++;
  5191. n = n.nextSibling;
  5192. }
  5193. if (offsetA <= offsetC)
  5194. return -1; // before
  5195. return 1; // after
  5196. }
  5197. // In the third case a child node C of the container of B is an ancestor container
  5198. // of A. In this case, A is before B if the index of the child node C is less than
  5199. // the offset of B and A is after B otherwise.
  5200. c = containerA;
  5201. while (c && c.parentNode != containerB) {
  5202. c = c.parentNode;
  5203. }
  5204. if (c) {
  5205. offsetC = 0;
  5206. n = containerB.firstChild;
  5207. while (n != c && offsetC < offsetB) {
  5208. offsetC++;
  5209. n = n.nextSibling;
  5210. }
  5211. if (offsetC < offsetB)
  5212. return -1; // before
  5213. return 1; // after
  5214. }
  5215. // In the fourth case, none of three other cases hold: the containers of A and B
  5216. // are siblings or descendants of sibling nodes. In this case, A is before B if
  5217. // the container of A is before the container of B in a pre-order traversal of the
  5218. // Ranges' context tree and A is after B otherwise.
  5219. cmnRoot = dom.findCommonAncestor(containerA, containerB);
  5220. childA = containerA;
  5221. while (childA && childA.parentNode != cmnRoot)
  5222. childA = childA.parentNode;
  5223. if (!childA)
  5224. childA = cmnRoot;
  5225. childB = containerB;
  5226. while (childB && childB.parentNode != cmnRoot)
  5227. childB = childB.parentNode;
  5228. if (!childB)
  5229. childB = cmnRoot;
  5230. if (childA == childB)
  5231. return 0; // equal
  5232. n = cmnRoot.firstChild;
  5233. while (n) {
  5234. if (n == childA)
  5235. return -1; // before
  5236. if (n == childB)
  5237. return 1; // after
  5238. n = n.nextSibling;
  5239. }
  5240. };
  5241. function _setEndPoint(st, n, o) {
  5242. var ec, sc;
  5243. if (st) {
  5244. t[START_CONTAINER] = n;
  5245. t[START_OFFSET] = o;
  5246. } else {
  5247. t[END_CONTAINER] = n;
  5248. t[END_OFFSET] = o;
  5249. }
  5250. // If one boundary-point of a Range is set to have a root container
  5251. // other than the current one for the Range, the Range is collapsed to
  5252. // the new position. This enforces the restriction that both boundary-
  5253. // points of a Range must have the same root container.
  5254. ec = t[END_CONTAINER];
  5255. while (ec.parentNode)
  5256. ec = ec.parentNode;
  5257. sc = t[START_CONTAINER];
  5258. while (sc.parentNode)
  5259. sc = sc.parentNode;
  5260. if (sc == ec) {
  5261. // The start position of a Range is guaranteed to never be after the
  5262. // end position. To enforce this restriction, if the start is set to
  5263. // be at a position after the end, the Range is collapsed to that
  5264. // position.
  5265. if (_compareBoundaryPoints(t[START_CONTAINER], t[START_OFFSET], t[END_CONTAINER], t[END_OFFSET]) > 0)
  5266. t.collapse(st);
  5267. } else
  5268. t.collapse(st);
  5269. t.collapsed = _isCollapsed();
  5270. t.commonAncestorContainer = dom.findCommonAncestor(t[START_CONTAINER], t[END_CONTAINER]);
  5271. };
  5272. function _traverse(how) {
  5273. var c, endContainerDepth = 0, startContainerDepth = 0, p, depthDiff, startNode, endNode, sp, ep;
  5274. if (t[START_CONTAINER] == t[END_CONTAINER])
  5275. return _traverseSameContainer(how);
  5276. for (c = t[END_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  5277. if (p == t[START_CONTAINER])
  5278. return _traverseCommonStartContainer(c, how);
  5279. ++endContainerDepth;
  5280. }
  5281. for (c = t[START_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  5282. if (p == t[END_CONTAINER])
  5283. return _traverseCommonEndContainer(c, how);
  5284. ++startContainerDepth;
  5285. }
  5286. depthDiff = startContainerDepth - endContainerDepth;
  5287. startNode = t[START_CONTAINER];
  5288. while (depthDiff > 0) {
  5289. startNode = startNode.parentNode;
  5290. depthDiff--;
  5291. }
  5292. endNode = t[END_CONTAINER];
  5293. while (depthDiff < 0) {
  5294. endNode = endNode.parentNode;
  5295. depthDiff++;
  5296. }
  5297. // ascend the ancestor hierarchy until we have a common parent.
  5298. for (sp = startNode.parentNode, ep = endNode.parentNode; sp != ep; sp = sp.parentNode, ep = ep.parentNode) {
  5299. startNode = sp;
  5300. endNode = ep;
  5301. }
  5302. return _traverseCommonAncestors(startNode, endNode, how);
  5303. };
  5304. function _traverseSameContainer(how) {
  5305. var frag, s, sub, n, cnt, sibling, xferNode, start, len;
  5306. if (how != DELETE)
  5307. frag = createDocumentFragment();
  5308. // If selection is empty, just return the fragment
  5309. if (t[START_OFFSET] == t[END_OFFSET])
  5310. return frag;
  5311. // Text node needs special case handling
  5312. if (t[START_CONTAINER].nodeType == 3 /* TEXT_NODE */) {
  5313. // get the substring
  5314. s = t[START_CONTAINER].nodeValue;
  5315. sub = s.substring(t[START_OFFSET], t[END_OFFSET]);
  5316. // set the original text node to its new value
  5317. if (how != CLONE) {
  5318. n = t[START_CONTAINER];
  5319. start = t[START_OFFSET];
  5320. len = t[END_OFFSET] - t[START_OFFSET];
  5321. if (start === 0 && len >= n.nodeValue.length - 1) {
  5322. n.parentNode.removeChild(n);
  5323. } else {
  5324. n.deleteData(start, len);
  5325. }
  5326. // Nothing is partially selected, so collapse to start point
  5327. t.collapse(TRUE);
  5328. }
  5329. if (how == DELETE)
  5330. return;
  5331. if (sub.length > 0) {
  5332. frag.appendChild(doc.createTextNode(sub));
  5333. }
  5334. return frag;
  5335. }
  5336. // Copy nodes between the start/end offsets.
  5337. n = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]);
  5338. cnt = t[END_OFFSET] - t[START_OFFSET];
  5339. while (n && cnt > 0) {
  5340. sibling = n.nextSibling;
  5341. xferNode = _traverseFullySelected(n, how);
  5342. if (frag)
  5343. frag.appendChild( xferNode );
  5344. --cnt;
  5345. n = sibling;
  5346. }
  5347. // Nothing is partially selected, so collapse to start point
  5348. if (how != CLONE)
  5349. t.collapse(TRUE);
  5350. return frag;
  5351. };
  5352. function _traverseCommonStartContainer(endAncestor, how) {
  5353. var frag, n, endIdx, cnt, sibling, xferNode;
  5354. if (how != DELETE)
  5355. frag = createDocumentFragment();
  5356. n = _traverseRightBoundary(endAncestor, how);
  5357. if (frag)
  5358. frag.appendChild(n);
  5359. endIdx = nodeIndex(endAncestor);
  5360. cnt = endIdx - t[START_OFFSET];
  5361. if (cnt <= 0) {
  5362. // Collapse to just before the endAncestor, which
  5363. // is partially selected.
  5364. if (how != CLONE) {
  5365. t.setEndBefore(endAncestor);
  5366. t.collapse(FALSE);
  5367. }
  5368. return frag;
  5369. }
  5370. n = endAncestor.previousSibling;
  5371. while (cnt > 0) {
  5372. sibling = n.previousSibling;
  5373. xferNode = _traverseFullySelected(n, how);
  5374. if (frag)
  5375. frag.insertBefore(xferNode, frag.firstChild);
  5376. --cnt;
  5377. n = sibling;
  5378. }
  5379. // Collapse to just before the endAncestor, which
  5380. // is partially selected.
  5381. if (how != CLONE) {
  5382. t.setEndBefore(endAncestor);
  5383. t.collapse(FALSE);
  5384. }
  5385. return frag;
  5386. };
  5387. function _traverseCommonEndContainer(startAncestor, how) {
  5388. var frag, startIdx, n, cnt, sibling, xferNode;
  5389. if (how != DELETE)
  5390. frag = createDocumentFragment();
  5391. n = _traverseLeftBoundary(startAncestor, how);
  5392. if (frag)
  5393. frag.appendChild(n);
  5394. startIdx = nodeIndex(startAncestor);
  5395. ++startIdx; // Because we already traversed it
  5396. cnt = t[END_OFFSET] - startIdx;
  5397. n = startAncestor.nextSibling;
  5398. while (n && cnt > 0) {
  5399. sibling = n.nextSibling;
  5400. xferNode = _traverseFullySelected(n, how);
  5401. if (frag)
  5402. frag.appendChild(xferNode);
  5403. --cnt;
  5404. n = sibling;
  5405. }
  5406. if (how != CLONE) {
  5407. t.setStartAfter(startAncestor);
  5408. t.collapse(TRUE);
  5409. }
  5410. return frag;
  5411. };
  5412. function _traverseCommonAncestors(startAncestor, endAncestor, how) {
  5413. var n, frag, commonParent, startOffset, endOffset, cnt, sibling, nextSibling;
  5414. if (how != DELETE)
  5415. frag = createDocumentFragment();
  5416. n = _traverseLeftBoundary(startAncestor, how);
  5417. if (frag)
  5418. frag.appendChild(n);
  5419. commonParent = startAncestor.parentNode;
  5420. startOffset = nodeIndex(startAncestor);
  5421. endOffset = nodeIndex(endAncestor);
  5422. ++startOffset;
  5423. cnt = endOffset - startOffset;
  5424. sibling = startAncestor.nextSibling;
  5425. while (cnt > 0) {
  5426. nextSibling = sibling.nextSibling;
  5427. n = _traverseFullySelected(sibling, how);
  5428. if (frag)
  5429. frag.appendChild(n);
  5430. sibling = nextSibling;
  5431. --cnt;
  5432. }
  5433. n = _traverseRightBoundary(endAncestor, how);
  5434. if (frag)
  5435. frag.appendChild(n);
  5436. if (how != CLONE) {
  5437. t.setStartAfter(startAncestor);
  5438. t.collapse(TRUE);
  5439. }
  5440. return frag;
  5441. };
  5442. function _traverseRightBoundary(root, how) {
  5443. var next = _getSelectedNode(t[END_CONTAINER], t[END_OFFSET] - 1), parent, clonedParent, prevSibling, clonedChild, clonedGrandParent, isFullySelected = next != t[END_CONTAINER];
  5444. if (next == root)
  5445. return _traverseNode(next, isFullySelected, FALSE, how);
  5446. parent = next.parentNode;
  5447. clonedParent = _traverseNode(parent, FALSE, FALSE, how);
  5448. while (parent) {
  5449. while (next) {
  5450. prevSibling = next.previousSibling;
  5451. clonedChild = _traverseNode(next, isFullySelected, FALSE, how);
  5452. if (how != DELETE)
  5453. clonedParent.insertBefore(clonedChild, clonedParent.firstChild);
  5454. isFullySelected = TRUE;
  5455. next = prevSibling;
  5456. }
  5457. if (parent == root)
  5458. return clonedParent;
  5459. next = parent.previousSibling;
  5460. parent = parent.parentNode;
  5461. clonedGrandParent = _traverseNode(parent, FALSE, FALSE, how);
  5462. if (how != DELETE)
  5463. clonedGrandParent.appendChild(clonedParent);
  5464. clonedParent = clonedGrandParent;
  5465. }
  5466. };
  5467. function _traverseLeftBoundary(root, how) {
  5468. var next = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]), isFullySelected = next != t[START_CONTAINER], parent, clonedParent, nextSibling, clonedChild, clonedGrandParent;
  5469. if (next == root)
  5470. return _traverseNode(next, isFullySelected, TRUE, how);
  5471. parent = next.parentNode;
  5472. clonedParent = _traverseNode(parent, FALSE, TRUE, how);
  5473. while (parent) {
  5474. while (next) {
  5475. nextSibling = next.nextSibling;
  5476. clonedChild = _traverseNode(next, isFullySelected, TRUE, how);
  5477. if (how != DELETE)
  5478. clonedParent.appendChild(clonedChild);
  5479. isFullySelected = TRUE;
  5480. next = nextSibling;
  5481. }
  5482. if (parent == root)
  5483. return clonedParent;
  5484. next = parent.nextSibling;
  5485. parent = parent.parentNode;
  5486. clonedGrandParent = _traverseNode(parent, FALSE, TRUE, how);
  5487. if (how != DELETE)
  5488. clonedGrandParent.appendChild(clonedParent);
  5489. clonedParent = clonedGrandParent;
  5490. }
  5491. };
  5492. function _traverseNode(n, isFullySelected, isLeft, how) {
  5493. var txtValue, newNodeValue, oldNodeValue, offset, newNode;
  5494. if (isFullySelected)
  5495. return _traverseFullySelected(n, how);
  5496. if (n.nodeType == 3 /* TEXT_NODE */) {
  5497. txtValue = n.nodeValue;
  5498. if (isLeft) {
  5499. offset = t[START_OFFSET];
  5500. newNodeValue = txtValue.substring(offset);
  5501. oldNodeValue = txtValue.substring(0, offset);
  5502. } else {
  5503. offset = t[END_OFFSET];
  5504. newNodeValue = txtValue.substring(0, offset);
  5505. oldNodeValue = txtValue.substring(offset);
  5506. }
  5507. if (how != CLONE)
  5508. n.nodeValue = oldNodeValue;
  5509. if (how == DELETE)
  5510. return;
  5511. newNode = dom.clone(n, FALSE);
  5512. newNode.nodeValue = newNodeValue;
  5513. return newNode;
  5514. }
  5515. if (how == DELETE)
  5516. return;
  5517. return dom.clone(n, FALSE);
  5518. };
  5519. function _traverseFullySelected(n, how) {
  5520. if (how != DELETE)
  5521. return how == CLONE ? dom.clone(n, TRUE) : n;
  5522. n.parentNode.removeChild(n);
  5523. };
  5524. function toStringIE() {
  5525. return dom.create('body', null, cloneContents()).outerText;
  5526. }
  5527. return t;
  5528. };
  5529. ns.Range = Range;
  5530. // Older IE versions doesn't let you override toString by it's constructor so we have to stick it in the prototype
  5531. Range.prototype.toString = function() {
  5532. return this.toStringIE();
  5533. };
  5534. })(tinymce.dom);
  5535. (function() {
  5536. function Selection(selection) {
  5537. var self = this, dom = selection.dom, TRUE = true, FALSE = false;
  5538. function getPosition(rng, start) {
  5539. var checkRng, startIndex = 0, endIndex, inside,
  5540. children, child, offset, index, position = -1, parent;
  5541. // Setup test range, collapse it and get the parent
  5542. checkRng = rng.duplicate();
  5543. checkRng.collapse(start);
  5544. parent = checkRng.parentElement();
  5545. // Check if the selection is within the right document
  5546. if (parent.ownerDocument !== selection.dom.doc)
  5547. return;
  5548. // IE will report non editable elements as it's parent so look for an editable one
  5549. while (parent.contentEditable === "false") {
  5550. parent = parent.parentNode;
  5551. }
  5552. // If parent doesn't have any children then return that we are inside the element
  5553. if (!parent.hasChildNodes()) {
  5554. return {node : parent, inside : 1};
  5555. }
  5556. // Setup node list and endIndex
  5557. children = parent.children;
  5558. endIndex = children.length - 1;
  5559. // Perform a binary search for the position
  5560. while (startIndex <= endIndex) {
  5561. index = Math.floor((startIndex + endIndex) / 2);
  5562. // Move selection to node and compare the ranges
  5563. child = children[index];
  5564. checkRng.moveToElementText(child);
  5565. position = checkRng.compareEndPoints(start ? 'StartToStart' : 'EndToEnd', rng);
  5566. // Before/after or an exact match
  5567. if (position > 0) {
  5568. endIndex = index - 1;
  5569. } else if (position < 0) {
  5570. startIndex = index + 1;
  5571. } else {
  5572. return {node : child};
  5573. }
  5574. }
  5575. // Check if child position is before or we didn't find a position
  5576. if (position < 0) {
  5577. // No element child was found use the parent element and the offset inside that
  5578. if (!child) {
  5579. checkRng.moveToElementText(parent);
  5580. checkRng.collapse(true);
  5581. child = parent;
  5582. inside = true;
  5583. } else
  5584. checkRng.collapse(false);
  5585. // 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
  5586. // We need to walk char by char since rng.text or rng.htmlText will trim line endings
  5587. offset = 0;
  5588. while (checkRng.compareEndPoints(start ? 'StartToStart' : 'StartToEnd', rng) !== 0) {
  5589. if (checkRng.move('character', 1) === 0 || parent != checkRng.parentElement()) {
  5590. break;
  5591. }
  5592. offset++;
  5593. }
  5594. } else {
  5595. // Child position is after the selection endpoint
  5596. checkRng.collapse(true);
  5597. // 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
  5598. offset = 0;
  5599. while (checkRng.compareEndPoints(start ? 'StartToStart' : 'StartToEnd', rng) !== 0) {
  5600. if (checkRng.move('character', -1) === 0 || parent != checkRng.parentElement()) {
  5601. break;
  5602. }
  5603. offset++;
  5604. }
  5605. }
  5606. return {node : child, position : position, offset : offset, inside : inside};
  5607. };
  5608. // Returns a W3C DOM compatible range object by using the IE Range API
  5609. function getRange() {
  5610. var ieRange = selection.getRng(), domRange = dom.createRng(), element, collapsed, tmpRange, element2, bookmark, fail;
  5611. // If selection is outside the current document just return an empty range
  5612. element = ieRange.item ? ieRange.item(0) : ieRange.parentElement();
  5613. if (element.ownerDocument != dom.doc)
  5614. return domRange;
  5615. collapsed = selection.isCollapsed();
  5616. // Handle control selection
  5617. if (ieRange.item) {
  5618. domRange.setStart(element.parentNode, dom.nodeIndex(element));
  5619. domRange.setEnd(domRange.startContainer, domRange.startOffset + 1);
  5620. return domRange;
  5621. }
  5622. function findEndPoint(start) {
  5623. var endPoint = getPosition(ieRange, start), container, offset, textNodeOffset = 0, sibling, undef, nodeValue;
  5624. container = endPoint.node;
  5625. offset = endPoint.offset;
  5626. if (endPoint.inside && !container.hasChildNodes()) {
  5627. domRange[start ? 'setStart' : 'setEnd'](container, 0);
  5628. return;
  5629. }
  5630. if (offset === undef) {
  5631. domRange[start ? 'setStartBefore' : 'setEndAfter'](container);
  5632. return;
  5633. }
  5634. if (endPoint.position < 0) {
  5635. sibling = endPoint.inside ? container.firstChild : container.nextSibling;
  5636. if (!sibling) {
  5637. domRange[start ? 'setStartAfter' : 'setEndAfter'](container);
  5638. return;
  5639. }
  5640. if (!offset) {
  5641. if (sibling.nodeType == 3)
  5642. domRange[start ? 'setStart' : 'setEnd'](sibling, 0);
  5643. else
  5644. domRange[start ? 'setStartBefore' : 'setEndBefore'](sibling);
  5645. return;
  5646. }
  5647. // Find the text node and offset
  5648. while (sibling) {
  5649. nodeValue = sibling.nodeValue;
  5650. textNodeOffset += nodeValue.length;
  5651. // We are at or passed the position we where looking for
  5652. if (textNodeOffset >= offset) {
  5653. container = sibling;
  5654. textNodeOffset -= offset;
  5655. textNodeOffset = nodeValue.length - textNodeOffset;
  5656. break;
  5657. }
  5658. sibling = sibling.nextSibling;
  5659. }
  5660. } else {
  5661. // Find the text node and offset
  5662. sibling = container.previousSibling;
  5663. if (!sibling)
  5664. return domRange[start ? 'setStartBefore' : 'setEndBefore'](container);
  5665. // If there isn't any text to loop then use the first position
  5666. if (!offset) {
  5667. if (container.nodeType == 3)
  5668. domRange[start ? 'setStart' : 'setEnd'](sibling, container.nodeValue.length);
  5669. else
  5670. domRange[start ? 'setStartAfter' : 'setEndAfter'](sibling);
  5671. return;
  5672. }
  5673. while (sibling) {
  5674. textNodeOffset += sibling.nodeValue.length;
  5675. // We are at or passed the position we where looking for
  5676. if (textNodeOffset >= offset) {
  5677. container = sibling;
  5678. textNodeOffset -= offset;
  5679. break;
  5680. }
  5681. sibling = sibling.previousSibling;
  5682. }
  5683. }
  5684. domRange[start ? 'setStart' : 'setEnd'](container, textNodeOffset);
  5685. };
  5686. try {
  5687. // Find start point
  5688. findEndPoint(true);
  5689. // Find end point if needed
  5690. if (!collapsed)
  5691. findEndPoint();
  5692. } catch (ex) {
  5693. // IE has a nasty bug where text nodes might throw "invalid argument" when you
  5694. // access the nodeValue or other properties of text nodes. This seems to happend when
  5695. // text nodes are split into two nodes by a delete/backspace call. So lets detect it and try to fix it.
  5696. if (ex.number == -2147024809) {
  5697. // Get the current selection
  5698. bookmark = self.getBookmark(2);
  5699. // Get start element
  5700. tmpRange = ieRange.duplicate();
  5701. tmpRange.collapse(true);
  5702. element = tmpRange.parentElement();
  5703. // Get end element
  5704. if (!collapsed) {
  5705. tmpRange = ieRange.duplicate();
  5706. tmpRange.collapse(false);
  5707. element2 = tmpRange.parentElement();
  5708. element2.innerHTML = element2.innerHTML;
  5709. }
  5710. // Remove the broken elements
  5711. element.innerHTML = element.innerHTML;
  5712. // Restore the selection
  5713. self.moveToBookmark(bookmark);
  5714. // Since the range has moved we need to re-get it
  5715. ieRange = selection.getRng();
  5716. // Find start point
  5717. findEndPoint(true);
  5718. // Find end point if needed
  5719. if (!collapsed)
  5720. findEndPoint();
  5721. } else
  5722. throw ex; // Throw other errors
  5723. }
  5724. return domRange;
  5725. };
  5726. this.getBookmark = function(type) {
  5727. var rng = selection.getRng(), start, end, bookmark = {};
  5728. function getIndexes(node) {
  5729. var parent, root, children, i, indexes = [];
  5730. parent = node.parentNode;
  5731. root = dom.getRoot().parentNode;
  5732. while (parent != root && parent.nodeType !== 9) {
  5733. children = parent.children;
  5734. i = children.length;
  5735. while (i--) {
  5736. if (node === children[i]) {
  5737. indexes.push(i);
  5738. break;
  5739. }
  5740. }
  5741. node = parent;
  5742. parent = parent.parentNode;
  5743. }
  5744. return indexes;
  5745. };
  5746. function getBookmarkEndPoint(start) {
  5747. var position;
  5748. position = getPosition(rng, start);
  5749. if (position) {
  5750. return {
  5751. position : position.position,
  5752. offset : position.offset,
  5753. indexes : getIndexes(position.node),
  5754. inside : position.inside
  5755. };
  5756. }
  5757. };
  5758. // Non ubstructive bookmark
  5759. if (type === 2) {
  5760. // Handle text selection
  5761. if (!rng.item) {
  5762. bookmark.start = getBookmarkEndPoint(true);
  5763. if (!selection.isCollapsed())
  5764. bookmark.end = getBookmarkEndPoint();
  5765. } else
  5766. bookmark.start = {ctrl : true, indexes : getIndexes(rng.item(0))};
  5767. }
  5768. return bookmark;
  5769. };
  5770. this.moveToBookmark = function(bookmark) {
  5771. var rng, body = dom.doc.body;
  5772. function resolveIndexes(indexes) {
  5773. var node, i, idx, children;
  5774. node = dom.getRoot();
  5775. for (i = indexes.length - 1; i >= 0; i--) {
  5776. children = node.children;
  5777. idx = indexes[i];
  5778. if (idx <= children.length - 1) {
  5779. node = children[idx];
  5780. }
  5781. }
  5782. return node;
  5783. };
  5784. function setBookmarkEndPoint(start) {
  5785. var endPoint = bookmark[start ? 'start' : 'end'], moveLeft, moveRng, undef;
  5786. if (endPoint) {
  5787. moveLeft = endPoint.position > 0;
  5788. moveRng = body.createTextRange();
  5789. moveRng.moveToElementText(resolveIndexes(endPoint.indexes));
  5790. offset = endPoint.offset;
  5791. if (offset !== undef) {
  5792. moveRng.collapse(endPoint.inside || moveLeft);
  5793. moveRng.moveStart('character', moveLeft ? -offset : offset);
  5794. } else
  5795. moveRng.collapse(start);
  5796. rng.setEndPoint(start ? 'StartToStart' : 'EndToStart', moveRng);
  5797. if (start)
  5798. rng.collapse(true);
  5799. }
  5800. };
  5801. if (bookmark.start) {
  5802. if (bookmark.start.ctrl) {
  5803. rng = body.createControlRange();
  5804. rng.addElement(resolveIndexes(bookmark.start.indexes));
  5805. rng.select();
  5806. } else {
  5807. rng = body.createTextRange();
  5808. setBookmarkEndPoint(true);
  5809. setBookmarkEndPoint();
  5810. rng.select();
  5811. }
  5812. }
  5813. };
  5814. this.addRange = function(rng) {
  5815. var ieRng, ctrlRng, startContainer, startOffset, endContainer, endOffset, sibling, doc = selection.dom.doc, body = doc.body;
  5816. function setEndPoint(start) {
  5817. var container, offset, marker, tmpRng, nodes;
  5818. marker = dom.create('a');
  5819. container = start ? startContainer : endContainer;
  5820. offset = start ? startOffset : endOffset;
  5821. tmpRng = ieRng.duplicate();
  5822. if (container == doc || container == doc.documentElement) {
  5823. container = body;
  5824. offset = 0;
  5825. }
  5826. if (container.nodeType == 3) {
  5827. container.parentNode.insertBefore(marker, container);
  5828. tmpRng.moveToElementText(marker);
  5829. tmpRng.moveStart('character', offset);
  5830. dom.remove(marker);
  5831. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  5832. } else {
  5833. nodes = container.childNodes;
  5834. if (nodes.length) {
  5835. if (offset >= nodes.length) {
  5836. dom.insertAfter(marker, nodes[nodes.length - 1]);
  5837. } else {
  5838. container.insertBefore(marker, nodes[offset]);
  5839. }
  5840. tmpRng.moveToElementText(marker);
  5841. } else if (container.canHaveHTML) {
  5842. // Empty node selection for example <div>|</div>
  5843. // Setting innerHTML with a span marker then remove that marker seems to keep empty block elements open
  5844. container.innerHTML = '<span>\uFEFF</span>';
  5845. marker = container.firstChild;
  5846. tmpRng.moveToElementText(marker);
  5847. tmpRng.collapse(FALSE); // Collapse false works better than true for some odd reason
  5848. }
  5849. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  5850. dom.remove(marker);
  5851. }
  5852. }
  5853. // Setup some shorter versions
  5854. startContainer = rng.startContainer;
  5855. startOffset = rng.startOffset;
  5856. endContainer = rng.endContainer;
  5857. endOffset = rng.endOffset;
  5858. ieRng = body.createTextRange();
  5859. // If single element selection then try making a control selection out of it
  5860. if (startContainer == endContainer && startContainer.nodeType == 1) {
  5861. // Trick to place the caret inside an empty block element like <p></p>
  5862. if (startOffset == endOffset && !startContainer.hasChildNodes()) {
  5863. if (startContainer.canHaveHTML) {
  5864. // Check if previous sibling is an empty block if it is then we need to render it
  5865. // IE would otherwise move the caret into the sibling instead of the empty startContainer see: #5236
  5866. // Example this: <p></p><p>|</p> would become this: <p>|</p><p></p>
  5867. sibling = startContainer.previousSibling;
  5868. if (sibling && !sibling.hasChildNodes() && dom.isBlock(sibling)) {
  5869. sibling.innerHTML = '\uFEFF';
  5870. } else {
  5871. sibling = null;
  5872. }
  5873. startContainer.innerHTML = '<span>\uFEFF</span><span>\uFEFF</span>';
  5874. ieRng.moveToElementText(startContainer.lastChild);
  5875. ieRng.select();
  5876. dom.doc.selection.clear();
  5877. startContainer.innerHTML = '';
  5878. if (sibling) {
  5879. sibling.innerHTML = '';
  5880. }
  5881. return;
  5882. } else {
  5883. startOffset = dom.nodeIndex(startContainer);
  5884. startContainer = startContainer.parentNode;
  5885. }
  5886. }
  5887. if (startOffset == endOffset - 1) {
  5888. try {
  5889. ctrlRng = body.createControlRange();
  5890. ctrlRng.addElement(startContainer.childNodes[startOffset]);
  5891. ctrlRng.select();
  5892. return;
  5893. } catch (ex) {
  5894. // Ignore
  5895. }
  5896. }
  5897. }
  5898. // Set start/end point of selection
  5899. setEndPoint(true);
  5900. setEndPoint();
  5901. // Select the new range and scroll it into view
  5902. ieRng.select();
  5903. };
  5904. // Expose range method
  5905. this.getRangeAt = getRange;
  5906. };
  5907. // Expose the selection object
  5908. tinymce.dom.TridentSelection = Selection;
  5909. })();
  5910. /*
  5911. * Sizzle CSS Selector Engine
  5912. * Copyright, The Dojo Foundation
  5913. * Released under the MIT, BSD, and GPL Licenses.
  5914. * More information: http://sizzlejs.com/
  5915. */
  5916. (function(){
  5917. var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
  5918. expando = "sizcache",
  5919. done = 0,
  5920. toString = Object.prototype.toString,
  5921. hasDuplicate = false,
  5922. baseHasDuplicate = true,
  5923. rBackslash = /\\/g,
  5924. rReturn = /\r\n/g,
  5925. rNonWord = /\W/;
  5926. // Here we check if the JavaScript engine is using some sort of
  5927. // optimization where it does not always call our comparision
  5928. // function. If that is the case, discard the hasDuplicate value.
  5929. // Thus far that includes Google Chrome.
  5930. [0, 0].sort(function() {
  5931. baseHasDuplicate = false;
  5932. return 0;
  5933. });
  5934. var Sizzle = function( selector, context, results, seed ) {
  5935. results = results || [];
  5936. context = context || document;
  5937. var origContext = context;
  5938. if ( context.nodeType !== 1 && context.nodeType !== 9 ) {
  5939. return [];
  5940. }
  5941. if ( !selector || typeof selector !== "string" ) {
  5942. return results;
  5943. }
  5944. var m, set, checkSet, extra, ret, cur, pop, i,
  5945. prune = true,
  5946. contextXML = Sizzle.isXML( context ),
  5947. parts = [],
  5948. soFar = selector;
  5949. // Reset the position of the chunker regexp (start from head)
  5950. do {
  5951. chunker.exec( "" );
  5952. m = chunker.exec( soFar );
  5953. if ( m ) {
  5954. soFar = m[3];
  5955. parts.push( m[1] );
  5956. if ( m[2] ) {
  5957. extra = m[3];
  5958. break;
  5959. }
  5960. }
  5961. } while ( m );
  5962. if ( parts.length > 1 && origPOS.exec( selector ) ) {
  5963. if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {
  5964. set = posProcess( parts[0] + parts[1], context, seed );
  5965. } else {
  5966. set = Expr.relative[ parts[0] ] ?
  5967. [ context ] :
  5968. Sizzle( parts.shift(), context );
  5969. while ( parts.length ) {
  5970. selector = parts.shift();
  5971. if ( Expr.relative[ selector ] ) {
  5972. selector += parts.shift();
  5973. }
  5974. set = posProcess( selector, set, seed );
  5975. }
  5976. }
  5977. } else {
  5978. // Take a shortcut and set the context if the root selector is an ID
  5979. // (but not if it'll be faster if the inner selector is an ID)
  5980. if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML &&
  5981. Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) {
  5982. ret = Sizzle.find( parts.shift(), context, contextXML );
  5983. context = ret.expr ?
  5984. Sizzle.filter( ret.expr, ret.set )[0] :
  5985. ret.set[0];
  5986. }
  5987. if ( context ) {
  5988. ret = seed ?
  5989. { expr: parts.pop(), set: makeArray(seed) } :
  5990. Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML );
  5991. set = ret.expr ?
  5992. Sizzle.filter( ret.expr, ret.set ) :
  5993. ret.set;
  5994. if ( parts.length > 0 ) {
  5995. checkSet = makeArray( set );
  5996. } else {
  5997. prune = false;
  5998. }
  5999. while ( parts.length ) {
  6000. cur = parts.pop();
  6001. pop = cur;
  6002. if ( !Expr.relative[ cur ] ) {
  6003. cur = "";
  6004. } else {
  6005. pop = parts.pop();
  6006. }
  6007. if ( pop == null ) {
  6008. pop = context;
  6009. }
  6010. Expr.relative[ cur ]( checkSet, pop, contextXML );
  6011. }
  6012. } else {
  6013. checkSet = parts = [];
  6014. }
  6015. }
  6016. if ( !checkSet ) {
  6017. checkSet = set;
  6018. }
  6019. if ( !checkSet ) {
  6020. Sizzle.error( cur || selector );
  6021. }
  6022. if ( toString.call(checkSet) === "[object Array]" ) {
  6023. if ( !prune ) {
  6024. results.push.apply( results, checkSet );
  6025. } else if ( context && context.nodeType === 1 ) {
  6026. for ( i = 0; checkSet[i] != null; i++ ) {
  6027. if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && Sizzle.contains(context, checkSet[i])) ) {
  6028. results.push( set[i] );
  6029. }
  6030. }
  6031. } else {
  6032. for ( i = 0; checkSet[i] != null; i++ ) {
  6033. if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
  6034. results.push( set[i] );
  6035. }
  6036. }
  6037. }
  6038. } else {
  6039. makeArray( checkSet, results );
  6040. }
  6041. if ( extra ) {
  6042. Sizzle( extra, origContext, results, seed );
  6043. Sizzle.uniqueSort( results );
  6044. }
  6045. return results;
  6046. };
  6047. Sizzle.uniqueSort = function( results ) {
  6048. if ( sortOrder ) {
  6049. hasDuplicate = baseHasDuplicate;
  6050. results.sort( sortOrder );
  6051. if ( hasDuplicate ) {
  6052. for ( var i = 1; i < results.length; i++ ) {
  6053. if ( results[i] === results[ i - 1 ] ) {
  6054. results.splice( i--, 1 );
  6055. }
  6056. }
  6057. }
  6058. }
  6059. return results;
  6060. };
  6061. Sizzle.matches = function( expr, set ) {
  6062. return Sizzle( expr, null, null, set );
  6063. };
  6064. Sizzle.matchesSelector = function( node, expr ) {
  6065. return Sizzle( expr, null, null, [node] ).length > 0;
  6066. };
  6067. Sizzle.find = function( expr, context, isXML ) {
  6068. var set, i, len, match, type, left;
  6069. if ( !expr ) {
  6070. return [];
  6071. }
  6072. for ( i = 0, len = Expr.order.length; i < len; i++ ) {
  6073. type = Expr.order[i];
  6074. if ( (match = Expr.leftMatch[ type ].exec( expr )) ) {
  6075. left = match[1];
  6076. match.splice( 1, 1 );
  6077. if ( left.substr( left.length - 1 ) !== "\\" ) {
  6078. match[1] = (match[1] || "").replace( rBackslash, "" );
  6079. set = Expr.find[ type ]( match, context, isXML );
  6080. if ( set != null ) {
  6081. expr = expr.replace( Expr.match[ type ], "" );
  6082. break;
  6083. }
  6084. }
  6085. }
  6086. }
  6087. if ( !set ) {
  6088. set = typeof context.getElementsByTagName !== "undefined" ?
  6089. context.getElementsByTagName( "*" ) :
  6090. [];
  6091. }
  6092. return { set: set, expr: expr };
  6093. };
  6094. Sizzle.filter = function( expr, set, inplace, not ) {
  6095. var match, anyFound,
  6096. type, found, item, filter, left,
  6097. i, pass,
  6098. old = expr,
  6099. result = [],
  6100. curLoop = set,
  6101. isXMLFilter = set && set[0] && Sizzle.isXML( set[0] );
  6102. while ( expr && set.length ) {
  6103. for ( type in Expr.filter ) {
  6104. if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {
  6105. filter = Expr.filter[ type ];
  6106. left = match[1];
  6107. anyFound = false;
  6108. match.splice(1,1);
  6109. if ( left.substr( left.length - 1 ) === "\\" ) {
  6110. continue;
  6111. }
  6112. if ( curLoop === result ) {
  6113. result = [];
  6114. }
  6115. if ( Expr.preFilter[ type ] ) {
  6116. match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter );
  6117. if ( !match ) {
  6118. anyFound = found = true;
  6119. } else if ( match === true ) {
  6120. continue;
  6121. }
  6122. }
  6123. if ( match ) {
  6124. for ( i = 0; (item = curLoop[i]) != null; i++ ) {
  6125. if ( item ) {
  6126. found = filter( item, match, i, curLoop );
  6127. pass = not ^ found;
  6128. if ( inplace && found != null ) {
  6129. if ( pass ) {
  6130. anyFound = true;
  6131. } else {
  6132. curLoop[i] = false;
  6133. }
  6134. } else if ( pass ) {
  6135. result.push( item );
  6136. anyFound = true;
  6137. }
  6138. }
  6139. }
  6140. }
  6141. if ( found !== undefined ) {
  6142. if ( !inplace ) {
  6143. curLoop = result;
  6144. }
  6145. expr = expr.replace( Expr.match[ type ], "" );
  6146. if ( !anyFound ) {
  6147. return [];
  6148. }
  6149. break;
  6150. }
  6151. }
  6152. }
  6153. // Improper expression
  6154. if ( expr === old ) {
  6155. if ( anyFound == null ) {
  6156. Sizzle.error( expr );
  6157. } else {
  6158. break;
  6159. }
  6160. }
  6161. old = expr;
  6162. }
  6163. return curLoop;
  6164. };
  6165. Sizzle.error = function( msg ) {
  6166. throw new Error( "Syntax error, unrecognized expression: " + msg );
  6167. };
  6168. var getText = Sizzle.getText = function( elem ) {
  6169. var i, node,
  6170. nodeType = elem.nodeType,
  6171. ret = "";
  6172. if ( nodeType ) {
  6173. if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
  6174. // Use textContent || innerText for elements
  6175. if ( typeof elem.textContent === 'string' ) {
  6176. return elem.textContent;
  6177. } else if ( typeof elem.innerText === 'string' ) {
  6178. // Replace IE's carriage returns
  6179. return elem.innerText.replace( rReturn, '' );
  6180. } else {
  6181. // Traverse it's children
  6182. for ( elem = elem.firstChild; elem; elem = elem.nextSibling) {
  6183. ret += getText( elem );
  6184. }
  6185. }
  6186. } else if ( nodeType === 3 || nodeType === 4 ) {
  6187. return elem.nodeValue;
  6188. }
  6189. } else {
  6190. // If no nodeType, this is expected to be an array
  6191. for ( i = 0; (node = elem[i]); i++ ) {
  6192. // Do not traverse comment nodes
  6193. if ( node.nodeType !== 8 ) {
  6194. ret += getText( node );
  6195. }
  6196. }
  6197. }
  6198. return ret;
  6199. };
  6200. var Expr = Sizzle.selectors = {
  6201. order: [ "ID", "NAME", "TAG" ],
  6202. match: {
  6203. ID: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
  6204. CLASS: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
  6205. NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,
  6206. ATTR: /\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/,
  6207. TAG: /^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,
  6208. CHILD: /:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/,
  6209. POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,
  6210. PSEUDO: /:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/
  6211. },
  6212. leftMatch: {},
  6213. attrMap: {
  6214. "class": "className",
  6215. "for": "htmlFor"
  6216. },
  6217. attrHandle: {
  6218. href: function( elem ) {
  6219. return elem.getAttribute( "href" );
  6220. },
  6221. type: function( elem ) {
  6222. return elem.getAttribute( "type" );
  6223. }
  6224. },
  6225. relative: {
  6226. "+": function(checkSet, part){
  6227. var isPartStr = typeof part === "string",
  6228. isTag = isPartStr && !rNonWord.test( part ),
  6229. isPartStrNotTag = isPartStr && !isTag;
  6230. if ( isTag ) {
  6231. part = part.toLowerCase();
  6232. }
  6233. for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) {
  6234. if ( (elem = checkSet[i]) ) {
  6235. while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}
  6236. checkSet[i] = isPartStrNotTag || elem && elem.nodeName.toLowerCase() === part ?
  6237. elem || false :
  6238. elem === part;
  6239. }
  6240. }
  6241. if ( isPartStrNotTag ) {
  6242. Sizzle.filter( part, checkSet, true );
  6243. }
  6244. },
  6245. ">": function( checkSet, part ) {
  6246. var elem,
  6247. isPartStr = typeof part === "string",
  6248. i = 0,
  6249. l = checkSet.length;
  6250. if ( isPartStr && !rNonWord.test( part ) ) {
  6251. part = part.toLowerCase();
  6252. for ( ; i < l; i++ ) {
  6253. elem = checkSet[i];
  6254. if ( elem ) {
  6255. var parent = elem.parentNode;
  6256. checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false;
  6257. }
  6258. }
  6259. } else {
  6260. for ( ; i < l; i++ ) {
  6261. elem = checkSet[i];
  6262. if ( elem ) {
  6263. checkSet[i] = isPartStr ?
  6264. elem.parentNode :
  6265. elem.parentNode === part;
  6266. }
  6267. }
  6268. if ( isPartStr ) {
  6269. Sizzle.filter( part, checkSet, true );
  6270. }
  6271. }
  6272. },
  6273. "": function(checkSet, part, isXML){
  6274. var nodeCheck,
  6275. doneName = done++,
  6276. checkFn = dirCheck;
  6277. if ( typeof part === "string" && !rNonWord.test( part ) ) {
  6278. part = part.toLowerCase();
  6279. nodeCheck = part;
  6280. checkFn = dirNodeCheck;
  6281. }
  6282. checkFn( "parentNode", part, doneName, checkSet, nodeCheck, isXML );
  6283. },
  6284. "~": function( checkSet, part, isXML ) {
  6285. var nodeCheck,
  6286. doneName = done++,
  6287. checkFn = dirCheck;
  6288. if ( typeof part === "string" && !rNonWord.test( part ) ) {
  6289. part = part.toLowerCase();
  6290. nodeCheck = part;
  6291. checkFn = dirNodeCheck;
  6292. }
  6293. checkFn( "previousSibling", part, doneName, checkSet, nodeCheck, isXML );
  6294. }
  6295. },
  6296. find: {
  6297. ID: function( match, context, isXML ) {
  6298. if ( typeof context.getElementById !== "undefined" && !isXML ) {
  6299. var m = context.getElementById(match[1]);
  6300. // Check parentNode to catch when Blackberry 4.6 returns
  6301. // nodes that are no longer in the document #6963
  6302. return m && m.parentNode ? [m] : [];
  6303. }
  6304. },
  6305. NAME: function( match, context ) {
  6306. if ( typeof context.getElementsByName !== "undefined" ) {
  6307. var ret = [],
  6308. results = context.getElementsByName( match[1] );
  6309. for ( var i = 0, l = results.length; i < l; i++ ) {
  6310. if ( results[i].getAttribute("name") === match[1] ) {
  6311. ret.push( results[i] );
  6312. }
  6313. }
  6314. return ret.length === 0 ? null : ret;
  6315. }
  6316. },
  6317. TAG: function( match, context ) {
  6318. if ( typeof context.getElementsByTagName !== "undefined" ) {
  6319. return context.getElementsByTagName( match[1] );
  6320. }
  6321. }
  6322. },
  6323. preFilter: {
  6324. CLASS: function( match, curLoop, inplace, result, not, isXML ) {
  6325. match = " " + match[1].replace( rBackslash, "" ) + " ";
  6326. if ( isXML ) {
  6327. return match;
  6328. }
  6329. for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) {
  6330. if ( elem ) {
  6331. if ( not ^ (elem.className && (" " + elem.className + " ").replace(/[\t\n\r]/g, " ").indexOf(match) >= 0) ) {
  6332. if ( !inplace ) {
  6333. result.push( elem );
  6334. }
  6335. } else if ( inplace ) {
  6336. curLoop[i] = false;
  6337. }
  6338. }
  6339. }
  6340. return false;
  6341. },
  6342. ID: function( match ) {
  6343. return match[1].replace( rBackslash, "" );
  6344. },
  6345. TAG: function( match, curLoop ) {
  6346. return match[1].replace( rBackslash, "" ).toLowerCase();
  6347. },
  6348. CHILD: function( match ) {
  6349. if ( match[1] === "nth" ) {
  6350. if ( !match[2] ) {
  6351. Sizzle.error( match[0] );
  6352. }
  6353. match[2] = match[2].replace(/^\+|\s*/g, '');
  6354. // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
  6355. var test = /(-?)(\d*)(?:n([+\-]?\d*))?/.exec(
  6356. match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" ||
  6357. !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);
  6358. // calculate the numbers (first)n+(last) including if they are negative
  6359. match[2] = (test[1] + (test[2] || 1)) - 0;
  6360. match[3] = test[3] - 0;
  6361. }
  6362. else if ( match[2] ) {
  6363. Sizzle.error( match[0] );
  6364. }
  6365. // TODO: Move to normal caching system
  6366. match[0] = done++;
  6367. return match;
  6368. },
  6369. ATTR: function( match, curLoop, inplace, result, not, isXML ) {
  6370. var name = match[1] = match[1].replace( rBackslash, "" );
  6371. if ( !isXML && Expr.attrMap[name] ) {
  6372. match[1] = Expr.attrMap[name];
  6373. }
  6374. // Handle if an un-quoted value was used
  6375. match[4] = ( match[4] || match[5] || "" ).replace( rBackslash, "" );
  6376. if ( match[2] === "~=" ) {
  6377. match[4] = " " + match[4] + " ";
  6378. }
  6379. return match;
  6380. },
  6381. PSEUDO: function( match, curLoop, inplace, result, not ) {
  6382. if ( match[1] === "not" ) {
  6383. // If we're dealing with a complex expression, or a simple one
  6384. if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) {
  6385. match[3] = Sizzle(match[3], null, null, curLoop);
  6386. } else {
  6387. var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
  6388. if ( !inplace ) {
  6389. result.push.apply( result, ret );
  6390. }
  6391. return false;
  6392. }
  6393. } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
  6394. return true;
  6395. }
  6396. return match;
  6397. },
  6398. POS: function( match ) {
  6399. match.unshift( true );
  6400. return match;
  6401. }
  6402. },
  6403. filters: {
  6404. enabled: function( elem ) {
  6405. return elem.disabled === false && elem.type !== "hidden";
  6406. },
  6407. disabled: function( elem ) {
  6408. return elem.disabled === true;
  6409. },
  6410. checked: function( elem ) {
  6411. return elem.checked === true;
  6412. },
  6413. selected: function( elem ) {
  6414. // Accessing this property makes selected-by-default
  6415. // options in Safari work properly
  6416. if ( elem.parentNode ) {
  6417. elem.parentNode.selectedIndex;
  6418. }
  6419. return elem.selected === true;
  6420. },
  6421. parent: function( elem ) {
  6422. return !!elem.firstChild;
  6423. },
  6424. empty: function( elem ) {
  6425. return !elem.firstChild;
  6426. },
  6427. has: function( elem, i, match ) {
  6428. return !!Sizzle( match[3], elem ).length;
  6429. },
  6430. header: function( elem ) {
  6431. return (/h\d/i).test( elem.nodeName );
  6432. },
  6433. text: function( elem ) {
  6434. var attr = elem.getAttribute( "type" ), type = elem.type;
  6435. // IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc)
  6436. // use getAttribute instead to test this case
  6437. return elem.nodeName.toLowerCase() === "input" && "text" === type && ( attr === type || attr === null );
  6438. },
  6439. radio: function( elem ) {
  6440. return elem.nodeName.toLowerCase() === "input" && "radio" === elem.type;
  6441. },
  6442. checkbox: function( elem ) {
  6443. return elem.nodeName.toLowerCase() === "input" && "checkbox" === elem.type;
  6444. },
  6445. file: function( elem ) {
  6446. return elem.nodeName.toLowerCase() === "input" && "file" === elem.type;
  6447. },
  6448. password: function( elem ) {
  6449. return elem.nodeName.toLowerCase() === "input" && "password" === elem.type;
  6450. },
  6451. submit: function( elem ) {
  6452. var name = elem.nodeName.toLowerCase();
  6453. return (name === "input" || name === "button") && "submit" === elem.type;
  6454. },
  6455. image: function( elem ) {
  6456. return elem.nodeName.toLowerCase() === "input" && "image" === elem.type;
  6457. },
  6458. reset: function( elem ) {
  6459. var name = elem.nodeName.toLowerCase();
  6460. return (name === "input" || name === "button") && "reset" === elem.type;
  6461. },
  6462. button: function( elem ) {
  6463. var name = elem.nodeName.toLowerCase();
  6464. return name === "input" && "button" === elem.type || name === "button";
  6465. },
  6466. input: function( elem ) {
  6467. return (/input|select|textarea|button/i).test( elem.nodeName );
  6468. },
  6469. focus: function( elem ) {
  6470. return elem === elem.ownerDocument.activeElement;
  6471. }
  6472. },
  6473. setFilters: {
  6474. first: function( elem, i ) {
  6475. return i === 0;
  6476. },
  6477. last: function( elem, i, match, array ) {
  6478. return i === array.length - 1;
  6479. },
  6480. even: function( elem, i ) {
  6481. return i % 2 === 0;
  6482. },
  6483. odd: function( elem, i ) {
  6484. return i % 2 === 1;
  6485. },
  6486. lt: function( elem, i, match ) {
  6487. return i < match[3] - 0;
  6488. },
  6489. gt: function( elem, i, match ) {
  6490. return i > match[3] - 0;
  6491. },
  6492. nth: function( elem, i, match ) {
  6493. return match[3] - 0 === i;
  6494. },
  6495. eq: function( elem, i, match ) {
  6496. return match[3] - 0 === i;
  6497. }
  6498. },
  6499. filter: {
  6500. PSEUDO: function( elem, match, i, array ) {
  6501. var name = match[1],
  6502. filter = Expr.filters[ name ];
  6503. if ( filter ) {
  6504. return filter( elem, i, match, array );
  6505. } else if ( name === "contains" ) {
  6506. return (elem.textContent || elem.innerText || getText([ elem ]) || "").indexOf(match[3]) >= 0;
  6507. } else if ( name === "not" ) {
  6508. var not = match[3];
  6509. for ( var j = 0, l = not.length; j < l; j++ ) {
  6510. if ( not[j] === elem ) {
  6511. return false;
  6512. }
  6513. }
  6514. return true;
  6515. } else {
  6516. Sizzle.error( name );
  6517. }
  6518. },
  6519. CHILD: function( elem, match ) {
  6520. var first, last,
  6521. doneName, parent, cache,
  6522. count, diff,
  6523. type = match[1],
  6524. node = elem;
  6525. switch ( type ) {
  6526. case "only":
  6527. case "first":
  6528. while ( (node = node.previousSibling) ) {
  6529. if ( node.nodeType === 1 ) {
  6530. return false;
  6531. }
  6532. }
  6533. if ( type === "first" ) {
  6534. return true;
  6535. }
  6536. node = elem;
  6537. /* falls through */
  6538. case "last":
  6539. while ( (node = node.nextSibling) ) {
  6540. if ( node.nodeType === 1 ) {
  6541. return false;
  6542. }
  6543. }
  6544. return true;
  6545. case "nth":
  6546. first = match[2];
  6547. last = match[3];
  6548. if ( first === 1 && last === 0 ) {
  6549. return true;
  6550. }
  6551. doneName = match[0];
  6552. parent = elem.parentNode;
  6553. if ( parent && (parent[ expando ] !== doneName || !elem.nodeIndex) ) {
  6554. count = 0;
  6555. for ( node = parent.firstChild; node; node = node.nextSibling ) {
  6556. if ( node.nodeType === 1 ) {
  6557. node.nodeIndex = ++count;
  6558. }
  6559. }
  6560. parent[ expando ] = doneName;
  6561. }
  6562. diff = elem.nodeIndex - last;
  6563. if ( first === 0 ) {
  6564. return diff === 0;
  6565. } else {
  6566. return ( diff % first === 0 && diff / first >= 0 );
  6567. }
  6568. }
  6569. },
  6570. ID: function( elem, match ) {
  6571. return elem.nodeType === 1 && elem.getAttribute("id") === match;
  6572. },
  6573. TAG: function( elem, match ) {
  6574. return (match === "*" && elem.nodeType === 1) || !!elem.nodeName && elem.nodeName.toLowerCase() === match;
  6575. },
  6576. CLASS: function( elem, match ) {
  6577. return (" " + (elem.className || elem.getAttribute("class")) + " ")
  6578. .indexOf( match ) > -1;
  6579. },
  6580. ATTR: function( elem, match ) {
  6581. var name = match[1],
  6582. result = Sizzle.attr ?
  6583. Sizzle.attr( elem, name ) :
  6584. Expr.attrHandle[ name ] ?
  6585. Expr.attrHandle[ name ]( elem ) :
  6586. elem[ name ] != null ?
  6587. elem[ name ] :
  6588. elem.getAttribute( name ),
  6589. value = result + "",
  6590. type = match[2],
  6591. check = match[4];
  6592. return result == null ?
  6593. type === "!=" :
  6594. !type && Sizzle.attr ?
  6595. result != null :
  6596. type === "=" ?
  6597. value === check :
  6598. type === "*=" ?
  6599. value.indexOf(check) >= 0 :
  6600. type === "~=" ?
  6601. (" " + value + " ").indexOf(check) >= 0 :
  6602. !check ?
  6603. value && result !== false :
  6604. type === "!=" ?
  6605. value !== check :
  6606. type === "^=" ?
  6607. value.indexOf(check) === 0 :
  6608. type === "$=" ?
  6609. value.substr(value.length - check.length) === check :
  6610. type === "|=" ?
  6611. value === check || value.substr(0, check.length + 1) === check + "-" :
  6612. false;
  6613. },
  6614. POS: function( elem, match, i, array ) {
  6615. var name = match[2],
  6616. filter = Expr.setFilters[ name ];
  6617. if ( filter ) {
  6618. return filter( elem, i, match, array );
  6619. }
  6620. }
  6621. }
  6622. };
  6623. var origPOS = Expr.match.POS,
  6624. fescape = function(all, num){
  6625. return "\\" + (num - 0 + 1);
  6626. };
  6627. for ( var type in Expr.match ) {
  6628. Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) );
  6629. Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) );
  6630. }
  6631. // Expose origPOS
  6632. // "global" as in regardless of relation to brackets/parens
  6633. Expr.match.globalPOS = origPOS;
  6634. var makeArray = function( array, results ) {
  6635. array = Array.prototype.slice.call( array, 0 );
  6636. if ( results ) {
  6637. results.push.apply( results, array );
  6638. return results;
  6639. }
  6640. return array;
  6641. };
  6642. // Perform a simple check to determine if the browser is capable of
  6643. // converting a NodeList to an array using builtin methods.
  6644. // Also verifies that the returned array holds DOM nodes
  6645. // (which is not the case in the Blackberry browser)
  6646. try {
  6647. Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType;
  6648. // Provide a fallback method if it does not work
  6649. } catch( e ) {
  6650. makeArray = function( array, results ) {
  6651. var i = 0,
  6652. ret = results || [];
  6653. if ( toString.call(array) === "[object Array]" ) {
  6654. Array.prototype.push.apply( ret, array );
  6655. } else {
  6656. if ( typeof array.length === "number" ) {
  6657. for ( var l = array.length; i < l; i++ ) {
  6658. ret.push( array[i] );
  6659. }
  6660. } else {
  6661. for ( ; array[i]; i++ ) {
  6662. ret.push( array[i] );
  6663. }
  6664. }
  6665. }
  6666. return ret;
  6667. };
  6668. }
  6669. var sortOrder, siblingCheck;
  6670. if ( document.documentElement.compareDocumentPosition ) {
  6671. sortOrder = function( a, b ) {
  6672. if ( a === b ) {
  6673. hasDuplicate = true;
  6674. return 0;
  6675. }
  6676. if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) {
  6677. return a.compareDocumentPosition ? -1 : 1;
  6678. }
  6679. return a.compareDocumentPosition(b) & 4 ? -1 : 1;
  6680. };
  6681. } else {
  6682. sortOrder = function( a, b ) {
  6683. // The nodes are identical, we can exit early
  6684. if ( a === b ) {
  6685. hasDuplicate = true;
  6686. return 0;
  6687. // Fallback to using sourceIndex (in IE) if it's available on both nodes
  6688. } else if ( a.sourceIndex && b.sourceIndex ) {
  6689. return a.sourceIndex - b.sourceIndex;
  6690. }
  6691. var al, bl,
  6692. ap = [],
  6693. bp = [],
  6694. aup = a.parentNode,
  6695. bup = b.parentNode,
  6696. cur = aup;
  6697. // If the nodes are siblings (or identical) we can do a quick check
  6698. if ( aup === bup ) {
  6699. return siblingCheck( a, b );
  6700. // If no parents were found then the nodes are disconnected
  6701. } else if ( !aup ) {
  6702. return -1;
  6703. } else if ( !bup ) {
  6704. return 1;
  6705. }
  6706. // Otherwise they're somewhere else in the tree so we need
  6707. // to build up a full list of the parentNodes for comparison
  6708. while ( cur ) {
  6709. ap.unshift( cur );
  6710. cur = cur.parentNode;
  6711. }
  6712. cur = bup;
  6713. while ( cur ) {
  6714. bp.unshift( cur );
  6715. cur = cur.parentNode;
  6716. }
  6717. al = ap.length;
  6718. bl = bp.length;
  6719. // Start walking down the tree looking for a discrepancy
  6720. for ( var i = 0; i < al && i < bl; i++ ) {
  6721. if ( ap[i] !== bp[i] ) {
  6722. return siblingCheck( ap[i], bp[i] );
  6723. }
  6724. }
  6725. // We ended someplace up the tree so do a sibling check
  6726. return i === al ?
  6727. siblingCheck( a, bp[i], -1 ) :
  6728. siblingCheck( ap[i], b, 1 );
  6729. };
  6730. siblingCheck = function( a, b, ret ) {
  6731. if ( a === b ) {
  6732. return ret;
  6733. }
  6734. var cur = a.nextSibling;
  6735. while ( cur ) {
  6736. if ( cur === b ) {
  6737. return -1;
  6738. }
  6739. cur = cur.nextSibling;
  6740. }
  6741. return 1;
  6742. };
  6743. }
  6744. // Check to see if the browser returns elements by name when
  6745. // querying by getElementById (and provide a workaround)
  6746. (function(){
  6747. // We're going to inject a fake input element with a specified name
  6748. var form = document.createElement("div"),
  6749. id = "script" + (new Date()).getTime(),
  6750. root = document.documentElement;
  6751. form.innerHTML = "<a name='" + id + "'/>";
  6752. // Inject it into the root element, check its status, and remove it quickly
  6753. root.insertBefore( form, root.firstChild );
  6754. // The workaround has to do additional checks after a getElementById
  6755. // Which slows things down for other browsers (hence the branching)
  6756. if ( document.getElementById( id ) ) {
  6757. Expr.find.ID = function( match, context, isXML ) {
  6758. if ( typeof context.getElementById !== "undefined" && !isXML ) {
  6759. var m = context.getElementById(match[1]);
  6760. return m ?
  6761. m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ?
  6762. [m] :
  6763. undefined :
  6764. [];
  6765. }
  6766. };
  6767. Expr.filter.ID = function( elem, match ) {
  6768. var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
  6769. return elem.nodeType === 1 && node && node.nodeValue === match;
  6770. };
  6771. }
  6772. root.removeChild( form );
  6773. // release memory in IE
  6774. root = form = null;
  6775. })();
  6776. (function(){
  6777. // Check to see if the browser returns only elements
  6778. // when doing getElementsByTagName("*")
  6779. // Create a fake element
  6780. var div = document.createElement("div");
  6781. div.appendChild( document.createComment("") );
  6782. // Make sure no comments are found
  6783. if ( div.getElementsByTagName("*").length > 0 ) {
  6784. Expr.find.TAG = function( match, context ) {
  6785. var results = context.getElementsByTagName( match[1] );
  6786. // Filter out possible comments
  6787. if ( match[1] === "*" ) {
  6788. var tmp = [];
  6789. for ( var i = 0; results[i]; i++ ) {
  6790. if ( results[i].nodeType === 1 ) {
  6791. tmp.push( results[i] );
  6792. }
  6793. }
  6794. results = tmp;
  6795. }
  6796. return results;
  6797. };
  6798. }
  6799. // Check to see if an attribute returns normalized href attributes
  6800. div.innerHTML = "<a href='#'></a>";
  6801. if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" &&
  6802. div.firstChild.getAttribute("href") !== "#" ) {
  6803. Expr.attrHandle.href = function( elem ) {
  6804. return elem.getAttribute( "href", 2 );
  6805. };
  6806. }
  6807. // release memory in IE
  6808. div = null;
  6809. })();
  6810. if ( document.querySelectorAll ) {
  6811. (function(){
  6812. var oldSizzle = Sizzle,
  6813. div = document.createElement("div"),
  6814. id = "__sizzle__";
  6815. div.innerHTML = "<p class='TEST'></p>";
  6816. // Safari can't handle uppercase or unicode characters when
  6817. // in quirks mode.
  6818. if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {
  6819. return;
  6820. }
  6821. Sizzle = function( query, context, extra, seed ) {
  6822. context = context || document;
  6823. // Only use querySelectorAll on non-XML documents
  6824. // (ID selectors don't work in non-HTML documents)
  6825. if ( !seed && !Sizzle.isXML(context) ) {
  6826. // See if we find a selector to speed up
  6827. var match = /^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec( query );
  6828. if ( match && (context.nodeType === 1 || context.nodeType === 9) ) {
  6829. // Speed-up: Sizzle("TAG")
  6830. if ( match[1] ) {
  6831. return makeArray( context.getElementsByTagName( query ), extra );
  6832. // Speed-up: Sizzle(".CLASS")
  6833. } else if ( match[2] && Expr.find.CLASS && context.getElementsByClassName ) {
  6834. return makeArray( context.getElementsByClassName( match[2] ), extra );
  6835. }
  6836. }
  6837. if ( context.nodeType === 9 ) {
  6838. // Speed-up: Sizzle("body")
  6839. // The body element only exists once, optimize finding it
  6840. if ( query === "body" && context.body ) {
  6841. return makeArray( [ context.body ], extra );
  6842. // Speed-up: Sizzle("#ID")
  6843. } else if ( match && match[3] ) {
  6844. var elem = context.getElementById( match[3] );
  6845. // Check parentNode to catch when Blackberry 4.6 returns
  6846. // nodes that are no longer in the document #6963
  6847. if ( elem && elem.parentNode ) {
  6848. // Handle the case where IE and Opera return items
  6849. // by name instead of ID
  6850. if ( elem.id === match[3] ) {
  6851. return makeArray( [ elem ], extra );
  6852. }
  6853. } else {
  6854. return makeArray( [], extra );
  6855. }
  6856. }
  6857. try {
  6858. return makeArray( context.querySelectorAll(query), extra );
  6859. } catch(qsaError) {}
  6860. // qSA works strangely on Element-rooted queries
  6861. // We can work around this by specifying an extra ID on the root
  6862. // and working up from there (Thanks to Andrew Dupont for the technique)
  6863. // IE 8 doesn't work on object elements
  6864. } else if ( context.nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
  6865. var oldContext = context,
  6866. old = context.getAttribute( "id" ),
  6867. nid = old || id,
  6868. hasParent = context.parentNode,
  6869. relativeHierarchySelector = /^\s*[+~]/.test( query );
  6870. if ( !old ) {
  6871. context.setAttribute( "id", nid );
  6872. } else {
  6873. nid = nid.replace( /'/g, "\\$&" );
  6874. }
  6875. if ( relativeHierarchySelector && hasParent ) {
  6876. context = context.parentNode;
  6877. }
  6878. try {
  6879. if ( !relativeHierarchySelector || hasParent ) {
  6880. return makeArray( context.querySelectorAll( "[id='" + nid + "'] " + query ), extra );
  6881. }
  6882. } catch(pseudoError) {
  6883. } finally {
  6884. if ( !old ) {
  6885. oldContext.removeAttribute( "id" );
  6886. }
  6887. }
  6888. }
  6889. }
  6890. return oldSizzle(query, context, extra, seed);
  6891. };
  6892. for ( var prop in oldSizzle ) {
  6893. Sizzle[ prop ] = oldSizzle[ prop ];
  6894. }
  6895. // release memory in IE
  6896. div = null;
  6897. })();
  6898. }
  6899. (function(){
  6900. var html = document.documentElement,
  6901. matches = html.matchesSelector || html.mozMatchesSelector || html.webkitMatchesSelector || html.msMatchesSelector;
  6902. if ( matches ) {
  6903. // Check to see if it's possible to do matchesSelector
  6904. // on a disconnected node (IE 9 fails this)
  6905. var disconnectedMatch = !matches.call( document.createElement( "div" ), "div" ),
  6906. pseudoWorks = false;
  6907. try {
  6908. // This should fail with an exception
  6909. // Gecko does not error, returns false instead
  6910. matches.call( document.documentElement, "[test!='']:sizzle" );
  6911. } catch( pseudoError ) {
  6912. pseudoWorks = true;
  6913. }
  6914. Sizzle.matchesSelector = function( node, expr ) {
  6915. // Make sure that attribute selectors are quoted
  6916. expr = expr.replace(/\=\s*([^'"\]]*)\s*\]/g, "='$1']");
  6917. if ( !Sizzle.isXML( node ) ) {
  6918. try {
  6919. if ( pseudoWorks || !Expr.match.PSEUDO.test( expr ) && !/!=/.test( expr ) ) {
  6920. var ret = matches.call( node, expr );
  6921. // IE 9's matchesSelector returns false on disconnected nodes
  6922. if ( ret || !disconnectedMatch ||
  6923. // As well, disconnected nodes are said to be in a document
  6924. // fragment in IE 9, so check for that
  6925. node.document && node.document.nodeType !== 11 ) {
  6926. return ret;
  6927. }
  6928. }
  6929. } catch(e) {}
  6930. }
  6931. return Sizzle(expr, null, null, [node]).length > 0;
  6932. };
  6933. }
  6934. })();
  6935. (function(){
  6936. var div = document.createElement("div");
  6937. div.innerHTML = "<div class='test e'></div><div class='test'></div>";
  6938. // Opera can't find a second classname (in 9.6)
  6939. // Also, make sure that getElementsByClassName actually exists
  6940. if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) {
  6941. return;
  6942. }
  6943. // Safari caches class attributes, doesn't catch changes (in 3.2)
  6944. div.lastChild.className = "e";
  6945. if ( div.getElementsByClassName("e").length === 1 ) {
  6946. return;
  6947. }
  6948. Expr.order.splice(1, 0, "CLASS");
  6949. Expr.find.CLASS = function( match, context, isXML ) {
  6950. if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {
  6951. return context.getElementsByClassName(match[1]);
  6952. }
  6953. };
  6954. // release memory in IE
  6955. div = null;
  6956. })();
  6957. function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
  6958. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  6959. var elem = checkSet[i];
  6960. if ( elem ) {
  6961. var match = false;
  6962. elem = elem[dir];
  6963. while ( elem ) {
  6964. if ( elem[ expando ] === doneName ) {
  6965. match = checkSet[elem.sizset];
  6966. break;
  6967. }
  6968. if ( elem.nodeType === 1 && !isXML ){
  6969. elem[ expando ] = doneName;
  6970. elem.sizset = i;
  6971. }
  6972. if ( elem.nodeName.toLowerCase() === cur ) {
  6973. match = elem;
  6974. break;
  6975. }
  6976. elem = elem[dir];
  6977. }
  6978. checkSet[i] = match;
  6979. }
  6980. }
  6981. }
  6982. function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
  6983. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  6984. var elem = checkSet[i];
  6985. if ( elem ) {
  6986. var match = false;
  6987. elem = elem[dir];
  6988. while ( elem ) {
  6989. if ( elem[ expando ] === doneName ) {
  6990. match = checkSet[elem.sizset];
  6991. break;
  6992. }
  6993. if ( elem.nodeType === 1 ) {
  6994. if ( !isXML ) {
  6995. elem[ expando ] = doneName;
  6996. elem.sizset = i;
  6997. }
  6998. if ( typeof cur !== "string" ) {
  6999. if ( elem === cur ) {
  7000. match = true;
  7001. break;
  7002. }
  7003. } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
  7004. match = elem;
  7005. break;
  7006. }
  7007. }
  7008. elem = elem[dir];
  7009. }
  7010. checkSet[i] = match;
  7011. }
  7012. }
  7013. }
  7014. if ( document.documentElement.contains ) {
  7015. Sizzle.contains = function( a, b ) {
  7016. return a !== b && (a.contains ? a.contains(b) : true);
  7017. };
  7018. } else if ( document.documentElement.compareDocumentPosition ) {
  7019. Sizzle.contains = function( a, b ) {
  7020. return !!(a.compareDocumentPosition(b) & 16);
  7021. };
  7022. } else {
  7023. Sizzle.contains = function() {
  7024. return false;
  7025. };
  7026. }
  7027. Sizzle.isXML = function( elem ) {
  7028. // documentElement is verified for cases where it doesn't yet exist
  7029. // (such as loading iframes in IE - #4833)
  7030. var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement;
  7031. return documentElement ? documentElement.nodeName !== "HTML" : false;
  7032. };
  7033. var posProcess = function( selector, context, seed ) {
  7034. var match,
  7035. tmpSet = [],
  7036. later = "",
  7037. root = context.nodeType ? [context] : context;
  7038. // Position selectors must be done after the filter
  7039. // And so must :not(positional) so we move all PSEUDOs to the end
  7040. while ( (match = Expr.match.PSEUDO.exec( selector )) ) {
  7041. later += match[0];
  7042. selector = selector.replace( Expr.match.PSEUDO, "" );
  7043. }
  7044. selector = Expr.relative[selector] ? selector + "*" : selector;
  7045. for ( var i = 0, l = root.length; i < l; i++ ) {
  7046. Sizzle( selector, root[i], tmpSet, seed );
  7047. }
  7048. return Sizzle.filter( later, tmpSet );
  7049. };
  7050. // EXPOSE
  7051. window.tinymce.dom.Sizzle = Sizzle;
  7052. })();
  7053. (function(tinymce) {
  7054. tinymce.dom.Element = function(id, settings) {
  7055. var t = this, dom, el;
  7056. t.settings = settings = settings || {};
  7057. t.id = id;
  7058. t.dom = dom = settings.dom || tinymce.DOM;
  7059. // Only IE leaks DOM references, this is a lot faster
  7060. if (!tinymce.isIE)
  7061. el = dom.get(t.id);
  7062. tinymce.each(
  7063. ('getPos,getRect,getParent,add,setStyle,getStyle,setStyles,' +
  7064. 'setAttrib,setAttribs,getAttrib,addClass,removeClass,' +
  7065. 'hasClass,getOuterHTML,setOuterHTML,remove,show,hide,' +
  7066. 'isHidden,setHTML,get').split(/,/), function(k) {
  7067. t[k] = function() {
  7068. var a = [id], i;
  7069. for (i = 0; i < arguments.length; i++)
  7070. a.push(arguments[i]);
  7071. a = dom[k].apply(dom, a);
  7072. t.update(k);
  7073. return a;
  7074. };
  7075. }
  7076. );
  7077. tinymce.extend(t, {
  7078. on : function(n, f, s) {
  7079. return tinymce.dom.Event.add(t.id, n, f, s);
  7080. },
  7081. getXY : function() {
  7082. return {
  7083. x : parseInt(t.getStyle('left')),
  7084. y : parseInt(t.getStyle('top'))
  7085. };
  7086. },
  7087. getSize : function() {
  7088. var n = dom.get(t.id);
  7089. return {
  7090. w : parseInt(t.getStyle('width') || n.clientWidth),
  7091. h : parseInt(t.getStyle('height') || n.clientHeight)
  7092. };
  7093. },
  7094. moveTo : function(x, y) {
  7095. t.setStyles({left : x, top : y});
  7096. },
  7097. moveBy : function(x, y) {
  7098. var p = t.getXY();
  7099. t.moveTo(p.x + x, p.y + y);
  7100. },
  7101. resizeTo : function(w, h) {
  7102. t.setStyles({width : w, height : h});
  7103. },
  7104. resizeBy : function(w, h) {
  7105. var s = t.getSize();
  7106. t.resizeTo(s.w + w, s.h + h);
  7107. },
  7108. update : function(k) {
  7109. var b;
  7110. if (tinymce.isIE6 && settings.blocker) {
  7111. k = k || '';
  7112. // Ignore getters
  7113. if (k.indexOf('get') === 0 || k.indexOf('has') === 0 || k.indexOf('is') === 0)
  7114. return;
  7115. // Remove blocker on remove
  7116. if (k == 'remove') {
  7117. dom.remove(t.blocker);
  7118. return;
  7119. }
  7120. if (!t.blocker) {
  7121. t.blocker = dom.uniqueId();
  7122. b = dom.add(settings.container || dom.getRoot(), 'iframe', {id : t.blocker, style : 'position:absolute;', frameBorder : 0, src : 'javascript:""'});
  7123. dom.setStyle(b, 'opacity', 0);
  7124. } else
  7125. b = dom.get(t.blocker);
  7126. dom.setStyles(b, {
  7127. left : t.getStyle('left', 1),
  7128. top : t.getStyle('top', 1),
  7129. width : t.getStyle('width', 1),
  7130. height : t.getStyle('height', 1),
  7131. display : t.getStyle('display', 1),
  7132. zIndex : parseInt(t.getStyle('zIndex', 1) || 0) - 1
  7133. });
  7134. }
  7135. }
  7136. });
  7137. };
  7138. })(tinymce);
  7139. (function(tinymce) {
  7140. function trimNl(s) {
  7141. return s.replace(/[\n\r]+/g, '');
  7142. };
  7143. // Shorten names
  7144. var is = tinymce.is, isIE = tinymce.isIE, each = tinymce.each, TreeWalker = tinymce.dom.TreeWalker;
  7145. tinymce.create('tinymce.dom.Selection', {
  7146. Selection : function(dom, win, serializer, editor) {
  7147. var t = this;
  7148. t.dom = dom;
  7149. t.win = win;
  7150. t.serializer = serializer;
  7151. t.editor = editor;
  7152. // Add events
  7153. each([
  7154. 'onBeforeSetContent',
  7155. 'onBeforeGetContent',
  7156. 'onSetContent',
  7157. 'onGetContent'
  7158. ], function(e) {
  7159. t[e] = new tinymce.util.Dispatcher(t);
  7160. });
  7161. // No W3C Range support
  7162. if (!t.win.getSelection)
  7163. t.tridentSel = new tinymce.dom.TridentSelection(t);
  7164. if (tinymce.isIE && dom.boxModel)
  7165. this._fixIESelection();
  7166. // Prevent leaks
  7167. tinymce.addUnload(t.destroy, t);
  7168. },
  7169. setCursorLocation: function(node, offset) {
  7170. var t = this; var r = t.dom.createRng();
  7171. r.setStart(node, offset);
  7172. r.setEnd(node, offset);
  7173. t.setRng(r);
  7174. t.collapse(false);
  7175. },
  7176. getContent : function(s) {
  7177. var t = this, r = t.getRng(), e = t.dom.create("body"), se = t.getSel(), wb, wa, n;
  7178. s = s || {};
  7179. wb = wa = '';
  7180. s.get = true;
  7181. s.format = s.format || 'html';
  7182. s.forced_root_block = '';
  7183. t.onBeforeGetContent.dispatch(t, s);
  7184. if (s.format == 'text')
  7185. return t.isCollapsed() ? '' : (r.text || (se.toString ? se.toString() : ''));
  7186. if (r.cloneContents) {
  7187. n = r.cloneContents();
  7188. if (n)
  7189. e.appendChild(n);
  7190. } else if (is(r.item) || is(r.htmlText)) {
  7191. // IE will produce invalid markup if elements are present that
  7192. // it doesn't understand like custom elements or HTML5 elements.
  7193. // Adding a BR in front of the contents and then remoiving it seems to fix it though.
  7194. e.innerHTML = '<br>' + (r.item ? r.item(0).outerHTML : r.htmlText);
  7195. e.removeChild(e.firstChild);
  7196. } else
  7197. e.innerHTML = r.toString();
  7198. // Keep whitespace before and after
  7199. if (/^\s/.test(e.innerHTML))
  7200. wb = ' ';
  7201. if (/\s+$/.test(e.innerHTML))
  7202. wa = ' ';
  7203. s.getInner = true;
  7204. s.content = t.isCollapsed() ? '' : wb + t.serializer.serialize(e, s) + wa;
  7205. t.onGetContent.dispatch(t, s);
  7206. return s.content;
  7207. },
  7208. setContent : function(content, args) {
  7209. var self = this, rng = self.getRng(), caretNode, doc = self.win.document, frag, temp;
  7210. args = args || {format : 'html'};
  7211. args.set = true;
  7212. content = args.content = content;
  7213. // Dispatch before set content event
  7214. if (!args.no_events)
  7215. self.onBeforeSetContent.dispatch(self, args);
  7216. content = args.content;
  7217. if (rng.insertNode) {
  7218. // Make caret marker since insertNode places the caret in the beginning of text after insert
  7219. content += '<span id="__caret">_</span>';
  7220. // Delete and insert new node
  7221. if (rng.startContainer == doc && rng.endContainer == doc) {
  7222. // WebKit will fail if the body is empty since the range is then invalid and it can't insert contents
  7223. doc.body.innerHTML = content;
  7224. } else {
  7225. rng.deleteContents();
  7226. if (doc.body.childNodes.length === 0) {
  7227. doc.body.innerHTML = content;
  7228. } else {
  7229. // createContextualFragment doesn't exists in IE 9 DOMRanges
  7230. if (rng.createContextualFragment) {
  7231. rng.insertNode(rng.createContextualFragment(content));
  7232. } else {
  7233. // Fake createContextualFragment call in IE 9
  7234. frag = doc.createDocumentFragment();
  7235. temp = doc.createElement('div');
  7236. frag.appendChild(temp);
  7237. temp.outerHTML = content;
  7238. rng.insertNode(frag);
  7239. }
  7240. }
  7241. }
  7242. // Move to caret marker
  7243. caretNode = self.dom.get('__caret');
  7244. // Make sure we wrap it compleatly, Opera fails with a simple select call
  7245. rng = doc.createRange();
  7246. rng.setStartBefore(caretNode);
  7247. rng.setEndBefore(caretNode);
  7248. self.setRng(rng);
  7249. // Remove the caret position
  7250. self.dom.remove('__caret');
  7251. try {
  7252. self.setRng(rng);
  7253. } catch (ex) {
  7254. // Might fail on Opera for some odd reason
  7255. }
  7256. } else {
  7257. if (rng.item) {
  7258. // Delete content and get caret text selection
  7259. doc.execCommand('Delete', false, null);
  7260. rng = self.getRng();
  7261. }
  7262. // Explorer removes spaces from the beginning of pasted contents
  7263. if (/^\s+/.test(content)) {
  7264. rng.pasteHTML('<span id="__mce_tmp">_</span>' + content);
  7265. self.dom.remove('__mce_tmp');
  7266. } else
  7267. rng.pasteHTML(content);
  7268. }
  7269. // Dispatch set content event
  7270. if (!args.no_events)
  7271. self.onSetContent.dispatch(self, args);
  7272. },
  7273. getStart : function() {
  7274. var self = this, rng = self.getRng(), startElement, parentElement, checkRng, node;
  7275. if (rng.duplicate || rng.item) {
  7276. // Control selection, return first item
  7277. if (rng.item)
  7278. return rng.item(0);
  7279. // Get start element
  7280. checkRng = rng.duplicate();
  7281. checkRng.collapse(1);
  7282. startElement = checkRng.parentElement();
  7283. if (startElement.ownerDocument !== self.dom.doc) {
  7284. startElement = self.dom.getRoot();
  7285. }
  7286. // Check if range parent is inside the start element, then return the inner parent element
  7287. // This will fix issues when a single element is selected, IE would otherwise return the wrong start element
  7288. parentElement = node = rng.parentElement();
  7289. while (node = node.parentNode) {
  7290. if (node == startElement) {
  7291. startElement = parentElement;
  7292. break;
  7293. }
  7294. }
  7295. return startElement;
  7296. } else {
  7297. startElement = rng.startContainer;
  7298. if (startElement.nodeType == 1 && startElement.hasChildNodes())
  7299. startElement = startElement.childNodes[Math.min(startElement.childNodes.length - 1, rng.startOffset)];
  7300. if (startElement && startElement.nodeType == 3)
  7301. return startElement.parentNode;
  7302. return startElement;
  7303. }
  7304. },
  7305. getEnd : function() {
  7306. var self = this, rng = self.getRng(), endElement, endOffset;
  7307. if (rng.duplicate || rng.item) {
  7308. if (rng.item)
  7309. return rng.item(0);
  7310. rng = rng.duplicate();
  7311. rng.collapse(0);
  7312. endElement = rng.parentElement();
  7313. if (endElement.ownerDocument !== self.dom.doc) {
  7314. endElement = self.dom.getRoot();
  7315. }
  7316. if (endElement && endElement.nodeName == 'BODY')
  7317. return endElement.lastChild || endElement;
  7318. return endElement;
  7319. } else {
  7320. endElement = rng.endContainer;
  7321. endOffset = rng.endOffset;
  7322. if (endElement.nodeType == 1 && endElement.hasChildNodes())
  7323. endElement = endElement.childNodes[endOffset > 0 ? endOffset - 1 : endOffset];
  7324. if (endElement && endElement.nodeType == 3)
  7325. return endElement.parentNode;
  7326. return endElement;
  7327. }
  7328. },
  7329. getBookmark : function(type, normalized) {
  7330. var t = this, dom = t.dom, rng, rng2, id, collapsed, name, element, index, chr = '\uFEFF', styles;
  7331. function findIndex(name, element) {
  7332. var index = 0;
  7333. each(dom.select(name), function(node, i) {
  7334. if (node == element)
  7335. index = i;
  7336. });
  7337. return index;
  7338. };
  7339. function normalizeTableCellSelection(rng) {
  7340. function moveEndPoint(start) {
  7341. var container, offset, childNodes, prefix = start ? 'start' : 'end';
  7342. container = rng[prefix + 'Container'];
  7343. offset = rng[prefix + 'Offset'];
  7344. if (container.nodeType == 1 && container.nodeName == "TR") {
  7345. childNodes = container.childNodes;
  7346. container = childNodes[Math.min(start ? offset : offset - 1, childNodes.length - 1)];
  7347. if (container) {
  7348. offset = start ? 0 : container.childNodes.length;
  7349. rng['set' + (start ? 'Start' : 'End')](container, offset);
  7350. }
  7351. }
  7352. };
  7353. moveEndPoint(true);
  7354. moveEndPoint();
  7355. return rng;
  7356. };
  7357. function getLocation() {
  7358. var rng = t.getRng(true), root = dom.getRoot(), bookmark = {};
  7359. function getPoint(rng, start) {
  7360. var container = rng[start ? 'startContainer' : 'endContainer'],
  7361. offset = rng[start ? 'startOffset' : 'endOffset'], point = [], node, childNodes, after = 0;
  7362. if (container.nodeType == 3) {
  7363. if (normalized) {
  7364. for (node = container.previousSibling; node && node.nodeType == 3; node = node.previousSibling)
  7365. offset += node.nodeValue.length;
  7366. }
  7367. point.push(offset);
  7368. } else {
  7369. childNodes = container.childNodes;
  7370. if (offset >= childNodes.length && childNodes.length) {
  7371. after = 1;
  7372. offset = Math.max(0, childNodes.length - 1);
  7373. }
  7374. point.push(t.dom.nodeIndex(childNodes[offset], normalized) + after);
  7375. }
  7376. for (; container && container != root; container = container.parentNode)
  7377. point.push(t.dom.nodeIndex(container, normalized));
  7378. return point;
  7379. };
  7380. bookmark.start = getPoint(rng, true);
  7381. if (!t.isCollapsed())
  7382. bookmark.end = getPoint(rng);
  7383. return bookmark;
  7384. };
  7385. if (type == 2) {
  7386. if (t.tridentSel)
  7387. return t.tridentSel.getBookmark(type);
  7388. return getLocation();
  7389. }
  7390. // Handle simple range
  7391. if (type)
  7392. return {rng : t.getRng()};
  7393. rng = t.getRng();
  7394. id = dom.uniqueId();
  7395. collapsed = tinyMCE.activeEditor.selection.isCollapsed();
  7396. styles = 'overflow:hidden;line-height:0px';
  7397. // Explorer method
  7398. if (rng.duplicate || rng.item) {
  7399. // Text selection
  7400. if (!rng.item) {
  7401. rng2 = rng.duplicate();
  7402. try {
  7403. // Insert start marker
  7404. rng.collapse();
  7405. rng.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_start" style="' + styles + '">' + chr + '</span>');
  7406. // Insert end marker
  7407. if (!collapsed) {
  7408. rng2.collapse(false);
  7409. // Detect the empty space after block elements in IE and move the end back one character <p></p>] becomes <p>]</p>
  7410. rng.moveToElementText(rng2.parentElement());
  7411. if (rng.compareEndPoints('StartToEnd', rng2) === 0)
  7412. rng2.move('character', -1);
  7413. rng2.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_end" style="' + styles + '">' + chr + '</span>');
  7414. }
  7415. } catch (ex) {
  7416. // IE might throw unspecified error so lets ignore it
  7417. return null;
  7418. }
  7419. } else {
  7420. // Control selection
  7421. element = rng.item(0);
  7422. name = element.nodeName;
  7423. return {name : name, index : findIndex(name, element)};
  7424. }
  7425. } else {
  7426. element = t.getNode();
  7427. name = element.nodeName;
  7428. if (name == 'IMG')
  7429. return {name : name, index : findIndex(name, element)};
  7430. // W3C method
  7431. rng2 = normalizeTableCellSelection(rng.cloneRange());
  7432. // Insert end marker
  7433. if (!collapsed) {
  7434. rng2.collapse(false);
  7435. rng2.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_end', style : styles}, chr));
  7436. }
  7437. rng = normalizeTableCellSelection(rng);
  7438. rng.collapse(true);
  7439. rng.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_start', style : styles}, chr));
  7440. }
  7441. t.moveToBookmark({id : id, keep : 1});
  7442. return {id : id};
  7443. },
  7444. moveToBookmark : function(bookmark) {
  7445. var t = this, dom = t.dom, marker1, marker2, rng, root, startContainer, endContainer, startOffset, endOffset;
  7446. function setEndPoint(start) {
  7447. var point = bookmark[start ? 'start' : 'end'], i, node, offset, children;
  7448. if (point) {
  7449. offset = point[0];
  7450. // Find container node
  7451. for (node = root, i = point.length - 1; i >= 1; i--) {
  7452. children = node.childNodes;
  7453. if (point[i] > children.length - 1)
  7454. return;
  7455. node = children[point[i]];
  7456. }
  7457. // Move text offset to best suitable location
  7458. if (node.nodeType === 3)
  7459. offset = Math.min(point[0], node.nodeValue.length);
  7460. // Move element offset to best suitable location
  7461. if (node.nodeType === 1)
  7462. offset = Math.min(point[0], node.childNodes.length);
  7463. // Set offset within container node
  7464. if (start)
  7465. rng.setStart(node, offset);
  7466. else
  7467. rng.setEnd(node, offset);
  7468. }
  7469. return true;
  7470. };
  7471. function restoreEndPoint(suffix) {
  7472. var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev, keep = bookmark.keep;
  7473. if (marker) {
  7474. node = marker.parentNode;
  7475. if (suffix == 'start') {
  7476. if (!keep) {
  7477. idx = dom.nodeIndex(marker);
  7478. } else {
  7479. node = marker.firstChild;
  7480. idx = 1;
  7481. }
  7482. startContainer = endContainer = node;
  7483. startOffset = endOffset = idx;
  7484. } else {
  7485. if (!keep) {
  7486. idx = dom.nodeIndex(marker);
  7487. } else {
  7488. node = marker.firstChild;
  7489. idx = 1;
  7490. }
  7491. endContainer = node;
  7492. endOffset = idx;
  7493. }
  7494. if (!keep) {
  7495. prev = marker.previousSibling;
  7496. next = marker.nextSibling;
  7497. // Remove all marker text nodes
  7498. each(tinymce.grep(marker.childNodes), function(node) {
  7499. if (node.nodeType == 3)
  7500. node.nodeValue = node.nodeValue.replace(/\uFEFF/g, '');
  7501. });
  7502. // Remove marker but keep children if for example contents where inserted into the marker
  7503. // Also remove duplicated instances of the marker for example by a split operation or by WebKit auto split on paste feature
  7504. while (marker = dom.get(bookmark.id + '_' + suffix))
  7505. dom.remove(marker, 1);
  7506. // If siblings are text nodes then merge them unless it's Opera since it some how removes the node
  7507. // 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
  7508. if (prev && next && prev.nodeType == next.nodeType && prev.nodeType == 3 && !tinymce.isOpera) {
  7509. idx = prev.nodeValue.length;
  7510. prev.appendData(next.nodeValue);
  7511. dom.remove(next);
  7512. if (suffix == 'start') {
  7513. startContainer = endContainer = prev;
  7514. startOffset = endOffset = idx;
  7515. } else {
  7516. endContainer = prev;
  7517. endOffset = idx;
  7518. }
  7519. }
  7520. }
  7521. }
  7522. };
  7523. function addBogus(node) {
  7524. // Adds a bogus BR element for empty block elements
  7525. if (dom.isBlock(node) && !node.innerHTML && !isIE)
  7526. node.innerHTML = '<br data-mce-bogus="1" />';
  7527. return node;
  7528. };
  7529. if (bookmark) {
  7530. if (bookmark.start) {
  7531. rng = dom.createRng();
  7532. root = dom.getRoot();
  7533. if (t.tridentSel)
  7534. return t.tridentSel.moveToBookmark(bookmark);
  7535. if (setEndPoint(true) && setEndPoint()) {
  7536. t.setRng(rng);
  7537. }
  7538. } else if (bookmark.id) {
  7539. // Restore start/end points
  7540. restoreEndPoint('start');
  7541. restoreEndPoint('end');
  7542. if (startContainer) {
  7543. rng = dom.createRng();
  7544. rng.setStart(addBogus(startContainer), startOffset);
  7545. rng.setEnd(addBogus(endContainer), endOffset);
  7546. t.setRng(rng);
  7547. }
  7548. } else if (bookmark.name) {
  7549. t.select(dom.select(bookmark.name)[bookmark.index]);
  7550. } else if (bookmark.rng)
  7551. t.setRng(bookmark.rng);
  7552. }
  7553. },
  7554. select : function(node, content) {
  7555. var t = this, dom = t.dom, rng = dom.createRng(), idx;
  7556. function setPoint(node, start) {
  7557. var walker = new TreeWalker(node, node);
  7558. do {
  7559. // Text node
  7560. if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length !== 0) {
  7561. if (start)
  7562. rng.setStart(node, 0);
  7563. else
  7564. rng.setEnd(node, node.nodeValue.length);
  7565. return;
  7566. }
  7567. // BR element
  7568. if (node.nodeName == 'BR') {
  7569. if (start)
  7570. rng.setStartBefore(node);
  7571. else
  7572. rng.setEndBefore(node);
  7573. return;
  7574. }
  7575. } while (node = (start ? walker.next() : walker.prev()));
  7576. };
  7577. if (node) {
  7578. idx = dom.nodeIndex(node);
  7579. rng.setStart(node.parentNode, idx);
  7580. rng.setEnd(node.parentNode, idx + 1);
  7581. // Find first/last text node or BR element
  7582. if (content) {
  7583. setPoint(node, 1);
  7584. setPoint(node);
  7585. }
  7586. t.setRng(rng);
  7587. }
  7588. return node;
  7589. },
  7590. isCollapsed : function() {
  7591. var t = this, r = t.getRng(), s = t.getSel();
  7592. if (!r || r.item)
  7593. return false;
  7594. if (r.compareEndPoints)
  7595. return r.compareEndPoints('StartToEnd', r) === 0;
  7596. return !s || r.collapsed;
  7597. },
  7598. collapse : function(to_start) {
  7599. var self = this, rng = self.getRng(), node;
  7600. // Control range on IE
  7601. if (rng.item) {
  7602. node = rng.item(0);
  7603. rng = self.win.document.body.createTextRange();
  7604. rng.moveToElementText(node);
  7605. }
  7606. rng.collapse(!!to_start);
  7607. self.setRng(rng);
  7608. },
  7609. getSel : function() {
  7610. var t = this, w = this.win;
  7611. return w.getSelection ? w.getSelection() : w.document.selection;
  7612. },
  7613. getRng : function(w3c) {
  7614. var self = this, selection, rng, elm, doc = self.win.document;
  7615. // Found tridentSel object then we need to use that one
  7616. if (w3c && self.tridentSel) {
  7617. return self.tridentSel.getRangeAt(0);
  7618. }
  7619. try {
  7620. if (selection = self.getSel()) {
  7621. rng = selection.rangeCount > 0 ? selection.getRangeAt(0) : (selection.createRange ? selection.createRange() : doc.createRange());
  7622. }
  7623. } catch (ex) {
  7624. // IE throws unspecified error here if TinyMCE is placed in a frame/iframe
  7625. }
  7626. // We have W3C ranges and it's IE then fake control selection since IE9 doesn't handle that correctly yet
  7627. if (tinymce.isIE && rng && rng.setStart && doc.selection.createRange().item) {
  7628. elm = doc.selection.createRange().item(0);
  7629. rng = doc.createRange();
  7630. rng.setStartBefore(elm);
  7631. rng.setEndAfter(elm);
  7632. }
  7633. // No range found then create an empty one
  7634. // This can occur when the editor is placed in a hidden container element on Gecko
  7635. // Or on IE when there was an exception
  7636. if (!rng) {
  7637. rng = doc.createRange ? doc.createRange() : doc.body.createTextRange();
  7638. }
  7639. // If range is at start of document then move it to start of body
  7640. if (rng.setStart && rng.startContainer.nodeType === 9 && rng.collapsed) {
  7641. elm = self.dom.getRoot();
  7642. rng.setStart(elm, 0);
  7643. rng.setEnd(elm, 0);
  7644. }
  7645. if (self.selectedRange && self.explicitRange) {
  7646. if (rng.compareBoundaryPoints(rng.START_TO_START, self.selectedRange) === 0 && rng.compareBoundaryPoints(rng.END_TO_END, self.selectedRange) === 0) {
  7647. // Safari, Opera and Chrome only ever select text which causes the range to change.
  7648. // This lets us use the originally set range if the selection hasn't been changed by the user.
  7649. rng = self.explicitRange;
  7650. } else {
  7651. self.selectedRange = null;
  7652. self.explicitRange = null;
  7653. }
  7654. }
  7655. return rng;
  7656. },
  7657. setRng : function(r, forward) {
  7658. var s, t = this;
  7659. if (!t.tridentSel) {
  7660. s = t.getSel();
  7661. if (s) {
  7662. t.explicitRange = r;
  7663. try {
  7664. s.removeAllRanges();
  7665. } catch (ex) {
  7666. // IE9 might throw errors here don't know why
  7667. }
  7668. s.addRange(r);
  7669. // Forward is set to false and we have an extend function
  7670. if (forward === false && s.extend) {
  7671. s.collapse(r.endContainer, r.endOffset);
  7672. s.extend(r.startContainer, r.startOffset);
  7673. }
  7674. // adding range isn't always successful so we need to check range count otherwise an exception can occur
  7675. t.selectedRange = s.rangeCount > 0 ? s.getRangeAt(0) : null;
  7676. }
  7677. } else {
  7678. // Is W3C Range
  7679. if (r.cloneRange) {
  7680. try {
  7681. t.tridentSel.addRange(r);
  7682. return;
  7683. } catch (ex) {
  7684. //IE9 throws an error here if called before selection is placed in the editor
  7685. }
  7686. }
  7687. // Is IE specific range
  7688. try {
  7689. r.select();
  7690. } catch (ex) {
  7691. // Needed for some odd IE bug #1843306
  7692. }
  7693. }
  7694. },
  7695. setNode : function(n) {
  7696. var t = this;
  7697. t.setContent(t.dom.getOuterHTML(n));
  7698. return n;
  7699. },
  7700. getNode : function() {
  7701. var t = this, rng = t.getRng(), sel = t.getSel(), elm, start = rng.startContainer, end = rng.endContainer;
  7702. function skipEmptyTextNodes(n, forwards) {
  7703. var orig = n;
  7704. while (n && n.nodeType === 3 && n.length === 0) {
  7705. n = forwards ? n.nextSibling : n.previousSibling;
  7706. }
  7707. return n || orig;
  7708. };
  7709. // Range maybe lost after the editor is made visible again
  7710. if (!rng)
  7711. return t.dom.getRoot();
  7712. if (rng.setStart) {
  7713. elm = rng.commonAncestorContainer;
  7714. // Handle selection a image or other control like element such as anchors
  7715. if (!rng.collapsed) {
  7716. if (rng.startContainer == rng.endContainer) {
  7717. if (rng.endOffset - rng.startOffset < 2) {
  7718. if (rng.startContainer.hasChildNodes())
  7719. elm = rng.startContainer.childNodes[rng.startOffset];
  7720. }
  7721. }
  7722. // If the anchor node is a element instead of a text node then return this element
  7723. //if (tinymce.isWebKit && sel.anchorNode && sel.anchorNode.nodeType == 1)
  7724. // return sel.anchorNode.childNodes[sel.anchorOffset];
  7725. // Handle cases where the selection is immediately wrapped around a node and return that node instead of it's parent.
  7726. // This happens when you double click an underlined word in FireFox.
  7727. if (start.nodeType === 3 && end.nodeType === 3) {
  7728. if (start.length === rng.startOffset) {
  7729. start = skipEmptyTextNodes(start.nextSibling, true);
  7730. } else {
  7731. start = start.parentNode;
  7732. }
  7733. if (rng.endOffset === 0) {
  7734. end = skipEmptyTextNodes(end.previousSibling, false);
  7735. } else {
  7736. end = end.parentNode;
  7737. }
  7738. if (start && start === end)
  7739. return start;
  7740. }
  7741. }
  7742. if (elm && elm.nodeType == 3)
  7743. return elm.parentNode;
  7744. return elm;
  7745. }
  7746. return rng.item ? rng.item(0) : rng.parentElement();
  7747. },
  7748. getSelectedBlocks : function(st, en) {
  7749. var t = this, dom = t.dom, sb, eb, n, bl = [];
  7750. sb = dom.getParent(st || t.getStart(), dom.isBlock);
  7751. eb = dom.getParent(en || t.getEnd(), dom.isBlock);
  7752. if (sb)
  7753. bl.push(sb);
  7754. if (sb && eb && sb != eb) {
  7755. n = sb;
  7756. var walker = new TreeWalker(sb, dom.getRoot());
  7757. while ((n = walker.next()) && n != eb) {
  7758. if (dom.isBlock(n))
  7759. bl.push(n);
  7760. }
  7761. }
  7762. if (eb && sb != eb)
  7763. bl.push(eb);
  7764. return bl;
  7765. },
  7766. isForward: function(){
  7767. var dom = this.dom, sel = this.getSel(), anchorRange, focusRange;
  7768. // No support for selection direction then always return true
  7769. if (!sel || sel.anchorNode == null || sel.focusNode == null) {
  7770. return true;
  7771. }
  7772. anchorRange = dom.createRng();
  7773. anchorRange.setStart(sel.anchorNode, sel.anchorOffset);
  7774. anchorRange.collapse(true);
  7775. focusRange = dom.createRng();
  7776. focusRange.setStart(sel.focusNode, sel.focusOffset);
  7777. focusRange.collapse(true);
  7778. return anchorRange.compareBoundaryPoints(anchorRange.START_TO_START, focusRange) <= 0;
  7779. },
  7780. normalize : function() {
  7781. var self = this, rng, normalized, collapsed, node, sibling;
  7782. function normalizeEndPoint(start) {
  7783. var container, offset, walker, dom = self.dom, body = dom.getRoot(), node, nonEmptyElementsMap, nodeName;
  7784. function hasBrBeforeAfter(node, left) {
  7785. var walker = new TreeWalker(node, dom.getParent(node.parentNode, dom.isBlock) || body);
  7786. while (node = walker[left ? 'prev' : 'next']()) {
  7787. if (node.nodeName === "BR") {
  7788. return true;
  7789. }
  7790. }
  7791. };
  7792. // Walks the dom left/right to find a suitable text node to move the endpoint into
  7793. // It will only walk within the current parent block or body and will stop if it hits a block or a BR/IMG
  7794. function findTextNodeRelative(left, startNode) {
  7795. var walker, lastInlineElement;
  7796. startNode = startNode || container;
  7797. walker = new TreeWalker(startNode, dom.getParent(startNode.parentNode, dom.isBlock) || body);
  7798. // Walk left until we hit a text node we can move to or a block/br/img
  7799. while (node = walker[left ? 'prev' : 'next']()) {
  7800. // Found text node that has a length
  7801. if (node.nodeType === 3 && node.nodeValue.length > 0) {
  7802. container = node;
  7803. offset = left ? node.nodeValue.length : 0;
  7804. normalized = true;
  7805. return;
  7806. }
  7807. // Break if we find a block or a BR/IMG/INPUT etc
  7808. if (dom.isBlock(node) || nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  7809. return;
  7810. }
  7811. lastInlineElement = node;
  7812. }
  7813. // Only fetch the last inline element when in caret mode for now
  7814. if (collapsed && lastInlineElement) {
  7815. container = lastInlineElement;
  7816. normalized = true;
  7817. offset = 0;
  7818. }
  7819. };
  7820. container = rng[(start ? 'start' : 'end') + 'Container'];
  7821. offset = rng[(start ? 'start' : 'end') + 'Offset'];
  7822. nonEmptyElementsMap = dom.schema.getNonEmptyElements();
  7823. // If the container is a document move it to the body element
  7824. if (container.nodeType === 9) {
  7825. container = dom.getRoot();
  7826. offset = 0;
  7827. }
  7828. // If the container is body try move it into the closest text node or position
  7829. if (container === body) {
  7830. // If start is before/after a image, table etc
  7831. if (start) {
  7832. node = container.childNodes[offset > 0 ? offset - 1 : 0];
  7833. if (node) {
  7834. nodeName = node.nodeName.toLowerCase();
  7835. if (nonEmptyElementsMap[node.nodeName] || node.nodeName == "TABLE") {
  7836. return;
  7837. }
  7838. }
  7839. }
  7840. // Resolve the index
  7841. if (container.hasChildNodes()) {
  7842. container = container.childNodes[Math.min(!start && offset > 0 ? offset - 1 : offset, container.childNodes.length - 1)];
  7843. offset = 0;
  7844. // Don't walk into elements that doesn't have any child nodes like a IMG
  7845. if (container.hasChildNodes() && !/TABLE/.test(container.nodeName)) {
  7846. // Walk the DOM to find a text node to place the caret at or a BR
  7847. node = container;
  7848. walker = new TreeWalker(container, body);
  7849. do {
  7850. // Found a text node use that position
  7851. if (node.nodeType === 3 && node.nodeValue.length > 0) {
  7852. offset = start ? 0 : node.nodeValue.length;
  7853. container = node;
  7854. normalized = true;
  7855. break;
  7856. }
  7857. // Found a BR/IMG element that we can place the caret before
  7858. if (nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  7859. offset = dom.nodeIndex(node);
  7860. container = node.parentNode;
  7861. // Put caret after image when moving the end point
  7862. if (node.nodeName == "IMG" && !start) {
  7863. offset++;
  7864. }
  7865. normalized = true;
  7866. break;
  7867. }
  7868. } while (node = (start ? walker.next() : walker.prev()));
  7869. }
  7870. }
  7871. }
  7872. // Lean the caret to the left if possible
  7873. if (collapsed) {
  7874. // So this: <b>x</b><i>|x</i>
  7875. // Becomes: <b>x|</b><i>x</i>
  7876. // Seems that only gecko has issues with this
  7877. if (container.nodeType === 3 && offset === 0) {
  7878. findTextNodeRelative(true);
  7879. }
  7880. // Lean left into empty inline elements when the caret is before a BR
  7881. // So this: <i><b></b><i>|<br></i>
  7882. // Becomes: <i><b>|</b><i><br></i>
  7883. // Seems that only gecko has issues with this
  7884. if (container.nodeType === 1) {
  7885. node = container.childNodes[offset];
  7886. if(node && node.nodeName === 'BR' && !hasBrBeforeAfter(node) && !hasBrBeforeAfter(node, true)) {
  7887. findTextNodeRelative(true, container.childNodes[offset]);
  7888. }
  7889. }
  7890. }
  7891. // Lean the start of the selection right if possible
  7892. // So this: x[<b>x]</b>
  7893. // Becomes: x<b>[x]</b>
  7894. if (start && !collapsed && container.nodeType === 3 && offset === container.nodeValue.length) {
  7895. findTextNodeRelative(false);
  7896. }
  7897. // Set endpoint if it was normalized
  7898. if (normalized)
  7899. rng['set' + (start ? 'Start' : 'End')](container, offset);
  7900. };
  7901. // Normalize only on non IE browsers for now
  7902. if (tinymce.isIE)
  7903. return;
  7904. rng = self.getRng();
  7905. collapsed = rng.collapsed;
  7906. // Normalize the end points
  7907. normalizeEndPoint(true);
  7908. if (!collapsed)
  7909. normalizeEndPoint();
  7910. // Set the selection if it was normalized
  7911. if (normalized) {
  7912. // If it was collapsed then make sure it still is
  7913. if (collapsed) {
  7914. rng.collapse(true);
  7915. }
  7916. //console.log(self.dom.dumpRng(rng));
  7917. self.setRng(rng, self.isForward());
  7918. }
  7919. },
  7920. selectorChanged: function(selector, callback) {
  7921. var self = this, currentSelectors;
  7922. if (!self.selectorChangedData) {
  7923. self.selectorChangedData = {};
  7924. currentSelectors = {};
  7925. self.editor.onNodeChange.addToTop(function(ed, cm, node) {
  7926. var dom = self.dom, parents = dom.getParents(node, null, dom.getRoot()), matchedSelectors = {};
  7927. // Check for new matching selectors
  7928. each(self.selectorChangedData, function(callbacks, selector) {
  7929. each(parents, function(node) {
  7930. if (dom.is(node, selector)) {
  7931. if (!currentSelectors[selector]) {
  7932. // Execute callbacks
  7933. each(callbacks, function(callback) {
  7934. callback(true, {node: node, selector: selector, parents: parents});
  7935. });
  7936. currentSelectors[selector] = callbacks;
  7937. }
  7938. matchedSelectors[selector] = callbacks;
  7939. return false;
  7940. }
  7941. });
  7942. });
  7943. // Check if current selectors still match
  7944. each(currentSelectors, function(callbacks, selector) {
  7945. if (!matchedSelectors[selector]) {
  7946. delete currentSelectors[selector];
  7947. each(callbacks, function(callback) {
  7948. callback(false, {node: node, selector: selector, parents: parents});
  7949. });
  7950. }
  7951. });
  7952. });
  7953. }
  7954. // Add selector listeners
  7955. if (!self.selectorChangedData[selector]) {
  7956. self.selectorChangedData[selector] = [];
  7957. }
  7958. self.selectorChangedData[selector].push(callback);
  7959. return self;
  7960. },
  7961. destroy : function(manual) {
  7962. var self = this;
  7963. self.win = null;
  7964. // Manual destroy then remove unload handler
  7965. if (!manual)
  7966. tinymce.removeUnload(self.destroy);
  7967. },
  7968. // IE has an issue where you can't select/move the caret by clicking outside the body if the document is in standards mode
  7969. _fixIESelection : function() {
  7970. var dom = this.dom, doc = dom.doc, body = doc.body, started, startRng, htmlElm;
  7971. // Return range from point or null if it failed
  7972. function rngFromPoint(x, y) {
  7973. var rng = body.createTextRange();
  7974. try {
  7975. rng.moveToPoint(x, y);
  7976. } catch (ex) {
  7977. // IE sometimes throws and exception, so lets just ignore it
  7978. rng = null;
  7979. }
  7980. return rng;
  7981. };
  7982. // Fires while the selection is changing
  7983. function selectionChange(e) {
  7984. var pointRng;
  7985. // Check if the button is down or not
  7986. if (e.button) {
  7987. // Create range from mouse position
  7988. pointRng = rngFromPoint(e.x, e.y);
  7989. if (pointRng) {
  7990. // Check if pointRange is before/after selection then change the endPoint
  7991. if (pointRng.compareEndPoints('StartToStart', startRng) > 0)
  7992. pointRng.setEndPoint('StartToStart', startRng);
  7993. else
  7994. pointRng.setEndPoint('EndToEnd', startRng);
  7995. pointRng.select();
  7996. }
  7997. } else
  7998. endSelection();
  7999. }
  8000. // Removes listeners
  8001. function endSelection() {
  8002. var rng = doc.selection.createRange();
  8003. // If the range is collapsed then use the last start range
  8004. if (startRng && !rng.item && rng.compareEndPoints('StartToEnd', rng) === 0)
  8005. startRng.select();
  8006. dom.unbind(doc, 'mouseup', endSelection);
  8007. dom.unbind(doc, 'mousemove', selectionChange);
  8008. startRng = started = 0;
  8009. };
  8010. // Make HTML element unselectable since we are going to handle selection by hand
  8011. doc.documentElement.unselectable = true;
  8012. // Detect when user selects outside BODY
  8013. dom.bind(doc, ['mousedown', 'contextmenu'], function(e) {
  8014. if (e.target.nodeName === 'HTML') {
  8015. if (started)
  8016. endSelection();
  8017. // Detect vertical scrollbar, since IE will fire a mousedown on the scrollbar and have target set as HTML
  8018. htmlElm = doc.documentElement;
  8019. if (htmlElm.scrollHeight > htmlElm.clientHeight)
  8020. return;
  8021. started = 1;
  8022. // Setup start position
  8023. startRng = rngFromPoint(e.x, e.y);
  8024. if (startRng) {
  8025. // Listen for selection change events
  8026. dom.bind(doc, 'mouseup', endSelection);
  8027. dom.bind(doc, 'mousemove', selectionChange);
  8028. dom.win.focus();
  8029. startRng.select();
  8030. }
  8031. }
  8032. });
  8033. }
  8034. });
  8035. })(tinymce);
  8036. (function(tinymce) {
  8037. tinymce.dom.Serializer = function(settings, dom, schema) {
  8038. var onPreProcess, onPostProcess, isIE = tinymce.isIE, each = tinymce.each, htmlParser;
  8039. // Support the old apply_source_formatting option
  8040. if (!settings.apply_source_formatting)
  8041. settings.indent = false;
  8042. // Default DOM and Schema if they are undefined
  8043. dom = dom || tinymce.DOM;
  8044. schema = schema || new tinymce.html.Schema(settings);
  8045. settings.entity_encoding = settings.entity_encoding || 'named';
  8046. settings.remove_trailing_brs = "remove_trailing_brs" in settings ? settings.remove_trailing_brs : true;
  8047. onPreProcess = new tinymce.util.Dispatcher(self);
  8048. onPostProcess = new tinymce.util.Dispatcher(self);
  8049. htmlParser = new tinymce.html.DomParser(settings, schema);
  8050. // Convert move data-mce-src, data-mce-href and data-mce-style into nodes or process them if needed
  8051. htmlParser.addAttributeFilter('src,href,style', function(nodes, name) {
  8052. var i = nodes.length, node, value, internalName = 'data-mce-' + name, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope, undef;
  8053. while (i--) {
  8054. node = nodes[i];
  8055. value = node.attributes.map[internalName];
  8056. if (value !== undef) {
  8057. // Set external name to internal value and remove internal
  8058. node.attr(name, value.length > 0 ? value : null);
  8059. node.attr(internalName, null);
  8060. } else {
  8061. // No internal attribute found then convert the value we have in the DOM
  8062. value = node.attributes.map[name];
  8063. if (name === "style")
  8064. value = dom.serializeStyle(dom.parseStyle(value), node.name);
  8065. else if (urlConverter)
  8066. value = urlConverter.call(urlConverterScope, value, name, node.name);
  8067. node.attr(name, value.length > 0 ? value : null);
  8068. }
  8069. }
  8070. });
  8071. // Remove internal classes mceItem<..> or mceSelected
  8072. htmlParser.addAttributeFilter('class', function(nodes, name) {
  8073. var i = nodes.length, node, value;
  8074. while (i--) {
  8075. node = nodes[i];
  8076. value = node.attr('class').replace(/(?:^|\s)mce(Item\w+|Selected)(?!\S)/g, '');
  8077. node.attr('class', value.length > 0 ? value : null);
  8078. }
  8079. });
  8080. // Remove bookmark elements
  8081. htmlParser.addAttributeFilter('data-mce-type', function(nodes, name, args) {
  8082. var i = nodes.length, node;
  8083. while (i--) {
  8084. node = nodes[i];
  8085. if (node.attributes.map['data-mce-type'] === 'bookmark' && !args.cleanup)
  8086. node.remove();
  8087. }
  8088. });
  8089. // Remove expando attributes
  8090. htmlParser.addAttributeFilter('data-mce-expando', function(nodes, name, args) {
  8091. var i = nodes.length;
  8092. while (i--) {
  8093. nodes[i].attr(name, null);
  8094. }
  8095. });
  8096. // Force script into CDATA sections and remove the mce- prefix also add comments around styles
  8097. htmlParser.addNodeFilter('script,style', function(nodes, name) {
  8098. var i = nodes.length, node, value;
  8099. function trim(value) {
  8100. return value.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n')
  8101. .replace(/^[\r\n]*|[\r\n]*$/g, '')
  8102. .replace(/^\s*((<!--)?(\s*\/\/)?\s*<!\[CDATA\[|(<!--\s*)?\/\*\s*<!\[CDATA\[\s*\*\/|(\/\/)?\s*<!--|\/\*\s*<!--\s*\*\/)\s*[\r\n]*/gi, '')
  8103. .replace(/\s*(\/\*\s*\]\]>\s*\*\/(-->)?|\s*\/\/\s*\]\]>(-->)?|\/\/\s*(-->)?|\]\]>|\/\*\s*-->\s*\*\/|\s*-->\s*)\s*$/g, '');
  8104. };
  8105. while (i--) {
  8106. node = nodes[i];
  8107. value = node.firstChild ? node.firstChild.value : '';
  8108. if (name === "script") {
  8109. // Remove mce- prefix from script elements
  8110. node.attr('type', (node.attr('type') || 'text/javascript').replace(/^mce\-/, ''));
  8111. if (value.length > 0)
  8112. node.firstChild.value = '// <![CDATA[\n' + trim(value) + '\n// ]]>';
  8113. } else {
  8114. if (value.length > 0)
  8115. node.firstChild.value = '<!--\n' + trim(value) + '\n-->';
  8116. }
  8117. }
  8118. });
  8119. // Convert comments to cdata and handle protected comments
  8120. htmlParser.addNodeFilter('#comment', function(nodes, name) {
  8121. var i = nodes.length, node;
  8122. while (i--) {
  8123. node = nodes[i];
  8124. if (node.value.indexOf('[CDATA[') === 0) {
  8125. node.name = '#cdata';
  8126. node.type = 4;
  8127. node.value = node.value.replace(/^\[CDATA\[|\]\]$/g, '');
  8128. } else if (node.value.indexOf('mce:protected ') === 0) {
  8129. node.name = "#text";
  8130. node.type = 3;
  8131. node.raw = true;
  8132. node.value = unescape(node.value).substr(14);
  8133. }
  8134. }
  8135. });
  8136. htmlParser.addNodeFilter('xml:namespace,input', function(nodes, name) {
  8137. var i = nodes.length, node;
  8138. while (i--) {
  8139. node = nodes[i];
  8140. if (node.type === 7)
  8141. node.remove();
  8142. else if (node.type === 1) {
  8143. if (name === "input" && !("type" in node.attributes.map))
  8144. node.attr('type', 'text');
  8145. }
  8146. }
  8147. });
  8148. // Fix list elements, TODO: Replace this later
  8149. if (settings.fix_list_elements) {
  8150. htmlParser.addNodeFilter('ul,ol', function(nodes, name) {
  8151. var i = nodes.length, node, parentNode;
  8152. while (i--) {
  8153. node = nodes[i];
  8154. parentNode = node.parent;
  8155. if (parentNode.name === 'ul' || parentNode.name === 'ol') {
  8156. if (node.prev && node.prev.name === 'li') {
  8157. node.prev.append(node);
  8158. }
  8159. }
  8160. }
  8161. });
  8162. }
  8163. // Remove internal data attributes
  8164. htmlParser.addAttributeFilter('data-mce-src,data-mce-href,data-mce-style', function(nodes, name) {
  8165. var i = nodes.length;
  8166. while (i--) {
  8167. nodes[i].attr(name, null);
  8168. }
  8169. });
  8170. // Return public methods
  8171. return {
  8172. schema : schema,
  8173. addNodeFilter : htmlParser.addNodeFilter,
  8174. addAttributeFilter : htmlParser.addAttributeFilter,
  8175. onPreProcess : onPreProcess,
  8176. onPostProcess : onPostProcess,
  8177. serialize : function(node, args) {
  8178. var impl, doc, oldDoc, htmlSerializer, content;
  8179. // Explorer won't clone contents of script and style and the
  8180. // selected index of select elements are cleared on a clone operation.
  8181. if (isIE && dom.select('script,style,select,map').length > 0) {
  8182. content = node.innerHTML;
  8183. node = node.cloneNode(false);
  8184. dom.setHTML(node, content);
  8185. } else
  8186. node = node.cloneNode(true);
  8187. // Nodes needs to be attached to something in WebKit/Opera
  8188. // Older builds of Opera crashes if you attach the node to an document created dynamically
  8189. // and since we can't feature detect a crash we need to sniff the acutal build number
  8190. // This fix will make DOM ranges and make Sizzle happy!
  8191. impl = node.ownerDocument.implementation;
  8192. if (impl.createHTMLDocument) {
  8193. // Create an empty HTML document
  8194. doc = impl.createHTMLDocument("");
  8195. // Add the element or it's children if it's a body element to the new document
  8196. each(node.nodeName == 'BODY' ? node.childNodes : [node], function(node) {
  8197. doc.body.appendChild(doc.importNode(node, true));
  8198. });
  8199. // Grab first child or body element for serialization
  8200. if (node.nodeName != 'BODY')
  8201. node = doc.body.firstChild;
  8202. else
  8203. node = doc.body;
  8204. // set the new document in DOMUtils so createElement etc works
  8205. oldDoc = dom.doc;
  8206. dom.doc = doc;
  8207. }
  8208. args = args || {};
  8209. args.format = args.format || 'html';
  8210. // Pre process
  8211. if (!args.no_events) {
  8212. args.node = node;
  8213. onPreProcess.dispatch(self, args);
  8214. }
  8215. // Setup serializer
  8216. htmlSerializer = new tinymce.html.Serializer(settings, schema);
  8217. // Parse and serialize HTML
  8218. args.content = htmlSerializer.serialize(
  8219. htmlParser.parse(tinymce.trim(args.getInner ? node.innerHTML : dom.getOuterHTML(node)), args)
  8220. );
  8221. // Replace all BOM characters for now until we can find a better solution
  8222. if (!args.cleanup)
  8223. args.content = args.content.replace(/\uFEFF|\u200B/g, '');
  8224. // Post process
  8225. if (!args.no_events)
  8226. onPostProcess.dispatch(self, args);
  8227. // Restore the old document if it was changed
  8228. if (oldDoc)
  8229. dom.doc = oldDoc;
  8230. args.node = null;
  8231. return args.content;
  8232. },
  8233. addRules : function(rules) {
  8234. schema.addValidElements(rules);
  8235. },
  8236. setRules : function(rules) {
  8237. schema.setValidElements(rules);
  8238. }
  8239. };
  8240. };
  8241. })(tinymce);
  8242. (function(tinymce) {
  8243. tinymce.dom.ScriptLoader = function(settings) {
  8244. var QUEUED = 0,
  8245. LOADING = 1,
  8246. LOADED = 2,
  8247. states = {},
  8248. queue = [],
  8249. scriptLoadedCallbacks = {},
  8250. queueLoadedCallbacks = [],
  8251. loading = 0,
  8252. undef;
  8253. function loadScript(url, callback) {
  8254. var t = this, dom = tinymce.DOM, elm, uri, loc, id;
  8255. // Execute callback when script is loaded
  8256. function done() {
  8257. dom.remove(id);
  8258. if (elm)
  8259. elm.onreadystatechange = elm.onload = elm = null;
  8260. callback();
  8261. };
  8262. function error() {
  8263. // Report the error so it's easier for people to spot loading errors
  8264. if (typeof(console) !== "undefined" && console.log)
  8265. console.log("Failed to load: " + url);
  8266. // We can't mark it as done if there is a load error since
  8267. // A) We don't want to produce 404 errors on the server and
  8268. // B) the onerror event won't fire on all browsers.
  8269. // done();
  8270. };
  8271. id = dom.uniqueId();
  8272. if (tinymce.isIE6) {
  8273. uri = new tinymce.util.URI(url);
  8274. loc = location;
  8275. // If script is from same domain and we
  8276. // use IE 6 then use XHR since it's more reliable
  8277. if (uri.host == loc.hostname && uri.port == loc.port && (uri.protocol + ':') == loc.protocol && uri.protocol.toLowerCase() != 'file') {
  8278. tinymce.util.XHR.send({
  8279. url : tinymce._addVer(uri.getURI()),
  8280. success : function(content) {
  8281. // Create new temp script element
  8282. var script = dom.create('script', {
  8283. type : 'text/javascript'
  8284. });
  8285. // Evaluate script in global scope
  8286. script.text = content;
  8287. document.getElementsByTagName('head')[0].appendChild(script);
  8288. dom.remove(script);
  8289. done();
  8290. },
  8291. error : error
  8292. });
  8293. return;
  8294. }
  8295. }
  8296. // Create new script element
  8297. elm = document.createElement('script');
  8298. elm.id = id;
  8299. elm.type = 'text/javascript';
  8300. elm.src = tinymce._addVer(url);
  8301. // Add onload listener for non IE browsers since IE9
  8302. // fires onload event before the script is parsed and executed
  8303. if (!tinymce.isIE)
  8304. elm.onload = done;
  8305. // Add onerror event will get fired on some browsers but not all of them
  8306. elm.onerror = error;
  8307. // Opera 9.60 doesn't seem to fire the onreadystate event at correctly
  8308. if (!tinymce.isOpera) {
  8309. elm.onreadystatechange = function() {
  8310. var state = elm.readyState;
  8311. // Loaded state is passed on IE 6 however there
  8312. // are known issues with this method but we can't use
  8313. // XHR in a cross domain loading
  8314. if (state == 'complete' || state == 'loaded')
  8315. done();
  8316. };
  8317. }
  8318. // Most browsers support this feature so we report errors
  8319. // for those at least to help users track their missing plugins etc
  8320. // todo: Removed since it produced error if the document is unloaded by navigating away, re-add it as an option
  8321. /*elm.onerror = function() {
  8322. alert('Failed to load: ' + url);
  8323. };*/
  8324. // Add script to document
  8325. (document.getElementsByTagName('head')[0] || document.body).appendChild(elm);
  8326. };
  8327. this.isDone = function(url) {
  8328. return states[url] == LOADED;
  8329. };
  8330. this.markDone = function(url) {
  8331. states[url] = LOADED;
  8332. };
  8333. this.add = this.load = function(url, callback, scope) {
  8334. var item, state = states[url];
  8335. // Add url to load queue
  8336. if (state == undef) {
  8337. queue.push(url);
  8338. states[url] = QUEUED;
  8339. }
  8340. if (callback) {
  8341. // Store away callback for later execution
  8342. if (!scriptLoadedCallbacks[url])
  8343. scriptLoadedCallbacks[url] = [];
  8344. scriptLoadedCallbacks[url].push({
  8345. func : callback,
  8346. scope : scope || this
  8347. });
  8348. }
  8349. };
  8350. this.loadQueue = function(callback, scope) {
  8351. this.loadScripts(queue, callback, scope);
  8352. };
  8353. this.loadScripts = function(scripts, callback, scope) {
  8354. var loadScripts;
  8355. function execScriptLoadedCallbacks(url) {
  8356. // Execute URL callback functions
  8357. tinymce.each(scriptLoadedCallbacks[url], function(callback) {
  8358. callback.func.call(callback.scope);
  8359. });
  8360. scriptLoadedCallbacks[url] = undef;
  8361. };
  8362. queueLoadedCallbacks.push({
  8363. func : callback,
  8364. scope : scope || this
  8365. });
  8366. loadScripts = function() {
  8367. var loadingScripts = tinymce.grep(scripts);
  8368. // Current scripts has been handled
  8369. scripts.length = 0;
  8370. // Load scripts that needs to be loaded
  8371. tinymce.each(loadingScripts, function(url) {
  8372. // Script is already loaded then execute script callbacks directly
  8373. if (states[url] == LOADED) {
  8374. execScriptLoadedCallbacks(url);
  8375. return;
  8376. }
  8377. // Is script not loading then start loading it
  8378. if (states[url] != LOADING) {
  8379. states[url] = LOADING;
  8380. loading++;
  8381. loadScript(url, function() {
  8382. states[url] = LOADED;
  8383. loading--;
  8384. execScriptLoadedCallbacks(url);
  8385. // Load more scripts if they where added by the recently loaded script
  8386. loadScripts();
  8387. });
  8388. }
  8389. });
  8390. // No scripts are currently loading then execute all pending queue loaded callbacks
  8391. if (!loading) {
  8392. tinymce.each(queueLoadedCallbacks, function(callback) {
  8393. callback.func.call(callback.scope);
  8394. });
  8395. queueLoadedCallbacks.length = 0;
  8396. }
  8397. };
  8398. loadScripts();
  8399. };
  8400. };
  8401. // Global script loader
  8402. tinymce.ScriptLoader = new tinymce.dom.ScriptLoader();
  8403. })(tinymce);
  8404. (function(tinymce) {
  8405. tinymce.dom.RangeUtils = function(dom) {
  8406. var INVISIBLE_CHAR = '\uFEFF';
  8407. this.walk = function(rng, callback) {
  8408. var startContainer = rng.startContainer,
  8409. startOffset = rng.startOffset,
  8410. endContainer = rng.endContainer,
  8411. endOffset = rng.endOffset,
  8412. ancestor, startPoint,
  8413. endPoint, node, parent, siblings, nodes;
  8414. // Handle table cell selection the table plugin enables
  8415. // you to fake select table cells and perform formatting actions on them
  8416. nodes = dom.select('td.mceSelected,th.mceSelected');
  8417. if (nodes.length > 0) {
  8418. tinymce.each(nodes, function(node) {
  8419. callback([node]);
  8420. });
  8421. return;
  8422. }
  8423. function exclude(nodes) {
  8424. var node;
  8425. // First node is excluded
  8426. node = nodes[0];
  8427. if (node.nodeType === 3 && node === startContainer && startOffset >= node.nodeValue.length) {
  8428. nodes.splice(0, 1);
  8429. }
  8430. // Last node is excluded
  8431. node = nodes[nodes.length - 1];
  8432. if (endOffset === 0 && nodes.length > 0 && node === endContainer && node.nodeType === 3) {
  8433. nodes.splice(nodes.length - 1, 1);
  8434. }
  8435. return nodes;
  8436. };
  8437. function collectSiblings(node, name, end_node) {
  8438. var siblings = [];
  8439. for (; node && node != end_node; node = node[name])
  8440. siblings.push(node);
  8441. return siblings;
  8442. };
  8443. function findEndPoint(node, root) {
  8444. do {
  8445. if (node.parentNode == root)
  8446. return node;
  8447. node = node.parentNode;
  8448. } while(node);
  8449. };
  8450. function walkBoundary(start_node, end_node, next) {
  8451. var siblingName = next ? 'nextSibling' : 'previousSibling';
  8452. for (node = start_node, parent = node.parentNode; node && node != end_node; node = parent) {
  8453. parent = node.parentNode;
  8454. siblings = collectSiblings(node == start_node ? node : node[siblingName], siblingName);
  8455. if (siblings.length) {
  8456. if (!next)
  8457. siblings.reverse();
  8458. callback(exclude(siblings));
  8459. }
  8460. }
  8461. };
  8462. // If index based start position then resolve it
  8463. if (startContainer.nodeType == 1 && startContainer.hasChildNodes())
  8464. startContainer = startContainer.childNodes[startOffset];
  8465. // If index based end position then resolve it
  8466. if (endContainer.nodeType == 1 && endContainer.hasChildNodes())
  8467. endContainer = endContainer.childNodes[Math.min(endOffset - 1, endContainer.childNodes.length - 1)];
  8468. // Same container
  8469. if (startContainer == endContainer)
  8470. return callback(exclude([startContainer]));
  8471. // Find common ancestor and end points
  8472. ancestor = dom.findCommonAncestor(startContainer, endContainer);
  8473. // Process left side
  8474. for (node = startContainer; node; node = node.parentNode) {
  8475. if (node === endContainer)
  8476. return walkBoundary(startContainer, ancestor, true);
  8477. if (node === ancestor)
  8478. break;
  8479. }
  8480. // Process right side
  8481. for (node = endContainer; node; node = node.parentNode) {
  8482. if (node === startContainer)
  8483. return walkBoundary(endContainer, ancestor);
  8484. if (node === ancestor)
  8485. break;
  8486. }
  8487. // Find start/end point
  8488. startPoint = findEndPoint(startContainer, ancestor) || startContainer;
  8489. endPoint = findEndPoint(endContainer, ancestor) || endContainer;
  8490. // Walk left leaf
  8491. walkBoundary(startContainer, startPoint, true);
  8492. // Walk the middle from start to end point
  8493. siblings = collectSiblings(
  8494. startPoint == startContainer ? startPoint : startPoint.nextSibling,
  8495. 'nextSibling',
  8496. endPoint == endContainer ? endPoint.nextSibling : endPoint
  8497. );
  8498. if (siblings.length)
  8499. callback(exclude(siblings));
  8500. // Walk right leaf
  8501. walkBoundary(endContainer, endPoint);
  8502. };
  8503. this.split = function(rng) {
  8504. var startContainer = rng.startContainer,
  8505. startOffset = rng.startOffset,
  8506. endContainer = rng.endContainer,
  8507. endOffset = rng.endOffset;
  8508. function splitText(node, offset) {
  8509. return node.splitText(offset);
  8510. };
  8511. // Handle single text node
  8512. if (startContainer == endContainer && startContainer.nodeType == 3) {
  8513. if (startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  8514. endContainer = splitText(startContainer, startOffset);
  8515. startContainer = endContainer.previousSibling;
  8516. if (endOffset > startOffset) {
  8517. endOffset = endOffset - startOffset;
  8518. startContainer = endContainer = splitText(endContainer, endOffset).previousSibling;
  8519. endOffset = endContainer.nodeValue.length;
  8520. startOffset = 0;
  8521. } else {
  8522. endOffset = 0;
  8523. }
  8524. }
  8525. } else {
  8526. // Split startContainer text node if needed
  8527. if (startContainer.nodeType == 3 && startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  8528. startContainer = splitText(startContainer, startOffset);
  8529. startOffset = 0;
  8530. }
  8531. // Split endContainer text node if needed
  8532. if (endContainer.nodeType == 3 && endOffset > 0 && endOffset < endContainer.nodeValue.length) {
  8533. endContainer = splitText(endContainer, endOffset).previousSibling;
  8534. endOffset = endContainer.nodeValue.length;
  8535. }
  8536. }
  8537. return {
  8538. startContainer : startContainer,
  8539. startOffset : startOffset,
  8540. endContainer : endContainer,
  8541. endOffset : endOffset
  8542. };
  8543. };
  8544. };
  8545. tinymce.dom.RangeUtils.compareRanges = function(rng1, rng2) {
  8546. if (rng1 && rng2) {
  8547. // Compare native IE ranges
  8548. if (rng1.item || rng1.duplicate) {
  8549. // Both are control ranges and the selected element matches
  8550. if (rng1.item && rng2.item && rng1.item(0) === rng2.item(0))
  8551. return true;
  8552. // Both are text ranges and the range matches
  8553. if (rng1.isEqual && rng2.isEqual && rng2.isEqual(rng1))
  8554. return true;
  8555. } else {
  8556. // Compare w3c ranges
  8557. return rng1.startContainer == rng2.startContainer && rng1.startOffset == rng2.startOffset;
  8558. }
  8559. }
  8560. return false;
  8561. };
  8562. })(tinymce);
  8563. (function(tinymce) {
  8564. var Event = tinymce.dom.Event, each = tinymce.each;
  8565. tinymce.create('tinymce.ui.KeyboardNavigation', {
  8566. KeyboardNavigation: function(settings, dom) {
  8567. var t = this, root = settings.root, items = settings.items,
  8568. enableUpDown = settings.enableUpDown, enableLeftRight = settings.enableLeftRight || !settings.enableUpDown,
  8569. excludeFromTabOrder = settings.excludeFromTabOrder,
  8570. itemFocussed, itemBlurred, rootKeydown, rootFocussed, focussedId;
  8571. dom = dom || tinymce.DOM;
  8572. itemFocussed = function(evt) {
  8573. focussedId = evt.target.id;
  8574. };
  8575. itemBlurred = function(evt) {
  8576. dom.setAttrib(evt.target.id, 'tabindex', '-1');
  8577. };
  8578. rootFocussed = function(evt) {
  8579. var item = dom.get(focussedId);
  8580. dom.setAttrib(item, 'tabindex', '0');
  8581. item.focus();
  8582. };
  8583. t.focus = function() {
  8584. dom.get(focussedId).focus();
  8585. };
  8586. t.destroy = function() {
  8587. each(items, function(item) {
  8588. var elm = dom.get(item.id);
  8589. dom.unbind(elm, 'focus', itemFocussed);
  8590. dom.unbind(elm, 'blur', itemBlurred);
  8591. });
  8592. var rootElm = dom.get(root);
  8593. dom.unbind(rootElm, 'focus', rootFocussed);
  8594. dom.unbind(rootElm, 'keydown', rootKeydown);
  8595. items = dom = root = t.focus = itemFocussed = itemBlurred = rootKeydown = rootFocussed = null;
  8596. t.destroy = function() {};
  8597. };
  8598. t.moveFocus = function(dir, evt) {
  8599. var idx = -1, controls = t.controls, newFocus;
  8600. if (!focussedId)
  8601. return;
  8602. each(items, function(item, index) {
  8603. if (item.id === focussedId) {
  8604. idx = index;
  8605. return false;
  8606. }
  8607. });
  8608. idx += dir;
  8609. if (idx < 0) {
  8610. idx = items.length - 1;
  8611. } else if (idx >= items.length) {
  8612. idx = 0;
  8613. }
  8614. newFocus = items[idx];
  8615. dom.setAttrib(focussedId, 'tabindex', '-1');
  8616. dom.setAttrib(newFocus.id, 'tabindex', '0');
  8617. dom.get(newFocus.id).focus();
  8618. if (settings.actOnFocus) {
  8619. settings.onAction(newFocus.id);
  8620. }
  8621. if (evt)
  8622. Event.cancel(evt);
  8623. };
  8624. rootKeydown = function(evt) {
  8625. 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;
  8626. switch (evt.keyCode) {
  8627. case DOM_VK_LEFT:
  8628. if (enableLeftRight) t.moveFocus(-1);
  8629. break;
  8630. case DOM_VK_RIGHT:
  8631. if (enableLeftRight) t.moveFocus(1);
  8632. break;
  8633. case DOM_VK_UP:
  8634. if (enableUpDown) t.moveFocus(-1);
  8635. break;
  8636. case DOM_VK_DOWN:
  8637. if (enableUpDown) t.moveFocus(1);
  8638. break;
  8639. case DOM_VK_ESCAPE:
  8640. if (settings.onCancel) {
  8641. settings.onCancel();
  8642. Event.cancel(evt);
  8643. }
  8644. break;
  8645. case DOM_VK_ENTER:
  8646. case DOM_VK_RETURN:
  8647. case DOM_VK_SPACE:
  8648. if (settings.onAction) {
  8649. settings.onAction(focussedId);
  8650. Event.cancel(evt);
  8651. }
  8652. break;
  8653. }
  8654. };
  8655. // Set up state and listeners for each item.
  8656. each(items, function(item, idx) {
  8657. var tabindex, elm;
  8658. if (!item.id) {
  8659. item.id = dom.uniqueId('_mce_item_');
  8660. }
  8661. elm = dom.get(item.id);
  8662. if (excludeFromTabOrder) {
  8663. dom.bind(elm, 'blur', itemBlurred);
  8664. tabindex = '-1';
  8665. } else {
  8666. tabindex = (idx === 0 ? '0' : '-1');
  8667. }
  8668. elm.setAttribute('tabindex', tabindex);
  8669. dom.bind(elm, 'focus', itemFocussed);
  8670. });
  8671. // Setup initial state for root element.
  8672. if (items[0]){
  8673. focussedId = items[0].id;
  8674. }
  8675. dom.setAttrib(root, 'tabindex', '-1');
  8676. // Setup listeners for root element.
  8677. var rootElm = dom.get(root);
  8678. dom.bind(rootElm, 'focus', rootFocussed);
  8679. dom.bind(rootElm, 'keydown', rootKeydown);
  8680. }
  8681. });
  8682. })(tinymce);
  8683. (function(tinymce) {
  8684. // Shorten class names
  8685. var DOM = tinymce.DOM, is = tinymce.is;
  8686. tinymce.create('tinymce.ui.Control', {
  8687. Control : function(id, s, editor) {
  8688. this.id = id;
  8689. this.settings = s = s || {};
  8690. this.rendered = false;
  8691. this.onRender = new tinymce.util.Dispatcher(this);
  8692. this.classPrefix = '';
  8693. this.scope = s.scope || this;
  8694. this.disabled = 0;
  8695. this.active = 0;
  8696. this.editor = editor;
  8697. },
  8698. setAriaProperty : function(property, value) {
  8699. var element = DOM.get(this.id + '_aria') || DOM.get(this.id);
  8700. if (element) {
  8701. DOM.setAttrib(element, 'aria-' + property, !!value);
  8702. }
  8703. },
  8704. focus : function() {
  8705. DOM.get(this.id).focus();
  8706. },
  8707. setDisabled : function(s) {
  8708. if (s != this.disabled) {
  8709. this.setAriaProperty('disabled', s);
  8710. this.setState('Disabled', s);
  8711. this.setState('Enabled', !s);
  8712. this.disabled = s;
  8713. }
  8714. },
  8715. isDisabled : function() {
  8716. return this.disabled;
  8717. },
  8718. setActive : function(s) {
  8719. if (s != this.active) {
  8720. this.setState('Active', s);
  8721. this.active = s;
  8722. this.setAriaProperty('pressed', s);
  8723. }
  8724. },
  8725. isActive : function() {
  8726. return this.active;
  8727. },
  8728. setState : function(c, s) {
  8729. var n = DOM.get(this.id);
  8730. c = this.classPrefix + c;
  8731. if (s)
  8732. DOM.addClass(n, c);
  8733. else
  8734. DOM.removeClass(n, c);
  8735. },
  8736. isRendered : function() {
  8737. return this.rendered;
  8738. },
  8739. renderHTML : function() {
  8740. },
  8741. renderTo : function(n) {
  8742. DOM.setHTML(n, this.renderHTML());
  8743. },
  8744. postRender : function() {
  8745. var t = this, b;
  8746. // Set pending states
  8747. if (is(t.disabled)) {
  8748. b = t.disabled;
  8749. t.disabled = -1;
  8750. t.setDisabled(b);
  8751. }
  8752. if (is(t.active)) {
  8753. b = t.active;
  8754. t.active = -1;
  8755. t.setActive(b);
  8756. }
  8757. },
  8758. remove : function() {
  8759. DOM.remove(this.id);
  8760. this.destroy();
  8761. },
  8762. destroy : function() {
  8763. tinymce.dom.Event.clear(this.id);
  8764. }
  8765. });
  8766. })(tinymce);
  8767. tinymce.create('tinymce.ui.Container:tinymce.ui.Control', {
  8768. Container : function(id, s, editor) {
  8769. this.parent(id, s, editor);
  8770. this.controls = [];
  8771. this.lookup = {};
  8772. },
  8773. add : function(c) {
  8774. this.lookup[c.id] = c;
  8775. this.controls.push(c);
  8776. return c;
  8777. },
  8778. get : function(n) {
  8779. return this.lookup[n];
  8780. }
  8781. });
  8782. tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', {
  8783. Separator : function(id, s) {
  8784. this.parent(id, s);
  8785. this.classPrefix = 'mceSeparator';
  8786. this.setDisabled(true);
  8787. },
  8788. renderHTML : function() {
  8789. return tinymce.DOM.createHTML('span', {'class' : this.classPrefix, role : 'separator', 'aria-orientation' : 'vertical', tabindex : '-1'});
  8790. }
  8791. });
  8792. (function(tinymce) {
  8793. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  8794. tinymce.create('tinymce.ui.MenuItem:tinymce.ui.Control', {
  8795. MenuItem : function(id, s) {
  8796. this.parent(id, s);
  8797. this.classPrefix = 'mceMenuItem';
  8798. },
  8799. setSelected : function(s) {
  8800. this.setState('Selected', s);
  8801. this.setAriaProperty('checked', !!s);
  8802. this.selected = s;
  8803. },
  8804. isSelected : function() {
  8805. return this.selected;
  8806. },
  8807. postRender : function() {
  8808. var t = this;
  8809. t.parent();
  8810. // Set pending state
  8811. if (is(t.selected))
  8812. t.setSelected(t.selected);
  8813. }
  8814. });
  8815. })(tinymce);
  8816. (function(tinymce) {
  8817. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  8818. tinymce.create('tinymce.ui.Menu:tinymce.ui.MenuItem', {
  8819. Menu : function(id, s) {
  8820. var t = this;
  8821. t.parent(id, s);
  8822. t.items = {};
  8823. t.collapsed = false;
  8824. t.menuCount = 0;
  8825. t.onAddItem = new tinymce.util.Dispatcher(this);
  8826. },
  8827. expand : function(d) {
  8828. var t = this;
  8829. if (d) {
  8830. walk(t, function(o) {
  8831. if (o.expand)
  8832. o.expand();
  8833. }, 'items', t);
  8834. }
  8835. t.collapsed = false;
  8836. },
  8837. collapse : function(d) {
  8838. var t = this;
  8839. if (d) {
  8840. walk(t, function(o) {
  8841. if (o.collapse)
  8842. o.collapse();
  8843. }, 'items', t);
  8844. }
  8845. t.collapsed = true;
  8846. },
  8847. isCollapsed : function() {
  8848. return this.collapsed;
  8849. },
  8850. add : function(o) {
  8851. if (!o.settings)
  8852. o = new tinymce.ui.MenuItem(o.id || DOM.uniqueId(), o);
  8853. this.onAddItem.dispatch(this, o);
  8854. return this.items[o.id] = o;
  8855. },
  8856. addSeparator : function() {
  8857. return this.add({separator : true});
  8858. },
  8859. addMenu : function(o) {
  8860. if (!o.collapse)
  8861. o = this.createMenu(o);
  8862. this.menuCount++;
  8863. return this.add(o);
  8864. },
  8865. hasMenus : function() {
  8866. return this.menuCount !== 0;
  8867. },
  8868. remove : function(o) {
  8869. delete this.items[o.id];
  8870. },
  8871. removeAll : function() {
  8872. var t = this;
  8873. walk(t, function(o) {
  8874. if (o.removeAll)
  8875. o.removeAll();
  8876. else
  8877. o.remove();
  8878. o.destroy();
  8879. }, 'items', t);
  8880. t.items = {};
  8881. },
  8882. createMenu : function(o) {
  8883. var m = new tinymce.ui.Menu(o.id || DOM.uniqueId(), o);
  8884. m.onAddItem.add(this.onAddItem.dispatch, this.onAddItem);
  8885. return m;
  8886. }
  8887. });
  8888. })(tinymce);
  8889. (function(tinymce) {
  8890. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event, Element = tinymce.dom.Element;
  8891. tinymce.create('tinymce.ui.DropMenu:tinymce.ui.Menu', {
  8892. DropMenu : function(id, s) {
  8893. s = s || {};
  8894. s.container = s.container || DOM.doc.body;
  8895. s.offset_x = s.offset_x || 0;
  8896. s.offset_y = s.offset_y || 0;
  8897. s.vp_offset_x = s.vp_offset_x || 0;
  8898. s.vp_offset_y = s.vp_offset_y || 0;
  8899. if (is(s.icons) && !s.icons)
  8900. s['class'] += ' mceNoIcons';
  8901. this.parent(id, s);
  8902. this.onShowMenu = new tinymce.util.Dispatcher(this);
  8903. this.onHideMenu = new tinymce.util.Dispatcher(this);
  8904. this.classPrefix = 'mceMenu';
  8905. },
  8906. createMenu : function(s) {
  8907. var t = this, cs = t.settings, m;
  8908. s.container = s.container || cs.container;
  8909. s.parent = t;
  8910. s.constrain = s.constrain || cs.constrain;
  8911. s['class'] = s['class'] || cs['class'];
  8912. s.vp_offset_x = s.vp_offset_x || cs.vp_offset_x;
  8913. s.vp_offset_y = s.vp_offset_y || cs.vp_offset_y;
  8914. s.keyboard_focus = cs.keyboard_focus;
  8915. m = new tinymce.ui.DropMenu(s.id || DOM.uniqueId(), s);
  8916. m.onAddItem.add(t.onAddItem.dispatch, t.onAddItem);
  8917. return m;
  8918. },
  8919. focus : function() {
  8920. var t = this;
  8921. if (t.keyboardNav) {
  8922. t.keyboardNav.focus();
  8923. }
  8924. },
  8925. update : function() {
  8926. var t = this, s = t.settings, tb = DOM.get('menu_' + t.id + '_tbl'), co = DOM.get('menu_' + t.id + '_co'), tw, th;
  8927. tw = s.max_width ? Math.min(tb.offsetWidth, s.max_width) : tb.offsetWidth;
  8928. th = s.max_height ? Math.min(tb.offsetHeight, s.max_height) : tb.offsetHeight;
  8929. if (!DOM.boxModel)
  8930. t.element.setStyles({width : tw + 2, height : th + 2});
  8931. else
  8932. t.element.setStyles({width : tw, height : th});
  8933. if (s.max_width)
  8934. DOM.setStyle(co, 'width', tw);
  8935. if (s.max_height) {
  8936. DOM.setStyle(co, 'height', th);
  8937. if (tb.clientHeight < s.max_height)
  8938. DOM.setStyle(co, 'overflow', 'hidden');
  8939. }
  8940. },
  8941. showMenu : function(x, y, px) {
  8942. var t = this, s = t.settings, co, vp = DOM.getViewPort(), w, h, mx, my, ot = 2, dm, tb, cp = t.classPrefix;
  8943. t.collapse(1);
  8944. if (t.isMenuVisible)
  8945. return;
  8946. if (!t.rendered) {
  8947. co = DOM.add(t.settings.container, t.renderNode());
  8948. each(t.items, function(o) {
  8949. o.postRender();
  8950. });
  8951. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  8952. } else
  8953. co = DOM.get('menu_' + t.id);
  8954. // Move layer out of sight unless it's Opera since it scrolls to top of page due to an bug
  8955. if (!tinymce.isOpera)
  8956. DOM.setStyles(co, {left : -0xFFFF , top : -0xFFFF});
  8957. DOM.show(co);
  8958. t.update();
  8959. x += s.offset_x || 0;
  8960. y += s.offset_y || 0;
  8961. vp.w -= 4;
  8962. vp.h -= 4;
  8963. // Move inside viewport if not submenu
  8964. if (s.constrain) {
  8965. w = co.clientWidth - ot;
  8966. h = co.clientHeight - ot;
  8967. mx = vp.x + vp.w;
  8968. my = vp.y + vp.h;
  8969. if ((x + s.vp_offset_x + w) > mx)
  8970. x = px ? px - w : Math.max(0, (mx - s.vp_offset_x) - w);
  8971. if ((y + s.vp_offset_y + h) > my)
  8972. y = Math.max(0, (my - s.vp_offset_y) - h);
  8973. }
  8974. DOM.setStyles(co, {left : x , top : y});
  8975. t.element.update();
  8976. t.isMenuVisible = 1;
  8977. t.mouseClickFunc = Event.add(co, 'click', function(e) {
  8978. var m;
  8979. e = e.target;
  8980. if (e && (e = DOM.getParent(e, 'tr')) && !DOM.hasClass(e, cp + 'ItemSub')) {
  8981. m = t.items[e.id];
  8982. if (m.isDisabled())
  8983. return;
  8984. dm = t;
  8985. while (dm) {
  8986. if (dm.hideMenu)
  8987. dm.hideMenu();
  8988. dm = dm.settings.parent;
  8989. }
  8990. if (m.settings.onclick)
  8991. m.settings.onclick(e);
  8992. return false; // Cancel to fix onbeforeunload problem
  8993. }
  8994. });
  8995. if (t.hasMenus()) {
  8996. t.mouseOverFunc = Event.add(co, 'mouseover', function(e) {
  8997. var m, r, mi;
  8998. e = e.target;
  8999. if (e && (e = DOM.getParent(e, 'tr'))) {
  9000. m = t.items[e.id];
  9001. if (t.lastMenu)
  9002. t.lastMenu.collapse(1);
  9003. if (m.isDisabled())
  9004. return;
  9005. if (e && DOM.hasClass(e, cp + 'ItemSub')) {
  9006. //p = DOM.getPos(s.container);
  9007. r = DOM.getRect(e);
  9008. m.showMenu((r.x + r.w - ot), r.y - ot, r.x);
  9009. t.lastMenu = m;
  9010. DOM.addClass(DOM.get(m.id).firstChild, cp + 'ItemActive');
  9011. }
  9012. }
  9013. });
  9014. }
  9015. Event.add(co, 'keydown', t._keyHandler, t);
  9016. t.onShowMenu.dispatch(t);
  9017. if (s.keyboard_focus) {
  9018. t._setupKeyboardNav();
  9019. }
  9020. },
  9021. hideMenu : function(c) {
  9022. var t = this, co = DOM.get('menu_' + t.id), e;
  9023. if (!t.isMenuVisible)
  9024. return;
  9025. if (t.keyboardNav) t.keyboardNav.destroy();
  9026. Event.remove(co, 'mouseover', t.mouseOverFunc);
  9027. Event.remove(co, 'click', t.mouseClickFunc);
  9028. Event.remove(co, 'keydown', t._keyHandler);
  9029. DOM.hide(co);
  9030. t.isMenuVisible = 0;
  9031. if (!c)
  9032. t.collapse(1);
  9033. if (t.element)
  9034. t.element.hide();
  9035. if (e = DOM.get(t.id))
  9036. DOM.removeClass(e.firstChild, t.classPrefix + 'ItemActive');
  9037. t.onHideMenu.dispatch(t);
  9038. },
  9039. add : function(o) {
  9040. var t = this, co;
  9041. o = t.parent(o);
  9042. if (t.isRendered && (co = DOM.get('menu_' + t.id)))
  9043. t._add(DOM.select('tbody', co)[0], o);
  9044. return o;
  9045. },
  9046. collapse : function(d) {
  9047. this.parent(d);
  9048. this.hideMenu(1);
  9049. },
  9050. remove : function(o) {
  9051. DOM.remove(o.id);
  9052. this.destroy();
  9053. return this.parent(o);
  9054. },
  9055. destroy : function() {
  9056. var t = this, co = DOM.get('menu_' + t.id);
  9057. if (t.keyboardNav) t.keyboardNav.destroy();
  9058. Event.remove(co, 'mouseover', t.mouseOverFunc);
  9059. Event.remove(DOM.select('a', co), 'focus', t.mouseOverFunc);
  9060. Event.remove(co, 'click', t.mouseClickFunc);
  9061. Event.remove(co, 'keydown', t._keyHandler);
  9062. if (t.element)
  9063. t.element.remove();
  9064. DOM.remove(co);
  9065. },
  9066. renderNode : function() {
  9067. var t = this, s = t.settings, n, tb, co, w;
  9068. 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'});
  9069. if (t.settings.parent) {
  9070. DOM.setAttrib(w, 'aria-parent', 'menu_' + t.settings.parent.id);
  9071. }
  9072. co = DOM.add(w, 'div', {role: 'presentation', id : 'menu_' + t.id + '_co', 'class' : t.classPrefix + (s['class'] ? ' ' + s['class'] : '')});
  9073. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  9074. if (s.menu_line)
  9075. DOM.add(co, 'span', {'class' : t.classPrefix + 'Line'});
  9076. // n = DOM.add(co, 'div', {id : 'menu_' + t.id + '_co', 'class' : 'mceMenuContainer'});
  9077. n = DOM.add(co, 'table', {role: 'presentation', id : 'menu_' + t.id + '_tbl', border : 0, cellPadding : 0, cellSpacing : 0});
  9078. tb = DOM.add(n, 'tbody');
  9079. each(t.items, function(o) {
  9080. t._add(tb, o);
  9081. });
  9082. t.rendered = true;
  9083. return w;
  9084. },
  9085. // Internal functions
  9086. _setupKeyboardNav : function(){
  9087. var contextMenu, menuItems, t=this;
  9088. contextMenu = DOM.get('menu_' + t.id);
  9089. menuItems = DOM.select('a[role=option]', 'menu_' + t.id);
  9090. menuItems.splice(0,0,contextMenu);
  9091. t.keyboardNav = new tinymce.ui.KeyboardNavigation({
  9092. root: 'menu_' + t.id,
  9093. items: menuItems,
  9094. onCancel: function() {
  9095. t.hideMenu();
  9096. },
  9097. enableUpDown: true
  9098. });
  9099. contextMenu.focus();
  9100. },
  9101. _keyHandler : function(evt) {
  9102. var t = this, e;
  9103. switch (evt.keyCode) {
  9104. case 37: // Left
  9105. if (t.settings.parent) {
  9106. t.hideMenu();
  9107. t.settings.parent.focus();
  9108. Event.cancel(evt);
  9109. }
  9110. break;
  9111. case 39: // Right
  9112. if (t.mouseOverFunc)
  9113. t.mouseOverFunc(evt);
  9114. break;
  9115. }
  9116. },
  9117. _add : function(tb, o) {
  9118. var n, s = o.settings, a, ro, it, cp = this.classPrefix, ic;
  9119. if (s.separator) {
  9120. ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'ItemSeparator'});
  9121. DOM.add(ro, 'td', {'class' : cp + 'ItemSeparator'});
  9122. if (n = ro.previousSibling)
  9123. DOM.addClass(n, 'mceLast');
  9124. return;
  9125. }
  9126. n = ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'Item ' + cp + 'ItemEnabled'});
  9127. n = it = DOM.add(n, s.titleItem ? 'th' : 'td');
  9128. n = a = DOM.add(n, 'a', {id: o.id + '_aria', role: s.titleItem ? 'presentation' : 'option', href : 'javascript:;', onclick : "return false;", onmousedown : 'return false;'});
  9129. if (s.parent) {
  9130. DOM.setAttrib(a, 'aria-haspopup', 'true');
  9131. DOM.setAttrib(a, 'aria-owns', 'menu_' + o.id);
  9132. }
  9133. DOM.addClass(it, s['class']);
  9134. // n = DOM.add(n, 'span', {'class' : 'item'});
  9135. ic = DOM.add(n, 'span', {'class' : 'mceIcon' + (s.icon ? ' mce_' + s.icon : '')});
  9136. if (s.icon_src)
  9137. DOM.add(ic, 'img', {src : s.icon_src});
  9138. n = DOM.add(n, s.element || 'span', {'class' : 'mceText', title : o.settings.title}, o.settings.title);
  9139. if (o.settings.style) {
  9140. if (typeof o.settings.style == "function")
  9141. o.settings.style = o.settings.style();
  9142. DOM.setAttrib(n, 'style', o.settings.style);
  9143. }
  9144. if (tb.childNodes.length == 1)
  9145. DOM.addClass(ro, 'mceFirst');
  9146. if ((n = ro.previousSibling) && DOM.hasClass(n, cp + 'ItemSeparator'))
  9147. DOM.addClass(ro, 'mceFirst');
  9148. if (o.collapse)
  9149. DOM.addClass(ro, cp + 'ItemSub');
  9150. if (n = ro.previousSibling)
  9151. DOM.removeClass(n, 'mceLast');
  9152. DOM.addClass(ro, 'mceLast');
  9153. }
  9154. });
  9155. })(tinymce);
  9156. (function(tinymce) {
  9157. var DOM = tinymce.DOM;
  9158. tinymce.create('tinymce.ui.Button:tinymce.ui.Control', {
  9159. Button : function(id, s, ed) {
  9160. this.parent(id, s, ed);
  9161. this.classPrefix = 'mceButton';
  9162. },
  9163. renderHTML : function() {
  9164. var cp = this.classPrefix, s = this.settings, h, l;
  9165. l = DOM.encode(s.label || '');
  9166. 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) + '">';
  9167. if (s.image && !(this.editor &&this.editor.forcedHighContrastMode) )
  9168. 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>' : '');
  9169. else
  9170. h += '<span class="mceIcon ' + s['class'] + '"></span>' + (l ? '<span class="' + cp + 'Label">' + l + '</span>' : '');
  9171. h += '<span class="mceVoiceLabel mceIconOnly" style="display: none;" id="' + this.id + '_voice">' + s.title + '</span>';
  9172. h += '</a>';
  9173. return h;
  9174. },
  9175. postRender : function() {
  9176. var t = this, s = t.settings, imgBookmark;
  9177. // In IE a large image that occupies the entire editor area will be deselected when a button is clicked, so
  9178. // need to keep the selection in case the selection is lost
  9179. if (tinymce.isIE && t.editor) {
  9180. tinymce.dom.Event.add(t.id, 'mousedown', function(e) {
  9181. var nodeName = t.editor.selection.getNode().nodeName;
  9182. imgBookmark = nodeName === 'IMG' ? t.editor.selection.getBookmark() : null;
  9183. });
  9184. }
  9185. tinymce.dom.Event.add(t.id, 'click', function(e) {
  9186. if (!t.isDisabled()) {
  9187. // restore the selection in case the selection is lost in IE
  9188. if (tinymce.isIE && t.editor && imgBookmark !== null) {
  9189. t.editor.selection.moveToBookmark(imgBookmark);
  9190. }
  9191. return s.onclick.call(s.scope, e);
  9192. }
  9193. });
  9194. tinymce.dom.Event.add(t.id, 'keyup', function(e) {
  9195. if (!t.isDisabled() && e.keyCode==tinymce.VK.SPACEBAR)
  9196. return s.onclick.call(s.scope, e);
  9197. });
  9198. }
  9199. });
  9200. })(tinymce);
  9201. (function(tinymce) {
  9202. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher, undef;
  9203. tinymce.create('tinymce.ui.ListBox:tinymce.ui.Control', {
  9204. ListBox : function(id, s, ed) {
  9205. var t = this;
  9206. t.parent(id, s, ed);
  9207. t.items = [];
  9208. t.onChange = new Dispatcher(t);
  9209. t.onPostRender = new Dispatcher(t);
  9210. t.onAdd = new Dispatcher(t);
  9211. t.onRenderMenu = new tinymce.util.Dispatcher(this);
  9212. t.classPrefix = 'mceListBox';
  9213. t.marked = {};
  9214. },
  9215. select : function(va) {
  9216. var t = this, fv, f;
  9217. t.marked = {};
  9218. if (va == undef)
  9219. return t.selectByIndex(-1);
  9220. // Is string or number make function selector
  9221. if (va && typeof(va)=="function")
  9222. f = va;
  9223. else {
  9224. f = function(v) {
  9225. return v == va;
  9226. };
  9227. }
  9228. // Do we need to do something?
  9229. if (va != t.selectedValue) {
  9230. // Find item
  9231. each(t.items, function(o, i) {
  9232. if (f(o.value)) {
  9233. fv = 1;
  9234. t.selectByIndex(i);
  9235. return false;
  9236. }
  9237. });
  9238. if (!fv)
  9239. t.selectByIndex(-1);
  9240. }
  9241. },
  9242. selectByIndex : function(idx) {
  9243. var t = this, e, o, label;
  9244. t.marked = {};
  9245. if (idx != t.selectedIndex) {
  9246. e = DOM.get(t.id + '_text');
  9247. label = DOM.get(t.id + '_voiceDesc');
  9248. o = t.items[idx];
  9249. if (o) {
  9250. t.selectedValue = o.value;
  9251. t.selectedIndex = idx;
  9252. DOM.setHTML(e, DOM.encode(o.title));
  9253. DOM.setHTML(label, t.settings.title + " - " + o.title);
  9254. DOM.removeClass(e, 'mceTitle');
  9255. DOM.setAttrib(t.id, 'aria-valuenow', o.title);
  9256. } else {
  9257. DOM.setHTML(e, DOM.encode(t.settings.title));
  9258. DOM.setHTML(label, DOM.encode(t.settings.title));
  9259. DOM.addClass(e, 'mceTitle');
  9260. t.selectedValue = t.selectedIndex = null;
  9261. DOM.setAttrib(t.id, 'aria-valuenow', t.settings.title);
  9262. }
  9263. e = 0;
  9264. }
  9265. },
  9266. mark : function(value) {
  9267. this.marked[value] = true;
  9268. },
  9269. add : function(n, v, o) {
  9270. var t = this;
  9271. o = o || {};
  9272. o = tinymce.extend(o, {
  9273. title : n,
  9274. value : v
  9275. });
  9276. t.items.push(o);
  9277. t.onAdd.dispatch(t, o);
  9278. },
  9279. getLength : function() {
  9280. return this.items.length;
  9281. },
  9282. renderHTML : function() {
  9283. var h = '', t = this, s = t.settings, cp = t.classPrefix;
  9284. 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>';
  9285. h += '<td>' + DOM.createHTML('span', {id: t.id + '_voiceDesc', 'class': 'voiceLabel', style:'display:none;'}, t.settings.title);
  9286. 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>';
  9287. 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>';
  9288. h += '</tr></tbody></table></span>';
  9289. return h;
  9290. },
  9291. showMenu : function() {
  9292. var t = this, p2, e = DOM.get(this.id), m;
  9293. if (t.isDisabled() || t.items.length === 0)
  9294. return;
  9295. if (t.menu && t.menu.isMenuVisible)
  9296. return t.hideMenu();
  9297. if (!t.isMenuRendered) {
  9298. t.renderMenu();
  9299. t.isMenuRendered = true;
  9300. }
  9301. p2 = DOM.getPos(e);
  9302. m = t.menu;
  9303. m.settings.offset_x = p2.x;
  9304. m.settings.offset_y = p2.y;
  9305. m.settings.keyboard_focus = !tinymce.isOpera; // Opera is buggy when it comes to auto focus
  9306. // Select in menu
  9307. each(t.items, function(o) {
  9308. if (m.items[o.id]) {
  9309. m.items[o.id].setSelected(0);
  9310. }
  9311. });
  9312. each(t.items, function(o) {
  9313. if (m.items[o.id] && t.marked[o.value]) {
  9314. m.items[o.id].setSelected(1);
  9315. }
  9316. if (o.value === t.selectedValue) {
  9317. m.items[o.id].setSelected(1);
  9318. }
  9319. });
  9320. m.showMenu(0, e.clientHeight);
  9321. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  9322. DOM.addClass(t.id, t.classPrefix + 'Selected');
  9323. //DOM.get(t.id + '_text').focus();
  9324. },
  9325. hideMenu : function(e) {
  9326. var t = this;
  9327. if (t.menu && t.menu.isMenuVisible) {
  9328. DOM.removeClass(t.id, t.classPrefix + 'Selected');
  9329. // Prevent double toogles by canceling the mouse click event to the button
  9330. if (e && e.type == "mousedown" && (e.target.id == t.id + '_text' || e.target.id == t.id + '_open'))
  9331. return;
  9332. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  9333. DOM.removeClass(t.id, t.classPrefix + 'Selected');
  9334. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  9335. t.menu.hideMenu();
  9336. }
  9337. }
  9338. },
  9339. renderMenu : function() {
  9340. var t = this, m;
  9341. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  9342. menu_line : 1,
  9343. 'class' : t.classPrefix + 'Menu mceNoIcons',
  9344. max_width : 250,
  9345. max_height : 150
  9346. });
  9347. m.onHideMenu.add(function() {
  9348. t.hideMenu();
  9349. t.focus();
  9350. });
  9351. m.add({
  9352. title : t.settings.title,
  9353. 'class' : 'mceMenuItemTitle',
  9354. onclick : function() {
  9355. if (t.settings.onselect('') !== false)
  9356. t.select(''); // Must be runned after
  9357. }
  9358. });
  9359. each(t.items, function(o) {
  9360. // No value then treat it as a title
  9361. if (o.value === undef) {
  9362. m.add({
  9363. title : o.title,
  9364. role : "option",
  9365. 'class' : 'mceMenuItemTitle',
  9366. onclick : function() {
  9367. if (t.settings.onselect('') !== false)
  9368. t.select(''); // Must be runned after
  9369. }
  9370. });
  9371. } else {
  9372. o.id = DOM.uniqueId();
  9373. o.role= "option";
  9374. o.onclick = function() {
  9375. if (t.settings.onselect(o.value) !== false)
  9376. t.select(o.value); // Must be runned after
  9377. };
  9378. m.add(o);
  9379. }
  9380. });
  9381. t.onRenderMenu.dispatch(t, m);
  9382. t.menu = m;
  9383. },
  9384. postRender : function() {
  9385. var t = this, cp = t.classPrefix;
  9386. Event.add(t.id, 'click', t.showMenu, t);
  9387. Event.add(t.id, 'keydown', function(evt) {
  9388. if (evt.keyCode == 32) { // Space
  9389. t.showMenu(evt);
  9390. Event.cancel(evt);
  9391. }
  9392. });
  9393. Event.add(t.id, 'focus', function() {
  9394. if (!t._focused) {
  9395. t.keyDownHandler = Event.add(t.id, 'keydown', function(e) {
  9396. if (e.keyCode == 40) {
  9397. t.showMenu();
  9398. Event.cancel(e);
  9399. }
  9400. });
  9401. t.keyPressHandler = Event.add(t.id, 'keypress', function(e) {
  9402. var v;
  9403. if (e.keyCode == 13) {
  9404. // Fake select on enter
  9405. v = t.selectedValue;
  9406. t.selectedValue = null; // Needs to be null to fake change
  9407. Event.cancel(e);
  9408. t.settings.onselect(v);
  9409. }
  9410. });
  9411. }
  9412. t._focused = 1;
  9413. });
  9414. Event.add(t.id, 'blur', function() {
  9415. Event.remove(t.id, 'keydown', t.keyDownHandler);
  9416. Event.remove(t.id, 'keypress', t.keyPressHandler);
  9417. t._focused = 0;
  9418. });
  9419. // Old IE doesn't have hover on all elements
  9420. if (tinymce.isIE6 || !DOM.boxModel) {
  9421. Event.add(t.id, 'mouseover', function() {
  9422. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  9423. DOM.addClass(t.id, cp + 'Hover');
  9424. });
  9425. Event.add(t.id, 'mouseout', function() {
  9426. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  9427. DOM.removeClass(t.id, cp + 'Hover');
  9428. });
  9429. }
  9430. t.onPostRender.dispatch(t, DOM.get(t.id));
  9431. },
  9432. destroy : function() {
  9433. this.parent();
  9434. Event.clear(this.id + '_text');
  9435. Event.clear(this.id + '_open');
  9436. }
  9437. });
  9438. })(tinymce);
  9439. (function(tinymce) {
  9440. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher, undef;
  9441. tinymce.create('tinymce.ui.NativeListBox:tinymce.ui.ListBox', {
  9442. NativeListBox : function(id, s) {
  9443. this.parent(id, s);
  9444. this.classPrefix = 'mceNativeListBox';
  9445. },
  9446. setDisabled : function(s) {
  9447. DOM.get(this.id).disabled = s;
  9448. this.setAriaProperty('disabled', s);
  9449. },
  9450. isDisabled : function() {
  9451. return DOM.get(this.id).disabled;
  9452. },
  9453. select : function(va) {
  9454. var t = this, fv, f;
  9455. if (va == undef)
  9456. return t.selectByIndex(-1);
  9457. // Is string or number make function selector
  9458. if (va && typeof(va)=="function")
  9459. f = va;
  9460. else {
  9461. f = function(v) {
  9462. return v == va;
  9463. };
  9464. }
  9465. // Do we need to do something?
  9466. if (va != t.selectedValue) {
  9467. // Find item
  9468. each(t.items, function(o, i) {
  9469. if (f(o.value)) {
  9470. fv = 1;
  9471. t.selectByIndex(i);
  9472. return false;
  9473. }
  9474. });
  9475. if (!fv)
  9476. t.selectByIndex(-1);
  9477. }
  9478. },
  9479. selectByIndex : function(idx) {
  9480. DOM.get(this.id).selectedIndex = idx + 1;
  9481. this.selectedValue = this.items[idx] ? this.items[idx].value : null;
  9482. },
  9483. add : function(n, v, a) {
  9484. var o, t = this;
  9485. a = a || {};
  9486. a.value = v;
  9487. if (t.isRendered())
  9488. DOM.add(DOM.get(this.id), 'option', a, n);
  9489. o = {
  9490. title : n,
  9491. value : v,
  9492. attribs : a
  9493. };
  9494. t.items.push(o);
  9495. t.onAdd.dispatch(t, o);
  9496. },
  9497. getLength : function() {
  9498. return this.items.length;
  9499. },
  9500. renderHTML : function() {
  9501. var h, t = this;
  9502. h = DOM.createHTML('option', {value : ''}, '-- ' + t.settings.title + ' --');
  9503. each(t.items, function(it) {
  9504. h += DOM.createHTML('option', {value : it.value}, it.title);
  9505. });
  9506. h = DOM.createHTML('select', {id : t.id, 'class' : 'mceNativeListBox', 'aria-labelledby': t.id + '_aria'}, h);
  9507. h += DOM.createHTML('span', {id : t.id + '_aria', 'style': 'display: none'}, t.settings.title);
  9508. return h;
  9509. },
  9510. postRender : function() {
  9511. var t = this, ch, changeListenerAdded = true;
  9512. t.rendered = true;
  9513. function onChange(e) {
  9514. var v = t.items[e.target.selectedIndex - 1];
  9515. if (v && (v = v.value)) {
  9516. t.onChange.dispatch(t, v);
  9517. if (t.settings.onselect)
  9518. t.settings.onselect(v);
  9519. }
  9520. };
  9521. Event.add(t.id, 'change', onChange);
  9522. // Accessibility keyhandler
  9523. Event.add(t.id, 'keydown', function(e) {
  9524. var bf;
  9525. Event.remove(t.id, 'change', ch);
  9526. changeListenerAdded = false;
  9527. bf = Event.add(t.id, 'blur', function() {
  9528. if (changeListenerAdded) return;
  9529. changeListenerAdded = true;
  9530. Event.add(t.id, 'change', onChange);
  9531. Event.remove(t.id, 'blur', bf);
  9532. });
  9533. //prevent default left and right keys on chrome - so that the keyboard navigation is used.
  9534. if (tinymce.isWebKit && (e.keyCode==37 ||e.keyCode==39)) {
  9535. return Event.prevent(e);
  9536. }
  9537. if (e.keyCode == 13 || e.keyCode == 32) {
  9538. onChange(e);
  9539. return Event.cancel(e);
  9540. }
  9541. });
  9542. t.onPostRender.dispatch(t, DOM.get(t.id));
  9543. }
  9544. });
  9545. })(tinymce);
  9546. (function(tinymce) {
  9547. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  9548. tinymce.create('tinymce.ui.MenuButton:tinymce.ui.Button', {
  9549. MenuButton : function(id, s, ed) {
  9550. this.parent(id, s, ed);
  9551. this.onRenderMenu = new tinymce.util.Dispatcher(this);
  9552. s.menu_container = s.menu_container || DOM.doc.body;
  9553. },
  9554. showMenu : function() {
  9555. var t = this, p1, p2, e = DOM.get(t.id), m;
  9556. if (t.isDisabled())
  9557. return;
  9558. if (!t.isMenuRendered) {
  9559. t.renderMenu();
  9560. t.isMenuRendered = true;
  9561. }
  9562. if (t.isMenuVisible)
  9563. return t.hideMenu();
  9564. p1 = DOM.getPos(t.settings.menu_container);
  9565. p2 = DOM.getPos(e);
  9566. m = t.menu;
  9567. m.settings.offset_x = p2.x;
  9568. m.settings.offset_y = p2.y;
  9569. m.settings.vp_offset_x = p2.x;
  9570. m.settings.vp_offset_y = p2.y;
  9571. m.settings.keyboard_focus = t._focused;
  9572. m.showMenu(0, e.firstChild.clientHeight);
  9573. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  9574. t.setState('Selected', 1);
  9575. t.isMenuVisible = 1;
  9576. },
  9577. renderMenu : function() {
  9578. var t = this, m;
  9579. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  9580. menu_line : 1,
  9581. 'class' : this.classPrefix + 'Menu',
  9582. icons : t.settings.icons
  9583. });
  9584. m.onHideMenu.add(function() {
  9585. t.hideMenu();
  9586. t.focus();
  9587. });
  9588. t.onRenderMenu.dispatch(t, m);
  9589. t.menu = m;
  9590. },
  9591. hideMenu : function(e) {
  9592. var t = this;
  9593. // Prevent double toogles by canceling the mouse click event to the button
  9594. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id || e.id === t.id + '_open';}))
  9595. return;
  9596. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  9597. t.setState('Selected', 0);
  9598. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  9599. if (t.menu)
  9600. t.menu.hideMenu();
  9601. }
  9602. t.isMenuVisible = 0;
  9603. },
  9604. postRender : function() {
  9605. var t = this, s = t.settings;
  9606. Event.add(t.id, 'click', function() {
  9607. if (!t.isDisabled()) {
  9608. if (s.onclick)
  9609. s.onclick(t.value);
  9610. t.showMenu();
  9611. }
  9612. });
  9613. }
  9614. });
  9615. })(tinymce);
  9616. (function(tinymce) {
  9617. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  9618. tinymce.create('tinymce.ui.SplitButton:tinymce.ui.MenuButton', {
  9619. SplitButton : function(id, s, ed) {
  9620. this.parent(id, s, ed);
  9621. this.classPrefix = 'mceSplitButton';
  9622. },
  9623. renderHTML : function() {
  9624. var h, t = this, s = t.settings, h1;
  9625. h = '<tbody><tr>';
  9626. if (s.image)
  9627. h1 = DOM.createHTML('img ', {src : s.image, role: 'presentation', 'class' : 'mceAction ' + s['class']});
  9628. else
  9629. h1 = DOM.createHTML('span', {'class' : 'mceAction ' + s['class']}, '');
  9630. h1 += DOM.createHTML('span', {'class': 'mceVoiceLabel mceIconOnly', id: t.id + '_voice', style: 'display:none;'}, s.title);
  9631. 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>';
  9632. h1 = DOM.createHTML('span', {'class' : 'mceOpen ' + s['class']}, '<span style="display:none;" class="mceIconOnly" aria-hidden="true">\u25BC</span>');
  9633. 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>';
  9634. h += '</tr></tbody>';
  9635. h = DOM.createHTML('table', { role: 'presentation', 'class' : 'mceSplitButton mceSplitButtonEnabled ' + s['class'], cellpadding : '0', cellspacing : '0', title : s.title}, h);
  9636. return DOM.createHTML('div', {id : t.id, role: 'button', tabindex: '0', 'aria-labelledby': t.id + '_voice', 'aria-haspopup': 'true'}, h);
  9637. },
  9638. postRender : function() {
  9639. var t = this, s = t.settings, activate;
  9640. if (s.onclick) {
  9641. activate = function(evt) {
  9642. if (!t.isDisabled()) {
  9643. s.onclick(t.value);
  9644. Event.cancel(evt);
  9645. }
  9646. };
  9647. Event.add(t.id + '_action', 'click', activate);
  9648. Event.add(t.id, ['click', 'keydown'], function(evt) {
  9649. var DOM_VK_SPACE = 32, DOM_VK_ENTER = 14, DOM_VK_RETURN = 13, DOM_VK_UP = 38, DOM_VK_DOWN = 40;
  9650. if ((evt.keyCode === 32 || evt.keyCode === 13 || evt.keyCode === 14) && !evt.altKey && !evt.ctrlKey && !evt.metaKey) {
  9651. activate();
  9652. Event.cancel(evt);
  9653. } else if (evt.type === 'click' || evt.keyCode === DOM_VK_DOWN) {
  9654. t.showMenu();
  9655. Event.cancel(evt);
  9656. }
  9657. });
  9658. }
  9659. Event.add(t.id + '_open', 'click', function (evt) {
  9660. t.showMenu();
  9661. Event.cancel(evt);
  9662. });
  9663. Event.add([t.id, t.id + '_open'], 'focus', function() {t._focused = 1;});
  9664. Event.add([t.id, t.id + '_open'], 'blur', function() {t._focused = 0;});
  9665. // Old IE doesn't have hover on all elements
  9666. if (tinymce.isIE6 || !DOM.boxModel) {
  9667. Event.add(t.id, 'mouseover', function() {
  9668. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  9669. DOM.addClass(t.id, 'mceSplitButtonHover');
  9670. });
  9671. Event.add(t.id, 'mouseout', function() {
  9672. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  9673. DOM.removeClass(t.id, 'mceSplitButtonHover');
  9674. });
  9675. }
  9676. },
  9677. destroy : function() {
  9678. this.parent();
  9679. Event.clear(this.id + '_action');
  9680. Event.clear(this.id + '_open');
  9681. Event.clear(this.id);
  9682. }
  9683. });
  9684. })(tinymce);
  9685. (function(tinymce) {
  9686. var DOM = tinymce.DOM, Event = tinymce.dom.Event, is = tinymce.is, each = tinymce.each;
  9687. tinymce.create('tinymce.ui.ColorSplitButton:tinymce.ui.SplitButton', {
  9688. ColorSplitButton : function(id, s, ed) {
  9689. var t = this;
  9690. t.parent(id, s, ed);
  9691. t.settings = s = tinymce.extend({
  9692. 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',
  9693. grid_width : 8,
  9694. default_color : '#888888'
  9695. }, t.settings);
  9696. t.onShowMenu = new tinymce.util.Dispatcher(t);
  9697. t.onHideMenu = new tinymce.util.Dispatcher(t);
  9698. t.value = s.default_color;
  9699. },
  9700. showMenu : function() {
  9701. var t = this, r, p, e, p2;
  9702. if (t.isDisabled())
  9703. return;
  9704. if (!t.isMenuRendered) {
  9705. t.renderMenu();
  9706. t.isMenuRendered = true;
  9707. }
  9708. if (t.isMenuVisible)
  9709. return t.hideMenu();
  9710. e = DOM.get(t.id);
  9711. DOM.show(t.id + '_menu');
  9712. DOM.addClass(e, 'mceSplitButtonSelected');
  9713. p2 = DOM.getPos(e);
  9714. DOM.setStyles(t.id + '_menu', {
  9715. left : p2.x,
  9716. top : p2.y + e.firstChild.clientHeight,
  9717. zIndex : 200000
  9718. });
  9719. e = 0;
  9720. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  9721. t.onShowMenu.dispatch(t);
  9722. if (t._focused) {
  9723. t._keyHandler = Event.add(t.id + '_menu', 'keydown', function(e) {
  9724. if (e.keyCode == 27)
  9725. t.hideMenu();
  9726. });
  9727. DOM.select('a', t.id + '_menu')[0].focus(); // Select first link
  9728. }
  9729. t.keyboardNav = new tinymce.ui.KeyboardNavigation({
  9730. root: t.id + '_menu',
  9731. items: DOM.select('a', t.id + '_menu'),
  9732. onCancel: function() {
  9733. t.hideMenu();
  9734. t.focus();
  9735. }
  9736. });
  9737. t.keyboardNav.focus();
  9738. t.isMenuVisible = 1;
  9739. },
  9740. hideMenu : function(e) {
  9741. var t = this;
  9742. if (t.isMenuVisible) {
  9743. // Prevent double toogles by canceling the mouse click event to the button
  9744. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id + '_open';}))
  9745. return;
  9746. if (!e || !DOM.getParent(e.target, '.mceSplitButtonMenu')) {
  9747. DOM.removeClass(t.id, 'mceSplitButtonSelected');
  9748. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  9749. Event.remove(t.id + '_menu', 'keydown', t._keyHandler);
  9750. DOM.hide(t.id + '_menu');
  9751. }
  9752. t.isMenuVisible = 0;
  9753. t.onHideMenu.dispatch();
  9754. t.keyboardNav.destroy();
  9755. }
  9756. },
  9757. renderMenu : function() {
  9758. var t = this, m, i = 0, s = t.settings, n, tb, tr, w, context;
  9759. 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;'});
  9760. m = DOM.add(w, 'div', {'class' : s['class'] + ' mceSplitButtonMenu'});
  9761. DOM.add(m, 'span', {'class' : 'mceMenuLine'});
  9762. n = DOM.add(m, 'table', {role: 'presentation', 'class' : 'mceColorSplitMenu'});
  9763. tb = DOM.add(n, 'tbody');
  9764. // Generate color grid
  9765. i = 0;
  9766. each(is(s.colors, 'array') ? s.colors : s.colors.split(','), function(c) {
  9767. c = c.replace(/^#/, '');
  9768. if (!i--) {
  9769. tr = DOM.add(tb, 'tr');
  9770. i = s.grid_width - 1;
  9771. }
  9772. n = DOM.add(tr, 'td');
  9773. var settings = {
  9774. href : 'javascript:;',
  9775. style : {
  9776. backgroundColor : '#' + c
  9777. },
  9778. 'title': t.editor.getLang('colors.' + c, c),
  9779. 'data-mce-color' : '#' + c
  9780. };
  9781. // adding a proper ARIA role = button causes JAWS to read things incorrectly on IE.
  9782. if (!tinymce.isIE ) {
  9783. settings.role = 'option';
  9784. }
  9785. n = DOM.add(n, 'a', settings);
  9786. if (t.editor.forcedHighContrastMode) {
  9787. n = DOM.add(n, 'canvas', { width: 16, height: 16, 'aria-hidden': 'true' });
  9788. if (n.getContext && (context = n.getContext("2d"))) {
  9789. context.fillStyle = '#' + c;
  9790. context.fillRect(0, 0, 16, 16);
  9791. } else {
  9792. // No point leaving a canvas element around if it's not supported for drawing on anyway.
  9793. DOM.remove(n);
  9794. }
  9795. }
  9796. });
  9797. if (s.more_colors_func) {
  9798. n = DOM.add(tb, 'tr');
  9799. n = DOM.add(n, 'td', {colspan : s.grid_width, 'class' : 'mceMoreColors'});
  9800. n = DOM.add(n, 'a', {role: 'option', id : t.id + '_more', href : 'javascript:;', onclick : 'return false;', 'class' : 'mceMoreColors'}, s.more_colors_title);
  9801. Event.add(n, 'click', function(e) {
  9802. s.more_colors_func.call(s.more_colors_scope || this);
  9803. return Event.cancel(e); // Cancel to fix onbeforeunload problem
  9804. });
  9805. }
  9806. DOM.addClass(m, 'mceColorSplitMenu');
  9807. // Prevent IE from scrolling and hindering click to occur #4019
  9808. Event.add(t.id + '_menu', 'mousedown', function(e) {return Event.cancel(e);});
  9809. Event.add(t.id + '_menu', 'click', function(e) {
  9810. var c;
  9811. e = DOM.getParent(e.target, 'a', tb);
  9812. if (e && e.nodeName.toLowerCase() == 'a' && (c = e.getAttribute('data-mce-color')))
  9813. t.setColor(c);
  9814. return false; // Prevent IE auto save warning
  9815. });
  9816. return w;
  9817. },
  9818. setColor : function(c) {
  9819. this.displayColor(c);
  9820. this.hideMenu();
  9821. this.settings.onselect(c);
  9822. },
  9823. displayColor : function(c) {
  9824. var t = this;
  9825. DOM.setStyle(t.id + '_preview', 'backgroundColor', c);
  9826. t.value = c;
  9827. },
  9828. postRender : function() {
  9829. var t = this, id = t.id;
  9830. t.parent();
  9831. DOM.add(id + '_action', 'div', {id : id + '_preview', 'class' : 'mceColorPreview'});
  9832. DOM.setStyle(t.id + '_preview', 'backgroundColor', t.value);
  9833. },
  9834. destroy : function() {
  9835. var self = this;
  9836. self.parent();
  9837. Event.clear(self.id + '_menu');
  9838. Event.clear(self.id + '_more');
  9839. DOM.remove(self.id + '_menu');
  9840. if (self.keyboardNav) {
  9841. self.keyboardNav.destroy();
  9842. }
  9843. }
  9844. });
  9845. })(tinymce);
  9846. (function(tinymce) {
  9847. // Shorten class names
  9848. var dom = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event;
  9849. tinymce.create('tinymce.ui.ToolbarGroup:tinymce.ui.Container', {
  9850. renderHTML : function() {
  9851. var t = this, h = [], controls = t.controls, each = tinymce.each, settings = t.settings;
  9852. h.push('<div id="' + t.id + '" role="group" aria-labelledby="' + t.id + '_voice">');
  9853. //TODO: ACC test this out - adding a role = application for getting the landmarks working well.
  9854. h.push("<span role='application'>");
  9855. h.push('<span id="' + t.id + '_voice" class="mceVoiceLabel" style="display:none;">' + dom.encode(settings.name) + '</span>');
  9856. each(controls, function(toolbar) {
  9857. h.push(toolbar.renderHTML());
  9858. });
  9859. h.push("</span>");
  9860. h.push('</div>');
  9861. return h.join('');
  9862. },
  9863. focus : function() {
  9864. var t = this;
  9865. dom.get(t.id).focus();
  9866. },
  9867. postRender : function() {
  9868. var t = this, items = [];
  9869. each(t.controls, function(toolbar) {
  9870. each (toolbar.controls, function(control) {
  9871. if (control.id) {
  9872. items.push(control);
  9873. }
  9874. });
  9875. });
  9876. t.keyNav = new tinymce.ui.KeyboardNavigation({
  9877. root: t.id,
  9878. items: items,
  9879. onCancel: function() {
  9880. //Move focus if webkit so that navigation back will read the item.
  9881. if (tinymce.isWebKit) {
  9882. dom.get(t.editor.id+"_ifr").focus();
  9883. }
  9884. t.editor.focus();
  9885. },
  9886. excludeFromTabOrder: !t.settings.tab_focus_toolbar
  9887. });
  9888. },
  9889. destroy : function() {
  9890. var self = this;
  9891. self.parent();
  9892. self.keyNav.destroy();
  9893. Event.clear(self.id);
  9894. }
  9895. });
  9896. })(tinymce);
  9897. (function(tinymce) {
  9898. // Shorten class names
  9899. var dom = tinymce.DOM, each = tinymce.each;
  9900. tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', {
  9901. renderHTML : function() {
  9902. var t = this, h = '', c, co, s = t.settings, i, pr, nx, cl;
  9903. cl = t.controls;
  9904. for (i=0; i<cl.length; i++) {
  9905. // Get current control, prev control, next control and if the control is a list box or not
  9906. co = cl[i];
  9907. pr = cl[i - 1];
  9908. nx = cl[i + 1];
  9909. // Add toolbar start
  9910. if (i === 0) {
  9911. c = 'mceToolbarStart';
  9912. if (co.Button)
  9913. c += ' mceToolbarStartButton';
  9914. else if (co.SplitButton)
  9915. c += ' mceToolbarStartSplitButton';
  9916. else if (co.ListBox)
  9917. c += ' mceToolbarStartListBox';
  9918. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  9919. }
  9920. // Add toolbar end before list box and after the previous button
  9921. // This is to fix the o2k7 editor skins
  9922. if (pr && co.ListBox) {
  9923. if (pr.Button || pr.SplitButton)
  9924. h += dom.createHTML('td', {'class' : 'mceToolbarEnd'}, dom.createHTML('span', null, '<!-- IE -->'));
  9925. }
  9926. // Render control HTML
  9927. // IE 8 quick fix, needed to propertly generate a hit area for anchors
  9928. if (dom.stdMode)
  9929. h += '<td style="position: relative">' + co.renderHTML() + '</td>';
  9930. else
  9931. h += '<td>' + co.renderHTML() + '</td>';
  9932. // Add toolbar start after list box and before the next button
  9933. // This is to fix the o2k7 editor skins
  9934. if (nx && co.ListBox) {
  9935. if (nx.Button || nx.SplitButton)
  9936. h += dom.createHTML('td', {'class' : 'mceToolbarStart'}, dom.createHTML('span', null, '<!-- IE -->'));
  9937. }
  9938. }
  9939. c = 'mceToolbarEnd';
  9940. if (co.Button)
  9941. c += ' mceToolbarEndButton';
  9942. else if (co.SplitButton)
  9943. c += ' mceToolbarEndSplitButton';
  9944. else if (co.ListBox)
  9945. c += ' mceToolbarEndListBox';
  9946. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  9947. 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>');
  9948. }
  9949. });
  9950. })(tinymce);
  9951. (function(tinymce) {
  9952. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each;
  9953. tinymce.create('tinymce.AddOnManager', {
  9954. AddOnManager : function() {
  9955. var self = this;
  9956. self.items = [];
  9957. self.urls = {};
  9958. self.lookup = {};
  9959. self.onAdd = new Dispatcher(self);
  9960. },
  9961. get : function(n) {
  9962. if (this.lookup[n]) {
  9963. return this.lookup[n].instance;
  9964. } else {
  9965. return undefined;
  9966. }
  9967. },
  9968. dependencies : function(n) {
  9969. var result;
  9970. if (this.lookup[n]) {
  9971. result = this.lookup[n].dependencies;
  9972. }
  9973. return result || [];
  9974. },
  9975. requireLangPack : function(n) {
  9976. var s = tinymce.settings;
  9977. if (s && s.language && s.language_load !== false)
  9978. tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js');
  9979. },
  9980. add : function(id, o, dependencies) {
  9981. this.items.push(o);
  9982. this.lookup[id] = {instance:o, dependencies:dependencies};
  9983. this.onAdd.dispatch(this, id, o);
  9984. return o;
  9985. },
  9986. createUrl: function(baseUrl, dep) {
  9987. if (typeof dep === "object") {
  9988. return dep
  9989. } else {
  9990. return {prefix: baseUrl.prefix, resource: dep, suffix: baseUrl.suffix};
  9991. }
  9992. },
  9993. addComponents: function(pluginName, scripts) {
  9994. var pluginUrl = this.urls[pluginName];
  9995. tinymce.each(scripts, function(script){
  9996. tinymce.ScriptLoader.add(pluginUrl+"/"+script);
  9997. });
  9998. },
  9999. load : function(n, u, cb, s) {
  10000. var t = this, url = u;
  10001. function loadDependencies() {
  10002. var dependencies = t.dependencies(n);
  10003. tinymce.each(dependencies, function(dep) {
  10004. var newUrl = t.createUrl(u, dep);
  10005. t.load(newUrl.resource, newUrl, undefined, undefined);
  10006. });
  10007. if (cb) {
  10008. if (s) {
  10009. cb.call(s);
  10010. } else {
  10011. cb.call(tinymce.ScriptLoader);
  10012. }
  10013. }
  10014. }
  10015. if (t.urls[n])
  10016. return;
  10017. if (typeof u === "object")
  10018. url = u.prefix + u.resource + u.suffix;
  10019. if (url.indexOf('/') !== 0 && url.indexOf('://') == -1)
  10020. url = tinymce.baseURL + '/' + url;
  10021. t.urls[n] = url.substring(0, url.lastIndexOf('/'));
  10022. if (t.lookup[n]) {
  10023. loadDependencies();
  10024. } else {
  10025. tinymce.ScriptLoader.add(url, loadDependencies, s);
  10026. }
  10027. }
  10028. });
  10029. // Create plugin and theme managers
  10030. tinymce.PluginManager = new tinymce.AddOnManager();
  10031. tinymce.ThemeManager = new tinymce.AddOnManager();
  10032. }(tinymce));
  10033. (function(tinymce) {
  10034. // Shorten names
  10035. var each = tinymce.each, extend = tinymce.extend,
  10036. DOM = tinymce.DOM, Event = tinymce.dom.Event,
  10037. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  10038. explode = tinymce.explode,
  10039. Dispatcher = tinymce.util.Dispatcher, undef, instanceCounter = 0;
  10040. // Setup some URLs where the editor API is located and where the document is
  10041. tinymce.documentBaseURL = window.location.href.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '');
  10042. if (!/[\/\\]$/.test(tinymce.documentBaseURL))
  10043. tinymce.documentBaseURL += '/';
  10044. tinymce.baseURL = new tinymce.util.URI(tinymce.documentBaseURL).toAbsolute(tinymce.baseURL);
  10045. tinymce.baseURI = new tinymce.util.URI(tinymce.baseURL);
  10046. // Add before unload listener
  10047. // This was required since IE was leaking memory if you added and removed beforeunload listeners
  10048. // with attachEvent/detatchEvent so this only adds one listener and instances can the attach to the onBeforeUnload event
  10049. tinymce.onBeforeUnload = new Dispatcher(tinymce);
  10050. // Must be on window or IE will leak if the editor is placed in frame or iframe
  10051. Event.add(window, 'beforeunload', function(e) {
  10052. tinymce.onBeforeUnload.dispatch(tinymce, e);
  10053. });
  10054. tinymce.onAddEditor = new Dispatcher(tinymce);
  10055. tinymce.onRemoveEditor = new Dispatcher(tinymce);
  10056. tinymce.EditorManager = extend(tinymce, {
  10057. editors : [],
  10058. i18n : {},
  10059. activeEditor : null,
  10060. init : function(s) {
  10061. var t = this, pl, sl = tinymce.ScriptLoader, e, el = [], ed;
  10062. function createId(elm) {
  10063. var id = elm.id;
  10064. // Use element id, or unique name or generate a unique id
  10065. if (!id) {
  10066. id = elm.name;
  10067. if (id && !DOM.get(id)) {
  10068. id = elm.name;
  10069. } else {
  10070. // Generate unique name
  10071. id = DOM.uniqueId();
  10072. }
  10073. elm.setAttribute('id', id);
  10074. }
  10075. return id;
  10076. };
  10077. function execCallback(se, n, s) {
  10078. var f = se[n];
  10079. if (!f)
  10080. return;
  10081. if (tinymce.is(f, 'string')) {
  10082. s = f.replace(/\.\w+$/, '');
  10083. s = s ? tinymce.resolve(s) : 0;
  10084. f = tinymce.resolve(f);
  10085. }
  10086. return f.apply(s || this, Array.prototype.slice.call(arguments, 2));
  10087. };
  10088. function hasClass(n, c) {
  10089. return c.constructor === RegExp ? c.test(n.className) : DOM.hasClass(n, c);
  10090. };
  10091. t.settings = s;
  10092. // Legacy call
  10093. Event.bind(window, 'ready', function() {
  10094. var l, co;
  10095. execCallback(s, 'onpageload');
  10096. switch (s.mode) {
  10097. case "exact":
  10098. l = s.elements || '';
  10099. if(l.length > 0) {
  10100. each(explode(l), function(v) {
  10101. if (DOM.get(v)) {
  10102. ed = new tinymce.Editor(v, s);
  10103. el.push(ed);
  10104. ed.render(1);
  10105. } else {
  10106. each(document.forms, function(f) {
  10107. each(f.elements, function(e) {
  10108. if (e.name === v) {
  10109. v = 'mce_editor_' + instanceCounter++;
  10110. DOM.setAttrib(e, 'id', v);
  10111. ed = new tinymce.Editor(v, s);
  10112. el.push(ed);
  10113. ed.render(1);
  10114. }
  10115. });
  10116. });
  10117. }
  10118. });
  10119. }
  10120. break;
  10121. case "textareas":
  10122. case "specific_textareas":
  10123. each(DOM.select('textarea'), function(elm) {
  10124. if (s.editor_deselector && hasClass(elm, s.editor_deselector))
  10125. return;
  10126. if (!s.editor_selector || hasClass(elm, s.editor_selector)) {
  10127. ed = new tinymce.Editor(createId(elm), s);
  10128. el.push(ed);
  10129. ed.render(1);
  10130. }
  10131. });
  10132. break;
  10133. default:
  10134. if (s.types) {
  10135. // Process type specific selector
  10136. each(s.types, function(type) {
  10137. each(DOM.select(type.selector), function(elm) {
  10138. var editor = new tinymce.Editor(createId(elm), tinymce.extend({}, s, type));
  10139. el.push(editor);
  10140. editor.render(1);
  10141. });
  10142. });
  10143. } else if (s.selector) {
  10144. // Process global selector
  10145. each(DOM.select(s.selector), function(elm) {
  10146. var editor = new tinymce.Editor(createId(elm), s);
  10147. el.push(editor);
  10148. editor.render(1);
  10149. });
  10150. }
  10151. }
  10152. // Call onInit when all editors are initialized
  10153. if (s.oninit) {
  10154. l = co = 0;
  10155. each(el, function(ed) {
  10156. co++;
  10157. if (!ed.initialized) {
  10158. // Wait for it
  10159. ed.onInit.add(function() {
  10160. l++;
  10161. // All done
  10162. if (l == co)
  10163. execCallback(s, 'oninit');
  10164. });
  10165. } else
  10166. l++;
  10167. // All done
  10168. if (l == co)
  10169. execCallback(s, 'oninit');
  10170. });
  10171. }
  10172. });
  10173. },
  10174. get : function(id) {
  10175. if (id === undef)
  10176. return this.editors;
  10177. return this.editors[id];
  10178. },
  10179. getInstanceById : function(id) {
  10180. return this.get(id);
  10181. },
  10182. add : function(editor) {
  10183. var self = this, editors = self.editors;
  10184. // Add named and index editor instance
  10185. editors[editor.id] = editor;
  10186. editors.push(editor);
  10187. self._setActive(editor);
  10188. self.onAddEditor.dispatch(self, editor);
  10189. return editor;
  10190. },
  10191. remove : function(editor) {
  10192. var t = this, i, editors = t.editors;
  10193. // Not in the collection
  10194. if (!editors[editor.id])
  10195. return null;
  10196. delete editors[editor.id];
  10197. for (i = 0; i < editors.length; i++) {
  10198. if (editors[i] == editor) {
  10199. editors.splice(i, 1);
  10200. break;
  10201. }
  10202. }
  10203. // Select another editor since the active one was removed
  10204. if (t.activeEditor == editor)
  10205. t._setActive(editors[0]);
  10206. editor.destroy();
  10207. t.onRemoveEditor.dispatch(t, editor);
  10208. return editor;
  10209. },
  10210. execCommand : function(c, u, v) {
  10211. var t = this, ed = t.get(v), w;
  10212. function clr() {
  10213. ed.destroy();
  10214. w.detachEvent('onunload', clr);
  10215. w = w.tinyMCE = w.tinymce = null; // IE leak
  10216. };
  10217. // Manager commands
  10218. switch (c) {
  10219. case "mceFocus":
  10220. ed.focus();
  10221. return true;
  10222. case "mceAddEditor":
  10223. case "mceAddControl":
  10224. if (!t.get(v))
  10225. new tinymce.Editor(v, t.settings).render();
  10226. return true;
  10227. case "mceAddFrameControl":
  10228. w = v.window;
  10229. // Add tinyMCE global instance and tinymce namespace to specified window
  10230. w.tinyMCE = tinyMCE;
  10231. w.tinymce = tinymce;
  10232. tinymce.DOM.doc = w.document;
  10233. tinymce.DOM.win = w;
  10234. ed = new tinymce.Editor(v.element_id, v);
  10235. ed.render();
  10236. // Fix IE memory leaks
  10237. if (tinymce.isIE) {
  10238. w.attachEvent('onunload', clr);
  10239. }
  10240. v.page_window = null;
  10241. return true;
  10242. case "mceRemoveEditor":
  10243. case "mceRemoveControl":
  10244. if (ed)
  10245. ed.remove();
  10246. return true;
  10247. case 'mceToggleEditor':
  10248. if (!ed) {
  10249. t.execCommand('mceAddControl', 0, v);
  10250. return true;
  10251. }
  10252. if (ed.isHidden())
  10253. ed.show();
  10254. else
  10255. ed.hide();
  10256. return true;
  10257. }
  10258. // Run command on active editor
  10259. if (t.activeEditor)
  10260. return t.activeEditor.execCommand(c, u, v);
  10261. return false;
  10262. },
  10263. execInstanceCommand : function(id, c, u, v) {
  10264. var ed = this.get(id);
  10265. if (ed)
  10266. return ed.execCommand(c, u, v);
  10267. return false;
  10268. },
  10269. triggerSave : function() {
  10270. each(this.editors, function(e) {
  10271. e.save();
  10272. });
  10273. },
  10274. addI18n : function(p, o) {
  10275. var lo, i18n = this.i18n;
  10276. if (!tinymce.is(p, 'string')) {
  10277. each(p, function(o, lc) {
  10278. each(o, function(o, g) {
  10279. each(o, function(o, k) {
  10280. if (g === 'common')
  10281. i18n[lc + '.' + k] = o;
  10282. else
  10283. i18n[lc + '.' + g + '.' + k] = o;
  10284. });
  10285. });
  10286. });
  10287. } else {
  10288. each(o, function(o, k) {
  10289. i18n[p + '.' + k] = o;
  10290. });
  10291. }
  10292. },
  10293. // Private methods
  10294. _setActive : function(editor) {
  10295. this.selectedInstance = this.activeEditor = editor;
  10296. }
  10297. });
  10298. })(tinymce);
  10299. (function(tinymce) {
  10300. // Shorten these names
  10301. var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend,
  10302. each = tinymce.each, isGecko = tinymce.isGecko,
  10303. isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, is = tinymce.is,
  10304. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  10305. explode = tinymce.explode;
  10306. tinymce.create('tinymce.Editor', {
  10307. Editor : function(id, settings) {
  10308. var self = this, TRUE = true;
  10309. self.settings = settings = extend({
  10310. id : id,
  10311. language : 'en',
  10312. theme : 'advanced',
  10313. skin : 'default',
  10314. delta_width : 0,
  10315. delta_height : 0,
  10316. popup_css : '',
  10317. plugins : '',
  10318. document_base_url : tinymce.documentBaseURL,
  10319. add_form_submit_trigger : TRUE,
  10320. submit_patch : TRUE,
  10321. add_unload_trigger : TRUE,
  10322. convert_urls : TRUE,
  10323. relative_urls : TRUE,
  10324. remove_script_host : TRUE,
  10325. table_inline_editing : false,
  10326. object_resizing : TRUE,
  10327. accessibility_focus : TRUE,
  10328. doctype : tinymce.isIE6 ? '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' : '<!DOCTYPE>', // Use old doctype on IE 6 to avoid horizontal scroll
  10329. visual : TRUE,
  10330. font_size_style_values : 'xx-small,x-small,small,medium,large,x-large,xx-large',
  10331. 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
  10332. apply_source_formatting : TRUE,
  10333. directionality : 'ltr',
  10334. forced_root_block : 'p',
  10335. hidden_input : TRUE,
  10336. padd_empty_editor : TRUE,
  10337. render_ui : TRUE,
  10338. indentation : '30px',
  10339. fix_table_elements : TRUE,
  10340. inline_styles : TRUE,
  10341. convert_fonts_to_spans : TRUE,
  10342. indent : 'simple',
  10343. 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',
  10344. 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',
  10345. validate : TRUE,
  10346. entity_encoding : 'named',
  10347. url_converter : self.convertURL,
  10348. url_converter_scope : self,
  10349. ie7_compat : TRUE
  10350. }, settings);
  10351. self.id = self.editorId = id;
  10352. self.isNotDirty = false;
  10353. self.plugins = {};
  10354. self.documentBaseURI = new tinymce.util.URI(settings.document_base_url || tinymce.documentBaseURL, {
  10355. base_uri : tinyMCE.baseURI
  10356. });
  10357. self.baseURI = tinymce.baseURI;
  10358. self.contentCSS = [];
  10359. self.contentStyles = [];
  10360. // Creates all events like onClick, onSetContent etc see Editor.Events.js for the actual logic
  10361. self.setupEvents();
  10362. // Internal command handler objects
  10363. self.execCommands = {};
  10364. self.queryStateCommands = {};
  10365. self.queryValueCommands = {};
  10366. // Call setup
  10367. self.execCallback('setup', self);
  10368. },
  10369. render : function(nst) {
  10370. var t = this, s = t.settings, id = t.id, sl = tinymce.ScriptLoader;
  10371. // Page is not loaded yet, wait for it
  10372. if (!Event.domLoaded) {
  10373. Event.add(window, 'ready', function() {
  10374. t.render();
  10375. });
  10376. return;
  10377. }
  10378. tinyMCE.settings = s;
  10379. // Element not found, then skip initialization
  10380. if (!t.getElement())
  10381. return;
  10382. // Is a iPad/iPhone and not on iOS5, then skip initialization. We need to sniff
  10383. // here since the browser says it has contentEditable support but there is no visible caret.
  10384. if (tinymce.isIDevice && !tinymce.isIOS5)
  10385. return;
  10386. // Add hidden input for non input elements inside form elements
  10387. if (!/TEXTAREA|INPUT/i.test(t.getElement().nodeName) && s.hidden_input && DOM.getParent(id, 'form'))
  10388. DOM.insertAfter(DOM.create('input', {type : 'hidden', name : id}), id);
  10389. // Hide target element early to prevent content flashing
  10390. if (!s.content_editable) {
  10391. t.orgVisibility = t.getElement().style.visibility;
  10392. t.getElement().style.visibility = 'hidden';
  10393. }
  10394. if (tinymce.WindowManager)
  10395. t.windowManager = new tinymce.WindowManager(t);
  10396. if (s.encoding == 'xml') {
  10397. t.onGetContent.add(function(ed, o) {
  10398. if (o.save)
  10399. o.content = DOM.encode(o.content);
  10400. });
  10401. }
  10402. if (s.add_form_submit_trigger) {
  10403. t.onSubmit.addToTop(function() {
  10404. if (t.initialized) {
  10405. t.save();
  10406. t.isNotDirty = 1;
  10407. }
  10408. });
  10409. }
  10410. if (s.add_unload_trigger) {
  10411. t._beforeUnload = tinyMCE.onBeforeUnload.add(function() {
  10412. if (t.initialized && !t.destroyed && !t.isHidden())
  10413. t.save({format : 'raw', no_events : true});
  10414. });
  10415. }
  10416. tinymce.addUnload(t.destroy, t);
  10417. if (s.submit_patch) {
  10418. t.onBeforeRenderUI.add(function() {
  10419. var n = t.getElement().form;
  10420. if (!n)
  10421. return;
  10422. // Already patched
  10423. if (n._mceOldSubmit)
  10424. return;
  10425. // Check page uses id="submit" or name="submit" for it's submit button
  10426. if (!n.submit.nodeType && !n.submit.length) {
  10427. t.formElement = n;
  10428. n._mceOldSubmit = n.submit;
  10429. n.submit = function() {
  10430. // Save all instances
  10431. tinymce.triggerSave();
  10432. t.isNotDirty = 1;
  10433. return t.formElement._mceOldSubmit(t.formElement);
  10434. };
  10435. }
  10436. n = null;
  10437. });
  10438. }
  10439. // Load scripts
  10440. function loadScripts() {
  10441. if (s.language && s.language_load !== false)
  10442. sl.add(tinymce.baseURL + '/langs/' + s.language + '.js');
  10443. if (s.theme && typeof s.theme != "function" && s.theme.charAt(0) != '-' && !ThemeManager.urls[s.theme])
  10444. ThemeManager.load(s.theme, 'themes/' + s.theme + '/editor_template' + tinymce.suffix + '.js');
  10445. each(explode(s.plugins), function(p) {
  10446. if (p &&!PluginManager.urls[p]) {
  10447. if (p.charAt(0) == '-') {
  10448. p = p.substr(1, p.length);
  10449. var dependencies = PluginManager.dependencies(p);
  10450. each(dependencies, function(dep) {
  10451. var defaultSettings = {prefix:'plugins/', resource: dep, suffix:'/editor_plugin' + tinymce.suffix + '.js'};
  10452. dep = PluginManager.createUrl(defaultSettings, dep);
  10453. PluginManager.load(dep.resource, dep);
  10454. });
  10455. } else {
  10456. // Skip safari plugin, since it is removed as of 3.3b1
  10457. if (p == 'safari') {
  10458. return;
  10459. }
  10460. PluginManager.load(p, {prefix:'plugins/', resource: p, suffix:'/editor_plugin' + tinymce.suffix + '.js'});
  10461. }
  10462. }
  10463. });
  10464. // Init when que is loaded
  10465. sl.loadQueue(function() {
  10466. if (!t.removed)
  10467. t.init();
  10468. });
  10469. };
  10470. loadScripts();
  10471. },
  10472. init : function() {
  10473. var n, t = this, s = t.settings, w, h, mh, e = t.getElement(), o, ti, u, bi, bc, re, i, initializedPlugins = [];
  10474. tinymce.add(t);
  10475. s.aria_label = s.aria_label || DOM.getAttrib(e, 'aria-label', t.getLang('aria.rich_text_area'));
  10476. if (s.theme) {
  10477. if (typeof s.theme != "function") {
  10478. s.theme = s.theme.replace(/-/, '');
  10479. o = ThemeManager.get(s.theme);
  10480. t.theme = new o();
  10481. if (t.theme.init)
  10482. t.theme.init(t, ThemeManager.urls[s.theme] || tinymce.documentBaseURL.replace(/\/$/, ''));
  10483. } else {
  10484. t.theme = s.theme;
  10485. }
  10486. }
  10487. function initPlugin(p) {
  10488. var c = PluginManager.get(p), u = PluginManager.urls[p] || tinymce.documentBaseURL.replace(/\/$/, ''), po;
  10489. if (c && tinymce.inArray(initializedPlugins,p) === -1) {
  10490. each(PluginManager.dependencies(p), function(dep){
  10491. initPlugin(dep);
  10492. });
  10493. po = new c(t, u);
  10494. t.plugins[p] = po;
  10495. if (po.init) {
  10496. po.init(t, u);
  10497. initializedPlugins.push(p);
  10498. }
  10499. }
  10500. }
  10501. // Create all plugins
  10502. each(explode(s.plugins.replace(/\-/g, '')), initPlugin);
  10503. // Setup popup CSS path(s)
  10504. if (s.popup_css !== false) {
  10505. if (s.popup_css)
  10506. s.popup_css = t.documentBaseURI.toAbsolute(s.popup_css);
  10507. else
  10508. s.popup_css = t.baseURI.toAbsolute("themes/" + s.theme + "/skins/" + s.skin + "/dialog.css");
  10509. }
  10510. if (s.popup_css_add)
  10511. s.popup_css += ',' + t.documentBaseURI.toAbsolute(s.popup_css_add);
  10512. t.controlManager = new tinymce.ControlManager(t);
  10513. // Enables users to override the control factory
  10514. t.onBeforeRenderUI.dispatch(t, t.controlManager);
  10515. // Measure box
  10516. if (s.render_ui && t.theme) {
  10517. t.orgDisplay = e.style.display;
  10518. if (typeof s.theme != "function") {
  10519. w = s.width || e.style.width || e.offsetWidth;
  10520. h = s.height || e.style.height || e.offsetHeight;
  10521. mh = s.min_height || 100;
  10522. re = /^[0-9\.]+(|px)$/i;
  10523. if (re.test('' + w))
  10524. w = Math.max(parseInt(w, 10) + (o.deltaWidth || 0), 100);
  10525. if (re.test('' + h))
  10526. h = Math.max(parseInt(h, 10) + (o.deltaHeight || 0), mh);
  10527. // Render UI
  10528. o = t.theme.renderUI({
  10529. targetNode : e,
  10530. width : w,
  10531. height : h,
  10532. deltaWidth : s.delta_width,
  10533. deltaHeight : s.delta_height
  10534. });
  10535. // Resize editor
  10536. DOM.setStyles(o.sizeContainer || o.editorContainer, {
  10537. width : w,
  10538. height : h
  10539. });
  10540. h = (o.iframeHeight || h) + (typeof(h) == 'number' ? (o.deltaHeight || 0) : '');
  10541. if (h < mh)
  10542. h = mh;
  10543. } else {
  10544. o = s.theme(t, e);
  10545. // Convert element type to id:s
  10546. if (o.editorContainer.nodeType) {
  10547. o.editorContainer = o.editorContainer.id = o.editorContainer.id || t.id + "_parent";
  10548. }
  10549. // Convert element type to id:s
  10550. if (o.iframeContainer.nodeType) {
  10551. o.iframeContainer = o.iframeContainer.id = o.iframeContainer.id || t.id + "_iframecontainer";
  10552. }
  10553. // Use specified iframe height or the targets offsetHeight
  10554. h = o.iframeHeight || e.offsetHeight;
  10555. // Store away the selection when it's changed to it can be restored later with a editor.focus() call
  10556. if (isIE) {
  10557. t.onInit.add(function(ed) {
  10558. ed.dom.bind(ed.getBody(), 'beforedeactivate keydown', function() {
  10559. ed.lastIERng = ed.selection.getRng();
  10560. });
  10561. });
  10562. }
  10563. }
  10564. t.editorContainer = o.editorContainer;
  10565. }
  10566. // Load specified content CSS last
  10567. if (s.content_css) {
  10568. each(explode(s.content_css), function(u) {
  10569. t.contentCSS.push(t.documentBaseURI.toAbsolute(u));
  10570. });
  10571. }
  10572. // Content editable mode ends here
  10573. if (s.content_editable) {
  10574. e = n = o = null; // Fix IE leak
  10575. return t.initContentBody();
  10576. }
  10577. // User specified a document.domain value
  10578. if (document.domain && location.hostname != document.domain)
  10579. tinymce.relaxedDomain = document.domain;
  10580. t.iframeHTML = s.doctype + '<html><head xmlns="http://www.w3.org/1999/xhtml">';
  10581. // We only need to override paths if we have to
  10582. // IE has a bug where it remove site absolute urls to relative ones if this is specified
  10583. if (s.document_base_url != tinymce.documentBaseURL)
  10584. t.iframeHTML += '<base href="' + t.documentBaseURI.getURI() + '" />';
  10585. // IE8 doesn't support carets behind images setting ie7_compat would force IE8+ to run in IE7 compat mode.
  10586. if (s.ie7_compat)
  10587. t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=7" />';
  10588. else
  10589. t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=edge" />';
  10590. t.iframeHTML += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
  10591. // Load the CSS by injecting them into the HTML this will reduce "flicker"
  10592. for (i = 0; i < t.contentCSS.length; i++) {
  10593. t.iframeHTML += '<link type="text/css" rel="stylesheet" href="' + t.contentCSS[i] + '" />';
  10594. }
  10595. t.contentCSS = [];
  10596. bi = s.body_id || 'tinymce';
  10597. if (bi.indexOf('=') != -1) {
  10598. bi = t.getParam('body_id', '', 'hash');
  10599. bi = bi[t.id] || bi;
  10600. }
  10601. bc = s.body_class || '';
  10602. if (bc.indexOf('=') != -1) {
  10603. bc = t.getParam('body_class', '', 'hash');
  10604. bc = bc[t.id] || '';
  10605. }
  10606. t.iframeHTML += '</head><body id="' + bi + '" class="mceContentBody ' + bc + '" onload="window.parent.tinyMCE.get(\'' + t.id + '\').onLoad.dispatch();"><br></body></html>';
  10607. // Domain relaxing enabled, then set document domain
  10608. if (tinymce.relaxedDomain && (isIE || (tinymce.isOpera && parseFloat(opera.version()) < 11))) {
  10609. // We need to write the contents here in IE since multiple writes messes up refresh button and back button
  10610. 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();})()';
  10611. }
  10612. // Create iframe
  10613. // TODO: ACC add the appropriate description on this.
  10614. n = DOM.add(o.iframeContainer, 'iframe', {
  10615. id : t.id + "_ifr",
  10616. src : u || 'javascript:""', // Workaround for HTTPS warning in IE6/7
  10617. frameBorder : '0',
  10618. allowTransparency : "true",
  10619. title : s.aria_label,
  10620. style : {
  10621. width : '100%',
  10622. height : h,
  10623. display : 'block' // Important for Gecko to render the iframe correctly
  10624. }
  10625. });
  10626. t.contentAreaContainer = o.iframeContainer;
  10627. if (o.editorContainer) {
  10628. DOM.get(o.editorContainer).style.display = t.orgDisplay;
  10629. }
  10630. // Restore visibility on target element
  10631. e.style.visibility = t.orgVisibility;
  10632. DOM.get(t.id).style.display = 'none';
  10633. DOM.setAttrib(t.id, 'aria-hidden', true);
  10634. if (!tinymce.relaxedDomain || !u)
  10635. t.initContentBody();
  10636. e = n = o = null; // Cleanup
  10637. },
  10638. initContentBody : function() {
  10639. var self = this, settings = self.settings, targetElm = DOM.get(self.id), doc = self.getDoc(), html, body, contentCssText;
  10640. // Setup iframe body
  10641. if ((!isIE || !tinymce.relaxedDomain) && !settings.content_editable) {
  10642. doc.open();
  10643. doc.write(self.iframeHTML);
  10644. doc.close();
  10645. if (tinymce.relaxedDomain)
  10646. doc.domain = tinymce.relaxedDomain;
  10647. }
  10648. if (settings.content_editable) {
  10649. DOM.addClass(targetElm, 'mceContentBody');
  10650. self.contentDocument = doc = settings.content_document || document;
  10651. self.contentWindow = settings.content_window || window;
  10652. self.bodyElement = targetElm;
  10653. // Prevent leak in IE
  10654. settings.content_document = settings.content_window = null;
  10655. }
  10656. // It will not steal focus while setting contentEditable
  10657. body = self.getBody();
  10658. body.disabled = true;
  10659. if (!settings.readonly)
  10660. body.contentEditable = self.getParam('content_editable_state', true);
  10661. body.disabled = false;
  10662. self.schema = new tinymce.html.Schema(settings);
  10663. self.dom = new tinymce.dom.DOMUtils(doc, {
  10664. keep_values : true,
  10665. url_converter : self.convertURL,
  10666. url_converter_scope : self,
  10667. hex_colors : settings.force_hex_style_colors,
  10668. class_filter : settings.class_filter,
  10669. update_styles : true,
  10670. root_element : settings.content_editable ? self.id : null,
  10671. schema : self.schema
  10672. });
  10673. self.parser = new tinymce.html.DomParser(settings, self.schema);
  10674. // Convert src and href into data-mce-src, data-mce-href and data-mce-style
  10675. self.parser.addAttributeFilter('src,href,style', function(nodes, name) {
  10676. var i = nodes.length, node, dom = self.dom, value, internalName;
  10677. while (i--) {
  10678. node = nodes[i];
  10679. value = node.attr(name);
  10680. internalName = 'data-mce-' + name;
  10681. // Add internal attribute if we need to we don't on a refresh of the document
  10682. if (!node.attributes.map[internalName]) {
  10683. if (name === "style")
  10684. node.attr(internalName, dom.serializeStyle(dom.parseStyle(value), node.name));
  10685. else
  10686. node.attr(internalName, self.convertURL(value, name, node.name));
  10687. }
  10688. }
  10689. });
  10690. // Keep scripts from executing
  10691. self.parser.addNodeFilter('script', function(nodes, name) {
  10692. var i = nodes.length, node;
  10693. while (i--) {
  10694. node = nodes[i];
  10695. node.attr('type', 'mce-' + (node.attr('type') || 'text/javascript'));
  10696. }
  10697. });
  10698. self.parser.addNodeFilter('#cdata', function(nodes, name) {
  10699. var i = nodes.length, node;
  10700. while (i--) {
  10701. node = nodes[i];
  10702. node.type = 8;
  10703. node.name = '#comment';
  10704. node.value = '[CDATA[' + node.value + ']]';
  10705. }
  10706. });
  10707. self.parser.addNodeFilter('p,h1,h2,h3,h4,h5,h6,div', function(nodes, name) {
  10708. var i = nodes.length, node, nonEmptyElements = self.schema.getNonEmptyElements();
  10709. while (i--) {
  10710. node = nodes[i];
  10711. if (node.isEmpty(nonEmptyElements))
  10712. node.empty().append(new tinymce.html.Node('br', 1)).shortEnded = true;
  10713. }
  10714. });
  10715. self.serializer = new tinymce.dom.Serializer(settings, self.dom, self.schema);
  10716. self.selection = new tinymce.dom.Selection(self.dom, self.getWin(), self.serializer, self);
  10717. self.formatter = new tinymce.Formatter(self);
  10718. self.undoManager = new tinymce.UndoManager(self);
  10719. self.forceBlocks = new tinymce.ForceBlocks(self);
  10720. self.enterKey = new tinymce.EnterKey(self);
  10721. self.editorCommands = new tinymce.EditorCommands(self);
  10722. self.onExecCommand.add(function(editor, command) {
  10723. // Don't refresh the select lists until caret move
  10724. if (!/^(FontName|FontSize)$/.test(command))
  10725. self.nodeChanged();
  10726. });
  10727. // Pass through
  10728. self.serializer.onPreProcess.add(function(se, o) {
  10729. return self.onPreProcess.dispatch(self, o, se);
  10730. });
  10731. self.serializer.onPostProcess.add(function(se, o) {
  10732. return self.onPostProcess.dispatch(self, o, se);
  10733. });
  10734. self.onPreInit.dispatch(self);
  10735. if (!settings.browser_spellcheck && !settings.gecko_spellcheck)
  10736. doc.body.spellcheck = false;
  10737. if (!settings.readonly) {
  10738. self.bindNativeEvents();
  10739. }
  10740. self.controlManager.onPostRender.dispatch(self, self.controlManager);
  10741. self.onPostRender.dispatch(self);
  10742. self.quirks = tinymce.util.Quirks(self);
  10743. if (settings.directionality)
  10744. body.dir = settings.directionality;
  10745. if (settings.nowrap)
  10746. body.style.whiteSpace = "nowrap";
  10747. if (settings.protect) {
  10748. self.onBeforeSetContent.add(function(ed, o) {
  10749. each(settings.protect, function(pattern) {
  10750. o.content = o.content.replace(pattern, function(str) {
  10751. return '<!--mce:protected ' + escape(str) + '-->';
  10752. });
  10753. });
  10754. });
  10755. }
  10756. // Add visual aids when new contents is added
  10757. self.onSetContent.add(function() {
  10758. self.addVisual(self.getBody());
  10759. });
  10760. // Remove empty contents
  10761. if (settings.padd_empty_editor) {
  10762. self.onPostProcess.add(function(ed, o) {
  10763. o.content = o.content.replace(/^(<p[^>]*>(&nbsp;|&#160;|\s|\u00a0|)<\/p>[\r\n]*|<br \/>[\r\n]*)$/, '');
  10764. });
  10765. }
  10766. self.load({initial : true, format : 'html'});
  10767. self.startContent = self.getContent({format : 'raw'});
  10768. self.initialized = true;
  10769. self.onInit.dispatch(self);
  10770. self.execCallback('setupcontent_callback', self.id, body, doc);
  10771. self.execCallback('init_instance_callback', self);
  10772. self.focus(true);
  10773. self.nodeChanged({initial : true});
  10774. // Add editor specific CSS styles
  10775. if (self.contentStyles.length > 0) {
  10776. contentCssText = '';
  10777. each(self.contentStyles, function(style) {
  10778. contentCssText += style + "\r\n";
  10779. });
  10780. self.dom.addStyle(contentCssText);
  10781. }
  10782. // Load specified content CSS last
  10783. each(self.contentCSS, function(url) {
  10784. self.dom.loadCSS(url);
  10785. });
  10786. // Handle auto focus
  10787. if (settings.auto_focus) {
  10788. setTimeout(function () {
  10789. var ed = tinymce.get(settings.auto_focus);
  10790. ed.selection.select(ed.getBody(), 1);
  10791. ed.selection.collapse(1);
  10792. ed.getBody().focus();
  10793. ed.getWin().focus();
  10794. }, 100);
  10795. }
  10796. // Clean up references for IE
  10797. targetElm = doc = body = null;
  10798. },
  10799. focus : function(skip_focus) {
  10800. var oed, self = this, selection = self.selection, contentEditable = self.settings.content_editable, ieRng, controlElm, doc = self.getDoc(), body;
  10801. if (!skip_focus) {
  10802. if (self.lastIERng) {
  10803. selection.setRng(self.lastIERng);
  10804. }
  10805. // Get selected control element
  10806. ieRng = selection.getRng();
  10807. if (ieRng.item) {
  10808. controlElm = ieRng.item(0);
  10809. }
  10810. self._refreshContentEditable();
  10811. // Focus the window iframe
  10812. if (!contentEditable) {
  10813. self.getWin().focus();
  10814. }
  10815. // Focus the body as well since it's contentEditable
  10816. if (tinymce.isGecko || contentEditable) {
  10817. body = self.getBody();
  10818. // Check for setActive since it doesn't scroll to the element
  10819. if (body.setActive) {
  10820. body.setActive();
  10821. } else {
  10822. body.focus();
  10823. }
  10824. if (contentEditable) {
  10825. selection.normalize();
  10826. }
  10827. }
  10828. // Restore selected control element
  10829. // This is needed when for example an image is selected within a
  10830. // layer a call to focus will then remove the control selection
  10831. if (controlElm && controlElm.ownerDocument == doc) {
  10832. ieRng = doc.body.createControlRange();
  10833. ieRng.addElement(controlElm);
  10834. ieRng.select();
  10835. }
  10836. }
  10837. if (tinymce.activeEditor != self) {
  10838. if ((oed = tinymce.activeEditor) != null)
  10839. oed.onDeactivate.dispatch(oed, self);
  10840. self.onActivate.dispatch(self, oed);
  10841. }
  10842. tinymce._setActive(self);
  10843. },
  10844. execCallback : function(n) {
  10845. var t = this, f = t.settings[n], s;
  10846. if (!f)
  10847. return;
  10848. // Look through lookup
  10849. if (t.callbackLookup && (s = t.callbackLookup[n])) {
  10850. f = s.func;
  10851. s = s.scope;
  10852. }
  10853. if (is(f, 'string')) {
  10854. s = f.replace(/\.\w+$/, '');
  10855. s = s ? tinymce.resolve(s) : 0;
  10856. f = tinymce.resolve(f);
  10857. t.callbackLookup = t.callbackLookup || {};
  10858. t.callbackLookup[n] = {func : f, scope : s};
  10859. }
  10860. return f.apply(s || t, Array.prototype.slice.call(arguments, 1));
  10861. },
  10862. translate : function(s) {
  10863. var c = this.settings.language || 'en', i18n = tinymce.i18n;
  10864. if (!s)
  10865. return '';
  10866. return i18n[c + '.' + s] || s.replace(/\{\#([^\}]+)\}/g, function(a, b) {
  10867. return i18n[c + '.' + b] || '{#' + b + '}';
  10868. });
  10869. },
  10870. getLang : function(n, dv) {
  10871. return tinymce.i18n[(this.settings.language || 'en') + '.' + n] || (is(dv) ? dv : '{#' + n + '}');
  10872. },
  10873. getParam : function(n, dv, ty) {
  10874. var tr = tinymce.trim, v = is(this.settings[n]) ? this.settings[n] : dv, o;
  10875. if (ty === 'hash') {
  10876. o = {};
  10877. if (is(v, 'string')) {
  10878. each(v.indexOf('=') > 0 ? v.split(/[;,](?![^=;,]*(?:[;,]|$))/) : v.split(','), function(v) {
  10879. v = v.split('=');
  10880. if (v.length > 1)
  10881. o[tr(v[0])] = tr(v[1]);
  10882. else
  10883. o[tr(v[0])] = tr(v);
  10884. });
  10885. } else
  10886. o = v;
  10887. return o;
  10888. }
  10889. return v;
  10890. },
  10891. nodeChanged : function(o) {
  10892. var self = this, selection = self.selection, node;
  10893. // Fix for bug #1896577 it seems that this can not be fired while the editor is loading
  10894. if (self.initialized) {
  10895. o = o || {};
  10896. // Get start node
  10897. node = selection.getStart() || self.getBody();
  10898. node = isIE && node.ownerDocument != self.getDoc() ? self.getBody() : node; // Fix for IE initial state
  10899. // Get parents and add them to object
  10900. o.parents = [];
  10901. self.dom.getParent(node, function(node) {
  10902. if (node.nodeName == 'BODY')
  10903. return true;
  10904. o.parents.push(node);
  10905. });
  10906. self.onNodeChange.dispatch(
  10907. self,
  10908. o ? o.controlManager || self.controlManager : self.controlManager,
  10909. node,
  10910. selection.isCollapsed(),
  10911. o
  10912. );
  10913. }
  10914. },
  10915. addButton : function(name, settings) {
  10916. var self = this;
  10917. self.buttons = self.buttons || {};
  10918. self.buttons[name] = settings;
  10919. },
  10920. addCommand : function(name, callback, scope) {
  10921. this.execCommands[name] = {func : callback, scope : scope || this};
  10922. },
  10923. addQueryStateHandler : function(name, callback, scope) {
  10924. this.queryStateCommands[name] = {func : callback, scope : scope || this};
  10925. },
  10926. addQueryValueHandler : function(name, callback, scope) {
  10927. this.queryValueCommands[name] = {func : callback, scope : scope || this};
  10928. },
  10929. addShortcut : function(pa, desc, cmd_func, sc) {
  10930. var t = this, c;
  10931. if (t.settings.custom_shortcuts === false)
  10932. return false;
  10933. t.shortcuts = t.shortcuts || {};
  10934. if (is(cmd_func, 'string')) {
  10935. c = cmd_func;
  10936. cmd_func = function() {
  10937. t.execCommand(c, false, null);
  10938. };
  10939. }
  10940. if (is(cmd_func, 'object')) {
  10941. c = cmd_func;
  10942. cmd_func = function() {
  10943. t.execCommand(c[0], c[1], c[2]);
  10944. };
  10945. }
  10946. each(explode(pa), function(pa) {
  10947. var o = {
  10948. func : cmd_func,
  10949. scope : sc || this,
  10950. desc : t.translate(desc),
  10951. alt : false,
  10952. ctrl : false,
  10953. shift : false
  10954. };
  10955. each(explode(pa, '+'), function(v) {
  10956. switch (v) {
  10957. case 'alt':
  10958. case 'ctrl':
  10959. case 'shift':
  10960. o[v] = true;
  10961. break;
  10962. default:
  10963. o.charCode = v.charCodeAt(0);
  10964. o.keyCode = v.toUpperCase().charCodeAt(0);
  10965. }
  10966. });
  10967. t.shortcuts[(o.ctrl ? 'ctrl' : '') + ',' + (o.alt ? 'alt' : '') + ',' + (o.shift ? 'shift' : '') + ',' + o.keyCode] = o;
  10968. });
  10969. return true;
  10970. },
  10971. execCommand : function(cmd, ui, val, a) {
  10972. var t = this, s = 0, o, st;
  10973. if (!/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint|SelectAll)$/.test(cmd) && (!a || !a.skip_focus))
  10974. t.focus();
  10975. a = extend({}, a);
  10976. t.onBeforeExecCommand.dispatch(t, cmd, ui, val, a);
  10977. if (a.terminate)
  10978. return false;
  10979. // Command callback
  10980. if (t.execCallback('execcommand_callback', t.id, t.selection.getNode(), cmd, ui, val)) {
  10981. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  10982. return true;
  10983. }
  10984. // Registred commands
  10985. if (o = t.execCommands[cmd]) {
  10986. st = o.func.call(o.scope, ui, val);
  10987. // Fall through on true
  10988. if (st !== true) {
  10989. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  10990. return st;
  10991. }
  10992. }
  10993. // Plugin commands
  10994. each(t.plugins, function(p) {
  10995. if (p.execCommand && p.execCommand(cmd, ui, val)) {
  10996. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  10997. s = 1;
  10998. return false;
  10999. }
  11000. });
  11001. if (s)
  11002. return true;
  11003. // Theme commands
  11004. if (t.theme && t.theme.execCommand && t.theme.execCommand(cmd, ui, val)) {
  11005. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  11006. return true;
  11007. }
  11008. // Editor commands
  11009. if (t.editorCommands.execCommand(cmd, ui, val)) {
  11010. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  11011. return true;
  11012. }
  11013. // Browser commands
  11014. t.getDoc().execCommand(cmd, ui, val);
  11015. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  11016. },
  11017. queryCommandState : function(cmd) {
  11018. var t = this, o, s;
  11019. // Is hidden then return undefined
  11020. if (t._isHidden())
  11021. return;
  11022. // Registred commands
  11023. if (o = t.queryStateCommands[cmd]) {
  11024. s = o.func.call(o.scope);
  11025. // Fall though on true
  11026. if (s !== true)
  11027. return s;
  11028. }
  11029. // Registred commands
  11030. o = t.editorCommands.queryCommandState(cmd);
  11031. if (o !== -1)
  11032. return o;
  11033. // Browser commands
  11034. try {
  11035. return this.getDoc().queryCommandState(cmd);
  11036. } catch (ex) {
  11037. // Fails sometimes see bug: 1896577
  11038. }
  11039. },
  11040. queryCommandValue : function(c) {
  11041. var t = this, o, s;
  11042. // Is hidden then return undefined
  11043. if (t._isHidden())
  11044. return;
  11045. // Registred commands
  11046. if (o = t.queryValueCommands[c]) {
  11047. s = o.func.call(o.scope);
  11048. // Fall though on true
  11049. if (s !== true)
  11050. return s;
  11051. }
  11052. // Registred commands
  11053. o = t.editorCommands.queryCommandValue(c);
  11054. if (is(o))
  11055. return o;
  11056. // Browser commands
  11057. try {
  11058. return this.getDoc().queryCommandValue(c);
  11059. } catch (ex) {
  11060. // Fails sometimes see bug: 1896577
  11061. }
  11062. },
  11063. show : function() {
  11064. var self = this;
  11065. DOM.show(self.getContainer());
  11066. DOM.hide(self.id);
  11067. self.load();
  11068. },
  11069. hide : function() {
  11070. var self = this, doc = self.getDoc();
  11071. // Fixed bug where IE has a blinking cursor left from the editor
  11072. if (isIE && doc)
  11073. doc.execCommand('SelectAll');
  11074. // We must save before we hide so Safari doesn't crash
  11075. self.save();
  11076. DOM.hide(self.getContainer());
  11077. DOM.setStyle(self.id, 'display', self.orgDisplay);
  11078. },
  11079. isHidden : function() {
  11080. return !DOM.isHidden(this.id);
  11081. },
  11082. setProgressState : function(b, ti, o) {
  11083. this.onSetProgressState.dispatch(this, b, ti, o);
  11084. return b;
  11085. },
  11086. load : function(o) {
  11087. var t = this, e = t.getElement(), h;
  11088. if (e) {
  11089. o = o || {};
  11090. o.load = true;
  11091. // Double encode existing entities in the value
  11092. h = t.setContent(is(e.value) ? e.value : e.innerHTML, o);
  11093. o.element = e;
  11094. if (!o.no_events)
  11095. t.onLoadContent.dispatch(t, o);
  11096. o.element = e = null;
  11097. return h;
  11098. }
  11099. },
  11100. save : function(o) {
  11101. var t = this, e = t.getElement(), h, f;
  11102. if (!e || !t.initialized)
  11103. return;
  11104. o = o || {};
  11105. o.save = true;
  11106. o.element = e;
  11107. h = o.content = t.getContent(o);
  11108. if (!o.no_events)
  11109. t.onSaveContent.dispatch(t, o);
  11110. h = o.content;
  11111. if (!/TEXTAREA|INPUT/i.test(e.nodeName)) {
  11112. e.innerHTML = h;
  11113. // Update hidden form element
  11114. if (f = DOM.getParent(t.id, 'form')) {
  11115. each(f.elements, function(e) {
  11116. if (e.name == t.id) {
  11117. e.value = h;
  11118. return false;
  11119. }
  11120. });
  11121. }
  11122. } else
  11123. e.value = h;
  11124. o.element = e = null;
  11125. return h;
  11126. },
  11127. setContent : function(content, args) {
  11128. var self = this, rootNode, body = self.getBody(), forcedRootBlockName;
  11129. // Setup args object
  11130. args = args || {};
  11131. args.format = args.format || 'html';
  11132. args.set = true;
  11133. args.content = content;
  11134. // Do preprocessing
  11135. if (!args.no_events)
  11136. self.onBeforeSetContent.dispatch(self, args);
  11137. content = args.content;
  11138. // Padd empty content in Gecko and Safari. Commands will otherwise fail on the content
  11139. // It will also be impossible to place the caret in the editor unless there is a BR element present
  11140. if (!tinymce.isIE && (content.length === 0 || /^\s+$/.test(content))) {
  11141. forcedRootBlockName = self.settings.forced_root_block;
  11142. if (forcedRootBlockName)
  11143. content = '<' + forcedRootBlockName + '><br data-mce-bogus="1"></' + forcedRootBlockName + '>';
  11144. else
  11145. content = '<br data-mce-bogus="1">';
  11146. body.innerHTML = content;
  11147. self.selection.select(body, true);
  11148. self.selection.collapse(true);
  11149. return;
  11150. }
  11151. // Parse and serialize the html
  11152. if (args.format !== 'raw') {
  11153. content = new tinymce.html.Serializer({}, self.schema).serialize(
  11154. self.parser.parse(content)
  11155. );
  11156. }
  11157. // Set the new cleaned contents to the editor
  11158. args.content = tinymce.trim(content);
  11159. self.dom.setHTML(body, args.content);
  11160. // Do post processing
  11161. if (!args.no_events)
  11162. self.onSetContent.dispatch(self, args);
  11163. // Don't normalize selection if the focused element isn't the body in content editable mode since it will steal focus otherwise
  11164. if (!self.settings.content_editable || document.activeElement === self.getBody()) {
  11165. self.selection.normalize();
  11166. }
  11167. return args.content;
  11168. },
  11169. getContent : function(args) {
  11170. var self = this, content;
  11171. // Setup args object
  11172. args = args || {};
  11173. args.format = args.format || 'html';
  11174. args.get = true;
  11175. args.getInner = true;
  11176. // Do preprocessing
  11177. if (!args.no_events)
  11178. self.onBeforeGetContent.dispatch(self, args);
  11179. // Get raw contents or by default the cleaned contents
  11180. if (args.format == 'raw')
  11181. content = self.getBody().innerHTML;
  11182. else
  11183. content = self.serializer.serialize(self.getBody(), args);
  11184. args.content = tinymce.trim(content);
  11185. // Do post processing
  11186. if (!args.no_events)
  11187. self.onGetContent.dispatch(self, args);
  11188. return args.content;
  11189. },
  11190. isDirty : function() {
  11191. var self = this;
  11192. return tinymce.trim(self.startContent) != tinymce.trim(self.getContent({format : 'raw', no_events : 1})) && !self.isNotDirty;
  11193. },
  11194. getContainer : function() {
  11195. var self = this;
  11196. if (!self.container)
  11197. self.container = DOM.get(self.editorContainer || self.id + '_parent');
  11198. return self.container;
  11199. },
  11200. getContentAreaContainer : function() {
  11201. return this.contentAreaContainer;
  11202. },
  11203. getElement : function() {
  11204. return DOM.get(this.settings.content_element || this.id);
  11205. },
  11206. getWin : function() {
  11207. var self = this, elm;
  11208. if (!self.contentWindow) {
  11209. elm = DOM.get(self.id + "_ifr");
  11210. if (elm)
  11211. self.contentWindow = elm.contentWindow;
  11212. }
  11213. return self.contentWindow;
  11214. },
  11215. getDoc : function() {
  11216. var self = this, win;
  11217. if (!self.contentDocument) {
  11218. win = self.getWin();
  11219. if (win)
  11220. self.contentDocument = win.document;
  11221. }
  11222. return self.contentDocument;
  11223. },
  11224. getBody : function() {
  11225. return this.bodyElement || this.getDoc().body;
  11226. },
  11227. convertURL : function(url, name, elm) {
  11228. var self = this, settings = self.settings;
  11229. // Use callback instead
  11230. if (settings.urlconverter_callback)
  11231. return self.execCallback('urlconverter_callback', url, elm, true, name);
  11232. // Don't convert link href since thats the CSS files that gets loaded into the editor also skip local file URLs
  11233. if (!settings.convert_urls || (elm && elm.nodeName == 'LINK') || url.indexOf('file:') === 0)
  11234. return url;
  11235. // Convert to relative
  11236. if (settings.relative_urls)
  11237. return self.documentBaseURI.toRelative(url);
  11238. // Convert to absolute
  11239. url = self.documentBaseURI.toAbsolute(url, settings.remove_script_host);
  11240. return url;
  11241. },
  11242. addVisual : function(elm) {
  11243. var self = this, settings = self.settings, dom = self.dom, cls;
  11244. elm = elm || self.getBody();
  11245. if (!is(self.hasVisual))
  11246. self.hasVisual = settings.visual;
  11247. each(dom.select('table,a', elm), function(elm) {
  11248. var value;
  11249. switch (elm.nodeName) {
  11250. case 'TABLE':
  11251. cls = settings.visual_table_class || 'mceItemTable';
  11252. value = dom.getAttrib(elm, 'border');
  11253. if (!value || value == '0') {
  11254. if (self.hasVisual)
  11255. dom.addClass(elm, cls);
  11256. else
  11257. dom.removeClass(elm, cls);
  11258. }
  11259. return;
  11260. case 'A':
  11261. if (!dom.getAttrib(elm, 'href', false)) {
  11262. value = dom.getAttrib(elm, 'name') || elm.id;
  11263. cls = 'mceItemAnchor';
  11264. if (value) {
  11265. if (self.hasVisual)
  11266. dom.addClass(elm, cls);
  11267. else
  11268. dom.removeClass(elm, cls);
  11269. }
  11270. }
  11271. return;
  11272. }
  11273. });
  11274. self.onVisualAid.dispatch(self, elm, self.hasVisual);
  11275. },
  11276. remove : function() {
  11277. var self = this, elm = self.getContainer();
  11278. if (!self.removed) {
  11279. self.removed = 1; // Cancels post remove event execution
  11280. self.hide();
  11281. // Don't clear the window or document if content editable
  11282. // is enabled since other instances might still be present
  11283. if (!self.settings.content_editable) {
  11284. Event.unbind(self.getWin());
  11285. Event.unbind(self.getDoc());
  11286. }
  11287. Event.unbind(self.getBody());
  11288. Event.clear(elm);
  11289. self.execCallback('remove_instance_callback', self);
  11290. self.onRemove.dispatch(self);
  11291. // Clear all execCommand listeners this is required to avoid errors if the editor was removed inside another command
  11292. self.onExecCommand.listeners = [];
  11293. tinymce.remove(self);
  11294. DOM.remove(elm);
  11295. }
  11296. },
  11297. destroy : function(s) {
  11298. var t = this;
  11299. // One time is enough
  11300. if (t.destroyed)
  11301. return;
  11302. // We must unbind on Gecko since it would otherwise produce the pesky "attempt to run compile-and-go script on a cleared scope" message
  11303. if (isGecko) {
  11304. Event.unbind(t.getDoc());
  11305. Event.unbind(t.getWin());
  11306. Event.unbind(t.getBody());
  11307. }
  11308. if (!s) {
  11309. tinymce.removeUnload(t.destroy);
  11310. tinyMCE.onBeforeUnload.remove(t._beforeUnload);
  11311. // Manual destroy
  11312. if (t.theme && t.theme.destroy)
  11313. t.theme.destroy();
  11314. // Destroy controls, selection and dom
  11315. t.controlManager.destroy();
  11316. t.selection.destroy();
  11317. t.dom.destroy();
  11318. }
  11319. if (t.formElement) {
  11320. t.formElement.submit = t.formElement._mceOldSubmit;
  11321. t.formElement._mceOldSubmit = null;
  11322. }
  11323. t.contentAreaContainer = t.formElement = t.container = t.settings.content_element = t.bodyElement = t.contentDocument = t.contentWindow = null;
  11324. if (t.selection)
  11325. t.selection = t.selection.win = t.selection.dom = t.selection.dom.doc = null;
  11326. t.destroyed = 1;
  11327. },
  11328. // Internal functions
  11329. _refreshContentEditable : function() {
  11330. var self = this, body, parent;
  11331. // Check if the editor was hidden and the re-initalize contentEditable mode by removing and adding the body again
  11332. if (self._isHidden()) {
  11333. body = self.getBody();
  11334. parent = body.parentNode;
  11335. parent.removeChild(body);
  11336. parent.appendChild(body);
  11337. body.focus();
  11338. }
  11339. },
  11340. _isHidden : function() {
  11341. var s;
  11342. if (!isGecko)
  11343. return 0;
  11344. // Weird, wheres that cursor selection?
  11345. s = this.selection.getSel();
  11346. return (!s || !s.rangeCount || s.rangeCount === 0);
  11347. }
  11348. });
  11349. })(tinymce);
  11350. (function(tinymce) {
  11351. var each = tinymce.each;
  11352. tinymce.Editor.prototype.setupEvents = function() {
  11353. var self = this, settings = self.settings;
  11354. // Add events to the editor
  11355. each([
  11356. 'onPreInit',
  11357. 'onBeforeRenderUI',
  11358. 'onPostRender',
  11359. 'onLoad',
  11360. 'onInit',
  11361. 'onRemove',
  11362. 'onActivate',
  11363. 'onDeactivate',
  11364. 'onClick',
  11365. 'onEvent',
  11366. 'onMouseUp',
  11367. 'onMouseDown',
  11368. 'onDblClick',
  11369. 'onKeyDown',
  11370. 'onKeyUp',
  11371. 'onKeyPress',
  11372. 'onContextMenu',
  11373. 'onSubmit',
  11374. 'onReset',
  11375. 'onPaste',
  11376. 'onPreProcess',
  11377. 'onPostProcess',
  11378. 'onBeforeSetContent',
  11379. 'onBeforeGetContent',
  11380. 'onSetContent',
  11381. 'onGetContent',
  11382. 'onLoadContent',
  11383. 'onSaveContent',
  11384. 'onNodeChange',
  11385. 'onChange',
  11386. 'onBeforeExecCommand',
  11387. 'onExecCommand',
  11388. 'onUndo',
  11389. 'onRedo',
  11390. 'onVisualAid',
  11391. 'onSetProgressState',
  11392. 'onSetAttrib'
  11393. ], function(name) {
  11394. self[name] = new tinymce.util.Dispatcher(self);
  11395. });
  11396. // Handle legacy cleanup_callback option
  11397. if (settings.cleanup_callback) {
  11398. self.onBeforeSetContent.add(function(ed, o) {
  11399. o.content = ed.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  11400. });
  11401. self.onPreProcess.add(function(ed, o) {
  11402. if (o.set)
  11403. ed.execCallback('cleanup_callback', 'insert_to_editor_dom', o.node, o);
  11404. if (o.get)
  11405. ed.execCallback('cleanup_callback', 'get_from_editor_dom', o.node, o);
  11406. });
  11407. self.onPostProcess.add(function(ed, o) {
  11408. if (o.set)
  11409. o.content = ed.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  11410. if (o.get)
  11411. o.content = ed.execCallback('cleanup_callback', 'get_from_editor', o.content, o);
  11412. });
  11413. }
  11414. // Handle legacy save_callback option
  11415. if (settings.save_callback) {
  11416. self.onGetContent.add(function(ed, o) {
  11417. if (o.save)
  11418. o.content = ed.execCallback('save_callback', ed.id, o.content, ed.getBody());
  11419. });
  11420. }
  11421. // Handle legacy handle_event_callback option
  11422. if (settings.handle_event_callback) {
  11423. self.onEvent.add(function(ed, e, o) {
  11424. if (self.execCallback('handle_event_callback', e, ed, o) === false) {
  11425. e.preventDefault();
  11426. e.stopPropagation();
  11427. }
  11428. });
  11429. }
  11430. // Handle legacy handle_node_change_callback option
  11431. if (settings.handle_node_change_callback) {
  11432. self.onNodeChange.add(function(ed, cm, n) {
  11433. ed.execCallback('handle_node_change_callback', ed.id, n, -1, -1, true, ed.selection.isCollapsed());
  11434. });
  11435. }
  11436. // Handle legacy save_callback option
  11437. if (settings.save_callback) {
  11438. self.onSaveContent.add(function(ed, o) {
  11439. var h = ed.execCallback('save_callback', ed.id, o.content, ed.getBody());
  11440. if (h)
  11441. o.content = h;
  11442. });
  11443. }
  11444. // Handle legacy onchange_callback option
  11445. if (settings.onchange_callback) {
  11446. self.onChange.add(function(ed, l) {
  11447. ed.execCallback('onchange_callback', ed, l);
  11448. });
  11449. }
  11450. };
  11451. tinymce.Editor.prototype.bindNativeEvents = function() {
  11452. // 'focus', 'blur', 'dblclick', 'beforedeactivate', submit, reset
  11453. var self = this, i, settings = self.settings, dom = self.dom, nativeToDispatcherMap;
  11454. nativeToDispatcherMap = {
  11455. mouseup : 'onMouseUp',
  11456. mousedown : 'onMouseDown',
  11457. click : 'onClick',
  11458. keyup : 'onKeyUp',
  11459. keydown : 'onKeyDown',
  11460. keypress : 'onKeyPress',
  11461. submit : 'onSubmit',
  11462. reset : 'onReset',
  11463. contextmenu : 'onContextMenu',
  11464. dblclick : 'onDblClick',
  11465. paste : 'onPaste' // Doesn't work in all browsers yet
  11466. };
  11467. // Handler that takes a native event and sends it out to a dispatcher like onKeyDown
  11468. function eventHandler(evt, args) {
  11469. var type = evt.type;
  11470. // Don't fire events when it's removed
  11471. if (self.removed)
  11472. return;
  11473. // Sends the native event out to a global dispatcher then to the specific event dispatcher
  11474. if (self.onEvent.dispatch(self, evt, args) !== false) {
  11475. self[nativeToDispatcherMap[evt.fakeType || evt.type]].dispatch(self, evt, args);
  11476. }
  11477. };
  11478. // Opera doesn't support focus event for contentEditable elements so we need to fake it
  11479. function doOperaFocus(e) {
  11480. self.focus(true);
  11481. };
  11482. function nodeChanged(ed, e) {
  11483. // 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
  11484. if (e.keyCode != 65 || !tinymce.VK.metaKeyPressed(e)) {
  11485. self.selection.normalize();
  11486. }
  11487. self.nodeChanged();
  11488. }
  11489. // Add DOM events
  11490. each(nativeToDispatcherMap, function(dispatcherName, nativeName) {
  11491. var root = settings.content_editable ? self.getBody() : self.getDoc();
  11492. switch (nativeName) {
  11493. case 'contextmenu':
  11494. dom.bind(root, nativeName, eventHandler);
  11495. break;
  11496. case 'paste':
  11497. dom.bind(self.getBody(), nativeName, eventHandler);
  11498. break;
  11499. case 'submit':
  11500. case 'reset':
  11501. dom.bind(self.getElement().form || tinymce.DOM.getParent(self.id, 'form'), nativeName, eventHandler);
  11502. break;
  11503. default:
  11504. dom.bind(root, nativeName, eventHandler);
  11505. }
  11506. });
  11507. // Set the editor as active when focused
  11508. dom.bind(settings.content_editable ? self.getBody() : (tinymce.isGecko ? self.getDoc() : self.getWin()), 'focus', function(e) {
  11509. self.focus(true);
  11510. });
  11511. if (settings.content_editable && tinymce.isOpera) {
  11512. dom.bind(self.getBody(), 'click', doOperaFocus);
  11513. dom.bind(self.getBody(), 'keydown', doOperaFocus);
  11514. }
  11515. // Add node change handler
  11516. self.onMouseUp.add(nodeChanged);
  11517. self.onKeyUp.add(function(ed, e) {
  11518. var keyCode = e.keyCode;
  11519. 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)
  11520. nodeChanged(ed, e);
  11521. });
  11522. // Add reset handler
  11523. self.onReset.add(function() {
  11524. self.setContent(self.startContent, {format : 'raw'});
  11525. });
  11526. // Add shortcuts
  11527. function handleShortcut(e, execute) {
  11528. if (e.altKey || e.ctrlKey || e.metaKey) {
  11529. each(self.shortcuts, function(shortcut) {
  11530. var ctrlState = tinymce.isMac ? e.metaKey : e.ctrlKey;
  11531. if (shortcut.ctrl != ctrlState || shortcut.alt != e.altKey || shortcut.shift != e.shiftKey)
  11532. return;
  11533. if (e.keyCode == shortcut.keyCode || (e.charCode && e.charCode == shortcut.charCode)) {
  11534. e.preventDefault();
  11535. if (execute) {
  11536. shortcut.func.call(shortcut.scope);
  11537. }
  11538. return true;
  11539. }
  11540. });
  11541. }
  11542. };
  11543. self.onKeyUp.add(function(ed, e) {
  11544. handleShortcut(e);
  11545. });
  11546. self.onKeyPress.add(function(ed, e) {
  11547. handleShortcut(e);
  11548. });
  11549. self.onKeyDown.add(function(ed, e) {
  11550. handleShortcut(e, true);
  11551. });
  11552. if (tinymce.isOpera) {
  11553. self.onClick.add(function(ed, e) {
  11554. e.preventDefault();
  11555. });
  11556. }
  11557. };
  11558. })(tinymce);
  11559. (function(tinymce) {
  11560. // Added for compression purposes
  11561. var each = tinymce.each, undef, TRUE = true, FALSE = false;
  11562. tinymce.EditorCommands = function(editor) {
  11563. var dom = editor.dom,
  11564. selection = editor.selection,
  11565. commands = {state: {}, exec : {}, value : {}},
  11566. settings = editor.settings,
  11567. formatter = editor.formatter,
  11568. bookmark;
  11569. function execCommand(command, ui, value) {
  11570. var func;
  11571. command = command.toLowerCase();
  11572. if (func = commands.exec[command]) {
  11573. func(command, ui, value);
  11574. return TRUE;
  11575. }
  11576. return FALSE;
  11577. };
  11578. function queryCommandState(command) {
  11579. var func;
  11580. command = command.toLowerCase();
  11581. if (func = commands.state[command])
  11582. return func(command);
  11583. return -1;
  11584. };
  11585. function queryCommandValue(command) {
  11586. var func;
  11587. command = command.toLowerCase();
  11588. if (func = commands.value[command])
  11589. return func(command);
  11590. return FALSE;
  11591. };
  11592. function addCommands(command_list, type) {
  11593. type = type || 'exec';
  11594. each(command_list, function(callback, command) {
  11595. each(command.toLowerCase().split(','), function(command) {
  11596. commands[type][command] = callback;
  11597. });
  11598. });
  11599. };
  11600. // Expose public methods
  11601. tinymce.extend(this, {
  11602. execCommand : execCommand,
  11603. queryCommandState : queryCommandState,
  11604. queryCommandValue : queryCommandValue,
  11605. addCommands : addCommands
  11606. });
  11607. // Private methods
  11608. function execNativeCommand(command, ui, value) {
  11609. if (ui === undef)
  11610. ui = FALSE;
  11611. if (value === undef)
  11612. value = null;
  11613. return editor.getDoc().execCommand(command, ui, value);
  11614. };
  11615. function isFormatMatch(name) {
  11616. return formatter.match(name);
  11617. };
  11618. function toggleFormat(name, value) {
  11619. formatter.toggle(name, value ? {value : value} : undef);
  11620. };
  11621. function storeSelection(type) {
  11622. bookmark = selection.getBookmark(type);
  11623. };
  11624. function restoreSelection() {
  11625. selection.moveToBookmark(bookmark);
  11626. };
  11627. // Add execCommand overrides
  11628. addCommands({
  11629. // Ignore these, added for compatibility
  11630. 'mceResetDesignMode,mceBeginUndoLevel' : function() {},
  11631. // Add undo manager logic
  11632. 'mceEndUndoLevel,mceAddUndoLevel' : function() {
  11633. editor.undoManager.add();
  11634. },
  11635. 'Cut,Copy,Paste' : function(command) {
  11636. var doc = editor.getDoc(), failed;
  11637. // Try executing the native command
  11638. try {
  11639. execNativeCommand(command);
  11640. } catch (ex) {
  11641. // Command failed
  11642. failed = TRUE;
  11643. }
  11644. // Present alert message about clipboard access not being available
  11645. if (failed || !doc.queryCommandSupported(command)) {
  11646. if (tinymce.isGecko) {
  11647. editor.windowManager.confirm(editor.getLang('clipboard_msg'), function(state) {
  11648. if (state)
  11649. open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', '_blank');
  11650. });
  11651. } else
  11652. editor.windowManager.alert(editor.getLang('clipboard_no_support'));
  11653. }
  11654. },
  11655. // Override unlink command
  11656. unlink : function(command) {
  11657. if (selection.isCollapsed())
  11658. selection.select(selection.getNode());
  11659. execNativeCommand(command);
  11660. selection.collapse(FALSE);
  11661. },
  11662. // Override justify commands to use the text formatter engine
  11663. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  11664. var align = command.substring(7);
  11665. // Remove all other alignments first
  11666. each('left,center,right,full'.split(','), function(name) {
  11667. if (align != name)
  11668. formatter.remove('align' + name);
  11669. });
  11670. toggleFormat('align' + align);
  11671. execCommand('mceRepaint');
  11672. },
  11673. // Override list commands to fix WebKit bug
  11674. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  11675. var listElm, listParent;
  11676. execNativeCommand(command);
  11677. // WebKit produces lists within block elements so we need to split them
  11678. // we will replace the native list creation logic to custom logic later on
  11679. // TODO: Remove this when the list creation logic is removed
  11680. listElm = dom.getParent(selection.getNode(), 'ol,ul');
  11681. if (listElm) {
  11682. listParent = listElm.parentNode;
  11683. // If list is within a text block then split that block
  11684. if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) {
  11685. storeSelection();
  11686. dom.split(listParent, listElm);
  11687. restoreSelection();
  11688. }
  11689. }
  11690. },
  11691. // Override commands to use the text formatter engine
  11692. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
  11693. toggleFormat(command);
  11694. },
  11695. // Override commands to use the text formatter engine
  11696. 'ForeColor,HiliteColor,FontName' : function(command, ui, value) {
  11697. toggleFormat(command, value);
  11698. },
  11699. FontSize : function(command, ui, value) {
  11700. var fontClasses, fontSizes;
  11701. // Convert font size 1-7 to styles
  11702. if (value >= 1 && value <= 7) {
  11703. fontSizes = tinymce.explode(settings.font_size_style_values);
  11704. fontClasses = tinymce.explode(settings.font_size_classes);
  11705. if (fontClasses)
  11706. value = fontClasses[value - 1] || value;
  11707. else
  11708. value = fontSizes[value - 1] || value;
  11709. }
  11710. toggleFormat(command, value);
  11711. },
  11712. RemoveFormat : function(command) {
  11713. formatter.remove(command);
  11714. },
  11715. mceBlockQuote : function(command) {
  11716. toggleFormat('blockquote');
  11717. },
  11718. FormatBlock : function(command, ui, value) {
  11719. return toggleFormat(value || 'p');
  11720. },
  11721. mceCleanup : function() {
  11722. var bookmark = selection.getBookmark();
  11723. editor.setContent(editor.getContent({cleanup : TRUE}), {cleanup : TRUE});
  11724. selection.moveToBookmark(bookmark);
  11725. },
  11726. mceRemoveNode : function(command, ui, value) {
  11727. var node = value || selection.getNode();
  11728. // Make sure that the body node isn't removed
  11729. if (node != editor.getBody()) {
  11730. storeSelection();
  11731. editor.dom.remove(node, TRUE);
  11732. restoreSelection();
  11733. }
  11734. },
  11735. mceSelectNodeDepth : function(command, ui, value) {
  11736. var counter = 0;
  11737. dom.getParent(selection.getNode(), function(node) {
  11738. if (node.nodeType == 1 && counter++ == value) {
  11739. selection.select(node);
  11740. return FALSE;
  11741. }
  11742. }, editor.getBody());
  11743. },
  11744. mceSelectNode : function(command, ui, value) {
  11745. selection.select(value);
  11746. },
  11747. mceInsertContent : function(command, ui, value) {
  11748. var parser, serializer, parentNode, rootNode, fragment, args,
  11749. marker, nodeRect, viewPortRect, rng, node, node2, bookmarkHtml, viewportBodyElement;
  11750. //selection.normalize();
  11751. // Setup parser and serializer
  11752. parser = editor.parser;
  11753. serializer = new tinymce.html.Serializer({}, editor.schema);
  11754. bookmarkHtml = '<span id="mce_marker" data-mce-type="bookmark">\uFEFF</span>';
  11755. // Run beforeSetContent handlers on the HTML to be inserted
  11756. args = {content: value, format: 'html'};
  11757. selection.onBeforeSetContent.dispatch(selection, args);
  11758. value = args.content;
  11759. // Add caret at end of contents if it's missing
  11760. if (value.indexOf('{$caret}') == -1)
  11761. value += '{$caret}';
  11762. // Replace the caret marker with a span bookmark element
  11763. value = value.replace(/\{\$caret\}/, bookmarkHtml);
  11764. // Insert node maker where we will insert the new HTML and get it's parent
  11765. if (!selection.isCollapsed())
  11766. editor.getDoc().execCommand('Delete', false, null);
  11767. parentNode = selection.getNode();
  11768. // Parse the fragment within the context of the parent node
  11769. args = {context : parentNode.nodeName.toLowerCase()};
  11770. fragment = parser.parse(value, args);
  11771. // Move the caret to a more suitable location
  11772. node = fragment.lastChild;
  11773. if (node.attr('id') == 'mce_marker') {
  11774. marker = node;
  11775. for (node = node.prev; node; node = node.walk(true)) {
  11776. if (node.type == 3 || !dom.isBlock(node.name)) {
  11777. node.parent.insert(marker, node, node.name === 'br');
  11778. break;
  11779. }
  11780. }
  11781. }
  11782. // If parser says valid we can insert the contents into that parent
  11783. if (!args.invalid) {
  11784. value = serializer.serialize(fragment);
  11785. // Check if parent is empty or only has one BR element then set the innerHTML of that parent
  11786. node = parentNode.firstChild;
  11787. node2 = parentNode.lastChild;
  11788. if (!node || (node === node2 && node.nodeName === 'BR'))
  11789. dom.setHTML(parentNode, value);
  11790. else
  11791. selection.setContent(value);
  11792. } else {
  11793. // If the fragment was invalid within that context then we need
  11794. // to parse and process the parent it's inserted into
  11795. // Insert bookmark node and get the parent
  11796. selection.setContent(bookmarkHtml);
  11797. parentNode = editor.selection.getNode();
  11798. rootNode = editor.getBody();
  11799. // Opera will return the document node when selection is in root
  11800. if (parentNode.nodeType == 9)
  11801. parentNode = node = rootNode;
  11802. else
  11803. node = parentNode;
  11804. // Find the ancestor just before the root element
  11805. while (node !== rootNode) {
  11806. parentNode = node;
  11807. node = node.parentNode;
  11808. }
  11809. // Get the outer/inner HTML depending on if we are in the root and parser and serialize that
  11810. value = parentNode == rootNode ? rootNode.innerHTML : dom.getOuterHTML(parentNode);
  11811. value = serializer.serialize(
  11812. parser.parse(
  11813. // Need to replace by using a function since $ in the contents would otherwise be a problem
  11814. value.replace(/<span (id="mce_marker"|id=mce_marker).+?<\/span>/i, function() {
  11815. return serializer.serialize(fragment);
  11816. })
  11817. )
  11818. );
  11819. // Set the inner/outer HTML depending on if we are in the root or not
  11820. if (parentNode == rootNode)
  11821. dom.setHTML(rootNode, value);
  11822. else
  11823. dom.setOuterHTML(parentNode, value);
  11824. }
  11825. marker = dom.get('mce_marker');
  11826. // Scroll range into view scrollIntoView on element can't be used since it will scroll the main view port as well
  11827. nodeRect = dom.getRect(marker);
  11828. viewPortRect = dom.getViewPort(editor.getWin());
  11829. // Check if node is out side the viewport if it is then scroll to it
  11830. if ((nodeRect.y + nodeRect.h > viewPortRect.y + viewPortRect.h || nodeRect.y < viewPortRect.y) ||
  11831. (nodeRect.x > viewPortRect.x + viewPortRect.w || nodeRect.x < viewPortRect.x)) {
  11832. viewportBodyElement = tinymce.isIE ? editor.getDoc().documentElement : editor.getBody();
  11833. viewportBodyElement.scrollLeft = nodeRect.x;
  11834. viewportBodyElement.scrollTop = nodeRect.y - viewPortRect.h + 25;
  11835. }
  11836. // Move selection before marker and remove it
  11837. rng = dom.createRng();
  11838. // If previous sibling is a text node set the selection to the end of that node
  11839. node = marker.previousSibling;
  11840. if (node && node.nodeType == 3) {
  11841. rng.setStart(node, node.nodeValue.length);
  11842. } else {
  11843. // If the previous sibling isn't a text node or doesn't exist set the selection before the marker node
  11844. rng.setStartBefore(marker);
  11845. rng.setEndBefore(marker);
  11846. }
  11847. // Remove the marker node and set the new range
  11848. dom.remove(marker);
  11849. selection.setRng(rng);
  11850. // Dispatch after event and add any visual elements needed
  11851. selection.onSetContent.dispatch(selection, args);
  11852. editor.addVisual();
  11853. },
  11854. mceInsertRawHTML : function(command, ui, value) {
  11855. selection.setContent('tiny_mce_marker');
  11856. editor.setContent(editor.getContent().replace(/tiny_mce_marker/g, function() { return value }));
  11857. },
  11858. mceToggleFormat : function(command, ui, value) {
  11859. toggleFormat(value);
  11860. },
  11861. mceSetContent : function(command, ui, value) {
  11862. editor.setContent(value);
  11863. },
  11864. 'Indent,Outdent' : function(command) {
  11865. var intentValue, indentUnit, value;
  11866. // Setup indent level
  11867. intentValue = settings.indentation;
  11868. indentUnit = /[a-z%]+$/i.exec(intentValue);
  11869. intentValue = parseInt(intentValue);
  11870. if (!queryCommandState('InsertUnorderedList') && !queryCommandState('InsertOrderedList')) {
  11871. // If forced_root_blocks is set to false we don't have a block to indent so lets create a div
  11872. if (!settings.forced_root_block && !dom.getParent(selection.getNode(), dom.isBlock)) {
  11873. formatter.apply('div');
  11874. }
  11875. each(selection.getSelectedBlocks(), function(element) {
  11876. if (command == 'outdent') {
  11877. value = Math.max(0, parseInt(element.style.paddingLeft || 0) - intentValue);
  11878. dom.setStyle(element, 'paddingLeft', value ? value + indentUnit : '');
  11879. } else
  11880. dom.setStyle(element, 'paddingLeft', (parseInt(element.style.paddingLeft || 0) + intentValue) + indentUnit);
  11881. });
  11882. } else
  11883. execNativeCommand(command);
  11884. },
  11885. mceRepaint : function() {
  11886. var bookmark;
  11887. if (tinymce.isGecko) {
  11888. try {
  11889. storeSelection(TRUE);
  11890. if (selection.getSel())
  11891. selection.getSel().selectAllChildren(editor.getBody());
  11892. selection.collapse(TRUE);
  11893. restoreSelection();
  11894. } catch (ex) {
  11895. // Ignore
  11896. }
  11897. }
  11898. },
  11899. mceToggleFormat : function(command, ui, value) {
  11900. formatter.toggle(value);
  11901. },
  11902. InsertHorizontalRule : function() {
  11903. editor.execCommand('mceInsertContent', false, '<hr />');
  11904. },
  11905. mceToggleVisualAid : function() {
  11906. editor.hasVisual = !editor.hasVisual;
  11907. editor.addVisual();
  11908. },
  11909. mceReplaceContent : function(command, ui, value) {
  11910. editor.execCommand('mceInsertContent', false, value.replace(/\{\$selection\}/g, selection.getContent({format : 'text'})));
  11911. },
  11912. mceInsertLink : function(command, ui, value) {
  11913. var anchor;
  11914. if (typeof(value) == 'string')
  11915. value = {href : value};
  11916. anchor = dom.getParent(selection.getNode(), 'a');
  11917. // Spaces are never valid in URLs and it's a very common mistake for people to make so we fix it here.
  11918. value.href = value.href.replace(' ', '%20');
  11919. // Remove existing links if there could be child links or that the href isn't specified
  11920. if (!anchor || !value.href) {
  11921. formatter.remove('link');
  11922. }
  11923. // Apply new link to selection
  11924. if (value.href) {
  11925. formatter.apply('link', value, anchor);
  11926. }
  11927. },
  11928. selectAll : function() {
  11929. var root = dom.getRoot(), rng = dom.createRng();
  11930. rng.setStart(root, 0);
  11931. rng.setEnd(root, root.childNodes.length);
  11932. editor.selection.setRng(rng);
  11933. }
  11934. });
  11935. // Add queryCommandState overrides
  11936. addCommands({
  11937. // Override justify commands
  11938. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  11939. var name = 'align' + command.substring(7);
  11940. var nodes = selection.isCollapsed() ? [dom.getParent(selection.getNode(), dom.isBlock)] : selection.getSelectedBlocks();
  11941. var matches = tinymce.map(nodes, function(node) {
  11942. return !!formatter.matchNode(node, name);
  11943. });
  11944. return tinymce.inArray(matches, TRUE) !== -1;
  11945. },
  11946. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
  11947. return isFormatMatch(command);
  11948. },
  11949. mceBlockQuote : function() {
  11950. return isFormatMatch('blockquote');
  11951. },
  11952. Outdent : function() {
  11953. var node;
  11954. if (settings.inline_styles) {
  11955. if ((node = dom.getParent(selection.getStart(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  11956. return TRUE;
  11957. if ((node = dom.getParent(selection.getEnd(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  11958. return TRUE;
  11959. }
  11960. return queryCommandState('InsertUnorderedList') || queryCommandState('InsertOrderedList') || (!settings.inline_styles && !!dom.getParent(selection.getNode(), 'BLOCKQUOTE'));
  11961. },
  11962. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  11963. return dom.getParent(selection.getNode(), command == 'insertunorderedlist' ? 'UL' : 'OL');
  11964. }
  11965. }, 'state');
  11966. // Add queryCommandValue overrides
  11967. addCommands({
  11968. 'FontSize,FontName' : function(command) {
  11969. var value = 0, parent;
  11970. if (parent = dom.getParent(selection.getNode(), 'span')) {
  11971. if (command == 'fontsize')
  11972. value = parent.style.fontSize;
  11973. else
  11974. value = parent.style.fontFamily.replace(/, /g, ',').replace(/[\'\"]/g, '').toLowerCase();
  11975. }
  11976. return value;
  11977. }
  11978. }, 'value');
  11979. // Add undo manager logic
  11980. addCommands({
  11981. Undo : function() {
  11982. editor.undoManager.undo();
  11983. },
  11984. Redo : function() {
  11985. editor.undoManager.redo();
  11986. }
  11987. });
  11988. };
  11989. })(tinymce);
  11990. (function(tinymce) {
  11991. var Dispatcher = tinymce.util.Dispatcher;
  11992. tinymce.UndoManager = function(editor) {
  11993. var self, index = 0, data = [], beforeBookmark, onAdd, onUndo, onRedo;
  11994. function getContent() {
  11995. // Remove whitespace before/after and remove pure bogus nodes
  11996. return tinymce.trim(editor.getContent({format : 'raw', no_events : 1}).replace(/<span[^>]+data-mce-bogus[^>]+>[\u200B\uFEFF]+<\/span>/g, ''));
  11997. };
  11998. function addNonTypingUndoLevel() {
  11999. self.typing = false;
  12000. self.add();
  12001. };
  12002. // Create event instances
  12003. onBeforeAdd = new Dispatcher(self);
  12004. onAdd = new Dispatcher(self);
  12005. onUndo = new Dispatcher(self);
  12006. onRedo = new Dispatcher(self);
  12007. // Pass though onAdd event from UndoManager to Editor as onChange
  12008. onAdd.add(function(undoman, level) {
  12009. if (undoman.hasUndo())
  12010. return editor.onChange.dispatch(editor, level, undoman);
  12011. });
  12012. // Pass though onUndo event from UndoManager to Editor
  12013. onUndo.add(function(undoman, level) {
  12014. return editor.onUndo.dispatch(editor, level, undoman);
  12015. });
  12016. // Pass though onRedo event from UndoManager to Editor
  12017. onRedo.add(function(undoman, level) {
  12018. return editor.onRedo.dispatch(editor, level, undoman);
  12019. });
  12020. // Add initial undo level when the editor is initialized
  12021. editor.onInit.add(function() {
  12022. self.add();
  12023. });
  12024. // Get position before an execCommand is processed
  12025. editor.onBeforeExecCommand.add(function(ed, cmd, ui, val, args) {
  12026. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!args || !args.skip_undo)) {
  12027. self.beforeChange();
  12028. }
  12029. });
  12030. // Add undo level after an execCommand call was made
  12031. editor.onExecCommand.add(function(ed, cmd, ui, val, args) {
  12032. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!args || !args.skip_undo)) {
  12033. self.add();
  12034. }
  12035. });
  12036. // Add undo level on save contents, drag end and blur/focusout
  12037. editor.onSaveContent.add(addNonTypingUndoLevel);
  12038. editor.dom.bind(editor.dom.getRoot(), 'dragend', addNonTypingUndoLevel);
  12039. editor.dom.bind(editor.getDoc(), tinymce.isGecko ? 'blur' : 'focusout', function(e) {
  12040. if (!editor.removed && self.typing) {
  12041. addNonTypingUndoLevel();
  12042. }
  12043. });
  12044. editor.onKeyUp.add(function(editor, e) {
  12045. var keyCode = e.keyCode;
  12046. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 45 || keyCode == 13 || e.ctrlKey) {
  12047. addNonTypingUndoLevel();
  12048. }
  12049. });
  12050. editor.onKeyDown.add(function(editor, e) {
  12051. var keyCode = e.keyCode;
  12052. // Is caracter positon keys left,right,up,down,home,end,pgdown,pgup,enter
  12053. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 45) {
  12054. if (self.typing) {
  12055. addNonTypingUndoLevel();
  12056. }
  12057. return;
  12058. }
  12059. // If key isn't shift,ctrl,alt,capslock,metakey
  12060. if ((keyCode < 16 || keyCode > 20) && keyCode != 224 && keyCode != 91 && !self.typing) {
  12061. self.beforeChange();
  12062. self.typing = true;
  12063. self.add();
  12064. }
  12065. });
  12066. editor.onMouseDown.add(function(editor, e) {
  12067. if (self.typing) {
  12068. addNonTypingUndoLevel();
  12069. }
  12070. });
  12071. // Add keyboard shortcuts for undo/redo keys
  12072. editor.addShortcut('ctrl+z', 'undo_desc', 'Undo');
  12073. editor.addShortcut('ctrl+y', 'redo_desc', 'Redo');
  12074. self = {
  12075. // Explose for debugging reasons
  12076. data : data,
  12077. typing : false,
  12078. onBeforeAdd: onBeforeAdd,
  12079. onAdd : onAdd,
  12080. onUndo : onUndo,
  12081. onRedo : onRedo,
  12082. beforeChange : function() {
  12083. beforeBookmark = editor.selection.getBookmark(2, true);
  12084. },
  12085. add : function(level) {
  12086. var i, settings = editor.settings, lastLevel;
  12087. level = level || {};
  12088. level.content = getContent();
  12089. self.onBeforeAdd.dispatch(self, level);
  12090. // Add undo level if needed
  12091. lastLevel = data[index];
  12092. if (lastLevel && lastLevel.content == level.content)
  12093. return null;
  12094. // Set before bookmark on previous level
  12095. if (data[index])
  12096. data[index].beforeBookmark = beforeBookmark;
  12097. // Time to compress
  12098. if (settings.custom_undo_redo_levels) {
  12099. if (data.length > settings.custom_undo_redo_levels) {
  12100. for (i = 0; i < data.length - 1; i++)
  12101. data[i] = data[i + 1];
  12102. data.length--;
  12103. index = data.length;
  12104. }
  12105. }
  12106. // Get a non intrusive normalized bookmark
  12107. level.bookmark = editor.selection.getBookmark(2, true);
  12108. // Crop array if needed
  12109. if (index < data.length - 1)
  12110. data.length = index + 1;
  12111. data.push(level);
  12112. index = data.length - 1;
  12113. self.onAdd.dispatch(self, level);
  12114. editor.isNotDirty = 0;
  12115. return level;
  12116. },
  12117. undo : function() {
  12118. var level, i;
  12119. if (self.typing) {
  12120. self.add();
  12121. self.typing = false;
  12122. }
  12123. if (index > 0) {
  12124. level = data[--index];
  12125. editor.setContent(level.content, {format : 'raw'});
  12126. editor.selection.moveToBookmark(level.beforeBookmark);
  12127. self.onUndo.dispatch(self, level);
  12128. }
  12129. return level;
  12130. },
  12131. redo : function() {
  12132. var level;
  12133. if (index < data.length - 1) {
  12134. level = data[++index];
  12135. editor.setContent(level.content, {format : 'raw'});
  12136. editor.selection.moveToBookmark(level.bookmark);
  12137. self.onRedo.dispatch(self, level);
  12138. }
  12139. return level;
  12140. },
  12141. clear : function() {
  12142. data = [];
  12143. index = 0;
  12144. self.typing = false;
  12145. },
  12146. hasUndo : function() {
  12147. return index > 0 || this.typing;
  12148. },
  12149. hasRedo : function() {
  12150. return index < data.length - 1 && !this.typing;
  12151. }
  12152. };
  12153. return self;
  12154. };
  12155. })(tinymce);
  12156. tinymce.ForceBlocks = function(editor) {
  12157. var settings = editor.settings, dom = editor.dom, selection = editor.selection, blockElements = editor.schema.getBlockElements();
  12158. function addRootBlocks() {
  12159. var node = selection.getStart(), rootNode = editor.getBody(), rng, startContainer, startOffset, endContainer, endOffset, rootBlockNode, tempNode, offset = -0xFFFFFF, wrapped, isInEditorDocument;
  12160. if (!node || node.nodeType !== 1 || !settings.forced_root_block)
  12161. return;
  12162. // Check if node is wrapped in block
  12163. while (node && node != rootNode) {
  12164. if (blockElements[node.nodeName])
  12165. return;
  12166. node = node.parentNode;
  12167. }
  12168. // Get current selection
  12169. rng = selection.getRng();
  12170. if (rng.setStart) {
  12171. startContainer = rng.startContainer;
  12172. startOffset = rng.startOffset;
  12173. endContainer = rng.endContainer;
  12174. endOffset = rng.endOffset;
  12175. } else {
  12176. // Force control range into text range
  12177. if (rng.item) {
  12178. node = rng.item(0);
  12179. rng = editor.getDoc().body.createTextRange();
  12180. rng.moveToElementText(node);
  12181. }
  12182. isInEditorDocument = rng.parentElement().ownerDocument === editor.getDoc();
  12183. tmpRng = rng.duplicate();
  12184. tmpRng.collapse(true);
  12185. startOffset = tmpRng.move('character', offset) * -1;
  12186. if (!tmpRng.collapsed) {
  12187. tmpRng = rng.duplicate();
  12188. tmpRng.collapse(false);
  12189. endOffset = (tmpRng.move('character', offset) * -1) - startOffset;
  12190. }
  12191. }
  12192. // Wrap non block elements and text nodes
  12193. node = rootNode.firstChild;
  12194. while (node) {
  12195. if (node.nodeType === 3 || (node.nodeType == 1 && !blockElements[node.nodeName])) {
  12196. if (!rootBlockNode) {
  12197. rootBlockNode = dom.create(settings.forced_root_block);
  12198. node.parentNode.insertBefore(rootBlockNode, node);
  12199. wrapped = true;
  12200. }
  12201. tempNode = node;
  12202. node = node.nextSibling;
  12203. rootBlockNode.appendChild(tempNode);
  12204. } else {
  12205. rootBlockNode = null;
  12206. node = node.nextSibling;
  12207. }
  12208. }
  12209. if (wrapped) {
  12210. if (rng.setStart) {
  12211. rng.setStart(startContainer, startOffset);
  12212. rng.setEnd(endContainer, endOffset);
  12213. selection.setRng(rng);
  12214. } else {
  12215. // Only select if the previous selection was inside the document to prevent auto focus in quirks mode
  12216. if (isInEditorDocument) {
  12217. try {
  12218. rng = editor.getDoc().body.createTextRange();
  12219. rng.moveToElementText(rootNode);
  12220. rng.collapse(true);
  12221. rng.moveStart('character', startOffset);
  12222. if (endOffset > 0)
  12223. rng.moveEnd('character', endOffset);
  12224. rng.select();
  12225. } catch (ex) {
  12226. // Ignore
  12227. }
  12228. }
  12229. }
  12230. editor.nodeChanged();
  12231. }
  12232. };
  12233. // Force root blocks
  12234. if (settings.forced_root_block) {
  12235. editor.onKeyUp.add(addRootBlocks);
  12236. editor.onNodeChange.add(addRootBlocks);
  12237. }
  12238. };
  12239. (function(tinymce) {
  12240. // Shorten names
  12241. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, extend = tinymce.extend;
  12242. tinymce.create('tinymce.ControlManager', {
  12243. ControlManager : function(ed, s) {
  12244. var t = this, i;
  12245. s = s || {};
  12246. t.editor = ed;
  12247. t.controls = {};
  12248. t.onAdd = new tinymce.util.Dispatcher(t);
  12249. t.onPostRender = new tinymce.util.Dispatcher(t);
  12250. t.prefix = s.prefix || ed.id + '_';
  12251. t._cls = {};
  12252. t.onPostRender.add(function() {
  12253. each(t.controls, function(c) {
  12254. c.postRender();
  12255. });
  12256. });
  12257. },
  12258. get : function(id) {
  12259. return this.controls[this.prefix + id] || this.controls[id];
  12260. },
  12261. setActive : function(id, s) {
  12262. var c = null;
  12263. if (c = this.get(id))
  12264. c.setActive(s);
  12265. return c;
  12266. },
  12267. setDisabled : function(id, s) {
  12268. var c = null;
  12269. if (c = this.get(id))
  12270. c.setDisabled(s);
  12271. return c;
  12272. },
  12273. add : function(c) {
  12274. var t = this;
  12275. if (c) {
  12276. t.controls[c.id] = c;
  12277. t.onAdd.dispatch(c, t);
  12278. }
  12279. return c;
  12280. },
  12281. createControl : function(name) {
  12282. var ctrl, i, l, self = this, editor = self.editor, factories, ctrlName;
  12283. // Build control factory cache
  12284. if (!self.controlFactories) {
  12285. self.controlFactories = [];
  12286. each(editor.plugins, function(plugin) {
  12287. if (plugin.createControl) {
  12288. self.controlFactories.push(plugin);
  12289. }
  12290. });
  12291. }
  12292. // Create controls by asking cached factories
  12293. factories = self.controlFactories;
  12294. for (i = 0, l = factories.length; i < l; i++) {
  12295. ctrl = factories[i].createControl(name, self);
  12296. if (ctrl) {
  12297. return self.add(ctrl);
  12298. }
  12299. }
  12300. // Create sepearator
  12301. if (name === "|" || name === "separator") {
  12302. return self.createSeparator();
  12303. }
  12304. // Create control from button collection
  12305. if (editor.buttons && (ctrl = editor.buttons[name])) {
  12306. return self.createButton(name, ctrl);
  12307. }
  12308. return self.add(ctrl);
  12309. },
  12310. createDropMenu : function(id, s, cc) {
  12311. var t = this, ed = t.editor, c, bm, v, cls;
  12312. s = extend({
  12313. 'class' : 'mceDropDown',
  12314. constrain : ed.settings.constrain_menus
  12315. }, s);
  12316. s['class'] = s['class'] + ' ' + ed.getParam('skin') + 'Skin';
  12317. if (v = ed.getParam('skin_variant'))
  12318. s['class'] += ' ' + ed.getParam('skin') + 'Skin' + v.substring(0, 1).toUpperCase() + v.substring(1);
  12319. s['class'] += ed.settings.directionality == "rtl" ? ' mceRtl' : '';
  12320. id = t.prefix + id;
  12321. cls = cc || t._cls.dropmenu || tinymce.ui.DropMenu;
  12322. c = t.controls[id] = new cls(id, s);
  12323. c.onAddItem.add(function(c, o) {
  12324. var s = o.settings;
  12325. s.title = ed.getLang(s.title, s.title);
  12326. if (!s.onclick) {
  12327. s.onclick = function(v) {
  12328. if (s.cmd)
  12329. ed.execCommand(s.cmd, s.ui || false, s.value);
  12330. };
  12331. }
  12332. });
  12333. ed.onRemove.add(function() {
  12334. c.destroy();
  12335. });
  12336. // Fix for bug #1897785, #1898007
  12337. if (tinymce.isIE) {
  12338. c.onShowMenu.add(function() {
  12339. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  12340. ed.focus();
  12341. bm = ed.selection.getBookmark(1);
  12342. });
  12343. c.onHideMenu.add(function() {
  12344. if (bm) {
  12345. ed.selection.moveToBookmark(bm);
  12346. bm = 0;
  12347. }
  12348. });
  12349. }
  12350. return t.add(c);
  12351. },
  12352. createListBox : function(id, s, cc) {
  12353. var t = this, ed = t.editor, cmd, c, cls;
  12354. if (t.get(id))
  12355. return null;
  12356. s.title = ed.translate(s.title);
  12357. s.scope = s.scope || ed;
  12358. if (!s.onselect) {
  12359. s.onselect = function(v) {
  12360. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  12361. };
  12362. }
  12363. s = extend({
  12364. title : s.title,
  12365. 'class' : 'mce_' + id,
  12366. scope : s.scope,
  12367. control_manager : t
  12368. }, s);
  12369. id = t.prefix + id;
  12370. function useNativeListForAccessibility(ed) {
  12371. return ed.settings.use_accessible_selects && !tinymce.isGecko
  12372. }
  12373. if (ed.settings.use_native_selects || useNativeListForAccessibility(ed))
  12374. c = new tinymce.ui.NativeListBox(id, s);
  12375. else {
  12376. cls = cc || t._cls.listbox || tinymce.ui.ListBox;
  12377. c = new cls(id, s, ed);
  12378. }
  12379. t.controls[id] = c;
  12380. // Fix focus problem in Safari
  12381. if (tinymce.isWebKit) {
  12382. c.onPostRender.add(function(c, n) {
  12383. // Store bookmark on mousedown
  12384. Event.add(n, 'mousedown', function() {
  12385. ed.bookmark = ed.selection.getBookmark(1);
  12386. });
  12387. // Restore on focus, since it might be lost
  12388. Event.add(n, 'focus', function() {
  12389. ed.selection.moveToBookmark(ed.bookmark);
  12390. ed.bookmark = null;
  12391. });
  12392. });
  12393. }
  12394. if (c.hideMenu)
  12395. ed.onMouseDown.add(c.hideMenu, c);
  12396. return t.add(c);
  12397. },
  12398. createButton : function(id, s, cc) {
  12399. var t = this, ed = t.editor, o, c, cls;
  12400. if (t.get(id))
  12401. return null;
  12402. s.title = ed.translate(s.title);
  12403. s.label = ed.translate(s.label);
  12404. s.scope = s.scope || ed;
  12405. if (!s.onclick && !s.menu_button) {
  12406. s.onclick = function() {
  12407. ed.execCommand(s.cmd, s.ui || false, s.value);
  12408. };
  12409. }
  12410. s = extend({
  12411. title : s.title,
  12412. 'class' : 'mce_' + id,
  12413. unavailable_prefix : ed.getLang('unavailable', ''),
  12414. scope : s.scope,
  12415. control_manager : t
  12416. }, s);
  12417. id = t.prefix + id;
  12418. if (s.menu_button) {
  12419. cls = cc || t._cls.menubutton || tinymce.ui.MenuButton;
  12420. c = new cls(id, s, ed);
  12421. ed.onMouseDown.add(c.hideMenu, c);
  12422. } else {
  12423. cls = t._cls.button || tinymce.ui.Button;
  12424. c = new cls(id, s, ed);
  12425. }
  12426. return t.add(c);
  12427. },
  12428. createMenuButton : function(id, s, cc) {
  12429. s = s || {};
  12430. s.menu_button = 1;
  12431. return this.createButton(id, s, cc);
  12432. },
  12433. createSplitButton : function(id, s, cc) {
  12434. var t = this, ed = t.editor, cmd, c, cls;
  12435. if (t.get(id))
  12436. return null;
  12437. s.title = ed.translate(s.title);
  12438. s.scope = s.scope || ed;
  12439. if (!s.onclick) {
  12440. s.onclick = function(v) {
  12441. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  12442. };
  12443. }
  12444. if (!s.onselect) {
  12445. s.onselect = function(v) {
  12446. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  12447. };
  12448. }
  12449. s = extend({
  12450. title : s.title,
  12451. 'class' : 'mce_' + id,
  12452. scope : s.scope,
  12453. control_manager : t
  12454. }, s);
  12455. id = t.prefix + id;
  12456. cls = cc || t._cls.splitbutton || tinymce.ui.SplitButton;
  12457. c = t.add(new cls(id, s, ed));
  12458. ed.onMouseDown.add(c.hideMenu, c);
  12459. return c;
  12460. },
  12461. createColorSplitButton : function(id, s, cc) {
  12462. var t = this, ed = t.editor, cmd, c, cls, bm;
  12463. if (t.get(id))
  12464. return null;
  12465. s.title = ed.translate(s.title);
  12466. s.scope = s.scope || ed;
  12467. if (!s.onclick) {
  12468. s.onclick = function(v) {
  12469. if (tinymce.isIE)
  12470. bm = ed.selection.getBookmark(1);
  12471. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  12472. };
  12473. }
  12474. if (!s.onselect) {
  12475. s.onselect = function(v) {
  12476. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  12477. };
  12478. }
  12479. s = extend({
  12480. title : s.title,
  12481. 'class' : 'mce_' + id,
  12482. 'menu_class' : ed.getParam('skin') + 'Skin',
  12483. scope : s.scope,
  12484. more_colors_title : ed.getLang('more_colors')
  12485. }, s);
  12486. id = t.prefix + id;
  12487. cls = cc || t._cls.colorsplitbutton || tinymce.ui.ColorSplitButton;
  12488. c = new cls(id, s, ed);
  12489. ed.onMouseDown.add(c.hideMenu, c);
  12490. // Remove the menu element when the editor is removed
  12491. ed.onRemove.add(function() {
  12492. c.destroy();
  12493. });
  12494. // Fix for bug #1897785, #1898007
  12495. if (tinymce.isIE) {
  12496. c.onShowMenu.add(function() {
  12497. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  12498. ed.focus();
  12499. bm = ed.selection.getBookmark(1);
  12500. });
  12501. c.onHideMenu.add(function() {
  12502. if (bm) {
  12503. ed.selection.moveToBookmark(bm);
  12504. bm = 0;
  12505. }
  12506. });
  12507. }
  12508. return t.add(c);
  12509. },
  12510. createToolbar : function(id, s, cc) {
  12511. var c, t = this, cls;
  12512. id = t.prefix + id;
  12513. cls = cc || t._cls.toolbar || tinymce.ui.Toolbar;
  12514. c = new cls(id, s, t.editor);
  12515. if (t.get(id))
  12516. return null;
  12517. return t.add(c);
  12518. },
  12519. createToolbarGroup : function(id, s, cc) {
  12520. var c, t = this, cls;
  12521. id = t.prefix + id;
  12522. cls = cc || this._cls.toolbarGroup || tinymce.ui.ToolbarGroup;
  12523. c = new cls(id, s, t.editor);
  12524. if (t.get(id))
  12525. return null;
  12526. return t.add(c);
  12527. },
  12528. createSeparator : function(cc) {
  12529. var cls = cc || this._cls.separator || tinymce.ui.Separator;
  12530. return new cls();
  12531. },
  12532. setControlType : function(n, c) {
  12533. return this._cls[n.toLowerCase()] = c;
  12534. },
  12535. destroy : function() {
  12536. each(this.controls, function(c) {
  12537. c.destroy();
  12538. });
  12539. this.controls = null;
  12540. }
  12541. });
  12542. })(tinymce);
  12543. (function(tinymce) {
  12544. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isIE = tinymce.isIE, isOpera = tinymce.isOpera;
  12545. tinymce.create('tinymce.WindowManager', {
  12546. WindowManager : function(ed) {
  12547. var t = this;
  12548. t.editor = ed;
  12549. t.onOpen = new Dispatcher(t);
  12550. t.onClose = new Dispatcher(t);
  12551. t.params = {};
  12552. t.features = {};
  12553. },
  12554. open : function(s, p) {
  12555. var t = this, f = '', x, y, mo = t.editor.settings.dialog_type == 'modal', w, sw, sh, vp = tinymce.DOM.getViewPort(), u;
  12556. // Default some options
  12557. s = s || {};
  12558. p = p || {};
  12559. sw = isOpera ? vp.w : screen.width; // Opera uses windows inside the Opera window
  12560. sh = isOpera ? vp.h : screen.height;
  12561. s.name = s.name || 'mc_' + new Date().getTime();
  12562. s.width = parseInt(s.width || 320);
  12563. s.height = parseInt(s.height || 240);
  12564. s.resizable = true;
  12565. s.left = s.left || parseInt(sw / 2.0) - (s.width / 2.0);
  12566. s.top = s.top || parseInt(sh / 2.0) - (s.height / 2.0);
  12567. p.inline = false;
  12568. p.mce_width = s.width;
  12569. p.mce_height = s.height;
  12570. p.mce_auto_focus = s.auto_focus;
  12571. if (mo) {
  12572. if (isIE) {
  12573. s.center = true;
  12574. s.help = false;
  12575. s.dialogWidth = s.width + 'px';
  12576. s.dialogHeight = s.height + 'px';
  12577. s.scroll = s.scrollbars || false;
  12578. }
  12579. }
  12580. // Build features string
  12581. each(s, function(v, k) {
  12582. if (tinymce.is(v, 'boolean'))
  12583. v = v ? 'yes' : 'no';
  12584. if (!/^(name|url)$/.test(k)) {
  12585. if (isIE && mo)
  12586. f += (f ? ';' : '') + k + ':' + v;
  12587. else
  12588. f += (f ? ',' : '') + k + '=' + v;
  12589. }
  12590. });
  12591. t.features = s;
  12592. t.params = p;
  12593. t.onOpen.dispatch(t, s, p);
  12594. u = s.url || s.file;
  12595. u = tinymce._addVer(u);
  12596. try {
  12597. if (isIE && mo) {
  12598. w = 1;
  12599. window.showModalDialog(u, window, f);
  12600. } else
  12601. w = window.open(u, s.name, f);
  12602. } catch (ex) {
  12603. // Ignore
  12604. }
  12605. if (!w)
  12606. alert(t.editor.getLang('popup_blocked'));
  12607. },
  12608. close : function(w) {
  12609. w.close();
  12610. this.onClose.dispatch(this);
  12611. },
  12612. createInstance : function(cl, a, b, c, d, e) {
  12613. var f = tinymce.resolve(cl);
  12614. return new f(a, b, c, d, e);
  12615. },
  12616. confirm : function(t, cb, s, w) {
  12617. w = w || window;
  12618. cb.call(s || this, w.confirm(this._decode(this.editor.getLang(t, t))));
  12619. },
  12620. alert : function(tx, cb, s, w) {
  12621. var t = this;
  12622. w = w || window;
  12623. w.alert(t._decode(t.editor.getLang(tx, tx)));
  12624. if (cb)
  12625. cb.call(s || t);
  12626. },
  12627. resizeBy : function(dw, dh, win) {
  12628. win.resizeBy(dw, dh);
  12629. },
  12630. // Internal functions
  12631. _decode : function(s) {
  12632. return tinymce.DOM.decode(s).replace(/\\n/g, '\n');
  12633. }
  12634. });
  12635. }(tinymce));
  12636. (function(tinymce) {
  12637. tinymce.Formatter = function(ed) {
  12638. var formats = {},
  12639. each = tinymce.each,
  12640. dom = ed.dom,
  12641. selection = ed.selection,
  12642. TreeWalker = tinymce.dom.TreeWalker,
  12643. rangeUtils = new tinymce.dom.RangeUtils(dom),
  12644. isValid = ed.schema.isValidChild,
  12645. isBlock = dom.isBlock,
  12646. forcedRootBlock = ed.settings.forced_root_block,
  12647. nodeIndex = dom.nodeIndex,
  12648. INVISIBLE_CHAR = tinymce.isGecko ? '\u200B' : '\uFEFF',
  12649. MCE_ATTR_RE = /^(src|href|style)$/,
  12650. FALSE = false,
  12651. TRUE = true,
  12652. formatChangeData,
  12653. undef,
  12654. getContentEditable = dom.getContentEditable;
  12655. function isArray(obj) {
  12656. return obj instanceof Array;
  12657. };
  12658. function getParents(node, selector) {
  12659. return dom.getParents(node, selector, dom.getRoot());
  12660. };
  12661. function isCaretNode(node) {
  12662. return node.nodeType === 1 && node.id === '_mce_caret';
  12663. };
  12664. function defaultFormats() {
  12665. register({
  12666. alignleft : [
  12667. {selector : 'figure,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}, defaultBlock: 'div'},
  12668. {selector : 'img,table', collapsed : false, styles : {'float' : 'left'}}
  12669. ],
  12670. aligncenter : [
  12671. {selector : 'figure,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}, defaultBlock: 'div'},
  12672. {selector : 'img', collapsed : false, styles : {display : 'block', marginLeft : 'auto', marginRight : 'auto'}},
  12673. {selector : 'table', collapsed : false, styles : {marginLeft : 'auto', marginRight : 'auto'}}
  12674. ],
  12675. alignright : [
  12676. {selector : 'figure,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}, defaultBlock: 'div'},
  12677. {selector : 'img,table', collapsed : false, styles : {'float' : 'right'}}
  12678. ],
  12679. alignfull : [
  12680. {selector : 'figure,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'justify'}, defaultBlock: 'div'}
  12681. ],
  12682. bold : [
  12683. {inline : 'strong', remove : 'all'},
  12684. {inline : 'span', styles : {fontWeight : 'bold'}},
  12685. {inline : 'b', remove : 'all'}
  12686. ],
  12687. italic : [
  12688. {inline : 'em', remove : 'all'},
  12689. {inline : 'span', styles : {fontStyle : 'italic'}},
  12690. {inline : 'i', remove : 'all'}
  12691. ],
  12692. underline : [
  12693. {inline : 'span', styles : {textDecoration : 'underline'}, exact : true},
  12694. {inline : 'u', remove : 'all'}
  12695. ],
  12696. strikethrough : [
  12697. {inline : 'span', styles : {textDecoration : 'line-through'}, exact : true},
  12698. {inline : 'strike', remove : 'all'}
  12699. ],
  12700. forecolor : {inline : 'span', styles : {color : '%value'}, wrap_links : false},
  12701. hilitecolor : {inline : 'span', styles : {backgroundColor : '%value'}, wrap_links : false},
  12702. fontname : {inline : 'span', styles : {fontFamily : '%value'}},
  12703. fontsize : {inline : 'span', styles : {fontSize : '%value'}},
  12704. fontsize_class : {inline : 'span', attributes : {'class' : '%value'}},
  12705. blockquote : {block : 'blockquote', wrapper : 1, remove : 'all'},
  12706. subscript : {inline : 'sub'},
  12707. superscript : {inline : 'sup'},
  12708. link : {inline : 'a', selector : 'a', remove : 'all', split : true, deep : true,
  12709. onmatch : function(node) {
  12710. return true;
  12711. },
  12712. onformat : function(elm, fmt, vars) {
  12713. each(vars, function(value, key) {
  12714. dom.setAttrib(elm, key, value);
  12715. });
  12716. }
  12717. },
  12718. removeformat : [
  12719. {selector : 'b,strong,em,i,font,u,strike', remove : 'all', split : true, expand : false, block_expand : true, deep : true},
  12720. {selector : 'span', attributes : ['style', 'class'], remove : 'empty', split : true, expand : false, deep : true},
  12721. {selector : '*', attributes : ['style', 'class'], split : false, expand : false, deep : true}
  12722. ]
  12723. });
  12724. // Register default block formats
  12725. each('p h1 h2 h3 h4 h5 h6 div address pre div code dt dd samp'.split(/\s/), function(name) {
  12726. register(name, {block : name, remove : 'all'});
  12727. });
  12728. // Register user defined formats
  12729. register(ed.settings.formats);
  12730. };
  12731. function addKeyboardShortcuts() {
  12732. // Add some inline shortcuts
  12733. ed.addShortcut('ctrl+b', 'bold_desc', 'Bold');
  12734. ed.addShortcut('ctrl+i', 'italic_desc', 'Italic');
  12735. ed.addShortcut('ctrl+u', 'underline_desc', 'Underline');
  12736. // BlockFormat shortcuts keys
  12737. for (var i = 1; i <= 6; i++) {
  12738. ed.addShortcut('ctrl+' + i, '', ['FormatBlock', false, 'h' + i]);
  12739. }
  12740. ed.addShortcut('ctrl+7', '', ['FormatBlock', false, 'p']);
  12741. ed.addShortcut('ctrl+8', '', ['FormatBlock', false, 'div']);
  12742. ed.addShortcut('ctrl+9', '', ['FormatBlock', false, 'address']);
  12743. };
  12744. // Public functions
  12745. function get(name) {
  12746. return name ? formats[name] : formats;
  12747. };
  12748. function register(name, format) {
  12749. if (name) {
  12750. if (typeof(name) !== 'string') {
  12751. each(name, function(format, name) {
  12752. register(name, format);
  12753. });
  12754. } else {
  12755. // Force format into array and add it to internal collection
  12756. format = format.length ? format : [format];
  12757. each(format, function(format) {
  12758. // Set deep to false by default on selector formats this to avoid removing
  12759. // alignment on images inside paragraphs when alignment is changed on paragraphs
  12760. if (format.deep === undef)
  12761. format.deep = !format.selector;
  12762. // Default to true
  12763. if (format.split === undef)
  12764. format.split = !format.selector || format.inline;
  12765. // Default to true
  12766. if (format.remove === undef && format.selector && !format.inline)
  12767. format.remove = 'none';
  12768. // Mark format as a mixed format inline + block level
  12769. if (format.selector && format.inline) {
  12770. format.mixed = true;
  12771. format.block_expand = true;
  12772. }
  12773. // Split classes if needed
  12774. if (typeof(format.classes) === 'string')
  12775. format.classes = format.classes.split(/\s+/);
  12776. });
  12777. formats[name] = format;
  12778. }
  12779. }
  12780. };
  12781. var getTextDecoration = function(node) {
  12782. var decoration;
  12783. ed.dom.getParent(node, function(n) {
  12784. decoration = ed.dom.getStyle(n, 'text-decoration');
  12785. return decoration && decoration !== 'none';
  12786. });
  12787. return decoration;
  12788. };
  12789. var processUnderlineAndColor = function(node) {
  12790. var textDecoration;
  12791. if (node.nodeType === 1 && node.parentNode && node.parentNode.nodeType === 1) {
  12792. textDecoration = getTextDecoration(node.parentNode);
  12793. if (ed.dom.getStyle(node, 'color') && textDecoration) {
  12794. ed.dom.setStyle(node, 'text-decoration', textDecoration);
  12795. } else if (ed.dom.getStyle(node, 'textdecoration') === textDecoration) {
  12796. ed.dom.setStyle(node, 'text-decoration', null);
  12797. }
  12798. }
  12799. };
  12800. function apply(name, vars, node) {
  12801. var formatList = get(name), format = formatList[0], bookmark, rng, i, isCollapsed = selection.isCollapsed();
  12802. function setElementFormat(elm, fmt) {
  12803. fmt = fmt || format;
  12804. if (elm) {
  12805. if (fmt.onformat) {
  12806. fmt.onformat(elm, fmt, vars, node);
  12807. }
  12808. each(fmt.styles, function(value, name) {
  12809. dom.setStyle(elm, name, replaceVars(value, vars));
  12810. });
  12811. each(fmt.attributes, function(value, name) {
  12812. dom.setAttrib(elm, name, replaceVars(value, vars));
  12813. });
  12814. each(fmt.classes, function(value) {
  12815. value = replaceVars(value, vars);
  12816. if (!dom.hasClass(elm, value))
  12817. dom.addClass(elm, value);
  12818. });
  12819. }
  12820. };
  12821. function adjustSelectionToVisibleSelection() {
  12822. function findSelectionEnd(start, end) {
  12823. var walker = new TreeWalker(end);
  12824. for (node = walker.current(); node; node = walker.prev()) {
  12825. if (node.childNodes.length > 1 || node == start || node.tagName == 'BR') {
  12826. return node;
  12827. }
  12828. }
  12829. };
  12830. // Adjust selection so that a end container with a end offset of zero is not included in the selection
  12831. // as this isn't visible to the user.
  12832. var rng = ed.selection.getRng();
  12833. var start = rng.startContainer;
  12834. var end = rng.endContainer;
  12835. if (start != end && rng.endOffset === 0) {
  12836. var newEnd = findSelectionEnd(start, end);
  12837. var endOffset = newEnd.nodeType == 3 ? newEnd.length : newEnd.childNodes.length;
  12838. rng.setEnd(newEnd, endOffset);
  12839. }
  12840. return rng;
  12841. }
  12842. function applyStyleToList(node, bookmark, wrapElm, newWrappers, process){
  12843. var nodes = [], listIndex = -1, list, startIndex = -1, endIndex = -1, currentWrapElm;
  12844. // find the index of the first child list.
  12845. each(node.childNodes, function(n, index) {
  12846. if (n.nodeName === "UL" || n.nodeName === "OL") {
  12847. listIndex = index;
  12848. list = n;
  12849. return false;
  12850. }
  12851. });
  12852. // get the index of the bookmarks
  12853. each(node.childNodes, function(n, index) {
  12854. if (n.nodeName === "SPAN" && dom.getAttrib(n, "data-mce-type") == "bookmark") {
  12855. if (n.id == bookmark.id + "_start") {
  12856. startIndex = index;
  12857. } else if (n.id == bookmark.id + "_end") {
  12858. endIndex = index;
  12859. }
  12860. }
  12861. });
  12862. // if the selection spans across an embedded list, or there isn't an embedded list - handle processing normally
  12863. if (listIndex <= 0 || (startIndex < listIndex && endIndex > listIndex)) {
  12864. each(tinymce.grep(node.childNodes), process);
  12865. return 0;
  12866. } else {
  12867. currentWrapElm = dom.clone(wrapElm, FALSE);
  12868. // create a list of the nodes on the same side of the list as the selection
  12869. each(tinymce.grep(node.childNodes), function(n, index) {
  12870. if ((startIndex < listIndex && index < listIndex) || (startIndex > listIndex && index > listIndex)) {
  12871. nodes.push(n);
  12872. n.parentNode.removeChild(n);
  12873. }
  12874. });
  12875. // insert the wrapping element either before or after the list.
  12876. if (startIndex < listIndex) {
  12877. node.insertBefore(currentWrapElm, list);
  12878. } else if (startIndex > listIndex) {
  12879. node.insertBefore(currentWrapElm, list.nextSibling);
  12880. }
  12881. // add the new nodes to the list.
  12882. newWrappers.push(currentWrapElm);
  12883. each(nodes, function(node) {
  12884. currentWrapElm.appendChild(node);
  12885. });
  12886. return currentWrapElm;
  12887. }
  12888. };
  12889. function applyRngStyle(rng, bookmark, node_specific) {
  12890. var newWrappers = [], wrapName, wrapElm, contentEditable = true;
  12891. // Setup wrapper element
  12892. wrapName = format.inline || format.block;
  12893. wrapElm = dom.create(wrapName);
  12894. setElementFormat(wrapElm);
  12895. rangeUtils.walk(rng, function(nodes) {
  12896. var currentWrapElm;
  12897. function process(node) {
  12898. var nodeName, parentName, found, hasContentEditableState, lastContentEditable;
  12899. lastContentEditable = contentEditable;
  12900. nodeName = node.nodeName.toLowerCase();
  12901. parentName = node.parentNode.nodeName.toLowerCase();
  12902. // Node has a contentEditable value
  12903. if (node.nodeType === 1 && getContentEditable(node)) {
  12904. lastContentEditable = contentEditable;
  12905. contentEditable = getContentEditable(node) === "true";
  12906. hasContentEditableState = true; // We don't want to wrap the container only it's children
  12907. }
  12908. // Stop wrapping on br elements
  12909. if (isEq(nodeName, 'br')) {
  12910. currentWrapElm = 0;
  12911. // Remove any br elements when we wrap things
  12912. if (format.block)
  12913. dom.remove(node);
  12914. return;
  12915. }
  12916. // If node is wrapper type
  12917. if (format.wrapper && matchNode(node, name, vars)) {
  12918. currentWrapElm = 0;
  12919. return;
  12920. }
  12921. // Can we rename the block
  12922. if (contentEditable && !hasContentEditableState && format.block && !format.wrapper && isTextBlock(nodeName)) {
  12923. node = dom.rename(node, wrapName);
  12924. setElementFormat(node);
  12925. newWrappers.push(node);
  12926. currentWrapElm = 0;
  12927. return;
  12928. }
  12929. // Handle selector patterns
  12930. if (format.selector) {
  12931. // Look for matching formats
  12932. each(formatList, function(format) {
  12933. // Check collapsed state if it exists
  12934. if ('collapsed' in format && format.collapsed !== isCollapsed) {
  12935. return;
  12936. }
  12937. if (dom.is(node, format.selector) && !isCaretNode(node)) {
  12938. setElementFormat(node, format);
  12939. found = true;
  12940. }
  12941. });
  12942. // Continue processing if a selector match wasn't found and a inline element is defined
  12943. if (!format.inline || found) {
  12944. currentWrapElm = 0;
  12945. return;
  12946. }
  12947. }
  12948. // Is it valid to wrap this item
  12949. if (contentEditable && !hasContentEditableState && isValid(wrapName, nodeName) && isValid(parentName, wrapName) &&
  12950. !(!node_specific && node.nodeType === 3 && node.nodeValue.length === 1 && node.nodeValue.charCodeAt(0) === 65279) && !isCaretNode(node)) {
  12951. // Start wrapping
  12952. if (!currentWrapElm) {
  12953. // Wrap the node
  12954. currentWrapElm = dom.clone(wrapElm, FALSE);
  12955. node.parentNode.insertBefore(currentWrapElm, node);
  12956. newWrappers.push(currentWrapElm);
  12957. }
  12958. currentWrapElm.appendChild(node);
  12959. } else if (nodeName == 'li' && bookmark) {
  12960. // Start wrapping - if we are in a list node and have a bookmark, then we will always begin by wrapping in a new element.
  12961. currentWrapElm = applyStyleToList(node, bookmark, wrapElm, newWrappers, process);
  12962. } else {
  12963. // Start a new wrapper for possible children
  12964. currentWrapElm = 0;
  12965. each(tinymce.grep(node.childNodes), process);
  12966. if (hasContentEditableState) {
  12967. contentEditable = lastContentEditable; // Restore last contentEditable state from stack
  12968. }
  12969. // End the last wrapper
  12970. currentWrapElm = 0;
  12971. }
  12972. };
  12973. // Process siblings from range
  12974. each(nodes, process);
  12975. });
  12976. // Wrap links inside as well, for example color inside a link when the wrapper is around the link
  12977. if (format.wrap_links === false) {
  12978. each(newWrappers, function(node) {
  12979. function process(node) {
  12980. var i, currentWrapElm, children;
  12981. if (node.nodeName === 'A') {
  12982. currentWrapElm = dom.clone(wrapElm, FALSE);
  12983. newWrappers.push(currentWrapElm);
  12984. children = tinymce.grep(node.childNodes);
  12985. for (i = 0; i < children.length; i++)
  12986. currentWrapElm.appendChild(children[i]);
  12987. node.appendChild(currentWrapElm);
  12988. }
  12989. each(tinymce.grep(node.childNodes), process);
  12990. };
  12991. process(node);
  12992. });
  12993. }
  12994. // Cleanup
  12995. each(newWrappers, function(node) {
  12996. var childCount;
  12997. function getChildCount(node) {
  12998. var count = 0;
  12999. each(node.childNodes, function(node) {
  13000. if (!isWhiteSpaceNode(node) && !isBookmarkNode(node))
  13001. count++;
  13002. });
  13003. return count;
  13004. };
  13005. function mergeStyles(node) {
  13006. var child, clone;
  13007. each(node.childNodes, function(node) {
  13008. if (node.nodeType == 1 && !isBookmarkNode(node) && !isCaretNode(node)) {
  13009. child = node;
  13010. return FALSE; // break loop
  13011. }
  13012. });
  13013. // If child was found and of the same type as the current node
  13014. if (child && matchName(child, format)) {
  13015. clone = dom.clone(child, FALSE);
  13016. setElementFormat(clone);
  13017. dom.replace(clone, node, TRUE);
  13018. dom.remove(child, 1);
  13019. }
  13020. return clone || node;
  13021. };
  13022. childCount = getChildCount(node);
  13023. // Remove empty nodes but only if there is multiple wrappers and they are not block
  13024. // elements so never remove single <h1></h1> since that would remove the currrent empty block element where the caret is at
  13025. if ((newWrappers.length > 1 || !isBlock(node)) && childCount === 0) {
  13026. dom.remove(node, 1);
  13027. return;
  13028. }
  13029. if (format.inline || format.wrapper) {
  13030. // Merges the current node with it's children of similar type to reduce the number of elements
  13031. if (!format.exact && childCount === 1)
  13032. node = mergeStyles(node);
  13033. // Remove/merge children
  13034. each(formatList, function(format) {
  13035. // Merge all children of similar type will move styles from child to parent
  13036. // this: <span style="color:red"><b><span style="color:red; font-size:10px">text</span></b></span>
  13037. // will become: <span style="color:red"><b><span style="font-size:10px">text</span></b></span>
  13038. each(dom.select(format.inline, node), function(child) {
  13039. var parent;
  13040. // When wrap_links is set to false we don't want
  13041. // to remove the format on children within links
  13042. if (format.wrap_links === false) {
  13043. parent = child.parentNode;
  13044. do {
  13045. if (parent.nodeName === 'A')
  13046. return;
  13047. } while (parent = parent.parentNode);
  13048. }
  13049. removeFormat(format, vars, child, format.exact ? child : null);
  13050. });
  13051. });
  13052. // Remove child if direct parent is of same type
  13053. if (matchNode(node.parentNode, name, vars)) {
  13054. dom.remove(node, 1);
  13055. node = 0;
  13056. return TRUE;
  13057. }
  13058. // Look for parent with similar style format
  13059. if (format.merge_with_parents) {
  13060. dom.getParent(node.parentNode, function(parent) {
  13061. if (matchNode(parent, name, vars)) {
  13062. dom.remove(node, 1);
  13063. node = 0;
  13064. return TRUE;
  13065. }
  13066. });
  13067. }
  13068. // Merge next and previous siblings if they are similar <b>text</b><b>text</b> becomes <b>texttext</b>
  13069. if (node && format.merge_siblings !== false) {
  13070. node = mergeSiblings(getNonWhiteSpaceSibling(node), node);
  13071. node = mergeSiblings(node, getNonWhiteSpaceSibling(node, TRUE));
  13072. }
  13073. }
  13074. });
  13075. };
  13076. if (format) {
  13077. if (node) {
  13078. if (node.nodeType) {
  13079. rng = dom.createRng();
  13080. rng.setStartBefore(node);
  13081. rng.setEndAfter(node);
  13082. applyRngStyle(expandRng(rng, formatList), null, true);
  13083. } else {
  13084. applyRngStyle(node, null, true);
  13085. }
  13086. } else {
  13087. if (!isCollapsed || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
  13088. // Obtain selection node before selection is unselected by applyRngStyle()
  13089. var curSelNode = ed.selection.getNode();
  13090. // 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
  13091. // It's kind of a hack but people should be using the default block type P since all desktop editors work that way
  13092. if (!forcedRootBlock && formatList[0].defaultBlock && !dom.getParent(curSelNode, dom.isBlock)) {
  13093. apply(formatList[0].defaultBlock);
  13094. }
  13095. // Apply formatting to selection
  13096. ed.selection.setRng(adjustSelectionToVisibleSelection());
  13097. bookmark = selection.getBookmark();
  13098. applyRngStyle(expandRng(selection.getRng(TRUE), formatList), bookmark);
  13099. // Colored nodes should be underlined so that the color of the underline matches the text color.
  13100. if (format.styles && (format.styles.color || format.styles.textDecoration)) {
  13101. tinymce.walk(curSelNode, processUnderlineAndColor, 'childNodes');
  13102. processUnderlineAndColor(curSelNode);
  13103. }
  13104. selection.moveToBookmark(bookmark);
  13105. moveStart(selection.getRng(TRUE));
  13106. ed.nodeChanged();
  13107. } else
  13108. performCaretAction('apply', name, vars);
  13109. }
  13110. }
  13111. };
  13112. function remove(name, vars, node) {
  13113. var formatList = get(name), format = formatList[0], bookmark, i, rng, contentEditable = true;
  13114. // Merges the styles for each node
  13115. function process(node) {
  13116. var children, i, l, localContentEditable, lastContentEditable, hasContentEditableState;
  13117. // Node has a contentEditable value
  13118. if (node.nodeType === 1 && getContentEditable(node)) {
  13119. lastContentEditable = contentEditable;
  13120. contentEditable = getContentEditable(node) === "true";
  13121. hasContentEditableState = true; // We don't want to wrap the container only it's children
  13122. }
  13123. // Grab the children first since the nodelist might be changed
  13124. children = tinymce.grep(node.childNodes);
  13125. // Process current node
  13126. if (contentEditable && !hasContentEditableState) {
  13127. for (i = 0, l = formatList.length; i < l; i++) {
  13128. if (removeFormat(formatList[i], vars, node, node))
  13129. break;
  13130. }
  13131. }
  13132. // Process the children
  13133. if (format.deep) {
  13134. if (children.length) {
  13135. for (i = 0, l = children.length; i < l; i++)
  13136. process(children[i]);
  13137. if (hasContentEditableState) {
  13138. contentEditable = lastContentEditable; // Restore last contentEditable state from stack
  13139. }
  13140. }
  13141. }
  13142. };
  13143. function findFormatRoot(container) {
  13144. var formatRoot;
  13145. // Find format root
  13146. each(getParents(container.parentNode).reverse(), function(parent) {
  13147. var format;
  13148. // Find format root element
  13149. if (!formatRoot && parent.id != '_start' && parent.id != '_end') {
  13150. // Is the node matching the format we are looking for
  13151. format = matchNode(parent, name, vars);
  13152. if (format && format.split !== false)
  13153. formatRoot = parent;
  13154. }
  13155. });
  13156. return formatRoot;
  13157. };
  13158. function wrapAndSplit(format_root, container, target, split) {
  13159. var parent, clone, lastClone, firstClone, i, formatRootParent;
  13160. // Format root found then clone formats and split it
  13161. if (format_root) {
  13162. formatRootParent = format_root.parentNode;
  13163. for (parent = container.parentNode; parent && parent != formatRootParent; parent = parent.parentNode) {
  13164. clone = dom.clone(parent, FALSE);
  13165. for (i = 0; i < formatList.length; i++) {
  13166. if (removeFormat(formatList[i], vars, clone, clone)) {
  13167. clone = 0;
  13168. break;
  13169. }
  13170. }
  13171. // Build wrapper node
  13172. if (clone) {
  13173. if (lastClone)
  13174. clone.appendChild(lastClone);
  13175. if (!firstClone)
  13176. firstClone = clone;
  13177. lastClone = clone;
  13178. }
  13179. }
  13180. // Never split block elements if the format is mixed
  13181. if (split && (!format.mixed || !isBlock(format_root)))
  13182. container = dom.split(format_root, container);
  13183. // Wrap container in cloned formats
  13184. if (lastClone) {
  13185. target.parentNode.insertBefore(lastClone, target);
  13186. firstClone.appendChild(target);
  13187. }
  13188. }
  13189. return container;
  13190. };
  13191. function splitToFormatRoot(container) {
  13192. return wrapAndSplit(findFormatRoot(container), container, container, true);
  13193. };
  13194. function unwrap(start) {
  13195. var node = dom.get(start ? '_start' : '_end'),
  13196. out = node[start ? 'firstChild' : 'lastChild'];
  13197. // If the end is placed within the start the result will be removed
  13198. // So this checks if the out node is a bookmark node if it is it
  13199. // checks for another more suitable node
  13200. if (isBookmarkNode(out))
  13201. out = out[start ? 'firstChild' : 'lastChild'];
  13202. dom.remove(node, true);
  13203. return out;
  13204. };
  13205. function removeRngStyle(rng) {
  13206. var startContainer, endContainer, node;
  13207. rng = expandRng(rng, formatList, TRUE);
  13208. if (format.split) {
  13209. startContainer = getContainer(rng, TRUE);
  13210. endContainer = getContainer(rng);
  13211. if (startContainer != endContainer) {
  13212. // 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
  13213. // This will happen if you tripple click a table cell and use remove formatting
  13214. if (/^(TR|TD)$/.test(startContainer.nodeName) && startContainer.firstChild) {
  13215. startContainer = (startContainer.nodeName == "TD" ? startContainer.firstChild : startContainer.firstChild.firstChild) || startContainer;
  13216. }
  13217. // Wrap start/end nodes in span element since these might be cloned/moved
  13218. startContainer = wrap(startContainer, 'span', {id : '_start', 'data-mce-type' : 'bookmark'});
  13219. endContainer = wrap(endContainer, 'span', {id : '_end', 'data-mce-type' : 'bookmark'});
  13220. // Split start/end
  13221. splitToFormatRoot(startContainer);
  13222. splitToFormatRoot(endContainer);
  13223. // Unwrap start/end to get real elements again
  13224. startContainer = unwrap(TRUE);
  13225. endContainer = unwrap();
  13226. } else
  13227. startContainer = endContainer = splitToFormatRoot(startContainer);
  13228. // Update range positions since they might have changed after the split operations
  13229. rng.startContainer = startContainer.parentNode;
  13230. rng.startOffset = nodeIndex(startContainer);
  13231. rng.endContainer = endContainer.parentNode;
  13232. rng.endOffset = nodeIndex(endContainer) + 1;
  13233. }
  13234. // Remove items between start/end
  13235. rangeUtils.walk(rng, function(nodes) {
  13236. each(nodes, function(node) {
  13237. process(node);
  13238. // Remove parent span if it only contains text-decoration: underline, yet a parent node is also underlined.
  13239. if (node.nodeType === 1 && ed.dom.getStyle(node, 'text-decoration') === 'underline' && node.parentNode && getTextDecoration(node.parentNode) === 'underline') {
  13240. removeFormat({'deep': false, 'exact': true, 'inline': 'span', 'styles': {'textDecoration' : 'underline'}}, null, node);
  13241. }
  13242. });
  13243. });
  13244. };
  13245. // Handle node
  13246. if (node) {
  13247. if (node.nodeType) {
  13248. rng = dom.createRng();
  13249. rng.setStartBefore(node);
  13250. rng.setEndAfter(node);
  13251. removeRngStyle(rng);
  13252. } else {
  13253. removeRngStyle(node);
  13254. }
  13255. return;
  13256. }
  13257. if (!selection.isCollapsed() || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
  13258. bookmark = selection.getBookmark();
  13259. removeRngStyle(selection.getRng(TRUE));
  13260. selection.moveToBookmark(bookmark);
  13261. // 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
  13262. if (format.inline && match(name, vars, selection.getStart())) {
  13263. moveStart(selection.getRng(true));
  13264. }
  13265. ed.nodeChanged();
  13266. } else
  13267. performCaretAction('remove', name, vars);
  13268. };
  13269. function toggle(name, vars, node) {
  13270. var fmt = get(name);
  13271. if (match(name, vars, node) && (!('toggle' in fmt[0]) || fmt[0].toggle))
  13272. remove(name, vars, node);
  13273. else
  13274. apply(name, vars, node);
  13275. };
  13276. function matchNode(node, name, vars, similar) {
  13277. var formatList = get(name), format, i, classes;
  13278. function matchItems(node, format, item_name) {
  13279. var key, value, items = format[item_name], i;
  13280. // Custom match
  13281. if (format.onmatch) {
  13282. return format.onmatch(node, format, item_name);
  13283. }
  13284. // Check all items
  13285. if (items) {
  13286. // Non indexed object
  13287. if (items.length === undef) {
  13288. for (key in items) {
  13289. if (items.hasOwnProperty(key)) {
  13290. if (item_name === 'attributes')
  13291. value = dom.getAttrib(node, key);
  13292. else
  13293. value = getStyle(node, key);
  13294. if (similar && !value && !format.exact)
  13295. return;
  13296. if ((!similar || format.exact) && !isEq(value, replaceVars(items[key], vars)))
  13297. return;
  13298. }
  13299. }
  13300. } else {
  13301. // Only one match needed for indexed arrays
  13302. for (i = 0; i < items.length; i++) {
  13303. if (item_name === 'attributes' ? dom.getAttrib(node, items[i]) : getStyle(node, items[i]))
  13304. return format;
  13305. }
  13306. }
  13307. }
  13308. return format;
  13309. };
  13310. if (formatList && node) {
  13311. // Check each format in list
  13312. for (i = 0; i < formatList.length; i++) {
  13313. format = formatList[i];
  13314. // Name name, attributes, styles and classes
  13315. if (matchName(node, format) && matchItems(node, format, 'attributes') && matchItems(node, format, 'styles')) {
  13316. // Match classes
  13317. if (classes = format.classes) {
  13318. for (i = 0; i < classes.length; i++) {
  13319. if (!dom.hasClass(node, classes[i]))
  13320. return;
  13321. }
  13322. }
  13323. return format;
  13324. }
  13325. }
  13326. }
  13327. };
  13328. function match(name, vars, node) {
  13329. var startNode;
  13330. function matchParents(node) {
  13331. // Find first node with similar format settings
  13332. node = dom.getParent(node, function(node) {
  13333. return !!matchNode(node, name, vars, true);
  13334. });
  13335. // Do an exact check on the similar format element
  13336. return matchNode(node, name, vars);
  13337. };
  13338. // Check specified node
  13339. if (node)
  13340. return matchParents(node);
  13341. // Check selected node
  13342. node = selection.getNode();
  13343. if (matchParents(node))
  13344. return TRUE;
  13345. // Check start node if it's different
  13346. startNode = selection.getStart();
  13347. if (startNode != node) {
  13348. if (matchParents(startNode))
  13349. return TRUE;
  13350. }
  13351. return FALSE;
  13352. };
  13353. function matchAll(names, vars) {
  13354. var startElement, matchedFormatNames = [], checkedMap = {}, i, ni, name;
  13355. // Check start of selection for formats
  13356. startElement = selection.getStart();
  13357. dom.getParent(startElement, function(node) {
  13358. var i, name;
  13359. for (i = 0; i < names.length; i++) {
  13360. name = names[i];
  13361. if (!checkedMap[name] && matchNode(node, name, vars)) {
  13362. checkedMap[name] = true;
  13363. matchedFormatNames.push(name);
  13364. }
  13365. }
  13366. }, dom.getRoot());
  13367. return matchedFormatNames;
  13368. };
  13369. function canApply(name) {
  13370. var formatList = get(name), startNode, parents, i, x, selector;
  13371. if (formatList) {
  13372. startNode = selection.getStart();
  13373. parents = getParents(startNode);
  13374. for (x = formatList.length - 1; x >= 0; x--) {
  13375. selector = formatList[x].selector;
  13376. // Format is not selector based, then always return TRUE
  13377. if (!selector)
  13378. return TRUE;
  13379. for (i = parents.length - 1; i >= 0; i--) {
  13380. if (dom.is(parents[i], selector))
  13381. return TRUE;
  13382. }
  13383. }
  13384. }
  13385. return FALSE;
  13386. };
  13387. function formatChanged(formats, callback) {
  13388. var currentFormats;
  13389. // Setup format node change logic
  13390. if (!formatChangeData) {
  13391. formatChangeData = {};
  13392. currentFormats = {};
  13393. ed.onNodeChange.addToTop(function(ed, cm, node) {
  13394. var parents = getParents(node), matchedFormats = {};
  13395. // Check for new formats
  13396. each(formatChangeData, function(callbacks, format) {
  13397. each(parents, function(node) {
  13398. if (matchNode(node, format, {}, true)) {
  13399. if (!currentFormats[format]) {
  13400. // Execute callbacks
  13401. each(callbacks, function(callback) {
  13402. callback(true, {node: node, format: format, parents: parents});
  13403. });
  13404. currentFormats[format] = callbacks;
  13405. }
  13406. matchedFormats[format] = callbacks;
  13407. return false;
  13408. }
  13409. });
  13410. });
  13411. // Check if current formats still match
  13412. each(currentFormats, function(callbacks, format) {
  13413. if (!matchedFormats[format]) {
  13414. delete currentFormats[format];
  13415. each(callbacks, function(callback) {
  13416. callback(false, {node: node, format: format, parents: parents});
  13417. });
  13418. }
  13419. });
  13420. });
  13421. }
  13422. // Add format listeners
  13423. each(formats.split(','), function(format) {
  13424. if (!formatChangeData[format]) {
  13425. formatChangeData[format] = [];
  13426. }
  13427. formatChangeData[format].push(callback);
  13428. });
  13429. return this;
  13430. };
  13431. // Expose to public
  13432. tinymce.extend(this, {
  13433. get : get,
  13434. register : register,
  13435. apply : apply,
  13436. remove : remove,
  13437. toggle : toggle,
  13438. match : match,
  13439. matchAll : matchAll,
  13440. matchNode : matchNode,
  13441. canApply : canApply,
  13442. formatChanged: formatChanged
  13443. });
  13444. // Initialize
  13445. defaultFormats();
  13446. addKeyboardShortcuts();
  13447. // Private functions
  13448. function matchName(node, format) {
  13449. // Check for inline match
  13450. if (isEq(node, format.inline))
  13451. return TRUE;
  13452. // Check for block match
  13453. if (isEq(node, format.block))
  13454. return TRUE;
  13455. // Check for selector match
  13456. if (format.selector)
  13457. return dom.is(node, format.selector);
  13458. };
  13459. function isEq(str1, str2) {
  13460. str1 = str1 || '';
  13461. str2 = str2 || '';
  13462. str1 = '' + (str1.nodeName || str1);
  13463. str2 = '' + (str2.nodeName || str2);
  13464. return str1.toLowerCase() == str2.toLowerCase();
  13465. };
  13466. function getStyle(node, name) {
  13467. var styleVal = dom.getStyle(node, name);
  13468. // Force the format to hex
  13469. if (name == 'color' || name == 'backgroundColor')
  13470. styleVal = dom.toHex(styleVal);
  13471. // Opera will return bold as 700
  13472. if (name == 'fontWeight' && styleVal == 700)
  13473. styleVal = 'bold';
  13474. return '' + styleVal;
  13475. };
  13476. function replaceVars(value, vars) {
  13477. if (typeof(value) != "string")
  13478. value = value(vars);
  13479. else if (vars) {
  13480. value = value.replace(/%(\w+)/g, function(str, name) {
  13481. return vars[name] || str;
  13482. });
  13483. }
  13484. return value;
  13485. };
  13486. function isWhiteSpaceNode(node) {
  13487. return node && node.nodeType === 3 && /^([\t \r\n]+|)$/.test(node.nodeValue);
  13488. };
  13489. function wrap(node, name, attrs) {
  13490. var wrapper = dom.create(name, attrs);
  13491. node.parentNode.insertBefore(wrapper, node);
  13492. wrapper.appendChild(node);
  13493. return wrapper;
  13494. };
  13495. function expandRng(rng, format, remove) {
  13496. var sibling, lastIdx, leaf, endPoint,
  13497. startContainer = rng.startContainer,
  13498. startOffset = rng.startOffset,
  13499. endContainer = rng.endContainer,
  13500. endOffset = rng.endOffset;
  13501. // This function walks up the tree if there is no siblings before/after the node
  13502. function findParentContainer(start) {
  13503. var container, parent, child, sibling, siblingName, root;
  13504. container = parent = start ? startContainer : endContainer;
  13505. siblingName = start ? 'previousSibling' : 'nextSibling';
  13506. root = dom.getRoot();
  13507. // If it's a text node and the offset is inside the text
  13508. if (container.nodeType == 3 && !isWhiteSpaceNode(container)) {
  13509. if (start ? startOffset > 0 : endOffset < container.nodeValue.length) {
  13510. return container;
  13511. }
  13512. }
  13513. for (;;) {
  13514. // Stop expanding on block elements
  13515. if (!format[0].block_expand && isBlock(parent))
  13516. return parent;
  13517. // Walk left/right
  13518. for (sibling = parent[siblingName]; sibling; sibling = sibling[siblingName]) {
  13519. if (!isBookmarkNode(sibling) && !isWhiteSpaceNode(sibling)) {
  13520. return parent;
  13521. }
  13522. }
  13523. // Check if we can move up are we at root level or body level
  13524. if (parent.parentNode == root) {
  13525. container = parent;
  13526. break;
  13527. }
  13528. parent = parent.parentNode;
  13529. }
  13530. return container;
  13531. };
  13532. // This function walks down the tree to find the leaf at the selection.
  13533. // The offset is also returned as if node initially a leaf, the offset may be in the middle of the text node.
  13534. function findLeaf(node, offset) {
  13535. if (offset === undef)
  13536. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  13537. while (node && node.hasChildNodes()) {
  13538. node = node.childNodes[offset];
  13539. if (node)
  13540. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  13541. }
  13542. return { node: node, offset: offset };
  13543. }
  13544. // If index based start position then resolve it
  13545. if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) {
  13546. lastIdx = startContainer.childNodes.length - 1;
  13547. startContainer = startContainer.childNodes[startOffset > lastIdx ? lastIdx : startOffset];
  13548. if (startContainer.nodeType == 3)
  13549. startOffset = 0;
  13550. }
  13551. // If index based end position then resolve it
  13552. if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) {
  13553. lastIdx = endContainer.childNodes.length - 1;
  13554. endContainer = endContainer.childNodes[endOffset > lastIdx ? lastIdx : endOffset - 1];
  13555. if (endContainer.nodeType == 3)
  13556. endOffset = endContainer.nodeValue.length;
  13557. }
  13558. // Expands the node to the closes contentEditable false element if it exists
  13559. function findParentContentEditable(node) {
  13560. var parent = node;
  13561. while (parent) {
  13562. if (parent.nodeType === 1 && getContentEditable(parent)) {
  13563. return getContentEditable(parent) === "false" ? parent : node;
  13564. }
  13565. parent = parent.parentNode;
  13566. }
  13567. return node;
  13568. };
  13569. function findWordEndPoint(container, offset, start) {
  13570. var walker, node, pos, lastTextNode;
  13571. function findSpace(node, offset) {
  13572. var pos, pos2, str = node.nodeValue;
  13573. if (typeof(offset) == "undefined") {
  13574. offset = start ? str.length : 0;
  13575. }
  13576. if (start) {
  13577. pos = str.lastIndexOf(' ', offset);
  13578. pos2 = str.lastIndexOf('\u00a0', offset);
  13579. pos = pos > pos2 ? pos : pos2;
  13580. // Include the space on remove to avoid tag soup
  13581. if (pos !== -1 && !remove) {
  13582. pos++;
  13583. }
  13584. } else {
  13585. pos = str.indexOf(' ', offset);
  13586. pos2 = str.indexOf('\u00a0', offset);
  13587. pos = pos !== -1 && (pos2 === -1 || pos < pos2) ? pos : pos2;
  13588. }
  13589. return pos;
  13590. };
  13591. if (container.nodeType === 3) {
  13592. pos = findSpace(container, offset);
  13593. if (pos !== -1) {
  13594. return {container : container, offset : pos};
  13595. }
  13596. lastTextNode = container;
  13597. }
  13598. // Walk the nodes inside the block
  13599. walker = new TreeWalker(container, dom.getParent(container, isBlock) || ed.getBody());
  13600. while (node = walker[start ? 'prev' : 'next']()) {
  13601. if (node.nodeType === 3) {
  13602. lastTextNode = node;
  13603. pos = findSpace(node);
  13604. if (pos !== -1) {
  13605. return {container : node, offset : pos};
  13606. }
  13607. } else if (isBlock(node)) {
  13608. break;
  13609. }
  13610. }
  13611. if (lastTextNode) {
  13612. if (start) {
  13613. offset = 0;
  13614. } else {
  13615. offset = lastTextNode.length;
  13616. }
  13617. return {container: lastTextNode, offset: offset};
  13618. }
  13619. };
  13620. function findSelectorEndPoint(container, sibling_name) {
  13621. var parents, i, y, curFormat;
  13622. if (container.nodeType == 3 && container.nodeValue.length === 0 && container[sibling_name])
  13623. container = container[sibling_name];
  13624. parents = getParents(container);
  13625. for (i = 0; i < parents.length; i++) {
  13626. for (y = 0; y < format.length; y++) {
  13627. curFormat = format[y];
  13628. // If collapsed state is set then skip formats that doesn't match that
  13629. if ("collapsed" in curFormat && curFormat.collapsed !== rng.collapsed)
  13630. continue;
  13631. if (dom.is(parents[i], curFormat.selector))
  13632. return parents[i];
  13633. }
  13634. }
  13635. return container;
  13636. };
  13637. function findBlockEndPoint(container, sibling_name, sibling_name2) {
  13638. var node;
  13639. // Expand to block of similar type
  13640. if (!format[0].wrapper)
  13641. node = dom.getParent(container, format[0].block);
  13642. // Expand to first wrappable block element or any block element
  13643. if (!node)
  13644. node = dom.getParent(container.nodeType == 3 ? container.parentNode : container, isBlock);
  13645. // Exclude inner lists from wrapping
  13646. if (node && format[0].wrapper)
  13647. node = getParents(node, 'ul,ol').reverse()[0] || node;
  13648. // Didn't find a block element look for first/last wrappable element
  13649. if (!node) {
  13650. node = container;
  13651. while (node[sibling_name] && !isBlock(node[sibling_name])) {
  13652. node = node[sibling_name];
  13653. // Break on BR but include it will be removed later on
  13654. // we can't remove it now since we need to check if it can be wrapped
  13655. if (isEq(node, 'br'))
  13656. break;
  13657. }
  13658. }
  13659. return node || container;
  13660. };
  13661. // Expand to closest contentEditable element
  13662. startContainer = findParentContentEditable(startContainer);
  13663. endContainer = findParentContentEditable(endContainer);
  13664. // Exclude bookmark nodes if possible
  13665. if (isBookmarkNode(startContainer.parentNode) || isBookmarkNode(startContainer)) {
  13666. startContainer = isBookmarkNode(startContainer) ? startContainer : startContainer.parentNode;
  13667. startContainer = startContainer.nextSibling || startContainer;
  13668. if (startContainer.nodeType == 3)
  13669. startOffset = 0;
  13670. }
  13671. if (isBookmarkNode(endContainer.parentNode) || isBookmarkNode(endContainer)) {
  13672. endContainer = isBookmarkNode(endContainer) ? endContainer : endContainer.parentNode;
  13673. endContainer = endContainer.previousSibling || endContainer;
  13674. if (endContainer.nodeType == 3)
  13675. endOffset = endContainer.length;
  13676. }
  13677. if (format[0].inline) {
  13678. if (rng.collapsed) {
  13679. // Expand left to closest word boundery
  13680. endPoint = findWordEndPoint(startContainer, startOffset, true);
  13681. if (endPoint) {
  13682. startContainer = endPoint.container;
  13683. startOffset = endPoint.offset;
  13684. }
  13685. // Expand right to closest word boundery
  13686. endPoint = findWordEndPoint(endContainer, endOffset);
  13687. if (endPoint) {
  13688. endContainer = endPoint.container;
  13689. endOffset = endPoint.offset;
  13690. }
  13691. }
  13692. // Avoid applying formatting to a trailing space.
  13693. leaf = findLeaf(endContainer, endOffset);
  13694. if (leaf.node) {
  13695. while (leaf.node && leaf.offset === 0 && leaf.node.previousSibling)
  13696. leaf = findLeaf(leaf.node.previousSibling);
  13697. if (leaf.node && leaf.offset > 0 && leaf.node.nodeType === 3 &&
  13698. leaf.node.nodeValue.charAt(leaf.offset - 1) === ' ') {
  13699. if (leaf.offset > 1) {
  13700. endContainer = leaf.node;
  13701. endContainer.splitText(leaf.offset - 1);
  13702. }
  13703. }
  13704. }
  13705. }
  13706. // Move start/end point up the tree if the leaves are sharp and if we are in different containers
  13707. // Example * becomes !: !<p><b><i>*text</i><i>text*</i></b></p>!
  13708. // This will reduce the number of wrapper elements that needs to be created
  13709. // Move start point up the tree
  13710. if (format[0].inline || format[0].block_expand) {
  13711. if (!format[0].inline || (startContainer.nodeType != 3 || startOffset === 0)) {
  13712. startContainer = findParentContainer(true);
  13713. }
  13714. if (!format[0].inline || (endContainer.nodeType != 3 || endOffset === endContainer.nodeValue.length)) {
  13715. endContainer = findParentContainer();
  13716. }
  13717. }
  13718. // Expand start/end container to matching selector
  13719. if (format[0].selector && format[0].expand !== FALSE && !format[0].inline) {
  13720. // Find new startContainer/endContainer if there is better one
  13721. startContainer = findSelectorEndPoint(startContainer, 'previousSibling');
  13722. endContainer = findSelectorEndPoint(endContainer, 'nextSibling');
  13723. }
  13724. // Expand start/end container to matching block element or text node
  13725. if (format[0].block || format[0].selector) {
  13726. // Find new startContainer/endContainer if there is better one
  13727. startContainer = findBlockEndPoint(startContainer, 'previousSibling');
  13728. endContainer = findBlockEndPoint(endContainer, 'nextSibling');
  13729. // Non block element then try to expand up the leaf
  13730. if (format[0].block) {
  13731. if (!isBlock(startContainer))
  13732. startContainer = findParentContainer(true);
  13733. if (!isBlock(endContainer))
  13734. endContainer = findParentContainer();
  13735. }
  13736. }
  13737. // Setup index for startContainer
  13738. if (startContainer.nodeType == 1) {
  13739. startOffset = nodeIndex(startContainer);
  13740. startContainer = startContainer.parentNode;
  13741. }
  13742. // Setup index for endContainer
  13743. if (endContainer.nodeType == 1) {
  13744. endOffset = nodeIndex(endContainer) + 1;
  13745. endContainer = endContainer.parentNode;
  13746. }
  13747. // Return new range like object
  13748. return {
  13749. startContainer : startContainer,
  13750. startOffset : startOffset,
  13751. endContainer : endContainer,
  13752. endOffset : endOffset
  13753. };
  13754. }
  13755. function removeFormat(format, vars, node, compare_node) {
  13756. var i, attrs, stylesModified;
  13757. // Check if node matches format
  13758. if (!matchName(node, format))
  13759. return FALSE;
  13760. // Should we compare with format attribs and styles
  13761. if (format.remove != 'all') {
  13762. // Remove styles
  13763. each(format.styles, function(value, name) {
  13764. value = replaceVars(value, vars);
  13765. // Indexed array
  13766. if (typeof(name) === 'number') {
  13767. name = value;
  13768. compare_node = 0;
  13769. }
  13770. if (!compare_node || isEq(getStyle(compare_node, name), value))
  13771. dom.setStyle(node, name, '');
  13772. stylesModified = 1;
  13773. });
  13774. // Remove style attribute if it's empty
  13775. if (stylesModified && dom.getAttrib(node, 'style') == '') {
  13776. node.removeAttribute('style');
  13777. node.removeAttribute('data-mce-style');
  13778. }
  13779. // Remove attributes
  13780. each(format.attributes, function(value, name) {
  13781. var valueOut;
  13782. value = replaceVars(value, vars);
  13783. // Indexed array
  13784. if (typeof(name) === 'number') {
  13785. name = value;
  13786. compare_node = 0;
  13787. }
  13788. if (!compare_node || isEq(dom.getAttrib(compare_node, name), value)) {
  13789. // Keep internal classes
  13790. if (name == 'class') {
  13791. value = dom.getAttrib(node, name);
  13792. if (value) {
  13793. // Build new class value where everything is removed except the internal prefixed classes
  13794. valueOut = '';
  13795. each(value.split(/\s+/), function(cls) {
  13796. if (/mce\w+/.test(cls))
  13797. valueOut += (valueOut ? ' ' : '') + cls;
  13798. });
  13799. // We got some internal classes left
  13800. if (valueOut) {
  13801. dom.setAttrib(node, name, valueOut);
  13802. return;
  13803. }
  13804. }
  13805. }
  13806. // IE6 has a bug where the attribute doesn't get removed correctly
  13807. if (name == "class")
  13808. node.removeAttribute('className');
  13809. // Remove mce prefixed attributes
  13810. if (MCE_ATTR_RE.test(name))
  13811. node.removeAttribute('data-mce-' + name);
  13812. node.removeAttribute(name);
  13813. }
  13814. });
  13815. // Remove classes
  13816. each(format.classes, function(value) {
  13817. value = replaceVars(value, vars);
  13818. if (!compare_node || dom.hasClass(compare_node, value))
  13819. dom.removeClass(node, value);
  13820. });
  13821. // Check for non internal attributes
  13822. attrs = dom.getAttribs(node);
  13823. for (i = 0; i < attrs.length; i++) {
  13824. if (attrs[i].nodeName.indexOf('_') !== 0)
  13825. return FALSE;
  13826. }
  13827. }
  13828. // Remove the inline child if it's empty for example <b> or <span>
  13829. if (format.remove != 'none') {
  13830. removeNode(node, format);
  13831. return TRUE;
  13832. }
  13833. };
  13834. function removeNode(node, format) {
  13835. var parentNode = node.parentNode, rootBlockElm;
  13836. function find(node, next, inc) {
  13837. node = getNonWhiteSpaceSibling(node, next, inc);
  13838. return !node || (node.nodeName == 'BR' || isBlock(node));
  13839. };
  13840. if (format.block) {
  13841. if (!forcedRootBlock) {
  13842. // Append BR elements if needed before we remove the block
  13843. if (isBlock(node) && !isBlock(parentNode)) {
  13844. if (!find(node, FALSE) && !find(node.firstChild, TRUE, 1))
  13845. node.insertBefore(dom.create('br'), node.firstChild);
  13846. if (!find(node, TRUE) && !find(node.lastChild, FALSE, 1))
  13847. node.appendChild(dom.create('br'));
  13848. }
  13849. } else {
  13850. // Wrap the block in a forcedRootBlock if we are at the root of document
  13851. if (parentNode == dom.getRoot()) {
  13852. if (!format.list_block || !isEq(node, format.list_block)) {
  13853. each(tinymce.grep(node.childNodes), function(node) {
  13854. if (isValid(forcedRootBlock, node.nodeName.toLowerCase())) {
  13855. if (!rootBlockElm)
  13856. rootBlockElm = wrap(node, forcedRootBlock);
  13857. else
  13858. rootBlockElm.appendChild(node);
  13859. } else
  13860. rootBlockElm = 0;
  13861. });
  13862. }
  13863. }
  13864. }
  13865. }
  13866. // Never remove nodes that isn't the specified inline element if a selector is specified too
  13867. if (format.selector && format.inline && !isEq(format.inline, node))
  13868. return;
  13869. dom.remove(node, 1);
  13870. };
  13871. function getNonWhiteSpaceSibling(node, next, inc) {
  13872. if (node) {
  13873. next = next ? 'nextSibling' : 'previousSibling';
  13874. for (node = inc ? node : node[next]; node; node = node[next]) {
  13875. if (node.nodeType == 1 || !isWhiteSpaceNode(node))
  13876. return node;
  13877. }
  13878. }
  13879. };
  13880. function isBookmarkNode(node) {
  13881. return node && node.nodeType == 1 && node.getAttribute('data-mce-type') == 'bookmark';
  13882. };
  13883. function mergeSiblings(prev, next) {
  13884. var marker, sibling, tmpSibling;
  13885. function compareElements(node1, node2) {
  13886. // Not the same name
  13887. if (node1.nodeName != node2.nodeName)
  13888. return FALSE;
  13889. function getAttribs(node) {
  13890. var attribs = {};
  13891. each(dom.getAttribs(node), function(attr) {
  13892. var name = attr.nodeName.toLowerCase();
  13893. // Don't compare internal attributes or style
  13894. if (name.indexOf('_') !== 0 && name !== 'style')
  13895. attribs[name] = dom.getAttrib(node, name);
  13896. });
  13897. return attribs;
  13898. };
  13899. function compareObjects(obj1, obj2) {
  13900. var value, name;
  13901. for (name in obj1) {
  13902. // Obj1 has item obj2 doesn't have
  13903. if (obj1.hasOwnProperty(name)) {
  13904. value = obj2[name];
  13905. // Obj2 doesn't have obj1 item
  13906. if (value === undef)
  13907. return FALSE;
  13908. // Obj2 item has a different value
  13909. if (obj1[name] != value)
  13910. return FALSE;
  13911. // Delete similar value
  13912. delete obj2[name];
  13913. }
  13914. }
  13915. // Check if obj 2 has something obj 1 doesn't have
  13916. for (name in obj2) {
  13917. // Obj2 has item obj1 doesn't have
  13918. if (obj2.hasOwnProperty(name))
  13919. return FALSE;
  13920. }
  13921. return TRUE;
  13922. };
  13923. // Attribs are not the same
  13924. if (!compareObjects(getAttribs(node1), getAttribs(node2)))
  13925. return FALSE;
  13926. // Styles are not the same
  13927. if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style'))))
  13928. return FALSE;
  13929. return TRUE;
  13930. };
  13931. function findElementSibling(node, sibling_name) {
  13932. for (sibling = node; sibling; sibling = sibling[sibling_name]) {
  13933. if (sibling.nodeType == 3 && sibling.nodeValue.length !== 0)
  13934. return node;
  13935. if (sibling.nodeType == 1 && !isBookmarkNode(sibling))
  13936. return sibling;
  13937. }
  13938. return node;
  13939. };
  13940. // Check if next/prev exists and that they are elements
  13941. if (prev && next) {
  13942. // If previous sibling is empty then jump over it
  13943. prev = findElementSibling(prev, 'previousSibling');
  13944. next = findElementSibling(next, 'nextSibling');
  13945. // Compare next and previous nodes
  13946. if (compareElements(prev, next)) {
  13947. // Append nodes between
  13948. for (sibling = prev.nextSibling; sibling && sibling != next;) {
  13949. tmpSibling = sibling;
  13950. sibling = sibling.nextSibling;
  13951. prev.appendChild(tmpSibling);
  13952. }
  13953. // Remove next node
  13954. dom.remove(next);
  13955. // Move children into prev node
  13956. each(tinymce.grep(next.childNodes), function(node) {
  13957. prev.appendChild(node);
  13958. });
  13959. return prev;
  13960. }
  13961. }
  13962. return next;
  13963. };
  13964. function isTextBlock(name) {
  13965. return /^(h[1-6]|p|div|pre|address|dl|dt|dd)$/.test(name);
  13966. };
  13967. function getContainer(rng, start) {
  13968. var container, offset, lastIdx, walker;
  13969. container = rng[start ? 'startContainer' : 'endContainer'];
  13970. offset = rng[start ? 'startOffset' : 'endOffset'];
  13971. if (container.nodeType == 1) {
  13972. lastIdx = container.childNodes.length - 1;
  13973. if (!start && offset)
  13974. offset--;
  13975. container = container.childNodes[offset > lastIdx ? lastIdx : offset];
  13976. }
  13977. // If start text node is excluded then walk to the next node
  13978. if (container.nodeType === 3 && start && offset >= container.nodeValue.length) {
  13979. container = new TreeWalker(container, ed.getBody()).next() || container;
  13980. }
  13981. // If end text node is excluded then walk to the previous node
  13982. if (container.nodeType === 3 && !start && offset === 0) {
  13983. container = new TreeWalker(container, ed.getBody()).prev() || container;
  13984. }
  13985. return container;
  13986. };
  13987. function performCaretAction(type, name, vars) {
  13988. var caretContainerId = '_mce_caret', debug = ed.settings.caret_debug;
  13989. // Creates a caret container bogus element
  13990. function createCaretContainer(fill) {
  13991. var caretContainer = dom.create('span', {id: caretContainerId, 'data-mce-bogus': true, style: debug ? 'color:red' : ''});
  13992. if (fill) {
  13993. caretContainer.appendChild(ed.getDoc().createTextNode(INVISIBLE_CHAR));
  13994. }
  13995. return caretContainer;
  13996. };
  13997. function isCaretContainerEmpty(node, nodes) {
  13998. while (node) {
  13999. if ((node.nodeType === 3 && node.nodeValue !== INVISIBLE_CHAR) || node.childNodes.length > 1) {
  14000. return false;
  14001. }
  14002. // Collect nodes
  14003. if (nodes && node.nodeType === 1) {
  14004. nodes.push(node);
  14005. }
  14006. node = node.firstChild;
  14007. }
  14008. return true;
  14009. };
  14010. // Returns any parent caret container element
  14011. function getParentCaretContainer(node) {
  14012. while (node) {
  14013. if (node.id === caretContainerId) {
  14014. return node;
  14015. }
  14016. node = node.parentNode;
  14017. }
  14018. };
  14019. // Finds the first text node in the specified node
  14020. function findFirstTextNode(node) {
  14021. var walker;
  14022. if (node) {
  14023. walker = new TreeWalker(node, node);
  14024. for (node = walker.current(); node; node = walker.next()) {
  14025. if (node.nodeType === 3) {
  14026. return node;
  14027. }
  14028. }
  14029. }
  14030. };
  14031. // Removes the caret container for the specified node or all on the current document
  14032. function removeCaretContainer(node, move_caret) {
  14033. var child, rng;
  14034. if (!node) {
  14035. node = getParentCaretContainer(selection.getStart());
  14036. if (!node) {
  14037. while (node = dom.get(caretContainerId)) {
  14038. removeCaretContainer(node, false);
  14039. }
  14040. }
  14041. } else {
  14042. rng = selection.getRng(true);
  14043. if (isCaretContainerEmpty(node)) {
  14044. if (move_caret !== false) {
  14045. rng.setStartBefore(node);
  14046. rng.setEndBefore(node);
  14047. }
  14048. dom.remove(node);
  14049. } else {
  14050. child = findFirstTextNode(node);
  14051. if (child.nodeValue.charAt(0) === INVISIBLE_CHAR) {
  14052. child = child.deleteData(0, 1);
  14053. }
  14054. dom.remove(node, 1);
  14055. }
  14056. selection.setRng(rng);
  14057. }
  14058. };
  14059. // Applies formatting to the caret postion
  14060. function applyCaretFormat() {
  14061. var rng, caretContainer, textNode, offset, bookmark, container, text;
  14062. rng = selection.getRng(true);
  14063. offset = rng.startOffset;
  14064. container = rng.startContainer;
  14065. text = container.nodeValue;
  14066. caretContainer = getParentCaretContainer(selection.getStart());
  14067. if (caretContainer) {
  14068. textNode = findFirstTextNode(caretContainer);
  14069. }
  14070. // Expand to word is caret is in the middle of a text node and the char before/after is a alpha numeric character
  14071. if (text && offset > 0 && offset < text.length && /\w/.test(text.charAt(offset)) && /\w/.test(text.charAt(offset - 1))) {
  14072. // Get bookmark of caret position
  14073. bookmark = selection.getBookmark();
  14074. // Collapse bookmark range (WebKit)
  14075. rng.collapse(true);
  14076. // Expand the range to the closest word and split it at those points
  14077. rng = expandRng(rng, get(name));
  14078. rng = rangeUtils.split(rng);
  14079. // Apply the format to the range
  14080. apply(name, vars, rng);
  14081. // Move selection back to caret position
  14082. selection.moveToBookmark(bookmark);
  14083. } else {
  14084. if (!caretContainer || textNode.nodeValue !== INVISIBLE_CHAR) {
  14085. caretContainer = createCaretContainer(true);
  14086. textNode = caretContainer.firstChild;
  14087. rng.insertNode(caretContainer);
  14088. offset = 1;
  14089. apply(name, vars, caretContainer);
  14090. } else {
  14091. apply(name, vars, caretContainer);
  14092. }
  14093. // Move selection to text node
  14094. selection.setCursorLocation(textNode, offset);
  14095. }
  14096. };
  14097. function removeCaretFormat() {
  14098. var rng = selection.getRng(true), container, offset, bookmark,
  14099. hasContentAfter, node, formatNode, parents = [], i, caretContainer;
  14100. container = rng.startContainer;
  14101. offset = rng.startOffset;
  14102. node = container;
  14103. if (container.nodeType == 3) {
  14104. if (offset != container.nodeValue.length || container.nodeValue === INVISIBLE_CHAR) {
  14105. hasContentAfter = true;
  14106. }
  14107. node = node.parentNode;
  14108. }
  14109. while (node) {
  14110. if (matchNode(node, name, vars)) {
  14111. formatNode = node;
  14112. break;
  14113. }
  14114. if (node.nextSibling) {
  14115. hasContentAfter = true;
  14116. }
  14117. parents.push(node);
  14118. node = node.parentNode;
  14119. }
  14120. // Node doesn't have the specified format
  14121. if (!formatNode) {
  14122. return;
  14123. }
  14124. // Is there contents after the caret then remove the format on the element
  14125. if (hasContentAfter) {
  14126. // Get bookmark of caret position
  14127. bookmark = selection.getBookmark();
  14128. // Collapse bookmark range (WebKit)
  14129. rng.collapse(true);
  14130. // Expand the range to the closest word and split it at those points
  14131. rng = expandRng(rng, get(name), true);
  14132. rng = rangeUtils.split(rng);
  14133. // Remove the format from the range
  14134. remove(name, vars, rng);
  14135. // Move selection back to caret position
  14136. selection.moveToBookmark(bookmark);
  14137. } else {
  14138. caretContainer = createCaretContainer();
  14139. node = caretContainer;
  14140. for (i = parents.length - 1; i >= 0; i--) {
  14141. node.appendChild(dom.clone(parents[i], false));
  14142. node = node.firstChild;
  14143. }
  14144. // Insert invisible character into inner most format element
  14145. node.appendChild(dom.doc.createTextNode(INVISIBLE_CHAR));
  14146. node = node.firstChild;
  14147. // Insert caret container after the formated node
  14148. dom.insertAfter(caretContainer, formatNode);
  14149. // Move selection to text node
  14150. selection.setCursorLocation(node, 1);
  14151. }
  14152. };
  14153. // Checks if the parent caret container node isn't empty if that is the case it
  14154. // will remove the bogus state on all children that isn't empty
  14155. function unmarkBogusCaretParents() {
  14156. var i, caretContainer, node;
  14157. caretContainer = getParentCaretContainer(selection.getStart());
  14158. if (caretContainer && !dom.isEmpty(caretContainer)) {
  14159. tinymce.walk(caretContainer, function(node) {
  14160. if (node.nodeType == 1 && node.id !== caretContainerId && !dom.isEmpty(node)) {
  14161. dom.setAttrib(node, 'data-mce-bogus', null);
  14162. }
  14163. }, 'childNodes');
  14164. }
  14165. };
  14166. // Only bind the caret events once
  14167. if (!self._hasCaretEvents) {
  14168. // Mark current caret container elements as bogus when getting the contents so we don't end up with empty elements
  14169. ed.onBeforeGetContent.addToTop(function() {
  14170. var nodes = [], i;
  14171. if (isCaretContainerEmpty(getParentCaretContainer(selection.getStart()), nodes)) {
  14172. // Mark children
  14173. i = nodes.length;
  14174. while (i--) {
  14175. dom.setAttrib(nodes[i], 'data-mce-bogus', '1');
  14176. }
  14177. }
  14178. });
  14179. // Remove caret container on mouse up and on key up
  14180. tinymce.each('onMouseUp onKeyUp'.split(' '), function(name) {
  14181. ed[name].addToTop(function() {
  14182. removeCaretContainer();
  14183. unmarkBogusCaretParents();
  14184. });
  14185. });
  14186. // Remove caret container on keydown and it's a backspace, enter or left/right arrow keys
  14187. ed.onKeyDown.addToTop(function(ed, e) {
  14188. var keyCode = e.keyCode;
  14189. if (keyCode == 8 || keyCode == 37 || keyCode == 39) {
  14190. removeCaretContainer(getParentCaretContainer(selection.getStart()));
  14191. }
  14192. unmarkBogusCaretParents();
  14193. });
  14194. // Remove bogus state if they got filled by contents using editor.selection.setContent
  14195. selection.onSetContent.add(unmarkBogusCaretParents);
  14196. self._hasCaretEvents = true;
  14197. }
  14198. // Do apply or remove caret format
  14199. if (type == "apply") {
  14200. applyCaretFormat();
  14201. } else {
  14202. removeCaretFormat();
  14203. }
  14204. };
  14205. function moveStart(rng) {
  14206. var container = rng.startContainer,
  14207. offset = rng.startOffset, isAtEndOfText,
  14208. walker, node, nodes, tmpNode;
  14209. // Convert text node into index if possible
  14210. if (container.nodeType == 3 && offset >= container.nodeValue.length) {
  14211. // Get the parent container location and walk from there
  14212. offset = nodeIndex(container);
  14213. container = container.parentNode;
  14214. isAtEndOfText = true;
  14215. }
  14216. // Move startContainer/startOffset in to a suitable node
  14217. if (container.nodeType == 1) {
  14218. nodes = container.childNodes;
  14219. container = nodes[Math.min(offset, nodes.length - 1)];
  14220. walker = new TreeWalker(container, dom.getParent(container, dom.isBlock));
  14221. // If offset is at end of the parent node walk to the next one
  14222. if (offset > nodes.length - 1 || isAtEndOfText)
  14223. walker.next();
  14224. for (node = walker.current(); node; node = walker.next()) {
  14225. if (node.nodeType == 3 && !isWhiteSpaceNode(node)) {
  14226. // IE has a "neat" feature where it moves the start node into the closest element
  14227. // we can avoid this by inserting an element before it and then remove it after we set the selection
  14228. tmpNode = dom.create('a', null, INVISIBLE_CHAR);
  14229. node.parentNode.insertBefore(tmpNode, node);
  14230. // Set selection and remove tmpNode
  14231. rng.setStart(node, 0);
  14232. selection.setRng(rng);
  14233. dom.remove(tmpNode);
  14234. return;
  14235. }
  14236. }
  14237. }
  14238. };
  14239. };
  14240. })(tinymce);
  14241. tinymce.onAddEditor.add(function(tinymce, ed) {
  14242. var filters, fontSizes, dom, settings = ed.settings;
  14243. function replaceWithSpan(node, styles) {
  14244. tinymce.each(styles, function(value, name) {
  14245. if (value)
  14246. dom.setStyle(node, name, value);
  14247. });
  14248. dom.rename(node, 'span');
  14249. };
  14250. function convert(editor, params) {
  14251. dom = editor.dom;
  14252. if (settings.convert_fonts_to_spans) {
  14253. tinymce.each(dom.select('font,u,strike', params.node), function(node) {
  14254. filters[node.nodeName.toLowerCase()](ed.dom, node);
  14255. });
  14256. }
  14257. };
  14258. if (settings.inline_styles) {
  14259. fontSizes = tinymce.explode(settings.font_size_legacy_values);
  14260. filters = {
  14261. font : function(dom, node) {
  14262. replaceWithSpan(node, {
  14263. backgroundColor : node.style.backgroundColor,
  14264. color : node.color,
  14265. fontFamily : node.face,
  14266. fontSize : fontSizes[parseInt(node.size, 10) - 1]
  14267. });
  14268. },
  14269. u : function(dom, node) {
  14270. replaceWithSpan(node, {
  14271. textDecoration : 'underline'
  14272. });
  14273. },
  14274. strike : function(dom, node) {
  14275. replaceWithSpan(node, {
  14276. textDecoration : 'line-through'
  14277. });
  14278. }
  14279. };
  14280. ed.onPreProcess.add(convert);
  14281. ed.onSetContent.add(convert);
  14282. ed.onInit.add(function() {
  14283. ed.selection.onSetContent.add(convert);
  14284. });
  14285. }
  14286. });
  14287. (function(tinymce) {
  14288. var TreeWalker = tinymce.dom.TreeWalker;
  14289. tinymce.EnterKey = function(editor) {
  14290. var dom = editor.dom, selection = editor.selection, settings = editor.settings, undoManager = editor.undoManager, nonEmptyElementsMap = editor.schema.getNonEmptyElements();
  14291. function handleEnterKey(evt) {
  14292. var rng = selection.getRng(true), tmpRng, editableRoot, container, offset, parentBlock, documentMode,
  14293. newBlock, fragment, containerBlock, parentBlockName, containerBlockName, newBlockName, isAfterLastNodeInContainer;
  14294. // Returns true if the block can be split into two blocks or not
  14295. function canSplitBlock(node) {
  14296. return node &&
  14297. dom.isBlock(node) &&
  14298. !/^(TD|TH|CAPTION|FORM)$/.test(node.nodeName) &&
  14299. !/^(fixed|absolute)/i.test(node.style.position) &&
  14300. dom.getContentEditable(node) !== "true";
  14301. };
  14302. // Renders empty block on IE
  14303. function renderBlockOnIE(block) {
  14304. var oldRng;
  14305. if (tinymce.isIE && dom.isBlock(block)) {
  14306. oldRng = selection.getRng();
  14307. block.appendChild(dom.create('span', null, '\u00a0'));
  14308. selection.select(block);
  14309. block.lastChild.outerHTML = '';
  14310. selection.setRng(oldRng);
  14311. }
  14312. };
  14313. // Remove the first empty inline element of the block so this: <p><b><em></em></b>x</p> becomes this: <p>x</p>
  14314. function trimInlineElementsOnLeftSideOfBlock(block) {
  14315. var node = block, firstChilds = [], i;
  14316. // Find inner most first child ex: <p><i><b>*</b></i></p>
  14317. while (node = node.firstChild) {
  14318. if (dom.isBlock(node)) {
  14319. return;
  14320. }
  14321. if (node.nodeType == 1 && !nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  14322. firstChilds.push(node);
  14323. }
  14324. }
  14325. i = firstChilds.length;
  14326. while (i--) {
  14327. node = firstChilds[i];
  14328. if (!node.hasChildNodes() || (node.firstChild == node.lastChild && node.firstChild.nodeValue === '')) {
  14329. dom.remove(node);
  14330. }
  14331. }
  14332. };
  14333. // Moves the caret to a suitable position within the root for example in the first non pure whitespace text node or before an image
  14334. function moveToCaretPosition(root) {
  14335. var walker, node, rng, y, viewPort, lastNode = root, tempElm;
  14336. rng = dom.createRng();
  14337. if (root.hasChildNodes()) {
  14338. walker = new TreeWalker(root, root);
  14339. while (node = walker.current()) {
  14340. if (node.nodeType == 3) {
  14341. rng.setStart(node, 0);
  14342. rng.setEnd(node, 0);
  14343. break;
  14344. }
  14345. if (nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  14346. rng.setStartBefore(node);
  14347. rng.setEndBefore(node);
  14348. break;
  14349. }
  14350. lastNode = node;
  14351. node = walker.next();
  14352. }
  14353. if (!node) {
  14354. rng.setStart(lastNode, 0);
  14355. rng.setEnd(lastNode, 0);
  14356. }
  14357. } else {
  14358. if (root.nodeName == 'BR') {
  14359. if (root.nextSibling && dom.isBlock(root.nextSibling)) {
  14360. // Trick on older IE versions to render the caret before the BR between two lists
  14361. if (!documentMode || documentMode < 9) {
  14362. tempElm = dom.create('br');
  14363. root.parentNode.insertBefore(tempElm, root);
  14364. }
  14365. rng.setStartBefore(root);
  14366. rng.setEndBefore(root);
  14367. } else {
  14368. rng.setStartAfter(root);
  14369. rng.setEndAfter(root);
  14370. }
  14371. } else {
  14372. rng.setStart(root, 0);
  14373. rng.setEnd(root, 0);
  14374. }
  14375. }
  14376. selection.setRng(rng);
  14377. // Remove tempElm created for old IE:s
  14378. dom.remove(tempElm);
  14379. viewPort = dom.getViewPort(editor.getWin());
  14380. // 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
  14381. y = dom.getPos(root).y;
  14382. if (y < viewPort.y || y + 25 > viewPort.y + viewPort.h) {
  14383. 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
  14384. }
  14385. };
  14386. // Creates a new block element by cloning the current one or creating a new one if the name is specified
  14387. // This function will also copy any text formatting from the parent block and add it to the new one
  14388. function createNewBlock(name) {
  14389. var node = container, block, clonedNode, caretNode;
  14390. block = name || parentBlockName == "TABLE" ? dom.create(name || newBlockName) : parentBlock.cloneNode(false);
  14391. caretNode = block;
  14392. // Clone any parent styles
  14393. if (settings.keep_styles !== false) {
  14394. do {
  14395. if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(node.nodeName)) {
  14396. clonedNode = node.cloneNode(false);
  14397. dom.setAttrib(clonedNode, 'id', ''); // Remove ID since it needs to be document unique
  14398. if (block.hasChildNodes()) {
  14399. clonedNode.appendChild(block.firstChild);
  14400. block.appendChild(clonedNode);
  14401. } else {
  14402. caretNode = clonedNode;
  14403. block.appendChild(clonedNode);
  14404. }
  14405. }
  14406. } while (node = node.parentNode);
  14407. }
  14408. // BR is needed in empty blocks on non IE browsers
  14409. if (!tinymce.isIE) {
  14410. caretNode.innerHTML = '<br>';
  14411. }
  14412. return block;
  14413. };
  14414. // Returns true/false if the caret is at the start/end of the parent block element
  14415. function isCaretAtStartOrEndOfBlock(start) {
  14416. var walker, node, name;
  14417. // Caret is in the middle of a text node like "a|b"
  14418. if (container.nodeType == 3 && (start ? offset > 0 : offset < container.nodeValue.length)) {
  14419. return false;
  14420. }
  14421. // If after the last element in block node edge case for #5091
  14422. if (container.parentNode == parentBlock && isAfterLastNodeInContainer && !start) {
  14423. return true;
  14424. }
  14425. // If the caret if before the first element in parentBlock
  14426. if (start && container.nodeType == 1 && container == parentBlock.firstChild) {
  14427. return true;
  14428. }
  14429. // Caret can be before/after a table
  14430. if (container.nodeName === "TABLE" || (container.previousSibling && container.previousSibling.nodeName == "TABLE")) {
  14431. return (isAfterLastNodeInContainer && !start) || (!isAfterLastNodeInContainer && start);
  14432. }
  14433. // Walk the DOM and look for text nodes or non empty elements
  14434. walker = new TreeWalker(container, parentBlock);
  14435. // If caret is in beginning or end of a text block then jump to the next/previous node
  14436. if (container.nodeType == 3) {
  14437. if (start && offset == 0) {
  14438. walker.prev();
  14439. } else if (!start && offset == container.nodeValue.length) {
  14440. walker.next();
  14441. }
  14442. }
  14443. while (node = walker.current()) {
  14444. if (node.nodeType === 1) {
  14445. // Ignore bogus elements
  14446. if (!node.getAttribute('data-mce-bogus')) {
  14447. // Keep empty elements like <img /> <input /> but not trailing br:s like <p>text|<br></p>
  14448. name = node.nodeName.toLowerCase();
  14449. if (nonEmptyElementsMap[name] && name !== 'br') {
  14450. return false;
  14451. }
  14452. }
  14453. } else if (node.nodeType === 3 && !/^[ \t\r\n]*$/.test(node.nodeValue)) {
  14454. return false;
  14455. }
  14456. if (start) {
  14457. walker.prev();
  14458. } else {
  14459. walker.next();
  14460. }
  14461. }
  14462. return true;
  14463. };
  14464. // Wraps any text nodes or inline elements in the specified forced root block name
  14465. function wrapSelfAndSiblingsInDefaultBlock(container, offset) {
  14466. var newBlock, parentBlock, startNode, node, next, blockName = newBlockName || 'P';
  14467. // Not in a block element or in a table cell or caption
  14468. parentBlock = dom.getParent(container, dom.isBlock);
  14469. if (!parentBlock || !canSplitBlock(parentBlock)) {
  14470. parentBlock = parentBlock || editableRoot;
  14471. if (!parentBlock.hasChildNodes()) {
  14472. newBlock = dom.create(blockName);
  14473. parentBlock.appendChild(newBlock);
  14474. rng.setStart(newBlock, 0);
  14475. rng.setEnd(newBlock, 0);
  14476. return newBlock;
  14477. }
  14478. // Find parent that is the first child of parentBlock
  14479. node = container;
  14480. while (node.parentNode != parentBlock) {
  14481. node = node.parentNode;
  14482. }
  14483. // Loop left to find start node start wrapping at
  14484. while (node && !dom.isBlock(node)) {
  14485. startNode = node;
  14486. node = node.previousSibling;
  14487. }
  14488. if (startNode) {
  14489. newBlock = dom.create(blockName);
  14490. startNode.parentNode.insertBefore(newBlock, startNode);
  14491. // Start wrapping until we hit a block
  14492. node = startNode;
  14493. while (node && !dom.isBlock(node)) {
  14494. next = node.nextSibling;
  14495. newBlock.appendChild(node);
  14496. node = next;
  14497. }
  14498. // Restore range to it's past location
  14499. rng.setStart(container, offset);
  14500. rng.setEnd(container, offset);
  14501. }
  14502. }
  14503. return container;
  14504. };
  14505. // Inserts a block or br before/after or in the middle of a split list of the LI is empty
  14506. function handleEmptyListItem() {
  14507. function isFirstOrLastLi(first) {
  14508. var node = containerBlock[first ? 'firstChild' : 'lastChild'];
  14509. // Find first/last element since there might be whitespace there
  14510. while (node) {
  14511. if (node.nodeType == 1) {
  14512. break;
  14513. }
  14514. node = node[first ? 'nextSibling' : 'previousSibling'];
  14515. }
  14516. return node === parentBlock;
  14517. };
  14518. newBlock = newBlockName ? createNewBlock(newBlockName) : dom.create('BR');
  14519. if (isFirstOrLastLi(true) && isFirstOrLastLi()) {
  14520. // Is first and last list item then replace the OL/UL with a text block
  14521. dom.replace(newBlock, containerBlock);
  14522. } else if (isFirstOrLastLi(true)) {
  14523. // First LI in list then remove LI and add text block before list
  14524. containerBlock.parentNode.insertBefore(newBlock, containerBlock);
  14525. } else if (isFirstOrLastLi()) {
  14526. // Last LI in list then temove LI and add text block after list
  14527. dom.insertAfter(newBlock, containerBlock);
  14528. renderBlockOnIE(newBlock);
  14529. } else {
  14530. // Middle LI in list the split the list and insert a text block in the middle
  14531. // Extract after fragment and insert it after the current block
  14532. tmpRng = rng.cloneRange();
  14533. tmpRng.setStartAfter(parentBlock);
  14534. tmpRng.setEndAfter(containerBlock);
  14535. fragment = tmpRng.extractContents();
  14536. dom.insertAfter(fragment, containerBlock);
  14537. dom.insertAfter(newBlock, containerBlock);
  14538. }
  14539. dom.remove(parentBlock);
  14540. moveToCaretPosition(newBlock);
  14541. undoManager.add();
  14542. };
  14543. // Walks the parent block to the right and look for BR elements
  14544. function hasRightSideBr() {
  14545. var walker = new TreeWalker(container, parentBlock), node;
  14546. while (node = walker.current()) {
  14547. if (node.nodeName == 'BR') {
  14548. return true;
  14549. }
  14550. node = walker.next();
  14551. }
  14552. }
  14553. // Inserts a BR element if the forced_root_block option is set to false or empty string
  14554. function insertBr() {
  14555. var brElm, extraBr;
  14556. if (container && container.nodeType == 3 && offset >= container.nodeValue.length) {
  14557. // Insert extra BR element at the end block elements
  14558. if (!tinymce.isIE && !hasRightSideBr()) {
  14559. brElm = dom.create('br')
  14560. rng.insertNode(brElm);
  14561. rng.setStartAfter(brElm);
  14562. rng.setEndAfter(brElm);
  14563. extraBr = true;
  14564. }
  14565. }
  14566. brElm = dom.create('br');
  14567. rng.insertNode(brElm);
  14568. // Rendering modes below IE8 doesn't display BR elements in PRE unless we have a \n before it
  14569. if (tinymce.isIE && parentBlockName == 'PRE' && (!documentMode || documentMode < 8)) {
  14570. brElm.parentNode.insertBefore(dom.doc.createTextNode('\r'), brElm);
  14571. }
  14572. if (!extraBr) {
  14573. rng.setStartAfter(brElm);
  14574. rng.setEndAfter(brElm);
  14575. } else {
  14576. rng.setStartBefore(brElm);
  14577. rng.setEndBefore(brElm);
  14578. }
  14579. selection.setRng(rng);
  14580. undoManager.add();
  14581. };
  14582. // Trims any linebreaks at the beginning of node user for example when pressing enter in a PRE element
  14583. function trimLeadingLineBreaks(node) {
  14584. do {
  14585. if (node.nodeType === 3) {
  14586. node.nodeValue = node.nodeValue.replace(/^[\r\n]+/, '');
  14587. }
  14588. node = node.firstChild;
  14589. } while (node);
  14590. };
  14591. function getEditableRoot(node) {
  14592. var root = dom.getRoot(), parent, editableRoot;
  14593. // Get all parents until we hit a non editable parent or the root
  14594. parent = node;
  14595. while (parent !== root && dom.getContentEditable(parent) !== "false") {
  14596. if (dom.getContentEditable(parent) === "true") {
  14597. editableRoot = parent;
  14598. }
  14599. parent = parent.parentNode;
  14600. }
  14601. return parent !== root ? editableRoot : root;
  14602. };
  14603. // 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
  14604. function addBrToBlockIfNeeded(block) {
  14605. var lastChild;
  14606. // IE will render the blocks correctly other browsers needs a BR
  14607. if (!tinymce.isIE) {
  14608. block.normalize(); // Remove empty text nodes that got left behind by the extract
  14609. // Check if the block is empty or contains a floated last child
  14610. lastChild = block.lastChild;
  14611. if (!lastChild || (/^(left|right)$/gi.test(dom.getStyle(lastChild, 'float', true)))) {
  14612. dom.add(block, 'br');
  14613. }
  14614. }
  14615. };
  14616. // Delete any selected contents
  14617. if (!rng.collapsed) {
  14618. editor.execCommand('Delete');
  14619. return;
  14620. }
  14621. // Event is blocked by some other handler for example the lists plugin
  14622. if (evt.isDefaultPrevented()) {
  14623. return;
  14624. }
  14625. // Setup range items and newBlockName
  14626. container = rng.startContainer;
  14627. offset = rng.startOffset;
  14628. newBlockName = settings.forced_root_block;
  14629. newBlockName = newBlockName ? newBlockName.toUpperCase() : '';
  14630. documentMode = dom.doc.documentMode;
  14631. // Resolve node index
  14632. if (container.nodeType == 1 && container.hasChildNodes()) {
  14633. isAfterLastNodeInContainer = offset > container.childNodes.length - 1;
  14634. container = container.childNodes[Math.min(offset, container.childNodes.length - 1)] || container;
  14635. if (isAfterLastNodeInContainer && container.nodeType == 3) {
  14636. offset = container.nodeValue.length;
  14637. } else {
  14638. offset = 0;
  14639. }
  14640. }
  14641. // Get editable root node normaly the body element but sometimes a div or span
  14642. editableRoot = getEditableRoot(container);
  14643. // If there is no editable root then enter is done inside a contentEditable false element
  14644. if (!editableRoot) {
  14645. return;
  14646. }
  14647. undoManager.beforeChange();
  14648. // If editable root isn't block nor the root of the editor
  14649. if (!dom.isBlock(editableRoot) && editableRoot != dom.getRoot()) {
  14650. if (!newBlockName || evt.shiftKey) {
  14651. insertBr();
  14652. }
  14653. return;
  14654. }
  14655. // Wrap the current node and it's sibling in a default block if it's needed.
  14656. // for example this <td>text|<b>text2</b></td> will become this <td><p>text|<b>text2</p></b></td>
  14657. // This won't happen if root blocks are disabled or the shiftKey is pressed
  14658. if ((newBlockName && !evt.shiftKey) || (!newBlockName && evt.shiftKey)) {
  14659. container = wrapSelfAndSiblingsInDefaultBlock(container, offset);
  14660. }
  14661. // Find parent block and setup empty block paddings
  14662. parentBlock = dom.getParent(container, dom.isBlock);
  14663. containerBlock = parentBlock ? dom.getParent(parentBlock.parentNode, dom.isBlock) : null;
  14664. // Setup block names
  14665. parentBlockName = parentBlock ? parentBlock.nodeName.toUpperCase() : ''; // IE < 9 & HTML5
  14666. containerBlockName = containerBlock ? containerBlock.nodeName.toUpperCase() : ''; // IE < 9 & HTML5
  14667. // Handle enter inside an empty list item
  14668. if (parentBlockName == 'LI' && dom.isEmpty(parentBlock)) {
  14669. // Let the list plugin or browser handle nested lists for now
  14670. if (/^(UL|OL|LI)$/.test(containerBlock.parentNode.nodeName)) {
  14671. return false;
  14672. }
  14673. handleEmptyListItem();
  14674. return;
  14675. }
  14676. // Don't split PRE tags but insert a BR instead easier when writing code samples etc
  14677. if (parentBlockName == 'PRE' && settings.br_in_pre !== false) {
  14678. if (!evt.shiftKey) {
  14679. insertBr();
  14680. return;
  14681. }
  14682. } else {
  14683. // If no root block is configured then insert a BR by default or if the shiftKey is pressed
  14684. if ((!newBlockName && !evt.shiftKey && parentBlockName != 'LI') || (newBlockName && evt.shiftKey)) {
  14685. insertBr();
  14686. return;
  14687. }
  14688. }
  14689. // Default block name if it's not configured
  14690. newBlockName = newBlockName || 'P';
  14691. // Insert new block before/after the parent block depending on caret location
  14692. if (isCaretAtStartOrEndOfBlock()) {
  14693. // 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
  14694. if (/^(H[1-6]|PRE)$/.test(parentBlockName) && containerBlockName != 'HGROUP') {
  14695. newBlock = createNewBlock(newBlockName);
  14696. } else {
  14697. newBlock = createNewBlock();
  14698. }
  14699. // Split the current container block element if enter is pressed inside an empty inner block element
  14700. if (settings.end_container_on_empty_block && canSplitBlock(containerBlock) && dom.isEmpty(parentBlock)) {
  14701. // Split container block for example a BLOCKQUOTE at the current blockParent location for example a P
  14702. newBlock = dom.split(containerBlock, parentBlock);
  14703. } else {
  14704. dom.insertAfter(newBlock, parentBlock);
  14705. }
  14706. moveToCaretPosition(newBlock);
  14707. } else if (isCaretAtStartOrEndOfBlock(true)) {
  14708. // Insert new block before
  14709. newBlock = parentBlock.parentNode.insertBefore(createNewBlock(), parentBlock);
  14710. renderBlockOnIE(newBlock);
  14711. } else {
  14712. // Extract after fragment and insert it after the current block
  14713. tmpRng = rng.cloneRange();
  14714. tmpRng.setEndAfter(parentBlock);
  14715. fragment = tmpRng.extractContents();
  14716. trimLeadingLineBreaks(fragment);
  14717. newBlock = fragment.firstChild;
  14718. dom.insertAfter(fragment, parentBlock);
  14719. trimInlineElementsOnLeftSideOfBlock(newBlock);
  14720. addBrToBlockIfNeeded(parentBlock);
  14721. moveToCaretPosition(newBlock);
  14722. }
  14723. dom.setAttrib(newBlock, 'id', ''); // Remove ID since it needs to be document unique
  14724. undoManager.add();
  14725. }
  14726. editor.onKeyDown.add(function(ed, evt) {
  14727. if (evt.keyCode == 13) {
  14728. if (handleEnterKey(evt) !== false) {
  14729. evt.preventDefault();
  14730. }
  14731. }
  14732. });
  14733. };
  14734. })(tinymce);