tiny_mce_src.js 420 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728
  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.7',
  7. releaseDate : '2011-11-03',
  8. _init : function() {
  9. var t = this, d = document, na = navigator, ua = na.userAgent, i, nl, n, base, p, v;
  10. t.isOpera = win.opera && opera.buildNumber;
  11. t.isWebKit = /WebKit/.test(ua);
  12. t.isIE = !t.isWebKit && !t.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(na.appName);
  13. t.isIE6 = t.isIE && /MSIE [56]/.test(ua);
  14. t.isIE7 = t.isIE && /MSIE [7]/.test(ua);
  15. t.isIE8 = t.isIE && /MSIE [8]/.test(ua);
  16. t.isIE9 = t.isIE && /MSIE [9]/.test(ua);
  17. t.isGecko = !t.isWebKit && /Gecko/.test(ua);
  18. t.isMac = ua.indexOf('Mac') != -1;
  19. t.isAir = /adobeair/i.test(ua);
  20. t.isIDevice = /(iPad|iPhone)/.test(ua);
  21. t.isIOS5 = t.isIDevice && ua.match(/AppleWebKit\/(\d*)/)[1]>=534;
  22. // TinyMCE .NET webcontrol might be setting the values for TinyMCE
  23. if (win.tinyMCEPreInit) {
  24. t.suffix = tinyMCEPreInit.suffix;
  25. t.baseURL = tinyMCEPreInit.base;
  26. t.query = tinyMCEPreInit.query;
  27. return;
  28. }
  29. // Get suffix and base
  30. t.suffix = '';
  31. // If base element found, add that infront of baseURL
  32. nl = d.getElementsByTagName('base');
  33. for (i=0; i<nl.length; i++) {
  34. if (v = nl[i].href) {
  35. // Host only value like http://site.com or http://site.com:8008
  36. if (/^https?:\/\/[^\/]+$/.test(v))
  37. v += '/';
  38. base = v ? v.match(/.*\//)[0] : ''; // Get only directory
  39. }
  40. }
  41. function getBase(n) {
  42. if (n.src && /tiny_mce(|_gzip|_jquery|_prototype|_full)(_dev|_src)?.js/.test(n.src)) {
  43. if (/_(src|dev)\.js/g.test(n.src))
  44. t.suffix = '_src';
  45. if ((p = n.src.indexOf('?')) != -1)
  46. t.query = n.src.substring(p + 1);
  47. t.baseURL = n.src.substring(0, n.src.lastIndexOf('/'));
  48. // If path to script is relative and a base href was found add that one infront
  49. // the src property will always be an absolute one on non IE browsers and IE 8
  50. // so this logic will basically only be executed on older IE versions
  51. if (base && t.baseURL.indexOf('://') == -1 && t.baseURL.indexOf('/') !== 0)
  52. t.baseURL = base + t.baseURL;
  53. return t.baseURL;
  54. }
  55. return null;
  56. };
  57. // Check document
  58. nl = d.getElementsByTagName('script');
  59. for (i=0; i<nl.length; i++) {
  60. if (getBase(nl[i]))
  61. return;
  62. }
  63. // Check head
  64. n = d.getElementsByTagName('head')[0];
  65. if (n) {
  66. nl = n.getElementsByTagName('script');
  67. for (i=0; i<nl.length; i++) {
  68. if (getBase(nl[i]))
  69. return;
  70. }
  71. }
  72. return;
  73. },
  74. is : function(o, t) {
  75. if (!t)
  76. return o !== undefined;
  77. if (t == 'array' && (o.hasOwnProperty && o instanceof Array))
  78. return true;
  79. return typeof(o) == t;
  80. },
  81. makeMap : function(items, delim, map) {
  82. var i;
  83. items = items || [];
  84. delim = delim || ',';
  85. if (typeof(items) == "string")
  86. items = items.split(delim);
  87. map = map || {};
  88. i = items.length;
  89. while (i--)
  90. map[items[i]] = {};
  91. return map;
  92. },
  93. each : function(o, cb, s) {
  94. var n, l;
  95. if (!o)
  96. return 0;
  97. s = s || o;
  98. if (o.length !== undefined) {
  99. // Indexed arrays, needed for Safari
  100. for (n=0, l = o.length; n < l; n++) {
  101. if (cb.call(s, o[n], n, o) === false)
  102. return 0;
  103. }
  104. } else {
  105. // Hashtables
  106. for (n in o) {
  107. if (o.hasOwnProperty(n)) {
  108. if (cb.call(s, o[n], n, o) === false)
  109. return 0;
  110. }
  111. }
  112. }
  113. return 1;
  114. },
  115. map : function(a, f) {
  116. var o = [];
  117. tinymce.each(a, function(v) {
  118. o.push(f(v));
  119. });
  120. return o;
  121. },
  122. grep : function(a, f) {
  123. var o = [];
  124. tinymce.each(a, function(v) {
  125. if (!f || f(v))
  126. o.push(v);
  127. });
  128. return o;
  129. },
  130. inArray : function(a, v) {
  131. var i, l;
  132. if (a) {
  133. for (i = 0, l = a.length; i < l; i++) {
  134. if (a[i] === v)
  135. return i;
  136. }
  137. }
  138. return -1;
  139. },
  140. extend : function(o, e) {
  141. var i, l, a = arguments;
  142. for (i = 1, l = a.length; i < l; i++) {
  143. e = a[i];
  144. tinymce.each(e, function(v, n) {
  145. if (v !== undefined)
  146. o[n] = v;
  147. });
  148. }
  149. return o;
  150. },
  151. trim : function(s) {
  152. return (s ? '' + s : '').replace(whiteSpaceRe, '');
  153. },
  154. create : function(s, p, root) {
  155. var t = this, sp, ns, cn, scn, c, de = 0;
  156. // Parse : <prefix> <class>:<super class>
  157. s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s);
  158. cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name
  159. // Create namespace for new class
  160. ns = t.createNS(s[3].replace(/\.\w+$/, ''), root);
  161. // Class already exists
  162. if (ns[cn])
  163. return;
  164. // Make pure static class
  165. if (s[2] == 'static') {
  166. ns[cn] = p;
  167. if (this.onCreate)
  168. this.onCreate(s[2], s[3], ns[cn]);
  169. return;
  170. }
  171. // Create default constructor
  172. if (!p[cn]) {
  173. p[cn] = function() {};
  174. de = 1;
  175. }
  176. // Add constructor and methods
  177. ns[cn] = p[cn];
  178. t.extend(ns[cn].prototype, p);
  179. // Extend
  180. if (s[5]) {
  181. sp = t.resolve(s[5]).prototype;
  182. scn = s[5].match(/\.(\w+)$/i)[1]; // Class name
  183. // Extend constructor
  184. c = ns[cn];
  185. if (de) {
  186. // Add passthrough constructor
  187. ns[cn] = function() {
  188. return sp[scn].apply(this, arguments);
  189. };
  190. } else {
  191. // Add inherit constructor
  192. ns[cn] = function() {
  193. this.parent = sp[scn];
  194. return c.apply(this, arguments);
  195. };
  196. }
  197. ns[cn].prototype[cn] = ns[cn];
  198. // Add super methods
  199. t.each(sp, function(f, n) {
  200. ns[cn].prototype[n] = sp[n];
  201. });
  202. // Add overridden methods
  203. t.each(p, function(f, n) {
  204. // Extend methods if needed
  205. if (sp[n]) {
  206. ns[cn].prototype[n] = function() {
  207. this.parent = sp[n];
  208. return f.apply(this, arguments);
  209. };
  210. } else {
  211. if (n != cn)
  212. ns[cn].prototype[n] = f;
  213. }
  214. });
  215. }
  216. // Add static methods
  217. t.each(p['static'], function(f, n) {
  218. ns[cn][n] = f;
  219. });
  220. if (this.onCreate)
  221. this.onCreate(s[2], s[3], ns[cn].prototype);
  222. },
  223. walk : function(o, f, n, s) {
  224. s = s || this;
  225. if (o) {
  226. if (n)
  227. o = o[n];
  228. tinymce.each(o, function(o, i) {
  229. if (f.call(s, o, i, n) === false)
  230. return false;
  231. tinymce.walk(o, f, n, s);
  232. });
  233. }
  234. },
  235. createNS : function(n, o) {
  236. var i, v;
  237. o = o || win;
  238. n = n.split('.');
  239. for (i=0; i<n.length; i++) {
  240. v = n[i];
  241. if (!o[v])
  242. o[v] = {};
  243. o = o[v];
  244. }
  245. return o;
  246. },
  247. resolve : function(n, o) {
  248. var i, l;
  249. o = o || win;
  250. n = n.split('.');
  251. for (i = 0, l = n.length; i < l; i++) {
  252. o = o[n[i]];
  253. if (!o)
  254. break;
  255. }
  256. return o;
  257. },
  258. addUnload : function(f, s) {
  259. var t = this;
  260. f = {func : f, scope : s || this};
  261. if (!t.unloads) {
  262. function unload() {
  263. var li = t.unloads, o, n;
  264. if (li) {
  265. // Call unload handlers
  266. for (n in li) {
  267. o = li[n];
  268. if (o && o.func)
  269. o.func.call(o.scope, 1); // Send in one arg to distinct unload and user destroy
  270. }
  271. // Detach unload function
  272. if (win.detachEvent) {
  273. win.detachEvent('onbeforeunload', fakeUnload);
  274. win.detachEvent('onunload', unload);
  275. } else if (win.removeEventListener)
  276. win.removeEventListener('unload', unload, false);
  277. // Destroy references
  278. t.unloads = o = li = w = unload = 0;
  279. // Run garbarge collector on IE
  280. if (win.CollectGarbage)
  281. CollectGarbage();
  282. }
  283. };
  284. function fakeUnload() {
  285. var d = document;
  286. // Is there things still loading, then do some magic
  287. if (d.readyState == 'interactive') {
  288. function stop() {
  289. // Prevent memory leak
  290. d.detachEvent('onstop', stop);
  291. // Call unload handler
  292. if (unload)
  293. unload();
  294. d = 0;
  295. };
  296. // Fire unload when the currently loading page is stopped
  297. if (d)
  298. d.attachEvent('onstop', stop);
  299. // Remove onstop listener after a while to prevent the unload function
  300. // to execute if the user presses cancel in an onbeforeunload
  301. // confirm dialog and then presses the browser stop button
  302. win.setTimeout(function() {
  303. if (d)
  304. d.detachEvent('onstop', stop);
  305. }, 0);
  306. }
  307. };
  308. // Attach unload handler
  309. if (win.attachEvent) {
  310. win.attachEvent('onunload', unload);
  311. win.attachEvent('onbeforeunload', fakeUnload);
  312. } else if (win.addEventListener)
  313. win.addEventListener('unload', unload, false);
  314. // Setup initial unload handler array
  315. t.unloads = [f];
  316. } else
  317. t.unloads.push(f);
  318. return f;
  319. },
  320. removeUnload : function(f) {
  321. var u = this.unloads, r = null;
  322. tinymce.each(u, function(o, i) {
  323. if (o && o.func == f) {
  324. u.splice(i, 1);
  325. r = f;
  326. return false;
  327. }
  328. });
  329. return r;
  330. },
  331. explode : function(s, d) {
  332. return s ? tinymce.map(s.split(d || ','), tinymce.trim) : s;
  333. },
  334. _addVer : function(u) {
  335. var v;
  336. if (!this.query)
  337. return u;
  338. v = (u.indexOf('?') == -1 ? '?' : '&') + this.query;
  339. if (u.indexOf('#') == -1)
  340. return u + v;
  341. return u.replace('#', v + '#');
  342. },
  343. // Fix function for IE 9 where regexps isn't working correctly
  344. // Todo: remove me once MS fixes the bug
  345. _replace : function(find, replace, str) {
  346. // On IE9 we have to fake $x replacement
  347. if (isRegExpBroken) {
  348. return str.replace(find, function() {
  349. var val = replace, args = arguments, i;
  350. for (i = 0; i < args.length - 2; i++) {
  351. if (args[i] === undefined) {
  352. val = val.replace(new RegExp('\\$' + i, 'g'), '');
  353. } else {
  354. val = val.replace(new RegExp('\\$' + i, 'g'), args[i]);
  355. }
  356. }
  357. return val;
  358. });
  359. }
  360. return str.replace(find, replace);
  361. }
  362. };
  363. // Initialize the API
  364. tinymce._init();
  365. // Expose tinymce namespace to the global namespace (window)
  366. win.tinymce = win.tinyMCE = tinymce;
  367. // Describe the different namespaces
  368. })(window);
  369. tinymce.create('tinymce.util.Dispatcher', {
  370. scope : null,
  371. listeners : null,
  372. Dispatcher : function(s) {
  373. this.scope = s || this;
  374. this.listeners = [];
  375. },
  376. add : function(cb, s) {
  377. this.listeners.push({cb : cb, scope : s || this.scope});
  378. return cb;
  379. },
  380. addToTop : function(cb, s) {
  381. this.listeners.unshift({cb : cb, scope : s || this.scope});
  382. return cb;
  383. },
  384. remove : function(cb) {
  385. var l = this.listeners, o = null;
  386. tinymce.each(l, function(c, i) {
  387. if (cb == c.cb) {
  388. o = cb;
  389. l.splice(i, 1);
  390. return false;
  391. }
  392. });
  393. return o;
  394. },
  395. dispatch : function() {
  396. var s, a = arguments, i, li = this.listeners, c;
  397. // Needs to be a real loop since the listener count might change while looping
  398. // And this is also more efficient
  399. for (i = 0; i<li.length; i++) {
  400. c = li[i];
  401. s = c.cb.apply(c.scope, a);
  402. if (s === false)
  403. break;
  404. }
  405. return s;
  406. }
  407. });
  408. (function() {
  409. var each = tinymce.each;
  410. tinymce.create('tinymce.util.URI', {
  411. URI : function(u, s) {
  412. var t = this, o, a, b, base_url;
  413. // Trim whitespace
  414. u = tinymce.trim(u);
  415. // Default settings
  416. s = t.settings = s || {};
  417. // Strange app protocol that isn't http/https or local anchor
  418. // For example: mailto,skype,tel etc.
  419. if (/^([\w\-]+):([^\/]{2})/i.test(u) || /^\s*#/.test(u)) {
  420. t.source = u;
  421. return;
  422. }
  423. // Absolute path with no host, fake host and protocol
  424. if (u.indexOf('/') === 0 && u.indexOf('//') !== 0)
  425. u = (s.base_uri ? s.base_uri.protocol || 'http' : 'http') + '://mce_host' + u;
  426. // Relative path http:// or protocol relative //path
  427. if (!/^[\w-]*:?\/\//.test(u)) {
  428. base_url = s.base_uri ? s.base_uri.path : new tinymce.util.URI(location.href).directory;
  429. u = ((s.base_uri && s.base_uri.protocol) || 'http') + '://mce_host' + t.toAbsPath(base_url, u);
  430. }
  431. // Parse URL (Credits goes to Steave, http://blog.stevenlevithan.com/archives/parseuri)
  432. u = u.replace(/@@/g, '(mce_at)'); // Zope 3 workaround, they use @@something
  433. u = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(u);
  434. each(["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], function(v, i) {
  435. var s = u[i];
  436. // Zope 3 workaround, they use @@something
  437. if (s)
  438. s = s.replace(/\(mce_at\)/g, '@@');
  439. t[v] = s;
  440. });
  441. if (b = s.base_uri) {
  442. if (!t.protocol)
  443. t.protocol = b.protocol;
  444. if (!t.userInfo)
  445. t.userInfo = b.userInfo;
  446. if (!t.port && t.host == 'mce_host')
  447. t.port = b.port;
  448. if (!t.host || t.host == 'mce_host')
  449. t.host = b.host;
  450. t.source = '';
  451. }
  452. //t.path = t.path || '/';
  453. },
  454. setPath : function(p) {
  455. var t = this;
  456. p = /^(.*?)\/?(\w+)?$/.exec(p);
  457. // Update path parts
  458. t.path = p[0];
  459. t.directory = p[1];
  460. t.file = p[2];
  461. // Rebuild source
  462. t.source = '';
  463. t.getURI();
  464. },
  465. toRelative : function(u) {
  466. var t = this, o;
  467. if (u === "./")
  468. return u;
  469. u = new tinymce.util.URI(u, {base_uri : t});
  470. // Not on same domain/port or protocol
  471. if ((u.host != 'mce_host' && t.host != u.host && u.host) || t.port != u.port || t.protocol != u.protocol)
  472. return u.getURI();
  473. o = t.toRelPath(t.path, u.path);
  474. // Add query
  475. if (u.query)
  476. o += '?' + u.query;
  477. // Add anchor
  478. if (u.anchor)
  479. o += '#' + u.anchor;
  480. return o;
  481. },
  482. toAbsolute : function(u, nh) {
  483. var u = new tinymce.util.URI(u, {base_uri : this});
  484. return u.getURI(this.host == u.host && this.protocol == u.protocol ? nh : 0);
  485. },
  486. toRelPath : function(base, path) {
  487. var items, bp = 0, out = '', i, l;
  488. // Split the paths
  489. base = base.substring(0, base.lastIndexOf('/'));
  490. base = base.split('/');
  491. items = path.split('/');
  492. if (base.length >= items.length) {
  493. for (i = 0, l = base.length; i < l; i++) {
  494. if (i >= items.length || base[i] != items[i]) {
  495. bp = i + 1;
  496. break;
  497. }
  498. }
  499. }
  500. if (base.length < items.length) {
  501. for (i = 0, l = items.length; i < l; i++) {
  502. if (i >= base.length || base[i] != items[i]) {
  503. bp = i + 1;
  504. break;
  505. }
  506. }
  507. }
  508. if (bp == 1)
  509. return path;
  510. for (i = 0, l = base.length - (bp - 1); i < l; i++)
  511. out += "../";
  512. for (i = bp - 1, l = items.length; i < l; i++) {
  513. if (i != bp - 1)
  514. out += "/" + items[i];
  515. else
  516. out += items[i];
  517. }
  518. return out;
  519. },
  520. toAbsPath : function(base, path) {
  521. var i, nb = 0, o = [], tr, outPath;
  522. // Split paths
  523. tr = /\/$/.test(path) ? '/' : '';
  524. base = base.split('/');
  525. path = path.split('/');
  526. // Remove empty chunks
  527. each(base, function(k) {
  528. if (k)
  529. o.push(k);
  530. });
  531. base = o;
  532. // Merge relURLParts chunks
  533. for (i = path.length - 1, o = []; i >= 0; i--) {
  534. // Ignore empty or .
  535. if (path[i].length == 0 || path[i] == ".")
  536. continue;
  537. // Is parent
  538. if (path[i] == '..') {
  539. nb++;
  540. continue;
  541. }
  542. // Move up
  543. if (nb > 0) {
  544. nb--;
  545. continue;
  546. }
  547. o.push(path[i]);
  548. }
  549. i = base.length - nb;
  550. // If /a/b/c or /
  551. if (i <= 0)
  552. outPath = o.reverse().join('/');
  553. else
  554. outPath = base.slice(0, i).join('/') + '/' + o.reverse().join('/');
  555. // Add front / if it's needed
  556. if (outPath.indexOf('/') !== 0)
  557. outPath = '/' + outPath;
  558. // Add traling / if it's needed
  559. if (tr && outPath.lastIndexOf('/') !== outPath.length - 1)
  560. outPath += tr;
  561. return outPath;
  562. },
  563. getURI : function(nh) {
  564. var s, t = this;
  565. // Rebuild source
  566. if (!t.source || nh) {
  567. s = '';
  568. if (!nh) {
  569. if (t.protocol)
  570. s += t.protocol + '://';
  571. if (t.userInfo)
  572. s += t.userInfo + '@';
  573. if (t.host)
  574. s += t.host;
  575. if (t.port)
  576. s += ':' + t.port;
  577. }
  578. if (t.path)
  579. s += t.path;
  580. if (t.query)
  581. s += '?' + t.query;
  582. if (t.anchor)
  583. s += '#' + t.anchor;
  584. t.source = s;
  585. }
  586. return t.source;
  587. }
  588. });
  589. })();
  590. (function() {
  591. var each = tinymce.each;
  592. tinymce.create('static tinymce.util.Cookie', {
  593. getHash : function(n) {
  594. var v = this.get(n), h;
  595. if (v) {
  596. each(v.split('&'), function(v) {
  597. v = v.split('=');
  598. h = h || {};
  599. h[unescape(v[0])] = unescape(v[1]);
  600. });
  601. }
  602. return h;
  603. },
  604. setHash : function(n, v, e, p, d, s) {
  605. var o = '';
  606. each(v, function(v, k) {
  607. o += (!o ? '' : '&') + escape(k) + '=' + escape(v);
  608. });
  609. this.set(n, o, e, p, d, s);
  610. },
  611. get : function(n) {
  612. var c = document.cookie, e, p = n + "=", b;
  613. // Strict mode
  614. if (!c)
  615. return;
  616. b = c.indexOf("; " + p);
  617. if (b == -1) {
  618. b = c.indexOf(p);
  619. if (b != 0)
  620. return null;
  621. } else
  622. b += 2;
  623. e = c.indexOf(";", b);
  624. if (e == -1)
  625. e = c.length;
  626. return unescape(c.substring(b + p.length, e));
  627. },
  628. set : function(n, v, e, p, d, s) {
  629. document.cookie = n + "=" + escape(v) +
  630. ((e) ? "; expires=" + e.toGMTString() : "") +
  631. ((p) ? "; path=" + escape(p) : "") +
  632. ((d) ? "; domain=" + d : "") +
  633. ((s) ? "; secure" : "");
  634. },
  635. remove : function(n, p) {
  636. var d = new Date();
  637. d.setTime(d.getTime() - 1000);
  638. this.set(n, '', d, p, d);
  639. }
  640. });
  641. })();
  642. (function() {
  643. function serialize(o, quote) {
  644. var i, v, t;
  645. quote = quote || '"';
  646. if (o == null)
  647. return 'null';
  648. t = typeof o;
  649. if (t == 'string') {
  650. v = '\bb\tt\nn\ff\rr\""\'\'\\\\';
  651. return quote + o.replace(/([\u0080-\uFFFF\x00-\x1f\"\'\\])/g, function(a, b) {
  652. // Make sure single quotes never get encoded inside double quotes for JSON compatibility
  653. if (quote === '"' && a === "'")
  654. return a;
  655. i = v.indexOf(b);
  656. if (i + 1)
  657. return '\\' + v.charAt(i + 1);
  658. a = b.charCodeAt().toString(16);
  659. return '\\u' + '0000'.substring(a.length) + a;
  660. }) + quote;
  661. }
  662. if (t == 'object') {
  663. if (o.hasOwnProperty && o instanceof Array) {
  664. for (i=0, v = '['; i<o.length; i++)
  665. v += (i > 0 ? ',' : '') + serialize(o[i], quote);
  666. return v + ']';
  667. }
  668. v = '{';
  669. for (i in o) {
  670. if (o.hasOwnProperty(i)) {
  671. v += typeof o[i] != 'function' ? (v.length > 1 ? ',' + quote : quote) + i + quote +':' + serialize(o[i], quote) : '';
  672. }
  673. }
  674. return v + '}';
  675. }
  676. return '' + o;
  677. };
  678. tinymce.util.JSON = {
  679. serialize: serialize,
  680. parse: function(s) {
  681. try {
  682. return eval('(' + s + ')');
  683. } catch (ex) {
  684. // Ignore
  685. }
  686. }
  687. };
  688. })();
  689. tinymce.create('static tinymce.util.XHR', {
  690. send : function(o) {
  691. var x, t, w = window, c = 0;
  692. // Default settings
  693. o.scope = o.scope || this;
  694. o.success_scope = o.success_scope || o.scope;
  695. o.error_scope = o.error_scope || o.scope;
  696. o.async = o.async === false ? false : true;
  697. o.data = o.data || '';
  698. function get(s) {
  699. x = 0;
  700. try {
  701. x = new ActiveXObject(s);
  702. } catch (ex) {
  703. }
  704. return x;
  705. };
  706. x = w.XMLHttpRequest ? new XMLHttpRequest() : get('Microsoft.XMLHTTP') || get('Msxml2.XMLHTTP');
  707. if (x) {
  708. if (x.overrideMimeType)
  709. x.overrideMimeType(o.content_type);
  710. x.open(o.type || (o.data ? 'POST' : 'GET'), o.url, o.async);
  711. if (o.content_type)
  712. x.setRequestHeader('Content-Type', o.content_type);
  713. x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  714. x.send(o.data);
  715. function ready() {
  716. if (!o.async || x.readyState == 4 || c++ > 10000) {
  717. if (o.success && c < 10000 && x.status == 200)
  718. o.success.call(o.success_scope, '' + x.responseText, x, o);
  719. else if (o.error)
  720. o.error.call(o.error_scope, c > 10000 ? 'TIMED_OUT' : 'GENERAL', x, o);
  721. x = null;
  722. } else
  723. w.setTimeout(ready, 10);
  724. };
  725. // Syncronous request
  726. if (!o.async)
  727. return ready();
  728. // Wait for response, onReadyStateChange can not be used since it leaks memory in IE
  729. t = w.setTimeout(ready, 10);
  730. }
  731. }
  732. });
  733. (function() {
  734. var extend = tinymce.extend, JSON = tinymce.util.JSON, XHR = tinymce.util.XHR;
  735. tinymce.create('tinymce.util.JSONRequest', {
  736. JSONRequest : function(s) {
  737. this.settings = extend({
  738. }, s);
  739. this.count = 0;
  740. },
  741. send : function(o) {
  742. var ecb = o.error, scb = o.success;
  743. o = extend(this.settings, o);
  744. o.success = function(c, x) {
  745. c = JSON.parse(c);
  746. if (typeof(c) == 'undefined') {
  747. c = {
  748. error : 'JSON Parse error.'
  749. };
  750. }
  751. if (c.error)
  752. ecb.call(o.error_scope || o.scope, c.error, x);
  753. else
  754. scb.call(o.success_scope || o.scope, c.result);
  755. };
  756. o.error = function(ty, x) {
  757. if (ecb)
  758. ecb.call(o.error_scope || o.scope, ty, x);
  759. };
  760. o.data = JSON.serialize({
  761. id : o.id || 'c' + (this.count++),
  762. method : o.method,
  763. params : o.params
  764. });
  765. // JSON content type for Ruby on rails. Bug: #1883287
  766. o.content_type = 'application/json';
  767. XHR.send(o);
  768. },
  769. 'static' : {
  770. sendRPC : function(o) {
  771. return new tinymce.util.JSONRequest().send(o);
  772. }
  773. }
  774. });
  775. }());
  776. (function(tinymce){
  777. tinymce.VK = {
  778. DELETE: 46,
  779. BACKSPACE: 8,
  780. ENTER: 13,
  781. TAB: 9,
  782. SPACEBAR: 32,
  783. UP: 38,
  784. DOWN: 40
  785. }
  786. })(tinymce);
  787. (function(tinymce) {
  788. var VK = tinymce.VK, BACKSPACE = VK.BACKSPACE, DELETE = VK.DELETE;
  789. function cleanupStylesWhenDeleting(ed) {
  790. var dom = ed.dom, selection = ed.selection;
  791. ed.onKeyDown.add(function(ed, e) {
  792. var rng, blockElm, node, clonedSpan, isDelete;
  793. isDelete = e.keyCode == DELETE;
  794. if (isDelete || e.keyCode == BACKSPACE) {
  795. e.preventDefault();
  796. rng = selection.getRng();
  797. // Find root block
  798. blockElm = dom.getParent(rng.startContainer, dom.isBlock);
  799. // On delete clone the root span of the next block element
  800. if (isDelete)
  801. blockElm = dom.getNext(blockElm, dom.isBlock);
  802. // Locate root span element and clone it since it would otherwise get merged by the "apple-style-span" on delete/backspace
  803. if (blockElm) {
  804. node = blockElm.firstChild;
  805. // Ignore empty text nodes
  806. while (node && node.nodeType == 3 && node.nodeValue.length == 0)
  807. node = node.nextSibling;
  808. if (node && node.nodeName === 'SPAN') {
  809. clonedSpan = node.cloneNode(false);
  810. }
  811. }
  812. // Do the backspace/delete actiopn
  813. ed.getDoc().execCommand(isDelete ? 'ForwardDelete' : 'Delete', false, null);
  814. // Find all odd apple-style-spans
  815. blockElm = dom.getParent(rng.startContainer, dom.isBlock);
  816. tinymce.each(dom.select('span.Apple-style-span,font.Apple-style-span', blockElm), function(span) {
  817. var bm = selection.getBookmark();
  818. if (clonedSpan) {
  819. dom.replace(clonedSpan.cloneNode(false), span, true);
  820. } else {
  821. dom.remove(span, true);
  822. }
  823. // Restore the selection
  824. selection.moveToBookmark(bm);
  825. });
  826. }
  827. });
  828. };
  829. function emptyEditorWhenDeleting(ed) {
  830. ed.onKeyUp.add(function(ed, e) {
  831. var keyCode = e.keyCode;
  832. if (keyCode == DELETE || keyCode == BACKSPACE) {
  833. if (ed.dom.isEmpty(ed.getBody())) {
  834. ed.setContent('', {format : 'raw'});
  835. ed.nodeChanged();
  836. return;
  837. }
  838. }
  839. });
  840. };
  841. function inputMethodFocus(ed) {
  842. ed.dom.bind(ed.getDoc(), 'focusin', function() {
  843. ed.selection.setRng(ed.selection.getRng());
  844. });
  845. };
  846. function removeHrOnBackspace(ed) {
  847. ed.onKeyDown.add(function(ed, e) {
  848. if (e.keyCode === BACKSPACE) {
  849. if (ed.selection.isCollapsed() && ed.selection.getRng(true).startOffset === 0) {
  850. var node = ed.selection.getNode();
  851. var previousSibling = node.previousSibling;
  852. if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === "hr") {
  853. ed.dom.remove(previousSibling);
  854. tinymce.dom.Event.cancel(e);
  855. }
  856. }
  857. }
  858. })
  859. }
  860. function focusBody(ed) {
  861. // Fix for a focus bug in FF 3.x where the body element
  862. // wouldn't get proper focus if the user clicked on the HTML element
  863. if (!Range.prototype.getClientRects) { // Detect getClientRects got introduced in FF 4
  864. ed.onMouseDown.add(function(ed, e) {
  865. if (e.target.nodeName === "HTML") {
  866. var body = ed.getBody();
  867. // Blur the body it's focused but not correctly focused
  868. body.blur();
  869. // Refocus the body after a little while
  870. setTimeout(function() {
  871. body.focus();
  872. }, 0);
  873. }
  874. });
  875. }
  876. };
  877. function selectControlElements(ed) {
  878. ed.onClick.add(function(ed, e) {
  879. e = e.target;
  880. // Workaround for bug, http://bugs.webkit.org/show_bug.cgi?id=12250
  881. // WebKit can't even do simple things like selecting an image
  882. // Needs tobe the setBaseAndExtend or it will fail to select floated images
  883. if (/^(IMG|HR)$/.test(e.nodeName))
  884. ed.selection.getSel().setBaseAndExtent(e, 0, e, 1);
  885. if (e.nodeName == 'A' && ed.dom.hasClass(e, 'mceItemAnchor'))
  886. ed.selection.select(e);
  887. ed.nodeChanged();
  888. });
  889. };
  890. function selectionChangeNodeChanged(ed) {
  891. var lastRng, selectionTimer;
  892. ed.dom.bind(ed.getDoc(), 'selectionchange', function() {
  893. if (selectionTimer) {
  894. clearTimeout(selectionTimer);
  895. selectionTimer = 0;
  896. }
  897. selectionTimer = window.setTimeout(function() {
  898. var rng = ed.selection.getRng();
  899. // Compare the ranges to see if it was a real change or not
  900. if (!lastRng || !tinymce.dom.RangeUtils.compareRanges(rng, lastRng)) {
  901. ed.nodeChanged();
  902. lastRng = rng;
  903. }
  904. }, 50);
  905. });
  906. }
  907. function ensureBodyHasRoleApplication(ed) {
  908. document.body.setAttribute("role", "application");
  909. }
  910. tinymce.create('tinymce.util.Quirks', {
  911. Quirks: function(ed) {
  912. // WebKit
  913. if (tinymce.isWebKit) {
  914. cleanupStylesWhenDeleting(ed);
  915. emptyEditorWhenDeleting(ed);
  916. inputMethodFocus(ed);
  917. selectControlElements(ed);
  918. // iOS
  919. if (tinymce.isIDevice) {
  920. selectionChangeNodeChanged(ed);
  921. }
  922. }
  923. // IE
  924. if (tinymce.isIE) {
  925. removeHrOnBackspace(ed);
  926. emptyEditorWhenDeleting(ed);
  927. ensureBodyHasRoleApplication(ed);
  928. }
  929. // Gecko
  930. if (tinymce.isGecko) {
  931. removeHrOnBackspace(ed);
  932. focusBody(ed);
  933. }
  934. }
  935. });
  936. })(tinymce);
  937. (function(tinymce) {
  938. var namedEntities, baseEntities, reverseEntities,
  939. attrsCharsRegExp = /[&<>\"\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  940. textCharsRegExp = /[<>&\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  941. rawCharsRegExp = /[<>&\"\']/g,
  942. entityRegExp = /&(#x|#)?([\w]+);/g,
  943. asciiMap = {
  944. 128 : "\u20AC", 130 : "\u201A", 131 : "\u0192", 132 : "\u201E", 133 : "\u2026", 134 : "\u2020",
  945. 135 : "\u2021", 136 : "\u02C6", 137 : "\u2030", 138 : "\u0160", 139 : "\u2039", 140 : "\u0152",
  946. 142 : "\u017D", 145 : "\u2018", 146 : "\u2019", 147 : "\u201C", 148 : "\u201D", 149 : "\u2022",
  947. 150 : "\u2013", 151 : "\u2014", 152 : "\u02DC", 153 : "\u2122", 154 : "\u0161", 155 : "\u203A",
  948. 156 : "\u0153", 158 : "\u017E", 159 : "\u0178"
  949. };
  950. // Raw entities
  951. baseEntities = {
  952. '\"' : '&quot;', // Needs to be escaped since the YUI compressor would otherwise break the code
  953. "'" : '&#39;',
  954. '<' : '&lt;',
  955. '>' : '&gt;',
  956. '&' : '&amp;'
  957. };
  958. // Reverse lookup table for raw entities
  959. reverseEntities = {
  960. '&lt;' : '<',
  961. '&gt;' : '>',
  962. '&amp;' : '&',
  963. '&quot;' : '"',
  964. '&apos;' : "'"
  965. };
  966. // Decodes text by using the browser
  967. function nativeDecode(text) {
  968. var elm;
  969. elm = document.createElement("div");
  970. elm.innerHTML = text;
  971. return elm.textContent || elm.innerText || text;
  972. };
  973. // Build a two way lookup table for the entities
  974. function buildEntitiesLookup(items, radix) {
  975. var i, chr, entity, lookup = {};
  976. if (items) {
  977. items = items.split(',');
  978. radix = radix || 10;
  979. // Build entities lookup table
  980. for (i = 0; i < items.length; i += 2) {
  981. chr = String.fromCharCode(parseInt(items[i], radix));
  982. // Only add non base entities
  983. if (!baseEntities[chr]) {
  984. entity = '&' + items[i + 1] + ';';
  985. lookup[chr] = entity;
  986. lookup[entity] = chr;
  987. }
  988. }
  989. return lookup;
  990. }
  991. };
  992. // Unpack entities lookup where the numbers are in radix 32 to reduce the size
  993. namedEntities = buildEntitiesLookup(
  994. '50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,' +
  995. '5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,' +
  996. '5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,' +
  997. '5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,' +
  998. '68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,' +
  999. '6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,' +
  1000. '6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,' +
  1001. '75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,' +
  1002. '7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,' +
  1003. '7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,' +
  1004. 'sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,' +
  1005. 'st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,' +
  1006. 't9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,' +
  1007. 'tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,' +
  1008. 'u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,' +
  1009. '81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,' +
  1010. '8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,' +
  1011. '8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,' +
  1012. '8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,' +
  1013. '8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,' +
  1014. 'nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,' +
  1015. 'rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,' +
  1016. 'Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,' +
  1017. '80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,' +
  1018. '811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro'
  1019. , 32);
  1020. tinymce.html = tinymce.html || {};
  1021. tinymce.html.Entities = {
  1022. encodeRaw : function(text, attr) {
  1023. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1024. return baseEntities[chr] || chr;
  1025. });
  1026. },
  1027. encodeAllRaw : function(text) {
  1028. return ('' + text).replace(rawCharsRegExp, function(chr) {
  1029. return baseEntities[chr] || chr;
  1030. });
  1031. },
  1032. encodeNumeric : function(text, attr) {
  1033. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1034. // Multi byte sequence convert it to a single entity
  1035. if (chr.length > 1)
  1036. return '&#' + (((chr.charCodeAt(0) - 0xD800) * 0x400) + (chr.charCodeAt(1) - 0xDC00) + 0x10000) + ';';
  1037. return baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';';
  1038. });
  1039. },
  1040. encodeNamed : function(text, attr, entities) {
  1041. entities = entities || namedEntities;
  1042. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1043. return baseEntities[chr] || entities[chr] || chr;
  1044. });
  1045. },
  1046. getEncodeFunc : function(name, entities) {
  1047. var Entities = tinymce.html.Entities;
  1048. entities = buildEntitiesLookup(entities) || namedEntities;
  1049. function encodeNamedAndNumeric(text, attr) {
  1050. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1051. return baseEntities[chr] || entities[chr] || '&#' + chr.charCodeAt(0) + ';' || chr;
  1052. });
  1053. };
  1054. function encodeCustomNamed(text, attr) {
  1055. return Entities.encodeNamed(text, attr, entities);
  1056. };
  1057. // Replace + with , to be compatible with previous TinyMCE versions
  1058. name = tinymce.makeMap(name.replace(/\+/g, ','));
  1059. // Named and numeric encoder
  1060. if (name.named && name.numeric)
  1061. return encodeNamedAndNumeric;
  1062. // Named encoder
  1063. if (name.named) {
  1064. // Custom names
  1065. if (entities)
  1066. return encodeCustomNamed;
  1067. return Entities.encodeNamed;
  1068. }
  1069. // Numeric
  1070. if (name.numeric)
  1071. return Entities.encodeNumeric;
  1072. // Raw encoder
  1073. return Entities.encodeRaw;
  1074. },
  1075. decode : function(text) {
  1076. return text.replace(entityRegExp, function(all, numeric, value) {
  1077. if (numeric) {
  1078. value = parseInt(value, numeric.length === 2 ? 16 : 10);
  1079. // Support upper UTF
  1080. if (value > 0xFFFF) {
  1081. value -= 0x10000;
  1082. return String.fromCharCode(0xD800 + (value >> 10), 0xDC00 + (value & 0x3FF));
  1083. } else
  1084. return asciiMap[value] || String.fromCharCode(value);
  1085. }
  1086. return reverseEntities[all] || namedEntities[all] || nativeDecode(all);
  1087. });
  1088. }
  1089. };
  1090. })(tinymce);
  1091. tinymce.html.Styles = function(settings, schema) {
  1092. var rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi,
  1093. urlOrStrRegExp = /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi,
  1094. styleRegExp = /\s*([^:]+):\s*([^;]+);?/g,
  1095. trimRightRegExp = /\s+$/,
  1096. urlColorRegExp = /rgb/,
  1097. undef, i, encodingLookup = {}, encodingItems;
  1098. settings = settings || {};
  1099. encodingItems = '\\" \\\' \\; \\: ; : \uFEFF'.split(' ');
  1100. for (i = 0; i < encodingItems.length; i++) {
  1101. encodingLookup[encodingItems[i]] = '\uFEFF' + i;
  1102. encodingLookup['\uFEFF' + i] = encodingItems[i];
  1103. }
  1104. function toHex(match, r, g, b) {
  1105. function hex(val) {
  1106. val = parseInt(val).toString(16);
  1107. return val.length > 1 ? val : '0' + val; // 0 -> 00
  1108. };
  1109. return '#' + hex(r) + hex(g) + hex(b);
  1110. };
  1111. return {
  1112. toHex : function(color) {
  1113. return color.replace(rgbRegExp, toHex);
  1114. },
  1115. parse : function(css) {
  1116. var styles = {}, matches, name, value, isEncoded, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope || this;
  1117. function compress(prefix, suffix) {
  1118. var top, right, bottom, left;
  1119. // Get values and check it it needs compressing
  1120. top = styles[prefix + '-top' + suffix];
  1121. if (!top)
  1122. return;
  1123. right = styles[prefix + '-right' + suffix];
  1124. if (top != right)
  1125. return;
  1126. bottom = styles[prefix + '-bottom' + suffix];
  1127. if (right != bottom)
  1128. return;
  1129. left = styles[prefix + '-left' + suffix];
  1130. if (bottom != left)
  1131. return;
  1132. // Compress
  1133. styles[prefix + suffix] = left;
  1134. delete styles[prefix + '-top' + suffix];
  1135. delete styles[prefix + '-right' + suffix];
  1136. delete styles[prefix + '-bottom' + suffix];
  1137. delete styles[prefix + '-left' + suffix];
  1138. };
  1139. function canCompress(key) {
  1140. var value = styles[key], i;
  1141. if (!value || value.indexOf(' ') < 0)
  1142. return;
  1143. value = value.split(' ');
  1144. i = value.length;
  1145. while (i--) {
  1146. if (value[i] !== value[0])
  1147. return false;
  1148. }
  1149. styles[key] = value[0];
  1150. return true;
  1151. };
  1152. function compress2(target, a, b, c) {
  1153. if (!canCompress(a))
  1154. return;
  1155. if (!canCompress(b))
  1156. return;
  1157. if (!canCompress(c))
  1158. return;
  1159. // Compress
  1160. styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c];
  1161. delete styles[a];
  1162. delete styles[b];
  1163. delete styles[c];
  1164. };
  1165. // Encodes the specified string by replacing all \" \' ; : with _<num>
  1166. function encode(str) {
  1167. isEncoded = true;
  1168. return encodingLookup[str];
  1169. };
  1170. // Decodes the specified string by replacing all _<num> with it's original value \" \' etc
  1171. // It will also decode the \" \' if keep_slashes is set to fale or omitted
  1172. function decode(str, keep_slashes) {
  1173. if (isEncoded) {
  1174. str = str.replace(/\uFEFF[0-9]/g, function(str) {
  1175. return encodingLookup[str];
  1176. });
  1177. }
  1178. if (!keep_slashes)
  1179. str = str.replace(/\\([\'\";:])/g, "$1");
  1180. return str;
  1181. }
  1182. if (css) {
  1183. // Encode \" \' % and ; and : inside strings so they don't interfere with the style parsing
  1184. css = css.replace(/\\[\"\';:\uFEFF]/g, encode).replace(/\"[^\"]+\"|\'[^\']+\'/g, function(str) {
  1185. return str.replace(/[;:]/g, encode);
  1186. });
  1187. // Parse styles
  1188. while (matches = styleRegExp.exec(css)) {
  1189. name = matches[1].replace(trimRightRegExp, '').toLowerCase();
  1190. value = matches[2].replace(trimRightRegExp, '');
  1191. if (name && value.length > 0) {
  1192. // Opera will produce 700 instead of bold in their style values
  1193. if (name === 'font-weight' && value === '700')
  1194. value = 'bold';
  1195. else if (name === 'color' || name === 'background-color') // Lowercase colors like RED
  1196. value = value.toLowerCase();
  1197. // Convert RGB colors to HEX
  1198. value = value.replace(rgbRegExp, toHex);
  1199. // Convert URLs and force them into url('value') format
  1200. value = value.replace(urlOrStrRegExp, function(match, url, url2, url3, str, str2) {
  1201. str = str || str2;
  1202. if (str) {
  1203. str = decode(str);
  1204. // Force strings into single quote format
  1205. return "'" + str.replace(/\'/g, "\\'") + "'";
  1206. }
  1207. url = decode(url || url2 || url3);
  1208. // Convert the URL to relative/absolute depending on config
  1209. if (urlConverter)
  1210. url = urlConverter.call(urlConverterScope, url, 'style');
  1211. // Output new URL format
  1212. return "url('" + url.replace(/\'/g, "\\'") + "')";
  1213. });
  1214. styles[name] = isEncoded ? decode(value, true) : value;
  1215. }
  1216. styleRegExp.lastIndex = matches.index + matches[0].length;
  1217. }
  1218. // Compress the styles to reduce it's size for example IE will expand styles
  1219. compress("border", "");
  1220. compress("border", "-width");
  1221. compress("border", "-color");
  1222. compress("border", "-style");
  1223. compress("padding", "");
  1224. compress("margin", "");
  1225. compress2('border', 'border-width', 'border-style', 'border-color');
  1226. // Remove pointless border, IE produces these
  1227. if (styles.border === 'medium none')
  1228. delete styles.border;
  1229. }
  1230. return styles;
  1231. },
  1232. serialize : function(styles, element_name) {
  1233. var css = '', name, value;
  1234. function serializeStyles(name) {
  1235. var styleList, i, l, value;
  1236. styleList = schema.styles[name];
  1237. if (styleList) {
  1238. for (i = 0, l = styleList.length; i < l; i++) {
  1239. name = styleList[i];
  1240. value = styles[name];
  1241. if (value !== undef && value.length > 0)
  1242. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  1243. }
  1244. }
  1245. };
  1246. // Serialize styles according to schema
  1247. if (element_name && schema && schema.styles) {
  1248. // Serialize global styles and element specific styles
  1249. serializeStyles('*');
  1250. serializeStyles(element_name);
  1251. } else {
  1252. // Output the styles in the order they are inside the object
  1253. for (name in styles) {
  1254. value = styles[name];
  1255. if (value !== undef && value.length > 0)
  1256. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  1257. }
  1258. }
  1259. return css;
  1260. }
  1261. };
  1262. };
  1263. (function(tinymce) {
  1264. var transitional = {}, boolAttrMap, blockElementsMap, shortEndedElementsMap, nonEmptyElementsMap, customElementsMap = {},
  1265. defaultWhiteSpaceElementsMap, selfClosingElementsMap, makeMap = tinymce.makeMap, each = tinymce.each;
  1266. function split(str, delim) {
  1267. return str.split(delim || ',');
  1268. };
  1269. function unpack(lookup, data) {
  1270. var key, elements = {};
  1271. function replace(value) {
  1272. return value.replace(/[A-Z]+/g, function(key) {
  1273. return replace(lookup[key]);
  1274. });
  1275. };
  1276. // Unpack lookup
  1277. for (key in lookup) {
  1278. if (lookup.hasOwnProperty(key))
  1279. lookup[key] = replace(lookup[key]);
  1280. }
  1281. // Unpack and parse data into object map
  1282. replace(data).replace(/#/g, '#text').replace(/(\w+)\[([^\]]+)\]\[([^\]]*)\]/g, function(str, name, attributes, children) {
  1283. attributes = split(attributes, '|');
  1284. elements[name] = {
  1285. attributes : makeMap(attributes),
  1286. attributesOrder : attributes,
  1287. children : makeMap(children, '|', {'#comment' : {}})
  1288. }
  1289. });
  1290. return elements;
  1291. };
  1292. // Build a lookup table for block elements both lowercase and uppercase
  1293. blockElementsMap = 'h1,h2,h3,h4,h5,h6,hr,p,div,address,pre,form,table,tbody,thead,tfoot,' +
  1294. 'th,tr,td,li,ol,ul,caption,blockquote,center,dl,dt,dd,dir,fieldset,' +
  1295. 'noscript,menu,isindex,samp,header,footer,article,section,hgroup';
  1296. blockElementsMap = makeMap(blockElementsMap, ',', makeMap(blockElementsMap.toUpperCase()));
  1297. // This is the XHTML 1.0 transitional elements with it's attributes and children packed to reduce it's size
  1298. transitional = unpack({
  1299. Z : 'H|K|N|O|P',
  1300. Y : 'X|form|R|Q',
  1301. ZG : 'E|span|width|align|char|charoff|valign',
  1302. X : 'p|T|div|U|W|isindex|fieldset|table',
  1303. ZF : 'E|align|char|charoff|valign',
  1304. W : 'pre|hr|blockquote|address|center|noframes',
  1305. ZE : 'abbr|axis|headers|scope|rowspan|colspan|align|char|charoff|valign|nowrap|bgcolor|width|height',
  1306. ZD : '[E][S]',
  1307. U : 'ul|ol|dl|menu|dir',
  1308. ZC : 'p|Y|div|U|W|table|br|span|bdo|object|applet|img|map|K|N|Q',
  1309. T : 'h1|h2|h3|h4|h5|h6',
  1310. ZB : 'X|S|Q',
  1311. S : 'R|P',
  1312. ZA : 'a|G|J|M|O|P',
  1313. R : 'a|H|K|N|O',
  1314. Q : 'noscript|P',
  1315. P : 'ins|del|script',
  1316. O : 'input|select|textarea|label|button',
  1317. N : 'M|L',
  1318. M : 'em|strong|dfn|code|q|samp|kbd|var|cite|abbr|acronym',
  1319. L : 'sub|sup',
  1320. K : 'J|I',
  1321. J : 'tt|i|b|u|s|strike',
  1322. I : 'big|small|font|basefont',
  1323. H : 'G|F',
  1324. G : 'br|span|bdo',
  1325. F : 'object|applet|img|map|iframe',
  1326. E : 'A|B|C',
  1327. D : 'accesskey|tabindex|onfocus|onblur',
  1328. C : 'onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup',
  1329. B : 'lang|xml:lang|dir',
  1330. A : 'id|class|style|title'
  1331. }, 'script[id|charset|type|language|src|defer|xml:space][]' +
  1332. 'style[B|id|type|media|title|xml:space][]' +
  1333. 'object[E|declare|classid|codebase|data|type|codetype|archive|standby|width|height|usemap|name|tabindex|align|border|hspace|vspace][#|param|Y]' +
  1334. 'param[id|name|value|valuetype|type][]' +
  1335. 'p[E|align][#|S]' +
  1336. 'a[E|D|charset|type|name|href|hreflang|rel|rev|shape|coords|target][#|Z]' +
  1337. 'br[A|clear][]' +
  1338. 'span[E][#|S]' +
  1339. 'bdo[A|C|B][#|S]' +
  1340. 'applet[A|codebase|archive|code|object|alt|name|width|height|align|hspace|vspace][#|param|Y]' +
  1341. 'h1[E|align][#|S]' +
  1342. 'img[E|src|alt|name|longdesc|width|height|usemap|ismap|align|border|hspace|vspace][]' +
  1343. 'map[B|C|A|name][X|form|Q|area]' +
  1344. 'h2[E|align][#|S]' +
  1345. 'iframe[A|longdesc|name|src|frameborder|marginwidth|marginheight|scrolling|align|width|height][#|Y]' +
  1346. 'h3[E|align][#|S]' +
  1347. 'tt[E][#|S]' +
  1348. 'i[E][#|S]' +
  1349. 'b[E][#|S]' +
  1350. 'u[E][#|S]' +
  1351. 's[E][#|S]' +
  1352. 'strike[E][#|S]' +
  1353. 'big[E][#|S]' +
  1354. 'small[E][#|S]' +
  1355. 'font[A|B|size|color|face][#|S]' +
  1356. 'basefont[id|size|color|face][]' +
  1357. 'em[E][#|S]' +
  1358. 'strong[E][#|S]' +
  1359. 'dfn[E][#|S]' +
  1360. 'code[E][#|S]' +
  1361. 'q[E|cite][#|S]' +
  1362. 'samp[E][#|S]' +
  1363. 'kbd[E][#|S]' +
  1364. 'var[E][#|S]' +
  1365. 'cite[E][#|S]' +
  1366. 'abbr[E][#|S]' +
  1367. 'acronym[E][#|S]' +
  1368. 'sub[E][#|S]' +
  1369. 'sup[E][#|S]' +
  1370. 'input[E|D|type|name|value|checked|disabled|readonly|size|maxlength|src|alt|usemap|onselect|onchange|accept|align][]' +
  1371. 'select[E|name|size|multiple|disabled|tabindex|onfocus|onblur|onchange][optgroup|option]' +
  1372. 'optgroup[E|disabled|label][option]' +
  1373. 'option[E|selected|disabled|label|value][]' +
  1374. 'textarea[E|D|name|rows|cols|disabled|readonly|onselect|onchange][]' +
  1375. 'label[E|for|accesskey|onfocus|onblur][#|S]' +
  1376. 'button[E|D|name|value|type|disabled][#|p|T|div|U|W|table|G|object|applet|img|map|K|N|Q]' +
  1377. 'h4[E|align][#|S]' +
  1378. 'ins[E|cite|datetime][#|Y]' +
  1379. 'h5[E|align][#|S]' +
  1380. 'del[E|cite|datetime][#|Y]' +
  1381. 'h6[E|align][#|S]' +
  1382. 'div[E|align][#|Y]' +
  1383. 'ul[E|type|compact][li]' +
  1384. 'li[E|type|value][#|Y]' +
  1385. 'ol[E|type|compact|start][li]' +
  1386. 'dl[E|compact][dt|dd]' +
  1387. 'dt[E][#|S]' +
  1388. 'dd[E][#|Y]' +
  1389. 'menu[E|compact][li]' +
  1390. 'dir[E|compact][li]' +
  1391. 'pre[E|width|xml:space][#|ZA]' +
  1392. 'hr[E|align|noshade|size|width][]' +
  1393. 'blockquote[E|cite][#|Y]' +
  1394. 'address[E][#|S|p]' +
  1395. 'center[E][#|Y]' +
  1396. 'noframes[E][#|Y]' +
  1397. 'isindex[A|B|prompt][]' +
  1398. 'fieldset[E][#|legend|Y]' +
  1399. 'legend[E|accesskey|align][#|S]' +
  1400. 'table[E|summary|width|border|frame|rules|cellspacing|cellpadding|align|bgcolor][caption|col|colgroup|thead|tfoot|tbody|tr]' +
  1401. 'caption[E|align][#|S]' +
  1402. 'col[ZG][]' +
  1403. 'colgroup[ZG][col]' +
  1404. 'thead[ZF][tr]' +
  1405. 'tr[ZF|bgcolor][th|td]' +
  1406. 'th[E|ZE][#|Y]' +
  1407. 'form[E|action|method|name|enctype|onsubmit|onreset|accept|accept-charset|target][#|X|R|Q]' +
  1408. 'noscript[E][#|Y]' +
  1409. 'td[E|ZE][#|Y]' +
  1410. 'tfoot[ZF][tr]' +
  1411. 'tbody[ZF][tr]' +
  1412. 'area[E|D|shape|coords|href|nohref|alt|target][]' +
  1413. 'base[id|href|target][]' +
  1414. 'body[E|onload|onunload|background|bgcolor|text|link|vlink|alink][#|Y]'
  1415. );
  1416. boolAttrMap = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected,autoplay,loop,controls');
  1417. shortEndedElementsMap = makeMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed,source');
  1418. nonEmptyElementsMap = tinymce.extend(makeMap('td,th,iframe,video,audio,object'), shortEndedElementsMap);
  1419. defaultWhiteSpaceElementsMap = makeMap('pre,script,style,textarea');
  1420. selfClosingElementsMap = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr');
  1421. tinymce.html.Schema = function(settings) {
  1422. var self = this, elements = {}, children = {}, patternElements = [], validStyles, whiteSpaceElementsMap;
  1423. settings = settings || {};
  1424. // Allow all elements and attributes if verify_html is set to false
  1425. if (settings.verify_html === false)
  1426. settings.valid_elements = '*[*]';
  1427. // Build styles list
  1428. if (settings.valid_styles) {
  1429. validStyles = {};
  1430. // Convert styles into a rule list
  1431. each(settings.valid_styles, function(value, key) {
  1432. validStyles[key] = tinymce.explode(value);
  1433. });
  1434. }
  1435. whiteSpaceElementsMap = settings.whitespace_elements ? makeMap(settings.whitespace_elements) : defaultWhiteSpaceElementsMap;
  1436. // Converts a wildcard expression string to a regexp for example *a will become /.*a/.
  1437. function patternToRegExp(str) {
  1438. return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$');
  1439. };
  1440. // Parses the specified valid_elements string and adds to the current rules
  1441. // This function is a bit hard to read since it's heavily optimized for speed
  1442. function addValidElements(valid_elements) {
  1443. var ei, el, ai, al, yl, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder,
  1444. prefix, outputName, globalAttributes, globalAttributesOrder, transElement, key, childKey, value,
  1445. elementRuleRegExp = /^([#+-])?([^\[\/]+)(?:\/([^\[]+))?(?:\[([^\]]+)\])?$/,
  1446. attrRuleRegExp = /^([!\-])?(\w+::\w+|[^=:<]+)?(?:([=:<])(.*))?$/,
  1447. hasPatternsRegExp = /[*?+]/;
  1448. if (valid_elements) {
  1449. // Split valid elements into an array with rules
  1450. valid_elements = split(valid_elements);
  1451. if (elements['@']) {
  1452. globalAttributes = elements['@'].attributes;
  1453. globalAttributesOrder = elements['@'].attributesOrder;
  1454. }
  1455. // Loop all rules
  1456. for (ei = 0, el = valid_elements.length; ei < el; ei++) {
  1457. // Parse element rule
  1458. matches = elementRuleRegExp.exec(valid_elements[ei]);
  1459. if (matches) {
  1460. // Setup local names for matches
  1461. prefix = matches[1];
  1462. elementName = matches[2];
  1463. outputName = matches[3];
  1464. attrData = matches[4];
  1465. // Create new attributes and attributesOrder
  1466. attributes = {};
  1467. attributesOrder = [];
  1468. // Create the new element
  1469. element = {
  1470. attributes : attributes,
  1471. attributesOrder : attributesOrder
  1472. };
  1473. // Padd empty elements prefix
  1474. if (prefix === '#')
  1475. element.paddEmpty = true;
  1476. // Remove empty elements prefix
  1477. if (prefix === '-')
  1478. element.removeEmpty = true;
  1479. // Copy attributes from global rule into current rule
  1480. if (globalAttributes) {
  1481. for (key in globalAttributes)
  1482. attributes[key] = globalAttributes[key];
  1483. attributesOrder.push.apply(attributesOrder, globalAttributesOrder);
  1484. }
  1485. // Attributes defined
  1486. if (attrData) {
  1487. attrData = split(attrData, '|');
  1488. for (ai = 0, al = attrData.length; ai < al; ai++) {
  1489. matches = attrRuleRegExp.exec(attrData[ai]);
  1490. if (matches) {
  1491. attr = {};
  1492. attrType = matches[1];
  1493. attrName = matches[2].replace(/::/g, ':');
  1494. prefix = matches[3];
  1495. value = matches[4];
  1496. // Required
  1497. if (attrType === '!') {
  1498. element.attributesRequired = element.attributesRequired || [];
  1499. element.attributesRequired.push(attrName);
  1500. attr.required = true;
  1501. }
  1502. // Denied from global
  1503. if (attrType === '-') {
  1504. delete attributes[attrName];
  1505. attributesOrder.splice(tinymce.inArray(attributesOrder, attrName), 1);
  1506. continue;
  1507. }
  1508. // Default value
  1509. if (prefix) {
  1510. // Default value
  1511. if (prefix === '=') {
  1512. element.attributesDefault = element.attributesDefault || [];
  1513. element.attributesDefault.push({name: attrName, value: value});
  1514. attr.defaultValue = value;
  1515. }
  1516. // Forced value
  1517. if (prefix === ':') {
  1518. element.attributesForced = element.attributesForced || [];
  1519. element.attributesForced.push({name: attrName, value: value});
  1520. attr.forcedValue = value;
  1521. }
  1522. // Required values
  1523. if (prefix === '<')
  1524. attr.validValues = makeMap(value, '?');
  1525. }
  1526. // Check for attribute patterns
  1527. if (hasPatternsRegExp.test(attrName)) {
  1528. element.attributePatterns = element.attributePatterns || [];
  1529. attr.pattern = patternToRegExp(attrName);
  1530. element.attributePatterns.push(attr);
  1531. } else {
  1532. // Add attribute to order list if it doesn't already exist
  1533. if (!attributes[attrName])
  1534. attributesOrder.push(attrName);
  1535. attributes[attrName] = attr;
  1536. }
  1537. }
  1538. }
  1539. }
  1540. // Global rule, store away these for later usage
  1541. if (!globalAttributes && elementName == '@') {
  1542. globalAttributes = attributes;
  1543. globalAttributesOrder = attributesOrder;
  1544. }
  1545. // Handle substitute elements such as b/strong
  1546. if (outputName) {
  1547. element.outputName = elementName;
  1548. elements[outputName] = element;
  1549. }
  1550. // Add pattern or exact element
  1551. if (hasPatternsRegExp.test(elementName)) {
  1552. element.pattern = patternToRegExp(elementName);
  1553. patternElements.push(element);
  1554. } else
  1555. elements[elementName] = element;
  1556. }
  1557. }
  1558. }
  1559. };
  1560. function setValidElements(valid_elements) {
  1561. elements = {};
  1562. patternElements = [];
  1563. addValidElements(valid_elements);
  1564. each(transitional, function(element, name) {
  1565. children[name] = element.children;
  1566. });
  1567. };
  1568. // Adds custom non HTML elements to the schema
  1569. function addCustomElements(custom_elements) {
  1570. var customElementRegExp = /^(~)?(.+)$/;
  1571. if (custom_elements) {
  1572. each(split(custom_elements), function(rule) {
  1573. var matches = customElementRegExp.exec(rule),
  1574. inline = matches[1] === '~',
  1575. cloneName = inline ? 'span' : 'div',
  1576. name = matches[2];
  1577. children[name] = children[cloneName];
  1578. customElementsMap[name] = cloneName;
  1579. // If it's not marked as inline then add it to valid block elements
  1580. if (!inline)
  1581. blockElementsMap[name] = {};
  1582. // Add custom elements at span/div positions
  1583. each(children, function(element, child) {
  1584. if (element[cloneName])
  1585. element[name] = element[cloneName];
  1586. });
  1587. });
  1588. }
  1589. };
  1590. // Adds valid children to the schema object
  1591. function addValidChildren(valid_children) {
  1592. var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/;
  1593. if (valid_children) {
  1594. each(split(valid_children), function(rule) {
  1595. var matches = childRuleRegExp.exec(rule), parent, prefix;
  1596. if (matches) {
  1597. prefix = matches[1];
  1598. // Add/remove items from default
  1599. if (prefix)
  1600. parent = children[matches[2]];
  1601. else
  1602. parent = children[matches[2]] = {'#comment' : {}};
  1603. parent = children[matches[2]];
  1604. each(split(matches[3], '|'), function(child) {
  1605. if (prefix === '-')
  1606. delete parent[child];
  1607. else
  1608. parent[child] = {};
  1609. });
  1610. }
  1611. });
  1612. }
  1613. };
  1614. function getElementRule(name) {
  1615. var element = elements[name], i;
  1616. // Exact match found
  1617. if (element)
  1618. return element;
  1619. // No exact match then try the patterns
  1620. i = patternElements.length;
  1621. while (i--) {
  1622. element = patternElements[i];
  1623. if (element.pattern.test(name))
  1624. return element;
  1625. }
  1626. };
  1627. if (!settings.valid_elements) {
  1628. // No valid elements defined then clone the elements from the transitional spec
  1629. each(transitional, function(element, name) {
  1630. elements[name] = {
  1631. attributes : element.attributes,
  1632. attributesOrder : element.attributesOrder
  1633. };
  1634. children[name] = element.children;
  1635. });
  1636. // Switch these
  1637. each(split('strong/b,em/i'), function(item) {
  1638. item = split(item, '/');
  1639. elements[item[1]].outputName = item[0];
  1640. });
  1641. // Add default alt attribute for images
  1642. elements.img.attributesDefault = [{name: 'alt', value: ''}];
  1643. // Remove these if they are empty by default
  1644. each(split('ol,ul,sub,sup,blockquote,span,font,a,table,tbody,tr'), function(name) {
  1645. elements[name].removeEmpty = true;
  1646. });
  1647. // Padd these by default
  1648. each(split('p,h1,h2,h3,h4,h5,h6,th,td,pre,div,address,caption'), function(name) {
  1649. elements[name].paddEmpty = true;
  1650. });
  1651. } else
  1652. setValidElements(settings.valid_elements);
  1653. addCustomElements(settings.custom_elements);
  1654. addValidChildren(settings.valid_children);
  1655. addValidElements(settings.extended_valid_elements);
  1656. // Todo: Remove this when we fix list handling to be valid
  1657. addValidChildren('+ol[ul|ol],+ul[ul|ol]');
  1658. // If the user didn't allow span only allow internal spans
  1659. if (!getElementRule('span'))
  1660. addValidElements('span[!data-mce-type|*]');
  1661. // Delete invalid elements
  1662. if (settings.invalid_elements) {
  1663. tinymce.each(tinymce.explode(settings.invalid_elements), function(item) {
  1664. if (elements[item])
  1665. delete elements[item];
  1666. });
  1667. }
  1668. self.children = children;
  1669. self.styles = validStyles;
  1670. self.getBoolAttrs = function() {
  1671. return boolAttrMap;
  1672. };
  1673. self.getBlockElements = function() {
  1674. return blockElementsMap;
  1675. };
  1676. self.getShortEndedElements = function() {
  1677. return shortEndedElementsMap;
  1678. };
  1679. self.getSelfClosingElements = function() {
  1680. return selfClosingElementsMap;
  1681. };
  1682. self.getNonEmptyElements = function() {
  1683. return nonEmptyElementsMap;
  1684. };
  1685. self.getWhiteSpaceElements = function() {
  1686. return whiteSpaceElementsMap;
  1687. };
  1688. self.isValidChild = function(name, child) {
  1689. var parent = children[name];
  1690. return !!(parent && parent[child]);
  1691. };
  1692. self.getElementRule = getElementRule;
  1693. self.getCustomElements = function() {
  1694. return customElementsMap;
  1695. };
  1696. self.addValidElements = addValidElements;
  1697. self.setValidElements = setValidElements;
  1698. self.addCustomElements = addCustomElements;
  1699. self.addValidChildren = addValidChildren;
  1700. };
  1701. // Expose boolMap and blockElementMap as static properties for usage in DOMUtils
  1702. tinymce.html.Schema.boolAttrMap = boolAttrMap;
  1703. tinymce.html.Schema.blockElementsMap = blockElementsMap;
  1704. })(tinymce);
  1705. (function(tinymce) {
  1706. tinymce.html.SaxParser = function(settings, schema) {
  1707. var self = this, noop = function() {};
  1708. settings = settings || {};
  1709. self.schema = schema = schema || new tinymce.html.Schema();
  1710. if (settings.fix_self_closing !== false)
  1711. settings.fix_self_closing = true;
  1712. // Add handler functions from settings and setup default handlers
  1713. tinymce.each('comment cdata text start end pi doctype'.split(' '), function(name) {
  1714. if (name)
  1715. self[name] = settings[name] || noop;
  1716. });
  1717. self.parse = function(html) {
  1718. var self = this, matches, index = 0, value, endRegExp, stack = [], attrList, i, text, name, isInternalElement, removeInternalElements,
  1719. shortEndedElements, fillAttrsMap, isShortEnded, validate, elementRule, isValidElement, attr, attribsValue, invalidPrefixRegExp,
  1720. validAttributesMap, validAttributePatterns, attributesRequired, attributesDefault, attributesForced, selfClosing,
  1721. tokenRegExp, attrRegExp, specialElements, attrValue, idCount = 0, decode = tinymce.html.Entities.decode, fixSelfClosing, isIE;
  1722. function processEndTag(name) {
  1723. var pos, i;
  1724. // Find position of parent of the same type
  1725. pos = stack.length;
  1726. while (pos--) {
  1727. if (stack[pos].name === name)
  1728. break;
  1729. }
  1730. // Found parent
  1731. if (pos >= 0) {
  1732. // Close all the open elements
  1733. for (i = stack.length - 1; i >= pos; i--) {
  1734. name = stack[i];
  1735. if (name.valid)
  1736. self.end(name.name);
  1737. }
  1738. // Remove the open elements from the stack
  1739. stack.length = pos;
  1740. }
  1741. };
  1742. // Precompile RegExps and map objects
  1743. tokenRegExp = new RegExp('<(?:' +
  1744. '(?:!--([\\w\\W]*?)-->)|' + // Comment
  1745. '(?:!\\[CDATA\\[([\\w\\W]*?)\\]\\]>)|' + // CDATA
  1746. '(?:!DOCTYPE([\\w\\W]*?)>)|' + // DOCTYPE
  1747. '(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|' + // PI
  1748. '(?:\\/([^>]+)>)|' + // End element
  1749. '(?:([^\\s\\/<>]+)((?:\\s+[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*|\\/)>)' + // Start element
  1750. ')', 'g');
  1751. attrRegExp = /([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:\\.|[^\"])*)\")|(?:\'((?:\\.|[^\'])*)\')|([^>\s]+)))?/g;
  1752. specialElements = {
  1753. 'script' : /<\/script[^>]*>/gi,
  1754. 'style' : /<\/style[^>]*>/gi,
  1755. 'noscript' : /<\/noscript[^>]*>/gi
  1756. };
  1757. // Setup lookup tables for empty elements and boolean attributes
  1758. shortEndedElements = schema.getShortEndedElements();
  1759. selfClosing = schema.getSelfClosingElements();
  1760. fillAttrsMap = schema.getBoolAttrs();
  1761. validate = settings.validate;
  1762. removeInternalElements = settings.remove_internals;
  1763. fixSelfClosing = settings.fix_self_closing;
  1764. isIE = tinymce.isIE;
  1765. invalidPrefixRegExp = /^:/;
  1766. while (matches = tokenRegExp.exec(html)) {
  1767. // Text
  1768. if (index < matches.index)
  1769. self.text(decode(html.substr(index, matches.index - index)));
  1770. if (value = matches[6]) { // End element
  1771. value = value.toLowerCase();
  1772. // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
  1773. if (isIE && invalidPrefixRegExp.test(value))
  1774. value = value.substr(1);
  1775. processEndTag(value);
  1776. } else if (value = matches[7]) { // Start element
  1777. value = value.toLowerCase();
  1778. // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
  1779. if (isIE && invalidPrefixRegExp.test(value))
  1780. value = value.substr(1);
  1781. isShortEnded = value in shortEndedElements;
  1782. // Is self closing tag for example an <li> after an open <li>
  1783. if (fixSelfClosing && selfClosing[value] && stack.length > 0 && stack[stack.length - 1].name === value)
  1784. processEndTag(value);
  1785. // Validate element
  1786. if (!validate || (elementRule = schema.getElementRule(value))) {
  1787. isValidElement = true;
  1788. // Grab attributes map and patters when validation is enabled
  1789. if (validate) {
  1790. validAttributesMap = elementRule.attributes;
  1791. validAttributePatterns = elementRule.attributePatterns;
  1792. }
  1793. // Parse attributes
  1794. if (attribsValue = matches[8]) {
  1795. isInternalElement = attribsValue.indexOf('data-mce-type') !== -1; // Check if the element is an internal element
  1796. // If the element has internal attributes then remove it if we are told to do so
  1797. if (isInternalElement && removeInternalElements)
  1798. isValidElement = false;
  1799. attrList = [];
  1800. attrList.map = {};
  1801. attribsValue.replace(attrRegExp, function(match, name, value, val2, val3) {
  1802. var attrRule, i;
  1803. name = name.toLowerCase();
  1804. value = name in fillAttrsMap ? name : decode(value || val2 || val3 || ''); // Handle boolean attribute than value attribute
  1805. // Validate name and value
  1806. if (validate && !isInternalElement && name.indexOf('data-') !== 0) {
  1807. attrRule = validAttributesMap[name];
  1808. // Find rule by pattern matching
  1809. if (!attrRule && validAttributePatterns) {
  1810. i = validAttributePatterns.length;
  1811. while (i--) {
  1812. attrRule = validAttributePatterns[i];
  1813. if (attrRule.pattern.test(name))
  1814. break;
  1815. }
  1816. // No rule matched
  1817. if (i === -1)
  1818. attrRule = null;
  1819. }
  1820. // No attribute rule found
  1821. if (!attrRule)
  1822. return;
  1823. // Validate value
  1824. if (attrRule.validValues && !(value in attrRule.validValues))
  1825. return;
  1826. }
  1827. // Add attribute to list and map
  1828. attrList.map[name] = value;
  1829. attrList.push({
  1830. name: name,
  1831. value: value
  1832. });
  1833. });
  1834. } else {
  1835. attrList = [];
  1836. attrList.map = {};
  1837. }
  1838. // Process attributes if validation is enabled
  1839. if (validate && !isInternalElement) {
  1840. attributesRequired = elementRule.attributesRequired;
  1841. attributesDefault = elementRule.attributesDefault;
  1842. attributesForced = elementRule.attributesForced;
  1843. // Handle forced attributes
  1844. if (attributesForced) {
  1845. i = attributesForced.length;
  1846. while (i--) {
  1847. attr = attributesForced[i];
  1848. name = attr.name;
  1849. attrValue = attr.value;
  1850. if (attrValue === '{$uid}')
  1851. attrValue = 'mce_' + idCount++;
  1852. attrList.map[name] = attrValue;
  1853. attrList.push({name: name, value: attrValue});
  1854. }
  1855. }
  1856. // Handle default attributes
  1857. if (attributesDefault) {
  1858. i = attributesDefault.length;
  1859. while (i--) {
  1860. attr = attributesDefault[i];
  1861. name = attr.name;
  1862. if (!(name in attrList.map)) {
  1863. attrValue = attr.value;
  1864. if (attrValue === '{$uid}')
  1865. attrValue = 'mce_' + idCount++;
  1866. attrList.map[name] = attrValue;
  1867. attrList.push({name: name, value: attrValue});
  1868. }
  1869. }
  1870. }
  1871. // Handle required attributes
  1872. if (attributesRequired) {
  1873. i = attributesRequired.length;
  1874. while (i--) {
  1875. if (attributesRequired[i] in attrList.map)
  1876. break;
  1877. }
  1878. // None of the required attributes where found
  1879. if (i === -1)
  1880. isValidElement = false;
  1881. }
  1882. // Invalidate element if it's marked as bogus
  1883. if (attrList.map['data-mce-bogus'])
  1884. isValidElement = false;
  1885. }
  1886. if (isValidElement)
  1887. self.start(value, attrList, isShortEnded);
  1888. } else
  1889. isValidElement = false;
  1890. // Treat script, noscript and style a bit different since they may include code that looks like elements
  1891. if (endRegExp = specialElements[value]) {
  1892. endRegExp.lastIndex = index = matches.index + matches[0].length;
  1893. if (matches = endRegExp.exec(html)) {
  1894. if (isValidElement)
  1895. text = html.substr(index, matches.index - index);
  1896. index = matches.index + matches[0].length;
  1897. } else {
  1898. text = html.substr(index);
  1899. index = html.length;
  1900. }
  1901. if (isValidElement && text.length > 0)
  1902. self.text(text, true);
  1903. if (isValidElement)
  1904. self.end(value);
  1905. tokenRegExp.lastIndex = index;
  1906. continue;
  1907. }
  1908. // Push value on to stack
  1909. if (!isShortEnded) {
  1910. if (!attribsValue || attribsValue.indexOf('/') != attribsValue.length - 1)
  1911. stack.push({name: value, valid: isValidElement});
  1912. else if (isValidElement)
  1913. self.end(value);
  1914. }
  1915. } else if (value = matches[1]) { // Comment
  1916. self.comment(value);
  1917. } else if (value = matches[2]) { // CDATA
  1918. self.cdata(value);
  1919. } else if (value = matches[3]) { // DOCTYPE
  1920. self.doctype(value);
  1921. } else if (value = matches[4]) { // PI
  1922. self.pi(value, matches[5]);
  1923. }
  1924. index = matches.index + matches[0].length;
  1925. }
  1926. // Text
  1927. if (index < html.length)
  1928. self.text(decode(html.substr(index)));
  1929. // Close any open elements
  1930. for (i = stack.length - 1; i >= 0; i--) {
  1931. value = stack[i];
  1932. if (value.valid)
  1933. self.end(value.name);
  1934. }
  1935. };
  1936. }
  1937. })(tinymce);
  1938. (function(tinymce) {
  1939. var whiteSpaceRegExp = /^[ \t\r\n]*$/, typeLookup = {
  1940. '#text' : 3,
  1941. '#comment' : 8,
  1942. '#cdata' : 4,
  1943. '#pi' : 7,
  1944. '#doctype' : 10,
  1945. '#document-fragment' : 11
  1946. };
  1947. // Walks the tree left/right
  1948. function walk(node, root_node, prev) {
  1949. var sibling, parent, startName = prev ? 'lastChild' : 'firstChild', siblingName = prev ? 'prev' : 'next';
  1950. // Walk into nodes if it has a start
  1951. if (node[startName])
  1952. return node[startName];
  1953. // Return the sibling if it has one
  1954. if (node !== root_node) {
  1955. sibling = node[siblingName];
  1956. if (sibling)
  1957. return sibling;
  1958. // Walk up the parents to look for siblings
  1959. for (parent = node.parent; parent && parent !== root_node; parent = parent.parent) {
  1960. sibling = parent[siblingName];
  1961. if (sibling)
  1962. return sibling;
  1963. }
  1964. }
  1965. };
  1966. function Node(name, type) {
  1967. this.name = name;
  1968. this.type = type;
  1969. if (type === 1) {
  1970. this.attributes = [];
  1971. this.attributes.map = {};
  1972. }
  1973. }
  1974. tinymce.extend(Node.prototype, {
  1975. replace : function(node) {
  1976. var self = this;
  1977. if (node.parent)
  1978. node.remove();
  1979. self.insert(node, self);
  1980. self.remove();
  1981. return self;
  1982. },
  1983. attr : function(name, value) {
  1984. var self = this, attrs, i, undef;
  1985. if (typeof name !== "string") {
  1986. for (i in name)
  1987. self.attr(i, name[i]);
  1988. return self;
  1989. }
  1990. if (attrs = self.attributes) {
  1991. if (value !== undef) {
  1992. // Remove attribute
  1993. if (value === null) {
  1994. if (name in attrs.map) {
  1995. delete attrs.map[name];
  1996. i = attrs.length;
  1997. while (i--) {
  1998. if (attrs[i].name === name) {
  1999. attrs = attrs.splice(i, 1);
  2000. return self;
  2001. }
  2002. }
  2003. }
  2004. return self;
  2005. }
  2006. // Set attribute
  2007. if (name in attrs.map) {
  2008. // Set attribute
  2009. i = attrs.length;
  2010. while (i--) {
  2011. if (attrs[i].name === name) {
  2012. attrs[i].value = value;
  2013. break;
  2014. }
  2015. }
  2016. } else
  2017. attrs.push({name: name, value: value});
  2018. attrs.map[name] = value;
  2019. return self;
  2020. } else {
  2021. return attrs.map[name];
  2022. }
  2023. }
  2024. },
  2025. clone : function() {
  2026. var self = this, clone = new Node(self.name, self.type), i, l, selfAttrs, selfAttr, cloneAttrs;
  2027. // Clone element attributes
  2028. if (selfAttrs = self.attributes) {
  2029. cloneAttrs = [];
  2030. cloneAttrs.map = {};
  2031. for (i = 0, l = selfAttrs.length; i < l; i++) {
  2032. selfAttr = selfAttrs[i];
  2033. // Clone everything except id
  2034. if (selfAttr.name !== 'id') {
  2035. cloneAttrs[cloneAttrs.length] = {name: selfAttr.name, value: selfAttr.value};
  2036. cloneAttrs.map[selfAttr.name] = selfAttr.value;
  2037. }
  2038. }
  2039. clone.attributes = cloneAttrs;
  2040. }
  2041. clone.value = self.value;
  2042. clone.shortEnded = self.shortEnded;
  2043. return clone;
  2044. },
  2045. wrap : function(wrapper) {
  2046. var self = this;
  2047. self.parent.insert(wrapper, self);
  2048. wrapper.append(self);
  2049. return self;
  2050. },
  2051. unwrap : function() {
  2052. var self = this, node, next;
  2053. for (node = self.firstChild; node; ) {
  2054. next = node.next;
  2055. self.insert(node, self, true);
  2056. node = next;
  2057. }
  2058. self.remove();
  2059. },
  2060. remove : function() {
  2061. var self = this, parent = self.parent, next = self.next, prev = self.prev;
  2062. if (parent) {
  2063. if (parent.firstChild === self) {
  2064. parent.firstChild = next;
  2065. if (next)
  2066. next.prev = null;
  2067. } else {
  2068. prev.next = next;
  2069. }
  2070. if (parent.lastChild === self) {
  2071. parent.lastChild = prev;
  2072. if (prev)
  2073. prev.next = null;
  2074. } else {
  2075. next.prev = prev;
  2076. }
  2077. self.parent = self.next = self.prev = null;
  2078. }
  2079. return self;
  2080. },
  2081. append : function(node) {
  2082. var self = this, last;
  2083. if (node.parent)
  2084. node.remove();
  2085. last = self.lastChild;
  2086. if (last) {
  2087. last.next = node;
  2088. node.prev = last;
  2089. self.lastChild = node;
  2090. } else
  2091. self.lastChild = self.firstChild = node;
  2092. node.parent = self;
  2093. return node;
  2094. },
  2095. insert : function(node, ref_node, before) {
  2096. var parent;
  2097. if (node.parent)
  2098. node.remove();
  2099. parent = ref_node.parent || this;
  2100. if (before) {
  2101. if (ref_node === parent.firstChild)
  2102. parent.firstChild = node;
  2103. else
  2104. ref_node.prev.next = node;
  2105. node.prev = ref_node.prev;
  2106. node.next = ref_node;
  2107. ref_node.prev = node;
  2108. } else {
  2109. if (ref_node === parent.lastChild)
  2110. parent.lastChild = node;
  2111. else
  2112. ref_node.next.prev = node;
  2113. node.next = ref_node.next;
  2114. node.prev = ref_node;
  2115. ref_node.next = node;
  2116. }
  2117. node.parent = parent;
  2118. return node;
  2119. },
  2120. getAll : function(name) {
  2121. var self = this, node, collection = [];
  2122. for (node = self.firstChild; node; node = walk(node, self)) {
  2123. if (node.name === name)
  2124. collection.push(node);
  2125. }
  2126. return collection;
  2127. },
  2128. empty : function() {
  2129. var self = this, nodes, i, node;
  2130. // Remove all children
  2131. if (self.firstChild) {
  2132. nodes = [];
  2133. // Collect the children
  2134. for (node = self.firstChild; node; node = walk(node, self))
  2135. nodes.push(node);
  2136. // Remove the children
  2137. i = nodes.length;
  2138. while (i--) {
  2139. node = nodes[i];
  2140. node.parent = node.firstChild = node.lastChild = node.next = node.prev = null;
  2141. }
  2142. }
  2143. self.firstChild = self.lastChild = null;
  2144. return self;
  2145. },
  2146. isEmpty : function(elements) {
  2147. var self = this, node = self.firstChild, i, name;
  2148. if (node) {
  2149. do {
  2150. if (node.type === 1) {
  2151. // Ignore bogus elements
  2152. if (node.attributes.map['data-mce-bogus'])
  2153. continue;
  2154. // Keep empty elements like <img />
  2155. if (elements[node.name])
  2156. return false;
  2157. // Keep elements with data attributes or name attribute like <a name="1"></a>
  2158. i = node.attributes.length;
  2159. while (i--) {
  2160. name = node.attributes[i].name;
  2161. if (name === "name" || name.indexOf('data-') === 0)
  2162. return false;
  2163. }
  2164. }
  2165. // Keep non whitespace text nodes
  2166. if ((node.type === 3 && !whiteSpaceRegExp.test(node.value)))
  2167. return false;
  2168. } while (node = walk(node, self));
  2169. }
  2170. return true;
  2171. },
  2172. walk : function(prev) {
  2173. return walk(this, null, prev);
  2174. }
  2175. });
  2176. tinymce.extend(Node, {
  2177. create : function(name, attrs) {
  2178. var node, attrName;
  2179. // Create node
  2180. node = new Node(name, typeLookup[name] || 1);
  2181. // Add attributes if needed
  2182. if (attrs) {
  2183. for (attrName in attrs)
  2184. node.attr(attrName, attrs[attrName]);
  2185. }
  2186. return node;
  2187. }
  2188. });
  2189. tinymce.html.Node = Node;
  2190. })(tinymce);
  2191. (function(tinymce) {
  2192. var Node = tinymce.html.Node;
  2193. tinymce.html.DomParser = function(settings, schema) {
  2194. var self = this, nodeFilters = {}, attributeFilters = [], matchedNodes = {}, matchedAttributes = {};
  2195. settings = settings || {};
  2196. settings.validate = "validate" in settings ? settings.validate : true;
  2197. settings.root_name = settings.root_name || 'body';
  2198. self.schema = schema = schema || new tinymce.html.Schema();
  2199. function fixInvalidChildren(nodes) {
  2200. var ni, node, parent, parents, newParent, currentNode, tempNode, childNode, i,
  2201. childClone, nonEmptyElements, nonSplitableElements, sibling, nextNode;
  2202. nonSplitableElements = tinymce.makeMap('tr,td,th,tbody,thead,tfoot,table');
  2203. nonEmptyElements = schema.getNonEmptyElements();
  2204. for (ni = 0; ni < nodes.length; ni++) {
  2205. node = nodes[ni];
  2206. // Already removed
  2207. if (!node.parent)
  2208. continue;
  2209. // Get list of all parent nodes until we find a valid parent to stick the child into
  2210. parents = [node];
  2211. for (parent = node.parent; parent && !schema.isValidChild(parent.name, node.name) && !nonSplitableElements[parent.name]; parent = parent.parent)
  2212. parents.push(parent);
  2213. // Found a suitable parent
  2214. if (parent && parents.length > 1) {
  2215. // Reverse the array since it makes looping easier
  2216. parents.reverse();
  2217. // Clone the related parent and insert that after the moved node
  2218. newParent = currentNode = self.filterNode(parents[0].clone());
  2219. // Start cloning and moving children on the left side of the target node
  2220. for (i = 0; i < parents.length - 1; i++) {
  2221. if (schema.isValidChild(currentNode.name, parents[i].name)) {
  2222. tempNode = self.filterNode(parents[i].clone());
  2223. currentNode.append(tempNode);
  2224. } else
  2225. tempNode = currentNode;
  2226. for (childNode = parents[i].firstChild; childNode && childNode != parents[i + 1]; ) {
  2227. nextNode = childNode.next;
  2228. tempNode.append(childNode);
  2229. childNode = nextNode;
  2230. }
  2231. currentNode = tempNode;
  2232. }
  2233. if (!newParent.isEmpty(nonEmptyElements)) {
  2234. parent.insert(newParent, parents[0], true);
  2235. parent.insert(node, newParent);
  2236. } else {
  2237. parent.insert(node, parents[0], true);
  2238. }
  2239. // Check if the element is empty by looking through it's contents and special treatment for <p><br /></p>
  2240. parent = parents[0];
  2241. if (parent.isEmpty(nonEmptyElements) || parent.firstChild === parent.lastChild && parent.firstChild.name === 'br') {
  2242. parent.empty().remove();
  2243. }
  2244. } else if (node.parent) {
  2245. // If it's an LI try to find a UL/OL for it or wrap it
  2246. if (node.name === 'li') {
  2247. sibling = node.prev;
  2248. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  2249. sibling.append(node);
  2250. continue;
  2251. }
  2252. sibling = node.next;
  2253. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  2254. sibling.insert(node, sibling.firstChild, true);
  2255. continue;
  2256. }
  2257. node.wrap(self.filterNode(new Node('ul', 1)));
  2258. continue;
  2259. }
  2260. // Try wrapping the element in a DIV
  2261. if (schema.isValidChild(node.parent.name, 'div') && schema.isValidChild('div', node.name)) {
  2262. node.wrap(self.filterNode(new Node('div', 1)));
  2263. } else {
  2264. // We failed wrapping it, then remove or unwrap it
  2265. if (node.name === 'style' || node.name === 'script')
  2266. node.empty().remove();
  2267. else
  2268. node.unwrap();
  2269. }
  2270. }
  2271. }
  2272. };
  2273. self.filterNode = function(node) {
  2274. var i, name, list;
  2275. // Run element filters
  2276. if (name in nodeFilters) {
  2277. list = matchedNodes[name];
  2278. if (list)
  2279. list.push(node);
  2280. else
  2281. matchedNodes[name] = [node];
  2282. }
  2283. // Run attribute filters
  2284. i = attributeFilters.length;
  2285. while (i--) {
  2286. name = attributeFilters[i].name;
  2287. if (name in node.attributes.map) {
  2288. list = matchedAttributes[name];
  2289. if (list)
  2290. list.push(node);
  2291. else
  2292. matchedAttributes[name] = [node];
  2293. }
  2294. }
  2295. return node;
  2296. };
  2297. self.addNodeFilter = function(name, callback) {
  2298. tinymce.each(tinymce.explode(name), function(name) {
  2299. var list = nodeFilters[name];
  2300. if (!list)
  2301. nodeFilters[name] = list = [];
  2302. list.push(callback);
  2303. });
  2304. };
  2305. self.addAttributeFilter = function(name, callback) {
  2306. tinymce.each(tinymce.explode(name), function(name) {
  2307. var i;
  2308. for (i = 0; i < attributeFilters.length; i++) {
  2309. if (attributeFilters[i].name === name) {
  2310. attributeFilters[i].callbacks.push(callback);
  2311. return;
  2312. }
  2313. }
  2314. attributeFilters.push({name: name, callbacks: [callback]});
  2315. });
  2316. };
  2317. self.parse = function(html, args) {
  2318. var parser, rootNode, node, nodes, i, l, fi, fl, list, name, validate,
  2319. blockElements, startWhiteSpaceRegExp, invalidChildren = [],
  2320. endWhiteSpaceRegExp, allWhiteSpaceRegExp, whiteSpaceElements, children, nonEmptyElements, rootBlockName;
  2321. args = args || {};
  2322. matchedNodes = {};
  2323. matchedAttributes = {};
  2324. blockElements = tinymce.extend(tinymce.makeMap('script,style,head,html,body,title,meta,param'), schema.getBlockElements());
  2325. nonEmptyElements = schema.getNonEmptyElements();
  2326. children = schema.children;
  2327. validate = settings.validate;
  2328. rootBlockName = "forced_root_block" in args ? args.forced_root_block : settings.forced_root_block;
  2329. whiteSpaceElements = schema.getWhiteSpaceElements();
  2330. startWhiteSpaceRegExp = /^[ \t\r\n]+/;
  2331. endWhiteSpaceRegExp = /[ \t\r\n]+$/;
  2332. allWhiteSpaceRegExp = /[ \t\r\n]+/g;
  2333. function addRootBlocks() {
  2334. var node = rootNode.firstChild, next, rootBlockNode;
  2335. while (node) {
  2336. next = node.next;
  2337. if (node.type == 3 || (node.type == 1 && node.name !== 'p' && !blockElements[node.name] && !node.attr('data-mce-type'))) {
  2338. if (!rootBlockNode) {
  2339. // Create a new root block element
  2340. rootBlockNode = createNode(rootBlockName, 1);
  2341. rootNode.insert(rootBlockNode, node);
  2342. rootBlockNode.append(node);
  2343. } else
  2344. rootBlockNode.append(node);
  2345. } else {
  2346. rootBlockNode = null;
  2347. }
  2348. node = next;
  2349. };
  2350. };
  2351. function createNode(name, type) {
  2352. var node = new Node(name, type), list;
  2353. if (name in nodeFilters) {
  2354. list = matchedNodes[name];
  2355. if (list)
  2356. list.push(node);
  2357. else
  2358. matchedNodes[name] = [node];
  2359. }
  2360. return node;
  2361. };
  2362. function removeWhitespaceBefore(node) {
  2363. var textNode, textVal, sibling;
  2364. for (textNode = node.prev; textNode && textNode.type === 3; ) {
  2365. textVal = textNode.value.replace(endWhiteSpaceRegExp, '');
  2366. if (textVal.length > 0) {
  2367. textNode.value = textVal;
  2368. textNode = textNode.prev;
  2369. } else {
  2370. sibling = textNode.prev;
  2371. textNode.remove();
  2372. textNode = sibling;
  2373. }
  2374. }
  2375. };
  2376. parser = new tinymce.html.SaxParser({
  2377. validate : validate,
  2378. fix_self_closing : !validate, // Let the DOM parser handle <li> in <li> or <p> in <p> for better results
  2379. cdata: function(text) {
  2380. node.append(createNode('#cdata', 4)).value = text;
  2381. },
  2382. text: function(text, raw) {
  2383. var textNode;
  2384. // Trim all redundant whitespace on non white space elements
  2385. if (!whiteSpaceElements[node.name]) {
  2386. text = text.replace(allWhiteSpaceRegExp, ' ');
  2387. if (node.lastChild && blockElements[node.lastChild.name])
  2388. text = text.replace(startWhiteSpaceRegExp, '');
  2389. }
  2390. // Do we need to create the node
  2391. if (text.length !== 0) {
  2392. textNode = createNode('#text', 3);
  2393. textNode.raw = !!raw;
  2394. node.append(textNode).value = text;
  2395. }
  2396. },
  2397. comment: function(text) {
  2398. node.append(createNode('#comment', 8)).value = text;
  2399. },
  2400. pi: function(name, text) {
  2401. node.append(createNode(name, 7)).value = text;
  2402. removeWhitespaceBefore(node);
  2403. },
  2404. doctype: function(text) {
  2405. var newNode;
  2406. newNode = node.append(createNode('#doctype', 10));
  2407. newNode.value = text;
  2408. removeWhitespaceBefore(node);
  2409. },
  2410. start: function(name, attrs, empty) {
  2411. var newNode, attrFiltersLen, elementRule, textNode, attrName, text, sibling, parent;
  2412. elementRule = validate ? schema.getElementRule(name) : {};
  2413. if (elementRule) {
  2414. newNode = createNode(elementRule.outputName || name, 1);
  2415. newNode.attributes = attrs;
  2416. newNode.shortEnded = empty;
  2417. node.append(newNode);
  2418. // Check if node is valid child of the parent node is the child is
  2419. // unknown we don't collect it since it's probably a custom element
  2420. parent = children[node.name];
  2421. if (parent && children[newNode.name] && !parent[newNode.name])
  2422. invalidChildren.push(newNode);
  2423. attrFiltersLen = attributeFilters.length;
  2424. while (attrFiltersLen--) {
  2425. attrName = attributeFilters[attrFiltersLen].name;
  2426. if (attrName in attrs.map) {
  2427. list = matchedAttributes[attrName];
  2428. if (list)
  2429. list.push(newNode);
  2430. else
  2431. matchedAttributes[attrName] = [newNode];
  2432. }
  2433. }
  2434. // Trim whitespace before block
  2435. if (blockElements[name])
  2436. removeWhitespaceBefore(newNode);
  2437. // Change current node if the element wasn't empty i.e not <br /> or <img />
  2438. if (!empty)
  2439. node = newNode;
  2440. }
  2441. },
  2442. end: function(name) {
  2443. var textNode, elementRule, text, sibling, tempNode;
  2444. elementRule = validate ? schema.getElementRule(name) : {};
  2445. if (elementRule) {
  2446. if (blockElements[name]) {
  2447. if (!whiteSpaceElements[node.name]) {
  2448. // Trim whitespace at beginning of block
  2449. for (textNode = node.firstChild; textNode && textNode.type === 3; ) {
  2450. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  2451. if (text.length > 0) {
  2452. textNode.value = text;
  2453. textNode = textNode.next;
  2454. } else {
  2455. sibling = textNode.next;
  2456. textNode.remove();
  2457. textNode = sibling;
  2458. }
  2459. }
  2460. // Trim whitespace at end of block
  2461. for (textNode = node.lastChild; textNode && textNode.type === 3; ) {
  2462. text = textNode.value.replace(endWhiteSpaceRegExp, '');
  2463. if (text.length > 0) {
  2464. textNode.value = text;
  2465. textNode = textNode.prev;
  2466. } else {
  2467. sibling = textNode.prev;
  2468. textNode.remove();
  2469. textNode = sibling;
  2470. }
  2471. }
  2472. }
  2473. // Trim start white space
  2474. textNode = node.prev;
  2475. if (textNode && textNode.type === 3) {
  2476. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  2477. if (text.length > 0)
  2478. textNode.value = text;
  2479. else
  2480. textNode.remove();
  2481. }
  2482. }
  2483. // Handle empty nodes
  2484. if (elementRule.removeEmpty || elementRule.paddEmpty) {
  2485. if (node.isEmpty(nonEmptyElements)) {
  2486. if (elementRule.paddEmpty)
  2487. node.empty().append(new Node('#text', '3')).value = '\u00a0';
  2488. else {
  2489. // Leave nodes that have a name like <a name="name">
  2490. if (!node.attributes.map.name) {
  2491. tempNode = node.parent;
  2492. node.empty().remove();
  2493. node = tempNode;
  2494. return;
  2495. }
  2496. }
  2497. }
  2498. }
  2499. node = node.parent;
  2500. }
  2501. }
  2502. }, schema);
  2503. rootNode = node = new Node(args.context || settings.root_name, 11);
  2504. parser.parse(html);
  2505. // Fix invalid children or report invalid children in a contextual parsing
  2506. if (validate && invalidChildren.length) {
  2507. if (!args.context)
  2508. fixInvalidChildren(invalidChildren);
  2509. else
  2510. args.invalid = true;
  2511. }
  2512. // Wrap nodes in the root into block elements if the root is body
  2513. if (rootBlockName && rootNode.name == 'body')
  2514. addRootBlocks();
  2515. // Run filters only when the contents is valid
  2516. if (!args.invalid) {
  2517. // Run node filters
  2518. for (name in matchedNodes) {
  2519. list = nodeFilters[name];
  2520. nodes = matchedNodes[name];
  2521. // Remove already removed children
  2522. fi = nodes.length;
  2523. while (fi--) {
  2524. if (!nodes[fi].parent)
  2525. nodes.splice(fi, 1);
  2526. }
  2527. for (i = 0, l = list.length; i < l; i++)
  2528. list[i](nodes, name, args);
  2529. }
  2530. // Run attribute filters
  2531. for (i = 0, l = attributeFilters.length; i < l; i++) {
  2532. list = attributeFilters[i];
  2533. if (list.name in matchedAttributes) {
  2534. nodes = matchedAttributes[list.name];
  2535. // Remove already removed children
  2536. fi = nodes.length;
  2537. while (fi--) {
  2538. if (!nodes[fi].parent)
  2539. nodes.splice(fi, 1);
  2540. }
  2541. for (fi = 0, fl = list.callbacks.length; fi < fl; fi++)
  2542. list.callbacks[fi](nodes, list.name, args);
  2543. }
  2544. }
  2545. }
  2546. return rootNode;
  2547. };
  2548. // Remove <br> at end of block elements Gecko and WebKit injects BR elements to
  2549. // make it possible to place the caret inside empty blocks. This logic tries to remove
  2550. // these elements and keep br elements that where intended to be there intact
  2551. if (settings.remove_trailing_brs) {
  2552. self.addNodeFilter('br', function(nodes, name) {
  2553. var i, l = nodes.length, node, blockElements = schema.getBlockElements(),
  2554. nonEmptyElements = schema.getNonEmptyElements(), parent, prev, prevName;
  2555. // Remove brs from body element as well
  2556. blockElements.body = 1;
  2557. // Must loop forwards since it will otherwise remove all brs in <p>a<br><br><br></p>
  2558. for (i = 0; i < l; i++) {
  2559. node = nodes[i];
  2560. parent = node.parent;
  2561. if (blockElements[node.parent.name] && node === parent.lastChild) {
  2562. // Loop all nodes to the right of the current node and check for other BR elements
  2563. // excluding bookmarks since they are invisible
  2564. prev = node.prev;
  2565. while (prev) {
  2566. prevName = prev.name;
  2567. // Ignore bookmarks
  2568. if (prevName !== "span" || prev.attr('data-mce-type') !== 'bookmark') {
  2569. // Found a non BR element
  2570. if (prevName !== "br")
  2571. break;
  2572. // Found another br it's a <br><br> structure then don't remove anything
  2573. if (prevName === 'br') {
  2574. node = null;
  2575. break;
  2576. }
  2577. }
  2578. prev = prev.prev;
  2579. }
  2580. if (node) {
  2581. node.remove();
  2582. // Is the parent to be considered empty after we removed the BR
  2583. if (parent.isEmpty(nonEmptyElements)) {
  2584. elementRule = schema.getElementRule(parent.name);
  2585. // Remove or padd the element depending on schema rule
  2586. if (elementRule) {
  2587. if (elementRule.removeEmpty)
  2588. parent.remove();
  2589. else if (elementRule.paddEmpty)
  2590. parent.empty().append(new tinymce.html.Node('#text', 3)).value = '\u00a0';
  2591. }
  2592. }
  2593. }
  2594. }
  2595. }
  2596. });
  2597. }
  2598. }
  2599. })(tinymce);
  2600. tinymce.html.Writer = function(settings) {
  2601. var html = [], indent, indentBefore, indentAfter, encode, htmlOutput;
  2602. settings = settings || {};
  2603. indent = settings.indent;
  2604. indentBefore = tinymce.makeMap(settings.indent_before || '');
  2605. indentAfter = tinymce.makeMap(settings.indent_after || '');
  2606. encode = tinymce.html.Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities);
  2607. htmlOutput = settings.element_format == "html";
  2608. return {
  2609. start: function(name, attrs, empty) {
  2610. var i, l, attr, value;
  2611. if (indent && indentBefore[name] && html.length > 0) {
  2612. value = html[html.length - 1];
  2613. if (value.length > 0 && value !== '\n')
  2614. html.push('\n');
  2615. }
  2616. html.push('<', name);
  2617. if (attrs) {
  2618. for (i = 0, l = attrs.length; i < l; i++) {
  2619. attr = attrs[i];
  2620. html.push(' ', attr.name, '="', encode(attr.value, true), '"');
  2621. }
  2622. }
  2623. if (!empty || htmlOutput)
  2624. html[html.length] = '>';
  2625. else
  2626. html[html.length] = ' />';
  2627. if (empty && indent && indentAfter[name] && html.length > 0) {
  2628. value = html[html.length - 1];
  2629. if (value.length > 0 && value !== '\n')
  2630. html.push('\n');
  2631. }
  2632. },
  2633. end: function(name) {
  2634. var value;
  2635. /*if (indent && indentBefore[name] && html.length > 0) {
  2636. value = html[html.length - 1];
  2637. if (value.length > 0 && value !== '\n')
  2638. html.push('\n');
  2639. }*/
  2640. html.push('</', name, '>');
  2641. if (indent && indentAfter[name] && html.length > 0) {
  2642. value = html[html.length - 1];
  2643. if (value.length > 0 && value !== '\n')
  2644. html.push('\n');
  2645. }
  2646. },
  2647. text: function(text, raw) {
  2648. if (text.length > 0)
  2649. html[html.length] = raw ? text : encode(text);
  2650. },
  2651. cdata: function(text) {
  2652. html.push('<![CDATA[', text, ']]>');
  2653. },
  2654. comment: function(text) {
  2655. html.push('<!--', text, '-->');
  2656. },
  2657. pi: function(name, text) {
  2658. if (text)
  2659. html.push('<?', name, ' ', text, '?>');
  2660. else
  2661. html.push('<?', name, '?>');
  2662. if (indent)
  2663. html.push('\n');
  2664. },
  2665. doctype: function(text) {
  2666. html.push('<!DOCTYPE', text, '>', indent ? '\n' : '');
  2667. },
  2668. reset: function() {
  2669. html.length = 0;
  2670. },
  2671. getContent: function() {
  2672. return html.join('').replace(/\n$/, '');
  2673. }
  2674. };
  2675. };
  2676. (function(tinymce) {
  2677. tinymce.html.Serializer = function(settings, schema) {
  2678. var self = this, writer = new tinymce.html.Writer(settings);
  2679. settings = settings || {};
  2680. settings.validate = "validate" in settings ? settings.validate : true;
  2681. self.schema = schema = schema || new tinymce.html.Schema();
  2682. self.writer = writer;
  2683. self.serialize = function(node) {
  2684. var handlers, validate;
  2685. validate = settings.validate;
  2686. handlers = {
  2687. // #text
  2688. 3: function(node, raw) {
  2689. writer.text(node.value, node.raw);
  2690. },
  2691. // #comment
  2692. 8: function(node) {
  2693. writer.comment(node.value);
  2694. },
  2695. // Processing instruction
  2696. 7: function(node) {
  2697. writer.pi(node.name, node.value);
  2698. },
  2699. // Doctype
  2700. 10: function(node) {
  2701. writer.doctype(node.value);
  2702. },
  2703. // CDATA
  2704. 4: function(node) {
  2705. writer.cdata(node.value);
  2706. },
  2707. // Document fragment
  2708. 11: function(node) {
  2709. if ((node = node.firstChild)) {
  2710. do {
  2711. walk(node);
  2712. } while (node = node.next);
  2713. }
  2714. }
  2715. };
  2716. writer.reset();
  2717. function walk(node) {
  2718. var handler = handlers[node.type], name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule;
  2719. if (!handler) {
  2720. name = node.name;
  2721. isEmpty = node.shortEnded;
  2722. attrs = node.attributes;
  2723. // Sort attributes
  2724. if (validate && attrs && attrs.length > 1) {
  2725. sortedAttrs = [];
  2726. sortedAttrs.map = {};
  2727. elementRule = schema.getElementRule(node.name);
  2728. for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
  2729. attrName = elementRule.attributesOrder[i];
  2730. if (attrName in attrs.map) {
  2731. attrValue = attrs.map[attrName];
  2732. sortedAttrs.map[attrName] = attrValue;
  2733. sortedAttrs.push({name: attrName, value: attrValue});
  2734. }
  2735. }
  2736. for (i = 0, l = attrs.length; i < l; i++) {
  2737. attrName = attrs[i].name;
  2738. if (!(attrName in sortedAttrs.map)) {
  2739. attrValue = attrs.map[attrName];
  2740. sortedAttrs.map[attrName] = attrValue;
  2741. sortedAttrs.push({name: attrName, value: attrValue});
  2742. }
  2743. }
  2744. attrs = sortedAttrs;
  2745. }
  2746. writer.start(node.name, attrs, isEmpty);
  2747. if (!isEmpty) {
  2748. if ((node = node.firstChild)) {
  2749. do {
  2750. walk(node);
  2751. } while (node = node.next);
  2752. }
  2753. writer.end(name);
  2754. }
  2755. } else
  2756. handler(node);
  2757. }
  2758. // Serialize element and treat all non elements as fragments
  2759. if (node.type == 1 && !settings.inner)
  2760. walk(node);
  2761. else
  2762. handlers[11](node);
  2763. return writer.getContent();
  2764. };
  2765. }
  2766. })(tinymce);
  2767. (function(tinymce) {
  2768. // Shorten names
  2769. var each = tinymce.each,
  2770. is = tinymce.is,
  2771. isWebKit = tinymce.isWebKit,
  2772. isIE = tinymce.isIE,
  2773. Entities = tinymce.html.Entities,
  2774. simpleSelectorRe = /^([a-z0-9],?)+$/i,
  2775. blockElementsMap = tinymce.html.Schema.blockElementsMap,
  2776. whiteSpaceRegExp = /^[ \t\r\n]*$/;
  2777. tinymce.create('tinymce.dom.DOMUtils', {
  2778. doc : null,
  2779. root : null,
  2780. files : null,
  2781. pixelStyles : /^(top|left|bottom|right|width|height|borderWidth)$/,
  2782. props : {
  2783. "for" : "htmlFor",
  2784. "class" : "className",
  2785. className : "className",
  2786. checked : "checked",
  2787. disabled : "disabled",
  2788. maxlength : "maxLength",
  2789. readonly : "readOnly",
  2790. selected : "selected",
  2791. value : "value",
  2792. id : "id",
  2793. name : "name",
  2794. type : "type"
  2795. },
  2796. DOMUtils : function(d, s) {
  2797. var t = this, globalStyle, name;
  2798. t.doc = d;
  2799. t.win = window;
  2800. t.files = {};
  2801. t.cssFlicker = false;
  2802. t.counter = 0;
  2803. t.stdMode = !tinymce.isIE || d.documentMode >= 8;
  2804. t.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat" || t.stdMode;
  2805. t.hasOuterHTML = "outerHTML" in d.createElement("a");
  2806. t.settings = s = tinymce.extend({
  2807. keep_values : false,
  2808. hex_colors : 1
  2809. }, s);
  2810. t.schema = s.schema;
  2811. t.styles = new tinymce.html.Styles({
  2812. url_converter : s.url_converter,
  2813. url_converter_scope : s.url_converter_scope
  2814. }, s.schema);
  2815. // Fix IE6SP2 flicker and check it failed for pre SP2
  2816. if (tinymce.isIE6) {
  2817. try {
  2818. d.execCommand('BackgroundImageCache', false, true);
  2819. } catch (e) {
  2820. t.cssFlicker = true;
  2821. }
  2822. }
  2823. if (isIE && s.schema) {
  2824. // Add missing HTML 4/5 elements to IE
  2825. ('abbr article aside audio canvas ' +
  2826. 'details figcaption figure footer ' +
  2827. 'header hgroup mark menu meter nav ' +
  2828. 'output progress section summary ' +
  2829. 'time video').replace(/\w+/g, function(name) {
  2830. d.createElement(name);
  2831. });
  2832. // Create all custom elements
  2833. for (name in s.schema.getCustomElements()) {
  2834. d.createElement(name);
  2835. }
  2836. }
  2837. tinymce.addUnload(t.destroy, t);
  2838. },
  2839. getRoot : function() {
  2840. var t = this, s = t.settings;
  2841. return (s && t.get(s.root_element)) || t.doc.body;
  2842. },
  2843. getViewPort : function(w) {
  2844. var d, b;
  2845. w = !w ? this.win : w;
  2846. d = w.document;
  2847. b = this.boxModel ? d.documentElement : d.body;
  2848. // Returns viewport size excluding scrollbars
  2849. return {
  2850. x : w.pageXOffset || b.scrollLeft,
  2851. y : w.pageYOffset || b.scrollTop,
  2852. w : w.innerWidth || b.clientWidth,
  2853. h : w.innerHeight || b.clientHeight
  2854. };
  2855. },
  2856. getRect : function(e) {
  2857. var p, t = this, sr;
  2858. e = t.get(e);
  2859. p = t.getPos(e);
  2860. sr = t.getSize(e);
  2861. return {
  2862. x : p.x,
  2863. y : p.y,
  2864. w : sr.w,
  2865. h : sr.h
  2866. };
  2867. },
  2868. getSize : function(e) {
  2869. var t = this, w, h;
  2870. e = t.get(e);
  2871. w = t.getStyle(e, 'width');
  2872. h = t.getStyle(e, 'height');
  2873. // Non pixel value, then force offset/clientWidth
  2874. if (w.indexOf('px') === -1)
  2875. w = 0;
  2876. // Non pixel value, then force offset/clientWidth
  2877. if (h.indexOf('px') === -1)
  2878. h = 0;
  2879. return {
  2880. w : parseInt(w) || e.offsetWidth || e.clientWidth,
  2881. h : parseInt(h) || e.offsetHeight || e.clientHeight
  2882. };
  2883. },
  2884. getParent : function(n, f, r) {
  2885. return this.getParents(n, f, r, false);
  2886. },
  2887. getParents : function(n, f, r, c) {
  2888. var t = this, na, se = t.settings, o = [];
  2889. n = t.get(n);
  2890. c = c === undefined;
  2891. if (se.strict_root)
  2892. r = r || t.getRoot();
  2893. // Wrap node name as func
  2894. if (is(f, 'string')) {
  2895. na = f;
  2896. if (f === '*') {
  2897. f = function(n) {return n.nodeType == 1;};
  2898. } else {
  2899. f = function(n) {
  2900. return t.is(n, na);
  2901. };
  2902. }
  2903. }
  2904. while (n) {
  2905. if (n == r || !n.nodeType || n.nodeType === 9)
  2906. break;
  2907. if (!f || f(n)) {
  2908. if (c)
  2909. o.push(n);
  2910. else
  2911. return n;
  2912. }
  2913. n = n.parentNode;
  2914. }
  2915. return c ? o : null;
  2916. },
  2917. get : function(e) {
  2918. var n;
  2919. if (e && this.doc && typeof(e) == 'string') {
  2920. n = e;
  2921. e = this.doc.getElementById(e);
  2922. // IE and Opera returns meta elements when they match the specified input ID, but getElementsByName seems to do the trick
  2923. if (e && e.id !== n)
  2924. return this.doc.getElementsByName(n)[1];
  2925. }
  2926. return e;
  2927. },
  2928. getNext : function(node, selector) {
  2929. return this._findSib(node, selector, 'nextSibling');
  2930. },
  2931. getPrev : function(node, selector) {
  2932. return this._findSib(node, selector, 'previousSibling');
  2933. },
  2934. select : function(pa, s) {
  2935. var t = this;
  2936. return tinymce.dom.Sizzle(pa, t.get(s) || t.get(t.settings.root_element) || t.doc, []);
  2937. },
  2938. is : function(n, selector) {
  2939. var i;
  2940. // If it isn't an array then try to do some simple selectors instead of Sizzle for to boost performance
  2941. if (n.length === undefined) {
  2942. // Simple all selector
  2943. if (selector === '*')
  2944. return n.nodeType == 1;
  2945. // Simple selector just elements
  2946. if (simpleSelectorRe.test(selector)) {
  2947. selector = selector.toLowerCase().split(/,/);
  2948. n = n.nodeName.toLowerCase();
  2949. for (i = selector.length - 1; i >= 0; i--) {
  2950. if (selector[i] == n)
  2951. return true;
  2952. }
  2953. return false;
  2954. }
  2955. }
  2956. return tinymce.dom.Sizzle.matches(selector, n.nodeType ? [n] : n).length > 0;
  2957. },
  2958. add : function(p, n, a, h, c) {
  2959. var t = this;
  2960. return this.run(p, function(p) {
  2961. var e, k;
  2962. e = is(n, 'string') ? t.doc.createElement(n) : n;
  2963. t.setAttribs(e, a);
  2964. if (h) {
  2965. if (h.nodeType)
  2966. e.appendChild(h);
  2967. else
  2968. t.setHTML(e, h);
  2969. }
  2970. return !c ? p.appendChild(e) : e;
  2971. });
  2972. },
  2973. create : function(n, a, h) {
  2974. return this.add(this.doc.createElement(n), n, a, h, 1);
  2975. },
  2976. createHTML : function(n, a, h) {
  2977. var o = '', t = this, k;
  2978. o += '<' + n;
  2979. for (k in a) {
  2980. if (a.hasOwnProperty(k))
  2981. o += ' ' + k + '="' + t.encode(a[k]) + '"';
  2982. }
  2983. // A call to tinymce.is doesn't work for some odd reason on IE9 possible bug inside their JS runtime
  2984. if (typeof(h) != "undefined")
  2985. return o + '>' + h + '</' + n + '>';
  2986. return o + ' />';
  2987. },
  2988. remove : function(node, keep_children) {
  2989. return this.run(node, function(node) {
  2990. var child, parent = node.parentNode;
  2991. if (!parent)
  2992. return null;
  2993. if (keep_children) {
  2994. while (child = node.firstChild) {
  2995. // IE 8 will crash if you don't remove completely empty text nodes
  2996. if (!tinymce.isIE || child.nodeType !== 3 || child.nodeValue)
  2997. parent.insertBefore(child, node);
  2998. else
  2999. node.removeChild(child);
  3000. }
  3001. }
  3002. return parent.removeChild(node);
  3003. });
  3004. },
  3005. setStyle : function(n, na, v) {
  3006. var t = this;
  3007. return t.run(n, function(e) {
  3008. var s, i;
  3009. s = e.style;
  3010. // Camelcase it, if needed
  3011. na = na.replace(/-(\D)/g, function(a, b){
  3012. return b.toUpperCase();
  3013. });
  3014. // Default px suffix on these
  3015. if (t.pixelStyles.test(na) && (tinymce.is(v, 'number') || /^[\-0-9\.]+$/.test(v)))
  3016. v += 'px';
  3017. switch (na) {
  3018. case 'opacity':
  3019. // IE specific opacity
  3020. if (isIE) {
  3021. s.filter = v === '' ? '' : "alpha(opacity=" + (v * 100) + ")";
  3022. if (!n.currentStyle || !n.currentStyle.hasLayout)
  3023. s.display = 'inline-block';
  3024. }
  3025. // Fix for older browsers
  3026. s[na] = s['-moz-opacity'] = s['-khtml-opacity'] = v || '';
  3027. break;
  3028. case 'float':
  3029. isIE ? s.styleFloat = v : s.cssFloat = v;
  3030. break;
  3031. default:
  3032. s[na] = v || '';
  3033. }
  3034. // Force update of the style data
  3035. if (t.settings.update_styles)
  3036. t.setAttrib(e, 'data-mce-style');
  3037. });
  3038. },
  3039. getStyle : function(n, na, c) {
  3040. n = this.get(n);
  3041. if (!n)
  3042. return;
  3043. // Gecko
  3044. if (this.doc.defaultView && c) {
  3045. // Remove camelcase
  3046. na = na.replace(/[A-Z]/g, function(a){
  3047. return '-' + a;
  3048. });
  3049. try {
  3050. return this.doc.defaultView.getComputedStyle(n, null).getPropertyValue(na);
  3051. } catch (ex) {
  3052. // Old safari might fail
  3053. return null;
  3054. }
  3055. }
  3056. // Camelcase it, if needed
  3057. na = na.replace(/-(\D)/g, function(a, b){
  3058. return b.toUpperCase();
  3059. });
  3060. if (na == 'float')
  3061. na = isIE ? 'styleFloat' : 'cssFloat';
  3062. // IE & Opera
  3063. if (n.currentStyle && c)
  3064. return n.currentStyle[na];
  3065. return n.style ? n.style[na] : undefined;
  3066. },
  3067. setStyles : function(e, o) {
  3068. var t = this, s = t.settings, ol;
  3069. ol = s.update_styles;
  3070. s.update_styles = 0;
  3071. each(o, function(v, n) {
  3072. t.setStyle(e, n, v);
  3073. });
  3074. // Update style info
  3075. s.update_styles = ol;
  3076. if (s.update_styles)
  3077. t.setAttrib(e, s.cssText);
  3078. },
  3079. removeAllAttribs: function(e) {
  3080. return this.run(e, function(e) {
  3081. var i, attrs = e.attributes;
  3082. for (i = attrs.length - 1; i >= 0; i--) {
  3083. e.removeAttributeNode(attrs.item(i));
  3084. }
  3085. });
  3086. },
  3087. setAttrib : function(e, n, v) {
  3088. var t = this;
  3089. // Whats the point
  3090. if (!e || !n)
  3091. return;
  3092. // Strict XML mode
  3093. if (t.settings.strict)
  3094. n = n.toLowerCase();
  3095. return this.run(e, function(e) {
  3096. var s = t.settings;
  3097. if (v !== null) {
  3098. switch (n) {
  3099. case "style":
  3100. if (!is(v, 'string')) {
  3101. each(v, function(v, n) {
  3102. t.setStyle(e, n, v);
  3103. });
  3104. return;
  3105. }
  3106. // No mce_style for elements with these since they might get resized by the user
  3107. if (s.keep_values) {
  3108. if (v && !t._isRes(v))
  3109. e.setAttribute('data-mce-style', v, 2);
  3110. else
  3111. e.removeAttribute('data-mce-style', 2);
  3112. }
  3113. e.style.cssText = v;
  3114. break;
  3115. case "class":
  3116. e.className = v || ''; // Fix IE null bug
  3117. break;
  3118. case "src":
  3119. case "href":
  3120. if (s.keep_values) {
  3121. if (s.url_converter)
  3122. v = s.url_converter.call(s.url_converter_scope || t, v, n, e);
  3123. t.setAttrib(e, 'data-mce-' + n, v, 2);
  3124. }
  3125. break;
  3126. case "shape":
  3127. e.setAttribute('data-mce-style', v);
  3128. break;
  3129. }
  3130. }
  3131. if (is(v) && v !== null && v.length !== 0)
  3132. e.setAttribute(n, '' + v, 2);
  3133. else
  3134. e.removeAttribute(n, 2);
  3135. });
  3136. },
  3137. setAttribs : function(e, o) {
  3138. var t = this;
  3139. return this.run(e, function(e) {
  3140. each(o, function(v, n) {
  3141. t.setAttrib(e, n, v);
  3142. });
  3143. });
  3144. },
  3145. getAttrib : function(e, n, dv) {
  3146. var v, t = this, undef;
  3147. e = t.get(e);
  3148. if (!e || e.nodeType !== 1)
  3149. return dv === undef ? false : dv;
  3150. if (!is(dv))
  3151. dv = '';
  3152. // Try the mce variant for these
  3153. if (/^(src|href|style|coords|shape)$/.test(n)) {
  3154. v = e.getAttribute("data-mce-" + n);
  3155. if (v)
  3156. return v;
  3157. }
  3158. if (isIE && t.props[n]) {
  3159. v = e[t.props[n]];
  3160. v = v && v.nodeValue ? v.nodeValue : v;
  3161. }
  3162. if (!v)
  3163. v = e.getAttribute(n, 2);
  3164. // Check boolean attribs
  3165. if (/^(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)$/.test(n)) {
  3166. if (e[t.props[n]] === true && v === '')
  3167. return n;
  3168. return v ? n : '';
  3169. }
  3170. // Inner input elements will override attributes on form elements
  3171. if (e.nodeName === "FORM" && e.getAttributeNode(n))
  3172. return e.getAttributeNode(n).nodeValue;
  3173. if (n === 'style') {
  3174. v = v || e.style.cssText;
  3175. if (v) {
  3176. v = t.serializeStyle(t.parseStyle(v), e.nodeName);
  3177. if (t.settings.keep_values && !t._isRes(v))
  3178. e.setAttribute('data-mce-style', v);
  3179. }
  3180. }
  3181. // Remove Apple and WebKit stuff
  3182. if (isWebKit && n === "class" && v)
  3183. v = v.replace(/(apple|webkit)\-[a-z\-]+/gi, '');
  3184. // Handle IE issues
  3185. if (isIE) {
  3186. switch (n) {
  3187. case 'rowspan':
  3188. case 'colspan':
  3189. // IE returns 1 as default value
  3190. if (v === 1)
  3191. v = '';
  3192. break;
  3193. case 'size':
  3194. // IE returns +0 as default value for size
  3195. if (v === '+0' || v === 20 || v === 0)
  3196. v = '';
  3197. break;
  3198. case 'width':
  3199. case 'height':
  3200. case 'vspace':
  3201. case 'checked':
  3202. case 'disabled':
  3203. case 'readonly':
  3204. if (v === 0)
  3205. v = '';
  3206. break;
  3207. case 'hspace':
  3208. // IE returns -1 as default value
  3209. if (v === -1)
  3210. v = '';
  3211. break;
  3212. case 'maxlength':
  3213. case 'tabindex':
  3214. // IE returns default value
  3215. if (v === 32768 || v === 2147483647 || v === '32768')
  3216. v = '';
  3217. break;
  3218. case 'multiple':
  3219. case 'compact':
  3220. case 'noshade':
  3221. case 'nowrap':
  3222. if (v === 65535)
  3223. return n;
  3224. return dv;
  3225. case 'shape':
  3226. v = v.toLowerCase();
  3227. break;
  3228. default:
  3229. // IE has odd anonymous function for event attributes
  3230. if (n.indexOf('on') === 0 && v)
  3231. v = tinymce._replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1', '' + v);
  3232. }
  3233. }
  3234. return (v !== undef && v !== null && v !== '') ? '' + v : dv;
  3235. },
  3236. getPos : function(n, ro) {
  3237. var t = this, x = 0, y = 0, e, d = t.doc, r;
  3238. n = t.get(n);
  3239. ro = ro || d.body;
  3240. if (n) {
  3241. // Use getBoundingClientRect if it exists since it's faster than looping offset nodes
  3242. if (n.getBoundingClientRect) {
  3243. n = n.getBoundingClientRect();
  3244. e = t.boxModel ? d.documentElement : d.body;
  3245. // Add scroll offsets from documentElement or body since IE with the wrong box model will use d.body and so do WebKit
  3246. // Also remove the body/documentelement clientTop/clientLeft on IE 6, 7 since they offset the position
  3247. x = n.left + (d.documentElement.scrollLeft || d.body.scrollLeft) - e.clientTop;
  3248. y = n.top + (d.documentElement.scrollTop || d.body.scrollTop) - e.clientLeft;
  3249. return {x : x, y : y};
  3250. }
  3251. r = n;
  3252. while (r && r != ro && r.nodeType) {
  3253. x += r.offsetLeft || 0;
  3254. y += r.offsetTop || 0;
  3255. r = r.offsetParent;
  3256. }
  3257. r = n.parentNode;
  3258. while (r && r != ro && r.nodeType) {
  3259. x -= r.scrollLeft || 0;
  3260. y -= r.scrollTop || 0;
  3261. r = r.parentNode;
  3262. }
  3263. }
  3264. return {x : x, y : y};
  3265. },
  3266. parseStyle : function(st) {
  3267. return this.styles.parse(st);
  3268. },
  3269. serializeStyle : function(o, name) {
  3270. return this.styles.serialize(o, name);
  3271. },
  3272. loadCSS : function(u) {
  3273. var t = this, d = t.doc, head;
  3274. if (!u)
  3275. u = '';
  3276. head = t.select('head')[0];
  3277. each(u.split(','), function(u) {
  3278. var link;
  3279. if (t.files[u])
  3280. return;
  3281. t.files[u] = true;
  3282. link = t.create('link', {rel : 'stylesheet', href : tinymce._addVer(u)});
  3283. // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug
  3284. // This fix seems to resolve that issue by realcing the document ones a stylesheet finishes loading
  3285. // It's ugly but it seems to work fine.
  3286. if (isIE && d.documentMode && d.recalc) {
  3287. link.onload = function() {
  3288. if (d.recalc)
  3289. d.recalc();
  3290. link.onload = null;
  3291. };
  3292. }
  3293. head.appendChild(link);
  3294. });
  3295. },
  3296. addClass : function(e, c) {
  3297. return this.run(e, function(e) {
  3298. var o;
  3299. if (!c)
  3300. return 0;
  3301. if (this.hasClass(e, c))
  3302. return e.className;
  3303. o = this.removeClass(e, c);
  3304. return e.className = (o != '' ? (o + ' ') : '') + c;
  3305. });
  3306. },
  3307. removeClass : function(e, c) {
  3308. var t = this, re;
  3309. return t.run(e, function(e) {
  3310. var v;
  3311. if (t.hasClass(e, c)) {
  3312. if (!re)
  3313. re = new RegExp("(^|\\s+)" + c + "(\\s+|$)", "g");
  3314. v = e.className.replace(re, ' ');
  3315. v = tinymce.trim(v != ' ' ? v : '');
  3316. e.className = v;
  3317. // Empty class attr
  3318. if (!v) {
  3319. e.removeAttribute('class');
  3320. e.removeAttribute('className');
  3321. }
  3322. return v;
  3323. }
  3324. return e.className;
  3325. });
  3326. },
  3327. hasClass : function(n, c) {
  3328. n = this.get(n);
  3329. if (!n || !c)
  3330. return false;
  3331. return (' ' + n.className + ' ').indexOf(' ' + c + ' ') !== -1;
  3332. },
  3333. show : function(e) {
  3334. return this.setStyle(e, 'display', 'block');
  3335. },
  3336. hide : function(e) {
  3337. return this.setStyle(e, 'display', 'none');
  3338. },
  3339. isHidden : function(e) {
  3340. e = this.get(e);
  3341. return !e || e.style.display == 'none' || this.getStyle(e, 'display') == 'none';
  3342. },
  3343. uniqueId : function(p) {
  3344. return (!p ? 'mce_' : p) + (this.counter++);
  3345. },
  3346. setHTML : function(element, html) {
  3347. var self = this;
  3348. return self.run(element, function(element) {
  3349. if (isIE) {
  3350. // Remove all child nodes, IE keeps empty text nodes in DOM
  3351. while (element.firstChild)
  3352. element.removeChild(element.firstChild);
  3353. try {
  3354. // IE will remove comments from the beginning
  3355. // unless you padd the contents with something
  3356. element.innerHTML = '<br />' + html;
  3357. element.removeChild(element.firstChild);
  3358. } catch (ex) {
  3359. // 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
  3360. // This seems to fix this problem
  3361. // Create new div with HTML contents and a BR infront to keep comments
  3362. element = self.create('div');
  3363. element.innerHTML = '<br />' + html;
  3364. // Add all children from div to target
  3365. each (element.childNodes, function(node, i) {
  3366. // Skip br element
  3367. if (i)
  3368. element.appendChild(node);
  3369. });
  3370. }
  3371. } else
  3372. element.innerHTML = html;
  3373. return html;
  3374. });
  3375. },
  3376. getOuterHTML : function(elm) {
  3377. var doc, self = this;
  3378. elm = self.get(elm);
  3379. if (!elm)
  3380. return null;
  3381. if (elm.nodeType === 1 && self.hasOuterHTML)
  3382. return elm.outerHTML;
  3383. doc = (elm.ownerDocument || self.doc).createElement("body");
  3384. doc.appendChild(elm.cloneNode(true));
  3385. return doc.innerHTML;
  3386. },
  3387. setOuterHTML : function(e, h, d) {
  3388. var t = this;
  3389. function setHTML(e, h, d) {
  3390. var n, tp;
  3391. tp = d.createElement("body");
  3392. tp.innerHTML = h;
  3393. n = tp.lastChild;
  3394. while (n) {
  3395. t.insertAfter(n.cloneNode(true), e);
  3396. n = n.previousSibling;
  3397. }
  3398. t.remove(e);
  3399. };
  3400. return this.run(e, function(e) {
  3401. e = t.get(e);
  3402. // Only set HTML on elements
  3403. if (e.nodeType == 1) {
  3404. d = d || e.ownerDocument || t.doc;
  3405. if (isIE) {
  3406. try {
  3407. // Try outerHTML for IE it sometimes produces an unknown runtime error
  3408. if (isIE && e.nodeType == 1)
  3409. e.outerHTML = h;
  3410. else
  3411. setHTML(e, h, d);
  3412. } catch (ex) {
  3413. // Fix for unknown runtime error
  3414. setHTML(e, h, d);
  3415. }
  3416. } else
  3417. setHTML(e, h, d);
  3418. }
  3419. });
  3420. },
  3421. decode : Entities.decode,
  3422. encode : Entities.encodeAllRaw,
  3423. insertAfter : function(node, reference_node) {
  3424. reference_node = this.get(reference_node);
  3425. return this.run(node, function(node) {
  3426. var parent, nextSibling;
  3427. parent = reference_node.parentNode;
  3428. nextSibling = reference_node.nextSibling;
  3429. if (nextSibling)
  3430. parent.insertBefore(node, nextSibling);
  3431. else
  3432. parent.appendChild(node);
  3433. return node;
  3434. });
  3435. },
  3436. isBlock : function(node) {
  3437. var type = node.nodeType;
  3438. // If it's a node then check the type and use the nodeName
  3439. if (type)
  3440. return !!(type === 1 && blockElementsMap[node.nodeName]);
  3441. return !!blockElementsMap[node];
  3442. },
  3443. replace : function(n, o, k) {
  3444. var t = this;
  3445. if (is(o, 'array'))
  3446. n = n.cloneNode(true);
  3447. return t.run(o, function(o) {
  3448. if (k) {
  3449. each(tinymce.grep(o.childNodes), function(c) {
  3450. n.appendChild(c);
  3451. });
  3452. }
  3453. return o.parentNode.replaceChild(n, o);
  3454. });
  3455. },
  3456. rename : function(elm, name) {
  3457. var t = this, newElm;
  3458. if (elm.nodeName != name.toUpperCase()) {
  3459. // Rename block element
  3460. newElm = t.create(name);
  3461. // Copy attribs to new block
  3462. each(t.getAttribs(elm), function(attr_node) {
  3463. t.setAttrib(newElm, attr_node.nodeName, t.getAttrib(elm, attr_node.nodeName));
  3464. });
  3465. // Replace block
  3466. t.replace(newElm, elm, 1);
  3467. }
  3468. return newElm || elm;
  3469. },
  3470. findCommonAncestor : function(a, b) {
  3471. var ps = a, pe;
  3472. while (ps) {
  3473. pe = b;
  3474. while (pe && ps != pe)
  3475. pe = pe.parentNode;
  3476. if (ps == pe)
  3477. break;
  3478. ps = ps.parentNode;
  3479. }
  3480. if (!ps && a.ownerDocument)
  3481. return a.ownerDocument.documentElement;
  3482. return ps;
  3483. },
  3484. toHex : function(s) {
  3485. var c = /^\s*rgb\s*?\(\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?\)\s*$/i.exec(s);
  3486. function hex(s) {
  3487. s = parseInt(s).toString(16);
  3488. return s.length > 1 ? s : '0' + s; // 0 -> 00
  3489. };
  3490. if (c) {
  3491. s = '#' + hex(c[1]) + hex(c[2]) + hex(c[3]);
  3492. return s;
  3493. }
  3494. return s;
  3495. },
  3496. getClasses : function() {
  3497. var t = this, cl = [], i, lo = {}, f = t.settings.class_filter, ov;
  3498. if (t.classes)
  3499. return t.classes;
  3500. function addClasses(s) {
  3501. // IE style imports
  3502. each(s.imports, function(r) {
  3503. addClasses(r);
  3504. });
  3505. each(s.cssRules || s.rules, function(r) {
  3506. // Real type or fake it on IE
  3507. switch (r.type || 1) {
  3508. // Rule
  3509. case 1:
  3510. if (r.selectorText) {
  3511. each(r.selectorText.split(','), function(v) {
  3512. v = v.replace(/^\s*|\s*$|^\s\./g, "");
  3513. // Is internal or it doesn't contain a class
  3514. if (/\.mce/.test(v) || !/\.[\w\-]+$/.test(v))
  3515. return;
  3516. // Remove everything but class name
  3517. ov = v;
  3518. v = tinymce._replace(/.*\.([a-z0-9_\-]+).*/i, '$1', v);
  3519. // Filter classes
  3520. if (f && !(v = f(v, ov)))
  3521. return;
  3522. if (!lo[v]) {
  3523. cl.push({'class' : v});
  3524. lo[v] = 1;
  3525. }
  3526. });
  3527. }
  3528. break;
  3529. // Import
  3530. case 3:
  3531. addClasses(r.styleSheet);
  3532. break;
  3533. }
  3534. });
  3535. };
  3536. try {
  3537. each(t.doc.styleSheets, addClasses);
  3538. } catch (ex) {
  3539. // Ignore
  3540. }
  3541. if (cl.length > 0)
  3542. t.classes = cl;
  3543. return cl;
  3544. },
  3545. run : function(e, f, s) {
  3546. var t = this, o;
  3547. if (t.doc && typeof(e) === 'string')
  3548. e = t.get(e);
  3549. if (!e)
  3550. return false;
  3551. s = s || this;
  3552. if (!e.nodeType && (e.length || e.length === 0)) {
  3553. o = [];
  3554. each(e, function(e, i) {
  3555. if (e) {
  3556. if (typeof(e) == 'string')
  3557. e = t.doc.getElementById(e);
  3558. o.push(f.call(s, e, i));
  3559. }
  3560. });
  3561. return o;
  3562. }
  3563. return f.call(s, e);
  3564. },
  3565. getAttribs : function(n) {
  3566. var o;
  3567. n = this.get(n);
  3568. if (!n)
  3569. return [];
  3570. if (isIE) {
  3571. o = [];
  3572. // Object will throw exception in IE
  3573. if (n.nodeName == 'OBJECT')
  3574. return n.attributes;
  3575. // IE doesn't keep the selected attribute if you clone option elements
  3576. if (n.nodeName === 'OPTION' && this.getAttrib(n, 'selected'))
  3577. o.push({specified : 1, nodeName : 'selected'});
  3578. // It's crazy that this is faster in IE but it's because it returns all attributes all the time
  3579. n.cloneNode(false).outerHTML.replace(/<\/?[\w:\-]+ ?|=[\"][^\"]+\"|=\'[^\']+\'|=[\w\-]+|>/gi, '').replace(/[\w:\-]+/gi, function(a) {
  3580. o.push({specified : 1, nodeName : a});
  3581. });
  3582. return o;
  3583. }
  3584. return n.attributes;
  3585. },
  3586. isEmpty : function(node, elements) {
  3587. var self = this, i, attributes, type, walker, name, parentNode;
  3588. node = node.firstChild;
  3589. if (node) {
  3590. walker = new tinymce.dom.TreeWalker(node);
  3591. elements = elements || self.schema ? self.schema.getNonEmptyElements() : null;
  3592. do {
  3593. type = node.nodeType;
  3594. if (type === 1) {
  3595. // Ignore bogus elements
  3596. if (node.getAttribute('data-mce-bogus'))
  3597. continue;
  3598. // Keep empty elements like <img />
  3599. name = node.nodeName.toLowerCase();
  3600. if (elements && elements[name]) {
  3601. // Ignore single BR elements in blocks like <p><br /></p>
  3602. parentNode = node.parentNode;
  3603. if (name === 'br' && self.isBlock(parentNode) && parentNode.firstChild === node && parentNode.lastChild === node) {
  3604. continue;
  3605. }
  3606. return false;
  3607. }
  3608. // Keep elements with data-bookmark attributes or name attribute like <a name="1"></a>
  3609. attributes = self.getAttribs(node);
  3610. i = node.attributes.length;
  3611. while (i--) {
  3612. name = node.attributes[i].nodeName;
  3613. if (name === "name" || name === 'data-mce-bookmark')
  3614. return false;
  3615. }
  3616. }
  3617. // Keep non whitespace text nodes
  3618. if ((type === 3 && !whiteSpaceRegExp.test(node.nodeValue)))
  3619. return false;
  3620. } while (node = walker.next());
  3621. }
  3622. return true;
  3623. },
  3624. destroy : function(s) {
  3625. var t = this;
  3626. if (t.events)
  3627. t.events.destroy();
  3628. t.win = t.doc = t.root = t.events = null;
  3629. // Manual destroy then remove unload handler
  3630. if (!s)
  3631. tinymce.removeUnload(t.destroy);
  3632. },
  3633. createRng : function() {
  3634. var d = this.doc;
  3635. return d.createRange ? d.createRange() : new tinymce.dom.Range(this);
  3636. },
  3637. nodeIndex : function(node, normalized) {
  3638. var idx = 0, lastNodeType, lastNode, nodeType;
  3639. if (node) {
  3640. for (lastNodeType = node.nodeType, node = node.previousSibling, lastNode = node; node; node = node.previousSibling) {
  3641. nodeType = node.nodeType;
  3642. // Normalize text nodes
  3643. if (normalized && nodeType == 3) {
  3644. if (nodeType == lastNodeType || !node.nodeValue.length)
  3645. continue;
  3646. }
  3647. idx++;
  3648. lastNodeType = nodeType;
  3649. }
  3650. }
  3651. return idx;
  3652. },
  3653. split : function(pe, e, re) {
  3654. var t = this, r = t.createRng(), bef, aft, pa;
  3655. // W3C valid browsers tend to leave empty nodes to the left/right side of the contents, this makes sense
  3656. // but we don't want that in our code since it serves no purpose for the end user
  3657. // For example if this is chopped:
  3658. // <p>text 1<span><b>CHOP</b></span>text 2</p>
  3659. // would produce:
  3660. // <p>text 1<span></span></p><b>CHOP</b><p><span></span>text 2</p>
  3661. // this function will then trim of empty edges and produce:
  3662. // <p>text 1</p><b>CHOP</b><p>text 2</p>
  3663. function trim(node) {
  3664. var i, children = node.childNodes, type = node.nodeType;
  3665. if (type == 1 && node.getAttribute('data-mce-type') == 'bookmark')
  3666. return;
  3667. for (i = children.length - 1; i >= 0; i--)
  3668. trim(children[i]);
  3669. if (type != 9) {
  3670. // Keep non whitespace text nodes
  3671. if (type == 3 && node.nodeValue.length > 0) {
  3672. // If parent element isn't a block or there isn't any useful contents for example "<p> </p>"
  3673. if (!t.isBlock(node.parentNode) || tinymce.trim(node.nodeValue).length > 0)
  3674. return;
  3675. } else if (type == 1) {
  3676. // If the only child is a bookmark then move it up
  3677. children = node.childNodes;
  3678. if (children.length == 1 && children[0] && children[0].nodeType == 1 && children[0].getAttribute('data-mce-type') == 'bookmark')
  3679. node.parentNode.insertBefore(children[0], node);
  3680. // Keep non empty elements or img, hr etc
  3681. if (children.length || /^(br|hr|input|img)$/i.test(node.nodeName))
  3682. return;
  3683. }
  3684. t.remove(node);
  3685. }
  3686. return node;
  3687. };
  3688. if (pe && e) {
  3689. // Get before chunk
  3690. r.setStart(pe.parentNode, t.nodeIndex(pe));
  3691. r.setEnd(e.parentNode, t.nodeIndex(e));
  3692. bef = r.extractContents();
  3693. // Get after chunk
  3694. r = t.createRng();
  3695. r.setStart(e.parentNode, t.nodeIndex(e) + 1);
  3696. r.setEnd(pe.parentNode, t.nodeIndex(pe) + 1);
  3697. aft = r.extractContents();
  3698. // Insert before chunk
  3699. pa = pe.parentNode;
  3700. pa.insertBefore(trim(bef), pe);
  3701. // Insert middle chunk
  3702. if (re)
  3703. pa.replaceChild(re, e);
  3704. else
  3705. pa.insertBefore(e, pe);
  3706. // Insert after chunk
  3707. pa.insertBefore(trim(aft), pe);
  3708. t.remove(pe);
  3709. return re || e;
  3710. }
  3711. },
  3712. bind : function(target, name, func, scope) {
  3713. var t = this;
  3714. if (!t.events)
  3715. t.events = new tinymce.dom.EventUtils();
  3716. return t.events.add(target, name, func, scope || this);
  3717. },
  3718. unbind : function(target, name, func) {
  3719. var t = this;
  3720. if (!t.events)
  3721. t.events = new tinymce.dom.EventUtils();
  3722. return t.events.remove(target, name, func);
  3723. },
  3724. _findSib : function(node, selector, name) {
  3725. var t = this, f = selector;
  3726. if (node) {
  3727. // If expression make a function of it using is
  3728. if (is(f, 'string')) {
  3729. f = function(node) {
  3730. return t.is(node, selector);
  3731. };
  3732. }
  3733. // Loop all siblings
  3734. for (node = node[name]; node; node = node[name]) {
  3735. if (f(node))
  3736. return node;
  3737. }
  3738. }
  3739. return null;
  3740. },
  3741. _isRes : function(c) {
  3742. // Is live resizble element
  3743. return /^(top|left|bottom|right|width|height)/i.test(c) || /;\s*(top|left|bottom|right|width|height)/i.test(c);
  3744. }
  3745. /*
  3746. walk : function(n, f, s) {
  3747. var d = this.doc, w;
  3748. if (d.createTreeWalker) {
  3749. w = d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false);
  3750. while ((n = w.nextNode()) != null)
  3751. f.call(s || this, n);
  3752. } else
  3753. tinymce.walk(n, f, 'childNodes', s);
  3754. }
  3755. */
  3756. /*
  3757. toRGB : function(s) {
  3758. var c = /^\s*?#([0-9A-F]{2})([0-9A-F]{1,2})([0-9A-F]{2})?\s*?$/.exec(s);
  3759. if (c) {
  3760. // #FFF -> #FFFFFF
  3761. if (!is(c[3]))
  3762. c[3] = c[2] = c[1];
  3763. return "rgb(" + parseInt(c[1], 16) + "," + parseInt(c[2], 16) + "," + parseInt(c[3], 16) + ")";
  3764. }
  3765. return s;
  3766. }
  3767. */
  3768. });
  3769. tinymce.DOM = new tinymce.dom.DOMUtils(document, {process_html : 0});
  3770. })(tinymce);
  3771. (function(ns) {
  3772. // Range constructor
  3773. function Range(dom) {
  3774. var t = this,
  3775. doc = dom.doc,
  3776. EXTRACT = 0,
  3777. CLONE = 1,
  3778. DELETE = 2,
  3779. TRUE = true,
  3780. FALSE = false,
  3781. START_OFFSET = 'startOffset',
  3782. START_CONTAINER = 'startContainer',
  3783. END_CONTAINER = 'endContainer',
  3784. END_OFFSET = 'endOffset',
  3785. extend = tinymce.extend,
  3786. nodeIndex = dom.nodeIndex;
  3787. extend(t, {
  3788. // Inital states
  3789. startContainer : doc,
  3790. startOffset : 0,
  3791. endContainer : doc,
  3792. endOffset : 0,
  3793. collapsed : TRUE,
  3794. commonAncestorContainer : doc,
  3795. // Range constants
  3796. START_TO_START : 0,
  3797. START_TO_END : 1,
  3798. END_TO_END : 2,
  3799. END_TO_START : 3,
  3800. // Public methods
  3801. setStart : setStart,
  3802. setEnd : setEnd,
  3803. setStartBefore : setStartBefore,
  3804. setStartAfter : setStartAfter,
  3805. setEndBefore : setEndBefore,
  3806. setEndAfter : setEndAfter,
  3807. collapse : collapse,
  3808. selectNode : selectNode,
  3809. selectNodeContents : selectNodeContents,
  3810. compareBoundaryPoints : compareBoundaryPoints,
  3811. deleteContents : deleteContents,
  3812. extractContents : extractContents,
  3813. cloneContents : cloneContents,
  3814. insertNode : insertNode,
  3815. surroundContents : surroundContents,
  3816. cloneRange : cloneRange
  3817. });
  3818. function setStart(n, o) {
  3819. _setEndPoint(TRUE, n, o);
  3820. };
  3821. function setEnd(n, o) {
  3822. _setEndPoint(FALSE, n, o);
  3823. };
  3824. function setStartBefore(n) {
  3825. setStart(n.parentNode, nodeIndex(n));
  3826. };
  3827. function setStartAfter(n) {
  3828. setStart(n.parentNode, nodeIndex(n) + 1);
  3829. };
  3830. function setEndBefore(n) {
  3831. setEnd(n.parentNode, nodeIndex(n));
  3832. };
  3833. function setEndAfter(n) {
  3834. setEnd(n.parentNode, nodeIndex(n) + 1);
  3835. };
  3836. function collapse(ts) {
  3837. if (ts) {
  3838. t[END_CONTAINER] = t[START_CONTAINER];
  3839. t[END_OFFSET] = t[START_OFFSET];
  3840. } else {
  3841. t[START_CONTAINER] = t[END_CONTAINER];
  3842. t[START_OFFSET] = t[END_OFFSET];
  3843. }
  3844. t.collapsed = TRUE;
  3845. };
  3846. function selectNode(n) {
  3847. setStartBefore(n);
  3848. setEndAfter(n);
  3849. };
  3850. function selectNodeContents(n) {
  3851. setStart(n, 0);
  3852. setEnd(n, n.nodeType === 1 ? n.childNodes.length : n.nodeValue.length);
  3853. };
  3854. function compareBoundaryPoints(h, r) {
  3855. var sc = t[START_CONTAINER], so = t[START_OFFSET], ec = t[END_CONTAINER], eo = t[END_OFFSET],
  3856. rsc = r.startContainer, rso = r.startOffset, rec = r.endContainer, reo = r.endOffset;
  3857. // Check START_TO_START
  3858. if (h === 0)
  3859. return _compareBoundaryPoints(sc, so, rsc, rso);
  3860. // Check START_TO_END
  3861. if (h === 1)
  3862. return _compareBoundaryPoints(ec, eo, rsc, rso);
  3863. // Check END_TO_END
  3864. if (h === 2)
  3865. return _compareBoundaryPoints(ec, eo, rec, reo);
  3866. // Check END_TO_START
  3867. if (h === 3)
  3868. return _compareBoundaryPoints(sc, so, rec, reo);
  3869. };
  3870. function deleteContents() {
  3871. _traverse(DELETE);
  3872. };
  3873. function extractContents() {
  3874. return _traverse(EXTRACT);
  3875. };
  3876. function cloneContents() {
  3877. return _traverse(CLONE);
  3878. };
  3879. function insertNode(n) {
  3880. var startContainer = this[START_CONTAINER],
  3881. startOffset = this[START_OFFSET], nn, o;
  3882. // Node is TEXT_NODE or CDATA
  3883. if ((startContainer.nodeType === 3 || startContainer.nodeType === 4) && startContainer.nodeValue) {
  3884. if (!startOffset) {
  3885. // At the start of text
  3886. startContainer.parentNode.insertBefore(n, startContainer);
  3887. } else if (startOffset >= startContainer.nodeValue.length) {
  3888. // At the end of text
  3889. dom.insertAfter(n, startContainer);
  3890. } else {
  3891. // Middle, need to split
  3892. nn = startContainer.splitText(startOffset);
  3893. startContainer.parentNode.insertBefore(n, nn);
  3894. }
  3895. } else {
  3896. // Insert element node
  3897. if (startContainer.childNodes.length > 0)
  3898. o = startContainer.childNodes[startOffset];
  3899. if (o)
  3900. startContainer.insertBefore(n, o);
  3901. else
  3902. startContainer.appendChild(n);
  3903. }
  3904. };
  3905. function surroundContents(n) {
  3906. var f = t.extractContents();
  3907. t.insertNode(n);
  3908. n.appendChild(f);
  3909. t.selectNode(n);
  3910. };
  3911. function cloneRange() {
  3912. return extend(new Range(dom), {
  3913. startContainer : t[START_CONTAINER],
  3914. startOffset : t[START_OFFSET],
  3915. endContainer : t[END_CONTAINER],
  3916. endOffset : t[END_OFFSET],
  3917. collapsed : t.collapsed,
  3918. commonAncestorContainer : t.commonAncestorContainer
  3919. });
  3920. };
  3921. // Private methods
  3922. function _getSelectedNode(container, offset) {
  3923. var child;
  3924. if (container.nodeType == 3 /* TEXT_NODE */)
  3925. return container;
  3926. if (offset < 0)
  3927. return container;
  3928. child = container.firstChild;
  3929. while (child && offset > 0) {
  3930. --offset;
  3931. child = child.nextSibling;
  3932. }
  3933. if (child)
  3934. return child;
  3935. return container;
  3936. };
  3937. function _isCollapsed() {
  3938. return (t[START_CONTAINER] == t[END_CONTAINER] && t[START_OFFSET] == t[END_OFFSET]);
  3939. };
  3940. function _compareBoundaryPoints(containerA, offsetA, containerB, offsetB) {
  3941. var c, offsetC, n, cmnRoot, childA, childB;
  3942. // In the first case the boundary-points have the same container. A is before B
  3943. // if its offset is less than the offset of B, A is equal to B if its offset is
  3944. // equal to the offset of B, and A is after B if its offset is greater than the
  3945. // offset of B.
  3946. if (containerA == containerB) {
  3947. if (offsetA == offsetB)
  3948. return 0; // equal
  3949. if (offsetA < offsetB)
  3950. return -1; // before
  3951. return 1; // after
  3952. }
  3953. // In the second case a child node C of the container of A is an ancestor
  3954. // container of B. In this case, A is before B if the offset of A is less than or
  3955. // equal to the index of the child node C and A is after B otherwise.
  3956. c = containerB;
  3957. while (c && c.parentNode != containerA)
  3958. c = c.parentNode;
  3959. if (c) {
  3960. offsetC = 0;
  3961. n = containerA.firstChild;
  3962. while (n != c && offsetC < offsetA) {
  3963. offsetC++;
  3964. n = n.nextSibling;
  3965. }
  3966. if (offsetA <= offsetC)
  3967. return -1; // before
  3968. return 1; // after
  3969. }
  3970. // In the third case a child node C of the container of B is an ancestor container
  3971. // of A. In this case, A is before B if the index of the child node C is less than
  3972. // the offset of B and A is after B otherwise.
  3973. c = containerA;
  3974. while (c && c.parentNode != containerB) {
  3975. c = c.parentNode;
  3976. }
  3977. if (c) {
  3978. offsetC = 0;
  3979. n = containerB.firstChild;
  3980. while (n != c && offsetC < offsetB) {
  3981. offsetC++;
  3982. n = n.nextSibling;
  3983. }
  3984. if (offsetC < offsetB)
  3985. return -1; // before
  3986. return 1; // after
  3987. }
  3988. // In the fourth case, none of three other cases hold: the containers of A and B
  3989. // are siblings or descendants of sibling nodes. In this case, A is before B if
  3990. // the container of A is before the container of B in a pre-order traversal of the
  3991. // Ranges' context tree and A is after B otherwise.
  3992. cmnRoot = dom.findCommonAncestor(containerA, containerB);
  3993. childA = containerA;
  3994. while (childA && childA.parentNode != cmnRoot)
  3995. childA = childA.parentNode;
  3996. if (!childA)
  3997. childA = cmnRoot;
  3998. childB = containerB;
  3999. while (childB && childB.parentNode != cmnRoot)
  4000. childB = childB.parentNode;
  4001. if (!childB)
  4002. childB = cmnRoot;
  4003. if (childA == childB)
  4004. return 0; // equal
  4005. n = cmnRoot.firstChild;
  4006. while (n) {
  4007. if (n == childA)
  4008. return -1; // before
  4009. if (n == childB)
  4010. return 1; // after
  4011. n = n.nextSibling;
  4012. }
  4013. };
  4014. function _setEndPoint(st, n, o) {
  4015. var ec, sc;
  4016. if (st) {
  4017. t[START_CONTAINER] = n;
  4018. t[START_OFFSET] = o;
  4019. } else {
  4020. t[END_CONTAINER] = n;
  4021. t[END_OFFSET] = o;
  4022. }
  4023. // If one boundary-point of a Range is set to have a root container
  4024. // other than the current one for the Range, the Range is collapsed to
  4025. // the new position. This enforces the restriction that both boundary-
  4026. // points of a Range must have the same root container.
  4027. ec = t[END_CONTAINER];
  4028. while (ec.parentNode)
  4029. ec = ec.parentNode;
  4030. sc = t[START_CONTAINER];
  4031. while (sc.parentNode)
  4032. sc = sc.parentNode;
  4033. if (sc == ec) {
  4034. // The start position of a Range is guaranteed to never be after the
  4035. // end position. To enforce this restriction, if the start is set to
  4036. // be at a position after the end, the Range is collapsed to that
  4037. // position.
  4038. if (_compareBoundaryPoints(t[START_CONTAINER], t[START_OFFSET], t[END_CONTAINER], t[END_OFFSET]) > 0)
  4039. t.collapse(st);
  4040. } else
  4041. t.collapse(st);
  4042. t.collapsed = _isCollapsed();
  4043. t.commonAncestorContainer = dom.findCommonAncestor(t[START_CONTAINER], t[END_CONTAINER]);
  4044. };
  4045. function _traverse(how) {
  4046. var c, endContainerDepth = 0, startContainerDepth = 0, p, depthDiff, startNode, endNode, sp, ep;
  4047. if (t[START_CONTAINER] == t[END_CONTAINER])
  4048. return _traverseSameContainer(how);
  4049. for (c = t[END_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  4050. if (p == t[START_CONTAINER])
  4051. return _traverseCommonStartContainer(c, how);
  4052. ++endContainerDepth;
  4053. }
  4054. for (c = t[START_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  4055. if (p == t[END_CONTAINER])
  4056. return _traverseCommonEndContainer(c, how);
  4057. ++startContainerDepth;
  4058. }
  4059. depthDiff = startContainerDepth - endContainerDepth;
  4060. startNode = t[START_CONTAINER];
  4061. while (depthDiff > 0) {
  4062. startNode = startNode.parentNode;
  4063. depthDiff--;
  4064. }
  4065. endNode = t[END_CONTAINER];
  4066. while (depthDiff < 0) {
  4067. endNode = endNode.parentNode;
  4068. depthDiff++;
  4069. }
  4070. // ascend the ancestor hierarchy until we have a common parent.
  4071. for (sp = startNode.parentNode, ep = endNode.parentNode; sp != ep; sp = sp.parentNode, ep = ep.parentNode) {
  4072. startNode = sp;
  4073. endNode = ep;
  4074. }
  4075. return _traverseCommonAncestors(startNode, endNode, how);
  4076. };
  4077. function _traverseSameContainer(how) {
  4078. var frag, s, sub, n, cnt, sibling, xferNode;
  4079. if (how != DELETE)
  4080. frag = doc.createDocumentFragment();
  4081. // If selection is empty, just return the fragment
  4082. if (t[START_OFFSET] == t[END_OFFSET])
  4083. return frag;
  4084. // Text node needs special case handling
  4085. if (t[START_CONTAINER].nodeType == 3 /* TEXT_NODE */) {
  4086. // get the substring
  4087. s = t[START_CONTAINER].nodeValue;
  4088. sub = s.substring(t[START_OFFSET], t[END_OFFSET]);
  4089. // set the original text node to its new value
  4090. if (how != CLONE) {
  4091. t[START_CONTAINER].deleteData(t[START_OFFSET], t[END_OFFSET] - t[START_OFFSET]);
  4092. // Nothing is partially selected, so collapse to start point
  4093. t.collapse(TRUE);
  4094. }
  4095. if (how == DELETE)
  4096. return;
  4097. frag.appendChild(doc.createTextNode(sub));
  4098. return frag;
  4099. }
  4100. // Copy nodes between the start/end offsets.
  4101. n = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]);
  4102. cnt = t[END_OFFSET] - t[START_OFFSET];
  4103. while (cnt > 0) {
  4104. sibling = n.nextSibling;
  4105. xferNode = _traverseFullySelected(n, how);
  4106. if (frag)
  4107. frag.appendChild( xferNode );
  4108. --cnt;
  4109. n = sibling;
  4110. }
  4111. // Nothing is partially selected, so collapse to start point
  4112. if (how != CLONE)
  4113. t.collapse(TRUE);
  4114. return frag;
  4115. };
  4116. function _traverseCommonStartContainer(endAncestor, how) {
  4117. var frag, n, endIdx, cnt, sibling, xferNode;
  4118. if (how != DELETE)
  4119. frag = doc.createDocumentFragment();
  4120. n = _traverseRightBoundary(endAncestor, how);
  4121. if (frag)
  4122. frag.appendChild(n);
  4123. endIdx = nodeIndex(endAncestor);
  4124. cnt = endIdx - t[START_OFFSET];
  4125. if (cnt <= 0) {
  4126. // Collapse to just before the endAncestor, which
  4127. // is partially selected.
  4128. if (how != CLONE) {
  4129. t.setEndBefore(endAncestor);
  4130. t.collapse(FALSE);
  4131. }
  4132. return frag;
  4133. }
  4134. n = endAncestor.previousSibling;
  4135. while (cnt > 0) {
  4136. sibling = n.previousSibling;
  4137. xferNode = _traverseFullySelected(n, how);
  4138. if (frag)
  4139. frag.insertBefore(xferNode, frag.firstChild);
  4140. --cnt;
  4141. n = sibling;
  4142. }
  4143. // Collapse to just before the endAncestor, which
  4144. // is partially selected.
  4145. if (how != CLONE) {
  4146. t.setEndBefore(endAncestor);
  4147. t.collapse(FALSE);
  4148. }
  4149. return frag;
  4150. };
  4151. function _traverseCommonEndContainer(startAncestor, how) {
  4152. var frag, startIdx, n, cnt, sibling, xferNode;
  4153. if (how != DELETE)
  4154. frag = doc.createDocumentFragment();
  4155. n = _traverseLeftBoundary(startAncestor, how);
  4156. if (frag)
  4157. frag.appendChild(n);
  4158. startIdx = nodeIndex(startAncestor);
  4159. ++startIdx; // Because we already traversed it
  4160. cnt = t[END_OFFSET] - startIdx;
  4161. n = startAncestor.nextSibling;
  4162. while (cnt > 0) {
  4163. sibling = n.nextSibling;
  4164. xferNode = _traverseFullySelected(n, how);
  4165. if (frag)
  4166. frag.appendChild(xferNode);
  4167. --cnt;
  4168. n = sibling;
  4169. }
  4170. if (how != CLONE) {
  4171. t.setStartAfter(startAncestor);
  4172. t.collapse(TRUE);
  4173. }
  4174. return frag;
  4175. };
  4176. function _traverseCommonAncestors(startAncestor, endAncestor, how) {
  4177. var n, frag, commonParent, startOffset, endOffset, cnt, sibling, nextSibling;
  4178. if (how != DELETE)
  4179. frag = doc.createDocumentFragment();
  4180. n = _traverseLeftBoundary(startAncestor, how);
  4181. if (frag)
  4182. frag.appendChild(n);
  4183. commonParent = startAncestor.parentNode;
  4184. startOffset = nodeIndex(startAncestor);
  4185. endOffset = nodeIndex(endAncestor);
  4186. ++startOffset;
  4187. cnt = endOffset - startOffset;
  4188. sibling = startAncestor.nextSibling;
  4189. while (cnt > 0) {
  4190. nextSibling = sibling.nextSibling;
  4191. n = _traverseFullySelected(sibling, how);
  4192. if (frag)
  4193. frag.appendChild(n);
  4194. sibling = nextSibling;
  4195. --cnt;
  4196. }
  4197. n = _traverseRightBoundary(endAncestor, how);
  4198. if (frag)
  4199. frag.appendChild(n);
  4200. if (how != CLONE) {
  4201. t.setStartAfter(startAncestor);
  4202. t.collapse(TRUE);
  4203. }
  4204. return frag;
  4205. };
  4206. function _traverseRightBoundary(root, how) {
  4207. var next = _getSelectedNode(t[END_CONTAINER], t[END_OFFSET] - 1), parent, clonedParent, prevSibling, clonedChild, clonedGrandParent, isFullySelected = next != t[END_CONTAINER];
  4208. if (next == root)
  4209. return _traverseNode(next, isFullySelected, FALSE, how);
  4210. parent = next.parentNode;
  4211. clonedParent = _traverseNode(parent, FALSE, FALSE, how);
  4212. while (parent) {
  4213. while (next) {
  4214. prevSibling = next.previousSibling;
  4215. clonedChild = _traverseNode(next, isFullySelected, FALSE, how);
  4216. if (how != DELETE)
  4217. clonedParent.insertBefore(clonedChild, clonedParent.firstChild);
  4218. isFullySelected = TRUE;
  4219. next = prevSibling;
  4220. }
  4221. if (parent == root)
  4222. return clonedParent;
  4223. next = parent.previousSibling;
  4224. parent = parent.parentNode;
  4225. clonedGrandParent = _traverseNode(parent, FALSE, FALSE, how);
  4226. if (how != DELETE)
  4227. clonedGrandParent.appendChild(clonedParent);
  4228. clonedParent = clonedGrandParent;
  4229. }
  4230. };
  4231. function _traverseLeftBoundary(root, how) {
  4232. var next = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]), isFullySelected = next != t[START_CONTAINER], parent, clonedParent, nextSibling, clonedChild, clonedGrandParent;
  4233. if (next == root)
  4234. return _traverseNode(next, isFullySelected, TRUE, how);
  4235. parent = next.parentNode;
  4236. clonedParent = _traverseNode(parent, FALSE, TRUE, how);
  4237. while (parent) {
  4238. while (next) {
  4239. nextSibling = next.nextSibling;
  4240. clonedChild = _traverseNode(next, isFullySelected, TRUE, how);
  4241. if (how != DELETE)
  4242. clonedParent.appendChild(clonedChild);
  4243. isFullySelected = TRUE;
  4244. next = nextSibling;
  4245. }
  4246. if (parent == root)
  4247. return clonedParent;
  4248. next = parent.nextSibling;
  4249. parent = parent.parentNode;
  4250. clonedGrandParent = _traverseNode(parent, FALSE, TRUE, how);
  4251. if (how != DELETE)
  4252. clonedGrandParent.appendChild(clonedParent);
  4253. clonedParent = clonedGrandParent;
  4254. }
  4255. };
  4256. function _traverseNode(n, isFullySelected, isLeft, how) {
  4257. var txtValue, newNodeValue, oldNodeValue, offset, newNode;
  4258. if (isFullySelected)
  4259. return _traverseFullySelected(n, how);
  4260. if (n.nodeType == 3 /* TEXT_NODE */) {
  4261. txtValue = n.nodeValue;
  4262. if (isLeft) {
  4263. offset = t[START_OFFSET];
  4264. newNodeValue = txtValue.substring(offset);
  4265. oldNodeValue = txtValue.substring(0, offset);
  4266. } else {
  4267. offset = t[END_OFFSET];
  4268. newNodeValue = txtValue.substring(0, offset);
  4269. oldNodeValue = txtValue.substring(offset);
  4270. }
  4271. if (how != CLONE)
  4272. n.nodeValue = oldNodeValue;
  4273. if (how == DELETE)
  4274. return;
  4275. newNode = n.cloneNode(FALSE);
  4276. newNode.nodeValue = newNodeValue;
  4277. return newNode;
  4278. }
  4279. if (how == DELETE)
  4280. return;
  4281. return n.cloneNode(FALSE);
  4282. };
  4283. function _traverseFullySelected(n, how) {
  4284. if (how != DELETE)
  4285. return how == CLONE ? n.cloneNode(TRUE) : n;
  4286. n.parentNode.removeChild(n);
  4287. };
  4288. };
  4289. ns.Range = Range;
  4290. })(tinymce.dom);
  4291. (function() {
  4292. function Selection(selection) {
  4293. var self = this, dom = selection.dom, TRUE = true, FALSE = false;
  4294. function getPosition(rng, start) {
  4295. var checkRng, startIndex = 0, endIndex, inside,
  4296. children, child, offset, index, position = -1, parent;
  4297. // Setup test range, collapse it and get the parent
  4298. checkRng = rng.duplicate();
  4299. checkRng.collapse(start);
  4300. parent = checkRng.parentElement();
  4301. // Check if the selection is within the right document
  4302. if (parent.ownerDocument !== selection.dom.doc)
  4303. return;
  4304. // IE will report non editable elements as it's parent so look for an editable one
  4305. while (parent.contentEditable === "false") {
  4306. parent = parent.parentNode;
  4307. }
  4308. // If parent doesn't have any children then return that we are inside the element
  4309. if (!parent.hasChildNodes()) {
  4310. return {node : parent, inside : 1};
  4311. }
  4312. // Setup node list and endIndex
  4313. children = parent.children;
  4314. endIndex = children.length - 1;
  4315. // Perform a binary search for the position
  4316. while (startIndex <= endIndex) {
  4317. index = Math.floor((startIndex + endIndex) / 2);
  4318. // Move selection to node and compare the ranges
  4319. child = children[index];
  4320. checkRng.moveToElementText(child);
  4321. position = checkRng.compareEndPoints(start ? 'StartToStart' : 'EndToEnd', rng);
  4322. // Before/after or an exact match
  4323. if (position > 0) {
  4324. endIndex = index - 1;
  4325. } else if (position < 0) {
  4326. startIndex = index + 1;
  4327. } else {
  4328. return {node : child};
  4329. }
  4330. }
  4331. // Check if child position is before or we didn't find a position
  4332. if (position < 0) {
  4333. // No element child was found use the parent element and the offset inside that
  4334. if (!child) {
  4335. checkRng.moveToElementText(parent);
  4336. checkRng.collapse(true);
  4337. child = parent;
  4338. inside = true;
  4339. } else
  4340. checkRng.collapse(false);
  4341. checkRng.setEndPoint(start ? 'EndToStart' : 'EndToEnd', rng);
  4342. // Fix for edge case: <div style="width: 100px; height:100px;"><table>..</table>ab|c</div>
  4343. if (checkRng.compareEndPoints(start ? 'StartToStart' : 'StartToEnd', rng) > 0) {
  4344. checkRng = rng.duplicate();
  4345. checkRng.collapse(start);
  4346. offset = -1;
  4347. while (parent == checkRng.parentElement()) {
  4348. if (checkRng.move('character', -1) == 0)
  4349. break;
  4350. offset++;
  4351. }
  4352. }
  4353. offset = offset || checkRng.text.replace('\r\n', ' ').length;
  4354. } else {
  4355. // Child position is after the selection endpoint
  4356. checkRng.collapse(true);
  4357. checkRng.setEndPoint(start ? 'StartToStart' : 'StartToEnd', rng);
  4358. // Get the length of the text to find where the endpoint is relative to it's container
  4359. offset = checkRng.text.replace('\r\n', ' ').length;
  4360. }
  4361. return {node : child, position : position, offset : offset, inside : inside};
  4362. };
  4363. // Returns a W3C DOM compatible range object by using the IE Range API
  4364. function getRange() {
  4365. var ieRange = selection.getRng(), domRange = dom.createRng(), element, collapsed, tmpRange, element2, bookmark, fail;
  4366. // If selection is outside the current document just return an empty range
  4367. element = ieRange.item ? ieRange.item(0) : ieRange.parentElement();
  4368. if (element.ownerDocument != dom.doc)
  4369. return domRange;
  4370. collapsed = selection.isCollapsed();
  4371. // Handle control selection
  4372. if (ieRange.item) {
  4373. domRange.setStart(element.parentNode, dom.nodeIndex(element));
  4374. domRange.setEnd(domRange.startContainer, domRange.startOffset + 1);
  4375. return domRange;
  4376. }
  4377. function findEndPoint(start) {
  4378. var endPoint = getPosition(ieRange, start), container, offset, textNodeOffset = 0, sibling, undef, nodeValue;
  4379. container = endPoint.node;
  4380. offset = endPoint.offset;
  4381. if (endPoint.inside && !container.hasChildNodes()) {
  4382. domRange[start ? 'setStart' : 'setEnd'](container, 0);
  4383. return;
  4384. }
  4385. if (offset === undef) {
  4386. domRange[start ? 'setStartBefore' : 'setEndAfter'](container);
  4387. return;
  4388. }
  4389. if (endPoint.position < 0) {
  4390. sibling = endPoint.inside ? container.firstChild : container.nextSibling;
  4391. if (!sibling) {
  4392. domRange[start ? 'setStartAfter' : 'setEndAfter'](container);
  4393. return;
  4394. }
  4395. if (!offset) {
  4396. if (sibling.nodeType == 3)
  4397. domRange[start ? 'setStart' : 'setEnd'](sibling, 0);
  4398. else
  4399. domRange[start ? 'setStartBefore' : 'setEndBefore'](sibling);
  4400. return;
  4401. }
  4402. // Find the text node and offset
  4403. while (sibling) {
  4404. nodeValue = sibling.nodeValue;
  4405. textNodeOffset += nodeValue.length;
  4406. // We are at or passed the position we where looking for
  4407. if (textNodeOffset >= offset) {
  4408. container = sibling;
  4409. textNodeOffset -= offset;
  4410. textNodeOffset = nodeValue.length - textNodeOffset;
  4411. break;
  4412. }
  4413. sibling = sibling.nextSibling;
  4414. }
  4415. } else {
  4416. // Find the text node and offset
  4417. sibling = container.previousSibling;
  4418. if (!sibling)
  4419. return domRange[start ? 'setStartBefore' : 'setEndBefore'](container);
  4420. // If there isn't any text to loop then use the first position
  4421. if (!offset) {
  4422. if (container.nodeType == 3)
  4423. domRange[start ? 'setStart' : 'setEnd'](sibling, container.nodeValue.length);
  4424. else
  4425. domRange[start ? 'setStartAfter' : 'setEndAfter'](sibling);
  4426. return;
  4427. }
  4428. while (sibling) {
  4429. textNodeOffset += sibling.nodeValue.length;
  4430. // We are at or passed the position we where looking for
  4431. if (textNodeOffset >= offset) {
  4432. container = sibling;
  4433. textNodeOffset -= offset;
  4434. break;
  4435. }
  4436. sibling = sibling.previousSibling;
  4437. }
  4438. }
  4439. domRange[start ? 'setStart' : 'setEnd'](container, textNodeOffset);
  4440. };
  4441. try {
  4442. // Find start point
  4443. findEndPoint(true);
  4444. // Find end point if needed
  4445. if (!collapsed)
  4446. findEndPoint();
  4447. } catch (ex) {
  4448. // IE has a nasty bug where text nodes might throw "invalid argument" when you
  4449. // access the nodeValue or other properties of text nodes. This seems to happend when
  4450. // text nodes are split into two nodes by a delete/backspace call. So lets detect it and try to fix it.
  4451. if (ex.number == -2147024809) {
  4452. // Get the current selection
  4453. bookmark = self.getBookmark(2);
  4454. // Get start element
  4455. tmpRange = ieRange.duplicate();
  4456. tmpRange.collapse(true);
  4457. element = tmpRange.parentElement();
  4458. // Get end element
  4459. if (!collapsed) {
  4460. tmpRange = ieRange.duplicate();
  4461. tmpRange.collapse(false);
  4462. element2 = tmpRange.parentElement();
  4463. element2.innerHTML = element2.innerHTML;
  4464. }
  4465. // Remove the broken elements
  4466. element.innerHTML = element.innerHTML;
  4467. // Restore the selection
  4468. self.moveToBookmark(bookmark);
  4469. // Since the range has moved we need to re-get it
  4470. ieRange = selection.getRng();
  4471. // Find start point
  4472. findEndPoint(true);
  4473. // Find end point if needed
  4474. if (!collapsed)
  4475. findEndPoint();
  4476. } else
  4477. throw ex; // Throw other errors
  4478. }
  4479. return domRange;
  4480. };
  4481. this.getBookmark = function(type) {
  4482. var rng = selection.getRng(), start, end, bookmark = {};
  4483. function getIndexes(node) {
  4484. var node, parent, root, children, i, indexes = [];
  4485. parent = node.parentNode;
  4486. root = dom.getRoot().parentNode;
  4487. while (parent != root && parent.nodeType !== 9) {
  4488. children = parent.children;
  4489. i = children.length;
  4490. while (i--) {
  4491. if (node === children[i]) {
  4492. indexes.push(i);
  4493. break;
  4494. }
  4495. }
  4496. node = parent;
  4497. parent = parent.parentNode;
  4498. }
  4499. return indexes;
  4500. };
  4501. function getBookmarkEndPoint(start) {
  4502. var position;
  4503. position = getPosition(rng, start);
  4504. if (position) {
  4505. return {
  4506. position : position.position,
  4507. offset : position.offset,
  4508. indexes : getIndexes(position.node),
  4509. inside : position.inside
  4510. };
  4511. }
  4512. };
  4513. // Non ubstructive bookmark
  4514. if (type === 2) {
  4515. // Handle text selection
  4516. if (!rng.item) {
  4517. bookmark.start = getBookmarkEndPoint(true);
  4518. if (!selection.isCollapsed())
  4519. bookmark.end = getBookmarkEndPoint();
  4520. } else
  4521. bookmark.start = {ctrl : true, indexes : getIndexes(rng.item(0))};
  4522. }
  4523. return bookmark;
  4524. };
  4525. this.moveToBookmark = function(bookmark) {
  4526. var rng, body = dom.doc.body;
  4527. function resolveIndexes(indexes) {
  4528. var node, i, idx, children;
  4529. node = dom.getRoot();
  4530. for (i = indexes.length - 1; i >= 0; i--) {
  4531. children = node.children;
  4532. idx = indexes[i];
  4533. if (idx <= children.length - 1) {
  4534. node = children[idx];
  4535. }
  4536. }
  4537. return node;
  4538. };
  4539. function setBookmarkEndPoint(start) {
  4540. var endPoint = bookmark[start ? 'start' : 'end'], moveLeft, moveRng, undef;
  4541. if (endPoint) {
  4542. moveLeft = endPoint.position > 0;
  4543. moveRng = body.createTextRange();
  4544. moveRng.moveToElementText(resolveIndexes(endPoint.indexes));
  4545. offset = endPoint.offset;
  4546. if (offset !== undef) {
  4547. moveRng.collapse(endPoint.inside || moveLeft);
  4548. moveRng.moveStart('character', moveLeft ? -offset : offset);
  4549. } else
  4550. moveRng.collapse(start);
  4551. rng.setEndPoint(start ? 'StartToStart' : 'EndToStart', moveRng);
  4552. if (start)
  4553. rng.collapse(true);
  4554. }
  4555. };
  4556. if (bookmark.start) {
  4557. if (bookmark.start.ctrl) {
  4558. rng = body.createControlRange();
  4559. rng.addElement(resolveIndexes(bookmark.start.indexes));
  4560. rng.select();
  4561. } else {
  4562. rng = body.createTextRange();
  4563. setBookmarkEndPoint(true);
  4564. setBookmarkEndPoint();
  4565. rng.select();
  4566. }
  4567. }
  4568. };
  4569. this.addRange = function(rng) {
  4570. var ieRng, ctrlRng, startContainer, startOffset, endContainer, endOffset, doc = selection.dom.doc, body = doc.body;
  4571. function setEndPoint(start) {
  4572. var container, offset, marker, tmpRng, nodes;
  4573. marker = dom.create('a');
  4574. container = start ? startContainer : endContainer;
  4575. offset = start ? startOffset : endOffset;
  4576. tmpRng = ieRng.duplicate();
  4577. if (container == doc || container == doc.documentElement) {
  4578. container = body;
  4579. offset = 0;
  4580. }
  4581. if (container.nodeType == 3) {
  4582. container.parentNode.insertBefore(marker, container);
  4583. tmpRng.moveToElementText(marker);
  4584. tmpRng.moveStart('character', offset);
  4585. dom.remove(marker);
  4586. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  4587. } else {
  4588. nodes = container.childNodes;
  4589. if (nodes.length) {
  4590. if (offset >= nodes.length) {
  4591. dom.insertAfter(marker, nodes[nodes.length - 1]);
  4592. } else {
  4593. container.insertBefore(marker, nodes[offset]);
  4594. }
  4595. tmpRng.moveToElementText(marker);
  4596. } else {
  4597. // Empty node selection for example <div>|</div>
  4598. marker = doc.createTextNode('\uFEFF');
  4599. container.appendChild(marker);
  4600. tmpRng.moveToElementText(marker.parentNode);
  4601. tmpRng.collapse(TRUE);
  4602. }
  4603. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  4604. dom.remove(marker);
  4605. }
  4606. }
  4607. // Setup some shorter versions
  4608. startContainer = rng.startContainer;
  4609. startOffset = rng.startOffset;
  4610. endContainer = rng.endContainer;
  4611. endOffset = rng.endOffset;
  4612. ieRng = body.createTextRange();
  4613. // If single element selection then try making a control selection out of it
  4614. if (startContainer == endContainer && startContainer.nodeType == 1 && startOffset == endOffset - 1) {
  4615. if (startOffset == endOffset - 1) {
  4616. try {
  4617. ctrlRng = body.createControlRange();
  4618. ctrlRng.addElement(startContainer.childNodes[startOffset]);
  4619. ctrlRng.select();
  4620. return;
  4621. } catch (ex) {
  4622. // Ignore
  4623. }
  4624. }
  4625. }
  4626. // Set start/end point of selection
  4627. setEndPoint(true);
  4628. setEndPoint();
  4629. // Select the new range and scroll it into view
  4630. ieRng.select();
  4631. };
  4632. // Expose range method
  4633. this.getRangeAt = getRange;
  4634. };
  4635. // Expose the selection object
  4636. tinymce.dom.TridentSelection = Selection;
  4637. })();
  4638. /*
  4639. * Sizzle CSS Selector Engine - v1.0
  4640. * Copyright 2009, The Dojo Foundation
  4641. * Released under the MIT, BSD, and GPL Licenses.
  4642. * More information: http://sizzlejs.com/
  4643. */
  4644. (function(){
  4645. var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
  4646. done = 0,
  4647. toString = Object.prototype.toString,
  4648. hasDuplicate = false,
  4649. baseHasDuplicate = true;
  4650. // Here we check if the JavaScript engine is using some sort of
  4651. // optimization where it does not always call our comparision
  4652. // function. If that is the case, discard the hasDuplicate value.
  4653. // Thus far that includes Google Chrome.
  4654. [0, 0].sort(function(){
  4655. baseHasDuplicate = false;
  4656. return 0;
  4657. });
  4658. var Sizzle = function(selector, context, results, seed) {
  4659. results = results || [];
  4660. context = context || document;
  4661. var origContext = context;
  4662. if ( context.nodeType !== 1 && context.nodeType !== 9 ) {
  4663. return [];
  4664. }
  4665. if ( !selector || typeof selector !== "string" ) {
  4666. return results;
  4667. }
  4668. var parts = [], m, set, checkSet, extra, prune = true, contextXML = Sizzle.isXML(context),
  4669. soFar = selector, ret, cur, pop, i;
  4670. // Reset the position of the chunker regexp (start from head)
  4671. do {
  4672. chunker.exec("");
  4673. m = chunker.exec(soFar);
  4674. if ( m ) {
  4675. soFar = m[3];
  4676. parts.push( m[1] );
  4677. if ( m[2] ) {
  4678. extra = m[3];
  4679. break;
  4680. }
  4681. }
  4682. } while ( m );
  4683. if ( parts.length > 1 && origPOS.exec( selector ) ) {
  4684. if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {
  4685. set = posProcess( parts[0] + parts[1], context );
  4686. } else {
  4687. set = Expr.relative[ parts[0] ] ?
  4688. [ context ] :
  4689. Sizzle( parts.shift(), context );
  4690. while ( parts.length ) {
  4691. selector = parts.shift();
  4692. if ( Expr.relative[ selector ] ) {
  4693. selector += parts.shift();
  4694. }
  4695. set = posProcess( selector, set );
  4696. }
  4697. }
  4698. } else {
  4699. // Take a shortcut and set the context if the root selector is an ID
  4700. // (but not if it'll be faster if the inner selector is an ID)
  4701. if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML &&
  4702. Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) {
  4703. ret = Sizzle.find( parts.shift(), context, contextXML );
  4704. context = ret.expr ? Sizzle.filter( ret.expr, ret.set )[0] : ret.set[0];
  4705. }
  4706. if ( context ) {
  4707. ret = seed ?
  4708. { expr: parts.pop(), set: makeArray(seed) } :
  4709. Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML );
  4710. set = ret.expr ? Sizzle.filter( ret.expr, ret.set ) : ret.set;
  4711. if ( parts.length > 0 ) {
  4712. checkSet = makeArray(set);
  4713. } else {
  4714. prune = false;
  4715. }
  4716. while ( parts.length ) {
  4717. cur = parts.pop();
  4718. pop = cur;
  4719. if ( !Expr.relative[ cur ] ) {
  4720. cur = "";
  4721. } else {
  4722. pop = parts.pop();
  4723. }
  4724. if ( pop == null ) {
  4725. pop = context;
  4726. }
  4727. Expr.relative[ cur ]( checkSet, pop, contextXML );
  4728. }
  4729. } else {
  4730. checkSet = parts = [];
  4731. }
  4732. }
  4733. if ( !checkSet ) {
  4734. checkSet = set;
  4735. }
  4736. if ( !checkSet ) {
  4737. Sizzle.error( cur || selector );
  4738. }
  4739. if ( toString.call(checkSet) === "[object Array]" ) {
  4740. if ( !prune ) {
  4741. results.push.apply( results, checkSet );
  4742. } else if ( context && context.nodeType === 1 ) {
  4743. for ( i = 0; checkSet[i] != null; i++ ) {
  4744. if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && Sizzle.contains(context, checkSet[i])) ) {
  4745. results.push( set[i] );
  4746. }
  4747. }
  4748. } else {
  4749. for ( i = 0; checkSet[i] != null; i++ ) {
  4750. if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
  4751. results.push( set[i] );
  4752. }
  4753. }
  4754. }
  4755. } else {
  4756. makeArray( checkSet, results );
  4757. }
  4758. if ( extra ) {
  4759. Sizzle( extra, origContext, results, seed );
  4760. Sizzle.uniqueSort( results );
  4761. }
  4762. return results;
  4763. };
  4764. Sizzle.uniqueSort = function(results){
  4765. if ( sortOrder ) {
  4766. hasDuplicate = baseHasDuplicate;
  4767. results.sort(sortOrder);
  4768. if ( hasDuplicate ) {
  4769. for ( var i = 1; i < results.length; i++ ) {
  4770. if ( results[i] === results[i-1] ) {
  4771. results.splice(i--, 1);
  4772. }
  4773. }
  4774. }
  4775. }
  4776. return results;
  4777. };
  4778. Sizzle.matches = function(expr, set){
  4779. return Sizzle(expr, null, null, set);
  4780. };
  4781. Sizzle.find = function(expr, context, isXML){
  4782. var set;
  4783. if ( !expr ) {
  4784. return [];
  4785. }
  4786. for ( var i = 0, l = Expr.order.length; i < l; i++ ) {
  4787. var type = Expr.order[i], match;
  4788. if ( (match = Expr.leftMatch[ type ].exec( expr )) ) {
  4789. var left = match[1];
  4790. match.splice(1,1);
  4791. if ( left.substr( left.length - 1 ) !== "\\" ) {
  4792. match[1] = (match[1] || "").replace(/\\/g, "");
  4793. set = Expr.find[ type ]( match, context, isXML );
  4794. if ( set != null ) {
  4795. expr = expr.replace( Expr.match[ type ], "" );
  4796. break;
  4797. }
  4798. }
  4799. }
  4800. }
  4801. if ( !set ) {
  4802. set = context.getElementsByTagName("*");
  4803. }
  4804. return {set: set, expr: expr};
  4805. };
  4806. Sizzle.filter = function(expr, set, inplace, not){
  4807. var old = expr, result = [], curLoop = set, match, anyFound,
  4808. isXMLFilter = set && set[0] && Sizzle.isXML(set[0]);
  4809. while ( expr && set.length ) {
  4810. for ( var type in Expr.filter ) {
  4811. if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {
  4812. var filter = Expr.filter[ type ], found, item, left = match[1];
  4813. anyFound = false;
  4814. match.splice(1,1);
  4815. if ( left.substr( left.length - 1 ) === "\\" ) {
  4816. continue;
  4817. }
  4818. if ( curLoop === result ) {
  4819. result = [];
  4820. }
  4821. if ( Expr.preFilter[ type ] ) {
  4822. match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter );
  4823. if ( !match ) {
  4824. anyFound = found = true;
  4825. } else if ( match === true ) {
  4826. continue;
  4827. }
  4828. }
  4829. if ( match ) {
  4830. for ( var i = 0; (item = curLoop[i]) != null; i++ ) {
  4831. if ( item ) {
  4832. found = filter( item, match, i, curLoop );
  4833. var pass = not ^ !!found;
  4834. if ( inplace && found != null ) {
  4835. if ( pass ) {
  4836. anyFound = true;
  4837. } else {
  4838. curLoop[i] = false;
  4839. }
  4840. } else if ( pass ) {
  4841. result.push( item );
  4842. anyFound = true;
  4843. }
  4844. }
  4845. }
  4846. }
  4847. if ( found !== undefined ) {
  4848. if ( !inplace ) {
  4849. curLoop = result;
  4850. }
  4851. expr = expr.replace( Expr.match[ type ], "" );
  4852. if ( !anyFound ) {
  4853. return [];
  4854. }
  4855. break;
  4856. }
  4857. }
  4858. }
  4859. // Improper expression
  4860. if ( expr === old ) {
  4861. if ( anyFound == null ) {
  4862. Sizzle.error( expr );
  4863. } else {
  4864. break;
  4865. }
  4866. }
  4867. old = expr;
  4868. }
  4869. return curLoop;
  4870. };
  4871. Sizzle.error = function( msg ) {
  4872. throw "Syntax error, unrecognized expression: " + msg;
  4873. };
  4874. var Expr = Sizzle.selectors = {
  4875. order: [ "ID", "NAME", "TAG" ],
  4876. match: {
  4877. ID: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
  4878. CLASS: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
  4879. NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,
  4880. ATTR: /\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/,
  4881. TAG: /^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,
  4882. CHILD: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+\-]*)\))?/,
  4883. POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,
  4884. PSEUDO: /:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/
  4885. },
  4886. leftMatch: {},
  4887. attrMap: {
  4888. "class": "className",
  4889. "for": "htmlFor"
  4890. },
  4891. attrHandle: {
  4892. href: function(elem){
  4893. return elem.getAttribute("href");
  4894. }
  4895. },
  4896. relative: {
  4897. "+": function(checkSet, part){
  4898. var isPartStr = typeof part === "string",
  4899. isTag = isPartStr && !/\W/.test(part),
  4900. isPartStrNotTag = isPartStr && !isTag;
  4901. if ( isTag ) {
  4902. part = part.toLowerCase();
  4903. }
  4904. for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) {
  4905. if ( (elem = checkSet[i]) ) {
  4906. while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}
  4907. checkSet[i] = isPartStrNotTag || elem && elem.nodeName.toLowerCase() === part ?
  4908. elem || false :
  4909. elem === part;
  4910. }
  4911. }
  4912. if ( isPartStrNotTag ) {
  4913. Sizzle.filter( part, checkSet, true );
  4914. }
  4915. },
  4916. ">": function(checkSet, part){
  4917. var isPartStr = typeof part === "string",
  4918. elem, i = 0, l = checkSet.length;
  4919. if ( isPartStr && !/\W/.test(part) ) {
  4920. part = part.toLowerCase();
  4921. for ( ; i < l; i++ ) {
  4922. elem = checkSet[i];
  4923. if ( elem ) {
  4924. var parent = elem.parentNode;
  4925. checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false;
  4926. }
  4927. }
  4928. } else {
  4929. for ( ; i < l; i++ ) {
  4930. elem = checkSet[i];
  4931. if ( elem ) {
  4932. checkSet[i] = isPartStr ?
  4933. elem.parentNode :
  4934. elem.parentNode === part;
  4935. }
  4936. }
  4937. if ( isPartStr ) {
  4938. Sizzle.filter( part, checkSet, true );
  4939. }
  4940. }
  4941. },
  4942. "": function(checkSet, part, isXML){
  4943. var doneName = done++, checkFn = dirCheck, nodeCheck;
  4944. if ( typeof part === "string" && !/\W/.test(part) ) {
  4945. part = part.toLowerCase();
  4946. nodeCheck = part;
  4947. checkFn = dirNodeCheck;
  4948. }
  4949. checkFn("parentNode", part, doneName, checkSet, nodeCheck, isXML);
  4950. },
  4951. "~": function(checkSet, part, isXML){
  4952. var doneName = done++, checkFn = dirCheck, nodeCheck;
  4953. if ( typeof part === "string" && !/\W/.test(part) ) {
  4954. part = part.toLowerCase();
  4955. nodeCheck = part;
  4956. checkFn = dirNodeCheck;
  4957. }
  4958. checkFn("previousSibling", part, doneName, checkSet, nodeCheck, isXML);
  4959. }
  4960. },
  4961. find: {
  4962. ID: function(match, context, isXML){
  4963. if ( typeof context.getElementById !== "undefined" && !isXML ) {
  4964. var m = context.getElementById(match[1]);
  4965. return m ? [m] : [];
  4966. }
  4967. },
  4968. NAME: function(match, context){
  4969. if ( typeof context.getElementsByName !== "undefined" ) {
  4970. var ret = [], results = context.getElementsByName(match[1]);
  4971. for ( var i = 0, l = results.length; i < l; i++ ) {
  4972. if ( results[i].getAttribute("name") === match[1] ) {
  4973. ret.push( results[i] );
  4974. }
  4975. }
  4976. return ret.length === 0 ? null : ret;
  4977. }
  4978. },
  4979. TAG: function(match, context){
  4980. return context.getElementsByTagName(match[1]);
  4981. }
  4982. },
  4983. preFilter: {
  4984. CLASS: function(match, curLoop, inplace, result, not, isXML){
  4985. match = " " + match[1].replace(/\\/g, "") + " ";
  4986. if ( isXML ) {
  4987. return match;
  4988. }
  4989. for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) {
  4990. if ( elem ) {
  4991. if ( not ^ (elem.className && (" " + elem.className + " ").replace(/[\t\n]/g, " ").indexOf(match) >= 0) ) {
  4992. if ( !inplace ) {
  4993. result.push( elem );
  4994. }
  4995. } else if ( inplace ) {
  4996. curLoop[i] = false;
  4997. }
  4998. }
  4999. }
  5000. return false;
  5001. },
  5002. ID: function(match){
  5003. return match[1].replace(/\\/g, "");
  5004. },
  5005. TAG: function(match, curLoop){
  5006. return match[1].toLowerCase();
  5007. },
  5008. CHILD: function(match){
  5009. if ( match[1] === "nth" ) {
  5010. // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
  5011. var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
  5012. match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" ||
  5013. !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);
  5014. // calculate the numbers (first)n+(last) including if they are negative
  5015. match[2] = (test[1] + (test[2] || 1)) - 0;
  5016. match[3] = test[3] - 0;
  5017. }
  5018. // TODO: Move to normal caching system
  5019. match[0] = done++;
  5020. return match;
  5021. },
  5022. ATTR: function(match, curLoop, inplace, result, not, isXML){
  5023. var name = match[1].replace(/\\/g, "");
  5024. if ( !isXML && Expr.attrMap[name] ) {
  5025. match[1] = Expr.attrMap[name];
  5026. }
  5027. if ( match[2] === "~=" ) {
  5028. match[4] = " " + match[4] + " ";
  5029. }
  5030. return match;
  5031. },
  5032. PSEUDO: function(match, curLoop, inplace, result, not){
  5033. if ( match[1] === "not" ) {
  5034. // If we're dealing with a complex expression, or a simple one
  5035. if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) {
  5036. match[3] = Sizzle(match[3], null, null, curLoop);
  5037. } else {
  5038. var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
  5039. if ( !inplace ) {
  5040. result.push.apply( result, ret );
  5041. }
  5042. return false;
  5043. }
  5044. } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
  5045. return true;
  5046. }
  5047. return match;
  5048. },
  5049. POS: function(match){
  5050. match.unshift( true );
  5051. return match;
  5052. }
  5053. },
  5054. filters: {
  5055. enabled: function(elem){
  5056. return elem.disabled === false && elem.type !== "hidden";
  5057. },
  5058. disabled: function(elem){
  5059. return elem.disabled === true;
  5060. },
  5061. checked: function(elem){
  5062. return elem.checked === true;
  5063. },
  5064. selected: function(elem){
  5065. // Accessing this property makes selected-by-default
  5066. // options in Safari work properly
  5067. elem.parentNode.selectedIndex;
  5068. return elem.selected === true;
  5069. },
  5070. parent: function(elem){
  5071. return !!elem.firstChild;
  5072. },
  5073. empty: function(elem){
  5074. return !elem.firstChild;
  5075. },
  5076. has: function(elem, i, match){
  5077. return !!Sizzle( match[3], elem ).length;
  5078. },
  5079. header: function(elem){
  5080. return (/h\d/i).test( elem.nodeName );
  5081. },
  5082. text: function(elem){
  5083. return "text" === elem.type;
  5084. },
  5085. radio: function(elem){
  5086. return "radio" === elem.type;
  5087. },
  5088. checkbox: function(elem){
  5089. return "checkbox" === elem.type;
  5090. },
  5091. file: function(elem){
  5092. return "file" === elem.type;
  5093. },
  5094. password: function(elem){
  5095. return "password" === elem.type;
  5096. },
  5097. submit: function(elem){
  5098. return "submit" === elem.type;
  5099. },
  5100. image: function(elem){
  5101. return "image" === elem.type;
  5102. },
  5103. reset: function(elem){
  5104. return "reset" === elem.type;
  5105. },
  5106. button: function(elem){
  5107. return "button" === elem.type || elem.nodeName.toLowerCase() === "button";
  5108. },
  5109. input: function(elem){
  5110. return (/input|select|textarea|button/i).test(elem.nodeName);
  5111. }
  5112. },
  5113. setFilters: {
  5114. first: function(elem, i){
  5115. return i === 0;
  5116. },
  5117. last: function(elem, i, match, array){
  5118. return i === array.length - 1;
  5119. },
  5120. even: function(elem, i){
  5121. return i % 2 === 0;
  5122. },
  5123. odd: function(elem, i){
  5124. return i % 2 === 1;
  5125. },
  5126. lt: function(elem, i, match){
  5127. return i < match[3] - 0;
  5128. },
  5129. gt: function(elem, i, match){
  5130. return i > match[3] - 0;
  5131. },
  5132. nth: function(elem, i, match){
  5133. return match[3] - 0 === i;
  5134. },
  5135. eq: function(elem, i, match){
  5136. return match[3] - 0 === i;
  5137. }
  5138. },
  5139. filter: {
  5140. PSEUDO: function(elem, match, i, array){
  5141. var name = match[1], filter = Expr.filters[ name ];
  5142. if ( filter ) {
  5143. return filter( elem, i, match, array );
  5144. } else if ( name === "contains" ) {
  5145. return (elem.textContent || elem.innerText || Sizzle.getText([ elem ]) || "").indexOf(match[3]) >= 0;
  5146. } else if ( name === "not" ) {
  5147. var not = match[3];
  5148. for ( var j = 0, l = not.length; j < l; j++ ) {
  5149. if ( not[j] === elem ) {
  5150. return false;
  5151. }
  5152. }
  5153. return true;
  5154. } else {
  5155. Sizzle.error( "Syntax error, unrecognized expression: " + name );
  5156. }
  5157. },
  5158. CHILD: function(elem, match){
  5159. var type = match[1], node = elem;
  5160. switch (type) {
  5161. case 'only':
  5162. case 'first':
  5163. while ( (node = node.previousSibling) ) {
  5164. if ( node.nodeType === 1 ) {
  5165. return false;
  5166. }
  5167. }
  5168. if ( type === "first" ) {
  5169. return true;
  5170. }
  5171. node = elem;
  5172. case 'last':
  5173. while ( (node = node.nextSibling) ) {
  5174. if ( node.nodeType === 1 ) {
  5175. return false;
  5176. }
  5177. }
  5178. return true;
  5179. case 'nth':
  5180. var first = match[2], last = match[3];
  5181. if ( first === 1 && last === 0 ) {
  5182. return true;
  5183. }
  5184. var doneName = match[0],
  5185. parent = elem.parentNode;
  5186. if ( parent && (parent.sizcache !== doneName || !elem.nodeIndex) ) {
  5187. var count = 0;
  5188. for ( node = parent.firstChild; node; node = node.nextSibling ) {
  5189. if ( node.nodeType === 1 ) {
  5190. node.nodeIndex = ++count;
  5191. }
  5192. }
  5193. parent.sizcache = doneName;
  5194. }
  5195. var diff = elem.nodeIndex - last;
  5196. if ( first === 0 ) {
  5197. return diff === 0;
  5198. } else {
  5199. return ( diff % first === 0 && diff / first >= 0 );
  5200. }
  5201. }
  5202. },
  5203. ID: function(elem, match){
  5204. return elem.nodeType === 1 && elem.getAttribute("id") === match;
  5205. },
  5206. TAG: function(elem, match){
  5207. return (match === "*" && elem.nodeType === 1) || elem.nodeName.toLowerCase() === match;
  5208. },
  5209. CLASS: function(elem, match){
  5210. return (" " + (elem.className || elem.getAttribute("class")) + " ")
  5211. .indexOf( match ) > -1;
  5212. },
  5213. ATTR: function(elem, match){
  5214. var name = match[1],
  5215. result = Expr.attrHandle[ name ] ?
  5216. Expr.attrHandle[ name ]( elem ) :
  5217. elem[ name ] != null ?
  5218. elem[ name ] :
  5219. elem.getAttribute( name ),
  5220. value = result + "",
  5221. type = match[2],
  5222. check = match[4];
  5223. return result == null ?
  5224. type === "!=" :
  5225. type === "=" ?
  5226. value === check :
  5227. type === "*=" ?
  5228. value.indexOf(check) >= 0 :
  5229. type === "~=" ?
  5230. (" " + value + " ").indexOf(check) >= 0 :
  5231. !check ?
  5232. value && result !== false :
  5233. type === "!=" ?
  5234. value !== check :
  5235. type === "^=" ?
  5236. value.indexOf(check) === 0 :
  5237. type === "$=" ?
  5238. value.substr(value.length - check.length) === check :
  5239. type === "|=" ?
  5240. value === check || value.substr(0, check.length + 1) === check + "-" :
  5241. false;
  5242. },
  5243. POS: function(elem, match, i, array){
  5244. var name = match[2], filter = Expr.setFilters[ name ];
  5245. if ( filter ) {
  5246. return filter( elem, i, match, array );
  5247. }
  5248. }
  5249. }
  5250. };
  5251. var origPOS = Expr.match.POS,
  5252. fescape = function(all, num){
  5253. return "\\" + (num - 0 + 1);
  5254. };
  5255. for ( var type in Expr.match ) {
  5256. Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) );
  5257. Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) );
  5258. }
  5259. var makeArray = function(array, results) {
  5260. array = Array.prototype.slice.call( array, 0 );
  5261. if ( results ) {
  5262. results.push.apply( results, array );
  5263. return results;
  5264. }
  5265. return array;
  5266. };
  5267. // Perform a simple check to determine if the browser is capable of
  5268. // converting a NodeList to an array using builtin methods.
  5269. // Also verifies that the returned array holds DOM nodes
  5270. // (which is not the case in the Blackberry browser)
  5271. try {
  5272. Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType;
  5273. // Provide a fallback method if it does not work
  5274. } catch(e){
  5275. makeArray = function(array, results) {
  5276. var ret = results || [], i = 0;
  5277. if ( toString.call(array) === "[object Array]" ) {
  5278. Array.prototype.push.apply( ret, array );
  5279. } else {
  5280. if ( typeof array.length === "number" ) {
  5281. for ( var l = array.length; i < l; i++ ) {
  5282. ret.push( array[i] );
  5283. }
  5284. } else {
  5285. for ( ; array[i]; i++ ) {
  5286. ret.push( array[i] );
  5287. }
  5288. }
  5289. }
  5290. return ret;
  5291. };
  5292. }
  5293. var sortOrder;
  5294. if ( document.documentElement.compareDocumentPosition ) {
  5295. sortOrder = function( a, b ) {
  5296. if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) {
  5297. if ( a == b ) {
  5298. hasDuplicate = true;
  5299. }
  5300. return a.compareDocumentPosition ? -1 : 1;
  5301. }
  5302. var ret = a.compareDocumentPosition(b) & 4 ? -1 : a === b ? 0 : 1;
  5303. if ( ret === 0 ) {
  5304. hasDuplicate = true;
  5305. }
  5306. return ret;
  5307. };
  5308. } else if ( "sourceIndex" in document.documentElement ) {
  5309. sortOrder = function( a, b ) {
  5310. if ( !a.sourceIndex || !b.sourceIndex ) {
  5311. if ( a == b ) {
  5312. hasDuplicate = true;
  5313. }
  5314. return a.sourceIndex ? -1 : 1;
  5315. }
  5316. var ret = a.sourceIndex - b.sourceIndex;
  5317. if ( ret === 0 ) {
  5318. hasDuplicate = true;
  5319. }
  5320. return ret;
  5321. };
  5322. } else if ( document.createRange ) {
  5323. sortOrder = function( a, b ) {
  5324. if ( !a.ownerDocument || !b.ownerDocument ) {
  5325. if ( a == b ) {
  5326. hasDuplicate = true;
  5327. }
  5328. return a.ownerDocument ? -1 : 1;
  5329. }
  5330. var aRange = a.ownerDocument.createRange(), bRange = b.ownerDocument.createRange();
  5331. aRange.setStart(a, 0);
  5332. aRange.setEnd(a, 0);
  5333. bRange.setStart(b, 0);
  5334. bRange.setEnd(b, 0);
  5335. var ret = aRange.compareBoundaryPoints(Range.START_TO_END, bRange);
  5336. if ( ret === 0 ) {
  5337. hasDuplicate = true;
  5338. }
  5339. return ret;
  5340. };
  5341. }
  5342. // Utility function for retreiving the text value of an array of DOM nodes
  5343. Sizzle.getText = function( elems ) {
  5344. var ret = "", elem;
  5345. for ( var i = 0; elems[i]; i++ ) {
  5346. elem = elems[i];
  5347. // Get the text from text nodes and CDATA nodes
  5348. if ( elem.nodeType === 3 || elem.nodeType === 4 ) {
  5349. ret += elem.nodeValue;
  5350. // Traverse everything else, except comment nodes
  5351. } else if ( elem.nodeType !== 8 ) {
  5352. ret += Sizzle.getText( elem.childNodes );
  5353. }
  5354. }
  5355. return ret;
  5356. };
  5357. // Check to see if the browser returns elements by name when
  5358. // querying by getElementById (and provide a workaround)
  5359. (function(){
  5360. // We're going to inject a fake input element with a specified name
  5361. var form = document.createElement("div"),
  5362. id = "script" + (new Date()).getTime();
  5363. form.innerHTML = "<a name='" + id + "'/>";
  5364. // Inject it into the root element, check its status, and remove it quickly
  5365. var root = document.documentElement;
  5366. root.insertBefore( form, root.firstChild );
  5367. // The workaround has to do additional checks after a getElementById
  5368. // Which slows things down for other browsers (hence the branching)
  5369. if ( document.getElementById( id ) ) {
  5370. Expr.find.ID = function(match, context, isXML){
  5371. if ( typeof context.getElementById !== "undefined" && !isXML ) {
  5372. var m = context.getElementById(match[1]);
  5373. return m ? m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : [];
  5374. }
  5375. };
  5376. Expr.filter.ID = function(elem, match){
  5377. var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
  5378. return elem.nodeType === 1 && node && node.nodeValue === match;
  5379. };
  5380. }
  5381. root.removeChild( form );
  5382. root = form = null; // release memory in IE
  5383. })();
  5384. (function(){
  5385. // Check to see if the browser returns only elements
  5386. // when doing getElementsByTagName("*")
  5387. // Create a fake element
  5388. var div = document.createElement("div");
  5389. div.appendChild( document.createComment("") );
  5390. // Make sure no comments are found
  5391. if ( div.getElementsByTagName("*").length > 0 ) {
  5392. Expr.find.TAG = function(match, context){
  5393. var results = context.getElementsByTagName(match[1]);
  5394. // Filter out possible comments
  5395. if ( match[1] === "*" ) {
  5396. var tmp = [];
  5397. for ( var i = 0; results[i]; i++ ) {
  5398. if ( results[i].nodeType === 1 ) {
  5399. tmp.push( results[i] );
  5400. }
  5401. }
  5402. results = tmp;
  5403. }
  5404. return results;
  5405. };
  5406. }
  5407. // Check to see if an attribute returns normalized href attributes
  5408. div.innerHTML = "<a href='#'></a>";
  5409. if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" &&
  5410. div.firstChild.getAttribute("href") !== "#" ) {
  5411. Expr.attrHandle.href = function(elem){
  5412. return elem.getAttribute("href", 2);
  5413. };
  5414. }
  5415. div = null; // release memory in IE
  5416. })();
  5417. if ( document.querySelectorAll ) {
  5418. (function(){
  5419. var oldSizzle = Sizzle, div = document.createElement("div");
  5420. div.innerHTML = "<p class='TEST'></p>";
  5421. // Safari can't handle uppercase or unicode characters when
  5422. // in quirks mode.
  5423. if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {
  5424. return;
  5425. }
  5426. Sizzle = function(query, context, extra, seed){
  5427. context = context || document;
  5428. // Only use querySelectorAll on non-XML documents
  5429. // (ID selectors don't work in non-HTML documents)
  5430. if ( !seed && context.nodeType === 9 && !Sizzle.isXML(context) ) {
  5431. try {
  5432. return makeArray( context.querySelectorAll(query), extra );
  5433. } catch(e){}
  5434. }
  5435. return oldSizzle(query, context, extra, seed);
  5436. };
  5437. for ( var prop in oldSizzle ) {
  5438. Sizzle[ prop ] = oldSizzle[ prop ];
  5439. }
  5440. div = null; // release memory in IE
  5441. })();
  5442. }
  5443. (function(){
  5444. var div = document.createElement("div");
  5445. div.innerHTML = "<div class='test e'></div><div class='test'></div>";
  5446. // Opera can't find a second classname (in 9.6)
  5447. // Also, make sure that getElementsByClassName actually exists
  5448. if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) {
  5449. return;
  5450. }
  5451. // Safari caches class attributes, doesn't catch changes (in 3.2)
  5452. div.lastChild.className = "e";
  5453. if ( div.getElementsByClassName("e").length === 1 ) {
  5454. return;
  5455. }
  5456. Expr.order.splice(1, 0, "CLASS");
  5457. Expr.find.CLASS = function(match, context, isXML) {
  5458. if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {
  5459. return context.getElementsByClassName(match[1]);
  5460. }
  5461. };
  5462. div = null; // release memory in IE
  5463. })();
  5464. function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
  5465. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  5466. var elem = checkSet[i];
  5467. if ( elem ) {
  5468. elem = elem[dir];
  5469. var match = false;
  5470. while ( elem ) {
  5471. if ( elem.sizcache === doneName ) {
  5472. match = checkSet[elem.sizset];
  5473. break;
  5474. }
  5475. if ( elem.nodeType === 1 && !isXML ){
  5476. elem.sizcache = doneName;
  5477. elem.sizset = i;
  5478. }
  5479. if ( elem.nodeName.toLowerCase() === cur ) {
  5480. match = elem;
  5481. break;
  5482. }
  5483. elem = elem[dir];
  5484. }
  5485. checkSet[i] = match;
  5486. }
  5487. }
  5488. }
  5489. function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
  5490. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  5491. var elem = checkSet[i];
  5492. if ( elem ) {
  5493. elem = elem[dir];
  5494. var match = false;
  5495. while ( elem ) {
  5496. if ( elem.sizcache === doneName ) {
  5497. match = checkSet[elem.sizset];
  5498. break;
  5499. }
  5500. if ( elem.nodeType === 1 ) {
  5501. if ( !isXML ) {
  5502. elem.sizcache = doneName;
  5503. elem.sizset = i;
  5504. }
  5505. if ( typeof cur !== "string" ) {
  5506. if ( elem === cur ) {
  5507. match = true;
  5508. break;
  5509. }
  5510. } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
  5511. match = elem;
  5512. break;
  5513. }
  5514. }
  5515. elem = elem[dir];
  5516. }
  5517. checkSet[i] = match;
  5518. }
  5519. }
  5520. }
  5521. Sizzle.contains = document.compareDocumentPosition ? function(a, b){
  5522. return !!(a.compareDocumentPosition(b) & 16);
  5523. } : function(a, b){
  5524. return a !== b && (a.contains ? a.contains(b) : true);
  5525. };
  5526. Sizzle.isXML = function(elem){
  5527. // documentElement is verified for cases where it doesn't yet exist
  5528. // (such as loading iframes in IE - #4833)
  5529. var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement;
  5530. return documentElement ? documentElement.nodeName !== "HTML" : false;
  5531. };
  5532. var posProcess = function(selector, context){
  5533. var tmpSet = [], later = "", match,
  5534. root = context.nodeType ? [context] : context;
  5535. // Position selectors must be done after the filter
  5536. // And so must :not(positional) so we move all PSEUDOs to the end
  5537. while ( (match = Expr.match.PSEUDO.exec( selector )) ) {
  5538. later += match[0];
  5539. selector = selector.replace( Expr.match.PSEUDO, "" );
  5540. }
  5541. selector = Expr.relative[selector] ? selector + "*" : selector;
  5542. for ( var i = 0, l = root.length; i < l; i++ ) {
  5543. Sizzle( selector, root[i], tmpSet );
  5544. }
  5545. return Sizzle.filter( later, tmpSet );
  5546. };
  5547. // EXPOSE
  5548. window.tinymce.dom.Sizzle = Sizzle;
  5549. })();
  5550. (function(tinymce) {
  5551. // Shorten names
  5552. var each = tinymce.each, DOM = tinymce.DOM, isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, Event;
  5553. tinymce.create('tinymce.dom.EventUtils', {
  5554. EventUtils : function() {
  5555. this.inits = [];
  5556. this.events = [];
  5557. },
  5558. add : function(o, n, f, s) {
  5559. var cb, t = this, el = t.events, r;
  5560. if (n instanceof Array) {
  5561. r = [];
  5562. each(n, function(n) {
  5563. r.push(t.add(o, n, f, s));
  5564. });
  5565. return r;
  5566. }
  5567. // Handle array
  5568. if (o && o.hasOwnProperty && o instanceof Array) {
  5569. r = [];
  5570. each(o, function(o) {
  5571. o = DOM.get(o);
  5572. r.push(t.add(o, n, f, s));
  5573. });
  5574. return r;
  5575. }
  5576. o = DOM.get(o);
  5577. if (!o)
  5578. return;
  5579. // Setup event callback
  5580. cb = function(e) {
  5581. // Is all events disabled
  5582. if (t.disabled)
  5583. return;
  5584. e = e || window.event;
  5585. // Patch in target, preventDefault and stopPropagation in IE it's W3C valid
  5586. if (e && isIE) {
  5587. if (!e.target)
  5588. e.target = e.srcElement;
  5589. // Patch in preventDefault, stopPropagation methods for W3C compatibility
  5590. tinymce.extend(e, t._stoppers);
  5591. }
  5592. if (!s)
  5593. return f(e);
  5594. return f.call(s, e);
  5595. };
  5596. if (n == 'unload') {
  5597. tinymce.unloads.unshift({func : cb});
  5598. return cb;
  5599. }
  5600. if (n == 'init') {
  5601. if (t.domLoaded)
  5602. cb();
  5603. else
  5604. t.inits.push(cb);
  5605. return cb;
  5606. }
  5607. // Store away listener reference
  5608. el.push({
  5609. obj : o,
  5610. name : n,
  5611. func : f,
  5612. cfunc : cb,
  5613. scope : s
  5614. });
  5615. t._add(o, n, cb);
  5616. return f;
  5617. },
  5618. remove : function(o, n, f) {
  5619. var t = this, a = t.events, s = false, r;
  5620. // Handle array
  5621. if (o && o.hasOwnProperty && o instanceof Array) {
  5622. r = [];
  5623. each(o, function(o) {
  5624. o = DOM.get(o);
  5625. r.push(t.remove(o, n, f));
  5626. });
  5627. return r;
  5628. }
  5629. o = DOM.get(o);
  5630. each(a, function(e, i) {
  5631. if (e.obj == o && e.name == n && (!f || (e.func == f || e.cfunc == f))) {
  5632. a.splice(i, 1);
  5633. t._remove(o, n, e.cfunc);
  5634. s = true;
  5635. return false;
  5636. }
  5637. });
  5638. return s;
  5639. },
  5640. clear : function(o) {
  5641. var t = this, a = t.events, i, e;
  5642. if (o) {
  5643. o = DOM.get(o);
  5644. for (i = a.length - 1; i >= 0; i--) {
  5645. e = a[i];
  5646. if (e.obj === o) {
  5647. t._remove(e.obj, e.name, e.cfunc);
  5648. e.obj = e.cfunc = null;
  5649. a.splice(i, 1);
  5650. }
  5651. }
  5652. }
  5653. },
  5654. cancel : function(e) {
  5655. if (!e)
  5656. return false;
  5657. this.stop(e);
  5658. return this.prevent(e);
  5659. },
  5660. stop : function(e) {
  5661. if (e.stopPropagation)
  5662. e.stopPropagation();
  5663. else
  5664. e.cancelBubble = true;
  5665. return false;
  5666. },
  5667. prevent : function(e) {
  5668. if (e.preventDefault)
  5669. e.preventDefault();
  5670. else
  5671. e.returnValue = false;
  5672. return false;
  5673. },
  5674. destroy : function() {
  5675. var t = this;
  5676. each(t.events, function(e, i) {
  5677. t._remove(e.obj, e.name, e.cfunc);
  5678. e.obj = e.cfunc = null;
  5679. });
  5680. t.events = [];
  5681. t = null;
  5682. },
  5683. _add : function(o, n, f) {
  5684. if (o.attachEvent)
  5685. o.attachEvent('on' + n, f);
  5686. else if (o.addEventListener)
  5687. o.addEventListener(n, f, false);
  5688. else
  5689. o['on' + n] = f;
  5690. },
  5691. _remove : function(o, n, f) {
  5692. if (o) {
  5693. try {
  5694. if (o.detachEvent)
  5695. o.detachEvent('on' + n, f);
  5696. else if (o.removeEventListener)
  5697. o.removeEventListener(n, f, false);
  5698. else
  5699. o['on' + n] = null;
  5700. } catch (ex) {
  5701. // Might fail with permission denined on IE so we just ignore that
  5702. }
  5703. }
  5704. },
  5705. _pageInit : function(win) {
  5706. var t = this;
  5707. // Keep it from running more than once
  5708. if (t.domLoaded)
  5709. return;
  5710. t.domLoaded = true;
  5711. each(t.inits, function(c) {
  5712. c();
  5713. });
  5714. t.inits = [];
  5715. },
  5716. _wait : function(win) {
  5717. var t = this, doc = win.document;
  5718. // No need since the document is already loaded
  5719. if (win.tinyMCE_GZ && tinyMCE_GZ.loaded) {
  5720. t.domLoaded = 1;
  5721. return;
  5722. }
  5723. // Use IE method
  5724. if (doc.attachEvent) {
  5725. doc.attachEvent("onreadystatechange", function() {
  5726. if (doc.readyState === "complete") {
  5727. doc.detachEvent("onreadystatechange", arguments.callee);
  5728. t._pageInit(win);
  5729. }
  5730. });
  5731. if (doc.documentElement.doScroll && win == win.top) {
  5732. (function() {
  5733. if (t.domLoaded)
  5734. return;
  5735. try {
  5736. // If IE is used, use the trick by Diego Perini licensed under MIT by request to the author.
  5737. // http://javascript.nwbox.com/IEContentLoaded/
  5738. doc.documentElement.doScroll("left");
  5739. } catch (ex) {
  5740. setTimeout(arguments.callee, 0);
  5741. return;
  5742. }
  5743. t._pageInit(win);
  5744. })();
  5745. }
  5746. } else if (doc.addEventListener) {
  5747. t._add(win, 'DOMContentLoaded', function() {
  5748. t._pageInit(win);
  5749. });
  5750. }
  5751. t._add(win, 'load', function() {
  5752. t._pageInit(win);
  5753. });
  5754. },
  5755. _stoppers : {
  5756. preventDefault : function() {
  5757. this.returnValue = false;
  5758. },
  5759. stopPropagation : function() {
  5760. this.cancelBubble = true;
  5761. }
  5762. }
  5763. });
  5764. Event = tinymce.dom.Event = new tinymce.dom.EventUtils();
  5765. // Dispatch DOM content loaded event for IE and Safari
  5766. Event._wait(window);
  5767. tinymce.addUnload(function() {
  5768. Event.destroy();
  5769. });
  5770. })(tinymce);
  5771. (function(tinymce) {
  5772. tinymce.dom.Element = function(id, settings) {
  5773. var t = this, dom, el;
  5774. t.settings = settings = settings || {};
  5775. t.id = id;
  5776. t.dom = dom = settings.dom || tinymce.DOM;
  5777. // Only IE leaks DOM references, this is a lot faster
  5778. if (!tinymce.isIE)
  5779. el = dom.get(t.id);
  5780. tinymce.each(
  5781. ('getPos,getRect,getParent,add,setStyle,getStyle,setStyles,' +
  5782. 'setAttrib,setAttribs,getAttrib,addClass,removeClass,' +
  5783. 'hasClass,getOuterHTML,setOuterHTML,remove,show,hide,' +
  5784. 'isHidden,setHTML,get').split(/,/)
  5785. , function(k) {
  5786. t[k] = function() {
  5787. var a = [id], i;
  5788. for (i = 0; i < arguments.length; i++)
  5789. a.push(arguments[i]);
  5790. a = dom[k].apply(dom, a);
  5791. t.update(k);
  5792. return a;
  5793. };
  5794. });
  5795. tinymce.extend(t, {
  5796. on : function(n, f, s) {
  5797. return tinymce.dom.Event.add(t.id, n, f, s);
  5798. },
  5799. getXY : function() {
  5800. return {
  5801. x : parseInt(t.getStyle('left')),
  5802. y : parseInt(t.getStyle('top'))
  5803. };
  5804. },
  5805. getSize : function() {
  5806. var n = dom.get(t.id);
  5807. return {
  5808. w : parseInt(t.getStyle('width') || n.clientWidth),
  5809. h : parseInt(t.getStyle('height') || n.clientHeight)
  5810. };
  5811. },
  5812. moveTo : function(x, y) {
  5813. t.setStyles({left : x, top : y});
  5814. },
  5815. moveBy : function(x, y) {
  5816. var p = t.getXY();
  5817. t.moveTo(p.x + x, p.y + y);
  5818. },
  5819. resizeTo : function(w, h) {
  5820. t.setStyles({width : w, height : h});
  5821. },
  5822. resizeBy : function(w, h) {
  5823. var s = t.getSize();
  5824. t.resizeTo(s.w + w, s.h + h);
  5825. },
  5826. update : function(k) {
  5827. var b;
  5828. if (tinymce.isIE6 && settings.blocker) {
  5829. k = k || '';
  5830. // Ignore getters
  5831. if (k.indexOf('get') === 0 || k.indexOf('has') === 0 || k.indexOf('is') === 0)
  5832. return;
  5833. // Remove blocker on remove
  5834. if (k == 'remove') {
  5835. dom.remove(t.blocker);
  5836. return;
  5837. }
  5838. if (!t.blocker) {
  5839. t.blocker = dom.uniqueId();
  5840. b = dom.add(settings.container || dom.getRoot(), 'iframe', {id : t.blocker, style : 'position:absolute;', frameBorder : 0, src : 'javascript:""'});
  5841. dom.setStyle(b, 'opacity', 0);
  5842. } else
  5843. b = dom.get(t.blocker);
  5844. dom.setStyles(b, {
  5845. left : t.getStyle('left', 1),
  5846. top : t.getStyle('top', 1),
  5847. width : t.getStyle('width', 1),
  5848. height : t.getStyle('height', 1),
  5849. display : t.getStyle('display', 1),
  5850. zIndex : parseInt(t.getStyle('zIndex', 1) || 0) - 1
  5851. });
  5852. }
  5853. }
  5854. });
  5855. };
  5856. })(tinymce);
  5857. (function(tinymce) {
  5858. function trimNl(s) {
  5859. return s.replace(/[\n\r]+/g, '');
  5860. };
  5861. // Shorten names
  5862. var is = tinymce.is, isIE = tinymce.isIE, each = tinymce.each;
  5863. tinymce.create('tinymce.dom.Selection', {
  5864. Selection : function(dom, win, serializer) {
  5865. var t = this;
  5866. t.dom = dom;
  5867. t.win = win;
  5868. t.serializer = serializer;
  5869. // Add events
  5870. each([
  5871. 'onBeforeSetContent',
  5872. 'onBeforeGetContent',
  5873. 'onSetContent',
  5874. 'onGetContent'
  5875. ], function(e) {
  5876. t[e] = new tinymce.util.Dispatcher(t);
  5877. });
  5878. // No W3C Range support
  5879. if (!t.win.getSelection)
  5880. t.tridentSel = new tinymce.dom.TridentSelection(t);
  5881. if (tinymce.isIE && dom.boxModel)
  5882. this._fixIESelection();
  5883. // Prevent leaks
  5884. tinymce.addUnload(t.destroy, t);
  5885. },
  5886. setCursorLocation: function(node, offset) {
  5887. var t = this; var r = t.dom.createRng();
  5888. r.setStart(node, offset);
  5889. r.setEnd(node, offset);
  5890. t.setRng(r);
  5891. t.collapse(false);
  5892. },
  5893. getContent : function(s) {
  5894. var t = this, r = t.getRng(), e = t.dom.create("body"), se = t.getSel(), wb, wa, n;
  5895. s = s || {};
  5896. wb = wa = '';
  5897. s.get = true;
  5898. s.format = s.format || 'html';
  5899. s.forced_root_block = '';
  5900. t.onBeforeGetContent.dispatch(t, s);
  5901. if (s.format == 'text')
  5902. return t.isCollapsed() ? '' : (r.text || (se.toString ? se.toString() : ''));
  5903. if (r.cloneContents) {
  5904. n = r.cloneContents();
  5905. if (n)
  5906. e.appendChild(n);
  5907. } else if (is(r.item) || is(r.htmlText)) {
  5908. // IE will produce invalid markup if elements are present that
  5909. // it doesn't understand like custom elements or HTML5 elements.
  5910. // Adding a BR in front of the contents and then remoiving it seems to fix it though.
  5911. e.innerHTML = '<br>' + (r.item ? r.item(0).outerHTML : r.htmlText);
  5912. e.removeChild(e.firstChild);
  5913. } else
  5914. e.innerHTML = r.toString();
  5915. // Keep whitespace before and after
  5916. if (/^\s/.test(e.innerHTML))
  5917. wb = ' ';
  5918. if (/\s+$/.test(e.innerHTML))
  5919. wa = ' ';
  5920. s.getInner = true;
  5921. s.content = t.isCollapsed() ? '' : wb + t.serializer.serialize(e, s) + wa;
  5922. t.onGetContent.dispatch(t, s);
  5923. return s.content;
  5924. },
  5925. setContent : function(content, args) {
  5926. var self = this, rng = self.getRng(), caretNode, doc = self.win.document, frag, temp;
  5927. args = args || {format : 'html'};
  5928. args.set = true;
  5929. content = args.content = content;
  5930. // Dispatch before set content event
  5931. if (!args.no_events)
  5932. self.onBeforeSetContent.dispatch(self, args);
  5933. content = args.content;
  5934. if (rng.insertNode) {
  5935. // Make caret marker since insertNode places the caret in the beginning of text after insert
  5936. content += '<span id="__caret">_</span>';
  5937. // Delete and insert new node
  5938. if (rng.startContainer == doc && rng.endContainer == doc) {
  5939. // WebKit will fail if the body is empty since the range is then invalid and it can't insert contents
  5940. doc.body.innerHTML = content;
  5941. } else {
  5942. rng.deleteContents();
  5943. if (doc.body.childNodes.length == 0) {
  5944. doc.body.innerHTML = content;
  5945. } else {
  5946. // createContextualFragment doesn't exists in IE 9 DOMRanges
  5947. if (rng.createContextualFragment) {
  5948. rng.insertNode(rng.createContextualFragment(content));
  5949. } else {
  5950. // Fake createContextualFragment call in IE 9
  5951. frag = doc.createDocumentFragment();
  5952. temp = doc.createElement('div');
  5953. frag.appendChild(temp);
  5954. temp.outerHTML = content;
  5955. rng.insertNode(frag);
  5956. }
  5957. }
  5958. }
  5959. // Move to caret marker
  5960. caretNode = self.dom.get('__caret');
  5961. // Make sure we wrap it compleatly, Opera fails with a simple select call
  5962. rng = doc.createRange();
  5963. rng.setStartBefore(caretNode);
  5964. rng.setEndBefore(caretNode);
  5965. self.setRng(rng);
  5966. // Remove the caret position
  5967. self.dom.remove('__caret');
  5968. try {
  5969. self.setRng(rng);
  5970. } catch (ex) {
  5971. // Might fail on Opera for some odd reason
  5972. }
  5973. } else {
  5974. if (rng.item) {
  5975. // Delete content and get caret text selection
  5976. doc.execCommand('Delete', false, null);
  5977. rng = self.getRng();
  5978. }
  5979. // Explorer removes spaces from the beginning of pasted contents
  5980. if (/^\s+/.test(content)) {
  5981. rng.pasteHTML('<span id="__mce_tmp">_</span>' + content);
  5982. self.dom.remove('__mce_tmp');
  5983. } else
  5984. rng.pasteHTML(content);
  5985. }
  5986. // Dispatch set content event
  5987. if (!args.no_events)
  5988. self.onSetContent.dispatch(self, args);
  5989. },
  5990. getStart : function() {
  5991. var rng = this.getRng(), startElement, parentElement, checkRng, node;
  5992. if (rng.duplicate || rng.item) {
  5993. // Control selection, return first item
  5994. if (rng.item)
  5995. return rng.item(0);
  5996. // Get start element
  5997. checkRng = rng.duplicate();
  5998. checkRng.collapse(1);
  5999. startElement = checkRng.parentElement();
  6000. // Check if range parent is inside the start element, then return the inner parent element
  6001. // This will fix issues when a single element is selected, IE would otherwise return the wrong start element
  6002. parentElement = node = rng.parentElement();
  6003. while (node = node.parentNode) {
  6004. if (node == startElement) {
  6005. startElement = parentElement;
  6006. break;
  6007. }
  6008. }
  6009. return startElement;
  6010. } else {
  6011. startElement = rng.startContainer;
  6012. if (startElement.nodeType == 1 && startElement.hasChildNodes())
  6013. startElement = startElement.childNodes[Math.min(startElement.childNodes.length - 1, rng.startOffset)];
  6014. if (startElement && startElement.nodeType == 3)
  6015. return startElement.parentNode;
  6016. return startElement;
  6017. }
  6018. },
  6019. getEnd : function() {
  6020. var t = this, r = t.getRng(), e, eo;
  6021. if (r.duplicate || r.item) {
  6022. if (r.item)
  6023. return r.item(0);
  6024. r = r.duplicate();
  6025. r.collapse(0);
  6026. e = r.parentElement();
  6027. if (e && e.nodeName == 'BODY')
  6028. return e.lastChild || e;
  6029. return e;
  6030. } else {
  6031. e = r.endContainer;
  6032. eo = r.endOffset;
  6033. if (e.nodeType == 1 && e.hasChildNodes())
  6034. e = e.childNodes[eo > 0 ? eo - 1 : eo];
  6035. if (e && e.nodeType == 3)
  6036. return e.parentNode;
  6037. return e;
  6038. }
  6039. },
  6040. getBookmark : function(type, normalized) {
  6041. var t = this, dom = t.dom, rng, rng2, id, collapsed, name, element, index, chr = '\uFEFF', styles;
  6042. function findIndex(name, element) {
  6043. var index = 0;
  6044. each(dom.select(name), function(node, i) {
  6045. if (node == element)
  6046. index = i;
  6047. });
  6048. return index;
  6049. };
  6050. if (type == 2) {
  6051. function getLocation() {
  6052. var rng = t.getRng(true), root = dom.getRoot(), bookmark = {};
  6053. function getPoint(rng, start) {
  6054. var container = rng[start ? 'startContainer' : 'endContainer'],
  6055. offset = rng[start ? 'startOffset' : 'endOffset'], point = [], node, childNodes, after = 0;
  6056. if (container.nodeType == 3) {
  6057. if (normalized) {
  6058. for (node = container.previousSibling; node && node.nodeType == 3; node = node.previousSibling)
  6059. offset += node.nodeValue.length;
  6060. }
  6061. point.push(offset);
  6062. } else {
  6063. childNodes = container.childNodes;
  6064. if (offset >= childNodes.length && childNodes.length) {
  6065. after = 1;
  6066. offset = Math.max(0, childNodes.length - 1);
  6067. }
  6068. point.push(t.dom.nodeIndex(childNodes[offset], normalized) + after);
  6069. }
  6070. for (; container && container != root; container = container.parentNode)
  6071. point.push(t.dom.nodeIndex(container, normalized));
  6072. return point;
  6073. };
  6074. bookmark.start = getPoint(rng, true);
  6075. if (!t.isCollapsed())
  6076. bookmark.end = getPoint(rng);
  6077. return bookmark;
  6078. };
  6079. if (t.tridentSel)
  6080. return t.tridentSel.getBookmark(type);
  6081. return getLocation();
  6082. }
  6083. // Handle simple range
  6084. if (type)
  6085. return {rng : t.getRng()};
  6086. rng = t.getRng();
  6087. id = dom.uniqueId();
  6088. collapsed = tinyMCE.activeEditor.selection.isCollapsed();
  6089. styles = 'overflow:hidden;line-height:0px';
  6090. // Explorer method
  6091. if (rng.duplicate || rng.item) {
  6092. // Text selection
  6093. if (!rng.item) {
  6094. rng2 = rng.duplicate();
  6095. try {
  6096. // Insert start marker
  6097. rng.collapse();
  6098. rng.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_start" style="' + styles + '">' + chr + '</span>');
  6099. // Insert end marker
  6100. if (!collapsed) {
  6101. rng2.collapse(false);
  6102. // Detect the empty space after block elements in IE and move the end back one character <p></p>] becomes <p>]</p>
  6103. rng.moveToElementText(rng2.parentElement());
  6104. if (rng.compareEndPoints('StartToEnd', rng2) == 0)
  6105. rng2.move('character', -1);
  6106. rng2.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_end" style="' + styles + '">' + chr + '</span>');
  6107. }
  6108. } catch (ex) {
  6109. // IE might throw unspecified error so lets ignore it
  6110. return null;
  6111. }
  6112. } else {
  6113. // Control selection
  6114. element = rng.item(0);
  6115. name = element.nodeName;
  6116. return {name : name, index : findIndex(name, element)};
  6117. }
  6118. } else {
  6119. element = t.getNode();
  6120. name = element.nodeName;
  6121. if (name == 'IMG')
  6122. return {name : name, index : findIndex(name, element)};
  6123. // W3C method
  6124. rng2 = rng.cloneRange();
  6125. // Insert end marker
  6126. if (!collapsed) {
  6127. rng2.collapse(false);
  6128. rng2.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_end', style : styles}, chr));
  6129. }
  6130. rng.collapse(true);
  6131. rng.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_start', style : styles}, chr));
  6132. }
  6133. t.moveToBookmark({id : id, keep : 1});
  6134. return {id : id};
  6135. },
  6136. moveToBookmark : function(bookmark) {
  6137. var t = this, dom = t.dom, marker1, marker2, rng, root, startContainer, endContainer, startOffset, endOffset;
  6138. if (bookmark) {
  6139. if (bookmark.start) {
  6140. rng = dom.createRng();
  6141. root = dom.getRoot();
  6142. function setEndPoint(start) {
  6143. var point = bookmark[start ? 'start' : 'end'], i, node, offset, children;
  6144. if (point) {
  6145. offset = point[0];
  6146. // Find container node
  6147. for (node = root, i = point.length - 1; i >= 1; i--) {
  6148. children = node.childNodes;
  6149. if (point[i] > children.length - 1)
  6150. return;
  6151. node = children[point[i]];
  6152. }
  6153. // Move text offset to best suitable location
  6154. if (node.nodeType === 3)
  6155. offset = Math.min(point[0], node.nodeValue.length);
  6156. // Move element offset to best suitable location
  6157. if (node.nodeType === 1)
  6158. offset = Math.min(point[0], node.childNodes.length);
  6159. // Set offset within container node
  6160. if (start)
  6161. rng.setStart(node, offset);
  6162. else
  6163. rng.setEnd(node, offset);
  6164. }
  6165. return true;
  6166. };
  6167. if (t.tridentSel)
  6168. return t.tridentSel.moveToBookmark(bookmark);
  6169. if (setEndPoint(true) && setEndPoint()) {
  6170. t.setRng(rng);
  6171. }
  6172. } else if (bookmark.id) {
  6173. function restoreEndPoint(suffix) {
  6174. var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev, keep = bookmark.keep;
  6175. if (marker) {
  6176. node = marker.parentNode;
  6177. if (suffix == 'start') {
  6178. if (!keep) {
  6179. idx = dom.nodeIndex(marker);
  6180. } else {
  6181. node = marker.firstChild;
  6182. idx = 1;
  6183. }
  6184. startContainer = endContainer = node;
  6185. startOffset = endOffset = idx;
  6186. } else {
  6187. if (!keep) {
  6188. idx = dom.nodeIndex(marker);
  6189. } else {
  6190. node = marker.firstChild;
  6191. idx = 1;
  6192. }
  6193. endContainer = node;
  6194. endOffset = idx;
  6195. }
  6196. if (!keep) {
  6197. prev = marker.previousSibling;
  6198. next = marker.nextSibling;
  6199. // Remove all marker text nodes
  6200. each(tinymce.grep(marker.childNodes), function(node) {
  6201. if (node.nodeType == 3)
  6202. node.nodeValue = node.nodeValue.replace(/\uFEFF/g, '');
  6203. });
  6204. // Remove marker but keep children if for example contents where inserted into the marker
  6205. // Also remove duplicated instances of the marker for example by a split operation or by WebKit auto split on paste feature
  6206. while (marker = dom.get(bookmark.id + '_' + suffix))
  6207. dom.remove(marker, 1);
  6208. // If siblings are text nodes then merge them unless it's Opera since it some how removes the node
  6209. // 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
  6210. if (prev && next && prev.nodeType == next.nodeType && prev.nodeType == 3 && !tinymce.isOpera) {
  6211. idx = prev.nodeValue.length;
  6212. prev.appendData(next.nodeValue);
  6213. dom.remove(next);
  6214. if (suffix == 'start') {
  6215. startContainer = endContainer = prev;
  6216. startOffset = endOffset = idx;
  6217. } else {
  6218. endContainer = prev;
  6219. endOffset = idx;
  6220. }
  6221. }
  6222. }
  6223. }
  6224. };
  6225. function addBogus(node) {
  6226. // Adds a bogus BR element for empty block elements or just a space on IE since it renders BR elements incorrectly
  6227. if (dom.isBlock(node) && !node.innerHTML)
  6228. node.innerHTML = !isIE ? '<br data-mce-bogus="1" />' : ' ';
  6229. return node;
  6230. };
  6231. // Restore start/end points
  6232. restoreEndPoint('start');
  6233. restoreEndPoint('end');
  6234. if (startContainer) {
  6235. rng = dom.createRng();
  6236. rng.setStart(addBogus(startContainer), startOffset);
  6237. rng.setEnd(addBogus(endContainer), endOffset);
  6238. t.setRng(rng);
  6239. }
  6240. } else if (bookmark.name) {
  6241. t.select(dom.select(bookmark.name)[bookmark.index]);
  6242. } else if (bookmark.rng)
  6243. t.setRng(bookmark.rng);
  6244. }
  6245. },
  6246. select : function(node, content) {
  6247. var t = this, dom = t.dom, rng = dom.createRng(), idx;
  6248. if (node) {
  6249. idx = dom.nodeIndex(node);
  6250. rng.setStart(node.parentNode, idx);
  6251. rng.setEnd(node.parentNode, idx + 1);
  6252. // Find first/last text node or BR element
  6253. if (content) {
  6254. function setPoint(node, start) {
  6255. var walker = new tinymce.dom.TreeWalker(node, node);
  6256. do {
  6257. // Text node
  6258. if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length != 0) {
  6259. if (start)
  6260. rng.setStart(node, 0);
  6261. else
  6262. rng.setEnd(node, node.nodeValue.length);
  6263. return;
  6264. }
  6265. // BR element
  6266. if (node.nodeName == 'BR') {
  6267. if (start)
  6268. rng.setStartBefore(node);
  6269. else
  6270. rng.setEndBefore(node);
  6271. return;
  6272. }
  6273. } while (node = (start ? walker.next() : walker.prev()));
  6274. };
  6275. setPoint(node, 1);
  6276. setPoint(node);
  6277. }
  6278. t.setRng(rng);
  6279. }
  6280. return node;
  6281. },
  6282. isCollapsed : function() {
  6283. var t = this, r = t.getRng(), s = t.getSel();
  6284. if (!r || r.item)
  6285. return false;
  6286. if (r.compareEndPoints)
  6287. return r.compareEndPoints('StartToEnd', r) === 0;
  6288. return !s || r.collapsed;
  6289. },
  6290. collapse : function(to_start) {
  6291. var self = this, rng = self.getRng(), node;
  6292. // Control range on IE
  6293. if (rng.item) {
  6294. node = rng.item(0);
  6295. rng = self.win.document.body.createTextRange();
  6296. rng.moveToElementText(node);
  6297. }
  6298. rng.collapse(!!to_start);
  6299. self.setRng(rng);
  6300. },
  6301. getSel : function() {
  6302. var t = this, w = this.win;
  6303. return w.getSelection ? w.getSelection() : w.document.selection;
  6304. },
  6305. getRng : function(w3c) {
  6306. var t = this, s, r, elm, doc = t.win.document;
  6307. // Found tridentSel object then we need to use that one
  6308. if (w3c && t.tridentSel)
  6309. return t.tridentSel.getRangeAt(0);
  6310. try {
  6311. if (s = t.getSel())
  6312. r = s.rangeCount > 0 ? s.getRangeAt(0) : (s.createRange ? s.createRange() : doc.createRange());
  6313. } catch (ex) {
  6314. // IE throws unspecified error here if TinyMCE is placed in a frame/iframe
  6315. }
  6316. // We have W3C ranges and it's IE then fake control selection since IE9 doesn't handle that correctly yet
  6317. if (tinymce.isIE && r && r.setStart && doc.selection.createRange().item) {
  6318. elm = doc.selection.createRange().item(0);
  6319. r = doc.createRange();
  6320. r.setStartBefore(elm);
  6321. r.setEndAfter(elm);
  6322. }
  6323. // No range found then create an empty one
  6324. // This can occur when the editor is placed in a hidden container element on Gecko
  6325. // Or on IE when there was an exception
  6326. if (!r)
  6327. r = doc.createRange ? doc.createRange() : doc.body.createTextRange();
  6328. if (t.selectedRange && t.explicitRange) {
  6329. if (r.compareBoundaryPoints(r.START_TO_START, t.selectedRange) === 0 && r.compareBoundaryPoints(r.END_TO_END, t.selectedRange) === 0) {
  6330. // Safari, Opera and Chrome only ever select text which causes the range to change.
  6331. // This lets us use the originally set range if the selection hasn't been changed by the user.
  6332. r = t.explicitRange;
  6333. } else {
  6334. t.selectedRange = null;
  6335. t.explicitRange = null;
  6336. }
  6337. }
  6338. return r;
  6339. },
  6340. setRng : function(r) {
  6341. var s, t = this;
  6342. if (!t.tridentSel) {
  6343. s = t.getSel();
  6344. if (s) {
  6345. t.explicitRange = r;
  6346. try {
  6347. s.removeAllRanges();
  6348. } catch (ex) {
  6349. // IE9 might throw errors here don't know why
  6350. }
  6351. s.addRange(r);
  6352. t.selectedRange = s.getRangeAt(0);
  6353. }
  6354. } else {
  6355. // Is W3C Range
  6356. if (r.cloneRange) {
  6357. t.tridentSel.addRange(r);
  6358. return;
  6359. }
  6360. // Is IE specific range
  6361. try {
  6362. r.select();
  6363. } catch (ex) {
  6364. // Needed for some odd IE bug #1843306
  6365. }
  6366. }
  6367. },
  6368. setNode : function(n) {
  6369. var t = this;
  6370. t.setContent(t.dom.getOuterHTML(n));
  6371. return n;
  6372. },
  6373. getNode : function() {
  6374. var t = this, rng = t.getRng(), sel = t.getSel(), elm, start = rng.startContainer, end = rng.endContainer;
  6375. // Range maybe lost after the editor is made visible again
  6376. if (!rng)
  6377. return t.dom.getRoot();
  6378. if (rng.setStart) {
  6379. elm = rng.commonAncestorContainer;
  6380. // Handle selection a image or other control like element such as anchors
  6381. if (!rng.collapsed) {
  6382. if (rng.startContainer == rng.endContainer) {
  6383. if (rng.endOffset - rng.startOffset < 2) {
  6384. if (rng.startContainer.hasChildNodes())
  6385. elm = rng.startContainer.childNodes[rng.startOffset];
  6386. }
  6387. }
  6388. // If the anchor node is a element instead of a text node then return this element
  6389. //if (tinymce.isWebKit && sel.anchorNode && sel.anchorNode.nodeType == 1)
  6390. // return sel.anchorNode.childNodes[sel.anchorOffset];
  6391. // Handle cases where the selection is immediately wrapped around a node and return that node instead of it's parent.
  6392. // This happens when you double click an underlined word in FireFox.
  6393. if (start.nodeType === 3 && end.nodeType === 3) {
  6394. function skipEmptyTextNodes(n, forwards) {
  6395. var orig = n;
  6396. while (n && n.nodeType === 3 && n.length === 0) {
  6397. n = forwards ? n.nextSibling : n.previousSibling;
  6398. }
  6399. return n || orig;
  6400. }
  6401. if (start.length === rng.startOffset) {
  6402. start = skipEmptyTextNodes(start.nextSibling, true);
  6403. } else {
  6404. start = start.parentNode;
  6405. }
  6406. if (rng.endOffset === 0) {
  6407. end = skipEmptyTextNodes(end.previousSibling, false);
  6408. } else {
  6409. end = end.parentNode;
  6410. }
  6411. if (start && start === end)
  6412. return start;
  6413. }
  6414. }
  6415. if (elm && elm.nodeType == 3)
  6416. return elm.parentNode;
  6417. return elm;
  6418. }
  6419. return rng.item ? rng.item(0) : rng.parentElement();
  6420. },
  6421. getSelectedBlocks : function(st, en) {
  6422. var t = this, dom = t.dom, sb, eb, n, bl = [];
  6423. sb = dom.getParent(st || t.getStart(), dom.isBlock);
  6424. eb = dom.getParent(en || t.getEnd(), dom.isBlock);
  6425. if (sb)
  6426. bl.push(sb);
  6427. if (sb && eb && sb != eb) {
  6428. n = sb;
  6429. var walker = new tinymce.dom.TreeWalker(sb, dom.getRoot());
  6430. while ((n = walker.next()) && n != eb) {
  6431. if (dom.isBlock(n))
  6432. bl.push(n);
  6433. }
  6434. }
  6435. if (eb && sb != eb)
  6436. bl.push(eb);
  6437. return bl;
  6438. },
  6439. normalize : function() {
  6440. var self = this, rng, normalized;
  6441. // Normalize only on non IE browsers for now
  6442. if (tinymce.isIE)
  6443. return;
  6444. function normalizeEndPoint(start) {
  6445. var container, offset, walker, dom = self.dom, body = dom.getRoot(), node;
  6446. container = rng[(start ? 'start' : 'end') + 'Container'];
  6447. offset = rng[(start ? 'start' : 'end') + 'Offset'];
  6448. // If the container is a document move it to the body element
  6449. if (container.nodeType === 9) {
  6450. container = container.body;
  6451. offset = 0;
  6452. }
  6453. // If the container is body try move it into the closest text node or position
  6454. // TODO: Add more logic here to handle element selection cases
  6455. if (container === body) {
  6456. // Resolve the index
  6457. if (container.hasChildNodes()) {
  6458. container = container.childNodes[Math.min(!start && offset > 0 ? offset - 1 : offset, container.childNodes.length - 1)];
  6459. offset = 0;
  6460. // Don't walk into elements that doesn't have any child nodes like a IMG
  6461. if (container.hasChildNodes()) {
  6462. // Walk the DOM to find a text node to place the caret at or a BR
  6463. node = container;
  6464. walker = new tinymce.dom.TreeWalker(container, body);
  6465. do {
  6466. // Found a text node use that position
  6467. if (node.nodeType === 3) {
  6468. offset = start ? 0 : node.nodeValue.length - 1;
  6469. container = node;
  6470. break;
  6471. }
  6472. // Found a BR element that we can place the caret before
  6473. if (node.nodeName === 'BR') {
  6474. offset = dom.nodeIndex(node);
  6475. container = node.parentNode;
  6476. break;
  6477. }
  6478. } while (node = (start ? walker.next() : walker.prev()));
  6479. normalized = true;
  6480. }
  6481. }
  6482. }
  6483. // Set endpoint if it was normalized
  6484. if (normalized)
  6485. rng['set' + (start ? 'Start' : 'End')](container, offset);
  6486. };
  6487. rng = self.getRng();
  6488. // Normalize the end points
  6489. normalizeEndPoint(true);
  6490. if (rng.collapsed)
  6491. normalizeEndPoint();
  6492. // Set the selection if it was normalized
  6493. if (normalized) {
  6494. //console.log(self.dom.dumpRng(rng));
  6495. self.setRng(rng);
  6496. }
  6497. },
  6498. destroy : function(s) {
  6499. var t = this;
  6500. t.win = null;
  6501. // Manual destroy then remove unload handler
  6502. if (!s)
  6503. tinymce.removeUnload(t.destroy);
  6504. },
  6505. // IE has an issue where you can't select/move the caret by clicking outside the body if the document is in standards mode
  6506. _fixIESelection : function() {
  6507. var dom = this.dom, doc = dom.doc, body = doc.body, started, startRng, htmlElm;
  6508. // Make HTML element unselectable since we are going to handle selection by hand
  6509. doc.documentElement.unselectable = true;
  6510. // Return range from point or null if it failed
  6511. function rngFromPoint(x, y) {
  6512. var rng = body.createTextRange();
  6513. try {
  6514. rng.moveToPoint(x, y);
  6515. } catch (ex) {
  6516. // IE sometimes throws and exception, so lets just ignore it
  6517. rng = null;
  6518. }
  6519. return rng;
  6520. };
  6521. // Fires while the selection is changing
  6522. function selectionChange(e) {
  6523. var pointRng;
  6524. // Check if the button is down or not
  6525. if (e.button) {
  6526. // Create range from mouse position
  6527. pointRng = rngFromPoint(e.x, e.y);
  6528. if (pointRng) {
  6529. // Check if pointRange is before/after selection then change the endPoint
  6530. if (pointRng.compareEndPoints('StartToStart', startRng) > 0)
  6531. pointRng.setEndPoint('StartToStart', startRng);
  6532. else
  6533. pointRng.setEndPoint('EndToEnd', startRng);
  6534. pointRng.select();
  6535. }
  6536. } else
  6537. endSelection();
  6538. }
  6539. // Removes listeners
  6540. function endSelection() {
  6541. var rng = doc.selection.createRange();
  6542. // If the range is collapsed then use the last start range
  6543. if (startRng && !rng.item && rng.compareEndPoints('StartToEnd', rng) === 0)
  6544. startRng.select();
  6545. dom.unbind(doc, 'mouseup', endSelection);
  6546. dom.unbind(doc, 'mousemove', selectionChange);
  6547. startRng = started = 0;
  6548. };
  6549. // Detect when user selects outside BODY
  6550. dom.bind(doc, ['mousedown', 'contextmenu'], function(e) {
  6551. if (e.target.nodeName === 'HTML') {
  6552. if (started)
  6553. endSelection();
  6554. // Detect vertical scrollbar, since IE will fire a mousedown on the scrollbar and have target set as HTML
  6555. htmlElm = doc.documentElement;
  6556. if (htmlElm.scrollHeight > htmlElm.clientHeight)
  6557. return;
  6558. started = 1;
  6559. // Setup start position
  6560. startRng = rngFromPoint(e.x, e.y);
  6561. if (startRng) {
  6562. // Listen for selection change events
  6563. dom.bind(doc, 'mouseup', endSelection);
  6564. dom.bind(doc, 'mousemove', selectionChange);
  6565. dom.win.focus();
  6566. startRng.select();
  6567. }
  6568. }
  6569. });
  6570. }
  6571. });
  6572. })(tinymce);
  6573. (function(tinymce) {
  6574. tinymce.dom.Serializer = function(settings, dom, schema) {
  6575. var onPreProcess, onPostProcess, isIE = tinymce.isIE, each = tinymce.each, htmlParser;
  6576. // Support the old apply_source_formatting option
  6577. if (!settings.apply_source_formatting)
  6578. settings.indent = false;
  6579. settings.remove_trailing_brs = true;
  6580. // Default DOM and Schema if they are undefined
  6581. dom = dom || tinymce.DOM;
  6582. schema = schema || new tinymce.html.Schema(settings);
  6583. settings.entity_encoding = settings.entity_encoding || 'named';
  6584. onPreProcess = new tinymce.util.Dispatcher(self);
  6585. onPostProcess = new tinymce.util.Dispatcher(self);
  6586. htmlParser = new tinymce.html.DomParser(settings, schema);
  6587. // Convert move data-mce-src, data-mce-href and data-mce-style into nodes or process them if needed
  6588. htmlParser.addAttributeFilter('src,href,style', function(nodes, name) {
  6589. var i = nodes.length, node, value, internalName = 'data-mce-' + name, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope, undef;
  6590. while (i--) {
  6591. node = nodes[i];
  6592. value = node.attributes.map[internalName];
  6593. if (value !== undef) {
  6594. // Set external name to internal value and remove internal
  6595. node.attr(name, value.length > 0 ? value : null);
  6596. node.attr(internalName, null);
  6597. } else {
  6598. // No internal attribute found then convert the value we have in the DOM
  6599. value = node.attributes.map[name];
  6600. if (name === "style")
  6601. value = dom.serializeStyle(dom.parseStyle(value), node.name);
  6602. else if (urlConverter)
  6603. value = urlConverter.call(urlConverterScope, value, name, node.name);
  6604. node.attr(name, value.length > 0 ? value : null);
  6605. }
  6606. }
  6607. });
  6608. // Remove internal classes mceItem<..>
  6609. htmlParser.addAttributeFilter('class', function(nodes, name) {
  6610. var i = nodes.length, node, value;
  6611. while (i--) {
  6612. node = nodes[i];
  6613. value = node.attr('class').replace(/\s*mce(Item\w+|Selected)\s*/g, '');
  6614. node.attr('class', value.length > 0 ? value : null);
  6615. }
  6616. });
  6617. // Remove bookmark elements
  6618. htmlParser.addAttributeFilter('data-mce-type', function(nodes, name, args) {
  6619. var i = nodes.length, node;
  6620. while (i--) {
  6621. node = nodes[i];
  6622. if (node.attributes.map['data-mce-type'] === 'bookmark' && !args.cleanup)
  6623. node.remove();
  6624. }
  6625. });
  6626. // Force script into CDATA sections and remove the mce- prefix also add comments around styles
  6627. htmlParser.addNodeFilter('script,style', function(nodes, name) {
  6628. var i = nodes.length, node, value;
  6629. function trim(value) {
  6630. return value.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n')
  6631. .replace(/^[\r\n]*|[\r\n]*$/g, '')
  6632. .replace(/^\s*(\/\/\s*<!--|\/\/\s*<!\[CDATA\[|<!--|<!\[CDATA\[)[\r\n]*/g, '')
  6633. .replace(/\s*(\/\/\s*\]\]>|\/\/\s*-->|\]\]>|-->|\]\]-->)\s*$/g, '');
  6634. };
  6635. while (i--) {
  6636. node = nodes[i];
  6637. value = node.firstChild ? node.firstChild.value : '';
  6638. if (name === "script") {
  6639. // Remove mce- prefix from script elements
  6640. node.attr('type', (node.attr('type') || 'text/javascript').replace(/^mce\-/, ''));
  6641. if (value.length > 0)
  6642. node.firstChild.value = '// <![CDATA[\n' + trim(value) + '\n// ]]>';
  6643. } else {
  6644. if (value.length > 0)
  6645. node.firstChild.value = '<!--\n' + trim(value) + '\n-->';
  6646. }
  6647. }
  6648. });
  6649. // Convert comments to cdata and handle protected comments
  6650. htmlParser.addNodeFilter('#comment', function(nodes, name) {
  6651. var i = nodes.length, node;
  6652. while (i--) {
  6653. node = nodes[i];
  6654. if (node.value.indexOf('[CDATA[') === 0) {
  6655. node.name = '#cdata';
  6656. node.type = 4;
  6657. node.value = node.value.replace(/^\[CDATA\[|\]\]$/g, '');
  6658. } else if (node.value.indexOf('mce:protected ') === 0) {
  6659. node.name = "#text";
  6660. node.type = 3;
  6661. node.raw = true;
  6662. node.value = unescape(node.value).substr(14);
  6663. }
  6664. }
  6665. });
  6666. htmlParser.addNodeFilter('xml:namespace,input', function(nodes, name) {
  6667. var i = nodes.length, node;
  6668. while (i--) {
  6669. node = nodes[i];
  6670. if (node.type === 7)
  6671. node.remove();
  6672. else if (node.type === 1) {
  6673. if (name === "input" && !("type" in node.attributes.map))
  6674. node.attr('type', 'text');
  6675. }
  6676. }
  6677. });
  6678. // Fix list elements, TODO: Replace this later
  6679. if (settings.fix_list_elements) {
  6680. htmlParser.addNodeFilter('ul,ol', function(nodes, name) {
  6681. var i = nodes.length, node, parentNode;
  6682. while (i--) {
  6683. node = nodes[i];
  6684. parentNode = node.parent;
  6685. if (parentNode.name === 'ul' || parentNode.name === 'ol') {
  6686. if (node.prev && node.prev.name === 'li') {
  6687. node.prev.append(node);
  6688. }
  6689. }
  6690. }
  6691. });
  6692. }
  6693. // Remove internal data attributes
  6694. htmlParser.addAttributeFilter('data-mce-src,data-mce-href,data-mce-style', function(nodes, name) {
  6695. var i = nodes.length;
  6696. while (i--) {
  6697. nodes[i].attr(name, null);
  6698. }
  6699. });
  6700. // Return public methods
  6701. return {
  6702. schema : schema,
  6703. addNodeFilter : htmlParser.addNodeFilter,
  6704. addAttributeFilter : htmlParser.addAttributeFilter,
  6705. onPreProcess : onPreProcess,
  6706. onPostProcess : onPostProcess,
  6707. serialize : function(node, args) {
  6708. var impl, doc, oldDoc, htmlSerializer, content;
  6709. // Explorer won't clone contents of script and style and the
  6710. // selected index of select elements are cleared on a clone operation.
  6711. if (isIE && dom.select('script,style,select,map').length > 0) {
  6712. content = node.innerHTML;
  6713. node = node.cloneNode(false);
  6714. dom.setHTML(node, content);
  6715. } else
  6716. node = node.cloneNode(true);
  6717. // Nodes needs to be attached to something in WebKit/Opera
  6718. // Older builds of Opera crashes if you attach the node to an document created dynamically
  6719. // and since we can't feature detect a crash we need to sniff the acutal build number
  6720. // This fix will make DOM ranges and make Sizzle happy!
  6721. impl = node.ownerDocument.implementation;
  6722. if (impl.createHTMLDocument) {
  6723. // Create an empty HTML document
  6724. doc = impl.createHTMLDocument("");
  6725. // Add the element or it's children if it's a body element to the new document
  6726. each(node.nodeName == 'BODY' ? node.childNodes : [node], function(node) {
  6727. doc.body.appendChild(doc.importNode(node, true));
  6728. });
  6729. // Grab first child or body element for serialization
  6730. if (node.nodeName != 'BODY')
  6731. node = doc.body.firstChild;
  6732. else
  6733. node = doc.body;
  6734. // set the new document in DOMUtils so createElement etc works
  6735. oldDoc = dom.doc;
  6736. dom.doc = doc;
  6737. }
  6738. args = args || {};
  6739. args.format = args.format || 'html';
  6740. // Pre process
  6741. if (!args.no_events) {
  6742. args.node = node;
  6743. onPreProcess.dispatch(self, args);
  6744. }
  6745. // Setup serializer
  6746. htmlSerializer = new tinymce.html.Serializer(settings, schema);
  6747. // Parse and serialize HTML
  6748. args.content = htmlSerializer.serialize(
  6749. htmlParser.parse(args.getInner ? node.innerHTML : tinymce.trim(dom.getOuterHTML(node), args), args)
  6750. );
  6751. // Replace all BOM characters for now until we can find a better solution
  6752. if (!args.cleanup)
  6753. args.content = args.content.replace(/\uFEFF|\u200B/g, '');
  6754. // Post process
  6755. if (!args.no_events)
  6756. onPostProcess.dispatch(self, args);
  6757. // Restore the old document if it was changed
  6758. if (oldDoc)
  6759. dom.doc = oldDoc;
  6760. args.node = null;
  6761. return args.content;
  6762. },
  6763. addRules : function(rules) {
  6764. schema.addValidElements(rules);
  6765. },
  6766. setRules : function(rules) {
  6767. schema.setValidElements(rules);
  6768. }
  6769. };
  6770. };
  6771. })(tinymce);
  6772. (function(tinymce) {
  6773. tinymce.dom.ScriptLoader = function(settings) {
  6774. var QUEUED = 0,
  6775. LOADING = 1,
  6776. LOADED = 2,
  6777. states = {},
  6778. queue = [],
  6779. scriptLoadedCallbacks = {},
  6780. queueLoadedCallbacks = [],
  6781. loading = 0,
  6782. undefined;
  6783. function loadScript(url, callback) {
  6784. var t = this, dom = tinymce.DOM, elm, uri, loc, id;
  6785. // Execute callback when script is loaded
  6786. function done() {
  6787. dom.remove(id);
  6788. if (elm)
  6789. elm.onreadystatechange = elm.onload = elm = null;
  6790. callback();
  6791. };
  6792. function error() {
  6793. // Report the error so it's easier for people to spot loading errors
  6794. if (typeof(console) !== "undefined" && console.log)
  6795. console.log("Failed to load: " + url);
  6796. // We can't mark it as done if there is a load error since
  6797. // A) We don't want to produce 404 errors on the server and
  6798. // B) the onerror event won't fire on all browsers.
  6799. // done();
  6800. };
  6801. id = dom.uniqueId();
  6802. if (tinymce.isIE6) {
  6803. uri = new tinymce.util.URI(url);
  6804. loc = location;
  6805. // If script is from same domain and we
  6806. // use IE 6 then use XHR since it's more reliable
  6807. if (uri.host == loc.hostname && uri.port == loc.port && (uri.protocol + ':') == loc.protocol && uri.protocol.toLowerCase() != 'file') {
  6808. tinymce.util.XHR.send({
  6809. url : tinymce._addVer(uri.getURI()),
  6810. success : function(content) {
  6811. // Create new temp script element
  6812. var script = dom.create('script', {
  6813. type : 'text/javascript'
  6814. });
  6815. // Evaluate script in global scope
  6816. script.text = content;
  6817. document.getElementsByTagName('head')[0].appendChild(script);
  6818. dom.remove(script);
  6819. done();
  6820. },
  6821. error : error
  6822. });
  6823. return;
  6824. }
  6825. }
  6826. // Create new script element
  6827. elm = dom.create('script', {
  6828. id : id,
  6829. type : 'text/javascript',
  6830. src : tinymce._addVer(url)
  6831. });
  6832. // Add onload listener for non IE browsers since IE9
  6833. // fires onload event before the script is parsed and executed
  6834. if (!tinymce.isIE)
  6835. elm.onload = done;
  6836. // Add onerror event will get fired on some browsers but not all of them
  6837. elm.onerror = error;
  6838. // Opera 9.60 doesn't seem to fire the onreadystate event at correctly
  6839. if (!tinymce.isOpera) {
  6840. elm.onreadystatechange = function() {
  6841. var state = elm.readyState;
  6842. // Loaded state is passed on IE 6 however there
  6843. // are known issues with this method but we can't use
  6844. // XHR in a cross domain loading
  6845. if (state == 'complete' || state == 'loaded')
  6846. done();
  6847. };
  6848. }
  6849. // Most browsers support this feature so we report errors
  6850. // for those at least to help users track their missing plugins etc
  6851. // todo: Removed since it produced error if the document is unloaded by navigating away, re-add it as an option
  6852. /*elm.onerror = function() {
  6853. alert('Failed to load: ' + url);
  6854. };*/
  6855. // Add script to document
  6856. (document.getElementsByTagName('head')[0] || document.body).appendChild(elm);
  6857. };
  6858. this.isDone = function(url) {
  6859. return states[url] == LOADED;
  6860. };
  6861. this.markDone = function(url) {
  6862. states[url] = LOADED;
  6863. };
  6864. this.add = this.load = function(url, callback, scope) {
  6865. var item, state = states[url];
  6866. // Add url to load queue
  6867. if (state == undefined) {
  6868. queue.push(url);
  6869. states[url] = QUEUED;
  6870. }
  6871. if (callback) {
  6872. // Store away callback for later execution
  6873. if (!scriptLoadedCallbacks[url])
  6874. scriptLoadedCallbacks[url] = [];
  6875. scriptLoadedCallbacks[url].push({
  6876. func : callback,
  6877. scope : scope || this
  6878. });
  6879. }
  6880. };
  6881. this.loadQueue = function(callback, scope) {
  6882. this.loadScripts(queue, callback, scope);
  6883. };
  6884. this.loadScripts = function(scripts, callback, scope) {
  6885. var loadScripts;
  6886. function execScriptLoadedCallbacks(url) {
  6887. // Execute URL callback functions
  6888. tinymce.each(scriptLoadedCallbacks[url], function(callback) {
  6889. callback.func.call(callback.scope);
  6890. });
  6891. scriptLoadedCallbacks[url] = undefined;
  6892. };
  6893. queueLoadedCallbacks.push({
  6894. func : callback,
  6895. scope : scope || this
  6896. });
  6897. loadScripts = function() {
  6898. var loadingScripts = tinymce.grep(scripts);
  6899. // Current scripts has been handled
  6900. scripts.length = 0;
  6901. // Load scripts that needs to be loaded
  6902. tinymce.each(loadingScripts, function(url) {
  6903. // Script is already loaded then execute script callbacks directly
  6904. if (states[url] == LOADED) {
  6905. execScriptLoadedCallbacks(url);
  6906. return;
  6907. }
  6908. // Is script not loading then start loading it
  6909. if (states[url] != LOADING) {
  6910. states[url] = LOADING;
  6911. loading++;
  6912. loadScript(url, function() {
  6913. states[url] = LOADED;
  6914. loading--;
  6915. execScriptLoadedCallbacks(url);
  6916. // Load more scripts if they where added by the recently loaded script
  6917. loadScripts();
  6918. });
  6919. }
  6920. });
  6921. // No scripts are currently loading then execute all pending queue loaded callbacks
  6922. if (!loading) {
  6923. tinymce.each(queueLoadedCallbacks, function(callback) {
  6924. callback.func.call(callback.scope);
  6925. });
  6926. queueLoadedCallbacks.length = 0;
  6927. }
  6928. };
  6929. loadScripts();
  6930. };
  6931. };
  6932. // Global script loader
  6933. tinymce.ScriptLoader = new tinymce.dom.ScriptLoader();
  6934. })(tinymce);
  6935. tinymce.dom.TreeWalker = function(start_node, root_node) {
  6936. var node = start_node;
  6937. function findSibling(node, start_name, sibling_name, shallow) {
  6938. var sibling, parent;
  6939. if (node) {
  6940. // Walk into nodes if it has a start
  6941. if (!shallow && node[start_name])
  6942. return node[start_name];
  6943. // Return the sibling if it has one
  6944. if (node != root_node) {
  6945. sibling = node[sibling_name];
  6946. if (sibling)
  6947. return sibling;
  6948. // Walk up the parents to look for siblings
  6949. for (parent = node.parentNode; parent && parent != root_node; parent = parent.parentNode) {
  6950. sibling = parent[sibling_name];
  6951. if (sibling)
  6952. return sibling;
  6953. }
  6954. }
  6955. }
  6956. };
  6957. this.current = function() {
  6958. return node;
  6959. };
  6960. this.next = function(shallow) {
  6961. return (node = findSibling(node, 'firstChild', 'nextSibling', shallow));
  6962. };
  6963. this.prev = function(shallow) {
  6964. return (node = findSibling(node, 'lastChild', 'previousSibling', shallow));
  6965. };
  6966. };
  6967. (function(tinymce) {
  6968. tinymce.dom.RangeUtils = function(dom) {
  6969. var INVISIBLE_CHAR = '\uFEFF';
  6970. this.walk = function(rng, callback) {
  6971. var startContainer = rng.startContainer,
  6972. startOffset = rng.startOffset,
  6973. endContainer = rng.endContainer,
  6974. endOffset = rng.endOffset,
  6975. ancestor, startPoint,
  6976. endPoint, node, parent, siblings, nodes;
  6977. // Handle table cell selection the table plugin enables
  6978. // you to fake select table cells and perform formatting actions on them
  6979. nodes = dom.select('td.mceSelected,th.mceSelected');
  6980. if (nodes.length > 0) {
  6981. tinymce.each(nodes, function(node) {
  6982. callback([node]);
  6983. });
  6984. return;
  6985. }
  6986. function exclude(nodes) {
  6987. var node;
  6988. // First node is excluded
  6989. node = nodes[0];
  6990. if (node.nodeType === 3 && node === startContainer && startOffset >= node.nodeValue.length) {
  6991. nodes.splice(0, 1);
  6992. }
  6993. // Last node is excluded
  6994. node = nodes[nodes.length - 1];
  6995. if (endOffset === 0 && nodes.length > 0 && node === endContainer && node.nodeType === 3) {
  6996. nodes.splice(nodes.length - 1, 1);
  6997. }
  6998. return nodes;
  6999. };
  7000. function collectSiblings(node, name, end_node) {
  7001. var siblings = [];
  7002. for (; node && node != end_node; node = node[name])
  7003. siblings.push(node);
  7004. return siblings;
  7005. };
  7006. function findEndPoint(node, root) {
  7007. do {
  7008. if (node.parentNode == root)
  7009. return node;
  7010. node = node.parentNode;
  7011. } while(node);
  7012. };
  7013. function walkBoundary(start_node, end_node, next) {
  7014. var siblingName = next ? 'nextSibling' : 'previousSibling';
  7015. for (node = start_node, parent = node.parentNode; node && node != end_node; node = parent) {
  7016. parent = node.parentNode;
  7017. siblings = collectSiblings(node == start_node ? node : node[siblingName], siblingName);
  7018. if (siblings.length) {
  7019. if (!next)
  7020. siblings.reverse();
  7021. callback(exclude(siblings));
  7022. }
  7023. }
  7024. };
  7025. // If index based start position then resolve it
  7026. if (startContainer.nodeType == 1 && startContainer.hasChildNodes())
  7027. startContainer = startContainer.childNodes[startOffset];
  7028. // If index based end position then resolve it
  7029. if (endContainer.nodeType == 1 && endContainer.hasChildNodes())
  7030. endContainer = endContainer.childNodes[Math.min(endOffset - 1, endContainer.childNodes.length - 1)];
  7031. // Same container
  7032. if (startContainer == endContainer)
  7033. return callback(exclude([startContainer]));
  7034. // Find common ancestor and end points
  7035. ancestor = dom.findCommonAncestor(startContainer, endContainer);
  7036. // Process left side
  7037. for (node = startContainer; node; node = node.parentNode) {
  7038. if (node === endContainer)
  7039. return walkBoundary(startContainer, ancestor, true);
  7040. if (node === ancestor)
  7041. break;
  7042. }
  7043. // Process right side
  7044. for (node = endContainer; node; node = node.parentNode) {
  7045. if (node === startContainer)
  7046. return walkBoundary(endContainer, ancestor);
  7047. if (node === ancestor)
  7048. break;
  7049. }
  7050. // Find start/end point
  7051. startPoint = findEndPoint(startContainer, ancestor) || startContainer;
  7052. endPoint = findEndPoint(endContainer, ancestor) || endContainer;
  7053. // Walk left leaf
  7054. walkBoundary(startContainer, startPoint, true);
  7055. // Walk the middle from start to end point
  7056. siblings = collectSiblings(
  7057. startPoint == startContainer ? startPoint : startPoint.nextSibling,
  7058. 'nextSibling',
  7059. endPoint == endContainer ? endPoint.nextSibling : endPoint
  7060. );
  7061. if (siblings.length)
  7062. callback(exclude(siblings));
  7063. // Walk right leaf
  7064. walkBoundary(endContainer, endPoint);
  7065. };
  7066. this.split = function(rng) {
  7067. var startContainer = rng.startContainer,
  7068. startOffset = rng.startOffset,
  7069. endContainer = rng.endContainer,
  7070. endOffset = rng.endOffset;
  7071. function splitText(node, offset) {
  7072. return node.splitText(offset);
  7073. };
  7074. // Handle single text node
  7075. if (startContainer == endContainer && startContainer.nodeType == 3) {
  7076. if (startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  7077. endContainer = splitText(startContainer, startOffset);
  7078. startContainer = endContainer.previousSibling;
  7079. if (endOffset > startOffset) {
  7080. endOffset = endOffset - startOffset;
  7081. startContainer = endContainer = splitText(endContainer, endOffset).previousSibling;
  7082. endOffset = endContainer.nodeValue.length;
  7083. startOffset = 0;
  7084. } else {
  7085. endOffset = 0;
  7086. }
  7087. }
  7088. } else {
  7089. // Split startContainer text node if needed
  7090. if (startContainer.nodeType == 3 && startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  7091. startContainer = splitText(startContainer, startOffset);
  7092. startOffset = 0;
  7093. }
  7094. // Split endContainer text node if needed
  7095. if (endContainer.nodeType == 3 && endOffset > 0 && endOffset < endContainer.nodeValue.length) {
  7096. endContainer = splitText(endContainer, endOffset).previousSibling;
  7097. endOffset = endContainer.nodeValue.length;
  7098. }
  7099. }
  7100. return {
  7101. startContainer : startContainer,
  7102. startOffset : startOffset,
  7103. endContainer : endContainer,
  7104. endOffset : endOffset
  7105. };
  7106. };
  7107. };
  7108. tinymce.dom.RangeUtils.compareRanges = function(rng1, rng2) {
  7109. if (rng1 && rng2) {
  7110. // Compare native IE ranges
  7111. if (rng1.item || rng1.duplicate) {
  7112. // Both are control ranges and the selected element matches
  7113. if (rng1.item && rng2.item && rng1.item(0) === rng2.item(0))
  7114. return true;
  7115. // Both are text ranges and the range matches
  7116. if (rng1.isEqual && rng2.isEqual && rng2.isEqual(rng1))
  7117. return true;
  7118. } else {
  7119. // Compare w3c ranges
  7120. return rng1.startContainer == rng2.startContainer && rng1.startOffset == rng2.startOffset;
  7121. }
  7122. }
  7123. return false;
  7124. };
  7125. })(tinymce);
  7126. (function(tinymce) {
  7127. var Event = tinymce.dom.Event, each = tinymce.each;
  7128. tinymce.create('tinymce.ui.KeyboardNavigation', {
  7129. KeyboardNavigation: function(settings, dom) {
  7130. var t = this, root = settings.root, items = settings.items,
  7131. enableUpDown = settings.enableUpDown, enableLeftRight = settings.enableLeftRight || !settings.enableUpDown,
  7132. excludeFromTabOrder = settings.excludeFromTabOrder,
  7133. itemFocussed, itemBlurred, rootKeydown, rootFocussed, focussedId;
  7134. dom = dom || tinymce.DOM;
  7135. itemFocussed = function(evt) {
  7136. focussedId = evt.target.id;
  7137. };
  7138. itemBlurred = function(evt) {
  7139. dom.setAttrib(evt.target.id, 'tabindex', '-1');
  7140. };
  7141. rootFocussed = function(evt) {
  7142. var item = dom.get(focussedId);
  7143. dom.setAttrib(item, 'tabindex', '0');
  7144. item.focus();
  7145. };
  7146. t.focus = function() {
  7147. dom.get(focussedId).focus();
  7148. };
  7149. t.destroy = function() {
  7150. each(items, function(item) {
  7151. dom.unbind(dom.get(item.id), 'focus', itemFocussed);
  7152. dom.unbind(dom.get(item.id), 'blur', itemBlurred);
  7153. });
  7154. dom.unbind(dom.get(root), 'focus', rootFocussed);
  7155. dom.unbind(dom.get(root), 'keydown', rootKeydown);
  7156. items = dom = root = t.focus = itemFocussed = itemBlurred = rootKeydown = rootFocussed = null;
  7157. t.destroy = function() {};
  7158. };
  7159. t.moveFocus = function(dir, evt) {
  7160. var idx = -1, controls = t.controls, newFocus;
  7161. if (!focussedId)
  7162. return;
  7163. each(items, function(item, index) {
  7164. if (item.id === focussedId) {
  7165. idx = index;
  7166. return false;
  7167. }
  7168. });
  7169. idx += dir;
  7170. if (idx < 0) {
  7171. idx = items.length - 1;
  7172. } else if (idx >= items.length) {
  7173. idx = 0;
  7174. }
  7175. newFocus = items[idx];
  7176. dom.setAttrib(focussedId, 'tabindex', '-1');
  7177. dom.setAttrib(newFocus.id, 'tabindex', '0');
  7178. dom.get(newFocus.id).focus();
  7179. if (settings.actOnFocus) {
  7180. settings.onAction(newFocus.id);
  7181. }
  7182. if (evt)
  7183. Event.cancel(evt);
  7184. };
  7185. rootKeydown = function(evt) {
  7186. 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;
  7187. switch (evt.keyCode) {
  7188. case DOM_VK_LEFT:
  7189. if (enableLeftRight) t.moveFocus(-1);
  7190. break;
  7191. case DOM_VK_RIGHT:
  7192. if (enableLeftRight) t.moveFocus(1);
  7193. break;
  7194. case DOM_VK_UP:
  7195. if (enableUpDown) t.moveFocus(-1);
  7196. break;
  7197. case DOM_VK_DOWN:
  7198. if (enableUpDown) t.moveFocus(1);
  7199. break;
  7200. case DOM_VK_ESCAPE:
  7201. if (settings.onCancel) {
  7202. settings.onCancel();
  7203. Event.cancel(evt);
  7204. }
  7205. break;
  7206. case DOM_VK_ENTER:
  7207. case DOM_VK_RETURN:
  7208. case DOM_VK_SPACE:
  7209. if (settings.onAction) {
  7210. settings.onAction(focussedId);
  7211. Event.cancel(evt);
  7212. }
  7213. break;
  7214. }
  7215. };
  7216. // Set up state and listeners for each item.
  7217. each(items, function(item, idx) {
  7218. var tabindex;
  7219. if (!item.id) {
  7220. item.id = dom.uniqueId('_mce_item_');
  7221. }
  7222. if (excludeFromTabOrder) {
  7223. dom.bind(item.id, 'blur', itemBlurred);
  7224. tabindex = '-1';
  7225. } else {
  7226. tabindex = (idx === 0 ? '0' : '-1');
  7227. }
  7228. dom.setAttrib(item.id, 'tabindex', tabindex);
  7229. dom.bind(dom.get(item.id), 'focus', itemFocussed);
  7230. });
  7231. // Setup initial state for root element.
  7232. if (items[0]){
  7233. focussedId = items[0].id;
  7234. }
  7235. dom.setAttrib(root, 'tabindex', '-1');
  7236. // Setup listeners for root element.
  7237. dom.bind(dom.get(root), 'focus', rootFocussed);
  7238. dom.bind(dom.get(root), 'keydown', rootKeydown);
  7239. }
  7240. });
  7241. })(tinymce);
  7242. (function(tinymce) {
  7243. // Shorten class names
  7244. var DOM = tinymce.DOM, is = tinymce.is;
  7245. tinymce.create('tinymce.ui.Control', {
  7246. Control : function(id, s, editor) {
  7247. this.id = id;
  7248. this.settings = s = s || {};
  7249. this.rendered = false;
  7250. this.onRender = new tinymce.util.Dispatcher(this);
  7251. this.classPrefix = '';
  7252. this.scope = s.scope || this;
  7253. this.disabled = 0;
  7254. this.active = 0;
  7255. this.editor = editor;
  7256. },
  7257. setAriaProperty : function(property, value) {
  7258. var element = DOM.get(this.id + '_aria') || DOM.get(this.id);
  7259. if (element) {
  7260. DOM.setAttrib(element, 'aria-' + property, !!value);
  7261. }
  7262. },
  7263. focus : function() {
  7264. DOM.get(this.id).focus();
  7265. },
  7266. setDisabled : function(s) {
  7267. if (s != this.disabled) {
  7268. this.setAriaProperty('disabled', s);
  7269. this.setState('Disabled', s);
  7270. this.setState('Enabled', !s);
  7271. this.disabled = s;
  7272. }
  7273. },
  7274. isDisabled : function() {
  7275. return this.disabled;
  7276. },
  7277. setActive : function(s) {
  7278. if (s != this.active) {
  7279. this.setState('Active', s);
  7280. this.active = s;
  7281. this.setAriaProperty('pressed', s);
  7282. }
  7283. },
  7284. isActive : function() {
  7285. return this.active;
  7286. },
  7287. setState : function(c, s) {
  7288. var n = DOM.get(this.id);
  7289. c = this.classPrefix + c;
  7290. if (s)
  7291. DOM.addClass(n, c);
  7292. else
  7293. DOM.removeClass(n, c);
  7294. },
  7295. isRendered : function() {
  7296. return this.rendered;
  7297. },
  7298. renderHTML : function() {
  7299. },
  7300. renderTo : function(n) {
  7301. DOM.setHTML(n, this.renderHTML());
  7302. },
  7303. postRender : function() {
  7304. var t = this, b;
  7305. // Set pending states
  7306. if (is(t.disabled)) {
  7307. b = t.disabled;
  7308. t.disabled = -1;
  7309. t.setDisabled(b);
  7310. }
  7311. if (is(t.active)) {
  7312. b = t.active;
  7313. t.active = -1;
  7314. t.setActive(b);
  7315. }
  7316. },
  7317. remove : function() {
  7318. DOM.remove(this.id);
  7319. this.destroy();
  7320. },
  7321. destroy : function() {
  7322. tinymce.dom.Event.clear(this.id);
  7323. }
  7324. });
  7325. })(tinymce);
  7326. tinymce.create('tinymce.ui.Container:tinymce.ui.Control', {
  7327. Container : function(id, s, editor) {
  7328. this.parent(id, s, editor);
  7329. this.controls = [];
  7330. this.lookup = {};
  7331. },
  7332. add : function(c) {
  7333. this.lookup[c.id] = c;
  7334. this.controls.push(c);
  7335. return c;
  7336. },
  7337. get : function(n) {
  7338. return this.lookup[n];
  7339. }
  7340. });
  7341. tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', {
  7342. Separator : function(id, s) {
  7343. this.parent(id, s);
  7344. this.classPrefix = 'mceSeparator';
  7345. this.setDisabled(true);
  7346. },
  7347. renderHTML : function() {
  7348. return tinymce.DOM.createHTML('span', {'class' : this.classPrefix, role : 'separator', 'aria-orientation' : 'vertical', tabindex : '-1'});
  7349. }
  7350. });
  7351. (function(tinymce) {
  7352. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  7353. tinymce.create('tinymce.ui.MenuItem:tinymce.ui.Control', {
  7354. MenuItem : function(id, s) {
  7355. this.parent(id, s);
  7356. this.classPrefix = 'mceMenuItem';
  7357. },
  7358. setSelected : function(s) {
  7359. this.setState('Selected', s);
  7360. this.setAriaProperty('checked', !!s);
  7361. this.selected = s;
  7362. },
  7363. isSelected : function() {
  7364. return this.selected;
  7365. },
  7366. postRender : function() {
  7367. var t = this;
  7368. t.parent();
  7369. // Set pending state
  7370. if (is(t.selected))
  7371. t.setSelected(t.selected);
  7372. }
  7373. });
  7374. })(tinymce);
  7375. (function(tinymce) {
  7376. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  7377. tinymce.create('tinymce.ui.Menu:tinymce.ui.MenuItem', {
  7378. Menu : function(id, s) {
  7379. var t = this;
  7380. t.parent(id, s);
  7381. t.items = {};
  7382. t.collapsed = false;
  7383. t.menuCount = 0;
  7384. t.onAddItem = new tinymce.util.Dispatcher(this);
  7385. },
  7386. expand : function(d) {
  7387. var t = this;
  7388. if (d) {
  7389. walk(t, function(o) {
  7390. if (o.expand)
  7391. o.expand();
  7392. }, 'items', t);
  7393. }
  7394. t.collapsed = false;
  7395. },
  7396. collapse : function(d) {
  7397. var t = this;
  7398. if (d) {
  7399. walk(t, function(o) {
  7400. if (o.collapse)
  7401. o.collapse();
  7402. }, 'items', t);
  7403. }
  7404. t.collapsed = true;
  7405. },
  7406. isCollapsed : function() {
  7407. return this.collapsed;
  7408. },
  7409. add : function(o) {
  7410. if (!o.settings)
  7411. o = new tinymce.ui.MenuItem(o.id || DOM.uniqueId(), o);
  7412. this.onAddItem.dispatch(this, o);
  7413. return this.items[o.id] = o;
  7414. },
  7415. addSeparator : function() {
  7416. return this.add({separator : true});
  7417. },
  7418. addMenu : function(o) {
  7419. if (!o.collapse)
  7420. o = this.createMenu(o);
  7421. this.menuCount++;
  7422. return this.add(o);
  7423. },
  7424. hasMenus : function() {
  7425. return this.menuCount !== 0;
  7426. },
  7427. remove : function(o) {
  7428. delete this.items[o.id];
  7429. },
  7430. removeAll : function() {
  7431. var t = this;
  7432. walk(t, function(o) {
  7433. if (o.removeAll)
  7434. o.removeAll();
  7435. else
  7436. o.remove();
  7437. o.destroy();
  7438. }, 'items', t);
  7439. t.items = {};
  7440. },
  7441. createMenu : function(o) {
  7442. var m = new tinymce.ui.Menu(o.id || DOM.uniqueId(), o);
  7443. m.onAddItem.add(this.onAddItem.dispatch, this.onAddItem);
  7444. return m;
  7445. }
  7446. });
  7447. })(tinymce);
  7448. (function(tinymce) {
  7449. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event, Element = tinymce.dom.Element;
  7450. tinymce.create('tinymce.ui.DropMenu:tinymce.ui.Menu', {
  7451. DropMenu : function(id, s) {
  7452. s = s || {};
  7453. s.container = s.container || DOM.doc.body;
  7454. s.offset_x = s.offset_x || 0;
  7455. s.offset_y = s.offset_y || 0;
  7456. s.vp_offset_x = s.vp_offset_x || 0;
  7457. s.vp_offset_y = s.vp_offset_y || 0;
  7458. if (is(s.icons) && !s.icons)
  7459. s['class'] += ' mceNoIcons';
  7460. this.parent(id, s);
  7461. this.onShowMenu = new tinymce.util.Dispatcher(this);
  7462. this.onHideMenu = new tinymce.util.Dispatcher(this);
  7463. this.classPrefix = 'mceMenu';
  7464. },
  7465. createMenu : function(s) {
  7466. var t = this, cs = t.settings, m;
  7467. s.container = s.container || cs.container;
  7468. s.parent = t;
  7469. s.constrain = s.constrain || cs.constrain;
  7470. s['class'] = s['class'] || cs['class'];
  7471. s.vp_offset_x = s.vp_offset_x || cs.vp_offset_x;
  7472. s.vp_offset_y = s.vp_offset_y || cs.vp_offset_y;
  7473. s.keyboard_focus = cs.keyboard_focus;
  7474. m = new tinymce.ui.DropMenu(s.id || DOM.uniqueId(), s);
  7475. m.onAddItem.add(t.onAddItem.dispatch, t.onAddItem);
  7476. return m;
  7477. },
  7478. focus : function() {
  7479. var t = this;
  7480. if (t.keyboardNav) {
  7481. t.keyboardNav.focus();
  7482. }
  7483. },
  7484. update : function() {
  7485. var t = this, s = t.settings, tb = DOM.get('menu_' + t.id + '_tbl'), co = DOM.get('menu_' + t.id + '_co'), tw, th;
  7486. tw = s.max_width ? Math.min(tb.clientWidth, s.max_width) : tb.clientWidth;
  7487. th = s.max_height ? Math.min(tb.clientHeight, s.max_height) : tb.clientHeight;
  7488. if (!DOM.boxModel)
  7489. t.element.setStyles({width : tw + 2, height : th + 2});
  7490. else
  7491. t.element.setStyles({width : tw, height : th});
  7492. if (s.max_width)
  7493. DOM.setStyle(co, 'width', tw);
  7494. if (s.max_height) {
  7495. DOM.setStyle(co, 'height', th);
  7496. if (tb.clientHeight < s.max_height)
  7497. DOM.setStyle(co, 'overflow', 'hidden');
  7498. }
  7499. },
  7500. showMenu : function(x, y, px) {
  7501. var t = this, s = t.settings, co, vp = DOM.getViewPort(), w, h, mx, my, ot = 2, dm, tb, cp = t.classPrefix;
  7502. t.collapse(1);
  7503. if (t.isMenuVisible)
  7504. return;
  7505. if (!t.rendered) {
  7506. co = DOM.add(t.settings.container, t.renderNode());
  7507. each(t.items, function(o) {
  7508. o.postRender();
  7509. });
  7510. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  7511. } else
  7512. co = DOM.get('menu_' + t.id);
  7513. // Move layer out of sight unless it's Opera since it scrolls to top of page due to an bug
  7514. if (!tinymce.isOpera)
  7515. DOM.setStyles(co, {left : -0xFFFF , top : -0xFFFF});
  7516. DOM.show(co);
  7517. t.update();
  7518. x += s.offset_x || 0;
  7519. y += s.offset_y || 0;
  7520. vp.w -= 4;
  7521. vp.h -= 4;
  7522. // Move inside viewport if not submenu
  7523. if (s.constrain) {
  7524. w = co.clientWidth - ot;
  7525. h = co.clientHeight - ot;
  7526. mx = vp.x + vp.w;
  7527. my = vp.y + vp.h;
  7528. if ((x + s.vp_offset_x + w) > mx)
  7529. x = px ? px - w : Math.max(0, (mx - s.vp_offset_x) - w);
  7530. if ((y + s.vp_offset_y + h) > my)
  7531. y = Math.max(0, (my - s.vp_offset_y) - h);
  7532. }
  7533. DOM.setStyles(co, {left : x , top : y});
  7534. t.element.update();
  7535. t.isMenuVisible = 1;
  7536. t.mouseClickFunc = Event.add(co, 'click', function(e) {
  7537. var m;
  7538. e = e.target;
  7539. if (e && (e = DOM.getParent(e, 'tr')) && !DOM.hasClass(e, cp + 'ItemSub')) {
  7540. m = t.items[e.id];
  7541. if (m.isDisabled())
  7542. return;
  7543. dm = t;
  7544. while (dm) {
  7545. if (dm.hideMenu)
  7546. dm.hideMenu();
  7547. dm = dm.settings.parent;
  7548. }
  7549. if (m.settings.onclick)
  7550. m.settings.onclick(e);
  7551. return Event.cancel(e); // Cancel to fix onbeforeunload problem
  7552. }
  7553. });
  7554. if (t.hasMenus()) {
  7555. t.mouseOverFunc = Event.add(co, 'mouseover', function(e) {
  7556. var m, r, mi;
  7557. e = e.target;
  7558. if (e && (e = DOM.getParent(e, 'tr'))) {
  7559. m = t.items[e.id];
  7560. if (t.lastMenu)
  7561. t.lastMenu.collapse(1);
  7562. if (m.isDisabled())
  7563. return;
  7564. if (e && DOM.hasClass(e, cp + 'ItemSub')) {
  7565. //p = DOM.getPos(s.container);
  7566. r = DOM.getRect(e);
  7567. m.showMenu((r.x + r.w - ot), r.y - ot, r.x);
  7568. t.lastMenu = m;
  7569. DOM.addClass(DOM.get(m.id).firstChild, cp + 'ItemActive');
  7570. }
  7571. }
  7572. });
  7573. }
  7574. Event.add(co, 'keydown', t._keyHandler, t);
  7575. t.onShowMenu.dispatch(t);
  7576. if (s.keyboard_focus) {
  7577. t._setupKeyboardNav();
  7578. }
  7579. },
  7580. hideMenu : function(c) {
  7581. var t = this, co = DOM.get('menu_' + t.id), e;
  7582. if (!t.isMenuVisible)
  7583. return;
  7584. if (t.keyboardNav) t.keyboardNav.destroy();
  7585. Event.remove(co, 'mouseover', t.mouseOverFunc);
  7586. Event.remove(co, 'click', t.mouseClickFunc);
  7587. Event.remove(co, 'keydown', t._keyHandler);
  7588. DOM.hide(co);
  7589. t.isMenuVisible = 0;
  7590. if (!c)
  7591. t.collapse(1);
  7592. if (t.element)
  7593. t.element.hide();
  7594. if (e = DOM.get(t.id))
  7595. DOM.removeClass(e.firstChild, t.classPrefix + 'ItemActive');
  7596. t.onHideMenu.dispatch(t);
  7597. },
  7598. add : function(o) {
  7599. var t = this, co;
  7600. o = t.parent(o);
  7601. if (t.isRendered && (co = DOM.get('menu_' + t.id)))
  7602. t._add(DOM.select('tbody', co)[0], o);
  7603. return o;
  7604. },
  7605. collapse : function(d) {
  7606. this.parent(d);
  7607. this.hideMenu(1);
  7608. },
  7609. remove : function(o) {
  7610. DOM.remove(o.id);
  7611. this.destroy();
  7612. return this.parent(o);
  7613. },
  7614. destroy : function() {
  7615. var t = this, co = DOM.get('menu_' + t.id);
  7616. if (t.keyboardNav) t.keyboardNav.destroy();
  7617. Event.remove(co, 'mouseover', t.mouseOverFunc);
  7618. Event.remove(DOM.select('a', co), 'focus', t.mouseOverFunc);
  7619. Event.remove(co, 'click', t.mouseClickFunc);
  7620. Event.remove(co, 'keydown', t._keyHandler);
  7621. if (t.element)
  7622. t.element.remove();
  7623. DOM.remove(co);
  7624. },
  7625. renderNode : function() {
  7626. var t = this, s = t.settings, n, tb, co, w;
  7627. 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'});
  7628. if (t.settings.parent) {
  7629. DOM.setAttrib(w, 'aria-parent', 'menu_' + t.settings.parent.id);
  7630. }
  7631. co = DOM.add(w, 'div', {role: 'presentation', id : 'menu_' + t.id + '_co', 'class' : t.classPrefix + (s['class'] ? ' ' + s['class'] : '')});
  7632. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  7633. if (s.menu_line)
  7634. DOM.add(co, 'span', {'class' : t.classPrefix + 'Line'});
  7635. // n = DOM.add(co, 'div', {id : 'menu_' + t.id + '_co', 'class' : 'mceMenuContainer'});
  7636. n = DOM.add(co, 'table', {role: 'presentation', id : 'menu_' + t.id + '_tbl', border : 0, cellPadding : 0, cellSpacing : 0});
  7637. tb = DOM.add(n, 'tbody');
  7638. each(t.items, function(o) {
  7639. t._add(tb, o);
  7640. });
  7641. t.rendered = true;
  7642. return w;
  7643. },
  7644. // Internal functions
  7645. _setupKeyboardNav : function(){
  7646. var contextMenu, menuItems, t=this;
  7647. contextMenu = DOM.select('#menu_' + t.id)[0];
  7648. menuItems = DOM.select('a[role=option]', 'menu_' + t.id);
  7649. menuItems.splice(0,0,contextMenu);
  7650. t.keyboardNav = new tinymce.ui.KeyboardNavigation({
  7651. root: 'menu_' + t.id,
  7652. items: menuItems,
  7653. onCancel: function() {
  7654. t.hideMenu();
  7655. },
  7656. enableUpDown: true
  7657. });
  7658. contextMenu.focus();
  7659. },
  7660. _keyHandler : function(evt) {
  7661. var t = this, e;
  7662. switch (evt.keyCode) {
  7663. case 37: // Left
  7664. if (t.settings.parent) {
  7665. t.hideMenu();
  7666. t.settings.parent.focus();
  7667. Event.cancel(evt);
  7668. }
  7669. break;
  7670. case 39: // Right
  7671. if (t.mouseOverFunc)
  7672. t.mouseOverFunc(evt);
  7673. break;
  7674. }
  7675. },
  7676. _add : function(tb, o) {
  7677. var n, s = o.settings, a, ro, it, cp = this.classPrefix, ic;
  7678. if (s.separator) {
  7679. ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'ItemSeparator'});
  7680. DOM.add(ro, 'td', {'class' : cp + 'ItemSeparator'});
  7681. if (n = ro.previousSibling)
  7682. DOM.addClass(n, 'mceLast');
  7683. return;
  7684. }
  7685. n = ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'Item ' + cp + 'ItemEnabled'});
  7686. n = it = DOM.add(n, s.titleItem ? 'th' : 'td');
  7687. n = a = DOM.add(n, 'a', {id: o.id + '_aria', role: s.titleItem ? 'presentation' : 'option', href : 'javascript:;', onclick : "return false;", onmousedown : 'return false;'});
  7688. if (s.parent) {
  7689. DOM.setAttrib(a, 'aria-haspopup', 'true');
  7690. DOM.setAttrib(a, 'aria-owns', 'menu_' + o.id);
  7691. }
  7692. DOM.addClass(it, s['class']);
  7693. // n = DOM.add(n, 'span', {'class' : 'item'});
  7694. ic = DOM.add(n, 'span', {'class' : 'mceIcon' + (s.icon ? ' mce_' + s.icon : '')});
  7695. if (s.icon_src)
  7696. DOM.add(ic, 'img', {src : s.icon_src});
  7697. n = DOM.add(n, s.element || 'span', {'class' : 'mceText', title : o.settings.title}, o.settings.title);
  7698. if (o.settings.style)
  7699. DOM.setAttrib(n, 'style', o.settings.style);
  7700. if (tb.childNodes.length == 1)
  7701. DOM.addClass(ro, 'mceFirst');
  7702. if ((n = ro.previousSibling) && DOM.hasClass(n, cp + 'ItemSeparator'))
  7703. DOM.addClass(ro, 'mceFirst');
  7704. if (o.collapse)
  7705. DOM.addClass(ro, cp + 'ItemSub');
  7706. if (n = ro.previousSibling)
  7707. DOM.removeClass(n, 'mceLast');
  7708. DOM.addClass(ro, 'mceLast');
  7709. }
  7710. });
  7711. })(tinymce);
  7712. (function(tinymce) {
  7713. var DOM = tinymce.DOM;
  7714. tinymce.create('tinymce.ui.Button:tinymce.ui.Control', {
  7715. Button : function(id, s, ed) {
  7716. this.parent(id, s, ed);
  7717. this.classPrefix = 'mceButton';
  7718. },
  7719. renderHTML : function() {
  7720. var cp = this.classPrefix, s = this.settings, h, l;
  7721. l = DOM.encode(s.label || '');
  7722. 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) + '">';
  7723. if (s.image && !(this.editor &&this.editor.forcedHighContrastMode) )
  7724. h += '<img class="mceIcon" src="' + s.image + '" alt="' + DOM.encode(s.title) + '" />' + l;
  7725. else
  7726. h += '<span class="mceIcon ' + s['class'] + '"></span>' + (l ? '<span class="' + cp + 'Label">' + l + '</span>' : '');
  7727. h += '<span class="mceVoiceLabel mceIconOnly" style="display: none;" id="' + this.id + '_voice">' + s.title + '</span>';
  7728. h += '</a>';
  7729. return h;
  7730. },
  7731. postRender : function() {
  7732. var t = this, s = t.settings;
  7733. tinymce.dom.Event.add(t.id, 'click', function(e) {
  7734. if (!t.isDisabled())
  7735. return s.onclick.call(s.scope, e);
  7736. });
  7737. }
  7738. });
  7739. })(tinymce);
  7740. (function(tinymce) {
  7741. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher;
  7742. tinymce.create('tinymce.ui.ListBox:tinymce.ui.Control', {
  7743. ListBox : function(id, s, ed) {
  7744. var t = this;
  7745. t.parent(id, s, ed);
  7746. t.items = [];
  7747. t.onChange = new Dispatcher(t);
  7748. t.onPostRender = new Dispatcher(t);
  7749. t.onAdd = new Dispatcher(t);
  7750. t.onRenderMenu = new tinymce.util.Dispatcher(this);
  7751. t.classPrefix = 'mceListBox';
  7752. },
  7753. select : function(va) {
  7754. var t = this, fv, f;
  7755. if (va == undefined)
  7756. return t.selectByIndex(-1);
  7757. // Is string or number make function selector
  7758. if (va && va.call)
  7759. f = va;
  7760. else {
  7761. f = function(v) {
  7762. return v == va;
  7763. };
  7764. }
  7765. // Do we need to do something?
  7766. if (va != t.selectedValue) {
  7767. // Find item
  7768. each(t.items, function(o, i) {
  7769. if (f(o.value)) {
  7770. fv = 1;
  7771. t.selectByIndex(i);
  7772. return false;
  7773. }
  7774. });
  7775. if (!fv)
  7776. t.selectByIndex(-1);
  7777. }
  7778. },
  7779. selectByIndex : function(idx) {
  7780. var t = this, e, o, label;
  7781. if (idx != t.selectedIndex) {
  7782. e = DOM.get(t.id + '_text');
  7783. label = DOM.get(t.id + '_voiceDesc');
  7784. o = t.items[idx];
  7785. if (o) {
  7786. t.selectedValue = o.value;
  7787. t.selectedIndex = idx;
  7788. DOM.setHTML(e, DOM.encode(o.title));
  7789. DOM.setHTML(label, t.settings.title + " - " + o.title);
  7790. DOM.removeClass(e, 'mceTitle');
  7791. DOM.setAttrib(t.id, 'aria-valuenow', o.title);
  7792. } else {
  7793. DOM.setHTML(e, DOM.encode(t.settings.title));
  7794. DOM.setHTML(label, DOM.encode(t.settings.title));
  7795. DOM.addClass(e, 'mceTitle');
  7796. t.selectedValue = t.selectedIndex = null;
  7797. DOM.setAttrib(t.id, 'aria-valuenow', t.settings.title);
  7798. }
  7799. e = 0;
  7800. }
  7801. },
  7802. add : function(n, v, o) {
  7803. var t = this;
  7804. o = o || {};
  7805. o = tinymce.extend(o, {
  7806. title : n,
  7807. value : v
  7808. });
  7809. t.items.push(o);
  7810. t.onAdd.dispatch(t, o);
  7811. },
  7812. getLength : function() {
  7813. return this.items.length;
  7814. },
  7815. renderHTML : function() {
  7816. var h = '', t = this, s = t.settings, cp = t.classPrefix;
  7817. h = '<span role="listbox" aria-haspopup="true" aria-labelledby="' + t.id +'_voiceDesc" aria-describedby="' + t.id + '_voiceDesc"><table role="presentation" tabindex="0" id="' + t.id + '" cellpadding="0" cellspacing="0" class="' + cp + ' ' + cp + 'Enabled' + (s['class'] ? (' ' + s['class']) : '') + '"><tbody><tr>';
  7818. h += '<td>' + DOM.createHTML('span', {id: t.id + '_voiceDesc', 'class': 'voiceLabel', style:'display:none;'}, t.settings.title);
  7819. 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>';
  7820. 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>';
  7821. h += '</tr></tbody></table></span>';
  7822. return h;
  7823. },
  7824. showMenu : function() {
  7825. var t = this, p2, e = DOM.get(this.id), m;
  7826. if (t.isDisabled() || t.items.length == 0)
  7827. return;
  7828. if (t.menu && t.menu.isMenuVisible)
  7829. return t.hideMenu();
  7830. if (!t.isMenuRendered) {
  7831. t.renderMenu();
  7832. t.isMenuRendered = true;
  7833. }
  7834. p2 = DOM.getPos(e);
  7835. m = t.menu;
  7836. m.settings.offset_x = p2.x;
  7837. m.settings.offset_y = p2.y;
  7838. m.settings.keyboard_focus = !tinymce.isOpera; // Opera is buggy when it comes to auto focus
  7839. // Select in menu
  7840. if (t.oldID)
  7841. m.items[t.oldID].setSelected(0);
  7842. each(t.items, function(o) {
  7843. if (o.value === t.selectedValue) {
  7844. m.items[o.id].setSelected(1);
  7845. t.oldID = o.id;
  7846. }
  7847. });
  7848. m.showMenu(0, e.clientHeight);
  7849. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  7850. DOM.addClass(t.id, t.classPrefix + 'Selected');
  7851. //DOM.get(t.id + '_text').focus();
  7852. },
  7853. hideMenu : function(e) {
  7854. var t = this;
  7855. if (t.menu && t.menu.isMenuVisible) {
  7856. DOM.removeClass(t.id, t.classPrefix + 'Selected');
  7857. // Prevent double toogles by canceling the mouse click event to the button
  7858. if (e && e.type == "mousedown" && (e.target.id == t.id + '_text' || e.target.id == t.id + '_open'))
  7859. return;
  7860. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  7861. DOM.removeClass(t.id, t.classPrefix + 'Selected');
  7862. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  7863. t.menu.hideMenu();
  7864. }
  7865. }
  7866. },
  7867. renderMenu : function() {
  7868. var t = this, m;
  7869. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  7870. menu_line : 1,
  7871. 'class' : t.classPrefix + 'Menu mceNoIcons',
  7872. max_width : 150,
  7873. max_height : 150
  7874. });
  7875. m.onHideMenu.add(function() {
  7876. t.hideMenu();
  7877. t.focus();
  7878. });
  7879. m.add({
  7880. title : t.settings.title,
  7881. 'class' : 'mceMenuItemTitle',
  7882. onclick : function() {
  7883. if (t.settings.onselect('') !== false)
  7884. t.select(''); // Must be runned after
  7885. }
  7886. });
  7887. each(t.items, function(o) {
  7888. // No value then treat it as a title
  7889. if (o.value === undefined) {
  7890. m.add({
  7891. title : o.title,
  7892. role : "option",
  7893. 'class' : 'mceMenuItemTitle',
  7894. onclick : function() {
  7895. if (t.settings.onselect('') !== false)
  7896. t.select(''); // Must be runned after
  7897. }
  7898. });
  7899. } else {
  7900. o.id = DOM.uniqueId();
  7901. o.role= "option";
  7902. o.onclick = function() {
  7903. if (t.settings.onselect(o.value) !== false)
  7904. t.select(o.value); // Must be runned after
  7905. };
  7906. m.add(o);
  7907. }
  7908. });
  7909. t.onRenderMenu.dispatch(t, m);
  7910. t.menu = m;
  7911. },
  7912. postRender : function() {
  7913. var t = this, cp = t.classPrefix;
  7914. Event.add(t.id, 'click', t.showMenu, t);
  7915. Event.add(t.id, 'keydown', function(evt) {
  7916. if (evt.keyCode == 32) { // Space
  7917. t.showMenu(evt);
  7918. Event.cancel(evt);
  7919. }
  7920. });
  7921. Event.add(t.id, 'focus', function() {
  7922. if (!t._focused) {
  7923. t.keyDownHandler = Event.add(t.id, 'keydown', function(e) {
  7924. if (e.keyCode == 40) {
  7925. t.showMenu();
  7926. Event.cancel(e);
  7927. }
  7928. });
  7929. t.keyPressHandler = Event.add(t.id, 'keypress', function(e) {
  7930. var v;
  7931. if (e.keyCode == 13) {
  7932. // Fake select on enter
  7933. v = t.selectedValue;
  7934. t.selectedValue = null; // Needs to be null to fake change
  7935. Event.cancel(e);
  7936. t.settings.onselect(v);
  7937. }
  7938. });
  7939. }
  7940. t._focused = 1;
  7941. });
  7942. Event.add(t.id, 'blur', function() {
  7943. Event.remove(t.id, 'keydown', t.keyDownHandler);
  7944. Event.remove(t.id, 'keypress', t.keyPressHandler);
  7945. t._focused = 0;
  7946. });
  7947. // Old IE doesn't have hover on all elements
  7948. if (tinymce.isIE6 || !DOM.boxModel) {
  7949. Event.add(t.id, 'mouseover', function() {
  7950. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  7951. DOM.addClass(t.id, cp + 'Hover');
  7952. });
  7953. Event.add(t.id, 'mouseout', function() {
  7954. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  7955. DOM.removeClass(t.id, cp + 'Hover');
  7956. });
  7957. }
  7958. t.onPostRender.dispatch(t, DOM.get(t.id));
  7959. },
  7960. destroy : function() {
  7961. this.parent();
  7962. Event.clear(this.id + '_text');
  7963. Event.clear(this.id + '_open');
  7964. }
  7965. });
  7966. })(tinymce);
  7967. (function(tinymce) {
  7968. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher;
  7969. tinymce.create('tinymce.ui.NativeListBox:tinymce.ui.ListBox', {
  7970. NativeListBox : function(id, s) {
  7971. this.parent(id, s);
  7972. this.classPrefix = 'mceNativeListBox';
  7973. },
  7974. setDisabled : function(s) {
  7975. DOM.get(this.id).disabled = s;
  7976. this.setAriaProperty('disabled', s);
  7977. },
  7978. isDisabled : function() {
  7979. return DOM.get(this.id).disabled;
  7980. },
  7981. select : function(va) {
  7982. var t = this, fv, f;
  7983. if (va == undefined)
  7984. return t.selectByIndex(-1);
  7985. // Is string or number make function selector
  7986. if (va && va.call)
  7987. f = va;
  7988. else {
  7989. f = function(v) {
  7990. return v == va;
  7991. };
  7992. }
  7993. // Do we need to do something?
  7994. if (va != t.selectedValue) {
  7995. // Find item
  7996. each(t.items, function(o, i) {
  7997. if (f(o.value)) {
  7998. fv = 1;
  7999. t.selectByIndex(i);
  8000. return false;
  8001. }
  8002. });
  8003. if (!fv)
  8004. t.selectByIndex(-1);
  8005. }
  8006. },
  8007. selectByIndex : function(idx) {
  8008. DOM.get(this.id).selectedIndex = idx + 1;
  8009. this.selectedValue = this.items[idx] ? this.items[idx].value : null;
  8010. },
  8011. add : function(n, v, a) {
  8012. var o, t = this;
  8013. a = a || {};
  8014. a.value = v;
  8015. if (t.isRendered())
  8016. DOM.add(DOM.get(this.id), 'option', a, n);
  8017. o = {
  8018. title : n,
  8019. value : v,
  8020. attribs : a
  8021. };
  8022. t.items.push(o);
  8023. t.onAdd.dispatch(t, o);
  8024. },
  8025. getLength : function() {
  8026. return this.items.length;
  8027. },
  8028. renderHTML : function() {
  8029. var h, t = this;
  8030. h = DOM.createHTML('option', {value : ''}, '-- ' + t.settings.title + ' --');
  8031. each(t.items, function(it) {
  8032. h += DOM.createHTML('option', {value : it.value}, it.title);
  8033. });
  8034. h = DOM.createHTML('select', {id : t.id, 'class' : 'mceNativeListBox', 'aria-labelledby': t.id + '_aria'}, h);
  8035. h += DOM.createHTML('span', {id : t.id + '_aria', 'style': 'display: none'}, t.settings.title);
  8036. return h;
  8037. },
  8038. postRender : function() {
  8039. var t = this, ch, changeListenerAdded = true;
  8040. t.rendered = true;
  8041. function onChange(e) {
  8042. var v = t.items[e.target.selectedIndex - 1];
  8043. if (v && (v = v.value)) {
  8044. t.onChange.dispatch(t, v);
  8045. if (t.settings.onselect)
  8046. t.settings.onselect(v);
  8047. }
  8048. };
  8049. Event.add(t.id, 'change', onChange);
  8050. // Accessibility keyhandler
  8051. Event.add(t.id, 'keydown', function(e) {
  8052. var bf;
  8053. Event.remove(t.id, 'change', ch);
  8054. changeListenerAdded = false;
  8055. bf = Event.add(t.id, 'blur', function() {
  8056. if (changeListenerAdded) return;
  8057. changeListenerAdded = true;
  8058. Event.add(t.id, 'change', onChange);
  8059. Event.remove(t.id, 'blur', bf);
  8060. });
  8061. //prevent default left and right keys on chrome - so that the keyboard navigation is used.
  8062. if (tinymce.isWebKit && (e.keyCode==37 ||e.keyCode==39)) {
  8063. return Event.prevent(e);
  8064. }
  8065. if (e.keyCode == 13 || e.keyCode == 32) {
  8066. onChange(e);
  8067. return Event.cancel(e);
  8068. }
  8069. });
  8070. t.onPostRender.dispatch(t, DOM.get(t.id));
  8071. }
  8072. });
  8073. })(tinymce);
  8074. (function(tinymce) {
  8075. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  8076. tinymce.create('tinymce.ui.MenuButton:tinymce.ui.Button', {
  8077. MenuButton : function(id, s, ed) {
  8078. this.parent(id, s, ed);
  8079. this.onRenderMenu = new tinymce.util.Dispatcher(this);
  8080. s.menu_container = s.menu_container || DOM.doc.body;
  8081. },
  8082. showMenu : function() {
  8083. var t = this, p1, p2, e = DOM.get(t.id), m;
  8084. if (t.isDisabled())
  8085. return;
  8086. if (!t.isMenuRendered) {
  8087. t.renderMenu();
  8088. t.isMenuRendered = true;
  8089. }
  8090. if (t.isMenuVisible)
  8091. return t.hideMenu();
  8092. p1 = DOM.getPos(t.settings.menu_container);
  8093. p2 = DOM.getPos(e);
  8094. m = t.menu;
  8095. m.settings.offset_x = p2.x;
  8096. m.settings.offset_y = p2.y;
  8097. m.settings.vp_offset_x = p2.x;
  8098. m.settings.vp_offset_y = p2.y;
  8099. m.settings.keyboard_focus = t._focused;
  8100. m.showMenu(0, e.clientHeight);
  8101. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  8102. t.setState('Selected', 1);
  8103. t.isMenuVisible = 1;
  8104. },
  8105. renderMenu : function() {
  8106. var t = this, m;
  8107. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  8108. menu_line : 1,
  8109. 'class' : this.classPrefix + 'Menu',
  8110. icons : t.settings.icons
  8111. });
  8112. m.onHideMenu.add(function() {
  8113. t.hideMenu();
  8114. t.focus();
  8115. });
  8116. t.onRenderMenu.dispatch(t, m);
  8117. t.menu = m;
  8118. },
  8119. hideMenu : function(e) {
  8120. var t = this;
  8121. // Prevent double toogles by canceling the mouse click event to the button
  8122. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id || e.id === t.id + '_open';}))
  8123. return;
  8124. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  8125. t.setState('Selected', 0);
  8126. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  8127. if (t.menu)
  8128. t.menu.hideMenu();
  8129. }
  8130. t.isMenuVisible = 0;
  8131. },
  8132. postRender : function() {
  8133. var t = this, s = t.settings;
  8134. Event.add(t.id, 'click', function() {
  8135. if (!t.isDisabled()) {
  8136. if (s.onclick)
  8137. s.onclick(t.value);
  8138. t.showMenu();
  8139. }
  8140. });
  8141. }
  8142. });
  8143. })(tinymce);
  8144. (function(tinymce) {
  8145. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  8146. tinymce.create('tinymce.ui.SplitButton:tinymce.ui.MenuButton', {
  8147. SplitButton : function(id, s, ed) {
  8148. this.parent(id, s, ed);
  8149. this.classPrefix = 'mceSplitButton';
  8150. },
  8151. renderHTML : function() {
  8152. var h, t = this, s = t.settings, h1;
  8153. h = '<tbody><tr>';
  8154. if (s.image)
  8155. h1 = DOM.createHTML('img ', {src : s.image, role: 'presentation', 'class' : 'mceAction ' + s['class']});
  8156. else
  8157. h1 = DOM.createHTML('span', {'class' : 'mceAction ' + s['class']}, '');
  8158. h1 += DOM.createHTML('span', {'class': 'mceVoiceLabel mceIconOnly', id: t.id + '_voice', style: 'display:none;'}, s.title);
  8159. 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>';
  8160. h1 = DOM.createHTML('span', {'class' : 'mceOpen ' + s['class']}, '<span style="display:none;" class="mceIconOnly" aria-hidden="true">\u25BC</span>');
  8161. 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>';
  8162. h += '</tr></tbody>';
  8163. h = DOM.createHTML('table', { role: 'presentation', 'class' : 'mceSplitButton mceSplitButtonEnabled ' + s['class'], cellpadding : '0', cellspacing : '0', title : s.title}, h);
  8164. return DOM.createHTML('div', {id : t.id, role: 'button', tabindex: '0', 'aria-labelledby': t.id + '_voice', 'aria-haspopup': 'true'}, h);
  8165. },
  8166. postRender : function() {
  8167. var t = this, s = t.settings, activate;
  8168. if (s.onclick) {
  8169. activate = function(evt) {
  8170. if (!t.isDisabled()) {
  8171. s.onclick(t.value);
  8172. Event.cancel(evt);
  8173. }
  8174. };
  8175. Event.add(t.id + '_action', 'click', activate);
  8176. Event.add(t.id, ['click', 'keydown'], function(evt) {
  8177. var DOM_VK_SPACE = 32, DOM_VK_ENTER = 14, DOM_VK_RETURN = 13, DOM_VK_UP = 38, DOM_VK_DOWN = 40;
  8178. if ((evt.keyCode === 32 || evt.keyCode === 13 || evt.keyCode === 14) && !evt.altKey && !evt.ctrlKey && !evt.metaKey) {
  8179. activate();
  8180. Event.cancel(evt);
  8181. } else if (evt.type === 'click' || evt.keyCode === DOM_VK_DOWN) {
  8182. t.showMenu();
  8183. Event.cancel(evt);
  8184. }
  8185. });
  8186. }
  8187. Event.add(t.id + '_open', 'click', function (evt) {
  8188. t.showMenu();
  8189. Event.cancel(evt);
  8190. });
  8191. Event.add([t.id, t.id + '_open'], 'focus', function() {t._focused = 1;});
  8192. Event.add([t.id, t.id + '_open'], 'blur', function() {t._focused = 0;});
  8193. // Old IE doesn't have hover on all elements
  8194. if (tinymce.isIE6 || !DOM.boxModel) {
  8195. Event.add(t.id, 'mouseover', function() {
  8196. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  8197. DOM.addClass(t.id, 'mceSplitButtonHover');
  8198. });
  8199. Event.add(t.id, 'mouseout', function() {
  8200. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  8201. DOM.removeClass(t.id, 'mceSplitButtonHover');
  8202. });
  8203. }
  8204. },
  8205. destroy : function() {
  8206. this.parent();
  8207. Event.clear(this.id + '_action');
  8208. Event.clear(this.id + '_open');
  8209. Event.clear(this.id);
  8210. }
  8211. });
  8212. })(tinymce);
  8213. (function(tinymce) {
  8214. var DOM = tinymce.DOM, Event = tinymce.dom.Event, is = tinymce.is, each = tinymce.each;
  8215. tinymce.create('tinymce.ui.ColorSplitButton:tinymce.ui.SplitButton', {
  8216. ColorSplitButton : function(id, s, ed) {
  8217. var t = this;
  8218. t.parent(id, s, ed);
  8219. t.settings = s = tinymce.extend({
  8220. 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',
  8221. grid_width : 8,
  8222. default_color : '#888888'
  8223. }, t.settings);
  8224. t.onShowMenu = new tinymce.util.Dispatcher(t);
  8225. t.onHideMenu = new tinymce.util.Dispatcher(t);
  8226. t.value = s.default_color;
  8227. },
  8228. showMenu : function() {
  8229. var t = this, r, p, e, p2;
  8230. if (t.isDisabled())
  8231. return;
  8232. if (!t.isMenuRendered) {
  8233. t.renderMenu();
  8234. t.isMenuRendered = true;
  8235. }
  8236. if (t.isMenuVisible)
  8237. return t.hideMenu();
  8238. e = DOM.get(t.id);
  8239. DOM.show(t.id + '_menu');
  8240. DOM.addClass(e, 'mceSplitButtonSelected');
  8241. p2 = DOM.getPos(e);
  8242. DOM.setStyles(t.id + '_menu', {
  8243. left : p2.x,
  8244. top : p2.y + e.clientHeight,
  8245. zIndex : 200000
  8246. });
  8247. e = 0;
  8248. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  8249. t.onShowMenu.dispatch(t);
  8250. if (t._focused) {
  8251. t._keyHandler = Event.add(t.id + '_menu', 'keydown', function(e) {
  8252. if (e.keyCode == 27)
  8253. t.hideMenu();
  8254. });
  8255. DOM.select('a', t.id + '_menu')[0].focus(); // Select first link
  8256. }
  8257. t.isMenuVisible = 1;
  8258. },
  8259. hideMenu : function(e) {
  8260. var t = this;
  8261. if (t.isMenuVisible) {
  8262. // Prevent double toogles by canceling the mouse click event to the button
  8263. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id + '_open';}))
  8264. return;
  8265. if (!e || !DOM.getParent(e.target, '.mceSplitButtonMenu')) {
  8266. DOM.removeClass(t.id, 'mceSplitButtonSelected');
  8267. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  8268. Event.remove(t.id + '_menu', 'keydown', t._keyHandler);
  8269. DOM.hide(t.id + '_menu');
  8270. }
  8271. t.isMenuVisible = 0;
  8272. t.onHideMenu.dispatch();
  8273. }
  8274. },
  8275. renderMenu : function() {
  8276. var t = this, m, i = 0, s = t.settings, n, tb, tr, w, context;
  8277. 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;'});
  8278. m = DOM.add(w, 'div', {'class' : s['class'] + ' mceSplitButtonMenu'});
  8279. DOM.add(m, 'span', {'class' : 'mceMenuLine'});
  8280. n = DOM.add(m, 'table', {role: 'presentation', 'class' : 'mceColorSplitMenu'});
  8281. tb = DOM.add(n, 'tbody');
  8282. // Generate color grid
  8283. i = 0;
  8284. each(is(s.colors, 'array') ? s.colors : s.colors.split(','), function(c) {
  8285. c = c.replace(/^#/, '');
  8286. if (!i--) {
  8287. tr = DOM.add(tb, 'tr');
  8288. i = s.grid_width - 1;
  8289. }
  8290. n = DOM.add(tr, 'td');
  8291. n = DOM.add(n, 'a', {
  8292. role : 'option',
  8293. href : 'javascript:;',
  8294. style : {
  8295. backgroundColor : '#' + c
  8296. },
  8297. 'title': t.editor.getLang('colors.' + c, c),
  8298. 'data-mce-color' : '#' + c
  8299. });
  8300. if (t.editor.forcedHighContrastMode) {
  8301. n = DOM.add(n, 'canvas', { width: 16, height: 16, 'aria-hidden': 'true' });
  8302. if (n.getContext && (context = n.getContext("2d"))) {
  8303. context.fillStyle = '#' + c;
  8304. context.fillRect(0, 0, 16, 16);
  8305. } else {
  8306. // No point leaving a canvas element around if it's not supported for drawing on anyway.
  8307. DOM.remove(n);
  8308. }
  8309. }
  8310. });
  8311. if (s.more_colors_func) {
  8312. n = DOM.add(tb, 'tr');
  8313. n = DOM.add(n, 'td', {colspan : s.grid_width, 'class' : 'mceMoreColors'});
  8314. n = DOM.add(n, 'a', {role: 'option', id : t.id + '_more', href : 'javascript:;', onclick : 'return false;', 'class' : 'mceMoreColors'}, s.more_colors_title);
  8315. Event.add(n, 'click', function(e) {
  8316. s.more_colors_func.call(s.more_colors_scope || this);
  8317. return Event.cancel(e); // Cancel to fix onbeforeunload problem
  8318. });
  8319. }
  8320. DOM.addClass(m, 'mceColorSplitMenu');
  8321. new tinymce.ui.KeyboardNavigation({
  8322. root: t.id + '_menu',
  8323. items: DOM.select('a', t.id + '_menu'),
  8324. onCancel: function() {
  8325. t.hideMenu();
  8326. t.focus();
  8327. }
  8328. });
  8329. // Prevent IE from scrolling and hindering click to occur #4019
  8330. Event.add(t.id + '_menu', 'mousedown', function(e) {return Event.cancel(e);});
  8331. Event.add(t.id + '_menu', 'click', function(e) {
  8332. var c;
  8333. e = DOM.getParent(e.target, 'a', tb);
  8334. if (e && e.nodeName.toLowerCase() == 'a' && (c = e.getAttribute('data-mce-color')))
  8335. t.setColor(c);
  8336. return Event.cancel(e); // Prevent IE auto save warning
  8337. });
  8338. return w;
  8339. },
  8340. setColor : function(c) {
  8341. this.displayColor(c);
  8342. this.hideMenu();
  8343. this.settings.onselect(c);
  8344. },
  8345. displayColor : function(c) {
  8346. var t = this;
  8347. DOM.setStyle(t.id + '_preview', 'backgroundColor', c);
  8348. t.value = c;
  8349. },
  8350. postRender : function() {
  8351. var t = this, id = t.id;
  8352. t.parent();
  8353. DOM.add(id + '_action', 'div', {id : id + '_preview', 'class' : 'mceColorPreview'});
  8354. DOM.setStyle(t.id + '_preview', 'backgroundColor', t.value);
  8355. },
  8356. destroy : function() {
  8357. this.parent();
  8358. Event.clear(this.id + '_menu');
  8359. Event.clear(this.id + '_more');
  8360. DOM.remove(this.id + '_menu');
  8361. }
  8362. });
  8363. })(tinymce);
  8364. (function(tinymce) {
  8365. // Shorten class names
  8366. var dom = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event;
  8367. tinymce.create('tinymce.ui.ToolbarGroup:tinymce.ui.Container', {
  8368. renderHTML : function() {
  8369. var t = this, h = [], controls = t.controls, each = tinymce.each, settings = t.settings;
  8370. h.push('<div id="' + t.id + '" role="group" aria-labelledby="' + t.id + '_voice">');
  8371. //TODO: ACC test this out - adding a role = application for getting the landmarks working well.
  8372. h.push("<span role='application'>");
  8373. h.push('<span id="' + t.id + '_voice" class="mceVoiceLabel" style="display:none;">' + dom.encode(settings.name) + '</span>');
  8374. each(controls, function(toolbar) {
  8375. h.push(toolbar.renderHTML());
  8376. });
  8377. h.push("</span>");
  8378. h.push('</div>');
  8379. return h.join('');
  8380. },
  8381. focus : function() {
  8382. var t = this;
  8383. dom.get(t.id).focus();
  8384. },
  8385. postRender : function() {
  8386. var t = this, items = [];
  8387. each(t.controls, function(toolbar) {
  8388. each (toolbar.controls, function(control) {
  8389. if (control.id) {
  8390. items.push(control);
  8391. }
  8392. });
  8393. });
  8394. t.keyNav = new tinymce.ui.KeyboardNavigation({
  8395. root: t.id,
  8396. items: items,
  8397. onCancel: function() {
  8398. //Move focus if webkit so that navigation back will read the item.
  8399. if (tinymce.isWebKit) {
  8400. dom.get(t.editor.id+"_ifr").focus();
  8401. }
  8402. t.editor.focus();
  8403. },
  8404. excludeFromTabOrder: !t.settings.tab_focus_toolbar
  8405. });
  8406. },
  8407. destroy : function() {
  8408. var self = this;
  8409. self.parent();
  8410. self.keyNav.destroy();
  8411. Event.clear(self.id);
  8412. }
  8413. });
  8414. })(tinymce);
  8415. (function(tinymce) {
  8416. // Shorten class names
  8417. var dom = tinymce.DOM, each = tinymce.each;
  8418. tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', {
  8419. renderHTML : function() {
  8420. var t = this, h = '', c, co, s = t.settings, i, pr, nx, cl;
  8421. cl = t.controls;
  8422. for (i=0; i<cl.length; i++) {
  8423. // Get current control, prev control, next control and if the control is a list box or not
  8424. co = cl[i];
  8425. pr = cl[i - 1];
  8426. nx = cl[i + 1];
  8427. // Add toolbar start
  8428. if (i === 0) {
  8429. c = 'mceToolbarStart';
  8430. if (co.Button)
  8431. c += ' mceToolbarStartButton';
  8432. else if (co.SplitButton)
  8433. c += ' mceToolbarStartSplitButton';
  8434. else if (co.ListBox)
  8435. c += ' mceToolbarStartListBox';
  8436. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  8437. }
  8438. // Add toolbar end before list box and after the previous button
  8439. // This is to fix the o2k7 editor skins
  8440. if (pr && co.ListBox) {
  8441. if (pr.Button || pr.SplitButton)
  8442. h += dom.createHTML('td', {'class' : 'mceToolbarEnd'}, dom.createHTML('span', null, '<!-- IE -->'));
  8443. }
  8444. // Render control HTML
  8445. // IE 8 quick fix, needed to propertly generate a hit area for anchors
  8446. if (dom.stdMode)
  8447. h += '<td style="position: relative">' + co.renderHTML() + '</td>';
  8448. else
  8449. h += '<td>' + co.renderHTML() + '</td>';
  8450. // Add toolbar start after list box and before the next button
  8451. // This is to fix the o2k7 editor skins
  8452. if (nx && co.ListBox) {
  8453. if (nx.Button || nx.SplitButton)
  8454. h += dom.createHTML('td', {'class' : 'mceToolbarStart'}, dom.createHTML('span', null, '<!-- IE -->'));
  8455. }
  8456. }
  8457. c = 'mceToolbarEnd';
  8458. if (co.Button)
  8459. c += ' mceToolbarEndButton';
  8460. else if (co.SplitButton)
  8461. c += ' mceToolbarEndSplitButton';
  8462. else if (co.ListBox)
  8463. c += ' mceToolbarEndListBox';
  8464. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  8465. 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>');
  8466. }
  8467. });
  8468. })(tinymce);
  8469. (function(tinymce) {
  8470. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each;
  8471. tinymce.create('tinymce.AddOnManager', {
  8472. AddOnManager : function() {
  8473. var self = this;
  8474. self.items = [];
  8475. self.urls = {};
  8476. self.lookup = {};
  8477. self.onAdd = new Dispatcher(self);
  8478. },
  8479. get : function(n) {
  8480. if (this.lookup[n]) {
  8481. return this.lookup[n].instance;
  8482. } else {
  8483. return undefined;
  8484. }
  8485. },
  8486. dependencies : function(n) {
  8487. var result;
  8488. if (this.lookup[n]) {
  8489. result = this.lookup[n].dependencies;
  8490. }
  8491. return result || [];
  8492. },
  8493. requireLangPack : function(n) {
  8494. var s = tinymce.settings;
  8495. if (s && s.language && s.language_load !== false)
  8496. tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js');
  8497. },
  8498. add : function(id, o, dependencies) {
  8499. this.items.push(o);
  8500. this.lookup[id] = {instance:o, dependencies:dependencies};
  8501. this.onAdd.dispatch(this, id, o);
  8502. return o;
  8503. },
  8504. createUrl: function(baseUrl, dep) {
  8505. if (typeof dep === "object") {
  8506. return dep
  8507. } else {
  8508. return {prefix: baseUrl.prefix, resource: dep, suffix: baseUrl.suffix};
  8509. }
  8510. },
  8511. addComponents: function(pluginName, scripts) {
  8512. var pluginUrl = this.urls[pluginName];
  8513. tinymce.each(scripts, function(script){
  8514. tinymce.ScriptLoader.add(pluginUrl+"/"+script);
  8515. });
  8516. },
  8517. load : function(n, u, cb, s) {
  8518. var t = this, url = u;
  8519. function loadDependencies() {
  8520. var dependencies = t.dependencies(n);
  8521. tinymce.each(dependencies, function(dep) {
  8522. var newUrl = t.createUrl(u, dep);
  8523. t.load(newUrl.resource, newUrl, undefined, undefined);
  8524. });
  8525. if (cb) {
  8526. if (s) {
  8527. cb.call(s);
  8528. } else {
  8529. cb.call(tinymce.ScriptLoader);
  8530. }
  8531. }
  8532. }
  8533. if (t.urls[n])
  8534. return;
  8535. if (typeof u === "object")
  8536. url = u.prefix + u.resource + u.suffix;
  8537. if (url.indexOf('/') != 0 && url.indexOf('://') == -1)
  8538. url = tinymce.baseURL + '/' + url;
  8539. t.urls[n] = url.substring(0, url.lastIndexOf('/'));
  8540. if (t.lookup[n]) {
  8541. loadDependencies();
  8542. } else {
  8543. tinymce.ScriptLoader.add(url, loadDependencies, s);
  8544. }
  8545. }
  8546. });
  8547. // Create plugin and theme managers
  8548. tinymce.PluginManager = new tinymce.AddOnManager();
  8549. tinymce.ThemeManager = new tinymce.AddOnManager();
  8550. }(tinymce));
  8551. (function(tinymce) {
  8552. // Shorten names
  8553. var each = tinymce.each, extend = tinymce.extend,
  8554. DOM = tinymce.DOM, Event = tinymce.dom.Event,
  8555. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  8556. explode = tinymce.explode,
  8557. Dispatcher = tinymce.util.Dispatcher, undefined, instanceCounter = 0;
  8558. // Setup some URLs where the editor API is located and where the document is
  8559. tinymce.documentBaseURL = window.location.href.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '');
  8560. if (!/[\/\\]$/.test(tinymce.documentBaseURL))
  8561. tinymce.documentBaseURL += '/';
  8562. tinymce.baseURL = new tinymce.util.URI(tinymce.documentBaseURL).toAbsolute(tinymce.baseURL);
  8563. tinymce.baseURI = new tinymce.util.URI(tinymce.baseURL);
  8564. // Add before unload listener
  8565. // This was required since IE was leaking memory if you added and removed beforeunload listeners
  8566. // with attachEvent/detatchEvent so this only adds one listener and instances can the attach to the onBeforeUnload event
  8567. tinymce.onBeforeUnload = new Dispatcher(tinymce);
  8568. // Must be on window or IE will leak if the editor is placed in frame or iframe
  8569. Event.add(window, 'beforeunload', function(e) {
  8570. tinymce.onBeforeUnload.dispatch(tinymce, e);
  8571. });
  8572. tinymce.onAddEditor = new Dispatcher(tinymce);
  8573. tinymce.onRemoveEditor = new Dispatcher(tinymce);
  8574. tinymce.EditorManager = extend(tinymce, {
  8575. editors : [],
  8576. i18n : {},
  8577. activeEditor : null,
  8578. init : function(s) {
  8579. var t = this, pl, sl = tinymce.ScriptLoader, e, el = [], ed;
  8580. function execCallback(se, n, s) {
  8581. var f = se[n];
  8582. if (!f)
  8583. return;
  8584. if (tinymce.is(f, 'string')) {
  8585. s = f.replace(/\.\w+$/, '');
  8586. s = s ? tinymce.resolve(s) : 0;
  8587. f = tinymce.resolve(f);
  8588. }
  8589. return f.apply(s || this, Array.prototype.slice.call(arguments, 2));
  8590. };
  8591. s = extend({
  8592. theme : "simple",
  8593. language : "en"
  8594. }, s);
  8595. t.settings = s;
  8596. // Legacy call
  8597. Event.add(document, 'init', function() {
  8598. var l, co;
  8599. execCallback(s, 'onpageload');
  8600. switch (s.mode) {
  8601. case "exact":
  8602. l = s.elements || '';
  8603. if(l.length > 0) {
  8604. each(explode(l), function(v) {
  8605. if (DOM.get(v)) {
  8606. ed = new tinymce.Editor(v, s);
  8607. el.push(ed);
  8608. ed.render(1);
  8609. } else {
  8610. each(document.forms, function(f) {
  8611. each(f.elements, function(e) {
  8612. if (e.name === v) {
  8613. v = 'mce_editor_' + instanceCounter++;
  8614. DOM.setAttrib(e, 'id', v);
  8615. ed = new tinymce.Editor(v, s);
  8616. el.push(ed);
  8617. ed.render(1);
  8618. }
  8619. });
  8620. });
  8621. }
  8622. });
  8623. }
  8624. break;
  8625. case "textareas":
  8626. case "specific_textareas":
  8627. function hasClass(n, c) {
  8628. return c.constructor === RegExp ? c.test(n.className) : DOM.hasClass(n, c);
  8629. };
  8630. each(DOM.select('textarea'), function(v) {
  8631. if (s.editor_deselector && hasClass(v, s.editor_deselector))
  8632. return;
  8633. if (!s.editor_selector || hasClass(v, s.editor_selector)) {
  8634. // Can we use the name
  8635. e = DOM.get(v.name);
  8636. if (!v.id && !e)
  8637. v.id = v.name;
  8638. // Generate unique name if missing or already exists
  8639. if (!v.id || t.get(v.id))
  8640. v.id = DOM.uniqueId();
  8641. ed = new tinymce.Editor(v.id, s);
  8642. el.push(ed);
  8643. ed.render(1);
  8644. }
  8645. });
  8646. break;
  8647. }
  8648. // Call onInit when all editors are initialized
  8649. if (s.oninit) {
  8650. l = co = 0;
  8651. each(el, function(ed) {
  8652. co++;
  8653. if (!ed.initialized) {
  8654. // Wait for it
  8655. ed.onInit.add(function() {
  8656. l++;
  8657. // All done
  8658. if (l == co)
  8659. execCallback(s, 'oninit');
  8660. });
  8661. } else
  8662. l++;
  8663. // All done
  8664. if (l == co)
  8665. execCallback(s, 'oninit');
  8666. });
  8667. }
  8668. });
  8669. },
  8670. get : function(id) {
  8671. if (id === undefined)
  8672. return this.editors;
  8673. return this.editors[id];
  8674. },
  8675. getInstanceById : function(id) {
  8676. return this.get(id);
  8677. },
  8678. add : function(editor) {
  8679. var self = this, editors = self.editors;
  8680. // Add named and index editor instance
  8681. editors[editor.id] = editor;
  8682. editors.push(editor);
  8683. self._setActive(editor);
  8684. self.onAddEditor.dispatch(self, editor);
  8685. return editor;
  8686. },
  8687. remove : function(editor) {
  8688. var t = this, i, editors = t.editors;
  8689. // Not in the collection
  8690. if (!editors[editor.id])
  8691. return null;
  8692. delete editors[editor.id];
  8693. for (i = 0; i < editors.length; i++) {
  8694. if (editors[i] == editor) {
  8695. editors.splice(i, 1);
  8696. break;
  8697. }
  8698. }
  8699. // Select another editor since the active one was removed
  8700. if (t.activeEditor == editor)
  8701. t._setActive(editors[0]);
  8702. editor.destroy();
  8703. t.onRemoveEditor.dispatch(t, editor);
  8704. return editor;
  8705. },
  8706. execCommand : function(c, u, v) {
  8707. var t = this, ed = t.get(v), w;
  8708. // Manager commands
  8709. switch (c) {
  8710. case "mceFocus":
  8711. ed.focus();
  8712. return true;
  8713. case "mceAddEditor":
  8714. case "mceAddControl":
  8715. if (!t.get(v))
  8716. new tinymce.Editor(v, t.settings).render();
  8717. return true;
  8718. case "mceAddFrameControl":
  8719. w = v.window;
  8720. // Add tinyMCE global instance and tinymce namespace to specified window
  8721. w.tinyMCE = tinyMCE;
  8722. w.tinymce = tinymce;
  8723. tinymce.DOM.doc = w.document;
  8724. tinymce.DOM.win = w;
  8725. ed = new tinymce.Editor(v.element_id, v);
  8726. ed.render();
  8727. // Fix IE memory leaks
  8728. if (tinymce.isIE) {
  8729. function clr() {
  8730. ed.destroy();
  8731. w.detachEvent('onunload', clr);
  8732. w = w.tinyMCE = w.tinymce = null; // IE leak
  8733. };
  8734. w.attachEvent('onunload', clr);
  8735. }
  8736. v.page_window = null;
  8737. return true;
  8738. case "mceRemoveEditor":
  8739. case "mceRemoveControl":
  8740. if (ed)
  8741. ed.remove();
  8742. return true;
  8743. case 'mceToggleEditor':
  8744. if (!ed) {
  8745. t.execCommand('mceAddControl', 0, v);
  8746. return true;
  8747. }
  8748. if (ed.isHidden())
  8749. ed.show();
  8750. else
  8751. ed.hide();
  8752. return true;
  8753. }
  8754. // Run command on active editor
  8755. if (t.activeEditor)
  8756. return t.activeEditor.execCommand(c, u, v);
  8757. return false;
  8758. },
  8759. execInstanceCommand : function(id, c, u, v) {
  8760. var ed = this.get(id);
  8761. if (ed)
  8762. return ed.execCommand(c, u, v);
  8763. return false;
  8764. },
  8765. triggerSave : function() {
  8766. each(this.editors, function(e) {
  8767. e.save();
  8768. });
  8769. },
  8770. addI18n : function(p, o) {
  8771. var lo, i18n = this.i18n;
  8772. if (!tinymce.is(p, 'string')) {
  8773. each(p, function(o, lc) {
  8774. each(o, function(o, g) {
  8775. each(o, function(o, k) {
  8776. if (g === 'common')
  8777. i18n[lc + '.' + k] = o;
  8778. else
  8779. i18n[lc + '.' + g + '.' + k] = o;
  8780. });
  8781. });
  8782. });
  8783. } else {
  8784. each(o, function(o, k) {
  8785. i18n[p + '.' + k] = o;
  8786. });
  8787. }
  8788. },
  8789. // Private methods
  8790. _setActive : function(editor) {
  8791. this.selectedInstance = this.activeEditor = editor;
  8792. }
  8793. });
  8794. })(tinymce);
  8795. (function(tinymce) {
  8796. // Shorten these names
  8797. var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend,
  8798. Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isGecko = tinymce.isGecko,
  8799. isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, is = tinymce.is,
  8800. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  8801. inArray = tinymce.inArray, grep = tinymce.grep, explode = tinymce.explode;
  8802. tinymce.create('tinymce.Editor', {
  8803. Editor : function(id, s) {
  8804. var t = this;
  8805. t.id = t.editorId = id;
  8806. t.execCommands = {};
  8807. t.queryStateCommands = {};
  8808. t.queryValueCommands = {};
  8809. t.isNotDirty = false;
  8810. t.plugins = {};
  8811. // Add events to the editor
  8812. each([
  8813. 'onPreInit',
  8814. 'onBeforeRenderUI',
  8815. 'onPostRender',
  8816. 'onInit',
  8817. 'onRemove',
  8818. 'onActivate',
  8819. 'onDeactivate',
  8820. 'onClick',
  8821. 'onEvent',
  8822. 'onMouseUp',
  8823. 'onMouseDown',
  8824. 'onDblClick',
  8825. 'onKeyDown',
  8826. 'onKeyUp',
  8827. 'onKeyPress',
  8828. 'onContextMenu',
  8829. 'onSubmit',
  8830. 'onReset',
  8831. 'onPaste',
  8832. 'onPreProcess',
  8833. 'onPostProcess',
  8834. 'onBeforeSetContent',
  8835. 'onBeforeGetContent',
  8836. 'onSetContent',
  8837. 'onGetContent',
  8838. 'onLoadContent',
  8839. 'onSaveContent',
  8840. 'onNodeChange',
  8841. 'onChange',
  8842. 'onBeforeExecCommand',
  8843. 'onExecCommand',
  8844. 'onUndo',
  8845. 'onRedo',
  8846. 'onVisualAid',
  8847. 'onSetProgressState'
  8848. ], function(e) {
  8849. t[e] = new Dispatcher(t);
  8850. });
  8851. t.settings = s = extend({
  8852. id : id,
  8853. language : 'en',
  8854. docs_language : 'en',
  8855. theme : 'simple',
  8856. skin : 'default',
  8857. delta_width : 0,
  8858. delta_height : 0,
  8859. popup_css : '',
  8860. plugins : '',
  8861. document_base_url : tinymce.documentBaseURL,
  8862. add_form_submit_trigger : 1,
  8863. submit_patch : 1,
  8864. add_unload_trigger : 1,
  8865. convert_urls : 1,
  8866. relative_urls : 1,
  8867. remove_script_host : 1,
  8868. table_inline_editing : 0,
  8869. object_resizing : 1,
  8870. cleanup : 1,
  8871. accessibility_focus : 1,
  8872. custom_shortcuts : 1,
  8873. custom_undo_redo_keyboard_shortcuts : 1,
  8874. custom_undo_redo_restore_selection : 1,
  8875. custom_undo_redo : 1,
  8876. doctype : tinymce.isIE6 ? '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' : '<!DOCTYPE>', // Use old doctype on IE 6 to avoid horizontal scroll
  8877. visual_table_class : 'mceItemTable',
  8878. visual : 1,
  8879. font_size_style_values : 'xx-small,x-small,small,medium,large,x-large,xx-large',
  8880. font_size_legacy_values : 'xx-small,small,medium,large,x-large,xx-large,300%', // See: http://www.w3.org/TR/CSS2/fonts.html#propdef-font-size
  8881. apply_source_formatting : 1,
  8882. directionality : 'ltr',
  8883. forced_root_block : 'p',
  8884. hidden_input : 1,
  8885. padd_empty_editor : 1,
  8886. render_ui : 1,
  8887. init_theme : 1,
  8888. force_p_newlines : 1,
  8889. indentation : '30px',
  8890. keep_styles : 1,
  8891. fix_table_elements : 1,
  8892. inline_styles : 1,
  8893. convert_fonts_to_spans : true,
  8894. indent : 'simple',
  8895. indent_before : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr',
  8896. indent_after : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr',
  8897. validate : true,
  8898. entity_encoding : 'named',
  8899. url_converter : t.convertURL,
  8900. url_converter_scope : t,
  8901. ie7_compat : true
  8902. }, s);
  8903. t.documentBaseURI = new tinymce.util.URI(s.document_base_url || tinymce.documentBaseURL, {
  8904. base_uri : tinyMCE.baseURI
  8905. });
  8906. t.baseURI = tinymce.baseURI;
  8907. t.contentCSS = [];
  8908. // Call setup
  8909. t.execCallback('setup', t);
  8910. },
  8911. render : function(nst) {
  8912. var t = this, s = t.settings, id = t.id, sl = tinymce.ScriptLoader;
  8913. // Page is not loaded yet, wait for it
  8914. if (!Event.domLoaded) {
  8915. Event.add(document, 'init', function() {
  8916. t.render();
  8917. });
  8918. return;
  8919. }
  8920. tinyMCE.settings = s;
  8921. // Element not found, then skip initialization
  8922. if (!t.getElement())
  8923. return;
  8924. // Is a iPad/iPhone and not on iOS5, then skip initialization. We need to sniff
  8925. // here since the browser says it has contentEditable support but there is no visible
  8926. // caret We will remove this check ones Apple implements full contentEditable support
  8927. if (tinymce.isIDevice && !tinymce.isIOS5)
  8928. return;
  8929. // Add hidden input for non input elements inside form elements
  8930. if (!/TEXTAREA|INPUT/i.test(t.getElement().nodeName) && s.hidden_input && DOM.getParent(id, 'form'))
  8931. DOM.insertAfter(DOM.create('input', {type : 'hidden', name : id}), id);
  8932. if (tinymce.WindowManager)
  8933. t.windowManager = new tinymce.WindowManager(t);
  8934. if (s.encoding == 'xml') {
  8935. t.onGetContent.add(function(ed, o) {
  8936. if (o.save)
  8937. o.content = DOM.encode(o.content);
  8938. });
  8939. }
  8940. if (s.add_form_submit_trigger) {
  8941. t.onSubmit.addToTop(function() {
  8942. if (t.initialized) {
  8943. t.save();
  8944. t.isNotDirty = 1;
  8945. }
  8946. });
  8947. }
  8948. if (s.add_unload_trigger) {
  8949. t._beforeUnload = tinyMCE.onBeforeUnload.add(function() {
  8950. if (t.initialized && !t.destroyed && !t.isHidden())
  8951. t.save({format : 'raw', no_events : true});
  8952. });
  8953. }
  8954. tinymce.addUnload(t.destroy, t);
  8955. if (s.submit_patch) {
  8956. t.onBeforeRenderUI.add(function() {
  8957. var n = t.getElement().form;
  8958. if (!n)
  8959. return;
  8960. // Already patched
  8961. if (n._mceOldSubmit)
  8962. return;
  8963. // Check page uses id="submit" or name="submit" for it's submit button
  8964. if (!n.submit.nodeType && !n.submit.length) {
  8965. t.formElement = n;
  8966. n._mceOldSubmit = n.submit;
  8967. n.submit = function() {
  8968. // Save all instances
  8969. tinymce.triggerSave();
  8970. t.isNotDirty = 1;
  8971. return t.formElement._mceOldSubmit(t.formElement);
  8972. };
  8973. }
  8974. n = null;
  8975. });
  8976. }
  8977. // Load scripts
  8978. function loadScripts() {
  8979. if (s.language && s.language_load !== false)
  8980. sl.add(tinymce.baseURL + '/langs/' + s.language + '.js');
  8981. if (s.theme && s.theme.charAt(0) != '-' && !ThemeManager.urls[s.theme])
  8982. ThemeManager.load(s.theme, 'themes/' + s.theme + '/editor_template' + tinymce.suffix + '.js');
  8983. each(explode(s.plugins), function(p) {
  8984. if (p &&!PluginManager.urls[p]) {
  8985. if (p.charAt(0) == '-') {
  8986. p = p.substr(1, p.length);
  8987. var dependencies = PluginManager.dependencies(p);
  8988. each(dependencies, function(dep) {
  8989. var defaultSettings = {prefix:'plugins/', resource: dep, suffix:'/editor_plugin' + tinymce.suffix + '.js'};
  8990. var dep = PluginManager.createUrl(defaultSettings, dep);
  8991. PluginManager.load(dep.resource, dep);
  8992. });
  8993. } else {
  8994. // Skip safari plugin, since it is removed as of 3.3b1
  8995. if (p == 'safari') {
  8996. return;
  8997. }
  8998. PluginManager.load(p, {prefix:'plugins/', resource: p, suffix:'/editor_plugin' + tinymce.suffix + '.js'});
  8999. }
  9000. }
  9001. });
  9002. // Init when que is loaded
  9003. sl.loadQueue(function() {
  9004. if (!t.removed)
  9005. t.init();
  9006. });
  9007. };
  9008. loadScripts();
  9009. },
  9010. init : function() {
  9011. var n, t = this, s = t.settings, w, h, e = t.getElement(), o, ti, u, bi, bc, re, i, initializedPlugins = [];
  9012. tinymce.add(t);
  9013. s.aria_label = s.aria_label || DOM.getAttrib(e, 'aria-label', t.getLang('aria.rich_text_area'));
  9014. if (s.theme) {
  9015. s.theme = s.theme.replace(/-/, '');
  9016. o = ThemeManager.get(s.theme);
  9017. t.theme = new o();
  9018. if (t.theme.init && s.init_theme)
  9019. t.theme.init(t, ThemeManager.urls[s.theme] || tinymce.documentBaseURL.replace(/\/$/, ''));
  9020. }
  9021. function initPlugin(p) {
  9022. var c = PluginManager.get(p), u = PluginManager.urls[p] || tinymce.documentBaseURL.replace(/\/$/, ''), po;
  9023. if (c && tinymce.inArray(initializedPlugins,p) === -1) {
  9024. each(PluginManager.dependencies(p), function(dep){
  9025. initPlugin(dep);
  9026. });
  9027. po = new c(t, u);
  9028. t.plugins[p] = po;
  9029. if (po.init) {
  9030. po.init(t, u);
  9031. initializedPlugins.push(p);
  9032. }
  9033. }
  9034. }
  9035. // Create all plugins
  9036. each(explode(s.plugins.replace(/\-/g, '')), initPlugin);
  9037. // Setup popup CSS path(s)
  9038. if (s.popup_css !== false) {
  9039. if (s.popup_css)
  9040. s.popup_css = t.documentBaseURI.toAbsolute(s.popup_css);
  9041. else
  9042. s.popup_css = t.baseURI.toAbsolute("themes/" + s.theme + "/skins/" + s.skin + "/dialog.css");
  9043. }
  9044. if (s.popup_css_add)
  9045. s.popup_css += ',' + t.documentBaseURI.toAbsolute(s.popup_css_add);
  9046. t.controlManager = new tinymce.ControlManager(t);
  9047. if (s.custom_undo_redo) {
  9048. t.onBeforeExecCommand.add(function(ed, cmd, ui, val, a) {
  9049. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo))
  9050. t.undoManager.beforeChange();
  9051. });
  9052. t.onExecCommand.add(function(ed, cmd, ui, val, a) {
  9053. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo))
  9054. t.undoManager.add();
  9055. });
  9056. }
  9057. t.onExecCommand.add(function(ed, c) {
  9058. // Don't refresh the select lists until caret move
  9059. if (!/^(FontName|FontSize)$/.test(c))
  9060. t.nodeChanged();
  9061. });
  9062. // Remove ghost selections on images and tables in Gecko
  9063. if (isGecko) {
  9064. function repaint(a, o) {
  9065. if (!o || !o.initial)
  9066. t.execCommand('mceRepaint');
  9067. };
  9068. t.onUndo.add(repaint);
  9069. t.onRedo.add(repaint);
  9070. t.onSetContent.add(repaint);
  9071. }
  9072. // Enables users to override the control factory
  9073. t.onBeforeRenderUI.dispatch(t, t.controlManager);
  9074. // Measure box
  9075. if (s.render_ui) {
  9076. w = s.width || e.style.width || e.offsetWidth;
  9077. h = s.height || e.style.height || e.offsetHeight;
  9078. t.orgDisplay = e.style.display;
  9079. re = /^[0-9\.]+(|px)$/i;
  9080. if (re.test('' + w))
  9081. w = Math.max(parseInt(w) + (o.deltaWidth || 0), 100);
  9082. if (re.test('' + h))
  9083. h = Math.max(parseInt(h) + (o.deltaHeight || 0), 100);
  9084. // Render UI
  9085. o = t.theme.renderUI({
  9086. targetNode : e,
  9087. width : w,
  9088. height : h,
  9089. deltaWidth : s.delta_width,
  9090. deltaHeight : s.delta_height
  9091. });
  9092. t.editorContainer = o.editorContainer;
  9093. }
  9094. // User specified a document.domain value
  9095. if (document.domain && location.hostname != document.domain)
  9096. tinymce.relaxedDomain = document.domain;
  9097. // Resize editor
  9098. DOM.setStyles(o.sizeContainer || o.editorContainer, {
  9099. width : w,
  9100. height : h
  9101. });
  9102. // Load specified content CSS last
  9103. if (s.content_css) {
  9104. tinymce.each(explode(s.content_css), function(u) {
  9105. t.contentCSS.push(t.documentBaseURI.toAbsolute(u));
  9106. });
  9107. }
  9108. h = (o.iframeHeight || h) + (typeof(h) == 'number' ? (o.deltaHeight || 0) : '');
  9109. if (h < 100)
  9110. h = 100;
  9111. t.iframeHTML = s.doctype + '<html><head xmlns="http://www.w3.org/1999/xhtml">';
  9112. // We only need to override paths if we have to
  9113. // IE has a bug where it remove site absolute urls to relative ones if this is specified
  9114. if (s.document_base_url != tinymce.documentBaseURL)
  9115. t.iframeHTML += '<base href="' + t.documentBaseURI.getURI() + '" />';
  9116. // IE8 doesn't support carets behind images setting ie7_compat would force IE8+ to run in IE7 compat mode.
  9117. if (s.ie7_compat)
  9118. t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=7" />';
  9119. else
  9120. t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=edge" />';
  9121. t.iframeHTML += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
  9122. // Load the CSS by injecting them into the HTML this will reduce "flicker"
  9123. for (i = 0; i < t.contentCSS.length; i++) {
  9124. t.iframeHTML += '<link type="text/css" rel="stylesheet" href="' + t.contentCSS[i] + '" />';
  9125. }
  9126. bi = s.body_id || 'tinymce';
  9127. if (bi.indexOf('=') != -1) {
  9128. bi = t.getParam('body_id', '', 'hash');
  9129. bi = bi[t.id] || bi;
  9130. }
  9131. bc = s.body_class || '';
  9132. if (bc.indexOf('=') != -1) {
  9133. bc = t.getParam('body_class', '', 'hash');
  9134. bc = bc[t.id] || '';
  9135. }
  9136. t.iframeHTML += '</head><body id="' + bi + '" class="mceContentBody ' + bc + '"><br></body></html>';
  9137. // Domain relaxing enabled, then set document domain
  9138. if (tinymce.relaxedDomain && (isIE || (tinymce.isOpera && parseFloat(opera.version()) < 11))) {
  9139. // We need to write the contents here in IE since multiple writes messes up refresh button and back button
  9140. 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();})()';
  9141. }
  9142. // Create iframe
  9143. // TODO: ACC add the appropriate description on this.
  9144. n = DOM.add(o.iframeContainer, 'iframe', {
  9145. id : t.id + "_ifr",
  9146. src : u || 'javascript:""', // Workaround for HTTPS warning in IE6/7
  9147. frameBorder : '0',
  9148. allowTransparency : "true",
  9149. title : s.aria_label,
  9150. style : {
  9151. width : '100%',
  9152. height : h,
  9153. display : 'block' // Important for Gecko to render the iframe correctly
  9154. }
  9155. });
  9156. t.contentAreaContainer = o.iframeContainer;
  9157. DOM.get(o.editorContainer).style.display = t.orgDisplay;
  9158. DOM.get(t.id).style.display = 'none';
  9159. DOM.setAttrib(t.id, 'aria-hidden', true);
  9160. if (!tinymce.relaxedDomain || !u)
  9161. t.setupIframe();
  9162. e = n = o = null; // Cleanup
  9163. },
  9164. setupIframe : function() {
  9165. var t = this, s = t.settings, e = DOM.get(t.id), d = t.getDoc(), h, b;
  9166. // Setup iframe body
  9167. if (!isIE || !tinymce.relaxedDomain) {
  9168. d.open();
  9169. d.write(t.iframeHTML);
  9170. d.close();
  9171. if (tinymce.relaxedDomain)
  9172. d.domain = tinymce.relaxedDomain;
  9173. }
  9174. // It will not steal focus while setting contentEditable
  9175. b = t.getBody();
  9176. b.disabled = true;
  9177. if (!s.readonly)
  9178. b.contentEditable = true;
  9179. b.disabled = false;
  9180. t.schema = new tinymce.html.Schema(s);
  9181. t.dom = new tinymce.dom.DOMUtils(t.getDoc(), {
  9182. keep_values : true,
  9183. url_converter : t.convertURL,
  9184. url_converter_scope : t,
  9185. hex_colors : s.force_hex_style_colors,
  9186. class_filter : s.class_filter,
  9187. update_styles : 1,
  9188. fix_ie_paragraphs : 1,
  9189. schema : t.schema
  9190. });
  9191. t.parser = new tinymce.html.DomParser(s, t.schema);
  9192. // Force anchor names closed, unless the setting "allow_html_in_named_anchor" is explicitly included.
  9193. if (!t.settings.allow_html_in_named_anchor) {
  9194. t.parser.addAttributeFilter('name', function(nodes, name) {
  9195. var i = nodes.length, sibling, prevSibling, parent, node;
  9196. while (i--) {
  9197. node = nodes[i];
  9198. if (node.name === 'a' && node.firstChild) {
  9199. parent = node.parent;
  9200. // Move children after current node
  9201. sibling = node.lastChild;
  9202. do {
  9203. prevSibling = sibling.prev;
  9204. parent.insert(sibling, node);
  9205. sibling = prevSibling;
  9206. } while (sibling);
  9207. }
  9208. }
  9209. });
  9210. }
  9211. // Convert src and href into data-mce-src, data-mce-href and data-mce-style
  9212. t.parser.addAttributeFilter('src,href,style', function(nodes, name) {
  9213. var i = nodes.length, node, dom = t.dom, value, internalName;
  9214. while (i--) {
  9215. node = nodes[i];
  9216. value = node.attr(name);
  9217. internalName = 'data-mce-' + name;
  9218. // Add internal attribute if we need to we don't on a refresh of the document
  9219. if (!node.attributes.map[internalName]) {
  9220. if (name === "style")
  9221. node.attr(internalName, dom.serializeStyle(dom.parseStyle(value), node.name));
  9222. else
  9223. node.attr(internalName, t.convertURL(value, name, node.name));
  9224. }
  9225. }
  9226. });
  9227. // Keep scripts from executing
  9228. t.parser.addNodeFilter('script', function(nodes, name) {
  9229. var i = nodes.length, node;
  9230. while (i--) {
  9231. node = nodes[i];
  9232. node.attr('type', 'mce-' + (node.attr('type') || 'text/javascript'));
  9233. }
  9234. });
  9235. t.parser.addNodeFilter('#cdata', function(nodes, name) {
  9236. var i = nodes.length, node;
  9237. while (i--) {
  9238. node = nodes[i];
  9239. node.type = 8;
  9240. node.name = '#comment';
  9241. node.value = '[CDATA[' + node.value + ']]';
  9242. }
  9243. });
  9244. t.parser.addNodeFilter('p,h1,h2,h3,h4,h5,h6,div', function(nodes, name) {
  9245. var i = nodes.length, node, nonEmptyElements = t.schema.getNonEmptyElements();
  9246. while (i--) {
  9247. node = nodes[i];
  9248. if (node.isEmpty(nonEmptyElements))
  9249. node.empty().append(new tinymce.html.Node('br', 1)).shortEnded = true;
  9250. }
  9251. });
  9252. t.serializer = new tinymce.dom.Serializer(s, t.dom, t.schema);
  9253. t.selection = new tinymce.dom.Selection(t.dom, t.getWin(), t.serializer);
  9254. t.formatter = new tinymce.Formatter(this);
  9255. // Register default formats
  9256. t.formatter.register({
  9257. alignleft : [
  9258. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}},
  9259. {selector : 'img,table', collapsed : false, styles : {'float' : 'left'}}
  9260. ],
  9261. aligncenter : [
  9262. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}},
  9263. {selector : 'img', collapsed : false, styles : {display : 'block', marginLeft : 'auto', marginRight : 'auto'}},
  9264. {selector : 'table', collapsed : false, styles : {marginLeft : 'auto', marginRight : 'auto'}}
  9265. ],
  9266. alignright : [
  9267. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}},
  9268. {selector : 'img,table', collapsed : false, styles : {'float' : 'right'}}
  9269. ],
  9270. alignfull : [
  9271. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'justify'}}
  9272. ],
  9273. bold : [
  9274. {inline : 'strong', remove : 'all'},
  9275. {inline : 'span', styles : {fontWeight : 'bold'}},
  9276. {inline : 'b', remove : 'all'}
  9277. ],
  9278. italic : [
  9279. {inline : 'em', remove : 'all'},
  9280. {inline : 'span', styles : {fontStyle : 'italic'}},
  9281. {inline : 'i', remove : 'all'}
  9282. ],
  9283. underline : [
  9284. {inline : 'span', styles : {textDecoration : 'underline'}, exact : true},
  9285. {inline : 'u', remove : 'all'}
  9286. ],
  9287. strikethrough : [
  9288. {inline : 'span', styles : {textDecoration : 'line-through'}, exact : true},
  9289. {inline : 'strike', remove : 'all'}
  9290. ],
  9291. forecolor : {inline : 'span', styles : {color : '%value'}, wrap_links : false},
  9292. hilitecolor : {inline : 'span', styles : {backgroundColor : '%value'}, wrap_links : false},
  9293. fontname : {inline : 'span', styles : {fontFamily : '%value'}},
  9294. fontsize : {inline : 'span', styles : {fontSize : '%value'}},
  9295. fontsize_class : {inline : 'span', attributes : {'class' : '%value'}},
  9296. blockquote : {block : 'blockquote', wrapper : 1, remove : 'all'},
  9297. subscript : {inline : 'sub'},
  9298. superscript : {inline : 'sup'},
  9299. link : {inline : 'a', selector : 'a', remove : 'all', split : true, deep : true,
  9300. onmatch : function(node) {
  9301. return true;
  9302. },
  9303. onformat : function(elm, fmt, vars) {
  9304. each(vars, function(value, key) {
  9305. t.dom.setAttrib(elm, key, value);
  9306. });
  9307. }
  9308. },
  9309. removeformat : [
  9310. {selector : 'b,strong,em,i,font,u,strike', remove : 'all', split : true, expand : false, block_expand : true, deep : true},
  9311. {selector : 'span', attributes : ['style', 'class'], remove : 'empty', split : true, expand : false, deep : true},
  9312. {selector : '*', attributes : ['style', 'class'], split : false, expand : false, deep : true}
  9313. ]
  9314. });
  9315. // Register default block formats
  9316. each('p h1 h2 h3 h4 h5 h6 div address pre div code dt dd samp'.split(/\s/), function(name) {
  9317. t.formatter.register(name, {block : name, remove : 'all'});
  9318. });
  9319. // Register user defined formats
  9320. t.formatter.register(t.settings.formats);
  9321. t.undoManager = new tinymce.UndoManager(t);
  9322. // Pass through
  9323. t.undoManager.onAdd.add(function(um, l) {
  9324. if (um.hasUndo())
  9325. return t.onChange.dispatch(t, l, um);
  9326. });
  9327. t.undoManager.onUndo.add(function(um, l) {
  9328. return t.onUndo.dispatch(t, l, um);
  9329. });
  9330. t.undoManager.onRedo.add(function(um, l) {
  9331. return t.onRedo.dispatch(t, l, um);
  9332. });
  9333. t.forceBlocks = new tinymce.ForceBlocks(t, {
  9334. forced_root_block : s.forced_root_block
  9335. });
  9336. t.editorCommands = new tinymce.EditorCommands(t);
  9337. // Pass through
  9338. t.serializer.onPreProcess.add(function(se, o) {
  9339. return t.onPreProcess.dispatch(t, o, se);
  9340. });
  9341. t.serializer.onPostProcess.add(function(se, o) {
  9342. return t.onPostProcess.dispatch(t, o, se);
  9343. });
  9344. t.onPreInit.dispatch(t);
  9345. if (!s.gecko_spellcheck)
  9346. t.getBody().spellcheck = 0;
  9347. if (!s.readonly)
  9348. t._addEvents();
  9349. t.controlManager.onPostRender.dispatch(t, t.controlManager);
  9350. t.onPostRender.dispatch(t);
  9351. t.quirks = new tinymce.util.Quirks(this);
  9352. if (s.directionality)
  9353. t.getBody().dir = s.directionality;
  9354. if (s.nowrap)
  9355. t.getBody().style.whiteSpace = "nowrap";
  9356. if (s.handle_node_change_callback) {
  9357. t.onNodeChange.add(function(ed, cm, n) {
  9358. t.execCallback('handle_node_change_callback', t.id, n, -1, -1, true, t.selection.isCollapsed());
  9359. });
  9360. }
  9361. if (s.save_callback) {
  9362. t.onSaveContent.add(function(ed, o) {
  9363. var h = t.execCallback('save_callback', t.id, o.content, t.getBody());
  9364. if (h)
  9365. o.content = h;
  9366. });
  9367. }
  9368. if (s.onchange_callback) {
  9369. t.onChange.add(function(ed, l) {
  9370. t.execCallback('onchange_callback', t, l);
  9371. });
  9372. }
  9373. if (s.protect) {
  9374. t.onBeforeSetContent.add(function(ed, o) {
  9375. if (s.protect) {
  9376. each(s.protect, function(pattern) {
  9377. o.content = o.content.replace(pattern, function(str) {
  9378. return '<!--mce:protected ' + escape(str) + '-->';
  9379. });
  9380. });
  9381. }
  9382. });
  9383. }
  9384. if (s.convert_newlines_to_brs) {
  9385. t.onBeforeSetContent.add(function(ed, o) {
  9386. if (o.initial)
  9387. o.content = o.content.replace(/\r?\n/g, '<br />');
  9388. });
  9389. }
  9390. if (s.preformatted) {
  9391. t.onPostProcess.add(function(ed, o) {
  9392. o.content = o.content.replace(/^\s*<pre.*?>/, '');
  9393. o.content = o.content.replace(/<\/pre>\s*$/, '');
  9394. if (o.set)
  9395. o.content = '<pre class="mceItemHidden">' + o.content + '</pre>';
  9396. });
  9397. }
  9398. if (s.verify_css_classes) {
  9399. t.serializer.attribValueFilter = function(n, v) {
  9400. var s, cl;
  9401. if (n == 'class') {
  9402. // Build regexp for classes
  9403. if (!t.classesRE) {
  9404. cl = t.dom.getClasses();
  9405. if (cl.length > 0) {
  9406. s = '';
  9407. each (cl, function(o) {
  9408. s += (s ? '|' : '') + o['class'];
  9409. });
  9410. t.classesRE = new RegExp('(' + s + ')', 'gi');
  9411. }
  9412. }
  9413. return !t.classesRE || /(\bmceItem\w+\b|\bmceTemp\w+\b)/g.test(v) || t.classesRE.test(v) ? v : '';
  9414. }
  9415. return v;
  9416. };
  9417. }
  9418. if (s.cleanup_callback) {
  9419. t.onBeforeSetContent.add(function(ed, o) {
  9420. o.content = t.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  9421. });
  9422. t.onPreProcess.add(function(ed, o) {
  9423. if (o.set)
  9424. t.execCallback('cleanup_callback', 'insert_to_editor_dom', o.node, o);
  9425. if (o.get)
  9426. t.execCallback('cleanup_callback', 'get_from_editor_dom', o.node, o);
  9427. });
  9428. t.onPostProcess.add(function(ed, o) {
  9429. if (o.set)
  9430. o.content = t.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  9431. if (o.get)
  9432. o.content = t.execCallback('cleanup_callback', 'get_from_editor', o.content, o);
  9433. });
  9434. }
  9435. if (s.save_callback) {
  9436. t.onGetContent.add(function(ed, o) {
  9437. if (o.save)
  9438. o.content = t.execCallback('save_callback', t.id, o.content, t.getBody());
  9439. });
  9440. }
  9441. if (s.handle_event_callback) {
  9442. t.onEvent.add(function(ed, e, o) {
  9443. if (t.execCallback('handle_event_callback', e, ed, o) === false)
  9444. Event.cancel(e);
  9445. });
  9446. }
  9447. // Add visual aids when new contents is added
  9448. t.onSetContent.add(function() {
  9449. t.addVisual(t.getBody());
  9450. });
  9451. // Remove empty contents
  9452. if (s.padd_empty_editor) {
  9453. t.onPostProcess.add(function(ed, o) {
  9454. o.content = o.content.replace(/^(<p[^>]*>(&nbsp;|&#160;|\s|\u00a0|)<\/p>[\r\n]*|<br \/>[\r\n]*)$/, '');
  9455. });
  9456. }
  9457. if (isGecko) {
  9458. // Fix gecko link bug, when a link is placed at the end of block elements there is
  9459. // no way to move the caret behind the link. This fix adds a bogus br element after the link
  9460. function fixLinks(ed, o) {
  9461. each(ed.dom.select('a'), function(n) {
  9462. var pn = n.parentNode;
  9463. if (ed.dom.isBlock(pn) && pn.lastChild === n)
  9464. ed.dom.add(pn, 'br', {'data-mce-bogus' : 1});
  9465. });
  9466. };
  9467. t.onExecCommand.add(function(ed, cmd) {
  9468. if (cmd === 'CreateLink')
  9469. fixLinks(ed);
  9470. });
  9471. t.onSetContent.add(t.selection.onSetContent.add(fixLinks));
  9472. }
  9473. t.load({initial : true, format : 'html'});
  9474. t.startContent = t.getContent({format : 'raw'});
  9475. t.undoManager.add();
  9476. t.initialized = true;
  9477. t.onInit.dispatch(t);
  9478. t.execCallback('setupcontent_callback', t.id, t.getBody(), t.getDoc());
  9479. t.execCallback('init_instance_callback', t);
  9480. t.focus(true);
  9481. t.nodeChanged({initial : 1});
  9482. // Load specified content CSS last
  9483. each(t.contentCSS, function(u) {
  9484. t.dom.loadCSS(u);
  9485. });
  9486. // Handle auto focus
  9487. if (s.auto_focus) {
  9488. setTimeout(function () {
  9489. var ed = tinymce.get(s.auto_focus);
  9490. ed.selection.select(ed.getBody(), 1);
  9491. ed.selection.collapse(1);
  9492. ed.getBody().focus();
  9493. ed.getWin().focus();
  9494. }, 100);
  9495. }
  9496. e = null;
  9497. },
  9498. focus : function(sf) {
  9499. var oed, t = this, selection = t.selection, ce = t.settings.content_editable, ieRng, controlElm, doc = t.getDoc();
  9500. if (!sf) {
  9501. // Get selected control element
  9502. ieRng = selection.getRng();
  9503. if (ieRng.item) {
  9504. controlElm = ieRng.item(0);
  9505. }
  9506. t._refreshContentEditable();
  9507. selection.normalize();
  9508. // Is not content editable
  9509. if (!ce)
  9510. t.getWin().focus();
  9511. // Focus the body as well since it's contentEditable
  9512. if (tinymce.isGecko) {
  9513. t.getBody().focus();
  9514. }
  9515. // Restore selected control element
  9516. // This is needed when for example an image is selected within a
  9517. // layer a call to focus will then remove the control selection
  9518. if (controlElm && controlElm.ownerDocument == doc) {
  9519. ieRng = doc.body.createControlRange();
  9520. ieRng.addElement(controlElm);
  9521. ieRng.select();
  9522. }
  9523. }
  9524. if (tinymce.activeEditor != t) {
  9525. if ((oed = tinymce.activeEditor) != null)
  9526. oed.onDeactivate.dispatch(oed, t);
  9527. t.onActivate.dispatch(t, oed);
  9528. }
  9529. tinymce._setActive(t);
  9530. },
  9531. execCallback : function(n) {
  9532. var t = this, f = t.settings[n], s;
  9533. if (!f)
  9534. return;
  9535. // Look through lookup
  9536. if (t.callbackLookup && (s = t.callbackLookup[n])) {
  9537. f = s.func;
  9538. s = s.scope;
  9539. }
  9540. if (is(f, 'string')) {
  9541. s = f.replace(/\.\w+$/, '');
  9542. s = s ? tinymce.resolve(s) : 0;
  9543. f = tinymce.resolve(f);
  9544. t.callbackLookup = t.callbackLookup || {};
  9545. t.callbackLookup[n] = {func : f, scope : s};
  9546. }
  9547. return f.apply(s || t, Array.prototype.slice.call(arguments, 1));
  9548. },
  9549. translate : function(s) {
  9550. var c = this.settings.language || 'en', i18n = tinymce.i18n;
  9551. if (!s)
  9552. return '';
  9553. return i18n[c + '.' + s] || s.replace(/{\#([^}]+)\}/g, function(a, b) {
  9554. return i18n[c + '.' + b] || '{#' + b + '}';
  9555. });
  9556. },
  9557. getLang : function(n, dv) {
  9558. return tinymce.i18n[(this.settings.language || 'en') + '.' + n] || (is(dv) ? dv : '{#' + n + '}');
  9559. },
  9560. getParam : function(n, dv, ty) {
  9561. var tr = tinymce.trim, v = is(this.settings[n]) ? this.settings[n] : dv, o;
  9562. if (ty === 'hash') {
  9563. o = {};
  9564. if (is(v, 'string')) {
  9565. each(v.indexOf('=') > 0 ? v.split(/[;,](?![^=;,]*(?:[;,]|$))/) : v.split(','), function(v) {
  9566. v = v.split('=');
  9567. if (v.length > 1)
  9568. o[tr(v[0])] = tr(v[1]);
  9569. else
  9570. o[tr(v[0])] = tr(v);
  9571. });
  9572. } else
  9573. o = v;
  9574. return o;
  9575. }
  9576. return v;
  9577. },
  9578. nodeChanged : function(o) {
  9579. var t = this, s = t.selection, n = s.getStart() || t.getBody();
  9580. // Fix for bug #1896577 it seems that this can not be fired while the editor is loading
  9581. if (t.initialized) {
  9582. o = o || {};
  9583. n = isIE && n.ownerDocument != t.getDoc() ? t.getBody() : n; // Fix for IE initial state
  9584. // Get parents and add them to object
  9585. o.parents = [];
  9586. t.dom.getParent(n, function(node) {
  9587. if (node.nodeName == 'BODY')
  9588. return true;
  9589. o.parents.push(node);
  9590. });
  9591. t.onNodeChange.dispatch(
  9592. t,
  9593. o ? o.controlManager || t.controlManager : t.controlManager,
  9594. n,
  9595. s.isCollapsed(),
  9596. o
  9597. );
  9598. }
  9599. },
  9600. addButton : function(n, s) {
  9601. var t = this;
  9602. t.buttons = t.buttons || {};
  9603. t.buttons[n] = s;
  9604. },
  9605. addCommand : function(name, callback, scope) {
  9606. this.execCommands[name] = {func : callback, scope : scope || this};
  9607. },
  9608. addQueryStateHandler : function(name, callback, scope) {
  9609. this.queryStateCommands[name] = {func : callback, scope : scope || this};
  9610. },
  9611. addQueryValueHandler : function(name, callback, scope) {
  9612. this.queryValueCommands[name] = {func : callback, scope : scope || this};
  9613. },
  9614. addShortcut : function(pa, desc, cmd_func, sc) {
  9615. var t = this, c;
  9616. if (!t.settings.custom_shortcuts)
  9617. return false;
  9618. t.shortcuts = t.shortcuts || {};
  9619. if (is(cmd_func, 'string')) {
  9620. c = cmd_func;
  9621. cmd_func = function() {
  9622. t.execCommand(c, false, null);
  9623. };
  9624. }
  9625. if (is(cmd_func, 'object')) {
  9626. c = cmd_func;
  9627. cmd_func = function() {
  9628. t.execCommand(c[0], c[1], c[2]);
  9629. };
  9630. }
  9631. each(explode(pa), function(pa) {
  9632. var o = {
  9633. func : cmd_func,
  9634. scope : sc || this,
  9635. desc : desc,
  9636. alt : false,
  9637. ctrl : false,
  9638. shift : false
  9639. };
  9640. each(explode(pa, '+'), function(v) {
  9641. switch (v) {
  9642. case 'alt':
  9643. case 'ctrl':
  9644. case 'shift':
  9645. o[v] = true;
  9646. break;
  9647. default:
  9648. o.charCode = v.charCodeAt(0);
  9649. o.keyCode = v.toUpperCase().charCodeAt(0);
  9650. }
  9651. });
  9652. t.shortcuts[(o.ctrl ? 'ctrl' : '') + ',' + (o.alt ? 'alt' : '') + ',' + (o.shift ? 'shift' : '') + ',' + o.keyCode] = o;
  9653. });
  9654. return true;
  9655. },
  9656. execCommand : function(cmd, ui, val, a) {
  9657. var t = this, s = 0, o, st;
  9658. if (!/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint|SelectAll)$/.test(cmd) && (!a || !a.skip_focus))
  9659. t.focus();
  9660. o = {};
  9661. t.onBeforeExecCommand.dispatch(t, cmd, ui, val, o);
  9662. if (o.terminate)
  9663. return false;
  9664. // Command callback
  9665. if (t.execCallback('execcommand_callback', t.id, t.selection.getNode(), cmd, ui, val)) {
  9666. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9667. return true;
  9668. }
  9669. // Registred commands
  9670. if (o = t.execCommands[cmd]) {
  9671. st = o.func.call(o.scope, ui, val);
  9672. // Fall through on true
  9673. if (st !== true) {
  9674. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9675. return st;
  9676. }
  9677. }
  9678. // Plugin commands
  9679. each(t.plugins, function(p) {
  9680. if (p.execCommand && p.execCommand(cmd, ui, val)) {
  9681. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9682. s = 1;
  9683. return false;
  9684. }
  9685. });
  9686. if (s)
  9687. return true;
  9688. // Theme commands
  9689. if (t.theme && t.theme.execCommand && t.theme.execCommand(cmd, ui, val)) {
  9690. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9691. return true;
  9692. }
  9693. // Editor commands
  9694. if (t.editorCommands.execCommand(cmd, ui, val)) {
  9695. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9696. return true;
  9697. }
  9698. // Browser commands
  9699. t.getDoc().execCommand(cmd, ui, val);
  9700. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9701. },
  9702. queryCommandState : function(cmd) {
  9703. var t = this, o, s;
  9704. // Is hidden then return undefined
  9705. if (t._isHidden())
  9706. return;
  9707. // Registred commands
  9708. if (o = t.queryStateCommands[cmd]) {
  9709. s = o.func.call(o.scope);
  9710. // Fall though on true
  9711. if (s !== true)
  9712. return s;
  9713. }
  9714. // Registred commands
  9715. o = t.editorCommands.queryCommandState(cmd);
  9716. if (o !== -1)
  9717. return o;
  9718. // Browser commands
  9719. try {
  9720. return this.getDoc().queryCommandState(cmd);
  9721. } catch (ex) {
  9722. // Fails sometimes see bug: 1896577
  9723. }
  9724. },
  9725. queryCommandValue : function(c) {
  9726. var t = this, o, s;
  9727. // Is hidden then return undefined
  9728. if (t._isHidden())
  9729. return;
  9730. // Registred commands
  9731. if (o = t.queryValueCommands[c]) {
  9732. s = o.func.call(o.scope);
  9733. // Fall though on true
  9734. if (s !== true)
  9735. return s;
  9736. }
  9737. // Registred commands
  9738. o = t.editorCommands.queryCommandValue(c);
  9739. if (is(o))
  9740. return o;
  9741. // Browser commands
  9742. try {
  9743. return this.getDoc().queryCommandValue(c);
  9744. } catch (ex) {
  9745. // Fails sometimes see bug: 1896577
  9746. }
  9747. },
  9748. show : function() {
  9749. var t = this;
  9750. DOM.show(t.getContainer());
  9751. DOM.hide(t.id);
  9752. t.load();
  9753. },
  9754. hide : function() {
  9755. var t = this, d = t.getDoc();
  9756. // Fixed bug where IE has a blinking cursor left from the editor
  9757. if (isIE && d)
  9758. d.execCommand('SelectAll');
  9759. // We must save before we hide so Safari doesn't crash
  9760. t.save();
  9761. DOM.hide(t.getContainer());
  9762. DOM.setStyle(t.id, 'display', t.orgDisplay);
  9763. },
  9764. isHidden : function() {
  9765. return !DOM.isHidden(this.id);
  9766. },
  9767. setProgressState : function(b, ti, o) {
  9768. this.onSetProgressState.dispatch(this, b, ti, o);
  9769. return b;
  9770. },
  9771. load : function(o) {
  9772. var t = this, e = t.getElement(), h;
  9773. if (e) {
  9774. o = o || {};
  9775. o.load = true;
  9776. // Double encode existing entities in the value
  9777. h = t.setContent(is(e.value) ? e.value : e.innerHTML, o);
  9778. o.element = e;
  9779. if (!o.no_events)
  9780. t.onLoadContent.dispatch(t, o);
  9781. o.element = e = null;
  9782. return h;
  9783. }
  9784. },
  9785. save : function(o) {
  9786. var t = this, e = t.getElement(), h, f;
  9787. if (!e || !t.initialized)
  9788. return;
  9789. o = o || {};
  9790. o.save = true;
  9791. // Add undo level will trigger onchange event
  9792. if (!o.no_events) {
  9793. t.undoManager.typing = false;
  9794. t.undoManager.add();
  9795. }
  9796. o.element = e;
  9797. h = o.content = t.getContent(o);
  9798. if (!o.no_events)
  9799. t.onSaveContent.dispatch(t, o);
  9800. h = o.content;
  9801. if (!/TEXTAREA|INPUT/i.test(e.nodeName)) {
  9802. e.innerHTML = h;
  9803. // Update hidden form element
  9804. if (f = DOM.getParent(t.id, 'form')) {
  9805. each(f.elements, function(e) {
  9806. if (e.name == t.id) {
  9807. e.value = h;
  9808. return false;
  9809. }
  9810. });
  9811. }
  9812. } else
  9813. e.value = h;
  9814. o.element = e = null;
  9815. return h;
  9816. },
  9817. setContent : function(content, args) {
  9818. var self = this, rootNode, body = self.getBody(), forcedRootBlockName;
  9819. // Setup args object
  9820. args = args || {};
  9821. args.format = args.format || 'html';
  9822. args.set = true;
  9823. args.content = content;
  9824. // Do preprocessing
  9825. if (!args.no_events)
  9826. self.onBeforeSetContent.dispatch(self, args);
  9827. content = args.content;
  9828. // Padd empty content in Gecko and Safari. Commands will otherwise fail on the content
  9829. // It will also be impossible to place the caret in the editor unless there is a BR element present
  9830. if (!tinymce.isIE && (content.length === 0 || /^\s+$/.test(content))) {
  9831. forcedRootBlockName = self.settings.forced_root_block;
  9832. if (forcedRootBlockName)
  9833. content = '<' + forcedRootBlockName + '><br data-mce-bogus="1"></' + forcedRootBlockName + '>';
  9834. else
  9835. content = '<br data-mce-bogus="1">';
  9836. body.innerHTML = content;
  9837. self.selection.select(body, true);
  9838. self.selection.collapse(true);
  9839. return;
  9840. }
  9841. // Parse and serialize the html
  9842. if (args.format !== 'raw') {
  9843. content = new tinymce.html.Serializer({}, self.schema).serialize(
  9844. self.parser.parse(content)
  9845. );
  9846. }
  9847. // Set the new cleaned contents to the editor
  9848. args.content = tinymce.trim(content);
  9849. self.dom.setHTML(body, args.content);
  9850. // Do post processing
  9851. if (!args.no_events)
  9852. self.onSetContent.dispatch(self, args);
  9853. self.selection.normalize();
  9854. return args.content;
  9855. },
  9856. getContent : function(args) {
  9857. var self = this, content;
  9858. // Setup args object
  9859. args = args || {};
  9860. args.format = args.format || 'html';
  9861. args.get = true;
  9862. // Do preprocessing
  9863. if (!args.no_events)
  9864. self.onBeforeGetContent.dispatch(self, args);
  9865. // Get raw contents or by default the cleaned contents
  9866. if (args.format == 'raw')
  9867. content = self.getBody().innerHTML;
  9868. else
  9869. content = self.serializer.serialize(self.getBody(), args);
  9870. args.content = tinymce.trim(content);
  9871. // Do post processing
  9872. if (!args.no_events)
  9873. self.onGetContent.dispatch(self, args);
  9874. return args.content;
  9875. },
  9876. isDirty : function() {
  9877. var self = this;
  9878. return tinymce.trim(self.startContent) != tinymce.trim(self.getContent({format : 'raw', no_events : 1})) && !self.isNotDirty;
  9879. },
  9880. getContainer : function() {
  9881. var t = this;
  9882. if (!t.container)
  9883. t.container = DOM.get(t.editorContainer || t.id + '_parent');
  9884. return t.container;
  9885. },
  9886. getContentAreaContainer : function() {
  9887. return this.contentAreaContainer;
  9888. },
  9889. getElement : function() {
  9890. return DOM.get(this.settings.content_element || this.id);
  9891. },
  9892. getWin : function() {
  9893. var t = this, e;
  9894. if (!t.contentWindow) {
  9895. e = DOM.get(t.id + "_ifr");
  9896. if (e)
  9897. t.contentWindow = e.contentWindow;
  9898. }
  9899. return t.contentWindow;
  9900. },
  9901. getDoc : function() {
  9902. var t = this, w;
  9903. if (!t.contentDocument) {
  9904. w = t.getWin();
  9905. if (w)
  9906. t.contentDocument = w.document;
  9907. }
  9908. return t.contentDocument;
  9909. },
  9910. getBody : function() {
  9911. return this.bodyElement || this.getDoc().body;
  9912. },
  9913. convertURL : function(u, n, e) {
  9914. var t = this, s = t.settings;
  9915. // Use callback instead
  9916. if (s.urlconverter_callback)
  9917. return t.execCallback('urlconverter_callback', u, e, true, n);
  9918. // Don't convert link href since thats the CSS files that gets loaded into the editor also skip local file URLs
  9919. if (!s.convert_urls || (e && e.nodeName == 'LINK') || u.indexOf('file:') === 0)
  9920. return u;
  9921. // Convert to relative
  9922. if (s.relative_urls)
  9923. return t.documentBaseURI.toRelative(u);
  9924. // Convert to absolute
  9925. u = t.documentBaseURI.toAbsolute(u, s.remove_script_host);
  9926. return u;
  9927. },
  9928. addVisual : function(e) {
  9929. var t = this, s = t.settings;
  9930. e = e || t.getBody();
  9931. if (!is(t.hasVisual))
  9932. t.hasVisual = s.visual;
  9933. each(t.dom.select('table,a', e), function(e) {
  9934. var v;
  9935. switch (e.nodeName) {
  9936. case 'TABLE':
  9937. v = t.dom.getAttrib(e, 'border');
  9938. if (!v || v == '0') {
  9939. if (t.hasVisual)
  9940. t.dom.addClass(e, s.visual_table_class);
  9941. else
  9942. t.dom.removeClass(e, s.visual_table_class);
  9943. }
  9944. return;
  9945. case 'A':
  9946. v = t.dom.getAttrib(e, 'name');
  9947. if (v) {
  9948. if (t.hasVisual)
  9949. t.dom.addClass(e, 'mceItemAnchor');
  9950. else
  9951. t.dom.removeClass(e, 'mceItemAnchor');
  9952. }
  9953. return;
  9954. }
  9955. });
  9956. t.onVisualAid.dispatch(t, e, t.hasVisual);
  9957. },
  9958. remove : function() {
  9959. var t = this, e = t.getContainer();
  9960. t.removed = 1; // Cancels post remove event execution
  9961. t.hide();
  9962. t.execCallback('remove_instance_callback', t);
  9963. t.onRemove.dispatch(t);
  9964. // Clear all execCommand listeners this is required to avoid errors if the editor was removed inside another command
  9965. t.onExecCommand.listeners = [];
  9966. tinymce.remove(t);
  9967. DOM.remove(e);
  9968. },
  9969. destroy : function(s) {
  9970. var t = this;
  9971. // One time is enough
  9972. if (t.destroyed)
  9973. return;
  9974. if (!s) {
  9975. tinymce.removeUnload(t.destroy);
  9976. tinyMCE.onBeforeUnload.remove(t._beforeUnload);
  9977. // Manual destroy
  9978. if (t.theme && t.theme.destroy)
  9979. t.theme.destroy();
  9980. // Destroy controls, selection and dom
  9981. t.controlManager.destroy();
  9982. t.selection.destroy();
  9983. t.dom.destroy();
  9984. // Remove all events
  9985. // Don't clear the window or document if content editable
  9986. // is enabled since other instances might still be present
  9987. if (!t.settings.content_editable) {
  9988. Event.clear(t.getWin());
  9989. Event.clear(t.getDoc());
  9990. }
  9991. Event.clear(t.getBody());
  9992. Event.clear(t.formElement);
  9993. }
  9994. if (t.formElement) {
  9995. t.formElement.submit = t.formElement._mceOldSubmit;
  9996. t.formElement._mceOldSubmit = null;
  9997. }
  9998. t.contentAreaContainer = t.formElement = t.container = t.settings.content_element = t.bodyElement = t.contentDocument = t.contentWindow = null;
  9999. if (t.selection)
  10000. t.selection = t.selection.win = t.selection.dom = t.selection.dom.doc = null;
  10001. t.destroyed = 1;
  10002. },
  10003. // Internal functions
  10004. _addEvents : function() {
  10005. // 'focus', 'blur', 'dblclick', 'beforedeactivate', submit, reset
  10006. var t = this, i, s = t.settings, dom = t.dom, lo = {
  10007. mouseup : 'onMouseUp',
  10008. mousedown : 'onMouseDown',
  10009. click : 'onClick',
  10010. keyup : 'onKeyUp',
  10011. keydown : 'onKeyDown',
  10012. keypress : 'onKeyPress',
  10013. submit : 'onSubmit',
  10014. reset : 'onReset',
  10015. contextmenu : 'onContextMenu',
  10016. dblclick : 'onDblClick',
  10017. paste : 'onPaste' // Doesn't work in all browsers yet
  10018. };
  10019. function eventHandler(e, o) {
  10020. var ty = e.type;
  10021. // Don't fire events when it's removed
  10022. if (t.removed)
  10023. return;
  10024. // Generic event handler
  10025. if (t.onEvent.dispatch(t, e, o) !== false) {
  10026. // Specific event handler
  10027. t[lo[e.fakeType || e.type]].dispatch(t, e, o);
  10028. }
  10029. };
  10030. // Add DOM events
  10031. each(lo, function(v, k) {
  10032. switch (k) {
  10033. case 'contextmenu':
  10034. dom.bind(t.getDoc(), k, eventHandler);
  10035. break;
  10036. case 'paste':
  10037. dom.bind(t.getBody(), k, function(e) {
  10038. eventHandler(e);
  10039. });
  10040. break;
  10041. case 'submit':
  10042. case 'reset':
  10043. dom.bind(t.getElement().form || DOM.getParent(t.id, 'form'), k, eventHandler);
  10044. break;
  10045. default:
  10046. dom.bind(s.content_editable ? t.getBody() : t.getDoc(), k, eventHandler);
  10047. }
  10048. });
  10049. dom.bind(s.content_editable ? t.getBody() : (isGecko ? t.getDoc() : t.getWin()), 'focus', function(e) {
  10050. t.focus(true);
  10051. });
  10052. // Fixes bug where a specified document_base_uri could result in broken images
  10053. // This will also fix drag drop of images in Gecko
  10054. if (tinymce.isGecko) {
  10055. dom.bind(t.getDoc(), 'DOMNodeInserted', function(e) {
  10056. var v;
  10057. e = e.target;
  10058. if (e.nodeType === 1 && e.nodeName === 'IMG' && (v = e.getAttribute('data-mce-src')))
  10059. e.src = t.documentBaseURI.toAbsolute(v);
  10060. });
  10061. }
  10062. // Set various midas options in Gecko
  10063. if (isGecko) {
  10064. function setOpts() {
  10065. var t = this, d = t.getDoc(), s = t.settings;
  10066. if (isGecko && !s.readonly) {
  10067. t._refreshContentEditable();
  10068. try {
  10069. // Try new Gecko method
  10070. d.execCommand("styleWithCSS", 0, false);
  10071. } catch (ex) {
  10072. // Use old method
  10073. if (!t._isHidden())
  10074. try {d.execCommand("useCSS", 0, true);} catch (ex) {}
  10075. }
  10076. if (!s.table_inline_editing)
  10077. try {d.execCommand('enableInlineTableEditing', false, false);} catch (ex) {}
  10078. if (!s.object_resizing)
  10079. try {d.execCommand('enableObjectResizing', false, false);} catch (ex) {}
  10080. }
  10081. };
  10082. t.onBeforeExecCommand.add(setOpts);
  10083. t.onMouseDown.add(setOpts);
  10084. }
  10085. // Add node change handlers
  10086. t.onMouseUp.add(t.nodeChanged);
  10087. //t.onClick.add(t.nodeChanged);
  10088. t.onKeyUp.add(function(ed, e) {
  10089. var c = e.keyCode;
  10090. 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)
  10091. t.nodeChanged();
  10092. });
  10093. // Add block quote deletion handler
  10094. t.onKeyDown.add(function(ed, e) {
  10095. // Was the BACKSPACE key pressed?
  10096. if (e.keyCode != 8)
  10097. return;
  10098. var n = ed.selection.getRng().startContainer;
  10099. var offset = ed.selection.getRng().startOffset;
  10100. while (n && n.nodeType && n.nodeType != 1 && n.parentNode)
  10101. n = n.parentNode;
  10102. // Is the cursor at the beginning of a blockquote?
  10103. if (n && n.parentNode && n.parentNode.tagName === 'BLOCKQUOTE' && n.parentNode.firstChild == n && offset == 0) {
  10104. // Remove the blockquote
  10105. ed.formatter.toggle('blockquote', null, n.parentNode);
  10106. // Move the caret to the beginning of n
  10107. var rng = ed.selection.getRng();
  10108. rng.setStart(n, 0);
  10109. rng.setEnd(n, 0);
  10110. ed.selection.setRng(rng);
  10111. ed.selection.collapse(false);
  10112. }
  10113. });
  10114. // Add reset handler
  10115. t.onReset.add(function() {
  10116. t.setContent(t.startContent, {format : 'raw'});
  10117. });
  10118. // Add shortcuts
  10119. if (s.custom_shortcuts) {
  10120. if (s.custom_undo_redo_keyboard_shortcuts) {
  10121. t.addShortcut('ctrl+z', t.getLang('undo_desc'), 'Undo');
  10122. t.addShortcut('ctrl+y', t.getLang('redo_desc'), 'Redo');
  10123. }
  10124. // Add default shortcuts for gecko
  10125. t.addShortcut('ctrl+b', t.getLang('bold_desc'), 'Bold');
  10126. t.addShortcut('ctrl+i', t.getLang('italic_desc'), 'Italic');
  10127. t.addShortcut('ctrl+u', t.getLang('underline_desc'), 'Underline');
  10128. // BlockFormat shortcuts keys
  10129. for (i=1; i<=6; i++)
  10130. t.addShortcut('ctrl+' + i, '', ['FormatBlock', false, 'h' + i]);
  10131. t.addShortcut('ctrl+7', '', ['FormatBlock', false, 'p']);
  10132. t.addShortcut('ctrl+8', '', ['FormatBlock', false, 'div']);
  10133. t.addShortcut('ctrl+9', '', ['FormatBlock', false, 'address']);
  10134. function find(e) {
  10135. var v = null;
  10136. if (!e.altKey && !e.ctrlKey && !e.metaKey)
  10137. return v;
  10138. each(t.shortcuts, function(o) {
  10139. if (tinymce.isMac && o.ctrl != e.metaKey)
  10140. return;
  10141. else if (!tinymce.isMac && o.ctrl != e.ctrlKey)
  10142. return;
  10143. if (o.alt != e.altKey)
  10144. return;
  10145. if (o.shift != e.shiftKey)
  10146. return;
  10147. if (e.keyCode == o.keyCode || (e.charCode && e.charCode == o.charCode)) {
  10148. v = o;
  10149. return false;
  10150. }
  10151. });
  10152. return v;
  10153. };
  10154. t.onKeyUp.add(function(ed, e) {
  10155. var o = find(e);
  10156. if (o)
  10157. return Event.cancel(e);
  10158. });
  10159. t.onKeyPress.add(function(ed, e) {
  10160. var o = find(e);
  10161. if (o)
  10162. return Event.cancel(e);
  10163. });
  10164. t.onKeyDown.add(function(ed, e) {
  10165. var o = find(e);
  10166. if (o) {
  10167. o.func.call(o.scope);
  10168. return Event.cancel(e);
  10169. }
  10170. });
  10171. }
  10172. if (tinymce.isIE) {
  10173. // Fix so resize will only update the width and height attributes not the styles of an image
  10174. // It will also block mceItemNoResize items
  10175. dom.bind(t.getDoc(), 'controlselect', function(e) {
  10176. var re = t.resizeInfo, cb;
  10177. e = e.target;
  10178. // Don't do this action for non image elements
  10179. if (e.nodeName !== 'IMG')
  10180. return;
  10181. if (re)
  10182. dom.unbind(re.node, re.ev, re.cb);
  10183. if (!dom.hasClass(e, 'mceItemNoResize')) {
  10184. ev = 'resizeend';
  10185. cb = dom.bind(e, ev, function(e) {
  10186. var v;
  10187. e = e.target;
  10188. if (v = dom.getStyle(e, 'width')) {
  10189. dom.setAttrib(e, 'width', v.replace(/[^0-9%]+/g, ''));
  10190. dom.setStyle(e, 'width', '');
  10191. }
  10192. if (v = dom.getStyle(e, 'height')) {
  10193. dom.setAttrib(e, 'height', v.replace(/[^0-9%]+/g, ''));
  10194. dom.setStyle(e, 'height', '');
  10195. }
  10196. });
  10197. } else {
  10198. ev = 'resizestart';
  10199. cb = dom.bind(e, 'resizestart', Event.cancel, Event);
  10200. }
  10201. re = t.resizeInfo = {
  10202. node : e,
  10203. ev : ev,
  10204. cb : cb
  10205. };
  10206. });
  10207. }
  10208. if (tinymce.isOpera) {
  10209. t.onClick.add(function(ed, e) {
  10210. Event.prevent(e);
  10211. });
  10212. }
  10213. // Add custom undo/redo handlers
  10214. if (s.custom_undo_redo) {
  10215. function addUndo() {
  10216. t.undoManager.typing = false;
  10217. t.undoManager.add();
  10218. };
  10219. dom.bind(t.getDoc(), 'focusout', function(e) {
  10220. if (!t.removed && t.undoManager.typing)
  10221. addUndo();
  10222. });
  10223. // Add undo level when contents is drag/dropped within the editor
  10224. t.dom.bind(t.dom.getRoot(), 'dragend', function(e) {
  10225. addUndo();
  10226. });
  10227. t.onKeyUp.add(function(ed, e) {
  10228. var keyCode = e.keyCode;
  10229. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 13 || keyCode == 45 || e.ctrlKey)
  10230. addUndo();
  10231. });
  10232. t.onKeyDown.add(function(ed, e) {
  10233. var keyCode = e.keyCode, sel;
  10234. if (keyCode == 8) {
  10235. sel = t.getDoc().selection;
  10236. // Fix IE control + backspace browser bug
  10237. if (sel && sel.createRange && sel.createRange().item) {
  10238. t.undoManager.beforeChange();
  10239. ed.dom.remove(sel.createRange().item(0));
  10240. addUndo();
  10241. return Event.cancel(e);
  10242. }
  10243. }
  10244. // Is caracter positon keys left,right,up,down,home,end,pgdown,pgup,enter
  10245. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 13 || keyCode == 45) {
  10246. // Add position before enter key is pressed, used by IE since it still uses the default browser behavior
  10247. // Todo: Remove this once we normalize enter behavior on IE
  10248. if (tinymce.isIE && keyCode == 13)
  10249. t.undoManager.beforeChange();
  10250. if (t.undoManager.typing)
  10251. addUndo();
  10252. return;
  10253. }
  10254. // If key isn't shift,ctrl,alt,capslock,metakey
  10255. if ((keyCode < 16 || keyCode > 20) && keyCode != 224 && keyCode != 91 && !t.undoManager.typing) {
  10256. t.undoManager.beforeChange();
  10257. t.undoManager.typing = true;
  10258. t.undoManager.add();
  10259. }
  10260. });
  10261. t.onMouseDown.add(function() {
  10262. if (t.undoManager.typing)
  10263. addUndo();
  10264. });
  10265. }
  10266. // Bug fix for FireFox keeping styles from end of selection instead of start.
  10267. if (tinymce.isGecko) {
  10268. function getAttributeApplyFunction() {
  10269. var template = t.dom.getAttribs(t.selection.getStart().cloneNode(false));
  10270. return function() {
  10271. var target = t.selection.getStart();
  10272. if (target !== t.getBody()) {
  10273. t.dom.setAttrib(target, "style", null);
  10274. each(template, function(attr) {
  10275. target.setAttributeNode(attr.cloneNode(true));
  10276. });
  10277. }
  10278. };
  10279. }
  10280. function isSelectionAcrossElements() {
  10281. var s = t.selection;
  10282. return !s.isCollapsed() && s.getStart() != s.getEnd();
  10283. }
  10284. t.onKeyPress.add(function(ed, e) {
  10285. var applyAttributes;
  10286. if ((e.keyCode == 8 || e.keyCode == 46) && isSelectionAcrossElements()) {
  10287. applyAttributes = getAttributeApplyFunction();
  10288. t.getDoc().execCommand('delete', false, null);
  10289. applyAttributes();
  10290. return Event.cancel(e);
  10291. }
  10292. });
  10293. t.dom.bind(t.getDoc(), 'cut', function(e) {
  10294. var applyAttributes;
  10295. if (isSelectionAcrossElements()) {
  10296. applyAttributes = getAttributeApplyFunction();
  10297. t.onKeyUp.addToTop(Event.cancel, Event);
  10298. setTimeout(function() {
  10299. applyAttributes();
  10300. t.onKeyUp.remove(Event.cancel, Event);
  10301. }, 0);
  10302. }
  10303. });
  10304. }
  10305. },
  10306. _refreshContentEditable : function() {
  10307. var self = this, body, parent;
  10308. // Check if the editor was hidden and the re-initalize contentEditable mode by removing and adding the body again
  10309. if (self._isHidden()) {
  10310. body = self.getBody();
  10311. parent = body.parentNode;
  10312. parent.removeChild(body);
  10313. parent.appendChild(body);
  10314. body.focus();
  10315. }
  10316. },
  10317. _isHidden : function() {
  10318. var s;
  10319. if (!isGecko)
  10320. return 0;
  10321. // Weird, wheres that cursor selection?
  10322. s = this.selection.getSel();
  10323. return (!s || !s.rangeCount || s.rangeCount == 0);
  10324. }
  10325. });
  10326. })(tinymce);
  10327. (function(tinymce) {
  10328. // Added for compression purposes
  10329. var each = tinymce.each, undefined, TRUE = true, FALSE = false;
  10330. tinymce.EditorCommands = function(editor) {
  10331. var dom = editor.dom,
  10332. selection = editor.selection,
  10333. commands = {state: {}, exec : {}, value : {}},
  10334. settings = editor.settings,
  10335. formatter = editor.formatter,
  10336. bookmark;
  10337. function execCommand(command, ui, value) {
  10338. var func;
  10339. command = command.toLowerCase();
  10340. if (func = commands.exec[command]) {
  10341. func(command, ui, value);
  10342. return TRUE;
  10343. }
  10344. return FALSE;
  10345. };
  10346. function queryCommandState(command) {
  10347. var func;
  10348. command = command.toLowerCase();
  10349. if (func = commands.state[command])
  10350. return func(command);
  10351. return -1;
  10352. };
  10353. function queryCommandValue(command) {
  10354. var func;
  10355. command = command.toLowerCase();
  10356. if (func = commands.value[command])
  10357. return func(command);
  10358. return FALSE;
  10359. };
  10360. function addCommands(command_list, type) {
  10361. type = type || 'exec';
  10362. each(command_list, function(callback, command) {
  10363. each(command.toLowerCase().split(','), function(command) {
  10364. commands[type][command] = callback;
  10365. });
  10366. });
  10367. };
  10368. // Expose public methods
  10369. tinymce.extend(this, {
  10370. execCommand : execCommand,
  10371. queryCommandState : queryCommandState,
  10372. queryCommandValue : queryCommandValue,
  10373. addCommands : addCommands
  10374. });
  10375. // Private methods
  10376. function execNativeCommand(command, ui, value) {
  10377. if (ui === undefined)
  10378. ui = FALSE;
  10379. if (value === undefined)
  10380. value = null;
  10381. return editor.getDoc().execCommand(command, ui, value);
  10382. };
  10383. function isFormatMatch(name) {
  10384. return formatter.match(name);
  10385. };
  10386. function toggleFormat(name, value) {
  10387. formatter.toggle(name, value ? {value : value} : undefined);
  10388. };
  10389. function storeSelection(type) {
  10390. bookmark = selection.getBookmark(type);
  10391. };
  10392. function restoreSelection() {
  10393. selection.moveToBookmark(bookmark);
  10394. };
  10395. // Add execCommand overrides
  10396. addCommands({
  10397. // Ignore these, added for compatibility
  10398. 'mceResetDesignMode,mceBeginUndoLevel' : function() {},
  10399. // Add undo manager logic
  10400. 'mceEndUndoLevel,mceAddUndoLevel' : function() {
  10401. editor.undoManager.add();
  10402. },
  10403. 'Cut,Copy,Paste' : function(command) {
  10404. var doc = editor.getDoc(), failed;
  10405. // Try executing the native command
  10406. try {
  10407. execNativeCommand(command);
  10408. } catch (ex) {
  10409. // Command failed
  10410. failed = TRUE;
  10411. }
  10412. // Present alert message about clipboard access not being available
  10413. if (failed || !doc.queryCommandSupported(command)) {
  10414. if (tinymce.isGecko) {
  10415. editor.windowManager.confirm(editor.getLang('clipboard_msg'), function(state) {
  10416. if (state)
  10417. open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', '_blank');
  10418. });
  10419. } else
  10420. editor.windowManager.alert(editor.getLang('clipboard_no_support'));
  10421. }
  10422. },
  10423. // Override unlink command
  10424. unlink : function(command) {
  10425. if (selection.isCollapsed())
  10426. selection.select(selection.getNode());
  10427. execNativeCommand(command);
  10428. selection.collapse(FALSE);
  10429. },
  10430. // Override justify commands to use the text formatter engine
  10431. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  10432. var align = command.substring(7);
  10433. // Remove all other alignments first
  10434. each('left,center,right,full'.split(','), function(name) {
  10435. if (align != name)
  10436. formatter.remove('align' + name);
  10437. });
  10438. toggleFormat('align' + align);
  10439. execCommand('mceRepaint');
  10440. },
  10441. // Override list commands to fix WebKit bug
  10442. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  10443. var listElm, listParent;
  10444. execNativeCommand(command);
  10445. // WebKit produces lists within block elements so we need to split them
  10446. // we will replace the native list creation logic to custom logic later on
  10447. // TODO: Remove this when the list creation logic is removed
  10448. listElm = dom.getParent(selection.getNode(), 'ol,ul');
  10449. if (listElm) {
  10450. listParent = listElm.parentNode;
  10451. // If list is within a text block then split that block
  10452. if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) {
  10453. storeSelection();
  10454. dom.split(listParent, listElm);
  10455. restoreSelection();
  10456. }
  10457. }
  10458. },
  10459. // Override commands to use the text formatter engine
  10460. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
  10461. toggleFormat(command);
  10462. },
  10463. // Override commands to use the text formatter engine
  10464. 'ForeColor,HiliteColor,FontName' : function(command, ui, value) {
  10465. toggleFormat(command, value);
  10466. },
  10467. FontSize : function(command, ui, value) {
  10468. var fontClasses, fontSizes;
  10469. // Convert font size 1-7 to styles
  10470. if (value >= 1 && value <= 7) {
  10471. fontSizes = tinymce.explode(settings.font_size_style_values);
  10472. fontClasses = tinymce.explode(settings.font_size_classes);
  10473. if (fontClasses)
  10474. value = fontClasses[value - 1] || value;
  10475. else
  10476. value = fontSizes[value - 1] || value;
  10477. }
  10478. toggleFormat(command, value);
  10479. },
  10480. RemoveFormat : function(command) {
  10481. formatter.remove(command);
  10482. },
  10483. mceBlockQuote : function(command) {
  10484. toggleFormat('blockquote');
  10485. },
  10486. FormatBlock : function(command, ui, value) {
  10487. return toggleFormat(value || 'p');
  10488. },
  10489. mceCleanup : function() {
  10490. var bookmark = selection.getBookmark();
  10491. editor.setContent(editor.getContent({cleanup : TRUE}), {cleanup : TRUE});
  10492. selection.moveToBookmark(bookmark);
  10493. },
  10494. mceRemoveNode : function(command, ui, value) {
  10495. var node = value || selection.getNode();
  10496. // Make sure that the body node isn't removed
  10497. if (node != editor.getBody()) {
  10498. storeSelection();
  10499. editor.dom.remove(node, TRUE);
  10500. restoreSelection();
  10501. }
  10502. },
  10503. mceSelectNodeDepth : function(command, ui, value) {
  10504. var counter = 0;
  10505. dom.getParent(selection.getNode(), function(node) {
  10506. if (node.nodeType == 1 && counter++ == value) {
  10507. selection.select(node);
  10508. return FALSE;
  10509. }
  10510. }, editor.getBody());
  10511. },
  10512. mceSelectNode : function(command, ui, value) {
  10513. selection.select(value);
  10514. },
  10515. mceInsertContent : function(command, ui, value) {
  10516. var parser, serializer, parentNode, rootNode, fragment, args,
  10517. marker, nodeRect, viewPortRect, rng, node, node2, bookmarkHtml, viewportBodyElement;
  10518. // Setup parser and serializer
  10519. parser = editor.parser;
  10520. serializer = new tinymce.html.Serializer({}, editor.schema);
  10521. bookmarkHtml = '<span id="mce_marker" data-mce-type="bookmark">\uFEFF</span>';
  10522. // Run beforeSetContent handlers on the HTML to be inserted
  10523. args = {content: value, format: 'html'};
  10524. selection.onBeforeSetContent.dispatch(selection, args);
  10525. value = args.content;
  10526. // Add caret at end of contents if it's missing
  10527. if (value.indexOf('{$caret}') == -1)
  10528. value += '{$caret}';
  10529. // Replace the caret marker with a span bookmark element
  10530. value = value.replace(/\{\$caret\}/, bookmarkHtml);
  10531. // Insert node maker where we will insert the new HTML and get it's parent
  10532. if (!selection.isCollapsed())
  10533. editor.getDoc().execCommand('Delete', false, null);
  10534. parentNode = selection.getNode();
  10535. // Parse the fragment within the context of the parent node
  10536. args = {context : parentNode.nodeName.toLowerCase()};
  10537. fragment = parser.parse(value, args);
  10538. // Move the caret to a more suitable location
  10539. node = fragment.lastChild;
  10540. if (node.attr('id') == 'mce_marker') {
  10541. marker = node;
  10542. for (node = node.prev; node; node = node.walk(true)) {
  10543. if (node.type == 3 || !dom.isBlock(node.name)) {
  10544. node.parent.insert(marker, node, node.name === 'br');
  10545. break;
  10546. }
  10547. }
  10548. }
  10549. // If parser says valid we can insert the contents into that parent
  10550. if (!args.invalid) {
  10551. value = serializer.serialize(fragment);
  10552. // Check if parent is empty or only has one BR element then set the innerHTML of that parent
  10553. node = parentNode.firstChild;
  10554. node2 = parentNode.lastChild;
  10555. if (!node || (node === node2 && node.nodeName === 'BR'))
  10556. dom.setHTML(parentNode, value);
  10557. else
  10558. selection.setContent(value);
  10559. } else {
  10560. // If the fragment was invalid within that context then we need
  10561. // to parse and process the parent it's inserted into
  10562. // Insert bookmark node and get the parent
  10563. selection.setContent(bookmarkHtml);
  10564. parentNode = editor.selection.getNode();
  10565. rootNode = editor.getBody();
  10566. // Opera will return the document node when selection is in root
  10567. if (parentNode.nodeType == 9)
  10568. parentNode = node = rootNode;
  10569. else
  10570. node = parentNode;
  10571. // Find the ancestor just before the root element
  10572. while (node !== rootNode) {
  10573. parentNode = node;
  10574. node = node.parentNode;
  10575. }
  10576. // Get the outer/inner HTML depending on if we are in the root and parser and serialize that
  10577. value = parentNode == rootNode ? rootNode.innerHTML : dom.getOuterHTML(parentNode);
  10578. value = serializer.serialize(
  10579. parser.parse(
  10580. // Need to replace by using a function since $ in the contents would otherwise be a problem
  10581. value.replace(/<span (id="mce_marker"|id=mce_marker).+?<\/span>/i, function() {
  10582. return serializer.serialize(fragment);
  10583. })
  10584. )
  10585. );
  10586. // Set the inner/outer HTML depending on if we are in the root or not
  10587. if (parentNode == rootNode)
  10588. dom.setHTML(rootNode, value);
  10589. else
  10590. dom.setOuterHTML(parentNode, value);
  10591. }
  10592. marker = dom.get('mce_marker');
  10593. // Scroll range into view scrollIntoView on element can't be used since it will scroll the main view port as well
  10594. nodeRect = dom.getRect(marker);
  10595. viewPortRect = dom.getViewPort(editor.getWin());
  10596. // Check if node is out side the viewport if it is then scroll to it
  10597. if ((nodeRect.y + nodeRect.h > viewPortRect.y + viewPortRect.h || nodeRect.y < viewPortRect.y) ||
  10598. (nodeRect.x > viewPortRect.x + viewPortRect.w || nodeRect.x < viewPortRect.x)) {
  10599. viewportBodyElement = tinymce.isIE ? editor.getDoc().documentElement : editor.getBody();
  10600. viewportBodyElement.scrollLeft = nodeRect.x;
  10601. viewportBodyElement.scrollTop = nodeRect.y - viewPortRect.h + 25;
  10602. }
  10603. // Move selection before marker and remove it
  10604. rng = dom.createRng();
  10605. // If previous sibling is a text node set the selection to the end of that node
  10606. node = marker.previousSibling;
  10607. if (node && node.nodeType == 3) {
  10608. rng.setStart(node, node.nodeValue.length);
  10609. } else {
  10610. // If the previous sibling isn't a text node or doesn't exist set the selection before the marker node
  10611. rng.setStartBefore(marker);
  10612. rng.setEndBefore(marker);
  10613. }
  10614. // Remove the marker node and set the new range
  10615. dom.remove(marker);
  10616. selection.setRng(rng);
  10617. // Dispatch after event and add any visual elements needed
  10618. selection.onSetContent.dispatch(selection, args);
  10619. editor.addVisual();
  10620. },
  10621. mceInsertRawHTML : function(command, ui, value) {
  10622. selection.setContent('tiny_mce_marker');
  10623. editor.setContent(editor.getContent().replace(/tiny_mce_marker/g, function() { return value }));
  10624. },
  10625. mceSetContent : function(command, ui, value) {
  10626. editor.setContent(value);
  10627. },
  10628. 'Indent,Outdent' : function(command) {
  10629. var intentValue, indentUnit, value;
  10630. // Setup indent level
  10631. intentValue = settings.indentation;
  10632. indentUnit = /[a-z%]+$/i.exec(intentValue);
  10633. intentValue = parseInt(intentValue);
  10634. if (!queryCommandState('InsertUnorderedList') && !queryCommandState('InsertOrderedList')) {
  10635. each(selection.getSelectedBlocks(), function(element) {
  10636. if (command == 'outdent') {
  10637. value = Math.max(0, parseInt(element.style.paddingLeft || 0) - intentValue);
  10638. dom.setStyle(element, 'paddingLeft', value ? value + indentUnit : '');
  10639. } else
  10640. dom.setStyle(element, 'paddingLeft', (parseInt(element.style.paddingLeft || 0) + intentValue) + indentUnit);
  10641. });
  10642. } else
  10643. execNativeCommand(command);
  10644. },
  10645. mceRepaint : function() {
  10646. var bookmark;
  10647. if (tinymce.isGecko) {
  10648. try {
  10649. storeSelection(TRUE);
  10650. if (selection.getSel())
  10651. selection.getSel().selectAllChildren(editor.getBody());
  10652. selection.collapse(TRUE);
  10653. restoreSelection();
  10654. } catch (ex) {
  10655. // Ignore
  10656. }
  10657. }
  10658. },
  10659. mceToggleFormat : function(command, ui, value) {
  10660. formatter.toggle(value);
  10661. },
  10662. InsertHorizontalRule : function() {
  10663. editor.execCommand('mceInsertContent', false, '<hr />');
  10664. },
  10665. mceToggleVisualAid : function() {
  10666. editor.hasVisual = !editor.hasVisual;
  10667. editor.addVisual();
  10668. },
  10669. mceReplaceContent : function(command, ui, value) {
  10670. editor.execCommand('mceInsertContent', false, value.replace(/\{\$selection\}/g, selection.getContent({format : 'text'})));
  10671. },
  10672. mceInsertLink : function(command, ui, value) {
  10673. var anchor;
  10674. if (typeof(value) == 'string')
  10675. value = {href : value};
  10676. anchor = dom.getParent(selection.getNode(), 'a');
  10677. // Spaces are never valid in URLs and it's a very common mistake for people to make so we fix it here.
  10678. value.href = value.href.replace(' ', '%20');
  10679. // Remove existing links if there could be child links or that the href isn't specified
  10680. if (!anchor || !value.href) {
  10681. formatter.remove('link');
  10682. }
  10683. // Apply new link to selection
  10684. if (value.href) {
  10685. formatter.apply('link', value, anchor);
  10686. }
  10687. },
  10688. selectAll : function() {
  10689. var root = dom.getRoot(), rng = dom.createRng();
  10690. rng.setStart(root, 0);
  10691. rng.setEnd(root, root.childNodes.length);
  10692. editor.selection.setRng(rng);
  10693. }
  10694. });
  10695. // Add queryCommandState overrides
  10696. addCommands({
  10697. // Override justify commands
  10698. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  10699. return isFormatMatch('align' + command.substring(7));
  10700. },
  10701. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
  10702. return isFormatMatch(command);
  10703. },
  10704. mceBlockQuote : function() {
  10705. return isFormatMatch('blockquote');
  10706. },
  10707. Outdent : function() {
  10708. var node;
  10709. if (settings.inline_styles) {
  10710. if ((node = dom.getParent(selection.getStart(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  10711. return TRUE;
  10712. if ((node = dom.getParent(selection.getEnd(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  10713. return TRUE;
  10714. }
  10715. return queryCommandState('InsertUnorderedList') || queryCommandState('InsertOrderedList') || (!settings.inline_styles && !!dom.getParent(selection.getNode(), 'BLOCKQUOTE'));
  10716. },
  10717. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  10718. return dom.getParent(selection.getNode(), command == 'insertunorderedlist' ? 'UL' : 'OL');
  10719. }
  10720. }, 'state');
  10721. // Add queryCommandValue overrides
  10722. addCommands({
  10723. 'FontSize,FontName' : function(command) {
  10724. var value = 0, parent;
  10725. if (parent = dom.getParent(selection.getNode(), 'span')) {
  10726. if (command == 'fontsize')
  10727. value = parent.style.fontSize;
  10728. else
  10729. value = parent.style.fontFamily.replace(/, /g, ',').replace(/[\'\"]/g, '').toLowerCase();
  10730. }
  10731. return value;
  10732. }
  10733. }, 'value');
  10734. // Add undo manager logic
  10735. if (settings.custom_undo_redo) {
  10736. addCommands({
  10737. Undo : function() {
  10738. editor.undoManager.undo();
  10739. },
  10740. Redo : function() {
  10741. editor.undoManager.redo();
  10742. }
  10743. });
  10744. }
  10745. };
  10746. })(tinymce);
  10747. (function(tinymce) {
  10748. var Dispatcher = tinymce.util.Dispatcher;
  10749. tinymce.UndoManager = function(editor) {
  10750. var self, index = 0, data = [], beforeBookmark;
  10751. function getContent() {
  10752. return tinymce.trim(editor.getContent({format : 'raw', no_events : 1}));
  10753. };
  10754. return self = {
  10755. typing : false,
  10756. onAdd : new Dispatcher(self),
  10757. onUndo : new Dispatcher(self),
  10758. onRedo : new Dispatcher(self),
  10759. beforeChange : function() {
  10760. beforeBookmark = editor.selection.getBookmark(2, true);
  10761. },
  10762. add : function(level) {
  10763. var i, settings = editor.settings, lastLevel;
  10764. level = level || {};
  10765. level.content = getContent();
  10766. // Add undo level if needed
  10767. lastLevel = data[index];
  10768. if (lastLevel && lastLevel.content == level.content)
  10769. return null;
  10770. // Set before bookmark on previous level
  10771. if (data[index])
  10772. data[index].beforeBookmark = beforeBookmark;
  10773. // Time to compress
  10774. if (settings.custom_undo_redo_levels) {
  10775. if (data.length > settings.custom_undo_redo_levels) {
  10776. for (i = 0; i < data.length - 1; i++)
  10777. data[i] = data[i + 1];
  10778. data.length--;
  10779. index = data.length;
  10780. }
  10781. }
  10782. // Get a non intrusive normalized bookmark
  10783. level.bookmark = editor.selection.getBookmark(2, true);
  10784. // Crop array if needed
  10785. if (index < data.length - 1)
  10786. data.length = index + 1;
  10787. data.push(level);
  10788. index = data.length - 1;
  10789. self.onAdd.dispatch(self, level);
  10790. editor.isNotDirty = 0;
  10791. return level;
  10792. },
  10793. undo : function() {
  10794. var level, i;
  10795. if (self.typing) {
  10796. self.add();
  10797. self.typing = false;
  10798. }
  10799. if (index > 0) {
  10800. level = data[--index];
  10801. editor.setContent(level.content, {format : 'raw'});
  10802. editor.selection.moveToBookmark(level.beforeBookmark);
  10803. self.onUndo.dispatch(self, level);
  10804. }
  10805. return level;
  10806. },
  10807. redo : function() {
  10808. var level;
  10809. if (index < data.length - 1) {
  10810. level = data[++index];
  10811. editor.setContent(level.content, {format : 'raw'});
  10812. editor.selection.moveToBookmark(level.bookmark);
  10813. self.onRedo.dispatch(self, level);
  10814. }
  10815. return level;
  10816. },
  10817. clear : function() {
  10818. data = [];
  10819. index = 0;
  10820. self.typing = false;
  10821. },
  10822. hasUndo : function() {
  10823. return index > 0 || this.typing;
  10824. },
  10825. hasRedo : function() {
  10826. return index < data.length - 1 && !this.typing;
  10827. }
  10828. };
  10829. };
  10830. })(tinymce);
  10831. (function(tinymce) {
  10832. // Shorten names
  10833. var Event = tinymce.dom.Event,
  10834. isIE = tinymce.isIE,
  10835. isGecko = tinymce.isGecko,
  10836. isOpera = tinymce.isOpera,
  10837. each = tinymce.each,
  10838. extend = tinymce.extend,
  10839. TRUE = true,
  10840. FALSE = false;
  10841. function cloneFormats(node) {
  10842. var clone, temp, inner;
  10843. do {
  10844. if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(node.nodeName)) {
  10845. if (clone) {
  10846. temp = node.cloneNode(false);
  10847. temp.appendChild(clone);
  10848. clone = temp;
  10849. } else {
  10850. clone = inner = node.cloneNode(false);
  10851. }
  10852. clone.removeAttribute('id');
  10853. }
  10854. } while (node = node.parentNode);
  10855. if (clone)
  10856. return {wrapper : clone, inner : inner};
  10857. };
  10858. // Checks if the selection/caret is at the end of the specified block element
  10859. function isAtEnd(rng, par) {
  10860. var rng2 = par.ownerDocument.createRange();
  10861. rng2.setStart(rng.endContainer, rng.endOffset);
  10862. rng2.setEndAfter(par);
  10863. // 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
  10864. return rng2.cloneContents().textContent.length == 0;
  10865. };
  10866. function splitList(selection, dom, li) {
  10867. var listBlock, block;
  10868. if (dom.isEmpty(li)) {
  10869. listBlock = dom.getParent(li, 'ul,ol');
  10870. if (!dom.getParent(listBlock.parentNode, 'ul,ol')) {
  10871. dom.split(listBlock, li);
  10872. block = dom.create('p', 0, '<br data-mce-bogus="1" />');
  10873. dom.replace(block, li);
  10874. selection.select(block, 1);
  10875. }
  10876. return FALSE;
  10877. }
  10878. return TRUE;
  10879. };
  10880. tinymce.create('tinymce.ForceBlocks', {
  10881. ForceBlocks : function(ed) {
  10882. var t = this, s = ed.settings, elm;
  10883. t.editor = ed;
  10884. t.dom = ed.dom;
  10885. elm = (s.forced_root_block || 'p').toLowerCase();
  10886. s.element = elm.toUpperCase();
  10887. ed.onPreInit.add(t.setup, t);
  10888. },
  10889. setup : function() {
  10890. var t = this, ed = t.editor, s = ed.settings, dom = ed.dom, selection = ed.selection, blockElements = ed.schema.getBlockElements();
  10891. // Force root blocks
  10892. if (s.forced_root_block) {
  10893. function addRootBlocks() {
  10894. var node = selection.getStart(), rootNode = ed.getBody(), rng, startContainer, startOffset, endContainer, endOffset, rootBlockNode, tempNode, offset = -0xFFFFFF;
  10895. if (!node || node.nodeType !== 1)
  10896. return;
  10897. // Check if node is wrapped in block
  10898. while (node != rootNode) {
  10899. if (blockElements[node.nodeName])
  10900. return;
  10901. node = node.parentNode;
  10902. }
  10903. // Get current selection
  10904. rng = selection.getRng();
  10905. if (rng.setStart) {
  10906. startContainer = rng.startContainer;
  10907. startOffset = rng.startOffset;
  10908. endContainer = rng.endContainer;
  10909. endOffset = rng.endOffset;
  10910. } else {
  10911. // Force control range into text range
  10912. if (rng.item) {
  10913. rng = ed.getDoc().body.createTextRange();
  10914. rng.moveToElementText(rng.item(0));
  10915. }
  10916. tmpRng = rng.duplicate();
  10917. tmpRng.collapse(true);
  10918. startOffset = tmpRng.move('character', offset) * -1;
  10919. if (!tmpRng.collapsed) {
  10920. tmpRng = rng.duplicate();
  10921. tmpRng.collapse(false);
  10922. endOffset = (tmpRng.move('character', offset) * -1) - startOffset;
  10923. }
  10924. }
  10925. // Wrap non block elements and text nodes
  10926. for (node = rootNode.firstChild; node; node) {
  10927. if (node.nodeType === 3 || (node.nodeType == 1 && !blockElements[node.nodeName])) {
  10928. if (!rootBlockNode) {
  10929. rootBlockNode = dom.create(s.forced_root_block);
  10930. node.parentNode.insertBefore(rootBlockNode, node);
  10931. }
  10932. tempNode = node;
  10933. node = node.nextSibling;
  10934. rootBlockNode.appendChild(tempNode);
  10935. } else {
  10936. rootBlockNode = null;
  10937. node = node.nextSibling;
  10938. }
  10939. }
  10940. if (rng.setStart) {
  10941. rng.setStart(startContainer, startOffset);
  10942. rng.setEnd(endContainer, endOffset);
  10943. selection.setRng(rng);
  10944. } else {
  10945. try {
  10946. rng = ed.getDoc().body.createTextRange();
  10947. rng.moveToElementText(rootNode);
  10948. rng.collapse(true);
  10949. rng.moveStart('character', startOffset);
  10950. if (endOffset > 0)
  10951. rng.moveEnd('character', endOffset);
  10952. rng.select();
  10953. } catch (ex) {
  10954. // Ignore
  10955. }
  10956. }
  10957. ed.nodeChanged();
  10958. };
  10959. ed.onKeyUp.add(addRootBlocks);
  10960. ed.onClick.add(addRootBlocks);
  10961. }
  10962. if (s.force_br_newlines) {
  10963. // Force IE to produce BRs on enter
  10964. if (isIE) {
  10965. ed.onKeyPress.add(function(ed, e) {
  10966. var n;
  10967. if (e.keyCode == 13 && selection.getNode().nodeName != 'LI') {
  10968. selection.setContent('<br id="__" /> ', {format : 'raw'});
  10969. n = dom.get('__');
  10970. n.removeAttribute('id');
  10971. selection.select(n);
  10972. selection.collapse();
  10973. return Event.cancel(e);
  10974. }
  10975. });
  10976. }
  10977. }
  10978. if (s.force_p_newlines) {
  10979. if (!isIE) {
  10980. ed.onKeyPress.add(function(ed, e) {
  10981. if (e.keyCode == 13 && !e.shiftKey && !t.insertPara(e))
  10982. Event.cancel(e);
  10983. });
  10984. } else {
  10985. // Ungly hack to for IE to preserve the formatting when you press
  10986. // enter at the end of a block element with formatted contents
  10987. // This logic overrides the browsers default logic with
  10988. // custom logic that enables us to control the output
  10989. tinymce.addUnload(function() {
  10990. t._previousFormats = 0; // Fix IE leak
  10991. });
  10992. ed.onKeyPress.add(function(ed, e) {
  10993. t._previousFormats = 0;
  10994. // Clone the current formats, this will later be applied to the new block contents
  10995. if (e.keyCode == 13 && !e.shiftKey && ed.selection.isCollapsed() && s.keep_styles)
  10996. t._previousFormats = cloneFormats(ed.selection.getStart());
  10997. });
  10998. ed.onKeyUp.add(function(ed, e) {
  10999. // Let IE break the element and the wrap the new caret location in the previous formats
  11000. if (e.keyCode == 13 && !e.shiftKey) {
  11001. var parent = ed.selection.getStart(), fmt = t._previousFormats;
  11002. // Parent is an empty block
  11003. if (!parent.hasChildNodes() && fmt) {
  11004. parent = dom.getParent(parent, dom.isBlock);
  11005. if (parent && parent.nodeName != 'LI') {
  11006. parent.innerHTML = '';
  11007. if (t._previousFormats) {
  11008. parent.appendChild(fmt.wrapper);
  11009. fmt.inner.innerHTML = '\uFEFF';
  11010. } else
  11011. parent.innerHTML = '\uFEFF';
  11012. selection.select(parent, 1);
  11013. selection.collapse(true);
  11014. ed.getDoc().execCommand('Delete', false, null);
  11015. t._previousFormats = 0;
  11016. }
  11017. }
  11018. }
  11019. });
  11020. }
  11021. if (isGecko) {
  11022. ed.onKeyDown.add(function(ed, e) {
  11023. if ((e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey)
  11024. t.backspaceDelete(e, e.keyCode == 8);
  11025. });
  11026. }
  11027. }
  11028. // Workaround for missing shift+enter support, http://bugs.webkit.org/show_bug.cgi?id=16973
  11029. if (tinymce.isWebKit) {
  11030. function insertBr(ed) {
  11031. var rng = selection.getRng(), br, div = dom.create('div', null, ' '), divYPos, vpHeight = dom.getViewPort(ed.getWin()).h;
  11032. // Insert BR element
  11033. rng.insertNode(br = dom.create('br'));
  11034. // Place caret after BR
  11035. rng.setStartAfter(br);
  11036. rng.setEndAfter(br);
  11037. selection.setRng(rng);
  11038. // Could not place caret after BR then insert an nbsp entity and move the caret
  11039. if (selection.getSel().focusNode == br.previousSibling) {
  11040. selection.select(dom.insertAfter(dom.doc.createTextNode('\u00a0'), br));
  11041. selection.collapse(TRUE);
  11042. }
  11043. // Create a temporary DIV after the BR and get the position as it
  11044. // seems like getPos() returns 0 for text nodes and BR elements.
  11045. dom.insertAfter(div, br);
  11046. divYPos = dom.getPos(div).y;
  11047. dom.remove(div);
  11048. // Scroll to new position, scrollIntoView can't be used due to bug: http://bugs.webkit.org/show_bug.cgi?id=16117
  11049. if (divYPos > vpHeight) // It is not necessary to scroll if the DIV is inside the view port.
  11050. ed.getWin().scrollTo(0, divYPos);
  11051. };
  11052. ed.onKeyPress.add(function(ed, e) {
  11053. if (e.keyCode == 13 && (e.shiftKey || (s.force_br_newlines && !dom.getParent(selection.getNode(), 'h1,h2,h3,h4,h5,h6,ol,ul')))) {
  11054. insertBr(ed);
  11055. Event.cancel(e);
  11056. }
  11057. });
  11058. }
  11059. // IE specific fixes
  11060. if (isIE) {
  11061. // Replaces IE:s auto generated paragraphs with the specified element name
  11062. if (s.element != 'P') {
  11063. ed.onKeyPress.add(function(ed, e) {
  11064. t.lastElm = selection.getNode().nodeName;
  11065. });
  11066. ed.onKeyUp.add(function(ed, e) {
  11067. var bl, n = selection.getNode(), b = ed.getBody();
  11068. if (b.childNodes.length === 1 && n.nodeName == 'P') {
  11069. n = dom.rename(n, s.element);
  11070. selection.select(n);
  11071. selection.collapse();
  11072. ed.nodeChanged();
  11073. } else if (e.keyCode == 13 && !e.shiftKey && t.lastElm != 'P') {
  11074. bl = dom.getParent(n, 'p');
  11075. if (bl) {
  11076. dom.rename(bl, s.element);
  11077. ed.nodeChanged();
  11078. }
  11079. }
  11080. });
  11081. }
  11082. }
  11083. },
  11084. getParentBlock : function(n) {
  11085. var d = this.dom;
  11086. return d.getParent(n, d.isBlock);
  11087. },
  11088. insertPara : function(e) {
  11089. 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;
  11090. var rb, ra, dir, sn, so, en, eo, sb, eb, bn, bef, aft, sc, ec, n, vp = dom.getViewPort(ed.getWin()), y, ch, car;
  11091. ed.undoManager.beforeChange();
  11092. // If root blocks are forced then use Operas default behavior since it's really good
  11093. // Removed due to bug: #1853816
  11094. // if (se.forced_root_block && isOpera)
  11095. // return TRUE;
  11096. // Setup before range
  11097. rb = d.createRange();
  11098. // If is before the first block element and in body, then move it into first block element
  11099. rb.setStart(s.anchorNode, s.anchorOffset);
  11100. rb.collapse(TRUE);
  11101. // Setup after range
  11102. ra = d.createRange();
  11103. // If is before the first block element and in body, then move it into first block element
  11104. ra.setStart(s.focusNode, s.focusOffset);
  11105. ra.collapse(TRUE);
  11106. // Setup start/end points
  11107. dir = rb.compareBoundaryPoints(rb.START_TO_END, ra) < 0;
  11108. sn = dir ? s.anchorNode : s.focusNode;
  11109. so = dir ? s.anchorOffset : s.focusOffset;
  11110. en = dir ? s.focusNode : s.anchorNode;
  11111. eo = dir ? s.focusOffset : s.anchorOffset;
  11112. // If selection is in empty table cell
  11113. if (sn === en && /^(TD|TH)$/.test(sn.nodeName)) {
  11114. if (sn.firstChild.nodeName == 'BR')
  11115. dom.remove(sn.firstChild); // Remove BR
  11116. // Create two new block elements
  11117. if (sn.childNodes.length == 0) {
  11118. ed.dom.add(sn, se.element, null, '<br />');
  11119. aft = ed.dom.add(sn, se.element, null, '<br />');
  11120. } else {
  11121. n = sn.innerHTML;
  11122. sn.innerHTML = '';
  11123. ed.dom.add(sn, se.element, null, n);
  11124. aft = ed.dom.add(sn, se.element, null, '<br />');
  11125. }
  11126. // Move caret into the last one
  11127. r = d.createRange();
  11128. r.selectNodeContents(aft);
  11129. r.collapse(1);
  11130. ed.selection.setRng(r);
  11131. return FALSE;
  11132. }
  11133. // If the caret is in an invalid location in FF we need to move it into the first block
  11134. if (sn == b && en == b && b.firstChild && ed.dom.isBlock(b.firstChild)) {
  11135. sn = en = sn.firstChild;
  11136. so = eo = 0;
  11137. rb = d.createRange();
  11138. rb.setStart(sn, 0);
  11139. ra = d.createRange();
  11140. ra.setStart(en, 0);
  11141. }
  11142. // If the body is totally empty add a BR element this might happen on webkit
  11143. if (!d.body.hasChildNodes()) {
  11144. d.body.appendChild(dom.create('br'));
  11145. }
  11146. // Never use body as start or end node
  11147. sn = sn.nodeName == "HTML" ? d.body : sn; // Fix for Opera bug: https://bugs.opera.com/show_bug.cgi?id=273224&comments=yes
  11148. sn = sn.nodeName == "BODY" ? sn.firstChild : sn;
  11149. en = en.nodeName == "HTML" ? d.body : en; // Fix for Opera bug: https://bugs.opera.com/show_bug.cgi?id=273224&comments=yes
  11150. en = en.nodeName == "BODY" ? en.firstChild : en;
  11151. // Get start and end blocks
  11152. sb = t.getParentBlock(sn);
  11153. eb = t.getParentBlock(en);
  11154. bn = sb ? sb.nodeName : se.element; // Get block name to create
  11155. // Return inside list use default browser behavior
  11156. if (n = t.dom.getParent(sb, 'li,pre')) {
  11157. if (n.nodeName == 'LI')
  11158. return splitList(ed.selection, t.dom, n);
  11159. return TRUE;
  11160. }
  11161. // If caption or absolute layers then always generate new blocks within
  11162. if (sb && (sb.nodeName == 'CAPTION' || /absolute|relative|fixed/gi.test(dom.getStyle(sb, 'position', 1)))) {
  11163. bn = se.element;
  11164. sb = null;
  11165. }
  11166. // If caption or absolute layers then always generate new blocks within
  11167. if (eb && (eb.nodeName == 'CAPTION' || /absolute|relative|fixed/gi.test(dom.getStyle(sb, 'position', 1)))) {
  11168. bn = se.element;
  11169. eb = null;
  11170. }
  11171. // Use P instead
  11172. if (/(TD|TABLE|TH|CAPTION)/.test(bn) || (sb && bn == "DIV" && /left|right/gi.test(dom.getStyle(sb, 'float', 1)))) {
  11173. bn = se.element;
  11174. sb = eb = null;
  11175. }
  11176. // Setup new before and after blocks
  11177. bef = (sb && sb.nodeName == bn) ? sb.cloneNode(0) : ed.dom.create(bn);
  11178. aft = (eb && eb.nodeName == bn) ? eb.cloneNode(0) : ed.dom.create(bn);
  11179. // Remove id from after clone
  11180. aft.removeAttribute('id');
  11181. // Is header and cursor is at the end, then force paragraph under
  11182. if (/^(H[1-6])$/.test(bn) && isAtEnd(r, sb))
  11183. aft = ed.dom.create(se.element);
  11184. // Find start chop node
  11185. n = sc = sn;
  11186. do {
  11187. if (n == b || n.nodeType == 9 || t.dom.isBlock(n) || /(TD|TABLE|TH|CAPTION)/.test(n.nodeName))
  11188. break;
  11189. sc = n;
  11190. } while ((n = n.previousSibling ? n.previousSibling : n.parentNode));
  11191. // Find end chop node
  11192. n = ec = en;
  11193. do {
  11194. if (n == b || n.nodeType == 9 || t.dom.isBlock(n) || /(TD|TABLE|TH|CAPTION)/.test(n.nodeName))
  11195. break;
  11196. ec = n;
  11197. } while ((n = n.nextSibling ? n.nextSibling : n.parentNode));
  11198. // Place first chop part into before block element
  11199. if (sc.nodeName == bn)
  11200. rb.setStart(sc, 0);
  11201. else
  11202. rb.setStartBefore(sc);
  11203. rb.setEnd(sn, so);
  11204. bef.appendChild(rb.cloneContents() || d.createTextNode('')); // Empty text node needed for Safari
  11205. // Place secnd chop part within new block element
  11206. try {
  11207. ra.setEndAfter(ec);
  11208. } catch(ex) {
  11209. //console.debug(s.focusNode, s.focusOffset);
  11210. }
  11211. ra.setStart(en, eo);
  11212. aft.appendChild(ra.cloneContents() || d.createTextNode('')); // Empty text node needed for Safari
  11213. // Create range around everything
  11214. r = d.createRange();
  11215. if (!sc.previousSibling && sc.parentNode.nodeName == bn) {
  11216. r.setStartBefore(sc.parentNode);
  11217. } else {
  11218. if (rb.startContainer.nodeName == bn && rb.startOffset == 0)
  11219. r.setStartBefore(rb.startContainer);
  11220. else
  11221. r.setStart(rb.startContainer, rb.startOffset);
  11222. }
  11223. if (!ec.nextSibling && ec.parentNode.nodeName == bn)
  11224. r.setEndAfter(ec.parentNode);
  11225. else
  11226. r.setEnd(ra.endContainer, ra.endOffset);
  11227. // Delete and replace it with new block elements
  11228. r.deleteContents();
  11229. if (isOpera)
  11230. ed.getWin().scrollTo(0, vp.y);
  11231. // Never wrap blocks in blocks
  11232. if (bef.firstChild && bef.firstChild.nodeName == bn)
  11233. bef.innerHTML = bef.firstChild.innerHTML;
  11234. if (aft.firstChild && aft.firstChild.nodeName == bn)
  11235. aft.innerHTML = aft.firstChild.innerHTML;
  11236. function appendStyles(e, en) {
  11237. var nl = [], nn, n, i;
  11238. e.innerHTML = '';
  11239. // Make clones of style elements
  11240. if (se.keep_styles) {
  11241. n = en;
  11242. do {
  11243. // We only want style specific elements
  11244. if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(n.nodeName)) {
  11245. nn = n.cloneNode(FALSE);
  11246. dom.setAttrib(nn, 'id', ''); // Remove ID since it needs to be unique
  11247. nl.push(nn);
  11248. }
  11249. } while (n = n.parentNode);
  11250. }
  11251. // Append style elements to aft
  11252. if (nl.length > 0) {
  11253. for (i = nl.length - 1, nn = e; i >= 0; i--)
  11254. nn = nn.appendChild(nl[i]);
  11255. // Padd most inner style element
  11256. nl[0].innerHTML = isOpera ? '\u00a0' : '<br />'; // Extra space for Opera so that the caret can move there
  11257. return nl[0]; // Move caret to most inner element
  11258. } else
  11259. e.innerHTML = isOpera ? '\u00a0' : '<br />'; // Extra space for Opera so that the caret can move there
  11260. };
  11261. // Padd empty blocks
  11262. if (dom.isEmpty(bef))
  11263. appendStyles(bef, sn);
  11264. // Fill empty afterblook with current style
  11265. if (dom.isEmpty(aft))
  11266. car = appendStyles(aft, en);
  11267. // Opera needs this one backwards for older versions
  11268. if (isOpera && parseFloat(opera.version()) < 9.5) {
  11269. r.insertNode(bef);
  11270. r.insertNode(aft);
  11271. } else {
  11272. r.insertNode(aft);
  11273. r.insertNode(bef);
  11274. }
  11275. // Normalize
  11276. aft.normalize();
  11277. bef.normalize();
  11278. // Move cursor and scroll into view
  11279. ed.selection.select(aft, true);
  11280. ed.selection.collapse(true);
  11281. // 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
  11282. y = ed.dom.getPos(aft).y;
  11283. //ch = aft.clientHeight;
  11284. // Is element within viewport
  11285. if (y < vp.y || y + 25 > vp.y + vp.h) {
  11286. 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
  11287. /*console.debug(
  11288. 'Element: y=' + y + ', h=' + ch + ', ' +
  11289. 'Viewport: y=' + vp.y + ", h=" + vp.h + ', bottom=' + (vp.y + vp.h)
  11290. );*/
  11291. }
  11292. ed.undoManager.add();
  11293. return FALSE;
  11294. },
  11295. backspaceDelete : function(e, bs) {
  11296. 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;
  11297. // Delete when caret is behind a element doesn't work correctly on Gecko see #3011651
  11298. if (!bs && r.collapsed && sc.nodeType == 1 && r.startOffset == sc.childNodes.length) {
  11299. walker = new tinymce.dom.TreeWalker(sc.lastChild, sc);
  11300. // Walk the dom backwards until we find a text node
  11301. for (n = sc.lastChild; n; n = walker.prev()) {
  11302. if (n.nodeType == 3) {
  11303. r.setStart(n, n.nodeValue.length);
  11304. r.collapse(true);
  11305. se.setRng(r);
  11306. return;
  11307. }
  11308. }
  11309. }
  11310. // The caret sometimes gets stuck in Gecko if you delete empty paragraphs
  11311. // This workaround removes the element by hand and moves the caret to the previous element
  11312. if (sc && ed.dom.isBlock(sc) && !/^(TD|TH)$/.test(sc.nodeName) && bs) {
  11313. if (sc.childNodes.length == 0 || (sc.childNodes.length == 1 && sc.firstChild.nodeName == 'BR')) {
  11314. // Find previous block element
  11315. n = sc;
  11316. while ((n = n.previousSibling) && !ed.dom.isBlock(n)) ;
  11317. if (n) {
  11318. if (sc != b.firstChild) {
  11319. // Find last text node
  11320. w = ed.dom.doc.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, FALSE);
  11321. while (tn = w.nextNode())
  11322. n = tn;
  11323. // Place caret at the end of last text node
  11324. r = ed.getDoc().createRange();
  11325. r.setStart(n, n.nodeValue ? n.nodeValue.length : 0);
  11326. r.setEnd(n, n.nodeValue ? n.nodeValue.length : 0);
  11327. se.setRng(r);
  11328. // Remove the target container
  11329. ed.dom.remove(sc);
  11330. }
  11331. return Event.cancel(e);
  11332. }
  11333. }
  11334. }
  11335. }
  11336. });
  11337. })(tinymce);
  11338. (function(tinymce) {
  11339. // Shorten names
  11340. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, extend = tinymce.extend;
  11341. tinymce.create('tinymce.ControlManager', {
  11342. ControlManager : function(ed, s) {
  11343. var t = this, i;
  11344. s = s || {};
  11345. t.editor = ed;
  11346. t.controls = {};
  11347. t.onAdd = new tinymce.util.Dispatcher(t);
  11348. t.onPostRender = new tinymce.util.Dispatcher(t);
  11349. t.prefix = s.prefix || ed.id + '_';
  11350. t._cls = {};
  11351. t.onPostRender.add(function() {
  11352. each(t.controls, function(c) {
  11353. c.postRender();
  11354. });
  11355. });
  11356. },
  11357. get : function(id) {
  11358. return this.controls[this.prefix + id] || this.controls[id];
  11359. },
  11360. setActive : function(id, s) {
  11361. var c = null;
  11362. if (c = this.get(id))
  11363. c.setActive(s);
  11364. return c;
  11365. },
  11366. setDisabled : function(id, s) {
  11367. var c = null;
  11368. if (c = this.get(id))
  11369. c.setDisabled(s);
  11370. return c;
  11371. },
  11372. add : function(c) {
  11373. var t = this;
  11374. if (c) {
  11375. t.controls[c.id] = c;
  11376. t.onAdd.dispatch(c, t);
  11377. }
  11378. return c;
  11379. },
  11380. createControl : function(n) {
  11381. var c, t = this, ed = t.editor;
  11382. each(ed.plugins, function(p) {
  11383. if (p.createControl) {
  11384. c = p.createControl(n, t);
  11385. if (c)
  11386. return false;
  11387. }
  11388. });
  11389. switch (n) {
  11390. case "|":
  11391. case "separator":
  11392. return t.createSeparator();
  11393. }
  11394. if (!c && ed.buttons && (c = ed.buttons[n]))
  11395. return t.createButton(n, c);
  11396. return t.add(c);
  11397. },
  11398. createDropMenu : function(id, s, cc) {
  11399. var t = this, ed = t.editor, c, bm, v, cls;
  11400. s = extend({
  11401. 'class' : 'mceDropDown',
  11402. constrain : ed.settings.constrain_menus
  11403. }, s);
  11404. s['class'] = s['class'] + ' ' + ed.getParam('skin') + 'Skin';
  11405. if (v = ed.getParam('skin_variant'))
  11406. s['class'] += ' ' + ed.getParam('skin') + 'Skin' + v.substring(0, 1).toUpperCase() + v.substring(1);
  11407. id = t.prefix + id;
  11408. cls = cc || t._cls.dropmenu || tinymce.ui.DropMenu;
  11409. c = t.controls[id] = new cls(id, s);
  11410. c.onAddItem.add(function(c, o) {
  11411. var s = o.settings;
  11412. s.title = ed.getLang(s.title, s.title);
  11413. if (!s.onclick) {
  11414. s.onclick = function(v) {
  11415. if (s.cmd)
  11416. ed.execCommand(s.cmd, s.ui || false, s.value);
  11417. };
  11418. }
  11419. });
  11420. ed.onRemove.add(function() {
  11421. c.destroy();
  11422. });
  11423. // Fix for bug #1897785, #1898007
  11424. if (tinymce.isIE) {
  11425. c.onShowMenu.add(function() {
  11426. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  11427. ed.focus();
  11428. bm = ed.selection.getBookmark(1);
  11429. });
  11430. c.onHideMenu.add(function() {
  11431. if (bm) {
  11432. ed.selection.moveToBookmark(bm);
  11433. bm = 0;
  11434. }
  11435. });
  11436. }
  11437. return t.add(c);
  11438. },
  11439. createListBox : function(id, s, cc) {
  11440. var t = this, ed = t.editor, cmd, c, cls;
  11441. if (t.get(id))
  11442. return null;
  11443. s.title = ed.translate(s.title);
  11444. s.scope = s.scope || ed;
  11445. if (!s.onselect) {
  11446. s.onselect = function(v) {
  11447. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11448. };
  11449. }
  11450. s = extend({
  11451. title : s.title,
  11452. 'class' : 'mce_' + id,
  11453. scope : s.scope,
  11454. control_manager : t
  11455. }, s);
  11456. id = t.prefix + id;
  11457. function useNativeListForAccessibility(ed) {
  11458. return ed.settings.use_accessible_selects && !tinymce.isGecko
  11459. }
  11460. if (ed.settings.use_native_selects || useNativeListForAccessibility(ed))
  11461. c = new tinymce.ui.NativeListBox(id, s);
  11462. else {
  11463. cls = cc || t._cls.listbox || tinymce.ui.ListBox;
  11464. c = new cls(id, s, ed);
  11465. }
  11466. t.controls[id] = c;
  11467. // Fix focus problem in Safari
  11468. if (tinymce.isWebKit) {
  11469. c.onPostRender.add(function(c, n) {
  11470. // Store bookmark on mousedown
  11471. Event.add(n, 'mousedown', function() {
  11472. ed.bookmark = ed.selection.getBookmark(1);
  11473. });
  11474. // Restore on focus, since it might be lost
  11475. Event.add(n, 'focus', function() {
  11476. ed.selection.moveToBookmark(ed.bookmark);
  11477. ed.bookmark = null;
  11478. });
  11479. });
  11480. }
  11481. if (c.hideMenu)
  11482. ed.onMouseDown.add(c.hideMenu, c);
  11483. return t.add(c);
  11484. },
  11485. createButton : function(id, s, cc) {
  11486. var t = this, ed = t.editor, o, c, cls;
  11487. if (t.get(id))
  11488. return null;
  11489. s.title = ed.translate(s.title);
  11490. s.label = ed.translate(s.label);
  11491. s.scope = s.scope || ed;
  11492. if (!s.onclick && !s.menu_button) {
  11493. s.onclick = function() {
  11494. ed.execCommand(s.cmd, s.ui || false, s.value);
  11495. };
  11496. }
  11497. s = extend({
  11498. title : s.title,
  11499. 'class' : 'mce_' + id,
  11500. unavailable_prefix : ed.getLang('unavailable', ''),
  11501. scope : s.scope,
  11502. control_manager : t
  11503. }, s);
  11504. id = t.prefix + id;
  11505. if (s.menu_button) {
  11506. cls = cc || t._cls.menubutton || tinymce.ui.MenuButton;
  11507. c = new cls(id, s, ed);
  11508. ed.onMouseDown.add(c.hideMenu, c);
  11509. } else {
  11510. cls = t._cls.button || tinymce.ui.Button;
  11511. c = new cls(id, s, ed);
  11512. }
  11513. return t.add(c);
  11514. },
  11515. createMenuButton : function(id, s, cc) {
  11516. s = s || {};
  11517. s.menu_button = 1;
  11518. return this.createButton(id, s, cc);
  11519. },
  11520. createSplitButton : function(id, s, cc) {
  11521. var t = this, ed = t.editor, cmd, c, cls;
  11522. if (t.get(id))
  11523. return null;
  11524. s.title = ed.translate(s.title);
  11525. s.scope = s.scope || ed;
  11526. if (!s.onclick) {
  11527. s.onclick = function(v) {
  11528. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11529. };
  11530. }
  11531. if (!s.onselect) {
  11532. s.onselect = function(v) {
  11533. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11534. };
  11535. }
  11536. s = extend({
  11537. title : s.title,
  11538. 'class' : 'mce_' + id,
  11539. scope : s.scope,
  11540. control_manager : t
  11541. }, s);
  11542. id = t.prefix + id;
  11543. cls = cc || t._cls.splitbutton || tinymce.ui.SplitButton;
  11544. c = t.add(new cls(id, s, ed));
  11545. ed.onMouseDown.add(c.hideMenu, c);
  11546. return c;
  11547. },
  11548. createColorSplitButton : function(id, s, cc) {
  11549. var t = this, ed = t.editor, cmd, c, cls, bm;
  11550. if (t.get(id))
  11551. return null;
  11552. s.title = ed.translate(s.title);
  11553. s.scope = s.scope || ed;
  11554. if (!s.onclick) {
  11555. s.onclick = function(v) {
  11556. if (tinymce.isIE)
  11557. bm = ed.selection.getBookmark(1);
  11558. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11559. };
  11560. }
  11561. if (!s.onselect) {
  11562. s.onselect = function(v) {
  11563. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11564. };
  11565. }
  11566. s = extend({
  11567. title : s.title,
  11568. 'class' : 'mce_' + id,
  11569. 'menu_class' : ed.getParam('skin') + 'Skin',
  11570. scope : s.scope,
  11571. more_colors_title : ed.getLang('more_colors')
  11572. }, s);
  11573. id = t.prefix + id;
  11574. cls = cc || t._cls.colorsplitbutton || tinymce.ui.ColorSplitButton;
  11575. c = new cls(id, s, ed);
  11576. ed.onMouseDown.add(c.hideMenu, c);
  11577. // Remove the menu element when the editor is removed
  11578. ed.onRemove.add(function() {
  11579. c.destroy();
  11580. });
  11581. // Fix for bug #1897785, #1898007
  11582. if (tinymce.isIE) {
  11583. c.onShowMenu.add(function() {
  11584. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  11585. ed.focus();
  11586. bm = ed.selection.getBookmark(1);
  11587. });
  11588. c.onHideMenu.add(function() {
  11589. if (bm) {
  11590. ed.selection.moveToBookmark(bm);
  11591. bm = 0;
  11592. }
  11593. });
  11594. }
  11595. return t.add(c);
  11596. },
  11597. createToolbar : function(id, s, cc) {
  11598. var c, t = this, cls;
  11599. id = t.prefix + id;
  11600. cls = cc || t._cls.toolbar || tinymce.ui.Toolbar;
  11601. c = new cls(id, s, t.editor);
  11602. if (t.get(id))
  11603. return null;
  11604. return t.add(c);
  11605. },
  11606. createToolbarGroup : function(id, s, cc) {
  11607. var c, t = this, cls;
  11608. id = t.prefix + id;
  11609. cls = cc || this._cls.toolbarGroup || tinymce.ui.ToolbarGroup;
  11610. c = new cls(id, s, t.editor);
  11611. if (t.get(id))
  11612. return null;
  11613. return t.add(c);
  11614. },
  11615. createSeparator : function(cc) {
  11616. var cls = cc || this._cls.separator || tinymce.ui.Separator;
  11617. return new cls();
  11618. },
  11619. setControlType : function(n, c) {
  11620. return this._cls[n.toLowerCase()] = c;
  11621. },
  11622. destroy : function() {
  11623. each(this.controls, function(c) {
  11624. c.destroy();
  11625. });
  11626. this.controls = null;
  11627. }
  11628. });
  11629. })(tinymce);
  11630. (function(tinymce) {
  11631. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isIE = tinymce.isIE, isOpera = tinymce.isOpera;
  11632. tinymce.create('tinymce.WindowManager', {
  11633. WindowManager : function(ed) {
  11634. var t = this;
  11635. t.editor = ed;
  11636. t.onOpen = new Dispatcher(t);
  11637. t.onClose = new Dispatcher(t);
  11638. t.params = {};
  11639. t.features = {};
  11640. },
  11641. open : function(s, p) {
  11642. var t = this, f = '', x, y, mo = t.editor.settings.dialog_type == 'modal', w, sw, sh, vp = tinymce.DOM.getViewPort(), u;
  11643. // Default some options
  11644. s = s || {};
  11645. p = p || {};
  11646. sw = isOpera ? vp.w : screen.width; // Opera uses windows inside the Opera window
  11647. sh = isOpera ? vp.h : screen.height;
  11648. s.name = s.name || 'mc_' + new Date().getTime();
  11649. s.width = parseInt(s.width || 320);
  11650. s.height = parseInt(s.height || 240);
  11651. s.resizable = true;
  11652. s.left = s.left || parseInt(sw / 2.0) - (s.width / 2.0);
  11653. s.top = s.top || parseInt(sh / 2.0) - (s.height / 2.0);
  11654. p.inline = false;
  11655. p.mce_width = s.width;
  11656. p.mce_height = s.height;
  11657. p.mce_auto_focus = s.auto_focus;
  11658. if (mo) {
  11659. if (isIE) {
  11660. s.center = true;
  11661. s.help = false;
  11662. s.dialogWidth = s.width + 'px';
  11663. s.dialogHeight = s.height + 'px';
  11664. s.scroll = s.scrollbars || false;
  11665. }
  11666. }
  11667. // Build features string
  11668. each(s, function(v, k) {
  11669. if (tinymce.is(v, 'boolean'))
  11670. v = v ? 'yes' : 'no';
  11671. if (!/^(name|url)$/.test(k)) {
  11672. if (isIE && mo)
  11673. f += (f ? ';' : '') + k + ':' + v;
  11674. else
  11675. f += (f ? ',' : '') + k + '=' + v;
  11676. }
  11677. });
  11678. t.features = s;
  11679. t.params = p;
  11680. t.onOpen.dispatch(t, s, p);
  11681. u = s.url || s.file;
  11682. u = tinymce._addVer(u);
  11683. try {
  11684. if (isIE && mo) {
  11685. w = 1;
  11686. window.showModalDialog(u, window, f);
  11687. } else
  11688. w = window.open(u, s.name, f);
  11689. } catch (ex) {
  11690. // Ignore
  11691. }
  11692. if (!w)
  11693. alert(t.editor.getLang('popup_blocked'));
  11694. },
  11695. close : function(w) {
  11696. w.close();
  11697. this.onClose.dispatch(this);
  11698. },
  11699. createInstance : function(cl, a, b, c, d, e) {
  11700. var f = tinymce.resolve(cl);
  11701. return new f(a, b, c, d, e);
  11702. },
  11703. confirm : function(t, cb, s, w) {
  11704. w = w || window;
  11705. cb.call(s || this, w.confirm(this._decode(this.editor.getLang(t, t))));
  11706. },
  11707. alert : function(tx, cb, s, w) {
  11708. var t = this;
  11709. w = w || window;
  11710. w.alert(t._decode(t.editor.getLang(tx, tx)));
  11711. if (cb)
  11712. cb.call(s || t);
  11713. },
  11714. resizeBy : function(dw, dh, win) {
  11715. win.resizeBy(dw, dh);
  11716. },
  11717. // Internal functions
  11718. _decode : function(s) {
  11719. return tinymce.DOM.decode(s).replace(/\\n/g, '\n');
  11720. }
  11721. });
  11722. }(tinymce));
  11723. (function(tinymce) {
  11724. tinymce.Formatter = function(ed) {
  11725. var formats = {},
  11726. each = tinymce.each,
  11727. dom = ed.dom,
  11728. selection = ed.selection,
  11729. TreeWalker = tinymce.dom.TreeWalker,
  11730. rangeUtils = new tinymce.dom.RangeUtils(dom),
  11731. isValid = ed.schema.isValidChild,
  11732. isBlock = dom.isBlock,
  11733. forcedRootBlock = ed.settings.forced_root_block,
  11734. nodeIndex = dom.nodeIndex,
  11735. INVISIBLE_CHAR = '\uFEFF',
  11736. MCE_ATTR_RE = /^(src|href|style)$/,
  11737. FALSE = false,
  11738. TRUE = true,
  11739. undefined;
  11740. function isArray(obj) {
  11741. return obj instanceof Array;
  11742. };
  11743. function getParents(node, selector) {
  11744. return dom.getParents(node, selector, dom.getRoot());
  11745. };
  11746. function isCaretNode(node) {
  11747. return node.nodeType === 1 && (node.face === 'mceinline' || node.style.fontFamily === 'mceinline');
  11748. };
  11749. // Public functions
  11750. function get(name) {
  11751. return name ? formats[name] : formats;
  11752. };
  11753. function register(name, format) {
  11754. if (name) {
  11755. if (typeof(name) !== 'string') {
  11756. each(name, function(format, name) {
  11757. register(name, format);
  11758. });
  11759. } else {
  11760. // Force format into array and add it to internal collection
  11761. format = format.length ? format : [format];
  11762. each(format, function(format) {
  11763. // Set deep to false by default on selector formats this to avoid removing
  11764. // alignment on images inside paragraphs when alignment is changed on paragraphs
  11765. if (format.deep === undefined)
  11766. format.deep = !format.selector;
  11767. // Default to true
  11768. if (format.split === undefined)
  11769. format.split = !format.selector || format.inline;
  11770. // Default to true
  11771. if (format.remove === undefined && format.selector && !format.inline)
  11772. format.remove = 'none';
  11773. // Mark format as a mixed format inline + block level
  11774. if (format.selector && format.inline) {
  11775. format.mixed = true;
  11776. format.block_expand = true;
  11777. }
  11778. // Split classes if needed
  11779. if (typeof(format.classes) === 'string')
  11780. format.classes = format.classes.split(/\s+/);
  11781. });
  11782. formats[name] = format;
  11783. }
  11784. }
  11785. };
  11786. var getTextDecoration = function(node) {
  11787. var decoration;
  11788. ed.dom.getParent(node, function(n) {
  11789. decoration = ed.dom.getStyle(n, 'text-decoration');
  11790. return decoration && decoration !== 'none';
  11791. });
  11792. return decoration;
  11793. };
  11794. var processUnderlineAndColor = function(node) {
  11795. var textDecoration;
  11796. if (node.nodeType === 1 && node.parentNode && node.parentNode.nodeType === 1) {
  11797. textDecoration = getTextDecoration(node.parentNode);
  11798. if (ed.dom.getStyle(node, 'color') && textDecoration) {
  11799. ed.dom.setStyle(node, 'text-decoration', textDecoration);
  11800. } else if (ed.dom.getStyle(node, 'textdecoration') === textDecoration) {
  11801. ed.dom.setStyle(node, 'text-decoration', null);
  11802. }
  11803. }
  11804. };
  11805. function apply(name, vars, node) {
  11806. var formatList = get(name), format = formatList[0], bookmark, rng, i, isCollapsed = selection.isCollapsed();
  11807. function moveStart(rng) {
  11808. var container = rng.startContainer,
  11809. offset = rng.startOffset,
  11810. walker, node;
  11811. // Move startContainer/startOffset in to a suitable node
  11812. if (container.nodeType == 1 || container.nodeValue === "") {
  11813. container = container.nodeType == 1 ? container.childNodes[offset] : container;
  11814. // Might fail if the offset is behind the last element in it's container
  11815. if (container) {
  11816. walker = new TreeWalker(container, container.parentNode);
  11817. for (node = walker.current(); node; node = walker.next()) {
  11818. if (node.nodeType == 3 && !isWhiteSpaceNode(node)) {
  11819. rng.setStart(node, 0);
  11820. break;
  11821. }
  11822. }
  11823. }
  11824. }
  11825. return rng;
  11826. };
  11827. function setElementFormat(elm, fmt) {
  11828. fmt = fmt || format;
  11829. if (elm) {
  11830. if (fmt.onformat) {
  11831. fmt.onformat(elm, fmt, vars, node);
  11832. }
  11833. each(fmt.styles, function(value, name) {
  11834. dom.setStyle(elm, name, replaceVars(value, vars));
  11835. });
  11836. each(fmt.attributes, function(value, name) {
  11837. dom.setAttrib(elm, name, replaceVars(value, vars));
  11838. });
  11839. each(fmt.classes, function(value) {
  11840. value = replaceVars(value, vars);
  11841. if (!dom.hasClass(elm, value))
  11842. dom.addClass(elm, value);
  11843. });
  11844. }
  11845. };
  11846. function adjustSelectionToVisibleSelection() {
  11847. function findSelectionEnd(start, end) {
  11848. var walker = new TreeWalker(end);
  11849. for (node = walker.current(); node; node = walker.prev()) {
  11850. if (node.childNodes.length > 1 || node == start) {
  11851. return node;
  11852. }
  11853. }
  11854. };
  11855. // Adjust selection so that a end container with a end offset of zero is not included in the selection
  11856. // as this isn't visible to the user.
  11857. var rng = ed.selection.getRng();
  11858. var start = rng.startContainer;
  11859. var end = rng.endContainer;
  11860. if (start != end && rng.endOffset == 0) {
  11861. var newEnd = findSelectionEnd(start, end);
  11862. var endOffset = newEnd.nodeType == 3 ? newEnd.length : newEnd.childNodes.length;
  11863. rng.setEnd(newEnd, endOffset);
  11864. }
  11865. return rng;
  11866. }
  11867. function applyStyleToList(node, bookmark, wrapElm, newWrappers, process){
  11868. var nodes = [], listIndex = -1, list, startIndex = -1, endIndex = -1, currentWrapElm;
  11869. // find the index of the first child list.
  11870. each(node.childNodes, function(n, index) {
  11871. if (n.nodeName === "UL" || n.nodeName === "OL") {
  11872. listIndex = index;
  11873. list = n;
  11874. return false;
  11875. }
  11876. });
  11877. // get the index of the bookmarks
  11878. each(node.childNodes, function(n, index) {
  11879. if (n.nodeName === "SPAN" && dom.getAttrib(n, "data-mce-type") == "bookmark") {
  11880. if (n.id == bookmark.id + "_start") {
  11881. startIndex = index;
  11882. } else if (n.id == bookmark.id + "_end") {
  11883. endIndex = index;
  11884. }
  11885. }
  11886. });
  11887. // if the selection spans across an embedded list, or there isn't an embedded list - handle processing normally
  11888. if (listIndex <= 0 || (startIndex < listIndex && endIndex > listIndex)) {
  11889. each(tinymce.grep(node.childNodes), process);
  11890. return 0;
  11891. } else {
  11892. currentWrapElm = wrapElm.cloneNode(FALSE);
  11893. // create a list of the nodes on the same side of the list as the selection
  11894. each(tinymce.grep(node.childNodes), function(n, index) {
  11895. if ((startIndex < listIndex && index < listIndex) || (startIndex > listIndex && index > listIndex)) {
  11896. nodes.push(n);
  11897. n.parentNode.removeChild(n);
  11898. }
  11899. });
  11900. // insert the wrapping element either before or after the list.
  11901. if (startIndex < listIndex) {
  11902. node.insertBefore(currentWrapElm, list);
  11903. } else if (startIndex > listIndex) {
  11904. node.insertBefore(currentWrapElm, list.nextSibling);
  11905. }
  11906. // add the new nodes to the list.
  11907. newWrappers.push(currentWrapElm);
  11908. each(nodes, function(node) {
  11909. currentWrapElm.appendChild(node);
  11910. });
  11911. return currentWrapElm;
  11912. }
  11913. };
  11914. function applyRngStyle(rng, bookmark, node_specific) {
  11915. var newWrappers = [], wrapName, wrapElm;
  11916. // Setup wrapper element
  11917. wrapName = format.inline || format.block;
  11918. wrapElm = dom.create(wrapName);
  11919. setElementFormat(wrapElm);
  11920. rangeUtils.walk(rng, function(nodes) {
  11921. var currentWrapElm;
  11922. function process(node) {
  11923. var nodeName = node.nodeName.toLowerCase(), parentName = node.parentNode.nodeName.toLowerCase(), found;
  11924. // Stop wrapping on br elements
  11925. if (isEq(nodeName, 'br')) {
  11926. currentWrapElm = 0;
  11927. // Remove any br elements when we wrap things
  11928. if (format.block)
  11929. dom.remove(node);
  11930. return;
  11931. }
  11932. // If node is wrapper type
  11933. if (format.wrapper && matchNode(node, name, vars)) {
  11934. currentWrapElm = 0;
  11935. return;
  11936. }
  11937. // Can we rename the block
  11938. if (format.block && !format.wrapper && isTextBlock(nodeName)) {
  11939. node = dom.rename(node, wrapName);
  11940. setElementFormat(node);
  11941. newWrappers.push(node);
  11942. currentWrapElm = 0;
  11943. return;
  11944. }
  11945. // Handle selector patterns
  11946. if (format.selector) {
  11947. // Look for matching formats
  11948. each(formatList, function(format) {
  11949. // Check collapsed state if it exists
  11950. if ('collapsed' in format && format.collapsed !== isCollapsed) {
  11951. return;
  11952. }
  11953. if (dom.is(node, format.selector) && !isCaretNode(node)) {
  11954. setElementFormat(node, format);
  11955. found = true;
  11956. }
  11957. });
  11958. // Continue processing if a selector match wasn't found and a inline element is defined
  11959. if (!format.inline || found) {
  11960. currentWrapElm = 0;
  11961. return;
  11962. }
  11963. }
  11964. // Is it valid to wrap this item
  11965. if (isValid(wrapName, nodeName) && isValid(parentName, wrapName) &&
  11966. !(!node_specific && node.nodeType === 3 && node.nodeValue.length === 1 && node.nodeValue.charCodeAt(0) === 65279) && node.id !== '_mce_caret') {
  11967. // Start wrapping
  11968. if (!currentWrapElm) {
  11969. // Wrap the node
  11970. currentWrapElm = wrapElm.cloneNode(FALSE);
  11971. node.parentNode.insertBefore(currentWrapElm, node);
  11972. newWrappers.push(currentWrapElm);
  11973. }
  11974. currentWrapElm.appendChild(node);
  11975. } else if (nodeName == 'li' && bookmark) {
  11976. // Start wrapping - if we are in a list node and have a bookmark, then we will always begin by wrapping in a new element.
  11977. currentWrapElm = applyStyleToList(node, bookmark, wrapElm, newWrappers, process);
  11978. } else {
  11979. // Start a new wrapper for possible children
  11980. currentWrapElm = 0;
  11981. each(tinymce.grep(node.childNodes), process);
  11982. // End the last wrapper
  11983. currentWrapElm = 0;
  11984. }
  11985. };
  11986. // Process siblings from range
  11987. each(nodes, process);
  11988. });
  11989. // Wrap links inside as well, for example color inside a link when the wrapper is around the link
  11990. if (format.wrap_links === false) {
  11991. each(newWrappers, function(node) {
  11992. function process(node) {
  11993. var i, currentWrapElm, children;
  11994. if (node.nodeName === 'A') {
  11995. currentWrapElm = wrapElm.cloneNode(FALSE);
  11996. newWrappers.push(currentWrapElm);
  11997. children = tinymce.grep(node.childNodes);
  11998. for (i = 0; i < children.length; i++)
  11999. currentWrapElm.appendChild(children[i]);
  12000. node.appendChild(currentWrapElm);
  12001. }
  12002. each(tinymce.grep(node.childNodes), process);
  12003. };
  12004. process(node);
  12005. });
  12006. }
  12007. // Cleanup
  12008. each(newWrappers, function(node) {
  12009. var childCount;
  12010. function getChildCount(node) {
  12011. var count = 0;
  12012. each(node.childNodes, function(node) {
  12013. if (!isWhiteSpaceNode(node) && !isBookmarkNode(node))
  12014. count++;
  12015. });
  12016. return count;
  12017. };
  12018. function mergeStyles(node) {
  12019. var child, clone;
  12020. each(node.childNodes, function(node) {
  12021. if (node.nodeType == 1 && !isBookmarkNode(node) && !isCaretNode(node)) {
  12022. child = node;
  12023. return FALSE; // break loop
  12024. }
  12025. });
  12026. // If child was found and of the same type as the current node
  12027. if (child && matchName(child, format)) {
  12028. clone = child.cloneNode(FALSE);
  12029. setElementFormat(clone);
  12030. dom.replace(clone, node, TRUE);
  12031. dom.remove(child, 1);
  12032. }
  12033. return clone || node;
  12034. };
  12035. childCount = getChildCount(node);
  12036. // Remove empty nodes but only if there is multiple wrappers and they are not block
  12037. // elements so never remove single <h1></h1> since that would remove the currrent empty block element where the caret is at
  12038. if ((newWrappers.length > 1 || !isBlock(node)) && childCount === 0) {
  12039. dom.remove(node, 1);
  12040. return;
  12041. }
  12042. if (format.inline || format.wrapper) {
  12043. // Merges the current node with it's children of similar type to reduce the number of elements
  12044. if (!format.exact && childCount === 1)
  12045. node = mergeStyles(node);
  12046. // Remove/merge children
  12047. each(formatList, function(format) {
  12048. // Merge all children of similar type will move styles from child to parent
  12049. // this: <span style="color:red"><b><span style="color:red; font-size:10px">text</span></b></span>
  12050. // will become: <span style="color:red"><b><span style="font-size:10px">text</span></b></span>
  12051. each(dom.select(format.inline, node), function(child) {
  12052. var parent;
  12053. // When wrap_links is set to false we don't want
  12054. // to remove the format on children within links
  12055. if (format.wrap_links === false) {
  12056. parent = child.parentNode;
  12057. do {
  12058. if (parent.nodeName === 'A')
  12059. return;
  12060. } while (parent = parent.parentNode);
  12061. }
  12062. removeFormat(format, vars, child, format.exact ? child : null);
  12063. });
  12064. });
  12065. // Remove child if direct parent is of same type
  12066. if (matchNode(node.parentNode, name, vars)) {
  12067. dom.remove(node, 1);
  12068. node = 0;
  12069. return TRUE;
  12070. }
  12071. // Look for parent with similar style format
  12072. if (format.merge_with_parents) {
  12073. dom.getParent(node.parentNode, function(parent) {
  12074. if (matchNode(parent, name, vars)) {
  12075. dom.remove(node, 1);
  12076. node = 0;
  12077. return TRUE;
  12078. }
  12079. });
  12080. }
  12081. // Merge next and previous siblings if they are similar <b>text</b><b>text</b> becomes <b>texttext</b>
  12082. if (node && format.merge_siblings !== false) {
  12083. node = mergeSiblings(getNonWhiteSpaceSibling(node), node);
  12084. node = mergeSiblings(node, getNonWhiteSpaceSibling(node, TRUE));
  12085. }
  12086. }
  12087. });
  12088. };
  12089. if (format) {
  12090. if (node) {
  12091. if (node.nodeType) {
  12092. rng = dom.createRng();
  12093. rng.setStartBefore(node);
  12094. rng.setEndAfter(node);
  12095. applyRngStyle(expandRng(rng, formatList), null, true);
  12096. } else {
  12097. applyRngStyle(node, null, true);
  12098. }
  12099. } else {
  12100. if (!isCollapsed || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
  12101. // Obtain selection node before selection is unselected by applyRngStyle()
  12102. var curSelNode = ed.selection.getNode();
  12103. // Apply formatting to selection
  12104. ed.selection.setRng(adjustSelectionToVisibleSelection());
  12105. bookmark = selection.getBookmark();
  12106. applyRngStyle(expandRng(selection.getRng(TRUE), formatList), bookmark);
  12107. // Colored nodes should be underlined so that the color of the underline matches the text color.
  12108. if (format.styles && (format.styles.color || format.styles.textDecoration)) {
  12109. tinymce.walk(curSelNode, processUnderlineAndColor, 'childNodes');
  12110. processUnderlineAndColor(curSelNode);
  12111. }
  12112. selection.moveToBookmark(bookmark);
  12113. selection.setRng(moveStart(selection.getRng(TRUE)));
  12114. ed.nodeChanged();
  12115. } else
  12116. performCaretAction('apply', name, vars);
  12117. }
  12118. }
  12119. };
  12120. function remove(name, vars, node) {
  12121. var formatList = get(name), format = formatList[0], bookmark, i, rng;
  12122. function moveStart(rng) {
  12123. var container = rng.startContainer,
  12124. offset = rng.startOffset,
  12125. walker, node, nodes, tmpNode;
  12126. // Convert text node into index if possible
  12127. if (container.nodeType == 3 && offset >= container.nodeValue.length - 1) {
  12128. container = container.parentNode;
  12129. offset = nodeIndex(container) + 1;
  12130. }
  12131. // Move startContainer/startOffset in to a suitable node
  12132. if (container.nodeType == 1) {
  12133. nodes = container.childNodes;
  12134. container = nodes[Math.min(offset, nodes.length - 1)];
  12135. walker = new TreeWalker(container);
  12136. // If offset is at end of the parent node walk to the next one
  12137. if (offset > nodes.length - 1)
  12138. walker.next();
  12139. for (node = walker.current(); node; node = walker.next()) {
  12140. if (node.nodeType == 3 && !isWhiteSpaceNode(node)) {
  12141. // IE has a "neat" feature where it moves the start node into the closest element
  12142. // we can avoid this by inserting an element before it and then remove it after we set the selection
  12143. tmpNode = dom.create('a', null, INVISIBLE_CHAR);
  12144. node.parentNode.insertBefore(tmpNode, node);
  12145. // Set selection and remove tmpNode
  12146. rng.setStart(node, 0);
  12147. selection.setRng(rng);
  12148. dom.remove(tmpNode);
  12149. return;
  12150. }
  12151. }
  12152. }
  12153. };
  12154. // Merges the styles for each node
  12155. function process(node) {
  12156. var children, i, l;
  12157. // Grab the children first since the nodelist might be changed
  12158. children = tinymce.grep(node.childNodes);
  12159. // Process current node
  12160. for (i = 0, l = formatList.length; i < l; i++) {
  12161. if (removeFormat(formatList[i], vars, node, node))
  12162. break;
  12163. }
  12164. // Process the children
  12165. if (format.deep) {
  12166. for (i = 0, l = children.length; i < l; i++)
  12167. process(children[i]);
  12168. }
  12169. };
  12170. function findFormatRoot(container) {
  12171. var formatRoot;
  12172. // Find format root
  12173. each(getParents(container.parentNode).reverse(), function(parent) {
  12174. var format;
  12175. // Find format root element
  12176. if (!formatRoot && parent.id != '_start' && parent.id != '_end') {
  12177. // Is the node matching the format we are looking for
  12178. format = matchNode(parent, name, vars);
  12179. if (format && format.split !== false)
  12180. formatRoot = parent;
  12181. }
  12182. });
  12183. return formatRoot;
  12184. };
  12185. function wrapAndSplit(format_root, container, target, split) {
  12186. var parent, clone, lastClone, firstClone, i, formatRootParent;
  12187. // Format root found then clone formats and split it
  12188. if (format_root) {
  12189. formatRootParent = format_root.parentNode;
  12190. for (parent = container.parentNode; parent && parent != formatRootParent; parent = parent.parentNode) {
  12191. clone = parent.cloneNode(FALSE);
  12192. for (i = 0; i < formatList.length; i++) {
  12193. if (removeFormat(formatList[i], vars, clone, clone)) {
  12194. clone = 0;
  12195. break;
  12196. }
  12197. }
  12198. // Build wrapper node
  12199. if (clone) {
  12200. if (lastClone)
  12201. clone.appendChild(lastClone);
  12202. if (!firstClone)
  12203. firstClone = clone;
  12204. lastClone = clone;
  12205. }
  12206. }
  12207. // Never split block elements if the format is mixed
  12208. if (split && (!format.mixed || !isBlock(format_root)))
  12209. container = dom.split(format_root, container);
  12210. // Wrap container in cloned formats
  12211. if (lastClone) {
  12212. target.parentNode.insertBefore(lastClone, target);
  12213. firstClone.appendChild(target);
  12214. }
  12215. }
  12216. return container;
  12217. };
  12218. function splitToFormatRoot(container) {
  12219. return wrapAndSplit(findFormatRoot(container), container, container, true);
  12220. };
  12221. function unwrap(start) {
  12222. var node = dom.get(start ? '_start' : '_end'),
  12223. out = node[start ? 'firstChild' : 'lastChild'];
  12224. // If the end is placed within the start the result will be removed
  12225. // So this checks if the out node is a bookmark node if it is it
  12226. // checks for another more suitable node
  12227. if (isBookmarkNode(out))
  12228. out = out[start ? 'firstChild' : 'lastChild'];
  12229. dom.remove(node, true);
  12230. return out;
  12231. };
  12232. function removeRngStyle(rng) {
  12233. var startContainer, endContainer;
  12234. rng = expandRng(rng, formatList, TRUE);
  12235. if (format.split) {
  12236. startContainer = getContainer(rng, TRUE);
  12237. endContainer = getContainer(rng);
  12238. if (startContainer != endContainer) {
  12239. // Wrap start/end nodes in span element since these might be cloned/moved
  12240. startContainer = wrap(startContainer, 'span', {id : '_start', 'data-mce-type' : 'bookmark'});
  12241. endContainer = wrap(endContainer, 'span', {id : '_end', 'data-mce-type' : 'bookmark'});
  12242. // Split start/end
  12243. splitToFormatRoot(startContainer);
  12244. splitToFormatRoot(endContainer);
  12245. // Unwrap start/end to get real elements again
  12246. startContainer = unwrap(TRUE);
  12247. endContainer = unwrap();
  12248. } else
  12249. startContainer = endContainer = splitToFormatRoot(startContainer);
  12250. // Update range positions since they might have changed after the split operations
  12251. rng.startContainer = startContainer.parentNode;
  12252. rng.startOffset = nodeIndex(startContainer);
  12253. rng.endContainer = endContainer.parentNode;
  12254. rng.endOffset = nodeIndex(endContainer) + 1;
  12255. }
  12256. // Remove items between start/end
  12257. rangeUtils.walk(rng, function(nodes) {
  12258. each(nodes, function(node) {
  12259. process(node);
  12260. // Remove parent span if it only contains text-decoration: underline, yet a parent node is also underlined.
  12261. if (node.nodeType === 1 && ed.dom.getStyle(node, 'text-decoration') === 'underline' && node.parentNode && getTextDecoration(node.parentNode) === 'underline') {
  12262. removeFormat({'deep': false, 'exact': true, 'inline': 'span', 'styles': {'textDecoration' : 'underline'}}, null, node);
  12263. }
  12264. });
  12265. });
  12266. };
  12267. // Handle node
  12268. if (node) {
  12269. if (node.nodeType) {
  12270. rng = dom.createRng();
  12271. rng.setStartBefore(node);
  12272. rng.setEndAfter(node);
  12273. removeRngStyle(rng);
  12274. } else {
  12275. removeRngStyle(node);
  12276. }
  12277. return;
  12278. }
  12279. if (!selection.isCollapsed() || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
  12280. bookmark = selection.getBookmark();
  12281. removeRngStyle(selection.getRng(TRUE));
  12282. selection.moveToBookmark(bookmark);
  12283. // 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
  12284. if (format.inline && match(name, vars, selection.getStart())) {
  12285. moveStart(selection.getRng(true));
  12286. }
  12287. ed.nodeChanged();
  12288. } else
  12289. performCaretAction('remove', name, vars);
  12290. // When you remove formatting from a table cell in WebKit (cell, not the contents of a cell) there is a rendering issue with column width
  12291. if (tinymce.isWebKit) {
  12292. ed.execCommand('mceCleanup');
  12293. }
  12294. };
  12295. function toggle(name, vars, node) {
  12296. var fmt = get(name);
  12297. if (match(name, vars, node) && (!('toggle' in fmt[0]) || fmt[0]['toggle']))
  12298. remove(name, vars, node);
  12299. else
  12300. apply(name, vars, node);
  12301. };
  12302. function matchNode(node, name, vars, similar) {
  12303. var formatList = get(name), format, i, classes;
  12304. function matchItems(node, format, item_name) {
  12305. var key, value, items = format[item_name], i;
  12306. // Custom match
  12307. if (format.onmatch) {
  12308. return format.onmatch(node, format, item_name);
  12309. }
  12310. // Check all items
  12311. if (items) {
  12312. // Non indexed object
  12313. if (items.length === undefined) {
  12314. for (key in items) {
  12315. if (items.hasOwnProperty(key)) {
  12316. if (item_name === 'attributes')
  12317. value = dom.getAttrib(node, key);
  12318. else
  12319. value = getStyle(node, key);
  12320. if (similar && !value && !format.exact)
  12321. return;
  12322. if ((!similar || format.exact) && !isEq(value, replaceVars(items[key], vars)))
  12323. return;
  12324. }
  12325. }
  12326. } else {
  12327. // Only one match needed for indexed arrays
  12328. for (i = 0; i < items.length; i++) {
  12329. if (item_name === 'attributes' ? dom.getAttrib(node, items[i]) : getStyle(node, items[i]))
  12330. return format;
  12331. }
  12332. }
  12333. }
  12334. return format;
  12335. };
  12336. if (formatList && node) {
  12337. // Check each format in list
  12338. for (i = 0; i < formatList.length; i++) {
  12339. format = formatList[i];
  12340. // Name name, attributes, styles and classes
  12341. if (matchName(node, format) && matchItems(node, format, 'attributes') && matchItems(node, format, 'styles')) {
  12342. // Match classes
  12343. if (classes = format.classes) {
  12344. for (i = 0; i < classes.length; i++) {
  12345. if (!dom.hasClass(node, classes[i]))
  12346. return;
  12347. }
  12348. }
  12349. return format;
  12350. }
  12351. }
  12352. }
  12353. };
  12354. function match(name, vars, node) {
  12355. var startNode;
  12356. function matchParents(node) {
  12357. // Find first node with similar format settings
  12358. node = dom.getParent(node, function(node) {
  12359. return !!matchNode(node, name, vars, true);
  12360. });
  12361. // Do an exact check on the similar format element
  12362. return matchNode(node, name, vars);
  12363. };
  12364. // Check specified node
  12365. if (node)
  12366. return matchParents(node);
  12367. // Check selected node
  12368. node = selection.getNode();
  12369. if (matchParents(node))
  12370. return TRUE;
  12371. // Check start node if it's different
  12372. startNode = selection.getStart();
  12373. if (startNode != node) {
  12374. if (matchParents(startNode))
  12375. return TRUE;
  12376. }
  12377. return FALSE;
  12378. };
  12379. function matchAll(names, vars) {
  12380. var startElement, matchedFormatNames = [], checkedMap = {}, i, ni, name;
  12381. // Check start of selection for formats
  12382. startElement = selection.getStart();
  12383. dom.getParent(startElement, function(node) {
  12384. var i, name;
  12385. for (i = 0; i < names.length; i++) {
  12386. name = names[i];
  12387. if (!checkedMap[name] && matchNode(node, name, vars)) {
  12388. checkedMap[name] = true;
  12389. matchedFormatNames.push(name);
  12390. }
  12391. }
  12392. });
  12393. return matchedFormatNames;
  12394. };
  12395. function canApply(name) {
  12396. var formatList = get(name), startNode, parents, i, x, selector;
  12397. if (formatList) {
  12398. startNode = selection.getStart();
  12399. parents = getParents(startNode);
  12400. for (x = formatList.length - 1; x >= 0; x--) {
  12401. selector = formatList[x].selector;
  12402. // Format is not selector based, then always return TRUE
  12403. if (!selector)
  12404. return TRUE;
  12405. for (i = parents.length - 1; i >= 0; i--) {
  12406. if (dom.is(parents[i], selector))
  12407. return TRUE;
  12408. }
  12409. }
  12410. }
  12411. return FALSE;
  12412. };
  12413. // Expose to public
  12414. tinymce.extend(this, {
  12415. get : get,
  12416. register : register,
  12417. apply : apply,
  12418. remove : remove,
  12419. toggle : toggle,
  12420. match : match,
  12421. matchAll : matchAll,
  12422. matchNode : matchNode,
  12423. canApply : canApply
  12424. });
  12425. // Private functions
  12426. function matchName(node, format) {
  12427. // Check for inline match
  12428. if (isEq(node, format.inline))
  12429. return TRUE;
  12430. // Check for block match
  12431. if (isEq(node, format.block))
  12432. return TRUE;
  12433. // Check for selector match
  12434. if (format.selector)
  12435. return dom.is(node, format.selector);
  12436. };
  12437. function isEq(str1, str2) {
  12438. str1 = str1 || '';
  12439. str2 = str2 || '';
  12440. str1 = '' + (str1.nodeName || str1);
  12441. str2 = '' + (str2.nodeName || str2);
  12442. return str1.toLowerCase() == str2.toLowerCase();
  12443. };
  12444. function getStyle(node, name) {
  12445. var styleVal = dom.getStyle(node, name);
  12446. // Force the format to hex
  12447. if (name == 'color' || name == 'backgroundColor')
  12448. styleVal = dom.toHex(styleVal);
  12449. // Opera will return bold as 700
  12450. if (name == 'fontWeight' && styleVal == 700)
  12451. styleVal = 'bold';
  12452. return '' + styleVal;
  12453. };
  12454. function replaceVars(value, vars) {
  12455. if (typeof(value) != "string")
  12456. value = value(vars);
  12457. else if (vars) {
  12458. value = value.replace(/%(\w+)/g, function(str, name) {
  12459. return vars[name] || str;
  12460. });
  12461. }
  12462. return value;
  12463. };
  12464. function isWhiteSpaceNode(node) {
  12465. return node && node.nodeType === 3 && /^([\t \r\n]+|)$/.test(node.nodeValue);
  12466. };
  12467. function wrap(node, name, attrs) {
  12468. var wrapper = dom.create(name, attrs);
  12469. node.parentNode.insertBefore(wrapper, node);
  12470. wrapper.appendChild(node);
  12471. return wrapper;
  12472. };
  12473. function expandRng(rng, format, remove) {
  12474. var startContainer = rng.startContainer,
  12475. startOffset = rng.startOffset,
  12476. endContainer = rng.endContainer,
  12477. endOffset = rng.endOffset, sibling, lastIdx, leaf, endPoint;
  12478. // This function walks up the tree if there is no siblings before/after the node
  12479. function findParentContainer(start) {
  12480. var container, parent, child, sibling, siblingName;
  12481. container = parent = start ? startContainer : endContainer;
  12482. siblingName = start ? 'previousSibling' : 'nextSibling';
  12483. root = dom.getRoot();
  12484. // If it's a text node and the offset is inside the text
  12485. if (container.nodeType == 3 && !isWhiteSpaceNode(container)) {
  12486. if (start ? startOffset > 0 : endOffset < container.nodeValue.length) {
  12487. return container;
  12488. }
  12489. }
  12490. for (;;) {
  12491. // Stop expanding on block elements or root depending on format
  12492. if (parent == root || (!format[0].block_expand && isBlock(parent)))
  12493. return parent;
  12494. // Walk left/right
  12495. for (sibling = parent[siblingName]; sibling; sibling = sibling[siblingName]) {
  12496. if (!isBookmarkNode(sibling) && !isWhiteSpaceNode(sibling)) {
  12497. return parent;
  12498. }
  12499. }
  12500. // Check if we can move up are we at root level or body level
  12501. parent = parent.parentNode;
  12502. }
  12503. return container;
  12504. };
  12505. // This function walks down the tree to find the leaf at the selection.
  12506. // The offset is also returned as if node initially a leaf, the offset may be in the middle of the text node.
  12507. function findLeaf(node, offset) {
  12508. if (offset === undefined)
  12509. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  12510. while (node && node.hasChildNodes()) {
  12511. node = node.childNodes[offset];
  12512. if (node)
  12513. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  12514. }
  12515. return { node: node, offset: offset };
  12516. }
  12517. // If index based start position then resolve it
  12518. if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) {
  12519. lastIdx = startContainer.childNodes.length - 1;
  12520. startContainer = startContainer.childNodes[startOffset > lastIdx ? lastIdx : startOffset];
  12521. if (startContainer.nodeType == 3)
  12522. startOffset = 0;
  12523. }
  12524. // If index based end position then resolve it
  12525. if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) {
  12526. lastIdx = endContainer.childNodes.length - 1;
  12527. endContainer = endContainer.childNodes[endOffset > lastIdx ? lastIdx : endOffset - 1];
  12528. if (endContainer.nodeType == 3)
  12529. endOffset = endContainer.nodeValue.length;
  12530. }
  12531. // Exclude bookmark nodes if possible
  12532. if (isBookmarkNode(startContainer.parentNode) || isBookmarkNode(startContainer)) {
  12533. startContainer = isBookmarkNode(startContainer) ? startContainer : startContainer.parentNode;
  12534. startContainer = startContainer.nextSibling || startContainer;
  12535. if (startContainer.nodeType == 3)
  12536. startOffset = 0;
  12537. }
  12538. if (isBookmarkNode(endContainer.parentNode) || isBookmarkNode(endContainer)) {
  12539. endContainer = isBookmarkNode(endContainer) ? endContainer : endContainer.parentNode;
  12540. endContainer = endContainer.previousSibling || endContainer;
  12541. if (endContainer.nodeType == 3)
  12542. endOffset = endContainer.length;
  12543. }
  12544. if (format[0].inline) {
  12545. if (rng.collapsed) {
  12546. function findWordEndPoint(container, offset, start) {
  12547. var walker, node, pos, lastTextNode;
  12548. function findSpace(node, offset) {
  12549. var pos, pos2, str = node.nodeValue;
  12550. if (typeof(offset) == "undefined") {
  12551. offset = start ? str.length : 0;
  12552. }
  12553. if (start) {
  12554. pos = str.lastIndexOf(' ', offset);
  12555. pos2 = str.lastIndexOf('\u00a0', offset);
  12556. pos = pos > pos2 ? pos : pos2;
  12557. // Include the space on remove to avoid tag soup
  12558. if (pos !== -1 && !remove) {
  12559. pos++;
  12560. }
  12561. } else {
  12562. pos = str.indexOf(' ', offset);
  12563. pos2 = str.indexOf('\u00a0', offset);
  12564. pos = pos !== -1 && (pos2 === -1 || pos < pos2) ? pos : pos2;
  12565. }
  12566. return pos;
  12567. };
  12568. if (container.nodeType === 3) {
  12569. pos = findSpace(container, offset);
  12570. if (pos !== -1) {
  12571. return {container : container, offset : pos};
  12572. }
  12573. lastTextNode = container;
  12574. }
  12575. // Walk the nodes inside the block
  12576. walker = new TreeWalker(container, dom.getParent(container, isBlock) || ed.getBody());
  12577. while (node = walker[start ? 'prev' : 'next']()) {
  12578. if (node.nodeType === 3) {
  12579. lastTextNode = node;
  12580. pos = findSpace(node);
  12581. if (pos !== -1) {
  12582. return {container : node, offset : pos};
  12583. }
  12584. } else if (isBlock(node)) {
  12585. break;
  12586. }
  12587. }
  12588. if (lastTextNode) {
  12589. if (start) {
  12590. offset = 0;
  12591. } else {
  12592. offset = lastTextNode.length;
  12593. }
  12594. return {container: lastTextNode, offset: offset};
  12595. }
  12596. }
  12597. // Expand left to closest word boundery
  12598. endPoint = findWordEndPoint(startContainer, startOffset, true);
  12599. if (endPoint) {
  12600. startContainer = endPoint.container;
  12601. startOffset = endPoint.offset;
  12602. }
  12603. // Expand right to closest word boundery
  12604. endPoint = findWordEndPoint(endContainer, endOffset);
  12605. if (endPoint) {
  12606. endContainer = endPoint.container;
  12607. endOffset = endPoint.offset;
  12608. }
  12609. }
  12610. // Avoid applying formatting to a trailing space.
  12611. leaf = findLeaf(endContainer, endOffset);
  12612. if (leaf.node) {
  12613. while (leaf.node && leaf.offset === 0 && leaf.node.previousSibling)
  12614. leaf = findLeaf(leaf.node.previousSibling);
  12615. if (leaf.node && leaf.offset > 0 && leaf.node.nodeType === 3 &&
  12616. leaf.node.nodeValue.charAt(leaf.offset - 1) === ' ') {
  12617. if (leaf.offset > 1) {
  12618. endContainer = leaf.node;
  12619. endContainer.splitText(leaf.offset - 1);
  12620. } else if (leaf.node.previousSibling) {
  12621. // TODO: Figure out why this is in here
  12622. //endContainer = leaf.node.previousSibling;
  12623. }
  12624. }
  12625. }
  12626. }
  12627. // Move start/end point up the tree if the leaves are sharp and if we are in different containers
  12628. // Example * becomes !: !<p><b><i>*text</i><i>text*</i></b></p>!
  12629. // This will reduce the number of wrapper elements that needs to be created
  12630. // Move start point up the tree
  12631. if (format[0].inline || format[0].block_expand) {
  12632. if (!format[0].inline || (startContainer.nodeType != 3 || startOffset === 0)) {
  12633. startContainer = findParentContainer(true);
  12634. }
  12635. if (!format[0].inline || (endContainer.nodeType != 3 || endOffset === endContainer.nodeValue.length)) {
  12636. endContainer = findParentContainer();
  12637. }
  12638. }
  12639. // Expand start/end container to matching selector
  12640. if (format[0].selector && format[0].expand !== FALSE && !format[0].inline) {
  12641. function findSelectorEndPoint(container, sibling_name) {
  12642. var parents, i, y, curFormat;
  12643. if (container.nodeType == 3 && container.nodeValue.length == 0 && container[sibling_name])
  12644. container = container[sibling_name];
  12645. parents = getParents(container);
  12646. for (i = 0; i < parents.length; i++) {
  12647. for (y = 0; y < format.length; y++) {
  12648. curFormat = format[y];
  12649. // If collapsed state is set then skip formats that doesn't match that
  12650. if ("collapsed" in curFormat && curFormat.collapsed !== rng.collapsed)
  12651. continue;
  12652. if (dom.is(parents[i], curFormat.selector))
  12653. return parents[i];
  12654. }
  12655. }
  12656. return container;
  12657. };
  12658. // Find new startContainer/endContainer if there is better one
  12659. startContainer = findSelectorEndPoint(startContainer, 'previousSibling');
  12660. endContainer = findSelectorEndPoint(endContainer, 'nextSibling');
  12661. }
  12662. // Expand start/end container to matching block element or text node
  12663. if (format[0].block || format[0].selector) {
  12664. function findBlockEndPoint(container, sibling_name, sibling_name2) {
  12665. var node;
  12666. // Expand to block of similar type
  12667. if (!format[0].wrapper)
  12668. node = dom.getParent(container, format[0].block);
  12669. // Expand to first wrappable block element or any block element
  12670. if (!node)
  12671. node = dom.getParent(container.nodeType == 3 ? container.parentNode : container, isBlock);
  12672. // Exclude inner lists from wrapping
  12673. if (node && format[0].wrapper)
  12674. node = getParents(node, 'ul,ol').reverse()[0] || node;
  12675. // Didn't find a block element look for first/last wrappable element
  12676. if (!node) {
  12677. node = container;
  12678. while (node[sibling_name] && !isBlock(node[sibling_name])) {
  12679. node = node[sibling_name];
  12680. // Break on BR but include it will be removed later on
  12681. // we can't remove it now since we need to check if it can be wrapped
  12682. if (isEq(node, 'br'))
  12683. break;
  12684. }
  12685. }
  12686. return node || container;
  12687. };
  12688. // Find new startContainer/endContainer if there is better one
  12689. startContainer = findBlockEndPoint(startContainer, 'previousSibling');
  12690. endContainer = findBlockEndPoint(endContainer, 'nextSibling');
  12691. // Non block element then try to expand up the leaf
  12692. if (format[0].block) {
  12693. if (!isBlock(startContainer))
  12694. startContainer = findParentContainer(true);
  12695. if (!isBlock(endContainer))
  12696. endContainer = findParentContainer();
  12697. }
  12698. }
  12699. // Setup index for startContainer
  12700. if (startContainer.nodeType == 1) {
  12701. startOffset = nodeIndex(startContainer);
  12702. startContainer = startContainer.parentNode;
  12703. }
  12704. // Setup index for endContainer
  12705. if (endContainer.nodeType == 1) {
  12706. endOffset = nodeIndex(endContainer) + 1;
  12707. endContainer = endContainer.parentNode;
  12708. }
  12709. // Return new range like object
  12710. return {
  12711. startContainer : startContainer,
  12712. startOffset : startOffset,
  12713. endContainer : endContainer,
  12714. endOffset : endOffset
  12715. };
  12716. }
  12717. function removeFormat(format, vars, node, compare_node) {
  12718. var i, attrs, stylesModified;
  12719. // Check if node matches format
  12720. if (!matchName(node, format))
  12721. return FALSE;
  12722. // Should we compare with format attribs and styles
  12723. if (format.remove != 'all') {
  12724. // Remove styles
  12725. each(format.styles, function(value, name) {
  12726. value = replaceVars(value, vars);
  12727. // Indexed array
  12728. if (typeof(name) === 'number') {
  12729. name = value;
  12730. compare_node = 0;
  12731. }
  12732. if (!compare_node || isEq(getStyle(compare_node, name), value))
  12733. dom.setStyle(node, name, '');
  12734. stylesModified = 1;
  12735. });
  12736. // Remove style attribute if it's empty
  12737. if (stylesModified && dom.getAttrib(node, 'style') == '') {
  12738. node.removeAttribute('style');
  12739. node.removeAttribute('data-mce-style');
  12740. }
  12741. // Remove attributes
  12742. each(format.attributes, function(value, name) {
  12743. var valueOut;
  12744. value = replaceVars(value, vars);
  12745. // Indexed array
  12746. if (typeof(name) === 'number') {
  12747. name = value;
  12748. compare_node = 0;
  12749. }
  12750. if (!compare_node || isEq(dom.getAttrib(compare_node, name), value)) {
  12751. // Keep internal classes
  12752. if (name == 'class') {
  12753. value = dom.getAttrib(node, name);
  12754. if (value) {
  12755. // Build new class value where everything is removed except the internal prefixed classes
  12756. valueOut = '';
  12757. each(value.split(/\s+/), function(cls) {
  12758. if (/mce\w+/.test(cls))
  12759. valueOut += (valueOut ? ' ' : '') + cls;
  12760. });
  12761. // We got some internal classes left
  12762. if (valueOut) {
  12763. dom.setAttrib(node, name, valueOut);
  12764. return;
  12765. }
  12766. }
  12767. }
  12768. // IE6 has a bug where the attribute doesn't get removed correctly
  12769. if (name == "class")
  12770. node.removeAttribute('className');
  12771. // Remove mce prefixed attributes
  12772. if (MCE_ATTR_RE.test(name))
  12773. node.removeAttribute('data-mce-' + name);
  12774. node.removeAttribute(name);
  12775. }
  12776. });
  12777. // Remove classes
  12778. each(format.classes, function(value) {
  12779. value = replaceVars(value, vars);
  12780. if (!compare_node || dom.hasClass(compare_node, value))
  12781. dom.removeClass(node, value);
  12782. });
  12783. // Check for non internal attributes
  12784. attrs = dom.getAttribs(node);
  12785. for (i = 0; i < attrs.length; i++) {
  12786. if (attrs[i].nodeName.indexOf('_') !== 0)
  12787. return FALSE;
  12788. }
  12789. }
  12790. // Remove the inline child if it's empty for example <b> or <span>
  12791. if (format.remove != 'none') {
  12792. removeNode(node, format);
  12793. return TRUE;
  12794. }
  12795. };
  12796. function removeNode(node, format) {
  12797. var parentNode = node.parentNode, rootBlockElm;
  12798. if (format.block) {
  12799. if (!forcedRootBlock) {
  12800. function find(node, next, inc) {
  12801. node = getNonWhiteSpaceSibling(node, next, inc);
  12802. return !node || (node.nodeName == 'BR' || isBlock(node));
  12803. };
  12804. // Append BR elements if needed before we remove the block
  12805. if (isBlock(node) && !isBlock(parentNode)) {
  12806. if (!find(node, FALSE) && !find(node.firstChild, TRUE, 1))
  12807. node.insertBefore(dom.create('br'), node.firstChild);
  12808. if (!find(node, TRUE) && !find(node.lastChild, FALSE, 1))
  12809. node.appendChild(dom.create('br'));
  12810. }
  12811. } else {
  12812. // Wrap the block in a forcedRootBlock if we are at the root of document
  12813. if (parentNode == dom.getRoot()) {
  12814. if (!format.list_block || !isEq(node, format.list_block)) {
  12815. each(tinymce.grep(node.childNodes), function(node) {
  12816. if (isValid(forcedRootBlock, node.nodeName.toLowerCase())) {
  12817. if (!rootBlockElm)
  12818. rootBlockElm = wrap(node, forcedRootBlock);
  12819. else
  12820. rootBlockElm.appendChild(node);
  12821. } else
  12822. rootBlockElm = 0;
  12823. });
  12824. }
  12825. }
  12826. }
  12827. }
  12828. // Never remove nodes that isn't the specified inline element if a selector is specified too
  12829. if (format.selector && format.inline && !isEq(format.inline, node))
  12830. return;
  12831. dom.remove(node, 1);
  12832. };
  12833. function getNonWhiteSpaceSibling(node, next, inc) {
  12834. if (node) {
  12835. next = next ? 'nextSibling' : 'previousSibling';
  12836. for (node = inc ? node : node[next]; node; node = node[next]) {
  12837. if (node.nodeType == 1 || !isWhiteSpaceNode(node))
  12838. return node;
  12839. }
  12840. }
  12841. };
  12842. function isBookmarkNode(node) {
  12843. return node && node.nodeType == 1 && node.getAttribute('data-mce-type') == 'bookmark';
  12844. };
  12845. function mergeSiblings(prev, next) {
  12846. var marker, sibling, tmpSibling;
  12847. function compareElements(node1, node2) {
  12848. // Not the same name
  12849. if (node1.nodeName != node2.nodeName)
  12850. return FALSE;
  12851. function getAttribs(node) {
  12852. var attribs = {};
  12853. each(dom.getAttribs(node), function(attr) {
  12854. var name = attr.nodeName.toLowerCase();
  12855. // Don't compare internal attributes or style
  12856. if (name.indexOf('_') !== 0 && name !== 'style')
  12857. attribs[name] = dom.getAttrib(node, name);
  12858. });
  12859. return attribs;
  12860. };
  12861. function compareObjects(obj1, obj2) {
  12862. var value, name;
  12863. for (name in obj1) {
  12864. // Obj1 has item obj2 doesn't have
  12865. if (obj1.hasOwnProperty(name)) {
  12866. value = obj2[name];
  12867. // Obj2 doesn't have obj1 item
  12868. if (value === undefined)
  12869. return FALSE;
  12870. // Obj2 item has a different value
  12871. if (obj1[name] != value)
  12872. return FALSE;
  12873. // Delete similar value
  12874. delete obj2[name];
  12875. }
  12876. }
  12877. // Check if obj 2 has something obj 1 doesn't have
  12878. for (name in obj2) {
  12879. // Obj2 has item obj1 doesn't have
  12880. if (obj2.hasOwnProperty(name))
  12881. return FALSE;
  12882. }
  12883. return TRUE;
  12884. };
  12885. // Attribs are not the same
  12886. if (!compareObjects(getAttribs(node1), getAttribs(node2)))
  12887. return FALSE;
  12888. // Styles are not the same
  12889. if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style'))))
  12890. return FALSE;
  12891. return TRUE;
  12892. };
  12893. // Check if next/prev exists and that they are elements
  12894. if (prev && next) {
  12895. function findElementSibling(node, sibling_name) {
  12896. for (sibling = node; sibling; sibling = sibling[sibling_name]) {
  12897. if (sibling.nodeType == 3 && sibling.nodeValue.length !== 0)
  12898. return node;
  12899. if (sibling.nodeType == 1 && !isBookmarkNode(sibling))
  12900. return sibling;
  12901. }
  12902. return node;
  12903. };
  12904. // If previous sibling is empty then jump over it
  12905. prev = findElementSibling(prev, 'previousSibling');
  12906. next = findElementSibling(next, 'nextSibling');
  12907. // Compare next and previous nodes
  12908. if (compareElements(prev, next)) {
  12909. // Append nodes between
  12910. for (sibling = prev.nextSibling; sibling && sibling != next;) {
  12911. tmpSibling = sibling;
  12912. sibling = sibling.nextSibling;
  12913. prev.appendChild(tmpSibling);
  12914. }
  12915. // Remove next node
  12916. dom.remove(next);
  12917. // Move children into prev node
  12918. each(tinymce.grep(next.childNodes), function(node) {
  12919. prev.appendChild(node);
  12920. });
  12921. return prev;
  12922. }
  12923. }
  12924. return next;
  12925. };
  12926. function isTextBlock(name) {
  12927. return /^(h[1-6]|p|div|pre|address|dl|dt|dd)$/.test(name);
  12928. };
  12929. function getContainer(rng, start) {
  12930. var container, offset, lastIdx, walker;
  12931. container = rng[start ? 'startContainer' : 'endContainer'];
  12932. offset = rng[start ? 'startOffset' : 'endOffset'];
  12933. if (container.nodeType == 1) {
  12934. lastIdx = container.childNodes.length - 1;
  12935. if (!start && offset)
  12936. offset--;
  12937. container = container.childNodes[offset > lastIdx ? lastIdx : offset];
  12938. }
  12939. // If start text node is excluded then walk to the next node
  12940. if (container.nodeType === 3 && start && offset >= container.nodeValue.length) {
  12941. container = new TreeWalker(container, ed.getBody()).next() || container;
  12942. }
  12943. // If end text node is excluded then walk to the previous node
  12944. if (container.nodeType === 3 && !start && offset == 0) {
  12945. container = new TreeWalker(container, ed.getBody()).prev() || container;
  12946. }
  12947. return container;
  12948. };
  12949. function performCaretAction(type, name, vars) {
  12950. var invisibleChar, caretContainerId = '_mce_caret', debug = ed.settings.caret_debug;
  12951. // Setup invisible character use zero width space on Gecko since it doesn't change the heigt of the container
  12952. invisibleChar = tinymce.isGecko ? '\u200B' : INVISIBLE_CHAR;
  12953. // Creates a caret container bogus element
  12954. function createCaretContainer(fill) {
  12955. var caretContainer = dom.create('span', {id: caretContainerId, 'data-mce-bogus': true, style: debug ? 'color:red' : ''});
  12956. if (fill) {
  12957. caretContainer.appendChild(ed.getDoc().createTextNode(invisibleChar));
  12958. }
  12959. return caretContainer;
  12960. };
  12961. function isCaretContainerEmpty(node, nodes) {
  12962. while (node) {
  12963. if ((node.nodeType === 3 && node.nodeValue !== invisibleChar) || node.childNodes.length > 1) {
  12964. return false;
  12965. }
  12966. // Collect nodes
  12967. if (nodes && node.nodeType === 1) {
  12968. nodes.push(node);
  12969. }
  12970. node = node.firstChild;
  12971. }
  12972. return true;
  12973. };
  12974. // Returns any parent caret container element
  12975. function getParentCaretContainer(node) {
  12976. while (node) {
  12977. if (node.id === caretContainerId) {
  12978. return node;
  12979. }
  12980. node = node.parentNode;
  12981. }
  12982. };
  12983. // Finds the first text node in the specified node
  12984. function findFirstTextNode(node) {
  12985. var walker;
  12986. if (node) {
  12987. walker = new TreeWalker(node, node);
  12988. for (node = walker.current(); node; node = walker.next()) {
  12989. if (node.nodeType === 3) {
  12990. return node;
  12991. }
  12992. }
  12993. }
  12994. };
  12995. // Removes the caret container for the specified node or all on the current document
  12996. function removeCaretContainer(node, move_caret) {
  12997. var child, rng;
  12998. if (!node) {
  12999. node = getParentCaretContainer(selection.getStart());
  13000. if (!node) {
  13001. while (node = dom.get(caretContainerId)) {
  13002. removeCaretContainer(node, false);
  13003. }
  13004. }
  13005. } else {
  13006. rng = selection.getRng(true);
  13007. if (isCaretContainerEmpty(node)) {
  13008. if (move_caret !== false) {
  13009. rng.setStartBefore(node);
  13010. rng.setEndBefore(node);
  13011. }
  13012. dom.remove(node);
  13013. } else {
  13014. child = findFirstTextNode(node);
  13015. child = child.deleteData(0, 1);
  13016. dom.remove(node, 1);
  13017. }
  13018. selection.setRng(rng);
  13019. }
  13020. };
  13021. // Applies formatting to the caret postion
  13022. function applyCaretFormat() {
  13023. var rng, caretContainer, textNode, offset, bookmark, container, text;
  13024. rng = selection.getRng(true);
  13025. offset = rng.startOffset;
  13026. container = rng.startContainer;
  13027. text = container.nodeValue;
  13028. caretContainer = getParentCaretContainer(selection.getStart());
  13029. if (caretContainer) {
  13030. textNode = findFirstTextNode(caretContainer);
  13031. }
  13032. // Expand to word is caret is in the middle of a text node and the char before/after is a alpha numeric character
  13033. if (text && offset > 0 && offset < text.length && /\w/.test(text.charAt(offset)) && /\w/.test(text.charAt(offset - 1))) {
  13034. // Get bookmark of caret position
  13035. bookmark = selection.getBookmark();
  13036. // Collapse bookmark range (WebKit)
  13037. rng.collapse(true);
  13038. // Expand the range to the closest word and split it at those points
  13039. rng = expandRng(rng, get(name));
  13040. rng = rangeUtils.split(rng);
  13041. // Apply the format to the range
  13042. apply(name, vars, rng);
  13043. // Move selection back to caret position
  13044. selection.moveToBookmark(bookmark);
  13045. } else {
  13046. if (!caretContainer || textNode.nodeValue !== invisibleChar) {
  13047. caretContainer = createCaretContainer(true);
  13048. textNode = caretContainer.firstChild;
  13049. rng.insertNode(caretContainer);
  13050. offset = 1;
  13051. apply(name, vars, caretContainer);
  13052. } else {
  13053. apply(name, vars, caretContainer);
  13054. }
  13055. // Move selection to text node
  13056. selection.setCursorLocation(textNode, offset);
  13057. }
  13058. };
  13059. function removeCaretFormat() {
  13060. var rng = selection.getRng(true), container, offset, bookmark,
  13061. hasContentAfter, node, formatNode, parents = [], i, caretContainer;
  13062. container = rng.startContainer;
  13063. offset = rng.startOffset;
  13064. node = container;
  13065. if (container.nodeType == 3) {
  13066. if (offset != container.nodeValue.length || container.nodeValue === invisibleChar) {
  13067. hasContentAfter = true;
  13068. }
  13069. node = node.parentNode;
  13070. }
  13071. while (node) {
  13072. if (matchNode(node, name, vars)) {
  13073. formatNode = node;
  13074. break;
  13075. }
  13076. if (node.nextSibling) {
  13077. hasContentAfter = true;
  13078. }
  13079. parents.push(node);
  13080. node = node.parentNode;
  13081. }
  13082. // Node doesn't have the specified format
  13083. if (!formatNode) {
  13084. return;
  13085. }
  13086. // Is there contents after the caret then remove the format on the element
  13087. if (hasContentAfter) {
  13088. // Get bookmark of caret position
  13089. bookmark = selection.getBookmark();
  13090. // Collapse bookmark range (WebKit)
  13091. rng.collapse(true);
  13092. // Expand the range to the closest word and split it at those points
  13093. rng = expandRng(rng, get(name), true);
  13094. rng = rangeUtils.split(rng);
  13095. // Remove the format from the range
  13096. remove(name, vars, rng);
  13097. // Move selection back to caret position
  13098. selection.moveToBookmark(bookmark);
  13099. } else {
  13100. caretContainer = createCaretContainer();
  13101. node = caretContainer;
  13102. for (i = parents.length - 1; i >= 0; i--) {
  13103. node.appendChild(parents[i].cloneNode(false));
  13104. node = node.firstChild;
  13105. }
  13106. // Insert invisible character into inner most format element
  13107. node.appendChild(dom.doc.createTextNode(invisibleChar));
  13108. node = node.firstChild;
  13109. // Insert caret container after the formated node
  13110. dom.insertAfter(caretContainer, formatNode);
  13111. // Move selection to text node
  13112. selection.setCursorLocation(node, 1);
  13113. }
  13114. };
  13115. // Mark current caret container elements as bogus when getting the contents so we don't end up with empty elements
  13116. ed.onBeforeGetContent.addToTop(function() {
  13117. var nodes = [], i;
  13118. if (isCaretContainerEmpty(getParentCaretContainer(selection.getStart()), nodes)) {
  13119. // Mark children
  13120. i = nodes.length;
  13121. while (i--) {
  13122. dom.setAttrib(nodes[i], 'data-mce-bogus', '1');
  13123. }
  13124. }
  13125. });
  13126. // Remove caret container on mouse up and on key up
  13127. tinymce.each('onMouseUp onKeyUp'.split(' '), function(name) {
  13128. ed[name].addToTop(function() {
  13129. removeCaretContainer();
  13130. });
  13131. });
  13132. // Remove caret container on keydown and it's a backspace, enter or left/right arrow keys
  13133. ed.onKeyDown.addToTop(function(ed, e) {
  13134. var keyCode = e.keyCode;
  13135. if (keyCode == 8 || keyCode == 37 || keyCode == 39) {
  13136. removeCaretContainer(getParentCaretContainer(selection.getStart()));
  13137. }
  13138. });
  13139. // Do apply or remove caret format
  13140. if (type == "apply") {
  13141. applyCaretFormat();
  13142. } else {
  13143. removeCaretFormat();
  13144. }
  13145. };
  13146. };
  13147. })(tinymce);
  13148. tinymce.onAddEditor.add(function(tinymce, ed) {
  13149. var filters, fontSizes, dom, settings = ed.settings;
  13150. if (settings.inline_styles) {
  13151. fontSizes = tinymce.explode(settings.font_size_legacy_values);
  13152. function replaceWithSpan(node, styles) {
  13153. tinymce.each(styles, function(value, name) {
  13154. if (value)
  13155. dom.setStyle(node, name, value);
  13156. });
  13157. dom.rename(node, 'span');
  13158. };
  13159. filters = {
  13160. font : function(dom, node) {
  13161. replaceWithSpan(node, {
  13162. backgroundColor : node.style.backgroundColor,
  13163. color : node.color,
  13164. fontFamily : node.face,
  13165. fontSize : fontSizes[parseInt(node.size) - 1]
  13166. });
  13167. },
  13168. u : function(dom, node) {
  13169. replaceWithSpan(node, {
  13170. textDecoration : 'underline'
  13171. });
  13172. },
  13173. strike : function(dom, node) {
  13174. replaceWithSpan(node, {
  13175. textDecoration : 'line-through'
  13176. });
  13177. }
  13178. };
  13179. function convert(editor, params) {
  13180. dom = editor.dom;
  13181. if (settings.convert_fonts_to_spans) {
  13182. tinymce.each(dom.select('font,u,strike', params.node), function(node) {
  13183. filters[node.nodeName.toLowerCase()](ed.dom, node);
  13184. });
  13185. }
  13186. };
  13187. ed.onPreProcess.add(convert);
  13188. ed.onSetContent.add(convert);
  13189. ed.onInit.add(function() {
  13190. ed.selection.onSetContent.add(convert);
  13191. });
  13192. }
  13193. });