editor_all.js 629 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369
  1. (function(){UEDITOR_CONFIG = window.UEDITOR_CONFIG || {};
  2. var baidu = window.baidu || {};
  3. window.baidu = baidu;
  4. window.UE = baidu.editor = {};
  5. UE.plugins = {};
  6. UE.commands = {};
  7. //UE.defaultplugins = {};
  8. //
  9. //UE.commands = function(){
  10. // var commandList = {},tmpList= {};
  11. // return {
  12. //
  13. // register : function(commandsName,pluginName){
  14. // commandsName = commandsName.split(',');
  15. // for(var i= 0,ci;ci=commandsName[i++];){
  16. // commandList[ci] = pluginName;
  17. // }
  18. //
  19. // },
  20. // get : function(commandName){
  21. // return commandList[commandName];
  22. // },
  23. // getList : function(){
  24. // return commandList;
  25. // }
  26. // }
  27. //}();
  28. UE.version = "1.2.2.0";
  29. var dom = UE.dom = {};
  30. ///import editor.js
  31. /**
  32. * @class baidu.editor.browser 判断浏览器
  33. */
  34. var browser = UE.browser = function(){
  35. var agent = navigator.userAgent.toLowerCase(),
  36. opera = window.opera,
  37. browser = {
  38. /**
  39. * 检测浏览器是否为IE
  40. * @name baidu.editor.browser.ie
  41. * @property 检测浏览器是否为IE
  42. * @grammar baidu.editor.browser.ie
  43. * @return {Boolean} 返回是否为ie浏览器
  44. */
  45. ie : !!window.ActiveXObject,
  46. /**
  47. * 检测浏览器是否为Opera
  48. * @name baidu.editor.browser.opera
  49. * @property 检测浏览器是否为Opera
  50. * @grammar baidu.editor.browser.opera
  51. * @return {Boolean} 返回是否为opera浏览器
  52. */
  53. opera : ( !!opera && opera.version ),
  54. /**
  55. * 检测浏览器是否为WebKit内核
  56. * @name baidu.editor.browser.webkit
  57. * @property 检测浏览器是否为WebKit内核
  58. * @grammar baidu.editor.browser.webkit
  59. * @return {Boolean} 返回是否为WebKit内核
  60. */
  61. webkit : ( agent.indexOf( ' applewebkit/' ) > -1 ),
  62. /**
  63. * 检查是否为Macintosh系统
  64. * @name baidu.editor.browser.mac
  65. * @property 检查是否为Macintosh系统
  66. * @grammar baidu.editor.browser.mac
  67. * @return {Boolean} 返回是否为Macintosh系统
  68. */
  69. mac : ( agent.indexOf( 'macintosh' ) > -1 ),
  70. /**
  71. * 检查浏览器是否为quirks模式
  72. * @name baidu.editor.browser.quirks
  73. * @property 检查浏览器是否为quirks模式
  74. * @grammar baidu.editor.browser.quirks
  75. * @return {Boolean} 返回是否为quirks模式
  76. */
  77. quirks : ( document.compatMode == 'BackCompat' )
  78. };
  79. /**
  80. * 检测浏览器是否为Gecko内核,如Firefox
  81. * @name baidu.editor.browser.gecko
  82. * @property 检测浏览器是否为Gecko内核
  83. * @grammar baidu.editor.browser.gecko
  84. * @return {Boolean} 返回是否为Gecko内核
  85. */
  86. browser.gecko = ( navigator.product == 'Gecko' && !browser.webkit && !browser.opera );
  87. var version = 0;
  88. // Internet Explorer 6.0+
  89. if ( browser.ie )
  90. {
  91. version = parseFloat( agent.match( /msie (\d+)/ )[1] );
  92. /**
  93. * 检测浏览器是否为 IE8 浏览器
  94. * @name baidu.editor.browser.IE8
  95. * @property 检测浏览器是否为 IE8 浏览器
  96. * @grammar baidu.editor.browser.IE8
  97. * @return {Boolean} 返回是否为 IE8 浏览器
  98. */
  99. browser.ie8 = !!document.documentMode;
  100. /**
  101. * 检测浏览器是否为 IE8 模式
  102. * @name baidu.editor.browser.ie8Compat
  103. * @property 检测浏览器是否为 IE8 模式
  104. * @grammar baidu.editor.browser.ie8Compat
  105. * @return {Boolean} 返回是否为 IE8 模式
  106. */
  107. browser.ie8Compat = document.documentMode == 8;
  108. /**
  109. * 检测浏览器是否运行在 兼容IE7模式
  110. * @name baidu.editor.browser.ie7Compat
  111. * @property 检测浏览器是否为兼容IE7模式
  112. * @grammar baidu.editor.browser.ie7Compat
  113. * @return {Boolean} 返回是否为兼容IE7模式
  114. */
  115. browser.ie7Compat = ( ( version == 7 && !document.documentMode )
  116. || document.documentMode == 7 );
  117. /**
  118. * 检测浏览器是否IE6模式或怪异模式
  119. * @name baidu.editor.browser.ie6Compat
  120. * @property 检测浏览器是否IE6 模式或怪异模式
  121. * @grammar baidu.editor.browser.ie6Compat
  122. * @return {Boolean} 返回是否为IE6 模式或怪异模式
  123. */
  124. browser.ie6Compat = ( version < 7 || browser.quirks );
  125. }
  126. // Gecko.
  127. if ( browser.gecko )
  128. {
  129. var geckoRelease = agent.match( /rv:([\d\.]+)/ );
  130. if ( geckoRelease )
  131. {
  132. geckoRelease = geckoRelease[1].split( '.' );
  133. version = geckoRelease[0] * 10000 + ( geckoRelease[1] || 0 ) * 100 + ( geckoRelease[2] || 0 ) * 1;
  134. }
  135. }
  136. /**
  137. * 检测浏览器是否为chrome
  138. * @name baidu.editor.browser.chrome
  139. * @property 检测浏览器是否为chrome
  140. * @grammar baidu.editor.browser.chrome
  141. * @return {Boolean} 返回是否为chrome浏览器
  142. */
  143. if (/chrome\/(\d+\.\d)/i.test(agent)) {
  144. browser.chrome = + RegExp['\x241'];
  145. }
  146. /**
  147. * 检测浏览器是否为safari
  148. * @name baidu.editor.browser.safari
  149. * @property 检测浏览器是否为safari
  150. * @grammar baidu.editor.browser.safari
  151. * @return {Boolean} 返回是否为safari浏览器
  152. */
  153. if(/(\d+\.\d)?(?:\.\d)?\s+safari\/?(\d+\.\d+)?/i.test(agent) && !/chrome/i.test(agent)){
  154. browser.safari = + (RegExp['\x241'] || RegExp['\x242']);
  155. }
  156. // Opera 9.50+
  157. if ( browser.opera )
  158. version = parseFloat( opera.version() );
  159. // WebKit 522+ (Safari 3+)
  160. if ( browser.webkit )
  161. version = parseFloat( agent.match( / applewebkit\/(\d+)/ )[1] );
  162. /**
  163. * 浏览器版本
  164. *
  165. * gecko内核浏览器的版本会转换成这样(如 1.9.0.2 -> 10900).
  166. *
  167. * webkit内核浏览器版本号使用其build号 (如 522).
  168. * @name baidu.editor.browser.version
  169. * @grammar baidu.editor.browser.version
  170. * @return {Boolean} 返回浏览器版本号
  171. * @example
  172. * if ( baidu.editor.browser.ie && <b>baidu.editor.browser.version</b> <= 6 )
  173. * alert( "Ouch!" );
  174. */
  175. browser.version = version;
  176. /**
  177. * 是否是兼容模式的浏览器
  178. * @name baidu.editor.browser.isCompatible
  179. * @grammar baidu.editor.browser.isCompatible
  180. * @return {Boolean} 返回是否是兼容模式的浏览器
  181. * @example
  182. * if ( baidu.editor.browser.isCompatible )
  183. * alert( "Your browser is pretty cool!" );
  184. */
  185. browser.isCompatible =
  186. !browser.mobile && (
  187. ( browser.ie && version >= 6 ) ||
  188. ( browser.gecko && version >= 10801 ) ||
  189. ( browser.opera && version >= 9.5 ) ||
  190. ( browser.air && version >= 1 ) ||
  191. ( browser.webkit && version >= 522 ) ||
  192. false );
  193. return browser;
  194. }();
  195. //快捷方式
  196. var ie = browser.ie,
  197. webkit = browser.webkit,
  198. gecko = browser.gecko;
  199. ///import editor.js
  200. ///import core/utils.js
  201. /**
  202. * @class baidu.editor.utils 工具类
  203. */
  204. var utils = UE.utils =
  205. /**@lends baidu.editor.utils.prototype*/
  206. {
  207. /**
  208. * 以obj为原型创建实例
  209. * @public
  210. * @function
  211. * @param {Object} obj
  212. * @return {Object} 返回新的对象
  213. */
  214. makeInstance: function(obj) {
  215. var noop = new Function();
  216. noop.prototype = obj;
  217. obj = new noop;
  218. noop.prototype = null;
  219. return obj;
  220. },
  221. /**
  222. * 将s对象中的属性扩展到t对象上
  223. * @public
  224. * @function
  225. * @param {Object} t
  226. * @param {Object} s
  227. * @param {Boolean} b 是否保留已有属性
  228. * @returns {Object} t 返回扩展了s对象属性的t
  229. */
  230. extend: function(t, s, b) {
  231. if (s) {
  232. for (var k in s) {
  233. if (!b || !t.hasOwnProperty(k)) {
  234. t[k] = s[k];
  235. }
  236. }
  237. }
  238. return t;
  239. },
  240. /**
  241. * 判断是否为数组
  242. * @public
  243. * @function
  244. * @param {Object} array
  245. * @return {Boolean} true:为数组,false:不为数组
  246. */
  247. isArray: function(array) {
  248. return Object.prototype.toString.apply(array) === '[object Array]'
  249. },
  250. /**
  251. * 判断是否为字符串
  252. * @public
  253. * @function
  254. * @param {Object} str
  255. * @return {Boolean} true:为字符串。 false:不为字符串
  256. */
  257. isString: function(str) {
  258. return typeof str == 'string' || str.constructor == String;
  259. },
  260. /**
  261. * subClass继承superClass
  262. * @public
  263. * @function
  264. * @param {Object} subClass 子类
  265. * @param {Object} superClass 超类
  266. * @return {Object} 扩展后的新对象
  267. */
  268. inherits: function(subClass, superClass) {
  269. var oldP = subClass.prototype,
  270. newP = utils.makeInstance(superClass.prototype);
  271. utils.extend(newP, oldP, true);
  272. subClass.prototype = newP;
  273. return (newP.constructor = subClass);
  274. },
  275. /**
  276. * 为对象绑定函数
  277. * @public
  278. * @function
  279. * @param {Function} fn 函数
  280. * @param {Object} this_ 对象
  281. * @return {Function} 绑定后的函数
  282. */
  283. bind: function(fn, this_) {
  284. return function() {
  285. return fn.apply(this_, arguments);
  286. };
  287. },
  288. /**
  289. * 创建延迟执行的函数
  290. * @public
  291. * @function
  292. * @param {Function} fn 要执行的函数
  293. * @param {Number} delay 延迟时间,单位为毫秒
  294. * @param {Boolean} exclusion 是否互斥执行,true则执行下一次defer时会先把前一次的延迟函数删除
  295. * @return {Function} 延迟执行的函数
  296. */
  297. defer: function(fn, delay, exclusion) {
  298. var timerID;
  299. return function() {
  300. if (exclusion) {
  301. clearTimeout(timerID);
  302. }
  303. timerID = setTimeout(fn, delay);
  304. };
  305. },
  306. /**
  307. * 查找元素在数组中的索引, 若找不到返回-1
  308. * @public
  309. * @function
  310. * @param {Array} array 要查找的数组
  311. * @param {*} item 查找的元素
  312. * @param {Number} at 开始查找的位置
  313. * @returns {Number} 返回在数组中的索引
  314. */
  315. indexOf: function(array, item, at) {
  316. for(var i=at||0,l = array.length;i<l;i++){
  317. if(array[i] === item){
  318. return i;
  319. }
  320. }
  321. return -1;
  322. },
  323. findNode : function(nodes,tagNames,fn){
  324. for(var i=0,ci;ci=nodes[i++];){
  325. if(fn? fn(ci) : this.indexOf(tagNames,ci.tagName.toLowerCase())!=-1){
  326. return ci;
  327. }
  328. }
  329. },
  330. /**
  331. * 移除数组中的元素
  332. * @public
  333. * @function
  334. * @param {Array} array 要删除元素的数组
  335. * @param {*} item 要删除的元素
  336. */
  337. removeItem: function(array, item) {
  338. for(var i=0,l = array.length;i<l;i++){
  339. if(array[i] === item){
  340. array.splice(i,1);
  341. i--;
  342. }
  343. }
  344. },
  345. /**
  346. * 删除字符串首尾空格
  347. * @public
  348. * @function
  349. * @param {String} str 字符串
  350. * @return {String} str 删除空格后的字符串
  351. */
  352. trim: function(str) {
  353. return str.replace(/(^[ \t\n\r]+)|([ \t\n\r]+$)/g, '');
  354. },
  355. /**
  356. * 将字符串转换成hashmap
  357. * @public
  358. * @function
  359. * @param {String/Array} list 字符串,以‘,’隔开
  360. * @returns {Object} 转成hashmap的对象
  361. */
  362. listToMap: function(list) {
  363. if(!list)return {};
  364. list = utils.isArray(list) ? list : list.split(',');
  365. for(var i=0,ci,obj={};ci=list[i++];){
  366. obj[ci.toUpperCase()] = obj[ci] = 1;
  367. }
  368. return obj;
  369. },
  370. /**
  371. * 将str中的html符号转义
  372. * @public
  373. * @function
  374. * @param {String} str 需要转义的字符串
  375. * @returns {String} 转义后的字符串
  376. */
  377. unhtml: function(str) {
  378. return str ? str.replace(/[&<">]/g, function(m){
  379. return {
  380. '<': '&lt;',
  381. '&': '&amp;',
  382. '"': '&quot;',
  383. '>': '&gt;'
  384. }[m]
  385. }) : '';
  386. },
  387. html: function(str) {
  388. return str ? str.replace(/&((g|l|quo)t|amp);/g, function(m){
  389. return {
  390. '&lt;':'<',
  391. '&amp;':'&',
  392. '&quot;':'"',
  393. '&gt;': '>'
  394. }[m]
  395. }) : '';
  396. },
  397. /**
  398. * 将css样式转换为驼峰的形式。如font-size -> fontSize
  399. * @public
  400. * @function
  401. * @param {String} cssName 需要转换的样式
  402. * @returns {String} 转换后的样式
  403. */
  404. cssStyleToDomStyle: function() {
  405. var test = document.createElement('div').style,
  406. cache = {
  407. 'float': test.cssFloat != undefined ? 'cssFloat' : test.styleFloat != undefined ? 'styleFloat': 'float'
  408. };
  409. return function(cssName) {
  410. return cache[cssName] || (cache[cssName] = cssName.toLowerCase().replace(/-./g, function(match){return match.charAt(1).toUpperCase();}));
  411. };
  412. }(),
  413. /**
  414. * 加载css文件,执行回调函数
  415. * @public
  416. * @function
  417. * @param {document} doc document对象
  418. * @param {String} path 文件路径
  419. * @param {Function} fun 回调函数
  420. * @param {String} id 元素id
  421. */
  422. loadFile : function(doc,obj,fun){
  423. if (obj.id && doc.getElementById(obj.id)) {
  424. return;
  425. }
  426. var element = doc.createElement(obj.tag);
  427. delete obj.tag;
  428. for(var p in obj){
  429. element.setAttribute(p,obj[p]);
  430. }
  431. element.onload = element.onreadystatechange = function() {
  432. if (!this.readyState || /loaded|complete/.test(this.readyState)) {
  433. fun && fun();
  434. element.onload = element.onreadystatechange = null;
  435. }
  436. };
  437. doc.getElementsByTagName("head")[0].appendChild(element);
  438. },
  439. /**
  440. * 判断对象是否为空
  441. * @param {Object} obj
  442. * @return {Boolean} true 空,false 不空
  443. */
  444. isEmptyObject : function(obj){
  445. for ( var p in obj ) {
  446. return false;
  447. }
  448. return true;
  449. },
  450. isFunction : function (source) {
  451. // chrome下,'function' == typeof /a/ 为true.
  452. return '[object Function]' == Object.prototype.toString.call(source);
  453. },
  454. fixColor : function (name, value) {
  455. if (/color/i.test(name) && /rgba?/.test(value)) {
  456. var array = value.split(",");
  457. if (array.length > 3)
  458. return "";
  459. value = "#";
  460. for (var i = 0, color; color = array[i++];) {
  461. color = parseInt(color.replace(/[^\d]/gi, ''), 10).toString(16);
  462. value += color.length == 1 ? "0" + color : color;
  463. }
  464. value = value.toUpperCase();
  465. }
  466. return value;
  467. },
  468. /**
  469. * 只针对border,padding,margin做了处理,因为性能问题
  470. * @public
  471. * @function
  472. * @param {String} val style字符串
  473. */
  474. optCss : function(val){
  475. var padding,margin,border;
  476. val = val.replace(/(padding|margin|border)\-([^:]+):([^;]+);?/gi,function(str,key,name,val){
  477. if(val.split(' ').length == 1){
  478. switch (key){
  479. case 'padding':
  480. !padding && (padding = {});
  481. padding[name] = val;
  482. return '';
  483. case 'margin':
  484. !margin && (margin = {});
  485. margin[name] = val;
  486. return '';
  487. case 'border':
  488. return val == 'initial' ? '' : str;
  489. }
  490. }
  491. return str
  492. });
  493. function opt(obj,name){
  494. if(!obj)
  495. return ''
  496. var t = obj.top ,b = obj.bottom,l = obj.left,r = obj.right,val = '';
  497. if(!t || !l || !b || !r){
  498. for(var p in obj){
  499. val +=';'+name+'-' + p + ':' + obj[p]+';';
  500. }
  501. }else{
  502. val += ';'+name+':' +
  503. (t == b && b == l && l == r ? t :
  504. t == b && l == r ? (t + ' ' + l) :
  505. l == r ? (t + ' ' + l + ' ' + b) : (t + ' ' + r + ' ' + b + ' ' + l))+';'
  506. }
  507. return val;
  508. }
  509. val += opt(padding,'padding') + opt(margin,'margin');
  510. return val.replace(/^[ \n\r\t;]*|[ \n\r\t]*$/,'').replace(/;([ \n\r\t]+)|\1;/g,';')
  511. .replace(/(&((l|g)t|quot|#39))?;{2,}/g,function(a,b){
  512. return b ? b + ";;" : ';'
  513. })
  514. },
  515. /**
  516. * DOMContentLoaded 事件注册
  517. * @public
  518. * @function
  519. * @param {Function} 触发的事件
  520. */
  521. domReady : function (){
  522. var isReady = false,
  523. fnArr = [];
  524. function doReady(){
  525. //确保onready只执行一次
  526. isReady = true;
  527. for(var ci;ci=fnArr.pop();){
  528. ci();
  529. }
  530. }
  531. return function(onready){
  532. if ( document.readyState === "complete" ) {
  533. return setTimeout( onready, 1 );
  534. }
  535. onready && fnArr.push(onready);
  536. isReady && doReady();
  537. if( browser.ie ){
  538. (function(){
  539. if ( isReady ) return;
  540. try {
  541. document.documentElement.doScroll("left");
  542. } catch( error ) {
  543. setTimeout( arguments.callee, 0 );
  544. return;
  545. }
  546. doReady();
  547. })();
  548. window.attachEvent('onload',doReady);
  549. }else{
  550. document.addEventListener( "DOMContentLoaded", function(){
  551. document.removeEventListener( "DOMContentLoaded", arguments.callee, false );
  552. doReady();
  553. }, false );
  554. window.addEventListener('load',doReady,false);
  555. }
  556. }
  557. }()
  558. };
  559. utils.domReady();
  560. ///import editor.js
  561. ///import core/utils.js
  562. /**
  563. * 事件基础类
  564. * @public
  565. * @class
  566. * @name baidu.editor.EventBase
  567. */
  568. var EventBase = UE.EventBase = function(){};
  569. EventBase.prototype = /**@lends baidu.editor.EventBase.prototype*/{
  570. /**
  571. * 注册事件监听器
  572. * @public
  573. * @function
  574. * @param {String} type 事件名
  575. * @param {Function} listener 监听器数组
  576. */
  577. addListener : function ( type, listener ) {
  578. getListener( this, type, true ).push( listener );
  579. },
  580. /**
  581. * 移除事件监听器
  582. * @public
  583. * @function
  584. * @param {String} type 事件名
  585. * @param {Function} listener 监听器数组
  586. */
  587. removeListener : function ( type, listener ) {
  588. var listeners = getListener( this, type );
  589. listeners && utils.removeItem( listeners, listener );
  590. },
  591. /**
  592. * 触发事件
  593. * @public
  594. * @function
  595. * @param {String} type 事件名
  596. *
  597. */
  598. fireEvent : function ( type ) {
  599. var listeners = getListener( this, type ),
  600. r, t, k;
  601. if ( listeners ) {
  602. k = listeners.length;
  603. while ( k -- ) {
  604. t = listeners[k].apply( this, arguments );
  605. if ( t !== undefined ) {
  606. r = t;
  607. }
  608. }
  609. }
  610. if ( t = this['on' + type.toLowerCase()] ) {
  611. r = t.apply( this, arguments );
  612. }
  613. return r;
  614. }
  615. };
  616. /**
  617. * 获得对象所拥有监听类型的所有监听器
  618. * @public
  619. * @function
  620. * @param {Object} obj 查询监听器的对象
  621. * @param {String} type 事件类型
  622. * @param {Boolean} force 为true且当前所有type类型的侦听器不存在时,创建一个空监听器数组
  623. * @returns {Array} 监听器数组
  624. */
  625. function getListener( obj, type, force ) {
  626. var allListeners;
  627. type = type.toLowerCase();
  628. return ( ( allListeners = ( obj.__allListeners || force && ( obj.__allListeners = {} ) ) )
  629. && ( allListeners[type] || force && ( allListeners[type] = [] ) ) );
  630. }
  631. ///import editor.js
  632. ///import core/dom/dom.js
  633. /**
  634. * dtd html语义化的体现类
  635. * @constructor
  636. * @namespace dtd
  637. */
  638. var dtd = dom.dtd = (function() {
  639. function _( s ) {
  640. for (var k in s) {
  641. s[k.toUpperCase()] = s[k];
  642. }
  643. return s;
  644. }
  645. function X( t ) {
  646. var a = arguments;
  647. for ( var i=1; i<a.length; i++ ) {
  648. var x = a[i];
  649. for ( var k in x ) {
  650. if (!t.hasOwnProperty(k)) {
  651. t[k] = x[k];
  652. }
  653. }
  654. }
  655. return t;
  656. }
  657. var A = _({isindex:1,fieldset:1}),
  658. B = _({input:1,button:1,select:1,textarea:1,label:1}),
  659. C = X( _({a:1}), B ),
  660. D = X( {iframe:1}, C ),
  661. E = _({hr:1,ul:1,menu:1,div:1,blockquote:1,noscript:1,table:1,center:1,address:1,dir:1,pre:1,h5:1,dl:1,h4:1,noframes:1,h6:1,ol:1,h1:1,h3:1,h2:1}),
  662. F = _({ins:1,del:1,script:1,style:1}),
  663. G = X( _({b:1,acronym:1,bdo:1,'var':1,'#':1,abbr:1,code:1,br:1,i:1,cite:1,kbd:1,u:1,strike:1,s:1,tt:1,strong:1,q:1,samp:1,em:1,dfn:1,span:1}), F ),
  664. H = X( _({sub:1,img:1,embed:1,object:1,sup:1,basefont:1,map:1,applet:1,font:1,big:1,small:1}), G ),
  665. I = X( _({p:1}), H ),
  666. J = X( _({iframe:1}), H, B ),
  667. K = _({img:1,embed:1,noscript:1,br:1,kbd:1,center:1,button:1,basefont:1,h5:1,h4:1,samp:1,h6:1,ol:1,h1:1,h3:1,h2:1,form:1,font:1,'#':1,select:1,menu:1,ins:1,abbr:1,label:1,code:1,table:1,script:1,cite:1,input:1,iframe:1,strong:1,textarea:1,noframes:1,big:1,small:1,span:1,hr:1,sub:1,bdo:1,'var':1,div:1,object:1,sup:1,strike:1,dir:1,map:1,dl:1,applet:1,del:1,isindex:1,fieldset:1,ul:1,b:1,acronym:1,a:1,blockquote:1,i:1,u:1,s:1,tt:1,address:1,q:1,pre:1,p:1,em:1,dfn:1}),
  668. L = X( _({a:0}), J ),//a不能被切开,所以把他
  669. M = _({tr:1}),
  670. N = _({'#':1}),
  671. O = X( _({param:1}), K ),
  672. P = X( _({form:1}), A, D, E, I ),
  673. Q = _({li:1}),
  674. R = _({style:1,script:1}),
  675. S = _({base:1,link:1,meta:1,title:1}),
  676. T = X( S, R ),
  677. U = _({head:1,body:1}),
  678. V = _({html:1});
  679. var block = _({address:1,blockquote:1,center:1,dir:1,div:1,dl:1,fieldset:1,form:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,hr:1,isindex:1,menu:1,noframes:1,ol:1,p:1,pre:1,table:1,ul:1}),
  680. //针对优酷的embed他添加了结束标识,导致粘贴进来会变成两个,暂时去掉 ,embed:1
  681. empty = _({area:1,base:1,br:1,col:1,hr:1,img:1,input:1,link:1,meta:1,param:1,embed:1});
  682. return _({
  683. // $ 表示自定的属性
  684. // body外的元素列表.
  685. $nonBodyContent: X( V, U, S ),
  686. //块结构元素列表
  687. $block : block,
  688. //内联元素列表
  689. $inline : L,
  690. $body : X( _({script:1,style:1}), block ),
  691. $cdata : _({script:1,style:1}),
  692. //自闭和元素
  693. $empty : empty,
  694. //不是自闭合,但不能让range选中里边
  695. $nonChild : _({iframe:1}),
  696. //列表元素列表
  697. $listItem : _({dd:1,dt:1,li:1}),
  698. //列表根元素列表
  699. $list: _({ul:1,ol:1,dl:1}),
  700. //不能认为是空的元素
  701. $isNotEmpty : _({table:1,ul:1,ol:1,dl:1,iframe:1,area:1,base:1,col:1,hr:1,img:1,embed:1,input:1,link:1,meta:1,param:1}),
  702. //如果没有子节点就可以删除的元素列表,像span,a
  703. $removeEmpty : _({a:1,abbr:1,acronym:1,address:1,b:1,bdo:1,big:1,cite:1,code:1,del:1,dfn:1,em:1,font:1,i:1,ins:1,label:1,kbd:1,q:1,s:1,samp:1,small:1,span:1,strike:1,strong:1,sub:1,sup:1,tt:1,u:1,'var':1}),
  704. $removeEmptyBlock : _({'p':1,'div':1}),
  705. //在table元素里的元素列表
  706. $tableContent : _({caption:1,col:1,colgroup:1,tbody:1,td:1,tfoot:1,th:1,thead:1,tr:1,table:1}),
  707. //不转换的标签
  708. $notTransContent : _({pre:1,script:1,style:1,textarea:1}),
  709. html: U,
  710. head: T,
  711. style: N,
  712. script: N,
  713. body: P,
  714. base: {},
  715. link: {},
  716. meta: {},
  717. title: N,
  718. col : {},
  719. tr : _({td:1,th:1}),
  720. img : {},
  721. embed: {},
  722. colgroup : _({thead:1,col:1,tbody:1,tr:1,tfoot:1}),
  723. noscript : P,
  724. td : P,
  725. br : {},
  726. th : P,
  727. center : P,
  728. kbd : L,
  729. button : X( I, E ),
  730. basefont : {},
  731. h5 : L,
  732. h4 : L,
  733. samp : L,
  734. h6 : L,
  735. ol : Q,
  736. h1 : L,
  737. h3 : L,
  738. option : N,
  739. h2 : L,
  740. form : X( A, D, E, I ),
  741. select : _({optgroup:1,option:1}),
  742. font : L,
  743. ins : L,
  744. menu : Q,
  745. abbr : L,
  746. label : L,
  747. table : _({thead:1,col:1,tbody:1,tr:1,colgroup:1,caption:1,tfoot:1}),
  748. code : L,
  749. tfoot : M,
  750. cite : L,
  751. li : P,
  752. input : {},
  753. iframe : P,
  754. strong : L,
  755. textarea : N,
  756. noframes : P,
  757. big : L,
  758. small : L,
  759. span :_({'#':1,br:1}),
  760. hr : L,
  761. dt : L,
  762. sub : L,
  763. optgroup : _({option:1}),
  764. param : {},
  765. bdo : L,
  766. 'var' : L,
  767. div : P,
  768. object : O,
  769. sup : L,
  770. dd : P,
  771. strike : L,
  772. area : {},
  773. dir : Q,
  774. map : X( _({area:1,form:1,p:1}), A, F, E ),
  775. applet : O,
  776. dl : _({dt:1,dd:1}),
  777. del : L,
  778. isindex : {},
  779. fieldset : X( _({legend:1}), K ),
  780. thead : M,
  781. ul : Q,
  782. acronym : L,
  783. b : L,
  784. a : X( _({a:1}), J ),
  785. blockquote :X(_({td:1,tr:1,tbody:1,li:1}),P),
  786. caption : L,
  787. i : L,
  788. u : L,
  789. tbody : M,
  790. s : L,
  791. address : X( D, I ),
  792. tt : L,
  793. legend : L,
  794. q : L,
  795. pre : X( G, C ),
  796. p : X(_({'a':1}),L),
  797. em :L,
  798. dfn : L
  799. });
  800. })();
  801. ///import editor.js
  802. ///import core/utils.js
  803. ///import core/browser.js
  804. ///import core/dom/dom.js
  805. ///import core/dom/dtd.js
  806. /**
  807. * @class baidu.editor.dom.domUtils dom工具类
  808. */
  809. //for getNextDomNode getPreviousDomNode
  810. function getDomNode(node, start, ltr, startFromChild, fn, guard) {
  811. var tmpNode = startFromChild && node[start],
  812. parent;
  813. !tmpNode && (tmpNode = node[ltr]);
  814. while (!tmpNode && (parent = (parent || node).parentNode)) {
  815. if (parent.tagName == 'BODY' || guard && !guard(parent))
  816. return null;
  817. tmpNode = parent[ltr];
  818. }
  819. if (tmpNode && fn && !fn(tmpNode)) {
  820. return getDomNode(tmpNode, start, ltr, false, fn)
  821. }
  822. return tmpNode;
  823. }
  824. var attrFix = ie && browser.version < 9 ? {
  825. tabindex: "tabIndex",
  826. readonly: "readOnly",
  827. "for": "htmlFor",
  828. "class": "className",
  829. maxlength: "maxLength",
  830. cellspacing: "cellSpacing",
  831. cellpadding: "cellPadding",
  832. rowspan: "rowSpan",
  833. colspan: "colSpan",
  834. usemap: "useMap",
  835. frameborder: "frameBorder"
  836. } : {
  837. tabindex: "tabIndex",
  838. readonly: "readOnly"
  839. },
  840. styleBlock = utils.listToMap([
  841. '-webkit-box','-moz-box','block' ,
  842. 'list-item' ,'table' ,'table-row-group' ,
  843. 'table-header-group','table-footer-group' ,
  844. 'table-row' ,'table-column-group' ,'table-column' ,
  845. 'table-cell' ,'table-caption'
  846. ]);
  847. var domUtils = dom.domUtils = {
  848. //节点常量
  849. NODE_ELEMENT : 1,
  850. NODE_DOCUMENT : 9,
  851. NODE_TEXT : 3,
  852. NODE_COMMENT : 8,
  853. NODE_DOCUMENT_FRAGMENT : 11,
  854. //位置关系
  855. POSITION_IDENTICAL : 0,
  856. POSITION_DISCONNECTED : 1,
  857. POSITION_FOLLOWING : 2,
  858. POSITION_PRECEDING : 4,
  859. POSITION_IS_CONTAINED : 8,
  860. POSITION_CONTAINS : 16,
  861. //ie6使用其他的会有一段空白出现
  862. fillChar : ie && browser.version == '6' ? '\ufeff' : '\u200B',
  863. //-------------------------Node部分--------------------------------
  864. keys : {
  865. /*Backspace*/ 8:1, /*Delete*/ 46:1,
  866. /*Shift*/ 16:1, /*Ctrl*/ 17:1, /*Alt*/ 18:1,
  867. 37:1, 38:1, 39:1, 40:1,
  868. 13:1 /*enter*/
  869. },
  870. /**
  871. * 获取两个节点的位置关系
  872. * @function
  873. * @param {Node} nodeA 节点A
  874. * @param {Node} nodeB 节点B
  875. * @returns {Number} 返回位置关系
  876. */
  877. getPosition : function (nodeA, nodeB) {
  878. // 如果两个节点是同一个节点
  879. if (nodeA === nodeB) {
  880. // domUtils.POSITION_IDENTICAL
  881. return 0;
  882. }
  883. var node,
  884. parentsA = [nodeA],
  885. parentsB = [nodeB];
  886. node = nodeA;
  887. while (node = node.parentNode) {
  888. // 如果nodeB是nodeA的祖先节点
  889. if (node === nodeB) {
  890. // domUtils.POSITION_IS_CONTAINED + domUtils.POSITION_FOLLOWING
  891. return 10;
  892. }
  893. parentsA.push(node);
  894. }
  895. node = nodeB;
  896. while (node = node.parentNode) {
  897. // 如果nodeA是nodeB的祖先节点
  898. if (node === nodeA) {
  899. // domUtils.POSITION_CONTAINS + domUtils.POSITION_PRECEDING
  900. return 20;
  901. }
  902. parentsB.push(node);
  903. }
  904. parentsA.reverse();
  905. parentsB.reverse();
  906. if (parentsA[0] !== parentsB[0])
  907. // domUtils.POSITION_DISCONNECTED
  908. return 1;
  909. var i = -1;
  910. while (i++,parentsA[i] === parentsB[i]) ;
  911. nodeA = parentsA[i];
  912. nodeB = parentsB[i];
  913. while (nodeA = nodeA.nextSibling) {
  914. if (nodeA === nodeB) {
  915. // domUtils.POSITION_PRECEDING
  916. return 4
  917. }
  918. }
  919. // domUtils.POSITION_FOLLOWING
  920. return 2;
  921. },
  922. /**
  923. * 返回节点索引,zero-based
  924. * @function
  925. * @param {Node} node 节点
  926. * @returns {Number} 节点的索引
  927. */
  928. getNodeIndex : function (node) {
  929. var child = node.parentNode.firstChild,i = 0;
  930. while(node!==child){
  931. i++;
  932. child = child.nextSibling;
  933. }
  934. return i;
  935. },
  936. /**
  937. * 判断节点是否在树上
  938. * @param node
  939. */
  940. inDoc: function (node, doc){
  941. while (node = node.parentNode) {
  942. if (node === doc) {
  943. return true;
  944. }
  945. }
  946. return false;
  947. },
  948. /**
  949. * 查找祖先节点
  950. * @function
  951. * @param {Node} node 节点
  952. * @param {Function} tester 以函数为规律
  953. * @param {Boolean} includeSelf 包含自己
  954. * @returns {Node} 返回祖先节点
  955. */
  956. findParent : function (node, tester, includeSelf) {
  957. if (!domUtils.isBody(node)) {
  958. node = includeSelf ? node : node.parentNode;
  959. while (node) {
  960. if (!tester || tester(node) || this.isBody(node)) {
  961. return tester && !tester(node) && this.isBody(node) ? null : node;
  962. }
  963. node = node.parentNode;
  964. }
  965. }
  966. return null;
  967. },
  968. /**
  969. * 查找祖先节点
  970. * @function
  971. * @param {Node} node 节点
  972. * @param {String} tagName 标签名称
  973. * @param {Boolean} includeSelf 包含自己
  974. * @returns {Node} 返回祖先节点
  975. */
  976. findParentByTagName : function(node, tagName, includeSelf,excludeFn) {
  977. if (node && node.nodeType && !this.isBody(node) && (node.nodeType == 1 || node.nodeType)) {
  978. tagName = utils.listToMap(utils.isArray(tagName) ? tagName : [tagName]);
  979. node = node.nodeType == 3 || !includeSelf ? node.parentNode : node;
  980. while (node && node.tagName && node.nodeType != 9) {
  981. if(excludeFn && excludeFn(node))
  982. break;
  983. if (tagName[node.tagName])
  984. return node;
  985. node = node.parentNode;
  986. }
  987. }
  988. return null;
  989. },
  990. /**
  991. * 查找祖先节点集合
  992. * @param {Node} node 节点
  993. * @param {Function} tester 函数
  994. * @param {Boolean} includeSelf 是否从自身开始找
  995. * @param {Boolean} closerFirst
  996. * @returns {Array} 祖先节点集合
  997. */
  998. findParents: function (node, includeSelf, tester, closerFirst) {
  999. var parents = includeSelf && ( tester && tester(node) || !tester ) ? [node] : [];
  1000. while (node = domUtils.findParent(node, tester)) {
  1001. parents.push(node);
  1002. }
  1003. return closerFirst ? parents : parents.reverse();
  1004. },
  1005. /**
  1006. * 往后插入节点
  1007. * @function
  1008. * @param {Node} node 基准节点
  1009. * @param {Node} nodeToInsert 要插入的节点
  1010. * @return {Node} 返回node
  1011. */
  1012. insertAfter : function (node, nodeToInsert) {
  1013. return node.parentNode.insertBefore(nodeToInsert, node.nextSibling);
  1014. },
  1015. /**
  1016. * 删除该节点
  1017. * @function
  1018. * @param {Node} node 要删除的节点
  1019. * @param {Boolean} keepChildren 是否保留子节点不删除
  1020. * @return {Node} 返回要删除的节点
  1021. */
  1022. remove : function (node, keepChildren) {
  1023. var parent = node.parentNode,
  1024. child;
  1025. if (parent) {
  1026. if (keepChildren && node.hasChildNodes()) {
  1027. while (child = node.firstChild) {
  1028. parent.insertBefore(child, node);
  1029. }
  1030. }
  1031. parent.removeChild(node);
  1032. }
  1033. return node;
  1034. },
  1035. /**
  1036. * 取得node节点在dom树上的下一个节点
  1037. * @function
  1038. * @param {Node} node 节点
  1039. * @param {Boolean} startFromChild 为true从子节点开始找
  1040. * @param {Function} fn fn为真的节点
  1041. * @return {Node} 返回下一个节点
  1042. */
  1043. getNextDomNode : function(node, startFromChild, filter, guard) {
  1044. return getDomNode(node, 'firstChild', 'nextSibling', startFromChild, filter, guard);
  1045. },
  1046. /**
  1047. * 是bookmark节点
  1048. * @param {Node} node 判断是否为书签节点
  1049. * @return {Boolean} 返回是否为书签节点
  1050. */
  1051. isBookmarkNode : function(node) {
  1052. return node.nodeType == 1 && node.id && /^_baidu_bookmark_/i.test(node.id);
  1053. },
  1054. /**
  1055. * 获取节点所在window对象
  1056. * @param {Node} node 节点
  1057. * @return {window} 返回window对象
  1058. */
  1059. getWindow : function (node) {
  1060. var doc = node.ownerDocument || node;
  1061. return doc.defaultView || doc.parentWindow;
  1062. },
  1063. /**
  1064. * 得到公共的祖先节点
  1065. * @param {Node} nodeA 节点A
  1066. * @param {Node} nodeB 节点B
  1067. * @return {Node} nodeA和nodeB的公共节点
  1068. */
  1069. getCommonAncestor : function(nodeA, nodeB) {
  1070. if (nodeA === nodeB)
  1071. return nodeA;
  1072. var parentsA = [nodeA] ,parentsB = [nodeB], parent = nodeA,
  1073. i = -1;
  1074. while (parent = parent.parentNode) {
  1075. if (parent === nodeB)
  1076. return parent;
  1077. parentsA.push(parent)
  1078. }
  1079. parent = nodeB;
  1080. while (parent = parent.parentNode) {
  1081. if (parent === nodeA)
  1082. return parent;
  1083. parentsB.push(parent)
  1084. }
  1085. parentsA.reverse();
  1086. parentsB.reverse();
  1087. while (i++,parentsA[i] === parentsB[i]);
  1088. return i == 0 ? null : parentsA[i - 1];
  1089. },
  1090. /**
  1091. * 清除该节点左右空的inline节点
  1092. * @function
  1093. * @param {Node} node
  1094. * @param {Boolean} ingoreNext 默认为false清除右边为空的inline节点。true为不清除右边为空的inline节点
  1095. * @param {Boolean} ingorePre 默认为false清除左边为空的inline节点。true为不清除左边为空的inline节点
  1096. * @exmaple <b></b><i></i>xxxx<b>bb</b> --> xxxx<b>bb</b>
  1097. */
  1098. clearEmptySibling : function(node, ingoreNext, ingorePre) {
  1099. function clear(next, dir) {
  1100. var tmpNode;
  1101. while(next && !domUtils.isBookmarkNode(next) && (domUtils.isEmptyInlineElement(next)
  1102. //这里不能把空格算进来会吧空格干掉,出现文字间的空格丢掉了
  1103. || !new RegExp('[^\t\n\r' + domUtils.fillChar + ']').test(next.nodeValue) )){
  1104. tmpNode = next[dir];
  1105. domUtils.remove(next);
  1106. next = tmpNode;
  1107. }
  1108. }
  1109. !ingoreNext && clear(node.nextSibling, 'nextSibling');
  1110. !ingorePre && clear(node.previousSibling, 'previousSibling');
  1111. },
  1112. //---------------------------Text----------------------------------
  1113. /**
  1114. * 将一个文本节点拆分成两个文本节点
  1115. * @param {TextNode} node 文本节点
  1116. * @param {Integer} offset 拆分的位置
  1117. * @return {TextNode} 拆分后的后一个文本节
  1118. */
  1119. split: function (node, offset) {
  1120. var doc = node.ownerDocument;
  1121. if (browser.ie && offset == node.nodeValue.length) {
  1122. var next = doc.createTextNode('');
  1123. return domUtils.insertAfter(node, next);
  1124. }
  1125. var retval = node.splitText(offset);
  1126. //ie8下splitText不会跟新childNodes,我们手动触发他的更新
  1127. if (browser.ie8) {
  1128. var tmpNode = doc.createTextNode('');
  1129. domUtils.insertAfter(retval, tmpNode);
  1130. domUtils.remove(tmpNode);
  1131. }
  1132. return retval;
  1133. },
  1134. /**
  1135. * 判断是否为空白节点
  1136. * @param {TextNode} node 节点
  1137. * @return {Boolean} 返回是否为文本节点
  1138. */
  1139. isWhitespace : function(node) {
  1140. return !new RegExp('[^ \t\n\r' + domUtils.fillChar + ']').test(node.nodeValue);
  1141. },
  1142. //------------------------------Element-------------------------------------------
  1143. /**
  1144. * 获取元素相对于viewport的像素坐标
  1145. * @param {Element} element 元素
  1146. * @returns {Object} 返回坐标对象{x:left,y:top}
  1147. */
  1148. getXY : function (element) {
  1149. var x = 0,y = 0;
  1150. while (element.offsetParent) {
  1151. y += element.offsetTop;
  1152. x += element.offsetLeft;
  1153. element = element.offsetParent;
  1154. }
  1155. return {
  1156. 'x': x,
  1157. 'y': y
  1158. };
  1159. },
  1160. /**
  1161. * 绑原生DOM事件
  1162. * @param {Element|Window|Document} target 元素
  1163. * @param {Array|String} type 事件类型
  1164. * @param {Function} handler 执行函数
  1165. */
  1166. on : function (obj, type, handler) {
  1167. var types = type instanceof Array ? type : [type],
  1168. k = types.length;
  1169. if (k) while (k --) {
  1170. type = types[k];
  1171. if (obj.addEventListener) {
  1172. obj.addEventListener(type, handler, false);
  1173. } else {
  1174. if(!handler._d)
  1175. handler._d ={};
  1176. var key = type+handler.toString();
  1177. if(!handler._d[key]){
  1178. handler._d[key] = function(evt) {
  1179. return handler.call(evt.srcElement, evt || window.event);
  1180. };
  1181. obj.attachEvent('on' + type,handler._d[key]);
  1182. }
  1183. }
  1184. }
  1185. obj = null;
  1186. },
  1187. /**
  1188. * 解除原生DOM事件绑定
  1189. * @param {Element|Window|Document} obj 元素
  1190. * @param {Array|String} type 事件类型
  1191. * @param {Function} handler 执行函数
  1192. */
  1193. un : function (obj, type, handler) {
  1194. var types = type instanceof Array ? type : [type],
  1195. k = types.length;
  1196. if (k) while (k --) {
  1197. type = types[k];
  1198. if (obj.removeEventListener) {
  1199. obj.removeEventListener(type, handler, false);
  1200. } else {
  1201. var key = type+handler.toString();
  1202. obj.detachEvent('on' + type, handler._d ? handler._d[key] : handler);
  1203. if(handler._d && handler._d[key]){
  1204. delete handler._d[key];
  1205. }
  1206. }
  1207. }
  1208. },
  1209. /**
  1210. * 比较两个节点是否tagName相同且有相同的属性和属性值
  1211. * @param {Element} nodeA 节点A
  1212. * @param {Element} nodeB 节点B
  1213. * @return {Boolean} 返回两个节点的标签,属性和属性值是否相同
  1214. * @example
  1215. * &lt;span style="font-size:12px"&gt;ssss&lt;/span&gt;和&lt;span style="font-size:12px"&gt;bbbbb&lt;/span&gt; 相等
  1216. * &lt;span style="font-size:13px"&gt;ssss&lt;/span&gt;和&lt;span style="font-size:12px"&gt;bbbbb&lt;/span&gt; 不相等
  1217. */
  1218. isSameElement : function(nodeA, nodeB) {
  1219. if (nodeA.tagName != nodeB.tagName)
  1220. return 0;
  1221. var thisAttribs = nodeA.attributes,
  1222. otherAttribs = nodeB.attributes;
  1223. if (!ie && thisAttribs.length != otherAttribs.length)
  1224. return 0;
  1225. var attrA,attrB,al = 0,bl=0;
  1226. for(var i= 0;attrA=thisAttribs[i++];){
  1227. if(attrA.nodeName == 'style' ){
  1228. if(attrA.specified)al++;
  1229. if(domUtils.isSameStyle(nodeA,nodeB)){
  1230. continue
  1231. }else{
  1232. return 0;
  1233. }
  1234. }
  1235. if(ie){
  1236. if(attrA.specified){
  1237. al++;
  1238. attrB = otherAttribs.getNamedItem(attrA.nodeName);
  1239. }else{
  1240. continue;
  1241. }
  1242. }else{
  1243. attrB = nodeB.attributes[attrA.nodeName];
  1244. }
  1245. if(!attrB.specified)return 0;
  1246. if(attrA.nodeValue != attrB.nodeValue)
  1247. return 0;
  1248. }
  1249. // 有可能attrB的属性包含了attrA的属性之外还有自己的属性
  1250. if(ie){
  1251. for(i=0;attrB = otherAttribs[i++];){
  1252. if(attrB.specified){
  1253. bl++;
  1254. }
  1255. }
  1256. if(al!=bl)
  1257. return 0;
  1258. }
  1259. return 1;
  1260. },
  1261. /**
  1262. * 判断两个元素的style属性是不是一致
  1263. * @param {Element} elementA 元素A
  1264. * @param {Element} elementB 元素B
  1265. * @return {boolean} 返回判断结果,true为一致
  1266. */
  1267. isSameStyle : function (elementA, elementB) {
  1268. var styleA = elementA.style.cssText.replace(/( ?; ?)/g,';').replace(/( ?: ?)/g,':'),
  1269. styleB = elementB.style.cssText.replace(/( ?; ?)/g,';').replace(/( ?: ?)/g,':');
  1270. if(!styleA || !styleB){
  1271. return styleA == styleB ? 1: 0;
  1272. }
  1273. styleA = styleA.split(';');
  1274. styleB = styleB.split(';');
  1275. if(styleA.length != styleB.length)
  1276. return 0;
  1277. for(var i = 0,ci;ci=styleA[i++];){
  1278. if(utils.indexOf(styleB,ci) == -1)
  1279. return 0
  1280. }
  1281. return 1;
  1282. },
  1283. /**
  1284. * 检查是否为块元素
  1285. * @function
  1286. * @param {Element} node 元素
  1287. * @param {String} customNodeNames 自定义的块元素的tagName
  1288. * @return {Boolean} 是否为块元素
  1289. */
  1290. isBlockElm : function (node) {
  1291. return node.nodeType == 1 && (dtd.$block[node.tagName]||styleBlock[domUtils.getComputedStyle(node,'display')])&& !dtd.$nonChild[node.tagName];
  1292. },
  1293. /**
  1294. * 判断是否body
  1295. * @param {Node} 节点
  1296. * @return {Boolean} 是否是body节点
  1297. */
  1298. isBody : function(node) {
  1299. return node && node.nodeType == 1 && node.tagName.toLowerCase() == 'body';
  1300. },
  1301. /**
  1302. * 以node节点为中心,将该节点的父节点拆分成2块
  1303. * @param {Element} node 节点
  1304. * @param {Element} parent 要被拆分的父节点
  1305. * @example <div>xxxx<b>xxx</b>xxx</div> ==> <div>xxx</div><b>xx</b><div>xxx</div>
  1306. */
  1307. breakParent : function(node, parent) {
  1308. var tmpNode, parentClone = node, clone = node, leftNodes, rightNodes;
  1309. do {
  1310. parentClone = parentClone.parentNode;
  1311. if (leftNodes) {
  1312. tmpNode = parentClone.cloneNode(false);
  1313. tmpNode.appendChild(leftNodes);
  1314. leftNodes = tmpNode;
  1315. tmpNode = parentClone.cloneNode(false);
  1316. tmpNode.appendChild(rightNodes);
  1317. rightNodes = tmpNode;
  1318. } else {
  1319. leftNodes = parentClone.cloneNode(false);
  1320. rightNodes = leftNodes.cloneNode(false);
  1321. }
  1322. while (tmpNode = clone.previousSibling) {
  1323. leftNodes.insertBefore(tmpNode, leftNodes.firstChild);
  1324. }
  1325. while (tmpNode = clone.nextSibling) {
  1326. rightNodes.appendChild(tmpNode);
  1327. }
  1328. clone = parentClone;
  1329. } while (parent !== parentClone);
  1330. tmpNode = parent.parentNode;
  1331. tmpNode.insertBefore(leftNodes, parent);
  1332. tmpNode.insertBefore(rightNodes, parent);
  1333. tmpNode.insertBefore(node, rightNodes);
  1334. domUtils.remove(parent);
  1335. return node;
  1336. },
  1337. /**
  1338. * 检查是否是空inline节点
  1339. * @param {Node} node 节点
  1340. * @return {Boolean} 返回1为是,0为否
  1341. * @example
  1342. * &lt;b&gt;&lt;i&gt;&lt;/i&gt;&lt;/b&gt; //true
  1343. * <b><i></i><u></u></b> true
  1344. * &lt;b&gt;&lt;/b&gt; true &lt;b&gt;xx&lt;i&gt;&lt;/i&gt;&lt;/b&gt; //false
  1345. */
  1346. isEmptyInlineElement : function(node) {
  1347. if (node.nodeType != 1 || !dtd.$removeEmpty[ node.tagName ])
  1348. return 0;
  1349. node = node.firstChild;
  1350. while (node) {
  1351. //如果是创建的bookmark就跳过
  1352. if (domUtils.isBookmarkNode(node))
  1353. return 0;
  1354. if (node.nodeType == 1 && !domUtils.isEmptyInlineElement(node) ||
  1355. node.nodeType == 3 && !domUtils.isWhitespace(node)
  1356. ) {
  1357. return 0;
  1358. }
  1359. node = node.nextSibling;
  1360. }
  1361. return 1;
  1362. },
  1363. /**
  1364. * 删除空白子节点
  1365. * @param {Element} node 需要删除空白子节点的元素
  1366. */
  1367. trimWhiteTextNode : function(node) {
  1368. function remove(dir) {
  1369. var child;
  1370. while ((child = node[dir]) && child.nodeType == 3 && domUtils.isWhitespace(child))
  1371. node.removeChild(child)
  1372. }
  1373. remove('firstChild');
  1374. remove('lastChild');
  1375. },
  1376. /**
  1377. * 合并子节点
  1378. * @param {Node} node 节点
  1379. * @param {String} tagName 标签
  1380. * @param {String} attrs 属性
  1381. * @example &lt;span style="font-size:12px;"&gt;xx&lt;span style="font-size:12px;"&gt;aa&lt;/span&gt;xx&lt;/span 使用后
  1382. * &lt;span style="font-size:12px;"&gt;xxaaxx&lt;/span
  1383. */
  1384. mergChild : function(node, tagName, attrs) {
  1385. var list = domUtils.getElementsByTagName(node, node.tagName.toLowerCase());
  1386. for (var i = 0,ci; ci = list[i++];) {
  1387. if (!ci.parentNode || domUtils.isBookmarkNode(ci)) continue;
  1388. //span单独处理
  1389. if (ci.tagName.toLowerCase() == 'span') {
  1390. if (node === ci.parentNode) {
  1391. domUtils.trimWhiteTextNode(node);
  1392. if (node.childNodes.length == 1) {
  1393. node.style.cssText = ci.style.cssText + ";" + node.style.cssText;
  1394. domUtils.remove(ci, true);
  1395. continue;
  1396. }
  1397. }
  1398. ci.style.cssText = node.style.cssText + ';' + ci.style.cssText;
  1399. if (attrs) {
  1400. var style = attrs.style;
  1401. if (style) {
  1402. style = style.split(';');
  1403. for (var j = 0,s; s = style[j++];) {
  1404. ci.style[utils.cssStyleToDomStyle(s.split(':')[0])] = s.split(':')[1];
  1405. }
  1406. }
  1407. }
  1408. if (domUtils.isSameStyle(ci, node)) {
  1409. domUtils.remove(ci, true)
  1410. }
  1411. continue;
  1412. }
  1413. if (domUtils.isSameElement(node, ci)) {
  1414. domUtils.remove(ci, true);
  1415. }
  1416. }
  1417. if (tagName == 'span') {
  1418. var as = domUtils.getElementsByTagName(node, 'a');
  1419. for (var i = 0,ai; ai = as[i++];) {
  1420. ai.style.cssText = ';' + node.style.cssText;
  1421. ai.style.textDecoration = 'underline';
  1422. }
  1423. }
  1424. },
  1425. /**
  1426. * 封装原生的getElemensByTagName
  1427. * @param {Node} node 根节点
  1428. * @param {String} name 标签的tagName
  1429. * @return {Array} 返回符合条件的元素数组
  1430. */
  1431. getElementsByTagName : function(node, name) {
  1432. var list = node.getElementsByTagName(name),arr = [];
  1433. for (var i = 0,ci; ci = list[i++];) {
  1434. arr.push(ci)
  1435. }
  1436. return arr;
  1437. },
  1438. /**
  1439. * 将子节点合并到父节点上
  1440. * @param {Element} node 节点
  1441. * @example &lt;span style="color:#ff"&gt;&lt;span style="font-size:12px"&gt;xxx&lt;/span&gt;&lt;/span&gt; ==&gt; &lt;span style="color:#ff;font-size:12px"&gt;xxx&lt;/span&gt;
  1442. */
  1443. mergToParent : function(node) {
  1444. var parent = node.parentNode;
  1445. while (parent && dtd.$removeEmpty[parent.tagName]) {
  1446. if (parent.tagName == node.tagName || parent.tagName == 'A') {//针对a标签单独处理
  1447. domUtils.trimWhiteTextNode(parent);
  1448. //span需要特殊处理 不处理这样的情况 <span stlye="color:#fff">xxx<span style="color:#ccc">xxx</span>xxx</span>
  1449. if (parent.tagName == 'SPAN' && !domUtils.isSameStyle(parent, node)
  1450. || (parent.tagName == 'A' && node.tagName == 'SPAN')) {
  1451. if (parent.childNodes.length > 1 || parent !== node.parentNode) {
  1452. node.style.cssText = parent.style.cssText + ";" + node.style.cssText;
  1453. parent = parent.parentNode;
  1454. continue;
  1455. } else {
  1456. parent.style.cssText += ";" + node.style.cssText;
  1457. //trace:952 a标签要保持下划线
  1458. if (parent.tagName == 'A') {
  1459. parent.style.textDecoration = 'underline';
  1460. }
  1461. }
  1462. }
  1463. if(parent.tagName != 'A' ){
  1464. parent === node.parentNode && domUtils.remove(node, true);
  1465. break;
  1466. }
  1467. }
  1468. parent = parent.parentNode;
  1469. }
  1470. },
  1471. /**
  1472. * 合并左右兄弟节点
  1473. * @function
  1474. * @param {Node} node
  1475. * @param {Boolean} ingoreNext 默认为false合并上一个兄弟节点。true为不合并上一个兄弟节点
  1476. * @param {Boolean} ingorePre 默认为false合并下一个兄弟节点。true为不合并下一个兄弟节点
  1477. * @example &lt;b&gt;xxxx&lt;/b&gt;&lt;b&gt;xxx&lt;/b&gt;&lt;b&gt;xxxx&lt;/b&gt; ==> &lt;b&gt;xxxxxxxxxxx&lt;/b&gt;
  1478. */
  1479. mergSibling : function(node, ingorePre, ingoreNext) {
  1480. function merg(rtl, start, node) {
  1481. var next;
  1482. if ((next = node[rtl]) && !domUtils.isBookmarkNode(next) && next.nodeType == 1 && domUtils.isSameElement(node, next)) {
  1483. while (next.firstChild) {
  1484. if (start == 'firstChild') {
  1485. node.insertBefore(next.lastChild, node.firstChild);
  1486. } else {
  1487. node.appendChild(next.firstChild)
  1488. }
  1489. }
  1490. domUtils.remove(next);
  1491. }
  1492. }
  1493. !ingorePre && merg('previousSibling', 'firstChild', node);
  1494. !ingoreNext && merg('nextSibling', 'lastChild', node);
  1495. },
  1496. /**
  1497. * 使得元素及其子节点不能被选择
  1498. * @function
  1499. * @param {Node} node 节点
  1500. */
  1501. unselectable :
  1502. gecko ?
  1503. function(node) {
  1504. node.style.MozUserSelect = 'none';
  1505. }
  1506. : webkit ?
  1507. function(node) {
  1508. node.style.KhtmlUserSelect = 'none';
  1509. }
  1510. :
  1511. function(node) {
  1512. //for ie9
  1513. node.onselectstart = function () { return false; };
  1514. node.onclick = node.onkeyup = node.onkeydown = function(){return false};
  1515. node.unselectable = 'on';
  1516. node.setAttribute("unselectable","on");
  1517. for (var i = 0,ci; ci = node.all[i++];) {
  1518. switch (ci.tagName.toLowerCase()) {
  1519. case 'iframe' :
  1520. case 'textarea' :
  1521. case 'input' :
  1522. case 'select' :
  1523. break;
  1524. default :
  1525. ci.unselectable = 'on';
  1526. node.setAttribute("unselectable","on");
  1527. }
  1528. }
  1529. },
  1530. /**
  1531. * 删除元素上的属性,可以删除多个
  1532. * @function
  1533. * @param {Element} element 元素
  1534. * @param {Array} attrNames 要删除的属性数组
  1535. */
  1536. removeAttributes : function (elm, attrNames) {
  1537. for(var i = 0,ci;ci=attrNames[i++];){
  1538. ci = attrFix[ci] || ci;
  1539. switch (ci){
  1540. case 'className':
  1541. elm[ci] = '';
  1542. break;
  1543. case 'style':
  1544. elm.style.cssText = '';
  1545. !browser.ie && elm.removeAttributeNode(elm.getAttributeNode('style'))
  1546. }
  1547. elm.removeAttribute(ci);
  1548. }
  1549. },
  1550. creElm : function(doc,tag,attrs){
  1551. return this.setAttributes(doc.createElement(tag),attrs)
  1552. },
  1553. /**
  1554. * 给节点添加属性
  1555. * @function
  1556. * @param {Node} node 节点
  1557. * @param {Object} attrNames 要添加的属性名称,采用json对象存放
  1558. */
  1559. setAttributes : function(node, attrs) {
  1560. for (var name in attrs) {
  1561. var value = attrs[name];
  1562. switch (name) {
  1563. case 'class':
  1564. //ie下要这样赋值,setAttribute不起作用
  1565. node.className = value;
  1566. break;
  1567. case 'style' :
  1568. node.style.cssText = node.style.cssText + ";" + value;
  1569. break;
  1570. case 'innerHTML':
  1571. node[name] = value;
  1572. break;
  1573. case 'value':
  1574. node.value = value;
  1575. break;
  1576. default:
  1577. node.setAttribute(attrFix[name]||name, value);
  1578. }
  1579. }
  1580. return node;
  1581. },
  1582. /**
  1583. * 获取元素的样式
  1584. * @function
  1585. * @param {Element} element 元素
  1586. * @param {String} styleName 样式名称
  1587. * @return {String} 样式值
  1588. */
  1589. getComputedStyle : function (element, styleName) {
  1590. function fixUnit(key, val) {
  1591. if (key == 'font-size' && /pt$/.test(val)) {
  1592. val = Math.round(parseFloat(val) / 0.75) + 'px';
  1593. }
  1594. return val;
  1595. }
  1596. if(element.nodeType == 3){
  1597. element = element.parentNode;
  1598. }
  1599. //ie下font-size若body下定义了font-size,则从currentStyle里会取到这个font-size. 取不到实际值,故此修改.
  1600. if (browser.ie && browser.version < 9 && styleName == 'font-size' && !element.style.fontSize &&
  1601. !dtd.$empty[element.tagName] && !dtd.$nonChild[element.tagName]) {
  1602. var span = element.ownerDocument.createElement('span');
  1603. span.style.cssText = 'padding:0;border:0;font-family:simsun;';
  1604. span.innerHTML = '.';
  1605. element.appendChild(span);
  1606. var result = span.offsetHeight;
  1607. element.removeChild(span);
  1608. span = null;
  1609. return result + 'px';
  1610. }
  1611. try {
  1612. var value = domUtils.getStyle(element, styleName) ||
  1613. (window.getComputedStyle ? domUtils.getWindow(element).getComputedStyle(element, '').getPropertyValue(styleName) :
  1614. ( element.currentStyle || element.style )[utils.cssStyleToDomStyle(styleName)]);
  1615. } catch(e) {
  1616. return null;
  1617. }
  1618. return fixUnit(styleName, utils.fixColor(styleName, value));
  1619. },
  1620. /**
  1621. * 删除cssClass,可以支持删除多个class,需以空格分隔
  1622. * @param {Element} element 元素
  1623. * @param {Array} classNames 删除的className
  1624. */
  1625. removeClasses : function (element, classNames) {
  1626. element.className = (' ' + element.className + ' ').replace(
  1627. new RegExp('(?:\\s+(?:' + classNames.join('|') + '))+\\s+', 'g'), ' ');
  1628. },
  1629. /**
  1630. * 删除元素的样式
  1631. * @param {Element} element元素
  1632. * @param {String} name 删除的样式名称
  1633. */
  1634. removeStyle : function(node, name) {
  1635. node.style[utils.cssStyleToDomStyle(name)] = '';
  1636. if(!node.style.cssText)
  1637. domUtils.removeAttributes(node,['style'])
  1638. },
  1639. /**
  1640. * 判断元素属性中是否包含某一个classname
  1641. * @param {Element} element 元素
  1642. * @param {String} className 样式名
  1643. * @returns {Boolean} 是否包含该classname
  1644. */
  1645. hasClass : function (element, className) {
  1646. return ( ' ' + element.className + ' ' ).indexOf(' ' + className + ' ') > -1;
  1647. },
  1648. /**
  1649. * 阻止事件默认行为
  1650. * @param {Event} evt 需要组织的事件对象
  1651. */
  1652. preventDefault : function (evt) {
  1653. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  1654. },
  1655. /**
  1656. * 获得元素样式
  1657. * @param {Element} element 元素
  1658. * @param {String} name 样式名称
  1659. * @return {String} 返回元素样式值
  1660. */
  1661. getStyle : function(element, name) {
  1662. var value = element.style[ utils.cssStyleToDomStyle(name) ];
  1663. return utils.fixColor(name, value);
  1664. },
  1665. setStyle: function (element, name, value) {
  1666. element.style[utils.cssStyleToDomStyle(name)] = value;
  1667. },
  1668. setStyles: function (element, styles) {
  1669. for (var name in styles) {
  1670. if (styles.hasOwnProperty(name)) {
  1671. domUtils.setStyle(element, name, styles[name]);
  1672. }
  1673. }
  1674. },
  1675. /**
  1676. * 删除_moz_dirty属性
  1677. * @function
  1678. * @param {Node} node 节点
  1679. */
  1680. removeDirtyAttr : function(node) {
  1681. for (var i = 0,ci,nodes = node.getElementsByTagName('*'); ci = nodes[i++];) {
  1682. ci.removeAttribute('_moz_dirty')
  1683. }
  1684. node.removeAttribute('_moz_dirty')
  1685. },
  1686. /**
  1687. * 返回子节点的数量
  1688. * @function
  1689. * @param {Node} node 父节点
  1690. * @param {Function} fn 过滤子节点的规则,若为空,则得到所有子节点的数量
  1691. * @return {Number} 符合条件子节点的数量
  1692. */
  1693. getChildCount : function (node, fn) {
  1694. var count = 0,first = node.firstChild;
  1695. fn = fn || function() {
  1696. return 1
  1697. };
  1698. while (first) {
  1699. if (fn(first))
  1700. count++;
  1701. first = first.nextSibling;
  1702. }
  1703. return count;
  1704. },
  1705. /**
  1706. * 判断是否为空节点
  1707. * @function
  1708. * @param {Node} node 节点
  1709. * @return {Boolean} 是否为空节点
  1710. */
  1711. isEmptyNode : function(node) {
  1712. return !node.firstChild || domUtils.getChildCount(node, function(node) {
  1713. return !domUtils.isBr(node) && !domUtils.isBookmarkNode(node) && !domUtils.isWhitespace(node)
  1714. }) == 0
  1715. },
  1716. /**
  1717. * 清空节点所有的className
  1718. * @function
  1719. * @param {Array} nodes 节点数组
  1720. */
  1721. clearSelectedArr : function(nodes) {
  1722. var node;
  1723. while(node = nodes.pop()){
  1724. domUtils.removeAttributes(node,['class']);
  1725. }
  1726. },
  1727. /**
  1728. * 将显示区域滚动到显示节点的位置
  1729. * @function
  1730. * @param {Node} node 节点
  1731. * @param {window} win window对象
  1732. * @param {Number} offsetTop 距离上方的偏移量
  1733. */
  1734. scrollToView : function(node, win, offsetTop) {
  1735. var
  1736. getViewPaneSize = function() {
  1737. var doc = win.document,
  1738. mode = doc.compatMode == 'CSS1Compat';
  1739. return {
  1740. width : ( mode ? doc.documentElement.clientWidth : doc.body.clientWidth ) || 0,
  1741. height : ( mode ? doc.documentElement.clientHeight : doc.body.clientHeight ) || 0
  1742. };
  1743. },
  1744. getScrollPosition = function(win) {
  1745. if ('pageXOffset' in win) {
  1746. return {
  1747. x : win.pageXOffset || 0,
  1748. y : win.pageYOffset || 0
  1749. };
  1750. }
  1751. else {
  1752. var doc = win.document;
  1753. return {
  1754. x : doc.documentElement.scrollLeft || doc.body.scrollLeft || 0,
  1755. y : doc.documentElement.scrollTop || doc.body.scrollTop || 0
  1756. };
  1757. }
  1758. };
  1759. var winHeight = getViewPaneSize().height,offset = winHeight * -1 + offsetTop;
  1760. offset += (node.offsetHeight || 0);
  1761. var elementPosition = domUtils.getXY(node);
  1762. offset += elementPosition.y;
  1763. var currentScroll = getScrollPosition(win).y;
  1764. // offset += 50;
  1765. if (offset > currentScroll || offset < currentScroll - winHeight)
  1766. win.scrollTo(0, offset + (offset < 0 ? -20 : 20));
  1767. },
  1768. /**
  1769. * 判断节点是否为br
  1770. * @function
  1771. * @param {Node} node 节点
  1772. */
  1773. isBr : function(node) {
  1774. return node.nodeType == 1 && node.tagName == 'BR';
  1775. },
  1776. isFillChar : function(node){
  1777. return node.nodeType == 3 && !node.nodeValue.replace(new RegExp( domUtils.fillChar ),'').length
  1778. },
  1779. isStartInblock : function(range){
  1780. var tmpRange = range.cloneRange(),
  1781. flag = 0,
  1782. start = tmpRange.startContainer,
  1783. tmp;
  1784. while(start && domUtils.isFillChar(start)){
  1785. tmp = start;
  1786. start = start.previousSibling
  1787. }
  1788. if(tmp){
  1789. tmpRange.setStartBefore(tmp);
  1790. start = tmpRange.startContainer;
  1791. }
  1792. if(start.nodeType == 1 && domUtils.isEmptyNode(start) && tmpRange.startOffset == 1){
  1793. tmpRange.setStart(start,0).collapse(true);
  1794. }
  1795. while(!tmpRange.startOffset){
  1796. start = tmpRange.startContainer;
  1797. if(domUtils.isBlockElm(start)||domUtils.isBody(start)){
  1798. flag = 1;
  1799. break;
  1800. }
  1801. var pre = tmpRange.startContainer.previousSibling,
  1802. tmpNode;
  1803. if(!pre){
  1804. tmpRange.setStartBefore(tmpRange.startContainer);
  1805. }else{
  1806. while(pre && domUtils.isFillChar(pre)){
  1807. tmpNode = pre;
  1808. pre = pre.previousSibling;
  1809. }
  1810. if(tmpNode){
  1811. tmpRange.setStartBefore(tmpNode);
  1812. }else
  1813. tmpRange.setStartBefore(tmpRange.startContainer);
  1814. }
  1815. }
  1816. return flag && !domUtils.isBody(tmpRange.startContainer) ? 1 : 0;
  1817. },
  1818. isEmptyBlock : function(node){
  1819. var reg = new RegExp( '[ \t\r\n' + domUtils.fillChar+']', 'g' );
  1820. if(node[browser.ie?'innerText':'textContent'].replace(reg,'').length >0)
  1821. return 0;
  1822. for(var n in dtd.$isNotEmpty){
  1823. if(node.getElementsByTagName(n).length)
  1824. return 0;
  1825. }
  1826. return 1;
  1827. },
  1828. setViewportOffset: function (element, offset){
  1829. var left = parseInt(element.style.left) | 0;
  1830. var top = parseInt(element.style.top) | 0;
  1831. var rect = element.getBoundingClientRect();
  1832. var offsetLeft = offset.left - rect.left;
  1833. var offsetTop = offset.top - rect.top;
  1834. if (offsetLeft) {
  1835. element.style.left = left + offsetLeft + 'px';
  1836. }
  1837. if (offsetTop) {
  1838. element.style.top = top + offsetTop + 'px';
  1839. }
  1840. },
  1841. fillNode : function(doc,node){
  1842. var tmpNode = browser.ie ? doc.createTextNode(domUtils.fillChar) : doc.createElement('br');
  1843. node.innerHTML = '';
  1844. node.appendChild(tmpNode);
  1845. },
  1846. moveChild : function(src,tag,dir){
  1847. while(src.firstChild){
  1848. if(dir && tag.firstChild){
  1849. tag.insertBefore(src.lastChild,tag.firstChild);
  1850. }else{
  1851. tag.appendChild(src.firstChild)
  1852. }
  1853. }
  1854. },
  1855. //判断是否有额外属性
  1856. hasNoAttributes : function(node){
  1857. return browser.ie ? /^<\w+\s*?>/.test(node.outerHTML) :node.attributes.length == 0;
  1858. },
  1859. //判断是否是编辑器自定义的参数
  1860. isCustomeNode : function(node){
  1861. return node.nodeType == 1 && node.getAttribute('_ue_div_script');
  1862. }
  1863. };
  1864. var fillCharReg = new RegExp( domUtils.fillChar, 'g' );
  1865. ///import editor.js
  1866. ///import core/utils.js
  1867. ///import core/browser.js
  1868. ///import core/dom/dom.js
  1869. ///import core/dom/dtd.js
  1870. ///import core/dom/domUtils.js
  1871. /**
  1872. * @class baidu.editor.dom.Range Range类
  1873. */
  1874. /**
  1875. * @description Range类实现
  1876. * @author zhanyi
  1877. */
  1878. (function() {
  1879. var guid = 0,
  1880. fillChar = domUtils.fillChar,
  1881. fillData;
  1882. /**
  1883. * 更新range的collapse状态
  1884. * @param {Range} range range对象
  1885. */
  1886. function updateCollapse( range ) {
  1887. range.collapsed =
  1888. range.startContainer && range.endContainer &&
  1889. range.startContainer === range.endContainer &&
  1890. range.startOffset == range.endOffset;
  1891. }
  1892. function setEndPoint( toStart, node, offset, range ) {
  1893. //如果node是自闭合标签要处理
  1894. if ( node.nodeType == 1 && (dtd.$empty[node.tagName] || dtd.$nonChild[node.tagName])) {
  1895. offset = domUtils.getNodeIndex( node ) + (toStart ? 0 : 1);
  1896. node = node.parentNode;
  1897. }
  1898. if ( toStart ) {
  1899. range.startContainer = node;
  1900. range.startOffset = offset;
  1901. if ( !range.endContainer ) {
  1902. range.collapse( true );
  1903. }
  1904. } else {
  1905. range.endContainer = node;
  1906. range.endOffset = offset;
  1907. if ( !range.startContainer ) {
  1908. range.collapse( false );
  1909. }
  1910. }
  1911. updateCollapse( range );
  1912. return range;
  1913. }
  1914. function execContentsAction ( range, action ) {
  1915. //调整边界
  1916. //range.includeBookmark();
  1917. var start = range.startContainer,
  1918. end = range.endContainer,
  1919. startOffset = range.startOffset,
  1920. endOffset = range.endOffset,
  1921. doc = range.document,
  1922. frag = doc.createDocumentFragment(),
  1923. tmpStart,tmpEnd;
  1924. if ( start.nodeType == 1 ) {
  1925. start = start.childNodes[startOffset] || (tmpStart = start.appendChild( doc.createTextNode( '' ) ));
  1926. }
  1927. if ( end.nodeType == 1 ) {
  1928. end = end.childNodes[endOffset] || (tmpEnd = end.appendChild( doc.createTextNode( '' ) ));
  1929. }
  1930. if ( start === end && start.nodeType == 3 ) {
  1931. frag.appendChild( doc.createTextNode( start.substringData( startOffset, endOffset - startOffset ) ) );
  1932. //is not clone
  1933. if ( action ) {
  1934. start.deleteData( startOffset, endOffset - startOffset );
  1935. range.collapse( true );
  1936. }
  1937. return frag;
  1938. }
  1939. var current,currentLevel,clone = frag,
  1940. startParents = domUtils.findParents( start, true ),endParents = domUtils.findParents( end, true );
  1941. for ( var i = 0; startParents[i] == endParents[i]; i++ );
  1942. for ( var j = i,si; si = startParents[j]; j++ ) {
  1943. current = si.nextSibling;
  1944. if ( si == start ) {
  1945. if ( !tmpStart ) {
  1946. if ( range.startContainer.nodeType == 3 ) {
  1947. clone.appendChild( doc.createTextNode( start.nodeValue.slice( startOffset ) ) );
  1948. //is not clone
  1949. if ( action ) {
  1950. start.deleteData( startOffset, start.nodeValue.length - startOffset );
  1951. }
  1952. } else {
  1953. clone.appendChild( !action ? start.cloneNode( true ) : start );
  1954. }
  1955. }
  1956. } else {
  1957. currentLevel = si.cloneNode( false );
  1958. clone.appendChild( currentLevel );
  1959. }
  1960. while ( current ) {
  1961. if ( current === end || current === endParents[j] )break;
  1962. si = current.nextSibling;
  1963. clone.appendChild( !action ? current.cloneNode( true ) : current );
  1964. current = si;
  1965. }
  1966. clone = currentLevel;
  1967. }
  1968. clone = frag;
  1969. if ( !startParents[i] ) {
  1970. clone.appendChild( startParents[i - 1].cloneNode( false ) );
  1971. clone = clone.firstChild;
  1972. }
  1973. for ( var j = i,ei; ei = endParents[j]; j++ ) {
  1974. current = ei.previousSibling;
  1975. if ( ei == end ) {
  1976. if ( !tmpEnd && range.endContainer.nodeType == 3 ) {
  1977. clone.appendChild( doc.createTextNode( end.substringData( 0, endOffset ) ) );
  1978. //is not clone
  1979. if ( action ) {
  1980. end.deleteData( 0, endOffset );
  1981. }
  1982. }
  1983. } else {
  1984. currentLevel = ei.cloneNode( false );
  1985. clone.appendChild( currentLevel );
  1986. }
  1987. //如果两端同级,右边第一次已经被开始做了
  1988. if ( j != i || !startParents[i] ) {
  1989. while ( current ) {
  1990. if ( current === start )break;
  1991. ei = current.previousSibling;
  1992. clone.insertBefore( !action ? current.cloneNode( true ) : current, clone.firstChild );
  1993. current = ei;
  1994. }
  1995. }
  1996. clone = currentLevel;
  1997. }
  1998. if ( action ) {
  1999. range.setStartBefore( !endParents[i] ? endParents[i - 1] : !startParents[i] ? startParents[i - 1] : endParents[i] ).collapse( true )
  2000. }
  2001. tmpStart && domUtils.remove( tmpStart );
  2002. tmpEnd && domUtils.remove( tmpEnd );
  2003. return frag;
  2004. }
  2005. /**
  2006. * Range类
  2007. * @param {Document} document 编辑器页面document对象
  2008. */
  2009. var Range = dom.Range = function( document ) {
  2010. var me = this;
  2011. me.startContainer =
  2012. me.startOffset =
  2013. me.endContainer =
  2014. me.endOffset = null;
  2015. me.document = document;
  2016. me.collapsed = true;
  2017. };
  2018. function removeFillData(doc,excludeNode){
  2019. try{
  2020. if ( fillData && domUtils.inDoc(fillData,doc) ) {
  2021. if(!fillData.nodeValue.replace( fillCharReg, '' ).length){
  2022. var tmpNode = fillData.parentNode;
  2023. domUtils.remove(fillData);
  2024. while(tmpNode && domUtils.isEmptyInlineElement(tmpNode) && !tmpNode.contains(excludeNode)){
  2025. fillData = tmpNode.parentNode;
  2026. domUtils.remove(tmpNode);
  2027. tmpNode = fillData
  2028. }
  2029. }else
  2030. fillData.nodeValue = fillData.nodeValue.replace( fillCharReg, '' )
  2031. }
  2032. }catch(e){}
  2033. }
  2034. function mergSibling(node,dir){
  2035. var tmpNode;
  2036. node = node[dir];
  2037. while(node && domUtils.isFillChar(node)){
  2038. tmpNode = node[dir];
  2039. domUtils.remove(node);
  2040. node = tmpNode;
  2041. }
  2042. }
  2043. Range.prototype = {
  2044. /**
  2045. * 克隆选中的内容到一个fragment里
  2046. * @public
  2047. * @function
  2048. * @name baidu.editor.dom.Range.cloneContents
  2049. * @return {Fragment} frag|null 返回选中内容的文本片段或者空
  2050. */
  2051. cloneContents : function() {
  2052. return this.collapsed ? null : execContentsAction( this, 0 );
  2053. },
  2054. /**
  2055. * 删除所选内容
  2056. * @public
  2057. * @function
  2058. * @name baidu.editor.dom.Range.deleteContents
  2059. * @return {Range} 删除选中内容后的Range
  2060. */
  2061. deleteContents : function() {
  2062. if ( !this.collapsed )
  2063. execContentsAction( this, 1 );
  2064. if(browser.webkit){
  2065. var txt = this.startContainer;
  2066. if(txt.nodeType == 3 && !txt.nodeValue.length){
  2067. this.setStartBefore(txt).collapse(true);
  2068. domUtils.remove(txt)
  2069. }
  2070. }
  2071. return this;
  2072. },
  2073. /**
  2074. * 取出内容
  2075. * @public
  2076. * @function
  2077. * @name baidu.editor.dom.Range.extractContents
  2078. * @return {String} 获得Range选中的内容
  2079. */
  2080. extractContents : function() {
  2081. return this.collapsed ? null : execContentsAction( this, 2 );
  2082. },
  2083. /**
  2084. * 设置range的开始位置
  2085. * @public
  2086. * @function
  2087. * @name baidu.editor.dom.Range.setStart
  2088. * @param {Node} node range开始节点
  2089. * @param {Number} offset 偏移量
  2090. * @return {Range} 返回Range
  2091. */
  2092. setStart : function( node, offset ) {
  2093. return setEndPoint( true, node, offset, this );
  2094. },
  2095. /**
  2096. * 设置range结束点的位置
  2097. * @public
  2098. * @function
  2099. * @name baidu.editor.dom.Range.setEnd
  2100. * @param {Node} node range结束节点
  2101. * @param {Number} offset 偏移量
  2102. * @return {Range} 返回Range
  2103. */
  2104. setEnd : function( node, offset ) {
  2105. return setEndPoint( false, node, offset, this );
  2106. },
  2107. /**
  2108. * 将开始位置设置到node后
  2109. * @public
  2110. * @function
  2111. * @name baidu.editor.dom.Range.setStartAfter
  2112. * @param {Node} node 节点
  2113. * @return {Range} 返回Range
  2114. */
  2115. setStartAfter : function( node ) {
  2116. return this.setStart( node.parentNode, domUtils.getNodeIndex( node ) + 1 );
  2117. },
  2118. /**
  2119. * 将开始位置设置到node前
  2120. * @public
  2121. * @function
  2122. * @name baidu.editor.dom.Range.setStartBefore
  2123. * @param {Node} node 节点
  2124. * @return {Range} 返回Range
  2125. */
  2126. setStartBefore : function( node ) {
  2127. return this.setStart( node.parentNode, domUtils.getNodeIndex( node ) );
  2128. },
  2129. /**
  2130. * 将结束点位置设置到node后
  2131. * @public
  2132. * @function
  2133. * @name baidu.editor.dom.Range.setEndAfter
  2134. * @param {Node} node 节点
  2135. * @return {Range} 返回Range
  2136. */
  2137. setEndAfter : function( node ) {
  2138. return this.setEnd( node.parentNode, domUtils.getNodeIndex( node ) + 1 );
  2139. },
  2140. /**
  2141. * 将开始设置到node的最开始位置 <element>^text</element>
  2142. * @public
  2143. * @function
  2144. * @name baidu.editor.dom.Range.setEndAfter
  2145. * @param {Node} node 节点
  2146. * @return {Range} 返回Range
  2147. */
  2148. setStartAtFirst : function(node){
  2149. return this.setStart(node,0)
  2150. },
  2151. /**
  2152. * 将开始设置到node的最开始位置 <element>text^</element>
  2153. * @public
  2154. * @function
  2155. * @name baidu.editor.dom.Range.setEndAfter
  2156. * @param {Node} node 节点
  2157. * @return {Range} 返回Range
  2158. */
  2159. setStartAtLast : function(node){
  2160. return this.setStart(node,node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length)
  2161. },
  2162. /**
  2163. * 将结束设置到node的最开始位置 <element>^text</element>
  2164. * @public
  2165. * @function
  2166. * @name baidu.editor.dom.Range.setEndAfter
  2167. * @param {Node} node 节点
  2168. * @return {Range} 返回Range
  2169. */
  2170. setEndAtFirst : function(node){
  2171. return this.setEnd(node,0)
  2172. },
  2173. /**
  2174. * 将结束设置到node的最开始位置 <element>text^</element>
  2175. * @public
  2176. * @function
  2177. * @name baidu.editor.dom.Range.setEndAfter
  2178. * @param {Node} node 节点
  2179. * @return {Range} 返回Range
  2180. */
  2181. setEndAtLast : function(node){
  2182. return this.setEnd(node,node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length)
  2183. },
  2184. /**
  2185. * 将结束点位置设置到node前
  2186. * @public
  2187. * @function
  2188. * @name baidu.editor.dom.Range.setEndBefore
  2189. * @param {Node} node 节点
  2190. * @return {Range} 返回Range
  2191. */
  2192. setEndBefore : function( node ) {
  2193. return this.setEnd( node.parentNode, domUtils.getNodeIndex( node ) );
  2194. },
  2195. /**
  2196. * 选中指定节点
  2197. * @public
  2198. * @function
  2199. * @name baidu.editor.dom.Range.selectNode
  2200. * @param {Node} node 节点
  2201. * @return {Range} 返回Range
  2202. */
  2203. selectNode : function( node ) {
  2204. return this.setStartBefore( node ).setEndAfter( node );
  2205. },
  2206. /**
  2207. * 选中node下的所有节点
  2208. * @public
  2209. * @function
  2210. * @name baidu.editor.dom.Range.selectNodeContents
  2211. * @param {Element} node 要设置的节点
  2212. * @return {Range} 返回Range
  2213. */
  2214. selectNodeContents : function( node ) {
  2215. return this.setStart( node, 0 ).setEnd( node, node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length );
  2216. },
  2217. /**
  2218. * 克隆range
  2219. * @public
  2220. * @function
  2221. * @name baidu.editor.dom.Range.cloneRange
  2222. * @return {Range} 克隆的range对象
  2223. */
  2224. cloneRange : function() {
  2225. var me = this,range = new Range( me.document );
  2226. return range.setStart( me.startContainer, me.startOffset ).setEnd( me.endContainer, me.endOffset );
  2227. },
  2228. /**
  2229. * 让选区闭合
  2230. * @public
  2231. * @function
  2232. * @name baidu.editor.dom.Range.collapse
  2233. * @param {Boolean} toStart 是否在选区开始位置闭合选区,true在开始位置闭合,false反之
  2234. * @return {Range} range对象
  2235. */
  2236. collapse : function( toStart ) {
  2237. var me = this;
  2238. if ( toStart ) {
  2239. me.endContainer = me.startContainer;
  2240. me.endOffset = me.startOffset;
  2241. }
  2242. else {
  2243. me.startContainer = me.endContainer;
  2244. me.startOffset = me.endOffset;
  2245. }
  2246. me.collapsed = true;
  2247. return me;
  2248. },
  2249. /**
  2250. * 调整range的边界,“缩”到合适的位置
  2251. * @public
  2252. * @function
  2253. * @name baidu.editor.dom.Range.shrinkBoundary
  2254. * @param {Boolean} ignoreEnd 是否考虑前面的元素
  2255. */
  2256. shrinkBoundary : function( ignoreEnd ) {
  2257. var me = this,child,
  2258. collapsed = me.collapsed;
  2259. while ( me.startContainer.nodeType == 1 //是element
  2260. && (child = me.startContainer.childNodes[me.startOffset]) //子节点也是element
  2261. && child.nodeType == 1 && !domUtils.isBookmarkNode(child)
  2262. && !dtd.$empty[child.tagName] && !dtd.$nonChild[child.tagName] ) {
  2263. me.setStart( child, 0 );
  2264. }
  2265. if ( collapsed )
  2266. return me.collapse( true );
  2267. if ( !ignoreEnd ) {
  2268. while ( me.endContainer.nodeType == 1//是element
  2269. && me.endOffset > 0 //如果是空元素就退出 endOffset=0那么endOffst-1为负值,childNodes[endOffset]报错
  2270. && (child = me.endContainer.childNodes[me.endOffset - 1]) //子节点也是element
  2271. && child.nodeType == 1 && !domUtils.isBookmarkNode(child)
  2272. && !dtd.$empty[child.tagName] && !dtd.$nonChild[child.tagName]) {
  2273. me.setEnd( child, child.childNodes.length );
  2274. }
  2275. }
  2276. return me;
  2277. },
  2278. /**
  2279. * 找到startContainer和endContainer的公共祖先节点
  2280. * @public
  2281. * @function
  2282. * @name baidu.editor.dom.Range.getCommonAncestor
  2283. * @param {Boolean} includeSelf 是否包含自身
  2284. * @param {Boolean} ignoreTextNode 是否忽略文本节点
  2285. * @return {Node} 祖先节点
  2286. */
  2287. getCommonAncestor : function( includeSelf, ignoreTextNode ) {
  2288. var start = this.startContainer,
  2289. end = this.endContainer;
  2290. if ( start === end ) {
  2291. if ( includeSelf && start.nodeType == 1 && this.startOffset == this.endOffset - 1 ) {
  2292. return start.childNodes[this.startOffset];
  2293. }
  2294. //只有在上来就相等的情况下才会出现是文本的情况
  2295. return ignoreTextNode && start.nodeType == 3 ? start.parentNode : start;
  2296. }
  2297. return domUtils.getCommonAncestor( start, end );
  2298. },
  2299. /**
  2300. * 切割文本节点,将边界扩大到element
  2301. * @public
  2302. * @function
  2303. * @name baidu.editor.dom.Range.trimBoundary
  2304. * @param {Boolean} ignoreEnd 为真就不处理结束边界
  2305. * @return {Range} range对象
  2306. * @example <b>|xxx</b>
  2307. * startContainer = xxx; startOffset = 0
  2308. * 执行后
  2309. * startContainer = <b>; startOffset = 0
  2310. * @example <b>xx|x</b>
  2311. * startContainer = xxx; startOffset = 2
  2312. * 执行后
  2313. * startContainer = <b>; startOffset = 1 因为将xxx切割成2个节点了
  2314. */
  2315. trimBoundary : function( ignoreEnd ) {
  2316. this.txtToElmBoundary();
  2317. var start = this.startContainer,
  2318. offset = this.startOffset,
  2319. collapsed = this.collapsed,
  2320. end = this.endContainer;
  2321. if ( start.nodeType == 3 ) {
  2322. if ( offset == 0 ) {
  2323. this.setStartBefore( start )
  2324. } else {
  2325. if ( offset >= start.nodeValue.length ) {
  2326. this.setStartAfter( start );
  2327. } else {
  2328. var textNode = domUtils.split( start, offset );
  2329. //跟新结束边界
  2330. if ( start === end )
  2331. this.setEnd( textNode, this.endOffset - offset );
  2332. else if ( start.parentNode === end )
  2333. this.endOffset += 1;
  2334. this.setStartBefore( textNode );
  2335. }
  2336. }
  2337. if ( collapsed ) {
  2338. return this.collapse( true );
  2339. }
  2340. }
  2341. if ( !ignoreEnd ) {
  2342. offset = this.endOffset;
  2343. end = this.endContainer;
  2344. if ( end.nodeType == 3 ) {
  2345. if ( offset == 0 ) {
  2346. this.setEndBefore( end );
  2347. } else {
  2348. if ( offset >= end.nodeValue.length ) {
  2349. this.setEndAfter( end );
  2350. } else {
  2351. domUtils.split( end, offset );
  2352. this.setEndAfter( end );
  2353. }
  2354. }
  2355. }
  2356. }
  2357. return this;
  2358. },
  2359. /**
  2360. * 如果选区在文本的边界上,就扩展选区到文本的父节点上
  2361. * @public
  2362. * @function
  2363. * @name baidu.editor.dom.Range.txtToElmBoundary
  2364. * @return {Range} range对象
  2365. * @example <b> |xxx</b>
  2366. * startContainer = xxx; startOffset = 0
  2367. * 执行后
  2368. * startContainer = <b>; startOffset = 0
  2369. * @example <b> xxx| </b>
  2370. * startContainer = xxx; startOffset = 3
  2371. * 执行后
  2372. * startContainer = <b>; startOffset = 1
  2373. */
  2374. txtToElmBoundary : function() {
  2375. function adjust( r, c ) {
  2376. var container = r[c + 'Container'],
  2377. offset = r[c + 'Offset'];
  2378. if ( container.nodeType == 3 ) {
  2379. if ( !offset ) {
  2380. r['set' + c.replace( /(\w)/, function( a ) {
  2381. return a.toUpperCase()
  2382. } ) + 'Before']( container )
  2383. } else if ( offset >= container.nodeValue.length ) {
  2384. r['set' + c.replace( /(\w)/, function( a ) {
  2385. return a.toUpperCase()
  2386. } ) + 'After' ]( container )
  2387. }
  2388. }
  2389. }
  2390. if ( !this.collapsed ) {
  2391. adjust( this, 'start' );
  2392. adjust( this, 'end' );
  2393. }
  2394. return this;
  2395. },
  2396. /**
  2397. * 在当前选区的开始位置前插入一个节点或者fragment
  2398. * @public
  2399. * @function
  2400. * @name baidu.editor.dom.Range.insertNode
  2401. * @param {Node/DocumentFragment} node 要插入的节点或fragment
  2402. * @return {Range} 返回range对象
  2403. */
  2404. insertNode : function( node ) {
  2405. var first = node,length = 1;
  2406. if ( node.nodeType == 11 ) {
  2407. first = node.firstChild;
  2408. length = node.childNodes.length;
  2409. }
  2410. this.trimBoundary( true );
  2411. var start = this.startContainer,
  2412. offset = this.startOffset;
  2413. var nextNode = start.childNodes[ offset ];
  2414. if ( nextNode ) {
  2415. start.insertBefore( node, nextNode );
  2416. }
  2417. else {
  2418. start.appendChild( node );
  2419. }
  2420. if ( first.parentNode === this.endContainer ) {
  2421. this.endOffset = this.endOffset + length;
  2422. }
  2423. return this.setStartBefore( first );
  2424. },
  2425. /**
  2426. * 设置光标位置
  2427. * @public
  2428. * @function
  2429. * @name baidu.editor.dom.Range.setCursor
  2430. * @param {Boolean} toEnd true为闭合到选区的结束位置后,false为闭合到选区的开始位置前
  2431. * @return {Range} 返回range对象
  2432. */
  2433. setCursor : function( toEnd ,notFillData) {
  2434. return this.collapse( toEnd ? false : true ).select(notFillData);
  2435. },
  2436. /**
  2437. * 创建书签
  2438. * @public
  2439. * @function
  2440. * @name baidu.editor.dom.Range.createBookmark
  2441. * @param {Boolean} serialize true:为true则返回对象中用id来分别表示书签的开始和结束节点
  2442. * @param {Boolean} same true:是否采用唯一的id,false将会为每一个标签产生一个唯一的id
  2443. * @returns {Object} bookmark对象
  2444. */
  2445. createBookmark : function( serialize, same ) {
  2446. var endNode,
  2447. startNode = this.document.createElement( 'span' );
  2448. startNode.style.cssText = 'display:none;line-height:0px;';
  2449. startNode.appendChild( this.document.createTextNode( '\uFEFF' ) );
  2450. startNode.id = '_baidu_bookmark_start_' + (same ? '' : guid++);
  2451. if ( !this.collapsed ) {
  2452. endNode = startNode.cloneNode( true );
  2453. endNode.id = '_baidu_bookmark_end_' + (same ? '' : guid++);
  2454. }
  2455. this.insertNode( startNode );
  2456. if ( endNode ) {
  2457. this.collapse( false ).insertNode( endNode );
  2458. this.setEndBefore( endNode )
  2459. }
  2460. this.setStartAfter( startNode );
  2461. return {
  2462. start : serialize ? startNode.id : startNode,
  2463. end : endNode ? serialize ? endNode.id : endNode : null,
  2464. id : serialize
  2465. }
  2466. },
  2467. /**
  2468. * 移动边界到书签,并删除书签
  2469. * @public
  2470. * @function
  2471. * @name baidu.editor.dom.Range.moveToBookmark
  2472. * @params {Object} bookmark对象
  2473. * @returns {Range} Range对象
  2474. */
  2475. moveToBookmark : function( bookmark ) {
  2476. var start = bookmark.id ? this.document.getElementById( bookmark.start ) : bookmark.start,
  2477. end = bookmark.end && bookmark.id ? this.document.getElementById( bookmark.end ) : bookmark.end;
  2478. this.setStartBefore( start );
  2479. domUtils.remove( start );
  2480. if ( end ) {
  2481. this.setEndBefore( end );
  2482. domUtils.remove( end )
  2483. } else {
  2484. this.collapse( true );
  2485. }
  2486. return this;
  2487. },
  2488. /**
  2489. * 调整边界到一个block元素上,或者移动到最大的位置
  2490. * @public
  2491. * @function
  2492. * @name baidu.editor.dom.Range.enlarge
  2493. * @params {Boolean} toBlock 扩展到block元素
  2494. * @params {Function} stopFn 停止函数,若返回true,则不再扩展
  2495. * @return {Range} Range对象
  2496. */
  2497. enlarge : function( toBlock, stopFn ) {
  2498. var isBody = domUtils.isBody,
  2499. pre,node,tmp = this.document.createTextNode( '' );
  2500. if ( toBlock ) {
  2501. node = this.startContainer;
  2502. if ( node.nodeType == 1 ) {
  2503. if ( node.childNodes[this.startOffset] ) {
  2504. pre = node = node.childNodes[this.startOffset]
  2505. } else {
  2506. node.appendChild( tmp );
  2507. pre = node = tmp;
  2508. }
  2509. } else {
  2510. pre = node;
  2511. }
  2512. while ( 1 ) {
  2513. if ( domUtils.isBlockElm( node ) ) {
  2514. node = pre;
  2515. while ( (pre = node.previousSibling) && !domUtils.isBlockElm( pre ) ) {
  2516. node = pre;
  2517. }
  2518. this.setStartBefore( node );
  2519. break;
  2520. }
  2521. pre = node;
  2522. node = node.parentNode;
  2523. }
  2524. node = this.endContainer;
  2525. if ( node.nodeType == 1 ) {
  2526. if(pre = node.childNodes[this.endOffset]) {
  2527. node.insertBefore( tmp, pre );
  2528. }else{
  2529. node.appendChild(tmp)
  2530. }
  2531. pre = node = tmp;
  2532. } else {
  2533. pre = node;
  2534. }
  2535. while ( 1 ) {
  2536. if ( domUtils.isBlockElm( node ) ) {
  2537. node = pre;
  2538. while ( (pre = node.nextSibling) && !domUtils.isBlockElm( pre ) ) {
  2539. node = pre;
  2540. }
  2541. this.setEndAfter( node );
  2542. break;
  2543. }
  2544. pre = node;
  2545. node = node.parentNode;
  2546. }
  2547. if ( tmp.parentNode === this.endContainer ) {
  2548. this.endOffset--;
  2549. }
  2550. domUtils.remove( tmp )
  2551. }
  2552. // 扩展边界到最大
  2553. if ( !this.collapsed ) {
  2554. while ( this.startOffset == 0 ) {
  2555. if ( stopFn && stopFn( this.startContainer ) )
  2556. break;
  2557. if ( isBody( this.startContainer ) )break;
  2558. this.setStartBefore( this.startContainer );
  2559. }
  2560. while ( this.endOffset == (this.endContainer.nodeType == 1 ? this.endContainer.childNodes.length : this.endContainer.nodeValue.length) ) {
  2561. if ( stopFn && stopFn( this.endContainer ) )
  2562. break;
  2563. if ( isBody( this.endContainer ) )break;
  2564. this.setEndAfter( this.endContainer )
  2565. }
  2566. }
  2567. return this;
  2568. },
  2569. /**
  2570. * 调整边界
  2571. * @public
  2572. * @function
  2573. * @name baidu.editor.dom.Range.adjustmentBoundary
  2574. * @return {Range} Range对象
  2575. * @example
  2576. * <b>xx[</b>xxxxx] ==> <b>xx</b>[xxxxx]
  2577. * <b>[xx</b><i>]xxx</i> ==> <b>[xx</b>]<i>xxx</i>
  2578. *
  2579. */
  2580. adjustmentBoundary : function() {
  2581. if(!this.collapsed){
  2582. while ( !domUtils.isBody( this.startContainer ) &&
  2583. this.startOffset == this.startContainer[this.startContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length
  2584. ) {
  2585. this.setStartAfter( this.startContainer );
  2586. }
  2587. while ( !domUtils.isBody( this.endContainer ) && !this.endOffset ) {
  2588. this.setEndBefore( this.endContainer );
  2589. }
  2590. }
  2591. return this;
  2592. },
  2593. /**
  2594. * 给选区中的内容加上inline样式
  2595. * @public
  2596. * @function
  2597. * @name baidu.editor.dom.Range.applyInlineStyle
  2598. * @param {String} tagName 标签名称
  2599. * @param {Object} attrObj 属性
  2600. * @return {Range} Range对象
  2601. */
  2602. applyInlineStyle : function( tagName, attrs ,list) {
  2603. if(this.collapsed)return this;
  2604. this.trimBoundary().enlarge( false,
  2605. function( node ) {
  2606. return node.nodeType == 1 && domUtils.isBlockElm( node )
  2607. } ).adjustmentBoundary();
  2608. var bookmark = this.createBookmark(),
  2609. end = bookmark.end,
  2610. filterFn = function( node ) {
  2611. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' : !domUtils.isWhitespace( node )
  2612. },
  2613. current = domUtils.getNextDomNode( bookmark.start, false, filterFn ),
  2614. node,
  2615. pre,
  2616. range = this.cloneRange();
  2617. while ( current && (domUtils.getPosition( current, end ) & domUtils.POSITION_PRECEDING) ) {
  2618. if ( current.nodeType == 3 || dtd[tagName][current.tagName] ) {
  2619. range.setStartBefore( current );
  2620. node = current;
  2621. while ( node && (node.nodeType == 3 || dtd[tagName][node.tagName]) && node !== end ) {
  2622. pre = node;
  2623. node = domUtils.getNextDomNode( node, node.nodeType == 1, null, function( parent ) {
  2624. return dtd[tagName][parent.tagName]
  2625. } )
  2626. }
  2627. var frag = range.setEndAfter( pre ).extractContents(),elm;
  2628. if(list && list.length > 0){
  2629. var level,top;
  2630. top = level = list[0].cloneNode(false);
  2631. for(var i=1,ci;ci=list[i++];){
  2632. level.appendChild(ci.cloneNode(false));
  2633. level = level.firstChild;
  2634. }
  2635. elm = level;
  2636. }else{
  2637. elm = range.document.createElement( tagName )
  2638. }
  2639. if ( attrs ) {
  2640. domUtils.setAttributes( elm, attrs )
  2641. }
  2642. elm.appendChild( frag );
  2643. range.insertNode( list ? top : elm );
  2644. //处理下滑线在a上的情况
  2645. var aNode;
  2646. if(tagName == 'span' && attrs.style && /text\-decoration/.test(attrs.style) && (aNode = domUtils.findParentByTagName(elm,'a',true)) ){
  2647. domUtils.setAttributes(aNode,attrs);
  2648. domUtils.remove(elm,true);
  2649. elm = aNode;
  2650. }else{
  2651. domUtils.mergSibling( elm );
  2652. domUtils.clearEmptySibling( elm );
  2653. }
  2654. //去除子节点相同的
  2655. domUtils.mergChild( elm, tagName,attrs );
  2656. current = domUtils.getNextDomNode( elm, false, filterFn );
  2657. domUtils.mergToParent( elm );
  2658. if ( node === end )break;
  2659. } else {
  2660. current = domUtils.getNextDomNode( current, true, filterFn )
  2661. }
  2662. }
  2663. return this.moveToBookmark( bookmark );
  2664. },
  2665. /**
  2666. * 去掉inline样式
  2667. * @public
  2668. * @function
  2669. * @name baidu.editor.dom.Range.removeInlineStyle
  2670. * @param {String/Array} tagName 要去掉的标签名
  2671. * @return {Range} Range对象
  2672. */
  2673. removeInlineStyle : function( tagName ) {
  2674. if(this.collapsed)return this;
  2675. tagName = utils.isArray( tagName ) ? tagName : [tagName];
  2676. this.shrinkBoundary().adjustmentBoundary();
  2677. var start = this.startContainer,end = this.endContainer;
  2678. while ( 1 ) {
  2679. if ( start.nodeType == 1 ) {
  2680. if ( utils.indexOf( tagName, start.tagName.toLowerCase() ) > -1 ) {
  2681. break;
  2682. }
  2683. if ( start.tagName.toLowerCase() == 'body' ) {
  2684. start = null;
  2685. break;
  2686. }
  2687. }
  2688. start = start.parentNode;
  2689. }
  2690. while ( 1 ) {
  2691. if ( end.nodeType == 1 ) {
  2692. if ( utils.indexOf( tagName, end.tagName.toLowerCase() ) > -1 ) {
  2693. break;
  2694. }
  2695. if ( end.tagName.toLowerCase() == 'body' ) {
  2696. end = null;
  2697. break;
  2698. }
  2699. }
  2700. end = end.parentNode;
  2701. }
  2702. var bookmark = this.createBookmark(),
  2703. frag,
  2704. tmpRange;
  2705. if ( start ) {
  2706. tmpRange = this.cloneRange().setEndBefore( bookmark.start ).setStartBefore( start );
  2707. frag = tmpRange.extractContents();
  2708. tmpRange.insertNode( frag );
  2709. domUtils.clearEmptySibling( start, true );
  2710. start.parentNode.insertBefore( bookmark.start, start );
  2711. }
  2712. if ( end ) {
  2713. tmpRange = this.cloneRange().setStartAfter( bookmark.end ).setEndAfter( end );
  2714. frag = tmpRange.extractContents();
  2715. tmpRange.insertNode( frag );
  2716. domUtils.clearEmptySibling( end, false, true );
  2717. end.parentNode.insertBefore( bookmark.end, end.nextSibling );
  2718. }
  2719. var current = domUtils.getNextDomNode( bookmark.start, false, function( node ) {
  2720. return node.nodeType == 1
  2721. } ),next;
  2722. while ( current && current !== bookmark.end ) {
  2723. next = domUtils.getNextDomNode( current, true, function( node ) {
  2724. return node.nodeType == 1
  2725. } );
  2726. if ( utils.indexOf( tagName, current.tagName.toLowerCase() ) > -1 ) {
  2727. domUtils.remove( current, true );
  2728. }
  2729. current = next;
  2730. }
  2731. return this.moveToBookmark( bookmark );
  2732. },
  2733. /**
  2734. * 得到一个自闭合的节点
  2735. * @public
  2736. * @function
  2737. * @name baidu.editor.dom.Range.getClosedNode
  2738. * @return {Node} 闭合节点
  2739. * @example
  2740. * <img />,<br />
  2741. */
  2742. getClosedNode : function() {
  2743. var node;
  2744. if ( !this.collapsed ) {
  2745. var range = this.cloneRange().adjustmentBoundary().shrinkBoundary();
  2746. if ( range.startContainer.nodeType == 1 && range.startContainer === range.endContainer && range.endOffset - range.startOffset == 1 ) {
  2747. var child = range.startContainer.childNodes[range.startOffset];
  2748. if ( child && child.nodeType == 1 && (dtd.$empty[child.tagName] || dtd.$nonChild[child.tagName])) {
  2749. node = child;
  2750. }
  2751. }
  2752. }
  2753. return node;
  2754. },
  2755. /**
  2756. * 根据range选中元素
  2757. * @public
  2758. * @function
  2759. * @name baidu.editor.dom.Range.select
  2760. * @param {Boolean} notInsertFillData true为不加占位符
  2761. */
  2762. select : browser.ie ? function( notInsertFillData ,textRange) {
  2763. var nativeRange;
  2764. if ( !this.collapsed )
  2765. this.shrinkBoundary();
  2766. var node = this.getClosedNode();
  2767. if ( node && !textRange) {
  2768. try {
  2769. nativeRange = this.document.body.createControlRange();
  2770. nativeRange.addElement( node );
  2771. nativeRange.select();
  2772. } catch( e ) {
  2773. }
  2774. return this;
  2775. }
  2776. var bookmark = this.createBookmark(),
  2777. start = bookmark.start,
  2778. end;
  2779. nativeRange = this.document.body.createTextRange();
  2780. nativeRange.moveToElementText( start );
  2781. nativeRange.moveStart( 'character', 1 );
  2782. if ( !this.collapsed ) {
  2783. var nativeRangeEnd = this.document.body.createTextRange();
  2784. end = bookmark.end;
  2785. nativeRangeEnd.moveToElementText( end );
  2786. nativeRange.setEndPoint( 'EndToEnd', nativeRangeEnd );
  2787. } else {
  2788. if ( !notInsertFillData && this.startContainer.nodeType != 3 ) {
  2789. //使用<span>|x<span>固定住光标
  2790. var tmpText = this.document.createTextNode( fillChar ),
  2791. tmp = this.document.createElement( 'span' );
  2792. tmp.appendChild( this.document.createTextNode( fillChar) );
  2793. start.parentNode.insertBefore( tmp, start );
  2794. start.parentNode.insertBefore( tmpText, start );
  2795. //当点b,i,u时,不能清除i上边的b
  2796. removeFillData(this.document,tmpText);
  2797. fillData = tmpText;
  2798. mergSibling(tmp,'previousSibling');
  2799. mergSibling(start,'nextSibling');
  2800. nativeRange.moveStart( 'character', -1 );
  2801. nativeRange.collapse( true );
  2802. }
  2803. }
  2804. this.moveToBookmark( bookmark );
  2805. tmp && domUtils.remove( tmp );
  2806. nativeRange.select();
  2807. return this;
  2808. } : function( notInsertFillData ) {
  2809. var win = domUtils.getWindow( this.document ),
  2810. sel = win.getSelection(),
  2811. txtNode;
  2812. browser.gecko ? this.document.body.focus() : win.focus();
  2813. if ( sel ) {
  2814. sel.removeAllRanges();
  2815. // trace:870 chrome/safari后边是br对于闭合得range不能定位 所以去掉了判断
  2816. // this.startContainer.nodeType != 3 &&! ((child = this.startContainer.childNodes[this.startOffset]) && child.nodeType == 1 && child.tagName == 'BR'
  2817. if ( this.collapsed && !notInsertFillData ){
  2818. txtNode = this.document.createTextNode( fillChar );
  2819. //跟着前边走
  2820. this.insertNode( txtNode );
  2821. removeFillData(this.document,txtNode);
  2822. mergSibling(txtNode,'previousSibling');
  2823. mergSibling(txtNode,'nextSibling');
  2824. fillData = txtNode;
  2825. this.setStart( txtNode, browser.webkit ? 1 : 0 ).collapse( true );
  2826. }
  2827. var nativeRange = this.document.createRange();
  2828. nativeRange.setStart( this.startContainer, this.startOffset );
  2829. nativeRange.setEnd( this.endContainer, this.endOffset );
  2830. sel.addRange( nativeRange );
  2831. }
  2832. return this;
  2833. },
  2834. /**
  2835. * 滚动到可视范围
  2836. * @public
  2837. * @function
  2838. * @name baidu.editor.dom.Range.scrollToView
  2839. * @param {Boolean} win 操作的window对象,若为空,则使用当前的window对象
  2840. * @param {Number} offset 滚动的偏移量
  2841. * @return {Range} Range对象
  2842. */
  2843. scrollToView : function(win,offset){
  2844. win = win ? window : domUtils.getWindow(this.document);
  2845. var span = this.document.createElement('span');
  2846. //trace:717
  2847. span.innerHTML = '&nbsp;';
  2848. var tmpRange = this.cloneRange();
  2849. tmpRange.insertNode(span);
  2850. domUtils.scrollToView(span,win,offset);
  2851. domUtils.remove(span);
  2852. return this;
  2853. }
  2854. };
  2855. })();
  2856. ///import editor.js
  2857. ///import core/browser.js
  2858. ///import core/dom/dom.js
  2859. ///import core/dom/dtd.js
  2860. ///import core/dom/domUtils.js
  2861. ///import core/dom/Range.js
  2862. /**
  2863. * @class baidu.editor.dom.Selection Selection类
  2864. */
  2865. (function () {
  2866. function getBoundaryInformation( range, start ) {
  2867. var getIndex = domUtils.getNodeIndex;
  2868. range = range.duplicate();
  2869. range.collapse( start );
  2870. var parent = range.parentElement();
  2871. //如果节点里没有子节点,直接退出
  2872. if ( !parent.hasChildNodes() ) {
  2873. return {container:parent,offset:0};
  2874. }
  2875. var siblings = parent.children,
  2876. child,
  2877. testRange = range.duplicate(),
  2878. startIndex = 0,endIndex = siblings.length - 1,index = -1,
  2879. distance;
  2880. while ( startIndex <= endIndex ) {
  2881. index = Math.floor( (startIndex + endIndex) / 2 );
  2882. child = siblings[index];
  2883. testRange.moveToElementText( child );
  2884. var position = testRange.compareEndPoints( 'StartToStart', range );
  2885. if ( position > 0 ) {
  2886. endIndex = index - 1;
  2887. } else if ( position < 0 ) {
  2888. startIndex = index + 1;
  2889. } else {
  2890. //trace:1043
  2891. return {container:parent,offset:getIndex( child )};
  2892. }
  2893. }
  2894. if ( index == -1 ) {
  2895. testRange.moveToElementText( parent );
  2896. testRange.setEndPoint( 'StartToStart', range );
  2897. distance = testRange.text.replace( /(\r\n|\r)/g, '\n' ).length;
  2898. siblings = parent.childNodes;
  2899. if ( !distance ) {
  2900. child = siblings[siblings.length - 1];
  2901. return {container:child,offset:child.nodeValue.length};
  2902. }
  2903. var i = siblings.length;
  2904. while ( distance > 0 )
  2905. distance -= siblings[ --i ].nodeValue.length;
  2906. return {container:siblings[i],offset:-distance}
  2907. }
  2908. testRange.collapse( position > 0 );
  2909. testRange.setEndPoint( position > 0 ? 'StartToStart' : 'EndToStart', range );
  2910. distance = testRange.text.replace( /(\r\n|\r)/g, '\n' ).length;
  2911. if ( !distance ) {
  2912. return dtd.$empty[child.tagName] || dtd.$nonChild[child.tagName]?
  2913. {container : parent,offset:getIndex( child ) + (position > 0 ? 0 : 1)} :
  2914. {container : child,offset: position > 0 ? 0 : child.childNodes.length}
  2915. }
  2916. while ( distance > 0 ) {
  2917. try{
  2918. var pre = child;
  2919. child = child[position > 0 ? 'previousSibling' : 'nextSibling'];
  2920. distance -= child.nodeValue.length;
  2921. }catch(e){
  2922. return {container:parent,offset:getIndex(pre)};
  2923. }
  2924. }
  2925. return {container:child,offset:position > 0 ? -distance : child.nodeValue.length + distance}
  2926. }
  2927. /**
  2928. * 将ieRange转换为Range对象
  2929. * @param {Range} ieRange ieRange对象
  2930. * @param {Range} range Range对象
  2931. * @return {Range} range 返回转换后的Range对象
  2932. */
  2933. function transformIERangeToRange( ieRange, range ) {
  2934. if ( ieRange.item ) {
  2935. range.selectNode( ieRange.item( 0 ) );
  2936. } else {
  2937. var bi = getBoundaryInformation( ieRange, true );
  2938. range.setStart( bi.container, bi.offset );
  2939. if ( ieRange.compareEndPoints( 'StartToEnd',ieRange ) != 0 ) {
  2940. bi = getBoundaryInformation( ieRange, false );
  2941. range.setEnd( bi.container, bi.offset );
  2942. }
  2943. }
  2944. return range;
  2945. }
  2946. /**
  2947. * 获得ieRange
  2948. * @param {Selection} sel Selection对象
  2949. * @return {ieRange} 得到ieRange
  2950. */
  2951. function _getIERange(sel){
  2952. var ieRange;
  2953. //ie下有可能报错
  2954. try{
  2955. ieRange = sel.getNative().createRange();
  2956. }catch(e){
  2957. return null;
  2958. }
  2959. var el = ieRange.item ? ieRange.item( 0 ) : ieRange.parentElement();
  2960. if ( ( el.ownerDocument || el ) === sel.document ) {
  2961. return ieRange;
  2962. }
  2963. return null;
  2964. }
  2965. var Selection = dom.Selection = function ( doc ) {
  2966. var me = this, iframe;
  2967. me.document = doc;
  2968. if ( ie ) {
  2969. iframe = domUtils.getWindow(doc).frameElement;
  2970. domUtils.on( iframe, 'beforedeactivate', function () {
  2971. me._bakIERange = me.getIERange();
  2972. } );
  2973. domUtils.on( iframe, 'activate', function () {
  2974. try {
  2975. if ( !_getIERange(me) && me._bakIERange ) {
  2976. me._bakIERange.select();
  2977. }
  2978. } catch ( ex ) {
  2979. }
  2980. me._bakIERange = null;
  2981. } );
  2982. }
  2983. iframe = doc = null;
  2984. };
  2985. Selection.prototype = {
  2986. /**
  2987. * 获取原生seleciton对象
  2988. * @public
  2989. * @function
  2990. * @name baidu.editor.dom.Selection.getNative
  2991. * @return {Selection} 获得selection对象
  2992. */
  2993. getNative : function () {
  2994. var doc = this.document;
  2995. try{
  2996. return !doc ? null : ie ? doc.selection : domUtils.getWindow( doc ).getSelection();
  2997. }catch(e){
  2998. return null;
  2999. }
  3000. },
  3001. /**
  3002. * 获得ieRange
  3003. * @public
  3004. * @function
  3005. * @name baidu.editor.dom.Selection.getIERange
  3006. * @return {ieRange} 返回ie原生的Range
  3007. */
  3008. getIERange : function () {
  3009. var ieRange = _getIERange(this);
  3010. if ( !ieRange ) {
  3011. if ( this._bakIERange ) {
  3012. return this._bakIERange;
  3013. }
  3014. }
  3015. return ieRange;
  3016. },
  3017. /**
  3018. * 缓存当前选区的range和选区的开始节点
  3019. * @public
  3020. * @function
  3021. * @name baidu.editor.dom.Selection.cache
  3022. */
  3023. cache : function () {
  3024. this.clear();
  3025. this._cachedRange = this.getRange();
  3026. this._cachedStartElement = this.getStart();
  3027. this._cachedStartElementPath = this.getStartElementPath();
  3028. },
  3029. getStartElementPath : function(){
  3030. if(this._cachedStartElementPath){
  3031. return this._cachedStartElementPath;
  3032. }
  3033. var start = this.getStart();
  3034. if(start){
  3035. return domUtils.findParents(start,true,null,true)
  3036. }
  3037. return [];
  3038. },
  3039. /**
  3040. * 清空缓存
  3041. * @public
  3042. * @function
  3043. * @name baidu.editor.dom.Selection.clear
  3044. */
  3045. clear : function () {
  3046. this._cachedStartElementPath = this._cachedRange = this._cachedStartElement = null;
  3047. },
  3048. /**
  3049. * 编辑器是否得到了选区
  3050. */
  3051. isFocus : function(){
  3052. try{
  3053. return browser.ie && _getIERange(this) || !browser.ie && this.getNative().rangeCount ? true : false;
  3054. }catch(e){
  3055. return false;
  3056. }
  3057. },
  3058. /**
  3059. * 获取选区对应的Range
  3060. * @public
  3061. * @function
  3062. * @name baidu.editor.dom.Selection.getRange
  3063. * @returns {baidu.editor.dom.Range} 得到Range对象
  3064. */
  3065. getRange : function () {
  3066. var me = this;
  3067. function optimze(range){
  3068. var child = me.document.body.firstChild,
  3069. collapsed = range.collapsed;
  3070. while(child && child.firstChild){
  3071. range.setStart(child,0);
  3072. child = child.firstChild;
  3073. }
  3074. if(!range.startContainer){
  3075. range.setStart(me.document.body,0)
  3076. }
  3077. if(collapsed){
  3078. range.collapse(true);
  3079. }
  3080. }
  3081. if ( me._cachedRange != null ) {
  3082. return this._cachedRange;
  3083. }
  3084. var range = new baidu.editor.dom.Range( me.document );
  3085. if ( ie ) {
  3086. var nativeRange = me.getIERange();
  3087. if(nativeRange){
  3088. transformIERangeToRange( nativeRange, range );
  3089. }else{
  3090. optimze(range)
  3091. }
  3092. } else {
  3093. var sel = me.getNative();
  3094. if ( sel && sel.rangeCount ) {
  3095. var firstRange = sel.getRangeAt( 0 ) ;
  3096. var lastRange = sel.getRangeAt( sel.rangeCount - 1 );
  3097. range.setStart( firstRange.startContainer, firstRange.startOffset ).setEnd( lastRange.endContainer, lastRange.endOffset );
  3098. if(range.collapsed && domUtils.isBody(range.startContainer) && !range.startOffset){
  3099. optimze(range)
  3100. }
  3101. } else {
  3102. //trace:1734 有可能已经不在dom树上了,标识的节点
  3103. if(this._bakRange && domUtils.inDoc(this._bakRange.startContainer,this.document))
  3104. return this._bakRange;
  3105. optimze(range)
  3106. }
  3107. }
  3108. return this._bakRange = range;
  3109. },
  3110. /**
  3111. * 获取开始元素,用于状态反射
  3112. * @public
  3113. * @function
  3114. * @name baidu.editor.dom.Selection.getStart
  3115. * @return {Element} 获得开始元素
  3116. */
  3117. getStart : function () {
  3118. if ( this._cachedStartElement ) {
  3119. return this._cachedStartElement;
  3120. }
  3121. var range = ie ? this.getIERange() : this.getRange(),
  3122. tmpRange,
  3123. start,tmp,parent;
  3124. if (ie) {
  3125. if(!range){
  3126. //todo 给第一个值可能会有问题
  3127. return this.document.body.firstChild;
  3128. }
  3129. //control元素
  3130. if (range.item)
  3131. return range.item(0);
  3132. tmpRange = range.duplicate();
  3133. //修正ie下<b>x</b>[xx] 闭合后 <b>x|</b>xx
  3134. tmpRange.text.length > 0 && tmpRange.moveStart('character',1);
  3135. tmpRange.collapse(1);
  3136. start = tmpRange.parentElement();
  3137. parent = tmp = range.parentElement();
  3138. while (tmp = tmp.parentNode) {
  3139. if (tmp == start) {
  3140. start = parent;
  3141. break;
  3142. }
  3143. }
  3144. } else {
  3145. range.shrinkBoundary();
  3146. start = range.startContainer;
  3147. if (start.nodeType == 1 && start.hasChildNodes())
  3148. start = start.childNodes[Math.min(start.childNodes.length - 1, range.startOffset)];
  3149. if (start.nodeType == 3)
  3150. return start.parentNode;
  3151. }
  3152. return start;
  3153. },
  3154. /**
  3155. * 得到选区中的文本
  3156. * @public
  3157. * @function
  3158. * @name baidu.editor.dom.Selection.getText
  3159. * @return {String} 选区中包含的文本
  3160. */
  3161. getText : function(){
  3162. var nativeSel,nativeRange;
  3163. if(this.isFocus() && (nativeSel = this.getNative())){
  3164. nativeRange = browser.ie ? nativeSel.createRange() : nativeSel.getRangeAt(0);
  3165. return browser.ie ? nativeRange.text : nativeRange.toString();
  3166. }
  3167. return '';
  3168. }
  3169. };
  3170. })();
  3171. ///import editor.js
  3172. ///import core/utils.js
  3173. ///import core/EventBase.js
  3174. ///import core/browser.js
  3175. ///import core/dom/dom.js
  3176. ///import core/dom/domUtils.js
  3177. ///import core/dom/Selection.js
  3178. ///import core/dom/dtd.js
  3179. (function () {
  3180. var uid = 0,
  3181. _selectionChangeTimer;
  3182. function replaceSrc(div){
  3183. var imgs = div.getElementsByTagName("img"),
  3184. orgSrc;
  3185. for(var i=0,img;img = imgs[i++];){
  3186. if(orgSrc = img.getAttribute("orgSrc")){
  3187. img.src = orgSrc;
  3188. img.removeAttribute("orgSrc");
  3189. }
  3190. }
  3191. var as = div.getElementsByTagName("a");
  3192. for(var i=0,ai;ai=as[i++];i++){
  3193. if(ai.getAttribute('data_ue_src')){
  3194. ai.setAttribute('href',ai.getAttribute('data_ue_src'))
  3195. }
  3196. }
  3197. }
  3198. function setValue(form,editor){
  3199. var textarea;
  3200. if(editor.textarea){
  3201. if(utils.isString(editor.textarea)){
  3202. for(var i= 0,ti,tis=domUtils.getElementsByTagName(form,'textarea');ti=tis[i++];){
  3203. if(ti.id == 'ueditor_textarea_' + editor.options.textarea){
  3204. textarea = ti;
  3205. break;
  3206. }
  3207. }
  3208. }else{
  3209. textarea = editor.textarea;
  3210. }
  3211. }
  3212. if(!textarea){
  3213. form.appendChild(textarea = domUtils.creElm(document,'textarea',{
  3214. 'name' : editor.options.textarea,
  3215. 'id' : 'ueditor_textarea_' + editor.options.textarea,
  3216. 'style' : "display:none"
  3217. }));
  3218. }
  3219. textarea.value = editor.getContent()
  3220. }
  3221. /**
  3222. * 编辑器类
  3223. * @public
  3224. * @class
  3225. * @extends baidu.editor.EventBase
  3226. * @name baidu.editor.Editor
  3227. * @param {Object} options
  3228. */
  3229. var Editor = UE.Editor = function( options ) {
  3230. var me = this;
  3231. me.uid = uid ++;
  3232. EventBase.call( me );
  3233. me.commands = {};
  3234. me.options = utils.extend( options || {},
  3235. UEDITOR_CONFIG, true );
  3236. //设置默认的常用属性
  3237. me.setOpt({
  3238. isShow : true,
  3239. initialContent:'欢迎使用ueditor!',
  3240. autoClearinitialContent:false,
  3241. iframeCssUrl: me.options.UEDITOR_HOME_URL + '/themes/default/iframe.css',
  3242. textarea:'editorValue',
  3243. focus:false,
  3244. minFrameHeight:320,
  3245. autoClearEmptyNode : true,
  3246. fullscreen : false,
  3247. readonly : false,
  3248. zIndex : 999,
  3249. imagePopup:true,
  3250. enterTag:'p',
  3251. pageBreakTag : '_baidu_page_break_tag_'
  3252. });
  3253. //初始化插件
  3254. for ( var pi in UE.plugins ) {
  3255. UE.plugins[pi].call( me )
  3256. }
  3257. };
  3258. Editor.prototype = /**@lends baidu.editor.Editor.prototype*/{
  3259. setOpt : function(key,val){
  3260. var obj = {};
  3261. if(utils.isString(key)){
  3262. obj[key] = val
  3263. }else{
  3264. obj = key;
  3265. }
  3266. utils.extend(this.options,obj,true);
  3267. },
  3268. destroy : function(){
  3269. var me = this;
  3270. me.fireEvent('destroy');
  3271. me.container.innerHTML = '';
  3272. domUtils.remove(me.container);
  3273. //trace:2004
  3274. for(var p in me){
  3275. delete this[p]
  3276. }
  3277. },
  3278. /**
  3279. * 渲染编辑器的DOM到指定容器,必须且只能调用一次
  3280. * @public
  3281. * @function
  3282. * @param {Element|String} container
  3283. */
  3284. render : function ( container ) {
  3285. if (container.constructor === String) {
  3286. container = document.getElementById(container);
  3287. }
  3288. if(container){
  3289. container.innerHTML = '<iframe id="' + 'baidu_editor_' + this.uid + '"' + 'width="100%" height="100%" frameborder="0"></iframe>';
  3290. container.style.overflow = 'hidden';
  3291. this._setup( container.firstChild.contentWindow.document );
  3292. }
  3293. },
  3294. _setup: function ( doc ) {
  3295. var me = this, options = me.options;
  3296. //防止在chrome下连接后边带# 会跳动的问题
  3297. !browser.webkit && doc.open();
  3298. var useBodyAsViewport = ie && browser.version < 9;
  3299. doc.write( ( ie && browser.version < 9 ? '' : '<!DOCTYPE html>') +
  3300. '<html xmlns="http://www.w3.org/1999/xhtml"' + (!useBodyAsViewport ? ' class="view"' : '') + '><head>' +
  3301. ( options.iframeCssUrl ? '<link rel="stylesheet" type="text/css" href="' + utils.unhtml( options.iframeCssUrl ) + '"/>' : '' ) +
  3302. '<style id="editorinitialstyle" type="text/css">' +
  3303. //这些默认属性不能够让用户改变
  3304. //选中的td上的样式
  3305. '.selectTdClass{background-color:#3399FF !important;}' +
  3306. 'table.noBorderTable td{border:1px dashed #ddd !important}'+
  3307. //插入的表格的默认样式
  3308. 'table{clear:both;margin-bottom:10px;border-collapse:collapse;word-break:break-all;}' +
  3309. //分页符的样式
  3310. '.pagebreak{display:block;clear:both !important;cursor:default !important;width: 100% !important;margin:0;}' +
  3311. //锚点的样式,注意这里背景图的路径
  3312. '.anchorclass{background: url("' + me.options.UEDITOR_HOME_URL + 'themes/default/images/anchor.gif") no-repeat scroll left center transparent;border: 1px dotted #0000FF;cursor: auto;display: inline-block;height: 16px;width: 15px;}' +
  3313. //设置四周的留边
  3314. '.view{padding:0;word-wrap:break-word;cursor:text;height:100%;}\n' +
  3315. //设置默认字体和字号
  3316. 'body{margin:8px;font-family:"宋体";font-size:16px;}' +
  3317. //针对li的处理
  3318. 'li{clear:both}' +
  3319. //设置段落间距
  3320. 'p{margin:5px 0;}'
  3321. + ( options.initialStyle ||' ' ) +
  3322. '</style></head><body' + (useBodyAsViewport ? ' class="view"' : '') + '></body></html>' );
  3323. !browser.webkit && doc.close();
  3324. if ( ie ) {
  3325. doc.body.disabled = true;
  3326. doc.body.contentEditable = true;
  3327. doc.body.disabled = false;
  3328. } else {
  3329. doc.body.contentEditable = true;
  3330. doc.body.spellcheck = false;
  3331. }
  3332. me.document = doc;
  3333. me.window = doc.defaultView || doc.parentWindow;
  3334. me.iframe = me.window.frameElement;
  3335. me.body = doc.body;
  3336. //设置编辑器最小高度
  3337. me.setHeight(options.minFrameHeight);
  3338. me.selection = new dom.Selection( doc );
  3339. //gecko初始化就能得到range,无法判断isFocus了
  3340. if(browser.gecko){
  3341. this.selection.getNative().removeAllRanges();
  3342. }
  3343. this._initEvents();
  3344. if(options.initialContent){
  3345. if(options.autoClearinitialContent){
  3346. var oldExecCommand = me.execCommand;
  3347. me.execCommand = function(){
  3348. me.fireEvent('firstBeforeExecCommand');
  3349. oldExecCommand.apply(me,arguments)
  3350. };
  3351. this.setDefaultContent(options.initialContent);
  3352. }else
  3353. this.setContent(options.initialContent,true);
  3354. }
  3355. //为form提交提供一个隐藏的textarea
  3356. for(var form = this.iframe.parentNode;!domUtils.isBody(form);form = form.parentNode){
  3357. if(form.tagName == 'FORM'){
  3358. domUtils.on(form,'submit',function(){
  3359. setValue(this,me)
  3360. });
  3361. break;
  3362. }
  3363. }
  3364. //编辑器不能为空内容
  3365. if(domUtils.isEmptyNode(me.body)){
  3366. me.body.innerHTML = '<p>'+(browser.ie?'':'<br/>')+'</p>';
  3367. }
  3368. //如果要求focus, 就把光标定位到内容开始
  3369. if(options.focus){
  3370. setTimeout(function(){
  3371. me.focus();
  3372. //如果自动清除开着,就不需要做selectionchange;
  3373. !me.options.autoClearinitialContent && me._selectionChange()
  3374. });
  3375. }
  3376. if(!me.container){
  3377. me.container = this.iframe.parentNode;
  3378. }
  3379. if(options.fullscreen && me.ui){
  3380. me.ui.setFullScreen(true)
  3381. }
  3382. me.fireEvent( 'ready' );
  3383. if(!browser.ie){
  3384. domUtils.on(me.window,'blur',function(){
  3385. me._bakRange = me.selection.getRange();
  3386. me.selection.getNative().removeAllRanges();
  3387. });
  3388. }
  3389. //trace:1518 ff3.6body不够寛,会导致点击空白处无法获得焦点
  3390. if(browser.gecko && browser.version <= 10902){
  3391. //修复ff3.6初始化进来,不能点击获得焦点
  3392. me.body.contentEditable = false;
  3393. setTimeout(function(){
  3394. me.body.contentEditable = true;
  3395. },100);
  3396. setInterval(function(){
  3397. me.body.style.height = me.iframe.offsetHeight - 20 + 'px'
  3398. },100)
  3399. }
  3400. !options.isShow && me.setHide();
  3401. options.readonly && me.setDisabled();
  3402. },
  3403. /**
  3404. * 创建textarea,同步编辑的内容到textarea,为后台获取内容做准备
  3405. * @param formId 制定在那个form下添加
  3406. * @public
  3407. * @function
  3408. */
  3409. sync : function(formId){
  3410. var me = this,
  3411. form = formId ? document.getElementById(formId) :
  3412. domUtils.findParent(me.iframe.parentNode,function(node){return node.tagName == 'FORM'},true);
  3413. form && setValue(form,me);
  3414. },
  3415. /**
  3416. * 设置编辑器高度
  3417. * @public
  3418. * @function
  3419. * @param {Number} height 高度
  3420. */
  3421. setHeight: function (height){
  3422. if (height !== parseInt(this.iframe.parentNode.style.height)){
  3423. this.iframe.parentNode.style.height = height + 'px';
  3424. }
  3425. this.document.body.style.height = height - 20 + 'px'
  3426. },
  3427. /**
  3428. * 获取编辑器内容
  3429. * @public
  3430. * @function
  3431. * @returns {String}
  3432. */
  3433. getContent : function (cmd,fn) {
  3434. if( cmd && utils.isFunction(cmd)){
  3435. fn = cmd;
  3436. cmd = '';
  3437. }
  3438. if(fn ? !fn():!this.hasContents())
  3439. return '';
  3440. this.fireEvent( 'beforegetcontent',cmd );
  3441. var reg = new RegExp( domUtils.fillChar, 'g' ),
  3442. //ie下取得的html可能会有\n存在,要去掉,在处理replace(/[\t\r\n]*/g,'');代码高量的\n不能去除
  3443. html = this.body.innerHTML.replace(reg,'').replace(/>[\t\r\n]*?</g,'><');
  3444. this.fireEvent( 'aftergetcontent',cmd );
  3445. if (this.serialize) {
  3446. var node = this.serialize.parseHTML(html);
  3447. node = this.serialize.transformOutput(node);
  3448. html = this.serialize.toHTML(node);
  3449. }
  3450. //多个&nbsp;要转换成空格加&nbsp;的形式,要不预览时会所成一个
  3451. return html.replace(/(&nbsp;)+/g,function(s){
  3452. for(var i= 0,str = [],l= s.split(';').length-1;i<l;i++){
  3453. str.push(i%2 == 0?' ':'&nbsp;')
  3454. }
  3455. return str.join('');
  3456. })
  3457. },
  3458. /**
  3459. * 得到编辑器的纯文本内容,但会保留段落格式
  3460. * @public
  3461. * @function
  3462. * @returns {String}
  3463. */
  3464. getPlainTxt : function(){
  3465. var reg = new RegExp( domUtils.fillChar,'g' ),
  3466. html = this.body.innerHTML.replace(/[\n\r]/g,'');//ie要先去了\n在处理
  3467. html = html.replace(/<(p|div)[^>]*>(<br\/?>|&nbsp;)<\/\1>/gi,'\n')
  3468. .replace(/<br\/?>/gi,'\n')
  3469. .replace(/<[^>/]+>/g,'')
  3470. .replace(/(\n)?<\/([^>]+)>/g,function(a,b,c){
  3471. return dtd.$block[c] ? '\n' : b ? b : '';
  3472. });
  3473. //取出来的空格会有c2a0会变成乱码,处理这种情况\u00a0
  3474. return html.replace(reg,'').replace(/\u00a0/g,' ').replace(/&nbsp;/g,' ')
  3475. },
  3476. /**
  3477. * 获取编辑器中的文本内容
  3478. * @public
  3479. * @function
  3480. * @returns {String}
  3481. */
  3482. getContentTxt : function(){
  3483. var reg = new RegExp( domUtils.fillChar,'g' );
  3484. //取出来的空格会有c2a0会变成乱码,处理这种情况\u00a0
  3485. return this.body[browser.ie ? 'innerText':'textContent'].replace(reg,'').replace(/\u00a0/g,' ')
  3486. },
  3487. /**
  3488. * 设置编辑器内容
  3489. * @public
  3490. * @function
  3491. * @param {String} html
  3492. */
  3493. setContent : function ( html,notFireSelectionchange) {
  3494. var me = this,
  3495. inline = utils.extend({a:1,A:1},dtd.$inline,true),
  3496. lastTagName;
  3497. html = html
  3498. .replace(/^[ \t\r\n]*?</,'<')
  3499. .replace(/>[ \t\r\n]*?$/,'>')
  3500. .replace(/>[\t\r\n]*?</g,'><')//代码高量的\n不能去除
  3501. .replace(/[\s\/]?(\w+)?>[ \t\r\n]*?<\/?(\w+)/gi,function(a,b,c){
  3502. if(b){
  3503. lastTagName = c;
  3504. }else{
  3505. b = lastTagName
  3506. }
  3507. return !inline[b] && !inline[c] ? a.replace(/>[ \t\r\n]*?</,'><') : a;
  3508. });
  3509. me.fireEvent( 'beforesetcontent' );
  3510. var serialize = this.serialize;
  3511. if (serialize) {
  3512. var node = serialize.parseHTML(html);
  3513. node = serialize.transformInput(node);
  3514. node = serialize.filter(node);
  3515. html = serialize.toHTML(node);
  3516. }
  3517. //html.replace(new RegExp('[\t\n\r' + domUtils.fillChar + ']*','g'),'');
  3518. //去掉了\t\n\r 如果有插入的代码,在源码切换所见即所得模式时,换行都丢掉了
  3519. //\r在ie下的不可见字符,在源码切换时会变成多个&nbsp;
  3520. //trace:1559
  3521. this.body.innerHTML = html.replace(new RegExp('[\r' + domUtils.fillChar + ']*','g'),'');
  3522. //处理ie6下innerHTML自动将相对路径转化成绝对路径的问题
  3523. if(browser.ie && browser.version < 7 ){
  3524. replaceSrc(this.document.body);
  3525. }
  3526. //给文本或者inline节点套p标签
  3527. if(me.options.enterTag == 'p'){
  3528. var child = this.body.firstChild,tmpNode;
  3529. if(!child || child.nodeType == 1 &&
  3530. (dtd.$cdata[child.tagName] ||
  3531. domUtils.isCustomeNode(child)
  3532. )
  3533. && child === this.body.lastChild){
  3534. this.body.innerHTML = '<p>'+(browser.ie ? '' :'<br/>')+'</p>' + this.body.innerHTML;
  3535. }else{
  3536. var p = me.document.createElement('p');
  3537. while(child){
  3538. while(child && (child.nodeType ==3 || child.nodeType == 1 && dtd.p[child.tagName] && !dtd.$cdata[child.tagName])){
  3539. tmpNode = child.nextSibling;
  3540. p.appendChild(child);
  3541. child = tmpNode;
  3542. }
  3543. if(p.firstChild){
  3544. if(!child){
  3545. me.body.appendChild(p);
  3546. break;
  3547. }else{
  3548. me.body.insertBefore(p,child);
  3549. p = me.document.createElement('p');
  3550. }
  3551. }
  3552. child = child.nextSibling;
  3553. }
  3554. }
  3555. }
  3556. me.adjustTable && me.adjustTable(me.body);
  3557. me.fireEvent( 'aftersetcontent' );
  3558. me.fireEvent( 'contentchange' );
  3559. !notFireSelectionchange && me._selectionChange();
  3560. //清除保存的选区
  3561. me._bakRange = me._bakIERange = null;
  3562. //trace:1742 setContent后gecko能得到焦点问题
  3563. if(browser.gecko){
  3564. me.selection.getNative().removeAllRanges();
  3565. }
  3566. },
  3567. /**
  3568. * 让编辑器获得焦点
  3569. * @public
  3570. * @function
  3571. */
  3572. focus : function () {
  3573. try{
  3574. this.selection.getRange().select(true);
  3575. }catch(e){}
  3576. },
  3577. /**
  3578. * 初始化事件,绑定selectionchange
  3579. * @private
  3580. * @function
  3581. */
  3582. _initEvents : function () {
  3583. var me = this,
  3584. doc = me.document,
  3585. win = me.window;
  3586. me._proxyDomEvent = utils.bind( me._proxyDomEvent, me );
  3587. domUtils.on( doc, ['click', 'contextmenu','mousedown','keydown', 'keyup','keypress', 'mouseup', 'mouseover', 'mouseout', 'selectstart'], me._proxyDomEvent );
  3588. domUtils.on( win, ['focus', 'blur'], me._proxyDomEvent );
  3589. domUtils.on( doc, ['mouseup','keydown'], function(evt){
  3590. //特殊键不触发selectionchange
  3591. if(evt.type == 'keydown' && (evt.ctrlKey || evt.metaKey || evt.shiftKey || evt.altKey)){
  3592. return;
  3593. }
  3594. if(evt.button == 2)return;
  3595. me._selectionChange(250, evt );
  3596. });
  3597. //处理拖拽
  3598. //ie ff不能从外边拖入
  3599. //chrome只针对从外边拖入的内容过滤
  3600. var innerDrag = 0,source = browser.ie ? me.body : me.document,dragoverHandler;
  3601. domUtils.on(source,'dragstart',function(){
  3602. innerDrag = 1;
  3603. });
  3604. domUtils.on(source,browser.webkit ? 'dragover' : 'drop',function(){
  3605. return browser.webkit ?
  3606. function(){
  3607. clearTimeout( dragoverHandler );
  3608. dragoverHandler = setTimeout( function(){
  3609. if(!innerDrag){
  3610. var sel = me.selection,
  3611. range = sel.getRange();
  3612. if(range){
  3613. var common = range.getCommonAncestor();
  3614. if(common && me.serialize){
  3615. var f = me.serialize,
  3616. node =
  3617. f.filter(
  3618. f.transformInput(
  3619. f.parseHTML(
  3620. f.word(common.innerHTML)
  3621. )
  3622. )
  3623. );
  3624. common.innerHTML = f.toHTML(node)
  3625. }
  3626. }
  3627. }
  3628. innerDrag = 0;
  3629. }, 200 );
  3630. } :
  3631. function(e){
  3632. if(!innerDrag){
  3633. e.preventDefault ? e.preventDefault() :(e.returnValue = false) ;
  3634. }
  3635. innerDrag = 0;
  3636. }
  3637. }());
  3638. },
  3639. _proxyDomEvent: function ( evt ) {
  3640. return this.fireEvent( evt.type.replace( /^on/, '' ), evt );
  3641. },
  3642. _selectionChange : function ( delay, evt ) {
  3643. var me = this;
  3644. //有光标才做selectionchange
  3645. if(!me.selection.isFocus())
  3646. return;
  3647. var hackForMouseUp = false;
  3648. var mouseX, mouseY;
  3649. if (browser.ie && browser.version < 9 && evt && evt.type == 'mouseup') {
  3650. var range = this.selection.getRange();
  3651. if (!range.collapsed) {
  3652. hackForMouseUp = true;
  3653. mouseX = evt.clientX;
  3654. mouseY = evt.clientY;
  3655. }
  3656. }
  3657. clearTimeout(_selectionChangeTimer);
  3658. _selectionChangeTimer = setTimeout(function(){
  3659. if(!me.selection.getNative()){
  3660. return;
  3661. }
  3662. //修复一个IE下的bug: 鼠标点击一段已选择的文本中间时,可能在mouseup后的一段时间内取到的range是在selection的type为None下的错误值.
  3663. //IE下如果用户是拖拽一段已选择文本,则不会触发mouseup事件,所以这里的特殊处理不会对其有影响
  3664. var ieRange;
  3665. if (hackForMouseUp && me.selection.getNative().type == 'None' ) {
  3666. ieRange = me.document.body.createTextRange();
  3667. try {
  3668. ieRange.moveToPoint( mouseX, mouseY );
  3669. } catch(ex){
  3670. ieRange = null;
  3671. }
  3672. }
  3673. var bakGetIERange;
  3674. if (ieRange) {
  3675. bakGetIERange = me.selection.getIERange;
  3676. me.selection.getIERange = function (){
  3677. return ieRange;
  3678. };
  3679. }
  3680. me.selection.cache();
  3681. if (bakGetIERange) {
  3682. me.selection.getIERange = bakGetIERange;
  3683. }
  3684. if ( me.selection._cachedRange && me.selection._cachedStartElement ) {
  3685. me.fireEvent( 'beforeselectionchange' );
  3686. // 第二个参数causeByUi为true代表由用户交互造成的selectionchange.
  3687. me.fireEvent( 'selectionchange', !!evt );
  3688. me.fireEvent('afterselectionchange');
  3689. me.selection.clear();
  3690. }
  3691. }, delay || 50);
  3692. },
  3693. _callCmdFn: function ( fnName, args ) {
  3694. var cmdName = args[0].toLowerCase(),
  3695. cmd, cmdFn;
  3696. cmd = this.commands[cmdName] || UE.commands[cmdName];
  3697. cmdFn = cmd && cmd[fnName];
  3698. //没有querycommandstate或者没有command的都默认返回0
  3699. if ( (!cmd || !cmdFn) && fnName == 'queryCommandState' ) {
  3700. return 0;
  3701. } else if ( cmdFn ) {
  3702. return cmdFn.apply( this, args );
  3703. }
  3704. },
  3705. /**
  3706. * 执行命令
  3707. * @public
  3708. * @function
  3709. * @param {String} cmdName 执行的命令名
  3710. *
  3711. */
  3712. execCommand : function ( cmdName ) {
  3713. cmdName = cmdName.toLowerCase();
  3714. var me = this,
  3715. result,
  3716. cmd = me.commands[cmdName] || UE.commands[cmdName];
  3717. if ( !cmd || !cmd.execCommand ) {
  3718. return;
  3719. }
  3720. if ( !cmd.notNeedUndo && !me.__hasEnterExecCommand ) {
  3721. me.__hasEnterExecCommand = true;
  3722. if(me.queryCommandState(cmdName) !=-1){
  3723. me.fireEvent( 'beforeexeccommand', cmdName );
  3724. result = this._callCmdFn( 'execCommand', arguments );
  3725. me.fireEvent( 'afterexeccommand', cmdName );
  3726. }
  3727. me.__hasEnterExecCommand = false;
  3728. } else {
  3729. result = this._callCmdFn( 'execCommand', arguments );
  3730. }
  3731. me._selectionChange();
  3732. return result;
  3733. },
  3734. /**
  3735. * 查询命令的状态
  3736. * @public
  3737. * @function
  3738. * @param {String} cmdName 执行的命令名
  3739. * @returns {Number|*} -1 : disabled, false : normal, true : enabled.
  3740. *
  3741. */
  3742. queryCommandState : function ( cmdName ) {
  3743. return this._callCmdFn( 'queryCommandState', arguments );
  3744. },
  3745. /**
  3746. * 查询命令的值
  3747. * @public
  3748. * @function
  3749. * @param {String} cmdName 执行的命令名
  3750. * @returns {*}
  3751. */
  3752. queryCommandValue : function ( cmdName ) {
  3753. return this._callCmdFn( 'queryCommandValue', arguments );
  3754. },
  3755. /**
  3756. * 检查编辑区域中是否有内容
  3757. * @public
  3758. * @params{Array} 自定义的标签
  3759. * @function
  3760. * @returns {Boolean} true 有,false 没有
  3761. */
  3762. hasContents : function(tags){
  3763. if(tags){
  3764. for(var i=0,ci;ci=tags[i++];){
  3765. if(this.document.getElementsByTagName(ci).length > 0)
  3766. return true;
  3767. }
  3768. }
  3769. if(!domUtils.isEmptyBlock(this.body)){
  3770. return true
  3771. }
  3772. //随时添加,定义的特殊标签如果存在,不能认为是空
  3773. tags = ['div'];
  3774. for(i= 0;ci=tags[i++];){
  3775. var nodes = domUtils.getElementsByTagName(this.document,ci);
  3776. for(var n= 0,cn;cn=nodes[n++];){
  3777. if(domUtils.isCustomeNode(cn)){
  3778. return true;
  3779. }
  3780. }
  3781. }
  3782. return false;
  3783. },
  3784. /**
  3785. * 从新设置
  3786. * @public
  3787. * @function
  3788. */
  3789. reset : function(){
  3790. this.fireEvent('reset');
  3791. },
  3792. /**
  3793. * 设置编辑区域可以编辑
  3794. */
  3795. setEnabled : function(){
  3796. var me = this,range;
  3797. if(me.body.contentEditable == 'false'){
  3798. me.body.contentEditable = true;
  3799. range = me.selection.getRange();
  3800. //有可能内容丢失了
  3801. try{
  3802. range.moveToBookmark(me.lastBk);
  3803. delete me.lastBk
  3804. }catch(e){
  3805. range.setStartAtFirst(me.body).collapse(true)
  3806. }
  3807. range.select(true);
  3808. if(me.bkqueryCommandState){
  3809. me.queryCommandState = me.bkqueryCommandState;
  3810. delete me.bkqueryCommandState;
  3811. }
  3812. me.fireEvent( 'selectionchange');
  3813. }
  3814. },
  3815. /**
  3816. * 设置编辑区域不可以编辑
  3817. */
  3818. setDisabled : function(exclude){
  3819. var me = this;
  3820. exclude = exclude ? utils.isArray(exclude) ? exclude : [exclude] : [];
  3821. if(me.body.contentEditable == 'true'){
  3822. if(!me.lastBk){
  3823. me.lastBk = me.selection.getRange().createBookmark(true);
  3824. }
  3825. me.body.contentEditable = false;
  3826. me.bkqueryCommandState = me.queryCommandState;
  3827. me.queryCommandState =function(type){
  3828. if(utils.indexOf(exclude,type)!=-1){
  3829. return me.bkqueryCommandState.apply(me,arguments)
  3830. }
  3831. return -1;
  3832. };
  3833. me.fireEvent( 'selectionchange');
  3834. }
  3835. },
  3836. /**
  3837. * 设置默认内容
  3838. * @function
  3839. * @param {String} cont 要存入的内容
  3840. */
  3841. setDefaultContent : function(){
  3842. function clear(){
  3843. var me = this;
  3844. if(me.document.getElementById('initContent')){
  3845. me.document.body.innerHTML = '<p>'+(ie ? '' : '<br/>')+'</p>';
  3846. var range = me.selection.getRange();
  3847. me.removeListener('firstBeforeExecCommand',clear);
  3848. me.removeListener('focus',clear);
  3849. setTimeout(function(){
  3850. range.setStart(me.document.body.firstChild,0).collapse(true).select(true);
  3851. me._selectionChange();
  3852. })
  3853. }
  3854. }
  3855. return function (cont){
  3856. var me = this;
  3857. me.document.body.innerHTML = '<p id="initContent">'+cont+'</p>';
  3858. if(browser.ie && browser.version < 7){
  3859. replaceSrc(me.document.body);
  3860. }
  3861. me.addListener('firstBeforeExecCommand',clear);
  3862. me.addListener('focus',clear);
  3863. }
  3864. }(),
  3865. /**
  3866. * 设置编辑器显示
  3867. * @function
  3868. */
  3869. setShow : function(){
  3870. var me = this,
  3871. range = me.selection.getRange();
  3872. if(me.container.style.display == 'none'){
  3873. //有可能内容丢失了
  3874. try{
  3875. range.moveToBookmark(me.lastBk);
  3876. delete me.lastBk
  3877. }catch(e){
  3878. range.setStartAtFirst(me.body).collapse(true)
  3879. }
  3880. range.select(true);
  3881. me.container.style.display = '';
  3882. }
  3883. },
  3884. /**
  3885. * 设置编辑器隐藏
  3886. * @function
  3887. */
  3888. setHide : function(){
  3889. var me = this;
  3890. if(!me.lastBk){
  3891. me.lastBk = me.selection.getRange().createBookmark(true);
  3892. }
  3893. me.container.style.display = 'none'
  3894. }
  3895. };
  3896. utils.inherits( Editor, EventBase );
  3897. })();
  3898. /**
  3899. * Created by .
  3900. * User: taoqili
  3901. * Date: 11-8-18
  3902. * Time: 下午3:18
  3903. * To change this template use File | Settings | File Templates.
  3904. */
  3905. /**
  3906. * ajax工具类
  3907. */
  3908. UE.ajax = function() {
  3909. return {
  3910. /**
  3911. * 向url发送ajax请求
  3912. * @param url
  3913. * @param ajaxOptions
  3914. */
  3915. request:function(url, ajaxOptions) {
  3916. var ajaxRequest = creatAjaxRequest(),
  3917. //是否超时
  3918. timeIsOut = false,
  3919. //默认参数
  3920. defaultAjaxOptions = {
  3921. method:"POST",
  3922. timeout:5000,
  3923. async:true,
  3924. data:{},//需要传递对象的话只能覆盖
  3925. onsuccess:function() {
  3926. },
  3927. onerror:function() {
  3928. }
  3929. };
  3930. if (typeof url === "object") {
  3931. ajaxOptions = url;
  3932. url = ajaxOptions.url;
  3933. }
  3934. if (!ajaxRequest || !url) return;
  3935. var ajaxOpts = ajaxOptions ? utils.extend(defaultAjaxOptions,ajaxOptions) : defaultAjaxOptions;
  3936. var submitStr = json2str(ajaxOpts); // { name:"Jim",city:"Beijing" } --> "name=Jim&city=Beijing"
  3937. //如果用户直接通过data参数传递json对象过来,则也要将此json对象转化为字符串
  3938. if (!utils.isEmptyObject(ajaxOpts.data)){
  3939. submitStr += (submitStr? "&":"") + json2str(ajaxOpts.data);
  3940. }
  3941. //超时检测
  3942. var timerID = setTimeout(function() {
  3943. if (ajaxRequest.readyState != 4) {
  3944. timeIsOut = true;
  3945. ajaxRequest.abort();
  3946. clearTimeout(timerID);
  3947. }
  3948. }, ajaxOpts.timeout);
  3949. var method = ajaxOpts.method.toUpperCase();
  3950. var str = url + (url.indexOf("?")==-1?"?":"&") + (method=="POST"?"":submitStr+ "&noCache=" + +new Date);
  3951. ajaxRequest.open(method, str, ajaxOpts.async);
  3952. ajaxRequest.onreadystatechange = function() {
  3953. if (ajaxRequest.readyState == 4) {
  3954. if (!timeIsOut && ajaxRequest.status == 200) {
  3955. ajaxOpts.onsuccess(ajaxRequest);
  3956. } else {
  3957. ajaxOpts.onerror(ajaxRequest);
  3958. }
  3959. }
  3960. };
  3961. if (method == "POST") {
  3962. ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  3963. ajaxRequest.send(submitStr);
  3964. } else {
  3965. ajaxRequest.send(null);
  3966. }
  3967. }
  3968. };
  3969. /**
  3970. * 将json参数转化成适合ajax提交的参数列表
  3971. * @param json
  3972. */
  3973. function json2str(json) {
  3974. var strArr = [];
  3975. for (var i in json) {
  3976. //忽略默认的几个参数
  3977. if(i=="method" || i=="timeout" || i=="async") continue;
  3978. //传递过来的对象和函数不在提交之列
  3979. if (!((typeof json[i]).toLowerCase() == "function" || (typeof json[i]).toLowerCase() == "object")) {
  3980. strArr.push( encodeURIComponent(i) + "="+encodeURIComponent(json[i]) );
  3981. }
  3982. }
  3983. return strArr.join("&");
  3984. }
  3985. /**
  3986. * 创建一个ajaxRequest对象
  3987. */
  3988. function creatAjaxRequest() {
  3989. var xmlHttp = null;
  3990. if (window.XMLHttpRequest) {
  3991. xmlHttp = new XMLHttpRequest();
  3992. } else {
  3993. try {
  3994. xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  3995. } catch (e) {
  3996. try {
  3997. xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  3998. } catch (e) {
  3999. }
  4000. }
  4001. }
  4002. return xmlHttp;
  4003. }
  4004. }();
  4005. ///import core
  4006. /**
  4007. * @description 插入内容
  4008. * @name baidu.editor.execCommand
  4009. * @param {String} cmdName inserthtml插入内容的命令
  4010. * @param {String} html 要插入的内容
  4011. * @author zhanyi
  4012. */
  4013. UE.commands['inserthtml'] = {
  4014. execCommand: function (command,html,notSerialize){
  4015. var me = this,
  4016. range,
  4017. div,
  4018. tds = me.currentSelectedArr;
  4019. range = me.selection.getRange();
  4020. div = range.document.createElement( 'div' );
  4021. div.style.display = 'inline';
  4022. var serialize = me.serialize;
  4023. if (!notSerialize && serialize) {
  4024. var node = serialize.parseHTML(html);
  4025. node = serialize.transformInput(node);
  4026. node = serialize.filter(node);
  4027. html = serialize.toHTML(node);
  4028. }
  4029. div.innerHTML = utils.trim( html );
  4030. try{
  4031. me.adjustTable && me.adjustTable(div);
  4032. }catch(e){}
  4033. if(tds && tds.length){
  4034. for(var i=0,ti;ti=tds[i++];){
  4035. ti.className = ''
  4036. }
  4037. tds[0].innerHTML = '';
  4038. range.setStart(tds[0],0).collapse(true);
  4039. me.currentSelectedArr = [];
  4040. }
  4041. if ( !range.collapsed ) {
  4042. range.deleteContents();
  4043. if(range.startContainer.nodeType == 1){
  4044. var child = range.startContainer.childNodes[range.startOffset],pre;
  4045. if(child && domUtils.isBlockElm(child) && (pre = child.previousSibling) && domUtils.isBlockElm(pre)){
  4046. range.setEnd(pre,pre.childNodes.length).collapse();
  4047. while(child.firstChild){
  4048. pre.appendChild(child.firstChild);
  4049. }
  4050. domUtils.remove(child);
  4051. }
  4052. }
  4053. }
  4054. var child,parent,pre,tmp,hadBreak = 0;
  4055. while ( child = div.firstChild ) {
  4056. range.insertNode( child );
  4057. if ( !hadBreak && child.nodeType == domUtils.NODE_ELEMENT && domUtils.isBlockElm( child ) ){
  4058. parent = domUtils.findParent( child,function ( node ){ return domUtils.isBlockElm( node ); } );
  4059. if ( parent && parent.tagName.toLowerCase() != 'body' && !(dtd[parent.tagName][child.nodeName] && child.parentNode === parent)){
  4060. if(!dtd[parent.tagName][child.nodeName]){
  4061. pre = parent;
  4062. }else{
  4063. tmp = child.parentNode;
  4064. while (tmp !== parent){
  4065. pre = tmp;
  4066. tmp = tmp.parentNode;
  4067. }
  4068. }
  4069. domUtils.breakParent( child, pre || tmp );
  4070. //去掉break后前一个多余的节点 <p>|<[p> ==> <p></p><div></div><p>|</p>
  4071. var pre = child.previousSibling;
  4072. domUtils.trimWhiteTextNode(pre);
  4073. if(!pre.childNodes.length){
  4074. domUtils.remove(pre);
  4075. }
  4076. //trace:2012,在非ie的情况,切开后剩下的节点有可能不能点入光标添加br占位
  4077. if(!browser.ie &&
  4078. (next = child.nextSibling) &&
  4079. domUtils.isBlockElm(next) &&
  4080. next.lastChild &&
  4081. !domUtils.isBr(next.lastChild)){
  4082. next.appendChild(me.document.createElement('br'))
  4083. }
  4084. hadBreak = 1;
  4085. }
  4086. }
  4087. var next = child.nextSibling;
  4088. if(!div.firstChild && next && domUtils.isBlockElm(next)){
  4089. range.setStart(next,0).collapse(true);
  4090. break;
  4091. }
  4092. range.setEndAfter( child ).collapse();
  4093. }
  4094. child = range.startContainer;
  4095. //用chrome可能有空白展位符
  4096. if(domUtils.isBlockElm(child) && domUtils.isEmptyNode(child)){
  4097. child.innerHTML = browser.ie ? '' : '<br/>'
  4098. }
  4099. //加上true因为在删除表情等时会删两次,第一次是删的fillData
  4100. range.select(true);
  4101. setTimeout(function(){
  4102. range = me.selection.getRange();
  4103. range.scrollToView(me.autoHeightEnabled,me.autoHeightEnabled ? domUtils.getXY(me.iframe).y:0);
  4104. },200)
  4105. }
  4106. };
  4107. ///import core
  4108. ///commands 自动排版
  4109. ///commandsName autotypeset
  4110. ///commandsTitle 自动排版
  4111. /**
  4112. * 自动排版
  4113. * @function
  4114. * @name baidu.editor.execCommands
  4115. */
  4116. UE.plugins['autotypeset'] = function(){
  4117. this.setOpt({'autotypeset':{
  4118. mergeEmptyline : true, //合并空行
  4119. removeClass : true, //去掉冗余的class
  4120. removeEmptyline : false, //去掉空行
  4121. textAlign : "left", //段落的排版方式,可以是 left,right,center,justify 去掉这个属性表示不执行排版
  4122. imageBlockLine : 'center', //图片的浮动方式,独占一行剧中,左右浮动,默认: center,left,right,none 去掉这个属性表示不执行排版
  4123. pasteFilter : false, //根据规则过滤没事粘贴进来的内容
  4124. clearFontSize : false, //去掉所有的内嵌字号,使用编辑器默认的字号
  4125. clearFontFamily : false, //去掉所有的内嵌字体,使用编辑器默认的字体
  4126. removeEmptyNode : false, // 去掉空节点
  4127. //可以去掉的标签
  4128. removeTagNames : utils.extend({div:1},dtd.$removeEmpty),
  4129. indent : false, // 行首缩进
  4130. indentValue : '2em' //行首缩进的大小
  4131. }});
  4132. var me = this,
  4133. opt = me.options.autotypeset,
  4134. remainClass = {
  4135. 'selectTdClass':1,
  4136. 'pagebreak':1,
  4137. 'anchorclass':1
  4138. },
  4139. remainTag = {
  4140. 'li':1
  4141. },
  4142. tags = {
  4143. div:1,
  4144. p:1,
  4145. //trace:2183 这些也认为是行
  4146. blockquote:1,center:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1
  4147. },
  4148. highlightCont;
  4149. //升级了版本,但配置项目里没有autotypeset
  4150. if(!opt){
  4151. return;
  4152. }
  4153. function isLine(node,notEmpty){
  4154. if(node && node.parentNode && tags[node.tagName.toLowerCase()]){
  4155. if(highlightCont && highlightCont.contains(node)
  4156. ||
  4157. node.getAttribute('pagebreak')
  4158. ){
  4159. return 0;
  4160. }
  4161. return notEmpty ? !domUtils.isEmptyBlock(node) : domUtils.isEmptyBlock(node);
  4162. }
  4163. }
  4164. function removeNotAttributeSpan(node){
  4165. if(!node.style.cssText){
  4166. domUtils.removeAttributes(node,['style']);
  4167. if(node.tagName.toLowerCase() == 'span' && domUtils.hasNoAttributes(node)){
  4168. domUtils.remove(node,true)
  4169. }
  4170. }
  4171. }
  4172. function autotype(type,html){
  4173. var cont;
  4174. if(html){
  4175. if(!opt.pasteFilter)return;
  4176. cont = me.document.createElement('div');
  4177. cont.innerHTML = html.html;
  4178. }else{
  4179. cont = me.document.body;
  4180. }
  4181. var nodes = domUtils.getElementsByTagName(cont,'*');
  4182. // 行首缩进,段落方向,段间距,段内间距
  4183. for(var i=0,ci;ci=nodes[i++];){
  4184. if(!highlightCont && ci.tagName == 'DIV' && ci.getAttribute('highlighter')){
  4185. highlightCont = ci;
  4186. }
  4187. //font-size
  4188. if(opt.clearFontSize && ci.style.fontSize){
  4189. ci.style.fontSize = '';
  4190. removeNotAttributeSpan(ci)
  4191. }
  4192. //font-family
  4193. if(opt.clearFontFamily && ci.style.fontFamily){
  4194. ci.style.fontFamily = '';
  4195. removeNotAttributeSpan(ci)
  4196. }
  4197. if(isLine(ci)){
  4198. //合并空行
  4199. if(opt.mergeEmptyline ){
  4200. var next = ci.nextSibling,tmpNode;
  4201. while(isLine(next)){
  4202. tmpNode = next;
  4203. next = tmpNode.nextSibling;
  4204. domUtils.remove(tmpNode);
  4205. }
  4206. }
  4207. //去掉空行,保留占位的空行
  4208. if(opt.removeEmptyline && domUtils.inDoc(ci,cont) && !remainTag[ci.parentNode.tagName.toLowerCase()] ){
  4209. domUtils.remove(ci);
  4210. continue;
  4211. }
  4212. }
  4213. if(isLine(ci,true) ){
  4214. if(opt.indent)
  4215. ci.style.textIndent = opt.indentValue;
  4216. if(opt.textAlign)
  4217. ci.style.textAlign = opt.textAlign;
  4218. // if(opt.lineHeight)
  4219. // ci.style.lineHeight = opt.lineHeight + 'cm';
  4220. }
  4221. //去掉class,保留的class不去掉
  4222. if(opt.removeClass && ci.className && !remainClass[ci.className.toLowerCase()]){
  4223. if(highlightCont && highlightCont.contains(ci)){
  4224. continue;
  4225. }
  4226. domUtils.removeAttributes(ci,['class'])
  4227. }
  4228. //表情不处理
  4229. if(opt.imageBlockLine && ci.tagName.toLowerCase() == 'img' && !ci.getAttribute('emotion')){
  4230. if(html){
  4231. var img = ci;
  4232. switch (opt.imageBlockLine){
  4233. case 'left':
  4234. case 'right':
  4235. case 'none':
  4236. var pN = img.parentNode,tmpNode,pre,next;
  4237. while(dtd.$inline[pN.tagName] || pN.tagName == 'A'){
  4238. pN = pN.parentNode;
  4239. }
  4240. tmpNode = pN;
  4241. if(tmpNode.tagName == 'P' && domUtils.getStyle(tmpNode,'text-align') == 'center'){
  4242. if(!domUtils.isBody(tmpNode) && domUtils.getChildCount(tmpNode,function(node){return !domUtils.isBr(node) && !domUtils.isWhitespace(node)}) == 1){
  4243. pre = tmpNode.previousSibling;
  4244. next = tmpNode.nextSibling;
  4245. if(pre && next && pre.nodeType == 1 && next.nodeType == 1 && pre.tagName == next.tagName && domUtils.isBlockElm(pre)){
  4246. pre.appendChild(tmpNode.firstChild);
  4247. while(next.firstChild){
  4248. pre.appendChild(next.firstChild)
  4249. }
  4250. domUtils.remove(tmpNode);
  4251. domUtils.remove(next);
  4252. }else{
  4253. domUtils.setStyle(tmpNode,'text-align','')
  4254. }
  4255. }
  4256. }
  4257. domUtils.setStyle(img,'float',opt.imageBlockLine);
  4258. break;
  4259. case 'center':
  4260. if(me.queryCommandValue('imagefloat') != 'center'){
  4261. pN = img.parentNode;
  4262. domUtils.setStyle(img,'float','none');
  4263. tmpNode = img;
  4264. while(pN && domUtils.getChildCount(pN,function(node){return !domUtils.isBr(node) && !domUtils.isWhitespace(node)}) == 1
  4265. && (dtd.$inline[pN.tagName] || pN.tagName == 'A')){
  4266. tmpNode = pN;
  4267. pN = pN.parentNode;
  4268. }
  4269. var pNode = me.document.createElement('p');
  4270. domUtils.setAttributes(pNode,{
  4271. style:'text-align:center'
  4272. });
  4273. tmpNode.parentNode.insertBefore(pNode,tmpNode);
  4274. pNode.appendChild(tmpNode);
  4275. domUtils.setStyle(tmpNode,'float','');
  4276. }
  4277. }
  4278. }else{
  4279. var range = me.selection.getRange();
  4280. range.selectNode(ci).select();
  4281. me.execCommand('imagefloat',opt.imageBlockLine);
  4282. }
  4283. }
  4284. //去掉冗余的标签
  4285. if(opt.removeEmptyNode){
  4286. if(opt.removeTagNames[ci.tagName.toLowerCase()] && domUtils.hasNoAttributes(ci) && domUtils.isEmptyBlock(ci)){
  4287. domUtils.remove(ci)
  4288. }
  4289. }
  4290. }
  4291. if(html)
  4292. html.html = cont.innerHTML
  4293. }
  4294. if(opt.pasteFilter){
  4295. me.addListener('beforepaste',autotype);
  4296. }
  4297. me.commands['autotypeset'] = {
  4298. execCommand:function () {
  4299. me.removeListener('beforepaste',autotype);
  4300. if(opt.pasteFilter){
  4301. me.addListener('beforepaste',autotype);
  4302. }
  4303. autotype();
  4304. }
  4305. };
  4306. };
  4307. UE.commands['autosubmit'] = {
  4308. execCommand:function () {
  4309. var me=this,
  4310. form = domUtils.findParentByTagName(me.iframe,"form", false);
  4311. if (form) {
  4312. if(me.fireEvent("beforesubmit")===false) return;
  4313. me.sync();
  4314. form.submit();
  4315. }
  4316. }
  4317. };
  4318. ///import core
  4319. ///import plugins\inserthtml.js
  4320. ///import plugins\catchremoteimage.js
  4321. ///commands 插入图片,操作图片的对齐方式
  4322. ///commandsName InsertImage,ImageNone,ImageLeft,ImageRight,ImageCenter
  4323. ///commandsTitle 图片,默认,居左,居右,居中
  4324. ///commandsDialog dialogs\image\image.html
  4325. /**
  4326. * Created by .
  4327. * User: zhanyi
  4328. * for image
  4329. */
  4330. UE.commands['imagefloat'] = {
  4331. execCommand : function (cmd, align){
  4332. var me = this,
  4333. range = me.selection.getRange();
  4334. if(!range.collapsed ){
  4335. var img = range.getClosedNode();
  4336. if(img && img.tagName == 'IMG'){
  4337. switch (align){
  4338. case 'left':
  4339. case 'right':
  4340. case 'none':
  4341. var pN = img.parentNode,tmpNode,pre,next;
  4342. while(dtd.$inline[pN.tagName] || pN.tagName == 'A'){
  4343. pN = pN.parentNode;
  4344. }
  4345. tmpNode = pN;
  4346. if(tmpNode.tagName == 'P' && domUtils.getStyle(tmpNode,'text-align') == 'center'){
  4347. if(!domUtils.isBody(tmpNode) && domUtils.getChildCount(tmpNode,function(node){return !domUtils.isBr(node) && !domUtils.isWhitespace(node)}) == 1){
  4348. pre = tmpNode.previousSibling;
  4349. next = tmpNode.nextSibling;
  4350. if(pre && next && pre.nodeType == 1 && next.nodeType == 1 && pre.tagName == next.tagName && domUtils.isBlockElm(pre)){
  4351. pre.appendChild(tmpNode.firstChild);
  4352. while(next.firstChild){
  4353. pre.appendChild(next.firstChild)
  4354. }
  4355. domUtils.remove(tmpNode);
  4356. domUtils.remove(next);
  4357. }else{
  4358. domUtils.setStyle(tmpNode,'text-align','')
  4359. }
  4360. }
  4361. range.selectNode(img).select()
  4362. }
  4363. domUtils.setStyle(img,'float',align);
  4364. break;
  4365. case 'center':
  4366. if(me.queryCommandValue('imagefloat') != 'center'){
  4367. pN = img.parentNode;
  4368. domUtils.setStyle(img,'float','none');
  4369. tmpNode = img;
  4370. while(pN && domUtils.getChildCount(pN,function(node){return !domUtils.isBr(node) && !domUtils.isWhitespace(node)}) == 1
  4371. && (dtd.$inline[pN.tagName] || pN.tagName == 'A')){
  4372. tmpNode = pN;
  4373. pN = pN.parentNode;
  4374. }
  4375. range.setStartBefore(tmpNode).setCursor(false);
  4376. pN = me.document.createElement('div');
  4377. pN.appendChild(tmpNode);
  4378. domUtils.setStyle(tmpNode,'float','');
  4379. me.execCommand('insertHtml','<p id="_img_parent_tmp" style="text-align:center">'+pN.innerHTML+'</p>');
  4380. tmpNode = me.document.getElementById('_img_parent_tmp');
  4381. tmpNode.removeAttribute('id');
  4382. tmpNode = tmpNode.firstChild;
  4383. range.selectNode(tmpNode).select();
  4384. //去掉后边多余的元素
  4385. next = tmpNode.parentNode.nextSibling;
  4386. if(next && domUtils.isEmptyNode(next)){
  4387. domUtils.remove(next)
  4388. }
  4389. }
  4390. break;
  4391. }
  4392. }
  4393. }
  4394. },
  4395. queryCommandValue : function() {
  4396. var range = this.selection.getRange(),
  4397. startNode,floatStyle;
  4398. if(range.collapsed){
  4399. return 'none';
  4400. }
  4401. startNode = range.getClosedNode();
  4402. if(startNode && startNode.nodeType == 1 && startNode.tagName == 'IMG'){
  4403. floatStyle = domUtils.getComputedStyle(startNode,'float');
  4404. if(floatStyle == 'none'){
  4405. floatStyle = domUtils.getComputedStyle(startNode.parentNode,'text-align') == 'center' ? 'center' : floatStyle
  4406. }
  4407. return {
  4408. left : 1,
  4409. right : 1,
  4410. center : 1
  4411. }[floatStyle] ? floatStyle : 'none'
  4412. }
  4413. return 'none'
  4414. },
  4415. queryCommandState : function(){
  4416. if(this.highlight){
  4417. return -1;
  4418. }
  4419. var range = this.selection.getRange(),
  4420. startNode;
  4421. if(range.collapsed){
  4422. return -1;
  4423. }
  4424. startNode = range.getClosedNode();
  4425. if(startNode && startNode.nodeType == 1 && startNode.tagName == 'IMG'){
  4426. return 0;
  4427. }
  4428. return -1;
  4429. }
  4430. };
  4431. UE.commands['insertimage'] = {
  4432. execCommand : function (cmd, opt){
  4433. opt = utils.isArray(opt) ? opt : [opt];
  4434. if(!opt.length) return;
  4435. var me = this,
  4436. range = me.selection.getRange(),
  4437. img = range.getClosedNode();
  4438. if(img && /img/i.test( img.tagName ) && img.className != "edui-faked-video" &&!img.getAttribute("word_img") ){
  4439. var first = opt.shift();
  4440. var floatStyle = first['floatStyle'];
  4441. delete first['floatStyle'];
  4442. //// img.style.border = (first.border||0) +"px solid #000";
  4443. //// img.style.margin = (first.margin||0) +"px";
  4444. // img.style.cssText += ';margin:' + (first.margin||0) +"px;" + 'border:' + (first.border||0) +"px solid #000";
  4445. domUtils.setAttributes(img,first);
  4446. me.execCommand('imagefloat',floatStyle);
  4447. if(opt.length > 0){
  4448. range.setStartAfter(img).setCursor(false,true);
  4449. me.execCommand('insertimage',opt);
  4450. }
  4451. }else{
  4452. var html = [],str = '',ci;
  4453. ci = opt[0];
  4454. if(opt.length == 1){
  4455. str = '<img src="'+ci.src+'" '+ (ci.data_ue_src ? ' data_ue_src="' + ci.data_ue_src +'" ':'') +
  4456. (ci.width ? 'width="'+ci.width+'" ':'') +
  4457. (ci.height ? ' height="'+ci.height+'" ':'') +
  4458. (ci['floatStyle']&&ci['floatStyle']!='center' ? ' style="float:'+ci['floatStyle']+';"':'') +
  4459. (ci.title?' title="'+ci.title+'"':'') + ' border="'+ (ci.border||0) + '" hspace = "'+(ci.hspace||0)+'" vspace = "'+(ci.vspace||0)+'" />';
  4460. if(ci['floatStyle'] == 'center'){
  4461. str = '<p style="text-align: center">'+str+'</p>'
  4462. }
  4463. html.push(str)
  4464. }else{
  4465. for(var i=0;ci=opt[i++];){
  4466. str = '<p ' + (ci['floatStyle'] == 'center' ? 'style="text-align: center" ' : '') + '><img src="'+ci.src+'" '+
  4467. (ci.width ? 'width="'+ci.width+'" ':'') + (ci.data_ue_src ? ' data_ue_src="' + ci.data_ue_src +'" ':'') +
  4468. (ci.height ? ' height="'+ci.height+'" ':'') +
  4469. ' style="' + (ci['floatStyle']&&ci['floatStyle']!='center' ? 'float:'+ci['floatStyle']+';':'') +
  4470. (ci.border||'') + '" ' +
  4471. (ci.title?' title="'+ci.title+'"':'') + ' /></p>';
  4472. // if(ci['floatStyle'] == 'center'){
  4473. // str = '<p style="text-align: center">'+str+'</p>'
  4474. // }
  4475. html.push(str)
  4476. }
  4477. }
  4478. me.execCommand('insertHtml',html.join(''));
  4479. }
  4480. },
  4481. queryCommandState : function(){
  4482. return this.highlight ? -1 :0;
  4483. }
  4484. };
  4485. ///import core
  4486. ///commands 段落格式,居左,居右,居中,两端对齐
  4487. ///commandsName JustifyLeft,JustifyCenter,JustifyRight,JustifyJustify
  4488. ///commandsTitle 居左对齐,居中对齐,居右对齐,两端对齐
  4489. /**
  4490. * @description 居左右中
  4491. * @name baidu.editor.execCommand
  4492. * @param {String} cmdName justify执行对齐方式的命令
  4493. * @param {String} align 对齐方式:left居左,right居右,center居中,justify两端对齐
  4494. * @author zhanyi
  4495. */
  4496. (function(){
  4497. var block = domUtils.isBlockElm,
  4498. defaultValue = {
  4499. left : 1,
  4500. right : 1,
  4501. center : 1,
  4502. justify : 1
  4503. },
  4504. doJustify = function(range,style){
  4505. var bookmark = range.createBookmark(),
  4506. filterFn = function( node ) {
  4507. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' && !domUtils.isBookmarkNode(node) : !domUtils.isWhitespace( node )
  4508. };
  4509. range.enlarge(true);
  4510. var bookmark2 = range.createBookmark(),
  4511. current = domUtils.getNextDomNode(bookmark2.start,false,filterFn),
  4512. tmpRange = range.cloneRange(),
  4513. tmpNode;
  4514. while(current && !(domUtils.getPosition(current,bookmark2.end)&domUtils.POSITION_FOLLOWING)){
  4515. if(current.nodeType == 3 || !block(current)){
  4516. tmpRange.setStartBefore(current);
  4517. while(current && current!==bookmark2.end && !block(current)){
  4518. tmpNode = current;
  4519. current = domUtils.getNextDomNode(current,false,null,function(node){
  4520. return !block(node)
  4521. });
  4522. }
  4523. tmpRange.setEndAfter(tmpNode);
  4524. var common = tmpRange.getCommonAncestor();
  4525. if( !domUtils.isBody(common) && block(common)){
  4526. domUtils.setStyles(common,utils.isString(style) ? {'text-align':style} : style);
  4527. current = common;
  4528. }else{
  4529. var p = range.document.createElement('p');
  4530. domUtils.setStyles(p,utils.isString(style) ? {'text-align':style} : style);
  4531. var frag = tmpRange.extractContents();
  4532. p.appendChild(frag);
  4533. tmpRange.insertNode(p);
  4534. current = p;
  4535. }
  4536. current = domUtils.getNextDomNode(current,false,filterFn);
  4537. }else{
  4538. current = domUtils.getNextDomNode(current,true,filterFn);
  4539. }
  4540. }
  4541. return range.moveToBookmark(bookmark2).moveToBookmark(bookmark)
  4542. };
  4543. UE.commands['justify'] = {
  4544. execCommand : function( cmdName,align ) {
  4545. var range = this.selection.getRange(),
  4546. txt;
  4547. if(this.currentSelectedArr && this.currentSelectedArr.length > 0){
  4548. for(var i=0,ti;ti=this.currentSelectedArr[i++];){
  4549. if(domUtils.isEmptyNode(ti)){
  4550. txt = this.document.createTextNode('p');
  4551. range.setStart(ti,0).collapse(true).insertNode(txt).selectNode(txt);
  4552. }else{
  4553. range.selectNodeContents(ti)
  4554. }
  4555. doJustify(range,align);
  4556. txt && domUtils.remove(txt);
  4557. }
  4558. range.selectNode(this.currentSelectedArr[0]).select()
  4559. }else{
  4560. //闭合时单独处理
  4561. if(range.collapsed){
  4562. txt = this.document.createTextNode('p');
  4563. range.insertNode(txt);
  4564. }
  4565. doJustify(range,align);
  4566. if(txt){
  4567. range.setStartBefore(txt).collapse(true);
  4568. domUtils.remove(txt);
  4569. }
  4570. range.select();
  4571. }
  4572. return true;
  4573. },
  4574. queryCommandValue : function() {
  4575. var startNode = this.selection.getStart(),
  4576. value = domUtils.getComputedStyle(startNode,'text-align');
  4577. return defaultValue[value] ? value : 'left';
  4578. },
  4579. queryCommandState : function(){
  4580. return this.highlight ? -1 : 0;
  4581. }
  4582. }
  4583. })();
  4584. ///import core
  4585. ///import plugins\removeformat.js
  4586. ///commands 字体颜色,背景色,字号,字体,下划线,删除线
  4587. ///commandsName ForeColor,BackColor,FontSize,FontFamily,Underline,StrikeThrough
  4588. ///commandsTitle 字体颜色,背景色,字号,字体,下划线,删除线
  4589. /**
  4590. * @description 字体
  4591. * @name baidu.editor.execCommand
  4592. * @param {String} cmdName 执行的功能名称
  4593. * @param {String} value 传入的值
  4594. */
  4595. UE.plugins['font'] = function() {
  4596. var me = this,
  4597. fonts = {
  4598. 'forecolor':'color',
  4599. 'backcolor':'background-color',
  4600. 'fontsize':'font-size',
  4601. 'fontfamily':'font-family',
  4602. 'underline':'text-decoration',
  4603. 'strikethrough':'text-decoration'
  4604. };
  4605. me.setOpt({
  4606. 'fontfamily':[
  4607. ['宋体',['宋体', 'SimSun']],
  4608. ['楷体',['楷体', '楷体_GB2312', 'SimKai']],
  4609. ['黑体',['黑体', 'SimHei']],
  4610. ['隶书',['隶书', 'SimLi']],
  4611. ['andale mono',['andale mono']],
  4612. ['arial',['arial', 'helvetica', 'sans-serif']],
  4613. ['arial black',['arial black', 'avant garde']],
  4614. ['comic sans ms',['comic sans ms']],
  4615. ['impact',['impact', 'chicago']],
  4616. ['times new roman',['times new roman']]
  4617. ],
  4618. 'fontsize':[10, 11, 12, 14, 16, 18, 20, 24, 36]
  4619. });
  4620. for ( var p in fonts ) {
  4621. (function( cmd, style ) {
  4622. UE.commands[cmd] = {
  4623. execCommand : function( cmdName, value ) {
  4624. value = value || (this.queryCommandState(cmdName) ? 'none' : cmdName == 'underline' ? 'underline' : 'line-through');
  4625. var me = this,
  4626. range = this.selection.getRange(),
  4627. text;
  4628. if ( value == 'default' ) {
  4629. if(range.collapsed){
  4630. text = me.document.createTextNode('font');
  4631. range.insertNode(text).select()
  4632. }
  4633. me.execCommand( 'removeFormat', 'span,a', style);
  4634. if(text){
  4635. range.setStartBefore(text).setCursor();
  4636. domUtils.remove(text)
  4637. }
  4638. } else {
  4639. if(me.currentSelectedArr && me.currentSelectedArr.length > 0){
  4640. for(var i=0,ci;ci=me.currentSelectedArr[i++];){
  4641. range.selectNodeContents(ci);
  4642. range.applyInlineStyle( 'span', {'style':style + ':' + value} );
  4643. }
  4644. range.selectNodeContents(this.currentSelectedArr[0]).select();
  4645. }else{
  4646. if ( !range.collapsed ) {
  4647. if((cmd == 'underline'||cmd=='strikethrough') && me.queryCommandValue(cmd)){
  4648. me.execCommand( 'removeFormat', 'span,a', style );
  4649. }
  4650. range = me.selection.getRange();
  4651. range.applyInlineStyle( 'span', {'style':style + ':' + value} ).select();
  4652. } else {
  4653. var span = domUtils.findParentByTagName(range.startContainer,'span',true);
  4654. text = me.document.createTextNode('font');
  4655. if(span && !span.children.length && !span[browser.ie ? 'innerText':'textContent'].replace(fillCharReg,'').length){
  4656. //for ie hack when enter
  4657. range.insertNode(text);
  4658. if(cmd == 'underline'||cmd=='strikethrough'){
  4659. range.selectNode(text).select();
  4660. me.execCommand( 'removeFormat','span,a', style, null );
  4661. span = domUtils.findParentByTagName(text,'span',true);
  4662. range.setStartBefore(text)
  4663. }
  4664. span.style.cssText = span.style.cssText + ';' + style + ':' + value;
  4665. range.collapse(true).select();
  4666. }else{
  4667. range.insertNode(text);
  4668. range.selectNode(text).select();
  4669. span = range.document.createElement( 'span' );
  4670. if(cmd == 'underline'||cmd=='strikethrough'){
  4671. //a标签内的不处理跳过
  4672. if(domUtils.findParentByTagName(text,'a',true)){
  4673. range.setStartBefore(text).setCursor();
  4674. domUtils.remove(text);
  4675. return;
  4676. }
  4677. me.execCommand( 'removeFormat','span,a', style );
  4678. }
  4679. span.style.cssText = style + ':' + value;
  4680. text.parentNode.insertBefore(span,text);
  4681. //修复,span套span 但样式不继承的问题
  4682. if(!browser.ie || browser.ie && browser.version == 9){
  4683. var spanParent = span.parentNode;
  4684. while(!domUtils.isBlockElm(spanParent)){
  4685. if(spanParent.tagName == 'SPAN'){
  4686. span.style.cssText = spanParent.style.cssText + span.style.cssText;
  4687. }
  4688. spanParent = spanParent.parentNode;
  4689. }
  4690. }
  4691. range.setStart(span,0).setCursor();
  4692. //trace:981
  4693. //domUtils.mergToParent(span)
  4694. }
  4695. domUtils.remove(text)
  4696. }
  4697. }
  4698. }
  4699. return true;
  4700. },
  4701. queryCommandValue : function (cmdName) {
  4702. var startNode = this.selection.getStart();
  4703. //trace:946
  4704. if(cmdName == 'underline'||cmdName=='strikethrough' ){
  4705. var tmpNode = startNode,value;
  4706. while(tmpNode && !domUtils.isBlockElm(tmpNode) && !domUtils.isBody(tmpNode)){
  4707. if(tmpNode.nodeType == 1){
  4708. value = domUtils.getComputedStyle( tmpNode, style );
  4709. if(value != 'none'){
  4710. return value;
  4711. }
  4712. }
  4713. tmpNode = tmpNode.parentNode;
  4714. }
  4715. return 'none'
  4716. }
  4717. return domUtils.getComputedStyle( startNode, style );
  4718. },
  4719. queryCommandState : function(cmdName){
  4720. if(this.highlight){
  4721. return -1;
  4722. }
  4723. if(!(cmdName == 'underline'||cmdName=='strikethrough'))
  4724. return 0;
  4725. return this.queryCommandValue(cmdName) == (cmdName == 'underline' ? 'underline' : 'line-through')
  4726. }
  4727. }
  4728. })( p, fonts[p] );
  4729. }
  4730. };
  4731. ///import core
  4732. ///commands 超链接,取消链接
  4733. ///commandsName Link,Unlink
  4734. ///commandsTitle 超链接,取消链接
  4735. ///commandsDialog dialogs\link\link.html
  4736. /**
  4737. * 超链接
  4738. * @function
  4739. * @name baidu.editor.execCommand
  4740. * @param {String} cmdName link插入超链接
  4741. * @param {Object} options url地址,title标题,target是否打开新页
  4742. * @author zhanyi
  4743. */
  4744. /**
  4745. * 取消链接
  4746. * @function
  4747. * @name baidu.editor.execCommand
  4748. * @param {String} cmdName unlink取消链接
  4749. * @author zhanyi
  4750. */
  4751. (function() {
  4752. function optimize( range ) {
  4753. var start = range.startContainer,end = range.endContainer;
  4754. if ( start = domUtils.findParentByTagName( start, 'a', true ) ) {
  4755. range.setStartBefore( start )
  4756. }
  4757. if ( end = domUtils.findParentByTagName( end, 'a', true ) ) {
  4758. range.setEndAfter( end )
  4759. }
  4760. }
  4761. UE.commands['unlink'] = {
  4762. execCommand : function() {
  4763. var as,
  4764. range = new dom.Range(this.document),
  4765. tds = this.currentSelectedArr,
  4766. bookmark;
  4767. if(tds && tds.length >0){
  4768. for(var i=0,ti;ti=tds[i++];){
  4769. as = domUtils.getElementsByTagName(ti,'a');
  4770. for(var j=0,aj;aj=as[j++];){
  4771. domUtils.remove(aj,true);
  4772. }
  4773. }
  4774. if(domUtils.isEmptyNode(tds[0])){
  4775. range.setStart(tds[0],0).setCursor();
  4776. }else{
  4777. range.selectNodeContents(tds[0]).select()
  4778. }
  4779. }else{
  4780. range = this.selection.getRange();
  4781. if(range.collapsed && !domUtils.findParentByTagName( range.startContainer, 'a', true )){
  4782. return;
  4783. }
  4784. bookmark = range.createBookmark();
  4785. optimize( range );
  4786. range.removeInlineStyle( 'a' ).moveToBookmark( bookmark ).select();
  4787. }
  4788. },
  4789. queryCommandState : function(){
  4790. return !this.highlight && this.queryCommandValue('link') ? 0 : -1;
  4791. }
  4792. };
  4793. function doLink(range,opt){
  4794. optimize( range = range.adjustmentBoundary() );
  4795. var start = range.startContainer;
  4796. if(start.nodeType == 1){
  4797. start = start.childNodes[range.startOffset];
  4798. if(start && start.nodeType == 1 && start.tagName == 'A' && /^(?:https?|ftp|file)\s*:\s*\/\//.test(start[browser.ie?'innerText':'textContent'])){
  4799. start[browser.ie ? 'innerText' : 'textContent'] = utils.html(opt.textValue||opt.href);
  4800. }
  4801. }
  4802. range.removeInlineStyle( 'a' );
  4803. if ( range.collapsed ) {
  4804. var a = range.document.createElement( 'a'),
  4805. text = '';
  4806. if(opt.textValue){
  4807. text = utils.html(opt.textValue);
  4808. delete opt.textValue;
  4809. }else{
  4810. text = utils.html(opt.href);
  4811. }
  4812. domUtils.setAttributes( a, opt );
  4813. range.insertNode( a );
  4814. a[browser.ie ? 'innerText' : 'textContent'] = text;
  4815. range.selectNode( a );
  4816. } else {
  4817. range.applyInlineStyle( 'a', opt )
  4818. }
  4819. }
  4820. UE.commands['link'] = {
  4821. queryCommandState : function(){
  4822. return this.highlight ? -1 :0;
  4823. },
  4824. execCommand : function( cmdName, opt ) {
  4825. var range = new dom.Range(this.document),
  4826. tds = this.currentSelectedArr;
  4827. opt.data_ue_src && (opt.data_ue_src = utils.unhtml(opt.data_ue_src));
  4828. opt.href && (opt.href = utils.unhtml(opt.href));
  4829. opt.textValue && (opt.textValue = utils.unhtml(opt.textValue));
  4830. if(tds && tds.length){
  4831. for(var i=0,ti;ti=tds[i++];){
  4832. if(domUtils.isEmptyNode(ti)){
  4833. ti[browser.ie ? 'innerText' : 'textContent'] = utils.html(opt.textValue || opt.href)
  4834. }
  4835. doLink(range.selectNodeContents(ti),opt)
  4836. }
  4837. range.selectNodeContents(tds[0]).select()
  4838. }else{
  4839. doLink(range=this.selection.getRange(),opt);
  4840. //闭合都不加占位符,如果加了会在a后边多个占位符节点,导致a是图片背景组成的列表,出现空白问题
  4841. range.collapse().select(true);
  4842. }
  4843. },
  4844. queryCommandValue : function() {
  4845. var range = new dom.Range(this.document),
  4846. tds = this.currentSelectedArr,
  4847. as,
  4848. node;
  4849. if(tds && tds.length){
  4850. for(var i=0,ti;ti=tds[i++];){
  4851. as = ti.getElementsByTagName('a');
  4852. if(as[0])
  4853. return as[0]
  4854. }
  4855. }else{
  4856. range = this.selection.getRange();
  4857. if ( range.collapsed ) {
  4858. node = this.selection.getStart();
  4859. if ( node && (node = domUtils.findParentByTagName( node, 'a', true )) ) {
  4860. return node;
  4861. }
  4862. } else {
  4863. //trace:1111 如果是<p><a>xx</a></p> startContainer是p就会找不到a
  4864. range.shrinkBoundary();
  4865. var start = range.startContainer.nodeType == 3 || !range.startContainer.childNodes[range.startOffset] ? range.startContainer : range.startContainer.childNodes[range.startOffset],
  4866. end = range.endContainer.nodeType == 3 || range.endOffset == 0 ? range.endContainer : range.endContainer.childNodes[range.endOffset-1],
  4867. common = range.getCommonAncestor();
  4868. node = domUtils.findParentByTagName( common, 'a', true );
  4869. if ( !node && common.nodeType == 1){
  4870. var as = common.getElementsByTagName( 'a' ),
  4871. ps,pe;
  4872. for ( var i = 0,ci; ci = as[i++]; ) {
  4873. ps = domUtils.getPosition( ci, start ),pe = domUtils.getPosition( ci,end);
  4874. if ( (ps & domUtils.POSITION_FOLLOWING || ps & domUtils.POSITION_CONTAINS)
  4875. &&
  4876. (pe & domUtils.POSITION_PRECEDING || pe & domUtils.POSITION_CONTAINS)
  4877. ) {
  4878. node = ci;
  4879. break;
  4880. }
  4881. }
  4882. }
  4883. return node;
  4884. }
  4885. }
  4886. }
  4887. };
  4888. })();
  4889. ///import core
  4890. ///import plugins\inserthtml.js
  4891. ///commands 地图
  4892. ///commandsName Map,GMap
  4893. ///commandsTitle Baidu地图,Google地图
  4894. ///commandsDialog dialogs\map\map.html,dialogs\gmap\gmap.html
  4895. UE.commands['gmap'] =
  4896. UE.commands['map'] = {
  4897. queryCommandState : function(){
  4898. return this.highlight ? -1 :0;
  4899. }
  4900. };
  4901. ///import core
  4902. ///import plugins\inserthtml.js
  4903. ///commands 插入框架
  4904. ///commandsName InsertFrame
  4905. ///commandsTitle 插入Iframe
  4906. ///commandsDialog dialogs\insertframe\insertframe.html
  4907. UE.plugins['insertframe'] = function() {
  4908. var me =this;
  4909. function deleteIframe(){
  4910. me._iframe && delete me._iframe;
  4911. }
  4912. me.addListener("selectionchange",function(){
  4913. deleteIframe();
  4914. });
  4915. me.commands["insertframe"] = {
  4916. queryCommandState : function(){
  4917. return this.highlight ? -1 :0;
  4918. }
  4919. }
  4920. };
  4921. ///import core
  4922. ///commands 清除格式
  4923. ///commandsName RemoveFormat
  4924. ///commandsTitle 清除格式
  4925. /**
  4926. * @description 清除格式
  4927. * @name baidu.editor.execCommand
  4928. * @param {String} cmdName removeformat清除格式命令
  4929. * @param {String} tags 以逗号隔开的标签。如:span,a
  4930. * @param {String} style 样式
  4931. * @param {String} attrs 属性
  4932. * @param {String} notIncluedA 是否把a标签切开
  4933. * @author zhanyi
  4934. */
  4935. UE.plugins['removeformat'] = function(){
  4936. var me = this;
  4937. me.setOpt({
  4938. 'removeFormatTags': 'b,big,code,del,dfn,em,font,i,ins,kbd,q,samp,small,span,strike,strong,sub,sup,tt,u,var',
  4939. 'removeFormatAttributes':'class,style,lang,width,height,align,hspace,valign'
  4940. });
  4941. me.commands['removeformat'] = {
  4942. execCommand : function( cmdName, tags, style, attrs,notIncludeA ) {
  4943. var tagReg = new RegExp( '^(?:' + (tags || this.options.removeFormatTags).replace( /,/g, '|' ) + ')$', 'i' ) ,
  4944. removeFormatAttributes = style ? [] : (attrs || this.options.removeFormatAttributes).split( ',' ),
  4945. range = new dom.Range( this.document ),
  4946. bookmark,node,parent,
  4947. filter = function( node ) {
  4948. return node.nodeType == 1;
  4949. };
  4950. function isRedundantSpan (node) {
  4951. if (node.nodeType == 3 || node.tagName.toLowerCase() != 'span')
  4952. return 0;
  4953. if (browser.ie) {
  4954. //ie 下判断实效,所以只能简单用style来判断
  4955. //return node.style.cssText == '' ? 1 : 0;
  4956. var attrs = node.attributes;
  4957. if ( attrs.length ) {
  4958. for ( var i = 0,l = attrs.length; i<l; i++ ) {
  4959. if ( attrs[i].specified ) {
  4960. return 0;
  4961. }
  4962. }
  4963. return 1;
  4964. }
  4965. }
  4966. return !node.attributes.length
  4967. }
  4968. function doRemove( range ) {
  4969. var bookmark1 = range.createBookmark();
  4970. if ( range.collapsed ) {
  4971. range.enlarge( true );
  4972. }
  4973. //不能把a标签切了
  4974. if(!notIncludeA){
  4975. var aNode = domUtils.findParentByTagName(range.startContainer,'a',true);
  4976. if(aNode){
  4977. range.setStartBefore(aNode)
  4978. }
  4979. aNode = domUtils.findParentByTagName(range.endContainer,'a',true);
  4980. if(aNode){
  4981. range.setEndAfter(aNode)
  4982. }
  4983. }
  4984. bookmark = range.createBookmark();
  4985. node = bookmark.start;
  4986. //切开始
  4987. while ( (parent = node.parentNode) && !domUtils.isBlockElm( parent ) ) {
  4988. domUtils.breakParent( node, parent );
  4989. domUtils.clearEmptySibling( node );
  4990. }
  4991. if ( bookmark.end ) {
  4992. //切结束
  4993. node = bookmark.end;
  4994. while ( (parent = node.parentNode) && !domUtils.isBlockElm( parent ) ) {
  4995. domUtils.breakParent( node, parent );
  4996. domUtils.clearEmptySibling( node );
  4997. }
  4998. //开始去除样式
  4999. var current = domUtils.getNextDomNode( bookmark.start, false, filter ),
  5000. next;
  5001. while ( current ) {
  5002. if ( current == bookmark.end ) {
  5003. break;
  5004. }
  5005. next = domUtils.getNextDomNode( current, true, filter );
  5006. if ( !dtd.$empty[current.tagName.toLowerCase()] && !domUtils.isBookmarkNode( current ) ) {
  5007. if ( tagReg.test( current.tagName ) ) {
  5008. if ( style ) {
  5009. domUtils.removeStyle( current, style );
  5010. if ( isRedundantSpan( current ) && style != 'text-decoration')
  5011. domUtils.remove( current, true );
  5012. } else {
  5013. domUtils.remove( current, true )
  5014. }
  5015. } else {
  5016. //trace:939 不能把list上的样式去掉
  5017. if(!dtd.$tableContent[current.tagName] && !dtd.$list[current.tagName]){
  5018. domUtils.removeAttributes( current, removeFormatAttributes );
  5019. if ( isRedundantSpan( current ) )
  5020. domUtils.remove( current, true );
  5021. }
  5022. }
  5023. }
  5024. current = next;
  5025. }
  5026. }
  5027. //trace:1035
  5028. //trace:1096 不能把td上的样式去掉,比如边框
  5029. var pN = bookmark.start.parentNode;
  5030. if(domUtils.isBlockElm(pN) && !dtd.$tableContent[pN.tagName] && !dtd.$list[pN.tagName]){
  5031. domUtils.removeAttributes( pN,removeFormatAttributes );
  5032. }
  5033. pN = bookmark.end.parentNode;
  5034. if(bookmark.end && domUtils.isBlockElm(pN) && !dtd.$tableContent[pN.tagName]&& !dtd.$list[pN.tagName]){
  5035. domUtils.removeAttributes( pN,removeFormatAttributes );
  5036. }
  5037. range.moveToBookmark( bookmark ).moveToBookmark(bookmark1);
  5038. //清除冗余的代码 <b><bookmark></b>
  5039. var node = range.startContainer,
  5040. tmp,
  5041. collapsed = range.collapsed;
  5042. while(node.nodeType == 1 && domUtils.isEmptyNode(node) && dtd.$removeEmpty[node.tagName]){
  5043. tmp = node.parentNode;
  5044. range.setStartBefore(node);
  5045. //trace:937
  5046. //更新结束边界
  5047. if(range.startContainer === range.endContainer){
  5048. range.endOffset--;
  5049. }
  5050. domUtils.remove(node);
  5051. node = tmp;
  5052. }
  5053. if(!collapsed){
  5054. node = range.endContainer;
  5055. while(node.nodeType == 1 && domUtils.isEmptyNode(node) && dtd.$removeEmpty[node.tagName]){
  5056. tmp = node.parentNode;
  5057. range.setEndBefore(node);
  5058. domUtils.remove(node);
  5059. node = tmp;
  5060. }
  5061. }
  5062. }
  5063. if ( this.currentSelectedArr && this.currentSelectedArr.length ) {
  5064. for ( var i = 0,ci; ci = this.currentSelectedArr[i++]; ) {
  5065. range.selectNodeContents( ci );
  5066. doRemove( range );
  5067. }
  5068. range.selectNodeContents( this.currentSelectedArr[0] ).select();
  5069. } else {
  5070. range = this.selection.getRange();
  5071. doRemove( range );
  5072. range.select();
  5073. }
  5074. },
  5075. queryCommandState : function(){
  5076. return this.highlight ? -1 :0;
  5077. }
  5078. };
  5079. };
  5080. ///import core
  5081. ///commands 引用
  5082. ///commandsName BlockQuote
  5083. ///commandsTitle 引用
  5084. /**
  5085. *
  5086. * 引用模块实现
  5087. * @function
  5088. * @name baidu.editor.execCommand
  5089. * @param {String} cmdName blockquote引用
  5090. */
  5091. (function() {
  5092. var getObj = function(editor){
  5093. // var startNode = editor.selection.getStart();
  5094. // return domUtils.findParentByTagName( startNode, 'blockquote', true )
  5095. return utils.findNode(editor.selection.getStartElementPath(),['blockquote'])
  5096. };
  5097. UE.commands['blockquote'] = {
  5098. execCommand : function( cmdName, attrs ) {
  5099. var range = this.selection.getRange(),
  5100. obj = getObj(this),
  5101. blockquote = dtd.blockquote,
  5102. bookmark = range.createBookmark(),
  5103. tds = this.currentSelectedArr;
  5104. if ( obj ) {
  5105. if(tds && tds.length){
  5106. domUtils.remove(obj,true)
  5107. }else{
  5108. var start = range.startContainer,
  5109. startBlock = domUtils.isBlockElm(start) ? start : domUtils.findParent(start,function(node){return domUtils.isBlockElm(node)}),
  5110. end = range.endContainer,
  5111. endBlock = domUtils.isBlockElm(end) ? end : domUtils.findParent(end,function(node){return domUtils.isBlockElm(node)});
  5112. //处理一下li
  5113. startBlock = domUtils.findParentByTagName(startBlock,'li',true) || startBlock;
  5114. endBlock = domUtils.findParentByTagName(endBlock,'li',true) || endBlock;
  5115. if(startBlock.tagName == 'LI' || startBlock.tagName == 'TD' || startBlock === obj){
  5116. domUtils.remove(obj,true)
  5117. }else{
  5118. domUtils.breakParent(startBlock,obj);
  5119. }
  5120. if(startBlock !== endBlock){
  5121. obj = domUtils.findParentByTagName(endBlock,'blockquote');
  5122. if(obj){
  5123. if(endBlock.tagName == 'LI' || endBlock.tagName == 'TD'){
  5124. domUtils.remove(obj,true)
  5125. }else{
  5126. domUtils.breakParent(endBlock,obj);
  5127. }
  5128. }
  5129. }
  5130. var blockquotes = domUtils.getElementsByTagName(this.document,'blockquote');
  5131. for(var i=0,bi;bi=blockquotes[i++];){
  5132. if(!bi.childNodes.length){
  5133. domUtils.remove(bi)
  5134. }else if(domUtils.getPosition(bi,startBlock)&domUtils.POSITION_FOLLOWING && domUtils.getPosition(bi,endBlock)&domUtils.POSITION_PRECEDING){
  5135. domUtils.remove(bi,true)
  5136. }
  5137. }
  5138. }
  5139. } else {
  5140. var tmpRange = range.cloneRange(),
  5141. node = tmpRange.startContainer.nodeType == 1 ? tmpRange.startContainer : tmpRange.startContainer.parentNode,
  5142. preNode = node,
  5143. doEnd = 1;
  5144. //调整开始
  5145. while ( 1 ) {
  5146. if ( domUtils.isBody(node) ) {
  5147. if ( preNode !== node ) {
  5148. if ( range.collapsed ) {
  5149. tmpRange.selectNode( preNode );
  5150. doEnd = 0;
  5151. } else {
  5152. tmpRange.setStartBefore( preNode );
  5153. }
  5154. }else{
  5155. tmpRange.setStart(node,0)
  5156. }
  5157. break;
  5158. }
  5159. if ( !blockquote[node.tagName] ) {
  5160. if ( range.collapsed ) {
  5161. tmpRange.selectNode( preNode )
  5162. } else
  5163. tmpRange.setStartBefore( preNode);
  5164. break;
  5165. }
  5166. preNode = node;
  5167. node = node.parentNode;
  5168. }
  5169. //调整结束
  5170. if ( doEnd ) {
  5171. preNode = node = node = tmpRange.endContainer.nodeType == 1 ? tmpRange.endContainer : tmpRange.endContainer.parentNode;
  5172. while ( 1 ) {
  5173. if ( domUtils.isBody( node ) ) {
  5174. if ( preNode !== node ) {
  5175. tmpRange.setEndAfter( preNode );
  5176. } else {
  5177. tmpRange.setEnd( node, node.childNodes.length )
  5178. }
  5179. break;
  5180. }
  5181. if ( !blockquote[node.tagName] ) {
  5182. tmpRange.setEndAfter( preNode );
  5183. break;
  5184. }
  5185. preNode = node;
  5186. node = node.parentNode;
  5187. }
  5188. }
  5189. node = range.document.createElement( 'blockquote' );
  5190. domUtils.setAttributes( node, attrs );
  5191. node.appendChild( tmpRange.extractContents() );
  5192. tmpRange.insertNode( node );
  5193. //去除重复的
  5194. var childs = domUtils.getElementsByTagName(node,'blockquote');
  5195. for(var i=0,ci;ci=childs[i++];){
  5196. if(ci.parentNode){
  5197. domUtils.remove(ci,true)
  5198. }
  5199. }
  5200. }
  5201. range.moveToBookmark( bookmark ).select()
  5202. },
  5203. queryCommandState : function() {
  5204. if(this.highlight){
  5205. return -1;
  5206. }
  5207. return getObj(this) ? 1 : 0;
  5208. }
  5209. };
  5210. })();
  5211. ///import core
  5212. ///import plugins\paragraph.js
  5213. ///commands 首行缩进
  5214. ///commandsName Outdent,Indent
  5215. ///commandsTitle 取消缩进,首行缩进
  5216. /**
  5217. * 首行缩进
  5218. * @function
  5219. * @name baidu.editor.execCommand
  5220. * @param {String} cmdName outdent取消缩进,indent缩进
  5221. */
  5222. UE.commands['indent'] = {
  5223. execCommand : function() {
  5224. var me = this,value = me.queryCommandState("indent") ? "0em" : (me.options.indentValue || '2em');
  5225. me.execCommand('Paragraph','p',{style:'text-indent:'+ value});
  5226. },
  5227. queryCommandState : function() {
  5228. if(this.highlight){return -1;}
  5229. var pN = utils.findNode(this.selection.getStartElementPath(),['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']);
  5230. return pN && pN.style.textIndent && parseInt(pN.style.textIndent) ? 1 : 0;
  5231. }
  5232. };
  5233. ///import core
  5234. ///commands 打印
  5235. ///commandsName Print
  5236. ///commandsTitle 打印
  5237. /**
  5238. * @description 打印
  5239. * @name baidu.editor.execCommand
  5240. * @param {String} cmdName print打印编辑器内容
  5241. * @author zhanyi
  5242. */
  5243. UE.commands['print'] = {
  5244. execCommand : function(){
  5245. this.window.print();
  5246. },
  5247. notNeedUndo : 1
  5248. };
  5249. ///import core
  5250. ///commands 预览
  5251. ///commandsName Preview
  5252. ///commandsTitle 预览
  5253. /**
  5254. * 预览
  5255. * @function
  5256. * @name baidu.editor.execCommand
  5257. * @param {String} cmdName preview预览编辑器内容
  5258. */
  5259. UE.commands['preview'] = {
  5260. execCommand : function(){
  5261. var me = this,
  5262. w = window.open('', '_blank', ""),
  5263. d = w.document,
  5264. css = me.document.getElementById("syntaxhighlighter_css"),
  5265. js = document.getElementById("syntaxhighlighter_js"),
  5266. // style = "<style type='text/css'>" + me.options.initialStyle + "</style>",
  5267. style = "<style type='text/css'>"+(me.document.getElementById("editorinitialstyle")&&me.document.getElementById("editorinitialstyle").innerHTML)+"</style>",
  5268. cont = me.getContent();
  5269. if(browser.ie){
  5270. cont = cont.replace(/<\s*br\s*\/?\s*>/gi,'<br/><br/>')
  5271. }
  5272. d.open();
  5273. d.write('<html><head>'+style+'<link rel="stylesheet" type="text/css" href="'+utils.unhtml( this.options.iframeCssUrl ) + '"/>'+
  5274. (css ? '<link rel="stylesheet" type="text/css" href="' + css.href + '"/>' : '')
  5275. + (css&&js ? ' <script type="text/javascript" charset="utf-8" src="'+js.src+'"></script>':'')
  5276. +'<title></title></head><body >' +
  5277. cont +
  5278. (css && js ? '<script type="text/javascript">'+(baidu.editor.browser.ie ? 'window.onload = function(){SyntaxHighlighter.all()};' : 'SyntaxHighlighter.all();')+
  5279. 'setTimeout(function(){' +
  5280. 'for(var i=0,di;di=SyntaxHighlighter.highlightContainers[i++];){' +
  5281. 'var tds = di.getElementsByTagName("td");' +
  5282. 'for(var j=0,li,ri;li=tds[0].childNodes[j];j++){' +
  5283. 'ri = tds[1].firstChild.childNodes[j];' +
  5284. 'ri.style.height = li.style.height = ri.offsetHeight + "px";' +
  5285. '}' +
  5286. '}},100)</script>':'') +
  5287. '</body></html>');
  5288. d.close();
  5289. },
  5290. notNeedUndo : 1
  5291. };
  5292. ///import core
  5293. ///import plugins\inserthtml.js
  5294. ///commands 特殊字符
  5295. ///commandsName Spechars
  5296. ///commandsTitle 特殊字符
  5297. ///commandsDialog dialogs\spechars\spechars.html
  5298. UE.commands['spechars'] = {
  5299. queryCommandState : function(){
  5300. return this.highlight ? -1 :0;
  5301. }
  5302. };
  5303. ///import core
  5304. ///import plugins\image.js
  5305. ///commands 插入表情
  5306. ///commandsName Emotion
  5307. ///commandsTitle 表情
  5308. ///commandsDialog dialogs\emotion\emotion.html
  5309. UE.commands['emotion'] = {
  5310. queryCommandState : function(){
  5311. return this.highlight ? -1 :0;
  5312. }
  5313. };
  5314. ///import core
  5315. ///commands 全选
  5316. ///commandsName SelectAll
  5317. ///commandsTitle 全选
  5318. /**
  5319. * 选中所有
  5320. * @function
  5321. * @name baidu.editor.execCommand
  5322. * @param {String} cmdName selectall选中编辑器里的所有内容
  5323. * @author zhanyi
  5324. */
  5325. UE.plugins['selectall'] = function(){
  5326. var me = this;
  5327. me.commands['selectall'] = {
  5328. execCommand : function(){
  5329. //去掉了原生的selectAll,因为会出现报错和当内容为空时,不能出现闭合状态的光标
  5330. var range = this.selection.getRange();
  5331. range.selectNodeContents(this.body);
  5332. if(domUtils.isEmptyBlock(this.body))
  5333. range.collapse(true);
  5334. range.select(true);
  5335. this.selectAll = true;
  5336. },
  5337. notNeedUndo : 1
  5338. };
  5339. me.addListener('ready',function(){
  5340. domUtils.on(me.document,'click',function(evt){
  5341. me.selectAll = false;
  5342. })
  5343. })
  5344. };
  5345. ///import core
  5346. ///commands 格式
  5347. ///commandsName Paragraph
  5348. ///commandsTitle 段落格式
  5349. /**
  5350. * 段落样式
  5351. * @function
  5352. * @name baidu.editor.execCommand
  5353. * @param {String} cmdName paragraph插入段落执行命令
  5354. * @param {String} style 标签值为:'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
  5355. * @param {String} attrs 标签的属性
  5356. * @author zhanyi
  5357. */
  5358. UE.plugins['paragraph'] = function() {
  5359. var me = this,
  5360. block = domUtils.isBlockElm,
  5361. notExchange = ['TD','LI','PRE'],
  5362. doParagraph = function(range,style,attrs,sourceCmdName){
  5363. var bookmark = range.createBookmark(),
  5364. filterFn = function( node ) {
  5365. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' && !domUtils.isBookmarkNode(node) : !domUtils.isWhitespace( node )
  5366. },
  5367. para;
  5368. range.enlarge( true );
  5369. var bookmark2 = range.createBookmark(),
  5370. current = domUtils.getNextDomNode( bookmark2.start, false, filterFn ),
  5371. tmpRange = range.cloneRange(),
  5372. tmpNode;
  5373. while ( current && !(domUtils.getPosition( current, bookmark2.end ) & domUtils.POSITION_FOLLOWING) ) {
  5374. if ( current.nodeType == 3 || !block( current ) ) {
  5375. tmpRange.setStartBefore( current );
  5376. while ( current && current !== bookmark2.end && !block( current ) ) {
  5377. tmpNode = current;
  5378. current = domUtils.getNextDomNode( current, false, null, function( node ) {
  5379. return !block( node )
  5380. } );
  5381. }
  5382. tmpRange.setEndAfter( tmpNode );
  5383. para = range.document.createElement( style );
  5384. if(attrs){
  5385. domUtils.setAttributes(para,attrs);
  5386. if(sourceCmdName && sourceCmdName == 'customstyle' && attrs.style)
  5387. para.style.cssText = attrs.style;
  5388. }
  5389. para.appendChild( tmpRange.extractContents() );
  5390. //需要内容占位
  5391. if(domUtils.isEmptyNode(para)){
  5392. domUtils.fillChar(range.document,para);
  5393. }
  5394. tmpRange.insertNode( para );
  5395. var parent = para.parentNode;
  5396. //如果para上一级是一个block元素且不是body,td就删除它
  5397. if ( block( parent ) && !domUtils.isBody( para.parentNode ) && utils.indexOf(notExchange,parent.tagName)==-1) {
  5398. //存储dir,style
  5399. if(!(sourceCmdName && sourceCmdName == 'customstyle')){
  5400. parent.getAttribute('dir') && para.setAttribute('dir',parent.getAttribute('dir'));
  5401. //trace:1070
  5402. parent.style.cssText && (para.style.cssText = parent.style.cssText + ';' + para.style.cssText);
  5403. //trace:1030
  5404. parent.style.textAlign && !para.style.textAlign && (para.style.textAlign = parent.style.textAlign);
  5405. parent.style.textIndent && !para.style.textIndent && (para.style.textIndent = parent.style.textIndent);
  5406. parent.style.padding && !para.style.padding && (para.style.padding = parent.style.padding);
  5407. }
  5408. //trace:1706 选择的就是h1-6要删除
  5409. if(attrs && /h\d/i.test(parent.tagName) && !/h\d/i.test(para.tagName) ){
  5410. domUtils.setAttributes(parent,attrs);
  5411. if(sourceCmdName && sourceCmdName == 'customstyle' && attrs.style)
  5412. parent.style.cssText = attrs.style;
  5413. domUtils.remove(para,true);
  5414. para = parent;
  5415. }else
  5416. domUtils.remove( para.parentNode, true );
  5417. }
  5418. if( utils.indexOf(notExchange,parent.tagName)!=-1){
  5419. current = parent;
  5420. }else{
  5421. current = para;
  5422. }
  5423. current = domUtils.getNextDomNode( current, false, filterFn );
  5424. } else {
  5425. current = domUtils.getNextDomNode( current, true, filterFn );
  5426. }
  5427. }
  5428. return range.moveToBookmark( bookmark2 ).moveToBookmark( bookmark );
  5429. };
  5430. me.setOpt('paragraph',['p:段落', 'h1:标题 1', 'h2:标题 2', 'h3:标题 3', 'h4:标题 4', 'h5:标题 5', 'h6:标题 6']);
  5431. me.commands['paragraph'] = {
  5432. execCommand : function( cmdName, style,attrs,sourceCmdName ) {
  5433. var range = new dom.Range(this.document);
  5434. if(this.currentSelectedArr && this.currentSelectedArr.length > 0){
  5435. for(var i=0,ti;ti=this.currentSelectedArr[i++];){
  5436. //trace:1079 不显示的不处理,插入文本,空的td也能加上相应的标签
  5437. if(ti.style.display == 'none') continue;
  5438. if(domUtils.isEmptyNode(ti)){
  5439. var tmpTxt = this.document.createTextNode('paragraph');
  5440. ti.innerHTML = '';
  5441. ti.appendChild(tmpTxt);
  5442. }
  5443. doParagraph(range.selectNodeContents(ti),style,attrs,sourceCmdName);
  5444. if(tmpTxt){
  5445. var pN = tmpTxt.parentNode;
  5446. domUtils.remove(tmpTxt);
  5447. if(domUtils.isEmptyNode(pN)){
  5448. domUtils.fillNode(this.document,pN)
  5449. }
  5450. }
  5451. }
  5452. var td = this.currentSelectedArr[0];
  5453. if(domUtils.isEmptyBlock(td)){
  5454. range.setStart(td,0).setCursor(false,true);
  5455. }else{
  5456. range.selectNode(td).select()
  5457. }
  5458. }else{
  5459. range = this.selection.getRange();
  5460. //闭合时单独处理
  5461. if(range.collapsed){
  5462. var txt = this.document.createTextNode('p');
  5463. range.insertNode(txt);
  5464. //去掉冗余的fillchar
  5465. if(browser.ie){
  5466. var node = txt.previousSibling;
  5467. if(node && domUtils.isWhitespace(node)){
  5468. domUtils.remove(node)
  5469. }
  5470. node = txt.nextSibling;
  5471. if(node && domUtils.isWhitespace(node)){
  5472. domUtils.remove(node)
  5473. }
  5474. }
  5475. }
  5476. range = doParagraph(range,style,attrs,sourceCmdName);
  5477. if(txt){
  5478. range.setStartBefore(txt).collapse(true);
  5479. pN = txt.parentNode;
  5480. domUtils.remove(txt);
  5481. if(domUtils.isBlockElm(pN)&&domUtils.isEmptyNode(pN)){
  5482. domUtils.fillNode(this.document,pN)
  5483. }
  5484. }
  5485. if(browser.gecko && range.collapsed && range.startContainer.nodeType == 1){
  5486. var child = range.startContainer.childNodes[range.startOffset];
  5487. if(child && child.nodeType == 1 && child.tagName.toLowerCase() == style){
  5488. range.setStart(child,0).collapse(true)
  5489. }
  5490. }
  5491. //trace:1097 原来有true,原因忘了,但去了就不能清除多余的占位符了
  5492. range.select()
  5493. }
  5494. return true;
  5495. },
  5496. queryCommandValue : function() {
  5497. var node = utils.findNode(this.selection.getStartElementPath(),['p','h1','h2','h3','h4','h5','h6']);
  5498. return node ? node.tagName.toLowerCase() : '';
  5499. },
  5500. queryCommandState : function(){
  5501. return this.highlight ? -1 :0;
  5502. }
  5503. }
  5504. };
  5505. ///import core
  5506. ///commands 输入的方向
  5507. ///commandsName DirectionalityLtr,DirectionalityRtl
  5508. ///commandsTitle 从左向右输入,从右向左输入
  5509. /**
  5510. * 输入的方向
  5511. * @function
  5512. * @name baidu.editor.execCommand
  5513. * @param {String} cmdName directionality执行函数的参数
  5514. * @param {String} forward ltr从左向右输入,rtl从右向左输入
  5515. */
  5516. (function() {
  5517. var block = domUtils.isBlockElm ,
  5518. getObj = function(editor){
  5519. // var startNode = editor.selection.getStart(),
  5520. // parents;
  5521. // if ( startNode ) {
  5522. // //查找所有的是block的父亲节点
  5523. // parents = domUtils.findParents( startNode, true, block, true );
  5524. // for ( var i = 0,ci; ci = parents[i++]; ) {
  5525. // if ( ci.getAttribute( 'dir' ) ) {
  5526. // return ci;
  5527. // }
  5528. // }
  5529. // }
  5530. return utils.findNode(editor.selection.getStartElementPath(),null,function(n){return n.getAttribute('dir')});
  5531. },
  5532. doDirectionality = function(range,editor,forward){
  5533. var bookmark,
  5534. filterFn = function( node ) {
  5535. return node.nodeType == 1 ? !domUtils.isBookmarkNode(node) : !domUtils.isWhitespace(node)
  5536. },
  5537. obj = getObj( editor );
  5538. if ( obj && range.collapsed ) {
  5539. obj.setAttribute( 'dir', forward );
  5540. return range;
  5541. }
  5542. bookmark = range.createBookmark();
  5543. range.enlarge( true );
  5544. var bookmark2 = range.createBookmark(),
  5545. current = domUtils.getNextDomNode( bookmark2.start, false, filterFn ),
  5546. tmpRange = range.cloneRange(),
  5547. tmpNode;
  5548. while ( current && !(domUtils.getPosition( current, bookmark2.end ) & domUtils.POSITION_FOLLOWING) ) {
  5549. if ( current.nodeType == 3 || !block( current ) ) {
  5550. tmpRange.setStartBefore( current );
  5551. while ( current && current !== bookmark2.end && !block( current ) ) {
  5552. tmpNode = current;
  5553. current = domUtils.getNextDomNode( current, false, null, function( node ) {
  5554. return !block( node )
  5555. } );
  5556. }
  5557. tmpRange.setEndAfter( tmpNode );
  5558. var common = tmpRange.getCommonAncestor();
  5559. if ( !domUtils.isBody( common ) && block( common ) ) {
  5560. //遍历到了block节点
  5561. common.setAttribute( 'dir', forward );
  5562. current = common;
  5563. } else {
  5564. //没有遍历到,添加一个block节点
  5565. var p = range.document.createElement( 'p' );
  5566. p.setAttribute( 'dir', forward );
  5567. var frag = tmpRange.extractContents();
  5568. p.appendChild( frag );
  5569. tmpRange.insertNode( p );
  5570. current = p;
  5571. }
  5572. current = domUtils.getNextDomNode( current, false, filterFn );
  5573. } else {
  5574. current = domUtils.getNextDomNode( current, true, filterFn );
  5575. }
  5576. }
  5577. return range.moveToBookmark( bookmark2 ).moveToBookmark( bookmark );
  5578. };
  5579. UE.commands['directionality'] = {
  5580. execCommand : function( cmdName,forward ) {
  5581. var range = new dom.Range(this.document);
  5582. if(this.currentSelectedArr && this.currentSelectedArr.length > 0){
  5583. for(var i=0,ti;ti=this.currentSelectedArr[i++];){
  5584. if(ti.style.display != 'none')
  5585. doDirectionality(range.selectNode(ti),this,forward);
  5586. }
  5587. range.selectNode(this.currentSelectedArr[0]).select()
  5588. }else{
  5589. range = this.selection.getRange();
  5590. //闭合时单独处理
  5591. if(range.collapsed){
  5592. var txt = this.document.createTextNode('d');
  5593. range.insertNode(txt);
  5594. }
  5595. doDirectionality(range,this,forward);
  5596. if(txt){
  5597. range.setStartBefore(txt).collapse(true);
  5598. domUtils.remove(txt);
  5599. }
  5600. range.select();
  5601. }
  5602. return true;
  5603. },
  5604. queryCommandValue : function() {
  5605. var node = getObj(this);
  5606. return node ? node.getAttribute('dir') : 'ltr'
  5607. },
  5608. queryCommandState : function(){
  5609. return this.highlight ? -1 :0;
  5610. }
  5611. }
  5612. })();
  5613. ///import core
  5614. ///import plugins\inserthtml.js
  5615. ///commands 分割线
  5616. ///commandsName Horizontal
  5617. ///commandsTitle 分隔线
  5618. /**
  5619. * 分割线
  5620. * @function
  5621. * @name baidu.editor.execCommand
  5622. * @param {String} cmdName horizontal插入分割线
  5623. */
  5624. UE.commands['horizontal'] = {
  5625. execCommand : function( cmdName ) {
  5626. var me = this;
  5627. if(me.queryCommandState(cmdName)!==-1){
  5628. me.execCommand('insertHtml','<hr>');
  5629. var range = me.selection.getRange(),
  5630. start = range.startContainer;
  5631. if(start.nodeType == 1 && !start.childNodes[range.startOffset] ){
  5632. var tmp;
  5633. if(tmp = start.childNodes[range.startOffset - 1]){
  5634. if(tmp.nodeType == 1 && tmp.tagName == 'HR'){
  5635. if(me.options.enterTag == 'p'){
  5636. tmp = me.document.createElement('p');
  5637. range.insertNode(tmp);
  5638. range.setStart(tmp,0).setCursor();
  5639. }else{
  5640. tmp = me.document.createElement('br');
  5641. range.insertNode(tmp);
  5642. range.setStartBefore(tmp).setCursor();
  5643. }
  5644. }
  5645. }
  5646. }
  5647. return true;
  5648. }
  5649. },
  5650. //边界在table里不能加分隔线
  5651. queryCommandState : function() {
  5652. return this.highlight || utils.findNode(this.selection.getStartElementPath(),['table']) ? -1 : 0;
  5653. }
  5654. };
  5655. ///import core
  5656. ///import plugins\inserthtml.js
  5657. ///commands 日期,时间
  5658. ///commandsName Date,Time
  5659. ///commandsTitle 日期,时间
  5660. /**
  5661. * 插入日期
  5662. * @function
  5663. * @name baidu.editor.execCommand
  5664. * @param {String} cmdName date插入日期
  5665. * @author zhuwenxuan
  5666. */
  5667. /**
  5668. * 插入时间
  5669. * @function
  5670. * @name baidu.editor.execCommand
  5671. * @param {String} cmdName time插入时间
  5672. * @author zhuwenxuan
  5673. */
  5674. UE.commands['time'] = UE.commands["date"] = {
  5675. execCommand : function(cmd){
  5676. var date = new Date;
  5677. this.execCommand('insertHtml',cmd == "time" ?
  5678. (date.getHours()+":"+ (date.getMinutes()<10 ? "0"+date.getMinutes() : date.getMinutes())+":"+(date.getSeconds()<10 ? "0"+date.getSeconds() : date.getSeconds())) :
  5679. (date.getFullYear()+"-"+((date.getMonth()+1)<10 ? "0"+(date.getMonth()+1) : date.getMonth()+1)+"-"+(date.getDate()<10?"0"+date.getDate():date.getDate())));
  5680. },
  5681. queryCommandState : function(){
  5682. return this.highlight ? -1 :0;
  5683. }
  5684. };
  5685. ///import core
  5686. ///import plugins\paragraph.js
  5687. ///commands 段间距
  5688. ///commandsName RowSpacingBottom,RowSpacingTop
  5689. ///commandsTitle 段间距
  5690. /**
  5691. * @description 设置段前距,段后距
  5692. * @name baidu.editor.execCommand
  5693. * @param {String} cmdName rowspacing设置段间距
  5694. * @param {String} value 值,以px为单位
  5695. * @param {String} dir top或bottom段前后段后
  5696. * @author zhanyi
  5697. */
  5698. UE.plugins['rowspacing'] = function(){
  5699. var me = this;
  5700. me.setOpt({
  5701. 'rowspacingtop':['5', '10', '15', '20', '25'],
  5702. 'rowspacingbottom':['5', '10', '15', '20', '25']
  5703. });
  5704. me.commands['rowspacing'] = {
  5705. execCommand : function( cmdName,value,dir ) {
  5706. this.execCommand('paragraph','p',{style:'margin-'+dir+':'+value + 'px'});
  5707. return true;
  5708. },
  5709. queryCommandValue : function(cmdName,dir) {
  5710. var pN = utils.findNode(this.selection.getStartElementPath(),null,function(node){return domUtils.isBlockElm(node) }),
  5711. value;
  5712. //trace:1026
  5713. if(pN){
  5714. value = domUtils.getComputedStyle(pN,'margin-'+dir).replace(/[^\d]/g,'');
  5715. return !value ? 0 : value;
  5716. }
  5717. return 0;
  5718. },
  5719. queryCommandState : function(){
  5720. return this.highlight ? -1 :0;
  5721. }
  5722. };
  5723. };
  5724. ///import core
  5725. ///import plugins\paragraph.js
  5726. ///commands 行间距
  5727. ///commandsName LineHeight
  5728. ///commandsTitle 行间距
  5729. /**
  5730. * @description 设置行内间距
  5731. * @name baidu.editor.execCommand
  5732. * @param {String} cmdName lineheight设置行内间距
  5733. * @param {String} value 值
  5734. * @author zhuwenxuan
  5735. */
  5736. UE.plugins['lineheight'] = function(){
  5737. var me = this;
  5738. me.setOpt({'lineheight':['1', '1.5','1.75','2', '3', '4', '5']});
  5739. me.commands['lineheight'] = {
  5740. execCommand : function( cmdName,value ) {
  5741. this.execCommand('paragraph','p',{style:'line-height:'+ (value == "1" ? "normal" : value + 'em') });
  5742. return true;
  5743. },
  5744. queryCommandValue : function() {
  5745. var pN = utils.findNode(this.selection.getStartElementPath(),null,function(node){return domUtils.isBlockElm(node)});
  5746. if(pN){
  5747. var value = domUtils.getComputedStyle(pN,'line-height');
  5748. return value == 'normal' ? 1 : value.replace(/[^\d.]*/ig,"")
  5749. }
  5750. },
  5751. queryCommandState : function(){
  5752. return this.highlight ? -1 :0;
  5753. }
  5754. };
  5755. };
  5756. ///import core
  5757. ///commands 清空文档
  5758. ///commandsName ClearDoc
  5759. ///commandsTitle 清空文档
  5760. /**
  5761. *
  5762. * 清空文档
  5763. * @function
  5764. * @name baidu.editor.execCommand
  5765. * @param {String} cmdName cleardoc清空文档
  5766. */
  5767. UE.commands['cleardoc'] = {
  5768. execCommand : function( cmdName) {
  5769. var me = this,
  5770. enterTag = me.options.enterTag,
  5771. range = me.selection.getRange();
  5772. if(enterTag == "br"){
  5773. me.body.innerHTML = "<br/>";
  5774. range.setStart(me.body,0).setCursor();
  5775. }else{
  5776. me.body.innerHTML = "<p>"+(ie ? "" : "<br/>")+"</p>";
  5777. range.setStart(me.body.firstChild,0).setCursor(false,true);
  5778. }
  5779. }
  5780. };
  5781. ///import core
  5782. ///commands 锚点
  5783. ///commandsName Anchor
  5784. ///commandsTitle 锚点
  5785. ///commandsDialog dialogs\anchor\anchor.html
  5786. /**
  5787. * 锚点
  5788. * @function
  5789. * @name baidu.editor.execCommands
  5790. * @param {String} cmdName cmdName="anchor"插入锚点
  5791. */
  5792. UE.commands['anchor'] = {
  5793. execCommand:function (cmd, name) {
  5794. var range = this.selection.getRange(),img = range.getClosedNode();
  5795. if (img && img.getAttribute('anchorname')) {
  5796. if (name) {
  5797. img.setAttribute('anchorname', name);
  5798. } else {
  5799. range.setStartBefore(img).setCursor();
  5800. domUtils.remove(img);
  5801. }
  5802. } else {
  5803. if (name) {
  5804. //只在选区的开始插入
  5805. var anchor = this.document.createElement('img');
  5806. range.collapse(true);
  5807. domUtils.setAttributes(anchor,{
  5808. 'anchorname':name,
  5809. 'class':'anchorclass'
  5810. });
  5811. range.insertNode(anchor).setStartAfter(anchor).setCursor(false,true);
  5812. }
  5813. }
  5814. },
  5815. queryCommandState:function () {
  5816. return this.highlight ? -1 : 0;
  5817. }
  5818. };
  5819. ///import core
  5820. ///commands 删除
  5821. ///commandsName Delete
  5822. ///commandsTitle 删除
  5823. /**
  5824. * 删除
  5825. * @function
  5826. * @name baidu.editor.execCommand
  5827. * @param {String} cmdName delete删除
  5828. */
  5829. UE.commands['delete'] = {
  5830. execCommand : function (){
  5831. var range = this.selection.getRange(),
  5832. mStart = 0,
  5833. mEnd = 0,
  5834. me = this;
  5835. if(this.selectAll ){
  5836. //trace:1633
  5837. me.body.innerHTML = '<p>'+(browser.ie ? '&nbsp;' : '<br/>')+'</p>';
  5838. range.setStart(me.body.firstChild,0).setCursor(false,true);
  5839. me.selectAll = false;
  5840. return;
  5841. }
  5842. if(me.currentSelectedArr && me.currentSelectedArr.length > 0){
  5843. for(var i=0,ci;ci=me.currentSelectedArr[i++];){
  5844. if(ci.style.display != 'none'){
  5845. ci.innerHTML = browser.ie ? domUtils.fillChar : '<br/>'
  5846. }
  5847. }
  5848. range.setStart(me.currentSelectedArr[0],0).setCursor();
  5849. return;
  5850. }
  5851. if(range.collapsed)
  5852. return;
  5853. range.txtToElmBoundary();
  5854. //&& !domUtils.isBlockElm(range.startContainer)
  5855. while(!range.startOffset && !domUtils.isBody(range.startContainer) && !dtd.$tableContent[range.startContainer.tagName] ){
  5856. mStart = 1;
  5857. range.setStartBefore(range.startContainer);
  5858. }
  5859. //&& !domUtils.isBlockElm(range.endContainer)
  5860. while(!domUtils.isBody(range.endContainer)&& !dtd.$tableContent[range.endContainer.tagName] ){
  5861. var child,endContainer = range.endContainer,endOffset = range.endOffset;
  5862. // if(endContainer.nodeType == 3 && endOffset == endContainer.nodeValue.length){
  5863. // range.setEndAfter(endContainer);
  5864. // continue;
  5865. // }
  5866. child = endContainer.childNodes[endOffset];
  5867. if(!child || domUtils.isBr(child) && endContainer.lastChild === child){
  5868. range.setEndAfter(endContainer);
  5869. continue;
  5870. }
  5871. break;
  5872. }
  5873. if(mStart){
  5874. var start = me.document.createElement('span');
  5875. start.innerHTML = 'start';
  5876. start.id = '_baidu_cut_start';
  5877. range.insertNode(start).setStartBefore(start)
  5878. }
  5879. if(mEnd){
  5880. var end = me.document.createElement('span');
  5881. end.innerHTML = 'end';
  5882. end.id = '_baidu_cut_end';
  5883. range.cloneRange().collapse(false).insertNode(end);
  5884. range.setEndAfter(end)
  5885. }
  5886. range.deleteContents();
  5887. if(domUtils.isBody(range.startContainer) && domUtils.isEmptyBlock(me.body)){
  5888. me.body.innerHTML = '<p>'+(browser.ie?'':'<br/>')+'</p>';
  5889. range.setStart(me.body.firstChild,0).collapse(true);
  5890. }else if ( !browser.ie && domUtils.isEmptyBlock(range.startContainer)){
  5891. range.startContainer.innerHTML = '<br/>'
  5892. }
  5893. range.select(true)
  5894. },
  5895. queryCommandState : function(){
  5896. if(this.currentSelectedArr && this.currentSelectedArr.length > 0){
  5897. return 0;
  5898. }
  5899. return this.highlight || this.selection.getRange().collapsed ? -1 : 0;
  5900. }
  5901. };
  5902. ///import core
  5903. ///commands 字数统计
  5904. ///commandsName WordCount,wordCount
  5905. ///commandsTitle 字数统计
  5906. /**
  5907. * Created by JetBrains WebStorm.
  5908. * User: taoqili
  5909. * Date: 11-9-7
  5910. * Time: 下午8:18
  5911. * To change this template use File | Settings | File Templates.
  5912. */
  5913. UE.plugins['wordcount'] = function(){
  5914. var me = this;
  5915. me.setOpt({
  5916. wordCount:true,
  5917. maximumWords:10000,
  5918. wordCountMsg:'当前已输入 {#count} 个字符,您还可以输入{#leave} 个字符 ',
  5919. wordOverFlowMsg:'<span style="color:red;">你输入的字符个数已经超出最大允许值,服务器可能会拒绝保存!</span>'
  5920. });
  5921. var opt = me.options,
  5922. max = opt.maximumWords,
  5923. msg = opt.wordCountMsg ,
  5924. errMsg = opt.wordOverFlowMsg;
  5925. if(!opt.wordCount)return;
  5926. me.commands["wordcount"]={
  5927. queryCommandValue:function(cmd,onlyCount){
  5928. var length,contentText,reg;
  5929. if(onlyCount){
  5930. reg = new RegExp("[\r\t\n]","g");
  5931. contentText = this.getContentTxt().replace(reg,"");
  5932. return contentText.length;
  5933. }
  5934. reg = new RegExp("[\r\t\n]","g");
  5935. contentText = this.getContentTxt().replace(reg,"");
  5936. length = contentText.length;
  5937. if(max-length<0){
  5938. me.fireEvent('wordcountoverflow');
  5939. return errMsg
  5940. }
  5941. return msg.replace("{#leave}",max-length >= 0 ? max-length:0).replace("{#count}",length);;
  5942. }
  5943. };
  5944. };
  5945. ///import core
  5946. ///commands 添加分页功能
  5947. ///commandsName PageBreak
  5948. ///commandsTitle 分页
  5949. /**
  5950. * @description 添加分页功能
  5951. * @author zhanyi
  5952. */
  5953. UE.plugins['pagebreak'] = function () {
  5954. var me = this,
  5955. notBreakTags = ['td'];
  5956. function fillNode(node){
  5957. if(domUtils.isEmptyBlock(node)){
  5958. var firstChild = node.firstChild,tmpNode;
  5959. while(firstChild && firstChild.nodeType == 1 && domUtils.isEmptyBlock(firstChild)){
  5960. tmpNode = firstChild;
  5961. firstChild = firstChild.firstChild;
  5962. }
  5963. !tmpNode && (tmpNode = node);
  5964. domUtils.fillNode(me.document,tmpNode);
  5965. }
  5966. }
  5967. function isHr(node){
  5968. return node && node.nodeType == 1 && node.tagName == 'HR' && node.className == 'pagebreak';
  5969. }
  5970. me.commands['pagebreak'] = {
  5971. execCommand:function () {
  5972. var range = me.selection.getRange(),hr = me.document.createElement('hr');
  5973. domUtils.setAttributes(hr,{
  5974. 'class' : 'pagebreak',
  5975. noshade:"noshade",
  5976. size:"5"
  5977. });
  5978. domUtils.unselectable(hr);
  5979. //table单独处理
  5980. var node = domUtils.findParentByTagName(range.startContainer, notBreakTags, true),
  5981. parents = [], pN;
  5982. if (node) {
  5983. switch (node.tagName) {
  5984. case 'TD':
  5985. pN = node.parentNode;
  5986. if (!pN.previousSibling) {
  5987. var table = domUtils.findParentByTagName(pN, 'table');
  5988. table.parentNode.insertBefore(hr, table);
  5989. parents = domUtils.findParents(hr, true);
  5990. } else {
  5991. pN.parentNode.insertBefore(hr, pN);
  5992. parents = domUtils.findParents(hr);
  5993. }
  5994. pN = parents[1];
  5995. if (hr !== pN) {
  5996. domUtils.breakParent(hr, pN);
  5997. }
  5998. domUtils.clearSelectedArr(me.currentSelectedArr);
  5999. }
  6000. } else {
  6001. if (!range.collapsed) {
  6002. range.deleteContents();
  6003. var start = range.startContainer;
  6004. while ( !domUtils.isBody(start) && domUtils.isBlockElm(start) && domUtils.isEmptyNode(start)) {
  6005. range.setStartBefore(start).collapse(true);
  6006. domUtils.remove(start);
  6007. start = range.startContainer;
  6008. }
  6009. }
  6010. range.insertNode(hr);
  6011. var pN = hr.parentNode, nextNode;
  6012. while (!domUtils.isBody(pN)) {
  6013. domUtils.breakParent(hr, pN);
  6014. nextNode = hr.nextSibling;
  6015. if (nextNode && domUtils.isEmptyBlock(nextNode)) {
  6016. domUtils.remove(nextNode)
  6017. }
  6018. pN = hr.parentNode;
  6019. }
  6020. nextNode = hr.nextSibling;
  6021. var pre = hr.previousSibling;
  6022. if(isHr(pre)){
  6023. domUtils.remove(pre)
  6024. }else{
  6025. pre && fillNode(pre);
  6026. }
  6027. if(!nextNode){
  6028. var p = me.document.createElement('p');
  6029. hr.parentNode.appendChild(p);
  6030. domUtils.fillNode(me.document,p);
  6031. range.setStart(p,0).collapse(true)
  6032. }else{
  6033. if(isHr(nextNode)){
  6034. domUtils.remove(nextNode)
  6035. }else{
  6036. fillNode(nextNode);
  6037. }
  6038. range.setEndAfter(hr).collapse(false)
  6039. }
  6040. range.select(true)
  6041. }
  6042. },
  6043. queryCommandState:function () {
  6044. return this.highlight ? -1 : 0;
  6045. }
  6046. }
  6047. };
  6048. ///import core
  6049. ///commands 本地图片引导上传
  6050. ///commandsName WordImage
  6051. ///commandsTitle 本地图片引导上传
  6052. UE.plugins["wordimage"] = function(){
  6053. var me = this,
  6054. images;
  6055. me.commands['wordimage'] = {
  6056. execCommand : function() {
  6057. images = domUtils.getElementsByTagName(me.document.body,"img");
  6058. var urlList = [];
  6059. for(var i=0,ci;ci=images[i++];){
  6060. var url=ci.getAttribute("word_img");
  6061. url && urlList.push(url);
  6062. }
  6063. if(images.length){
  6064. this["word_img"] = urlList;
  6065. }
  6066. },
  6067. queryCommandState: function(){
  6068. images = domUtils.getElementsByTagName(me.document.body,"img");
  6069. for(var i=0,ci;ci =images[i++];){
  6070. if(ci.getAttribute("word_img")){
  6071. return 1;
  6072. }
  6073. }
  6074. return -1;
  6075. }
  6076. };
  6077. };
  6078. ///import core
  6079. ///commands 撤销和重做
  6080. ///commandsName Undo,Redo
  6081. ///commandsTitle 撤销,重做
  6082. /**
  6083. * @description 回退
  6084. * @author zhanyi
  6085. */
  6086. UE.plugins['undo'] = function() {
  6087. var me = this,
  6088. maxUndoCount = me.options.maxUndoCount || 20,
  6089. maxInputCount = me.options.maxInputCount || 20,
  6090. fillchar = new RegExp(domUtils.fillChar + '|<\/hr>','gi'),// ie会产生多余的</hr>
  6091. //在比较时,需要过滤掉这些属性
  6092. specialAttr = /\b(?:href|src|name)="[^"]*?"/gi;
  6093. function UndoManager() {
  6094. this.list = [];
  6095. this.index = 0;
  6096. this.hasUndo = false;
  6097. this.hasRedo = false;
  6098. this.undo = function() {
  6099. if ( this.hasUndo ) {
  6100. var currentScene = this.getScene(),
  6101. lastScene = this.list[this.index];
  6102. if ( lastScene.content.replace(specialAttr,'') != currentScene.content.replace(specialAttr,'') ) {
  6103. this.save();
  6104. }
  6105. if(!this.list[this.index - 1] && this.list.length == 1){
  6106. this.reset();
  6107. return;
  6108. }
  6109. while ( this.list[this.index].content == this.list[this.index - 1].content ) {
  6110. this.index--;
  6111. if ( this.index == 0 ) {
  6112. return this.restore( 0 )
  6113. }
  6114. }
  6115. this.restore( --this.index );
  6116. }
  6117. };
  6118. this.redo = function() {
  6119. if ( this.hasRedo ) {
  6120. while ( this.list[this.index].content == this.list[this.index + 1].content ) {
  6121. this.index++;
  6122. if ( this.index == this.list.length - 1 ) {
  6123. return this.restore( this.index )
  6124. }
  6125. }
  6126. this.restore( ++this.index );
  6127. }
  6128. };
  6129. this.restore = function() {
  6130. var scene = this.list[this.index];
  6131. //trace:873
  6132. //去掉展位符
  6133. me.document.body.innerHTML = scene.bookcontent.replace(fillchar,'');
  6134. //处理undo后空格不展位的问题
  6135. if(browser.ie){
  6136. for(var i=0,pi,ps = me.document.getElementsByTagName('p');pi = ps[i++];){
  6137. if(pi.innerHTML == ''){
  6138. domUtils.fillNode(me.document,pi);
  6139. }
  6140. }
  6141. }
  6142. var range = new dom.Range( me.document );
  6143. range.moveToBookmark( {
  6144. start : '_baidu_bookmark_start_',
  6145. end : '_baidu_bookmark_end_',
  6146. id : true
  6147. //去掉true 是为了<b>|</b>,回退后还能在b里
  6148. //todo safari里输入中文时,会因为改变了dom而导致丢字
  6149. } );
  6150. //trace:1278 ie9block元素为空,将出现光标定位的问题,必须填充内容
  6151. if(browser.ie && browser.version == 9 && range.collapsed && domUtils.isBlockElm(range.startContainer) && domUtils.isEmptyNode(range.startContainer)){
  6152. domUtils.fillNode(range.document,range.startContainer);
  6153. }
  6154. range.select(!browser.gecko);
  6155. setTimeout(function(){
  6156. range.scrollToView(me.autoHeightEnabled,me.autoHeightEnabled ? domUtils.getXY(me.iframe).y:0);
  6157. },200);
  6158. this.update();
  6159. //table的单独处理
  6160. if(me.currentSelectedArr){
  6161. me.currentSelectedArr = [];
  6162. var tds = me.document.getElementsByTagName('td');
  6163. for(var i=0,td;td=tds[i++];){
  6164. if(td.className == me.options.selectedTdClass){
  6165. me.currentSelectedArr.push(td);
  6166. }
  6167. }
  6168. }
  6169. this.clearKey();
  6170. //不能把自己reset了
  6171. me.fireEvent('reset',true);
  6172. me.fireEvent('contentchange')
  6173. };
  6174. this.getScene = function() {
  6175. var range = me.selection.getRange(),
  6176. cont = me.body.innerHTML.replace(fillchar,'');
  6177. //有可能边界落到了<table>|<tbody>这样的位置,所以缩一下位置
  6178. range.shrinkBoundary();
  6179. browser.ie && (cont = cont.replace(/>&nbsp;</g,'><').replace(/\s*</g,'').replace(/>\s*/g,'>'));
  6180. var bookmark = range.createBookmark( true, true ),
  6181. bookCont = me.body.innerHTML.replace(fillchar,'');
  6182. range.moveToBookmark( bookmark ).select( true );
  6183. return {
  6184. bookcontent : bookCont,
  6185. content : cont
  6186. }
  6187. };
  6188. this.save = function() {
  6189. var currentScene = this.getScene(),
  6190. lastScene = this.list[this.index];
  6191. //内容相同位置相同不存
  6192. if ( lastScene && lastScene.content == currentScene.content &&
  6193. lastScene.bookcontent == currentScene.bookcontent
  6194. ) {
  6195. return;
  6196. }
  6197. this.list = this.list.slice( 0, this.index + 1 );
  6198. this.list.push( currentScene );
  6199. //如果大于最大数量了,就把最前的剔除
  6200. if ( this.list.length > maxUndoCount ) {
  6201. this.list.shift();
  6202. }
  6203. this.index = this.list.length - 1;
  6204. this.clearKey();
  6205. //跟新undo/redo状态
  6206. this.update();
  6207. me.fireEvent('contentchange')
  6208. };
  6209. this.update = function() {
  6210. this.hasRedo = this.list[this.index + 1] ? true : false;
  6211. this.hasUndo = this.list[this.index - 1] || this.list.length == 1 ? true : false;
  6212. };
  6213. this.reset = function() {
  6214. this.list = [];
  6215. this.index = 0;
  6216. this.hasUndo = false;
  6217. this.hasRedo = false;
  6218. this.clearKey();
  6219. };
  6220. this.clearKey = function(){
  6221. keycont = 0;
  6222. lastKeyCode = null;
  6223. }
  6224. }
  6225. me.undoManger = new UndoManager();
  6226. function saveScene() {
  6227. this.undoManger.save()
  6228. }
  6229. me.addListener( 'beforeexeccommand', saveScene );
  6230. me.addListener( 'afterexeccommand', saveScene );
  6231. me.addListener('reset',function(type,exclude){
  6232. if(!exclude)
  6233. me.undoManger.reset();
  6234. });
  6235. me.commands['redo'] = me.commands['undo'] = {
  6236. execCommand : function( cmdName ) {
  6237. me.undoManger[cmdName]();
  6238. },
  6239. queryCommandState : function( cmdName ) {
  6240. return me.undoManger['has' + (cmdName.toLowerCase() == 'undo' ? 'Undo' : 'Redo')] ? 0 : -1;
  6241. },
  6242. notNeedUndo : 1
  6243. };
  6244. var keys = {
  6245. // /*Backspace*/ 8:1, /*Delete*/ 46:1,
  6246. /*Shift*/ 16:1, /*Ctrl*/ 17:1, /*Alt*/ 18:1,
  6247. 37:1, 38:1, 39:1, 40:1,
  6248. 13:1 /*enter*/
  6249. },
  6250. keycont = 0,
  6251. lastKeyCode;
  6252. me.addListener( 'keydown', function( type, evt ) {
  6253. var keyCode = evt.keyCode || evt.which;
  6254. if ( !keys[keyCode] && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey ) {
  6255. if ( me.undoManger.list.length == 0 || ((keyCode == 8 ||keyCode == 46) && lastKeyCode != keyCode) ) {
  6256. me.undoManger.save();
  6257. lastKeyCode = keyCode;
  6258. return
  6259. }
  6260. //trace:856
  6261. //修正第一次输入后,回退,再输入要到keycont>maxInputCount才能在回退的问题
  6262. if(me.undoManger.list.length == 2 && me.undoManger.index == 0 && keycont == 0){
  6263. me.undoManger.list.splice(1,1);
  6264. me.undoManger.update();
  6265. }
  6266. lastKeyCode = keyCode;
  6267. keycont++;
  6268. if ( keycont > maxInputCount ) {
  6269. setTimeout( function() {
  6270. me.undoManger.save();
  6271. }, 0 );
  6272. }
  6273. }
  6274. } )
  6275. };
  6276. ///import core
  6277. ///import plugins/inserthtml.js
  6278. ///import plugins/undo.js
  6279. ///import plugins/serialize.js
  6280. ///commands 粘贴
  6281. ///commandsName PastePlain
  6282. ///commandsTitle 纯文本粘贴模式
  6283. /*
  6284. ** @description 粘贴
  6285. * @author zhanyi
  6286. */
  6287. (function() {
  6288. function getClipboardData( callback ) {
  6289. var doc = this.document;
  6290. if ( doc.getElementById( 'baidu_pastebin' ) ) {
  6291. return;
  6292. }
  6293. var range = this.selection.getRange(),
  6294. bk = range.createBookmark(),
  6295. //创建剪贴的容器div
  6296. pastebin = doc.createElement( 'div' );
  6297. pastebin.id = 'baidu_pastebin';
  6298. // Safari 要求div必须有内容,才能粘贴内容进来
  6299. browser.webkit && pastebin.appendChild( doc.createTextNode( domUtils.fillChar + domUtils.fillChar ) );
  6300. doc.body.appendChild( pastebin );
  6301. //trace:717 隐藏的span不能得到top
  6302. //bk.start.innerHTML = '&nbsp;';
  6303. bk.start.style.display = '';
  6304. pastebin.style.cssText = "position:absolute;width:1px;height:1px;overflow:hidden;left:-1000px;white-space:nowrap;top:" +
  6305. //要在现在光标平行的位置加入,否则会出现跳动的问题
  6306. domUtils.getXY( bk.start ).y + 'px';
  6307. range.selectNodeContents( pastebin ).select( true );
  6308. setTimeout( function() {
  6309. if (browser.webkit) {
  6310. for(var i=0,pastebins = doc.querySelectorAll('#baidu_pastebin'),pi;pi=pastebins[i++];){
  6311. if(domUtils.isEmptyNode(pi)){
  6312. domUtils.remove(pi)
  6313. }else{
  6314. pastebin = pi;
  6315. break;
  6316. }
  6317. }
  6318. }
  6319. try{
  6320. pastebin.parentNode.removeChild(pastebin);
  6321. }catch(e){}
  6322. range.moveToBookmark( bk ).select(true);
  6323. callback( pastebin );
  6324. }, 0 );
  6325. }
  6326. UE.plugins['paste'] = function() {
  6327. var me = this;
  6328. var word_img_flag = {flag:""};
  6329. var pasteplain = me.options.pasteplain === true;
  6330. var modify_num = {flag:""};
  6331. me.commands['pasteplain'] = {
  6332. queryCommandState: function (){
  6333. return pasteplain;
  6334. },
  6335. execCommand: function (){
  6336. pasteplain = !pasteplain|0;
  6337. },
  6338. notNeedUndo : 1
  6339. };
  6340. function filter(div){
  6341. var html;
  6342. if ( div.firstChild ) {
  6343. //去掉cut中添加的边界值
  6344. var nodes = domUtils.getElementsByTagName(div,'span');
  6345. for(var i=0,ni;ni=nodes[i++];){
  6346. if(ni.id == '_baidu_cut_start' || ni.id == '_baidu_cut_end'){
  6347. domUtils.remove(ni)
  6348. }
  6349. }
  6350. if(browser.webkit){
  6351. var brs = div.querySelectorAll('div br');
  6352. for(var i=0,bi;bi=brs[i++];){
  6353. var pN = bi.parentNode;
  6354. if(pN.tagName == 'DIV' && pN.childNodes.length ==1){
  6355. pN.innerHTML = '<p><br/></p>';
  6356. domUtils.remove(pN)
  6357. }
  6358. }
  6359. var divs = div.querySelectorAll('#baidu_pastebin');
  6360. for(var i=0,di;di=divs[i++];){
  6361. var tmpP = me.document.createElement('p');
  6362. di.parentNode.insertBefore(tmpP,di);
  6363. while(di.firstChild){
  6364. tmpP.appendChild(di.firstChild)
  6365. }
  6366. domUtils.remove(di)
  6367. }
  6368. var metas = div.querySelectorAll('meta');
  6369. for(var i=0,ci;ci=metas[i++];){
  6370. domUtils.remove(ci);
  6371. }
  6372. var brs = div.querySelectorAll('br');
  6373. for(i=0;ci=brs[i++];){
  6374. if(/^apple-/.test(ci)){
  6375. domUtils.remove(ci)
  6376. }
  6377. }
  6378. }
  6379. if(browser.gecko){
  6380. var dirtyNodes = div.querySelectorAll('[_moz_dirty]')
  6381. for(i=0;ci=dirtyNodes[i++];){
  6382. ci.removeAttribute( '_moz_dirty' )
  6383. }
  6384. }
  6385. if(!browser.ie ){
  6386. var spans = div.querySelectorAll('span.apple-style-span');
  6387. for(var i=0,ci;ci=spans[i++];){
  6388. domUtils.remove(ci,true);
  6389. }
  6390. }
  6391. html = div.innerHTML;
  6392. var f = me.serialize;
  6393. if(f){
  6394. //如果过滤出现问题,捕获它,直接插入内容,避免出现错误导致粘贴整个失败
  6395. try{
  6396. var node = f.transformInput(
  6397. f.parseHTML(
  6398. //todo: 暂时不走dtd的过滤
  6399. f.word(html)//, true
  6400. ),word_img_flag
  6401. );
  6402. //trace:924
  6403. //纯文本模式也要保留段落
  6404. node = f.filter(node,pasteplain ? {
  6405. whiteList: {
  6406. 'p': {'br':1,'BR':1},
  6407. 'br':{'$':{}},
  6408. 'div':{'br':1,'BR':1,'$':{}},
  6409. 'li':{'$':{}},
  6410. 'tr':{'td':1,'$':{}},
  6411. 'td':{'$':{}}
  6412. },
  6413. blackList: {
  6414. 'style':1,
  6415. 'script':1,
  6416. 'object':1
  6417. }
  6418. } : null, !pasteplain ? modify_num : null);
  6419. if(browser.webkit){
  6420. var length = node.children.length,
  6421. child;
  6422. while((child = node.children[length-1]) && child.tag == 'br'){
  6423. node.children.splice(length-1,1);
  6424. length = node.children.length;
  6425. }
  6426. }
  6427. html = f.toHTML(node,pasteplain)
  6428. }catch(e){}
  6429. }
  6430. //自定义的处理
  6431. html = {'html':html};
  6432. me.fireEvent('beforepaste',html);
  6433. //不用在走过滤了
  6434. me.execCommand( 'insertHtml',html.html,true);
  6435. me.fireEvent("afterpaste");
  6436. }
  6437. }
  6438. me.addListener('ready',function(){
  6439. domUtils.on(me.body,'cut',function(){
  6440. var range = me.selection.getRange();
  6441. if(!range.collapsed && me.undoManger){
  6442. me.undoManger.save()
  6443. }
  6444. });
  6445. //ie下beforepaste在点击右键时也会触发,所以用监控键盘才处理
  6446. domUtils.on(me.body, browser.ie ? 'keydown' : 'paste',function(e){
  6447. if(browser.ie && (!e.ctrlKey || e.keyCode != '86'))
  6448. return;
  6449. getClipboardData.call( me, function( div ) {
  6450. filter(div);
  6451. } );
  6452. })
  6453. });
  6454. }
  6455. })();
  6456. ///import core
  6457. ///commands 有序列表,无序列表
  6458. ///commandsName InsertOrderedList,InsertUnorderedList
  6459. ///commandsTitle 有序列表,无序列表
  6460. /**
  6461. * 有序列表
  6462. * @function
  6463. * @name baidu.editor.execCommand
  6464. * @param {String} cmdName insertorderlist插入有序列表
  6465. * @param {String} style 值为:decimal,lower-alpha,lower-roman,upper-alpha,upper-roman
  6466. * @author zhanyi
  6467. */
  6468. /**
  6469. * 无序链接
  6470. * @function
  6471. * @name baidu.editor.execCommand
  6472. * @param {String} cmdName insertunorderlist插入无序列表
  6473. * * @param {String} style 值为:circle,disc,square
  6474. * @author zhanyi
  6475. */
  6476. UE.plugins['list'] = function(){
  6477. var me = this,
  6478. notExchange = {
  6479. 'TD':1,
  6480. 'PRE':1,
  6481. 'BLOCKQUOTE':1
  6482. };
  6483. me.setOpt({
  6484. 'insertorderedlist':[
  6485. ['1,2,3...','decimal'],
  6486. ['a,b,c...','lower-alpha'],
  6487. ['i,ii,iii...','lower-roman'],
  6488. ['A,B,C','upper-alpha'],
  6489. ['I,II,III...','upper-roman']
  6490. ],
  6491. 'insertunorderedlist':[
  6492. ['○ 小圆圈','circle'],
  6493. ['● 小圆点','disc'],
  6494. ['■ 小方块','square']
  6495. ]
  6496. });
  6497. function adjustList(list,tag,style){
  6498. var nextList = list.nextSibling;
  6499. if(nextList && nextList.nodeType == 1 && nextList.tagName.toLowerCase() == tag && (domUtils.getStyle(nextList,'list-style-type')||(tag == 'ol'?'decimal' : 'disc')) == style){
  6500. domUtils.moveChild(nextList,list);
  6501. if(nextList.childNodes.length == 0){
  6502. domUtils.remove(nextList);
  6503. }
  6504. }
  6505. var preList = list.previousSibling;
  6506. if(preList && preList.nodeType == 1 && preList.tagName.toLowerCase() == tag && (domUtils.getStyle(preList,'list-style-type')||(tag == 'ol'?'decimal' : 'disc')) == style){
  6507. domUtils.moveChild(list,preList)
  6508. }
  6509. if(list.childNodes.length == 0){
  6510. domUtils.remove(list);
  6511. }
  6512. }
  6513. me.addListener('keydown', function(type, evt) {
  6514. function preventAndSave(){
  6515. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false)
  6516. me.undoManger && me.undoManger.save()
  6517. }
  6518. var keyCode = evt.keyCode || evt.which;
  6519. if (keyCode == 13) {//回车
  6520. var range = me.selection.getRange(),
  6521. start = domUtils.findParentByTagName(range.startContainer, ['ol','ul'], true,function(node){return node.tagName == 'TABLE'}),
  6522. end = domUtils.findParentByTagName(range.endContainer, ['ol','ul'], true,function(node){return node.tagName == 'TABLE'});
  6523. if (start && end && start === end) {
  6524. if(!range.collapsed){
  6525. start = domUtils.findParentByTagName(range.startContainer, 'li', true);
  6526. end = domUtils.findParentByTagName(range.endContainer, 'li', true);
  6527. if(start && end && start === end){
  6528. range.deleteContents();
  6529. li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  6530. if(li && domUtils.isEmptyBlock(li)){
  6531. pre = li.previousSibling;
  6532. next = li.nextSibling;
  6533. p = me.document.createElement('p');
  6534. domUtils.fillNode(me.document,p);
  6535. parentList = li.parentNode;
  6536. if(pre && next){
  6537. range.setStart(next,0).collapse(true).select(true);
  6538. domUtils.remove(li);
  6539. }else{
  6540. if(!pre && !next || !pre){
  6541. parentList.parentNode.insertBefore(p,parentList);
  6542. } else{
  6543. li.parentNode.parentNode.insertBefore(p,parentList.nextSibling);
  6544. }
  6545. domUtils.remove(li);
  6546. if(!parentList.firstChild){
  6547. domUtils.remove(parentList)
  6548. }
  6549. range.setStart(p,0).setCursor();
  6550. }
  6551. preventAndSave();
  6552. return;
  6553. }
  6554. }else{
  6555. var tmpRange = range.cloneRange(),
  6556. bk = tmpRange.collapse(false).createBookmark();
  6557. range.deleteContents();
  6558. tmpRange.moveToBookmark(bk);
  6559. var li = domUtils.findParentByTagName(tmpRange.startContainer, 'li', true),
  6560. pre = li.previousSibling,
  6561. next = li.nextSibling;
  6562. if (pre ) {
  6563. li = pre;
  6564. if(pre.firstChild && domUtils.isBlockElm(pre.firstChild)){
  6565. pre = pre.firstChild;
  6566. }
  6567. if(domUtils.isEmptyNode(pre))
  6568. domUtils.remove(li);
  6569. }
  6570. if (next ) {
  6571. li = next;
  6572. if(next.firstChild && domUtils.isBlockElm(next.firstChild)){
  6573. next = next.firstChild;
  6574. }
  6575. if(domUtils.isEmptyNode(next))
  6576. domUtils.remove(li);
  6577. }
  6578. tmpRange.select();
  6579. preventAndSave();
  6580. return;
  6581. }
  6582. }
  6583. li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  6584. if (li) {
  6585. if(domUtils.isEmptyBlock(li)){
  6586. bk = range.createBookmark();
  6587. var parentList = li.parentNode;
  6588. if(li!==parentList.lastChild){
  6589. domUtils.breakParent(li,parentList);
  6590. }else{
  6591. parentList.parentNode.insertBefore(li,parentList.nextSibling);
  6592. if(domUtils.isEmptyNode(parentList)){
  6593. domUtils.remove(parentList);
  6594. }
  6595. }
  6596. //嵌套不处理
  6597. if(!dtd.$list[li.parentNode.tagName]){
  6598. if(!domUtils.isBlockElm(li.firstChild)){
  6599. p = me.document.createElement('p');
  6600. li.parentNode.insertBefore(p,li);
  6601. while(li.firstChild){
  6602. p.appendChild(li.firstChild);
  6603. }
  6604. domUtils.remove(li);
  6605. }else{
  6606. domUtils.remove(li,true);
  6607. }
  6608. }
  6609. range.moveToBookmark(bk).select();
  6610. }else{
  6611. var first = li.firstChild;
  6612. if(!first || !domUtils.isBlockElm(first)){
  6613. var p = me.document.createElement('p');
  6614. !li.firstChild && domUtils.fillNode(me.document,p);
  6615. while(li.firstChild){
  6616. p.appendChild(li.firstChild);
  6617. }
  6618. li.appendChild(p);
  6619. first = p;
  6620. }
  6621. var span = me.document.createElement('span');
  6622. range.insertNode(span);
  6623. domUtils.breakParent(span, li);
  6624. var nextLi = span.nextSibling;
  6625. first = nextLi.firstChild;
  6626. if (!first) {
  6627. p = me.document.createElement('p');
  6628. domUtils.fillNode(me.document,p);
  6629. nextLi.appendChild(p);
  6630. first = p;
  6631. }
  6632. if (domUtils.isEmptyNode(first)) {
  6633. first.innerHTML = '';
  6634. domUtils.fillNode(me.document,first);
  6635. }
  6636. range.setStart(first, 0).collapse(true).shrinkBoundary().select();
  6637. domUtils.remove(span);
  6638. pre = nextLi.previousSibling;
  6639. if(pre && domUtils.isEmptyBlock(pre)){
  6640. pre.innerHTML = '<p></p>';
  6641. domUtils.fillNode(me.document,pre.firstChild);
  6642. }
  6643. }
  6644. // }
  6645. preventAndSave();
  6646. }
  6647. }
  6648. }
  6649. if(keyCode == 8){
  6650. //修中ie中li下的问题
  6651. range = me.selection.getRange();
  6652. if (range.collapsed && domUtils.isStartInblock(range)) {
  6653. tmpRange = range.cloneRange().trimBoundary();
  6654. li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  6655. //要在li的最左边,才能处理
  6656. if (li && domUtils.isStartInblock(tmpRange)) {
  6657. if (li && (pre = li.previousSibling)) {
  6658. if (keyCode == 46 && li.childNodes.length)
  6659. return;
  6660. //有可能上边的兄弟节点是个2级菜单,要追加到2级菜单的最后的li
  6661. if(dtd.$list[pre.tagName]){
  6662. pre = pre.lastChild;
  6663. }
  6664. me.undoManger && me.undoManger.save();
  6665. first = li.firstChild;
  6666. if (domUtils.isBlockElm(first)) {
  6667. if (domUtils.isEmptyNode(first)) {
  6668. // range.setEnd(pre, pre.childNodes.length).shrinkBoundary().collapse().select(true);
  6669. pre.appendChild(first);
  6670. range.setStart(first,0).setCursor(false,true);
  6671. //first不是唯一的节点
  6672. while(li.firstChild){
  6673. pre.appendChild(li.firstChild)
  6674. }
  6675. } else {
  6676. start = domUtils.findParentByTagName(range.startContainer, 'p', true);
  6677. if(start && start !== first){
  6678. return;
  6679. }
  6680. span = me.document.createElement('span');
  6681. range.insertNode(span);
  6682. // if (domUtils.isBlockElm(pre.firstChild)) {
  6683. //
  6684. // pre.firstChild.appendChild(span);
  6685. // while (first.firstChild) {
  6686. // pre.firstChild.appendChild(first.firstChild);
  6687. // }
  6688. //
  6689. // } else {
  6690. // while (first.firstChild) {
  6691. // pre.appendChild(first.firstChild);
  6692. // }
  6693. // }
  6694. domUtils.moveChild(li,pre);
  6695. range.setStartBefore(span).collapse(true).select(true);
  6696. domUtils.remove(span)
  6697. }
  6698. } else {
  6699. if (domUtils.isEmptyNode(li)) {
  6700. var p = me.document.createElement('p');
  6701. pre.appendChild(p);
  6702. range.setStart(p,0).setCursor();
  6703. // range.setEnd(pre, pre.childNodes.length).shrinkBoundary().collapse().select(true);
  6704. } else {
  6705. range.setEnd(pre, pre.childNodes.length).collapse().select(true);
  6706. while (li.firstChild) {
  6707. pre.appendChild(li.firstChild)
  6708. }
  6709. }
  6710. }
  6711. domUtils.remove(li);
  6712. me.undoManger && me.undoManger.save();
  6713. domUtils.preventDefault(evt);
  6714. return;
  6715. }
  6716. //trace:980
  6717. if (li && !li.previousSibling) {
  6718. first = li.firstChild;
  6719. //trace:1648 要判断li下只有一个节点
  6720. if (!first || li.lastChild === first && domUtils.isEmptyNode(domUtils.isBlockElm(first) ? first : li)) {
  6721. var p = me.document.createElement('p');
  6722. li.parentNode.parentNode.insertBefore(p, li.parentNode);
  6723. domUtils.fillNode(me.document,p);
  6724. range.setStart(p, 0).setCursor();
  6725. domUtils.remove(!li.nextSibling ? li.parentNode : li);
  6726. me.undoManger && me.undoManger.save();
  6727. domUtils.preventDefault(evt);
  6728. return;
  6729. }
  6730. }
  6731. }
  6732. }
  6733. }
  6734. });
  6735. me.commands['insertorderedlist'] =
  6736. me.commands['insertunorderedlist'] = {
  6737. execCommand : function( command, style ) {
  6738. if(!style){
  6739. style = command.toLowerCase() == 'insertorderedlist' ? 'decimal' : 'disc'
  6740. }
  6741. var me = this,
  6742. range = this.selection.getRange(),
  6743. filterFn = function( node ) {
  6744. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' : !domUtils.isWhitespace( node )
  6745. },
  6746. tag = command.toLowerCase() == 'insertorderedlist' ? 'ol' : 'ul',
  6747. frag = me.document.createDocumentFragment();
  6748. //去掉是因为会出现选到末尾,导致adjustmentBoundary缩到ol/ul的位置
  6749. //range.shrinkBoundary();//.adjustmentBoundary();
  6750. range.adjustmentBoundary().shrinkBoundary();
  6751. var bko = range.createBookmark(true),
  6752. start = domUtils.findParentByTagName(me.document.getElementById(bko.start),'li'),
  6753. modifyStart = 0,
  6754. end = domUtils.findParentByTagName(me.document.getElementById(bko.end),'li'),
  6755. modifyEnd = 0,
  6756. startParent,endParent,
  6757. list,tmp;
  6758. if(start || end){
  6759. start && (startParent = start.parentNode);
  6760. if(!bko.end){
  6761. end = start;
  6762. }
  6763. end && (endParent = end.parentNode);
  6764. if(startParent === endParent){
  6765. while(start !== end){
  6766. tmp = start;
  6767. start = start.nextSibling;
  6768. if(!domUtils.isBlockElm(tmp.firstChild)){
  6769. var p = me.document.createElement('p');
  6770. while(tmp.firstChild){
  6771. p.appendChild(tmp.firstChild)
  6772. }
  6773. tmp.appendChild(p);
  6774. }
  6775. frag.appendChild(tmp);
  6776. }
  6777. tmp = me.document.createElement('span');
  6778. startParent.insertBefore(tmp,end);
  6779. if(!domUtils.isBlockElm(end.firstChild)){
  6780. p = me.document.createElement('p');
  6781. while(end.firstChild){
  6782. p.appendChild(end.firstChild)
  6783. }
  6784. end.appendChild(p);
  6785. }
  6786. frag.appendChild(end);
  6787. domUtils.breakParent(tmp,startParent);
  6788. if(domUtils.isEmptyNode(tmp.previousSibling)){
  6789. domUtils.remove(tmp.previousSibling)
  6790. }
  6791. if(domUtils.isEmptyNode(tmp.nextSibling)){
  6792. domUtils.remove(tmp.nextSibling)
  6793. }
  6794. var nodeStyle = domUtils.getComputedStyle( startParent, 'list-style-type' ) || (command.toLowerCase() == 'insertorderedlist' ? 'decimal' : 'disc');
  6795. if(startParent.tagName.toLowerCase() == tag && nodeStyle == style){
  6796. for(var i=0,ci,tmpFrag = me.document.createDocumentFragment();ci=frag.childNodes[i++];){
  6797. while(ci.firstChild){
  6798. tmpFrag.appendChild(ci.firstChild);
  6799. }
  6800. }
  6801. tmp.parentNode.insertBefore(tmpFrag,tmp);
  6802. }else{
  6803. list = me.document.createElement(tag);
  6804. domUtils.setStyle(list,'list-style-type',style);
  6805. list.appendChild(frag);
  6806. tmp.parentNode.insertBefore(list,tmp);
  6807. }
  6808. domUtils.remove(tmp);
  6809. list && adjustList(list,tag,style);
  6810. range.moveToBookmark(bko).select();
  6811. return;
  6812. }
  6813. //开始
  6814. if(start){
  6815. while(start){
  6816. tmp = start.nextSibling;
  6817. var tmpfrag = me.document.createDocumentFragment(),
  6818. hasBlock = 0;
  6819. while(start.firstChild){
  6820. if(domUtils.isBlockElm(start.firstChild))
  6821. hasBlock = 1;
  6822. tmpfrag.appendChild(start.firstChild);
  6823. }
  6824. if(!hasBlock){
  6825. var tmpP = me.document.createElement('p');
  6826. tmpP.appendChild(tmpfrag);
  6827. frag.appendChild(tmpP)
  6828. }else{
  6829. frag.appendChild(tmpfrag);
  6830. }
  6831. domUtils.remove(start);
  6832. start = tmp;
  6833. }
  6834. startParent.parentNode.insertBefore(frag,startParent.nextSibling);
  6835. if(domUtils.isEmptyNode(startParent)){
  6836. range.setStartBefore(startParent);
  6837. domUtils.remove(startParent)
  6838. }else{
  6839. range.setStartAfter(startParent);
  6840. }
  6841. modifyStart = 1;
  6842. }
  6843. if(end){
  6844. //结束
  6845. start = endParent.firstChild;
  6846. while(start !== end){
  6847. tmp = start.nextSibling;
  6848. tmpfrag = me.document.createDocumentFragment();
  6849. hasBlock = 0;
  6850. while(start.firstChild){
  6851. if(domUtils.isBlockElm(start.firstChild))
  6852. hasBlock = 1;
  6853. tmpfrag.appendChild(start.firstChild);
  6854. }
  6855. if(!hasBlock){
  6856. tmpP = me.document.createElement('p');
  6857. tmpP.appendChild(tmpfrag);
  6858. frag.appendChild(tmpP)
  6859. }else{
  6860. frag.appendChild(tmpfrag);
  6861. }
  6862. domUtils.remove(start);
  6863. start = tmp;
  6864. }
  6865. frag.appendChild(end.firstChild);
  6866. domUtils.remove(end);
  6867. endParent.parentNode.insertBefore(frag,endParent);
  6868. range.setEndBefore(endParent);
  6869. if(domUtils.isEmptyNode(endParent)){
  6870. domUtils.remove(endParent)
  6871. }
  6872. modifyEnd = 1;
  6873. }
  6874. }
  6875. if(!modifyStart){
  6876. range.setStartBefore(me.document.getElementById(bko.start))
  6877. }
  6878. if(bko.end && !modifyEnd){
  6879. range.setEndAfter(me.document.getElementById(bko.end))
  6880. }
  6881. range.enlarge(true,function(node){return notExchange[node.tagName] });
  6882. frag = me.document.createDocumentFragment();
  6883. var bk = range.createBookmark(),
  6884. current = domUtils.getNextDomNode( bk.start, false, filterFn ),
  6885. tmpRange = range.cloneRange(),
  6886. tmpNode,
  6887. block = domUtils.isBlockElm;
  6888. while ( current && current !== bk.end && (domUtils.getPosition( current, bk.end ) & domUtils.POSITION_PRECEDING) ) {
  6889. if ( current.nodeType == 3 || dtd.li[current.tagName] ) {
  6890. if(current.nodeType == 1 && dtd.$list[current.tagName]){
  6891. while(current.firstChild){
  6892. frag.appendChild(current.firstChild)
  6893. }
  6894. tmpNode = domUtils.getNextDomNode( current, false, filterFn );
  6895. domUtils.remove(current);
  6896. current = tmpNode;
  6897. continue;
  6898. }
  6899. tmpNode = current;
  6900. tmpRange.setStartBefore( current );
  6901. while ( current && current !== bk.end && (!block(current) || domUtils.isBookmarkNode(current) )) {
  6902. tmpNode = current;
  6903. current = domUtils.getNextDomNode( current, false, null, function( node ) {
  6904. return !notExchange[node.tagName]
  6905. } );
  6906. }
  6907. if(current && block(current)){
  6908. tmp = domUtils.getNextDomNode( tmpNode, false, filterFn );
  6909. if(tmp && domUtils.isBookmarkNode(tmp)){
  6910. current = domUtils.getNextDomNode( tmp, false, filterFn );
  6911. tmpNode = tmp;
  6912. }
  6913. }
  6914. tmpRange.setEndAfter( tmpNode );
  6915. current = domUtils.getNextDomNode( tmpNode, false, filterFn );
  6916. var li = range.document.createElement( 'li' );
  6917. li.appendChild(tmpRange.extractContents());
  6918. frag.appendChild(li);
  6919. } else {
  6920. current = domUtils.getNextDomNode( current, true, filterFn );
  6921. }
  6922. }
  6923. range.moveToBookmark(bk).collapse(true);
  6924. list = me.document.createElement(tag);
  6925. domUtils.setStyle(list,'list-style-type',style);
  6926. list.appendChild(frag);
  6927. range.insertNode(list);
  6928. //当前list上下看能否合并
  6929. adjustList(list,tag,style);
  6930. range.moveToBookmark(bko).select();
  6931. },
  6932. queryCommandState : function( command ) {
  6933. return this.highlight ? -1 :
  6934. utils.findNode(this.selection.getStartElementPath(),[command.toLowerCase() == 'insertorderedlist' ? 'ol' : 'ul']) ? 1: 0;
  6935. },
  6936. queryCommandValue : function( command ) {
  6937. var node = utils.findNode(this.selection.getStartElementPath(),[command.toLowerCase() == 'insertorderedlist' ? 'ol' : 'ul']);
  6938. return node ? domUtils.getComputedStyle( node, 'list-style-type' ) : null;
  6939. }
  6940. }
  6941. };
  6942. ///import core
  6943. ///import plugins/serialize.js
  6944. ///import plugins/undo.js
  6945. ///commands 查看源码
  6946. ///commandsName Source
  6947. ///commandsTitle 查看源码
  6948. (function (){
  6949. function SourceFormater(config){
  6950. config = config || {};
  6951. this.indentChar = config.indentChar || ' ';
  6952. this.breakChar = config.breakChar || '\n';
  6953. this.selfClosingEnd = config.selfClosingEnd || ' />';
  6954. }
  6955. var unhtml1 = function (){
  6956. var map = { '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' };
  6957. function rep( m ){ return map[m]; }
  6958. return function ( str ) {
  6959. str = str + '';
  6960. return str ? str.replace( /[<>"']/g, rep ) : '';
  6961. };
  6962. }();
  6963. var inline = utils.extend({a:1,A:1},dtd.$inline,true);
  6964. function printAttrs(attrs){
  6965. var buff = [];
  6966. for (var k in attrs) {
  6967. buff.push(k + '="' + unhtml1(attrs[k]) + '"');
  6968. }
  6969. return buff.join(' ');
  6970. }
  6971. SourceFormater.prototype = {
  6972. format: function (html){
  6973. var node = UE.serialize.parseHTML(html);
  6974. this.buff = [];
  6975. this.indents = '';
  6976. this.indenting = 1;
  6977. this.visitNode(node);
  6978. return this.buff.join('');
  6979. },
  6980. visitNode: function (node){
  6981. if (node.type == 'fragment') {
  6982. this.visitChildren(node.children);
  6983. } else if (node.type == 'element') {
  6984. var selfClosing = dtd.$empty[node.tag];
  6985. this.visitTag(node.tag, node.attributes, selfClosing);
  6986. this.visitChildren(node.children);
  6987. if (!selfClosing) {
  6988. this.visitEndTag(node.tag);
  6989. }
  6990. } else if (node.type == 'comment') {
  6991. this.visitComment(node.data);
  6992. } else {
  6993. this.visitText(node.data,dtd.$notTransContent[node.parent.tag]);
  6994. }
  6995. },
  6996. visitChildren: function (children){
  6997. for (var i=0; i<children.length; i++) {
  6998. this.visitNode(children[i]);
  6999. }
  7000. },
  7001. visitTag: function (tag, attrs, selfClosing){
  7002. if (this.indenting) {
  7003. this.indent();
  7004. } else if (!inline[tag]) { // todo: 去掉a, 因为dtd的inline里面没有a
  7005. this.newline();
  7006. this.indent();
  7007. }
  7008. this.buff.push('<', tag);
  7009. var attrPart = printAttrs(attrs);
  7010. if (attrPart) {
  7011. this.buff.push(' ', attrPart);
  7012. }
  7013. if (selfClosing) {
  7014. this.buff.push(this.selfClosingEnd);
  7015. if (tag == 'br') {
  7016. this.newline();
  7017. }
  7018. } else {
  7019. this.buff.push('>');
  7020. this.indents += this.indentChar;
  7021. }
  7022. if (!inline[tag]) {
  7023. this.newline();
  7024. }
  7025. },
  7026. indent: function (){
  7027. this.buff.push(this.indents);
  7028. this.indenting = 0;
  7029. },
  7030. newline: function (){
  7031. this.buff.push(this.breakChar);
  7032. this.indenting = 1;
  7033. },
  7034. visitEndTag: function (tag){
  7035. this.indents = this.indents.slice(0, -this.indentChar.length);
  7036. if (this.indenting) {
  7037. this.indent();
  7038. } else if (!inline[tag]) {
  7039. this.newline();
  7040. this.indent();
  7041. }
  7042. this.buff.push('</', tag, '>');
  7043. },
  7044. visitText: function (text,notTrans){
  7045. if (this.indenting) {
  7046. this.indent();
  7047. }
  7048. // if(!notTrans){
  7049. // text = text.replace(/&nbsp;/g, ' ').replace(/[ ][ ]+/g, function (m){
  7050. // return new Array(m.length + 1).join('&nbsp;');
  7051. // }).replace(/(?:^ )|(?: $)/g, '&nbsp;');
  7052. // }
  7053. text = text.replace(/&nbsp;/g, ' ')
  7054. this.buff.push(text);
  7055. },
  7056. visitComment: function (text){
  7057. if (this.indenting) {
  7058. this.indent();
  7059. }
  7060. this.buff.push('<!--', text, '-->');
  7061. }
  7062. };
  7063. var sourceEditors = {
  7064. textarea: function (editor, holder){
  7065. var textarea = holder.ownerDocument.createElement('textarea');
  7066. textarea.style.cssText = 'position:absolute;resize:none;width:100%;height:100%;border:0;padding:0;margin:0;overflow-y:auto;';
  7067. // todo: IE下只有onresize属性可用... 很纠结
  7068. if (browser.ie && browser.version < 8) {
  7069. textarea.style.width = holder.offsetWidth + 'px';
  7070. textarea.style.height = holder.offsetHeight + 'px';
  7071. holder.onresize = function (){
  7072. textarea.style.width = holder.offsetWidth + 'px';
  7073. textarea.style.height = holder.offsetHeight + 'px';
  7074. };
  7075. }
  7076. holder.appendChild(textarea);
  7077. return {
  7078. setContent: function (content){
  7079. textarea.value = content;
  7080. },
  7081. getContent: function (){
  7082. return textarea.value;
  7083. },
  7084. select: function (){
  7085. var range;
  7086. if (browser.ie) {
  7087. range = textarea.createTextRange();
  7088. range.collapse(true);
  7089. range.select();
  7090. } else {
  7091. //todo: chrome下无法设置焦点
  7092. textarea.setSelectionRange(0, 0);
  7093. textarea.focus();
  7094. }
  7095. },
  7096. dispose: function (){
  7097. holder.removeChild(textarea);
  7098. // todo
  7099. holder.onresize = null;
  7100. textarea = null;
  7101. holder = null;
  7102. }
  7103. };
  7104. },
  7105. codemirror: function (editor, holder){
  7106. var options = {
  7107. mode: "text/html",
  7108. tabMode: "indent",
  7109. lineNumbers: true,
  7110. lineWrapping:true
  7111. };
  7112. var codeEditor = window.CodeMirror(holder, options);
  7113. var dom = codeEditor.getWrapperElement();
  7114. dom.style.cssText = 'position:absolute;left:0;top:0;width:100%;height:100%;font-family:consolas,"Courier new",monospace;font-size:13px;';
  7115. codeEditor.getScrollerElement().style.cssText = 'position:absolute;left:0;top:0;width:100%;height:100%;';
  7116. codeEditor.refresh();
  7117. return {
  7118. setContent: function (content){
  7119. codeEditor.setValue(content);
  7120. },
  7121. getContent: function (){
  7122. return codeEditor.getValue();
  7123. },
  7124. select: function (){
  7125. codeEditor.focus();
  7126. },
  7127. dispose: function (){
  7128. holder.removeChild(dom);
  7129. dom = null;
  7130. codeEditor = null;
  7131. }
  7132. };
  7133. }
  7134. };
  7135. UE.plugins['source'] = function (){
  7136. var me = this;
  7137. var opt = this.options;
  7138. var formatter = new SourceFormater(opt.source);
  7139. var sourceMode = false;
  7140. var sourceEditor;
  7141. opt.sourceEditor = opt.sourceEditor || 'codemirror';
  7142. function createSourceEditor(holder){
  7143. return sourceEditors[opt.sourceEditor == 'codemirror' && window.CodeMirror ? 'codemirror' : 'textarea'](me, holder);
  7144. }
  7145. var bakCssText;
  7146. me.commands['source'] = {
  7147. execCommand: function (){
  7148. sourceMode = !sourceMode;
  7149. if (sourceMode) {
  7150. me.undoManger && me.undoManger.save();
  7151. this.currentSelectedArr && domUtils.clearSelectedArr(this.currentSelectedArr);
  7152. if(browser.gecko)
  7153. me.body.contentEditable = false;
  7154. bakCssText = me.iframe.style.cssText;
  7155. me.iframe.style.cssText += 'position:absolute;left:-32768px;top:-32768px;';
  7156. var content = formatter.format(me.hasContents() ? me.getContent() : '');
  7157. sourceEditor = createSourceEditor(me.iframe.parentNode);
  7158. sourceEditor.setContent(content);
  7159. setTimeout(function (){
  7160. sourceEditor.select();
  7161. });
  7162. } else {
  7163. me.iframe.style.cssText = bakCssText;
  7164. var cont = sourceEditor.getContent() || '<p>' + (browser.ie ? '' : '<br/>')+'</p>';
  7165. cont = cont.replace(/>[\n\r\t]+([ ]{4})+/g,'>').replace(/[\n\r\t]+([ ]{4})+</g,'<').replace(/>[\n\r\t]+</g,'><');
  7166. me.setContent(cont);
  7167. sourceEditor.dispose();
  7168. sourceEditor = null;
  7169. setTimeout(function(){
  7170. var first = me.body.firstChild;
  7171. //trace:1106 都删除空了,下边会报错,所以补充一个p占位
  7172. if(!first){
  7173. me.body.innerHTML = '<p>'+(browser.ie?'':'<br/>')+'</p>';
  7174. first = me.body.firstChild;
  7175. }
  7176. //要在ifm为显示时ff才能取到selection,否则报错
  7177. me.undoManger && me.undoManger.save();
  7178. while(first && first.firstChild){
  7179. first = first.firstChild;
  7180. }
  7181. var range = me.selection.getRange();
  7182. if(first.nodeType == 3 || dtd.$empty[first.tagName]){
  7183. range.setStartBefore(first)
  7184. }else{
  7185. range.setStart(first,0);
  7186. }
  7187. if(browser.gecko){
  7188. var input = document.createElement('input');
  7189. input.style.cssText = 'position:absolute;left:0;top:-32768px';
  7190. document.body.appendChild(input);
  7191. me.body.contentEditable = false;
  7192. setTimeout(function(){
  7193. domUtils.setViewportOffset(input, { left: -32768, top: 0 });
  7194. input.focus();
  7195. setTimeout(function(){
  7196. me.body.contentEditable = true;
  7197. range.setCursor(false,true);
  7198. domUtils.remove(input)
  7199. })
  7200. })
  7201. }else{
  7202. range.setCursor(false,true);
  7203. }
  7204. })
  7205. }
  7206. this.fireEvent('sourcemodechanged', sourceMode);
  7207. },
  7208. queryCommandState: function (){
  7209. return sourceMode|0;
  7210. }
  7211. };
  7212. var oldQueryCommandState = me.queryCommandState;
  7213. me.queryCommandState = function (cmdName){
  7214. cmdName = cmdName.toLowerCase();
  7215. if (sourceMode) {
  7216. return cmdName == 'source' ? 1 : -1;
  7217. }
  7218. return oldQueryCommandState.apply(this, arguments);
  7219. };
  7220. //解决在源码模式下getContent不能得到最新的内容问题
  7221. var oldGetContent = me.getContent;
  7222. me.getContent = function (){
  7223. if(sourceMode && sourceEditor ){
  7224. var html = sourceEditor.getContent();
  7225. if (this.serialize) {
  7226. var node = this.serialize.parseHTML(html);
  7227. node = this.serialize.filter(node);
  7228. html = this.serialize.toHTML(node);
  7229. }
  7230. return html;
  7231. }else{
  7232. return oldGetContent.apply(this, arguments)
  7233. }
  7234. };
  7235. if(opt.sourceEditor == "codemirror"){
  7236. me.addListener("ready",function(){
  7237. utils.loadFile(document,{
  7238. src : opt.codeMirrorJsUrl || opt.UEDITOR_HOME_URL + "third-party/codemirror2.15/codemirror.js",
  7239. tag : "script",
  7240. type : "text/javascript",
  7241. defer : "defer"
  7242. });
  7243. utils.loadFile(document,{
  7244. tag : "link",
  7245. rel : "stylesheet",
  7246. type : "text/css",
  7247. href : opt.codeMirrorCssUrl || opt.UEDITOR_HOME_URL + "third-party/codemirror2.15/codemirror.css"
  7248. });
  7249. });
  7250. }
  7251. };
  7252. })();
  7253. ///import core
  7254. ///commands 快捷键
  7255. ///commandsName ShortCutKeys
  7256. ///commandsTitle 快捷键
  7257. //配置快捷键
  7258. UE.plugins['shortcutkeys'] = function(){
  7259. var me = this,
  7260. shortcutkeys = {
  7261. "ctrl+66" : "Bold" ,//^B
  7262. "ctrl+90" : "Undo" ,//undo
  7263. "ctrl+89" : "Redo", //redo
  7264. "ctrl+73" : "Italic", //^I
  7265. "ctrl+85" : "Underline" ,//^U
  7266. "ctrl+shift+67" : "removeformat", //清除格式
  7267. "ctrl+shift+76" : "justify:left", //居左
  7268. "ctrl+shift+82" : "justify:right", //居右
  7269. "ctrl+65" : "selectAll",
  7270. "ctrl+13" : "autosubmit"//手动提交
  7271. // ,"9" : "indent" //tab
  7272. };
  7273. me.addListener('keydown',function(type,e){
  7274. var keyCode = e.keyCode || e.which,value;
  7275. for ( var i in shortcutkeys ) {
  7276. if ( /^(ctrl)(\+shift)?\+(\d+)$/.test( i.toLowerCase() ) || /^(\d+)$/.test( i ) ) {
  7277. if ( ( (RegExp.$1 == 'ctrl' ? (e.ctrlKey||e.metaKey) : 0)
  7278. && (RegExp.$2 != "" ? e[RegExp.$2.slice(1) + "Key"] : 1)
  7279. && keyCode == RegExp.$3
  7280. ) ||
  7281. keyCode == RegExp.$1
  7282. ){
  7283. value = shortcutkeys[i].split(':');
  7284. me.execCommand( value[0],value[1]);
  7285. domUtils.preventDefault(e)
  7286. }
  7287. }
  7288. }
  7289. });
  7290. };
  7291. ///import core
  7292. ///import plugins/undo.js
  7293. ///commands 设置回车标签p或br
  7294. ///commandsName EnterKey
  7295. ///commandsTitle 设置回车标签p或br
  7296. /**
  7297. * @description 处理回车
  7298. * @author zhanyi
  7299. */
  7300. UE.plugins['enterkey'] = function() {
  7301. var hTag,
  7302. me = this,
  7303. tag = me.options.enterTag;
  7304. me.addListener('keyup', function(type, evt) {
  7305. var keyCode = evt.keyCode || evt.which;
  7306. if (keyCode == 13) {
  7307. var range = me.selection.getRange(),
  7308. start = range.startContainer,
  7309. doSave;
  7310. //修正在h1-h6里边回车后不能嵌套p的问题
  7311. if (!browser.ie) {
  7312. if (/h\d/i.test(hTag)) {
  7313. if (browser.gecko) {
  7314. var h = domUtils.findParentByTagName(start, [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6','blockquote'], true);
  7315. if (!h) {
  7316. me.document.execCommand('formatBlock', false, '<p>');
  7317. doSave = 1;
  7318. }
  7319. } else {
  7320. //chrome remove div
  7321. if (start.nodeType == 1) {
  7322. var tmp = me.document.createTextNode(''),div;
  7323. range.insertNode(tmp);
  7324. div = domUtils.findParentByTagName(tmp, 'div', true);
  7325. if (div) {
  7326. var p = me.document.createElement('p');
  7327. while (div.firstChild) {
  7328. p.appendChild(div.firstChild);
  7329. }
  7330. div.parentNode.insertBefore(p, div);
  7331. domUtils.remove(div);
  7332. range.setStartBefore(tmp).setCursor();
  7333. doSave = 1;
  7334. }
  7335. domUtils.remove(tmp);
  7336. }
  7337. }
  7338. if (me.undoManger && doSave) {
  7339. me.undoManger.save()
  7340. }
  7341. }
  7342. }
  7343. setTimeout(function() {
  7344. me.selection.getRange().scrollToView(me.autoHeightEnabled, me.autoHeightEnabled ? domUtils.getXY(me.iframe).y : 0);
  7345. }, 50)
  7346. }
  7347. });
  7348. me.addListener('keydown', function(type, evt) {
  7349. var keyCode = evt.keyCode || evt.which;
  7350. if (keyCode == 13) {//回车
  7351. if (me.undoManger) {
  7352. me.undoManger.save()
  7353. }
  7354. hTag = '';
  7355. var range = me.selection.getRange();
  7356. if (!range.collapsed) {
  7357. //跨td不能删
  7358. var start = range.startContainer,
  7359. end = range.endContainer,
  7360. startTd = domUtils.findParentByTagName(start, 'td', true),
  7361. endTd = domUtils.findParentByTagName(end, 'td', true);
  7362. if (startTd && endTd && startTd !== endTd || !startTd && endTd || startTd && !endTd) {
  7363. evt.preventDefault ? evt.preventDefault() : ( evt.returnValue = false);
  7364. return;
  7365. }
  7366. }
  7367. me.currentSelectedArr && domUtils.clearSelectedArr(me.currentSelectedArr);
  7368. if (tag == 'p') {
  7369. if (!browser.ie) {
  7370. start = domUtils.findParentByTagName(range.startContainer, ['ol','ul','p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6','blockquote'], true);
  7371. if (!start) {
  7372. me.document.execCommand('formatBlock', false, '<p>');
  7373. if (browser.gecko) {
  7374. range = me.selection.getRange();
  7375. start = domUtils.findParentByTagName(range.startContainer, 'p', true);
  7376. start && domUtils.removeDirtyAttr(start);
  7377. }
  7378. } else {
  7379. hTag = start.tagName;
  7380. start.tagName.toLowerCase() == 'p' && browser.gecko && domUtils.removeDirtyAttr(start);
  7381. }
  7382. }
  7383. } else {
  7384. evt.preventDefault ? evt.preventDefault() : ( evt.returnValue = false);
  7385. if (!range.collapsed) {
  7386. range.deleteContents();
  7387. start = range.startContainer;
  7388. if (start.nodeType == 1 && (start = start.childNodes[range.startOffset])) {
  7389. while (start.nodeType == 1) {
  7390. if (dtd.$empty[start.tagName]) {
  7391. range.setStartBefore(start).setCursor();
  7392. if (me.undoManger) {
  7393. me.undoManger.save()
  7394. }
  7395. return false;
  7396. }
  7397. if (!start.firstChild) {
  7398. var br = range.document.createElement('br');
  7399. start.appendChild(br);
  7400. range.setStart(start, 0).setCursor();
  7401. if (me.undoManger) {
  7402. me.undoManger.save()
  7403. }
  7404. return false;
  7405. }
  7406. start = start.firstChild
  7407. }
  7408. if (start === range.startContainer.childNodes[range.startOffset]) {
  7409. br = range.document.createElement('br');
  7410. range.insertNode(br).setCursor();
  7411. } else {
  7412. range.setStart(start, 0).setCursor();
  7413. }
  7414. } else {
  7415. br = range.document.createElement('br');
  7416. range.insertNode(br).setStartAfter(br).setCursor();
  7417. }
  7418. } else {
  7419. br = range.document.createElement('br');
  7420. range.insertNode(br);
  7421. var parent = br.parentNode;
  7422. if (parent.lastChild === br) {
  7423. br.parentNode.insertBefore(br.cloneNode(true), br);
  7424. range.setStartBefore(br)
  7425. } else {
  7426. range.setStartAfter(br)
  7427. }
  7428. range.setCursor();
  7429. }
  7430. }
  7431. }
  7432. });
  7433. };
  7434. /*
  7435. * 处理特殊键的兼容性问题
  7436. */
  7437. UE.plugins['keystrokes'] = function() {
  7438. var me = this,
  7439. flag = 0,
  7440. keys = domUtils.keys,
  7441. trans = {
  7442. 'B' : 'strong',
  7443. 'I' : 'em',
  7444. 'FONT' : 'span'
  7445. },
  7446. sizeMap = [0, 10, 12, 16, 18, 24, 32, 48],
  7447. listStyle = {
  7448. 'OL':['decimal','lower-alpha','lower-roman','upper-alpha','upper-roman'],
  7449. 'UL':[ 'circle','disc','square']
  7450. };
  7451. me.addListener('keydown', function(type, evt) {
  7452. var keyCode = evt.keyCode || evt.which;
  7453. if(this.selectAll){
  7454. this.selectAll = false;
  7455. if((keyCode == 8 || keyCode == 46)){
  7456. me.undoManger && me.undoManger.save();
  7457. //trace:1633
  7458. me.body.innerHTML = '<p>'+(browser.ie ? '' : '<br/>')+'</p>';
  7459. new dom.Range(me.document).setStart(me.body.firstChild,0).setCursor(false,true);
  7460. me.undoManger && me.undoManger.save();
  7461. //todo 对性能会有影响
  7462. browser.ie && me._selectionChange();
  7463. domUtils.preventDefault(evt);
  7464. return;
  7465. }
  7466. }
  7467. //处理backspace/del
  7468. if (keyCode == 8 ) {//|| keyCode == 46
  7469. var range = me.selection.getRange(),
  7470. tmpRange,
  7471. start,end;
  7472. //当删除到body最开始的位置时,会删除到body,阻止这个动作
  7473. if(range.collapsed){
  7474. start = range.startContainer;
  7475. //有可能是展位符号
  7476. if(domUtils.isWhitespace(start)){
  7477. start = start.parentNode;
  7478. }
  7479. if(domUtils.isEmptyNode(start) && start === me.body.firstChild){
  7480. if(start.tagName != 'P'){
  7481. p = me.document.createElement('p');
  7482. me.body.insertBefore(p,start);
  7483. domUtils.fillNode(me.document,p);
  7484. range.setStart(p,0).setCursor(false,true);
  7485. //trace:1645
  7486. domUtils.remove(start);
  7487. }
  7488. domUtils.preventDefault(evt);
  7489. return;
  7490. }
  7491. }
  7492. if (range.collapsed && range.startContainer.nodeType == 3 && range.startContainer.nodeValue.replace(new RegExp(domUtils.fillChar, 'g'), '').length == 0) {
  7493. range.setStartBefore(range.startContainer).collapse(true)
  7494. }
  7495. //解决选中control元素不能删除的问题
  7496. if (start = range.getClosedNode()) {
  7497. me.undoManger && me.undoManger.save();
  7498. range.setStartBefore(start);
  7499. domUtils.remove(start);
  7500. range.setCursor();
  7501. me.undoManger && me.undoManger.save();
  7502. domUtils.preventDefault(evt);
  7503. return;
  7504. }
  7505. //阻止在table上的删除
  7506. if (!browser.ie) {
  7507. start = domUtils.findParentByTagName(range.startContainer, 'table', true);
  7508. end = domUtils.findParentByTagName(range.endContainer, 'table', true);
  7509. if (start && !end || !start && end || start !== end) {
  7510. evt.preventDefault();
  7511. return;
  7512. }
  7513. //表格里回车,删除时,光标被定位到了p外边,导致多次删除才能到上一行,这里的处理忘记是为什么,暂时注视掉
  7514. //解决trace:1966的问题
  7515. // if (browser.webkit && range.collapsed && start) {
  7516. // tmpRange = range.cloneRange().txtToElmBoundary();
  7517. // start = tmpRange.startContainer;
  7518. // debugger
  7519. // if (domUtils.isBlockElm(start) && !dtd.$tableContent[start.tagName] && !domUtils.getChildCount(start, function(node) {
  7520. // return node.nodeType == 1 ? node.tagName !== 'BR' : 1;
  7521. // })) {
  7522. //
  7523. // tmpRange.setStartBefore(start).setCursor();
  7524. // domUtils.remove(start, true);
  7525. // evt.preventDefault();
  7526. // return;
  7527. // }
  7528. // }
  7529. }
  7530. if (me.undoManger) {
  7531. if (!range.collapsed) {
  7532. me.undoManger.save();
  7533. flag = 1;
  7534. }
  7535. }
  7536. }
  7537. //处理tab键的逻辑
  7538. if (keyCode == 9) {
  7539. range = me.selection.getRange();
  7540. me.undoManger && me.undoManger.save();
  7541. for (var i = 0,txt = '',tabSize = me.options.tabSize|| 4,tabNode = me.options.tabNode || '&nbsp;'; i < tabSize; i++) {
  7542. txt += tabNode;
  7543. }
  7544. var span = me.document.createElement('span');
  7545. span.innerHTML = txt;
  7546. if (range.collapsed) {
  7547. var li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  7548. if (li && domUtils.isStartInblock(range)) {
  7549. bk = range.createBookmark();
  7550. var parentLi = li.parentNode,
  7551. list = me.document.createElement(parentLi.tagName);
  7552. var index = utils.indexOf(listStyle[list.tagName], domUtils.getComputedStyle(parentLi, 'list-style-type'));
  7553. index = index + 1 == listStyle[list.tagName].length ? 0 : index + 1;
  7554. domUtils.setStyle(list, 'list-style-type', listStyle[list.tagName][index]);
  7555. parentLi.insertBefore(list, li);
  7556. list.appendChild(li);
  7557. range.moveToBookmark(bk).select()
  7558. } else
  7559. range.insertNode(span.cloneNode(true).firstChild).setCursor(true);
  7560. } else {
  7561. //处理table
  7562. start = domUtils.findParentByTagName(range.startContainer, 'table', true);
  7563. end = domUtils.findParentByTagName(range.endContainer, 'table', true);
  7564. if (start || end) {
  7565. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  7566. return
  7567. }
  7568. //处理列表 再一个list里处理
  7569. start = domUtils.findParentByTagName(range.startContainer, ['ol','ul'], true);
  7570. end = domUtils.findParentByTagName(range.endContainer, ['ol','ul'], true);
  7571. if (start && end && start === end) {
  7572. var bk = range.createBookmark();
  7573. start = domUtils.findParentByTagName(range.startContainer, 'li', true);
  7574. end = domUtils.findParentByTagName(range.endContainer, 'li', true);
  7575. //在开始单独处理
  7576. if (start === start.parentNode.firstChild) {
  7577. var parentList = me.document.createElement(start.parentNode.tagName);
  7578. start.parentNode.parentNode.insertBefore(parentList, start.parentNode);
  7579. parentList.appendChild(start.parentNode);
  7580. } else {
  7581. parentLi = start.parentNode,
  7582. list = me.document.createElement(parentLi.tagName);
  7583. index = utils.indexOf(listStyle[list.tagName], domUtils.getComputedStyle(parentLi, 'list-style-type'));
  7584. index = index + 1 == listStyle[list.tagName].length ? 0 : index + 1;
  7585. domUtils.setStyle(list, 'list-style-type', listStyle[list.tagName][index]);
  7586. start.parentNode.insertBefore(list, start);
  7587. var nextLi;
  7588. while (start !== end) {
  7589. nextLi = start.nextSibling;
  7590. list.appendChild(start);
  7591. start = nextLi;
  7592. }
  7593. list.appendChild(end);
  7594. }
  7595. range.moveToBookmark(bk).select();
  7596. } else {
  7597. if (start || end) {
  7598. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  7599. return
  7600. }
  7601. //普通的情况
  7602. start = domUtils.findParent(range.startContainer, filterFn);
  7603. end = domUtils.findParent(range.endContainer, filterFn);
  7604. if (start && end && start === end) {
  7605. range.deleteContents();
  7606. range.insertNode(span.cloneNode(true).firstChild).setCursor(true);
  7607. } else {
  7608. var bookmark = range.createBookmark(),
  7609. filterFn = function(node) {
  7610. return domUtils.isBlockElm(node);
  7611. };
  7612. range.enlarge(true);
  7613. var bookmark2 = range.createBookmark(),
  7614. current = domUtils.getNextDomNode(bookmark2.start, false, filterFn);
  7615. while (current && !(domUtils.getPosition(current, bookmark2.end) & domUtils.POSITION_FOLLOWING)) {
  7616. current.insertBefore(span.cloneNode(true).firstChild, current.firstChild);
  7617. current = domUtils.getNextDomNode(current, false, filterFn);
  7618. }
  7619. range.moveToBookmark(bookmark2).moveToBookmark(bookmark).select();
  7620. }
  7621. }
  7622. }
  7623. me.undoManger && me.undoManger.save();
  7624. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  7625. }
  7626. //trace:1634
  7627. //ff的del键在容器空的时候,也会删除
  7628. if(browser.gecko && keyCode == 46){
  7629. range = me.selection.getRange();
  7630. if(range.collapsed){
  7631. start = range.startContainer;
  7632. if(domUtils.isEmptyBlock(start)){
  7633. var parent = start.parentNode;
  7634. while(domUtils.getChildCount(parent) == 1 && !domUtils.isBody(parent)){
  7635. start = parent;
  7636. parent = parent.parentNode;
  7637. }
  7638. if(start === parent.lastChild)
  7639. evt.preventDefault();
  7640. return;
  7641. }
  7642. }
  7643. }
  7644. });
  7645. me.addListener('keyup', function(type, evt) {
  7646. var keyCode = evt.keyCode || evt.which;
  7647. //修复ie/chrome <strong><em>x|</em></strong> 当点退格后在输入文字后会出现 <b><i>x</i></b>
  7648. if (!browser.gecko && !keys[keyCode] && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey) {
  7649. range = me.selection.getRange();
  7650. if (range.collapsed) {
  7651. var start = range.startContainer,
  7652. isFixed = 0;
  7653. while (!domUtils.isBlockElm(start)) {
  7654. if (start.nodeType == 1 && utils.indexOf(['FONT','B','I'], start.tagName) != -1) {
  7655. var tmpNode = me.document.createElement(trans[start.tagName]);
  7656. if (start.tagName == 'FONT') {
  7657. //chrome only remember color property
  7658. tmpNode.style.cssText = (start.getAttribute('size') ? 'font-size:' + (sizeMap[start.getAttribute('size')] || 12) + 'px' : '')
  7659. + ';' + (start.getAttribute('color') ? 'color:' + start.getAttribute('color') : '')
  7660. + ';' + (start.getAttribute('face') ? 'font-family:' + start.getAttribute('face') : '')
  7661. + ';' + start.style.cssText;
  7662. }
  7663. while (start.firstChild) {
  7664. tmpNode.appendChild(start.firstChild)
  7665. }
  7666. start.parentNode.insertBefore(tmpNode, start);
  7667. domUtils.remove(start);
  7668. if (!isFixed) {
  7669. range.setEnd(tmpNode, tmpNode.childNodes.length).collapse(true)
  7670. }
  7671. start = tmpNode;
  7672. isFixed = 1;
  7673. }
  7674. start = start.parentNode;
  7675. }
  7676. isFixed && range.select()
  7677. }
  7678. }
  7679. if (keyCode == 8 ) {//|| keyCode == 46
  7680. //针对ff下在列表首行退格,不能删除空格行的问题
  7681. if(browser.gecko){
  7682. for(var i=0,li,lis = domUtils.getElementsByTagName(this.body,'li');li=lis[i++];){
  7683. if(domUtils.isEmptyNode(li) && !li.previousSibling){
  7684. var liOfPn = li.parentNode;
  7685. domUtils.remove(li);
  7686. if(domUtils.isEmptyNode(liOfPn)){
  7687. domUtils.remove(liOfPn)
  7688. }
  7689. }
  7690. }
  7691. }
  7692. var range,start,parent,
  7693. tds = this.currentSelectedArr;
  7694. if (tds && tds.length > 0) {
  7695. for (var i = 0,ti; ti = tds[i++];) {
  7696. ti.innerHTML = browser.ie ? ( browser.version < 9 ? '&#65279' : '' ) : '<br/>';
  7697. }
  7698. range = new dom.Range(this.document);
  7699. range.setStart(tds[0], 0).setCursor();
  7700. if (flag) {
  7701. me.undoManger.save();
  7702. flag = 0;
  7703. }
  7704. //阻止chrome执行默认的动作
  7705. if (browser.webkit) {
  7706. evt.preventDefault();
  7707. }
  7708. return;
  7709. }
  7710. range = me.selection.getRange();
  7711. //ctrl+a 后全部删除做处理
  7712. //
  7713. // if (domUtils.isEmptyBlock(me.body) && !range.startOffset) {
  7714. // //trace:1633
  7715. // me.body.innerHTML = '<p>'+(browser.ie ? '&nbsp;' : '<br/>')+'</p>';
  7716. // range.setStart(me.body.firstChild,0).setCursor(false,true);
  7717. // me.undoManger && me.undoManger.save();
  7718. // //todo 对性能会有影响
  7719. // browser.ie && me._selectionChange();
  7720. // return;
  7721. // }
  7722. //处理删除不干净的问题
  7723. start = range.startContainer;
  7724. if(domUtils.isWhitespace(start)){
  7725. start = start.parentNode
  7726. }
  7727. //标志位防止空的p无法删除
  7728. var removeFlag = 0;
  7729. while (start.nodeType == 1 && domUtils.isEmptyNode(start) && dtd.$removeEmpty[start.tagName]) {
  7730. removeFlag = 1;
  7731. parent = start.parentNode;
  7732. domUtils.remove(start);
  7733. start = parent;
  7734. }
  7735. if ( removeFlag && start.nodeType == 1 && domUtils.isEmptyNode(start)) {
  7736. //ie下的问题,虽然没有了相应的节点但一旦你输入文字还是会自动把删除的节点加上,
  7737. if (browser.ie) {
  7738. var span = range.document.createElement('span');
  7739. start.appendChild(span);
  7740. range.setStart(start,0).setCursor();
  7741. //for ie
  7742. li = domUtils.findParentByTagName(start,'li',true);
  7743. if(li){
  7744. var next = li.nextSibling;
  7745. while(next){
  7746. if(domUtils.isEmptyBlock(next)){
  7747. li = next;
  7748. next = next.nextSibling;
  7749. domUtils.remove(li);
  7750. continue;
  7751. }
  7752. break;
  7753. }
  7754. }
  7755. } else {
  7756. start.innerHTML = '<br/>';
  7757. range.setStart(start, 0).setCursor(false,true);
  7758. }
  7759. setTimeout(function() {
  7760. if (browser.ie) {
  7761. domUtils.remove(span);
  7762. }
  7763. if (flag) {
  7764. me.undoManger.save();
  7765. flag = 0;
  7766. }
  7767. }, 0)
  7768. } else {
  7769. if (flag) {
  7770. me.undoManger.save();
  7771. flag = 0;
  7772. }
  7773. }
  7774. }
  7775. })
  7776. };
  7777. ///import core
  7778. ///commands 修复chrome下图片不能点击的问题
  7779. ///commandsName FixImgClick
  7780. ///commandsTitle 修复chrome下图片不能点击的问题
  7781. //修复chrome下图片不能点击的问题
  7782. //todo 可以改大小
  7783. UE.plugins['fiximgclick'] = function() {
  7784. var me = this;
  7785. if ( browser.webkit ) {
  7786. me.addListener( 'click', function( type, e ) {
  7787. if ( e.target.tagName == 'IMG' ) {
  7788. var range = new dom.Range( me.document );
  7789. range.selectNode( e.target ).select();
  7790. }
  7791. } )
  7792. }
  7793. };
  7794. ///import core
  7795. ///commands 为非ie浏览器自动添加a标签
  7796. ///commandsName AutoLink
  7797. ///commandsTitle 自动增加链接
  7798. /**
  7799. * @description 为非ie浏览器自动添加a标签
  7800. * @author zhanyi
  7801. */
  7802. UE.plugins['autolink'] = function() {
  7803. var cont = 0;
  7804. if (browser.ie) {
  7805. return;
  7806. }
  7807. var me = this;
  7808. me.addListener('reset',function(){
  7809. cont = 0;
  7810. });
  7811. me.addListener('keydown', function(type, evt) {
  7812. var keyCode = evt.keyCode || evt.which;
  7813. if (keyCode == 32 || keyCode == 13) {
  7814. var sel = me.selection.getNative(),
  7815. range = sel.getRangeAt(0).cloneRange(),
  7816. offset,
  7817. charCode;
  7818. var start = range.startContainer;
  7819. while (start.nodeType == 1 && range.startOffset > 0) {
  7820. start = range.startContainer.childNodes[range.startOffset - 1];
  7821. if (!start)
  7822. break;
  7823. range.setStart(start, start.nodeType == 1 ? start.childNodes.length : start.nodeValue.length);
  7824. range.collapse(true);
  7825. start = range.startContainer;
  7826. }
  7827. do{
  7828. if (range.startOffset == 0) {
  7829. start = range.startContainer.previousSibling;
  7830. while (start && start.nodeType == 1) {
  7831. start = start.lastChild;
  7832. }
  7833. if (!start || domUtils.isFillChar(start))
  7834. break;
  7835. offset = start.nodeValue.length;
  7836. } else {
  7837. start = range.startContainer;
  7838. offset = range.startOffset;
  7839. }
  7840. range.setStart(start, offset - 1);
  7841. charCode = range.toString().charCodeAt(0);
  7842. } while (charCode != 160 && charCode != 32);
  7843. if (range.toString().replace(new RegExp(domUtils.fillChar, 'g'), '').match(/(?:https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.)/i)) {
  7844. while(range.toString().length){
  7845. if(/^(?:https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.)/i.test(range.toString())){
  7846. break;
  7847. }
  7848. try{
  7849. range.setStart(range.startContainer,range.startOffset+1)
  7850. }catch(e){
  7851. //trace:2121
  7852. var start = range.startContainer;
  7853. while(!(next = start.nextSibling)){
  7854. if(domUtils.isBody(start)){
  7855. return;
  7856. }
  7857. start = start.parentNode;
  7858. }
  7859. range.setStart(next,0)
  7860. }
  7861. }
  7862. var a = me.document.createElement('a'),text = me.document.createTextNode(' '),href;
  7863. me.undoManger && me.undoManger.save();
  7864. a.appendChild(range.extractContents());
  7865. a.href = a.innerHTML = a.innerHTML.replace(/<[^>]+>/g,'');
  7866. href = a.getAttribute("href").replace(new RegExp(domUtils.fillChar,'g'),'');
  7867. href = /^(?:https?:\/\/)/ig.test(href) ? href : "http://"+ href;
  7868. a.setAttribute('data_ue_src',href);
  7869. a.href = href;
  7870. range.insertNode(a);
  7871. a.parentNode.insertBefore(text, a.nextSibling);
  7872. range.setStart(text, 0);
  7873. range.collapse(true);
  7874. sel.removeAllRanges();
  7875. sel.addRange(range);
  7876. me.undoManger && me.undoManger.save();
  7877. }
  7878. }
  7879. })
  7880. };
  7881. ///import core
  7882. ///commands 当输入内容超过编辑器高度时,编辑器自动增高
  7883. ///commandsName AutoHeight,autoHeightEnabled
  7884. ///commandsTitle 自动增高
  7885. /**
  7886. * @description 自动伸展
  7887. * @author zhanyi
  7888. */
  7889. UE.plugins['autoheight'] = function () {
  7890. var me = this;
  7891. //提供开关,就算加载也可以关闭
  7892. me.autoHeightEnabled = me.options.autoHeightEnabled !== false ;
  7893. if (!me.autoHeightEnabled)return;
  7894. var bakOverflow,
  7895. span, tmpNode,
  7896. lastHeight = 0,
  7897. currentHeight,
  7898. timer;
  7899. function adjustHeight() {
  7900. clearTimeout(timer);
  7901. timer = setTimeout(function () {
  7902. if (me.queryCommandState('source') != 1) {
  7903. if (!span) {
  7904. span = me.document.createElement('span');
  7905. //trace:1764
  7906. span.style.cssText = 'display:block;width:0;margin:0;padding:0;border:0;clear:both;';
  7907. span.innerHTML = '.';
  7908. }
  7909. tmpNode = span.cloneNode(true);
  7910. me.body.appendChild(tmpNode);
  7911. currentHeight = Math.max(domUtils.getXY(tmpNode).y + tmpNode.offsetHeight, me.options.minFrameHeight);
  7912. if (currentHeight != lastHeight) {
  7913. me.setHeight(currentHeight);
  7914. lastHeight = currentHeight;
  7915. }
  7916. domUtils.remove(tmpNode);
  7917. }
  7918. }, 50)
  7919. }
  7920. me.addListener('destroy', function () {
  7921. me.removeListener('contentchange', adjustHeight);
  7922. me.removeListener('keyup', adjustHeight);
  7923. me.removeListener('mouseup', adjustHeight);
  7924. });
  7925. me.enableAutoHeight = function () {
  7926. if(!me.autoHeightEnabled)return;
  7927. var doc = me.document;
  7928. me.autoHeightEnabled = true;
  7929. bakOverflow = doc.body.style.overflowY;
  7930. doc.body.style.overflowY = 'hidden';
  7931. me.addListener('contentchange', adjustHeight);
  7932. me.addListener('keyup', adjustHeight);
  7933. me.addListener('mouseup', adjustHeight);
  7934. //ff不给事件算得不对
  7935. setTimeout(function () {
  7936. adjustHeight();
  7937. }, browser.gecko ? 100 : 0);
  7938. me.fireEvent('autoheightchanged', me.autoHeightEnabled);
  7939. };
  7940. me.disableAutoHeight = function () {
  7941. me.body.style.overflowY = bakOverflow || '';
  7942. me.removeListener('contentchange', adjustHeight);
  7943. me.removeListener('keyup', adjustHeight);
  7944. me.removeListener('mouseup', adjustHeight);
  7945. me.autoHeightEnabled = false;
  7946. me.fireEvent('autoheightchanged', me.autoHeightEnabled);
  7947. };
  7948. me.addListener('ready', function () {
  7949. me.enableAutoHeight();
  7950. //trace:1764
  7951. var timer;
  7952. domUtils.on(browser.ie ? me.body : me.document,browser.webkit ? 'dragover' : 'drop',function(){
  7953. clearTimeout(timer);
  7954. timer = setTimeout(function(){
  7955. adjustHeight()
  7956. },100)
  7957. });
  7958. });
  7959. };
  7960. ///import core
  7961. ///commands 悬浮工具栏
  7962. ///commandsName AutoFloat,autoFloatEnabled
  7963. ///commandsTitle 悬浮工具栏
  7964. /*
  7965. * modified by chengchao01
  7966. *
  7967. * 注意: 引入此功能后,在IE6下会将body的背景图片覆盖掉!
  7968. */
  7969. UE.plugins['autofloat'] = function() {
  7970. var me = this,
  7971. optsAutoFloatEnabled = me.options.autoFloatEnabled !== false;
  7972. //如果不固定toolbar的位置,则直接退出
  7973. if(!optsAutoFloatEnabled){
  7974. return;
  7975. }
  7976. var uiUtils = UE.ui.uiUtils,
  7977. LteIE6 = browser.ie && browser.version <= 6,
  7978. quirks = browser.quirks;
  7979. function checkHasUI(editor){
  7980. if(!editor.ui){
  7981. alert('autofloat插件功能依赖于UEditor UI\nautofloat定义位置: _src/plugins/autofloat.js');
  7982. throw({
  7983. name: '未包含UI文件',
  7984. message: 'autofloat功能依赖于UEditor UI。autofloat定义位置: _src/plugins/autofloat.js'
  7985. });
  7986. }
  7987. return 1;
  7988. }
  7989. function fixIE6FixedPos(){
  7990. var docStyle = document.body.style;
  7991. docStyle.backgroundImage = 'url("about:blank")';
  7992. docStyle.backgroundAttachment = 'fixed';
  7993. }
  7994. var bakCssText,
  7995. placeHolder = document.createElement('div'),
  7996. toolbarBox,orgTop,
  7997. getPosition,
  7998. flag =true; //ie7模式下需要偏移
  7999. function setFloating(){
  8000. var toobarBoxPos = domUtils.getXY(toolbarBox),
  8001. origalFloat = domUtils.getComputedStyle(toolbarBox,'position'),
  8002. origalLeft = domUtils.getComputedStyle(toolbarBox,'left');
  8003. toolbarBox.style.width = toolbarBox.offsetWidth + 'px';
  8004. toolbarBox.style.zIndex = me.options.zIndex * 1 + 1;
  8005. toolbarBox.parentNode.insertBefore(placeHolder, toolbarBox);
  8006. if (LteIE6 || quirks) {
  8007. if(toolbarBox.style.position != 'absolute'){
  8008. toolbarBox.style.position = 'absolute';
  8009. }
  8010. toolbarBox.style.top = (document.body.scrollTop||document.documentElement.scrollTop) - orgTop + 'px';
  8011. } else {
  8012. if (browser.ie7Compat && flag) {
  8013. flag = false;
  8014. toolbarBox.style.left = domUtils.getXY(toolbarBox).x - document.documentElement.getBoundingClientRect().left+2 + 'px';
  8015. }
  8016. if(toolbarBox.style.position != 'fixed'){
  8017. toolbarBox.style.position = 'fixed';
  8018. toolbarBox.style.top = '0';
  8019. ((origalFloat == 'absolute' || origalFloat == 'relative') && parseFloat(origalLeft)) && (toolbarBox.style.left = toobarBoxPos.x + 'px');
  8020. }
  8021. }
  8022. }
  8023. function unsetFloating(){
  8024. flag = true;
  8025. if(placeHolder.parentNode)
  8026. placeHolder.parentNode.removeChild(placeHolder);
  8027. toolbarBox.style.cssText = bakCssText;
  8028. }
  8029. function updateFloating(){
  8030. var rect3 = getPosition(me.container);
  8031. if (rect3.top < 0 && rect3.bottom - toolbarBox.offsetHeight > 0) {
  8032. setFloating();
  8033. }else{
  8034. unsetFloating();
  8035. }
  8036. }
  8037. var defer_updateFloating = utils.defer(function(){
  8038. updateFloating();
  8039. },browser.ie ? 200 : 100,true);
  8040. me.addListener('destroy',function(){
  8041. domUtils.un(window, ['scroll','resize'], updateFloating);
  8042. me.removeListener('keydown', defer_updateFloating);
  8043. });
  8044. me.addListener('ready', function(){
  8045. if(checkHasUI(me)){
  8046. getPosition = uiUtils.getClientRect;
  8047. toolbarBox = me.ui.getDom('toolbarbox');
  8048. orgTop = getPosition(toolbarBox).top;
  8049. bakCssText = toolbarBox.style.cssText;
  8050. placeHolder.style.height = toolbarBox.offsetHeight + 'px';
  8051. if(LteIE6){
  8052. fixIE6FixedPos();
  8053. }
  8054. me.addListener('autoheightchanged', function (t, enabled){
  8055. if (enabled) {
  8056. domUtils.on(window, ['scroll','resize'], updateFloating);
  8057. me.addListener('keydown', defer_updateFloating);
  8058. } else {
  8059. domUtils.un(window, ['scroll','resize'], updateFloating);
  8060. me.removeListener('keydown', defer_updateFloating);
  8061. }
  8062. });
  8063. me.addListener('beforefullscreenchange', function (t, enabled){
  8064. if (enabled) {
  8065. unsetFloating();
  8066. }
  8067. });
  8068. me.addListener('fullscreenchanged', function (t, enabled){
  8069. if (!enabled) {
  8070. updateFloating();
  8071. }
  8072. });
  8073. me.addListener('sourcemodechanged', function (t, enabled){
  8074. setTimeout(function (){
  8075. updateFloating();
  8076. });
  8077. });
  8078. }
  8079. })
  8080. };
  8081. ///import core
  8082. ///import plugins/inserthtml.js
  8083. ///commands 插入代码
  8084. ///commandsName HighlightCode
  8085. ///commandsTitle 插入代码
  8086. ///commandsDialog dialogs\code\code.html
  8087. UE.plugins['highlight'] = function() {
  8088. var me = this;
  8089. if(!/highlightcode/i.test(me.options.toolbars.join('')))return;
  8090. me.commands['highlightcode'] = {
  8091. execCommand: function (cmdName, code, syntax) {
  8092. if(code && syntax){
  8093. var pre = document.createElement("pre");
  8094. pre.className = "brush: "+syntax+";toolbar:false;";
  8095. pre.style.display = "";
  8096. pre.appendChild(document.createTextNode(code));
  8097. document.body.appendChild(pre);
  8098. if(me.queryCommandState("highlightcode")){
  8099. me.execCommand("highlightcode");
  8100. }
  8101. me.execCommand('inserthtml', SyntaxHighlighter.highlight(pre,null,true),true);
  8102. var div = me.document.getElementById(SyntaxHighlighter.getHighlighterDivId());
  8103. div.setAttribute('highlighter',pre.className);
  8104. domUtils.remove(pre);
  8105. adjustHeight()
  8106. }else{
  8107. var range = this.selection.getRange(),
  8108. start = domUtils.findParentByTagName(range.startContainer, 'table', true),
  8109. end = domUtils.findParentByTagName(range.endContainer, 'table', true),
  8110. codediv;
  8111. if(start && end && start === end && start.parentNode.className.indexOf("syntaxhighlighter")>-1){
  8112. codediv = start.parentNode;
  8113. if(domUtils.isBody(codediv.parentNode)){
  8114. var p = me.document.createElement('p');
  8115. p.innerHTML = browser.ie ? '' : '<br/>';
  8116. me.body.insertBefore(p,codediv);
  8117. range.setStart(p,0)
  8118. }else{
  8119. range.setStartBefore(codediv)
  8120. }
  8121. range.setCursor();
  8122. domUtils.remove(codediv);
  8123. }
  8124. }
  8125. },
  8126. queryCommandState: function(){
  8127. var range = this.selection.getRange(),start,end;
  8128. range.adjustmentBoundary();
  8129. start = domUtils.findParent(range.startContainer,function(node){
  8130. return node.nodeType == 1 && node.tagName == 'DIV' && domUtils.hasClass(node,'syntaxhighlighter')
  8131. },true);
  8132. end = domUtils.findParent(range.endContainer,function(node){
  8133. return node.nodeType == 1 && node.tagName == 'DIV' && domUtils.hasClass(node,'syntaxhighlighter')
  8134. },true);
  8135. return start && end && start == end ? 1 : 0;
  8136. }
  8137. };
  8138. me.addListener('beforeselectionchange',function(){
  8139. me.highlight = me.queryCommandState('highlightcode');
  8140. });
  8141. me.addListener('afterselectionchange',function(){
  8142. me.highlight = 0;
  8143. });
  8144. me.addListener("ready",function(){
  8145. //避免重复加载高亮文件
  8146. if(typeof XRegExp == "undefined"){
  8147. var obj = {
  8148. id : "syntaxhighlighter_js",
  8149. src : me.options.highlightJsUrl || me.options.UEDITOR_HOME_URL + "third-party/SyntaxHighlighter/shCore.js",
  8150. tag : "script",
  8151. type : "text/javascript",
  8152. defer : "defer"
  8153. };
  8154. utils.loadFile(document,obj,function(){
  8155. changePre();
  8156. });
  8157. }
  8158. if(!me.document.getElementById("syntaxhighlighter_css")){
  8159. var obj = {
  8160. id : "syntaxhighlighter_css",
  8161. tag : "link",
  8162. rel : "stylesheet",
  8163. type : "text/css",
  8164. href : me.options.highlightCssUrl ||me.options.UEDITOR_HOME_URL + "third-party/SyntaxHighlighter/shCoreDefault.css"
  8165. };
  8166. utils.loadFile(me.document,obj);
  8167. }
  8168. });
  8169. me.addListener("beforegetcontent",function(type,cmd){
  8170. for(var i=0,di,divs=domUtils.getElementsByTagName(me.body,'div');di=divs[i++];){
  8171. if(di.className == 'container'){
  8172. var pN = di.parentNode;
  8173. while(pN){
  8174. if(pN.tagName == 'DIV' && /highlighter/.test(pN.id)){
  8175. break;
  8176. }
  8177. pN = pN.parentNode;
  8178. }
  8179. if(!pN)return;
  8180. var pre = me.document.createElement('pre');
  8181. for(var str=[],c=0,ci;ci=di.childNodes[c++];){
  8182. str.push(ci[browser.ie?'innerText':'textContent']);
  8183. }
  8184. pre.appendChild(me.document.createTextNode(str.join('\n')));
  8185. pre.className = pN.getAttribute('highlighter');
  8186. pN.parentNode.insertBefore(pre,pN);
  8187. domUtils.remove(pN);
  8188. }
  8189. }
  8190. });
  8191. me.addListener("aftergetcontent",function(type,cmd){
  8192. changePre();
  8193. });
  8194. function adjustHeight(){
  8195. setTimeout(function(){
  8196. var div = me.document.getElementById(SyntaxHighlighter.getHighlighterDivId());
  8197. if(div){
  8198. var tds = div.getElementsByTagName('td');
  8199. for(var i=0,li,ri;li=tds[0].childNodes[i];i++){
  8200. ri = tds[1].firstChild.childNodes[i];
  8201. //trace:1949
  8202. if(ri){
  8203. ri.style.height = li.style.height = ri.offsetHeight + 'px';
  8204. }
  8205. }
  8206. }
  8207. });
  8208. }
  8209. function changePre(){
  8210. for(var i=0,pr,pres = domUtils.getElementsByTagName(me.document,"pre");pr=pres[i++];){
  8211. if(pr.className.indexOf("brush")>-1){
  8212. var pre = document.createElement("pre"),txt,div;
  8213. pre.className = pr.className;
  8214. pre.style.display = "none";
  8215. pre.appendChild(document.createTextNode(pr[browser.ie?'innerText':'textContent']));
  8216. document.body.appendChild(pre);
  8217. try{
  8218. txt = SyntaxHighlighter.highlight(pre,null,true);
  8219. }catch(e){
  8220. domUtils.remove(pre);
  8221. return ;
  8222. }
  8223. div = me.document.createElement("div");
  8224. div.innerHTML = txt;
  8225. div.firstChild.setAttribute('highlighter',pre.className);
  8226. pr.parentNode.insertBefore(div.firstChild,pr);
  8227. domUtils.remove(pre);
  8228. domUtils.remove(pr);
  8229. adjustHeight()
  8230. }
  8231. }
  8232. }
  8233. me.addListener("aftersetcontent",function(){
  8234. changePre();
  8235. });
  8236. //全屏时,重新算一下宽度
  8237. me.addListener('fullscreenchanged',function(){
  8238. var div = domUtils.getElementsByTagName(me.document,'div');
  8239. for(var j=0,di;di=div[j++];){
  8240. if(/^highlighter/.test(di.id)){
  8241. var tds = di.getElementsByTagName('td');
  8242. for(var i=0,li,ri;li=tds[0].childNodes[i];i++){
  8243. ri = tds[1].firstChild.childNodes[i];
  8244. ri.style.height = li.style.height = ri.offsetHeight + 'px';
  8245. }
  8246. }
  8247. }
  8248. })
  8249. };
  8250. ///import core
  8251. ///commands 定制过滤规则
  8252. ///commandsName Serialize
  8253. ///commandsTitle 定制过滤规则
  8254. UE.plugins['serialize'] = function () {
  8255. var ie = browser.ie,
  8256. version = browser.version;
  8257. function ptToPx(value){
  8258. return /pt/.test(value) ? value.replace( /([\d.]+)pt/g, function( str ) {
  8259. return Math.round(parseFloat(str) * 96 / 72) + "px";
  8260. } ) : value;
  8261. }
  8262. var me = this, autoClearEmptyNode = me.options.autoClearEmptyNode,
  8263. EMPTY_TAG = dtd.$empty,
  8264. parseHTML = function () {
  8265. //干掉<a> 后便变得空格,保留</a> 这样的空格
  8266. var RE_PART = /<(?:(?:\/([^>]+)>)|(?:!--([\S|\s]*?)-->)|(?:([^\s\/>]+)\s*((?:(?:"[^"]*")|(?:'[^']*')|[^"'<>])*)\/?>))/g,
  8267. RE_ATTR = /([\w\-:.]+)(?:(?:\s*=\s*(?:(?:"([^"]*)")|(?:'([^']*)')|([^\s>]+)))|(?=\s|$))/g,
  8268. EMPTY_ATTR = {checked:1,compact:1,declare:1,defer:1,disabled:1,ismap:1,multiple:1,nohref:1,noresize:1,noshade:1,nowrap:1,readonly:1,selected:1},
  8269. CDATA_TAG = {script:1,style: 1},
  8270. NEED_PARENT_TAG = {
  8271. "li": { "$": 'ul', "ul": 1, "ol": 1 },
  8272. "dd": { "$": "dl", "dl": 1 },
  8273. "dt": { "$": "dl", "dl": 1 },
  8274. "option": { "$": "select", "select": 1 },
  8275. "td": { "$": "tr", "tr": 1 },
  8276. "th": { "$": "tr", "tr": 1 },
  8277. "tr": { "$": "tbody", "tbody": 1, "thead": 1, "tfoot": 1, "table": 1 },
  8278. "tbody": { "$": "table", 'table':1,"colgroup": 1 },
  8279. "thead": { "$": "table", "table": 1 },
  8280. "tfoot": { "$": "table", "table": 1 },
  8281. "col": { "$": "colgroup","colgroup":1 }
  8282. };
  8283. var NEED_CHILD_TAG = {
  8284. "table": "td", "tbody": "td", "thead": "td", "tfoot": "td", "tr": "td",
  8285. "colgroup": "col",
  8286. "ul": "li", "ol": "li",
  8287. "dl": "dd",
  8288. "select": "option"
  8289. };
  8290. function parse( html, callbacks ) {
  8291. var match,
  8292. nextIndex = 0,
  8293. tagName,
  8294. cdata;
  8295. RE_PART.exec( "" );
  8296. while ( (match = RE_PART.exec( html )) ) {
  8297. var tagIndex = match.index;
  8298. if ( tagIndex > nextIndex ) {
  8299. var text = html.slice( nextIndex, tagIndex );
  8300. if ( cdata ) {
  8301. cdata.push( text );
  8302. } else {
  8303. callbacks.onText( text );
  8304. }
  8305. }
  8306. nextIndex = RE_PART.lastIndex;
  8307. if ( (tagName = match[1]) ) {
  8308. tagName = tagName.toLowerCase();
  8309. if ( cdata && tagName == cdata._tag_name ) {
  8310. callbacks.onCDATA( cdata.join( '' ) );
  8311. cdata = null;
  8312. }
  8313. if ( !cdata ) {
  8314. callbacks.onTagClose( tagName );
  8315. continue;
  8316. }
  8317. }
  8318. if ( cdata ) {
  8319. cdata.push( match[0] );
  8320. continue;
  8321. }
  8322. if ( (tagName = match[3]) ) {
  8323. if ( /="/.test( tagName ) ) {
  8324. continue;
  8325. }
  8326. tagName = tagName.toLowerCase();
  8327. var attrPart = match[4],
  8328. attrMatch,
  8329. attrMap = {},
  8330. selfClosing = attrPart && attrPart.slice( -1 ) == '/';
  8331. if ( attrPart ) {
  8332. RE_ATTR.exec( "" );
  8333. while ( (attrMatch = RE_ATTR.exec( attrPart )) ) {
  8334. var attrName = attrMatch[1].toLowerCase(),
  8335. attrValue = attrMatch[2] || attrMatch[3] || attrMatch[4] || '';
  8336. if ( !attrValue && EMPTY_ATTR[attrName] ) {
  8337. attrValue = attrName;
  8338. }
  8339. if ( attrName == 'style' ) {
  8340. if ( ie && version <= 6 ) {
  8341. attrValue = attrValue.replace( /(?!;)\s*([\w-]+):/g, function ( m, p1 ) {
  8342. return p1.toLowerCase() + ':';
  8343. } );
  8344. }
  8345. }
  8346. //没有值的属性不添加
  8347. if ( attrValue ) {
  8348. attrMap[attrName] = attrValue.replace( /:\s*/g, ':' )
  8349. }
  8350. }
  8351. }
  8352. callbacks.onTagOpen( tagName, attrMap, selfClosing );
  8353. if ( !cdata && CDATA_TAG[tagName] ) {
  8354. cdata = [];
  8355. cdata._tag_name = tagName;
  8356. }
  8357. continue;
  8358. }
  8359. if ( (tagName = match[2]) ) {
  8360. callbacks.onComment( tagName );
  8361. }
  8362. }
  8363. if ( html.length > nextIndex ) {
  8364. callbacks.onText( html.slice( nextIndex, html.length ) );
  8365. }
  8366. }
  8367. return function ( html, forceDtd ) {
  8368. var fragment = {
  8369. type: 'fragment',
  8370. parent: null,
  8371. children: []
  8372. };
  8373. var currentNode = fragment;
  8374. function addChild( node ) {
  8375. node.parent = currentNode;
  8376. currentNode.children.push( node );
  8377. }
  8378. function addElement( element, open ) {
  8379. var node = element;
  8380. // 遇到结构化标签的时候
  8381. if ( NEED_PARENT_TAG[node.tag] ) {
  8382. // 考虑这种情况的时候, 结束之前的标签
  8383. // e.g. <table><tr><td>12312`<tr>`4566
  8384. while ( NEED_PARENT_TAG[currentNode.tag] && NEED_PARENT_TAG[currentNode.tag][node.tag] ) {
  8385. currentNode = currentNode.parent;
  8386. }
  8387. // 如果前一个标签和这个标签是同一级, 结束之前的标签
  8388. // e.g. <ul><li>123<li>
  8389. if ( currentNode.tag == node.tag ) {
  8390. currentNode = currentNode.parent;
  8391. }
  8392. // 向上补齐父标签
  8393. while ( NEED_PARENT_TAG[node.tag] ) {
  8394. if ( NEED_PARENT_TAG[node.tag][currentNode.tag] ) break;
  8395. node = node.parent = {
  8396. type: 'element',
  8397. tag: NEED_PARENT_TAG[node.tag]['$'],
  8398. attributes: {},
  8399. children: [node]
  8400. };
  8401. }
  8402. }
  8403. if ( forceDtd ) {
  8404. // 如果遇到这个标签不能放在前一个标签内部,则结束前一个标签,span单独处理
  8405. while ( dtd[node.tag] && !(currentNode.tag == 'span' ? utils.extend( dtd['strong'], {'a':1,'A':1} ) : (dtd[currentNode.tag] || dtd['div']))[node.tag] ) {
  8406. if ( tagEnd( currentNode ) ) continue;
  8407. if ( !currentNode.parent ) break;
  8408. currentNode = currentNode.parent;
  8409. }
  8410. }
  8411. node.parent = currentNode;
  8412. currentNode.children.push( node );
  8413. if ( open ) {
  8414. currentNode = element;
  8415. }
  8416. if ( element.attributes.style ) {
  8417. element.attributes.style = element.attributes.style.toLowerCase();
  8418. }
  8419. return element;
  8420. }
  8421. // 结束一个标签的时候,需要判断一下它是否缺少子标签
  8422. // e.g. <table></table>
  8423. function tagEnd( node ) {
  8424. var needTag;
  8425. if ( !node.children.length && (needTag = NEED_CHILD_TAG[node.tag]) ) {
  8426. addElement( {
  8427. type: 'element',
  8428. tag: needTag,
  8429. attributes: {},
  8430. children: []
  8431. }, true );
  8432. return true;
  8433. }
  8434. return false;
  8435. }
  8436. parse( html, {
  8437. onText: function ( text ) {
  8438. while ( !(dtd[currentNode.tag] || dtd['div'])['#'] ) {
  8439. //节点之间的空白不能当作节点处理
  8440. // if(/^[ \t\r\n]+$/.test( text )){
  8441. // return;
  8442. // }
  8443. if ( tagEnd( currentNode ) ) continue;
  8444. currentNode = currentNode.parent;
  8445. }
  8446. //if(/^[ \t\n\r]*/.test(text))
  8447. addChild( {
  8448. type: 'text',
  8449. data: text
  8450. } );
  8451. },
  8452. onComment: function ( text ) {
  8453. addChild( {
  8454. type: 'comment',
  8455. data: text
  8456. } );
  8457. },
  8458. onCDATA: function ( text ) {
  8459. while ( !(dtd[currentNode.tag] || dtd['div'])['#'] ) {
  8460. if ( tagEnd( currentNode ) ) continue;
  8461. currentNode = currentNode.parent;
  8462. }
  8463. addChild( {
  8464. type: 'cdata',
  8465. data: text
  8466. } );
  8467. },
  8468. onTagOpen: function ( tag, attrs, closed ) {
  8469. closed = closed || EMPTY_TAG[tag] ;
  8470. addElement( {
  8471. type: 'element',
  8472. tag: tag,
  8473. attributes: attrs,
  8474. closed: closed,
  8475. children: []
  8476. }, !closed );
  8477. },
  8478. onTagClose: function ( tag ) {
  8479. var node = currentNode;
  8480. // 向上找匹配的标签, 这里不考虑dtd的情况是因为tagOpen的时候已经处理过了, 这里不会遇到
  8481. while ( node && tag != node.tag ) {
  8482. node = node.parent;
  8483. }
  8484. if ( node ) {
  8485. // 关闭中间的标签
  8486. for ( var tnode = currentNode; tnode !== node.parent; tnode = tnode.parent ) {
  8487. tagEnd( tnode );
  8488. }
  8489. //去掉空白的inline节点
  8490. //分页,锚点保留
  8491. //|| dtd.$removeEmptyBlock[node.tag])
  8492. // if ( !node.children.length && dtd.$removeEmpty[node.tag] && !node.attributes.anchorname && node.attributes['class'] != 'pagebreak' && node.tag != 'a') {
  8493. //
  8494. // node.parent.children.pop();
  8495. // }
  8496. currentNode = node.parent;
  8497. } else {
  8498. // 如果没有找到开始标签, 则创建新标签
  8499. // eg. </div> => <div></div>
  8500. //针对视屏网站embed会给结束符,这里特殊处理一下
  8501. if ( !(dtd.$removeEmpty[tag] || dtd.$removeEmptyBlock[tag] || tag == 'embed') ) {
  8502. node = {
  8503. type: 'element',
  8504. tag: tag,
  8505. attributes: {},
  8506. children: []
  8507. };
  8508. addElement( node, true );
  8509. tagEnd( node );
  8510. currentNode = node.parent;
  8511. }
  8512. }
  8513. }
  8514. } );
  8515. // 处理这种情况, 只有开始标签没有结束标签的情况, 需要关闭开始标签
  8516. // eg. <table>
  8517. while ( currentNode !== fragment ) {
  8518. tagEnd( currentNode );
  8519. currentNode = currentNode.parent;
  8520. }
  8521. return fragment;
  8522. };
  8523. }();
  8524. var unhtml1 = function () {
  8525. var map = { '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' };
  8526. function rep( m ) {
  8527. return map[m];
  8528. }
  8529. return function ( str ) {
  8530. str = str + '';
  8531. return str ? str.replace( /[<>"']/g, rep ) : '';
  8532. };
  8533. }();
  8534. var toHTML = function () {
  8535. function printChildren( node, pasteplain ) {
  8536. var children = node.children;
  8537. var buff = [];
  8538. for ( var i = 0,ci; ci = children[i]; i++ ) {
  8539. buff.push( toHTML( ci, pasteplain ) );
  8540. }
  8541. return buff.join( '' );
  8542. }
  8543. function printAttrs( attrs ) {
  8544. var buff = [];
  8545. for ( var k in attrs ) {
  8546. var value = attrs[k];
  8547. if(k == 'style'){
  8548. //pt==>px
  8549. value = ptToPx(value);
  8550. //color rgb ==> hex
  8551. if(/rgba?\s*\([^)]*\)/.test(value)){
  8552. value = value.replace( /rgba?\s*\(([^)]*)\)/g, function( str ) {
  8553. return utils.fixColor('color',str);
  8554. } )
  8555. }
  8556. //过滤掉所有的white-space,在纯文本编辑器里粘贴过来的内容,到chrome中会带有span和white-space属性,导致出现不能折行的情况
  8557. //所以在这里去掉这个属性
  8558. attrs[k] = utils.optCss(value.replace(/windowtext/g,'#000'))
  8559. .replace(/white-space[^;]+;/g,'');
  8560. }
  8561. buff.push( k + '="' + unhtml1( attrs[k] ) + '"' );
  8562. }
  8563. return buff.join( ' ' )
  8564. }
  8565. function printData( node, notTrans ) {
  8566. //trace:1399 输入html代码时空格转换成为&nbsp;
  8567. //node.data.replace(/&nbsp;/g,' ') 针对pre中的空格和出现的&nbsp;把他们在得到的html代码中都转换成为空格,为了在源码模式下显示为空格而不是&nbsp;
  8568. return notTrans ? node.data.replace(/&nbsp;/g,' ') : unhtml1( node.data ).replace(/ /g,'&nbsp;');
  8569. }
  8570. //纯文本模式下标签转换
  8571. var transHtml = {
  8572. 'div':'p',
  8573. 'li':'p',
  8574. 'tr':'p',
  8575. 'br':'br',
  8576. 'p':'p'//trace:1398 碰到p标签自己要加上p,否则transHtml[tag]是undefined
  8577. };
  8578. function printElement( node, pasteplain ) {
  8579. if ( node.type == 'element' && !node.children.length && (dtd.$removeEmpty[node.tag]) && node.tag != 'a' && utils.isEmptyObject(node.attributes) && autoClearEmptyNode) {// 锚点保留
  8580. return html;
  8581. }
  8582. var tag = node.tag;
  8583. if ( pasteplain && tag == 'td' ) {
  8584. if ( !html ) html = '';
  8585. html += printChildren( node, pasteplain ) + '&nbsp;&nbsp;&nbsp;';
  8586. } else {
  8587. var attrs = printAttrs( node.attributes );
  8588. var html = '<' + (pasteplain && transHtml[tag] ? transHtml[tag] : tag) + (attrs ? ' ' + attrs : '') + (EMPTY_TAG[tag] ? ' />' : '>');
  8589. if ( !EMPTY_TAG[tag] ) {
  8590. //trace:1627 ,2070
  8591. //p标签为空,将不占位这里占位符不起作用,用&nbsp;或者br
  8592. if( tag == 'p' && !node.children.length){
  8593. html += browser.ie ? '&nbsp;' : '<br/>';
  8594. }
  8595. html += printChildren( node, pasteplain );
  8596. html += '</' + (pasteplain && transHtml[tag] ? transHtml[tag] : tag) + '>';
  8597. }
  8598. }
  8599. return html;
  8600. }
  8601. return function ( node, pasteplain ) {
  8602. if ( node.type == 'fragment' ) {
  8603. return printChildren( node, pasteplain );
  8604. } else if ( node.type == 'element' ) {
  8605. return printElement( node, pasteplain );
  8606. } else if ( node.type == 'text' || node.type == 'cdata' ) {
  8607. return printData( node, dtd.$notTransContent[node.parent.tag] );
  8608. } else if ( node.type == 'comment' ) {
  8609. return '<!--' + node.data + '-->';
  8610. }
  8611. return '';
  8612. };
  8613. }();
  8614. //过滤word
  8615. var transformWordHtml = function () {
  8616. function isWordDocument( strValue ) {
  8617. var re = new RegExp( /(class="?Mso|style="[^"]*\bmso\-|w:WordDocument|<v:)/ig );
  8618. return re.test( strValue );
  8619. }
  8620. function ensureUnits( v ) {
  8621. v = v.replace( /([\d.]+)([\w]+)?/g, function ( m, p1, p2 ) {
  8622. return (Math.round( parseFloat( p1 ) ) || 1) + (p2 || 'px');
  8623. } );
  8624. return v;
  8625. }
  8626. function filterPasteWord( str ) {
  8627. str = str.replace( /<!--\s*EndFragment\s*-->[\s\S]*$/, '' )
  8628. //remove link break
  8629. .replace( /^(\r\n|\n|\r)|(\r\n|\n|\r)$/ig, "" )
  8630. //remove &nbsp; entities at the start of contents
  8631. .replace( /^\s*(&nbsp;)+/ig, "" )
  8632. //remove &nbsp; entities at the end of contents
  8633. .replace( /(&nbsp;|<br[^>]*>)+\s*$/ig, "" )
  8634. // Word comments like conditional comments etc
  8635. .replace( /<!--[\s\S]*?-->/ig, "" )
  8636. //转换图片
  8637. .replace(/<v:shape [^>]*>[\s\S]*?.<\/v:shape>/gi,function(str){
  8638. try{
  8639. var width = str.match(/width:([ \d.]*p[tx])/i)[1],
  8640. height = str.match(/height:([ \d.]*p[tx])/i)[1],
  8641. src = str.match(/src=\s*"([^"]*)"/i)[1];
  8642. return '<img width="'+ptToPx(width)+'" height="'+ptToPx(height)+'" src="' + src + '" />'
  8643. } catch(e){
  8644. return '';
  8645. }
  8646. })
  8647. //去掉多余的属性
  8648. .replace( /v:\w+=["']?[^'"]+["']?/g, '' )
  8649. // Remove comments, scripts (e.g., msoShowComment), XML tag, VML content, MS Office namespaced tags, and a few other tags
  8650. .replace( /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|xml|meta|link|style|\w+:\w+)(?=[\s\/>]))[^>]*>/gi, "" )
  8651. //convert word headers to strong
  8652. .replace( /<p [^>]*class="?MsoHeading"?[^>]*>(.*?)<\/p>/gi, "<p><strong>$1</strong></p>" )
  8653. //remove lang attribute
  8654. .replace( /(lang)\s*=\s*([\'\"]?)[\w-]+\2/ig, "" )
  8655. //清除多余的font不能匹配&nbsp;有可能是空格
  8656. .replace( /<font[^>]*>\s*<\/font>/gi, '' )
  8657. //清除多余的class
  8658. .replace( /class\s*=\s*["']?(?:(?:MsoTableGrid)|(?:MsoListParagraph)|(?:MsoNormal(Table)?))\s*["']?/gi, '' );
  8659. // Examine all styles: delete junk, transform some, and keep the rest
  8660. //修复了原有的问题, 比如style='fontsize:"宋体"'原来的匹配失效了
  8661. str = str.replace( /(<[a-z][^>]*)\sstyle=(["'])([^\2]*?)\2/gi, function( str, tag, tmp, style ) {
  8662. var n = [],
  8663. i = 0,
  8664. s = style.replace( /^\s+|\s+$/, '' ).replace( /&quot;/gi, "'" ).split( /;\s*/g );
  8665. // Examine each style definition within the tag's style attribute
  8666. for ( var i = 0; i < s.length; i++ ) {
  8667. var v = s[i];
  8668. var name, value,
  8669. parts = v.split( ":" );
  8670. if ( parts.length == 2 ) {
  8671. name = parts[0].toLowerCase();
  8672. value = parts[1].toLowerCase();
  8673. // Translate certain MS Office styles into their CSS equivalents
  8674. switch ( name ) {
  8675. case "mso-padding-alt":
  8676. case "mso-padding-top-alt":
  8677. case "mso-padding-right-alt":
  8678. case "mso-padding-bottom-alt":
  8679. case "mso-padding-left-alt":
  8680. case "mso-margin-alt":
  8681. case "mso-margin-top-alt":
  8682. case "mso-margin-right-alt":
  8683. case "mso-margin-bottom-alt":
  8684. case "mso-margin-left-alt":
  8685. //ie下会出现挤到一起的情况
  8686. // case "mso-table-layout-alt":
  8687. case "mso-height":
  8688. case "mso-width":
  8689. case "mso-vertical-align-alt":
  8690. //trace:1819 ff下会解析出padding在table上
  8691. if(!/<table/.test(tag))
  8692. n[i] = name.replace( /^mso-|-alt$/g, "" ) + ":" + ensureUnits( value );
  8693. continue;
  8694. case "horiz-align":
  8695. n[i] = "text-align:" + value;
  8696. continue;
  8697. case "vert-align":
  8698. n[i] = "vertical-align:" + value;
  8699. continue;
  8700. case "font-color":
  8701. case "mso-foreground":
  8702. n[i] = "color:" + value;
  8703. continue;
  8704. case "mso-background":
  8705. case "mso-highlight":
  8706. n[i] = "background:" + value;
  8707. continue;
  8708. case "mso-default-height":
  8709. n[i] = "min-height:" + ensureUnits( value );
  8710. continue;
  8711. case "mso-default-width":
  8712. n[i] = "min-width:" + ensureUnits( value );
  8713. continue;
  8714. case "mso-padding-between-alt":
  8715. n[i] = "border-collapse:separate;border-spacing:" + ensureUnits( value );
  8716. continue;
  8717. case "text-line-through":
  8718. if ( (value == "single") || (value == "double") ) {
  8719. n[i] = "text-decoration:line-through";
  8720. }
  8721. continue;
  8722. //trace:1870
  8723. // //word里边的字体统一干掉
  8724. // case 'font-family':
  8725. // continue;
  8726. case "mso-zero-height":
  8727. if ( value == "yes" ) {
  8728. n[i] = "display:none";
  8729. }
  8730. continue;
  8731. case 'margin':
  8732. if ( !/[1-9]/.test( parts[1] ) ) {
  8733. continue;
  8734. }
  8735. }
  8736. if ( /^(mso|column|font-emph|lang|layout|line-break|list-image|nav|panose|punct|row|ruby|sep|size|src|tab-|table-border|text-(?:decor|trans)|top-bar|version|vnd|word-break)/.test( name ) ) {
  8737. // if ( !/mso\-list/.test( name ) )
  8738. continue;
  8739. }
  8740. if(/text\-indent|padding|margin/.test(name) && /\-[\d.]+/.test(value)){
  8741. continue;
  8742. }
  8743. n[i] = name + ":" + parts[1]; // Lower-case name, but keep value case
  8744. }
  8745. }
  8746. // If style attribute contained any valid styles the re-write it; otherwise delete style attribute.
  8747. if ( i > 0 ) {
  8748. return tag + ' style="' + n.join( ';' ) + '"';
  8749. } else {
  8750. return tag;
  8751. }
  8752. } );
  8753. str = str.replace( /([ ]+)<\/span>/ig, function ( m, p ) {
  8754. return new Array( p.length + 1 ).join( '&nbsp;' ) + '</span>';
  8755. } );
  8756. return str;
  8757. }
  8758. return function ( html ) {
  8759. //过了word,才能转p->li
  8760. first = null;
  8761. parentTag = '',liStyle = '',firstTag = '';
  8762. if ( isWordDocument( html ) ) {
  8763. html = filterPasteWord( html );
  8764. }
  8765. return html.replace( />[ \t\r\n]*</g, '><' );
  8766. };
  8767. }();
  8768. var NODE_NAME_MAP = {
  8769. 'text': '#text',
  8770. 'comment': '#comment',
  8771. 'cdata': '#cdata-section',
  8772. 'fragment': '#document-fragment'
  8773. };
  8774. // function _likeLi( node ) {
  8775. // var a;
  8776. // if ( node && node.tag == 'p' ) {
  8777. // //office 2011下有效
  8778. // if ( node.attributes['class'] == 'MsoListParagraph' || /mso-list/.test( node.attributes.style ) ) {
  8779. // a = 1;
  8780. // } else {
  8781. // var firstChild = node.children[0];
  8782. // if ( firstChild && firstChild.tag == 'span' && /Wingdings/i.test( firstChild.attributes.style ) ) {
  8783. // a = 1;
  8784. // }
  8785. // }
  8786. // }
  8787. // return a;
  8788. // }
  8789. //为p==>li 做个标志
  8790. var first,
  8791. // orderStyle = {
  8792. // 'decimal' : /\d+/,
  8793. // 'lower-roman': /^m{0,4}(cm|cd|d?c{0,3})(xc|xl|l?x{0,3})(ix|iv|v?i{0,3})$/,
  8794. // 'upper-roman': /^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,
  8795. // 'lower-alpha' : /^\(?[a-z]+\)?$/,
  8796. // 'upper-alpha': /^\(?[A-Z]+\)?$/
  8797. // },
  8798. // unorderStyle = { 'disc' : /^[l\u00B7\u2002]/, 'circle' : /^[\u006F\u00D8]/,'square' : /^[\u006E\u25C6]/},
  8799. parentTag = '',liStyle = '',firstTag;
  8800. //写入编辑器时,调用,进行转换操作
  8801. function transNode( node, word_img_flag ) {
  8802. var sizeMap = [0, 10, 12, 16, 18, 24, 32, 48],
  8803. attr,
  8804. indexOf = utils.indexOf;
  8805. switch ( node.tag ) {
  8806. case 'script':
  8807. node.tag = 'div';
  8808. node.attributes._ue_div_script = 1;
  8809. node.attributes._ue_script_data = node.children[0] ? encodeURIComponent(node.children[0].data) : '';
  8810. node.children = [];
  8811. break;
  8812. case 'img':
  8813. //todo base64暂时去掉,后边做远程图片上传后,干掉这个
  8814. if(node.attributes.src && /^data:/.test(node.attributes.src)){
  8815. return {
  8816. type : 'fragment',
  8817. children:[]
  8818. }
  8819. }
  8820. if ( node.attributes.src && /^(?:file)/.test( node.attributes.src ) ) {
  8821. if ( !/(gif|bmp|png|jpg|jpeg)$/.test( node.attributes.src ) ) {
  8822. return {
  8823. type : 'fragment',
  8824. children:[]
  8825. }
  8826. }
  8827. node.attributes.word_img = node.attributes.src;
  8828. node.attributes.src = me.options.UEDITOR_HOME_URL + 'themes/default/images/spacer.gif';
  8829. var flag = parseInt(node.attributes.width)<128||parseInt(node.attributes.height)<43;
  8830. node.attributes.style="background:url(" + me.options.UEDITOR_HOME_URL +"themes/default/images/"+(flag?"word.gif":"localimage.png")+") no-repeat center center;border:1px solid #ddd";
  8831. //node.attributes.style = 'width:395px;height:173px;';
  8832. word_img_flag && (word_img_flag.flag = 1);
  8833. }
  8834. if(browser.ie && browser.version < 7 )
  8835. node.attributes.orgSrc = node.attributes.src;
  8836. node.attributes.data_ue_src = node.attributes.data_ue_src || node.attributes.src;
  8837. break;
  8838. case 'li':
  8839. var child = node.children[0];
  8840. if ( !child || child.type != 'element' || child.tag != 'p' && dtd.p[child.tag] ) {
  8841. var tmpPNode = {
  8842. type: 'element',
  8843. tag: 'p',
  8844. attributes: {},
  8845. parent : node
  8846. };
  8847. tmpPNode.children = child ? node.children :[
  8848. browser.ie ? {
  8849. type:'text',
  8850. data:domUtils.fillChar,
  8851. parent : tmpPNode
  8852. }:
  8853. {
  8854. type : 'element',
  8855. tag : 'br',
  8856. attributes:{},
  8857. closed: true,
  8858. children: [],
  8859. parent : tmpPNode
  8860. }
  8861. ];
  8862. node.children = [tmpPNode];
  8863. }
  8864. break;
  8865. case 'table':
  8866. case 'td':
  8867. optStyle( node );
  8868. break;
  8869. case 'a'://锚点,a==>img
  8870. if ( node.attributes['anchorname'] ) {
  8871. node.tag = 'img';
  8872. node.attributes = {
  8873. 'class' : 'anchorclass',
  8874. 'anchorname':node.attributes['name']
  8875. };
  8876. node.closed = 1;
  8877. }
  8878. node.attributes.href && (node.attributes.data_ue_src = node.attributes.href);
  8879. break;
  8880. case 'b':
  8881. node.tag = node.name = 'strong';
  8882. break;
  8883. case 'i':
  8884. node.tag = node.name = 'em';
  8885. break;
  8886. case 'u':
  8887. node.tag = node.name = 'span';
  8888. node.attributes.style = (node.attributes.style || '') + ';text-decoration:underline;';
  8889. break;
  8890. case 's':
  8891. case 'del':
  8892. node.tag = node.name = 'span';
  8893. node.attributes.style = (node.attributes.style || '') + ';text-decoration:line-through;';
  8894. if ( node.children.length == 1 ) {
  8895. child = node.children[0];
  8896. if ( child.tag == node.tag ) {
  8897. node.attributes.style += ";" + child.attributes.style;
  8898. node.children = child.children;
  8899. }
  8900. }
  8901. break;
  8902. case 'span':
  8903. // if ( /mso-list/.test( node.attributes.style ) ) {
  8904. //
  8905. //
  8906. // //判断了两次就不在判断了
  8907. // if ( firstTag != 'end' ) {
  8908. //
  8909. // var ci = node.children[0],p;
  8910. // while ( ci.type == 'element' ) {
  8911. // ci = ci.children[0];
  8912. // }
  8913. // for ( p in unorderStyle ) {
  8914. // if ( unorderStyle[p].test( ci.data ) ) {
  8915. //
  8916. // // ci.data = ci.data.replace(unorderStyle[p],'');
  8917. // parentTag = 'ul';
  8918. // liStyle = p;
  8919. // break;
  8920. // }
  8921. // }
  8922. //
  8923. //
  8924. // if ( !parentTag ) {
  8925. // for ( p in orderStyle ) {
  8926. // if ( orderStyle[p].test( ci.data.replace( /\.$/, '' ) ) ) {
  8927. // // ci.data = ci.data.replace(orderStyle[p],'');
  8928. // parentTag = 'ol';
  8929. // liStyle = p;
  8930. // break;
  8931. // }
  8932. // }
  8933. // }
  8934. // if ( firstTag ) {
  8935. // if ( ci.data == firstTag ) {
  8936. // if ( parentTag != 'ul' ) {
  8937. // liStyle = '';
  8938. // }
  8939. // parentTag = 'ul'
  8940. // } else {
  8941. // if ( parentTag != 'ol' ) {
  8942. // liStyle = '';
  8943. // }
  8944. // parentTag = 'ol'
  8945. // }
  8946. // firstTag = 'end'
  8947. // } else {
  8948. // firstTag = ci.data
  8949. // }
  8950. // if ( parentTag ) {
  8951. // var tmpNode = node;
  8952. // while ( tmpNode && tmpNode.tag != 'ul' && tmpNode.tag != 'ol' ) {
  8953. // tmpNode = tmpNode.parent;
  8954. // }
  8955. // if(tmpNode ){
  8956. // tmpNode.tag = parentTag;
  8957. // tmpNode.attributes.style = 'list-style-type:' + liStyle;
  8958. // }
  8959. //
  8960. //
  8961. //
  8962. // }
  8963. //
  8964. // }
  8965. //
  8966. // node = {
  8967. // type : 'fragment',
  8968. // children : []
  8969. // };
  8970. // break;
  8971. //
  8972. //
  8973. // }
  8974. var style = node.attributes.style;
  8975. if ( style ) {
  8976. if ( !node.attributes.style || browser.webkit && style == "white-space:nowrap;") {
  8977. delete node.attributes.style;
  8978. }
  8979. }
  8980. //针对ff3.6span的样式不能正确继承的修复
  8981. if(browser.gecko && browser.version <= 10902 && node.parent){
  8982. var parent = node.parent;
  8983. if(parent.tag == 'span' && parent.attributes && parent.attributes.style){
  8984. node.attributes.style = parent.attributes.style + ';' + node.attributes.style;
  8985. }
  8986. }
  8987. if ( utils.isEmptyObject( node.attributes ) && autoClearEmptyNode) {
  8988. node.type = 'fragment'
  8989. }
  8990. break;
  8991. case 'font':
  8992. node.tag = node.name = 'span';
  8993. attr = node.attributes;
  8994. node.attributes = {
  8995. 'style': (attr.size ? 'font-size:' + (sizeMap[attr.size] || 12) + 'px' : '')
  8996. + ';' + (attr.color ? 'color:'+ attr.color : '')
  8997. + ';' + (attr.face ? 'font-family:'+ attr.face : '')
  8998. + ';' + (attr.style||'')
  8999. };
  9000. while(node.parent.tag == node.tag && node.parent.children.length == 1){
  9001. node.attributes.style && (node.parent.attributes.style ? (node.parent.attributes.style += ";" + node.attributes.style) : (node.parent.attributes.style = node.attributes.style));
  9002. node.parent.children = node.children;
  9003. node = node.parent;
  9004. }
  9005. break;
  9006. case 'p':
  9007. if ( node.attributes.align ) {
  9008. node.attributes.style = (node.attributes.style || '') + ';text-align:' +
  9009. node.attributes.align + ';';
  9010. delete node.attributes.align;
  9011. }
  9012. // if ( _likeLi( node ) ) {
  9013. //
  9014. // if ( !first ) {
  9015. //
  9016. // var ulNode = {
  9017. // type: 'element',
  9018. // tag: 'ul',
  9019. // attributes: {},
  9020. // children: []
  9021. // },
  9022. // index = indexOf( node.parent.children, node );
  9023. // node.parent.children[index] = ulNode;
  9024. // ulNode.parent = node.parent;
  9025. // ulNode.children[0] = node;
  9026. // node.parent = ulNode;
  9027. //
  9028. // while ( 1 ) {
  9029. // node = ulNode.parent.children[index + 1];
  9030. // if ( _likeLi( node ) ) {
  9031. // ulNode.children[ulNode.children.length] = node;
  9032. // node.parent = ulNode;
  9033. // ulNode.parent.children.splice( index + 1, 1 );
  9034. //
  9035. // } else {
  9036. // break;
  9037. // }
  9038. // }
  9039. //
  9040. // return ulNode;
  9041. // }
  9042. // node.tag = node.name = 'li';
  9043. // //为chrome能找到标号做的处理
  9044. // if ( browser.webkit ) {
  9045. // var span = node.children[0];
  9046. //
  9047. // while ( span && span.type == 'element' ) {
  9048. // span = span.children[0]
  9049. // }
  9050. // span && (span.parent.attributes.style = (span.parent.attributes.style || '') + ';mso-list:10');
  9051. // }
  9052. //
  9053. //
  9054. // delete node.attributes['class'];
  9055. // delete node.attributes.style;
  9056. //
  9057. //
  9058. // }
  9059. }
  9060. return node;
  9061. }
  9062. function optStyle( node ) {
  9063. if ( ie && node.attributes.style ) {
  9064. var style = node.attributes.style;
  9065. node.attributes.style = style.replace(/;\s*/g,';');
  9066. node.attributes.style = node.attributes.style.replace( /^\s*|\s*$/, '' )
  9067. }
  9068. }
  9069. //getContent调用转换
  9070. function transOutNode( node ) {
  9071. switch ( node.tag ) {
  9072. case 'div' :
  9073. if(node.attributes._ue_div_script){
  9074. node.tag = 'script';
  9075. node.children = [{type:'cdata',data:decodeURIComponent(node.attributes._ue_script_data)||'',parent:node}];
  9076. delete node.attributes._ue_div_script;
  9077. delete node.attributes._ue_script_data;
  9078. break;
  9079. }
  9080. case 'table':
  9081. !node.attributes.style && delete node.attributes.style;
  9082. if ( ie && node.attributes.style ) {
  9083. optStyle( node );
  9084. }
  9085. if(node.attributes['class'] == 'noBorderTable'){
  9086. delete node.attributes['class'];
  9087. }
  9088. break;
  9089. case 'td':
  9090. case 'th':
  9091. if ( /display\s*:\s*none/i.test( node.attributes.style ) ) {
  9092. return {
  9093. type: 'fragment',
  9094. children: []
  9095. };
  9096. }
  9097. if ( ie && !node.children.length ) {
  9098. var txtNode = {
  9099. type: 'text',
  9100. data:domUtils.fillChar,
  9101. parent : node
  9102. };
  9103. node.children[0] = txtNode;
  9104. }
  9105. if ( ie && node.attributes.style ) {
  9106. optStyle( node );
  9107. }
  9108. if(node.attributes['class'] == 'selectTdClass'){
  9109. delete node.attributes['class']
  9110. }
  9111. break;
  9112. case 'img'://锚点,img==>a
  9113. if ( node.attributes.anchorname ) {
  9114. node.tag = 'a';
  9115. node.attributes = {
  9116. name : node.attributes.anchorname,
  9117. anchorname : 1
  9118. };
  9119. node.closed = null;
  9120. }else{
  9121. if(node.attributes.data_ue_src){
  9122. node.attributes.src = node.attributes.data_ue_src;
  9123. delete node.attributes.data_ue_src;
  9124. }
  9125. }
  9126. break;
  9127. case 'a':
  9128. if(node.attributes.data_ue_src){
  9129. node.attributes.href = node.attributes.data_ue_src;
  9130. delete node.attributes.data_ue_src;
  9131. }
  9132. }
  9133. return node;
  9134. }
  9135. function childrenAccept( node, visit, ctx ) {
  9136. if ( !node.children || !node.children.length ) {
  9137. return node;
  9138. }
  9139. var children = node.children;
  9140. for ( var i = 0; i < children.length; i++ ) {
  9141. var newNode = visit( children[i], ctx );
  9142. if ( newNode.type == 'fragment' ) {
  9143. var args = [i, 1];
  9144. args.push.apply( args, newNode.children );
  9145. children.splice.apply( children, args );
  9146. //节点为空的就干掉,不然后边的补全操作会添加多余的节点
  9147. if ( !children.length ) {
  9148. node = {
  9149. type: 'fragment',
  9150. children: []
  9151. }
  9152. }
  9153. i --;
  9154. } else {
  9155. children[i] = newNode;
  9156. }
  9157. }
  9158. return node;
  9159. }
  9160. function Serialize( rules ) {
  9161. this.rules = rules;
  9162. }
  9163. Serialize.prototype = {
  9164. // NOTE: selector目前只支持tagName
  9165. rules: null,
  9166. // NOTE: node必须是fragment
  9167. filter: function ( node, rules, modify ) {
  9168. rules = rules || this.rules;
  9169. var whiteList = rules && rules.whiteList;
  9170. var blackList = rules && rules.blackList;
  9171. function visitNode( node, parent ) {
  9172. node.name = node.type == 'element' ?
  9173. node.tag : NODE_NAME_MAP[node.type];
  9174. if ( parent == null ) {
  9175. return childrenAccept( node, visitNode, node );
  9176. }
  9177. if ( blackList && blackList[node.name] ) {
  9178. modify && (modify.flag = 1);
  9179. return {
  9180. type: 'fragment',
  9181. children: []
  9182. };
  9183. }
  9184. if ( whiteList ) {
  9185. if ( node.type == 'element' ) {
  9186. if ( parent.type == 'fragment' ? whiteList[node.name] : whiteList[node.name] && whiteList[parent.name][node.name] ) {
  9187. var props;
  9188. if ( (props = whiteList[node.name].$) ) {
  9189. var oldAttrs = node.attributes;
  9190. var newAttrs = {};
  9191. for ( var k in props ) {
  9192. if ( oldAttrs[k] ) {
  9193. newAttrs[k] = oldAttrs[k];
  9194. }
  9195. }
  9196. node.attributes = newAttrs;
  9197. }
  9198. } else {
  9199. modify && (modify.flag = 1);
  9200. node.type = 'fragment';
  9201. // NOTE: 这里算是一个hack
  9202. node.name = parent.name;
  9203. }
  9204. } else {
  9205. // NOTE: 文本默认允许
  9206. }
  9207. }
  9208. if ( blackList || whiteList ) {
  9209. childrenAccept( node, visitNode, node );
  9210. }
  9211. return node;
  9212. }
  9213. return visitNode( node, null );
  9214. },
  9215. transformInput: function ( node, word_img_flag ) {
  9216. function visitNode( node ) {
  9217. node = transNode( node, word_img_flag );
  9218. // if ( node.tag == 'ol' || node.tag == 'ul' ) {
  9219. // first = 1;
  9220. // }
  9221. node = childrenAccept( node, visitNode, node );
  9222. // if ( node.tag == 'ol' || node.tag == 'ul' ) {
  9223. // first = 0;
  9224. // parentTag = '',liStyle = '',firstTag = '';
  9225. // }
  9226. if ( me.options.pageBreakTag && node.type == 'text' && node.data.replace( /\s/g, '' ) == me.options.pageBreakTag ) {
  9227. node.type = 'element';
  9228. node.name = node.tag = 'hr';
  9229. delete node.data;
  9230. node.attributes = {
  9231. 'class' : 'pagebreak',
  9232. noshade:"noshade",
  9233. size:"5",
  9234. 'unselectable' : 'on',
  9235. 'style' : 'moz-user-select:none;-khtml-user-select: none;'
  9236. };
  9237. node.children = [];
  9238. }
  9239. //去掉多余的空格和换行
  9240. if(node.type == 'text' && !dtd.$notTransContent[node.parent.tag]){
  9241. node.data = node.data.replace(/[\r\t\n]*/g,'')//.replace(/[ ]*$/g,'')
  9242. }
  9243. return node;
  9244. }
  9245. return visitNode( node );
  9246. },
  9247. transformOutput: function ( node ) {
  9248. function visitNode( node ) {
  9249. if ( node.tag == 'hr' && node.attributes['class'] == 'pagebreak' ) {
  9250. delete node.tag;
  9251. node.type = 'text';
  9252. node.data = me.options.pageBreakTag;
  9253. delete node.children;
  9254. }
  9255. node = transOutNode( node );
  9256. if ( node.tag == 'ol' || node.tag == 'ul' ) {
  9257. first = 1;
  9258. }
  9259. node = childrenAccept( node, visitNode, node );
  9260. if ( node.tag == 'ol' || node.tag == 'ul' ) {
  9261. first = 0;
  9262. }
  9263. return node;
  9264. }
  9265. return visitNode( node );
  9266. },
  9267. toHTML: toHTML,
  9268. parseHTML: parseHTML,
  9269. word: transformWordHtml
  9270. };
  9271. me.serialize = new Serialize( me.options.serialize || {});
  9272. UE.serialize = new Serialize( {} );
  9273. };
  9274. ///import core
  9275. ///import plugins/inserthtml.js
  9276. ///commands 视频
  9277. ///commandsName InsertVideo
  9278. ///commandsTitle 插入视频
  9279. ///commandsDialog dialogs\video\video.html
  9280. UE.plugins['video'] = function (){
  9281. var me =this,
  9282. div;
  9283. /**
  9284. * 创建插入视频字符窜
  9285. * @param url 视频地址
  9286. * @param width 视频宽度
  9287. * @param height 视频高度
  9288. * @param align 视频对齐
  9289. * @param toEmbed 是否以图片代替显示
  9290. * @param addParagraph 是否需要添加P 标签
  9291. */
  9292. function creatInsertStr(url,width,height,align,toEmbed,addParagraph){
  9293. return !toEmbed ?
  9294. (addParagraph? ('<p '+ (align !="none" ? ( align == "center"? ' style="text-align:center;" ':' style="float:"'+ align ) : '') + '>'): '') +
  9295. '<img align="'+align+'" width="'+ width +'" height="' + height + '" _url="'+url+'" class="edui-faked-video"' +
  9296. ' src="'+me.options.UEDITOR_HOME_URL+'themes/default/images/spacer.gif" style="background:url('+me.options.UEDITOR_HOME_URL+'themes/default/images/videologo.gif) no-repeat center center; border:1px solid gray;" />' +
  9297. (addParagraph?'</p>':'')
  9298. :
  9299. '<embed type="application/x-shockwave-flash" class="edui-faked-video" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  9300. ' src="' + url + '" width="' + width + '" height="' + height + '" align="' + align + '"' +
  9301. ( align !="none" ? ' style= "'+ ( align == "center"? "display:block;":" float: "+ align ) + '"' :'' ) +
  9302. ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >';
  9303. }
  9304. function switchImgAndEmbed(img2embed){
  9305. var tmpdiv,
  9306. nodes =domUtils.getElementsByTagName(me.document, !img2embed ? "embed" : "img");
  9307. for(var i=0,node;node = nodes[i++];){
  9308. if(node.className!="edui-faked-video")continue;
  9309. tmpdiv = me.document.createElement("div");
  9310. //先看float在看align,浮动有的是时候是在float上定义的
  9311. var align = node.style.cssFloat;
  9312. tmpdiv.innerHTML = creatInsertStr(img2embed ? node.getAttribute("_url"):node.getAttribute("src"),node.width,node.height,align || node.getAttribute("align"),img2embed);
  9313. node.parentNode.replaceChild(tmpdiv.firstChild,node);
  9314. }
  9315. }
  9316. me.addListener("beforegetcontent",function(){
  9317. switchImgAndEmbed(true);
  9318. });
  9319. me.addListener('aftersetcontent',function(){
  9320. switchImgAndEmbed(false);
  9321. });
  9322. me.addListener('aftergetcontent',function(cmdName){
  9323. if(cmdName == 'aftergetcontent' && me.queryCommandState('source'))
  9324. return;
  9325. switchImgAndEmbed(false);
  9326. });
  9327. me.commands["insertvideo"] = {
  9328. execCommand: function (cmd, videoObjs){
  9329. videoObjs = utils.isArray(videoObjs)?videoObjs:[videoObjs];
  9330. var html = [];
  9331. for(var i=0,vi,len = videoObjs.length;i<len;i++){
  9332. vi = videoObjs[i];
  9333. html.push(creatInsertStr( vi.url, vi.width || 420, vi.height || 280, vi.align||"none",false,true));
  9334. }
  9335. me.execCommand("inserthtml",html.join(""));
  9336. },
  9337. queryCommandState : function(){
  9338. var img = me.selection.getRange().getClosedNode(),
  9339. flag = img && (img.className == "edui-faked-video");
  9340. return this.highlight ? -1 :(flag?1:0);
  9341. }
  9342. }
  9343. };
  9344. ///import core
  9345. ///commands 表格
  9346. ///commandsName InsertTable,DeleteTable,InsertParagraphBeforeTable,InsertRow,DeleteRow,InsertCol,DeleteCol,MergeCells,MergeRight,MergeDown,SplittoCells,SplittoRows,SplittoCols
  9347. ///commandsTitle 表格,删除表格,表格前插行,前插入行,删除行,前插入列,删除列,合并多个单元格,右合并单元格,下合并单元格,完全拆分单元格,拆分成行,拆分成列
  9348. ///commandsDialog dialogs\table\table.html
  9349. /**
  9350. * Created by .
  9351. * User: taoqili
  9352. * Date: 11-5-5
  9353. * Time: 下午2:06
  9354. * To change this template use File | Settings | File Templates.
  9355. */
  9356. /**
  9357. * table操作插件
  9358. */
  9359. UE.plugins['table'] = function () {
  9360. var me = this,
  9361. keys = domUtils.keys,
  9362. clearSelectedTd = domUtils.clearSelectedArr;
  9363. //框选时用到的几个全局变量
  9364. var anchorTd,
  9365. tableOpt,
  9366. _isEmpty = domUtils.isEmptyNode;
  9367. function getIndex( cell ) {
  9368. var cells = cell.parentNode.cells;
  9369. for ( var i = 0, ci; ci = cells[i]; i++ ) {
  9370. if ( ci === cell ) {
  9371. return i;
  9372. }
  9373. }
  9374. }
  9375. function deleteTable( table, range ) {
  9376. var p = table.ownerDocument.createElement( 'p' );
  9377. domUtils.fillNode( me.document, p );
  9378. var pN = table.parentNode;
  9379. if ( pN && pN.getAttribute( 'dropdrag' ) ) {
  9380. table = pN;
  9381. }
  9382. table.parentNode.insertBefore( p, table );
  9383. domUtils.remove( table );
  9384. range.setStart( p, 0 ).setCursor();
  9385. }
  9386. /**
  9387. * 判断当前单元格是否处于隐藏状态
  9388. * @param cell 待判断的单元格
  9389. * @return {Boolean} 隐藏时返回true,否则返回false
  9390. */
  9391. function _isHide( cell ) {
  9392. return cell.style.display == "none";
  9393. }
  9394. function getCount( arr ) {
  9395. var count = 0;
  9396. for ( var i = 0, ti; ti = arr[i++]; ) {
  9397. if ( !_isHide( ti ) ) {
  9398. count++
  9399. }
  9400. }
  9401. return count;
  9402. }
  9403. me.currentSelectedArr = [];
  9404. me.addListener( 'mousedown', _mouseDownEvent );
  9405. me.addListener( 'keydown', function ( type, evt ) {
  9406. var keyCode = evt.keyCode || evt.which;
  9407. if ( !keys[keyCode] && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey ) {
  9408. clearSelectedTd( me.currentSelectedArr )
  9409. }
  9410. } );
  9411. me.addListener( 'mouseup', function () {
  9412. anchorTd = null;
  9413. me.removeListener( 'mouseover', _mouseDownEvent );
  9414. var td = me.currentSelectedArr[0];
  9415. if ( td ) {
  9416. me.document.body.style.webkitUserSelect = '';
  9417. var range = new dom.Range( me.document );
  9418. if ( _isEmpty( td ) ) {
  9419. range.setStart( me.currentSelectedArr[0], 0 ).setCursor();
  9420. } else {
  9421. range.selectNodeContents( me.currentSelectedArr[0] ).select();
  9422. }
  9423. } else {
  9424. //浏览器能从table外边选到里边导致currentSelectedArr为空,清掉当前选区回到选区的最开始
  9425. var range = me.selection.getRange().shrinkBoundary();
  9426. if ( !range.collapsed ) {
  9427. var start = domUtils.findParentByTagName( range.startContainer, 'td', true ),
  9428. end = domUtils.findParentByTagName( range.endContainer, 'td', true );
  9429. //在table里边的不能清除
  9430. if ( start && !end || !start && end || start && end && start !== end ) {
  9431. range.collapse( true ).select( true )
  9432. }
  9433. }
  9434. }
  9435. } );
  9436. function reset() {
  9437. me.currentSelectedArr = [];
  9438. anchorTd = null;
  9439. }
  9440. /**
  9441. * 插入表格
  9442. * @param numRows 行数
  9443. * @param numCols 列数
  9444. * @param height 列数
  9445. * @param width 列数
  9446. * @param heightUnit 列数
  9447. * @param widthUnit 列数
  9448. * @param bgColor 表格背景
  9449. * @param border 边框大小
  9450. * @param borderColor 边框颜色
  9451. * @param cellSpacing 单元格间距
  9452. * @param cellPadding 单元格边距
  9453. */
  9454. me.commands['inserttable'] = {
  9455. queryCommandState:function () {
  9456. if ( this.highlight ) {
  9457. return -1;
  9458. }
  9459. var range = this.selection.getRange();
  9460. return domUtils.findParentByTagName( range.startContainer, 'table', true )
  9461. || domUtils.findParentByTagName( range.endContainer, 'table', true )
  9462. || me.currentSelectedArr.length > 0 ? -1 : 0;
  9463. },
  9464. execCommand:function ( cmdName, opt ) {
  9465. opt = opt || {numRows:5, numCols:5,border:1};
  9466. var html = ['<table ' + (opt.border == "0" ? ' class="noBorderTable"' : '') + ' _innerCreateTable = "true" '];
  9467. if ( opt.cellSpacing && opt.cellSpacing != '0' || opt.cellPadding && opt.cellPadding != '0' ) {
  9468. html.push( ' style="border-collapse:separate;" ' )
  9469. }
  9470. opt.cellSpacing && opt.cellSpacing != '0' && html.push( ' cellSpacing="' + opt.cellSpacing + '" ' );
  9471. opt.cellPadding && opt.cellPadding != '0' && html.push( ' cellPadding="' + opt.cellPadding + '" ' );
  9472. html.push( ' width="' + (opt.width || 100) + (typeof opt.widthUnit == "undefined" ? '%' : opt.widthUnit) + '" ' );
  9473. opt.height && html.push( ' height="' + opt.height + (typeof opt.heightUnit == "undefined" ? '%' : opt.heightUnit) + '" ' );
  9474. opt.align && (html.push( ' align="' + opt.align + '" ' ));
  9475. html.push( ' border="' + (opt.border || 0) + '" borderColor="' + (opt.borderColor || '#000000') + '"' );
  9476. opt.borderType == "1" && html.push( ' borderType="1" ' );
  9477. opt.bgColor && html.push( ' bgColor="' + opt.bgColor + '"' );
  9478. html.push( ' ><tbody>' );
  9479. opt.width = Math.floor( (opt.width || '100') / opt.numCols );
  9480. for ( var i = 0; i < opt.numRows; i++ ) {
  9481. html.push( '<tr>' )
  9482. for ( var j = 0; j < opt.numCols; j++ ) {
  9483. html.push( '<td style="width:' + opt.width + (typeof opt.widthUnit == "undefined" ? '%' : opt.widthUnit) + ';'
  9484. + (opt.borderType == '1' ? 'border:' + opt.border + 'px solid ' + (opt.borderColor || '#000000') : '')
  9485. + '">'
  9486. + (browser.ie ? domUtils.fillChar : '<br/>') + '</td>' )
  9487. }
  9488. html.push( '</tr>' )
  9489. }
  9490. me.execCommand( 'insertHtml', html.join( '' ) + '</tbody></table>' );
  9491. reset();
  9492. //如果表格的align不是默认,将不占位,给后边的block元素设置clear:both
  9493. if ( opt.align ) {
  9494. var range = me.selection.getRange(),
  9495. bk = range.createBookmark(),
  9496. start = range.startContainer;
  9497. while ( start && !domUtils.isBody( start ) ) {
  9498. if ( domUtils.isBlockElm( start ) ) {
  9499. start.style.clear = 'both';
  9500. range.moveToBookmark( bk ).select();
  9501. break;
  9502. }
  9503. start = start.parentNode;
  9504. }
  9505. }
  9506. }
  9507. };
  9508. me.commands['edittable'] = {
  9509. queryCommandState:function () {
  9510. var range = this.selection.getRange();
  9511. if ( this.highlight ) {
  9512. return -1;
  9513. }
  9514. return domUtils.findParentByTagName( range.startContainer, 'table', true )
  9515. || me.currentSelectedArr.length > 0 ? 0 : -1;
  9516. },
  9517. execCommand:function ( cmdName, opt ) {
  9518. var start = me.selection.getStart(),
  9519. table = domUtils.findParentByTagName( start, 'table', true );
  9520. if ( table ) {
  9521. table.style.cssText = table.style.cssText.replace( /border[^;]+/gi, '' );
  9522. table.style.borderCollapse = opt.cellSpacing && opt.cellSpacing != '0' || opt.cellPadding && opt.cellPadding != '0' ? 'separate' : 'collapse';
  9523. opt.cellSpacing && opt.cellSpacing != '0' ? table.setAttribute( 'cellSpacing', opt.cellSpacing ) : table.removeAttribute( 'cellSpacing' );
  9524. opt.cellPadding && opt.cellPadding != '0' ? table.setAttribute( 'cellPadding', opt.cellPadding ) : table.removeAttribute( 'cellPadding' );
  9525. opt.height && table.setAttribute( 'height', opt.height + opt.heightUnit );
  9526. opt.align && table.setAttribute( 'align', opt.align );
  9527. opt.width && table.setAttribute( 'width', opt.width + opt.widthUnit );
  9528. opt.bgColor && table.setAttribute( 'bgColor', opt.bgColor );
  9529. opt.borderColor && table.setAttribute( 'borderColor', opt.borderColor );
  9530. table.setAttribute( 'border', opt.border );
  9531. table.className = opt.border == "0" ? "noBorderTable" : "";
  9532. if ( opt.borderType == "1" ) {
  9533. for ( var i = 0, ti, tds = table.getElementsByTagName( 'td' ); ti = tds[i++]; ) {
  9534. ti.style.border = opt.border + 'px solid ' + (opt.borderColor || '#000000')
  9535. }
  9536. table.setAttribute( 'borderType', '1' )
  9537. } else {
  9538. for ( var i = 0, ti, tds = table.getElementsByTagName( 'td' ); ti = tds[i++]; ) {
  9539. if ( browser.ie ) {
  9540. ti.style.cssText = ti.style.cssText.replace( /border[^;]+/gi, '' );
  9541. } else {
  9542. domUtils.removeStyle( ti, 'border' );
  9543. domUtils.removeStyle( ti, 'border-image' )
  9544. }
  9545. }
  9546. table.removeAttribute( 'borderType' )
  9547. }
  9548. }
  9549. }
  9550. };
  9551. me.commands['edittd'] = {
  9552. queryCommandState:function () {
  9553. if ( this.highlight ) {
  9554. return -1;
  9555. }
  9556. var range = this.selection.getRange();
  9557. return (domUtils.findParentByTagName( range.startContainer, 'table', true )
  9558. && domUtils.findParentByTagName( range.endContainer, 'table', true )) || me.currentSelectedArr.length > 0 ? 0 : -1;
  9559. },
  9560. /**
  9561. * 单元格属性编辑
  9562. * @param cmdName
  9563. * @param tdItems
  9564. */
  9565. execCommand:function ( cmdName, tdItems ) {
  9566. var range = this.selection.getRange(),
  9567. tds = !me.currentSelectedArr.length ? [domUtils.findParentByTagName( range.startContainer, ['td', 'th'], true )] : me.currentSelectedArr;
  9568. for ( var i = 0, td; td = tds[i++]; ) {
  9569. domUtils.setAttributes( td, {
  9570. "bgColor":tdItems.bgColor,
  9571. "align":tdItems.align,
  9572. "vAlign":tdItems.vAlign
  9573. } );
  9574. }
  9575. }
  9576. };
  9577. /**
  9578. * 删除表格
  9579. */
  9580. me.commands['deletetable'] = {
  9581. queryCommandState:function () {
  9582. if ( this.highlight ) {
  9583. return -1;
  9584. }
  9585. var range = this.selection.getRange();
  9586. return (domUtils.findParentByTagName( range.startContainer, 'table', true )
  9587. && domUtils.findParentByTagName( range.endContainer, 'table', true )) || me.currentSelectedArr.length > 0 ? 0 : -1;
  9588. },
  9589. execCommand:function () {
  9590. var range = this.selection.getRange(),
  9591. table = domUtils.findParentByTagName( me.currentSelectedArr.length > 0 ? me.currentSelectedArr[0] : range.startContainer, 'table', true );
  9592. deleteTable( table, range );
  9593. reset();
  9594. }
  9595. };
  9596. /**
  9597. * 添加表格标题
  9598. */
  9599. me.commands['addcaption'] = {
  9600. queryCommandState:function () {
  9601. if ( this.highlight ) {
  9602. return -1;
  9603. }
  9604. var range = this.selection.getRange();
  9605. return (domUtils.findParentByTagName( range.startContainer, 'table', true )
  9606. && domUtils.findParentByTagName( range.endContainer, 'table', true )) || me.currentSelectedArr.length > 0 ? 0 : -1;
  9607. },
  9608. execCommand:function ( cmdName, opt ) {
  9609. var range = this.selection.getRange(),
  9610. table = domUtils.findParentByTagName( me.currentSelectedArr.length > 0 ? me.currentSelectedArr[0] : range.startContainer, 'table', true );
  9611. if ( opt == "on" ) {
  9612. var c = table.createCaption();
  9613. c.innerHTML = "请在此输入表格标题";
  9614. } else {
  9615. table.removeChild( table.caption );
  9616. }
  9617. }
  9618. };
  9619. /**
  9620. * 向右合并单元格
  9621. */
  9622. me.commands['mergeright'] = {
  9623. queryCommandState:function () {
  9624. if ( this.highlight ) {
  9625. return -1;
  9626. }
  9627. var range = this.selection.getRange(),
  9628. start = range.startContainer,
  9629. td = domUtils.findParentByTagName( start, ['td', 'th'], true );
  9630. if ( !td || this.currentSelectedArr.length > 1 )return -1;
  9631. var tr = td.parentNode;
  9632. //最右边行不能向右合并
  9633. var rightCellIndex = getIndex( td ) + td.colSpan;
  9634. if ( rightCellIndex >= tr.cells.length ) {
  9635. return -1;
  9636. }
  9637. //单元格不在同一行不能向右合并
  9638. var rightCell = tr.cells[rightCellIndex];
  9639. if ( _isHide( rightCell ) ) {
  9640. return -1;
  9641. }
  9642. return td.rowSpan == rightCell.rowSpan ? 0 : -1;
  9643. },
  9644. execCommand:function () {
  9645. var range = this.selection.getRange(),
  9646. start = range.startContainer,
  9647. td = domUtils.findParentByTagName( start, ['td', 'th'], true ) || me.currentSelectedArr[0],
  9648. tr = td.parentNode,
  9649. rows = tr.parentNode.parentNode.rows;
  9650. //找到当前单元格右边的未隐藏单元格
  9651. var rightCellRowIndex = tr.rowIndex,
  9652. rightCellCellIndex = getIndex( td ) + td.colSpan,
  9653. rightCell = rows[rightCellRowIndex].cells[rightCellCellIndex];
  9654. //在隐藏的原生td对象上增加两个属性,分别表示当前td对应的真实td坐标
  9655. for ( var i = rightCellRowIndex; i < rightCellRowIndex + rightCell.rowSpan; i++ ) {
  9656. for ( var j = rightCellCellIndex; j < rightCellCellIndex + rightCell.colSpan; j++ ) {
  9657. var tmpCell = rows[i].cells[j];
  9658. tmpCell.setAttribute( 'rootRowIndex', tr.rowIndex );
  9659. tmpCell.setAttribute( 'rootCellIndex', getIndex( td ) );
  9660. }
  9661. }
  9662. //合并单元格
  9663. td.colSpan += rightCell.colSpan || 1;
  9664. //合并内容
  9665. _moveContent( td, rightCell );
  9666. //删除被合并的单元格,此处用隐藏方式实现来提升性能
  9667. rightCell.style.display = "none";
  9668. //重新让单元格获取焦点
  9669. //trace:1565
  9670. if ( domUtils.isEmptyBlock( td ) ) {
  9671. range.setStart( td, 0 ).setCursor();
  9672. } else {
  9673. range.selectNodeContents( td ).setCursor( true, true );
  9674. }
  9675. //处理有寛高,导致ie的文字不能输入占满
  9676. browser.ie && domUtils.removeAttributes( td, ['width', 'height'] );
  9677. }
  9678. };
  9679. /**
  9680. * 向下合并单元格
  9681. */
  9682. me.commands['mergedown'] = {
  9683. queryCommandState:function () {
  9684. if ( this.highlight ) {
  9685. return -1;
  9686. }
  9687. var range = this.selection.getRange(),
  9688. start = range.startContainer,
  9689. td = domUtils.findParentByTagName( start, 'td', true );
  9690. if ( !td || getCount( me.currentSelectedArr ) > 1 )return -1;
  9691. var tr = td.parentNode,
  9692. table = tr.parentNode.parentNode,
  9693. rows = table.rows;
  9694. //已经是最底行,不能向下合并
  9695. var downCellRowIndex = tr.rowIndex + td.rowSpan;
  9696. if ( downCellRowIndex >= rows.length ) {
  9697. return -1;
  9698. }
  9699. //如果下一个单元格是隐藏的,表明他是由左边span过来的,不能向下合并
  9700. var downCell = rows[downCellRowIndex].cells[getIndex( td )];
  9701. if ( _isHide( downCell ) ) {
  9702. return -1;
  9703. }
  9704. //只有列span都相等时才能合并
  9705. return td.colSpan == downCell.colSpan ? 0 : -1;
  9706. },
  9707. execCommand:function () {
  9708. var range = this.selection.getRange(),
  9709. start = range.startContainer,
  9710. td = domUtils.findParentByTagName( start, ['td', 'th'], true ) || me.currentSelectedArr[0];
  9711. var tr = td.parentNode,
  9712. rows = tr.parentNode.parentNode.rows;
  9713. var downCellRowIndex = tr.rowIndex + td.rowSpan,
  9714. downCellCellIndex = getIndex( td ),
  9715. downCell = rows[downCellRowIndex].cells[downCellCellIndex];
  9716. //找到当前列的下一个未被隐藏的单元格
  9717. for ( var i = downCellRowIndex; i < downCellRowIndex + downCell.rowSpan; i++ ) {
  9718. for ( var j = downCellCellIndex; j < downCellCellIndex + downCell.colSpan; j++ ) {
  9719. var tmpCell = rows[i].cells[j];
  9720. tmpCell.setAttribute( 'rootRowIndex', tr.rowIndex );
  9721. tmpCell.setAttribute( 'rootCellIndex', getIndex( td ) );
  9722. }
  9723. }
  9724. //合并单元格
  9725. td.rowSpan += downCell.rowSpan || 1;
  9726. //合并内容
  9727. _moveContent( td, downCell );
  9728. //删除被合并的单元格,此处用隐藏方式实现来提升性能
  9729. downCell.style.display = "none";
  9730. //重新让单元格获取焦点
  9731. if ( domUtils.isEmptyBlock( td ) ) {
  9732. range.setStart( td, 0 ).setCursor();
  9733. } else {
  9734. range.selectNodeContents( td ).setCursor( true, true );
  9735. }
  9736. //处理有寛高,导致ie的文字不能输入占满
  9737. browser.ie && domUtils.removeAttributes( td, ['width', 'height'] );
  9738. }
  9739. };
  9740. /**
  9741. * 删除行
  9742. */
  9743. me.commands['deleterow'] = {
  9744. queryCommandState:function () {
  9745. if ( this.highlight ) {
  9746. return -1;
  9747. }
  9748. var range = this.selection.getRange(),
  9749. start = range.startContainer,
  9750. td = domUtils.findParentByTagName( start, ['td', 'th'], true );
  9751. if ( !td && me.currentSelectedArr.length == 0 )return -1;
  9752. },
  9753. execCommand:function () {
  9754. var range = this.selection.getRange(),
  9755. start = range.startContainer,
  9756. td = domUtils.findParentByTagName( start, ['td', 'th'], true ),
  9757. tr,
  9758. table,
  9759. cells,
  9760. rows ,
  9761. rowIndex ,
  9762. cellIndex;
  9763. if ( td && me.currentSelectedArr.length == 0 ) {
  9764. var count = (td.rowSpan || 1) - 1;
  9765. me.currentSelectedArr.push( td );
  9766. tr = td.parentNode,
  9767. table = tr.parentNode.parentNode;
  9768. rows = table.rows,
  9769. rowIndex = tr.rowIndex + 1,
  9770. cellIndex = getIndex( td );
  9771. while ( count ) {
  9772. me.currentSelectedArr.push( rows[rowIndex].cells[cellIndex] );
  9773. count--;
  9774. rowIndex++
  9775. }
  9776. }
  9777. while ( td = me.currentSelectedArr.pop() ) {
  9778. if ( !domUtils.findParentByTagName( td, 'table' ) ) {//|| _isHide(td)
  9779. continue;
  9780. }
  9781. tr = td.parentNode,
  9782. table = tr.parentNode.parentNode;
  9783. cells = tr.cells,
  9784. rows = table.rows,
  9785. rowIndex = tr.rowIndex,
  9786. cellIndex = getIndex( td );
  9787. /*
  9788. * 从最左边开始扫描并隐藏当前行的所有单元格
  9789. * 若当前单元格的display为none,往上找到它所在的真正单元格,获取colSpan和rowSpan,
  9790. * 将rowspan减一,并跳转到cellIndex+colSpan列继续处理
  9791. * 若当前单元格的display不为none,分两种情况:
  9792. * 1、rowspan == 1 ,直接设置display为none,跳转到cellIndex+colSpan列继续处理
  9793. * 2、rowspan > 1 , 修改当前单元格的下一个单元格的display为"",
  9794. * 并将当前单元格的rowspan-1赋给下一个单元格的rowspan,当前单元格的colspan赋给下一个单元格的colspan,
  9795. * 然后隐藏当前单元格,跳转到cellIndex+colSpan列继续处理
  9796. */
  9797. for ( var currentCellIndex = 0; currentCellIndex < cells.length; ) {
  9798. var currentNode = cells[currentCellIndex];
  9799. if ( _isHide( currentNode ) ) {
  9800. var topNode = rows[currentNode.getAttribute( 'rootRowIndex' )].cells[currentNode.getAttribute( 'rootCellIndex' )];
  9801. topNode.rowSpan--;
  9802. currentCellIndex += topNode.colSpan;
  9803. } else {
  9804. if ( currentNode.rowSpan == 1 ) {
  9805. currentCellIndex += currentNode.colSpan;
  9806. } else {
  9807. var downNode = rows[rowIndex + 1].cells[currentCellIndex];
  9808. downNode.style.display = "";
  9809. downNode.rowSpan = currentNode.rowSpan - 1;
  9810. downNode.colSpan = currentNode.colSpan;
  9811. currentCellIndex += currentNode.colSpan;
  9812. }
  9813. }
  9814. }
  9815. //完成更新后再删除外层包裹的tr
  9816. domUtils.remove( tr );
  9817. //重新定位焦点
  9818. var topRowTd, focusTd, downRowTd;
  9819. if ( rowIndex == rows.length ) { //如果被删除的行是最后一行,这里之所以没有-1是因为已经删除了一行
  9820. //如果删除的行也是第一行,那么表格总共只有一行,删除整个表格
  9821. if ( rowIndex == 0 ) {
  9822. deleteTable( table, range );
  9823. return;
  9824. }
  9825. //如果上一单元格未隐藏,则直接定位,否则定位到最近的上一个非隐藏单元格
  9826. var preRowIndex = rowIndex - 1;
  9827. topRowTd = rows[preRowIndex].cells[ cellIndex];
  9828. focusTd = _isHide( topRowTd ) ? rows[topRowTd.getAttribute( 'rootRowIndex' )].cells[topRowTd.getAttribute( 'rootCellIndex' )] : topRowTd;
  9829. } else { //如果被删除的不是最后一行,则光标定位到下一行,此处未加1是因为已经删除了一行
  9830. downRowTd = rows[rowIndex].cells[cellIndex];
  9831. focusTd = _isHide( downRowTd ) ? rows[downRowTd.getAttribute( 'rootRowIndex' )].cells[downRowTd.getAttribute( 'rootCellIndex' )] : downRowTd;
  9832. }
  9833. }
  9834. range.setStart( focusTd, 0 ).setCursor();
  9835. update( table )
  9836. }
  9837. };
  9838. /**
  9839. * 删除列
  9840. */
  9841. me.commands['deletecol'] = {
  9842. queryCommandState:function () {
  9843. if ( this.highlight ) {
  9844. return -1;
  9845. }
  9846. var range = this.selection.getRange(),
  9847. start = range.startContainer,
  9848. td = domUtils.findParentByTagName( start, ['td', 'th'], true );
  9849. if ( !td && me.currentSelectedArr.length == 0 )return -1;
  9850. },
  9851. execCommand:function () {
  9852. var range = this.selection.getRange(),
  9853. start = range.startContainer,
  9854. td = domUtils.findParentByTagName( start, ['td', 'th'], true );
  9855. if ( td && me.currentSelectedArr.length == 0 ) {
  9856. var count = (td.colSpan || 1) - 1;
  9857. me.currentSelectedArr.push( td );
  9858. while ( count ) {
  9859. do {
  9860. td = td.nextSibling
  9861. } while ( td.nodeType == 3 );
  9862. me.currentSelectedArr.push( td );
  9863. count--;
  9864. }
  9865. }
  9866. while ( td = me.currentSelectedArr.pop() ) {
  9867. if ( !domUtils.findParentByTagName( td, 'table' ) ) { //|| _isHide(td)
  9868. continue;
  9869. }
  9870. var tr = td.parentNode,
  9871. table = tr.parentNode.parentNode,
  9872. cellIndex = getIndex( td ),
  9873. rows = table.rows,
  9874. cells = tr.cells,
  9875. rowIndex = tr.rowIndex;
  9876. /*
  9877. * 从第一行开始扫描并隐藏当前列的所有单元格
  9878. * 若当前单元格的display为none,表明它是由左边Span过来的,
  9879. * 将左边第一个非none单元格的colSpan减去1并删去对应的单元格后跳转到rowIndex + rowspan行继续处理;
  9880. * 若当前单元格的display不为none,分两种情况,
  9881. * 1、当前单元格的colspan == 1 , 则直接删除该节点,跳转到rowIndex + rowspan行继续处理
  9882. * 2、当前单元格的colsapn > 1, 修改当前单元格右边单元格的display为"",
  9883. * 并将当前单元格的colspan-1赋给它的colspan,当前单元格的rolspan赋给它的rolspan,
  9884. * 然后删除当前单元格,跳转到rowIndex+rowSpan行继续处理
  9885. */
  9886. var rowSpan;
  9887. for ( var currentRowIndex = 0; currentRowIndex < rows.length; ) {
  9888. var currentNode = rows[currentRowIndex].cells[cellIndex];
  9889. if ( _isHide( currentNode ) ) {
  9890. var leftNode = rows[currentNode.getAttribute( 'rootRowIndex' )].cells[currentNode.getAttribute( 'rootCellIndex' )];
  9891. //依次删除对应的单元格
  9892. rowSpan = leftNode.rowSpan;
  9893. for ( var i = 0; i < leftNode.rowSpan; i++ ) {
  9894. var delNode = rows[currentRowIndex + i].cells[cellIndex];
  9895. domUtils.remove( delNode );
  9896. }
  9897. //修正被删后的单元格信息
  9898. leftNode.colSpan--;
  9899. currentRowIndex += rowSpan;
  9900. } else {
  9901. if ( currentNode.colSpan == 1 ) {
  9902. rowSpan = currentNode.rowSpan;
  9903. for ( var i = currentRowIndex, l = currentRowIndex + currentNode.rowSpan; i < l; i++ ) {
  9904. domUtils.remove( rows[i].cells[cellIndex] );
  9905. }
  9906. currentRowIndex += rowSpan;
  9907. } else {
  9908. var rightNode = rows[currentRowIndex].cells[cellIndex + 1];
  9909. rightNode.style.display = "";
  9910. rightNode.rowSpan = currentNode.rowSpan;
  9911. rightNode.colSpan = currentNode.colSpan - 1;
  9912. currentRowIndex += currentNode.rowSpan;
  9913. domUtils.remove( currentNode );
  9914. }
  9915. }
  9916. }
  9917. //重新定位焦点
  9918. var preColTd, focusTd, nextColTd;
  9919. if ( cellIndex == cells.length ) { //如果当前列是最后一列,光标定位到当前列的前一列,同样,这里没有减去1是因为已经被删除了一列
  9920. //如果当前列也是第一列,则删除整个表格
  9921. if ( cellIndex == 0 ) {
  9922. deleteTable( table, range );
  9923. return;
  9924. }
  9925. //找到当前单元格前一列中和本单元格最近的一个未隐藏单元格
  9926. var preCellIndex = cellIndex - 1;
  9927. preColTd = rows[rowIndex].cells[preCellIndex];
  9928. focusTd = _isHide( preColTd ) ? rows[preColTd.getAttribute( 'rootRowIndex' )].cells[preColTd.getAttribute( 'rootCellIndex' )] : preColTd;
  9929. } else { //如果当前列不是最后一列,则光标定位到当前列的后一列
  9930. nextColTd = rows[rowIndex].cells[cellIndex];
  9931. focusTd = _isHide( nextColTd ) ? rows[nextColTd.getAttribute( 'rootRowIndex' )].cells[nextColTd.getAttribute( 'rootCellIndex' )] : nextColTd;
  9932. }
  9933. }
  9934. range.setStart( focusTd, 0 ).setCursor();
  9935. update( table )
  9936. }
  9937. };
  9938. /**
  9939. * 完全拆分单元格
  9940. */
  9941. me.commands['splittocells'] = {
  9942. queryCommandState:function () {
  9943. if ( this.highlight ) {
  9944. return -1;
  9945. }
  9946. var range = this.selection.getRange(),
  9947. start = range.startContainer,
  9948. td = domUtils.findParentByTagName( start, ['td', 'th'], true );
  9949. return td && ( td.rowSpan > 1 || td.colSpan > 1 ) && (!me.currentSelectedArr.length || getCount( me.currentSelectedArr ) == 1) ? 0 : -1;
  9950. },
  9951. execCommand:function () {
  9952. var range = this.selection.getRange(),
  9953. start = range.startContainer,
  9954. td = domUtils.findParentByTagName( start, ['td', 'th'], true ),
  9955. tr = td.parentNode,
  9956. table = tr.parentNode.parentNode;
  9957. var rowIndex = tr.rowIndex,
  9958. cellIndex = getIndex( td ),
  9959. rowSpan = td.rowSpan,
  9960. colSpan = td.colSpan;
  9961. for ( var i = 0; i < rowSpan; i++ ) {
  9962. for ( var j = 0; j < colSpan; j++ ) {
  9963. var cell = table.rows[rowIndex + i].cells[cellIndex + j];
  9964. cell.rowSpan = 1;
  9965. cell.colSpan = 1;
  9966. if ( _isHide( cell ) ) {
  9967. cell.style.display = "";
  9968. cell.innerHTML = browser.ie ? '' : "<br/>";
  9969. }
  9970. }
  9971. }
  9972. }
  9973. };
  9974. /**
  9975. * 将单元格拆分成行
  9976. */
  9977. me.commands['splittorows'] = {
  9978. queryCommandState:function () {
  9979. if ( this.highlight ) {
  9980. return -1;
  9981. }
  9982. var range = this.selection.getRange(),
  9983. start = range.startContainer,
  9984. td = domUtils.findParentByTagName( start, 'td', true ) || me.currentSelectedArr[0];
  9985. return td && ( td.rowSpan > 1) && (!me.currentSelectedArr.length || getCount( me.currentSelectedArr ) == 1) ? 0 : -1;
  9986. },
  9987. execCommand:function () {
  9988. var range = this.selection.getRange(),
  9989. start = range.startContainer,
  9990. td = domUtils.findParentByTagName( start, 'td', true ) || me.currentSelectedArr[0],
  9991. tr = td.parentNode,
  9992. rows = tr.parentNode.parentNode.rows;
  9993. var rowIndex = tr.rowIndex,
  9994. cellIndex = getIndex( td ),
  9995. rowSpan = td.rowSpan,
  9996. colSpan = td.colSpan;
  9997. for ( var i = 0; i < rowSpan; i++ ) {
  9998. var cells = rows[rowIndex + i],
  9999. cell = cells.cells[cellIndex];
  10000. cell.rowSpan = 1;
  10001. cell.colSpan = colSpan;
  10002. if ( _isHide( cell ) ) {
  10003. cell.style.display = "";
  10004. //原有的内容要清除掉
  10005. cell.innerHTML = browser.ie ? '' : '<br/>'
  10006. }
  10007. //修正被隐藏单元格中存储的rootRowIndex和rootCellIndex信息
  10008. for ( var j = cellIndex + 1; j < cellIndex + colSpan; j++ ) {
  10009. cell = cells.cells[j];
  10010. cell.setAttribute( 'rootRowIndex', rowIndex + i )
  10011. }
  10012. }
  10013. clearSelectedTd( me.currentSelectedArr );
  10014. this.selection.getRange().setStart( td, 0 ).setCursor();
  10015. }
  10016. };
  10017. /**
  10018. * 在表格前插入行
  10019. */
  10020. me.commands['insertparagraphbeforetable'] = {
  10021. queryCommandState:function () {
  10022. if ( this.highlight ) {
  10023. return -1;
  10024. }
  10025. var range = this.selection.getRange(),
  10026. start = range.startContainer,
  10027. td = domUtils.findParentByTagName( start, 'td', true ) || me.currentSelectedArr[0];
  10028. return td && domUtils.findParentByTagName( td, 'table' ) ? 0 : -1;
  10029. },
  10030. execCommand:function () {
  10031. var range = this.selection.getRange(),
  10032. start = range.startContainer,
  10033. table = domUtils.findParentByTagName( start, 'table', true );
  10034. start = me.document.createElement( me.options.enterTag );
  10035. table.parentNode.insertBefore( start, table );
  10036. clearSelectedTd( me.currentSelectedArr );
  10037. if ( start.tagName == 'P' ) {
  10038. //trace:868
  10039. start.innerHTML = browser.ie ? '' : '<br/>';
  10040. range.setStart( start, 0 )
  10041. } else {
  10042. range.setStartBefore( start )
  10043. }
  10044. range.setCursor();
  10045. }
  10046. };
  10047. /**
  10048. * 将单元格拆分成列
  10049. */
  10050. me.commands['splittocols'] = {
  10051. queryCommandState:function () {
  10052. if ( this.highlight ) {
  10053. return -1;
  10054. }
  10055. var range = this.selection.getRange(),
  10056. start = range.startContainer,
  10057. td = domUtils.findParentByTagName( start, ['td', 'th'], true ) || me.currentSelectedArr[0];
  10058. return td && ( td.colSpan > 1) && (!me.currentSelectedArr.length || getCount( me.currentSelectedArr ) == 1) ? 0 : -1;
  10059. },
  10060. execCommand:function () {
  10061. var range = this.selection.getRange(),
  10062. start = range.startContainer,
  10063. td = domUtils.findParentByTagName( start, ['td', 'th'], true ) || me.currentSelectedArr[0],
  10064. tr = td.parentNode,
  10065. rows = tr.parentNode.parentNode.rows;
  10066. var rowIndex = tr.rowIndex,
  10067. cellIndex = getIndex( td ),
  10068. rowSpan = td.rowSpan,
  10069. colSpan = td.colSpan;
  10070. for ( var i = 0; i < colSpan; i++ ) {
  10071. var cell = rows[rowIndex].cells[cellIndex + i];
  10072. cell.rowSpan = rowSpan;
  10073. cell.colSpan = 1;
  10074. if ( _isHide( cell ) ) {
  10075. cell.style.display = "";
  10076. cell.innerHTML = browser.ie ? '' : '<br/>'
  10077. }
  10078. for ( var j = rowIndex + 1; j < rowIndex + rowSpan; j++ ) {
  10079. var tmpCell = rows[j].cells[cellIndex + i];
  10080. tmpCell.setAttribute( 'rootCellIndex', cellIndex + i );
  10081. }
  10082. }
  10083. clearSelectedTd( me.currentSelectedArr );
  10084. this.selection.getRange().setStart( td, 0 ).setCursor();
  10085. }
  10086. };
  10087. /**
  10088. * 插入行
  10089. */
  10090. me.commands['insertrow'] = {
  10091. queryCommandState:function () {
  10092. if ( this.highlight ) {
  10093. return -1;
  10094. }
  10095. var range = this.selection.getRange();
  10096. return domUtils.findParentByTagName( range.startContainer, 'table', true )
  10097. || domUtils.findParentByTagName( range.endContainer, 'table', true ) || me.currentSelectedArr.length != 0 ? 0 : -1;
  10098. },
  10099. execCommand:function () {
  10100. var range = this.selection.getRange(),
  10101. start = range.startContainer,
  10102. tr = domUtils.findParentByTagName( start, 'tr', true ) || me.currentSelectedArr[0].parentNode,
  10103. table = tr.parentNode.parentNode,
  10104. rows = table.rows;
  10105. //记录插入位置原来所有的单元格
  10106. var rowIndex = tr.rowIndex,
  10107. cells = rows[rowIndex].cells;
  10108. //插入新的一行
  10109. var newRow = table.insertRow( rowIndex );
  10110. var newCell;
  10111. //遍历表格中待插入位置中的所有单元格,检查其状态,并据此修正新插入行的单元格状态
  10112. for ( var cellIndex = 0; cellIndex < cells.length; ) {
  10113. var tmpCell = cells[cellIndex];
  10114. if ( _isHide( tmpCell ) ) { //如果当前单元格是隐藏的,表明当前单元格由其上部span过来,找到其上部单元格
  10115. //找到被隐藏单元格真正所属的单元格
  10116. var topCell = rows[tmpCell.getAttribute( 'rootRowIndex' )].cells[tmpCell.getAttribute( 'rootCellIndex' )];
  10117. //增加一行,并将所有新插入的单元格隐藏起来
  10118. topCell.rowSpan++;
  10119. for ( var i = 0; i < topCell.colSpan; i++ ) {
  10120. newCell = tmpCell.cloneNode( false );
  10121. domUtils.removeAttributes( newCell, ["bgColor", "valign", "align"] );
  10122. newCell.rowSpan = newCell.colSpan = 1;
  10123. newCell.innerHTML = browser.ie ? '' : "<br/>";
  10124. newCell.className = '';
  10125. if ( newRow.children[cellIndex + i] ) {
  10126. newRow.insertBefore( newCell, newRow.children[cellIndex + i] );
  10127. } else {
  10128. newRow.appendChild( newCell )
  10129. }
  10130. newCell.style.display = "none";
  10131. }
  10132. cellIndex += topCell.colSpan;
  10133. } else {//若当前单元格未隐藏,则在其上行插入colspan个单元格
  10134. for ( var j = 0; j < tmpCell.colSpan; j++ ) {
  10135. newCell = tmpCell.cloneNode( false );
  10136. domUtils.removeAttributes( newCell, ["bgColor", "valign", "align"] );
  10137. newCell.rowSpan = newCell.colSpan = 1;
  10138. newCell.innerHTML = browser.ie ? '' : "<br/>";
  10139. newCell.className = '';
  10140. if ( newRow.children[cellIndex + j] ) {
  10141. newRow.insertBefore( newCell, newRow.children[cellIndex + j] );
  10142. } else {
  10143. newRow.appendChild( newCell )
  10144. }
  10145. }
  10146. cellIndex += tmpCell.colSpan;
  10147. }
  10148. }
  10149. update( table );
  10150. range.setStart( newRow.cells[0], 0 ).setCursor();
  10151. clearSelectedTd( me.currentSelectedArr );
  10152. }
  10153. };
  10154. /**
  10155. * 插入列
  10156. */
  10157. me.commands['insertcol'] = {
  10158. queryCommandState:function () {
  10159. if ( this.highlight ) {
  10160. return -1;
  10161. }
  10162. var range = this.selection.getRange();
  10163. return domUtils.findParentByTagName( range.startContainer, 'table', true )
  10164. || domUtils.findParentByTagName( range.endContainer, 'table', true ) || me.currentSelectedArr.length != 0 ? 0 : -1;
  10165. },
  10166. execCommand:function () {
  10167. var range = this.selection.getRange(),
  10168. start = range.startContainer,
  10169. td = domUtils.findParentByTagName( start, ['td', 'th'], true ) || me.currentSelectedArr[0],
  10170. table = domUtils.findParentByTagName( td, 'table' ),
  10171. rows = table.rows;
  10172. var cellIndex = getIndex( td ),
  10173. newCell;
  10174. //遍历当前列中的所有单元格,检查其状态,并据此修正新插入列的单元格状态
  10175. for ( var rowIndex = 0; rowIndex < rows.length; ) {
  10176. var tmpCell = rows[rowIndex].cells[cellIndex], tr;
  10177. if ( _isHide( tmpCell ) ) {//如果当前单元格是隐藏的,表明当前单元格由其左边span过来,找到其左边单元格
  10178. var leftCell = rows[tmpCell.getAttribute( 'rootRowIndex' )].cells[tmpCell.getAttribute( 'rootCellIndex' )];
  10179. leftCell.colSpan++;
  10180. for ( var i = 0; i < leftCell.rowSpan; i++ ) {
  10181. newCell = td.cloneNode( false );
  10182. domUtils.removeAttributes( newCell, ["bgColor", "valign", "align"] );
  10183. newCell.rowSpan = newCell.colSpan = 1;
  10184. newCell.innerHTML = browser.ie ? '' : "<br/>";
  10185. newCell.className = '';
  10186. tr = rows[rowIndex + i];
  10187. if ( tr.children[cellIndex] ) {
  10188. tr.insertBefore( newCell, tr.children[cellIndex] );
  10189. } else {
  10190. tr.appendChild( newCell )
  10191. }
  10192. newCell.style.display = "none";
  10193. }
  10194. rowIndex += leftCell.rowSpan;
  10195. } else { //若当前单元格未隐藏,则在其左边插入rowspan个单元格
  10196. for ( var j = 0; j < tmpCell.rowSpan; j++ ) {
  10197. newCell = td.cloneNode( false );
  10198. domUtils.removeAttributes( newCell, ["bgColor", "valign", "align"] );
  10199. newCell.rowSpan = newCell.colSpan = 1;
  10200. newCell.innerHTML = browser.ie ? '' : "<br/>";
  10201. newCell.className = '';
  10202. tr = rows[rowIndex + j];
  10203. if ( tr.children[cellIndex] ) {
  10204. tr.insertBefore( newCell, tr.children[cellIndex] );
  10205. } else {
  10206. tr.appendChild( newCell )
  10207. }
  10208. newCell.innerHTML = browser.ie ? '' : "<br/>";
  10209. }
  10210. rowIndex += tmpCell.rowSpan;
  10211. }
  10212. }
  10213. update( table );
  10214. range.setStart( rows[0].cells[cellIndex], 0 ).setCursor();
  10215. clearSelectedTd( me.currentSelectedArr );
  10216. }
  10217. };
  10218. /**
  10219. * 合并多个单元格,通过两个cell将当前包含的所有横纵单元格进行合并
  10220. */
  10221. me.commands['mergecells'] = {
  10222. queryCommandState:function () {
  10223. if ( this.highlight ) {
  10224. return -1;
  10225. }
  10226. var count = 0;
  10227. for ( var i = 0, ti; ti = this.currentSelectedArr[i++]; ) {
  10228. if ( !_isHide( ti ) )
  10229. count++;
  10230. }
  10231. return count > 1 ? 0 : -1;
  10232. },
  10233. execCommand:function () {
  10234. var start = me.currentSelectedArr[0],
  10235. end = me.currentSelectedArr[me.currentSelectedArr.length - 1],
  10236. table = domUtils.findParentByTagName( start, 'table' ),
  10237. rows = table.rows,
  10238. cellsRange = {
  10239. beginRowIndex:start.parentNode.rowIndex,
  10240. beginCellIndex:getIndex( start ),
  10241. endRowIndex:end.parentNode.rowIndex,
  10242. endCellIndex:getIndex( end )
  10243. },
  10244. beginRowIndex = cellsRange.beginRowIndex,
  10245. beginCellIndex = cellsRange.beginCellIndex,
  10246. rowsLength = cellsRange.endRowIndex - cellsRange.beginRowIndex + 1,
  10247. cellLength = cellsRange.endCellIndex - cellsRange.beginCellIndex + 1,
  10248. tmp = rows[beginRowIndex].cells[beginCellIndex];
  10249. for ( var i = 0, ri; (ri = rows[beginRowIndex + i++]) && i <= rowsLength; ) {
  10250. for ( var j = 0, ci; (ci = ri.cells[beginCellIndex + j++]) && j <= cellLength; ) {
  10251. if ( i == 1 && j == 1 ) {
  10252. ci.style.display = "";
  10253. ci.rowSpan = rowsLength;
  10254. ci.colSpan = cellLength;
  10255. } else {
  10256. ci.style.display = "none";
  10257. ci.rowSpan = 1;
  10258. ci.colSpan = 1;
  10259. ci.setAttribute( 'rootRowIndex', beginRowIndex );
  10260. ci.setAttribute( 'rootCellIndex', beginCellIndex );
  10261. //传递内容
  10262. _moveContent( tmp, ci );
  10263. }
  10264. }
  10265. }
  10266. this.selection.getRange().setStart( tmp, 0 ).setCursor();
  10267. //处理有寛高,导致ie的文字不能输入占满
  10268. browser.ie && domUtils.removeAttributes( tmp, ['width', 'height'] );
  10269. clearSelectedTd( me.currentSelectedArr );
  10270. }
  10271. };
  10272. /**
  10273. * 将cellFrom单元格中的内容移动到cellTo中
  10274. * @param cellTo 目标单元格
  10275. * @param cellFrom 源单元格
  10276. */
  10277. function _moveContent( cellTo, cellFrom ) {
  10278. if ( _isEmpty( cellFrom ) ) return;
  10279. if ( _isEmpty( cellTo ) ) {
  10280. cellTo.innerHTML = cellFrom.innerHTML;
  10281. return;
  10282. }
  10283. var child = cellTo.lastChild;
  10284. if ( child.nodeType != 1 || child.tagName != 'BR' ) {
  10285. cellTo.appendChild( cellTo.ownerDocument.createElement( 'br' ) )
  10286. }
  10287. //依次移动内容
  10288. while ( child = cellFrom.firstChild ) {
  10289. cellTo.appendChild( child );
  10290. }
  10291. }
  10292. /**
  10293. * 根据两个单元格来获取中间包含的所有单元格集合选区
  10294. * @param cellA
  10295. * @param cellB
  10296. * @return {Object} 选区的左上和右下坐标
  10297. */
  10298. function _getCellsRange( cellA, cellB ) {
  10299. var trA = cellA.parentNode,
  10300. trB = cellB.parentNode,
  10301. aRowIndex = trA.rowIndex,
  10302. bRowIndex = trB.rowIndex,
  10303. rows = trA.parentNode.parentNode.rows,
  10304. rowsNum = rows.length,
  10305. cellsNum = rows[0].cells.length,
  10306. cellAIndex = getIndex( cellA ),
  10307. cellBIndex = getIndex( cellB );
  10308. if ( cellA == cellB ) {
  10309. return {
  10310. beginRowIndex:aRowIndex,
  10311. beginCellIndex:cellAIndex,
  10312. endRowIndex:aRowIndex + cellA.rowSpan - 1,
  10313. endCellIndex:cellBIndex + cellA.colSpan - 1
  10314. }
  10315. }
  10316. var
  10317. beginRowIndex = Math.min( aRowIndex, bRowIndex ),
  10318. beginCellIndex = Math.min( cellAIndex, cellBIndex ),
  10319. endRowIndex = Math.max( aRowIndex + cellA.rowSpan - 1, bRowIndex + cellB.rowSpan - 1 ),
  10320. endCellIndex = Math.max( cellAIndex + cellA.colSpan - 1, cellBIndex + cellB.colSpan - 1 );
  10321. while ( 1 ) {
  10322. var tmpBeginRowIndex = beginRowIndex,
  10323. tmpBeginCellIndex = beginCellIndex,
  10324. tmpEndRowIndex = endRowIndex,
  10325. tmpEndCellIndex = endCellIndex;
  10326. // 检查是否有超出TableRange上边界的情况
  10327. if ( beginRowIndex > 0 ) {
  10328. for ( cellIndex = beginCellIndex; cellIndex <= endCellIndex; ) {
  10329. var currentTopTd = rows[beginRowIndex].cells[cellIndex];
  10330. if ( _isHide( currentTopTd ) ) {
  10331. //overflowRowIndex = beginRowIndex == currentTopTd.rootRowIndex ? 1:0;
  10332. beginRowIndex = currentTopTd.getAttribute( 'rootRowIndex' );
  10333. currentTopTd = rows[currentTopTd.getAttribute( 'rootRowIndex' )].cells[currentTopTd.getAttribute( 'rootCellIndex' )];
  10334. }
  10335. cellIndex = getIndex( currentTopTd ) + (currentTopTd.colSpan || 1);
  10336. }
  10337. }
  10338. //检查是否有超出左边界的情况
  10339. if ( beginCellIndex > 0 ) {
  10340. for ( var rowIndex = beginRowIndex; rowIndex <= endRowIndex; ) {
  10341. var currentLeftTd = rows[rowIndex].cells[beginCellIndex];
  10342. if ( _isHide( currentLeftTd ) ) {
  10343. // overflowCellIndex = beginCellIndex== currentLeftTd.rootCellIndex ? 1:0;
  10344. beginCellIndex = currentLeftTd.getAttribute( 'rootCellIndex' );
  10345. currentLeftTd = rows[currentLeftTd.getAttribute( 'rootRowIndex' )].cells[currentLeftTd.getAttribute( 'rootCellIndex' )];
  10346. }
  10347. rowIndex = currentLeftTd.parentNode.rowIndex + (currentLeftTd.rowSpan || 1);
  10348. }
  10349. }
  10350. // 检查是否有超出TableRange下边界的情况
  10351. if ( endRowIndex < rowsNum ) {
  10352. for ( var cellIndex = beginCellIndex; cellIndex <= endCellIndex; ) {
  10353. var currentDownTd = rows[endRowIndex].cells[cellIndex];
  10354. if ( _isHide( currentDownTd ) ) {
  10355. currentDownTd = rows[currentDownTd.getAttribute( 'rootRowIndex' )].cells[currentDownTd.getAttribute( 'rootCellIndex' )];
  10356. }
  10357. endRowIndex = currentDownTd.parentNode.rowIndex + currentDownTd.rowSpan - 1;
  10358. cellIndex = getIndex( currentDownTd ) + (currentDownTd.colSpan || 1);
  10359. }
  10360. }
  10361. //检查是否有超出右边界的情况
  10362. if ( endCellIndex < cellsNum ) {
  10363. for ( rowIndex = beginRowIndex; rowIndex <= endRowIndex; ) {
  10364. var currentRightTd = rows[rowIndex].cells[endCellIndex];
  10365. if ( _isHide( currentRightTd ) ) {
  10366. currentRightTd = rows[currentRightTd.getAttribute( 'rootRowIndex' )].cells[currentRightTd.getAttribute( 'rootCellIndex' )];
  10367. }
  10368. endCellIndex = getIndex( currentRightTd ) + currentRightTd.colSpan - 1;
  10369. rowIndex = currentRightTd.parentNode.rowIndex + (currentRightTd.rowSpan || 1);
  10370. }
  10371. }
  10372. if ( tmpBeginCellIndex == beginCellIndex && tmpEndCellIndex == endCellIndex && tmpEndRowIndex == endRowIndex && tmpBeginRowIndex == beginRowIndex ) {
  10373. break;
  10374. }
  10375. }
  10376. //返回选区的起始和结束坐标
  10377. return {
  10378. beginRowIndex:beginRowIndex,
  10379. beginCellIndex:beginCellIndex,
  10380. endRowIndex:endRowIndex,
  10381. endCellIndex:endCellIndex
  10382. }
  10383. }
  10384. /**
  10385. * 鼠标按下事件
  10386. * @param type
  10387. * @param evt
  10388. */
  10389. function _mouseDownEvent( type, evt ) {
  10390. anchorTd = evt.target || evt.srcElement;
  10391. if ( me.queryCommandState( 'highlightcode' ) || domUtils.findParent( anchorTd, function ( node ) {
  10392. return node.tagName == "DIV" && /highlighter/.test( node.id );
  10393. } ) ) {
  10394. return;
  10395. }
  10396. if ( evt.button == 2 )return;
  10397. me.document.body.style.webkitUserSelect = '';
  10398. clearSelectedTd( me.currentSelectedArr );
  10399. domUtils.clearSelectedArr( me.currentSelectedArr );
  10400. //在td里边点击,anchorTd不是td
  10401. if ( anchorTd.tagName !== 'TD' ) {
  10402. anchorTd = domUtils.findParentByTagName( anchorTd, 'td' ) || anchorTd;
  10403. }
  10404. if ( anchorTd.tagName == 'TD' ) {
  10405. me.addListener( 'mouseover', function ( type, evt ) {
  10406. var tmpTd = evt.target || evt.srcElement;
  10407. _mouseOverEvent.call( me, tmpTd );
  10408. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  10409. } );
  10410. } else {
  10411. reset();
  10412. }
  10413. }
  10414. /**
  10415. * 鼠标移动事件
  10416. * @param tmpTd
  10417. */
  10418. function _mouseOverEvent( tmpTd ) {
  10419. if ( anchorTd && tmpTd.tagName == "TD" ) {
  10420. me.document.body.style.webkitUserSelect = 'none';
  10421. var table = tmpTd.parentNode.parentNode.parentNode;
  10422. me.selection.getNative()[browser.ie ? 'empty' : 'removeAllRanges']();
  10423. var range = _getCellsRange( anchorTd, tmpTd );
  10424. _toggleSelect( table, range );
  10425. }
  10426. }
  10427. /**
  10428. * 切换选区状态
  10429. * @param table
  10430. * @param cellsRange
  10431. */
  10432. function _toggleSelect( table, cellsRange ) {
  10433. var rows = table.rows;
  10434. clearSelectedTd( me.currentSelectedArr );
  10435. for ( var i = cellsRange.beginRowIndex; i <= cellsRange.endRowIndex; i++ ) {
  10436. for ( var j = cellsRange.beginCellIndex; j <= cellsRange.endCellIndex; j++ ) {
  10437. var td = rows[i].cells[j];
  10438. td.className = "selectTdClass";
  10439. me.currentSelectedArr.push( td );
  10440. }
  10441. }
  10442. }
  10443. //更新rootRowIndxe,rootCellIndex
  10444. function update( table ) {
  10445. var tds = table.getElementsByTagName( 'td' ),
  10446. rowIndex, cellIndex, rows = table.rows;
  10447. for ( var j = 0, tj; tj = tds[j++]; ) {
  10448. if ( !_isHide( tj ) ) {
  10449. rowIndex = tj.parentNode.rowIndex;
  10450. cellIndex = getIndex( tj );
  10451. for ( var r = 0; r < tj.rowSpan; r++ ) {
  10452. var c = r == 0 ? 1 : 0;
  10453. for ( ; c < tj.colSpan; c++ ) {
  10454. var tmp = rows[rowIndex + r].children[cellIndex + c];
  10455. tmp.setAttribute( 'rootRowIndex', rowIndex );
  10456. tmp.setAttribute( 'rootCellIndex', cellIndex );
  10457. }
  10458. }
  10459. }
  10460. if ( !_isHide( tj ) ) {
  10461. domUtils.removeAttributes( tj, ['rootRowIndex', 'rootCellIndex'] );
  10462. }
  10463. if ( tj.colSpan && tj.colSpan == 1 ) {
  10464. tj.removeAttribute( 'colSpan' )
  10465. }
  10466. if ( tj.rowSpan && tj.rowSpan == 1 ) {
  10467. tj.removeAttribute( 'rowSpan' )
  10468. }
  10469. var width;
  10470. if ( !_isHide( tj ) && (width = tj.style.width) && /%/.test( width ) ) {
  10471. tj.style.width = Math.floor( 100 / tj.parentNode.cells.length ) + '%'
  10472. }
  10473. }
  10474. }
  10475. me.adjustTable = function ( cont ) {
  10476. var table = cont.getElementsByTagName( 'table' );
  10477. for ( var i = 0, ti; ti = table[i++]; ) {
  10478. //如果表格的align不是默认,将不占位,给后边的block元素设置clear:both
  10479. if ( ti.getAttribute( 'align' ) ) {
  10480. var next = ti.nextSibling;
  10481. while ( next ) {
  10482. if ( domUtils.isBlockElm( next ) ) {
  10483. break;
  10484. }
  10485. next = next.nextSibling;
  10486. }
  10487. if ( next ) {
  10488. next.style.clear = 'both';
  10489. }
  10490. }
  10491. ti.removeAttribute( '_innerCreateTable' );
  10492. var tds = domUtils.getElementsByTagName( ti, 'td' ),
  10493. td, tmpTd;
  10494. for ( var j = 0, tj; tj = tds[j++]; ) {
  10495. if ( domUtils.isEmptyNode( tj ) ) {
  10496. tj.innerHTML = browser.ie ? domUtils.fillChar : '<br/>';
  10497. }
  10498. var index = getIndex( tj ),
  10499. rowIndex = tj.parentNode.rowIndex,
  10500. rows = domUtils.findParentByTagName( tj, 'table' ).rows;
  10501. for ( var r = 0; r < tj.rowSpan; r++ ) {
  10502. var c = r == 0 ? 1 : 0;
  10503. for ( ; c < tj.colSpan; c++ ) {
  10504. if ( !td ) {
  10505. td = tj.cloneNode( false );
  10506. td.rowSpan = td.colSpan = 1;
  10507. td.style.display = 'none';
  10508. td.innerHTML = browser.ie ? '' : '<br/>';
  10509. } else {
  10510. td = td.cloneNode( true )
  10511. }
  10512. td.setAttribute( 'rootRowIndex', tj.parentNode.rowIndex );
  10513. td.setAttribute( 'rootCellIndex', index );
  10514. if ( r == 0 ) {
  10515. if ( tj.nextSibling ) {
  10516. tj.parentNode.insertBefore( td, tj.nextSibling );
  10517. } else {
  10518. tj.parentNode.appendChild( td )
  10519. }
  10520. } else {
  10521. tmpTd = rows[rowIndex + r].children[index];
  10522. if ( tmpTd ) {
  10523. tmpTd.parentNode.insertBefore( td, tmpTd )
  10524. } else {
  10525. //trace:1032
  10526. rows[rowIndex + r].appendChild( td )
  10527. }
  10528. }
  10529. }
  10530. }
  10531. }
  10532. var bw = domUtils.getComputedStyle( ti, "border-width" );
  10533. if ( bw == '0px' || (bw == "" && ti.getAttribute( "border" ) === "0") ) {
  10534. ti.className = "noBorderTable";
  10535. }
  10536. }
  10537. me.fireEvent( "afteradjusttable", cont );
  10538. };
  10539. // me.addListener('beforegetcontent',function(){
  10540. // for(var i=0,ti,ts=me.document.getElementsByTagName('table');ti=ts[i++];){
  10541. // var pN = ti.parentNode;
  10542. // if(pN && pN.getAttribute('dropdrag')){
  10543. // domUtils.remove(pN,true)
  10544. // }
  10545. // }
  10546. // });
  10547. //
  10548. // me.addListener('aftergetcontent',function(){
  10549. // if(!me.queryCommandState('source'))
  10550. // me.fireEvent('afteradjusttable',me.document)
  10551. // });
  10552. // //table拖拽
  10553. // me.addListener("afteradjusttable",function(type,cont){
  10554. // var table = cont.getElementsByTagName("table"),
  10555. // dragCont = me.document.createElement("div");
  10556. // domUtils.setAttributes(dragCont,{
  10557. // style:'margin:0;padding:5px;border:0;',
  10558. // dropdrag:true
  10559. // });
  10560. // for (var i = 0,ti; ti = table[i++];) {
  10561. // if(ti.parentNode && ti.parentNode.nodeType == 1){
  10562. //
  10563. //
  10564. // (function(ti){
  10565. // var div = dragCont.cloneNode(false);
  10566. // ti.parentNode.insertBefore(div,ti);
  10567. // div.appendChild(ti);
  10568. // var borderStyle;
  10569. // domUtils.on(div,'mousemove',function(evt){
  10570. // var tag = evt.srcElement || evt.target;
  10571. // if(tag.tagName.toLowerCase()=="div"){
  10572. // if(ie && me.body.getAttribute("contentEditable") == 'true')
  10573. // me.body.setAttribute("contentEditable","false");
  10574. // borderStyle = clickPosition(ti,this,evt)
  10575. //
  10576. // }
  10577. // });
  10578. // if(ie){
  10579. // domUtils.on(div,'mouseleave',function(evt){
  10580. //
  10581. // if(evt.srcElement.tagName.toLowerCase()=="div" && ie && me.body.getAttribute("contentEditable") == 'false'){
  10582. //
  10583. // me.body.setAttribute("contentEditable","true");
  10584. // }
  10585. //
  10586. //
  10587. // });
  10588. // }
  10589. //
  10590. // domUtils.on(div,"mousedown",function(evt){
  10591. // var tag = evt.srcElement || evt.target;
  10592. //
  10593. // if(tag.tagName.toLowerCase()=="div"){
  10594. // if(ie && me.body.getAttribute("contentEditable") == 'true')
  10595. // me.body.setAttribute("contentEditable","false");
  10596. // var tWidth = ti.offsetWidth,
  10597. // tHeight = ti.offsetHeight,
  10598. // align = ti.getAttribute('align');
  10599. //
  10600. //
  10601. // try{
  10602. // baidu.editor.ui.uiUtils.startDrag(evt, {
  10603. // ondragstart:function(){},
  10604. // ondragmove: function (x, y){
  10605. //
  10606. // if(align && align!="left" && /\w?w-/.test(borderStyle)){
  10607. // x = -x;
  10608. // }
  10609. // if(/^s?[we]/.test(borderStyle)){
  10610. // ti.setAttribute("width",(tWidth+x)>0?tWidth+x: 0);
  10611. // }
  10612. // if(/^s/.test(borderStyle)){
  10613. // ti.setAttribute("height",(tHeight+y)>0?tHeight+y:0);
  10614. // }
  10615. // },
  10616. // ondragstop: function (){}
  10617. // },me.document);
  10618. // }catch(e){
  10619. // alert("您没有引入uiUtils,无法拖动table");
  10620. // }
  10621. //
  10622. // }
  10623. // });
  10624. //
  10625. // domUtils.on(ti,"mouseover",function(){
  10626. // var div = ti.parentNode;
  10627. // if(div && div.parentNode && div.getAttribute('dropdrag')){
  10628. // domUtils.setStyle(div,"cursor","text");
  10629. // if(ie && me.body.getAttribute("contentEditable") == 'false')
  10630. // me.body.setAttribute("contentEditable","true");
  10631. // }
  10632. //
  10633. //
  10634. // });
  10635. // })(ti);
  10636. //
  10637. // }
  10638. // }
  10639. // });
  10640. // function clickPosition(table,div,evt){
  10641. // var pos = domUtils.getXY(table),
  10642. // tWidth = table.offsetWidth,
  10643. // tHeight = table.offsetHeight,
  10644. // evtPos = {
  10645. // top : evt.clientY,
  10646. // left : evt.clientX
  10647. // },
  10648. // borderStyle = "";
  10649. //
  10650. // if(Math.abs(pos.x-evtPos.left)<15){
  10651. //
  10652. // //左,左下
  10653. // borderStyle = Math.abs(evtPos.top-pos.y-tHeight)<15 ? "sw-resize" : "w-resize";
  10654. // }else if(Math.abs(evtPos.left-pos.x-tWidth)<15){
  10655. // //右,右下
  10656. // borderStyle = Math.abs(evtPos.top-pos.y-tHeight)<15 ? "se-resize" : "e-resize";
  10657. // }else if(Math.abs(evtPos.top-pos.y-tHeight)<15 && Math.abs(evtPos.left-pos.x)<tWidth){
  10658. // //下
  10659. // borderStyle = "s-resize";
  10660. // }
  10661. // domUtils.setStyle(div,"cursor",borderStyle||'text');
  10662. // return borderStyle;
  10663. // }
  10664. };
  10665. ///import core
  10666. ///commands 右键菜单
  10667. ///commandsName ContextMenu
  10668. ///commandsTitle 右键菜单
  10669. /**
  10670. * 右键菜单
  10671. * @function
  10672. * @name baidu.editor.plugins.contextmenu
  10673. * @author zhanyi
  10674. */
  10675. UE.plugins['contextmenu'] = function () {
  10676. var me = this,
  10677. menu,
  10678. items = me.options.contextMenu||[
  10679. {label:'删除',cmdName:'delete'},
  10680. {label:'全选',cmdName:'selectall'},
  10681. {
  10682. label:'删除代码',
  10683. cmdName:'highlightcode',
  10684. icon:'deletehighlightcode'
  10685. },
  10686. {
  10687. label:'清空文档',
  10688. cmdName:'cleardoc',
  10689. exec:function () {
  10690. if ( confirm( '确定清空文档吗?' ) ) {
  10691. this.execCommand( 'cleardoc' );
  10692. }
  10693. }
  10694. },
  10695. '-',
  10696. {
  10697. label:'取消链接',
  10698. cmdName:'unlink'
  10699. },
  10700. '-',
  10701. {
  10702. group:'段落格式',
  10703. icon:'justifyjustify',
  10704. subMenu:[
  10705. {
  10706. label:'居左对齐',
  10707. cmdName:'justify',
  10708. value:'left'
  10709. },
  10710. {
  10711. label:'居右对齐',
  10712. cmdName:'justify',
  10713. value:'right'
  10714. },
  10715. {
  10716. label:'居中对齐',
  10717. cmdName:'justify',
  10718. value:'center'
  10719. },
  10720. {
  10721. label:'两端对齐',
  10722. cmdName:'justify',
  10723. value:'justify'
  10724. }
  10725. ]
  10726. },
  10727. '-',
  10728. {
  10729. label:'表格属性',
  10730. cmdName:'edittable',
  10731. exec:function () {
  10732. this.ui._dialogs['inserttableDialog'].open();
  10733. }
  10734. },
  10735. {
  10736. label:'单元格属性',
  10737. cmdName:'edittd',
  10738. exec:function () {
  10739. //如果没有创建,创建一下先
  10740. if(UE.ui['edittd']){
  10741. new UE.ui['edittd'](this);
  10742. }
  10743. this.ui._dialogs['edittdDialog'].open();
  10744. }
  10745. },
  10746. {
  10747. group:'表格',
  10748. icon:'table',
  10749. subMenu:[
  10750. {
  10751. label:'删除表格',
  10752. cmdName:'deletetable'
  10753. },
  10754. {
  10755. label:'表格前插行',
  10756. cmdName:'insertparagraphbeforetable'
  10757. },
  10758. '-',
  10759. {
  10760. label:'删除行',
  10761. cmdName:'deleterow'
  10762. },
  10763. {
  10764. label:'删除列',
  10765. cmdName:'deletecol'
  10766. },
  10767. '-',
  10768. {
  10769. label:'前插入行',
  10770. cmdName:'insertrow'
  10771. },
  10772. {
  10773. label:'前插入列',
  10774. cmdName:'insertcol'
  10775. },
  10776. '-',
  10777. {
  10778. label:'右合并单元格',
  10779. cmdName:'mergeright'
  10780. },
  10781. {
  10782. label:'下合并单元格',
  10783. cmdName:'mergedown'
  10784. },
  10785. '-',
  10786. {
  10787. label:'拆分成行',
  10788. cmdName:'splittorows'
  10789. },
  10790. {
  10791. label:'拆分成列',
  10792. cmdName:'splittocols'
  10793. },
  10794. {
  10795. label:'合并多个单元格',
  10796. cmdName:'mergecells'
  10797. },
  10798. {
  10799. label:'完全拆分单元格',
  10800. cmdName:'splittocells'
  10801. }
  10802. ]
  10803. },
  10804. {
  10805. label:'复制(ctrl+c)',
  10806. cmdName:'copy',
  10807. exec:function () {
  10808. alert( "请使用ctrl+c进行复制" );
  10809. },
  10810. query : function(){return 0;}
  10811. },
  10812. {
  10813. label:'粘贴(ctrl+v)',
  10814. cmdName:'paste',
  10815. exec:function () {
  10816. alert( "请使用ctrl+v进行粘贴" );
  10817. },
  10818. query : function(){return 0;}
  10819. }
  10820. ];
  10821. if(!items.length)return;
  10822. var uiUtils = UE.ui.uiUtils;
  10823. me.addListener('contextmenu',function(type,evt){
  10824. var offset = uiUtils.getViewportOffsetByEvent(evt);
  10825. me.fireEvent('beforeselectionchange');
  10826. if (menu)
  10827. menu.destroy();
  10828. for (var i = 0,ti,contextItems = []; ti = items[i]; i++) {
  10829. var last;
  10830. (function(item) {
  10831. if (item == '-') {
  10832. if ((last = contextItems[contextItems.length - 1 ] ) && last !== '-')
  10833. contextItems.push('-');
  10834. } else if (item.group) {
  10835. for (var j = 0,cj,subMenu = []; cj = item.subMenu[j]; j++) {
  10836. (function(subItem) {
  10837. if (subItem == '-') {
  10838. if ((last = subMenu[subMenu.length - 1 ] ) && last !== '-')
  10839. subMenu.push('-');
  10840. } else {
  10841. if ((me.commands[subItem.cmdName] || UE.commands[subItem.cmdName]||subItem.query) &&
  10842. (subItem.query ? subItem.query() : me.queryCommandState(subItem.cmdName)) > -1) {
  10843. subMenu.push({
  10844. 'label':subItem.label,
  10845. className: 'edui-for-' + subItem.cmdName + (subItem.value || ''),
  10846. onclick : subItem.exec ? function() {
  10847. subItem.exec.call(me)
  10848. } : function() {
  10849. me.execCommand(subItem.cmdName, subItem.value)
  10850. }
  10851. })
  10852. }
  10853. }
  10854. })(cj)
  10855. }
  10856. if (subMenu.length) {
  10857. contextItems.push({
  10858. 'label' : item.group,
  10859. className: 'edui-for-' + item.icon,
  10860. 'subMenu' : {
  10861. items: subMenu,
  10862. editor:me
  10863. }
  10864. })
  10865. }
  10866. } else {
  10867. //有可能commmand没有加载右键不能出来,或者没有command也想能展示出来添加query方法
  10868. if ((me.commands[item.cmdName] || UE.commands[item.cmdName]||item.query) &&
  10869. (item.query ? item.query() : me.queryCommandState(item.cmdName)) > -1) {
  10870. //highlight todo
  10871. if(item.cmdName == 'highlightcode' && me.queryCommandState(item.cmdName) == 0)
  10872. return;
  10873. contextItems.push({
  10874. 'label':item.label,
  10875. className: 'edui-for-' + (item.icon ? item.icon : item.cmdName + (item.value || '')),
  10876. onclick : item.exec ? function() {
  10877. item.exec.call(me)
  10878. } : function() {
  10879. me.execCommand(item.cmdName, item.value)
  10880. }
  10881. })
  10882. }
  10883. }
  10884. })(ti)
  10885. }
  10886. if (contextItems[contextItems.length - 1] == '-')
  10887. contextItems.pop();
  10888. menu = new UE.ui.Menu({
  10889. items: contextItems,
  10890. editor:me
  10891. });
  10892. menu.render();
  10893. menu.showAt(offset);
  10894. domUtils.preventDefault(evt);
  10895. if(browser.ie){
  10896. var ieRange;
  10897. try{
  10898. ieRange = me.selection.getNative().createRange();
  10899. }catch(e){
  10900. return;
  10901. }
  10902. if(ieRange.item){
  10903. var range = new dom.Range(me.document);
  10904. range.selectNode(ieRange.item(0)).select(true,true);
  10905. }
  10906. }
  10907. })
  10908. };
  10909. ///import core
  10910. ///commands 加粗,斜体,上标,下标
  10911. ///commandsName Bold,Italic,Subscript,Superscript
  10912. ///commandsTitle 加粗,加斜,下标,上标
  10913. /**
  10914. * b u i等基础功能实现
  10915. * @function
  10916. * @name baidu.editor.execCommands
  10917. * @param {String} cmdName bold加粗。italic斜体。subscript上标。superscript下标。
  10918. */
  10919. UE.plugins['basestyle'] = function(){
  10920. var basestyles = {
  10921. 'bold':['strong','b'],
  10922. 'italic':['em','i'],
  10923. 'subscript':['sub'],
  10924. 'superscript':['sup']
  10925. },
  10926. getObj = function(editor,tagNames){
  10927. //var start = editor.selection.getStart();
  10928. var path = editor.selection.getStartElementPath();
  10929. // return domUtils.findParentByTagName( start, tagNames, true )
  10930. return utils.findNode(path,tagNames);
  10931. },
  10932. me = this;
  10933. for ( var style in basestyles ) {
  10934. (function( cmd, tagNames ) {
  10935. me.commands[cmd] = {
  10936. execCommand : function( cmdName ) {
  10937. var range = new dom.Range(me.document),obj = '';
  10938. //table的处理
  10939. if(me.currentSelectedArr && me.currentSelectedArr.length > 0){
  10940. for(var i=0,ci;ci=me.currentSelectedArr[i++];){
  10941. if(ci.style.display != 'none'){
  10942. range.selectNodeContents(ci).select();
  10943. //trace:943
  10944. !obj && (obj = getObj(this,tagNames));
  10945. if(cmdName == 'superscript' || cmdName == 'subscript'){
  10946. if(!obj || obj.tagName.toLowerCase() != cmdName)
  10947. range.removeInlineStyle(['sub','sup'])
  10948. }
  10949. obj ? range.removeInlineStyle( tagNames ) : range.applyInlineStyle( tagNames[0] )
  10950. }
  10951. }
  10952. range.selectNodeContents(me.currentSelectedArr[0]).select();
  10953. }else{
  10954. range = me.selection.getRange();
  10955. obj = getObj(this,tagNames);
  10956. if ( range.collapsed ) {
  10957. if ( obj ) {
  10958. var tmpText = me.document.createTextNode('');
  10959. range.insertNode( tmpText ).removeInlineStyle( tagNames );
  10960. range.setStartBefore(tmpText);
  10961. domUtils.remove(tmpText);
  10962. } else {
  10963. var tmpNode = range.document.createElement( tagNames[0] );
  10964. if(cmdName == 'superscript' || cmdName == 'subscript'){
  10965. tmpText = me.document.createTextNode('');
  10966. range.insertNode(tmpText)
  10967. .removeInlineStyle(['sub','sup'])
  10968. .setStartBefore(tmpText)
  10969. .collapse(true);
  10970. }
  10971. range.insertNode( tmpNode ).setStart( tmpNode, 0 );
  10972. }
  10973. range.collapse( true )
  10974. } else {
  10975. if(cmdName == 'superscript' || cmdName == 'subscript'){
  10976. if(!obj || obj.tagName.toLowerCase() != cmdName)
  10977. range.removeInlineStyle(['sub','sup'])
  10978. }
  10979. obj ? range.removeInlineStyle( tagNames ) : range.applyInlineStyle( tagNames[0] )
  10980. }
  10981. range.select();
  10982. }
  10983. return true;
  10984. },
  10985. queryCommandState : function() {
  10986. if(this.highlight){
  10987. return -1;
  10988. }
  10989. return getObj(this,tagNames) ? 1 : 0;
  10990. }
  10991. }
  10992. })( style, basestyles[style] );
  10993. }
  10994. };
  10995. ///import core
  10996. ///commands 选区路径
  10997. ///commandsName ElementPath,elementPathEnabled
  10998. ///commandsTitle 选区路径
  10999. /**
  11000. * 选区路径
  11001. * @function
  11002. * @name baidu.editor.execCommand
  11003. * @param {String} cmdName elementpath选区路径
  11004. */
  11005. UE.plugins['elementpath'] = function(){
  11006. var currentLevel,
  11007. tagNames,
  11008. me = this;
  11009. me.setOpt('elementPathEnabled',true);
  11010. if(!me.options.elementPathEnabled)return;
  11011. me.commands['elementpath'] = {
  11012. execCommand : function( cmdName, level ) {
  11013. var start = tagNames[level],
  11014. range = me.selection.getRange();
  11015. me.currentSelectedArr && domUtils.clearSelectedArr(me.currentSelectedArr);
  11016. currentLevel = level*1;
  11017. if(dtd.$tableContent[start.tagName]){
  11018. switch (start.tagName){
  11019. case 'TD':me.currentSelectedArr = [start];
  11020. start.className = me.options.selectedTdClass;
  11021. break;
  11022. case 'TR':
  11023. var cells = start.cells;
  11024. for(var i=0,ti;ti=cells[i++];){
  11025. me.currentSelectedArr.push(ti);
  11026. ti.className = me.options.selectedTdClass;
  11027. }
  11028. break;
  11029. case 'TABLE':
  11030. case 'TBODY':
  11031. var rows = start.rows;
  11032. for(var i=0,ri;ri=rows[i++];){
  11033. cells = ri.cells;
  11034. for(var j=0,tj;tj=cells[j++];){
  11035. me.currentSelectedArr.push(tj);
  11036. tj.className = me.options.selectedTdClass;
  11037. }
  11038. }
  11039. }
  11040. start = me.currentSelectedArr[0];
  11041. if(domUtils.isEmptyNode(start)){
  11042. range.setStart(start,0).setCursor()
  11043. }else{
  11044. range.selectNodeContents(start).select()
  11045. }
  11046. }else{
  11047. range.selectNode(start).select()
  11048. }
  11049. },
  11050. queryCommandValue : function() {
  11051. //产生一个副本,不能修改原来的startElementPath;
  11052. var parents = [].concat(this.selection.getStartElementPath()).reverse(),
  11053. names = [];
  11054. tagNames = parents;
  11055. for(var i=0,ci;ci=parents[i];i++){
  11056. if(ci.nodeType == 3) continue;
  11057. var name = ci.tagName.toLowerCase();
  11058. if(name == 'img' && ci.getAttribute('anchorname')){
  11059. name = 'anchor'
  11060. }
  11061. names[i] = name;
  11062. if(currentLevel == i){
  11063. currentLevel = -1;
  11064. break;
  11065. }
  11066. }
  11067. return names;
  11068. }
  11069. }
  11070. };
  11071. ///import core
  11072. ///import plugins\removeformat.js
  11073. ///commands 格式刷
  11074. ///commandsName FormatMatch
  11075. ///commandsTitle 格式刷
  11076. /**
  11077. * 格式刷,只格式inline的
  11078. * @function
  11079. * @name baidu.editor.execCommand
  11080. * @param {String} cmdName formatmatch执行格式刷
  11081. */
  11082. UE.plugins['formatmatch'] = function(){
  11083. var me = this,
  11084. list = [],img,
  11085. flag = 0;
  11086. me.addListener('reset',function(){
  11087. list = [];
  11088. flag = 0;
  11089. });
  11090. function addList(type,evt){
  11091. if(browser.webkit){
  11092. var target = evt.target.tagName == 'IMG' ? evt.target : null;
  11093. }
  11094. function addFormat(range){
  11095. if(text && (!me.currentSelectedArr || !me.currentSelectedArr.length)){
  11096. range.selectNode(text);
  11097. }
  11098. return range.applyInlineStyle(list[list.length-1].tagName,null,list);
  11099. }
  11100. me.undoManger && me.undoManger.save();
  11101. var range = me.selection.getRange(),
  11102. imgT = target || range.getClosedNode();
  11103. if(img && imgT && imgT.tagName == 'IMG'){
  11104. //trace:964
  11105. imgT.style.cssText += ';float:' + (img.style.cssFloat || img.style.styleFloat ||'none') + ';display:' + (img.style.display||'inline');
  11106. img = null;
  11107. }else{
  11108. if(!img){
  11109. var collapsed = range.collapsed;
  11110. if(collapsed){
  11111. var text = me.document.createTextNode('match');
  11112. range.insertNode(text).select();
  11113. }
  11114. me.__hasEnterExecCommand = true;
  11115. //不能把block上的属性干掉
  11116. //trace:1553
  11117. var removeFormatAttributes = me.options.removeFormatAttributes;
  11118. me.options.removeFormatAttributes = '';
  11119. me.execCommand('removeformat');
  11120. me.options.removeFormatAttributes = removeFormatAttributes;
  11121. me.__hasEnterExecCommand = false;
  11122. //trace:969
  11123. range = me.selection.getRange();
  11124. if(list.length == 0){
  11125. if(me.currentSelectedArr && me.currentSelectedArr.length > 0){
  11126. range.selectNodeContents(me.currentSelectedArr[0]).select();
  11127. }
  11128. }else{
  11129. if(me.currentSelectedArr && me.currentSelectedArr.length > 0){
  11130. for(var i=0,ci;ci=me.currentSelectedArr[i++];){
  11131. range.selectNodeContents(ci);
  11132. addFormat(range);
  11133. }
  11134. range.selectNodeContents(me.currentSelectedArr[0]).select();
  11135. }else{
  11136. addFormat(range)
  11137. }
  11138. }
  11139. if(!me.currentSelectedArr || !me.currentSelectedArr.length){
  11140. if(text){
  11141. range.setStartBefore(text).collapse(true);
  11142. }
  11143. range.select()
  11144. }
  11145. text && domUtils.remove(text);
  11146. }
  11147. }
  11148. me.undoManger && me.undoManger.save();
  11149. me.removeListener('mouseup',addList);
  11150. flag = 0;
  11151. }
  11152. me.commands['formatmatch'] = {
  11153. execCommand : function( cmdName ) {
  11154. if(flag){
  11155. flag = 0;
  11156. list = [];
  11157. me.removeListener('mouseup',addList);
  11158. return;
  11159. }
  11160. var range = me.selection.getRange();
  11161. img = range.getClosedNode();
  11162. if(!img || img.tagName != 'IMG'){
  11163. range.collapse(true).shrinkBoundary();
  11164. var start = range.startContainer;
  11165. list = domUtils.findParents(start,true,function(node){
  11166. return !domUtils.isBlockElm(node) && node.nodeType == 1
  11167. });
  11168. //a不能加入格式刷, 并且克隆节点
  11169. for(var i=0,ci;ci=list[i];i++){
  11170. if(ci.tagName == 'A'){
  11171. list.splice(i,1);
  11172. break;
  11173. }
  11174. }
  11175. }
  11176. me.addListener('mouseup',addList);
  11177. flag = 1;
  11178. },
  11179. queryCommandState : function() {
  11180. if(this.highlight){
  11181. return -1;
  11182. }
  11183. return flag;
  11184. },
  11185. notNeedUndo : 1
  11186. }
  11187. };
  11188. ///import core
  11189. ///commands 查找替换
  11190. ///commandsName SearchReplace
  11191. ///commandsTitle 查询替换
  11192. ///commandsDialog dialogs\searchreplace\searchreplace.html
  11193. /**
  11194. * @description 查找替换
  11195. * @author zhanyi
  11196. */
  11197. UE.plugins['searchreplace'] = function(){
  11198. var currentRange,
  11199. first,
  11200. me = this;
  11201. me.addListener('reset',function(){
  11202. currentRange = null;
  11203. first = null;
  11204. });
  11205. me.commands['searchreplace'] = {
  11206. execCommand : function(cmdName,opt){
  11207. var me = this,
  11208. sel = me.selection,
  11209. range,
  11210. nativeRange,
  11211. num = 0,
  11212. opt = utils.extend(opt,{
  11213. all : false,
  11214. casesensitive : false,
  11215. dir : 1
  11216. },true);
  11217. if(browser.ie){
  11218. while(1){
  11219. var tmpRange;
  11220. nativeRange = me.document.selection.createRange();
  11221. tmpRange = nativeRange.duplicate();
  11222. tmpRange.moveToElementText(me.document.body);
  11223. if(opt.all){
  11224. first = 0;
  11225. opt.dir = 1;
  11226. if(currentRange){
  11227. tmpRange.setEndPoint(opt.dir == -1 ? 'EndToStart' : 'StartToEnd',currentRange)
  11228. }
  11229. }else{
  11230. tmpRange.setEndPoint(opt.dir == -1 ? 'EndToStart' : 'StartToEnd',nativeRange);
  11231. if(opt.hasOwnProperty("replaceStr")){
  11232. tmpRange.setEndPoint(opt.dir == -1 ? 'StartToEnd' : 'EndToStart',nativeRange);
  11233. }
  11234. }
  11235. nativeRange = tmpRange.duplicate();
  11236. if(!tmpRange.findText(opt.searchStr,opt.dir,opt.casesensitive ? 4 : 0)){
  11237. currentRange = null;
  11238. tmpRange = me.document.selection.createRange();
  11239. tmpRange.scrollIntoView();
  11240. return num;
  11241. }
  11242. tmpRange.select();
  11243. //替换
  11244. if(opt.hasOwnProperty("replaceStr")){
  11245. range = sel.getRange();
  11246. range.deleteContents().insertNode(range.document.createTextNode(opt.replaceStr)).select();
  11247. currentRange = sel.getNative().createRange();
  11248. }
  11249. num++;
  11250. if(!opt.all)break;
  11251. }
  11252. }else{
  11253. var w = me.window,nativeSel = sel.getNative(),tmpRange;
  11254. while(1){
  11255. if(opt.all){
  11256. if(currentRange){
  11257. currentRange.collapse(false);
  11258. nativeRange = currentRange;
  11259. }else{
  11260. nativeRange = me.document.createRange();
  11261. nativeRange.setStart(me.document.body,0);
  11262. }
  11263. nativeSel.removeAllRanges();
  11264. nativeSel.addRange( nativeRange );
  11265. first = 0;
  11266. opt.dir = 1;
  11267. }else{
  11268. nativeRange = w.getSelection().getRangeAt(0);
  11269. if(opt.hasOwnProperty("replaceStr")){
  11270. nativeRange.collapse(opt.dir == 1 ? true : false);
  11271. }
  11272. }
  11273. //如果是第一次并且海选中了内容那就要清除,为find做准备
  11274. if(!first){
  11275. nativeRange.collapse( opt.dir <0 ? true : false);
  11276. nativeSel.removeAllRanges();
  11277. nativeSel.addRange( nativeRange );
  11278. }else{
  11279. nativeSel.removeAllRanges();
  11280. }
  11281. if(!w.find(opt.searchStr,opt.casesensitive,opt.dir < 0 ? true : false) ) {
  11282. currentRange = null;
  11283. nativeSel.removeAllRanges();
  11284. return num;
  11285. }
  11286. first = 0;
  11287. range = w.getSelection().getRangeAt(0);
  11288. if(!range.collapsed){
  11289. if(opt.hasOwnProperty("replaceStr")){
  11290. range.deleteContents();
  11291. var text = w.document.createTextNode(opt.replaceStr);
  11292. range.insertNode(text);
  11293. range.selectNode(text);
  11294. nativeSel.addRange(range);
  11295. currentRange = range.cloneRange();
  11296. }
  11297. }
  11298. num++;
  11299. if(!opt.all)break;
  11300. }
  11301. }
  11302. return true;
  11303. }
  11304. }
  11305. };
  11306. ///import core
  11307. ///commands 自定义样式
  11308. ///commandsName CustomStyle
  11309. ///commandsTitle 自定义样式
  11310. UE.plugins['customstyle'] = function() {
  11311. var me = this;
  11312. me.setOpt({ 'customstyle':[
  11313. {tag:'h1', label:'居中标题', style:'font-size:32px;font-weight:bold;line-height:38px;border-bottom:#ccc 2px solid;padding:0 4px 0 0;text-align:center;margin:0 0 20px 0;'},
  11314. {tag:'h1', label:'居左标题', style:'font-size:32px;font-weight:bold;line-height:38px;border-bottom:#ccc 2px solid;padding:0 4px 0 0;text-align:left;margin:0 0 10px 0;'},
  11315. {tag:'span', label:'强调', style:'font-size:16px;font-style:italic;font-weight:bold;color:#000;line-height:18px;'},
  11316. {tag:'span', label:'明显强调', style:'font-size:16px;font-style:italic;font-weight:bold;color:rgb(51, 153, 204);line-height:18px;'}
  11317. ]});
  11318. me.commands['customstyle'] = {
  11319. execCommand : function(cmdName, obj) {
  11320. var me = this,
  11321. tagName = obj.tag,
  11322. node = domUtils.findParent(me.selection.getStart(), function(node) {
  11323. return node.getAttribute('label')
  11324. }, true),
  11325. range,bk,tmpObj = {};
  11326. for (var p in obj) {
  11327. tmpObj[p] = obj[p]
  11328. }
  11329. delete tmpObj.tag;
  11330. if (node && node.getAttribute('label') == obj.label) {
  11331. range = this.selection.getRange();
  11332. bk = range.createBookmark();
  11333. if (range.collapsed) {
  11334. //trace:1732 删掉自定义标签,要有p来回填站位
  11335. if(dtd.$block[node.tagName]){
  11336. var fillNode = me.document.createElement('p');
  11337. domUtils.moveChild(node, fillNode);
  11338. node.parentNode.insertBefore(fillNode, node);
  11339. domUtils.remove(node)
  11340. }else{
  11341. domUtils.remove(node,true)
  11342. }
  11343. } else {
  11344. var common = domUtils.getCommonAncestor(bk.start, bk.end),
  11345. nodes = domUtils.getElementsByTagName(common, tagName);
  11346. if(new RegExp(tagName,'i').test(common.tagName)){
  11347. nodes.push(common);
  11348. }
  11349. for (var i = 0,ni; ni = nodes[i++];) {
  11350. if (ni.getAttribute('label') == obj.label) {
  11351. var ps = domUtils.getPosition(ni, bk.start),pe = domUtils.getPosition(ni, bk.end);
  11352. if ((ps & domUtils.POSITION_FOLLOWING || ps & domUtils.POSITION_CONTAINS)
  11353. &&
  11354. (pe & domUtils.POSITION_PRECEDING || pe & domUtils.POSITION_CONTAINS)
  11355. )
  11356. if (dtd.$block[tagName]) {
  11357. var fillNode = me.document.createElement('p');
  11358. domUtils.moveChild(ni, fillNode);
  11359. ni.parentNode.insertBefore(fillNode, ni);
  11360. }
  11361. domUtils.remove(ni, true)
  11362. }
  11363. }
  11364. node = domUtils.findParent(common, function(node) {
  11365. return node.getAttribute('label') == obj.label
  11366. }, true);
  11367. if (node) {
  11368. domUtils.remove(node, true)
  11369. }
  11370. }
  11371. range.moveToBookmark(bk).select();
  11372. } else {
  11373. if (dtd.$block[tagName]) {
  11374. this.execCommand('paragraph', tagName, tmpObj,'customstyle');
  11375. range = me.selection.getRange();
  11376. if (!range.collapsed) {
  11377. range.collapse();
  11378. node = domUtils.findParent(me.selection.getStart(), function(node) {
  11379. return node.getAttribute('label') == obj.label
  11380. }, true);
  11381. var pNode = me.document.createElement('p');
  11382. domUtils.insertAfter(node, pNode);
  11383. domUtils.fillNode(me.document, pNode);
  11384. range.setStart(pNode, 0).setCursor()
  11385. }
  11386. } else {
  11387. range = me.selection.getRange();
  11388. if (range.collapsed) {
  11389. node = me.document.createElement(tagName);
  11390. domUtils.setAttributes(node, tmpObj);
  11391. range.insertNode(node).setStart(node, 0).setCursor();
  11392. return;
  11393. }
  11394. bk = range.createBookmark();
  11395. range.applyInlineStyle(tagName, tmpObj).moveToBookmark(bk).select()
  11396. }
  11397. }
  11398. },
  11399. queryCommandValue : function() {
  11400. var parent = utils.findNode(this.selection.getStartElementPath(),null,function(node){return node.getAttribute('label')});
  11401. return parent ? parent.getAttribute('label') : '';
  11402. },
  11403. queryCommandState : function() {
  11404. return this.highlight ? -1 : 0;
  11405. }
  11406. };
  11407. //当去掉customstyle是,如果是块元素,用p代替
  11408. me.addListener('keyup', function(type, evt) {
  11409. var keyCode = evt.keyCode || evt.which;
  11410. if (keyCode == 32 || keyCode == 13) {
  11411. var range = me.selection.getRange();
  11412. if (range.collapsed) {
  11413. var node = domUtils.findParent(me.selection.getStart(), function(node) {
  11414. return node.getAttribute('label')
  11415. }, true);
  11416. if (node && dtd.$block[node.tagName] && domUtils.isEmptyNode(node)) {
  11417. var p = me.document.createElement('p');
  11418. domUtils.insertAfter(node, p);
  11419. domUtils.fillNode(me.document, p);
  11420. domUtils.remove(node);
  11421. range.setStart(p, 0).setCursor();
  11422. }
  11423. }
  11424. }
  11425. })
  11426. };
  11427. ///import core
  11428. ///commandsName catchRemoteImage
  11429. /**
  11430. * 远程图片抓取,当开启本插件时所有不符合本地域名的图片都将被抓取成为本地服务器上的图片
  11431. *
  11432. */
  11433. UE.plugins['catchremoteimage'] = function () {
  11434. if (this.options.catchRemoteImageEnable===false)return;
  11435. var me = this;
  11436. this.setOpt({
  11437. localDomain:["127.0.0.1","localhost"],
  11438. separater:'ue_separate_ue',
  11439. catchFieldName:"upfile",
  11440. catchRemoteImageEnable:true
  11441. });
  11442. var ajax = UE.ajax,
  11443. localDomain = me.options.localDomain ,
  11444. catcherUrl = me.options.catcherUrl,
  11445. separater = me.options.separater;
  11446. function catchremoteimage(imgs, callbacks) {
  11447. var submitStr = imgs.join(separater);
  11448. var tmpOption = {
  11449. timeout:60000, //单位:毫秒,回调请求超时设置。目标用户如果网速不是很快的话此处建议设置一个较大的数值
  11450. onsuccess:callbacks["success"],
  11451. onerror:callbacks["error"]
  11452. };
  11453. tmpOption[me.options.catchFieldName] = submitStr;
  11454. ajax.request(catcherUrl, tmpOption);
  11455. }
  11456. me.addListener("afterpaste", function () {
  11457. me.fireEvent("catchRemoteImage");
  11458. });
  11459. me.addListener("catchRemoteImage", function () {
  11460. var remoteImages = [];
  11461. var imgs = domUtils.getElementsByTagName(me.document, "img");
  11462. var test = function (src,urls) {
  11463. for (var j = 0, url; url = urls[j++];) {
  11464. if (src.indexOf(url) !== -1) {
  11465. return true;
  11466. }
  11467. }
  11468. return false;
  11469. };
  11470. for (var i = 0, ci; ci = imgs[i++];) {
  11471. if (ci.getAttribute("word_img"))continue;
  11472. var src = ci.getAttribute("data_ue_src") || ci.src || "";
  11473. if (/^(https?|ftp):/i.test(src) && !test(src,localDomain)) {
  11474. remoteImages.push(src);
  11475. }
  11476. }
  11477. if (remoteImages.length) {
  11478. catchremoteimage(remoteImages, {
  11479. //成功抓取
  11480. success:function (xhr) {
  11481. try {
  11482. var info = eval("(" + xhr.responseText + ")");
  11483. } catch (e) {
  11484. return;
  11485. }
  11486. var srcUrls = info.srcUrl.split(separater),
  11487. urls = info.url.split(separater);
  11488. for (var i = 0, ci; ci = imgs[i++];) {
  11489. var src = ci.getAttribute("data_ue_src") || ci.src || "";
  11490. for (var j = 0, cj; cj = srcUrls[j++];) {
  11491. var url = urls[j - 1];
  11492. if (src == cj && url != "error") { //抓取失败时不做替换处理
  11493. //地址修正
  11494. var newSrc = me.options.catcherPath + url;
  11495. domUtils.setAttributes(ci, {
  11496. "src":newSrc,
  11497. "data_ue_src":newSrc
  11498. });
  11499. break;
  11500. }
  11501. }
  11502. }
  11503. },
  11504. //回调失败,本次请求超时
  11505. error:function () {
  11506. me.fireEvent("catchremoteerror");
  11507. }
  11508. })
  11509. }
  11510. })
  11511. };
  11512. ///import core
  11513. ///commandsName snapscreen
  11514. ///commandsTitle 截屏
  11515. /**
  11516. * 截屏插件
  11517. */
  11518. UE.commands['snapscreen'] = {
  11519. execCommand: function(){
  11520. var me = this;
  11521. me.setOpt({
  11522. snapscreenServerPort: 80 //屏幕截图的server端端口
  11523. ,snapscreenImgAlign: 'center' //截图的图片默认的排版方式
  11524. });
  11525. var editorOptions = me.options;
  11526. if(!browser.ie){
  11527. alert('截图功能需要在ie浏览器下使用');
  11528. return;
  11529. }
  11530. var onSuccess = function(rs){
  11531. try{
  11532. rs = eval("("+ rs +")");
  11533. }catch(e){
  11534. alert('截屏上传有误\n\n请检查editor_config.js中关于截屏的配置项\n\nsnapscreenHost 变量值 应该为屏幕截图的server端文件所在的网站地址或者ip');
  11535. return;
  11536. }
  11537. if(rs.state != 'SUCCESS'){
  11538. alert(rs.state);
  11539. return;
  11540. }
  11541. me.execCommand('insertimage', {
  11542. src: editorOptions.snapscreenPath + rs.url,
  11543. floatStyle: editorOptions.snapscreenImgAlign,
  11544. data_ue_src:editorOptions.snapscreenPath + rs.url
  11545. });
  11546. };
  11547. var onStartUpload = function(){
  11548. //开始截图上传
  11549. };
  11550. var onError = function(){
  11551. alert('截图上传失败,请检查你的PHP环境。 ');
  11552. };
  11553. try{
  11554. var nativeObj = new ActiveXObject('Snapsie.CoSnapsie');
  11555. nativeObj.saveSnapshot(editorOptions.snapscreenHost, editorOptions.snapscreenServerUrl, editorOptions.snapscreenServerPort, onStartUpload,onSuccess,onError);
  11556. }catch(e){
  11557. me.ui._dialogs['snapscreenDialog'].open();
  11558. }
  11559. },
  11560. queryCommandState: function(){
  11561. return this.highlight || !browser.ie ? -1 :0;
  11562. }
  11563. };
  11564. ///import core
  11565. ///commandsName attachment
  11566. ///commandsTitle 附件上传
  11567. UE.commands["attachment"] = {
  11568. queryCommandState:function(){
  11569. return this.highlight ? -1 :0;
  11570. }
  11571. };
  11572. /**
  11573. * Created by JetBrains PhpStorm.
  11574. * User: taoqili
  11575. * Date: 12-5-7
  11576. * Time: 下午2:37
  11577. * To change this template use File | Settings | File Templates.
  11578. */
  11579. UE.plugins['webapp'] = function () {
  11580. var me = this;
  11581. function createInsertStr( obj, toIframe, addParagraph ) {
  11582. return !toIframe ?
  11583. (addParagraph ? '<p>' : '') + '<img title="'+obj.title+'" width="' + obj.width + '" height="' + obj.height + '"' +
  11584. ' src="' + me.options.UEDITOR_HOME_URL + 'themes/default/images/spacer.gif" style="background:url(' + obj.logo+') no-repeat center center; border:1px solid gray;" class="edui-faked-webapp" _url="' + obj.url + '" />' +
  11585. (addParagraph ? '</p>' : '')
  11586. :
  11587. '<iframe class="edui-faked-webapp" title="'+obj.title+'" width="' + obj.width + '" height="' + obj.height + '" scrolling="no" frameborder="0" src="' + obj.url + '" logo_url = '+obj.logo+'></iframe>';
  11588. }
  11589. function switchImgAndIframe( img2frame ) {
  11590. var tmpdiv,
  11591. nodes = domUtils.getElementsByTagName( me.document, !img2frame ? "iframe" : "img" );
  11592. for ( var i = 0, node; node = nodes[i++]; ) {
  11593. if ( node.className != "edui-faked-webapp" )continue;
  11594. tmpdiv = me.document.createElement( "div" );
  11595. tmpdiv.innerHTML = createInsertStr( img2frame ? {url:node.getAttribute( "_url" ), width:node.width, height:node.height,title:node.title,logo:node.style.backgroundImage.replace("url(","").replace(")","")} : {url:node.getAttribute( "src", 2 ),title:node.title, width:node.width, height:node.height,logo:node.getAttribute("logo_url")}, img2frame ? true : false,false );
  11596. node.parentNode.replaceChild( tmpdiv.firstChild, node );
  11597. }
  11598. }
  11599. me.addListener( "beforegetcontent", function () {
  11600. switchImgAndIframe( true );
  11601. } );
  11602. me.addListener( 'aftersetcontent', function () {
  11603. switchImgAndIframe( false );
  11604. } );
  11605. me.addListener( 'aftergetcontent', function ( cmdName ) {
  11606. if ( cmdName == 'aftergetcontent' && me.queryCommandState( 'source' ) )
  11607. return;
  11608. switchImgAndIframe( false );
  11609. } );
  11610. UE.commands['webapp'] = {
  11611. execCommand:function ( cmd, obj ) {
  11612. me.execCommand( "inserthtml", createInsertStr( obj, false,true ) );
  11613. },
  11614. queryCommandState:function () {
  11615. return me.highlight ? -1 : 0;
  11616. }
  11617. };
  11618. };
  11619. var baidu = baidu || {};
  11620. baidu.editor = baidu.editor || {};
  11621. baidu.editor.ui = {};
  11622. (function (){
  11623. var browser = baidu.editor.browser,
  11624. domUtils = baidu.editor.dom.domUtils;
  11625. var magic = '$EDITORUI';
  11626. var root = window[magic] = {};
  11627. var uidMagic = 'ID' + magic;
  11628. var uidCount = 0;
  11629. var uiUtils = baidu.editor.ui.uiUtils = {
  11630. uid: function (obj){
  11631. return (obj ? obj[uidMagic] || (obj[uidMagic] = ++ uidCount) : ++ uidCount);
  11632. },
  11633. hook: function ( fn, callback ) {
  11634. var dg;
  11635. if (fn && fn._callbacks) {
  11636. dg = fn;
  11637. } else {
  11638. dg = function (){
  11639. var q;
  11640. if (fn) {
  11641. q = fn.apply(this, arguments);
  11642. }
  11643. var callbacks = dg._callbacks;
  11644. var k = callbacks.length;
  11645. while (k --) {
  11646. var r = callbacks[k].apply(this, arguments);
  11647. if (q === undefined) {
  11648. q = r;
  11649. }
  11650. }
  11651. return q;
  11652. };
  11653. dg._callbacks = [];
  11654. }
  11655. dg._callbacks.push(callback);
  11656. return dg;
  11657. },
  11658. createElementByHtml: function (html){
  11659. var el = document.createElement('div');
  11660. el.innerHTML = html;
  11661. el = el.firstChild;
  11662. el.parentNode.removeChild(el);
  11663. return el;
  11664. },
  11665. getViewportElement: function (){
  11666. return (browser.ie && browser.quirks) ?
  11667. document.body : document.documentElement;
  11668. },
  11669. getClientRect: function (element){
  11670. var bcr;
  11671. //trace IE6下在控制编辑器显隐时可能会报错,catch一下
  11672. try{
  11673. bcr = element.getBoundingClientRect();
  11674. }catch(e){
  11675. bcr={left:0,top:0,height:0,width:0}
  11676. }
  11677. var rect = {
  11678. left: Math.round(bcr.left),
  11679. top: Math.round(bcr.top),
  11680. height: Math.round(bcr.bottom - bcr.top),
  11681. width: Math.round(bcr.right - bcr.left)
  11682. };
  11683. var doc;
  11684. while ((doc = element.ownerDocument) !== document &&
  11685. (element = domUtils.getWindow(doc).frameElement)) {
  11686. bcr = element.getBoundingClientRect();
  11687. rect.left += bcr.left;
  11688. rect.top += bcr.top;
  11689. }
  11690. rect.bottom = rect.top + rect.height;
  11691. rect.right = rect.left + rect.width;
  11692. return rect;
  11693. },
  11694. getViewportRect: function (){
  11695. var viewportEl = uiUtils.getViewportElement();
  11696. var width = (window.innerWidth || viewportEl.clientWidth) | 0;
  11697. var height = (window.innerHeight ||viewportEl.clientHeight) | 0;
  11698. return {
  11699. left: 0,
  11700. top: 0,
  11701. height: height,
  11702. width: width,
  11703. bottom: height,
  11704. right: width
  11705. };
  11706. },
  11707. setViewportOffset: function (element, offset){
  11708. var rect;
  11709. var fixedLayer = uiUtils.getFixedLayer();
  11710. if (element.parentNode === fixedLayer) {
  11711. element.style.left = offset.left + 'px';
  11712. element.style.top = offset.top + 'px';
  11713. } else {
  11714. domUtils.setViewportOffset(element, offset);
  11715. }
  11716. },
  11717. getEventOffset: function (evt){
  11718. var el = evt.target || evt.srcElement;
  11719. var rect = uiUtils.getClientRect(el);
  11720. var offset = uiUtils.getViewportOffsetByEvent(evt);
  11721. return {
  11722. left: offset.left - rect.left,
  11723. top: offset.top - rect.top
  11724. };
  11725. },
  11726. getViewportOffsetByEvent: function (evt){
  11727. var el = evt.target || evt.srcElement;
  11728. var frameEl = domUtils.getWindow(el).frameElement;
  11729. var offset = {
  11730. left: evt.clientX,
  11731. top: evt.clientY
  11732. };
  11733. if (frameEl && el.ownerDocument !== document) {
  11734. var rect = uiUtils.getClientRect(frameEl);
  11735. offset.left += rect.left;
  11736. offset.top += rect.top;
  11737. }
  11738. return offset;
  11739. },
  11740. setGlobal: function (id, obj){
  11741. root[id] = obj;
  11742. return magic + '["' + id + '"]';
  11743. },
  11744. unsetGlobal: function (id){
  11745. delete root[id];
  11746. },
  11747. copyAttributes: function (tgt, src){
  11748. var attributes = src.attributes;
  11749. var k = attributes.length;
  11750. while (k --) {
  11751. var attrNode = attributes[k];
  11752. if ( attrNode.nodeName != 'style' && attrNode.nodeName != 'class' && (!browser.ie || attrNode.specified) ) {
  11753. tgt.setAttribute(attrNode.nodeName, attrNode.nodeValue);
  11754. }
  11755. }
  11756. if (src.className) {
  11757. tgt.className += ' ' + src.className;
  11758. }
  11759. if (src.style.cssText) {
  11760. tgt.style.cssText += ';' + src.style.cssText;
  11761. }
  11762. },
  11763. removeStyle: function (el, styleName){
  11764. if (el.style.removeProperty) {
  11765. el.style.removeProperty(styleName);
  11766. } else if (el.style.removeAttribute) {
  11767. el.style.removeAttribute(styleName);
  11768. } else throw '';
  11769. },
  11770. contains: function (elA, elB){
  11771. return elA && elB && (elA === elB ? false : (
  11772. elA.contains ? elA.contains(elB) :
  11773. elA.compareDocumentPosition(elB) & 16
  11774. ));
  11775. },
  11776. startDrag: function (evt, callbacks,doc){
  11777. var doc = doc || document;
  11778. var startX = evt.clientX;
  11779. var startY = evt.clientY;
  11780. function handleMouseMove(evt){
  11781. var x = evt.clientX - startX;
  11782. var y = evt.clientY - startY;
  11783. callbacks.ondragmove(x, y);
  11784. if (evt.stopPropagation) {
  11785. evt.stopPropagation();
  11786. } else {
  11787. evt.cancelBubble = true;
  11788. }
  11789. }
  11790. if (doc.addEventListener) {
  11791. function handleMouseUp(evt){
  11792. doc.removeEventListener('mousemove', handleMouseMove, true);
  11793. doc.removeEventListener('mouseup', handleMouseMove, true);
  11794. window.removeEventListener('mouseup', handleMouseUp, true);
  11795. callbacks.ondragstop();
  11796. }
  11797. doc.addEventListener('mousemove', handleMouseMove, true);
  11798. doc.addEventListener('mouseup', handleMouseUp, true);
  11799. window.addEventListener('mouseup', handleMouseUp, true);
  11800. evt.preventDefault();
  11801. } else {
  11802. var elm = evt.srcElement;
  11803. elm.setCapture();
  11804. function releaseCaptrue(){
  11805. elm.releaseCapture();
  11806. elm.detachEvent('onmousemove', handleMouseMove);
  11807. elm.detachEvent('onmouseup', releaseCaptrue);
  11808. elm.detachEvent('onlosecaptrue', releaseCaptrue);
  11809. callbacks.ondragstop();
  11810. }
  11811. elm.attachEvent('onmousemove', handleMouseMove);
  11812. elm.attachEvent('onmouseup', releaseCaptrue);
  11813. elm.attachEvent('onlosecaptrue', releaseCaptrue);
  11814. evt.returnValue = false;
  11815. }
  11816. callbacks.ondragstart();
  11817. },
  11818. getFixedLayer: function (){
  11819. var layer = document.getElementById('edui_fixedlayer');
  11820. if (layer == null) {
  11821. layer = document.createElement('div');
  11822. layer.id = 'edui_fixedlayer';
  11823. document.body.appendChild(layer);
  11824. if (browser.ie && browser.version <= 8) {
  11825. layer.style.position = 'absolute';
  11826. bindFixedLayer();
  11827. setTimeout(updateFixedOffset);
  11828. } else {
  11829. layer.style.position = 'fixed';
  11830. }
  11831. layer.style.left = '0';
  11832. layer.style.top = '0';
  11833. layer.style.width = '0';
  11834. layer.style.height = '0';
  11835. }
  11836. return layer;
  11837. },
  11838. makeUnselectable: function (element){
  11839. if (browser.opera || (browser.ie && browser.version < 9)) {
  11840. element.unselectable = 'on';
  11841. if (element.hasChildNodes()) {
  11842. for (var i=0; i<element.childNodes.length; i++) {
  11843. if (element.childNodes[i].nodeType == 1) {
  11844. uiUtils.makeUnselectable(element.childNodes[i]);
  11845. }
  11846. }
  11847. }
  11848. } else {
  11849. if (element.style.MozUserSelect !== undefined) {
  11850. element.style.MozUserSelect = 'none';
  11851. } else if (element.style.WebkitUserSelect !== undefined) {
  11852. element.style.WebkitUserSelect = 'none';
  11853. } else if (element.style.KhtmlUserSelect !== undefined) {
  11854. element.style.KhtmlUserSelect = 'none';
  11855. }
  11856. }
  11857. }
  11858. };
  11859. function updateFixedOffset(){
  11860. var layer = document.getElementById('edui_fixedlayer');
  11861. uiUtils.setViewportOffset(layer, {
  11862. left: 0,
  11863. top: 0
  11864. });
  11865. // layer.style.display = 'none';
  11866. // layer.style.display = 'block';
  11867. //#trace: 1354
  11868. // setTimeout(updateFixedOffset);
  11869. }
  11870. function bindFixedLayer(adjOffset){
  11871. domUtils.on(window, 'scroll', updateFixedOffset);
  11872. domUtils.on(window, 'resize', baidu.editor.utils.defer(updateFixedOffset, 0, true));
  11873. }
  11874. })();
  11875. (function (){
  11876. var utils = baidu.editor.utils,
  11877. uiUtils = baidu.editor.ui.uiUtils,
  11878. EventBase = baidu.editor.EventBase,
  11879. UIBase = baidu.editor.ui.UIBase = function (){};
  11880. UIBase.prototype = {
  11881. className: '',
  11882. uiName: '',
  11883. initOptions: function (options){
  11884. var me = this;
  11885. for (var k in options) {
  11886. me[k] = options[k];
  11887. }
  11888. this.id = this.id || 'edui' + uiUtils.uid();
  11889. },
  11890. initUIBase: function (){
  11891. this._globalKey = utils.unhtml( uiUtils.setGlobal(this.id, this) );
  11892. },
  11893. render: function (holder){
  11894. var html = this.renderHtml();
  11895. var el = uiUtils.createElementByHtml(html);
  11896. var seatEl = this.getDom();
  11897. if (seatEl != null) {
  11898. seatEl.parentNode.replaceChild(el, seatEl);
  11899. uiUtils.copyAttributes(el, seatEl);
  11900. } else {
  11901. if (typeof holder == 'string') {
  11902. holder = document.getElementById(holder);
  11903. }
  11904. holder = holder || uiUtils.getFixedLayer();
  11905. holder.appendChild(el);
  11906. }
  11907. this.postRender();
  11908. },
  11909. getDom: function (name){
  11910. if (!name) {
  11911. return document.getElementById( this.id );
  11912. } else {
  11913. return document.getElementById( this.id + '_' + name );
  11914. }
  11915. },
  11916. postRender: function (){
  11917. this.fireEvent('postrender');
  11918. },
  11919. getHtmlTpl: function (){
  11920. return '';
  11921. },
  11922. formatHtml: function (tpl){
  11923. var prefix = 'edui-' + this.uiName;
  11924. return (tpl
  11925. .replace(/##/g, this.id)
  11926. .replace(/%%-/g, this.uiName ? prefix + '-' : '')
  11927. .replace(/%%/g, (this.uiName ? prefix : '') + ' ' + this.className)
  11928. .replace(/\$\$/g, this._globalKey));
  11929. },
  11930. renderHtml: function (){
  11931. return this.formatHtml(this.getHtmlTpl());
  11932. },
  11933. dispose: function (){
  11934. var box = this.getDom();
  11935. if (box) baidu.editor.dom.domUtils.remove( box );
  11936. uiUtils.unsetGlobal(this.id);
  11937. }
  11938. };
  11939. utils.inherits(UIBase, EventBase);
  11940. })();
  11941. (function (){
  11942. var utils = baidu.editor.utils,
  11943. UIBase = baidu.editor.ui.UIBase,
  11944. Separator = baidu.editor.ui.Separator = function (options){
  11945. this.initOptions(options);
  11946. this.initSeparator();
  11947. };
  11948. Separator.prototype = {
  11949. uiName: 'separator',
  11950. initSeparator: function (){
  11951. this.initUIBase();
  11952. },
  11953. getHtmlTpl: function (){
  11954. return '<div id="##" class="edui-box %%"></div>';
  11955. }
  11956. };
  11957. utils.inherits(Separator, UIBase);
  11958. })();
  11959. ///import core
  11960. ///import uicore
  11961. (function (){
  11962. var utils = baidu.editor.utils,
  11963. domUtils = baidu.editor.dom.domUtils,
  11964. UIBase = baidu.editor.ui.UIBase,
  11965. uiUtils = baidu.editor.ui.uiUtils;
  11966. var Mask = baidu.editor.ui.Mask = function (options){
  11967. this.initOptions(options);
  11968. this.initUIBase();
  11969. };
  11970. Mask.prototype = {
  11971. getHtmlTpl: function (){
  11972. return '<div id="##" class="edui-mask %%" onmousedown="return $$._onMouseDown(event, this);"></div>';
  11973. },
  11974. postRender: function (){
  11975. var me = this;
  11976. domUtils.on(window, 'resize', function (){
  11977. setTimeout(function (){
  11978. if (!me.isHidden()) {
  11979. me._fill();
  11980. }
  11981. });
  11982. });
  11983. },
  11984. show: function (zIndex){
  11985. this._fill();
  11986. this.getDom().style.display = '';
  11987. this.getDom().style.zIndex = zIndex;
  11988. },
  11989. hide: function (){
  11990. this.getDom().style.display = 'none';
  11991. this.getDom().style.zIndex = '';
  11992. },
  11993. isHidden: function (){
  11994. return this.getDom().style.display == 'none';
  11995. },
  11996. _onMouseDown: function (){
  11997. return false;
  11998. },
  11999. _fill: function (){
  12000. var el = this.getDom();
  12001. var vpRect = uiUtils.getViewportRect();
  12002. el.style.width = vpRect.width + 'px';
  12003. el.style.height = vpRect.height + 'px';
  12004. }
  12005. };
  12006. utils.inherits(Mask, UIBase);
  12007. })();
  12008. ///import core
  12009. ///import uicore
  12010. (function () {
  12011. var utils = baidu.editor.utils,
  12012. uiUtils = baidu.editor.ui.uiUtils,
  12013. domUtils = baidu.editor.dom.domUtils,
  12014. UIBase = baidu.editor.ui.UIBase,
  12015. Popup = baidu.editor.ui.Popup = function (options){
  12016. this.initOptions(options);
  12017. this.initPopup();
  12018. };
  12019. var allPopups = [];
  12020. function closeAllPopup( el ){
  12021. var newAll = [];
  12022. for ( var i = 0; i < allPopups.length; i++ ) {
  12023. var pop = allPopups[i];
  12024. if (!pop.isHidden()) {
  12025. if (pop.queryAutoHide(el) !== false) {
  12026. pop.hide();
  12027. }
  12028. }
  12029. }
  12030. }
  12031. Popup.postHide = closeAllPopup;
  12032. var ANCHOR_CLASSES = ['edui-anchor-topleft','edui-anchor-topright',
  12033. 'edui-anchor-bottomleft','edui-anchor-bottomright'];
  12034. Popup.prototype = {
  12035. SHADOW_RADIUS: 5,
  12036. content: null,
  12037. _hidden: false,
  12038. autoRender: true,
  12039. canSideLeft: true,
  12040. canSideUp: true,
  12041. initPopup: function (){
  12042. this.initUIBase();
  12043. allPopups.push( this );
  12044. },
  12045. getHtmlTpl: function (){
  12046. return '<div id="##" class="edui-popup %%">' +
  12047. ' <div id="##_body" class="edui-popup-body">' +
  12048. ' <iframe style="position:absolute;z-index:-1;left:0;top:0;background-color: white;" frameborder="0" width="100%" height="100%" src="javascript:"></iframe>' +
  12049. ' <div class="edui-shadow"></div>' +
  12050. ' <div id="##_content" class="edui-popup-content">' +
  12051. this.getContentHtmlTpl() +
  12052. ' </div>' +
  12053. ' </div>' +
  12054. '</div>';
  12055. },
  12056. getContentHtmlTpl: function (){
  12057. if(this.content){
  12058. if (typeof this.content == 'string') {
  12059. return this.content;
  12060. }
  12061. return this.content.renderHtml();
  12062. }else{
  12063. return ''
  12064. }
  12065. },
  12066. _UIBase_postRender: UIBase.prototype.postRender,
  12067. postRender: function (){
  12068. if (this.content instanceof UIBase) {
  12069. this.content.postRender();
  12070. }
  12071. this.fireEvent('postRenderAfter');
  12072. this.hide(true);
  12073. this._UIBase_postRender();
  12074. },
  12075. _doAutoRender: function (){
  12076. if (!this.getDom() && this.autoRender) {
  12077. this.render();
  12078. }
  12079. },
  12080. mesureSize: function (){
  12081. var box = this.getDom('content');
  12082. return uiUtils.getClientRect(box);
  12083. },
  12084. fitSize: function (){
  12085. var popBodyEl = this.getDom('body');
  12086. popBodyEl.style.width = '';
  12087. popBodyEl.style.height = '';
  12088. var size = this.mesureSize();
  12089. popBodyEl.style.width = size.width + 'px';
  12090. popBodyEl.style.height = size.height + 'px';
  12091. return size;
  12092. },
  12093. showAnchor: function ( element, hoz ){
  12094. this.showAnchorRect( uiUtils.getClientRect( element ), hoz );
  12095. },
  12096. showAnchorRect: function ( rect, hoz, adj ){
  12097. this._doAutoRender();
  12098. var vpRect = uiUtils.getViewportRect();
  12099. this._show();
  12100. var popSize = this.fitSize();
  12101. var sideLeft, sideUp, left, top;
  12102. if (hoz) {
  12103. sideLeft = this.canSideLeft && (rect.right + popSize.width > vpRect.right && rect.left > popSize.width);
  12104. sideUp = this.canSideUp && (rect.top + popSize.height > vpRect.bottom && rect.bottom > popSize.height);
  12105. left = (sideLeft ? rect.left - popSize.width : rect.right);
  12106. top = (sideUp ? rect.bottom - popSize.height : rect.top);
  12107. } else {
  12108. sideLeft = this.canSideLeft && (rect.right + popSize.width > vpRect.right && rect.left > popSize.width);
  12109. sideUp = this.canSideUp && (rect.top + popSize.height > vpRect.bottom && rect.bottom > popSize.height);
  12110. left = (sideLeft ? rect.right - popSize.width : rect.left);
  12111. top = (sideUp ? rect.top - popSize.height : rect.bottom);
  12112. }
  12113. var popEl = this.getDom();
  12114. uiUtils.setViewportOffset(popEl, {
  12115. left: left,
  12116. top: top
  12117. });
  12118. domUtils.removeClasses(popEl, ANCHOR_CLASSES);
  12119. popEl.className += ' ' + ANCHOR_CLASSES[(sideUp ? 1 : 0) * 2 + (sideLeft ? 1 : 0)];
  12120. if(this.editor){
  12121. popEl.style.zIndex = this.editor.container.style.zIndex * 1 + 10;
  12122. baidu.editor.ui.uiUtils.getFixedLayer().style.zIndex = popEl.style.zIndex - 1;
  12123. }
  12124. },
  12125. showAt: function (offset) {
  12126. var left = offset.left;
  12127. var top = offset.top;
  12128. var rect = {
  12129. left: left,
  12130. top: top,
  12131. right: left,
  12132. bottom: top,
  12133. height: 0,
  12134. width: 0
  12135. };
  12136. this.showAnchorRect(rect, false, true);
  12137. },
  12138. _show: function (){
  12139. if (this._hidden) {
  12140. var box = this.getDom();
  12141. box.style.display = '';
  12142. this._hidden = false;
  12143. // if (box.setActive) {
  12144. // box.setActive();
  12145. // }
  12146. this.fireEvent('show');
  12147. }
  12148. },
  12149. isHidden: function (){
  12150. return this._hidden;
  12151. },
  12152. show: function (){
  12153. this._doAutoRender();
  12154. this._show();
  12155. },
  12156. hide: function (notNofity){
  12157. if (!this._hidden && this.getDom()) {
  12158. // this.getDom().style.visibility = 'hidden';
  12159. this.getDom().style.display = 'none';
  12160. this._hidden = true;
  12161. if (!notNofity) {
  12162. this.fireEvent('hide');
  12163. }
  12164. }
  12165. },
  12166. queryAutoHide: function (el){
  12167. return !el || !uiUtils.contains(this.getDom(), el);
  12168. }
  12169. };
  12170. utils.inherits(Popup, UIBase);
  12171. domUtils.on( document, 'mousedown', function ( evt ) {
  12172. var el = evt.target || evt.srcElement;
  12173. closeAllPopup( el );
  12174. } );
  12175. domUtils.on( window, 'scroll', function () {
  12176. closeAllPopup();
  12177. } );
  12178. // var lastVpRect = uiUtils.getViewportRect();
  12179. // domUtils.on( window, 'resize', function () {
  12180. // var vpRect = uiUtils.getViewportRect();
  12181. // if (vpRect.width != lastVpRect.width || vpRect.height != lastVpRect.height) {
  12182. // closeAllPopup();
  12183. // }
  12184. // } );
  12185. })();
  12186. ///import core
  12187. ///import uicore
  12188. (function (){
  12189. var utils = baidu.editor.utils,
  12190. UIBase = baidu.editor.ui.UIBase,
  12191. ColorPicker = baidu.editor.ui.ColorPicker = function (options){
  12192. this.initOptions(options);
  12193. this.noColorText = this.noColorText || '不设置颜色';
  12194. this.initUIBase();
  12195. };
  12196. ColorPicker.prototype = {
  12197. getHtmlTpl: function (){
  12198. return genColorPicker(
  12199. this.noColorText
  12200. );
  12201. },
  12202. _onTableClick: function (evt){
  12203. var tgt = evt.target || evt.srcElement;
  12204. var color = tgt.getAttribute('data-color');
  12205. if (color) {
  12206. this.fireEvent('pickcolor', color);
  12207. }
  12208. },
  12209. _onTableOver: function (evt){
  12210. var tgt = evt.target || evt.srcElement;
  12211. var color = tgt.getAttribute('data-color');
  12212. if (color) {
  12213. this.getDom('preview').style.backgroundColor = color;
  12214. }
  12215. },
  12216. _onTableOut: function (){
  12217. this.getDom('preview').style.backgroundColor = '';
  12218. },
  12219. _onPickNoColor: function (){
  12220. this.fireEvent('picknocolor');
  12221. }
  12222. };
  12223. utils.inherits(ColorPicker, UIBase);
  12224. var COLORS = (
  12225. 'ffffff,000000,eeece1,1f497d,4f81bd,c0504d,9bbb59,8064a2,4bacc6,f79646,' +
  12226. 'f2f2f2,7f7f7f,ddd9c3,c6d9f0,dbe5f1,f2dcdb,ebf1dd,e5e0ec,dbeef3,fdeada,' +
  12227. 'd8d8d8,595959,c4bd97,8db3e2,b8cce4,e5b9b7,d7e3bc,ccc1d9,b7dde8,fbd5b5,' +
  12228. 'bfbfbf,3f3f3f,938953,548dd4,95b3d7,d99694,c3d69b,b2a2c7,92cddc,fac08f,' +
  12229. 'a5a5a5,262626,494429,17365d,366092,953734,76923c,5f497a,31859b,e36c09,' +
  12230. '7f7f7f,0c0c0c,1d1b10,0f243e,244061,632423,4f6128,3f3151,205867,974806,' +
  12231. 'c00000,ff0000,ffc000,ffff00,92d050,00b050,00b0f0,0070c0,002060,7030a0,').split(',');
  12232. function genColorPicker(noColorText){
  12233. var html = '<div id="##" class="edui-colorpicker %%">' +
  12234. '<div class="edui-colorpicker-topbar edui-clearfix">' +
  12235. '<div unselectable="on" id="##_preview" class="edui-colorpicker-preview"></div>' +
  12236. '<div unselectable="on" class="edui-colorpicker-nocolor" onclick="$$._onPickNoColor(event, this);">'+ noColorText +'</div>' +
  12237. '</div>' +
  12238. '<table class="edui-box" style="border-collapse: collapse;" onmouseover="$$._onTableOver(event, this);" onmouseout="$$._onTableOut(event, this);" onclick="return $$._onTableClick(event, this);" cellspacing="0" cellpadding="0">' +
  12239. '<tr style="border-bottom: 1px solid #ddd;font-size: 13px;line-height: 25px;color:#366092;padding-top: 2px"><td colspan="10">主题颜色</td> </tr>'+
  12240. '<tr class="edui-colorpicker-tablefirstrow" >';
  12241. for (var i=0; i<COLORS.length; i++) {
  12242. if (i && i%10 === 0) {
  12243. html += '</tr>'+(i==60?'<tr style="border-bottom: 1px solid #ddd;font-size: 13px;line-height: 25px;color:#366092;"><td colspan="10">标准颜色</td></tr>':'')+'<tr'+(i==60?' class="edui-colorpicker-tablefirstrow"':'')+'>';
  12244. }
  12245. html += i<70 ? '<td style="padding: 0 2px;"><a hidefocus title="'+COLORS[i]+'" onclick="return false;" href="javascript:" unselectable="on" class="edui-box edui-colorpicker-colorcell"' +
  12246. ' data-color="#'+ COLORS[i] +'"'+
  12247. ' style="background-color:#'+ COLORS[i] +';border:solid #ccc;'+
  12248. (i<10 || i>=60?'border-width:1px;':
  12249. i>=10&&i<20?'border-width:1px 1px 0 1px;':
  12250. 'border-width:0 1px 0 1px;')+
  12251. '"' +
  12252. '></a></td>':'';
  12253. }
  12254. html += '</tr></table></div>';
  12255. return html;
  12256. }
  12257. })();
  12258. ///import core
  12259. ///import uicore
  12260. (function (){
  12261. var utils = baidu.editor.utils,
  12262. uiUtils = baidu.editor.ui.uiUtils,
  12263. UIBase = baidu.editor.ui.UIBase;
  12264. var TablePicker = baidu.editor.ui.TablePicker = function (options){
  12265. this.initOptions(options);
  12266. this.initTablePicker();
  12267. };
  12268. TablePicker.prototype = {
  12269. defaultNumRows: 10,
  12270. defaultNumCols: 10,
  12271. maxNumRows: 20,
  12272. maxNumCols: 20,
  12273. numRows: 10,
  12274. numCols: 10,
  12275. lengthOfCellSide: 22,
  12276. initTablePicker: function (){
  12277. this.initUIBase();
  12278. },
  12279. getHtmlTpl: function (){
  12280. return '<div id="##" class="edui-tablepicker %%">' +
  12281. '<div class="edui-tablepicker-body">' +
  12282. '<div class="edui-infoarea">' +
  12283. '<span id="##_label" class="edui-label"></span>' +
  12284. '<span class="edui-clickable" onclick="$$._onMore();">更多</span>' +
  12285. '</div>' +
  12286. '<div class="edui-pickarea"' +
  12287. ' onmousemove="$$._onMouseMove(event, this);"' +
  12288. ' onmouseover="$$._onMouseOver(event, this);"' +
  12289. ' onmouseout="$$._onMouseOut(event, this);"' +
  12290. ' onclick="$$._onClick(event, this);"' +
  12291. '>' +
  12292. '<div id="##_overlay" class="edui-overlay"></div>' +
  12293. '</div>' +
  12294. '</div>' +
  12295. '</div>';
  12296. },
  12297. _UIBase_render: UIBase.prototype.render,
  12298. render: function (holder){
  12299. this._UIBase_render(holder);
  12300. this.getDom('label').innerHTML = '0列 x 0行';
  12301. },
  12302. _track: function (numCols, numRows){
  12303. var style = this.getDom('overlay').style;
  12304. var sideLen = this.lengthOfCellSide;
  12305. style.width = numCols * sideLen + 'px';
  12306. style.height = numRows * sideLen + 'px';
  12307. var label = this.getDom('label');
  12308. label.innerHTML = numCols + '列 x ' + numRows + '行';
  12309. this.numCols = numCols;
  12310. this.numRows = numRows;
  12311. },
  12312. _onMouseOver: function (evt, el){
  12313. var rel = evt.relatedTarget || evt.fromElement;
  12314. if (!uiUtils.contains(el, rel) && el !== rel) {
  12315. this.getDom('label').innerHTML = '0列 x 0行';
  12316. this.getDom('overlay').style.visibility = '';
  12317. }
  12318. },
  12319. _onMouseOut: function (evt, el){
  12320. var rel = evt.relatedTarget || evt.toElement;
  12321. if (!uiUtils.contains(el, rel) && el !== rel) {
  12322. this.getDom('label').innerHTML = '0列 x 0行';
  12323. this.getDom('overlay').style.visibility = 'hidden';
  12324. }
  12325. },
  12326. _onMouseMove: function (evt, el){
  12327. var style = this.getDom('overlay').style;
  12328. var offset = uiUtils.getEventOffset(evt);
  12329. var sideLen = this.lengthOfCellSide;
  12330. var numCols = Math.ceil(offset.left / sideLen);
  12331. var numRows = Math.ceil(offset.top / sideLen);
  12332. this._track(numCols, numRows);
  12333. },
  12334. _onClick: function (){
  12335. this.fireEvent('picktable', this.numCols, this.numRows);
  12336. },
  12337. _onMore: function (){
  12338. this.fireEvent('more');
  12339. }
  12340. };
  12341. utils.inherits(TablePicker, UIBase);
  12342. })();
  12343. (function (){
  12344. var browser = baidu.editor.browser,
  12345. domUtils = baidu.editor.dom.domUtils,
  12346. uiUtils = baidu.editor.ui.uiUtils;
  12347. var TPL_STATEFUL = 'onmousedown="$$.Stateful_onMouseDown(event, this);"' +
  12348. ' onmouseup="$$.Stateful_onMouseUp(event, this);"' +
  12349. ( browser.ie ? (
  12350. ' onmouseenter="$$.Stateful_onMouseEnter(event, this);"' +
  12351. ' onmouseleave="$$.Stateful_onMouseLeave(event, this);"' )
  12352. : (
  12353. ' onmouseover="$$.Stateful_onMouseOver(event, this);"' +
  12354. ' onmouseout="$$.Stateful_onMouseOut(event, this);"' ));
  12355. baidu.editor.ui.Stateful = {
  12356. alwalysHoverable: false,
  12357. Stateful_init: function (){
  12358. this._Stateful_dGetHtmlTpl = this.getHtmlTpl;
  12359. this.getHtmlTpl = this.Stateful_getHtmlTpl;
  12360. },
  12361. Stateful_getHtmlTpl: function (){
  12362. var tpl = this._Stateful_dGetHtmlTpl();
  12363. // 使用function避免$转义
  12364. return tpl.replace(/stateful/g, function (){ return TPL_STATEFUL; });
  12365. },
  12366. Stateful_onMouseEnter: function (evt, el){
  12367. if (!this.isDisabled() || this.alwalysHoverable) {
  12368. this.addState('hover');
  12369. this.fireEvent('over');
  12370. }
  12371. },
  12372. Stateful_onMouseLeave: function (evt, el){
  12373. if (!this.isDisabled() || this.alwalysHoverable) {
  12374. this.removeState('hover');
  12375. this.removeState('active');
  12376. this.fireEvent('out');
  12377. }
  12378. },
  12379. Stateful_onMouseOver: function (evt, el){
  12380. var rel = evt.relatedTarget;
  12381. if (!uiUtils.contains(el, rel) && el !== rel) {
  12382. this.Stateful_onMouseEnter(evt, el);
  12383. }
  12384. },
  12385. Stateful_onMouseOut: function (evt, el){
  12386. var rel = evt.relatedTarget;
  12387. if (!uiUtils.contains(el, rel) && el !== rel) {
  12388. this.Stateful_onMouseLeave(evt, el);
  12389. }
  12390. },
  12391. Stateful_onMouseDown: function (evt, el){
  12392. if (!this.isDisabled()) {
  12393. this.addState('active');
  12394. }
  12395. },
  12396. Stateful_onMouseUp: function (evt, el){
  12397. if (!this.isDisabled()) {
  12398. this.removeState('active');
  12399. }
  12400. },
  12401. Stateful_postRender: function (){
  12402. if (this.disabled && !this.hasState('disabled')) {
  12403. this.addState('disabled');
  12404. }
  12405. },
  12406. hasState: function (state){
  12407. return domUtils.hasClass(this.getStateDom(), 'edui-state-' + state);
  12408. },
  12409. addState: function (state){
  12410. if (!this.hasState(state)) {
  12411. this.getStateDom().className += ' edui-state-' + state;
  12412. }
  12413. },
  12414. removeState: function (state){
  12415. if (this.hasState(state)) {
  12416. domUtils.removeClasses(this.getStateDom(), ['edui-state-' + state]);
  12417. }
  12418. },
  12419. getStateDom: function (){
  12420. return this.getDom('state');
  12421. },
  12422. isChecked: function (){
  12423. return this.hasState('checked');
  12424. },
  12425. setChecked: function (checked){
  12426. if (!this.isDisabled() && checked) {
  12427. this.addState('checked');
  12428. } else {
  12429. this.removeState('checked');
  12430. }
  12431. },
  12432. isDisabled: function (){
  12433. return this.hasState('disabled');
  12434. },
  12435. setDisabled: function (disabled){
  12436. if (disabled) {
  12437. this.removeState('hover');
  12438. this.removeState('checked');
  12439. this.removeState('active');
  12440. this.addState('disabled');
  12441. } else {
  12442. this.removeState('disabled');
  12443. }
  12444. }
  12445. };
  12446. })();
  12447. ///import core
  12448. ///import uicore
  12449. ///import ui/stateful.js
  12450. (function (){
  12451. var utils = baidu.editor.utils,
  12452. UIBase = baidu.editor.ui.UIBase,
  12453. Stateful = baidu.editor.ui.Stateful,
  12454. Button = baidu.editor.ui.Button = function (options){
  12455. this.initOptions(options);
  12456. this.initButton();
  12457. };
  12458. Button.prototype = {
  12459. uiName: 'button',
  12460. label: '',
  12461. title: '',
  12462. showIcon: true,
  12463. showText: true,
  12464. initButton: function (){
  12465. this.initUIBase();
  12466. this.Stateful_init();
  12467. },
  12468. getHtmlTpl: function (){
  12469. return '<div id="##" class="edui-box %%">' +
  12470. '<div id="##_state" stateful>' +
  12471. '<div class="%%-wrap"><div id="##_body" unselectable="on" ' + (this.title ? 'title="' + this.title + '"' : '') +
  12472. ' class="%%-body" onmousedown="return false;" onclick="return $$._onClick();">' +
  12473. (this.showIcon ? '<div class="edui-box edui-icon"></div>' : '') +
  12474. (this.showText ? '<div class="edui-box edui-label">' + this.label + '</div>' : '') +
  12475. '</div>' +
  12476. '</div>' +
  12477. '</div></div>';
  12478. },
  12479. postRender: function (){
  12480. this.Stateful_postRender();
  12481. },
  12482. _onClick: function (){
  12483. if (!this.isDisabled()) {
  12484. this.fireEvent('click');
  12485. }
  12486. }
  12487. };
  12488. utils.inherits(Button, UIBase);
  12489. utils.extend(Button.prototype, Stateful);
  12490. })();
  12491. ///import core
  12492. ///import uicore
  12493. ///import ui/stateful.js
  12494. (function (){
  12495. var utils = baidu.editor.utils,
  12496. uiUtils = baidu.editor.ui.uiUtils,
  12497. domUtils = baidu.editor.dom.domUtils,
  12498. UIBase = baidu.editor.ui.UIBase,
  12499. Stateful = baidu.editor.ui.Stateful,
  12500. SplitButton = baidu.editor.ui.SplitButton = function (options){
  12501. this.initOptions(options);
  12502. this.initSplitButton();
  12503. };
  12504. SplitButton.prototype = {
  12505. popup: null,
  12506. uiName: 'splitbutton',
  12507. title: '',
  12508. initSplitButton: function (){
  12509. this.initUIBase();
  12510. this.Stateful_init();
  12511. var me = this;
  12512. if (this.popup != null) {
  12513. var popup = this.popup;
  12514. this.popup = null;
  12515. this.setPopup(popup);
  12516. }
  12517. },
  12518. _UIBase_postRender: UIBase.prototype.postRender,
  12519. postRender: function (){
  12520. this.Stateful_postRender();
  12521. this._UIBase_postRender();
  12522. },
  12523. setPopup: function (popup){
  12524. if (this.popup === popup) return;
  12525. if (this.popup != null) {
  12526. this.popup.dispose();
  12527. }
  12528. popup.addListener('show', utils.bind(this._onPopupShow, this));
  12529. popup.addListener('hide', utils.bind(this._onPopupHide, this));
  12530. popup.addListener('postrender', utils.bind(function (){
  12531. popup.getDom('body').appendChild(
  12532. uiUtils.createElementByHtml('<div id="' +
  12533. this.popup.id + '_bordereraser" class="edui-bordereraser edui-background" style="width:' +
  12534. (uiUtils.getClientRect(this.getDom()).width - 2) + 'px"></div>')
  12535. );
  12536. popup.getDom().className += ' ' + this.className;
  12537. }, this));
  12538. this.popup = popup;
  12539. },
  12540. _onPopupShow: function (){
  12541. this.addState('opened');
  12542. },
  12543. _onPopupHide: function (){
  12544. this.removeState('opened');
  12545. },
  12546. getHtmlTpl: function (){
  12547. return '<div id="##" class="edui-box %%">' +
  12548. '<div '+ (this.title ? 'title="' + this.title + '"' : '') +' id="##_state" stateful><div class="%%-body">' +
  12549. '<div id="##_button_body" class="edui-box edui-button-body" onclick="$$._onButtonClick(event, this);">' +
  12550. '<div class="edui-box edui-icon"></div>' +
  12551. '</div>' +
  12552. '<div class="edui-box edui-splitborder"></div>' +
  12553. '<div class="edui-box edui-arrow" onclick="$$._onArrowClick();"></div>' +
  12554. '</div></div></div>';
  12555. },
  12556. showPopup: function (){
  12557. // 当popup往上弹出的时候,做特殊处理
  12558. var rect = uiUtils.getClientRect(this.getDom());
  12559. rect.top -= this.popup.SHADOW_RADIUS;
  12560. rect.height += this.popup.SHADOW_RADIUS;
  12561. this.popup.showAnchorRect(rect);
  12562. },
  12563. _onArrowClick: function (event, el){
  12564. if (!this.isDisabled()) {
  12565. this.showPopup();
  12566. }
  12567. },
  12568. _onButtonClick: function (){
  12569. if (!this.isDisabled()) {
  12570. this.fireEvent('buttonclick');
  12571. }
  12572. }
  12573. };
  12574. utils.inherits(SplitButton, UIBase);
  12575. utils.extend(SplitButton.prototype, Stateful, true);
  12576. })();
  12577. ///import core
  12578. ///import uicore
  12579. ///import ui/colorpicker.js
  12580. ///import ui/popup.js
  12581. ///import ui/splitbutton.js
  12582. (function (){
  12583. var utils = baidu.editor.utils,
  12584. uiUtils = baidu.editor.ui.uiUtils,
  12585. ColorPicker = baidu.editor.ui.ColorPicker,
  12586. Popup = baidu.editor.ui.Popup,
  12587. SplitButton = baidu.editor.ui.SplitButton,
  12588. ColorButton = baidu.editor.ui.ColorButton = function (options){
  12589. this.initOptions(options);
  12590. this.initColorButton();
  12591. };
  12592. ColorButton.prototype = {
  12593. initColorButton: function (){
  12594. var me = this;
  12595. this.popup = new Popup({
  12596. content: new ColorPicker({
  12597. noColorText: '清除颜色',
  12598. onpickcolor: function (t, color){
  12599. me._onPickColor(color);
  12600. },
  12601. onpicknocolor: function (t, color){
  12602. me._onPickNoColor(color);
  12603. }
  12604. }),
  12605. editor:me.editor
  12606. });
  12607. this.initSplitButton();
  12608. },
  12609. _SplitButton_postRender: SplitButton.prototype.postRender,
  12610. postRender: function (){
  12611. this._SplitButton_postRender();
  12612. this.getDom('button_body').appendChild(
  12613. uiUtils.createElementByHtml('<div id="' + this.id + '_colorlump" class="edui-colorlump"></div>')
  12614. );
  12615. this.getDom().className += ' edui-colorbutton';
  12616. },
  12617. setColor: function (color){
  12618. this.getDom('colorlump').style.backgroundColor = color;
  12619. this.color = color;
  12620. },
  12621. _onPickColor: function (color){
  12622. if (this.fireEvent('pickcolor', color) !== false) {
  12623. this.setColor(color);
  12624. this.popup.hide();
  12625. }
  12626. },
  12627. _onPickNoColor: function (color){
  12628. if (this.fireEvent('picknocolor') !== false) {
  12629. this.popup.hide();
  12630. }
  12631. }
  12632. };
  12633. utils.inherits(ColorButton, SplitButton);
  12634. })();
  12635. ///import core
  12636. ///import uicore
  12637. ///import ui/popup.js
  12638. ///import ui/tablepicker.js
  12639. ///import ui/splitbutton.js
  12640. (function (){
  12641. var utils = baidu.editor.utils,
  12642. Popup = baidu.editor.ui.Popup,
  12643. TablePicker = baidu.editor.ui.TablePicker,
  12644. SplitButton = baidu.editor.ui.SplitButton,
  12645. TableButton = baidu.editor.ui.TableButton = function (options){
  12646. this.initOptions(options);
  12647. this.initTableButton();
  12648. };
  12649. TableButton.prototype = {
  12650. initTableButton: function (){
  12651. var me = this;
  12652. this.popup = new Popup({
  12653. content: new TablePicker({
  12654. onpicktable: function (t, numCols, numRows){
  12655. me._onPickTable(numCols, numRows);
  12656. },
  12657. onmore: function (){
  12658. me.popup.hide();
  12659. me.fireEvent('more');
  12660. }
  12661. }),
  12662. 'editor':me.editor
  12663. });
  12664. this.initSplitButton();
  12665. },
  12666. _onPickTable: function (numCols, numRows){
  12667. if (this.fireEvent('picktable', numCols, numRows) !== false) {
  12668. this.popup.hide();
  12669. }
  12670. }
  12671. };
  12672. utils.inherits(TableButton, SplitButton);
  12673. })();
  12674. ///import core
  12675. ///import uicore
  12676. (function (){
  12677. var utils = baidu.editor.utils,
  12678. UIBase = baidu.editor.ui.UIBase;
  12679. var AutoTypeSetPicker = baidu.editor.ui.AutoTypeSetPicker = function (options){
  12680. this.initOptions(options);
  12681. this.initAutoTypeSetPicker();
  12682. };
  12683. AutoTypeSetPicker.prototype = {
  12684. initAutoTypeSetPicker: function (){
  12685. this.initUIBase();
  12686. },
  12687. getHtmlTpl: function (){
  12688. var opt = this.editor.options.autotypeset;
  12689. return '<div id="##" class="edui-autotypesetpicker %%">' +
  12690. '<div class="edui-autotypesetpicker-body">' +
  12691. '<table >' +
  12692. '<tr><td colspan="2"><input type="checkbox" name="mergeEmptyline" '+ (opt["mergeEmptyline"] ? "checked" : "" )+'>合并空行</td><td colspan="2"><input type="checkbox" name="removeEmptyline" '+ (opt["removeEmptyline"] ? "checked" : "" )+'>删除空行</td></tr>'+
  12693. '<tr><td colspan="2"><input type="checkbox" name="removeClass" '+ (opt["removeClass"] ? "checked" : "" )+'>清除样式</td><td colspan="2"><input type="checkbox" name="indent" '+ (opt["indent"] ? "checked" : "" )+'>首行缩进2字</td></tr>'+
  12694. '<tr><td colspan="2"><input type="checkbox" name="textAlign" '+ (opt["textAlign"] ? "checked" : "" )+'>对齐方式:</td><td colspan="2" id="textAlignValue"><input type="radio" name="textAlignValue" value="left" '+((opt["textAlign"]&&opt["textAlign"]=="left") ? "checked" : "")+'>左对齐<input type="radio" name="textAlignValue" value="center" '+((opt["textAlign"]&&opt["textAlign"]=="center") ? "checked" : "")+'>居中对齐<input type="radio" name="textAlignValue" value="right" '+((opt["textAlign"]&&opt["textAlign"]=="right") ? "checked" : "")+'>右对齐 </tr>'+
  12695. '<tr><td colspan="2"><input type="checkbox" name="imageBlockLine" '+ (opt["imageBlockLine"] ? "checked" : "" )+'>图片浮动</td>' +
  12696. '<td colspan="2" id="imageBlockLineValue">' +
  12697. '<input type="radio" name="imageBlockLineValue" value="none" '+((opt["imageBlockLine"]&&opt["imageBlockLine"]=="none") ? "checked" : "")+'>默认' +
  12698. '<input type="radio" name="imageBlockLineValue" value="left" '+((opt["imageBlockLine"]&&opt["imageBlockLine"]=="left") ? "checked" : "")+'>左浮动' +
  12699. '<input type="radio" name="imageBlockLineValue" value="center" '+((opt["imageBlockLine"]&&opt["imageBlockLine"]=="center") ? "checked" : "")+'>独占行居中' +
  12700. '<input type="radio" name="imageBlockLineValue" value="right" '+((opt["imageBlockLine"]&&opt["imageBlockLine"]=="right") ? "checked" : "")+'>右浮动</tr>'+
  12701. '<tr><td colspan="2"><input type="checkbox" name="clearFontSize" '+ (opt["clearFontSize"] ? "checked" : "" )+'>清除字号</td><td colspan="2"><input type="checkbox" name="clearFontFamily" '+ (opt["clearFontFamily"] ? "checked" : "" )+'>清除字体</td></tr>'+
  12702. '<tr><td colspan="4"><input type="checkbox" name="removeEmptyNode" '+ (opt["removeEmptyNode"] ? "checked" : "" )+'>去掉冗余的html代码</td></tr>'+
  12703. '<tr><td colspan="4"><input type="checkbox" name="pasteFilter" '+ (opt["pasteFilter"] ? "checked" : "" )+'>粘贴过滤 (对每次粘贴的内容应用以上过滤规则)</td></tr>'+
  12704. '<tr><td colspan="4" align="right"><button >执行</button></td></tr>'+
  12705. '</table>'+
  12706. '</div>' +
  12707. '</div>';
  12708. },
  12709. _UIBase_render: UIBase.prototype.render
  12710. };
  12711. utils.inherits(AutoTypeSetPicker, UIBase);
  12712. })();
  12713. ///import core
  12714. ///import uicore
  12715. ///import ui/popup.js
  12716. ///import ui/autotypesetpicker.js
  12717. ///import ui/splitbutton.js
  12718. (function (){
  12719. var utils = baidu.editor.utils,
  12720. Popup = baidu.editor.ui.Popup,
  12721. AutoTypeSetPicker = baidu.editor.ui.AutoTypeSetPicker,
  12722. SplitButton = baidu.editor.ui.SplitButton,
  12723. AutoTypeSetButton = baidu.editor.ui.AutoTypeSetButton = function (options){
  12724. this.initOptions(options);
  12725. this.initAutoTypeSetButton();
  12726. };
  12727. function getPara(me){
  12728. var opt = me.editor.options.autotypeset,
  12729. cont = me.getDom(),
  12730. ipts = domUtils.getElementsByTagName(cont,"input");
  12731. for(var i=ipts.length-1,ipt;ipt=ipts[i--];){
  12732. if(ipt.getAttribute("type")=="checkbox"){
  12733. var attrName = ipt.getAttribute("name");
  12734. opt[attrName] && delete opt[attrName];
  12735. if(ipt.checked){
  12736. var attrValue = document.getElementById(attrName+"Value");
  12737. if(attrValue){
  12738. if(/input/ig.test(attrValue.tagName)){
  12739. opt[attrName] = attrValue.value;
  12740. }else{
  12741. var iptChilds = attrValue.getElementsByTagName("input");
  12742. for(var j=iptChilds.length-1,iptchild;iptchild=iptChilds[j--];){
  12743. if(iptchild.checked){
  12744. opt[attrName] = iptchild.value;
  12745. break;
  12746. }
  12747. }
  12748. }
  12749. }else{
  12750. opt[attrName] = true;
  12751. }
  12752. }
  12753. }
  12754. }
  12755. var selects = domUtils.getElementsByTagName(cont,"select");
  12756. for(var i=0,si;si=selects[i++];){
  12757. var attr = si.getAttribute('name');
  12758. opt[attr] = opt[attr] ? si.value : '';
  12759. }
  12760. me.editor.options.autotypeset = opt;
  12761. }
  12762. AutoTypeSetButton.prototype = {
  12763. initAutoTypeSetButton: function (){
  12764. var me = this;
  12765. this.popup = new Popup({
  12766. //传入配置参数
  12767. content: new AutoTypeSetPicker({editor:me.editor}),
  12768. 'editor':me.editor,
  12769. hide : function(){
  12770. if (!this._hidden && this.getDom()) {
  12771. getPara(this);
  12772. this.getDom().style.display = 'none';
  12773. this._hidden = true;
  12774. this.fireEvent('hide');
  12775. }
  12776. }
  12777. });
  12778. var flag = 0;
  12779. this.popup.addListener('postRenderAfter',function(){
  12780. var popupUI = this;
  12781. if(flag)return;
  12782. var cont = this.getDom(),
  12783. btn = cont.getElementsByTagName('button')[0];
  12784. btn.onclick = function(){
  12785. getPara(popupUI);
  12786. me.editor.execCommand('autotypeset')
  12787. };
  12788. flag = 1;
  12789. });
  12790. this.initSplitButton();
  12791. }
  12792. };
  12793. utils.inherits(AutoTypeSetButton, SplitButton);
  12794. })();
  12795. (function (){
  12796. var utils = baidu.editor.utils,
  12797. uiUtils = baidu.editor.ui.uiUtils,
  12798. UIBase = baidu.editor.ui.UIBase,
  12799. Toolbar = baidu.editor.ui.Toolbar = function (options){
  12800. this.initOptions(options);
  12801. this.initToolbar();
  12802. };
  12803. Toolbar.prototype = {
  12804. items: null,
  12805. initToolbar: function (){
  12806. this.items = this.items || [];
  12807. this.initUIBase();
  12808. },
  12809. add: function (item){
  12810. this.items.push(item);
  12811. },
  12812. getHtmlTpl: function (){
  12813. var buff = [];
  12814. for (var i=0; i<this.items.length; i++) {
  12815. buff[i] = this.items[i].renderHtml();
  12816. }
  12817. return '<div id="##" class="edui-toolbar %%" onselectstart="return false;" onmousedown="return $$._onMouseDown(event, this);">' +
  12818. buff.join('') +
  12819. '</div>'
  12820. },
  12821. postRender: function (){
  12822. var box = this.getDom();
  12823. for (var i=0; i<this.items.length; i++) {
  12824. this.items[i].postRender();
  12825. }
  12826. uiUtils.makeUnselectable(box);
  12827. },
  12828. _onMouseDown: function (){
  12829. return false;
  12830. }
  12831. };
  12832. utils.inherits(Toolbar, UIBase);
  12833. })();
  12834. ///import core
  12835. ///import uicore
  12836. ///import ui\popup.js
  12837. ///import ui\stateful.js
  12838. (function (){
  12839. var utils = baidu.editor.utils,
  12840. domUtils = baidu.editor.dom.domUtils,
  12841. uiUtils = baidu.editor.ui.uiUtils,
  12842. UIBase = baidu.editor.ui.UIBase,
  12843. Popup = baidu.editor.ui.Popup,
  12844. Stateful = baidu.editor.ui.Stateful,
  12845. Menu = baidu.editor.ui.Menu = function (options){
  12846. this.initOptions(options);
  12847. this.initMenu();
  12848. };
  12849. var menuSeparator = {
  12850. renderHtml: function (){
  12851. return '<div class="edui-menuitem edui-menuseparator"><div class="edui-menuseparator-inner"></div></div>';
  12852. },
  12853. postRender: function (){},
  12854. queryAutoHide: function (){ return true; }
  12855. };
  12856. Menu.prototype = {
  12857. items: null,
  12858. uiName: 'menu',
  12859. initMenu: function (){
  12860. this.items = this.items || [];
  12861. this.initPopup();
  12862. this.initItems();
  12863. },
  12864. initItems: function (){
  12865. for (var i=0; i<this.items.length; i++) {
  12866. var item = this.items[i];
  12867. if (item == '-') {
  12868. this.items[i] = this.getSeparator();
  12869. } else if (!(item instanceof MenuItem)) {
  12870. this.items[i] = this.createItem(item);
  12871. }
  12872. }
  12873. },
  12874. getSeparator: function (){
  12875. return menuSeparator;
  12876. },
  12877. createItem: function (item){
  12878. return new MenuItem(item);
  12879. },
  12880. _Popup_getContentHtmlTpl: Popup.prototype.getContentHtmlTpl,
  12881. getContentHtmlTpl: function (){
  12882. if (this.items.length == 0) {
  12883. return this._Popup_getContentHtmlTpl();
  12884. }
  12885. var buff = [];
  12886. for (var i=0; i<this.items.length; i++) {
  12887. var item = this.items[i];
  12888. buff[i] = item.renderHtml();
  12889. }
  12890. return ('<div class="%%-body">' + buff.join('') + '</div>');
  12891. },
  12892. _Popup_postRender: Popup.prototype.postRender,
  12893. postRender: function (){
  12894. var me = this;
  12895. for (var i=0; i<this.items.length; i++) {
  12896. var item = this.items[i];
  12897. item.ownerMenu = this;
  12898. item.postRender();
  12899. }
  12900. domUtils.on(this.getDom(), 'mouseover', function (evt){
  12901. evt = evt || event;
  12902. var rel = evt.relatedTarget || evt.fromElement;
  12903. var el = me.getDom();
  12904. if (!uiUtils.contains(el, rel) && el !== rel) {
  12905. me.fireEvent('over');
  12906. }
  12907. });
  12908. this._Popup_postRender();
  12909. },
  12910. queryAutoHide: function (el){
  12911. if (el) {
  12912. if (uiUtils.contains(this.getDom(), el)) {
  12913. return false;
  12914. }
  12915. for (var i=0; i<this.items.length; i++) {
  12916. var item = this.items[i];
  12917. if (item.queryAutoHide(el) === false) {
  12918. return false;
  12919. }
  12920. }
  12921. }
  12922. },
  12923. clearItems: function (){
  12924. for (var i=0; i<this.items.length; i++) {
  12925. var item = this.items[i];
  12926. clearTimeout(item._showingTimer);
  12927. clearTimeout(item._closingTimer);
  12928. if (item.subMenu) {
  12929. item.subMenu.destroy();
  12930. }
  12931. }
  12932. this.items = [];
  12933. },
  12934. destroy: function (){
  12935. if (this.getDom()) {
  12936. domUtils.remove(this.getDom());
  12937. }
  12938. this.clearItems();
  12939. },
  12940. dispose: function (){
  12941. this.destroy();
  12942. }
  12943. };
  12944. utils.inherits(Menu, Popup);
  12945. var MenuItem = baidu.editor.ui.MenuItem = function (options){
  12946. this.initOptions(options);
  12947. this.initUIBase();
  12948. this.Stateful_init();
  12949. if (this.subMenu && !(this.subMenu instanceof Menu)) {
  12950. this.subMenu = new Menu(this.subMenu);
  12951. }
  12952. };
  12953. MenuItem.prototype = {
  12954. label: '',
  12955. subMenu: null,
  12956. ownerMenu: null,
  12957. uiName: 'menuitem',
  12958. alwalysHoverable: true,
  12959. getHtmlTpl: function (){
  12960. return '<div id="##" class="%%" stateful onclick="$$._onClick(event, this);">' +
  12961. '<div class="%%-body">' +
  12962. this.renderLabelHtml() +
  12963. '</div>' +
  12964. '</div>';
  12965. },
  12966. postRender: function (){
  12967. var me = this;
  12968. this.addListener('over', function (){
  12969. me.ownerMenu.fireEvent('submenuover', me);
  12970. if (me.subMenu) {
  12971. me.delayShowSubMenu();
  12972. }
  12973. });
  12974. if (this.subMenu) {
  12975. this.getDom().className += ' edui-hassubmenu';
  12976. this.subMenu.render();
  12977. this.addListener('out', function (){
  12978. me.delayHideSubMenu();
  12979. });
  12980. this.subMenu.addListener('over', function (){
  12981. clearTimeout(me._closingTimer);
  12982. me._closingTimer = null;
  12983. me.addState('opened');
  12984. });
  12985. this.ownerMenu.addListener('hide', function (){
  12986. me.hideSubMenu();
  12987. });
  12988. this.ownerMenu.addListener('submenuover', function (t, subMenu){
  12989. if (subMenu !== me) {
  12990. me.delayHideSubMenu();
  12991. }
  12992. });
  12993. this.subMenu._bakQueryAutoHide = this.subMenu.queryAutoHide;
  12994. this.subMenu.queryAutoHide = function (el){
  12995. if (el && uiUtils.contains(me.getDom(), el)) {
  12996. return false;
  12997. }
  12998. return this._bakQueryAutoHide(el);
  12999. };
  13000. }
  13001. this.getDom().style.tabIndex = '-1';
  13002. uiUtils.makeUnselectable(this.getDom());
  13003. this.Stateful_postRender();
  13004. },
  13005. delayShowSubMenu: function (){
  13006. var me = this;
  13007. if (!me.isDisabled()) {
  13008. me.addState('opened');
  13009. clearTimeout(me._showingTimer);
  13010. clearTimeout(me._closingTimer);
  13011. me._closingTimer = null;
  13012. me._showingTimer = setTimeout(function (){
  13013. me.showSubMenu();
  13014. }, 250);
  13015. }
  13016. },
  13017. delayHideSubMenu: function (){
  13018. var me = this;
  13019. if (!me.isDisabled()) {
  13020. me.removeState('opened');
  13021. clearTimeout(me._showingTimer);
  13022. if (!me._closingTimer) {
  13023. me._closingTimer = setTimeout(function (){
  13024. if (!me.hasState('opened')) {
  13025. me.hideSubMenu();
  13026. }
  13027. me._closingTimer = null;
  13028. }, 400);
  13029. }
  13030. }
  13031. },
  13032. renderLabelHtml: function (){
  13033. return '<div class="edui-arrow"></div>' +
  13034. '<div class="edui-box edui-icon"></div>' +
  13035. '<div class="edui-box edui-label %%-label">' + (this.label || '') + '</div>';
  13036. },
  13037. getStateDom: function (){
  13038. return this.getDom();
  13039. },
  13040. queryAutoHide: function (el){
  13041. if (this.subMenu && this.hasState('opened')) {
  13042. return this.subMenu.queryAutoHide(el);
  13043. }
  13044. },
  13045. _onClick: function (event, this_){
  13046. if (this.hasState('disabled')) return;
  13047. if (this.fireEvent('click', event, this_) !== false) {
  13048. if (this.subMenu) {
  13049. this.showSubMenu();
  13050. } else {
  13051. Popup.postHide();
  13052. }
  13053. }
  13054. },
  13055. showSubMenu: function (){
  13056. var rect = uiUtils.getClientRect(this.getDom());
  13057. rect.right -= 5;
  13058. rect.left += 2;
  13059. rect.width -= 7;
  13060. rect.top -= 4;
  13061. rect.bottom += 4;
  13062. rect.height += 8;
  13063. this.subMenu.showAnchorRect(rect, true, true);
  13064. },
  13065. hideSubMenu: function (){
  13066. this.subMenu.hide();
  13067. }
  13068. };
  13069. utils.inherits(MenuItem, UIBase);
  13070. utils.extend(MenuItem.prototype, Stateful, true);
  13071. })();
  13072. ///import core
  13073. ///import uicore
  13074. ///import ui/menu.js
  13075. ///import ui/splitbutton.js
  13076. (function (){
  13077. // todo: menu和item提成通用list
  13078. var utils = baidu.editor.utils,
  13079. uiUtils = baidu.editor.ui.uiUtils,
  13080. Menu = baidu.editor.ui.Menu,
  13081. SplitButton = baidu.editor.ui.SplitButton,
  13082. Combox = baidu.editor.ui.Combox = function (options){
  13083. this.initOptions(options);
  13084. this.initCombox();
  13085. };
  13086. Combox.prototype = {
  13087. uiName: 'combox',
  13088. initCombox: function (){
  13089. var me = this;
  13090. this.items = this.items || [];
  13091. for (var i=0; i<this.items.length; i++) {
  13092. var item = this.items[i];
  13093. item.uiName = 'listitem';
  13094. item.index = i;
  13095. item.onclick = function (){
  13096. me.selectByIndex(this.index);
  13097. };
  13098. }
  13099. this.popup = new Menu({
  13100. items: this.items,
  13101. uiName: 'list',
  13102. editor:this.editor
  13103. });
  13104. this.initSplitButton();
  13105. },
  13106. _SplitButton_postRender: SplitButton.prototype.postRender,
  13107. postRender: function (){
  13108. this._SplitButton_postRender();
  13109. this.setLabel(this.label || '');
  13110. this.setValue(this.initValue || '');
  13111. },
  13112. showPopup: function (){
  13113. var rect = uiUtils.getClientRect(this.getDom());
  13114. rect.top += 1;
  13115. rect.bottom -= 1;
  13116. rect.height -= 2;
  13117. this.popup.showAnchorRect(rect);
  13118. },
  13119. getValue: function (){
  13120. return this.value;
  13121. },
  13122. setValue: function (value){
  13123. var index = this.indexByValue(value);
  13124. if (index != -1) {
  13125. this.selectedIndex = index;
  13126. this.setLabel(this.items[index].label);
  13127. this.value = this.items[index].value;
  13128. } else {
  13129. this.selectedIndex = -1;
  13130. this.setLabel(this.getLabelForUnknowValue(value));
  13131. this.value = value;
  13132. }
  13133. },
  13134. setLabel: function (label){
  13135. this.getDom('button_body').innerHTML = label;
  13136. this.label = label;
  13137. },
  13138. getLabelForUnknowValue: function (value){
  13139. return value;
  13140. },
  13141. indexByValue: function (value){
  13142. for (var i=0; i<this.items.length; i++) {
  13143. if (value == this.items[i].value) {
  13144. return i;
  13145. }
  13146. }
  13147. return -1;
  13148. },
  13149. getItem: function (index){
  13150. return this.items[index];
  13151. },
  13152. selectByIndex: function (index){
  13153. if (index < this.items.length && this.fireEvent('select', index) !== false) {
  13154. this.selectedIndex = index;
  13155. this.value = this.items[index].value;
  13156. this.setLabel(this.items[index].label);
  13157. }
  13158. }
  13159. };
  13160. utils.inherits(Combox, SplitButton);
  13161. })();
  13162. ///import core
  13163. ///import uicore
  13164. ///import ui/mask.js
  13165. ///import ui/button.js
  13166. (function (){
  13167. var utils = baidu.editor.utils,
  13168. domUtils = baidu.editor.dom.domUtils,
  13169. uiUtils = baidu.editor.ui.uiUtils,
  13170. Mask = baidu.editor.ui.Mask,
  13171. UIBase = baidu.editor.ui.UIBase,
  13172. Button = baidu.editor.ui.Button,
  13173. Dialog = baidu.editor.ui.Dialog = function (options){
  13174. this.initOptions(utils.extend({
  13175. autoReset: true,
  13176. draggable: true,
  13177. onok: function (){},
  13178. oncancel: function (){},
  13179. onclose: function (t, ok){
  13180. return ok ? this.onok() : this.oncancel();
  13181. }
  13182. },options));
  13183. this.initDialog();
  13184. };
  13185. var modalMask;
  13186. var dragMask;
  13187. Dialog.prototype = {
  13188. draggable: false,
  13189. uiName: 'dialog',
  13190. initDialog: function (){
  13191. var me = this;
  13192. this.initUIBase();
  13193. this.modalMask = (modalMask || (modalMask = new Mask({
  13194. className: 'edui-dialog-modalmask'
  13195. })));
  13196. this.dragMask = (dragMask || (dragMask = new Mask({
  13197. className: 'edui-dialog-dragmask'
  13198. })));
  13199. this.closeButton = new Button({
  13200. className: 'edui-dialog-closebutton',
  13201. title: '关闭对话框',
  13202. onclick: function (){
  13203. me.close(false);
  13204. }
  13205. });
  13206. if (this.buttons) {
  13207. for (var i=0; i<this.buttons.length; i++) {
  13208. if (!(this.buttons[i] instanceof Button)) {
  13209. this.buttons[i] = new Button(this.buttons[i]);
  13210. }
  13211. }
  13212. }
  13213. },
  13214. fitSize: function (){
  13215. var popBodyEl = this.getDom('body');
  13216. // if (!(baidu.editor.browser.ie && baidu.editor.browser.version == 7)) {
  13217. // uiUtils.removeStyle(popBodyEl, 'width');
  13218. // uiUtils.removeStyle(popBodyEl, 'height');
  13219. // }
  13220. var size = this.mesureSize();
  13221. popBodyEl.style.width = size.width + 'px';
  13222. popBodyEl.style.height = size.height + 'px';
  13223. return size;
  13224. },
  13225. safeSetOffset: function (offset){
  13226. var me = this;
  13227. var el = me.getDom();
  13228. var vpRect = uiUtils.getViewportRect();
  13229. var rect = uiUtils.getClientRect(el);
  13230. var left = offset.left;
  13231. if (left + rect.width > vpRect.right) {
  13232. left = vpRect.right - rect.width;
  13233. }
  13234. var top = offset.top;
  13235. if (top + rect.height > vpRect.bottom) {
  13236. top = vpRect.bottom - rect.height;
  13237. }
  13238. el.style.left = Math.max(left, 0) + 'px';
  13239. el.style.top = Math.max(top, 0) + 'px';
  13240. },
  13241. showAtCenter: function (){
  13242. this.getDom().style.display = '';
  13243. var vpRect = uiUtils.getViewportRect();
  13244. var popSize = this.fitSize();
  13245. var titleHeight = this.getDom('titlebar').offsetHeight | 0;
  13246. var left = vpRect.width / 2 - popSize.width / 2;
  13247. var top = vpRect.height / 2 - (popSize.height - titleHeight) / 2 - titleHeight;
  13248. var popEl = this.getDom();
  13249. this.safeSetOffset({
  13250. left: Math.max(left | 0, 0),
  13251. top: Math.max(top | 0, 0)
  13252. });
  13253. if (!domUtils.hasClass(popEl, 'edui-state-centered')) {
  13254. popEl.className += ' edui-state-centered';
  13255. }
  13256. this._show();
  13257. },
  13258. getContentHtml: function (){
  13259. var contentHtml = '';
  13260. if (typeof this.content == 'string') {
  13261. contentHtml = this.content;
  13262. } else if (this.iframeUrl) {
  13263. contentHtml = '<span id="'+ this.id +'_contmask" class="dialogcontmask"></span><iframe id="'+ this.id +
  13264. '_iframe" class="%%-iframe" height="100%" width="100%" frameborder="0" src="'+ this.iframeUrl +'"></iframe>';
  13265. }
  13266. return contentHtml;
  13267. },
  13268. getHtmlTpl: function (){
  13269. var footHtml = '';
  13270. if (this.buttons) {
  13271. var buff = [];
  13272. for (var i=0; i<this.buttons.length; i++) {
  13273. buff[i] = this.buttons[i].renderHtml();
  13274. }
  13275. footHtml = '<div class="%%-foot">' +
  13276. '<div id="##_buttons" class="%%-buttons">' + buff.join('') + '</div>' +
  13277. '</div>';
  13278. }
  13279. return '<div id="##" class="%%"><div class="%%-wrap"><div id="##_body" class="%%-body">' +
  13280. '<div class="%%-shadow"></div>' +
  13281. '<div id="##_titlebar" class="%%-titlebar">' +
  13282. '<div class="%%-draghandle" onmousedown="$$._onTitlebarMouseDown(event, this);">' +
  13283. '<span class="%%-caption">' + (this.title || '') + '</span>' +
  13284. '</div>' +
  13285. this.closeButton.renderHtml() +
  13286. '</div>' +
  13287. '<div id="##_content" class="%%-content">'+ ( this.autoReset ? '' : this.getContentHtml()) +'</div>' +
  13288. footHtml +
  13289. '</div></div></div>';
  13290. },
  13291. postRender: function (){
  13292. // todo: 保持居中/记住上次关闭位置选项
  13293. if (!this.modalMask.getDom()) {
  13294. this.modalMask.render();
  13295. this.modalMask.hide();
  13296. }
  13297. if (!this.dragMask.getDom()) {
  13298. this.dragMask.render();
  13299. this.dragMask.hide();
  13300. }
  13301. var me = this;
  13302. this.addListener('show', function (){
  13303. me.modalMask.show(this.getDom().style.zIndex - 2);
  13304. });
  13305. this.addListener('hide', function (){
  13306. me.modalMask.hide();
  13307. });
  13308. if (this.buttons) {
  13309. for (var i=0; i<this.buttons.length; i++) {
  13310. this.buttons[i].postRender();
  13311. }
  13312. }
  13313. domUtils.on(window, 'resize', function (){
  13314. setTimeout(function (){
  13315. if (!me.isHidden()) {
  13316. me.safeSetOffset(uiUtils.getClientRect(me.getDom()));
  13317. }
  13318. });
  13319. });
  13320. this._hide();
  13321. },
  13322. mesureSize: function (){
  13323. var body = this.getDom('body');
  13324. var width = uiUtils.getClientRect(this.getDom('content')).width;
  13325. var dialogBodyStyle = body.style;
  13326. dialogBodyStyle.width = width;
  13327. return uiUtils.getClientRect(body);
  13328. },
  13329. _onTitlebarMouseDown: function (evt, el){
  13330. if (this.draggable) {
  13331. var rect;
  13332. var vpRect = uiUtils.getViewportRect();
  13333. var me = this;
  13334. uiUtils.startDrag(evt, {
  13335. ondragstart: function (){
  13336. rect = uiUtils.getClientRect(me.getDom());
  13337. me.getDom('contmask').style.visibility = 'visible';
  13338. me.dragMask.show(me.getDom().style.zIndex - 1);
  13339. },
  13340. ondragmove: function (x, y){
  13341. var left = rect.left + x;
  13342. var top = rect.top + y;
  13343. me.safeSetOffset({
  13344. left: left,
  13345. top: top
  13346. });
  13347. },
  13348. ondragstop: function (){
  13349. me.getDom('contmask').style.visibility = 'hidden';
  13350. domUtils.removeClasses(me.getDom(), ['edui-state-centered']);
  13351. me.dragMask.hide();
  13352. }
  13353. });
  13354. }
  13355. },
  13356. reset: function (){
  13357. this.getDom('content').innerHTML = this.getContentHtml();
  13358. },
  13359. _show: function (){
  13360. if (this._hidden) {
  13361. this.getDom().style.display = '';
  13362. //要高过编辑器的zindxe
  13363. this.editor.container.style.zIndex && (this.getDom().style.zIndex = this.editor.container.style.zIndex * 1 + 10);
  13364. this._hidden = false;
  13365. this.fireEvent('show');
  13366. baidu.editor.ui.uiUtils.getFixedLayer().style.zIndex = this.getDom().style.zIndex - 4;
  13367. }
  13368. },
  13369. isHidden: function (){
  13370. return this._hidden;
  13371. },
  13372. _hide: function (){
  13373. if (!this._hidden) {
  13374. this.getDom().style.display = 'none';
  13375. this.getDom().style.zIndex = '';
  13376. this._hidden = true;
  13377. this.fireEvent('hide');
  13378. }
  13379. },
  13380. open: function (){
  13381. if (this.autoReset) {
  13382. //有可能还没有渲染
  13383. try{
  13384. this.reset();
  13385. }catch(e){
  13386. this.render();
  13387. this.open()
  13388. }
  13389. }
  13390. this.showAtCenter();
  13391. if (this.iframeUrl) {
  13392. try {
  13393. this.getDom('iframe').focus();
  13394. } catch(ex){}
  13395. }
  13396. },
  13397. _onCloseButtonClick: function (evt, el){
  13398. this.close(false);
  13399. },
  13400. close: function (ok){
  13401. if (this.fireEvent('close', ok) !== false) {
  13402. this._hide();
  13403. }
  13404. }
  13405. };
  13406. utils.inherits(Dialog, UIBase);
  13407. })();
  13408. ///import core
  13409. ///import uicore
  13410. ///import ui/menu.js
  13411. ///import ui/splitbutton.js
  13412. (function (){
  13413. var utils = baidu.editor.utils,
  13414. Menu = baidu.editor.ui.Menu,
  13415. SplitButton = baidu.editor.ui.SplitButton,
  13416. MenuButton = baidu.editor.ui.MenuButton = function (options){
  13417. this.initOptions(options);
  13418. this.initMenuButton();
  13419. };
  13420. MenuButton.prototype = {
  13421. initMenuButton: function (){
  13422. var me = this;
  13423. this.uiName = "menubutton";
  13424. this.popup = new Menu({
  13425. items: me.items,
  13426. className: me.className,
  13427. editor:me.editor
  13428. });
  13429. this.popup.addListener('show', function (){
  13430. var list = this;
  13431. for (var i=0; i<list.items.length; i++) {
  13432. list.items[i].removeState('checked');
  13433. if (list.items[i].value == me._value) {
  13434. list.items[i].addState('checked');
  13435. this.value = me._value;
  13436. }
  13437. }
  13438. });
  13439. this.initSplitButton();
  13440. },
  13441. setValue : function(value){
  13442. this._value = value;
  13443. }
  13444. };
  13445. utils.inherits(MenuButton, SplitButton);
  13446. })();
  13447. //ui跟编辑器的适配層
  13448. //那个按钮弹出是dialog,是下拉筐等都是在这个js中配置
  13449. //自己写的ui也要在这里配置,放到baidu.editor.ui下边,当编辑器实例化的时候会根据editor_config中的toolbars找到相应的进行实例化
  13450. (function (){
  13451. var utils = baidu.editor.utils;
  13452. var editorui = baidu.editor.ui;
  13453. var _Dialog = editorui.Dialog;
  13454. editorui.Dialog = function (options){
  13455. var dialog = new _Dialog(options);
  13456. dialog.addListener('hide', function (){
  13457. if (dialog.editor) {
  13458. var editor = dialog.editor;
  13459. try {
  13460. editor.focus()
  13461. } catch(ex){}
  13462. }
  13463. });
  13464. return dialog;
  13465. };
  13466. var iframeUrlMap ={
  13467. 'anchor':'~/dialogs/anchor/anchor.html',
  13468. 'insertimage':'~/dialogs/image/image.html',
  13469. 'inserttable':'~/dialogs/table/table.html',
  13470. 'link':'~/dialogs/link/link.html',
  13471. 'spechars':'~/dialogs/spechars/spechars.html',
  13472. 'searchreplace':'~/dialogs/searchreplace/searchreplace.html',
  13473. 'map':'~/dialogs/map/map.html',
  13474. 'gmap':'~/dialogs/gmap/gmap.html',
  13475. 'insertvideo':'~/dialogs/video/video.html',
  13476. 'help':'~/dialogs/help/help.html',
  13477. 'highlightcode':'~/dialogs/code/code.html',
  13478. 'emotion':'~/dialogs/emotion/emotion.html',
  13479. 'wordimage':'~/dialogs/wordimage/wordimage.html',
  13480. 'attachment':'~/dialogs/attachment/attachment.html',
  13481. 'insertframe':'~/dialogs/insertframe/insertframe.html',
  13482. 'edittd':'~/dialogs/table/edittd.html',
  13483. 'webapp':'~/dialogs/webapp/webapp.html',
  13484. 'snapscreen': '~/dialogs/snapscreen/snapscreen.html'
  13485. };
  13486. //为工具栏添加按钮,以下都是统一的按钮触发命令,所以写在一起
  13487. var btnCmds = ['undo', 'redo','formatmatch',
  13488. 'bold', 'italic', 'underline',
  13489. 'strikethrough', 'subscript', 'superscript','source','indent','outdent',
  13490. 'blockquote','pasteplain','pagebreak',
  13491. 'selectall', 'print', 'preview', 'horizontal', 'removeformat','time','date','unlink',
  13492. 'insertparagraphbeforetable','insertrow','insertcol','mergeright','mergedown','deleterow',
  13493. 'deletecol','splittorows','splittocols','splittocells','mergecells','deletetable'];
  13494. for(var i=0,ci;ci=btnCmds[i++];){
  13495. ci = ci.toLowerCase();
  13496. editorui[ci] = function (cmd){
  13497. return function (editor, title){
  13498. var ui = new editorui.Button({
  13499. className: 'edui-for-' + cmd,
  13500. title: title || editor.options.labelMap[cmd] || '',
  13501. onclick: function (){
  13502. editor.execCommand(cmd);
  13503. },
  13504. showText: false
  13505. });
  13506. editor.addListener('selectionchange', function (type, causeByUi, uiReady){
  13507. var state = editor.queryCommandState(cmd);
  13508. if (state == -1) {
  13509. ui.setDisabled(true);
  13510. ui.setChecked(false);
  13511. } else {
  13512. if(!uiReady){
  13513. ui.setDisabled(false);
  13514. ui.setChecked(state);
  13515. }
  13516. }
  13517. });
  13518. return ui;
  13519. };
  13520. }(ci);
  13521. }
  13522. //清除文档
  13523. editorui.cleardoc = function(editor, title){
  13524. var ui = new editorui.Button({
  13525. className: 'edui-for-cleardoc',
  13526. title: title || editor.options.labelMap.cleardoc || '',
  13527. onclick: function (){
  13528. if(confirm('确定清空文档吗?')){
  13529. editor.execCommand('cleardoc');
  13530. }
  13531. }
  13532. });
  13533. editor.addListener('selectionchange',function(){
  13534. ui.setDisabled(editor.queryCommandState('cleardoc') == -1);
  13535. });
  13536. return ui;
  13537. };
  13538. //排版,图片排版,文字方向
  13539. var typeset = {
  13540. 'justify' : ['left','right','center','justify'],
  13541. 'imagefloat' : ['none','left','center','right'],
  13542. 'directionality' : ['ltr','rtl']
  13543. };
  13544. for(var p in typeset){
  13545. (function(cmd,val){
  13546. for(var i=0,ci;ci=val[i++];){
  13547. (function(cmd2){
  13548. editorui[cmd.replace('float','')+cmd2] = function (editor, title){
  13549. var ui = new editorui.Button({
  13550. className: 'edui-for-'+ cmd.replace('float','') + cmd2,
  13551. title: title || editor.options.labelMap[cmd.replace('float','') + cmd2] || '',
  13552. onclick: function (){
  13553. editor.execCommand(cmd, cmd2);
  13554. }
  13555. });
  13556. editor.addListener('selectionchange', function (type, causeByUi, uiReady){
  13557. ui.setDisabled(editor.queryCommandState(cmd) == -1);
  13558. ui.setChecked(editor.queryCommandValue(cmd) == cmd2 && !uiReady);
  13559. });
  13560. return ui;
  13561. };
  13562. })(ci)
  13563. }
  13564. })(p,typeset[p])
  13565. }
  13566. //字体颜色和背景颜色
  13567. for(var i=0,ci;ci = ['backcolor', 'forecolor'][i++];){
  13568. editorui[ci] = function (cmd){
  13569. return function (editor, title){
  13570. var ui = new editorui.ColorButton({
  13571. className: 'edui-for-' + cmd,
  13572. color: 'default',
  13573. title: title || editor.options.labelMap[cmd] || '',
  13574. editor:editor,
  13575. onpickcolor: function (t, color){
  13576. editor.execCommand(cmd, color);
  13577. },
  13578. onpicknocolor: function (){
  13579. editor.execCommand(cmd, 'default');
  13580. this.setColor('transparent');
  13581. this.color = 'default';
  13582. },
  13583. onbuttonclick: function (){
  13584. editor.execCommand(cmd, this.color);
  13585. }
  13586. });
  13587. editor.addListener('selectionchange', function (){
  13588. ui.setDisabled(editor.queryCommandState(cmd) == -1);
  13589. });
  13590. return ui;
  13591. };
  13592. }(ci);
  13593. }
  13594. var dialogBtns = {
  13595. noOk : ['searchreplace','help','spechars','webapp'],
  13596. ok : ['attachment','anchor','link', 'insertimage', 'map', 'gmap','insertframe','wordimage',
  13597. 'insertvideo','highlightcode','insertframe','edittd']
  13598. };
  13599. for(var p in dialogBtns){
  13600. (function(type,vals){
  13601. for(var i = 0,ci;ci=vals[i++];){
  13602. (function(cmd){
  13603. editorui[cmd] =function (editor, iframeUrl, title){
  13604. iframeUrl = iframeUrl || (editor.options.iframeUrlMap||{})[cmd] || iframeUrlMap[cmd];
  13605. title = title ||editor.options.labelMap[cmd.toLowerCase()] || '';
  13606. //没有iframeUrl不创建dialog
  13607. var dialog
  13608. if(iframeUrl){
  13609. dialog = new editorui.Dialog( utils.extend({
  13610. iframeUrl: editor.ui.mapUrl(iframeUrl),
  13611. editor: editor,
  13612. className: 'edui-for-' + cmd,
  13613. title: title
  13614. },type == 'ok'?{
  13615. buttons: [{
  13616. className: 'edui-okbutton',
  13617. label: '确认',
  13618. onclick: function (){
  13619. dialog.close(true);
  13620. }
  13621. }, {
  13622. className: 'edui-cancelbutton',
  13623. label: '取消',
  13624. onclick: function (){
  13625. dialog.close(false);
  13626. }
  13627. }]
  13628. }:{}));
  13629. editor.ui._dialogs[cmd+"Dialog"] = dialog;
  13630. }
  13631. var ui = new editorui.Button({
  13632. className: 'edui-for-' + cmd,
  13633. title: title,
  13634. onclick: function (){
  13635. if(dialog){
  13636. if(cmd=="wordimage"){//wordimage需要先判断是否存在word_img属性再确定是否打开
  13637. editor.execCommand("wordimage","word_img");
  13638. if(editor.word_img){
  13639. dialog.render();
  13640. dialog.open();
  13641. }
  13642. }else{
  13643. dialog.render();
  13644. dialog.open();
  13645. }
  13646. }
  13647. }
  13648. });
  13649. editor.addListener('selectionchange', function (){
  13650. //只存在于右键菜单而无工具栏按钮的ui不需要检测状态
  13651. var unNeedCheckState = {'edittd':1,'edittable':1};
  13652. if(cmd in unNeedCheckState)return;
  13653. var state = editor.queryCommandState(cmd);
  13654. ui.setDisabled(state == -1);
  13655. ui.setChecked(state);
  13656. });
  13657. return ui;
  13658. };
  13659. })(ci.toLowerCase())
  13660. }
  13661. })(p,dialogBtns[p])
  13662. }
  13663. editorui.snapscreen = function(editor, iframeUrl, title){
  13664. title = title || editor.options.labelMap['snapscreen'] || '';
  13665. var ui = new editorui.Button({
  13666. className: 'edui-for-snapscreen',
  13667. title: title,
  13668. onclick: function (){
  13669. editor.execCommand("snapscreen");
  13670. }
  13671. });
  13672. if(browser.ie){
  13673. iframeUrl = iframeUrl || (editor.options.iframeUrlMap||{})["snapscreen"] || iframeUrlMap["snapscreen"];
  13674. if(iframeUrl){
  13675. var dialog = new editorui.Dialog({
  13676. iframeUrl: editor.ui.mapUrl(iframeUrl),
  13677. editor: editor,
  13678. className: 'edui-for-snapscreen',
  13679. title: title,
  13680. buttons: [{
  13681. className: 'edui-okbutton',
  13682. label: '确认',
  13683. onclick: function (){
  13684. dialog.close(true);
  13685. }
  13686. }, {
  13687. className: 'edui-cancelbutton',
  13688. label: '取消',
  13689. onclick: function (){
  13690. dialog.close(false);
  13691. }
  13692. }]
  13693. });
  13694. dialog.render();
  13695. editor.ui._dialogs["snapscreenDialog"] = dialog;
  13696. }
  13697. }
  13698. editor.addListener('selectionchange',function(){
  13699. ui.setDisabled( editor.queryCommandState('snapscreen') == -1);
  13700. });
  13701. return ui;
  13702. };
  13703. editorui.fontfamily = function (editor, list, title){
  13704. list = list || editor.options['fontfamily'] || [];
  13705. title = title || editor.options.labelMap['fontfamily'] || '';
  13706. for(var i=0,ci,items=[];ci=list[i++];){
  13707. (function(key,val){
  13708. items.push({
  13709. label: key,
  13710. value: val,
  13711. renderLabelHtml: function (){
  13712. return '<div class="edui-label %%-label" style="font-family:' +
  13713. utils.unhtml(this.value.join(',')) + '">' + (this.label || '') + '</div>';
  13714. }
  13715. });
  13716. })(ci[0],ci[1])
  13717. }
  13718. var ui = new editorui.Combox({
  13719. editor:editor,
  13720. items: items,
  13721. onselect: function (t,index){
  13722. editor.execCommand('FontFamily', this.items[index].value);
  13723. },
  13724. onbuttonclick: function (){
  13725. this.showPopup();
  13726. },
  13727. title: title,
  13728. initValue: title,
  13729. className: 'edui-for-fontfamily',
  13730. indexByValue: function (value){
  13731. if(value){
  13732. for(var i=0,ci;ci=this.items[i];i++){
  13733. if(ci.value.join(',').indexOf(value) != -1)
  13734. return i;
  13735. }
  13736. }
  13737. return -1;
  13738. }
  13739. });
  13740. editor.addListener('selectionchange', function (type, causeByUi, uiReady){
  13741. if(!uiReady){
  13742. var state = editor.queryCommandState('FontFamily');
  13743. if (state == -1) {
  13744. ui.setDisabled(true);
  13745. } else {
  13746. ui.setDisabled(false);
  13747. var value = editor.queryCommandValue('FontFamily');
  13748. //trace:1871 ie下从源码模式切换回来时,字体会带单引号,而且会有逗号
  13749. value && (value = value.replace(/['"]/g,'').split(',')[0]);
  13750. ui.setValue( value);
  13751. }
  13752. }
  13753. });
  13754. return ui;
  13755. };
  13756. editorui.fontsize = function (editor, list, title){
  13757. title = title || editor.options.labelMap['fontsize'] || '';
  13758. list = list || editor.options['fontsize'] || [];
  13759. var items = [];
  13760. for (var i=0; i<list.length; i++) {
  13761. var size = list[i] + 'px';
  13762. items.push({
  13763. label: size,
  13764. value: size,
  13765. renderLabelHtml: function (){
  13766. return '<div class="edui-label %%-label" style="line-height:1;font-size:' +
  13767. this.value + '">' + (this.label || '') + '</div>';
  13768. }
  13769. });
  13770. }
  13771. var ui = new editorui.Combox({
  13772. editor:editor,
  13773. items: items,
  13774. title: title,
  13775. initValue: title,
  13776. onselect: function (t,index){
  13777. editor.execCommand('FontSize', this.items[index].value);
  13778. },
  13779. onbuttonclick: function (){
  13780. this.showPopup();
  13781. },
  13782. className: 'edui-for-fontsize'
  13783. });
  13784. editor.addListener('selectionchange', function (type, causeByUi, uiReady){
  13785. if(!uiReady){
  13786. var state = editor.queryCommandState('FontSize');
  13787. if (state == -1) {
  13788. ui.setDisabled(true);
  13789. } else {
  13790. ui.setDisabled(false);
  13791. ui.setValue(editor.queryCommandValue('FontSize'));
  13792. }
  13793. }
  13794. });
  13795. return ui;
  13796. };
  13797. editorui.paragraph = function (editor, list, title){
  13798. title = title || editor.options.labelMap['paragraph'] || '';
  13799. list = list || editor.options['paragraph'] || [];
  13800. for (var i=0,items = []; i<list.length; i++) {
  13801. var item = list[i].split(':');
  13802. var tag = item[0];
  13803. var label = item[1];
  13804. items.push({
  13805. label: label,
  13806. value: tag,
  13807. renderLabelHtml: function (){
  13808. return '<div class="edui-label %%-label"><span class="edui-for-' + this.value + '">' + (this.label || '') + '</span></div>';
  13809. }
  13810. });
  13811. }
  13812. var ui = new editorui.Combox({
  13813. editor:editor,
  13814. items: items,
  13815. title: title,
  13816. initValue: title,
  13817. className: 'edui-for-paragraph',
  13818. onselect: function (t,index){
  13819. editor.execCommand('Paragraph', this.items[index].value);
  13820. },
  13821. onbuttonclick: function (){
  13822. this.showPopup();
  13823. }
  13824. });
  13825. editor.addListener('selectionchange', function (type, causeByUi, uiReady){
  13826. if(!uiReady){
  13827. var state = editor.queryCommandState('Paragraph');
  13828. if (state == -1) {
  13829. ui.setDisabled(true);
  13830. } else {
  13831. ui.setDisabled(false);
  13832. var value = editor.queryCommandValue('Paragraph');
  13833. var index = ui.indexByValue(value);
  13834. if (index != -1) {
  13835. ui.setValue(value);
  13836. } else {
  13837. ui.setValue(ui.initValue);
  13838. }
  13839. }
  13840. }
  13841. });
  13842. return ui;
  13843. };
  13844. //自定义标题
  13845. editorui.customstyle = function(editor,list,title){
  13846. list = list || editor.options['customstyle'];
  13847. title = title || editor.options.labelMap['customstyle'] || '';
  13848. if(!list)
  13849. return;
  13850. for(var i=0,items = [],t;t=list[i++];){
  13851. (function(ti){
  13852. items.push({
  13853. label: ti.label,
  13854. value: ti,
  13855. renderLabelHtml: function (){
  13856. return '<div class="edui-label %%-label">' +'<'+ ti.tag +' ' + (ti.className?' class="'+ti.className+'"':"")
  13857. + (ti.style ? ' style="' + ti.style+'"':"") + '>' + ti.label+"<\/"+ti.tag+">"
  13858. + '</div>';
  13859. }
  13860. });
  13861. })(t)
  13862. }
  13863. var ui = new editorui.Combox({
  13864. editor:editor,
  13865. items: items,
  13866. title: title,
  13867. initValue:title,
  13868. className: 'edui-for-customstyle',
  13869. onselect: function (t,index){
  13870. editor.execCommand('customstyle', this.items[index].value);
  13871. },
  13872. onbuttonclick: function (){
  13873. this.showPopup();
  13874. },
  13875. indexByValue: function (value){
  13876. for(var i=0,ti;ti=this.items[i++];){
  13877. if(ti.label == value){
  13878. return i-1
  13879. }
  13880. }
  13881. return -1;
  13882. }
  13883. });
  13884. editor.addListener('selectionchange', function (type, causeByUi, uiReady){
  13885. if(!uiReady){
  13886. var state = editor.queryCommandState('customstyle');
  13887. if (state == -1) {
  13888. ui.setDisabled(true);
  13889. } else {
  13890. ui.setDisabled(false);
  13891. var value = editor.queryCommandValue('customstyle');
  13892. var index = ui.indexByValue(value);
  13893. if (index != -1) {
  13894. ui.setValue(value);
  13895. } else {
  13896. ui.setValue(ui.initValue);
  13897. }
  13898. }
  13899. }
  13900. });
  13901. return ui;
  13902. };
  13903. editorui.inserttable = function (editor, iframeUrl, title){
  13904. iframeUrl = iframeUrl || (editor.options.iframeUrlMap||{})['inserttable'] || iframeUrlMap['inserttable'];
  13905. title = title || editor.options.labelMap['inserttable'] || '';
  13906. if(iframeUrl){
  13907. var dialog = new editorui.Dialog({
  13908. iframeUrl: editor.ui.mapUrl(iframeUrl),
  13909. editor: editor,
  13910. className: 'edui-for-inserttable',
  13911. title: title,
  13912. buttons: [{
  13913. className: 'edui-okbutton',
  13914. label: '确认',
  13915. onclick: function (){
  13916. dialog.close(true);
  13917. }
  13918. }, {
  13919. className: 'edui-cancelbutton',
  13920. label: '取消',
  13921. onclick: function (){
  13922. dialog.close(false);
  13923. }
  13924. }]
  13925. });
  13926. dialog.render();
  13927. editor.ui._dialogs['inserttableDialog'] = dialog;
  13928. }
  13929. var ui = new editorui.TableButton({
  13930. editor:editor,
  13931. title: title,
  13932. className: 'edui-for-inserttable',
  13933. onpicktable: function (t,numCols, numRows){
  13934. editor.execCommand('InsertTable', {numRows:numRows, numCols:numCols,border:1});
  13935. },
  13936. onmore: function (){
  13937. dialog && dialog.open();
  13938. },
  13939. onbuttonclick: function (){
  13940. dialog && dialog.open();
  13941. }
  13942. });
  13943. editor.addListener('selectionchange', function (){
  13944. ui.setDisabled(editor.queryCommandState('inserttable') == -1);
  13945. });
  13946. return ui;
  13947. };
  13948. editorui.lineheight = function (editor, title){
  13949. var val = editor.options.lineheight;
  13950. for(var i=0,ci,items=[];ci = val[i++];){
  13951. items.push({
  13952. //todo:写死了
  13953. label : ci == '1' ? '默认' : ci,
  13954. value: ci,
  13955. onclick:function(){
  13956. editor.execCommand("lineheight", this.value);
  13957. }
  13958. })
  13959. }
  13960. var ui = new editorui.MenuButton({
  13961. editor:editor,
  13962. className : 'edui-for-lineheight',
  13963. title : title || editor.options.labelMap['lineheight'] || '',
  13964. items :items,
  13965. onbuttonclick: function (){
  13966. var value = editor.queryCommandValue('LineHeight') || this.value;
  13967. editor.execCommand("LineHeight", value);
  13968. }
  13969. });
  13970. editor.addListener('selectionchange', function (){
  13971. var state = editor.queryCommandState('LineHeight');
  13972. if (state == -1) {
  13973. ui.setDisabled(true);
  13974. } else {
  13975. ui.setDisabled(false);
  13976. var value = editor.queryCommandValue('LineHeight');
  13977. value && ui.setValue((value + '').replace(/cm/,''));
  13978. ui.setChecked(state)
  13979. }
  13980. });
  13981. return ui;
  13982. };
  13983. var rowspacings = ['top','bottom'];
  13984. for(var r=0,ri;ri=rowspacings[r++];){
  13985. (function(cmd){
  13986. editorui['rowspacing' + cmd] = function(editor){
  13987. var val = editor.options['rowspacing'+cmd] ;
  13988. for(var i=0,ci,items=[];ci = val[i++];){
  13989. items.push({
  13990. label : ci,
  13991. value: ci,
  13992. onclick:function(){
  13993. editor.execCommand("rowspacing", this.value,cmd);
  13994. }
  13995. })
  13996. }
  13997. var ui = new editorui.MenuButton({
  13998. editor:editor,
  13999. className : 'edui-for-rowspacing'+cmd,
  14000. title : editor.options.labelMap['rowspacing'+cmd],
  14001. items :items,
  14002. onbuttonclick: function (){
  14003. var value = editor.queryCommandValue('rowspacing',cmd) || this.value;
  14004. editor.execCommand("rowspacing", value,cmd);
  14005. }
  14006. });
  14007. editor.addListener('selectionchange', function (){
  14008. var state = editor.queryCommandState('rowspacing',cmd);
  14009. if (state == -1) {
  14010. ui.setDisabled(true);
  14011. } else {
  14012. ui.setDisabled(false);
  14013. var value = editor.queryCommandValue('rowspacing',cmd);
  14014. value && ui.setValue((value + '').replace(/%/,''));
  14015. ui.setChecked(state)
  14016. }
  14017. });
  14018. return ui;
  14019. }
  14020. })(ri)
  14021. }
  14022. //有序,无序列表
  14023. var lists = ['insertorderedlist','insertunorderedlist'];
  14024. for(var l = 0,cl;cl = lists[l++]; ){
  14025. (function(cmd){
  14026. editorui[cmd] =function (editor){
  14027. var vals = editor.options[cmd],
  14028. _onMenuClick = function(){
  14029. editor.execCommand(cmd, this.value);
  14030. };
  14031. for(var i=0,items=[],ci;ci=vals[i++];){
  14032. items.push({
  14033. label : ci[0],
  14034. value : ci[1],
  14035. onclick : _onMenuClick
  14036. })
  14037. }
  14038. var ui = new editorui.MenuButton({
  14039. editor:editor,
  14040. className : 'edui-for-'+cmd,
  14041. title : editor.options.labelMap[cmd] || '',
  14042. 'items' :items,
  14043. onbuttonclick: function (){
  14044. var value = editor.queryCommandValue(cmd) || this.value;
  14045. editor.execCommand(cmd, value);
  14046. }
  14047. });
  14048. editor.addListener('selectionchange', function (){
  14049. var state = editor.queryCommandState(cmd);
  14050. if (state == -1) {
  14051. ui.setDisabled(true);
  14052. } else {
  14053. ui.setDisabled(false);
  14054. var value = editor.queryCommandValue(cmd);
  14055. ui.setValue(value);
  14056. ui.setChecked(state)
  14057. }
  14058. });
  14059. return ui;
  14060. };
  14061. })(cl)
  14062. }
  14063. editorui.fullscreen = function (editor, title){
  14064. title = title || editor.options.labelMap['fullscreen'] || '';
  14065. var ui = new editorui.Button({
  14066. className: 'edui-for-fullscreen',
  14067. title: title,
  14068. onclick: function (){
  14069. if (editor.ui) {
  14070. editor.ui.setFullScreen(!editor.ui.isFullScreen());
  14071. }
  14072. this.setChecked(editor.ui.isFullScreen());
  14073. }
  14074. });
  14075. editor.addListener('selectionchange', function (){
  14076. var state = editor.queryCommandState('fullscreen');
  14077. ui.setDisabled(state == -1);
  14078. ui.setChecked(editor.ui.isFullScreen());
  14079. });
  14080. return ui;
  14081. };
  14082. // 表情
  14083. editorui.emotion = function(editor, iframeUrl, title){
  14084. var ui = new editorui.MultiMenuPop({
  14085. title: title || editor.options.labelMap.emotion || '',
  14086. editor: editor,
  14087. className: 'edui-for-emotion',
  14088. iframeUrl: editor.ui.mapUrl(iframeUrl || (editor.options.iframeUrlMap||{})['emotion'] || iframeUrlMap['emotion'])
  14089. });
  14090. editor.addListener('selectionchange', function (){
  14091. ui.setDisabled(editor.queryCommandState('emotion') == -1)
  14092. });
  14093. return ui;
  14094. };
  14095. editorui.autotypeset = function (editor){
  14096. var ui = new editorui.AutoTypeSetButton({
  14097. editor:editor,
  14098. title: editor.options.labelMap['autotypeset'] || '',
  14099. className: 'edui-for-autotypeset',
  14100. onbuttonclick: function (){
  14101. editor.execCommand('autotypeset')
  14102. }
  14103. });
  14104. editor.addListener('selectionchange', function (){
  14105. ui.setDisabled(editor.queryCommandState('autotypeset') == -1);
  14106. });
  14107. return ui;
  14108. };
  14109. })();
  14110. ///import core
  14111. ///commands 全屏
  14112. ///commandsName FullScreen
  14113. ///commandsTitle 全屏
  14114. (function () {
  14115. var utils = baidu.editor.utils,
  14116. uiUtils = baidu.editor.ui.uiUtils,
  14117. UIBase = baidu.editor.ui.UIBase,
  14118. domUtils = baidu.editor.dom.domUtils;
  14119. function EditorUI( options ) {
  14120. this.initOptions( options );
  14121. this.initEditorUI();
  14122. }
  14123. EditorUI.prototype = {
  14124. uiName: 'editor',
  14125. initEditorUI: function () {
  14126. this.editor.ui = this;
  14127. this._dialogs = {};
  14128. this.initUIBase();
  14129. this._initToolbars();
  14130. var editor = this.editor,
  14131. me = this;
  14132. editor.addListener( 'ready', function () {
  14133. domUtils.on( editor.window, 'scroll', function () {
  14134. baidu.editor.ui.Popup.postHide();
  14135. } );
  14136. //display bottom-bar label based on config
  14137. if ( editor.options.elementPathEnabled ) {
  14138. editor.ui.getDom( 'elementpath' ).innerHTML = '<div class="edui-editor-breadcrumb">path:</div>';
  14139. }
  14140. if ( editor.options.wordCount ) {
  14141. editor.ui.getDom( 'wordcount' ).innerHTML = '字数统计';
  14142. //为wordcount捕获中文输入法的空格
  14143. editor.addListener('keyup',function(type,evt){
  14144. var keyCode = evt.keyCode || evt.which;
  14145. if(keyCode == 32){
  14146. me._wordCount();
  14147. }
  14148. });
  14149. }
  14150. if(!editor.options.elementPathEnabled && !editor.options.wordCount){
  14151. editor.ui.getDom( 'elementpath' ).style.display="none";
  14152. editor.ui.getDom( 'wordcount' ).style.display="none";
  14153. }
  14154. if(!editor.selection.isFocus())return;
  14155. editor.fireEvent( 'selectionchange', false, true );
  14156. } );
  14157. editor.addListener( 'mousedown', function ( t, evt ) {
  14158. var el = evt.target || evt.srcElement;
  14159. baidu.editor.ui.Popup.postHide( el );
  14160. } );
  14161. editor.addListener( 'contextmenu', function ( t, evt ) {
  14162. baidu.editor.ui.Popup.postHide();
  14163. } );
  14164. editor.addListener( 'selectionchange', function () {
  14165. //if(!editor.selection.isFocus())return;
  14166. if ( editor.options.elementPathEnabled ) {
  14167. me[(editor.queryCommandState('elementpath') == -1 ? 'dis':'en') + 'ableElementPath']()
  14168. }
  14169. if ( editor.options.wordCount ) {
  14170. me[(editor.queryCommandState('wordcount') == -1 ? 'dis':'en') + 'ableWordCount']()
  14171. }
  14172. } );
  14173. var popup = new baidu.editor.ui.Popup( {
  14174. editor:editor,
  14175. content: '',
  14176. className: 'edui-bubble',
  14177. _onEditButtonClick: function () {
  14178. this.hide();
  14179. editor.ui._dialogs.linkDialog.open();
  14180. },
  14181. _onImgEditButtonClick: function (name) {
  14182. this.hide();
  14183. editor.ui._dialogs[name] && editor.ui._dialogs[name].open();
  14184. },
  14185. _onImgSetFloat: function( value ) {
  14186. this.hide();
  14187. editor.execCommand( "imagefloat", value );
  14188. },
  14189. _setIframeAlign: function( value ) {
  14190. var frame = popup.anchorEl;
  14191. var newFrame = frame.cloneNode( true );
  14192. switch ( value ) {
  14193. case -2:
  14194. newFrame.setAttribute( "align", "" );
  14195. break;
  14196. case -1:
  14197. newFrame.setAttribute( "align", "left" );
  14198. break;
  14199. case 1:
  14200. newFrame.setAttribute( "align", "right" );
  14201. break;
  14202. case 2:
  14203. newFrame.setAttribute( "align", "middle" );
  14204. break;
  14205. }
  14206. frame.parentNode.insertBefore( newFrame, frame );
  14207. domUtils.remove( frame );
  14208. popup.anchorEl = newFrame;
  14209. popup.showAnchor( popup.anchorEl );
  14210. },
  14211. _updateIframe: function() {
  14212. editor._iframe = popup.anchorEl;
  14213. editor.ui._dialogs.insertframeDialog.open();
  14214. popup.hide();
  14215. },
  14216. _onRemoveButtonClick: function (cmdName) {
  14217. editor.execCommand( cmdName );
  14218. this.hide();
  14219. },
  14220. queryAutoHide: function ( el ) {
  14221. if ( el && el.ownerDocument == editor.document ) {
  14222. if ( el.tagName.toLowerCase() == 'img' || domUtils.findParentByTagName( el, 'a', true ) ) {
  14223. return el !== popup.anchorEl;
  14224. }
  14225. }
  14226. return baidu.editor.ui.Popup.prototype.queryAutoHide.call( this, el );
  14227. }
  14228. } );
  14229. popup.render();
  14230. if(editor.options.imagePopup){
  14231. editor.addListener( 'mouseover', function( t, evt ) {
  14232. evt = evt || window.event;
  14233. var el = evt.target || evt.srcElement;
  14234. if ( editor.ui._dialogs.insertframeDialog && /iframe/ig.test( el.tagName ) ) {
  14235. var html = popup.formatHtml(
  14236. '<nobr>属性: <span onclick=$$._setIframeAlign(-2) class="edui-clickable">默认</span>&nbsp;&nbsp;<span onclick=$$._setIframeAlign(-1) class="edui-clickable">左对齐</span>&nbsp;&nbsp;<span onclick=$$._setIframeAlign(1) class="edui-clickable">右对齐</span>&nbsp;&nbsp;' +
  14237. '<span onclick=$$._setIframeAlign(2) class="edui-clickable">居中</span>' +
  14238. ' <span onclick="$$._updateIframe( this);" class="edui-clickable">修改</span></nobr>' );
  14239. if ( html ) {
  14240. popup.getDom( 'content' ).innerHTML = html;
  14241. popup.anchorEl = el;
  14242. popup.showAnchor( popup.anchorEl );
  14243. } else {
  14244. popup.hide();
  14245. }
  14246. }
  14247. } );
  14248. editor.addListener( 'selectionchange', function ( t, causeByUi ) {
  14249. if ( !causeByUi ) return;
  14250. var html = '',
  14251. img = editor.selection.getRange().getClosedNode(),
  14252. dialogs = editor.ui._dialogs;
  14253. if ( img && img.tagName == 'IMG' ) {
  14254. var dialogName = 'insertimageDialog';
  14255. if ( img.className.indexOf( "edui-faked-video" ) != -1 ) {
  14256. dialogName = "insertvideoDialog"
  14257. }
  14258. if(img.className.indexOf( "edui-faked-webapp" ) != -1){
  14259. dialogName = "webappDialog"
  14260. }
  14261. if ( img.src.indexOf( "http://api.map.baidu.com" ) != -1 ) {
  14262. dialogName = "mapDialog"
  14263. }
  14264. if ( img.src.indexOf( "http://maps.google.com/maps/api/staticmap" ) != -1 ) {
  14265. dialogName = "gmapDialog"
  14266. }
  14267. if ( img.getAttribute( "anchorname" ) ) {
  14268. dialogName = "anchorDialog";
  14269. html = popup.formatHtml(
  14270. '<nobr>属性: <span onclick=$$._onImgEditButtonClick("anchorDialog") class="edui-clickable">修改</span>&nbsp;&nbsp;' +
  14271. '<span onclick=$$._onRemoveButtonClick(\'anchor\') class="edui-clickable">删除</span></nobr>' );
  14272. }
  14273. if( img.getAttribute("word_img")){
  14274. //todo 放到dialog去做查询
  14275. editor.word_img = [img.getAttribute("word_img")];
  14276. dialogName = "wordimageDialog"
  14277. }
  14278. if(!dialogs[dialogName]){
  14279. return;
  14280. }
  14281. !html && (html = popup.formatHtml(
  14282. '<nobr>属性: <span onclick=$$._onImgSetFloat("none") class="edui-clickable">默认</span>&nbsp;&nbsp;' +
  14283. '<span onclick=$$._onImgSetFloat("left") class="edui-clickable">居左</span>&nbsp;&nbsp;' +
  14284. '<span onclick=$$._onImgSetFloat("right") class="edui-clickable">居右</span>&nbsp;&nbsp;' +
  14285. '<span onclick=$$._onImgSetFloat("center") class="edui-clickable">居中</span>&nbsp;&nbsp;' +
  14286. '<span onclick="$$._onImgEditButtonClick(\''+dialogName+'\');" class="edui-clickable">修改</span></nobr>' ))
  14287. }
  14288. if(editor.ui._dialogs.linkDialog){
  14289. var link = domUtils.findParentByTagName( editor.selection.getStart(), "a", true );
  14290. var url;
  14291. if ( link && (url = (link.getAttribute( 'data_ue_src' ) || link.getAttribute( 'href', 2 ))) ) {
  14292. var txt = url;
  14293. if ( url.length > 30 ) {
  14294. txt = url.substring( 0, 20 ) + "...";
  14295. }
  14296. if ( html ) {
  14297. html += '<div style="height:5px;"></div>'
  14298. }
  14299. html += popup.formatHtml(
  14300. '<nobr>链接: <a target="_blank" href="' + url + '" title="' + url + '" >' + txt + '</a>' +
  14301. ' <span class="edui-clickable" onclick="$$._onEditButtonClick();">修改</span>' +
  14302. ' <span class="edui-clickable" onclick="$$._onRemoveButtonClick(\'unlink\');"> 清除</span></nobr>' );
  14303. popup.showAnchor( link );
  14304. }
  14305. }
  14306. if ( html ) {
  14307. popup.getDom( 'content' ).innerHTML = html;
  14308. popup.anchorEl = img || link;
  14309. popup.showAnchor( popup.anchorEl );
  14310. } else {
  14311. popup.hide();
  14312. }
  14313. } );
  14314. }
  14315. },
  14316. _initToolbars: function () {
  14317. var editor = this.editor;
  14318. var toolbars = this.toolbars || [];
  14319. var toolbarUis = [];
  14320. for ( var i = 0; i < toolbars.length; i++ ) {
  14321. var toolbar = toolbars[i];
  14322. var toolbarUi = new baidu.editor.ui.Toolbar();
  14323. for ( var j = 0; j < toolbar.length; j++ ) {
  14324. var toolbarItem = toolbar[j].toLowerCase();
  14325. var toolbarItemUi = null;
  14326. if ( typeof toolbarItem == 'string' ) {
  14327. if ( toolbarItem == '|' ) {
  14328. toolbarItem = 'Separator';
  14329. }
  14330. if ( baidu.editor.ui[toolbarItem] ) {
  14331. toolbarItemUi = new baidu.editor.ui[toolbarItem]( editor );
  14332. }
  14333. //todo fullscreen这里单独处理一下,放到首行去
  14334. if ( toolbarItem == 'FullScreen' ) {
  14335. if ( toolbarUis && toolbarUis[0] ) {
  14336. toolbarUis[0].items.splice( 0, 0, toolbarItemUi );
  14337. } else {
  14338. toolbarItemUi && toolbarUi.items.splice( 0, 0, toolbarItemUi );
  14339. }
  14340. continue;
  14341. }
  14342. } else {
  14343. toolbarItemUi = toolbarItem;
  14344. }
  14345. if ( toolbarItemUi ) {
  14346. toolbarUi.add( toolbarItemUi );
  14347. }
  14348. }
  14349. toolbarUis[i] = toolbarUi;
  14350. }
  14351. this.toolbars = toolbarUis;
  14352. },
  14353. getHtmlTpl: function () {
  14354. return '<div id="##" class="%%">' +
  14355. '<div id="##_toolbarbox" class="%%-toolbarbox">' +
  14356. (this.toolbars.length ?
  14357. '<div id="##_toolbarboxouter" class="%%-toolbarboxouter"><div class="%%-toolbarboxinner">' +
  14358. this.renderToolbarBoxHtml() +
  14359. '</div></div>':'') +
  14360. '<div id="##_toolbarmsg" class="%%-toolbarmsg" style="display:none;">' +
  14361. '<div id = "##_upload_dialog" class="%%-toolbarmsg-upload" onclick="$$.showWordImageDialog();">点此上传</div>' +
  14362. '<div class="%%-toolbarmsg-close" onclick="$$.hideToolbarMsg();">x</div>' +
  14363. '<div id="##_toolbarmsg_label" class="%%-toolbarmsg-label"></div>' +
  14364. '<div style="height:0;overflow:hidden;clear:both;"></div>' +
  14365. '</div>' +
  14366. '</div>' +
  14367. '<div id="##_iframeholder" class="%%-iframeholder"></div>' +
  14368. //modify wdcount by matao
  14369. '<div id="##_bottombar" class="%%-bottomContainer"><table><tr>' +
  14370. '<td id="##_elementpath" class="%%-bottombar"></td>' +
  14371. '<td id="##_wordcount" class="%%-wordcount"></td>' +
  14372. '</tr></table></div>' +
  14373. '</div>';
  14374. },
  14375. showWordImageDialog:function() {
  14376. this.editor.execCommand( "wordimage", "word_img" );
  14377. this._dialogs['wordimageDialog'].open();
  14378. },
  14379. renderToolbarBoxHtml: function () {
  14380. var buff = [];
  14381. for ( var i = 0; i < this.toolbars.length; i++ ) {
  14382. buff.push( this.toolbars[i].renderHtml() );
  14383. }
  14384. return buff.join( '' );
  14385. },
  14386. setFullScreen: function ( fullscreen ) {
  14387. if ( this._fullscreen != fullscreen ) {
  14388. this._fullscreen = fullscreen;
  14389. this.editor.fireEvent( 'beforefullscreenchange', fullscreen );
  14390. var editor = this.editor;
  14391. if ( baidu.editor.browser.gecko ) {
  14392. var bk = editor.selection.getRange().createBookmark();
  14393. }
  14394. if ( fullscreen ) {
  14395. this._bakHtmlOverflow = document.documentElement.style.overflow;
  14396. this._bakBodyOverflow = document.body.style.overflow;
  14397. this._bakAutoHeight = this.editor.autoHeightEnabled;
  14398. this._bakScrollTop = Math.max( document.documentElement.scrollTop, document.body.scrollTop );
  14399. if ( this._bakAutoHeight ) {
  14400. //当全屏时不能执行自动长高
  14401. editor.autoHeightEnabled = false;
  14402. this.editor.disableAutoHeight();
  14403. }
  14404. document.documentElement.style.overflow = 'hidden';
  14405. document.body.style.overflow = 'hidden';
  14406. this._bakCssText = this.getDom().style.cssText;
  14407. this._bakCssText1 = this.getDom( 'iframeholder' ).style.cssText;
  14408. this._updateFullScreen();
  14409. } else {
  14410. this.getDom().style.cssText = this._bakCssText;
  14411. this.getDom( 'iframeholder' ).style.cssText = this._bakCssText1;
  14412. if ( this._bakAutoHeight ) {
  14413. editor.autoHeightEnabled = true;
  14414. this.editor.enableAutoHeight();
  14415. }
  14416. document.documentElement.style.overflow = this._bakHtmlOverflow;
  14417. document.body.style.overflow = this._bakBodyOverflow;
  14418. window.scrollTo( 0, this._bakScrollTop );
  14419. }
  14420. if ( baidu.editor.browser.gecko ) {
  14421. var input = document.createElement( 'input' );
  14422. document.body.appendChild( input );
  14423. editor.body.contentEditable = false;
  14424. setTimeout( function() {
  14425. input.focus();
  14426. setTimeout( function() {
  14427. editor.body.contentEditable = true;
  14428. editor.selection.getRange().moveToBookmark( bk ).select( true );
  14429. baidu.editor.dom.domUtils.remove( input );
  14430. fullscreen && window.scroll( 0, 0 );
  14431. } )
  14432. } )
  14433. }
  14434. this.editor.fireEvent( 'fullscreenchanged', fullscreen );
  14435. this.triggerLayout();
  14436. }
  14437. },
  14438. _wordCount:function() {
  14439. var wdcount = this.getDom( 'wordcount' );
  14440. if ( !this.editor.options.wordCount ) {
  14441. wdcount.style.display = "none";
  14442. return;
  14443. }
  14444. wdcount.innerHTML = this.editor.queryCommandValue( "wordcount" );
  14445. },
  14446. disableWordCount: function () {
  14447. var w = this.getDom( 'wordcount' );
  14448. w.innerHTML = '';
  14449. w.style.display = 'none';
  14450. this.wordcount = false;
  14451. },
  14452. enableWordCount: function () {
  14453. var w = this.getDom( 'wordcount' );
  14454. w.style.display = '';
  14455. this.wordcount = true;
  14456. this._wordCount();
  14457. },
  14458. _updateFullScreen: function () {
  14459. if ( this._fullscreen ) {
  14460. var vpRect = uiUtils.getViewportRect();
  14461. this.getDom().style.cssText = 'border:0;position:absolute;left:0;top:0;width:' + vpRect.width + 'px;height:' + vpRect.height + 'px;z-index:' + (this.getDom().style.zIndex * 1 + 100);
  14462. uiUtils.setViewportOffset( this.getDom(), { left: 0, top: 0 } );
  14463. this.editor.setHeight( vpRect.height - this.getDom( 'toolbarbox' ).offsetHeight - this.getDom( 'bottombar' ).offsetHeight );
  14464. }
  14465. },
  14466. _updateElementPath: function () {
  14467. var bottom = this.getDom( 'elementpath' ),list;
  14468. if ( this.elementPathEnabled && (list = this.editor.queryCommandValue( 'elementpath' ))) {
  14469. var buff = [];
  14470. for ( var i = 0,ci; ci = list[i]; i++ ) {
  14471. buff[i] = this.formatHtml( '<span unselectable="on" onclick="$$.editor.execCommand(&quot;elementpath&quot;, &quot;' + i + '&quot;);">' + ci + '</span>' );
  14472. }
  14473. bottom.innerHTML = '<div class="edui-editor-breadcrumb" onmousedown="return false;">path: ' + buff.join( ' &gt; ' ) + '</div>';
  14474. } else {
  14475. bottom.style.display = 'none'
  14476. }
  14477. },
  14478. disableElementPath: function () {
  14479. var bottom = this.getDom( 'elementpath' );
  14480. bottom.innerHTML = '';
  14481. bottom.style.display = 'none';
  14482. this.elementPathEnabled = false;
  14483. },
  14484. enableElementPath: function () {
  14485. var bottom = this.getDom( 'elementpath' );
  14486. bottom.style.display = '';
  14487. this.elementPathEnabled = true;
  14488. this._updateElementPath();
  14489. },
  14490. isFullScreen: function () {
  14491. return this._fullscreen;
  14492. },
  14493. postRender: function () {
  14494. UIBase.prototype.postRender.call( this );
  14495. for ( var i = 0; i < this.toolbars.length; i++ ) {
  14496. this.toolbars[i].postRender();
  14497. }
  14498. var me = this;
  14499. var timerId,
  14500. domUtils = baidu.editor.dom.domUtils,
  14501. updateFullScreenTime = function() {
  14502. clearTimeout( timerId );
  14503. timerId = setTimeout( function () {
  14504. me._updateFullScreen();
  14505. } );
  14506. };
  14507. domUtils.on( window, 'resize', updateFullScreenTime );
  14508. me.addListener( 'destroy', function() {
  14509. domUtils.un( window, 'resize', updateFullScreenTime );
  14510. clearTimeout( timerId );
  14511. } )
  14512. },
  14513. showToolbarMsg: function ( msg, flag ) {
  14514. this.getDom( 'toolbarmsg_label' ).innerHTML = msg;
  14515. this.getDom( 'toolbarmsg' ).style.display = '';
  14516. //
  14517. if ( !flag ) {
  14518. var w = this.getDom( 'upload_dialog' );
  14519. w.style.display = 'none';
  14520. }
  14521. },
  14522. hideToolbarMsg: function () {
  14523. this.getDom( 'toolbarmsg' ).style.display = 'none';
  14524. },
  14525. mapUrl: function ( url ) {
  14526. return url ? url.replace( '~/', this.editor.options.UEDITOR_HOME_URL || '' ) : ''
  14527. },
  14528. triggerLayout: function () {
  14529. var dom = this.getDom();
  14530. if ( dom.style.zoom == '1' ) {
  14531. dom.style.zoom = '100%';
  14532. } else {
  14533. dom.style.zoom = '1';
  14534. }
  14535. }
  14536. };
  14537. utils.inherits( EditorUI, baidu.editor.ui.UIBase );
  14538. baidu.editor.ui.Editor = function ( options ) {
  14539. var editor = new baidu.editor.Editor( options );
  14540. editor.options.editor = editor;
  14541. var oldRender = editor.render;
  14542. editor.render = function ( holder ) {
  14543. utils.domReady(function(){
  14544. new EditorUI( editor.options );
  14545. if ( holder ) {
  14546. if ( holder.constructor === String ) {
  14547. holder = document.getElementById( holder );
  14548. }
  14549. holder && holder.getAttribute( 'name' ) && ( editor.options.textarea = holder.getAttribute( 'name' ));
  14550. if ( holder && /script|textarea/ig.test( holder.tagName ) ) {
  14551. var newDiv = document.createElement( 'div' );
  14552. holder.parentNode.insertBefore( newDiv, holder );
  14553. var cont = holder.value || holder.innerHTML;
  14554. editor.options.initialContent = /^[\t\r\n ]*$/.test(cont) ? editor.options.initialContent :
  14555. cont.replace(/>[\n\r\t]+([ ]{4})+/g,'>')
  14556. .replace(/[\n\r\t]+([ ]{4})+</g,'<')
  14557. .replace(/>[\n\r\t]+</g,'><');
  14558. holder.id && (newDiv.id = holder.id);
  14559. holder.className && (newDiv.className = holder.className);
  14560. holder.style.cssText && (newDiv.style.cssText = holder.style.cssText);
  14561. if(/textarea/i.test(holder.tagName)){
  14562. editor.textarea = holder;
  14563. editor.textarea.style.display = 'none'
  14564. }else{
  14565. holder.parentNode.removeChild( holder )
  14566. }
  14567. holder = newDiv;
  14568. holder.innerHTML = '';
  14569. }
  14570. }
  14571. editor.ui.render( holder );
  14572. var iframeholder = editor.ui.getDom( 'iframeholder' );
  14573. //给实例添加一个编辑器的容器引用
  14574. editor.container = editor.ui.getDom();
  14575. editor.container.style.zIndex = editor.options.zIndex;
  14576. oldRender.call( editor, iframeholder );
  14577. })
  14578. };
  14579. return editor;
  14580. };
  14581. })();
  14582. ///import core
  14583. ///import uicore
  14584. ///commands 表情
  14585. (function(){
  14586. var utils = baidu.editor.utils,
  14587. Popup = baidu.editor.ui.Popup,
  14588. SplitButton = baidu.editor.ui.SplitButton,
  14589. MultiMenuPop = baidu.editor.ui.MultiMenuPop = function(options){
  14590. this.initOptions(options);
  14591. this.initMultiMenu();
  14592. };
  14593. MultiMenuPop.prototype = {
  14594. initMultiMenu: function (){
  14595. var me = this;
  14596. this.popup = new Popup({
  14597. content: '',
  14598. editor : me.editor,
  14599. iframe_rendered: false,
  14600. onshow: function (){
  14601. if (!this.iframe_rendered) {
  14602. this.iframe_rendered = true;
  14603. this.getDom('content').innerHTML = '<iframe id="'+me.id+'_iframe" src="'+ me.iframeUrl +'" frameborder="0"></iframe>';
  14604. me.editor.container.style.zIndex && (this.getDom().style.zIndex = me.editor.container.style.zIndex * 1 + 1);
  14605. }
  14606. }
  14607. // canSideUp:false,
  14608. // canSideLeft:false
  14609. });
  14610. this.onbuttonclick = function(){
  14611. this.showPopup();
  14612. };
  14613. this.initSplitButton();
  14614. }
  14615. };
  14616. utils.inherits(MultiMenuPop, SplitButton);
  14617. })();
  14618. })();