tiny_mce_src.js 417 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064
  1. (function(win) {
  2. var whiteSpaceRe = /^\s*|\s*$/g,
  3. undefined, isRegExpBroken = 'B'.replace(/A(.)|B/, '$1') === '$1';
  4. var tinymce = {
  5. majorVersion : '3',
  6. minorVersion : '4.3.1',
  7. releaseDate : '2011-06-16',
  8. _init : function() {
  9. var t = this, d = document, na = navigator, ua = na.userAgent, i, nl, n, base, p, v;
  10. t.isOpera = win.opera && opera.buildNumber;
  11. t.isWebKit = /WebKit/.test(ua);
  12. t.isIE = !t.isWebKit && !t.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(na.appName);
  13. t.isIE6 = t.isIE && /MSIE [56]/.test(ua);
  14. t.isGecko = !t.isWebKit && /Gecko/.test(ua);
  15. t.isMac = ua.indexOf('Mac') != -1;
  16. t.isAir = /adobeair/i.test(ua);
  17. t.isIDevice = /(iPad|iPhone)/.test(ua);
  18. t.isIOS5 = t.isIDevice && ua.match(/AppleWebKit\/(\d*)/)[1]>=534;
  19. // TinyMCE .NET webcontrol might be setting the values for TinyMCE
  20. if (win.tinyMCEPreInit) {
  21. t.suffix = tinyMCEPreInit.suffix;
  22. t.baseURL = tinyMCEPreInit.base;
  23. t.query = tinyMCEPreInit.query;
  24. return;
  25. }
  26. // Get suffix and base
  27. t.suffix = '';
  28. // If base element found, add that infront of baseURL
  29. nl = d.getElementsByTagName('base');
  30. for (i=0; i<nl.length; i++) {
  31. if (v = nl[i].href) {
  32. // Host only value like http://site.com or http://site.com:8008
  33. if (/^https?:\/\/[^\/]+$/.test(v))
  34. v += '/';
  35. base = v ? v.match(/.*\//)[0] : ''; // Get only directory
  36. }
  37. }
  38. function getBase(n) {
  39. if (n.src && /tiny_mce(|_gzip|_jquery|_prototype|_full)(_dev|_src)?.js/.test(n.src)) {
  40. if (/_(src|dev)\.js/g.test(n.src))
  41. t.suffix = '_src';
  42. if ((p = n.src.indexOf('?')) != -1)
  43. t.query = n.src.substring(p + 1);
  44. t.baseURL = n.src.substring(0, n.src.lastIndexOf('/'));
  45. // If path to script is relative and a base href was found add that one infront
  46. // the src property will always be an absolute one on non IE browsers and IE 8
  47. // so this logic will basically only be executed on older IE versions
  48. if (base && t.baseURL.indexOf('://') == -1 && t.baseURL.indexOf('/') !== 0)
  49. t.baseURL = base + t.baseURL;
  50. return t.baseURL;
  51. }
  52. return null;
  53. };
  54. // Check document
  55. nl = d.getElementsByTagName('script');
  56. for (i=0; i<nl.length; i++) {
  57. if (getBase(nl[i]))
  58. return;
  59. }
  60. // Check head
  61. n = d.getElementsByTagName('head')[0];
  62. if (n) {
  63. nl = n.getElementsByTagName('script');
  64. for (i=0; i<nl.length; i++) {
  65. if (getBase(nl[i]))
  66. return;
  67. }
  68. }
  69. return;
  70. },
  71. is : function(o, t) {
  72. if (!t)
  73. return o !== undefined;
  74. if (t == 'array' && (o.hasOwnProperty && o instanceof Array))
  75. return true;
  76. return typeof(o) == t;
  77. },
  78. makeMap : function(items, delim, map) {
  79. var i;
  80. items = items || [];
  81. delim = delim || ',';
  82. if (typeof(items) == "string")
  83. items = items.split(delim);
  84. map = map || {};
  85. i = items.length;
  86. while (i--)
  87. map[items[i]] = {};
  88. return map;
  89. },
  90. each : function(o, cb, s) {
  91. var n, l;
  92. if (!o)
  93. return 0;
  94. s = s || o;
  95. if (o.length !== undefined) {
  96. // Indexed arrays, needed for Safari
  97. for (n=0, l = o.length; n < l; n++) {
  98. if (cb.call(s, o[n], n, o) === false)
  99. return 0;
  100. }
  101. } else {
  102. // Hashtables
  103. for (n in o) {
  104. if (o.hasOwnProperty(n)) {
  105. if (cb.call(s, o[n], n, o) === false)
  106. return 0;
  107. }
  108. }
  109. }
  110. return 1;
  111. },
  112. map : function(a, f) {
  113. var o = [];
  114. tinymce.each(a, function(v) {
  115. o.push(f(v));
  116. });
  117. return o;
  118. },
  119. grep : function(a, f) {
  120. var o = [];
  121. tinymce.each(a, function(v) {
  122. if (!f || f(v))
  123. o.push(v);
  124. });
  125. return o;
  126. },
  127. inArray : function(a, v) {
  128. var i, l;
  129. if (a) {
  130. for (i = 0, l = a.length; i < l; i++) {
  131. if (a[i] === v)
  132. return i;
  133. }
  134. }
  135. return -1;
  136. },
  137. extend : function(o, e) {
  138. var i, l, a = arguments;
  139. for (i = 1, l = a.length; i < l; i++) {
  140. e = a[i];
  141. tinymce.each(e, function(v, n) {
  142. if (v !== undefined)
  143. o[n] = v;
  144. });
  145. }
  146. return o;
  147. },
  148. trim : function(s) {
  149. return (s ? '' + s : '').replace(whiteSpaceRe, '');
  150. },
  151. create : function(s, p, root) {
  152. var t = this, sp, ns, cn, scn, c, de = 0;
  153. // Parse : <prefix> <class>:<super class>
  154. s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s);
  155. cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name
  156. // Create namespace for new class
  157. ns = t.createNS(s[3].replace(/\.\w+$/, ''), root);
  158. // Class already exists
  159. if (ns[cn])
  160. return;
  161. // Make pure static class
  162. if (s[2] == 'static') {
  163. ns[cn] = p;
  164. if (this.onCreate)
  165. this.onCreate(s[2], s[3], ns[cn]);
  166. return;
  167. }
  168. // Create default constructor
  169. if (!p[cn]) {
  170. p[cn] = function() {};
  171. de = 1;
  172. }
  173. // Add constructor and methods
  174. ns[cn] = p[cn];
  175. t.extend(ns[cn].prototype, p);
  176. // Extend
  177. if (s[5]) {
  178. sp = t.resolve(s[5]).prototype;
  179. scn = s[5].match(/\.(\w+)$/i)[1]; // Class name
  180. // Extend constructor
  181. c = ns[cn];
  182. if (de) {
  183. // Add passthrough constructor
  184. ns[cn] = function() {
  185. return sp[scn].apply(this, arguments);
  186. };
  187. } else {
  188. // Add inherit constructor
  189. ns[cn] = function() {
  190. this.parent = sp[scn];
  191. return c.apply(this, arguments);
  192. };
  193. }
  194. ns[cn].prototype[cn] = ns[cn];
  195. // Add super methods
  196. t.each(sp, function(f, n) {
  197. ns[cn].prototype[n] = sp[n];
  198. });
  199. // Add overridden methods
  200. t.each(p, function(f, n) {
  201. // Extend methods if needed
  202. if (sp[n]) {
  203. ns[cn].prototype[n] = function() {
  204. this.parent = sp[n];
  205. return f.apply(this, arguments);
  206. };
  207. } else {
  208. if (n != cn)
  209. ns[cn].prototype[n] = f;
  210. }
  211. });
  212. }
  213. // Add static methods
  214. t.each(p['static'], function(f, n) {
  215. ns[cn][n] = f;
  216. });
  217. if (this.onCreate)
  218. this.onCreate(s[2], s[3], ns[cn].prototype);
  219. },
  220. walk : function(o, f, n, s) {
  221. s = s || this;
  222. if (o) {
  223. if (n)
  224. o = o[n];
  225. tinymce.each(o, function(o, i) {
  226. if (f.call(s, o, i, n) === false)
  227. return false;
  228. tinymce.walk(o, f, n, s);
  229. });
  230. }
  231. },
  232. createNS : function(n, o) {
  233. var i, v;
  234. o = o || win;
  235. n = n.split('.');
  236. for (i=0; i<n.length; i++) {
  237. v = n[i];
  238. if (!o[v])
  239. o[v] = {};
  240. o = o[v];
  241. }
  242. return o;
  243. },
  244. resolve : function(n, o) {
  245. var i, l;
  246. o = o || win;
  247. n = n.split('.');
  248. for (i = 0, l = n.length; i < l; i++) {
  249. o = o[n[i]];
  250. if (!o)
  251. break;
  252. }
  253. return o;
  254. },
  255. addUnload : function(f, s) {
  256. var t = this;
  257. f = {func : f, scope : s || this};
  258. if (!t.unloads) {
  259. function unload() {
  260. var li = t.unloads, o, n;
  261. if (li) {
  262. // Call unload handlers
  263. for (n in li) {
  264. o = li[n];
  265. if (o && o.func)
  266. o.func.call(o.scope, 1); // Send in one arg to distinct unload and user destroy
  267. }
  268. // Detach unload function
  269. if (win.detachEvent) {
  270. win.detachEvent('onbeforeunload', fakeUnload);
  271. win.detachEvent('onunload', unload);
  272. } else if (win.removeEventListener)
  273. win.removeEventListener('unload', unload, false);
  274. // Destroy references
  275. t.unloads = o = li = w = unload = 0;
  276. // Run garbarge collector on IE
  277. if (win.CollectGarbage)
  278. CollectGarbage();
  279. }
  280. };
  281. function fakeUnload() {
  282. var d = document;
  283. // Is there things still loading, then do some magic
  284. if (d.readyState == 'interactive') {
  285. function stop() {
  286. // Prevent memory leak
  287. d.detachEvent('onstop', stop);
  288. // Call unload handler
  289. if (unload)
  290. unload();
  291. d = 0;
  292. };
  293. // Fire unload when the currently loading page is stopped
  294. if (d)
  295. d.attachEvent('onstop', stop);
  296. // Remove onstop listener after a while to prevent the unload function
  297. // to execute if the user presses cancel in an onbeforeunload
  298. // confirm dialog and then presses the browser stop button
  299. win.setTimeout(function() {
  300. if (d)
  301. d.detachEvent('onstop', stop);
  302. }, 0);
  303. }
  304. };
  305. // Attach unload handler
  306. if (win.attachEvent) {
  307. win.attachEvent('onunload', unload);
  308. win.attachEvent('onbeforeunload', fakeUnload);
  309. } else if (win.addEventListener)
  310. win.addEventListener('unload', unload, false);
  311. // Setup initial unload handler array
  312. t.unloads = [f];
  313. } else
  314. t.unloads.push(f);
  315. return f;
  316. },
  317. removeUnload : function(f) {
  318. var u = this.unloads, r = null;
  319. tinymce.each(u, function(o, i) {
  320. if (o && o.func == f) {
  321. u.splice(i, 1);
  322. r = f;
  323. return false;
  324. }
  325. });
  326. return r;
  327. },
  328. explode : function(s, d) {
  329. return s ? tinymce.map(s.split(d || ','), tinymce.trim) : s;
  330. },
  331. _addVer : function(u) {
  332. var v;
  333. if (!this.query)
  334. return u;
  335. v = (u.indexOf('?') == -1 ? '?' : '&') + this.query;
  336. if (u.indexOf('#') == -1)
  337. return u + v;
  338. return u.replace('#', v + '#');
  339. },
  340. // Fix function for IE 9 where regexps isn't working correctly
  341. // Todo: remove me once MS fixes the bug
  342. _replace : function(find, replace, str) {
  343. // On IE9 we have to fake $x replacement
  344. if (isRegExpBroken) {
  345. return str.replace(find, function() {
  346. var val = replace, args = arguments, i;
  347. for (i = 0; i < args.length - 2; i++) {
  348. if (args[i] === undefined) {
  349. val = val.replace(new RegExp('\\$' + i, 'g'), '');
  350. } else {
  351. val = val.replace(new RegExp('\\$' + i, 'g'), args[i]);
  352. }
  353. }
  354. return val;
  355. });
  356. }
  357. return str.replace(find, replace);
  358. }
  359. };
  360. // Initialize the API
  361. tinymce._init();
  362. // Expose tinymce namespace to the global namespace (window)
  363. win.tinymce = win.tinyMCE = tinymce;
  364. // Describe the different namespaces
  365. })(window);
  366. tinymce.create('tinymce.util.Dispatcher', {
  367. scope : null,
  368. listeners : null,
  369. Dispatcher : function(s) {
  370. this.scope = s || this;
  371. this.listeners = [];
  372. },
  373. add : function(cb, s) {
  374. this.listeners.push({cb : cb, scope : s || this.scope});
  375. return cb;
  376. },
  377. addToTop : function(cb, s) {
  378. this.listeners.unshift({cb : cb, scope : s || this.scope});
  379. return cb;
  380. },
  381. remove : function(cb) {
  382. var l = this.listeners, o = null;
  383. tinymce.each(l, function(c, i) {
  384. if (cb == c.cb) {
  385. o = cb;
  386. l.splice(i, 1);
  387. return false;
  388. }
  389. });
  390. return o;
  391. },
  392. dispatch : function() {
  393. var s, a = arguments, i, li = this.listeners, c;
  394. // Needs to be a real loop since the listener count might change while looping
  395. // And this is also more efficient
  396. for (i = 0; i<li.length; i++) {
  397. c = li[i];
  398. s = c.cb.apply(c.scope, a);
  399. if (s === false)
  400. break;
  401. }
  402. return s;
  403. }
  404. });
  405. (function() {
  406. var each = tinymce.each;
  407. tinymce.create('tinymce.util.URI', {
  408. URI : function(u, s) {
  409. var t = this, o, a, b, base_url;
  410. // Trim whitespace
  411. u = tinymce.trim(u);
  412. // Default settings
  413. s = t.settings = s || {};
  414. // Strange app protocol or local anchor
  415. if (/^(mailto|tel|news|javascript|about|data):/i.test(u) || /^\s*#/.test(u)) {
  416. t.source = u;
  417. return;
  418. }
  419. // Absolute path with no host, fake host and protocol
  420. if (u.indexOf('/') === 0 && u.indexOf('//') !== 0)
  421. u = (s.base_uri ? s.base_uri.protocol || 'http' : 'http') + '://mce_host' + u;
  422. // Relative path http:// or protocol relative //path
  423. if (!/^[\w-]*:?\/\//.test(u)) {
  424. base_url = s.base_uri ? s.base_uri.path : new tinymce.util.URI(location.href).directory;
  425. u = ((s.base_uri && s.base_uri.protocol) || 'http') + '://mce_host' + t.toAbsPath(base_url, u);
  426. }
  427. // Parse URL (Credits goes to Steave, http://blog.stevenlevithan.com/archives/parseuri)
  428. u = u.replace(/@@/g, '(mce_at)'); // Zope 3 workaround, they use @@something
  429. u = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(u);
  430. each(["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], function(v, i) {
  431. var s = u[i];
  432. // Zope 3 workaround, they use @@something
  433. if (s)
  434. s = s.replace(/\(mce_at\)/g, '@@');
  435. t[v] = s;
  436. });
  437. if (b = s.base_uri) {
  438. if (!t.protocol)
  439. t.protocol = b.protocol;
  440. if (!t.userInfo)
  441. t.userInfo = b.userInfo;
  442. if (!t.port && t.host == 'mce_host')
  443. t.port = b.port;
  444. if (!t.host || t.host == 'mce_host')
  445. t.host = b.host;
  446. t.source = '';
  447. }
  448. //t.path = t.path || '/';
  449. },
  450. setPath : function(p) {
  451. var t = this;
  452. p = /^(.*?)\/?(\w+)?$/.exec(p);
  453. // Update path parts
  454. t.path = p[0];
  455. t.directory = p[1];
  456. t.file = p[2];
  457. // Rebuild source
  458. t.source = '';
  459. t.getURI();
  460. },
  461. toRelative : function(u) {
  462. var t = this, o;
  463. if (u === "./")
  464. return u;
  465. u = new tinymce.util.URI(u, {base_uri : t});
  466. // Not on same domain/port or protocol
  467. if ((u.host != 'mce_host' && t.host != u.host && u.host) || t.port != u.port || t.protocol != u.protocol)
  468. return u.getURI();
  469. o = t.toRelPath(t.path, u.path);
  470. // Add query
  471. if (u.query)
  472. o += '?' + u.query;
  473. // Add anchor
  474. if (u.anchor)
  475. o += '#' + u.anchor;
  476. return o;
  477. },
  478. toAbsolute : function(u, nh) {
  479. var u = new tinymce.util.URI(u, {base_uri : this});
  480. return u.getURI(this.host == u.host && this.protocol == u.protocol ? nh : 0);
  481. },
  482. toRelPath : function(base, path) {
  483. var items, bp = 0, out = '', i, l;
  484. // Split the paths
  485. base = base.substring(0, base.lastIndexOf('/'));
  486. base = base.split('/');
  487. items = path.split('/');
  488. if (base.length >= items.length) {
  489. for (i = 0, l = base.length; i < l; i++) {
  490. if (i >= items.length || base[i] != items[i]) {
  491. bp = i + 1;
  492. break;
  493. }
  494. }
  495. }
  496. if (base.length < items.length) {
  497. for (i = 0, l = items.length; i < l; i++) {
  498. if (i >= base.length || base[i] != items[i]) {
  499. bp = i + 1;
  500. break;
  501. }
  502. }
  503. }
  504. if (bp == 1)
  505. return path;
  506. for (i = 0, l = base.length - (bp - 1); i < l; i++)
  507. out += "../";
  508. for (i = bp - 1, l = items.length; i < l; i++) {
  509. if (i != bp - 1)
  510. out += "/" + items[i];
  511. else
  512. out += items[i];
  513. }
  514. return out;
  515. },
  516. toAbsPath : function(base, path) {
  517. var i, nb = 0, o = [], tr, outPath;
  518. // Split paths
  519. tr = /\/$/.test(path) ? '/' : '';
  520. base = base.split('/');
  521. path = path.split('/');
  522. // Remove empty chunks
  523. each(base, function(k) {
  524. if (k)
  525. o.push(k);
  526. });
  527. base = o;
  528. // Merge relURLParts chunks
  529. for (i = path.length - 1, o = []; i >= 0; i--) {
  530. // Ignore empty or .
  531. if (path[i].length == 0 || path[i] == ".")
  532. continue;
  533. // Is parent
  534. if (path[i] == '..') {
  535. nb++;
  536. continue;
  537. }
  538. // Move up
  539. if (nb > 0) {
  540. nb--;
  541. continue;
  542. }
  543. o.push(path[i]);
  544. }
  545. i = base.length - nb;
  546. // If /a/b/c or /
  547. if (i <= 0)
  548. outPath = o.reverse().join('/');
  549. else
  550. outPath = base.slice(0, i).join('/') + '/' + o.reverse().join('/');
  551. // Add front / if it's needed
  552. if (outPath.indexOf('/') !== 0)
  553. outPath = '/' + outPath;
  554. // Add traling / if it's needed
  555. if (tr && outPath.lastIndexOf('/') !== outPath.length - 1)
  556. outPath += tr;
  557. return outPath;
  558. },
  559. getURI : function(nh) {
  560. var s, t = this;
  561. // Rebuild source
  562. if (!t.source || nh) {
  563. s = '';
  564. if (!nh) {
  565. if (t.protocol)
  566. s += t.protocol + '://';
  567. if (t.userInfo)
  568. s += t.userInfo + '@';
  569. if (t.host)
  570. s += t.host;
  571. if (t.port)
  572. s += ':' + t.port;
  573. }
  574. if (t.path)
  575. s += t.path;
  576. if (t.query)
  577. s += '?' + t.query;
  578. if (t.anchor)
  579. s += '#' + t.anchor;
  580. t.source = s;
  581. }
  582. return t.source;
  583. }
  584. });
  585. })();
  586. (function() {
  587. var each = tinymce.each;
  588. tinymce.create('static tinymce.util.Cookie', {
  589. getHash : function(n) {
  590. var v = this.get(n), h;
  591. if (v) {
  592. each(v.split('&'), function(v) {
  593. v = v.split('=');
  594. h = h || {};
  595. h[unescape(v[0])] = unescape(v[1]);
  596. });
  597. }
  598. return h;
  599. },
  600. setHash : function(n, v, e, p, d, s) {
  601. var o = '';
  602. each(v, function(v, k) {
  603. o += (!o ? '' : '&') + escape(k) + '=' + escape(v);
  604. });
  605. this.set(n, o, e, p, d, s);
  606. },
  607. get : function(n) {
  608. var c = document.cookie, e, p = n + "=", b;
  609. // Strict mode
  610. if (!c)
  611. return;
  612. b = c.indexOf("; " + p);
  613. if (b == -1) {
  614. b = c.indexOf(p);
  615. if (b != 0)
  616. return null;
  617. } else
  618. b += 2;
  619. e = c.indexOf(";", b);
  620. if (e == -1)
  621. e = c.length;
  622. return unescape(c.substring(b + p.length, e));
  623. },
  624. set : function(n, v, e, p, d, s) {
  625. document.cookie = n + "=" + escape(v) +
  626. ((e) ? "; expires=" + e.toGMTString() : "") +
  627. ((p) ? "; path=" + escape(p) : "") +
  628. ((d) ? "; domain=" + d : "") +
  629. ((s) ? "; secure" : "");
  630. },
  631. remove : function(n, p) {
  632. var d = new Date();
  633. d.setTime(d.getTime() - 1000);
  634. this.set(n, '', d, p, d);
  635. }
  636. });
  637. })();
  638. (function() {
  639. function serialize(o, quote) {
  640. var i, v, t;
  641. quote = quote || '"';
  642. if (o == null)
  643. return 'null';
  644. t = typeof o;
  645. if (t == 'string') {
  646. v = '\bb\tt\nn\ff\rr\""\'\'\\\\';
  647. return quote + o.replace(/([\u0080-\uFFFF\x00-\x1f\"\'\\])/g, function(a, b) {
  648. // Make sure single quotes never get encoded inside double quotes for JSON compatibility
  649. if (quote === '"' && a === "'")
  650. return a;
  651. i = v.indexOf(b);
  652. if (i + 1)
  653. return '\\' + v.charAt(i + 1);
  654. a = b.charCodeAt().toString(16);
  655. return '\\u' + '0000'.substring(a.length) + a;
  656. }) + quote;
  657. }
  658. if (t == 'object') {
  659. if (o.hasOwnProperty && o instanceof Array) {
  660. for (i=0, v = '['; i<o.length; i++)
  661. v += (i > 0 ? ',' : '') + serialize(o[i], quote);
  662. return v + ']';
  663. }
  664. v = '{';
  665. for (i in o)
  666. v += typeof o[i] != 'function' ? (v.length > 1 ? ',' + quote : quote) + i + quote +':' + serialize(o[i], quote) : '';
  667. return v + '}';
  668. }
  669. return '' + o;
  670. };
  671. tinymce.util.JSON = {
  672. serialize: serialize,
  673. parse: function(s) {
  674. try {
  675. return eval('(' + s + ')');
  676. } catch (ex) {
  677. // Ignore
  678. }
  679. }
  680. };
  681. })();
  682. tinymce.create('static tinymce.util.XHR', {
  683. send : function(o) {
  684. var x, t, w = window, c = 0;
  685. // Default settings
  686. o.scope = o.scope || this;
  687. o.success_scope = o.success_scope || o.scope;
  688. o.error_scope = o.error_scope || o.scope;
  689. o.async = o.async === false ? false : true;
  690. o.data = o.data || '';
  691. function get(s) {
  692. x = 0;
  693. try {
  694. x = new ActiveXObject(s);
  695. } catch (ex) {
  696. }
  697. return x;
  698. };
  699. x = w.XMLHttpRequest ? new XMLHttpRequest() : get('Microsoft.XMLHTTP') || get('Msxml2.XMLHTTP');
  700. if (x) {
  701. if (x.overrideMimeType)
  702. x.overrideMimeType(o.content_type);
  703. x.open(o.type || (o.data ? 'POST' : 'GET'), o.url, o.async);
  704. if (o.content_type)
  705. x.setRequestHeader('Content-Type', o.content_type);
  706. x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  707. x.send(o.data);
  708. function ready() {
  709. if (!o.async || x.readyState == 4 || c++ > 10000) {
  710. if (o.success && c < 10000 && x.status == 200)
  711. o.success.call(o.success_scope, '' + x.responseText, x, o);
  712. else if (o.error)
  713. o.error.call(o.error_scope, c > 10000 ? 'TIMED_OUT' : 'GENERAL', x, o);
  714. x = null;
  715. } else
  716. w.setTimeout(ready, 10);
  717. };
  718. // Syncronous request
  719. if (!o.async)
  720. return ready();
  721. // Wait for response, onReadyStateChange can not be used since it leaks memory in IE
  722. t = w.setTimeout(ready, 10);
  723. }
  724. }
  725. });
  726. (function() {
  727. var extend = tinymce.extend, JSON = tinymce.util.JSON, XHR = tinymce.util.XHR;
  728. tinymce.create('tinymce.util.JSONRequest', {
  729. JSONRequest : function(s) {
  730. this.settings = extend({
  731. }, s);
  732. this.count = 0;
  733. },
  734. send : function(o) {
  735. var ecb = o.error, scb = o.success;
  736. o = extend(this.settings, o);
  737. o.success = function(c, x) {
  738. c = JSON.parse(c);
  739. if (typeof(c) == 'undefined') {
  740. c = {
  741. error : 'JSON Parse error.'
  742. };
  743. }
  744. if (c.error)
  745. ecb.call(o.error_scope || o.scope, c.error, x);
  746. else
  747. scb.call(o.success_scope || o.scope, c.result);
  748. };
  749. o.error = function(ty, x) {
  750. if (ecb)
  751. ecb.call(o.error_scope || o.scope, ty, x);
  752. };
  753. o.data = JSON.serialize({
  754. id : o.id || 'c' + (this.count++),
  755. method : o.method,
  756. params : o.params
  757. });
  758. // JSON content type for Ruby on rails. Bug: #1883287
  759. o.content_type = 'application/json';
  760. XHR.send(o);
  761. },
  762. 'static' : {
  763. sendRPC : function(o) {
  764. return new tinymce.util.JSONRequest().send(o);
  765. }
  766. }
  767. });
  768. }());
  769. (function(tinymce) {
  770. var namedEntities, baseEntities, reverseEntities,
  771. attrsCharsRegExp = /[&<>\"\u007E-\uD7FF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  772. textCharsRegExp = /[<>&\u007E-\uD7FF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  773. rawCharsRegExp = /[<>&\"\']/g,
  774. entityRegExp = /&(#x|#)?([\w]+);/g,
  775. asciiMap = {
  776. 128 : "\u20AC", 130 : "\u201A", 131 : "\u0192", 132 : "\u201E", 133 : "\u2026", 134 : "\u2020",
  777. 135 : "\u2021", 136 : "\u02C6", 137 : "\u2030", 138 : "\u0160", 139 : "\u2039", 140 : "\u0152",
  778. 142 : "\u017D", 145 : "\u2018", 146 : "\u2019", 147 : "\u201C", 148 : "\u201D", 149 : "\u2022",
  779. 150 : "\u2013", 151 : "\u2014", 152 : "\u02DC", 153 : "\u2122", 154 : "\u0161", 155 : "\u203A",
  780. 156 : "\u0153", 158 : "\u017E", 159 : "\u0178"
  781. };
  782. // Raw entities
  783. baseEntities = {
  784. '"' : '&quot;',
  785. "'" : '&#39;',
  786. '<' : '&lt;',
  787. '>' : '&gt;',
  788. '&' : '&amp;'
  789. };
  790. // Reverse lookup table for raw entities
  791. reverseEntities = {
  792. '&lt;' : '<',
  793. '&gt;' : '>',
  794. '&amp;' : '&',
  795. '&quot;' : '"',
  796. '&apos;' : "'"
  797. };
  798. // Decodes text by using the browser
  799. function nativeDecode(text) {
  800. var elm;
  801. elm = document.createElement("div");
  802. elm.innerHTML = text;
  803. return elm.textContent || elm.innerText || text;
  804. };
  805. // Build a two way lookup table for the entities
  806. function buildEntitiesLookup(items, radix) {
  807. var i, chr, entity, lookup = {};
  808. if (items) {
  809. items = items.split(',');
  810. radix = radix || 10;
  811. // Build entities lookup table
  812. for (i = 0; i < items.length; i += 2) {
  813. chr = String.fromCharCode(parseInt(items[i], radix));
  814. // Only add non base entities
  815. if (!baseEntities[chr]) {
  816. entity = '&' + items[i + 1] + ';';
  817. lookup[chr] = entity;
  818. lookup[entity] = chr;
  819. }
  820. }
  821. return lookup;
  822. }
  823. };
  824. // Unpack entities lookup where the numbers are in radix 32 to reduce the size
  825. namedEntities = buildEntitiesLookup(
  826. '50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,' +
  827. '5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,' +
  828. '5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,' +
  829. '5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,' +
  830. '68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,' +
  831. '6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,' +
  832. '6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,' +
  833. '75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,' +
  834. '7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,' +
  835. '7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,' +
  836. 'sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,' +
  837. 'st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,' +
  838. 't9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,' +
  839. 'tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,' +
  840. 'u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,' +
  841. '81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,' +
  842. '8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,' +
  843. '8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,' +
  844. '8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,' +
  845. '8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,' +
  846. 'nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,' +
  847. 'rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,' +
  848. 'Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,' +
  849. '80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,' +
  850. '811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro'
  851. , 32);
  852. tinymce.html = tinymce.html || {};
  853. tinymce.html.Entities = {
  854. encodeRaw : function(text, attr) {
  855. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  856. return baseEntities[chr] || chr;
  857. });
  858. },
  859. encodeAllRaw : function(text) {
  860. return ('' + text).replace(rawCharsRegExp, function(chr) {
  861. return baseEntities[chr] || chr;
  862. });
  863. },
  864. encodeNumeric : function(text, attr) {
  865. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  866. // Multi byte sequence convert it to a single entity
  867. if (chr.length > 1)
  868. return '&#' + (((chr.charCodeAt(0) - 0xD800) * 0x400) + (chr.charCodeAt(1) - 0xDC00) + 0x10000) + ';';
  869. return baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';';
  870. });
  871. },
  872. encodeNamed : function(text, attr, entities) {
  873. entities = entities || namedEntities;
  874. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  875. return baseEntities[chr] || entities[chr] || chr;
  876. });
  877. },
  878. getEncodeFunc : function(name, entities) {
  879. var Entities = tinymce.html.Entities;
  880. entities = buildEntitiesLookup(entities) || namedEntities;
  881. function encodeNamedAndNumeric(text, attr) {
  882. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  883. return baseEntities[chr] || entities[chr] || '&#' + chr.charCodeAt(0) + ';' || chr;
  884. });
  885. };
  886. function encodeCustomNamed(text, attr) {
  887. return Entities.encodeNamed(text, attr, entities);
  888. };
  889. // Replace + with , to be compatible with previous TinyMCE versions
  890. name = tinymce.makeMap(name.replace(/\+/g, ','));
  891. // Named and numeric encoder
  892. if (name.named && name.numeric)
  893. return encodeNamedAndNumeric;
  894. // Named encoder
  895. if (name.named) {
  896. // Custom names
  897. if (entities)
  898. return encodeCustomNamed;
  899. return Entities.encodeNamed;
  900. }
  901. // Numeric
  902. if (name.numeric)
  903. return Entities.encodeNumeric;
  904. // Raw encoder
  905. return Entities.encodeRaw;
  906. },
  907. decode : function(text) {
  908. return text.replace(entityRegExp, function(all, numeric, value) {
  909. if (numeric) {
  910. value = parseInt(value, numeric.length === 2 ? 16 : 10);
  911. // Support upper UTF
  912. if (value > 0xFFFF) {
  913. value -= 0x10000;
  914. return String.fromCharCode(0xD800 + (value >> 10), 0xDC00 + (value & 0x3FF));
  915. } else
  916. return asciiMap[value] || String.fromCharCode(value);
  917. }
  918. return reverseEntities[all] || namedEntities[all] || nativeDecode(all);
  919. });
  920. }
  921. };
  922. })(tinymce);
  923. tinymce.html.Styles = function(settings, schema) {
  924. var rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi,
  925. urlOrStrRegExp = /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi,
  926. styleRegExp = /\s*([^:]+):\s*([^;]+);?/g,
  927. trimRightRegExp = /\s+$/,
  928. urlColorRegExp = /rgb/,
  929. undef, i, encodingLookup = {}, encodingItems;
  930. settings = settings || {};
  931. encodingItems = '\\" \\\' \\; \\: ; : \uFEFF'.split(' ');
  932. for (i = 0; i < encodingItems.length; i++) {
  933. encodingLookup[encodingItems[i]] = '\uFEFF' + i;
  934. encodingLookup['\uFEFF' + i] = encodingItems[i];
  935. }
  936. function toHex(match, r, g, b) {
  937. function hex(val) {
  938. val = parseInt(val).toString(16);
  939. return val.length > 1 ? val : '0' + val; // 0 -> 00
  940. };
  941. return '#' + hex(r) + hex(g) + hex(b);
  942. };
  943. return {
  944. toHex : function(color) {
  945. return color.replace(rgbRegExp, toHex);
  946. },
  947. parse : function(css) {
  948. var styles = {}, matches, name, value, isEncoded, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope || this;
  949. function compress(prefix, suffix) {
  950. var top, right, bottom, left;
  951. // Get values and check it it needs compressing
  952. top = styles[prefix + '-top' + suffix];
  953. if (!top)
  954. return;
  955. right = styles[prefix + '-right' + suffix];
  956. if (top != right)
  957. return;
  958. bottom = styles[prefix + '-bottom' + suffix];
  959. if (right != bottom)
  960. return;
  961. left = styles[prefix + '-left' + suffix];
  962. if (bottom != left)
  963. return;
  964. // Compress
  965. styles[prefix + suffix] = left;
  966. delete styles[prefix + '-top' + suffix];
  967. delete styles[prefix + '-right' + suffix];
  968. delete styles[prefix + '-bottom' + suffix];
  969. delete styles[prefix + '-left' + suffix];
  970. };
  971. function canCompress(key) {
  972. var value = styles[key], i;
  973. if (!value || value.indexOf(' ') < 0)
  974. return;
  975. value = value.split(' ');
  976. i = value.length;
  977. while (i--) {
  978. if (value[i] !== value[0])
  979. return false;
  980. }
  981. styles[key] = value[0];
  982. return true;
  983. };
  984. function compress2(target, a, b, c) {
  985. if (!canCompress(a))
  986. return;
  987. if (!canCompress(b))
  988. return;
  989. if (!canCompress(c))
  990. return;
  991. // Compress
  992. styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c];
  993. delete styles[a];
  994. delete styles[b];
  995. delete styles[c];
  996. };
  997. // Encodes the specified string by replacing all \" \' ; : with _<num>
  998. function encode(str) {
  999. isEncoded = true;
  1000. return encodingLookup[str];
  1001. };
  1002. // Decodes the specified string by replacing all _<num> with it's original value \" \' etc
  1003. // It will also decode the \" \' if keep_slashes is set to fale or omitted
  1004. function decode(str, keep_slashes) {
  1005. if (isEncoded) {
  1006. str = str.replace(/\uFEFF[0-9]/g, function(str) {
  1007. return encodingLookup[str];
  1008. });
  1009. }
  1010. if (!keep_slashes)
  1011. str = str.replace(/\\([\'\";:])/g, "$1");
  1012. return str;
  1013. }
  1014. if (css) {
  1015. // Encode \" \' % and ; and : inside strings so they don't interfere with the style parsing
  1016. css = css.replace(/\\[\"\';:\uFEFF]/g, encode).replace(/\"[^\"]+\"|\'[^\']+\'/g, function(str) {
  1017. return str.replace(/[;:]/g, encode);
  1018. });
  1019. // Parse styles
  1020. while (matches = styleRegExp.exec(css)) {
  1021. name = matches[1].replace(trimRightRegExp, '').toLowerCase();
  1022. value = matches[2].replace(trimRightRegExp, '');
  1023. if (name && value.length > 0) {
  1024. // Opera will produce 700 instead of bold in their style values
  1025. if (name === 'font-weight' && value === '700')
  1026. value = 'bold';
  1027. else if (name === 'color' || name === 'background-color') // Lowercase colors like RED
  1028. value = value.toLowerCase();
  1029. // Convert RGB colors to HEX
  1030. value = value.replace(rgbRegExp, toHex);
  1031. // Convert URLs and force them into url('value') format
  1032. value = value.replace(urlOrStrRegExp, function(match, url, url2, url3, str, str2) {
  1033. str = str || str2;
  1034. if (str) {
  1035. str = decode(str);
  1036. // Force strings into single quote format
  1037. return "'" + str.replace(/\'/g, "\\'") + "'";
  1038. }
  1039. url = decode(url || url2 || url3);
  1040. // Convert the URL to relative/absolute depending on config
  1041. if (urlConverter)
  1042. url = urlConverter.call(urlConverterScope, url, 'style');
  1043. // Output new URL format
  1044. return "url('" + url.replace(/\'/g, "\\'") + "')";
  1045. });
  1046. styles[name] = isEncoded ? decode(value, true) : value;
  1047. }
  1048. styleRegExp.lastIndex = matches.index + matches[0].length;
  1049. }
  1050. // Compress the styles to reduce it's size for example IE will expand styles
  1051. compress("border", "");
  1052. compress("border", "-width");
  1053. compress("border", "-color");
  1054. compress("border", "-style");
  1055. compress("padding", "");
  1056. compress("margin", "");
  1057. compress2('border', 'border-width', 'border-style', 'border-color');
  1058. // Remove pointless border, IE produces these
  1059. if (styles.border === 'medium none')
  1060. delete styles.border;
  1061. }
  1062. return styles;
  1063. },
  1064. serialize : function(styles, element_name) {
  1065. var css = '', name, value;
  1066. function serializeStyles(name) {
  1067. var styleList, i, l, value;
  1068. styleList = schema.styles[name];
  1069. if (styleList) {
  1070. for (i = 0, l = styleList.length; i < l; i++) {
  1071. name = styleList[i];
  1072. value = styles[name];
  1073. if (value !== undef && value.length > 0)
  1074. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  1075. }
  1076. }
  1077. };
  1078. // Serialize styles according to schema
  1079. if (element_name && schema && schema.styles) {
  1080. // Serialize global styles and element specific styles
  1081. serializeStyles('*');
  1082. serializeStyles(element_name);
  1083. } else {
  1084. // Output the styles in the order they are inside the object
  1085. for (name in styles) {
  1086. value = styles[name];
  1087. if (value !== undef && value.length > 0)
  1088. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  1089. }
  1090. }
  1091. return css;
  1092. }
  1093. };
  1094. };
  1095. (function(tinymce) {
  1096. var transitional = {}, boolAttrMap, blockElementsMap, shortEndedElementsMap, nonEmptyElementsMap, customElementsMap = {},
  1097. whiteSpaceElementsMap, selfClosingElementsMap, makeMap = tinymce.makeMap, each = tinymce.each;
  1098. function split(str, delim) {
  1099. return str.split(delim || ',');
  1100. };
  1101. function unpack(lookup, data) {
  1102. var key, elements = {};
  1103. function replace(value) {
  1104. return value.replace(/[A-Z]+/g, function(key) {
  1105. return replace(lookup[key]);
  1106. });
  1107. };
  1108. // Unpack lookup
  1109. for (key in lookup) {
  1110. if (lookup.hasOwnProperty(key))
  1111. lookup[key] = replace(lookup[key]);
  1112. }
  1113. // Unpack and parse data into object map
  1114. replace(data).replace(/#/g, '#text').replace(/(\w+)\[([^\]]+)\]\[([^\]]*)\]/g, function(str, name, attributes, children) {
  1115. attributes = split(attributes, '|');
  1116. elements[name] = {
  1117. attributes : makeMap(attributes),
  1118. attributesOrder : attributes,
  1119. children : makeMap(children, '|', {'#comment' : {}})
  1120. }
  1121. });
  1122. return elements;
  1123. };
  1124. // Build a lookup table for block elements both lowercase and uppercase
  1125. blockElementsMap = 'h1,h2,h3,h4,h5,h6,hr,p,div,address,pre,form,table,tbody,thead,tfoot,' +
  1126. 'th,tr,td,li,ol,ul,caption,blockquote,center,dl,dt,dd,dir,fieldset,' +
  1127. 'noscript,menu,isindex,samp,header,footer,article,section,hgroup';
  1128. blockElementsMap = makeMap(blockElementsMap, ',', makeMap(blockElementsMap.toUpperCase()));
  1129. // This is the XHTML 1.0 transitional elements with it's attributes and children packed to reduce it's size
  1130. transitional = unpack({
  1131. Z : 'H|K|N|O|P',
  1132. Y : 'X|form|R|Q',
  1133. ZG : 'E|span|width|align|char|charoff|valign',
  1134. X : 'p|T|div|U|W|isindex|fieldset|table',
  1135. ZF : 'E|align|char|charoff|valign',
  1136. W : 'pre|hr|blockquote|address|center|noframes',
  1137. ZE : 'abbr|axis|headers|scope|rowspan|colspan|align|char|charoff|valign|nowrap|bgcolor|width|height',
  1138. ZD : '[E][S]',
  1139. U : 'ul|ol|dl|menu|dir',
  1140. ZC : 'p|Y|div|U|W|table|br|span|bdo|object|applet|img|map|K|N|Q',
  1141. T : 'h1|h2|h3|h4|h5|h6',
  1142. ZB : 'X|S|Q',
  1143. S : 'R|P',
  1144. ZA : 'a|G|J|M|O|P',
  1145. R : 'a|H|K|N|O',
  1146. Q : 'noscript|P',
  1147. P : 'ins|del|script',
  1148. O : 'input|select|textarea|label|button',
  1149. N : 'M|L',
  1150. M : 'em|strong|dfn|code|q|samp|kbd|var|cite|abbr|acronym',
  1151. L : 'sub|sup',
  1152. K : 'J|I',
  1153. J : 'tt|i|b|u|s|strike',
  1154. I : 'big|small|font|basefont',
  1155. H : 'G|F',
  1156. G : 'br|span|bdo',
  1157. F : 'object|applet|img|map|iframe',
  1158. E : 'A|B|C',
  1159. D : 'accesskey|tabindex|onfocus|onblur',
  1160. C : 'onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup',
  1161. B : 'lang|xml:lang|dir',
  1162. A : 'id|class|style|title'
  1163. }, 'script[id|charset|type|language|src|defer|xml:space][]' +
  1164. 'style[B|id|type|media|title|xml:space][]' +
  1165. 'object[E|declare|classid|codebase|data|type|codetype|archive|standby|width|height|usemap|name|tabindex|align|border|hspace|vspace][#|param|Y]' +
  1166. 'param[id|name|value|valuetype|type][]' +
  1167. 'p[E|align][#|S]' +
  1168. 'a[E|D|charset|type|name|href|hreflang|rel|rev|shape|coords|target][#|Z]' +
  1169. 'br[A|clear][]' +
  1170. 'span[E][#|S]' +
  1171. 'bdo[A|C|B][#|S]' +
  1172. 'applet[A|codebase|archive|code|object|alt|name|width|height|align|hspace|vspace][#|param|Y]' +
  1173. 'h1[E|align][#|S]' +
  1174. 'img[E|src|alt|name|longdesc|width|height|usemap|ismap|align|border|hspace|vspace][]' +
  1175. 'map[B|C|A|name][X|form|Q|area]' +
  1176. 'h2[E|align][#|S]' +
  1177. 'iframe[A|longdesc|name|src|frameborder|marginwidth|marginheight|scrolling|align|width|height][#|Y]' +
  1178. 'h3[E|align][#|S]' +
  1179. 'tt[E][#|S]' +
  1180. 'i[E][#|S]' +
  1181. 'b[E][#|S]' +
  1182. 'u[E][#|S]' +
  1183. 's[E][#|S]' +
  1184. 'strike[E][#|S]' +
  1185. 'big[E][#|S]' +
  1186. 'small[E][#|S]' +
  1187. 'font[A|B|size|color|face][#|S]' +
  1188. 'basefont[id|size|color|face][]' +
  1189. 'em[E][#|S]' +
  1190. 'strong[E][#|S]' +
  1191. 'dfn[E][#|S]' +
  1192. 'code[E][#|S]' +
  1193. 'q[E|cite][#|S]' +
  1194. 'samp[E][#|S]' +
  1195. 'kbd[E][#|S]' +
  1196. 'var[E][#|S]' +
  1197. 'cite[E][#|S]' +
  1198. 'abbr[E][#|S]' +
  1199. 'acronym[E][#|S]' +
  1200. 'sub[E][#|S]' +
  1201. 'sup[E][#|S]' +
  1202. 'input[E|D|type|name|value|checked|disabled|readonly|size|maxlength|src|alt|usemap|onselect|onchange|accept|align][]' +
  1203. 'select[E|name|size|multiple|disabled|tabindex|onfocus|onblur|onchange][optgroup|option]' +
  1204. 'optgroup[E|disabled|label][option]' +
  1205. 'option[E|selected|disabled|label|value][]' +
  1206. 'textarea[E|D|name|rows|cols|disabled|readonly|onselect|onchange][]' +
  1207. 'label[E|for|accesskey|onfocus|onblur][#|S]' +
  1208. 'button[E|D|name|value|type|disabled][#|p|T|div|U|W|table|G|object|applet|img|map|K|N|Q]' +
  1209. 'h4[E|align][#|S]' +
  1210. 'ins[E|cite|datetime][#|Y]' +
  1211. 'h5[E|align][#|S]' +
  1212. 'del[E|cite|datetime][#|Y]' +
  1213. 'h6[E|align][#|S]' +
  1214. 'div[E|align][#|Y]' +
  1215. 'ul[E|type|compact][li]' +
  1216. 'li[E|type|value][#|Y]' +
  1217. 'ol[E|type|compact|start][li]' +
  1218. 'dl[E|compact][dt|dd]' +
  1219. 'dt[E][#|S]' +
  1220. 'dd[E][#|Y]' +
  1221. 'menu[E|compact][li]' +
  1222. 'dir[E|compact][li]' +
  1223. 'pre[E|width|xml:space][#|ZA]' +
  1224. 'hr[E|align|noshade|size|width][]' +
  1225. 'blockquote[E|cite][#|Y]' +
  1226. 'address[E][#|S|p]' +
  1227. 'center[E][#|Y]' +
  1228. 'noframes[E][#|Y]' +
  1229. 'isindex[A|B|prompt][]' +
  1230. 'fieldset[E][#|legend|Y]' +
  1231. 'legend[E|accesskey|align][#|S]' +
  1232. 'table[E|summary|width|border|frame|rules|cellspacing|cellpadding|align|bgcolor][caption|col|colgroup|thead|tfoot|tbody|tr]' +
  1233. 'caption[E|align][#|S]' +
  1234. 'col[ZG][]' +
  1235. 'colgroup[ZG][col]' +
  1236. 'thead[ZF][tr]' +
  1237. 'tr[ZF|bgcolor][th|td]' +
  1238. 'th[E|ZE][#|Y]' +
  1239. 'form[E|action|method|name|enctype|onsubmit|onreset|accept|accept-charset|target][#|X|R|Q]' +
  1240. 'noscript[E][#|Y]' +
  1241. 'td[E|ZE][#|Y]' +
  1242. 'tfoot[ZF][tr]' +
  1243. 'tbody[ZF][tr]' +
  1244. 'area[E|D|shape|coords|href|nohref|alt|target][]' +
  1245. 'base[id|href|target][]' +
  1246. 'body[E|onload|onunload|background|bgcolor|text|link|vlink|alink][#|Y]'
  1247. );
  1248. boolAttrMap = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected,preload,autoplay,loop,controls');
  1249. shortEndedElementsMap = makeMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed,source');
  1250. nonEmptyElementsMap = tinymce.extend(makeMap('td,th,iframe,video,object'), shortEndedElementsMap);
  1251. whiteSpaceElementsMap = makeMap('pre,script,style');
  1252. selfClosingElementsMap = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr');
  1253. tinymce.html.Schema = function(settings) {
  1254. var self = this, elements = {}, children = {}, patternElements = [], validStyles;
  1255. settings = settings || {};
  1256. // Allow all elements and attributes if verify_html is set to false
  1257. if (settings.verify_html === false)
  1258. settings.valid_elements = '*[*]';
  1259. // Build styles list
  1260. if (settings.valid_styles) {
  1261. validStyles = {};
  1262. // Convert styles into a rule list
  1263. each(settings.valid_styles, function(value, key) {
  1264. validStyles[key] = tinymce.explode(value);
  1265. });
  1266. }
  1267. // Converts a wildcard expression string to a regexp for example *a will become /.*a/.
  1268. function patternToRegExp(str) {
  1269. return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$');
  1270. };
  1271. // Parses the specified valid_elements string and adds to the current rules
  1272. // This function is a bit hard to read since it's heavily optimized for speed
  1273. function addValidElements(valid_elements) {
  1274. var ei, el, ai, al, yl, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder,
  1275. prefix, outputName, globalAttributes, globalAttributesOrder, transElement, key, childKey, value,
  1276. elementRuleRegExp = /^([#+-])?([^\[\/]+)(?:\/([^\[]+))?(?:\[([^\]]+)\])?$/,
  1277. attrRuleRegExp = /^([!\-])?(\w+::\w+|[^=:<]+)?(?:([=:<])(.*))?$/,
  1278. hasPatternsRegExp = /[*?+]/;
  1279. if (valid_elements) {
  1280. // Split valid elements into an array with rules
  1281. valid_elements = split(valid_elements);
  1282. if (elements['@']) {
  1283. globalAttributes = elements['@'].attributes;
  1284. globalAttributesOrder = elements['@'].attributesOrder;
  1285. }
  1286. // Loop all rules
  1287. for (ei = 0, el = valid_elements.length; ei < el; ei++) {
  1288. // Parse element rule
  1289. matches = elementRuleRegExp.exec(valid_elements[ei]);
  1290. if (matches) {
  1291. // Setup local names for matches
  1292. prefix = matches[1];
  1293. elementName = matches[2];
  1294. outputName = matches[3];
  1295. attrData = matches[4];
  1296. // Create new attributes and attributesOrder
  1297. attributes = {};
  1298. attributesOrder = [];
  1299. // Create the new element
  1300. element = {
  1301. attributes : attributes,
  1302. attributesOrder : attributesOrder
  1303. };
  1304. // Padd empty elements prefix
  1305. if (prefix === '#')
  1306. element.paddEmpty = true;
  1307. // Remove empty elements prefix
  1308. if (prefix === '-')
  1309. element.removeEmpty = true;
  1310. // Copy attributes from global rule into current rule
  1311. if (globalAttributes) {
  1312. for (key in globalAttributes)
  1313. attributes[key] = globalAttributes[key];
  1314. attributesOrder.push.apply(attributesOrder, globalAttributesOrder);
  1315. }
  1316. // Attributes defined
  1317. if (attrData) {
  1318. attrData = split(attrData, '|');
  1319. for (ai = 0, al = attrData.length; ai < al; ai++) {
  1320. matches = attrRuleRegExp.exec(attrData[ai]);
  1321. if (matches) {
  1322. attr = {};
  1323. attrType = matches[1];
  1324. attrName = matches[2].replace(/::/g, ':');
  1325. prefix = matches[3];
  1326. value = matches[4];
  1327. // Required
  1328. if (attrType === '!') {
  1329. element.attributesRequired = element.attributesRequired || [];
  1330. element.attributesRequired.push(attrName);
  1331. attr.required = true;
  1332. }
  1333. // Denied from global
  1334. if (attrType === '-') {
  1335. delete attributes[attrName];
  1336. attributesOrder.splice(tinymce.inArray(attributesOrder, attrName), 1);
  1337. continue;
  1338. }
  1339. // Default value
  1340. if (prefix) {
  1341. // Default value
  1342. if (prefix === '=') {
  1343. element.attributesDefault = element.attributesDefault || [];
  1344. element.attributesDefault.push({name: attrName, value: value});
  1345. attr.defaultValue = value;
  1346. }
  1347. // Forced value
  1348. if (prefix === ':') {
  1349. element.attributesForced = element.attributesForced || [];
  1350. element.attributesForced.push({name: attrName, value: value});
  1351. attr.forcedValue = value;
  1352. }
  1353. // Required values
  1354. if (prefix === '<')
  1355. attr.validValues = makeMap(value, '?');
  1356. }
  1357. // Check for attribute patterns
  1358. if (hasPatternsRegExp.test(attrName)) {
  1359. element.attributePatterns = element.attributePatterns || [];
  1360. attr.pattern = patternToRegExp(attrName);
  1361. element.attributePatterns.push(attr);
  1362. } else {
  1363. // Add attribute to order list if it doesn't already exist
  1364. if (!attributes[attrName])
  1365. attributesOrder.push(attrName);
  1366. attributes[attrName] = attr;
  1367. }
  1368. }
  1369. }
  1370. }
  1371. // Global rule, store away these for later usage
  1372. if (!globalAttributes && elementName == '@') {
  1373. globalAttributes = attributes;
  1374. globalAttributesOrder = attributesOrder;
  1375. }
  1376. // Handle substitute elements such as b/strong
  1377. if (outputName) {
  1378. element.outputName = elementName;
  1379. elements[outputName] = element;
  1380. }
  1381. // Add pattern or exact element
  1382. if (hasPatternsRegExp.test(elementName)) {
  1383. element.pattern = patternToRegExp(elementName);
  1384. patternElements.push(element);
  1385. } else
  1386. elements[elementName] = element;
  1387. }
  1388. }
  1389. }
  1390. };
  1391. function setValidElements(valid_elements) {
  1392. elements = {};
  1393. patternElements = [];
  1394. addValidElements(valid_elements);
  1395. each(transitional, function(element, name) {
  1396. children[name] = element.children;
  1397. });
  1398. };
  1399. // Adds custom non HTML elements to the schema
  1400. function addCustomElements(custom_elements) {
  1401. var customElementRegExp = /^(~)?(.+)$/;
  1402. if (custom_elements) {
  1403. each(split(custom_elements), function(rule) {
  1404. var matches = customElementRegExp.exec(rule),
  1405. inline = matches[1] === '~',
  1406. cloneName = inline ? 'span' : 'div',
  1407. name = matches[2];
  1408. children[name] = children[cloneName];
  1409. customElementsMap[name] = cloneName;
  1410. // If it's not marked as inline then add it to valid block elements
  1411. if (!inline)
  1412. blockElementsMap[name] = {};
  1413. // Add custom elements at span/div positions
  1414. each(children, function(element, child) {
  1415. if (element[cloneName])
  1416. element[name] = element[cloneName];
  1417. });
  1418. });
  1419. }
  1420. };
  1421. // Adds valid children to the schema object
  1422. function addValidChildren(valid_children) {
  1423. var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/;
  1424. if (valid_children) {
  1425. each(split(valid_children), function(rule) {
  1426. var matches = childRuleRegExp.exec(rule), parent, prefix;
  1427. if (matches) {
  1428. prefix = matches[1];
  1429. // Add/remove items from default
  1430. if (prefix)
  1431. parent = children[matches[2]];
  1432. else
  1433. parent = children[matches[2]] = {'#comment' : {}};
  1434. parent = children[matches[2]];
  1435. each(split(matches[3], '|'), function(child) {
  1436. if (prefix === '-')
  1437. delete parent[child];
  1438. else
  1439. parent[child] = {};
  1440. });
  1441. }
  1442. });
  1443. }
  1444. }
  1445. if (!settings.valid_elements) {
  1446. // No valid elements defined then clone the elements from the transitional spec
  1447. each(transitional, function(element, name) {
  1448. elements[name] = {
  1449. attributes : element.attributes,
  1450. attributesOrder : element.attributesOrder
  1451. };
  1452. children[name] = element.children;
  1453. });
  1454. // Switch these
  1455. each(split('strong/b,em/i'), function(item) {
  1456. item = split(item, '/');
  1457. elements[item[1]].outputName = item[0];
  1458. });
  1459. // Add default alt attribute for images
  1460. elements.img.attributesDefault = [{name: 'alt', value: ''}];
  1461. // Remove these if they are empty by default
  1462. each(split('ol,ul,sub,sup,blockquote,span,font,a,table,tbody,tr'), function(name) {
  1463. elements[name].removeEmpty = true;
  1464. });
  1465. // Padd these by default
  1466. each(split('p,h1,h2,h3,h4,h5,h6,th,td,pre,div,address,caption'), function(name) {
  1467. elements[name].paddEmpty = true;
  1468. });
  1469. } else
  1470. setValidElements(settings.valid_elements);
  1471. addCustomElements(settings.custom_elements);
  1472. addValidChildren(settings.valid_children);
  1473. addValidElements(settings.extended_valid_elements);
  1474. // Todo: Remove this when we fix list handling to be valid
  1475. addValidChildren('+ol[ul|ol],+ul[ul|ol]');
  1476. // Delete invalid elements
  1477. if (settings.invalid_elements) {
  1478. tinymce.each(tinymce.explode(settings.invalid_elements), function(item) {
  1479. if (elements[item])
  1480. delete elements[item];
  1481. });
  1482. }
  1483. self.children = children;
  1484. self.styles = validStyles;
  1485. self.getBoolAttrs = function() {
  1486. return boolAttrMap;
  1487. };
  1488. self.getBlockElements = function() {
  1489. return blockElementsMap;
  1490. };
  1491. self.getShortEndedElements = function() {
  1492. return shortEndedElementsMap;
  1493. };
  1494. self.getSelfClosingElements = function() {
  1495. return selfClosingElementsMap;
  1496. };
  1497. self.getNonEmptyElements = function() {
  1498. return nonEmptyElementsMap;
  1499. };
  1500. self.getWhiteSpaceElements = function() {
  1501. return whiteSpaceElementsMap;
  1502. };
  1503. self.isValidChild = function(name, child) {
  1504. var parent = children[name];
  1505. return !!(parent && parent[child]);
  1506. };
  1507. self.getElementRule = function(name) {
  1508. var element = elements[name], i;
  1509. // Exact match found
  1510. if (element)
  1511. return element;
  1512. // No exact match then try the patterns
  1513. i = patternElements.length;
  1514. while (i--) {
  1515. element = patternElements[i];
  1516. if (element.pattern.test(name))
  1517. return element;
  1518. }
  1519. };
  1520. self.getCustomElements = function() {
  1521. return customElementsMap;
  1522. };
  1523. self.addValidElements = addValidElements;
  1524. self.setValidElements = setValidElements;
  1525. self.addCustomElements = addCustomElements;
  1526. self.addValidChildren = addValidChildren;
  1527. };
  1528. // Expose boolMap and blockElementMap as static properties for usage in DOMUtils
  1529. tinymce.html.Schema.boolAttrMap = boolAttrMap;
  1530. tinymce.html.Schema.blockElementsMap = blockElementsMap;
  1531. })(tinymce);
  1532. (function(tinymce) {
  1533. tinymce.html.SaxParser = function(settings, schema) {
  1534. var self = this, noop = function() {};
  1535. settings = settings || {};
  1536. self.schema = schema = schema || new tinymce.html.Schema();
  1537. if (settings.fix_self_closing !== false)
  1538. settings.fix_self_closing = true;
  1539. // Add handler functions from settings and setup default handlers
  1540. tinymce.each('comment cdata text start end pi doctype'.split(' '), function(name) {
  1541. if (name)
  1542. self[name] = settings[name] || noop;
  1543. });
  1544. self.parse = function(html) {
  1545. var self = this, matches, index = 0, value, endRegExp, stack = [], attrList, i, text, name,
  1546. shortEndedElements, fillAttrsMap, isShortEnded, validate, elementRule, isValidElement, attr, attribsValue,
  1547. validAttributesMap, validAttributePatterns, attributesRequired, attributesDefault, attributesForced, selfClosing,
  1548. tokenRegExp, attrRegExp, specialElements, attrValue, idCount = 0, decode = tinymce.html.Entities.decode, fixSelfClosing;
  1549. function processEndTag(name) {
  1550. var pos, i;
  1551. // Find position of parent of the same type
  1552. pos = stack.length;
  1553. while (pos--) {
  1554. if (stack[pos].name === name)
  1555. break;
  1556. }
  1557. // Found parent
  1558. if (pos >= 0) {
  1559. // Close all the open elements
  1560. for (i = stack.length - 1; i >= pos; i--) {
  1561. name = stack[i];
  1562. if (name.valid)
  1563. self.end(name.name);
  1564. }
  1565. // Remove the open elements from the stack
  1566. stack.length = pos;
  1567. }
  1568. };
  1569. // Precompile RegExps and map objects
  1570. tokenRegExp = new RegExp('<(?:' +
  1571. '(?:!--([\\w\\W]*?)-->)|' + // Comment
  1572. '(?:!\\[CDATA\\[([\\w\\W]*?)\\]\\]>)|' + // CDATA
  1573. '(?:!DOCTYPE([\\w\\W]*?)>)|' + // DOCTYPE
  1574. '(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|' + // PI
  1575. '(?:\\/([^>]+)>)|' + // End element
  1576. '(?:([^\\s\\/<>]+)\\s*((?:[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*)>)' + // Start element
  1577. ')', 'g');
  1578. attrRegExp = /([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:\\.|[^\"])*)\")|(?:\'((?:\\.|[^\'])*)\')|([^>\s]+)))?/g;
  1579. specialElements = {
  1580. 'script' : /<\/script[^>]*>/gi,
  1581. 'style' : /<\/style[^>]*>/gi,
  1582. 'noscript' : /<\/noscript[^>]*>/gi
  1583. };
  1584. // Setup lookup tables for empty elements and boolean attributes
  1585. shortEndedElements = schema.getShortEndedElements();
  1586. selfClosing = schema.getSelfClosingElements();
  1587. fillAttrsMap = schema.getBoolAttrs();
  1588. validate = settings.validate;
  1589. fixSelfClosing = settings.fix_self_closing;
  1590. while (matches = tokenRegExp.exec(html)) {
  1591. // Text
  1592. if (index < matches.index)
  1593. self.text(decode(html.substr(index, matches.index - index)));
  1594. if (value = matches[6]) { // End element
  1595. processEndTag(value.toLowerCase());
  1596. } else if (value = matches[7]) { // Start element
  1597. value = value.toLowerCase();
  1598. isShortEnded = value in shortEndedElements;
  1599. // Is self closing tag for example an <li> after an open <li>
  1600. if (fixSelfClosing && selfClosing[value] && stack.length > 0 && stack[stack.length - 1].name === value)
  1601. processEndTag(value);
  1602. // Validate element
  1603. if (!validate || (elementRule = schema.getElementRule(value))) {
  1604. isValidElement = true;
  1605. // Grab attributes map and patters when validation is enabled
  1606. if (validate) {
  1607. validAttributesMap = elementRule.attributes;
  1608. validAttributePatterns = elementRule.attributePatterns;
  1609. }
  1610. // Parse attributes
  1611. if (attribsValue = matches[8]) {
  1612. attrList = [];
  1613. attrList.map = {};
  1614. attribsValue.replace(attrRegExp, function(match, name, value, val2, val3) {
  1615. var attrRule, i;
  1616. name = name.toLowerCase();
  1617. value = name in fillAttrsMap ? name : decode(value || val2 || val3 || ''); // Handle boolean attribute than value attribute
  1618. // Validate name and value
  1619. if (validate && name.indexOf('data-') !== 0) {
  1620. attrRule = validAttributesMap[name];
  1621. // Find rule by pattern matching
  1622. if (!attrRule && validAttributePatterns) {
  1623. i = validAttributePatterns.length;
  1624. while (i--) {
  1625. attrRule = validAttributePatterns[i];
  1626. if (attrRule.pattern.test(name))
  1627. break;
  1628. }
  1629. // No rule matched
  1630. if (i === -1)
  1631. attrRule = null;
  1632. }
  1633. // No attribute rule found
  1634. if (!attrRule)
  1635. return;
  1636. // Validate value
  1637. if (attrRule.validValues && !(value in attrRule.validValues))
  1638. return;
  1639. }
  1640. // Add attribute to list and map
  1641. attrList.map[name] = value;
  1642. attrList.push({
  1643. name: name,
  1644. value: value
  1645. });
  1646. });
  1647. } else {
  1648. attrList = [];
  1649. attrList.map = {};
  1650. }
  1651. // Process attributes if validation is enabled
  1652. if (validate) {
  1653. attributesRequired = elementRule.attributesRequired;
  1654. attributesDefault = elementRule.attributesDefault;
  1655. attributesForced = elementRule.attributesForced;
  1656. // Handle forced attributes
  1657. if (attributesForced) {
  1658. i = attributesForced.length;
  1659. while (i--) {
  1660. attr = attributesForced[i];
  1661. name = attr.name;
  1662. attrValue = attr.value;
  1663. if (attrValue === '{$uid}')
  1664. attrValue = 'mce_' + idCount++;
  1665. attrList.map[name] = attrValue;
  1666. attrList.push({name: name, value: attrValue});
  1667. }
  1668. }
  1669. // Handle default attributes
  1670. if (attributesDefault) {
  1671. i = attributesDefault.length;
  1672. while (i--) {
  1673. attr = attributesDefault[i];
  1674. name = attr.name;
  1675. if (!(name in attrList.map)) {
  1676. attrValue = attr.value;
  1677. if (attrValue === '{$uid}')
  1678. attrValue = 'mce_' + idCount++;
  1679. attrList.map[name] = attrValue;
  1680. attrList.push({name: name, value: attrValue});
  1681. }
  1682. }
  1683. }
  1684. // Handle required attributes
  1685. if (attributesRequired) {
  1686. i = attributesRequired.length;
  1687. while (i--) {
  1688. if (attributesRequired[i] in attrList.map)
  1689. break;
  1690. }
  1691. // None of the required attributes where found
  1692. if (i === -1)
  1693. isValidElement = false;
  1694. }
  1695. // Invalidate element if it's marked as bogus
  1696. if (attrList.map['data-mce-bogus'])
  1697. isValidElement = false;
  1698. }
  1699. if (isValidElement)
  1700. self.start(value, attrList, isShortEnded);
  1701. } else
  1702. isValidElement = false;
  1703. // Treat script, noscript and style a bit different since they may include code that looks like elements
  1704. if (endRegExp = specialElements[value]) {
  1705. endRegExp.lastIndex = index = matches.index + matches[0].length;
  1706. if (matches = endRegExp.exec(html)) {
  1707. if (isValidElement)
  1708. text = html.substr(index, matches.index - index);
  1709. index = matches.index + matches[0].length;
  1710. } else {
  1711. text = html.substr(index);
  1712. index = html.length;
  1713. }
  1714. if (isValidElement && text.length > 0)
  1715. self.text(text, true);
  1716. if (isValidElement)
  1717. self.end(value);
  1718. tokenRegExp.lastIndex = index;
  1719. continue;
  1720. }
  1721. // Push value on to stack
  1722. if (!isShortEnded) {
  1723. if (!attribsValue || attribsValue.indexOf('/') != attribsValue.length - 1)
  1724. stack.push({name: value, valid: isValidElement});
  1725. else if (isValidElement)
  1726. self.end(value);
  1727. }
  1728. } else if (value = matches[1]) { // Comment
  1729. self.comment(value);
  1730. } else if (value = matches[2]) { // CDATA
  1731. self.cdata(value);
  1732. } else if (value = matches[3]) { // DOCTYPE
  1733. self.doctype(value);
  1734. } else if (value = matches[4]) { // PI
  1735. self.pi(value, matches[5]);
  1736. }
  1737. index = matches.index + matches[0].length;
  1738. }
  1739. // Text
  1740. if (index < html.length)
  1741. self.text(decode(html.substr(index)));
  1742. // Close any open elements
  1743. for (i = stack.length - 1; i >= 0; i--) {
  1744. value = stack[i];
  1745. if (value.valid)
  1746. self.end(value.name);
  1747. }
  1748. };
  1749. }
  1750. })(tinymce);
  1751. (function(tinymce) {
  1752. var whiteSpaceRegExp = /^[ \t\r\n]*$/, typeLookup = {
  1753. '#text' : 3,
  1754. '#comment' : 8,
  1755. '#cdata' : 4,
  1756. '#pi' : 7,
  1757. '#doctype' : 10,
  1758. '#document-fragment' : 11
  1759. };
  1760. // Walks the tree left/right
  1761. function walk(node, root_node, prev) {
  1762. var sibling, parent, startName = prev ? 'lastChild' : 'firstChild', siblingName = prev ? 'prev' : 'next';
  1763. // Walk into nodes if it has a start
  1764. if (node[startName])
  1765. return node[startName];
  1766. // Return the sibling if it has one
  1767. if (node !== root_node) {
  1768. sibling = node[siblingName];
  1769. if (sibling)
  1770. return sibling;
  1771. // Walk up the parents to look for siblings
  1772. for (parent = node.parent; parent && parent !== root_node; parent = parent.parent) {
  1773. sibling = parent[siblingName];
  1774. if (sibling)
  1775. return sibling;
  1776. }
  1777. }
  1778. };
  1779. function Node(name, type) {
  1780. this.name = name;
  1781. this.type = type;
  1782. if (type === 1) {
  1783. this.attributes = [];
  1784. this.attributes.map = {};
  1785. }
  1786. }
  1787. tinymce.extend(Node.prototype, {
  1788. replace : function(node) {
  1789. var self = this;
  1790. if (node.parent)
  1791. node.remove();
  1792. self.insert(node, self);
  1793. self.remove();
  1794. return self;
  1795. },
  1796. attr : function(name, value) {
  1797. var self = this, attrs, i, undef;
  1798. if (typeof name !== "string") {
  1799. for (i in name)
  1800. self.attr(i, name[i]);
  1801. return self;
  1802. }
  1803. if (attrs = self.attributes) {
  1804. if (value !== undef) {
  1805. // Remove attribute
  1806. if (value === null) {
  1807. if (name in attrs.map) {
  1808. delete attrs.map[name];
  1809. i = attrs.length;
  1810. while (i--) {
  1811. if (attrs[i].name === name) {
  1812. attrs = attrs.splice(i, 1);
  1813. return self;
  1814. }
  1815. }
  1816. }
  1817. return self;
  1818. }
  1819. // Set attribute
  1820. if (name in attrs.map) {
  1821. // Set attribute
  1822. i = attrs.length;
  1823. while (i--) {
  1824. if (attrs[i].name === name) {
  1825. attrs[i].value = value;
  1826. break;
  1827. }
  1828. }
  1829. } else
  1830. attrs.push({name: name, value: value});
  1831. attrs.map[name] = value;
  1832. return self;
  1833. } else {
  1834. return attrs.map[name];
  1835. }
  1836. }
  1837. },
  1838. clone : function() {
  1839. var self = this, clone = new Node(self.name, self.type), i, l, selfAttrs, selfAttr, cloneAttrs;
  1840. // Clone element attributes
  1841. if (selfAttrs = self.attributes) {
  1842. cloneAttrs = [];
  1843. cloneAttrs.map = {};
  1844. for (i = 0, l = selfAttrs.length; i < l; i++) {
  1845. selfAttr = selfAttrs[i];
  1846. // Clone everything except id
  1847. if (selfAttr.name !== 'id') {
  1848. cloneAttrs[cloneAttrs.length] = {name: selfAttr.name, value: selfAttr.value};
  1849. cloneAttrs.map[selfAttr.name] = selfAttr.value;
  1850. }
  1851. }
  1852. clone.attributes = cloneAttrs;
  1853. }
  1854. clone.value = self.value;
  1855. clone.shortEnded = self.shortEnded;
  1856. return clone;
  1857. },
  1858. wrap : function(wrapper) {
  1859. var self = this;
  1860. self.parent.insert(wrapper, self);
  1861. wrapper.append(self);
  1862. return self;
  1863. },
  1864. unwrap : function() {
  1865. var self = this, node, next;
  1866. for (node = self.firstChild; node; ) {
  1867. next = node.next;
  1868. self.insert(node, self, true);
  1869. node = next;
  1870. }
  1871. self.remove();
  1872. },
  1873. remove : function() {
  1874. var self = this, parent = self.parent, next = self.next, prev = self.prev;
  1875. if (parent) {
  1876. if (parent.firstChild === self) {
  1877. parent.firstChild = next;
  1878. if (next)
  1879. next.prev = null;
  1880. } else {
  1881. prev.next = next;
  1882. }
  1883. if (parent.lastChild === self) {
  1884. parent.lastChild = prev;
  1885. if (prev)
  1886. prev.next = null;
  1887. } else {
  1888. next.prev = prev;
  1889. }
  1890. self.parent = self.next = self.prev = null;
  1891. }
  1892. return self;
  1893. },
  1894. append : function(node) {
  1895. var self = this, last;
  1896. if (node.parent)
  1897. node.remove();
  1898. last = self.lastChild;
  1899. if (last) {
  1900. last.next = node;
  1901. node.prev = last;
  1902. self.lastChild = node;
  1903. } else
  1904. self.lastChild = self.firstChild = node;
  1905. node.parent = self;
  1906. return node;
  1907. },
  1908. insert : function(node, ref_node, before) {
  1909. var parent;
  1910. if (node.parent)
  1911. node.remove();
  1912. parent = ref_node.parent || this;
  1913. if (before) {
  1914. if (ref_node === parent.firstChild)
  1915. parent.firstChild = node;
  1916. else
  1917. ref_node.prev.next = node;
  1918. node.prev = ref_node.prev;
  1919. node.next = ref_node;
  1920. ref_node.prev = node;
  1921. } else {
  1922. if (ref_node === parent.lastChild)
  1923. parent.lastChild = node;
  1924. else
  1925. ref_node.next.prev = node;
  1926. node.next = ref_node.next;
  1927. node.prev = ref_node;
  1928. ref_node.next = node;
  1929. }
  1930. node.parent = parent;
  1931. return node;
  1932. },
  1933. getAll : function(name) {
  1934. var self = this, node, collection = [];
  1935. for (node = self.firstChild; node; node = walk(node, self)) {
  1936. if (node.name === name)
  1937. collection.push(node);
  1938. }
  1939. return collection;
  1940. },
  1941. empty : function() {
  1942. var self = this, nodes, i, node;
  1943. // Remove all children
  1944. if (self.firstChild) {
  1945. nodes = [];
  1946. // Collect the children
  1947. for (node = self.firstChild; node; node = walk(node, self))
  1948. nodes.push(node);
  1949. // Remove the children
  1950. i = nodes.length;
  1951. while (i--) {
  1952. node = nodes[i];
  1953. node.parent = node.firstChild = node.lastChild = node.next = node.prev = null;
  1954. }
  1955. }
  1956. self.firstChild = self.lastChild = null;
  1957. return self;
  1958. },
  1959. isEmpty : function(elements) {
  1960. var self = this, node = self.firstChild, i, name;
  1961. if (node) {
  1962. do {
  1963. if (node.type === 1) {
  1964. // Ignore bogus elements
  1965. if (node.attributes.map['data-mce-bogus'])
  1966. continue;
  1967. // Keep empty elements like <img />
  1968. if (elements[node.name])
  1969. return false;
  1970. // Keep elements with data attributes or name attribute like <a name="1"></a>
  1971. i = node.attributes.length;
  1972. while (i--) {
  1973. name = node.attributes[i].name;
  1974. if (name === "name" || name.indexOf('data-') === 0)
  1975. return false;
  1976. }
  1977. }
  1978. // Keep non whitespace text nodes
  1979. if ((node.type === 3 && !whiteSpaceRegExp.test(node.value)))
  1980. return false;
  1981. } while (node = walk(node, self));
  1982. }
  1983. return true;
  1984. },
  1985. walk : function(prev) {
  1986. return walk(this, null, prev);
  1987. }
  1988. });
  1989. tinymce.extend(Node, {
  1990. create : function(name, attrs) {
  1991. var node, attrName;
  1992. // Create node
  1993. node = new Node(name, typeLookup[name] || 1);
  1994. // Add attributes if needed
  1995. if (attrs) {
  1996. for (attrName in attrs)
  1997. node.attr(attrName, attrs[attrName]);
  1998. }
  1999. return node;
  2000. }
  2001. });
  2002. tinymce.html.Node = Node;
  2003. })(tinymce);
  2004. (function(tinymce) {
  2005. var Node = tinymce.html.Node;
  2006. tinymce.html.DomParser = function(settings, schema) {
  2007. var self = this, nodeFilters = {}, attributeFilters = [], matchedNodes = {}, matchedAttributes = {};
  2008. settings = settings || {};
  2009. settings.validate = "validate" in settings ? settings.validate : true;
  2010. settings.root_name = settings.root_name || 'body';
  2011. self.schema = schema = schema || new tinymce.html.Schema();
  2012. function fixInvalidChildren(nodes) {
  2013. var ni, node, parent, parents, newParent, currentNode, tempNode, childNode, i,
  2014. childClone, nonEmptyElements, nonSplitableElements, sibling, nextNode;
  2015. nonSplitableElements = tinymce.makeMap('tr,td,th,tbody,thead,tfoot,table');
  2016. nonEmptyElements = schema.getNonEmptyElements();
  2017. for (ni = 0; ni < nodes.length; ni++) {
  2018. node = nodes[ni];
  2019. // Already removed
  2020. if (!node.parent)
  2021. continue;
  2022. // Get list of all parent nodes until we find a valid parent to stick the child into
  2023. parents = [node];
  2024. for (parent = node.parent; parent && !schema.isValidChild(parent.name, node.name) && !nonSplitableElements[parent.name]; parent = parent.parent)
  2025. parents.push(parent);
  2026. // Found a suitable parent
  2027. if (parent && parents.length > 1) {
  2028. // Reverse the array since it makes looping easier
  2029. parents.reverse();
  2030. // Clone the related parent and insert that after the moved node
  2031. newParent = currentNode = self.filterNode(parents[0].clone());
  2032. // Start cloning and moving children on the left side of the target node
  2033. for (i = 0; i < parents.length - 1; i++) {
  2034. if (schema.isValidChild(currentNode.name, parents[i].name)) {
  2035. tempNode = self.filterNode(parents[i].clone());
  2036. currentNode.append(tempNode);
  2037. } else
  2038. tempNode = currentNode;
  2039. for (childNode = parents[i].firstChild; childNode && childNode != parents[i + 1]; ) {
  2040. nextNode = childNode.next;
  2041. tempNode.append(childNode);
  2042. childNode = nextNode;
  2043. }
  2044. currentNode = tempNode;
  2045. }
  2046. if (!newParent.isEmpty(nonEmptyElements)) {
  2047. parent.insert(newParent, parents[0], true);
  2048. parent.insert(node, newParent);
  2049. } else {
  2050. parent.insert(node, parents[0], true);
  2051. }
  2052. // Check if the element is empty by looking through it's contents and special treatment for <p><br /></p>
  2053. parent = parents[0];
  2054. if (parent.isEmpty(nonEmptyElements) || parent.firstChild === parent.lastChild && parent.firstChild.name === 'br') {
  2055. parent.empty().remove();
  2056. }
  2057. } else if (node.parent) {
  2058. // If it's an LI try to find a UL/OL for it or wrap it
  2059. if (node.name === 'li') {
  2060. sibling = node.prev;
  2061. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  2062. sibling.append(node);
  2063. continue;
  2064. }
  2065. sibling = node.next;
  2066. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  2067. sibling.insert(node, sibling.firstChild, true);
  2068. continue;
  2069. }
  2070. node.wrap(self.filterNode(new Node('ul', 1)));
  2071. continue;
  2072. }
  2073. // Try wrapping the element in a DIV
  2074. if (schema.isValidChild(node.parent.name, 'div') && schema.isValidChild('div', node.name)) {
  2075. node.wrap(self.filterNode(new Node('div', 1)));
  2076. } else {
  2077. // We failed wrapping it, then remove or unwrap it
  2078. if (node.name === 'style' || node.name === 'script')
  2079. node.empty().remove();
  2080. else
  2081. node.unwrap();
  2082. }
  2083. }
  2084. }
  2085. };
  2086. self.filterNode = function(node) {
  2087. var i, name, list;
  2088. // Run element filters
  2089. if (name in nodeFilters) {
  2090. list = matchedNodes[name];
  2091. if (list)
  2092. list.push(node);
  2093. else
  2094. matchedNodes[name] = [node];
  2095. }
  2096. // Run attribute filters
  2097. i = attributeFilters.length;
  2098. while (i--) {
  2099. name = attributeFilters[i].name;
  2100. if (name in node.attributes.map) {
  2101. list = matchedAttributes[name];
  2102. if (list)
  2103. list.push(node);
  2104. else
  2105. matchedAttributes[name] = [node];
  2106. }
  2107. }
  2108. return node;
  2109. };
  2110. self.addNodeFilter = function(name, callback) {
  2111. tinymce.each(tinymce.explode(name), function(name) {
  2112. var list = nodeFilters[name];
  2113. if (!list)
  2114. nodeFilters[name] = list = [];
  2115. list.push(callback);
  2116. });
  2117. };
  2118. self.addAttributeFilter = function(name, callback) {
  2119. tinymce.each(tinymce.explode(name), function(name) {
  2120. var i;
  2121. for (i = 0; i < attributeFilters.length; i++) {
  2122. if (attributeFilters[i].name === name) {
  2123. attributeFilters[i].callbacks.push(callback);
  2124. return;
  2125. }
  2126. }
  2127. attributeFilters.push({name: name, callbacks: [callback]});
  2128. });
  2129. };
  2130. self.parse = function(html, args) {
  2131. var parser, rootNode, node, nodes, i, l, fi, fl, list, name, validate,
  2132. blockElements, startWhiteSpaceRegExp, invalidChildren = [],
  2133. endWhiteSpaceRegExp, allWhiteSpaceRegExp, whiteSpaceElements, children, nonEmptyElements, rootBlockName;
  2134. args = args || {};
  2135. matchedNodes = {};
  2136. matchedAttributes = {};
  2137. blockElements = tinymce.extend(tinymce.makeMap('script,style,head,html,body,title,meta,param'), schema.getBlockElements());
  2138. nonEmptyElements = schema.getNonEmptyElements();
  2139. children = schema.children;
  2140. validate = settings.validate;
  2141. rootBlockName = "forced_root_block" in args ? args.forced_root_block : settings.forced_root_block;
  2142. whiteSpaceElements = schema.getWhiteSpaceElements();
  2143. startWhiteSpaceRegExp = /^[ \t\r\n]+/;
  2144. endWhiteSpaceRegExp = /[ \t\r\n]+$/;
  2145. allWhiteSpaceRegExp = /[ \t\r\n]+/g;
  2146. function addRootBlocks() {
  2147. var node = rootNode.firstChild, next, rootBlockNode;
  2148. while (node) {
  2149. next = node.next;
  2150. if (node.type == 3 || (node.type == 1 && node.name !== 'p' && !blockElements[node.name] && !node.attr('data-mce-type'))) {
  2151. if (!rootBlockNode) {
  2152. // Create a new root block element
  2153. rootBlockNode = createNode(rootBlockName, 1);
  2154. rootNode.insert(rootBlockNode, node);
  2155. rootBlockNode.append(node);
  2156. } else
  2157. rootBlockNode.append(node);
  2158. } else {
  2159. rootBlockNode = null;
  2160. }
  2161. node = next;
  2162. };
  2163. };
  2164. function createNode(name, type) {
  2165. var node = new Node(name, type), list;
  2166. if (name in nodeFilters) {
  2167. list = matchedNodes[name];
  2168. if (list)
  2169. list.push(node);
  2170. else
  2171. matchedNodes[name] = [node];
  2172. }
  2173. return node;
  2174. };
  2175. function removeWhitespaceBefore(node) {
  2176. var textNode, textVal, sibling;
  2177. for (textNode = node.prev; textNode && textNode.type === 3; ) {
  2178. textVal = textNode.value.replace(endWhiteSpaceRegExp, '');
  2179. if (textVal.length > 0) {
  2180. textNode.value = textVal;
  2181. textNode = textNode.prev;
  2182. } else {
  2183. sibling = textNode.prev;
  2184. textNode.remove();
  2185. textNode = sibling;
  2186. }
  2187. }
  2188. };
  2189. parser = new tinymce.html.SaxParser({
  2190. validate : validate,
  2191. fix_self_closing : !validate, // Let the DOM parser handle <li> in <li> or <p> in <p> for better results
  2192. cdata: function(text) {
  2193. node.append(createNode('#cdata', 4)).value = text;
  2194. },
  2195. text: function(text, raw) {
  2196. var textNode;
  2197. // Trim all redundant whitespace on non white space elements
  2198. if (!whiteSpaceElements[node.name]) {
  2199. text = text.replace(allWhiteSpaceRegExp, ' ');
  2200. if (node.lastChild && blockElements[node.lastChild.name])
  2201. text = text.replace(startWhiteSpaceRegExp, '');
  2202. }
  2203. // Do we need to create the node
  2204. if (text.length !== 0) {
  2205. textNode = createNode('#text', 3);
  2206. textNode.raw = !!raw;
  2207. node.append(textNode).value = text;
  2208. }
  2209. },
  2210. comment: function(text) {
  2211. node.append(createNode('#comment', 8)).value = text;
  2212. },
  2213. pi: function(name, text) {
  2214. node.append(createNode(name, 7)).value = text;
  2215. removeWhitespaceBefore(node);
  2216. },
  2217. doctype: function(text) {
  2218. var newNode;
  2219. newNode = node.append(createNode('#doctype', 10));
  2220. newNode.value = text;
  2221. removeWhitespaceBefore(node);
  2222. },
  2223. start: function(name, attrs, empty) {
  2224. var newNode, attrFiltersLen, elementRule, textNode, attrName, text, sibling, parent;
  2225. elementRule = validate ? schema.getElementRule(name) : {};
  2226. if (elementRule) {
  2227. newNode = createNode(elementRule.outputName || name, 1);
  2228. newNode.attributes = attrs;
  2229. newNode.shortEnded = empty;
  2230. node.append(newNode);
  2231. // Check if node is valid child of the parent node is the child is
  2232. // unknown we don't collect it since it's probably a custom element
  2233. parent = children[node.name];
  2234. if (parent && children[newNode.name] && !parent[newNode.name])
  2235. invalidChildren.push(newNode);
  2236. attrFiltersLen = attributeFilters.length;
  2237. while (attrFiltersLen--) {
  2238. attrName = attributeFilters[attrFiltersLen].name;
  2239. if (attrName in attrs.map) {
  2240. list = matchedAttributes[attrName];
  2241. if (list)
  2242. list.push(newNode);
  2243. else
  2244. matchedAttributes[attrName] = [newNode];
  2245. }
  2246. }
  2247. // Trim whitespace before block
  2248. if (blockElements[name])
  2249. removeWhitespaceBefore(newNode);
  2250. // Change current node if the element wasn't empty i.e not <br /> or <img />
  2251. if (!empty)
  2252. node = newNode;
  2253. }
  2254. },
  2255. end: function(name) {
  2256. var textNode, elementRule, text, sibling, tempNode;
  2257. elementRule = validate ? schema.getElementRule(name) : {};
  2258. if (elementRule) {
  2259. if (blockElements[name]) {
  2260. if (!whiteSpaceElements[node.name]) {
  2261. // Trim whitespace at beginning of block
  2262. for (textNode = node.firstChild; textNode && textNode.type === 3; ) {
  2263. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  2264. if (text.length > 0) {
  2265. textNode.value = text;
  2266. textNode = textNode.next;
  2267. } else {
  2268. sibling = textNode.next;
  2269. textNode.remove();
  2270. textNode = sibling;
  2271. }
  2272. }
  2273. // Trim whitespace at end of block
  2274. for (textNode = node.lastChild; textNode && textNode.type === 3; ) {
  2275. text = textNode.value.replace(endWhiteSpaceRegExp, '');
  2276. if (text.length > 0) {
  2277. textNode.value = text;
  2278. textNode = textNode.prev;
  2279. } else {
  2280. sibling = textNode.prev;
  2281. textNode.remove();
  2282. textNode = sibling;
  2283. }
  2284. }
  2285. }
  2286. // Trim start white space
  2287. textNode = node.prev;
  2288. if (textNode && textNode.type === 3) {
  2289. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  2290. if (text.length > 0)
  2291. textNode.value = text;
  2292. else
  2293. textNode.remove();
  2294. }
  2295. }
  2296. // Handle empty nodes
  2297. if (elementRule.removeEmpty || elementRule.paddEmpty) {
  2298. if (node.isEmpty(nonEmptyElements)) {
  2299. if (elementRule.paddEmpty)
  2300. node.empty().append(new Node('#text', '3')).value = '\u00a0';
  2301. else {
  2302. // Leave nodes that have a name like <a name="name">
  2303. if (!node.attributes.map.name) {
  2304. tempNode = node.parent;
  2305. node.empty().remove();
  2306. node = tempNode;
  2307. return;
  2308. }
  2309. }
  2310. }
  2311. }
  2312. node = node.parent;
  2313. }
  2314. }
  2315. }, schema);
  2316. rootNode = node = new Node(args.context || settings.root_name, 11);
  2317. parser.parse(html);
  2318. // Fix invalid children or report invalid children in a contextual parsing
  2319. if (validate && invalidChildren.length) {
  2320. if (!args.context)
  2321. fixInvalidChildren(invalidChildren);
  2322. else
  2323. args.invalid = true;
  2324. }
  2325. // Wrap nodes in the root into block elements if the root is body
  2326. if (rootBlockName && rootNode.name == 'body')
  2327. addRootBlocks();
  2328. // Run filters only when the contents is valid
  2329. if (!args.invalid) {
  2330. // Run node filters
  2331. for (name in matchedNodes) {
  2332. list = nodeFilters[name];
  2333. nodes = matchedNodes[name];
  2334. // Remove already removed children
  2335. fi = nodes.length;
  2336. while (fi--) {
  2337. if (!nodes[fi].parent)
  2338. nodes.splice(fi, 1);
  2339. }
  2340. for (i = 0, l = list.length; i < l; i++)
  2341. list[i](nodes, name, args);
  2342. }
  2343. // Run attribute filters
  2344. for (i = 0, l = attributeFilters.length; i < l; i++) {
  2345. list = attributeFilters[i];
  2346. if (list.name in matchedAttributes) {
  2347. nodes = matchedAttributes[list.name];
  2348. // Remove already removed children
  2349. fi = nodes.length;
  2350. while (fi--) {
  2351. if (!nodes[fi].parent)
  2352. nodes.splice(fi, 1);
  2353. }
  2354. for (fi = 0, fl = list.callbacks.length; fi < fl; fi++)
  2355. list.callbacks[fi](nodes, list.name, args);
  2356. }
  2357. }
  2358. }
  2359. return rootNode;
  2360. };
  2361. // Remove <br> at end of block elements Gecko and WebKit injects BR elements to
  2362. // make it possible to place the caret inside empty blocks. This logic tries to remove
  2363. // these elements and keep br elements that where intended to be there intact
  2364. if (settings.remove_trailing_brs) {
  2365. self.addNodeFilter('br', function(nodes, name) {
  2366. var i, l = nodes.length, node, blockElements = schema.getBlockElements(),
  2367. nonEmptyElements = schema.getNonEmptyElements(), parent, prev, prevName;
  2368. // Remove brs from body element as well
  2369. blockElements.body = 1;
  2370. // Must loop forwards since it will otherwise remove all brs in <p>a<br><br><br></p>
  2371. for (i = 0; i < l; i++) {
  2372. node = nodes[i];
  2373. parent = node.parent;
  2374. if (blockElements[node.parent.name] && node === parent.lastChild) {
  2375. // Loop all nodes to the right of the current node and check for other BR elements
  2376. // excluding bookmarks since they are invisible
  2377. prev = node.prev;
  2378. while (prev) {
  2379. prevName = prev.name;
  2380. // Ignore bookmarks
  2381. if (prevName !== "span" || prev.attr('data-mce-type') !== 'bookmark') {
  2382. // Found a non BR element
  2383. if (prevName !== "br")
  2384. break;
  2385. // Found another br it's a <br><br> structure then don't remove anything
  2386. if (prevName === 'br') {
  2387. node = null;
  2388. break;
  2389. }
  2390. }
  2391. prev = prev.prev;
  2392. }
  2393. if (node) {
  2394. node.remove();
  2395. // Is the parent to be considered empty after we removed the BR
  2396. if (parent.isEmpty(nonEmptyElements)) {
  2397. elementRule = schema.getElementRule(parent.name);
  2398. // Remove or padd the element depending on schema rule
  2399. if (elementRule.removeEmpty)
  2400. parent.remove();
  2401. else if (elementRule.paddEmpty)
  2402. parent.empty().append(new tinymce.html.Node('#text', 3)).value = '\u00a0';
  2403. }
  2404. }
  2405. }
  2406. }
  2407. });
  2408. }
  2409. }
  2410. })(tinymce);
  2411. tinymce.html.Writer = function(settings) {
  2412. var html = [], indent, indentBefore, indentAfter, encode, htmlOutput;
  2413. settings = settings || {};
  2414. indent = settings.indent;
  2415. indentBefore = tinymce.makeMap(settings.indent_before || '');
  2416. indentAfter = tinymce.makeMap(settings.indent_after || '');
  2417. encode = tinymce.html.Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities);
  2418. htmlOutput = settings.element_format == "html";
  2419. return {
  2420. start: function(name, attrs, empty) {
  2421. var i, l, attr, value;
  2422. if (indent && indentBefore[name] && html.length > 0) {
  2423. value = html[html.length - 1];
  2424. if (value.length > 0 && value !== '\n')
  2425. html.push('\n');
  2426. }
  2427. html.push('<', name);
  2428. if (attrs) {
  2429. for (i = 0, l = attrs.length; i < l; i++) {
  2430. attr = attrs[i];
  2431. html.push(' ', attr.name, '="', encode(attr.value, true), '"');
  2432. }
  2433. }
  2434. if (!empty || htmlOutput)
  2435. html[html.length] = '>';
  2436. else
  2437. html[html.length] = ' />';
  2438. if (empty && indent && indentAfter[name] && html.length > 0) {
  2439. value = html[html.length - 1];
  2440. if (value.length > 0 && value !== '\n')
  2441. html.push('\n');
  2442. }
  2443. },
  2444. end: function(name) {
  2445. var value;
  2446. /*if (indent && indentBefore[name] && html.length > 0) {
  2447. value = html[html.length - 1];
  2448. if (value.length > 0 && value !== '\n')
  2449. html.push('\n');
  2450. }*/
  2451. html.push('</', name, '>');
  2452. if (indent && indentAfter[name] && html.length > 0) {
  2453. value = html[html.length - 1];
  2454. if (value.length > 0 && value !== '\n')
  2455. html.push('\n');
  2456. }
  2457. },
  2458. text: function(text, raw) {
  2459. if (text.length > 0)
  2460. html[html.length] = raw ? text : encode(text);
  2461. },
  2462. cdata: function(text) {
  2463. html.push('<![CDATA[', text, ']]>');
  2464. },
  2465. comment: function(text) {
  2466. html.push('<!--', text, '-->');
  2467. },
  2468. pi: function(name, text) {
  2469. if (text)
  2470. html.push('<?', name, ' ', text, '?>');
  2471. else
  2472. html.push('<?', name, '?>');
  2473. if (indent)
  2474. html.push('\n');
  2475. },
  2476. doctype: function(text) {
  2477. html.push('<!DOCTYPE', text, '>', indent ? '\n' : '');
  2478. },
  2479. reset: function() {
  2480. html.length = 0;
  2481. },
  2482. getContent: function() {
  2483. return html.join('').replace(/\n$/, '');
  2484. }
  2485. };
  2486. };
  2487. (function(tinymce) {
  2488. tinymce.html.Serializer = function(settings, schema) {
  2489. var self = this, writer = new tinymce.html.Writer(settings);
  2490. settings = settings || {};
  2491. settings.validate = "validate" in settings ? settings.validate : true;
  2492. self.schema = schema = schema || new tinymce.html.Schema();
  2493. self.writer = writer;
  2494. self.serialize = function(node) {
  2495. var handlers, validate;
  2496. validate = settings.validate;
  2497. handlers = {
  2498. // #text
  2499. 3: function(node, raw) {
  2500. writer.text(node.value, node.raw);
  2501. },
  2502. // #comment
  2503. 8: function(node) {
  2504. writer.comment(node.value);
  2505. },
  2506. // Processing instruction
  2507. 7: function(node) {
  2508. writer.pi(node.name, node.value);
  2509. },
  2510. // Doctype
  2511. 10: function(node) {
  2512. writer.doctype(node.value);
  2513. },
  2514. // CDATA
  2515. 4: function(node) {
  2516. writer.cdata(node.value);
  2517. },
  2518. // Document fragment
  2519. 11: function(node) {
  2520. if ((node = node.firstChild)) {
  2521. do {
  2522. walk(node);
  2523. } while (node = node.next);
  2524. }
  2525. }
  2526. };
  2527. writer.reset();
  2528. function walk(node) {
  2529. var handler = handlers[node.type], name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule;
  2530. if (!handler) {
  2531. name = node.name;
  2532. isEmpty = node.shortEnded;
  2533. attrs = node.attributes;
  2534. // Sort attributes
  2535. if (validate && attrs && attrs.length > 1) {
  2536. sortedAttrs = [];
  2537. sortedAttrs.map = {};
  2538. elementRule = schema.getElementRule(node.name);
  2539. for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
  2540. attrName = elementRule.attributesOrder[i];
  2541. if (attrName in attrs.map) {
  2542. attrValue = attrs.map[attrName];
  2543. sortedAttrs.map[attrName] = attrValue;
  2544. sortedAttrs.push({name: attrName, value: attrValue});
  2545. }
  2546. }
  2547. for (i = 0, l = attrs.length; i < l; i++) {
  2548. attrName = attrs[i].name;
  2549. if (!(attrName in sortedAttrs.map)) {
  2550. attrValue = attrs.map[attrName];
  2551. sortedAttrs.map[attrName] = attrValue;
  2552. sortedAttrs.push({name: attrName, value: attrValue});
  2553. }
  2554. }
  2555. attrs = sortedAttrs;
  2556. }
  2557. writer.start(node.name, attrs, isEmpty);
  2558. if (!isEmpty) {
  2559. if ((node = node.firstChild)) {
  2560. do {
  2561. walk(node);
  2562. } while (node = node.next);
  2563. }
  2564. writer.end(name);
  2565. }
  2566. } else
  2567. handler(node);
  2568. }
  2569. // Serialize element and treat all non elements as fragments
  2570. if (node.type == 1 && !settings.inner)
  2571. walk(node);
  2572. else
  2573. handlers[11](node);
  2574. return writer.getContent();
  2575. };
  2576. }
  2577. })(tinymce);
  2578. (function(tinymce) {
  2579. // Shorten names
  2580. var each = tinymce.each,
  2581. is = tinymce.is,
  2582. isWebKit = tinymce.isWebKit,
  2583. isIE = tinymce.isIE,
  2584. Entities = tinymce.html.Entities,
  2585. simpleSelectorRe = /^([a-z0-9],?)+$/i,
  2586. blockElementsMap = tinymce.html.Schema.blockElementsMap,
  2587. whiteSpaceRegExp = /^[ \t\r\n]*$/;
  2588. tinymce.create('tinymce.dom.DOMUtils', {
  2589. doc : null,
  2590. root : null,
  2591. files : null,
  2592. pixelStyles : /^(top|left|bottom|right|width|height|borderWidth)$/,
  2593. props : {
  2594. "for" : "htmlFor",
  2595. "class" : "className",
  2596. className : "className",
  2597. checked : "checked",
  2598. disabled : "disabled",
  2599. maxlength : "maxLength",
  2600. readonly : "readOnly",
  2601. selected : "selected",
  2602. value : "value",
  2603. id : "id",
  2604. name : "name",
  2605. type : "type"
  2606. },
  2607. DOMUtils : function(d, s) {
  2608. var t = this, globalStyle, name;
  2609. t.doc = d;
  2610. t.win = window;
  2611. t.files = {};
  2612. t.cssFlicker = false;
  2613. t.counter = 0;
  2614. t.stdMode = !tinymce.isIE || d.documentMode >= 8;
  2615. t.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat" || t.stdMode;
  2616. t.hasOuterHTML = "outerHTML" in d.createElement("a");
  2617. t.settings = s = tinymce.extend({
  2618. keep_values : false,
  2619. hex_colors : 1
  2620. }, s);
  2621. t.schema = s.schema;
  2622. t.styles = new tinymce.html.Styles({
  2623. url_converter : s.url_converter,
  2624. url_converter_scope : s.url_converter_scope
  2625. }, s.schema);
  2626. // Fix IE6SP2 flicker and check it failed for pre SP2
  2627. if (tinymce.isIE6) {
  2628. try {
  2629. d.execCommand('BackgroundImageCache', false, true);
  2630. } catch (e) {
  2631. t.cssFlicker = true;
  2632. }
  2633. }
  2634. if (isIE && s.schema) {
  2635. // Add missing HTML 4/5 elements to IE
  2636. ('abbr article aside audio canvas ' +
  2637. 'details figcaption figure footer ' +
  2638. 'header hgroup mark menu meter nav ' +
  2639. 'output progress section summary ' +
  2640. 'time video').replace(/\w+/g, function(name) {
  2641. d.createElement(name);
  2642. });
  2643. // Create all custom elements
  2644. for (name in s.schema.getCustomElements()) {
  2645. d.createElement(name);
  2646. }
  2647. }
  2648. tinymce.addUnload(t.destroy, t);
  2649. },
  2650. getRoot : function() {
  2651. var t = this, s = t.settings;
  2652. return (s && t.get(s.root_element)) || t.doc.body;
  2653. },
  2654. getViewPort : function(w) {
  2655. var d, b;
  2656. w = !w ? this.win : w;
  2657. d = w.document;
  2658. b = this.boxModel ? d.documentElement : d.body;
  2659. // Returns viewport size excluding scrollbars
  2660. return {
  2661. x : w.pageXOffset || b.scrollLeft,
  2662. y : w.pageYOffset || b.scrollTop,
  2663. w : w.innerWidth || b.clientWidth,
  2664. h : w.innerHeight || b.clientHeight
  2665. };
  2666. },
  2667. getRect : function(e) {
  2668. var p, t = this, sr;
  2669. e = t.get(e);
  2670. p = t.getPos(e);
  2671. sr = t.getSize(e);
  2672. return {
  2673. x : p.x,
  2674. y : p.y,
  2675. w : sr.w,
  2676. h : sr.h
  2677. };
  2678. },
  2679. getSize : function(e) {
  2680. var t = this, w, h;
  2681. e = t.get(e);
  2682. w = t.getStyle(e, 'width');
  2683. h = t.getStyle(e, 'height');
  2684. // Non pixel value, then force offset/clientWidth
  2685. if (w.indexOf('px') === -1)
  2686. w = 0;
  2687. // Non pixel value, then force offset/clientWidth
  2688. if (h.indexOf('px') === -1)
  2689. h = 0;
  2690. return {
  2691. w : parseInt(w) || e.offsetWidth || e.clientWidth,
  2692. h : parseInt(h) || e.offsetHeight || e.clientHeight
  2693. };
  2694. },
  2695. getParent : function(n, f, r) {
  2696. return this.getParents(n, f, r, false);
  2697. },
  2698. getParents : function(n, f, r, c) {
  2699. var t = this, na, se = t.settings, o = [];
  2700. n = t.get(n);
  2701. c = c === undefined;
  2702. if (se.strict_root)
  2703. r = r || t.getRoot();
  2704. // Wrap node name as func
  2705. if (is(f, 'string')) {
  2706. na = f;
  2707. if (f === '*') {
  2708. f = function(n) {return n.nodeType == 1;};
  2709. } else {
  2710. f = function(n) {
  2711. return t.is(n, na);
  2712. };
  2713. }
  2714. }
  2715. while (n) {
  2716. if (n == r || !n.nodeType || n.nodeType === 9)
  2717. break;
  2718. if (!f || f(n)) {
  2719. if (c)
  2720. o.push(n);
  2721. else
  2722. return n;
  2723. }
  2724. n = n.parentNode;
  2725. }
  2726. return c ? o : null;
  2727. },
  2728. get : function(e) {
  2729. var n;
  2730. if (e && this.doc && typeof(e) == 'string') {
  2731. n = e;
  2732. e = this.doc.getElementById(e);
  2733. // IE and Opera returns meta elements when they match the specified input ID, but getElementsByName seems to do the trick
  2734. if (e && e.id !== n)
  2735. return this.doc.getElementsByName(n)[1];
  2736. }
  2737. return e;
  2738. },
  2739. getNext : function(node, selector) {
  2740. return this._findSib(node, selector, 'nextSibling');
  2741. },
  2742. getPrev : function(node, selector) {
  2743. return this._findSib(node, selector, 'previousSibling');
  2744. },
  2745. select : function(pa, s) {
  2746. var t = this;
  2747. return tinymce.dom.Sizzle(pa, t.get(s) || t.get(t.settings.root_element) || t.doc, []);
  2748. },
  2749. is : function(n, selector) {
  2750. var i;
  2751. // If it isn't an array then try to do some simple selectors instead of Sizzle for to boost performance
  2752. if (n.length === undefined) {
  2753. // Simple all selector
  2754. if (selector === '*')
  2755. return n.nodeType == 1;
  2756. // Simple selector just elements
  2757. if (simpleSelectorRe.test(selector)) {
  2758. selector = selector.toLowerCase().split(/,/);
  2759. n = n.nodeName.toLowerCase();
  2760. for (i = selector.length - 1; i >= 0; i--) {
  2761. if (selector[i] == n)
  2762. return true;
  2763. }
  2764. return false;
  2765. }
  2766. }
  2767. return tinymce.dom.Sizzle.matches(selector, n.nodeType ? [n] : n).length > 0;
  2768. },
  2769. add : function(p, n, a, h, c) {
  2770. var t = this;
  2771. return this.run(p, function(p) {
  2772. var e, k;
  2773. e = is(n, 'string') ? t.doc.createElement(n) : n;
  2774. t.setAttribs(e, a);
  2775. if (h) {
  2776. if (h.nodeType)
  2777. e.appendChild(h);
  2778. else
  2779. t.setHTML(e, h);
  2780. }
  2781. return !c ? p.appendChild(e) : e;
  2782. });
  2783. },
  2784. create : function(n, a, h) {
  2785. return this.add(this.doc.createElement(n), n, a, h, 1);
  2786. },
  2787. createHTML : function(n, a, h) {
  2788. var o = '', t = this, k;
  2789. o += '<' + n;
  2790. for (k in a) {
  2791. if (a.hasOwnProperty(k))
  2792. o += ' ' + k + '="' + t.encode(a[k]) + '"';
  2793. }
  2794. // A call to tinymce.is doesn't work for some odd reason on IE9 possible bug inside their JS runtime
  2795. if (typeof(h) != "undefined")
  2796. return o + '>' + h + '</' + n + '>';
  2797. return o + ' />';
  2798. },
  2799. remove : function(node, keep_children) {
  2800. return this.run(node, function(node) {
  2801. var child, parent = node.parentNode;
  2802. if (!parent)
  2803. return null;
  2804. if (keep_children) {
  2805. while (child = node.firstChild) {
  2806. // IE 8 will crash if you don't remove completely empty text nodes
  2807. if (!tinymce.isIE || child.nodeType !== 3 || child.nodeValue)
  2808. parent.insertBefore(child, node);
  2809. else
  2810. node.removeChild(child);
  2811. }
  2812. }
  2813. return parent.removeChild(node);
  2814. });
  2815. },
  2816. setStyle : function(n, na, v) {
  2817. var t = this;
  2818. return t.run(n, function(e) {
  2819. var s, i;
  2820. s = e.style;
  2821. // Camelcase it, if needed
  2822. na = na.replace(/-(\D)/g, function(a, b){
  2823. return b.toUpperCase();
  2824. });
  2825. // Default px suffix on these
  2826. if (t.pixelStyles.test(na) && (tinymce.is(v, 'number') || /^[\-0-9\.]+$/.test(v)))
  2827. v += 'px';
  2828. switch (na) {
  2829. case 'opacity':
  2830. // IE specific opacity
  2831. if (isIE) {
  2832. s.filter = v === '' ? '' : "alpha(opacity=" + (v * 100) + ")";
  2833. if (!n.currentStyle || !n.currentStyle.hasLayout)
  2834. s.display = 'inline-block';
  2835. }
  2836. // Fix for older browsers
  2837. s[na] = s['-moz-opacity'] = s['-khtml-opacity'] = v || '';
  2838. break;
  2839. case 'float':
  2840. isIE ? s.styleFloat = v : s.cssFloat = v;
  2841. break;
  2842. default:
  2843. s[na] = v || '';
  2844. }
  2845. // Force update of the style data
  2846. if (t.settings.update_styles)
  2847. t.setAttrib(e, 'data-mce-style');
  2848. });
  2849. },
  2850. getStyle : function(n, na, c) {
  2851. n = this.get(n);
  2852. if (!n)
  2853. return;
  2854. // Gecko
  2855. if (this.doc.defaultView && c) {
  2856. // Remove camelcase
  2857. na = na.replace(/[A-Z]/g, function(a){
  2858. return '-' + a;
  2859. });
  2860. try {
  2861. return this.doc.defaultView.getComputedStyle(n, null).getPropertyValue(na);
  2862. } catch (ex) {
  2863. // Old safari might fail
  2864. return null;
  2865. }
  2866. }
  2867. // Camelcase it, if needed
  2868. na = na.replace(/-(\D)/g, function(a, b){
  2869. return b.toUpperCase();
  2870. });
  2871. if (na == 'float')
  2872. na = isIE ? 'styleFloat' : 'cssFloat';
  2873. // IE & Opera
  2874. if (n.currentStyle && c)
  2875. return n.currentStyle[na];
  2876. return n.style ? n.style[na] : undefined;
  2877. },
  2878. setStyles : function(e, o) {
  2879. var t = this, s = t.settings, ol;
  2880. ol = s.update_styles;
  2881. s.update_styles = 0;
  2882. each(o, function(v, n) {
  2883. t.setStyle(e, n, v);
  2884. });
  2885. // Update style info
  2886. s.update_styles = ol;
  2887. if (s.update_styles)
  2888. t.setAttrib(e, s.cssText);
  2889. },
  2890. removeAllAttribs: function(e) {
  2891. return this.run(e, function(e) {
  2892. var i, attrs = e.attributes;
  2893. for (i = attrs.length - 1; i >= 0; i--) {
  2894. e.removeAttributeNode(attrs.item(i));
  2895. }
  2896. });
  2897. },
  2898. setAttrib : function(e, n, v) {
  2899. var t = this;
  2900. // Whats the point
  2901. if (!e || !n)
  2902. return;
  2903. // Strict XML mode
  2904. if (t.settings.strict)
  2905. n = n.toLowerCase();
  2906. return this.run(e, function(e) {
  2907. var s = t.settings;
  2908. switch (n) {
  2909. case "style":
  2910. if (!is(v, 'string')) {
  2911. each(v, function(v, n) {
  2912. t.setStyle(e, n, v);
  2913. });
  2914. return;
  2915. }
  2916. // No mce_style for elements with these since they might get resized by the user
  2917. if (s.keep_values) {
  2918. if (v && !t._isRes(v))
  2919. e.setAttribute('data-mce-style', v, 2);
  2920. else
  2921. e.removeAttribute('data-mce-style', 2);
  2922. }
  2923. e.style.cssText = v;
  2924. break;
  2925. case "class":
  2926. e.className = v || ''; // Fix IE null bug
  2927. break;
  2928. case "src":
  2929. case "href":
  2930. if (s.keep_values) {
  2931. if (s.url_converter)
  2932. v = s.url_converter.call(s.url_converter_scope || t, v, n, e);
  2933. t.setAttrib(e, 'data-mce-' + n, v, 2);
  2934. }
  2935. break;
  2936. case "shape":
  2937. e.setAttribute('data-mce-style', v);
  2938. break;
  2939. }
  2940. if (is(v) && v !== null && v.length !== 0)
  2941. e.setAttribute(n, '' + v, 2);
  2942. else
  2943. e.removeAttribute(n, 2);
  2944. });
  2945. },
  2946. setAttribs : function(e, o) {
  2947. var t = this;
  2948. return this.run(e, function(e) {
  2949. each(o, function(v, n) {
  2950. t.setAttrib(e, n, v);
  2951. });
  2952. });
  2953. },
  2954. getAttrib : function(e, n, dv) {
  2955. var v, t = this;
  2956. e = t.get(e);
  2957. if (!e || e.nodeType !== 1)
  2958. return false;
  2959. if (!is(dv))
  2960. dv = '';
  2961. // Try the mce variant for these
  2962. if (/^(src|href|style|coords|shape)$/.test(n)) {
  2963. v = e.getAttribute("data-mce-" + n);
  2964. if (v)
  2965. return v;
  2966. }
  2967. if (isIE && t.props[n]) {
  2968. v = e[t.props[n]];
  2969. v = v && v.nodeValue ? v.nodeValue : v;
  2970. }
  2971. if (!v)
  2972. v = e.getAttribute(n, 2);
  2973. // Check boolean attribs
  2974. if (/^(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)$/.test(n)) {
  2975. if (e[t.props[n]] === true && v === '')
  2976. return n;
  2977. return v ? n : '';
  2978. }
  2979. // Inner input elements will override attributes on form elements
  2980. if (e.nodeName === "FORM" && e.getAttributeNode(n))
  2981. return e.getAttributeNode(n).nodeValue;
  2982. if (n === 'style') {
  2983. v = v || e.style.cssText;
  2984. if (v) {
  2985. v = t.serializeStyle(t.parseStyle(v), e.nodeName);
  2986. if (t.settings.keep_values && !t._isRes(v))
  2987. e.setAttribute('data-mce-style', v);
  2988. }
  2989. }
  2990. // Remove Apple and WebKit stuff
  2991. if (isWebKit && n === "class" && v)
  2992. v = v.replace(/(apple|webkit)\-[a-z\-]+/gi, '');
  2993. // Handle IE issues
  2994. if (isIE) {
  2995. switch (n) {
  2996. case 'rowspan':
  2997. case 'colspan':
  2998. // IE returns 1 as default value
  2999. if (v === 1)
  3000. v = '';
  3001. break;
  3002. case 'size':
  3003. // IE returns +0 as default value for size
  3004. if (v === '+0' || v === 20 || v === 0)
  3005. v = '';
  3006. break;
  3007. case 'width':
  3008. case 'height':
  3009. case 'vspace':
  3010. case 'checked':
  3011. case 'disabled':
  3012. case 'readonly':
  3013. if (v === 0)
  3014. v = '';
  3015. break;
  3016. case 'hspace':
  3017. // IE returns -1 as default value
  3018. if (v === -1)
  3019. v = '';
  3020. break;
  3021. case 'maxlength':
  3022. case 'tabindex':
  3023. // IE returns default value
  3024. if (v === 32768 || v === 2147483647 || v === '32768')
  3025. v = '';
  3026. break;
  3027. case 'multiple':
  3028. case 'compact':
  3029. case 'noshade':
  3030. case 'nowrap':
  3031. if (v === 65535)
  3032. return n;
  3033. return dv;
  3034. case 'shape':
  3035. v = v.toLowerCase();
  3036. break;
  3037. default:
  3038. // IE has odd anonymous function for event attributes
  3039. if (n.indexOf('on') === 0 && v)
  3040. v = tinymce._replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1', '' + v);
  3041. }
  3042. }
  3043. return (v !== undefined && v !== null && v !== '') ? '' + v : dv;
  3044. },
  3045. getPos : function(n, ro) {
  3046. var t = this, x = 0, y = 0, e, d = t.doc, r;
  3047. n = t.get(n);
  3048. ro = ro || d.body;
  3049. if (n) {
  3050. // Use getBoundingClientRect if it exists since it's faster than looping offset nodes
  3051. if (n.getBoundingClientRect) {
  3052. n = n.getBoundingClientRect();
  3053. e = t.boxModel ? d.documentElement : d.body;
  3054. // Add scroll offsets from documentElement or body since IE with the wrong box model will use d.body and so do WebKit
  3055. // Also remove the body/documentelement clientTop/clientLeft on IE 6, 7 since they offset the position
  3056. x = n.left + (d.documentElement.scrollLeft || d.body.scrollLeft) - e.clientTop;
  3057. y = n.top + (d.documentElement.scrollTop || d.body.scrollTop) - e.clientLeft;
  3058. return {x : x, y : y};
  3059. }
  3060. r = n;
  3061. while (r && r != ro && r.nodeType) {
  3062. x += r.offsetLeft || 0;
  3063. y += r.offsetTop || 0;
  3064. r = r.offsetParent;
  3065. }
  3066. r = n.parentNode;
  3067. while (r && r != ro && r.nodeType) {
  3068. x -= r.scrollLeft || 0;
  3069. y -= r.scrollTop || 0;
  3070. r = r.parentNode;
  3071. }
  3072. }
  3073. return {x : x, y : y};
  3074. },
  3075. parseStyle : function(st) {
  3076. return this.styles.parse(st);
  3077. },
  3078. serializeStyle : function(o, name) {
  3079. return this.styles.serialize(o, name);
  3080. },
  3081. loadCSS : function(u) {
  3082. var t = this, d = t.doc, head;
  3083. if (!u)
  3084. u = '';
  3085. head = t.select('head')[0];
  3086. each(u.split(','), function(u) {
  3087. var link;
  3088. if (t.files[u])
  3089. return;
  3090. t.files[u] = true;
  3091. link = t.create('link', {rel : 'stylesheet', href : tinymce._addVer(u)});
  3092. // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug
  3093. // This fix seems to resolve that issue by realcing the document ones a stylesheet finishes loading
  3094. // It's ugly but it seems to work fine.
  3095. if (isIE && d.documentMode && d.recalc) {
  3096. link.onload = function() {
  3097. if (d.recalc)
  3098. d.recalc();
  3099. link.onload = null;
  3100. };
  3101. }
  3102. head.appendChild(link);
  3103. });
  3104. },
  3105. addClass : function(e, c) {
  3106. return this.run(e, function(e) {
  3107. var o;
  3108. if (!c)
  3109. return 0;
  3110. if (this.hasClass(e, c))
  3111. return e.className;
  3112. o = this.removeClass(e, c);
  3113. return e.className = (o != '' ? (o + ' ') : '') + c;
  3114. });
  3115. },
  3116. removeClass : function(e, c) {
  3117. var t = this, re;
  3118. return t.run(e, function(e) {
  3119. var v;
  3120. if (t.hasClass(e, c)) {
  3121. if (!re)
  3122. re = new RegExp("(^|\\s+)" + c + "(\\s+|$)", "g");
  3123. v = e.className.replace(re, ' ');
  3124. v = tinymce.trim(v != ' ' ? v : '');
  3125. e.className = v;
  3126. // Empty class attr
  3127. if (!v) {
  3128. e.removeAttribute('class');
  3129. e.removeAttribute('className');
  3130. }
  3131. return v;
  3132. }
  3133. return e.className;
  3134. });
  3135. },
  3136. hasClass : function(n, c) {
  3137. n = this.get(n);
  3138. if (!n || !c)
  3139. return false;
  3140. return (' ' + n.className + ' ').indexOf(' ' + c + ' ') !== -1;
  3141. },
  3142. show : function(e) {
  3143. return this.setStyle(e, 'display', 'block');
  3144. },
  3145. hide : function(e) {
  3146. return this.setStyle(e, 'display', 'none');
  3147. },
  3148. isHidden : function(e) {
  3149. e = this.get(e);
  3150. return !e || e.style.display == 'none' || this.getStyle(e, 'display') == 'none';
  3151. },
  3152. uniqueId : function(p) {
  3153. return (!p ? 'mce_' : p) + (this.counter++);
  3154. },
  3155. setHTML : function(element, html) {
  3156. var self = this;
  3157. return self.run(element, function(element) {
  3158. if (isIE) {
  3159. // Remove all child nodes, IE keeps empty text nodes in DOM
  3160. while (element.firstChild)
  3161. element.removeChild(element.firstChild);
  3162. try {
  3163. // IE will remove comments from the beginning
  3164. // unless you padd the contents with something
  3165. element.innerHTML = '<br />' + html;
  3166. element.removeChild(element.firstChild);
  3167. } catch (ex) {
  3168. // 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
  3169. // This seems to fix this problem
  3170. // Create new div with HTML contents and a BR infront to keep comments
  3171. element = self.create('div');
  3172. element.innerHTML = '<br />' + html;
  3173. // Add all children from div to target
  3174. each (element.childNodes, function(node, i) {
  3175. // Skip br element
  3176. if (i)
  3177. element.appendChild(node);
  3178. });
  3179. }
  3180. } else
  3181. element.innerHTML = html;
  3182. return html;
  3183. });
  3184. },
  3185. getOuterHTML : function(elm) {
  3186. var doc, self = this;
  3187. elm = self.get(elm);
  3188. if (!elm)
  3189. return null;
  3190. if (elm.nodeType === 1 && self.hasOuterHTML)
  3191. return elm.outerHTML;
  3192. doc = (elm.ownerDocument || self.doc).createElement("body");
  3193. doc.appendChild(elm.cloneNode(true));
  3194. return doc.innerHTML;
  3195. },
  3196. setOuterHTML : function(e, h, d) {
  3197. var t = this;
  3198. function setHTML(e, h, d) {
  3199. var n, tp;
  3200. tp = d.createElement("body");
  3201. tp.innerHTML = h;
  3202. n = tp.lastChild;
  3203. while (n) {
  3204. t.insertAfter(n.cloneNode(true), e);
  3205. n = n.previousSibling;
  3206. }
  3207. t.remove(e);
  3208. };
  3209. return this.run(e, function(e) {
  3210. e = t.get(e);
  3211. // Only set HTML on elements
  3212. if (e.nodeType == 1) {
  3213. d = d || e.ownerDocument || t.doc;
  3214. if (isIE) {
  3215. try {
  3216. // Try outerHTML for IE it sometimes produces an unknown runtime error
  3217. if (isIE && e.nodeType == 1)
  3218. e.outerHTML = h;
  3219. else
  3220. setHTML(e, h, d);
  3221. } catch (ex) {
  3222. // Fix for unknown runtime error
  3223. setHTML(e, h, d);
  3224. }
  3225. } else
  3226. setHTML(e, h, d);
  3227. }
  3228. });
  3229. },
  3230. decode : Entities.decode,
  3231. encode : Entities.encodeAllRaw,
  3232. insertAfter : function(node, reference_node) {
  3233. reference_node = this.get(reference_node);
  3234. return this.run(node, function(node) {
  3235. var parent, nextSibling;
  3236. parent = reference_node.parentNode;
  3237. nextSibling = reference_node.nextSibling;
  3238. if (nextSibling)
  3239. parent.insertBefore(node, nextSibling);
  3240. else
  3241. parent.appendChild(node);
  3242. return node;
  3243. });
  3244. },
  3245. isBlock : function(node) {
  3246. var type = node.nodeType;
  3247. // If it's a node then check the type and use the nodeName
  3248. if (type)
  3249. return !!(type === 1 && blockElementsMap[node.nodeName]);
  3250. return !!blockElementsMap[node];
  3251. },
  3252. replace : function(n, o, k) {
  3253. var t = this;
  3254. if (is(o, 'array'))
  3255. n = n.cloneNode(true);
  3256. return t.run(o, function(o) {
  3257. if (k) {
  3258. each(tinymce.grep(o.childNodes), function(c) {
  3259. n.appendChild(c);
  3260. });
  3261. }
  3262. return o.parentNode.replaceChild(n, o);
  3263. });
  3264. },
  3265. rename : function(elm, name) {
  3266. var t = this, newElm;
  3267. if (elm.nodeName != name.toUpperCase()) {
  3268. // Rename block element
  3269. newElm = t.create(name);
  3270. // Copy attribs to new block
  3271. each(t.getAttribs(elm), function(attr_node) {
  3272. t.setAttrib(newElm, attr_node.nodeName, t.getAttrib(elm, attr_node.nodeName));
  3273. });
  3274. // Replace block
  3275. t.replace(newElm, elm, 1);
  3276. }
  3277. return newElm || elm;
  3278. },
  3279. findCommonAncestor : function(a, b) {
  3280. var ps = a, pe;
  3281. while (ps) {
  3282. pe = b;
  3283. while (pe && ps != pe)
  3284. pe = pe.parentNode;
  3285. if (ps == pe)
  3286. break;
  3287. ps = ps.parentNode;
  3288. }
  3289. if (!ps && a.ownerDocument)
  3290. return a.ownerDocument.documentElement;
  3291. return ps;
  3292. },
  3293. toHex : function(s) {
  3294. var c = /^\s*rgb\s*?\(\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?\)\s*$/i.exec(s);
  3295. function hex(s) {
  3296. s = parseInt(s).toString(16);
  3297. return s.length > 1 ? s : '0' + s; // 0 -> 00
  3298. };
  3299. if (c) {
  3300. s = '#' + hex(c[1]) + hex(c[2]) + hex(c[3]);
  3301. return s;
  3302. }
  3303. return s;
  3304. },
  3305. getClasses : function() {
  3306. var t = this, cl = [], i, lo = {}, f = t.settings.class_filter, ov;
  3307. if (t.classes)
  3308. return t.classes;
  3309. function addClasses(s) {
  3310. // IE style imports
  3311. each(s.imports, function(r) {
  3312. addClasses(r);
  3313. });
  3314. each(s.cssRules || s.rules, function(r) {
  3315. // Real type or fake it on IE
  3316. switch (r.type || 1) {
  3317. // Rule
  3318. case 1:
  3319. if (r.selectorText) {
  3320. each(r.selectorText.split(','), function(v) {
  3321. v = v.replace(/^\s*|\s*$|^\s\./g, "");
  3322. // Is internal or it doesn't contain a class
  3323. if (/\.mce/.test(v) || !/\.[\w\-]+$/.test(v))
  3324. return;
  3325. // Remove everything but class name
  3326. ov = v;
  3327. v = tinymce._replace(/.*\.([a-z0-9_\-]+).*/i, '$1', v);
  3328. // Filter classes
  3329. if (f && !(v = f(v, ov)))
  3330. return;
  3331. if (!lo[v]) {
  3332. cl.push({'class' : v});
  3333. lo[v] = 1;
  3334. }
  3335. });
  3336. }
  3337. break;
  3338. // Import
  3339. case 3:
  3340. addClasses(r.styleSheet);
  3341. break;
  3342. }
  3343. });
  3344. };
  3345. try {
  3346. each(t.doc.styleSheets, addClasses);
  3347. } catch (ex) {
  3348. // Ignore
  3349. }
  3350. if (cl.length > 0)
  3351. t.classes = cl;
  3352. return cl;
  3353. },
  3354. run : function(e, f, s) {
  3355. var t = this, o;
  3356. if (t.doc && typeof(e) === 'string')
  3357. e = t.get(e);
  3358. if (!e)
  3359. return false;
  3360. s = s || this;
  3361. if (!e.nodeType && (e.length || e.length === 0)) {
  3362. o = [];
  3363. each(e, function(e, i) {
  3364. if (e) {
  3365. if (typeof(e) == 'string')
  3366. e = t.doc.getElementById(e);
  3367. o.push(f.call(s, e, i));
  3368. }
  3369. });
  3370. return o;
  3371. }
  3372. return f.call(s, e);
  3373. },
  3374. getAttribs : function(n) {
  3375. var o;
  3376. n = this.get(n);
  3377. if (!n)
  3378. return [];
  3379. if (isIE) {
  3380. o = [];
  3381. // Object will throw exception in IE
  3382. if (n.nodeName == 'OBJECT')
  3383. return n.attributes;
  3384. // IE doesn't keep the selected attribute if you clone option elements
  3385. if (n.nodeName === 'OPTION' && this.getAttrib(n, 'selected'))
  3386. o.push({specified : 1, nodeName : 'selected'});
  3387. // It's crazy that this is faster in IE but it's because it returns all attributes all the time
  3388. n.cloneNode(false).outerHTML.replace(/<\/?[\w:\-]+ ?|=[\"][^\"]+\"|=\'[^\']+\'|=[\w\-]+|>/gi, '').replace(/[\w:\-]+/gi, function(a) {
  3389. o.push({specified : 1, nodeName : a});
  3390. });
  3391. return o;
  3392. }
  3393. return n.attributes;
  3394. },
  3395. isEmpty : function(node, elements) {
  3396. var self = this, i, attributes, type, walker, name;
  3397. node = node.firstChild;
  3398. if (node) {
  3399. walker = new tinymce.dom.TreeWalker(node);
  3400. elements = elements || self.schema ? self.schema.getNonEmptyElements() : null;
  3401. do {
  3402. type = node.nodeType;
  3403. if (type === 1) {
  3404. // Ignore bogus elements
  3405. if (node.getAttribute('data-mce-bogus'))
  3406. continue;
  3407. // Keep empty elements like <img />
  3408. if (elements && elements[node.nodeName.toLowerCase()])
  3409. return false;
  3410. // Keep elements with data attributes or name attribute like <a name="1"></a>
  3411. attributes = self.getAttribs(node);
  3412. i = node.attributes.length;
  3413. while (i--) {
  3414. name = node.attributes[i].nodeName;
  3415. if (name === "name" || name.indexOf('data-') === 0)
  3416. return false;
  3417. }
  3418. }
  3419. // Keep non whitespace text nodes
  3420. if ((type === 3 && !whiteSpaceRegExp.test(node.nodeValue)))
  3421. return false;
  3422. } while (node = walker.next());
  3423. }
  3424. return true;
  3425. },
  3426. destroy : function(s) {
  3427. var t = this;
  3428. if (t.events)
  3429. t.events.destroy();
  3430. t.win = t.doc = t.root = t.events = null;
  3431. // Manual destroy then remove unload handler
  3432. if (!s)
  3433. tinymce.removeUnload(t.destroy);
  3434. },
  3435. createRng : function() {
  3436. var d = this.doc;
  3437. return d.createRange ? d.createRange() : new tinymce.dom.Range(this);
  3438. },
  3439. nodeIndex : function(node, normalized) {
  3440. var idx = 0, lastNodeType, lastNode, nodeType;
  3441. if (node) {
  3442. for (lastNodeType = node.nodeType, node = node.previousSibling, lastNode = node; node; node = node.previousSibling) {
  3443. nodeType = node.nodeType;
  3444. // Normalize text nodes
  3445. if (normalized && nodeType == 3) {
  3446. if (nodeType == lastNodeType || !node.nodeValue.length)
  3447. continue;
  3448. }
  3449. idx++;
  3450. lastNodeType = nodeType;
  3451. }
  3452. }
  3453. return idx;
  3454. },
  3455. split : function(pe, e, re) {
  3456. var t = this, r = t.createRng(), bef, aft, pa;
  3457. // W3C valid browsers tend to leave empty nodes to the left/right side of the contents, this makes sense
  3458. // but we don't want that in our code since it serves no purpose for the end user
  3459. // For example if this is chopped:
  3460. // <p>text 1<span><b>CHOP</b></span>text 2</p>
  3461. // would produce:
  3462. // <p>text 1<span></span></p><b>CHOP</b><p><span></span>text 2</p>
  3463. // this function will then trim of empty edges and produce:
  3464. // <p>text 1</p><b>CHOP</b><p>text 2</p>
  3465. function trim(node) {
  3466. var i, children = node.childNodes, type = node.nodeType;
  3467. if (type == 1 && node.getAttribute('data-mce-type') == 'bookmark')
  3468. return;
  3469. for (i = children.length - 1; i >= 0; i--)
  3470. trim(children[i]);
  3471. if (type != 9) {
  3472. // Keep non whitespace text nodes
  3473. if (type == 3 && node.nodeValue.length > 0) {
  3474. // If parent element isn't a block or there isn't any useful contents for example "<p> </p>"
  3475. if (!t.isBlock(node.parentNode) || tinymce.trim(node.nodeValue).length > 0)
  3476. return;
  3477. } else if (type == 1) {
  3478. // If the only child is a bookmark then move it up
  3479. children = node.childNodes;
  3480. if (children.length == 1 && children[0] && children[0].nodeType == 1 && children[0].getAttribute('data-mce-type') == 'bookmark')
  3481. node.parentNode.insertBefore(children[0], node);
  3482. // Keep non empty elements or img, hr etc
  3483. if (children.length || /^(br|hr|input|img)$/i.test(node.nodeName))
  3484. return;
  3485. }
  3486. t.remove(node);
  3487. }
  3488. return node;
  3489. };
  3490. if (pe && e) {
  3491. // Get before chunk
  3492. r.setStart(pe.parentNode, t.nodeIndex(pe));
  3493. r.setEnd(e.parentNode, t.nodeIndex(e));
  3494. bef = r.extractContents();
  3495. // Get after chunk
  3496. r = t.createRng();
  3497. r.setStart(e.parentNode, t.nodeIndex(e) + 1);
  3498. r.setEnd(pe.parentNode, t.nodeIndex(pe) + 1);
  3499. aft = r.extractContents();
  3500. // Insert before chunk
  3501. pa = pe.parentNode;
  3502. pa.insertBefore(trim(bef), pe);
  3503. // Insert middle chunk
  3504. if (re)
  3505. pa.replaceChild(re, e);
  3506. else
  3507. pa.insertBefore(e, pe);
  3508. // Insert after chunk
  3509. pa.insertBefore(trim(aft), pe);
  3510. t.remove(pe);
  3511. return re || e;
  3512. }
  3513. },
  3514. bind : function(target, name, func, scope) {
  3515. var t = this;
  3516. if (!t.events)
  3517. t.events = new tinymce.dom.EventUtils();
  3518. return t.events.add(target, name, func, scope || this);
  3519. },
  3520. unbind : function(target, name, func) {
  3521. var t = this;
  3522. if (!t.events)
  3523. t.events = new tinymce.dom.EventUtils();
  3524. return t.events.remove(target, name, func);
  3525. },
  3526. _findSib : function(node, selector, name) {
  3527. var t = this, f = selector;
  3528. if (node) {
  3529. // If expression make a function of it using is
  3530. if (is(f, 'string')) {
  3531. f = function(node) {
  3532. return t.is(node, selector);
  3533. };
  3534. }
  3535. // Loop all siblings
  3536. for (node = node[name]; node; node = node[name]) {
  3537. if (f(node))
  3538. return node;
  3539. }
  3540. }
  3541. return null;
  3542. },
  3543. _isRes : function(c) {
  3544. // Is live resizble element
  3545. return /^(top|left|bottom|right|width|height)/i.test(c) || /;\s*(top|left|bottom|right|width|height)/i.test(c);
  3546. }
  3547. /*
  3548. walk : function(n, f, s) {
  3549. var d = this.doc, w;
  3550. if (d.createTreeWalker) {
  3551. w = d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false);
  3552. while ((n = w.nextNode()) != null)
  3553. f.call(s || this, n);
  3554. } else
  3555. tinymce.walk(n, f, 'childNodes', s);
  3556. }
  3557. */
  3558. /*
  3559. toRGB : function(s) {
  3560. var c = /^\s*?#([0-9A-F]{2})([0-9A-F]{1,2})([0-9A-F]{2})?\s*?$/.exec(s);
  3561. if (c) {
  3562. // #FFF -> #FFFFFF
  3563. if (!is(c[3]))
  3564. c[3] = c[2] = c[1];
  3565. return "rgb(" + parseInt(c[1], 16) + "," + parseInt(c[2], 16) + "," + parseInt(c[3], 16) + ")";
  3566. }
  3567. return s;
  3568. }
  3569. */
  3570. });
  3571. tinymce.DOM = new tinymce.dom.DOMUtils(document, {process_html : 0});
  3572. })(tinymce);
  3573. (function(ns) {
  3574. // Range constructor
  3575. function Range(dom) {
  3576. var t = this,
  3577. doc = dom.doc,
  3578. EXTRACT = 0,
  3579. CLONE = 1,
  3580. DELETE = 2,
  3581. TRUE = true,
  3582. FALSE = false,
  3583. START_OFFSET = 'startOffset',
  3584. START_CONTAINER = 'startContainer',
  3585. END_CONTAINER = 'endContainer',
  3586. END_OFFSET = 'endOffset',
  3587. extend = tinymce.extend,
  3588. nodeIndex = dom.nodeIndex;
  3589. extend(t, {
  3590. // Inital states
  3591. startContainer : doc,
  3592. startOffset : 0,
  3593. endContainer : doc,
  3594. endOffset : 0,
  3595. collapsed : TRUE,
  3596. commonAncestorContainer : doc,
  3597. // Range constants
  3598. START_TO_START : 0,
  3599. START_TO_END : 1,
  3600. END_TO_END : 2,
  3601. END_TO_START : 3,
  3602. // Public methods
  3603. setStart : setStart,
  3604. setEnd : setEnd,
  3605. setStartBefore : setStartBefore,
  3606. setStartAfter : setStartAfter,
  3607. setEndBefore : setEndBefore,
  3608. setEndAfter : setEndAfter,
  3609. collapse : collapse,
  3610. selectNode : selectNode,
  3611. selectNodeContents : selectNodeContents,
  3612. compareBoundaryPoints : compareBoundaryPoints,
  3613. deleteContents : deleteContents,
  3614. extractContents : extractContents,
  3615. cloneContents : cloneContents,
  3616. insertNode : insertNode,
  3617. surroundContents : surroundContents,
  3618. cloneRange : cloneRange
  3619. });
  3620. function setStart(n, o) {
  3621. _setEndPoint(TRUE, n, o);
  3622. };
  3623. function setEnd(n, o) {
  3624. _setEndPoint(FALSE, n, o);
  3625. };
  3626. function setStartBefore(n) {
  3627. setStart(n.parentNode, nodeIndex(n));
  3628. };
  3629. function setStartAfter(n) {
  3630. setStart(n.parentNode, nodeIndex(n) + 1);
  3631. };
  3632. function setEndBefore(n) {
  3633. setEnd(n.parentNode, nodeIndex(n));
  3634. };
  3635. function setEndAfter(n) {
  3636. setEnd(n.parentNode, nodeIndex(n) + 1);
  3637. };
  3638. function collapse(ts) {
  3639. if (ts) {
  3640. t[END_CONTAINER] = t[START_CONTAINER];
  3641. t[END_OFFSET] = t[START_OFFSET];
  3642. } else {
  3643. t[START_CONTAINER] = t[END_CONTAINER];
  3644. t[START_OFFSET] = t[END_OFFSET];
  3645. }
  3646. t.collapsed = TRUE;
  3647. };
  3648. function selectNode(n) {
  3649. setStartBefore(n);
  3650. setEndAfter(n);
  3651. };
  3652. function selectNodeContents(n) {
  3653. setStart(n, 0);
  3654. setEnd(n, n.nodeType === 1 ? n.childNodes.length : n.nodeValue.length);
  3655. };
  3656. function compareBoundaryPoints(h, r) {
  3657. var sc = t[START_CONTAINER], so = t[START_OFFSET], ec = t[END_CONTAINER], eo = t[END_OFFSET],
  3658. rsc = r.startContainer, rso = r.startOffset, rec = r.endContainer, reo = r.endOffset;
  3659. // Check START_TO_START
  3660. if (h === 0)
  3661. return _compareBoundaryPoints(sc, so, rsc, rso);
  3662. // Check START_TO_END
  3663. if (h === 1)
  3664. return _compareBoundaryPoints(ec, eo, rsc, rso);
  3665. // Check END_TO_END
  3666. if (h === 2)
  3667. return _compareBoundaryPoints(ec, eo, rec, reo);
  3668. // Check END_TO_START
  3669. if (h === 3)
  3670. return _compareBoundaryPoints(sc, so, rec, reo);
  3671. };
  3672. function deleteContents() {
  3673. _traverse(DELETE);
  3674. };
  3675. function extractContents() {
  3676. return _traverse(EXTRACT);
  3677. };
  3678. function cloneContents() {
  3679. return _traverse(CLONE);
  3680. };
  3681. function insertNode(n) {
  3682. var startContainer = this[START_CONTAINER],
  3683. startOffset = this[START_OFFSET], nn, o;
  3684. // Node is TEXT_NODE or CDATA
  3685. if ((startContainer.nodeType === 3 || startContainer.nodeType === 4) && startContainer.nodeValue) {
  3686. if (!startOffset) {
  3687. // At the start of text
  3688. startContainer.parentNode.insertBefore(n, startContainer);
  3689. } else if (startOffset >= startContainer.nodeValue.length) {
  3690. // At the end of text
  3691. dom.insertAfter(n, startContainer);
  3692. } else {
  3693. // Middle, need to split
  3694. nn = startContainer.splitText(startOffset);
  3695. startContainer.parentNode.insertBefore(n, nn);
  3696. }
  3697. } else {
  3698. // Insert element node
  3699. if (startContainer.childNodes.length > 0)
  3700. o = startContainer.childNodes[startOffset];
  3701. if (o)
  3702. startContainer.insertBefore(n, o);
  3703. else
  3704. startContainer.appendChild(n);
  3705. }
  3706. };
  3707. function surroundContents(n) {
  3708. var f = t.extractContents();
  3709. t.insertNode(n);
  3710. n.appendChild(f);
  3711. t.selectNode(n);
  3712. };
  3713. function cloneRange() {
  3714. return extend(new Range(dom), {
  3715. startContainer : t[START_CONTAINER],
  3716. startOffset : t[START_OFFSET],
  3717. endContainer : t[END_CONTAINER],
  3718. endOffset : t[END_OFFSET],
  3719. collapsed : t.collapsed,
  3720. commonAncestorContainer : t.commonAncestorContainer
  3721. });
  3722. };
  3723. // Private methods
  3724. function _getSelectedNode(container, offset) {
  3725. var child;
  3726. if (container.nodeType == 3 /* TEXT_NODE */)
  3727. return container;
  3728. if (offset < 0)
  3729. return container;
  3730. child = container.firstChild;
  3731. while (child && offset > 0) {
  3732. --offset;
  3733. child = child.nextSibling;
  3734. }
  3735. if (child)
  3736. return child;
  3737. return container;
  3738. };
  3739. function _isCollapsed() {
  3740. return (t[START_CONTAINER] == t[END_CONTAINER] && t[START_OFFSET] == t[END_OFFSET]);
  3741. };
  3742. function _compareBoundaryPoints(containerA, offsetA, containerB, offsetB) {
  3743. var c, offsetC, n, cmnRoot, childA, childB;
  3744. // In the first case the boundary-points have the same container. A is before B
  3745. // if its offset is less than the offset of B, A is equal to B if its offset is
  3746. // equal to the offset of B, and A is after B if its offset is greater than the
  3747. // offset of B.
  3748. if (containerA == containerB) {
  3749. if (offsetA == offsetB)
  3750. return 0; // equal
  3751. if (offsetA < offsetB)
  3752. return -1; // before
  3753. return 1; // after
  3754. }
  3755. // In the second case a child node C of the container of A is an ancestor
  3756. // container of B. In this case, A is before B if the offset of A is less than or
  3757. // equal to the index of the child node C and A is after B otherwise.
  3758. c = containerB;
  3759. while (c && c.parentNode != containerA)
  3760. c = c.parentNode;
  3761. if (c) {
  3762. offsetC = 0;
  3763. n = containerA.firstChild;
  3764. while (n != c && offsetC < offsetA) {
  3765. offsetC++;
  3766. n = n.nextSibling;
  3767. }
  3768. if (offsetA <= offsetC)
  3769. return -1; // before
  3770. return 1; // after
  3771. }
  3772. // In the third case a child node C of the container of B is an ancestor container
  3773. // of A. In this case, A is before B if the index of the child node C is less than
  3774. // the offset of B and A is after B otherwise.
  3775. c = containerA;
  3776. while (c && c.parentNode != containerB) {
  3777. c = c.parentNode;
  3778. }
  3779. if (c) {
  3780. offsetC = 0;
  3781. n = containerB.firstChild;
  3782. while (n != c && offsetC < offsetB) {
  3783. offsetC++;
  3784. n = n.nextSibling;
  3785. }
  3786. if (offsetC < offsetB)
  3787. return -1; // before
  3788. return 1; // after
  3789. }
  3790. // In the fourth case, none of three other cases hold: the containers of A and B
  3791. // are siblings or descendants of sibling nodes. In this case, A is before B if
  3792. // the container of A is before the container of B in a pre-order traversal of the
  3793. // Ranges' context tree and A is after B otherwise.
  3794. cmnRoot = dom.findCommonAncestor(containerA, containerB);
  3795. childA = containerA;
  3796. while (childA && childA.parentNode != cmnRoot)
  3797. childA = childA.parentNode;
  3798. if (!childA)
  3799. childA = cmnRoot;
  3800. childB = containerB;
  3801. while (childB && childB.parentNode != cmnRoot)
  3802. childB = childB.parentNode;
  3803. if (!childB)
  3804. childB = cmnRoot;
  3805. if (childA == childB)
  3806. return 0; // equal
  3807. n = cmnRoot.firstChild;
  3808. while (n) {
  3809. if (n == childA)
  3810. return -1; // before
  3811. if (n == childB)
  3812. return 1; // after
  3813. n = n.nextSibling;
  3814. }
  3815. };
  3816. function _setEndPoint(st, n, o) {
  3817. var ec, sc;
  3818. if (st) {
  3819. t[START_CONTAINER] = n;
  3820. t[START_OFFSET] = o;
  3821. } else {
  3822. t[END_CONTAINER] = n;
  3823. t[END_OFFSET] = o;
  3824. }
  3825. // If one boundary-point of a Range is set to have a root container
  3826. // other than the current one for the Range, the Range is collapsed to
  3827. // the new position. This enforces the restriction that both boundary-
  3828. // points of a Range must have the same root container.
  3829. ec = t[END_CONTAINER];
  3830. while (ec.parentNode)
  3831. ec = ec.parentNode;
  3832. sc = t[START_CONTAINER];
  3833. while (sc.parentNode)
  3834. sc = sc.parentNode;
  3835. if (sc == ec) {
  3836. // The start position of a Range is guaranteed to never be after the
  3837. // end position. To enforce this restriction, if the start is set to
  3838. // be at a position after the end, the Range is collapsed to that
  3839. // position.
  3840. if (_compareBoundaryPoints(t[START_CONTAINER], t[START_OFFSET], t[END_CONTAINER], t[END_OFFSET]) > 0)
  3841. t.collapse(st);
  3842. } else
  3843. t.collapse(st);
  3844. t.collapsed = _isCollapsed();
  3845. t.commonAncestorContainer = dom.findCommonAncestor(t[START_CONTAINER], t[END_CONTAINER]);
  3846. };
  3847. function _traverse(how) {
  3848. var c, endContainerDepth = 0, startContainerDepth = 0, p, depthDiff, startNode, endNode, sp, ep;
  3849. if (t[START_CONTAINER] == t[END_CONTAINER])
  3850. return _traverseSameContainer(how);
  3851. for (c = t[END_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  3852. if (p == t[START_CONTAINER])
  3853. return _traverseCommonStartContainer(c, how);
  3854. ++endContainerDepth;
  3855. }
  3856. for (c = t[START_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  3857. if (p == t[END_CONTAINER])
  3858. return _traverseCommonEndContainer(c, how);
  3859. ++startContainerDepth;
  3860. }
  3861. depthDiff = startContainerDepth - endContainerDepth;
  3862. startNode = t[START_CONTAINER];
  3863. while (depthDiff > 0) {
  3864. startNode = startNode.parentNode;
  3865. depthDiff--;
  3866. }
  3867. endNode = t[END_CONTAINER];
  3868. while (depthDiff < 0) {
  3869. endNode = endNode.parentNode;
  3870. depthDiff++;
  3871. }
  3872. // ascend the ancestor hierarchy until we have a common parent.
  3873. for (sp = startNode.parentNode, ep = endNode.parentNode; sp != ep; sp = sp.parentNode, ep = ep.parentNode) {
  3874. startNode = sp;
  3875. endNode = ep;
  3876. }
  3877. return _traverseCommonAncestors(startNode, endNode, how);
  3878. };
  3879. function _traverseSameContainer(how) {
  3880. var frag, s, sub, n, cnt, sibling, xferNode;
  3881. if (how != DELETE)
  3882. frag = doc.createDocumentFragment();
  3883. // If selection is empty, just return the fragment
  3884. if (t[START_OFFSET] == t[END_OFFSET])
  3885. return frag;
  3886. // Text node needs special case handling
  3887. if (t[START_CONTAINER].nodeType == 3 /* TEXT_NODE */) {
  3888. // get the substring
  3889. s = t[START_CONTAINER].nodeValue;
  3890. sub = s.substring(t[START_OFFSET], t[END_OFFSET]);
  3891. // set the original text node to its new value
  3892. if (how != CLONE) {
  3893. t[START_CONTAINER].deleteData(t[START_OFFSET], t[END_OFFSET] - t[START_OFFSET]);
  3894. // Nothing is partially selected, so collapse to start point
  3895. t.collapse(TRUE);
  3896. }
  3897. if (how == DELETE)
  3898. return;
  3899. frag.appendChild(doc.createTextNode(sub));
  3900. return frag;
  3901. }
  3902. // Copy nodes between the start/end offsets.
  3903. n = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]);
  3904. cnt = t[END_OFFSET] - t[START_OFFSET];
  3905. while (cnt > 0) {
  3906. sibling = n.nextSibling;
  3907. xferNode = _traverseFullySelected(n, how);
  3908. if (frag)
  3909. frag.appendChild( xferNode );
  3910. --cnt;
  3911. n = sibling;
  3912. }
  3913. // Nothing is partially selected, so collapse to start point
  3914. if (how != CLONE)
  3915. t.collapse(TRUE);
  3916. return frag;
  3917. };
  3918. function _traverseCommonStartContainer(endAncestor, how) {
  3919. var frag, n, endIdx, cnt, sibling, xferNode;
  3920. if (how != DELETE)
  3921. frag = doc.createDocumentFragment();
  3922. n = _traverseRightBoundary(endAncestor, how);
  3923. if (frag)
  3924. frag.appendChild(n);
  3925. endIdx = nodeIndex(endAncestor);
  3926. cnt = endIdx - t[START_OFFSET];
  3927. if (cnt <= 0) {
  3928. // Collapse to just before the endAncestor, which
  3929. // is partially selected.
  3930. if (how != CLONE) {
  3931. t.setEndBefore(endAncestor);
  3932. t.collapse(FALSE);
  3933. }
  3934. return frag;
  3935. }
  3936. n = endAncestor.previousSibling;
  3937. while (cnt > 0) {
  3938. sibling = n.previousSibling;
  3939. xferNode = _traverseFullySelected(n, how);
  3940. if (frag)
  3941. frag.insertBefore(xferNode, frag.firstChild);
  3942. --cnt;
  3943. n = sibling;
  3944. }
  3945. // Collapse to just before the endAncestor, which
  3946. // is partially selected.
  3947. if (how != CLONE) {
  3948. t.setEndBefore(endAncestor);
  3949. t.collapse(FALSE);
  3950. }
  3951. return frag;
  3952. };
  3953. function _traverseCommonEndContainer(startAncestor, how) {
  3954. var frag, startIdx, n, cnt, sibling, xferNode;
  3955. if (how != DELETE)
  3956. frag = doc.createDocumentFragment();
  3957. n = _traverseLeftBoundary(startAncestor, how);
  3958. if (frag)
  3959. frag.appendChild(n);
  3960. startIdx = nodeIndex(startAncestor);
  3961. ++startIdx; // Because we already traversed it
  3962. cnt = t[END_OFFSET] - startIdx;
  3963. n = startAncestor.nextSibling;
  3964. while (cnt > 0) {
  3965. sibling = n.nextSibling;
  3966. xferNode = _traverseFullySelected(n, how);
  3967. if (frag)
  3968. frag.appendChild(xferNode);
  3969. --cnt;
  3970. n = sibling;
  3971. }
  3972. if (how != CLONE) {
  3973. t.setStartAfter(startAncestor);
  3974. t.collapse(TRUE);
  3975. }
  3976. return frag;
  3977. };
  3978. function _traverseCommonAncestors(startAncestor, endAncestor, how) {
  3979. var n, frag, commonParent, startOffset, endOffset, cnt, sibling, nextSibling;
  3980. if (how != DELETE)
  3981. frag = doc.createDocumentFragment();
  3982. n = _traverseLeftBoundary(startAncestor, how);
  3983. if (frag)
  3984. frag.appendChild(n);
  3985. commonParent = startAncestor.parentNode;
  3986. startOffset = nodeIndex(startAncestor);
  3987. endOffset = nodeIndex(endAncestor);
  3988. ++startOffset;
  3989. cnt = endOffset - startOffset;
  3990. sibling = startAncestor.nextSibling;
  3991. while (cnt > 0) {
  3992. nextSibling = sibling.nextSibling;
  3993. n = _traverseFullySelected(sibling, how);
  3994. if (frag)
  3995. frag.appendChild(n);
  3996. sibling = nextSibling;
  3997. --cnt;
  3998. }
  3999. n = _traverseRightBoundary(endAncestor, how);
  4000. if (frag)
  4001. frag.appendChild(n);
  4002. if (how != CLONE) {
  4003. t.setStartAfter(startAncestor);
  4004. t.collapse(TRUE);
  4005. }
  4006. return frag;
  4007. };
  4008. function _traverseRightBoundary(root, how) {
  4009. var next = _getSelectedNode(t[END_CONTAINER], t[END_OFFSET] - 1), parent, clonedParent, prevSibling, clonedChild, clonedGrandParent, isFullySelected = next != t[END_CONTAINER];
  4010. if (next == root)
  4011. return _traverseNode(next, isFullySelected, FALSE, how);
  4012. parent = next.parentNode;
  4013. clonedParent = _traverseNode(parent, FALSE, FALSE, how);
  4014. while (parent) {
  4015. while (next) {
  4016. prevSibling = next.previousSibling;
  4017. clonedChild = _traverseNode(next, isFullySelected, FALSE, how);
  4018. if (how != DELETE)
  4019. clonedParent.insertBefore(clonedChild, clonedParent.firstChild);
  4020. isFullySelected = TRUE;
  4021. next = prevSibling;
  4022. }
  4023. if (parent == root)
  4024. return clonedParent;
  4025. next = parent.previousSibling;
  4026. parent = parent.parentNode;
  4027. clonedGrandParent = _traverseNode(parent, FALSE, FALSE, how);
  4028. if (how != DELETE)
  4029. clonedGrandParent.appendChild(clonedParent);
  4030. clonedParent = clonedGrandParent;
  4031. }
  4032. };
  4033. function _traverseLeftBoundary(root, how) {
  4034. var next = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]), isFullySelected = next != t[START_CONTAINER], parent, clonedParent, nextSibling, clonedChild, clonedGrandParent;
  4035. if (next == root)
  4036. return _traverseNode(next, isFullySelected, TRUE, how);
  4037. parent = next.parentNode;
  4038. clonedParent = _traverseNode(parent, FALSE, TRUE, how);
  4039. while (parent) {
  4040. while (next) {
  4041. nextSibling = next.nextSibling;
  4042. clonedChild = _traverseNode(next, isFullySelected, TRUE, how);
  4043. if (how != DELETE)
  4044. clonedParent.appendChild(clonedChild);
  4045. isFullySelected = TRUE;
  4046. next = nextSibling;
  4047. }
  4048. if (parent == root)
  4049. return clonedParent;
  4050. next = parent.nextSibling;
  4051. parent = parent.parentNode;
  4052. clonedGrandParent = _traverseNode(parent, FALSE, TRUE, how);
  4053. if (how != DELETE)
  4054. clonedGrandParent.appendChild(clonedParent);
  4055. clonedParent = clonedGrandParent;
  4056. }
  4057. };
  4058. function _traverseNode(n, isFullySelected, isLeft, how) {
  4059. var txtValue, newNodeValue, oldNodeValue, offset, newNode;
  4060. if (isFullySelected)
  4061. return _traverseFullySelected(n, how);
  4062. if (n.nodeType == 3 /* TEXT_NODE */) {
  4063. txtValue = n.nodeValue;
  4064. if (isLeft) {
  4065. offset = t[START_OFFSET];
  4066. newNodeValue = txtValue.substring(offset);
  4067. oldNodeValue = txtValue.substring(0, offset);
  4068. } else {
  4069. offset = t[END_OFFSET];
  4070. newNodeValue = txtValue.substring(0, offset);
  4071. oldNodeValue = txtValue.substring(offset);
  4072. }
  4073. if (how != CLONE)
  4074. n.nodeValue = oldNodeValue;
  4075. if (how == DELETE)
  4076. return;
  4077. newNode = n.cloneNode(FALSE);
  4078. newNode.nodeValue = newNodeValue;
  4079. return newNode;
  4080. }
  4081. if (how == DELETE)
  4082. return;
  4083. return n.cloneNode(FALSE);
  4084. };
  4085. function _traverseFullySelected(n, how) {
  4086. if (how != DELETE)
  4087. return how == CLONE ? n.cloneNode(TRUE) : n;
  4088. n.parentNode.removeChild(n);
  4089. };
  4090. };
  4091. ns.Range = Range;
  4092. })(tinymce.dom);
  4093. (function() {
  4094. function Selection(selection) {
  4095. var self = this, dom = selection.dom, TRUE = true, FALSE = false;
  4096. function getPosition(rng, start) {
  4097. var checkRng, startIndex = 0, endIndex, inside,
  4098. children, child, offset, index, position = -1, parent;
  4099. // Setup test range, collapse it and get the parent
  4100. checkRng = rng.duplicate();
  4101. checkRng.collapse(start);
  4102. parent = checkRng.parentElement();
  4103. // Check if the selection is within the right document
  4104. if (parent.ownerDocument !== selection.dom.doc)
  4105. return;
  4106. // IE will report non editable elements as it's parent so look for an editable one
  4107. while (parent.contentEditable === "false") {
  4108. parent = parent.parentNode;
  4109. }
  4110. // If parent doesn't have any children then return that we are inside the element
  4111. if (!parent.hasChildNodes()) {
  4112. return {node : parent, inside : 1};
  4113. }
  4114. // Setup node list and endIndex
  4115. children = parent.children;
  4116. endIndex = children.length - 1;
  4117. // Perform a binary search for the position
  4118. while (startIndex <= endIndex) {
  4119. index = Math.floor((startIndex + endIndex) / 2);
  4120. // Move selection to node and compare the ranges
  4121. child = children[index];
  4122. checkRng.moveToElementText(child);
  4123. position = checkRng.compareEndPoints(start ? 'StartToStart' : 'EndToEnd', rng);
  4124. // Before/after or an exact match
  4125. if (position > 0) {
  4126. endIndex = index - 1;
  4127. } else if (position < 0) {
  4128. startIndex = index + 1;
  4129. } else {
  4130. return {node : child};
  4131. }
  4132. }
  4133. // Check if child position is before or we didn't find a position
  4134. if (position < 0) {
  4135. // No element child was found use the parent element and the offset inside that
  4136. if (!child) {
  4137. checkRng.moveToElementText(parent);
  4138. checkRng.collapse(true);
  4139. child = parent;
  4140. inside = true;
  4141. } else
  4142. checkRng.collapse(false);
  4143. checkRng.setEndPoint(start ? 'EndToStart' : 'EndToEnd', rng);
  4144. // Fix for edge case: <div style="width: 100px; height:100px;"><table>..</table>ab|c</div>
  4145. if (checkRng.compareEndPoints(start ? 'StartToStart' : 'StartToEnd', rng) > 0) {
  4146. checkRng = rng.duplicate();
  4147. checkRng.collapse(start);
  4148. offset = -1;
  4149. while (parent == checkRng.parentElement()) {
  4150. if (checkRng.move('character', -1) == 0)
  4151. break;
  4152. offset++;
  4153. }
  4154. }
  4155. offset = offset || checkRng.text.replace('\r\n', ' ').length;
  4156. } else {
  4157. // Child position is after the selection endpoint
  4158. checkRng.collapse(true);
  4159. checkRng.setEndPoint(start ? 'StartToStart' : 'StartToEnd', rng);
  4160. // Get the length of the text to find where the endpoint is relative to it's container
  4161. offset = checkRng.text.replace('\r\n', ' ').length;
  4162. }
  4163. return {node : child, position : position, offset : offset, inside : inside};
  4164. };
  4165. // Returns a W3C DOM compatible range object by using the IE Range API
  4166. function getRange() {
  4167. var ieRange = selection.getRng(), domRange = dom.createRng(), element, collapsed, tmpRange, element2, bookmark, fail;
  4168. // If selection is outside the current document just return an empty range
  4169. element = ieRange.item ? ieRange.item(0) : ieRange.parentElement();
  4170. if (element.ownerDocument != dom.doc)
  4171. return domRange;
  4172. collapsed = selection.isCollapsed();
  4173. // Handle control selection
  4174. if (ieRange.item) {
  4175. domRange.setStart(element.parentNode, dom.nodeIndex(element));
  4176. domRange.setEnd(domRange.startContainer, domRange.startOffset + 1);
  4177. return domRange;
  4178. }
  4179. function findEndPoint(start) {
  4180. var endPoint = getPosition(ieRange, start), container, offset, textNodeOffset = 0, sibling, undef, nodeValue;
  4181. container = endPoint.node;
  4182. offset = endPoint.offset;
  4183. if (endPoint.inside && !container.hasChildNodes()) {
  4184. domRange[start ? 'setStart' : 'setEnd'](container, 0);
  4185. return;
  4186. }
  4187. if (offset === undef) {
  4188. domRange[start ? 'setStartBefore' : 'setEndAfter'](container);
  4189. return;
  4190. }
  4191. if (endPoint.position < 0) {
  4192. sibling = endPoint.inside ? container.firstChild : container.nextSibling;
  4193. if (!sibling) {
  4194. domRange[start ? 'setStartAfter' : 'setEndAfter'](container);
  4195. return;
  4196. }
  4197. if (!offset) {
  4198. if (sibling.nodeType == 3)
  4199. domRange[start ? 'setStart' : 'setEnd'](sibling, 0);
  4200. else
  4201. domRange[start ? 'setStartBefore' : 'setEndBefore'](sibling);
  4202. return;
  4203. }
  4204. // Find the text node and offset
  4205. while (sibling) {
  4206. nodeValue = sibling.nodeValue;
  4207. textNodeOffset += nodeValue.length;
  4208. // We are at or passed the position we where looking for
  4209. if (textNodeOffset >= offset) {
  4210. container = sibling;
  4211. textNodeOffset -= offset;
  4212. textNodeOffset = nodeValue.length - textNodeOffset;
  4213. break;
  4214. }
  4215. sibling = sibling.nextSibling;
  4216. }
  4217. } else {
  4218. // Find the text node and offset
  4219. sibling = container.previousSibling;
  4220. if (!sibling)
  4221. return domRange[start ? 'setStartBefore' : 'setEndBefore'](container);
  4222. // If there isn't any text to loop then use the first position
  4223. if (!offset) {
  4224. if (container.nodeType == 3)
  4225. domRange[start ? 'setStart' : 'setEnd'](sibling, container.nodeValue.length);
  4226. else
  4227. domRange[start ? 'setStartAfter' : 'setEndAfter'](sibling);
  4228. return;
  4229. }
  4230. while (sibling) {
  4231. textNodeOffset += sibling.nodeValue.length;
  4232. // We are at or passed the position we where looking for
  4233. if (textNodeOffset >= offset) {
  4234. container = sibling;
  4235. textNodeOffset -= offset;
  4236. break;
  4237. }
  4238. sibling = sibling.previousSibling;
  4239. }
  4240. }
  4241. domRange[start ? 'setStart' : 'setEnd'](container, textNodeOffset);
  4242. };
  4243. try {
  4244. // Find start point
  4245. findEndPoint(true);
  4246. // Find end point if needed
  4247. if (!collapsed)
  4248. findEndPoint();
  4249. } catch (ex) {
  4250. // IE has a nasty bug where text nodes might throw "invalid argument" when you
  4251. // access the nodeValue or other properties of text nodes. This seems to happend when
  4252. // text nodes are split into two nodes by a delete/backspace call. So lets detect it and try to fix it.
  4253. if (ex.number == -2147024809) {
  4254. // Get the current selection
  4255. bookmark = self.getBookmark(2);
  4256. // Get start element
  4257. tmpRange = ieRange.duplicate();
  4258. tmpRange.collapse(true);
  4259. element = tmpRange.parentElement();
  4260. // Get end element
  4261. if (!collapsed) {
  4262. tmpRange = ieRange.duplicate();
  4263. tmpRange.collapse(false);
  4264. element2 = tmpRange.parentElement();
  4265. element2.innerHTML = element2.innerHTML;
  4266. }
  4267. // Remove the broken elements
  4268. element.innerHTML = element.innerHTML;
  4269. // Restore the selection
  4270. self.moveToBookmark(bookmark);
  4271. // Since the range has moved we need to re-get it
  4272. ieRange = selection.getRng();
  4273. // Find start point
  4274. findEndPoint(true);
  4275. // Find end point if needed
  4276. if (!collapsed)
  4277. findEndPoint();
  4278. } else
  4279. throw ex; // Throw other errors
  4280. }
  4281. return domRange;
  4282. };
  4283. this.getBookmark = function(type) {
  4284. var rng = selection.getRng(), start, end, bookmark = {};
  4285. function getIndexes(node) {
  4286. var node, parent, root, children, i, indexes = [];
  4287. parent = node.parentNode;
  4288. root = dom.getRoot().parentNode;
  4289. while (parent != root) {
  4290. children = parent.children;
  4291. i = children.length;
  4292. while (i--) {
  4293. if (node === children[i]) {
  4294. indexes.push(i);
  4295. break;
  4296. }
  4297. }
  4298. node = parent;
  4299. parent = parent.parentNode;
  4300. }
  4301. return indexes;
  4302. };
  4303. function getBookmarkEndPoint(start) {
  4304. var position;
  4305. position = getPosition(rng, start);
  4306. if (position) {
  4307. return {
  4308. position : position.position,
  4309. offset : position.offset,
  4310. indexes : getIndexes(position.node),
  4311. inside : position.inside
  4312. };
  4313. }
  4314. };
  4315. // Non ubstructive bookmark
  4316. if (type === 2) {
  4317. // Handle text selection
  4318. if (!rng.item) {
  4319. bookmark.start = getBookmarkEndPoint(true);
  4320. if (!selection.isCollapsed())
  4321. bookmark.end = getBookmarkEndPoint();
  4322. } else
  4323. bookmark.start = {ctrl : true, indexes : getIndexes(rng.item(0))};
  4324. }
  4325. return bookmark;
  4326. };
  4327. this.moveToBookmark = function(bookmark) {
  4328. var rng, body = dom.doc.body;
  4329. function resolveIndexes(indexes) {
  4330. var node, i, idx, children;
  4331. node = dom.getRoot();
  4332. for (i = indexes.length - 1; i >= 0; i--) {
  4333. children = node.children;
  4334. idx = indexes[i];
  4335. if (idx <= children.length - 1) {
  4336. node = children[idx];
  4337. }
  4338. }
  4339. return node;
  4340. };
  4341. function setBookmarkEndPoint(start) {
  4342. var endPoint = bookmark[start ? 'start' : 'end'], moveLeft, moveRng, undef;
  4343. if (endPoint) {
  4344. moveLeft = endPoint.position > 0;
  4345. moveRng = body.createTextRange();
  4346. moveRng.moveToElementText(resolveIndexes(endPoint.indexes));
  4347. offset = endPoint.offset;
  4348. if (offset !== undef) {
  4349. moveRng.collapse(endPoint.inside || moveLeft);
  4350. moveRng.moveStart('character', moveLeft ? -offset : offset);
  4351. } else
  4352. moveRng.collapse(start);
  4353. rng.setEndPoint(start ? 'StartToStart' : 'EndToStart', moveRng);
  4354. if (start)
  4355. rng.collapse(true);
  4356. }
  4357. };
  4358. if (bookmark.start) {
  4359. if (bookmark.start.ctrl) {
  4360. rng = body.createControlRange();
  4361. rng.addElement(resolveIndexes(bookmark.start.indexes));
  4362. rng.select();
  4363. } else {
  4364. rng = body.createTextRange();
  4365. setBookmarkEndPoint(true);
  4366. setBookmarkEndPoint();
  4367. rng.select();
  4368. }
  4369. }
  4370. };
  4371. this.addRange = function(rng) {
  4372. var ieRng, ctrlRng, startContainer, startOffset, endContainer, endOffset, doc = selection.dom.doc, body = doc.body;
  4373. function setEndPoint(start) {
  4374. var container, offset, marker, tmpRng, nodes;
  4375. marker = dom.create('a');
  4376. container = start ? startContainer : endContainer;
  4377. offset = start ? startOffset : endOffset;
  4378. tmpRng = ieRng.duplicate();
  4379. if (container == doc || container == doc.documentElement) {
  4380. container = body;
  4381. offset = 0;
  4382. }
  4383. if (container.nodeType == 3) {
  4384. container.parentNode.insertBefore(marker, container);
  4385. tmpRng.moveToElementText(marker);
  4386. tmpRng.moveStart('character', offset);
  4387. dom.remove(marker);
  4388. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  4389. } else {
  4390. nodes = container.childNodes;
  4391. if (nodes.length) {
  4392. if (offset >= nodes.length) {
  4393. dom.insertAfter(marker, nodes[nodes.length - 1]);
  4394. } else {
  4395. container.insertBefore(marker, nodes[offset]);
  4396. }
  4397. tmpRng.moveToElementText(marker);
  4398. } else {
  4399. // Empty node selection for example <div>|</div>
  4400. marker = doc.createTextNode('\uFEFF');
  4401. container.appendChild(marker);
  4402. tmpRng.moveToElementText(marker.parentNode);
  4403. tmpRng.collapse(TRUE);
  4404. }
  4405. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  4406. dom.remove(marker);
  4407. }
  4408. }
  4409. // Setup some shorter versions
  4410. startContainer = rng.startContainer;
  4411. startOffset = rng.startOffset;
  4412. endContainer = rng.endContainer;
  4413. endOffset = rng.endOffset;
  4414. ieRng = body.createTextRange();
  4415. // If single element selection then try making a control selection out of it
  4416. if (startContainer == endContainer && startContainer.nodeType == 1 && startOffset == endOffset - 1) {
  4417. if (startOffset == endOffset - 1) {
  4418. try {
  4419. ctrlRng = body.createControlRange();
  4420. ctrlRng.addElement(startContainer.childNodes[startOffset]);
  4421. ctrlRng.select();
  4422. return;
  4423. } catch (ex) {
  4424. // Ignore
  4425. }
  4426. }
  4427. }
  4428. // Set start/end point of selection
  4429. setEndPoint(true);
  4430. setEndPoint();
  4431. // Select the new range and scroll it into view
  4432. ieRng.select();
  4433. };
  4434. // Expose range method
  4435. this.getRangeAt = getRange;
  4436. };
  4437. // Expose the selection object
  4438. tinymce.dom.TridentSelection = Selection;
  4439. })();
  4440. /*
  4441. * Sizzle CSS Selector Engine - v1.0
  4442. * Copyright 2009, The Dojo Foundation
  4443. * Released under the MIT, BSD, and GPL Licenses.
  4444. * More information: http://sizzlejs.com/
  4445. */
  4446. (function(){
  4447. var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
  4448. done = 0,
  4449. toString = Object.prototype.toString,
  4450. hasDuplicate = false,
  4451. baseHasDuplicate = true;
  4452. // Here we check if the JavaScript engine is using some sort of
  4453. // optimization where it does not always call our comparision
  4454. // function. If that is the case, discard the hasDuplicate value.
  4455. // Thus far that includes Google Chrome.
  4456. [0, 0].sort(function(){
  4457. baseHasDuplicate = false;
  4458. return 0;
  4459. });
  4460. var Sizzle = function(selector, context, results, seed) {
  4461. results = results || [];
  4462. context = context || document;
  4463. var origContext = context;
  4464. if ( context.nodeType !== 1 && context.nodeType !== 9 ) {
  4465. return [];
  4466. }
  4467. if ( !selector || typeof selector !== "string" ) {
  4468. return results;
  4469. }
  4470. var parts = [], m, set, checkSet, extra, prune = true, contextXML = Sizzle.isXML(context),
  4471. soFar = selector, ret, cur, pop, i;
  4472. // Reset the position of the chunker regexp (start from head)
  4473. do {
  4474. chunker.exec("");
  4475. m = chunker.exec(soFar);
  4476. if ( m ) {
  4477. soFar = m[3];
  4478. parts.push( m[1] );
  4479. if ( m[2] ) {
  4480. extra = m[3];
  4481. break;
  4482. }
  4483. }
  4484. } while ( m );
  4485. if ( parts.length > 1 && origPOS.exec( selector ) ) {
  4486. if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {
  4487. set = posProcess( parts[0] + parts[1], context );
  4488. } else {
  4489. set = Expr.relative[ parts[0] ] ?
  4490. [ context ] :
  4491. Sizzle( parts.shift(), context );
  4492. while ( parts.length ) {
  4493. selector = parts.shift();
  4494. if ( Expr.relative[ selector ] ) {
  4495. selector += parts.shift();
  4496. }
  4497. set = posProcess( selector, set );
  4498. }
  4499. }
  4500. } else {
  4501. // Take a shortcut and set the context if the root selector is an ID
  4502. // (but not if it'll be faster if the inner selector is an ID)
  4503. if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML &&
  4504. Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) {
  4505. ret = Sizzle.find( parts.shift(), context, contextXML );
  4506. context = ret.expr ? Sizzle.filter( ret.expr, ret.set )[0] : ret.set[0];
  4507. }
  4508. if ( context ) {
  4509. ret = seed ?
  4510. { expr: parts.pop(), set: makeArray(seed) } :
  4511. Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML );
  4512. set = ret.expr ? Sizzle.filter( ret.expr, ret.set ) : ret.set;
  4513. if ( parts.length > 0 ) {
  4514. checkSet = makeArray(set);
  4515. } else {
  4516. prune = false;
  4517. }
  4518. while ( parts.length ) {
  4519. cur = parts.pop();
  4520. pop = cur;
  4521. if ( !Expr.relative[ cur ] ) {
  4522. cur = "";
  4523. } else {
  4524. pop = parts.pop();
  4525. }
  4526. if ( pop == null ) {
  4527. pop = context;
  4528. }
  4529. Expr.relative[ cur ]( checkSet, pop, contextXML );
  4530. }
  4531. } else {
  4532. checkSet = parts = [];
  4533. }
  4534. }
  4535. if ( !checkSet ) {
  4536. checkSet = set;
  4537. }
  4538. if ( !checkSet ) {
  4539. Sizzle.error( cur || selector );
  4540. }
  4541. if ( toString.call(checkSet) === "[object Array]" ) {
  4542. if ( !prune ) {
  4543. results.push.apply( results, checkSet );
  4544. } else if ( context && context.nodeType === 1 ) {
  4545. for ( i = 0; checkSet[i] != null; i++ ) {
  4546. if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && Sizzle.contains(context, checkSet[i])) ) {
  4547. results.push( set[i] );
  4548. }
  4549. }
  4550. } else {
  4551. for ( i = 0; checkSet[i] != null; i++ ) {
  4552. if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
  4553. results.push( set[i] );
  4554. }
  4555. }
  4556. }
  4557. } else {
  4558. makeArray( checkSet, results );
  4559. }
  4560. if ( extra ) {
  4561. Sizzle( extra, origContext, results, seed );
  4562. Sizzle.uniqueSort( results );
  4563. }
  4564. return results;
  4565. };
  4566. Sizzle.uniqueSort = function(results){
  4567. if ( sortOrder ) {
  4568. hasDuplicate = baseHasDuplicate;
  4569. results.sort(sortOrder);
  4570. if ( hasDuplicate ) {
  4571. for ( var i = 1; i < results.length; i++ ) {
  4572. if ( results[i] === results[i-1] ) {
  4573. results.splice(i--, 1);
  4574. }
  4575. }
  4576. }
  4577. }
  4578. return results;
  4579. };
  4580. Sizzle.matches = function(expr, set){
  4581. return Sizzle(expr, null, null, set);
  4582. };
  4583. Sizzle.find = function(expr, context, isXML){
  4584. var set;
  4585. if ( !expr ) {
  4586. return [];
  4587. }
  4588. for ( var i = 0, l = Expr.order.length; i < l; i++ ) {
  4589. var type = Expr.order[i], match;
  4590. if ( (match = Expr.leftMatch[ type ].exec( expr )) ) {
  4591. var left = match[1];
  4592. match.splice(1,1);
  4593. if ( left.substr( left.length - 1 ) !== "\\" ) {
  4594. match[1] = (match[1] || "").replace(/\\/g, "");
  4595. set = Expr.find[ type ]( match, context, isXML );
  4596. if ( set != null ) {
  4597. expr = expr.replace( Expr.match[ type ], "" );
  4598. break;
  4599. }
  4600. }
  4601. }
  4602. }
  4603. if ( !set ) {
  4604. set = context.getElementsByTagName("*");
  4605. }
  4606. return {set: set, expr: expr};
  4607. };
  4608. Sizzle.filter = function(expr, set, inplace, not){
  4609. var old = expr, result = [], curLoop = set, match, anyFound,
  4610. isXMLFilter = set && set[0] && Sizzle.isXML(set[0]);
  4611. while ( expr && set.length ) {
  4612. for ( var type in Expr.filter ) {
  4613. if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {
  4614. var filter = Expr.filter[ type ], found, item, left = match[1];
  4615. anyFound = false;
  4616. match.splice(1,1);
  4617. if ( left.substr( left.length - 1 ) === "\\" ) {
  4618. continue;
  4619. }
  4620. if ( curLoop === result ) {
  4621. result = [];
  4622. }
  4623. if ( Expr.preFilter[ type ] ) {
  4624. match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter );
  4625. if ( !match ) {
  4626. anyFound = found = true;
  4627. } else if ( match === true ) {
  4628. continue;
  4629. }
  4630. }
  4631. if ( match ) {
  4632. for ( var i = 0; (item = curLoop[i]) != null; i++ ) {
  4633. if ( item ) {
  4634. found = filter( item, match, i, curLoop );
  4635. var pass = not ^ !!found;
  4636. if ( inplace && found != null ) {
  4637. if ( pass ) {
  4638. anyFound = true;
  4639. } else {
  4640. curLoop[i] = false;
  4641. }
  4642. } else if ( pass ) {
  4643. result.push( item );
  4644. anyFound = true;
  4645. }
  4646. }
  4647. }
  4648. }
  4649. if ( found !== undefined ) {
  4650. if ( !inplace ) {
  4651. curLoop = result;
  4652. }
  4653. expr = expr.replace( Expr.match[ type ], "" );
  4654. if ( !anyFound ) {
  4655. return [];
  4656. }
  4657. break;
  4658. }
  4659. }
  4660. }
  4661. // Improper expression
  4662. if ( expr === old ) {
  4663. if ( anyFound == null ) {
  4664. Sizzle.error( expr );
  4665. } else {
  4666. break;
  4667. }
  4668. }
  4669. old = expr;
  4670. }
  4671. return curLoop;
  4672. };
  4673. Sizzle.error = function( msg ) {
  4674. throw "Syntax error, unrecognized expression: " + msg;
  4675. };
  4676. var Expr = Sizzle.selectors = {
  4677. order: [ "ID", "NAME", "TAG" ],
  4678. match: {
  4679. ID: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
  4680. CLASS: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
  4681. NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,
  4682. ATTR: /\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/,
  4683. TAG: /^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,
  4684. CHILD: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+\-]*)\))?/,
  4685. POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,
  4686. PSEUDO: /:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/
  4687. },
  4688. leftMatch: {},
  4689. attrMap: {
  4690. "class": "className",
  4691. "for": "htmlFor"
  4692. },
  4693. attrHandle: {
  4694. href: function(elem){
  4695. return elem.getAttribute("href");
  4696. }
  4697. },
  4698. relative: {
  4699. "+": function(checkSet, part){
  4700. var isPartStr = typeof part === "string",
  4701. isTag = isPartStr && !/\W/.test(part),
  4702. isPartStrNotTag = isPartStr && !isTag;
  4703. if ( isTag ) {
  4704. part = part.toLowerCase();
  4705. }
  4706. for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) {
  4707. if ( (elem = checkSet[i]) ) {
  4708. while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}
  4709. checkSet[i] = isPartStrNotTag || elem && elem.nodeName.toLowerCase() === part ?
  4710. elem || false :
  4711. elem === part;
  4712. }
  4713. }
  4714. if ( isPartStrNotTag ) {
  4715. Sizzle.filter( part, checkSet, true );
  4716. }
  4717. },
  4718. ">": function(checkSet, part){
  4719. var isPartStr = typeof part === "string",
  4720. elem, i = 0, l = checkSet.length;
  4721. if ( isPartStr && !/\W/.test(part) ) {
  4722. part = part.toLowerCase();
  4723. for ( ; i < l; i++ ) {
  4724. elem = checkSet[i];
  4725. if ( elem ) {
  4726. var parent = elem.parentNode;
  4727. checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false;
  4728. }
  4729. }
  4730. } else {
  4731. for ( ; i < l; i++ ) {
  4732. elem = checkSet[i];
  4733. if ( elem ) {
  4734. checkSet[i] = isPartStr ?
  4735. elem.parentNode :
  4736. elem.parentNode === part;
  4737. }
  4738. }
  4739. if ( isPartStr ) {
  4740. Sizzle.filter( part, checkSet, true );
  4741. }
  4742. }
  4743. },
  4744. "": function(checkSet, part, isXML){
  4745. var doneName = done++, checkFn = dirCheck, nodeCheck;
  4746. if ( typeof part === "string" && !/\W/.test(part) ) {
  4747. part = part.toLowerCase();
  4748. nodeCheck = part;
  4749. checkFn = dirNodeCheck;
  4750. }
  4751. checkFn("parentNode", part, doneName, checkSet, nodeCheck, isXML);
  4752. },
  4753. "~": function(checkSet, part, isXML){
  4754. var doneName = done++, checkFn = dirCheck, nodeCheck;
  4755. if ( typeof part === "string" && !/\W/.test(part) ) {
  4756. part = part.toLowerCase();
  4757. nodeCheck = part;
  4758. checkFn = dirNodeCheck;
  4759. }
  4760. checkFn("previousSibling", part, doneName, checkSet, nodeCheck, isXML);
  4761. }
  4762. },
  4763. find: {
  4764. ID: function(match, context, isXML){
  4765. if ( typeof context.getElementById !== "undefined" && !isXML ) {
  4766. var m = context.getElementById(match[1]);
  4767. return m ? [m] : [];
  4768. }
  4769. },
  4770. NAME: function(match, context){
  4771. if ( typeof context.getElementsByName !== "undefined" ) {
  4772. var ret = [], results = context.getElementsByName(match[1]);
  4773. for ( var i = 0, l = results.length; i < l; i++ ) {
  4774. if ( results[i].getAttribute("name") === match[1] ) {
  4775. ret.push( results[i] );
  4776. }
  4777. }
  4778. return ret.length === 0 ? null : ret;
  4779. }
  4780. },
  4781. TAG: function(match, context){
  4782. return context.getElementsByTagName(match[1]);
  4783. }
  4784. },
  4785. preFilter: {
  4786. CLASS: function(match, curLoop, inplace, result, not, isXML){
  4787. match = " " + match[1].replace(/\\/g, "") + " ";
  4788. if ( isXML ) {
  4789. return match;
  4790. }
  4791. for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) {
  4792. if ( elem ) {
  4793. if ( not ^ (elem.className && (" " + elem.className + " ").replace(/[\t\n]/g, " ").indexOf(match) >= 0) ) {
  4794. if ( !inplace ) {
  4795. result.push( elem );
  4796. }
  4797. } else if ( inplace ) {
  4798. curLoop[i] = false;
  4799. }
  4800. }
  4801. }
  4802. return false;
  4803. },
  4804. ID: function(match){
  4805. return match[1].replace(/\\/g, "");
  4806. },
  4807. TAG: function(match, curLoop){
  4808. return match[1].toLowerCase();
  4809. },
  4810. CHILD: function(match){
  4811. if ( match[1] === "nth" ) {
  4812. // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
  4813. var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
  4814. match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" ||
  4815. !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);
  4816. // calculate the numbers (first)n+(last) including if they are negative
  4817. match[2] = (test[1] + (test[2] || 1)) - 0;
  4818. match[3] = test[3] - 0;
  4819. }
  4820. // TODO: Move to normal caching system
  4821. match[0] = done++;
  4822. return match;
  4823. },
  4824. ATTR: function(match, curLoop, inplace, result, not, isXML){
  4825. var name = match[1].replace(/\\/g, "");
  4826. if ( !isXML && Expr.attrMap[name] ) {
  4827. match[1] = Expr.attrMap[name];
  4828. }
  4829. if ( match[2] === "~=" ) {
  4830. match[4] = " " + match[4] + " ";
  4831. }
  4832. return match;
  4833. },
  4834. PSEUDO: function(match, curLoop, inplace, result, not){
  4835. if ( match[1] === "not" ) {
  4836. // If we're dealing with a complex expression, or a simple one
  4837. if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) {
  4838. match[3] = Sizzle(match[3], null, null, curLoop);
  4839. } else {
  4840. var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
  4841. if ( !inplace ) {
  4842. result.push.apply( result, ret );
  4843. }
  4844. return false;
  4845. }
  4846. } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
  4847. return true;
  4848. }
  4849. return match;
  4850. },
  4851. POS: function(match){
  4852. match.unshift( true );
  4853. return match;
  4854. }
  4855. },
  4856. filters: {
  4857. enabled: function(elem){
  4858. return elem.disabled === false && elem.type !== "hidden";
  4859. },
  4860. disabled: function(elem){
  4861. return elem.disabled === true;
  4862. },
  4863. checked: function(elem){
  4864. return elem.checked === true;
  4865. },
  4866. selected: function(elem){
  4867. // Accessing this property makes selected-by-default
  4868. // options in Safari work properly
  4869. elem.parentNode.selectedIndex;
  4870. return elem.selected === true;
  4871. },
  4872. parent: function(elem){
  4873. return !!elem.firstChild;
  4874. },
  4875. empty: function(elem){
  4876. return !elem.firstChild;
  4877. },
  4878. has: function(elem, i, match){
  4879. return !!Sizzle( match[3], elem ).length;
  4880. },
  4881. header: function(elem){
  4882. return (/h\d/i).test( elem.nodeName );
  4883. },
  4884. text: function(elem){
  4885. return "text" === elem.type;
  4886. },
  4887. radio: function(elem){
  4888. return "radio" === elem.type;
  4889. },
  4890. checkbox: function(elem){
  4891. return "checkbox" === elem.type;
  4892. },
  4893. file: function(elem){
  4894. return "file" === elem.type;
  4895. },
  4896. password: function(elem){
  4897. return "password" === elem.type;
  4898. },
  4899. submit: function(elem){
  4900. return "submit" === elem.type;
  4901. },
  4902. image: function(elem){
  4903. return "image" === elem.type;
  4904. },
  4905. reset: function(elem){
  4906. return "reset" === elem.type;
  4907. },
  4908. button: function(elem){
  4909. return "button" === elem.type || elem.nodeName.toLowerCase() === "button";
  4910. },
  4911. input: function(elem){
  4912. return (/input|select|textarea|button/i).test(elem.nodeName);
  4913. }
  4914. },
  4915. setFilters: {
  4916. first: function(elem, i){
  4917. return i === 0;
  4918. },
  4919. last: function(elem, i, match, array){
  4920. return i === array.length - 1;
  4921. },
  4922. even: function(elem, i){
  4923. return i % 2 === 0;
  4924. },
  4925. odd: function(elem, i){
  4926. return i % 2 === 1;
  4927. },
  4928. lt: function(elem, i, match){
  4929. return i < match[3] - 0;
  4930. },
  4931. gt: function(elem, i, match){
  4932. return i > match[3] - 0;
  4933. },
  4934. nth: function(elem, i, match){
  4935. return match[3] - 0 === i;
  4936. },
  4937. eq: function(elem, i, match){
  4938. return match[3] - 0 === i;
  4939. }
  4940. },
  4941. filter: {
  4942. PSEUDO: function(elem, match, i, array){
  4943. var name = match[1], filter = Expr.filters[ name ];
  4944. if ( filter ) {
  4945. return filter( elem, i, match, array );
  4946. } else if ( name === "contains" ) {
  4947. return (elem.textContent || elem.innerText || Sizzle.getText([ elem ]) || "").indexOf(match[3]) >= 0;
  4948. } else if ( name === "not" ) {
  4949. var not = match[3];
  4950. for ( var j = 0, l = not.length; j < l; j++ ) {
  4951. if ( not[j] === elem ) {
  4952. return false;
  4953. }
  4954. }
  4955. return true;
  4956. } else {
  4957. Sizzle.error( "Syntax error, unrecognized expression: " + name );
  4958. }
  4959. },
  4960. CHILD: function(elem, match){
  4961. var type = match[1], node = elem;
  4962. switch (type) {
  4963. case 'only':
  4964. case 'first':
  4965. while ( (node = node.previousSibling) ) {
  4966. if ( node.nodeType === 1 ) {
  4967. return false;
  4968. }
  4969. }
  4970. if ( type === "first" ) {
  4971. return true;
  4972. }
  4973. node = elem;
  4974. case 'last':
  4975. while ( (node = node.nextSibling) ) {
  4976. if ( node.nodeType === 1 ) {
  4977. return false;
  4978. }
  4979. }
  4980. return true;
  4981. case 'nth':
  4982. var first = match[2], last = match[3];
  4983. if ( first === 1 && last === 0 ) {
  4984. return true;
  4985. }
  4986. var doneName = match[0],
  4987. parent = elem.parentNode;
  4988. if ( parent && (parent.sizcache !== doneName || !elem.nodeIndex) ) {
  4989. var count = 0;
  4990. for ( node = parent.firstChild; node; node = node.nextSibling ) {
  4991. if ( node.nodeType === 1 ) {
  4992. node.nodeIndex = ++count;
  4993. }
  4994. }
  4995. parent.sizcache = doneName;
  4996. }
  4997. var diff = elem.nodeIndex - last;
  4998. if ( first === 0 ) {
  4999. return diff === 0;
  5000. } else {
  5001. return ( diff % first === 0 && diff / first >= 0 );
  5002. }
  5003. }
  5004. },
  5005. ID: function(elem, match){
  5006. return elem.nodeType === 1 && elem.getAttribute("id") === match;
  5007. },
  5008. TAG: function(elem, match){
  5009. return (match === "*" && elem.nodeType === 1) || elem.nodeName.toLowerCase() === match;
  5010. },
  5011. CLASS: function(elem, match){
  5012. return (" " + (elem.className || elem.getAttribute("class")) + " ")
  5013. .indexOf( match ) > -1;
  5014. },
  5015. ATTR: function(elem, match){
  5016. var name = match[1],
  5017. result = Expr.attrHandle[ name ] ?
  5018. Expr.attrHandle[ name ]( elem ) :
  5019. elem[ name ] != null ?
  5020. elem[ name ] :
  5021. elem.getAttribute( name ),
  5022. value = result + "",
  5023. type = match[2],
  5024. check = match[4];
  5025. return result == null ?
  5026. type === "!=" :
  5027. type === "=" ?
  5028. value === check :
  5029. type === "*=" ?
  5030. value.indexOf(check) >= 0 :
  5031. type === "~=" ?
  5032. (" " + value + " ").indexOf(check) >= 0 :
  5033. !check ?
  5034. value && result !== false :
  5035. type === "!=" ?
  5036. value !== check :
  5037. type === "^=" ?
  5038. value.indexOf(check) === 0 :
  5039. type === "$=" ?
  5040. value.substr(value.length - check.length) === check :
  5041. type === "|=" ?
  5042. value === check || value.substr(0, check.length + 1) === check + "-" :
  5043. false;
  5044. },
  5045. POS: function(elem, match, i, array){
  5046. var name = match[2], filter = Expr.setFilters[ name ];
  5047. if ( filter ) {
  5048. return filter( elem, i, match, array );
  5049. }
  5050. }
  5051. }
  5052. };
  5053. var origPOS = Expr.match.POS,
  5054. fescape = function(all, num){
  5055. return "\\" + (num - 0 + 1);
  5056. };
  5057. for ( var type in Expr.match ) {
  5058. Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) );
  5059. Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) );
  5060. }
  5061. var makeArray = function(array, results) {
  5062. array = Array.prototype.slice.call( array, 0 );
  5063. if ( results ) {
  5064. results.push.apply( results, array );
  5065. return results;
  5066. }
  5067. return array;
  5068. };
  5069. // Perform a simple check to determine if the browser is capable of
  5070. // converting a NodeList to an array using builtin methods.
  5071. // Also verifies that the returned array holds DOM nodes
  5072. // (which is not the case in the Blackberry browser)
  5073. try {
  5074. Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType;
  5075. // Provide a fallback method if it does not work
  5076. } catch(e){
  5077. makeArray = function(array, results) {
  5078. var ret = results || [], i = 0;
  5079. if ( toString.call(array) === "[object Array]" ) {
  5080. Array.prototype.push.apply( ret, array );
  5081. } else {
  5082. if ( typeof array.length === "number" ) {
  5083. for ( var l = array.length; i < l; i++ ) {
  5084. ret.push( array[i] );
  5085. }
  5086. } else {
  5087. for ( ; array[i]; i++ ) {
  5088. ret.push( array[i] );
  5089. }
  5090. }
  5091. }
  5092. return ret;
  5093. };
  5094. }
  5095. var sortOrder;
  5096. if ( document.documentElement.compareDocumentPosition ) {
  5097. sortOrder = function( a, b ) {
  5098. if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) {
  5099. if ( a == b ) {
  5100. hasDuplicate = true;
  5101. }
  5102. return a.compareDocumentPosition ? -1 : 1;
  5103. }
  5104. var ret = a.compareDocumentPosition(b) & 4 ? -1 : a === b ? 0 : 1;
  5105. if ( ret === 0 ) {
  5106. hasDuplicate = true;
  5107. }
  5108. return ret;
  5109. };
  5110. } else if ( "sourceIndex" in document.documentElement ) {
  5111. sortOrder = function( a, b ) {
  5112. if ( !a.sourceIndex || !b.sourceIndex ) {
  5113. if ( a == b ) {
  5114. hasDuplicate = true;
  5115. }
  5116. return a.sourceIndex ? -1 : 1;
  5117. }
  5118. var ret = a.sourceIndex - b.sourceIndex;
  5119. if ( ret === 0 ) {
  5120. hasDuplicate = true;
  5121. }
  5122. return ret;
  5123. };
  5124. } else if ( document.createRange ) {
  5125. sortOrder = function( a, b ) {
  5126. if ( !a.ownerDocument || !b.ownerDocument ) {
  5127. if ( a == b ) {
  5128. hasDuplicate = true;
  5129. }
  5130. return a.ownerDocument ? -1 : 1;
  5131. }
  5132. var aRange = a.ownerDocument.createRange(), bRange = b.ownerDocument.createRange();
  5133. aRange.setStart(a, 0);
  5134. aRange.setEnd(a, 0);
  5135. bRange.setStart(b, 0);
  5136. bRange.setEnd(b, 0);
  5137. var ret = aRange.compareBoundaryPoints(Range.START_TO_END, bRange);
  5138. if ( ret === 0 ) {
  5139. hasDuplicate = true;
  5140. }
  5141. return ret;
  5142. };
  5143. }
  5144. // Utility function for retreiving the text value of an array of DOM nodes
  5145. Sizzle.getText = function( elems ) {
  5146. var ret = "", elem;
  5147. for ( var i = 0; elems[i]; i++ ) {
  5148. elem = elems[i];
  5149. // Get the text from text nodes and CDATA nodes
  5150. if ( elem.nodeType === 3 || elem.nodeType === 4 ) {
  5151. ret += elem.nodeValue;
  5152. // Traverse everything else, except comment nodes
  5153. } else if ( elem.nodeType !== 8 ) {
  5154. ret += Sizzle.getText( elem.childNodes );
  5155. }
  5156. }
  5157. return ret;
  5158. };
  5159. // Check to see if the browser returns elements by name when
  5160. // querying by getElementById (and provide a workaround)
  5161. (function(){
  5162. // We're going to inject a fake input element with a specified name
  5163. var form = document.createElement("div"),
  5164. id = "script" + (new Date()).getTime();
  5165. form.innerHTML = "<a name='" + id + "'/>";
  5166. // Inject it into the root element, check its status, and remove it quickly
  5167. var root = document.documentElement;
  5168. root.insertBefore( form, root.firstChild );
  5169. // The workaround has to do additional checks after a getElementById
  5170. // Which slows things down for other browsers (hence the branching)
  5171. if ( document.getElementById( id ) ) {
  5172. Expr.find.ID = function(match, context, isXML){
  5173. if ( typeof context.getElementById !== "undefined" && !isXML ) {
  5174. var m = context.getElementById(match[1]);
  5175. return m ? m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : [];
  5176. }
  5177. };
  5178. Expr.filter.ID = function(elem, match){
  5179. var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
  5180. return elem.nodeType === 1 && node && node.nodeValue === match;
  5181. };
  5182. }
  5183. root.removeChild( form );
  5184. root = form = null; // release memory in IE
  5185. })();
  5186. (function(){
  5187. // Check to see if the browser returns only elements
  5188. // when doing getElementsByTagName("*")
  5189. // Create a fake element
  5190. var div = document.createElement("div");
  5191. div.appendChild( document.createComment("") );
  5192. // Make sure no comments are found
  5193. if ( div.getElementsByTagName("*").length > 0 ) {
  5194. Expr.find.TAG = function(match, context){
  5195. var results = context.getElementsByTagName(match[1]);
  5196. // Filter out possible comments
  5197. if ( match[1] === "*" ) {
  5198. var tmp = [];
  5199. for ( var i = 0; results[i]; i++ ) {
  5200. if ( results[i].nodeType === 1 ) {
  5201. tmp.push( results[i] );
  5202. }
  5203. }
  5204. results = tmp;
  5205. }
  5206. return results;
  5207. };
  5208. }
  5209. // Check to see if an attribute returns normalized href attributes
  5210. div.innerHTML = "<a href='#'></a>";
  5211. if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" &&
  5212. div.firstChild.getAttribute("href") !== "#" ) {
  5213. Expr.attrHandle.href = function(elem){
  5214. return elem.getAttribute("href", 2);
  5215. };
  5216. }
  5217. div = null; // release memory in IE
  5218. })();
  5219. if ( document.querySelectorAll ) {
  5220. (function(){
  5221. var oldSizzle = Sizzle, div = document.createElement("div");
  5222. div.innerHTML = "<p class='TEST'></p>";
  5223. // Safari can't handle uppercase or unicode characters when
  5224. // in quirks mode.
  5225. if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {
  5226. return;
  5227. }
  5228. Sizzle = function(query, context, extra, seed){
  5229. context = context || document;
  5230. // Only use querySelectorAll on non-XML documents
  5231. // (ID selectors don't work in non-HTML documents)
  5232. if ( !seed && context.nodeType === 9 && !Sizzle.isXML(context) ) {
  5233. try {
  5234. return makeArray( context.querySelectorAll(query), extra );
  5235. } catch(e){}
  5236. }
  5237. return oldSizzle(query, context, extra, seed);
  5238. };
  5239. for ( var prop in oldSizzle ) {
  5240. Sizzle[ prop ] = oldSizzle[ prop ];
  5241. }
  5242. div = null; // release memory in IE
  5243. })();
  5244. }
  5245. (function(){
  5246. var div = document.createElement("div");
  5247. div.innerHTML = "<div class='test e'></div><div class='test'></div>";
  5248. // Opera can't find a second classname (in 9.6)
  5249. // Also, make sure that getElementsByClassName actually exists
  5250. if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) {
  5251. return;
  5252. }
  5253. // Safari caches class attributes, doesn't catch changes (in 3.2)
  5254. div.lastChild.className = "e";
  5255. if ( div.getElementsByClassName("e").length === 1 ) {
  5256. return;
  5257. }
  5258. Expr.order.splice(1, 0, "CLASS");
  5259. Expr.find.CLASS = function(match, context, isXML) {
  5260. if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {
  5261. return context.getElementsByClassName(match[1]);
  5262. }
  5263. };
  5264. div = null; // release memory in IE
  5265. })();
  5266. function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
  5267. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  5268. var elem = checkSet[i];
  5269. if ( elem ) {
  5270. elem = elem[dir];
  5271. var match = false;
  5272. while ( elem ) {
  5273. if ( elem.sizcache === doneName ) {
  5274. match = checkSet[elem.sizset];
  5275. break;
  5276. }
  5277. if ( elem.nodeType === 1 && !isXML ){
  5278. elem.sizcache = doneName;
  5279. elem.sizset = i;
  5280. }
  5281. if ( elem.nodeName.toLowerCase() === cur ) {
  5282. match = elem;
  5283. break;
  5284. }
  5285. elem = elem[dir];
  5286. }
  5287. checkSet[i] = match;
  5288. }
  5289. }
  5290. }
  5291. function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
  5292. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  5293. var elem = checkSet[i];
  5294. if ( elem ) {
  5295. elem = elem[dir];
  5296. var match = false;
  5297. while ( elem ) {
  5298. if ( elem.sizcache === doneName ) {
  5299. match = checkSet[elem.sizset];
  5300. break;
  5301. }
  5302. if ( elem.nodeType === 1 ) {
  5303. if ( !isXML ) {
  5304. elem.sizcache = doneName;
  5305. elem.sizset = i;
  5306. }
  5307. if ( typeof cur !== "string" ) {
  5308. if ( elem === cur ) {
  5309. match = true;
  5310. break;
  5311. }
  5312. } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
  5313. match = elem;
  5314. break;
  5315. }
  5316. }
  5317. elem = elem[dir];
  5318. }
  5319. checkSet[i] = match;
  5320. }
  5321. }
  5322. }
  5323. Sizzle.contains = document.compareDocumentPosition ? function(a, b){
  5324. return !!(a.compareDocumentPosition(b) & 16);
  5325. } : function(a, b){
  5326. return a !== b && (a.contains ? a.contains(b) : true);
  5327. };
  5328. Sizzle.isXML = function(elem){
  5329. // documentElement is verified for cases where it doesn't yet exist
  5330. // (such as loading iframes in IE - #4833)
  5331. var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement;
  5332. return documentElement ? documentElement.nodeName !== "HTML" : false;
  5333. };
  5334. var posProcess = function(selector, context){
  5335. var tmpSet = [], later = "", match,
  5336. root = context.nodeType ? [context] : context;
  5337. // Position selectors must be done after the filter
  5338. // And so must :not(positional) so we move all PSEUDOs to the end
  5339. while ( (match = Expr.match.PSEUDO.exec( selector )) ) {
  5340. later += match[0];
  5341. selector = selector.replace( Expr.match.PSEUDO, "" );
  5342. }
  5343. selector = Expr.relative[selector] ? selector + "*" : selector;
  5344. for ( var i = 0, l = root.length; i < l; i++ ) {
  5345. Sizzle( selector, root[i], tmpSet );
  5346. }
  5347. return Sizzle.filter( later, tmpSet );
  5348. };
  5349. // EXPOSE
  5350. window.tinymce.dom.Sizzle = Sizzle;
  5351. })();
  5352. (function(tinymce) {
  5353. // Shorten names
  5354. var each = tinymce.each, DOM = tinymce.DOM, isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, Event;
  5355. tinymce.create('tinymce.dom.EventUtils', {
  5356. EventUtils : function() {
  5357. this.inits = [];
  5358. this.events = [];
  5359. },
  5360. add : function(o, n, f, s) {
  5361. var cb, t = this, el = t.events, r;
  5362. if (n instanceof Array) {
  5363. r = [];
  5364. each(n, function(n) {
  5365. r.push(t.add(o, n, f, s));
  5366. });
  5367. return r;
  5368. }
  5369. // Handle array
  5370. if (o && o.hasOwnProperty && o instanceof Array) {
  5371. r = [];
  5372. each(o, function(o) {
  5373. o = DOM.get(o);
  5374. r.push(t.add(o, n, f, s));
  5375. });
  5376. return r;
  5377. }
  5378. o = DOM.get(o);
  5379. if (!o)
  5380. return;
  5381. // Setup event callback
  5382. cb = function(e) {
  5383. // Is all events disabled
  5384. if (t.disabled)
  5385. return;
  5386. e = e || window.event;
  5387. // Patch in target, preventDefault and stopPropagation in IE it's W3C valid
  5388. if (e && isIE) {
  5389. if (!e.target)
  5390. e.target = e.srcElement;
  5391. // Patch in preventDefault, stopPropagation methods for W3C compatibility
  5392. tinymce.extend(e, t._stoppers);
  5393. }
  5394. if (!s)
  5395. return f(e);
  5396. return f.call(s, e);
  5397. };
  5398. if (n == 'unload') {
  5399. tinymce.unloads.unshift({func : cb});
  5400. return cb;
  5401. }
  5402. if (n == 'init') {
  5403. if (t.domLoaded)
  5404. cb();
  5405. else
  5406. t.inits.push(cb);
  5407. return cb;
  5408. }
  5409. // Store away listener reference
  5410. el.push({
  5411. obj : o,
  5412. name : n,
  5413. func : f,
  5414. cfunc : cb,
  5415. scope : s
  5416. });
  5417. t._add(o, n, cb);
  5418. return f;
  5419. },
  5420. remove : function(o, n, f) {
  5421. var t = this, a = t.events, s = false, r;
  5422. // Handle array
  5423. if (o && o.hasOwnProperty && o instanceof Array) {
  5424. r = [];
  5425. each(o, function(o) {
  5426. o = DOM.get(o);
  5427. r.push(t.remove(o, n, f));
  5428. });
  5429. return r;
  5430. }
  5431. o = DOM.get(o);
  5432. each(a, function(e, i) {
  5433. if (e.obj == o && e.name == n && (!f || (e.func == f || e.cfunc == f))) {
  5434. a.splice(i, 1);
  5435. t._remove(o, n, e.cfunc);
  5436. s = true;
  5437. return false;
  5438. }
  5439. });
  5440. return s;
  5441. },
  5442. clear : function(o) {
  5443. var t = this, a = t.events, i, e;
  5444. if (o) {
  5445. o = DOM.get(o);
  5446. for (i = a.length - 1; i >= 0; i--) {
  5447. e = a[i];
  5448. if (e.obj === o) {
  5449. t._remove(e.obj, e.name, e.cfunc);
  5450. e.obj = e.cfunc = null;
  5451. a.splice(i, 1);
  5452. }
  5453. }
  5454. }
  5455. },
  5456. cancel : function(e) {
  5457. if (!e)
  5458. return false;
  5459. this.stop(e);
  5460. return this.prevent(e);
  5461. },
  5462. stop : function(e) {
  5463. if (e.stopPropagation)
  5464. e.stopPropagation();
  5465. else
  5466. e.cancelBubble = true;
  5467. return false;
  5468. },
  5469. prevent : function(e) {
  5470. if (e.preventDefault)
  5471. e.preventDefault();
  5472. else
  5473. e.returnValue = false;
  5474. return false;
  5475. },
  5476. destroy : function() {
  5477. var t = this;
  5478. each(t.events, function(e, i) {
  5479. t._remove(e.obj, e.name, e.cfunc);
  5480. e.obj = e.cfunc = null;
  5481. });
  5482. t.events = [];
  5483. t = null;
  5484. },
  5485. _add : function(o, n, f) {
  5486. if (o.attachEvent)
  5487. o.attachEvent('on' + n, f);
  5488. else if (o.addEventListener)
  5489. o.addEventListener(n, f, false);
  5490. else
  5491. o['on' + n] = f;
  5492. },
  5493. _remove : function(o, n, f) {
  5494. if (o) {
  5495. try {
  5496. if (o.detachEvent)
  5497. o.detachEvent('on' + n, f);
  5498. else if (o.removeEventListener)
  5499. o.removeEventListener(n, f, false);
  5500. else
  5501. o['on' + n] = null;
  5502. } catch (ex) {
  5503. // Might fail with permission denined on IE so we just ignore that
  5504. }
  5505. }
  5506. },
  5507. _pageInit : function(win) {
  5508. var t = this;
  5509. // Keep it from running more than once
  5510. if (t.domLoaded)
  5511. return;
  5512. t.domLoaded = true;
  5513. each(t.inits, function(c) {
  5514. c();
  5515. });
  5516. t.inits = [];
  5517. },
  5518. _wait : function(win) {
  5519. var t = this, doc = win.document;
  5520. // No need since the document is already loaded
  5521. if (win.tinyMCE_GZ && tinyMCE_GZ.loaded) {
  5522. t.domLoaded = 1;
  5523. return;
  5524. }
  5525. // Use IE method
  5526. if (doc.attachEvent) {
  5527. doc.attachEvent("onreadystatechange", function() {
  5528. if (doc.readyState === "complete") {
  5529. doc.detachEvent("onreadystatechange", arguments.callee);
  5530. t._pageInit(win);
  5531. }
  5532. });
  5533. if (doc.documentElement.doScroll && win == win.top) {
  5534. (function() {
  5535. if (t.domLoaded)
  5536. return;
  5537. try {
  5538. // If IE is used, use the trick by Diego Perini licensed under MIT by request to the author.
  5539. // http://javascript.nwbox.com/IEContentLoaded/
  5540. doc.documentElement.doScroll("left");
  5541. } catch (ex) {
  5542. setTimeout(arguments.callee, 0);
  5543. return;
  5544. }
  5545. t._pageInit(win);
  5546. })();
  5547. }
  5548. } else if (doc.addEventListener) {
  5549. t._add(win, 'DOMContentLoaded', function() {
  5550. t._pageInit(win);
  5551. });
  5552. }
  5553. t._add(win, 'load', function() {
  5554. t._pageInit(win);
  5555. });
  5556. },
  5557. _stoppers : {
  5558. preventDefault : function() {
  5559. this.returnValue = false;
  5560. },
  5561. stopPropagation : function() {
  5562. this.cancelBubble = true;
  5563. }
  5564. }
  5565. });
  5566. Event = tinymce.dom.Event = new tinymce.dom.EventUtils();
  5567. // Dispatch DOM content loaded event for IE and Safari
  5568. Event._wait(window);
  5569. tinymce.addUnload(function() {
  5570. Event.destroy();
  5571. });
  5572. })(tinymce);
  5573. (function(tinymce) {
  5574. tinymce.dom.Element = function(id, settings) {
  5575. var t = this, dom, el;
  5576. t.settings = settings = settings || {};
  5577. t.id = id;
  5578. t.dom = dom = settings.dom || tinymce.DOM;
  5579. // Only IE leaks DOM references, this is a lot faster
  5580. if (!tinymce.isIE)
  5581. el = dom.get(t.id);
  5582. tinymce.each(
  5583. ('getPos,getRect,getParent,add,setStyle,getStyle,setStyles,' +
  5584. 'setAttrib,setAttribs,getAttrib,addClass,removeClass,' +
  5585. 'hasClass,getOuterHTML,setOuterHTML,remove,show,hide,' +
  5586. 'isHidden,setHTML,get').split(/,/)
  5587. , function(k) {
  5588. t[k] = function() {
  5589. var a = [id], i;
  5590. for (i = 0; i < arguments.length; i++)
  5591. a.push(arguments[i]);
  5592. a = dom[k].apply(dom, a);
  5593. t.update(k);
  5594. return a;
  5595. };
  5596. });
  5597. tinymce.extend(t, {
  5598. on : function(n, f, s) {
  5599. return tinymce.dom.Event.add(t.id, n, f, s);
  5600. },
  5601. getXY : function() {
  5602. return {
  5603. x : parseInt(t.getStyle('left')),
  5604. y : parseInt(t.getStyle('top'))
  5605. };
  5606. },
  5607. getSize : function() {
  5608. var n = dom.get(t.id);
  5609. return {
  5610. w : parseInt(t.getStyle('width') || n.clientWidth),
  5611. h : parseInt(t.getStyle('height') || n.clientHeight)
  5612. };
  5613. },
  5614. moveTo : function(x, y) {
  5615. t.setStyles({left : x, top : y});
  5616. },
  5617. moveBy : function(x, y) {
  5618. var p = t.getXY();
  5619. t.moveTo(p.x + x, p.y + y);
  5620. },
  5621. resizeTo : function(w, h) {
  5622. t.setStyles({width : w, height : h});
  5623. },
  5624. resizeBy : function(w, h) {
  5625. var s = t.getSize();
  5626. t.resizeTo(s.w + w, s.h + h);
  5627. },
  5628. update : function(k) {
  5629. var b;
  5630. if (tinymce.isIE6 && settings.blocker) {
  5631. k = k || '';
  5632. // Ignore getters
  5633. if (k.indexOf('get') === 0 || k.indexOf('has') === 0 || k.indexOf('is') === 0)
  5634. return;
  5635. // Remove blocker on remove
  5636. if (k == 'remove') {
  5637. dom.remove(t.blocker);
  5638. return;
  5639. }
  5640. if (!t.blocker) {
  5641. t.blocker = dom.uniqueId();
  5642. b = dom.add(settings.container || dom.getRoot(), 'iframe', {id : t.blocker, style : 'position:absolute;', frameBorder : 0, src : 'javascript:""'});
  5643. dom.setStyle(b, 'opacity', 0);
  5644. } else
  5645. b = dom.get(t.blocker);
  5646. dom.setStyles(b, {
  5647. left : t.getStyle('left', 1),
  5648. top : t.getStyle('top', 1),
  5649. width : t.getStyle('width', 1),
  5650. height : t.getStyle('height', 1),
  5651. display : t.getStyle('display', 1),
  5652. zIndex : parseInt(t.getStyle('zIndex', 1) || 0) - 1
  5653. });
  5654. }
  5655. }
  5656. });
  5657. };
  5658. })(tinymce);
  5659. (function(tinymce) {
  5660. function trimNl(s) {
  5661. return s.replace(/[\n\r]+/g, '');
  5662. };
  5663. // Shorten names
  5664. var is = tinymce.is, isIE = tinymce.isIE, each = tinymce.each;
  5665. tinymce.create('tinymce.dom.Selection', {
  5666. Selection : function(dom, win, serializer) {
  5667. var t = this;
  5668. t.dom = dom;
  5669. t.win = win;
  5670. t.serializer = serializer;
  5671. // Add events
  5672. each([
  5673. 'onBeforeSetContent',
  5674. 'onBeforeGetContent',
  5675. 'onSetContent',
  5676. 'onGetContent'
  5677. ], function(e) {
  5678. t[e] = new tinymce.util.Dispatcher(t);
  5679. });
  5680. // No W3C Range support
  5681. if (!t.win.getSelection)
  5682. t.tridentSel = new tinymce.dom.TridentSelection(t);
  5683. if (tinymce.isIE && dom.boxModel)
  5684. this._fixIESelection();
  5685. // Prevent leaks
  5686. tinymce.addUnload(t.destroy, t);
  5687. },
  5688. getContent : function(s) {
  5689. var t = this, r = t.getRng(), e = t.dom.create("body"), se = t.getSel(), wb, wa, n;
  5690. s = s || {};
  5691. wb = wa = '';
  5692. s.get = true;
  5693. s.format = s.format || 'html';
  5694. s.forced_root_block = '';
  5695. t.onBeforeGetContent.dispatch(t, s);
  5696. if (s.format == 'text')
  5697. return t.isCollapsed() ? '' : (r.text || (se.toString ? se.toString() : ''));
  5698. if (r.cloneContents) {
  5699. n = r.cloneContents();
  5700. if (n)
  5701. e.appendChild(n);
  5702. } else if (is(r.item) || is(r.htmlText))
  5703. e.innerHTML = r.item ? r.item(0).outerHTML : r.htmlText;
  5704. else
  5705. e.innerHTML = r.toString();
  5706. // Keep whitespace before and after
  5707. if (/^\s/.test(e.innerHTML))
  5708. wb = ' ';
  5709. if (/\s+$/.test(e.innerHTML))
  5710. wa = ' ';
  5711. s.getInner = true;
  5712. s.content = t.isCollapsed() ? '' : wb + t.serializer.serialize(e, s) + wa;
  5713. t.onGetContent.dispatch(t, s);
  5714. return s.content;
  5715. },
  5716. setContent : function(content, args) {
  5717. var self = this, rng = self.getRng(), caretNode, doc = self.win.document, frag, temp;
  5718. args = args || {format : 'html'};
  5719. args.set = true;
  5720. content = args.content = content;
  5721. // Dispatch before set content event
  5722. if (!args.no_events)
  5723. self.onBeforeSetContent.dispatch(self, args);
  5724. content = args.content;
  5725. if (rng.insertNode) {
  5726. // Make caret marker since insertNode places the caret in the beginning of text after insert
  5727. content += '<span id="__caret">_</span>';
  5728. // Delete and insert new node
  5729. if (rng.startContainer == doc && rng.endContainer == doc) {
  5730. // WebKit will fail if the body is empty since the range is then invalid and it can't insert contents
  5731. doc.body.innerHTML = content;
  5732. } else {
  5733. rng.deleteContents();
  5734. if (doc.body.childNodes.length == 0) {
  5735. doc.body.innerHTML = content;
  5736. } else {
  5737. // createContextualFragment doesn't exists in IE 9 DOMRanges
  5738. if (rng.createContextualFragment) {
  5739. rng.insertNode(rng.createContextualFragment(content));
  5740. } else {
  5741. // Fake createContextualFragment call in IE 9
  5742. frag = doc.createDocumentFragment();
  5743. temp = doc.createElement('div');
  5744. frag.appendChild(temp);
  5745. temp.outerHTML = content;
  5746. rng.insertNode(frag);
  5747. }
  5748. }
  5749. }
  5750. // Move to caret marker
  5751. caretNode = self.dom.get('__caret');
  5752. // Make sure we wrap it compleatly, Opera fails with a simple select call
  5753. rng = doc.createRange();
  5754. rng.setStartBefore(caretNode);
  5755. rng.setEndBefore(caretNode);
  5756. self.setRng(rng);
  5757. // Remove the caret position
  5758. self.dom.remove('__caret');
  5759. try {
  5760. self.setRng(rng);
  5761. } catch (ex) {
  5762. // Might fail on Opera for some odd reason
  5763. }
  5764. } else {
  5765. if (rng.item) {
  5766. // Delete content and get caret text selection
  5767. doc.execCommand('Delete', false, null);
  5768. rng = self.getRng();
  5769. }
  5770. rng.pasteHTML(content);
  5771. }
  5772. // Dispatch set content event
  5773. if (!args.no_events)
  5774. self.onSetContent.dispatch(self, args);
  5775. },
  5776. getStart : function() {
  5777. var rng = this.getRng(), startElement, parentElement, checkRng, node;
  5778. if (rng.duplicate || rng.item) {
  5779. // Control selection, return first item
  5780. if (rng.item)
  5781. return rng.item(0);
  5782. // Get start element
  5783. checkRng = rng.duplicate();
  5784. checkRng.collapse(1);
  5785. startElement = checkRng.parentElement();
  5786. // Check if range parent is inside the start element, then return the inner parent element
  5787. // This will fix issues when a single element is selected, IE would otherwise return the wrong start element
  5788. parentElement = node = rng.parentElement();
  5789. while (node = node.parentNode) {
  5790. if (node == startElement) {
  5791. startElement = parentElement;
  5792. break;
  5793. }
  5794. }
  5795. return startElement;
  5796. } else {
  5797. startElement = rng.startContainer;
  5798. if (startElement.nodeType == 1 && startElement.hasChildNodes())
  5799. startElement = startElement.childNodes[Math.min(startElement.childNodes.length - 1, rng.startOffset)];
  5800. if (startElement && startElement.nodeType == 3)
  5801. return startElement.parentNode;
  5802. return startElement;
  5803. }
  5804. },
  5805. getEnd : function() {
  5806. var t = this, r = t.getRng(), e, eo;
  5807. if (r.duplicate || r.item) {
  5808. if (r.item)
  5809. return r.item(0);
  5810. r = r.duplicate();
  5811. r.collapse(0);
  5812. e = r.parentElement();
  5813. if (e && e.nodeName == 'BODY')
  5814. return e.lastChild || e;
  5815. return e;
  5816. } else {
  5817. e = r.endContainer;
  5818. eo = r.endOffset;
  5819. if (e.nodeType == 1 && e.hasChildNodes())
  5820. e = e.childNodes[eo > 0 ? eo - 1 : eo];
  5821. if (e && e.nodeType == 3)
  5822. return e.parentNode;
  5823. return e;
  5824. }
  5825. },
  5826. getBookmark : function(type, normalized) {
  5827. var t = this, dom = t.dom, rng, rng2, id, collapsed, name, element, index, chr = '\uFEFF', styles;
  5828. function findIndex(name, element) {
  5829. var index = 0;
  5830. each(dom.select(name), function(node, i) {
  5831. if (node == element)
  5832. index = i;
  5833. });
  5834. return index;
  5835. };
  5836. if (type == 2) {
  5837. function getLocation() {
  5838. var rng = t.getRng(true), root = dom.getRoot(), bookmark = {};
  5839. function getPoint(rng, start) {
  5840. var container = rng[start ? 'startContainer' : 'endContainer'],
  5841. offset = rng[start ? 'startOffset' : 'endOffset'], point = [], node, childNodes, after = 0;
  5842. if (container.nodeType == 3) {
  5843. if (normalized) {
  5844. for (node = container.previousSibling; node && node.nodeType == 3; node = node.previousSibling)
  5845. offset += node.nodeValue.length;
  5846. }
  5847. point.push(offset);
  5848. } else {
  5849. childNodes = container.childNodes;
  5850. if (offset >= childNodes.length && childNodes.length) {
  5851. after = 1;
  5852. offset = Math.max(0, childNodes.length - 1);
  5853. }
  5854. point.push(t.dom.nodeIndex(childNodes[offset], normalized) + after);
  5855. }
  5856. for (; container && container != root; container = container.parentNode)
  5857. point.push(t.dom.nodeIndex(container, normalized));
  5858. return point;
  5859. };
  5860. bookmark.start = getPoint(rng, true);
  5861. if (!t.isCollapsed())
  5862. bookmark.end = getPoint(rng);
  5863. return bookmark;
  5864. };
  5865. if (t.tridentSel)
  5866. return t.tridentSel.getBookmark(type);
  5867. return getLocation();
  5868. }
  5869. // Handle simple range
  5870. if (type)
  5871. return {rng : t.getRng()};
  5872. rng = t.getRng();
  5873. id = dom.uniqueId();
  5874. collapsed = tinyMCE.activeEditor.selection.isCollapsed();
  5875. styles = 'overflow:hidden;line-height:0px';
  5876. // Explorer method
  5877. if (rng.duplicate || rng.item) {
  5878. // Text selection
  5879. if (!rng.item) {
  5880. rng2 = rng.duplicate();
  5881. try {
  5882. // Insert start marker
  5883. rng.collapse();
  5884. rng.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_start" style="' + styles + '">' + chr + '</span>');
  5885. // Insert end marker
  5886. if (!collapsed) {
  5887. rng2.collapse(false);
  5888. // Detect the empty space after block elements in IE and move the end back one character <p></p>] becomes <p>]</p>
  5889. rng.moveToElementText(rng2.parentElement());
  5890. if (rng.compareEndPoints('StartToEnd', rng2) == 0)
  5891. rng2.move('character', -1);
  5892. rng2.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_end" style="' + styles + '">' + chr + '</span>');
  5893. }
  5894. } catch (ex) {
  5895. // IE might throw unspecified error so lets ignore it
  5896. return null;
  5897. }
  5898. } else {
  5899. // Control selection
  5900. element = rng.item(0);
  5901. name = element.nodeName;
  5902. return {name : name, index : findIndex(name, element)};
  5903. }
  5904. } else {
  5905. element = t.getNode();
  5906. name = element.nodeName;
  5907. if (name == 'IMG')
  5908. return {name : name, index : findIndex(name, element)};
  5909. // W3C method
  5910. rng2 = rng.cloneRange();
  5911. // Insert end marker
  5912. if (!collapsed) {
  5913. rng2.collapse(false);
  5914. rng2.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_end', style : styles}, chr));
  5915. }
  5916. rng.collapse(true);
  5917. rng.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_start', style : styles}, chr));
  5918. }
  5919. t.moveToBookmark({id : id, keep : 1});
  5920. return {id : id};
  5921. },
  5922. moveToBookmark : function(bookmark) {
  5923. var t = this, dom = t.dom, marker1, marker2, rng, root, startContainer, endContainer, startOffset, endOffset;
  5924. if (bookmark) {
  5925. if (bookmark.start) {
  5926. rng = dom.createRng();
  5927. root = dom.getRoot();
  5928. function setEndPoint(start) {
  5929. var point = bookmark[start ? 'start' : 'end'], i, node, offset, children;
  5930. if (point) {
  5931. offset = point[0];
  5932. // Find container node
  5933. for (node = root, i = point.length - 1; i >= 1; i--) {
  5934. children = node.childNodes;
  5935. if (point[i] > children.length - 1)
  5936. return;
  5937. node = children[point[i]];
  5938. }
  5939. // Move text offset to best suitable location
  5940. if (node.nodeType === 3)
  5941. offset = Math.min(point[0], node.nodeValue.length);
  5942. // Move element offset to best suitable location
  5943. if (node.nodeType === 1)
  5944. offset = Math.min(point[0], node.childNodes.length);
  5945. // Set offset within container node
  5946. if (start)
  5947. rng.setStart(node, offset);
  5948. else
  5949. rng.setEnd(node, offset);
  5950. }
  5951. return true;
  5952. };
  5953. if (t.tridentSel)
  5954. return t.tridentSel.moveToBookmark(bookmark);
  5955. if (setEndPoint(true) && setEndPoint()) {
  5956. t.setRng(rng);
  5957. }
  5958. } else if (bookmark.id) {
  5959. function restoreEndPoint(suffix) {
  5960. var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev, keep = bookmark.keep;
  5961. if (marker) {
  5962. node = marker.parentNode;
  5963. if (suffix == 'start') {
  5964. if (!keep) {
  5965. idx = dom.nodeIndex(marker);
  5966. } else {
  5967. node = marker.firstChild;
  5968. idx = 1;
  5969. }
  5970. startContainer = endContainer = node;
  5971. startOffset = endOffset = idx;
  5972. } else {
  5973. if (!keep) {
  5974. idx = dom.nodeIndex(marker);
  5975. } else {
  5976. node = marker.firstChild;
  5977. idx = 1;
  5978. }
  5979. endContainer = node;
  5980. endOffset = idx;
  5981. }
  5982. if (!keep) {
  5983. prev = marker.previousSibling;
  5984. next = marker.nextSibling;
  5985. // Remove all marker text nodes
  5986. each(tinymce.grep(marker.childNodes), function(node) {
  5987. if (node.nodeType == 3)
  5988. node.nodeValue = node.nodeValue.replace(/\uFEFF/g, '');
  5989. });
  5990. // Remove marker but keep children if for example contents where inserted into the marker
  5991. // Also remove duplicated instances of the marker for example by a split operation or by WebKit auto split on paste feature
  5992. while (marker = dom.get(bookmark.id + '_' + suffix))
  5993. dom.remove(marker, 1);
  5994. // If siblings are text nodes then merge them unless it's Opera since it some how removes the node
  5995. // 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
  5996. if (prev && next && prev.nodeType == next.nodeType && prev.nodeType == 3 && !tinymce.isOpera) {
  5997. idx = prev.nodeValue.length;
  5998. prev.appendData(next.nodeValue);
  5999. dom.remove(next);
  6000. if (suffix == 'start') {
  6001. startContainer = endContainer = prev;
  6002. startOffset = endOffset = idx;
  6003. } else {
  6004. endContainer = prev;
  6005. endOffset = idx;
  6006. }
  6007. }
  6008. }
  6009. }
  6010. };
  6011. function addBogus(node) {
  6012. // Adds a bogus BR element for empty block elements or just a space on IE since it renders BR elements incorrectly
  6013. if (dom.isBlock(node) && !node.innerHTML)
  6014. node.innerHTML = !isIE ? '<br data-mce-bogus="1" />' : ' ';
  6015. return node;
  6016. };
  6017. // Restore start/end points
  6018. restoreEndPoint('start');
  6019. restoreEndPoint('end');
  6020. if (startContainer) {
  6021. rng = dom.createRng();
  6022. rng.setStart(addBogus(startContainer), startOffset);
  6023. rng.setEnd(addBogus(endContainer), endOffset);
  6024. t.setRng(rng);
  6025. }
  6026. } else if (bookmark.name) {
  6027. t.select(dom.select(bookmark.name)[bookmark.index]);
  6028. } else if (bookmark.rng)
  6029. t.setRng(bookmark.rng);
  6030. }
  6031. },
  6032. select : function(node, content) {
  6033. var t = this, dom = t.dom, rng = dom.createRng(), idx;
  6034. if (node) {
  6035. idx = dom.nodeIndex(node);
  6036. rng.setStart(node.parentNode, idx);
  6037. rng.setEnd(node.parentNode, idx + 1);
  6038. // Find first/last text node or BR element
  6039. if (content) {
  6040. function setPoint(node, start) {
  6041. var walker = new tinymce.dom.TreeWalker(node, node);
  6042. do {
  6043. // Text node
  6044. if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length != 0) {
  6045. if (start)
  6046. rng.setStart(node, 0);
  6047. else
  6048. rng.setEnd(node, node.nodeValue.length);
  6049. return;
  6050. }
  6051. // BR element
  6052. if (node.nodeName == 'BR') {
  6053. if (start)
  6054. rng.setStartBefore(node);
  6055. else
  6056. rng.setEndBefore(node);
  6057. return;
  6058. }
  6059. } while (node = (start ? walker.next() : walker.prev()));
  6060. };
  6061. setPoint(node, 1);
  6062. setPoint(node);
  6063. }
  6064. t.setRng(rng);
  6065. }
  6066. return node;
  6067. },
  6068. isCollapsed : function() {
  6069. var t = this, r = t.getRng(), s = t.getSel();
  6070. if (!r || r.item)
  6071. return false;
  6072. if (r.compareEndPoints)
  6073. return r.compareEndPoints('StartToEnd', r) === 0;
  6074. return !s || r.collapsed;
  6075. },
  6076. collapse : function(to_start) {
  6077. var self = this, rng = self.getRng(), node;
  6078. // Control range on IE
  6079. if (rng.item) {
  6080. node = rng.item(0);
  6081. rng = self.win.document.body.createTextRange();
  6082. rng.moveToElementText(node);
  6083. }
  6084. rng.collapse(!!to_start);
  6085. self.setRng(rng);
  6086. },
  6087. getSel : function() {
  6088. var t = this, w = this.win;
  6089. return w.getSelection ? w.getSelection() : w.document.selection;
  6090. },
  6091. getRng : function(w3c) {
  6092. var t = this, s, r, elm, doc = t.win.document;
  6093. // Found tridentSel object then we need to use that one
  6094. if (w3c && t.tridentSel)
  6095. return t.tridentSel.getRangeAt(0);
  6096. try {
  6097. if (s = t.getSel())
  6098. r = s.rangeCount > 0 ? s.getRangeAt(0) : (s.createRange ? s.createRange() : doc.createRange());
  6099. } catch (ex) {
  6100. // IE throws unspecified error here if TinyMCE is placed in a frame/iframe
  6101. }
  6102. // We have W3C ranges and it's IE then fake control selection since IE9 doesn't handle that correctly yet
  6103. if (tinymce.isIE && r && r.setStart && doc.selection.createRange().item) {
  6104. elm = doc.selection.createRange().item(0);
  6105. r = doc.createRange();
  6106. r.setStartBefore(elm);
  6107. r.setEndAfter(elm);
  6108. }
  6109. // No range found then create an empty one
  6110. // This can occur when the editor is placed in a hidden container element on Gecko
  6111. // Or on IE when there was an exception
  6112. if (!r)
  6113. r = doc.createRange ? doc.createRange() : doc.body.createTextRange();
  6114. if (t.selectedRange && t.explicitRange) {
  6115. if (r.compareBoundaryPoints(r.START_TO_START, t.selectedRange) === 0 && r.compareBoundaryPoints(r.END_TO_END, t.selectedRange) === 0) {
  6116. // Safari, Opera and Chrome only ever select text which causes the range to change.
  6117. // This lets us use the originally set range if the selection hasn't been changed by the user.
  6118. r = t.explicitRange;
  6119. } else {
  6120. t.selectedRange = null;
  6121. t.explicitRange = null;
  6122. }
  6123. }
  6124. return r;
  6125. },
  6126. setRng : function(r) {
  6127. var s, t = this;
  6128. if (!t.tridentSel) {
  6129. s = t.getSel();
  6130. if (s) {
  6131. t.explicitRange = r;
  6132. try {
  6133. s.removeAllRanges();
  6134. } catch (ex) {
  6135. // IE9 might throw errors here don't know why
  6136. }
  6137. s.addRange(r);
  6138. t.selectedRange = s.getRangeAt(0);
  6139. }
  6140. } else {
  6141. // Is W3C Range
  6142. if (r.cloneRange) {
  6143. t.tridentSel.addRange(r);
  6144. return;
  6145. }
  6146. // Is IE specific range
  6147. try {
  6148. r.select();
  6149. } catch (ex) {
  6150. // Needed for some odd IE bug #1843306
  6151. }
  6152. }
  6153. },
  6154. setNode : function(n) {
  6155. var t = this;
  6156. t.setContent(t.dom.getOuterHTML(n));
  6157. return n;
  6158. },
  6159. getNode : function() {
  6160. var t = this, rng = t.getRng(), sel = t.getSel(), elm, start = rng.startContainer, end = rng.endContainer;
  6161. // Range maybe lost after the editor is made visible again
  6162. if (!rng)
  6163. return t.dom.getRoot();
  6164. if (rng.setStart) {
  6165. elm = rng.commonAncestorContainer;
  6166. // Handle selection a image or other control like element such as anchors
  6167. if (!rng.collapsed) {
  6168. if (rng.startContainer == rng.endContainer) {
  6169. if (rng.endOffset - rng.startOffset < 2) {
  6170. if (rng.startContainer.hasChildNodes())
  6171. elm = rng.startContainer.childNodes[rng.startOffset];
  6172. }
  6173. }
  6174. // If the anchor node is a element instead of a text node then return this element
  6175. //if (tinymce.isWebKit && sel.anchorNode && sel.anchorNode.nodeType == 1)
  6176. // return sel.anchorNode.childNodes[sel.anchorOffset];
  6177. // Handle cases where the selection is immediately wrapped around a node and return that node instead of it's parent.
  6178. // This happens when you double click an underlined word in FireFox.
  6179. if (start.nodeType === 3 && end.nodeType === 3) {
  6180. function skipEmptyTextNodes(n, forwards) {
  6181. var orig = n;
  6182. while (n && n.nodeType === 3 && n.length === 0) {
  6183. n = forwards ? n.nextSibling : n.previousSibling;
  6184. }
  6185. return n || orig;
  6186. }
  6187. if (start.length === rng.startOffset) {
  6188. start = skipEmptyTextNodes(start.nextSibling, true);
  6189. } else {
  6190. start = start.parentNode;
  6191. }
  6192. if (rng.endOffset === 0) {
  6193. end = skipEmptyTextNodes(end.previousSibling, false);
  6194. } else {
  6195. end = end.parentNode;
  6196. }
  6197. if (start && start === end)
  6198. return start;
  6199. }
  6200. }
  6201. if (elm && elm.nodeType == 3)
  6202. return elm.parentNode;
  6203. return elm;
  6204. }
  6205. return rng.item ? rng.item(0) : rng.parentElement();
  6206. },
  6207. getSelectedBlocks : function(st, en) {
  6208. var t = this, dom = t.dom, sb, eb, n, bl = [];
  6209. sb = dom.getParent(st || t.getStart(), dom.isBlock);
  6210. eb = dom.getParent(en || t.getEnd(), dom.isBlock);
  6211. if (sb)
  6212. bl.push(sb);
  6213. if (sb && eb && sb != eb) {
  6214. n = sb;
  6215. while ((n = n.nextSibling) && n != eb) {
  6216. if (dom.isBlock(n))
  6217. bl.push(n);
  6218. }
  6219. }
  6220. if (eb && sb != eb)
  6221. bl.push(eb);
  6222. return bl;
  6223. },
  6224. destroy : function(s) {
  6225. var t = this;
  6226. t.win = null;
  6227. // Manual destroy then remove unload handler
  6228. if (!s)
  6229. tinymce.removeUnload(t.destroy);
  6230. },
  6231. // IE has an issue where you can't select/move the caret by clicking outside the body if the document is in standards mode
  6232. _fixIESelection : function() {
  6233. var dom = this.dom, doc = dom.doc, body = doc.body, started, startRng, htmlElm;
  6234. // Make HTML element unselectable since we are going to handle selection by hand
  6235. doc.documentElement.unselectable = true;
  6236. // Return range from point or null if it failed
  6237. function rngFromPoint(x, y) {
  6238. var rng = body.createTextRange();
  6239. try {
  6240. rng.moveToPoint(x, y);
  6241. } catch (ex) {
  6242. // IE sometimes throws and exception, so lets just ignore it
  6243. rng = null;
  6244. }
  6245. return rng;
  6246. };
  6247. // Fires while the selection is changing
  6248. function selectionChange(e) {
  6249. var pointRng;
  6250. // Check if the button is down or not
  6251. if (e.button) {
  6252. // Create range from mouse position
  6253. pointRng = rngFromPoint(e.x, e.y);
  6254. if (pointRng) {
  6255. // Check if pointRange is before/after selection then change the endPoint
  6256. if (pointRng.compareEndPoints('StartToStart', startRng) > 0)
  6257. pointRng.setEndPoint('StartToStart', startRng);
  6258. else
  6259. pointRng.setEndPoint('EndToEnd', startRng);
  6260. pointRng.select();
  6261. }
  6262. } else
  6263. endSelection();
  6264. }
  6265. // Removes listeners
  6266. function endSelection() {
  6267. var rng = doc.selection.createRange();
  6268. // If the range is collapsed then use the last start range
  6269. if (startRng && !rng.item && rng.compareEndPoints('StartToEnd', rng) === 0)
  6270. startRng.select();
  6271. dom.unbind(doc, 'mouseup', endSelection);
  6272. dom.unbind(doc, 'mousemove', selectionChange);
  6273. startRng = started = 0;
  6274. };
  6275. // Detect when user selects outside BODY
  6276. dom.bind(doc, ['mousedown', 'contextmenu'], function(e) {
  6277. if (e.target.nodeName === 'HTML') {
  6278. if (started)
  6279. endSelection();
  6280. // Detect vertical scrollbar, since IE will fire a mousedown on the scrollbar and have target set as HTML
  6281. htmlElm = doc.documentElement;
  6282. if (htmlElm.scrollHeight > htmlElm.clientHeight)
  6283. return;
  6284. started = 1;
  6285. // Setup start position
  6286. startRng = rngFromPoint(e.x, e.y);
  6287. if (startRng) {
  6288. // Listen for selection change events
  6289. dom.bind(doc, 'mouseup', endSelection);
  6290. dom.bind(doc, 'mousemove', selectionChange);
  6291. dom.win.focus();
  6292. startRng.select();
  6293. }
  6294. }
  6295. });
  6296. }
  6297. });
  6298. })(tinymce);
  6299. (function(tinymce) {
  6300. tinymce.dom.Serializer = function(settings, dom, schema) {
  6301. var onPreProcess, onPostProcess, isIE = tinymce.isIE, each = tinymce.each, htmlParser;
  6302. // Support the old apply_source_formatting option
  6303. if (!settings.apply_source_formatting)
  6304. settings.indent = false;
  6305. settings.remove_trailing_brs = true;
  6306. // Default DOM and Schema if they are undefined
  6307. dom = dom || tinymce.DOM;
  6308. schema = schema || new tinymce.html.Schema(settings);
  6309. settings.entity_encoding = settings.entity_encoding || 'named';
  6310. onPreProcess = new tinymce.util.Dispatcher(self);
  6311. onPostProcess = new tinymce.util.Dispatcher(self);
  6312. htmlParser = new tinymce.html.DomParser(settings, schema);
  6313. // Convert move data-mce-src, data-mce-href and data-mce-style into nodes or process them if needed
  6314. htmlParser.addAttributeFilter('src,href,style', function(nodes, name) {
  6315. var i = nodes.length, node, value, internalName = 'data-mce-' + name, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope, undef;
  6316. while (i--) {
  6317. node = nodes[i];
  6318. value = node.attributes.map[internalName];
  6319. if (value !== undef) {
  6320. // Set external name to internal value and remove internal
  6321. node.attr(name, value.length > 0 ? value : null);
  6322. node.attr(internalName, null);
  6323. } else {
  6324. // No internal attribute found then convert the value we have in the DOM
  6325. value = node.attributes.map[name];
  6326. if (name === "style")
  6327. value = dom.serializeStyle(dom.parseStyle(value), node.name);
  6328. else if (urlConverter)
  6329. value = urlConverter.call(urlConverterScope, value, name, node.name);
  6330. node.attr(name, value.length > 0 ? value : null);
  6331. }
  6332. }
  6333. });
  6334. // Remove internal classes mceItem<..>
  6335. htmlParser.addAttributeFilter('class', function(nodes, name) {
  6336. var i = nodes.length, node, value;
  6337. while (i--) {
  6338. node = nodes[i];
  6339. value = node.attr('class').replace(/\s*mce(Item\w+|Selected)\s*/g, '');
  6340. node.attr('class', value.length > 0 ? value : null);
  6341. }
  6342. });
  6343. // Remove bookmark elements
  6344. htmlParser.addAttributeFilter('data-mce-type', function(nodes, name, args) {
  6345. var i = nodes.length, node;
  6346. while (i--) {
  6347. node = nodes[i];
  6348. if (node.attributes.map['data-mce-type'] === 'bookmark' && !args.cleanup)
  6349. node.remove();
  6350. }
  6351. });
  6352. // Force script into CDATA sections and remove the mce- prefix also add comments around styles
  6353. htmlParser.addNodeFilter('script,style', function(nodes, name) {
  6354. var i = nodes.length, node, value;
  6355. function trim(value) {
  6356. return value.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n')
  6357. .replace(/^[\r\n]*|[\r\n]*$/g, '')
  6358. .replace(/^\s*(\/\/\s*<!--|\/\/\s*<!\[CDATA\[|<!--|<!\[CDATA\[)[\r\n]*/g, '')
  6359. .replace(/\s*(\/\/\s*\]\]>|\/\/\s*-->|\]\]>|-->|\]\]-->)\s*$/g, '');
  6360. };
  6361. while (i--) {
  6362. node = nodes[i];
  6363. value = node.firstChild ? node.firstChild.value : '';
  6364. if (name === "script") {
  6365. // Remove mce- prefix from script elements
  6366. node.attr('type', (node.attr('type') || 'text/javascript').replace(/^mce\-/, ''));
  6367. if (value.length > 0)
  6368. node.firstChild.value = '// <![CDATA[\n' + trim(value) + '\n// ]]>';
  6369. } else {
  6370. if (value.length > 0)
  6371. node.firstChild.value = '<!--\n' + trim(value) + '\n-->';
  6372. }
  6373. }
  6374. });
  6375. // Convert comments to cdata and handle protected comments
  6376. htmlParser.addNodeFilter('#comment', function(nodes, name) {
  6377. var i = nodes.length, node;
  6378. while (i--) {
  6379. node = nodes[i];
  6380. if (node.value.indexOf('[CDATA[') === 0) {
  6381. node.name = '#cdata';
  6382. node.type = 4;
  6383. node.value = node.value.replace(/^\[CDATA\[|\]\]$/g, '');
  6384. } else if (node.value.indexOf('mce:protected ') === 0) {
  6385. node.name = "#text";
  6386. node.type = 3;
  6387. node.raw = true;
  6388. node.value = unescape(node.value).substr(14);
  6389. }
  6390. }
  6391. });
  6392. htmlParser.addNodeFilter('xml:namespace,input', function(nodes, name) {
  6393. var i = nodes.length, node;
  6394. while (i--) {
  6395. node = nodes[i];
  6396. if (node.type === 7)
  6397. node.remove();
  6398. else if (node.type === 1) {
  6399. if (name === "input" && !("type" in node.attributes.map))
  6400. node.attr('type', 'text');
  6401. }
  6402. }
  6403. });
  6404. // Fix list elements, TODO: Replace this later
  6405. if (settings.fix_list_elements) {
  6406. htmlParser.addNodeFilter('ul,ol', function(nodes, name) {
  6407. var i = nodes.length, node, parentNode;
  6408. while (i--) {
  6409. node = nodes[i];
  6410. parentNode = node.parent;
  6411. if (parentNode.name === 'ul' || parentNode.name === 'ol') {
  6412. if (node.prev && node.prev.name === 'li') {
  6413. node.prev.append(node);
  6414. }
  6415. }
  6416. }
  6417. });
  6418. }
  6419. // Remove internal data attributes
  6420. htmlParser.addAttributeFilter('data-mce-src,data-mce-href,data-mce-style', function(nodes, name) {
  6421. var i = nodes.length;
  6422. while (i--) {
  6423. nodes[i].attr(name, null);
  6424. }
  6425. });
  6426. // Return public methods
  6427. return {
  6428. schema : schema,
  6429. addNodeFilter : htmlParser.addNodeFilter,
  6430. addAttributeFilter : htmlParser.addAttributeFilter,
  6431. onPreProcess : onPreProcess,
  6432. onPostProcess : onPostProcess,
  6433. serialize : function(node, args) {
  6434. var impl, doc, oldDoc, htmlSerializer, content;
  6435. // Explorer won't clone contents of script and style and the
  6436. // selected index of select elements are cleared on a clone operation.
  6437. if (isIE && dom.select('script,style,select').length > 0) {
  6438. content = node.innerHTML;
  6439. node = node.cloneNode(false);
  6440. dom.setHTML(node, content);
  6441. } else
  6442. node = node.cloneNode(true);
  6443. // Nodes needs to be attached to something in WebKit/Opera
  6444. // Older builds of Opera crashes if you attach the node to an document created dynamically
  6445. // and since we can't feature detect a crash we need to sniff the acutal build number
  6446. // This fix will make DOM ranges and make Sizzle happy!
  6447. impl = node.ownerDocument.implementation;
  6448. if (impl.createHTMLDocument) {
  6449. // Create an empty HTML document
  6450. doc = impl.createHTMLDocument("");
  6451. // Add the element or it's children if it's a body element to the new document
  6452. each(node.nodeName == 'BODY' ? node.childNodes : [node], function(node) {
  6453. doc.body.appendChild(doc.importNode(node, true));
  6454. });
  6455. // Grab first child or body element for serialization
  6456. if (node.nodeName != 'BODY')
  6457. node = doc.body.firstChild;
  6458. else
  6459. node = doc.body;
  6460. // set the new document in DOMUtils so createElement etc works
  6461. oldDoc = dom.doc;
  6462. dom.doc = doc;
  6463. }
  6464. args = args || {};
  6465. args.format = args.format || 'html';
  6466. // Pre process
  6467. if (!args.no_events) {
  6468. args.node = node;
  6469. onPreProcess.dispatch(self, args);
  6470. }
  6471. // Setup serializer
  6472. htmlSerializer = new tinymce.html.Serializer(settings, schema);
  6473. // Parse and serialize HTML
  6474. args.content = htmlSerializer.serialize(
  6475. htmlParser.parse(args.getInner ? node.innerHTML : tinymce.trim(dom.getOuterHTML(node), args), args)
  6476. );
  6477. // Replace all BOM characters for now until we can find a better solution
  6478. if (!args.cleanup)
  6479. args.content = args.content.replace(/\uFEFF/g, '');
  6480. // Post process
  6481. if (!args.no_events)
  6482. onPostProcess.dispatch(self, args);
  6483. // Restore the old document if it was changed
  6484. if (oldDoc)
  6485. dom.doc = oldDoc;
  6486. args.node = null;
  6487. return args.content;
  6488. },
  6489. addRules : function(rules) {
  6490. schema.addValidElements(rules);
  6491. },
  6492. setRules : function(rules) {
  6493. schema.setValidElements(rules);
  6494. }
  6495. };
  6496. };
  6497. })(tinymce);
  6498. (function(tinymce) {
  6499. tinymce.dom.ScriptLoader = function(settings) {
  6500. var QUEUED = 0,
  6501. LOADING = 1,
  6502. LOADED = 2,
  6503. states = {},
  6504. queue = [],
  6505. scriptLoadedCallbacks = {},
  6506. queueLoadedCallbacks = [],
  6507. loading = 0,
  6508. undefined;
  6509. function loadScript(url, callback) {
  6510. var t = this, dom = tinymce.DOM, elm, uri, loc, id;
  6511. // Execute callback when script is loaded
  6512. function done() {
  6513. dom.remove(id);
  6514. if (elm)
  6515. elm.onreadystatechange = elm.onload = elm = null;
  6516. callback();
  6517. };
  6518. function error() {
  6519. // Report the error so it's easier for people to spot loading errors
  6520. if (typeof(console) !== "undefined" && console.log)
  6521. console.log("Failed to load: " + url);
  6522. // We can't mark it as done if there is a load error since
  6523. // A) We don't want to produce 404 errors on the server and
  6524. // B) the onerror event won't fire on all browsers.
  6525. // done();
  6526. };
  6527. id = dom.uniqueId();
  6528. if (tinymce.isIE6) {
  6529. uri = new tinymce.util.URI(url);
  6530. loc = location;
  6531. // If script is from same domain and we
  6532. // use IE 6 then use XHR since it's more reliable
  6533. if (uri.host == loc.hostname && uri.port == loc.port && (uri.protocol + ':') == loc.protocol && uri.protocol.toLowerCase() != 'file') {
  6534. tinymce.util.XHR.send({
  6535. url : tinymce._addVer(uri.getURI()),
  6536. success : function(content) {
  6537. // Create new temp script element
  6538. var script = dom.create('script', {
  6539. type : 'text/javascript'
  6540. });
  6541. // Evaluate script in global scope
  6542. script.text = content;
  6543. document.getElementsByTagName('head')[0].appendChild(script);
  6544. dom.remove(script);
  6545. done();
  6546. },
  6547. error : error
  6548. });
  6549. return;
  6550. }
  6551. }
  6552. // Create new script element
  6553. elm = dom.create('script', {
  6554. id : id,
  6555. type : 'text/javascript',
  6556. src : tinymce._addVer(url)
  6557. });
  6558. // Add onload listener for non IE browsers since IE9
  6559. // fires onload event before the script is parsed and executed
  6560. if (!tinymce.isIE)
  6561. elm.onload = done;
  6562. // Add onerror event will get fired on some browsers but not all of them
  6563. elm.onerror = error;
  6564. // Opera 9.60 doesn't seem to fire the onreadystate event at correctly
  6565. if (!tinymce.isOpera) {
  6566. elm.onreadystatechange = function() {
  6567. var state = elm.readyState;
  6568. // Loaded state is passed on IE 6 however there
  6569. // are known issues with this method but we can't use
  6570. // XHR in a cross domain loading
  6571. if (state == 'complete' || state == 'loaded')
  6572. done();
  6573. };
  6574. }
  6575. // Most browsers support this feature so we report errors
  6576. // for those at least to help users track their missing plugins etc
  6577. // todo: Removed since it produced error if the document is unloaded by navigating away, re-add it as an option
  6578. /*elm.onerror = function() {
  6579. alert('Failed to load: ' + url);
  6580. };*/
  6581. // Add script to document
  6582. (document.getElementsByTagName('head')[0] || document.body).appendChild(elm);
  6583. };
  6584. this.isDone = function(url) {
  6585. return states[url] == LOADED;
  6586. };
  6587. this.markDone = function(url) {
  6588. states[url] = LOADED;
  6589. };
  6590. this.add = this.load = function(url, callback, scope) {
  6591. var item, state = states[url];
  6592. // Add url to load queue
  6593. if (state == undefined) {
  6594. queue.push(url);
  6595. states[url] = QUEUED;
  6596. }
  6597. if (callback) {
  6598. // Store away callback for later execution
  6599. if (!scriptLoadedCallbacks[url])
  6600. scriptLoadedCallbacks[url] = [];
  6601. scriptLoadedCallbacks[url].push({
  6602. func : callback,
  6603. scope : scope || this
  6604. });
  6605. }
  6606. };
  6607. this.loadQueue = function(callback, scope) {
  6608. this.loadScripts(queue, callback, scope);
  6609. };
  6610. this.loadScripts = function(scripts, callback, scope) {
  6611. var loadScripts;
  6612. function execScriptLoadedCallbacks(url) {
  6613. // Execute URL callback functions
  6614. tinymce.each(scriptLoadedCallbacks[url], function(callback) {
  6615. callback.func.call(callback.scope);
  6616. });
  6617. scriptLoadedCallbacks[url] = undefined;
  6618. };
  6619. queueLoadedCallbacks.push({
  6620. func : callback,
  6621. scope : scope || this
  6622. });
  6623. loadScripts = function() {
  6624. var loadingScripts = tinymce.grep(scripts);
  6625. // Current scripts has been handled
  6626. scripts.length = 0;
  6627. // Load scripts that needs to be loaded
  6628. tinymce.each(loadingScripts, function(url) {
  6629. // Script is already loaded then execute script callbacks directly
  6630. if (states[url] == LOADED) {
  6631. execScriptLoadedCallbacks(url);
  6632. return;
  6633. }
  6634. // Is script not loading then start loading it
  6635. if (states[url] != LOADING) {
  6636. states[url] = LOADING;
  6637. loading++;
  6638. loadScript(url, function() {
  6639. states[url] = LOADED;
  6640. loading--;
  6641. execScriptLoadedCallbacks(url);
  6642. // Load more scripts if they where added by the recently loaded script
  6643. loadScripts();
  6644. });
  6645. }
  6646. });
  6647. // No scripts are currently loading then execute all pending queue loaded callbacks
  6648. if (!loading) {
  6649. tinymce.each(queueLoadedCallbacks, function(callback) {
  6650. callback.func.call(callback.scope);
  6651. });
  6652. queueLoadedCallbacks.length = 0;
  6653. }
  6654. };
  6655. loadScripts();
  6656. };
  6657. };
  6658. // Global script loader
  6659. tinymce.ScriptLoader = new tinymce.dom.ScriptLoader();
  6660. })(tinymce);
  6661. tinymce.dom.TreeWalker = function(start_node, root_node) {
  6662. var node = start_node;
  6663. function findSibling(node, start_name, sibling_name, shallow) {
  6664. var sibling, parent;
  6665. if (node) {
  6666. // Walk into nodes if it has a start
  6667. if (!shallow && node[start_name])
  6668. return node[start_name];
  6669. // Return the sibling if it has one
  6670. if (node != root_node) {
  6671. sibling = node[sibling_name];
  6672. if (sibling)
  6673. return sibling;
  6674. // Walk up the parents to look for siblings
  6675. for (parent = node.parentNode; parent && parent != root_node; parent = parent.parentNode) {
  6676. sibling = parent[sibling_name];
  6677. if (sibling)
  6678. return sibling;
  6679. }
  6680. }
  6681. }
  6682. };
  6683. this.current = function() {
  6684. return node;
  6685. };
  6686. this.next = function(shallow) {
  6687. return (node = findSibling(node, 'firstChild', 'nextSibling', shallow));
  6688. };
  6689. this.prev = function(shallow) {
  6690. return (node = findSibling(node, 'lastChild', 'previousSibling', shallow));
  6691. };
  6692. };
  6693. (function(tinymce) {
  6694. tinymce.dom.RangeUtils = function(dom) {
  6695. var INVISIBLE_CHAR = '\uFEFF';
  6696. this.walk = function(rng, callback) {
  6697. var startContainer = rng.startContainer,
  6698. startOffset = rng.startOffset,
  6699. endContainer = rng.endContainer,
  6700. endOffset = rng.endOffset,
  6701. ancestor, startPoint,
  6702. endPoint, node, parent, siblings, nodes;
  6703. // Handle table cell selection the table plugin enables
  6704. // you to fake select table cells and perform formatting actions on them
  6705. nodes = dom.select('td.mceSelected,th.mceSelected');
  6706. if (nodes.length > 0) {
  6707. tinymce.each(nodes, function(node) {
  6708. callback([node]);
  6709. });
  6710. return;
  6711. }
  6712. function collectSiblings(node, name, end_node) {
  6713. var siblings = [];
  6714. for (; node && node != end_node; node = node[name])
  6715. siblings.push(node);
  6716. return siblings;
  6717. };
  6718. function findEndPoint(node, root) {
  6719. do {
  6720. if (node.parentNode == root)
  6721. return node;
  6722. node = node.parentNode;
  6723. } while(node);
  6724. };
  6725. function walkBoundary(start_node, end_node, next) {
  6726. var siblingName = next ? 'nextSibling' : 'previousSibling';
  6727. for (node = start_node, parent = node.parentNode; node && node != end_node; node = parent) {
  6728. parent = node.parentNode;
  6729. siblings = collectSiblings(node == start_node ? node : node[siblingName], siblingName);
  6730. if (siblings.length) {
  6731. if (!next)
  6732. siblings.reverse();
  6733. callback(siblings);
  6734. }
  6735. }
  6736. };
  6737. // If index based start position then resolve it
  6738. if (startContainer.nodeType == 1 && startContainer.hasChildNodes())
  6739. startContainer = startContainer.childNodes[startOffset];
  6740. // If index based end position then resolve it
  6741. if (endContainer.nodeType == 1 && endContainer.hasChildNodes())
  6742. endContainer = endContainer.childNodes[Math.min(endOffset - 1, endContainer.childNodes.length - 1)];
  6743. // Find common ancestor and end points
  6744. ancestor = dom.findCommonAncestor(startContainer, endContainer);
  6745. // Same container
  6746. if (startContainer == endContainer)
  6747. return callback([startContainer]);
  6748. // Process left side
  6749. for (node = startContainer; node; node = node.parentNode) {
  6750. if (node == endContainer)
  6751. return walkBoundary(startContainer, ancestor, true);
  6752. if (node == ancestor)
  6753. break;
  6754. }
  6755. // Process right side
  6756. for (node = endContainer; node; node = node.parentNode) {
  6757. if (node == startContainer)
  6758. return walkBoundary(endContainer, ancestor);
  6759. if (node == ancestor)
  6760. break;
  6761. }
  6762. // Find start/end point
  6763. startPoint = findEndPoint(startContainer, ancestor) || startContainer;
  6764. endPoint = findEndPoint(endContainer, ancestor) || endContainer;
  6765. // Walk left leaf
  6766. walkBoundary(startContainer, startPoint, true);
  6767. // Walk the middle from start to end point
  6768. siblings = collectSiblings(
  6769. startPoint == startContainer ? startPoint : startPoint.nextSibling,
  6770. 'nextSibling',
  6771. endPoint == endContainer ? endPoint.nextSibling : endPoint
  6772. );
  6773. if (siblings.length)
  6774. callback(siblings);
  6775. // Walk right leaf
  6776. walkBoundary(endContainer, endPoint);
  6777. };
  6778. /* this.split = function(rng) {
  6779. var startContainer = rng.startContainer,
  6780. startOffset = rng.startOffset,
  6781. endContainer = rng.endContainer,
  6782. endOffset = rng.endOffset;
  6783. function splitText(node, offset) {
  6784. if (offset == node.nodeValue.length)
  6785. node.appendData(INVISIBLE_CHAR);
  6786. node = node.splitText(offset);
  6787. if (node.nodeValue === INVISIBLE_CHAR)
  6788. node.nodeValue = '';
  6789. return node;
  6790. };
  6791. // Handle single text node
  6792. if (startContainer == endContainer) {
  6793. if (startContainer.nodeType == 3) {
  6794. if (startOffset != 0)
  6795. startContainer = endContainer = splitText(startContainer, startOffset);
  6796. if (endOffset - startOffset != startContainer.nodeValue.length)
  6797. splitText(startContainer, endOffset - startOffset);
  6798. }
  6799. } else {
  6800. // Split startContainer text node if needed
  6801. if (startContainer.nodeType == 3 && startOffset != 0) {
  6802. startContainer = splitText(startContainer, startOffset);
  6803. startOffset = 0;
  6804. }
  6805. // Split endContainer text node if needed
  6806. if (endContainer.nodeType == 3 && endOffset != endContainer.nodeValue.length) {
  6807. endContainer = splitText(endContainer, endOffset).previousSibling;
  6808. endOffset = endContainer.nodeValue.length;
  6809. }
  6810. }
  6811. return {
  6812. startContainer : startContainer,
  6813. startOffset : startOffset,
  6814. endContainer : endContainer,
  6815. endOffset : endOffset
  6816. };
  6817. };
  6818. */
  6819. };
  6820. tinymce.dom.RangeUtils.compareRanges = function(rng1, rng2) {
  6821. if (rng1 && rng2) {
  6822. // Compare native IE ranges
  6823. if (rng1.item || rng1.duplicate) {
  6824. // Both are control ranges and the selected element matches
  6825. if (rng1.item && rng2.item && rng1.item(0) === rng2.item(0))
  6826. return true;
  6827. // Both are text ranges and the range matches
  6828. if (rng1.isEqual && rng2.isEqual && rng2.isEqual(rng1))
  6829. return true;
  6830. } else {
  6831. // Compare w3c ranges
  6832. return rng1.startContainer == rng2.startContainer && rng1.startOffset == rng2.startOffset;
  6833. }
  6834. }
  6835. return false;
  6836. };
  6837. })(tinymce);
  6838. (function(tinymce) {
  6839. var Event = tinymce.dom.Event, each = tinymce.each;
  6840. tinymce.create('tinymce.ui.KeyboardNavigation', {
  6841. KeyboardNavigation: function(settings, dom) {
  6842. var t = this, root = settings.root, items = settings.items,
  6843. enableUpDown = settings.enableUpDown, enableLeftRight = settings.enableLeftRight || !settings.enableUpDown,
  6844. excludeFromTabOrder = settings.excludeFromTabOrder,
  6845. itemFocussed, itemBlurred, rootKeydown, rootFocussed, focussedId;
  6846. dom = dom || tinymce.DOM;
  6847. itemFocussed = function(evt) {
  6848. focussedId = evt.target.id;
  6849. };
  6850. itemBlurred = function(evt) {
  6851. dom.setAttrib(evt.target.id, 'tabindex', '-1');
  6852. };
  6853. rootFocussed = function(evt) {
  6854. var item = dom.get(focussedId);
  6855. dom.setAttrib(item, 'tabindex', '0');
  6856. item.focus();
  6857. };
  6858. t.focus = function() {
  6859. dom.get(focussedId).focus();
  6860. };
  6861. t.destroy = function() {
  6862. each(items, function(item) {
  6863. dom.unbind(dom.get(item.id), 'focus', itemFocussed);
  6864. dom.unbind(dom.get(item.id), 'blur', itemBlurred);
  6865. });
  6866. dom.unbind(dom.get(root), 'focus', rootFocussed);
  6867. dom.unbind(dom.get(root), 'keydown', rootKeydown);
  6868. items = dom = root = t.focus = itemFocussed = itemBlurred = rootKeydown = rootFocussed = null;
  6869. t.destroy = function() {};
  6870. };
  6871. t.moveFocus = function(dir, evt) {
  6872. var idx = -1, controls = t.controls, newFocus;
  6873. if (!focussedId)
  6874. return;
  6875. each(items, function(item, index) {
  6876. if (item.id === focussedId) {
  6877. idx = index;
  6878. return false;
  6879. }
  6880. });
  6881. idx += dir;
  6882. if (idx < 0) {
  6883. idx = items.length - 1;
  6884. } else if (idx >= items.length) {
  6885. idx = 0;
  6886. }
  6887. newFocus = items[idx];
  6888. dom.setAttrib(focussedId, 'tabindex', '-1');
  6889. dom.setAttrib(newFocus.id, 'tabindex', '0');
  6890. dom.get(newFocus.id).focus();
  6891. if (settings.actOnFocus) {
  6892. settings.onAction(newFocus.id);
  6893. }
  6894. if (evt)
  6895. Event.cancel(evt);
  6896. };
  6897. rootKeydown = function(evt) {
  6898. 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;
  6899. switch (evt.keyCode) {
  6900. case DOM_VK_LEFT:
  6901. if (enableLeftRight) t.moveFocus(-1);
  6902. break;
  6903. case DOM_VK_RIGHT:
  6904. if (enableLeftRight) t.moveFocus(1);
  6905. break;
  6906. case DOM_VK_UP:
  6907. if (enableUpDown) t.moveFocus(-1);
  6908. break;
  6909. case DOM_VK_DOWN:
  6910. if (enableUpDown) t.moveFocus(1);
  6911. break;
  6912. case DOM_VK_ESCAPE:
  6913. if (settings.onCancel) {
  6914. settings.onCancel();
  6915. Event.cancel(evt);
  6916. }
  6917. break;
  6918. case DOM_VK_ENTER:
  6919. case DOM_VK_RETURN:
  6920. case DOM_VK_SPACE:
  6921. if (settings.onAction) {
  6922. settings.onAction(focussedId);
  6923. Event.cancel(evt);
  6924. }
  6925. break;
  6926. }
  6927. };
  6928. // Set up state and listeners for each item.
  6929. each(items, function(item, idx) {
  6930. var tabindex;
  6931. if (!item.id) {
  6932. item.id = dom.uniqueId('_mce_item_');
  6933. }
  6934. if (excludeFromTabOrder) {
  6935. dom.bind(item.id, 'blur', itemBlurred);
  6936. tabindex = '-1';
  6937. } else {
  6938. tabindex = (idx === 0 ? '0' : '-1');
  6939. }
  6940. dom.setAttrib(item.id, 'tabindex', tabindex);
  6941. dom.bind(dom.get(item.id), 'focus', itemFocussed);
  6942. });
  6943. // Setup initial state for root element.
  6944. if (items[0]){
  6945. focussedId = items[0].id;
  6946. }
  6947. dom.setAttrib(root, 'tabindex', '-1');
  6948. // Setup listeners for root element.
  6949. dom.bind(dom.get(root), 'focus', rootFocussed);
  6950. dom.bind(dom.get(root), 'keydown', rootKeydown);
  6951. }
  6952. });
  6953. })(tinymce);
  6954. (function(tinymce) {
  6955. // Shorten class names
  6956. var DOM = tinymce.DOM, is = tinymce.is;
  6957. tinymce.create('tinymce.ui.Control', {
  6958. Control : function(id, s, editor) {
  6959. this.id = id;
  6960. this.settings = s = s || {};
  6961. this.rendered = false;
  6962. this.onRender = new tinymce.util.Dispatcher(this);
  6963. this.classPrefix = '';
  6964. this.scope = s.scope || this;
  6965. this.disabled = 0;
  6966. this.active = 0;
  6967. this.editor = editor;
  6968. },
  6969. setAriaProperty : function(property, value) {
  6970. var element = DOM.get(this.id + '_aria') || DOM.get(this.id);
  6971. if (element) {
  6972. DOM.setAttrib(element, 'aria-' + property, !!value);
  6973. }
  6974. },
  6975. focus : function() {
  6976. DOM.get(this.id).focus();
  6977. },
  6978. setDisabled : function(s) {
  6979. if (s != this.disabled) {
  6980. this.setAriaProperty('disabled', s);
  6981. this.setState('Disabled', s);
  6982. this.setState('Enabled', !s);
  6983. this.disabled = s;
  6984. }
  6985. },
  6986. isDisabled : function() {
  6987. return this.disabled;
  6988. },
  6989. setActive : function(s) {
  6990. if (s != this.active) {
  6991. this.setState('Active', s);
  6992. this.active = s;
  6993. this.setAriaProperty('pressed', s);
  6994. }
  6995. },
  6996. isActive : function() {
  6997. return this.active;
  6998. },
  6999. setState : function(c, s) {
  7000. var n = DOM.get(this.id);
  7001. c = this.classPrefix + c;
  7002. if (s)
  7003. DOM.addClass(n, c);
  7004. else
  7005. DOM.removeClass(n, c);
  7006. },
  7007. isRendered : function() {
  7008. return this.rendered;
  7009. },
  7010. renderHTML : function() {
  7011. },
  7012. renderTo : function(n) {
  7013. DOM.setHTML(n, this.renderHTML());
  7014. },
  7015. postRender : function() {
  7016. var t = this, b;
  7017. // Set pending states
  7018. if (is(t.disabled)) {
  7019. b = t.disabled;
  7020. t.disabled = -1;
  7021. t.setDisabled(b);
  7022. }
  7023. if (is(t.active)) {
  7024. b = t.active;
  7025. t.active = -1;
  7026. t.setActive(b);
  7027. }
  7028. },
  7029. remove : function() {
  7030. DOM.remove(this.id);
  7031. this.destroy();
  7032. },
  7033. destroy : function() {
  7034. tinymce.dom.Event.clear(this.id);
  7035. }
  7036. });
  7037. })(tinymce);
  7038. tinymce.create('tinymce.ui.Container:tinymce.ui.Control', {
  7039. Container : function(id, s, editor) {
  7040. this.parent(id, s, editor);
  7041. this.controls = [];
  7042. this.lookup = {};
  7043. },
  7044. add : function(c) {
  7045. this.lookup[c.id] = c;
  7046. this.controls.push(c);
  7047. return c;
  7048. },
  7049. get : function(n) {
  7050. return this.lookup[n];
  7051. }
  7052. });
  7053. tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', {
  7054. Separator : function(id, s) {
  7055. this.parent(id, s);
  7056. this.classPrefix = 'mceSeparator';
  7057. this.setDisabled(true);
  7058. },
  7059. renderHTML : function() {
  7060. return tinymce.DOM.createHTML('span', {'class' : this.classPrefix, role : 'separator', 'aria-orientation' : 'vertical', tabindex : '-1'});
  7061. }
  7062. });
  7063. (function(tinymce) {
  7064. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  7065. tinymce.create('tinymce.ui.MenuItem:tinymce.ui.Control', {
  7066. MenuItem : function(id, s) {
  7067. this.parent(id, s);
  7068. this.classPrefix = 'mceMenuItem';
  7069. },
  7070. setSelected : function(s) {
  7071. this.setState('Selected', s);
  7072. this.setAriaProperty('checked', !!s);
  7073. this.selected = s;
  7074. },
  7075. isSelected : function() {
  7076. return this.selected;
  7077. },
  7078. postRender : function() {
  7079. var t = this;
  7080. t.parent();
  7081. // Set pending state
  7082. if (is(t.selected))
  7083. t.setSelected(t.selected);
  7084. }
  7085. });
  7086. })(tinymce);
  7087. (function(tinymce) {
  7088. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  7089. tinymce.create('tinymce.ui.Menu:tinymce.ui.MenuItem', {
  7090. Menu : function(id, s) {
  7091. var t = this;
  7092. t.parent(id, s);
  7093. t.items = {};
  7094. t.collapsed = false;
  7095. t.menuCount = 0;
  7096. t.onAddItem = new tinymce.util.Dispatcher(this);
  7097. },
  7098. expand : function(d) {
  7099. var t = this;
  7100. if (d) {
  7101. walk(t, function(o) {
  7102. if (o.expand)
  7103. o.expand();
  7104. }, 'items', t);
  7105. }
  7106. t.collapsed = false;
  7107. },
  7108. collapse : function(d) {
  7109. var t = this;
  7110. if (d) {
  7111. walk(t, function(o) {
  7112. if (o.collapse)
  7113. o.collapse();
  7114. }, 'items', t);
  7115. }
  7116. t.collapsed = true;
  7117. },
  7118. isCollapsed : function() {
  7119. return this.collapsed;
  7120. },
  7121. add : function(o) {
  7122. if (!o.settings)
  7123. o = new tinymce.ui.MenuItem(o.id || DOM.uniqueId(), o);
  7124. this.onAddItem.dispatch(this, o);
  7125. return this.items[o.id] = o;
  7126. },
  7127. addSeparator : function() {
  7128. return this.add({separator : true});
  7129. },
  7130. addMenu : function(o) {
  7131. if (!o.collapse)
  7132. o = this.createMenu(o);
  7133. this.menuCount++;
  7134. return this.add(o);
  7135. },
  7136. hasMenus : function() {
  7137. return this.menuCount !== 0;
  7138. },
  7139. remove : function(o) {
  7140. delete this.items[o.id];
  7141. },
  7142. removeAll : function() {
  7143. var t = this;
  7144. walk(t, function(o) {
  7145. if (o.removeAll)
  7146. o.removeAll();
  7147. else
  7148. o.remove();
  7149. o.destroy();
  7150. }, 'items', t);
  7151. t.items = {};
  7152. },
  7153. createMenu : function(o) {
  7154. var m = new tinymce.ui.Menu(o.id || DOM.uniqueId(), o);
  7155. m.onAddItem.add(this.onAddItem.dispatch, this.onAddItem);
  7156. return m;
  7157. }
  7158. });
  7159. })(tinymce);
  7160. (function(tinymce) {
  7161. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event, Element = tinymce.dom.Element;
  7162. tinymce.create('tinymce.ui.DropMenu:tinymce.ui.Menu', {
  7163. DropMenu : function(id, s) {
  7164. s = s || {};
  7165. s.container = s.container || DOM.doc.body;
  7166. s.offset_x = s.offset_x || 0;
  7167. s.offset_y = s.offset_y || 0;
  7168. s.vp_offset_x = s.vp_offset_x || 0;
  7169. s.vp_offset_y = s.vp_offset_y || 0;
  7170. if (is(s.icons) && !s.icons)
  7171. s['class'] += ' mceNoIcons';
  7172. this.parent(id, s);
  7173. this.onShowMenu = new tinymce.util.Dispatcher(this);
  7174. this.onHideMenu = new tinymce.util.Dispatcher(this);
  7175. this.classPrefix = 'mceMenu';
  7176. },
  7177. createMenu : function(s) {
  7178. var t = this, cs = t.settings, m;
  7179. s.container = s.container || cs.container;
  7180. s.parent = t;
  7181. s.constrain = s.constrain || cs.constrain;
  7182. s['class'] = s['class'] || cs['class'];
  7183. s.vp_offset_x = s.vp_offset_x || cs.vp_offset_x;
  7184. s.vp_offset_y = s.vp_offset_y || cs.vp_offset_y;
  7185. s.keyboard_focus = cs.keyboard_focus;
  7186. m = new tinymce.ui.DropMenu(s.id || DOM.uniqueId(), s);
  7187. m.onAddItem.add(t.onAddItem.dispatch, t.onAddItem);
  7188. return m;
  7189. },
  7190. focus : function() {
  7191. var t = this;
  7192. if (t.keyboardNav) {
  7193. t.keyboardNav.focus();
  7194. }
  7195. },
  7196. update : function() {
  7197. var t = this, s = t.settings, tb = DOM.get('menu_' + t.id + '_tbl'), co = DOM.get('menu_' + t.id + '_co'), tw, th;
  7198. tw = s.max_width ? Math.min(tb.clientWidth, s.max_width) : tb.clientWidth;
  7199. th = s.max_height ? Math.min(tb.clientHeight, s.max_height) : tb.clientHeight;
  7200. if (!DOM.boxModel)
  7201. t.element.setStyles({width : tw + 2, height : th + 2});
  7202. else
  7203. t.element.setStyles({width : tw, height : th});
  7204. if (s.max_width)
  7205. DOM.setStyle(co, 'width', tw);
  7206. if (s.max_height) {
  7207. DOM.setStyle(co, 'height', th);
  7208. if (tb.clientHeight < s.max_height)
  7209. DOM.setStyle(co, 'overflow', 'hidden');
  7210. }
  7211. },
  7212. showMenu : function(x, y, px) {
  7213. var t = this, s = t.settings, co, vp = DOM.getViewPort(), w, h, mx, my, ot = 2, dm, tb, cp = t.classPrefix;
  7214. t.collapse(1);
  7215. if (t.isMenuVisible)
  7216. return;
  7217. if (!t.rendered) {
  7218. co = DOM.add(t.settings.container, t.renderNode());
  7219. each(t.items, function(o) {
  7220. o.postRender();
  7221. });
  7222. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  7223. } else
  7224. co = DOM.get('menu_' + t.id);
  7225. // Move layer out of sight unless it's Opera since it scrolls to top of page due to an bug
  7226. if (!tinymce.isOpera)
  7227. DOM.setStyles(co, {left : -0xFFFF , top : -0xFFFF});
  7228. DOM.show(co);
  7229. t.update();
  7230. x += s.offset_x || 0;
  7231. y += s.offset_y || 0;
  7232. vp.w -= 4;
  7233. vp.h -= 4;
  7234. // Move inside viewport if not submenu
  7235. if (s.constrain) {
  7236. w = co.clientWidth - ot;
  7237. h = co.clientHeight - ot;
  7238. mx = vp.x + vp.w;
  7239. my = vp.y + vp.h;
  7240. if ((x + s.vp_offset_x + w) > mx)
  7241. x = px ? px - w : Math.max(0, (mx - s.vp_offset_x) - w);
  7242. if ((y + s.vp_offset_y + h) > my)
  7243. y = Math.max(0, (my - s.vp_offset_y) - h);
  7244. }
  7245. DOM.setStyles(co, {left : x , top : y});
  7246. t.element.update();
  7247. t.isMenuVisible = 1;
  7248. t.mouseClickFunc = Event.add(co, 'click', function(e) {
  7249. var m;
  7250. e = e.target;
  7251. if (e && (e = DOM.getParent(e, 'tr')) && !DOM.hasClass(e, cp + 'ItemSub')) {
  7252. m = t.items[e.id];
  7253. if (m.isDisabled())
  7254. return;
  7255. dm = t;
  7256. while (dm) {
  7257. if (dm.hideMenu)
  7258. dm.hideMenu();
  7259. dm = dm.settings.parent;
  7260. }
  7261. if (m.settings.onclick)
  7262. m.settings.onclick(e);
  7263. return Event.cancel(e); // Cancel to fix onbeforeunload problem
  7264. }
  7265. });
  7266. if (t.hasMenus()) {
  7267. t.mouseOverFunc = Event.add(co, 'mouseover', function(e) {
  7268. var m, r, mi;
  7269. e = e.target;
  7270. if (e && (e = DOM.getParent(e, 'tr'))) {
  7271. m = t.items[e.id];
  7272. if (t.lastMenu)
  7273. t.lastMenu.collapse(1);
  7274. if (m.isDisabled())
  7275. return;
  7276. if (e && DOM.hasClass(e, cp + 'ItemSub')) {
  7277. //p = DOM.getPos(s.container);
  7278. r = DOM.getRect(e);
  7279. m.showMenu((r.x + r.w - ot), r.y - ot, r.x);
  7280. t.lastMenu = m;
  7281. DOM.addClass(DOM.get(m.id).firstChild, cp + 'ItemActive');
  7282. }
  7283. }
  7284. });
  7285. }
  7286. Event.add(co, 'keydown', t._keyHandler, t);
  7287. t.onShowMenu.dispatch(t);
  7288. if (s.keyboard_focus) {
  7289. t._setupKeyboardNav();
  7290. }
  7291. },
  7292. hideMenu : function(c) {
  7293. var t = this, co = DOM.get('menu_' + t.id), e;
  7294. if (!t.isMenuVisible)
  7295. return;
  7296. if (t.keyboardNav) t.keyboardNav.destroy();
  7297. Event.remove(co, 'mouseover', t.mouseOverFunc);
  7298. Event.remove(co, 'click', t.mouseClickFunc);
  7299. Event.remove(co, 'keydown', t._keyHandler);
  7300. DOM.hide(co);
  7301. t.isMenuVisible = 0;
  7302. if (!c)
  7303. t.collapse(1);
  7304. if (t.element)
  7305. t.element.hide();
  7306. if (e = DOM.get(t.id))
  7307. DOM.removeClass(e.firstChild, t.classPrefix + 'ItemActive');
  7308. t.onHideMenu.dispatch(t);
  7309. },
  7310. add : function(o) {
  7311. var t = this, co;
  7312. o = t.parent(o);
  7313. if (t.isRendered && (co = DOM.get('menu_' + t.id)))
  7314. t._add(DOM.select('tbody', co)[0], o);
  7315. return o;
  7316. },
  7317. collapse : function(d) {
  7318. this.parent(d);
  7319. this.hideMenu(1);
  7320. },
  7321. remove : function(o) {
  7322. DOM.remove(o.id);
  7323. this.destroy();
  7324. return this.parent(o);
  7325. },
  7326. destroy : function() {
  7327. var t = this, co = DOM.get('menu_' + t.id);
  7328. if (t.keyboardNav) t.keyboardNav.destroy();
  7329. Event.remove(co, 'mouseover', t.mouseOverFunc);
  7330. Event.remove(DOM.select('a', co), 'focus', t.mouseOverFunc);
  7331. Event.remove(co, 'click', t.mouseClickFunc);
  7332. Event.remove(co, 'keydown', t._keyHandler);
  7333. if (t.element)
  7334. t.element.remove();
  7335. DOM.remove(co);
  7336. },
  7337. renderNode : function() {
  7338. var t = this, s = t.settings, n, tb, co, w;
  7339. 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'});
  7340. if (t.settings.parent) {
  7341. DOM.setAttrib(w, 'aria-parent', 'menu_' + t.settings.parent.id);
  7342. }
  7343. co = DOM.add(w, 'div', {role: 'presentation', id : 'menu_' + t.id + '_co', 'class' : t.classPrefix + (s['class'] ? ' ' + s['class'] : '')});
  7344. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  7345. if (s.menu_line)
  7346. DOM.add(co, 'span', {'class' : t.classPrefix + 'Line'});
  7347. // n = DOM.add(co, 'div', {id : 'menu_' + t.id + '_co', 'class' : 'mceMenuContainer'});
  7348. n = DOM.add(co, 'table', {role: 'presentation', id : 'menu_' + t.id + '_tbl', border : 0, cellPadding : 0, cellSpacing : 0});
  7349. tb = DOM.add(n, 'tbody');
  7350. each(t.items, function(o) {
  7351. t._add(tb, o);
  7352. });
  7353. t.rendered = true;
  7354. return w;
  7355. },
  7356. // Internal functions
  7357. _setupKeyboardNav : function(){
  7358. var contextMenu, menuItems, t=this;
  7359. contextMenu = DOM.select('#menu_' + t.id)[0];
  7360. menuItems = DOM.select('a[role=option]', 'menu_' + t.id);
  7361. menuItems.splice(0,0,contextMenu);
  7362. t.keyboardNav = new tinymce.ui.KeyboardNavigation({
  7363. root: 'menu_' + t.id,
  7364. items: menuItems,
  7365. onCancel: function() {
  7366. t.hideMenu();
  7367. },
  7368. enableUpDown: true
  7369. });
  7370. contextMenu.focus();
  7371. },
  7372. _keyHandler : function(evt) {
  7373. var t = this, e;
  7374. switch (evt.keyCode) {
  7375. case 37: // Left
  7376. if (t.settings.parent) {
  7377. t.hideMenu();
  7378. t.settings.parent.focus();
  7379. Event.cancel(evt);
  7380. }
  7381. break;
  7382. case 39: // Right
  7383. if (t.mouseOverFunc)
  7384. t.mouseOverFunc(evt);
  7385. break;
  7386. }
  7387. },
  7388. _add : function(tb, o) {
  7389. var n, s = o.settings, a, ro, it, cp = this.classPrefix, ic;
  7390. if (s.separator) {
  7391. ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'ItemSeparator'});
  7392. DOM.add(ro, 'td', {'class' : cp + 'ItemSeparator'});
  7393. if (n = ro.previousSibling)
  7394. DOM.addClass(n, 'mceLast');
  7395. return;
  7396. }
  7397. n = ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'Item ' + cp + 'ItemEnabled'});
  7398. n = it = DOM.add(n, s.titleItem ? 'th' : 'td');
  7399. n = a = DOM.add(n, 'a', {id: o.id + '_aria', role: s.titleItem ? 'presentation' : 'option', href : 'javascript:;', onclick : "return false;", onmousedown : 'return false;'});
  7400. if (s.parent) {
  7401. DOM.setAttrib(a, 'aria-haspopup', 'true');
  7402. DOM.setAttrib(a, 'aria-owns', 'menu_' + o.id);
  7403. }
  7404. DOM.addClass(it, s['class']);
  7405. // n = DOM.add(n, 'span', {'class' : 'item'});
  7406. ic = DOM.add(n, 'span', {'class' : 'mceIcon' + (s.icon ? ' mce_' + s.icon : '')});
  7407. if (s.icon_src)
  7408. DOM.add(ic, 'img', {src : s.icon_src});
  7409. n = DOM.add(n, s.element || 'span', {'class' : 'mceText', title : o.settings.title}, o.settings.title);
  7410. if (o.settings.style)
  7411. DOM.setAttrib(n, 'style', o.settings.style);
  7412. if (tb.childNodes.length == 1)
  7413. DOM.addClass(ro, 'mceFirst');
  7414. if ((n = ro.previousSibling) && DOM.hasClass(n, cp + 'ItemSeparator'))
  7415. DOM.addClass(ro, 'mceFirst');
  7416. if (o.collapse)
  7417. DOM.addClass(ro, cp + 'ItemSub');
  7418. if (n = ro.previousSibling)
  7419. DOM.removeClass(n, 'mceLast');
  7420. DOM.addClass(ro, 'mceLast');
  7421. }
  7422. });
  7423. })(tinymce);
  7424. (function(tinymce) {
  7425. var DOM = tinymce.DOM;
  7426. tinymce.create('tinymce.ui.Button:tinymce.ui.Control', {
  7427. Button : function(id, s, ed) {
  7428. this.parent(id, s, ed);
  7429. this.classPrefix = 'mceButton';
  7430. },
  7431. renderHTML : function() {
  7432. var cp = this.classPrefix, s = this.settings, h, l;
  7433. l = DOM.encode(s.label || '');
  7434. 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) + '">';
  7435. if (s.image && !(this.editor &&this.editor.forcedHighContrastMode) )
  7436. h += '<img class="mceIcon" src="' + s.image + '" alt="' + DOM.encode(s.title) + '" />' + l;
  7437. else
  7438. h += '<span class="mceIcon ' + s['class'] + '"></span>' + (l ? '<span class="' + cp + 'Label">' + l + '</span>' : '');
  7439. h += '<span class="mceVoiceLabel mceIconOnly" style="display: none;" id="' + this.id + '_voice">' + s.title + '</span>';
  7440. h += '</a>';
  7441. return h;
  7442. },
  7443. postRender : function() {
  7444. var t = this, s = t.settings;
  7445. tinymce.dom.Event.add(t.id, 'click', function(e) {
  7446. if (!t.isDisabled())
  7447. return s.onclick.call(s.scope, e);
  7448. });
  7449. }
  7450. });
  7451. })(tinymce);
  7452. (function(tinymce) {
  7453. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher;
  7454. tinymce.create('tinymce.ui.ListBox:tinymce.ui.Control', {
  7455. ListBox : function(id, s, ed) {
  7456. var t = this;
  7457. t.parent(id, s, ed);
  7458. t.items = [];
  7459. t.onChange = new Dispatcher(t);
  7460. t.onPostRender = new Dispatcher(t);
  7461. t.onAdd = new Dispatcher(t);
  7462. t.onRenderMenu = new tinymce.util.Dispatcher(this);
  7463. t.classPrefix = 'mceListBox';
  7464. },
  7465. select : function(va) {
  7466. var t = this, fv, f;
  7467. if (va == undefined)
  7468. return t.selectByIndex(-1);
  7469. // Is string or number make function selector
  7470. if (va && va.call)
  7471. f = va;
  7472. else {
  7473. f = function(v) {
  7474. return v == va;
  7475. };
  7476. }
  7477. // Do we need to do something?
  7478. if (va != t.selectedValue) {
  7479. // Find item
  7480. each(t.items, function(o, i) {
  7481. if (f(o.value)) {
  7482. fv = 1;
  7483. t.selectByIndex(i);
  7484. return false;
  7485. }
  7486. });
  7487. if (!fv)
  7488. t.selectByIndex(-1);
  7489. }
  7490. },
  7491. selectByIndex : function(idx) {
  7492. var t = this, e, o;
  7493. if (idx != t.selectedIndex) {
  7494. e = DOM.get(t.id + '_text');
  7495. o = t.items[idx];
  7496. if (o) {
  7497. t.selectedValue = o.value;
  7498. t.selectedIndex = idx;
  7499. DOM.setHTML(e, DOM.encode(o.title));
  7500. DOM.removeClass(e, 'mceTitle');
  7501. DOM.setAttrib(t.id, 'aria-valuenow', o.title);
  7502. } else {
  7503. DOM.setHTML(e, DOM.encode(t.settings.title));
  7504. DOM.addClass(e, 'mceTitle');
  7505. t.selectedValue = t.selectedIndex = null;
  7506. DOM.setAttrib(t.id, 'aria-valuenow', t.settings.title);
  7507. }
  7508. e = 0;
  7509. }
  7510. },
  7511. add : function(n, v, o) {
  7512. var t = this;
  7513. o = o || {};
  7514. o = tinymce.extend(o, {
  7515. title : n,
  7516. value : v
  7517. });
  7518. t.items.push(o);
  7519. t.onAdd.dispatch(t, o);
  7520. },
  7521. getLength : function() {
  7522. return this.items.length;
  7523. },
  7524. renderHTML : function() {
  7525. var h = '', t = this, s = t.settings, cp = t.classPrefix;
  7526. h = '<span role="button" aria-haspopup="true" aria-labelledby="' + t.id +'_text" 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>';
  7527. h += '<td>' + DOM.createHTML('span', {id: t.id + '_voiceDesc', 'class': 'voiceLabel', style:'display:none;'}, t.settings.title);
  7528. 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>';
  7529. 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>';
  7530. h += '</tr></tbody></table></span>';
  7531. return h;
  7532. },
  7533. showMenu : function() {
  7534. var t = this, p2, e = DOM.get(this.id), m;
  7535. if (t.isDisabled() || t.items.length == 0)
  7536. return;
  7537. if (t.menu && t.menu.isMenuVisible)
  7538. return t.hideMenu();
  7539. if (!t.isMenuRendered) {
  7540. t.renderMenu();
  7541. t.isMenuRendered = true;
  7542. }
  7543. p2 = DOM.getPos(e);
  7544. m = t.menu;
  7545. m.settings.offset_x = p2.x;
  7546. m.settings.offset_y = p2.y;
  7547. m.settings.keyboard_focus = !tinymce.isOpera; // Opera is buggy when it comes to auto focus
  7548. // Select in menu
  7549. if (t.oldID)
  7550. m.items[t.oldID].setSelected(0);
  7551. each(t.items, function(o) {
  7552. if (o.value === t.selectedValue) {
  7553. m.items[o.id].setSelected(1);
  7554. t.oldID = o.id;
  7555. }
  7556. });
  7557. m.showMenu(0, e.clientHeight);
  7558. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  7559. DOM.addClass(t.id, t.classPrefix + 'Selected');
  7560. //DOM.get(t.id + '_text').focus();
  7561. },
  7562. hideMenu : function(e) {
  7563. var t = this;
  7564. if (t.menu && t.menu.isMenuVisible) {
  7565. DOM.removeClass(t.id, t.classPrefix + 'Selected');
  7566. // Prevent double toogles by canceling the mouse click event to the button
  7567. if (e && e.type == "mousedown" && (e.target.id == t.id + '_text' || e.target.id == t.id + '_open'))
  7568. return;
  7569. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  7570. DOM.removeClass(t.id, t.classPrefix + 'Selected');
  7571. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  7572. t.menu.hideMenu();
  7573. }
  7574. }
  7575. },
  7576. renderMenu : function() {
  7577. var t = this, m;
  7578. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  7579. menu_line : 1,
  7580. 'class' : t.classPrefix + 'Menu mceNoIcons',
  7581. max_width : 150,
  7582. max_height : 150
  7583. });
  7584. m.onHideMenu.add(function() {
  7585. t.hideMenu();
  7586. t.focus();
  7587. });
  7588. m.add({
  7589. title : t.settings.title,
  7590. 'class' : 'mceMenuItemTitle',
  7591. onclick : function() {
  7592. if (t.settings.onselect('') !== false)
  7593. t.select(''); // Must be runned after
  7594. }
  7595. });
  7596. each(t.items, function(o) {
  7597. // No value then treat it as a title
  7598. if (o.value === undefined) {
  7599. m.add({
  7600. title : o.title,
  7601. 'class' : 'mceMenuItemTitle',
  7602. onclick : function() {
  7603. if (t.settings.onselect('') !== false)
  7604. t.select(''); // Must be runned after
  7605. }
  7606. });
  7607. } else {
  7608. o.id = DOM.uniqueId();
  7609. o.onclick = function() {
  7610. if (t.settings.onselect(o.value) !== false)
  7611. t.select(o.value); // Must be runned after
  7612. };
  7613. m.add(o);
  7614. }
  7615. });
  7616. t.onRenderMenu.dispatch(t, m);
  7617. t.menu = m;
  7618. },
  7619. postRender : function() {
  7620. var t = this, cp = t.classPrefix;
  7621. Event.add(t.id, 'click', t.showMenu, t);
  7622. Event.add(t.id, 'keydown', function(evt) {
  7623. if (evt.keyCode == 32) { // Space
  7624. t.showMenu(evt);
  7625. Event.cancel(evt);
  7626. }
  7627. });
  7628. Event.add(t.id, 'focus', function() {
  7629. if (!t._focused) {
  7630. t.keyDownHandler = Event.add(t.id, 'keydown', function(e) {
  7631. if (e.keyCode == 40) {
  7632. t.showMenu();
  7633. Event.cancel(e);
  7634. }
  7635. });
  7636. t.keyPressHandler = Event.add(t.id, 'keypress', function(e) {
  7637. var v;
  7638. if (e.keyCode == 13) {
  7639. // Fake select on enter
  7640. v = t.selectedValue;
  7641. t.selectedValue = null; // Needs to be null to fake change
  7642. Event.cancel(e);
  7643. t.settings.onselect(v);
  7644. }
  7645. });
  7646. }
  7647. t._focused = 1;
  7648. });
  7649. Event.add(t.id, 'blur', function() {
  7650. Event.remove(t.id, 'keydown', t.keyDownHandler);
  7651. Event.remove(t.id, 'keypress', t.keyPressHandler);
  7652. t._focused = 0;
  7653. });
  7654. // Old IE doesn't have hover on all elements
  7655. if (tinymce.isIE6 || !DOM.boxModel) {
  7656. Event.add(t.id, 'mouseover', function() {
  7657. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  7658. DOM.addClass(t.id, cp + 'Hover');
  7659. });
  7660. Event.add(t.id, 'mouseout', function() {
  7661. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  7662. DOM.removeClass(t.id, cp + 'Hover');
  7663. });
  7664. }
  7665. t.onPostRender.dispatch(t, DOM.get(t.id));
  7666. },
  7667. destroy : function() {
  7668. this.parent();
  7669. Event.clear(this.id + '_text');
  7670. Event.clear(this.id + '_open');
  7671. }
  7672. });
  7673. })(tinymce);
  7674. (function(tinymce) {
  7675. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher;
  7676. tinymce.create('tinymce.ui.NativeListBox:tinymce.ui.ListBox', {
  7677. NativeListBox : function(id, s) {
  7678. this.parent(id, s);
  7679. this.classPrefix = 'mceNativeListBox';
  7680. },
  7681. setDisabled : function(s) {
  7682. DOM.get(this.id).disabled = s;
  7683. this.setAriaProperty('disabled', s);
  7684. },
  7685. isDisabled : function() {
  7686. return DOM.get(this.id).disabled;
  7687. },
  7688. select : function(va) {
  7689. var t = this, fv, f;
  7690. if (va == undefined)
  7691. return t.selectByIndex(-1);
  7692. // Is string or number make function selector
  7693. if (va && va.call)
  7694. f = va;
  7695. else {
  7696. f = function(v) {
  7697. return v == va;
  7698. };
  7699. }
  7700. // Do we need to do something?
  7701. if (va != t.selectedValue) {
  7702. // Find item
  7703. each(t.items, function(o, i) {
  7704. if (f(o.value)) {
  7705. fv = 1;
  7706. t.selectByIndex(i);
  7707. return false;
  7708. }
  7709. });
  7710. if (!fv)
  7711. t.selectByIndex(-1);
  7712. }
  7713. },
  7714. selectByIndex : function(idx) {
  7715. DOM.get(this.id).selectedIndex = idx + 1;
  7716. this.selectedValue = this.items[idx] ? this.items[idx].value : null;
  7717. },
  7718. add : function(n, v, a) {
  7719. var o, t = this;
  7720. a = a || {};
  7721. a.value = v;
  7722. if (t.isRendered())
  7723. DOM.add(DOM.get(this.id), 'option', a, n);
  7724. o = {
  7725. title : n,
  7726. value : v,
  7727. attribs : a
  7728. };
  7729. t.items.push(o);
  7730. t.onAdd.dispatch(t, o);
  7731. },
  7732. getLength : function() {
  7733. return this.items.length;
  7734. },
  7735. renderHTML : function() {
  7736. var h, t = this;
  7737. h = DOM.createHTML('option', {value : ''}, '-- ' + t.settings.title + ' --');
  7738. each(t.items, function(it) {
  7739. h += DOM.createHTML('option', {value : it.value}, it.title);
  7740. });
  7741. h = DOM.createHTML('select', {id : t.id, 'class' : 'mceNativeListBox', 'aria-labelledby': t.id + '_aria'}, h);
  7742. h += DOM.createHTML('span', {id : t.id + '_aria', 'style': 'display: none'}, t.settings.title);
  7743. return h;
  7744. },
  7745. postRender : function() {
  7746. var t = this, ch, changeListenerAdded = true;
  7747. t.rendered = true;
  7748. function onChange(e) {
  7749. var v = t.items[e.target.selectedIndex - 1];
  7750. if (v && (v = v.value)) {
  7751. t.onChange.dispatch(t, v);
  7752. if (t.settings.onselect)
  7753. t.settings.onselect(v);
  7754. }
  7755. };
  7756. Event.add(t.id, 'change', onChange);
  7757. // Accessibility keyhandler
  7758. Event.add(t.id, 'keydown', function(e) {
  7759. var bf;
  7760. Event.remove(t.id, 'change', ch);
  7761. changeListenerAdded = false;
  7762. bf = Event.add(t.id, 'blur', function() {
  7763. if (changeListenerAdded) return;
  7764. changeListenerAdded = true;
  7765. Event.add(t.id, 'change', onChange);
  7766. Event.remove(t.id, 'blur', bf);
  7767. });
  7768. if (e.keyCode == 13 || e.keyCode == 32) {
  7769. onChange(e);
  7770. return Event.cancel(e);
  7771. }
  7772. });
  7773. t.onPostRender.dispatch(t, DOM.get(t.id));
  7774. }
  7775. });
  7776. })(tinymce);
  7777. (function(tinymce) {
  7778. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  7779. tinymce.create('tinymce.ui.MenuButton:tinymce.ui.Button', {
  7780. MenuButton : function(id, s, ed) {
  7781. this.parent(id, s, ed);
  7782. this.onRenderMenu = new tinymce.util.Dispatcher(this);
  7783. s.menu_container = s.menu_container || DOM.doc.body;
  7784. },
  7785. showMenu : function() {
  7786. var t = this, p1, p2, e = DOM.get(t.id), m;
  7787. if (t.isDisabled())
  7788. return;
  7789. if (!t.isMenuRendered) {
  7790. t.renderMenu();
  7791. t.isMenuRendered = true;
  7792. }
  7793. if (t.isMenuVisible)
  7794. return t.hideMenu();
  7795. p1 = DOM.getPos(t.settings.menu_container);
  7796. p2 = DOM.getPos(e);
  7797. m = t.menu;
  7798. m.settings.offset_x = p2.x;
  7799. m.settings.offset_y = p2.y;
  7800. m.settings.vp_offset_x = p2.x;
  7801. m.settings.vp_offset_y = p2.y;
  7802. m.settings.keyboard_focus = t._focused;
  7803. m.showMenu(0, e.clientHeight);
  7804. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  7805. t.setState('Selected', 1);
  7806. t.isMenuVisible = 1;
  7807. },
  7808. renderMenu : function() {
  7809. var t = this, m;
  7810. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  7811. menu_line : 1,
  7812. 'class' : this.classPrefix + 'Menu',
  7813. icons : t.settings.icons
  7814. });
  7815. m.onHideMenu.add(function() {
  7816. t.hideMenu();
  7817. t.focus();
  7818. });
  7819. t.onRenderMenu.dispatch(t, m);
  7820. t.menu = m;
  7821. },
  7822. hideMenu : function(e) {
  7823. var t = this;
  7824. // Prevent double toogles by canceling the mouse click event to the button
  7825. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id || e.id === t.id + '_open';}))
  7826. return;
  7827. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  7828. t.setState('Selected', 0);
  7829. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  7830. if (t.menu)
  7831. t.menu.hideMenu();
  7832. }
  7833. t.isMenuVisible = 0;
  7834. },
  7835. postRender : function() {
  7836. var t = this, s = t.settings;
  7837. Event.add(t.id, 'click', function() {
  7838. if (!t.isDisabled()) {
  7839. if (s.onclick)
  7840. s.onclick(t.value);
  7841. t.showMenu();
  7842. }
  7843. });
  7844. }
  7845. });
  7846. })(tinymce);
  7847. (function(tinymce) {
  7848. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  7849. tinymce.create('tinymce.ui.SplitButton:tinymce.ui.MenuButton', {
  7850. SplitButton : function(id, s, ed) {
  7851. this.parent(id, s, ed);
  7852. this.classPrefix = 'mceSplitButton';
  7853. },
  7854. renderHTML : function() {
  7855. var h, t = this, s = t.settings, h1;
  7856. h = '<tbody><tr>';
  7857. if (s.image)
  7858. h1 = DOM.createHTML('img ', {src : s.image, role: 'presentation', 'class' : 'mceAction ' + s['class']});
  7859. else
  7860. h1 = DOM.createHTML('span', {'class' : 'mceAction ' + s['class']}, '');
  7861. h1 += DOM.createHTML('span', {'class': 'mceVoiceLabel mceIconOnly', id: t.id + '_voice', style: 'display:none;'}, s.title);
  7862. 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>';
  7863. h1 = DOM.createHTML('span', {'class' : 'mceOpen ' + s['class']}, '<span style="display:none;" class="mceIconOnly" aria-hidden="true">\u25BC</span>');
  7864. 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>';
  7865. h += '</tr></tbody>';
  7866. h = DOM.createHTML('table', {id : t.id, role: 'presentation', tabindex: '0', 'class' : 'mceSplitButton mceSplitButtonEnabled ' + s['class'], cellpadding : '0', cellspacing : '0', title : s.title}, h);
  7867. return DOM.createHTML('span', {role: 'button', 'aria-labelledby': t.id + '_voice', 'aria-haspopup': 'true'}, h);
  7868. },
  7869. postRender : function() {
  7870. var t = this, s = t.settings, activate;
  7871. if (s.onclick) {
  7872. activate = function(evt) {
  7873. if (!t.isDisabled()) {
  7874. s.onclick(t.value);
  7875. Event.cancel(evt);
  7876. }
  7877. };
  7878. Event.add(t.id + '_action', 'click', activate);
  7879. Event.add(t.id, ['click', 'keydown'], function(evt) {
  7880. var DOM_VK_SPACE = 32, DOM_VK_ENTER = 14, DOM_VK_RETURN = 13, DOM_VK_UP = 38, DOM_VK_DOWN = 40;
  7881. if ((evt.keyCode === 32 || evt.keyCode === 13 || evt.keyCode === 14) && !evt.altKey && !evt.ctrlKey && !evt.metaKey) {
  7882. activate();
  7883. Event.cancel(evt);
  7884. } else if (evt.type === 'click' || evt.keyCode === DOM_VK_DOWN) {
  7885. t.showMenu();
  7886. Event.cancel(evt);
  7887. }
  7888. });
  7889. }
  7890. Event.add(t.id + '_open', 'click', function (evt) {
  7891. t.showMenu();
  7892. Event.cancel(evt);
  7893. });
  7894. Event.add([t.id, t.id + '_open'], 'focus', function() {t._focused = 1;});
  7895. Event.add([t.id, t.id + '_open'], 'blur', function() {t._focused = 0;});
  7896. // Old IE doesn't have hover on all elements
  7897. if (tinymce.isIE6 || !DOM.boxModel) {
  7898. Event.add(t.id, 'mouseover', function() {
  7899. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  7900. DOM.addClass(t.id, 'mceSplitButtonHover');
  7901. });
  7902. Event.add(t.id, 'mouseout', function() {
  7903. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  7904. DOM.removeClass(t.id, 'mceSplitButtonHover');
  7905. });
  7906. }
  7907. },
  7908. destroy : function() {
  7909. this.parent();
  7910. Event.clear(this.id + '_action');
  7911. Event.clear(this.id + '_open');
  7912. Event.clear(this.id);
  7913. }
  7914. });
  7915. })(tinymce);
  7916. (function(tinymce) {
  7917. var DOM = tinymce.DOM, Event = tinymce.dom.Event, is = tinymce.is, each = tinymce.each;
  7918. tinymce.create('tinymce.ui.ColorSplitButton:tinymce.ui.SplitButton', {
  7919. ColorSplitButton : function(id, s, ed) {
  7920. var t = this;
  7921. t.parent(id, s, ed);
  7922. t.settings = s = tinymce.extend({
  7923. 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',
  7924. grid_width : 8,
  7925. default_color : '#888888'
  7926. }, t.settings);
  7927. t.onShowMenu = new tinymce.util.Dispatcher(t);
  7928. t.onHideMenu = new tinymce.util.Dispatcher(t);
  7929. t.value = s.default_color;
  7930. },
  7931. showMenu : function() {
  7932. var t = this, r, p, e, p2;
  7933. if (t.isDisabled())
  7934. return;
  7935. if (!t.isMenuRendered) {
  7936. t.renderMenu();
  7937. t.isMenuRendered = true;
  7938. }
  7939. if (t.isMenuVisible)
  7940. return t.hideMenu();
  7941. e = DOM.get(t.id);
  7942. DOM.show(t.id + '_menu');
  7943. DOM.addClass(e, 'mceSplitButtonSelected');
  7944. p2 = DOM.getPos(e);
  7945. DOM.setStyles(t.id + '_menu', {
  7946. left : p2.x,
  7947. top : p2.y + e.clientHeight,
  7948. zIndex : 200000
  7949. });
  7950. e = 0;
  7951. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  7952. t.onShowMenu.dispatch(t);
  7953. if (t._focused) {
  7954. t._keyHandler = Event.add(t.id + '_menu', 'keydown', function(e) {
  7955. if (e.keyCode == 27)
  7956. t.hideMenu();
  7957. });
  7958. DOM.select('a', t.id + '_menu')[0].focus(); // Select first link
  7959. }
  7960. t.isMenuVisible = 1;
  7961. },
  7962. hideMenu : function(e) {
  7963. var t = this;
  7964. if (t.isMenuVisible) {
  7965. // Prevent double toogles by canceling the mouse click event to the button
  7966. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id + '_open';}))
  7967. return;
  7968. if (!e || !DOM.getParent(e.target, '.mceSplitButtonMenu')) {
  7969. DOM.removeClass(t.id, 'mceSplitButtonSelected');
  7970. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  7971. Event.remove(t.id + '_menu', 'keydown', t._keyHandler);
  7972. DOM.hide(t.id + '_menu');
  7973. }
  7974. t.isMenuVisible = 0;
  7975. }
  7976. },
  7977. renderMenu : function() {
  7978. var t = this, m, i = 0, s = t.settings, n, tb, tr, w, context;
  7979. 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;'});
  7980. m = DOM.add(w, 'div', {'class' : s['class'] + ' mceSplitButtonMenu'});
  7981. DOM.add(m, 'span', {'class' : 'mceMenuLine'});
  7982. n = DOM.add(m, 'table', {role: 'presentation', 'class' : 'mceColorSplitMenu'});
  7983. tb = DOM.add(n, 'tbody');
  7984. // Generate color grid
  7985. i = 0;
  7986. each(is(s.colors, 'array') ? s.colors : s.colors.split(','), function(c) {
  7987. c = c.replace(/^#/, '');
  7988. if (!i--) {
  7989. tr = DOM.add(tb, 'tr');
  7990. i = s.grid_width - 1;
  7991. }
  7992. n = DOM.add(tr, 'td');
  7993. n = DOM.add(n, 'a', {
  7994. role : 'option',
  7995. href : 'javascript:;',
  7996. style : {
  7997. backgroundColor : '#' + c
  7998. },
  7999. 'title': t.editor.getLang('colors.' + c, c),
  8000. 'data-mce-color' : '#' + c
  8001. });
  8002. if (t.editor.forcedHighContrastMode) {
  8003. n = DOM.add(n, 'canvas', { width: 16, height: 16, 'aria-hidden': 'true' });
  8004. if (n.getContext && (context = n.getContext("2d"))) {
  8005. context.fillStyle = '#' + c;
  8006. context.fillRect(0, 0, 16, 16);
  8007. } else {
  8008. // No point leaving a canvas element around if it's not supported for drawing on anyway.
  8009. DOM.remove(n);
  8010. }
  8011. }
  8012. });
  8013. if (s.more_colors_func) {
  8014. n = DOM.add(tb, 'tr');
  8015. n = DOM.add(n, 'td', {colspan : s.grid_width, 'class' : 'mceMoreColors'});
  8016. n = DOM.add(n, 'a', {role: 'option', id : t.id + '_more', href : 'javascript:;', onclick : 'return false;', 'class' : 'mceMoreColors'}, s.more_colors_title);
  8017. Event.add(n, 'click', function(e) {
  8018. s.more_colors_func.call(s.more_colors_scope || this);
  8019. return Event.cancel(e); // Cancel to fix onbeforeunload problem
  8020. });
  8021. }
  8022. DOM.addClass(m, 'mceColorSplitMenu');
  8023. new tinymce.ui.KeyboardNavigation({
  8024. root: t.id + '_menu',
  8025. items: DOM.select('a', t.id + '_menu'),
  8026. onCancel: function() {
  8027. t.hideMenu();
  8028. t.focus();
  8029. }
  8030. });
  8031. // Prevent IE from scrolling and hindering click to occur #4019
  8032. Event.add(t.id + '_menu', 'mousedown', function(e) {return Event.cancel(e);});
  8033. Event.add(t.id + '_menu', 'click', function(e) {
  8034. var c;
  8035. e = DOM.getParent(e.target, 'a', tb);
  8036. if (e && e.nodeName.toLowerCase() == 'a' && (c = e.getAttribute('data-mce-color')))
  8037. t.setColor(c);
  8038. return Event.cancel(e); // Prevent IE auto save warning
  8039. });
  8040. return w;
  8041. },
  8042. setColor : function(c) {
  8043. this.displayColor(c);
  8044. this.hideMenu();
  8045. this.settings.onselect(c);
  8046. },
  8047. displayColor : function(c) {
  8048. var t = this;
  8049. DOM.setStyle(t.id + '_preview', 'backgroundColor', c);
  8050. t.value = c;
  8051. },
  8052. postRender : function() {
  8053. var t = this, id = t.id;
  8054. t.parent();
  8055. DOM.add(id + '_action', 'div', {id : id + '_preview', 'class' : 'mceColorPreview'});
  8056. DOM.setStyle(t.id + '_preview', 'backgroundColor', t.value);
  8057. },
  8058. destroy : function() {
  8059. this.parent();
  8060. Event.clear(this.id + '_menu');
  8061. Event.clear(this.id + '_more');
  8062. DOM.remove(this.id + '_menu');
  8063. }
  8064. });
  8065. })(tinymce);
  8066. (function(tinymce) {
  8067. // Shorten class names
  8068. var dom = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event;
  8069. tinymce.create('tinymce.ui.ToolbarGroup:tinymce.ui.Container', {
  8070. renderHTML : function() {
  8071. var t = this, h = [], controls = t.controls, each = tinymce.each, settings = t.settings;
  8072. h.push('<div id="' + t.id + '" role="group" aria-labelledby="' + t.id + '_voice">');
  8073. //TODO: ACC test this out - adding a role = application for getting the landmarks working well.
  8074. h.push("<span role='application'>");
  8075. h.push('<span id="' + t.id + '_voice" class="mceVoiceLabel" style="display:none;">' + dom.encode(settings.name) + '</span>');
  8076. each(controls, function(toolbar) {
  8077. h.push(toolbar.renderHTML());
  8078. });
  8079. h.push("</span>");
  8080. h.push('</div>');
  8081. return h.join('');
  8082. },
  8083. focus : function() {
  8084. this.keyNav.focus();
  8085. },
  8086. postRender : function() {
  8087. var t = this, items = [];
  8088. each(t.controls, function(toolbar) {
  8089. each (toolbar.controls, function(control) {
  8090. if (control.id) {
  8091. items.push(control);
  8092. }
  8093. });
  8094. });
  8095. t.keyNav = new tinymce.ui.KeyboardNavigation({
  8096. root: t.id,
  8097. items: items,
  8098. onCancel: function() {
  8099. t.editor.focus();
  8100. },
  8101. excludeFromTabOrder: !t.settings.tab_focus_toolbar
  8102. });
  8103. },
  8104. destroy : function() {
  8105. var self = this;
  8106. self.parent();
  8107. self.keyNav.destroy();
  8108. Event.clear(self.id);
  8109. }
  8110. });
  8111. })(tinymce);
  8112. (function(tinymce) {
  8113. // Shorten class names
  8114. var dom = tinymce.DOM, each = tinymce.each;
  8115. tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', {
  8116. renderHTML : function() {
  8117. var t = this, h = '', c, co, s = t.settings, i, pr, nx, cl;
  8118. cl = t.controls;
  8119. for (i=0; i<cl.length; i++) {
  8120. // Get current control, prev control, next control and if the control is a list box or not
  8121. co = cl[i];
  8122. pr = cl[i - 1];
  8123. nx = cl[i + 1];
  8124. // Add toolbar start
  8125. if (i === 0) {
  8126. c = 'mceToolbarStart';
  8127. if (co.Button)
  8128. c += ' mceToolbarStartButton';
  8129. else if (co.SplitButton)
  8130. c += ' mceToolbarStartSplitButton';
  8131. else if (co.ListBox)
  8132. c += ' mceToolbarStartListBox';
  8133. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  8134. }
  8135. // Add toolbar end before list box and after the previous button
  8136. // This is to fix the o2k7 editor skins
  8137. if (pr && co.ListBox) {
  8138. if (pr.Button || pr.SplitButton)
  8139. h += dom.createHTML('td', {'class' : 'mceToolbarEnd'}, dom.createHTML('span', null, '<!-- IE -->'));
  8140. }
  8141. // Render control HTML
  8142. // IE 8 quick fix, needed to propertly generate a hit area for anchors
  8143. if (dom.stdMode)
  8144. h += '<td style="position: relative">' + co.renderHTML() + '</td>';
  8145. else
  8146. h += '<td>' + co.renderHTML() + '</td>';
  8147. // Add toolbar start after list box and before the next button
  8148. // This is to fix the o2k7 editor skins
  8149. if (nx && co.ListBox) {
  8150. if (nx.Button || nx.SplitButton)
  8151. h += dom.createHTML('td', {'class' : 'mceToolbarStart'}, dom.createHTML('span', null, '<!-- IE -->'));
  8152. }
  8153. }
  8154. c = 'mceToolbarEnd';
  8155. if (co.Button)
  8156. c += ' mceToolbarEndButton';
  8157. else if (co.SplitButton)
  8158. c += ' mceToolbarEndSplitButton';
  8159. else if (co.ListBox)
  8160. c += ' mceToolbarEndListBox';
  8161. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  8162. 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>');
  8163. }
  8164. });
  8165. })(tinymce);
  8166. (function(tinymce) {
  8167. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each;
  8168. tinymce.create('tinymce.AddOnManager', {
  8169. AddOnManager : function() {
  8170. var self = this;
  8171. self.items = [];
  8172. self.urls = {};
  8173. self.lookup = {};
  8174. self.onAdd = new Dispatcher(self);
  8175. },
  8176. get : function(n) {
  8177. if (this.lookup[n]) {
  8178. return this.lookup[n].instance;
  8179. } else {
  8180. return undefined;
  8181. }
  8182. },
  8183. dependencies : function(n) {
  8184. var result;
  8185. if (this.lookup[n]) {
  8186. result = this.lookup[n].dependencies;
  8187. }
  8188. return result || [];
  8189. },
  8190. requireLangPack : function(n) {
  8191. var s = tinymce.settings;
  8192. if (s && s.language && s.language_load !== false)
  8193. tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js');
  8194. },
  8195. add : function(id, o, dependencies) {
  8196. this.items.push(o);
  8197. this.lookup[id] = {instance:o, dependencies:dependencies};
  8198. this.onAdd.dispatch(this, id, o);
  8199. return o;
  8200. },
  8201. createUrl: function(baseUrl, dep) {
  8202. if (typeof dep === "object") {
  8203. return dep
  8204. } else {
  8205. return {prefix: baseUrl.prefix, resource: dep, suffix: baseUrl.suffix};
  8206. }
  8207. },
  8208. addComponents: function(pluginName, scripts) {
  8209. var pluginUrl = this.urls[pluginName];
  8210. tinymce.each(scripts, function(script){
  8211. tinymce.ScriptLoader.add(pluginUrl+"/"+script);
  8212. });
  8213. },
  8214. load : function(n, u, cb, s) {
  8215. var t = this, url = u;
  8216. function loadDependencies() {
  8217. var dependencies = t.dependencies(n);
  8218. tinymce.each(dependencies, function(dep) {
  8219. var newUrl = t.createUrl(u, dep);
  8220. t.load(newUrl.resource, newUrl, undefined, undefined);
  8221. });
  8222. if (cb) {
  8223. if (s) {
  8224. cb.call(s);
  8225. } else {
  8226. cb.call(tinymce.ScriptLoader);
  8227. }
  8228. }
  8229. }
  8230. if (t.urls[n])
  8231. return;
  8232. if (typeof u === "object")
  8233. url = u.prefix + u.resource + u.suffix;
  8234. if (url.indexOf('/') != 0 && url.indexOf('://') == -1)
  8235. url = tinymce.baseURL + '/' + url;
  8236. t.urls[n] = url.substring(0, url.lastIndexOf('/'));
  8237. if (t.lookup[n]) {
  8238. loadDependencies();
  8239. } else {
  8240. tinymce.ScriptLoader.add(url, loadDependencies, s);
  8241. }
  8242. }
  8243. });
  8244. // Create plugin and theme managers
  8245. tinymce.PluginManager = new tinymce.AddOnManager();
  8246. tinymce.ThemeManager = new tinymce.AddOnManager();
  8247. }(tinymce));
  8248. (function(tinymce) {
  8249. // Shorten names
  8250. var each = tinymce.each, extend = tinymce.extend,
  8251. DOM = tinymce.DOM, Event = tinymce.dom.Event,
  8252. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  8253. explode = tinymce.explode,
  8254. Dispatcher = tinymce.util.Dispatcher, undefined, instanceCounter = 0;
  8255. // Setup some URLs where the editor API is located and where the document is
  8256. tinymce.documentBaseURL = window.location.href.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '');
  8257. if (!/[\/\\]$/.test(tinymce.documentBaseURL))
  8258. tinymce.documentBaseURL += '/';
  8259. tinymce.baseURL = new tinymce.util.URI(tinymce.documentBaseURL).toAbsolute(tinymce.baseURL);
  8260. tinymce.baseURI = new tinymce.util.URI(tinymce.baseURL);
  8261. // Add before unload listener
  8262. // This was required since IE was leaking memory if you added and removed beforeunload listeners
  8263. // with attachEvent/detatchEvent so this only adds one listener and instances can the attach to the onBeforeUnload event
  8264. tinymce.onBeforeUnload = new Dispatcher(tinymce);
  8265. // Must be on window or IE will leak if the editor is placed in frame or iframe
  8266. Event.add(window, 'beforeunload', function(e) {
  8267. tinymce.onBeforeUnload.dispatch(tinymce, e);
  8268. });
  8269. tinymce.onAddEditor = new Dispatcher(tinymce);
  8270. tinymce.onRemoveEditor = new Dispatcher(tinymce);
  8271. tinymce.EditorManager = extend(tinymce, {
  8272. editors : [],
  8273. i18n : {},
  8274. activeEditor : null,
  8275. init : function(s) {
  8276. var t = this, pl, sl = tinymce.ScriptLoader, e, el = [], ed;
  8277. function execCallback(se, n, s) {
  8278. var f = se[n];
  8279. if (!f)
  8280. return;
  8281. if (tinymce.is(f, 'string')) {
  8282. s = f.replace(/\.\w+$/, '');
  8283. s = s ? tinymce.resolve(s) : 0;
  8284. f = tinymce.resolve(f);
  8285. }
  8286. return f.apply(s || this, Array.prototype.slice.call(arguments, 2));
  8287. };
  8288. s = extend({
  8289. theme : "simple",
  8290. language : "en"
  8291. }, s);
  8292. t.settings = s;
  8293. // Legacy call
  8294. Event.add(document, 'init', function() {
  8295. var l, co;
  8296. execCallback(s, 'onpageload');
  8297. switch (s.mode) {
  8298. case "exact":
  8299. l = s.elements || '';
  8300. if(l.length > 0) {
  8301. each(explode(l), function(v) {
  8302. if (DOM.get(v)) {
  8303. ed = new tinymce.Editor(v, s);
  8304. el.push(ed);
  8305. ed.render(1);
  8306. } else {
  8307. each(document.forms, function(f) {
  8308. each(f.elements, function(e) {
  8309. if (e.name === v) {
  8310. v = 'mce_editor_' + instanceCounter++;
  8311. DOM.setAttrib(e, 'id', v);
  8312. ed = new tinymce.Editor(v, s);
  8313. el.push(ed);
  8314. ed.render(1);
  8315. }
  8316. });
  8317. });
  8318. }
  8319. });
  8320. }
  8321. break;
  8322. case "textareas":
  8323. case "specific_textareas":
  8324. function hasClass(n, c) {
  8325. return c.constructor === RegExp ? c.test(n.className) : DOM.hasClass(n, c);
  8326. };
  8327. each(DOM.select('textarea'), function(v) {
  8328. if (s.editor_deselector && hasClass(v, s.editor_deselector))
  8329. return;
  8330. if (!s.editor_selector || hasClass(v, s.editor_selector)) {
  8331. // Can we use the name
  8332. e = DOM.get(v.name);
  8333. if (!v.id && !e)
  8334. v.id = v.name;
  8335. // Generate unique name if missing or already exists
  8336. if (!v.id || t.get(v.id))
  8337. v.id = DOM.uniqueId();
  8338. ed = new tinymce.Editor(v.id, s);
  8339. el.push(ed);
  8340. ed.render(1);
  8341. }
  8342. });
  8343. break;
  8344. }
  8345. // Call onInit when all editors are initialized
  8346. if (s.oninit) {
  8347. l = co = 0;
  8348. each(el, function(ed) {
  8349. co++;
  8350. if (!ed.initialized) {
  8351. // Wait for it
  8352. ed.onInit.add(function() {
  8353. l++;
  8354. // All done
  8355. if (l == co)
  8356. execCallback(s, 'oninit');
  8357. });
  8358. } else
  8359. l++;
  8360. // All done
  8361. if (l == co)
  8362. execCallback(s, 'oninit');
  8363. });
  8364. }
  8365. });
  8366. },
  8367. get : function(id) {
  8368. if (id === undefined)
  8369. return this.editors;
  8370. return this.editors[id];
  8371. },
  8372. getInstanceById : function(id) {
  8373. return this.get(id);
  8374. },
  8375. add : function(editor) {
  8376. var self = this, editors = self.editors;
  8377. // Add named and index editor instance
  8378. editors[editor.id] = editor;
  8379. editors.push(editor);
  8380. self._setActive(editor);
  8381. self.onAddEditor.dispatch(self, editor);
  8382. return editor;
  8383. },
  8384. remove : function(editor) {
  8385. var t = this, i, editors = t.editors;
  8386. // Not in the collection
  8387. if (!editors[editor.id])
  8388. return null;
  8389. delete editors[editor.id];
  8390. for (i = 0; i < editors.length; i++) {
  8391. if (editors[i] == editor) {
  8392. editors.splice(i, 1);
  8393. break;
  8394. }
  8395. }
  8396. // Select another editor since the active one was removed
  8397. if (t.activeEditor == editor)
  8398. t._setActive(editors[0]);
  8399. editor.destroy();
  8400. t.onRemoveEditor.dispatch(t, editor);
  8401. return editor;
  8402. },
  8403. execCommand : function(c, u, v) {
  8404. var t = this, ed = t.get(v), w;
  8405. // Manager commands
  8406. switch (c) {
  8407. case "mceFocus":
  8408. ed.focus();
  8409. return true;
  8410. case "mceAddEditor":
  8411. case "mceAddControl":
  8412. if (!t.get(v))
  8413. new tinymce.Editor(v, t.settings).render();
  8414. return true;
  8415. case "mceAddFrameControl":
  8416. w = v.window;
  8417. // Add tinyMCE global instance and tinymce namespace to specified window
  8418. w.tinyMCE = tinyMCE;
  8419. w.tinymce = tinymce;
  8420. tinymce.DOM.doc = w.document;
  8421. tinymce.DOM.win = w;
  8422. ed = new tinymce.Editor(v.element_id, v);
  8423. ed.render();
  8424. // Fix IE memory leaks
  8425. if (tinymce.isIE) {
  8426. function clr() {
  8427. ed.destroy();
  8428. w.detachEvent('onunload', clr);
  8429. w = w.tinyMCE = w.tinymce = null; // IE leak
  8430. };
  8431. w.attachEvent('onunload', clr);
  8432. }
  8433. v.page_window = null;
  8434. return true;
  8435. case "mceRemoveEditor":
  8436. case "mceRemoveControl":
  8437. if (ed)
  8438. ed.remove();
  8439. return true;
  8440. case 'mceToggleEditor':
  8441. if (!ed) {
  8442. t.execCommand('mceAddControl', 0, v);
  8443. return true;
  8444. }
  8445. if (ed.isHidden())
  8446. ed.show();
  8447. else
  8448. ed.hide();
  8449. return true;
  8450. }
  8451. // Run command on active editor
  8452. if (t.activeEditor)
  8453. return t.activeEditor.execCommand(c, u, v);
  8454. return false;
  8455. },
  8456. execInstanceCommand : function(id, c, u, v) {
  8457. var ed = this.get(id);
  8458. if (ed)
  8459. return ed.execCommand(c, u, v);
  8460. return false;
  8461. },
  8462. triggerSave : function() {
  8463. each(this.editors, function(e) {
  8464. e.save();
  8465. });
  8466. },
  8467. addI18n : function(p, o) {
  8468. var lo, i18n = this.i18n;
  8469. if (!tinymce.is(p, 'string')) {
  8470. each(p, function(o, lc) {
  8471. each(o, function(o, g) {
  8472. each(o, function(o, k) {
  8473. if (g === 'common')
  8474. i18n[lc + '.' + k] = o;
  8475. else
  8476. i18n[lc + '.' + g + '.' + k] = o;
  8477. });
  8478. });
  8479. });
  8480. } else {
  8481. each(o, function(o, k) {
  8482. i18n[p + '.' + k] = o;
  8483. });
  8484. }
  8485. },
  8486. // Private methods
  8487. _setActive : function(editor) {
  8488. this.selectedInstance = this.activeEditor = editor;
  8489. }
  8490. });
  8491. })(tinymce);
  8492. (function(tinymce) {
  8493. // Shorten these names
  8494. var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend,
  8495. Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isGecko = tinymce.isGecko,
  8496. isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, is = tinymce.is,
  8497. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  8498. inArray = tinymce.inArray, grep = tinymce.grep, explode = tinymce.explode;
  8499. tinymce.create('tinymce.Editor', {
  8500. Editor : function(id, s) {
  8501. var t = this;
  8502. t.id = t.editorId = id;
  8503. t.execCommands = {};
  8504. t.queryStateCommands = {};
  8505. t.queryValueCommands = {};
  8506. t.isNotDirty = false;
  8507. t.plugins = {};
  8508. // Add events to the editor
  8509. each([
  8510. 'onPreInit',
  8511. 'onBeforeRenderUI',
  8512. 'onPostRender',
  8513. 'onInit',
  8514. 'onRemove',
  8515. 'onActivate',
  8516. 'onDeactivate',
  8517. 'onClick',
  8518. 'onEvent',
  8519. 'onMouseUp',
  8520. 'onMouseDown',
  8521. 'onDblClick',
  8522. 'onKeyDown',
  8523. 'onKeyUp',
  8524. 'onKeyPress',
  8525. 'onContextMenu',
  8526. 'onSubmit',
  8527. 'onReset',
  8528. 'onPaste',
  8529. 'onPreProcess',
  8530. 'onPostProcess',
  8531. 'onBeforeSetContent',
  8532. 'onBeforeGetContent',
  8533. 'onSetContent',
  8534. 'onGetContent',
  8535. 'onLoadContent',
  8536. 'onSaveContent',
  8537. 'onNodeChange',
  8538. 'onChange',
  8539. 'onBeforeExecCommand',
  8540. 'onExecCommand',
  8541. 'onUndo',
  8542. 'onRedo',
  8543. 'onVisualAid',
  8544. 'onSetProgressState'
  8545. ], function(e) {
  8546. t[e] = new Dispatcher(t);
  8547. });
  8548. t.settings = s = extend({
  8549. id : id,
  8550. language : 'en',
  8551. docs_language : 'en',
  8552. theme : 'simple',
  8553. skin : 'default',
  8554. delta_width : 0,
  8555. delta_height : 0,
  8556. popup_css : '',
  8557. plugins : '',
  8558. document_base_url : tinymce.documentBaseURL,
  8559. add_form_submit_trigger : 1,
  8560. submit_patch : 1,
  8561. add_unload_trigger : 1,
  8562. convert_urls : 1,
  8563. relative_urls : 1,
  8564. remove_script_host : 1,
  8565. table_inline_editing : 0,
  8566. object_resizing : 1,
  8567. cleanup : 1,
  8568. accessibility_focus : 1,
  8569. custom_shortcuts : 1,
  8570. custom_undo_redo_keyboard_shortcuts : 1,
  8571. custom_undo_redo_restore_selection : 1,
  8572. custom_undo_redo : 1,
  8573. doctype : tinymce.isIE6 ? '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' : '<!DOCTYPE>', // Use old doctype on IE 6 to avoid horizontal scroll
  8574. visual_table_class : 'mceItemTable',
  8575. visual : 1,
  8576. font_size_style_values : 'xx-small,x-small,small,medium,large,x-large,xx-large',
  8577. apply_source_formatting : 1,
  8578. directionality : 'ltr',
  8579. forced_root_block : 'p',
  8580. hidden_input : 1,
  8581. padd_empty_editor : 1,
  8582. render_ui : 1,
  8583. init_theme : 1,
  8584. force_p_newlines : 1,
  8585. indentation : '30px',
  8586. keep_styles : 1,
  8587. fix_table_elements : 1,
  8588. inline_styles : 1,
  8589. convert_fonts_to_spans : true,
  8590. indent : 'simple',
  8591. indent_before : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr',
  8592. indent_after : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr',
  8593. validate : true,
  8594. entity_encoding : 'named',
  8595. url_converter : t.convertURL,
  8596. url_converter_scope : t,
  8597. ie7_compat : true
  8598. }, s);
  8599. t.documentBaseURI = new tinymce.util.URI(s.document_base_url || tinymce.documentBaseURL, {
  8600. base_uri : tinyMCE.baseURI
  8601. });
  8602. t.baseURI = tinymce.baseURI;
  8603. t.contentCSS = [];
  8604. // Call setup
  8605. t.execCallback('setup', t);
  8606. },
  8607. render : function(nst) {
  8608. var t = this, s = t.settings, id = t.id, sl = tinymce.ScriptLoader;
  8609. // Page is not loaded yet, wait for it
  8610. if (!Event.domLoaded) {
  8611. Event.add(document, 'init', function() {
  8612. t.render();
  8613. });
  8614. return;
  8615. }
  8616. tinyMCE.settings = s;
  8617. // Element not found, then skip initialization
  8618. if (!t.getElement())
  8619. return;
  8620. // Is a iPad/iPhone and not on iOS5, then skip initialization. We need to sniff
  8621. // here since the browser says it has contentEditable support but there is no visible
  8622. // caret We will remove this check ones Apple implements full contentEditable support
  8623. if (tinymce.isIDevice && !tinymce.isIOS5)
  8624. return;
  8625. // Add hidden input for non input elements inside form elements
  8626. if (!/TEXTAREA|INPUT/i.test(t.getElement().nodeName) && s.hidden_input && DOM.getParent(id, 'form'))
  8627. DOM.insertAfter(DOM.create('input', {type : 'hidden', name : id}), id);
  8628. if (tinymce.WindowManager)
  8629. t.windowManager = new tinymce.WindowManager(t);
  8630. if (s.encoding == 'xml') {
  8631. t.onGetContent.add(function(ed, o) {
  8632. if (o.save)
  8633. o.content = DOM.encode(o.content);
  8634. });
  8635. }
  8636. if (s.add_form_submit_trigger) {
  8637. t.onSubmit.addToTop(function() {
  8638. if (t.initialized) {
  8639. t.save();
  8640. t.isNotDirty = 1;
  8641. }
  8642. });
  8643. }
  8644. if (s.add_unload_trigger) {
  8645. t._beforeUnload = tinyMCE.onBeforeUnload.add(function() {
  8646. if (t.initialized && !t.destroyed && !t.isHidden())
  8647. t.save({format : 'raw', no_events : true});
  8648. });
  8649. }
  8650. tinymce.addUnload(t.destroy, t);
  8651. if (s.submit_patch) {
  8652. t.onBeforeRenderUI.add(function() {
  8653. var n = t.getElement().form;
  8654. if (!n)
  8655. return;
  8656. // Already patched
  8657. if (n._mceOldSubmit)
  8658. return;
  8659. // Check page uses id="submit" or name="submit" for it's submit button
  8660. if (!n.submit.nodeType && !n.submit.length) {
  8661. t.formElement = n;
  8662. n._mceOldSubmit = n.submit;
  8663. n.submit = function() {
  8664. // Save all instances
  8665. tinymce.triggerSave();
  8666. t.isNotDirty = 1;
  8667. return t.formElement._mceOldSubmit(t.formElement);
  8668. };
  8669. }
  8670. n = null;
  8671. });
  8672. }
  8673. // Load scripts
  8674. function loadScripts() {
  8675. if (s.language && s.language_load !== false)
  8676. sl.add(tinymce.baseURL + '/langs/' + s.language + '.js');
  8677. if (s.theme && s.theme.charAt(0) != '-' && !ThemeManager.urls[s.theme])
  8678. ThemeManager.load(s.theme, 'themes/' + s.theme + '/editor_template' + tinymce.suffix + '.js');
  8679. each(explode(s.plugins), function(p) {
  8680. if (p &&!PluginManager.urls[p]) {
  8681. if (p.charAt(0) == '-') {
  8682. p = p.substr(1, p.length);
  8683. var dependencies = PluginManager.dependencies(p);
  8684. each(dependencies, function(dep) {
  8685. var defaultSettings = {prefix:'plugins/', resource: dep, suffix:'/editor_plugin' + tinymce.suffix + '.js'};
  8686. var dep = PluginManager.createUrl(defaultSettings, dep);
  8687. PluginManager.load(dep.resource, dep);
  8688. });
  8689. } else {
  8690. // Skip safari plugin, since it is removed as of 3.3b1
  8691. if (p == 'safari') {
  8692. return;
  8693. }
  8694. PluginManager.load(p, {prefix:'plugins/', resource: p, suffix:'/editor_plugin' + tinymce.suffix + '.js'});
  8695. }
  8696. }
  8697. });
  8698. // Init when que is loaded
  8699. sl.loadQueue(function() {
  8700. if (!t.removed)
  8701. t.init();
  8702. });
  8703. };
  8704. loadScripts();
  8705. },
  8706. init : function() {
  8707. var n, t = this, s = t.settings, w, h, e = t.getElement(), o, ti, u, bi, bc, re, i, initializedPlugins = [];
  8708. tinymce.add(t);
  8709. s.aria_label = s.aria_label || DOM.getAttrib(e, 'aria-label', t.getLang('aria.rich_text_area'));
  8710. if (s.theme) {
  8711. s.theme = s.theme.replace(/-/, '');
  8712. o = ThemeManager.get(s.theme);
  8713. t.theme = new o();
  8714. if (t.theme.init && s.init_theme)
  8715. t.theme.init(t, ThemeManager.urls[s.theme] || tinymce.documentBaseURL.replace(/\/$/, ''));
  8716. }
  8717. function initPlugin(p) {
  8718. var c = PluginManager.get(p), u = PluginManager.urls[p] || tinymce.documentBaseURL.replace(/\/$/, ''), po;
  8719. if (c && tinymce.inArray(initializedPlugins,p) === -1) {
  8720. each(PluginManager.dependencies(p), function(dep){
  8721. initPlugin(dep);
  8722. });
  8723. po = new c(t, u);
  8724. t.plugins[p] = po;
  8725. if (po.init) {
  8726. po.init(t, u);
  8727. initializedPlugins.push(p);
  8728. }
  8729. }
  8730. }
  8731. // Create all plugins
  8732. each(explode(s.plugins.replace(/\-/g, '')), initPlugin);
  8733. // Setup popup CSS path(s)
  8734. if (s.popup_css !== false) {
  8735. if (s.popup_css)
  8736. s.popup_css = t.documentBaseURI.toAbsolute(s.popup_css);
  8737. else
  8738. s.popup_css = t.baseURI.toAbsolute("themes/" + s.theme + "/skins/" + s.skin + "/dialog.css");
  8739. }
  8740. if (s.popup_css_add)
  8741. s.popup_css += ',' + t.documentBaseURI.toAbsolute(s.popup_css_add);
  8742. t.controlManager = new tinymce.ControlManager(t);
  8743. if (s.custom_undo_redo) {
  8744. t.onBeforeExecCommand.add(function(ed, cmd, ui, val, a) {
  8745. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo))
  8746. t.undoManager.beforeChange();
  8747. });
  8748. t.onExecCommand.add(function(ed, cmd, ui, val, a) {
  8749. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo))
  8750. t.undoManager.add();
  8751. });
  8752. }
  8753. t.onExecCommand.add(function(ed, c) {
  8754. // Don't refresh the select lists until caret move
  8755. if (!/^(FontName|FontSize)$/.test(c))
  8756. t.nodeChanged();
  8757. });
  8758. // Remove ghost selections on images and tables in Gecko
  8759. if (isGecko) {
  8760. function repaint(a, o) {
  8761. if (!o || !o.initial)
  8762. t.execCommand('mceRepaint');
  8763. };
  8764. t.onUndo.add(repaint);
  8765. t.onRedo.add(repaint);
  8766. t.onSetContent.add(repaint);
  8767. }
  8768. // Enables users to override the control factory
  8769. t.onBeforeRenderUI.dispatch(t, t.controlManager);
  8770. // Measure box
  8771. if (s.render_ui) {
  8772. w = s.width || e.style.width || e.offsetWidth;
  8773. h = s.height || e.style.height || e.offsetHeight;
  8774. t.orgDisplay = e.style.display;
  8775. re = /^[0-9\.]+(|px)$/i;
  8776. if (re.test('' + w))
  8777. w = Math.max(parseInt(w) + (o.deltaWidth || 0), 100);
  8778. if (re.test('' + h))
  8779. h = Math.max(parseInt(h) + (o.deltaHeight || 0), 100);
  8780. // Render UI
  8781. o = t.theme.renderUI({
  8782. targetNode : e,
  8783. width : w,
  8784. height : h,
  8785. deltaWidth : s.delta_width,
  8786. deltaHeight : s.delta_height
  8787. });
  8788. t.editorContainer = o.editorContainer;
  8789. }
  8790. // User specified a document.domain value
  8791. if (document.domain && location.hostname != document.domain)
  8792. tinymce.relaxedDomain = document.domain;
  8793. // Resize editor
  8794. DOM.setStyles(o.sizeContainer || o.editorContainer, {
  8795. width : w,
  8796. height : h
  8797. });
  8798. // Load specified content CSS last
  8799. if (s.content_css) {
  8800. tinymce.each(explode(s.content_css), function(u) {
  8801. t.contentCSS.push(t.documentBaseURI.toAbsolute(u));
  8802. });
  8803. }
  8804. h = (o.iframeHeight || h) + (typeof(h) == 'number' ? (o.deltaHeight || 0) : '');
  8805. if (h < 100)
  8806. h = 100;
  8807. t.iframeHTML = s.doctype + '<html><head xmlns="http://www.w3.org/1999/xhtml">';
  8808. // We only need to override paths if we have to
  8809. // IE has a bug where it remove site absolute urls to relative ones if this is specified
  8810. if (s.document_base_url != tinymce.documentBaseURL)
  8811. t.iframeHTML += '<base href="' + t.documentBaseURI.getURI() + '" />';
  8812. // IE8 doesn't support carets behind images setting ie7_compat would force IE8+ to run in IE7 compat mode.
  8813. if (s.ie7_compat)
  8814. t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=7" />';
  8815. else
  8816. t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=edge" />';
  8817. t.iframeHTML += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
  8818. // Firefox 2 doesn't load stylesheets correctly this way
  8819. if (!isGecko || !/Firefox\/2/.test(navigator.userAgent)) {
  8820. for (i = 0; i < t.contentCSS.length; i++)
  8821. t.iframeHTML += '<link type="text/css" rel="stylesheet" href="' + t.contentCSS[i] + '" />';
  8822. t.contentCSS = [];
  8823. }
  8824. bi = s.body_id || 'tinymce';
  8825. if (bi.indexOf('=') != -1) {
  8826. bi = t.getParam('body_id', '', 'hash');
  8827. bi = bi[t.id] || bi;
  8828. }
  8829. bc = s.body_class || '';
  8830. if (bc.indexOf('=') != -1) {
  8831. bc = t.getParam('body_class', '', 'hash');
  8832. bc = bc[t.id] || '';
  8833. }
  8834. t.iframeHTML += '</head><body id="' + bi + '" class="mceContentBody ' + bc + '"></body></html>';
  8835. // Domain relaxing enabled, then set document domain
  8836. if (tinymce.relaxedDomain && (isIE || (tinymce.isOpera && parseFloat(opera.version()) < 11))) {
  8837. // We need to write the contents here in IE since multiple writes messes up refresh button and back button
  8838. u = 'javascript:(function(){document.open();document.domain="' + document.domain + '";var ed = window.parent.tinyMCE.get("' + t.id + '");document.write(ed.iframeHTML);document.close();ed.setupIframe();})()';
  8839. }
  8840. // Create iframe
  8841. // TODO: ACC add the appropriate description on this.
  8842. n = DOM.add(o.iframeContainer, 'iframe', {
  8843. id : t.id + "_ifr",
  8844. src : u || 'javascript:""', // Workaround for HTTPS warning in IE6/7
  8845. frameBorder : '0',
  8846. allowTransparency : "true",
  8847. title : s.aria_label,
  8848. style : {
  8849. width : '100%',
  8850. height : h
  8851. }
  8852. });
  8853. t.contentAreaContainer = o.iframeContainer;
  8854. DOM.get(o.editorContainer).style.display = t.orgDisplay;
  8855. DOM.get(t.id).style.display = 'none';
  8856. DOM.setAttrib(t.id, 'aria-hidden', true);
  8857. if (!tinymce.relaxedDomain || !u)
  8858. t.setupIframe();
  8859. e = n = o = null; // Cleanup
  8860. },
  8861. setupIframe : function(filled) {
  8862. var t = this, s = t.settings, e = DOM.get(t.id), d = t.getDoc(), h, b;
  8863. // Setup iframe body
  8864. if ((!isIE || !tinymce.relaxedDomain) && !filled) {
  8865. // We need to wait for the load event on Gecko
  8866. if (isGecko && !s.readonly) {
  8867. t.getWin().onload = function() {
  8868. window.setTimeout(function() {
  8869. var b = t.getBody(), undef;
  8870. // Editable element needs to have some contents or backspace/delete won't work properly for some odd reason on FF 3.6 or older
  8871. b.innerHTML = '<br>';
  8872. // Check if Gecko supports contentEditable mode FF2 doesn't
  8873. if (b.contentEditable !== undef) {
  8874. // Setting the contentEditable off/on seems to force caret mode in the editor and enabled auto focus
  8875. b.contentEditable = false;
  8876. b.contentEditable = true;
  8877. // Caret doesn't get rendered when you mousedown on the HTML element on FF 3.x
  8878. t.onMouseDown.add(function(ed, e) {
  8879. if (e.target.nodeName === "HTML") {
  8880. d.designMode = 'on'; // Render the caret
  8881. // Remove design mode again after a while so it has some time to execute
  8882. window.setTimeout(function() {
  8883. d.designMode = 'off';
  8884. t.getBody().focus();
  8885. }, 1);
  8886. }
  8887. });
  8888. } else
  8889. d.designMode = 'on';
  8890. // Call setup frame once the contentEditable/designMode has been initialized
  8891. // since the caret won't be rendered some times otherwise.
  8892. t.setupIframe(true);
  8893. }, 1);
  8894. };
  8895. }
  8896. d.open();
  8897. d.write(t.iframeHTML);
  8898. d.close();
  8899. if (tinymce.relaxedDomain)
  8900. d.domain = tinymce.relaxedDomain;
  8901. // Wait for iframe onload event on Gecko
  8902. if (isGecko && !s.readonly)
  8903. return;
  8904. }
  8905. // It will not steal focus while setting contentEditable
  8906. b = t.getBody();
  8907. b.disabled = true;
  8908. if (!isGecko && !s.readonly)
  8909. b.contentEditable = true;
  8910. b.disabled = false;
  8911. t.schema = new tinymce.html.Schema(s);
  8912. t.dom = new tinymce.dom.DOMUtils(t.getDoc(), {
  8913. keep_values : true,
  8914. url_converter : t.convertURL,
  8915. url_converter_scope : t,
  8916. hex_colors : s.force_hex_style_colors,
  8917. class_filter : s.class_filter,
  8918. update_styles : 1,
  8919. fix_ie_paragraphs : 1,
  8920. schema : t.schema
  8921. });
  8922. t.parser = new tinymce.html.DomParser(s, t.schema);
  8923. // Force anchor names closed, unless the setting "allow_html_in_named_anchor" is explicitly included.
  8924. if (!t.settings.allow_html_in_named_anchor) {
  8925. t.parser.addAttributeFilter('name', function(nodes, name) {
  8926. var i = nodes.length, sibling, prevSibling, parent, node;
  8927. while (i--) {
  8928. node = nodes[i];
  8929. if (node.name === 'a' && node.firstChild) {
  8930. parent = node.parent;
  8931. // Move children after current node
  8932. sibling = node.lastChild;
  8933. do {
  8934. prevSibling = sibling.prev;
  8935. parent.insert(sibling, node);
  8936. sibling = prevSibling;
  8937. } while (sibling);
  8938. }
  8939. }
  8940. });
  8941. }
  8942. // Convert src and href into data-mce-src, data-mce-href and data-mce-style
  8943. t.parser.addAttributeFilter('src,href,style', function(nodes, name) {
  8944. var i = nodes.length, node, dom = t.dom, value, internalName;
  8945. while (i--) {
  8946. node = nodes[i];
  8947. value = node.attr(name);
  8948. internalName = 'data-mce-' + name;
  8949. // Add internal attribute if we need to we don't on a refresh of the document
  8950. if (!node.attributes.map[internalName]) {
  8951. if (name === "style")
  8952. node.attr(internalName, dom.serializeStyle(dom.parseStyle(value), node.name));
  8953. else
  8954. node.attr(internalName, t.convertURL(value, name, node.name));
  8955. }
  8956. }
  8957. });
  8958. // Keep scripts from executing
  8959. t.parser.addNodeFilter('script', function(nodes, name) {
  8960. var i = nodes.length;
  8961. while (i--)
  8962. nodes[i].attr('type', 'mce-text/javascript');
  8963. });
  8964. t.parser.addNodeFilter('#cdata', function(nodes, name) {
  8965. var i = nodes.length, node;
  8966. while (i--) {
  8967. node = nodes[i];
  8968. node.type = 8;
  8969. node.name = '#comment';
  8970. node.value = '[CDATA[' + node.value + ']]';
  8971. }
  8972. });
  8973. t.parser.addNodeFilter('p,h1,h2,h3,h4,h5,h6,div', function(nodes, name) {
  8974. var i = nodes.length, node, nonEmptyElements = t.schema.getNonEmptyElements();
  8975. while (i--) {
  8976. node = nodes[i];
  8977. if (node.isEmpty(nonEmptyElements))
  8978. node.empty().append(new tinymce.html.Node('br', 1)).shortEnded = true;
  8979. }
  8980. });
  8981. t.serializer = new tinymce.dom.Serializer(s, t.dom, t.schema);
  8982. t.selection = new tinymce.dom.Selection(t.dom, t.getWin(), t.serializer);
  8983. t.formatter = new tinymce.Formatter(this);
  8984. // Register default formats
  8985. t.formatter.register({
  8986. alignleft : [
  8987. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}},
  8988. {selector : 'img,table', collapsed : false, styles : {'float' : 'left'}}
  8989. ],
  8990. aligncenter : [
  8991. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}},
  8992. {selector : 'img', collapsed : false, styles : {display : 'block', marginLeft : 'auto', marginRight : 'auto'}},
  8993. {selector : 'table', collapsed : false, styles : {marginLeft : 'auto', marginRight : 'auto'}}
  8994. ],
  8995. alignright : [
  8996. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}},
  8997. {selector : 'img,table', collapsed : false, styles : {'float' : 'right'}}
  8998. ],
  8999. alignfull : [
  9000. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'justify'}}
  9001. ],
  9002. bold : [
  9003. {inline : 'strong', remove : 'all'},
  9004. {inline : 'span', styles : {fontWeight : 'bold'}},
  9005. {inline : 'b', remove : 'all'}
  9006. ],
  9007. italic : [
  9008. {inline : 'em', remove : 'all'},
  9009. {inline : 'span', styles : {fontStyle : 'italic'}},
  9010. {inline : 'i', remove : 'all'}
  9011. ],
  9012. underline : [
  9013. {inline : 'span', styles : {textDecoration : 'underline'}, exact : true},
  9014. {inline : 'u', remove : 'all'}
  9015. ],
  9016. strikethrough : [
  9017. {inline : 'span', styles : {textDecoration : 'line-through'}, exact : true},
  9018. {inline : 'strike', remove : 'all'}
  9019. ],
  9020. forecolor : {inline : 'span', styles : {color : '%value'}, wrap_links : false},
  9021. hilitecolor : {inline : 'span', styles : {backgroundColor : '%value'}, wrap_links : false},
  9022. fontname : {inline : 'span', styles : {fontFamily : '%value'}},
  9023. fontsize : {inline : 'span', styles : {fontSize : '%value'}},
  9024. fontsize_class : {inline : 'span', attributes : {'class' : '%value'}},
  9025. blockquote : {block : 'blockquote', wrapper : 1, remove : 'all'},
  9026. subscript : {inline : 'sub'},
  9027. superscript : {inline : 'sup'},
  9028. removeformat : [
  9029. {selector : 'b,strong,em,i,font,u,strike', remove : 'all', split : true, expand : false, block_expand : true, deep : true},
  9030. {selector : 'span', attributes : ['style', 'class'], remove : 'empty', split : true, expand : false, deep : true},
  9031. {selector : '*', attributes : ['style', 'class'], split : false, expand : false, deep : true}
  9032. ]
  9033. });
  9034. // Register default block formats
  9035. each('p h1 h2 h3 h4 h5 h6 div address pre div code dt dd samp'.split(/\s/), function(name) {
  9036. t.formatter.register(name, {block : name, remove : 'all'});
  9037. });
  9038. // Register user defined formats
  9039. t.formatter.register(t.settings.formats);
  9040. t.undoManager = new tinymce.UndoManager(t);
  9041. // Pass through
  9042. t.undoManager.onAdd.add(function(um, l) {
  9043. if (um.hasUndo())
  9044. return t.onChange.dispatch(t, l, um);
  9045. });
  9046. t.undoManager.onUndo.add(function(um, l) {
  9047. return t.onUndo.dispatch(t, l, um);
  9048. });
  9049. t.undoManager.onRedo.add(function(um, l) {
  9050. return t.onRedo.dispatch(t, l, um);
  9051. });
  9052. t.forceBlocks = new tinymce.ForceBlocks(t, {
  9053. forced_root_block : s.forced_root_block
  9054. });
  9055. t.editorCommands = new tinymce.EditorCommands(t);
  9056. // Pass through
  9057. t.serializer.onPreProcess.add(function(se, o) {
  9058. return t.onPreProcess.dispatch(t, o, se);
  9059. });
  9060. t.serializer.onPostProcess.add(function(se, o) {
  9061. return t.onPostProcess.dispatch(t, o, se);
  9062. });
  9063. t.onPreInit.dispatch(t);
  9064. if (!s.gecko_spellcheck)
  9065. t.getBody().spellcheck = 0;
  9066. if (!s.readonly)
  9067. t._addEvents();
  9068. t.controlManager.onPostRender.dispatch(t, t.controlManager);
  9069. t.onPostRender.dispatch(t);
  9070. if (s.directionality)
  9071. t.getBody().dir = s.directionality;
  9072. if (s.nowrap)
  9073. t.getBody().style.whiteSpace = "nowrap";
  9074. if (s.handle_node_change_callback) {
  9075. t.onNodeChange.add(function(ed, cm, n) {
  9076. t.execCallback('handle_node_change_callback', t.id, n, -1, -1, true, t.selection.isCollapsed());
  9077. });
  9078. }
  9079. if (s.save_callback) {
  9080. t.onSaveContent.add(function(ed, o) {
  9081. var h = t.execCallback('save_callback', t.id, o.content, t.getBody());
  9082. if (h)
  9083. o.content = h;
  9084. });
  9085. }
  9086. if (s.onchange_callback) {
  9087. t.onChange.add(function(ed, l) {
  9088. t.execCallback('onchange_callback', t, l);
  9089. });
  9090. }
  9091. if (s.protect) {
  9092. t.onBeforeSetContent.add(function(ed, o) {
  9093. if (s.protect) {
  9094. each(s.protect, function(pattern) {
  9095. o.content = o.content.replace(pattern, function(str) {
  9096. return '<!--mce:protected ' + escape(str) + '-->';
  9097. });
  9098. });
  9099. }
  9100. });
  9101. }
  9102. if (s.convert_newlines_to_brs) {
  9103. t.onBeforeSetContent.add(function(ed, o) {
  9104. if (o.initial)
  9105. o.content = o.content.replace(/\r?\n/g, '<br />');
  9106. });
  9107. }
  9108. if (s.preformatted) {
  9109. t.onPostProcess.add(function(ed, o) {
  9110. o.content = o.content.replace(/^\s*<pre.*?>/, '');
  9111. o.content = o.content.replace(/<\/pre>\s*$/, '');
  9112. if (o.set)
  9113. o.content = '<pre class="mceItemHidden">' + o.content + '</pre>';
  9114. });
  9115. }
  9116. if (s.verify_css_classes) {
  9117. t.serializer.attribValueFilter = function(n, v) {
  9118. var s, cl;
  9119. if (n == 'class') {
  9120. // Build regexp for classes
  9121. if (!t.classesRE) {
  9122. cl = t.dom.getClasses();
  9123. if (cl.length > 0) {
  9124. s = '';
  9125. each (cl, function(o) {
  9126. s += (s ? '|' : '') + o['class'];
  9127. });
  9128. t.classesRE = new RegExp('(' + s + ')', 'gi');
  9129. }
  9130. }
  9131. return !t.classesRE || /(\bmceItem\w+\b|\bmceTemp\w+\b)/g.test(v) || t.classesRE.test(v) ? v : '';
  9132. }
  9133. return v;
  9134. };
  9135. }
  9136. if (s.cleanup_callback) {
  9137. t.onBeforeSetContent.add(function(ed, o) {
  9138. o.content = t.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  9139. });
  9140. t.onPreProcess.add(function(ed, o) {
  9141. if (o.set)
  9142. t.execCallback('cleanup_callback', 'insert_to_editor_dom', o.node, o);
  9143. if (o.get)
  9144. t.execCallback('cleanup_callback', 'get_from_editor_dom', o.node, o);
  9145. });
  9146. t.onPostProcess.add(function(ed, o) {
  9147. if (o.set)
  9148. o.content = t.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  9149. if (o.get)
  9150. o.content = t.execCallback('cleanup_callback', 'get_from_editor', o.content, o);
  9151. });
  9152. }
  9153. if (s.save_callback) {
  9154. t.onGetContent.add(function(ed, o) {
  9155. if (o.save)
  9156. o.content = t.execCallback('save_callback', t.id, o.content, t.getBody());
  9157. });
  9158. }
  9159. if (s.handle_event_callback) {
  9160. t.onEvent.add(function(ed, e, o) {
  9161. if (t.execCallback('handle_event_callback', e, ed, o) === false)
  9162. Event.cancel(e);
  9163. });
  9164. }
  9165. // Add visual aids when new contents is added
  9166. t.onSetContent.add(function() {
  9167. t.addVisual(t.getBody());
  9168. });
  9169. // Remove empty contents
  9170. if (s.padd_empty_editor) {
  9171. t.onPostProcess.add(function(ed, o) {
  9172. o.content = o.content.replace(/^(<p[^>]*>(&nbsp;|&#160;|\s|\u00a0|)<\/p>[\r\n]*|<br \/>[\r\n]*)$/, '');
  9173. });
  9174. }
  9175. if (isGecko) {
  9176. // Fix gecko link bug, when a link is placed at the end of block elements there is
  9177. // no way to move the caret behind the link. This fix adds a bogus br element after the link
  9178. function fixLinks(ed, o) {
  9179. each(ed.dom.select('a'), function(n) {
  9180. var pn = n.parentNode;
  9181. if (ed.dom.isBlock(pn) && pn.lastChild === n)
  9182. ed.dom.add(pn, 'br', {'data-mce-bogus' : 1});
  9183. });
  9184. };
  9185. t.onExecCommand.add(function(ed, cmd) {
  9186. if (cmd === 'CreateLink')
  9187. fixLinks(ed);
  9188. });
  9189. t.onSetContent.add(t.selection.onSetContent.add(fixLinks));
  9190. }
  9191. t.load({initial : true, format : 'html'});
  9192. t.startContent = t.getContent({format : 'raw'});
  9193. t.undoManager.add();
  9194. t.initialized = true;
  9195. t.onInit.dispatch(t);
  9196. t.execCallback('setupcontent_callback', t.id, t.getBody(), t.getDoc());
  9197. t.execCallback('init_instance_callback', t);
  9198. t.focus(true);
  9199. t.nodeChanged({initial : 1});
  9200. // Load specified content CSS last
  9201. each(t.contentCSS, function(u) {
  9202. t.dom.loadCSS(u);
  9203. });
  9204. // Handle auto focus
  9205. if (s.auto_focus) {
  9206. setTimeout(function () {
  9207. var ed = tinymce.get(s.auto_focus);
  9208. ed.selection.select(ed.getBody(), 1);
  9209. ed.selection.collapse(1);
  9210. ed.getBody().focus();
  9211. ed.getWin().focus();
  9212. }, 100);
  9213. }
  9214. e = null;
  9215. },
  9216. focus : function(sf) {
  9217. var oed, t = this, ce = t.settings.content_editable, ieRng, controlElm, doc = t.getDoc();
  9218. if (!sf) {
  9219. // Get selected control element
  9220. ieRng = t.selection.getRng();
  9221. if (ieRng.item) {
  9222. controlElm = ieRng.item(0);
  9223. }
  9224. // Is not content editable
  9225. if (!ce)
  9226. t.getWin().focus();
  9227. // Restore selected control element
  9228. // This is needed when for example an image is selected within a
  9229. // layer a call to focus will then remove the control selection
  9230. if (controlElm && controlElm.ownerDocument == doc) {
  9231. ieRng = doc.body.createControlRange();
  9232. ieRng.addElement(controlElm);
  9233. ieRng.select();
  9234. }
  9235. }
  9236. if (tinymce.activeEditor != t) {
  9237. if ((oed = tinymce.activeEditor) != null)
  9238. oed.onDeactivate.dispatch(oed, t);
  9239. t.onActivate.dispatch(t, oed);
  9240. }
  9241. tinymce._setActive(t);
  9242. },
  9243. execCallback : function(n) {
  9244. var t = this, f = t.settings[n], s;
  9245. if (!f)
  9246. return;
  9247. // Look through lookup
  9248. if (t.callbackLookup && (s = t.callbackLookup[n])) {
  9249. f = s.func;
  9250. s = s.scope;
  9251. }
  9252. if (is(f, 'string')) {
  9253. s = f.replace(/\.\w+$/, '');
  9254. s = s ? tinymce.resolve(s) : 0;
  9255. f = tinymce.resolve(f);
  9256. t.callbackLookup = t.callbackLookup || {};
  9257. t.callbackLookup[n] = {func : f, scope : s};
  9258. }
  9259. return f.apply(s || t, Array.prototype.slice.call(arguments, 1));
  9260. },
  9261. translate : function(s) {
  9262. var c = this.settings.language || 'en', i18n = tinymce.i18n;
  9263. if (!s)
  9264. return '';
  9265. return i18n[c + '.' + s] || s.replace(/{\#([^}]+)\}/g, function(a, b) {
  9266. return i18n[c + '.' + b] || '{#' + b + '}';
  9267. });
  9268. },
  9269. getLang : function(n, dv) {
  9270. return tinymce.i18n[(this.settings.language || 'en') + '.' + n] || (is(dv) ? dv : '{#' + n + '}');
  9271. },
  9272. getParam : function(n, dv, ty) {
  9273. var tr = tinymce.trim, v = is(this.settings[n]) ? this.settings[n] : dv, o;
  9274. if (ty === 'hash') {
  9275. o = {};
  9276. if (is(v, 'string')) {
  9277. each(v.indexOf('=') > 0 ? v.split(/[;,](?![^=;,]*(?:[;,]|$))/) : v.split(','), function(v) {
  9278. v = v.split('=');
  9279. if (v.length > 1)
  9280. o[tr(v[0])] = tr(v[1]);
  9281. else
  9282. o[tr(v[0])] = tr(v);
  9283. });
  9284. } else
  9285. o = v;
  9286. return o;
  9287. }
  9288. return v;
  9289. },
  9290. nodeChanged : function(o) {
  9291. var t = this, s = t.selection, n = s.getStart() || t.getBody();
  9292. // Fix for bug #1896577 it seems that this can not be fired while the editor is loading
  9293. if (t.initialized) {
  9294. o = o || {};
  9295. n = isIE && n.ownerDocument != t.getDoc() ? t.getBody() : n; // Fix for IE initial state
  9296. // Get parents and add them to object
  9297. o.parents = [];
  9298. t.dom.getParent(n, function(node) {
  9299. if (node.nodeName == 'BODY')
  9300. return true;
  9301. o.parents.push(node);
  9302. });
  9303. t.onNodeChange.dispatch(
  9304. t,
  9305. o ? o.controlManager || t.controlManager : t.controlManager,
  9306. n,
  9307. s.isCollapsed(),
  9308. o
  9309. );
  9310. }
  9311. },
  9312. addButton : function(n, s) {
  9313. var t = this;
  9314. t.buttons = t.buttons || {};
  9315. t.buttons[n] = s;
  9316. },
  9317. addCommand : function(name, callback, scope) {
  9318. this.execCommands[name] = {func : callback, scope : scope || this};
  9319. },
  9320. addQueryStateHandler : function(name, callback, scope) {
  9321. this.queryStateCommands[name] = {func : callback, scope : scope || this};
  9322. },
  9323. addQueryValueHandler : function(name, callback, scope) {
  9324. this.queryValueCommands[name] = {func : callback, scope : scope || this};
  9325. },
  9326. addShortcut : function(pa, desc, cmd_func, sc) {
  9327. var t = this, c;
  9328. if (!t.settings.custom_shortcuts)
  9329. return false;
  9330. t.shortcuts = t.shortcuts || {};
  9331. if (is(cmd_func, 'string')) {
  9332. c = cmd_func;
  9333. cmd_func = function() {
  9334. t.execCommand(c, false, null);
  9335. };
  9336. }
  9337. if (is(cmd_func, 'object')) {
  9338. c = cmd_func;
  9339. cmd_func = function() {
  9340. t.execCommand(c[0], c[1], c[2]);
  9341. };
  9342. }
  9343. each(explode(pa), function(pa) {
  9344. var o = {
  9345. func : cmd_func,
  9346. scope : sc || this,
  9347. desc : desc,
  9348. alt : false,
  9349. ctrl : false,
  9350. shift : false
  9351. };
  9352. each(explode(pa, '+'), function(v) {
  9353. switch (v) {
  9354. case 'alt':
  9355. case 'ctrl':
  9356. case 'shift':
  9357. o[v] = true;
  9358. break;
  9359. default:
  9360. o.charCode = v.charCodeAt(0);
  9361. o.keyCode = v.toUpperCase().charCodeAt(0);
  9362. }
  9363. });
  9364. t.shortcuts[(o.ctrl ? 'ctrl' : '') + ',' + (o.alt ? 'alt' : '') + ',' + (o.shift ? 'shift' : '') + ',' + o.keyCode] = o;
  9365. });
  9366. return true;
  9367. },
  9368. execCommand : function(cmd, ui, val, a) {
  9369. var t = this, s = 0, o, st;
  9370. if (!/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint|SelectAll)$/.test(cmd) && (!a || !a.skip_focus))
  9371. t.focus();
  9372. o = {};
  9373. t.onBeforeExecCommand.dispatch(t, cmd, ui, val, o);
  9374. if (o.terminate)
  9375. return false;
  9376. // Command callback
  9377. if (t.execCallback('execcommand_callback', t.id, t.selection.getNode(), cmd, ui, val)) {
  9378. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9379. return true;
  9380. }
  9381. // Registred commands
  9382. if (o = t.execCommands[cmd]) {
  9383. st = o.func.call(o.scope, ui, val);
  9384. // Fall through on true
  9385. if (st !== true) {
  9386. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9387. return st;
  9388. }
  9389. }
  9390. // Plugin commands
  9391. each(t.plugins, function(p) {
  9392. if (p.execCommand && p.execCommand(cmd, ui, val)) {
  9393. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9394. s = 1;
  9395. return false;
  9396. }
  9397. });
  9398. if (s)
  9399. return true;
  9400. // Theme commands
  9401. if (t.theme && t.theme.execCommand && t.theme.execCommand(cmd, ui, val)) {
  9402. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9403. return true;
  9404. }
  9405. // Editor commands
  9406. if (t.editorCommands.execCommand(cmd, ui, val)) {
  9407. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9408. return true;
  9409. }
  9410. // Browser commands
  9411. t.getDoc().execCommand(cmd, ui, val);
  9412. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9413. },
  9414. queryCommandState : function(cmd) {
  9415. var t = this, o, s;
  9416. // Is hidden then return undefined
  9417. if (t._isHidden())
  9418. return;
  9419. // Registred commands
  9420. if (o = t.queryStateCommands[cmd]) {
  9421. s = o.func.call(o.scope);
  9422. // Fall though on true
  9423. if (s !== true)
  9424. return s;
  9425. }
  9426. // Registred commands
  9427. o = t.editorCommands.queryCommandState(cmd);
  9428. if (o !== -1)
  9429. return o;
  9430. // Browser commands
  9431. try {
  9432. return this.getDoc().queryCommandState(cmd);
  9433. } catch (ex) {
  9434. // Fails sometimes see bug: 1896577
  9435. }
  9436. },
  9437. queryCommandValue : function(c) {
  9438. var t = this, o, s;
  9439. // Is hidden then return undefined
  9440. if (t._isHidden())
  9441. return;
  9442. // Registred commands
  9443. if (o = t.queryValueCommands[c]) {
  9444. s = o.func.call(o.scope);
  9445. // Fall though on true
  9446. if (s !== true)
  9447. return s;
  9448. }
  9449. // Registred commands
  9450. o = t.editorCommands.queryCommandValue(c);
  9451. if (is(o))
  9452. return o;
  9453. // Browser commands
  9454. try {
  9455. return this.getDoc().queryCommandValue(c);
  9456. } catch (ex) {
  9457. // Fails sometimes see bug: 1896577
  9458. }
  9459. },
  9460. show : function() {
  9461. var t = this;
  9462. DOM.show(t.getContainer());
  9463. DOM.hide(t.id);
  9464. t.load();
  9465. },
  9466. hide : function() {
  9467. var t = this, d = t.getDoc();
  9468. // Fixed bug where IE has a blinking cursor left from the editor
  9469. if (isIE && d)
  9470. d.execCommand('SelectAll');
  9471. // We must save before we hide so Safari doesn't crash
  9472. t.save();
  9473. DOM.hide(t.getContainer());
  9474. DOM.setStyle(t.id, 'display', t.orgDisplay);
  9475. },
  9476. isHidden : function() {
  9477. return !DOM.isHidden(this.id);
  9478. },
  9479. setProgressState : function(b, ti, o) {
  9480. this.onSetProgressState.dispatch(this, b, ti, o);
  9481. return b;
  9482. },
  9483. load : function(o) {
  9484. var t = this, e = t.getElement(), h;
  9485. if (e) {
  9486. o = o || {};
  9487. o.load = true;
  9488. // Double encode existing entities in the value
  9489. h = t.setContent(is(e.value) ? e.value : e.innerHTML, o);
  9490. o.element = e;
  9491. if (!o.no_events)
  9492. t.onLoadContent.dispatch(t, o);
  9493. o.element = e = null;
  9494. return h;
  9495. }
  9496. },
  9497. save : function(o) {
  9498. var t = this, e = t.getElement(), h, f;
  9499. if (!e || !t.initialized)
  9500. return;
  9501. o = o || {};
  9502. o.save = true;
  9503. // Add undo level will trigger onchange event
  9504. if (!o.no_events) {
  9505. t.undoManager.typing = false;
  9506. t.undoManager.add();
  9507. }
  9508. o.element = e;
  9509. h = o.content = t.getContent(o);
  9510. if (!o.no_events)
  9511. t.onSaveContent.dispatch(t, o);
  9512. h = o.content;
  9513. if (!/TEXTAREA|INPUT/i.test(e.nodeName)) {
  9514. e.innerHTML = h;
  9515. // Update hidden form element
  9516. if (f = DOM.getParent(t.id, 'form')) {
  9517. each(f.elements, function(e) {
  9518. if (e.name == t.id) {
  9519. e.value = h;
  9520. return false;
  9521. }
  9522. });
  9523. }
  9524. } else
  9525. e.value = h;
  9526. o.element = e = null;
  9527. return h;
  9528. },
  9529. setContent : function(content, args) {
  9530. var self = this, rootNode, body = self.getBody(), forcedRootBlockName;
  9531. // Setup args object
  9532. args = args || {};
  9533. args.format = args.format || 'html';
  9534. args.set = true;
  9535. args.content = content;
  9536. // Do preprocessing
  9537. if (!args.no_events)
  9538. self.onBeforeSetContent.dispatch(self, args);
  9539. content = args.content;
  9540. // Padd empty content in Gecko and Safari. Commands will otherwise fail on the content
  9541. // It will also be impossible to place the caret in the editor unless there is a BR element present
  9542. if (!tinymce.isIE && (content.length === 0 || /^\s+$/.test(content))) {
  9543. forcedRootBlockName = self.settings.forced_root_block;
  9544. if (forcedRootBlockName)
  9545. content = '<' + forcedRootBlockName + '><br data-mce-bogus="1"></' + forcedRootBlockName + '>';
  9546. else
  9547. content = '<br data-mce-bogus="1">';
  9548. body.innerHTML = content;
  9549. self.selection.select(body, true);
  9550. self.selection.collapse(true);
  9551. return;
  9552. }
  9553. // Parse and serialize the html
  9554. if (args.format !== 'raw') {
  9555. content = new tinymce.html.Serializer({}, self.schema).serialize(
  9556. self.parser.parse(content)
  9557. );
  9558. }
  9559. // Set the new cleaned contents to the editor
  9560. args.content = tinymce.trim(content);
  9561. self.dom.setHTML(body, args.content);
  9562. // Do post processing
  9563. if (!args.no_events)
  9564. self.onSetContent.dispatch(self, args);
  9565. return args.content;
  9566. },
  9567. getContent : function(args) {
  9568. var self = this, content;
  9569. // Setup args object
  9570. args = args || {};
  9571. args.format = args.format || 'html';
  9572. args.get = true;
  9573. // Do preprocessing
  9574. if (!args.no_events)
  9575. self.onBeforeGetContent.dispatch(self, args);
  9576. // Get raw contents or by default the cleaned contents
  9577. if (args.format == 'raw')
  9578. content = self.getBody().innerHTML;
  9579. else
  9580. content = self.serializer.serialize(self.getBody(), args);
  9581. args.content = tinymce.trim(content);
  9582. // Do post processing
  9583. if (!args.no_events)
  9584. self.onGetContent.dispatch(self, args);
  9585. return args.content;
  9586. },
  9587. isDirty : function() {
  9588. var self = this;
  9589. return tinymce.trim(self.startContent) != tinymce.trim(self.getContent({format : 'raw', no_events : 1})) && !self.isNotDirty;
  9590. },
  9591. getContainer : function() {
  9592. var t = this;
  9593. if (!t.container)
  9594. t.container = DOM.get(t.editorContainer || t.id + '_parent');
  9595. return t.container;
  9596. },
  9597. getContentAreaContainer : function() {
  9598. return this.contentAreaContainer;
  9599. },
  9600. getElement : function() {
  9601. return DOM.get(this.settings.content_element || this.id);
  9602. },
  9603. getWin : function() {
  9604. var t = this, e;
  9605. if (!t.contentWindow) {
  9606. e = DOM.get(t.id + "_ifr");
  9607. if (e)
  9608. t.contentWindow = e.contentWindow;
  9609. }
  9610. return t.contentWindow;
  9611. },
  9612. getDoc : function() {
  9613. var t = this, w;
  9614. if (!t.contentDocument) {
  9615. w = t.getWin();
  9616. if (w)
  9617. t.contentDocument = w.document;
  9618. }
  9619. return t.contentDocument;
  9620. },
  9621. getBody : function() {
  9622. return this.bodyElement || this.getDoc().body;
  9623. },
  9624. convertURL : function(u, n, e) {
  9625. var t = this, s = t.settings;
  9626. // Use callback instead
  9627. if (s.urlconverter_callback)
  9628. return t.execCallback('urlconverter_callback', u, e, true, n);
  9629. // Don't convert link href since thats the CSS files that gets loaded into the editor also skip local file URLs
  9630. if (!s.convert_urls || (e && e.nodeName == 'LINK') || u.indexOf('file:') === 0)
  9631. return u;
  9632. // Convert to relative
  9633. if (s.relative_urls)
  9634. return t.documentBaseURI.toRelative(u);
  9635. // Convert to absolute
  9636. u = t.documentBaseURI.toAbsolute(u, s.remove_script_host);
  9637. return u;
  9638. },
  9639. addVisual : function(e) {
  9640. var t = this, s = t.settings;
  9641. e = e || t.getBody();
  9642. if (!is(t.hasVisual))
  9643. t.hasVisual = s.visual;
  9644. each(t.dom.select('table,a', e), function(e) {
  9645. var v;
  9646. switch (e.nodeName) {
  9647. case 'TABLE':
  9648. v = t.dom.getAttrib(e, 'border');
  9649. if (!v || v == '0') {
  9650. if (t.hasVisual)
  9651. t.dom.addClass(e, s.visual_table_class);
  9652. else
  9653. t.dom.removeClass(e, s.visual_table_class);
  9654. }
  9655. return;
  9656. case 'A':
  9657. v = t.dom.getAttrib(e, 'name');
  9658. if (v) {
  9659. if (t.hasVisual)
  9660. t.dom.addClass(e, 'mceItemAnchor');
  9661. else
  9662. t.dom.removeClass(e, 'mceItemAnchor');
  9663. }
  9664. return;
  9665. }
  9666. });
  9667. t.onVisualAid.dispatch(t, e, t.hasVisual);
  9668. },
  9669. remove : function() {
  9670. var t = this, e = t.getContainer();
  9671. t.removed = 1; // Cancels post remove event execution
  9672. t.hide();
  9673. t.execCallback('remove_instance_callback', t);
  9674. t.onRemove.dispatch(t);
  9675. // Clear all execCommand listeners this is required to avoid errors if the editor was removed inside another command
  9676. t.onExecCommand.listeners = [];
  9677. tinymce.remove(t);
  9678. DOM.remove(e);
  9679. },
  9680. destroy : function(s) {
  9681. var t = this;
  9682. // One time is enough
  9683. if (t.destroyed)
  9684. return;
  9685. if (!s) {
  9686. tinymce.removeUnload(t.destroy);
  9687. tinyMCE.onBeforeUnload.remove(t._beforeUnload);
  9688. // Manual destroy
  9689. if (t.theme && t.theme.destroy)
  9690. t.theme.destroy();
  9691. // Destroy controls, selection and dom
  9692. t.controlManager.destroy();
  9693. t.selection.destroy();
  9694. t.dom.destroy();
  9695. // Remove all events
  9696. // Don't clear the window or document if content editable
  9697. // is enabled since other instances might still be present
  9698. if (!t.settings.content_editable) {
  9699. Event.clear(t.getWin());
  9700. Event.clear(t.getDoc());
  9701. }
  9702. Event.clear(t.getBody());
  9703. Event.clear(t.formElement);
  9704. }
  9705. if (t.formElement) {
  9706. t.formElement.submit = t.formElement._mceOldSubmit;
  9707. t.formElement._mceOldSubmit = null;
  9708. }
  9709. t.contentAreaContainer = t.formElement = t.container = t.settings.content_element = t.bodyElement = t.contentDocument = t.contentWindow = null;
  9710. if (t.selection)
  9711. t.selection = t.selection.win = t.selection.dom = t.selection.dom.doc = null;
  9712. t.destroyed = 1;
  9713. },
  9714. // Internal functions
  9715. _addEvents : function() {
  9716. // 'focus', 'blur', 'dblclick', 'beforedeactivate', submit, reset
  9717. var t = this, i, s = t.settings, dom = t.dom, lo = {
  9718. mouseup : 'onMouseUp',
  9719. mousedown : 'onMouseDown',
  9720. click : 'onClick',
  9721. keyup : 'onKeyUp',
  9722. keydown : 'onKeyDown',
  9723. keypress : 'onKeyPress',
  9724. submit : 'onSubmit',
  9725. reset : 'onReset',
  9726. contextmenu : 'onContextMenu',
  9727. dblclick : 'onDblClick',
  9728. paste : 'onPaste' // Doesn't work in all browsers yet
  9729. };
  9730. function eventHandler(e, o) {
  9731. var ty = e.type;
  9732. // Don't fire events when it's removed
  9733. if (t.removed)
  9734. return;
  9735. // Generic event handler
  9736. if (t.onEvent.dispatch(t, e, o) !== false) {
  9737. // Specific event handler
  9738. t[lo[e.fakeType || e.type]].dispatch(t, e, o);
  9739. }
  9740. };
  9741. // Add DOM events
  9742. each(lo, function(v, k) {
  9743. switch (k) {
  9744. case 'contextmenu':
  9745. dom.bind(t.getDoc(), k, eventHandler);
  9746. break;
  9747. case 'paste':
  9748. dom.bind(t.getBody(), k, function(e) {
  9749. eventHandler(e);
  9750. });
  9751. break;
  9752. case 'submit':
  9753. case 'reset':
  9754. dom.bind(t.getElement().form || DOM.getParent(t.id, 'form'), k, eventHandler);
  9755. break;
  9756. default:
  9757. dom.bind(s.content_editable ? t.getBody() : t.getDoc(), k, eventHandler);
  9758. }
  9759. });
  9760. dom.bind(s.content_editable ? t.getBody() : (isGecko ? t.getDoc() : t.getWin()), 'focus', function(e) {
  9761. t.focus(true);
  9762. });
  9763. // Fixes bug where a specified document_base_uri could result in broken images
  9764. // This will also fix drag drop of images in Gecko
  9765. if (tinymce.isGecko) {
  9766. dom.bind(t.getDoc(), 'DOMNodeInserted', function(e) {
  9767. var v;
  9768. e = e.target;
  9769. if (e.nodeType === 1 && e.nodeName === 'IMG' && (v = e.getAttribute('data-mce-src')))
  9770. e.src = t.documentBaseURI.toAbsolute(v);
  9771. });
  9772. }
  9773. // Set various midas options in Gecko
  9774. if (isGecko) {
  9775. function setOpts() {
  9776. var t = this, d = t.getDoc(), s = t.settings;
  9777. if (isGecko && !s.readonly) {
  9778. if (t._isHidden()) {
  9779. try {
  9780. if (!s.content_editable) {
  9781. d.body.contentEditable = false;
  9782. d.body.contentEditable = true;
  9783. }
  9784. } catch (ex) {
  9785. // Fails if it's hidden
  9786. }
  9787. }
  9788. try {
  9789. // Try new Gecko method
  9790. d.execCommand("styleWithCSS", 0, false);
  9791. } catch (ex) {
  9792. // Use old method
  9793. if (!t._isHidden())
  9794. try {d.execCommand("useCSS", 0, true);} catch (ex) {}
  9795. }
  9796. if (!s.table_inline_editing)
  9797. try {d.execCommand('enableInlineTableEditing', false, false);} catch (ex) {}
  9798. if (!s.object_resizing)
  9799. try {d.execCommand('enableObjectResizing', false, false);} catch (ex) {}
  9800. }
  9801. };
  9802. t.onBeforeExecCommand.add(setOpts);
  9803. t.onMouseDown.add(setOpts);
  9804. }
  9805. t.onClick.add(function(ed, e) {
  9806. e = e.target;
  9807. // Workaround for bug, http://bugs.webkit.org/show_bug.cgi?id=12250
  9808. // WebKit can't even do simple things like selecting an image
  9809. // Needs tobe the setBaseAndExtend or it will fail to select floated images
  9810. if (tinymce.isWebKit && e.nodeName == 'IMG')
  9811. t.selection.getSel().setBaseAndExtent(e, 0, e, 1);
  9812. if (e.nodeName == 'A' && dom.hasClass(e, 'mceItemAnchor'))
  9813. t.selection.select(e);
  9814. t.nodeChanged();
  9815. });
  9816. // Add node change handlers
  9817. t.onMouseUp.add(t.nodeChanged);
  9818. //t.onClick.add(t.nodeChanged);
  9819. t.onKeyUp.add(function(ed, e) {
  9820. var c = e.keyCode;
  9821. if ((c >= 33 && c <= 36) || (c >= 37 && c <= 40) || c == 13 || c == 45 || c == 46 || c == 8 || (tinymce.isMac && (c == 91 || c == 93)) || e.ctrlKey)
  9822. t.nodeChanged();
  9823. });
  9824. // Add reset handler
  9825. t.onReset.add(function() {
  9826. t.setContent(t.startContent, {format : 'raw'});
  9827. });
  9828. // Add shortcuts
  9829. if (s.custom_shortcuts) {
  9830. if (s.custom_undo_redo_keyboard_shortcuts) {
  9831. t.addShortcut('ctrl+z', t.getLang('undo_desc'), 'Undo');
  9832. t.addShortcut('ctrl+y', t.getLang('redo_desc'), 'Redo');
  9833. }
  9834. // Add default shortcuts for gecko
  9835. t.addShortcut('ctrl+b', t.getLang('bold_desc'), 'Bold');
  9836. t.addShortcut('ctrl+i', t.getLang('italic_desc'), 'Italic');
  9837. t.addShortcut('ctrl+u', t.getLang('underline_desc'), 'Underline');
  9838. // BlockFormat shortcuts keys
  9839. for (i=1; i<=6; i++)
  9840. t.addShortcut('ctrl+' + i, '', ['FormatBlock', false, 'h' + i]);
  9841. t.addShortcut('ctrl+7', '', ['FormatBlock', false, '<p>']);
  9842. t.addShortcut('ctrl+8', '', ['FormatBlock', false, '<div>']);
  9843. t.addShortcut('ctrl+9', '', ['FormatBlock', false, '<address>']);
  9844. function find(e) {
  9845. var v = null;
  9846. if (!e.altKey && !e.ctrlKey && !e.metaKey)
  9847. return v;
  9848. each(t.shortcuts, function(o) {
  9849. if (tinymce.isMac && o.ctrl != e.metaKey)
  9850. return;
  9851. else if (!tinymce.isMac && o.ctrl != e.ctrlKey)
  9852. return;
  9853. if (o.alt != e.altKey)
  9854. return;
  9855. if (o.shift != e.shiftKey)
  9856. return;
  9857. if (e.keyCode == o.keyCode || (e.charCode && e.charCode == o.charCode)) {
  9858. v = o;
  9859. return false;
  9860. }
  9861. });
  9862. return v;
  9863. };
  9864. t.onKeyUp.add(function(ed, e) {
  9865. var o = find(e);
  9866. if (o)
  9867. return Event.cancel(e);
  9868. });
  9869. t.onKeyPress.add(function(ed, e) {
  9870. var o = find(e);
  9871. if (o)
  9872. return Event.cancel(e);
  9873. });
  9874. t.onKeyDown.add(function(ed, e) {
  9875. var o = find(e);
  9876. if (o) {
  9877. o.func.call(o.scope);
  9878. return Event.cancel(e);
  9879. }
  9880. });
  9881. }
  9882. if (tinymce.isIE) {
  9883. // Fix so resize will only update the width and height attributes not the styles of an image
  9884. // It will also block mceItemNoResize items
  9885. dom.bind(t.getDoc(), 'controlselect', function(e) {
  9886. var re = t.resizeInfo, cb;
  9887. e = e.target;
  9888. // Don't do this action for non image elements
  9889. if (e.nodeName !== 'IMG')
  9890. return;
  9891. if (re)
  9892. dom.unbind(re.node, re.ev, re.cb);
  9893. if (!dom.hasClass(e, 'mceItemNoResize')) {
  9894. ev = 'resizeend';
  9895. cb = dom.bind(e, ev, function(e) {
  9896. var v;
  9897. e = e.target;
  9898. if (v = dom.getStyle(e, 'width')) {
  9899. dom.setAttrib(e, 'width', v.replace(/[^0-9%]+/g, ''));
  9900. dom.setStyle(e, 'width', '');
  9901. }
  9902. if (v = dom.getStyle(e, 'height')) {
  9903. dom.setAttrib(e, 'height', v.replace(/[^0-9%]+/g, ''));
  9904. dom.setStyle(e, 'height', '');
  9905. }
  9906. });
  9907. } else {
  9908. ev = 'resizestart';
  9909. cb = dom.bind(e, 'resizestart', Event.cancel, Event);
  9910. }
  9911. re = t.resizeInfo = {
  9912. node : e,
  9913. ev : ev,
  9914. cb : cb
  9915. };
  9916. });
  9917. }
  9918. if (tinymce.isOpera) {
  9919. t.onClick.add(function(ed, e) {
  9920. Event.prevent(e);
  9921. });
  9922. }
  9923. // Add custom undo/redo handlers
  9924. if (s.custom_undo_redo) {
  9925. function addUndo() {
  9926. t.undoManager.typing = false;
  9927. t.undoManager.add();
  9928. };
  9929. dom.bind(t.getDoc(), 'focusout', function(e) {
  9930. if (!t.removed && t.undoManager.typing)
  9931. addUndo();
  9932. });
  9933. // Add undo level when contents is drag/dropped within the editor
  9934. t.dom.bind(t.dom.getRoot(), 'dragend', function(e) {
  9935. addUndo();
  9936. });
  9937. t.onKeyUp.add(function(ed, e) {
  9938. var keyCode = e.keyCode;
  9939. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 13 || keyCode == 45 || e.ctrlKey)
  9940. addUndo();
  9941. });
  9942. t.onKeyDown.add(function(ed, e) {
  9943. var keyCode = e.keyCode, sel;
  9944. if (keyCode == 8) {
  9945. sel = t.getDoc().selection;
  9946. // Fix IE control + backspace browser bug
  9947. if (sel && sel.createRange && sel.createRange().item) {
  9948. t.undoManager.beforeChange();
  9949. ed.dom.remove(sel.createRange().item(0));
  9950. addUndo();
  9951. return Event.cancel(e);
  9952. }
  9953. }
  9954. // Is caracter positon keys left,right,up,down,home,end,pgdown,pgup,enter
  9955. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 13 || keyCode == 45) {
  9956. // Add position before enter key is pressed, used by IE since it still uses the default browser behavior
  9957. // Todo: Remove this once we normalize enter behavior on IE
  9958. if (tinymce.isIE && keyCode == 13)
  9959. t.undoManager.beforeChange();
  9960. if (t.undoManager.typing)
  9961. addUndo();
  9962. return;
  9963. }
  9964. // If key isn't shift,ctrl,alt,capslock,metakey
  9965. if ((keyCode < 16 || keyCode > 20) && keyCode != 224 && keyCode != 91 && !t.undoManager.typing) {
  9966. t.undoManager.beforeChange();
  9967. t.undoManager.typing = true;
  9968. t.undoManager.add();
  9969. }
  9970. });
  9971. t.onMouseDown.add(function() {
  9972. if (t.undoManager.typing)
  9973. addUndo();
  9974. });
  9975. }
  9976. // Bug fix for FireFox keeping styles from end of selection instead of start.
  9977. if (tinymce.isGecko) {
  9978. function getAttributeApplyFunction() {
  9979. var template = t.dom.getAttribs(t.selection.getStart().cloneNode(false));
  9980. return function() {
  9981. var target = t.selection.getStart();
  9982. t.dom.removeAllAttribs(target);
  9983. each(template, function(attr) {
  9984. target.setAttributeNode(attr.cloneNode(true));
  9985. });
  9986. };
  9987. }
  9988. function isSelectionAcrossElements() {
  9989. var s = t.selection;
  9990. return !s.isCollapsed() && s.getStart() != s.getEnd();
  9991. }
  9992. t.onKeyPress.add(function(ed, e) {
  9993. var applyAttributes;
  9994. if ((e.keyCode == 8 || e.keyCode == 46) && isSelectionAcrossElements()) {
  9995. applyAttributes = getAttributeApplyFunction();
  9996. t.getDoc().execCommand('delete', false, null);
  9997. applyAttributes();
  9998. return Event.cancel(e);
  9999. }
  10000. });
  10001. t.dom.bind(t.getDoc(), 'cut', function(e) {
  10002. var applyAttributes;
  10003. if (isSelectionAcrossElements()) {
  10004. applyAttributes = getAttributeApplyFunction();
  10005. t.onKeyUp.addToTop(Event.cancel, Event);
  10006. setTimeout(function() {
  10007. applyAttributes();
  10008. t.onKeyUp.remove(Event.cancel, Event);
  10009. }, 0);
  10010. }
  10011. });
  10012. }
  10013. },
  10014. _isHidden : function() {
  10015. var s;
  10016. if (!isGecko)
  10017. return 0;
  10018. // Weird, wheres that cursor selection?
  10019. s = this.selection.getSel();
  10020. return (!s || !s.rangeCount || s.rangeCount == 0);
  10021. }
  10022. });
  10023. })(tinymce);
  10024. (function(tinymce) {
  10025. // Added for compression purposes
  10026. var each = tinymce.each, undefined, TRUE = true, FALSE = false;
  10027. tinymce.EditorCommands = function(editor) {
  10028. var dom = editor.dom,
  10029. selection = editor.selection,
  10030. commands = {state: {}, exec : {}, value : {}},
  10031. settings = editor.settings,
  10032. bookmark;
  10033. function execCommand(command, ui, value) {
  10034. var func;
  10035. command = command.toLowerCase();
  10036. if (func = commands.exec[command]) {
  10037. func(command, ui, value);
  10038. return TRUE;
  10039. }
  10040. return FALSE;
  10041. };
  10042. function queryCommandState(command) {
  10043. var func;
  10044. command = command.toLowerCase();
  10045. if (func = commands.state[command])
  10046. return func(command);
  10047. return -1;
  10048. };
  10049. function queryCommandValue(command) {
  10050. var func;
  10051. command = command.toLowerCase();
  10052. if (func = commands.value[command])
  10053. return func(command);
  10054. return FALSE;
  10055. };
  10056. function addCommands(command_list, type) {
  10057. type = type || 'exec';
  10058. each(command_list, function(callback, command) {
  10059. each(command.toLowerCase().split(','), function(command) {
  10060. commands[type][command] = callback;
  10061. });
  10062. });
  10063. };
  10064. // Expose public methods
  10065. tinymce.extend(this, {
  10066. execCommand : execCommand,
  10067. queryCommandState : queryCommandState,
  10068. queryCommandValue : queryCommandValue,
  10069. addCommands : addCommands
  10070. });
  10071. // Private methods
  10072. function execNativeCommand(command, ui, value) {
  10073. if (ui === undefined)
  10074. ui = FALSE;
  10075. if (value === undefined)
  10076. value = null;
  10077. return editor.getDoc().execCommand(command, ui, value);
  10078. };
  10079. function isFormatMatch(name) {
  10080. return editor.formatter.match(name);
  10081. };
  10082. function toggleFormat(name, value) {
  10083. editor.formatter.toggle(name, value ? {value : value} : undefined);
  10084. };
  10085. function storeSelection(type) {
  10086. bookmark = selection.getBookmark(type);
  10087. };
  10088. function restoreSelection() {
  10089. selection.moveToBookmark(bookmark);
  10090. };
  10091. // Add execCommand overrides
  10092. addCommands({
  10093. // Ignore these, added for compatibility
  10094. 'mceResetDesignMode,mceBeginUndoLevel' : function() {},
  10095. // Add undo manager logic
  10096. 'mceEndUndoLevel,mceAddUndoLevel' : function() {
  10097. editor.undoManager.add();
  10098. },
  10099. 'Cut,Copy,Paste' : function(command) {
  10100. var doc = editor.getDoc(), failed;
  10101. // Try executing the native command
  10102. try {
  10103. execNativeCommand(command);
  10104. } catch (ex) {
  10105. // Command failed
  10106. failed = TRUE;
  10107. }
  10108. // Present alert message about clipboard access not being available
  10109. if (failed || !doc.queryCommandSupported(command)) {
  10110. if (tinymce.isGecko) {
  10111. editor.windowManager.confirm(editor.getLang('clipboard_msg'), function(state) {
  10112. if (state)
  10113. open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', '_blank');
  10114. });
  10115. } else
  10116. editor.windowManager.alert(editor.getLang('clipboard_no_support'));
  10117. }
  10118. },
  10119. // Override unlink command
  10120. unlink : function(command) {
  10121. if (selection.isCollapsed())
  10122. selection.select(selection.getNode());
  10123. execNativeCommand(command);
  10124. selection.collapse(FALSE);
  10125. },
  10126. // Override justify commands to use the text formatter engine
  10127. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  10128. var align = command.substring(7);
  10129. // Remove all other alignments first
  10130. each('left,center,right,full'.split(','), function(name) {
  10131. if (align != name)
  10132. editor.formatter.remove('align' + name);
  10133. });
  10134. toggleFormat('align' + align);
  10135. execCommand('mceRepaint');
  10136. },
  10137. // Override list commands to fix WebKit bug
  10138. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  10139. var listElm, listParent;
  10140. execNativeCommand(command);
  10141. // WebKit produces lists within block elements so we need to split them
  10142. // we will replace the native list creation logic to custom logic later on
  10143. // TODO: Remove this when the list creation logic is removed
  10144. listElm = dom.getParent(selection.getNode(), 'ol,ul');
  10145. if (listElm) {
  10146. listParent = listElm.parentNode;
  10147. // If list is within a text block then split that block
  10148. if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) {
  10149. storeSelection();
  10150. dom.split(listParent, listElm);
  10151. restoreSelection();
  10152. }
  10153. }
  10154. },
  10155. // Override commands to use the text formatter engine
  10156. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
  10157. toggleFormat(command);
  10158. },
  10159. // Override commands to use the text formatter engine
  10160. 'ForeColor,HiliteColor,FontName' : function(command, ui, value) {
  10161. toggleFormat(command, value);
  10162. },
  10163. FontSize : function(command, ui, value) {
  10164. var fontClasses, fontSizes;
  10165. // Convert font size 1-7 to styles
  10166. if (value >= 1 && value <= 7) {
  10167. fontSizes = tinymce.explode(settings.font_size_style_values);
  10168. fontClasses = tinymce.explode(settings.font_size_classes);
  10169. if (fontClasses)
  10170. value = fontClasses[value - 1] || value;
  10171. else
  10172. value = fontSizes[value - 1] || value;
  10173. }
  10174. toggleFormat(command, value);
  10175. },
  10176. RemoveFormat : function(command) {
  10177. editor.formatter.remove(command);
  10178. },
  10179. mceBlockQuote : function(command) {
  10180. toggleFormat('blockquote');
  10181. },
  10182. FormatBlock : function(command, ui, value) {
  10183. return toggleFormat(value || 'p');
  10184. },
  10185. mceCleanup : function() {
  10186. var bookmark = selection.getBookmark();
  10187. editor.setContent(editor.getContent({cleanup : TRUE}), {cleanup : TRUE});
  10188. selection.moveToBookmark(bookmark);
  10189. },
  10190. mceRemoveNode : function(command, ui, value) {
  10191. var node = value || selection.getNode();
  10192. // Make sure that the body node isn't removed
  10193. if (node != editor.getBody()) {
  10194. storeSelection();
  10195. editor.dom.remove(node, TRUE);
  10196. restoreSelection();
  10197. }
  10198. },
  10199. mceSelectNodeDepth : function(command, ui, value) {
  10200. var counter = 0;
  10201. dom.getParent(selection.getNode(), function(node) {
  10202. if (node.nodeType == 1 && counter++ == value) {
  10203. selection.select(node);
  10204. return FALSE;
  10205. }
  10206. }, editor.getBody());
  10207. },
  10208. mceSelectNode : function(command, ui, value) {
  10209. selection.select(value);
  10210. },
  10211. mceInsertContent : function(command, ui, value) {
  10212. var parser, serializer, parentNode, rootNode, fragment, args,
  10213. marker, nodeRect, viewPortRect, rng, node, node2, bookmarkHtml, viewportBodyElement;
  10214. // Setup parser and serializer
  10215. parser = editor.parser;
  10216. serializer = new tinymce.html.Serializer({}, editor.schema);
  10217. bookmarkHtml = '<span id="mce_marker" data-mce-type="bookmark">\uFEFF</span>';
  10218. // Run beforeSetContent handlers on the HTML to be inserted
  10219. args = {content: value, format: 'html'};
  10220. selection.onBeforeSetContent.dispatch(selection, args);
  10221. value = args.content;
  10222. // Add caret at end of contents if it's missing
  10223. if (value.indexOf('{$caret}') == -1)
  10224. value += '{$caret}';
  10225. // Replace the caret marker with a span bookmark element
  10226. value = value.replace(/\{\$caret\}/, bookmarkHtml);
  10227. // Insert node maker where we will insert the new HTML and get it's parent
  10228. if (!selection.isCollapsed())
  10229. editor.getDoc().execCommand('Delete', false, null);
  10230. parentNode = selection.getNode();
  10231. // Parse the fragment within the context of the parent node
  10232. args = {context : parentNode.nodeName.toLowerCase()};
  10233. fragment = parser.parse(value, args);
  10234. // Move the caret to a more suitable location
  10235. node = fragment.lastChild;
  10236. if (node.attr('id') == 'mce_marker') {
  10237. marker = node;
  10238. for (node = node.prev; node; node = node.walk(true)) {
  10239. if (node.type == 3 || !dom.isBlock(node.name)) {
  10240. node.parent.insert(marker, node, node.name === 'br');
  10241. break;
  10242. }
  10243. }
  10244. }
  10245. // If parser says valid we can insert the contents into that parent
  10246. if (!args.invalid) {
  10247. value = serializer.serialize(fragment);
  10248. // Check if parent is empty or only has one BR element then set the innerHTML of that parent
  10249. node = parentNode.firstChild;
  10250. node2 = parentNode.lastChild;
  10251. if (!node || (node === node2 && node.nodeName === 'BR'))
  10252. dom.setHTML(parentNode, value);
  10253. else
  10254. selection.setContent(value);
  10255. } else {
  10256. // If the fragment was invalid within that context then we need
  10257. // to parse and process the parent it's inserted into
  10258. // Insert bookmark node and get the parent
  10259. selection.setContent(bookmarkHtml);
  10260. parentNode = editor.selection.getNode();
  10261. rootNode = editor.getBody();
  10262. // Opera will return the document node when selection is in root
  10263. if (parentNode.nodeType == 9)
  10264. parentNode = node = rootNode;
  10265. else
  10266. node = parentNode;
  10267. // Find the ancestor just before the root element
  10268. while (node !== rootNode) {
  10269. parentNode = node;
  10270. node = node.parentNode;
  10271. }
  10272. // Get the outer/inner HTML depending on if we are in the root and parser and serialize that
  10273. value = parentNode == rootNode ? rootNode.innerHTML : dom.getOuterHTML(parentNode);
  10274. value = serializer.serialize(
  10275. parser.parse(
  10276. // Need to replace by using a function since $ in the contents would otherwise be a problem
  10277. value.replace(/<span (id="mce_marker"|id=mce_marker).+<\/span>/i, function() {
  10278. return serializer.serialize(fragment);
  10279. })
  10280. )
  10281. );
  10282. // Set the inner/outer HTML depending on if we are in the root or not
  10283. if (parentNode == rootNode)
  10284. dom.setHTML(rootNode, value);
  10285. else
  10286. dom.setOuterHTML(parentNode, value);
  10287. }
  10288. marker = dom.get('mce_marker');
  10289. // Scroll range into view scrollIntoView on element can't be used since it will scroll the main view port as well
  10290. nodeRect = dom.getRect(marker);
  10291. viewPortRect = dom.getViewPort(editor.getWin());
  10292. // Check if node is out side the viewport if it is then scroll to it
  10293. if ((nodeRect.y + nodeRect.h > viewPortRect.y + viewPortRect.h || nodeRect.y < viewPortRect.y) ||
  10294. (nodeRect.x > viewPortRect.x + viewPortRect.w || nodeRect.x < viewPortRect.x)) {
  10295. viewportBodyElement = tinymce.isIE ? editor.getDoc().documentElement : editor.getBody();
  10296. viewportBodyElement.scrollLeft = nodeRect.x;
  10297. viewportBodyElement.scrollTop = nodeRect.y - viewPortRect.h + 25;
  10298. }
  10299. // Move selection before marker and remove it
  10300. rng = dom.createRng();
  10301. // If previous sibling is a text node set the selection to the end of that node
  10302. node = marker.previousSibling;
  10303. if (node && node.nodeType == 3) {
  10304. rng.setStart(node, node.nodeValue.length);
  10305. } else {
  10306. // If the previous sibling isn't a text node or doesn't exist set the selection before the marker node
  10307. rng.setStartBefore(marker);
  10308. rng.setEndBefore(marker);
  10309. }
  10310. // Remove the marker node and set the new range
  10311. dom.remove(marker);
  10312. selection.setRng(rng);
  10313. // Dispatch after event and add any visual elements needed
  10314. selection.onSetContent.dispatch(selection, args);
  10315. editor.addVisual();
  10316. },
  10317. mceInsertRawHTML : function(command, ui, value) {
  10318. selection.setContent('tiny_mce_marker');
  10319. editor.setContent(editor.getContent().replace(/tiny_mce_marker/g, function() { return value }));
  10320. },
  10321. mceSetContent : function(command, ui, value) {
  10322. editor.setContent(value);
  10323. },
  10324. 'Indent,Outdent' : function(command) {
  10325. var intentValue, indentUnit, value;
  10326. // Setup indent level
  10327. intentValue = settings.indentation;
  10328. indentUnit = /[a-z%]+$/i.exec(intentValue);
  10329. intentValue = parseInt(intentValue);
  10330. if (!queryCommandState('InsertUnorderedList') && !queryCommandState('InsertOrderedList')) {
  10331. each(selection.getSelectedBlocks(), function(element) {
  10332. if (command == 'outdent') {
  10333. value = Math.max(0, parseInt(element.style.paddingLeft || 0) - intentValue);
  10334. dom.setStyle(element, 'paddingLeft', value ? value + indentUnit : '');
  10335. } else
  10336. dom.setStyle(element, 'paddingLeft', (parseInt(element.style.paddingLeft || 0) + intentValue) + indentUnit);
  10337. });
  10338. } else
  10339. execNativeCommand(command);
  10340. },
  10341. mceRepaint : function() {
  10342. var bookmark;
  10343. if (tinymce.isGecko) {
  10344. try {
  10345. storeSelection(TRUE);
  10346. if (selection.getSel())
  10347. selection.getSel().selectAllChildren(editor.getBody());
  10348. selection.collapse(TRUE);
  10349. restoreSelection();
  10350. } catch (ex) {
  10351. // Ignore
  10352. }
  10353. }
  10354. },
  10355. mceToggleFormat : function(command, ui, value) {
  10356. editor.formatter.toggle(value);
  10357. },
  10358. InsertHorizontalRule : function() {
  10359. editor.execCommand('mceInsertContent', false, '<hr />');
  10360. },
  10361. mceToggleVisualAid : function() {
  10362. editor.hasVisual = !editor.hasVisual;
  10363. editor.addVisual();
  10364. },
  10365. mceReplaceContent : function(command, ui, value) {
  10366. editor.execCommand('mceInsertContent', false, value.replace(/\{\$selection\}/g, selection.getContent({format : 'text'})));
  10367. },
  10368. mceInsertLink : function(command, ui, value) {
  10369. var link = dom.getParent(selection.getNode(), 'a'), img, style, cls;
  10370. if (tinymce.is(value, 'string'))
  10371. value = {href : value};
  10372. // Spaces are never valid in URLs and it's a very common mistake for people to make so we fix it here.
  10373. value.href = value.href.replace(' ', '%20');
  10374. if (!link) {
  10375. // WebKit can't create links on floated images for some odd reason
  10376. // So, just remove styles and restore it later
  10377. if (tinymce.isWebKit) {
  10378. img = dom.getParent(selection.getNode(), 'img');
  10379. if (img) {
  10380. style = img.style.cssText;
  10381. cls = img.className;
  10382. img.style.cssText = null;
  10383. img.className = null;
  10384. }
  10385. }
  10386. execNativeCommand('CreateLink', FALSE, 'javascript:mctmp(0);');
  10387. // Restore styles
  10388. if (style)
  10389. img.style.cssText = style;
  10390. if (cls)
  10391. img.className = cls;
  10392. each(dom.select("a[href='javascript:mctmp(0);']"), function(link) {
  10393. dom.setAttribs(link, value);
  10394. });
  10395. } else {
  10396. if (value.href)
  10397. dom.setAttribs(link, value);
  10398. else
  10399. editor.dom.remove(link, TRUE);
  10400. }
  10401. },
  10402. selectAll : function() {
  10403. var root = dom.getRoot(), rng = dom.createRng();
  10404. rng.setStart(root, 0);
  10405. rng.setEnd(root, root.childNodes.length);
  10406. editor.selection.setRng(rng);
  10407. }
  10408. });
  10409. // Add queryCommandState overrides
  10410. addCommands({
  10411. // Override justify commands
  10412. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  10413. return isFormatMatch('align' + command.substring(7));
  10414. },
  10415. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
  10416. return isFormatMatch(command);
  10417. },
  10418. mceBlockQuote : function() {
  10419. return isFormatMatch('blockquote');
  10420. },
  10421. Outdent : function() {
  10422. var node;
  10423. if (settings.inline_styles) {
  10424. if ((node = dom.getParent(selection.getStart(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  10425. return TRUE;
  10426. if ((node = dom.getParent(selection.getEnd(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  10427. return TRUE;
  10428. }
  10429. return queryCommandState('InsertUnorderedList') || queryCommandState('InsertOrderedList') || (!settings.inline_styles && !!dom.getParent(selection.getNode(), 'BLOCKQUOTE'));
  10430. },
  10431. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  10432. return dom.getParent(selection.getNode(), command == 'insertunorderedlist' ? 'UL' : 'OL');
  10433. }
  10434. }, 'state');
  10435. // Add queryCommandValue overrides
  10436. addCommands({
  10437. 'FontSize,FontName' : function(command) {
  10438. var value = 0, parent;
  10439. if (parent = dom.getParent(selection.getNode(), 'span')) {
  10440. if (command == 'fontsize')
  10441. value = parent.style.fontSize;
  10442. else
  10443. value = parent.style.fontFamily.replace(/, /g, ',').replace(/[\'\"]/g, '').toLowerCase();
  10444. }
  10445. return value;
  10446. }
  10447. }, 'value');
  10448. // Add undo manager logic
  10449. if (settings.custom_undo_redo) {
  10450. addCommands({
  10451. Undo : function() {
  10452. editor.undoManager.undo();
  10453. },
  10454. Redo : function() {
  10455. editor.undoManager.redo();
  10456. }
  10457. });
  10458. }
  10459. };
  10460. })(tinymce);
  10461. (function(tinymce) {
  10462. var Dispatcher = tinymce.util.Dispatcher;
  10463. tinymce.UndoManager = function(editor) {
  10464. var self, index = 0, data = [], beforeBookmark;
  10465. function getContent() {
  10466. return tinymce.trim(editor.getContent({format : 'raw', no_events : 1}));
  10467. };
  10468. return self = {
  10469. typing : false,
  10470. onAdd : new Dispatcher(self),
  10471. onUndo : new Dispatcher(self),
  10472. onRedo : new Dispatcher(self),
  10473. beforeChange : function() {
  10474. beforeBookmark = editor.selection.getBookmark(2, true);
  10475. },
  10476. add : function(level) {
  10477. var i, settings = editor.settings, lastLevel;
  10478. level = level || {};
  10479. level.content = getContent();
  10480. // Add undo level if needed
  10481. lastLevel = data[index];
  10482. if (lastLevel && lastLevel.content == level.content)
  10483. return null;
  10484. // Set before bookmark on previous level
  10485. if (data[index])
  10486. data[index].beforeBookmark = beforeBookmark;
  10487. // Time to compress
  10488. if (settings.custom_undo_redo_levels) {
  10489. if (data.length > settings.custom_undo_redo_levels) {
  10490. for (i = 0; i < data.length - 1; i++)
  10491. data[i] = data[i + 1];
  10492. data.length--;
  10493. index = data.length;
  10494. }
  10495. }
  10496. // Get a non intrusive normalized bookmark
  10497. level.bookmark = editor.selection.getBookmark(2, true);
  10498. // Crop array if needed
  10499. if (index < data.length - 1)
  10500. data.length = index + 1;
  10501. data.push(level);
  10502. index = data.length - 1;
  10503. self.onAdd.dispatch(self, level);
  10504. editor.isNotDirty = 0;
  10505. return level;
  10506. },
  10507. undo : function() {
  10508. var level, i;
  10509. if (self.typing) {
  10510. self.add();
  10511. self.typing = false;
  10512. }
  10513. if (index > 0) {
  10514. level = data[--index];
  10515. editor.setContent(level.content, {format : 'raw'});
  10516. editor.selection.moveToBookmark(level.beforeBookmark);
  10517. self.onUndo.dispatch(self, level);
  10518. }
  10519. return level;
  10520. },
  10521. redo : function() {
  10522. var level;
  10523. if (index < data.length - 1) {
  10524. level = data[++index];
  10525. editor.setContent(level.content, {format : 'raw'});
  10526. editor.selection.moveToBookmark(level.bookmark);
  10527. self.onRedo.dispatch(self, level);
  10528. }
  10529. return level;
  10530. },
  10531. clear : function() {
  10532. data = [];
  10533. index = 0;
  10534. self.typing = false;
  10535. },
  10536. hasUndo : function() {
  10537. return index > 0 || this.typing;
  10538. },
  10539. hasRedo : function() {
  10540. return index < data.length - 1 && !this.typing;
  10541. }
  10542. };
  10543. };
  10544. })(tinymce);
  10545. (function(tinymce) {
  10546. // Shorten names
  10547. var Event = tinymce.dom.Event,
  10548. isIE = tinymce.isIE,
  10549. isGecko = tinymce.isGecko,
  10550. isOpera = tinymce.isOpera,
  10551. each = tinymce.each,
  10552. extend = tinymce.extend,
  10553. TRUE = true,
  10554. FALSE = false;
  10555. function cloneFormats(node) {
  10556. var clone, temp, inner;
  10557. do {
  10558. if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(node.nodeName)) {
  10559. if (clone) {
  10560. temp = node.cloneNode(false);
  10561. temp.appendChild(clone);
  10562. clone = temp;
  10563. } else {
  10564. clone = inner = node.cloneNode(false);
  10565. }
  10566. clone.removeAttribute('id');
  10567. }
  10568. } while (node = node.parentNode);
  10569. if (clone)
  10570. return {wrapper : clone, inner : inner};
  10571. };
  10572. // Checks if the selection/caret is at the end of the specified block element
  10573. function isAtEnd(rng, par) {
  10574. var rng2 = par.ownerDocument.createRange();
  10575. rng2.setStart(rng.endContainer, rng.endOffset);
  10576. rng2.setEndAfter(par);
  10577. // Get number of characters to the right of the cursor if it's zero then we are at the end and need to merge the next block element
  10578. return rng2.cloneContents().textContent.length == 0;
  10579. };
  10580. function splitList(selection, dom, li) {
  10581. var listBlock, block;
  10582. if (dom.isEmpty(li)) {
  10583. listBlock = dom.getParent(li, 'ul,ol');
  10584. if (!dom.getParent(listBlock.parentNode, 'ul,ol')) {
  10585. dom.split(listBlock, li);
  10586. block = dom.create('p', 0, '<br data-mce-bogus="1" />');
  10587. dom.replace(block, li);
  10588. selection.select(block, 1);
  10589. }
  10590. return FALSE;
  10591. }
  10592. return TRUE;
  10593. };
  10594. tinymce.create('tinymce.ForceBlocks', {
  10595. ForceBlocks : function(ed) {
  10596. var t = this, s = ed.settings, elm;
  10597. t.editor = ed;
  10598. t.dom = ed.dom;
  10599. elm = (s.forced_root_block || 'p').toLowerCase();
  10600. s.element = elm.toUpperCase();
  10601. ed.onPreInit.add(t.setup, t);
  10602. },
  10603. setup : function() {
  10604. var t = this, ed = t.editor, s = ed.settings, dom = ed.dom, selection = ed.selection, blockElements = ed.schema.getBlockElements();
  10605. // Force root blocks
  10606. if (s.forced_root_block) {
  10607. function addRootBlocks() {
  10608. var node = selection.getStart(), rootNode = ed.getBody(), rng, startContainer, startOffset, endContainer, endOffset, rootBlockNode, tempNode, offset = -0xFFFFFF;
  10609. if (!node || node.nodeType !== 1)
  10610. return;
  10611. // Check if node is wrapped in block
  10612. while (node != rootNode) {
  10613. if (blockElements[node.nodeName])
  10614. return;
  10615. node = node.parentNode;
  10616. }
  10617. // Get current selection
  10618. rng = selection.getRng();
  10619. if (rng.setStart) {
  10620. startContainer = rng.startContainer;
  10621. startOffset = rng.startOffset;
  10622. endContainer = rng.endContainer;
  10623. endOffset = rng.endOffset;
  10624. } else {
  10625. // Force control range into text range
  10626. if (rng.item) {
  10627. rng = ed.getDoc().body.createTextRange();
  10628. rng.moveToElementText(rng.item(0));
  10629. }
  10630. tmpRng = rng.duplicate();
  10631. tmpRng.collapse(true);
  10632. startOffset = tmpRng.move('character', offset) * -1;
  10633. if (!tmpRng.collapsed) {
  10634. tmpRng = rng.duplicate();
  10635. tmpRng.collapse(false);
  10636. endOffset = (tmpRng.move('character', offset) * -1) - startOffset;
  10637. }
  10638. }
  10639. // Wrap non block elements and text nodes
  10640. for (node = rootNode.firstChild; node; node) {
  10641. if (node.nodeType === 3 || (node.nodeType == 1 && !blockElements[node.nodeName])) {
  10642. if (!rootBlockNode) {
  10643. rootBlockNode = dom.create(s.forced_root_block);
  10644. node.parentNode.insertBefore(rootBlockNode, node);
  10645. }
  10646. tempNode = node;
  10647. node = node.nextSibling;
  10648. rootBlockNode.appendChild(tempNode);
  10649. } else {
  10650. rootBlockNode = null;
  10651. node = node.nextSibling;
  10652. }
  10653. }
  10654. if (rng.setStart) {
  10655. rng.setStart(startContainer, startOffset);
  10656. rng.setEnd(endContainer, endOffset);
  10657. selection.setRng(rng);
  10658. } else {
  10659. try {
  10660. rng = ed.getDoc().body.createTextRange();
  10661. rng.moveToElementText(rootNode);
  10662. rng.collapse(true);
  10663. rng.moveStart('character', startOffset);
  10664. if (endOffset > 0)
  10665. rng.moveEnd('character', endOffset);
  10666. rng.select();
  10667. } catch (ex) {
  10668. // Ignore
  10669. }
  10670. }
  10671. ed.nodeChanged();
  10672. };
  10673. ed.onKeyUp.add(addRootBlocks);
  10674. ed.onClick.add(addRootBlocks);
  10675. }
  10676. if (s.force_br_newlines) {
  10677. // Force IE to produce BRs on enter
  10678. if (isIE) {
  10679. ed.onKeyPress.add(function(ed, e) {
  10680. var n;
  10681. if (e.keyCode == 13 && selection.getNode().nodeName != 'LI') {
  10682. selection.setContent('<br id="__" /> ', {format : 'raw'});
  10683. n = dom.get('__');
  10684. n.removeAttribute('id');
  10685. selection.select(n);
  10686. selection.collapse();
  10687. return Event.cancel(e);
  10688. }
  10689. });
  10690. }
  10691. }
  10692. if (s.force_p_newlines) {
  10693. if (!isIE) {
  10694. ed.onKeyPress.add(function(ed, e) {
  10695. if (e.keyCode == 13 && !e.shiftKey && !t.insertPara(e))
  10696. Event.cancel(e);
  10697. });
  10698. } else {
  10699. // Ungly hack to for IE to preserve the formatting when you press
  10700. // enter at the end of a block element with formatted contents
  10701. // This logic overrides the browsers default logic with
  10702. // custom logic that enables us to control the output
  10703. tinymce.addUnload(function() {
  10704. t._previousFormats = 0; // Fix IE leak
  10705. });
  10706. ed.onKeyPress.add(function(ed, e) {
  10707. t._previousFormats = 0;
  10708. // Clone the current formats, this will later be applied to the new block contents
  10709. if (e.keyCode == 13 && !e.shiftKey && ed.selection.isCollapsed() && s.keep_styles)
  10710. t._previousFormats = cloneFormats(ed.selection.getStart());
  10711. });
  10712. ed.onKeyUp.add(function(ed, e) {
  10713. // Let IE break the element and the wrap the new caret location in the previous formats
  10714. if (e.keyCode == 13 && !e.shiftKey) {
  10715. var parent = ed.selection.getStart(), fmt = t._previousFormats;
  10716. // Parent is an empty block
  10717. if (!parent.hasChildNodes() && fmt) {
  10718. parent = dom.getParent(parent, dom.isBlock);
  10719. if (parent && parent.nodeName != 'LI') {
  10720. parent.innerHTML = '';
  10721. if (t._previousFormats) {
  10722. parent.appendChild(fmt.wrapper);
  10723. fmt.inner.innerHTML = '\uFEFF';
  10724. } else
  10725. parent.innerHTML = '\uFEFF';
  10726. selection.select(parent, 1);
  10727. selection.collapse(true);
  10728. ed.getDoc().execCommand('Delete', false, null);
  10729. t._previousFormats = 0;
  10730. }
  10731. }
  10732. }
  10733. });
  10734. }
  10735. if (isGecko) {
  10736. ed.onKeyDown.add(function(ed, e) {
  10737. if ((e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey)
  10738. t.backspaceDelete(e, e.keyCode == 8);
  10739. });
  10740. }
  10741. }
  10742. // Workaround for missing shift+enter support, http://bugs.webkit.org/show_bug.cgi?id=16973
  10743. if (tinymce.isWebKit) {
  10744. function insertBr(ed) {
  10745. var rng = selection.getRng(), br, div = dom.create('div', null, ' '), divYPos, vpHeight = dom.getViewPort(ed.getWin()).h;
  10746. // Insert BR element
  10747. rng.insertNode(br = dom.create('br'));
  10748. // Place caret after BR
  10749. rng.setStartAfter(br);
  10750. rng.setEndAfter(br);
  10751. selection.setRng(rng);
  10752. // Could not place caret after BR then insert an nbsp entity and move the caret
  10753. if (selection.getSel().focusNode == br.previousSibling) {
  10754. selection.select(dom.insertAfter(dom.doc.createTextNode('\u00a0'), br));
  10755. selection.collapse(TRUE);
  10756. }
  10757. // Create a temporary DIV after the BR and get the position as it
  10758. // seems like getPos() returns 0 for text nodes and BR elements.
  10759. dom.insertAfter(div, br);
  10760. divYPos = dom.getPos(div).y;
  10761. dom.remove(div);
  10762. // Scroll to new position, scrollIntoView can't be used due to bug: http://bugs.webkit.org/show_bug.cgi?id=16117
  10763. if (divYPos > vpHeight) // It is not necessary to scroll if the DIV is inside the view port.
  10764. ed.getWin().scrollTo(0, divYPos);
  10765. };
  10766. ed.onKeyPress.add(function(ed, e) {
  10767. if (e.keyCode == 13 && (e.shiftKey || (s.force_br_newlines && !dom.getParent(selection.getNode(), 'h1,h2,h3,h4,h5,h6,ol,ul')))) {
  10768. insertBr(ed);
  10769. Event.cancel(e);
  10770. }
  10771. });
  10772. }
  10773. // IE specific fixes
  10774. if (isIE) {
  10775. // Replaces IE:s auto generated paragraphs with the specified element name
  10776. if (s.element != 'P') {
  10777. ed.onKeyPress.add(function(ed, e) {
  10778. t.lastElm = selection.getNode().nodeName;
  10779. });
  10780. ed.onKeyUp.add(function(ed, e) {
  10781. var bl, n = selection.getNode(), b = ed.getBody();
  10782. if (b.childNodes.length === 1 && n.nodeName == 'P') {
  10783. n = dom.rename(n, s.element);
  10784. selection.select(n);
  10785. selection.collapse();
  10786. ed.nodeChanged();
  10787. } else if (e.keyCode == 13 && !e.shiftKey && t.lastElm != 'P') {
  10788. bl = dom.getParent(n, 'p');
  10789. if (bl) {
  10790. dom.rename(bl, s.element);
  10791. ed.nodeChanged();
  10792. }
  10793. }
  10794. });
  10795. }
  10796. }
  10797. },
  10798. getParentBlock : function(n) {
  10799. var d = this.dom;
  10800. return d.getParent(n, d.isBlock);
  10801. },
  10802. insertPara : function(e) {
  10803. var t = this, ed = t.editor, dom = ed.dom, d = ed.getDoc(), se = ed.settings, s = ed.selection.getSel(), r = s.getRangeAt(0), b = d.body;
  10804. var rb, ra, dir, sn, so, en, eo, sb, eb, bn, bef, aft, sc, ec, n, vp = dom.getViewPort(ed.getWin()), y, ch, car;
  10805. ed.undoManager.beforeChange();
  10806. // If root blocks are forced then use Operas default behavior since it's really good
  10807. // Removed due to bug: #1853816
  10808. // if (se.forced_root_block && isOpera)
  10809. // return TRUE;
  10810. // Setup before range
  10811. rb = d.createRange();
  10812. // If is before the first block element and in body, then move it into first block element
  10813. rb.setStart(s.anchorNode, s.anchorOffset);
  10814. rb.collapse(TRUE);
  10815. // Setup after range
  10816. ra = d.createRange();
  10817. // If is before the first block element and in body, then move it into first block element
  10818. ra.setStart(s.focusNode, s.focusOffset);
  10819. ra.collapse(TRUE);
  10820. // Setup start/end points
  10821. dir = rb.compareBoundaryPoints(rb.START_TO_END, ra) < 0;
  10822. sn = dir ? s.anchorNode : s.focusNode;
  10823. so = dir ? s.anchorOffset : s.focusOffset;
  10824. en = dir ? s.focusNode : s.anchorNode;
  10825. eo = dir ? s.focusOffset : s.anchorOffset;
  10826. // If selection is in empty table cell
  10827. if (sn === en && /^(TD|TH)$/.test(sn.nodeName)) {
  10828. if (sn.firstChild.nodeName == 'BR')
  10829. dom.remove(sn.firstChild); // Remove BR
  10830. // Create two new block elements
  10831. if (sn.childNodes.length == 0) {
  10832. ed.dom.add(sn, se.element, null, '<br />');
  10833. aft = ed.dom.add(sn, se.element, null, '<br />');
  10834. } else {
  10835. n = sn.innerHTML;
  10836. sn.innerHTML = '';
  10837. ed.dom.add(sn, se.element, null, n);
  10838. aft = ed.dom.add(sn, se.element, null, '<br />');
  10839. }
  10840. // Move caret into the last one
  10841. r = d.createRange();
  10842. r.selectNodeContents(aft);
  10843. r.collapse(1);
  10844. ed.selection.setRng(r);
  10845. return FALSE;
  10846. }
  10847. // If the caret is in an invalid location in FF we need to move it into the first block
  10848. if (sn == b && en == b && b.firstChild && ed.dom.isBlock(b.firstChild)) {
  10849. sn = en = sn.firstChild;
  10850. so = eo = 0;
  10851. rb = d.createRange();
  10852. rb.setStart(sn, 0);
  10853. ra = d.createRange();
  10854. ra.setStart(en, 0);
  10855. }
  10856. // Never use body as start or end node
  10857. sn = sn.nodeName == "HTML" ? d.body : sn; // Fix for Opera bug: https://bugs.opera.com/show_bug.cgi?id=273224&comments=yes
  10858. sn = sn.nodeName == "BODY" ? sn.firstChild : sn;
  10859. en = en.nodeName == "HTML" ? d.body : en; // Fix for Opera bug: https://bugs.opera.com/show_bug.cgi?id=273224&comments=yes
  10860. en = en.nodeName == "BODY" ? en.firstChild : en;
  10861. // Get start and end blocks
  10862. sb = t.getParentBlock(sn);
  10863. eb = t.getParentBlock(en);
  10864. bn = sb ? sb.nodeName : se.element; // Get block name to create
  10865. // Return inside list use default browser behavior
  10866. if (n = t.dom.getParent(sb, 'li,pre')) {
  10867. if (n.nodeName == 'LI')
  10868. return splitList(ed.selection, t.dom, n);
  10869. return TRUE;
  10870. }
  10871. // If caption or absolute layers then always generate new blocks within
  10872. if (sb && (sb.nodeName == 'CAPTION' || /absolute|relative|fixed/gi.test(dom.getStyle(sb, 'position', 1)))) {
  10873. bn = se.element;
  10874. sb = null;
  10875. }
  10876. // If caption or absolute layers then always generate new blocks within
  10877. if (eb && (eb.nodeName == 'CAPTION' || /absolute|relative|fixed/gi.test(dom.getStyle(sb, 'position', 1)))) {
  10878. bn = se.element;
  10879. eb = null;
  10880. }
  10881. // Use P instead
  10882. if (/(TD|TABLE|TH|CAPTION)/.test(bn) || (sb && bn == "DIV" && /left|right/gi.test(dom.getStyle(sb, 'float', 1)))) {
  10883. bn = se.element;
  10884. sb = eb = null;
  10885. }
  10886. // Setup new before and after blocks
  10887. bef = (sb && sb.nodeName == bn) ? sb.cloneNode(0) : ed.dom.create(bn);
  10888. aft = (eb && eb.nodeName == bn) ? eb.cloneNode(0) : ed.dom.create(bn);
  10889. // Remove id from after clone
  10890. aft.removeAttribute('id');
  10891. // Is header and cursor is at the end, then force paragraph under
  10892. if (/^(H[1-6])$/.test(bn) && isAtEnd(r, sb))
  10893. aft = ed.dom.create(se.element);
  10894. // Find start chop node
  10895. n = sc = sn;
  10896. do {
  10897. if (n == b || n.nodeType == 9 || t.dom.isBlock(n) || /(TD|TABLE|TH|CAPTION)/.test(n.nodeName))
  10898. break;
  10899. sc = n;
  10900. } while ((n = n.previousSibling ? n.previousSibling : n.parentNode));
  10901. // Find end chop node
  10902. n = ec = en;
  10903. do {
  10904. if (n == b || n.nodeType == 9 || t.dom.isBlock(n) || /(TD|TABLE|TH|CAPTION)/.test(n.nodeName))
  10905. break;
  10906. ec = n;
  10907. } while ((n = n.nextSibling ? n.nextSibling : n.parentNode));
  10908. // Place first chop part into before block element
  10909. if (sc.nodeName == bn)
  10910. rb.setStart(sc, 0);
  10911. else
  10912. rb.setStartBefore(sc);
  10913. rb.setEnd(sn, so);
  10914. bef.appendChild(rb.cloneContents() || d.createTextNode('')); // Empty text node needed for Safari
  10915. // Place secnd chop part within new block element
  10916. try {
  10917. ra.setEndAfter(ec);
  10918. } catch(ex) {
  10919. //console.debug(s.focusNode, s.focusOffset);
  10920. }
  10921. ra.setStart(en, eo);
  10922. aft.appendChild(ra.cloneContents() || d.createTextNode('')); // Empty text node needed for Safari
  10923. // Create range around everything
  10924. r = d.createRange();
  10925. if (!sc.previousSibling && sc.parentNode.nodeName == bn) {
  10926. r.setStartBefore(sc.parentNode);
  10927. } else {
  10928. if (rb.startContainer.nodeName == bn && rb.startOffset == 0)
  10929. r.setStartBefore(rb.startContainer);
  10930. else
  10931. r.setStart(rb.startContainer, rb.startOffset);
  10932. }
  10933. if (!ec.nextSibling && ec.parentNode.nodeName == bn)
  10934. r.setEndAfter(ec.parentNode);
  10935. else
  10936. r.setEnd(ra.endContainer, ra.endOffset);
  10937. // Delete and replace it with new block elements
  10938. r.deleteContents();
  10939. if (isOpera)
  10940. ed.getWin().scrollTo(0, vp.y);
  10941. // Never wrap blocks in blocks
  10942. if (bef.firstChild && bef.firstChild.nodeName == bn)
  10943. bef.innerHTML = bef.firstChild.innerHTML;
  10944. if (aft.firstChild && aft.firstChild.nodeName == bn)
  10945. aft.innerHTML = aft.firstChild.innerHTML;
  10946. function appendStyles(e, en) {
  10947. var nl = [], nn, n, i;
  10948. e.innerHTML = '';
  10949. // Make clones of style elements
  10950. if (se.keep_styles) {
  10951. n = en;
  10952. do {
  10953. // We only want style specific elements
  10954. if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(n.nodeName)) {
  10955. nn = n.cloneNode(FALSE);
  10956. dom.setAttrib(nn, 'id', ''); // Remove ID since it needs to be unique
  10957. nl.push(nn);
  10958. }
  10959. } while (n = n.parentNode);
  10960. }
  10961. // Append style elements to aft
  10962. if (nl.length > 0) {
  10963. for (i = nl.length - 1, nn = e; i >= 0; i--)
  10964. nn = nn.appendChild(nl[i]);
  10965. // Padd most inner style element
  10966. nl[0].innerHTML = isOpera ? '\u00a0' : '<br />'; // Extra space for Opera so that the caret can move there
  10967. return nl[0]; // Move caret to most inner element
  10968. } else
  10969. e.innerHTML = isOpera ? '\u00a0' : '<br />'; // Extra space for Opera so that the caret can move there
  10970. };
  10971. // Padd empty blocks
  10972. if (dom.isEmpty(bef))
  10973. appendStyles(bef, sn);
  10974. // Fill empty afterblook with current style
  10975. if (dom.isEmpty(aft))
  10976. car = appendStyles(aft, en);
  10977. // Opera needs this one backwards for older versions
  10978. if (isOpera && parseFloat(opera.version()) < 9.5) {
  10979. r.insertNode(bef);
  10980. r.insertNode(aft);
  10981. } else {
  10982. r.insertNode(aft);
  10983. r.insertNode(bef);
  10984. }
  10985. // Normalize
  10986. aft.normalize();
  10987. bef.normalize();
  10988. // Move cursor and scroll into view
  10989. ed.selection.select(aft, true);
  10990. ed.selection.collapse(true);
  10991. // 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
  10992. y = ed.dom.getPos(aft).y;
  10993. //ch = aft.clientHeight;
  10994. // Is element within viewport
  10995. if (y < vp.y || y + 25 > vp.y + vp.h) {
  10996. ed.getWin().scrollTo(0, y < vp.y ? y : y - vp.h + 25); // Needs to be hardcoded to roughly one line of text if a huge text block is broken into two blocks
  10997. /*console.debug(
  10998. 'Element: y=' + y + ', h=' + ch + ', ' +
  10999. 'Viewport: y=' + vp.y + ", h=" + vp.h + ', bottom=' + (vp.y + vp.h)
  11000. );*/
  11001. }
  11002. ed.undoManager.add();
  11003. return FALSE;
  11004. },
  11005. backspaceDelete : function(e, bs) {
  11006. var t = this, ed = t.editor, b = ed.getBody(), dom = ed.dom, n, se = ed.selection, r = se.getRng(), sc = r.startContainer, n, w, tn, walker;
  11007. // Delete when caret is behind a element doesn't work correctly on Gecko see #3011651
  11008. if (!bs && r.collapsed && sc.nodeType == 1 && r.startOffset == sc.childNodes.length) {
  11009. walker = new tinymce.dom.TreeWalker(sc.lastChild, sc);
  11010. // Walk the dom backwards until we find a text node
  11011. for (n = sc.lastChild; n; n = walker.prev()) {
  11012. if (n.nodeType == 3) {
  11013. r.setStart(n, n.nodeValue.length);
  11014. r.collapse(true);
  11015. se.setRng(r);
  11016. return;
  11017. }
  11018. }
  11019. }
  11020. // The caret sometimes gets stuck in Gecko if you delete empty paragraphs
  11021. // This workaround removes the element by hand and moves the caret to the previous element
  11022. if (sc && ed.dom.isBlock(sc) && !/^(TD|TH)$/.test(sc.nodeName) && bs) {
  11023. if (sc.childNodes.length == 0 || (sc.childNodes.length == 1 && sc.firstChild.nodeName == 'BR')) {
  11024. // Find previous block element
  11025. n = sc;
  11026. while ((n = n.previousSibling) && !ed.dom.isBlock(n)) ;
  11027. if (n) {
  11028. if (sc != b.firstChild) {
  11029. // Find last text node
  11030. w = ed.dom.doc.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, FALSE);
  11031. while (tn = w.nextNode())
  11032. n = tn;
  11033. // Place caret at the end of last text node
  11034. r = ed.getDoc().createRange();
  11035. r.setStart(n, n.nodeValue ? n.nodeValue.length : 0);
  11036. r.setEnd(n, n.nodeValue ? n.nodeValue.length : 0);
  11037. se.setRng(r);
  11038. // Remove the target container
  11039. ed.dom.remove(sc);
  11040. }
  11041. return Event.cancel(e);
  11042. }
  11043. }
  11044. }
  11045. }
  11046. });
  11047. })(tinymce);
  11048. (function(tinymce) {
  11049. // Shorten names
  11050. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, extend = tinymce.extend;
  11051. tinymce.create('tinymce.ControlManager', {
  11052. ControlManager : function(ed, s) {
  11053. var t = this, i;
  11054. s = s || {};
  11055. t.editor = ed;
  11056. t.controls = {};
  11057. t.onAdd = new tinymce.util.Dispatcher(t);
  11058. t.onPostRender = new tinymce.util.Dispatcher(t);
  11059. t.prefix = s.prefix || ed.id + '_';
  11060. t._cls = {};
  11061. t.onPostRender.add(function() {
  11062. each(t.controls, function(c) {
  11063. c.postRender();
  11064. });
  11065. });
  11066. },
  11067. get : function(id) {
  11068. return this.controls[this.prefix + id] || this.controls[id];
  11069. },
  11070. setActive : function(id, s) {
  11071. var c = null;
  11072. if (c = this.get(id))
  11073. c.setActive(s);
  11074. return c;
  11075. },
  11076. setDisabled : function(id, s) {
  11077. var c = null;
  11078. if (c = this.get(id))
  11079. c.setDisabled(s);
  11080. return c;
  11081. },
  11082. add : function(c) {
  11083. var t = this;
  11084. if (c) {
  11085. t.controls[c.id] = c;
  11086. t.onAdd.dispatch(c, t);
  11087. }
  11088. return c;
  11089. },
  11090. createControl : function(n) {
  11091. var c, t = this, ed = t.editor;
  11092. each(ed.plugins, function(p) {
  11093. if (p.createControl) {
  11094. c = p.createControl(n, t);
  11095. if (c)
  11096. return false;
  11097. }
  11098. });
  11099. switch (n) {
  11100. case "|":
  11101. case "separator":
  11102. return t.createSeparator();
  11103. }
  11104. if (!c && ed.buttons && (c = ed.buttons[n]))
  11105. return t.createButton(n, c);
  11106. return t.add(c);
  11107. },
  11108. createDropMenu : function(id, s, cc) {
  11109. var t = this, ed = t.editor, c, bm, v, cls;
  11110. s = extend({
  11111. 'class' : 'mceDropDown',
  11112. constrain : ed.settings.constrain_menus
  11113. }, s);
  11114. s['class'] = s['class'] + ' ' + ed.getParam('skin') + 'Skin';
  11115. if (v = ed.getParam('skin_variant'))
  11116. s['class'] += ' ' + ed.getParam('skin') + 'Skin' + v.substring(0, 1).toUpperCase() + v.substring(1);
  11117. id = t.prefix + id;
  11118. cls = cc || t._cls.dropmenu || tinymce.ui.DropMenu;
  11119. c = t.controls[id] = new cls(id, s);
  11120. c.onAddItem.add(function(c, o) {
  11121. var s = o.settings;
  11122. s.title = ed.getLang(s.title, s.title);
  11123. if (!s.onclick) {
  11124. s.onclick = function(v) {
  11125. if (s.cmd)
  11126. ed.execCommand(s.cmd, s.ui || false, s.value);
  11127. };
  11128. }
  11129. });
  11130. ed.onRemove.add(function() {
  11131. c.destroy();
  11132. });
  11133. // Fix for bug #1897785, #1898007
  11134. if (tinymce.isIE) {
  11135. c.onShowMenu.add(function() {
  11136. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  11137. ed.focus();
  11138. bm = ed.selection.getBookmark(1);
  11139. });
  11140. c.onHideMenu.add(function() {
  11141. if (bm) {
  11142. ed.selection.moveToBookmark(bm);
  11143. bm = 0;
  11144. }
  11145. });
  11146. }
  11147. return t.add(c);
  11148. },
  11149. createListBox : function(id, s, cc) {
  11150. var t = this, ed = t.editor, cmd, c, cls;
  11151. if (t.get(id))
  11152. return null;
  11153. s.title = ed.translate(s.title);
  11154. s.scope = s.scope || ed;
  11155. if (!s.onselect) {
  11156. s.onselect = function(v) {
  11157. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11158. };
  11159. }
  11160. s = extend({
  11161. title : s.title,
  11162. 'class' : 'mce_' + id,
  11163. scope : s.scope,
  11164. control_manager : t
  11165. }, s);
  11166. id = t.prefix + id;
  11167. if (ed.settings.use_native_selects)
  11168. c = new tinymce.ui.NativeListBox(id, s);
  11169. else {
  11170. cls = cc || t._cls.listbox || tinymce.ui.ListBox;
  11171. c = new cls(id, s, ed);
  11172. }
  11173. t.controls[id] = c;
  11174. // Fix focus problem in Safari
  11175. if (tinymce.isWebKit) {
  11176. c.onPostRender.add(function(c, n) {
  11177. // Store bookmark on mousedown
  11178. Event.add(n, 'mousedown', function() {
  11179. ed.bookmark = ed.selection.getBookmark(1);
  11180. });
  11181. // Restore on focus, since it might be lost
  11182. Event.add(n, 'focus', function() {
  11183. ed.selection.moveToBookmark(ed.bookmark);
  11184. ed.bookmark = null;
  11185. });
  11186. });
  11187. }
  11188. if (c.hideMenu)
  11189. ed.onMouseDown.add(c.hideMenu, c);
  11190. return t.add(c);
  11191. },
  11192. createButton : function(id, s, cc) {
  11193. var t = this, ed = t.editor, o, c, cls;
  11194. if (t.get(id))
  11195. return null;
  11196. s.title = ed.translate(s.title);
  11197. s.label = ed.translate(s.label);
  11198. s.scope = s.scope || ed;
  11199. if (!s.onclick && !s.menu_button) {
  11200. s.onclick = function() {
  11201. ed.execCommand(s.cmd, s.ui || false, s.value);
  11202. };
  11203. }
  11204. s = extend({
  11205. title : s.title,
  11206. 'class' : 'mce_' + id,
  11207. unavailable_prefix : ed.getLang('unavailable', ''),
  11208. scope : s.scope,
  11209. control_manager : t
  11210. }, s);
  11211. id = t.prefix + id;
  11212. if (s.menu_button) {
  11213. cls = cc || t._cls.menubutton || tinymce.ui.MenuButton;
  11214. c = new cls(id, s, ed);
  11215. ed.onMouseDown.add(c.hideMenu, c);
  11216. } else {
  11217. cls = t._cls.button || tinymce.ui.Button;
  11218. c = new cls(id, s, ed);
  11219. }
  11220. return t.add(c);
  11221. },
  11222. createMenuButton : function(id, s, cc) {
  11223. s = s || {};
  11224. s.menu_button = 1;
  11225. return this.createButton(id, s, cc);
  11226. },
  11227. createSplitButton : function(id, s, cc) {
  11228. var t = this, ed = t.editor, cmd, c, cls;
  11229. if (t.get(id))
  11230. return null;
  11231. s.title = ed.translate(s.title);
  11232. s.scope = s.scope || ed;
  11233. if (!s.onclick) {
  11234. s.onclick = function(v) {
  11235. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11236. };
  11237. }
  11238. if (!s.onselect) {
  11239. s.onselect = function(v) {
  11240. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11241. };
  11242. }
  11243. s = extend({
  11244. title : s.title,
  11245. 'class' : 'mce_' + id,
  11246. scope : s.scope,
  11247. control_manager : t
  11248. }, s);
  11249. id = t.prefix + id;
  11250. cls = cc || t._cls.splitbutton || tinymce.ui.SplitButton;
  11251. c = t.add(new cls(id, s, ed));
  11252. ed.onMouseDown.add(c.hideMenu, c);
  11253. return c;
  11254. },
  11255. createColorSplitButton : function(id, s, cc) {
  11256. var t = this, ed = t.editor, cmd, c, cls, bm;
  11257. if (t.get(id))
  11258. return null;
  11259. s.title = ed.translate(s.title);
  11260. s.scope = s.scope || ed;
  11261. if (!s.onclick) {
  11262. s.onclick = function(v) {
  11263. if (tinymce.isIE)
  11264. bm = ed.selection.getBookmark(1);
  11265. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11266. };
  11267. }
  11268. if (!s.onselect) {
  11269. s.onselect = function(v) {
  11270. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11271. };
  11272. }
  11273. s = extend({
  11274. title : s.title,
  11275. 'class' : 'mce_' + id,
  11276. 'menu_class' : ed.getParam('skin') + 'Skin',
  11277. scope : s.scope,
  11278. more_colors_title : ed.getLang('more_colors')
  11279. }, s);
  11280. id = t.prefix + id;
  11281. cls = cc || t._cls.colorsplitbutton || tinymce.ui.ColorSplitButton;
  11282. c = new cls(id, s, ed);
  11283. ed.onMouseDown.add(c.hideMenu, c);
  11284. // Remove the menu element when the editor is removed
  11285. ed.onRemove.add(function() {
  11286. c.destroy();
  11287. });
  11288. // Fix for bug #1897785, #1898007
  11289. if (tinymce.isIE) {
  11290. c.onShowMenu.add(function() {
  11291. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  11292. ed.focus();
  11293. bm = ed.selection.getBookmark(1);
  11294. });
  11295. c.onHideMenu.add(function() {
  11296. if (bm) {
  11297. ed.selection.moveToBookmark(bm);
  11298. bm = 0;
  11299. }
  11300. });
  11301. }
  11302. return t.add(c);
  11303. },
  11304. createToolbar : function(id, s, cc) {
  11305. var c, t = this, cls;
  11306. id = t.prefix + id;
  11307. cls = cc || t._cls.toolbar || tinymce.ui.Toolbar;
  11308. c = new cls(id, s, t.editor);
  11309. if (t.get(id))
  11310. return null;
  11311. return t.add(c);
  11312. },
  11313. createToolbarGroup : function(id, s, cc) {
  11314. var c, t = this, cls;
  11315. id = t.prefix + id;
  11316. cls = cc || this._cls.toolbarGroup || tinymce.ui.ToolbarGroup;
  11317. c = new cls(id, s, t.editor);
  11318. if (t.get(id))
  11319. return null;
  11320. return t.add(c);
  11321. },
  11322. createSeparator : function(cc) {
  11323. var cls = cc || this._cls.separator || tinymce.ui.Separator;
  11324. return new cls();
  11325. },
  11326. setControlType : function(n, c) {
  11327. return this._cls[n.toLowerCase()] = c;
  11328. },
  11329. destroy : function() {
  11330. each(this.controls, function(c) {
  11331. c.destroy();
  11332. });
  11333. this.controls = null;
  11334. }
  11335. });
  11336. })(tinymce);
  11337. (function(tinymce) {
  11338. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isIE = tinymce.isIE, isOpera = tinymce.isOpera;
  11339. tinymce.create('tinymce.WindowManager', {
  11340. WindowManager : function(ed) {
  11341. var t = this;
  11342. t.editor = ed;
  11343. t.onOpen = new Dispatcher(t);
  11344. t.onClose = new Dispatcher(t);
  11345. t.params = {};
  11346. t.features = {};
  11347. },
  11348. open : function(s, p) {
  11349. var t = this, f = '', x, y, mo = t.editor.settings.dialog_type == 'modal', w, sw, sh, vp = tinymce.DOM.getViewPort(), u;
  11350. // Default some options
  11351. s = s || {};
  11352. p = p || {};
  11353. sw = isOpera ? vp.w : screen.width; // Opera uses windows inside the Opera window
  11354. sh = isOpera ? vp.h : screen.height;
  11355. s.name = s.name || 'mc_' + new Date().getTime();
  11356. s.width = parseInt(s.width || 320);
  11357. s.height = parseInt(s.height || 240);
  11358. s.resizable = true;
  11359. s.left = s.left || parseInt(sw / 2.0) - (s.width / 2.0);
  11360. s.top = s.top || parseInt(sh / 2.0) - (s.height / 2.0);
  11361. p.inline = false;
  11362. p.mce_width = s.width;
  11363. p.mce_height = s.height;
  11364. p.mce_auto_focus = s.auto_focus;
  11365. if (mo) {
  11366. if (isIE) {
  11367. s.center = true;
  11368. s.help = false;
  11369. s.dialogWidth = s.width + 'px';
  11370. s.dialogHeight = s.height + 'px';
  11371. s.scroll = s.scrollbars || false;
  11372. }
  11373. }
  11374. // Build features string
  11375. each(s, function(v, k) {
  11376. if (tinymce.is(v, 'boolean'))
  11377. v = v ? 'yes' : 'no';
  11378. if (!/^(name|url)$/.test(k)) {
  11379. if (isIE && mo)
  11380. f += (f ? ';' : '') + k + ':' + v;
  11381. else
  11382. f += (f ? ',' : '') + k + '=' + v;
  11383. }
  11384. });
  11385. t.features = s;
  11386. t.params = p;
  11387. t.onOpen.dispatch(t, s, p);
  11388. u = s.url || s.file;
  11389. u = tinymce._addVer(u);
  11390. try {
  11391. if (isIE && mo) {
  11392. w = 1;
  11393. window.showModalDialog(u, window, f);
  11394. } else
  11395. w = window.open(u, s.name, f);
  11396. } catch (ex) {
  11397. // Ignore
  11398. }
  11399. if (!w)
  11400. alert(t.editor.getLang('popup_blocked'));
  11401. },
  11402. close : function(w) {
  11403. w.close();
  11404. this.onClose.dispatch(this);
  11405. },
  11406. createInstance : function(cl, a, b, c, d, e) {
  11407. var f = tinymce.resolve(cl);
  11408. return new f(a, b, c, d, e);
  11409. },
  11410. confirm : function(t, cb, s, w) {
  11411. w = w || window;
  11412. cb.call(s || this, w.confirm(this._decode(this.editor.getLang(t, t))));
  11413. },
  11414. alert : function(tx, cb, s, w) {
  11415. var t = this;
  11416. w = w || window;
  11417. w.alert(t._decode(t.editor.getLang(tx, tx)));
  11418. if (cb)
  11419. cb.call(s || t);
  11420. },
  11421. resizeBy : function(dw, dh, win) {
  11422. win.resizeBy(dw, dh);
  11423. },
  11424. // Internal functions
  11425. _decode : function(s) {
  11426. return tinymce.DOM.decode(s).replace(/\\n/g, '\n');
  11427. }
  11428. });
  11429. }(tinymce));
  11430. (function(tinymce) {
  11431. tinymce.Formatter = function(ed) {
  11432. var formats = {},
  11433. each = tinymce.each,
  11434. dom = ed.dom,
  11435. selection = ed.selection,
  11436. TreeWalker = tinymce.dom.TreeWalker,
  11437. rangeUtils = new tinymce.dom.RangeUtils(dom),
  11438. isValid = ed.schema.isValidChild,
  11439. isBlock = dom.isBlock,
  11440. forcedRootBlock = ed.settings.forced_root_block,
  11441. nodeIndex = dom.nodeIndex,
  11442. INVISIBLE_CHAR = '\uFEFF',
  11443. MCE_ATTR_RE = /^(src|href|style)$/,
  11444. FALSE = false,
  11445. TRUE = true,
  11446. undefined,
  11447. pendingFormats = {apply : [], remove : []};
  11448. function isArray(obj) {
  11449. return obj instanceof Array;
  11450. };
  11451. function getParents(node, selector) {
  11452. return dom.getParents(node, selector, dom.getRoot());
  11453. };
  11454. function isCaretNode(node) {
  11455. return node.nodeType === 1 && (node.face === 'mceinline' || node.style.fontFamily === 'mceinline');
  11456. };
  11457. // Public functions
  11458. function get(name) {
  11459. return name ? formats[name] : formats;
  11460. };
  11461. function register(name, format) {
  11462. if (name) {
  11463. if (typeof(name) !== 'string') {
  11464. each(name, function(format, name) {
  11465. register(name, format);
  11466. });
  11467. } else {
  11468. // Force format into array and add it to internal collection
  11469. format = format.length ? format : [format];
  11470. each(format, function(format) {
  11471. // Set deep to false by default on selector formats this to avoid removing
  11472. // alignment on images inside paragraphs when alignment is changed on paragraphs
  11473. if (format.deep === undefined)
  11474. format.deep = !format.selector;
  11475. // Default to true
  11476. if (format.split === undefined)
  11477. format.split = !format.selector || format.inline;
  11478. // Default to true
  11479. if (format.remove === undefined && format.selector && !format.inline)
  11480. format.remove = 'none';
  11481. // Mark format as a mixed format inline + block level
  11482. if (format.selector && format.inline) {
  11483. format.mixed = true;
  11484. format.block_expand = true;
  11485. }
  11486. // Split classes if needed
  11487. if (typeof(format.classes) === 'string')
  11488. format.classes = format.classes.split(/\s+/);
  11489. });
  11490. formats[name] = format;
  11491. }
  11492. }
  11493. };
  11494. var getTextDecoration = function(node) {
  11495. var decoration;
  11496. ed.dom.getParent(node, function(n) {
  11497. decoration = ed.dom.getStyle(n, 'text-decoration');
  11498. return decoration && decoration !== 'none';
  11499. });
  11500. return decoration;
  11501. };
  11502. var processUnderlineAndColor = function(node) {
  11503. var textDecoration;
  11504. if (node.nodeType === 1 && node.parentNode && node.parentNode.nodeType === 1) {
  11505. textDecoration = getTextDecoration(node.parentNode);
  11506. if (ed.dom.getStyle(node, 'color') && textDecoration) {
  11507. ed.dom.setStyle(node, 'text-decoration', textDecoration);
  11508. } else if (ed.dom.getStyle(node, 'textdecoration') === textDecoration) {
  11509. ed.dom.setStyle(node, 'text-decoration', null);
  11510. }
  11511. }
  11512. };
  11513. function apply(name, vars, node) {
  11514. var formatList = get(name), format = formatList[0], bookmark, rng, i, isCollapsed = selection.isCollapsed();
  11515. function moveStart(rng) {
  11516. var container = rng.startContainer,
  11517. offset = rng.startOffset,
  11518. walker, node;
  11519. // Move startContainer/startOffset in to a suitable node
  11520. if (container.nodeType == 1 || container.nodeValue === "") {
  11521. container = container.nodeType == 1 ? container.childNodes[offset] : container;
  11522. // Might fail if the offset is behind the last element in it's container
  11523. if (container) {
  11524. walker = new TreeWalker(container, container.parentNode);
  11525. for (node = walker.current(); node; node = walker.next()) {
  11526. if (node.nodeType == 3 && !isWhiteSpaceNode(node)) {
  11527. rng.setStart(node, 0);
  11528. break;
  11529. }
  11530. }
  11531. }
  11532. }
  11533. return rng;
  11534. };
  11535. function setElementFormat(elm, fmt) {
  11536. fmt = fmt || format;
  11537. if (elm) {
  11538. each(fmt.styles, function(value, name) {
  11539. dom.setStyle(elm, name, replaceVars(value, vars));
  11540. });
  11541. each(fmt.attributes, function(value, name) {
  11542. dom.setAttrib(elm, name, replaceVars(value, vars));
  11543. });
  11544. each(fmt.classes, function(value) {
  11545. value = replaceVars(value, vars);
  11546. if (!dom.hasClass(elm, value))
  11547. dom.addClass(elm, value);
  11548. });
  11549. }
  11550. };
  11551. function applyRngStyle(rng) {
  11552. var newWrappers = [], wrapName, wrapElm;
  11553. // Setup wrapper element
  11554. wrapName = format.inline || format.block;
  11555. wrapElm = dom.create(wrapName);
  11556. setElementFormat(wrapElm);
  11557. rangeUtils.walk(rng, function(nodes) {
  11558. var currentWrapElm;
  11559. function process(node) {
  11560. var nodeName = node.nodeName.toLowerCase(), parentName = node.parentNode.nodeName.toLowerCase(), found;
  11561. // Stop wrapping on br elements
  11562. if (isEq(nodeName, 'br')) {
  11563. currentWrapElm = 0;
  11564. // Remove any br elements when we wrap things
  11565. if (format.block)
  11566. dom.remove(node);
  11567. return;
  11568. }
  11569. // If node is wrapper type
  11570. if (format.wrapper && matchNode(node, name, vars)) {
  11571. currentWrapElm = 0;
  11572. return;
  11573. }
  11574. // Can we rename the block
  11575. if (format.block && !format.wrapper && isTextBlock(nodeName)) {
  11576. node = dom.rename(node, wrapName);
  11577. setElementFormat(node);
  11578. newWrappers.push(node);
  11579. currentWrapElm = 0;
  11580. return;
  11581. }
  11582. // Handle selector patterns
  11583. if (format.selector) {
  11584. // Look for matching formats
  11585. each(formatList, function(format) {
  11586. // Check collapsed state if it exists
  11587. if ('collapsed' in format && format.collapsed !== isCollapsed) {
  11588. return;
  11589. }
  11590. if (dom.is(node, format.selector) && !isCaretNode(node)) {
  11591. setElementFormat(node, format);
  11592. found = true;
  11593. }
  11594. });
  11595. // Continue processing if a selector match wasn't found and a inline element is defined
  11596. if (!format.inline || found) {
  11597. currentWrapElm = 0;
  11598. return;
  11599. }
  11600. }
  11601. // Is it valid to wrap this item
  11602. if (isValid(wrapName, nodeName) && isValid(parentName, wrapName) &&
  11603. !(node.nodeType === 3 && node.nodeValue.length === 1 && node.nodeValue.charCodeAt(0) === 65279)) {
  11604. // Start wrapping
  11605. if (!currentWrapElm) {
  11606. // Wrap the node
  11607. currentWrapElm = wrapElm.cloneNode(FALSE);
  11608. node.parentNode.insertBefore(currentWrapElm, node);
  11609. newWrappers.push(currentWrapElm);
  11610. }
  11611. currentWrapElm.appendChild(node);
  11612. } else if (nodeName == 'li') {
  11613. // Start wrapping
  11614. if (!currentWrapElm) {
  11615. // Wrap the node
  11616. liTextNode = node.ownerDocument.createTextNode('');
  11617. each(tinymce.grep(node.childNodes), function(n) { if (n.nodeType == 3) { liTextNode.nodeValue += n.nodeValue; n.parentNode.removeChild(n); } });
  11618. currentWrapElm = wrapElm.cloneNode(FALSE);
  11619. node.insertBefore(currentWrapElm, node.firstChild);
  11620. newWrappers.push(currentWrapElm);
  11621. }
  11622. currentWrapElm.appendChild(liTextNode);
  11623. } else {
  11624. // Start a new wrapper for possible children
  11625. currentWrapElm = 0;
  11626. each(tinymce.grep(node.childNodes), process);
  11627. // End the last wrapper
  11628. currentWrapElm = 0;
  11629. }
  11630. };
  11631. // Process siblings from range
  11632. each(nodes, process);
  11633. });
  11634. // Wrap links inside as well, for example color inside a link when the wrapper is around the link
  11635. if (format.wrap_links === false) {
  11636. each(newWrappers, function(node) {
  11637. function process(node) {
  11638. var i, currentWrapElm, children;
  11639. if (node.nodeName === 'A') {
  11640. currentWrapElm = wrapElm.cloneNode(FALSE);
  11641. newWrappers.push(currentWrapElm);
  11642. children = tinymce.grep(node.childNodes);
  11643. for (i = 0; i < children.length; i++)
  11644. currentWrapElm.appendChild(children[i]);
  11645. node.appendChild(currentWrapElm);
  11646. }
  11647. each(tinymce.grep(node.childNodes), process);
  11648. };
  11649. process(node);
  11650. });
  11651. }
  11652. // Cleanup
  11653. each(newWrappers, function(node) {
  11654. var childCount;
  11655. function getChildCount(node) {
  11656. var count = 0;
  11657. each(node.childNodes, function(node) {
  11658. if (!isWhiteSpaceNode(node) && !isBookmarkNode(node))
  11659. count++;
  11660. });
  11661. return count;
  11662. };
  11663. function mergeStyles(node) {
  11664. var child, clone;
  11665. each(node.childNodes, function(node) {
  11666. if (node.nodeType == 1 && !isBookmarkNode(node) && !isCaretNode(node)) {
  11667. child = node;
  11668. return FALSE; // break loop
  11669. }
  11670. });
  11671. // If child was found and of the same type as the current node
  11672. if (child && matchName(child, format)) {
  11673. clone = child.cloneNode(FALSE);
  11674. setElementFormat(clone);
  11675. dom.replace(clone, node, TRUE);
  11676. dom.remove(child, 1);
  11677. }
  11678. return clone || node;
  11679. };
  11680. childCount = getChildCount(node);
  11681. // Remove empty nodes but only if there is multiple wrappers and they are not block
  11682. // elements so never remove single <h1></h1> since that would remove the currrent empty block element where the caret is at
  11683. if ((newWrappers.length > 1 || !isBlock(node)) && childCount === 0) {
  11684. dom.remove(node, 1);
  11685. return;
  11686. }
  11687. if (format.inline || format.wrapper) {
  11688. // Merges the current node with it's children of similar type to reduce the number of elements
  11689. if (!format.exact && childCount === 1)
  11690. node = mergeStyles(node);
  11691. // Remove/merge children
  11692. each(formatList, function(format) {
  11693. // Merge all children of similar type will move styles from child to parent
  11694. // this: <span style="color:red"><b><span style="color:red; font-size:10px">text</span></b></span>
  11695. // will become: <span style="color:red"><b><span style="font-size:10px">text</span></b></span>
  11696. each(dom.select(format.inline, node), function(child) {
  11697. var parent;
  11698. // When wrap_links is set to false we don't want
  11699. // to remove the format on children within links
  11700. if (format.wrap_links === false) {
  11701. parent = child.parentNode;
  11702. do {
  11703. if (parent.nodeName === 'A')
  11704. return;
  11705. } while (parent = parent.parentNode);
  11706. }
  11707. removeFormat(format, vars, child, format.exact ? child : null);
  11708. });
  11709. });
  11710. // Remove child if direct parent is of same type
  11711. if (matchNode(node.parentNode, name, vars)) {
  11712. dom.remove(node, 1);
  11713. node = 0;
  11714. return TRUE;
  11715. }
  11716. // Look for parent with similar style format
  11717. if (format.merge_with_parents) {
  11718. dom.getParent(node.parentNode, function(parent) {
  11719. if (matchNode(parent, name, vars)) {
  11720. dom.remove(node, 1);
  11721. node = 0;
  11722. return TRUE;
  11723. }
  11724. });
  11725. }
  11726. // Merge next and previous siblings if they are similar <b>text</b><b>text</b> becomes <b>texttext</b>
  11727. if (node) {
  11728. node = mergeSiblings(getNonWhiteSpaceSibling(node), node);
  11729. node = mergeSiblings(node, getNonWhiteSpaceSibling(node, TRUE));
  11730. }
  11731. }
  11732. });
  11733. };
  11734. if (format) {
  11735. if (node) {
  11736. rng = dom.createRng();
  11737. rng.setStartBefore(node);
  11738. rng.setEndAfter(node);
  11739. applyRngStyle(expandRng(rng, formatList));
  11740. } else {
  11741. if (!isCollapsed || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
  11742. // Obtain selection node before selection is unselected by applyRngStyle()
  11743. var curSelNode = ed.selection.getNode();
  11744. // Apply formatting to selection
  11745. bookmark = selection.getBookmark();
  11746. applyRngStyle(expandRng(selection.getRng(TRUE), formatList));
  11747. // Colored nodes should be underlined so that the color of the underline matches the text color.
  11748. if (format.styles && (format.styles.color || format.styles.textDecoration)) {
  11749. tinymce.walk(curSelNode, processUnderlineAndColor, 'childNodes');
  11750. processUnderlineAndColor(curSelNode);
  11751. }
  11752. selection.moveToBookmark(bookmark);
  11753. selection.setRng(moveStart(selection.getRng(TRUE)));
  11754. ed.nodeChanged();
  11755. } else
  11756. performCaretAction('apply', name, vars);
  11757. }
  11758. }
  11759. };
  11760. function remove(name, vars, node) {
  11761. var formatList = get(name), format = formatList[0], bookmark, i, rng;
  11762. function moveStart(rng) {
  11763. var container = rng.startContainer,
  11764. offset = rng.startOffset,
  11765. walker, node, nodes, tmpNode;
  11766. // Convert text node into index if possible
  11767. if (container.nodeType == 3 && offset >= container.nodeValue.length - 1) {
  11768. container = container.parentNode;
  11769. offset = nodeIndex(container) + 1;
  11770. }
  11771. // Move startContainer/startOffset in to a suitable node
  11772. if (container.nodeType == 1) {
  11773. nodes = container.childNodes;
  11774. container = nodes[Math.min(offset, nodes.length - 1)];
  11775. walker = new TreeWalker(container);
  11776. // If offset is at end of the parent node walk to the next one
  11777. if (offset > nodes.length - 1)
  11778. walker.next();
  11779. for (node = walker.current(); node; node = walker.next()) {
  11780. if (node.nodeType == 3 && !isWhiteSpaceNode(node)) {
  11781. // IE has a "neat" feature where it moves the start node into the closest element
  11782. // we can avoid this by inserting an element before it and then remove it after we set the selection
  11783. tmpNode = dom.create('a', null, INVISIBLE_CHAR);
  11784. node.parentNode.insertBefore(tmpNode, node);
  11785. // Set selection and remove tmpNode
  11786. rng.setStart(node, 0);
  11787. selection.setRng(rng);
  11788. dom.remove(tmpNode);
  11789. return;
  11790. }
  11791. }
  11792. }
  11793. };
  11794. // Merges the styles for each node
  11795. function process(node) {
  11796. var children, i, l;
  11797. // Grab the children first since the nodelist might be changed
  11798. children = tinymce.grep(node.childNodes);
  11799. // Process current node
  11800. for (i = 0, l = formatList.length; i < l; i++) {
  11801. if (removeFormat(formatList[i], vars, node, node))
  11802. break;
  11803. }
  11804. // Process the children
  11805. if (format.deep) {
  11806. for (i = 0, l = children.length; i < l; i++)
  11807. process(children[i]);
  11808. }
  11809. };
  11810. function findFormatRoot(container) {
  11811. var formatRoot;
  11812. // Find format root
  11813. each(getParents(container.parentNode).reverse(), function(parent) {
  11814. var format;
  11815. // Find format root element
  11816. if (!formatRoot && parent.id != '_start' && parent.id != '_end') {
  11817. // Is the node matching the format we are looking for
  11818. format = matchNode(parent, name, vars);
  11819. if (format && format.split !== false)
  11820. formatRoot = parent;
  11821. }
  11822. });
  11823. return formatRoot;
  11824. };
  11825. function wrapAndSplit(format_root, container, target, split) {
  11826. var parent, clone, lastClone, firstClone, i, formatRootParent;
  11827. // Format root found then clone formats and split it
  11828. if (format_root) {
  11829. formatRootParent = format_root.parentNode;
  11830. for (parent = container.parentNode; parent && parent != formatRootParent; parent = parent.parentNode) {
  11831. clone = parent.cloneNode(FALSE);
  11832. for (i = 0; i < formatList.length; i++) {
  11833. if (removeFormat(formatList[i], vars, clone, clone)) {
  11834. clone = 0;
  11835. break;
  11836. }
  11837. }
  11838. // Build wrapper node
  11839. if (clone) {
  11840. if (lastClone)
  11841. clone.appendChild(lastClone);
  11842. if (!firstClone)
  11843. firstClone = clone;
  11844. lastClone = clone;
  11845. }
  11846. }
  11847. // Never split block elements if the format is mixed
  11848. if (split && (!format.mixed || !isBlock(format_root)))
  11849. container = dom.split(format_root, container);
  11850. // Wrap container in cloned formats
  11851. if (lastClone) {
  11852. target.parentNode.insertBefore(lastClone, target);
  11853. firstClone.appendChild(target);
  11854. }
  11855. }
  11856. return container;
  11857. };
  11858. function splitToFormatRoot(container) {
  11859. return wrapAndSplit(findFormatRoot(container), container, container, true);
  11860. };
  11861. function unwrap(start) {
  11862. var node = dom.get(start ? '_start' : '_end'),
  11863. out = node[start ? 'firstChild' : 'lastChild'];
  11864. // If the end is placed within the start the result will be removed
  11865. // So this checks if the out node is a bookmark node if it is it
  11866. // checks for another more suitable node
  11867. if (isBookmarkNode(out))
  11868. out = out[start ? 'firstChild' : 'lastChild'];
  11869. dom.remove(node, true);
  11870. return out;
  11871. };
  11872. function removeRngStyle(rng) {
  11873. var startContainer, endContainer;
  11874. rng = expandRng(rng, formatList, TRUE);
  11875. if (format.split) {
  11876. startContainer = getContainer(rng, TRUE);
  11877. endContainer = getContainer(rng);
  11878. if (startContainer != endContainer) {
  11879. // Wrap start/end nodes in span element since these might be cloned/moved
  11880. startContainer = wrap(startContainer, 'span', {id : '_start', 'data-mce-type' : 'bookmark'});
  11881. endContainer = wrap(endContainer, 'span', {id : '_end', 'data-mce-type' : 'bookmark'});
  11882. // Split start/end
  11883. splitToFormatRoot(startContainer);
  11884. splitToFormatRoot(endContainer);
  11885. // Unwrap start/end to get real elements again
  11886. startContainer = unwrap(TRUE);
  11887. endContainer = unwrap();
  11888. } else
  11889. startContainer = endContainer = splitToFormatRoot(startContainer);
  11890. // Update range positions since they might have changed after the split operations
  11891. rng.startContainer = startContainer.parentNode;
  11892. rng.startOffset = nodeIndex(startContainer);
  11893. rng.endContainer = endContainer.parentNode;
  11894. rng.endOffset = nodeIndex(endContainer) + 1;
  11895. }
  11896. // Remove items between start/end
  11897. rangeUtils.walk(rng, function(nodes) {
  11898. each(nodes, function(node) {
  11899. process(node);
  11900. // Remove parent span if it only contains text-decoration: underline, yet a parent node is also underlined.
  11901. if (node.nodeType === 1 && ed.dom.getStyle(node, 'text-decoration') === 'underline' && node.parentNode && getTextDecoration(node.parentNode) === 'underline') {
  11902. removeFormat({'deep': false, 'exact': true, 'inline': 'span', 'styles': {'textDecoration' : 'underline'}}, null, node);
  11903. }
  11904. });
  11905. });
  11906. };
  11907. // Handle node
  11908. if (node) {
  11909. rng = dom.createRng();
  11910. rng.setStartBefore(node);
  11911. rng.setEndAfter(node);
  11912. removeRngStyle(rng);
  11913. return;
  11914. }
  11915. if (!selection.isCollapsed() || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
  11916. bookmark = selection.getBookmark();
  11917. removeRngStyle(selection.getRng(TRUE));
  11918. selection.moveToBookmark(bookmark);
  11919. // 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
  11920. if (match(name, vars, selection.getStart())) {
  11921. moveStart(selection.getRng(true));
  11922. }
  11923. ed.nodeChanged();
  11924. } else
  11925. performCaretAction('remove', name, vars);
  11926. };
  11927. function toggle(name, vars, node) {
  11928. var fmt = get(name);
  11929. if (match(name, vars, node) && (!('toggle' in fmt[0]) || fmt[0]['toggle']))
  11930. remove(name, vars, node);
  11931. else
  11932. apply(name, vars, node);
  11933. };
  11934. function matchNode(node, name, vars, similar) {
  11935. var formatList = get(name), format, i, classes;
  11936. function matchItems(node, format, item_name) {
  11937. var key, value, items = format[item_name], i;
  11938. // Check all items
  11939. if (items) {
  11940. // Non indexed object
  11941. if (items.length === undefined) {
  11942. for (key in items) {
  11943. if (items.hasOwnProperty(key)) {
  11944. if (item_name === 'attributes')
  11945. value = dom.getAttrib(node, key);
  11946. else
  11947. value = getStyle(node, key);
  11948. if (similar && !value && !format.exact)
  11949. return;
  11950. if ((!similar || format.exact) && !isEq(value, replaceVars(items[key], vars)))
  11951. return;
  11952. }
  11953. }
  11954. } else {
  11955. // Only one match needed for indexed arrays
  11956. for (i = 0; i < items.length; i++) {
  11957. if (item_name === 'attributes' ? dom.getAttrib(node, items[i]) : getStyle(node, items[i]))
  11958. return format;
  11959. }
  11960. }
  11961. }
  11962. return format;
  11963. };
  11964. if (formatList && node) {
  11965. // Check each format in list
  11966. for (i = 0; i < formatList.length; i++) {
  11967. format = formatList[i];
  11968. // Name name, attributes, styles and classes
  11969. if (matchName(node, format) && matchItems(node, format, 'attributes') && matchItems(node, format, 'styles')) {
  11970. // Match classes
  11971. if (classes = format.classes) {
  11972. for (i = 0; i < classes.length; i++) {
  11973. if (!dom.hasClass(node, classes[i]))
  11974. return;
  11975. }
  11976. }
  11977. return format;
  11978. }
  11979. }
  11980. }
  11981. };
  11982. function match(name, vars, node) {
  11983. var startNode, i;
  11984. function matchParents(node) {
  11985. // Find first node with similar format settings
  11986. node = dom.getParent(node, function(node) {
  11987. return !!matchNode(node, name, vars, true);
  11988. });
  11989. // Do an exact check on the similar format element
  11990. return matchNode(node, name, vars);
  11991. };
  11992. // Check specified node
  11993. if (node)
  11994. return matchParents(node);
  11995. // Check pending formats
  11996. if (selection.isCollapsed()) {
  11997. for (i = pendingFormats.apply.length - 1; i >= 0; i--) {
  11998. if (pendingFormats.apply[i].name == name)
  11999. return true;
  12000. }
  12001. for (i = pendingFormats.remove.length - 1; i >= 0; i--) {
  12002. if (pendingFormats.remove[i].name == name)
  12003. return false;
  12004. }
  12005. return matchParents(selection.getNode());
  12006. }
  12007. // Check selected node
  12008. node = selection.getNode();
  12009. if (matchParents(node))
  12010. return TRUE;
  12011. // Check start node if it's different
  12012. startNode = selection.getStart();
  12013. if (startNode != node) {
  12014. if (matchParents(startNode))
  12015. return TRUE;
  12016. }
  12017. return FALSE;
  12018. };
  12019. function matchAll(names, vars) {
  12020. var startElement, matchedFormatNames = [], checkedMap = {}, i, ni, name;
  12021. // If the selection is collapsed then check pending formats
  12022. if (selection.isCollapsed()) {
  12023. for (ni = 0; ni < names.length; ni++) {
  12024. // If the name is to be removed, then stop it from being added
  12025. for (i = pendingFormats.remove.length - 1; i >= 0; i--) {
  12026. name = names[ni];
  12027. if (pendingFormats.remove[i].name == name) {
  12028. checkedMap[name] = true;
  12029. break;
  12030. }
  12031. }
  12032. }
  12033. // If the format is to be applied
  12034. for (i = pendingFormats.apply.length - 1; i >= 0; i--) {
  12035. for (ni = 0; ni < names.length; ni++) {
  12036. name = names[ni];
  12037. if (!checkedMap[name] && pendingFormats.apply[i].name == name) {
  12038. checkedMap[name] = true;
  12039. matchedFormatNames.push(name);
  12040. }
  12041. }
  12042. }
  12043. }
  12044. // Check start of selection for formats
  12045. startElement = selection.getStart();
  12046. dom.getParent(startElement, function(node) {
  12047. var i, name;
  12048. for (i = 0; i < names.length; i++) {
  12049. name = names[i];
  12050. if (!checkedMap[name] && matchNode(node, name, vars)) {
  12051. checkedMap[name] = true;
  12052. matchedFormatNames.push(name);
  12053. }
  12054. }
  12055. });
  12056. return matchedFormatNames;
  12057. };
  12058. function canApply(name) {
  12059. var formatList = get(name), startNode, parents, i, x, selector;
  12060. if (formatList) {
  12061. startNode = selection.getStart();
  12062. parents = getParents(startNode);
  12063. for (x = formatList.length - 1; x >= 0; x--) {
  12064. selector = formatList[x].selector;
  12065. // Format is not selector based, then always return TRUE
  12066. if (!selector)
  12067. return TRUE;
  12068. for (i = parents.length - 1; i >= 0; i--) {
  12069. if (dom.is(parents[i], selector))
  12070. return TRUE;
  12071. }
  12072. }
  12073. }
  12074. return FALSE;
  12075. };
  12076. // Expose to public
  12077. tinymce.extend(this, {
  12078. get : get,
  12079. register : register,
  12080. apply : apply,
  12081. remove : remove,
  12082. toggle : toggle,
  12083. match : match,
  12084. matchAll : matchAll,
  12085. matchNode : matchNode,
  12086. canApply : canApply
  12087. });
  12088. // Private functions
  12089. function matchName(node, format) {
  12090. // Check for inline match
  12091. if (isEq(node, format.inline))
  12092. return TRUE;
  12093. // Check for block match
  12094. if (isEq(node, format.block))
  12095. return TRUE;
  12096. // Check for selector match
  12097. if (format.selector)
  12098. return dom.is(node, format.selector);
  12099. };
  12100. function isEq(str1, str2) {
  12101. str1 = str1 || '';
  12102. str2 = str2 || '';
  12103. str1 = '' + (str1.nodeName || str1);
  12104. str2 = '' + (str2.nodeName || str2);
  12105. return str1.toLowerCase() == str2.toLowerCase();
  12106. };
  12107. function getStyle(node, name) {
  12108. var styleVal = dom.getStyle(node, name);
  12109. // Force the format to hex
  12110. if (name == 'color' || name == 'backgroundColor')
  12111. styleVal = dom.toHex(styleVal);
  12112. // Opera will return bold as 700
  12113. if (name == 'fontWeight' && styleVal == 700)
  12114. styleVal = 'bold';
  12115. return '' + styleVal;
  12116. };
  12117. function replaceVars(value, vars) {
  12118. if (typeof(value) != "string")
  12119. value = value(vars);
  12120. else if (vars) {
  12121. value = value.replace(/%(\w+)/g, function(str, name) {
  12122. return vars[name] || str;
  12123. });
  12124. }
  12125. return value;
  12126. };
  12127. function isWhiteSpaceNode(node) {
  12128. return node && node.nodeType === 3 && /^([\s\r\n]+|)$/.test(node.nodeValue);
  12129. };
  12130. function wrap(node, name, attrs) {
  12131. var wrapper = dom.create(name, attrs);
  12132. node.parentNode.insertBefore(wrapper, node);
  12133. wrapper.appendChild(node);
  12134. return wrapper;
  12135. };
  12136. function expandRng(rng, format, remove) {
  12137. var startContainer = rng.startContainer,
  12138. startOffset = rng.startOffset,
  12139. endContainer = rng.endContainer,
  12140. endOffset = rng.endOffset, sibling, lastIdx, leaf;
  12141. // This function walks up the tree if there is no siblings before/after the node
  12142. function findParentContainer(container, child_name, sibling_name, root) {
  12143. var parent, child;
  12144. root = root || dom.getRoot();
  12145. for (;;) {
  12146. // Check if we can move up are we at root level or body level
  12147. parent = container.parentNode;
  12148. // Stop expanding on block elements or root depending on format
  12149. if (parent == root || (!format[0].block_expand && isBlock(parent)))
  12150. return container;
  12151. for (sibling = parent[child_name]; sibling && sibling != container; sibling = sibling[sibling_name]) {
  12152. if (sibling.nodeType == 1 && !isBookmarkNode(sibling))
  12153. return container;
  12154. if (sibling.nodeType == 3 && !isWhiteSpaceNode(sibling))
  12155. return container;
  12156. }
  12157. container = container.parentNode;
  12158. }
  12159. return container;
  12160. };
  12161. // This function walks down the tree to find the leaf at the selection.
  12162. // The offset is also returned as if node initially a leaf, the offset may be in the middle of the text node.
  12163. function findLeaf(node, offset) {
  12164. if (offset === undefined)
  12165. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  12166. while (node && node.hasChildNodes()) {
  12167. node = node.childNodes[offset];
  12168. if (node)
  12169. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  12170. }
  12171. return { node: node, offset: offset };
  12172. }
  12173. // If index based start position then resolve it
  12174. if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) {
  12175. lastIdx = startContainer.childNodes.length - 1;
  12176. startContainer = startContainer.childNodes[startOffset > lastIdx ? lastIdx : startOffset];
  12177. if (startContainer.nodeType == 3)
  12178. startOffset = 0;
  12179. }
  12180. // If index based end position then resolve it
  12181. if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) {
  12182. lastIdx = endContainer.childNodes.length - 1;
  12183. endContainer = endContainer.childNodes[endOffset > lastIdx ? lastIdx : endOffset - 1];
  12184. if (endContainer.nodeType == 3)
  12185. endOffset = endContainer.nodeValue.length;
  12186. }
  12187. // Exclude bookmark nodes if possible
  12188. if (isBookmarkNode(startContainer.parentNode))
  12189. startContainer = startContainer.parentNode;
  12190. if (isBookmarkNode(startContainer))
  12191. startContainer = startContainer.nextSibling || startContainer;
  12192. if (isBookmarkNode(endContainer.parentNode)) {
  12193. endOffset = dom.nodeIndex(endContainer);
  12194. endContainer = endContainer.parentNode;
  12195. }
  12196. if (isBookmarkNode(endContainer) && endContainer.previousSibling) {
  12197. endContainer = endContainer.previousSibling;
  12198. endOffset = endContainer.length;
  12199. }
  12200. if (format[0].inline) {
  12201. // Avoid applying formatting to a trailing space.
  12202. leaf = findLeaf(endContainer, endOffset);
  12203. if (leaf.node) {
  12204. while (leaf.node && leaf.offset === 0 && leaf.node.previousSibling)
  12205. leaf = findLeaf(leaf.node.previousSibling);
  12206. if (leaf.node && leaf.offset > 0 && leaf.node.nodeType === 3 &&
  12207. leaf.node.nodeValue.charAt(leaf.offset - 1) === ' ') {
  12208. if (leaf.offset > 1) {
  12209. endContainer = leaf.node;
  12210. endContainer.splitText(leaf.offset - 1);
  12211. } else if (leaf.node.previousSibling) {
  12212. endContainer = leaf.node.previousSibling;
  12213. }
  12214. }
  12215. }
  12216. }
  12217. // Move start/end point up the tree if the leaves are sharp and if we are in different containers
  12218. // Example * becomes !: !<p><b><i>*text</i><i>text*</i></b></p>!
  12219. // This will reduce the number of wrapper elements that needs to be created
  12220. // Move start point up the tree
  12221. if (format[0].inline || format[0].block_expand) {
  12222. startContainer = findParentContainer(startContainer, 'firstChild', 'nextSibling');
  12223. endContainer = findParentContainer(endContainer, 'lastChild', 'previousSibling');
  12224. }
  12225. // Expand start/end container to matching selector
  12226. if (format[0].selector && format[0].expand !== FALSE && !format[0].inline) {
  12227. function findSelectorEndPoint(container, sibling_name) {
  12228. var parents, i, y, curFormat;
  12229. if (container.nodeType == 3 && container.nodeValue.length == 0 && container[sibling_name])
  12230. container = container[sibling_name];
  12231. parents = getParents(container);
  12232. for (i = 0; i < parents.length; i++) {
  12233. for (y = 0; y < format.length; y++) {
  12234. curFormat = format[y];
  12235. // If collapsed state is set then skip formats that doesn't match that
  12236. if ("collapsed" in curFormat && curFormat.collapsed !== rng.collapsed)
  12237. continue;
  12238. if (dom.is(parents[i], curFormat.selector))
  12239. return parents[i];
  12240. }
  12241. }
  12242. return container;
  12243. };
  12244. // Find new startContainer/endContainer if there is better one
  12245. startContainer = findSelectorEndPoint(startContainer, 'previousSibling');
  12246. endContainer = findSelectorEndPoint(endContainer, 'nextSibling');
  12247. }
  12248. // Expand start/end container to matching block element or text node
  12249. if (format[0].block || format[0].selector) {
  12250. function findBlockEndPoint(container, sibling_name, sibling_name2) {
  12251. var node;
  12252. // Expand to block of similar type
  12253. if (!format[0].wrapper)
  12254. node = dom.getParent(container, format[0].block);
  12255. // Expand to first wrappable block element or any block element
  12256. if (!node)
  12257. node = dom.getParent(container.nodeType == 3 ? container.parentNode : container, isBlock);
  12258. // Exclude inner lists from wrapping
  12259. if (node && format[0].wrapper)
  12260. node = getParents(node, 'ul,ol').reverse()[0] || node;
  12261. // Didn't find a block element look for first/last wrappable element
  12262. if (!node) {
  12263. node = container;
  12264. while (node[sibling_name] && !isBlock(node[sibling_name])) {
  12265. node = node[sibling_name];
  12266. // Break on BR but include it will be removed later on
  12267. // we can't remove it now since we need to check if it can be wrapped
  12268. if (isEq(node, 'br'))
  12269. break;
  12270. }
  12271. }
  12272. return node || container;
  12273. };
  12274. // Find new startContainer/endContainer if there is better one
  12275. startContainer = findBlockEndPoint(startContainer, 'previousSibling');
  12276. endContainer = findBlockEndPoint(endContainer, 'nextSibling');
  12277. // Non block element then try to expand up the leaf
  12278. if (format[0].block) {
  12279. if (!isBlock(startContainer))
  12280. startContainer = findParentContainer(startContainer, 'firstChild', 'nextSibling');
  12281. if (!isBlock(endContainer))
  12282. endContainer = findParentContainer(endContainer, 'lastChild', 'previousSibling');
  12283. }
  12284. }
  12285. // Setup index for startContainer
  12286. if (startContainer.nodeType == 1) {
  12287. startOffset = nodeIndex(startContainer);
  12288. startContainer = startContainer.parentNode;
  12289. }
  12290. // Setup index for endContainer
  12291. if (endContainer.nodeType == 1) {
  12292. endOffset = nodeIndex(endContainer) + 1;
  12293. endContainer = endContainer.parentNode;
  12294. }
  12295. // Return new range like object
  12296. return {
  12297. startContainer : startContainer,
  12298. startOffset : startOffset,
  12299. endContainer : endContainer,
  12300. endOffset : endOffset
  12301. };
  12302. }
  12303. function removeFormat(format, vars, node, compare_node) {
  12304. var i, attrs, stylesModified;
  12305. // Check if node matches format
  12306. if (!matchName(node, format))
  12307. return FALSE;
  12308. // Should we compare with format attribs and styles
  12309. if (format.remove != 'all') {
  12310. // Remove styles
  12311. each(format.styles, function(value, name) {
  12312. value = replaceVars(value, vars);
  12313. // Indexed array
  12314. if (typeof(name) === 'number') {
  12315. name = value;
  12316. compare_node = 0;
  12317. }
  12318. if (!compare_node || isEq(getStyle(compare_node, name), value))
  12319. dom.setStyle(node, name, '');
  12320. stylesModified = 1;
  12321. });
  12322. // Remove style attribute if it's empty
  12323. if (stylesModified && dom.getAttrib(node, 'style') == '') {
  12324. node.removeAttribute('style');
  12325. node.removeAttribute('data-mce-style');
  12326. }
  12327. // Remove attributes
  12328. each(format.attributes, function(value, name) {
  12329. var valueOut;
  12330. value = replaceVars(value, vars);
  12331. // Indexed array
  12332. if (typeof(name) === 'number') {
  12333. name = value;
  12334. compare_node = 0;
  12335. }
  12336. if (!compare_node || isEq(dom.getAttrib(compare_node, name), value)) {
  12337. // Keep internal classes
  12338. if (name == 'class') {
  12339. value = dom.getAttrib(node, name);
  12340. if (value) {
  12341. // Build new class value where everything is removed except the internal prefixed classes
  12342. valueOut = '';
  12343. each(value.split(/\s+/), function(cls) {
  12344. if (/mce\w+/.test(cls))
  12345. valueOut += (valueOut ? ' ' : '') + cls;
  12346. });
  12347. // We got some internal classes left
  12348. if (valueOut) {
  12349. dom.setAttrib(node, name, valueOut);
  12350. return;
  12351. }
  12352. }
  12353. }
  12354. // IE6 has a bug where the attribute doesn't get removed correctly
  12355. if (name == "class")
  12356. node.removeAttribute('className');
  12357. // Remove mce prefixed attributes
  12358. if (MCE_ATTR_RE.test(name))
  12359. node.removeAttribute('data-mce-' + name);
  12360. node.removeAttribute(name);
  12361. }
  12362. });
  12363. // Remove classes
  12364. each(format.classes, function(value) {
  12365. value = replaceVars(value, vars);
  12366. if (!compare_node || dom.hasClass(compare_node, value))
  12367. dom.removeClass(node, value);
  12368. });
  12369. // Check for non internal attributes
  12370. attrs = dom.getAttribs(node);
  12371. for (i = 0; i < attrs.length; i++) {
  12372. if (attrs[i].nodeName.indexOf('_') !== 0)
  12373. return FALSE;
  12374. }
  12375. }
  12376. // Remove the inline child if it's empty for example <b> or <span>
  12377. if (format.remove != 'none') {
  12378. removeNode(node, format);
  12379. return TRUE;
  12380. }
  12381. };
  12382. function removeNode(node, format) {
  12383. var parentNode = node.parentNode, rootBlockElm;
  12384. if (format.block) {
  12385. if (!forcedRootBlock) {
  12386. function find(node, next, inc) {
  12387. node = getNonWhiteSpaceSibling(node, next, inc);
  12388. return !node || (node.nodeName == 'BR' || isBlock(node));
  12389. };
  12390. // Append BR elements if needed before we remove the block
  12391. if (isBlock(node) && !isBlock(parentNode)) {
  12392. if (!find(node, FALSE) && !find(node.firstChild, TRUE, 1))
  12393. node.insertBefore(dom.create('br'), node.firstChild);
  12394. if (!find(node, TRUE) && !find(node.lastChild, FALSE, 1))
  12395. node.appendChild(dom.create('br'));
  12396. }
  12397. } else {
  12398. // Wrap the block in a forcedRootBlock if we are at the root of document
  12399. if (parentNode == dom.getRoot()) {
  12400. if (!format.list_block || !isEq(node, format.list_block)) {
  12401. each(tinymce.grep(node.childNodes), function(node) {
  12402. if (isValid(forcedRootBlock, node.nodeName.toLowerCase())) {
  12403. if (!rootBlockElm)
  12404. rootBlockElm = wrap(node, forcedRootBlock);
  12405. else
  12406. rootBlockElm.appendChild(node);
  12407. } else
  12408. rootBlockElm = 0;
  12409. });
  12410. }
  12411. }
  12412. }
  12413. }
  12414. // Never remove nodes that isn't the specified inline element if a selector is specified too
  12415. if (format.selector && format.inline && !isEq(format.inline, node))
  12416. return;
  12417. dom.remove(node, 1);
  12418. };
  12419. function getNonWhiteSpaceSibling(node, next, inc) {
  12420. if (node) {
  12421. next = next ? 'nextSibling' : 'previousSibling';
  12422. for (node = inc ? node : node[next]; node; node = node[next]) {
  12423. if (node.nodeType == 1 || !isWhiteSpaceNode(node))
  12424. return node;
  12425. }
  12426. }
  12427. };
  12428. function isBookmarkNode(node) {
  12429. return node && node.nodeType == 1 && node.getAttribute('data-mce-type') == 'bookmark';
  12430. };
  12431. function mergeSiblings(prev, next) {
  12432. var marker, sibling, tmpSibling;
  12433. function compareElements(node1, node2) {
  12434. // Not the same name
  12435. if (node1.nodeName != node2.nodeName)
  12436. return FALSE;
  12437. function getAttribs(node) {
  12438. var attribs = {};
  12439. each(dom.getAttribs(node), function(attr) {
  12440. var name = attr.nodeName.toLowerCase();
  12441. // Don't compare internal attributes or style
  12442. if (name.indexOf('_') !== 0 && name !== 'style')
  12443. attribs[name] = dom.getAttrib(node, name);
  12444. });
  12445. return attribs;
  12446. };
  12447. function compareObjects(obj1, obj2) {
  12448. var value, name;
  12449. for (name in obj1) {
  12450. // Obj1 has item obj2 doesn't have
  12451. if (obj1.hasOwnProperty(name)) {
  12452. value = obj2[name];
  12453. // Obj2 doesn't have obj1 item
  12454. if (value === undefined)
  12455. return FALSE;
  12456. // Obj2 item has a different value
  12457. if (obj1[name] != value)
  12458. return FALSE;
  12459. // Delete similar value
  12460. delete obj2[name];
  12461. }
  12462. }
  12463. // Check if obj 2 has something obj 1 doesn't have
  12464. for (name in obj2) {
  12465. // Obj2 has item obj1 doesn't have
  12466. if (obj2.hasOwnProperty(name))
  12467. return FALSE;
  12468. }
  12469. return TRUE;
  12470. };
  12471. // Attribs are not the same
  12472. if (!compareObjects(getAttribs(node1), getAttribs(node2)))
  12473. return FALSE;
  12474. // Styles are not the same
  12475. if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style'))))
  12476. return FALSE;
  12477. return TRUE;
  12478. };
  12479. // Check if next/prev exists and that they are elements
  12480. if (prev && next) {
  12481. function findElementSibling(node, sibling_name) {
  12482. for (sibling = node; sibling; sibling = sibling[sibling_name]) {
  12483. if (sibling.nodeType == 3 && sibling.nodeValue.length !== 0)
  12484. return node;
  12485. if (sibling.nodeType == 1 && !isBookmarkNode(sibling))
  12486. return sibling;
  12487. }
  12488. return node;
  12489. };
  12490. // If previous sibling is empty then jump over it
  12491. prev = findElementSibling(prev, 'previousSibling');
  12492. next = findElementSibling(next, 'nextSibling');
  12493. // Compare next and previous nodes
  12494. if (compareElements(prev, next)) {
  12495. // Append nodes between
  12496. for (sibling = prev.nextSibling; sibling && sibling != next;) {
  12497. tmpSibling = sibling;
  12498. sibling = sibling.nextSibling;
  12499. prev.appendChild(tmpSibling);
  12500. }
  12501. // Remove next node
  12502. dom.remove(next);
  12503. // Move children into prev node
  12504. each(tinymce.grep(next.childNodes), function(node) {
  12505. prev.appendChild(node);
  12506. });
  12507. return prev;
  12508. }
  12509. }
  12510. return next;
  12511. };
  12512. function isTextBlock(name) {
  12513. return /^(h[1-6]|p|div|pre|address|dl|dt|dd)$/.test(name);
  12514. };
  12515. function getContainer(rng, start) {
  12516. var container, offset, lastIdx;
  12517. container = rng[start ? 'startContainer' : 'endContainer'];
  12518. offset = rng[start ? 'startOffset' : 'endOffset'];
  12519. if (container.nodeType == 1) {
  12520. lastIdx = container.childNodes.length - 1;
  12521. if (!start && offset)
  12522. offset--;
  12523. container = container.childNodes[offset > lastIdx ? lastIdx : offset];
  12524. }
  12525. return container;
  12526. };
  12527. function performCaretAction(type, name, vars) {
  12528. var i, currentPendingFormats = pendingFormats[type],
  12529. otherPendingFormats = pendingFormats[type == 'apply' ? 'remove' : 'apply'];
  12530. function hasPending() {
  12531. return pendingFormats.apply.length || pendingFormats.remove.length;
  12532. };
  12533. function resetPending() {
  12534. pendingFormats.apply = [];
  12535. pendingFormats.remove = [];
  12536. };
  12537. function perform(caret_node) {
  12538. // Apply pending formats
  12539. each(pendingFormats.apply.reverse(), function(item) {
  12540. apply(item.name, item.vars, caret_node);
  12541. // Colored nodes should be underlined so that the color of the underline matches the text color.
  12542. if (item.name === 'forecolor' && item.vars.value)
  12543. processUnderlineAndColor(caret_node.parentNode);
  12544. });
  12545. // Remove pending formats
  12546. each(pendingFormats.remove.reverse(), function(item) {
  12547. remove(item.name, item.vars, caret_node);
  12548. });
  12549. dom.remove(caret_node, 1);
  12550. resetPending();
  12551. };
  12552. // Check if it already exists then ignore it
  12553. for (i = currentPendingFormats.length - 1; i >= 0; i--) {
  12554. if (currentPendingFormats[i].name == name)
  12555. return;
  12556. }
  12557. currentPendingFormats.push({name : name, vars : vars});
  12558. // Check if it's in the other type, then remove it
  12559. for (i = otherPendingFormats.length - 1; i >= 0; i--) {
  12560. if (otherPendingFormats[i].name == name)
  12561. otherPendingFormats.splice(i, 1);
  12562. }
  12563. // Pending apply or remove formats
  12564. if (hasPending()) {
  12565. ed.getDoc().execCommand('FontName', false, 'mceinline');
  12566. pendingFormats.lastRng = selection.getRng();
  12567. // IE will convert the current word
  12568. each(dom.select('font,span'), function(node) {
  12569. var bookmark;
  12570. if (isCaretNode(node)) {
  12571. bookmark = selection.getBookmark();
  12572. perform(node);
  12573. selection.moveToBookmark(bookmark);
  12574. ed.nodeChanged();
  12575. }
  12576. });
  12577. // Only register listeners once if we need to
  12578. if (!pendingFormats.isListening && hasPending()) {
  12579. pendingFormats.isListening = true;
  12580. each('onKeyDown,onKeyUp,onKeyPress,onMouseUp'.split(','), function(event) {
  12581. ed[event].addToTop(function(ed, e) {
  12582. // Do we have pending formats and is the selection moved has moved
  12583. if (hasPending() && !tinymce.dom.RangeUtils.compareRanges(pendingFormats.lastRng, selection.getRng())) {
  12584. each(dom.select('font,span'), function(node) {
  12585. var textNode, rng;
  12586. // Look for marker
  12587. if (isCaretNode(node)) {
  12588. textNode = node.firstChild;
  12589. // Find the first text node within node
  12590. while (textNode && textNode.nodeType != 3)
  12591. textNode = textNode.firstChild;
  12592. if (textNode) {
  12593. perform(node);
  12594. rng = dom.createRng();
  12595. rng.setStart(textNode, textNode.nodeValue.length);
  12596. rng.setEnd(textNode, textNode.nodeValue.length);
  12597. selection.setRng(rng);
  12598. ed.nodeChanged();
  12599. } else
  12600. dom.remove(node);
  12601. }
  12602. });
  12603. // Always unbind and clear pending styles on keyup
  12604. if (e.type == 'keyup' || e.type == 'mouseup')
  12605. resetPending();
  12606. }
  12607. });
  12608. });
  12609. }
  12610. }
  12611. };
  12612. };
  12613. })(tinymce);
  12614. tinymce.onAddEditor.add(function(tinymce, ed) {
  12615. var filters, fontSizes, dom, settings = ed.settings;
  12616. if (settings.inline_styles) {
  12617. fontSizes = tinymce.explode(settings.font_size_style_values);
  12618. function replaceWithSpan(node, styles) {
  12619. tinymce.each(styles, function(value, name) {
  12620. if (value)
  12621. dom.setStyle(node, name, value);
  12622. });
  12623. dom.rename(node, 'span');
  12624. };
  12625. filters = {
  12626. font : function(dom, node) {
  12627. replaceWithSpan(node, {
  12628. backgroundColor : node.style.backgroundColor,
  12629. color : node.color,
  12630. fontFamily : node.face,
  12631. fontSize : fontSizes[parseInt(node.size) - 1]
  12632. });
  12633. },
  12634. u : function(dom, node) {
  12635. replaceWithSpan(node, {
  12636. textDecoration : 'underline'
  12637. });
  12638. },
  12639. strike : function(dom, node) {
  12640. replaceWithSpan(node, {
  12641. textDecoration : 'line-through'
  12642. });
  12643. }
  12644. };
  12645. function convert(editor, params) {
  12646. dom = editor.dom;
  12647. if (settings.convert_fonts_to_spans) {
  12648. tinymce.each(dom.select('font,u,strike', params.node), function(node) {
  12649. filters[node.nodeName.toLowerCase()](ed.dom, node);
  12650. });
  12651. }
  12652. };
  12653. ed.onPreProcess.add(convert);
  12654. ed.onSetContent.add(convert);
  12655. ed.onInit.add(function() {
  12656. ed.selection.onSetContent.add(convert);
  12657. });
  12658. }
  12659. });