ueditor.all.min.js 1004 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317
  1. /*!
  2. * UEditor
  3. * version: ueditor
  4. * build: Wed Dec 26 2018 17:24:52 GMT+0800 (CST)
  5. */
  6. // const { default: axios } = require('axios')
  7. ;(function () {
  8. // editor.js
  9. UEDITOR_CONFIG = window.UEDITOR_CONFIG || {}
  10. var baidu = window.baidu || {}
  11. window.baidu = baidu
  12. window.UE = baidu.editor = window.UE || {}
  13. UE.plugins = {}
  14. UE.commands = {}
  15. UE.instants = {}
  16. UE.I18N = {}
  17. UE._customizeUI = {}
  18. UE.version = '1.4.3'
  19. var dom = (UE.dom = {})
  20. // core/browser.js
  21. /**
  22. * 浏览器判断模块
  23. * @file
  24. * @module UE.browser
  25. * @since 1.2.6.1
  26. */
  27. /**
  28. * 提供浏览器检测的模块
  29. * @unfile
  30. * @module UE.browser
  31. */
  32. var browser = (UE.browser = (function () {
  33. var agent = navigator.userAgent.toLowerCase(),
  34. opera = window.opera,
  35. browser = {
  36. /**
  37. * @property {boolean} ie 检测当前浏览器是否为IE
  38. * @example
  39. * ```javascript
  40. * if ( UE.browser.ie ) {
  41. * console.log( '当前浏览器是IE' );
  42. * }
  43. * ```
  44. */
  45. ie: /(msie\s|trident.*rv:)([\w.]+)/.test(agent),
  46. /**
  47. * @property {boolean} opera 检测当前浏览器是否为Opera
  48. * @example
  49. * ```javascript
  50. * if ( UE.browser.opera ) {
  51. * console.log( '当前浏览器是Opera' );
  52. * }
  53. * ```
  54. */
  55. opera: !!opera && opera.version,
  56. /**
  57. * @property {boolean} webkit 检测当前浏览器是否是webkit内核的浏览器
  58. * @example
  59. * ```javascript
  60. * if ( UE.browser.webkit ) {
  61. * console.log( '当前浏览器是webkit内核浏览器' );
  62. * }
  63. * ```
  64. */
  65. webkit: agent.indexOf(' applewebkit/') > -1,
  66. /**
  67. * @property {boolean} mac 检测当前浏览器是否是运行在mac平台下
  68. * @example
  69. * ```javascript
  70. * if ( UE.browser.mac ) {
  71. * console.log( '当前浏览器运行在mac平台下' );
  72. * }
  73. * ```
  74. */
  75. mac: agent.indexOf('macintosh') > -1,
  76. /**
  77. * @property {boolean} quirks 检测当前浏览器是否处于“怪异模式”下
  78. * @example
  79. * ```javascript
  80. * if ( UE.browser.quirks ) {
  81. * console.log( '当前浏览器运行处于“怪异模式”' );
  82. * }
  83. * ```
  84. */
  85. quirks: document.compatMode == 'BackCompat'
  86. }
  87. /**
  88. * @property {boolean} gecko 检测当前浏览器内核是否是gecko内核
  89. * @example
  90. * ```javascript
  91. * if ( UE.browser.gecko ) {
  92. * console.log( '当前浏览器内核是gecko内核' );
  93. * }
  94. * ```
  95. */
  96. browser.gecko = navigator.product == 'Gecko' && !browser.webkit && !browser.opera && !browser.ie
  97. var version = 0
  98. // Internet Explorer 6.0+
  99. if (browser.ie) {
  100. var v1 = agent.match(/(?:msie\s([\w.]+))/)
  101. var v2 = agent.match(/(?:trident.*rv:([\w.]+))/)
  102. if (v1 && v2 && v1[1] && v2[1]) {
  103. version = Math.max(v1[1] * 1, v2[1] * 1)
  104. } else if (v1 && v1[1]) {
  105. version = v1[1] * 1
  106. } else if (v2 && v2[1]) {
  107. version = v2[1] * 1
  108. } else {
  109. version = 0
  110. }
  111. browser.ie11Compat = document.documentMode == 11
  112. /**
  113. * @property { boolean } ie9Compat 检测浏览器模式是否为 IE9 兼容模式
  114. * @warning 如果浏览器不是IE, 则该值为undefined
  115. * @example
  116. * ```javascript
  117. * if ( UE.browser.ie9Compat ) {
  118. * console.log( '当前浏览器运行在IE9兼容模式下' );
  119. * }
  120. * ```
  121. */
  122. browser.ie9Compat = document.documentMode == 9
  123. /**
  124. * @property { boolean } ie8 检测浏览器是否是IE8浏览器
  125. * @warning 如果浏览器不是IE, 则该值为undefined
  126. * @example
  127. * ```javascript
  128. * if ( UE.browser.ie8 ) {
  129. * console.log( '当前浏览器是IE8浏览器' );
  130. * }
  131. * ```
  132. */
  133. browser.ie8 = !!document.documentMode
  134. /**
  135. * @property { boolean } ie8Compat 检测浏览器模式是否为 IE8 兼容模式
  136. * @warning 如果浏览器不是IE, 则该值为undefined
  137. * @example
  138. * ```javascript
  139. * if ( UE.browser.ie8Compat ) {
  140. * console.log( '当前浏览器运行在IE8兼容模式下' );
  141. * }
  142. * ```
  143. */
  144. browser.ie8Compat = document.documentMode == 8
  145. /**
  146. * @property { boolean } ie7Compat 检测浏览器模式是否为 IE7 兼容模式
  147. * @warning 如果浏览器不是IE, 则该值为undefined
  148. * @example
  149. * ```javascript
  150. * if ( UE.browser.ie7Compat ) {
  151. * console.log( '当前浏览器运行在IE7兼容模式下' );
  152. * }
  153. * ```
  154. */
  155. browser.ie7Compat = (version == 7 && !document.documentMode) || document.documentMode == 7
  156. /**
  157. * @property { boolean } ie6Compat 检测浏览器模式是否为 IE6 模式 或者怪异模式
  158. * @warning 如果浏览器不是IE, 则该值为undefined
  159. * @example
  160. * ```javascript
  161. * if ( UE.browser.ie6Compat ) {
  162. * console.log( '当前浏览器运行在IE6模式或者怪异模式下' );
  163. * }
  164. * ```
  165. */
  166. browser.ie6Compat = version < 7 || browser.quirks
  167. browser.ie9above = version > 8
  168. browser.ie9below = version < 9
  169. browser.ie11above = version > 10
  170. browser.ie11below = version < 11
  171. }
  172. // Gecko.
  173. if (browser.gecko) {
  174. var geckoRelease = agent.match(/rv:([\d\.]+)/)
  175. if (geckoRelease) {
  176. geckoRelease = geckoRelease[1].split('.')
  177. version =
  178. geckoRelease[0] * 10000 + (geckoRelease[1] || 0) * 100 + (geckoRelease[2] || 0) * 1
  179. }
  180. }
  181. /**
  182. * @property { Number } chrome 检测当前浏览器是否为Chrome, 如果是,则返回Chrome的大版本号
  183. * @warning 如果浏览器不是chrome, 则该值为undefined
  184. * @example
  185. * ```javascript
  186. * if ( UE.browser.chrome ) {
  187. * console.log( '当前浏览器是Chrome' );
  188. * }
  189. * ```
  190. */
  191. if (/chrome\/(\d+\.\d)/i.test(agent)) {
  192. browser.chrome = +RegExp['\x241']
  193. }
  194. /**
  195. * @property { Number } safari 检测当前浏览器是否为Safari, 如果是,则返回Safari的大版本号
  196. * @warning 如果浏览器不是safari, 则该值为undefined
  197. * @example
  198. * ```javascript
  199. * if ( UE.browser.safari ) {
  200. * console.log( '当前浏览器是Safari' );
  201. * }
  202. * ```
  203. */
  204. if (/(\d+\.\d)?(?:\.\d)?\s+safari\/?(\d+\.\d+)?/i.test(agent) && !/chrome/i.test(agent)) {
  205. browser.safari = +(RegExp['\x241'] || RegExp['\x242'])
  206. }
  207. // Opera 9.50+
  208. if (browser.opera) version = parseFloat(opera.version())
  209. // WebKit 522+ (Safari 3+)
  210. if (browser.webkit) version = parseFloat(agent.match(/ applewebkit\/(\d+)/)[1])
  211. /**
  212. * @property { Number } version 检测当前浏览器版本号
  213. * @remind
  214. * <ul>
  215. * <li>IE系列返回值为5,6,7,8,9,10等</li>
  216. * <li>gecko系列会返回10900,158900等</li>
  217. * <li>webkit系列会返回其build号 (如 522等)</li>
  218. * </ul>
  219. * @example
  220. * ```javascript
  221. * console.log( '当前浏览器版本号是: ' + UE.browser.version );
  222. * ```
  223. */
  224. browser.version = version
  225. /**
  226. * @property { boolean } isCompatible 检测当前浏览器是否能够与UEditor良好兼容
  227. * @example
  228. * ```javascript
  229. * if ( UE.browser.isCompatible ) {
  230. * console.log( '浏览器与UEditor能够良好兼容' );
  231. * }
  232. * ```
  233. */
  234. browser.isCompatible =
  235. !browser.mobile &&
  236. ((browser.ie && version >= 6) ||
  237. (browser.gecko && version >= 10801) ||
  238. (browser.opera && version >= 9.5) ||
  239. (browser.air && version >= 1) ||
  240. (browser.webkit && version >= 522) ||
  241. false)
  242. return browser
  243. })())
  244. //快捷方式
  245. var ie = browser.ie,
  246. webkit = browser.webkit,
  247. gecko = browser.gecko,
  248. opera = browser.opera
  249. // core/utils.js
  250. /**
  251. * 工具函数包
  252. * @file
  253. * @module UE.utils
  254. * @since 1.2.6.1
  255. */
  256. /**
  257. * UEditor封装使用的静态工具函数
  258. * @module UE.utils
  259. * @unfile
  260. */
  261. var utils = (UE.utils = {
  262. /**
  263. * 用给定的迭代器遍历对象
  264. * @method each
  265. * @param { Object } obj 需要遍历的对象
  266. * @param { Function } iterator 迭代器, 该方法接受两个参数, 第一个参数是当前所处理的value, 第二个参数是当前遍历对象的key
  267. * @example
  268. * ```javascript
  269. * var demoObj = {
  270. * key1: 1,
  271. * key2: 2
  272. * };
  273. *
  274. * //output: key1: 1, key2: 2
  275. * UE.utils.each( demoObj, funciton ( value, key ) {
  276. *
  277. * console.log( key + ":" + value );
  278. *
  279. * } );
  280. * ```
  281. */
  282. /**
  283. * 用给定的迭代器遍历数组或类数组对象
  284. * @method each
  285. * @param { Array } array 需要遍历的数组或者类数组
  286. * @param { Function } iterator 迭代器, 该方法接受两个参数, 第一个参数是当前所处理的value, 第二个参数是当前遍历对象的key
  287. * @example
  288. * ```javascript
  289. * var divs = document.getElmentByTagNames( "div" );
  290. *
  291. * //output: 0: DIV, 1: DIV ...
  292. * UE.utils.each( divs, funciton ( value, key ) {
  293. *
  294. * console.log( key + ":" + value.tagName );
  295. *
  296. * } );
  297. * ```
  298. */
  299. each: function (obj, iterator, context) {
  300. if (obj == null) return
  301. if (obj.length === +obj.length) {
  302. for (var i = 0, l = obj.length; i < l; i++) {
  303. if (iterator.call(context, obj[i], i, obj) === false) return false
  304. }
  305. } else {
  306. for (var key in obj) {
  307. if (obj.hasOwnProperty(key)) {
  308. if (iterator.call(context, obj[key], key, obj) === false) return false
  309. }
  310. }
  311. }
  312. },
  313. /**
  314. * 以给定对象作为原型创建一个新对象
  315. * @method makeInstance
  316. * @param { Object } protoObject 该对象将作为新创建对象的原型
  317. * @return { Object } 新的对象, 该对象的原型是给定的protoObject对象
  318. * @example
  319. * ```javascript
  320. *
  321. * var protoObject = { sayHello: function () { console.log('Hello UEditor!'); } };
  322. *
  323. * var newObject = UE.utils.makeInstance( protoObject );
  324. * //output: Hello UEditor!
  325. * newObject.sayHello();
  326. * ```
  327. */
  328. makeInstance: function (obj) {
  329. var noop = new Function()
  330. noop.prototype = obj
  331. obj = new noop()
  332. noop.prototype = null
  333. return obj
  334. },
  335. /**
  336. * 将source对象中的属性扩展到target对象上
  337. * @method extend
  338. * @remind 该方法将强制把source对象上的属性复制到target对象上
  339. * @see UE.utils.extend(Object,Object,Boolean)
  340. * @param { Object } target 目标对象, 新的属性将附加到该对象上
  341. * @param { Object } source 源对象, 该对象的属性会被附加到target对象上
  342. * @return { Object } 返回target对象
  343. * @example
  344. * ```javascript
  345. *
  346. * var target = { name: 'target', sex: 1 },
  347. * source = { name: 'source', age: 17 };
  348. *
  349. * UE.utils.extend( target, source );
  350. *
  351. * //output: { name: 'source', sex: 1, age: 17 }
  352. * console.log( target );
  353. *
  354. * ```
  355. */
  356. /**
  357. * 将source对象中的属性扩展到target对象上, 根据指定的isKeepTarget值决定是否保留目标对象中与
  358. * 源对象属性名相同的属性值。
  359. * @method extend
  360. * @param { Object } target 目标对象, 新的属性将附加到该对象上
  361. * @param { Object } source 源对象, 该对象的属性会被附加到target对象上
  362. * @param { Boolean } isKeepTarget 是否保留目标对象中与源对象中属性名相同的属性
  363. * @return { Object } 返回target对象
  364. * @example
  365. * ```javascript
  366. *
  367. * var target = { name: 'target', sex: 1 },
  368. * source = { name: 'source', age: 17 };
  369. *
  370. * UE.utils.extend( target, source, true );
  371. *
  372. * //output: { name: 'target', sex: 1, age: 17 }
  373. * console.log( target );
  374. *
  375. * ```
  376. */
  377. extend: function (t, s, b) {
  378. if (s) {
  379. for (var k in s) {
  380. if (!b || !t.hasOwnProperty(k)) {
  381. t[k] = s[k]
  382. }
  383. }
  384. }
  385. return t
  386. },
  387. /**
  388. * 将给定的多个对象的属性复制到目标对象target上
  389. * @method extend2
  390. * @remind 该方法将强制把源对象上的属性复制到target对象上
  391. * @remind 该方法支持两个及以上的参数, 从第二个参数开始, 其属性都会被复制到第一个参数上。 如果遇到同名的属性,
  392. * 将会覆盖掉之前的值。
  393. * @param { Object } target 目标对象, 新的属性将附加到该对象上
  394. * @param { Object... } source 源对象, 支持多个对象, 该对象的属性会被附加到target对象上
  395. * @return { Object } 返回target对象
  396. * @example
  397. * ```javascript
  398. *
  399. * var target = {},
  400. * source1 = { name: 'source', age: 17 },
  401. * source2 = { title: 'dev' };
  402. *
  403. * UE.utils.extend2( target, source1, source2 );
  404. *
  405. * //output: { name: 'source', age: 17, title: 'dev' }
  406. * console.log( target );
  407. *
  408. * ```
  409. */
  410. extend2: function (t) {
  411. var a = arguments
  412. for (var i = 1; i < a.length; i++) {
  413. var x = a[i]
  414. for (var k in x) {
  415. if (!t.hasOwnProperty(k)) {
  416. t[k] = x[k]
  417. }
  418. }
  419. }
  420. return t
  421. },
  422. /**
  423. * 模拟继承机制, 使得subClass继承自superClass
  424. * @method inherits
  425. * @param { Object } subClass 子类对象
  426. * @param { Object } superClass 超类对象
  427. * @warning 该方法只能让subClass继承超类的原型, subClass对象自身的属性和方法不会被继承
  428. * @return { Object } 继承superClass后的子类对象
  429. * @example
  430. * ```javascript
  431. * function SuperClass(){
  432. * this.name = "小李";
  433. * }
  434. *
  435. * SuperClass.prototype = {
  436. * hello:function(str){
  437. * console.log(this.name + str);
  438. * }
  439. * }
  440. *
  441. * function SubClass(){
  442. * this.name = "小张";
  443. * }
  444. *
  445. * UE.utils.inherits(SubClass,SuperClass);
  446. *
  447. * var sub = new SubClass();
  448. * //output: '小张早上好!
  449. * sub.hello("早上好!");
  450. * ```
  451. */
  452. inherits: function (subClass, superClass) {
  453. var oldP = subClass.prototype,
  454. newP = utils.makeInstance(superClass.prototype)
  455. utils.extend(newP, oldP, true)
  456. subClass.prototype = newP
  457. return (newP.constructor = subClass)
  458. },
  459. /**
  460. * 用指定的context对象作为函数fn的上下文
  461. * @method bind
  462. * @param { Function } fn 需要绑定上下文的函数对象
  463. * @param { Object } content 函数fn新的上下文对象
  464. * @return { Function } 一个新的函数, 该函数作为原始函数fn的代理, 将完成fn的上下文调换工作。
  465. * @example
  466. * ```javascript
  467. *
  468. * var name = 'window',
  469. * newTest = null;
  470. *
  471. * function test () {
  472. * console.log( this.name );
  473. * }
  474. *
  475. * newTest = UE.utils.bind( test, { name: 'object' } );
  476. *
  477. * //output: object
  478. * newTest();
  479. *
  480. * //output: window
  481. * test();
  482. *
  483. * ```
  484. */
  485. bind: function (fn, context) {
  486. return function () {
  487. return fn.apply(context, arguments)
  488. }
  489. },
  490. /**
  491. * 创建延迟指定时间后执行的函数fn
  492. * @method defer
  493. * @param { Function } fn 需要延迟执行的函数对象
  494. * @param { int } delay 延迟的时间, 单位是毫秒
  495. * @warning 该方法的时间控制是不精确的,仅仅只能保证函数的执行是在给定的时间之后,
  496. * 而不能保证刚好到达延迟时间时执行。
  497. * @return { Function } 目标函数fn的代理函数, 只有执行该函数才能起到延时效果
  498. * @example
  499. * ```javascript
  500. * var start = 0;
  501. *
  502. * function test(){
  503. * console.log( new Date() - start );
  504. * }
  505. *
  506. * var testDefer = UE.utils.defer( test, 1000 );
  507. * //
  508. * start = new Date();
  509. * //output: (大约在1000毫秒之后输出) 1000
  510. * testDefer();
  511. * ```
  512. */
  513. /**
  514. * 创建延迟指定时间后执行的函数fn, 如果在延迟时间内再次执行该方法, 将会根据指定的exclusion的值,
  515. * 决定是否取消前一次函数的执行, 如果exclusion的值为true, 则取消执行,反之,将继续执行前一个方法。
  516. * @method defer
  517. * @param { Function } fn 需要延迟执行的函数对象
  518. * @param { int } delay 延迟的时间, 单位是毫秒
  519. * @param { Boolean } exclusion 如果在延迟时间内再次执行该函数,该值将决定是否取消执行前一次函数的执行,
  520. * 值为true表示取消执行, 反之则将在执行前一次函数之后才执行本次函数调用。
  521. * @warning 该方法的时间控制是不精确的,仅仅只能保证函数的执行是在给定的时间之后,
  522. * 而不能保证刚好到达延迟时间时执行。
  523. * @return { Function } 目标函数fn的代理函数, 只有执行该函数才能起到延时效果
  524. * @example
  525. * ```javascript
  526. *
  527. * function test(){
  528. * console.log(1);
  529. * }
  530. *
  531. * var testDefer = UE.utils.defer( test, 1000, true );
  532. *
  533. * //output: (两次调用仅有一次输出) 1
  534. * testDefer();
  535. * testDefer();
  536. * ```
  537. */
  538. defer: function (fn, delay, exclusion) {
  539. var timerID
  540. return function () {
  541. if (exclusion) {
  542. clearTimeout(timerID)
  543. }
  544. timerID = setTimeout(fn, delay)
  545. }
  546. },
  547. /**
  548. * 获取元素item在数组array中首次出现的位置, 如果未找到item, 则返回-1
  549. * @method indexOf
  550. * @remind 该方法的匹配过程使用的是恒等“===”
  551. * @param { Array } array 需要查找的数组对象
  552. * @param { * } item 需要在目标数组中查找的值
  553. * @return { int } 返回item在目标数组array中首次出现的位置, 如果在数组中未找到item, 则返回-1
  554. * @example
  555. * ```javascript
  556. * var item = 1,
  557. * arr = [ 3, 4, 6, 8, 1, 1, 2 ];
  558. *
  559. * //output: 4
  560. * console.log( UE.utils.indexOf( arr, item ) );
  561. * ```
  562. */
  563. /**
  564. * 获取元素item数组array中首次出现的位置, 如果未找到item, 则返回-1。通过start的值可以指定搜索的起始位置。
  565. * @method indexOf
  566. * @remind 该方法的匹配过程使用的是恒等“===”
  567. * @param { Array } array 需要查找的数组对象
  568. * @param { * } item 需要在目标数组中查找的值
  569. * @param { int } start 搜索的起始位置
  570. * @return { int } 返回item在目标数组array中的start位置之后首次出现的位置, 如果在数组中未找到item, 则返回-1
  571. * @example
  572. * ```javascript
  573. * var item = 1,
  574. * arr = [ 3, 4, 6, 8, 1, 2, 8, 3, 2, 1, 1, 4 ];
  575. *
  576. * //output: 9
  577. * console.log( UE.utils.indexOf( arr, item, 5 ) );
  578. * ```
  579. */
  580. indexOf: function (array, item, start) {
  581. var index = -1
  582. start = this.isNumber(start) ? start : 0
  583. this.each(array, function (v, i) {
  584. if (i >= start && v === item) {
  585. index = i
  586. return false
  587. }
  588. })
  589. return index
  590. },
  591. /**
  592. * 移除数组array中所有的元素item
  593. * @method removeItem
  594. * @param { Array } array 要移除元素的目标数组
  595. * @param { * } item 将要被移除的元素
  596. * @remind 该方法的匹配过程使用的是恒等“===”
  597. * @example
  598. * ```javascript
  599. * var arr = [ 4, 5, 7, 1, 3, 4, 6 ];
  600. *
  601. * UE.utils.removeItem( arr, 4 );
  602. * //output: [ 5, 7, 1, 3, 6 ]
  603. * console.log( arr );
  604. *
  605. * ```
  606. */
  607. removeItem: function (array, item) {
  608. for (var i = 0, l = array.length; i < l; i++) {
  609. if (array[i] === item) {
  610. array.splice(i, 1)
  611. i--
  612. }
  613. }
  614. },
  615. /**
  616. * 删除字符串str的首尾空格
  617. * @method trim
  618. * @param { String } str 需要删除首尾空格的字符串
  619. * @return { String } 删除了首尾的空格后的字符串
  620. * @example
  621. * ```javascript
  622. *
  623. * var str = " UEdtior ";
  624. *
  625. * //output: 9
  626. * console.log( str.length );
  627. *
  628. * //output: 7
  629. * console.log( UE.utils.trim( " UEdtior " ).length );
  630. *
  631. * //output: 9
  632. * console.log( str.length );
  633. *
  634. * ```
  635. */
  636. trim: function (str) {
  637. return str.replace(/(^[ \t\n\r]+)|([ \t\n\r]+$)/g, '')
  638. },
  639. /**
  640. * 将字符串str以','分隔成数组后,将该数组转换成哈希对象, 其生成的hash对象的key为数组中的元素, value为1
  641. * @method listToMap
  642. * @warning 该方法在生成的hash对象中,会为每一个key同时生成一个另一个全大写的key。
  643. * @param { String } str 该字符串将被以','分割为数组, 然后进行转化
  644. * @return { Object } 转化之后的hash对象
  645. * @example
  646. * ```javascript
  647. *
  648. * //output: Object {UEdtior: 1, UEDTIOR: 1, Hello: 1, HELLO: 1}
  649. * console.log( UE.utils.listToMap( 'UEdtior,Hello' ) );
  650. *
  651. * ```
  652. */
  653. /**
  654. * 将字符串数组转换成哈希对象, 其生成的hash对象的key为数组中的元素, value为1
  655. * @method listToMap
  656. * @warning 该方法在生成的hash对象中,会为每一个key同时生成一个另一个全大写的key。
  657. * @param { Array } arr 字符串数组
  658. * @return { Object } 转化之后的hash对象
  659. * @example
  660. * ```javascript
  661. *
  662. * //output: Object {UEdtior: 1, UEDTIOR: 1, Hello: 1, HELLO: 1}
  663. * console.log( UE.utils.listToMap( [ 'UEdtior', 'Hello' ] ) );
  664. *
  665. * ```
  666. */
  667. listToMap: function (list) {
  668. if (!list) return {}
  669. list = utils.isArray(list) ? list : list.split(',')
  670. for (var i = 0, ci, obj = {}; (ci = list[i++]); ) {
  671. obj[ci.toUpperCase()] = obj[ci] = 1
  672. }
  673. return obj
  674. },
  675. /**
  676. * 将str中的html符号转义,将转义“',&,<,",>”五个字符
  677. * @method unhtml
  678. * @param { String } str 需要转义的字符串
  679. * @return { String } 转义后的字符串
  680. * @example
  681. * ```javascript
  682. * var html = '<body>&</body>';
  683. *
  684. * //output: &lt;body&gt;&amp;&lt;/body&gt;
  685. * console.log( UE.utils.unhtml( html ) );
  686. *
  687. * ```
  688. */
  689. unhtml: function (str, reg) {
  690. return str
  691. ? str.replace(reg || /[&<">'](?:(amp|lt|quot|gt|#39|nbsp|#\d+);)?/g, function (a, b) {
  692. if (b) {
  693. return a
  694. } else {
  695. return {
  696. '<': '&lt;',
  697. '&': '&amp;',
  698. '"': '&quot;',
  699. '>': '&gt;',
  700. "'": '&#39;'
  701. }[a]
  702. }
  703. })
  704. : ''
  705. },
  706. /**
  707. * 将url中的html字符转义, 仅转义 ', ", <, > 四个字符
  708. * @param { String } str 需要转义的字符串
  709. * @param { RegExp } reg 自定义的正则
  710. * @return { String } 转义后的字符串
  711. */
  712. unhtmlForUrl: function (str, reg) {
  713. return str
  714. ? str.replace(reg || /[<">']/g, function (a) {
  715. return {
  716. '<': '&lt;',
  717. '&': '&amp;',
  718. '"': '&quot;',
  719. '>': '&gt;',
  720. "'": '&#39;'
  721. }[a]
  722. })
  723. : ''
  724. },
  725. /**
  726. * 将str中的转义字符还原成html字符
  727. * @see UE.utils.unhtml(String);
  728. * @method html
  729. * @param { String } str 需要逆转义的字符串
  730. * @return { String } 逆转义后的字符串
  731. * @example
  732. * ```javascript
  733. *
  734. * var str = '&lt;body&gt;&amp;&lt;/body&gt;';
  735. *
  736. * //output: <body>&</body>
  737. * console.log( UE.utils.html( str ) );
  738. *
  739. * ```
  740. */
  741. html: function (str) {
  742. return str
  743. ? str.replace(/&((g|l|quo)t|amp|#39|nbsp);/g, function (m) {
  744. return {
  745. '&lt;': '<',
  746. '&amp;': '&',
  747. '&quot;': '"',
  748. '&gt;': '>',
  749. '&#39;': "'",
  750. '&nbsp;': ' '
  751. }[m]
  752. })
  753. : ''
  754. },
  755. /**
  756. * 将css样式转换为驼峰的形式
  757. * @method cssStyleToDomStyle
  758. * @param { String } cssName 需要转换的css样式名
  759. * @return { String } 转换成驼峰形式后的css样式名
  760. * @example
  761. * ```javascript
  762. *
  763. * var str = 'border-top';
  764. *
  765. * //output: borderTop
  766. * console.log( UE.utils.cssStyleToDomStyle( str ) );
  767. *
  768. * ```
  769. */
  770. cssStyleToDomStyle: (function () {
  771. var test = document.createElement('div').style,
  772. cache = {
  773. float:
  774. test.cssFloat != undefined
  775. ? 'cssFloat'
  776. : test.styleFloat != undefined
  777. ? 'styleFloat'
  778. : 'float'
  779. }
  780. return function (cssName) {
  781. return (
  782. cache[cssName] ||
  783. (cache[cssName] = cssName.toLowerCase().replace(/-./g, function (match) {
  784. return match.charAt(1).toUpperCase()
  785. }))
  786. )
  787. }
  788. })(),
  789. /**
  790. * 动态加载文件到doc中
  791. * @method loadFile
  792. * @param { DomDocument } document 需要加载资源文件的文档对象
  793. * @param { Object } options 加载资源文件的属性集合, 取值请参考代码示例
  794. * @example
  795. * ```javascript
  796. *
  797. * UE.utils.loadFile( document, {
  798. * src:"test.js",
  799. * tag:"script",
  800. * type:"text/javascript",
  801. * defer:"defer"
  802. * } );
  803. *
  804. * ```
  805. */
  806. /**
  807. * 动态加载文件到doc中,加载成功后执行的回调函数fn
  808. * @method loadFile
  809. * @param { DomDocument } document 需要加载资源文件的文档对象
  810. * @param { Object } options 加载资源文件的属性集合, 该集合支持的值是script标签和style标签支持的所有属性。
  811. * @param { Function } fn 资源文件加载成功之后执行的回调
  812. * @warning 对于在同一个文档中多次加载同一URL的文件, 该方法会在第一次加载之后缓存该请求,
  813. * 在此之后的所有同一URL的请求, 将会直接触发回调。
  814. * @example
  815. * ```javascript
  816. *
  817. * UE.utils.loadFile( document, {
  818. * src:"test.js",
  819. * tag:"script",
  820. * type:"text/javascript",
  821. * defer:"defer"
  822. * }, function () {
  823. * console.log('加载成功');
  824. * } );
  825. *
  826. * ```
  827. */
  828. loadFile: (function () {
  829. var tmpList = []
  830. function getItem(doc, obj) {
  831. try {
  832. for (var i = 0, ci; (ci = tmpList[i++]); ) {
  833. if (ci.doc === doc && ci.url == (obj.src || obj.href)) {
  834. return ci
  835. }
  836. }
  837. } catch (e) {
  838. return null
  839. }
  840. }
  841. return function (doc, obj, fn) {
  842. var item = getItem(doc, obj)
  843. if (item) {
  844. if (item.ready) {
  845. fn && fn()
  846. } else {
  847. item.funs.push(fn)
  848. }
  849. return
  850. }
  851. tmpList.push({
  852. doc: doc,
  853. url: obj.src || obj.href,
  854. funs: [fn]
  855. })
  856. if (!doc.body) {
  857. var html = []
  858. for (var p in obj) {
  859. if (p == 'tag') continue
  860. html.push(p + '="' + obj[p] + '"')
  861. }
  862. doc.write('<' + obj.tag + ' ' + html.join(' ') + ' ></' + obj.tag + '>')
  863. return
  864. }
  865. if (obj.id && doc.getElementById(obj.id)) {
  866. return
  867. }
  868. var element = doc.createElement(obj.tag)
  869. delete obj.tag
  870. for (var p in obj) {
  871. element.setAttribute(p, obj[p])
  872. }
  873. element.onload = element.onreadystatechange = function () {
  874. if (!this.readyState || /loaded|complete/.test(this.readyState)) {
  875. item = getItem(doc, obj)
  876. if (item.funs.length > 0) {
  877. item.ready = 1
  878. for (var fi; (fi = item.funs.pop()); ) {
  879. fi()
  880. }
  881. }
  882. element.onload = element.onreadystatechange = null
  883. }
  884. }
  885. element.onerror = function () {
  886. throw Error(
  887. 'The load ' +
  888. (obj.href || obj.src) +
  889. ' fails,check the url settings of file ueditor.config.js '
  890. )
  891. }
  892. doc.getElementsByTagName('head')[0].appendChild(element)
  893. }
  894. })(),
  895. /**
  896. * 判断obj对象是否为空
  897. * @method isEmptyObject
  898. * @param { * } obj 需要判断的对象
  899. * @remind 如果判断的对象是NULL, 将直接返回true, 如果是数组且为空, 返回true, 如果是字符串, 且字符串为空,
  900. * 返回true, 如果是普通对象, 且该对象没有任何实例属性, 返回true
  901. * @return { Boolean } 对象是否为空
  902. * @example
  903. * ```javascript
  904. *
  905. * //output: true
  906. * console.log( UE.utils.isEmptyObject( {} ) );
  907. *
  908. * //output: true
  909. * console.log( UE.utils.isEmptyObject( [] ) );
  910. *
  911. * //output: true
  912. * console.log( UE.utils.isEmptyObject( "" ) );
  913. *
  914. * //output: false
  915. * console.log( UE.utils.isEmptyObject( { key: 1 } ) );
  916. *
  917. * //output: false
  918. * console.log( UE.utils.isEmptyObject( [1] ) );
  919. *
  920. * //output: false
  921. * console.log( UE.utils.isEmptyObject( "1" ) );
  922. *
  923. * ```
  924. */
  925. isEmptyObject: function (obj) {
  926. if (obj == null) return true
  927. if (this.isArray(obj) || this.isString(obj)) return obj.length === 0
  928. for (var key in obj) if (obj.hasOwnProperty(key)) return false
  929. return true
  930. },
  931. /**
  932. * 把rgb格式的颜色值转换成16进制格式
  933. * @method fixColor
  934. * @param { String } rgb格式的颜色值
  935. * @param { String }
  936. * @example
  937. * rgb(255,255,255) => "#ffffff"
  938. */
  939. fixColor: function (name, value) {
  940. if (/color/i.test(name) && /rgba?/.test(value)) {
  941. var array = value.split(',')
  942. if (array.length > 3) return ''
  943. value = '#'
  944. for (var i = 0, color; (color = array[i++]); ) {
  945. color = parseInt(color.replace(/[^\d]/gi, ''), 10).toString(16)
  946. value += color.length == 1 ? '0' + color : color
  947. }
  948. value = value.toUpperCase()
  949. }
  950. return value
  951. },
  952. /**
  953. * 只针对border,padding,margin做了处理,因为性能问题
  954. * @public
  955. * @function
  956. * @param {String} val style字符串
  957. */
  958. optCss: function (val) {
  959. var padding, margin, border
  960. val = val.replace(
  961. /(padding|margin|border)\-([^:]+):([^;]+);?/gi,
  962. function (str, key, name, val) {
  963. if (val.split(' ').length == 1) {
  964. switch (key) {
  965. case 'padding':
  966. !padding && (padding = {})
  967. padding[name] = val
  968. return ''
  969. case 'margin':
  970. !margin && (margin = {})
  971. margin[name] = val
  972. return ''
  973. case 'border':
  974. return val == 'initial' ? '' : str
  975. }
  976. }
  977. return str
  978. }
  979. )
  980. function opt(obj, name) {
  981. if (!obj) {
  982. return ''
  983. }
  984. var t = obj.top,
  985. b = obj.bottom,
  986. l = obj.left,
  987. r = obj.right,
  988. val = ''
  989. if (!t || !l || !b || !r) {
  990. for (var p in obj) {
  991. val += ';' + name + '-' + p + ':' + obj[p] + ';'
  992. }
  993. } else {
  994. val +=
  995. ';' +
  996. name +
  997. ':' +
  998. (t == b && b == l && l == r
  999. ? t
  1000. : t == b && l == r
  1001. ? t + ' ' + l
  1002. : l == r
  1003. ? t + ' ' + l + ' ' + b
  1004. : t + ' ' + r + ' ' + b + ' ' + l) +
  1005. ';'
  1006. }
  1007. return val
  1008. }
  1009. val += opt(padding, 'padding') + opt(margin, 'margin')
  1010. return val
  1011. .replace(/^[ \n\r\t;]*|[ \n\r\t]*$/, '')
  1012. .replace(/;([ \n\r\t]+)|\1;/g, ';')
  1013. .replace(/(&((l|g)t|quot|#39))?;{2,}/g, function (a, b) {
  1014. return b ? b + ';;' : ';'
  1015. })
  1016. },
  1017. /**
  1018. * 克隆对象
  1019. * @method clone
  1020. * @param { Object } source 源对象
  1021. * @return { Object } source的一个副本
  1022. */
  1023. /**
  1024. * 深度克隆对象,将source的属性克隆到target对象, 会覆盖target重名的属性。
  1025. * @method clone
  1026. * @param { Object } source 源对象
  1027. * @param { Object } target 目标对象
  1028. * @return { Object } 附加了source对象所有属性的target对象
  1029. */
  1030. clone: function (source, target) {
  1031. var tmp
  1032. target = target || {}
  1033. for (var i in source) {
  1034. if (source.hasOwnProperty(i)) {
  1035. tmp = source[i]
  1036. if (typeof tmp == 'object') {
  1037. target[i] = utils.isArray(tmp) ? [] : {}
  1038. utils.clone(source[i], target[i])
  1039. } else {
  1040. target[i] = tmp
  1041. }
  1042. }
  1043. }
  1044. return target
  1045. },
  1046. /**
  1047. * 把cm/pt为单位的值转换为px为单位的值
  1048. * @method transUnitToPx
  1049. * @param { String } 待转换的带单位的字符串
  1050. * @return { String } 转换为px为计量单位的值的字符串
  1051. * @example
  1052. * ```javascript
  1053. *
  1054. * //output: 500px
  1055. * console.log( UE.utils.transUnitToPx( '20cm' ) );
  1056. *
  1057. * //output: 27px
  1058. * console.log( UE.utils.transUnitToPx( '20pt' ) );
  1059. *
  1060. * ```
  1061. */
  1062. transUnitToPx: function (val) {
  1063. if (!/(pt|cm)/.test(val)) {
  1064. return val
  1065. }
  1066. var unit
  1067. val.replace(/([\d.]+)(\w+)/, function (str, v, u) {
  1068. val = v
  1069. unit = u
  1070. })
  1071. switch (unit) {
  1072. case 'cm':
  1073. val = parseFloat(val) * 25
  1074. break
  1075. case 'pt':
  1076. val = Math.round((parseFloat(val) * 96) / 72)
  1077. }
  1078. return val + (val ? 'px' : '')
  1079. },
  1080. /**
  1081. * 在dom树ready之后执行给定的回调函数
  1082. * @method domReady
  1083. * @remind 如果在执行该方法的时候, dom树已经ready, 那么回调函数将立刻执行
  1084. * @param { Function } fn dom树ready之后的回调函数
  1085. * @example
  1086. * ```javascript
  1087. *
  1088. * UE.utils.domReady( function () {
  1089. *
  1090. * console.log('123');
  1091. *
  1092. * } );
  1093. *
  1094. * ```
  1095. */
  1096. domReady: (function () {
  1097. var fnArr = []
  1098. function doReady(doc) {
  1099. //确保onready只执行一次
  1100. doc.isReady = true
  1101. for (var ci; (ci = fnArr.pop()); ci()) {}
  1102. }
  1103. return function (onready, win) {
  1104. win = win || window
  1105. var doc = win.document
  1106. onready && fnArr.push(onready)
  1107. if (doc.readyState === 'complete') {
  1108. doReady(doc)
  1109. } else {
  1110. doc.isReady && doReady(doc)
  1111. if (browser.ie && browser.version != 11) {
  1112. ;(function () {
  1113. if (doc.isReady) return
  1114. try {
  1115. doc.documentElement.doScroll('left')
  1116. } catch (error) {
  1117. setTimeout(arguments.callee, 0)
  1118. return
  1119. }
  1120. doReady(doc)
  1121. })()
  1122. win.attachEvent('onload', function () {
  1123. doReady(doc)
  1124. })
  1125. } else {
  1126. doc.addEventListener(
  1127. 'DOMContentLoaded',
  1128. function () {
  1129. doc.removeEventListener('DOMContentLoaded', arguments.callee, false)
  1130. doReady(doc)
  1131. },
  1132. false
  1133. )
  1134. win.addEventListener(
  1135. 'load',
  1136. function () {
  1137. doReady(doc)
  1138. },
  1139. false
  1140. )
  1141. }
  1142. }
  1143. }
  1144. })(),
  1145. /**
  1146. * 动态添加css样式
  1147. * @method cssRule
  1148. * @param { String } 节点名称
  1149. * @grammar UE.utils.cssRule('添加的样式的节点名称',['样式','放到哪个document上'])
  1150. * @grammar UE.utils.cssRule('body','body{background:#ccc}') => null //给body添加背景颜色
  1151. * @grammar UE.utils.cssRule('body') =>样式的字符串 //取得key值为body的样式的内容,如果没有找到key值先关的样式将返回空,例如刚才那个背景颜色,将返回 body{background:#ccc}
  1152. * @grammar UE.utils.cssRule('body',document) => 返回指定key的样式,并且指定是哪个document
  1153. * @grammar UE.utils.cssRule('body','') =>null //清空给定的key值的背景颜色
  1154. */
  1155. cssRule:
  1156. browser.ie && browser.version != 11
  1157. ? function (key, style, doc) {
  1158. var indexList, index
  1159. if (style === undefined || (style && style.nodeType && style.nodeType == 9)) {
  1160. //获取样式
  1161. doc = style && style.nodeType && style.nodeType == 9 ? style : doc || document
  1162. indexList = doc.indexList || (doc.indexList = {})
  1163. index = indexList[key]
  1164. if (index !== undefined) {
  1165. return doc.styleSheets[index].cssText
  1166. }
  1167. return undefined
  1168. }
  1169. doc = doc || document
  1170. indexList = doc.indexList || (doc.indexList = {})
  1171. index = indexList[key]
  1172. //清除样式
  1173. if (style === '') {
  1174. if (index !== undefined) {
  1175. doc.styleSheets[index].cssText = ''
  1176. delete indexList[key]
  1177. return true
  1178. }
  1179. return false
  1180. }
  1181. //添加样式
  1182. if (index !== undefined) {
  1183. sheetStyle = doc.styleSheets[index]
  1184. } else {
  1185. sheetStyle = doc.createStyleSheet('', (index = doc.styleSheets.length))
  1186. indexList[key] = index
  1187. }
  1188. sheetStyle.cssText = style
  1189. }
  1190. : function (key, style, doc) {
  1191. var head, node
  1192. if (style === undefined || (style && style.nodeType && style.nodeType == 9)) {
  1193. //获取样式
  1194. doc = style && style.nodeType && style.nodeType == 9 ? style : doc || document
  1195. node = doc.getElementById(key)
  1196. return node ? node.innerHTML : undefined
  1197. }
  1198. doc = doc || document
  1199. node = doc.getElementById(key)
  1200. //清除样式
  1201. if (style === '') {
  1202. if (node) {
  1203. node.parentNode.removeChild(node)
  1204. return true
  1205. }
  1206. return false
  1207. }
  1208. //添加样式
  1209. if (node) {
  1210. node.innerHTML = style
  1211. } else {
  1212. node = doc.createElement('style')
  1213. node.id = key
  1214. node.innerHTML = style
  1215. doc.getElementsByTagName('head')[0].appendChild(node)
  1216. }
  1217. },
  1218. sort: function (array, compareFn) {
  1219. compareFn =
  1220. compareFn ||
  1221. function (item1, item2) {
  1222. return item1.localeCompare(item2)
  1223. }
  1224. for (var i = 0, len = array.length; i < len; i++) {
  1225. for (var j = i, length = array.length; j < length; j++) {
  1226. if (compareFn(array[i], array[j]) > 0) {
  1227. var t = array[i]
  1228. array[i] = array[j]
  1229. array[j] = t
  1230. }
  1231. }
  1232. }
  1233. return array
  1234. },
  1235. serializeParam: function (json) {
  1236. var strArr = []
  1237. for (var i in json) {
  1238. //忽略默认的几个参数
  1239. if (i == 'method' || i == 'timeout' || i == 'async') continue
  1240. //传递过来的对象和函数不在提交之列
  1241. if (
  1242. !(
  1243. (typeof json[i]).toLowerCase() == 'function' ||
  1244. (typeof json[i]).toLowerCase() == 'object'
  1245. )
  1246. ) {
  1247. strArr.push(encodeURIComponent(i) + '=' + encodeURIComponent(json[i]))
  1248. } else if (utils.isArray(json[i])) {
  1249. //支持传数组内容
  1250. for (var j = 0; j < json[i].length; j++) {
  1251. strArr.push(encodeURIComponent(i) + '[]=' + encodeURIComponent(json[i][j]))
  1252. }
  1253. }
  1254. }
  1255. return strArr.join('&')
  1256. },
  1257. formatUrl: function (url) {
  1258. var u = url.replace(/&&/g, '&')
  1259. u = u.replace(/\?&/g, '?')
  1260. u = u.replace(/&$/g, '')
  1261. u = u.replace(/&#/g, '#')
  1262. u = u.replace(/&+/g, '&')
  1263. return u
  1264. },
  1265. isCrossDomainUrl: function (url) {
  1266. var a = document.createElement('a')
  1267. a.href = url
  1268. if (browser.ie) {
  1269. a.href = a.href
  1270. }
  1271. return !(
  1272. a.protocol == location.protocol &&
  1273. a.hostname == location.hostname &&
  1274. (a.port == location.port ||
  1275. (a.port == '80' && location.port == '') ||
  1276. (a.port == '' && location.port == '80'))
  1277. )
  1278. },
  1279. clearEmptyAttrs: function (obj) {
  1280. for (var p in obj) {
  1281. if (obj[p] === '') {
  1282. delete obj[p]
  1283. }
  1284. }
  1285. return obj
  1286. },
  1287. str2json: function (s) {
  1288. if (!utils.isString(s)) return null
  1289. if (window.JSON) {
  1290. return JSON.parse(s)
  1291. } else {
  1292. return new Function('return ' + utils.trim(s || ''))()
  1293. }
  1294. },
  1295. json2str: (function () {
  1296. if (window.JSON) {
  1297. return JSON.stringify
  1298. } else {
  1299. var escapeMap = {
  1300. '\b': '\\b',
  1301. '\t': '\\t',
  1302. '\n': '\\n',
  1303. '\f': '\\f',
  1304. '\r': '\\r',
  1305. '"': '\\"',
  1306. '\\': '\\\\'
  1307. }
  1308. function encodeString(source) {
  1309. if (/["\\\x00-\x1f]/.test(source)) {
  1310. source = source.replace(/["\\\x00-\x1f]/g, function (match) {
  1311. var c = escapeMap[match]
  1312. if (c) {
  1313. return c
  1314. }
  1315. c = match.charCodeAt()
  1316. return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16)
  1317. })
  1318. }
  1319. return '"' + source + '"'
  1320. }
  1321. function encodeArray(source) {
  1322. var result = ['['],
  1323. l = source.length,
  1324. preComma,
  1325. i,
  1326. item
  1327. for (i = 0; i < l; i++) {
  1328. item = source[i]
  1329. switch (typeof item) {
  1330. case 'undefined':
  1331. case 'function':
  1332. case 'unknown':
  1333. break
  1334. default:
  1335. if (preComma) {
  1336. result.push(',')
  1337. }
  1338. result.push(utils.json2str(item))
  1339. preComma = 1
  1340. }
  1341. }
  1342. result.push(']')
  1343. return result.join('')
  1344. }
  1345. function pad(source) {
  1346. return source < 10 ? '0' + source : source
  1347. }
  1348. function encodeDate(source) {
  1349. return (
  1350. '"' +
  1351. source.getFullYear() +
  1352. '-' +
  1353. pad(source.getMonth() + 1) +
  1354. '-' +
  1355. pad(source.getDate()) +
  1356. 'T' +
  1357. pad(source.getHours()) +
  1358. ':' +
  1359. pad(source.getMinutes()) +
  1360. ':' +
  1361. pad(source.getSeconds()) +
  1362. '"'
  1363. )
  1364. }
  1365. return function (value) {
  1366. switch (typeof value) {
  1367. case 'undefined':
  1368. return 'undefined'
  1369. case 'number':
  1370. return isFinite(value) ? String(value) : 'null'
  1371. case 'string':
  1372. return encodeString(value)
  1373. case 'boolean':
  1374. return String(value)
  1375. default:
  1376. if (value === null) {
  1377. return 'null'
  1378. } else if (utils.isArray(value)) {
  1379. return encodeArray(value)
  1380. } else if (utils.isDate(value)) {
  1381. return encodeDate(value)
  1382. } else {
  1383. var result = ['{'],
  1384. encode = utils.json2str,
  1385. preComma,
  1386. item
  1387. for (var key in value) {
  1388. if (Object.prototype.hasOwnProperty.call(value, key)) {
  1389. item = value[key]
  1390. switch (typeof item) {
  1391. case 'undefined':
  1392. case 'unknown':
  1393. case 'function':
  1394. break
  1395. default:
  1396. if (preComma) {
  1397. result.push(',')
  1398. }
  1399. preComma = 1
  1400. result.push(encode(key) + ':' + encode(item))
  1401. }
  1402. }
  1403. }
  1404. result.push('}')
  1405. return result.join('')
  1406. }
  1407. }
  1408. }
  1409. }
  1410. })()
  1411. })
  1412. /**
  1413. * 判断给定的对象是否是字符串
  1414. * @method isString
  1415. * @param { * } object 需要判断的对象
  1416. * @return { Boolean } 给定的对象是否是字符串
  1417. */
  1418. /**
  1419. * 判断给定的对象是否是数组
  1420. * @method isArray
  1421. * @param { * } object 需要判断的对象
  1422. * @return { Boolean } 给定的对象是否是数组
  1423. */
  1424. /**
  1425. * 判断给定的对象是否是一个Function
  1426. * @method isFunction
  1427. * @param { * } object 需要判断的对象
  1428. * @return { Boolean } 给定的对象是否是Function
  1429. */
  1430. /**
  1431. * 判断给定的对象是否是Number
  1432. * @method isNumber
  1433. * @param { * } object 需要判断的对象
  1434. * @return { Boolean } 给定的对象是否是Number
  1435. */
  1436. /**
  1437. * 判断给定的对象是否是一个正则表达式
  1438. * @method isRegExp
  1439. * @param { * } object 需要判断的对象
  1440. * @return { Boolean } 给定的对象是否是正则表达式
  1441. */
  1442. /**
  1443. * 判断给定的对象是否是一个普通对象
  1444. * @method isObject
  1445. * @param { * } object 需要判断的对象
  1446. * @return { Boolean } 给定的对象是否是普通对象
  1447. */
  1448. utils.each(['String', 'Function', 'Array', 'Number', 'RegExp', 'Object', 'Date'], function (v) {
  1449. UE.utils['is' + v] = function (obj) {
  1450. return Object.prototype.toString.apply(obj) == '[object ' + v + ']'
  1451. }
  1452. })
  1453. // core/EventBase.js
  1454. /**
  1455. * UE采用的事件基类
  1456. * @file
  1457. * @module UE
  1458. * @class EventBase
  1459. * @since 1.2.6.1
  1460. */
  1461. /**
  1462. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  1463. * @unfile
  1464. * @module UE
  1465. */
  1466. /**
  1467. * UE采用的事件基类,继承此类的对应类将获取addListener,removeListener,fireEvent方法。
  1468. * 在UE中,Editor以及所有ui实例都继承了该类,故可以在对应的ui对象以及editor对象上使用上述方法。
  1469. * @unfile
  1470. * @module UE
  1471. * @class EventBase
  1472. */
  1473. /**
  1474. * 通过此构造器,子类可以继承EventBase获取事件监听的方法
  1475. * @constructor
  1476. * @example
  1477. * ```javascript
  1478. * UE.EventBase.call(editor);
  1479. * ```
  1480. */
  1481. var EventBase = (UE.EventBase = function () {})
  1482. EventBase.prototype = {
  1483. /**
  1484. * 注册事件监听器
  1485. * @method addListener
  1486. * @param { String } types 监听的事件名称,同时监听多个事件使用空格分隔
  1487. * @param { Function } fn 监听的事件被触发时,会执行该回调函数
  1488. * @waining 事件被触发时,监听的函数假如返回的值恒等于true,回调函数的队列中后面的函数将不执行
  1489. * @example
  1490. * ```javascript
  1491. * editor.addListener('selectionchange',function(){
  1492. * console.log("选区已经变化!");
  1493. * })
  1494. * editor.addListener('beforegetcontent aftergetcontent',function(type){
  1495. * if(type == 'beforegetcontent'){
  1496. * //do something
  1497. * }else{
  1498. * //do something
  1499. * }
  1500. * console.log(this.getContent) // this是注册的事件的编辑器实例
  1501. * })
  1502. * ```
  1503. * @see UE.EventBase:fireEvent(String)
  1504. */
  1505. addListener: function (types, listener) {
  1506. types = utils.trim(types).split(/\s+/)
  1507. for (var i = 0, ti; (ti = types[i++]); ) {
  1508. getListener(this, ti, true).push(listener)
  1509. }
  1510. },
  1511. on: function (types, listener) {
  1512. return this.addListener(types, listener)
  1513. },
  1514. off: function (types, listener) {
  1515. return this.removeListener(types, listener)
  1516. },
  1517. trigger: function () {
  1518. return this.fireEvent.apply(this, arguments)
  1519. },
  1520. /**
  1521. * 移除事件监听器
  1522. * @method removeListener
  1523. * @param { String } types 移除的事件名称,同时移除多个事件使用空格分隔
  1524. * @param { Function } fn 移除监听事件的函数引用
  1525. * @example
  1526. * ```javascript
  1527. * //changeCallback为方法体
  1528. * editor.removeListener("selectionchange",changeCallback);
  1529. * ```
  1530. */
  1531. removeListener: function (types, listener) {
  1532. types = utils.trim(types).split(/\s+/)
  1533. for (var i = 0, ti; (ti = types[i++]); ) {
  1534. utils.removeItem(getListener(this, ti) || [], listener)
  1535. }
  1536. },
  1537. /**
  1538. * 触发事件
  1539. * @method fireEvent
  1540. * @param { String } types 触发的事件名称,同时触发多个事件使用空格分隔
  1541. * @remind 该方法会触发addListener
  1542. * @return { * } 返回触发事件的队列中,最后执行的回调函数的返回值
  1543. * @example
  1544. * ```javascript
  1545. * editor.fireEvent("selectionchange");
  1546. * ```
  1547. */
  1548. /**
  1549. * 触发事件
  1550. * @method fireEvent
  1551. * @param { String } types 触发的事件名称,同时触发多个事件使用空格分隔
  1552. * @param { *... } options 可选参数,可以传入一个或多个参数,会传给事件触发的回调函数
  1553. * @return { * } 返回触发事件的队列中,最后执行的回调函数的返回值
  1554. * @example
  1555. * ```javascript
  1556. *
  1557. * editor.addListener( "selectionchange", function ( type, arg1, arg2 ) {
  1558. *
  1559. * console.log( arg1 + " " + arg2 );
  1560. *
  1561. * } );
  1562. *
  1563. * //触发selectionchange事件, 会执行上面的事件监听器
  1564. * //output: Hello World
  1565. * editor.fireEvent("selectionchange", "Hello", "World");
  1566. * ```
  1567. */
  1568. fireEvent: function () {
  1569. var types = arguments[0]
  1570. types = utils.trim(types).split(' ')
  1571. for (var i = 0, ti; (ti = types[i++]); ) {
  1572. var listeners = getListener(this, ti),
  1573. r,
  1574. t,
  1575. k
  1576. if (listeners) {
  1577. k = listeners.length
  1578. while (k--) {
  1579. if (!listeners[k]) continue
  1580. t = listeners[k].apply(this, arguments)
  1581. if (t === true) {
  1582. return t
  1583. }
  1584. if (t !== undefined) {
  1585. r = t
  1586. }
  1587. }
  1588. }
  1589. if ((t = this['on' + ti.toLowerCase()])) {
  1590. r = t.apply(this, arguments)
  1591. }
  1592. }
  1593. return r
  1594. }
  1595. }
  1596. /**
  1597. * 获得对象所拥有监听类型的所有监听器
  1598. * @unfile
  1599. * @module UE
  1600. * @since 1.2.6.1
  1601. * @method getListener
  1602. * @public
  1603. * @param { Object } obj 查询监听器的对象
  1604. * @param { String } type 事件类型
  1605. * @param { Boolean } force 为true且当前所有type类型的侦听器不存在时,创建一个空监听器数组
  1606. * @return { Array } 监听器数组
  1607. */
  1608. function getListener(obj, type, force) {
  1609. var allListeners
  1610. type = type.toLowerCase()
  1611. return (
  1612. (allListeners = obj.__allListeners || (force && (obj.__allListeners = {}))) &&
  1613. (allListeners[type] || (force && (allListeners[type] = [])))
  1614. )
  1615. }
  1616. // core/dtd.js
  1617. ///import editor.js
  1618. ///import core/dom/dom.js
  1619. ///import core/utils.js
  1620. /**
  1621. * dtd html语义化的体现类
  1622. * @constructor
  1623. * @namespace dtd
  1624. */
  1625. var dtd = (dom.dtd = (function () {
  1626. function _(s) {
  1627. for (var k in s) {
  1628. s[k.toUpperCase()] = s[k]
  1629. }
  1630. return s
  1631. }
  1632. var X = utils.extend2
  1633. var A = _({ isindex: 1, fieldset: 1 }),
  1634. B = _({ input: 1, button: 1, select: 1, textarea: 1, label: 1 }),
  1635. C = X(_({ a: 1 }), B),
  1636. D = X({ iframe: 1 }, C),
  1637. E = _({
  1638. hr: 1,
  1639. ul: 1,
  1640. menu: 1,
  1641. div: 1,
  1642. blockquote: 1,
  1643. noscript: 1,
  1644. table: 1,
  1645. center: 1,
  1646. address: 1,
  1647. dir: 1,
  1648. pre: 1,
  1649. h5: 1,
  1650. dl: 1,
  1651. h4: 1,
  1652. noframes: 1,
  1653. h6: 1,
  1654. ol: 1,
  1655. h1: 1,
  1656. h3: 1,
  1657. h2: 1
  1658. }),
  1659. F = _({ ins: 1, del: 1, script: 1, style: 1 }),
  1660. G = X(
  1661. _({
  1662. b: 1,
  1663. acronym: 1,
  1664. bdo: 1,
  1665. var: 1,
  1666. '#': 1,
  1667. abbr: 1,
  1668. code: 1,
  1669. br: 1,
  1670. i: 1,
  1671. cite: 1,
  1672. kbd: 1,
  1673. u: 1,
  1674. strike: 1,
  1675. s: 1,
  1676. tt: 1,
  1677. strong: 1,
  1678. q: 1,
  1679. samp: 1,
  1680. em: 1,
  1681. dfn: 1,
  1682. span: 1
  1683. }),
  1684. F
  1685. ),
  1686. H = X(
  1687. _({
  1688. sub: 1,
  1689. img: 1,
  1690. embed: 1,
  1691. object: 1,
  1692. sup: 1,
  1693. basefont: 1,
  1694. map: 1,
  1695. applet: 1,
  1696. font: 1,
  1697. big: 1,
  1698. small: 1
  1699. }),
  1700. G
  1701. ),
  1702. I = X(_({ p: 1 }), H),
  1703. J = X(_({ iframe: 1 }), H, B),
  1704. K = _({
  1705. img: 1,
  1706. embed: 1,
  1707. noscript: 1,
  1708. br: 1,
  1709. kbd: 1,
  1710. center: 1,
  1711. button: 1,
  1712. basefont: 1,
  1713. h5: 1,
  1714. h4: 1,
  1715. samp: 1,
  1716. h6: 1,
  1717. ol: 1,
  1718. h1: 1,
  1719. h3: 1,
  1720. h2: 1,
  1721. form: 1,
  1722. font: 1,
  1723. '#': 1,
  1724. select: 1,
  1725. menu: 1,
  1726. ins: 1,
  1727. abbr: 1,
  1728. label: 1,
  1729. code: 1,
  1730. table: 1,
  1731. script: 1,
  1732. cite: 1,
  1733. input: 1,
  1734. iframe: 1,
  1735. strong: 1,
  1736. textarea: 1,
  1737. noframes: 1,
  1738. big: 1,
  1739. small: 1,
  1740. span: 1,
  1741. hr: 1,
  1742. sub: 1,
  1743. bdo: 1,
  1744. var: 1,
  1745. div: 1,
  1746. object: 1,
  1747. sup: 1,
  1748. strike: 1,
  1749. dir: 1,
  1750. map: 1,
  1751. dl: 1,
  1752. applet: 1,
  1753. del: 1,
  1754. isindex: 1,
  1755. fieldset: 1,
  1756. ul: 1,
  1757. b: 1,
  1758. acronym: 1,
  1759. a: 1,
  1760. blockquote: 1,
  1761. i: 1,
  1762. u: 1,
  1763. s: 1,
  1764. tt: 1,
  1765. address: 1,
  1766. q: 1,
  1767. pre: 1,
  1768. p: 1,
  1769. em: 1,
  1770. dfn: 1
  1771. }),
  1772. L = X(_({ a: 0 }), J), //a不能被切开,所以把他
  1773. M = _({ tr: 1 }),
  1774. N = _({ '#': 1 }),
  1775. O = X(_({ param: 1 }), K),
  1776. P = X(_({ form: 1 }), A, D, E, I),
  1777. Q = _({ li: 1, ol: 1, ul: 1 }),
  1778. R = _({ style: 1, script: 1 }),
  1779. S = _({ base: 1, link: 1, meta: 1, title: 1 }),
  1780. T = X(S, R),
  1781. U = _({ head: 1, body: 1 }),
  1782. V = _({ html: 1 })
  1783. var block = _({
  1784. address: 1,
  1785. blockquote: 1,
  1786. center: 1,
  1787. dir: 1,
  1788. div: 1,
  1789. dl: 1,
  1790. fieldset: 1,
  1791. form: 1,
  1792. h1: 1,
  1793. h2: 1,
  1794. h3: 1,
  1795. h4: 1,
  1796. h5: 1,
  1797. h6: 1,
  1798. hr: 1,
  1799. isindex: 1,
  1800. menu: 1,
  1801. noframes: 1,
  1802. ol: 1,
  1803. p: 1,
  1804. pre: 1,
  1805. table: 1,
  1806. ul: 1
  1807. }),
  1808. empty = _({
  1809. area: 1,
  1810. base: 1,
  1811. basefont: 1,
  1812. br: 1,
  1813. col: 1,
  1814. command: 1,
  1815. dialog: 1,
  1816. embed: 1,
  1817. hr: 1,
  1818. img: 1,
  1819. input: 1,
  1820. isindex: 1,
  1821. keygen: 1,
  1822. link: 1,
  1823. meta: 1,
  1824. param: 1,
  1825. source: 1,
  1826. track: 1,
  1827. wbr: 1
  1828. })
  1829. return _({
  1830. // $ 表示自定的属性
  1831. // body外的元素列表.
  1832. $nonBodyContent: X(V, U, S),
  1833. //块结构元素列表
  1834. $block: block,
  1835. //内联元素列表
  1836. $inline: L,
  1837. $inlineWithA: X(_({ a: 1 }), L),
  1838. $body: X(_({ script: 1, style: 1 }), block),
  1839. $cdata: _({ script: 1, style: 1 }),
  1840. //自闭和元素
  1841. $empty: empty,
  1842. //不是自闭合,但不能让range选中里边
  1843. $nonChild: _({ iframe: 1, textarea: 1 }),
  1844. //列表元素列表
  1845. $listItem: _({ dd: 1, dt: 1, li: 1 }),
  1846. //列表根元素列表
  1847. $list: _({ ul: 1, ol: 1, dl: 1 }),
  1848. //不能认为是空的元素
  1849. $isNotEmpty: _({
  1850. table: 1,
  1851. ul: 1,
  1852. ol: 1,
  1853. dl: 1,
  1854. iframe: 1,
  1855. area: 1,
  1856. base: 1,
  1857. col: 1,
  1858. hr: 1,
  1859. img: 1,
  1860. embed: 1,
  1861. input: 1,
  1862. link: 1,
  1863. meta: 1,
  1864. param: 1,
  1865. h1: 1,
  1866. h2: 1,
  1867. h3: 1,
  1868. h4: 1,
  1869. h5: 1,
  1870. h6: 1
  1871. }),
  1872. //如果没有子节点就可以删除的元素列表,像span,a
  1873. $removeEmpty: _({
  1874. a: 1,
  1875. abbr: 1,
  1876. acronym: 1,
  1877. address: 1,
  1878. b: 1,
  1879. bdo: 1,
  1880. big: 1,
  1881. cite: 1,
  1882. code: 1,
  1883. del: 1,
  1884. dfn: 1,
  1885. em: 1,
  1886. font: 1,
  1887. i: 1,
  1888. ins: 1,
  1889. label: 1,
  1890. kbd: 1,
  1891. q: 1,
  1892. s: 1,
  1893. samp: 1,
  1894. small: 1,
  1895. span: 1,
  1896. strike: 1,
  1897. strong: 1,
  1898. sub: 1,
  1899. sup: 1,
  1900. tt: 1,
  1901. u: 1,
  1902. var: 1
  1903. }),
  1904. $removeEmptyBlock: _({ p: 1, div: 1 }),
  1905. //在table元素里的元素列表
  1906. $tableContent: _({
  1907. caption: 1,
  1908. col: 1,
  1909. colgroup: 1,
  1910. tbody: 1,
  1911. td: 1,
  1912. tfoot: 1,
  1913. th: 1,
  1914. thead: 1,
  1915. tr: 1,
  1916. table: 1
  1917. }),
  1918. //不转换的标签
  1919. $notTransContent: _({ pre: 1, script: 1, style: 1, textarea: 1 }),
  1920. html: U,
  1921. head: T,
  1922. style: N,
  1923. script: N,
  1924. body: P,
  1925. base: {},
  1926. link: {},
  1927. meta: {},
  1928. title: N,
  1929. col: {},
  1930. tr: _({ td: 1, th: 1 }),
  1931. img: {},
  1932. embed: {},
  1933. colgroup: _({ thead: 1, col: 1, tbody: 1, tr: 1, tfoot: 1 }),
  1934. noscript: P,
  1935. td: P,
  1936. br: {},
  1937. th: P,
  1938. center: P,
  1939. kbd: L,
  1940. button: X(I, E),
  1941. basefont: {},
  1942. h5: L,
  1943. h4: L,
  1944. samp: L,
  1945. h6: L,
  1946. ol: Q,
  1947. h1: L,
  1948. h3: L,
  1949. option: N,
  1950. h2: L,
  1951. form: X(A, D, E, I),
  1952. select: _({ optgroup: 1, option: 1 }),
  1953. font: L,
  1954. ins: L,
  1955. menu: Q,
  1956. abbr: L,
  1957. label: L,
  1958. table: _({
  1959. thead: 1,
  1960. col: 1,
  1961. tbody: 1,
  1962. tr: 1,
  1963. colgroup: 1,
  1964. caption: 1,
  1965. tfoot: 1
  1966. }),
  1967. code: L,
  1968. tfoot: M,
  1969. cite: L,
  1970. li: P,
  1971. input: {},
  1972. iframe: P,
  1973. strong: L,
  1974. textarea: N,
  1975. noframes: P,
  1976. big: L,
  1977. small: L,
  1978. //trace:
  1979. span: _({
  1980. '#': 1,
  1981. br: 1,
  1982. b: 1,
  1983. strong: 1,
  1984. u: 1,
  1985. i: 1,
  1986. em: 1,
  1987. sub: 1,
  1988. sup: 1,
  1989. strike: 1,
  1990. span: 1
  1991. }),
  1992. hr: L,
  1993. dt: L,
  1994. sub: L,
  1995. optgroup: _({ option: 1 }),
  1996. param: {},
  1997. bdo: L,
  1998. var: L,
  1999. div: P,
  2000. object: O,
  2001. sup: L,
  2002. dd: P,
  2003. strike: L,
  2004. area: {},
  2005. dir: Q,
  2006. map: X(_({ area: 1, form: 1, p: 1 }), A, F, E),
  2007. applet: O,
  2008. dl: _({ dt: 1, dd: 1 }),
  2009. del: L,
  2010. isindex: {},
  2011. fieldset: X(_({ legend: 1 }), K),
  2012. thead: M,
  2013. ul: Q,
  2014. acronym: L,
  2015. b: L,
  2016. a: X(_({ a: 1 }), J),
  2017. blockquote: X(_({ td: 1, tr: 1, tbody: 1, li: 1 }), P),
  2018. caption: L,
  2019. i: L,
  2020. u: L,
  2021. tbody: M,
  2022. s: L,
  2023. address: X(D, I),
  2024. tt: L,
  2025. legend: L,
  2026. q: L,
  2027. pre: X(G, C),
  2028. p: X(_({ a: 1 }), L),
  2029. em: L,
  2030. dfn: L
  2031. })
  2032. })())
  2033. // core/domUtils.js
  2034. /**
  2035. * Dom操作工具包
  2036. * @file
  2037. * @module UE.dom.domUtils
  2038. * @since 1.2.6.1
  2039. */
  2040. /**
  2041. * Dom操作工具包
  2042. * @unfile
  2043. * @module UE.dom.domUtils
  2044. */
  2045. function getDomNode(node, start, ltr, startFromChild, fn, guard) {
  2046. var tmpNode = startFromChild && node[start],
  2047. parent
  2048. !tmpNode && (tmpNode = node[ltr])
  2049. while (!tmpNode && (parent = (parent || node).parentNode)) {
  2050. if (parent.tagName == 'BODY' || (guard && !guard(parent))) {
  2051. return null
  2052. }
  2053. tmpNode = parent[ltr]
  2054. }
  2055. if (tmpNode && fn && !fn(tmpNode)) {
  2056. return getDomNode(tmpNode, start, ltr, false, fn)
  2057. }
  2058. return tmpNode
  2059. }
  2060. var attrFix =
  2061. ie && browser.version < 9
  2062. ? {
  2063. tabindex: 'tabIndex',
  2064. readonly: 'readOnly',
  2065. for: 'htmlFor',
  2066. class: 'className',
  2067. maxlength: 'maxLength',
  2068. cellspacing: 'cellSpacing',
  2069. cellpadding: 'cellPadding',
  2070. rowspan: 'rowSpan',
  2071. colspan: 'colSpan',
  2072. usemap: 'useMap',
  2073. frameborder: 'frameBorder'
  2074. }
  2075. : {
  2076. tabindex: 'tabIndex',
  2077. readonly: 'readOnly'
  2078. },
  2079. styleBlock = utils.listToMap([
  2080. '-webkit-box',
  2081. '-moz-box',
  2082. 'block',
  2083. 'list-item',
  2084. 'table',
  2085. 'table-row-group',
  2086. 'table-header-group',
  2087. 'table-footer-group',
  2088. 'table-row',
  2089. 'table-column-group',
  2090. 'table-column',
  2091. 'table-cell',
  2092. 'table-caption'
  2093. ])
  2094. var domUtils = (dom.domUtils = {
  2095. //节点常量
  2096. NODE_ELEMENT: 1,
  2097. NODE_DOCUMENT: 9,
  2098. NODE_TEXT: 3,
  2099. NODE_COMMENT: 8,
  2100. NODE_DOCUMENT_FRAGMENT: 11,
  2101. //位置关系
  2102. POSITION_IDENTICAL: 0,
  2103. POSITION_DISCONNECTED: 1,
  2104. POSITION_FOLLOWING: 2,
  2105. POSITION_PRECEDING: 4,
  2106. POSITION_IS_CONTAINED: 8,
  2107. POSITION_CONTAINS: 16,
  2108. //ie6使用其他的会有一段空白出现
  2109. fillChar: ie && browser.version == '6' ? '\ufeff' : '\u200B',
  2110. //-------------------------Node部分--------------------------------
  2111. keys: {
  2112. /*Backspace*/ 8: 1,
  2113. /*Delete*/ 46: 1,
  2114. /*Shift*/ 16: 1,
  2115. /*Ctrl*/ 17: 1,
  2116. /*Alt*/ 18: 1,
  2117. 37: 1,
  2118. 38: 1,
  2119. 39: 1,
  2120. 40: 1,
  2121. 13: 1 /*enter*/
  2122. },
  2123. /**
  2124. * 获取节点A相对于节点B的位置关系
  2125. * @method getPosition
  2126. * @param { Node } nodeA 需要查询位置关系的节点A
  2127. * @param { Node } nodeB 需要查询位置关系的节点B
  2128. * @return { Number } 节点A与节点B的关系
  2129. * @example
  2130. * ```javascript
  2131. * //output: 20
  2132. * var position = UE.dom.domUtils.getPosition( document.documentElement, document.body );
  2133. *
  2134. * switch ( position ) {
  2135. *
  2136. * //0
  2137. * case UE.dom.domUtils.POSITION_IDENTICAL:
  2138. * console.log('元素相同');
  2139. * break;
  2140. * //1
  2141. * case UE.dom.domUtils.POSITION_DISCONNECTED:
  2142. * console.log('两个节点在不同的文档中');
  2143. * break;
  2144. * //2
  2145. * case UE.dom.domUtils.POSITION_FOLLOWING:
  2146. * console.log('节点A在节点B之后');
  2147. * break;
  2148. * //4
  2149. * case UE.dom.domUtils.POSITION_PRECEDING;
  2150. * console.log('节点A在节点B之前');
  2151. * break;
  2152. * //8
  2153. * case UE.dom.domUtils.POSITION_IS_CONTAINED:
  2154. * console.log('节点A被节点B包含');
  2155. * break;
  2156. * case 10:
  2157. * console.log('节点A被节点B包含且节点A在节点B之后');
  2158. * break;
  2159. * //16
  2160. * case UE.dom.domUtils.POSITION_CONTAINS:
  2161. * console.log('节点A包含节点B');
  2162. * break;
  2163. * case 20:
  2164. * console.log('节点A包含节点B且节点A在节点B之前');
  2165. * break;
  2166. *
  2167. * }
  2168. * ```
  2169. */
  2170. getPosition: function (nodeA, nodeB) {
  2171. // 如果两个节点是同一个节点
  2172. if (nodeA === nodeB) {
  2173. // domUtils.POSITION_IDENTICAL
  2174. return 0
  2175. }
  2176. var node,
  2177. parentsA = [nodeA],
  2178. parentsB = [nodeB]
  2179. node = nodeA
  2180. while ((node = node.parentNode)) {
  2181. // 如果nodeB是nodeA的祖先节点
  2182. if (node === nodeB) {
  2183. // domUtils.POSITION_IS_CONTAINED + domUtils.POSITION_FOLLOWING
  2184. return 10
  2185. }
  2186. parentsA.push(node)
  2187. }
  2188. node = nodeB
  2189. while ((node = node.parentNode)) {
  2190. // 如果nodeA是nodeB的祖先节点
  2191. if (node === nodeA) {
  2192. // domUtils.POSITION_CONTAINS + domUtils.POSITION_PRECEDING
  2193. return 20
  2194. }
  2195. parentsB.push(node)
  2196. }
  2197. parentsA.reverse()
  2198. parentsB.reverse()
  2199. if (parentsA[0] !== parentsB[0]) {
  2200. // domUtils.POSITION_DISCONNECTED
  2201. return 1
  2202. }
  2203. var i = -1
  2204. while ((i++, parentsA[i] === parentsB[i])) {}
  2205. nodeA = parentsA[i]
  2206. nodeB = parentsB[i]
  2207. while ((nodeA = nodeA.nextSibling)) {
  2208. if (nodeA === nodeB) {
  2209. // domUtils.POSITION_PRECEDING
  2210. return 4
  2211. }
  2212. }
  2213. // domUtils.POSITION_FOLLOWING
  2214. return 2
  2215. },
  2216. /**
  2217. * 检测节点node在父节点中的索引位置
  2218. * @method getNodeIndex
  2219. * @param { Node } node 需要检测的节点对象
  2220. * @return { Number } 该节点在父节点中的位置
  2221. * @see UE.dom.domUtils.getNodeIndex(Node,Boolean)
  2222. */
  2223. /**
  2224. * 检测节点node在父节点中的索引位置, 根据给定的mergeTextNode参数决定是否要合并多个连续的文本节点为一个节点
  2225. * @method getNodeIndex
  2226. * @param { Node } node 需要检测的节点对象
  2227. * @param { Boolean } mergeTextNode 是否合并多个连续的文本节点为一个节点
  2228. * @return { Number } 该节点在父节点中的位置
  2229. * @example
  2230. * ```javascript
  2231. *
  2232. * var node = document.createElement("div");
  2233. *
  2234. * node.appendChild( document.createTextNode( "hello" ) );
  2235. * node.appendChild( document.createTextNode( "world" ) );
  2236. * node.appendChild( node = document.createElement( "div" ) );
  2237. *
  2238. * //output: 2
  2239. * console.log( UE.dom.domUtils.getNodeIndex( node ) );
  2240. *
  2241. * //output: 1
  2242. * console.log( UE.dom.domUtils.getNodeIndex( node, true ) );
  2243. *
  2244. * ```
  2245. */
  2246. getNodeIndex: function (node, ignoreTextNode) {
  2247. var preNode = node,
  2248. i = 0
  2249. while ((preNode = preNode.previousSibling)) {
  2250. if (ignoreTextNode && preNode.nodeType == 3) {
  2251. if (preNode.nodeType != preNode.nextSibling.nodeType) {
  2252. i++
  2253. }
  2254. continue
  2255. }
  2256. i++
  2257. }
  2258. return i
  2259. },
  2260. /**
  2261. * 检测节点node是否在给定的document对象上
  2262. * @method inDoc
  2263. * @param { Node } node 需要检测的节点对象
  2264. * @param { DomDocument } doc 需要检测的document对象
  2265. * @return { Boolean } 该节点node是否在给定的document的dom树上
  2266. * @example
  2267. * ```javascript
  2268. *
  2269. * var node = document.createElement("div");
  2270. *
  2271. * //output: false
  2272. * console.log( UE.do.domUtils.inDoc( node, document ) );
  2273. *
  2274. * document.body.appendChild( node );
  2275. *
  2276. * //output: true
  2277. * console.log( UE.do.domUtils.inDoc( node, document ) );
  2278. *
  2279. * ```
  2280. */
  2281. inDoc: function (node, doc) {
  2282. return domUtils.getPosition(node, doc) == 10
  2283. },
  2284. /**
  2285. * 根据给定的过滤规则filterFn, 查找符合该过滤规则的node节点的第一个祖先节点,
  2286. * 查找的起点是给定node节点的父节点。
  2287. * @method findParent
  2288. * @param { Node } node 需要查找的节点
  2289. * @param { Function } filterFn 自定义的过滤方法。
  2290. * @warning 查找的终点是到body节点为止
  2291. * @remind 自定义的过滤方法filterFn接受一个Node对象作为参数, 该对象代表当前执行检测的祖先节点。 如果该
  2292. * 节点满足过滤条件, 则要求返回true, 这时将直接返回该节点作为findParent()的结果, 否则, 请返回false。
  2293. * @return { Node | Null } 如果找到符合过滤条件的节点, 就返回该节点, 否则返回NULL
  2294. * @example
  2295. * ```javascript
  2296. * var filterNode = UE.dom.domUtils.findParent( document.body.firstChild, function ( node ) {
  2297. *
  2298. * //由于查找的终点是body节点, 所以永远也不会匹配当前过滤器的条件, 即这里永远会返回false
  2299. * return node.tagName === "HTML";
  2300. *
  2301. * } );
  2302. *
  2303. * //output: true
  2304. * console.log( filterNode === null );
  2305. * ```
  2306. */
  2307. /**
  2308. * 根据给定的过滤规则filterFn, 查找符合该过滤规则的node节点的第一个祖先节点,
  2309. * 如果includeSelf的值为true,则查找的起点是给定的节点node, 否则, 起点是node的父节点
  2310. * @method findParent
  2311. * @param { Node } node 需要查找的节点
  2312. * @param { Function } filterFn 自定义的过滤方法。
  2313. * @param { Boolean } includeSelf 查找过程是否包含自身
  2314. * @warning 查找的终点是到body节点为止
  2315. * @remind 自定义的过滤方法filterFn接受一个Node对象作为参数, 该对象代表当前执行检测的祖先节点。 如果该
  2316. * 节点满足过滤条件, 则要求返回true, 这时将直接返回该节点作为findParent()的结果, 否则, 请返回false。
  2317. * @remind 如果includeSelf为true, 则过滤器第一次执行时的参数会是节点本身。
  2318. * 反之, 过滤器第一次执行时的参数将是该节点的父节点。
  2319. * @return { Node | Null } 如果找到符合过滤条件的节点, 就返回该节点, 否则返回NULL
  2320. * @example
  2321. * ```html
  2322. * <body>
  2323. *
  2324. * <div id="test">
  2325. * </div>
  2326. *
  2327. * <script type="text/javascript">
  2328. *
  2329. * //output: DIV, BODY
  2330. * var filterNode = UE.dom.domUtils.findParent( document.getElementById( "test" ), function ( node ) {
  2331. *
  2332. * console.log( node.tagName );
  2333. * return false;
  2334. *
  2335. * }, true );
  2336. *
  2337. * </script>
  2338. * </body>
  2339. * ```
  2340. */
  2341. findParent: function (node, filterFn, includeSelf) {
  2342. if (node && !domUtils.isBody(node)) {
  2343. node = includeSelf ? node : node.parentNode
  2344. while (node) {
  2345. if (!filterFn || filterFn(node) || domUtils.isBody(node)) {
  2346. return filterFn && !filterFn(node) && domUtils.isBody(node) ? null : node
  2347. }
  2348. node = node.parentNode
  2349. }
  2350. }
  2351. return null
  2352. },
  2353. /**
  2354. * 查找node的节点名为tagName的第一个祖先节点, 查找的起点是node节点的父节点。
  2355. * @method findParentByTagName
  2356. * @param { Node } node 需要查找的节点对象
  2357. * @param { Array } tagNames 需要查找的父节点的名称数组
  2358. * @warning 查找的终点是到body节点为止
  2359. * @return { Node | NULL } 如果找到符合条件的节点, 则返回该节点, 否则返回NULL
  2360. * @example
  2361. * ```javascript
  2362. * var node = UE.dom.domUtils.findParentByTagName( document.getElementsByTagName("div")[0], [ "BODY" ] );
  2363. * //output: BODY
  2364. * console.log( node.tagName );
  2365. * ```
  2366. */
  2367. /**
  2368. * 查找node的节点名为tagName的祖先节点, 如果includeSelf的值为true,则查找的起点是给定的节点node,
  2369. * 否则, 起点是node的父节点。
  2370. * @method findParentByTagName
  2371. * @param { Node } node 需要查找的节点对象
  2372. * @param { Array } tagNames 需要查找的父节点的名称数组
  2373. * @param { Boolean } includeSelf 查找过程是否包含node节点自身
  2374. * @warning 查找的终点是到body节点为止
  2375. * @return { Node | NULL } 如果找到符合条件的节点, 则返回该节点, 否则返回NULL
  2376. * @example
  2377. * ```javascript
  2378. * var queryTarget = document.getElementsByTagName("div")[0];
  2379. * var node = UE.dom.domUtils.findParentByTagName( queryTarget, [ "DIV" ], true );
  2380. * //output: true
  2381. * console.log( queryTarget === node );
  2382. * ```
  2383. */
  2384. findParentByTagName: function (node, tagNames, includeSelf, excludeFn) {
  2385. tagNames = utils.listToMap(utils.isArray(tagNames) ? tagNames : [tagNames])
  2386. return domUtils.findParent(
  2387. node,
  2388. function (node) {
  2389. return tagNames[node.tagName] && !(excludeFn && excludeFn(node))
  2390. },
  2391. includeSelf
  2392. )
  2393. },
  2394. /**
  2395. * 查找节点node的祖先节点集合, 查找的起点是给定节点的父节点,结果集中不包含给定的节点。
  2396. * @method findParents
  2397. * @param { Node } node 需要查找的节点对象
  2398. * @return { Array } 给定节点的祖先节点数组
  2399. * @grammar UE.dom.domUtils.findParents(node) => Array //返回一个祖先节点数组集合,不包含自身
  2400. * @grammar UE.dom.domUtils.findParents(node,includeSelf) => Array //返回一个祖先节点数组集合,includeSelf指定是否包含自身
  2401. * @grammar UE.dom.domUtils.findParents(node,includeSelf,filterFn) => Array //返回一个祖先节点数组集合,filterFn指定过滤条件,返回true的node将被选取
  2402. * @grammar UE.dom.domUtils.findParents(node,includeSelf,filterFn,closerFirst) => Array //返回一个祖先节点数组集合,closerFirst为true的话,node的直接父亲节点是数组的第0个
  2403. */
  2404. /**
  2405. * 查找节点node的祖先节点集合, 如果includeSelf的值为true,
  2406. * 则返回的结果集中允许出现当前给定的节点, 否则, 该节点不会出现在其结果集中。
  2407. * @method findParents
  2408. * @param { Node } node 需要查找的节点对象
  2409. * @param { Boolean } includeSelf 查找的结果中是否允许包含当前查找的节点对象
  2410. * @return { Array } 给定节点的祖先节点数组
  2411. */
  2412. findParents: function (node, includeSelf, filterFn, closerFirst) {
  2413. var parents = includeSelf && ((filterFn && filterFn(node)) || !filterFn) ? [node] : []
  2414. while ((node = domUtils.findParent(node, filterFn))) {
  2415. parents.push(node)
  2416. }
  2417. return closerFirst ? parents : parents.reverse()
  2418. },
  2419. /**
  2420. * 在节点node后面插入新节点newNode
  2421. * @method insertAfter
  2422. * @param { Node } node 目标节点
  2423. * @param { Node } newNode 新插入的节点, 该节点将置于目标节点之后
  2424. * @return { Node } 新插入的节点
  2425. */
  2426. insertAfter: function (node, newNode) {
  2427. return node.nextSibling
  2428. ? node.parentNode.insertBefore(newNode, node.nextSibling)
  2429. : node.parentNode.appendChild(newNode)
  2430. },
  2431. /**
  2432. * 删除节点node及其下属的所有节点
  2433. * @method remove
  2434. * @param { Node } node 需要删除的节点对象
  2435. * @return { Node } 返回刚删除的节点对象
  2436. * @example
  2437. * ```html
  2438. * <div id="test">
  2439. * <div id="child">你好</div>
  2440. * </div>
  2441. * <script>
  2442. * UE.dom.domUtils.remove( document.body, false );
  2443. * //output: false
  2444. * console.log( document.getElementById( "child" ) !== null );
  2445. * </script>
  2446. * ```
  2447. */
  2448. /**
  2449. * 删除节点node,并根据keepChildren的值决定是否保留子节点
  2450. * @method remove
  2451. * @param { Node } node 需要删除的节点对象
  2452. * @param { Boolean } keepChildren 是否需要保留子节点
  2453. * @return { Node } 返回刚删除的节点对象
  2454. * @example
  2455. * ```html
  2456. * <div id="test">
  2457. * <div id="child">你好</div>
  2458. * </div>
  2459. * <script>
  2460. * UE.dom.domUtils.remove( document.body, true );
  2461. * //output: true
  2462. * console.log( document.getElementById( "child" ) !== null );
  2463. * </script>
  2464. * ```
  2465. */
  2466. remove: function (node, keepChildren) {
  2467. var parent = node.parentNode,
  2468. child
  2469. if (parent) {
  2470. if (keepChildren && node.hasChildNodes()) {
  2471. while ((child = node.firstChild)) {
  2472. parent.insertBefore(child, node)
  2473. }
  2474. }
  2475. parent.removeChild(node)
  2476. }
  2477. return node
  2478. },
  2479. /**
  2480. * 取得node节点的下一个兄弟节点, 如果该节点其后没有兄弟节点, 则递归查找其父节点之后的第一个兄弟节点,
  2481. * 直到找到满足条件的节点或者递归到BODY节点之后才会结束。
  2482. * @method getNextDomNode
  2483. * @param { Node } node 需要获取其后的兄弟节点的节点对象
  2484. * @return { Node | NULL } 如果找满足条件的节点, 则返回该节点, 否则返回NULL
  2485. * @example
  2486. * ```html
  2487. * <body>
  2488. * <div id="test">
  2489. * <span></span>
  2490. * </div>
  2491. * <i>xxx</i>
  2492. * </body>
  2493. * <script>
  2494. *
  2495. * //output: i节点
  2496. * console.log( UE.dom.domUtils.getNextDomNode( document.getElementById( "test" ) ) );
  2497. *
  2498. * </script>
  2499. * ```
  2500. * @example
  2501. * ```html
  2502. * <body>
  2503. * <div>
  2504. * <span></span>
  2505. * <i id="test">xxx</i>
  2506. * </div>
  2507. * <b>xxx</b>
  2508. * </body>
  2509. * <script>
  2510. *
  2511. * //由于id为test的i节点之后没有兄弟节点, 则查找其父节点(div)后面的兄弟节点
  2512. * //output: b节点
  2513. * console.log( UE.dom.domUtils.getNextDomNode( document.getElementById( "test" ) ) );
  2514. *
  2515. * </script>
  2516. * ```
  2517. */
  2518. /**
  2519. * 取得node节点的下一个兄弟节点, 如果startFromChild的值为ture,则先获取其子节点,
  2520. * 如果有子节点则直接返回第一个子节点;如果没有子节点或者startFromChild的值为false,
  2521. * 则执行<a href="#UE.dom.domUtils.getNextDomNode(Node)">getNextDomNode(Node node)</a>的查找过程。
  2522. * @method getNextDomNode
  2523. * @param { Node } node 需要获取其后的兄弟节点的节点对象
  2524. * @param { Boolean } startFromChild 查找过程是否从其子节点开始
  2525. * @return { Node | NULL } 如果找满足条件的节点, 则返回该节点, 否则返回NULL
  2526. * @see UE.dom.domUtils.getNextDomNode(Node)
  2527. */
  2528. getNextDomNode: function (node, startFromChild, filterFn, guard) {
  2529. return getDomNode(node, 'firstChild', 'nextSibling', startFromChild, filterFn, guard)
  2530. },
  2531. getPreDomNode: function (node, startFromChild, filterFn, guard) {
  2532. return getDomNode(node, 'lastChild', 'previousSibling', startFromChild, filterFn, guard)
  2533. },
  2534. /**
  2535. * 检测节点node是否属是UEditor定义的bookmark节点
  2536. * @method isBookmarkNode
  2537. * @private
  2538. * @param { Node } node 需要检测的节点对象
  2539. * @return { Boolean } 是否是bookmark节点
  2540. * @example
  2541. * ```html
  2542. * <span id="_baidu_bookmark_1"></span>
  2543. * <script>
  2544. * var bookmarkNode = document.getElementById("_baidu_bookmark_1");
  2545. * //output: true
  2546. * console.log( UE.dom.domUtils.isBookmarkNode( bookmarkNode ) );
  2547. * </script>
  2548. * ```
  2549. */
  2550. isBookmarkNode: function (node) {
  2551. return node.nodeType == 1 && node.id && /^_baidu_bookmark_/i.test(node.id)
  2552. },
  2553. /**
  2554. * 获取节点node所属的window对象
  2555. * @method getWindow
  2556. * @param { Node } node 节点对象
  2557. * @return { Window } 当前节点所属的window对象
  2558. * @example
  2559. * ```javascript
  2560. * //output: true
  2561. * console.log( UE.dom.domUtils.getWindow( document.body ) === window );
  2562. * ```
  2563. */
  2564. getWindow: function (node) {
  2565. var doc = node.ownerDocument || node
  2566. return doc.defaultView || doc.parentWindow
  2567. },
  2568. /**
  2569. * 获取离nodeA与nodeB最近的公共的祖先节点
  2570. * @method getCommonAncestor
  2571. * @param { Node } nodeA 第一个节点
  2572. * @param { Node } nodeB 第二个节点
  2573. * @remind 如果给定的两个节点是同一个节点, 将直接返回该节点。
  2574. * @return { Node | NULL } 如果未找到公共节点, 返回NULL, 否则返回最近的公共祖先节点。
  2575. * @example
  2576. * ```javascript
  2577. * var commonAncestor = UE.dom.domUtils.getCommonAncestor( document.body, document.body.firstChild );
  2578. * //output: true
  2579. * console.log( commonAncestor.tagName.toLowerCase() === 'body' );
  2580. * ```
  2581. */
  2582. getCommonAncestor: function (nodeA, nodeB) {
  2583. if (nodeA === nodeB) return nodeA
  2584. var parentsA = [nodeA],
  2585. parentsB = [nodeB],
  2586. parent = nodeA,
  2587. i = -1
  2588. while ((parent = parent.parentNode)) {
  2589. if (parent === nodeB) {
  2590. return parent
  2591. }
  2592. parentsA.push(parent)
  2593. }
  2594. parent = nodeB
  2595. while ((parent = parent.parentNode)) {
  2596. if (parent === nodeA) return parent
  2597. parentsB.push(parent)
  2598. }
  2599. parentsA.reverse()
  2600. parentsB.reverse()
  2601. while ((i++, parentsA[i] === parentsB[i])) {}
  2602. return i == 0 ? null : parentsA[i - 1]
  2603. },
  2604. /**
  2605. * 清除node节点左右连续为空的兄弟inline节点
  2606. * @method clearEmptySibling
  2607. * @param { Node } node 执行的节点对象, 如果该节点的左右连续的兄弟节点是空的inline节点,
  2608. * 则这些兄弟节点将被删除
  2609. * @grammar UE.dom.domUtils.clearEmptySibling(node,ignoreNext) //ignoreNext指定是否忽略右边空节点
  2610. * @grammar UE.dom.domUtils.clearEmptySibling(node,ignoreNext,ignorePre) //ignorePre指定是否忽略左边空节点
  2611. * @example
  2612. * ```html
  2613. * <body>
  2614. * <div></div>
  2615. * <span id="test"></span>
  2616. * <i></i>
  2617. * <b></b>
  2618. * <em>xxx</em>
  2619. * <span></span>
  2620. * </body>
  2621. * <script>
  2622. *
  2623. * UE.dom.domUtils.clearEmptySibling( document.getElementById( "test" ) );
  2624. *
  2625. * //output: <div></div><span id="test"></span><em>xxx</em><span></span>
  2626. * console.log( document.body.innerHTML );
  2627. *
  2628. * </script>
  2629. * ```
  2630. */
  2631. /**
  2632. * 清除node节点左右连续为空的兄弟inline节点, 如果ignoreNext的值为true,
  2633. * 则忽略对右边兄弟节点的操作。
  2634. * @method clearEmptySibling
  2635. * @param { Node } node 执行的节点对象, 如果该节点的左右连续的兄弟节点是空的inline节点,
  2636. * @param { Boolean } ignoreNext 是否忽略忽略对右边的兄弟节点的操作
  2637. * 则这些兄弟节点将被删除
  2638. * @see UE.dom.domUtils.clearEmptySibling(Node)
  2639. */
  2640. /**
  2641. * 清除node节点左右连续为空的兄弟inline节点, 如果ignoreNext的值为true,
  2642. * 则忽略对右边兄弟节点的操作, 如果ignorePre的值为true,则忽略对左边兄弟节点的操作。
  2643. * @method clearEmptySibling
  2644. * @param { Node } node 执行的节点对象, 如果该节点的左右连续的兄弟节点是空的inline节点,
  2645. * @param { Boolean } ignoreNext 是否忽略忽略对右边的兄弟节点的操作
  2646. * @param { Boolean } ignorePre 是否忽略忽略对左边的兄弟节点的操作
  2647. * 则这些兄弟节点将被删除
  2648. * @see UE.dom.domUtils.clearEmptySibling(Node)
  2649. */
  2650. clearEmptySibling: function (node, ignoreNext, ignorePre) {
  2651. function clear(next, dir) {
  2652. var tmpNode
  2653. while (
  2654. next &&
  2655. !domUtils.isBookmarkNode(next) &&
  2656. (domUtils.isEmptyInlineElement(next) ||
  2657. //这里不能把空格算进来会吧空格干掉,出现文字间的空格丢掉了
  2658. !new RegExp('[^\t\n\r' + domUtils.fillChar + ']').test(next.nodeValue))
  2659. ) {
  2660. tmpNode = next[dir]
  2661. domUtils.remove(next)
  2662. next = tmpNode
  2663. }
  2664. }
  2665. !ignoreNext && clear(node.nextSibling, 'nextSibling')
  2666. !ignorePre && clear(node.previousSibling, 'previousSibling')
  2667. },
  2668. /**
  2669. * 将一个文本节点textNode拆分成两个文本节点,offset指定拆分位置
  2670. * @method split
  2671. * @param { Node } textNode 需要拆分的文本节点对象
  2672. * @param { int } offset 需要拆分的位置, 位置计算从0开始
  2673. * @return { Node } 拆分后形成的新节点
  2674. * @example
  2675. * ```html
  2676. * <div id="test">abcdef</div>
  2677. * <script>
  2678. * var newNode = UE.dom.domUtils.split( document.getElementById( "test" ).firstChild, 3 );
  2679. * //output: def
  2680. * console.log( newNode.nodeValue );
  2681. * </script>
  2682. * ```
  2683. */
  2684. split: function (node, offset) {
  2685. var doc = node.ownerDocument
  2686. if (browser.ie && offset == node.nodeValue.length) {
  2687. var next = doc.createTextNode('')
  2688. return domUtils.insertAfter(node, next)
  2689. }
  2690. var retval = node.splitText(offset)
  2691. //ie8下splitText不会跟新childNodes,我们手动触发他的更新
  2692. if (browser.ie8) {
  2693. var tmpNode = doc.createTextNode('')
  2694. domUtils.insertAfter(retval, tmpNode)
  2695. domUtils.remove(tmpNode)
  2696. }
  2697. return retval
  2698. },
  2699. /**
  2700. * 检测文本节点textNode是否为空节点(包括空格、换行、占位符等字符)
  2701. * @method isWhitespace
  2702. * @param { Node } node 需要检测的节点对象
  2703. * @return { Boolean } 检测的节点是否为空
  2704. * @example
  2705. * ```html
  2706. * <div id="test">
  2707. *
  2708. * </div>
  2709. * <script>
  2710. * //output: true
  2711. * console.log( UE.dom.domUtils.isWhitespace( document.getElementById("test").firstChild ) );
  2712. * </script>
  2713. * ```
  2714. */
  2715. isWhitespace: function (node) {
  2716. return !new RegExp('[^ \t\n\r' + domUtils.fillChar + ']').test(node.nodeValue)
  2717. },
  2718. /**
  2719. * 获取元素element相对于viewport的位置坐标
  2720. * @method getXY
  2721. * @param { Node } element 需要计算位置的节点对象
  2722. * @return { Object } 返回形如{x:left,y:top}的一个key-value映射对象, 其中键x代表水平偏移距离,
  2723. * y代表垂直偏移距离。
  2724. *
  2725. * @example
  2726. * ```javascript
  2727. * var location = UE.dom.domUtils.getXY( document.getElementById("test") );
  2728. * //output: test的坐标为: 12, 24
  2729. * console.log( 'test的坐标为: ', location.x, ',', location.y );
  2730. * ```
  2731. */
  2732. getXY: function (element) {
  2733. var x = 0,
  2734. y = 0
  2735. while (element.offsetParent) {
  2736. y += element.offsetTop
  2737. x += element.offsetLeft
  2738. element = element.offsetParent
  2739. }
  2740. return { x: x, y: y }
  2741. },
  2742. /**
  2743. * 为元素element绑定原生DOM事件,type为事件类型,handler为处理函数
  2744. * @method on
  2745. * @param { Node } element 需要绑定事件的节点对象
  2746. * @param { String } type 绑定的事件类型
  2747. * @param { Function } handler 事件处理器
  2748. * @example
  2749. * ```javascript
  2750. * UE.dom.domUtils.on(document.body,"click",function(e){
  2751. * //e为事件对象,this为被点击元素对戏那个
  2752. * });
  2753. * ```
  2754. */
  2755. /**
  2756. * 为元素element绑定原生DOM事件,type为事件类型,handler为处理函数
  2757. * @method on
  2758. * @param { Node } element 需要绑定事件的节点对象
  2759. * @param { Array } type 绑定的事件类型数组
  2760. * @param { Function } handler 事件处理器
  2761. * @example
  2762. * ```javascript
  2763. * UE.dom.domUtils.on(document.body,["click","mousedown"],function(evt){
  2764. * //evt为事件对象,this为被点击元素对象
  2765. * });
  2766. * ```
  2767. */
  2768. on: function (element, type, handler) {
  2769. var types = utils.isArray(type) ? type : utils.trim(type).split(/\s+/),
  2770. k = types.length
  2771. if (k)
  2772. while (k--) {
  2773. type = types[k]
  2774. if (element.addEventListener) {
  2775. element.addEventListener(type, handler, false)
  2776. } else {
  2777. if (!handler._d) {
  2778. handler._d = {
  2779. els: []
  2780. }
  2781. }
  2782. var key = type + handler.toString(),
  2783. index = utils.indexOf(handler._d.els, element)
  2784. if (!handler._d[key] || index == -1) {
  2785. if (index == -1) {
  2786. handler._d.els.push(element)
  2787. }
  2788. if (!handler._d[key]) {
  2789. handler._d[key] = function (evt) {
  2790. return handler.call(evt.srcElement, evt || window.event)
  2791. }
  2792. }
  2793. element.attachEvent('on' + type, handler._d[key])
  2794. }
  2795. }
  2796. }
  2797. element = null
  2798. },
  2799. /**
  2800. * 解除DOM事件绑定
  2801. * @method un
  2802. * @param { Node } element 需要解除事件绑定的节点对象
  2803. * @param { String } type 需要接触绑定的事件类型
  2804. * @param { Function } handler 对应的事件处理器
  2805. * @example
  2806. * ```javascript
  2807. * UE.dom.domUtils.un(document.body,"click",function(evt){
  2808. * //evt为事件对象,this为被点击元素对象
  2809. * });
  2810. * ```
  2811. */
  2812. /**
  2813. * 解除DOM事件绑定
  2814. * @method un
  2815. * @param { Node } element 需要解除事件绑定的节点对象
  2816. * @param { Array } type 需要接触绑定的事件类型数组
  2817. * @param { Function } handler 对应的事件处理器
  2818. * @example
  2819. * ```javascript
  2820. * UE.dom.domUtils.un(document.body, ["click","mousedown"],function(evt){
  2821. * //evt为事件对象,this为被点击元素对象
  2822. * });
  2823. * ```
  2824. */
  2825. un: function (element, type, handler) {
  2826. var types = utils.isArray(type) ? type : utils.trim(type).split(/\s+/),
  2827. k = types.length
  2828. if (k)
  2829. while (k--) {
  2830. type = types[k]
  2831. if (element && element.removeEventListener) {
  2832. element.removeEventListener(type, handler, false)
  2833. } else {
  2834. var key = type + handler.toString()
  2835. try {
  2836. element.detachEvent('on' + type, handler._d ? handler._d[key] : handler)
  2837. } catch (e) {}
  2838. if (handler._d && handler._d[key]) {
  2839. var index = utils.indexOf(handler._d.els, element)
  2840. if (index != -1) {
  2841. handler._d.els.splice(index, 1)
  2842. }
  2843. handler._d.els.length == 0 && delete handler._d[key]
  2844. }
  2845. }
  2846. }
  2847. },
  2848. /**
  2849. * 比较节点nodeA与节点nodeB是否具有相同的标签名、属性名以及属性值
  2850. * @method isSameElement
  2851. * @param { Node } nodeA 需要比较的节点
  2852. * @param { Node } nodeB 需要比较的节点
  2853. * @return { Boolean } 两个节点是否具有相同的标签名、属性名以及属性值
  2854. * @example
  2855. * ```html
  2856. * <span style="font-size:12px">ssss</span>
  2857. * <span style="font-size:12px">bbbbb</span>
  2858. * <span style="font-size:13px">ssss</span>
  2859. * <span style="font-size:14px">bbbbb</span>
  2860. *
  2861. * <script>
  2862. *
  2863. * var nodes = document.getElementsByTagName( "span" );
  2864. *
  2865. * //output: true
  2866. * console.log( UE.dom.domUtils.isSameElement( nodes[0], nodes[1] ) );
  2867. *
  2868. * //output: false
  2869. * console.log( UE.dom.domUtils.isSameElement( nodes[2], nodes[3] ) );
  2870. *
  2871. * </script>
  2872. * ```
  2873. */
  2874. isSameElement: function (nodeA, nodeB) {
  2875. if (nodeA.tagName != nodeB.tagName) {
  2876. return false
  2877. }
  2878. var thisAttrs = nodeA.attributes,
  2879. otherAttrs = nodeB.attributes
  2880. if (!ie && thisAttrs.length != otherAttrs.length) {
  2881. return false
  2882. }
  2883. var attrA,
  2884. attrB,
  2885. al = 0,
  2886. bl = 0
  2887. for (var i = 0; (attrA = thisAttrs[i++]); ) {
  2888. if (attrA.nodeName == 'style') {
  2889. if (attrA.specified) {
  2890. al++
  2891. }
  2892. if (domUtils.isSameStyle(nodeA, nodeB)) {
  2893. continue
  2894. } else {
  2895. return false
  2896. }
  2897. }
  2898. if (ie) {
  2899. if (attrA.specified) {
  2900. al++
  2901. attrB = otherAttrs.getNamedItem(attrA.nodeName)
  2902. } else {
  2903. continue
  2904. }
  2905. } else {
  2906. attrB = nodeB.attributes[attrA.nodeName]
  2907. }
  2908. if (!attrB.specified || attrA.nodeValue != attrB.nodeValue) {
  2909. return false
  2910. }
  2911. }
  2912. // 有可能attrB的属性包含了attrA的属性之外还有自己的属性
  2913. if (ie) {
  2914. for (i = 0; (attrB = otherAttrs[i++]); ) {
  2915. if (attrB.specified) {
  2916. bl++
  2917. }
  2918. }
  2919. if (al != bl) {
  2920. return false
  2921. }
  2922. }
  2923. return true
  2924. },
  2925. /**
  2926. * 判断节点nodeA与节点nodeB的元素的style属性是否一致
  2927. * @method isSameStyle
  2928. * @param { Node } nodeA 需要比较的节点
  2929. * @param { Node } nodeB 需要比较的节点
  2930. * @return { Boolean } 两个节点是否具有相同的style属性值
  2931. * @example
  2932. * ```html
  2933. * <span style="font-size:12px">ssss</span>
  2934. * <span style="font-size:12px">bbbbb</span>
  2935. * <span style="font-size:13px">ssss</span>
  2936. * <span style="font-size:14px">bbbbb</span>
  2937. *
  2938. * <script>
  2939. *
  2940. * var nodes = document.getElementsByTagName( "span" );
  2941. *
  2942. * //output: true
  2943. * console.log( UE.dom.domUtils.isSameStyle( nodes[0], nodes[1] ) );
  2944. *
  2945. * //output: false
  2946. * console.log( UE.dom.domUtils.isSameStyle( nodes[2], nodes[3] ) );
  2947. *
  2948. * </script>
  2949. * ```
  2950. */
  2951. isSameStyle: function (nodeA, nodeB) {
  2952. var styleA = nodeA.style.cssText.replace(/( ?; ?)/g, ';').replace(/( ?: ?)/g, ':'),
  2953. styleB = nodeB.style.cssText.replace(/( ?; ?)/g, ';').replace(/( ?: ?)/g, ':')
  2954. if (browser.opera) {
  2955. styleA = nodeA.style
  2956. styleB = nodeB.style
  2957. if (styleA.length != styleB.length) return false
  2958. for (var p in styleA) {
  2959. if (/^(\d+|csstext)$/i.test(p)) {
  2960. continue
  2961. }
  2962. if (styleA[p] != styleB[p]) {
  2963. return false
  2964. }
  2965. }
  2966. return true
  2967. }
  2968. if (!styleA || !styleB) {
  2969. return styleA == styleB
  2970. }
  2971. styleA = styleA.split(';')
  2972. styleB = styleB.split(';')
  2973. if (styleA.length != styleB.length) {
  2974. return false
  2975. }
  2976. for (var i = 0, ci; (ci = styleA[i++]); ) {
  2977. if (utils.indexOf(styleB, ci) == -1) {
  2978. return false
  2979. }
  2980. }
  2981. return true
  2982. },
  2983. /**
  2984. * 检查节点node是否为block元素
  2985. * @method isBlockElm
  2986. * @param { Node } node 需要检测的节点对象
  2987. * @return { Boolean } 是否是block元素节点
  2988. * @warning 该方法的判断规则如下: 如果该元素原本是block元素, 则不论该元素当前的css样式是什么都会返回true;
  2989. * 否则,检测该元素的css样式, 如果该元素当前是block元素, 则返回true。 其余情况下都返回false。
  2990. * @example
  2991. * ```html
  2992. * <span id="test1" style="display: block"></span>
  2993. * <span id="test2"></span>
  2994. * <div id="test3" style="display: inline"></div>
  2995. *
  2996. * <script>
  2997. *
  2998. * //output: true
  2999. * console.log( UE.dom.domUtils.isBlockElm( document.getElementById("test1") ) );
  3000. *
  3001. * //output: false
  3002. * console.log( UE.dom.domUtils.isBlockElm( document.getElementById("test2") ) );
  3003. *
  3004. * //output: true
  3005. * console.log( UE.dom.domUtils.isBlockElm( document.getElementById("test3") ) );
  3006. *
  3007. * </script>
  3008. * ```
  3009. */
  3010. isBlockElm: function (node) {
  3011. return (
  3012. node.nodeType == 1 &&
  3013. (dtd.$block[node.tagName] || styleBlock[domUtils.getComputedStyle(node, 'display')]) &&
  3014. !dtd.$nonChild[node.tagName]
  3015. )
  3016. },
  3017. /**
  3018. * 检测node节点是否为body节点
  3019. * @method isBody
  3020. * @param { Element } node 需要检测的dom元素
  3021. * @return { Boolean } 给定的元素是否是body元素
  3022. * @example
  3023. * ```javascript
  3024. * //output: true
  3025. * console.log( UE.dom.domUtils.isBody( document.body ) );
  3026. * ```
  3027. */
  3028. isBody: function (node) {
  3029. return node && node.nodeType == 1 && node.tagName.toLowerCase() == 'body'
  3030. },
  3031. /**
  3032. * 以node节点为分界,将该节点的指定祖先节点parent拆分成两个独立的节点,
  3033. * 拆分形成的两个节点之间是node节点
  3034. * @method breakParent
  3035. * @param { Node } node 作为分界的节点对象
  3036. * @param { Node } parent 该节点必须是node节点的祖先节点, 且是block节点。
  3037. * @return { Node } 给定的node分界节点
  3038. * @example
  3039. * ```javascript
  3040. *
  3041. * var node = document.createElement("span"),
  3042. * wrapNode = document.createElement( "div" ),
  3043. * parent = document.createElement("p");
  3044. *
  3045. * parent.appendChild( node );
  3046. * wrapNode.appendChild( parent );
  3047. *
  3048. * //拆分前
  3049. * //output: <p><span></span></p>
  3050. * console.log( wrapNode.innerHTML );
  3051. *
  3052. *
  3053. * UE.dom.domUtils.breakParent( node, parent );
  3054. * //拆分后
  3055. * //output: <p></p><span></span><p></p>
  3056. * console.log( wrapNode.innerHTML );
  3057. *
  3058. * ```
  3059. */
  3060. breakParent: function (node, parent) {
  3061. var tmpNode,
  3062. parentClone = node,
  3063. clone = node,
  3064. leftNodes,
  3065. rightNodes
  3066. do {
  3067. parentClone = parentClone.parentNode
  3068. if (leftNodes) {
  3069. tmpNode = parentClone.cloneNode(false)
  3070. tmpNode.appendChild(leftNodes)
  3071. leftNodes = tmpNode
  3072. tmpNode = parentClone.cloneNode(false)
  3073. tmpNode.appendChild(rightNodes)
  3074. rightNodes = tmpNode
  3075. } else {
  3076. leftNodes = parentClone.cloneNode(false)
  3077. rightNodes = leftNodes.cloneNode(false)
  3078. }
  3079. while ((tmpNode = clone.previousSibling)) {
  3080. leftNodes.insertBefore(tmpNode, leftNodes.firstChild)
  3081. }
  3082. while ((tmpNode = clone.nextSibling)) {
  3083. rightNodes.appendChild(tmpNode)
  3084. }
  3085. clone = parentClone
  3086. } while (parent !== parentClone)
  3087. tmpNode = parent.parentNode
  3088. tmpNode.insertBefore(leftNodes, parent)
  3089. tmpNode.insertBefore(rightNodes, parent)
  3090. tmpNode.insertBefore(node, rightNodes)
  3091. domUtils.remove(parent)
  3092. return node
  3093. },
  3094. /**
  3095. * 检查节点node是否是空inline节点
  3096. * @method isEmptyInlineElement
  3097. * @param { Node } node 需要检测的节点对象
  3098. * @return { Number } 如果给定的节点是空的inline节点, 则返回1, 否则返回0。
  3099. * @example
  3100. * ```html
  3101. * <b><i></i></b> => 1
  3102. * <b><i></i><u></u></b> => 1
  3103. * <b></b> => 1
  3104. * <b>xx<i></i></b> => 0
  3105. * ```
  3106. */
  3107. isEmptyInlineElement: function (node) {
  3108. if (node.nodeType != 1 || !dtd.$removeEmpty[node.tagName]) {
  3109. return 0
  3110. }
  3111. node = node.firstChild
  3112. while (node) {
  3113. //如果是创建的bookmark就跳过
  3114. if (domUtils.isBookmarkNode(node)) {
  3115. return 0
  3116. }
  3117. if (
  3118. (node.nodeType == 1 && !domUtils.isEmptyInlineElement(node)) ||
  3119. (node.nodeType == 3 && !domUtils.isWhitespace(node))
  3120. ) {
  3121. return 0
  3122. }
  3123. node = node.nextSibling
  3124. }
  3125. return 1
  3126. },
  3127. /**
  3128. * 删除node节点下首尾两端的空白文本子节点
  3129. * @method trimWhiteTextNode
  3130. * @param { Element } node 需要执行删除操作的元素对象
  3131. * @example
  3132. * ```javascript
  3133. * var node = document.createElement("div");
  3134. *
  3135. * node.appendChild( document.createTextNode( "" ) );
  3136. *
  3137. * node.appendChild( document.createElement("div") );
  3138. *
  3139. * node.appendChild( document.createTextNode( "" ) );
  3140. *
  3141. * //3
  3142. * console.log( node.childNodes.length );
  3143. *
  3144. * UE.dom.domUtils.trimWhiteTextNode( node );
  3145. *
  3146. * //1
  3147. * console.log( node.childNodes.length );
  3148. * ```
  3149. */
  3150. trimWhiteTextNode: function (node) {
  3151. function remove(dir) {
  3152. var child
  3153. while ((child = node[dir]) && child.nodeType == 3 && domUtils.isWhitespace(child)) {
  3154. node.removeChild(child)
  3155. }
  3156. }
  3157. remove('firstChild')
  3158. remove('lastChild')
  3159. },
  3160. /**
  3161. * 合并node节点下相同的子节点
  3162. * @name mergeChild
  3163. * @desc
  3164. * UE.dom.domUtils.mergeChild(node,tagName) //tagName要合并的子节点的标签
  3165. * @example
  3166. * <p><span style="font-size:12px;">xx<span style="font-size:12px;">aa</span>xx</span></p>
  3167. * ==> UE.dom.domUtils.mergeChild(node,'span')
  3168. * <p><span style="font-size:12px;">xxaaxx</span></p>
  3169. */
  3170. mergeChild: function (node, tagName, attrs) {
  3171. var list = domUtils.getElementsByTagName(node, node.tagName.toLowerCase())
  3172. for (var i = 0, ci; (ci = list[i++]); ) {
  3173. if (!ci.parentNode || domUtils.isBookmarkNode(ci)) {
  3174. continue
  3175. }
  3176. //span单独处理
  3177. if (ci.tagName.toLowerCase() == 'span') {
  3178. if (node === ci.parentNode) {
  3179. domUtils.trimWhiteTextNode(node)
  3180. if (node.childNodes.length == 1) {
  3181. node.style.cssText = ci.style.cssText + ';' + node.style.cssText
  3182. domUtils.remove(ci, true)
  3183. continue
  3184. }
  3185. }
  3186. ci.style.cssText = node.style.cssText + ';' + ci.style.cssText
  3187. if (attrs) {
  3188. var style = attrs.style
  3189. if (style) {
  3190. style = style.split(';')
  3191. for (var j = 0, s; (s = style[j++]); ) {
  3192. ci.style[utils.cssStyleToDomStyle(s.split(':')[0])] = s.split(':')[1]
  3193. }
  3194. }
  3195. }
  3196. if (domUtils.isSameStyle(ci, node)) {
  3197. domUtils.remove(ci, true)
  3198. }
  3199. continue
  3200. }
  3201. if (domUtils.isSameElement(node, ci)) {
  3202. domUtils.remove(ci, true)
  3203. }
  3204. }
  3205. },
  3206. /**
  3207. * 原生方法getElementsByTagName的封装
  3208. * @method getElementsByTagName
  3209. * @param { Node } node 目标节点对象
  3210. * @param { String } tagName 需要查找的节点的tagName, 多个tagName以空格分割
  3211. * @return { Array } 符合条件的节点集合
  3212. */
  3213. getElementsByTagName: function (node, name, filter) {
  3214. if (filter && utils.isString(filter)) {
  3215. var className = filter
  3216. filter = function (node) {
  3217. return domUtils.hasClass(node, className)
  3218. }
  3219. }
  3220. name = utils
  3221. .trim(name)
  3222. .replace(/[ ]{2,}/g, ' ')
  3223. .split(' ')
  3224. var arr = []
  3225. for (var n = 0, ni; (ni = name[n++]); ) {
  3226. var list = node.getElementsByTagName(ni)
  3227. for (var i = 0, ci; (ci = list[i++]); ) {
  3228. if (!filter || filter(ci)) arr.push(ci)
  3229. }
  3230. }
  3231. return arr
  3232. },
  3233. /**
  3234. * 将节点node提取到父节点上
  3235. * @method mergeToParent
  3236. * @param { Element } node 需要提取的元素对象
  3237. * @example
  3238. * ```html
  3239. * <div id="parent">
  3240. * <div id="sub">
  3241. * <span id="child"></span>
  3242. * </div>
  3243. * </div>
  3244. *
  3245. * <script>
  3246. *
  3247. * var child = document.getElementById( "child" );
  3248. *
  3249. * //output: sub
  3250. * console.log( child.parentNode.id );
  3251. *
  3252. * UE.dom.domUtils.mergeToParent( child );
  3253. *
  3254. * //output: parent
  3255. * console.log( child.parentNode.id );
  3256. *
  3257. * </script>
  3258. * ```
  3259. */
  3260. mergeToParent: function (node) {
  3261. var parent = node.parentNode
  3262. while (parent && dtd.$removeEmpty[parent.tagName]) {
  3263. if (parent.tagName == node.tagName || parent.tagName == 'A') {
  3264. //针对a标签单独处理
  3265. domUtils.trimWhiteTextNode(parent)
  3266. //span需要特殊处理 不处理这样的情况 <span stlye="color:#fff">xxx<span style="color:#ccc">xxx</span>xxx</span>
  3267. if (
  3268. (parent.tagName == 'SPAN' && !domUtils.isSameStyle(parent, node)) ||
  3269. (parent.tagName == 'A' && node.tagName == 'SPAN')
  3270. ) {
  3271. if (parent.childNodes.length > 1 || parent !== node.parentNode) {
  3272. node.style.cssText = parent.style.cssText + ';' + node.style.cssText
  3273. parent = parent.parentNode
  3274. continue
  3275. } else {
  3276. parent.style.cssText += ';' + node.style.cssText
  3277. //trace:952 a标签要保持下划线
  3278. if (parent.tagName == 'A') {
  3279. parent.style.textDecoration = 'underline'
  3280. }
  3281. }
  3282. }
  3283. if (parent.tagName != 'A') {
  3284. parent === node.parentNode && domUtils.remove(node, true)
  3285. break
  3286. }
  3287. }
  3288. parent = parent.parentNode
  3289. }
  3290. },
  3291. /**
  3292. * 合并节点node的左右兄弟节点
  3293. * @method mergeSibling
  3294. * @param { Element } node 需要合并的目标节点
  3295. * @example
  3296. * ```html
  3297. * <b>xxxx</b><b id="test">ooo</b><b>xxxx</b>
  3298. *
  3299. * <script>
  3300. * var demoNode = document.getElementById("test");
  3301. * UE.dom.domUtils.mergeSibling( demoNode );
  3302. * //output: xxxxoooxxxx
  3303. * console.log( demoNode.innerHTML );
  3304. * </script>
  3305. * ```
  3306. */
  3307. /**
  3308. * 合并节点node的左右兄弟节点, 可以根据给定的条件选择是否忽略合并左节点。
  3309. * @method mergeSibling
  3310. * @param { Element } node 需要合并的目标节点
  3311. * @param { Boolean } ignorePre 是否忽略合并左节点
  3312. * @example
  3313. * ```html
  3314. * <b>xxxx</b><b id="test">ooo</b><b>xxxx</b>
  3315. *
  3316. * <script>
  3317. * var demoNode = document.getElementById("test");
  3318. * UE.dom.domUtils.mergeSibling( demoNode, true );
  3319. * //output: oooxxxx
  3320. * console.log( demoNode.innerHTML );
  3321. * </script>
  3322. * ```
  3323. */
  3324. /**
  3325. * 合并节点node的左右兄弟节点,可以根据给定的条件选择是否忽略合并左右节点。
  3326. * @method mergeSibling
  3327. * @param { Element } node 需要合并的目标节点
  3328. * @param { Boolean } ignorePre 是否忽略合并左节点
  3329. * @param { Boolean } ignoreNext 是否忽略合并右节点
  3330. * @remind 如果同时忽略左右节点, 则该操作什么也不会做
  3331. * @example
  3332. * ```html
  3333. * <b>xxxx</b><b id="test">ooo</b><b>xxxx</b>
  3334. *
  3335. * <script>
  3336. * var demoNode = document.getElementById("test");
  3337. * UE.dom.domUtils.mergeSibling( demoNode, false, true );
  3338. * //output: xxxxooo
  3339. * console.log( demoNode.innerHTML );
  3340. * </script>
  3341. * ```
  3342. */
  3343. mergeSibling: function (node, ignorePre, ignoreNext) {
  3344. function merge(rtl, start, node) {
  3345. var next
  3346. if (
  3347. (next = node[rtl]) &&
  3348. !domUtils.isBookmarkNode(next) &&
  3349. next.nodeType == 1 &&
  3350. domUtils.isSameElement(node, next)
  3351. ) {
  3352. while (next.firstChild) {
  3353. if (start == 'firstChild') {
  3354. node.insertBefore(next.lastChild, node.firstChild)
  3355. } else {
  3356. node.appendChild(next.firstChild)
  3357. }
  3358. }
  3359. domUtils.remove(next)
  3360. }
  3361. }
  3362. !ignorePre && merge('previousSibling', 'firstChild', node)
  3363. !ignoreNext && merge('nextSibling', 'lastChild', node)
  3364. },
  3365. /**
  3366. * 设置节点node及其子节点不会被选中
  3367. * @method unSelectable
  3368. * @param { Element } node 需要执行操作的dom元素
  3369. * @remind 执行该操作后的节点, 将不能被鼠标选中
  3370. * @example
  3371. * ```javascript
  3372. * UE.dom.domUtils.unSelectable( document.body );
  3373. * ```
  3374. */
  3375. unSelectable:
  3376. (ie && browser.ie9below) || browser.opera
  3377. ? function (node) {
  3378. //for ie9
  3379. node.onselectstart = function () {
  3380. return false
  3381. }
  3382. node.onclick =
  3383. node.onkeyup =
  3384. node.onkeydown =
  3385. function () {
  3386. return false
  3387. }
  3388. node.unselectable = 'on'
  3389. node.setAttribute('unselectable', 'on')
  3390. for (var i = 0, ci; (ci = node.all[i++]); ) {
  3391. switch (ci.tagName.toLowerCase()) {
  3392. case 'iframe':
  3393. case 'textarea':
  3394. case 'input':
  3395. case 'select':
  3396. break
  3397. default:
  3398. ci.unselectable = 'on'
  3399. node.setAttribute('unselectable', 'on')
  3400. }
  3401. }
  3402. }
  3403. : function (node) {
  3404. node.style.MozUserSelect =
  3405. node.style.webkitUserSelect =
  3406. node.style.msUserSelect =
  3407. node.style.KhtmlUserSelect =
  3408. 'none'
  3409. },
  3410. /**
  3411. * 删除节点node上的指定属性名称的属性
  3412. * @method removeAttributes
  3413. * @param { Node } node 需要删除属性的节点对象
  3414. * @param { String } attrNames 可以是空格隔开的多个属性名称,该操作将会依次删除相应的属性
  3415. * @example
  3416. * ```html
  3417. * <div id="wrap">
  3418. * <span style="font-size:14px;" id="test" name="followMe">xxxxx</span>
  3419. * </div>
  3420. *
  3421. * <script>
  3422. *
  3423. * UE.dom.domUtils.removeAttributes( document.getElementById( "test" ), "id name" );
  3424. *
  3425. * //output: <span style="font-size:14px;">xxxxx</span>
  3426. * console.log( document.getElementById("wrap").innerHTML );
  3427. *
  3428. * </script>
  3429. * ```
  3430. */
  3431. /**
  3432. * 删除节点node上的指定属性名称的属性
  3433. * @method removeAttributes
  3434. * @param { Node } node 需要删除属性的节点对象
  3435. * @param { Array } attrNames 需要删除的属性名数组
  3436. * @example
  3437. * ```html
  3438. * <div id="wrap">
  3439. * <span style="font-size:14px;" id="test" name="followMe">xxxxx</span>
  3440. * </div>
  3441. *
  3442. * <script>
  3443. *
  3444. * UE.dom.domUtils.removeAttributes( document.getElementById( "test" ), ["id", "name"] );
  3445. *
  3446. * //output: <span style="font-size:14px;">xxxxx</span>
  3447. * console.log( document.getElementById("wrap").innerHTML );
  3448. *
  3449. * </script>
  3450. * ```
  3451. */
  3452. removeAttributes: function (node, attrNames) {
  3453. attrNames = utils.isArray(attrNames)
  3454. ? attrNames
  3455. : utils
  3456. .trim(attrNames)
  3457. .replace(/[ ]{2,}/g, ' ')
  3458. .split(' ')
  3459. for (var i = 0, ci; (ci = attrNames[i++]); ) {
  3460. ci = attrFix[ci] || ci
  3461. switch (ci) {
  3462. case 'className':
  3463. node[ci] = ''
  3464. break
  3465. case 'style':
  3466. node.style.cssText = ''
  3467. var val = node.getAttributeNode('style')
  3468. !browser.ie && val && node.removeAttributeNode(val)
  3469. }
  3470. node.removeAttribute(ci)
  3471. }
  3472. },
  3473. /**
  3474. * 在doc下创建一个标签名为tag,属性为attrs的元素
  3475. * @method createElement
  3476. * @param { DomDocument } doc 新创建的元素属于该document节点创建
  3477. * @param { String } tagName 需要创建的元素的标签名
  3478. * @param { Object } attrs 新创建的元素的属性key-value集合
  3479. * @return { Element } 新创建的元素对象
  3480. * @example
  3481. * ```javascript
  3482. * var ele = UE.dom.domUtils.createElement( document, 'div', {
  3483. * id: 'test'
  3484. * } );
  3485. *
  3486. * //output: DIV
  3487. * console.log( ele.tagName );
  3488. *
  3489. * //output: test
  3490. * console.log( ele.id );
  3491. *
  3492. * ```
  3493. */
  3494. createElement: function (doc, tag, attrs) {
  3495. return domUtils.setAttributes(doc.createElement(tag), attrs)
  3496. },
  3497. /**
  3498. * 为节点node添加属性attrs,attrs为属性键值对
  3499. * @method setAttributes
  3500. * @param { Element } node 需要设置属性的元素对象
  3501. * @param { Object } attrs 需要设置的属性名-值对
  3502. * @return { Element } 设置属性的元素对象
  3503. * @example
  3504. * ```html
  3505. * <span id="test"></span>
  3506. *
  3507. * <script>
  3508. *
  3509. * var testNode = UE.dom.domUtils.setAttributes( document.getElementById( "test" ), {
  3510. * id: 'demo'
  3511. * } );
  3512. *
  3513. * //output: demo
  3514. * console.log( testNode.id );
  3515. *
  3516. * </script>
  3517. *
  3518. */
  3519. setAttributes: function (node, attrs) {
  3520. for (var attr in attrs) {
  3521. if (attrs.hasOwnProperty(attr)) {
  3522. var value = attrs[attr]
  3523. switch (attr) {
  3524. case 'class':
  3525. //ie下要这样赋值,setAttribute不起作用
  3526. node.className = value
  3527. break
  3528. case 'style':
  3529. node.style.cssText = node.style.cssText + ';' + value
  3530. break
  3531. case 'innerHTML':
  3532. node[attr] = value
  3533. break
  3534. case 'value':
  3535. node.value = value
  3536. break
  3537. default:
  3538. node.setAttribute(attrFix[attr] || attr, value)
  3539. }
  3540. }
  3541. }
  3542. return node
  3543. },
  3544. /**
  3545. * 获取元素element经过计算后的样式值
  3546. * @method getComputedStyle
  3547. * @param { Element } element 需要获取样式的元素对象
  3548. * @param { String } styleName 需要获取的样式名
  3549. * @return { String } 获取到的样式值
  3550. * @example
  3551. * ```html
  3552. * <style type="text/css">
  3553. * #test {
  3554. * font-size: 15px;
  3555. * }
  3556. * </style>
  3557. *
  3558. * <span id="test"></span>
  3559. *
  3560. * <script>
  3561. * //output: 15px
  3562. * console.log( UE.dom.domUtils.getComputedStyle( document.getElementById( "test" ), 'font-size' ) );
  3563. * </script>
  3564. * ```
  3565. */
  3566. getComputedStyle: function (element, styleName) {
  3567. //一下的属性单独处理
  3568. var pros = 'width height top left'
  3569. if (pros.indexOf(styleName) > -1) {
  3570. return (
  3571. element[
  3572. 'offset' +
  3573. styleName.replace(/^\w/, function (s) {
  3574. return s.toUpperCase()
  3575. })
  3576. ] + 'px'
  3577. )
  3578. }
  3579. //忽略文本节点
  3580. if (element.nodeType == 3) {
  3581. element = element.parentNode
  3582. }
  3583. //ie下font-size若body下定义了font-size,则从currentStyle里会取到这个font-size. 取不到实际值,故此修改.
  3584. if (
  3585. browser.ie &&
  3586. browser.version < 9 &&
  3587. styleName == 'font-size' &&
  3588. !element.style.fontSize &&
  3589. !dtd.$empty[element.tagName] &&
  3590. !dtd.$nonChild[element.tagName]
  3591. ) {
  3592. var span = element.ownerDocument.createElement('span')
  3593. span.style.cssText = 'padding:0;border:0;font-family:simsun;'
  3594. span.innerHTML = '.'
  3595. element.appendChild(span)
  3596. var result = span.offsetHeight
  3597. element.removeChild(span)
  3598. span = null
  3599. return result + 'px'
  3600. }
  3601. try {
  3602. var value =
  3603. domUtils.getStyle(element, styleName) ||
  3604. (window.getComputedStyle
  3605. ? domUtils.getWindow(element).getComputedStyle(element, '').getPropertyValue(styleName)
  3606. : (element.currentStyle || element.style)[utils.cssStyleToDomStyle(styleName)])
  3607. } catch (e) {
  3608. return ''
  3609. }
  3610. return utils.transUnitToPx(utils.fixColor(styleName, value))
  3611. },
  3612. /**
  3613. * 删除元素element指定的className
  3614. * @method removeClasses
  3615. * @param { Element } ele 需要删除class的元素节点
  3616. * @param { String } classNames 需要删除的className, 多个className之间以空格分开
  3617. * @example
  3618. * ```html
  3619. * <span id="test" class="test1 test2 test3">xxx</span>
  3620. *
  3621. * <script>
  3622. *
  3623. * var testNode = document.getElementById( "test" );
  3624. * UE.dom.domUtils.removeClasses( testNode, "test1 test2" );
  3625. *
  3626. * //output: test3
  3627. * console.log( testNode.className );
  3628. *
  3629. * </script>
  3630. * ```
  3631. */
  3632. /**
  3633. * 删除元素element指定的className
  3634. * @method removeClasses
  3635. * @param { Element } ele 需要删除class的元素节点
  3636. * @param { Array } classNames 需要删除的className数组
  3637. * @example
  3638. * ```html
  3639. * <span id="test" class="test1 test2 test3">xxx</span>
  3640. *
  3641. * <script>
  3642. *
  3643. * var testNode = document.getElementById( "test" );
  3644. * UE.dom.domUtils.removeClasses( testNode, ["test1", "test2"] );
  3645. *
  3646. * //output: test3
  3647. * console.log( testNode.className );
  3648. *
  3649. * </script>
  3650. * ```
  3651. */
  3652. removeClasses: function (elm, classNames) {
  3653. classNames = utils.isArray(classNames)
  3654. ? classNames
  3655. : utils
  3656. .trim(classNames)
  3657. .replace(/[ ]{2,}/g, ' ')
  3658. .split(' ')
  3659. for (var i = 0, ci, cls = elm.className; (ci = classNames[i++]); ) {
  3660. cls = cls.replace(new RegExp('\\b' + ci + '\\b'), '')
  3661. }
  3662. cls = utils.trim(cls).replace(/[ ]{2,}/g, ' ')
  3663. if (cls) {
  3664. elm.className = cls
  3665. } else {
  3666. domUtils.removeAttributes(elm, ['class'])
  3667. }
  3668. },
  3669. /**
  3670. * 给元素element添加className
  3671. * @method addClass
  3672. * @param { Node } ele 需要增加className的元素
  3673. * @param { String } classNames 需要添加的className, 多个className之间以空格分割
  3674. * @remind 相同的类名不会被重复添加
  3675. * @example
  3676. * ```html
  3677. * <span id="test" class="cls1 cls2"></span>
  3678. *
  3679. * <script>
  3680. * var testNode = document.getElementById("test");
  3681. *
  3682. * UE.dom.domUtils.addClass( testNode, "cls2 cls3 cls4" );
  3683. *
  3684. * //output: cl1 cls2 cls3 cls4
  3685. * console.log( testNode.className );
  3686. *
  3687. * <script>
  3688. * ```
  3689. */
  3690. /**
  3691. * 给元素element添加className
  3692. * @method addClass
  3693. * @param { Node } ele 需要增加className的元素
  3694. * @param { Array } classNames 需要添加的className的数组
  3695. * @remind 相同的类名不会被重复添加
  3696. * @example
  3697. * ```html
  3698. * <span id="test" class="cls1 cls2"></span>
  3699. *
  3700. * <script>
  3701. * var testNode = document.getElementById("test");
  3702. *
  3703. * UE.dom.domUtils.addClass( testNode, ["cls2", "cls3", "cls4"] );
  3704. *
  3705. * //output: cl1 cls2 cls3 cls4
  3706. * console.log( testNode.className );
  3707. *
  3708. * <script>
  3709. * ```
  3710. */
  3711. addClass: function (elm, classNames) {
  3712. if (!elm) return
  3713. classNames = utils
  3714. .trim(classNames)
  3715. .replace(/[ ]{2,}/g, ' ')
  3716. .split(' ')
  3717. for (var i = 0, ci, cls = elm.className; (ci = classNames[i++]); ) {
  3718. if (!new RegExp('\\b' + ci + '\\b').test(cls)) {
  3719. cls += ' ' + ci
  3720. }
  3721. }
  3722. elm.className = utils.trim(cls)
  3723. },
  3724. /**
  3725. * 判断元素element是否包含给定的样式类名className
  3726. * @method hasClass
  3727. * @param { Node } ele 需要检测的元素
  3728. * @param { String } classNames 需要检测的className, 多个className之间用空格分割
  3729. * @return { Boolean } 元素是否包含所有给定的className
  3730. * @example
  3731. * ```html
  3732. * <span id="test1" class="cls1 cls2"></span>
  3733. *
  3734. * <script>
  3735. * var test1 = document.getElementById("test1");
  3736. *
  3737. * //output: false
  3738. * console.log( UE.dom.domUtils.hasClass( test1, "cls2 cls1 cls3" ) );
  3739. *
  3740. * //output: true
  3741. * console.log( UE.dom.domUtils.hasClass( test1, "cls2 cls1" ) );
  3742. * </script>
  3743. * ```
  3744. */
  3745. /**
  3746. * 判断元素element是否包含给定的样式类名className
  3747. * @method hasClass
  3748. * @param { Node } ele 需要检测的元素
  3749. * @param { Array } classNames 需要检测的className数组
  3750. * @return { Boolean } 元素是否包含所有给定的className
  3751. * @example
  3752. * ```html
  3753. * <span id="test1" class="cls1 cls2"></span>
  3754. *
  3755. * <script>
  3756. * var test1 = document.getElementById("test1");
  3757. *
  3758. * //output: false
  3759. * console.log( UE.dom.domUtils.hasClass( test1, [ "cls2", "cls1", "cls3" ] ) );
  3760. *
  3761. * //output: true
  3762. * console.log( UE.dom.domUtils.hasClass( test1, [ "cls2", "cls1" ]) );
  3763. * </script>
  3764. * ```
  3765. */
  3766. hasClass: function (element, className) {
  3767. if (utils.isRegExp(className)) {
  3768. return className.test(element.className)
  3769. }
  3770. className = utils
  3771. .trim(className)
  3772. .replace(/[ ]{2,}/g, ' ')
  3773. .split(' ')
  3774. for (var i = 0, ci, cls = element.className; (ci = className[i++]); ) {
  3775. if (!new RegExp('\\b' + ci + '\\b', 'i').test(cls)) {
  3776. return false
  3777. }
  3778. }
  3779. return i - 1 == className.length
  3780. },
  3781. /**
  3782. * 阻止事件默认行为
  3783. * @method preventDefault
  3784. * @param { Event } evt 需要阻止默认行为的事件对象
  3785. * @example
  3786. * ```javascript
  3787. * UE.dom.domUtils.preventDefault( evt );
  3788. * ```
  3789. */
  3790. preventDefault: function (evt) {
  3791. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false)
  3792. },
  3793. /**
  3794. * 删除元素element指定的样式
  3795. * @method removeStyle
  3796. * @param { Element } element 需要删除样式的元素
  3797. * @param { String } styleName 需要删除的样式名
  3798. * @example
  3799. * ```html
  3800. * <span id="test" style="color: red; background: blue;"></span>
  3801. *
  3802. * <script>
  3803. *
  3804. * var testNode = document.getElementById("test");
  3805. *
  3806. * UE.dom.domUtils.removeStyle( testNode, 'color' );
  3807. *
  3808. * //output: background: blue;
  3809. * console.log( testNode.style.cssText );
  3810. *
  3811. * </script>
  3812. * ```
  3813. */
  3814. removeStyle: function (element, name) {
  3815. if (browser.ie) {
  3816. //针对color先单独处理一下
  3817. if (name == 'color') {
  3818. name = '(^|;)' + name
  3819. }
  3820. element.style.cssText = element.style.cssText.replace(
  3821. new RegExp(name + '[^:]*:[^;]+;?', 'ig'),
  3822. ''
  3823. )
  3824. } else {
  3825. if (element.style.removeProperty) {
  3826. element.style.removeProperty(name)
  3827. } else {
  3828. element.style.removeAttribute(utils.cssStyleToDomStyle(name))
  3829. }
  3830. }
  3831. if (!element.style.cssText) {
  3832. domUtils.removeAttributes(element, ['style'])
  3833. }
  3834. },
  3835. /**
  3836. * 获取元素element的style属性的指定值
  3837. * @method getStyle
  3838. * @param { Element } element 需要获取属性值的元素
  3839. * @param { String } styleName 需要获取的style的名称
  3840. * @warning 该方法仅获取元素style属性中所标明的值
  3841. * @return { String } 该元素包含指定的style属性值
  3842. * @example
  3843. * ```html
  3844. * <div id="test" style="color: red;"></div>
  3845. *
  3846. * <script>
  3847. *
  3848. * var testNode = document.getElementById( "test" );
  3849. *
  3850. * //output: red
  3851. * console.log( UE.dom.domUtils.getStyle( testNode, "color" ) );
  3852. *
  3853. * //output: ""
  3854. * console.log( UE.dom.domUtils.getStyle( testNode, "background" ) );
  3855. *
  3856. * </script>
  3857. * ```
  3858. */
  3859. getStyle: function (element, name) {
  3860. var value = element.style[utils.cssStyleToDomStyle(name)]
  3861. return utils.fixColor(name, value)
  3862. },
  3863. /**
  3864. * 为元素element设置样式属性值
  3865. * @method setStyle
  3866. * @param { Element } element 需要设置样式的元素
  3867. * @param { String } styleName 样式名
  3868. * @param { String } styleValue 样式值
  3869. * @example
  3870. * ```html
  3871. * <div id="test"></div>
  3872. *
  3873. * <script>
  3874. *
  3875. * var testNode = document.getElementById( "test" );
  3876. *
  3877. * //output: ""
  3878. * console.log( testNode.style.color );
  3879. *
  3880. * UE.dom.domUtils.setStyle( testNode, 'color', 'red' );
  3881. * //output: "red"
  3882. * console.log( testNode.style.color );
  3883. *
  3884. * </script>
  3885. * ```
  3886. */
  3887. setStyle: function (element, name, value) {
  3888. element.style[utils.cssStyleToDomStyle(name)] = value
  3889. if (!utils.trim(element.style.cssText)) {
  3890. this.removeAttributes(element, 'style')
  3891. }
  3892. },
  3893. /**
  3894. * 为元素element设置多个样式属性值
  3895. * @method setStyles
  3896. * @param { Element } element 需要设置样式的元素
  3897. * @param { Object } styles 样式名值对
  3898. * @example
  3899. * ```html
  3900. * <div id="test"></div>
  3901. *
  3902. * <script>
  3903. *
  3904. * var testNode = document.getElementById( "test" );
  3905. *
  3906. * //output: ""
  3907. * console.log( testNode.style.color );
  3908. *
  3909. * UE.dom.domUtils.setStyles( testNode, {
  3910. * 'color': 'red'
  3911. * } );
  3912. * //output: "red"
  3913. * console.log( testNode.style.color );
  3914. *
  3915. * </script>
  3916. * ```
  3917. */
  3918. setStyles: function (element, styles) {
  3919. for (var name in styles) {
  3920. if (styles.hasOwnProperty(name)) {
  3921. domUtils.setStyle(element, name, styles[name])
  3922. }
  3923. }
  3924. },
  3925. /**
  3926. * 删除_moz_dirty属性
  3927. * @private
  3928. * @method removeDirtyAttr
  3929. */
  3930. removeDirtyAttr: function (node) {
  3931. for (var i = 0, ci, nodes = node.getElementsByTagName('*'); (ci = nodes[i++]); ) {
  3932. ci.removeAttribute('_moz_dirty')
  3933. }
  3934. node.removeAttribute('_moz_dirty')
  3935. },
  3936. /**
  3937. * 获取子节点的数量
  3938. * @method getChildCount
  3939. * @param { Element } node 需要检测的元素
  3940. * @return { Number } 给定的node元素的子节点数量
  3941. * @example
  3942. * ```html
  3943. * <div id="test">
  3944. * <span></span>
  3945. * </div>
  3946. *
  3947. * <script>
  3948. *
  3949. * //output: 3
  3950. * console.log( UE.dom.domUtils.getChildCount( document.getElementById("test") ) );
  3951. *
  3952. * </script>
  3953. * ```
  3954. */
  3955. /**
  3956. * 根据给定的过滤规则, 获取符合条件的子节点的数量
  3957. * @method getChildCount
  3958. * @param { Element } node 需要检测的元素
  3959. * @param { Function } fn 过滤器, 要求对符合条件的子节点返回true, 反之则要求返回false
  3960. * @return { Number } 符合过滤条件的node元素的子节点数量
  3961. * @example
  3962. * ```html
  3963. * <div id="test">
  3964. * <span></span>
  3965. * </div>
  3966. *
  3967. * <script>
  3968. *
  3969. * //output: 1
  3970. * console.log( UE.dom.domUtils.getChildCount( document.getElementById("test"), function ( node ) {
  3971. *
  3972. * return node.nodeType === 1;
  3973. *
  3974. * } ) );
  3975. *
  3976. * </script>
  3977. * ```
  3978. */
  3979. getChildCount: function (node, fn) {
  3980. var count = 0,
  3981. first = node.firstChild
  3982. fn =
  3983. fn ||
  3984. function () {
  3985. return 1
  3986. }
  3987. while (first) {
  3988. if (fn(first)) {
  3989. count++
  3990. }
  3991. first = first.nextSibling
  3992. }
  3993. return count
  3994. },
  3995. /**
  3996. * 判断给定节点是否为空节点
  3997. * @method isEmptyNode
  3998. * @param { Node } node 需要检测的节点对象
  3999. * @return { Boolean } 节点是否为空
  4000. * @example
  4001. * ```javascript
  4002. * UE.dom.domUtils.isEmptyNode( document.body );
  4003. * ```
  4004. */
  4005. isEmptyNode: function (node) {
  4006. return (
  4007. !node.firstChild ||
  4008. domUtils.getChildCount(node, function (node) {
  4009. return (
  4010. !domUtils.isBr(node) && !domUtils.isBookmarkNode(node) && !domUtils.isWhitespace(node)
  4011. )
  4012. }) == 0
  4013. )
  4014. },
  4015. clearSelectedArr: function (nodes) {
  4016. var node
  4017. while ((node = nodes.pop())) {
  4018. domUtils.removeAttributes(node, ['class'])
  4019. }
  4020. },
  4021. /**
  4022. * 将显示区域滚动到指定节点的位置
  4023. * @method scrollToView
  4024. * @param {Node} node 节点
  4025. * @param {window} win window对象
  4026. * @param {Number} offsetTop 距离上方的偏移量
  4027. */
  4028. scrollToView: function (node, win, offsetTop) {
  4029. var getViewPaneSize = function () {
  4030. var doc = win.document,
  4031. mode = doc.compatMode == 'CSS1Compat'
  4032. return {
  4033. width: (mode ? doc.documentElement.clientWidth : doc.body.clientWidth) || 0,
  4034. height: (mode ? doc.documentElement.clientHeight : doc.body.clientHeight) || 0
  4035. }
  4036. },
  4037. getScrollPosition = function (win) {
  4038. if ('pageXOffset' in win) {
  4039. return {
  4040. x: win.pageXOffset || 0,
  4041. y: win.pageYOffset || 0
  4042. }
  4043. } else {
  4044. var doc = win.document
  4045. return {
  4046. x: doc.documentElement.scrollLeft || doc.body.scrollLeft || 0,
  4047. y: doc.documentElement.scrollTop || doc.body.scrollTop || 0
  4048. }
  4049. }
  4050. }
  4051. var winHeight = getViewPaneSize().height,
  4052. offset = winHeight * -1 + offsetTop
  4053. offset += node.offsetHeight || 0
  4054. var elementPosition = domUtils.getXY(node)
  4055. offset += elementPosition.y
  4056. var currentScroll = getScrollPosition(win).y
  4057. // offset += 50;
  4058. if (offset > currentScroll || offset < currentScroll - winHeight) {
  4059. win.scrollTo(0, offset + (offset < 0 ? -20 : 20))
  4060. }
  4061. },
  4062. /**
  4063. * 判断给定节点是否为br
  4064. * @method isBr
  4065. * @param { Node } node 需要判断的节点对象
  4066. * @return { Boolean } 给定的节点是否是br节点
  4067. */
  4068. isBr: function (node) {
  4069. return node.nodeType == 1 && node.tagName == 'BR'
  4070. },
  4071. /**
  4072. * 判断给定的节点是否是一个“填充”节点
  4073. * @private
  4074. * @method isFillChar
  4075. * @param { Node } node 需要判断的节点
  4076. * @param { Boolean } isInStart 是否从节点内容的开始位置匹配
  4077. * @returns { Boolean } 节点是否是填充节点
  4078. */
  4079. isFillChar: function (node, isInStart) {
  4080. if (node.nodeType != 3) return false
  4081. var text = node.nodeValue
  4082. if (isInStart) {
  4083. return new RegExp('^' + domUtils.fillChar).test(text)
  4084. }
  4085. return !text.replace(new RegExp(domUtils.fillChar, 'g'), '').length
  4086. },
  4087. isStartInblock: function (range) {
  4088. var tmpRange = range.cloneRange(),
  4089. flag = 0,
  4090. start = tmpRange.startContainer,
  4091. tmp
  4092. if (start.nodeType == 1 && start.childNodes[tmpRange.startOffset]) {
  4093. start = start.childNodes[tmpRange.startOffset]
  4094. var pre = start.previousSibling
  4095. while (pre && domUtils.isFillChar(pre)) {
  4096. start = pre
  4097. pre = pre.previousSibling
  4098. }
  4099. }
  4100. if (this.isFillChar(start, true) && tmpRange.startOffset == 1) {
  4101. tmpRange.setStartBefore(start)
  4102. start = tmpRange.startContainer
  4103. }
  4104. while (start && domUtils.isFillChar(start)) {
  4105. tmp = start
  4106. start = start.previousSibling
  4107. }
  4108. if (tmp) {
  4109. tmpRange.setStartBefore(tmp)
  4110. start = tmpRange.startContainer
  4111. }
  4112. if (start.nodeType == 1 && domUtils.isEmptyNode(start) && tmpRange.startOffset == 1) {
  4113. tmpRange.setStart(start, 0).collapse(true)
  4114. }
  4115. while (!tmpRange.startOffset) {
  4116. start = tmpRange.startContainer
  4117. if (domUtils.isBlockElm(start) || domUtils.isBody(start)) {
  4118. flag = 1
  4119. break
  4120. }
  4121. var pre = tmpRange.startContainer.previousSibling,
  4122. tmpNode
  4123. if (!pre) {
  4124. tmpRange.setStartBefore(tmpRange.startContainer)
  4125. } else {
  4126. while (pre && domUtils.isFillChar(pre)) {
  4127. tmpNode = pre
  4128. pre = pre.previousSibling
  4129. }
  4130. if (tmpNode) {
  4131. tmpRange.setStartBefore(tmpNode)
  4132. } else {
  4133. tmpRange.setStartBefore(tmpRange.startContainer)
  4134. }
  4135. }
  4136. }
  4137. return flag && !domUtils.isBody(tmpRange.startContainer) ? 1 : 0
  4138. },
  4139. /**
  4140. * 判断给定的元素是否是一个空元素
  4141. * @method isEmptyBlock
  4142. * @param { Element } node 需要判断的元素
  4143. * @return { Boolean } 是否是空元素
  4144. * @example
  4145. * ```html
  4146. * <div id="test"></div>
  4147. *
  4148. * <script>
  4149. * //output: true
  4150. * console.log( UE.dom.domUtils.isEmptyBlock( document.getElementById("test") ) );
  4151. * </script>
  4152. * ```
  4153. */
  4154. /**
  4155. * 根据指定的判断规则判断给定的元素是否是一个空元素
  4156. * @method isEmptyBlock
  4157. * @param { Element } node 需要判断的元素
  4158. * @param { RegExp } reg 对内容执行判断的正则表达式对象
  4159. * @return { Boolean } 是否是空元素
  4160. */
  4161. isEmptyBlock: function (node, reg) {
  4162. // HaoChuan9421
  4163. if (!node) {
  4164. return
  4165. }
  4166. if (node.nodeType != 1) return 0
  4167. reg = reg || new RegExp('[ \xa0\t\r\n' + domUtils.fillChar + ']', 'g')
  4168. if (node[browser.ie ? 'innerText' : 'textContent'].replace(reg, '').length > 0) {
  4169. return 0
  4170. }
  4171. for (var n in dtd.$isNotEmpty) {
  4172. if (node.getElementsByTagName(n).length) {
  4173. return 0
  4174. }
  4175. }
  4176. return 1
  4177. },
  4178. /**
  4179. * 移动元素使得该元素的位置移动指定的偏移量的距离
  4180. * @method setViewportOffset
  4181. * @param { Element } element 需要设置偏移量的元素
  4182. * @param { Object } offset 偏移量, 形如{ left: 100, top: 50 }的一个键值对, 表示该元素将在
  4183. * 现有的位置上向水平方向偏移offset.left的距离, 在竖直方向上偏移
  4184. * offset.top的距离
  4185. * @example
  4186. * ```html
  4187. * <div id="test" style="top: 100px; left: 50px; position: absolute;"></div>
  4188. *
  4189. * <script>
  4190. *
  4191. * var testNode = document.getElementById("test");
  4192. *
  4193. * UE.dom.domUtils.setViewportOffset( testNode, {
  4194. * left: 200,
  4195. * top: 50
  4196. * } );
  4197. *
  4198. * //output: top: 300px; left: 100px; position: absolute;
  4199. * console.log( testNode.style.cssText );
  4200. *
  4201. * </script>
  4202. * ```
  4203. */
  4204. setViewportOffset: function (element, offset) {
  4205. var left = parseInt(element.style.left) | 0
  4206. var top = parseInt(element.style.top) | 0
  4207. var rect = element.getBoundingClientRect()
  4208. var offsetLeft = offset.left - rect.left
  4209. var offsetTop = offset.top - rect.top
  4210. if (offsetLeft) {
  4211. element.style.left = left + offsetLeft + 'px'
  4212. }
  4213. if (offsetTop) {
  4214. element.style.top = top + offsetTop + 'px'
  4215. }
  4216. },
  4217. /**
  4218. * 用“填充字符”填充节点
  4219. * @method fillNode
  4220. * @private
  4221. * @param { DomDocument } doc 填充的节点所在的docment对象
  4222. * @param { Node } node 需要填充的节点对象
  4223. * @example
  4224. * ```html
  4225. * <div id="test"></div>
  4226. *
  4227. * <script>
  4228. * var testNode = document.getElementById("test");
  4229. *
  4230. * //output: 0
  4231. * console.log( testNode.childNodes.length );
  4232. *
  4233. * UE.dom.domUtils.fillNode( document, testNode );
  4234. *
  4235. * //output: 1
  4236. * console.log( testNode.childNodes.length );
  4237. *
  4238. * </script>
  4239. * ```
  4240. */
  4241. fillNode: function (doc, node) {
  4242. var tmpNode = browser.ie ? doc.createTextNode(domUtils.fillChar) : doc.createElement('br')
  4243. node.innerHTML = ''
  4244. node.appendChild(tmpNode)
  4245. },
  4246. /**
  4247. * 把节点src的所有子节点追加到另一个节点tag上去
  4248. * @method moveChild
  4249. * @param { Node } src 源节点, 该节点下的所有子节点将被移除
  4250. * @param { Node } tag 目标节点, 从源节点移除的子节点将被追加到该节点下
  4251. * @example
  4252. * ```html
  4253. * <div id="test1">
  4254. * <span></span>
  4255. * </div>
  4256. * <div id="test2">
  4257. * <div></div>
  4258. * </div>
  4259. *
  4260. * <script>
  4261. *
  4262. * var test1 = document.getElementById("test1"),
  4263. * test2 = document.getElementById("test2");
  4264. *
  4265. * UE.dom.domUtils.moveChild( test1, test2 );
  4266. *
  4267. * //output: ""(空字符串)
  4268. * console.log( test1.innerHTML );
  4269. *
  4270. * //output: "<div></div><span></span>"
  4271. * console.log( test2.innerHTML );
  4272. *
  4273. * </script>
  4274. * ```
  4275. */
  4276. /**
  4277. * 把节点src的所有子节点移动到另一个节点tag上去, 可以通过dir参数控制附加的行为是“追加”还是“插入顶部”
  4278. * @method moveChild
  4279. * @param { Node } src 源节点, 该节点下的所有子节点将被移除
  4280. * @param { Node } tag 目标节点, 从源节点移除的子节点将被附加到该节点下
  4281. * @param { Boolean } dir 附加方式, 如果为true, 则附加进去的节点将被放到目标节点的顶部, 反之,则放到末尾
  4282. * @example
  4283. * ```html
  4284. * <div id="test1">
  4285. * <span></span>
  4286. * </div>
  4287. * <div id="test2">
  4288. * <div></div>
  4289. * </div>
  4290. *
  4291. * <script>
  4292. *
  4293. * var test1 = document.getElementById("test1"),
  4294. * test2 = document.getElementById("test2");
  4295. *
  4296. * UE.dom.domUtils.moveChild( test1, test2, true );
  4297. *
  4298. * //output: ""(空字符串)
  4299. * console.log( test1.innerHTML );
  4300. *
  4301. * //output: "<span></span><div></div>"
  4302. * console.log( test2.innerHTML );
  4303. *
  4304. * </script>
  4305. * ```
  4306. */
  4307. moveChild: function (src, tag, dir) {
  4308. while (src.firstChild) {
  4309. if (dir && tag.firstChild) {
  4310. tag.insertBefore(src.lastChild, tag.firstChild)
  4311. } else {
  4312. tag.appendChild(src.firstChild)
  4313. }
  4314. }
  4315. },
  4316. /**
  4317. * 判断节点的标签上是否不存在任何属性
  4318. * @method hasNoAttributes
  4319. * @private
  4320. * @param { Node } node 需要检测的节点对象
  4321. * @return { Boolean } 节点是否不包含任何属性
  4322. * @example
  4323. * ```html
  4324. * <div id="test"><span>xxxx</span></div>
  4325. *
  4326. * <script>
  4327. *
  4328. * //output: false
  4329. * console.log( UE.dom.domUtils.hasNoAttributes( document.getElementById("test") ) );
  4330. *
  4331. * //output: true
  4332. * console.log( UE.dom.domUtils.hasNoAttributes( document.getElementById("test").firstChild ) );
  4333. *
  4334. * </script>
  4335. * ```
  4336. */
  4337. hasNoAttributes: function (node) {
  4338. return browser.ie ? /^<\w+\s*?>/.test(node.outerHTML) : node.attributes.length == 0
  4339. },
  4340. /**
  4341. * 检测节点是否是UEditor所使用的辅助节点
  4342. * @method isCustomeNode
  4343. * @private
  4344. * @param { Node } node 需要检测的节点
  4345. * @remind 辅助节点是指编辑器要完成工作临时添加的节点, 在输出的时候将会从编辑器内移除, 不会影响最终的结果。
  4346. * @return { Boolean } 给定的节点是否是一个辅助节点
  4347. */
  4348. isCustomeNode: function (node) {
  4349. return node.nodeType == 1 && node.getAttribute('_ue_custom_node_')
  4350. },
  4351. /**
  4352. * 检测节点的标签是否是给定的标签
  4353. * @method isTagNode
  4354. * @param { Node } node 需要检测的节点对象
  4355. * @param { String } tagName 标签
  4356. * @return { Boolean } 节点的标签是否是给定的标签
  4357. * @example
  4358. * ```html
  4359. * <div id="test"></div>
  4360. *
  4361. * <script>
  4362. *
  4363. * //output: true
  4364. * console.log( UE.dom.domUtils.isTagNode( document.getElementById("test"), "div" ) );
  4365. *
  4366. * </script>
  4367. * ```
  4368. */
  4369. isTagNode: function (node, tagNames) {
  4370. return node.nodeType == 1 && new RegExp('\\b' + node.tagName + '\\b', 'i').test(tagNames)
  4371. },
  4372. /**
  4373. * 给定一个节点数组,在通过指定的过滤器过滤后, 获取其中满足过滤条件的第一个节点
  4374. * @method filterNodeList
  4375. * @param { Array } nodeList 需要过滤的节点数组
  4376. * @param { Function } fn 过滤器, 对符合条件的节点, 执行结果返回true, 反之则返回false
  4377. * @return { Node | NULL } 如果找到符合过滤条件的节点, 则返回该节点, 否则返回NULL
  4378. * @example
  4379. * ```javascript
  4380. * var divNodes = document.getElementsByTagName("div");
  4381. * divNodes = [].slice.call( divNodes, 0 );
  4382. *
  4383. * //output: null
  4384. * console.log( UE.dom.domUtils.filterNodeList( divNodes, function ( node ) {
  4385. * return node.tagName.toLowerCase() !== 'div';
  4386. * } ) );
  4387. * ```
  4388. */
  4389. /**
  4390. * 给定一个节点数组nodeList和一组标签名tagNames, 获取其中能够匹配标签名的节点集合中的第一个节点
  4391. * @method filterNodeList
  4392. * @param { Array } nodeList 需要过滤的节点数组
  4393. * @param { String } tagNames 需要匹配的标签名, 多个标签名之间用空格分割
  4394. * @return { Node | NULL } 如果找到标签名匹配的节点, 则返回该节点, 否则返回NULL
  4395. * @example
  4396. * ```javascript
  4397. * var divNodes = document.getElementsByTagName("div");
  4398. * divNodes = [].slice.call( divNodes, 0 );
  4399. *
  4400. * //output: null
  4401. * console.log( UE.dom.domUtils.filterNodeList( divNodes, 'a span' ) );
  4402. * ```
  4403. */
  4404. /**
  4405. * 给定一个节点数组,在通过指定的过滤器过滤后, 如果参数forAll为true, 则会返回所有满足过滤
  4406. * 条件的节点集合, 否则, 返回满足条件的节点集合中的第一个节点
  4407. * @method filterNodeList
  4408. * @param { Array } nodeList 需要过滤的节点数组
  4409. * @param { Function } fn 过滤器, 对符合条件的节点, 执行结果返回true, 反之则返回false
  4410. * @param { Boolean } forAll 是否返回整个节点数组, 如果该参数为false, 则返回节点集合中的第一个节点
  4411. * @return { Array | Node | NULL } 如果找到符合过滤条件的节点, 则根据参数forAll的值决定返回满足
  4412. * 过滤条件的节点数组或第一个节点, 否则返回NULL
  4413. * @example
  4414. * ```javascript
  4415. * var divNodes = document.getElementsByTagName("div");
  4416. * divNodes = [].slice.call( divNodes, 0 );
  4417. *
  4418. * //output: 3(假定有3个div)
  4419. * console.log( divNodes.length );
  4420. *
  4421. * var nodes = UE.dom.domUtils.filterNodeList( divNodes, function ( node ) {
  4422. * return node.tagName.toLowerCase() === 'div';
  4423. * }, true );
  4424. *
  4425. * //output: 3
  4426. * console.log( nodes.length );
  4427. *
  4428. * var node = UE.dom.domUtils.filterNodeList( divNodes, function ( node ) {
  4429. * return node.tagName.toLowerCase() === 'div';
  4430. * }, false );
  4431. *
  4432. * //output: div
  4433. * console.log( node.nodeName );
  4434. * ```
  4435. */
  4436. filterNodeList: function (nodelist, filter, forAll) {
  4437. var results = []
  4438. if (!utils.isFunction(filter)) {
  4439. var str = filter
  4440. filter = function (n) {
  4441. return (
  4442. utils.indexOf(utils.isArray(str) ? str : str.split(' '), n.tagName.toLowerCase()) != -1
  4443. )
  4444. }
  4445. }
  4446. utils.each(nodelist, function (n) {
  4447. filter(n) && results.push(n)
  4448. })
  4449. return results.length == 0 ? null : results.length == 1 || !forAll ? results[0] : results
  4450. },
  4451. /**
  4452. * 查询给定的range选区是否在给定的node节点内,且在该节点的最末尾
  4453. * @method isInNodeEndBoundary
  4454. * @param { UE.dom.Range } rng 需要判断的range对象, 该对象的startContainer不能为NULL
  4455. * @param node 需要检测的节点对象
  4456. * @return { Number } 如果给定的选取range对象是在node内部的最末端, 则返回1, 否则返回0
  4457. */
  4458. isInNodeEndBoundary: function (rng, node) {
  4459. var start = rng.startContainer
  4460. if (start.nodeType == 3 && rng.startOffset != start.nodeValue.length) {
  4461. return 0
  4462. }
  4463. if (start.nodeType == 1 && rng.startOffset != start.childNodes.length) {
  4464. return 0
  4465. }
  4466. while (start !== node) {
  4467. if (start.nextSibling) {
  4468. return 0
  4469. }
  4470. start = start.parentNode
  4471. }
  4472. return 1
  4473. },
  4474. isBoundaryNode: function (node, dir) {
  4475. var tmp
  4476. while (!domUtils.isBody(node)) {
  4477. tmp = node
  4478. node = node.parentNode
  4479. if (tmp !== node[dir]) {
  4480. return false
  4481. }
  4482. }
  4483. return true
  4484. },
  4485. fillHtml: browser.ie11below ? '&nbsp;' : '<br/>'
  4486. })
  4487. var fillCharReg = new RegExp(domUtils.fillChar, 'g')
  4488. // core/Range.js
  4489. /**
  4490. * Range封装
  4491. * @file
  4492. * @module UE.dom
  4493. * @class Range
  4494. * @since 1.2.6.1
  4495. */
  4496. /**
  4497. * dom操作封装
  4498. * @unfile
  4499. * @module UE.dom
  4500. */
  4501. /**
  4502. * Range实现类,本类是UEditor底层核心类,封装不同浏览器之间的Range操作。
  4503. * @unfile
  4504. * @module UE.dom
  4505. * @class Range
  4506. */
  4507. ;(function () {
  4508. var guid = 0,
  4509. fillChar = domUtils.fillChar,
  4510. fillData
  4511. /**
  4512. * 更新range的collapse状态
  4513. * @param {Range} range range对象
  4514. */
  4515. function updateCollapse(range) {
  4516. range.collapsed =
  4517. range.startContainer &&
  4518. range.endContainer &&
  4519. range.startContainer === range.endContainer &&
  4520. range.startOffset == range.endOffset
  4521. }
  4522. function selectOneNode(rng) {
  4523. return (
  4524. !rng.collapsed &&
  4525. rng.startContainer.nodeType == 1 &&
  4526. rng.startContainer === rng.endContainer &&
  4527. rng.endOffset - rng.startOffset == 1
  4528. )
  4529. }
  4530. function setEndPoint(toStart, node, offset, range) {
  4531. //如果node是自闭合标签要处理
  4532. if (node.nodeType == 1 && (dtd.$empty[node.tagName] || dtd.$nonChild[node.tagName])) {
  4533. offset = domUtils.getNodeIndex(node) + (toStart ? 0 : 1)
  4534. node = node.parentNode
  4535. }
  4536. if (toStart) {
  4537. range.startContainer = node
  4538. range.startOffset = offset
  4539. if (!range.endContainer) {
  4540. range.collapse(true)
  4541. }
  4542. } else {
  4543. range.endContainer = node
  4544. range.endOffset = offset
  4545. if (!range.startContainer) {
  4546. range.collapse(false)
  4547. }
  4548. }
  4549. updateCollapse(range)
  4550. return range
  4551. }
  4552. function execContentsAction(range, action) {
  4553. //调整边界
  4554. //range.includeBookmark();
  4555. var start = range.startContainer,
  4556. end = range.endContainer,
  4557. startOffset = range.startOffset,
  4558. endOffset = range.endOffset,
  4559. doc = range.document,
  4560. frag = doc.createDocumentFragment(),
  4561. tmpStart,
  4562. tmpEnd
  4563. if (start.nodeType == 1) {
  4564. start =
  4565. start.childNodes[startOffset] || (tmpStart = start.appendChild(doc.createTextNode('')))
  4566. }
  4567. if (end.nodeType == 1) {
  4568. end = end.childNodes[endOffset] || (tmpEnd = end.appendChild(doc.createTextNode('')))
  4569. }
  4570. if (start === end && start.nodeType == 3) {
  4571. frag.appendChild(
  4572. doc.createTextNode(start.substringData(startOffset, endOffset - startOffset))
  4573. )
  4574. //is not clone
  4575. if (action) {
  4576. start.deleteData(startOffset, endOffset - startOffset)
  4577. range.collapse(true)
  4578. }
  4579. return frag
  4580. }
  4581. var current,
  4582. currentLevel,
  4583. clone = frag,
  4584. startParents = domUtils.findParents(start, true),
  4585. endParents = domUtils.findParents(end, true)
  4586. for (var i = 0; startParents[i] == endParents[i]; ) {
  4587. i++
  4588. }
  4589. for (var j = i, si; (si = startParents[j]); j++) {
  4590. current = si.nextSibling
  4591. if (si == start) {
  4592. if (!tmpStart) {
  4593. if (range.startContainer.nodeType == 3) {
  4594. clone.appendChild(doc.createTextNode(start.nodeValue.slice(startOffset)))
  4595. //is not clone
  4596. if (action) {
  4597. start.deleteData(startOffset, start.nodeValue.length - startOffset)
  4598. }
  4599. } else {
  4600. clone.appendChild(!action ? start.cloneNode(true) : start)
  4601. }
  4602. }
  4603. } else {
  4604. currentLevel = si.cloneNode(false)
  4605. clone.appendChild(currentLevel)
  4606. }
  4607. while (current) {
  4608. if (current === end || current === endParents[j]) {
  4609. break
  4610. }
  4611. si = current.nextSibling
  4612. clone.appendChild(!action ? current.cloneNode(true) : current)
  4613. current = si
  4614. }
  4615. clone = currentLevel
  4616. }
  4617. clone = frag
  4618. if (!startParents[i]) {
  4619. clone.appendChild(startParents[i - 1].cloneNode(false))
  4620. clone = clone.firstChild
  4621. }
  4622. for (var j = i, ei; (ei = endParents[j]); j++) {
  4623. current = ei.previousSibling
  4624. if (ei == end) {
  4625. if (!tmpEnd && range.endContainer.nodeType == 3) {
  4626. clone.appendChild(doc.createTextNode(end.substringData(0, endOffset)))
  4627. //is not clone
  4628. if (action) {
  4629. end.deleteData(0, endOffset)
  4630. }
  4631. }
  4632. } else {
  4633. currentLevel = ei.cloneNode(false)
  4634. clone.appendChild(currentLevel)
  4635. }
  4636. //如果两端同级,右边第一次已经被开始做了
  4637. if (j != i || !startParents[i]) {
  4638. while (current) {
  4639. if (current === start) {
  4640. break
  4641. }
  4642. ei = current.previousSibling
  4643. clone.insertBefore(!action ? current.cloneNode(true) : current, clone.firstChild)
  4644. current = ei
  4645. }
  4646. }
  4647. clone = currentLevel
  4648. }
  4649. if (action) {
  4650. range
  4651. .setStartBefore(
  4652. !endParents[i]
  4653. ? endParents[i - 1]
  4654. : !startParents[i]
  4655. ? startParents[i - 1]
  4656. : endParents[i]
  4657. )
  4658. .collapse(true)
  4659. }
  4660. tmpStart && domUtils.remove(tmpStart)
  4661. tmpEnd && domUtils.remove(tmpEnd)
  4662. return frag
  4663. }
  4664. /**
  4665. * 创建一个跟document绑定的空的Range实例
  4666. * @constructor
  4667. * @param { Document } document 新建的选区所属的文档对象
  4668. */
  4669. /**
  4670. * @property { Node } startContainer 当前Range的开始边界的容器节点, 可以是一个元素节点或者是文本节点
  4671. */
  4672. /**
  4673. * @property { Node } startOffset 当前Range的开始边界容器节点的偏移量, 如果是元素节点,
  4674. * 该值就是childNodes中的第几个节点, 如果是文本节点就是文本内容的第几个字符
  4675. */
  4676. /**
  4677. * @property { Node } endContainer 当前Range的结束边界的容器节点, 可以是一个元素节点或者是文本节点
  4678. */
  4679. /**
  4680. * @property { Node } endOffset 当前Range的结束边界容器节点的偏移量, 如果是元素节点,
  4681. * 该值就是childNodes中的第几个节点, 如果是文本节点就是文本内容的第几个字符
  4682. */
  4683. /**
  4684. * @property { Boolean } collapsed 当前Range是否闭合
  4685. * @default true
  4686. * @remind Range是闭合的时候, startContainer === endContainer && startOffset === endOffset
  4687. */
  4688. /**
  4689. * @property { Document } document 当前Range所属的Document对象
  4690. * @remind 不同range的的document属性可以是不同的
  4691. */
  4692. var Range = (dom.Range = function (document) {
  4693. var me = this
  4694. me.startContainer = me.startOffset = me.endContainer = me.endOffset = null
  4695. me.document = document
  4696. me.collapsed = true
  4697. })
  4698. /**
  4699. * 删除fillData
  4700. * @param doc
  4701. * @param excludeNode
  4702. */
  4703. function removeFillData(doc, excludeNode) {
  4704. try {
  4705. if (fillData && domUtils.inDoc(fillData, doc)) {
  4706. if (!fillData.nodeValue.replace(fillCharReg, '').length) {
  4707. var tmpNode = fillData.parentNode
  4708. domUtils.remove(fillData)
  4709. while (
  4710. tmpNode &&
  4711. domUtils.isEmptyInlineElement(tmpNode) &&
  4712. //safari的contains有bug
  4713. (browser.safari
  4714. ? !(domUtils.getPosition(tmpNode, excludeNode) & domUtils.POSITION_CONTAINS)
  4715. : !tmpNode.contains(excludeNode))
  4716. ) {
  4717. fillData = tmpNode.parentNode
  4718. domUtils.remove(tmpNode)
  4719. tmpNode = fillData
  4720. }
  4721. } else {
  4722. fillData.nodeValue = fillData.nodeValue.replace(fillCharReg, '')
  4723. }
  4724. }
  4725. } catch (e) {}
  4726. }
  4727. /**
  4728. * @param node
  4729. * @param dir
  4730. */
  4731. function mergeSibling(node, dir) {
  4732. var tmpNode
  4733. node = node[dir]
  4734. while (node && domUtils.isFillChar(node)) {
  4735. tmpNode = node[dir]
  4736. domUtils.remove(node)
  4737. node = tmpNode
  4738. }
  4739. }
  4740. Range.prototype = {
  4741. /**
  4742. * 克隆选区的内容到一个DocumentFragment里
  4743. * @method cloneContents
  4744. * @return { DocumentFragment | NULL } 如果选区是闭合的将返回null, 否则, 返回包含所clone内容的DocumentFragment元素
  4745. * @example
  4746. * ```html
  4747. * <body>
  4748. * <!-- 中括号表示选区 -->
  4749. * <b>x<i>x[x</i>xx]x</b>
  4750. *
  4751. * <script>
  4752. * //range是已选中的选区
  4753. * var fragment = range.cloneContents(),
  4754. * node = document.createElement("div");
  4755. *
  4756. * node.appendChild( fragment );
  4757. *
  4758. * //output: <i>x</i>xx
  4759. * console.log( node.innerHTML );
  4760. *
  4761. * </script>
  4762. * </body>
  4763. * ```
  4764. */
  4765. cloneContents: function () {
  4766. return this.collapsed ? null : execContentsAction(this, 0)
  4767. },
  4768. /**
  4769. * 删除当前选区范围中的所有内容
  4770. * @method deleteContents
  4771. * @remind 执行完该操作后, 当前Range对象变成了闭合状态
  4772. * @return { UE.dom.Range } 当前操作的Range对象
  4773. * @example
  4774. * ```html
  4775. * <body>
  4776. * <!-- 中括号表示选区 -->
  4777. * <b>x<i>x[x</i>xx]x</b>
  4778. *
  4779. * <script>
  4780. * //range是已选中的选区
  4781. * range.deleteContents();
  4782. *
  4783. * //竖线表示闭合后的选区位置
  4784. * //output: <b>x<i>x</i>|x</b>
  4785. * console.log( document.body.innerHTML );
  4786. *
  4787. * //此时, range的各项属性为
  4788. * //output: B
  4789. * console.log( range.startContainer.tagName );
  4790. * //output: 2
  4791. * console.log( range.startOffset );
  4792. * //output: B
  4793. * console.log( range.endContainer.tagName );
  4794. * //output: 2
  4795. * console.log( range.endOffset );
  4796. * //output: true
  4797. * console.log( range.collapsed );
  4798. *
  4799. * </script>
  4800. * </body>
  4801. * ```
  4802. */
  4803. deleteContents: function () {
  4804. var txt
  4805. if (!this.collapsed) {
  4806. execContentsAction(this, 1)
  4807. }
  4808. if (browser.webkit) {
  4809. txt = this.startContainer
  4810. if (txt.nodeType == 3 && !txt.nodeValue.length) {
  4811. this.setStartBefore(txt).collapse(true)
  4812. domUtils.remove(txt)
  4813. }
  4814. }
  4815. return this
  4816. },
  4817. /**
  4818. * 将当前选区的内容提取到一个DocumentFragment里
  4819. * @method extractContents
  4820. * @remind 执行该操作后, 选区将变成闭合状态
  4821. * @warning 执行该操作后, 原来选区所选中的内容将从dom树上剥离出来
  4822. * @return { DocumentFragment } 返回包含所提取内容的DocumentFragment对象
  4823. * @example
  4824. * ```html
  4825. * <body>
  4826. * <!-- 中括号表示选区 -->
  4827. * <b>x<i>x[x</i>xx]x</b>
  4828. *
  4829. * <script>
  4830. * //range是已选中的选区
  4831. * var fragment = range.extractContents(),
  4832. * node = document.createElement( "div" );
  4833. *
  4834. * node.appendChild( fragment );
  4835. *
  4836. * //竖线表示闭合后的选区位置
  4837. *
  4838. * //output: <b>x<i>x</i>|x</b>
  4839. * console.log( document.body.innerHTML );
  4840. * //output: <i>x</i>xx
  4841. * console.log( node.innerHTML );
  4842. *
  4843. * //此时, range的各项属性为
  4844. * //output: B
  4845. * console.log( range.startContainer.tagName );
  4846. * //output: 2
  4847. * console.log( range.startOffset );
  4848. * //output: B
  4849. * console.log( range.endContainer.tagName );
  4850. * //output: 2
  4851. * console.log( range.endOffset );
  4852. * //output: true
  4853. * console.log( range.collapsed );
  4854. *
  4855. * </script>
  4856. * </body>
  4857. */
  4858. extractContents: function () {
  4859. return this.collapsed ? null : execContentsAction(this, 2)
  4860. },
  4861. /**
  4862. * 设置Range的开始容器节点和偏移量
  4863. * @method setStart
  4864. * @remind 如果给定的节点是元素节点,那么offset指的是其子元素中索引为offset的元素,
  4865. * 如果是文本节点,那么offset指的是其文本内容的第offset个字符
  4866. * @remind 如果提供的容器节点是一个不能包含子元素的节点, 则该选区的开始容器将被设置
  4867. * 为该节点的父节点, 此时, 其距离开始容器的偏移量也变成了该节点在其父节点
  4868. * 中的索引
  4869. * @param { Node } node 将被设为当前选区开始边界容器的节点对象
  4870. * @param { int } offset 选区的开始位置偏移量
  4871. * @return { UE.dom.Range } 当前range对象
  4872. * @example
  4873. * ```html
  4874. * <!-- 选区 -->
  4875. * <b>xxx<i>x<span>xx</span>xx<em>xx</em>xxx</i>[xxx]</b>
  4876. *
  4877. * <script>
  4878. *
  4879. * //执行操作
  4880. * range.setStart( document.getElementsByTagName("i")[0], 1 );
  4881. *
  4882. * //此时, 选区变成了
  4883. * //<b>xxx<i>x[<span>xx</span>xx<em>xx</em>xxx</i>xxx]</b>
  4884. *
  4885. * </script>
  4886. * ```
  4887. * @example
  4888. * ```html
  4889. * <!-- 选区 -->
  4890. * <b>xxx<img>[xx]x</b>
  4891. *
  4892. * <script>
  4893. *
  4894. * //执行操作
  4895. * range.setStart( document.getElementsByTagName("img")[0], 3 );
  4896. *
  4897. * //此时, 选区变成了
  4898. * //<b>xxx[<img>xx]x</b>
  4899. *
  4900. * </script>
  4901. * ```
  4902. */
  4903. setStart: function (node, offset) {
  4904. return setEndPoint(true, node, offset, this)
  4905. },
  4906. /**
  4907. * 设置Range的结束容器和偏移量
  4908. * @method setEnd
  4909. * @param { Node } node 作为当前选区结束边界容器的节点对象
  4910. * @param { int } offset 结束边界的偏移量
  4911. * @see UE.dom.Range:setStart(Node,int)
  4912. * @return { UE.dom.Range } 当前range对象
  4913. */
  4914. setEnd: function (node, offset) {
  4915. return setEndPoint(false, node, offset, this)
  4916. },
  4917. /**
  4918. * 将Range开始位置设置到node节点之后
  4919. * @method setStartAfter
  4920. * @remind 该操作将会把给定节点的父节点作为range的开始容器, 且偏移量是该节点在其父节点中的位置索引+1
  4921. * @param { Node } node 选区的开始边界将紧接着该节点之后
  4922. * @return { UE.dom.Range } 当前range对象
  4923. * @example
  4924. * ```html
  4925. * <!-- 选区示例 -->
  4926. * <b>xx<i>xxx</i><span>xx[x</span>xxx]</b>
  4927. *
  4928. * <script>
  4929. *
  4930. * //执行操作
  4931. * range.setStartAfter( document.getElementsByTagName("i")[0] );
  4932. *
  4933. * //结果选区
  4934. * //<b>xx<i>xxx</i>[<span>xxx</span>xxx]</b>
  4935. *
  4936. * </script>
  4937. * ```
  4938. */
  4939. setStartAfter: function (node) {
  4940. return this.setStart(node.parentNode, domUtils.getNodeIndex(node) + 1)
  4941. },
  4942. /**
  4943. * 将Range开始位置设置到node节点之前
  4944. * @method setStartBefore
  4945. * @remind 该操作将会把给定节点的父节点作为range的开始容器, 且偏移量是该节点在其父节点中的位置索引
  4946. * @param { Node } node 新的选区开始位置在该节点之前
  4947. * @see UE.dom.Range:setStartAfter(Node)
  4948. * @return { UE.dom.Range } 当前range对象
  4949. */
  4950. setStartBefore: function (node) {
  4951. return this.setStart(node.parentNode, domUtils.getNodeIndex(node))
  4952. },
  4953. /**
  4954. * 将Range结束位置设置到node节点之后
  4955. * @method setEndAfter
  4956. * @remind 该操作将会把给定节点的父节点作为range的结束容器, 且偏移量是该节点在其父节点中的位置索引+1
  4957. * @param { Node } node 目标节点
  4958. * @see UE.dom.Range:setStartAfter(Node)
  4959. * @return { UE.dom.Range } 当前range对象
  4960. * @example
  4961. * ```html
  4962. * <!-- 选区示例 -->
  4963. * <b>[xx<i>xxx</i><span>xx]x</span>xxx</b>
  4964. *
  4965. * <script>
  4966. *
  4967. * //执行操作
  4968. * range.setStartAfter( document.getElementsByTagName("span")[0] );
  4969. *
  4970. * //结果选区
  4971. * //<b>[xx<i>xxx</i><span>xxx</span>]xxx</b>
  4972. *
  4973. * </script>
  4974. * ```
  4975. */
  4976. setEndAfter: function (node) {
  4977. return this.setEnd(node.parentNode, domUtils.getNodeIndex(node) + 1)
  4978. },
  4979. /**
  4980. * 将Range结束位置设置到node节点之前
  4981. * @method setEndBefore
  4982. * @remind 该操作将会把给定节点的父节点作为range的结束容器, 且偏移量是该节点在其父节点中的位置索引
  4983. * @param { Node } node 目标节点
  4984. * @see UE.dom.Range:setEndAfter(Node)
  4985. * @return { UE.dom.Range } 当前range对象
  4986. */
  4987. setEndBefore: function (node) {
  4988. return this.setEnd(node.parentNode, domUtils.getNodeIndex(node))
  4989. },
  4990. /**
  4991. * 设置Range的开始位置到node节点内的第一个子节点之前
  4992. * @method setStartAtFirst
  4993. * @remind 选区的开始容器将变成给定的节点, 且偏移量为0
  4994. * @remind 如果给定的节点是元素节点, 则该节点必须是允许包含子节点的元素。
  4995. * @param { Node } node 目标节点
  4996. * @see UE.dom.Range:setStartBefore(Node)
  4997. * @return { UE.dom.Range } 当前range对象
  4998. * @example
  4999. * ```html
  5000. * <!-- 选区示例 -->
  5001. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  5002. *
  5003. * <script>
  5004. *
  5005. * //执行操作
  5006. * range.setStartAtFirst( document.getElementsByTagName("i")[0] );
  5007. *
  5008. * //结果选区
  5009. * //<b>xx<i>[xxx</i><span>xx]x</span>xxx</b>
  5010. *
  5011. * </script>
  5012. * ```
  5013. */
  5014. setStartAtFirst: function (node) {
  5015. return this.setStart(node, 0)
  5016. },
  5017. /**
  5018. * 设置Range的开始位置到node节点内的最后一个节点之后
  5019. * @method setStartAtLast
  5020. * @remind 选区的开始容器将变成给定的节点, 且偏移量为该节点的子节点数
  5021. * @remind 如果给定的节点是元素节点, 则该节点必须是允许包含子节点的元素。
  5022. * @param { Node } node 目标节点
  5023. * @see UE.dom.Range:setStartAtFirst(Node)
  5024. * @return { UE.dom.Range } 当前range对象
  5025. */
  5026. setStartAtLast: function (node) {
  5027. return this.setStart(
  5028. node,
  5029. node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length
  5030. )
  5031. },
  5032. /**
  5033. * 设置Range的结束位置到node节点内的第一个节点之前
  5034. * @method setEndAtFirst
  5035. * @param { Node } node 目标节点
  5036. * @remind 选区的结束容器将变成给定的节点, 且偏移量为0
  5037. * @remind node必须是一个元素节点, 且必须是允许包含子节点的元素。
  5038. * @see UE.dom.Range:setStartAtFirst(Node)
  5039. * @return { UE.dom.Range } 当前range对象
  5040. */
  5041. setEndAtFirst: function (node) {
  5042. return this.setEnd(node, 0)
  5043. },
  5044. /**
  5045. * 设置Range的结束位置到node节点内的最后一个节点之后
  5046. * @method setEndAtLast
  5047. * @param { Node } node 目标节点
  5048. * @remind 选区的结束容器将变成给定的节点, 且偏移量为该节点的子节点数量
  5049. * @remind node必须是一个元素节点, 且必须是允许包含子节点的元素。
  5050. * @see UE.dom.Range:setStartAtFirst(Node)
  5051. * @return { UE.dom.Range } 当前range对象
  5052. */
  5053. setEndAtLast: function (node) {
  5054. return this.setEnd(
  5055. node,
  5056. node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length
  5057. )
  5058. },
  5059. /**
  5060. * 选中给定节点
  5061. * @method selectNode
  5062. * @remind 此时, 选区的开始容器和结束容器都是该节点的父节点, 其startOffset是该节点在父节点中的位置索引,
  5063. * 而endOffset为startOffset+1
  5064. * @param { Node } node 需要选中的节点
  5065. * @return { UE.dom.Range } 当前range对象,此时的range仅包含当前给定的节点对象
  5066. * @example
  5067. * ```html
  5068. * <!-- 选区示例 -->
  5069. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  5070. *
  5071. * <script>
  5072. *
  5073. * //执行操作
  5074. * range.selectNode( document.getElementsByTagName("i")[0] );
  5075. *
  5076. * //结果选区
  5077. * //<b>xx[<i>xxx</i>]<span>xxx</span>xxx</b>
  5078. *
  5079. * </script>
  5080. * ```
  5081. */
  5082. selectNode: function (node) {
  5083. return this.setStartBefore(node).setEndAfter(node)
  5084. },
  5085. /**
  5086. * 选中给定节点内部的所有节点
  5087. * @method selectNodeContents
  5088. * @remind 此时, 选区的开始容器和结束容器都是该节点, 其startOffset为0,
  5089. * 而endOffset是该节点的子节点数。
  5090. * @param { Node } node 目标节点, 当前range将包含该节点内的所有节点
  5091. * @return { UE.dom.Range } 当前range对象, 此时range仅包含给定节点的所有子节点
  5092. * @example
  5093. * ```html
  5094. * <!-- 选区示例 -->
  5095. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  5096. *
  5097. * <script>
  5098. *
  5099. * //执行操作
  5100. * range.selectNode( document.getElementsByTagName("b")[0] );
  5101. *
  5102. * //结果选区
  5103. * //<b>[xx<i>xxx</i><span>xxx</span>xxx]</b>
  5104. *
  5105. * </script>
  5106. * ```
  5107. */
  5108. selectNodeContents: function (node) {
  5109. return this.setStart(node, 0).setEndAtLast(node)
  5110. },
  5111. /**
  5112. * clone当前Range对象
  5113. * @method cloneRange
  5114. * @remind 返回的range是一个全新的range对象, 其内部所有属性与当前被clone的range相同。
  5115. * @return { UE.dom.Range } 当前range对象的一个副本
  5116. */
  5117. cloneRange: function () {
  5118. var me = this
  5119. return new Range(me.document)
  5120. .setStart(me.startContainer, me.startOffset)
  5121. .setEnd(me.endContainer, me.endOffset)
  5122. },
  5123. /**
  5124. * 向当前选区的结束处闭合选区
  5125. * @method collapse
  5126. * @return { UE.dom.Range } 当前range对象
  5127. * @example
  5128. * ```html
  5129. * <!-- 选区示例 -->
  5130. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  5131. *
  5132. * <script>
  5133. *
  5134. * //执行操作
  5135. * range.collapse();
  5136. *
  5137. * //结果选区
  5138. * //“|”表示选区已闭合
  5139. * //<b>xx<i>xxx</i><span>xx|x</span>xxx</b>
  5140. *
  5141. * </script>
  5142. * ```
  5143. */
  5144. /**
  5145. * 闭合当前选区,根据给定的toStart参数项决定是向当前选区开始处闭合还是向结束处闭合,
  5146. * 如果toStart的值为true,则向开始位置闭合, 反之,向结束位置闭合。
  5147. * @method collapse
  5148. * @param { Boolean } toStart 是否向选区开始处闭合
  5149. * @return { UE.dom.Range } 当前range对象,此时range对象处于闭合状态
  5150. * @see UE.dom.Range:collapse()
  5151. * @example
  5152. * ```html
  5153. * <!-- 选区示例 -->
  5154. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  5155. *
  5156. * <script>
  5157. *
  5158. * //执行操作
  5159. * range.collapse( true );
  5160. *
  5161. * //结果选区
  5162. * //“|”表示选区已闭合
  5163. * //<b>xx<i>xxx</i><span>|xxx</span>xxx</b>
  5164. *
  5165. * </script>
  5166. * ```
  5167. */
  5168. collapse: function (toStart) {
  5169. var me = this
  5170. if (toStart) {
  5171. me.endContainer = me.startContainer
  5172. me.endOffset = me.startOffset
  5173. } else {
  5174. me.startContainer = me.endContainer
  5175. me.startOffset = me.endOffset
  5176. }
  5177. me.collapsed = true
  5178. return me
  5179. },
  5180. /**
  5181. * 调整range的开始位置和结束位置,使其"收缩"到最小的位置
  5182. * @method shrinkBoundary
  5183. * @return { UE.dom.Range } 当前range对象
  5184. * @example
  5185. * ```html
  5186. * <span>xx<b>xx[</b>xxxxx]</span> => <span>xx<b>xx</b>[xxxxx]</span>
  5187. * ```
  5188. *
  5189. * @example
  5190. * ```html
  5191. * <!-- 选区示例 -->
  5192. * <b>x[xx</b><i>]xxx</i>
  5193. *
  5194. * <script>
  5195. *
  5196. * //执行收缩
  5197. * range.shrinkBoundary();
  5198. *
  5199. * //结果选区
  5200. * //<b>x[xx]</b><i>xxx</i>
  5201. * </script>
  5202. * ```
  5203. *
  5204. * @example
  5205. * ```html
  5206. * [<b><i>xxxx</i>xxxxxxx</b>] => <b><i>[xxxx</i>xxxxxxx]</b>
  5207. * ```
  5208. */
  5209. /**
  5210. * 调整range的开始位置和结束位置,使其"收缩"到最小的位置,
  5211. * 如果ignoreEnd的值为true,则忽略对结束位置的调整
  5212. * @method shrinkBoundary
  5213. * @param { Boolean } ignoreEnd 是否忽略对结束位置的调整
  5214. * @return { UE.dom.Range } 当前range对象
  5215. * @see UE.dom.domUtils.Range:shrinkBoundary()
  5216. */
  5217. shrinkBoundary: function (ignoreEnd) {
  5218. var me = this,
  5219. child,
  5220. collapsed = me.collapsed
  5221. function check(node) {
  5222. return (
  5223. node.nodeType == 1 &&
  5224. !domUtils.isBookmarkNode(node) &&
  5225. !dtd.$empty[node.tagName] &&
  5226. !dtd.$nonChild[node.tagName]
  5227. )
  5228. }
  5229. while (
  5230. me.startContainer.nodeType == 1 && //是element
  5231. (child = me.startContainer.childNodes[me.startOffset]) && //子节点也是element
  5232. check(child)
  5233. ) {
  5234. me.setStart(child, 0)
  5235. }
  5236. if (collapsed) {
  5237. return me.collapse(true)
  5238. }
  5239. if (!ignoreEnd) {
  5240. while (
  5241. me.endContainer.nodeType == 1 && //是element
  5242. me.endOffset > 0 && //如果是空元素就退出 endOffset=0那么endOffst-1为负值,childNodes[endOffset]报错
  5243. (child = me.endContainer.childNodes[me.endOffset - 1]) && //子节点也是element
  5244. check(child)
  5245. ) {
  5246. me.setEnd(child, child.childNodes.length)
  5247. }
  5248. }
  5249. return me
  5250. },
  5251. /**
  5252. * 获取离当前选区内包含的所有节点最近的公共祖先节点,
  5253. * @method getCommonAncestor
  5254. * @remind 返回的公共祖先节点一定不是range自身的容器节点, 但有可能是一个文本节点
  5255. * @return { Node } 当前range对象内所有节点的公共祖先节点
  5256. * @example
  5257. * ```html
  5258. * //选区示例
  5259. * <span>xxx<b>x[x<em>xx]x</em>xxx</b>xx</span>
  5260. * <script>
  5261. *
  5262. * var node = range.getCommonAncestor();
  5263. *
  5264. * //公共祖先节点是: b节点
  5265. * //输出: B
  5266. * console.log(node.tagName);
  5267. *
  5268. * </script>
  5269. * ```
  5270. */
  5271. /**
  5272. * 获取当前选区所包含的所有节点的公共祖先节点, 可以根据给定的参数 includeSelf 决定获取到
  5273. * 的公共祖先节点是否可以是当前选区的startContainer或endContainer节点, 如果 includeSelf
  5274. * 的取值为true, 则返回的节点可以是自身的容器节点, 否则, 则不能是容器节点
  5275. * @method getCommonAncestor
  5276. * @param { Boolean } includeSelf 是否允许获取到的公共祖先节点是当前range对象的容器节点
  5277. * @return { Node } 当前range对象内所有节点的公共祖先节点
  5278. * @see UE.dom.Range:getCommonAncestor()
  5279. * @example
  5280. * ```html
  5281. * <body>
  5282. *
  5283. * <!-- 选区示例 -->
  5284. * <b>xxx<i>xxxx<span>xx[x</span>xx]x</i>xxxxxxx</b>
  5285. *
  5286. * <script>
  5287. *
  5288. * var node = range.getCommonAncestor( false );
  5289. *
  5290. * //这里的公共祖先节点是B而不是I, 是因为参数限制了获取到的节点不能是容器节点
  5291. * //output: B
  5292. * console.log( node.tagName );
  5293. *
  5294. * </script>
  5295. *
  5296. * </body>
  5297. * ```
  5298. */
  5299. /**
  5300. * 获取当前选区所包含的所有节点的公共祖先节点, 可以根据给定的参数 includeSelf 决定获取到
  5301. * 的公共祖先节点是否可以是当前选区的startContainer或endContainer节点, 如果 includeSelf
  5302. * 的取值为true, 则返回的节点可以是自身的容器节点, 否则, 则不能是容器节点; 同时可以根据
  5303. * ignoreTextNode 参数的取值决定是否忽略类型为文本节点的祖先节点。
  5304. * @method getCommonAncestor
  5305. * @param { Boolean } includeSelf 是否允许获取到的公共祖先节点是当前range对象的容器节点
  5306. * @param { Boolean } ignoreTextNode 获取祖先节点的过程中是否忽略类型为文本节点的祖先节点
  5307. * @return { Node } 当前range对象内所有节点的公共祖先节点
  5308. * @see UE.dom.Range:getCommonAncestor()
  5309. * @see UE.dom.Range:getCommonAncestor(Boolean)
  5310. * @example
  5311. * ```html
  5312. * <body>
  5313. *
  5314. * <!-- 选区示例 -->
  5315. * <b>xxx<i>xxxx<span>x[x]x</span>xxx</i>xxxxxxx</b>
  5316. *
  5317. * <script>
  5318. *
  5319. * var node = range.getCommonAncestor( true, false );
  5320. *
  5321. * //output: SPAN
  5322. * console.log( node.tagName );
  5323. *
  5324. * </script>
  5325. *
  5326. * </body>
  5327. * ```
  5328. */
  5329. getCommonAncestor: function (includeSelf, ignoreTextNode) {
  5330. var me = this,
  5331. start = me.startContainer,
  5332. end = me.endContainer
  5333. if (start === end) {
  5334. if (includeSelf && selectOneNode(this)) {
  5335. start = start.childNodes[me.startOffset]
  5336. if (start.nodeType == 1) return start
  5337. }
  5338. //只有在上来就相等的情况下才会出现是文本的情况
  5339. return ignoreTextNode && start.nodeType == 3 ? start.parentNode : start
  5340. }
  5341. return domUtils.getCommonAncestor(start, end)
  5342. },
  5343. /**
  5344. * 调整当前Range的开始和结束边界容器,如果是容器节点是文本节点,就调整到包含该文本节点的父节点上
  5345. * @method trimBoundary
  5346. * @remind 该操作有可能会引起文本节点被切开
  5347. * @return { UE.dom.Range } 当前range对象
  5348. * @example
  5349. * ```html
  5350. *
  5351. * //选区示例
  5352. * <b>xxx<i>[xxxxx]</i>xxx</b>
  5353. *
  5354. * <script>
  5355. * //未调整前, 选区的开始容器和结束都是文本节点
  5356. * //执行调整
  5357. * range.trimBoundary();
  5358. *
  5359. * //调整之后, 容器节点变成了i节点
  5360. * //<b>xxx[<i>xxxxx</i>]xxx</b>
  5361. * </script>
  5362. * ```
  5363. */
  5364. /**
  5365. * 调整当前Range的开始和结束边界容器,如果是容器节点是文本节点,就调整到包含该文本节点的父节点上,
  5366. * 可以根据 ignoreEnd 参数的值决定是否调整对结束边界的调整
  5367. * @method trimBoundary
  5368. * @param { Boolean } ignoreEnd 是否忽略对结束边界的调整
  5369. * @return { UE.dom.Range } 当前range对象
  5370. * @example
  5371. * ```html
  5372. *
  5373. * //选区示例
  5374. * <b>xxx<i>[xxxxx]</i>xxx</b>
  5375. *
  5376. * <script>
  5377. * //未调整前, 选区的开始容器和结束都是文本节点
  5378. * //执行调整
  5379. * range.trimBoundary( true );
  5380. *
  5381. * //调整之后, 开始容器节点变成了i节点
  5382. * //但是, 结束容器没有发生变化
  5383. * //<b>xxx[<i>xxxxx]</i>xxx</b>
  5384. * </script>
  5385. * ```
  5386. */
  5387. trimBoundary: function (ignoreEnd) {
  5388. this.txtToElmBoundary()
  5389. var start = this.startContainer,
  5390. offset = this.startOffset,
  5391. collapsed = this.collapsed,
  5392. end = this.endContainer
  5393. if (start.nodeType == 3) {
  5394. if (offset == 0) {
  5395. this.setStartBefore(start)
  5396. } else {
  5397. if (offset >= start.nodeValue.length) {
  5398. this.setStartAfter(start)
  5399. } else {
  5400. var textNode = domUtils.split(start, offset)
  5401. //跟新结束边界
  5402. if (start === end) {
  5403. this.setEnd(textNode, this.endOffset - offset)
  5404. } else if (start.parentNode === end) {
  5405. this.endOffset += 1
  5406. }
  5407. this.setStartBefore(textNode)
  5408. }
  5409. }
  5410. if (collapsed) {
  5411. return this.collapse(true)
  5412. }
  5413. }
  5414. if (!ignoreEnd) {
  5415. offset = this.endOffset
  5416. end = this.endContainer
  5417. if (end.nodeType == 3) {
  5418. if (offset == 0) {
  5419. this.setEndBefore(end)
  5420. } else {
  5421. offset < end.nodeValue.length && domUtils.split(end, offset)
  5422. this.setEndAfter(end)
  5423. }
  5424. }
  5425. }
  5426. return this
  5427. },
  5428. /**
  5429. * 如果选区在文本的边界上,就扩展选区到文本的父节点上, 如果当前选区是闭合的, 则什么也不做
  5430. * @method txtToElmBoundary
  5431. * @remind 该操作不会修改dom节点
  5432. * @return { UE.dom.Range } 当前range对象
  5433. */
  5434. /**
  5435. * 如果选区在文本的边界上,就扩展选区到文本的父节点上, 如果当前选区是闭合的, 则根据参数项
  5436. * ignoreCollapsed 的值决定是否执行该调整
  5437. * @method txtToElmBoundary
  5438. * @param { Boolean } ignoreCollapsed 是否忽略选区的闭合状态, 如果该参数取值为true, 则
  5439. * 不论选区是否闭合, 都会执行该操作, 反之, 则不会对闭合的选区执行该操作
  5440. * @return { UE.dom.Range } 当前range对象
  5441. */
  5442. txtToElmBoundary: function (ignoreCollapsed) {
  5443. function adjust(r, c) {
  5444. var container = r[c + 'Container'],
  5445. offset = r[c + 'Offset']
  5446. if (container.nodeType == 3) {
  5447. if (!offset) {
  5448. r[
  5449. 'set' +
  5450. c.replace(/(\w)/, function (a) {
  5451. return a.toUpperCase()
  5452. }) +
  5453. 'Before'
  5454. ](container)
  5455. } else if (offset >= container.nodeValue.length) {
  5456. r[
  5457. 'set' +
  5458. c.replace(/(\w)/, function (a) {
  5459. return a.toUpperCase()
  5460. }) +
  5461. 'After'
  5462. ](container)
  5463. }
  5464. }
  5465. }
  5466. if (ignoreCollapsed || !this.collapsed) {
  5467. adjust(this, 'start')
  5468. adjust(this, 'end')
  5469. }
  5470. return this
  5471. },
  5472. /**
  5473. * 在当前选区的开始位置前插入节点,新插入的节点会被该range包含
  5474. * @method insertNode
  5475. * @param { Node } node 需要插入的节点
  5476. * @remind 插入的节点可以是一个DocumentFragment依次插入多个节点
  5477. * @return { UE.dom.Range } 当前range对象
  5478. */
  5479. insertNode: function (node) {
  5480. var first = node,
  5481. length = 1
  5482. if (node.nodeType == 11) {
  5483. first = node.firstChild
  5484. length = node.childNodes.length
  5485. }
  5486. this.trimBoundary(true)
  5487. var start = this.startContainer,
  5488. offset = this.startOffset
  5489. var nextNode = start.childNodes[offset]
  5490. if (nextNode) {
  5491. start.insertBefore(node, nextNode)
  5492. } else {
  5493. start.appendChild(node)
  5494. }
  5495. if (first.parentNode === this.endContainer) {
  5496. this.endOffset = this.endOffset + length
  5497. }
  5498. return this.setStartBefore(first)
  5499. },
  5500. /**
  5501. * 闭合选区到当前选区的开始位置, 并且定位光标到闭合后的位置
  5502. * @method setCursor
  5503. * @return { UE.dom.Range } 当前range对象
  5504. * @see UE.dom.Range:collapse()
  5505. */
  5506. /**
  5507. * 闭合选区,可以根据参数toEnd的值控制选区是向前闭合还是向后闭合, 并且定位光标到闭合后的位置。
  5508. * @method setCursor
  5509. * @param { Boolean } toEnd 是否向后闭合, 如果为true, 则闭合选区时, 将向结束容器方向闭合,
  5510. * 反之,则向开始容器方向闭合
  5511. * @return { UE.dom.Range } 当前range对象
  5512. * @see UE.dom.Range:collapse(Boolean)
  5513. */
  5514. setCursor: function (toEnd, noFillData) {
  5515. return this.collapse(!toEnd).select(noFillData)
  5516. },
  5517. /**
  5518. * 创建当前range的一个书签,记录下当前range的位置,方便当dom树改变时,还能找回原来的选区位置
  5519. * @method createBookmark
  5520. * @param { Boolean } serialize 控制返回的标记位置是对当前位置的引用还是ID,如果该值为true,则
  5521. * 返回标记位置的ID, 反之则返回标记位置节点的引用
  5522. * @return { Object } 返回一个书签记录键值对, 其包含的key有: start => 开始标记的ID或者引用,
  5523. * end => 结束标记的ID或引用, id => 当前标记的类型, 如果为true,则表示
  5524. * 返回的记录的类型为ID, 反之则为引用
  5525. */
  5526. createBookmark: function (serialize, same) {
  5527. var endNode,
  5528. startNode = this.document.createElement('span')
  5529. startNode.style.cssText = 'display:none;line-height:0px;'
  5530. startNode.appendChild(this.document.createTextNode('\u200D'))
  5531. startNode.id = '_baidu_bookmark_start_' + (same ? '' : guid++)
  5532. if (!this.collapsed) {
  5533. endNode = startNode.cloneNode(true)
  5534. endNode.id = '_baidu_bookmark_end_' + (same ? '' : guid++)
  5535. }
  5536. this.insertNode(startNode)
  5537. if (endNode) {
  5538. this.collapse().insertNode(endNode).setEndBefore(endNode)
  5539. }
  5540. this.setStartAfter(startNode)
  5541. return {
  5542. start: serialize ? startNode.id : startNode,
  5543. end: endNode ? (serialize ? endNode.id : endNode) : null,
  5544. id: serialize
  5545. }
  5546. },
  5547. /**
  5548. * 调整当前range的边界到书签位置,并删除该书签对象所标记的位置内的节点
  5549. * @method moveToBookmark
  5550. * @param { BookMark } bookmark createBookmark所创建的标签对象
  5551. * @return { UE.dom.Range } 当前range对象
  5552. * @see UE.dom.Range:createBookmark(Boolean)
  5553. */
  5554. moveToBookmark: function (bookmark) {
  5555. var start = bookmark.id ? this.document.getElementById(bookmark.start) : bookmark.start,
  5556. end =
  5557. bookmark.end && bookmark.id ? this.document.getElementById(bookmark.end) : bookmark.end
  5558. this.setStartBefore(start)
  5559. domUtils.remove(start)
  5560. if (end) {
  5561. this.setEndBefore(end)
  5562. domUtils.remove(end)
  5563. } else {
  5564. this.collapse(true)
  5565. }
  5566. return this
  5567. },
  5568. /**
  5569. * 调整range的边界,使其"放大"到最近的父节点
  5570. * @method enlarge
  5571. * @remind 会引起选区的变化
  5572. * @return { UE.dom.Range } 当前range对象
  5573. */
  5574. /**
  5575. * 调整range的边界,使其"放大"到最近的父节点,根据参数 toBlock 的取值, 可以
  5576. * 要求扩大之后的父节点是block节点
  5577. * @method enlarge
  5578. * @param { Boolean } toBlock 是否要求扩大之后的父节点必须是block节点
  5579. * @return { UE.dom.Range } 当前range对象
  5580. */
  5581. enlarge: function (toBlock, stopFn) {
  5582. var isBody = domUtils.isBody,
  5583. pre,
  5584. node,
  5585. tmp = this.document.createTextNode('')
  5586. if (toBlock) {
  5587. node = this.startContainer
  5588. if (node.nodeType == 1) {
  5589. if (node.childNodes[this.startOffset]) {
  5590. pre = node = node.childNodes[this.startOffset]
  5591. } else {
  5592. node.appendChild(tmp)
  5593. pre = node = tmp
  5594. }
  5595. } else {
  5596. pre = node
  5597. }
  5598. while (1) {
  5599. if (domUtils.isBlockElm(node)) {
  5600. node = pre
  5601. while ((pre = node.previousSibling) && !domUtils.isBlockElm(pre)) {
  5602. node = pre
  5603. }
  5604. this.setStartBefore(node)
  5605. break
  5606. }
  5607. pre = node
  5608. node = node.parentNode
  5609. }
  5610. node = this.endContainer
  5611. if (node.nodeType == 1) {
  5612. if ((pre = node.childNodes[this.endOffset])) {
  5613. node.insertBefore(tmp, pre)
  5614. } else {
  5615. node.appendChild(tmp)
  5616. }
  5617. pre = node = tmp
  5618. } else {
  5619. pre = node
  5620. }
  5621. while (1) {
  5622. if (domUtils.isBlockElm(node)) {
  5623. node = pre
  5624. while ((pre = node.nextSibling) && !domUtils.isBlockElm(pre)) {
  5625. node = pre
  5626. }
  5627. this.setEndAfter(node)
  5628. break
  5629. }
  5630. pre = node
  5631. node = node.parentNode
  5632. }
  5633. if (tmp.parentNode === this.endContainer) {
  5634. this.endOffset--
  5635. }
  5636. domUtils.remove(tmp)
  5637. }
  5638. // 扩展边界到最大
  5639. if (!this.collapsed) {
  5640. while (this.startOffset == 0) {
  5641. if (stopFn && stopFn(this.startContainer)) {
  5642. break
  5643. }
  5644. if (isBody(this.startContainer)) {
  5645. break
  5646. }
  5647. this.setStartBefore(this.startContainer)
  5648. }
  5649. while (
  5650. this.endOffset ==
  5651. (this.endContainer.nodeType == 1
  5652. ? this.endContainer.childNodes.length
  5653. : this.endContainer.nodeValue.length)
  5654. ) {
  5655. if (stopFn && stopFn(this.endContainer)) {
  5656. break
  5657. }
  5658. if (isBody(this.endContainer)) {
  5659. break
  5660. }
  5661. this.setEndAfter(this.endContainer)
  5662. }
  5663. }
  5664. return this
  5665. },
  5666. enlargeToBlockElm: function (ignoreEnd) {
  5667. while (!domUtils.isBlockElm(this.startContainer)) {
  5668. this.setStartBefore(this.startContainer)
  5669. }
  5670. if (!ignoreEnd) {
  5671. while (!domUtils.isBlockElm(this.endContainer)) {
  5672. this.setEndAfter(this.endContainer)
  5673. }
  5674. }
  5675. return this
  5676. },
  5677. /**
  5678. * 调整Range的边界,使其"缩小"到最合适的位置
  5679. * @method adjustmentBoundary
  5680. * @return { UE.dom.Range } 当前range对象
  5681. * @see UE.dom.Range:shrinkBoundary()
  5682. */
  5683. adjustmentBoundary: function () {
  5684. if (!this.collapsed) {
  5685. while (
  5686. !domUtils.isBody(this.startContainer) &&
  5687. this.startOffset ==
  5688. this.startContainer[this.startContainer.nodeType == 3 ? 'nodeValue' : 'childNodes']
  5689. .length &&
  5690. this.startContainer[this.startContainer.nodeType == 3 ? 'nodeValue' : 'childNodes']
  5691. .length
  5692. ) {
  5693. this.setStartAfter(this.startContainer)
  5694. }
  5695. while (
  5696. !domUtils.isBody(this.endContainer) &&
  5697. !this.endOffset &&
  5698. this.endContainer[this.endContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length
  5699. ) {
  5700. this.setEndBefore(this.endContainer)
  5701. }
  5702. }
  5703. return this
  5704. },
  5705. /**
  5706. * 给range选区中的内容添加给定的inline标签
  5707. * @method applyInlineStyle
  5708. * @param { String } tagName 需要添加的标签名
  5709. * @example
  5710. * ```html
  5711. * <p>xxxx[xxxx]x</p> ==> range.applyInlineStyle("strong") ==> <p>xxxx[<strong>xxxx</strong>]x</p>
  5712. * ```
  5713. */
  5714. /**
  5715. * 给range选区中的内容添加给定的inline标签, 并且为标签附加上一些初始化属性。
  5716. * @method applyInlineStyle
  5717. * @param { String } tagName 需要添加的标签名
  5718. * @param { Object } attrs 跟随新添加的标签的属性
  5719. * @return { UE.dom.Range } 当前选区
  5720. * @example
  5721. * ```html
  5722. * <p>xxxx[xxxx]x</p>
  5723. *
  5724. * ==>
  5725. *
  5726. * <!-- 执行操作 -->
  5727. * range.applyInlineStyle("strong",{"style":"font-size:12px"})
  5728. *
  5729. * ==>
  5730. *
  5731. * <p>xxxx[<strong style="font-size:12px">xxxx</strong>]x</p>
  5732. * ```
  5733. */
  5734. applyInlineStyle: function (tagName, attrs, list) {
  5735. if (this.collapsed) return this
  5736. this.trimBoundary()
  5737. .enlarge(false, function (node) {
  5738. return node.nodeType == 1 && domUtils.isBlockElm(node)
  5739. })
  5740. .adjustmentBoundary()
  5741. var bookmark = this.createBookmark(),
  5742. end = bookmark.end,
  5743. filterFn = function (node) {
  5744. return node.nodeType == 1
  5745. ? node.tagName.toLowerCase() != 'br'
  5746. : !domUtils.isWhitespace(node)
  5747. },
  5748. current = domUtils.getNextDomNode(bookmark.start, false, filterFn),
  5749. node,
  5750. pre,
  5751. range = this.cloneRange()
  5752. while (current && domUtils.getPosition(current, end) & domUtils.POSITION_PRECEDING) {
  5753. if (current.nodeType == 3 || dtd[tagName][current.tagName]) {
  5754. range.setStartBefore(current)
  5755. node = current
  5756. while (node && (node.nodeType == 3 || dtd[tagName][node.tagName]) && node !== end) {
  5757. pre = node
  5758. node = domUtils.getNextDomNode(node, node.nodeType == 1, null, function (parent) {
  5759. return dtd[tagName][parent.tagName]
  5760. })
  5761. }
  5762. var frag = range.setEndAfter(pre).extractContents(),
  5763. elm
  5764. if (list && list.length > 0) {
  5765. var level, top
  5766. top = level = list[0].cloneNode(false)
  5767. for (var i = 1, ci; (ci = list[i++]); ) {
  5768. level.appendChild(ci.cloneNode(false))
  5769. level = level.firstChild
  5770. }
  5771. elm = level
  5772. } else {
  5773. elm = range.document.createElement(tagName)
  5774. }
  5775. if (attrs) {
  5776. domUtils.setAttributes(elm, attrs)
  5777. }
  5778. elm.appendChild(frag)
  5779. range.insertNode(list ? top : elm)
  5780. //处理下滑线在a上的情况
  5781. var aNode
  5782. if (
  5783. tagName == 'span' &&
  5784. attrs.style &&
  5785. /text\-decoration/.test(attrs.style) &&
  5786. (aNode = domUtils.findParentByTagName(elm, 'a', true))
  5787. ) {
  5788. domUtils.setAttributes(aNode, attrs)
  5789. domUtils.remove(elm, true)
  5790. elm = aNode
  5791. } else {
  5792. domUtils.mergeSibling(elm)
  5793. domUtils.clearEmptySibling(elm)
  5794. }
  5795. //去除子节点相同的
  5796. domUtils.mergeChild(elm, attrs)
  5797. current = domUtils.getNextDomNode(elm, false, filterFn)
  5798. domUtils.mergeToParent(elm)
  5799. if (node === end) {
  5800. break
  5801. }
  5802. } else {
  5803. current = domUtils.getNextDomNode(current, true, filterFn)
  5804. }
  5805. }
  5806. return this.moveToBookmark(bookmark)
  5807. },
  5808. /**
  5809. * 移除当前选区内指定的inline标签,但保留其中的内容
  5810. * @method removeInlineStyle
  5811. * @param { String } tagName 需要移除的标签名
  5812. * @return { UE.dom.Range } 当前的range对象
  5813. * @example
  5814. * ```html
  5815. * xx[x<span>xxx<em>yyy</em>zz]z</span> => range.removeInlineStyle(["em"]) => xx[x<span>xxxyyyzz]z</span>
  5816. * ```
  5817. */
  5818. /**
  5819. * 移除当前选区内指定的一组inline标签,但保留其中的内容
  5820. * @method removeInlineStyle
  5821. * @param { Array } tagNameArr 需要移除的标签名的数组
  5822. * @return { UE.dom.Range } 当前的range对象
  5823. * @see UE.dom.Range:removeInlineStyle(String)
  5824. */
  5825. removeInlineStyle: function (tagNames) {
  5826. if (this.collapsed) return this
  5827. tagNames = utils.isArray(tagNames) ? tagNames : [tagNames]
  5828. this.shrinkBoundary().adjustmentBoundary()
  5829. var start = this.startContainer,
  5830. end = this.endContainer
  5831. while (1) {
  5832. if (start.nodeType == 1) {
  5833. if (utils.indexOf(tagNames, start.tagName.toLowerCase()) > -1) {
  5834. break
  5835. }
  5836. if (start.tagName.toLowerCase() == 'body') {
  5837. start = null
  5838. break
  5839. }
  5840. }
  5841. start = start.parentNode
  5842. }
  5843. while (1) {
  5844. if (end.nodeType == 1) {
  5845. if (utils.indexOf(tagNames, end.tagName.toLowerCase()) > -1) {
  5846. break
  5847. }
  5848. if (end.tagName.toLowerCase() == 'body') {
  5849. end = null
  5850. break
  5851. }
  5852. }
  5853. end = end.parentNode
  5854. }
  5855. var bookmark = this.createBookmark(),
  5856. frag,
  5857. tmpRange
  5858. if (start) {
  5859. tmpRange = this.cloneRange().setEndBefore(bookmark.start).setStartBefore(start)
  5860. frag = tmpRange.extractContents()
  5861. tmpRange.insertNode(frag)
  5862. domUtils.clearEmptySibling(start, true)
  5863. start.parentNode.insertBefore(bookmark.start, start)
  5864. }
  5865. if (end) {
  5866. tmpRange = this.cloneRange().setStartAfter(bookmark.end).setEndAfter(end)
  5867. frag = tmpRange.extractContents()
  5868. tmpRange.insertNode(frag)
  5869. domUtils.clearEmptySibling(end, false, true)
  5870. end.parentNode.insertBefore(bookmark.end, end.nextSibling)
  5871. }
  5872. var current = domUtils.getNextDomNode(bookmark.start, false, function (node) {
  5873. return node.nodeType == 1
  5874. }),
  5875. next
  5876. while (current && current !== bookmark.end) {
  5877. next = domUtils.getNextDomNode(current, true, function (node) {
  5878. return node.nodeType == 1
  5879. })
  5880. if (utils.indexOf(tagNames, current.tagName.toLowerCase()) > -1) {
  5881. domUtils.remove(current, true)
  5882. }
  5883. current = next
  5884. }
  5885. return this.moveToBookmark(bookmark)
  5886. },
  5887. /**
  5888. * 获取当前选中的自闭合的节点
  5889. * @method getClosedNode
  5890. * @return { Node | NULL } 如果当前选中的是自闭合节点, 则返回该节点, 否则返回NULL
  5891. */
  5892. getClosedNode: function () {
  5893. var node
  5894. if (!this.collapsed) {
  5895. var range = this.cloneRange().adjustmentBoundary().shrinkBoundary()
  5896. if (selectOneNode(range)) {
  5897. var child = range.startContainer.childNodes[range.startOffset]
  5898. if (
  5899. child &&
  5900. child.nodeType == 1 &&
  5901. (dtd.$empty[child.tagName] || dtd.$nonChild[child.tagName])
  5902. ) {
  5903. node = child
  5904. }
  5905. }
  5906. }
  5907. return node
  5908. },
  5909. /**
  5910. * 在页面上高亮range所表示的选区
  5911. * @method select
  5912. * @return { UE.dom.Range } 返回当前Range对象
  5913. */
  5914. //这里不区分ie9以上,trace:3824
  5915. select: browser.ie
  5916. ? function (noFillData, textRange) {
  5917. var nativeRange
  5918. if (!this.collapsed) this.shrinkBoundary()
  5919. var node = this.getClosedNode()
  5920. if (node && !textRange) {
  5921. try {
  5922. nativeRange = this.document.body.createControlRange()
  5923. nativeRange.addElement(node)
  5924. nativeRange.select()
  5925. } catch (e) {}
  5926. return this
  5927. }
  5928. var bookmark = this.createBookmark(),
  5929. start = bookmark.start,
  5930. end
  5931. nativeRange = this.document.body.createTextRange()
  5932. nativeRange.moveToElementText(start)
  5933. nativeRange.moveStart('character', 1)
  5934. if (!this.collapsed) {
  5935. var nativeRangeEnd = this.document.body.createTextRange()
  5936. end = bookmark.end
  5937. nativeRangeEnd.moveToElementText(end)
  5938. nativeRange.setEndPoint('EndToEnd', nativeRangeEnd)
  5939. } else {
  5940. if (!noFillData && this.startContainer.nodeType != 3) {
  5941. //使用<span>|x<span>固定住光标
  5942. var tmpText = this.document.createTextNode(fillChar),
  5943. tmp = this.document.createElement('span')
  5944. tmp.appendChild(this.document.createTextNode(fillChar))
  5945. start.parentNode.insertBefore(tmp, start)
  5946. start.parentNode.insertBefore(tmpText, start)
  5947. //当点b,i,u时,不能清除i上边的b
  5948. removeFillData(this.document, tmpText)
  5949. fillData = tmpText
  5950. mergeSibling(tmp, 'previousSibling')
  5951. mergeSibling(start, 'nextSibling')
  5952. nativeRange.moveStart('character', -1)
  5953. nativeRange.collapse(true)
  5954. }
  5955. }
  5956. this.moveToBookmark(bookmark)
  5957. tmp && domUtils.remove(tmp)
  5958. //IE在隐藏状态下不支持range操作,catch一下
  5959. try {
  5960. nativeRange.select()
  5961. } catch (e) {}
  5962. return this
  5963. }
  5964. : function (notInsertFillData) {
  5965. function checkOffset(rng) {
  5966. function check(node, offset, dir) {
  5967. if (node.nodeType == 3 && node.nodeValue.length < offset) {
  5968. rng[dir + 'Offset'] = node.nodeValue.length
  5969. }
  5970. }
  5971. check(rng.startContainer, rng.startOffset, 'start')
  5972. check(rng.endContainer, rng.endOffset, 'end')
  5973. }
  5974. var win = domUtils.getWindow(this.document),
  5975. sel = win.getSelection(),
  5976. txtNode
  5977. //FF下关闭自动长高时滚动条在关闭dialog时会跳
  5978. //ff下如果不body.focus将不能定位闭合光标到编辑器内
  5979. browser.gecko ? this.document.body.focus() : win.focus()
  5980. if (sel) {
  5981. sel.removeAllRanges()
  5982. // trace:870 chrome/safari后边是br对于闭合得range不能定位 所以去掉了判断
  5983. // this.startContainer.nodeType != 3 &&! ((child = this.startContainer.childNodes[this.startOffset]) && child.nodeType == 1 && child.tagName == 'BR'
  5984. if (this.collapsed && !notInsertFillData) {
  5985. // //opear如果没有节点接着,原生的不能够定位,不能在body的第一级插入空白节点
  5986. // if (notInsertFillData && browser.opera && !domUtils.isBody(this.startContainer) && this.startContainer.nodeType == 1) {
  5987. // var tmp = this.document.createTextNode('');
  5988. // this.insertNode(tmp).setStart(tmp, 0).collapse(true);
  5989. // }
  5990. //
  5991. //处理光标落在文本节点的情况
  5992. //处理以下的情况
  5993. //<b>|xxxx</b>
  5994. //<b>xxxx</b>|xxxx
  5995. //xxxx<b>|</b>
  5996. var start = this.startContainer,
  5997. child = start
  5998. if (start.nodeType == 1) {
  5999. child = start.childNodes[this.startOffset]
  6000. }
  6001. if (
  6002. !(start.nodeType == 3 && this.startOffset) &&
  6003. (child
  6004. ? !child.previousSibling || child.previousSibling.nodeType != 3
  6005. : !start.lastChild || start.lastChild.nodeType != 3)
  6006. ) {
  6007. txtNode = this.document.createTextNode(fillChar)
  6008. //跟着前边走
  6009. this.insertNode(txtNode)
  6010. removeFillData(this.document, txtNode)
  6011. mergeSibling(txtNode, 'previousSibling')
  6012. mergeSibling(txtNode, 'nextSibling')
  6013. fillData = txtNode
  6014. this.setStart(txtNode, browser.webkit ? 1 : 0).collapse(true)
  6015. }
  6016. }
  6017. var nativeRange = this.document.createRange()
  6018. if (this.collapsed && browser.opera && this.startContainer.nodeType == 1) {
  6019. var child = this.startContainer.childNodes[this.startOffset]
  6020. if (!child) {
  6021. //往前靠拢
  6022. child = this.startContainer.lastChild
  6023. if (child && domUtils.isBr(child)) {
  6024. this.setStartBefore(child).collapse(true)
  6025. }
  6026. } else {
  6027. //向后靠拢
  6028. while (child && domUtils.isBlockElm(child)) {
  6029. if (child.nodeType == 1 && child.childNodes[0]) {
  6030. child = child.childNodes[0]
  6031. } else {
  6032. break
  6033. }
  6034. }
  6035. child && this.setStartBefore(child).collapse(true)
  6036. }
  6037. }
  6038. //是createAddress最后一位算的不准,现在这里进行微调
  6039. checkOffset(this)
  6040. nativeRange.setStart(this.startContainer, this.startOffset)
  6041. nativeRange.setEnd(this.endContainer, this.endOffset)
  6042. sel.addRange(nativeRange)
  6043. }
  6044. return this
  6045. },
  6046. /**
  6047. * 滚动到当前range开始的位置
  6048. * @method scrollToView
  6049. * @param { Window } win 当前range对象所属的window对象
  6050. * @return { UE.dom.Range } 当前Range对象
  6051. */
  6052. /**
  6053. * 滚动到距离当前range开始位置 offset 的位置处
  6054. * @method scrollToView
  6055. * @param { Window } win 当前range对象所属的window对象
  6056. * @param { Number } offset 距离range开始位置处的偏移量, 如果为正数, 则向下偏移, 反之, 则向上偏移
  6057. * @return { UE.dom.Range } 当前Range对象
  6058. */
  6059. scrollToView: function (win, offset) {
  6060. win = win ? window : domUtils.getWindow(this.document)
  6061. var me = this,
  6062. span = me.document.createElement('span')
  6063. //trace:717
  6064. span.innerHTML = '&nbsp;'
  6065. me.cloneRange().insertNode(span)
  6066. domUtils.scrollToView(span, win, offset)
  6067. domUtils.remove(span)
  6068. return me
  6069. },
  6070. /**
  6071. * 判断当前选区内容是否占位符
  6072. * @private
  6073. * @method inFillChar
  6074. * @return { Boolean } 如果是占位符返回true,否则返回false
  6075. */
  6076. inFillChar: function () {
  6077. var start = this.startContainer
  6078. if (
  6079. this.collapsed &&
  6080. start.nodeType == 3 &&
  6081. start.nodeValue.replace(new RegExp('^' + domUtils.fillChar), '').length + 1 ==
  6082. start.nodeValue.length
  6083. ) {
  6084. return true
  6085. }
  6086. return false
  6087. },
  6088. /**
  6089. * 保存
  6090. * @method createAddress
  6091. * @private
  6092. * @return { Boolean } 返回开始和结束的位置
  6093. * @example
  6094. * ```html
  6095. * <body>
  6096. * <p>
  6097. * aaaa
  6098. * <em>
  6099. * <!-- 选区开始 -->
  6100. * bbbb
  6101. * <!-- 选区结束 -->
  6102. * </em>
  6103. * </p>
  6104. *
  6105. * <script>
  6106. * //output: {startAddress:[0,1,0,0],endAddress:[0,1,0,4]}
  6107. * console.log( range.createAddress() );
  6108. * </script>
  6109. * </body>
  6110. * ```
  6111. */
  6112. createAddress: function (ignoreEnd, ignoreTxt) {
  6113. var addr = {},
  6114. me = this
  6115. function getAddress(isStart) {
  6116. var node = isStart ? me.startContainer : me.endContainer
  6117. var parents = domUtils.findParents(node, true, function (node) {
  6118. return !domUtils.isBody(node)
  6119. }),
  6120. addrs = []
  6121. for (var i = 0, ci; (ci = parents[i++]); ) {
  6122. addrs.push(domUtils.getNodeIndex(ci, ignoreTxt))
  6123. }
  6124. var firstIndex = 0
  6125. if (ignoreTxt) {
  6126. if (node.nodeType == 3) {
  6127. var tmpNode = node.previousSibling
  6128. while (tmpNode && tmpNode.nodeType == 3) {
  6129. firstIndex += tmpNode.nodeValue.replace(fillCharReg, '').length
  6130. tmpNode = tmpNode.previousSibling
  6131. }
  6132. firstIndex += isStart ? me.startOffset : me.endOffset // - (fillCharReg.test(node.nodeValue) ? 1 : 0 )
  6133. } else {
  6134. node = node.childNodes[isStart ? me.startOffset : me.endOffset]
  6135. if (node) {
  6136. firstIndex = domUtils.getNodeIndex(node, ignoreTxt)
  6137. } else {
  6138. node = isStart ? me.startContainer : me.endContainer
  6139. var first = node.firstChild
  6140. while (first) {
  6141. if (domUtils.isFillChar(first)) {
  6142. first = first.nextSibling
  6143. continue
  6144. }
  6145. firstIndex++
  6146. if (first.nodeType == 3) {
  6147. while (first && first.nodeType == 3) {
  6148. first = first.nextSibling
  6149. }
  6150. } else {
  6151. first = first.nextSibling
  6152. }
  6153. }
  6154. }
  6155. }
  6156. } else {
  6157. firstIndex = isStart ? (domUtils.isFillChar(node) ? 0 : me.startOffset) : me.endOffset
  6158. }
  6159. if (firstIndex < 0) {
  6160. firstIndex = 0
  6161. }
  6162. addrs.push(firstIndex)
  6163. return addrs
  6164. }
  6165. addr.startAddress = getAddress(true)
  6166. if (!ignoreEnd) {
  6167. addr.endAddress = me.collapsed ? [].concat(addr.startAddress) : getAddress()
  6168. }
  6169. return addr
  6170. },
  6171. /**
  6172. * 保存
  6173. * @method createAddress
  6174. * @private
  6175. * @return { Boolean } 返回开始和结束的位置
  6176. * @example
  6177. * ```html
  6178. * <body>
  6179. * <p>
  6180. * aaaa
  6181. * <em>
  6182. * <!-- 选区开始 -->
  6183. * bbbb
  6184. * <!-- 选区结束 -->
  6185. * </em>
  6186. * </p>
  6187. *
  6188. * <script>
  6189. * var range = editor.selection.getRange();
  6190. * range.moveToAddress({startAddress:[0,1,0,0],endAddress:[0,1,0,4]});
  6191. * range.select();
  6192. * //output: 'bbbb'
  6193. * console.log(editor.selection.getText());
  6194. * </script>
  6195. * </body>
  6196. * ```
  6197. */
  6198. moveToAddress: function (addr, ignoreEnd) {
  6199. var me = this
  6200. function getNode(address, isStart) {
  6201. var tmpNode = me.document.body,
  6202. parentNode,
  6203. offset
  6204. for (var i = 0, ci, l = address.length; i < l; i++) {
  6205. ci = address[i]
  6206. parentNode = tmpNode
  6207. tmpNode = tmpNode.childNodes[ci]
  6208. if (!tmpNode) {
  6209. offset = ci
  6210. break
  6211. }
  6212. }
  6213. if (isStart) {
  6214. if (tmpNode) {
  6215. me.setStartBefore(tmpNode)
  6216. } else {
  6217. me.setStart(parentNode, offset)
  6218. }
  6219. } else {
  6220. if (tmpNode) {
  6221. me.setEndBefore(tmpNode)
  6222. } else {
  6223. me.setEnd(parentNode, offset)
  6224. }
  6225. }
  6226. }
  6227. getNode(addr.startAddress, true)
  6228. !ignoreEnd && addr.endAddress && getNode(addr.endAddress)
  6229. return me
  6230. },
  6231. /**
  6232. * 判断给定的Range对象是否和当前Range对象表示的是同一个选区
  6233. * @method equals
  6234. * @param { UE.dom.Range } 需要判断的Range对象
  6235. * @return { Boolean } 如果给定的Range对象与当前Range对象表示的是同一个选区, 则返回true, 否则返回false
  6236. */
  6237. equals: function (rng) {
  6238. for (var p in this) {
  6239. if (this.hasOwnProperty(p)) {
  6240. if (this[p] !== rng[p]) return false
  6241. }
  6242. }
  6243. return true
  6244. },
  6245. /**
  6246. * 遍历range内的节点。每当遍历一个节点时, 都会执行参数项 doFn 指定的函数, 该函数的接受当前遍历的节点
  6247. * 作为其参数。
  6248. * @method traversal
  6249. * @param { Function } doFn 对每个遍历的节点要执行的方法, 该方法接受当前遍历的节点作为其参数
  6250. * @return { UE.dom.Range } 当前range对象
  6251. * @example
  6252. * ```html
  6253. *
  6254. * <body>
  6255. *
  6256. * <!-- 选区开始 -->
  6257. * <span></span>
  6258. * <a></a>
  6259. * <!-- 选区结束 -->
  6260. * </body>
  6261. *
  6262. * <script>
  6263. *
  6264. * //output: <span></span><a></a>
  6265. * console.log( range.cloneContents() );
  6266. *
  6267. * range.traversal( function ( node ) {
  6268. *
  6269. * if ( node.nodeType === 1 ) {
  6270. * node.className = "test";
  6271. * }
  6272. *
  6273. * } );
  6274. *
  6275. * //output: <span class="test"></span><a class="test"></a>
  6276. * console.log( range.cloneContents() );
  6277. *
  6278. * </script>
  6279. * ```
  6280. */
  6281. /**
  6282. * 遍历range内的节点。
  6283. * 每当遍历一个节点时, 都会执行参数项 doFn 指定的函数, 该函数的接受当前遍历的节点
  6284. * 作为其参数。
  6285. * 可以通过参数项 filterFn 来指定一个过滤器, 只有符合该过滤器过滤规则的节点才会触
  6286. * 发doFn函数的执行
  6287. * @method traversal
  6288. * @param { Function } doFn 对每个遍历的节点要执行的方法, 该方法接受当前遍历的节点作为其参数
  6289. * @param { Function } filterFn 过滤器, 该函数接受当前遍历的节点作为参数, 如果该节点满足过滤
  6290. * 规则, 请返回true, 该节点会触发doFn, 否则, 请返回false, 则该节点不
  6291. * 会触发doFn。
  6292. * @return { UE.dom.Range } 当前range对象
  6293. * @see UE.dom.Range:traversal(Function)
  6294. * @example
  6295. * ```html
  6296. *
  6297. * <body>
  6298. *
  6299. * <!-- 选区开始 -->
  6300. * <span></span>
  6301. * <a></a>
  6302. * <!-- 选区结束 -->
  6303. * </body>
  6304. *
  6305. * <script>
  6306. *
  6307. * //output: <span></span><a></a>
  6308. * console.log( range.cloneContents() );
  6309. *
  6310. * range.traversal( function ( node ) {
  6311. *
  6312. * node.className = "test";
  6313. *
  6314. * }, function ( node ) {
  6315. * return node.nodeType === 1;
  6316. * } );
  6317. *
  6318. * //output: <span class="test"></span><a class="test"></a>
  6319. * console.log( range.cloneContents() );
  6320. *
  6321. * </script>
  6322. * ```
  6323. */
  6324. traversal: function (doFn, filterFn) {
  6325. if (this.collapsed) return this
  6326. var bookmark = this.createBookmark(),
  6327. end = bookmark.end,
  6328. current = domUtils.getNextDomNode(bookmark.start, false, filterFn)
  6329. while (
  6330. current &&
  6331. current !== end &&
  6332. domUtils.getPosition(current, end) & domUtils.POSITION_PRECEDING
  6333. ) {
  6334. var tmpNode = domUtils.getNextDomNode(current, false, filterFn)
  6335. doFn(current)
  6336. current = tmpNode
  6337. }
  6338. return this.moveToBookmark(bookmark)
  6339. }
  6340. }
  6341. })()
  6342. // core/Selection.js
  6343. /**
  6344. * 选集
  6345. * @file
  6346. * @module UE.dom
  6347. * @class Selection
  6348. * @since 1.2.6.1
  6349. */
  6350. /**
  6351. * 选区集合
  6352. * @unfile
  6353. * @module UE.dom
  6354. * @class Selection
  6355. */
  6356. ;(function () {
  6357. function getBoundaryInformation(range, start) {
  6358. var getIndex = domUtils.getNodeIndex
  6359. range = range.duplicate()
  6360. range.collapse(start)
  6361. var parent = range.parentElement()
  6362. //如果节点里没有子节点,直接退出
  6363. if (!parent.hasChildNodes()) {
  6364. return { container: parent, offset: 0 }
  6365. }
  6366. var siblings = parent.children,
  6367. child,
  6368. testRange = range.duplicate(),
  6369. startIndex = 0,
  6370. endIndex = siblings.length - 1,
  6371. index = -1,
  6372. distance
  6373. while (startIndex <= endIndex) {
  6374. index = Math.floor((startIndex + endIndex) / 2)
  6375. child = siblings[index]
  6376. testRange.moveToElementText(child)
  6377. var position = testRange.compareEndPoints('StartToStart', range)
  6378. if (position > 0) {
  6379. endIndex = index - 1
  6380. } else if (position < 0) {
  6381. startIndex = index + 1
  6382. } else {
  6383. //trace:1043
  6384. return { container: parent, offset: getIndex(child) }
  6385. }
  6386. }
  6387. if (index == -1) {
  6388. testRange.moveToElementText(parent)
  6389. testRange.setEndPoint('StartToStart', range)
  6390. distance = testRange.text.replace(/(\r\n|\r)/g, '\n').length
  6391. siblings = parent.childNodes
  6392. if (!distance) {
  6393. child = siblings[siblings.length - 1]
  6394. return { container: child, offset: child.nodeValue.length }
  6395. }
  6396. var i = siblings.length
  6397. while (distance > 0) {
  6398. distance -= siblings[--i].nodeValue.length
  6399. }
  6400. return { container: siblings[i], offset: -distance }
  6401. }
  6402. testRange.collapse(position > 0)
  6403. testRange.setEndPoint(position > 0 ? 'StartToStart' : 'EndToStart', range)
  6404. distance = testRange.text.replace(/(\r\n|\r)/g, '\n').length
  6405. if (!distance) {
  6406. return dtd.$empty[child.tagName] || dtd.$nonChild[child.tagName]
  6407. ? {
  6408. container: parent,
  6409. offset: getIndex(child) + (position > 0 ? 0 : 1)
  6410. }
  6411. : {
  6412. container: child,
  6413. offset: position > 0 ? 0 : child.childNodes.length
  6414. }
  6415. }
  6416. while (distance > 0) {
  6417. try {
  6418. var pre = child
  6419. child = child[position > 0 ? 'previousSibling' : 'nextSibling']
  6420. distance -= child.nodeValue.length
  6421. } catch (e) {
  6422. return { container: parent, offset: getIndex(pre) }
  6423. }
  6424. }
  6425. return {
  6426. container: child,
  6427. offset: position > 0 ? -distance : child.nodeValue.length + distance
  6428. }
  6429. }
  6430. /**
  6431. * 将ieRange转换为Range对象
  6432. * @param {Range} ieRange ieRange对象
  6433. * @param {Range} range Range对象
  6434. * @return {Range} range 返回转换后的Range对象
  6435. */
  6436. function transformIERangeToRange(ieRange, range) {
  6437. if (ieRange.item) {
  6438. range.selectNode(ieRange.item(0))
  6439. } else {
  6440. var bi = getBoundaryInformation(ieRange, true)
  6441. range.setStart(bi.container, bi.offset)
  6442. if (ieRange.compareEndPoints('StartToEnd', ieRange) != 0) {
  6443. bi = getBoundaryInformation(ieRange, false)
  6444. range.setEnd(bi.container, bi.offset)
  6445. }
  6446. }
  6447. return range
  6448. }
  6449. /**
  6450. * 获得ieRange
  6451. * @param {Selection} sel Selection对象
  6452. * @return {ieRange} 得到ieRange
  6453. */
  6454. function _getIERange(sel) {
  6455. var ieRange
  6456. //ie下有可能报错
  6457. try {
  6458. ieRange = sel.getNative().createRange()
  6459. } catch (e) {
  6460. return null
  6461. }
  6462. var el = ieRange.item ? ieRange.item(0) : ieRange.parentElement()
  6463. if ((el.ownerDocument || el) === sel.document) {
  6464. return ieRange
  6465. }
  6466. return null
  6467. }
  6468. var Selection = (dom.Selection = function (doc) {
  6469. var me = this,
  6470. iframe
  6471. me.document = doc
  6472. if (browser.ie9below) {
  6473. iframe = domUtils.getWindow(doc).frameElement
  6474. domUtils.on(iframe, 'beforedeactivate', function () {
  6475. me._bakIERange = me.getIERange()
  6476. })
  6477. domUtils.on(iframe, 'activate', function () {
  6478. try {
  6479. if (!_getIERange(me) && me._bakIERange) {
  6480. me._bakIERange.select()
  6481. }
  6482. } catch (ex) {}
  6483. me._bakIERange = null
  6484. })
  6485. }
  6486. iframe = doc = null
  6487. })
  6488. Selection.prototype = {
  6489. rangeInBody: function (rng, txtRange) {
  6490. var node =
  6491. browser.ie9below || txtRange
  6492. ? rng.item
  6493. ? rng.item()
  6494. : rng.parentElement()
  6495. : rng.startContainer
  6496. return node === this.document.body || domUtils.inDoc(node, this.document)
  6497. },
  6498. /**
  6499. * 获取原生seleciton对象
  6500. * @method getNative
  6501. * @return { Object } 获得selection对象
  6502. * @example
  6503. * ```javascript
  6504. * editor.selection.getNative();
  6505. * ```
  6506. */
  6507. getNative: function () {
  6508. var doc = this.document
  6509. try {
  6510. return !doc
  6511. ? null
  6512. : browser.ie9below
  6513. ? doc.selection
  6514. : domUtils.getWindow(doc).getSelection()
  6515. } catch (e) {
  6516. return null
  6517. }
  6518. },
  6519. /**
  6520. * 获得ieRange
  6521. * @method getIERange
  6522. * @return { Object } 返回ie原生的Range
  6523. * @example
  6524. * ```javascript
  6525. * editor.selection.getIERange();
  6526. * ```
  6527. */
  6528. getIERange: function () {
  6529. var ieRange = _getIERange(this)
  6530. if (!ieRange) {
  6531. if (this._bakIERange) {
  6532. return this._bakIERange
  6533. }
  6534. }
  6535. return ieRange
  6536. },
  6537. /**
  6538. * 缓存当前选区的range和选区的开始节点
  6539. * @method cache
  6540. */
  6541. cache: function () {
  6542. this.clear()
  6543. this._cachedRange = this.getRange()
  6544. this._cachedStartElement = this.getStart()
  6545. this._cachedStartElementPath = this.getStartElementPath()
  6546. },
  6547. /**
  6548. * 获取选区开始位置的父节点到body
  6549. * @method getStartElementPath
  6550. * @return { Array } 返回父节点集合
  6551. * @example
  6552. * ```javascript
  6553. * editor.selection.getStartElementPath();
  6554. * ```
  6555. */
  6556. getStartElementPath: function () {
  6557. if (this._cachedStartElementPath) {
  6558. return this._cachedStartElementPath
  6559. }
  6560. var start = this.getStart()
  6561. if (start) {
  6562. return domUtils.findParents(start, true, null, true)
  6563. }
  6564. return []
  6565. },
  6566. /**
  6567. * 清空缓存
  6568. * @method clear
  6569. */
  6570. clear: function () {
  6571. this._cachedStartElementPath = this._cachedRange = this._cachedStartElement = null
  6572. },
  6573. /**
  6574. * 编辑器是否得到了选区
  6575. * @method isFocus
  6576. */
  6577. isFocus: function () {
  6578. try {
  6579. if (browser.ie9below) {
  6580. var nativeRange = _getIERange(this)
  6581. return !!(nativeRange && this.rangeInBody(nativeRange))
  6582. } else {
  6583. return !!this.getNative().rangeCount
  6584. }
  6585. } catch (e) {
  6586. return false
  6587. }
  6588. },
  6589. /**
  6590. * 获取选区对应的Range
  6591. * @method getRange
  6592. * @return { Object } 得到Range对象
  6593. * @example
  6594. * ```javascript
  6595. * editor.selection.getRange();
  6596. * ```
  6597. */
  6598. getRange: function () {
  6599. var me = this
  6600. function optimze(range) {
  6601. var child = me.document.body.firstChild,
  6602. collapsed = range.collapsed
  6603. while (child && child.firstChild) {
  6604. range.setStart(child, 0)
  6605. child = child.firstChild
  6606. }
  6607. if (!range.startContainer) {
  6608. range.setStart(me.document.body, 0)
  6609. }
  6610. if (collapsed) {
  6611. range.collapse(true)
  6612. }
  6613. }
  6614. if (me._cachedRange != null) {
  6615. return this._cachedRange
  6616. }
  6617. var range = new baidu.editor.dom.Range(me.document)
  6618. if (browser.ie9below) {
  6619. var nativeRange = me.getIERange()
  6620. if (nativeRange) {
  6621. //备份的_bakIERange可能已经实效了,dom树发生了变化比如从源码模式切回来,所以try一下,实效就放到body开始位置
  6622. try {
  6623. transformIERangeToRange(nativeRange, range)
  6624. } catch (e) {
  6625. optimze(range)
  6626. }
  6627. } else {
  6628. optimze(range)
  6629. }
  6630. } else {
  6631. var sel = me.getNative()
  6632. if (sel && sel.rangeCount) {
  6633. var firstRange = sel.getRangeAt(0)
  6634. var lastRange = sel.getRangeAt(sel.rangeCount - 1)
  6635. range
  6636. .setStart(firstRange.startContainer, firstRange.startOffset)
  6637. .setEnd(lastRange.endContainer, lastRange.endOffset)
  6638. if (range.collapsed && domUtils.isBody(range.startContainer) && !range.startOffset) {
  6639. optimze(range)
  6640. }
  6641. } else {
  6642. //trace:1734 有可能已经不在dom树上了,标识的节点
  6643. if (this._bakRange && domUtils.inDoc(this._bakRange.startContainer, this.document)) {
  6644. return this._bakRange
  6645. }
  6646. optimze(range)
  6647. }
  6648. }
  6649. return (this._bakRange = range)
  6650. },
  6651. /**
  6652. * 获取开始元素,用于状态反射
  6653. * @method getStart
  6654. * @return { Element } 获得开始元素
  6655. * @example
  6656. * ```javascript
  6657. * editor.selection.getStart();
  6658. * ```
  6659. */
  6660. getStart: function () {
  6661. if (this._cachedStartElement) {
  6662. return this._cachedStartElement
  6663. }
  6664. var range = browser.ie9below ? this.getIERange() : this.getRange(),
  6665. tmpRange,
  6666. start,
  6667. tmp,
  6668. parent
  6669. if (browser.ie9below) {
  6670. if (!range) {
  6671. //todo 给第一个值可能会有问题
  6672. return this.document.body.firstChild
  6673. }
  6674. //control元素
  6675. if (range.item) {
  6676. return range.item(0)
  6677. }
  6678. tmpRange = range.duplicate()
  6679. //修正ie下<b>x</b>[xx] 闭合后 <b>x|</b>xx
  6680. tmpRange.text.length > 0 && tmpRange.moveStart('character', 1)
  6681. tmpRange.collapse(1)
  6682. start = tmpRange.parentElement()
  6683. parent = tmp = range.parentElement()
  6684. while ((tmp = tmp.parentNode)) {
  6685. if (tmp == start) {
  6686. start = parent
  6687. break
  6688. }
  6689. }
  6690. } else {
  6691. range.shrinkBoundary()
  6692. start = range.startContainer
  6693. if (start.nodeType == 1 && start.hasChildNodes()) {
  6694. start = start.childNodes[Math.min(start.childNodes.length - 1, range.startOffset)]
  6695. }
  6696. if (start.nodeType == 3) {
  6697. return start.parentNode
  6698. }
  6699. }
  6700. return start
  6701. },
  6702. /**
  6703. * 得到选区中的文本
  6704. * @method getText
  6705. * @return { String } 选区中包含的文本
  6706. * @example
  6707. * ```javascript
  6708. * editor.selection.getText();
  6709. * ```
  6710. */
  6711. getText: function () {
  6712. var nativeSel, nativeRange
  6713. if (this.isFocus() && (nativeSel = this.getNative())) {
  6714. nativeRange = browser.ie9below ? nativeSel.createRange() : nativeSel.getRangeAt(0)
  6715. return browser.ie9below ? nativeRange.text : nativeRange.toString()
  6716. }
  6717. return ''
  6718. },
  6719. /**
  6720. * 清除选区
  6721. * @method clearRange
  6722. * @example
  6723. * ```javascript
  6724. * editor.selection.clearRange();
  6725. * ```
  6726. */
  6727. clearRange: function () {
  6728. this.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']()
  6729. }
  6730. }
  6731. })()
  6732. // core/Editor.js
  6733. /**
  6734. * 编辑器主类,包含编辑器提供的大部分公用接口
  6735. * @file
  6736. * @module UE
  6737. * @class Editor
  6738. * @since 1.2.6.1
  6739. */
  6740. /**
  6741. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  6742. * @unfile
  6743. * @module UE
  6744. */
  6745. /**
  6746. * UEditor的核心类,为用户提供与编辑器交互的接口。
  6747. * @unfile
  6748. * @module UE
  6749. * @class Editor
  6750. */
  6751. ;(function () {
  6752. var uid = 0,
  6753. _selectionChangeTimer
  6754. /**
  6755. * 获取编辑器的html内容,赋值到编辑器所在表单的textarea文本域里面
  6756. * @private
  6757. * @method setValue
  6758. * @param { UE.Editor } editor 编辑器事例
  6759. */
  6760. function setValue(form, editor) {
  6761. var textarea
  6762. if (editor.textarea) {
  6763. if (utils.isString(editor.textarea)) {
  6764. for (
  6765. var i = 0, ti, tis = domUtils.getElementsByTagName(form, 'textarea');
  6766. (ti = tis[i++]);
  6767. ) {
  6768. if (ti.id == 'ueditor_textarea_' + editor.options.textarea) {
  6769. textarea = ti
  6770. break
  6771. }
  6772. }
  6773. } else {
  6774. textarea = editor.textarea
  6775. }
  6776. }
  6777. if (!textarea) {
  6778. form.appendChild(
  6779. (textarea = domUtils.createElement(document, 'textarea', {
  6780. name: editor.options.textarea,
  6781. id: 'ueditor_textarea_' + editor.options.textarea,
  6782. style: 'display:none'
  6783. }))
  6784. )
  6785. //不要产生多个textarea
  6786. editor.textarea = textarea
  6787. }
  6788. !textarea.getAttribute('name') && textarea.setAttribute('name', editor.options.textarea)
  6789. textarea.value = editor.hasContents()
  6790. ? editor.options.allHtmlEnabled
  6791. ? editor.getAllHtml()
  6792. : editor.getContent(null, null, true)
  6793. : ''
  6794. }
  6795. function loadPlugins(me) {
  6796. //初始化插件
  6797. for (var pi in UE.plugins) {
  6798. UE.plugins[pi].call(me)
  6799. }
  6800. }
  6801. function checkCurLang(I18N) {
  6802. for (var lang in I18N) {
  6803. return lang
  6804. }
  6805. }
  6806. function langReadied(me) {
  6807. me.langIsReady = true
  6808. me.fireEvent('langReady')
  6809. }
  6810. /**
  6811. * 编辑器准备就绪后会触发该事件
  6812. * @module UE
  6813. * @class Editor
  6814. * @event ready
  6815. * @remind render方法执行完成之后,会触发该事件
  6816. * @remind
  6817. * @example
  6818. * ```javascript
  6819. * editor.addListener( 'ready', function( editor ) {
  6820. * editor.execCommand( 'focus' ); //编辑器家在完成后,让编辑器拿到焦点
  6821. * } );
  6822. * ```
  6823. */
  6824. /**
  6825. * 执行destroy方法,会触发该事件
  6826. * @module UE
  6827. * @class Editor
  6828. * @event destroy
  6829. * @see UE.Editor:destroy()
  6830. */
  6831. /**
  6832. * 执行reset方法,会触发该事件
  6833. * @module UE
  6834. * @class Editor
  6835. * @event reset
  6836. * @see UE.Editor:reset()
  6837. */
  6838. /**
  6839. * 执行focus方法,会触发该事件
  6840. * @module UE
  6841. * @class Editor
  6842. * @event focus
  6843. * @see UE.Editor:focus(Boolean)
  6844. */
  6845. /**
  6846. * 语言加载完成会触发该事件
  6847. * @module UE
  6848. * @class Editor
  6849. * @event langReady
  6850. */
  6851. /**
  6852. * 运行命令之后会触发该命令
  6853. * @module UE
  6854. * @class Editor
  6855. * @event beforeExecCommand
  6856. */
  6857. /**
  6858. * 运行命令之后会触发该命令
  6859. * @module UE
  6860. * @class Editor
  6861. * @event afterExecCommand
  6862. */
  6863. /**
  6864. * 运行命令之前会触发该命令
  6865. * @module UE
  6866. * @class Editor
  6867. * @event firstBeforeExecCommand
  6868. */
  6869. /**
  6870. * 在getContent方法执行之前会触发该事件
  6871. * @module UE
  6872. * @class Editor
  6873. * @event beforeGetContent
  6874. * @see UE.Editor:getContent()
  6875. */
  6876. /**
  6877. * 在getContent方法执行之后会触发该事件
  6878. * @module UE
  6879. * @class Editor
  6880. * @event afterGetContent
  6881. * @see UE.Editor:getContent()
  6882. */
  6883. /**
  6884. * 在getAllHtml方法执行时会触发该事件
  6885. * @module UE
  6886. * @class Editor
  6887. * @event getAllHtml
  6888. * @see UE.Editor:getAllHtml()
  6889. */
  6890. /**
  6891. * 在setContent方法执行之前会触发该事件
  6892. * @module UE
  6893. * @class Editor
  6894. * @event beforeSetContent
  6895. * @see UE.Editor:setContent(String)
  6896. */
  6897. /**
  6898. * 在setContent方法执行之后会触发该事件
  6899. * @module UE
  6900. * @class Editor
  6901. * @event afterSetContent
  6902. * @see UE.Editor:setContent(String)
  6903. */
  6904. /**
  6905. * 每当编辑器内部选区发生改变时,将触发该事件
  6906. * @event selectionchange
  6907. * @warning 该事件的触发非常频繁,不建议在该事件的处理过程中做重量级的处理
  6908. * @example
  6909. * ```javascript
  6910. * editor.addListener( 'selectionchange', function( editor ) {
  6911. * console.log('选区发生改变');
  6912. * }
  6913. */
  6914. /**
  6915. * 在所有selectionchange的监听函数执行之前,会触发该事件
  6916. * @module UE
  6917. * @class Editor
  6918. * @event beforeSelectionChange
  6919. * @see UE.Editor:selectionchange
  6920. */
  6921. /**
  6922. * 在所有selectionchange的监听函数执行完之后,会触发该事件
  6923. * @module UE
  6924. * @class Editor
  6925. * @event afterSelectionChange
  6926. * @see UE.Editor:selectionchange
  6927. */
  6928. /**
  6929. * 编辑器内容发生改变时会触发该事件
  6930. * @module UE
  6931. * @class Editor
  6932. * @event contentChange
  6933. */
  6934. /**
  6935. * 以默认参数构建一个编辑器实例
  6936. * @constructor
  6937. * @remind 通过 改构造方法实例化的编辑器,不带ui层.需要render到一个容器,编辑器实例才能正常渲染到页面
  6938. * @example
  6939. * ```javascript
  6940. * var editor = new UE.Editor();
  6941. * editor.execCommand('blod');
  6942. * ```
  6943. * @see UE.Config
  6944. */
  6945. /**
  6946. * 以给定的参数集合创建一个编辑器实例,对于未指定的参数,将应用默认参数。
  6947. * @constructor
  6948. * @remind 通过 改构造方法实例化的编辑器,不带ui层.需要render到一个容器,编辑器实例才能正常渲染到页面
  6949. * @param { Object } setting 创建编辑器的参数
  6950. * @example
  6951. * ```javascript
  6952. * var editor = new UE.Editor();
  6953. * editor.execCommand('blod');
  6954. * ```
  6955. * @see UE.Config
  6956. */
  6957. var Editor = (UE.Editor = function (options) {
  6958. var me = this
  6959. me.uid = uid++
  6960. EventBase.call(me)
  6961. me.commands = {}
  6962. me.options = utils.extend(utils.clone(options || {}), UEDITOR_CONFIG, true)
  6963. me.shortcutkeys = {}
  6964. me.inputRules = []
  6965. me.outputRules = []
  6966. //设置默认的常用属性
  6967. me.setOpt(Editor.defaultOptions(me))
  6968. /* 尝试异步加载后台配置 */
  6969. // me.loadServerConfig()
  6970. if (!utils.isEmptyObject(UE.I18N)) {
  6971. //修改默认的语言类型
  6972. me.options.lang = checkCurLang(UE.I18N)
  6973. UE.plugin.load(me)
  6974. langReadied(me)
  6975. } else {
  6976. utils.loadFile(
  6977. document,
  6978. {
  6979. src: me.options.langPath + me.options.lang + '/' + me.options.lang + '.js',
  6980. tag: 'script',
  6981. type: 'text/javascript',
  6982. defer: 'defer'
  6983. },
  6984. function () {
  6985. UE.plugin.load(me)
  6986. langReadied(me)
  6987. }
  6988. )
  6989. }
  6990. UE.instants['ueditorInstant' + me.uid] = me
  6991. })
  6992. Editor.prototype = {
  6993. registerCommand: function (name, obj) {
  6994. this.commands[name] = obj
  6995. },
  6996. /**
  6997. * 编辑器对外提供的监听ready事件的接口, 通过调用该方法,达到的效果与监听ready事件是一致的
  6998. * @method ready
  6999. * @param { Function } fn 编辑器ready之后所执行的回调, 如果在注册事件之前编辑器已经ready,将会
  7000. * 立即触发该回调。
  7001. * @remind 需要等待编辑器加载完成后才能执行的代码,可以使用该方法传入
  7002. * @example
  7003. * ```javascript
  7004. * editor.ready( function( editor ) {
  7005. * editor.setContent('初始化完毕');
  7006. * } );
  7007. * ```
  7008. * @see UE.Editor.event:ready
  7009. */
  7010. ready: function (fn) {
  7011. var me = this
  7012. if (fn) {
  7013. me.isReady ? fn.apply(me) : me.addListener('ready', fn)
  7014. }
  7015. },
  7016. /**
  7017. * 该方法是提供给插件里面使用,设置配置项默认值
  7018. * @method setOpt
  7019. * @warning 三处设置配置项的优先级: 实例化时传入参数 > setOpt()设置 > config文件里设置
  7020. * @warning 该方法仅供编辑器插件内部和编辑器初始化时调用,其他地方不能调用。
  7021. * @param { String } key 编辑器的可接受的选项名称
  7022. * @param { * } val 该选项可接受的值
  7023. * @example
  7024. * ```javascript
  7025. * editor.setOpt( 'initContent', '欢迎使用编辑器' );
  7026. * ```
  7027. */
  7028. /**
  7029. * 该方法是提供给插件里面使用,以{key:value}集合的方式设置插件内用到的配置项默认值
  7030. * @method setOpt
  7031. * @warning 三处设置配置项的优先级: 实例化时传入参数 > setOpt()设置 > config文件里设置
  7032. * @warning 该方法仅供编辑器插件内部和编辑器初始化时调用,其他地方不能调用。
  7033. * @param { Object } options 将要设置的选项的键值对对象
  7034. * @example
  7035. * ```javascript
  7036. * editor.setOpt( {
  7037. * 'initContent': '欢迎使用编辑器'
  7038. * } );
  7039. * ```
  7040. */
  7041. setOpt: function (key, val) {
  7042. var obj = {}
  7043. if (utils.isString(key)) {
  7044. obj[key] = val
  7045. } else {
  7046. obj = key
  7047. }
  7048. utils.extend(this.options, obj, true)
  7049. },
  7050. getOpt: function (key) {
  7051. return this.options[key]
  7052. },
  7053. /**
  7054. * 销毁编辑器实例,使用textarea代替
  7055. * @method destroy
  7056. * @example
  7057. * ```javascript
  7058. * editor.destroy();
  7059. * ```
  7060. */
  7061. destroy: function () {
  7062. var me = this
  7063. me.fireEvent('destroy')
  7064. var container = me.container.parentNode
  7065. var textarea = me.textarea
  7066. if (!textarea) {
  7067. textarea = document.createElement('textarea')
  7068. container.parentNode.insertBefore(textarea, container)
  7069. } else {
  7070. textarea.style.display = ''
  7071. }
  7072. textarea.style.width = me.iframe.offsetWidth + 'px'
  7073. textarea.style.height = me.iframe.offsetHeight + 'px'
  7074. textarea.value = me.getContent()
  7075. textarea.id = me.key
  7076. container.innerHTML = ''
  7077. domUtils.remove(container)
  7078. var key = me.key
  7079. //trace:2004
  7080. for (var p in me) {
  7081. if (me.hasOwnProperty(p)) {
  7082. delete this[p]
  7083. }
  7084. }
  7085. UE.delEditor(key)
  7086. },
  7087. /**
  7088. * 渲染编辑器的DOM到指定容器
  7089. * @method render
  7090. * @param { String } containerId 指定一个容器ID
  7091. * @remind 执行该方法,会触发ready事件
  7092. * @warning 必须且只能调用一次
  7093. */
  7094. /**
  7095. * 渲染编辑器的DOM到指定容器
  7096. * @method render
  7097. * @param { Element } containerDom 直接指定容器对象
  7098. * @remind 执行该方法,会触发ready事件
  7099. * @warning 必须且只能调用一次
  7100. */
  7101. render: function (container) {
  7102. var me = this,
  7103. options = me.options,
  7104. getStyleValue = function (attr) {
  7105. return parseInt(domUtils.getComputedStyle(container, attr))
  7106. }
  7107. if (utils.isString(container)) {
  7108. container = document.getElementById(container)
  7109. }
  7110. if (container) {
  7111. if (options.initialFrameWidth) {
  7112. options.minFrameWidth = options.initialFrameWidth
  7113. } else {
  7114. options.minFrameWidth = options.initialFrameWidth = container.offsetWidth
  7115. }
  7116. if (options.initialFrameHeight) {
  7117. options.minFrameHeight = options.initialFrameHeight
  7118. } else {
  7119. options.initialFrameHeight = options.minFrameHeight = container.offsetHeight
  7120. }
  7121. container.style.width = /%$/.test(options.initialFrameWidth)
  7122. ? '100%'
  7123. : options.initialFrameWidth -
  7124. getStyleValue('padding-left') -
  7125. getStyleValue('padding-right') +
  7126. 'px'
  7127. container.style.height = /%$/.test(options.initialFrameHeight)
  7128. ? '100%'
  7129. : options.initialFrameHeight -
  7130. getStyleValue('padding-top') -
  7131. getStyleValue('padding-bottom') +
  7132. 'px'
  7133. container.style.zIndex = options.zIndex
  7134. var html =
  7135. (ie && browser.version < 9 ? '' : '<!DOCTYPE html>') +
  7136. "<html xmlns='http://www.w3.org/1999/xhtml' class='view' ><head>" +
  7137. "<style type='text/css'>" +
  7138. //设置四周的留边
  7139. '.view{padding:0;word-wrap:break-word;cursor:text;height:90%;}\n' +
  7140. //设置默认字体和字号
  7141. //font-family不能呢随便改,在safari下fillchar会有解析问题
  7142. 'body{margin:8px;font-family:sans-serif;font-size:16px;}' +
  7143. //设置段落间距
  7144. 'p{margin:5px 0;}</style>' +
  7145. (options.iframeCssUrl
  7146. ? "<link rel='stylesheet' type='text/css' href='" +
  7147. utils.unhtml(options.iframeCssUrl) +
  7148. "'/>"
  7149. : '') +
  7150. (options.initialStyle ? '<style>' + options.initialStyle + '</style>' : '') +
  7151. "</head><body class='view' ></body>" +
  7152. "<script type='text/javascript' " +
  7153. (ie ? "defer='defer'" : '') +
  7154. " id='_initialScript'>" +
  7155. "setTimeout(function(){editor = window.parent.UE.instants['ueditorInstant" +
  7156. me.uid +
  7157. "'];editor._setup(document);},0);" +
  7158. "var _tmpScript = document.getElementById('_initialScript');_tmpScript.parentNode.removeChild(_tmpScript);</script></html>"
  7159. container.appendChild(
  7160. domUtils.createElement(document, 'iframe', {
  7161. id: 'ueditor_' + me.uid,
  7162. width: '100%',
  7163. height: '100%',
  7164. frameborder: '0',
  7165. //先注释掉了,加的原因忘记了,但开启会直接导致全屏模式下内容多时不会出现滚动条
  7166. // scrolling :'no',
  7167. src:
  7168. 'javascript:void(function(){document.open();' +
  7169. (options.customDomain && document.domain != location.hostname
  7170. ? 'document.domain="' + document.domain + '";'
  7171. : '') +
  7172. 'document.write("' +
  7173. html +
  7174. '");document.close();}())'
  7175. })
  7176. )
  7177. container.style.overflow = 'hidden'
  7178. //解决如果是给定的百分比,会导致高度算不对的问题
  7179. setTimeout(function () {
  7180. if (/%$/.test(options.initialFrameWidth)) {
  7181. options.minFrameWidth = options.initialFrameWidth = container.offsetWidth
  7182. //如果这里给定宽度,会导致ie在拖动窗口大小时,编辑区域不随着变化
  7183. // container.style.width = options.initialFrameWidth + 'px';
  7184. }
  7185. if (/%$/.test(options.initialFrameHeight)) {
  7186. options.minFrameHeight = options.initialFrameHeight = container.offsetHeight
  7187. container.style.height = options.initialFrameHeight + 'px'
  7188. }
  7189. })
  7190. }
  7191. },
  7192. /**
  7193. * 编辑器初始化
  7194. * @method _setup
  7195. * @private
  7196. * @param { Element } doc 编辑器Iframe中的文档对象
  7197. */
  7198. _setup: function (doc) {
  7199. var me = this,
  7200. options = me.options
  7201. if (ie) {
  7202. doc.body.disabled = true
  7203. doc.body.contentEditable = true
  7204. doc.body.disabled = false
  7205. } else {
  7206. doc.body.contentEditable = true
  7207. }
  7208. doc.body.spellcheck = false
  7209. me.document = doc
  7210. me.window = doc.defaultView || doc.parentWindow
  7211. me.iframe = me.window.frameElement
  7212. me.body = doc.body
  7213. me.selection = new dom.Selection(doc)
  7214. //gecko初始化就能得到range,无法判断isFocus了
  7215. var geckoSel
  7216. if (browser.gecko && (geckoSel = this.selection.getNative())) {
  7217. geckoSel.removeAllRanges()
  7218. }
  7219. this._initEvents()
  7220. //为form提交提供一个隐藏的textarea
  7221. for (var form = this.iframe.parentNode; !domUtils.isBody(form); form = form.parentNode) {
  7222. if (form.tagName == 'FORM') {
  7223. me.form = form
  7224. if (me.options.autoSyncData) {
  7225. domUtils.on(me.window, 'blur', function () {
  7226. setValue(form, me)
  7227. })
  7228. } else {
  7229. domUtils.on(form, 'submit', function () {
  7230. setValue(this, me)
  7231. })
  7232. }
  7233. break
  7234. }
  7235. }
  7236. if (options.initialContent) {
  7237. if (options.autoClearinitialContent) {
  7238. var oldExecCommand = me.execCommand
  7239. me.execCommand = function () {
  7240. me.fireEvent('firstBeforeExecCommand')
  7241. return oldExecCommand.apply(me, arguments)
  7242. }
  7243. this._setDefaultContent(options.initialContent)
  7244. } else this.setContent(options.initialContent, false, true)
  7245. }
  7246. //编辑器不能为空内容
  7247. if (domUtils.isEmptyNode(me.body)) {
  7248. me.body.innerHTML = '<p>' + (browser.ie ? '' : '<br/>') + '</p>'
  7249. }
  7250. //如果要求focus, 就把光标定位到内容开始
  7251. if (options.focus) {
  7252. setTimeout(function () {
  7253. me.focus(me.options.focusInEnd)
  7254. //如果自动清除开着,就不需要做selectionchange;
  7255. !me.options.autoClearinitialContent && me._selectionChange()
  7256. }, 0)
  7257. }
  7258. if (!me.container) {
  7259. me.container = this.iframe.parentNode
  7260. }
  7261. if (options.fullscreen && me.ui) {
  7262. me.ui.setFullScreen(true)
  7263. }
  7264. try {
  7265. me.document.execCommand('2D-position', false, false)
  7266. } catch (e) {}
  7267. try {
  7268. me.document.execCommand('enableInlineTableEditing', false, false)
  7269. } catch (e) {}
  7270. try {
  7271. me.document.execCommand('enableObjectResizing', false, false)
  7272. } catch (e) {}
  7273. //挂接快捷键
  7274. me._bindshortcutKeys()
  7275. me.isReady = 1
  7276. me.fireEvent('ready')
  7277. options.onready && options.onready.call(me)
  7278. if (!browser.ie9below) {
  7279. domUtils.on(me.window, ['blur', 'focus'], function (e) {
  7280. //chrome下会出现alt+tab切换时,导致选区位置不对
  7281. if (e.type == 'blur') {
  7282. me._bakRange = me.selection.getRange()
  7283. try {
  7284. me._bakNativeRange = me.selection.getNative().getRangeAt(0)
  7285. me.selection.getNative().removeAllRanges()
  7286. } catch (e) {
  7287. me._bakNativeRange = null
  7288. }
  7289. } else {
  7290. try {
  7291. me._bakRange && me._bakRange.select()
  7292. } catch (e) {}
  7293. }
  7294. })
  7295. }
  7296. //trace:1518 ff3.6body不够寛,会导致点击空白处无法获得焦点
  7297. if (browser.gecko && browser.version <= 10902) {
  7298. //修复ff3.6初始化进来,不能点击获得焦点
  7299. me.body.contentEditable = false
  7300. setTimeout(function () {
  7301. me.body.contentEditable = true
  7302. }, 100)
  7303. setInterval(function () {
  7304. me.body.style.height = me.iframe.offsetHeight - 20 + 'px'
  7305. }, 100)
  7306. }
  7307. !options.isShow && me.setHide()
  7308. options.readonly && me.setDisabled()
  7309. },
  7310. /**
  7311. * 同步数据到编辑器所在的form
  7312. * 从编辑器的容器节点向上查找form元素,若找到,就同步编辑内容到找到的form里,为提交数据做准备,主要用于是手动提交的情况
  7313. * 后台取得数据的键值,使用你容器上的name属性,如果没有就使用参数里的textarea项
  7314. * @method sync
  7315. * @example
  7316. * ```javascript
  7317. * editor.sync();
  7318. * form.sumbit(); //form变量已经指向了form元素
  7319. * ```
  7320. */
  7321. /**
  7322. * 根据传入的formId,在页面上查找要同步数据的表单,若找到,就同步编辑内容到找到的form里,为提交数据做准备
  7323. * 后台取得数据的键值,该键值默认使用给定的编辑器容器的name属性,如果没有name属性则使用参数项里给定的“textarea”项
  7324. * @method sync
  7325. * @param { String } formID 指定一个要同步数据的form的id,编辑器的数据会同步到你指定form下
  7326. */
  7327. sync: function (formId) {
  7328. var me = this,
  7329. form = formId
  7330. ? document.getElementById(formId)
  7331. : domUtils.findParent(
  7332. me.iframe.parentNode,
  7333. function (node) {
  7334. return node.tagName == 'FORM'
  7335. },
  7336. true
  7337. )
  7338. form && setValue(form, me)
  7339. },
  7340. /**
  7341. * 设置编辑器高度
  7342. * @method setHeight
  7343. * @remind 当配置项autoHeightEnabled为真时,该方法无效
  7344. * @param { Number } number 设置的高度值,纯数值,不带单位
  7345. * @example
  7346. * ```javascript
  7347. * editor.setHeight(number);
  7348. * ```
  7349. */
  7350. setHeight: function (height, notSetHeight) {
  7351. if (height !== parseInt(this.iframe.parentNode.style.height)) {
  7352. this.iframe.parentNode.style.height = height + 'px'
  7353. }
  7354. !notSetHeight && (this.options.minFrameHeight = this.options.initialFrameHeight = height)
  7355. this.body.style.height = height + 'px'
  7356. !notSetHeight && this.trigger('setHeight')
  7357. },
  7358. /**
  7359. * 为编辑器的编辑命令提供快捷键
  7360. * 这个接口是为插件扩展提供的接口,主要是为新添加的插件,如果需要添加快捷键,所提供的接口
  7361. * @method addshortcutkey
  7362. * @param { Object } keyset 命令名和快捷键键值对对象,多个按钮的快捷键用“+”分隔
  7363. * @example
  7364. * ```javascript
  7365. * editor.addshortcutkey({
  7366. * "Bold" : "ctrl+66",//^B
  7367. * "Italic" : "ctrl+73", //^I
  7368. * });
  7369. * ```
  7370. */
  7371. /**
  7372. * 这个接口是为插件扩展提供的接口,主要是为新添加的插件,如果需要添加快捷键,所提供的接口
  7373. * @method addshortcutkey
  7374. * @param { String } cmd 触发快捷键时,响应的命令
  7375. * @param { String } keys 快捷键的字符串,多个按钮用“+”分隔
  7376. * @example
  7377. * ```javascript
  7378. * editor.addshortcutkey("Underline", "ctrl+85"); //^U
  7379. * ```
  7380. */
  7381. addshortcutkey: function (cmd, keys) {
  7382. var obj = {}
  7383. if (keys) {
  7384. obj[cmd] = keys
  7385. } else {
  7386. obj = cmd
  7387. }
  7388. utils.extend(this.shortcutkeys, obj)
  7389. },
  7390. /**
  7391. * 对编辑器设置keydown事件监听,绑定快捷键和命令,当快捷键组合触发成功,会响应对应的命令
  7392. * @method _bindshortcutKeys
  7393. * @private
  7394. */
  7395. _bindshortcutKeys: function () {
  7396. var me = this,
  7397. shortcutkeys = this.shortcutkeys
  7398. me.addListener('keydown', function (type, e) {
  7399. var keyCode = e.keyCode || e.which
  7400. for (var i in shortcutkeys) {
  7401. var tmp = shortcutkeys[i].split(',')
  7402. for (var t = 0, ti; (ti = tmp[t++]); ) {
  7403. ti = ti.split(':')
  7404. var key = ti[0],
  7405. param = ti[1]
  7406. if (/^(ctrl)(\+shift)?\+(\d+)$/.test(key.toLowerCase()) || /^(\d+)$/.test(key)) {
  7407. if (
  7408. ((RegExp.$1 == 'ctrl' ? e.ctrlKey || e.metaKey : 0) &&
  7409. (RegExp.$2 != '' ? e[RegExp.$2.slice(1) + 'Key'] : 1) &&
  7410. keyCode == RegExp.$3) ||
  7411. keyCode == RegExp.$1
  7412. ) {
  7413. if (me.queryCommandState(i, param) != -1) me.execCommand(i, param)
  7414. domUtils.preventDefault(e)
  7415. }
  7416. }
  7417. }
  7418. }
  7419. })
  7420. },
  7421. /**
  7422. * 获取编辑器的内容
  7423. * @method getContent
  7424. * @warning 该方法获取到的是经过编辑器内置的过滤规则进行过滤后得到的内容
  7425. * @return { String } 编辑器的内容字符串, 如果编辑器的内容为空,或者是空的标签内容(如:”&lt;p&gt;&lt;br/&gt;&lt;/p&gt;“), 则返回空字符串
  7426. * @example
  7427. * ```javascript
  7428. * //编辑器html内容:<p>1<strong>2<em>34</em>5</strong>6</p>
  7429. * var content = editor.getContent(); //返回值:<p>1<strong>2<em>34</em>5</strong>6</p>
  7430. * ```
  7431. */
  7432. /**
  7433. * 获取编辑器的内容。 可以通过参数定义编辑器内置的判空规则
  7434. * @method getContent
  7435. * @param { Function } fn 自定的判空规则, 要求该方法返回一个boolean类型的值,
  7436. * 代表当前编辑器的内容是否空,
  7437. * 如果返回true, 则该方法将直接返回空字符串;如果返回false,则编辑器将返回
  7438. * 经过内置过滤规则处理后的内容。
  7439. * @remind 该方法在处理包含有初始化内容的时候能起到很好的作用。
  7440. * @warning 该方法获取到的是经过编辑器内置的过滤规则进行过滤后得到的内容
  7441. * @return { String } 编辑器的内容字符串
  7442. * @example
  7443. * ```javascript
  7444. * // editor 是一个编辑器的实例
  7445. * var content = editor.getContent( function ( editor ) {
  7446. * return editor.body.innerHTML === '欢迎使用UEditor'; //返回空字符串
  7447. * } );
  7448. * ```
  7449. */
  7450. getContent: function (cmd, fn, notSetCursor, ignoreBlank, formatter) {
  7451. var me = this
  7452. if (cmd && utils.isFunction(cmd)) {
  7453. fn = cmd
  7454. cmd = ''
  7455. }
  7456. if (fn ? !fn() : !this.hasContents()) {
  7457. return ''
  7458. }
  7459. me.fireEvent('beforegetcontent')
  7460. var root = UE.htmlparser(me.body.innerHTML, ignoreBlank)
  7461. me.filterOutputRule(root)
  7462. me.fireEvent('aftergetcontent', cmd, root)
  7463. return root.toHtml(formatter)
  7464. },
  7465. /**
  7466. * 取得完整的html代码,可以直接显示成完整的html文档
  7467. * @method getAllHtml
  7468. * @return { String } 编辑器的内容html文档字符串
  7469. * @eaxmple
  7470. * ```javascript
  7471. * editor.getAllHtml(); //返回格式大致是: <html><head>...</head><body>...</body></html>
  7472. * ```
  7473. */
  7474. getAllHtml: function () {
  7475. var me = this,
  7476. headHtml = [],
  7477. html = ''
  7478. me.fireEvent('getAllHtml', headHtml)
  7479. if (browser.ie && browser.version > 8) {
  7480. var headHtmlForIE9 = ''
  7481. utils.each(me.document.styleSheets, function (si) {
  7482. headHtmlForIE9 += si.href
  7483. ? '<link rel="stylesheet" type="text/css" href="' + si.href + '" />'
  7484. : '<style>' + si.cssText + '</style>'
  7485. })
  7486. utils.each(me.document.getElementsByTagName('script'), function (si) {
  7487. headHtmlForIE9 += si.outerHTML
  7488. })
  7489. }
  7490. return (
  7491. '<html><head>' +
  7492. (me.options.charset
  7493. ? '<meta http-equiv="Content-Type" content="text/html; charset=' +
  7494. me.options.charset +
  7495. '"/>'
  7496. : '') +
  7497. (headHtmlForIE9 || me.document.getElementsByTagName('head')[0].innerHTML) +
  7498. headHtml.join('\n') +
  7499. '</head>' +
  7500. '<body ' +
  7501. (ie && browser.version < 9 ? 'class="view"' : '') +
  7502. '>' +
  7503. me.getContent(null, null, true) +
  7504. '</body></html>'
  7505. )
  7506. },
  7507. /**
  7508. * 得到编辑器的纯文本内容,但会保留段落格式
  7509. * @method getPlainTxt
  7510. * @return { String } 编辑器带段落格式的纯文本内容字符串
  7511. * @example
  7512. * ```javascript
  7513. * //编辑器html内容:<p><strong>1</strong></p><p><strong>2</strong></p>
  7514. * console.log(editor.getPlainTxt()); //输出:"1\n2\n
  7515. * ```
  7516. */
  7517. getPlainTxt: function () {
  7518. var reg = new RegExp(domUtils.fillChar, 'g'),
  7519. html = this.body.innerHTML.replace(/[\n\r]/g, '') //ie要先去了\n在处理
  7520. html = html
  7521. .replace(/<(p|div)[^>]*>(<br\/?>|&nbsp;)<\/\1>/gi, '\n')
  7522. .replace(/<br\/?>/gi, '\n')
  7523. .replace(/<[^>/]+>/g, '')
  7524. .replace(/(\n)?<\/([^>]+)>/g, function (a, b, c) {
  7525. return dtd.$block[c] ? '\n' : b ? b : ''
  7526. })
  7527. //取出来的空格会有c2a0会变成乱码,处理这种情况\u00a0
  7528. return html
  7529. .replace(reg, '')
  7530. .replace(/\u00a0/g, ' ')
  7531. .replace(/&nbsp;/g, ' ')
  7532. },
  7533. /**
  7534. * 获取编辑器中的纯文本内容,没有段落格式
  7535. * @method getContentTxt
  7536. * @return { String } 编辑器不带段落格式的纯文本内容字符串
  7537. * @example
  7538. * ```javascript
  7539. * //编辑器html内容:<p><strong>1</strong></p><p><strong>2</strong></p>
  7540. * console.log(editor.getPlainTxt()); //输出:"12
  7541. * ```
  7542. */
  7543. getContentTxt: function () {
  7544. var reg = new RegExp(domUtils.fillChar, 'g')
  7545. //取出来的空格会有c2a0会变成乱码,处理这种情况\u00a0
  7546. return this.body[browser.ie ? 'innerText' : 'textContent']
  7547. .replace(reg, '')
  7548. .replace(/\u00a0/g, ' ')
  7549. },
  7550. /**
  7551. * 设置编辑器的内容,可修改编辑器当前的html内容
  7552. * @method setContent
  7553. * @warning 通过该方法插入的内容,是经过编辑器内置的过滤规则进行过滤后得到的内容
  7554. * @warning 该方法会触发selectionchange事件
  7555. * @param { String } html 要插入的html内容
  7556. * @example
  7557. * ```javascript
  7558. * editor.getContent('<p>test</p>');
  7559. * ```
  7560. */
  7561. /**
  7562. * 设置编辑器的内容,可修改编辑器当前的html内容
  7563. * @method setContent
  7564. * @warning 通过该方法插入的内容,是经过编辑器内置的过滤规则进行过滤后得到的内容
  7565. * @warning 该方法会触发selectionchange事件
  7566. * @param { String } html 要插入的html内容
  7567. * @param { Boolean } isAppendTo 若传入true,不清空原来的内容,在最后插入内容,否则,清空内容再插入
  7568. * @example
  7569. * ```javascript
  7570. * //假设设置前的编辑器内容是 <p>old text</p>
  7571. * editor.setContent('<p>new text</p>', true); //插入的结果是<p>old text</p><p>new text</p>
  7572. * ```
  7573. */
  7574. setContent: function (html, isAppendTo, notFireSelectionchange) {
  7575. var me = this
  7576. me.fireEvent('beforesetcontent', html)
  7577. var root = UE.htmlparser(html)
  7578. me.filterInputRule(root)
  7579. html = root.toHtml()
  7580. me.body.innerHTML = (isAppendTo ? me.body.innerHTML : '') + html
  7581. function isCdataDiv(node) {
  7582. return node.tagName == 'DIV' && node.getAttribute('cdata_tag')
  7583. }
  7584. //给文本或者inline节点套p标签
  7585. if (me.options.enterTag == 'p') {
  7586. var child = this.body.firstChild,
  7587. tmpNode
  7588. if (
  7589. !child ||
  7590. (child.nodeType == 1 &&
  7591. (dtd.$cdata[child.tagName] || isCdataDiv(child) || domUtils.isCustomeNode(child)) &&
  7592. child === this.body.lastChild)
  7593. ) {
  7594. this.body.innerHTML =
  7595. '<p>' + (browser.ie ? '&nbsp;' : '<br/>') + '</p>' + this.body.innerHTML
  7596. } else {
  7597. var p = me.document.createElement('p')
  7598. while (child) {
  7599. while (
  7600. child &&
  7601. (child.nodeType == 3 ||
  7602. (child.nodeType == 1 && dtd.p[child.tagName] && !dtd.$cdata[child.tagName]))
  7603. ) {
  7604. tmpNode = child.nextSibling
  7605. p.appendChild(child)
  7606. child = tmpNode
  7607. }
  7608. if (p.firstChild) {
  7609. if (!child) {
  7610. me.body.appendChild(p)
  7611. break
  7612. } else {
  7613. child.parentNode.insertBefore(p, child)
  7614. p = me.document.createElement('p')
  7615. }
  7616. }
  7617. child = child.nextSibling
  7618. }
  7619. }
  7620. }
  7621. me.fireEvent('aftersetcontent')
  7622. me.fireEvent('contentchange')
  7623. !notFireSelectionchange && me._selectionChange()
  7624. //清除保存的选区
  7625. me._bakRange = me._bakIERange = me._bakNativeRange = null
  7626. //trace:1742 setContent后gecko能得到焦点问题
  7627. var geckoSel
  7628. if (browser.gecko && (geckoSel = this.selection.getNative())) {
  7629. geckoSel.removeAllRanges()
  7630. }
  7631. if (me.options.autoSyncData) {
  7632. me.form && setValue(me.form, me)
  7633. }
  7634. },
  7635. /**
  7636. * 让编辑器获得焦点,默认focus到编辑器头部
  7637. * @method focus
  7638. * @example
  7639. * ```javascript
  7640. * editor.focus()
  7641. * ```
  7642. */
  7643. /**
  7644. * 让编辑器获得焦点,toEnd确定focus位置
  7645. * @method focus
  7646. * @param { Boolean } toEnd 默认focus到编辑器头部,toEnd为true时focus到内容尾部
  7647. * @example
  7648. * ```javascript
  7649. * editor.focus(true)
  7650. * ```
  7651. */
  7652. focus: function (toEnd) {
  7653. try {
  7654. var me = this,
  7655. rng = me.selection.getRange()
  7656. if (toEnd) {
  7657. var node = me.body.lastChild
  7658. if (node && node.nodeType == 1 && !dtd.$empty[node.tagName]) {
  7659. if (domUtils.isEmptyBlock(node)) {
  7660. rng.setStartAtFirst(node)
  7661. } else {
  7662. rng.setStartAtLast(node)
  7663. }
  7664. rng.collapse(true)
  7665. }
  7666. rng.setCursor(true)
  7667. } else {
  7668. if (!rng.collapsed && domUtils.isBody(rng.startContainer) && rng.startOffset == 0) {
  7669. var node = me.body.firstChild
  7670. if (node && node.nodeType == 1 && !dtd.$empty[node.tagName]) {
  7671. rng.setStartAtFirst(node).collapse(true)
  7672. }
  7673. }
  7674. rng.select(true)
  7675. }
  7676. this.fireEvent('focus selectionchange')
  7677. } catch (e) {}
  7678. },
  7679. isFocus: function () {
  7680. return this.selection.isFocus()
  7681. },
  7682. blur: function () {
  7683. var sel = this.selection.getNative()
  7684. if (sel.empty && browser.ie) {
  7685. var nativeRng = document.body.createTextRange()
  7686. nativeRng.moveToElementText(document.body)
  7687. nativeRng.collapse(true)
  7688. nativeRng.select()
  7689. sel.empty()
  7690. } else {
  7691. sel.removeAllRanges()
  7692. }
  7693. //this.fireEvent('blur selectionchange');
  7694. },
  7695. /**
  7696. * 初始化UE事件及部分事件代理
  7697. * @method _initEvents
  7698. * @private
  7699. */
  7700. _initEvents: function () {
  7701. var me = this,
  7702. doc = me.document,
  7703. win = me.window
  7704. me._proxyDomEvent = utils.bind(me._proxyDomEvent, me)
  7705. domUtils.on(
  7706. doc,
  7707. [
  7708. 'click',
  7709. 'contextmenu',
  7710. 'mousedown',
  7711. 'keydown',
  7712. 'keyup',
  7713. 'keypress',
  7714. 'mouseup',
  7715. 'mouseover',
  7716. 'mouseout',
  7717. 'selectstart'
  7718. ],
  7719. me._proxyDomEvent
  7720. )
  7721. domUtils.on(win, ['focus', 'blur'], me._proxyDomEvent)
  7722. domUtils.on(me.body, 'drop', function (e) {
  7723. //阻止ff下默认的弹出新页面打开图片
  7724. if (browser.gecko && e.stopPropagation) {
  7725. e.stopPropagation()
  7726. }
  7727. me.fireEvent('contentchange')
  7728. })
  7729. domUtils.on(doc, ['mouseup', 'keydown'], function (evt) {
  7730. //特殊键不触发selectionchange
  7731. if (evt.type == 'keydown' && (evt.ctrlKey || evt.metaKey || evt.shiftKey || evt.altKey)) {
  7732. return
  7733. }
  7734. if (evt.button == 2) return
  7735. me._selectionChange(250, evt)
  7736. })
  7737. },
  7738. /**
  7739. * 触发事件代理
  7740. * @method _proxyDomEvent
  7741. * @private
  7742. * @return { * } fireEvent的返回值
  7743. * @see UE.EventBase:fireEvent(String)
  7744. */
  7745. _proxyDomEvent: function (evt) {
  7746. if (this.fireEvent('before' + evt.type.replace(/^on/, '').toLowerCase()) === false) {
  7747. return false
  7748. }
  7749. if (this.fireEvent(evt.type.replace(/^on/, ''), evt) === false) {
  7750. return false
  7751. }
  7752. return this.fireEvent('after' + evt.type.replace(/^on/, '').toLowerCase())
  7753. },
  7754. /**
  7755. * 变化选区
  7756. * @method _selectionChange
  7757. * @private
  7758. */
  7759. _selectionChange: function (delay, evt) {
  7760. var me = this
  7761. //有光标才做selectionchange 为了解决未focus时点击source不能触发更改工具栏状态的问题(source命令notNeedUndo=1)
  7762. // if ( !me.selection.isFocus() ){
  7763. // return;
  7764. // }
  7765. var hackForMouseUp = false
  7766. var mouseX, mouseY
  7767. if (browser.ie && browser.version < 9 && evt && evt.type == 'mouseup') {
  7768. var range = this.selection.getRange()
  7769. if (!range.collapsed) {
  7770. hackForMouseUp = true
  7771. mouseX = evt.clientX
  7772. mouseY = evt.clientY
  7773. }
  7774. }
  7775. clearTimeout(_selectionChangeTimer)
  7776. _selectionChangeTimer = setTimeout(function () {
  7777. if (!me.selection || !me.selection.getNative()) {
  7778. return
  7779. }
  7780. //修复一个IE下的bug: 鼠标点击一段已选择的文本中间时,可能在mouseup后的一段时间内取到的range是在selection的type为None下的错误值.
  7781. //IE下如果用户是拖拽一段已选择文本,则不会触发mouseup事件,所以这里的特殊处理不会对其有影响
  7782. var ieRange
  7783. if (hackForMouseUp && me.selection.getNative().type == 'None') {
  7784. ieRange = me.document.body.createTextRange()
  7785. try {
  7786. ieRange.moveToPoint(mouseX, mouseY)
  7787. } catch (ex) {
  7788. ieRange = null
  7789. }
  7790. }
  7791. var bakGetIERange
  7792. if (ieRange) {
  7793. bakGetIERange = me.selection.getIERange
  7794. me.selection.getIERange = function () {
  7795. return ieRange
  7796. }
  7797. }
  7798. me.selection.cache()
  7799. if (bakGetIERange) {
  7800. me.selection.getIERange = bakGetIERange
  7801. }
  7802. if (me.selection._cachedRange && me.selection._cachedStartElement) {
  7803. me.fireEvent('beforeselectionchange')
  7804. // 第二个参数causeByUi为true代表由用户交互造成的selectionchange.
  7805. me.fireEvent('selectionchange', !!evt)
  7806. me.fireEvent('afterselectionchange')
  7807. me.selection.clear()
  7808. }
  7809. }, delay || 50)
  7810. },
  7811. /**
  7812. * 执行编辑命令
  7813. * @method _callCmdFn
  7814. * @private
  7815. * @param { String } fnName 函数名称
  7816. * @param { * } args 传给命令函数的参数
  7817. * @return { * } 返回命令函数运行的返回值
  7818. */
  7819. _callCmdFn: function (fnName, args) {
  7820. var cmdName = args[0].toLowerCase(),
  7821. cmd,
  7822. cmdFn
  7823. cmd = this.commands[cmdName] || UE.commands[cmdName]
  7824. cmdFn = cmd && cmd[fnName]
  7825. //没有querycommandstate或者没有command的都默认返回0
  7826. if ((!cmd || !cmdFn) && fnName == 'queryCommandState') {
  7827. return 0
  7828. } else if (cmdFn) {
  7829. return cmdFn.apply(this, args)
  7830. }
  7831. },
  7832. /**
  7833. * 执行编辑命令cmdName,完成富文本编辑效果
  7834. * @method execCommand
  7835. * @param { String } cmdName 需要执行的命令
  7836. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  7837. * @return { * } 返回命令函数运行的返回值
  7838. * @example
  7839. * ```javascript
  7840. * editor.execCommand(cmdName);
  7841. * ```
  7842. */
  7843. execCommand: function (cmdName) {
  7844. cmdName = cmdName.toLowerCase()
  7845. var me = this,
  7846. result,
  7847. cmd = me.commands[cmdName] || UE.commands[cmdName]
  7848. if (!cmd || !cmd.execCommand) {
  7849. return null
  7850. }
  7851. if (!cmd.notNeedUndo && !me.__hasEnterExecCommand) {
  7852. me.__hasEnterExecCommand = true
  7853. if (me.queryCommandState.apply(me, arguments) != -1) {
  7854. me.fireEvent('saveScene')
  7855. me.fireEvent.apply(me, ['beforeexeccommand', cmdName].concat(arguments))
  7856. result = this._callCmdFn('execCommand', arguments)
  7857. //保存场景时,做了内容对比,再看是否进行contentchange触发,这里多触发了一次,去掉
  7858. // (!cmd.ignoreContentChange && !me._ignoreContentChange) && me.fireEvent('contentchange');
  7859. me.fireEvent.apply(me, ['afterexeccommand', cmdName].concat(arguments))
  7860. me.fireEvent('saveScene')
  7861. }
  7862. me.__hasEnterExecCommand = false
  7863. } else {
  7864. result = this._callCmdFn('execCommand', arguments)
  7865. !me.__hasEnterExecCommand &&
  7866. !cmd.ignoreContentChange &&
  7867. !me._ignoreContentChange &&
  7868. me.fireEvent('contentchange')
  7869. }
  7870. !me.__hasEnterExecCommand &&
  7871. !cmd.ignoreContentChange &&
  7872. !me._ignoreContentChange &&
  7873. me._selectionChange()
  7874. return result
  7875. },
  7876. /**
  7877. * 根据传入的command命令,查选编辑器当前的选区,返回命令的状态
  7878. * @method queryCommandState
  7879. * @param { String } cmdName 需要查询的命令名称
  7880. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  7881. * @return { Number } number 返回放前命令的状态,返回值三种情况:(-1|0|1)
  7882. * @example
  7883. * ```javascript
  7884. * editor.queryCommandState(cmdName) => (-1|0|1)
  7885. * ```
  7886. * @see COMMAND.LIST
  7887. */
  7888. queryCommandState: function (cmdName) {
  7889. return this._callCmdFn('queryCommandState', arguments)
  7890. },
  7891. /**
  7892. * 根据传入的command命令,查选编辑器当前的选区,根据命令返回相关的值
  7893. * @method queryCommandValue
  7894. * @param { String } cmdName 需要查询的命令名称
  7895. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  7896. * @remind 只有部分插件有此方法
  7897. * @return { * } 返回每个命令特定的当前状态值
  7898. * @grammar editor.queryCommandValue(cmdName) => {*}
  7899. * @see COMMAND.LIST
  7900. */
  7901. queryCommandValue: function (cmdName) {
  7902. return this._callCmdFn('queryCommandValue', arguments)
  7903. },
  7904. /**
  7905. * 检查编辑区域中是否有内容
  7906. * @method hasContents
  7907. * @remind 默认有文本内容,或者有以下节点都不认为是空
  7908. * table,ul,ol,dl,iframe,area,base,col,hr,img,embed,input,link,meta,param
  7909. * @return { Boolean } 检查有内容返回true,否则返回false
  7910. * @example
  7911. * ```javascript
  7912. * editor.hasContents()
  7913. * ```
  7914. */
  7915. /**
  7916. * 检查编辑区域中是否有内容,若包含参数tags中的节点类型,直接返回true
  7917. * @method hasContents
  7918. * @param { Array } tags 传入数组判断时用到的节点类型
  7919. * @return { Boolean } 若文档中包含tags数组里对应的tag,返回true,否则返回false
  7920. * @example
  7921. * ```javascript
  7922. * editor.hasContents(['span']);
  7923. * ```
  7924. */
  7925. hasContents: function (tags) {
  7926. if (tags) {
  7927. for (var i = 0, ci; (ci = tags[i++]); ) {
  7928. if (this.document.getElementsByTagName(ci).length > 0) {
  7929. return true
  7930. }
  7931. }
  7932. }
  7933. if (!domUtils.isEmptyBlock(this.body)) {
  7934. return true
  7935. }
  7936. //随时添加,定义的特殊标签如果存在,不能认为是空
  7937. tags = ['div']
  7938. for (i = 0; (ci = tags[i++]); ) {
  7939. var nodes = domUtils.getElementsByTagName(this.document, ci)
  7940. for (var n = 0, cn; (cn = nodes[n++]); ) {
  7941. if (domUtils.isCustomeNode(cn)) {
  7942. return true
  7943. }
  7944. }
  7945. }
  7946. return false
  7947. },
  7948. /**
  7949. * 重置编辑器,可用来做多个tab使用同一个编辑器实例
  7950. * @method reset
  7951. * @remind 此方法会清空编辑器内容,清空回退列表,会触发reset事件
  7952. * @example
  7953. * ```javascript
  7954. * editor.reset()
  7955. * ```
  7956. */
  7957. reset: function () {
  7958. this.fireEvent('reset')
  7959. },
  7960. /**
  7961. * 设置当前编辑区域可以编辑
  7962. * @method setEnabled
  7963. * @example
  7964. * ```javascript
  7965. * editor.setEnabled()
  7966. * ```
  7967. */
  7968. setEnabled: function () {
  7969. var me = this,
  7970. range
  7971. if (me.body.contentEditable == 'false') {
  7972. me.body.contentEditable = true
  7973. range = me.selection.getRange()
  7974. //有可能内容丢失了
  7975. try {
  7976. range.moveToBookmark(me.lastBk)
  7977. delete me.lastBk
  7978. } catch (e) {
  7979. range.setStartAtFirst(me.body).collapse(true)
  7980. }
  7981. range.select(true)
  7982. if (me.bkqueryCommandState) {
  7983. me.queryCommandState = me.bkqueryCommandState
  7984. delete me.bkqueryCommandState
  7985. }
  7986. if (me.bkqueryCommandValue) {
  7987. me.queryCommandValue = me.bkqueryCommandValue
  7988. delete me.bkqueryCommandValue
  7989. }
  7990. me.fireEvent('selectionchange')
  7991. }
  7992. },
  7993. enable: function () {
  7994. return this.setEnabled()
  7995. },
  7996. /** 设置当前编辑区域不可编辑
  7997. * @method setDisabled
  7998. */
  7999. /** 设置当前编辑区域不可编辑,except中的命令除外
  8000. * @method setDisabled
  8001. * @param { String } except 例外命令的字符串
  8002. * @remind 即使设置了disable,此处配置的例外命令仍然可以执行
  8003. * @example
  8004. * ```javascript
  8005. * editor.setDisabled('bold'); //禁用工具栏中除加粗之外的所有功能
  8006. * ```
  8007. */
  8008. /** 设置当前编辑区域不可编辑,except中的命令除外
  8009. * @method setDisabled
  8010. * @param { Array } except 例外命令的字符串数组,数组中的命令仍然可以执行
  8011. * @remind 即使设置了disable,此处配置的例外命令仍然可以执行
  8012. * @example
  8013. * ```javascript
  8014. * editor.setDisabled(['bold','insertimage']); //禁用工具栏中除加粗和插入图片之外的所有功能
  8015. * ```
  8016. */
  8017. setDisabled: function (except) {
  8018. var me = this
  8019. except = except ? (utils.isArray(except) ? except : [except]) : []
  8020. if (me.body.contentEditable == 'true') {
  8021. if (!me.lastBk) {
  8022. me.lastBk = me.selection.getRange().createBookmark(true)
  8023. }
  8024. me.body.contentEditable = false
  8025. me.bkqueryCommandState = me.queryCommandState
  8026. me.bkqueryCommandValue = me.queryCommandValue
  8027. me.queryCommandState = function (type) {
  8028. if (utils.indexOf(except, type) != -1) {
  8029. return me.bkqueryCommandState.apply(me, arguments)
  8030. }
  8031. return -1
  8032. }
  8033. me.queryCommandValue = function (type) {
  8034. if (utils.indexOf(except, type) != -1) {
  8035. return me.bkqueryCommandValue.apply(me, arguments)
  8036. }
  8037. return null
  8038. }
  8039. me.fireEvent('selectionchange')
  8040. }
  8041. },
  8042. disable: function (except) {
  8043. return this.setDisabled(except)
  8044. },
  8045. /**
  8046. * 设置默认内容
  8047. * @method _setDefaultContent
  8048. * @private
  8049. * @param { String } cont 要存入的内容
  8050. */
  8051. _setDefaultContent: (function () {
  8052. function clear() {
  8053. var me = this
  8054. if (me.document.getElementById('initContent')) {
  8055. me.body.innerHTML = '<p>' + (ie ? '' : '<br/>') + '</p>'
  8056. me.removeListener('firstBeforeExecCommand focus', clear)
  8057. setTimeout(function () {
  8058. me.focus()
  8059. me._selectionChange()
  8060. }, 0)
  8061. }
  8062. }
  8063. return function (cont) {
  8064. var me = this
  8065. me.body.innerHTML = '<p id="initContent">' + cont + '</p>'
  8066. me.addListener('firstBeforeExecCommand focus', clear)
  8067. }
  8068. })(),
  8069. /**
  8070. * 显示编辑器
  8071. * @method setShow
  8072. * @example
  8073. * ```javascript
  8074. * editor.setShow()
  8075. * ```
  8076. */
  8077. setShow: function () {
  8078. var me = this,
  8079. range = me.selection.getRange()
  8080. if (me.container.style.display == 'none') {
  8081. //有可能内容丢失了
  8082. try {
  8083. range.moveToBookmark(me.lastBk)
  8084. delete me.lastBk
  8085. } catch (e) {
  8086. range.setStartAtFirst(me.body).collapse(true)
  8087. }
  8088. //ie下focus实效,所以做了个延迟
  8089. setTimeout(function () {
  8090. range.select(true)
  8091. }, 100)
  8092. me.container.style.display = ''
  8093. }
  8094. },
  8095. show: function () {
  8096. return this.setShow()
  8097. },
  8098. /**
  8099. * 隐藏编辑器
  8100. * @method setHide
  8101. * @example
  8102. * ```javascript
  8103. * editor.setHide()
  8104. * ```
  8105. */
  8106. setHide: function () {
  8107. var me = this
  8108. if (!me.lastBk) {
  8109. me.lastBk = me.selection.getRange().createBookmark(true)
  8110. }
  8111. me.container.style.display = 'none'
  8112. },
  8113. hide: function () {
  8114. return this.setHide()
  8115. },
  8116. /**
  8117. * 根据指定的路径,获取对应的语言资源
  8118. * @method getLang
  8119. * @param { String } path 路径根据的是lang目录下的语言文件的路径结构
  8120. * @return { Object | String } 根据路径返回语言资源的Json格式对象或者语言字符串
  8121. * @example
  8122. * ```javascript
  8123. * editor.getLang('contextMenu.delete'); //如果当前是中文,那返回是的是'删除'
  8124. * ```
  8125. */
  8126. getLang: function (path) {
  8127. // HaoChuan9421
  8128. if (!this.options) {
  8129. return ''
  8130. }
  8131. var lang = UE.I18N[this.options.lang]
  8132. if (!lang) {
  8133. throw Error('not import language file')
  8134. }
  8135. path = (path || '').split('.')
  8136. for (var i = 0, ci; (ci = path[i++]); ) {
  8137. lang = lang[ci]
  8138. if (!lang) break
  8139. }
  8140. return lang
  8141. },
  8142. /**
  8143. * 计算编辑器html内容字符串的长度
  8144. * @method getContentLength
  8145. * @return { Number } 返回计算的长度
  8146. * @example
  8147. * ```javascript
  8148. * //编辑器html内容<p><strong>132</strong></p>
  8149. * editor.getContentLength() //返回27
  8150. * ```
  8151. */
  8152. /**
  8153. * 计算编辑器当前纯文本内容的长度
  8154. * @method getContentLength
  8155. * @param { Boolean } ingoneHtml 传入true时,只按照纯文本来计算
  8156. * @return { Number } 返回计算的长度,内容中有hr/img/iframe标签,长度加1
  8157. * @example
  8158. * ```javascript
  8159. * //编辑器html内容<p><strong>132</strong></p>
  8160. * editor.getContentLength() //返回3
  8161. * ```
  8162. */
  8163. getContentLength: function (ingoneHtml, tagNames) {
  8164. var count = this.getContent(false, false, true).length
  8165. if (ingoneHtml) {
  8166. tagNames = (tagNames || []).concat(['hr', 'img', 'iframe'])
  8167. count = this.getContentTxt().replace(/[\t\r\n]+/g, '').length
  8168. for (var i = 0, ci; (ci = tagNames[i++]); ) {
  8169. count += this.document.getElementsByTagName(ci).length
  8170. }
  8171. }
  8172. return count
  8173. },
  8174. /**
  8175. * 注册输入过滤规则
  8176. * @method addInputRule
  8177. * @param { Function } rule 要添加的过滤规则
  8178. * @example
  8179. * ```javascript
  8180. * editor.addInputRule(function(root){
  8181. * $.each(root.getNodesByTagName('div'),function(i,node){
  8182. * node.tagName="p";
  8183. * });
  8184. * });
  8185. * ```
  8186. */
  8187. addInputRule: function (rule) {
  8188. this.inputRules.push(rule)
  8189. },
  8190. /**
  8191. * 执行注册的过滤规则
  8192. * @method filterInputRule
  8193. * @param { UE.uNode } root 要过滤的uNode节点
  8194. * @remind 执行editor.setContent方法和执行'inserthtml'命令后,会运行该过滤函数
  8195. * @example
  8196. * ```javascript
  8197. * editor.filterInputRule(editor.body);
  8198. * ```
  8199. * @see UE.Editor:addInputRule
  8200. */
  8201. filterInputRule: function (root) {
  8202. for (var i = 0, ci; (ci = this.inputRules[i++]); ) {
  8203. ci.call(this, root)
  8204. }
  8205. },
  8206. /**
  8207. * 注册输出过滤规则
  8208. * @method addOutputRule
  8209. * @param { Function } rule 要添加的过滤规则
  8210. * @example
  8211. * ```javascript
  8212. * editor.addOutputRule(function(root){
  8213. * $.each(root.getNodesByTagName('p'),function(i,node){
  8214. * node.tagName="div";
  8215. * });
  8216. * });
  8217. * ```
  8218. */
  8219. addOutputRule: function (rule) {
  8220. this.outputRules.push(rule)
  8221. },
  8222. /**
  8223. * 根据输出过滤规则,过滤编辑器内容
  8224. * @method filterOutputRule
  8225. * @remind 执行editor.getContent方法的时候,会先运行该过滤函数
  8226. * @param { UE.uNode } root 要过滤的uNode节点
  8227. * @example
  8228. * ```javascript
  8229. * editor.filterOutputRule(editor.body);
  8230. * ```
  8231. * @see UE.Editor:addOutputRule
  8232. */
  8233. filterOutputRule: function (root) {
  8234. for (var i = 0, ci; (ci = this.outputRules[i++]); ) {
  8235. ci.call(this, root)
  8236. }
  8237. },
  8238. /**
  8239. * 根据action名称获取请求的路径
  8240. * @method getActionUrl
  8241. * @remind 假如没有设置serverUrl,会根据imageUrl设置默认的controller路径
  8242. * @param { String } action action名称
  8243. * @example
  8244. * ```javascript
  8245. * editor.getActionUrl('config'); //返回 "/ueditor/php/controller.php?action=config"
  8246. * editor.getActionUrl('image'); //返回 "/ueditor/php/controller.php?action=uplaodimage"
  8247. * editor.getActionUrl('scrawl'); //返回 "/ueditor/php/controller.php?action=uplaodscrawl"
  8248. * editor.getActionUrl('imageManager'); //返回 "/ueditor/php/controller.php?action=listimage"
  8249. * ```
  8250. */
  8251. getActionUrl: function (action) {
  8252. var actionName = this.getOpt(action) || action,
  8253. imageUrl = this.getOpt('imageUrl'),
  8254. serverUrl = this.getOpt('serverUrl')
  8255. if (!serverUrl && imageUrl) {
  8256. serverUrl = imageUrl.replace(/^(.*[\/]).+([\.].+)$/, '$1controller$2')
  8257. }
  8258. if (serverUrl) {
  8259. serverUrl =
  8260. serverUrl + (serverUrl.indexOf('?') == -1 ? '?' : '&') + 'action=' + (actionName || '')
  8261. return utils.formatUrl(serverUrl)
  8262. } else {
  8263. return ''
  8264. }
  8265. }
  8266. }
  8267. utils.inherits(Editor, EventBase)
  8268. })()
  8269. // core/Editor.defaultoptions.js
  8270. //维护编辑器一下默认的不在插件中的配置项
  8271. UE.Editor.defaultOptions = function (editor) {
  8272. var _url = editor.options.UEDITOR_HOME_URL
  8273. return {
  8274. isShow: true,
  8275. initialContent: '',
  8276. initialStyle: '',
  8277. autoClearinitialContent: false,
  8278. iframeCssUrl: _url + 'themes/iframe.css',
  8279. textarea: 'editorValue',
  8280. focus: false,
  8281. focusInEnd: true,
  8282. autoClearEmptyNode: true,
  8283. fullscreen: false,
  8284. readonly: false,
  8285. zIndex: 999,
  8286. imagePopup: true,
  8287. enterTag: 'p',
  8288. customDomain: false,
  8289. lang: 'zh-cn',
  8290. langPath: _url + 'lang/',
  8291. theme: 'default',
  8292. themePath: _url + 'themes/',
  8293. allHtmlEnabled: false,
  8294. scaleEnabled: false,
  8295. tableNativeEditInFF: false,
  8296. autoSyncData: true,
  8297. fileNameFormat: '{time}{rand:6}'
  8298. }
  8299. }
  8300. // core/loadconfig.js
  8301. ;(function () {
  8302. UE.Editor.prototype.loadServerConfig = function () {
  8303. var me = this
  8304. setTimeout(function () {
  8305. try {
  8306. me.options.imageUrl &&
  8307. me.setOpt(
  8308. 'serverUrl',
  8309. me.options.imageUrl.replace(/^(.*[\/]).+([\.].+)$/, '$1controller$2')
  8310. )
  8311. var configUrl = me.getActionUrl('config'),
  8312. isJsonp = utils.isCrossDomainUrl(configUrl)
  8313. /* 发出ajax请求 */
  8314. me._serverConfigLoaded = false
  8315. configUrl &&
  8316. UE.ajax.request(configUrl, {
  8317. method: 'GET',
  8318. dataType: isJsonp ? 'jsonp' : '',
  8319. onsuccess: function (r) {
  8320. try {
  8321. var config = isJsonp ? r : eval('(' + r.responseText + ')')
  8322. utils.extend(me.options, config)
  8323. me.fireEvent('serverConfigLoaded')
  8324. me._serverConfigLoaded = true
  8325. } catch (e) {
  8326. showErrorMsg(me.getLang('loadconfigFormatError'))
  8327. }
  8328. },
  8329. onerror: function () {
  8330. showErrorMsg(me.getLang('loadconfigHttpError'))
  8331. }
  8332. })
  8333. } catch (e) {
  8334. showErrorMsg(me.getLang('loadconfigError'))
  8335. }
  8336. })
  8337. function showErrorMsg(msg) {
  8338. console && console.error(msg)
  8339. //me.fireEvent('showMessage', {
  8340. // 'title': msg,
  8341. // 'type': 'error'
  8342. //});
  8343. }
  8344. }
  8345. UE.Editor.prototype.isServerConfigLoaded = function () {
  8346. var me = this
  8347. return me._serverConfigLoaded || false
  8348. }
  8349. UE.Editor.prototype.afterConfigReady = function (handler) {
  8350. if (!handler || !utils.isFunction(handler)) return
  8351. var me = this
  8352. var readyHandler = function () {
  8353. handler.apply(me, arguments)
  8354. me.removeListener('serverConfigLoaded', readyHandler)
  8355. }
  8356. if (me.isServerConfigLoaded()) {
  8357. handler.call(me, 'serverConfigLoaded')
  8358. } else {
  8359. me.addListener('serverConfigLoaded', readyHandler)
  8360. }
  8361. }
  8362. })()
  8363. // core/ajax.js
  8364. /**
  8365. * @file
  8366. * @module UE.ajax
  8367. * @since 1.2.6.1
  8368. */
  8369. /**
  8370. * 提供对ajax请求的支持
  8371. * @module UE.ajax
  8372. */
  8373. UE.ajax = (function () {
  8374. //创建一个ajaxRequest对象
  8375. var fnStr = 'XMLHttpRequest()'
  8376. try {
  8377. new ActiveXObject('Msxml2.XMLHTTP')
  8378. fnStr = "ActiveXObject('Msxml2.XMLHTTP')"
  8379. } catch (e) {
  8380. try {
  8381. new ActiveXObject('Microsoft.XMLHTTP')
  8382. fnStr = "ActiveXObject('Microsoft.XMLHTTP')"
  8383. } catch (e) {}
  8384. }
  8385. var creatAjaxRequest = new Function('return new ' + fnStr)
  8386. /**
  8387. * 将json参数转化成适合ajax提交的参数列表
  8388. * @param json
  8389. */
  8390. function json2str(json) {
  8391. var strArr = []
  8392. for (var i in json) {
  8393. //忽略默认的几个参数
  8394. if (i == 'method' || i == 'timeout' || i == 'async' || i == 'dataType' || i == 'callback')
  8395. continue
  8396. //忽略控制
  8397. if (json[i] == undefined || json[i] == null) continue
  8398. //传递过来的对象和函数不在提交之列
  8399. if (
  8400. !(
  8401. (typeof json[i]).toLowerCase() == 'function' ||
  8402. (typeof json[i]).toLowerCase() == 'object'
  8403. )
  8404. ) {
  8405. strArr.push(encodeURIComponent(i) + '=' + encodeURIComponent(json[i]))
  8406. } else if (utils.isArray(json[i])) {
  8407. //支持传数组内容
  8408. for (var j = 0; j < json[i].length; j++) {
  8409. strArr.push(encodeURIComponent(i) + '[]=' + encodeURIComponent(json[i][j]))
  8410. }
  8411. }
  8412. }
  8413. return strArr.join('&')
  8414. }
  8415. function doAjax(url, ajaxOptions) {
  8416. var xhr = creatAjaxRequest(),
  8417. //是否超时
  8418. timeIsOut = false,
  8419. //默认参数
  8420. defaultAjaxOptions = {
  8421. method: 'POST',
  8422. timeout: 5000,
  8423. async: true,
  8424. data: {}, //需要传递对象的话只能覆盖
  8425. onsuccess: function () {},
  8426. onerror: function () {}
  8427. }
  8428. if (typeof url === 'object') {
  8429. ajaxOptions = url
  8430. url = ajaxOptions.url
  8431. }
  8432. if (!xhr || !url) return
  8433. var ajaxOpts = ajaxOptions
  8434. ? utils.extend(defaultAjaxOptions, ajaxOptions)
  8435. : defaultAjaxOptions
  8436. var submitStr = json2str(ajaxOpts) // { name:"Jim",city:"Beijing" } --> "name=Jim&city=Beijing"
  8437. //如果用户直接通过data参数传递json对象过来,则也要将此json对象转化为字符串
  8438. if (!utils.isEmptyObject(ajaxOpts.data)) {
  8439. submitStr += (submitStr ? '&' : '') + json2str(ajaxOpts.data)
  8440. }
  8441. //超时检测
  8442. var timerID = setTimeout(function () {
  8443. if (xhr.readyState != 4) {
  8444. timeIsOut = true
  8445. xhr.abort()
  8446. clearTimeout(timerID)
  8447. }
  8448. }, ajaxOpts.timeout)
  8449. var method = ajaxOpts.method.toUpperCase()
  8450. var str =
  8451. url +
  8452. (url.indexOf('?') == -1 ? '?' : '&') +
  8453. (method == 'POST' ? '' : submitStr + '&noCache=' + +new Date())
  8454. xhr.open(method, str, ajaxOpts.async)
  8455. xhr.onreadystatechange = function () {
  8456. if (xhr.readyState == 4) {
  8457. if (!timeIsOut && xhr.status == 200) {
  8458. ajaxOpts.onsuccess(xhr)
  8459. } else {
  8460. ajaxOpts.onerror(xhr)
  8461. }
  8462. }
  8463. }
  8464. if (method == 'POST') {
  8465. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
  8466. xhr.send(submitStr)
  8467. } else {
  8468. xhr.send(null)
  8469. }
  8470. }
  8471. function doJsonp(url, opts) {
  8472. var successhandler = opts.onsuccess || function () {},
  8473. scr = document.createElement('SCRIPT'),
  8474. options = opts || {},
  8475. charset = options['charset'],
  8476. callbackField = options['jsonp'] || 'callback',
  8477. callbackFnName,
  8478. timeOut = options['timeOut'] || 0,
  8479. timer,
  8480. reg = new RegExp('(\\?|&)' + callbackField + '=([^&]*)'),
  8481. matches
  8482. if (utils.isFunction(successhandler)) {
  8483. callbackFnName = 'bd__editor__' + Math.floor(Math.random() * 2147483648).toString(36)
  8484. window[callbackFnName] = getCallBack(0)
  8485. } else if (utils.isString(successhandler)) {
  8486. callbackFnName = successhandler
  8487. } else {
  8488. if ((matches = reg.exec(url))) {
  8489. callbackFnName = matches[2]
  8490. }
  8491. }
  8492. url = url.replace(reg, '\x241' + callbackField + '=' + callbackFnName)
  8493. if (url.search(reg) < 0) {
  8494. url += (url.indexOf('?') < 0 ? '?' : '&') + callbackField + '=' + callbackFnName
  8495. }
  8496. var queryStr = json2str(opts) // { name:"Jim",city:"Beijing" } --> "name=Jim&city=Beijing"
  8497. //如果用户直接通过data参数传递json对象过来,则也要将此json对象转化为字符串
  8498. if (!utils.isEmptyObject(opts.data)) {
  8499. queryStr += (queryStr ? '&' : '') + json2str(opts.data)
  8500. }
  8501. if (queryStr) {
  8502. url = url.replace(/\?/, '?' + queryStr + '&')
  8503. }
  8504. scr.onerror = getCallBack(1)
  8505. if (timeOut) {
  8506. timer = setTimeout(getCallBack(1), timeOut)
  8507. }
  8508. createScriptTag(scr, url, charset)
  8509. function createScriptTag(scr, url, charset) {
  8510. scr.setAttribute('type', 'text/javascript')
  8511. scr.setAttribute('defer', 'defer')
  8512. charset && scr.setAttribute('charset', charset)
  8513. scr.setAttribute('src', url)
  8514. document.getElementsByTagName('head')[0].appendChild(scr)
  8515. }
  8516. function getCallBack(onTimeOut) {
  8517. return function () {
  8518. try {
  8519. if (onTimeOut) {
  8520. options.onerror && options.onerror()
  8521. } else {
  8522. try {
  8523. clearTimeout(timer)
  8524. successhandler.apply(window, arguments)
  8525. } catch (e) {}
  8526. }
  8527. } catch (exception) {
  8528. options.onerror && options.onerror.call(window, exception)
  8529. } finally {
  8530. options.oncomplete && options.oncomplete.apply(window, arguments)
  8531. scr.parentNode && scr.parentNode.removeChild(scr)
  8532. window[callbackFnName] = null
  8533. try {
  8534. delete window[callbackFnName]
  8535. } catch (e) {}
  8536. }
  8537. }
  8538. }
  8539. }
  8540. return {
  8541. /**
  8542. * 根据给定的参数项,向指定的url发起一个ajax请求。 ajax请求完成后,会根据请求结果调用相应回调: 如果请求
  8543. * 成功, 则调用onsuccess回调, 失败则调用 onerror 回调
  8544. * @method request
  8545. * @param { URLString } url ajax请求的url地址
  8546. * @param { Object } ajaxOptions ajax请求选项的键值对,支持的选项如下:
  8547. * @example
  8548. * ```javascript
  8549. * //向sayhello.php发起一个异步的Ajax GET请求, 请求超时时间为10s, 请求完成后执行相应的回调。
  8550. * UE.ajax.requeset( 'sayhello.php', {
  8551. *
  8552. * //请求方法。可选值: 'GET', 'POST',默认值是'POST'
  8553. * method: 'GET',
  8554. *
  8555. * //超时时间。 默认为5000, 单位是ms
  8556. * timeout: 10000,
  8557. *
  8558. * //是否是异步请求。 true为异步请求, false为同步请求
  8559. * async: true,
  8560. *
  8561. * //请求携带的数据。如果请求为GET请求, data会经过stringify后附加到请求url之后。
  8562. * data: {
  8563. * name: 'ueditor'
  8564. * },
  8565. *
  8566. * //请求成功后的回调, 该回调接受当前的XMLHttpRequest对象作为参数。
  8567. * onsuccess: function ( xhr ) {
  8568. * console.log( xhr.responseText );
  8569. * },
  8570. *
  8571. * //请求失败或者超时后的回调。
  8572. * onerror: function ( xhr ) {
  8573. * alert( 'Ajax请求失败' );
  8574. * }
  8575. *
  8576. * } );
  8577. * ```
  8578. */
  8579. /**
  8580. * 根据给定的参数项发起一个ajax请求, 参数项里必须包含一个url地址。 ajax请求完成后,会根据请求结果调用相应回调: 如果请求
  8581. * 成功, 则调用onsuccess回调, 失败则调用 onerror 回调。
  8582. * @method request
  8583. * @warning 如果在参数项里未提供一个key为“url”的地址值,则该请求将直接退出。
  8584. * @param { Object } ajaxOptions ajax请求选项的键值对,支持的选项如下:
  8585. * @example
  8586. * ```javascript
  8587. *
  8588. * //向sayhello.php发起一个异步的Ajax POST请求, 请求超时时间为5s, 请求完成后不执行任何回调。
  8589. * UE.ajax.requeset( 'sayhello.php', {
  8590. *
  8591. * //请求的地址, 该项是必须的。
  8592. * url: 'sayhello.php'
  8593. *
  8594. * } );
  8595. * ```
  8596. */
  8597. request: function (url, opts) {
  8598. if (opts && opts.dataType == 'jsonp') {
  8599. doJsonp(url, opts)
  8600. } else {
  8601. doAjax(url, opts)
  8602. }
  8603. },
  8604. getJSONP: function (url, data, fn) {
  8605. var opts = {
  8606. data: data,
  8607. oncomplete: fn
  8608. }
  8609. doJsonp(url, opts)
  8610. }
  8611. }
  8612. })()
  8613. // core/filterword.js
  8614. /**
  8615. * UE过滤word的静态方法
  8616. * @file
  8617. */
  8618. /**
  8619. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  8620. * @module UE
  8621. */
  8622. /**
  8623. * 根据传入html字符串过滤word
  8624. * @module UE
  8625. * @since 1.2.6.1
  8626. * @method filterWord
  8627. * @param { String } html html字符串
  8628. * @return { String } 已过滤后的结果字符串
  8629. * @example
  8630. * ```javascript
  8631. * UE.filterWord(html);
  8632. * ```
  8633. */
  8634. var filterWord = (UE.filterWord = (function () {
  8635. //是否是word过来的内容
  8636. function isWordDocument(str) {
  8637. return /(class="?Mso|style="[^"]*\bmso\-|w:WordDocument|<(v|o):|lang=)/gi.test(str)
  8638. }
  8639. //去掉小数
  8640. function transUnit(v) {
  8641. v = v.replace(/[\d.]+\w+/g, function (m) {
  8642. return utils.transUnitToPx(m)
  8643. })
  8644. return v
  8645. }
  8646. function filterPasteWord(str) {
  8647. return (
  8648. str
  8649. .replace(/[\t\r\n]+/g, ' ')
  8650. .replace(/<!--[\s\S]*?-->/gi, '')
  8651. //转换图片
  8652. .replace(/<v:shape [^>]*>[\s\S]*?.<\/v:shape>/gi, function (str) {
  8653. //opera能自己解析出image所这里直接返回空
  8654. if (browser.opera) {
  8655. return ''
  8656. }
  8657. try {
  8658. //有可能是bitmap占为图,无用,直接过滤掉,主要体现在粘贴excel表格中
  8659. if (/Bitmap/i.test(str)) {
  8660. return ''
  8661. }
  8662. var width = str.match(/width:([ \d.]*p[tx])/i)[1],
  8663. height = str.match(/height:([ \d.]*p[tx])/i)[1],
  8664. src = str.match(/src=\s*"([^"]*)"/i)[1]
  8665. return (
  8666. '<img width="' +
  8667. transUnit(width) +
  8668. '" height="' +
  8669. transUnit(height) +
  8670. '" src="' +
  8671. src +
  8672. '" />'
  8673. )
  8674. } catch (e) {
  8675. return ''
  8676. }
  8677. })
  8678. //针对wps添加的多余标签处理
  8679. .replace(/<\/?div[^>]*>/g, '')
  8680. //去掉多余的属性
  8681. .replace(/v:\w+=(["']?)[^'"]+\1/g, '')
  8682. .replace(
  8683. /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|xml|meta|link|style|\w+:\w+)(?=[\s\/>]))[^>]*>/gi,
  8684. ''
  8685. )
  8686. .replace(/<p [^>]*class="?MsoHeading"?[^>]*>(.*?)<\/p>/gi, '<p><strong>$1</strong></p>')
  8687. //去掉多余的属性
  8688. .replace(
  8689. /\s+(class|lang|align)\s*=\s*(['"]?)([\w-]+)\2/gi,
  8690. function (str, name, marks, val) {
  8691. //保留list的标示
  8692. return name == 'class' && val == 'MsoListParagraph' ? str : ''
  8693. }
  8694. )
  8695. //清除多余的font/span不能匹配&nbsp;有可能是空格
  8696. .replace(/<(font|span)[^>]*>(\s*)<\/\1>/gi, function (a, b, c) {
  8697. return c.replace(/[\t\r\n ]+/g, ' ')
  8698. })
  8699. //处理style的问题
  8700. .replace(/(<[a-z][^>]*)\sstyle=(["'])([^\2]*?)\2/gi, function (str, tag, tmp, style) {
  8701. var n = [],
  8702. s = style
  8703. .replace(/^\s+|\s+$/, '')
  8704. .replace(/&#39;/g, "'")
  8705. .replace(/&quot;/gi, "'")
  8706. .replace(/[\d.]+(cm|pt)/g, function (str) {
  8707. return utils.transUnitToPx(str)
  8708. })
  8709. .split(/;\s*/g)
  8710. for (var i = 0, v; (v = s[i]); i++) {
  8711. var name,
  8712. value,
  8713. parts = v.split(':')
  8714. if (parts.length == 2) {
  8715. name = parts[0].toLowerCase()
  8716. value = parts[1].toLowerCase()
  8717. if (
  8718. (/^(background)\w*/.test(name) &&
  8719. value.replace(/(initial|\s)/g, '').length == 0) ||
  8720. (/^(margin)\w*/.test(name) && /^0\w+$/.test(value))
  8721. ) {
  8722. continue
  8723. }
  8724. switch (name) {
  8725. case 'mso-padding-alt':
  8726. case 'mso-padding-top-alt':
  8727. case 'mso-padding-right-alt':
  8728. case 'mso-padding-bottom-alt':
  8729. case 'mso-padding-left-alt':
  8730. case 'mso-margin-alt':
  8731. case 'mso-margin-top-alt':
  8732. case 'mso-margin-right-alt':
  8733. case 'mso-margin-bottom-alt':
  8734. case 'mso-margin-left-alt':
  8735. //ie下会出现挤到一起的情况
  8736. //case "mso-table-layout-alt":
  8737. case 'mso-height':
  8738. case 'mso-width':
  8739. case 'mso-vertical-align-alt':
  8740. //trace:1819 ff下会解析出padding在table上
  8741. if (!/<table/.test(tag))
  8742. n[i] = name.replace(/^mso-|-alt$/g, '') + ':' + transUnit(value)
  8743. continue
  8744. case 'horiz-align':
  8745. n[i] = 'text-align:' + value
  8746. continue
  8747. case 'vert-align':
  8748. n[i] = 'vertical-align:' + value
  8749. continue
  8750. case 'font-color':
  8751. case 'mso-foreground':
  8752. n[i] = 'color:' + value
  8753. continue
  8754. case 'mso-background':
  8755. case 'mso-highlight':
  8756. n[i] = 'background:' + value
  8757. continue
  8758. case 'mso-default-height':
  8759. n[i] = 'min-height:' + transUnit(value)
  8760. continue
  8761. case 'mso-default-width':
  8762. n[i] = 'min-width:' + transUnit(value)
  8763. continue
  8764. case 'mso-padding-between-alt':
  8765. n[i] = 'border-collapse:separate;border-spacing:' + transUnit(value)
  8766. continue
  8767. case 'text-line-through':
  8768. if (value == 'single' || value == 'double') {
  8769. n[i] = 'text-decoration:line-through'
  8770. }
  8771. continue
  8772. case 'mso-zero-height':
  8773. if (value == 'yes') {
  8774. n[i] = 'display:none'
  8775. }
  8776. continue
  8777. // case 'background':
  8778. // break;
  8779. case 'margin':
  8780. if (!/[1-9]/.test(value)) {
  8781. continue
  8782. }
  8783. }
  8784. if (
  8785. /^(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(
  8786. name
  8787. ) ||
  8788. (/text\-indent|padding|margin/.test(name) && /\-[\d.]+/.test(value))
  8789. ) {
  8790. continue
  8791. }
  8792. n[i] = name + ':' + parts[1]
  8793. }
  8794. }
  8795. return tag + (n.length ? ' style="' + n.join(';').replace(/;{2,}/g, ';') + '"' : '')
  8796. })
  8797. )
  8798. }
  8799. return function (html) {
  8800. return isWordDocument(html) ? filterPasteWord(html) : html
  8801. }
  8802. })())
  8803. // core/node.js
  8804. /**
  8805. * 编辑器模拟的节点类
  8806. * @file
  8807. * @module UE
  8808. * @class uNode
  8809. * @since 1.2.6.1
  8810. */
  8811. /**
  8812. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  8813. * @unfile
  8814. * @module UE
  8815. */
  8816. ;(function () {
  8817. /**
  8818. * 编辑器模拟的节点类
  8819. * @unfile
  8820. * @module UE
  8821. * @class uNode
  8822. */
  8823. /**
  8824. * 通过一个键值对,创建一个uNode对象
  8825. * @constructor
  8826. * @param { Object } attr 传入要创建的uNode的初始属性
  8827. * @example
  8828. * ```javascript
  8829. * var node = new uNode({
  8830. * type:'element',
  8831. * tagName:'span',
  8832. * attrs:{style:'font-size:14px;'}
  8833. * }
  8834. * ```
  8835. */
  8836. var uNode = (UE.uNode = function (obj) {
  8837. this.type = obj.type
  8838. this.data = obj.data
  8839. this.tagName = obj.tagName
  8840. this.parentNode = obj.parentNode
  8841. this.attrs = obj.attrs || {}
  8842. this.children = obj.children
  8843. })
  8844. var notTransAttrs = {
  8845. href: 1,
  8846. src: 1,
  8847. _src: 1,
  8848. _href: 1,
  8849. cdata_data: 1
  8850. }
  8851. var notTransTagName = {
  8852. style: 1,
  8853. script: 1
  8854. }
  8855. var indentChar = ' ',
  8856. breakChar = '\n'
  8857. function insertLine(arr, current, begin) {
  8858. arr.push(breakChar)
  8859. return current + (begin ? 1 : -1)
  8860. }
  8861. function insertIndent(arr, current) {
  8862. //插入缩进
  8863. for (var i = 0; i < current; i++) {
  8864. arr.push(indentChar)
  8865. }
  8866. }
  8867. //创建uNode的静态方法
  8868. //支持标签和html
  8869. uNode.createElement = function (html) {
  8870. if (/[<>]/.test(html)) {
  8871. return UE.htmlparser(html).children[0]
  8872. } else {
  8873. return new uNode({
  8874. type: 'element',
  8875. children: [],
  8876. tagName: html
  8877. })
  8878. }
  8879. }
  8880. uNode.createText = function (data, noTrans) {
  8881. return new UE.uNode({
  8882. type: 'text',
  8883. data: noTrans ? data : utils.unhtml(data || '')
  8884. })
  8885. }
  8886. function nodeToHtml(node, arr, formatter, current) {
  8887. switch (node.type) {
  8888. case 'root':
  8889. for (var i = 0, ci; (ci = node.children[i++]); ) {
  8890. //插入新行
  8891. if (formatter && ci.type == 'element' && !dtd.$inlineWithA[ci.tagName] && i > 1) {
  8892. insertLine(arr, current, true)
  8893. insertIndent(arr, current)
  8894. }
  8895. nodeToHtml(ci, arr, formatter, current)
  8896. }
  8897. break
  8898. case 'text':
  8899. isText(node, arr)
  8900. break
  8901. case 'element':
  8902. isElement(node, arr, formatter, current)
  8903. break
  8904. case 'comment':
  8905. isComment(node, arr, formatter)
  8906. }
  8907. return arr
  8908. }
  8909. function isText(node, arr) {
  8910. if (node.parentNode.tagName == 'pre') {
  8911. //源码模式下输入html标签,不能做转换处理,直接输出
  8912. arr.push(node.data)
  8913. } else {
  8914. arr.push(
  8915. notTransTagName[node.parentNode.tagName]
  8916. ? utils.html(node.data)
  8917. : node.data.replace(/[ ]{2}/g, ' &nbsp;')
  8918. )
  8919. }
  8920. }
  8921. function isElement(node, arr, formatter, current) {
  8922. var attrhtml = ''
  8923. if (node.attrs) {
  8924. attrhtml = []
  8925. var attrs = node.attrs
  8926. for (var a in attrs) {
  8927. //这里就针对
  8928. //<p>'<img src='http://nsclick.baidu.com/u.gif?&asdf=\"sdf&asdfasdfs;asdf'></p>
  8929. //这里边的\"做转换,要不用innerHTML直接被截断了,属性src
  8930. //有可能做的不够
  8931. attrhtml.push(
  8932. a +
  8933. (attrs[a] !== undefined
  8934. ? '="' +
  8935. (notTransAttrs[a]
  8936. ? utils.html(attrs[a]).replace(/["]/g, function (a) {
  8937. return '&quot;'
  8938. })
  8939. : utils.unhtml(attrs[a])) +
  8940. '"'
  8941. : '')
  8942. )
  8943. }
  8944. attrhtml = attrhtml.join(' ')
  8945. }
  8946. arr.push(
  8947. '<' +
  8948. node.tagName +
  8949. (attrhtml ? ' ' + attrhtml : '') +
  8950. (dtd.$empty[node.tagName] ? '/' : '') +
  8951. '>'
  8952. )
  8953. //插入新行
  8954. if (formatter && !dtd.$inlineWithA[node.tagName] && node.tagName != 'pre') {
  8955. if (node.children && node.children.length) {
  8956. current = insertLine(arr, current, true)
  8957. insertIndent(arr, current)
  8958. }
  8959. }
  8960. if (node.children && node.children.length) {
  8961. for (var i = 0, ci; (ci = node.children[i++]); ) {
  8962. if (formatter && ci.type == 'element' && !dtd.$inlineWithA[ci.tagName] && i > 1) {
  8963. insertLine(arr, current)
  8964. insertIndent(arr, current)
  8965. }
  8966. nodeToHtml(ci, arr, formatter, current)
  8967. }
  8968. }
  8969. if (!dtd.$empty[node.tagName]) {
  8970. if (formatter && !dtd.$inlineWithA[node.tagName] && node.tagName != 'pre') {
  8971. if (node.children && node.children.length) {
  8972. current = insertLine(arr, current)
  8973. insertIndent(arr, current)
  8974. }
  8975. }
  8976. arr.push('</' + node.tagName + '>')
  8977. }
  8978. }
  8979. function isComment(node, arr) {
  8980. arr.push('<!--' + node.data + '-->')
  8981. }
  8982. function getNodeById(root, id) {
  8983. var node
  8984. if (root.type == 'element' && root.getAttr('id') == id) {
  8985. return root
  8986. }
  8987. if (root.children && root.children.length) {
  8988. for (var i = 0, ci; (ci = root.children[i++]); ) {
  8989. if ((node = getNodeById(ci, id))) {
  8990. return node
  8991. }
  8992. }
  8993. }
  8994. }
  8995. function getNodesByTagName(node, tagName, arr) {
  8996. if (node.type == 'element' && node.tagName == tagName) {
  8997. arr.push(node)
  8998. }
  8999. if (node.children && node.children.length) {
  9000. for (var i = 0, ci; (ci = node.children[i++]); ) {
  9001. getNodesByTagName(ci, tagName, arr)
  9002. }
  9003. }
  9004. }
  9005. function nodeTraversal(root, fn) {
  9006. if (root.children && root.children.length) {
  9007. for (var i = 0, ci; (ci = root.children[i]); ) {
  9008. nodeTraversal(ci, fn)
  9009. //ci被替换的情况,这里就不再走 fn了
  9010. if (ci.parentNode) {
  9011. if (ci.children && ci.children.length) {
  9012. fn(ci)
  9013. }
  9014. if (ci.parentNode) i++
  9015. }
  9016. }
  9017. } else {
  9018. fn(root)
  9019. }
  9020. }
  9021. uNode.prototype = {
  9022. /**
  9023. * 当前节点对象,转换成html文本
  9024. * @method toHtml
  9025. * @return { String } 返回转换后的html字符串
  9026. * @example
  9027. * ```javascript
  9028. * node.toHtml();
  9029. * ```
  9030. */
  9031. /**
  9032. * 当前节点对象,转换成html文本
  9033. * @method toHtml
  9034. * @param { Boolean } formatter 是否格式化返回值
  9035. * @return { String } 返回转换后的html字符串
  9036. * @example
  9037. * ```javascript
  9038. * node.toHtml( true );
  9039. * ```
  9040. */
  9041. toHtml: function (formatter) {
  9042. var arr = []
  9043. nodeToHtml(this, arr, formatter, 0)
  9044. return arr.join('')
  9045. },
  9046. /**
  9047. * 获取节点的html内容
  9048. * @method innerHTML
  9049. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  9050. * @return { String } 返回节点的html内容
  9051. * @example
  9052. * ```javascript
  9053. * var htmlstr = node.innerHTML();
  9054. * ```
  9055. */
  9056. /**
  9057. * 设置节点的html内容
  9058. * @method innerHTML
  9059. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  9060. * @param { String } htmlstr 传入要设置的html内容
  9061. * @return { UE.uNode } 返回节点本身
  9062. * @example
  9063. * ```javascript
  9064. * node.innerHTML('<span>text</span>');
  9065. * ```
  9066. */
  9067. innerHTML: function (htmlstr) {
  9068. if (this.type != 'element' || dtd.$empty[this.tagName]) {
  9069. return this
  9070. }
  9071. if (utils.isString(htmlstr)) {
  9072. if (this.children) {
  9073. for (var i = 0, ci; (ci = this.children[i++]); ) {
  9074. ci.parentNode = null
  9075. }
  9076. }
  9077. this.children = []
  9078. var tmpRoot = UE.htmlparser(htmlstr)
  9079. for (var i = 0, ci; (ci = tmpRoot.children[i++]); ) {
  9080. this.children.push(ci)
  9081. ci.parentNode = this
  9082. }
  9083. return this
  9084. } else {
  9085. var tmpRoot = new UE.uNode({
  9086. type: 'root',
  9087. children: this.children
  9088. })
  9089. return tmpRoot.toHtml()
  9090. }
  9091. },
  9092. /**
  9093. * 获取节点的纯文本内容
  9094. * @method innerText
  9095. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  9096. * @return { String } 返回节点的存文本内容
  9097. * @example
  9098. * ```javascript
  9099. * var textStr = node.innerText();
  9100. * ```
  9101. */
  9102. /**
  9103. * 设置节点的纯文本内容
  9104. * @method innerText
  9105. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  9106. * @param { String } textStr 传入要设置的文本内容
  9107. * @return { UE.uNode } 返回节点本身
  9108. * @example
  9109. * ```javascript
  9110. * node.innerText('<span>text</span>');
  9111. * ```
  9112. */
  9113. innerText: function (textStr, noTrans) {
  9114. if (this.type != 'element' || dtd.$empty[this.tagName]) {
  9115. return this
  9116. }
  9117. if (textStr) {
  9118. if (this.children) {
  9119. for (var i = 0, ci; (ci = this.children[i++]); ) {
  9120. ci.parentNode = null
  9121. }
  9122. }
  9123. this.children = []
  9124. this.appendChild(uNode.createText(textStr, noTrans))
  9125. return this
  9126. } else {
  9127. return this.toHtml().replace(/<[^>]+>/g, '')
  9128. }
  9129. },
  9130. /**
  9131. * 获取当前对象的data属性
  9132. * @method getData
  9133. * @return { Object } 若节点的type值是elemenet,返回空字符串,否则返回节点的data属性
  9134. * @example
  9135. * ```javascript
  9136. * node.getData();
  9137. * ```
  9138. */
  9139. getData: function () {
  9140. if (this.type == 'element') return ''
  9141. return this.data
  9142. },
  9143. /**
  9144. * 获取当前节点下的第一个子节点
  9145. * @method firstChild
  9146. * @return { UE.uNode } 返回第一个子节点
  9147. * @example
  9148. * ```javascript
  9149. * node.firstChild(); //返回第一个子节点
  9150. * ```
  9151. */
  9152. firstChild: function () {
  9153. // if (this.type != 'element' || dtd.$empty[this.tagName]) {
  9154. // return this;
  9155. // }
  9156. return this.children ? this.children[0] : null
  9157. },
  9158. /**
  9159. * 获取当前节点下的最后一个子节点
  9160. * @method lastChild
  9161. * @return { UE.uNode } 返回最后一个子节点
  9162. * @example
  9163. * ```javascript
  9164. * node.lastChild(); //返回最后一个子节点
  9165. * ```
  9166. */
  9167. lastChild: function () {
  9168. // if (this.type != 'element' || dtd.$empty[this.tagName] ) {
  9169. // return this;
  9170. // }
  9171. return this.children ? this.children[this.children.length - 1] : null
  9172. },
  9173. /**
  9174. * 获取和当前节点有相同父亲节点的前一个节点
  9175. * @method previousSibling
  9176. * @return { UE.uNode } 返回前一个节点
  9177. * @example
  9178. * ```javascript
  9179. * node.children[2].previousSibling(); //返回子节点node.children[1]
  9180. * ```
  9181. */
  9182. previousSibling: function () {
  9183. var parent = this.parentNode
  9184. for (var i = 0, ci; (ci = parent.children[i]); i++) {
  9185. if (ci === this) {
  9186. return i == 0 ? null : parent.children[i - 1]
  9187. }
  9188. }
  9189. },
  9190. /**
  9191. * 获取和当前节点有相同父亲节点的后一个节点
  9192. * @method nextSibling
  9193. * @return { UE.uNode } 返回后一个节点,找不到返回null
  9194. * @example
  9195. * ```javascript
  9196. * node.children[2].nextSibling(); //如果有,返回子节点node.children[3]
  9197. * ```
  9198. */
  9199. nextSibling: function () {
  9200. var parent = this.parentNode
  9201. for (var i = 0, ci; (ci = parent.children[i++]); ) {
  9202. if (ci === this) {
  9203. return parent.children[i]
  9204. }
  9205. }
  9206. },
  9207. /**
  9208. * 用新的节点替换当前节点
  9209. * @method replaceChild
  9210. * @param { UE.uNode } target 要替换成该节点参数
  9211. * @param { UE.uNode } source 要被替换掉的节点
  9212. * @return { UE.uNode } 返回替换之后的节点对象
  9213. * @example
  9214. * ```javascript
  9215. * node.replaceChild(newNode, childNode); //用newNode替换childNode,childNode是node的子节点
  9216. * ```
  9217. */
  9218. replaceChild: function (target, source) {
  9219. if (this.children) {
  9220. if (target.parentNode) {
  9221. target.parentNode.removeChild(target)
  9222. }
  9223. for (var i = 0, ci; (ci = this.children[i]); i++) {
  9224. if (ci === source) {
  9225. this.children.splice(i, 1, target)
  9226. source.parentNode = null
  9227. target.parentNode = this
  9228. return target
  9229. }
  9230. }
  9231. }
  9232. },
  9233. /**
  9234. * 在节点的子节点列表最后位置插入一个节点
  9235. * @method appendChild
  9236. * @param { UE.uNode } node 要插入的节点
  9237. * @return { UE.uNode } 返回刚插入的子节点
  9238. * @example
  9239. * ```javascript
  9240. * node.appendChild( newNode ); //在node内插入子节点newNode
  9241. * ```
  9242. */
  9243. appendChild: function (node) {
  9244. if (this.type == 'root' || (this.type == 'element' && !dtd.$empty[this.tagName])) {
  9245. if (!this.children) {
  9246. this.children = []
  9247. }
  9248. if (node.parentNode) {
  9249. node.parentNode.removeChild(node)
  9250. }
  9251. for (var i = 0, ci; (ci = this.children[i]); i++) {
  9252. if (ci === node) {
  9253. this.children.splice(i, 1)
  9254. break
  9255. }
  9256. }
  9257. this.children.push(node)
  9258. node.parentNode = this
  9259. return node
  9260. }
  9261. },
  9262. /**
  9263. * 在传入节点的前面插入一个节点
  9264. * @method insertBefore
  9265. * @param { UE.uNode } target 要插入的节点
  9266. * @param { UE.uNode } source 在该参数节点前面插入
  9267. * @return { UE.uNode } 返回刚插入的子节点
  9268. * @example
  9269. * ```javascript
  9270. * node.parentNode.insertBefore(newNode, node); //在node节点后面插入newNode
  9271. * ```
  9272. */
  9273. insertBefore: function (target, source) {
  9274. if (this.children) {
  9275. if (target.parentNode) {
  9276. target.parentNode.removeChild(target)
  9277. }
  9278. for (var i = 0, ci; (ci = this.children[i]); i++) {
  9279. if (ci === source) {
  9280. this.children.splice(i, 0, target)
  9281. target.parentNode = this
  9282. return target
  9283. }
  9284. }
  9285. }
  9286. },
  9287. /**
  9288. * 在传入节点的后面插入一个节点
  9289. * @method insertAfter
  9290. * @param { UE.uNode } target 要插入的节点
  9291. * @param { UE.uNode } source 在该参数节点后面插入
  9292. * @return { UE.uNode } 返回刚插入的子节点
  9293. * @example
  9294. * ```javascript
  9295. * node.parentNode.insertAfter(newNode, node); //在node节点后面插入newNode
  9296. * ```
  9297. */
  9298. insertAfter: function (target, source) {
  9299. if (this.children) {
  9300. if (target.parentNode) {
  9301. target.parentNode.removeChild(target)
  9302. }
  9303. for (var i = 0, ci; (ci = this.children[i]); i++) {
  9304. if (ci === source) {
  9305. this.children.splice(i + 1, 0, target)
  9306. target.parentNode = this
  9307. return target
  9308. }
  9309. }
  9310. }
  9311. },
  9312. /**
  9313. * 从当前节点的子节点列表中,移除节点
  9314. * @method removeChild
  9315. * @param { UE.uNode } node 要移除的节点引用
  9316. * @param { Boolean } keepChildren 是否保留移除节点的子节点,若传入true,自动把移除节点的子节点插入到移除的位置
  9317. * @return { * } 返回刚移除的子节点
  9318. * @example
  9319. * ```javascript
  9320. * node.removeChild(childNode,true); //在node的子节点列表中移除child节点,并且吧child的子节点插入到移除的位置
  9321. * ```
  9322. */
  9323. removeChild: function (node, keepChildren) {
  9324. if (this.children) {
  9325. for (var i = 0, ci; (ci = this.children[i]); i++) {
  9326. if (ci === node) {
  9327. this.children.splice(i, 1)
  9328. ci.parentNode = null
  9329. if (keepChildren && ci.children && ci.children.length) {
  9330. for (var j = 0, cj; (cj = ci.children[j]); j++) {
  9331. this.children.splice(i + j, 0, cj)
  9332. cj.parentNode = this
  9333. }
  9334. }
  9335. return ci
  9336. }
  9337. }
  9338. }
  9339. },
  9340. /**
  9341. * 获取当前节点所代表的元素属性,即获取attrs对象下的属性值
  9342. * @method getAttr
  9343. * @param { String } attrName 要获取的属性名称
  9344. * @return { * } 返回attrs对象下的属性值
  9345. * @example
  9346. * ```javascript
  9347. * node.getAttr('title');
  9348. * ```
  9349. */
  9350. getAttr: function (attrName) {
  9351. return this.attrs && this.attrs[attrName.toLowerCase()]
  9352. },
  9353. /**
  9354. * 设置当前节点所代表的元素属性,即设置attrs对象下的属性值
  9355. * @method setAttr
  9356. * @param { String } attrName 要设置的属性名称
  9357. * @param { * } attrVal 要设置的属性值,类型视设置的属性而定
  9358. * @return { * } 返回attrs对象下的属性值
  9359. * @example
  9360. * ```javascript
  9361. * node.setAttr('title','标题');
  9362. * ```
  9363. */
  9364. setAttr: function (attrName, attrVal) {
  9365. if (!attrName) {
  9366. delete this.attrs
  9367. return
  9368. }
  9369. if (!this.attrs) {
  9370. this.attrs = {}
  9371. }
  9372. if (utils.isObject(attrName)) {
  9373. for (var a in attrName) {
  9374. if (!attrName[a]) {
  9375. delete this.attrs[a]
  9376. } else {
  9377. this.attrs[a.toLowerCase()] = attrName[a]
  9378. }
  9379. }
  9380. } else {
  9381. if (!attrVal) {
  9382. delete this.attrs[attrName]
  9383. } else {
  9384. this.attrs[attrName.toLowerCase()] = attrVal
  9385. }
  9386. }
  9387. },
  9388. /**
  9389. * 获取当前节点在父节点下的位置索引
  9390. * @method getIndex
  9391. * @return { Number } 返回索引数值,如果没有父节点,返回-1
  9392. * @example
  9393. * ```javascript
  9394. * node.getIndex();
  9395. * ```
  9396. */
  9397. getIndex: function () {
  9398. var parent = this.parentNode
  9399. for (var i = 0, ci; (ci = parent.children[i]); i++) {
  9400. if (ci === this) {
  9401. return i
  9402. }
  9403. }
  9404. return -1
  9405. },
  9406. /**
  9407. * 在当前节点下,根据id查找节点
  9408. * @method getNodeById
  9409. * @param { String } id 要查找的id
  9410. * @return { UE.uNode } 返回找到的节点
  9411. * @example
  9412. * ```javascript
  9413. * node.getNodeById('textId');
  9414. * ```
  9415. */
  9416. getNodeById: function (id) {
  9417. var node
  9418. if (this.children && this.children.length) {
  9419. for (var i = 0, ci; (ci = this.children[i++]); ) {
  9420. if ((node = getNodeById(ci, id))) {
  9421. return node
  9422. }
  9423. }
  9424. }
  9425. },
  9426. /**
  9427. * 在当前节点下,根据元素名称查找节点列表
  9428. * @method getNodesByTagName
  9429. * @param { String } tagNames 要查找的元素名称
  9430. * @return { Array } 返回找到的节点列表
  9431. * @example
  9432. * ```javascript
  9433. * node.getNodesByTagName('span');
  9434. * ```
  9435. */
  9436. getNodesByTagName: function (tagNames) {
  9437. tagNames = utils
  9438. .trim(tagNames)
  9439. .replace(/[ ]{2,}/g, ' ')
  9440. .split(' ')
  9441. var arr = [],
  9442. me = this
  9443. utils.each(tagNames, function (tagName) {
  9444. if (me.children && me.children.length) {
  9445. for (var i = 0, ci; (ci = me.children[i++]); ) {
  9446. getNodesByTagName(ci, tagName, arr)
  9447. }
  9448. }
  9449. })
  9450. return arr
  9451. },
  9452. /**
  9453. * 根据样式名称,获取节点的样式值
  9454. * @method getStyle
  9455. * @param { String } name 要获取的样式名称
  9456. * @return { String } 返回样式值
  9457. * @example
  9458. * ```javascript
  9459. * node.getStyle('font-size');
  9460. * ```
  9461. */
  9462. getStyle: function (name) {
  9463. var cssStyle = this.getAttr('style')
  9464. if (!cssStyle) {
  9465. return ''
  9466. }
  9467. var reg = new RegExp('(^|;)\\s*' + name + ':([^;]+)', 'i')
  9468. var match = cssStyle.match(reg)
  9469. if (match && match[0]) {
  9470. return match[2]
  9471. }
  9472. return ''
  9473. },
  9474. /**
  9475. * 给节点设置样式
  9476. * @method setStyle
  9477. * @param { String } name 要设置的的样式名称
  9478. * @param { String } val 要设置的的样值
  9479. * @example
  9480. * ```javascript
  9481. * node.setStyle('font-size', '12px');
  9482. * ```
  9483. */
  9484. setStyle: function (name, val) {
  9485. function exec(name, val) {
  9486. var reg = new RegExp('(^|;)\\s*' + name + ':([^;]+;?)', 'gi')
  9487. cssStyle = cssStyle.replace(reg, '$1')
  9488. if (val) {
  9489. cssStyle = name + ':' + utils.unhtml(val) + ';' + cssStyle
  9490. }
  9491. }
  9492. var cssStyle = this.getAttr('style')
  9493. if (!cssStyle) {
  9494. cssStyle = ''
  9495. }
  9496. if (utils.isObject(name)) {
  9497. for (var a in name) {
  9498. exec(a, name[a])
  9499. }
  9500. } else {
  9501. exec(name, val)
  9502. }
  9503. this.setAttr('style', utils.trim(cssStyle))
  9504. },
  9505. /**
  9506. * 传入一个函数,递归遍历当前节点下的所有节点
  9507. * @method traversal
  9508. * @param { Function } fn 遍历到节点的时,传入节点作为参数,运行此函数
  9509. * @example
  9510. * ```javascript
  9511. * traversal(node, function(){
  9512. * console.log(node.type);
  9513. * });
  9514. * ```
  9515. */
  9516. traversal: function (fn) {
  9517. if (this.children && this.children.length) {
  9518. nodeTraversal(this, fn)
  9519. }
  9520. return this
  9521. }
  9522. }
  9523. })()
  9524. // core/htmlparser.js
  9525. /**
  9526. * html字符串转换成uNode节点
  9527. * @file
  9528. * @module UE
  9529. * @since 1.2.6.1
  9530. */
  9531. /**
  9532. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  9533. * @unfile
  9534. * @module UE
  9535. */
  9536. /**
  9537. * html字符串转换成uNode节点的静态方法
  9538. * @method htmlparser
  9539. * @param { String } htmlstr 要转换的html代码
  9540. * @param { Boolean } ignoreBlank 若设置为true,转换的时候忽略\n\r\t等空白字符
  9541. * @return { uNode } 给定的html片段转换形成的uNode对象
  9542. * @example
  9543. * ```javascript
  9544. * var root = UE.htmlparser('<p><b>htmlparser</b></p>', true);
  9545. * ```
  9546. */
  9547. var htmlparser = (UE.htmlparser = function (htmlstr, ignoreBlank) {
  9548. //todo 原来的方式 [^"'<>\/] 有\/就不能配对上 <TD vAlign=top background=../AAA.JPG> 这样的标签了
  9549. //先去掉了,加上的原因忘了,这里先记录
  9550. var re_tag =
  9551. /<(?:(?:\/([^>]+)>)|(?:!--([\S|\s]*?)-->)|(?:([^\s\/<>]+)\s*((?:(?:"[^"]*")|(?:'[^']*')|[^"'<>])*)\/?>))/g,
  9552. re_attr = /([\w\-:.]+)(?:(?:\s*=\s*(?:(?:"([^"]*)")|(?:'([^']*)')|([^\s>]+)))|(?=\s|$))/g
  9553. //ie下取得的html可能会有\n存在,要去掉,在处理replace(/[\t\r\n]*/g,'');代码高量的\n不能去除
  9554. var allowEmptyTags = {
  9555. b: 1,
  9556. code: 1,
  9557. i: 1,
  9558. u: 1,
  9559. strike: 1,
  9560. s: 1,
  9561. tt: 1,
  9562. strong: 1,
  9563. q: 1,
  9564. samp: 1,
  9565. em: 1,
  9566. span: 1,
  9567. sub: 1,
  9568. img: 1,
  9569. sup: 1,
  9570. font: 1,
  9571. big: 1,
  9572. small: 1,
  9573. iframe: 1,
  9574. a: 1,
  9575. br: 1,
  9576. pre: 1
  9577. }
  9578. htmlstr = htmlstr.replace(new RegExp(domUtils.fillChar, 'g'), '')
  9579. if (!ignoreBlank) {
  9580. htmlstr = htmlstr.replace(
  9581. new RegExp(
  9582. '[\\r\\t\\n' +
  9583. (ignoreBlank ? '' : ' ') +
  9584. ']*</?(\\w+)\\s*(?:[^>]*)>[\\r\\t\\n' +
  9585. (ignoreBlank ? '' : ' ') +
  9586. ']*',
  9587. 'g'
  9588. ),
  9589. function (a, b) {
  9590. //br暂时单独处理
  9591. if (b && allowEmptyTags[b.toLowerCase()]) {
  9592. return a.replace(/(^[\n\r]+)|([\n\r]+$)/g, '')
  9593. }
  9594. return a
  9595. .replace(new RegExp('^[\\r\\n' + (ignoreBlank ? '' : ' ') + ']+'), '')
  9596. .replace(new RegExp('[\\r\\n' + (ignoreBlank ? '' : ' ') + ']+$'), '')
  9597. }
  9598. )
  9599. }
  9600. var notTransAttrs = {
  9601. href: 1,
  9602. src: 1
  9603. }
  9604. var uNode = UE.uNode,
  9605. needParentNode = {
  9606. td: 'tr',
  9607. tr: ['tbody', 'thead', 'tfoot'],
  9608. tbody: 'table',
  9609. th: 'tr',
  9610. thead: 'table',
  9611. tfoot: 'table',
  9612. caption: 'table',
  9613. li: ['ul', 'ol'],
  9614. dt: 'dl',
  9615. dd: 'dl',
  9616. option: 'select'
  9617. },
  9618. needChild = {
  9619. ol: 'li',
  9620. ul: 'li'
  9621. }
  9622. function text(parent, data) {
  9623. if (needChild[parent.tagName]) {
  9624. var tmpNode = uNode.createElement(needChild[parent.tagName])
  9625. parent.appendChild(tmpNode)
  9626. tmpNode.appendChild(uNode.createText(data))
  9627. parent = tmpNode
  9628. } else {
  9629. parent.appendChild(uNode.createText(data))
  9630. }
  9631. }
  9632. function element(parent, tagName, htmlattr) {
  9633. var needParentTag
  9634. if ((needParentTag = needParentNode[tagName])) {
  9635. var tmpParent = parent,
  9636. hasParent
  9637. while (tmpParent.type != 'root') {
  9638. if (
  9639. utils.isArray(needParentTag)
  9640. ? utils.indexOf(needParentTag, tmpParent.tagName) != -1
  9641. : needParentTag == tmpParent.tagName
  9642. ) {
  9643. parent = tmpParent
  9644. hasParent = true
  9645. break
  9646. }
  9647. tmpParent = tmpParent.parentNode
  9648. }
  9649. if (!hasParent) {
  9650. parent = element(parent, utils.isArray(needParentTag) ? needParentTag[0] : needParentTag)
  9651. }
  9652. }
  9653. //按dtd处理嵌套
  9654. // if(parent.type != 'root' && !dtd[parent.tagName][tagName])
  9655. // parent = parent.parentNode;
  9656. var elm = new uNode({
  9657. parentNode: parent,
  9658. type: 'element',
  9659. tagName: tagName.toLowerCase(),
  9660. //是自闭合的处理一下
  9661. children: dtd.$empty[tagName] ? null : []
  9662. })
  9663. //如果属性存在,处理属性
  9664. if (htmlattr) {
  9665. var attrs = {},
  9666. match
  9667. while ((match = re_attr.exec(htmlattr))) {
  9668. attrs[match[1].toLowerCase()] = notTransAttrs[match[1].toLowerCase()]
  9669. ? match[2] || match[3] || match[4]
  9670. : utils.unhtml(match[2] || match[3] || match[4])
  9671. }
  9672. elm.attrs = attrs
  9673. }
  9674. //trace:3970
  9675. // //如果parent下不能放elm
  9676. // if(dtd.$inline[parent.tagName] && dtd.$block[elm.tagName] && !dtd[parent.tagName][elm.tagName]){
  9677. // parent = parent.parentNode;
  9678. // elm.parentNode = parent;
  9679. // }
  9680. parent.children.push(elm)
  9681. //如果是自闭合节点返回父亲节点
  9682. return dtd.$empty[tagName] ? parent : elm
  9683. }
  9684. function comment(parent, data) {
  9685. parent.children.push(
  9686. new uNode({
  9687. type: 'comment',
  9688. data: data,
  9689. parentNode: parent
  9690. })
  9691. )
  9692. }
  9693. var match,
  9694. currentIndex = 0,
  9695. nextIndex = 0
  9696. //设置根节点
  9697. var root = new uNode({
  9698. type: 'root',
  9699. children: []
  9700. })
  9701. var currentParent = root
  9702. while ((match = re_tag.exec(htmlstr))) {
  9703. currentIndex = match.index
  9704. try {
  9705. if (currentIndex > nextIndex) {
  9706. //text node
  9707. text(currentParent, htmlstr.slice(nextIndex, currentIndex))
  9708. }
  9709. if (match[3]) {
  9710. if (dtd.$cdata[currentParent.tagName]) {
  9711. text(currentParent, match[0])
  9712. } else {
  9713. //start tag
  9714. currentParent = element(currentParent, match[3].toLowerCase(), match[4])
  9715. }
  9716. } else if (match[1]) {
  9717. if (currentParent.type != 'root') {
  9718. if (dtd.$cdata[currentParent.tagName] && !dtd.$cdata[match[1]]) {
  9719. text(currentParent, match[0])
  9720. } else {
  9721. var tmpParent = currentParent
  9722. while (
  9723. currentParent.type == 'element' &&
  9724. currentParent.tagName != match[1].toLowerCase()
  9725. ) {
  9726. currentParent = currentParent.parentNode
  9727. if (currentParent.type == 'root') {
  9728. currentParent = tmpParent
  9729. throw 'break'
  9730. }
  9731. }
  9732. //end tag
  9733. currentParent = currentParent.parentNode
  9734. }
  9735. }
  9736. } else if (match[2]) {
  9737. //comment
  9738. comment(currentParent, match[2])
  9739. }
  9740. } catch (e) {}
  9741. nextIndex = re_tag.lastIndex
  9742. }
  9743. //如果结束是文本,就有可能丢掉,所以这里手动判断一下
  9744. //例如 <li>sdfsdfsdf<li>sdfsdfsdfsdf
  9745. if (nextIndex < htmlstr.length) {
  9746. text(currentParent, htmlstr.slice(nextIndex))
  9747. }
  9748. return root
  9749. })
  9750. // core/filternode.js
  9751. /**
  9752. * UE过滤节点的静态方法
  9753. * @file
  9754. */
  9755. /**
  9756. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  9757. * @module UE
  9758. */
  9759. /**
  9760. * 根据传入节点和过滤规则过滤相应节点
  9761. * @module UE
  9762. * @since 1.2.6.1
  9763. * @method filterNode
  9764. * @param { Object } root 指定root节点
  9765. * @param { Object } rules 过滤规则json对象
  9766. * @example
  9767. * ```javascript
  9768. * UE.filterNode(root,editor.options.filterRules);
  9769. * ```
  9770. */
  9771. var filterNode = (UE.filterNode = (function () {
  9772. function filterNode(node, rules) {
  9773. switch (node.type) {
  9774. case 'text':
  9775. break
  9776. case 'element':
  9777. var val
  9778. if ((val = rules[node.tagName])) {
  9779. if (val === '-') {
  9780. node.parentNode.removeChild(node)
  9781. } else if (utils.isFunction(val)) {
  9782. var parentNode = node.parentNode,
  9783. index = node.getIndex()
  9784. val(node)
  9785. if (node.parentNode) {
  9786. if (node.children) {
  9787. for (var i = 0, ci; (ci = node.children[i]); ) {
  9788. filterNode(ci, rules)
  9789. if (ci.parentNode) {
  9790. i++
  9791. }
  9792. }
  9793. }
  9794. } else {
  9795. for (var i = index, ci; (ci = parentNode.children[i]); ) {
  9796. filterNode(ci, rules)
  9797. if (ci.parentNode) {
  9798. i++
  9799. }
  9800. }
  9801. }
  9802. } else {
  9803. var attrs = val['$']
  9804. if (attrs && node.attrs) {
  9805. var tmpAttrs = {},
  9806. tmpVal
  9807. for (var a in attrs) {
  9808. tmpVal = node.getAttr(a)
  9809. //todo 只先对style单独处理
  9810. if (a == 'style' && utils.isArray(attrs[a])) {
  9811. var tmpCssStyle = []
  9812. utils.each(attrs[a], function (v) {
  9813. var tmp
  9814. if ((tmp = node.getStyle(v))) {
  9815. tmpCssStyle.push(v + ':' + tmp)
  9816. }
  9817. })
  9818. tmpVal = tmpCssStyle.join(';')
  9819. }
  9820. if (tmpVal) {
  9821. tmpAttrs[a] = tmpVal
  9822. }
  9823. }
  9824. node.attrs = tmpAttrs
  9825. }
  9826. if (node.children) {
  9827. for (var i = 0, ci; (ci = node.children[i]); ) {
  9828. filterNode(ci, rules)
  9829. if (ci.parentNode) {
  9830. i++
  9831. }
  9832. }
  9833. }
  9834. }
  9835. } else {
  9836. //如果不在名单里扣出子节点并删除该节点,cdata除外
  9837. if (dtd.$cdata[node.tagName]) {
  9838. node.parentNode.removeChild(node)
  9839. } else {
  9840. var parentNode = node.parentNode,
  9841. index = node.getIndex()
  9842. node.parentNode.removeChild(node, true)
  9843. for (var i = index, ci; (ci = parentNode.children[i]); ) {
  9844. filterNode(ci, rules)
  9845. if (ci.parentNode) {
  9846. i++
  9847. }
  9848. }
  9849. }
  9850. }
  9851. break
  9852. case 'comment':
  9853. node.parentNode.removeChild(node)
  9854. }
  9855. }
  9856. return function (root, rules) {
  9857. if (utils.isEmptyObject(rules)) {
  9858. return root
  9859. }
  9860. var val
  9861. if ((val = rules['-'])) {
  9862. utils.each(val.split(' '), function (k) {
  9863. rules[k] = '-'
  9864. })
  9865. }
  9866. for (var i = 0, ci; (ci = root.children[i]); ) {
  9867. filterNode(ci, rules)
  9868. if (ci.parentNode) {
  9869. i++
  9870. }
  9871. }
  9872. return root
  9873. }
  9874. })())
  9875. // core/plugin.js
  9876. /**
  9877. * Created with JetBrains PhpStorm.
  9878. * User: campaign
  9879. * Date: 10/8/13
  9880. * Time: 6:15 PM
  9881. * To change this template use File | Settings | File Templates.
  9882. */
  9883. UE.plugin = (function () {
  9884. var _plugins = {}
  9885. return {
  9886. register: function (pluginName, fn, oldOptionName, afterDisabled) {
  9887. if (oldOptionName && utils.isFunction(oldOptionName)) {
  9888. afterDisabled = oldOptionName
  9889. oldOptionName = null
  9890. }
  9891. _plugins[pluginName] = {
  9892. optionName: oldOptionName || pluginName,
  9893. execFn: fn,
  9894. //当插件被禁用时执行
  9895. afterDisabled: afterDisabled
  9896. }
  9897. },
  9898. load: function (editor) {
  9899. utils.each(_plugins, function (plugin) {
  9900. var _export = plugin.execFn.call(editor)
  9901. if (editor.options[plugin.optionName] !== false) {
  9902. if (_export) {
  9903. //后边需要再做扩展
  9904. utils.each(_export, function (v, k) {
  9905. switch (k.toLowerCase()) {
  9906. case 'shortcutkey':
  9907. editor.addshortcutkey(v)
  9908. break
  9909. case 'bindevents':
  9910. utils.each(v, function (fn, eventName) {
  9911. editor.addListener(eventName, fn)
  9912. })
  9913. break
  9914. case 'bindmultievents':
  9915. utils.each(utils.isArray(v) ? v : [v], function (event) {
  9916. var types = utils.trim(event.type).split(/\s+/)
  9917. utils.each(types, function (eventName) {
  9918. editor.addListener(eventName, event.handler)
  9919. })
  9920. })
  9921. break
  9922. case 'commands':
  9923. utils.each(v, function (execFn, execName) {
  9924. editor.commands[execName] = execFn
  9925. })
  9926. break
  9927. case 'outputrule':
  9928. editor.addOutputRule(v)
  9929. break
  9930. case 'inputrule':
  9931. editor.addInputRule(v)
  9932. break
  9933. case 'defaultoptions':
  9934. editor.setOpt(v)
  9935. }
  9936. })
  9937. }
  9938. } else if (plugin.afterDisabled) {
  9939. plugin.afterDisabled.call(editor)
  9940. }
  9941. })
  9942. //向下兼容
  9943. utils.each(UE.plugins, function (plugin) {
  9944. plugin.call(editor)
  9945. })
  9946. },
  9947. run: function (pluginName, editor) {
  9948. var plugin = _plugins[pluginName]
  9949. if (plugin) {
  9950. plugin.exeFn.call(editor)
  9951. }
  9952. }
  9953. }
  9954. })()
  9955. // core/keymap.js
  9956. var keymap = (UE.keymap = {
  9957. Backspace: 8,
  9958. Tab: 9,
  9959. Enter: 13,
  9960. Shift: 16,
  9961. Control: 17,
  9962. Alt: 18,
  9963. CapsLock: 20,
  9964. Esc: 27,
  9965. Spacebar: 32,
  9966. PageUp: 33,
  9967. PageDown: 34,
  9968. End: 35,
  9969. Home: 36,
  9970. Left: 37,
  9971. Up: 38,
  9972. Right: 39,
  9973. Down: 40,
  9974. Insert: 45,
  9975. Del: 46,
  9976. NumLock: 144,
  9977. Cmd: 91,
  9978. '=': 187,
  9979. '-': 189,
  9980. b: 66,
  9981. i: 73,
  9982. //回退
  9983. z: 90,
  9984. y: 89,
  9985. //粘贴
  9986. v: 86,
  9987. x: 88,
  9988. s: 83,
  9989. n: 78
  9990. })
  9991. // core/localstorage.js
  9992. //存储媒介封装
  9993. var LocalStorage = (UE.LocalStorage = (function () {
  9994. var storage = window.localStorage || getUserData() || null,
  9995. LOCAL_FILE = 'localStorage'
  9996. return {
  9997. saveLocalData: function (key, data) {
  9998. if (storage && data) {
  9999. storage.setItem(key, data)
  10000. return true
  10001. }
  10002. return false
  10003. },
  10004. getLocalData: function (key) {
  10005. if (storage) {
  10006. return storage.getItem(key)
  10007. }
  10008. return null
  10009. },
  10010. removeItem: function (key) {
  10011. storage && storage.removeItem(key)
  10012. }
  10013. }
  10014. function getUserData() {
  10015. var container = document.createElement('div')
  10016. container.style.display = 'none'
  10017. if (!container.addBehavior) {
  10018. return null
  10019. }
  10020. container.addBehavior('#default#userdata')
  10021. return {
  10022. getItem: function (key) {
  10023. var result = null
  10024. try {
  10025. document.body.appendChild(container)
  10026. container.load(LOCAL_FILE)
  10027. result = container.getAttribute(key)
  10028. document.body.removeChild(container)
  10029. } catch (e) {}
  10030. return result
  10031. },
  10032. setItem: function (key, value) {
  10033. document.body.appendChild(container)
  10034. container.setAttribute(key, value)
  10035. container.save(LOCAL_FILE)
  10036. document.body.removeChild(container)
  10037. },
  10038. //// 暂时没有用到
  10039. //clear: function () {
  10040. //
  10041. // var expiresTime = new Date();
  10042. // expiresTime.setFullYear(expiresTime.getFullYear() - 1);
  10043. // document.body.appendChild(container);
  10044. // container.expires = expiresTime.toUTCString();
  10045. // container.save(LOCAL_FILE);
  10046. // document.body.removeChild(container);
  10047. //
  10048. //},
  10049. removeItem: function (key) {
  10050. document.body.appendChild(container)
  10051. container.removeAttribute(key)
  10052. container.save(LOCAL_FILE)
  10053. document.body.removeChild(container)
  10054. }
  10055. }
  10056. }
  10057. })())
  10058. ;(function () {
  10059. var ROOTKEY = 'ueditor_preference'
  10060. UE.Editor.prototype.setPreferences = function (key, value) {
  10061. var obj = {}
  10062. if (utils.isString(key)) {
  10063. obj[key] = value
  10064. } else {
  10065. obj = key
  10066. }
  10067. var data = LocalStorage.getLocalData(ROOTKEY)
  10068. if (data && (data = utils.str2json(data))) {
  10069. utils.extend(data, obj)
  10070. } else {
  10071. data = obj
  10072. }
  10073. data && LocalStorage.saveLocalData(ROOTKEY, utils.json2str(data))
  10074. }
  10075. UE.Editor.prototype.getPreferences = function (key) {
  10076. var data = LocalStorage.getLocalData(ROOTKEY)
  10077. if (data && (data = utils.str2json(data))) {
  10078. return key ? data[key] : data
  10079. }
  10080. return null
  10081. }
  10082. UE.Editor.prototype.removePreferences = function (key) {
  10083. var data = LocalStorage.getLocalData(ROOTKEY)
  10084. if (data && (data = utils.str2json(data))) {
  10085. data[key] = undefined
  10086. delete data[key]
  10087. }
  10088. data && LocalStorage.saveLocalData(ROOTKEY, utils.json2str(data))
  10089. }
  10090. })()
  10091. // plugins/defaultfilter.js
  10092. ///import core
  10093. ///plugin 编辑器默认的过滤转换机制
  10094. UE.plugins['defaultfilter'] = function () {
  10095. var me = this
  10096. me.setOpt({
  10097. allowDivTransToP: true,
  10098. disabledTableInTable: true
  10099. })
  10100. //默认的过滤处理
  10101. //进入编辑器的内容处理
  10102. me.addInputRule(function (root) {
  10103. var allowDivTransToP = this.options.allowDivTransToP
  10104. var val
  10105. function tdParent(node) {
  10106. while (node && node.type == 'element') {
  10107. if (node.tagName == 'td') {
  10108. return true
  10109. }
  10110. node = node.parentNode
  10111. }
  10112. return false
  10113. }
  10114. //进行默认的处理
  10115. root.traversal(function (node) {
  10116. if (node.type == 'element') {
  10117. if (
  10118. !dtd.$cdata[node.tagName] &&
  10119. me.options.autoClearEmptyNode &&
  10120. dtd.$inline[node.tagName] &&
  10121. !dtd.$empty[node.tagName] &&
  10122. (!node.attrs || utils.isEmptyObject(node.attrs))
  10123. ) {
  10124. if (!node.firstChild()) node.parentNode.removeChild(node)
  10125. else if (node.tagName == 'span' && (!node.attrs || utils.isEmptyObject(node.attrs))) {
  10126. node.parentNode.removeChild(node, true)
  10127. }
  10128. return
  10129. }
  10130. switch (node.tagName) {
  10131. case 'style':
  10132. case 'script':
  10133. node.setAttr({
  10134. cdata_tag: node.tagName,
  10135. cdata_data: node.innerHTML() || '',
  10136. _ue_custom_node_: 'true'
  10137. })
  10138. node.tagName = 'div'
  10139. node.innerHTML('')
  10140. break
  10141. case 'a':
  10142. if ((val = node.getAttr('href'))) {
  10143. node.setAttr('_href', val)
  10144. }
  10145. break
  10146. case 'img':
  10147. //todo base64暂时去掉,后边做远程图片上传后,干掉这个
  10148. if ((val = node.getAttr('src'))) {
  10149. if (/^data:/.test(val)) {
  10150. node.parentNode.removeChild(node)
  10151. break
  10152. }
  10153. }
  10154. node.setAttr('_src', node.getAttr('src'))
  10155. break
  10156. case 'span':
  10157. if (browser.webkit && (val = node.getStyle('white-space'))) {
  10158. if (/nowrap|normal/.test(val)) {
  10159. node.setStyle('white-space', '')
  10160. if (me.options.autoClearEmptyNode && utils.isEmptyObject(node.attrs)) {
  10161. node.parentNode.removeChild(node, true)
  10162. }
  10163. }
  10164. }
  10165. val = node.getAttr('id')
  10166. if (val && /^_baidu_bookmark_/i.test(val)) {
  10167. node.parentNode.removeChild(node)
  10168. }
  10169. break
  10170. case 'p':
  10171. if ((val = node.getAttr('align'))) {
  10172. node.setAttr('align')
  10173. node.setStyle('text-align', val)
  10174. }
  10175. //trace:3431
  10176. // var cssStyle = node.getAttr('style');
  10177. // if (cssStyle) {
  10178. // cssStyle = cssStyle.replace(/(margin|padding)[^;]+/g, '');
  10179. // node.setAttr('style', cssStyle)
  10180. //
  10181. // }
  10182. //p标签不允许嵌套
  10183. utils.each(node.children, function (n) {
  10184. if (n.type == 'element' && n.tagName == 'p') {
  10185. var next = n.nextSibling()
  10186. node.parentNode.insertAfter(n, node)
  10187. var last = n
  10188. while (next) {
  10189. var tmp = next.nextSibling()
  10190. node.parentNode.insertAfter(next, last)
  10191. last = next
  10192. next = tmp
  10193. }
  10194. return false
  10195. }
  10196. })
  10197. if (!node.firstChild()) {
  10198. node.innerHTML(browser.ie ? '&nbsp;' : '<br/>')
  10199. }
  10200. break
  10201. case 'div':
  10202. if (node.getAttr('cdata_tag')) {
  10203. break
  10204. }
  10205. //针对代码这里不处理插入代码的div
  10206. val = node.getAttr('class')
  10207. if (val && /^line number\d+/.test(val)) {
  10208. break
  10209. }
  10210. if (!allowDivTransToP) {
  10211. break
  10212. }
  10213. var tmpNode,
  10214. p = UE.uNode.createElement('p')
  10215. while ((tmpNode = node.firstChild())) {
  10216. if (tmpNode.type == 'text' || !UE.dom.dtd.$block[tmpNode.tagName]) {
  10217. p.appendChild(tmpNode)
  10218. } else {
  10219. if (p.firstChild()) {
  10220. node.parentNode.insertBefore(p, node)
  10221. p = UE.uNode.createElement('p')
  10222. } else {
  10223. node.parentNode.insertBefore(tmpNode, node)
  10224. }
  10225. }
  10226. }
  10227. if (p.firstChild()) {
  10228. node.parentNode.insertBefore(p, node)
  10229. }
  10230. node.parentNode.removeChild(node)
  10231. break
  10232. case 'dl':
  10233. node.tagName = 'ul'
  10234. break
  10235. case 'dt':
  10236. case 'dd':
  10237. node.tagName = 'li'
  10238. break
  10239. case 'li':
  10240. var className = node.getAttr('class')
  10241. if (!className || !/list\-/.test(className)) {
  10242. node.setAttr()
  10243. }
  10244. var tmpNodes = node.getNodesByTagName('ol ul')
  10245. UE.utils.each(tmpNodes, function (n) {
  10246. node.parentNode.insertAfter(n, node)
  10247. })
  10248. break
  10249. case 'td':
  10250. case 'th':
  10251. case 'caption':
  10252. if (!node.children || !node.children.length) {
  10253. node.appendChild(
  10254. browser.ie11below ? UE.uNode.createText(' ') : UE.uNode.createElement('br')
  10255. )
  10256. }
  10257. break
  10258. case 'table':
  10259. if (me.options.disabledTableInTable && tdParent(node)) {
  10260. node.parentNode.insertBefore(UE.uNode.createText(node.innerText()), node)
  10261. node.parentNode.removeChild(node)
  10262. }
  10263. }
  10264. }
  10265. // if(node.type == 'comment'){
  10266. // node.parentNode.removeChild(node);
  10267. // }
  10268. })
  10269. })
  10270. //从编辑器出去的内容处理
  10271. me.addOutputRule(function (root) {
  10272. var val
  10273. root.traversal(function (node) {
  10274. if (node.type == 'element') {
  10275. if (
  10276. me.options.autoClearEmptyNode &&
  10277. dtd.$inline[node.tagName] &&
  10278. !dtd.$empty[node.tagName] &&
  10279. (!node.attrs || utils.isEmptyObject(node.attrs))
  10280. ) {
  10281. if (!node.firstChild()) node.parentNode.removeChild(node)
  10282. else if (node.tagName == 'span' && (!node.attrs || utils.isEmptyObject(node.attrs))) {
  10283. node.parentNode.removeChild(node, true)
  10284. }
  10285. return
  10286. }
  10287. switch (node.tagName) {
  10288. case 'div':
  10289. if ((val = node.getAttr('cdata_tag'))) {
  10290. node.tagName = val
  10291. node.appendChild(UE.uNode.createText(node.getAttr('cdata_data')))
  10292. node.setAttr({
  10293. cdata_tag: '',
  10294. cdata_data: '',
  10295. _ue_custom_node_: ''
  10296. })
  10297. }
  10298. break
  10299. case 'a':
  10300. if ((val = node.getAttr('_href'))) {
  10301. node.setAttr({
  10302. href: utils.html(val),
  10303. _href: ''
  10304. })
  10305. }
  10306. break
  10307. break
  10308. case 'span':
  10309. val = node.getAttr('id')
  10310. if (val && /^_baidu_bookmark_/i.test(val)) {
  10311. node.parentNode.removeChild(node)
  10312. }
  10313. break
  10314. case 'img':
  10315. if ((val = node.getAttr('_src'))) {
  10316. node.setAttr({
  10317. src: node.getAttr('_src'),
  10318. _src: ''
  10319. })
  10320. }
  10321. }
  10322. }
  10323. })
  10324. })
  10325. }
  10326. // plugins/inserthtml.js
  10327. /**
  10328. * 插入html字符串插件
  10329. * @file
  10330. * @since 1.2.6.1
  10331. */
  10332. /**
  10333. * 插入html代码
  10334. * @command inserthtml
  10335. * @method execCommand
  10336. * @param { String } cmd 命令字符串
  10337. * @param { String } html 插入的html字符串
  10338. * @remaind 插入的标签内容是在当前的选区位置上插入,如果当前是闭合状态,那直接插入内容, 如果当前是选中状态,将先清除当前选中内容后,再做插入
  10339. * @warning 注意:该命令会对当前选区的位置,对插入的内容进行过滤转换处理。 过滤的规则遵循html语意化的原则。
  10340. * @example
  10341. * ```javascript
  10342. * //xxx[BB]xxx 当前选区为非闭合选区,选中BB这两个文本
  10343. * //执行命令,插入<b>CC</b>
  10344. * //插入后的效果 xxx<b>CC</b>xxx
  10345. * //<p>xx|xxx</p> 当前选区为闭合状态
  10346. * //插入<p>CC</p>
  10347. * //结果 <p>xx</p><p>CC</p><p>xxx</p>
  10348. * //<p>xxxx</p>|</p>xxx</p> 当前选区在两个p标签之间
  10349. * //插入 xxxx
  10350. * //结果 <p>xxxx</p><p>xxxx</p></p>xxx</p>
  10351. * ```
  10352. */
  10353. UE.commands['inserthtml'] = {
  10354. execCommand: function (command, html, notNeedFilter) {
  10355. var me = this,
  10356. range,
  10357. div
  10358. if (!html) {
  10359. return
  10360. }
  10361. if (me.fireEvent('beforeinserthtml', html) === true) {
  10362. return
  10363. }
  10364. range = me.selection.getRange()
  10365. div = range.document.createElement('div')
  10366. div.style.display = 'inline'
  10367. if (!notNeedFilter) {
  10368. var root = UE.htmlparser(html)
  10369. //如果给了过滤规则就先进行过滤
  10370. if (me.options.filterRules) {
  10371. UE.filterNode(root, me.options.filterRules)
  10372. }
  10373. //执行默认的处理
  10374. me.filterInputRule(root)
  10375. html = root.toHtml()
  10376. }
  10377. div.innerHTML = utils.trim(html)
  10378. if (!range.collapsed) {
  10379. var tmpNode = range.startContainer
  10380. if (domUtils.isFillChar(tmpNode)) {
  10381. range.setStartBefore(tmpNode)
  10382. }
  10383. tmpNode = range.endContainer
  10384. if (domUtils.isFillChar(tmpNode)) {
  10385. range.setEndAfter(tmpNode)
  10386. }
  10387. range.txtToElmBoundary()
  10388. //结束边界可能放到了br的前边,要把br包含进来
  10389. // x[xxx]<br/>
  10390. if (range.endContainer && range.endContainer.nodeType == 1) {
  10391. tmpNode = range.endContainer.childNodes[range.endOffset]
  10392. if (tmpNode && domUtils.isBr(tmpNode)) {
  10393. range.setEndAfter(tmpNode)
  10394. }
  10395. }
  10396. if (range.startOffset == 0) {
  10397. tmpNode = range.startContainer
  10398. if (domUtils.isBoundaryNode(tmpNode, 'firstChild')) {
  10399. tmpNode = range.endContainer
  10400. if (
  10401. range.endOffset ==
  10402. (tmpNode.nodeType == 3 ? tmpNode.nodeValue.length : tmpNode.childNodes.length) &&
  10403. domUtils.isBoundaryNode(tmpNode, 'lastChild')
  10404. ) {
  10405. me.body.innerHTML = '<p>' + (browser.ie ? '' : '<br/>') + '</p>'
  10406. range.setStart(me.body.firstChild, 0).collapse(true)
  10407. }
  10408. }
  10409. }
  10410. !range.collapsed && range.deleteContents()
  10411. if (range.startContainer.nodeType == 1) {
  10412. var child = range.startContainer.childNodes[range.startOffset],
  10413. pre
  10414. if (
  10415. child &&
  10416. domUtils.isBlockElm(child) &&
  10417. (pre = child.previousSibling) &&
  10418. domUtils.isBlockElm(pre)
  10419. ) {
  10420. range.setEnd(pre, pre.childNodes.length).collapse()
  10421. while (child.firstChild) {
  10422. pre.appendChild(child.firstChild)
  10423. }
  10424. domUtils.remove(child)
  10425. }
  10426. }
  10427. }
  10428. var child,
  10429. parent,
  10430. pre,
  10431. tmp,
  10432. hadBreak = 0,
  10433. nextNode
  10434. //如果当前位置选中了fillchar要干掉,要不会产生空行
  10435. if (range.inFillChar()) {
  10436. child = range.startContainer
  10437. if (domUtils.isFillChar(child)) {
  10438. range.setStartBefore(child).collapse(true)
  10439. domUtils.remove(child)
  10440. } else if (domUtils.isFillChar(child, true)) {
  10441. child.nodeValue = child.nodeValue.replace(fillCharReg, '')
  10442. range.startOffset--
  10443. range.collapsed && range.collapse(true)
  10444. }
  10445. }
  10446. //列表单独处理
  10447. var li = domUtils.findParentByTagName(range.startContainer, 'li', true)
  10448. if (li) {
  10449. var next, last
  10450. while ((child = div.firstChild)) {
  10451. //针对hr单独处理一下先
  10452. while (
  10453. child &&
  10454. (child.nodeType == 3 || !domUtils.isBlockElm(child) || child.tagName == 'HR')
  10455. ) {
  10456. next = child.nextSibling
  10457. range.insertNode(child).collapse()
  10458. last = child
  10459. child = next
  10460. }
  10461. if (child) {
  10462. if (/^(ol|ul)$/i.test(child.tagName)) {
  10463. while (child.firstChild) {
  10464. last = child.firstChild
  10465. domUtils.insertAfter(li, child.firstChild)
  10466. li = li.nextSibling
  10467. }
  10468. domUtils.remove(child)
  10469. } else {
  10470. var tmpLi
  10471. next = child.nextSibling
  10472. tmpLi = me.document.createElement('li')
  10473. domUtils.insertAfter(li, tmpLi)
  10474. tmpLi.appendChild(child)
  10475. last = child
  10476. child = next
  10477. li = tmpLi
  10478. }
  10479. }
  10480. }
  10481. li = domUtils.findParentByTagName(range.startContainer, 'li', true)
  10482. if (domUtils.isEmptyBlock(li)) {
  10483. domUtils.remove(li)
  10484. }
  10485. if (last) {
  10486. range.setStartAfter(last).collapse(true).select(true)
  10487. }
  10488. } else {
  10489. while ((child = div.firstChild)) {
  10490. if (hadBreak) {
  10491. var p = me.document.createElement('p')
  10492. while (child && (child.nodeType == 3 || !dtd.$block[child.tagName])) {
  10493. nextNode = child.nextSibling
  10494. p.appendChild(child)
  10495. child = nextNode
  10496. }
  10497. if (p.firstChild) {
  10498. child = p
  10499. }
  10500. }
  10501. range.insertNode(child)
  10502. nextNode = child.nextSibling
  10503. if (!hadBreak && child.nodeType == domUtils.NODE_ELEMENT && domUtils.isBlockElm(child)) {
  10504. parent = domUtils.findParent(child, function (node) {
  10505. return domUtils.isBlockElm(node)
  10506. })
  10507. if (
  10508. parent &&
  10509. parent.tagName.toLowerCase() != 'body' &&
  10510. !(dtd[parent.tagName][child.nodeName] && child.parentNode === parent)
  10511. ) {
  10512. if (!dtd[parent.tagName][child.nodeName]) {
  10513. pre = parent
  10514. } else {
  10515. tmp = child.parentNode
  10516. while (tmp !== parent) {
  10517. pre = tmp
  10518. tmp = tmp.parentNode
  10519. }
  10520. }
  10521. domUtils.breakParent(child, pre || tmp)
  10522. //去掉break后前一个多余的节点 <p>|<[p> ==> <p></p><div></div><p>|</p>
  10523. var pre = child.previousSibling
  10524. domUtils.trimWhiteTextNode(pre)
  10525. if (!pre.childNodes.length) {
  10526. domUtils.remove(pre)
  10527. }
  10528. //trace:2012,在非ie的情况,切开后剩下的节点有可能不能点入光标添加br占位
  10529. if (
  10530. !browser.ie &&
  10531. (next = child.nextSibling) &&
  10532. domUtils.isBlockElm(next) &&
  10533. next.lastChild &&
  10534. !domUtils.isBr(next.lastChild)
  10535. ) {
  10536. next.appendChild(me.document.createElement('br'))
  10537. }
  10538. hadBreak = 1
  10539. }
  10540. }
  10541. var next = child.nextSibling
  10542. if (!div.firstChild && next && domUtils.isBlockElm(next)) {
  10543. range.setStart(next, 0).collapse(true)
  10544. break
  10545. }
  10546. range.setEndAfter(child).collapse()
  10547. }
  10548. child = range.startContainer
  10549. if (nextNode && domUtils.isBr(nextNode)) {
  10550. domUtils.remove(nextNode)
  10551. }
  10552. //用chrome可能有空白展位符
  10553. if (domUtils.isBlockElm(child) && domUtils.isEmptyNode(child)) {
  10554. if ((nextNode = child.nextSibling)) {
  10555. domUtils.remove(child)
  10556. if (nextNode.nodeType == 1 && dtd.$block[nextNode.tagName]) {
  10557. range.setStart(nextNode, 0).collapse(true).shrinkBoundary()
  10558. }
  10559. } else {
  10560. try {
  10561. child.innerHTML = browser.ie ? domUtils.fillChar : '<br/>'
  10562. } catch (e) {
  10563. range.setStartBefore(child)
  10564. domUtils.remove(child)
  10565. }
  10566. }
  10567. }
  10568. //加上true因为在删除表情等时会删两次,第一次是删的fillData
  10569. try {
  10570. range.select(true)
  10571. } catch (e) {}
  10572. }
  10573. setTimeout(function () {
  10574. range = me.selection.getRange()
  10575. range.scrollToView(
  10576. me.autoHeightEnabled,
  10577. me.autoHeightEnabled ? domUtils.getXY(me.iframe).y : 0
  10578. )
  10579. me.fireEvent('afterinserthtml', html)
  10580. }, 200)
  10581. }
  10582. }
  10583. // plugins/autotypeset.js
  10584. /**
  10585. * 自动排版
  10586. * @file
  10587. * @since 1.2.6.1
  10588. */
  10589. /**
  10590. * 对当前编辑器的内容执行自动排版, 排版的行为根据config配置文件里的“autotypeset”选项进行控制。
  10591. * @command autotypeset
  10592. * @method execCommand
  10593. * @param { String } cmd 命令字符串
  10594. * @example
  10595. * ```javascript
  10596. * editor.execCommand( 'autotypeset' );
  10597. * ```
  10598. */
  10599. UE.plugins['autotypeset'] = function () {
  10600. this.setOpt({
  10601. autotypeset: {
  10602. mergeEmptyline: true, //合并空行
  10603. removeClass: true, //去掉冗余的class
  10604. removeEmptyline: false, //去掉空行
  10605. textAlign: 'left', //段落的排版方式,可以是 left,right,center,justify 去掉这个属性表示不执行排版
  10606. imageBlockLine: 'center', //图片的浮动方式,独占一行剧中,左右浮动,默认: center,left,right,none 去掉这个属性表示不执行排版
  10607. pasteFilter: false, //根据规则过滤没事粘贴进来的内容
  10608. clearFontSize: false, //去掉所有的内嵌字号,使用编辑器默认的字号
  10609. clearFontFamily: false, //去掉所有的内嵌字体,使用编辑器默认的字体
  10610. removeEmptyNode: false, // 去掉空节点
  10611. //可以去掉的标签
  10612. removeTagNames: utils.extend({ div: 1 }, dtd.$removeEmpty),
  10613. indent: false, // 行首缩进
  10614. indentValue: '2em', //行首缩进的大小
  10615. bdc2sb: false,
  10616. tobdc: false
  10617. }
  10618. })
  10619. var me = this,
  10620. opt = me.options.autotypeset,
  10621. remainClass = {
  10622. selectTdClass: 1,
  10623. pagebreak: 1,
  10624. anchorclass: 1
  10625. },
  10626. remainTag = {
  10627. li: 1
  10628. },
  10629. tags = {
  10630. div: 1,
  10631. p: 1,
  10632. //trace:2183 这些也认为是行
  10633. blockquote: 1,
  10634. center: 1,
  10635. h1: 1,
  10636. h2: 1,
  10637. h3: 1,
  10638. h4: 1,
  10639. h5: 1,
  10640. h6: 1,
  10641. span: 1
  10642. },
  10643. highlightCont
  10644. //升级了版本,但配置项目里没有autotypeset
  10645. if (!opt) {
  10646. return
  10647. }
  10648. readLocalOpts()
  10649. function isLine(node, notEmpty) {
  10650. if (!node || node.nodeType == 3) return 0
  10651. if (domUtils.isBr(node)) return 1
  10652. if (node && node.parentNode && tags[node.tagName.toLowerCase()]) {
  10653. if ((highlightCont && highlightCont.contains(node)) || node.getAttribute('pagebreak')) {
  10654. return 0
  10655. }
  10656. return notEmpty
  10657. ? !domUtils.isEmptyBlock(node)
  10658. : domUtils.isEmptyBlock(node, new RegExp('[\\s' + domUtils.fillChar + ']', 'g'))
  10659. }
  10660. }
  10661. function removeNotAttributeSpan(node) {
  10662. if (!node.style.cssText) {
  10663. domUtils.removeAttributes(node, ['style'])
  10664. if (node.tagName.toLowerCase() == 'span' && domUtils.hasNoAttributes(node)) {
  10665. domUtils.remove(node, true)
  10666. }
  10667. }
  10668. }
  10669. function autotype(type, html) {
  10670. var me = this,
  10671. cont
  10672. if (html) {
  10673. if (!opt.pasteFilter) {
  10674. return
  10675. }
  10676. cont = me.document.createElement('div')
  10677. cont.innerHTML = html.html
  10678. } else {
  10679. cont = me.document.body
  10680. }
  10681. var nodes = domUtils.getElementsByTagName(cont, '*')
  10682. // 行首缩进,段落方向,段间距,段内间距
  10683. for (var i = 0, ci; (ci = nodes[i++]); ) {
  10684. if (me.fireEvent('excludeNodeinautotype', ci) === true) {
  10685. continue
  10686. }
  10687. //font-size
  10688. if (opt.clearFontSize && ci.style.fontSize) {
  10689. domUtils.removeStyle(ci, 'font-size')
  10690. removeNotAttributeSpan(ci)
  10691. }
  10692. //font-family
  10693. if (opt.clearFontFamily && ci.style.fontFamily) {
  10694. domUtils.removeStyle(ci, 'font-family')
  10695. removeNotAttributeSpan(ci)
  10696. }
  10697. if (isLine(ci)) {
  10698. //合并空行
  10699. if (opt.mergeEmptyline) {
  10700. var next = ci.nextSibling,
  10701. tmpNode,
  10702. isBr = domUtils.isBr(ci)
  10703. while (isLine(next)) {
  10704. tmpNode = next
  10705. next = tmpNode.nextSibling
  10706. if (isBr && (!next || (next && !domUtils.isBr(next)))) {
  10707. break
  10708. }
  10709. domUtils.remove(tmpNode)
  10710. }
  10711. }
  10712. //去掉空行,保留占位的空行
  10713. if (
  10714. opt.removeEmptyline &&
  10715. domUtils.inDoc(ci, cont) &&
  10716. !remainTag[ci.parentNode.tagName.toLowerCase()]
  10717. ) {
  10718. if (domUtils.isBr(ci)) {
  10719. next = ci.nextSibling
  10720. if (next && !domUtils.isBr(next)) {
  10721. continue
  10722. }
  10723. }
  10724. domUtils.remove(ci)
  10725. continue
  10726. }
  10727. }
  10728. if (isLine(ci, true) && ci.tagName != 'SPAN') {
  10729. if (opt.indent) {
  10730. ci.style.textIndent = opt.indentValue
  10731. }
  10732. if (opt.textAlign) {
  10733. ci.style.textAlign = opt.textAlign
  10734. }
  10735. // if(opt.lineHeight)
  10736. // ci.style.lineHeight = opt.lineHeight + 'cm';
  10737. }
  10738. //去掉class,保留的class不去掉
  10739. if (opt.removeClass && ci.className && !remainClass[ci.className.toLowerCase()]) {
  10740. if (highlightCont && highlightCont.contains(ci)) {
  10741. continue
  10742. }
  10743. domUtils.removeAttributes(ci, ['class'])
  10744. }
  10745. //表情不处理
  10746. if (
  10747. opt.imageBlockLine &&
  10748. ci.tagName.toLowerCase() == 'img' &&
  10749. !ci.getAttribute('emotion')
  10750. ) {
  10751. if (html) {
  10752. var img = ci
  10753. switch (opt.imageBlockLine) {
  10754. case 'left':
  10755. case 'right':
  10756. case 'none':
  10757. var pN = img.parentNode,
  10758. tmpNode,
  10759. pre,
  10760. next
  10761. while (dtd.$inline[pN.tagName] || pN.tagName == 'A') {
  10762. pN = pN.parentNode
  10763. }
  10764. tmpNode = pN
  10765. if (
  10766. tmpNode.tagName == 'P' &&
  10767. domUtils.getStyle(tmpNode, 'text-align') == 'center'
  10768. ) {
  10769. if (
  10770. !domUtils.isBody(tmpNode) &&
  10771. domUtils.getChildCount(tmpNode, function (node) {
  10772. return !domUtils.isBr(node) && !domUtils.isWhitespace(node)
  10773. }) == 1
  10774. ) {
  10775. pre = tmpNode.previousSibling
  10776. next = tmpNode.nextSibling
  10777. if (
  10778. pre &&
  10779. next &&
  10780. pre.nodeType == 1 &&
  10781. next.nodeType == 1 &&
  10782. pre.tagName == next.tagName &&
  10783. domUtils.isBlockElm(pre)
  10784. ) {
  10785. pre.appendChild(tmpNode.firstChild)
  10786. while (next.firstChild) {
  10787. pre.appendChild(next.firstChild)
  10788. }
  10789. domUtils.remove(tmpNode)
  10790. domUtils.remove(next)
  10791. } else {
  10792. domUtils.setStyle(tmpNode, 'text-align', '')
  10793. }
  10794. }
  10795. }
  10796. domUtils.setStyle(img, 'float', opt.imageBlockLine)
  10797. break
  10798. case 'center':
  10799. if (me.queryCommandValue('imagefloat') != 'center') {
  10800. pN = img.parentNode
  10801. domUtils.setStyle(img, 'float', 'none')
  10802. tmpNode = img
  10803. while (
  10804. pN &&
  10805. domUtils.getChildCount(pN, function (node) {
  10806. return !domUtils.isBr(node) && !domUtils.isWhitespace(node)
  10807. }) == 1 &&
  10808. (dtd.$inline[pN.tagName] || pN.tagName == 'A')
  10809. ) {
  10810. tmpNode = pN
  10811. pN = pN.parentNode
  10812. }
  10813. var pNode = me.document.createElement('p')
  10814. domUtils.setAttributes(pNode, {
  10815. style: 'text-align:center'
  10816. })
  10817. tmpNode.parentNode.insertBefore(pNode, tmpNode)
  10818. pNode.appendChild(tmpNode)
  10819. domUtils.setStyle(tmpNode, 'float', '')
  10820. }
  10821. }
  10822. } else {
  10823. var range = me.selection.getRange()
  10824. range.selectNode(ci).select()
  10825. me.execCommand('imagefloat', opt.imageBlockLine)
  10826. }
  10827. }
  10828. //去掉冗余的标签
  10829. if (opt.removeEmptyNode) {
  10830. if (
  10831. opt.removeTagNames[ci.tagName.toLowerCase()] &&
  10832. domUtils.hasNoAttributes(ci) &&
  10833. domUtils.isEmptyBlock(ci)
  10834. ) {
  10835. domUtils.remove(ci)
  10836. }
  10837. }
  10838. }
  10839. if (opt.tobdc) {
  10840. var root = UE.htmlparser(cont.innerHTML)
  10841. root.traversal(function (node) {
  10842. if (node.type == 'text') {
  10843. node.data = ToDBC(node.data)
  10844. }
  10845. })
  10846. cont.innerHTML = root.toHtml()
  10847. }
  10848. if (opt.bdc2sb) {
  10849. var root = UE.htmlparser(cont.innerHTML)
  10850. root.traversal(function (node) {
  10851. if (node.type == 'text') {
  10852. node.data = DBC2SB(node.data)
  10853. }
  10854. })
  10855. cont.innerHTML = root.toHtml()
  10856. }
  10857. if (html) {
  10858. html.html = cont.innerHTML
  10859. }
  10860. }
  10861. if (opt.pasteFilter) {
  10862. me.addListener('beforepaste', autotype)
  10863. }
  10864. function DBC2SB(str) {
  10865. var result = ''
  10866. for (var i = 0; i < str.length; i++) {
  10867. var code = str.charCodeAt(i) //获取当前字符的unicode编码
  10868. if (code >= 65281 && code <= 65373) {
  10869. //在这个unicode编码范围中的是所有的英文字母已经各种字符
  10870. result += String.fromCharCode(str.charCodeAt(i) - 65248) //把全角字符的unicode编码转换为对应半角字符的unicode码
  10871. } else if (code == 12288) {
  10872. //空格
  10873. result += String.fromCharCode(str.charCodeAt(i) - 12288 + 32)
  10874. } else {
  10875. result += str.charAt(i)
  10876. }
  10877. }
  10878. return result
  10879. }
  10880. function ToDBC(txtstring) {
  10881. txtstring = utils.html(txtstring)
  10882. var tmp = ''
  10883. var mark = '' /*用于判断,如果是html尖括里的标记,则不进行全角的转换*/
  10884. for (var i = 0; i < txtstring.length; i++) {
  10885. if (txtstring.charCodeAt(i) == 32) {
  10886. tmp = tmp + String.fromCharCode(12288)
  10887. } else if (txtstring.charCodeAt(i) < 127) {
  10888. tmp = tmp + String.fromCharCode(txtstring.charCodeAt(i) + 65248)
  10889. } else {
  10890. tmp += txtstring.charAt(i)
  10891. }
  10892. }
  10893. return tmp
  10894. }
  10895. function readLocalOpts() {
  10896. var cookieOpt = me.getPreferences('autotypeset')
  10897. utils.extend(me.options.autotypeset, cookieOpt)
  10898. }
  10899. me.commands['autotypeset'] = {
  10900. execCommand: function () {
  10901. me.removeListener('beforepaste', autotype)
  10902. if (opt.pasteFilter) {
  10903. me.addListener('beforepaste', autotype)
  10904. }
  10905. autotype.call(me)
  10906. }
  10907. }
  10908. }
  10909. // plugins/autosubmit.js
  10910. /**
  10911. * 快捷键提交
  10912. * @file
  10913. * @since 1.2.6.1
  10914. */
  10915. /**
  10916. * 提交表单
  10917. * @command autosubmit
  10918. * @method execCommand
  10919. * @param { String } cmd 命令字符串
  10920. * @example
  10921. * ```javascript
  10922. * editor.execCommand( 'autosubmit' );
  10923. * ```
  10924. */
  10925. UE.plugin.register('autosubmit', function () {
  10926. return {
  10927. shortcutkey: {
  10928. autosubmit: 'ctrl+13' //手动提交
  10929. },
  10930. commands: {
  10931. autosubmit: {
  10932. execCommand: function () {
  10933. var me = this,
  10934. form = domUtils.findParentByTagName(me.iframe, 'form', false)
  10935. if (form) {
  10936. if (me.fireEvent('beforesubmit') === false) {
  10937. return
  10938. }
  10939. me.sync()
  10940. form.submit()
  10941. }
  10942. }
  10943. }
  10944. }
  10945. }
  10946. })
  10947. // plugins/background.js
  10948. /**
  10949. * 背景插件,为UEditor提供设置背景功能
  10950. * @file
  10951. * @since 1.2.6.1
  10952. */
  10953. UE.plugin.register('background', function () {
  10954. var me = this,
  10955. cssRuleId = 'editor_background',
  10956. isSetColored,
  10957. reg = new RegExp('body[\\s]*\\{(.+)\\}', 'i')
  10958. function stringToObj(str) {
  10959. var obj = {},
  10960. styles = str.split(';')
  10961. utils.each(styles, function (v) {
  10962. var index = v.indexOf(':'),
  10963. key = utils.trim(v.substr(0, index)).toLowerCase()
  10964. key && (obj[key] = utils.trim(v.substr(index + 1) || ''))
  10965. })
  10966. return obj
  10967. }
  10968. function setBackground(obj) {
  10969. if (obj) {
  10970. var styles = []
  10971. for (var name in obj) {
  10972. if (obj.hasOwnProperty(name)) {
  10973. styles.push(name + ':' + obj[name] + '; ')
  10974. }
  10975. }
  10976. utils.cssRule(cssRuleId, styles.length ? 'body{' + styles.join('') + '}' : '', me.document)
  10977. } else {
  10978. utils.cssRule(cssRuleId, '', me.document)
  10979. }
  10980. }
  10981. //重写editor.hasContent方法
  10982. var orgFn = me.hasContents
  10983. me.hasContents = function () {
  10984. if (me.queryCommandValue('background')) {
  10985. return true
  10986. }
  10987. return orgFn.apply(me, arguments)
  10988. }
  10989. return {
  10990. bindEvents: {
  10991. getAllHtml: function (type, headHtml) {
  10992. var body = this.body,
  10993. su = domUtils.getComputedStyle(body, 'background-image'),
  10994. url = ''
  10995. if (su.indexOf(me.options.imagePath) > 0) {
  10996. url = su
  10997. .substring(su.indexOf(me.options.imagePath), su.length - 1)
  10998. .replace(/"|\(|\)/gi, '')
  10999. } else {
  11000. url = su != 'none' ? su.replace(/url\("?|"?\)/gi, '') : ''
  11001. }
  11002. var html = '<style type="text/css">body{'
  11003. var bgObj = {
  11004. 'background-color': domUtils.getComputedStyle(body, 'background-color') || '#ffffff',
  11005. 'background-image': url ? 'url(' + url + ')' : '',
  11006. 'background-repeat': domUtils.getComputedStyle(body, 'background-repeat') || '',
  11007. 'background-position': browser.ie
  11008. ? domUtils.getComputedStyle(body, 'background-position-x') +
  11009. ' ' +
  11010. domUtils.getComputedStyle(body, 'background-position-y')
  11011. : domUtils.getComputedStyle(body, 'background-position'),
  11012. height: domUtils.getComputedStyle(body, 'height')
  11013. }
  11014. for (var name in bgObj) {
  11015. if (bgObj.hasOwnProperty(name)) {
  11016. html += name + ':' + bgObj[name] + '; '
  11017. }
  11018. }
  11019. html += '}</style> '
  11020. headHtml.push(html)
  11021. },
  11022. aftersetcontent: function () {
  11023. if (isSetColored == false) setBackground()
  11024. }
  11025. },
  11026. inputRule: function (root) {
  11027. isSetColored = false
  11028. utils.each(root.getNodesByTagName('p'), function (p) {
  11029. var styles = p.getAttr('data-background')
  11030. if (styles) {
  11031. isSetColored = true
  11032. setBackground(stringToObj(styles))
  11033. p.parentNode.removeChild(p)
  11034. }
  11035. })
  11036. },
  11037. outputRule: function (root) {
  11038. var me = this,
  11039. styles = (utils.cssRule(cssRuleId, me.document) || '').replace(/[\n\r]+/g, '').match(reg)
  11040. if (styles) {
  11041. root.appendChild(
  11042. UE.uNode.createElement(
  11043. '<p style="display:none;" data-background="' +
  11044. utils.trim(styles[1].replace(/"/g, '').replace(/[\s]+/g, ' ')) +
  11045. '"><br/></p>'
  11046. )
  11047. )
  11048. }
  11049. },
  11050. commands: {
  11051. background: {
  11052. execCommand: function (cmd, obj) {
  11053. setBackground(obj)
  11054. },
  11055. queryCommandValue: function () {
  11056. var me = this,
  11057. styles = (utils.cssRule(cssRuleId, me.document) || '')
  11058. .replace(/[\n\r]+/g, '')
  11059. .match(reg)
  11060. return styles ? stringToObj(styles[1]) : null
  11061. },
  11062. notNeedUndo: true
  11063. }
  11064. }
  11065. }
  11066. })
  11067. // plugins/image.js
  11068. /**
  11069. * 图片插入、排版插件
  11070. * @file
  11071. * @since 1.2.6.1
  11072. */
  11073. /**
  11074. * 图片对齐方式
  11075. * @command imagefloat
  11076. * @method execCommand
  11077. * @remind 值center为独占一行居中
  11078. * @param { String } cmd 命令字符串
  11079. * @param { String } align 对齐方式,可传left、right、none、center
  11080. * @remaind center表示图片独占一行
  11081. * @example
  11082. * ```javascript
  11083. * editor.execCommand( 'imagefloat', 'center' );
  11084. * ```
  11085. */
  11086. /**
  11087. * 如果选区所在位置是图片区域
  11088. * @command imagefloat
  11089. * @method queryCommandValue
  11090. * @param { String } cmd 命令字符串
  11091. * @return { String } 返回图片对齐方式
  11092. * @example
  11093. * ```javascript
  11094. * editor.queryCommandValue( 'imagefloat' );
  11095. * ```
  11096. */
  11097. UE.commands['imagefloat'] = {
  11098. execCommand: function (cmd, align) {
  11099. var me = this,
  11100. range = me.selection.getRange()
  11101. if (!range.collapsed) {
  11102. var img = range.getClosedNode()
  11103. if (img && img.tagName == 'IMG') {
  11104. switch (align) {
  11105. case 'left':
  11106. case 'right':
  11107. case 'none':
  11108. var pN = img.parentNode,
  11109. tmpNode,
  11110. pre,
  11111. next
  11112. while (dtd.$inline[pN.tagName] || pN.tagName == 'A') {
  11113. pN = pN.parentNode
  11114. }
  11115. tmpNode = pN
  11116. if (tmpNode.tagName == 'P' && domUtils.getStyle(tmpNode, 'text-align') == 'center') {
  11117. if (
  11118. !domUtils.isBody(tmpNode) &&
  11119. domUtils.getChildCount(tmpNode, function (node) {
  11120. return !domUtils.isBr(node) && !domUtils.isWhitespace(node)
  11121. }) == 1
  11122. ) {
  11123. pre = tmpNode.previousSibling
  11124. next = tmpNode.nextSibling
  11125. if (
  11126. pre &&
  11127. next &&
  11128. pre.nodeType == 1 &&
  11129. next.nodeType == 1 &&
  11130. pre.tagName == next.tagName &&
  11131. domUtils.isBlockElm(pre)
  11132. ) {
  11133. pre.appendChild(tmpNode.firstChild)
  11134. while (next.firstChild) {
  11135. pre.appendChild(next.firstChild)
  11136. }
  11137. domUtils.remove(tmpNode)
  11138. domUtils.remove(next)
  11139. } else {
  11140. domUtils.setStyle(tmpNode, 'text-align', '')
  11141. }
  11142. }
  11143. range.selectNode(img).select()
  11144. }
  11145. domUtils.setStyle(img, 'float', align == 'none' ? '' : align)
  11146. if (align == 'none') {
  11147. domUtils.removeAttributes(img, 'align')
  11148. }
  11149. break
  11150. case 'center':
  11151. if (me.queryCommandValue('imagefloat') != 'center') {
  11152. pN = img.parentNode
  11153. domUtils.setStyle(img, 'float', '')
  11154. domUtils.removeAttributes(img, 'align')
  11155. tmpNode = img
  11156. while (
  11157. pN &&
  11158. domUtils.getChildCount(pN, function (node) {
  11159. return !domUtils.isBr(node) && !domUtils.isWhitespace(node)
  11160. }) == 1 &&
  11161. (dtd.$inline[pN.tagName] || pN.tagName == 'A')
  11162. ) {
  11163. tmpNode = pN
  11164. pN = pN.parentNode
  11165. }
  11166. range.setStartBefore(tmpNode).setCursor(false)
  11167. pN = me.document.createElement('div')
  11168. pN.appendChild(tmpNode)
  11169. domUtils.setStyle(tmpNode, 'float', '')
  11170. me.execCommand(
  11171. 'insertHtml',
  11172. '<p id="_img_parent_tmp" style="text-align:center">' + pN.innerHTML + '</p>'
  11173. )
  11174. tmpNode = me.document.getElementById('_img_parent_tmp')
  11175. tmpNode.removeAttribute('id')
  11176. tmpNode = tmpNode.firstChild
  11177. range.selectNode(tmpNode).select()
  11178. //去掉后边多余的元素
  11179. next = tmpNode.parentNode.nextSibling
  11180. if (next && domUtils.isEmptyNode(next)) {
  11181. domUtils.remove(next)
  11182. }
  11183. }
  11184. break
  11185. }
  11186. }
  11187. }
  11188. },
  11189. queryCommandValue: function () {
  11190. var range = this.selection.getRange(),
  11191. startNode,
  11192. floatStyle
  11193. if (range.collapsed) {
  11194. return 'none'
  11195. }
  11196. startNode = range.getClosedNode()
  11197. if (startNode && startNode.nodeType == 1 && startNode.tagName == 'IMG') {
  11198. floatStyle =
  11199. domUtils.getComputedStyle(startNode, 'float') || startNode.getAttribute('align')
  11200. if (floatStyle == 'none') {
  11201. floatStyle =
  11202. domUtils.getComputedStyle(startNode.parentNode, 'text-align') == 'center'
  11203. ? 'center'
  11204. : floatStyle
  11205. }
  11206. return {
  11207. left: 1,
  11208. right: 1,
  11209. center: 1
  11210. }[floatStyle]
  11211. ? floatStyle
  11212. : 'none'
  11213. }
  11214. return 'none'
  11215. },
  11216. queryCommandState: function () {
  11217. var range = this.selection.getRange(),
  11218. startNode
  11219. if (range.collapsed) return -1
  11220. startNode = range.getClosedNode()
  11221. if (startNode && startNode.nodeType == 1 && startNode.tagName == 'IMG') {
  11222. return 0
  11223. }
  11224. return -1
  11225. }
  11226. }
  11227. /**
  11228. * 插入图片
  11229. * @command insertimage
  11230. * @method execCommand
  11231. * @param { String } cmd 命令字符串
  11232. * @param { Object } opt 属性键值对,这些属性都将被复制到当前插入图片
  11233. * @remind 该命令第二个参数可接受一个图片配置项对象的数组,可以插入多张图片,
  11234. * 此时数组的每一个元素都是一个Object类型的图片属性集合。
  11235. * @example
  11236. * ```javascript
  11237. * editor.execCommand( 'insertimage', {
  11238. * src:'a/b/c.jpg',
  11239. * width:'100',
  11240. * height:'100'
  11241. * } );
  11242. * ```
  11243. * @example
  11244. * ```javascript
  11245. * editor.execCommand( 'insertimage', [{
  11246. * src:'a/b/c.jpg',
  11247. * width:'100',
  11248. * height:'100'
  11249. * },{
  11250. * src:'a/b/d.jpg',
  11251. * width:'100',
  11252. * height:'100'
  11253. * }] );
  11254. * ```
  11255. */
  11256. UE.commands['insertimage'] = {
  11257. execCommand: function (cmd, opt) {
  11258. opt = utils.isArray(opt) ? opt : [opt]
  11259. if (!opt.length) {
  11260. return
  11261. }
  11262. var me = this,
  11263. range = me.selection.getRange(),
  11264. img = range.getClosedNode()
  11265. if (me.fireEvent('beforeinsertimage', opt) === true) {
  11266. return
  11267. }
  11268. function unhtmlData(imgCi) {
  11269. utils.each('width,height,border,hspace,vspace'.split(','), function (item) {
  11270. if (imgCi[item]) {
  11271. imgCi[item] = parseInt(imgCi[item], 10) || 0
  11272. }
  11273. })
  11274. utils.each('src,_src'.split(','), function (item) {
  11275. if (imgCi[item]) {
  11276. imgCi[item] = utils.unhtmlForUrl(imgCi[item])
  11277. }
  11278. })
  11279. utils.each('title,alt'.split(','), function (item) {
  11280. if (imgCi[item]) {
  11281. imgCi[item] = utils.unhtml(imgCi[item])
  11282. }
  11283. })
  11284. }
  11285. if (
  11286. img &&
  11287. /img/i.test(img.tagName) &&
  11288. (img.className != 'edui-faked-video' || img.className.indexOf('edui-upload-video') != -1) &&
  11289. !img.getAttribute('word_img')
  11290. ) {
  11291. var first = opt.shift()
  11292. var floatStyle = first['floatStyle']
  11293. delete first['floatStyle']
  11294. //// img.style.border = (first.border||0) +"px solid #000";
  11295. //// img.style.margin = (first.margin||0) +"px";
  11296. // img.style.cssText += ';margin:' + (first.margin||0) +"px;" + 'border:' + (first.border||0) +"px solid #000";
  11297. domUtils.setAttributes(img, first)
  11298. me.execCommand('imagefloat', floatStyle)
  11299. if (opt.length > 0) {
  11300. range.setStartAfter(img).setCursor(false, true)
  11301. me.execCommand('insertimage', opt)
  11302. }
  11303. } else {
  11304. var html = [],
  11305. str = '',
  11306. ci
  11307. ci = opt[0]
  11308. if (opt.length == 1) {
  11309. unhtmlData(ci)
  11310. str =
  11311. '<img src="' +
  11312. ci.src +
  11313. '" ' +
  11314. (ci._src ? ' _src="' + ci._src + '" ' : '') +
  11315. (ci.width ? 'width="' + ci.width + '" ' : '') +
  11316. (ci.height ? ' height="' + ci.height + '" ' : '') +
  11317. (ci['floatStyle'] == 'left' || ci['floatStyle'] == 'right'
  11318. ? ' style="float:' + ci['floatStyle'] + ';"'
  11319. : '') +
  11320. (ci.title && ci.title != '' ? ' title="' + ci.title + '"' : '') +
  11321. (ci.border && ci.border != '0' ? ' border="' + ci.border + '"' : '') +
  11322. (ci.alt && ci.alt != '' ? ' alt="' + ci.alt + '"' : '') +
  11323. (ci.hspace && ci.hspace != '0' ? ' hspace = "' + ci.hspace + '"' : '') +
  11324. (ci.vspace && ci.vspace != '0' ? ' vspace = "' + ci.vspace + '"' : '') +
  11325. '/>'
  11326. if (ci['floatStyle'] == 'center') {
  11327. str = '<p style="text-align: center">' + str + '</p>'
  11328. }
  11329. html.push(str)
  11330. } else {
  11331. for (var i = 0; (ci = opt[i++]); ) {
  11332. unhtmlData(ci)
  11333. str =
  11334. '<p ' +
  11335. (ci['floatStyle'] == 'center' ? 'style="text-align: center" ' : '') +
  11336. '><img src="' +
  11337. ci.src +
  11338. '" ' +
  11339. (ci.width ? 'width="' + ci.width + '" ' : '') +
  11340. (ci._src ? ' _src="' + ci._src + '" ' : '') +
  11341. (ci.height ? ' height="' + ci.height + '" ' : '') +
  11342. ' style="' +
  11343. (ci['floatStyle'] && ci['floatStyle'] != 'center'
  11344. ? 'float:' + ci['floatStyle'] + ';'
  11345. : '') +
  11346. (ci.border || '') +
  11347. '" ' +
  11348. (ci.title ? ' title="' + ci.title + '"' : '') +
  11349. ' /></p>'
  11350. html.push(str)
  11351. }
  11352. }
  11353. me.execCommand('insertHtml', html.join(''))
  11354. }
  11355. me.fireEvent('afterinsertimage', opt)
  11356. }
  11357. }
  11358. // plugins/justify.js
  11359. /**
  11360. * 段落格式
  11361. * @file
  11362. * @since 1.2.6.1
  11363. */
  11364. /**
  11365. * 段落对齐方式
  11366. * @command justify
  11367. * @method execCommand
  11368. * @param { String } cmd 命令字符串
  11369. * @param { String } align 对齐方式:left => 居左,right => 居右,center => 居中,justify => 两端对齐
  11370. * @example
  11371. * ```javascript
  11372. * editor.execCommand( 'justify', 'center' );
  11373. * ```
  11374. */
  11375. /**
  11376. * 如果选区所在位置是段落区域,返回当前段落对齐方式
  11377. * @command justify
  11378. * @method queryCommandValue
  11379. * @param { String } cmd 命令字符串
  11380. * @return { String } 返回段落对齐方式
  11381. * @example
  11382. * ```javascript
  11383. * editor.queryCommandValue( 'justify' );
  11384. * ```
  11385. */
  11386. UE.plugins['justify'] = function () {
  11387. var me = this,
  11388. block = domUtils.isBlockElm,
  11389. defaultValue = {
  11390. left: 1,
  11391. right: 1,
  11392. center: 1,
  11393. justify: 1
  11394. },
  11395. doJustify = function (range, style) {
  11396. var bookmark = range.createBookmark(),
  11397. filterFn = function (node) {
  11398. return node.nodeType == 1
  11399. ? node.tagName.toLowerCase() != 'br' && !domUtils.isBookmarkNode(node)
  11400. : !domUtils.isWhitespace(node)
  11401. }
  11402. range.enlarge(true)
  11403. var bookmark2 = range.createBookmark(),
  11404. current = domUtils.getNextDomNode(bookmark2.start, false, filterFn),
  11405. tmpRange = range.cloneRange(),
  11406. tmpNode
  11407. while (
  11408. current &&
  11409. !(domUtils.getPosition(current, bookmark2.end) & domUtils.POSITION_FOLLOWING)
  11410. ) {
  11411. if (current.nodeType == 3 || !block(current)) {
  11412. tmpRange.setStartBefore(current)
  11413. while (current && current !== bookmark2.end && !block(current)) {
  11414. tmpNode = current
  11415. current = domUtils.getNextDomNode(current, false, null, function (node) {
  11416. return !block(node)
  11417. })
  11418. }
  11419. tmpRange.setEndAfter(tmpNode)
  11420. var common = tmpRange.getCommonAncestor()
  11421. if (!domUtils.isBody(common) && block(common)) {
  11422. domUtils.setStyles(common, utils.isString(style) ? { 'text-align': style } : style)
  11423. current = common
  11424. } else {
  11425. var p = range.document.createElement('p')
  11426. domUtils.setStyles(p, utils.isString(style) ? { 'text-align': style } : style)
  11427. var frag = tmpRange.extractContents()
  11428. p.appendChild(frag)
  11429. tmpRange.insertNode(p)
  11430. current = p
  11431. }
  11432. current = domUtils.getNextDomNode(current, false, filterFn)
  11433. } else {
  11434. current = domUtils.getNextDomNode(current, true, filterFn)
  11435. }
  11436. }
  11437. return range.moveToBookmark(bookmark2).moveToBookmark(bookmark)
  11438. }
  11439. UE.commands['justify'] = {
  11440. execCommand: function (cmdName, align) {
  11441. var range = this.selection.getRange(),
  11442. txt
  11443. //闭合时单独处理
  11444. if (range.collapsed) {
  11445. txt = this.document.createTextNode('p')
  11446. range.insertNode(txt)
  11447. }
  11448. doJustify(range, align)
  11449. if (txt) {
  11450. range.setStartBefore(txt).collapse(true)
  11451. domUtils.remove(txt)
  11452. }
  11453. range.select()
  11454. return true
  11455. },
  11456. queryCommandValue: function () {
  11457. var startNode = this.selection.getStart(),
  11458. value = domUtils.getComputedStyle(startNode, 'text-align')
  11459. return defaultValue[value] ? value : 'left'
  11460. },
  11461. queryCommandState: function () {
  11462. var start = this.selection.getStart(),
  11463. cell = start && domUtils.findParentByTagName(start, ['td', 'th', 'caption'], true)
  11464. return cell ? -1 : 0
  11465. }
  11466. }
  11467. }
  11468. // plugins/font.js
  11469. /**
  11470. * 字体颜色,背景色,字号,字体,下划线,删除线
  11471. * @file
  11472. * @since 1.2.6.1
  11473. */
  11474. /**
  11475. * 字体颜色
  11476. * @command forecolor
  11477. * @method execCommand
  11478. * @param { String } cmd 命令字符串
  11479. * @param { String } value 色值(必须十六进制)
  11480. * @example
  11481. * ```javascript
  11482. * editor.execCommand( 'forecolor', '#000' );
  11483. * ```
  11484. */
  11485. /**
  11486. * 返回选区字体颜色
  11487. * @command forecolor
  11488. * @method queryCommandValue
  11489. * @param { String } cmd 命令字符串
  11490. * @return { String } 返回字体颜色
  11491. * @example
  11492. * ```javascript
  11493. * editor.queryCommandValue( 'forecolor' );
  11494. * ```
  11495. */
  11496. /**
  11497. * 字体背景颜色
  11498. * @command backcolor
  11499. * @method execCommand
  11500. * @param { String } cmd 命令字符串
  11501. * @param { String } value 色值(必须十六进制)
  11502. * @example
  11503. * ```javascript
  11504. * editor.execCommand( 'backcolor', '#000' );
  11505. * ```
  11506. */
  11507. /**
  11508. * 返回选区字体颜色
  11509. * @command backcolor
  11510. * @method queryCommandValue
  11511. * @param { String } cmd 命令字符串
  11512. * @return { String } 返回字体背景颜色
  11513. * @example
  11514. * ```javascript
  11515. * editor.queryCommandValue( 'backcolor' );
  11516. * ```
  11517. */
  11518. /**
  11519. * 字体大小
  11520. * @command fontsize
  11521. * @method execCommand
  11522. * @param { String } cmd 命令字符串
  11523. * @param { String } value 字体大小
  11524. * @example
  11525. * ```javascript
  11526. * editor.execCommand( 'fontsize', '14px' );
  11527. * ```
  11528. */
  11529. /**
  11530. * 返回选区字体大小
  11531. * @command fontsize
  11532. * @method queryCommandValue
  11533. * @param { String } cmd 命令字符串
  11534. * @return { String } 返回字体大小
  11535. * @example
  11536. * ```javascript
  11537. * editor.queryCommandValue( 'fontsize' );
  11538. * ```
  11539. */
  11540. /**
  11541. * 字体样式
  11542. * @command fontfamily
  11543. * @method execCommand
  11544. * @param { String } cmd 命令字符串
  11545. * @param { String } value 字体样式
  11546. * @example
  11547. * ```javascript
  11548. * editor.execCommand( 'fontfamily', '微软雅黑' );
  11549. * ```
  11550. */
  11551. /**
  11552. * 返回选区字体样式
  11553. * @command fontfamily
  11554. * @method queryCommandValue
  11555. * @param { String } cmd 命令字符串
  11556. * @return { String } 返回字体样式
  11557. * @example
  11558. * ```javascript
  11559. * editor.queryCommandValue( 'fontfamily' );
  11560. * ```
  11561. */
  11562. /**
  11563. * 字体下划线,与删除线互斥
  11564. * @command underline
  11565. * @method execCommand
  11566. * @param { String } cmd 命令字符串
  11567. * @example
  11568. * ```javascript
  11569. * editor.execCommand( 'underline' );
  11570. * ```
  11571. */
  11572. /**
  11573. * 字体删除线,与下划线互斥
  11574. * @command strikethrough
  11575. * @method execCommand
  11576. * @param { String } cmd 命令字符串
  11577. * @example
  11578. * ```javascript
  11579. * editor.execCommand( 'strikethrough' );
  11580. * ```
  11581. */
  11582. /**
  11583. * 字体边框
  11584. * @command fontborder
  11585. * @method execCommand
  11586. * @param { String } cmd 命令字符串
  11587. * @example
  11588. * ```javascript
  11589. * editor.execCommand( 'fontborder' );
  11590. * ```
  11591. */
  11592. UE.plugins['font'] = function () {
  11593. var me = this,
  11594. fonts = {
  11595. forecolor: 'color',
  11596. backcolor: 'background-color',
  11597. fontsize: 'font-size',
  11598. fontfamily: 'font-family',
  11599. underline: 'text-decoration',
  11600. strikethrough: 'text-decoration',
  11601. fontborder: 'border'
  11602. },
  11603. needCmd = { underline: 1, strikethrough: 1, fontborder: 1 },
  11604. needSetChild = {
  11605. forecolor: 'color',
  11606. backcolor: 'background-color',
  11607. fontsize: 'font-size',
  11608. fontfamily: 'font-family'
  11609. }
  11610. me.setOpt({
  11611. fontfamily: [
  11612. { name: 'songti', val: '宋体,SimSun' },
  11613. { name: 'yahei', val: '微软雅黑,Microsoft YaHei' },
  11614. { name: 'kaiti', val: '楷体,楷体_GB2312, SimKai' },
  11615. { name: 'heiti', val: '黑体, SimHei' },
  11616. { name: 'lishu', val: '隶书, SimLi' },
  11617. { name: 'andaleMono', val: 'andale mono' },
  11618. { name: 'arial', val: 'arial, helvetica,sans-serif' },
  11619. { name: 'arialBlack', val: 'arial black,avant garde' },
  11620. { name: 'comicSansMs', val: 'comic sans ms' },
  11621. { name: 'impact', val: 'impact,chicago' },
  11622. { name: 'timesNewRoman', val: 'times new roman' }
  11623. ],
  11624. fontsize: [10, 11, 12, 14, 16, 18, 20, 24, 36]
  11625. })
  11626. function mergeWithParent(node) {
  11627. var parent
  11628. while ((parent = node.parentNode)) {
  11629. if (
  11630. parent.tagName == 'SPAN' &&
  11631. domUtils.getChildCount(parent, function (child) {
  11632. return !domUtils.isBookmarkNode(child) && !domUtils.isBr(child)
  11633. }) == 1
  11634. ) {
  11635. parent.style.cssText += node.style.cssText
  11636. domUtils.remove(node, true)
  11637. node = parent
  11638. } else {
  11639. break
  11640. }
  11641. }
  11642. }
  11643. function mergeChild(rng, cmdName, value) {
  11644. if (needSetChild[cmdName]) {
  11645. rng.adjustmentBoundary()
  11646. if (!rng.collapsed && rng.startContainer.nodeType == 1) {
  11647. var start = rng.startContainer.childNodes[rng.startOffset]
  11648. if (start && domUtils.isTagNode(start, 'span')) {
  11649. var bk = rng.createBookmark()
  11650. utils.each(domUtils.getElementsByTagName(start, 'span'), function (span) {
  11651. if (!span.parentNode || domUtils.isBookmarkNode(span)) return
  11652. if (
  11653. cmdName == 'backcolor' &&
  11654. domUtils.getComputedStyle(span, 'background-color').toLowerCase() === value
  11655. ) {
  11656. return
  11657. }
  11658. domUtils.removeStyle(span, needSetChild[cmdName])
  11659. if (span.style.cssText.replace(/^\s+$/, '').length == 0) {
  11660. domUtils.remove(span, true)
  11661. }
  11662. })
  11663. rng.moveToBookmark(bk)
  11664. }
  11665. }
  11666. }
  11667. }
  11668. function mergesibling(rng, cmdName, value) {
  11669. var collapsed = rng.collapsed,
  11670. bk = rng.createBookmark(),
  11671. common
  11672. if (collapsed) {
  11673. common = bk.start.parentNode
  11674. while (dtd.$inline[common.tagName]) {
  11675. common = common.parentNode
  11676. }
  11677. } else {
  11678. common = domUtils.getCommonAncestor(bk.start, bk.end)
  11679. }
  11680. utils.each(domUtils.getElementsByTagName(common, 'span'), function (span) {
  11681. if (!span.parentNode || domUtils.isBookmarkNode(span)) return
  11682. if (/\s*border\s*:\s*none;?\s*/i.test(span.style.cssText)) {
  11683. if (/^\s*border\s*:\s*none;?\s*$/.test(span.style.cssText)) {
  11684. domUtils.remove(span, true)
  11685. } else {
  11686. domUtils.removeStyle(span, 'border')
  11687. }
  11688. return
  11689. }
  11690. if (
  11691. /border/i.test(span.style.cssText) &&
  11692. span.parentNode.tagName == 'SPAN' &&
  11693. /border/i.test(span.parentNode.style.cssText)
  11694. ) {
  11695. span.style.cssText = span.style.cssText.replace(/border[^:]*:[^;]+;?/gi, '')
  11696. }
  11697. if (!(cmdName == 'fontborder' && value == 'none')) {
  11698. var next = span.nextSibling
  11699. while (next && next.nodeType == 1 && next.tagName == 'SPAN') {
  11700. if (domUtils.isBookmarkNode(next) && cmdName == 'fontborder') {
  11701. span.appendChild(next)
  11702. next = span.nextSibling
  11703. continue
  11704. }
  11705. if (next.style.cssText == span.style.cssText) {
  11706. domUtils.moveChild(next, span)
  11707. domUtils.remove(next)
  11708. }
  11709. if (span.nextSibling === next) break
  11710. next = span.nextSibling
  11711. }
  11712. }
  11713. mergeWithParent(span)
  11714. if (browser.ie && browser.version > 8) {
  11715. //拷贝父亲们的特别的属性,这里只做背景颜色的处理
  11716. var parent = domUtils.findParent(span, function (n) {
  11717. return n.tagName == 'SPAN' && /background-color/.test(n.style.cssText)
  11718. })
  11719. if (parent && !/background-color/.test(span.style.cssText)) {
  11720. span.style.backgroundColor = parent.style.backgroundColor
  11721. }
  11722. }
  11723. })
  11724. rng.moveToBookmark(bk)
  11725. mergeChild(rng, cmdName, value)
  11726. }
  11727. me.addInputRule(function (root) {
  11728. utils.each(root.getNodesByTagName('u s del font strike'), function (node) {
  11729. if (node.tagName == 'font') {
  11730. var cssStyle = []
  11731. for (var p in node.attrs) {
  11732. switch (p) {
  11733. case 'size':
  11734. cssStyle.push(
  11735. 'font-size:' +
  11736. ({
  11737. 1: '10',
  11738. 2: '12',
  11739. 3: '16',
  11740. 4: '18',
  11741. 5: '24',
  11742. 6: '32',
  11743. 7: '48'
  11744. }[node.attrs[p]] || node.attrs[p]) +
  11745. 'px'
  11746. )
  11747. break
  11748. case 'color':
  11749. cssStyle.push('color:' + node.attrs[p])
  11750. break
  11751. case 'face':
  11752. cssStyle.push('font-family:' + node.attrs[p])
  11753. break
  11754. case 'style':
  11755. cssStyle.push(node.attrs[p])
  11756. }
  11757. }
  11758. node.attrs = {
  11759. style: cssStyle.join(';')
  11760. }
  11761. } else {
  11762. var val = node.tagName == 'u' ? 'underline' : 'line-through'
  11763. node.attrs = {
  11764. style: (node.getAttr('style') || '') + 'text-decoration:' + val + ';'
  11765. }
  11766. }
  11767. node.tagName = 'span'
  11768. })
  11769. // utils.each(root.getNodesByTagName('span'), function (node) {
  11770. // var val;
  11771. // if(val = node.getAttr('class')){
  11772. // if(/fontstrikethrough/.test(val)){
  11773. // node.setStyle('text-decoration','line-through');
  11774. // if(node.attrs['class']){
  11775. // node.attrs['class'] = node.attrs['class'].replace(/fontstrikethrough/,'');
  11776. // }else{
  11777. // node.setAttr('class')
  11778. // }
  11779. // }
  11780. // if(/fontborder/.test(val)){
  11781. // node.setStyle('border','1px solid #000');
  11782. // if(node.attrs['class']){
  11783. // node.attrs['class'] = node.attrs['class'].replace(/fontborder/,'');
  11784. // }else{
  11785. // node.setAttr('class')
  11786. // }
  11787. // }
  11788. // }
  11789. // });
  11790. })
  11791. // me.addOutputRule(function(root){
  11792. // utils.each(root.getNodesByTagName('span'), function (node) {
  11793. // var val;
  11794. // if(val = node.getStyle('text-decoration')){
  11795. // if(/line-through/.test(val)){
  11796. // if(node.attrs['class']){
  11797. // node.attrs['class'] += ' fontstrikethrough';
  11798. // }else{
  11799. // node.setAttr('class','fontstrikethrough')
  11800. // }
  11801. // }
  11802. //
  11803. // node.setStyle('text-decoration')
  11804. // }
  11805. // if(val = node.getStyle('border')){
  11806. // if(/1px/.test(val) && /solid/.test(val)){
  11807. // if(node.attrs['class']){
  11808. // node.attrs['class'] += ' fontborder';
  11809. //
  11810. // }else{
  11811. // node.setAttr('class','fontborder')
  11812. // }
  11813. // }
  11814. // node.setStyle('border')
  11815. //
  11816. // }
  11817. // });
  11818. // });
  11819. for (var p in fonts) {
  11820. ;(function (cmd, style) {
  11821. UE.commands[cmd] = {
  11822. execCommand: function (cmdName, value) {
  11823. value =
  11824. value ||
  11825. (this.queryCommandState(cmdName)
  11826. ? 'none'
  11827. : cmdName == 'underline'
  11828. ? 'underline'
  11829. : cmdName == 'fontborder'
  11830. ? '1px solid #000'
  11831. : 'line-through')
  11832. var me = this,
  11833. range = this.selection.getRange(),
  11834. text
  11835. if (value == 'default') {
  11836. if (range.collapsed) {
  11837. text = me.document.createTextNode('font')
  11838. range.insertNode(text).select()
  11839. }
  11840. me.execCommand('removeFormat', 'span,a', style)
  11841. if (text) {
  11842. range.setStartBefore(text).collapse(true)
  11843. domUtils.remove(text)
  11844. }
  11845. mergesibling(range, cmdName, value)
  11846. range.select()
  11847. } else {
  11848. if (!range.collapsed) {
  11849. if (needCmd[cmd] && me.queryCommandValue(cmd)) {
  11850. me.execCommand('removeFormat', 'span,a', style)
  11851. }
  11852. range = me.selection.getRange()
  11853. range.applyInlineStyle('span', { style: style + ':' + value })
  11854. mergesibling(range, cmdName, value)
  11855. range.select()
  11856. } else {
  11857. var span = domUtils.findParentByTagName(range.startContainer, 'span', true)
  11858. text = me.document.createTextNode('font')
  11859. if (
  11860. span &&
  11861. !span.children.length &&
  11862. !span[browser.ie ? 'innerText' : 'textContent'].replace(fillCharReg, '').length
  11863. ) {
  11864. //for ie hack when enter
  11865. range.insertNode(text)
  11866. if (needCmd[cmd]) {
  11867. range.selectNode(text).select()
  11868. me.execCommand('removeFormat', 'span,a', style, null)
  11869. span = domUtils.findParentByTagName(text, 'span', true)
  11870. range.setStartBefore(text)
  11871. }
  11872. span && (span.style.cssText += ';' + style + ':' + value)
  11873. range.collapse(true).select()
  11874. } else {
  11875. range.insertNode(text)
  11876. range.selectNode(text).select()
  11877. span = range.document.createElement('span')
  11878. if (needCmd[cmd]) {
  11879. //a标签内的不处理跳过
  11880. if (domUtils.findParentByTagName(text, 'a', true)) {
  11881. range.setStartBefore(text).setCursor()
  11882. domUtils.remove(text)
  11883. return
  11884. }
  11885. me.execCommand('removeFormat', 'span,a', style)
  11886. }
  11887. span.style.cssText = style + ':' + value
  11888. text.parentNode.insertBefore(span, text)
  11889. //修复,span套span 但样式不继承的问题
  11890. if (!browser.ie || (browser.ie && browser.version == 9)) {
  11891. var spanParent = span.parentNode
  11892. while (!domUtils.isBlockElm(spanParent)) {
  11893. if (spanParent.tagName == 'SPAN') {
  11894. //opera合并style不会加入";"
  11895. span.style.cssText = spanParent.style.cssText + ';' + span.style.cssText
  11896. }
  11897. spanParent = spanParent.parentNode
  11898. }
  11899. }
  11900. if (opera) {
  11901. setTimeout(function () {
  11902. range.setStart(span, 0).collapse(true)
  11903. mergesibling(range, cmdName, value)
  11904. range.select()
  11905. })
  11906. } else {
  11907. range.setStart(span, 0).collapse(true)
  11908. mergesibling(range, cmdName, value)
  11909. range.select()
  11910. }
  11911. //trace:981
  11912. //domUtils.mergeToParent(span)
  11913. }
  11914. domUtils.remove(text)
  11915. }
  11916. }
  11917. return true
  11918. },
  11919. queryCommandValue: function (cmdName) {
  11920. var startNode = this.selection.getStart()
  11921. //trace:946
  11922. if (cmdName == 'underline' || cmdName == 'strikethrough') {
  11923. var tmpNode = startNode,
  11924. value
  11925. while (tmpNode && !domUtils.isBlockElm(tmpNode) && !domUtils.isBody(tmpNode)) {
  11926. if (tmpNode.nodeType == 1) {
  11927. value = domUtils.getComputedStyle(tmpNode, style)
  11928. if (value != 'none') {
  11929. return value
  11930. }
  11931. }
  11932. tmpNode = tmpNode.parentNode
  11933. }
  11934. return 'none'
  11935. }
  11936. if (cmdName == 'fontborder') {
  11937. var tmp = startNode,
  11938. val
  11939. while (tmp && dtd.$inline[tmp.tagName]) {
  11940. if ((val = domUtils.getComputedStyle(tmp, 'border'))) {
  11941. if (/1px/.test(val) && /solid/.test(val)) {
  11942. return val
  11943. }
  11944. }
  11945. tmp = tmp.parentNode
  11946. }
  11947. return ''
  11948. }
  11949. if (cmdName == 'FontSize') {
  11950. var styleVal = domUtils.getComputedStyle(startNode, style),
  11951. tmp = /^([\d\.]+)(\w+)$/.exec(styleVal)
  11952. if (tmp) {
  11953. return Math.floor(tmp[1]) + tmp[2]
  11954. }
  11955. return styleVal
  11956. }
  11957. return domUtils.getComputedStyle(startNode, style)
  11958. },
  11959. queryCommandState: function (cmdName) {
  11960. if (!needCmd[cmdName]) return 0
  11961. var val = this.queryCommandValue(cmdName)
  11962. if (cmdName == 'fontborder') {
  11963. return /1px/.test(val) && /solid/.test(val)
  11964. } else {
  11965. return cmdName == 'underline' ? /underline/.test(val) : /line\-through/.test(val)
  11966. }
  11967. }
  11968. }
  11969. })(p, fonts[p])
  11970. }
  11971. }
  11972. // plugins/link.js
  11973. /**
  11974. * 超链接
  11975. * @file
  11976. * @since 1.2.6.1
  11977. */
  11978. /**
  11979. * 插入超链接
  11980. * @command link
  11981. * @method execCommand
  11982. * @param { String } cmd 命令字符串
  11983. * @param { Object } options 设置自定义属性,例如:url、title、target
  11984. * @example
  11985. * ```javascript
  11986. * editor.execCommand( 'link', '{
  11987. * url:'ueditor.baidu.com',
  11988. * title:'ueditor',
  11989. * target:'_blank'
  11990. * }' );
  11991. * ```
  11992. */
  11993. /**
  11994. * 返回当前选中的第一个超链接节点
  11995. * @command link
  11996. * @method queryCommandValue
  11997. * @param { String } cmd 命令字符串
  11998. * @return { Element } 超链接节点
  11999. * @example
  12000. * ```javascript
  12001. * editor.queryCommandValue( 'link' );
  12002. * ```
  12003. */
  12004. /**
  12005. * 取消超链接
  12006. * @command unlink
  12007. * @method execCommand
  12008. * @param { String } cmd 命令字符串
  12009. * @example
  12010. * ```javascript
  12011. * editor.execCommand( 'unlink');
  12012. * ```
  12013. */
  12014. UE.plugins['link'] = function () {
  12015. function optimize(range) {
  12016. var start = range.startContainer,
  12017. end = range.endContainer
  12018. if ((start = domUtils.findParentByTagName(start, 'a', true))) {
  12019. range.setStartBefore(start)
  12020. }
  12021. if ((end = domUtils.findParentByTagName(end, 'a', true))) {
  12022. range.setEndAfter(end)
  12023. }
  12024. }
  12025. UE.commands['unlink'] = {
  12026. execCommand: function () {
  12027. var range = this.selection.getRange(),
  12028. bookmark
  12029. if (range.collapsed && !domUtils.findParentByTagName(range.startContainer, 'a', true)) {
  12030. return
  12031. }
  12032. bookmark = range.createBookmark()
  12033. optimize(range)
  12034. range.removeInlineStyle('a').moveToBookmark(bookmark).select()
  12035. },
  12036. queryCommandState: function () {
  12037. return !this.highlight && this.queryCommandValue('link') ? 0 : -1
  12038. }
  12039. }
  12040. function doLink(range, opt, me) {
  12041. var rngClone = range.cloneRange(),
  12042. link = me.queryCommandValue('link')
  12043. optimize((range = range.adjustmentBoundary()))
  12044. var start = range.startContainer
  12045. if (start.nodeType == 1 && link) {
  12046. start = start.childNodes[range.startOffset]
  12047. if (
  12048. start &&
  12049. start.nodeType == 1 &&
  12050. start.tagName == 'A' &&
  12051. /^(?:https?|ftp|file)\s*:\s*\/\//.test(start[browser.ie ? 'innerText' : 'textContent'])
  12052. ) {
  12053. start[browser.ie ? 'innerText' : 'textContent'] = utils.html(opt.textValue || opt.href)
  12054. }
  12055. }
  12056. if (!rngClone.collapsed || link) {
  12057. range.removeInlineStyle('a')
  12058. rngClone = range.cloneRange()
  12059. }
  12060. if (rngClone.collapsed) {
  12061. var a = range.document.createElement('a'),
  12062. text = ''
  12063. if (opt.textValue) {
  12064. text = utils.html(opt.textValue)
  12065. delete opt.textValue
  12066. } else {
  12067. text = utils.html(opt.href)
  12068. }
  12069. domUtils.setAttributes(a, opt)
  12070. start = domUtils.findParentByTagName(rngClone.startContainer, 'a', true)
  12071. if (start && domUtils.isInNodeEndBoundary(rngClone, start)) {
  12072. range.setStartAfter(start).collapse(true)
  12073. }
  12074. a[browser.ie ? 'innerText' : 'textContent'] = text
  12075. range.insertNode(a).selectNode(a)
  12076. } else {
  12077. range.applyInlineStyle('a', opt)
  12078. }
  12079. }
  12080. UE.commands['link'] = {
  12081. execCommand: function (cmdName, opt) {
  12082. var range
  12083. opt._href && (opt._href = utils.unhtml(opt._href, /[<">]/g))
  12084. opt.href && (opt.href = utils.unhtml(opt.href, /[<">]/g))
  12085. opt.textValue && (opt.textValue = utils.unhtml(opt.textValue, /[<">]/g))
  12086. doLink((range = this.selection.getRange()), opt, this)
  12087. //闭合都不加占位符,如果加了会在a后边多个占位符节点,导致a是图片背景组成的列表,出现空白问题
  12088. range.collapse().select(true)
  12089. },
  12090. queryCommandValue: function () {
  12091. var range = this.selection.getRange(),
  12092. node
  12093. if (range.collapsed) {
  12094. // node = this.selection.getStart();
  12095. //在ie下getstart()取值偏上了
  12096. node = range.startContainer
  12097. node = node.nodeType == 1 ? node : node.parentNode
  12098. if (
  12099. node &&
  12100. (node = domUtils.findParentByTagName(node, 'a', true)) &&
  12101. !domUtils.isInNodeEndBoundary(range, node)
  12102. ) {
  12103. return node
  12104. }
  12105. } else {
  12106. //trace:1111 如果是<p><a>xx</a></p> startContainer是p就会找不到a
  12107. range.shrinkBoundary()
  12108. var start =
  12109. range.startContainer.nodeType == 3 ||
  12110. !range.startContainer.childNodes[range.startOffset]
  12111. ? range.startContainer
  12112. : range.startContainer.childNodes[range.startOffset],
  12113. end =
  12114. range.endContainer.nodeType == 3 || range.endOffset == 0
  12115. ? range.endContainer
  12116. : range.endContainer.childNodes[range.endOffset - 1],
  12117. common = range.getCommonAncestor()
  12118. node = domUtils.findParentByTagName(common, 'a', true)
  12119. if (!node && common.nodeType == 1) {
  12120. var as = common.getElementsByTagName('a'),
  12121. ps,
  12122. pe
  12123. for (var i = 0, ci; (ci = as[i++]); ) {
  12124. ;(ps = domUtils.getPosition(ci, start)), (pe = domUtils.getPosition(ci, end))
  12125. if (
  12126. (ps & domUtils.POSITION_FOLLOWING || ps & domUtils.POSITION_CONTAINS) &&
  12127. (pe & domUtils.POSITION_PRECEDING || pe & domUtils.POSITION_CONTAINS)
  12128. ) {
  12129. node = ci
  12130. break
  12131. }
  12132. }
  12133. }
  12134. return node
  12135. }
  12136. },
  12137. queryCommandState: function () {
  12138. //判断如果是视频的话连接不可用
  12139. //fix 853
  12140. var img = this.selection.getRange().getClosedNode(),
  12141. flag =
  12142. img &&
  12143. (img.className == 'edui-faked-video' ||
  12144. img.className.indexOf('edui-upload-video') != -1)
  12145. return flag ? -1 : 0
  12146. }
  12147. }
  12148. }
  12149. // plugins/iframe.js
  12150. ///import core
  12151. ///import plugins\inserthtml.js
  12152. ///commands 插入框架
  12153. ///commandsName InsertFrame
  12154. ///commandsTitle 插入Iframe
  12155. ///commandsDialog dialogs\insertframe
  12156. UE.plugins['insertframe'] = function () {
  12157. var me = this
  12158. function deleteIframe() {
  12159. me._iframe && delete me._iframe
  12160. }
  12161. me.addListener('selectionchange', function () {
  12162. deleteIframe()
  12163. })
  12164. }
  12165. // plugins/scrawl.js
  12166. ///import core
  12167. ///commands 涂鸦
  12168. ///commandsName Scrawl
  12169. ///commandsTitle 涂鸦
  12170. ///commandsDialog dialogs\scrawl
  12171. UE.commands['scrawl'] = {
  12172. queryCommandState: function () {
  12173. return browser.ie && browser.version <= 8 ? -1 : 0
  12174. }
  12175. }
  12176. // plugins/removeformat.js
  12177. /**
  12178. * 清除格式
  12179. * @file
  12180. * @since 1.2.6.1
  12181. */
  12182. /**
  12183. * 清除文字样式
  12184. * @command removeformat
  12185. * @method execCommand
  12186. * @param { String } cmd 命令字符串
  12187. * @param {String} tags 以逗号隔开的标签。如:strong
  12188. * @param {String} style 样式如:color
  12189. * @param {String} attrs 属性如:width
  12190. * @example
  12191. * ```javascript
  12192. * editor.execCommand( 'removeformat', 'strong','color','width' );
  12193. * ```
  12194. */
  12195. UE.plugins['removeformat'] = function () {
  12196. var me = this
  12197. me.setOpt({
  12198. removeFormatTags:
  12199. 'b,big,code,del,dfn,em,font,i,ins,kbd,q,samp,small,span,strike,strong,sub,sup,tt,u,var',
  12200. removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign'
  12201. })
  12202. me.commands['removeformat'] = {
  12203. execCommand: function (cmdName, tags, style, attrs, notIncludeA) {
  12204. var tagReg = new RegExp(
  12205. '^(?:' + (tags || this.options.removeFormatTags).replace(/,/g, '|') + ')$',
  12206. 'i'
  12207. ),
  12208. removeFormatAttributes = style
  12209. ? []
  12210. : (attrs || this.options.removeFormatAttributes).split(','),
  12211. range = new dom.Range(this.document),
  12212. bookmark,
  12213. node,
  12214. parent,
  12215. filter = function (node) {
  12216. return node.nodeType == 1
  12217. }
  12218. function isRedundantSpan(node) {
  12219. if (node.nodeType == 3 || node.tagName.toLowerCase() != 'span') {
  12220. return 0
  12221. }
  12222. if (browser.ie) {
  12223. //ie 下判断实效,所以只能简单用style来判断
  12224. //return node.style.cssText == '' ? 1 : 0;
  12225. var attrs = node.attributes
  12226. if (attrs.length) {
  12227. for (var i = 0, l = attrs.length; i < l; i++) {
  12228. if (attrs[i].specified) {
  12229. return 0
  12230. }
  12231. }
  12232. return 1
  12233. }
  12234. }
  12235. return !node.attributes.length
  12236. }
  12237. function doRemove(range) {
  12238. var bookmark1 = range.createBookmark()
  12239. if (range.collapsed) {
  12240. range.enlarge(true)
  12241. }
  12242. //不能把a标签切了
  12243. if (!notIncludeA) {
  12244. var aNode = domUtils.findParentByTagName(range.startContainer, 'a', true)
  12245. if (aNode) {
  12246. range.setStartBefore(aNode)
  12247. }
  12248. aNode = domUtils.findParentByTagName(range.endContainer, 'a', true)
  12249. if (aNode) {
  12250. range.setEndAfter(aNode)
  12251. }
  12252. }
  12253. bookmark = range.createBookmark()
  12254. node = bookmark.start
  12255. //切开始
  12256. while ((parent = node.parentNode) && !domUtils.isBlockElm(parent)) {
  12257. domUtils.breakParent(node, parent)
  12258. domUtils.clearEmptySibling(node)
  12259. }
  12260. if (bookmark.end) {
  12261. //切结束
  12262. node = bookmark.end
  12263. while ((parent = node.parentNode) && !domUtils.isBlockElm(parent)) {
  12264. domUtils.breakParent(node, parent)
  12265. domUtils.clearEmptySibling(node)
  12266. }
  12267. //开始去除样式
  12268. var current = domUtils.getNextDomNode(bookmark.start, false, filter),
  12269. next
  12270. while (current) {
  12271. if (current == bookmark.end) {
  12272. break
  12273. }
  12274. next = domUtils.getNextDomNode(current, true, filter)
  12275. if (!dtd.$empty[current.tagName.toLowerCase()] && !domUtils.isBookmarkNode(current)) {
  12276. if (tagReg.test(current.tagName)) {
  12277. if (style) {
  12278. domUtils.removeStyle(current, style)
  12279. if (isRedundantSpan(current) && style != 'text-decoration') {
  12280. domUtils.remove(current, true)
  12281. }
  12282. } else {
  12283. domUtils.remove(current, true)
  12284. }
  12285. } else {
  12286. //trace:939 不能把list上的样式去掉
  12287. if (!dtd.$tableContent[current.tagName] && !dtd.$list[current.tagName]) {
  12288. domUtils.removeAttributes(current, removeFormatAttributes)
  12289. if (isRedundantSpan(current)) {
  12290. domUtils.remove(current, true)
  12291. }
  12292. }
  12293. }
  12294. }
  12295. current = next
  12296. }
  12297. }
  12298. //trace:1035
  12299. //trace:1096 不能把td上的样式去掉,比如边框
  12300. var pN = bookmark.start.parentNode
  12301. if (domUtils.isBlockElm(pN) && !dtd.$tableContent[pN.tagName] && !dtd.$list[pN.tagName]) {
  12302. domUtils.removeAttributes(pN, removeFormatAttributes)
  12303. }
  12304. pN = bookmark.end.parentNode
  12305. if (
  12306. bookmark.end &&
  12307. domUtils.isBlockElm(pN) &&
  12308. !dtd.$tableContent[pN.tagName] &&
  12309. !dtd.$list[pN.tagName]
  12310. ) {
  12311. domUtils.removeAttributes(pN, removeFormatAttributes)
  12312. }
  12313. range.moveToBookmark(bookmark).moveToBookmark(bookmark1)
  12314. //清除冗余的代码 <b><bookmark></b>
  12315. var node = range.startContainer,
  12316. tmp,
  12317. collapsed = range.collapsed
  12318. while (
  12319. node.nodeType == 1 &&
  12320. domUtils.isEmptyNode(node) &&
  12321. dtd.$removeEmpty[node.tagName]
  12322. ) {
  12323. tmp = node.parentNode
  12324. range.setStartBefore(node)
  12325. //trace:937
  12326. //更新结束边界
  12327. if (range.startContainer === range.endContainer) {
  12328. range.endOffset--
  12329. }
  12330. domUtils.remove(node)
  12331. node = tmp
  12332. }
  12333. if (!collapsed) {
  12334. node = range.endContainer
  12335. while (
  12336. node.nodeType == 1 &&
  12337. domUtils.isEmptyNode(node) &&
  12338. dtd.$removeEmpty[node.tagName]
  12339. ) {
  12340. tmp = node.parentNode
  12341. range.setEndBefore(node)
  12342. domUtils.remove(node)
  12343. node = tmp
  12344. }
  12345. }
  12346. }
  12347. range = this.selection.getRange()
  12348. doRemove(range)
  12349. range.select()
  12350. }
  12351. }
  12352. }
  12353. // plugins/blockquote.js
  12354. /**
  12355. * 添加引用
  12356. * @file
  12357. * @since 1.2.6.1
  12358. */
  12359. /**
  12360. * 添加引用
  12361. * @command blockquote
  12362. * @method execCommand
  12363. * @param { String } cmd 命令字符串
  12364. * @example
  12365. * ```javascript
  12366. * editor.execCommand( 'blockquote' );
  12367. * ```
  12368. */
  12369. /**
  12370. * 添加引用
  12371. * @command blockquote
  12372. * @method execCommand
  12373. * @param { String } cmd 命令字符串
  12374. * @param { Object } attrs 节点属性
  12375. * @example
  12376. * ```javascript
  12377. * editor.execCommand( 'blockquote',{
  12378. * style: "color: red;"
  12379. * } );
  12380. * ```
  12381. */
  12382. UE.plugins['blockquote'] = function () {
  12383. var me = this
  12384. function getObj(editor) {
  12385. return domUtils.filterNodeList(editor.selection.getStartElementPath(), 'blockquote')
  12386. }
  12387. me.commands['blockquote'] = {
  12388. execCommand: function (cmdName, attrs) {
  12389. var range = this.selection.getRange(),
  12390. obj = getObj(this),
  12391. blockquote = dtd.blockquote,
  12392. bookmark = range.createBookmark()
  12393. if (obj) {
  12394. var start = range.startContainer,
  12395. startBlock = domUtils.isBlockElm(start)
  12396. ? start
  12397. : domUtils.findParent(start, function (node) {
  12398. return domUtils.isBlockElm(node)
  12399. }),
  12400. end = range.endContainer,
  12401. endBlock = domUtils.isBlockElm(end)
  12402. ? end
  12403. : domUtils.findParent(end, function (node) {
  12404. return domUtils.isBlockElm(node)
  12405. })
  12406. //处理一下li
  12407. startBlock = domUtils.findParentByTagName(startBlock, 'li', true) || startBlock
  12408. endBlock = domUtils.findParentByTagName(endBlock, 'li', true) || endBlock
  12409. if (
  12410. startBlock.tagName == 'LI' ||
  12411. startBlock.tagName == 'TD' ||
  12412. startBlock === obj ||
  12413. domUtils.isBody(startBlock)
  12414. ) {
  12415. domUtils.remove(obj, true)
  12416. } else {
  12417. domUtils.breakParent(startBlock, obj)
  12418. }
  12419. if (startBlock !== endBlock) {
  12420. obj = domUtils.findParentByTagName(endBlock, 'blockquote')
  12421. if (obj) {
  12422. if (
  12423. endBlock.tagName == 'LI' ||
  12424. endBlock.tagName == 'TD' ||
  12425. domUtils.isBody(endBlock)
  12426. ) {
  12427. obj.parentNode && domUtils.remove(obj, true)
  12428. } else {
  12429. domUtils.breakParent(endBlock, obj)
  12430. }
  12431. }
  12432. }
  12433. var blockquotes = domUtils.getElementsByTagName(this.document, 'blockquote')
  12434. for (var i = 0, bi; (bi = blockquotes[i++]); ) {
  12435. if (!bi.childNodes.length) {
  12436. domUtils.remove(bi)
  12437. } else if (
  12438. domUtils.getPosition(bi, startBlock) & domUtils.POSITION_FOLLOWING &&
  12439. domUtils.getPosition(bi, endBlock) & domUtils.POSITION_PRECEDING
  12440. ) {
  12441. domUtils.remove(bi, true)
  12442. }
  12443. }
  12444. } else {
  12445. var tmpRange = range.cloneRange(),
  12446. node =
  12447. tmpRange.startContainer.nodeType == 1
  12448. ? tmpRange.startContainer
  12449. : tmpRange.startContainer.parentNode,
  12450. preNode = node,
  12451. doEnd = 1
  12452. //调整开始
  12453. while (1) {
  12454. if (domUtils.isBody(node)) {
  12455. if (preNode !== node) {
  12456. if (range.collapsed) {
  12457. tmpRange.selectNode(preNode)
  12458. doEnd = 0
  12459. } else {
  12460. tmpRange.setStartBefore(preNode)
  12461. }
  12462. } else {
  12463. tmpRange.setStart(node, 0)
  12464. }
  12465. break
  12466. }
  12467. if (!blockquote[node.tagName]) {
  12468. if (range.collapsed) {
  12469. tmpRange.selectNode(preNode)
  12470. } else {
  12471. tmpRange.setStartBefore(preNode)
  12472. }
  12473. break
  12474. }
  12475. preNode = node
  12476. node = node.parentNode
  12477. }
  12478. //调整结束
  12479. if (doEnd) {
  12480. preNode =
  12481. node =
  12482. node =
  12483. tmpRange.endContainer.nodeType == 1
  12484. ? tmpRange.endContainer
  12485. : tmpRange.endContainer.parentNode
  12486. while (1) {
  12487. if (domUtils.isBody(node)) {
  12488. if (preNode !== node) {
  12489. tmpRange.setEndAfter(preNode)
  12490. } else {
  12491. tmpRange.setEnd(node, node.childNodes.length)
  12492. }
  12493. break
  12494. }
  12495. if (!blockquote[node.tagName]) {
  12496. tmpRange.setEndAfter(preNode)
  12497. break
  12498. }
  12499. preNode = node
  12500. node = node.parentNode
  12501. }
  12502. }
  12503. node = range.document.createElement('blockquote')
  12504. domUtils.setAttributes(node, attrs)
  12505. node.appendChild(tmpRange.extractContents())
  12506. tmpRange.insertNode(node)
  12507. //去除重复的
  12508. var childs = domUtils.getElementsByTagName(node, 'blockquote')
  12509. for (var i = 0, ci; (ci = childs[i++]); ) {
  12510. if (ci.parentNode) {
  12511. domUtils.remove(ci, true)
  12512. }
  12513. }
  12514. }
  12515. range.moveToBookmark(bookmark).select()
  12516. },
  12517. queryCommandState: function () {
  12518. return getObj(this) ? 1 : 0
  12519. }
  12520. }
  12521. }
  12522. // plugins/convertcase.js
  12523. /**
  12524. * 大小写转换
  12525. * @file
  12526. * @since 1.2.6.1
  12527. */
  12528. /**
  12529. * 把选区内文本变大写,与“tolowercase”命令互斥
  12530. * @command touppercase
  12531. * @method execCommand
  12532. * @param { String } cmd 命令字符串
  12533. * @example
  12534. * ```javascript
  12535. * editor.execCommand( 'touppercase' );
  12536. * ```
  12537. */
  12538. /**
  12539. * 把选区内文本变小写,与“touppercase”命令互斥
  12540. * @command tolowercase
  12541. * @method execCommand
  12542. * @param { String } cmd 命令字符串
  12543. * @example
  12544. * ```javascript
  12545. * editor.execCommand( 'tolowercase' );
  12546. * ```
  12547. */
  12548. UE.commands['touppercase'] = UE.commands['tolowercase'] = {
  12549. execCommand: function (cmd) {
  12550. var me = this
  12551. var rng = me.selection.getRange()
  12552. if (rng.collapsed) {
  12553. return rng
  12554. }
  12555. var bk = rng.createBookmark(),
  12556. bkEnd = bk.end,
  12557. filterFn = function (node) {
  12558. return !domUtils.isBr(node) && !domUtils.isWhitespace(node)
  12559. },
  12560. curNode = domUtils.getNextDomNode(bk.start, false, filterFn)
  12561. while (curNode && domUtils.getPosition(curNode, bkEnd) & domUtils.POSITION_PRECEDING) {
  12562. if (curNode.nodeType == 3) {
  12563. curNode.nodeValue =
  12564. curNode.nodeValue[cmd == 'touppercase' ? 'toUpperCase' : 'toLowerCase']()
  12565. }
  12566. curNode = domUtils.getNextDomNode(curNode, true, filterFn)
  12567. if (curNode === bkEnd) {
  12568. break
  12569. }
  12570. }
  12571. rng.moveToBookmark(bk).select()
  12572. }
  12573. }
  12574. // plugins/indent.js
  12575. /**
  12576. * 首行缩进
  12577. * @file
  12578. * @since 1.2.6.1
  12579. */
  12580. /**
  12581. * 缩进
  12582. * @command indent
  12583. * @method execCommand
  12584. * @param { String } cmd 命令字符串
  12585. * @example
  12586. * ```javascript
  12587. * editor.execCommand( 'indent' );
  12588. * ```
  12589. */
  12590. UE.commands['indent'] = {
  12591. execCommand: function () {
  12592. var me = this,
  12593. value = me.queryCommandState('indent') ? '0em' : me.options.indentValue || '2em'
  12594. me.execCommand('Paragraph', 'p', { style: 'text-indent:' + value })
  12595. },
  12596. queryCommandState: function () {
  12597. var pN = domUtils.filterNodeList(this.selection.getStartElementPath(), 'p h1 h2 h3 h4 h5 h6')
  12598. return pN && pN.style.textIndent && parseInt(pN.style.textIndent) ? 1 : 0
  12599. }
  12600. }
  12601. // plugins/print.js
  12602. /**
  12603. * 打印
  12604. * @file
  12605. * @since 1.2.6.1
  12606. */
  12607. /**
  12608. * 打印
  12609. * @command print
  12610. * @method execCommand
  12611. * @param { String } cmd 命令字符串
  12612. * @example
  12613. * ```javascript
  12614. * editor.execCommand( 'print' );
  12615. * ```
  12616. */
  12617. UE.commands['print'] = {
  12618. execCommand: function () {
  12619. this.window.print()
  12620. },
  12621. notNeedUndo: 1
  12622. }
  12623. // plugins/preview.js
  12624. /**
  12625. * 预览
  12626. * @file
  12627. * @since 1.2.6.1
  12628. */
  12629. /**
  12630. * 预览
  12631. * @command preview
  12632. * @method execCommand
  12633. * @param { String } cmd 命令字符串
  12634. * @example
  12635. * ```javascript
  12636. * editor.execCommand( 'preview' );
  12637. * ```
  12638. */
  12639. UE.commands['preview'] = {
  12640. execCommand: function () {
  12641. var w = window.open('', '_blank', ''),
  12642. d = w.document
  12643. d.open()
  12644. d.write(
  12645. '<!DOCTYPE html><html><head><meta charset="utf-8"/><script src="' +
  12646. this.options.UEDITOR_HOME_URL +
  12647. 'ueditor.parse.js"></script><script>' +
  12648. "setTimeout(function(){uParse('div',{rootPath: '" +
  12649. this.options.UEDITOR_HOME_URL +
  12650. "'})},300)" +
  12651. '</script></head><body><div>' +
  12652. this.getContent(null, null, true) +
  12653. '</div></body></html>'
  12654. )
  12655. d.close()
  12656. },
  12657. notNeedUndo: 1
  12658. }
  12659. // plugins/selectall.js
  12660. /**
  12661. * 全选
  12662. * @file
  12663. * @since 1.2.6.1
  12664. */
  12665. /**
  12666. * 选中所有内容
  12667. * @command selectall
  12668. * @method execCommand
  12669. * @param { String } cmd 命令字符串
  12670. * @example
  12671. * ```javascript
  12672. * editor.execCommand( 'selectall' );
  12673. * ```
  12674. */
  12675. UE.plugins['selectall'] = function () {
  12676. var me = this
  12677. me.commands['selectall'] = {
  12678. execCommand: function () {
  12679. //去掉了原生的selectAll,因为会出现报错和当内容为空时,不能出现闭合状态的光标
  12680. var me = this,
  12681. body = me.body,
  12682. range = me.selection.getRange()
  12683. range.selectNodeContents(body)
  12684. if (domUtils.isEmptyBlock(body)) {
  12685. //opera不能自动合并到元素的里边,要手动处理一下
  12686. if (browser.opera && body.firstChild && body.firstChild.nodeType == 1) {
  12687. range.setStartAtFirst(body.firstChild)
  12688. }
  12689. range.collapse(true)
  12690. }
  12691. range.select(true)
  12692. },
  12693. notNeedUndo: 1
  12694. }
  12695. //快捷键
  12696. me.addshortcutkey({
  12697. selectAll: 'ctrl+65'
  12698. })
  12699. }
  12700. // plugins/paragraph.js
  12701. /**
  12702. * 段落样式
  12703. * @file
  12704. * @since 1.2.6.1
  12705. */
  12706. /**
  12707. * 段落格式
  12708. * @command paragraph
  12709. * @method execCommand
  12710. * @param { String } cmd 命令字符串
  12711. * @param {String} style 标签值为:'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
  12712. * @param {Object} attrs 标签的属性
  12713. * @example
  12714. * ```javascript
  12715. * editor.execCommand( 'Paragraph','h1','{
  12716. * class:'test'
  12717. * }' );
  12718. * ```
  12719. */
  12720. /**
  12721. * 返回选区内节点标签名
  12722. * @command paragraph
  12723. * @method queryCommandValue
  12724. * @param { String } cmd 命令字符串
  12725. * @return { String } 节点标签名
  12726. * @example
  12727. * ```javascript
  12728. * editor.queryCommandValue( 'Paragraph' );
  12729. * ```
  12730. */
  12731. UE.plugins['paragraph'] = function () {
  12732. var me = this,
  12733. block = domUtils.isBlockElm,
  12734. notExchange = ['TD', 'LI', 'PRE'],
  12735. doParagraph = function (range, style, attrs, sourceCmdName) {
  12736. var bookmark = range.createBookmark(),
  12737. filterFn = function (node) {
  12738. return node.nodeType == 1
  12739. ? node.tagName.toLowerCase() != 'br' && !domUtils.isBookmarkNode(node)
  12740. : !domUtils.isWhitespace(node)
  12741. },
  12742. para
  12743. range.enlarge(true)
  12744. var bookmark2 = range.createBookmark(),
  12745. current = domUtils.getNextDomNode(bookmark2.start, false, filterFn),
  12746. tmpRange = range.cloneRange(),
  12747. tmpNode
  12748. while (
  12749. current &&
  12750. !(domUtils.getPosition(current, bookmark2.end) & domUtils.POSITION_FOLLOWING)
  12751. ) {
  12752. if (current.nodeType == 3 || !block(current)) {
  12753. tmpRange.setStartBefore(current)
  12754. while (current && current !== bookmark2.end && !block(current)) {
  12755. tmpNode = current
  12756. current = domUtils.getNextDomNode(current, false, null, function (node) {
  12757. return !block(node)
  12758. })
  12759. }
  12760. tmpRange.setEndAfter(tmpNode)
  12761. para = range.document.createElement(style)
  12762. if (attrs) {
  12763. domUtils.setAttributes(para, attrs)
  12764. if (sourceCmdName && sourceCmdName == 'customstyle' && attrs.style) {
  12765. para.style.cssText = attrs.style
  12766. }
  12767. }
  12768. para.appendChild(tmpRange.extractContents())
  12769. //需要内容占位
  12770. if (domUtils.isEmptyNode(para)) {
  12771. domUtils.fillChar(range.document, para)
  12772. }
  12773. tmpRange.insertNode(para)
  12774. var parent = para.parentNode
  12775. //如果para上一级是一个block元素且不是body,td就删除它
  12776. if (
  12777. block(parent) &&
  12778. !domUtils.isBody(para.parentNode) &&
  12779. utils.indexOf(notExchange, parent.tagName) == -1
  12780. ) {
  12781. //存储dir,style
  12782. if (!(sourceCmdName && sourceCmdName == 'customstyle')) {
  12783. parent.getAttribute('dir') && para.setAttribute('dir', parent.getAttribute('dir'))
  12784. //trace:1070
  12785. parent.style.cssText &&
  12786. (para.style.cssText = parent.style.cssText + ';' + para.style.cssText)
  12787. //trace:1030
  12788. parent.style.textAlign &&
  12789. !para.style.textAlign &&
  12790. (para.style.textAlign = parent.style.textAlign)
  12791. parent.style.textIndent &&
  12792. !para.style.textIndent &&
  12793. (para.style.textIndent = parent.style.textIndent)
  12794. parent.style.padding &&
  12795. !para.style.padding &&
  12796. (para.style.padding = parent.style.padding)
  12797. }
  12798. //trace:1706 选择的就是h1-6要删除
  12799. if (attrs && /h\d/i.test(parent.tagName) && !/h\d/i.test(para.tagName)) {
  12800. domUtils.setAttributes(parent, attrs)
  12801. if (sourceCmdName && sourceCmdName == 'customstyle' && attrs.style) {
  12802. parent.style.cssText = attrs.style
  12803. }
  12804. domUtils.remove(para, true)
  12805. para = parent
  12806. } else {
  12807. domUtils.remove(para.parentNode, true)
  12808. }
  12809. }
  12810. if (utils.indexOf(notExchange, parent.tagName) != -1) {
  12811. current = parent
  12812. } else {
  12813. current = para
  12814. }
  12815. current = domUtils.getNextDomNode(current, false, filterFn)
  12816. } else {
  12817. current = domUtils.getNextDomNode(current, true, filterFn)
  12818. }
  12819. }
  12820. return range.moveToBookmark(bookmark2).moveToBookmark(bookmark)
  12821. }
  12822. me.setOpt('paragraph', {
  12823. p: '',
  12824. h1: '',
  12825. h2: '',
  12826. h3: '',
  12827. h4: '',
  12828. h5: '',
  12829. h6: ''
  12830. })
  12831. me.commands['paragraph'] = {
  12832. execCommand: function (cmdName, style, attrs, sourceCmdName) {
  12833. var range = this.selection.getRange()
  12834. //闭合时单独处理
  12835. if (range.collapsed) {
  12836. var txt = this.document.createTextNode('p')
  12837. range.insertNode(txt)
  12838. //去掉冗余的fillchar
  12839. if (browser.ie) {
  12840. var node = txt.previousSibling
  12841. if (node && domUtils.isWhitespace(node)) {
  12842. domUtils.remove(node)
  12843. }
  12844. node = txt.nextSibling
  12845. if (node && domUtils.isWhitespace(node)) {
  12846. domUtils.remove(node)
  12847. }
  12848. }
  12849. }
  12850. range = doParagraph(range, style, attrs, sourceCmdName)
  12851. if (txt) {
  12852. range.setStartBefore(txt).collapse(true)
  12853. pN = txt.parentNode
  12854. domUtils.remove(txt)
  12855. if (domUtils.isBlockElm(pN) && domUtils.isEmptyNode(pN)) {
  12856. domUtils.fillNode(this.document, pN)
  12857. }
  12858. }
  12859. if (browser.gecko && range.collapsed && range.startContainer.nodeType == 1) {
  12860. var child = range.startContainer.childNodes[range.startOffset]
  12861. if (child && child.nodeType == 1 && child.tagName.toLowerCase() == style) {
  12862. range.setStart(child, 0).collapse(true)
  12863. }
  12864. }
  12865. //trace:1097 原来有true,原因忘了,但去了就不能清除多余的占位符了
  12866. range.select()
  12867. return true
  12868. },
  12869. queryCommandValue: function () {
  12870. var node = domUtils.filterNodeList(
  12871. this.selection.getStartElementPath(),
  12872. 'p h1 h2 h3 h4 h5 h6'
  12873. )
  12874. return node ? node.tagName.toLowerCase() : ''
  12875. }
  12876. }
  12877. }
  12878. // plugins/directionality.js
  12879. /**
  12880. * 设置文字输入的方向的插件
  12881. * @file
  12882. * @since 1.2.6.1
  12883. */
  12884. ;(function () {
  12885. var block = domUtils.isBlockElm,
  12886. getObj = function (editor) {
  12887. // var startNode = editor.selection.getStart(),
  12888. // parents;
  12889. // if ( startNode ) {
  12890. // //查找所有的是block的父亲节点
  12891. // parents = domUtils.findParents( startNode, true, block, true );
  12892. // for ( var i = 0,ci; ci = parents[i++]; ) {
  12893. // if ( ci.getAttribute( 'dir' ) ) {
  12894. // return ci;
  12895. // }
  12896. // }
  12897. // }
  12898. return domUtils.filterNodeList(editor.selection.getStartElementPath(), function (n) {
  12899. return n && n.nodeType == 1 && n.getAttribute('dir')
  12900. })
  12901. },
  12902. doDirectionality = function (range, editor, forward) {
  12903. var bookmark,
  12904. filterFn = function (node) {
  12905. return node.nodeType == 1
  12906. ? !domUtils.isBookmarkNode(node)
  12907. : !domUtils.isWhitespace(node)
  12908. },
  12909. obj = getObj(editor)
  12910. if (obj && range.collapsed) {
  12911. obj.setAttribute('dir', forward)
  12912. return range
  12913. }
  12914. bookmark = range.createBookmark()
  12915. range.enlarge(true)
  12916. var bookmark2 = range.createBookmark(),
  12917. current = domUtils.getNextDomNode(bookmark2.start, false, filterFn),
  12918. tmpRange = range.cloneRange(),
  12919. tmpNode
  12920. while (
  12921. current &&
  12922. !(domUtils.getPosition(current, bookmark2.end) & domUtils.POSITION_FOLLOWING)
  12923. ) {
  12924. if (current.nodeType == 3 || !block(current)) {
  12925. tmpRange.setStartBefore(current)
  12926. while (current && current !== bookmark2.end && !block(current)) {
  12927. tmpNode = current
  12928. current = domUtils.getNextDomNode(current, false, null, function (node) {
  12929. return !block(node)
  12930. })
  12931. }
  12932. tmpRange.setEndAfter(tmpNode)
  12933. var common = tmpRange.getCommonAncestor()
  12934. if (!domUtils.isBody(common) && block(common)) {
  12935. //遍历到了block节点
  12936. common.setAttribute('dir', forward)
  12937. current = common
  12938. } else {
  12939. //没有遍历到,添加一个block节点
  12940. var p = range.document.createElement('p')
  12941. p.setAttribute('dir', forward)
  12942. var frag = tmpRange.extractContents()
  12943. p.appendChild(frag)
  12944. tmpRange.insertNode(p)
  12945. current = p
  12946. }
  12947. current = domUtils.getNextDomNode(current, false, filterFn)
  12948. } else {
  12949. current = domUtils.getNextDomNode(current, true, filterFn)
  12950. }
  12951. }
  12952. return range.moveToBookmark(bookmark2).moveToBookmark(bookmark)
  12953. }
  12954. /**
  12955. * 文字输入方向
  12956. * @command directionality
  12957. * @method execCommand
  12958. * @param { String } cmdName 命令字符串
  12959. * @param { String } forward 传入'ltr'表示从左向右输入,传入'rtl'表示从右向左输入
  12960. * @example
  12961. * ```javascript
  12962. * editor.execCommand( 'directionality', 'ltr');
  12963. * ```
  12964. */
  12965. /**
  12966. * 查询当前选区的文字输入方向
  12967. * @command directionality
  12968. * @method queryCommandValue
  12969. * @param { String } cmdName 命令字符串
  12970. * @return { String } 返回'ltr'表示从左向右输入,返回'rtl'表示从右向左输入
  12971. * @example
  12972. * ```javascript
  12973. * editor.queryCommandValue( 'directionality');
  12974. * ```
  12975. */
  12976. UE.commands['directionality'] = {
  12977. execCommand: function (cmdName, forward) {
  12978. var range = this.selection.getRange()
  12979. //闭合时单独处理
  12980. if (range.collapsed) {
  12981. var txt = this.document.createTextNode('d')
  12982. range.insertNode(txt)
  12983. }
  12984. doDirectionality(range, this, forward)
  12985. if (txt) {
  12986. range.setStartBefore(txt).collapse(true)
  12987. domUtils.remove(txt)
  12988. }
  12989. range.select()
  12990. return true
  12991. },
  12992. queryCommandValue: function () {
  12993. var node = getObj(this)
  12994. return node ? node.getAttribute('dir') : 'ltr'
  12995. }
  12996. }
  12997. })()
  12998. // plugins/horizontal.js
  12999. /**
  13000. * 插入分割线插件
  13001. * @file
  13002. * @since 1.2.6.1
  13003. */
  13004. /**
  13005. * 插入分割线
  13006. * @command horizontal
  13007. * @method execCommand
  13008. * @param { String } cmdName 命令字符串
  13009. * @example
  13010. * ```javascript
  13011. * editor.execCommand( 'horizontal' );
  13012. * ```
  13013. */
  13014. UE.plugins['horizontal'] = function () {
  13015. var me = this
  13016. me.commands['horizontal'] = {
  13017. execCommand: function (cmdName) {
  13018. var me = this
  13019. if (me.queryCommandState(cmdName) !== -1) {
  13020. me.execCommand('insertHtml', '<hr>')
  13021. var range = me.selection.getRange(),
  13022. start = range.startContainer
  13023. if (start.nodeType == 1 && !start.childNodes[range.startOffset]) {
  13024. var tmp
  13025. if ((tmp = start.childNodes[range.startOffset - 1])) {
  13026. if (tmp.nodeType == 1 && tmp.tagName == 'HR') {
  13027. if (me.options.enterTag == 'p') {
  13028. tmp = me.document.createElement('p')
  13029. range.insertNode(tmp)
  13030. range.setStart(tmp, 0).setCursor()
  13031. } else {
  13032. tmp = me.document.createElement('br')
  13033. range.insertNode(tmp)
  13034. range.setStartBefore(tmp).setCursor()
  13035. }
  13036. }
  13037. }
  13038. }
  13039. return true
  13040. }
  13041. },
  13042. //边界在table里不能加分隔线
  13043. queryCommandState: function () {
  13044. return domUtils.filterNodeList(this.selection.getStartElementPath(), 'table') ? -1 : 0
  13045. }
  13046. }
  13047. // me.addListener('delkeyup',function(){
  13048. // var rng = this.selection.getRange();
  13049. // if(browser.ie && browser.version > 8){
  13050. // rng.txtToElmBoundary(true);
  13051. // if(domUtils.isStartInblock(rng)){
  13052. // var tmpNode = rng.startContainer;
  13053. // var pre = tmpNode.previousSibling;
  13054. // if(pre && domUtils.isTagNode(pre,'hr')){
  13055. // domUtils.remove(pre);
  13056. // rng.select();
  13057. // return;
  13058. // }
  13059. // }
  13060. // }
  13061. // if(domUtils.isBody(rng.startContainer)){
  13062. // var hr = rng.startContainer.childNodes[rng.startOffset -1];
  13063. // if(hr && hr.nodeName == 'HR'){
  13064. // var next = hr.nextSibling;
  13065. // if(next){
  13066. // rng.setStart(next,0)
  13067. // }else if(hr.previousSibling){
  13068. // rng.setStartAtLast(hr.previousSibling)
  13069. // }else{
  13070. // var p = this.document.createElement('p');
  13071. // hr.parentNode.insertBefore(p,hr);
  13072. // domUtils.fillNode(this.document,p);
  13073. // rng.setStart(p,0);
  13074. // }
  13075. // domUtils.remove(hr);
  13076. // rng.setCursor(false,true);
  13077. // }
  13078. // }
  13079. // })
  13080. me.addListener('delkeydown', function (name, evt) {
  13081. var rng = this.selection.getRange()
  13082. rng.txtToElmBoundary(true)
  13083. if (domUtils.isStartInblock(rng)) {
  13084. var tmpNode = rng.startContainer
  13085. var pre = tmpNode.previousSibling
  13086. if (pre && domUtils.isTagNode(pre, 'hr')) {
  13087. domUtils.remove(pre)
  13088. rng.select()
  13089. domUtils.preventDefault(evt)
  13090. return true
  13091. }
  13092. }
  13093. })
  13094. }
  13095. // plugins/time.js
  13096. /**
  13097. * 插入时间和日期
  13098. * @file
  13099. * @since 1.2.6.1
  13100. */
  13101. /**
  13102. * 插入时间,默认格式:12:59:59
  13103. * @command time
  13104. * @method execCommand
  13105. * @param { String } cmd 命令字符串
  13106. * @example
  13107. * ```javascript
  13108. * editor.execCommand( 'time');
  13109. * ```
  13110. */
  13111. /**
  13112. * 插入日期,默认格式:2013-08-30
  13113. * @command date
  13114. * @method execCommand
  13115. * @param { String } cmd 命令字符串
  13116. * @example
  13117. * ```javascript
  13118. * editor.execCommand( 'date');
  13119. * ```
  13120. */
  13121. UE.commands['time'] = UE.commands['date'] = {
  13122. execCommand: function (cmd, format) {
  13123. var date = new Date()
  13124. function formatTime(date, format) {
  13125. var hh = ('0' + date.getHours()).slice(-2),
  13126. ii = ('0' + date.getMinutes()).slice(-2),
  13127. ss = ('0' + date.getSeconds()).slice(-2)
  13128. format = format || 'hh:ii:ss'
  13129. return format.replace(/hh/gi, hh).replace(/ii/gi, ii).replace(/ss/gi, ss)
  13130. }
  13131. function formatDate(date, format) {
  13132. var yyyy = ('000' + date.getFullYear()).slice(-4),
  13133. yy = yyyy.slice(-2),
  13134. mm = ('0' + (date.getMonth() + 1)).slice(-2),
  13135. dd = ('0' + date.getDate()).slice(-2)
  13136. format = format || 'yyyy-mm-dd'
  13137. return format
  13138. .replace(/yyyy/gi, yyyy)
  13139. .replace(/yy/gi, yy)
  13140. .replace(/mm/gi, mm)
  13141. .replace(/dd/gi, dd)
  13142. }
  13143. this.execCommand(
  13144. 'insertHtml',
  13145. cmd == 'time' ? formatTime(date, format) : formatDate(date, format)
  13146. )
  13147. }
  13148. }
  13149. // plugins/rowspacing.js
  13150. /**
  13151. * 段前段后间距插件
  13152. * @file
  13153. * @since 1.2.6.1
  13154. */
  13155. /**
  13156. * 设置段间距
  13157. * @command rowspacing
  13158. * @method execCommand
  13159. * @param { String } cmd 命令字符串
  13160. * @param { String } value 段间距的值,以px为单位
  13161. * @param { String } dir 间距位置,top或bottom,分别表示段前和段后
  13162. * @example
  13163. * ```javascript
  13164. * editor.execCommand( 'rowspacing', '10', 'top' );
  13165. * ```
  13166. */
  13167. UE.plugins['rowspacing'] = function () {
  13168. var me = this
  13169. me.setOpt({
  13170. rowspacingtop: ['5', '10', '15', '20', '25'],
  13171. rowspacingbottom: ['5', '10', '15', '20', '25']
  13172. })
  13173. me.commands['rowspacing'] = {
  13174. execCommand: function (cmdName, value, dir) {
  13175. this.execCommand('paragraph', 'p', {
  13176. style: 'margin-' + dir + ':' + value + 'px'
  13177. })
  13178. return true
  13179. },
  13180. queryCommandValue: function (cmdName, dir) {
  13181. var pN = domUtils.filterNodeList(this.selection.getStartElementPath(), function (node) {
  13182. return domUtils.isBlockElm(node)
  13183. }),
  13184. value
  13185. //trace:1026
  13186. if (pN) {
  13187. value = domUtils.getComputedStyle(pN, 'margin-' + dir).replace(/[^\d]/g, '')
  13188. return !value ? 0 : value
  13189. }
  13190. return 0
  13191. }
  13192. }
  13193. }
  13194. // plugins/lineheight.js
  13195. /**
  13196. * 设置行内间距
  13197. * @file
  13198. * @since 1.2.6.1
  13199. */
  13200. UE.plugins['lineheight'] = function () {
  13201. var me = this
  13202. me.setOpt({ lineheight: ['1', '1.5', '1.75', '2', '3', '4', '5'] })
  13203. /**
  13204. * 行距
  13205. * @command lineheight
  13206. * @method execCommand
  13207. * @param { String } cmdName 命令字符串
  13208. * @param { String } value 传入的行高值, 该值是当前字体的倍数, 例如: 1.5, 1.75
  13209. * @example
  13210. * ```javascript
  13211. * editor.execCommand( 'lineheight', 1.5);
  13212. * ```
  13213. */
  13214. /**
  13215. * 查询当前选区内容的行高大小
  13216. * @command lineheight
  13217. * @method queryCommandValue
  13218. * @param { String } cmd 命令字符串
  13219. * @return { String } 返回当前行高大小
  13220. * @example
  13221. * ```javascript
  13222. * editor.queryCommandValue( 'lineheight' );
  13223. * ```
  13224. */
  13225. me.commands['lineheight'] = {
  13226. execCommand: function (cmdName, value) {
  13227. this.execCommand('paragraph', 'p', {
  13228. style: 'line-height:' + (value == '1' ? 'normal' : value + 'em')
  13229. })
  13230. return true
  13231. },
  13232. queryCommandValue: function () {
  13233. var pN = domUtils.filterNodeList(this.selection.getStartElementPath(), function (node) {
  13234. return domUtils.isBlockElm(node)
  13235. })
  13236. if (pN) {
  13237. var value = domUtils.getComputedStyle(pN, 'line-height')
  13238. return value == 'normal' ? 1 : value.replace(/[^\d.]*/gi, '')
  13239. }
  13240. }
  13241. }
  13242. }
  13243. // plugins/insertcode.js
  13244. /**
  13245. * 插入代码插件
  13246. * @file
  13247. * @since 1.2.6.1
  13248. */
  13249. UE.plugins['insertcode'] = function () {
  13250. var me = this
  13251. me.ready(function () {
  13252. utils.cssRule(
  13253. 'pre',
  13254. 'pre{margin:.5em 0;padding:.4em .6em;border-radius:8px;background:#f8f8f8;}',
  13255. me.document
  13256. )
  13257. })
  13258. me.setOpt('insertcode', {
  13259. as3: 'ActionScript3',
  13260. bash: 'Bash/Shell',
  13261. cpp: 'C/C++',
  13262. css: 'Css',
  13263. cf: 'CodeFunction',
  13264. 'c#': 'C#',
  13265. delphi: 'Delphi',
  13266. diff: 'Diff',
  13267. erlang: 'Erlang',
  13268. groovy: 'Groovy',
  13269. html: 'Html',
  13270. java: 'Java',
  13271. jfx: 'JavaFx',
  13272. js: 'Javascript',
  13273. pl: 'Perl',
  13274. php: 'Php',
  13275. plain: 'Plain Text',
  13276. ps: 'PowerShell',
  13277. python: 'Python',
  13278. ruby: 'Ruby',
  13279. scala: 'Scala',
  13280. sql: 'Sql',
  13281. vb: 'Vb',
  13282. xml: 'Xml'
  13283. })
  13284. /**
  13285. * 插入代码
  13286. * @command insertcode
  13287. * @method execCommand
  13288. * @param { String } cmd 命令字符串
  13289. * @param { String } lang 插入代码的语言
  13290. * @example
  13291. * ```javascript
  13292. * editor.execCommand( 'insertcode', 'javascript' );
  13293. * ```
  13294. */
  13295. /**
  13296. * 如果选区所在位置是插入插入代码区域,返回代码的语言
  13297. * @command insertcode
  13298. * @method queryCommandValue
  13299. * @param { String } cmd 命令字符串
  13300. * @return { String } 返回代码的语言
  13301. * @example
  13302. * ```javascript
  13303. * editor.queryCommandValue( 'insertcode' );
  13304. * ```
  13305. */
  13306. me.commands['insertcode'] = {
  13307. execCommand: function (cmd, lang) {
  13308. var me = this,
  13309. rng = me.selection.getRange(),
  13310. pre = domUtils.findParentByTagName(rng.startContainer, 'pre', true)
  13311. if (pre) {
  13312. pre.className = 'brush:' + lang + ';toolbar:false;'
  13313. } else {
  13314. var code = ''
  13315. if (rng.collapsed) {
  13316. code =
  13317. browser.ie && browser.ie11below ? (browser.version <= 8 ? '&nbsp;' : '') : '<br/>'
  13318. } else {
  13319. var frag = rng.extractContents()
  13320. var div = me.document.createElement('div')
  13321. div.appendChild(frag)
  13322. utils.each(
  13323. UE.filterNode(
  13324. UE.htmlparser(div.innerHTML.replace(/[\r\t]/g, '')),
  13325. me.options.filterTxtRules
  13326. ).children,
  13327. function (node) {
  13328. if (browser.ie && browser.ie11below && browser.version > 8) {
  13329. if (node.type == 'element') {
  13330. if (node.tagName == 'br') {
  13331. code += '\n'
  13332. } else if (!dtd.$empty[node.tagName]) {
  13333. utils.each(node.children, function (cn) {
  13334. if (cn.type == 'element') {
  13335. if (cn.tagName == 'br') {
  13336. code += '\n'
  13337. } else if (!dtd.$empty[node.tagName]) {
  13338. code += cn.innerText()
  13339. }
  13340. } else {
  13341. code += cn.data
  13342. }
  13343. })
  13344. if (!/\n$/.test(code)) {
  13345. code += '\n'
  13346. }
  13347. }
  13348. } else {
  13349. code += node.data + '\n'
  13350. }
  13351. if (!node.nextSibling() && /\n$/.test(code)) {
  13352. code = code.replace(/\n$/, '')
  13353. }
  13354. } else {
  13355. if (browser.ie && browser.ie11below) {
  13356. if (node.type == 'element') {
  13357. if (node.tagName == 'br') {
  13358. code += '<br>'
  13359. } else if (!dtd.$empty[node.tagName]) {
  13360. utils.each(node.children, function (cn) {
  13361. if (cn.type == 'element') {
  13362. if (cn.tagName == 'br') {
  13363. code += '<br>'
  13364. } else if (!dtd.$empty[node.tagName]) {
  13365. code += cn.innerText()
  13366. }
  13367. } else {
  13368. code += cn.data
  13369. }
  13370. })
  13371. if (!/br>$/.test(code)) {
  13372. code += '<br>'
  13373. }
  13374. }
  13375. } else {
  13376. code += node.data + '<br>'
  13377. }
  13378. if (!node.nextSibling() && /<br>$/.test(code)) {
  13379. code = code.replace(/<br>$/, '')
  13380. }
  13381. } else {
  13382. code +=
  13383. node.type == 'element'
  13384. ? dtd.$empty[node.tagName]
  13385. ? ''
  13386. : node.innerText()
  13387. : node.data
  13388. if (!/br\/?\s*>$/.test(code)) {
  13389. if (!node.nextSibling()) return
  13390. code += '<br>'
  13391. }
  13392. }
  13393. }
  13394. }
  13395. )
  13396. }
  13397. me.execCommand(
  13398. 'inserthtml',
  13399. '<pre id="coder"class="brush:' + lang + ';toolbar:false">' + code + '</pre>',
  13400. true
  13401. )
  13402. pre = me.document.getElementById('coder')
  13403. domUtils.removeAttributes(pre, 'id')
  13404. var tmpNode = pre.previousSibling
  13405. if (
  13406. tmpNode &&
  13407. ((tmpNode.nodeType == 3 &&
  13408. tmpNode.nodeValue.length == 1 &&
  13409. browser.ie &&
  13410. browser.version == 6) ||
  13411. domUtils.isEmptyBlock(tmpNode))
  13412. ) {
  13413. domUtils.remove(tmpNode)
  13414. }
  13415. var rng = me.selection.getRange()
  13416. if (domUtils.isEmptyBlock(pre)) {
  13417. rng.setStart(pre, 0).setCursor(false, true)
  13418. } else {
  13419. rng.selectNodeContents(pre).select()
  13420. }
  13421. }
  13422. },
  13423. queryCommandValue: function () {
  13424. var path = this.selection.getStartElementPath()
  13425. var lang = ''
  13426. utils.each(path, function (node) {
  13427. if (node.nodeName == 'PRE') {
  13428. var match = node.className.match(/brush:([^;]+)/)
  13429. lang = match && match[1] ? match[1] : ''
  13430. return false
  13431. }
  13432. })
  13433. return lang
  13434. }
  13435. }
  13436. me.addInputRule(function (root) {
  13437. utils.each(root.getNodesByTagName('pre'), function (pre) {
  13438. var brs = pre.getNodesByTagName('br')
  13439. if (brs.length) {
  13440. browser.ie &&
  13441. browser.ie11below &&
  13442. browser.version > 8 &&
  13443. utils.each(brs, function (br) {
  13444. var txt = UE.uNode.createText('\n')
  13445. br.parentNode.insertBefore(txt, br)
  13446. br.parentNode.removeChild(br)
  13447. })
  13448. return
  13449. }
  13450. if (browser.ie && browser.ie11below && browser.version > 8) return
  13451. var code = pre.innerText().split(/\n/)
  13452. pre.innerHTML('')
  13453. utils.each(code, function (c) {
  13454. if (c.length) {
  13455. pre.appendChild(UE.uNode.createText(c))
  13456. }
  13457. pre.appendChild(UE.uNode.createElement('br'))
  13458. })
  13459. })
  13460. })
  13461. me.addOutputRule(function (root) {
  13462. utils.each(root.getNodesByTagName('pre'), function (pre) {
  13463. var code = ''
  13464. utils.each(pre.children, function (n) {
  13465. if (n.type == 'text') {
  13466. //在ie下文本内容有可能末尾带有\n要去掉
  13467. //trace:3396
  13468. code += n.data.replace(/[ ]/g, '&nbsp;').replace(/\n$/, '')
  13469. } else {
  13470. if (n.tagName == 'br') {
  13471. code += '\n'
  13472. } else {
  13473. code += !dtd.$empty[n.tagName] ? '' : n.innerText()
  13474. }
  13475. }
  13476. })
  13477. pre.innerText(code.replace(/(&nbsp;|\n)+$/, ''))
  13478. })
  13479. })
  13480. //不需要判断highlight的command列表
  13481. me.notNeedCodeQuery = {
  13482. help: 1,
  13483. undo: 1,
  13484. redo: 1,
  13485. source: 1,
  13486. print: 1,
  13487. searchreplace: 1,
  13488. fullscreen: 1,
  13489. preview: 1,
  13490. insertparagraph: 1,
  13491. elementpath: 1,
  13492. insertcode: 1,
  13493. inserthtml: 1,
  13494. selectall: 1
  13495. }
  13496. //将queyCommamndState重置
  13497. var orgQuery = me.queryCommandState
  13498. me.queryCommandState = function (cmd) {
  13499. var me = this
  13500. if (
  13501. !me.notNeedCodeQuery[cmd.toLowerCase()] &&
  13502. me.selection &&
  13503. me.queryCommandValue('insertcode')
  13504. ) {
  13505. return -1
  13506. }
  13507. return UE.Editor.prototype.queryCommandState.apply(this, arguments)
  13508. }
  13509. me.addListener('beforeenterkeydown', function () {
  13510. var rng = me.selection.getRange()
  13511. var pre = domUtils.findParentByTagName(rng.startContainer, 'pre', true)
  13512. if (pre) {
  13513. me.fireEvent('saveScene')
  13514. if (!rng.collapsed) {
  13515. rng.deleteContents()
  13516. }
  13517. if (!browser.ie || browser.ie9above) {
  13518. var tmpNode = me.document.createElement('br'),
  13519. pre
  13520. rng.insertNode(tmpNode).setStartAfter(tmpNode).collapse(true)
  13521. var next = tmpNode.nextSibling
  13522. if (!next && (!browser.ie || browser.version > 10)) {
  13523. rng.insertNode(tmpNode.cloneNode(false))
  13524. } else {
  13525. rng.setStartAfter(tmpNode)
  13526. }
  13527. pre = tmpNode.previousSibling
  13528. var tmp
  13529. while (pre) {
  13530. tmp = pre
  13531. pre = pre.previousSibling
  13532. if (!pre || pre.nodeName == 'BR') {
  13533. pre = tmp
  13534. break
  13535. }
  13536. }
  13537. if (pre) {
  13538. var str = ''
  13539. while (
  13540. pre &&
  13541. pre.nodeName != 'BR' &&
  13542. new RegExp('^[\\s' + domUtils.fillChar + ']*$').test(pre.nodeValue)
  13543. ) {
  13544. str += pre.nodeValue
  13545. pre = pre.nextSibling
  13546. }
  13547. if (pre.nodeName != 'BR') {
  13548. var match = pre.nodeValue.match(new RegExp('^([\\s' + domUtils.fillChar + ']+)'))
  13549. if (match && match[1]) {
  13550. str += match[1]
  13551. }
  13552. }
  13553. if (str) {
  13554. str = me.document.createTextNode(str)
  13555. rng.insertNode(str).setStartAfter(str)
  13556. }
  13557. }
  13558. rng.collapse(true).select(true)
  13559. } else {
  13560. if (browser.version > 8) {
  13561. var txt = me.document.createTextNode('\n')
  13562. var start = rng.startContainer
  13563. if (rng.startOffset == 0) {
  13564. var preNode = start.previousSibling
  13565. if (preNode) {
  13566. rng.insertNode(txt)
  13567. var fillchar = me.document.createTextNode(' ')
  13568. rng
  13569. .setStartAfter(txt)
  13570. .insertNode(fillchar)
  13571. .setStart(fillchar, 0)
  13572. .collapse(true)
  13573. .select(true)
  13574. }
  13575. } else {
  13576. rng.insertNode(txt).setStartAfter(txt)
  13577. var fillchar = me.document.createTextNode(' ')
  13578. start = rng.startContainer.childNodes[rng.startOffset]
  13579. if (start && !/^\n/.test(start.nodeValue)) {
  13580. rng.setStartBefore(txt)
  13581. }
  13582. rng.insertNode(fillchar).setStart(fillchar, 0).collapse(true).select(true)
  13583. }
  13584. } else {
  13585. var tmpNode = me.document.createElement('br')
  13586. rng.insertNode(tmpNode)
  13587. rng.insertNode(me.document.createTextNode(domUtils.fillChar))
  13588. rng.setStartAfter(tmpNode)
  13589. pre = tmpNode.previousSibling
  13590. var tmp
  13591. while (pre) {
  13592. tmp = pre
  13593. pre = pre.previousSibling
  13594. if (!pre || pre.nodeName == 'BR') {
  13595. pre = tmp
  13596. break
  13597. }
  13598. }
  13599. if (pre) {
  13600. var str = ''
  13601. while (
  13602. pre &&
  13603. pre.nodeName != 'BR' &&
  13604. new RegExp('^[ ' + domUtils.fillChar + ']*$').test(pre.nodeValue)
  13605. ) {
  13606. str += pre.nodeValue
  13607. pre = pre.nextSibling
  13608. }
  13609. if (pre.nodeName != 'BR') {
  13610. var match = pre.nodeValue.match(new RegExp('^([ ' + domUtils.fillChar + ']+)'))
  13611. if (match && match[1]) {
  13612. str += match[1]
  13613. }
  13614. }
  13615. str = me.document.createTextNode(str)
  13616. rng.insertNode(str).setStartAfter(str)
  13617. }
  13618. rng.collapse(true).select()
  13619. }
  13620. }
  13621. me.fireEvent('saveScene')
  13622. return true
  13623. }
  13624. })
  13625. me.addListener('tabkeydown', function (cmd, evt) {
  13626. var rng = me.selection.getRange()
  13627. var pre = domUtils.findParentByTagName(rng.startContainer, 'pre', true)
  13628. if (pre) {
  13629. me.fireEvent('saveScene')
  13630. if (evt.shiftKey) {
  13631. } else {
  13632. if (!rng.collapsed) {
  13633. var bk = rng.createBookmark()
  13634. var start = bk.start.previousSibling
  13635. while (start) {
  13636. if (pre.firstChild === start && !domUtils.isBr(start)) {
  13637. pre.insertBefore(me.document.createTextNode(' '), start)
  13638. break
  13639. }
  13640. if (domUtils.isBr(start)) {
  13641. pre.insertBefore(me.document.createTextNode(' '), start.nextSibling)
  13642. break
  13643. }
  13644. start = start.previousSibling
  13645. }
  13646. var end = bk.end
  13647. start = bk.start.nextSibling
  13648. if (pre.firstChild === bk.start) {
  13649. pre.insertBefore(me.document.createTextNode(' '), start.nextSibling)
  13650. }
  13651. while (start && start !== end) {
  13652. if (domUtils.isBr(start) && start.nextSibling) {
  13653. if (start.nextSibling === end) {
  13654. break
  13655. }
  13656. pre.insertBefore(me.document.createTextNode(' '), start.nextSibling)
  13657. }
  13658. start = start.nextSibling
  13659. }
  13660. rng.moveToBookmark(bk).select()
  13661. } else {
  13662. var tmpNode = me.document.createTextNode(' ')
  13663. rng.insertNode(tmpNode).setStartAfter(tmpNode).collapse(true).select(true)
  13664. }
  13665. }
  13666. me.fireEvent('saveScene')
  13667. return true
  13668. }
  13669. })
  13670. me.addListener('beforeinserthtml', function (evtName, html) {
  13671. var me = this,
  13672. rng = me.selection.getRange(),
  13673. pre = domUtils.findParentByTagName(rng.startContainer, 'pre', true)
  13674. if (pre) {
  13675. if (!rng.collapsed) {
  13676. rng.deleteContents()
  13677. }
  13678. var htmlstr = ''
  13679. if (browser.ie && browser.version > 8) {
  13680. utils.each(
  13681. UE.filterNode(UE.htmlparser(html), me.options.filterTxtRules).children,
  13682. function (node) {
  13683. if (node.type == 'element') {
  13684. if (node.tagName == 'br') {
  13685. htmlstr += '\n'
  13686. } else if (!dtd.$empty[node.tagName]) {
  13687. utils.each(node.children, function (cn) {
  13688. if (cn.type == 'element') {
  13689. if (cn.tagName == 'br') {
  13690. htmlstr += '\n'
  13691. } else if (!dtd.$empty[node.tagName]) {
  13692. htmlstr += cn.innerText()
  13693. }
  13694. } else {
  13695. htmlstr += cn.data
  13696. }
  13697. })
  13698. if (!/\n$/.test(htmlstr)) {
  13699. htmlstr += '\n'
  13700. }
  13701. }
  13702. } else {
  13703. htmlstr += node.data + '\n'
  13704. }
  13705. if (!node.nextSibling() && /\n$/.test(htmlstr)) {
  13706. htmlstr = htmlstr.replace(/\n$/, '')
  13707. }
  13708. }
  13709. )
  13710. var tmpNode = me.document.createTextNode(utils.html(htmlstr.replace(/&nbsp;/g, ' ')))
  13711. rng.insertNode(tmpNode).selectNode(tmpNode).select()
  13712. } else {
  13713. var frag = me.document.createDocumentFragment()
  13714. utils.each(
  13715. UE.filterNode(UE.htmlparser(html), me.options.filterTxtRules).children,
  13716. function (node) {
  13717. if (node.type == 'element') {
  13718. if (node.tagName == 'br') {
  13719. frag.appendChild(me.document.createElement('br'))
  13720. } else if (!dtd.$empty[node.tagName]) {
  13721. utils.each(node.children, function (cn) {
  13722. if (cn.type == 'element') {
  13723. if (cn.tagName == 'br') {
  13724. frag.appendChild(me.document.createElement('br'))
  13725. } else if (!dtd.$empty[node.tagName]) {
  13726. frag.appendChild(
  13727. me.document.createTextNode(
  13728. utils.html(cn.innerText().replace(/&nbsp;/g, ' '))
  13729. )
  13730. )
  13731. }
  13732. } else {
  13733. frag.appendChild(
  13734. me.document.createTextNode(utils.html(cn.data.replace(/&nbsp;/g, ' ')))
  13735. )
  13736. }
  13737. })
  13738. if (frag.lastChild.nodeName != 'BR') {
  13739. frag.appendChild(me.document.createElement('br'))
  13740. }
  13741. }
  13742. } else {
  13743. frag.appendChild(
  13744. me.document.createTextNode(utils.html(node.data.replace(/&nbsp;/g, ' ')))
  13745. )
  13746. }
  13747. if (!node.nextSibling() && frag.lastChild.nodeName == 'BR') {
  13748. frag.removeChild(frag.lastChild)
  13749. }
  13750. }
  13751. )
  13752. rng.insertNode(frag).select()
  13753. }
  13754. return true
  13755. }
  13756. })
  13757. //方向键的处理
  13758. me.addListener('keydown', function (cmd, evt) {
  13759. var me = this,
  13760. keyCode = evt.keyCode || evt.which
  13761. if (keyCode == 40) {
  13762. var rng = me.selection.getRange(),
  13763. pre,
  13764. start = rng.startContainer
  13765. if (
  13766. rng.collapsed &&
  13767. (pre = domUtils.findParentByTagName(rng.startContainer, 'pre', true)) &&
  13768. !pre.nextSibling
  13769. ) {
  13770. var last = pre.lastChild
  13771. while (last && last.nodeName == 'BR') {
  13772. last = last.previousSibling
  13773. }
  13774. if (
  13775. last === start ||
  13776. (rng.startContainer === pre && rng.startOffset == pre.childNodes.length)
  13777. ) {
  13778. me.execCommand('insertparagraph')
  13779. domUtils.preventDefault(evt)
  13780. }
  13781. }
  13782. }
  13783. })
  13784. //trace:3395
  13785. me.addListener('delkeydown', function (type, evt) {
  13786. var rng = this.selection.getRange()
  13787. rng.txtToElmBoundary(true)
  13788. var start = rng.startContainer
  13789. if (domUtils.isTagNode(start, 'pre') && rng.collapsed && domUtils.isStartInblock(rng)) {
  13790. var p = me.document.createElement('p')
  13791. domUtils.fillNode(me.document, p)
  13792. start.parentNode.insertBefore(p, start)
  13793. domUtils.remove(start)
  13794. rng.setStart(p, 0).setCursor(false, true)
  13795. domUtils.preventDefault(evt)
  13796. return true
  13797. }
  13798. })
  13799. }
  13800. // plugins/cleardoc.js
  13801. /**
  13802. * 清空文档插件
  13803. * @file
  13804. * @since 1.2.6.1
  13805. */
  13806. /**
  13807. * 清空文档
  13808. * @command cleardoc
  13809. * @method execCommand
  13810. * @param { String } cmd 命令字符串
  13811. * @example
  13812. * ```javascript
  13813. * //editor 是编辑器实例
  13814. * editor.execCommand('cleardoc');
  13815. * ```
  13816. */
  13817. UE.commands['cleardoc'] = {
  13818. execCommand: function (cmdName) {
  13819. var me = this,
  13820. enterTag = me.options.enterTag,
  13821. range = me.selection.getRange()
  13822. if (enterTag == 'br') {
  13823. me.body.innerHTML = '<br/>'
  13824. range.setStart(me.body, 0).setCursor()
  13825. } else {
  13826. me.body.innerHTML = '<p>' + (ie ? '' : '<br/>') + '</p>'
  13827. range.setStart(me.body.firstChild, 0).setCursor(false, true)
  13828. }
  13829. setTimeout(function () {
  13830. me.fireEvent('clearDoc')
  13831. }, 0)
  13832. }
  13833. }
  13834. // plugins/anchor.js
  13835. /**
  13836. * 锚点插件,为UEditor提供插入锚点支持
  13837. * @file
  13838. * @since 1.2.6.1
  13839. */
  13840. UE.plugin.register('anchor', function () {
  13841. return {
  13842. bindEvents: {
  13843. ready: function () {
  13844. utils.cssRule(
  13845. 'anchor',
  13846. ".anchorclass{background: url('" +
  13847. this.options.themePath +
  13848. this.options.theme +
  13849. "/images/anchor.gif') no-repeat scroll left center transparent;cursor: auto;display: inline-block;height: 16px;width: 15px;}",
  13850. this.document
  13851. )
  13852. }
  13853. },
  13854. outputRule: function (root) {
  13855. utils.each(root.getNodesByTagName('img'), function (a) {
  13856. var val
  13857. if ((val = a.getAttr('anchorname'))) {
  13858. a.tagName = 'a'
  13859. a.setAttr({
  13860. anchorname: '',
  13861. name: val,
  13862. class: ''
  13863. })
  13864. }
  13865. })
  13866. },
  13867. inputRule: function (root) {
  13868. utils.each(root.getNodesByTagName('a'), function (a) {
  13869. var val
  13870. if ((val = a.getAttr('name')) && !a.getAttr('href')) {
  13871. a.tagName = 'img'
  13872. a.setAttr({
  13873. anchorname: a.getAttr('name'),
  13874. class: 'anchorclass'
  13875. })
  13876. a.setAttr('name')
  13877. }
  13878. })
  13879. },
  13880. commands: {
  13881. /**
  13882. * 插入锚点
  13883. * @command anchor
  13884. * @method execCommand
  13885. * @param { String } cmd 命令字符串
  13886. * @param { String } name 锚点名称字符串
  13887. * @example
  13888. * ```javascript
  13889. * //editor 是编辑器实例
  13890. * editor.execCommand('anchor', 'anchor1');
  13891. * ```
  13892. */
  13893. anchor: {
  13894. execCommand: function (cmd, name) {
  13895. var range = this.selection.getRange(),
  13896. img = range.getClosedNode()
  13897. if (img && img.getAttribute('anchorname')) {
  13898. if (name) {
  13899. img.setAttribute('anchorname', name)
  13900. } else {
  13901. range.setStartBefore(img).setCursor()
  13902. domUtils.remove(img)
  13903. }
  13904. } else {
  13905. if (name) {
  13906. //只在选区的开始插入
  13907. var anchor = this.document.createElement('img')
  13908. range.collapse(true)
  13909. domUtils.setAttributes(anchor, {
  13910. anchorname: name,
  13911. class: 'anchorclass'
  13912. })
  13913. range.insertNode(anchor).setStartAfter(anchor).setCursor(false, true)
  13914. }
  13915. }
  13916. }
  13917. }
  13918. }
  13919. }
  13920. })
  13921. // plugins/wordcount.js
  13922. ///import core
  13923. ///commands 字数统计
  13924. ///commandsName WordCount,wordCount
  13925. ///commandsTitle 字数统计
  13926. /*
  13927. * Created by JetBrains WebStorm.
  13928. * User: taoqili
  13929. * Date: 11-9-7
  13930. * Time: 下午8:18
  13931. * To change this template use File | Settings | File Templates.
  13932. */
  13933. UE.plugins['wordcount'] = function () {
  13934. var me = this
  13935. me.setOpt('wordCount', true)
  13936. me.addListener('contentchange', function () {
  13937. me.fireEvent('wordcount')
  13938. })
  13939. var timer
  13940. me.addListener('ready', function () {
  13941. var me = this
  13942. domUtils.on(me.body, 'keyup', function (evt) {
  13943. var code = evt.keyCode || evt.which,
  13944. //忽略的按键,ctr,alt,shift,方向键
  13945. ignores = { 16: 1, 18: 1, 20: 1, 37: 1, 38: 1, 39: 1, 40: 1 }
  13946. if (code in ignores) return
  13947. clearTimeout(timer)
  13948. timer = setTimeout(function () {
  13949. me.fireEvent('wordcount')
  13950. }, 200)
  13951. })
  13952. })
  13953. }
  13954. // plugins/pagebreak.js
  13955. /**
  13956. * 分页功能插件
  13957. * @file
  13958. * @since 1.2.6.1
  13959. */
  13960. UE.plugins['pagebreak'] = function () {
  13961. var me = this,
  13962. notBreakTags = ['td']
  13963. me.setOpt('pageBreakTag', '_ueditor_page_break_tag_')
  13964. function fillNode(node) {
  13965. if (domUtils.isEmptyBlock(node)) {
  13966. var firstChild = node.firstChild,
  13967. tmpNode
  13968. while (firstChild && firstChild.nodeType == 1 && domUtils.isEmptyBlock(firstChild)) {
  13969. tmpNode = firstChild
  13970. firstChild = firstChild.firstChild
  13971. }
  13972. !tmpNode && (tmpNode = node)
  13973. domUtils.fillNode(me.document, tmpNode)
  13974. }
  13975. }
  13976. //分页符样式添加
  13977. me.ready(function () {
  13978. utils.cssRule(
  13979. 'pagebreak',
  13980. '.pagebreak{display:block;clear:both !important;cursor:default !important;width: 100% !important;margin:0;}',
  13981. me.document
  13982. )
  13983. })
  13984. function isHr(node) {
  13985. return node && node.nodeType == 1 && node.tagName == 'HR' && node.className == 'pagebreak'
  13986. }
  13987. me.addInputRule(function (root) {
  13988. root.traversal(function (node) {
  13989. if (node.type == 'text' && node.data == me.options.pageBreakTag) {
  13990. var hr = UE.uNode.createElement(
  13991. '<hr class="pagebreak" noshade="noshade" size="5" style="-webkit-user-select: none;">'
  13992. )
  13993. node.parentNode.insertBefore(hr, node)
  13994. node.parentNode.removeChild(node)
  13995. }
  13996. })
  13997. })
  13998. me.addOutputRule(function (node) {
  13999. utils.each(node.getNodesByTagName('hr'), function (n) {
  14000. if (n.getAttr('class') == 'pagebreak') {
  14001. var txt = UE.uNode.createText(me.options.pageBreakTag)
  14002. n.parentNode.insertBefore(txt, n)
  14003. n.parentNode.removeChild(n)
  14004. }
  14005. })
  14006. })
  14007. /**
  14008. * 插入分页符
  14009. * @command pagebreak
  14010. * @method execCommand
  14011. * @param { String } cmd 命令字符串
  14012. * @remind 在表格中插入分页符会把表格切分成两部分
  14013. * @remind 获取编辑器内的数据时, 编辑器会把分页符转换成“_ueditor_page_break_tag_”字符串,
  14014. * 以便于提交数据到服务器端后处理分页。
  14015. * @example
  14016. * ```javascript
  14017. * editor.execCommand( 'pagebreak'); //插入一个hr标签,带有样式类名pagebreak
  14018. * ```
  14019. */
  14020. me.commands['pagebreak'] = {
  14021. execCommand: function () {
  14022. var range = me.selection.getRange(),
  14023. hr = me.document.createElement('hr')
  14024. domUtils.setAttributes(hr, {
  14025. class: 'pagebreak',
  14026. noshade: 'noshade',
  14027. size: '5'
  14028. })
  14029. domUtils.unSelectable(hr)
  14030. //table单独处理
  14031. var node = domUtils.findParentByTagName(range.startContainer, notBreakTags, true),
  14032. parents = [],
  14033. pN
  14034. if (node) {
  14035. switch (node.tagName) {
  14036. case 'TD':
  14037. pN = node.parentNode
  14038. if (!pN.previousSibling) {
  14039. var table = domUtils.findParentByTagName(pN, 'table')
  14040. // var tableWrapDiv = table.parentNode;
  14041. // if(tableWrapDiv && tableWrapDiv.nodeType == 1
  14042. // && tableWrapDiv.tagName == 'DIV'
  14043. // && tableWrapDiv.getAttribute('dropdrag')
  14044. // ){
  14045. // domUtils.remove(tableWrapDiv,true);
  14046. // }
  14047. table.parentNode.insertBefore(hr, table)
  14048. parents = domUtils.findParents(hr, true)
  14049. } else {
  14050. pN.parentNode.insertBefore(hr, pN)
  14051. parents = domUtils.findParents(hr)
  14052. }
  14053. pN = parents[1]
  14054. if (hr !== pN) {
  14055. domUtils.breakParent(hr, pN)
  14056. }
  14057. //table要重写绑定一下拖拽
  14058. me.fireEvent('afteradjusttable', me.document)
  14059. }
  14060. } else {
  14061. if (!range.collapsed) {
  14062. range.deleteContents()
  14063. var start = range.startContainer
  14064. while (
  14065. !domUtils.isBody(start) &&
  14066. domUtils.isBlockElm(start) &&
  14067. domUtils.isEmptyNode(start)
  14068. ) {
  14069. range.setStartBefore(start).collapse(true)
  14070. domUtils.remove(start)
  14071. start = range.startContainer
  14072. }
  14073. }
  14074. range.insertNode(hr)
  14075. var pN = hr.parentNode,
  14076. nextNode
  14077. while (!domUtils.isBody(pN)) {
  14078. domUtils.breakParent(hr, pN)
  14079. nextNode = hr.nextSibling
  14080. if (nextNode && domUtils.isEmptyBlock(nextNode)) {
  14081. domUtils.remove(nextNode)
  14082. }
  14083. pN = hr.parentNode
  14084. }
  14085. nextNode = hr.nextSibling
  14086. var pre = hr.previousSibling
  14087. if (isHr(pre)) {
  14088. domUtils.remove(pre)
  14089. } else {
  14090. pre && fillNode(pre)
  14091. }
  14092. if (!nextNode) {
  14093. var p = me.document.createElement('p')
  14094. hr.parentNode.appendChild(p)
  14095. domUtils.fillNode(me.document, p)
  14096. range.setStart(p, 0).collapse(true)
  14097. } else {
  14098. if (isHr(nextNode)) {
  14099. domUtils.remove(nextNode)
  14100. } else {
  14101. fillNode(nextNode)
  14102. }
  14103. range.setEndAfter(hr).collapse(false)
  14104. }
  14105. range.select(true)
  14106. }
  14107. }
  14108. }
  14109. }
  14110. // plugins/wordimage.js
  14111. ///import core
  14112. ///commands 本地图片引导上传
  14113. ///commandsName WordImage
  14114. ///commandsTitle 本地图片引导上传
  14115. ///commandsDialog dialogs\wordimage
  14116. UE.plugin.register('wordimage', function () {
  14117. var me = this,
  14118. images = []
  14119. return {
  14120. commands: {
  14121. wordimage: {
  14122. execCommand: function () {
  14123. var images = domUtils.getElementsByTagName(me.body, 'img')
  14124. var urlList = []
  14125. for (var i = 0, ci; (ci = images[i++]); ) {
  14126. var url = ci.getAttribute('word_img')
  14127. url && urlList.push(url)
  14128. }
  14129. return urlList
  14130. },
  14131. queryCommandState: function () {
  14132. images = domUtils.getElementsByTagName(me.body, 'img')
  14133. for (var i = 0, ci; (ci = images[i++]); ) {
  14134. if (ci.getAttribute('word_img')) {
  14135. return 1
  14136. }
  14137. }
  14138. return -1
  14139. },
  14140. notNeedUndo: true
  14141. }
  14142. },
  14143. inputRule: function (root) {
  14144. utils.each(root.getNodesByTagName('img'), function (img) {
  14145. var attrs = img.attrs,
  14146. flag = parseInt(attrs.width) < 128 || parseInt(attrs.height) < 43,
  14147. opt = me.options,
  14148. src = opt.UEDITOR_HOME_URL + 'themes/default/images/spacer.gif'
  14149. if (attrs['src'] && /^(?:(file:\/+))/.test(attrs['src'])) {
  14150. img.setAttr({
  14151. width: attrs.width,
  14152. height: attrs.height,
  14153. alt: attrs.alt,
  14154. word_img: attrs.src,
  14155. src: src,
  14156. style:
  14157. 'background:url(' +
  14158. (flag
  14159. ? opt.themePath + opt.theme + '/images/word.gif'
  14160. : opt.langPath + opt.lang + '/images/localimage.png') +
  14161. ') no-repeat center center;border:1px solid #ddd'
  14162. })
  14163. }
  14164. })
  14165. }
  14166. }
  14167. })
  14168. // plugins/dragdrop.js
  14169. UE.plugins['dragdrop'] = function () {
  14170. var me = this
  14171. me.ready(function () {
  14172. domUtils.on(this.body, 'dragend', function () {
  14173. var rng = me.selection.getRange()
  14174. var node = rng.getClosedNode() || me.selection.getStart()
  14175. if (node && node.tagName == 'IMG') {
  14176. var pre = node.previousSibling,
  14177. next
  14178. while ((next = node.nextSibling)) {
  14179. if (next.nodeType == 1 && next.tagName == 'SPAN' && !next.firstChild) {
  14180. domUtils.remove(next)
  14181. } else {
  14182. break
  14183. }
  14184. }
  14185. if (
  14186. ((pre && pre.nodeType == 1 && !domUtils.isEmptyBlock(pre)) || !pre) &&
  14187. (!next || (next && !domUtils.isEmptyBlock(next)))
  14188. ) {
  14189. if (pre && pre.tagName == 'P' && !domUtils.isEmptyBlock(pre)) {
  14190. pre.appendChild(node)
  14191. domUtils.moveChild(next, pre)
  14192. domUtils.remove(next)
  14193. } else if (next && next.tagName == 'P' && !domUtils.isEmptyBlock(next)) {
  14194. next.insertBefore(node, next.firstChild)
  14195. }
  14196. if (pre && pre.tagName == 'P' && domUtils.isEmptyBlock(pre)) {
  14197. domUtils.remove(pre)
  14198. }
  14199. if (next && next.tagName == 'P' && domUtils.isEmptyBlock(next)) {
  14200. domUtils.remove(next)
  14201. }
  14202. rng.selectNode(node).select()
  14203. me.fireEvent('saveScene')
  14204. }
  14205. }
  14206. })
  14207. })
  14208. me.addListener('keyup', function (type, evt) {
  14209. var keyCode = evt.keyCode || evt.which
  14210. if (keyCode == 13) {
  14211. var rng = me.selection.getRange(),
  14212. node
  14213. if ((node = domUtils.findParentByTagName(rng.startContainer, 'p', true))) {
  14214. if (domUtils.getComputedStyle(node, 'text-align') == 'center') {
  14215. domUtils.removeStyle(node, 'text-align')
  14216. }
  14217. }
  14218. }
  14219. })
  14220. }
  14221. // plugins/undo.js
  14222. /**
  14223. * undo redo
  14224. * @file
  14225. * @since 1.2.6.1
  14226. */
  14227. /**
  14228. * 撤销上一次执行的命令
  14229. * @command undo
  14230. * @method execCommand
  14231. * @param { String } cmd 命令字符串
  14232. * @example
  14233. * ```javascript
  14234. * editor.execCommand( 'undo' );
  14235. * ```
  14236. */
  14237. /**
  14238. * 重做上一次执行的命令
  14239. * @command redo
  14240. * @method execCommand
  14241. * @param { String } cmd 命令字符串
  14242. * @example
  14243. * ```javascript
  14244. * editor.execCommand( 'redo' );
  14245. * ```
  14246. */
  14247. UE.plugins['undo'] = function () {
  14248. var saveSceneTimer
  14249. var me = this,
  14250. maxUndoCount = me.options.maxUndoCount || 20,
  14251. maxInputCount = me.options.maxInputCount || 20,
  14252. fillchar = new RegExp(domUtils.fillChar + '|</hr>', 'gi') // ie会产生多余的</hr>
  14253. var noNeedFillCharTags = {
  14254. ol: 1,
  14255. ul: 1,
  14256. table: 1,
  14257. tbody: 1,
  14258. tr: 1,
  14259. body: 1
  14260. }
  14261. var orgState = me.options.autoClearEmptyNode
  14262. function compareAddr(indexA, indexB) {
  14263. if (indexA.length != indexB.length) return 0
  14264. for (var i = 0, l = indexA.length; i < l; i++) {
  14265. if (indexA[i] != indexB[i]) return 0
  14266. }
  14267. return 1
  14268. }
  14269. function compareRangeAddress(rngAddrA, rngAddrB) {
  14270. if (rngAddrA.collapsed != rngAddrB.collapsed) {
  14271. return 0
  14272. }
  14273. if (
  14274. !compareAddr(rngAddrA.startAddress, rngAddrB.startAddress) ||
  14275. !compareAddr(rngAddrA.endAddress, rngAddrB.endAddress)
  14276. ) {
  14277. return 0
  14278. }
  14279. return 1
  14280. }
  14281. function UndoManager() {
  14282. this.list = []
  14283. this.index = 0
  14284. this.hasUndo = false
  14285. this.hasRedo = false
  14286. this.undo = function () {
  14287. if (this.hasUndo) {
  14288. if (!this.list[this.index - 1] && this.list.length == 1) {
  14289. this.reset()
  14290. return
  14291. }
  14292. while (this.list[this.index].content == this.list[this.index - 1].content) {
  14293. this.index--
  14294. if (this.index == 0) {
  14295. return this.restore(0)
  14296. }
  14297. }
  14298. this.restore(--this.index)
  14299. }
  14300. }
  14301. this.redo = function () {
  14302. if (this.hasRedo) {
  14303. while (this.list[this.index].content == this.list[this.index + 1].content) {
  14304. this.index++
  14305. if (this.index == this.list.length - 1) {
  14306. return this.restore(this.index)
  14307. }
  14308. }
  14309. this.restore(++this.index)
  14310. }
  14311. }
  14312. this.restore = function () {
  14313. var me = this.editor
  14314. var scene = this.list[this.index]
  14315. var root = UE.htmlparser(scene.content.replace(fillchar, ''))
  14316. me.options.autoClearEmptyNode = false
  14317. me.filterInputRule(root)
  14318. me.options.autoClearEmptyNode = orgState
  14319. //trace:873
  14320. //去掉展位符
  14321. me.document.body.innerHTML = root.toHtml()
  14322. me.fireEvent('afterscencerestore')
  14323. //处理undo后空格不展位的问题
  14324. if (browser.ie) {
  14325. utils.each(
  14326. domUtils.getElementsByTagName(me.document, 'td th caption p'),
  14327. function (node) {
  14328. if (domUtils.isEmptyNode(node)) {
  14329. domUtils.fillNode(me.document, node)
  14330. }
  14331. }
  14332. )
  14333. }
  14334. try {
  14335. var rng = new dom.Range(me.document).moveToAddress(scene.address)
  14336. rng.select(noNeedFillCharTags[rng.startContainer.nodeName.toLowerCase()])
  14337. } catch (e) {}
  14338. this.update()
  14339. this.clearKey()
  14340. //不能把自己reset了
  14341. me.fireEvent('reset', true)
  14342. }
  14343. this.getScene = function () {
  14344. var me = this.editor
  14345. var rng = me.selection.getRange(),
  14346. rngAddress = rng.createAddress(false, true)
  14347. me.fireEvent('beforegetscene')
  14348. var root = UE.htmlparser(me.body.innerHTML)
  14349. me.options.autoClearEmptyNode = false
  14350. me.filterOutputRule(root)
  14351. me.options.autoClearEmptyNode = orgState
  14352. var cont = root.toHtml()
  14353. //trace:3461
  14354. //这个会引起回退时导致空格丢失的情况
  14355. // browser.ie && (cont = cont.replace(/>&nbsp;</g, '><').replace(/\s*</g, '<').replace(/>\s*/g, '>'));
  14356. me.fireEvent('aftergetscene')
  14357. return {
  14358. address: rngAddress,
  14359. content: cont
  14360. }
  14361. }
  14362. this.save = function (notCompareRange, notSetCursor) {
  14363. clearTimeout(saveSceneTimer)
  14364. var currentScene = this.getScene(notSetCursor),
  14365. lastScene = this.list[this.index]
  14366. if (lastScene && lastScene.content != currentScene.content) {
  14367. me.trigger('contentchange')
  14368. }
  14369. //内容相同位置相同不存
  14370. if (
  14371. lastScene &&
  14372. lastScene.content == currentScene.content &&
  14373. (notCompareRange ? 1 : compareRangeAddress(lastScene.address, currentScene.address))
  14374. ) {
  14375. return
  14376. }
  14377. this.list = this.list.slice(0, this.index + 1)
  14378. this.list.push(currentScene)
  14379. //如果大于最大数量了,就把最前的剔除
  14380. if (this.list.length > maxUndoCount) {
  14381. this.list.shift()
  14382. }
  14383. this.index = this.list.length - 1
  14384. this.clearKey()
  14385. //跟新undo/redo状态
  14386. this.update()
  14387. }
  14388. this.update = function () {
  14389. this.hasRedo = !!this.list[this.index + 1]
  14390. this.hasUndo = !!this.list[this.index - 1]
  14391. }
  14392. this.reset = function () {
  14393. this.list = []
  14394. this.index = 0
  14395. this.hasUndo = false
  14396. this.hasRedo = false
  14397. this.clearKey()
  14398. }
  14399. this.clearKey = function () {
  14400. keycont = 0
  14401. lastKeyCode = null
  14402. }
  14403. }
  14404. me.undoManger = new UndoManager()
  14405. me.undoManger.editor = me
  14406. function saveScene() {
  14407. this.undoManger.save()
  14408. }
  14409. me.addListener('saveScene', function () {
  14410. var args = Array.prototype.splice.call(arguments, 1)
  14411. this.undoManger.save.apply(this.undoManger, args)
  14412. })
  14413. // me.addListener('beforeexeccommand', saveScene);
  14414. // me.addListener('afterexeccommand', saveScene);
  14415. me.addListener('reset', function (type, exclude) {
  14416. if (!exclude) {
  14417. this.undoManger.reset()
  14418. }
  14419. })
  14420. me.commands['redo'] = me.commands['undo'] = {
  14421. execCommand: function (cmdName) {
  14422. this.undoManger[cmdName]()
  14423. },
  14424. queryCommandState: function (cmdName) {
  14425. return this.undoManger['has' + (cmdName.toLowerCase() == 'undo' ? 'Undo' : 'Redo')] ? 0 : -1
  14426. },
  14427. notNeedUndo: 1
  14428. }
  14429. var keys = {
  14430. // /*Backspace*/ 8:1, /*Delete*/ 46:1,
  14431. /*Shift*/ 16: 1,
  14432. /*Ctrl*/ 17: 1,
  14433. /*Alt*/ 18: 1,
  14434. 37: 1,
  14435. 38: 1,
  14436. 39: 1,
  14437. 40: 1
  14438. },
  14439. keycont = 0,
  14440. lastKeyCode
  14441. //输入法状态下不计算字符数
  14442. var inputType = false
  14443. me.addListener('ready', function () {
  14444. domUtils.on(this.body, 'compositionstart', function () {
  14445. inputType = true
  14446. })
  14447. domUtils.on(this.body, 'compositionend', function () {
  14448. inputType = false
  14449. })
  14450. })
  14451. //快捷键
  14452. me.addshortcutkey({
  14453. Undo: 'ctrl+90', //undo
  14454. Redo: 'ctrl+89' //redo
  14455. })
  14456. var isCollapsed = true
  14457. me.addListener('keydown', function (type, evt) {
  14458. var me = this
  14459. var keyCode = evt.keyCode || evt.which
  14460. if (!keys[keyCode] && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey) {
  14461. if (inputType) return
  14462. if (!me.selection.getRange().collapsed) {
  14463. me.undoManger.save(false, true)
  14464. isCollapsed = false
  14465. return
  14466. }
  14467. if (me.undoManger.list.length == 0) {
  14468. me.undoManger.save(true)
  14469. }
  14470. clearTimeout(saveSceneTimer)
  14471. function save(cont) {
  14472. cont.undoManger.save(false, true)
  14473. cont.fireEvent('selectionchange')
  14474. }
  14475. saveSceneTimer = setTimeout(function () {
  14476. if (inputType) {
  14477. var interalTimer = setInterval(function () {
  14478. if (!inputType) {
  14479. save(me)
  14480. clearInterval(interalTimer)
  14481. }
  14482. }, 300)
  14483. return
  14484. }
  14485. save(me)
  14486. }, 200)
  14487. lastKeyCode = keyCode
  14488. keycont++
  14489. if (keycont >= maxInputCount) {
  14490. save(me)
  14491. }
  14492. }
  14493. })
  14494. me.addListener('keyup', function (type, evt) {
  14495. var keyCode = evt.keyCode || evt.which
  14496. if (!keys[keyCode] && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey) {
  14497. if (inputType) return
  14498. if (!isCollapsed) {
  14499. this.undoManger.save(false, true)
  14500. isCollapsed = true
  14501. }
  14502. }
  14503. })
  14504. //扩展实例,添加关闭和开启命令undo
  14505. me.stopCmdUndo = function () {
  14506. me.__hasEnterExecCommand = true
  14507. }
  14508. me.startCmdUndo = function () {
  14509. me.__hasEnterExecCommand = false
  14510. }
  14511. }
  14512. // plugins/copy.js
  14513. UE.plugin.register('copy', function () {
  14514. var me = this
  14515. function initZeroClipboard() {
  14516. ZeroClipboard.config({
  14517. debug: false,
  14518. swfPath: me.options.UEDITOR_HOME_URL + 'third-party/zeroclipboard/ZeroClipboard.swf'
  14519. })
  14520. var client = (me.zeroclipboard = new ZeroClipboard())
  14521. // 复制内容
  14522. client.on('copy', function (e) {
  14523. var client = e.client,
  14524. rng = me.selection.getRange(),
  14525. div = document.createElement('div')
  14526. div.appendChild(rng.cloneContents())
  14527. client.setText(div.innerText || div.textContent)
  14528. client.setHtml(div.innerHTML)
  14529. rng.select()
  14530. })
  14531. // hover事件传递到target
  14532. client.on('mouseover mouseout', function (e) {
  14533. var target = e.target
  14534. if (e.type == 'mouseover') {
  14535. domUtils.addClass(target, 'edui-state-hover')
  14536. } else if (e.type == 'mouseout') {
  14537. domUtils.removeClasses(target, 'edui-state-hover')
  14538. }
  14539. })
  14540. // flash加载不成功
  14541. client.on('wrongflash noflash', function () {
  14542. ZeroClipboard.destroy()
  14543. })
  14544. }
  14545. return {
  14546. bindEvents: {
  14547. ready: function () {
  14548. if (!browser.ie) {
  14549. if (window.ZeroClipboard) {
  14550. initZeroClipboard()
  14551. } else {
  14552. utils.loadFile(
  14553. document,
  14554. {
  14555. src: me.options.UEDITOR_HOME_URL + 'third-party/zeroclipboard/ZeroClipboard.js',
  14556. tag: 'script',
  14557. type: 'text/javascript',
  14558. defer: 'defer'
  14559. },
  14560. function () {
  14561. initZeroClipboard()
  14562. }
  14563. )
  14564. }
  14565. }
  14566. }
  14567. },
  14568. commands: {
  14569. copy: {
  14570. execCommand: function (cmd) {
  14571. if (!me.document.execCommand('copy')) {
  14572. alert(me.getLang('copymsg'))
  14573. }
  14574. }
  14575. }
  14576. }
  14577. }
  14578. })
  14579. // plugins/paste.js
  14580. ///import core
  14581. ///import plugins/inserthtml.js
  14582. ///import plugins/undo.js
  14583. ///import plugins/serialize.js
  14584. ///commands 粘贴
  14585. ///commandsName PastePlain
  14586. ///commandsTitle 纯文本粘贴模式
  14587. /**
  14588. * @description 粘贴
  14589. * @author zhanyi
  14590. */
  14591. UE.plugins['paste'] = function () {
  14592. function getClipboardData(callback) {
  14593. var doc = this.document
  14594. if (doc.getElementById('baidu_pastebin')) {
  14595. return
  14596. }
  14597. var range = this.selection.getRange(),
  14598. bk = range.createBookmark(),
  14599. //创建剪贴的容器div
  14600. pastebin = doc.createElement('div')
  14601. pastebin.id = 'baidu_pastebin'
  14602. // Safari 要求div必须有内容,才能粘贴内容进来
  14603. browser.webkit &&
  14604. pastebin.appendChild(doc.createTextNode(domUtils.fillChar + domUtils.fillChar))
  14605. doc.body.appendChild(pastebin)
  14606. //trace:717 隐藏的span不能得到top
  14607. //bk.start.innerHTML = '&nbsp;';
  14608. bk.start.style.display = ''
  14609. pastebin.style.cssText =
  14610. 'position:absolute;width:1px;height:1px;overflow:hidden;left:-1000px;white-space:nowrap;top:' +
  14611. //要在现在光标平行的位置加入,否则会出现跳动的问题
  14612. domUtils.getXY(bk.start).y +
  14613. 'px'
  14614. range.selectNodeContents(pastebin).select(true)
  14615. setTimeout(function () {
  14616. if (browser.webkit) {
  14617. for (
  14618. var i = 0, pastebins = doc.querySelectorAll('#baidu_pastebin'), pi;
  14619. (pi = pastebins[i++]);
  14620. ) {
  14621. if (domUtils.isEmptyNode(pi)) {
  14622. domUtils.remove(pi)
  14623. } else {
  14624. pastebin = pi
  14625. break
  14626. }
  14627. }
  14628. }
  14629. try {
  14630. pastebin.parentNode.removeChild(pastebin)
  14631. } catch (e) {}
  14632. range.moveToBookmark(bk).select(true)
  14633. callback(pastebin)
  14634. }, 0)
  14635. }
  14636. var me = this
  14637. me.setOpt({
  14638. retainOnlyLabelPasted: false
  14639. })
  14640. var txtContent, htmlContent, address
  14641. function getPureHtml(html) {
  14642. return html.replace(/<(\/?)([\w\-]+)([^>]*)>/gi, function (a, b, tagName, attrs) {
  14643. tagName = tagName.toLowerCase()
  14644. if ({ img: 1 }[tagName]) {
  14645. return a
  14646. }
  14647. attrs = attrs.replace(
  14648. /([\w\-]*?)\s*=\s*(("([^"]*)")|('([^']*)')|([^\s>]+))/gi,
  14649. function (str, atr, val) {
  14650. if (
  14651. {
  14652. src: 1,
  14653. href: 1,
  14654. name: 1
  14655. }[atr.toLowerCase()]
  14656. ) {
  14657. return atr + '=' + val + ' '
  14658. }
  14659. return ''
  14660. }
  14661. )
  14662. if (
  14663. {
  14664. span: 1,
  14665. div: 1
  14666. }[tagName]
  14667. ) {
  14668. return ''
  14669. } else {
  14670. return '<' + b + tagName + ' ' + utils.trim(attrs) + '>'
  14671. }
  14672. })
  14673. }
  14674. function filter(div) {
  14675. var html
  14676. if (div.firstChild) {
  14677. //去掉cut中添加的边界值
  14678. var nodes = domUtils.getElementsByTagName(div, 'span')
  14679. for (var i = 0, ni; (ni = nodes[i++]); ) {
  14680. if (ni.id == '_baidu_cut_start' || ni.id == '_baidu_cut_end') {
  14681. domUtils.remove(ni)
  14682. }
  14683. }
  14684. if (browser.webkit) {
  14685. var brs = div.querySelectorAll('div br')
  14686. for (var i = 0, bi; (bi = brs[i++]); ) {
  14687. var pN = bi.parentNode
  14688. if (pN.tagName == 'DIV' && pN.childNodes.length == 1) {
  14689. pN.innerHTML = '<p><br/></p>'
  14690. domUtils.remove(pN)
  14691. }
  14692. }
  14693. var divs = div.querySelectorAll('#baidu_pastebin')
  14694. for (var i = 0, di; (di = divs[i++]); ) {
  14695. var tmpP = me.document.createElement('p')
  14696. di.parentNode.insertBefore(tmpP, di)
  14697. while (di.firstChild) {
  14698. tmpP.appendChild(di.firstChild)
  14699. }
  14700. domUtils.remove(di)
  14701. }
  14702. var metas = div.querySelectorAll('meta')
  14703. for (var i = 0, ci; (ci = metas[i++]); ) {
  14704. domUtils.remove(ci)
  14705. }
  14706. var brs = div.querySelectorAll('br')
  14707. for (i = 0; (ci = brs[i++]); ) {
  14708. if (/^apple-/i.test(ci.className)) {
  14709. domUtils.remove(ci)
  14710. }
  14711. }
  14712. }
  14713. if (browser.gecko) {
  14714. var dirtyNodes = div.querySelectorAll('[_moz_dirty]')
  14715. for (i = 0; (ci = dirtyNodes[i++]); ) {
  14716. ci.removeAttribute('_moz_dirty')
  14717. }
  14718. }
  14719. if (!browser.ie) {
  14720. var spans = div.querySelectorAll('span.Apple-style-span')
  14721. for (var i = 0, ci; (ci = spans[i++]); ) {
  14722. domUtils.remove(ci, true)
  14723. }
  14724. }
  14725. //ie下使用innerHTML会产生多余的\r\n字符,也会产生&nbsp;这里过滤掉
  14726. html = div.innerHTML //.replace(/>(?:(\s|&nbsp;)*?)</g,'><');
  14727. //过滤word粘贴过来的冗余属性
  14728. html = UE.filterWord(html)
  14729. //取消了忽略空白的第二个参数,粘贴过来的有些是有空白的,会被套上相关的标签
  14730. var root = UE.htmlparser(html)
  14731. //如果给了过滤规则就先进行过滤
  14732. if (me.options.filterRules) {
  14733. UE.filterNode(root, me.options.filterRules)
  14734. }
  14735. //执行默认的处理
  14736. me.filterInputRule(root)
  14737. //针对chrome的处理
  14738. if (browser.webkit) {
  14739. var br = root.lastChild()
  14740. if (br && br.type == 'element' && br.tagName == 'br') {
  14741. root.removeChild(br)
  14742. }
  14743. utils.each(me.body.querySelectorAll('div'), function (node) {
  14744. if (domUtils.isEmptyBlock(node)) {
  14745. domUtils.remove(node, true)
  14746. }
  14747. })
  14748. }
  14749. html = { html: root.toHtml() }
  14750. me.fireEvent('beforepaste', html, root)
  14751. //抢了默认的粘贴,那后边的内容就不执行了,比如表格粘贴
  14752. if (!html.html) {
  14753. return
  14754. }
  14755. root = UE.htmlparser(html.html, true)
  14756. //如果开启了纯文本模式
  14757. if (me.queryCommandState('pasteplain') === 1) {
  14758. me.execCommand(
  14759. 'insertHtml',
  14760. UE.filterNode(root, me.options.filterTxtRules).toHtml(),
  14761. true
  14762. )
  14763. } else {
  14764. //文本模式
  14765. UE.filterNode(root, me.options.filterTxtRules)
  14766. txtContent = root.toHtml()
  14767. //完全模式
  14768. htmlContent = html.html
  14769. address = me.selection.getRange().createAddress(true)
  14770. me.execCommand(
  14771. 'insertHtml',
  14772. me.getOpt('retainOnlyLabelPasted') === true ? getPureHtml(htmlContent) : htmlContent,
  14773. true
  14774. )
  14775. }
  14776. me.fireEvent('afterpaste', html)
  14777. }
  14778. }
  14779. me.addListener('pasteTransfer', function (cmd, plainType) {
  14780. if (address && txtContent && htmlContent && txtContent != htmlContent) {
  14781. var range = me.selection.getRange()
  14782. range.moveToAddress(address, true)
  14783. if (!range.collapsed) {
  14784. while (!domUtils.isBody(range.startContainer)) {
  14785. var start = range.startContainer
  14786. if (start.nodeType == 1) {
  14787. start = start.childNodes[range.startOffset]
  14788. if (!start) {
  14789. range.setStartBefore(range.startContainer)
  14790. continue
  14791. }
  14792. var pre = start.previousSibling
  14793. if (
  14794. pre &&
  14795. pre.nodeType == 3 &&
  14796. new RegExp('^[\n\r\t ' + domUtils.fillChar + ']*$').test(pre.nodeValue)
  14797. ) {
  14798. range.setStartBefore(pre)
  14799. }
  14800. }
  14801. if (range.startOffset == 0) {
  14802. range.setStartBefore(range.startContainer)
  14803. } else {
  14804. break
  14805. }
  14806. }
  14807. while (!domUtils.isBody(range.endContainer)) {
  14808. var end = range.endContainer
  14809. if (end.nodeType == 1) {
  14810. end = end.childNodes[range.endOffset]
  14811. if (!end) {
  14812. range.setEndAfter(range.endContainer)
  14813. continue
  14814. }
  14815. var next = end.nextSibling
  14816. if (
  14817. next &&
  14818. next.nodeType == 3 &&
  14819. new RegExp('^[\n\r\t' + domUtils.fillChar + ']*$').test(next.nodeValue)
  14820. ) {
  14821. range.setEndAfter(next)
  14822. }
  14823. }
  14824. if (
  14825. range.endOffset ==
  14826. range.endContainer[range.endContainer.nodeType == 3 ? 'nodeValue' : 'childNodes']
  14827. .length
  14828. ) {
  14829. range.setEndAfter(range.endContainer)
  14830. } else {
  14831. break
  14832. }
  14833. }
  14834. }
  14835. range.deleteContents()
  14836. range.select(true)
  14837. me.__hasEnterExecCommand = true
  14838. var html = htmlContent
  14839. if (plainType === 2) {
  14840. html = getPureHtml(html)
  14841. } else if (plainType) {
  14842. html = txtContent
  14843. }
  14844. me.execCommand('inserthtml', html, true)
  14845. me.__hasEnterExecCommand = false
  14846. var rng = me.selection.getRange()
  14847. while (
  14848. !domUtils.isBody(rng.startContainer) &&
  14849. !rng.startOffset &&
  14850. rng.startContainer[rng.startContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length
  14851. ) {
  14852. rng.setStartBefore(rng.startContainer)
  14853. }
  14854. var tmpAddress = rng.createAddress(true)
  14855. address.endAddress = tmpAddress.startAddress
  14856. }
  14857. })
  14858. me.addListener('ready', function () {
  14859. domUtils.on(me.body, 'cut', function () {
  14860. var range = me.selection.getRange()
  14861. if (!range.collapsed && me.undoManger) {
  14862. me.undoManger.save()
  14863. }
  14864. })
  14865. //ie下beforepaste在点击右键时也会触发,所以用监控键盘才处理
  14866. domUtils.on(me.body, browser.ie || browser.opera ? 'keydown' : 'paste', function (e) {
  14867. if ((browser.ie || browser.opera) && ((!e.ctrlKey && !e.metaKey) || e.keyCode != '86')) {
  14868. return
  14869. }
  14870. getClipboardData.call(me, function (div) {
  14871. filter(div)
  14872. })
  14873. })
  14874. })
  14875. me.commands['paste'] = {
  14876. execCommand: function (cmd) {
  14877. if (browser.ie) {
  14878. getClipboardData.call(me, function (div) {
  14879. filter(div)
  14880. })
  14881. me.document.execCommand('paste')
  14882. } else {
  14883. alert(me.getLang('pastemsg'))
  14884. }
  14885. }
  14886. }
  14887. }
  14888. // plugins/puretxtpaste.js
  14889. /**
  14890. * 纯文本粘贴插件
  14891. * @file
  14892. * @since 1.2.6.1
  14893. */
  14894. UE.plugins['pasteplain'] = function () {
  14895. var me = this
  14896. me.setOpt({
  14897. pasteplain: false,
  14898. filterTxtRules: (function () {
  14899. function transP(node) {
  14900. node.tagName = 'p'
  14901. node.setStyle()
  14902. }
  14903. function removeNode(node) {
  14904. node.parentNode.removeChild(node, true)
  14905. }
  14906. return {
  14907. //直接删除及其字节点内容
  14908. '-': 'script style object iframe embed input select',
  14909. p: { $: {} },
  14910. br: { $: {} },
  14911. div: function (node) {
  14912. var tmpNode,
  14913. p = UE.uNode.createElement('p')
  14914. while ((tmpNode = node.firstChild())) {
  14915. if (tmpNode.type == 'text' || !UE.dom.dtd.$block[tmpNode.tagName]) {
  14916. p.appendChild(tmpNode)
  14917. } else {
  14918. if (p.firstChild()) {
  14919. node.parentNode.insertBefore(p, node)
  14920. p = UE.uNode.createElement('p')
  14921. } else {
  14922. node.parentNode.insertBefore(tmpNode, node)
  14923. }
  14924. }
  14925. }
  14926. if (p.firstChild()) {
  14927. node.parentNode.insertBefore(p, node)
  14928. }
  14929. node.parentNode.removeChild(node)
  14930. },
  14931. ol: removeNode,
  14932. ul: removeNode,
  14933. dl: removeNode,
  14934. dt: removeNode,
  14935. dd: removeNode,
  14936. li: removeNode,
  14937. caption: transP,
  14938. th: transP,
  14939. tr: transP,
  14940. h1: transP,
  14941. h2: transP,
  14942. h3: transP,
  14943. h4: transP,
  14944. h5: transP,
  14945. h6: transP,
  14946. td: function (node) {
  14947. //没有内容的td直接删掉
  14948. var txt = !!node.innerText()
  14949. if (txt) {
  14950. node.parentNode.insertAfter(UE.uNode.createText(' &nbsp; &nbsp;'), node)
  14951. }
  14952. node.parentNode.removeChild(node, node.innerText())
  14953. }
  14954. }
  14955. })()
  14956. })
  14957. //暂时这里支持一下老版本的属性
  14958. var pasteplain = me.options.pasteplain
  14959. /**
  14960. * 启用或取消纯文本粘贴模式
  14961. * @command pasteplain
  14962. * @method execCommand
  14963. * @param { String } cmd 命令字符串
  14964. * @example
  14965. * ```javascript
  14966. * editor.queryCommandState( 'pasteplain' );
  14967. * ```
  14968. */
  14969. /**
  14970. * 查询当前是否处于纯文本粘贴模式
  14971. * @command pasteplain
  14972. * @method queryCommandState
  14973. * @param { String } cmd 命令字符串
  14974. * @return { int } 如果处于纯文本模式,返回1,否则,返回0
  14975. * @example
  14976. * ```javascript
  14977. * editor.queryCommandState( 'pasteplain' );
  14978. * ```
  14979. */
  14980. me.commands['pasteplain'] = {
  14981. queryCommandState: function () {
  14982. return pasteplain ? 1 : 0
  14983. },
  14984. execCommand: function () {
  14985. pasteplain = !pasteplain | 0
  14986. },
  14987. notNeedUndo: 1
  14988. }
  14989. }
  14990. // plugins/list.js
  14991. /**
  14992. * 有序列表,无序列表插件
  14993. * @file
  14994. * @since 1.2.6.1
  14995. */
  14996. UE.plugins['list'] = function () {
  14997. var me = this,
  14998. notExchange = {
  14999. TD: 1,
  15000. PRE: 1,
  15001. BLOCKQUOTE: 1
  15002. }
  15003. var customStyle = {
  15004. cn: 'cn-1-',
  15005. cn1: 'cn-2-',
  15006. cn2: 'cn-3-',
  15007. num: 'num-1-',
  15008. num1: 'num-2-',
  15009. num2: 'num-3-',
  15010. dash: 'dash',
  15011. dot: 'dot'
  15012. }
  15013. me.setOpt({
  15014. autoTransWordToList: false,
  15015. insertorderedlist: {
  15016. num: '',
  15017. num1: '',
  15018. num2: '',
  15019. cn: '',
  15020. cn1: '',
  15021. cn2: '',
  15022. decimal: '',
  15023. 'lower-alpha': '',
  15024. 'lower-roman': '',
  15025. 'upper-alpha': '',
  15026. 'upper-roman': ''
  15027. },
  15028. insertunorderedlist: {
  15029. circle: '',
  15030. disc: '',
  15031. square: '',
  15032. dash: '',
  15033. dot: ''
  15034. },
  15035. listDefaultPaddingLeft: '30',
  15036. listiconpath: 'http://bs.baidu.com/listicon/',
  15037. maxListLevel: -1, //-1不限制
  15038. disablePInList: false
  15039. })
  15040. function listToArray(list) {
  15041. var arr = []
  15042. for (var p in list) {
  15043. arr.push(p)
  15044. }
  15045. return arr
  15046. }
  15047. var listStyle = {
  15048. OL: listToArray(me.options.insertorderedlist),
  15049. UL: listToArray(me.options.insertunorderedlist)
  15050. }
  15051. var liiconpath = me.options.listiconpath
  15052. //根据用户配置,调整customStyle
  15053. for (var s in customStyle) {
  15054. if (
  15055. !me.options.insertorderedlist.hasOwnProperty(s) &&
  15056. !me.options.insertunorderedlist.hasOwnProperty(s)
  15057. ) {
  15058. delete customStyle[s]
  15059. }
  15060. }
  15061. me.ready(function () {
  15062. var customCss = []
  15063. for (var p in customStyle) {
  15064. if (p == 'dash' || p == 'dot') {
  15065. customCss.push(
  15066. 'li.list-' +
  15067. customStyle[p] +
  15068. '{background-image:url(' +
  15069. liiconpath +
  15070. customStyle[p] +
  15071. '.gif)}'
  15072. )
  15073. customCss.push(
  15074. 'ul.custom_' +
  15075. p +
  15076. '{list-style:none;}ul.custom_' +
  15077. p +
  15078. ' li{background-position:0 3px;background-repeat:no-repeat}'
  15079. )
  15080. } else {
  15081. for (var i = 0; i < 99; i++) {
  15082. customCss.push(
  15083. 'li.list-' +
  15084. customStyle[p] +
  15085. i +
  15086. '{background-image:url(' +
  15087. liiconpath +
  15088. 'list-' +
  15089. customStyle[p] +
  15090. i +
  15091. '.gif)}'
  15092. )
  15093. }
  15094. customCss.push(
  15095. 'ol.custom_' +
  15096. p +
  15097. '{list-style:none;}ol.custom_' +
  15098. p +
  15099. ' li{background-position:0 3px;background-repeat:no-repeat}'
  15100. )
  15101. }
  15102. switch (p) {
  15103. case 'cn':
  15104. customCss.push('li.list-' + p + '-paddingleft-1{padding-left:25px}')
  15105. customCss.push('li.list-' + p + '-paddingleft-2{padding-left:40px}')
  15106. customCss.push('li.list-' + p + '-paddingleft-3{padding-left:55px}')
  15107. break
  15108. case 'cn1':
  15109. customCss.push('li.list-' + p + '-paddingleft-1{padding-left:30px}')
  15110. customCss.push('li.list-' + p + '-paddingleft-2{padding-left:40px}')
  15111. customCss.push('li.list-' + p + '-paddingleft-3{padding-left:55px}')
  15112. break
  15113. case 'cn2':
  15114. customCss.push('li.list-' + p + '-paddingleft-1{padding-left:40px}')
  15115. customCss.push('li.list-' + p + '-paddingleft-2{padding-left:55px}')
  15116. customCss.push('li.list-' + p + '-paddingleft-3{padding-left:68px}')
  15117. break
  15118. case 'num':
  15119. case 'num1':
  15120. customCss.push('li.list-' + p + '-paddingleft-1{padding-left:25px}')
  15121. break
  15122. case 'num2':
  15123. customCss.push('li.list-' + p + '-paddingleft-1{padding-left:35px}')
  15124. customCss.push('li.list-' + p + '-paddingleft-2{padding-left:40px}')
  15125. break
  15126. case 'dash':
  15127. customCss.push('li.list-' + p + '-paddingleft{padding-left:35px}')
  15128. break
  15129. case 'dot':
  15130. customCss.push('li.list-' + p + '-paddingleft{padding-left:20px}')
  15131. }
  15132. }
  15133. customCss.push('.list-paddingleft-1{padding-left:0}')
  15134. customCss.push(
  15135. '.list-paddingleft-2{padding-left:' + me.options.listDefaultPaddingLeft + 'px}'
  15136. )
  15137. customCss.push(
  15138. '.list-paddingleft-3{padding-left:' + me.options.listDefaultPaddingLeft * 2 + 'px}'
  15139. )
  15140. //如果不给宽度会在自定应样式里出现滚动条
  15141. utils.cssRule(
  15142. 'list',
  15143. 'ol,ul{margin:0;pading:0;' +
  15144. (browser.ie ? '' : 'width:95%') +
  15145. '}li{clear:both;}' +
  15146. customCss.join('\n'),
  15147. me.document
  15148. )
  15149. })
  15150. //单独处理剪切的问题
  15151. me.ready(function () {
  15152. domUtils.on(me.body, 'cut', function () {
  15153. setTimeout(function () {
  15154. var rng = me.selection.getRange(),
  15155. li
  15156. //trace:3416
  15157. if (!rng.collapsed) {
  15158. if ((li = domUtils.findParentByTagName(rng.startContainer, 'li', true))) {
  15159. if (!li.nextSibling && domUtils.isEmptyBlock(li)) {
  15160. var pn = li.parentNode,
  15161. node
  15162. if ((node = pn.previousSibling)) {
  15163. domUtils.remove(pn)
  15164. rng.setStartAtLast(node).collapse(true)
  15165. rng.select(true)
  15166. } else if ((node = pn.nextSibling)) {
  15167. domUtils.remove(pn)
  15168. rng.setStartAtFirst(node).collapse(true)
  15169. rng.select(true)
  15170. } else {
  15171. var tmpNode = me.document.createElement('p')
  15172. domUtils.fillNode(me.document, tmpNode)
  15173. pn.parentNode.insertBefore(tmpNode, pn)
  15174. domUtils.remove(pn)
  15175. rng.setStart(tmpNode, 0).collapse(true)
  15176. rng.select(true)
  15177. }
  15178. }
  15179. }
  15180. }
  15181. })
  15182. })
  15183. })
  15184. function getStyle(node) {
  15185. var cls = node.className
  15186. if (domUtils.hasClass(node, /custom_/)) {
  15187. return cls.match(/custom_(\w+)/)[1]
  15188. }
  15189. return domUtils.getStyle(node, 'list-style-type')
  15190. }
  15191. me.addListener('beforepaste', function (type, html) {
  15192. var me = this,
  15193. rng = me.selection.getRange(),
  15194. li
  15195. var root = UE.htmlparser(html.html, true)
  15196. if ((li = domUtils.findParentByTagName(rng.startContainer, 'li', true))) {
  15197. var list = li.parentNode,
  15198. tagName = list.tagName == 'OL' ? 'ul' : 'ol'
  15199. utils.each(root.getNodesByTagName(tagName), function (n) {
  15200. n.tagName = list.tagName
  15201. n.setAttr()
  15202. if (n.parentNode === root) {
  15203. type = getStyle(list) || (list.tagName == 'OL' ? 'decimal' : 'disc')
  15204. } else {
  15205. var className = n.parentNode.getAttr('class')
  15206. if (className && /custom_/.test(className)) {
  15207. type = className.match(/custom_(\w+)/)[1]
  15208. } else {
  15209. type = n.parentNode.getStyle('list-style-type')
  15210. }
  15211. if (!type) {
  15212. type = list.tagName == 'OL' ? 'decimal' : 'disc'
  15213. }
  15214. }
  15215. var index = utils.indexOf(listStyle[list.tagName], type)
  15216. if (n.parentNode !== root)
  15217. index = index + 1 == listStyle[list.tagName].length ? 0 : index + 1
  15218. var currentStyle = listStyle[list.tagName][index]
  15219. if (customStyle[currentStyle]) {
  15220. n.setAttr('class', 'custom_' + currentStyle)
  15221. } else {
  15222. n.setStyle('list-style-type', currentStyle)
  15223. }
  15224. })
  15225. }
  15226. html.html = root.toHtml()
  15227. })
  15228. //导出时,去掉p标签
  15229. me.getOpt('disablePInList') === true &&
  15230. me.addOutputRule(function (root) {
  15231. utils.each(root.getNodesByTagName('li'), function (li) {
  15232. var newChildrens = [],
  15233. index = 0
  15234. utils.each(li.children, function (n) {
  15235. if (n.tagName == 'p') {
  15236. var tmpNode
  15237. while ((tmpNode = n.children.pop())) {
  15238. newChildrens.splice(index, 0, tmpNode)
  15239. tmpNode.parentNode = li
  15240. lastNode = tmpNode
  15241. }
  15242. tmpNode = newChildrens[newChildrens.length - 1]
  15243. if (!tmpNode || tmpNode.type != 'element' || tmpNode.tagName != 'br') {
  15244. var br = UE.uNode.createElement('br')
  15245. br.parentNode = li
  15246. newChildrens.push(br)
  15247. }
  15248. index = newChildrens.length
  15249. }
  15250. })
  15251. if (newChildrens.length) {
  15252. li.children = newChildrens
  15253. }
  15254. })
  15255. })
  15256. //进入编辑器的li要套p标签
  15257. me.addInputRule(function (root) {
  15258. utils.each(root.getNodesByTagName('li'), function (li) {
  15259. var tmpP = UE.uNode.createElement('p')
  15260. for (var i = 0, ci; (ci = li.children[i]); ) {
  15261. if (ci.type == 'text' || dtd.p[ci.tagName]) {
  15262. tmpP.appendChild(ci)
  15263. } else {
  15264. if (tmpP.firstChild()) {
  15265. li.insertBefore(tmpP, ci)
  15266. tmpP = UE.uNode.createElement('p')
  15267. i = i + 2
  15268. } else {
  15269. i++
  15270. }
  15271. }
  15272. }
  15273. if ((tmpP.firstChild() && !tmpP.parentNode) || !li.firstChild()) {
  15274. li.appendChild(tmpP)
  15275. }
  15276. //trace:3357
  15277. //p不能为空
  15278. if (!tmpP.firstChild()) {
  15279. tmpP.innerHTML(browser.ie ? '&nbsp;' : '<br/>')
  15280. }
  15281. //去掉末尾的空白
  15282. var p = li.firstChild()
  15283. var lastChild = p.lastChild()
  15284. if (lastChild && lastChild.type == 'text' && /^\s*$/.test(lastChild.data)) {
  15285. p.removeChild(lastChild)
  15286. }
  15287. })
  15288. if (me.options.autoTransWordToList) {
  15289. var orderlisttype = {
  15290. num1: /^\d+\)/,
  15291. decimal: /^\d+\./,
  15292. 'lower-alpha': /^[a-z]+\)/,
  15293. 'upper-alpha': /^[A-Z]+\./,
  15294. cn: /^[\u4E00\u4E8C\u4E09\u56DB\u516d\u4e94\u4e03\u516b\u4e5d]+[\u3001]/,
  15295. cn2: /^\([\u4E00\u4E8C\u4E09\u56DB\u516d\u4e94\u4e03\u516b\u4e5d]+\)/
  15296. },
  15297. unorderlisttype = {
  15298. square: 'n'
  15299. }
  15300. function checkListType(content, container) {
  15301. var span = container.firstChild()
  15302. if (
  15303. span &&
  15304. span.type == 'element' &&
  15305. span.tagName == 'span' &&
  15306. /Wingdings|Symbol/.test(span.getStyle('font-family'))
  15307. ) {
  15308. for (var p in unorderlisttype) {
  15309. if (unorderlisttype[p] == span.data) {
  15310. return p
  15311. }
  15312. }
  15313. return 'disc'
  15314. }
  15315. for (var p in orderlisttype) {
  15316. if (orderlisttype[p].test(content)) {
  15317. return p
  15318. }
  15319. }
  15320. }
  15321. utils.each(root.getNodesByTagName('p'), function (node) {
  15322. if (node.getAttr('class') != 'MsoListParagraph') {
  15323. return
  15324. }
  15325. //word粘贴过来的会带有margin要去掉,但这样也可能会误命中一些央视
  15326. node.setStyle('margin', '')
  15327. node.setStyle('margin-left', '')
  15328. node.setAttr('class', '')
  15329. function appendLi(list, p, type) {
  15330. if (list.tagName == 'ol') {
  15331. if (browser.ie) {
  15332. var first = p.firstChild()
  15333. if (
  15334. first.type == 'element' &&
  15335. first.tagName == 'span' &&
  15336. orderlisttype[type].test(first.innerText())
  15337. ) {
  15338. p.removeChild(first)
  15339. }
  15340. } else {
  15341. p.innerHTML(p.innerHTML().replace(orderlisttype[type], ''))
  15342. }
  15343. } else {
  15344. p.removeChild(p.firstChild())
  15345. }
  15346. var li = UE.uNode.createElement('li')
  15347. li.appendChild(p)
  15348. list.appendChild(li)
  15349. }
  15350. var tmp = node,
  15351. type,
  15352. cacheNode = node
  15353. if (node.parentNode.tagName != 'li' && (type = checkListType(node.innerText(), node))) {
  15354. var list = UE.uNode.createElement(
  15355. me.options.insertorderedlist.hasOwnProperty(type) ? 'ol' : 'ul'
  15356. )
  15357. if (customStyle[type]) {
  15358. list.setAttr('class', 'custom_' + type)
  15359. } else {
  15360. list.setStyle('list-style-type', type)
  15361. }
  15362. while (
  15363. node &&
  15364. node.parentNode.tagName != 'li' &&
  15365. checkListType(node.innerText(), node)
  15366. ) {
  15367. tmp = node.nextSibling()
  15368. if (!tmp) {
  15369. node.parentNode.insertBefore(list, node)
  15370. }
  15371. appendLi(list, node, type)
  15372. node = tmp
  15373. }
  15374. if (!list.parentNode && node && node.parentNode) {
  15375. node.parentNode.insertBefore(list, node)
  15376. }
  15377. }
  15378. var span = cacheNode.firstChild()
  15379. if (
  15380. span &&
  15381. span.type == 'element' &&
  15382. span.tagName == 'span' &&
  15383. /^\s*(&nbsp;)+\s*$/.test(span.innerText())
  15384. ) {
  15385. span.parentNode.removeChild(span)
  15386. }
  15387. })
  15388. }
  15389. })
  15390. //调整索引标签
  15391. me.addListener('contentchange', function () {
  15392. adjustListStyle(me.document)
  15393. })
  15394. function adjustListStyle(doc, ignore) {
  15395. utils.each(domUtils.getElementsByTagName(doc, 'ol ul'), function (node) {
  15396. if (!domUtils.inDoc(node, doc)) return
  15397. var parent = node.parentNode
  15398. if (parent.tagName == node.tagName) {
  15399. var nodeStyleType = getStyle(node) || (node.tagName == 'OL' ? 'decimal' : 'disc'),
  15400. parentStyleType = getStyle(parent) || (parent.tagName == 'OL' ? 'decimal' : 'disc')
  15401. if (nodeStyleType == parentStyleType) {
  15402. var styleIndex = utils.indexOf(listStyle[node.tagName], nodeStyleType)
  15403. styleIndex = styleIndex + 1 == listStyle[node.tagName].length ? 0 : styleIndex + 1
  15404. setListStyle(node, listStyle[node.tagName][styleIndex])
  15405. }
  15406. }
  15407. var index = 0,
  15408. type = 2
  15409. if (domUtils.hasClass(node, /custom_/)) {
  15410. if (!(/[ou]l/i.test(parent.tagName) && domUtils.hasClass(parent, /custom_/))) {
  15411. type = 1
  15412. }
  15413. } else {
  15414. if (/[ou]l/i.test(parent.tagName) && domUtils.hasClass(parent, /custom_/)) {
  15415. type = 3
  15416. }
  15417. }
  15418. var style = domUtils.getStyle(node, 'list-style-type')
  15419. style && (node.style.cssText = 'list-style-type:' + style)
  15420. node.className =
  15421. utils.trim(node.className.replace(/list-paddingleft-\w+/, '')) +
  15422. ' list-paddingleft-' +
  15423. type
  15424. utils.each(domUtils.getElementsByTagName(node, 'li'), function (li) {
  15425. li.style.cssText && (li.style.cssText = '')
  15426. if (!li.firstChild) {
  15427. domUtils.remove(li)
  15428. return
  15429. }
  15430. if (li.parentNode !== node) {
  15431. return
  15432. }
  15433. index++
  15434. if (domUtils.hasClass(node, /custom_/)) {
  15435. var paddingLeft = 1,
  15436. currentStyle = getStyle(node)
  15437. if (node.tagName == 'OL') {
  15438. if (currentStyle) {
  15439. switch (currentStyle) {
  15440. case 'cn':
  15441. case 'cn1':
  15442. case 'cn2':
  15443. if (index > 10 && (index % 10 == 0 || (index > 10 && index < 20))) {
  15444. paddingLeft = 2
  15445. } else if (index > 20) {
  15446. paddingLeft = 3
  15447. }
  15448. break
  15449. case 'num2':
  15450. if (index > 9) {
  15451. paddingLeft = 2
  15452. }
  15453. }
  15454. }
  15455. li.className =
  15456. 'list-' +
  15457. customStyle[currentStyle] +
  15458. index +
  15459. ' ' +
  15460. 'list-' +
  15461. currentStyle +
  15462. '-paddingleft-' +
  15463. paddingLeft
  15464. } else {
  15465. li.className =
  15466. 'list-' + customStyle[currentStyle] + ' ' + 'list-' + currentStyle + '-paddingleft'
  15467. }
  15468. } else {
  15469. li.className = li.className.replace(/list-[\w\-]+/gi, '')
  15470. }
  15471. var className = li.getAttribute('class')
  15472. if (className !== null && !className.replace(/\s/g, '')) {
  15473. domUtils.removeAttributes(li, 'class')
  15474. }
  15475. })
  15476. !ignore &&
  15477. adjustList(
  15478. node,
  15479. node.tagName.toLowerCase(),
  15480. getStyle(node) || domUtils.getStyle(node, 'list-style-type'),
  15481. true
  15482. )
  15483. })
  15484. }
  15485. function adjustList(list, tag, style, ignoreEmpty) {
  15486. var nextList = list.nextSibling
  15487. if (
  15488. nextList &&
  15489. nextList.nodeType == 1 &&
  15490. nextList.tagName.toLowerCase() == tag &&
  15491. (getStyle(nextList) ||
  15492. domUtils.getStyle(nextList, 'list-style-type') ||
  15493. (tag == 'ol' ? 'decimal' : 'disc')) == style
  15494. ) {
  15495. domUtils.moveChild(nextList, list)
  15496. if (nextList.childNodes.length == 0) {
  15497. domUtils.remove(nextList)
  15498. }
  15499. }
  15500. if (nextList && domUtils.isFillChar(nextList)) {
  15501. domUtils.remove(nextList)
  15502. }
  15503. var preList = list.previousSibling
  15504. if (
  15505. preList &&
  15506. preList.nodeType == 1 &&
  15507. preList.tagName.toLowerCase() == tag &&
  15508. (getStyle(preList) ||
  15509. domUtils.getStyle(preList, 'list-style-type') ||
  15510. (tag == 'ol' ? 'decimal' : 'disc')) == style
  15511. ) {
  15512. domUtils.moveChild(list, preList)
  15513. }
  15514. if (preList && domUtils.isFillChar(preList)) {
  15515. domUtils.remove(preList)
  15516. }
  15517. !ignoreEmpty && domUtils.isEmptyBlock(list) && domUtils.remove(list)
  15518. if (getStyle(list)) {
  15519. adjustListStyle(list.ownerDocument, true)
  15520. }
  15521. }
  15522. function setListStyle(list, style) {
  15523. if (customStyle[style]) {
  15524. list.className = 'custom_' + style
  15525. }
  15526. try {
  15527. domUtils.setStyle(list, 'list-style-type', style)
  15528. } catch (e) {}
  15529. }
  15530. function clearEmptySibling(node) {
  15531. var tmpNode = node.previousSibling
  15532. if (tmpNode && domUtils.isEmptyBlock(tmpNode)) {
  15533. domUtils.remove(tmpNode)
  15534. }
  15535. tmpNode = node.nextSibling
  15536. if (tmpNode && domUtils.isEmptyBlock(tmpNode)) {
  15537. domUtils.remove(tmpNode)
  15538. }
  15539. }
  15540. me.addListener('keydown', function (type, evt) {
  15541. function preventAndSave() {
  15542. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false)
  15543. me.fireEvent('contentchange')
  15544. me.undoManger && me.undoManger.save()
  15545. }
  15546. function findList(node, filterFn) {
  15547. while (node && !domUtils.isBody(node)) {
  15548. if (filterFn(node)) {
  15549. return null
  15550. }
  15551. if (node.nodeType == 1 && /[ou]l/i.test(node.tagName)) {
  15552. return node
  15553. }
  15554. node = node.parentNode
  15555. }
  15556. return null
  15557. }
  15558. var keyCode = evt.keyCode || evt.which
  15559. if (keyCode == 13 && !evt.shiftKey) {
  15560. //回车
  15561. var rng = me.selection.getRange(),
  15562. parent = domUtils.findParent(
  15563. rng.startContainer,
  15564. function (node) {
  15565. return domUtils.isBlockElm(node)
  15566. },
  15567. true
  15568. ),
  15569. li = domUtils.findParentByTagName(rng.startContainer, 'li', true)
  15570. if (parent && parent.tagName != 'PRE' && !li) {
  15571. var html = parent.innerHTML.replace(new RegExp(domUtils.fillChar, 'g'), '')
  15572. if (/^\s*1\s*\.[^\d]/.test(html)) {
  15573. parent.innerHTML = html.replace(/^\s*1\s*\./, '')
  15574. rng.setStartAtLast(parent).collapse(true).select()
  15575. me.__hasEnterExecCommand = true
  15576. me.execCommand('insertorderedlist')
  15577. me.__hasEnterExecCommand = false
  15578. }
  15579. }
  15580. var range = me.selection.getRange(),
  15581. start = findList(range.startContainer, function (node) {
  15582. return node.tagName == 'TABLE'
  15583. }),
  15584. end = range.collapsed
  15585. ? start
  15586. : findList(range.endContainer, function (node) {
  15587. return node.tagName == 'TABLE'
  15588. })
  15589. if (start && end && start === end) {
  15590. if (!range.collapsed) {
  15591. start = domUtils.findParentByTagName(range.startContainer, 'li', true)
  15592. end = domUtils.findParentByTagName(range.endContainer, 'li', true)
  15593. if (start && end && start === end) {
  15594. range.deleteContents()
  15595. li = domUtils.findParentByTagName(range.startContainer, 'li', true)
  15596. if (li && domUtils.isEmptyBlock(li)) {
  15597. pre = li.previousSibling
  15598. next = li.nextSibling
  15599. p = me.document.createElement('p')
  15600. domUtils.fillNode(me.document, p)
  15601. parentList = li.parentNode
  15602. if (pre && next) {
  15603. range.setStart(next, 0).collapse(true).select(true)
  15604. domUtils.remove(li)
  15605. } else {
  15606. if ((!pre && !next) || !pre) {
  15607. parentList.parentNode.insertBefore(p, parentList)
  15608. } else {
  15609. li.parentNode.parentNode.insertBefore(p, parentList.nextSibling)
  15610. }
  15611. domUtils.remove(li)
  15612. if (!parentList.firstChild) {
  15613. domUtils.remove(parentList)
  15614. }
  15615. range.setStart(p, 0).setCursor()
  15616. }
  15617. preventAndSave()
  15618. return
  15619. }
  15620. } else {
  15621. var tmpRange = range.cloneRange(),
  15622. bk = tmpRange.collapse(false).createBookmark()
  15623. range.deleteContents()
  15624. tmpRange.moveToBookmark(bk)
  15625. var li = domUtils.findParentByTagName(tmpRange.startContainer, 'li', true)
  15626. clearEmptySibling(li)
  15627. tmpRange.select()
  15628. preventAndSave()
  15629. return
  15630. }
  15631. }
  15632. li = domUtils.findParentByTagName(range.startContainer, 'li', true)
  15633. if (li) {
  15634. if (domUtils.isEmptyBlock(li)) {
  15635. bk = range.createBookmark()
  15636. var parentList = li.parentNode
  15637. if (li !== parentList.lastChild) {
  15638. domUtils.breakParent(li, parentList)
  15639. clearEmptySibling(li)
  15640. } else {
  15641. parentList.parentNode.insertBefore(li, parentList.nextSibling)
  15642. if (domUtils.isEmptyNode(parentList)) {
  15643. domUtils.remove(parentList)
  15644. }
  15645. }
  15646. //嵌套不处理
  15647. if (!dtd.$list[li.parentNode.tagName]) {
  15648. if (!domUtils.isBlockElm(li.firstChild)) {
  15649. p = me.document.createElement('p')
  15650. li.parentNode.insertBefore(p, li)
  15651. while (li.firstChild) {
  15652. p.appendChild(li.firstChild)
  15653. }
  15654. domUtils.remove(li)
  15655. } else {
  15656. domUtils.remove(li, true)
  15657. }
  15658. }
  15659. range.moveToBookmark(bk).select()
  15660. } else {
  15661. var first = li.firstChild
  15662. if (!first || !domUtils.isBlockElm(first)) {
  15663. var p = me.document.createElement('p')
  15664. !li.firstChild && domUtils.fillNode(me.document, p)
  15665. while (li.firstChild) {
  15666. p.appendChild(li.firstChild)
  15667. }
  15668. li.appendChild(p)
  15669. first = p
  15670. }
  15671. var span = me.document.createElement('span')
  15672. range.insertNode(span)
  15673. domUtils.breakParent(span, li)
  15674. var nextLi = span.nextSibling
  15675. first = nextLi.firstChild
  15676. if (!first) {
  15677. p = me.document.createElement('p')
  15678. domUtils.fillNode(me.document, p)
  15679. nextLi.appendChild(p)
  15680. first = p
  15681. }
  15682. if (domUtils.isEmptyNode(first)) {
  15683. first.innerHTML = ''
  15684. domUtils.fillNode(me.document, first)
  15685. }
  15686. range.setStart(first, 0).collapse(true).shrinkBoundary().select()
  15687. domUtils.remove(span)
  15688. var pre = nextLi.previousSibling
  15689. if (pre && domUtils.isEmptyBlock(pre)) {
  15690. pre.innerHTML = '<p></p>'
  15691. domUtils.fillNode(me.document, pre.firstChild)
  15692. }
  15693. }
  15694. // }
  15695. preventAndSave()
  15696. }
  15697. }
  15698. }
  15699. if (keyCode == 8) {
  15700. //修中ie中li下的问题
  15701. range = me.selection.getRange()
  15702. if (range.collapsed && domUtils.isStartInblock(range)) {
  15703. tmpRange = range.cloneRange().trimBoundary()
  15704. li = domUtils.findParentByTagName(range.startContainer, 'li', true)
  15705. //要在li的最左边,才能处理
  15706. if (li && domUtils.isStartInblock(tmpRange)) {
  15707. start = domUtils.findParentByTagName(range.startContainer, 'p', true)
  15708. if (start && start !== li.firstChild) {
  15709. var parentList = domUtils.findParentByTagName(start, ['ol', 'ul'])
  15710. domUtils.breakParent(start, parentList)
  15711. clearEmptySibling(start)
  15712. me.fireEvent('contentchange')
  15713. range.setStart(start, 0).setCursor(false, true)
  15714. me.fireEvent('saveScene')
  15715. domUtils.preventDefault(evt)
  15716. return
  15717. }
  15718. if (li && (pre = li.previousSibling)) {
  15719. if (keyCode == 46 && li.childNodes.length) {
  15720. return
  15721. }
  15722. //有可能上边的兄弟节点是个2级菜单,要追加到2级菜单的最后的li
  15723. if (dtd.$list[pre.tagName]) {
  15724. pre = pre.lastChild
  15725. }
  15726. me.undoManger && me.undoManger.save()
  15727. first = li.firstChild
  15728. if (domUtils.isBlockElm(first)) {
  15729. if (domUtils.isEmptyNode(first)) {
  15730. // range.setEnd(pre, pre.childNodes.length).shrinkBoundary().collapse().select(true);
  15731. pre.appendChild(first)
  15732. range.setStart(first, 0).setCursor(false, true)
  15733. //first不是唯一的节点
  15734. while (li.firstChild) {
  15735. pre.appendChild(li.firstChild)
  15736. }
  15737. } else {
  15738. span = me.document.createElement('span')
  15739. range.insertNode(span)
  15740. //判断pre是否是空的节点,如果是<p><br/></p>类型的空节点,干掉p标签防止它占位
  15741. if (domUtils.isEmptyBlock(pre)) {
  15742. pre.innerHTML = ''
  15743. }
  15744. domUtils.moveChild(li, pre)
  15745. range.setStartBefore(span).collapse(true).select(true)
  15746. domUtils.remove(span)
  15747. }
  15748. } else {
  15749. if (domUtils.isEmptyNode(li)) {
  15750. var p = me.document.createElement('p')
  15751. pre.appendChild(p)
  15752. range.setStart(p, 0).setCursor()
  15753. // range.setEnd(pre, pre.childNodes.length).shrinkBoundary().collapse().select(true);
  15754. } else {
  15755. range.setEnd(pre, pre.childNodes.length).collapse().select(true)
  15756. while (li.firstChild) {
  15757. pre.appendChild(li.firstChild)
  15758. }
  15759. }
  15760. }
  15761. domUtils.remove(li)
  15762. me.fireEvent('contentchange')
  15763. me.fireEvent('saveScene')
  15764. domUtils.preventDefault(evt)
  15765. return
  15766. }
  15767. //trace:980
  15768. if (li && !li.previousSibling) {
  15769. var parentList = li.parentNode
  15770. var bk = range.createBookmark()
  15771. if (domUtils.isTagNode(parentList.parentNode, 'ol ul')) {
  15772. parentList.parentNode.insertBefore(li, parentList)
  15773. if (domUtils.isEmptyNode(parentList)) {
  15774. domUtils.remove(parentList)
  15775. }
  15776. } else {
  15777. while (li.firstChild) {
  15778. parentList.parentNode.insertBefore(li.firstChild, parentList)
  15779. }
  15780. domUtils.remove(li)
  15781. if (domUtils.isEmptyNode(parentList)) {
  15782. domUtils.remove(parentList)
  15783. }
  15784. }
  15785. range.moveToBookmark(bk).setCursor(false, true)
  15786. me.fireEvent('contentchange')
  15787. me.fireEvent('saveScene')
  15788. domUtils.preventDefault(evt)
  15789. return
  15790. }
  15791. }
  15792. }
  15793. }
  15794. })
  15795. me.addListener('keyup', function (type, evt) {
  15796. var keyCode = evt.keyCode || evt.which
  15797. if (keyCode == 8) {
  15798. var rng = me.selection.getRange(),
  15799. list
  15800. if ((list = domUtils.findParentByTagName(rng.startContainer, ['ol', 'ul'], true))) {
  15801. adjustList(
  15802. list,
  15803. list.tagName.toLowerCase(),
  15804. getStyle(list) || domUtils.getComputedStyle(list, 'list-style-type'),
  15805. true
  15806. )
  15807. }
  15808. }
  15809. })
  15810. //处理tab键
  15811. me.addListener('tabkeydown', function () {
  15812. var range = me.selection.getRange()
  15813. //控制级数
  15814. function checkLevel(li) {
  15815. if (me.options.maxListLevel != -1) {
  15816. var level = li.parentNode,
  15817. levelNum = 0
  15818. while (/[ou]l/i.test(level.tagName)) {
  15819. levelNum++
  15820. level = level.parentNode
  15821. }
  15822. if (levelNum >= me.options.maxListLevel) {
  15823. return true
  15824. }
  15825. }
  15826. }
  15827. //只以开始为准
  15828. //todo 后续改进
  15829. var li = domUtils.findParentByTagName(range.startContainer, 'li', true)
  15830. if (li) {
  15831. var bk
  15832. if (range.collapsed) {
  15833. if (checkLevel(li)) return true
  15834. var parentLi = li.parentNode,
  15835. list = me.document.createElement(parentLi.tagName),
  15836. index = utils.indexOf(
  15837. listStyle[list.tagName],
  15838. getStyle(parentLi) || domUtils.getComputedStyle(parentLi, 'list-style-type')
  15839. )
  15840. index = index + 1 == listStyle[list.tagName].length ? 0 : index + 1
  15841. var currentStyle = listStyle[list.tagName][index]
  15842. setListStyle(list, currentStyle)
  15843. if (domUtils.isStartInblock(range)) {
  15844. me.fireEvent('saveScene')
  15845. bk = range.createBookmark()
  15846. parentLi.insertBefore(list, li)
  15847. list.appendChild(li)
  15848. adjustList(list, list.tagName.toLowerCase(), currentStyle)
  15849. me.fireEvent('contentchange')
  15850. range.moveToBookmark(bk).select(true)
  15851. return true
  15852. }
  15853. } else {
  15854. me.fireEvent('saveScene')
  15855. bk = range.createBookmark()
  15856. for (
  15857. var i = 0, closeList, parents = domUtils.findParents(li), ci;
  15858. (ci = parents[i++]);
  15859. ) {
  15860. if (domUtils.isTagNode(ci, 'ol ul')) {
  15861. closeList = ci
  15862. break
  15863. }
  15864. }
  15865. var current = li
  15866. if (bk.end) {
  15867. while (
  15868. current &&
  15869. !(domUtils.getPosition(current, bk.end) & domUtils.POSITION_FOLLOWING)
  15870. ) {
  15871. if (checkLevel(current)) {
  15872. current = domUtils.getNextDomNode(current, false, null, function (node) {
  15873. return node !== closeList
  15874. })
  15875. continue
  15876. }
  15877. var parentLi = current.parentNode,
  15878. list = me.document.createElement(parentLi.tagName),
  15879. index = utils.indexOf(
  15880. listStyle[list.tagName],
  15881. getStyle(parentLi) || domUtils.getComputedStyle(parentLi, 'list-style-type')
  15882. )
  15883. var currentIndex = index + 1 == listStyle[list.tagName].length ? 0 : index + 1
  15884. var currentStyle = listStyle[list.tagName][currentIndex]
  15885. setListStyle(list, currentStyle)
  15886. parentLi.insertBefore(list, current)
  15887. while (
  15888. current &&
  15889. !(domUtils.getPosition(current, bk.end) & domUtils.POSITION_FOLLOWING)
  15890. ) {
  15891. li = current.nextSibling
  15892. list.appendChild(current)
  15893. if (!li || domUtils.isTagNode(li, 'ol ul')) {
  15894. if (li) {
  15895. while ((li = li.firstChild)) {
  15896. if (li.tagName == 'LI') {
  15897. break
  15898. }
  15899. }
  15900. } else {
  15901. li = domUtils.getNextDomNode(current, false, null, function (node) {
  15902. return node !== closeList
  15903. })
  15904. }
  15905. break
  15906. }
  15907. current = li
  15908. }
  15909. adjustList(list, list.tagName.toLowerCase(), currentStyle)
  15910. current = li
  15911. }
  15912. }
  15913. me.fireEvent('contentchange')
  15914. range.moveToBookmark(bk).select()
  15915. return true
  15916. }
  15917. }
  15918. })
  15919. function getLi(start) {
  15920. while (start && !domUtils.isBody(start)) {
  15921. if (start.nodeName == 'TABLE') {
  15922. return null
  15923. }
  15924. if (start.nodeName == 'LI') {
  15925. return start
  15926. }
  15927. start = start.parentNode
  15928. }
  15929. }
  15930. /**
  15931. * 有序列表,与“insertunorderedlist”命令互斥
  15932. * @command insertorderedlist
  15933. * @method execCommand
  15934. * @param { String } command 命令字符串
  15935. * @param { String } style 插入的有序列表类型,值为:decimal,lower-alpha,lower-roman,upper-alpha,upper-roman,cn,cn1,cn2,num,num1,num2
  15936. * @example
  15937. * ```javascript
  15938. * editor.execCommand( 'insertorderedlist','decimal');
  15939. * ```
  15940. */
  15941. /**
  15942. * 查询当前选区内容是否有序列表
  15943. * @command insertorderedlist
  15944. * @method queryCommandState
  15945. * @param { String } cmd 命令字符串
  15946. * @return { int } 如果当前选区是有序列表返回1,否则返回0
  15947. * @example
  15948. * ```javascript
  15949. * editor.queryCommandState( 'insertorderedlist' );
  15950. * ```
  15951. */
  15952. /**
  15953. * 查询当前选区内容是否有序列表
  15954. * @command insertorderedlist
  15955. * @method queryCommandValue
  15956. * @param { String } cmd 命令字符串
  15957. * @return { String } 返回当前有序列表的类型,值为null或decimal,lower-alpha,lower-roman,upper-alpha,upper-roman,cn,cn1,cn2,num,num1,num2
  15958. * @example
  15959. * ```javascript
  15960. * editor.queryCommandValue( 'insertorderedlist' );
  15961. * ```
  15962. */
  15963. /**
  15964. * 无序列表,与“insertorderedlist”命令互斥
  15965. * @command insertunorderedlist
  15966. * @method execCommand
  15967. * @param { String } command 命令字符串
  15968. * @param { String } style 插入的无序列表类型,值为:circle,disc,square,dash,dot
  15969. * @example
  15970. * ```javascript
  15971. * editor.execCommand( 'insertunorderedlist','circle');
  15972. * ```
  15973. */
  15974. /**
  15975. * 查询当前是否有word文档粘贴进来的图片
  15976. * @command insertunorderedlist
  15977. * @method insertunorderedlist
  15978. * @param { String } command 命令字符串
  15979. * @return { int } 如果当前选区是无序列表返回1,否则返回0
  15980. * @example
  15981. * ```javascript
  15982. * editor.queryCommandState( 'insertunorderedlist' );
  15983. * ```
  15984. */
  15985. /**
  15986. * 查询当前选区内容是否有序列表
  15987. * @command insertunorderedlist
  15988. * @method queryCommandValue
  15989. * @param { String } command 命令字符串
  15990. * @return { String } 返回当前无序列表的类型,值为null或circle,disc,square,dash,dot
  15991. * @example
  15992. * ```javascript
  15993. * editor.queryCommandValue( 'insertunorderedlist' );
  15994. * ```
  15995. */
  15996. me.commands['insertorderedlist'] = me.commands['insertunorderedlist'] = {
  15997. execCommand: function (command, style) {
  15998. if (!style) {
  15999. style = command.toLowerCase() == 'insertorderedlist' ? 'decimal' : 'disc'
  16000. }
  16001. var me = this,
  16002. range = this.selection.getRange(),
  16003. filterFn = function (node) {
  16004. return node.nodeType == 1
  16005. ? node.tagName.toLowerCase() != 'br'
  16006. : !domUtils.isWhitespace(node)
  16007. },
  16008. tag = command.toLowerCase() == 'insertorderedlist' ? 'ol' : 'ul',
  16009. frag = me.document.createDocumentFragment()
  16010. //去掉是因为会出现选到末尾,导致adjustmentBoundary缩到ol/ul的位置
  16011. //range.shrinkBoundary();//.adjustmentBoundary();
  16012. range.adjustmentBoundary().shrinkBoundary()
  16013. var bko = range.createBookmark(true),
  16014. start = getLi(me.document.getElementById(bko.start)),
  16015. modifyStart = 0,
  16016. end = getLi(me.document.getElementById(bko.end)),
  16017. modifyEnd = 0,
  16018. startParent,
  16019. endParent,
  16020. list,
  16021. tmp
  16022. if (start || end) {
  16023. start && (startParent = start.parentNode)
  16024. if (!bko.end) {
  16025. end = start
  16026. }
  16027. end && (endParent = end.parentNode)
  16028. if (startParent === endParent) {
  16029. while (start !== end) {
  16030. tmp = start
  16031. start = start.nextSibling
  16032. if (!domUtils.isBlockElm(tmp.firstChild)) {
  16033. var p = me.document.createElement('p')
  16034. while (tmp.firstChild) {
  16035. p.appendChild(tmp.firstChild)
  16036. }
  16037. tmp.appendChild(p)
  16038. }
  16039. frag.appendChild(tmp)
  16040. }
  16041. tmp = me.document.createElement('span')
  16042. startParent.insertBefore(tmp, end)
  16043. if (!domUtils.isBlockElm(end.firstChild)) {
  16044. p = me.document.createElement('p')
  16045. while (end.firstChild) {
  16046. p.appendChild(end.firstChild)
  16047. }
  16048. end.appendChild(p)
  16049. }
  16050. frag.appendChild(end)
  16051. domUtils.breakParent(tmp, startParent)
  16052. if (domUtils.isEmptyNode(tmp.previousSibling)) {
  16053. domUtils.remove(tmp.previousSibling)
  16054. }
  16055. if (domUtils.isEmptyNode(tmp.nextSibling)) {
  16056. domUtils.remove(tmp.nextSibling)
  16057. }
  16058. var nodeStyle =
  16059. getStyle(startParent) ||
  16060. domUtils.getComputedStyle(startParent, 'list-style-type') ||
  16061. (command.toLowerCase() == 'insertorderedlist' ? 'decimal' : 'disc')
  16062. if (startParent.tagName.toLowerCase() == tag && nodeStyle == style) {
  16063. for (
  16064. var i = 0, ci, tmpFrag = me.document.createDocumentFragment();
  16065. (ci = frag.firstChild);
  16066. ) {
  16067. if (domUtils.isTagNode(ci, 'ol ul')) {
  16068. // 删除时,子列表不处理
  16069. // utils.each(domUtils.getElementsByTagName(ci,'li'),function(li){
  16070. // while(li.firstChild){
  16071. // tmpFrag.appendChild(li.firstChild);
  16072. // }
  16073. //
  16074. // });
  16075. tmpFrag.appendChild(ci)
  16076. } else {
  16077. while (ci.firstChild) {
  16078. tmpFrag.appendChild(ci.firstChild)
  16079. domUtils.remove(ci)
  16080. }
  16081. }
  16082. }
  16083. tmp.parentNode.insertBefore(tmpFrag, tmp)
  16084. } else {
  16085. list = me.document.createElement(tag)
  16086. setListStyle(list, style)
  16087. list.appendChild(frag)
  16088. tmp.parentNode.insertBefore(list, tmp)
  16089. }
  16090. domUtils.remove(tmp)
  16091. list && adjustList(list, tag, style)
  16092. range.moveToBookmark(bko).select()
  16093. return
  16094. }
  16095. //开始
  16096. if (start) {
  16097. while (start) {
  16098. tmp = start.nextSibling
  16099. if (domUtils.isTagNode(start, 'ol ul')) {
  16100. frag.appendChild(start)
  16101. } else {
  16102. var tmpfrag = me.document.createDocumentFragment(),
  16103. hasBlock = 0
  16104. while (start.firstChild) {
  16105. if (domUtils.isBlockElm(start.firstChild)) {
  16106. hasBlock = 1
  16107. }
  16108. tmpfrag.appendChild(start.firstChild)
  16109. }
  16110. if (!hasBlock) {
  16111. var tmpP = me.document.createElement('p')
  16112. tmpP.appendChild(tmpfrag)
  16113. frag.appendChild(tmpP)
  16114. } else {
  16115. frag.appendChild(tmpfrag)
  16116. }
  16117. domUtils.remove(start)
  16118. }
  16119. start = tmp
  16120. }
  16121. startParent.parentNode.insertBefore(frag, startParent.nextSibling)
  16122. if (domUtils.isEmptyNode(startParent)) {
  16123. range.setStartBefore(startParent)
  16124. domUtils.remove(startParent)
  16125. } else {
  16126. range.setStartAfter(startParent)
  16127. }
  16128. modifyStart = 1
  16129. }
  16130. if (end && domUtils.inDoc(endParent, me.document)) {
  16131. //结束
  16132. start = endParent.firstChild
  16133. while (start && start !== end) {
  16134. tmp = start.nextSibling
  16135. if (domUtils.isTagNode(start, 'ol ul')) {
  16136. frag.appendChild(start)
  16137. } else {
  16138. tmpfrag = me.document.createDocumentFragment()
  16139. hasBlock = 0
  16140. while (start.firstChild) {
  16141. if (domUtils.isBlockElm(start.firstChild)) {
  16142. hasBlock = 1
  16143. }
  16144. tmpfrag.appendChild(start.firstChild)
  16145. }
  16146. if (!hasBlock) {
  16147. tmpP = me.document.createElement('p')
  16148. tmpP.appendChild(tmpfrag)
  16149. frag.appendChild(tmpP)
  16150. } else {
  16151. frag.appendChild(tmpfrag)
  16152. }
  16153. domUtils.remove(start)
  16154. }
  16155. start = tmp
  16156. }
  16157. var tmpDiv = domUtils.createElement(me.document, 'div', {
  16158. tmpDiv: 1
  16159. })
  16160. domUtils.moveChild(end, tmpDiv)
  16161. frag.appendChild(tmpDiv)
  16162. domUtils.remove(end)
  16163. endParent.parentNode.insertBefore(frag, endParent)
  16164. range.setEndBefore(endParent)
  16165. if (domUtils.isEmptyNode(endParent)) {
  16166. domUtils.remove(endParent)
  16167. }
  16168. modifyEnd = 1
  16169. }
  16170. }
  16171. if (!modifyStart) {
  16172. range.setStartBefore(me.document.getElementById(bko.start))
  16173. }
  16174. if (bko.end && !modifyEnd) {
  16175. range.setEndAfter(me.document.getElementById(bko.end))
  16176. }
  16177. range.enlarge(true, function (node) {
  16178. return notExchange[node.tagName]
  16179. })
  16180. frag = me.document.createDocumentFragment()
  16181. var bk = range.createBookmark(),
  16182. current = domUtils.getNextDomNode(bk.start, false, filterFn),
  16183. tmpRange = range.cloneRange(),
  16184. tmpNode,
  16185. block = domUtils.isBlockElm
  16186. while (
  16187. current &&
  16188. current !== bk.end &&
  16189. domUtils.getPosition(current, bk.end) & domUtils.POSITION_PRECEDING
  16190. ) {
  16191. if (current.nodeType == 3 || dtd.li[current.tagName]) {
  16192. if (current.nodeType == 1 && dtd.$list[current.tagName]) {
  16193. while (current.firstChild) {
  16194. frag.appendChild(current.firstChild)
  16195. }
  16196. tmpNode = domUtils.getNextDomNode(current, false, filterFn)
  16197. domUtils.remove(current)
  16198. current = tmpNode
  16199. continue
  16200. }
  16201. tmpNode = current
  16202. tmpRange.setStartBefore(current)
  16203. while (
  16204. current &&
  16205. current !== bk.end &&
  16206. (!block(current) || domUtils.isBookmarkNode(current))
  16207. ) {
  16208. tmpNode = current
  16209. current = domUtils.getNextDomNode(current, false, null, function (node) {
  16210. return !notExchange[node.tagName]
  16211. })
  16212. }
  16213. if (current && block(current)) {
  16214. tmp = domUtils.getNextDomNode(tmpNode, false, filterFn)
  16215. if (tmp && domUtils.isBookmarkNode(tmp)) {
  16216. current = domUtils.getNextDomNode(tmp, false, filterFn)
  16217. tmpNode = tmp
  16218. }
  16219. }
  16220. tmpRange.setEndAfter(tmpNode)
  16221. current = domUtils.getNextDomNode(tmpNode, false, filterFn)
  16222. var li = range.document.createElement('li')
  16223. li.appendChild(tmpRange.extractContents())
  16224. if (domUtils.isEmptyNode(li)) {
  16225. var tmpNode = range.document.createElement('p')
  16226. while (li.firstChild) {
  16227. tmpNode.appendChild(li.firstChild)
  16228. }
  16229. li.appendChild(tmpNode)
  16230. }
  16231. frag.appendChild(li)
  16232. } else {
  16233. current = domUtils.getNextDomNode(current, true, filterFn)
  16234. }
  16235. }
  16236. range.moveToBookmark(bk).collapse(true)
  16237. list = me.document.createElement(tag)
  16238. setListStyle(list, style)
  16239. list.appendChild(frag)
  16240. range.insertNode(list)
  16241. //当前list上下看能否合并
  16242. adjustList(list, tag, style)
  16243. //去掉冗余的tmpDiv
  16244. for (
  16245. var i = 0, ci, tmpDivs = domUtils.getElementsByTagName(list, 'div');
  16246. (ci = tmpDivs[i++]);
  16247. ) {
  16248. if (ci.getAttribute('tmpDiv')) {
  16249. domUtils.remove(ci, true)
  16250. }
  16251. }
  16252. range.moveToBookmark(bko).select()
  16253. },
  16254. queryCommandState: function (command) {
  16255. var tag = command.toLowerCase() == 'insertorderedlist' ? 'ol' : 'ul'
  16256. var path = this.selection.getStartElementPath()
  16257. for (var i = 0, ci; (ci = path[i++]); ) {
  16258. if (ci.nodeName == 'TABLE') {
  16259. return 0
  16260. }
  16261. if (tag == ci.nodeName.toLowerCase()) {
  16262. return 1
  16263. }
  16264. }
  16265. return 0
  16266. },
  16267. queryCommandValue: function (command) {
  16268. var tag = command.toLowerCase() == 'insertorderedlist' ? 'ol' : 'ul'
  16269. var path = this.selection.getStartElementPath(),
  16270. node
  16271. for (var i = 0, ci; (ci = path[i++]); ) {
  16272. if (ci.nodeName == 'TABLE') {
  16273. node = null
  16274. break
  16275. }
  16276. if (tag == ci.nodeName.toLowerCase()) {
  16277. node = ci
  16278. break
  16279. }
  16280. }
  16281. return node ? getStyle(node) || domUtils.getComputedStyle(node, 'list-style-type') : null
  16282. }
  16283. }
  16284. }
  16285. // plugins/source.js
  16286. /**
  16287. * 源码编辑插件
  16288. * @file
  16289. * @since 1.2.6.1
  16290. */
  16291. ;(function () {
  16292. var sourceEditors = {
  16293. textarea: function (editor, holder) {
  16294. var textarea = holder.ownerDocument.createElement('textarea')
  16295. textarea.style.cssText =
  16296. 'position:absolute;resize:none;width:100%;height:100%;border:0;padding:0;margin:0;overflow-y:auto;'
  16297. // todo: IE下只有onresize属性可用... 很纠结
  16298. if (browser.ie && browser.version < 8) {
  16299. textarea.style.width = holder.offsetWidth + 'px'
  16300. textarea.style.height = holder.offsetHeight + 'px'
  16301. holder.onresize = function () {
  16302. textarea.style.width = holder.offsetWidth + 'px'
  16303. textarea.style.height = holder.offsetHeight + 'px'
  16304. }
  16305. }
  16306. holder.appendChild(textarea)
  16307. return {
  16308. setContent: function (content) {
  16309. textarea.value = content
  16310. },
  16311. getContent: function () {
  16312. return textarea.value
  16313. },
  16314. select: function () {
  16315. var range
  16316. if (browser.ie) {
  16317. range = textarea.createTextRange()
  16318. range.collapse(true)
  16319. range.select()
  16320. } else {
  16321. //todo: chrome下无法设置焦点
  16322. textarea.setSelectionRange(0, 0)
  16323. textarea.focus()
  16324. }
  16325. },
  16326. dispose: function () {
  16327. holder.removeChild(textarea)
  16328. // todo
  16329. holder.onresize = null
  16330. textarea = null
  16331. holder = null
  16332. }
  16333. }
  16334. },
  16335. codemirror: function (editor, holder) {
  16336. var codeEditor = window.CodeMirror(holder, {
  16337. mode: 'text/html',
  16338. tabMode: 'indent',
  16339. lineNumbers: true,
  16340. lineWrapping: true
  16341. })
  16342. var dom = codeEditor.getWrapperElement()
  16343. dom.style.cssText =
  16344. 'position:absolute;left:0;top:0;width:100%;height:100%;font-family:consolas,"Courier new",monospace;font-size:13px;'
  16345. codeEditor.getScrollerElement().style.cssText =
  16346. 'position:absolute;left:0;top:0;width:100%;height:100%;'
  16347. codeEditor.refresh()
  16348. return {
  16349. getCodeMirror: function () {
  16350. return codeEditor
  16351. },
  16352. setContent: function (content) {
  16353. codeEditor.setValue(content)
  16354. },
  16355. getContent: function () {
  16356. return codeEditor.getValue()
  16357. },
  16358. select: function () {
  16359. codeEditor.focus()
  16360. },
  16361. dispose: function () {
  16362. holder.removeChild(dom)
  16363. dom = null
  16364. codeEditor = null
  16365. }
  16366. }
  16367. }
  16368. }
  16369. UE.plugins['source'] = function () {
  16370. var me = this
  16371. var opt = this.options
  16372. var sourceMode = false
  16373. var sourceEditor
  16374. var orgSetContent
  16375. opt.sourceEditor = browser.ie ? 'textarea' : opt.sourceEditor || 'codemirror'
  16376. me.setOpt({
  16377. sourceEditorFirst: false
  16378. })
  16379. function createSourceEditor(holder) {
  16380. return sourceEditors[
  16381. opt.sourceEditor == 'codemirror' && window.CodeMirror ? 'codemirror' : 'textarea'
  16382. ](me, holder)
  16383. }
  16384. var bakCssText
  16385. //解决在源码模式下getContent不能得到最新的内容问题
  16386. var oldGetContent, bakAddress
  16387. /**
  16388. * 切换源码模式和编辑模式
  16389. * @command source
  16390. * @method execCommand
  16391. * @param { String } cmd 命令字符串
  16392. * @example
  16393. * ```javascript
  16394. * editor.execCommand( 'source');
  16395. * ```
  16396. */
  16397. /**
  16398. * 查询当前编辑区域的状态是源码模式还是可视化模式
  16399. * @command source
  16400. * @method queryCommandState
  16401. * @param { String } cmd 命令字符串
  16402. * @return { int } 如果当前是源码编辑模式,返回1,否则返回0
  16403. * @example
  16404. * ```javascript
  16405. * editor.queryCommandState( 'source' );
  16406. * ```
  16407. */
  16408. me.commands['source'] = {
  16409. execCommand: function () {
  16410. sourceMode = !sourceMode
  16411. if (sourceMode) {
  16412. bakAddress = me.selection.getRange().createAddress(false, true)
  16413. me.undoManger && me.undoManger.save(true)
  16414. if (browser.gecko) {
  16415. me.body.contentEditable = false
  16416. }
  16417. bakCssText = me.iframe.style.cssText
  16418. me.iframe.style.cssText += 'position:absolute;left:-32768px;top:-32768px;'
  16419. me.fireEvent('beforegetcontent')
  16420. var root = UE.htmlparser(me.body.innerHTML)
  16421. me.filterOutputRule(root)
  16422. root.traversal(function (node) {
  16423. if (node.type == 'element') {
  16424. switch (node.tagName) {
  16425. case 'td':
  16426. case 'th':
  16427. case 'caption':
  16428. if (node.children && node.children.length == 1) {
  16429. if (node.firstChild().tagName == 'br') {
  16430. node.removeChild(node.firstChild())
  16431. }
  16432. }
  16433. break
  16434. case 'pre':
  16435. node.innerText(node.innerText().replace(/&nbsp;/g, ' '))
  16436. }
  16437. }
  16438. })
  16439. me.fireEvent('aftergetcontent')
  16440. var content = root.toHtml(true)
  16441. sourceEditor = createSourceEditor(me.iframe.parentNode)
  16442. sourceEditor.setContent(content)
  16443. orgSetContent = me.setContent
  16444. me.setContent = function (html) {
  16445. //这里暂时不触发事件,防止报错
  16446. var root = UE.htmlparser(html)
  16447. me.filterInputRule(root)
  16448. html = root.toHtml()
  16449. sourceEditor.setContent(html)
  16450. }
  16451. setTimeout(function () {
  16452. sourceEditor.select()
  16453. me.addListener('fullscreenchanged', function () {
  16454. try {
  16455. sourceEditor.getCodeMirror().refresh()
  16456. } catch (e) {}
  16457. })
  16458. })
  16459. //重置getContent,源码模式下取值也能是最新的数据
  16460. oldGetContent = me.getContent
  16461. me.getContent = function () {
  16462. return sourceEditor.getContent() || '<p>' + (browser.ie ? '' : '<br/>') + '</p>'
  16463. }
  16464. } else {
  16465. me.iframe.style.cssText = bakCssText
  16466. var cont = sourceEditor.getContent() || '<p>' + (browser.ie ? '' : '<br/>') + '</p>'
  16467. //处理掉block节点前后的空格,有可能会误命中,暂时不考虑
  16468. cont = cont.replace(
  16469. new RegExp('[\\r\\t\\n ]*</?(\\w+)\\s*(?:[^>]*)>', 'g'),
  16470. function (a, b) {
  16471. if (b && !dtd.$inlineWithA[b.toLowerCase()]) {
  16472. return a.replace(/(^[\n\r\t ]*)|([\n\r\t ]*$)/g, '')
  16473. }
  16474. return a.replace(/(^[\n\r\t]*)|([\n\r\t]*$)/g, '')
  16475. }
  16476. )
  16477. me.setContent = orgSetContent
  16478. me.setContent(cont)
  16479. sourceEditor.dispose()
  16480. sourceEditor = null
  16481. //还原getContent方法
  16482. me.getContent = oldGetContent
  16483. var first = me.body.firstChild
  16484. //trace:1106 都删除空了,下边会报错,所以补充一个p占位
  16485. if (!first) {
  16486. me.body.innerHTML = '<p>' + (browser.ie ? '' : '<br/>') + '</p>'
  16487. first = me.body.firstChild
  16488. }
  16489. //要在ifm为显示时ff才能取到selection,否则报错
  16490. //这里不能比较位置了
  16491. me.undoManger && me.undoManger.save(true)
  16492. if (browser.gecko) {
  16493. var input = document.createElement('input')
  16494. input.style.cssText = 'position:absolute;left:0;top:-32768px'
  16495. document.body.appendChild(input)
  16496. me.body.contentEditable = false
  16497. setTimeout(function () {
  16498. domUtils.setViewportOffset(input, { left: -32768, top: 0 })
  16499. input.focus()
  16500. setTimeout(function () {
  16501. me.body.contentEditable = true
  16502. me.selection.getRange().moveToAddress(bakAddress).select(true)
  16503. domUtils.remove(input)
  16504. })
  16505. })
  16506. } else {
  16507. //ie下有可能报错,比如在代码顶头的情况
  16508. try {
  16509. me.selection.getRange().moveToAddress(bakAddress).select(true)
  16510. } catch (e) {}
  16511. }
  16512. }
  16513. this.fireEvent('sourcemodechanged', sourceMode)
  16514. },
  16515. queryCommandState: function () {
  16516. return sourceMode | 0
  16517. },
  16518. notNeedUndo: 1
  16519. }
  16520. var oldQueryCommandState = me.queryCommandState
  16521. me.queryCommandState = function (cmdName) {
  16522. cmdName = cmdName.toLowerCase()
  16523. if (sourceMode) {
  16524. //源码模式下可以开启的命令
  16525. return cmdName in
  16526. {
  16527. source: 1,
  16528. fullscreen: 1
  16529. }
  16530. ? 1
  16531. : -1
  16532. }
  16533. return oldQueryCommandState.apply(this, arguments)
  16534. }
  16535. if (opt.sourceEditor == 'codemirror') {
  16536. me.addListener('ready', function () {
  16537. utils.loadFile(
  16538. document,
  16539. {
  16540. src:
  16541. opt.codeMirrorJsUrl ||
  16542. opt.UEDITOR_HOME_URL + 'third-party/codemirror/codemirror.js',
  16543. tag: 'script',
  16544. type: 'text/javascript',
  16545. defer: 'defer'
  16546. },
  16547. function () {
  16548. if (opt.sourceEditorFirst) {
  16549. setTimeout(function () {
  16550. me.execCommand('source')
  16551. }, 0)
  16552. }
  16553. }
  16554. )
  16555. utils.loadFile(document, {
  16556. tag: 'link',
  16557. rel: 'stylesheet',
  16558. type: 'text/css',
  16559. href:
  16560. opt.codeMirrorCssUrl || opt.UEDITOR_HOME_URL + 'third-party/codemirror/codemirror.css'
  16561. })
  16562. })
  16563. }
  16564. }
  16565. })()
  16566. // plugins/enterkey.js
  16567. ///import core
  16568. ///import plugins/undo.js
  16569. ///commands 设置回车标签p或br
  16570. ///commandsName EnterKey
  16571. ///commandsTitle 设置回车标签p或br
  16572. /**
  16573. * @description 处理回车
  16574. * @author zhanyi
  16575. */
  16576. UE.plugins['enterkey'] = function () {
  16577. var hTag,
  16578. me = this,
  16579. tag = me.options.enterTag
  16580. me.addListener('keyup', function (type, evt) {
  16581. var keyCode = evt.keyCode || evt.which
  16582. if (keyCode == 13) {
  16583. var range = me.selection.getRange(),
  16584. start = range.startContainer,
  16585. doSave
  16586. //修正在h1-h6里边回车后不能嵌套p的问题
  16587. if (!browser.ie) {
  16588. if (/h\d/i.test(hTag)) {
  16589. if (browser.gecko) {
  16590. var h = domUtils.findParentByTagName(
  16591. start,
  16592. ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'caption', 'table'],
  16593. true
  16594. )
  16595. if (!h) {
  16596. me.document.execCommand('formatBlock', false, '<p>')
  16597. doSave = 1
  16598. }
  16599. } else {
  16600. //chrome remove div
  16601. if (start.nodeType == 1) {
  16602. var tmp = me.document.createTextNode(''),
  16603. div
  16604. range.insertNode(tmp)
  16605. div = domUtils.findParentByTagName(tmp, 'div', true)
  16606. if (div) {
  16607. var p = me.document.createElement('p')
  16608. while (div.firstChild) {
  16609. p.appendChild(div.firstChild)
  16610. }
  16611. div.parentNode.insertBefore(p, div)
  16612. domUtils.remove(div)
  16613. range.setStartBefore(tmp).setCursor()
  16614. doSave = 1
  16615. }
  16616. domUtils.remove(tmp)
  16617. }
  16618. }
  16619. if (me.undoManger && doSave) {
  16620. me.undoManger.save()
  16621. }
  16622. }
  16623. //没有站位符,会出现多行的问题
  16624. browser.opera && range.select()
  16625. } else {
  16626. me.fireEvent('saveScene', true, true)
  16627. }
  16628. }
  16629. })
  16630. me.addListener('keydown', function (type, evt) {
  16631. var keyCode = evt.keyCode || evt.which
  16632. if (keyCode == 13) {
  16633. //回车
  16634. if (me.fireEvent('beforeenterkeydown')) {
  16635. domUtils.preventDefault(evt)
  16636. return
  16637. }
  16638. me.fireEvent('saveScene', true, true)
  16639. hTag = ''
  16640. var range = me.selection.getRange()
  16641. if (!range.collapsed) {
  16642. //跨td不能删
  16643. var start = range.startContainer,
  16644. end = range.endContainer,
  16645. startTd = domUtils.findParentByTagName(start, 'td', true),
  16646. endTd = domUtils.findParentByTagName(end, 'td', true)
  16647. if (
  16648. (startTd && endTd && startTd !== endTd) ||
  16649. (!startTd && endTd) ||
  16650. (startTd && !endTd)
  16651. ) {
  16652. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false)
  16653. return
  16654. }
  16655. }
  16656. if (tag == 'p') {
  16657. if (!browser.ie) {
  16658. start = domUtils.findParentByTagName(
  16659. range.startContainer,
  16660. ['ol', 'ul', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'caption'],
  16661. true
  16662. )
  16663. //opera下执行formatblock会在table的场景下有问题,回车在opera原生支持很好,所以暂时在opera去掉调用这个原生的command
  16664. //trace:2431
  16665. if (!start && !browser.opera) {
  16666. me.document.execCommand('formatBlock', false, '<p>')
  16667. if (browser.gecko) {
  16668. range = me.selection.getRange()
  16669. start = domUtils.findParentByTagName(range.startContainer, 'p', true)
  16670. start && domUtils.removeDirtyAttr(start)
  16671. }
  16672. } else {
  16673. hTag = start.tagName
  16674. start.tagName.toLowerCase() == 'p' && browser.gecko && domUtils.removeDirtyAttr(start)
  16675. }
  16676. }
  16677. } else {
  16678. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false)
  16679. if (!range.collapsed) {
  16680. range.deleteContents()
  16681. start = range.startContainer
  16682. if (start.nodeType == 1 && (start = start.childNodes[range.startOffset])) {
  16683. while (start.nodeType == 1) {
  16684. if (dtd.$empty[start.tagName]) {
  16685. range.setStartBefore(start).setCursor()
  16686. if (me.undoManger) {
  16687. me.undoManger.save()
  16688. }
  16689. return false
  16690. }
  16691. if (!start.firstChild) {
  16692. var br = range.document.createElement('br')
  16693. start.appendChild(br)
  16694. range.setStart(start, 0).setCursor()
  16695. if (me.undoManger) {
  16696. me.undoManger.save()
  16697. }
  16698. return false
  16699. }
  16700. start = start.firstChild
  16701. }
  16702. if (start === range.startContainer.childNodes[range.startOffset]) {
  16703. br = range.document.createElement('br')
  16704. range.insertNode(br).setCursor()
  16705. } else {
  16706. range.setStart(start, 0).setCursor()
  16707. }
  16708. } else {
  16709. br = range.document.createElement('br')
  16710. range.insertNode(br).setStartAfter(br).setCursor()
  16711. }
  16712. } else {
  16713. br = range.document.createElement('br')
  16714. range.insertNode(br)
  16715. var parent = br.parentNode
  16716. if (parent.lastChild === br) {
  16717. br.parentNode.insertBefore(br.cloneNode(true), br)
  16718. range.setStartBefore(br)
  16719. } else {
  16720. range.setStartAfter(br)
  16721. }
  16722. range.setCursor()
  16723. }
  16724. }
  16725. }
  16726. })
  16727. }
  16728. // plugins/keystrokes.js
  16729. /* 处理特殊键的兼容性问题 */
  16730. UE.plugins['keystrokes'] = function () {
  16731. var me = this
  16732. var collapsed = true
  16733. me.addListener('keydown', function (type, evt) {
  16734. var keyCode = evt.keyCode || evt.which,
  16735. rng = me.selection.getRange()
  16736. //处理全选的情况
  16737. if (
  16738. !rng.collapsed &&
  16739. !(evt.ctrlKey || evt.shiftKey || evt.altKey || evt.metaKey) &&
  16740. ((keyCode >= 65 && keyCode <= 90) ||
  16741. (keyCode >= 48 && keyCode <= 57) ||
  16742. (keyCode >= 96 && keyCode <= 111) ||
  16743. {
  16744. 13: 1,
  16745. 8: 1,
  16746. 46: 1
  16747. }[keyCode])
  16748. ) {
  16749. var tmpNode = rng.startContainer
  16750. if (domUtils.isFillChar(tmpNode)) {
  16751. rng.setStartBefore(tmpNode)
  16752. }
  16753. tmpNode = rng.endContainer
  16754. if (domUtils.isFillChar(tmpNode)) {
  16755. rng.setEndAfter(tmpNode)
  16756. }
  16757. rng.txtToElmBoundary()
  16758. //结束边界可能放到了br的前边,要把br包含进来
  16759. // x[xxx]<br/>
  16760. if (rng.endContainer && rng.endContainer.nodeType == 1) {
  16761. tmpNode = rng.endContainer.childNodes[rng.endOffset]
  16762. if (tmpNode && domUtils.isBr(tmpNode)) {
  16763. rng.setEndAfter(tmpNode)
  16764. }
  16765. }
  16766. if (rng.startOffset == 0) {
  16767. tmpNode = rng.startContainer
  16768. if (domUtils.isBoundaryNode(tmpNode, 'firstChild')) {
  16769. tmpNode = rng.endContainer
  16770. if (
  16771. rng.endOffset ==
  16772. (tmpNode.nodeType == 3 ? tmpNode.nodeValue.length : tmpNode.childNodes.length) &&
  16773. domUtils.isBoundaryNode(tmpNode, 'lastChild')
  16774. ) {
  16775. me.fireEvent('saveScene')
  16776. me.body.innerHTML = '<p>' + (browser.ie ? '' : '<br/>') + '</p>'
  16777. rng.setStart(me.body.firstChild, 0).setCursor(false, true)
  16778. me._selectionChange()
  16779. return
  16780. }
  16781. }
  16782. }
  16783. }
  16784. //处理backspace
  16785. if (keyCode == keymap.Backspace) {
  16786. rng = me.selection.getRange()
  16787. collapsed = rng.collapsed
  16788. if (me.fireEvent('delkeydown', evt)) {
  16789. return
  16790. }
  16791. var start, end
  16792. //避免按两次删除才能生效的问题
  16793. if (rng.collapsed && rng.inFillChar()) {
  16794. start = rng.startContainer
  16795. if (domUtils.isFillChar(start)) {
  16796. rng.setStartBefore(start).shrinkBoundary(true).collapse(true)
  16797. domUtils.remove(start)
  16798. } else {
  16799. start.nodeValue = start.nodeValue.replace(new RegExp('^' + domUtils.fillChar), '')
  16800. rng.startOffset--
  16801. rng.collapse(true).select(true)
  16802. }
  16803. }
  16804. //解决选中control元素不能删除的问题
  16805. if ((start = rng.getClosedNode())) {
  16806. me.fireEvent('saveScene')
  16807. rng.setStartBefore(start)
  16808. domUtils.remove(start)
  16809. rng.setCursor()
  16810. me.fireEvent('saveScene')
  16811. domUtils.preventDefault(evt)
  16812. return
  16813. }
  16814. //阻止在table上的删除
  16815. if (!browser.ie) {
  16816. start = domUtils.findParentByTagName(rng.startContainer, 'table', true)
  16817. end = domUtils.findParentByTagName(rng.endContainer, 'table', true)
  16818. if ((start && !end) || (!start && end) || start !== end) {
  16819. evt.preventDefault()
  16820. return
  16821. }
  16822. }
  16823. }
  16824. //处理tab键的逻辑
  16825. if (keyCode == keymap.Tab) {
  16826. //不处理以下标签
  16827. var excludeTagNameForTabKey = {
  16828. ol: 1,
  16829. ul: 1,
  16830. table: 1
  16831. }
  16832. //处理组件里的tab按下事件
  16833. if (me.fireEvent('tabkeydown', evt)) {
  16834. domUtils.preventDefault(evt)
  16835. return
  16836. }
  16837. var range = me.selection.getRange()
  16838. me.fireEvent('saveScene')
  16839. for (
  16840. var i = 0,
  16841. txt = '',
  16842. tabSize = me.options.tabSize || 4,
  16843. tabNode = me.options.tabNode || '&nbsp;';
  16844. i < tabSize;
  16845. i++
  16846. ) {
  16847. txt += tabNode
  16848. }
  16849. var span = me.document.createElement('span')
  16850. span.innerHTML = txt + domUtils.fillChar
  16851. if (range.collapsed) {
  16852. range.insertNode(span.cloneNode(true).firstChild).setCursor(true)
  16853. } else {
  16854. var filterFn = function (node) {
  16855. return domUtils.isBlockElm(node) && !excludeTagNameForTabKey[node.tagName.toLowerCase()]
  16856. }
  16857. //普通的情况
  16858. start = domUtils.findParent(range.startContainer, filterFn, true)
  16859. end = domUtils.findParent(range.endContainer, filterFn, true)
  16860. if (start && end && start === end) {
  16861. range.deleteContents()
  16862. range.insertNode(span.cloneNode(true).firstChild).setCursor(true)
  16863. } else {
  16864. var bookmark = range.createBookmark()
  16865. range.enlarge(true)
  16866. var bookmark2 = range.createBookmark(),
  16867. current = domUtils.getNextDomNode(bookmark2.start, false, filterFn)
  16868. while (
  16869. current &&
  16870. !(domUtils.getPosition(current, bookmark2.end) & domUtils.POSITION_FOLLOWING)
  16871. ) {
  16872. current.insertBefore(span.cloneNode(true).firstChild, current.firstChild)
  16873. current = domUtils.getNextDomNode(current, false, filterFn)
  16874. }
  16875. range.moveToBookmark(bookmark2).moveToBookmark(bookmark).select()
  16876. }
  16877. }
  16878. domUtils.preventDefault(evt)
  16879. }
  16880. //trace:1634
  16881. //ff的del键在容器空的时候,也会删除
  16882. if (browser.gecko && keyCode == 46) {
  16883. range = me.selection.getRange()
  16884. if (range.collapsed) {
  16885. start = range.startContainer
  16886. if (domUtils.isEmptyBlock(start)) {
  16887. var parent = start.parentNode
  16888. while (domUtils.getChildCount(parent) == 1 && !domUtils.isBody(parent)) {
  16889. start = parent
  16890. parent = parent.parentNode
  16891. }
  16892. if (start === parent.lastChild) evt.preventDefault()
  16893. return
  16894. }
  16895. }
  16896. }
  16897. })
  16898. me.addListener('keyup', function (type, evt) {
  16899. var keyCode = evt.keyCode || evt.which,
  16900. rng,
  16901. me = this
  16902. if (keyCode == keymap.Backspace) {
  16903. if (me.fireEvent('delkeyup')) {
  16904. return
  16905. }
  16906. rng = me.selection.getRange()
  16907. if (rng.collapsed) {
  16908. var tmpNode,
  16909. autoClearTagName = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']
  16910. if (
  16911. (tmpNode = domUtils.findParentByTagName(rng.startContainer, autoClearTagName, true))
  16912. ) {
  16913. if (domUtils.isEmptyBlock(tmpNode)) {
  16914. var pre = tmpNode.previousSibling
  16915. if (pre && pre.nodeName != 'TABLE') {
  16916. domUtils.remove(tmpNode)
  16917. rng.setStartAtLast(pre).setCursor(false, true)
  16918. return
  16919. } else {
  16920. var next = tmpNode.nextSibling
  16921. if (next && next.nodeName != 'TABLE') {
  16922. domUtils.remove(tmpNode)
  16923. rng.setStartAtFirst(next).setCursor(false, true)
  16924. return
  16925. }
  16926. }
  16927. }
  16928. }
  16929. //处理当删除到body时,要重新给p标签展位
  16930. if (domUtils.isBody(rng.startContainer)) {
  16931. var tmpNode = domUtils.createElement(me.document, 'p', {
  16932. innerHTML: browser.ie ? domUtils.fillChar : '<br/>'
  16933. })
  16934. rng.insertNode(tmpNode).setStart(tmpNode, 0).setCursor(false, true)
  16935. }
  16936. }
  16937. //chrome下如果删除了inline标签,浏览器会有记忆,在输入文字还是会套上刚才删除的标签,所以这里再选一次就不会了
  16938. if (
  16939. !collapsed &&
  16940. (rng.startContainer.nodeType == 3 ||
  16941. (rng.startContainer.nodeType == 1 && domUtils.isEmptyBlock(rng.startContainer)))
  16942. ) {
  16943. if (browser.ie) {
  16944. var span = rng.document.createElement('span')
  16945. rng.insertNode(span).setStartBefore(span).collapse(true)
  16946. rng.select()
  16947. domUtils.remove(span)
  16948. } else {
  16949. rng.select()
  16950. }
  16951. }
  16952. }
  16953. })
  16954. }
  16955. // plugins/fiximgclick.js
  16956. ///import core
  16957. ///commands 修复chrome下图片不能点击的问题,出现八个角可改变大小
  16958. ///commandsName FixImgClick
  16959. ///commandsTitle 修复chrome下图片不能点击的问题,出现八个角可改变大小
  16960. //修复chrome下图片不能点击的问题,出现八个角可改变大小
  16961. UE.plugins['fiximgclick'] = (function () {
  16962. var elementUpdated = false
  16963. function Scale() {
  16964. this.editor = null
  16965. this.resizer = null
  16966. this.cover = null
  16967. this.doc = document
  16968. this.prePos = { x: 0, y: 0 }
  16969. this.startPos = { x: 0, y: 0 }
  16970. }
  16971. ;(function () {
  16972. var rect = [
  16973. //[left, top, width, height]
  16974. [0, 0, -1, -1],
  16975. [0, 0, 0, -1],
  16976. [0, 0, 1, -1],
  16977. [0, 0, -1, 0],
  16978. [0, 0, 1, 0],
  16979. [0, 0, -1, 1],
  16980. [0, 0, 0, 1],
  16981. [0, 0, 1, 1]
  16982. ]
  16983. Scale.prototype = {
  16984. init: function (editor) {
  16985. var me = this
  16986. me.editor = editor
  16987. me.startPos = this.prePos = { x: 0, y: 0 }
  16988. me.dragId = -1
  16989. var hands = [],
  16990. cover = (me.cover = document.createElement('div')),
  16991. resizer = (me.resizer = document.createElement('div'))
  16992. cover.id = me.editor.ui.id + '_imagescale_cover'
  16993. cover.style.cssText =
  16994. 'position:absolute;display:none;z-index:' +
  16995. me.editor.options.zIndex +
  16996. ';filter:alpha(opacity=0); opacity:0;background:#CCC;'
  16997. domUtils.on(cover, 'mousedown click', function () {
  16998. me.hide()
  16999. })
  17000. for (i = 0; i < 8; i++) {
  17001. hands.push('<span class="edui-editor-imagescale-hand' + i + '"></span>')
  17002. }
  17003. resizer.id = me.editor.ui.id + '_imagescale'
  17004. resizer.className = 'edui-editor-imagescale'
  17005. resizer.innerHTML = hands.join('')
  17006. resizer.style.cssText +=
  17007. ';display:none;border:1px solid #3b77ff;z-index:' + me.editor.options.zIndex + ';'
  17008. me.editor.ui.getDom().appendChild(cover)
  17009. me.editor.ui.getDom().appendChild(resizer)
  17010. me.initStyle()
  17011. me.initEvents()
  17012. },
  17013. initStyle: function () {
  17014. utils.cssRule(
  17015. 'imagescale',
  17016. '.edui-editor-imagescale{display:none;position:absolute;border:1px solid #38B2CE;cursor:hand;-webkit-box-sizing: content-box;-moz-box-sizing: content-box;box-sizing: content-box;}' +
  17017. '.edui-editor-imagescale span{position:absolute;width:6px;height:6px;overflow:hidden;font-size:0px;display:block;background-color:#3C9DD0;}' +
  17018. '.edui-editor-imagescale .edui-editor-imagescale-hand0{cursor:nw-resize;top:0;margin-top:-4px;left:0;margin-left:-4px;}' +
  17019. '.edui-editor-imagescale .edui-editor-imagescale-hand1{cursor:n-resize;top:0;margin-top:-4px;left:50%;margin-left:-4px;}' +
  17020. '.edui-editor-imagescale .edui-editor-imagescale-hand2{cursor:ne-resize;top:0;margin-top:-4px;left:100%;margin-left:-3px;}' +
  17021. '.edui-editor-imagescale .edui-editor-imagescale-hand3{cursor:w-resize;top:50%;margin-top:-4px;left:0;margin-left:-4px;}' +
  17022. '.edui-editor-imagescale .edui-editor-imagescale-hand4{cursor:e-resize;top:50%;margin-top:-4px;left:100%;margin-left:-3px;}' +
  17023. '.edui-editor-imagescale .edui-editor-imagescale-hand5{cursor:sw-resize;top:100%;margin-top:-3px;left:0;margin-left:-4px;}' +
  17024. '.edui-editor-imagescale .edui-editor-imagescale-hand6{cursor:s-resize;top:100%;margin-top:-3px;left:50%;margin-left:-4px;}' +
  17025. '.edui-editor-imagescale .edui-editor-imagescale-hand7{cursor:se-resize;top:100%;margin-top:-3px;left:100%;margin-left:-3px;}'
  17026. )
  17027. },
  17028. initEvents: function () {
  17029. var me = this
  17030. me.startPos.x = me.startPos.y = 0
  17031. me.isDraging = false
  17032. },
  17033. _eventHandler: function (e) {
  17034. var me = this
  17035. switch (e.type) {
  17036. case 'mousedown':
  17037. var hand = e.target || e.srcElement,
  17038. hand
  17039. if (hand.className.indexOf('edui-editor-imagescale-hand') != -1 && me.dragId == -1) {
  17040. me.dragId = hand.className.slice(-1)
  17041. me.startPos.x = me.prePos.x = e.clientX
  17042. me.startPos.y = me.prePos.y = e.clientY
  17043. domUtils.on(me.doc, 'mousemove', me.proxy(me._eventHandler, me))
  17044. }
  17045. break
  17046. case 'mousemove':
  17047. if (me.dragId != -1) {
  17048. me.updateContainerStyle(me.dragId, {
  17049. x: e.clientX - me.prePos.x,
  17050. y: e.clientY - me.prePos.y
  17051. })
  17052. me.prePos.x = e.clientX
  17053. me.prePos.y = e.clientY
  17054. elementUpdated = true
  17055. me.updateTargetElement()
  17056. }
  17057. break
  17058. case 'mouseup':
  17059. if (me.dragId != -1) {
  17060. me.updateContainerStyle(me.dragId, {
  17061. x: e.clientX - me.prePos.x,
  17062. y: e.clientY - me.prePos.y
  17063. })
  17064. me.updateTargetElement()
  17065. if (me.target.parentNode) me.attachTo(me.target)
  17066. me.dragId = -1
  17067. }
  17068. domUtils.un(me.doc, 'mousemove', me.proxy(me._eventHandler, me))
  17069. //修复只是点击挪动点,但没有改变大小,不应该触发contentchange
  17070. if (elementUpdated) {
  17071. elementUpdated = false
  17072. me.editor.fireEvent('contentchange')
  17073. }
  17074. break
  17075. default:
  17076. break
  17077. }
  17078. },
  17079. updateTargetElement: function () {
  17080. var me = this
  17081. domUtils.setStyles(me.target, {
  17082. width: me.resizer.style.width,
  17083. height: me.resizer.style.height
  17084. })
  17085. me.target.width = parseInt(me.resizer.style.width)
  17086. me.target.height = parseInt(me.resizer.style.height)
  17087. me.attachTo(me.target)
  17088. },
  17089. updateContainerStyle: function (dir, offset) {
  17090. var me = this,
  17091. dom = me.resizer,
  17092. tmp
  17093. if (rect[dir][0] != 0) {
  17094. tmp = parseInt(dom.style.left) + offset.x
  17095. dom.style.left = me._validScaledProp('left', tmp) + 'px'
  17096. }
  17097. if (rect[dir][1] != 0) {
  17098. tmp = parseInt(dom.style.top) + offset.y
  17099. dom.style.top = me._validScaledProp('top', tmp) + 'px'
  17100. }
  17101. if (rect[dir][2] != 0) {
  17102. tmp = dom.clientWidth + rect[dir][2] * offset.x
  17103. dom.style.width = me._validScaledProp('width', tmp) + 'px'
  17104. }
  17105. if (rect[dir][3] != 0) {
  17106. tmp = dom.clientHeight + rect[dir][3] * offset.y
  17107. dom.style.height = me._validScaledProp('height', tmp) + 'px'
  17108. }
  17109. },
  17110. _validScaledProp: function (prop, value) {
  17111. var ele = this.resizer,
  17112. wrap = document
  17113. value = isNaN(value) ? 0 : value
  17114. switch (prop) {
  17115. case 'left':
  17116. return value < 0
  17117. ? 0
  17118. : value + ele.clientWidth > wrap.clientWidth
  17119. ? wrap.clientWidth - ele.clientWidth
  17120. : value
  17121. case 'top':
  17122. return value < 0
  17123. ? 0
  17124. : value + ele.clientHeight > wrap.clientHeight
  17125. ? wrap.clientHeight - ele.clientHeight
  17126. : value
  17127. case 'width':
  17128. return value <= 0
  17129. ? 1
  17130. : value + ele.offsetLeft > wrap.clientWidth
  17131. ? wrap.clientWidth - ele.offsetLeft
  17132. : value
  17133. case 'height':
  17134. return value <= 0
  17135. ? 1
  17136. : value + ele.offsetTop > wrap.clientHeight
  17137. ? wrap.clientHeight - ele.offsetTop
  17138. : value
  17139. }
  17140. },
  17141. hideCover: function () {
  17142. this.cover.style.display = 'none'
  17143. },
  17144. showCover: function () {
  17145. var me = this,
  17146. editorPos = domUtils.getXY(me.editor.ui.getDom()),
  17147. iframePos = domUtils.getXY(me.editor.iframe)
  17148. domUtils.setStyles(me.cover, {
  17149. width: me.editor.iframe.offsetWidth + 'px',
  17150. height: me.editor.iframe.offsetHeight + 'px',
  17151. top: iframePos.y - editorPos.y + 'px',
  17152. left: iframePos.x - editorPos.x + 'px',
  17153. position: 'absolute',
  17154. display: ''
  17155. })
  17156. },
  17157. show: function (targetObj) {
  17158. var me = this
  17159. me.resizer.style.display = 'block'
  17160. if (targetObj) me.attachTo(targetObj)
  17161. domUtils.on(this.resizer, 'mousedown', me.proxy(me._eventHandler, me))
  17162. domUtils.on(me.doc, 'mouseup', me.proxy(me._eventHandler, me))
  17163. me.showCover()
  17164. me.editor.fireEvent('afterscaleshow', me)
  17165. me.editor.fireEvent('saveScene')
  17166. },
  17167. hide: function () {
  17168. var me = this
  17169. me.hideCover()
  17170. me.resizer.style.display = 'none'
  17171. domUtils.un(me.resizer, 'mousedown', me.proxy(me._eventHandler, me))
  17172. domUtils.un(me.doc, 'mouseup', me.proxy(me._eventHandler, me))
  17173. me.editor.fireEvent('afterscalehide', me)
  17174. },
  17175. proxy: function (fn, context) {
  17176. return function (e) {
  17177. return fn.apply(context || this, arguments)
  17178. }
  17179. },
  17180. attachTo: function (targetObj) {
  17181. var me = this,
  17182. target = (me.target = targetObj),
  17183. resizer = this.resizer,
  17184. imgPos = domUtils.getXY(target),
  17185. iframePos = domUtils.getXY(me.editor.iframe),
  17186. editorPos = domUtils.getXY(resizer.parentNode)
  17187. domUtils.setStyles(resizer, {
  17188. width: target.width + 'px',
  17189. height: target.height + 'px',
  17190. left:
  17191. iframePos.x +
  17192. imgPos.x -
  17193. me.editor.document.body.scrollLeft -
  17194. editorPos.x -
  17195. parseInt(resizer.style.borderLeftWidth) +
  17196. 'px',
  17197. top:
  17198. iframePos.y +
  17199. imgPos.y -
  17200. me.editor.document.body.scrollTop -
  17201. editorPos.y -
  17202. parseInt(resizer.style.borderTopWidth) +
  17203. 'px'
  17204. })
  17205. }
  17206. }
  17207. })()
  17208. return function () {
  17209. var me = this,
  17210. imageScale
  17211. me.setOpt('imageScaleEnabled', true)
  17212. if (!browser.ie && me.options.imageScaleEnabled) {
  17213. me.addListener('click', function (type, e) {
  17214. var range = me.selection.getRange(),
  17215. img = range.getClosedNode()
  17216. if (img && img.tagName == 'IMG' && me.body.contentEditable != 'false') {
  17217. if (
  17218. img.className.indexOf('edui-faked-music') != -1 ||
  17219. img.getAttribute('anchorname') ||
  17220. domUtils.hasClass(img, 'loadingclass') ||
  17221. domUtils.hasClass(img, 'loaderrorclass')
  17222. ) {
  17223. return
  17224. }
  17225. if (!imageScale) {
  17226. imageScale = new Scale()
  17227. imageScale.init(me)
  17228. me.ui.getDom().appendChild(imageScale.resizer)
  17229. var _keyDownHandler = function (e) {
  17230. imageScale.hide()
  17231. if (imageScale.target)
  17232. me.selection.getRange().selectNode(imageScale.target).select()
  17233. },
  17234. _mouseDownHandler = function (e) {
  17235. var ele = e.target || e.srcElement
  17236. if (
  17237. ele &&
  17238. (ele.className === undefined ||
  17239. ele.className.indexOf('edui-editor-imagescale') == -1)
  17240. ) {
  17241. _keyDownHandler(e)
  17242. }
  17243. },
  17244. timer
  17245. me.addListener('afterscaleshow', function (e) {
  17246. me.addListener('beforekeydown', _keyDownHandler)
  17247. me.addListener('beforemousedown', _mouseDownHandler)
  17248. domUtils.on(document, 'keydown', _keyDownHandler)
  17249. domUtils.on(document, 'mousedown', _mouseDownHandler)
  17250. me.selection.getNative().removeAllRanges()
  17251. })
  17252. me.addListener('afterscalehide', function (e) {
  17253. me.removeListener('beforekeydown', _keyDownHandler)
  17254. me.removeListener('beforemousedown', _mouseDownHandler)
  17255. domUtils.un(document, 'keydown', _keyDownHandler)
  17256. domUtils.un(document, 'mousedown', _mouseDownHandler)
  17257. var target = imageScale.target
  17258. if (target.parentNode) {
  17259. me.selection.getRange().selectNode(target).select()
  17260. }
  17261. })
  17262. //TODO 有iframe的情况,mousedown不能往下传。。
  17263. domUtils.on(imageScale.resizer, 'mousedown', function (e) {
  17264. me.selection.getNative().removeAllRanges()
  17265. var ele = e.target || e.srcElement
  17266. if (ele && ele.className.indexOf('edui-editor-imagescale-hand') == -1) {
  17267. timer = setTimeout(function () {
  17268. imageScale.hide()
  17269. if (imageScale.target) me.selection.getRange().selectNode(ele).select()
  17270. }, 200)
  17271. }
  17272. })
  17273. domUtils.on(imageScale.resizer, 'mouseup', function (e) {
  17274. var ele = e.target || e.srcElement
  17275. if (ele && ele.className.indexOf('edui-editor-imagescale-hand') == -1) {
  17276. clearTimeout(timer)
  17277. }
  17278. })
  17279. }
  17280. imageScale.show(img)
  17281. } else {
  17282. if (imageScale && imageScale.resizer.style.display != 'none') imageScale.hide()
  17283. }
  17284. })
  17285. }
  17286. if (browser.webkit) {
  17287. me.addListener('click', function (type, e) {
  17288. if (e.target.tagName == 'IMG' && me.body.contentEditable != 'false') {
  17289. var range = new dom.Range(me.document)
  17290. range.selectNode(e.target).select()
  17291. }
  17292. })
  17293. }
  17294. }
  17295. })()
  17296. // plugins/autolink.js
  17297. ///import core
  17298. ///commands 为非ie浏览器自动添加a标签
  17299. ///commandsName AutoLink
  17300. ///commandsTitle 自动增加链接
  17301. /**
  17302. * @description 为非ie浏览器自动添加a标签
  17303. * @author zhanyi
  17304. */
  17305. UE.plugin.register(
  17306. 'autolink',
  17307. function () {
  17308. var cont = 0
  17309. return !browser.ie
  17310. ? {
  17311. bindEvents: {
  17312. reset: function () {
  17313. cont = 0
  17314. },
  17315. keydown: function (type, evt) {
  17316. var me = this
  17317. var keyCode = evt.keyCode || evt.which
  17318. if (keyCode == 32 || keyCode == 13) {
  17319. var sel = me.selection.getNative(),
  17320. range = sel.getRangeAt(0).cloneRange(),
  17321. offset,
  17322. charCode
  17323. var start = range.startContainer
  17324. while (start.nodeType == 1 && range.startOffset > 0) {
  17325. start = range.startContainer.childNodes[range.startOffset - 1]
  17326. if (!start) {
  17327. break
  17328. }
  17329. range.setStart(
  17330. start,
  17331. start.nodeType == 1 ? start.childNodes.length : start.nodeValue.length
  17332. )
  17333. range.collapse(true)
  17334. start = range.startContainer
  17335. }
  17336. do {
  17337. if (range.startOffset == 0) {
  17338. start = range.startContainer.previousSibling
  17339. while (start && start.nodeType == 1) {
  17340. start = start.lastChild
  17341. }
  17342. if (!start || domUtils.isFillChar(start)) {
  17343. break
  17344. }
  17345. offset = start.nodeValue.length
  17346. } else {
  17347. start = range.startContainer
  17348. offset = range.startOffset
  17349. }
  17350. range.setStart(start, offset - 1)
  17351. charCode = range.toString().charCodeAt(0)
  17352. } while (charCode != 160 && charCode != 32)
  17353. if (
  17354. range
  17355. .toString()
  17356. .replace(new RegExp(domUtils.fillChar, 'g'), '')
  17357. .match(/(?:https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.)/i)
  17358. ) {
  17359. while (range.toString().length) {
  17360. if (
  17361. /^(?:https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.)/i.test(range.toString())
  17362. ) {
  17363. break
  17364. }
  17365. try {
  17366. range.setStart(range.startContainer, range.startOffset + 1)
  17367. } catch (e) {
  17368. //trace:2121
  17369. var start = range.startContainer
  17370. while (!(next = start.nextSibling)) {
  17371. if (domUtils.isBody(start)) {
  17372. return
  17373. }
  17374. start = start.parentNode
  17375. }
  17376. range.setStart(next, 0)
  17377. }
  17378. }
  17379. //range的开始边界已经在a标签里的不再处理
  17380. if (domUtils.findParentByTagName(range.startContainer, 'a', true)) {
  17381. return
  17382. }
  17383. var a = me.document.createElement('a'),
  17384. text = me.document.createTextNode(' '),
  17385. href
  17386. me.undoManger && me.undoManger.save()
  17387. a.appendChild(range.extractContents())
  17388. a.href = a.innerHTML = a.innerHTML.replace(/<[^>]+>/g, '')
  17389. href = a.getAttribute('href').replace(new RegExp(domUtils.fillChar, 'g'), '')
  17390. href = /^(?:https?:\/\/)/gi.test(href) ? href : 'http://' + href
  17391. a.setAttribute('_src', utils.html(href))
  17392. a.href = utils.html(href)
  17393. range.insertNode(a)
  17394. a.parentNode.insertBefore(text, a.nextSibling)
  17395. range.setStart(text, 0)
  17396. range.collapse(true)
  17397. sel.removeAllRanges()
  17398. sel.addRange(range)
  17399. me.undoManger && me.undoManger.save()
  17400. }
  17401. }
  17402. }
  17403. }
  17404. }
  17405. : {}
  17406. },
  17407. function () {
  17408. var keyCodes = {
  17409. 37: 1,
  17410. 38: 1,
  17411. 39: 1,
  17412. 40: 1,
  17413. 13: 1,
  17414. 32: 1
  17415. }
  17416. function checkIsCludeLink(node) {
  17417. if (node.nodeType == 3) {
  17418. return null
  17419. }
  17420. if (node.nodeName == 'A') {
  17421. return node
  17422. }
  17423. var lastChild = node.lastChild
  17424. while (lastChild) {
  17425. if (lastChild.nodeName == 'A') {
  17426. return lastChild
  17427. }
  17428. if (lastChild.nodeType == 3) {
  17429. if (domUtils.isWhitespace(lastChild)) {
  17430. lastChild = lastChild.previousSibling
  17431. continue
  17432. }
  17433. return null
  17434. }
  17435. lastChild = lastChild.lastChild
  17436. }
  17437. }
  17438. browser.ie &&
  17439. this.addListener('keyup', function (cmd, evt) {
  17440. var me = this,
  17441. keyCode = evt.keyCode
  17442. if (keyCodes[keyCode]) {
  17443. var rng = me.selection.getRange()
  17444. var start = rng.startContainer
  17445. if (keyCode == 13) {
  17446. while (start && !domUtils.isBody(start) && !domUtils.isBlockElm(start)) {
  17447. start = start.parentNode
  17448. }
  17449. if (start && !domUtils.isBody(start) && start.nodeName == 'P') {
  17450. var pre = start.previousSibling
  17451. if (pre && pre.nodeType == 1) {
  17452. var pre = checkIsCludeLink(pre)
  17453. if (pre && !pre.getAttribute('_href')) {
  17454. domUtils.remove(pre, true)
  17455. }
  17456. }
  17457. }
  17458. } else if (keyCode == 32) {
  17459. if (start.nodeType == 3 && /^\s$/.test(start.nodeValue)) {
  17460. start = start.previousSibling
  17461. if (start && start.nodeName == 'A' && !start.getAttribute('_href')) {
  17462. domUtils.remove(start, true)
  17463. }
  17464. }
  17465. } else {
  17466. start = domUtils.findParentByTagName(start, 'a', true)
  17467. if (start && !start.getAttribute('_href')) {
  17468. var bk = rng.createBookmark()
  17469. domUtils.remove(start, true)
  17470. rng.moveToBookmark(bk).select(true)
  17471. }
  17472. }
  17473. }
  17474. })
  17475. }
  17476. )
  17477. // plugins/autoheight.js
  17478. ///import core
  17479. ///commands 当输入内容超过编辑器高度时,编辑器自动增高
  17480. ///commandsName AutoHeight,autoHeightEnabled
  17481. ///commandsTitle 自动增高
  17482. /**
  17483. * @description 自动伸展
  17484. * @author zhanyi
  17485. */
  17486. UE.plugins['autoheight'] = function () {
  17487. var me = this
  17488. //提供开关,就算加载也可以关闭
  17489. me.autoHeightEnabled = me.options.autoHeightEnabled !== false
  17490. if (!me.autoHeightEnabled) {
  17491. return
  17492. }
  17493. var bakOverflow,
  17494. lastHeight = 0,
  17495. options = me.options,
  17496. currentHeight,
  17497. timer
  17498. function adjustHeight() {
  17499. var me = this
  17500. clearTimeout(timer)
  17501. if (isFullscreen) return
  17502. if (!me.queryCommandState || (me.queryCommandState && me.queryCommandState('source') != 1)) {
  17503. timer = setTimeout(function () {
  17504. var node = me.body.lastChild
  17505. while (node && node.nodeType != 1) {
  17506. node = node.previousSibling
  17507. }
  17508. if (node && node.nodeType == 1) {
  17509. node.style.clear = 'both'
  17510. currentHeight = Math.max(
  17511. domUtils.getXY(node).y + node.offsetHeight + 25,
  17512. Math.max(options.minFrameHeight, options.initialFrameHeight)
  17513. )
  17514. if (currentHeight != lastHeight) {
  17515. if (currentHeight !== parseInt(me.iframe.parentNode.style.height)) {
  17516. me.iframe.parentNode.style.height = currentHeight + 'px'
  17517. }
  17518. me.body.style.height = currentHeight + 'px'
  17519. lastHeight = currentHeight
  17520. }
  17521. domUtils.removeStyle(node, 'clear')
  17522. }
  17523. }, 50)
  17524. }
  17525. }
  17526. var isFullscreen
  17527. me.addListener('fullscreenchanged', function (cmd, f) {
  17528. isFullscreen = f
  17529. })
  17530. me.addListener('destroy', function () {
  17531. me.removeListener('contentchange afterinserthtml keyup mouseup', adjustHeight)
  17532. })
  17533. me.enableAutoHeight = function () {
  17534. var me = this
  17535. if (!me.autoHeightEnabled) {
  17536. return
  17537. }
  17538. var doc = me.document
  17539. me.autoHeightEnabled = true
  17540. bakOverflow = doc.body.style.overflowY
  17541. doc.body.style.overflowY = 'hidden'
  17542. me.addListener('contentchange afterinserthtml keyup mouseup', adjustHeight)
  17543. //ff不给事件算得不对
  17544. setTimeout(
  17545. function () {
  17546. adjustHeight.call(me)
  17547. },
  17548. browser.gecko ? 100 : 0
  17549. )
  17550. me.fireEvent('autoheightchanged', me.autoHeightEnabled)
  17551. }
  17552. me.disableAutoHeight = function () {
  17553. me.body.style.overflowY = bakOverflow || ''
  17554. me.removeListener('contentchange', adjustHeight)
  17555. me.removeListener('keyup', adjustHeight)
  17556. me.removeListener('mouseup', adjustHeight)
  17557. me.autoHeightEnabled = false
  17558. me.fireEvent('autoheightchanged', me.autoHeightEnabled)
  17559. }
  17560. me.on('setHeight', function () {
  17561. me.disableAutoHeight()
  17562. })
  17563. me.addListener('ready', function () {
  17564. me.enableAutoHeight()
  17565. //trace:1764
  17566. var timer
  17567. domUtils.on(
  17568. browser.ie ? me.body : me.document,
  17569. browser.webkit ? 'dragover' : 'drop',
  17570. function () {
  17571. clearTimeout(timer)
  17572. timer = setTimeout(function () {
  17573. //trace:3681
  17574. adjustHeight.call(me)
  17575. }, 100)
  17576. }
  17577. )
  17578. //修复内容过多时,回到顶部,顶部内容被工具栏遮挡问题
  17579. var lastScrollY
  17580. window.onscroll = function () {
  17581. if (lastScrollY === null) {
  17582. lastScrollY = this.scrollY
  17583. } else if (this.scrollY == 0 && lastScrollY != 0) {
  17584. me.window.scrollTo(0, 0)
  17585. lastScrollY = null
  17586. }
  17587. }
  17588. })
  17589. }
  17590. // plugins/autofloat.js
  17591. ///import core
  17592. ///commands 悬浮工具栏
  17593. ///commandsName AutoFloat,autoFloatEnabled
  17594. ///commandsTitle 悬浮工具栏
  17595. /**
  17596. * modified by chengchao01
  17597. * 注意: 引入此功能后,在IE6下会将body的背景图片覆盖掉!
  17598. */
  17599. UE.plugins['autofloat'] = function () {
  17600. var me = this,
  17601. lang = me.getLang()
  17602. me.setOpt({
  17603. topOffset: 0
  17604. })
  17605. var optsAutoFloatEnabled = me.options.autoFloatEnabled !== false,
  17606. topOffset = me.options.topOffset
  17607. //如果不固定toolbar的位置,则直接退出
  17608. if (!optsAutoFloatEnabled) {
  17609. return
  17610. }
  17611. var uiUtils = UE.ui.uiUtils,
  17612. LteIE6 = browser.ie && browser.version <= 6,
  17613. quirks = browser.quirks
  17614. function checkHasUI() {
  17615. if (!UE.ui) {
  17616. alert(lang.autofloatMsg)
  17617. return 0
  17618. }
  17619. return 1
  17620. }
  17621. function fixIE6FixedPos() {
  17622. var docStyle = document.body.style
  17623. docStyle.backgroundImage = 'url("about:blank")'
  17624. docStyle.backgroundAttachment = 'fixed'
  17625. }
  17626. var bakCssText,
  17627. placeHolder = document.createElement('div'),
  17628. toolbarBox,
  17629. orgTop,
  17630. getPosition,
  17631. flag = true //ie7模式下需要偏移
  17632. function setFloating() {
  17633. var toobarBoxPos = domUtils.getXY(toolbarBox),
  17634. origalFloat = domUtils.getComputedStyle(toolbarBox, 'position'),
  17635. origalLeft = domUtils.getComputedStyle(toolbarBox, 'left')
  17636. toolbarBox.style.width = toolbarBox.offsetWidth + 'px'
  17637. toolbarBox.style.zIndex = me.options.zIndex * 1 + 1
  17638. toolbarBox.parentNode.insertBefore(placeHolder, toolbarBox)
  17639. if (LteIE6 || (quirks && browser.ie)) {
  17640. if (toolbarBox.style.position != 'absolute') {
  17641. toolbarBox.style.position = 'absolute'
  17642. }
  17643. toolbarBox.style.top =
  17644. (document.body.scrollTop || document.documentElement.scrollTop) -
  17645. orgTop +
  17646. topOffset +
  17647. 'px'
  17648. } else {
  17649. if (browser.ie7Compat && flag) {
  17650. flag = false
  17651. toolbarBox.style.left =
  17652. domUtils.getXY(toolbarBox).x -
  17653. document.documentElement.getBoundingClientRect().left +
  17654. 2 +
  17655. 'px'
  17656. }
  17657. if (toolbarBox.style.position != 'fixed') {
  17658. toolbarBox.style.position = 'fixed'
  17659. toolbarBox.style.top = topOffset + 'px'
  17660. ;(origalFloat == 'absolute' || origalFloat == 'relative') &&
  17661. parseFloat(origalLeft) &&
  17662. (toolbarBox.style.left = toobarBoxPos.x + 'px')
  17663. }
  17664. }
  17665. }
  17666. function unsetFloating() {
  17667. flag = true
  17668. if (placeHolder.parentNode) {
  17669. placeHolder.parentNode.removeChild(placeHolder)
  17670. }
  17671. toolbarBox.style.cssText = bakCssText
  17672. }
  17673. function updateFloating() {
  17674. var rect3 = getPosition(me.container)
  17675. var offset = me.options.toolbarTopOffset || 0
  17676. if (rect3.top < 0 && rect3.bottom - toolbarBox.offsetHeight > offset) {
  17677. setFloating()
  17678. } else {
  17679. unsetFloating()
  17680. }
  17681. }
  17682. var defer_updateFloating = utils.defer(
  17683. function () {
  17684. updateFloating()
  17685. },
  17686. browser.ie ? 200 : 100,
  17687. true
  17688. )
  17689. me.addListener('destroy', function () {
  17690. domUtils.un(window, ['scroll', 'resize'], updateFloating)
  17691. me.removeListener('keydown', defer_updateFloating)
  17692. })
  17693. me.addListener('ready', function () {
  17694. if (checkHasUI(me)) {
  17695. //加载了ui组件,但在new时,没有加载ui,导致编辑器实例上没有u单团,所以这里做判断
  17696. if (!me.ui) {
  17697. return
  17698. }
  17699. getPosition = uiUtils.getClientRect
  17700. toolbarBox = me.ui.getDom('toolbarbox')
  17701. orgTop = getPosition(toolbarBox).top
  17702. bakCssText = toolbarBox.style.cssText
  17703. placeHolder.style.height = toolbarBox.offsetHeight + 'px'
  17704. if (LteIE6) {
  17705. fixIE6FixedPos()
  17706. }
  17707. domUtils.on(window, ['scroll', 'resize'], updateFloating)
  17708. me.addListener('keydown', defer_updateFloating)
  17709. me.addListener('beforefullscreenchange', function (t, enabled) {
  17710. if (enabled) {
  17711. unsetFloating()
  17712. }
  17713. })
  17714. me.addListener('fullscreenchanged', function (t, enabled) {
  17715. if (!enabled) {
  17716. updateFloating()
  17717. }
  17718. })
  17719. me.addListener('sourcemodechanged', function (t, enabled) {
  17720. setTimeout(function () {
  17721. updateFloating()
  17722. }, 0)
  17723. })
  17724. me.addListener('clearDoc', function () {
  17725. setTimeout(function () {
  17726. updateFloating()
  17727. }, 0)
  17728. })
  17729. }
  17730. })
  17731. }
  17732. // plugins/video.js
  17733. /**
  17734. * video插件, 为UEditor提供视频插入支持
  17735. * @file
  17736. * @since 1.2.6.1
  17737. */
  17738. UE.plugins['video'] = function () {
  17739. var me = this
  17740. /**
  17741. * 创建插入视频字符窜
  17742. * @param url 视频地址
  17743. * @param width 视频宽度
  17744. * @param height 视频高度
  17745. * @param align 视频对齐
  17746. * @param toEmbed 是否以flash代替显示
  17747. * @param addParagraph 是否需要添加P 标签
  17748. */
  17749. function creatInsertStr(url, width, height, id, align, classname, type) {
  17750. url = utils.unhtmlForUrl(url)
  17751. align = utils.unhtml(align)
  17752. classname = utils.unhtml(classname).trim()
  17753. width = parseInt(width, 10) || 0
  17754. height = parseInt(height, 10) || 0
  17755. var str
  17756. switch (type) {
  17757. case 'image':
  17758. str =
  17759. '<img ' +
  17760. (id ? 'id="' + id + '"' : '') +
  17761. ' width="' +
  17762. width +
  17763. '" height="' +
  17764. height +
  17765. '" _url="' +
  17766. url +
  17767. '" class="' +
  17768. classname.replace(/\bvideo-js\b/, '') +
  17769. '"' +
  17770. ' src="' +
  17771. me.options.UEDITOR_HOME_URL +
  17772. 'themes/default/images/spacer.gif" style="background:url(' +
  17773. me.options.UEDITOR_HOME_URL +
  17774. 'themes/default/images/videologo.gif) no-repeat center center; border:1px solid gray;' +
  17775. (align ? 'float:' + align + ';' : '') +
  17776. '" />'
  17777. break
  17778. case 'embed':
  17779. str =
  17780. '<embed type="application/x-shockwave-flash" class="' +
  17781. classname +
  17782. '" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  17783. ' src="' +
  17784. utils.html(url) +
  17785. '" width="' +
  17786. width +
  17787. '" height="' +
  17788. height +
  17789. '"' +
  17790. (align ? ' style="float:' + align + '"' : '') +
  17791. ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >'
  17792. break
  17793. case 'video':
  17794. var ext = url.substr(url.lastIndexOf('.') + 1)
  17795. if (ext == 'ogv') ext = 'ogg'
  17796. str =
  17797. '<video' +
  17798. (id ? ' id="' + id + '"' : '') +
  17799. ' class="' +
  17800. classname +
  17801. ' video-js" ' +
  17802. (align ? ' style="float:' + align + '"' : '') +
  17803. ' controls preload="none" width="' +
  17804. width +
  17805. '" height="' +
  17806. height +
  17807. '" src="' +
  17808. url +
  17809. '" data-setup="{}">' +
  17810. '<source src="' +
  17811. url +
  17812. '" type="video/' +
  17813. ext +
  17814. '" /></video>'
  17815. break
  17816. }
  17817. return str
  17818. }
  17819. function switchImgAndVideo(root, img2video) {
  17820. utils.each(root.getNodesByTagName(img2video ? 'img' : 'embed video'), function (node) {
  17821. var className = node.getAttr('class')
  17822. if (className && className.indexOf('edui-faked-video') != -1) {
  17823. var html = creatInsertStr(
  17824. img2video ? node.getAttr('_url') : node.getAttr('src'),
  17825. node.getAttr('width'),
  17826. node.getAttr('height'),
  17827. null,
  17828. node.getStyle('float') || '',
  17829. className,
  17830. img2video ? 'embed' : 'image'
  17831. )
  17832. node.parentNode.replaceChild(UE.uNode.createElement(html), node)
  17833. }
  17834. if (className && className.indexOf('edui-upload-video') != -1) {
  17835. var html = creatInsertStr(
  17836. img2video ? node.getAttr('_url') : node.getAttr('src'),
  17837. node.getAttr('width'),
  17838. node.getAttr('height'),
  17839. null,
  17840. node.getStyle('float') || '',
  17841. className,
  17842. img2video ? 'video' : 'image'
  17843. )
  17844. node.parentNode.replaceChild(UE.uNode.createElement(html), node)
  17845. }
  17846. })
  17847. }
  17848. me.addOutputRule(function (root) {
  17849. switchImgAndVideo(root, true)
  17850. })
  17851. me.addInputRule(function (root) {
  17852. switchImgAndVideo(root)
  17853. })
  17854. /**
  17855. * 插入视频
  17856. * @command insertvideo
  17857. * @method execCommand
  17858. * @param { String } cmd 命令字符串
  17859. * @param { Object } videoAttr 键值对对象, 描述一个视频的所有属性
  17860. * @example
  17861. * ```javascript
  17862. *
  17863. * var videoAttr = {
  17864. * //视频地址
  17865. * url: 'http://www.youku.com/xxx',
  17866. * //视频宽高值, 单位px
  17867. * width: 200,
  17868. * height: 100
  17869. * };
  17870. *
  17871. * //editor 是编辑器实例
  17872. * //向编辑器插入单个视频
  17873. * editor.execCommand( 'insertvideo', videoAttr );
  17874. * ```
  17875. */
  17876. /**
  17877. * 插入视频
  17878. * @command insertvideo
  17879. * @method execCommand
  17880. * @param { String } cmd 命令字符串
  17881. * @param { Array } videoArr 需要插入的视频的数组, 其中的每一个元素都是一个键值对对象, 描述了一个视频的所有属性
  17882. * @example
  17883. * ```javascript
  17884. *
  17885. * var videoAttr1 = {
  17886. * //视频地址
  17887. * url: 'http://www.youku.com/xxx',
  17888. * //视频宽高值, 单位px
  17889. * width: 200,
  17890. * height: 100
  17891. * },
  17892. * videoAttr2 = {
  17893. * //视频地址
  17894. * url: 'http://www.youku.com/xxx',
  17895. * //视频宽高值, 单位px
  17896. * width: 200,
  17897. * height: 100
  17898. * }
  17899. *
  17900. * //editor 是编辑器实例
  17901. * //该方法将会向编辑器内插入两个视频
  17902. * editor.execCommand( 'insertvideo', [ videoAttr1, videoAttr2 ] );
  17903. * ```
  17904. */
  17905. /**
  17906. * 查询当前光标所在处是否是一个视频
  17907. * @command insertvideo
  17908. * @method queryCommandState
  17909. * @param { String } cmd 需要查询的命令字符串
  17910. * @return { int } 如果当前光标所在处的元素是一个视频对象, 则返回1,否则返回0
  17911. * @example
  17912. * ```javascript
  17913. *
  17914. * //editor 是编辑器实例
  17915. * editor.queryCommandState( 'insertvideo' );
  17916. * ```
  17917. */
  17918. me.commands['insertvideo'] = {
  17919. execCommand: function (cmd, videoObjs, type) {
  17920. videoObjs = utils.isArray(videoObjs) ? videoObjs : [videoObjs]
  17921. var html = [],
  17922. id = 'tmpVedio',
  17923. cl
  17924. for (var i = 0, vi, len = videoObjs.length; i < len; i++) {
  17925. vi = videoObjs[i]
  17926. cl = type == 'upload' ? 'edui-upload-video video-js vjs-default-skin' : 'edui-faked-video'
  17927. html.push(
  17928. creatInsertStr(vi.url, vi.width || 420, vi.height || 280, id + i, null, cl, 'image')
  17929. )
  17930. }
  17931. me.execCommand('inserthtml', html.join(''), true)
  17932. var rng = this.selection.getRange()
  17933. for (var i = 0, len = videoObjs.length; i < len; i++) {
  17934. var img = this.document.getElementById('tmpVedio' + i)
  17935. domUtils.removeAttributes(img, 'id')
  17936. rng.selectNode(img).select()
  17937. me.execCommand('imagefloat', videoObjs[i].align)
  17938. }
  17939. },
  17940. queryCommandState: function () {
  17941. var img = me.selection.getRange().getClosedNode(),
  17942. flag =
  17943. img &&
  17944. (img.className == 'edui-faked-video' ||
  17945. img.className.indexOf('edui-upload-video') != -1)
  17946. return flag ? 1 : 0
  17947. }
  17948. }
  17949. }
  17950. // plugins/table.core.js
  17951. /**
  17952. * Created with JetBrains WebStorm.
  17953. * User: taoqili
  17954. * Date: 13-1-18
  17955. * Time: 上午11:09
  17956. * To change this template use File | Settings | File Templates.
  17957. */
  17958. /**
  17959. * UE表格操作类
  17960. * @param table
  17961. * @constructor
  17962. */
  17963. ;(function () {
  17964. var UETable = (UE.UETable = function (table) {
  17965. this.table = table
  17966. this.indexTable = []
  17967. this.selectedTds = []
  17968. this.cellsRange = {}
  17969. this.update(table)
  17970. })
  17971. //===以下为静态工具方法===
  17972. UETable.removeSelectedClass = function (cells) {
  17973. utils.each(cells, function (cell) {
  17974. domUtils.removeClasses(cell, 'selectTdClass')
  17975. })
  17976. }
  17977. UETable.addSelectedClass = function (cells) {
  17978. utils.each(cells, function (cell) {
  17979. domUtils.addClass(cell, 'selectTdClass')
  17980. })
  17981. }
  17982. UETable.isEmptyBlock = function (node) {
  17983. var reg = new RegExp(domUtils.fillChar, 'g')
  17984. if (
  17985. node[browser.ie ? 'innerText' : 'textContent'].replace(/^\s*$/, '').replace(reg, '')
  17986. .length > 0
  17987. ) {
  17988. return 0
  17989. }
  17990. for (var i in dtd.$isNotEmpty)
  17991. if (dtd.$isNotEmpty.hasOwnProperty(i)) {
  17992. if (node.getElementsByTagName(i).length) {
  17993. return 0
  17994. }
  17995. }
  17996. return 1
  17997. }
  17998. UETable.getWidth = function (cell) {
  17999. if (!cell) return 0
  18000. return parseInt(domUtils.getComputedStyle(cell, 'width'), 10)
  18001. }
  18002. /**
  18003. * 获取单元格或者单元格组的“对齐”状态。 如果当前的检测对象是一个单元格组, 只有在满足所有单元格的 水平和竖直 对齐属性都相同的
  18004. * 条件时才会返回其状态值,否则将返回null; 如果当前只检测了一个单元格, 则直接返回当前单元格的对齐状态;
  18005. * @param table cell or table cells , 支持单个单元格dom对象 或者 单元格dom对象数组
  18006. * @return { align: 'left' || 'right' || 'center', valign: 'top' || 'middle' || 'bottom' } 或者 null
  18007. */
  18008. UETable.getTableCellAlignState = function (cells) {
  18009. !utils.isArray(cells) && (cells = [cells])
  18010. var result = {},
  18011. status = ['align', 'valign'],
  18012. tempStatus = null,
  18013. isSame = true //状态是否相同
  18014. utils.each(cells, function (cellNode) {
  18015. utils.each(status, function (currentState) {
  18016. tempStatus = cellNode.getAttribute(currentState)
  18017. if (!result[currentState] && tempStatus) {
  18018. result[currentState] = tempStatus
  18019. } else if (!result[currentState] || tempStatus !== result[currentState]) {
  18020. isSame = false
  18021. return false
  18022. }
  18023. })
  18024. return isSame
  18025. })
  18026. return isSame ? result : null
  18027. }
  18028. /**
  18029. * 根据当前选区获取相关的table信息
  18030. * @return {Object}
  18031. */
  18032. UETable.getTableItemsByRange = function (editor) {
  18033. var start = editor.selection.getStart()
  18034. //ff下会选中bookmark
  18035. if (
  18036. start &&
  18037. start.id &&
  18038. start.id.indexOf('_baidu_bookmark_start_') === 0 &&
  18039. start.nextSibling
  18040. ) {
  18041. start = start.nextSibling
  18042. }
  18043. //在table或者td边缘有可能存在选中tr的情况
  18044. var cell = start && domUtils.findParentByTagName(start, ['td', 'th'], true),
  18045. tr = cell && cell.parentNode,
  18046. caption = start && domUtils.findParentByTagName(start, 'caption', true),
  18047. table = caption ? caption.parentNode : tr && tr.parentNode.parentNode
  18048. return {
  18049. cell: cell,
  18050. tr: tr,
  18051. table: table,
  18052. caption: caption
  18053. }
  18054. }
  18055. UETable.getUETableBySelected = function (editor) {
  18056. var table = UETable.getTableItemsByRange(editor).table
  18057. if (table && table.ueTable && table.ueTable.selectedTds.length) {
  18058. return table.ueTable
  18059. }
  18060. return null
  18061. }
  18062. UETable.getDefaultValue = function (editor, table) {
  18063. var borderMap = {
  18064. thin: '0px',
  18065. medium: '1px',
  18066. thick: '2px'
  18067. },
  18068. tableBorder,
  18069. tdPadding,
  18070. tdBorder,
  18071. tmpValue
  18072. if (!table) {
  18073. table = editor.document.createElement('table')
  18074. table.insertRow(0).insertCell(0).innerHTML = 'xxx'
  18075. editor.body.appendChild(table)
  18076. var td = table.getElementsByTagName('td')[0]
  18077. tmpValue = domUtils.getComputedStyle(table, 'border-left-width')
  18078. tableBorder = parseInt(borderMap[tmpValue] || tmpValue, 10)
  18079. tmpValue = domUtils.getComputedStyle(td, 'padding-left')
  18080. tdPadding = parseInt(borderMap[tmpValue] || tmpValue, 10)
  18081. tmpValue = domUtils.getComputedStyle(td, 'border-left-width')
  18082. tdBorder = parseInt(borderMap[tmpValue] || tmpValue, 10)
  18083. domUtils.remove(table)
  18084. return {
  18085. tableBorder: tableBorder,
  18086. tdPadding: tdPadding,
  18087. tdBorder: tdBorder
  18088. }
  18089. } else {
  18090. td = table.getElementsByTagName('td')[0]
  18091. tmpValue = domUtils.getComputedStyle(table, 'border-left-width')
  18092. tableBorder = parseInt(borderMap[tmpValue] || tmpValue, 10)
  18093. tmpValue = domUtils.getComputedStyle(td, 'padding-left')
  18094. tdPadding = parseInt(borderMap[tmpValue] || tmpValue, 10)
  18095. tmpValue = domUtils.getComputedStyle(td, 'border-left-width')
  18096. tdBorder = parseInt(borderMap[tmpValue] || tmpValue, 10)
  18097. return {
  18098. tableBorder: tableBorder,
  18099. tdPadding: tdPadding,
  18100. tdBorder: tdBorder
  18101. }
  18102. }
  18103. }
  18104. /**
  18105. * 根据当前点击的td或者table获取索引对象
  18106. * @param tdOrTable
  18107. */
  18108. UETable.getUETable = function (tdOrTable) {
  18109. var tag = tdOrTable.tagName.toLowerCase()
  18110. tdOrTable =
  18111. tag == 'td' || tag == 'th' || tag == 'caption'
  18112. ? domUtils.findParentByTagName(tdOrTable, 'table', true)
  18113. : tdOrTable
  18114. if (!tdOrTable.ueTable) {
  18115. tdOrTable.ueTable = new UETable(tdOrTable)
  18116. }
  18117. return tdOrTable.ueTable
  18118. }
  18119. UETable.cloneCell = function (cell, ignoreMerge, keepPro) {
  18120. if (!cell || utils.isString(cell)) {
  18121. return this.table.ownerDocument.createElement(cell || 'td')
  18122. }
  18123. var flag = domUtils.hasClass(cell, 'selectTdClass')
  18124. flag && domUtils.removeClasses(cell, 'selectTdClass')
  18125. var tmpCell = cell.cloneNode(true)
  18126. if (ignoreMerge) {
  18127. tmpCell.rowSpan = tmpCell.colSpan = 1
  18128. }
  18129. //去掉宽高
  18130. !keepPro && domUtils.removeAttributes(tmpCell, 'width height')
  18131. !keepPro && domUtils.removeAttributes(tmpCell, 'style')
  18132. tmpCell.style.borderLeftStyle = ''
  18133. tmpCell.style.borderTopStyle = ''
  18134. tmpCell.style.borderLeftColor = cell.style.borderRightColor
  18135. tmpCell.style.borderLeftWidth = cell.style.borderRightWidth
  18136. tmpCell.style.borderTopColor = cell.style.borderBottomColor
  18137. tmpCell.style.borderTopWidth = cell.style.borderBottomWidth
  18138. flag && domUtils.addClass(cell, 'selectTdClass')
  18139. return tmpCell
  18140. }
  18141. UETable.prototype = {
  18142. getMaxRows: function () {
  18143. var rows = this.table.rows,
  18144. maxLen = 1
  18145. for (var i = 0, row; (row = rows[i]); i++) {
  18146. var currentMax = 1
  18147. for (var j = 0, cj; (cj = row.cells[j++]); ) {
  18148. currentMax = Math.max(cj.rowSpan || 1, currentMax)
  18149. }
  18150. maxLen = Math.max(currentMax + i, maxLen)
  18151. }
  18152. return maxLen
  18153. },
  18154. /**
  18155. * 获取当前表格的最大列数
  18156. */
  18157. getMaxCols: function () {
  18158. var rows = this.table.rows,
  18159. maxLen = 0,
  18160. cellRows = {}
  18161. for (var i = 0, row; (row = rows[i]); i++) {
  18162. var cellsNum = 0
  18163. for (var j = 0, cj; (cj = row.cells[j++]); ) {
  18164. cellsNum += cj.colSpan || 1
  18165. if (cj.rowSpan && cj.rowSpan > 1) {
  18166. for (var k = 1; k < cj.rowSpan; k++) {
  18167. if (!cellRows['row_' + (i + k)]) {
  18168. cellRows['row_' + (i + k)] = cj.colSpan || 1
  18169. } else {
  18170. cellRows['row_' + (i + k)]++
  18171. }
  18172. }
  18173. }
  18174. }
  18175. cellsNum += cellRows['row_' + i] || 0
  18176. maxLen = Math.max(cellsNum, maxLen)
  18177. }
  18178. return maxLen
  18179. },
  18180. getCellColIndex: function (cell) {},
  18181. /**
  18182. * 获取当前cell旁边的单元格,
  18183. * @param cell
  18184. * @param right
  18185. */
  18186. getHSideCell: function (cell, right) {
  18187. try {
  18188. var cellInfo = this.getCellInfo(cell),
  18189. previewRowIndex,
  18190. previewColIndex
  18191. var len = this.selectedTds.length,
  18192. range = this.cellsRange
  18193. //首行或者首列没有前置单元格
  18194. if (
  18195. (!right && (!len ? !cellInfo.colIndex : !range.beginColIndex)) ||
  18196. (right &&
  18197. (!len
  18198. ? cellInfo.colIndex == this.colsNum - 1
  18199. : range.endColIndex == this.colsNum - 1))
  18200. )
  18201. return null
  18202. previewRowIndex = !len ? cellInfo.rowIndex : range.beginRowIndex
  18203. previewColIndex = !right
  18204. ? !len
  18205. ? cellInfo.colIndex < 1
  18206. ? 0
  18207. : cellInfo.colIndex - 1
  18208. : range.beginColIndex - 1
  18209. : !len
  18210. ? cellInfo.colIndex + 1
  18211. : range.endColIndex + 1
  18212. return this.getCell(
  18213. this.indexTable[previewRowIndex][previewColIndex].rowIndex,
  18214. this.indexTable[previewRowIndex][previewColIndex].cellIndex
  18215. )
  18216. } catch (e) {
  18217. showError(e)
  18218. }
  18219. },
  18220. getTabNextCell: function (cell, preRowIndex) {
  18221. var cellInfo = this.getCellInfo(cell),
  18222. rowIndex = preRowIndex || cellInfo.rowIndex,
  18223. colIndex = cellInfo.colIndex + 1 + (cellInfo.colSpan - 1),
  18224. nextCell
  18225. try {
  18226. nextCell = this.getCell(
  18227. this.indexTable[rowIndex][colIndex].rowIndex,
  18228. this.indexTable[rowIndex][colIndex].cellIndex
  18229. )
  18230. } catch (e) {
  18231. try {
  18232. rowIndex = rowIndex * 1 + 1
  18233. colIndex = 0
  18234. nextCell = this.getCell(
  18235. this.indexTable[rowIndex][colIndex].rowIndex,
  18236. this.indexTable[rowIndex][colIndex].cellIndex
  18237. )
  18238. } catch (e) {}
  18239. }
  18240. return nextCell
  18241. },
  18242. /**
  18243. * 获取视觉上的后置单元格
  18244. * @param cell
  18245. * @param bottom
  18246. */
  18247. getVSideCell: function (cell, bottom, ignoreRange) {
  18248. try {
  18249. var cellInfo = this.getCellInfo(cell),
  18250. nextRowIndex,
  18251. nextColIndex
  18252. var len = this.selectedTds.length && !ignoreRange,
  18253. range = this.cellsRange
  18254. //末行或者末列没有后置单元格
  18255. if (
  18256. (!bottom && cellInfo.rowIndex == 0) ||
  18257. (bottom &&
  18258. (!len
  18259. ? cellInfo.rowIndex + cellInfo.rowSpan > this.rowsNum - 1
  18260. : range.endRowIndex == this.rowsNum - 1))
  18261. )
  18262. return null
  18263. nextRowIndex = !bottom
  18264. ? !len
  18265. ? cellInfo.rowIndex - 1
  18266. : range.beginRowIndex - 1
  18267. : !len
  18268. ? cellInfo.rowIndex + cellInfo.rowSpan
  18269. : range.endRowIndex + 1
  18270. nextColIndex = !len ? cellInfo.colIndex : range.beginColIndex
  18271. return this.getCell(
  18272. this.indexTable[nextRowIndex][nextColIndex].rowIndex,
  18273. this.indexTable[nextRowIndex][nextColIndex].cellIndex
  18274. )
  18275. } catch (e) {
  18276. showError(e)
  18277. }
  18278. },
  18279. /**
  18280. * 获取相同结束位置的单元格,xOrY指代了是获取x轴相同还是y轴相同
  18281. */
  18282. getSameEndPosCells: function (cell, xOrY) {
  18283. try {
  18284. var flag = xOrY.toLowerCase() === 'x',
  18285. end =
  18286. domUtils.getXY(cell)[flag ? 'x' : 'y'] + cell['offset' + (flag ? 'Width' : 'Height')],
  18287. rows = this.table.rows,
  18288. cells = null,
  18289. returns = []
  18290. for (var i = 0; i < this.rowsNum; i++) {
  18291. cells = rows[i].cells
  18292. for (var j = 0, tmpCell; (tmpCell = cells[j++]); ) {
  18293. var tmpEnd =
  18294. domUtils.getXY(tmpCell)[flag ? 'x' : 'y'] +
  18295. tmpCell['offset' + (flag ? 'Width' : 'Height')]
  18296. //对应行的td已经被上面行rowSpan了
  18297. if (tmpEnd > end && flag) break
  18298. if (cell == tmpCell || end == tmpEnd) {
  18299. //只获取单一的单元格
  18300. //todo 仅获取单一单元格在特定情况下会造成returns为空,从而影响后续的拖拽实现,修正这个。需考虑性能
  18301. if (tmpCell[flag ? 'colSpan' : 'rowSpan'] == 1) {
  18302. returns.push(tmpCell)
  18303. }
  18304. if (flag) break
  18305. }
  18306. }
  18307. }
  18308. return returns
  18309. } catch (e) {
  18310. showError(e)
  18311. }
  18312. },
  18313. setCellContent: function (cell, content) {
  18314. cell.innerHTML = content || (browser.ie ? domUtils.fillChar : '<br />')
  18315. },
  18316. cloneCell: UETable.cloneCell,
  18317. /**
  18318. * 获取跟当前单元格的右边竖线为左边的所有未合并单元格
  18319. */
  18320. getSameStartPosXCells: function (cell) {
  18321. try {
  18322. var start = domUtils.getXY(cell).x + cell.offsetWidth,
  18323. rows = this.table.rows,
  18324. cells,
  18325. returns = []
  18326. for (var i = 0; i < this.rowsNum; i++) {
  18327. cells = rows[i].cells
  18328. for (var j = 0, tmpCell; (tmpCell = cells[j++]); ) {
  18329. var tmpStart = domUtils.getXY(tmpCell).x
  18330. if (tmpStart > start) break
  18331. if (tmpStart == start && tmpCell.colSpan == 1) {
  18332. returns.push(tmpCell)
  18333. break
  18334. }
  18335. }
  18336. }
  18337. return returns
  18338. } catch (e) {
  18339. showError(e)
  18340. }
  18341. },
  18342. /**
  18343. * 更新table对应的索引表
  18344. */
  18345. update: function (table) {
  18346. this.table = table || this.table
  18347. this.selectedTds = []
  18348. this.cellsRange = {}
  18349. this.indexTable = []
  18350. var rows = this.table.rows,
  18351. rowsNum = this.getMaxRows(),
  18352. dNum = rowsNum - rows.length,
  18353. colsNum = this.getMaxCols()
  18354. while (dNum--) {
  18355. this.table.insertRow(rows.length)
  18356. }
  18357. this.rowsNum = rowsNum
  18358. this.colsNum = colsNum
  18359. for (var i = 0, len = rows.length; i < len; i++) {
  18360. this.indexTable[i] = new Array(colsNum)
  18361. }
  18362. //填充索引表
  18363. for (var rowIndex = 0, row; (row = rows[rowIndex]); rowIndex++) {
  18364. for (var cellIndex = 0, cell, cells = row.cells; (cell = cells[cellIndex]); cellIndex++) {
  18365. //修正整行被rowSpan时导致的行数计算错误
  18366. if (cell.rowSpan > rowsNum) {
  18367. cell.rowSpan = rowsNum
  18368. }
  18369. var colIndex = cellIndex,
  18370. rowSpan = cell.rowSpan || 1,
  18371. colSpan = cell.colSpan || 1
  18372. //当已经被上一行rowSpan或者被前一列colSpan了,则跳到下一个单元格进行
  18373. while (this.indexTable[rowIndex][colIndex]) colIndex++
  18374. for (var j = 0; j < rowSpan; j++) {
  18375. for (var k = 0; k < colSpan; k++) {
  18376. this.indexTable[rowIndex + j][colIndex + k] = {
  18377. rowIndex: rowIndex,
  18378. cellIndex: cellIndex,
  18379. colIndex: colIndex,
  18380. rowSpan: rowSpan,
  18381. colSpan: colSpan
  18382. }
  18383. }
  18384. }
  18385. }
  18386. }
  18387. //修复残缺td
  18388. for (j = 0; j < rowsNum; j++) {
  18389. for (k = 0; k < colsNum; k++) {
  18390. if (this.indexTable[j][k] === undefined) {
  18391. row = rows[j]
  18392. cell = row.cells[row.cells.length - 1]
  18393. cell = cell ? cell.cloneNode(true) : this.table.ownerDocument.createElement('td')
  18394. this.setCellContent(cell)
  18395. if (cell.colSpan !== 1) cell.colSpan = 1
  18396. if (cell.rowSpan !== 1) cell.rowSpan = 1
  18397. row.appendChild(cell)
  18398. this.indexTable[j][k] = {
  18399. rowIndex: j,
  18400. cellIndex: cell.cellIndex,
  18401. colIndex: k,
  18402. rowSpan: 1,
  18403. colSpan: 1
  18404. }
  18405. }
  18406. }
  18407. }
  18408. //当框选后删除行或者列后撤销,需要重建选区。
  18409. var tds = domUtils.getElementsByTagName(this.table, 'td'),
  18410. selectTds = []
  18411. utils.each(tds, function (td) {
  18412. if (domUtils.hasClass(td, 'selectTdClass')) {
  18413. selectTds.push(td)
  18414. }
  18415. })
  18416. if (selectTds.length) {
  18417. var start = selectTds[0],
  18418. end = selectTds[selectTds.length - 1],
  18419. startInfo = this.getCellInfo(start),
  18420. endInfo = this.getCellInfo(end)
  18421. this.selectedTds = selectTds
  18422. this.cellsRange = {
  18423. beginRowIndex: startInfo.rowIndex,
  18424. beginColIndex: startInfo.colIndex,
  18425. endRowIndex: endInfo.rowIndex + endInfo.rowSpan - 1,
  18426. endColIndex: endInfo.colIndex + endInfo.colSpan - 1
  18427. }
  18428. }
  18429. //给第一行设置firstRow的样式名称,在排序图标的样式上使用到
  18430. if (!domUtils.hasClass(this.table.rows[0], 'firstRow')) {
  18431. domUtils.addClass(this.table.rows[0], 'firstRow')
  18432. for (var i = 1; i < this.table.rows.length; i++) {
  18433. domUtils.removeClasses(this.table.rows[i], 'firstRow')
  18434. }
  18435. }
  18436. },
  18437. /**
  18438. * 获取单元格的索引信息
  18439. */
  18440. getCellInfo: function (cell) {
  18441. if (!cell) return
  18442. var cellIndex = cell.cellIndex,
  18443. rowIndex = cell.parentNode.rowIndex,
  18444. rowInfo = this.indexTable[rowIndex],
  18445. numCols = this.colsNum
  18446. for (var colIndex = cellIndex; colIndex < numCols; colIndex++) {
  18447. var cellInfo = rowInfo[colIndex]
  18448. if (cellInfo.rowIndex === rowIndex && cellInfo.cellIndex === cellIndex) {
  18449. return cellInfo
  18450. }
  18451. }
  18452. },
  18453. /**
  18454. * 根据行列号获取单元格
  18455. */
  18456. getCell: function (rowIndex, cellIndex) {
  18457. return (rowIndex < this.rowsNum && this.table.rows[rowIndex].cells[cellIndex]) || null
  18458. },
  18459. /**
  18460. * 删除单元格
  18461. */
  18462. deleteCell: function (cell, rowIndex) {
  18463. rowIndex = typeof rowIndex == 'number' ? rowIndex : cell.parentNode.rowIndex
  18464. var row = this.table.rows[rowIndex]
  18465. row.deleteCell(cell.cellIndex)
  18466. },
  18467. /**
  18468. * 根据始末两个单元格获取被框选的所有单元格范围
  18469. */
  18470. getCellsRange: function (cellA, cellB) {
  18471. function checkRange(beginRowIndex, beginColIndex, endRowIndex, endColIndex) {
  18472. var tmpBeginRowIndex = beginRowIndex,
  18473. tmpBeginColIndex = beginColIndex,
  18474. tmpEndRowIndex = endRowIndex,
  18475. tmpEndColIndex = endColIndex,
  18476. cellInfo,
  18477. colIndex,
  18478. rowIndex
  18479. // 通过indexTable检查是否存在超出TableRange上边界的情况
  18480. if (beginRowIndex > 0) {
  18481. for (colIndex = beginColIndex; colIndex < endColIndex; colIndex++) {
  18482. cellInfo = me.indexTable[beginRowIndex][colIndex]
  18483. rowIndex = cellInfo.rowIndex
  18484. if (rowIndex < beginRowIndex) {
  18485. tmpBeginRowIndex = Math.min(rowIndex, tmpBeginRowIndex)
  18486. }
  18487. }
  18488. }
  18489. // 通过indexTable检查是否存在超出TableRange右边界的情况
  18490. if (endColIndex < me.colsNum) {
  18491. for (rowIndex = beginRowIndex; rowIndex < endRowIndex; rowIndex++) {
  18492. cellInfo = me.indexTable[rowIndex][endColIndex]
  18493. colIndex = cellInfo.colIndex + cellInfo.colSpan - 1
  18494. if (colIndex > endColIndex) {
  18495. tmpEndColIndex = Math.max(colIndex, tmpEndColIndex)
  18496. }
  18497. }
  18498. }
  18499. // 检查是否有超出TableRange下边界的情况
  18500. if (endRowIndex < me.rowsNum) {
  18501. for (colIndex = beginColIndex; colIndex < endColIndex; colIndex++) {
  18502. cellInfo = me.indexTable[endRowIndex][colIndex]
  18503. rowIndex = cellInfo.rowIndex + cellInfo.rowSpan - 1
  18504. if (rowIndex > endRowIndex) {
  18505. tmpEndRowIndex = Math.max(rowIndex, tmpEndRowIndex)
  18506. }
  18507. }
  18508. }
  18509. // 检查是否有超出TableRange左边界的情况
  18510. if (beginColIndex > 0) {
  18511. for (rowIndex = beginRowIndex; rowIndex < endRowIndex; rowIndex++) {
  18512. cellInfo = me.indexTable[rowIndex][beginColIndex]
  18513. colIndex = cellInfo.colIndex
  18514. if (colIndex < beginColIndex) {
  18515. tmpBeginColIndex = Math.min(cellInfo.colIndex, tmpBeginColIndex)
  18516. }
  18517. }
  18518. }
  18519. //递归调用直至所有完成所有框选单元格的扩展
  18520. if (
  18521. tmpBeginRowIndex != beginRowIndex ||
  18522. tmpBeginColIndex != beginColIndex ||
  18523. tmpEndRowIndex != endRowIndex ||
  18524. tmpEndColIndex != endColIndex
  18525. ) {
  18526. return checkRange(tmpBeginRowIndex, tmpBeginColIndex, tmpEndRowIndex, tmpEndColIndex)
  18527. } else {
  18528. // 不需要扩展TableRange的情况
  18529. return {
  18530. beginRowIndex: beginRowIndex,
  18531. beginColIndex: beginColIndex,
  18532. endRowIndex: endRowIndex,
  18533. endColIndex: endColIndex
  18534. }
  18535. }
  18536. }
  18537. try {
  18538. var me = this,
  18539. cellAInfo = me.getCellInfo(cellA)
  18540. if (cellA === cellB) {
  18541. return {
  18542. beginRowIndex: cellAInfo.rowIndex,
  18543. beginColIndex: cellAInfo.colIndex,
  18544. endRowIndex: cellAInfo.rowIndex + cellAInfo.rowSpan - 1,
  18545. endColIndex: cellAInfo.colIndex + cellAInfo.colSpan - 1
  18546. }
  18547. }
  18548. var cellBInfo = me.getCellInfo(cellB)
  18549. // 计算TableRange的四个边
  18550. var beginRowIndex = Math.min(cellAInfo.rowIndex, cellBInfo.rowIndex),
  18551. beginColIndex = Math.min(cellAInfo.colIndex, cellBInfo.colIndex),
  18552. endRowIndex = Math.max(
  18553. cellAInfo.rowIndex + cellAInfo.rowSpan - 1,
  18554. cellBInfo.rowIndex + cellBInfo.rowSpan - 1
  18555. ),
  18556. endColIndex = Math.max(
  18557. cellAInfo.colIndex + cellAInfo.colSpan - 1,
  18558. cellBInfo.colIndex + cellBInfo.colSpan - 1
  18559. )
  18560. return checkRange(beginRowIndex, beginColIndex, endRowIndex, endColIndex)
  18561. } catch (e) {
  18562. //throw e;
  18563. }
  18564. },
  18565. /**
  18566. * 依据cellsRange获取对应的单元格集合
  18567. */
  18568. getCells: function (range) {
  18569. //每次获取cells之前必须先清除上次的选择,否则会对后续获取操作造成影响
  18570. this.clearSelected()
  18571. var beginRowIndex = range.beginRowIndex,
  18572. beginColIndex = range.beginColIndex,
  18573. endRowIndex = range.endRowIndex,
  18574. endColIndex = range.endColIndex,
  18575. cellInfo,
  18576. rowIndex,
  18577. colIndex,
  18578. tdHash = {},
  18579. returnTds = []
  18580. for (var i = beginRowIndex; i <= endRowIndex; i++) {
  18581. for (var j = beginColIndex; j <= endColIndex; j++) {
  18582. cellInfo = this.indexTable[i][j]
  18583. rowIndex = cellInfo.rowIndex
  18584. colIndex = cellInfo.colIndex
  18585. // 如果Cells里已经包含了此Cell则跳过
  18586. var key = rowIndex + '|' + colIndex
  18587. if (tdHash[key]) continue
  18588. tdHash[key] = 1
  18589. if (
  18590. rowIndex < i ||
  18591. colIndex < j ||
  18592. rowIndex + cellInfo.rowSpan - 1 > endRowIndex ||
  18593. colIndex + cellInfo.colSpan - 1 > endColIndex
  18594. ) {
  18595. return null
  18596. }
  18597. returnTds.push(this.getCell(rowIndex, cellInfo.cellIndex))
  18598. }
  18599. }
  18600. return returnTds
  18601. },
  18602. /**
  18603. * 清理已经选中的单元格
  18604. */
  18605. clearSelected: function () {
  18606. UETable.removeSelectedClass(this.selectedTds)
  18607. this.selectedTds = []
  18608. this.cellsRange = {}
  18609. },
  18610. /**
  18611. * 根据range设置已经选中的单元格
  18612. */
  18613. setSelected: function (range) {
  18614. var cells = this.getCells(range)
  18615. UETable.addSelectedClass(cells)
  18616. this.selectedTds = cells
  18617. this.cellsRange = range
  18618. },
  18619. isFullRow: function () {
  18620. var range = this.cellsRange
  18621. return range.endColIndex - range.beginColIndex + 1 == this.colsNum
  18622. },
  18623. isFullCol: function () {
  18624. var range = this.cellsRange,
  18625. table = this.table,
  18626. ths = table.getElementsByTagName('th'),
  18627. rows = range.endRowIndex - range.beginRowIndex + 1
  18628. return !ths.length ? rows == this.rowsNum : rows == this.rowsNum || rows == this.rowsNum - 1
  18629. },
  18630. /**
  18631. * 获取视觉上的前置单元格,默认是左边,top传入时
  18632. * @param cell
  18633. * @param top
  18634. */
  18635. getNextCell: function (cell, bottom, ignoreRange) {
  18636. try {
  18637. var cellInfo = this.getCellInfo(cell),
  18638. nextRowIndex,
  18639. nextColIndex
  18640. var len = this.selectedTds.length && !ignoreRange,
  18641. range = this.cellsRange
  18642. //末行或者末列没有后置单元格
  18643. if (
  18644. (!bottom && cellInfo.rowIndex == 0) ||
  18645. (bottom &&
  18646. (!len
  18647. ? cellInfo.rowIndex + cellInfo.rowSpan > this.rowsNum - 1
  18648. : range.endRowIndex == this.rowsNum - 1))
  18649. )
  18650. return null
  18651. nextRowIndex = !bottom
  18652. ? !len
  18653. ? cellInfo.rowIndex - 1
  18654. : range.beginRowIndex - 1
  18655. : !len
  18656. ? cellInfo.rowIndex + cellInfo.rowSpan
  18657. : range.endRowIndex + 1
  18658. nextColIndex = !len ? cellInfo.colIndex : range.beginColIndex
  18659. return this.getCell(
  18660. this.indexTable[nextRowIndex][nextColIndex].rowIndex,
  18661. this.indexTable[nextRowIndex][nextColIndex].cellIndex
  18662. )
  18663. } catch (e) {
  18664. showError(e)
  18665. }
  18666. },
  18667. getPreviewCell: function (cell, top) {
  18668. try {
  18669. var cellInfo = this.getCellInfo(cell),
  18670. previewRowIndex,
  18671. previewColIndex
  18672. var len = this.selectedTds.length,
  18673. range = this.cellsRange
  18674. //首行或者首列没有前置单元格
  18675. if (
  18676. (!top && (!len ? !cellInfo.colIndex : !range.beginColIndex)) ||
  18677. (top &&
  18678. (!len ? cellInfo.rowIndex > this.colsNum - 1 : range.endColIndex == this.colsNum - 1))
  18679. )
  18680. return null
  18681. previewRowIndex = !top
  18682. ? !len
  18683. ? cellInfo.rowIndex
  18684. : range.beginRowIndex
  18685. : !len
  18686. ? cellInfo.rowIndex < 1
  18687. ? 0
  18688. : cellInfo.rowIndex - 1
  18689. : range.beginRowIndex
  18690. previewColIndex = !top
  18691. ? !len
  18692. ? cellInfo.colIndex < 1
  18693. ? 0
  18694. : cellInfo.colIndex - 1
  18695. : range.beginColIndex - 1
  18696. : !len
  18697. ? cellInfo.colIndex
  18698. : range.endColIndex + 1
  18699. return this.getCell(
  18700. this.indexTable[previewRowIndex][previewColIndex].rowIndex,
  18701. this.indexTable[previewRowIndex][previewColIndex].cellIndex
  18702. )
  18703. } catch (e) {
  18704. showError(e)
  18705. }
  18706. },
  18707. /**
  18708. * 移动单元格中的内容
  18709. */
  18710. moveContent: function (cellTo, cellFrom) {
  18711. if (UETable.isEmptyBlock(cellFrom)) return
  18712. if (UETable.isEmptyBlock(cellTo)) {
  18713. cellTo.innerHTML = cellFrom.innerHTML
  18714. return
  18715. }
  18716. var child = cellTo.lastChild
  18717. if (child.nodeType == 3 || !dtd.$block[child.tagName]) {
  18718. cellTo.appendChild(cellTo.ownerDocument.createElement('br'))
  18719. }
  18720. while ((child = cellFrom.firstChild)) {
  18721. cellTo.appendChild(child)
  18722. }
  18723. },
  18724. /**
  18725. * 向右合并单元格
  18726. */
  18727. mergeRight: function (cell) {
  18728. var cellInfo = this.getCellInfo(cell),
  18729. rightColIndex = cellInfo.colIndex + cellInfo.colSpan,
  18730. rightCellInfo = this.indexTable[cellInfo.rowIndex][rightColIndex],
  18731. rightCell = this.getCell(rightCellInfo.rowIndex, rightCellInfo.cellIndex)
  18732. //合并
  18733. cell.colSpan = cellInfo.colSpan + rightCellInfo.colSpan
  18734. //被合并的单元格不应存在宽度属性
  18735. cell.removeAttribute('width')
  18736. //移动内容
  18737. this.moveContent(cell, rightCell)
  18738. //删掉被合并的Cell
  18739. this.deleteCell(rightCell, rightCellInfo.rowIndex)
  18740. this.update()
  18741. },
  18742. /**
  18743. * 向下合并单元格
  18744. */
  18745. mergeDown: function (cell) {
  18746. var cellInfo = this.getCellInfo(cell),
  18747. downRowIndex = cellInfo.rowIndex + cellInfo.rowSpan,
  18748. downCellInfo = this.indexTable[downRowIndex][cellInfo.colIndex],
  18749. downCell = this.getCell(downCellInfo.rowIndex, downCellInfo.cellIndex)
  18750. cell.rowSpan = cellInfo.rowSpan + downCellInfo.rowSpan
  18751. cell.removeAttribute('height')
  18752. this.moveContent(cell, downCell)
  18753. this.deleteCell(downCell, downCellInfo.rowIndex)
  18754. this.update()
  18755. },
  18756. /**
  18757. * 合并整个range中的内容
  18758. */
  18759. mergeRange: function () {
  18760. //由于合并操作可以在任意时刻进行,所以无法通过鼠标位置等信息实时生成range,只能通过缓存实例中的cellsRange对象来访问
  18761. var range = this.cellsRange,
  18762. leftTopCell = this.getCell(
  18763. range.beginRowIndex,
  18764. this.indexTable[range.beginRowIndex][range.beginColIndex].cellIndex
  18765. )
  18766. if (leftTopCell.tagName == 'TH' && range.endRowIndex !== range.beginRowIndex) {
  18767. var index = this.indexTable,
  18768. info = this.getCellInfo(leftTopCell)
  18769. leftTopCell = this.getCell(1, index[1][info.colIndex].cellIndex)
  18770. range = this.getCellsRange(
  18771. leftTopCell,
  18772. this.getCell(
  18773. index[this.rowsNum - 1][info.colIndex].rowIndex,
  18774. index[this.rowsNum - 1][info.colIndex].cellIndex
  18775. )
  18776. )
  18777. }
  18778. // 删除剩余的Cells
  18779. var cells = this.getCells(range)
  18780. for (var i = 0, ci; (ci = cells[i++]); ) {
  18781. if (ci !== leftTopCell) {
  18782. this.moveContent(leftTopCell, ci)
  18783. this.deleteCell(ci)
  18784. }
  18785. }
  18786. // 修改左上角Cell的rowSpan和colSpan,并调整宽度属性设置
  18787. leftTopCell.rowSpan = range.endRowIndex - range.beginRowIndex + 1
  18788. leftTopCell.rowSpan > 1 && leftTopCell.removeAttribute('height')
  18789. leftTopCell.colSpan = range.endColIndex - range.beginColIndex + 1
  18790. leftTopCell.colSpan > 1 && leftTopCell.removeAttribute('width')
  18791. if (leftTopCell.rowSpan == this.rowsNum && leftTopCell.colSpan != 1) {
  18792. leftTopCell.colSpan = 1
  18793. }
  18794. if (leftTopCell.colSpan == this.colsNum && leftTopCell.rowSpan != 1) {
  18795. var rowIndex = leftTopCell.parentNode.rowIndex
  18796. //解决IE下的表格操作问题
  18797. if (this.table.deleteRow) {
  18798. for (
  18799. var i = rowIndex + 1, curIndex = rowIndex + 1, len = leftTopCell.rowSpan;
  18800. i < len;
  18801. i++
  18802. ) {
  18803. this.table.deleteRow(curIndex)
  18804. }
  18805. } else {
  18806. for (var i = 0, len = leftTopCell.rowSpan - 1; i < len; i++) {
  18807. var row = this.table.rows[rowIndex + 1]
  18808. row.parentNode.removeChild(row)
  18809. }
  18810. }
  18811. leftTopCell.rowSpan = 1
  18812. }
  18813. this.update()
  18814. },
  18815. /**
  18816. * 插入一行单元格
  18817. */
  18818. insertRow: function (rowIndex, sourceCell) {
  18819. var numCols = this.colsNum,
  18820. table = this.table,
  18821. row = table.insertRow(rowIndex),
  18822. cell,
  18823. isInsertTitle = typeof sourceCell == 'string' && sourceCell.toUpperCase() == 'TH'
  18824. function replaceTdToTh(colIndex, cell, tableRow) {
  18825. if (colIndex == 0) {
  18826. var tr = tableRow.nextSibling || tableRow.previousSibling,
  18827. th = tr.cells[colIndex]
  18828. if (th.tagName == 'TH') {
  18829. th = cell.ownerDocument.createElement('th')
  18830. th.appendChild(cell.firstChild)
  18831. tableRow.insertBefore(th, cell)
  18832. domUtils.remove(cell)
  18833. }
  18834. } else {
  18835. if (cell.tagName == 'TH') {
  18836. var td = cell.ownerDocument.createElement('td')
  18837. td.appendChild(cell.firstChild)
  18838. tableRow.insertBefore(td, cell)
  18839. domUtils.remove(cell)
  18840. }
  18841. }
  18842. }
  18843. //首行直接插入,无需考虑部分单元格被rowspan的情况
  18844. if (rowIndex == 0 || rowIndex == this.rowsNum) {
  18845. for (var colIndex = 0; colIndex < numCols; colIndex++) {
  18846. cell = this.cloneCell(sourceCell, true)
  18847. this.setCellContent(cell)
  18848. cell.getAttribute('vAlign') && cell.setAttribute('vAlign', cell.getAttribute('vAlign'))
  18849. row.appendChild(cell)
  18850. if (!isInsertTitle) replaceTdToTh(colIndex, cell, row)
  18851. }
  18852. } else {
  18853. var infoRow = this.indexTable[rowIndex],
  18854. cellIndex = 0
  18855. for (colIndex = 0; colIndex < numCols; colIndex++) {
  18856. var cellInfo = infoRow[colIndex]
  18857. //如果存在某个单元格的rowspan穿过待插入行的位置,则修改该单元格的rowspan即可,无需插入单元格
  18858. if (cellInfo.rowIndex < rowIndex) {
  18859. cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex)
  18860. cell.rowSpan = cellInfo.rowSpan + 1
  18861. } else {
  18862. cell = this.cloneCell(sourceCell, true)
  18863. this.setCellContent(cell)
  18864. row.appendChild(cell)
  18865. }
  18866. if (!isInsertTitle) replaceTdToTh(colIndex, cell, row)
  18867. }
  18868. }
  18869. //框选时插入不触发contentchange,需要手动更新索引。
  18870. this.update()
  18871. return row
  18872. },
  18873. /**
  18874. * 删除一行单元格
  18875. * @param rowIndex
  18876. */
  18877. deleteRow: function (rowIndex) {
  18878. var row = this.table.rows[rowIndex],
  18879. infoRow = this.indexTable[rowIndex],
  18880. colsNum = this.colsNum,
  18881. count = 0 //处理计数
  18882. for (var colIndex = 0; colIndex < colsNum; ) {
  18883. var cellInfo = infoRow[colIndex],
  18884. cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex)
  18885. if (cell.rowSpan > 1) {
  18886. if (cellInfo.rowIndex == rowIndex) {
  18887. var clone = cell.cloneNode(true)
  18888. clone.rowSpan = cell.rowSpan - 1
  18889. clone.innerHTML = ''
  18890. cell.rowSpan = 1
  18891. var nextRowIndex = rowIndex + 1,
  18892. nextRow = this.table.rows[nextRowIndex],
  18893. insertCellIndex,
  18894. preMerged = this.getPreviewMergedCellsNum(nextRowIndex, colIndex) - count
  18895. if (preMerged < colIndex) {
  18896. insertCellIndex = colIndex - preMerged - 1
  18897. //nextRow.insertCell(insertCellIndex);
  18898. domUtils.insertAfter(nextRow.cells[insertCellIndex], clone)
  18899. } else {
  18900. if (nextRow.cells.length) nextRow.insertBefore(clone, nextRow.cells[0])
  18901. }
  18902. count += 1
  18903. //cell.parentNode.removeChild(cell);
  18904. }
  18905. }
  18906. colIndex += cell.colSpan || 1
  18907. }
  18908. var deleteTds = [],
  18909. cacheMap = {}
  18910. for (colIndex = 0; colIndex < colsNum; colIndex++) {
  18911. var tmpRowIndex = infoRow[colIndex].rowIndex,
  18912. tmpCellIndex = infoRow[colIndex].cellIndex,
  18913. key = tmpRowIndex + '_' + tmpCellIndex
  18914. if (cacheMap[key]) continue
  18915. cacheMap[key] = 1
  18916. cell = this.getCell(tmpRowIndex, tmpCellIndex)
  18917. deleteTds.push(cell)
  18918. }
  18919. var mergeTds = []
  18920. utils.each(deleteTds, function (td) {
  18921. if (td.rowSpan == 1) {
  18922. td.parentNode.removeChild(td)
  18923. } else {
  18924. mergeTds.push(td)
  18925. }
  18926. })
  18927. utils.each(mergeTds, function (td) {
  18928. td.rowSpan--
  18929. })
  18930. row.parentNode.removeChild(row)
  18931. //浏览器方法本身存在bug,采用自定义方法删除
  18932. //this.table.deleteRow(rowIndex);
  18933. this.update()
  18934. },
  18935. insertCol: function (colIndex, sourceCell, defaultValue) {
  18936. var rowsNum = this.rowsNum,
  18937. rowIndex = 0,
  18938. tableRow,
  18939. cell,
  18940. backWidth = parseInt(
  18941. (this.table.offsetWidth - (this.colsNum + 1) * 20 - (this.colsNum + 1)) /
  18942. (this.colsNum + 1),
  18943. 10
  18944. ),
  18945. isInsertTitleCol = typeof sourceCell == 'string' && sourceCell.toUpperCase() == 'TH'
  18946. function replaceTdToTh(rowIndex, cell, tableRow) {
  18947. if (rowIndex == 0) {
  18948. var th = cell.nextSibling || cell.previousSibling
  18949. if (th.tagName == 'TH') {
  18950. th = cell.ownerDocument.createElement('th')
  18951. th.appendChild(cell.firstChild)
  18952. tableRow.insertBefore(th, cell)
  18953. domUtils.remove(cell)
  18954. }
  18955. } else {
  18956. if (cell.tagName == 'TH') {
  18957. var td = cell.ownerDocument.createElement('td')
  18958. td.appendChild(cell.firstChild)
  18959. tableRow.insertBefore(td, cell)
  18960. domUtils.remove(cell)
  18961. }
  18962. }
  18963. }
  18964. var preCell
  18965. if (colIndex == 0 || colIndex == this.colsNum) {
  18966. for (; rowIndex < rowsNum; rowIndex++) {
  18967. tableRow = this.table.rows[rowIndex]
  18968. preCell = tableRow.cells[colIndex == 0 ? colIndex : tableRow.cells.length]
  18969. cell = this.cloneCell(sourceCell, true) //tableRow.insertCell(colIndex == 0 ? colIndex : tableRow.cells.length);
  18970. this.setCellContent(cell)
  18971. cell.setAttribute('vAlign', cell.getAttribute('vAlign'))
  18972. preCell && cell.setAttribute('width', preCell.getAttribute('width'))
  18973. if (!colIndex) {
  18974. tableRow.insertBefore(cell, tableRow.cells[0])
  18975. } else {
  18976. domUtils.insertAfter(tableRow.cells[tableRow.cells.length - 1], cell)
  18977. }
  18978. if (!isInsertTitleCol) replaceTdToTh(rowIndex, cell, tableRow)
  18979. }
  18980. } else {
  18981. for (; rowIndex < rowsNum; rowIndex++) {
  18982. var cellInfo = this.indexTable[rowIndex][colIndex]
  18983. if (cellInfo.colIndex < colIndex) {
  18984. cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex)
  18985. cell.colSpan = cellInfo.colSpan + 1
  18986. } else {
  18987. tableRow = this.table.rows[rowIndex]
  18988. preCell = tableRow.cells[cellInfo.cellIndex]
  18989. cell = this.cloneCell(sourceCell, true) //tableRow.insertCell(cellInfo.cellIndex);
  18990. this.setCellContent(cell)
  18991. cell.setAttribute('vAlign', cell.getAttribute('vAlign'))
  18992. preCell && cell.setAttribute('width', preCell.getAttribute('width'))
  18993. //防止IE下报错
  18994. preCell ? tableRow.insertBefore(cell, preCell) : tableRow.appendChild(cell)
  18995. }
  18996. if (!isInsertTitleCol) replaceTdToTh(rowIndex, cell, tableRow)
  18997. }
  18998. }
  18999. //框选时插入不触发contentchange,需要手动更新索引
  19000. this.update()
  19001. this.updateWidth(backWidth, defaultValue || { tdPadding: 10, tdBorder: 1 })
  19002. },
  19003. updateWidth: function (width, defaultValue) {
  19004. var table = this.table,
  19005. tmpWidth =
  19006. UETable.getWidth(table) - defaultValue.tdPadding * 2 - defaultValue.tdBorder + width
  19007. if (tmpWidth < table.ownerDocument.body.offsetWidth) {
  19008. table.setAttribute('width', tmpWidth)
  19009. return
  19010. }
  19011. var tds = domUtils.getElementsByTagName(this.table, 'td th')
  19012. utils.each(tds, function (td) {
  19013. td.setAttribute('width', width)
  19014. })
  19015. },
  19016. deleteCol: function (colIndex) {
  19017. var indexTable = this.indexTable,
  19018. tableRows = this.table.rows,
  19019. backTableWidth = this.table.getAttribute('width'),
  19020. backTdWidth = 0,
  19021. rowsNum = this.rowsNum,
  19022. cacheMap = {}
  19023. for (var rowIndex = 0; rowIndex < rowsNum; ) {
  19024. var infoRow = indexTable[rowIndex],
  19025. cellInfo = infoRow[colIndex],
  19026. key = cellInfo.rowIndex + '_' + cellInfo.colIndex
  19027. // 跳过已经处理过的Cell
  19028. if (cacheMap[key]) continue
  19029. cacheMap[key] = 1
  19030. var cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex)
  19031. if (!backTdWidth)
  19032. backTdWidth = cell && parseInt(cell.offsetWidth / cell.colSpan, 10).toFixed(0)
  19033. // 如果Cell的colSpan大于1, 就修改colSpan, 否则就删掉这个Cell
  19034. if (cell.colSpan > 1) {
  19035. cell.colSpan--
  19036. } else {
  19037. tableRows[rowIndex].deleteCell(cellInfo.cellIndex)
  19038. }
  19039. rowIndex += cellInfo.rowSpan || 1
  19040. }
  19041. this.table.setAttribute('width', backTableWidth - backTdWidth)
  19042. this.update()
  19043. },
  19044. splitToCells: function (cell) {
  19045. var me = this,
  19046. cells = this.splitToRows(cell)
  19047. utils.each(cells, function (cell) {
  19048. me.splitToCols(cell)
  19049. })
  19050. },
  19051. splitToRows: function (cell) {
  19052. var cellInfo = this.getCellInfo(cell),
  19053. rowIndex = cellInfo.rowIndex,
  19054. colIndex = cellInfo.colIndex,
  19055. results = []
  19056. // 修改Cell的rowSpan
  19057. cell.rowSpan = 1
  19058. results.push(cell)
  19059. // 补齐单元格
  19060. for (var i = rowIndex, endRow = rowIndex + cellInfo.rowSpan; i < endRow; i++) {
  19061. if (i == rowIndex) continue
  19062. var tableRow = this.table.rows[i],
  19063. tmpCell = tableRow.insertCell(colIndex - this.getPreviewMergedCellsNum(i, colIndex))
  19064. tmpCell.colSpan = cellInfo.colSpan
  19065. this.setCellContent(tmpCell)
  19066. tmpCell.setAttribute('vAlign', cell.getAttribute('vAlign'))
  19067. tmpCell.setAttribute('align', cell.getAttribute('align'))
  19068. if (cell.style.cssText) {
  19069. tmpCell.style.cssText = cell.style.cssText
  19070. }
  19071. results.push(tmpCell)
  19072. }
  19073. this.update()
  19074. return results
  19075. },
  19076. getPreviewMergedCellsNum: function (rowIndex, colIndex) {
  19077. var indexRow = this.indexTable[rowIndex],
  19078. num = 0
  19079. for (var i = 0; i < colIndex; ) {
  19080. var colSpan = indexRow[i].colSpan,
  19081. tmpRowIndex = indexRow[i].rowIndex
  19082. num += colSpan - (tmpRowIndex == rowIndex ? 1 : 0)
  19083. i += colSpan
  19084. }
  19085. return num
  19086. },
  19087. splitToCols: function (cell) {
  19088. var backWidth = (cell.offsetWidth / cell.colSpan - 22).toFixed(0),
  19089. cellInfo = this.getCellInfo(cell),
  19090. rowIndex = cellInfo.rowIndex,
  19091. colIndex = cellInfo.colIndex,
  19092. results = []
  19093. // 修改Cell的rowSpan
  19094. cell.colSpan = 1
  19095. cell.setAttribute('width', backWidth)
  19096. results.push(cell)
  19097. // 补齐单元格
  19098. for (var j = colIndex, endCol = colIndex + cellInfo.colSpan; j < endCol; j++) {
  19099. if (j == colIndex) continue
  19100. var tableRow = this.table.rows[rowIndex],
  19101. tmpCell = tableRow.insertCell(this.indexTable[rowIndex][j].cellIndex + 1)
  19102. tmpCell.rowSpan = cellInfo.rowSpan
  19103. this.setCellContent(tmpCell)
  19104. tmpCell.setAttribute('vAlign', cell.getAttribute('vAlign'))
  19105. tmpCell.setAttribute('align', cell.getAttribute('align'))
  19106. tmpCell.setAttribute('width', backWidth)
  19107. if (cell.style.cssText) {
  19108. tmpCell.style.cssText = cell.style.cssText
  19109. }
  19110. //处理th的情况
  19111. if (cell.tagName == 'TH') {
  19112. var th = cell.ownerDocument.createElement('th')
  19113. th.appendChild(tmpCell.firstChild)
  19114. th.setAttribute('vAlign', cell.getAttribute('vAlign'))
  19115. th.rowSpan = tmpCell.rowSpan
  19116. tableRow.insertBefore(th, tmpCell)
  19117. domUtils.remove(tmpCell)
  19118. }
  19119. results.push(tmpCell)
  19120. }
  19121. this.update()
  19122. return results
  19123. },
  19124. isLastCell: function (cell, rowsNum, colsNum) {
  19125. rowsNum = rowsNum || this.rowsNum
  19126. colsNum = colsNum || this.colsNum
  19127. var cellInfo = this.getCellInfo(cell)
  19128. return (
  19129. cellInfo.rowIndex + cellInfo.rowSpan == rowsNum &&
  19130. cellInfo.colIndex + cellInfo.colSpan == colsNum
  19131. )
  19132. },
  19133. getLastCell: function (cells) {
  19134. cells = cells || this.table.getElementsByTagName('td')
  19135. var firstInfo = this.getCellInfo(cells[0])
  19136. var me = this,
  19137. last = cells[0],
  19138. tr = last.parentNode,
  19139. cellsNum = 0,
  19140. cols = 0,
  19141. rows
  19142. utils.each(cells, function (cell) {
  19143. if (cell.parentNode == tr) cols += cell.colSpan || 1
  19144. cellsNum += cell.rowSpan * cell.colSpan || 1
  19145. })
  19146. rows = cellsNum / cols
  19147. utils.each(cells, function (cell) {
  19148. if (me.isLastCell(cell, rows, cols)) {
  19149. last = cell
  19150. return false
  19151. }
  19152. })
  19153. return last
  19154. },
  19155. selectRow: function (rowIndex) {
  19156. var indexRow = this.indexTable[rowIndex],
  19157. start = this.getCell(indexRow[0].rowIndex, indexRow[0].cellIndex),
  19158. end = this.getCell(
  19159. indexRow[this.colsNum - 1].rowIndex,
  19160. indexRow[this.colsNum - 1].cellIndex
  19161. ),
  19162. range = this.getCellsRange(start, end)
  19163. this.setSelected(range)
  19164. },
  19165. selectTable: function () {
  19166. var tds = this.table.getElementsByTagName('td'),
  19167. range = this.getCellsRange(tds[0], tds[tds.length - 1])
  19168. this.setSelected(range)
  19169. },
  19170. setBackground: function (cells, value) {
  19171. if (typeof value === 'string') {
  19172. utils.each(cells, function (cell) {
  19173. cell.style.backgroundColor = value
  19174. })
  19175. } else if (typeof value === 'object') {
  19176. value = utils.extend(
  19177. {
  19178. repeat: true,
  19179. colorList: ['#ddd', '#fff']
  19180. },
  19181. value
  19182. )
  19183. var rowIndex = this.getCellInfo(cells[0]).rowIndex,
  19184. count = 0,
  19185. colors = value.colorList,
  19186. getColor = function (list, index, repeat) {
  19187. return list[index] ? list[index] : repeat ? list[index % list.length] : ''
  19188. }
  19189. for (var i = 0, cell; (cell = cells[i++]); ) {
  19190. var cellInfo = this.getCellInfo(cell)
  19191. cell.style.backgroundColor = getColor(
  19192. colors,
  19193. rowIndex + count == cellInfo.rowIndex ? count : ++count,
  19194. value.repeat
  19195. )
  19196. }
  19197. }
  19198. },
  19199. removeBackground: function (cells) {
  19200. utils.each(cells, function (cell) {
  19201. cell.style.backgroundColor = ''
  19202. })
  19203. }
  19204. }
  19205. function showError(e) {}
  19206. })()
  19207. // plugins/table.cmds.js
  19208. /**
  19209. * Created with JetBrains PhpStorm.
  19210. * User: taoqili
  19211. * Date: 13-2-20
  19212. * Time: 下午6:25
  19213. * To change this template use File | Settings | File Templates.
  19214. */
  19215. ;(function () {
  19216. var UT = UE.UETable,
  19217. getTableItemsByRange = function (editor) {
  19218. return UT.getTableItemsByRange(editor)
  19219. },
  19220. getUETableBySelected = function (editor) {
  19221. return UT.getUETableBySelected(editor)
  19222. },
  19223. getDefaultValue = function (editor, table) {
  19224. return UT.getDefaultValue(editor, table)
  19225. },
  19226. getUETable = function (tdOrTable) {
  19227. return UT.getUETable(tdOrTable)
  19228. }
  19229. UE.commands['inserttable'] = {
  19230. queryCommandState: function () {
  19231. return getTableItemsByRange(this).table ? -1 : 0
  19232. },
  19233. execCommand: function (cmd, opt) {
  19234. function createTable(opt, tdWidth) {
  19235. var html = [],
  19236. rowsNum = opt.numRows,
  19237. colsNum = opt.numCols
  19238. for (var r = 0; r < rowsNum; r++) {
  19239. html.push('<tr' + (r == 0 ? ' class="firstRow"' : '') + '>')
  19240. for (var c = 0; c < colsNum; c++) {
  19241. html.push(
  19242. '<td width="' +
  19243. tdWidth +
  19244. '" vAlign="' +
  19245. opt.tdvalign +
  19246. '" >' +
  19247. (browser.ie && browser.version < 11 ? domUtils.fillChar : '<br/>') +
  19248. '</td>'
  19249. )
  19250. }
  19251. html.push('</tr>')
  19252. }
  19253. //禁止指定table-width
  19254. return '<table><tbody>' + html.join('') + '</tbody></table>'
  19255. }
  19256. if (!opt) {
  19257. opt = utils.extend(
  19258. {},
  19259. {
  19260. numCols: this.options.defaultCols,
  19261. numRows: this.options.defaultRows,
  19262. tdvalign: this.options.tdvalign
  19263. }
  19264. )
  19265. }
  19266. var me = this
  19267. var range = this.selection.getRange(),
  19268. start = range.startContainer,
  19269. firstParentBlock =
  19270. domUtils.findParent(
  19271. start,
  19272. function (node) {
  19273. return domUtils.isBlockElm(node)
  19274. },
  19275. true
  19276. ) || me.body
  19277. var defaultValue = getDefaultValue(me),
  19278. tableWidth = firstParentBlock.offsetWidth,
  19279. tdWidth = Math.floor(
  19280. tableWidth / opt.numCols - defaultValue.tdPadding * 2 - defaultValue.tdBorder
  19281. )
  19282. //todo其他属性
  19283. !opt.tdvalign && (opt.tdvalign = me.options.tdvalign)
  19284. me.execCommand('inserthtml', createTable(opt, tdWidth))
  19285. }
  19286. }
  19287. UE.commands['insertparagraphbeforetable'] = {
  19288. queryCommandState: function () {
  19289. return getTableItemsByRange(this).cell ? 0 : -1
  19290. },
  19291. execCommand: function () {
  19292. var table = getTableItemsByRange(this).table
  19293. if (table) {
  19294. var p = this.document.createElement('p')
  19295. p.innerHTML = browser.ie ? '&nbsp;' : '<br />'
  19296. table.parentNode.insertBefore(p, table)
  19297. this.selection.getRange().setStart(p, 0).setCursor()
  19298. }
  19299. }
  19300. }
  19301. UE.commands['deletetable'] = {
  19302. queryCommandState: function () {
  19303. var rng = this.selection.getRange()
  19304. return domUtils.findParentByTagName(rng.startContainer, 'table', true) ? 0 : -1
  19305. },
  19306. execCommand: function (cmd, table) {
  19307. var rng = this.selection.getRange()
  19308. table = table || domUtils.findParentByTagName(rng.startContainer, 'table', true)
  19309. if (table) {
  19310. var next = table.nextSibling
  19311. if (!next) {
  19312. next = domUtils.createElement(this.document, 'p', {
  19313. innerHTML: browser.ie ? domUtils.fillChar : '<br/>'
  19314. })
  19315. table.parentNode.insertBefore(next, table)
  19316. }
  19317. domUtils.remove(table)
  19318. rng = this.selection.getRange()
  19319. if (next.nodeType == 3) {
  19320. rng.setStartBefore(next)
  19321. } else {
  19322. rng.setStart(next, 0)
  19323. }
  19324. rng.setCursor(false, true)
  19325. this.fireEvent('tablehasdeleted')
  19326. }
  19327. }
  19328. }
  19329. UE.commands['cellalign'] = {
  19330. queryCommandState: function () {
  19331. return getSelectedArr(this).length ? 0 : -1
  19332. },
  19333. execCommand: function (cmd, align) {
  19334. var selectedTds = getSelectedArr(this)
  19335. if (selectedTds.length) {
  19336. for (var i = 0, ci; (ci = selectedTds[i++]); ) {
  19337. ci.setAttribute('align', align)
  19338. }
  19339. }
  19340. }
  19341. }
  19342. UE.commands['cellvalign'] = {
  19343. queryCommandState: function () {
  19344. return getSelectedArr(this).length ? 0 : -1
  19345. },
  19346. execCommand: function (cmd, valign) {
  19347. var selectedTds = getSelectedArr(this)
  19348. if (selectedTds.length) {
  19349. for (var i = 0, ci; (ci = selectedTds[i++]); ) {
  19350. ci.setAttribute('vAlign', valign)
  19351. }
  19352. }
  19353. }
  19354. }
  19355. UE.commands['insertcaption'] = {
  19356. queryCommandState: function () {
  19357. var table = getTableItemsByRange(this).table
  19358. if (table) {
  19359. return table.getElementsByTagName('caption').length == 0 ? 1 : -1
  19360. }
  19361. return -1
  19362. },
  19363. execCommand: function () {
  19364. var table = getTableItemsByRange(this).table
  19365. if (table) {
  19366. var caption = this.document.createElement('caption')
  19367. caption.innerHTML = browser.ie ? domUtils.fillChar : '<br/>'
  19368. table.insertBefore(caption, table.firstChild)
  19369. var range = this.selection.getRange()
  19370. range.setStart(caption, 0).setCursor()
  19371. }
  19372. }
  19373. }
  19374. UE.commands['deletecaption'] = {
  19375. queryCommandState: function () {
  19376. var rng = this.selection.getRange(),
  19377. table = domUtils.findParentByTagName(rng.startContainer, 'table')
  19378. if (table) {
  19379. return table.getElementsByTagName('caption').length == 0 ? -1 : 1
  19380. }
  19381. return -1
  19382. },
  19383. execCommand: function () {
  19384. var rng = this.selection.getRange(),
  19385. table = domUtils.findParentByTagName(rng.startContainer, 'table')
  19386. if (table) {
  19387. domUtils.remove(table.getElementsByTagName('caption')[0])
  19388. var range = this.selection.getRange()
  19389. range.setStart(table.rows[0].cells[0], 0).setCursor()
  19390. }
  19391. }
  19392. }
  19393. UE.commands['inserttitle'] = {
  19394. queryCommandState: function () {
  19395. var table = getTableItemsByRange(this).table
  19396. if (table) {
  19397. var firstRow = table.rows[0]
  19398. return firstRow.cells[firstRow.cells.length - 1].tagName.toLowerCase() != 'th' ? 0 : -1
  19399. }
  19400. return -1
  19401. },
  19402. execCommand: function () {
  19403. var table = getTableItemsByRange(this).table
  19404. if (table) {
  19405. getUETable(table).insertRow(0, 'th')
  19406. }
  19407. var th = table.getElementsByTagName('th')[0]
  19408. this.selection.getRange().setStart(th, 0).setCursor(false, true)
  19409. }
  19410. }
  19411. UE.commands['deletetitle'] = {
  19412. queryCommandState: function () {
  19413. var table = getTableItemsByRange(this).table
  19414. if (table) {
  19415. var firstRow = table.rows[0]
  19416. return firstRow.cells[firstRow.cells.length - 1].tagName.toLowerCase() == 'th' ? 0 : -1
  19417. }
  19418. return -1
  19419. },
  19420. execCommand: function () {
  19421. var table = getTableItemsByRange(this).table
  19422. if (table) {
  19423. domUtils.remove(table.rows[0])
  19424. }
  19425. var td = table.getElementsByTagName('td')[0]
  19426. this.selection.getRange().setStart(td, 0).setCursor(false, true)
  19427. }
  19428. }
  19429. UE.commands['inserttitlecol'] = {
  19430. queryCommandState: function () {
  19431. var table = getTableItemsByRange(this).table
  19432. if (table) {
  19433. var lastRow = table.rows[table.rows.length - 1]
  19434. return lastRow.getElementsByTagName('th').length ? -1 : 0
  19435. }
  19436. return -1
  19437. },
  19438. execCommand: function (cmd) {
  19439. var table = getTableItemsByRange(this).table
  19440. if (table) {
  19441. getUETable(table).insertCol(0, 'th')
  19442. }
  19443. resetTdWidth(table, this)
  19444. var th = table.getElementsByTagName('th')[0]
  19445. this.selection.getRange().setStart(th, 0).setCursor(false, true)
  19446. }
  19447. }
  19448. UE.commands['deletetitlecol'] = {
  19449. queryCommandState: function () {
  19450. var table = getTableItemsByRange(this).table
  19451. if (table) {
  19452. var lastRow = table.rows[table.rows.length - 1]
  19453. return lastRow.getElementsByTagName('th').length ? 0 : -1
  19454. }
  19455. return -1
  19456. },
  19457. execCommand: function () {
  19458. var table = getTableItemsByRange(this).table
  19459. if (table) {
  19460. for (var i = 0; i < table.rows.length; i++) {
  19461. domUtils.remove(table.rows[i].children[0])
  19462. }
  19463. }
  19464. resetTdWidth(table, this)
  19465. var td = table.getElementsByTagName('td')[0]
  19466. this.selection.getRange().setStart(td, 0).setCursor(false, true)
  19467. }
  19468. }
  19469. UE.commands['mergeright'] = {
  19470. queryCommandState: function (cmd) {
  19471. var tableItems = getTableItemsByRange(this),
  19472. table = tableItems.table,
  19473. cell = tableItems.cell
  19474. if (!table || !cell) return -1
  19475. var ut = getUETable(table)
  19476. if (ut.selectedTds.length) return -1
  19477. var cellInfo = ut.getCellInfo(cell),
  19478. rightColIndex = cellInfo.colIndex + cellInfo.colSpan
  19479. if (rightColIndex >= ut.colsNum) return -1 // 如果处于最右边则不能向右合并
  19480. var rightCellInfo = ut.indexTable[cellInfo.rowIndex][rightColIndex],
  19481. rightCell = table.rows[rightCellInfo.rowIndex].cells[rightCellInfo.cellIndex]
  19482. if (!rightCell || cell.tagName != rightCell.tagName) return -1 // TH和TD不能相互合并
  19483. // 当且仅当两个Cell的开始列号和结束列号一致时能进行合并
  19484. return rightCellInfo.rowIndex == cellInfo.rowIndex &&
  19485. rightCellInfo.rowSpan == cellInfo.rowSpan
  19486. ? 0
  19487. : -1
  19488. },
  19489. execCommand: function (cmd) {
  19490. var rng = this.selection.getRange(),
  19491. bk = rng.createBookmark(true)
  19492. var cell = getTableItemsByRange(this).cell,
  19493. ut = getUETable(cell)
  19494. ut.mergeRight(cell)
  19495. rng.moveToBookmark(bk).select()
  19496. }
  19497. }
  19498. UE.commands['mergedown'] = {
  19499. queryCommandState: function (cmd) {
  19500. var tableItems = getTableItemsByRange(this),
  19501. table = tableItems.table,
  19502. cell = tableItems.cell
  19503. if (!table || !cell) return -1
  19504. var ut = getUETable(table)
  19505. if (ut.selectedTds.length) return -1
  19506. var cellInfo = ut.getCellInfo(cell),
  19507. downRowIndex = cellInfo.rowIndex + cellInfo.rowSpan
  19508. if (downRowIndex >= ut.rowsNum) return -1 // 如果处于最下边则不能向下合并
  19509. var downCellInfo = ut.indexTable[downRowIndex][cellInfo.colIndex],
  19510. downCell = table.rows[downCellInfo.rowIndex].cells[downCellInfo.cellIndex]
  19511. if (!downCell || cell.tagName != downCell.tagName) return -1 // TH和TD不能相互合并
  19512. // 当且仅当两个Cell的开始列号和结束列号一致时能进行合并
  19513. return downCellInfo.colIndex == cellInfo.colIndex &&
  19514. downCellInfo.colSpan == cellInfo.colSpan
  19515. ? 0
  19516. : -1
  19517. },
  19518. execCommand: function () {
  19519. var rng = this.selection.getRange(),
  19520. bk = rng.createBookmark(true)
  19521. var cell = getTableItemsByRange(this).cell,
  19522. ut = getUETable(cell)
  19523. ut.mergeDown(cell)
  19524. rng.moveToBookmark(bk).select()
  19525. }
  19526. }
  19527. UE.commands['mergecells'] = {
  19528. queryCommandState: function () {
  19529. return getUETableBySelected(this) ? 0 : -1
  19530. },
  19531. execCommand: function () {
  19532. var ut = getUETableBySelected(this)
  19533. if (ut && ut.selectedTds.length) {
  19534. var cell = ut.selectedTds[0]
  19535. ut.mergeRange()
  19536. var rng = this.selection.getRange()
  19537. if (domUtils.isEmptyBlock(cell)) {
  19538. rng.setStart(cell, 0).collapse(true)
  19539. } else {
  19540. rng.selectNodeContents(cell)
  19541. }
  19542. rng.select()
  19543. }
  19544. }
  19545. }
  19546. UE.commands['insertrow'] = {
  19547. queryCommandState: function () {
  19548. var tableItems = getTableItemsByRange(this),
  19549. cell = tableItems.cell
  19550. return cell &&
  19551. (cell.tagName == 'TD' ||
  19552. (cell.tagName == 'TH' && tableItems.tr !== tableItems.table.rows[0])) &&
  19553. getUETable(tableItems.table).rowsNum < this.options.maxRowNum
  19554. ? 0
  19555. : -1
  19556. },
  19557. execCommand: function () {
  19558. var rng = this.selection.getRange(),
  19559. bk = rng.createBookmark(true)
  19560. var tableItems = getTableItemsByRange(this),
  19561. cell = tableItems.cell,
  19562. table = tableItems.table,
  19563. ut = getUETable(table),
  19564. cellInfo = ut.getCellInfo(cell)
  19565. //ut.insertRow(!ut.selectedTds.length ? cellInfo.rowIndex:ut.cellsRange.beginRowIndex,'');
  19566. if (!ut.selectedTds.length) {
  19567. ut.insertRow(cellInfo.rowIndex, cell)
  19568. } else {
  19569. var range = ut.cellsRange
  19570. for (var i = 0, len = range.endRowIndex - range.beginRowIndex + 1; i < len; i++) {
  19571. ut.insertRow(range.beginRowIndex, cell)
  19572. }
  19573. }
  19574. rng.moveToBookmark(bk).select()
  19575. if (table.getAttribute('interlaced') === 'enabled') this.fireEvent('interlacetable', table)
  19576. }
  19577. }
  19578. //后插入行
  19579. UE.commands['insertrownext'] = {
  19580. queryCommandState: function () {
  19581. var tableItems = getTableItemsByRange(this),
  19582. cell = tableItems.cell
  19583. return cell &&
  19584. cell.tagName == 'TD' &&
  19585. getUETable(tableItems.table).rowsNum < this.options.maxRowNum
  19586. ? 0
  19587. : -1
  19588. },
  19589. execCommand: function () {
  19590. var rng = this.selection.getRange(),
  19591. bk = rng.createBookmark(true)
  19592. var tableItems = getTableItemsByRange(this),
  19593. cell = tableItems.cell,
  19594. table = tableItems.table,
  19595. ut = getUETable(table),
  19596. cellInfo = ut.getCellInfo(cell)
  19597. //ut.insertRow(!ut.selectedTds.length? cellInfo.rowIndex + cellInfo.rowSpan : ut.cellsRange.endRowIndex + 1,'');
  19598. if (!ut.selectedTds.length) {
  19599. ut.insertRow(cellInfo.rowIndex + cellInfo.rowSpan, cell)
  19600. } else {
  19601. var range = ut.cellsRange
  19602. for (var i = 0, len = range.endRowIndex - range.beginRowIndex + 1; i < len; i++) {
  19603. ut.insertRow(range.endRowIndex + 1, cell)
  19604. }
  19605. }
  19606. rng.moveToBookmark(bk).select()
  19607. if (table.getAttribute('interlaced') === 'enabled') this.fireEvent('interlacetable', table)
  19608. }
  19609. }
  19610. UE.commands['deleterow'] = {
  19611. queryCommandState: function () {
  19612. var tableItems = getTableItemsByRange(this)
  19613. return tableItems.cell ? 0 : -1
  19614. },
  19615. execCommand: function () {
  19616. var cell = getTableItemsByRange(this).cell,
  19617. ut = getUETable(cell),
  19618. cellsRange = ut.cellsRange,
  19619. cellInfo = ut.getCellInfo(cell),
  19620. preCell = ut.getVSideCell(cell),
  19621. nextCell = ut.getVSideCell(cell, true),
  19622. rng = this.selection.getRange()
  19623. if (utils.isEmptyObject(cellsRange)) {
  19624. ut.deleteRow(cellInfo.rowIndex)
  19625. } else {
  19626. for (var i = cellsRange.beginRowIndex; i < cellsRange.endRowIndex + 1; i++) {
  19627. ut.deleteRow(cellsRange.beginRowIndex)
  19628. }
  19629. }
  19630. var table = ut.table
  19631. if (!table.getElementsByTagName('td').length) {
  19632. var nextSibling = table.nextSibling
  19633. domUtils.remove(table)
  19634. if (nextSibling) {
  19635. rng.setStart(nextSibling, 0).setCursor(false, true)
  19636. }
  19637. } else {
  19638. if (
  19639. cellInfo.rowSpan == 1 ||
  19640. cellInfo.rowSpan == cellsRange.endRowIndex - cellsRange.beginRowIndex + 1
  19641. ) {
  19642. if (nextCell || preCell)
  19643. rng.selectNodeContents(nextCell || preCell).setCursor(false, true)
  19644. } else {
  19645. var newCell = ut.getCell(
  19646. cellInfo.rowIndex,
  19647. ut.indexTable[cellInfo.rowIndex][cellInfo.colIndex].cellIndex
  19648. )
  19649. if (newCell) rng.selectNodeContents(newCell).setCursor(false, true)
  19650. }
  19651. }
  19652. if (table.getAttribute('interlaced') === 'enabled') this.fireEvent('interlacetable', table)
  19653. }
  19654. }
  19655. UE.commands['insertcol'] = {
  19656. queryCommandState: function (cmd) {
  19657. var tableItems = getTableItemsByRange(this),
  19658. cell = tableItems.cell
  19659. return cell &&
  19660. (cell.tagName == 'TD' || (cell.tagName == 'TH' && cell !== tableItems.tr.cells[0])) &&
  19661. getUETable(tableItems.table).colsNum < this.options.maxColNum
  19662. ? 0
  19663. : -1
  19664. },
  19665. execCommand: function (cmd) {
  19666. var rng = this.selection.getRange(),
  19667. bk = rng.createBookmark(true)
  19668. if (this.queryCommandState(cmd) == -1) return
  19669. var cell = getTableItemsByRange(this).cell,
  19670. ut = getUETable(cell),
  19671. cellInfo = ut.getCellInfo(cell)
  19672. //ut.insertCol(!ut.selectedTds.length ? cellInfo.colIndex:ut.cellsRange.beginColIndex);
  19673. if (!ut.selectedTds.length) {
  19674. ut.insertCol(cellInfo.colIndex, cell)
  19675. } else {
  19676. var range = ut.cellsRange
  19677. for (var i = 0, len = range.endColIndex - range.beginColIndex + 1; i < len; i++) {
  19678. ut.insertCol(range.beginColIndex, cell)
  19679. }
  19680. }
  19681. rng.moveToBookmark(bk).select(true)
  19682. }
  19683. }
  19684. UE.commands['insertcolnext'] = {
  19685. queryCommandState: function () {
  19686. var tableItems = getTableItemsByRange(this),
  19687. cell = tableItems.cell
  19688. return cell && getUETable(tableItems.table).colsNum < this.options.maxColNum ? 0 : -1
  19689. },
  19690. execCommand: function () {
  19691. var rng = this.selection.getRange(),
  19692. bk = rng.createBookmark(true)
  19693. var cell = getTableItemsByRange(this).cell,
  19694. ut = getUETable(cell),
  19695. cellInfo = ut.getCellInfo(cell)
  19696. //ut.insertCol(!ut.selectedTds.length ? cellInfo.colIndex + cellInfo.colSpan:ut.cellsRange.endColIndex +1);
  19697. if (!ut.selectedTds.length) {
  19698. ut.insertCol(cellInfo.colIndex + cellInfo.colSpan, cell)
  19699. } else {
  19700. var range = ut.cellsRange
  19701. for (var i = 0, len = range.endColIndex - range.beginColIndex + 1; i < len; i++) {
  19702. ut.insertCol(range.endColIndex + 1, cell)
  19703. }
  19704. }
  19705. rng.moveToBookmark(bk).select()
  19706. }
  19707. }
  19708. UE.commands['deletecol'] = {
  19709. queryCommandState: function () {
  19710. var tableItems = getTableItemsByRange(this)
  19711. return tableItems.cell ? 0 : -1
  19712. },
  19713. execCommand: function () {
  19714. var cell = getTableItemsByRange(this).cell,
  19715. ut = getUETable(cell),
  19716. range = ut.cellsRange,
  19717. cellInfo = ut.getCellInfo(cell),
  19718. preCell = ut.getHSideCell(cell),
  19719. nextCell = ut.getHSideCell(cell, true)
  19720. if (utils.isEmptyObject(range)) {
  19721. ut.deleteCol(cellInfo.colIndex)
  19722. } else {
  19723. for (var i = range.beginColIndex; i < range.endColIndex + 1; i++) {
  19724. ut.deleteCol(range.beginColIndex)
  19725. }
  19726. }
  19727. var table = ut.table,
  19728. rng = this.selection.getRange()
  19729. if (!table.getElementsByTagName('td').length) {
  19730. var nextSibling = table.nextSibling
  19731. domUtils.remove(table)
  19732. if (nextSibling) {
  19733. rng.setStart(nextSibling, 0).setCursor(false, true)
  19734. }
  19735. } else {
  19736. if (domUtils.inDoc(cell, this.document)) {
  19737. rng.setStart(cell, 0).setCursor(false, true)
  19738. } else {
  19739. if (nextCell && domUtils.inDoc(nextCell, this.document)) {
  19740. rng.selectNodeContents(nextCell).setCursor(false, true)
  19741. } else {
  19742. if (preCell && domUtils.inDoc(preCell, this.document)) {
  19743. rng.selectNodeContents(preCell).setCursor(true, true)
  19744. }
  19745. }
  19746. }
  19747. }
  19748. }
  19749. }
  19750. UE.commands['splittocells'] = {
  19751. queryCommandState: function () {
  19752. var tableItems = getTableItemsByRange(this),
  19753. cell = tableItems.cell
  19754. if (!cell) return -1
  19755. var ut = getUETable(tableItems.table)
  19756. if (ut.selectedTds.length > 0) return -1
  19757. return cell && (cell.colSpan > 1 || cell.rowSpan > 1) ? 0 : -1
  19758. },
  19759. execCommand: function () {
  19760. var rng = this.selection.getRange(),
  19761. bk = rng.createBookmark(true)
  19762. var cell = getTableItemsByRange(this).cell,
  19763. ut = getUETable(cell)
  19764. ut.splitToCells(cell)
  19765. rng.moveToBookmark(bk).select()
  19766. }
  19767. }
  19768. UE.commands['splittorows'] = {
  19769. queryCommandState: function () {
  19770. var tableItems = getTableItemsByRange(this),
  19771. cell = tableItems.cell
  19772. if (!cell) return -1
  19773. var ut = getUETable(tableItems.table)
  19774. if (ut.selectedTds.length > 0) return -1
  19775. return cell && cell.rowSpan > 1 ? 0 : -1
  19776. },
  19777. execCommand: function () {
  19778. var rng = this.selection.getRange(),
  19779. bk = rng.createBookmark(true)
  19780. var cell = getTableItemsByRange(this).cell,
  19781. ut = getUETable(cell)
  19782. ut.splitToRows(cell)
  19783. rng.moveToBookmark(bk).select()
  19784. }
  19785. }
  19786. UE.commands['splittocols'] = {
  19787. queryCommandState: function () {
  19788. var tableItems = getTableItemsByRange(this),
  19789. cell = tableItems.cell
  19790. if (!cell) return -1
  19791. var ut = getUETable(tableItems.table)
  19792. if (ut.selectedTds.length > 0) return -1
  19793. return cell && cell.colSpan > 1 ? 0 : -1
  19794. },
  19795. execCommand: function () {
  19796. var rng = this.selection.getRange(),
  19797. bk = rng.createBookmark(true)
  19798. var cell = getTableItemsByRange(this).cell,
  19799. ut = getUETable(cell)
  19800. ut.splitToCols(cell)
  19801. rng.moveToBookmark(bk).select()
  19802. }
  19803. }
  19804. UE.commands['adaptbytext'] = UE.commands['adaptbywindow'] = {
  19805. queryCommandState: function () {
  19806. return getTableItemsByRange(this).table ? 0 : -1
  19807. },
  19808. execCommand: function (cmd) {
  19809. var tableItems = getTableItemsByRange(this),
  19810. table = tableItems.table
  19811. if (table) {
  19812. if (cmd == 'adaptbywindow') {
  19813. resetTdWidth(table, this)
  19814. } else {
  19815. var cells = domUtils.getElementsByTagName(table, 'td th')
  19816. utils.each(cells, function (cell) {
  19817. cell.removeAttribute('width')
  19818. })
  19819. table.removeAttribute('width')
  19820. }
  19821. }
  19822. }
  19823. }
  19824. //平均分配各列
  19825. UE.commands['averagedistributecol'] = {
  19826. queryCommandState: function () {
  19827. var ut = getUETableBySelected(this)
  19828. if (!ut) return -1
  19829. return ut.isFullRow() || ut.isFullCol() ? 0 : -1
  19830. },
  19831. execCommand: function (cmd) {
  19832. var me = this,
  19833. ut = getUETableBySelected(me)
  19834. function getAverageWidth() {
  19835. var tb = ut.table,
  19836. averageWidth,
  19837. sumWidth = 0,
  19838. colsNum = 0,
  19839. tbAttr = getDefaultValue(me, tb)
  19840. if (ut.isFullRow()) {
  19841. sumWidth = tb.offsetWidth
  19842. colsNum = ut.colsNum
  19843. } else {
  19844. var begin = ut.cellsRange.beginColIndex,
  19845. end = ut.cellsRange.endColIndex,
  19846. node
  19847. for (var i = begin; i <= end; ) {
  19848. node = ut.selectedTds[i]
  19849. sumWidth += node.offsetWidth
  19850. i += node.colSpan
  19851. colsNum += 1
  19852. }
  19853. }
  19854. averageWidth = Math.ceil(sumWidth / colsNum) - tbAttr.tdBorder * 2 - tbAttr.tdPadding * 2
  19855. return averageWidth
  19856. }
  19857. function setAverageWidth(averageWidth) {
  19858. utils.each(domUtils.getElementsByTagName(ut.table, 'th'), function (node) {
  19859. node.setAttribute('width', '')
  19860. })
  19861. var cells = ut.isFullRow()
  19862. ? domUtils.getElementsByTagName(ut.table, 'td')
  19863. : ut.selectedTds
  19864. utils.each(cells, function (node) {
  19865. if (node.colSpan == 1) {
  19866. node.setAttribute('width', averageWidth)
  19867. }
  19868. })
  19869. }
  19870. if (ut && ut.selectedTds.length) {
  19871. setAverageWidth(getAverageWidth())
  19872. }
  19873. }
  19874. }
  19875. //平均分配各行
  19876. UE.commands['averagedistributerow'] = {
  19877. queryCommandState: function () {
  19878. var ut = getUETableBySelected(this)
  19879. if (!ut) return -1
  19880. if (ut.selectedTds && /th/gi.test(ut.selectedTds[0].tagName)) return -1
  19881. return ut.isFullRow() || ut.isFullCol() ? 0 : -1
  19882. },
  19883. execCommand: function (cmd) {
  19884. var me = this,
  19885. ut = getUETableBySelected(me)
  19886. function getAverageHeight() {
  19887. var averageHeight,
  19888. rowNum,
  19889. sumHeight = 0,
  19890. tb = ut.table,
  19891. tbAttr = getDefaultValue(me, tb),
  19892. tdpadding = parseInt(
  19893. domUtils.getComputedStyle(tb.getElementsByTagName('td')[0], 'padding-top')
  19894. )
  19895. if (ut.isFullCol()) {
  19896. var captionArr = domUtils.getElementsByTagName(tb, 'caption'),
  19897. thArr = domUtils.getElementsByTagName(tb, 'th'),
  19898. captionHeight,
  19899. thHeight
  19900. if (captionArr.length > 0) {
  19901. captionHeight = captionArr[0].offsetHeight
  19902. }
  19903. if (thArr.length > 0) {
  19904. thHeight = thArr[0].offsetHeight
  19905. }
  19906. sumHeight = tb.offsetHeight - (captionHeight || 0) - (thHeight || 0)
  19907. rowNum = thArr.length == 0 ? ut.rowsNum : ut.rowsNum - 1
  19908. } else {
  19909. var begin = ut.cellsRange.beginRowIndex,
  19910. end = ut.cellsRange.endRowIndex,
  19911. count = 0,
  19912. trs = domUtils.getElementsByTagName(tb, 'tr')
  19913. for (var i = begin; i <= end; i++) {
  19914. sumHeight += trs[i].offsetHeight
  19915. count += 1
  19916. }
  19917. rowNum = count
  19918. }
  19919. //ie8下是混杂模式
  19920. if (browser.ie && browser.version < 9) {
  19921. averageHeight = Math.ceil(sumHeight / rowNum)
  19922. } else {
  19923. averageHeight = Math.ceil(sumHeight / rowNum) - tbAttr.tdBorder * 2 - tdpadding * 2
  19924. }
  19925. return averageHeight
  19926. }
  19927. function setAverageHeight(averageHeight) {
  19928. var cells = ut.isFullCol()
  19929. ? domUtils.getElementsByTagName(ut.table, 'td')
  19930. : ut.selectedTds
  19931. utils.each(cells, function (node) {
  19932. if (node.rowSpan == 1) {
  19933. node.setAttribute('height', averageHeight)
  19934. }
  19935. })
  19936. }
  19937. if (ut && ut.selectedTds.length) {
  19938. setAverageHeight(getAverageHeight())
  19939. }
  19940. }
  19941. }
  19942. //单元格对齐方式
  19943. UE.commands['cellalignment'] = {
  19944. queryCommandState: function () {
  19945. return getTableItemsByRange(this).table ? 0 : -1
  19946. },
  19947. execCommand: function (cmd, data) {
  19948. var me = this,
  19949. ut = getUETableBySelected(me)
  19950. if (!ut) {
  19951. var start = me.selection.getStart(),
  19952. cell = start && domUtils.findParentByTagName(start, ['td', 'th', 'caption'], true)
  19953. if (!/caption/gi.test(cell.tagName)) {
  19954. domUtils.setAttributes(cell, data)
  19955. } else {
  19956. cell.style.textAlign = data.align
  19957. cell.style.verticalAlign = data.vAlign
  19958. }
  19959. me.selection.getRange().setCursor(true)
  19960. } else {
  19961. utils.each(ut.selectedTds, function (cell) {
  19962. domUtils.setAttributes(cell, data)
  19963. })
  19964. }
  19965. },
  19966. /**
  19967. * 查询当前点击的单元格的对齐状态, 如果当前已经选择了多个单元格, 则会返回所有单元格经过统一协调过后的状态
  19968. * @see UE.UETable.getTableCellAlignState
  19969. */
  19970. queryCommandValue: function (cmd) {
  19971. var activeMenuCell = getTableItemsByRange(this).cell
  19972. if (!activeMenuCell) {
  19973. activeMenuCell = getSelectedArr(this)[0]
  19974. }
  19975. if (!activeMenuCell) {
  19976. return null
  19977. } else {
  19978. //获取同时选中的其他单元格
  19979. var cells = UE.UETable.getUETable(activeMenuCell).selectedTds
  19980. !cells.length && (cells = activeMenuCell)
  19981. return UE.UETable.getTableCellAlignState(cells)
  19982. }
  19983. }
  19984. }
  19985. //表格对齐方式
  19986. UE.commands['tablealignment'] = {
  19987. queryCommandState: function () {
  19988. if (browser.ie && browser.version < 8) {
  19989. return -1
  19990. }
  19991. return getTableItemsByRange(this).table ? 0 : -1
  19992. },
  19993. execCommand: function (cmd, value) {
  19994. var me = this,
  19995. start = me.selection.getStart(),
  19996. table = start && domUtils.findParentByTagName(start, ['table'], true)
  19997. if (table) {
  19998. table.setAttribute('align', value)
  19999. }
  20000. }
  20001. }
  20002. //表格属性
  20003. UE.commands['edittable'] = {
  20004. queryCommandState: function () {
  20005. return getTableItemsByRange(this).table ? 0 : -1
  20006. },
  20007. execCommand: function (cmd, color) {
  20008. var rng = this.selection.getRange(),
  20009. table = domUtils.findParentByTagName(rng.startContainer, 'table')
  20010. if (table) {
  20011. var arr = domUtils
  20012. .getElementsByTagName(table, 'td')
  20013. .concat(
  20014. domUtils.getElementsByTagName(table, 'th'),
  20015. domUtils.getElementsByTagName(table, 'caption')
  20016. )
  20017. utils.each(arr, function (node) {
  20018. node.style.borderColor = color
  20019. })
  20020. }
  20021. }
  20022. }
  20023. //单元格属性
  20024. UE.commands['edittd'] = {
  20025. queryCommandState: function () {
  20026. return getTableItemsByRange(this).table ? 0 : -1
  20027. },
  20028. execCommand: function (cmd, bkColor) {
  20029. var me = this,
  20030. ut = getUETableBySelected(me)
  20031. if (!ut) {
  20032. var start = me.selection.getStart(),
  20033. cell = start && domUtils.findParentByTagName(start, ['td', 'th', 'caption'], true)
  20034. if (cell) {
  20035. cell.style.backgroundColor = bkColor
  20036. }
  20037. } else {
  20038. utils.each(ut.selectedTds, function (cell) {
  20039. cell.style.backgroundColor = bkColor
  20040. })
  20041. }
  20042. }
  20043. }
  20044. UE.commands['settablebackground'] = {
  20045. queryCommandState: function () {
  20046. return getSelectedArr(this).length > 1 ? 0 : -1
  20047. },
  20048. execCommand: function (cmd, value) {
  20049. var cells, ut
  20050. cells = getSelectedArr(this)
  20051. ut = getUETable(cells[0])
  20052. ut.setBackground(cells, value)
  20053. }
  20054. }
  20055. UE.commands['cleartablebackground'] = {
  20056. queryCommandState: function () {
  20057. var cells = getSelectedArr(this)
  20058. if (!cells.length) return -1
  20059. for (var i = 0, cell; (cell = cells[i++]); ) {
  20060. if (cell.style.backgroundColor !== '') return 0
  20061. }
  20062. return -1
  20063. },
  20064. execCommand: function () {
  20065. var cells = getSelectedArr(this),
  20066. ut = getUETable(cells[0])
  20067. ut.removeBackground(cells)
  20068. }
  20069. }
  20070. UE.commands['interlacetable'] = UE.commands['uninterlacetable'] = {
  20071. queryCommandState: function (cmd) {
  20072. var table = getTableItemsByRange(this).table
  20073. if (!table) return -1
  20074. var interlaced = table.getAttribute('interlaced')
  20075. if (cmd == 'interlacetable') {
  20076. //TODO 待定
  20077. //是否需要待定,如果设置,则命令只能单次执行成功,但反射具备toggle效果;否则可以覆盖前次命令,但反射将不存在toggle效果
  20078. return interlaced === 'enabled' ? -1 : 0
  20079. } else {
  20080. return !interlaced || interlaced === 'disabled' ? -1 : 0
  20081. }
  20082. },
  20083. execCommand: function (cmd, classList) {
  20084. var table = getTableItemsByRange(this).table
  20085. if (cmd == 'interlacetable') {
  20086. table.setAttribute('interlaced', 'enabled')
  20087. this.fireEvent('interlacetable', table, classList)
  20088. } else {
  20089. table.setAttribute('interlaced', 'disabled')
  20090. this.fireEvent('uninterlacetable', table)
  20091. }
  20092. }
  20093. }
  20094. UE.commands['setbordervisible'] = {
  20095. queryCommandState: function (cmd) {
  20096. var table = getTableItemsByRange(this).table
  20097. if (!table) return -1
  20098. return 0
  20099. },
  20100. execCommand: function () {
  20101. var table = getTableItemsByRange(this).table
  20102. utils.each(domUtils.getElementsByTagName(table, 'td'), function (td) {
  20103. td.style.borderWidth = '1px'
  20104. td.style.borderStyle = 'solid'
  20105. })
  20106. }
  20107. }
  20108. function resetTdWidth(table, editor) {
  20109. var tds = domUtils.getElementsByTagName(table, 'td th')
  20110. utils.each(tds, function (td) {
  20111. td.removeAttribute('width')
  20112. })
  20113. table.setAttribute('width', getTableWidth(editor, true, getDefaultValue(editor, table)))
  20114. var tdsWidths = []
  20115. setTimeout(function () {
  20116. utils.each(tds, function (td) {
  20117. td.colSpan == 1 && tdsWidths.push(td.offsetWidth)
  20118. })
  20119. utils.each(tds, function (td, i) {
  20120. td.colSpan == 1 && td.setAttribute('width', tdsWidths[i] + '')
  20121. })
  20122. }, 0)
  20123. }
  20124. function getTableWidth(editor, needIEHack, defaultValue) {
  20125. var body = editor.body
  20126. return (
  20127. body.offsetWidth -
  20128. (needIEHack ? parseInt(domUtils.getComputedStyle(body, 'margin-left'), 10) * 2 : 0) -
  20129. defaultValue.tableBorder * 2 -
  20130. (editor.options.offsetWidth || 0)
  20131. )
  20132. }
  20133. function getSelectedArr(editor) {
  20134. var cell = getTableItemsByRange(editor).cell
  20135. if (cell) {
  20136. var ut = getUETable(cell)
  20137. return ut.selectedTds.length ? ut.selectedTds : [cell]
  20138. } else {
  20139. return []
  20140. }
  20141. }
  20142. })()
  20143. // plugins/table.action.js
  20144. /**
  20145. * Created with JetBrains PhpStorm.
  20146. * User: taoqili
  20147. * Date: 12-10-12
  20148. * Time: 上午10:05
  20149. * To change this template use File | Settings | File Templates.
  20150. */
  20151. UE.plugins['table'] = function () {
  20152. var me = this,
  20153. tabTimer = null,
  20154. //拖动计时器
  20155. tableDragTimer = null,
  20156. //双击计时器
  20157. tableResizeTimer = null,
  20158. //单元格最小宽度
  20159. cellMinWidth = 5,
  20160. isInResizeBuffer = false,
  20161. //单元格边框大小
  20162. cellBorderWidth = 5,
  20163. //鼠标偏移距离
  20164. offsetOfTableCell = 10,
  20165. //记录在有限时间内的点击状态, 共有3个取值, 0, 1, 2。 0代表未初始化, 1代表单击了1次,2代表2次
  20166. singleClickState = 0,
  20167. userActionStatus = null,
  20168. //双击允许的时间范围
  20169. dblclickTime = 360,
  20170. UT = UE.UETable,
  20171. getUETable = function (tdOrTable) {
  20172. return UT.getUETable(tdOrTable)
  20173. },
  20174. getUETableBySelected = function (editor) {
  20175. return UT.getUETableBySelected(editor)
  20176. },
  20177. getDefaultValue = function (editor, table) {
  20178. return UT.getDefaultValue(editor, table)
  20179. },
  20180. removeSelectedClass = function (cells) {
  20181. return UT.removeSelectedClass(cells)
  20182. }
  20183. function showError(e) {
  20184. // throw e;
  20185. }
  20186. me.ready(function () {
  20187. var me = this
  20188. var orgGetText = me.selection.getText
  20189. me.selection.getText = function () {
  20190. var table = getUETableBySelected(me)
  20191. if (table) {
  20192. var str = ''
  20193. utils.each(table.selectedTds, function (td) {
  20194. str += td[browser.ie ? 'innerText' : 'textContent']
  20195. })
  20196. return str
  20197. } else {
  20198. return orgGetText.call(me.selection)
  20199. }
  20200. }
  20201. })
  20202. //处理拖动及框选相关方法
  20203. var startTd = null, //鼠标按下时的锚点td
  20204. currentTd = null, //当前鼠标经过时的td
  20205. onDrag = '', //指示当前拖动状态,其值可为"","h","v" ,分别表示未拖动状态,横向拖动状态,纵向拖动状态,用于鼠标移动过程中的判断
  20206. onBorder = false, //检测鼠标按下时是否处在单元格边缘位置
  20207. dragButton = null,
  20208. dragOver = false,
  20209. dragLine = null, //模拟的拖动线
  20210. dragTd = null //发生拖动的目标td
  20211. var mousedown = false,
  20212. //todo 判断混乱模式
  20213. needIEHack = true
  20214. me.setOpt({
  20215. maxColNum: 20,
  20216. maxRowNum: 100,
  20217. defaultCols: 5,
  20218. defaultRows: 5,
  20219. tdvalign: 'top',
  20220. cursorpath: me.options.UEDITOR_HOME_URL + 'themes/default/images/cursor_',
  20221. tableDragable: false,
  20222. classList: ['ue-table-interlace-color-single', 'ue-table-interlace-color-double']
  20223. })
  20224. me.getUETable = getUETable
  20225. var commands = {
  20226. deletetable: 1,
  20227. inserttable: 1,
  20228. cellvalign: 1,
  20229. insertcaption: 1,
  20230. deletecaption: 1,
  20231. inserttitle: 1,
  20232. deletetitle: 1,
  20233. mergeright: 1,
  20234. mergedown: 1,
  20235. mergecells: 1,
  20236. insertrow: 1,
  20237. insertrownext: 1,
  20238. deleterow: 1,
  20239. insertcol: 1,
  20240. insertcolnext: 1,
  20241. deletecol: 1,
  20242. splittocells: 1,
  20243. splittorows: 1,
  20244. splittocols: 1,
  20245. adaptbytext: 1,
  20246. adaptbywindow: 1,
  20247. adaptbycustomer: 1,
  20248. insertparagraph: 1,
  20249. insertparagraphbeforetable: 1,
  20250. averagedistributecol: 1,
  20251. averagedistributerow: 1
  20252. }
  20253. me.ready(function () {
  20254. utils.cssRule(
  20255. 'table',
  20256. //选中的td上的样式
  20257. '.selectTdClass{background-color:#edf5fa !important}' +
  20258. 'table.noBorderTable td,table.noBorderTable th,table.noBorderTable caption{border:1px dashed #ddd !important}' +
  20259. //插入的表格的默认样式
  20260. 'table{margin-bottom:10px;border-collapse:collapse;display:table;}' +
  20261. 'td,th{padding: 5px 10px;border: 1px solid #DDD;}' +
  20262. 'caption{border:1px dashed #DDD;border-bottom:0;padding:3px;text-align:center;}' +
  20263. 'th{border-top:1px solid #BBB;background-color:#F7F7F7;}' +
  20264. 'table tr.firstRow th{border-top-width:2px;}' +
  20265. '.ue-table-interlace-color-single{ background-color: #fcfcfc; } .ue-table-interlace-color-double{ background-color: #f7faff; }' +
  20266. 'td p{margin:0;padding:0;}',
  20267. me.document
  20268. )
  20269. var tableCopyList, isFullCol, isFullRow
  20270. //注册del/backspace事件
  20271. me.addListener('keydown', function (cmd, evt) {
  20272. var me = this
  20273. var keyCode = evt.keyCode || evt.which
  20274. if (keyCode == 8) {
  20275. var ut = getUETableBySelected(me)
  20276. if (ut && ut.selectedTds.length) {
  20277. if (ut.isFullCol()) {
  20278. me.execCommand('deletecol')
  20279. } else if (ut.isFullRow()) {
  20280. me.execCommand('deleterow')
  20281. } else {
  20282. me.fireEvent('delcells')
  20283. }
  20284. domUtils.preventDefault(evt)
  20285. }
  20286. var caption = domUtils.findParentByTagName(me.selection.getStart(), 'caption', true),
  20287. range = me.selection.getRange()
  20288. if (range.collapsed && caption && isEmptyBlock(caption)) {
  20289. me.fireEvent('saveScene')
  20290. var table = caption.parentNode
  20291. domUtils.remove(caption)
  20292. if (table) {
  20293. range.setStart(table.rows[0].cells[0], 0).setCursor(false, true)
  20294. }
  20295. me.fireEvent('saveScene')
  20296. }
  20297. }
  20298. if (keyCode == 46) {
  20299. ut = getUETableBySelected(me)
  20300. if (ut) {
  20301. me.fireEvent('saveScene')
  20302. for (var i = 0, ci; (ci = ut.selectedTds[i++]); ) {
  20303. domUtils.fillNode(me.document, ci)
  20304. }
  20305. me.fireEvent('saveScene')
  20306. domUtils.preventDefault(evt)
  20307. }
  20308. }
  20309. if (keyCode == 13) {
  20310. var rng = me.selection.getRange(),
  20311. caption = domUtils.findParentByTagName(rng.startContainer, 'caption', true)
  20312. if (caption) {
  20313. var table = domUtils.findParentByTagName(caption, 'table')
  20314. if (!rng.collapsed) {
  20315. rng.deleteContents()
  20316. me.fireEvent('saveScene')
  20317. } else {
  20318. if (caption) {
  20319. rng.setStart(table.rows[0].cells[0], 0).setCursor(false, true)
  20320. }
  20321. }
  20322. domUtils.preventDefault(evt)
  20323. return
  20324. }
  20325. if (rng.collapsed) {
  20326. var table = domUtils.findParentByTagName(rng.startContainer, 'table')
  20327. if (table) {
  20328. var cell = table.rows[0].cells[0],
  20329. start = domUtils.findParentByTagName(me.selection.getStart(), ['td', 'th'], true),
  20330. preNode = table.previousSibling
  20331. if (
  20332. cell === start &&
  20333. (!preNode || (preNode.nodeType == 1 && preNode.tagName == 'TABLE')) &&
  20334. domUtils.isStartInblock(rng)
  20335. ) {
  20336. var first = domUtils.findParent(
  20337. me.selection.getStart(),
  20338. function (n) {
  20339. return domUtils.isBlockElm(n)
  20340. },
  20341. true
  20342. )
  20343. if (first && (/t(h|d)/i.test(first.tagName) || first === start.firstChild)) {
  20344. me.execCommand('insertparagraphbeforetable')
  20345. domUtils.preventDefault(evt)
  20346. }
  20347. }
  20348. }
  20349. }
  20350. }
  20351. if ((evt.ctrlKey || evt.metaKey) && evt.keyCode == '67') {
  20352. tableCopyList = null
  20353. var ut = getUETableBySelected(me)
  20354. if (ut) {
  20355. var tds = ut.selectedTds
  20356. isFullCol = ut.isFullCol()
  20357. isFullRow = ut.isFullRow()
  20358. tableCopyList = [[ut.cloneCell(tds[0], null, true)]]
  20359. for (var i = 1, ci; (ci = tds[i]); i++) {
  20360. if (ci.parentNode !== tds[i - 1].parentNode) {
  20361. tableCopyList.push([ut.cloneCell(ci, null, true)])
  20362. } else {
  20363. tableCopyList[tableCopyList.length - 1].push(ut.cloneCell(ci, null, true))
  20364. }
  20365. }
  20366. }
  20367. }
  20368. })
  20369. me.addListener('tablehasdeleted', function () {
  20370. toggleDraggableState(this, false, '', null)
  20371. if (dragButton) domUtils.remove(dragButton)
  20372. })
  20373. me.addListener('beforepaste', function (cmd, html) {
  20374. var me = this
  20375. var rng = me.selection.getRange()
  20376. if (domUtils.findParentByTagName(rng.startContainer, 'caption', true)) {
  20377. var div = me.document.createElement('div')
  20378. div.innerHTML = html.html
  20379. //trace:3729
  20380. html.html = div[browser.ie9below ? 'innerText' : 'textContent']
  20381. return
  20382. }
  20383. var table = getUETableBySelected(me)
  20384. if (tableCopyList) {
  20385. me.fireEvent('saveScene')
  20386. var rng = me.selection.getRange()
  20387. var td = domUtils.findParentByTagName(rng.startContainer, ['td', 'th'], true),
  20388. tmpNode,
  20389. preNode
  20390. if (td) {
  20391. var ut = getUETable(td)
  20392. if (isFullRow) {
  20393. var rowIndex = ut.getCellInfo(td).rowIndex
  20394. if (td.tagName == 'TH') {
  20395. rowIndex++
  20396. }
  20397. for (var i = 0, ci; (ci = tableCopyList[i++]); ) {
  20398. var tr = ut.insertRow(rowIndex++, 'td')
  20399. for (var j = 0, cj; (cj = ci[j]); j++) {
  20400. var cell = tr.cells[j]
  20401. if (!cell) {
  20402. cell = tr.insertCell(j)
  20403. }
  20404. cell.innerHTML = cj.innerHTML
  20405. cj.getAttribute('width') && cell.setAttribute('width', cj.getAttribute('width'))
  20406. cj.getAttribute('vAlign') &&
  20407. cell.setAttribute('vAlign', cj.getAttribute('vAlign'))
  20408. cj.getAttribute('align') && cell.setAttribute('align', cj.getAttribute('align'))
  20409. cj.style.cssText && (cell.style.cssText = cj.style.cssText)
  20410. }
  20411. for (var j = 0, cj; (cj = tr.cells[j]); j++) {
  20412. if (!ci[j]) break
  20413. cj.innerHTML = ci[j].innerHTML
  20414. ci[j].getAttribute('width') &&
  20415. cj.setAttribute('width', ci[j].getAttribute('width'))
  20416. ci[j].getAttribute('vAlign') &&
  20417. cj.setAttribute('vAlign', ci[j].getAttribute('vAlign'))
  20418. ci[j].getAttribute('align') &&
  20419. cj.setAttribute('align', ci[j].getAttribute('align'))
  20420. ci[j].style.cssText && (cj.style.cssText = ci[j].style.cssText)
  20421. }
  20422. }
  20423. } else {
  20424. if (isFullCol) {
  20425. cellInfo = ut.getCellInfo(td)
  20426. var maxColNum = 0
  20427. for (var j = 0, ci = tableCopyList[0], cj; (cj = ci[j++]); ) {
  20428. maxColNum += cj.colSpan || 1
  20429. }
  20430. me.__hasEnterExecCommand = true
  20431. for (i = 0; i < maxColNum; i++) {
  20432. me.execCommand('insertcol')
  20433. }
  20434. me.__hasEnterExecCommand = false
  20435. td = ut.table.rows[0].cells[cellInfo.cellIndex]
  20436. if (td.tagName == 'TH') {
  20437. td = ut.table.rows[1].cells[cellInfo.cellIndex]
  20438. }
  20439. }
  20440. for (var i = 0, ci; (ci = tableCopyList[i++]); ) {
  20441. tmpNode = td
  20442. for (var j = 0, cj; (cj = ci[j++]); ) {
  20443. if (td) {
  20444. td.innerHTML = cj.innerHTML
  20445. //todo 定制处理
  20446. cj.getAttribute('width') && td.setAttribute('width', cj.getAttribute('width'))
  20447. cj.getAttribute('vAlign') &&
  20448. td.setAttribute('vAlign', cj.getAttribute('vAlign'))
  20449. cj.getAttribute('align') && td.setAttribute('align', cj.getAttribute('align'))
  20450. cj.style.cssText && (td.style.cssText = cj.style.cssText)
  20451. preNode = td
  20452. td = td.nextSibling
  20453. } else {
  20454. var cloneTd = cj.cloneNode(true)
  20455. domUtils.removeAttributes(cloneTd, ['class', 'rowSpan', 'colSpan'])
  20456. preNode.parentNode.appendChild(cloneTd)
  20457. }
  20458. }
  20459. td = ut.getNextCell(tmpNode, true, true)
  20460. if (!tableCopyList[i]) break
  20461. if (!td) {
  20462. var cellInfo = ut.getCellInfo(tmpNode)
  20463. ut.table.insertRow(ut.table.rows.length)
  20464. ut.update()
  20465. td = ut.getVSideCell(tmpNode, true)
  20466. }
  20467. }
  20468. }
  20469. ut.update()
  20470. } else {
  20471. table = me.document.createElement('table')
  20472. for (var i = 0, ci; (ci = tableCopyList[i++]); ) {
  20473. var tr = table.insertRow(table.rows.length)
  20474. for (var j = 0, cj; (cj = ci[j++]); ) {
  20475. cloneTd = UT.cloneCell(cj, null, true)
  20476. domUtils.removeAttributes(cloneTd, ['class'])
  20477. tr.appendChild(cloneTd)
  20478. }
  20479. if (j == 2 && cloneTd.rowSpan > 1) {
  20480. cloneTd.rowSpan = 1
  20481. }
  20482. }
  20483. var defaultValue = getDefaultValue(me),
  20484. width =
  20485. me.body.offsetWidth -
  20486. (needIEHack
  20487. ? parseInt(domUtils.getComputedStyle(me.body, 'margin-left'), 10) * 2
  20488. : 0) -
  20489. defaultValue.tableBorder * 2 -
  20490. (me.options.offsetWidth || 0)
  20491. me.execCommand(
  20492. 'insertHTML',
  20493. '<table ' +
  20494. (isFullCol && isFullRow ? 'width="' + width + '"' : '') +
  20495. '>' +
  20496. table.innerHTML.replace(/>\s*</g, '><').replace(/\bth\b/gi, 'td') +
  20497. '</table>'
  20498. )
  20499. }
  20500. me.fireEvent('contentchange')
  20501. me.fireEvent('saveScene')
  20502. html.html = ''
  20503. return true
  20504. } else {
  20505. var div = me.document.createElement('div'),
  20506. tables
  20507. div.innerHTML = html.html
  20508. tables = div.getElementsByTagName('table')
  20509. if (domUtils.findParentByTagName(me.selection.getStart(), 'table')) {
  20510. utils.each(tables, function (t) {
  20511. domUtils.remove(t)
  20512. })
  20513. if (domUtils.findParentByTagName(me.selection.getStart(), 'caption', true)) {
  20514. div.innerHTML = div[browser.ie ? 'innerText' : 'textContent']
  20515. }
  20516. } else {
  20517. utils.each(tables, function (table) {
  20518. removeStyleSize(table, true)
  20519. domUtils.removeAttributes(table, ['style', 'border'])
  20520. utils.each(domUtils.getElementsByTagName(table, 'td'), function (td) {
  20521. if (isEmptyBlock(td)) {
  20522. domUtils.fillNode(me.document, td)
  20523. }
  20524. removeStyleSize(td, true)
  20525. // domUtils.removeAttributes(td, ['style'])
  20526. })
  20527. })
  20528. }
  20529. html.html = div.innerHTML
  20530. }
  20531. })
  20532. me.addListener('afterpaste', function () {
  20533. utils.each(domUtils.getElementsByTagName(me.body, 'table'), function (table) {
  20534. if (table.offsetWidth > me.body.offsetWidth) {
  20535. var defaultValue = getDefaultValue(me, table)
  20536. table.style.width =
  20537. me.body.offsetWidth -
  20538. (needIEHack
  20539. ? parseInt(domUtils.getComputedStyle(me.body, 'margin-left'), 10) * 2
  20540. : 0) -
  20541. defaultValue.tableBorder * 2 -
  20542. (me.options.offsetWidth || 0) +
  20543. 'px'
  20544. }
  20545. })
  20546. })
  20547. me.addListener('blur', function () {
  20548. tableCopyList = null
  20549. })
  20550. var timer
  20551. me.addListener('keydown', function () {
  20552. clearTimeout(timer)
  20553. timer = setTimeout(function () {
  20554. var rng = me.selection.getRange(),
  20555. cell = domUtils.findParentByTagName(rng.startContainer, ['th', 'td'], true)
  20556. if (cell) {
  20557. var table = cell.parentNode.parentNode.parentNode
  20558. if (table.offsetWidth > table.getAttribute('width')) {
  20559. cell.style.wordBreak = 'break-all'
  20560. }
  20561. }
  20562. }, 100)
  20563. })
  20564. me.addListener('selectionchange', function () {
  20565. toggleDraggableState(me, false, '', null)
  20566. })
  20567. //内容变化时触发索引更新
  20568. //todo 可否考虑标记检测,如果不涉及表格的变化就不进行索引重建和更新
  20569. me.addListener('contentchange', function () {
  20570. var me = this
  20571. //尽可能排除一些不需要更新的状况
  20572. hideDragLine(me)
  20573. if (getUETableBySelected(me)) return
  20574. var rng = me.selection.getRange()
  20575. var start = rng.startContainer
  20576. start = domUtils.findParentByTagName(start, ['td', 'th'], true)
  20577. utils.each(domUtils.getElementsByTagName(me.document, 'table'), function (table) {
  20578. if (me.fireEvent('excludetable', table) === true) return
  20579. table.ueTable = new UT(table)
  20580. //trace:3742
  20581. // utils.each(domUtils.getElementsByTagName(me.document, 'td'), function (td) {
  20582. //
  20583. // if (domUtils.isEmptyBlock(td) && td !== start) {
  20584. // domUtils.fillNode(me.document, td);
  20585. // if (browser.ie && browser.version == 6) {
  20586. // td.innerHTML = '&nbsp;'
  20587. // }
  20588. // }
  20589. // });
  20590. // utils.each(domUtils.getElementsByTagName(me.document, 'th'), function (th) {
  20591. // if (domUtils.isEmptyBlock(th) && th !== start) {
  20592. // domUtils.fillNode(me.document, th);
  20593. // if (browser.ie && browser.version == 6) {
  20594. // th.innerHTML = '&nbsp;'
  20595. // }
  20596. // }
  20597. // });
  20598. table.onmouseover = function () {
  20599. me.fireEvent('tablemouseover', table)
  20600. }
  20601. table.onmousemove = function () {
  20602. me.fireEvent('tablemousemove', table)
  20603. me.options.tableDragable && toggleDragButton(true, this, me)
  20604. utils.defer(function () {
  20605. me.fireEvent('contentchange', 50)
  20606. }, true)
  20607. }
  20608. table.onmouseout = function () {
  20609. me.fireEvent('tablemouseout', table)
  20610. toggleDraggableState(me, false, '', null)
  20611. hideDragLine(me)
  20612. }
  20613. table.onclick = function (evt) {
  20614. evt = me.window.event || evt
  20615. var target = getParentTdOrTh(evt.target || evt.srcElement)
  20616. if (!target) return
  20617. var ut = getUETable(target),
  20618. table = ut.table,
  20619. cellInfo = ut.getCellInfo(target),
  20620. cellsRange,
  20621. rng = me.selection.getRange()
  20622. // if ("topLeft" == inPosition(table, mouseCoords(evt))) {
  20623. // cellsRange = ut.getCellsRange(ut.table.rows[0].cells[0], ut.getLastCell());
  20624. // ut.setSelected(cellsRange);
  20625. // return;
  20626. // }
  20627. // if ("bottomRight" == inPosition(table, mouseCoords(evt))) {
  20628. //
  20629. // return;
  20630. // }
  20631. if (inTableSide(table, target, evt, true)) {
  20632. var endTdCol = ut.getCell(
  20633. ut.indexTable[ut.rowsNum - 1][cellInfo.colIndex].rowIndex,
  20634. ut.indexTable[ut.rowsNum - 1][cellInfo.colIndex].cellIndex
  20635. )
  20636. if (evt.shiftKey && ut.selectedTds.length) {
  20637. if (ut.selectedTds[0] !== endTdCol) {
  20638. cellsRange = ut.getCellsRange(ut.selectedTds[0], endTdCol)
  20639. ut.setSelected(cellsRange)
  20640. } else {
  20641. rng && rng.selectNodeContents(endTdCol).select()
  20642. }
  20643. } else {
  20644. if (target !== endTdCol) {
  20645. cellsRange = ut.getCellsRange(target, endTdCol)
  20646. ut.setSelected(cellsRange)
  20647. } else {
  20648. rng && rng.selectNodeContents(endTdCol).select()
  20649. }
  20650. }
  20651. return
  20652. }
  20653. if (inTableSide(table, target, evt)) {
  20654. var endTdRow = ut.getCell(
  20655. ut.indexTable[cellInfo.rowIndex][ut.colsNum - 1].rowIndex,
  20656. ut.indexTable[cellInfo.rowIndex][ut.colsNum - 1].cellIndex
  20657. )
  20658. if (evt.shiftKey && ut.selectedTds.length) {
  20659. if (ut.selectedTds[0] !== endTdRow) {
  20660. cellsRange = ut.getCellsRange(ut.selectedTds[0], endTdRow)
  20661. ut.setSelected(cellsRange)
  20662. } else {
  20663. rng && rng.selectNodeContents(endTdRow).select()
  20664. }
  20665. } else {
  20666. if (target !== endTdRow) {
  20667. cellsRange = ut.getCellsRange(target, endTdRow)
  20668. ut.setSelected(cellsRange)
  20669. } else {
  20670. rng && rng.selectNodeContents(endTdRow).select()
  20671. }
  20672. }
  20673. }
  20674. }
  20675. })
  20676. switchBorderColor(me, true)
  20677. })
  20678. domUtils.on(me.document, 'mousemove', mouseMoveEvent)
  20679. domUtils.on(me.document, 'mouseout', function (evt) {
  20680. var target = evt.target || evt.srcElement
  20681. if (target.tagName == 'TABLE') {
  20682. toggleDraggableState(me, false, '', null)
  20683. }
  20684. })
  20685. /**
  20686. * 表格隔行变色
  20687. */
  20688. me.addListener('interlacetable', function (type, table, classList) {
  20689. if (!table) return
  20690. var me = this,
  20691. rows = table.rows,
  20692. len = rows.length,
  20693. getClass = function (list, index, repeat) {
  20694. return list[index] ? list[index] : repeat ? list[index % list.length] : ''
  20695. }
  20696. for (var i = 0; i < len; i++) {
  20697. rows[i].className = getClass(classList || me.options.classList, i, true)
  20698. }
  20699. })
  20700. me.addListener('uninterlacetable', function (type, table) {
  20701. if (!table) return
  20702. var me = this,
  20703. rows = table.rows,
  20704. classList = me.options.classList,
  20705. len = rows.length
  20706. for (var i = 0; i < len; i++) {
  20707. domUtils.removeClasses(rows[i], classList)
  20708. }
  20709. })
  20710. me.addListener('mousedown', mouseDownEvent)
  20711. me.addListener('mouseup', mouseUpEvent)
  20712. //拖动的时候触发mouseup
  20713. domUtils.on(me.body, 'dragstart', function (evt) {
  20714. mouseUpEvent.call(me, 'dragstart', evt)
  20715. })
  20716. me.addOutputRule(function (root) {
  20717. utils.each(root.getNodesByTagName('div'), function (n) {
  20718. if (n.getAttr('id') == 'ue_tableDragLine') {
  20719. n.parentNode.removeChild(n)
  20720. }
  20721. })
  20722. })
  20723. var currentRowIndex = 0
  20724. me.addListener('mousedown', function () {
  20725. currentRowIndex = 0
  20726. })
  20727. me.addListener('tabkeydown', function () {
  20728. var range = this.selection.getRange(),
  20729. common = range.getCommonAncestor(true, true),
  20730. table = domUtils.findParentByTagName(common, 'table')
  20731. if (table) {
  20732. if (domUtils.findParentByTagName(common, 'caption', true)) {
  20733. var cell = domUtils.getElementsByTagName(table, 'th td')
  20734. if (cell && cell.length) {
  20735. range.setStart(cell[0], 0).setCursor(false, true)
  20736. }
  20737. } else {
  20738. var cell = domUtils.findParentByTagName(common, ['td', 'th'], true),
  20739. ua = getUETable(cell)
  20740. currentRowIndex = cell.rowSpan > 1 ? currentRowIndex : ua.getCellInfo(cell).rowIndex
  20741. var nextCell = ua.getTabNextCell(cell, currentRowIndex)
  20742. if (nextCell) {
  20743. if (isEmptyBlock(nextCell)) {
  20744. range.setStart(nextCell, 0).setCursor(false, true)
  20745. } else {
  20746. range.selectNodeContents(nextCell).select()
  20747. }
  20748. } else {
  20749. me.fireEvent('saveScene')
  20750. me.__hasEnterExecCommand = true
  20751. this.execCommand('insertrownext')
  20752. me.__hasEnterExecCommand = false
  20753. range = this.selection.getRange()
  20754. range.setStart(table.rows[table.rows.length - 1].cells[0], 0).setCursor()
  20755. me.fireEvent('saveScene')
  20756. }
  20757. }
  20758. return true
  20759. }
  20760. })
  20761. browser.ie &&
  20762. me.addListener('selectionchange', function () {
  20763. toggleDraggableState(this, false, '', null)
  20764. })
  20765. me.addListener('keydown', function (type, evt) {
  20766. var me = this
  20767. //处理在表格的最后一个输入tab产生新的表格
  20768. var keyCode = evt.keyCode || evt.which
  20769. if (keyCode == 8 || keyCode == 46) {
  20770. return
  20771. }
  20772. var notCtrlKey = !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey
  20773. notCtrlKey && removeSelectedClass(domUtils.getElementsByTagName(me.body, 'td'))
  20774. var ut = getUETableBySelected(me)
  20775. if (!ut) return
  20776. notCtrlKey && ut.clearSelected()
  20777. })
  20778. me.addListener('beforegetcontent', function () {
  20779. switchBorderColor(this, false)
  20780. browser.ie &&
  20781. utils.each(this.document.getElementsByTagName('caption'), function (ci) {
  20782. if (domUtils.isEmptyNode(ci)) {
  20783. ci.innerHTML = '&nbsp;'
  20784. }
  20785. })
  20786. })
  20787. me.addListener('aftergetcontent', function () {
  20788. switchBorderColor(this, true)
  20789. })
  20790. me.addListener('getAllHtml', function () {
  20791. removeSelectedClass(me.document.getElementsByTagName('td'))
  20792. })
  20793. //修正全屏状态下插入的表格宽度在非全屏状态下撑开编辑器的情况
  20794. me.addListener('fullscreenchanged', function (type, fullscreen) {
  20795. if (!fullscreen) {
  20796. var ratio = this.body.offsetWidth / document.body.offsetWidth,
  20797. tables = domUtils.getElementsByTagName(this.body, 'table')
  20798. utils.each(tables, function (table) {
  20799. if (table.offsetWidth < me.body.offsetWidth) return false
  20800. var tds = domUtils.getElementsByTagName(table, 'td'),
  20801. backWidths = []
  20802. utils.each(tds, function (td) {
  20803. backWidths.push(td.offsetWidth)
  20804. })
  20805. for (var i = 0, td; (td = tds[i]); i++) {
  20806. td.setAttribute('width', Math.floor(backWidths[i] * ratio))
  20807. }
  20808. table.setAttribute(
  20809. 'width',
  20810. Math.floor(getTableWidth(me, needIEHack, getDefaultValue(me)))
  20811. )
  20812. })
  20813. }
  20814. })
  20815. //重写execCommand命令,用于处理框选时的处理
  20816. var oldExecCommand = me.execCommand
  20817. me.execCommand = function (cmd, datatat) {
  20818. var me = this,
  20819. args = arguments
  20820. cmd = cmd.toLowerCase()
  20821. var ut = getUETableBySelected(me),
  20822. tds,
  20823. range = new dom.Range(me.document),
  20824. cmdFun = me.commands[cmd] || UE.commands[cmd],
  20825. result
  20826. if (!cmdFun) return
  20827. if (ut && !commands[cmd] && !cmdFun.notNeedUndo && !me.__hasEnterExecCommand) {
  20828. me.__hasEnterExecCommand = true
  20829. me.fireEvent('beforeexeccommand', cmd)
  20830. tds = ut.selectedTds
  20831. var lastState = -2,
  20832. lastValue = -2,
  20833. value,
  20834. state
  20835. for (var i = 0, td; (td = tds[i]); i++) {
  20836. if (isEmptyBlock(td)) {
  20837. range.setStart(td, 0).setCursor(false, true)
  20838. } else {
  20839. range.selectNode(td).select(true)
  20840. }
  20841. state = me.queryCommandState(cmd)
  20842. value = me.queryCommandValue(cmd)
  20843. if (state != -1) {
  20844. if (lastState !== state || lastValue !== value) {
  20845. me._ignoreContentChange = true
  20846. result = oldExecCommand.apply(me, arguments)
  20847. me._ignoreContentChange = false
  20848. }
  20849. lastState = me.queryCommandState(cmd)
  20850. lastValue = me.queryCommandValue(cmd)
  20851. if (domUtils.isEmptyBlock(td)) {
  20852. domUtils.fillNode(me.document, td)
  20853. }
  20854. }
  20855. }
  20856. range.setStart(tds[0], 0).shrinkBoundary(true).setCursor(false, true)
  20857. me.fireEvent('contentchange')
  20858. me.fireEvent('afterexeccommand', cmd)
  20859. me.__hasEnterExecCommand = false
  20860. me._selectionChange()
  20861. } else {
  20862. result = oldExecCommand.apply(me, arguments)
  20863. }
  20864. return result
  20865. }
  20866. })
  20867. /**
  20868. * 删除obj的宽高style,改成属性宽高
  20869. * @param obj
  20870. * @param replaceToProperty
  20871. */
  20872. function removeStyleSize(obj, replaceToProperty) {
  20873. removeStyle(obj, 'width', true)
  20874. removeStyle(obj, 'height', true)
  20875. }
  20876. function removeStyle(obj, styleName, replaceToProperty) {
  20877. if (obj.style[styleName]) {
  20878. replaceToProperty && obj.setAttribute(styleName, parseInt(obj.style[styleName], 10))
  20879. obj.style[styleName] = ''
  20880. }
  20881. }
  20882. function getParentTdOrTh(ele) {
  20883. if (ele.tagName == 'TD' || ele.tagName == 'TH') return ele
  20884. var td
  20885. if (
  20886. (td =
  20887. domUtils.findParentByTagName(ele, 'td', true) ||
  20888. domUtils.findParentByTagName(ele, 'th', true))
  20889. )
  20890. return td
  20891. return null
  20892. }
  20893. function isEmptyBlock(node) {
  20894. var reg = new RegExp(domUtils.fillChar, 'g')
  20895. if (
  20896. node[browser.ie ? 'innerText' : 'textContent'].replace(/^\s*$/, '').replace(reg, '')
  20897. .length > 0
  20898. ) {
  20899. return 0
  20900. }
  20901. for (var n in dtd.$isNotEmpty) {
  20902. if (node.getElementsByTagName(n).length) {
  20903. return 0
  20904. }
  20905. }
  20906. return 1
  20907. }
  20908. function mouseCoords(evt) {
  20909. if (evt.pageX || evt.pageY) {
  20910. return { x: evt.pageX, y: evt.pageY }
  20911. }
  20912. return {
  20913. x: evt.clientX + me.document.body.scrollLeft - me.document.body.clientLeft,
  20914. y: evt.clientY + me.document.body.scrollTop - me.document.body.clientTop
  20915. }
  20916. }
  20917. function mouseMoveEvent(evt) {
  20918. if (isEditorDisabled()) {
  20919. return
  20920. }
  20921. try {
  20922. //普通状态下鼠标移动
  20923. var target = getParentTdOrTh(evt.target || evt.srcElement),
  20924. pos
  20925. //区分用户的行为是拖动还是双击
  20926. if (isInResizeBuffer) {
  20927. me.body.style.webkitUserSelect = 'none'
  20928. if (
  20929. Math.abs(userActionStatus.x - evt.clientX) > offsetOfTableCell ||
  20930. Math.abs(userActionStatus.y - evt.clientY) > offsetOfTableCell
  20931. ) {
  20932. clearTableDragTimer()
  20933. isInResizeBuffer = false
  20934. singleClickState = 0
  20935. //drag action
  20936. tableBorderDrag(evt)
  20937. }
  20938. }
  20939. //修改单元格大小时的鼠标移动
  20940. if (onDrag && dragTd) {
  20941. singleClickState = 0
  20942. me.body.style.webkitUserSelect = 'none'
  20943. me.selection.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']()
  20944. pos = mouseCoords(evt)
  20945. toggleDraggableState(me, true, onDrag, pos, target)
  20946. if (onDrag == 'h') {
  20947. dragLine.style.left = getPermissionX(dragTd, evt) + 'px'
  20948. } else if (onDrag == 'v') {
  20949. dragLine.style.top = getPermissionY(dragTd, evt) + 'px'
  20950. }
  20951. return
  20952. }
  20953. //当鼠标处于table上时,修改移动过程中的光标状态
  20954. if (target) {
  20955. //针对使用table作为容器的组件不触发拖拽效果
  20956. if (me.fireEvent('excludetable', target) === true) return
  20957. pos = mouseCoords(evt)
  20958. var state = getRelation(target, pos),
  20959. table = domUtils.findParentByTagName(target, 'table', true)
  20960. if (inTableSide(table, target, evt, true)) {
  20961. if (me.fireEvent('excludetable', table) === true) return
  20962. me.body.style.cursor = 'url(' + me.options.cursorpath + 'h.png),pointer'
  20963. } else if (inTableSide(table, target, evt)) {
  20964. if (me.fireEvent('excludetable', table) === true) return
  20965. me.body.style.cursor = 'url(' + me.options.cursorpath + 'v.png),pointer'
  20966. } else {
  20967. me.body.style.cursor = 'text'
  20968. var curCell = target
  20969. if (/\d/.test(state)) {
  20970. state = state.replace(/\d/, '')
  20971. target = getUETable(target).getPreviewCell(target, state == 'v')
  20972. }
  20973. //位于第一行的顶部或者第一列的左边时不可拖动
  20974. toggleDraggableState(me, target ? !!state : false, target ? state : '', pos, target)
  20975. }
  20976. } else {
  20977. toggleDragButton(false, table, me)
  20978. }
  20979. } catch (e) {
  20980. showError(e)
  20981. }
  20982. }
  20983. var dragButtonTimer
  20984. function toggleDragButton(show, table, editor) {
  20985. if (!show) {
  20986. if (dragOver) return
  20987. dragButtonTimer = setTimeout(function () {
  20988. !dragOver &&
  20989. dragButton &&
  20990. dragButton.parentNode &&
  20991. dragButton.parentNode.removeChild(dragButton)
  20992. }, 2000)
  20993. } else {
  20994. createDragButton(table, editor)
  20995. }
  20996. }
  20997. function createDragButton(table, editor) {
  20998. var pos = domUtils.getXY(table),
  20999. doc = table.ownerDocument
  21000. if (dragButton && dragButton.parentNode) return dragButton
  21001. dragButton = doc.createElement('div')
  21002. dragButton.contentEditable = false
  21003. dragButton.innerHTML = ''
  21004. dragButton.style.cssText =
  21005. 'width:15px;height:15px;background-image:url(' +
  21006. editor.options.UEDITOR_HOME_URL +
  21007. 'dialogs/table/dragicon.png);position: absolute;cursor:move;top:' +
  21008. (pos.y - 15) +
  21009. 'px;left:' +
  21010. pos.x +
  21011. 'px;'
  21012. domUtils.unSelectable(dragButton)
  21013. dragButton.onmouseover = function (evt) {
  21014. dragOver = true
  21015. }
  21016. dragButton.onmouseout = function (evt) {
  21017. dragOver = false
  21018. }
  21019. domUtils.on(dragButton, 'click', function (type, evt) {
  21020. doClick(evt, this)
  21021. })
  21022. domUtils.on(dragButton, 'dblclick', function (type, evt) {
  21023. doDblClick(evt)
  21024. })
  21025. domUtils.on(dragButton, 'dragstart', function (type, evt) {
  21026. domUtils.preventDefault(evt)
  21027. })
  21028. var timer
  21029. function doClick(evt, button) {
  21030. // 部分浏览器下需要清理
  21031. clearTimeout(timer)
  21032. timer = setTimeout(function () {
  21033. editor.fireEvent('tableClicked', table, button)
  21034. }, 300)
  21035. }
  21036. function doDblClick(evt) {
  21037. clearTimeout(timer)
  21038. var ut = getUETable(table),
  21039. start = table.rows[0].cells[0],
  21040. end = ut.getLastCell(),
  21041. range = ut.getCellsRange(start, end)
  21042. editor.selection.getRange().setStart(start, 0).setCursor(false, true)
  21043. ut.setSelected(range)
  21044. }
  21045. doc.body.appendChild(dragButton)
  21046. }
  21047. // function inPosition(table, pos) {
  21048. // var tablePos = domUtils.getXY(table),
  21049. // width = table.offsetWidth,
  21050. // height = table.offsetHeight;
  21051. // if (pos.x - tablePos.x < 5 && pos.y - tablePos.y < 5) {
  21052. // return "topLeft";
  21053. // } else if (tablePos.x + width - pos.x < 5 && tablePos.y + height - pos.y < 5) {
  21054. // return "bottomRight";
  21055. // }
  21056. // }
  21057. function inTableSide(table, cell, evt, top) {
  21058. var pos = mouseCoords(evt),
  21059. state = getRelation(cell, pos)
  21060. if (top) {
  21061. var caption = table.getElementsByTagName('caption')[0],
  21062. capHeight = caption ? caption.offsetHeight : 0
  21063. return state == 'v1' && pos.y - domUtils.getXY(table).y - capHeight < 8
  21064. } else {
  21065. return state == 'h1' && pos.x - domUtils.getXY(table).x < 8
  21066. }
  21067. }
  21068. /**
  21069. * 获取拖动时允许的X轴坐标
  21070. * @param dragTd
  21071. * @param evt
  21072. */
  21073. function getPermissionX(dragTd, evt) {
  21074. var ut = getUETable(dragTd)
  21075. if (ut) {
  21076. var preTd = ut.getSameEndPosCells(dragTd, 'x')[0],
  21077. nextTd = ut.getSameStartPosXCells(dragTd)[0],
  21078. mouseX = mouseCoords(evt).x,
  21079. left = (preTd ? domUtils.getXY(preTd).x : domUtils.getXY(ut.table).x) + 20,
  21080. right = nextTd
  21081. ? domUtils.getXY(nextTd).x + nextTd.offsetWidth - 20
  21082. : me.body.offsetWidth + 5 || parseInt(domUtils.getComputedStyle(me.body, 'width'), 10)
  21083. left += cellMinWidth
  21084. right -= cellMinWidth
  21085. return mouseX < left ? left : mouseX > right ? right : mouseX
  21086. }
  21087. }
  21088. /**
  21089. * 获取拖动时允许的Y轴坐标
  21090. */
  21091. function getPermissionY(dragTd, evt) {
  21092. try {
  21093. var top = domUtils.getXY(dragTd).y,
  21094. mousePosY = mouseCoords(evt).y
  21095. return mousePosY < top ? top : mousePosY
  21096. } catch (e) {
  21097. showError(e)
  21098. }
  21099. }
  21100. /**
  21101. * 移动状态切换
  21102. */
  21103. function toggleDraggableState(editor, draggable, dir, mousePos, cell) {
  21104. try {
  21105. editor.body.style.cursor = dir == 'h' ? 'col-resize' : dir == 'v' ? 'row-resize' : 'text'
  21106. if (browser.ie) {
  21107. if (dir && !mousedown && !getUETableBySelected(editor)) {
  21108. getDragLine(editor, editor.document)
  21109. showDragLineAt(dir, cell)
  21110. } else {
  21111. hideDragLine(editor)
  21112. }
  21113. }
  21114. onBorder = draggable
  21115. } catch (e) {
  21116. showError(e)
  21117. }
  21118. }
  21119. /**
  21120. * 获取与UETable相关的resize line
  21121. * @param uetable UETable对象
  21122. */
  21123. function getResizeLineByUETable() {
  21124. var lineId = '_UETableResizeLine',
  21125. line = this.document.getElementById(lineId)
  21126. if (!line) {
  21127. line = this.document.createElement('div')
  21128. line.id = lineId
  21129. line.contnetEditable = false
  21130. line.setAttribute('unselectable', 'on')
  21131. var styles = {
  21132. width: 2 * cellBorderWidth + 1 + 'px',
  21133. position: 'absolute',
  21134. 'z-index': 100000,
  21135. cursor: 'col-resize',
  21136. background: 'red',
  21137. display: 'none'
  21138. }
  21139. //切换状态
  21140. line.onmouseout = function () {
  21141. this.style.display = 'none'
  21142. }
  21143. utils.extend(line.style, styles)
  21144. this.document.body.appendChild(line)
  21145. }
  21146. return line
  21147. }
  21148. /**
  21149. * 更新resize-line
  21150. */
  21151. function updateResizeLine(cell, uetable) {
  21152. var line = getResizeLineByUETable.call(this),
  21153. table = uetable.table,
  21154. styles = {
  21155. top: domUtils.getXY(table).y + 'px',
  21156. left: domUtils.getXY(cell).x + cell.offsetWidth - cellBorderWidth + 'px',
  21157. display: 'block',
  21158. height: table.offsetHeight + 'px'
  21159. }
  21160. utils.extend(line.style, styles)
  21161. }
  21162. /**
  21163. * 显示resize-line
  21164. */
  21165. function showResizeLine(cell) {
  21166. var uetable = getUETable(cell)
  21167. updateResizeLine.call(this, cell, uetable)
  21168. }
  21169. /**
  21170. * 获取鼠标与当前单元格的相对位置
  21171. * @param ele
  21172. * @param mousePos
  21173. */
  21174. function getRelation(ele, mousePos) {
  21175. var elePos = domUtils.getXY(ele)
  21176. if (!elePos) {
  21177. return ''
  21178. }
  21179. if (elePos.x + ele.offsetWidth - mousePos.x < cellBorderWidth) {
  21180. return 'h'
  21181. }
  21182. if (mousePos.x - elePos.x < cellBorderWidth) {
  21183. return 'h1'
  21184. }
  21185. if (elePos.y + ele.offsetHeight - mousePos.y < cellBorderWidth) {
  21186. return 'v'
  21187. }
  21188. if (mousePos.y - elePos.y < cellBorderWidth) {
  21189. return 'v1'
  21190. }
  21191. return ''
  21192. }
  21193. function mouseDownEvent(type, evt) {
  21194. if (isEditorDisabled()) {
  21195. return
  21196. }
  21197. userActionStatus = {
  21198. x: evt.clientX,
  21199. y: evt.clientY
  21200. }
  21201. //右键菜单单独处理
  21202. if (evt.button == 2) {
  21203. var ut = getUETableBySelected(me),
  21204. flag = false
  21205. if (ut) {
  21206. var td = getTargetTd(me, evt)
  21207. utils.each(ut.selectedTds, function (ti) {
  21208. if (ti === td) {
  21209. flag = true
  21210. }
  21211. })
  21212. if (!flag) {
  21213. removeSelectedClass(domUtils.getElementsByTagName(me.body, 'th td'))
  21214. ut.clearSelected()
  21215. } else {
  21216. td = ut.selectedTds[0]
  21217. setTimeout(function () {
  21218. me.selection.getRange().setStart(td, 0).setCursor(false, true)
  21219. }, 0)
  21220. }
  21221. }
  21222. } else {
  21223. tableClickHander(evt)
  21224. }
  21225. }
  21226. //清除表格的计时器
  21227. function clearTableTimer() {
  21228. tabTimer && clearTimeout(tabTimer)
  21229. tabTimer = null
  21230. }
  21231. //双击收缩
  21232. function tableDbclickHandler(evt) {
  21233. singleClickState = 0
  21234. evt = evt || me.window.event
  21235. var target = getParentTdOrTh(evt.target || evt.srcElement)
  21236. if (target) {
  21237. var h
  21238. if ((h = getRelation(target, mouseCoords(evt)))) {
  21239. hideDragLine(me)
  21240. if (h == 'h1') {
  21241. h = 'h'
  21242. if (inTableSide(domUtils.findParentByTagName(target, 'table'), target, evt)) {
  21243. me.execCommand('adaptbywindow')
  21244. } else {
  21245. target = getUETable(target).getPreviewCell(target)
  21246. if (target) {
  21247. var rng = me.selection.getRange()
  21248. rng.selectNodeContents(target).setCursor(true, true)
  21249. }
  21250. }
  21251. }
  21252. if (h == 'h') {
  21253. var ut = getUETable(target),
  21254. table = ut.table,
  21255. cells = getCellsByMoveBorder(target, table, true)
  21256. cells = extractArray(cells, 'left')
  21257. ut.width = ut.offsetWidth
  21258. var oldWidth = [],
  21259. newWidth = []
  21260. utils.each(cells, function (cell) {
  21261. oldWidth.push(cell.offsetWidth)
  21262. })
  21263. utils.each(cells, function (cell) {
  21264. cell.removeAttribute('width')
  21265. })
  21266. window.setTimeout(function () {
  21267. //是否允许改变
  21268. var changeable = true
  21269. utils.each(cells, function (cell, index) {
  21270. var width = cell.offsetWidth
  21271. if (width > oldWidth[index]) {
  21272. changeable = false
  21273. return false
  21274. }
  21275. newWidth.push(width)
  21276. })
  21277. var change = changeable ? newWidth : oldWidth
  21278. utils.each(cells, function (cell, index) {
  21279. cell.width = change[index] - getTabcellSpace()
  21280. })
  21281. }, 0)
  21282. // minWidth -= cellMinWidth;
  21283. //
  21284. // table.removeAttribute("width");
  21285. // utils.each(cells, function (cell) {
  21286. // cell.style.width = "";
  21287. // cell.width -= minWidth;
  21288. // });
  21289. }
  21290. }
  21291. }
  21292. }
  21293. function tableClickHander(evt) {
  21294. removeSelectedClass(domUtils.getElementsByTagName(me.body, 'td th'))
  21295. //trace:3113
  21296. //选中单元格,点击table外部,不会清掉table上挂的ueTable,会引起getUETableBySelected方法返回值
  21297. utils.each(me.document.getElementsByTagName('table'), function (t) {
  21298. t.ueTable = null
  21299. })
  21300. startTd = getTargetTd(me, evt)
  21301. if (!startTd) return
  21302. var table = domUtils.findParentByTagName(startTd, 'table', true)
  21303. ut = getUETable(table)
  21304. ut && ut.clearSelected()
  21305. //判断当前鼠标状态
  21306. if (!onBorder) {
  21307. me.document.body.style.webkitUserSelect = ''
  21308. mousedown = true
  21309. me.addListener('mouseover', mouseOverEvent)
  21310. } else {
  21311. //边框上的动作处理
  21312. borderActionHandler(evt)
  21313. }
  21314. }
  21315. //处理表格边框上的动作, 这里做延时处理,避免两种动作互相影响
  21316. function borderActionHandler(evt) {
  21317. if (browser.ie) {
  21318. evt = reconstruct(evt)
  21319. }
  21320. clearTableDragTimer()
  21321. //是否正在等待resize的缓冲中
  21322. isInResizeBuffer = true
  21323. tableDragTimer = setTimeout(function () {
  21324. tableBorderDrag(evt)
  21325. }, dblclickTime)
  21326. }
  21327. function extractArray(originArr, key) {
  21328. var result = [],
  21329. tmp = null
  21330. for (var i = 0, len = originArr.length; i < len; i++) {
  21331. tmp = originArr[i][key]
  21332. if (tmp) {
  21333. result.push(tmp)
  21334. }
  21335. }
  21336. return result
  21337. }
  21338. function clearTableDragTimer() {
  21339. tableDragTimer && clearTimeout(tableDragTimer)
  21340. tableDragTimer = null
  21341. }
  21342. function reconstruct(obj) {
  21343. var attrs = ['pageX', 'pageY', 'clientX', 'clientY', 'srcElement', 'target'],
  21344. newObj = {}
  21345. if (obj) {
  21346. for (var i = 0, key, val; (key = attrs[i]); i++) {
  21347. val = obj[key]
  21348. val && (newObj[key] = val)
  21349. }
  21350. }
  21351. return newObj
  21352. }
  21353. //边框拖动
  21354. function tableBorderDrag(evt) {
  21355. isInResizeBuffer = false
  21356. startTd = evt.target || evt.srcElement
  21357. if (!startTd) return
  21358. var state = getRelation(startTd, mouseCoords(evt))
  21359. if (/\d/.test(state)) {
  21360. state = state.replace(/\d/, '')
  21361. startTd = getUETable(startTd).getPreviewCell(startTd, state == 'v')
  21362. }
  21363. hideDragLine(me)
  21364. getDragLine(me, me.document)
  21365. me.fireEvent('saveScene')
  21366. showDragLineAt(state, startTd)
  21367. mousedown = true
  21368. //拖动开始
  21369. onDrag = state
  21370. dragTd = startTd
  21371. }
  21372. function mouseUpEvent(type, evt) {
  21373. if (isEditorDisabled()) {
  21374. return
  21375. }
  21376. clearTableDragTimer()
  21377. isInResizeBuffer = false
  21378. if (onBorder) {
  21379. singleClickState = ++singleClickState % 3
  21380. userActionStatus = {
  21381. x: evt.clientX,
  21382. y: evt.clientY
  21383. }
  21384. tableResizeTimer = setTimeout(function () {
  21385. singleClickState > 0 && singleClickState--
  21386. }, dblclickTime)
  21387. if (singleClickState === 2) {
  21388. singleClickState = 0
  21389. tableDbclickHandler(evt)
  21390. return
  21391. }
  21392. }
  21393. if (evt.button == 2) return
  21394. var me = this
  21395. //清除表格上原生跨选问题
  21396. var range = me.selection.getRange(),
  21397. start = domUtils.findParentByTagName(range.startContainer, 'table', true),
  21398. end = domUtils.findParentByTagName(range.endContainer, 'table', true)
  21399. if (start || end) {
  21400. if (start === end) {
  21401. start = domUtils.findParentByTagName(range.startContainer, ['td', 'th', 'caption'], true)
  21402. end = domUtils.findParentByTagName(range.endContainer, ['td', 'th', 'caption'], true)
  21403. if (start !== end) {
  21404. me.selection.clearRange()
  21405. }
  21406. } else {
  21407. me.selection.clearRange()
  21408. }
  21409. }
  21410. mousedown = false
  21411. me.document.body.style.webkitUserSelect = ''
  21412. //拖拽状态下的mouseUP
  21413. if (onDrag && dragTd) {
  21414. me.selection.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']()
  21415. singleClickState = 0
  21416. dragLine = me.document.getElementById('ue_tableDragLine')
  21417. // trace 3973
  21418. if (dragLine) {
  21419. var dragTdPos = domUtils.getXY(dragTd),
  21420. dragLinePos = domUtils.getXY(dragLine)
  21421. switch (onDrag) {
  21422. case 'h':
  21423. changeColWidth(dragTd, dragLinePos.x - dragTdPos.x)
  21424. break
  21425. case 'v':
  21426. changeRowHeight(dragTd, dragLinePos.y - dragTdPos.y - dragTd.offsetHeight)
  21427. break
  21428. default:
  21429. }
  21430. onDrag = ''
  21431. dragTd = null
  21432. hideDragLine(me)
  21433. me.fireEvent('saveScene')
  21434. return
  21435. }
  21436. }
  21437. //正常状态下的mouseup
  21438. if (!startTd) {
  21439. var target = domUtils.findParentByTagName(evt.target || evt.srcElement, 'td', true)
  21440. if (!target) target = domUtils.findParentByTagName(evt.target || evt.srcElement, 'th', true)
  21441. if (target && (target.tagName == 'TD' || target.tagName == 'TH')) {
  21442. if (me.fireEvent('excludetable', target) === true) return
  21443. range = new dom.Range(me.document)
  21444. range.setStart(target, 0).setCursor(false, true)
  21445. }
  21446. } else {
  21447. var ut = getUETable(startTd),
  21448. cell = ut ? ut.selectedTds[0] : null
  21449. if (cell) {
  21450. range = new dom.Range(me.document)
  21451. if (domUtils.isEmptyBlock(cell)) {
  21452. range.setStart(cell, 0).setCursor(false, true)
  21453. } else {
  21454. range.selectNodeContents(cell).shrinkBoundary().setCursor(false, true)
  21455. }
  21456. } else {
  21457. range = me.selection.getRange().shrinkBoundary()
  21458. if (!range.collapsed) {
  21459. var start = domUtils.findParentByTagName(range.startContainer, ['td', 'th'], true),
  21460. end = domUtils.findParentByTagName(range.endContainer, ['td', 'th'], true)
  21461. //在table里边的不能清除
  21462. if ((start && !end) || (!start && end) || (start && end && start !== end)) {
  21463. range.setCursor(false, true)
  21464. }
  21465. }
  21466. }
  21467. startTd = null
  21468. me.removeListener('mouseover', mouseOverEvent)
  21469. }
  21470. me._selectionChange(250, evt)
  21471. }
  21472. function mouseOverEvent(type, evt) {
  21473. if (isEditorDisabled()) {
  21474. return
  21475. }
  21476. var me = this,
  21477. tar = evt.target || evt.srcElement
  21478. currentTd =
  21479. domUtils.findParentByTagName(tar, 'td', true) ||
  21480. domUtils.findParentByTagName(tar, 'th', true)
  21481. //需要判断两个TD是否位于同一个表格内
  21482. if (
  21483. startTd &&
  21484. currentTd &&
  21485. ((startTd.tagName == 'TD' && currentTd.tagName == 'TD') ||
  21486. (startTd.tagName == 'TH' && currentTd.tagName == 'TH')) &&
  21487. domUtils.findParentByTagName(startTd, 'table') ==
  21488. domUtils.findParentByTagName(currentTd, 'table')
  21489. ) {
  21490. var ut = getUETable(currentTd)
  21491. if (startTd != currentTd) {
  21492. me.document.body.style.webkitUserSelect = 'none'
  21493. me.selection.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']()
  21494. var range = ut.getCellsRange(startTd, currentTd)
  21495. ut.setSelected(range)
  21496. } else {
  21497. me.document.body.style.webkitUserSelect = ''
  21498. ut.clearSelected()
  21499. }
  21500. }
  21501. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false)
  21502. }
  21503. function setCellHeight(cell, height, backHeight) {
  21504. var lineHight = parseInt(domUtils.getComputedStyle(cell, 'line-height'), 10),
  21505. tmpHeight = backHeight + height
  21506. height = tmpHeight < lineHight ? lineHight : tmpHeight
  21507. if (cell.style.height) cell.style.height = ''
  21508. cell.rowSpan == 1
  21509. ? cell.setAttribute('height', height)
  21510. : cell.removeAttribute && cell.removeAttribute('height')
  21511. }
  21512. function getWidth(cell) {
  21513. if (!cell) return 0
  21514. return parseInt(domUtils.getComputedStyle(cell, 'width'), 10)
  21515. }
  21516. function changeColWidth(cell, changeValue) {
  21517. var ut = getUETable(cell)
  21518. if (ut) {
  21519. //根据当前移动的边框获取相关的单元格
  21520. var table = ut.table,
  21521. cells = getCellsByMoveBorder(cell, table)
  21522. table.style.width = ''
  21523. table.removeAttribute('width')
  21524. //修正改变量
  21525. changeValue = correctChangeValue(changeValue, cell, cells)
  21526. if (cell.nextSibling) {
  21527. var i = 0
  21528. utils.each(cells, function (cellGroup) {
  21529. cellGroup.left.width = +cellGroup.left.width + changeValue
  21530. cellGroup.right && (cellGroup.right.width = +cellGroup.right.width - changeValue)
  21531. })
  21532. } else {
  21533. utils.each(cells, function (cellGroup) {
  21534. cellGroup.left.width -= -changeValue
  21535. })
  21536. }
  21537. }
  21538. }
  21539. function isEditorDisabled() {
  21540. return me.body.contentEditable === 'false'
  21541. }
  21542. function changeRowHeight(td, changeValue) {
  21543. if (Math.abs(changeValue) < 10) return
  21544. var ut = getUETable(td)
  21545. if (ut) {
  21546. var cells = ut.getSameEndPosCells(td, 'y'),
  21547. //备份需要连带变化的td的原始高度,否则后期无法获取正确的值
  21548. backHeight = cells[0] ? cells[0].offsetHeight : 0
  21549. for (var i = 0, cell; (cell = cells[i++]); ) {
  21550. setCellHeight(cell, changeValue, backHeight)
  21551. }
  21552. }
  21553. }
  21554. /**
  21555. * 获取调整单元格大小的相关单元格
  21556. * @isContainMergeCell 返回的结果中是否包含发生合并后的单元格
  21557. */
  21558. function getCellsByMoveBorder(cell, table, isContainMergeCell) {
  21559. if (!table) {
  21560. table = domUtils.findParentByTagName(cell, 'table')
  21561. }
  21562. if (!table) {
  21563. return null
  21564. }
  21565. //获取到该单元格所在行的序列号
  21566. var index = domUtils.getNodeIndex(cell),
  21567. temp = cell,
  21568. rows = table.rows,
  21569. colIndex = 0
  21570. while (temp) {
  21571. //获取到当前单元格在未发生单元格合并时的序列
  21572. if (temp.nodeType === 1) {
  21573. colIndex += temp.colSpan || 1
  21574. }
  21575. temp = temp.previousSibling
  21576. }
  21577. temp = null
  21578. //记录想关的单元格
  21579. var borderCells = []
  21580. utils.each(rows, function (tabRow) {
  21581. var cells = tabRow.cells,
  21582. currIndex = 0
  21583. utils.each(cells, function (tabCell) {
  21584. currIndex += tabCell.colSpan || 1
  21585. if (currIndex === colIndex) {
  21586. borderCells.push({
  21587. left: tabCell,
  21588. right: tabCell.nextSibling || null
  21589. })
  21590. return false
  21591. } else if (currIndex > colIndex) {
  21592. if (isContainMergeCell) {
  21593. borderCells.push({
  21594. left: tabCell
  21595. })
  21596. }
  21597. return false
  21598. }
  21599. })
  21600. })
  21601. return borderCells
  21602. }
  21603. /**
  21604. * 通过给定的单元格集合获取最小的单元格width
  21605. */
  21606. function getMinWidthByTableCells(cells) {
  21607. var minWidth = Number.MAX_VALUE
  21608. for (var i = 0, curCell; (curCell = cells[i]); i++) {
  21609. minWidth = Math.min(minWidth, curCell.width || getTableCellWidth(curCell))
  21610. }
  21611. return minWidth
  21612. }
  21613. function correctChangeValue(changeValue, relatedCell, cells) {
  21614. //为单元格的paading预留空间
  21615. changeValue -= getTabcellSpace()
  21616. if (changeValue < 0) {
  21617. return 0
  21618. }
  21619. changeValue -= getTableCellWidth(relatedCell)
  21620. //确定方向
  21621. var direction = changeValue < 0 ? 'left' : 'right'
  21622. changeValue = Math.abs(changeValue)
  21623. //只关心非最后一个单元格就可以
  21624. utils.each(cells, function (cellGroup) {
  21625. var curCell = cellGroup[direction]
  21626. //为单元格保留最小空间
  21627. if (curCell) {
  21628. changeValue = Math.min(changeValue, getTableCellWidth(curCell) - cellMinWidth)
  21629. }
  21630. })
  21631. //修正越界
  21632. changeValue = changeValue < 0 ? 0 : changeValue
  21633. return direction === 'left' ? -changeValue : changeValue
  21634. }
  21635. function getTableCellWidth(cell) {
  21636. var width = 0,
  21637. //偏移纠正量
  21638. offset = 0,
  21639. width = cell.offsetWidth - getTabcellSpace()
  21640. //最后一个节点纠正一下
  21641. if (!cell.nextSibling) {
  21642. width -= getTableCellOffset(cell)
  21643. }
  21644. width = width < 0 ? 0 : width
  21645. try {
  21646. cell.width = width
  21647. } catch (e) {}
  21648. return width
  21649. }
  21650. /**
  21651. * 获取单元格所在表格的最末单元格的偏移量
  21652. */
  21653. function getTableCellOffset(cell) {
  21654. tab = domUtils.findParentByTagName(cell, 'table', false)
  21655. if (tab.offsetVal === undefined) {
  21656. var prev = cell.previousSibling
  21657. if (prev) {
  21658. //最后一个单元格和前一个单元格的width diff结果 如果恰好为一个border width, 则条件成立
  21659. tab.offsetVal =
  21660. cell.offsetWidth - prev.offsetWidth === UT.borderWidth ? UT.borderWidth : 0
  21661. } else {
  21662. tab.offsetVal = 0
  21663. }
  21664. }
  21665. return tab.offsetVal
  21666. }
  21667. function getTabcellSpace() {
  21668. if (UT.tabcellSpace === undefined) {
  21669. var cell = null,
  21670. tab = me.document.createElement('table'),
  21671. tbody = me.document.createElement('tbody'),
  21672. trow = me.document.createElement('tr'),
  21673. tabcell = me.document.createElement('td'),
  21674. mirror = null
  21675. tabcell.style.cssText = 'border: 0;'
  21676. tabcell.width = 1
  21677. trow.appendChild(tabcell)
  21678. trow.appendChild((mirror = tabcell.cloneNode(false)))
  21679. tbody.appendChild(trow)
  21680. tab.appendChild(tbody)
  21681. tab.style.cssText = 'visibility: hidden;'
  21682. me.body.appendChild(tab)
  21683. UT.paddingSpace = tabcell.offsetWidth - 1
  21684. var tmpTabWidth = tab.offsetWidth
  21685. tabcell.style.cssText = ''
  21686. mirror.style.cssText = ''
  21687. UT.borderWidth = (tab.offsetWidth - tmpTabWidth) / 3
  21688. UT.tabcellSpace = UT.paddingSpace + UT.borderWidth
  21689. me.body.removeChild(tab)
  21690. }
  21691. getTabcellSpace = function () {
  21692. return UT.tabcellSpace
  21693. }
  21694. return UT.tabcellSpace
  21695. }
  21696. function getDragLine(editor, doc) {
  21697. if (mousedown) return
  21698. dragLine = editor.document.createElement('div')
  21699. domUtils.setAttributes(dragLine, {
  21700. id: 'ue_tableDragLine',
  21701. unselectable: 'on',
  21702. contenteditable: false,
  21703. onresizestart: 'return false',
  21704. ondragstart: 'return false',
  21705. onselectstart: 'return false',
  21706. style:
  21707. 'background-color:blue;position:absolute;padding:0;margin:0;background-image:none;border:0px none;opacity:0;filter:alpha(opacity=0)'
  21708. })
  21709. editor.body.appendChild(dragLine)
  21710. }
  21711. function hideDragLine(editor) {
  21712. if (mousedown) return
  21713. var line
  21714. while ((line = editor.document.getElementById('ue_tableDragLine'))) {
  21715. domUtils.remove(line)
  21716. }
  21717. }
  21718. /**
  21719. * 依据state(v|h)在cell位置显示横线
  21720. * @param state
  21721. * @param cell
  21722. */
  21723. function showDragLineAt(state, cell) {
  21724. if (!cell) return
  21725. var table = domUtils.findParentByTagName(cell, 'table'),
  21726. caption = table.getElementsByTagName('caption'),
  21727. width = table.offsetWidth,
  21728. height = table.offsetHeight - (caption.length > 0 ? caption[0].offsetHeight : 0),
  21729. tablePos = domUtils.getXY(table),
  21730. cellPos = domUtils.getXY(cell),
  21731. css
  21732. switch (state) {
  21733. case 'h':
  21734. css =
  21735. 'height:' +
  21736. height +
  21737. 'px;top:' +
  21738. (tablePos.y + (caption.length > 0 ? caption[0].offsetHeight : 0)) +
  21739. 'px;left:' +
  21740. (cellPos.x + cell.offsetWidth)
  21741. dragLine.style.cssText =
  21742. css +
  21743. 'px;position: absolute;display:block;background-color:blue;width:1px;border:0; color:blue;opacity:.3;filter:alpha(opacity=30)'
  21744. break
  21745. case 'v':
  21746. css =
  21747. 'width:' + width + 'px;left:' + tablePos.x + 'px;top:' + (cellPos.y + cell.offsetHeight)
  21748. //必须加上border:0和color:blue,否则低版ie不支持背景色显示
  21749. dragLine.style.cssText =
  21750. css +
  21751. 'px;overflow:hidden;position: absolute;display:block;background-color:blue;height:1px;border:0;color:blue;opacity:.2;filter:alpha(opacity=20)'
  21752. break
  21753. default:
  21754. }
  21755. }
  21756. /**
  21757. * 当表格边框颜色为白色时设置为虚线,true为添加虚线
  21758. * @param editor
  21759. * @param flag
  21760. */
  21761. function switchBorderColor(editor, flag) {
  21762. var tableArr = domUtils.getElementsByTagName(editor.body, 'table'),
  21763. color
  21764. for (var i = 0, node; (node = tableArr[i++]); ) {
  21765. var td = domUtils.getElementsByTagName(node, 'td')
  21766. if (td[0]) {
  21767. if (flag) {
  21768. color = td[0].style.borderColor.replace(/\s/g, '')
  21769. if (/(#ffffff)|(rgb\(255,255,255\))/gi.test(color))
  21770. domUtils.addClass(node, 'noBorderTable')
  21771. } else {
  21772. domUtils.removeClasses(node, 'noBorderTable')
  21773. }
  21774. }
  21775. }
  21776. }
  21777. function getTableWidth(editor, needIEHack, defaultValue) {
  21778. var body = editor.body
  21779. return (
  21780. body.offsetWidth -
  21781. (needIEHack ? parseInt(domUtils.getComputedStyle(body, 'margin-left'), 10) * 2 : 0) -
  21782. defaultValue.tableBorder * 2 -
  21783. (editor.options.offsetWidth || 0)
  21784. )
  21785. }
  21786. /**
  21787. * 获取当前拖动的单元格
  21788. */
  21789. function getTargetTd(editor, evt) {
  21790. var target = domUtils.findParentByTagName(evt.target || evt.srcElement, ['td', 'th'], true),
  21791. dir = null
  21792. if (!target) {
  21793. return null
  21794. }
  21795. dir = getRelation(target, mouseCoords(evt))
  21796. //如果有前一个节点, 需要做一个修正, 否则可能会得到一个错误的td
  21797. if (!target) {
  21798. return null
  21799. }
  21800. if (dir === 'h1' && target.previousSibling) {
  21801. var position = domUtils.getXY(target),
  21802. cellWidth = target.offsetWidth
  21803. if (Math.abs(position.x + cellWidth - evt.clientX) > cellWidth / 3) {
  21804. target = target.previousSibling
  21805. }
  21806. } else if (dir === 'v1' && target.parentNode.previousSibling) {
  21807. var position = domUtils.getXY(target),
  21808. cellHeight = target.offsetHeight
  21809. if (Math.abs(position.y + cellHeight - evt.clientY) > cellHeight / 3) {
  21810. target = target.parentNode.previousSibling.firstChild
  21811. }
  21812. }
  21813. //排除了非td内部以及用于代码高亮部分的td
  21814. return target && !(editor.fireEvent('excludetable', target) === true) ? target : null
  21815. }
  21816. }
  21817. // plugins/table.sort.js
  21818. /**
  21819. * Created with JetBrains PhpStorm.
  21820. * User: Jinqn
  21821. * Date: 13-10-12
  21822. * Time: 上午10:20
  21823. * To change this template use File | Settings | File Templates.
  21824. */
  21825. UE.UETable.prototype.sortTable = function (sortByCellIndex, compareFn) {
  21826. var table = this.table,
  21827. rows = table.rows,
  21828. trArray = [],
  21829. flag = rows[0].cells[0].tagName === 'TH',
  21830. lastRowIndex = 0
  21831. if (this.selectedTds.length) {
  21832. var range = this.cellsRange,
  21833. len = range.endRowIndex + 1
  21834. for (var i = range.beginRowIndex; i < len; i++) {
  21835. trArray[i] = rows[i]
  21836. }
  21837. trArray.splice(0, range.beginRowIndex)
  21838. lastRowIndex = range.endRowIndex + 1 === this.rowsNum ? 0 : range.endRowIndex + 1
  21839. } else {
  21840. for (var i = 0, len = rows.length; i < len; i++) {
  21841. trArray[i] = rows[i]
  21842. }
  21843. }
  21844. var Fn = {
  21845. reversecurrent: function (td1, td2) {
  21846. return 1
  21847. },
  21848. orderbyasc: function (td1, td2) {
  21849. var value1 = td1.innerText || td1.textContent,
  21850. value2 = td2.innerText || td2.textContent
  21851. return value1.localeCompare(value2)
  21852. },
  21853. reversebyasc: function (td1, td2) {
  21854. var value1 = td1.innerHTML,
  21855. value2 = td2.innerHTML
  21856. return value2.localeCompare(value1)
  21857. },
  21858. orderbynum: function (td1, td2) {
  21859. var value1 = td1[browser.ie ? 'innerText' : 'textContent'].match(/\d+/),
  21860. value2 = td2[browser.ie ? 'innerText' : 'textContent'].match(/\d+/)
  21861. if (value1) value1 = +value1[0]
  21862. if (value2) value2 = +value2[0]
  21863. return (value1 || 0) - (value2 || 0)
  21864. },
  21865. reversebynum: function (td1, td2) {
  21866. var value1 = td1[browser.ie ? 'innerText' : 'textContent'].match(/\d+/),
  21867. value2 = td2[browser.ie ? 'innerText' : 'textContent'].match(/\d+/)
  21868. if (value1) value1 = +value1[0]
  21869. if (value2) value2 = +value2[0]
  21870. return (value2 || 0) - (value1 || 0)
  21871. }
  21872. }
  21873. //对表格设置排序的标记data-sort-type
  21874. table.setAttribute(
  21875. 'data-sort-type',
  21876. compareFn && typeof compareFn === 'string' && Fn[compareFn] ? compareFn : ''
  21877. )
  21878. //th不参与排序
  21879. flag && trArray.splice(0, 1)
  21880. trArray = utils.sort(trArray, function (tr1, tr2) {
  21881. var result
  21882. if (compareFn && typeof compareFn === 'function') {
  21883. result = compareFn.call(this, tr1.cells[sortByCellIndex], tr2.cells[sortByCellIndex])
  21884. } else if (compareFn && typeof compareFn === 'number') {
  21885. result = 1
  21886. } else if (compareFn && typeof compareFn === 'string' && Fn[compareFn]) {
  21887. result = Fn[compareFn].call(this, tr1.cells[sortByCellIndex], tr2.cells[sortByCellIndex])
  21888. } else {
  21889. result = Fn['orderbyasc'].call(this, tr1.cells[sortByCellIndex], tr2.cells[sortByCellIndex])
  21890. }
  21891. return result
  21892. })
  21893. var fragment = table.ownerDocument.createDocumentFragment()
  21894. for (var j = 0, len = trArray.length; j < len; j++) {
  21895. fragment.appendChild(trArray[j])
  21896. }
  21897. var tbody = table.getElementsByTagName('tbody')[0]
  21898. if (!lastRowIndex) {
  21899. tbody.appendChild(fragment)
  21900. } else {
  21901. tbody.insertBefore(fragment, rows[lastRowIndex - range.endRowIndex + range.beginRowIndex - 1])
  21902. }
  21903. }
  21904. UE.plugins['tablesort'] = function () {
  21905. var me = this,
  21906. UT = UE.UETable,
  21907. getUETable = function (tdOrTable) {
  21908. return UT.getUETable(tdOrTable)
  21909. },
  21910. getTableItemsByRange = function (editor) {
  21911. return UT.getTableItemsByRange(editor)
  21912. }
  21913. me.ready(function () {
  21914. //添加表格可排序的样式
  21915. utils.cssRule(
  21916. 'tablesort',
  21917. 'table.sortEnabled tr.firstRow th,table.sortEnabled tr.firstRow td{padding-right:20px;background-repeat: no-repeat;background-position: center right;' +
  21918. ' background-image:url(' +
  21919. me.options.themePath +
  21920. me.options.theme +
  21921. '/images/sortable.png);}',
  21922. me.document
  21923. )
  21924. //做单元格合并操作时,清除可排序标识
  21925. me.addListener('afterexeccommand', function (type, cmd) {
  21926. if (cmd == 'mergeright' || cmd == 'mergedown' || cmd == 'mergecells') {
  21927. this.execCommand('disablesort')
  21928. }
  21929. })
  21930. })
  21931. //表格排序
  21932. UE.commands['sorttable'] = {
  21933. queryCommandState: function () {
  21934. var me = this,
  21935. tableItems = getTableItemsByRange(me)
  21936. if (!tableItems.cell) return -1
  21937. var table = tableItems.table,
  21938. cells = table.getElementsByTagName('td')
  21939. for (var i = 0, cell; (cell = cells[i++]); ) {
  21940. if (cell.rowSpan != 1 || cell.colSpan != 1) return -1
  21941. }
  21942. return 0
  21943. },
  21944. execCommand: function (cmd, fn) {
  21945. var me = this,
  21946. range = me.selection.getRange(),
  21947. bk = range.createBookmark(true),
  21948. tableItems = getTableItemsByRange(me),
  21949. cell = tableItems.cell,
  21950. ut = getUETable(tableItems.table),
  21951. cellInfo = ut.getCellInfo(cell)
  21952. ut.sortTable(cellInfo.cellIndex, fn)
  21953. range.moveToBookmark(bk)
  21954. try {
  21955. range.select()
  21956. } catch (e) {}
  21957. }
  21958. }
  21959. //设置表格可排序,清除表格可排序
  21960. UE.commands['enablesort'] = UE.commands['disablesort'] = {
  21961. queryCommandState: function (cmd) {
  21962. var table = getTableItemsByRange(this).table
  21963. if (table && cmd == 'enablesort') {
  21964. var cells = domUtils.getElementsByTagName(table, 'th td')
  21965. for (var i = 0; i < cells.length; i++) {
  21966. if (cells[i].getAttribute('colspan') > 1 || cells[i].getAttribute('rowspan') > 1)
  21967. return -1
  21968. }
  21969. }
  21970. return !table
  21971. ? -1
  21972. : (cmd == 'enablesort') ^ (table.getAttribute('data-sort') != 'sortEnabled')
  21973. ? -1
  21974. : 0
  21975. },
  21976. execCommand: function (cmd) {
  21977. var table = getTableItemsByRange(this).table
  21978. table.setAttribute('data-sort', cmd == 'enablesort' ? 'sortEnabled' : 'sortDisabled')
  21979. cmd == 'enablesort'
  21980. ? domUtils.addClass(table, 'sortEnabled')
  21981. : domUtils.removeClasses(table, 'sortEnabled')
  21982. }
  21983. }
  21984. }
  21985. // plugins/contextmenu.js
  21986. ///import core
  21987. ///commands 右键菜单
  21988. ///commandsName ContextMenu
  21989. ///commandsTitle 右键菜单
  21990. /**
  21991. * 右键菜单
  21992. * @function
  21993. * @name baidu.editor.plugins.contextmenu
  21994. * @author zhanyi
  21995. */
  21996. UE.plugins['contextmenu'] = function () {
  21997. var me = this
  21998. me.setOpt('enableContextMenu', true)
  21999. if (me.getOpt('enableContextMenu') === false) {
  22000. return
  22001. }
  22002. var lang = me.getLang('contextMenu'),
  22003. menu,
  22004. items = me.options.contextMenu || [
  22005. { label: lang['selectall'], cmdName: 'selectall' },
  22006. {
  22007. label: lang.cleardoc,
  22008. cmdName: 'cleardoc',
  22009. exec: function () {
  22010. if (confirm(lang.confirmclear)) {
  22011. this.execCommand('cleardoc')
  22012. }
  22013. }
  22014. },
  22015. '-',
  22016. {
  22017. label: lang.unlink,
  22018. cmdName: 'unlink'
  22019. },
  22020. '-',
  22021. {
  22022. group: lang.paragraph,
  22023. icon: 'justifyjustify',
  22024. subMenu: [
  22025. {
  22026. label: lang.justifyleft,
  22027. cmdName: 'justify',
  22028. value: 'left'
  22029. },
  22030. {
  22031. label: lang.justifyright,
  22032. cmdName: 'justify',
  22033. value: 'right'
  22034. },
  22035. {
  22036. label: lang.justifycenter,
  22037. cmdName: 'justify',
  22038. value: 'center'
  22039. },
  22040. {
  22041. label: lang.justifyjustify,
  22042. cmdName: 'justify',
  22043. value: 'justify'
  22044. }
  22045. ]
  22046. },
  22047. '-',
  22048. {
  22049. group: lang.table,
  22050. icon: 'table',
  22051. subMenu: [
  22052. {
  22053. label: lang.inserttable,
  22054. cmdName: 'inserttable'
  22055. },
  22056. {
  22057. label: lang.deletetable,
  22058. cmdName: 'deletetable'
  22059. },
  22060. '-',
  22061. {
  22062. label: lang.deleterow,
  22063. cmdName: 'deleterow'
  22064. },
  22065. {
  22066. label: lang.deletecol,
  22067. cmdName: 'deletecol'
  22068. },
  22069. {
  22070. label: lang.insertcol,
  22071. cmdName: 'insertcol'
  22072. },
  22073. {
  22074. label: lang.insertcolnext,
  22075. cmdName: 'insertcolnext'
  22076. },
  22077. {
  22078. label: lang.insertrow,
  22079. cmdName: 'insertrow'
  22080. },
  22081. {
  22082. label: lang.insertrownext,
  22083. cmdName: 'insertrownext'
  22084. },
  22085. '-',
  22086. {
  22087. label: lang.insertcaption,
  22088. cmdName: 'insertcaption'
  22089. },
  22090. {
  22091. label: lang.deletecaption,
  22092. cmdName: 'deletecaption'
  22093. },
  22094. {
  22095. label: lang.inserttitle,
  22096. cmdName: 'inserttitle'
  22097. },
  22098. {
  22099. label: lang.deletetitle,
  22100. cmdName: 'deletetitle'
  22101. },
  22102. {
  22103. label: lang.inserttitlecol,
  22104. cmdName: 'inserttitlecol'
  22105. },
  22106. {
  22107. label: lang.deletetitlecol,
  22108. cmdName: 'deletetitlecol'
  22109. },
  22110. '-',
  22111. {
  22112. label: lang.mergecells,
  22113. cmdName: 'mergecells'
  22114. },
  22115. {
  22116. label: lang.mergeright,
  22117. cmdName: 'mergeright'
  22118. },
  22119. {
  22120. label: lang.mergedown,
  22121. cmdName: 'mergedown'
  22122. },
  22123. '-',
  22124. {
  22125. label: lang.splittorows,
  22126. cmdName: 'splittorows'
  22127. },
  22128. {
  22129. label: lang.splittocols,
  22130. cmdName: 'splittocols'
  22131. },
  22132. {
  22133. label: lang.splittocells,
  22134. cmdName: 'splittocells'
  22135. },
  22136. '-',
  22137. {
  22138. label: lang.averageDiseRow,
  22139. cmdName: 'averagedistributerow'
  22140. },
  22141. {
  22142. label: lang.averageDisCol,
  22143. cmdName: 'averagedistributecol'
  22144. },
  22145. '-',
  22146. {
  22147. label: lang.edittd,
  22148. cmdName: 'edittd',
  22149. exec: function () {
  22150. if (UE.ui['edittd']) {
  22151. new UE.ui['edittd'](this)
  22152. }
  22153. this.getDialog('edittd').open()
  22154. }
  22155. },
  22156. {
  22157. label: lang.edittable,
  22158. cmdName: 'edittable',
  22159. exec: function () {
  22160. if (UE.ui['edittable']) {
  22161. new UE.ui['edittable'](this)
  22162. }
  22163. this.getDialog('edittable').open()
  22164. }
  22165. },
  22166. {
  22167. label: lang.setbordervisible,
  22168. cmdName: 'setbordervisible'
  22169. }
  22170. ]
  22171. },
  22172. {
  22173. group: lang.tablesort,
  22174. icon: 'tablesort',
  22175. subMenu: [
  22176. {
  22177. label: lang.enablesort,
  22178. cmdName: 'enablesort'
  22179. },
  22180. {
  22181. label: lang.disablesort,
  22182. cmdName: 'disablesort'
  22183. },
  22184. '-',
  22185. {
  22186. label: lang.reversecurrent,
  22187. cmdName: 'sorttable',
  22188. value: 'reversecurrent'
  22189. },
  22190. {
  22191. label: lang.orderbyasc,
  22192. cmdName: 'sorttable',
  22193. value: 'orderbyasc'
  22194. },
  22195. {
  22196. label: lang.reversebyasc,
  22197. cmdName: 'sorttable',
  22198. value: 'reversebyasc'
  22199. },
  22200. {
  22201. label: lang.orderbynum,
  22202. cmdName: 'sorttable',
  22203. value: 'orderbynum'
  22204. },
  22205. {
  22206. label: lang.reversebynum,
  22207. cmdName: 'sorttable',
  22208. value: 'reversebynum'
  22209. }
  22210. ]
  22211. },
  22212. {
  22213. group: lang.borderbk,
  22214. icon: 'borderBack',
  22215. subMenu: [
  22216. {
  22217. label: lang.setcolor,
  22218. cmdName: 'interlacetable',
  22219. exec: function () {
  22220. this.execCommand('interlacetable')
  22221. }
  22222. },
  22223. {
  22224. label: lang.unsetcolor,
  22225. cmdName: 'uninterlacetable',
  22226. exec: function () {
  22227. this.execCommand('uninterlacetable')
  22228. }
  22229. },
  22230. {
  22231. label: lang.setbackground,
  22232. cmdName: 'settablebackground',
  22233. exec: function () {
  22234. this.execCommand('settablebackground', {
  22235. repeat: true,
  22236. colorList: ['#bbb', '#ccc']
  22237. })
  22238. }
  22239. },
  22240. {
  22241. label: lang.unsetbackground,
  22242. cmdName: 'cleartablebackground',
  22243. exec: function () {
  22244. this.execCommand('cleartablebackground')
  22245. }
  22246. },
  22247. {
  22248. label: lang.redandblue,
  22249. cmdName: 'settablebackground',
  22250. exec: function () {
  22251. this.execCommand('settablebackground', {
  22252. repeat: true,
  22253. colorList: ['red', 'blue']
  22254. })
  22255. }
  22256. },
  22257. {
  22258. label: lang.threecolorgradient,
  22259. cmdName: 'settablebackground',
  22260. exec: function () {
  22261. this.execCommand('settablebackground', {
  22262. repeat: true,
  22263. colorList: ['#aaa', '#bbb', '#ccc']
  22264. })
  22265. }
  22266. }
  22267. ]
  22268. },
  22269. {
  22270. group: lang.aligntd,
  22271. icon: 'aligntd',
  22272. subMenu: [
  22273. {
  22274. cmdName: 'cellalignment',
  22275. value: { align: 'left', vAlign: 'top' }
  22276. },
  22277. {
  22278. cmdName: 'cellalignment',
  22279. value: { align: 'center', vAlign: 'top' }
  22280. },
  22281. {
  22282. cmdName: 'cellalignment',
  22283. value: { align: 'right', vAlign: 'top' }
  22284. },
  22285. {
  22286. cmdName: 'cellalignment',
  22287. value: { align: 'left', vAlign: 'middle' }
  22288. },
  22289. {
  22290. cmdName: 'cellalignment',
  22291. value: { align: 'center', vAlign: 'middle' }
  22292. },
  22293. {
  22294. cmdName: 'cellalignment',
  22295. value: { align: 'right', vAlign: 'middle' }
  22296. },
  22297. {
  22298. cmdName: 'cellalignment',
  22299. value: { align: 'left', vAlign: 'bottom' }
  22300. },
  22301. {
  22302. cmdName: 'cellalignment',
  22303. value: { align: 'center', vAlign: 'bottom' }
  22304. },
  22305. {
  22306. cmdName: 'cellalignment',
  22307. value: { align: 'right', vAlign: 'bottom' }
  22308. }
  22309. ]
  22310. },
  22311. {
  22312. group: lang.aligntable,
  22313. icon: 'aligntable',
  22314. subMenu: [
  22315. {
  22316. cmdName: 'tablealignment',
  22317. className: 'left',
  22318. label: lang.tableleft,
  22319. value: 'left'
  22320. },
  22321. {
  22322. cmdName: 'tablealignment',
  22323. className: 'center',
  22324. label: lang.tablecenter,
  22325. value: 'center'
  22326. },
  22327. {
  22328. cmdName: 'tablealignment',
  22329. className: 'right',
  22330. label: lang.tableright,
  22331. value: 'right'
  22332. }
  22333. ]
  22334. },
  22335. '-',
  22336. {
  22337. label: lang.insertparagraphbefore,
  22338. cmdName: 'insertparagraph',
  22339. value: true
  22340. },
  22341. {
  22342. label: lang.insertparagraphafter,
  22343. cmdName: 'insertparagraph'
  22344. },
  22345. {
  22346. label: lang['copy'],
  22347. cmdName: 'copy'
  22348. },
  22349. {
  22350. label: lang['paste'],
  22351. cmdName: 'paste'
  22352. }
  22353. ]
  22354. if (!items.length) {
  22355. return
  22356. }
  22357. var uiUtils = UE.ui.uiUtils
  22358. me.addListener('contextmenu', function (type, evt) {
  22359. var offset = uiUtils.getViewportOffsetByEvent(evt)
  22360. me.fireEvent('beforeselectionchange')
  22361. if (menu) {
  22362. menu.destroy()
  22363. }
  22364. for (var i = 0, ti, contextItems = []; (ti = items[i]); i++) {
  22365. var last
  22366. ;(function (item) {
  22367. if (item == '-') {
  22368. if ((last = contextItems[contextItems.length - 1]) && last !== '-') {
  22369. contextItems.push('-')
  22370. }
  22371. } else if (item.hasOwnProperty('group')) {
  22372. for (var j = 0, cj, subMenu = []; (cj = item.subMenu[j]); j++) {
  22373. ;(function (subItem) {
  22374. if (subItem == '-') {
  22375. if ((last = subMenu[subMenu.length - 1]) && last !== '-') {
  22376. subMenu.push('-')
  22377. } else {
  22378. subMenu.splice(subMenu.length - 1)
  22379. }
  22380. } else {
  22381. if (
  22382. (me.commands[subItem.cmdName] ||
  22383. UE.commands[subItem.cmdName] ||
  22384. subItem.query) &&
  22385. (subItem.query ? subItem.query() : me.queryCommandState(subItem.cmdName)) > -1
  22386. ) {
  22387. subMenu.push({
  22388. label:
  22389. subItem.label ||
  22390. me.getLang('contextMenu.' + subItem.cmdName + (subItem.value || '')) ||
  22391. '',
  22392. className:
  22393. 'edui-for-' +
  22394. subItem.cmdName +
  22395. (subItem.className
  22396. ? ' edui-for-' + subItem.cmdName + '-' + subItem.className
  22397. : ''),
  22398. onclick: subItem.exec
  22399. ? function () {
  22400. subItem.exec.call(me)
  22401. }
  22402. : function () {
  22403. me.execCommand(subItem.cmdName, subItem.value)
  22404. }
  22405. })
  22406. }
  22407. }
  22408. })(cj)
  22409. }
  22410. if (subMenu.length) {
  22411. function getLabel() {
  22412. switch (item.icon) {
  22413. case 'table':
  22414. return me.getLang('contextMenu.table')
  22415. case 'justifyjustify':
  22416. return me.getLang('contextMenu.paragraph')
  22417. case 'aligntd':
  22418. return me.getLang('contextMenu.aligntd')
  22419. case 'aligntable':
  22420. return me.getLang('contextMenu.aligntable')
  22421. case 'tablesort':
  22422. return lang.tablesort
  22423. case 'borderBack':
  22424. return lang.borderbk
  22425. default:
  22426. return ''
  22427. }
  22428. }
  22429. contextItems.push({
  22430. //todo 修正成自动获取方式
  22431. label: getLabel(),
  22432. className: 'edui-for-' + item.icon,
  22433. subMenu: {
  22434. items: subMenu,
  22435. editor: me
  22436. }
  22437. })
  22438. }
  22439. } else {
  22440. //有可能commmand没有加载右键不能出来,或者没有command也想能展示出来添加query方法
  22441. if (
  22442. (me.commands[item.cmdName] || UE.commands[item.cmdName] || item.query) &&
  22443. (item.query ? item.query.call(me) : me.queryCommandState(item.cmdName)) > -1
  22444. ) {
  22445. contextItems.push({
  22446. label: item.label || me.getLang('contextMenu.' + item.cmdName),
  22447. className:
  22448. 'edui-for-' + (item.icon ? item.icon : item.cmdName + (item.value || '')),
  22449. onclick: item.exec
  22450. ? function () {
  22451. item.exec.call(me)
  22452. }
  22453. : function () {
  22454. me.execCommand(item.cmdName, item.value)
  22455. }
  22456. })
  22457. }
  22458. }
  22459. })(ti)
  22460. }
  22461. if (contextItems[contextItems.length - 1] == '-') {
  22462. contextItems.pop()
  22463. }
  22464. menu = new UE.ui.Menu({
  22465. items: contextItems,
  22466. className: 'edui-contextmenu',
  22467. editor: me
  22468. })
  22469. menu.render()
  22470. menu.showAt(offset)
  22471. me.fireEvent('aftershowcontextmenu', menu)
  22472. domUtils.preventDefault(evt)
  22473. if (browser.ie) {
  22474. var ieRange
  22475. try {
  22476. ieRange = me.selection.getNative().createRange()
  22477. } catch (e) {
  22478. return
  22479. }
  22480. if (ieRange.item) {
  22481. var range = new dom.Range(me.document)
  22482. range.selectNode(ieRange.item(0)).select(true, true)
  22483. }
  22484. }
  22485. })
  22486. // 添加复制的flash按钮
  22487. me.addListener('aftershowcontextmenu', function (type, menu) {
  22488. if (me.zeroclipboard) {
  22489. var items = menu.items
  22490. for (var key in items) {
  22491. if (items[key].className == 'edui-for-copy') {
  22492. me.zeroclipboard.clip(items[key].getDom())
  22493. }
  22494. }
  22495. }
  22496. })
  22497. }
  22498. // plugins/shortcutmenu.js
  22499. ///import core
  22500. ///commands 弹出菜单
  22501. // commandsName popupmenu
  22502. ///commandsTitle 弹出菜单
  22503. /**
  22504. * 弹出菜单
  22505. * @function
  22506. * @name baidu.editor.plugins.popupmenu
  22507. * @author xuheng
  22508. */
  22509. UE.plugins['shortcutmenu'] = function () {
  22510. var me = this,
  22511. menu,
  22512. items = me.options.shortcutMenu || []
  22513. if (!items.length) {
  22514. return
  22515. }
  22516. me.addListener('contextmenu mouseup', function (type, e) {
  22517. var me = this,
  22518. customEvt = {
  22519. type: type,
  22520. target: e.target || e.srcElement,
  22521. screenX: e.screenX,
  22522. screenY: e.screenY,
  22523. clientX: e.clientX,
  22524. clientY: e.clientY
  22525. }
  22526. setTimeout(function () {
  22527. var rng = me.selection.getRange()
  22528. if (rng.collapsed === false || type == 'contextmenu') {
  22529. if (!menu) {
  22530. menu = new baidu.editor.ui.ShortCutMenu({
  22531. editor: me,
  22532. items: items,
  22533. theme: me.options.theme,
  22534. className: 'edui-shortcutmenu'
  22535. })
  22536. menu.render()
  22537. me.fireEvent('afterrendershortcutmenu', menu)
  22538. }
  22539. menu.show(customEvt, !!UE.plugins['contextmenu'])
  22540. }
  22541. })
  22542. if (type == 'contextmenu') {
  22543. domUtils.preventDefault(e)
  22544. if (browser.ie9below) {
  22545. var ieRange
  22546. try {
  22547. ieRange = me.selection.getNative().createRange()
  22548. } catch (e) {
  22549. return
  22550. }
  22551. if (ieRange.item) {
  22552. var range = new dom.Range(me.document)
  22553. range.selectNode(ieRange.item(0)).select(true, true)
  22554. }
  22555. }
  22556. }
  22557. })
  22558. me.addListener('keydown', function (type) {
  22559. if (type == 'keydown') {
  22560. menu && !menu.isHidden && menu.hide()
  22561. }
  22562. })
  22563. }
  22564. // plugins/basestyle.js
  22565. /**
  22566. * B、I、sub、super命令支持
  22567. * @file
  22568. * @since 1.2.6.1
  22569. */
  22570. UE.plugins['basestyle'] = function () {
  22571. /**
  22572. * 字体加粗
  22573. * @command bold
  22574. * @param { String } cmd 命令字符串
  22575. * @remind 对已加粗的文本内容执行该命令, 将取消加粗
  22576. * @method execCommand
  22577. * @example
  22578. * ```javascript
  22579. * //editor是编辑器实例
  22580. * //对当前选中的文本内容执行加粗操作
  22581. * //第一次执行, 文本内容加粗
  22582. * editor.execCommand( 'bold' );
  22583. *
  22584. * //第二次执行, 文本内容取消加粗
  22585. * editor.execCommand( 'bold' );
  22586. * ```
  22587. */
  22588. /**
  22589. * 字体倾斜
  22590. * @command italic
  22591. * @method execCommand
  22592. * @param { String } cmd 命令字符串
  22593. * @remind 对已倾斜的文本内容执行该命令, 将取消倾斜
  22594. * @example
  22595. * ```javascript
  22596. * //editor是编辑器实例
  22597. * //对当前选中的文本内容执行斜体操作
  22598. * //第一次操作, 文本内容将变成斜体
  22599. * editor.execCommand( 'italic' );
  22600. *
  22601. * //再次对同一文本内容执行, 则文本内容将恢复正常
  22602. * editor.execCommand( 'italic' );
  22603. * ```
  22604. */
  22605. /**
  22606. * 下标文本,与“superscript”命令互斥
  22607. * @command subscript
  22608. * @method execCommand
  22609. * @remind 把选中的文本内容切换成下标文本, 如果当前选中的文本已经是下标, 则该操作会把文本内容还原成正常文本
  22610. * @param { String } cmd 命令字符串
  22611. * @example
  22612. * ```javascript
  22613. * //editor是编辑器实例
  22614. * //对当前选中的文本内容执行下标操作
  22615. * //第一次操作, 文本内容将变成下标文本
  22616. * editor.execCommand( 'subscript' );
  22617. *
  22618. * //再次对同一文本内容执行, 则文本内容将恢复正常
  22619. * editor.execCommand( 'subscript' );
  22620. * ```
  22621. */
  22622. /**
  22623. * 上标文本,与“subscript”命令互斥
  22624. * @command superscript
  22625. * @method execCommand
  22626. * @remind 把选中的文本内容切换成上标文本, 如果当前选中的文本已经是上标, 则该操作会把文本内容还原成正常文本
  22627. * @param { String } cmd 命令字符串
  22628. * @example
  22629. * ```javascript
  22630. * //editor是编辑器实例
  22631. * //对当前选中的文本内容执行上标操作
  22632. * //第一次操作, 文本内容将变成上标文本
  22633. * editor.execCommand( 'superscript' );
  22634. *
  22635. * //再次对同一文本内容执行, 则文本内容将恢复正常
  22636. * editor.execCommand( 'superscript' );
  22637. * ```
  22638. */
  22639. var basestyles = {
  22640. bold: ['strong', 'b'],
  22641. italic: ['em', 'i'],
  22642. subscript: ['sub'],
  22643. superscript: ['sup']
  22644. },
  22645. getObj = function (editor, tagNames) {
  22646. return domUtils.filterNodeList(editor.selection.getStartElementPath(), tagNames)
  22647. },
  22648. me = this
  22649. //添加快捷键
  22650. me.addshortcutkey({
  22651. Bold: 'ctrl+66', //^B
  22652. Italic: 'ctrl+73', //^I
  22653. Underline: 'ctrl+85' //^U
  22654. })
  22655. me.addInputRule(function (root) {
  22656. utils.each(root.getNodesByTagName('b i'), function (node) {
  22657. switch (node.tagName) {
  22658. case 'b':
  22659. node.tagName = 'strong'
  22660. break
  22661. case 'i':
  22662. node.tagName = 'em'
  22663. }
  22664. })
  22665. })
  22666. for (var style in basestyles) {
  22667. ;(function (cmd, tagNames) {
  22668. me.commands[cmd] = {
  22669. execCommand: function (cmdName) {
  22670. var range = me.selection.getRange(),
  22671. obj = getObj(this, tagNames)
  22672. if (range.collapsed) {
  22673. if (obj) {
  22674. var tmpText = me.document.createTextNode('')
  22675. range.insertNode(tmpText).removeInlineStyle(tagNames)
  22676. range.setStartBefore(tmpText)
  22677. domUtils.remove(tmpText)
  22678. } else {
  22679. var tmpNode = range.document.createElement(tagNames[0])
  22680. if (cmdName == 'superscript' || cmdName == 'subscript') {
  22681. tmpText = me.document.createTextNode('')
  22682. range
  22683. .insertNode(tmpText)
  22684. .removeInlineStyle(['sub', 'sup'])
  22685. .setStartBefore(tmpText)
  22686. .collapse(true)
  22687. }
  22688. range.insertNode(tmpNode).setStart(tmpNode, 0)
  22689. }
  22690. range.collapse(true)
  22691. } else {
  22692. if (cmdName == 'superscript' || cmdName == 'subscript') {
  22693. if (!obj || obj.tagName.toLowerCase() != cmdName) {
  22694. range.removeInlineStyle(['sub', 'sup'])
  22695. }
  22696. }
  22697. obj ? range.removeInlineStyle(tagNames) : range.applyInlineStyle(tagNames[0])
  22698. }
  22699. range.select()
  22700. },
  22701. queryCommandState: function () {
  22702. return getObj(this, tagNames) ? 1 : 0
  22703. }
  22704. }
  22705. })(style, basestyles[style])
  22706. }
  22707. }
  22708. // plugins/elementpath.js
  22709. /**
  22710. * 选取路径命令
  22711. * @file
  22712. */
  22713. UE.plugins['elementpath'] = function () {
  22714. var currentLevel,
  22715. tagNames,
  22716. me = this
  22717. me.setOpt('elementPathEnabled', true)
  22718. if (!me.options.elementPathEnabled) {
  22719. return
  22720. }
  22721. me.commands['elementpath'] = {
  22722. execCommand: function (cmdName, level) {
  22723. var start = tagNames[level],
  22724. range = me.selection.getRange()
  22725. currentLevel = level * 1
  22726. range.selectNode(start).select()
  22727. },
  22728. queryCommandValue: function () {
  22729. //产生一个副本,不能修改原来的startElementPath;
  22730. var parents = [].concat(this.selection.getStartElementPath()).reverse(),
  22731. names = []
  22732. tagNames = parents
  22733. for (var i = 0, ci; (ci = parents[i]); i++) {
  22734. if (ci.nodeType == 3) {
  22735. continue
  22736. }
  22737. var name = ci.tagName.toLowerCase()
  22738. if (name == 'img' && ci.getAttribute('anchorname')) {
  22739. name = 'anchor'
  22740. }
  22741. names[i] = name
  22742. if (currentLevel == i) {
  22743. currentLevel = -1
  22744. break
  22745. }
  22746. }
  22747. return names
  22748. }
  22749. }
  22750. }
  22751. // plugins/formatmatch.js
  22752. /**
  22753. * 格式刷,只格式inline的
  22754. * @file
  22755. * @since 1.2.6.1
  22756. */
  22757. /**
  22758. * 格式刷
  22759. * @command formatmatch
  22760. * @method execCommand
  22761. * @remind 该操作不能复制段落格式
  22762. * @param { String } cmd 命令字符串
  22763. * @example
  22764. * ```javascript
  22765. * //editor是编辑器实例
  22766. * //获取格式刷
  22767. * editor.execCommand( 'formatmatch' );
  22768. * ```
  22769. */
  22770. UE.plugins['formatmatch'] = function () {
  22771. var me = this,
  22772. list = [],
  22773. img,
  22774. flag = 0
  22775. me.addListener('reset', function () {
  22776. list = []
  22777. flag = 0
  22778. })
  22779. function addList(type, evt) {
  22780. if (browser.webkit) {
  22781. var target = evt.target.tagName == 'IMG' ? evt.target : null
  22782. }
  22783. function addFormat(range) {
  22784. if (text) {
  22785. range.selectNode(text)
  22786. }
  22787. return range.applyInlineStyle(list[list.length - 1].tagName, null, list)
  22788. }
  22789. me.undoManger && me.undoManger.save()
  22790. var range = me.selection.getRange(),
  22791. imgT = target || range.getClosedNode()
  22792. if (img && imgT && imgT.tagName == 'IMG') {
  22793. //trace:964
  22794. imgT.style.cssText +=
  22795. ';float:' +
  22796. (img.style.cssFloat || img.style.styleFloat || 'none') +
  22797. ';display:' +
  22798. (img.style.display || 'inline')
  22799. img = null
  22800. } else {
  22801. if (!img) {
  22802. var collapsed = range.collapsed
  22803. if (collapsed) {
  22804. var text = me.document.createTextNode('match')
  22805. range.insertNode(text).select()
  22806. }
  22807. me.__hasEnterExecCommand = true
  22808. //不能把block上的属性干掉
  22809. //trace:1553
  22810. var removeFormatAttributes = me.options.removeFormatAttributes
  22811. me.options.removeFormatAttributes = ''
  22812. me.execCommand('removeformat')
  22813. me.options.removeFormatAttributes = removeFormatAttributes
  22814. me.__hasEnterExecCommand = false
  22815. //trace:969
  22816. range = me.selection.getRange()
  22817. if (list.length) {
  22818. addFormat(range)
  22819. }
  22820. if (text) {
  22821. range.setStartBefore(text).collapse(true)
  22822. }
  22823. range.select()
  22824. text && domUtils.remove(text)
  22825. }
  22826. }
  22827. me.undoManger && me.undoManger.save()
  22828. me.removeListener('mouseup', addList)
  22829. flag = 0
  22830. }
  22831. me.commands['formatmatch'] = {
  22832. execCommand: function (cmdName) {
  22833. if (flag) {
  22834. flag = 0
  22835. list = []
  22836. me.removeListener('mouseup', addList)
  22837. return
  22838. }
  22839. var range = me.selection.getRange()
  22840. img = range.getClosedNode()
  22841. if (!img || img.tagName != 'IMG') {
  22842. range.collapse(true).shrinkBoundary()
  22843. var start = range.startContainer
  22844. list = domUtils.findParents(start, true, function (node) {
  22845. return !domUtils.isBlockElm(node) && node.nodeType == 1
  22846. })
  22847. //a不能加入格式刷, 并且克隆节点
  22848. for (var i = 0, ci; (ci = list[i]); i++) {
  22849. if (ci.tagName == 'A') {
  22850. list.splice(i, 1)
  22851. break
  22852. }
  22853. }
  22854. }
  22855. me.addListener('mouseup', addList)
  22856. flag = 1
  22857. },
  22858. queryCommandState: function () {
  22859. return flag
  22860. },
  22861. notNeedUndo: 1
  22862. }
  22863. }
  22864. // plugins/searchreplace.js
  22865. ///import core
  22866. ///commands 查找替换
  22867. ///commandsName SearchReplace
  22868. ///commandsTitle 查询替换
  22869. ///commandsDialog dialogs\searchreplace
  22870. /**
  22871. * @description 查找替换
  22872. * @author zhanyi
  22873. */
  22874. UE.plugin.register('searchreplace', function () {
  22875. var me = this
  22876. var _blockElm = { table: 1, tbody: 1, tr: 1, ol: 1, ul: 1 }
  22877. function findTextInString(textContent, opt, currentIndex) {
  22878. var str = opt.searchStr
  22879. if (opt.dir == -1) {
  22880. textContent = textContent.split('').reverse().join('')
  22881. str = str.split('').reverse().join('')
  22882. currentIndex = textContent.length - currentIndex
  22883. }
  22884. var reg = new RegExp(str, 'g' + (opt.casesensitive ? '' : 'i')),
  22885. match
  22886. while ((match = reg.exec(textContent))) {
  22887. if (match.index >= currentIndex) {
  22888. return opt.dir == -1
  22889. ? textContent.length - match.index - opt.searchStr.length
  22890. : match.index
  22891. }
  22892. }
  22893. return -1
  22894. }
  22895. function findTextBlockElm(node, currentIndex, opt) {
  22896. var textContent,
  22897. index,
  22898. methodName = opt.all || opt.dir == 1 ? 'getNextDomNode' : 'getPreDomNode'
  22899. if (domUtils.isBody(node)) {
  22900. node = node.firstChild
  22901. }
  22902. var first = 1
  22903. while (node) {
  22904. textContent =
  22905. node.nodeType == 3 ? node.nodeValue : node[browser.ie ? 'innerText' : 'textContent']
  22906. index = findTextInString(textContent, opt, currentIndex)
  22907. first = 0
  22908. if (index != -1) {
  22909. return {
  22910. node: node,
  22911. index: index
  22912. }
  22913. }
  22914. node = domUtils[methodName](node)
  22915. while (node && _blockElm[node.nodeName.toLowerCase()]) {
  22916. node = domUtils[methodName](node, true)
  22917. }
  22918. if (node) {
  22919. currentIndex =
  22920. opt.dir == -1
  22921. ? (node.nodeType == 3
  22922. ? node.nodeValue
  22923. : node[browser.ie ? 'innerText' : 'textContent']
  22924. ).length
  22925. : 0
  22926. }
  22927. }
  22928. }
  22929. function findNTextInBlockElm(node, index, str) {
  22930. var currentIndex = 0,
  22931. currentNode = node.firstChild,
  22932. currentNodeLength = 0,
  22933. result
  22934. while (currentNode) {
  22935. if (currentNode.nodeType == 3) {
  22936. currentNodeLength = currentNode.nodeValue.replace(/(^[\t\r\n]+)|([\t\r\n]+$)/, '').length
  22937. currentIndex += currentNodeLength
  22938. if (currentIndex >= index) {
  22939. return {
  22940. node: currentNode,
  22941. index: currentNodeLength - (currentIndex - index)
  22942. }
  22943. }
  22944. } else if (!dtd.$empty[currentNode.tagName]) {
  22945. currentNodeLength = currentNode[browser.ie ? 'innerText' : 'textContent'].replace(
  22946. /(^[\t\r\n]+)|([\t\r\n]+$)/,
  22947. ''
  22948. ).length
  22949. currentIndex += currentNodeLength
  22950. if (currentIndex >= index) {
  22951. result = findNTextInBlockElm(
  22952. currentNode,
  22953. currentNodeLength - (currentIndex - index),
  22954. str
  22955. )
  22956. if (result) {
  22957. return result
  22958. }
  22959. }
  22960. }
  22961. currentNode = domUtils.getNextDomNode(currentNode)
  22962. }
  22963. }
  22964. function searchReplace(me, opt) {
  22965. var rng = me.selection.getRange(),
  22966. startBlockNode,
  22967. searchStr = opt.searchStr,
  22968. span = me.document.createElement('span')
  22969. span.innerHTML = '$$ueditor_searchreplace_key$$'
  22970. rng.shrinkBoundary(true)
  22971. //判断是不是第一次选中
  22972. if (!rng.collapsed) {
  22973. rng.select()
  22974. var rngText = me.selection.getText()
  22975. if (new RegExp('^' + opt.searchStr + '$', opt.casesensitive ? '' : 'i').test(rngText)) {
  22976. if (opt.replaceStr != undefined) {
  22977. replaceText(rng, opt.replaceStr)
  22978. rng.select()
  22979. return true
  22980. } else {
  22981. rng.collapse(opt.dir == -1)
  22982. }
  22983. }
  22984. }
  22985. rng.insertNode(span)
  22986. rng.enlargeToBlockElm(true)
  22987. startBlockNode = rng.startContainer
  22988. var currentIndex = startBlockNode[browser.ie ? 'innerText' : 'textContent'].indexOf(
  22989. '$$ueditor_searchreplace_key$$'
  22990. )
  22991. rng.setStartBefore(span)
  22992. domUtils.remove(span)
  22993. var result = findTextBlockElm(startBlockNode, currentIndex, opt)
  22994. if (result) {
  22995. var rngStart = findNTextInBlockElm(result.node, result.index, searchStr)
  22996. var rngEnd = findNTextInBlockElm(result.node, result.index + searchStr.length, searchStr)
  22997. rng.setStart(rngStart.node, rngStart.index).setEnd(rngEnd.node, rngEnd.index)
  22998. if (opt.replaceStr !== undefined) {
  22999. replaceText(rng, opt.replaceStr)
  23000. }
  23001. rng.select()
  23002. return true
  23003. } else {
  23004. rng.setCursor()
  23005. }
  23006. }
  23007. function replaceText(rng, str) {
  23008. str = me.document.createTextNode(str)
  23009. rng.deleteContents().insertNode(str)
  23010. }
  23011. return {
  23012. commands: {
  23013. searchreplace: {
  23014. execCommand: function (cmdName, opt) {
  23015. utils.extend(
  23016. opt,
  23017. {
  23018. all: false,
  23019. casesensitive: false,
  23020. dir: 1
  23021. },
  23022. true
  23023. )
  23024. var num = 0
  23025. if (opt.all) {
  23026. var rng = me.selection.getRange(),
  23027. first = me.body.firstChild
  23028. if (first && first.nodeType == 1) {
  23029. rng.setStart(first, 0)
  23030. rng.shrinkBoundary(true)
  23031. } else if (first.nodeType == 3) {
  23032. rng.setStartBefore(first)
  23033. }
  23034. rng.collapse(true).select(true)
  23035. if (opt.replaceStr !== undefined) {
  23036. me.fireEvent('saveScene')
  23037. }
  23038. while (searchReplace(this, opt)) {
  23039. num++
  23040. }
  23041. if (num) {
  23042. me.fireEvent('saveScene')
  23043. }
  23044. } else {
  23045. if (opt.replaceStr !== undefined) {
  23046. me.fireEvent('saveScene')
  23047. }
  23048. if (searchReplace(this, opt)) {
  23049. num++
  23050. }
  23051. if (num) {
  23052. me.fireEvent('saveScene')
  23053. }
  23054. }
  23055. return num
  23056. },
  23057. notNeedUndo: 1
  23058. }
  23059. }
  23060. }
  23061. })
  23062. // plugins/customstyle.js
  23063. /**
  23064. * 自定义样式
  23065. * @file
  23066. * @since 1.2.6.1
  23067. */
  23068. /**
  23069. * 根据config配置文件里“customstyle”选项的值对匹配的标签执行样式替换。
  23070. * @command customstyle
  23071. * @method execCommand
  23072. * @param { String } cmd 命令字符串
  23073. * @example
  23074. * ```javascript
  23075. * editor.execCommand( 'customstyle' );
  23076. * ```
  23077. */
  23078. UE.plugins['customstyle'] = function () {
  23079. var me = this
  23080. me.setOpt({
  23081. customstyle: [
  23082. {
  23083. tag: 'h1',
  23084. name: 'tc',
  23085. style:
  23086. 'font-size:32px;font-weight:bold;border-bottom:#ccc 2px solid;padding:0 4px 0 0;text-align:center;margin:0 0 20px 0;'
  23087. },
  23088. {
  23089. tag: 'h1',
  23090. name: 'tl',
  23091. style:
  23092. 'font-size:32px;font-weight:bold;border-bottom:#ccc 2px solid;padding:0 4px 0 0;text-align:left;margin:0 0 10px 0;'
  23093. },
  23094. {
  23095. tag: 'span',
  23096. name: 'im',
  23097. style: 'font-size:16px;font-style:italic;font-weight:bold;line-height:18px;'
  23098. },
  23099. {
  23100. tag: 'span',
  23101. name: 'hi',
  23102. style:
  23103. 'font-size:16px;font-style:italic;font-weight:bold;color:rgb(51, 153, 204);line-height:18px;'
  23104. }
  23105. ]
  23106. })
  23107. me.commands['customstyle'] = {
  23108. execCommand: function (cmdName, obj) {
  23109. var me = this,
  23110. tagName = obj.tag,
  23111. node = domUtils.findParent(
  23112. me.selection.getStart(),
  23113. function (node) {
  23114. return node.getAttribute('label')
  23115. },
  23116. true
  23117. ),
  23118. range,
  23119. bk,
  23120. tmpObj = {}
  23121. for (var p in obj) {
  23122. if (obj[p] !== undefined) tmpObj[p] = obj[p]
  23123. }
  23124. delete tmpObj.tag
  23125. if (node && node.getAttribute('label') == obj.label) {
  23126. range = this.selection.getRange()
  23127. bk = range.createBookmark()
  23128. if (range.collapsed) {
  23129. //trace:1732 删掉自定义标签,要有p来回填站位
  23130. if (dtd.$block[node.tagName]) {
  23131. var fillNode = me.document.createElement('p')
  23132. domUtils.moveChild(node, fillNode)
  23133. node.parentNode.insertBefore(fillNode, node)
  23134. domUtils.remove(node)
  23135. } else {
  23136. domUtils.remove(node, true)
  23137. }
  23138. } else {
  23139. var common = domUtils.getCommonAncestor(bk.start, bk.end),
  23140. nodes = domUtils.getElementsByTagName(common, tagName)
  23141. if (new RegExp(tagName, 'i').test(common.tagName)) {
  23142. nodes.push(common)
  23143. }
  23144. for (var i = 0, ni; (ni = nodes[i++]); ) {
  23145. if (ni.getAttribute('label') == obj.label) {
  23146. var ps = domUtils.getPosition(ni, bk.start),
  23147. pe = domUtils.getPosition(ni, bk.end)
  23148. if (
  23149. (ps & domUtils.POSITION_FOLLOWING || ps & domUtils.POSITION_CONTAINS) &&
  23150. (pe & domUtils.POSITION_PRECEDING || pe & domUtils.POSITION_CONTAINS)
  23151. )
  23152. if (dtd.$block[tagName]) {
  23153. var fillNode = me.document.createElement('p')
  23154. domUtils.moveChild(ni, fillNode)
  23155. ni.parentNode.insertBefore(fillNode, ni)
  23156. }
  23157. domUtils.remove(ni, true)
  23158. }
  23159. }
  23160. node = domUtils.findParent(
  23161. common,
  23162. function (node) {
  23163. return node.getAttribute('label') == obj.label
  23164. },
  23165. true
  23166. )
  23167. if (node) {
  23168. domUtils.remove(node, true)
  23169. }
  23170. }
  23171. range.moveToBookmark(bk).select()
  23172. } else {
  23173. if (dtd.$block[tagName]) {
  23174. this.execCommand('paragraph', tagName, tmpObj, 'customstyle')
  23175. range = me.selection.getRange()
  23176. if (!range.collapsed) {
  23177. range.collapse()
  23178. node = domUtils.findParent(
  23179. me.selection.getStart(),
  23180. function (node) {
  23181. return node.getAttribute('label') == obj.label
  23182. },
  23183. true
  23184. )
  23185. var pNode = me.document.createElement('p')
  23186. domUtils.insertAfter(node, pNode)
  23187. domUtils.fillNode(me.document, pNode)
  23188. range.setStart(pNode, 0).setCursor()
  23189. }
  23190. } else {
  23191. range = me.selection.getRange()
  23192. if (range.collapsed) {
  23193. node = me.document.createElement(tagName)
  23194. domUtils.setAttributes(node, tmpObj)
  23195. range.insertNode(node).setStart(node, 0).setCursor()
  23196. return
  23197. }
  23198. bk = range.createBookmark()
  23199. range.applyInlineStyle(tagName, tmpObj).moveToBookmark(bk).select()
  23200. }
  23201. }
  23202. },
  23203. queryCommandValue: function () {
  23204. var parent = domUtils.filterNodeList(this.selection.getStartElementPath(), function (node) {
  23205. return node.getAttribute('label')
  23206. })
  23207. return parent ? parent.getAttribute('label') : ''
  23208. }
  23209. }
  23210. //当去掉customstyle是,如果是块元素,用p代替
  23211. me.addListener('keyup', function (type, evt) {
  23212. var keyCode = evt.keyCode || evt.which
  23213. if (keyCode == 32 || keyCode == 13) {
  23214. var range = me.selection.getRange()
  23215. if (range.collapsed) {
  23216. var node = domUtils.findParent(
  23217. me.selection.getStart(),
  23218. function (node) {
  23219. return node.getAttribute('label')
  23220. },
  23221. true
  23222. )
  23223. if (node && dtd.$block[node.tagName] && domUtils.isEmptyNode(node)) {
  23224. var p = me.document.createElement('p')
  23225. domUtils.insertAfter(node, p)
  23226. domUtils.fillNode(me.document, p)
  23227. domUtils.remove(node)
  23228. range.setStart(p, 0).setCursor()
  23229. }
  23230. }
  23231. }
  23232. })
  23233. }
  23234. // plugins/catchremoteimage.js
  23235. ///import core
  23236. ///commands 远程图片抓取
  23237. ///commandsName catchRemoteImage,catchremoteimageenable
  23238. ///commandsTitle 远程图片抓取
  23239. /**
  23240. * 远程图片抓取,当开启本插件时所有不符合本地域名的图片都将被抓取成为本地服务器上的图片
  23241. */
  23242. UE.plugins['catchremoteimage'] = function () {
  23243. var me = this,
  23244. ajax = UE.ajax
  23245. /* 设置默认值 */
  23246. if (me.options.catchRemoteImageEnable === false) return
  23247. me.setOpt({
  23248. catchRemoteImageEnable: false
  23249. })
  23250. me.addListener('afterpaste', function () {
  23251. me.fireEvent('catchRemoteImage')
  23252. })
  23253. me.addListener('catchRemoteImage', function () {
  23254. var catcherLocalDomain = me.getOpt('catcherLocalDomain'),
  23255. catcherActionUrl = me.getActionUrl(me.getOpt('catcherActionName')),
  23256. catcherUrlPrefix = me.getOpt('catcherUrlPrefix'),
  23257. catcherFieldName = me.getOpt('catcherFieldName')
  23258. var remoteImages = [],
  23259. imgs = domUtils.getElementsByTagName(me.document, 'img'),
  23260. test = function (src, urls) {
  23261. if (src.indexOf(location.host) != -1 || /(^\.)|(^\/)/.test(src)) {
  23262. return true
  23263. }
  23264. if (urls) {
  23265. for (var j = 0, url; (url = urls[j++]); ) {
  23266. if (src.indexOf(url) !== -1) {
  23267. return true
  23268. }
  23269. }
  23270. }
  23271. return false
  23272. }
  23273. for (var i = 0, ci; (ci = imgs[i++]); ) {
  23274. if (ci.getAttribute('word_img')) {
  23275. continue
  23276. }
  23277. var src = ci.getAttribute('_src') || ci.src || ''
  23278. if (/^(https?|ftp):/i.test(src) && !test(src, catcherLocalDomain)) {
  23279. remoteImages.push(src)
  23280. }
  23281. }
  23282. if (remoteImages.length) {
  23283. catchremoteimage(remoteImages, {
  23284. //成功抓取
  23285. success: function (r) {
  23286. try {
  23287. var info = r.state !== undefined ? r : eval('(' + r.responseText + ')')
  23288. } catch (e) {
  23289. return
  23290. }
  23291. /* 获取源路径和新路径 */
  23292. var i,
  23293. j,
  23294. ci,
  23295. cj,
  23296. oldSrc,
  23297. newSrc,
  23298. list = info.list
  23299. for (i = 0; (ci = imgs[i++]); ) {
  23300. oldSrc = ci.getAttribute('_src') || ci.src || ''
  23301. for (j = 0; (cj = list[j++]); ) {
  23302. if (oldSrc == cj.source && cj.state == 'SUCCESS') {
  23303. //抓取失败时不做替换处理
  23304. newSrc = catcherUrlPrefix + cj.url
  23305. domUtils.setAttributes(ci, {
  23306. src: newSrc,
  23307. _src: newSrc
  23308. })
  23309. break
  23310. }
  23311. }
  23312. }
  23313. me.fireEvent('catchremotesuccess')
  23314. },
  23315. //回调失败,本次请求超时
  23316. error: function () {
  23317. me.fireEvent('catchremoteerror')
  23318. }
  23319. })
  23320. }
  23321. function catchremoteimage(imgs, callbacks) {
  23322. var params = utils.serializeParam(me.queryCommandValue('serverparam')) || '',
  23323. url = utils.formatUrl(
  23324. catcherActionUrl + (catcherActionUrl.indexOf('?') == -1 ? '?' : '&') + params
  23325. ),
  23326. isJsonp = utils.isCrossDomainUrl(url),
  23327. opt = {
  23328. method: 'POST',
  23329. dataType: isJsonp ? 'jsonp' : '',
  23330. timeout: 60000, //单位:毫秒,回调请求超时设置。目标用户如果网速不是很快的话此处建议设置一个较大的数值
  23331. onsuccess: callbacks['success'],
  23332. onerror: callbacks['error']
  23333. }
  23334. opt[catcherFieldName] = imgs
  23335. ajax.request(url, opt)
  23336. }
  23337. })
  23338. }
  23339. // plugins/snapscreen.js
  23340. /**
  23341. * 截屏插件,为UEditor提供插入支持
  23342. * @file
  23343. * @since 1.4.2
  23344. */
  23345. UE.plugin.register('snapscreen', function () {
  23346. var me = this
  23347. var snapplugin
  23348. function getLocation(url) {
  23349. var search,
  23350. a = document.createElement('a'),
  23351. params = utils.serializeParam(me.queryCommandValue('serverparam')) || ''
  23352. a.href = url
  23353. if (browser.ie) {
  23354. a.href = a.href
  23355. }
  23356. search = a.search
  23357. if (params) {
  23358. search = search + (search.indexOf('?') == -1 ? '?' : '&') + params
  23359. search = search.replace(/[&]+/gi, '&')
  23360. }
  23361. return {
  23362. port: a.port,
  23363. hostname: a.hostname,
  23364. path: a.pathname + search || +a.hash
  23365. }
  23366. }
  23367. return {
  23368. commands: {
  23369. /**
  23370. * 字体背景颜色
  23371. * @command snapscreen
  23372. * @method execCommand
  23373. * @param { String } cmd 命令字符串
  23374. * @example
  23375. * ```javascript
  23376. * editor.execCommand('snapscreen');
  23377. * ```
  23378. */
  23379. snapscreen: {
  23380. execCommand: function (cmd) {
  23381. var url, local, res
  23382. var lang = me.getLang('snapScreen_plugin')
  23383. if (!snapplugin) {
  23384. var container = me.container
  23385. var doc = me.container.ownerDocument || me.container.document
  23386. snapplugin = doc.createElement('object')
  23387. try {
  23388. snapplugin.type = 'application/x-pluginbaidusnap'
  23389. } catch (e) {
  23390. return
  23391. }
  23392. snapplugin.style.cssText = 'position:absolute;left:-9999px;width:0;height:0;'
  23393. snapplugin.setAttribute('width', '0')
  23394. snapplugin.setAttribute('height', '0')
  23395. container.appendChild(snapplugin)
  23396. }
  23397. function onSuccess(rs) {
  23398. try {
  23399. rs = eval('(' + rs + ')')
  23400. if (rs.state == 'SUCCESS') {
  23401. var opt = me.options
  23402. me.execCommand('insertimage', {
  23403. src: opt.snapscreenUrlPrefix + rs.url,
  23404. _src: opt.snapscreenUrlPrefix + rs.url,
  23405. alt: rs.title || '',
  23406. floatStyle: opt.snapscreenImgAlign
  23407. })
  23408. } else {
  23409. alert(rs.state)
  23410. }
  23411. } catch (e) {
  23412. alert(lang.callBackErrorMsg)
  23413. }
  23414. }
  23415. url = me.getActionUrl(me.getOpt('snapscreenActionName'))
  23416. local = getLocation(url)
  23417. setTimeout(function () {
  23418. try {
  23419. res = snapplugin.saveSnapshot(local.hostname, local.path, local.port)
  23420. } catch (e) {
  23421. me.ui._dialogs['snapscreenDialog'].open()
  23422. return
  23423. }
  23424. onSuccess(res)
  23425. }, 50)
  23426. },
  23427. queryCommandState: function () {
  23428. return navigator.userAgent.indexOf('Windows', 0) != -1 ? 0 : -1
  23429. }
  23430. }
  23431. }
  23432. }
  23433. })
  23434. // plugins/insertparagraph.js
  23435. /**
  23436. * 插入段落
  23437. * @file
  23438. * @since 1.2.6.1
  23439. */
  23440. /**
  23441. * 插入段落
  23442. * @command insertparagraph
  23443. * @method execCommand
  23444. * @param { String } cmd 命令字符串
  23445. * @example
  23446. * ```javascript
  23447. * //editor是编辑器实例
  23448. * editor.execCommand( 'insertparagraph' );
  23449. * ```
  23450. */
  23451. UE.commands['insertparagraph'] = {
  23452. execCommand: function (cmdName, front) {
  23453. var me = this,
  23454. range = me.selection.getRange(),
  23455. start = range.startContainer,
  23456. tmpNode
  23457. while (start) {
  23458. if (domUtils.isBody(start)) {
  23459. break
  23460. }
  23461. tmpNode = start
  23462. start = start.parentNode
  23463. }
  23464. if (tmpNode) {
  23465. var p = me.document.createElement('p')
  23466. if (front) {
  23467. tmpNode.parentNode.insertBefore(p, tmpNode)
  23468. } else {
  23469. tmpNode.parentNode.insertBefore(p, tmpNode.nextSibling)
  23470. }
  23471. domUtils.fillNode(me.document, p)
  23472. range.setStart(p, 0).setCursor(false, true)
  23473. }
  23474. }
  23475. }
  23476. // plugins/webapp.js
  23477. /**
  23478. * 百度应用
  23479. * @file
  23480. * @since 1.2.6.1
  23481. */
  23482. /**
  23483. * 插入百度应用
  23484. * @command webapp
  23485. * @method execCommand
  23486. * @remind 需要百度APPKey
  23487. * @remind 百度应用主页: <a href="http://app.baidu.com/" target="_blank">http://app.baidu.com/</a>
  23488. * @param { Object } appOptions 应用所需的参数项, 支持的key有: title=>应用标题, width=>应用容器宽度,
  23489. * height=>应用容器高度,logo=>应用logo,url=>应用地址
  23490. * @example
  23491. * ```javascript
  23492. * //editor是编辑器实例
  23493. * //在编辑器里插入一个“植物大战僵尸”的APP
  23494. * editor.execCommand( 'webapp' , {
  23495. * title: '植物大战僵尸',
  23496. * width: 560,
  23497. * height: 465,
  23498. * logo: '应用展示的图片',
  23499. * url: '百度应用的地址'
  23500. * } );
  23501. * ```
  23502. */
  23503. //UE.plugins['webapp'] = function () {
  23504. // var me = this;
  23505. // function createInsertStr( obj, toIframe, addParagraph ) {
  23506. // return !toIframe ?
  23507. // (addParagraph ? '<p>' : '') + '<img title="'+obj.title+'" width="' + obj.width + '" height="' + obj.height + '"' +
  23508. // ' 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 + '" />' +
  23509. // (addParagraph ? '</p>' : '')
  23510. // :
  23511. // '<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>';
  23512. // }
  23513. //
  23514. // function switchImgAndIframe( img2frame ) {
  23515. // var tmpdiv,
  23516. // nodes = domUtils.getElementsByTagName( me.document, !img2frame ? "iframe" : "img" );
  23517. // for ( var i = 0, node; node = nodes[i++]; ) {
  23518. // if ( node.className != "edui-faked-webapp" ){
  23519. // continue;
  23520. // }
  23521. // tmpdiv = me.document.createElement( "div" );
  23522. // 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 );
  23523. // node.parentNode.replaceChild( tmpdiv.firstChild, node );
  23524. // }
  23525. // }
  23526. //
  23527. // me.addListener( "beforegetcontent", function () {
  23528. // switchImgAndIframe( true );
  23529. // } );
  23530. // me.addListener( 'aftersetcontent', function () {
  23531. // switchImgAndIframe( false );
  23532. // } );
  23533. // me.addListener( 'aftergetcontent', function ( cmdName ) {
  23534. // if ( cmdName == 'aftergetcontent' && me.queryCommandState( 'source' ) ){
  23535. // return;
  23536. // }
  23537. // switchImgAndIframe( false );
  23538. // } );
  23539. //
  23540. // me.commands['webapp'] = {
  23541. // execCommand:function ( cmd, obj ) {
  23542. // me.execCommand( "inserthtml", createInsertStr( obj, false,true ) );
  23543. // }
  23544. // };
  23545. //};
  23546. UE.plugin.register('webapp', function () {
  23547. var me = this
  23548. function createInsertStr(obj, toEmbed) {
  23549. return !toEmbed
  23550. ? '<img title="' +
  23551. obj.title +
  23552. '" width="' +
  23553. obj.width +
  23554. '" height="' +
  23555. obj.height +
  23556. '"' +
  23557. ' src="' +
  23558. me.options.UEDITOR_HOME_URL +
  23559. 'themes/default/images/spacer.gif" _logo_url="' +
  23560. obj.logo +
  23561. '" style="background:url(' +
  23562. obj.logo +
  23563. ') no-repeat center center; border:1px solid gray;" class="edui-faked-webapp" _url="' +
  23564. obj.url +
  23565. '" ' +
  23566. (obj.align && !obj.cssfloat ? 'align="' + obj.align + '"' : '') +
  23567. (obj.cssfloat ? 'style="float:' + obj.cssfloat + '"' : '') +
  23568. '/>'
  23569. : '<iframe class="edui-faked-webapp" title="' +
  23570. obj.title +
  23571. '" ' +
  23572. (obj.align && !obj.cssfloat ? 'align="' + obj.align + '"' : '') +
  23573. (obj.cssfloat ? 'style="float:' + obj.cssfloat + '"' : '') +
  23574. 'width="' +
  23575. obj.width +
  23576. '" height="' +
  23577. obj.height +
  23578. '" scrolling="no" frameborder="0" src="' +
  23579. obj.url +
  23580. '" logo_url = "' +
  23581. obj.logo +
  23582. '"></iframe>'
  23583. }
  23584. return {
  23585. outputRule: function (root) {
  23586. utils.each(root.getNodesByTagName('img'), function (node) {
  23587. var html
  23588. if (node.getAttr('class') == 'edui-faked-webapp') {
  23589. html = createInsertStr(
  23590. {
  23591. title: node.getAttr('title'),
  23592. width: node.getAttr('width'),
  23593. height: node.getAttr('height'),
  23594. align: node.getAttr('align'),
  23595. cssfloat: node.getStyle('float'),
  23596. url: node.getAttr('_url'),
  23597. logo: node.getAttr('_logo_url')
  23598. },
  23599. true
  23600. )
  23601. var embed = UE.uNode.createElement(html)
  23602. node.parentNode.replaceChild(embed, node)
  23603. }
  23604. })
  23605. },
  23606. inputRule: function (root) {
  23607. utils.each(root.getNodesByTagName('iframe'), function (node) {
  23608. if (node.getAttr('class') == 'edui-faked-webapp') {
  23609. var img = UE.uNode.createElement(
  23610. createInsertStr({
  23611. title: node.getAttr('title'),
  23612. width: node.getAttr('width'),
  23613. height: node.getAttr('height'),
  23614. align: node.getAttr('align'),
  23615. cssfloat: node.getStyle('float'),
  23616. url: node.getAttr('src'),
  23617. logo: node.getAttr('logo_url')
  23618. })
  23619. )
  23620. node.parentNode.replaceChild(img, node)
  23621. }
  23622. })
  23623. },
  23624. commands: {
  23625. /**
  23626. * 插入百度应用
  23627. * @command webapp
  23628. * @method execCommand
  23629. * @remind 需要百度APPKey
  23630. * @remind 百度应用主页: <a href="http://app.baidu.com/" target="_blank">http://app.baidu.com/</a>
  23631. * @param { Object } appOptions 应用所需的参数项, 支持的key有: title=>应用标题, width=>应用容器宽度,
  23632. * height=>应用容器高度,logo=>应用logo,url=>应用地址
  23633. * @example
  23634. * ```javascript
  23635. * //editor是编辑器实例
  23636. * //在编辑器里插入一个“植物大战僵尸”的APP
  23637. * editor.execCommand( 'webapp' , {
  23638. * title: '植物大战僵尸',
  23639. * width: 560,
  23640. * height: 465,
  23641. * logo: '应用展示的图片',
  23642. * url: '百度应用的地址'
  23643. * } );
  23644. * ```
  23645. */
  23646. webapp: {
  23647. execCommand: function (cmd, obj) {
  23648. var me = this,
  23649. str = createInsertStr(
  23650. utils.extend(obj, {
  23651. align: 'none'
  23652. }),
  23653. false
  23654. )
  23655. me.execCommand('inserthtml', str)
  23656. },
  23657. queryCommandState: function () {
  23658. var me = this,
  23659. img = me.selection.getRange().getClosedNode(),
  23660. flag = img && img.className == 'edui-faked-webapp'
  23661. return flag ? 1 : 0
  23662. }
  23663. }
  23664. }
  23665. }
  23666. })
  23667. // plugins/template.js
  23668. ///import core
  23669. ///import plugins\inserthtml.js
  23670. ///import plugins\cleardoc.js
  23671. ///commands 模板
  23672. ///commandsName template
  23673. ///commandsTitle 模板
  23674. ///commandsDialog dialogs\template
  23675. UE.plugins['template'] = function () {
  23676. UE.commands['template'] = {
  23677. execCommand: function (cmd, obj) {
  23678. obj.html && this.execCommand('inserthtml', obj.html)
  23679. }
  23680. }
  23681. this.addListener('click', function (type, evt) {
  23682. var el = evt.target || evt.srcElement,
  23683. range = this.selection.getRange()
  23684. var tnode = domUtils.findParent(
  23685. el,
  23686. function (node) {
  23687. if (node.className && domUtils.hasClass(node, 'ue_t')) {
  23688. return node
  23689. }
  23690. },
  23691. true
  23692. )
  23693. tnode && range.selectNode(tnode).shrinkBoundary().select()
  23694. })
  23695. this.addListener('keydown', function (type, evt) {
  23696. var range = this.selection.getRange()
  23697. if (!range.collapsed) {
  23698. if (!evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey) {
  23699. var tnode = domUtils.findParent(
  23700. range.startContainer,
  23701. function (node) {
  23702. if (node.className && domUtils.hasClass(node, 'ue_t')) {
  23703. return node
  23704. }
  23705. },
  23706. true
  23707. )
  23708. if (tnode) {
  23709. domUtils.removeClasses(tnode, ['ue_t'])
  23710. }
  23711. }
  23712. }
  23713. })
  23714. }
  23715. // plugins/music.js
  23716. /**
  23717. * 插入音乐命令
  23718. * @file
  23719. */
  23720. UE.plugin.register('music', function () {
  23721. var me = this
  23722. function creatInsertStr(url, width, height, align, cssfloat, toEmbed) {
  23723. return !toEmbed
  23724. ? '<img ' +
  23725. (align && !cssfloat ? 'align="' + align + '"' : '') +
  23726. (cssfloat ? 'style="float:' + cssfloat + '"' : '') +
  23727. ' width="' +
  23728. width +
  23729. '" height="' +
  23730. height +
  23731. '" _url="' +
  23732. url +
  23733. '" class="edui-faked-music"' +
  23734. ' src="' +
  23735. me.options.langPath +
  23736. me.options.lang +
  23737. '/images/music.png" />'
  23738. : '<embed type="application/x-shockwave-flash" class="edui-faked-music" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  23739. ' src="' +
  23740. url +
  23741. '" width="' +
  23742. width +
  23743. '" height="' +
  23744. height +
  23745. '" ' +
  23746. (align && !cssfloat ? 'align="' + align + '"' : '') +
  23747. (cssfloat ? 'style="float:' + cssfloat + '"' : '') +
  23748. ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >'
  23749. }
  23750. return {
  23751. outputRule: function (root) {
  23752. utils.each(root.getNodesByTagName('img'), function (node) {
  23753. var html
  23754. if (node.getAttr('class') == 'edui-faked-music') {
  23755. var cssfloat = node.getStyle('float')
  23756. var align = node.getAttr('align')
  23757. html = creatInsertStr(
  23758. node.getAttr('_url'),
  23759. node.getAttr('width'),
  23760. node.getAttr('height'),
  23761. align,
  23762. cssfloat,
  23763. true
  23764. )
  23765. var embed = UE.uNode.createElement(html)
  23766. node.parentNode.replaceChild(embed, node)
  23767. }
  23768. })
  23769. },
  23770. inputRule: function (root) {
  23771. utils.each(root.getNodesByTagName('embed'), function (node) {
  23772. if (node.getAttr('class') == 'edui-faked-music') {
  23773. var cssfloat = node.getStyle('float')
  23774. var align = node.getAttr('align')
  23775. html = creatInsertStr(
  23776. node.getAttr('src'),
  23777. node.getAttr('width'),
  23778. node.getAttr('height'),
  23779. align,
  23780. cssfloat,
  23781. false
  23782. )
  23783. var img = UE.uNode.createElement(html)
  23784. node.parentNode.replaceChild(img, node)
  23785. }
  23786. })
  23787. },
  23788. commands: {
  23789. /**
  23790. * 插入音乐
  23791. * @command music
  23792. * @method execCommand
  23793. * @param { Object } musicOptions 插入音乐的参数项, 支持的key有: url=>音乐地址;
  23794. * width=>音乐容器宽度;height=>音乐容器高度;align=>音乐文件的对齐方式, 可选值有: left, center, right, none
  23795. * @example
  23796. * ```javascript
  23797. * //editor是编辑器实例
  23798. * //在编辑器里插入一个“植物大战僵尸”的APP
  23799. * editor.execCommand( 'music' , {
  23800. * width: 400,
  23801. * height: 95,
  23802. * align: "center",
  23803. * url: "音乐地址"
  23804. * } );
  23805. * ```
  23806. */
  23807. music: {
  23808. execCommand: function (cmd, musicObj) {
  23809. var me = this,
  23810. str = creatInsertStr(
  23811. musicObj.url,
  23812. musicObj.width || 400,
  23813. musicObj.height || 95,
  23814. 'none',
  23815. false
  23816. )
  23817. me.execCommand('inserthtml', str)
  23818. },
  23819. queryCommandState: function () {
  23820. var me = this,
  23821. img = me.selection.getRange().getClosedNode(),
  23822. flag = img && img.className == 'edui-faked-music'
  23823. return flag ? 1 : 0
  23824. }
  23825. }
  23826. }
  23827. }
  23828. })
  23829. // plugins/autoupload.js
  23830. /**
  23831. * @description
  23832. * 1.拖放文件到编辑区域,自动上传并插入到选区
  23833. * 2.插入粘贴板的图片,自动上传并插入到选区
  23834. * @author Jinqn
  23835. * @date 2013-10-14
  23836. */
  23837. UE.plugin.register('autoupload', function () {
  23838. function sendAndInsertFile(file, editor) {
  23839. var me = editor
  23840. //模拟数据
  23841. var fieldName,
  23842. urlPrefix,
  23843. maxSize,
  23844. allowFiles,
  23845. actionUrl,
  23846. loadingHtml,
  23847. errorHandler,
  23848. successHandler,
  23849. filetype = /image\/\w+/i.test(file.type) ? 'image' : 'file',
  23850. loadingId = 'loading_' + (+new Date()).toString(36)
  23851. fieldName = me.getOpt(filetype + 'FieldName')
  23852. urlPrefix = me.getOpt(filetype + 'UrlPrefix')
  23853. maxSize = me.getOpt(filetype + 'MaxSize')
  23854. allowFiles = me.getOpt(filetype + 'AllowFiles')
  23855. actionUrl = me.getActionUrl(me.getOpt(filetype + 'ActionName'))
  23856. errorHandler = function (title) {
  23857. var loader = me.document.getElementById(loadingId)
  23858. loader && domUtils.remove(loader)
  23859. me.fireEvent('showmessage', {
  23860. id: loadingId,
  23861. content: title,
  23862. type: 'error',
  23863. timeout: 4000
  23864. })
  23865. }
  23866. if (filetype == 'image') {
  23867. loadingHtml =
  23868. '<img class="loadingclass" id="' +
  23869. loadingId +
  23870. '" src="' +
  23871. me.options.themePath +
  23872. me.options.theme +
  23873. '/images/spacer.gif" title="' +
  23874. (me.getLang('autoupload.loading') || '') +
  23875. '" >'
  23876. successHandler = function (data) {
  23877. var link = urlPrefix + data.url,
  23878. loader = me.document.getElementById(loadingId)
  23879. if (loader) {
  23880. loader.setAttribute('src', link)
  23881. loader.setAttribute('_src', link)
  23882. loader.setAttribute('title', data.title || '')
  23883. loader.setAttribute('alt', data.original || '')
  23884. loader.removeAttribute('id')
  23885. domUtils.removeClasses(loader, 'loadingclass')
  23886. }
  23887. }
  23888. } else {
  23889. loadingHtml =
  23890. '<p>' +
  23891. '<img class="loadingclass" id="' +
  23892. loadingId +
  23893. '" src="' +
  23894. me.options.themePath +
  23895. me.options.theme +
  23896. '/images/spacer.gif" title="' +
  23897. (me.getLang('autoupload.loading') || '') +
  23898. '" >' +
  23899. '</p>'
  23900. successHandler = function (data) {
  23901. var link = urlPrefix + data.url,
  23902. loader = me.document.getElementById(loadingId)
  23903. var rng = me.selection.getRange(),
  23904. bk = rng.createBookmark()
  23905. rng.selectNode(loader).select()
  23906. me.execCommand('insertfile', { url: link })
  23907. rng.moveToBookmark(bk).select()
  23908. }
  23909. }
  23910. /* 插入loading的占位符 */
  23911. me.execCommand('inserthtml', loadingHtml)
  23912. /* 判断后端配置是否没有加载成功 */
  23913. if (!me.getOpt(filetype + 'ActionName')) {
  23914. errorHandler(me.getLang('autoupload.errorLoadConfig'))
  23915. return
  23916. }
  23917. /* 判断文件大小是否超出限制 */
  23918. if (file.size > maxSize) {
  23919. errorHandler(me.getLang('autoupload.exceedSizeError'))
  23920. return
  23921. }
  23922. /* 判断文件格式是否超出允许 */
  23923. var fileext = file.name ? file.name.substr(file.name.lastIndexOf('.')) : ''
  23924. if (
  23925. (fileext && filetype != 'image') ||
  23926. (allowFiles && (allowFiles.join('') + '.').indexOf(fileext.toLowerCase() + '.') == -1)
  23927. ) {
  23928. errorHandler(me.getLang('autoupload.exceedTypeError'))
  23929. return
  23930. }
  23931. /* 创建Ajax并提交 */
  23932. var xhr = new XMLHttpRequest(),
  23933. fd = new FormData(),
  23934. params = utils.serializeParam(me.queryCommandValue('serverparam')) || '',
  23935. url = utils.formatUrl(actionUrl + (actionUrl.indexOf('?') == -1 ? '?' : '&') + params)
  23936. fd.append(fieldName, file, file.name || 'blob.' + file.type.substr('image/'.length))
  23937. fd.append('type', 'ajax')
  23938. xhr.open('post', url, true)
  23939. xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
  23940. xhr.addEventListener('load', function (e) {
  23941. try {
  23942. var json = new Function('return ' + utils.trim(e.target.response))()
  23943. if (json.state == 'SUCCESS' && json.url) {
  23944. successHandler(json)
  23945. } else {
  23946. errorHandler(json.state)
  23947. }
  23948. } catch (er) {
  23949. errorHandler(me.getLang('autoupload.loadError'))
  23950. }
  23951. })
  23952. xhr.send(fd)
  23953. }
  23954. function getPasteImage(e) {
  23955. return e.clipboardData &&
  23956. e.clipboardData.items &&
  23957. e.clipboardData.items.length == 1 &&
  23958. /^image\//.test(e.clipboardData.items[0].type)
  23959. ? e.clipboardData.items
  23960. : null
  23961. }
  23962. function getDropImage(e) {
  23963. return e.dataTransfer && e.dataTransfer.files ? e.dataTransfer.files : null
  23964. }
  23965. return {
  23966. outputRule: function (root) {
  23967. utils.each(root.getNodesByTagName('img'), function (n) {
  23968. if (/\b(loaderrorclass)|(bloaderrorclass)\b/.test(n.getAttr('class'))) {
  23969. n.parentNode.removeChild(n)
  23970. }
  23971. })
  23972. utils.each(root.getNodesByTagName('p'), function (n) {
  23973. if (/\bloadpara\b/.test(n.getAttr('class'))) {
  23974. n.parentNode.removeChild(n)
  23975. }
  23976. })
  23977. },
  23978. bindEvents: {
  23979. //插入粘贴板的图片,拖放插入图片
  23980. ready: function (e) {
  23981. var me = this
  23982. if (window.FormData && window.FileReader) {
  23983. domUtils.on(me.body, 'paste drop', function (e) {
  23984. var hasImg = false,
  23985. items
  23986. //获取粘贴板文件列表或者拖放文件列表
  23987. items = e.type == 'paste' ? getPasteImage(e) : getDropImage(e)
  23988. if (items) {
  23989. var len = items.length,
  23990. file
  23991. while (len--) {
  23992. file = items[len]
  23993. if (file.getAsFile) file = file.getAsFile()
  23994. if (file && file.size > 0) {
  23995. sendAndInsertFile(file, me)
  23996. hasImg = true
  23997. }
  23998. }
  23999. hasImg && e.preventDefault()
  24000. }
  24001. })
  24002. //取消拖放图片时出现的文字光标位置提示
  24003. domUtils.on(me.body, 'dragover', function (e) {
  24004. if (e.dataTransfer.types[0] == 'Files') {
  24005. e.preventDefault()
  24006. }
  24007. })
  24008. //设置loading的样式
  24009. utils.cssRule(
  24010. 'loading',
  24011. ".loadingclass{display:inline-block;cursor:default;background: url('" +
  24012. this.options.themePath +
  24013. this.options.theme +
  24014. "/images/loading.gif') no-repeat center center transparent;border:1px solid #cccccc;margin-left:1px;height: 22px;width: 22px;}\n" +
  24015. ".loaderrorclass{display:inline-block;cursor:default;background: url('" +
  24016. this.options.themePath +
  24017. this.options.theme +
  24018. "/images/loaderror.png') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;" +
  24019. '}',
  24020. this.document
  24021. )
  24022. }
  24023. }
  24024. }
  24025. }
  24026. })
  24027. // plugins/autosave.js
  24028. UE.plugin.register('autosave', function () {
  24029. var me = this,
  24030. //无限循环保护
  24031. lastSaveTime = new Date(),
  24032. //最小保存间隔时间
  24033. MIN_TIME = 20,
  24034. //auto save key
  24035. saveKey = null
  24036. function save(editor) {
  24037. var saveData
  24038. if (new Date() - lastSaveTime < MIN_TIME) {
  24039. return
  24040. }
  24041. if (!editor.hasContents()) {
  24042. //这里不能调用命令来删除, 会造成事件死循环
  24043. saveKey && me.removePreferences(saveKey)
  24044. return
  24045. }
  24046. lastSaveTime = new Date()
  24047. editor._saveFlag = null
  24048. saveData = me.body.innerHTML
  24049. if (
  24050. editor.fireEvent('beforeautosave', {
  24051. content: saveData
  24052. }) === false
  24053. ) {
  24054. return
  24055. }
  24056. me.setPreferences(saveKey, saveData)
  24057. editor.fireEvent('afterautosave', {
  24058. content: saveData
  24059. })
  24060. }
  24061. return {
  24062. defaultOptions: {
  24063. //默认间隔时间
  24064. saveInterval: 500,
  24065. enableAutoSave: true // HaoChuan9421
  24066. },
  24067. bindEvents: {
  24068. ready: function () {
  24069. var _suffix = '-drafts-data',
  24070. key = null
  24071. if (me.key) {
  24072. key = me.key + _suffix
  24073. } else {
  24074. key = (me.container.parentNode.id || 'ue-common') + _suffix
  24075. }
  24076. //页面地址+编辑器ID 保持唯一
  24077. saveKey =
  24078. (location.protocol + location.host + location.pathname).replace(/[.:\/]/g, '_') + key
  24079. },
  24080. contentchange: function () {
  24081. // HaoChuan9421
  24082. if (!me.getOpt('enableAutoSave')) {
  24083. return
  24084. }
  24085. if (!saveKey) {
  24086. return
  24087. }
  24088. if (me._saveFlag) {
  24089. window.clearTimeout(me._saveFlag)
  24090. }
  24091. if (me.options.saveInterval > 0) {
  24092. me._saveFlag = window.setTimeout(function () {
  24093. save(me)
  24094. }, me.options.saveInterval)
  24095. } else {
  24096. save(me)
  24097. }
  24098. }
  24099. },
  24100. commands: {
  24101. clearlocaldata: {
  24102. execCommand: function (cmd, name) {
  24103. if (saveKey && me.getPreferences(saveKey)) {
  24104. me.removePreferences(saveKey)
  24105. }
  24106. },
  24107. notNeedUndo: true,
  24108. ignoreContentChange: true
  24109. },
  24110. getlocaldata: {
  24111. execCommand: function (cmd, name) {
  24112. return saveKey ? me.getPreferences(saveKey) || '' : ''
  24113. },
  24114. notNeedUndo: true,
  24115. ignoreContentChange: true
  24116. },
  24117. drafts: {
  24118. execCommand: function (cmd, name) {
  24119. if (saveKey) {
  24120. me.body.innerHTML = me.getPreferences(saveKey) || '<p>' + domUtils.fillHtml + '</p>'
  24121. me.focus(true)
  24122. }
  24123. },
  24124. queryCommandState: function () {
  24125. return saveKey ? (me.getPreferences(saveKey) === null ? -1 : 0) : -1
  24126. },
  24127. notNeedUndo: true,
  24128. ignoreContentChange: true
  24129. }
  24130. }
  24131. }
  24132. })
  24133. // plugins/charts.js
  24134. UE.plugin.register('charts', function () {
  24135. var me = this
  24136. return {
  24137. bindEvents: {
  24138. chartserror: function () {}
  24139. },
  24140. commands: {
  24141. charts: {
  24142. execCommand: function (cmd, data) {
  24143. var tableNode = domUtils.findParentByTagName(
  24144. this.selection.getRange().startContainer,
  24145. 'table',
  24146. true
  24147. ),
  24148. flagText = [],
  24149. config = {}
  24150. if (!tableNode) {
  24151. return false
  24152. }
  24153. if (!validData(tableNode)) {
  24154. me.fireEvent('chartserror')
  24155. return false
  24156. }
  24157. config.title = data.title || ''
  24158. config.subTitle = data.subTitle || ''
  24159. config.xTitle = data.xTitle || ''
  24160. config.yTitle = data.yTitle || ''
  24161. config.suffix = data.suffix || ''
  24162. config.tip = data.tip || ''
  24163. //数据对齐方式
  24164. config.dataFormat = data.tableDataFormat || ''
  24165. //图表类型
  24166. config.chartType = data.chartType || 0
  24167. for (var key in config) {
  24168. if (!config.hasOwnProperty(key)) {
  24169. continue
  24170. }
  24171. flagText.push(key + ':' + config[key])
  24172. }
  24173. tableNode.setAttribute('data-chart', flagText.join(';'))
  24174. domUtils.addClass(tableNode, 'edui-charts-table')
  24175. },
  24176. queryCommandState: function (cmd, name) {
  24177. var tableNode = domUtils.findParentByTagName(
  24178. this.selection.getRange().startContainer,
  24179. 'table',
  24180. true
  24181. )
  24182. return tableNode && validData(tableNode) ? 0 : -1
  24183. }
  24184. }
  24185. },
  24186. inputRule: function (root) {
  24187. utils.each(root.getNodesByTagName('table'), function (tableNode) {
  24188. if (tableNode.getAttr('data-chart') !== undefined) {
  24189. tableNode.setAttr('style')
  24190. }
  24191. })
  24192. },
  24193. outputRule: function (root) {
  24194. utils.each(root.getNodesByTagName('table'), function (tableNode) {
  24195. if (tableNode.getAttr('data-chart') !== undefined) {
  24196. tableNode.setAttr('style', 'display: none;')
  24197. }
  24198. })
  24199. }
  24200. }
  24201. function validData(table) {
  24202. var firstRows = null,
  24203. cellCount = 0
  24204. //行数不够
  24205. if (table.rows.length < 2) {
  24206. return false
  24207. }
  24208. //列数不够
  24209. if (table.rows[0].cells.length < 2) {
  24210. return false
  24211. }
  24212. //第一行所有cell必须是th
  24213. firstRows = table.rows[0].cells
  24214. cellCount = firstRows.length
  24215. for (var i = 0, cell; (cell = firstRows[i]); i++) {
  24216. if (cell.tagName.toLowerCase() !== 'th') {
  24217. return false
  24218. }
  24219. }
  24220. for (var i = 1, row; (row = table.rows[i]); i++) {
  24221. //每行单元格数不匹配, 返回false
  24222. if (row.cells.length != cellCount) {
  24223. return false
  24224. }
  24225. //第一列不是th也返回false
  24226. if (row.cells[0].tagName.toLowerCase() !== 'th') {
  24227. return false
  24228. }
  24229. for (var j = 1, cell; (cell = row.cells[j]); j++) {
  24230. var value = utils.trim(cell.innerText || cell.textContent || '')
  24231. value = value
  24232. .replace(new RegExp(UE.dom.domUtils.fillChar, 'g'), '')
  24233. .replace(/^\s+|\s+$/g, '')
  24234. //必须是数字
  24235. if (!/^\d*\.?\d+$/.test(value)) {
  24236. return false
  24237. }
  24238. }
  24239. }
  24240. return true
  24241. }
  24242. })
  24243. // plugins/section.js
  24244. /**
  24245. * 目录大纲支持插件
  24246. * @file
  24247. * @since 1.3.0
  24248. */
  24249. UE.plugin.register('section', function () {
  24250. /* 目录节点对象 */
  24251. function Section(option) {
  24252. this.tag = ''
  24253. ;(this.level = -1), (this.dom = null)
  24254. this.nextSection = null
  24255. this.previousSection = null
  24256. this.parentSection = null
  24257. this.startAddress = []
  24258. this.endAddress = []
  24259. this.children = []
  24260. }
  24261. function getSection(option) {
  24262. var section = new Section()
  24263. return utils.extend(section, option)
  24264. }
  24265. function getNodeFromAddress(startAddress, root) {
  24266. var current = root
  24267. for (var i = 0; i < startAddress.length; i++) {
  24268. if (!current.childNodes) return null
  24269. current = current.childNodes[startAddress[i]]
  24270. }
  24271. return current
  24272. }
  24273. var me = this
  24274. return {
  24275. bindMultiEvents: {
  24276. type: 'aftersetcontent afterscencerestore',
  24277. handler: function () {
  24278. me.fireEvent('updateSections')
  24279. }
  24280. },
  24281. bindEvents: {
  24282. /* 初始化、拖拽、粘贴、执行setcontent之后 */
  24283. ready: function () {
  24284. me.fireEvent('updateSections')
  24285. domUtils.on(me.body, 'drop paste', function () {
  24286. me.fireEvent('updateSections')
  24287. })
  24288. },
  24289. /* 执行paragraph命令之后 */
  24290. afterexeccommand: function (type, cmd) {
  24291. if (cmd == 'paragraph') {
  24292. me.fireEvent('updateSections')
  24293. }
  24294. },
  24295. /* 部分键盘操作,触发updateSections事件 */
  24296. keyup: function (type, e) {
  24297. var me = this,
  24298. range = me.selection.getRange()
  24299. if (range.collapsed != true) {
  24300. me.fireEvent('updateSections')
  24301. } else {
  24302. var keyCode = e.keyCode || e.which
  24303. if (keyCode == 13 || keyCode == 8 || keyCode == 46) {
  24304. me.fireEvent('updateSections')
  24305. }
  24306. }
  24307. }
  24308. },
  24309. commands: {
  24310. getsections: {
  24311. execCommand: function (cmd, levels) {
  24312. var levelFn = levels || ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']
  24313. for (var i = 0; i < levelFn.length; i++) {
  24314. if (typeof levelFn[i] == 'string') {
  24315. levelFn[i] = (function (fn) {
  24316. return function (node) {
  24317. return node.tagName == fn.toUpperCase()
  24318. }
  24319. })(levelFn[i])
  24320. } else if (typeof levelFn[i] != 'function') {
  24321. levelFn[i] = function (node) {
  24322. return null
  24323. }
  24324. }
  24325. }
  24326. function getSectionLevel(node) {
  24327. for (var i = 0; i < levelFn.length; i++) {
  24328. if (levelFn[i](node)) return i
  24329. }
  24330. return -1
  24331. }
  24332. var me = this,
  24333. Directory = getSection({ level: -1, title: 'root' }),
  24334. previous = Directory
  24335. function traversal(node, Directory) {
  24336. var level,
  24337. tmpSection = null,
  24338. parent,
  24339. child,
  24340. children = node.childNodes
  24341. for (var i = 0, len = children.length; i < len; i++) {
  24342. child = children[i]
  24343. level = getSectionLevel(child)
  24344. if (level >= 0) {
  24345. var address = me.selection
  24346. .getRange()
  24347. .selectNode(child)
  24348. .createAddress(true).startAddress,
  24349. current = getSection({
  24350. tag: child.tagName,
  24351. title: child.innerText || child.textContent || '',
  24352. level: level,
  24353. dom: child,
  24354. startAddress: utils.clone(address, []),
  24355. endAddress: utils.clone(address, []),
  24356. children: []
  24357. })
  24358. previous.nextSection = current
  24359. current.previousSection = previous
  24360. parent = previous
  24361. while (level <= parent.level) {
  24362. parent = parent.parentSection
  24363. }
  24364. current.parentSection = parent
  24365. parent.children.push(current)
  24366. tmpSection = previous = current
  24367. } else {
  24368. child.nodeType === 1 && traversal(child, Directory)
  24369. tmpSection && tmpSection.endAddress[tmpSection.endAddress.length - 1]++
  24370. }
  24371. }
  24372. }
  24373. traversal(me.body, Directory)
  24374. return Directory
  24375. },
  24376. notNeedUndo: true
  24377. },
  24378. movesection: {
  24379. execCommand: function (cmd, sourceSection, targetSection, isAfter) {
  24380. var me = this,
  24381. targetAddress,
  24382. target
  24383. if (!sourceSection || !targetSection || targetSection.level == -1) return
  24384. targetAddress = isAfter ? targetSection.endAddress : targetSection.startAddress
  24385. target = getNodeFromAddress(targetAddress, me.body)
  24386. /* 判断目标地址是否被源章节包含 */
  24387. if (
  24388. !targetAddress ||
  24389. !target ||
  24390. isContainsAddress(sourceSection.startAddress, sourceSection.endAddress, targetAddress)
  24391. )
  24392. return
  24393. var startNode = getNodeFromAddress(sourceSection.startAddress, me.body),
  24394. endNode = getNodeFromAddress(sourceSection.endAddress, me.body),
  24395. current,
  24396. nextNode
  24397. if (isAfter) {
  24398. current = endNode
  24399. while (
  24400. current &&
  24401. !(domUtils.getPosition(startNode, current) & domUtils.POSITION_FOLLOWING)
  24402. ) {
  24403. nextNode = current.previousSibling
  24404. domUtils.insertAfter(target, current)
  24405. if (current == startNode) break
  24406. current = nextNode
  24407. }
  24408. } else {
  24409. current = startNode
  24410. while (
  24411. current &&
  24412. !(domUtils.getPosition(current, endNode) & domUtils.POSITION_FOLLOWING)
  24413. ) {
  24414. nextNode = current.nextSibling
  24415. target.parentNode.insertBefore(current, target)
  24416. if (current == endNode) break
  24417. current = nextNode
  24418. }
  24419. }
  24420. me.fireEvent('updateSections')
  24421. /* 获取地址的包含关系 */
  24422. function isContainsAddress(startAddress, endAddress, addressTarget) {
  24423. var isAfterStartAddress = false,
  24424. isBeforeEndAddress = false
  24425. for (var i = 0; i < startAddress.length; i++) {
  24426. if (i >= addressTarget.length) break
  24427. if (addressTarget[i] > startAddress[i]) {
  24428. isAfterStartAddress = true
  24429. break
  24430. } else if (addressTarget[i] < startAddress[i]) {
  24431. break
  24432. }
  24433. }
  24434. for (var i = 0; i < endAddress.length; i++) {
  24435. if (i >= addressTarget.length) break
  24436. if (addressTarget[i] < startAddress[i]) {
  24437. isBeforeEndAddress = true
  24438. break
  24439. } else if (addressTarget[i] > startAddress[i]) {
  24440. break
  24441. }
  24442. }
  24443. return isAfterStartAddress && isBeforeEndAddress
  24444. }
  24445. }
  24446. },
  24447. deletesection: {
  24448. execCommand: function (cmd, section, keepChildren) {
  24449. var me = this
  24450. if (!section) return
  24451. function getNodeFromAddress(startAddress) {
  24452. var current = me.body
  24453. for (var i = 0; i < startAddress.length; i++) {
  24454. if (!current.childNodes) return null
  24455. current = current.childNodes[startAddress[i]]
  24456. }
  24457. return current
  24458. }
  24459. var startNode = getNodeFromAddress(section.startAddress),
  24460. endNode = getNodeFromAddress(section.endAddress),
  24461. current = startNode,
  24462. nextNode
  24463. if (!keepChildren) {
  24464. while (
  24465. current &&
  24466. domUtils.inDoc(endNode, me.document) &&
  24467. !(domUtils.getPosition(current, endNode) & domUtils.POSITION_FOLLOWING)
  24468. ) {
  24469. nextNode = current.nextSibling
  24470. domUtils.remove(current)
  24471. current = nextNode
  24472. }
  24473. } else {
  24474. domUtils.remove(current)
  24475. }
  24476. me.fireEvent('updateSections')
  24477. }
  24478. },
  24479. selectsection: {
  24480. execCommand: function (cmd, section) {
  24481. if (!section && !section.dom) return false
  24482. var me = this,
  24483. range = me.selection.getRange(),
  24484. address = {
  24485. startAddress: utils.clone(section.startAddress, []),
  24486. endAddress: utils.clone(section.endAddress, [])
  24487. }
  24488. address.endAddress[address.endAddress.length - 1]++
  24489. range.moveToAddress(address).select().scrollToView()
  24490. return true
  24491. },
  24492. notNeedUndo: true
  24493. },
  24494. scrolltosection: {
  24495. execCommand: function (cmd, section) {
  24496. if (!section && !section.dom) return false
  24497. var me = this,
  24498. range = me.selection.getRange(),
  24499. address = {
  24500. startAddress: section.startAddress,
  24501. endAddress: section.endAddress
  24502. }
  24503. address.endAddress[address.endAddress.length - 1]++
  24504. range.moveToAddress(address).scrollToView()
  24505. return true
  24506. },
  24507. notNeedUndo: true
  24508. }
  24509. }
  24510. }
  24511. })
  24512. // plugins/simpleupload.js
  24513. /**
  24514. * @description
  24515. * 简单上传:点击按钮,直接选择文件上传。
  24516. * 原 UEditor 作者使用了 form 表单 + iframe 的方式上传
  24517. * 但由于同源策略的限制,父页面无法访问跨域的 iframe 内容
  24518. * 导致无法获取接口返回的数据,使得单图上传无法在跨域的情况下使用
  24519. * 这里改为普通的XHR上传,兼容到IE10+
  24520. * @author HaoChuan9421 <hc199421@gmail.com>
  24521. * @date 2018-12-20
  24522. */
  24523. UE.plugin.register('simpleupload', function () {
  24524. var me = this,
  24525. containerBtn,
  24526. timestrap = (+new Date()).toString(36)
  24527. function initUploadBtn() {
  24528. var w = containerBtn.offsetWidth || 20,
  24529. h = containerBtn.offsetHeight || 20,
  24530. btnStyle =
  24531. 'display:block;width:' +
  24532. w +
  24533. 'px;height:' +
  24534. h +
  24535. 'px;overflow:hidden;border:0;margin:0;padding:0;position:absolute;top:0;left:0;filter:alpha(opacity=0);-moz-opacity:0;-khtml-opacity: 0;opacity: 0;cursor:pointer;'
  24536. var form = document.createElement('form')
  24537. var input = document.createElement('input')
  24538. form.id = 'edui_form_' + timestrap
  24539. form.enctype = 'multipart/form-data'
  24540. form.style = btnStyle
  24541. input.id = 'edui_input_' + timestrap
  24542. input.type = 'file'
  24543. input.accept = 'image/*'
  24544. input.name = me.options.imageFieldName
  24545. input.style = btnStyle
  24546. form.appendChild(input)
  24547. containerBtn.appendChild(form)
  24548. input.addEventListener('change', function (event) {
  24549. if (!input.value) return
  24550. var loadingId = 'loading_' + (+new Date()).toString(36)
  24551. var imageActionUrl = me.getActionUrl(me.getOpt('imageActionName'))
  24552. var params = utils.serializeParam(me.queryCommandValue('serverparam')) || ''
  24553. var action = utils.formatUrl(
  24554. imageActionUrl + (imageActionUrl.indexOf('?') == -1 ? '?' : '&') + params
  24555. )
  24556. var allowFiles = me.getOpt('imageAllowFiles')
  24557. console.log(action, 'action', 'allowFiles', allowFiles)
  24558. me.focus()
  24559. me.execCommand(
  24560. 'inserthtml',
  24561. '<img class="loadingclass" id="' +
  24562. loadingId +
  24563. '" src="' +
  24564. me.options.themePath +
  24565. me.options.theme +
  24566. '/images/spacer.gif" title="' +
  24567. (me.getLang('simpleupload.loading') || '') +
  24568. '" >'
  24569. )
  24570. function showErrorLoader(title) {
  24571. if (loadingId) {
  24572. var loader = me.document.getElementById(loadingId)
  24573. loader && domUtils.remove(loader)
  24574. me.fireEvent('showmessage', {
  24575. id: loadingId,
  24576. content: title,
  24577. type: 'error',
  24578. timeout: 4000
  24579. })
  24580. }
  24581. }
  24582. /* 判断后端配置是否没有加载成功 */
  24583. if (!me.getOpt('imageActionName')) {
  24584. showErrorLoader(me.getLang('autoupload.errorLoadConfig'))
  24585. return
  24586. }
  24587. // 判断文件格式是否错误
  24588. var filename = input.value,
  24589. fileext = filename ? filename.substr(filename.lastIndexOf('.')) : ''
  24590. if (
  24591. !fileext ||
  24592. (allowFiles && (allowFiles.join('') + '.').indexOf(fileext.toLowerCase() + '.') == -1)
  24593. ) {
  24594. showErrorLoader(me.getLang('simpleupload.exceedTypeError'))
  24595. return
  24596. }
  24597. console.log('filename', input.value)
  24598. console.log('准备上传action', action, input)
  24599. let formData = new FormData()
  24600. let files = input.files[0]
  24601. formData.append('file', files)
  24602. var xhr = new XMLHttpRequest()
  24603. // xhr.setRequestHeader('Content-Type', 'multipart/form-data')
  24604. xhr.open('post', action, true)
  24605. xhr.send(formData)
  24606. if (
  24607. me.options.headers &&
  24608. Object.prototype.toString.apply(me.options.headers) === '[object Object]'
  24609. ) {
  24610. for (var key in me.options.headers) {
  24611. xhr.setRequestHeader(key, me.options.headers[key])
  24612. }
  24613. }
  24614. xhr.onload = function () {
  24615. if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304) {
  24616. var res = JSON.parse(xhr.responseText)
  24617. var link = res.data.url
  24618. if (res.code == 200 && res.data.url) {
  24619. loader = me.document.getElementById(loadingId)
  24620. loader.setAttribute('src', link)
  24621. loader.setAttribute('_src', link)
  24622. loader.setAttribute('title', res.title || '')
  24623. loader.setAttribute('alt', res.original || '')
  24624. loader.removeAttribute('id')
  24625. domUtils.removeClasses(loader, 'loadingclass')
  24626. me.fireEvent('contentchange')
  24627. } else {
  24628. showErrorLoader(res.state)
  24629. }
  24630. } else {
  24631. console.log('请求失败')
  24632. showErrorLoader(me.getLang('simpleupload.loadError'))
  24633. }
  24634. }
  24635. xhr.onerror = function () {
  24636. console.log('请求失败onerror')
  24637. showErrorLoader(me.getLang('simpleupload.loadError'))
  24638. }
  24639. form.reset()
  24640. })
  24641. }
  24642. return {
  24643. bindEvents: {
  24644. ready: function () {
  24645. //设置loading的样式
  24646. utils.cssRule(
  24647. 'loading',
  24648. ".loadingclass{display:inline-block;cursor:default;background: url('" +
  24649. this.options.themePath +
  24650. this.options.theme +
  24651. "/images/loading.gif') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;}\n" +
  24652. ".loaderrorclass{display:inline-block;cursor:default;background: url('" +
  24653. this.options.themePath +
  24654. this.options.theme +
  24655. "/images/loaderror.png') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;" +
  24656. '}',
  24657. this.document
  24658. )
  24659. },
  24660. /* 初始化简单上传按钮 */
  24661. simpleuploadbtnready: function (type, container) {
  24662. containerBtn = container
  24663. me.afterConfigReady(initUploadBtn)
  24664. }
  24665. },
  24666. outputRule: function (root) {
  24667. utils.each(root.getNodesByTagName('img'), function (n) {
  24668. if (/\b(loaderrorclass)|(bloaderrorclass)\b/.test(n.getAttr('class'))) {
  24669. n.parentNode.removeChild(n)
  24670. }
  24671. })
  24672. }
  24673. }
  24674. })
  24675. // plugins/serverparam.js
  24676. /**
  24677. * 服务器提交的额外参数列表设置插件
  24678. * @file
  24679. * @since 1.2.6.1
  24680. */
  24681. UE.plugin.register('serverparam', function () {
  24682. var me = this,
  24683. serverParam = {}
  24684. return {
  24685. commands: {
  24686. /**
  24687. * 修改服务器提交的额外参数列表,清除所有项
  24688. * @command serverparam
  24689. * @method execCommand
  24690. * @param { String } cmd 命令字符串
  24691. * @example
  24692. * ```javascript
  24693. * editor.execCommand('serverparam');
  24694. * editor.queryCommandValue('serverparam'); //返回空
  24695. * ```
  24696. */
  24697. /**
  24698. * 修改服务器提交的额外参数列表,删除指定项
  24699. * @command serverparam
  24700. * @method execCommand
  24701. * @param { String } cmd 命令字符串
  24702. * @param { String } key 要清除的属性
  24703. * @example
  24704. * ```javascript
  24705. * editor.execCommand('serverparam', 'name'); //删除属性name
  24706. * ```
  24707. */
  24708. /**
  24709. * 修改服务器提交的额外参数列表,使用键值添加项
  24710. * @command serverparam
  24711. * @method execCommand
  24712. * @param { String } cmd 命令字符串
  24713. * @param { String } key 要添加的属性
  24714. * @param { String } value 要添加属性的值
  24715. * @example
  24716. * ```javascript
  24717. * editor.execCommand('serverparam', 'name', 'hello');
  24718. * editor.queryCommandValue('serverparam'); //返回对象 {'name': 'hello'}
  24719. * ```
  24720. */
  24721. /**
  24722. * 修改服务器提交的额外参数列表,传入键值对对象添加多项
  24723. * @command serverparam
  24724. * @method execCommand
  24725. * @param { String } cmd 命令字符串
  24726. * @param { Object } key 传入的键值对对象
  24727. * @example
  24728. * ```javascript
  24729. * editor.execCommand('serverparam', {'name': 'hello'});
  24730. * editor.queryCommandValue('serverparam'); //返回对象 {'name': 'hello'}
  24731. * ```
  24732. */
  24733. /**
  24734. * 修改服务器提交的额外参数列表,使用自定义函数添加多项
  24735. * @command serverparam
  24736. * @method execCommand
  24737. * @param { String } cmd 命令字符串
  24738. * @param { Function } key 自定义获取参数的函数
  24739. * @example
  24740. * ```javascript
  24741. * editor.execCommand('serverparam', function(editor){
  24742. * return {'key': 'value'};
  24743. * });
  24744. * editor.queryCommandValue('serverparam'); //返回对象 {'key': 'value'}
  24745. * ```
  24746. */
  24747. /**
  24748. * 获取服务器提交的额外参数列表
  24749. * @command serverparam
  24750. * @method queryCommandValue
  24751. * @param { String } cmd 命令字符串
  24752. * @example
  24753. * ```javascript
  24754. * editor.queryCommandValue( 'serverparam' ); //返回对象 {'key': 'value'}
  24755. * ```
  24756. */
  24757. serverparam: {
  24758. execCommand: function (cmd, key, value) {
  24759. if (key === undefined || key === null) {
  24760. //不传参数,清空列表
  24761. serverParam = {}
  24762. } else if (utils.isString(key)) {
  24763. //传入键值
  24764. if (value === undefined || value === null) {
  24765. delete serverParam[key]
  24766. } else {
  24767. serverParam[key] = value
  24768. }
  24769. } else if (utils.isObject(key)) {
  24770. //传入对象,覆盖列表项
  24771. utils.extend(serverParam, key, true)
  24772. } else if (utils.isFunction(key)) {
  24773. //传入函数,添加列表项
  24774. utils.extend(serverParam, key(), true)
  24775. }
  24776. },
  24777. queryCommandValue: function () {
  24778. return serverParam || {}
  24779. }
  24780. }
  24781. }
  24782. }
  24783. })
  24784. // plugins/insertfile.js
  24785. /**
  24786. * 插入附件
  24787. */
  24788. UE.plugin.register('insertfile', function () {
  24789. var me = this
  24790. function getFileIcon(url) {
  24791. var ext = url.substr(url.lastIndexOf('.') + 1).toLowerCase(),
  24792. maps = {
  24793. rar: 'icon_rar.gif',
  24794. zip: 'icon_rar.gif',
  24795. tar: 'icon_rar.gif',
  24796. gz: 'icon_rar.gif',
  24797. bz2: 'icon_rar.gif',
  24798. doc: 'icon_doc.gif',
  24799. docx: 'icon_doc.gif',
  24800. pdf: 'icon_pdf.gif',
  24801. mp3: 'icon_mp3.gif',
  24802. xls: 'icon_xls.gif',
  24803. chm: 'icon_chm.gif',
  24804. ppt: 'icon_ppt.gif',
  24805. pptx: 'icon_ppt.gif',
  24806. avi: 'icon_mv.gif',
  24807. rmvb: 'icon_mv.gif',
  24808. wmv: 'icon_mv.gif',
  24809. flv: 'icon_mv.gif',
  24810. swf: 'icon_mv.gif',
  24811. rm: 'icon_mv.gif',
  24812. exe: 'icon_exe.gif',
  24813. psd: 'icon_psd.gif',
  24814. txt: 'icon_txt.gif',
  24815. jpg: 'icon_jpg.gif',
  24816. png: 'icon_jpg.gif',
  24817. jpeg: 'icon_jpg.gif',
  24818. gif: 'icon_jpg.gif',
  24819. ico: 'icon_jpg.gif',
  24820. bmp: 'icon_jpg.gif'
  24821. }
  24822. return maps[ext] ? maps[ext] : maps['txt']
  24823. }
  24824. return {
  24825. commands: {
  24826. insertfile: {
  24827. execCommand: function (command, filelist) {
  24828. filelist = utils.isArray(filelist) ? filelist : [filelist]
  24829. var i,
  24830. item,
  24831. icon,
  24832. title,
  24833. html = '',
  24834. URL = me.getOpt('UEDITOR_HOME_URL'),
  24835. iconDir =
  24836. URL +
  24837. (URL.substr(URL.length - 1) == '/' ? '' : '/') +
  24838. 'dialogs/attachment/fileTypeImages/'
  24839. for (i = 0; i < filelist.length; i++) {
  24840. item = filelist[i]
  24841. icon = iconDir + getFileIcon(item.url)
  24842. title = item.title || item.url.substr(item.url.lastIndexOf('/') + 1)
  24843. html +=
  24844. '<p style="line-height: 16px;">' +
  24845. '<img style="vertical-align: middle; margin-right: 2px;" src="' +
  24846. icon +
  24847. '" _src="' +
  24848. icon +
  24849. '" />' +
  24850. '<a style="font-size:12px; color:#0066cc;" href="' +
  24851. item.url +
  24852. '" title="' +
  24853. title +
  24854. '">' +
  24855. title +
  24856. '</a>' +
  24857. '</p>'
  24858. }
  24859. me.execCommand('insertHtml', html)
  24860. }
  24861. }
  24862. }
  24863. }
  24864. })
  24865. // plugins/xssFilter.js
  24866. /**
  24867. * @file xssFilter.js
  24868. * @desc xss过滤器
  24869. * @author robbenmu
  24870. */
  24871. UE.plugins.xssFilter = function () {
  24872. var config = UEDITOR_CONFIG
  24873. var whitList = config.whitList
  24874. function filter(node) {
  24875. var tagName = node.tagName
  24876. var attrs = node.attrs
  24877. if (!whitList.hasOwnProperty(tagName)) {
  24878. node.parentNode.removeChild(node)
  24879. return false
  24880. }
  24881. UE.utils.each(attrs, function (val, key) {
  24882. if (whitList[tagName].indexOf(key) === -1) {
  24883. node.setAttr(key)
  24884. }
  24885. })
  24886. }
  24887. // 添加inserthtml\paste等操作用的过滤规则
  24888. if (whitList && config.xssFilterRules) {
  24889. this.options.filterRules = (function () {
  24890. var result = {}
  24891. UE.utils.each(whitList, function (val, key) {
  24892. result[key] = function (node) {
  24893. return filter(node)
  24894. }
  24895. })
  24896. return result
  24897. })()
  24898. }
  24899. var tagList = []
  24900. UE.utils.each(whitList, function (val, key) {
  24901. tagList.push(key)
  24902. })
  24903. // 添加input过滤规则
  24904. //
  24905. if (whitList && config.inputXssFilter) {
  24906. this.addInputRule(function (root) {
  24907. root.traversal(function (node) {
  24908. if (node.type !== 'element') {
  24909. return false
  24910. }
  24911. filter(node)
  24912. })
  24913. })
  24914. }
  24915. // 添加output过滤规则
  24916. //
  24917. if (whitList && config.outputXssFilter) {
  24918. this.addOutputRule(function (root) {
  24919. root.traversal(function (node) {
  24920. if (node.type !== 'element') {
  24921. return false
  24922. }
  24923. filter(node)
  24924. })
  24925. })
  24926. }
  24927. }
  24928. // ui/ui.js
  24929. var baidu = baidu || {}
  24930. baidu.editor = baidu.editor || {}
  24931. UE.ui = baidu.editor.ui = {}
  24932. // ui/uiutils.js
  24933. ;(function () {
  24934. var browser = baidu.editor.browser,
  24935. domUtils = baidu.editor.dom.domUtils
  24936. var magic = '$EDITORUI'
  24937. var root = (window[magic] = {})
  24938. var uidMagic = 'ID' + magic
  24939. var uidCount = 0
  24940. var uiUtils = (baidu.editor.ui.uiUtils = {
  24941. uid: function (obj) {
  24942. return obj ? obj[uidMagic] || (obj[uidMagic] = ++uidCount) : ++uidCount
  24943. },
  24944. hook: function (fn, callback) {
  24945. var dg
  24946. if (fn && fn._callbacks) {
  24947. dg = fn
  24948. } else {
  24949. dg = function () {
  24950. var q
  24951. if (fn) {
  24952. q = fn.apply(this, arguments)
  24953. }
  24954. var callbacks = dg._callbacks
  24955. var k = callbacks.length
  24956. while (k--) {
  24957. var r = callbacks[k].apply(this, arguments)
  24958. if (q === undefined) {
  24959. q = r
  24960. }
  24961. }
  24962. return q
  24963. }
  24964. dg._callbacks = []
  24965. }
  24966. dg._callbacks.push(callback)
  24967. return dg
  24968. },
  24969. createElementByHtml: function (html) {
  24970. var el = document.createElement('div')
  24971. el.innerHTML = html
  24972. el = el.firstChild
  24973. el.parentNode.removeChild(el)
  24974. return el
  24975. },
  24976. getViewportElement: function () {
  24977. return browser.ie && browser.quirks ? document.body : document.documentElement
  24978. },
  24979. getClientRect: function (element) {
  24980. var bcr
  24981. //trace IE6下在控制编辑器显隐时可能会报错,catch一下
  24982. try {
  24983. bcr = element.getBoundingClientRect()
  24984. } catch (e) {
  24985. bcr = { left: 0, top: 0, height: 0, width: 0 }
  24986. }
  24987. var rect = {
  24988. left: Math.round(bcr.left),
  24989. top: Math.round(bcr.top),
  24990. height: Math.round(bcr.bottom - bcr.top),
  24991. width: Math.round(bcr.right - bcr.left)
  24992. }
  24993. var doc
  24994. while (
  24995. (doc = element.ownerDocument) !== document &&
  24996. (element = domUtils.getWindow(doc).frameElement)
  24997. ) {
  24998. bcr = element.getBoundingClientRect()
  24999. rect.left += bcr.left
  25000. rect.top += bcr.top
  25001. }
  25002. rect.bottom = rect.top + rect.height
  25003. rect.right = rect.left + rect.width
  25004. return rect
  25005. },
  25006. getViewportRect: function () {
  25007. var viewportEl = uiUtils.getViewportElement()
  25008. var width = (window.innerWidth || viewportEl.clientWidth) | 0
  25009. var height = (window.innerHeight || viewportEl.clientHeight) | 0
  25010. return {
  25011. left: 0,
  25012. top: 0,
  25013. height: height,
  25014. width: width,
  25015. bottom: height,
  25016. right: width
  25017. }
  25018. },
  25019. setViewportOffset: function (element, offset) {
  25020. var rect
  25021. var fixedLayer = uiUtils.getFixedLayer()
  25022. if (element.parentNode === fixedLayer) {
  25023. element.style.left = offset.left + 'px'
  25024. element.style.top = offset.top + 'px'
  25025. } else {
  25026. domUtils.setViewportOffset(element, offset)
  25027. }
  25028. },
  25029. getEventOffset: function (evt) {
  25030. var el = evt.target || evt.srcElement
  25031. var rect = uiUtils.getClientRect(el)
  25032. var offset = uiUtils.getViewportOffsetByEvent(evt)
  25033. return {
  25034. left: offset.left - rect.left,
  25035. top: offset.top - rect.top
  25036. }
  25037. },
  25038. getViewportOffsetByEvent: function (evt) {
  25039. var el = evt.target || evt.srcElement
  25040. var frameEl = domUtils.getWindow(el).frameElement
  25041. var offset = {
  25042. left: evt.clientX,
  25043. top: evt.clientY
  25044. }
  25045. if (frameEl && el.ownerDocument !== document) {
  25046. var rect = uiUtils.getClientRect(frameEl)
  25047. offset.left += rect.left
  25048. offset.top += rect.top
  25049. }
  25050. return offset
  25051. },
  25052. setGlobal: function (id, obj) {
  25053. root[id] = obj
  25054. return magic + '["' + id + '"]'
  25055. },
  25056. unsetGlobal: function (id) {
  25057. delete root[id]
  25058. },
  25059. copyAttributes: function (tgt, src) {
  25060. var attributes = src.attributes
  25061. var k = attributes.length
  25062. while (k--) {
  25063. var attrNode = attributes[k]
  25064. if (
  25065. attrNode.nodeName != 'style' &&
  25066. attrNode.nodeName != 'class' &&
  25067. (!browser.ie || attrNode.specified)
  25068. ) {
  25069. tgt.setAttribute(attrNode.nodeName, attrNode.nodeValue)
  25070. }
  25071. }
  25072. if (src.className) {
  25073. domUtils.addClass(tgt, src.className)
  25074. }
  25075. if (src.style.cssText) {
  25076. tgt.style.cssText += ';' + src.style.cssText
  25077. }
  25078. },
  25079. removeStyle: function (el, styleName) {
  25080. if (el.style.removeProperty) {
  25081. el.style.removeProperty(styleName)
  25082. } else if (el.style.removeAttribute) {
  25083. el.style.removeAttribute(styleName)
  25084. } else throw ''
  25085. },
  25086. contains: function (elA, elB) {
  25087. return (
  25088. elA &&
  25089. elB &&
  25090. (elA === elB
  25091. ? false
  25092. : elA.contains
  25093. ? elA.contains(elB)
  25094. : elA.compareDocumentPosition(elB) & 16)
  25095. )
  25096. },
  25097. startDrag: function (evt, callbacks, doc) {
  25098. var doc = doc || document
  25099. var startX = evt.clientX
  25100. var startY = evt.clientY
  25101. function handleMouseMove(evt) {
  25102. var x = evt.clientX - startX
  25103. var y = evt.clientY - startY
  25104. callbacks.ondragmove(x, y, evt)
  25105. if (evt.stopPropagation) {
  25106. evt.stopPropagation()
  25107. } else {
  25108. evt.cancelBubble = true
  25109. }
  25110. }
  25111. if (doc.addEventListener) {
  25112. function handleMouseUp(evt) {
  25113. doc.removeEventListener('mousemove', handleMouseMove, true)
  25114. doc.removeEventListener('mouseup', handleMouseUp, true)
  25115. window.removeEventListener('mouseup', handleMouseUp, true)
  25116. callbacks.ondragstop()
  25117. }
  25118. doc.addEventListener('mousemove', handleMouseMove, true)
  25119. doc.addEventListener('mouseup', handleMouseUp, true)
  25120. window.addEventListener('mouseup', handleMouseUp, true)
  25121. evt.preventDefault()
  25122. } else {
  25123. var elm = evt.srcElement
  25124. elm.setCapture()
  25125. function releaseCaptrue() {
  25126. elm.releaseCapture()
  25127. elm.detachEvent('onmousemove', handleMouseMove)
  25128. elm.detachEvent('onmouseup', releaseCaptrue)
  25129. elm.detachEvent('onlosecaptrue', releaseCaptrue)
  25130. callbacks.ondragstop()
  25131. }
  25132. elm.attachEvent('onmousemove', handleMouseMove)
  25133. elm.attachEvent('onmouseup', releaseCaptrue)
  25134. elm.attachEvent('onlosecaptrue', releaseCaptrue)
  25135. evt.returnValue = false
  25136. }
  25137. callbacks.ondragstart()
  25138. },
  25139. getFixedLayer: function () {
  25140. var layer = document.getElementById('edui_fixedlayer')
  25141. if (layer == null) {
  25142. layer = document.createElement('div')
  25143. layer.id = 'edui_fixedlayer'
  25144. document.body.appendChild(layer)
  25145. if (browser.ie && browser.version <= 8) {
  25146. layer.style.position = 'absolute'
  25147. bindFixedLayer()
  25148. setTimeout(updateFixedOffset)
  25149. } else {
  25150. layer.style.position = 'fixed'
  25151. }
  25152. layer.style.left = '0'
  25153. layer.style.top = '0'
  25154. layer.style.width = '0'
  25155. layer.style.height = '0'
  25156. layer.style.zIndex = '3005'
  25157. }
  25158. return layer
  25159. },
  25160. makeUnselectable: function (element) {
  25161. if (browser.opera || (browser.ie && browser.version < 9)) {
  25162. element.unselectable = 'on'
  25163. if (element.hasChildNodes()) {
  25164. for (var i = 0; i < element.childNodes.length; i++) {
  25165. if (element.childNodes[i].nodeType == 1) {
  25166. uiUtils.makeUnselectable(element.childNodes[i])
  25167. }
  25168. }
  25169. }
  25170. } else {
  25171. if (element.style.MozUserSelect !== undefined) {
  25172. element.style.MozUserSelect = 'none'
  25173. } else if (element.style.WebkitUserSelect !== undefined) {
  25174. element.style.WebkitUserSelect = 'none'
  25175. } else if (element.style.KhtmlUserSelect !== undefined) {
  25176. element.style.KhtmlUserSelect = 'none'
  25177. }
  25178. }
  25179. }
  25180. })
  25181. function updateFixedOffset() {
  25182. var layer = document.getElementById('edui_fixedlayer')
  25183. uiUtils.setViewportOffset(layer, {
  25184. left: 0,
  25185. top: 0
  25186. })
  25187. // layer.style.display = 'none';
  25188. // layer.style.display = 'block';
  25189. //#trace: 1354
  25190. // setTimeout(updateFixedOffset);
  25191. }
  25192. function bindFixedLayer(adjOffset) {
  25193. domUtils.on(window, 'scroll', updateFixedOffset)
  25194. domUtils.on(window, 'resize', baidu.editor.utils.defer(updateFixedOffset, 0, true))
  25195. }
  25196. })()
  25197. // ui/uibase.js
  25198. ;(function () {
  25199. var utils = baidu.editor.utils,
  25200. uiUtils = baidu.editor.ui.uiUtils,
  25201. EventBase = baidu.editor.EventBase,
  25202. UIBase = (baidu.editor.ui.UIBase = function () {})
  25203. UIBase.prototype = {
  25204. className: '',
  25205. uiName: '',
  25206. initOptions: function (options) {
  25207. var me = this
  25208. for (var k in options) {
  25209. me[k] = options[k]
  25210. }
  25211. this.id = this.id || 'edui' + uiUtils.uid()
  25212. },
  25213. initUIBase: function () {
  25214. this._globalKey = utils.unhtml(uiUtils.setGlobal(this.id, this))
  25215. },
  25216. render: function (holder) {
  25217. var html = this.renderHtml()
  25218. var el = uiUtils.createElementByHtml(html)
  25219. //by xuheng 给每个node添加class
  25220. var list = domUtils.getElementsByTagName(el, '*')
  25221. var theme = 'edui-' + (this.theme || this.editor.options.theme)
  25222. var layer = document.getElementById('edui_fixedlayer')
  25223. for (var i = 0, node; (node = list[i++]); ) {
  25224. domUtils.addClass(node, theme)
  25225. }
  25226. domUtils.addClass(el, theme)
  25227. if (layer) {
  25228. layer.className = ''
  25229. domUtils.addClass(layer, theme)
  25230. }
  25231. var seatEl = this.getDom()
  25232. if (seatEl != null) {
  25233. seatEl.parentNode.replaceChild(el, seatEl)
  25234. uiUtils.copyAttributes(el, seatEl)
  25235. } else {
  25236. if (typeof holder == 'string') {
  25237. holder = document.getElementById(holder)
  25238. }
  25239. holder = holder || uiUtils.getFixedLayer()
  25240. domUtils.addClass(holder, theme)
  25241. holder.appendChild(el)
  25242. }
  25243. this.postRender()
  25244. },
  25245. getDom: function (name) {
  25246. if (!name) {
  25247. return document.getElementById(this.id)
  25248. } else {
  25249. return document.getElementById(this.id + '_' + name)
  25250. }
  25251. },
  25252. postRender: function () {
  25253. this.fireEvent('postrender')
  25254. },
  25255. getHtmlTpl: function () {
  25256. return ''
  25257. },
  25258. formatHtml: function (tpl) {
  25259. var prefix = 'edui-' + this.uiName
  25260. return tpl
  25261. .replace(/##/g, this.id)
  25262. .replace(/%%-/g, this.uiName ? prefix + '-' : '')
  25263. .replace(/%%/g, (this.uiName ? prefix : '') + ' ' + this.className)
  25264. .replace(/\$\$/g, this._globalKey)
  25265. },
  25266. renderHtml: function () {
  25267. return this.formatHtml(this.getHtmlTpl())
  25268. },
  25269. dispose: function () {
  25270. var box = this.getDom()
  25271. if (box) baidu.editor.dom.domUtils.remove(box)
  25272. uiUtils.unsetGlobal(this.id)
  25273. }
  25274. }
  25275. utils.inherits(UIBase, EventBase)
  25276. })()
  25277. // ui/separator.js
  25278. ;(function () {
  25279. var utils = baidu.editor.utils,
  25280. UIBase = baidu.editor.ui.UIBase,
  25281. Separator = (baidu.editor.ui.Separator = function (options) {
  25282. this.initOptions(options)
  25283. this.initSeparator()
  25284. })
  25285. Separator.prototype = {
  25286. uiName: 'separator',
  25287. initSeparator: function () {
  25288. this.initUIBase()
  25289. },
  25290. getHtmlTpl: function () {
  25291. return '<div id="##" class="edui-box %%"></div>'
  25292. }
  25293. }
  25294. utils.inherits(Separator, UIBase)
  25295. })()
  25296. // ui/mask.js
  25297. ///import core
  25298. ///import uicore
  25299. ;(function () {
  25300. var utils = baidu.editor.utils,
  25301. domUtils = baidu.editor.dom.domUtils,
  25302. UIBase = baidu.editor.ui.UIBase,
  25303. uiUtils = baidu.editor.ui.uiUtils
  25304. var Mask = (baidu.editor.ui.Mask = function (options) {
  25305. this.initOptions(options)
  25306. this.initUIBase()
  25307. })
  25308. Mask.prototype = {
  25309. getHtmlTpl: function () {
  25310. return '<div id="##" class="edui-mask %%" onclick="return $$._onClick(event, this);" onmousedown="return $$._onMouseDown(event, this);"></div>'
  25311. },
  25312. postRender: function () {
  25313. var me = this
  25314. domUtils.on(window, 'resize', function () {
  25315. setTimeout(function () {
  25316. if (!me.isHidden()) {
  25317. me._fill()
  25318. }
  25319. })
  25320. })
  25321. },
  25322. show: function (zIndex) {
  25323. this._fill()
  25324. this.getDom().style.display = ''
  25325. this.getDom().style.zIndex = zIndex
  25326. },
  25327. hide: function () {
  25328. this.getDom().style.display = 'none'
  25329. this.getDom().style.zIndex = ''
  25330. },
  25331. isHidden: function () {
  25332. return this.getDom().style.display == 'none'
  25333. },
  25334. _onMouseDown: function () {
  25335. return false
  25336. },
  25337. _onClick: function (e, target) {
  25338. this.fireEvent('click', e, target)
  25339. },
  25340. _fill: function () {
  25341. var el = this.getDom()
  25342. var vpRect = uiUtils.getViewportRect()
  25343. el.style.width = vpRect.width + 'px'
  25344. el.style.height = vpRect.height + 'px'
  25345. }
  25346. }
  25347. utils.inherits(Mask, UIBase)
  25348. })()
  25349. // ui/popup.js
  25350. ///import core
  25351. ///import uicore
  25352. ;(function () {
  25353. var utils = baidu.editor.utils,
  25354. uiUtils = baidu.editor.ui.uiUtils,
  25355. domUtils = baidu.editor.dom.domUtils,
  25356. UIBase = baidu.editor.ui.UIBase,
  25357. Popup = (baidu.editor.ui.Popup = function (options) {
  25358. this.initOptions(options)
  25359. this.initPopup()
  25360. })
  25361. var allPopups = []
  25362. function closeAllPopup(evt, el) {
  25363. for (var i = 0; i < allPopups.length; i++) {
  25364. var pop = allPopups[i]
  25365. if (!pop.isHidden()) {
  25366. if (pop.queryAutoHide(el) !== false) {
  25367. if (evt && /scroll/gi.test(evt.type) && pop.className == 'edui-wordpastepop') return
  25368. pop.hide()
  25369. }
  25370. }
  25371. }
  25372. if (allPopups.length) pop.editor.fireEvent('afterhidepop')
  25373. }
  25374. Popup.postHide = closeAllPopup
  25375. var ANCHOR_CLASSES = [
  25376. 'edui-anchor-topleft',
  25377. 'edui-anchor-topright',
  25378. 'edui-anchor-bottomleft',
  25379. 'edui-anchor-bottomright'
  25380. ]
  25381. Popup.prototype = {
  25382. SHADOW_RADIUS: 5,
  25383. content: null,
  25384. _hidden: false,
  25385. autoRender: true,
  25386. canSideLeft: true,
  25387. canSideUp: true,
  25388. initPopup: function () {
  25389. this.initUIBase()
  25390. allPopups.push(this)
  25391. },
  25392. getHtmlTpl: function () {
  25393. return (
  25394. '<div id="##" class="edui-popup %%" onmousedown="return false;">' +
  25395. ' <div id="##_body" class="edui-popup-body">' +
  25396. ' <iframe style="position:absolute;z-index:-1;left:0;top:0;background-color: transparent;" frameborder="0" width="100%" height="100%" src="about:blank"></iframe>' +
  25397. ' <div class="edui-shadow"></div>' +
  25398. ' <div id="##_content" class="edui-popup-content">' +
  25399. this.getContentHtmlTpl() +
  25400. ' </div>' +
  25401. ' </div>' +
  25402. '</div>'
  25403. )
  25404. },
  25405. getContentHtmlTpl: function () {
  25406. if (this.content) {
  25407. if (typeof this.content == 'string') {
  25408. return this.content
  25409. }
  25410. return this.content.renderHtml()
  25411. } else {
  25412. return ''
  25413. }
  25414. },
  25415. _UIBase_postRender: UIBase.prototype.postRender,
  25416. postRender: function () {
  25417. if (this.content instanceof UIBase) {
  25418. this.content.postRender()
  25419. }
  25420. //捕获鼠标滚轮
  25421. if (this.captureWheel && !this.captured) {
  25422. this.captured = true
  25423. var winHeight =
  25424. (document.documentElement.clientHeight || document.body.clientHeight) - 80,
  25425. _height = this.getDom().offsetHeight,
  25426. _top = uiUtils.getClientRect(this.combox.getDom()).top,
  25427. content = this.getDom('content'),
  25428. ifr = this.getDom('body').getElementsByTagName('iframe'),
  25429. me = this
  25430. ifr.length && (ifr = ifr[0])
  25431. while (_top + _height > winHeight) {
  25432. _height -= 30
  25433. }
  25434. content.style.height = _height + 'px'
  25435. //同步更改iframe高度
  25436. ifr && (ifr.style.height = _height + 'px')
  25437. //阻止在combox上的鼠标滚轮事件, 防止用户的正常操作被误解
  25438. if (window.XMLHttpRequest) {
  25439. domUtils.on(
  25440. content,
  25441. 'onmousewheel' in document.body ? 'mousewheel' : 'DOMMouseScroll',
  25442. function (e) {
  25443. if (e.preventDefault) {
  25444. e.preventDefault()
  25445. } else {
  25446. e.returnValue = false
  25447. }
  25448. if (e.wheelDelta) {
  25449. content.scrollTop -= (e.wheelDelta / 120) * 60
  25450. } else {
  25451. content.scrollTop -= (e.detail / -3) * 60
  25452. }
  25453. }
  25454. )
  25455. } else {
  25456. //ie6
  25457. domUtils.on(this.getDom(), 'mousewheel', function (e) {
  25458. e.returnValue = false
  25459. me.getDom('content').scrollTop -= (e.wheelDelta / 120) * 60
  25460. })
  25461. }
  25462. }
  25463. this.fireEvent('postRenderAfter')
  25464. this.hide(true)
  25465. this._UIBase_postRender()
  25466. },
  25467. _doAutoRender: function () {
  25468. if (!this.getDom() && this.autoRender) {
  25469. this.render()
  25470. }
  25471. },
  25472. mesureSize: function () {
  25473. var box = this.getDom('content')
  25474. return uiUtils.getClientRect(box)
  25475. },
  25476. fitSize: function () {
  25477. if (this.captureWheel && this.sized) {
  25478. return this.__size
  25479. }
  25480. this.sized = true
  25481. var popBodyEl = this.getDom('body')
  25482. popBodyEl.style.width = ''
  25483. popBodyEl.style.height = ''
  25484. var size = this.mesureSize()
  25485. if (this.captureWheel) {
  25486. popBodyEl.style.width = -(-20 - size.width) + 'px'
  25487. var height = parseInt(this.getDom('content').style.height, 10)
  25488. !window.isNaN(height) && (size.height = height)
  25489. } else {
  25490. popBodyEl.style.width = size.width + 'px'
  25491. }
  25492. popBodyEl.style.height = size.height + 'px'
  25493. this.__size = size
  25494. this.captureWheel && (this.getDom('content').style.overflow = 'auto')
  25495. return size
  25496. },
  25497. showAnchor: function (element, hoz) {
  25498. this.showAnchorRect(uiUtils.getClientRect(element), hoz)
  25499. },
  25500. showAnchorRect: function (rect, hoz, adj) {
  25501. this._doAutoRender()
  25502. var vpRect = uiUtils.getViewportRect()
  25503. this.getDom().style.visibility = 'hidden'
  25504. this._show()
  25505. var popSize = this.fitSize()
  25506. var sideLeft, sideUp, left, top
  25507. if (hoz) {
  25508. sideLeft =
  25509. this.canSideLeft &&
  25510. rect.right + popSize.width > vpRect.right &&
  25511. rect.left > popSize.width
  25512. sideUp =
  25513. this.canSideUp &&
  25514. rect.top + popSize.height > vpRect.bottom &&
  25515. rect.bottom > popSize.height
  25516. left = sideLeft ? rect.left - popSize.width : rect.right
  25517. top = sideUp ? rect.bottom - popSize.height : rect.top
  25518. } else {
  25519. sideLeft =
  25520. this.canSideLeft &&
  25521. rect.right + popSize.width > vpRect.right &&
  25522. rect.left > popSize.width
  25523. sideUp =
  25524. this.canSideUp &&
  25525. rect.top + popSize.height > vpRect.bottom &&
  25526. rect.bottom > popSize.height
  25527. left = sideLeft ? rect.right - popSize.width : rect.left
  25528. top = sideUp ? rect.top - popSize.height : rect.bottom
  25529. }
  25530. var popEl = this.getDom()
  25531. uiUtils.setViewportOffset(popEl, {
  25532. left: left,
  25533. top: top
  25534. })
  25535. domUtils.removeClasses(popEl, ANCHOR_CLASSES)
  25536. popEl.className += ' ' + ANCHOR_CLASSES[(sideUp ? 1 : 0) * 2 + (sideLeft ? 1 : 0)]
  25537. if (this.editor) {
  25538. popEl.style.zIndex = this.editor.container.style.zIndex * 1 + 10
  25539. baidu.editor.ui.uiUtils.getFixedLayer().style.zIndex = popEl.style.zIndex - 1
  25540. }
  25541. this.getDom().style.visibility = 'visible'
  25542. },
  25543. showAt: function (offset) {
  25544. var left = offset.left
  25545. var top = offset.top
  25546. var rect = {
  25547. left: left,
  25548. top: top,
  25549. right: left,
  25550. bottom: top,
  25551. height: 0,
  25552. width: 0
  25553. }
  25554. this.showAnchorRect(rect, false, true)
  25555. },
  25556. _show: function () {
  25557. if (this._hidden) {
  25558. var box = this.getDom()
  25559. box.style.display = ''
  25560. this._hidden = false
  25561. // if (box.setActive) {
  25562. // box.setActive();
  25563. // }
  25564. this.fireEvent('show')
  25565. }
  25566. },
  25567. isHidden: function () {
  25568. return this._hidden
  25569. },
  25570. show: function () {
  25571. this._doAutoRender()
  25572. this._show()
  25573. },
  25574. hide: function (notNofity) {
  25575. if (!this._hidden && this.getDom()) {
  25576. this.getDom().style.display = 'none'
  25577. this._hidden = true
  25578. if (!notNofity) {
  25579. this.fireEvent('hide')
  25580. }
  25581. }
  25582. },
  25583. queryAutoHide: function (el) {
  25584. return !el || !uiUtils.contains(this.getDom(), el)
  25585. }
  25586. }
  25587. utils.inherits(Popup, UIBase)
  25588. domUtils.on(document, 'mousedown', function (evt) {
  25589. var el = evt.target || evt.srcElement
  25590. closeAllPopup(evt, el)
  25591. })
  25592. domUtils.on(window, 'scroll', function (evt, el) {
  25593. closeAllPopup(evt, el)
  25594. })
  25595. })()
  25596. // ui/colorpicker.js
  25597. ///import core
  25598. ///import uicore
  25599. ;(function () {
  25600. var utils = baidu.editor.utils,
  25601. UIBase = baidu.editor.ui.UIBase,
  25602. ColorPicker = (baidu.editor.ui.ColorPicker = function (options) {
  25603. this.initOptions(options)
  25604. this.noColorText = this.noColorText || this.editor.getLang('clearColor')
  25605. this.initUIBase()
  25606. })
  25607. ColorPicker.prototype = {
  25608. getHtmlTpl: function () {
  25609. return genColorPicker(this.noColorText, this.editor)
  25610. },
  25611. _onTableClick: function (evt) {
  25612. var tgt = evt.target || evt.srcElement
  25613. var color = tgt.getAttribute('data-color')
  25614. if (color) {
  25615. this.fireEvent('pickcolor', color)
  25616. }
  25617. },
  25618. _onTableOver: function (evt) {
  25619. var tgt = evt.target || evt.srcElement
  25620. var color = tgt.getAttribute('data-color')
  25621. if (color) {
  25622. this.getDom('preview').style.backgroundColor = color
  25623. }
  25624. },
  25625. _onTableOut: function () {
  25626. this.getDom('preview').style.backgroundColor = ''
  25627. },
  25628. _onPickNoColor: function () {
  25629. this.fireEvent('picknocolor')
  25630. }
  25631. }
  25632. utils.inherits(ColorPicker, UIBase)
  25633. var COLORS = (
  25634. 'ffffff,000000,eeece1,1f497d,4f81bd,c0504d,9bbb59,8064a2,4bacc6,f79646,' +
  25635. 'f2f2f2,7f7f7f,ddd9c3,c6d9f0,dbe5f1,f2dcdb,ebf1dd,e5e0ec,dbeef3,fdeada,' +
  25636. 'd8d8d8,595959,c4bd97,8db3e2,b8cce4,e5b9b7,d7e3bc,ccc1d9,b7dde8,fbd5b5,' +
  25637. 'bfbfbf,3f3f3f,938953,548dd4,95b3d7,d99694,c3d69b,b2a2c7,92cddc,fac08f,' +
  25638. 'a5a5a5,262626,494429,17365d,366092,953734,76923c,5f497a,31859b,e36c09,' +
  25639. '7f7f7f,0c0c0c,1d1b10,0f243e,244061,632423,4f6128,3f3151,205867,974806,' +
  25640. 'c00000,ff0000,ffc000,ffff00,92d050,00b050,00b0f0,0070c0,002060,7030a0,'
  25641. ).split(',')
  25642. function genColorPicker(noColorText, editor) {
  25643. var html =
  25644. '<div id="##" class="edui-colorpicker %%">' +
  25645. '<div class="edui-colorpicker-topbar edui-clearfix">' +
  25646. '<div unselectable="on" id="##_preview" class="edui-colorpicker-preview"></div>' +
  25647. '<div unselectable="on" class="edui-colorpicker-nocolor" onclick="$$._onPickNoColor(event, this);">' +
  25648. noColorText +
  25649. '</div>' +
  25650. '</div>' +
  25651. '<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">' +
  25652. '<tr style="border-bottom: 1px solid #ddd;font-size: 13px;line-height: 25px;color:#39C;padding-top: 2px"><td colspan="10">' +
  25653. editor.getLang('themeColor') +
  25654. '</td> </tr>' +
  25655. '<tr class="edui-colorpicker-tablefirstrow" >'
  25656. for (var i = 0; i < COLORS.length; i++) {
  25657. if (i && i % 10 === 0) {
  25658. html +=
  25659. '</tr>' +
  25660. (i == 60
  25661. ? '<tr style="border-bottom: 1px solid #ddd;font-size: 13px;line-height: 25px;color:#39C;"><td colspan="10">' +
  25662. editor.getLang('standardColor') +
  25663. '</td></tr>'
  25664. : '') +
  25665. '<tr' +
  25666. (i == 60 ? ' class="edui-colorpicker-tablefirstrow"' : '') +
  25667. '>'
  25668. }
  25669. html +=
  25670. i < 70
  25671. ? '<td style="padding: 0 2px;"><a hidefocus title="' +
  25672. COLORS[i] +
  25673. '" onclick="return false;" href="javascript:" unselectable="on" class="edui-box edui-colorpicker-colorcell"' +
  25674. ' data-color="#' +
  25675. COLORS[i] +
  25676. '"' +
  25677. ' style="background-color:#' +
  25678. COLORS[i] +
  25679. ';border:solid #ccc;' +
  25680. (i < 10 || i >= 60
  25681. ? 'border-width:1px;'
  25682. : i >= 10 && i < 20
  25683. ? 'border-width:1px 1px 0 1px;'
  25684. : 'border-width:0 1px 0 1px;') +
  25685. '"' +
  25686. '></a></td>'
  25687. : ''
  25688. }
  25689. html += '</tr></table></div>'
  25690. return html
  25691. }
  25692. })()
  25693. // ui/tablepicker.js
  25694. ///import core
  25695. ///import uicore
  25696. ;(function () {
  25697. var utils = baidu.editor.utils,
  25698. uiUtils = baidu.editor.ui.uiUtils,
  25699. UIBase = baidu.editor.ui.UIBase
  25700. var TablePicker = (baidu.editor.ui.TablePicker = function (options) {
  25701. this.initOptions(options)
  25702. this.initTablePicker()
  25703. })
  25704. TablePicker.prototype = {
  25705. defaultNumRows: 10,
  25706. defaultNumCols: 10,
  25707. maxNumRows: 20,
  25708. maxNumCols: 20,
  25709. numRows: 10,
  25710. numCols: 10,
  25711. lengthOfCellSide: 22,
  25712. initTablePicker: function () {
  25713. this.initUIBase()
  25714. },
  25715. getHtmlTpl: function () {
  25716. var me = this
  25717. return (
  25718. '<div id="##" class="edui-tablepicker %%">' +
  25719. '<div class="edui-tablepicker-body">' +
  25720. '<div class="edui-infoarea">' +
  25721. '<span id="##_label" class="edui-label"></span>' +
  25722. '</div>' +
  25723. '<div class="edui-pickarea"' +
  25724. ' onmousemove="$$._onMouseMove(event, this);"' +
  25725. ' onmouseover="$$._onMouseOver(event, this);"' +
  25726. ' onmouseout="$$._onMouseOut(event, this);"' +
  25727. ' onclick="$$._onClick(event, this);"' +
  25728. '>' +
  25729. '<div id="##_overlay" class="edui-overlay"></div>' +
  25730. '</div>' +
  25731. '</div>' +
  25732. '</div>'
  25733. )
  25734. },
  25735. _UIBase_render: UIBase.prototype.render,
  25736. render: function (holder) {
  25737. this._UIBase_render(holder)
  25738. this.getDom('label').innerHTML =
  25739. '0' + this.editor.getLang('t_row') + ' x 0' + this.editor.getLang('t_col')
  25740. },
  25741. _track: function (numCols, numRows) {
  25742. var style = this.getDom('overlay').style
  25743. var sideLen = this.lengthOfCellSide
  25744. style.width = numCols * sideLen + 'px'
  25745. style.height = numRows * sideLen + 'px'
  25746. var label = this.getDom('label')
  25747. label.innerHTML =
  25748. numCols + this.editor.getLang('t_col') + ' x ' + numRows + this.editor.getLang('t_row')
  25749. this.numCols = numCols
  25750. this.numRows = numRows
  25751. },
  25752. _onMouseOver: function (evt, el) {
  25753. var rel = evt.relatedTarget || evt.fromElement
  25754. if (!uiUtils.contains(el, rel) && el !== rel) {
  25755. this.getDom('label').innerHTML =
  25756. '0' + this.editor.getLang('t_col') + ' x 0' + this.editor.getLang('t_row')
  25757. this.getDom('overlay').style.visibility = ''
  25758. }
  25759. },
  25760. _onMouseOut: function (evt, el) {
  25761. var rel = evt.relatedTarget || evt.toElement
  25762. if (!uiUtils.contains(el, rel) && el !== rel) {
  25763. this.getDom('label').innerHTML =
  25764. '0' + this.editor.getLang('t_col') + ' x 0' + this.editor.getLang('t_row')
  25765. this.getDom('overlay').style.visibility = 'hidden'
  25766. }
  25767. },
  25768. _onMouseMove: function (evt, el) {
  25769. var style = this.getDom('overlay').style
  25770. var offset = uiUtils.getEventOffset(evt)
  25771. var sideLen = this.lengthOfCellSide
  25772. var numCols = Math.ceil(offset.left / sideLen)
  25773. var numRows = Math.ceil(offset.top / sideLen)
  25774. this._track(numCols, numRows)
  25775. },
  25776. _onClick: function () {
  25777. this.fireEvent('picktable', this.numCols, this.numRows)
  25778. }
  25779. }
  25780. utils.inherits(TablePicker, UIBase)
  25781. })()
  25782. // ui/stateful.js
  25783. ;(function () {
  25784. var browser = baidu.editor.browser,
  25785. domUtils = baidu.editor.dom.domUtils,
  25786. uiUtils = baidu.editor.ui.uiUtils
  25787. var TPL_STATEFUL =
  25788. 'onmousedown="$$.Stateful_onMouseDown(event, this);"' +
  25789. ' onmouseup="$$.Stateful_onMouseUp(event, this);"' +
  25790. (browser.ie
  25791. ? ' onmouseenter="$$.Stateful_onMouseEnter(event, this);"' +
  25792. ' onmouseleave="$$.Stateful_onMouseLeave(event, this);"'
  25793. : ' onmouseover="$$.Stateful_onMouseOver(event, this);"' +
  25794. ' onmouseout="$$.Stateful_onMouseOut(event, this);"')
  25795. baidu.editor.ui.Stateful = {
  25796. alwalysHoverable: false,
  25797. target: null, //目标元素和this指向dom不一样
  25798. Stateful_init: function () {
  25799. this._Stateful_dGetHtmlTpl = this.getHtmlTpl
  25800. this.getHtmlTpl = this.Stateful_getHtmlTpl
  25801. },
  25802. Stateful_getHtmlTpl: function () {
  25803. var tpl = this._Stateful_dGetHtmlTpl()
  25804. // 使用function避免$转义
  25805. return tpl.replace(/stateful/g, function () {
  25806. return TPL_STATEFUL
  25807. })
  25808. },
  25809. Stateful_onMouseEnter: function (evt, el) {
  25810. this.target = el
  25811. if (!this.isDisabled() || this.alwalysHoverable) {
  25812. this.addState('hover')
  25813. this.fireEvent('over')
  25814. }
  25815. },
  25816. Stateful_onMouseLeave: function (evt, el) {
  25817. if (!this.isDisabled() || this.alwalysHoverable) {
  25818. this.removeState('hover')
  25819. this.removeState('active')
  25820. this.fireEvent('out')
  25821. }
  25822. },
  25823. Stateful_onMouseOver: function (evt, el) {
  25824. var rel = evt.relatedTarget
  25825. if (!uiUtils.contains(el, rel) && el !== rel) {
  25826. this.Stateful_onMouseEnter(evt, el)
  25827. }
  25828. },
  25829. Stateful_onMouseOut: function (evt, el) {
  25830. var rel = evt.relatedTarget
  25831. if (!uiUtils.contains(el, rel) && el !== rel) {
  25832. this.Stateful_onMouseLeave(evt, el)
  25833. }
  25834. },
  25835. Stateful_onMouseDown: function (evt, el) {
  25836. if (!this.isDisabled()) {
  25837. this.addState('active')
  25838. }
  25839. },
  25840. Stateful_onMouseUp: function (evt, el) {
  25841. if (!this.isDisabled()) {
  25842. this.removeState('active')
  25843. }
  25844. },
  25845. Stateful_postRender: function () {
  25846. if (this.disabled && !this.hasState('disabled')) {
  25847. this.addState('disabled')
  25848. }
  25849. },
  25850. hasState: function (state) {
  25851. return domUtils.hasClass(this.getStateDom(), 'edui-state-' + state)
  25852. },
  25853. addState: function (state) {
  25854. if (!this.hasState(state)) {
  25855. this.getStateDom().className += ' edui-state-' + state
  25856. }
  25857. },
  25858. removeState: function (state) {
  25859. if (this.hasState(state)) {
  25860. domUtils.removeClasses(this.getStateDom(), ['edui-state-' + state])
  25861. }
  25862. },
  25863. getStateDom: function () {
  25864. return this.getDom('state')
  25865. },
  25866. isChecked: function () {
  25867. return this.hasState('checked')
  25868. },
  25869. setChecked: function (checked) {
  25870. if (!this.isDisabled() && checked) {
  25871. this.addState('checked')
  25872. } else {
  25873. this.removeState('checked')
  25874. }
  25875. },
  25876. isDisabled: function () {
  25877. return this.hasState('disabled')
  25878. },
  25879. setDisabled: function (disabled) {
  25880. if (disabled) {
  25881. this.removeState('hover')
  25882. this.removeState('checked')
  25883. this.removeState('active')
  25884. this.addState('disabled')
  25885. } else {
  25886. this.removeState('disabled')
  25887. }
  25888. }
  25889. }
  25890. })()
  25891. // ui/button.js
  25892. ///import core
  25893. ///import uicore
  25894. ///import ui/stateful.js
  25895. ;(function () {
  25896. var utils = baidu.editor.utils,
  25897. UIBase = baidu.editor.ui.UIBase,
  25898. Stateful = baidu.editor.ui.Stateful,
  25899. Button = (baidu.editor.ui.Button = function (options) {
  25900. if (options.name) {
  25901. var btnName = options.name
  25902. var cssRules = options.cssRules
  25903. if (!options.className) {
  25904. options.className = 'edui-for-' + btnName
  25905. }
  25906. options.cssRules =
  25907. '.edui-default .edui-for-' + btnName + ' .edui-icon {' + cssRules + '}'
  25908. }
  25909. this.initOptions(options)
  25910. this.initButton()
  25911. })
  25912. Button.prototype = {
  25913. uiName: 'button',
  25914. label: '',
  25915. title: '',
  25916. showIcon: true,
  25917. showText: true,
  25918. cssRules: '',
  25919. initButton: function () {
  25920. this.initUIBase()
  25921. this.Stateful_init()
  25922. if (this.cssRules) {
  25923. utils.cssRule('edui-customize-' + this.name + '-style', this.cssRules)
  25924. }
  25925. },
  25926. getHtmlTpl: function () {
  25927. return (
  25928. '<div id="##" class="edui-box %%">' +
  25929. '<div id="##_state" stateful>' +
  25930. '<div class="%%-wrap"><div id="##_body" unselectable="on" ' +
  25931. (this.title ? 'title="' + this.title + '"' : '') +
  25932. ' class="%%-body" onmousedown="return $$._onMouseDown(event, this);" onclick="return $$._onClick(event, this);">' +
  25933. (this.showIcon ? '<div class="edui-box edui-icon"></div>' : '') +
  25934. (this.showText ? '<div class="edui-box edui-label">' + this.label + '</div>' : '') +
  25935. '</div>' +
  25936. '</div>' +
  25937. '</div></div>'
  25938. )
  25939. },
  25940. postRender: function () {
  25941. this.Stateful_postRender()
  25942. this.setDisabled(this.disabled)
  25943. },
  25944. _onMouseDown: function (e) {
  25945. var target = e.target || e.srcElement,
  25946. tagName = target && target.tagName && target.tagName.toLowerCase()
  25947. if (tagName == 'input' || tagName == 'object' || tagName == 'object') {
  25948. return false
  25949. }
  25950. },
  25951. _onClick: function () {
  25952. if (!this.isDisabled()) {
  25953. this.fireEvent('click')
  25954. }
  25955. },
  25956. setTitle: function (text) {
  25957. var label = this.getDom('label')
  25958. label.innerHTML = text
  25959. }
  25960. }
  25961. utils.inherits(Button, UIBase)
  25962. utils.extend(Button.prototype, Stateful)
  25963. })()
  25964. // ui/splitbutton.js
  25965. ///import core
  25966. ///import uicore
  25967. ///import ui/stateful.js
  25968. ;(function () {
  25969. var utils = baidu.editor.utils,
  25970. uiUtils = baidu.editor.ui.uiUtils,
  25971. domUtils = baidu.editor.dom.domUtils,
  25972. UIBase = baidu.editor.ui.UIBase,
  25973. Stateful = baidu.editor.ui.Stateful,
  25974. SplitButton = (baidu.editor.ui.SplitButton = function (options) {
  25975. this.initOptions(options)
  25976. this.initSplitButton()
  25977. })
  25978. SplitButton.prototype = {
  25979. popup: null,
  25980. uiName: 'splitbutton',
  25981. title: '',
  25982. initSplitButton: function () {
  25983. this.initUIBase()
  25984. this.Stateful_init()
  25985. var me = this
  25986. if (this.popup != null) {
  25987. var popup = this.popup
  25988. this.popup = null
  25989. this.setPopup(popup)
  25990. }
  25991. },
  25992. _UIBase_postRender: UIBase.prototype.postRender,
  25993. postRender: function () {
  25994. this.Stateful_postRender()
  25995. this._UIBase_postRender()
  25996. },
  25997. setPopup: function (popup) {
  25998. if (this.popup === popup) return
  25999. if (this.popup != null) {
  26000. this.popup.dispose()
  26001. }
  26002. popup.addListener('show', utils.bind(this._onPopupShow, this))
  26003. popup.addListener('hide', utils.bind(this._onPopupHide, this))
  26004. popup.addListener(
  26005. 'postrender',
  26006. utils.bind(function () {
  26007. popup
  26008. .getDom('body')
  26009. .appendChild(
  26010. uiUtils.createElementByHtml(
  26011. '<div id="' +
  26012. this.popup.id +
  26013. '_bordereraser" class="edui-bordereraser edui-background" style="width:' +
  26014. (uiUtils.getClientRect(this.getDom()).width + 20) +
  26015. 'px"></div>'
  26016. )
  26017. )
  26018. popup.getDom().className += ' ' + this.className
  26019. }, this)
  26020. )
  26021. this.popup = popup
  26022. },
  26023. _onPopupShow: function () {
  26024. this.addState('opened')
  26025. },
  26026. _onPopupHide: function () {
  26027. this.removeState('opened')
  26028. },
  26029. getHtmlTpl: function () {
  26030. return (
  26031. '<div id="##" class="edui-box %%">' +
  26032. '<div ' +
  26033. (this.title ? 'title="' + this.title + '"' : '') +
  26034. ' id="##_state" stateful><div class="%%-body">' +
  26035. '<div id="##_button_body" class="edui-box edui-button-body" onclick="$$._onButtonClick(event, this);">' +
  26036. '<div class="edui-box edui-icon"></div>' +
  26037. '</div>' +
  26038. '<div class="edui-box edui-splitborder"></div>' +
  26039. '<div class="edui-box edui-arrow" onclick="$$._onArrowClick();"></div>' +
  26040. '</div></div></div>'
  26041. )
  26042. },
  26043. showPopup: function () {
  26044. // 当popup往上弹出的时候,做特殊处理
  26045. var rect = uiUtils.getClientRect(this.getDom())
  26046. rect.top -= this.popup.SHADOW_RADIUS
  26047. rect.height += this.popup.SHADOW_RADIUS
  26048. this.popup.showAnchorRect(rect)
  26049. },
  26050. _onArrowClick: function (event, el) {
  26051. if (!this.isDisabled()) {
  26052. this.showPopup()
  26053. }
  26054. },
  26055. _onButtonClick: function () {
  26056. if (!this.isDisabled()) {
  26057. this.fireEvent('buttonclick')
  26058. }
  26059. }
  26060. }
  26061. utils.inherits(SplitButton, UIBase)
  26062. utils.extend(SplitButton.prototype, Stateful, true)
  26063. })()
  26064. // ui/colorbutton.js
  26065. ///import core
  26066. ///import uicore
  26067. ///import ui/colorpicker.js
  26068. ///import ui/popup.js
  26069. ///import ui/splitbutton.js
  26070. ;(function () {
  26071. var utils = baidu.editor.utils,
  26072. uiUtils = baidu.editor.ui.uiUtils,
  26073. ColorPicker = baidu.editor.ui.ColorPicker,
  26074. Popup = baidu.editor.ui.Popup,
  26075. SplitButton = baidu.editor.ui.SplitButton,
  26076. ColorButton = (baidu.editor.ui.ColorButton = function (options) {
  26077. this.initOptions(options)
  26078. this.initColorButton()
  26079. })
  26080. ColorButton.prototype = {
  26081. initColorButton: function () {
  26082. var me = this
  26083. this.popup = new Popup({
  26084. content: new ColorPicker({
  26085. noColorText: me.editor.getLang('clearColor'),
  26086. editor: me.editor,
  26087. onpickcolor: function (t, color) {
  26088. me._onPickColor(color)
  26089. },
  26090. onpicknocolor: function (t, color) {
  26091. me._onPickNoColor(color)
  26092. }
  26093. }),
  26094. editor: me.editor
  26095. })
  26096. this.initSplitButton()
  26097. },
  26098. _SplitButton_postRender: SplitButton.prototype.postRender,
  26099. postRender: function () {
  26100. this._SplitButton_postRender()
  26101. this.getDom('button_body').appendChild(
  26102. uiUtils.createElementByHtml(
  26103. '<div id="' + this.id + '_colorlump" class="edui-colorlump"></div>'
  26104. )
  26105. )
  26106. this.getDom().className += ' edui-colorbutton'
  26107. },
  26108. setColor: function (color) {
  26109. this.getDom('colorlump').style.backgroundColor = color
  26110. this.color = color
  26111. },
  26112. _onPickColor: function (color) {
  26113. if (this.fireEvent('pickcolor', color) !== false) {
  26114. this.setColor(color)
  26115. this.popup.hide()
  26116. }
  26117. },
  26118. _onPickNoColor: function (color) {
  26119. if (this.fireEvent('picknocolor') !== false) {
  26120. this.popup.hide()
  26121. }
  26122. }
  26123. }
  26124. utils.inherits(ColorButton, SplitButton)
  26125. })()
  26126. // ui/tablebutton.js
  26127. ///import core
  26128. ///import uicore
  26129. ///import ui/popup.js
  26130. ///import ui/tablepicker.js
  26131. ///import ui/splitbutton.js
  26132. ;(function () {
  26133. var utils = baidu.editor.utils,
  26134. Popup = baidu.editor.ui.Popup,
  26135. TablePicker = baidu.editor.ui.TablePicker,
  26136. SplitButton = baidu.editor.ui.SplitButton,
  26137. TableButton = (baidu.editor.ui.TableButton = function (options) {
  26138. this.initOptions(options)
  26139. this.initTableButton()
  26140. })
  26141. TableButton.prototype = {
  26142. initTableButton: function () {
  26143. var me = this
  26144. this.popup = new Popup({
  26145. content: new TablePicker({
  26146. editor: me.editor,
  26147. onpicktable: function (t, numCols, numRows) {
  26148. me._onPickTable(numCols, numRows)
  26149. }
  26150. }),
  26151. editor: me.editor
  26152. })
  26153. this.initSplitButton()
  26154. },
  26155. _onPickTable: function (numCols, numRows) {
  26156. if (this.fireEvent('picktable', numCols, numRows) !== false) {
  26157. this.popup.hide()
  26158. }
  26159. }
  26160. }
  26161. utils.inherits(TableButton, SplitButton)
  26162. })()
  26163. // ui/autotypesetpicker.js
  26164. ///import core
  26165. ///import uicore
  26166. ;(function () {
  26167. var utils = baidu.editor.utils,
  26168. UIBase = baidu.editor.ui.UIBase
  26169. var AutoTypeSetPicker = (baidu.editor.ui.AutoTypeSetPicker = function (options) {
  26170. this.initOptions(options)
  26171. this.initAutoTypeSetPicker()
  26172. })
  26173. AutoTypeSetPicker.prototype = {
  26174. initAutoTypeSetPicker: function () {
  26175. this.initUIBase()
  26176. },
  26177. getHtmlTpl: function () {
  26178. var me = this.editor,
  26179. opt = me.options.autotypeset,
  26180. lang = me.getLang('autoTypeSet')
  26181. var textAlignInputName = 'textAlignValue' + me.uid,
  26182. imageBlockInputName = 'imageBlockLineValue' + me.uid,
  26183. symbolConverInputName = 'symbolConverValue' + me.uid
  26184. return (
  26185. '<div id="##" class="edui-autotypesetpicker %%">' +
  26186. '<div class="edui-autotypesetpicker-body">' +
  26187. '<table >' +
  26188. '<tr><td nowrap><input type="checkbox" name="mergeEmptyline" ' +
  26189. (opt['mergeEmptyline'] ? 'checked' : '') +
  26190. '>' +
  26191. lang.mergeLine +
  26192. '</td><td colspan="2"><input type="checkbox" name="removeEmptyline" ' +
  26193. (opt['removeEmptyline'] ? 'checked' : '') +
  26194. '>' +
  26195. lang.delLine +
  26196. '</td></tr>' +
  26197. '<tr><td nowrap><input type="checkbox" name="removeClass" ' +
  26198. (opt['removeClass'] ? 'checked' : '') +
  26199. '>' +
  26200. lang.removeFormat +
  26201. '</td><td colspan="2"><input type="checkbox" name="indent" ' +
  26202. (opt['indent'] ? 'checked' : '') +
  26203. '>' +
  26204. lang.indent +
  26205. '</td></tr>' +
  26206. '<tr>' +
  26207. '<td nowrap><input type="checkbox" name="textAlign" ' +
  26208. (opt['textAlign'] ? 'checked' : '') +
  26209. '>' +
  26210. lang.alignment +
  26211. '</td>' +
  26212. '<td colspan="2" id="' +
  26213. textAlignInputName +
  26214. '">' +
  26215. '<input type="radio" name="' +
  26216. textAlignInputName +
  26217. '" value="left" ' +
  26218. (opt['textAlign'] && opt['textAlign'] == 'left' ? 'checked' : '') +
  26219. '>' +
  26220. me.getLang('justifyleft') +
  26221. '<input type="radio" name="' +
  26222. textAlignInputName +
  26223. '" value="center" ' +
  26224. (opt['textAlign'] && opt['textAlign'] == 'center' ? 'checked' : '') +
  26225. '>' +
  26226. me.getLang('justifycenter') +
  26227. '<input type="radio" name="' +
  26228. textAlignInputName +
  26229. '" value="right" ' +
  26230. (opt['textAlign'] && opt['textAlign'] == 'right' ? 'checked' : '') +
  26231. '>' +
  26232. me.getLang('justifyright') +
  26233. '</td>' +
  26234. '</tr>' +
  26235. '<tr>' +
  26236. '<td nowrap><input type="checkbox" name="imageBlockLine" ' +
  26237. (opt['imageBlockLine'] ? 'checked' : '') +
  26238. '>' +
  26239. lang.imageFloat +
  26240. '</td>' +
  26241. '<td nowrap id="' +
  26242. imageBlockInputName +
  26243. '">' +
  26244. '<input type="radio" name="' +
  26245. imageBlockInputName +
  26246. '" value="none" ' +
  26247. (opt['imageBlockLine'] && opt['imageBlockLine'] == 'none' ? 'checked' : '') +
  26248. '>' +
  26249. me.getLang('default') +
  26250. '<input type="radio" name="' +
  26251. imageBlockInputName +
  26252. '" value="left" ' +
  26253. (opt['imageBlockLine'] && opt['imageBlockLine'] == 'left' ? 'checked' : '') +
  26254. '>' +
  26255. me.getLang('justifyleft') +
  26256. '<input type="radio" name="' +
  26257. imageBlockInputName +
  26258. '" value="center" ' +
  26259. (opt['imageBlockLine'] && opt['imageBlockLine'] == 'center' ? 'checked' : '') +
  26260. '>' +
  26261. me.getLang('justifycenter') +
  26262. '<input type="radio" name="' +
  26263. imageBlockInputName +
  26264. '" value="right" ' +
  26265. (opt['imageBlockLine'] && opt['imageBlockLine'] == 'right' ? 'checked' : '') +
  26266. '>' +
  26267. me.getLang('justifyright') +
  26268. '</td>' +
  26269. '</tr>' +
  26270. '<tr><td nowrap><input type="checkbox" name="clearFontSize" ' +
  26271. (opt['clearFontSize'] ? 'checked' : '') +
  26272. '>' +
  26273. lang.removeFontsize +
  26274. '</td><td colspan="2"><input type="checkbox" name="clearFontFamily" ' +
  26275. (opt['clearFontFamily'] ? 'checked' : '') +
  26276. '>' +
  26277. lang.removeFontFamily +
  26278. '</td></tr>' +
  26279. '<tr><td nowrap colspan="3"><input type="checkbox" name="removeEmptyNode" ' +
  26280. (opt['removeEmptyNode'] ? 'checked' : '') +
  26281. '>' +
  26282. lang.removeHtml +
  26283. '</td></tr>' +
  26284. '<tr><td nowrap colspan="3"><input type="checkbox" name="pasteFilter" ' +
  26285. (opt['pasteFilter'] ? 'checked' : '') +
  26286. '>' +
  26287. lang.pasteFilter +
  26288. '</td></tr>' +
  26289. '<tr>' +
  26290. '<td nowrap><input type="checkbox" name="symbolConver" ' +
  26291. (opt['bdc2sb'] || opt['tobdc'] ? 'checked' : '') +
  26292. '>' +
  26293. lang.symbol +
  26294. '</td>' +
  26295. '<td id="' +
  26296. symbolConverInputName +
  26297. '">' +
  26298. '<input type="radio" name="bdc" value="bdc2sb" ' +
  26299. (opt['bdc2sb'] ? 'checked' : '') +
  26300. '>' +
  26301. lang.bdc2sb +
  26302. '<input type="radio" name="bdc" value="tobdc" ' +
  26303. (opt['tobdc'] ? 'checked' : '') +
  26304. '>' +
  26305. lang.tobdc +
  26306. '' +
  26307. '</td>' +
  26308. '<td nowrap align="right"><button >' +
  26309. lang.run +
  26310. '</button></td>' +
  26311. '</tr>' +
  26312. '</table>' +
  26313. '</div>' +
  26314. '</div>'
  26315. )
  26316. },
  26317. _UIBase_render: UIBase.prototype.render
  26318. }
  26319. utils.inherits(AutoTypeSetPicker, UIBase)
  26320. })()
  26321. // ui/autotypesetbutton.js
  26322. ///import core
  26323. ///import uicore
  26324. ///import ui/popup.js
  26325. ///import ui/autotypesetpicker.js
  26326. ///import ui/splitbutton.js
  26327. ;(function () {
  26328. var utils = baidu.editor.utils,
  26329. Popup = baidu.editor.ui.Popup,
  26330. AutoTypeSetPicker = baidu.editor.ui.AutoTypeSetPicker,
  26331. SplitButton = baidu.editor.ui.SplitButton,
  26332. AutoTypeSetButton = (baidu.editor.ui.AutoTypeSetButton = function (options) {
  26333. this.initOptions(options)
  26334. this.initAutoTypeSetButton()
  26335. })
  26336. function getPara(me) {
  26337. var opt = {},
  26338. cont = me.getDom(),
  26339. editorId = me.editor.uid,
  26340. inputType = null,
  26341. attrName = null,
  26342. ipts = domUtils.getElementsByTagName(cont, 'input')
  26343. for (var i = ipts.length - 1, ipt; (ipt = ipts[i--]); ) {
  26344. inputType = ipt.getAttribute('type')
  26345. if (inputType == 'checkbox') {
  26346. attrName = ipt.getAttribute('name')
  26347. opt[attrName] && delete opt[attrName]
  26348. if (ipt.checked) {
  26349. var attrValue = document.getElementById(attrName + 'Value' + editorId)
  26350. if (attrValue) {
  26351. if (/input/gi.test(attrValue.tagName)) {
  26352. opt[attrName] = attrValue.value
  26353. } else {
  26354. var iptChilds = attrValue.getElementsByTagName('input')
  26355. for (var j = iptChilds.length - 1, iptchild; (iptchild = iptChilds[j--]); ) {
  26356. if (iptchild.checked) {
  26357. opt[attrName] = iptchild.value
  26358. break
  26359. }
  26360. }
  26361. }
  26362. } else {
  26363. opt[attrName] = true
  26364. }
  26365. } else {
  26366. opt[attrName] = false
  26367. }
  26368. } else {
  26369. opt[ipt.getAttribute('value')] = ipt.checked
  26370. }
  26371. }
  26372. var selects = domUtils.getElementsByTagName(cont, 'select')
  26373. for (var i = 0, si; (si = selects[i++]); ) {
  26374. var attr = si.getAttribute('name')
  26375. opt[attr] = opt[attr] ? si.value : ''
  26376. }
  26377. utils.extend(me.editor.options.autotypeset, opt)
  26378. me.editor.setPreferences('autotypeset', opt)
  26379. }
  26380. AutoTypeSetButton.prototype = {
  26381. initAutoTypeSetButton: function () {
  26382. var me = this
  26383. this.popup = new Popup({
  26384. //传入配置参数
  26385. content: new AutoTypeSetPicker({ editor: me.editor }),
  26386. editor: me.editor,
  26387. hide: function () {
  26388. if (!this._hidden && this.getDom()) {
  26389. getPara(this)
  26390. this.getDom().style.display = 'none'
  26391. this._hidden = true
  26392. this.fireEvent('hide')
  26393. }
  26394. }
  26395. })
  26396. var flag = 0
  26397. this.popup.addListener('postRenderAfter', function () {
  26398. var popupUI = this
  26399. if (flag) return
  26400. var cont = this.getDom(),
  26401. btn = cont.getElementsByTagName('button')[0]
  26402. btn.onclick = function () {
  26403. getPara(popupUI)
  26404. me.editor.execCommand('autotypeset')
  26405. popupUI.hide()
  26406. }
  26407. domUtils.on(cont, 'click', function (e) {
  26408. var target = e.target || e.srcElement,
  26409. editorId = me.editor.uid
  26410. if (target && target.tagName == 'INPUT') {
  26411. // 点击图片浮动的checkbox,去除对应的radio
  26412. if (
  26413. target.name == 'imageBlockLine' ||
  26414. target.name == 'textAlign' ||
  26415. target.name == 'symbolConver'
  26416. ) {
  26417. var checked = target.checked,
  26418. radioTd = document.getElementById(target.name + 'Value' + editorId),
  26419. radios = radioTd.getElementsByTagName('input'),
  26420. defalutSelect = {
  26421. imageBlockLine: 'none',
  26422. textAlign: 'left',
  26423. symbolConver: 'tobdc'
  26424. }
  26425. for (var i = 0; i < radios.length; i++) {
  26426. if (checked) {
  26427. if (radios[i].value == defalutSelect[target.name]) {
  26428. radios[i].checked = 'checked'
  26429. }
  26430. } else {
  26431. radios[i].checked = false
  26432. }
  26433. }
  26434. }
  26435. // 点击radio,选中对应的checkbox
  26436. if (
  26437. target.name == 'imageBlockLineValue' + editorId ||
  26438. target.name == 'textAlignValue' + editorId ||
  26439. target.name == 'bdc'
  26440. ) {
  26441. var checkboxs = target.parentNode.previousSibling.getElementsByTagName('input')
  26442. checkboxs && (checkboxs[0].checked = true)
  26443. }
  26444. getPara(popupUI)
  26445. }
  26446. })
  26447. flag = 1
  26448. })
  26449. this.initSplitButton()
  26450. }
  26451. }
  26452. utils.inherits(AutoTypeSetButton, SplitButton)
  26453. })()
  26454. // ui/cellalignpicker.js
  26455. ///import core
  26456. ///import uicore
  26457. ;(function () {
  26458. var utils = baidu.editor.utils,
  26459. Popup = baidu.editor.ui.Popup,
  26460. Stateful = baidu.editor.ui.Stateful,
  26461. UIBase = baidu.editor.ui.UIBase
  26462. /**
  26463. * 该参数将新增一个参数: selected, 参数类型为一个Object, 形如{ 'align': 'center', 'valign': 'top' }, 表示单元格的初始
  26464. * 对齐状态为: 竖直居上,水平居中; 其中 align的取值为:'center', 'left', 'right'; valign的取值为: 'top', 'middle', 'bottom'
  26465. * @update 2013/4/2 hancong03@baidu.com
  26466. */
  26467. var CellAlignPicker = (baidu.editor.ui.CellAlignPicker = function (options) {
  26468. this.initOptions(options)
  26469. this.initSelected()
  26470. this.initCellAlignPicker()
  26471. })
  26472. CellAlignPicker.prototype = {
  26473. //初始化选中状态, 该方法将根据传递进来的参数获取到应该选中的对齐方式图标的索引
  26474. initSelected: function () {
  26475. var status = {
  26476. valign: {
  26477. top: 0,
  26478. middle: 1,
  26479. bottom: 2
  26480. },
  26481. align: {
  26482. left: 0,
  26483. center: 1,
  26484. right: 2
  26485. },
  26486. count: 3
  26487. },
  26488. result = -1
  26489. if (this.selected) {
  26490. this.selectedIndex =
  26491. status.valign[this.selected.valign] * status.count + status.align[this.selected.align]
  26492. }
  26493. },
  26494. initCellAlignPicker: function () {
  26495. this.initUIBase()
  26496. this.Stateful_init()
  26497. },
  26498. getHtmlTpl: function () {
  26499. var alignType = ['left', 'center', 'right'],
  26500. COUNT = 9,
  26501. tempClassName = null,
  26502. tempIndex = -1,
  26503. tmpl = []
  26504. for (var i = 0; i < COUNT; i++) {
  26505. tempClassName = this.selectedIndex === i ? ' class="edui-cellalign-selected" ' : ''
  26506. tempIndex = i % 3
  26507. tempIndex === 0 && tmpl.push('<tr>')
  26508. tmpl.push(
  26509. '<td index="' +
  26510. i +
  26511. '" ' +
  26512. tempClassName +
  26513. ' stateful><div class="edui-icon edui-' +
  26514. alignType[tempIndex] +
  26515. '"></div></td>'
  26516. )
  26517. tempIndex === 2 && tmpl.push('</tr>')
  26518. }
  26519. return (
  26520. '<div id="##" class="edui-cellalignpicker %%">' +
  26521. '<div class="edui-cellalignpicker-body">' +
  26522. '<table onclick="$$._onClick(event);">' +
  26523. tmpl.join('') +
  26524. '</table>' +
  26525. '</div>' +
  26526. '</div>'
  26527. )
  26528. },
  26529. getStateDom: function () {
  26530. return this.target
  26531. },
  26532. _onClick: function (evt) {
  26533. var target = evt.target || evt.srcElement
  26534. if (/icon/.test(target.className)) {
  26535. this.items[target.parentNode.getAttribute('index')].onclick()
  26536. Popup.postHide(evt)
  26537. }
  26538. },
  26539. _UIBase_render: UIBase.prototype.render
  26540. }
  26541. utils.inherits(CellAlignPicker, UIBase)
  26542. utils.extend(CellAlignPicker.prototype, Stateful, true)
  26543. })()
  26544. // ui/pastepicker.js
  26545. ///import core
  26546. ///import uicore
  26547. ;(function () {
  26548. var utils = baidu.editor.utils,
  26549. Stateful = baidu.editor.ui.Stateful,
  26550. uiUtils = baidu.editor.ui.uiUtils,
  26551. UIBase = baidu.editor.ui.UIBase
  26552. var PastePicker = (baidu.editor.ui.PastePicker = function (options) {
  26553. this.initOptions(options)
  26554. this.initPastePicker()
  26555. })
  26556. PastePicker.prototype = {
  26557. initPastePicker: function () {
  26558. this.initUIBase()
  26559. this.Stateful_init()
  26560. },
  26561. getHtmlTpl: function () {
  26562. return (
  26563. '<div class="edui-pasteicon" onclick="$$._onClick(this)"></div>' +
  26564. '<div class="edui-pastecontainer">' +
  26565. '<div class="edui-title">' +
  26566. this.editor.getLang('pasteOpt') +
  26567. '</div>' +
  26568. '<div class="edui-button">' +
  26569. '<div title="' +
  26570. this.editor.getLang('pasteSourceFormat') +
  26571. '" onclick="$$.format(false)" stateful>' +
  26572. '<div class="edui-richtxticon"></div></div>' +
  26573. '<div title="' +
  26574. this.editor.getLang('tagFormat') +
  26575. '" onclick="$$.format(2)" stateful>' +
  26576. '<div class="edui-tagicon"></div></div>' +
  26577. '<div title="' +
  26578. this.editor.getLang('pasteTextFormat') +
  26579. '" onclick="$$.format(true)" stateful>' +
  26580. '<div class="edui-plaintxticon"></div></div>' +
  26581. '</div>' +
  26582. '</div>' +
  26583. '</div>'
  26584. )
  26585. },
  26586. getStateDom: function () {
  26587. return this.target
  26588. },
  26589. format: function (param) {
  26590. this.editor.ui._isTransfer = true
  26591. this.editor.fireEvent('pasteTransfer', param)
  26592. },
  26593. _onClick: function (cur) {
  26594. var node = domUtils.getNextDomNode(cur),
  26595. screenHt = uiUtils.getViewportRect().height,
  26596. subPop = uiUtils.getClientRect(node)
  26597. if (subPop.top + subPop.height > screenHt)
  26598. node.style.top = -subPop.height - cur.offsetHeight + 'px'
  26599. else node.style.top = ''
  26600. if (/hidden/gi.test(domUtils.getComputedStyle(node, 'visibility'))) {
  26601. node.style.visibility = 'visible'
  26602. domUtils.addClass(cur, 'edui-state-opened')
  26603. } else {
  26604. node.style.visibility = 'hidden'
  26605. domUtils.removeClasses(cur, 'edui-state-opened')
  26606. }
  26607. },
  26608. _UIBase_render: UIBase.prototype.render
  26609. }
  26610. utils.inherits(PastePicker, UIBase)
  26611. utils.extend(PastePicker.prototype, Stateful, true)
  26612. })()
  26613. // ui/toolbar.js
  26614. ;(function () {
  26615. var utils = baidu.editor.utils,
  26616. uiUtils = baidu.editor.ui.uiUtils,
  26617. UIBase = baidu.editor.ui.UIBase,
  26618. Toolbar = (baidu.editor.ui.Toolbar = function (options) {
  26619. this.initOptions(options)
  26620. this.initToolbar()
  26621. })
  26622. Toolbar.prototype = {
  26623. items: null,
  26624. initToolbar: function () {
  26625. this.items = this.items || []
  26626. this.initUIBase()
  26627. },
  26628. add: function (item, index) {
  26629. if (index === undefined) {
  26630. this.items.push(item)
  26631. } else {
  26632. this.items.splice(index, 0, item)
  26633. }
  26634. },
  26635. getHtmlTpl: function () {
  26636. var buff = []
  26637. for (var i = 0; i < this.items.length; i++) {
  26638. buff[i] = this.items[i].renderHtml()
  26639. }
  26640. return (
  26641. '<div id="##" class="edui-toolbar %%" onselectstart="return false;" onmousedown="return $$._onMouseDown(event, this);">' +
  26642. buff.join('') +
  26643. '</div>'
  26644. )
  26645. },
  26646. postRender: function () {
  26647. var box = this.getDom()
  26648. for (var i = 0; i < this.items.length; i++) {
  26649. this.items[i].postRender()
  26650. }
  26651. uiUtils.makeUnselectable(box)
  26652. },
  26653. _onMouseDown: function (e) {
  26654. var target = e.target || e.srcElement,
  26655. tagName = target && target.tagName && target.tagName.toLowerCase()
  26656. if (tagName == 'input' || tagName == 'object' || tagName == 'object') {
  26657. return false
  26658. }
  26659. }
  26660. }
  26661. utils.inherits(Toolbar, UIBase)
  26662. })()
  26663. // ui/menu.js
  26664. ///import core
  26665. ///import uicore
  26666. ///import ui\popup.js
  26667. ///import ui\stateful.js
  26668. ;(function () {
  26669. var utils = baidu.editor.utils,
  26670. domUtils = baidu.editor.dom.domUtils,
  26671. uiUtils = baidu.editor.ui.uiUtils,
  26672. UIBase = baidu.editor.ui.UIBase,
  26673. Popup = baidu.editor.ui.Popup,
  26674. Stateful = baidu.editor.ui.Stateful,
  26675. CellAlignPicker = baidu.editor.ui.CellAlignPicker,
  26676. Menu = (baidu.editor.ui.Menu = function (options) {
  26677. this.initOptions(options)
  26678. this.initMenu()
  26679. })
  26680. var menuSeparator = {
  26681. renderHtml: function () {
  26682. return '<div class="edui-menuitem edui-menuseparator"><div class="edui-menuseparator-inner"></div></div>'
  26683. },
  26684. postRender: function () {},
  26685. queryAutoHide: function () {
  26686. return true
  26687. }
  26688. }
  26689. Menu.prototype = {
  26690. items: null,
  26691. uiName: 'menu',
  26692. initMenu: function () {
  26693. this.items = this.items || []
  26694. this.initPopup()
  26695. this.initItems()
  26696. },
  26697. initItems: function () {
  26698. for (var i = 0; i < this.items.length; i++) {
  26699. var item = this.items[i]
  26700. if (item == '-') {
  26701. this.items[i] = this.getSeparator()
  26702. } else if (!(item instanceof MenuItem)) {
  26703. item.editor = this.editor
  26704. item.theme = this.editor.options.theme
  26705. this.items[i] = this.createItem(item)
  26706. }
  26707. }
  26708. },
  26709. getSeparator: function () {
  26710. return menuSeparator
  26711. },
  26712. createItem: function (item) {
  26713. //新增一个参数menu, 该参数存储了menuItem所对应的menu引用
  26714. item.menu = this
  26715. return new MenuItem(item)
  26716. },
  26717. _Popup_getContentHtmlTpl: Popup.prototype.getContentHtmlTpl,
  26718. getContentHtmlTpl: function () {
  26719. if (this.items.length == 0) {
  26720. return this._Popup_getContentHtmlTpl()
  26721. }
  26722. var buff = []
  26723. for (var i = 0; i < this.items.length; i++) {
  26724. var item = this.items[i]
  26725. buff[i] = item.renderHtml()
  26726. }
  26727. return '<div class="%%-body">' + buff.join('') + '</div>'
  26728. },
  26729. _Popup_postRender: Popup.prototype.postRender,
  26730. postRender: function () {
  26731. var me = this
  26732. for (var i = 0; i < this.items.length; i++) {
  26733. var item = this.items[i]
  26734. item.ownerMenu = this
  26735. item.postRender()
  26736. }
  26737. domUtils.on(this.getDom(), 'mouseover', function (evt) {
  26738. evt = evt || event
  26739. var rel = evt.relatedTarget || evt.fromElement
  26740. var el = me.getDom()
  26741. if (!uiUtils.contains(el, rel) && el !== rel) {
  26742. me.fireEvent('over')
  26743. }
  26744. })
  26745. this._Popup_postRender()
  26746. },
  26747. queryAutoHide: function (el) {
  26748. if (el) {
  26749. if (uiUtils.contains(this.getDom(), el)) {
  26750. return false
  26751. }
  26752. for (var i = 0; i < this.items.length; i++) {
  26753. var item = this.items[i]
  26754. if (item.queryAutoHide(el) === false) {
  26755. return false
  26756. }
  26757. }
  26758. }
  26759. },
  26760. clearItems: function () {
  26761. for (var i = 0; i < this.items.length; i++) {
  26762. var item = this.items[i]
  26763. clearTimeout(item._showingTimer)
  26764. clearTimeout(item._closingTimer)
  26765. if (item.subMenu) {
  26766. item.subMenu.destroy()
  26767. }
  26768. }
  26769. this.items = []
  26770. },
  26771. destroy: function () {
  26772. if (this.getDom()) {
  26773. domUtils.remove(this.getDom())
  26774. }
  26775. this.clearItems()
  26776. },
  26777. dispose: function () {
  26778. this.destroy()
  26779. }
  26780. }
  26781. utils.inherits(Menu, Popup)
  26782. /**
  26783. * @update 2013/04/03 hancong03 新增一个参数menu, 该参数存储了menuItem所对应的menu引用
  26784. * @type {Function}
  26785. */
  26786. var MenuItem = (baidu.editor.ui.MenuItem = function (options) {
  26787. this.initOptions(options)
  26788. this.initUIBase()
  26789. this.Stateful_init()
  26790. if (this.subMenu && !(this.subMenu instanceof Menu)) {
  26791. if (options.className && options.className.indexOf('aligntd') != -1) {
  26792. var me = this
  26793. //获取单元格对齐初始状态
  26794. this.subMenu.selected = this.editor.queryCommandValue('cellalignment')
  26795. this.subMenu = new Popup({
  26796. content: new CellAlignPicker(this.subMenu),
  26797. parentMenu: me,
  26798. editor: me.editor,
  26799. destroy: function () {
  26800. if (this.getDom()) {
  26801. domUtils.remove(this.getDom())
  26802. }
  26803. }
  26804. })
  26805. this.subMenu.addListener('postRenderAfter', function () {
  26806. domUtils.on(this.getDom(), 'mouseover', function () {
  26807. me.addState('opened')
  26808. })
  26809. })
  26810. } else {
  26811. this.subMenu = new Menu(this.subMenu)
  26812. }
  26813. }
  26814. })
  26815. MenuItem.prototype = {
  26816. label: '',
  26817. subMenu: null,
  26818. ownerMenu: null,
  26819. uiName: 'menuitem',
  26820. alwalysHoverable: true,
  26821. getHtmlTpl: function () {
  26822. return (
  26823. '<div id="##" class="%%" stateful onclick="$$._onClick(event, this);">' +
  26824. '<div class="%%-body">' +
  26825. this.renderLabelHtml() +
  26826. '</div>' +
  26827. '</div>'
  26828. )
  26829. },
  26830. postRender: function () {
  26831. var me = this
  26832. this.addListener('over', function () {
  26833. me.ownerMenu.fireEvent('submenuover', me)
  26834. if (me.subMenu) {
  26835. me.delayShowSubMenu()
  26836. }
  26837. })
  26838. if (this.subMenu) {
  26839. this.getDom().className += ' edui-hassubmenu'
  26840. this.subMenu.render()
  26841. this.addListener('out', function () {
  26842. me.delayHideSubMenu()
  26843. })
  26844. this.subMenu.addListener('over', function () {
  26845. clearTimeout(me._closingTimer)
  26846. me._closingTimer = null
  26847. me.addState('opened')
  26848. })
  26849. this.ownerMenu.addListener('hide', function () {
  26850. me.hideSubMenu()
  26851. })
  26852. this.ownerMenu.addListener('submenuover', function (t, subMenu) {
  26853. if (subMenu !== me) {
  26854. me.delayHideSubMenu()
  26855. }
  26856. })
  26857. this.subMenu._bakQueryAutoHide = this.subMenu.queryAutoHide
  26858. this.subMenu.queryAutoHide = function (el) {
  26859. if (el && uiUtils.contains(me.getDom(), el)) {
  26860. return false
  26861. }
  26862. return this._bakQueryAutoHide(el)
  26863. }
  26864. }
  26865. this.getDom().style.tabIndex = '-1'
  26866. uiUtils.makeUnselectable(this.getDom())
  26867. this.Stateful_postRender()
  26868. },
  26869. delayShowSubMenu: function () {
  26870. var me = this
  26871. if (!me.isDisabled()) {
  26872. me.addState('opened')
  26873. clearTimeout(me._showingTimer)
  26874. clearTimeout(me._closingTimer)
  26875. me._closingTimer = null
  26876. me._showingTimer = setTimeout(function () {
  26877. me.showSubMenu()
  26878. }, 250)
  26879. }
  26880. },
  26881. delayHideSubMenu: function () {
  26882. var me = this
  26883. if (!me.isDisabled()) {
  26884. me.removeState('opened')
  26885. clearTimeout(me._showingTimer)
  26886. if (!me._closingTimer) {
  26887. me._closingTimer = setTimeout(function () {
  26888. if (!me.hasState('opened')) {
  26889. me.hideSubMenu()
  26890. }
  26891. me._closingTimer = null
  26892. }, 400)
  26893. }
  26894. }
  26895. },
  26896. renderLabelHtml: function () {
  26897. return (
  26898. '<div class="edui-arrow"></div>' +
  26899. '<div class="edui-box edui-icon"></div>' +
  26900. '<div class="edui-box edui-label %%-label">' +
  26901. (this.label || '') +
  26902. '</div>'
  26903. )
  26904. },
  26905. getStateDom: function () {
  26906. return this.getDom()
  26907. },
  26908. queryAutoHide: function (el) {
  26909. if (this.subMenu && this.hasState('opened')) {
  26910. return this.subMenu.queryAutoHide(el)
  26911. }
  26912. },
  26913. _onClick: function (event, this_) {
  26914. if (this.hasState('disabled')) return
  26915. if (this.fireEvent('click', event, this_) !== false) {
  26916. if (this.subMenu) {
  26917. this.showSubMenu()
  26918. } else {
  26919. Popup.postHide(event)
  26920. }
  26921. }
  26922. },
  26923. showSubMenu: function () {
  26924. var rect = uiUtils.getClientRect(this.getDom())
  26925. rect.right -= 5
  26926. rect.left += 2
  26927. rect.width -= 7
  26928. rect.top -= 4
  26929. rect.bottom += 4
  26930. rect.height += 8
  26931. this.subMenu.showAnchorRect(rect, true, true)
  26932. },
  26933. hideSubMenu: function () {
  26934. this.subMenu.hide()
  26935. }
  26936. }
  26937. utils.inherits(MenuItem, UIBase)
  26938. utils.extend(MenuItem.prototype, Stateful, true)
  26939. })()
  26940. // ui/combox.js
  26941. ///import core
  26942. ///import uicore
  26943. ///import ui/menu.js
  26944. ///import ui/splitbutton.js
  26945. ;(function () {
  26946. // todo: menu和item提成通用list
  26947. var utils = baidu.editor.utils,
  26948. uiUtils = baidu.editor.ui.uiUtils,
  26949. Menu = baidu.editor.ui.Menu,
  26950. SplitButton = baidu.editor.ui.SplitButton,
  26951. Combox = (baidu.editor.ui.Combox = function (options) {
  26952. this.initOptions(options)
  26953. this.initCombox()
  26954. })
  26955. Combox.prototype = {
  26956. uiName: 'combox',
  26957. onbuttonclick: function () {
  26958. this.showPopup()
  26959. },
  26960. initCombox: function () {
  26961. var me = this
  26962. this.items = this.items || []
  26963. for (var i = 0; i < this.items.length; i++) {
  26964. var item = this.items[i]
  26965. item.uiName = 'listitem'
  26966. item.index = i
  26967. item.onclick = function () {
  26968. me.selectByIndex(this.index)
  26969. }
  26970. }
  26971. this.popup = new Menu({
  26972. items: this.items,
  26973. uiName: 'list',
  26974. editor: this.editor,
  26975. captureWheel: true,
  26976. combox: this
  26977. })
  26978. this.initSplitButton()
  26979. },
  26980. _SplitButton_postRender: SplitButton.prototype.postRender,
  26981. postRender: function () {
  26982. this._SplitButton_postRender()
  26983. this.setLabel(this.label || '')
  26984. this.setValue(this.initValue || '')
  26985. },
  26986. showPopup: function () {
  26987. var rect = uiUtils.getClientRect(this.getDom())
  26988. rect.top += 1
  26989. rect.bottom -= 1
  26990. rect.height -= 2
  26991. this.popup.showAnchorRect(rect)
  26992. },
  26993. getValue: function () {
  26994. return this.value
  26995. },
  26996. setValue: function (value) {
  26997. var index = this.indexByValue(value)
  26998. if (index != -1) {
  26999. this.selectedIndex = index
  27000. this.setLabel(this.items[index].label)
  27001. this.value = this.items[index].value
  27002. } else {
  27003. this.selectedIndex = -1
  27004. this.setLabel(this.getLabelForUnknowValue(value))
  27005. this.value = value
  27006. }
  27007. },
  27008. setLabel: function (label) {
  27009. this.getDom('button_body').innerHTML = label
  27010. this.label = label
  27011. },
  27012. getLabelForUnknowValue: function (value) {
  27013. return value
  27014. },
  27015. indexByValue: function (value) {
  27016. for (var i = 0; i < this.items.length; i++) {
  27017. if (value == this.items[i].value) {
  27018. return i
  27019. }
  27020. }
  27021. return -1
  27022. },
  27023. getItem: function (index) {
  27024. return this.items[index]
  27025. },
  27026. selectByIndex: function (index) {
  27027. if (index < this.items.length && this.fireEvent('select', index) !== false) {
  27028. this.selectedIndex = index
  27029. this.value = this.items[index].value
  27030. this.setLabel(this.items[index].label)
  27031. }
  27032. }
  27033. }
  27034. utils.inherits(Combox, SplitButton)
  27035. })()
  27036. // ui/dialog.js
  27037. ///import core
  27038. ///import uicore
  27039. ///import ui/mask.js
  27040. ///import ui/button.js
  27041. ;(function () {
  27042. var utils = baidu.editor.utils,
  27043. domUtils = baidu.editor.dom.domUtils,
  27044. uiUtils = baidu.editor.ui.uiUtils,
  27045. Mask = baidu.editor.ui.Mask,
  27046. UIBase = baidu.editor.ui.UIBase,
  27047. Button = baidu.editor.ui.Button,
  27048. Dialog = (baidu.editor.ui.Dialog = function (options) {
  27049. if (options.name) {
  27050. var name = options.name
  27051. var cssRules = options.cssRules
  27052. if (!options.className) {
  27053. options.className = 'edui-for-' + name
  27054. }
  27055. if (cssRules) {
  27056. options.cssRules =
  27057. '.edui-default .edui-for-' + name + ' .edui-dialog-content {' + cssRules + '}'
  27058. }
  27059. }
  27060. this.initOptions(
  27061. utils.extend(
  27062. {
  27063. autoReset: true,
  27064. draggable: true,
  27065. onok: function () {},
  27066. oncancel: function () {},
  27067. onclose: function (t, ok) {
  27068. return ok ? this.onok() : this.oncancel()
  27069. },
  27070. //是否控制dialog中的scroll事件, 默认为不阻止
  27071. holdScroll: false
  27072. },
  27073. options
  27074. )
  27075. )
  27076. this.initDialog()
  27077. })
  27078. var modalMask
  27079. var dragMask
  27080. var activeDialog
  27081. Dialog.prototype = {
  27082. draggable: false,
  27083. uiName: 'dialog',
  27084. initDialog: function () {
  27085. var me = this,
  27086. theme = this.editor.options.theme
  27087. if (this.cssRules) {
  27088. utils.cssRule('edui-customize-' + this.name + '-style', this.cssRules)
  27089. }
  27090. this.initUIBase()
  27091. this.modalMask =
  27092. modalMask ||
  27093. (modalMask = new Mask({
  27094. className: 'edui-dialog-modalmask',
  27095. theme: theme,
  27096. onclick: function () {
  27097. activeDialog && activeDialog.close(false)
  27098. }
  27099. }))
  27100. this.dragMask =
  27101. dragMask ||
  27102. (dragMask = new Mask({
  27103. className: 'edui-dialog-dragmask',
  27104. theme: theme
  27105. }))
  27106. this.closeButton = new Button({
  27107. className: 'edui-dialog-closebutton',
  27108. title: me.closeDialog,
  27109. theme: theme,
  27110. onclick: function () {
  27111. me.close(false)
  27112. }
  27113. })
  27114. this.fullscreen && this.initResizeEvent()
  27115. if (this.buttons) {
  27116. for (var i = 0; i < this.buttons.length; i++) {
  27117. if (!(this.buttons[i] instanceof Button)) {
  27118. this.buttons[i] = new Button(
  27119. utils.extend(
  27120. this.buttons[i],
  27121. {
  27122. editor: this.editor
  27123. },
  27124. true
  27125. )
  27126. )
  27127. }
  27128. }
  27129. }
  27130. },
  27131. initResizeEvent: function () {
  27132. var me = this
  27133. domUtils.on(window, 'resize', function () {
  27134. if (me._hidden || me._hidden === undefined) {
  27135. return
  27136. }
  27137. if (me.__resizeTimer) {
  27138. window.clearTimeout(me.__resizeTimer)
  27139. }
  27140. me.__resizeTimer = window.setTimeout(function () {
  27141. me.__resizeTimer = null
  27142. var dialogWrapNode = me.getDom(),
  27143. contentNode = me.getDom('content'),
  27144. wrapRect = UE.ui.uiUtils.getClientRect(dialogWrapNode),
  27145. contentRect = UE.ui.uiUtils.getClientRect(contentNode),
  27146. vpRect = uiUtils.getViewportRect()
  27147. contentNode.style.width = vpRect.width - wrapRect.width + contentRect.width + 'px'
  27148. contentNode.style.height = vpRect.height - wrapRect.height + contentRect.height + 'px'
  27149. dialogWrapNode.style.width = vpRect.width + 'px'
  27150. dialogWrapNode.style.height = vpRect.height + 'px'
  27151. me.fireEvent('resize')
  27152. }, 100)
  27153. })
  27154. },
  27155. fitSize: function () {
  27156. var popBodyEl = this.getDom('body')
  27157. // if (!(baidu.editor.browser.ie && baidu.editor.browser.version == 7)) {
  27158. // uiUtils.removeStyle(popBodyEl, 'width');
  27159. // uiUtils.removeStyle(popBodyEl, 'height');
  27160. // }
  27161. var size = this.mesureSize()
  27162. popBodyEl.style.width = size.width + 'px'
  27163. popBodyEl.style.height = size.height + 'px'
  27164. return size
  27165. },
  27166. safeSetOffset: function (offset) {
  27167. var me = this
  27168. var el = me.getDom()
  27169. var vpRect = uiUtils.getViewportRect()
  27170. var rect = uiUtils.getClientRect(el)
  27171. var left = offset.left
  27172. if (left + rect.width > vpRect.right) {
  27173. left = vpRect.right - rect.width
  27174. }
  27175. var top = offset.top
  27176. if (top + rect.height > vpRect.bottom) {
  27177. top = vpRect.bottom - rect.height
  27178. }
  27179. el.style.left = Math.max(left, 0) + 'px'
  27180. el.style.top = Math.max(top, 0) + 'px'
  27181. },
  27182. showAtCenter: function () {
  27183. var vpRect = uiUtils.getViewportRect()
  27184. if (!this.fullscreen) {
  27185. this.getDom().style.display = ''
  27186. var popSize = this.fitSize()
  27187. var titleHeight = this.getDom('titlebar').offsetHeight | 0
  27188. var left = vpRect.width / 2 - popSize.width / 2
  27189. var top = vpRect.height / 2 - (popSize.height - titleHeight) / 2 - titleHeight
  27190. var popEl = this.getDom()
  27191. this.safeSetOffset({
  27192. left: Math.max(left | 0, 0),
  27193. top: Math.max(top | 0, 0)
  27194. })
  27195. if (!domUtils.hasClass(popEl, 'edui-state-centered')) {
  27196. popEl.className += ' edui-state-centered'
  27197. }
  27198. } else {
  27199. var dialogWrapNode = this.getDom(),
  27200. contentNode = this.getDom('content')
  27201. dialogWrapNode.style.display = 'block'
  27202. var wrapRect = UE.ui.uiUtils.getClientRect(dialogWrapNode),
  27203. contentRect = UE.ui.uiUtils.getClientRect(contentNode)
  27204. dialogWrapNode.style.left = '-100000px'
  27205. contentNode.style.width = vpRect.width - wrapRect.width + contentRect.width + 'px'
  27206. contentNode.style.height = vpRect.height - wrapRect.height + contentRect.height + 'px'
  27207. dialogWrapNode.style.width = vpRect.width + 'px'
  27208. dialogWrapNode.style.height = vpRect.height + 'px'
  27209. dialogWrapNode.style.left = 0
  27210. //保存环境的overflow值
  27211. this._originalContext = {
  27212. html: {
  27213. overflowX: document.documentElement.style.overflowX,
  27214. overflowY: document.documentElement.style.overflowY
  27215. },
  27216. body: {
  27217. overflowX: document.body.style.overflowX,
  27218. overflowY: document.body.style.overflowY
  27219. }
  27220. }
  27221. document.documentElement.style.overflowX = 'hidden'
  27222. document.documentElement.style.overflowY = 'hidden'
  27223. document.body.style.overflowX = 'hidden'
  27224. document.body.style.overflowY = 'hidden'
  27225. }
  27226. this._show()
  27227. },
  27228. getContentHtml: function () {
  27229. var contentHtml = ''
  27230. if (typeof this.content == 'string') {
  27231. contentHtml = this.content
  27232. } else if (this.iframeUrl) {
  27233. contentHtml =
  27234. '<span id="' +
  27235. this.id +
  27236. '_contmask" class="dialogcontmask"></span><iframe id="' +
  27237. this.id +
  27238. '_iframe" class="%%-iframe" height="100%" width="100%" frameborder="0" src="' +
  27239. this.iframeUrl +
  27240. '"></iframe>'
  27241. }
  27242. return contentHtml
  27243. },
  27244. getHtmlTpl: function () {
  27245. var footHtml = ''
  27246. if (this.buttons) {
  27247. var buff = []
  27248. for (var i = 0; i < this.buttons.length; i++) {
  27249. buff[i] = this.buttons[i].renderHtml()
  27250. }
  27251. footHtml =
  27252. '<div class="%%-foot">' +
  27253. '<div id="##_buttons" class="%%-buttons">' +
  27254. buff.join('') +
  27255. '</div>' +
  27256. '</div>'
  27257. }
  27258. return (
  27259. '<div id="##" class="%%"><div ' +
  27260. (!this.fullscreen ? 'class="%%"' : 'class="%%-wrap edui-dialog-fullscreen-flag"') +
  27261. '><div id="##_body" class="%%-body">' +
  27262. '<div class="%%-shadow"></div>' +
  27263. '<div id="##_titlebar" class="%%-titlebar">' +
  27264. '<div class="%%-draghandle" onmousedown="$$._onTitlebarMouseDown(event, this);">' +
  27265. '<span class="%%-caption">' +
  27266. (this.title || '') +
  27267. '</span>' +
  27268. '</div>' +
  27269. this.closeButton.renderHtml() +
  27270. '</div>' +
  27271. '<div id="##_content" class="%%-content">' +
  27272. (this.autoReset ? '' : this.getContentHtml()) +
  27273. '</div>' +
  27274. footHtml +
  27275. '</div></div></div>'
  27276. )
  27277. },
  27278. postRender: function () {
  27279. // todo: 保持居中/记住上次关闭位置选项
  27280. if (!this.modalMask.getDom()) {
  27281. this.modalMask.render()
  27282. this.modalMask.hide()
  27283. }
  27284. if (!this.dragMask.getDom()) {
  27285. this.dragMask.render()
  27286. this.dragMask.hide()
  27287. }
  27288. var me = this
  27289. this.addListener('show', function () {
  27290. me.modalMask.show(this.getDom().style.zIndex - 2)
  27291. })
  27292. this.addListener('hide', function () {
  27293. me.modalMask.hide()
  27294. })
  27295. if (this.buttons) {
  27296. for (var i = 0; i < this.buttons.length; i++) {
  27297. this.buttons[i].postRender()
  27298. }
  27299. }
  27300. domUtils.on(window, 'resize', function () {
  27301. setTimeout(function () {
  27302. if (!me.isHidden()) {
  27303. me.safeSetOffset(uiUtils.getClientRect(me.getDom()))
  27304. }
  27305. })
  27306. })
  27307. //hold住scroll事件,防止dialog的滚动影响页面
  27308. // if( this.holdScroll ) {
  27309. //
  27310. // if( !me.iframeUrl ) {
  27311. // domUtils.on( document.getElementById( me.id + "_iframe"), !browser.gecko ? "mousewheel" : "DOMMouseScroll", function(e){
  27312. // domUtils.preventDefault(e);
  27313. // } );
  27314. // } else {
  27315. // me.addListener('dialogafterreset', function(){
  27316. // window.setTimeout(function(){
  27317. // var iframeWindow = document.getElementById( me.id + "_iframe").contentWindow;
  27318. //
  27319. // if( browser.ie ) {
  27320. //
  27321. // var timer = window.setInterval(function(){
  27322. //
  27323. // if( iframeWindow.document && iframeWindow.document.body ) {
  27324. // window.clearInterval( timer );
  27325. // timer = null;
  27326. // domUtils.on( iframeWindow.document.body, !browser.gecko ? "mousewheel" : "DOMMouseScroll", function(e){
  27327. // domUtils.preventDefault(e);
  27328. // } );
  27329. // }
  27330. //
  27331. // }, 100);
  27332. //
  27333. // } else {
  27334. // domUtils.on( iframeWindow, !browser.gecko ? "mousewheel" : "DOMMouseScroll", function(e){
  27335. // domUtils.preventDefault(e);
  27336. // } );
  27337. // }
  27338. //
  27339. // }, 1);
  27340. // });
  27341. // }
  27342. //
  27343. // }
  27344. this._hide()
  27345. },
  27346. mesureSize: function () {
  27347. var body = this.getDom('body')
  27348. var width = uiUtils.getClientRect(this.getDom('content')).width
  27349. var dialogBodyStyle = body.style
  27350. dialogBodyStyle.width = width
  27351. return uiUtils.getClientRect(body)
  27352. },
  27353. _onTitlebarMouseDown: function (evt, el) {
  27354. if (this.draggable) {
  27355. var rect
  27356. var vpRect = uiUtils.getViewportRect()
  27357. var me = this
  27358. uiUtils.startDrag(evt, {
  27359. ondragstart: function () {
  27360. rect = uiUtils.getClientRect(me.getDom())
  27361. me.getDom('contmask').style.visibility = 'visible'
  27362. me.dragMask.show(me.getDom().style.zIndex - 1)
  27363. },
  27364. ondragmove: function (x, y) {
  27365. var left = rect.left + x
  27366. var top = rect.top + y
  27367. me.safeSetOffset({
  27368. left: left,
  27369. top: top
  27370. })
  27371. },
  27372. ondragstop: function () {
  27373. me.getDom('contmask').style.visibility = 'hidden'
  27374. domUtils.removeClasses(me.getDom(), ['edui-state-centered'])
  27375. me.dragMask.hide()
  27376. }
  27377. })
  27378. }
  27379. },
  27380. reset: function () {
  27381. this.getDom('content').innerHTML = this.getContentHtml()
  27382. this.fireEvent('dialogafterreset')
  27383. },
  27384. _show: function () {
  27385. if (this._hidden) {
  27386. this.getDom().style.display = ''
  27387. //要高过编辑器的zindxe
  27388. this.editor.container.style.zIndex &&
  27389. (this.getDom().style.zIndex = this.editor.container.style.zIndex * 1 + 10)
  27390. this._hidden = false
  27391. this.fireEvent('show')
  27392. baidu.editor.ui.uiUtils.getFixedLayer().style.zIndex = this.getDom().style.zIndex - 4
  27393. }
  27394. },
  27395. isHidden: function () {
  27396. return this._hidden
  27397. },
  27398. _hide: function () {
  27399. if (!this._hidden) {
  27400. var wrapNode = this.getDom()
  27401. wrapNode.style.display = 'none'
  27402. wrapNode.style.zIndex = ''
  27403. wrapNode.style.width = ''
  27404. wrapNode.style.height = ''
  27405. this._hidden = true
  27406. this.fireEvent('hide')
  27407. }
  27408. },
  27409. open: function () {
  27410. if (this.autoReset) {
  27411. //有可能还没有渲染
  27412. try {
  27413. this.reset()
  27414. } catch (e) {
  27415. this.render()
  27416. this.open()
  27417. }
  27418. }
  27419. this.showAtCenter()
  27420. if (this.iframeUrl) {
  27421. try {
  27422. this.getDom('iframe').focus()
  27423. } catch (ex) {}
  27424. }
  27425. activeDialog = this
  27426. },
  27427. _onCloseButtonClick: function (evt, el) {
  27428. this.close(false)
  27429. },
  27430. close: function (ok) {
  27431. if (this.fireEvent('close', ok) !== false) {
  27432. //还原环境
  27433. if (this.fullscreen) {
  27434. document.documentElement.style.overflowX = this._originalContext.html.overflowX
  27435. document.documentElement.style.overflowY = this._originalContext.html.overflowY
  27436. document.body.style.overflowX = this._originalContext.body.overflowX
  27437. document.body.style.overflowY = this._originalContext.body.overflowY
  27438. delete this._originalContext
  27439. }
  27440. this._hide()
  27441. //销毁content
  27442. var content = this.getDom('content')
  27443. var iframe = this.getDom('iframe')
  27444. if (content && iframe) {
  27445. var doc = iframe.contentDocument || iframe.contentWindow.document
  27446. doc && (doc.body.innerHTML = '')
  27447. domUtils.remove(content)
  27448. }
  27449. }
  27450. }
  27451. }
  27452. utils.inherits(Dialog, UIBase)
  27453. })()
  27454. // ui/menubutton.js
  27455. ///import core
  27456. ///import uicore
  27457. ///import ui/menu.js
  27458. ///import ui/splitbutton.js
  27459. ;(function () {
  27460. var utils = baidu.editor.utils,
  27461. Menu = baidu.editor.ui.Menu,
  27462. SplitButton = baidu.editor.ui.SplitButton,
  27463. MenuButton = (baidu.editor.ui.MenuButton = function (options) {
  27464. this.initOptions(options)
  27465. this.initMenuButton()
  27466. })
  27467. MenuButton.prototype = {
  27468. initMenuButton: function () {
  27469. var me = this
  27470. this.uiName = 'menubutton'
  27471. this.popup = new Menu({
  27472. items: me.items,
  27473. className: me.className,
  27474. editor: me.editor
  27475. })
  27476. this.popup.addListener('show', function () {
  27477. var list = this
  27478. for (var i = 0; i < list.items.length; i++) {
  27479. list.items[i].removeState('checked')
  27480. if (list.items[i].value == me._value) {
  27481. list.items[i].addState('checked')
  27482. this.value = me._value
  27483. }
  27484. }
  27485. })
  27486. this.initSplitButton()
  27487. },
  27488. setValue: function (value) {
  27489. this._value = value
  27490. }
  27491. }
  27492. utils.inherits(MenuButton, SplitButton)
  27493. })()
  27494. // ui/multiMenu.js
  27495. ///import core
  27496. ///import uicore
  27497. ///commands 表情
  27498. ;(function () {
  27499. var utils = baidu.editor.utils,
  27500. Popup = baidu.editor.ui.Popup,
  27501. SplitButton = baidu.editor.ui.SplitButton,
  27502. MultiMenuPop = (baidu.editor.ui.MultiMenuPop = function (options) {
  27503. this.initOptions(options)
  27504. this.initMultiMenu()
  27505. })
  27506. MultiMenuPop.prototype = {
  27507. initMultiMenu: function () {
  27508. var me = this
  27509. this.popup = new Popup({
  27510. content: '',
  27511. editor: me.editor,
  27512. iframe_rendered: false,
  27513. onshow: function () {
  27514. if (!this.iframe_rendered) {
  27515. this.iframe_rendered = true
  27516. this.getDom('content').innerHTML =
  27517. '<iframe id="' +
  27518. me.id +
  27519. '_iframe" src="' +
  27520. me.iframeUrl +
  27521. '" frameborder="0"></iframe>'
  27522. me.editor.container.style.zIndex &&
  27523. (this.getDom().style.zIndex = me.editor.container.style.zIndex * 1 + 1)
  27524. }
  27525. }
  27526. // canSideUp:false,
  27527. // canSideLeft:false
  27528. })
  27529. this.onbuttonclick = function () {
  27530. this.showPopup()
  27531. }
  27532. this.initSplitButton()
  27533. }
  27534. }
  27535. utils.inherits(MultiMenuPop, SplitButton)
  27536. })()
  27537. // ui/shortcutmenu.js
  27538. ;(function () {
  27539. var UI = baidu.editor.ui,
  27540. UIBase = UI.UIBase,
  27541. uiUtils = UI.uiUtils,
  27542. utils = baidu.editor.utils,
  27543. domUtils = baidu.editor.dom.domUtils
  27544. var allMenus = [], //存储所有快捷菜单
  27545. timeID,
  27546. isSubMenuShow = false //是否有子pop显示
  27547. var ShortCutMenu = (UI.ShortCutMenu = function (options) {
  27548. this.initOptions(options)
  27549. this.initShortCutMenu()
  27550. })
  27551. ShortCutMenu.postHide = hideAllMenu
  27552. ShortCutMenu.prototype = {
  27553. isHidden: true,
  27554. SPACE: 5,
  27555. initShortCutMenu: function () {
  27556. this.items = this.items || []
  27557. this.initUIBase()
  27558. this.initItems()
  27559. this.initEvent()
  27560. allMenus.push(this)
  27561. },
  27562. initEvent: function () {
  27563. var me = this,
  27564. doc = me.editor.document
  27565. domUtils.on(doc, 'mousemove', function (e) {
  27566. if (me.isHidden === false) {
  27567. //有pop显示就不隐藏快捷菜单
  27568. if (me.getSubMenuMark() || me.eventType == 'contextmenu') return
  27569. var flag = true,
  27570. el = me.getDom(),
  27571. wt = el.offsetWidth,
  27572. ht = el.offsetHeight,
  27573. distanceX = wt / 2 + me.SPACE, //距离中心X标准
  27574. distanceY = ht / 2, //距离中心Y标准
  27575. x = Math.abs(e.screenX - me.left), //离中心距离横坐标
  27576. y = Math.abs(e.screenY - me.top) //离中心距离纵坐标
  27577. clearTimeout(timeID)
  27578. timeID = setTimeout(function () {
  27579. if (y > 0 && y < distanceY) {
  27580. me.setOpacity(el, '1')
  27581. } else if (y > distanceY && y < distanceY + 70) {
  27582. me.setOpacity(el, '0.5')
  27583. flag = false
  27584. } else if (y > distanceY + 70 && y < distanceY + 140) {
  27585. me.hide()
  27586. }
  27587. if (flag && x > 0 && x < distanceX) {
  27588. me.setOpacity(el, '1')
  27589. } else if (x > distanceX && x < distanceX + 70) {
  27590. me.setOpacity(el, '0.5')
  27591. } else if (x > distanceX + 70 && x < distanceX + 140) {
  27592. me.hide()
  27593. }
  27594. })
  27595. }
  27596. })
  27597. //ie\ff下 mouseout不准
  27598. if (browser.chrome) {
  27599. domUtils.on(doc, 'mouseout', function (e) {
  27600. var relatedTgt = e.relatedTarget || e.toElement
  27601. if (relatedTgt == null || relatedTgt.tagName == 'HTML') {
  27602. me.hide()
  27603. }
  27604. })
  27605. }
  27606. me.editor.addListener('afterhidepop', function () {
  27607. if (!me.isHidden) {
  27608. isSubMenuShow = true
  27609. }
  27610. })
  27611. },
  27612. initItems: function () {
  27613. if (utils.isArray(this.items)) {
  27614. for (var i = 0, len = this.items.length; i < len; i++) {
  27615. var item = this.items[i].toLowerCase()
  27616. if (UI[item]) {
  27617. this.items[i] = new UI[item](this.editor)
  27618. this.items[i].className += ' edui-shortcutsubmenu '
  27619. }
  27620. }
  27621. }
  27622. },
  27623. setOpacity: function (el, value) {
  27624. if (browser.ie && browser.version < 9) {
  27625. el.style.filter = 'alpha(opacity = ' + parseFloat(value) * 100 + ');'
  27626. } else {
  27627. el.style.opacity = value
  27628. }
  27629. },
  27630. getSubMenuMark: function () {
  27631. isSubMenuShow = false
  27632. var layerEle = uiUtils.getFixedLayer()
  27633. var list = domUtils.getElementsByTagName(layerEle, 'div', function (node) {
  27634. return domUtils.hasClass(node, 'edui-shortcutsubmenu edui-popup')
  27635. })
  27636. for (var i = 0, node; (node = list[i++]); ) {
  27637. if (node.style.display != 'none') {
  27638. isSubMenuShow = true
  27639. }
  27640. }
  27641. return isSubMenuShow
  27642. },
  27643. show: function (e, hasContextmenu) {
  27644. var me = this,
  27645. offset = {},
  27646. el = this.getDom(),
  27647. fixedlayer = uiUtils.getFixedLayer()
  27648. function setPos(offset) {
  27649. if (offset.left < 0) {
  27650. offset.left = 0
  27651. }
  27652. if (offset.top < 0) {
  27653. offset.top = 0
  27654. }
  27655. el.style.cssText =
  27656. 'position:absolute;left:' + offset.left + 'px;top:' + offset.top + 'px;'
  27657. }
  27658. function setPosByCxtMenu(menu) {
  27659. if (!menu.tagName) {
  27660. menu = menu.getDom()
  27661. }
  27662. offset.left = parseInt(menu.style.left)
  27663. offset.top = parseInt(menu.style.top)
  27664. offset.top -= el.offsetHeight + 15
  27665. setPos(offset)
  27666. }
  27667. me.eventType = e.type
  27668. el.style.cssText = 'display:block;left:-9999px'
  27669. if (e.type == 'contextmenu' && hasContextmenu) {
  27670. var menu = domUtils.getElementsByTagName(fixedlayer, 'div', 'edui-contextmenu')[0]
  27671. if (menu) {
  27672. setPosByCxtMenu(menu)
  27673. } else {
  27674. me.editor.addListener('aftershowcontextmenu', function (type, menu) {
  27675. setPosByCxtMenu(menu)
  27676. })
  27677. }
  27678. } else {
  27679. offset = uiUtils.getViewportOffsetByEvent(e)
  27680. offset.top -= el.offsetHeight + me.SPACE
  27681. offset.left += me.SPACE + 20
  27682. setPos(offset)
  27683. me.setOpacity(el, 0.2)
  27684. }
  27685. me.isHidden = false
  27686. me.left = e.screenX + el.offsetWidth / 2 - me.SPACE
  27687. me.top = e.screenY - el.offsetHeight / 2 - me.SPACE
  27688. if (me.editor) {
  27689. el.style.zIndex = me.editor.container.style.zIndex * 1 + 10
  27690. fixedlayer.style.zIndex = el.style.zIndex - 1
  27691. }
  27692. },
  27693. hide: function () {
  27694. if (this.getDom()) {
  27695. this.getDom().style.display = 'none'
  27696. }
  27697. this.isHidden = true
  27698. },
  27699. postRender: function () {
  27700. if (utils.isArray(this.items)) {
  27701. for (var i = 0, item; (item = this.items[i++]); ) {
  27702. item.postRender()
  27703. }
  27704. }
  27705. },
  27706. getHtmlTpl: function () {
  27707. var buff
  27708. if (utils.isArray(this.items)) {
  27709. buff = []
  27710. for (var i = 0; i < this.items.length; i++) {
  27711. buff[i] = this.items[i].renderHtml()
  27712. }
  27713. buff = buff.join('')
  27714. } else {
  27715. buff = this.items
  27716. }
  27717. return (
  27718. '<div id="##" class="%% edui-toolbar" data-src="shortcutmenu" onmousedown="return false;" onselectstart="return false;" >' +
  27719. buff +
  27720. '</div>'
  27721. )
  27722. }
  27723. }
  27724. utils.inherits(ShortCutMenu, UIBase)
  27725. function hideAllMenu(e) {
  27726. var tgt = e.target || e.srcElement,
  27727. cur = domUtils.findParent(
  27728. tgt,
  27729. function (node) {
  27730. return (
  27731. domUtils.hasClass(node, 'edui-shortcutmenu') || domUtils.hasClass(node, 'edui-popup')
  27732. )
  27733. },
  27734. true
  27735. )
  27736. if (!cur) {
  27737. for (var i = 0, menu; (menu = allMenus[i++]); ) {
  27738. menu.hide()
  27739. }
  27740. }
  27741. }
  27742. domUtils.on(document, 'mousedown', function (e) {
  27743. hideAllMenu(e)
  27744. })
  27745. domUtils.on(window, 'scroll', function (e) {
  27746. hideAllMenu(e)
  27747. })
  27748. })()
  27749. // ui/breakline.js
  27750. ;(function () {
  27751. var utils = baidu.editor.utils,
  27752. UIBase = baidu.editor.ui.UIBase,
  27753. Breakline = (baidu.editor.ui.Breakline = function (options) {
  27754. this.initOptions(options)
  27755. this.initSeparator()
  27756. })
  27757. Breakline.prototype = {
  27758. uiName: 'Breakline',
  27759. initSeparator: function () {
  27760. this.initUIBase()
  27761. },
  27762. getHtmlTpl: function () {
  27763. return '<br/>'
  27764. }
  27765. }
  27766. utils.inherits(Breakline, UIBase)
  27767. })()
  27768. // ui/message.js
  27769. ///import core
  27770. ///import uicore
  27771. ;(function () {
  27772. var utils = baidu.editor.utils,
  27773. domUtils = baidu.editor.dom.domUtils,
  27774. UIBase = baidu.editor.ui.UIBase,
  27775. Message = (baidu.editor.ui.Message = function (options) {
  27776. this.initOptions(options)
  27777. this.initMessage()
  27778. })
  27779. Message.prototype = {
  27780. initMessage: function () {
  27781. this.initUIBase()
  27782. },
  27783. getHtmlTpl: function () {
  27784. return (
  27785. '<div id="##" class="edui-message %%">' +
  27786. ' <div id="##_closer" class="edui-message-closer">×</div>' +
  27787. ' <div id="##_body" class="edui-message-body edui-message-type-info">' +
  27788. ' <iframe style="position:absolute;z-index:-1;left:0;top:0;background-color: transparent;" frameborder="0" width="100%" height="100%" src="about:blank"></iframe>' +
  27789. ' <div class="edui-shadow"></div>' +
  27790. ' <div id="##_content" class="edui-message-content">' +
  27791. ' </div>' +
  27792. ' </div>' +
  27793. '</div>'
  27794. )
  27795. },
  27796. reset: function (opt) {
  27797. var me = this
  27798. if (!opt.keepshow) {
  27799. clearTimeout(this.timer)
  27800. me.timer = setTimeout(function () {
  27801. me.hide()
  27802. }, opt.timeout || 4000)
  27803. }
  27804. opt.content !== undefined && me.setContent(opt.content)
  27805. opt.type !== undefined && me.setType(opt.type)
  27806. me.show()
  27807. },
  27808. postRender: function () {
  27809. var me = this,
  27810. closer = this.getDom('closer')
  27811. closer &&
  27812. domUtils.on(closer, 'click', function () {
  27813. me.hide()
  27814. })
  27815. },
  27816. setContent: function (content) {
  27817. this.getDom('content').innerHTML = content
  27818. },
  27819. setType: function (type) {
  27820. type = type || 'info'
  27821. var body = this.getDom('body')
  27822. body.className = body.className.replace(
  27823. /edui-message-type-[\w-]+/,
  27824. 'edui-message-type-' + type
  27825. )
  27826. },
  27827. getContent: function () {
  27828. return this.getDom('content').innerHTML
  27829. },
  27830. getType: function () {
  27831. var arr = this.getDom('body').match(/edui-message-type-([\w-]+)/)
  27832. return arr ? arr[1] : ''
  27833. },
  27834. show: function () {
  27835. this.getDom().style.display = 'block'
  27836. },
  27837. hide: function () {
  27838. var dom = this.getDom()
  27839. if (dom) {
  27840. dom.style.display = 'none'
  27841. dom.parentNode && dom.parentNode.removeChild(dom)
  27842. }
  27843. }
  27844. }
  27845. utils.inherits(Message, UIBase)
  27846. })()
  27847. // adapter/editorui.js
  27848. //ui跟编辑器的适配層
  27849. //那个按钮弹出是dialog,是下拉筐等都是在这个js中配置
  27850. //自己写的ui也要在这里配置,放到baidu.editor.ui下边,当编辑器实例化的时候会根据ueditor.config中的toolbars找到相应的进行实例化
  27851. ;(function () {
  27852. var utils = baidu.editor.utils
  27853. var editorui = baidu.editor.ui
  27854. var _Dialog = editorui.Dialog
  27855. editorui.buttons = {}
  27856. editorui.Dialog = function (options) {
  27857. var dialog = new _Dialog(options)
  27858. dialog.addListener('hide', function () {
  27859. if (dialog.editor) {
  27860. var editor = dialog.editor
  27861. try {
  27862. if (browser.gecko) {
  27863. var y = editor.window.scrollY,
  27864. x = editor.window.scrollX
  27865. editor.body.focus()
  27866. editor.window.scrollTo(x, y)
  27867. } else {
  27868. editor.focus()
  27869. }
  27870. } catch (ex) {}
  27871. }
  27872. })
  27873. return dialog
  27874. }
  27875. var iframeUrlMap = {
  27876. anchor: '~/dialogs/anchor/anchor.html',
  27877. insertimage: '~/dialogs/image/image.html',
  27878. link: '~/dialogs/link/link.html',
  27879. spechars: '~/dialogs/spechars/spechars.html',
  27880. searchreplace: '~/dialogs/searchreplace/searchreplace.html',
  27881. map: '~/dialogs/map/map.html',
  27882. gmap: '~/dialogs/gmap/gmap.html',
  27883. insertvideo: '~/dialogs/video/video.html',
  27884. help: '~/dialogs/help/help.html',
  27885. preview: '~/dialogs/preview/preview.html',
  27886. emotion: '~/dialogs/emotion/emotion.html',
  27887. wordimage: '~/dialogs/wordimage/wordimage.html',
  27888. attachment: '~/dialogs/attachment/attachment.html',
  27889. insertframe: '~/dialogs/insertframe/insertframe.html',
  27890. edittip: '~/dialogs/table/edittip.html',
  27891. edittable: '~/dialogs/table/edittable.html',
  27892. edittd: '~/dialogs/table/edittd.html',
  27893. webapp: '~/dialogs/webapp/webapp.html',
  27894. snapscreen: '~/dialogs/snapscreen/snapscreen.html',
  27895. scrawl: '~/dialogs/scrawl/scrawl.html',
  27896. music: '~/dialogs/music/music.html',
  27897. template: '~/dialogs/template/template.html',
  27898. background: '~/dialogs/background/background.html',
  27899. charts: '~/dialogs/charts/charts.html'
  27900. }
  27901. //为工具栏添加按钮,以下都是统一的按钮触发命令,所以写在一起
  27902. var btnCmds = [
  27903. 'undo',
  27904. 'redo',
  27905. 'formatmatch',
  27906. 'bold',
  27907. 'italic',
  27908. 'underline',
  27909. 'fontborder',
  27910. 'touppercase',
  27911. 'tolowercase',
  27912. 'strikethrough',
  27913. 'subscript',
  27914. 'superscript',
  27915. 'source',
  27916. 'indent',
  27917. 'outdent',
  27918. 'blockquote',
  27919. 'pasteplain',
  27920. 'pagebreak',
  27921. 'selectall',
  27922. 'print',
  27923. 'horizontal',
  27924. 'removeformat',
  27925. 'time',
  27926. 'date',
  27927. 'unlink',
  27928. 'insertparagraphbeforetable',
  27929. 'insertrow',
  27930. 'insertcol',
  27931. 'mergeright',
  27932. 'mergedown',
  27933. 'deleterow',
  27934. 'deletecol',
  27935. 'splittorows',
  27936. 'splittocols',
  27937. 'splittocells',
  27938. 'mergecells',
  27939. 'deletetable',
  27940. 'drafts'
  27941. ]
  27942. for (var i = 0, ci; (ci = btnCmds[i++]); ) {
  27943. ci = ci.toLowerCase()
  27944. editorui[ci] = (function (cmd) {
  27945. return function (editor) {
  27946. var ui = new editorui.Button({
  27947. className: 'edui-for-' + cmd,
  27948. title: editor.options.labelMap[cmd] || editor.getLang('labelMap.' + cmd) || '',
  27949. onclick: function () {
  27950. editor.execCommand(cmd)
  27951. },
  27952. theme: editor.options.theme,
  27953. showText: false
  27954. })
  27955. editorui.buttons[cmd] = ui
  27956. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  27957. var state = editor.queryCommandState(cmd)
  27958. if (state == -1) {
  27959. ui.setDisabled(true)
  27960. ui.setChecked(false)
  27961. } else {
  27962. if (!uiReady) {
  27963. ui.setDisabled(false)
  27964. ui.setChecked(state)
  27965. }
  27966. }
  27967. })
  27968. return ui
  27969. }
  27970. })(ci)
  27971. }
  27972. //清除文档
  27973. editorui.cleardoc = function (editor) {
  27974. var ui = new editorui.Button({
  27975. className: 'edui-for-cleardoc',
  27976. title: editor.options.labelMap.cleardoc || editor.getLang('labelMap.cleardoc') || '',
  27977. theme: editor.options.theme,
  27978. onclick: function () {
  27979. if (confirm(editor.getLang('confirmClear'))) {
  27980. editor.execCommand('cleardoc')
  27981. }
  27982. }
  27983. })
  27984. editorui.buttons['cleardoc'] = ui
  27985. editor.addListener('selectionchange', function () {
  27986. ui.setDisabled(editor.queryCommandState('cleardoc') == -1)
  27987. })
  27988. return ui
  27989. }
  27990. //排版,图片排版,文字方向
  27991. var typeset = {
  27992. justify: ['left', 'right', 'center', 'justify'],
  27993. imagefloat: ['none', 'left', 'center', 'right'],
  27994. directionality: ['ltr', 'rtl']
  27995. }
  27996. for (var p in typeset) {
  27997. ;(function (cmd, val) {
  27998. for (var i = 0, ci; (ci = val[i++]); ) {
  27999. ;(function (cmd2) {
  28000. editorui[cmd.replace('float', '') + cmd2] = function (editor) {
  28001. var ui = new editorui.Button({
  28002. className: 'edui-for-' + cmd.replace('float', '') + cmd2,
  28003. title:
  28004. editor.options.labelMap[cmd.replace('float', '') + cmd2] ||
  28005. editor.getLang('labelMap.' + cmd.replace('float', '') + cmd2) ||
  28006. '',
  28007. theme: editor.options.theme,
  28008. onclick: function () {
  28009. editor.execCommand(cmd, cmd2)
  28010. }
  28011. })
  28012. editorui.buttons[cmd] = ui
  28013. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  28014. ui.setDisabled(editor.queryCommandState(cmd) == -1)
  28015. ui.setChecked(editor.queryCommandValue(cmd) == cmd2 && !uiReady)
  28016. })
  28017. return ui
  28018. }
  28019. })(ci)
  28020. }
  28021. })(p, typeset[p])
  28022. }
  28023. //字体颜色和背景颜色
  28024. for (var i = 0, ci; (ci = ['backcolor', 'forecolor'][i++]); ) {
  28025. editorui[ci] = (function (cmd) {
  28026. return function (editor) {
  28027. var ui = new editorui.ColorButton({
  28028. className: 'edui-for-' + cmd,
  28029. color: 'default',
  28030. title: editor.options.labelMap[cmd] || editor.getLang('labelMap.' + cmd) || '',
  28031. editor: editor,
  28032. onpickcolor: function (t, color) {
  28033. editor.execCommand(cmd, color)
  28034. },
  28035. onpicknocolor: function () {
  28036. editor.execCommand(cmd, 'default')
  28037. this.setColor('transparent')
  28038. this.color = 'default'
  28039. },
  28040. onbuttonclick: function () {
  28041. editor.execCommand(cmd, this.color)
  28042. }
  28043. })
  28044. editorui.buttons[cmd] = ui
  28045. editor.addListener('selectionchange', function () {
  28046. ui.setDisabled(editor.queryCommandState(cmd) == -1)
  28047. })
  28048. return ui
  28049. }
  28050. })(ci)
  28051. }
  28052. var dialogBtns = {
  28053. noOk: ['searchreplace', 'help', 'spechars', 'webapp', 'preview'],
  28054. ok: [
  28055. 'attachment',
  28056. 'anchor',
  28057. 'link',
  28058. 'insertimage',
  28059. 'map',
  28060. 'gmap',
  28061. 'insertframe',
  28062. 'wordimage',
  28063. 'insertvideo',
  28064. 'insertframe',
  28065. 'edittip',
  28066. 'edittable',
  28067. 'edittd',
  28068. 'scrawl',
  28069. 'template',
  28070. 'music',
  28071. 'background',
  28072. 'charts'
  28073. ]
  28074. }
  28075. for (var p in dialogBtns) {
  28076. ;(function (type, vals) {
  28077. for (var i = 0, ci; (ci = vals[i++]); ) {
  28078. //todo opera下存在问题
  28079. if (browser.opera && ci === 'searchreplace') {
  28080. continue
  28081. }
  28082. ;(function (cmd) {
  28083. editorui[cmd] = function (editor, iframeUrl, title) {
  28084. iframeUrl = iframeUrl || (editor.options.iframeUrlMap || {})[cmd] || iframeUrlMap[cmd]
  28085. title = editor.options.labelMap[cmd] || editor.getLang('labelMap.' + cmd) || ''
  28086. var dialog
  28087. //没有iframeUrl不创建dialog
  28088. if (iframeUrl) {
  28089. dialog = new editorui.Dialog(
  28090. utils.extend(
  28091. {
  28092. iframeUrl: editor.ui.mapUrl(iframeUrl),
  28093. editor: editor,
  28094. className: 'edui-for-' + cmd,
  28095. title: title,
  28096. holdScroll: cmd === 'insertimage',
  28097. fullscreen: /charts|preview/.test(cmd),
  28098. closeDialog: editor.getLang('closeDialog')
  28099. },
  28100. type == 'ok'
  28101. ? {
  28102. buttons: [
  28103. {
  28104. className: 'edui-okbutton',
  28105. label: editor.getLang('ok'),
  28106. editor: editor,
  28107. onclick: function () {
  28108. dialog.close(true)
  28109. }
  28110. },
  28111. {
  28112. className: 'edui-cancelbutton',
  28113. label: editor.getLang('cancel'),
  28114. editor: editor,
  28115. onclick: function () {
  28116. dialog.close(false)
  28117. }
  28118. }
  28119. ]
  28120. }
  28121. : {}
  28122. )
  28123. )
  28124. editor.ui._dialogs[cmd + 'Dialog'] = dialog
  28125. }
  28126. var ui = new editorui.Button({
  28127. className: 'edui-for-' + cmd,
  28128. title: title,
  28129. onclick: function () {
  28130. if (dialog) {
  28131. switch (cmd) {
  28132. case 'wordimage':
  28133. var images = editor.execCommand('wordimage')
  28134. if (images && images.length) {
  28135. dialog.render()
  28136. dialog.open()
  28137. }
  28138. break
  28139. case 'scrawl':
  28140. if (editor.queryCommandState('scrawl') != -1) {
  28141. dialog.render()
  28142. dialog.open()
  28143. }
  28144. break
  28145. default:
  28146. dialog.render()
  28147. dialog.open()
  28148. }
  28149. }
  28150. },
  28151. theme: editor.options.theme,
  28152. disabled:
  28153. (cmd == 'scrawl' && editor.queryCommandState('scrawl') == -1) || cmd == 'charts'
  28154. })
  28155. editorui.buttons[cmd] = ui
  28156. editor.addListener('selectionchange', function () {
  28157. //只存在于右键菜单而无工具栏按钮的ui不需要检测状态
  28158. var unNeedCheckState = { edittable: 1 }
  28159. if (cmd in unNeedCheckState) return
  28160. var state = editor.queryCommandState(cmd)
  28161. if (ui.getDom()) {
  28162. ui.setDisabled(state == -1)
  28163. ui.setChecked(state)
  28164. }
  28165. })
  28166. return ui
  28167. }
  28168. })(ci.toLowerCase())
  28169. }
  28170. })(p, dialogBtns[p])
  28171. }
  28172. editorui.snapscreen = function (editor, iframeUrl, title) {
  28173. title = editor.options.labelMap['snapscreen'] || editor.getLang('labelMap.snapscreen') || ''
  28174. var ui = new editorui.Button({
  28175. className: 'edui-for-snapscreen',
  28176. title: title,
  28177. onclick: function () {
  28178. editor.execCommand('snapscreen')
  28179. },
  28180. theme: editor.options.theme
  28181. })
  28182. editorui.buttons['snapscreen'] = ui
  28183. iframeUrl =
  28184. iframeUrl || (editor.options.iframeUrlMap || {})['snapscreen'] || iframeUrlMap['snapscreen']
  28185. if (iframeUrl) {
  28186. var dialog = new editorui.Dialog({
  28187. iframeUrl: editor.ui.mapUrl(iframeUrl),
  28188. editor: editor,
  28189. className: 'edui-for-snapscreen',
  28190. title: title,
  28191. buttons: [
  28192. {
  28193. className: 'edui-okbutton',
  28194. label: editor.getLang('ok'),
  28195. editor: editor,
  28196. onclick: function () {
  28197. dialog.close(true)
  28198. }
  28199. },
  28200. {
  28201. className: 'edui-cancelbutton',
  28202. label: editor.getLang('cancel'),
  28203. editor: editor,
  28204. onclick: function () {
  28205. dialog.close(false)
  28206. }
  28207. }
  28208. ]
  28209. })
  28210. dialog.render()
  28211. editor.ui._dialogs['snapscreenDialog'] = dialog
  28212. }
  28213. editor.addListener('selectionchange', function () {
  28214. ui.setDisabled(editor.queryCommandState('snapscreen') == -1)
  28215. })
  28216. return ui
  28217. }
  28218. editorui.insertcode = function (editor, list, title) {
  28219. list = editor.options['insertcode'] || []
  28220. title = editor.options.labelMap['insertcode'] || editor.getLang('labelMap.insertcode') || ''
  28221. // if (!list.length) return;
  28222. var items = []
  28223. utils.each(list, function (key, val) {
  28224. items.push({
  28225. label: key,
  28226. value: val,
  28227. theme: editor.options.theme,
  28228. renderLabelHtml: function () {
  28229. return '<div class="edui-label %%-label" >' + (this.label || '') + '</div>'
  28230. }
  28231. })
  28232. })
  28233. var ui = new editorui.Combox({
  28234. editor: editor,
  28235. items: items,
  28236. onselect: function (t, index) {
  28237. editor.execCommand('insertcode', this.items[index].value)
  28238. },
  28239. onbuttonclick: function () {
  28240. this.showPopup()
  28241. },
  28242. title: title,
  28243. initValue: title,
  28244. className: 'edui-for-insertcode',
  28245. indexByValue: function (value) {
  28246. if (value) {
  28247. for (var i = 0, ci; (ci = this.items[i]); i++) {
  28248. if (ci.value.indexOf(value) != -1) return i
  28249. }
  28250. }
  28251. return -1
  28252. }
  28253. })
  28254. editorui.buttons['insertcode'] = ui
  28255. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  28256. if (!uiReady) {
  28257. var state = editor.queryCommandState('insertcode')
  28258. if (state == -1) {
  28259. ui.setDisabled(true)
  28260. } else {
  28261. ui.setDisabled(false)
  28262. var value = editor.queryCommandValue('insertcode')
  28263. if (!value) {
  28264. ui.setValue(title)
  28265. return
  28266. }
  28267. //trace:1871 ie下从源码模式切换回来时,字体会带单引号,而且会有逗号
  28268. value && (value = value.replace(/['"]/g, '').split(',')[0])
  28269. ui.setValue(value)
  28270. }
  28271. }
  28272. })
  28273. return ui
  28274. }
  28275. editorui.fontfamily = function (editor, list, title) {
  28276. list = editor.options['fontfamily'] || []
  28277. title = editor.options.labelMap['fontfamily'] || editor.getLang('labelMap.fontfamily') || ''
  28278. if (!list.length) return
  28279. for (var i = 0, ci, items = []; (ci = list[i]); i++) {
  28280. var langLabel = editor.getLang('fontfamily')[ci.name] || ''
  28281. ;(function (key, val) {
  28282. items.push({
  28283. label: key,
  28284. value: val,
  28285. theme: editor.options.theme,
  28286. renderLabelHtml: function () {
  28287. return (
  28288. '<div class="edui-label %%-label" style="font-family:' +
  28289. utils.unhtml(this.value) +
  28290. '">' +
  28291. (this.label || '') +
  28292. '</div>'
  28293. )
  28294. }
  28295. })
  28296. })(ci.label || langLabel, ci.val)
  28297. }
  28298. var ui = new editorui.Combox({
  28299. editor: editor,
  28300. items: items,
  28301. onselect: function (t, index) {
  28302. editor.execCommand('FontFamily', this.items[index].value)
  28303. },
  28304. onbuttonclick: function () {
  28305. this.showPopup()
  28306. },
  28307. title: title,
  28308. initValue: title,
  28309. className: 'edui-for-fontfamily',
  28310. indexByValue: function (value) {
  28311. if (value) {
  28312. for (var i = 0, ci; (ci = this.items[i]); i++) {
  28313. if (ci.value.indexOf(value) != -1) return i
  28314. }
  28315. }
  28316. return -1
  28317. }
  28318. })
  28319. editorui.buttons['fontfamily'] = ui
  28320. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  28321. if (!uiReady) {
  28322. var state = editor.queryCommandState('FontFamily')
  28323. if (state == -1) {
  28324. ui.setDisabled(true)
  28325. } else {
  28326. ui.setDisabled(false)
  28327. var value = editor.queryCommandValue('FontFamily')
  28328. //trace:1871 ie下从源码模式切换回来时,字体会带单引号,而且会有逗号
  28329. value && (value = value.replace(/['"]/g, '').split(',')[0])
  28330. ui.setValue(value)
  28331. }
  28332. }
  28333. })
  28334. return ui
  28335. }
  28336. editorui.fontsize = function (editor, list, title) {
  28337. title = editor.options.labelMap['fontsize'] || editor.getLang('labelMap.fontsize') || ''
  28338. list = list || editor.options['fontsize'] || []
  28339. if (!list.length) return
  28340. var items = []
  28341. for (var i = 0; i < list.length; i++) {
  28342. var size = list[i] + 'px'
  28343. items.push({
  28344. label: size,
  28345. value: size,
  28346. theme: editor.options.theme,
  28347. renderLabelHtml: function () {
  28348. return (
  28349. '<div class="edui-label %%-label" style="line-height:1;font-size:' +
  28350. this.value +
  28351. '">' +
  28352. (this.label || '') +
  28353. '</div>'
  28354. )
  28355. }
  28356. })
  28357. }
  28358. var ui = new editorui.Combox({
  28359. editor: editor,
  28360. items: items,
  28361. title: title,
  28362. initValue: title,
  28363. onselect: function (t, index) {
  28364. editor.execCommand('FontSize', this.items[index].value)
  28365. },
  28366. onbuttonclick: function () {
  28367. this.showPopup()
  28368. },
  28369. className: 'edui-for-fontsize'
  28370. })
  28371. editorui.buttons['fontsize'] = ui
  28372. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  28373. if (!uiReady) {
  28374. var state = editor.queryCommandState('FontSize')
  28375. if (state == -1) {
  28376. ui.setDisabled(true)
  28377. } else {
  28378. ui.setDisabled(false)
  28379. ui.setValue(editor.queryCommandValue('FontSize'))
  28380. }
  28381. }
  28382. })
  28383. return ui
  28384. }
  28385. editorui.paragraph = function (editor, list, title) {
  28386. title = editor.options.labelMap['paragraph'] || editor.getLang('labelMap.paragraph') || ''
  28387. list = editor.options['paragraph'] || []
  28388. if (utils.isEmptyObject(list)) return
  28389. var items = []
  28390. for (var i in list) {
  28391. items.push({
  28392. value: i,
  28393. label: list[i] || editor.getLang('paragraph')[i],
  28394. theme: editor.options.theme,
  28395. renderLabelHtml: function () {
  28396. return (
  28397. '<div class="edui-label %%-label"><span class="edui-for-' +
  28398. this.value +
  28399. '">' +
  28400. (this.label || '') +
  28401. '</span></div>'
  28402. )
  28403. }
  28404. })
  28405. }
  28406. var ui = new editorui.Combox({
  28407. editor: editor,
  28408. items: items,
  28409. title: title,
  28410. initValue: title,
  28411. className: 'edui-for-paragraph',
  28412. onselect: function (t, index) {
  28413. editor.execCommand('Paragraph', this.items[index].value)
  28414. },
  28415. onbuttonclick: function () {
  28416. this.showPopup()
  28417. }
  28418. })
  28419. editorui.buttons['paragraph'] = ui
  28420. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  28421. if (!uiReady) {
  28422. var state = editor.queryCommandState('Paragraph')
  28423. if (state == -1) {
  28424. ui.setDisabled(true)
  28425. } else {
  28426. ui.setDisabled(false)
  28427. var value = editor.queryCommandValue('Paragraph')
  28428. var index = ui.indexByValue(value)
  28429. if (index != -1) {
  28430. ui.setValue(value)
  28431. } else {
  28432. ui.setValue(ui.initValue)
  28433. }
  28434. }
  28435. }
  28436. })
  28437. return ui
  28438. }
  28439. //自定义标题
  28440. editorui.customstyle = function (editor) {
  28441. var list = editor.options['customstyle'] || [],
  28442. title =
  28443. editor.options.labelMap['customstyle'] || editor.getLang('labelMap.customstyle') || ''
  28444. if (!list.length) return
  28445. var langCs = editor.getLang('customstyle')
  28446. for (var i = 0, items = [], t; (t = list[i++]); ) {
  28447. ;(function (t) {
  28448. var ck = {}
  28449. ck.label = t.label ? t.label : langCs[t.name]
  28450. ck.style = t.style
  28451. ck.className = t.className
  28452. ck.tag = t.tag
  28453. items.push({
  28454. label: ck.label,
  28455. value: ck,
  28456. theme: editor.options.theme,
  28457. renderLabelHtml: function () {
  28458. return (
  28459. '<div class="edui-label %%-label">' +
  28460. '<' +
  28461. ck.tag +
  28462. ' ' +
  28463. (ck.className ? ' class="' + ck.className + '"' : '') +
  28464. (ck.style ? ' style="' + ck.style + '"' : '') +
  28465. '>' +
  28466. ck.label +
  28467. '</' +
  28468. ck.tag +
  28469. '>' +
  28470. '</div>'
  28471. )
  28472. }
  28473. })
  28474. })(t)
  28475. }
  28476. var ui = new editorui.Combox({
  28477. editor: editor,
  28478. items: items,
  28479. title: title,
  28480. initValue: title,
  28481. className: 'edui-for-customstyle',
  28482. onselect: function (t, index) {
  28483. editor.execCommand('customstyle', this.items[index].value)
  28484. },
  28485. onbuttonclick: function () {
  28486. this.showPopup()
  28487. },
  28488. indexByValue: function (value) {
  28489. for (var i = 0, ti; (ti = this.items[i++]); ) {
  28490. if (ti.label == value) {
  28491. return i - 1
  28492. }
  28493. }
  28494. return -1
  28495. }
  28496. })
  28497. editorui.buttons['customstyle'] = ui
  28498. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  28499. if (!uiReady) {
  28500. var state = editor.queryCommandState('customstyle')
  28501. if (state == -1) {
  28502. ui.setDisabled(true)
  28503. } else {
  28504. ui.setDisabled(false)
  28505. var value = editor.queryCommandValue('customstyle')
  28506. var index = ui.indexByValue(value)
  28507. if (index != -1) {
  28508. ui.setValue(value)
  28509. } else {
  28510. ui.setValue(ui.initValue)
  28511. }
  28512. }
  28513. }
  28514. })
  28515. return ui
  28516. }
  28517. editorui.inserttable = function (editor, iframeUrl, title) {
  28518. title = editor.options.labelMap['inserttable'] || editor.getLang('labelMap.inserttable') || ''
  28519. var ui = new editorui.TableButton({
  28520. editor: editor,
  28521. title: title,
  28522. className: 'edui-for-inserttable',
  28523. onpicktable: function (t, numCols, numRows) {
  28524. editor.execCommand('InsertTable', {
  28525. numRows: numRows,
  28526. numCols: numCols,
  28527. border: 1
  28528. })
  28529. },
  28530. onbuttonclick: function () {
  28531. this.showPopup()
  28532. }
  28533. })
  28534. editorui.buttons['inserttable'] = ui
  28535. editor.addListener('selectionchange', function () {
  28536. ui.setDisabled(editor.queryCommandState('inserttable') == -1)
  28537. })
  28538. return ui
  28539. }
  28540. editorui.lineheight = function (editor) {
  28541. var val = editor.options.lineheight || []
  28542. if (!val.length) return
  28543. for (var i = 0, ci, items = []; (ci = val[i++]); ) {
  28544. items.push({
  28545. //todo:写死了
  28546. label: ci,
  28547. value: ci,
  28548. theme: editor.options.theme,
  28549. onclick: function () {
  28550. editor.execCommand('lineheight', this.value)
  28551. }
  28552. })
  28553. }
  28554. var ui = new editorui.MenuButton({
  28555. editor: editor,
  28556. className: 'edui-for-lineheight',
  28557. title: editor.options.labelMap['lineheight'] || editor.getLang('labelMap.lineheight') || '',
  28558. items: items,
  28559. onbuttonclick: function () {
  28560. var value = editor.queryCommandValue('LineHeight') || this.value
  28561. editor.execCommand('LineHeight', value)
  28562. }
  28563. })
  28564. editorui.buttons['lineheight'] = ui
  28565. editor.addListener('selectionchange', function () {
  28566. var state = editor.queryCommandState('LineHeight')
  28567. if (state == -1) {
  28568. ui.setDisabled(true)
  28569. } else {
  28570. ui.setDisabled(false)
  28571. var value = editor.queryCommandValue('LineHeight')
  28572. value && ui.setValue((value + '').replace(/cm/, ''))
  28573. ui.setChecked(state)
  28574. }
  28575. })
  28576. return ui
  28577. }
  28578. var rowspacings = ['top', 'bottom']
  28579. for (var r = 0, ri; (ri = rowspacings[r++]); ) {
  28580. ;(function (cmd) {
  28581. editorui['rowspacing' + cmd] = function (editor) {
  28582. var val = editor.options['rowspacing' + cmd] || []
  28583. if (!val.length) return null
  28584. for (var i = 0, ci, items = []; (ci = val[i++]); ) {
  28585. items.push({
  28586. label: ci,
  28587. value: ci,
  28588. theme: editor.options.theme,
  28589. onclick: function () {
  28590. editor.execCommand('rowspacing', this.value, cmd)
  28591. }
  28592. })
  28593. }
  28594. var ui = new editorui.MenuButton({
  28595. editor: editor,
  28596. className: 'edui-for-rowspacing' + cmd,
  28597. title:
  28598. editor.options.labelMap['rowspacing' + cmd] ||
  28599. editor.getLang('labelMap.rowspacing' + cmd) ||
  28600. '',
  28601. items: items,
  28602. onbuttonclick: function () {
  28603. var value = editor.queryCommandValue('rowspacing', cmd) || this.value
  28604. editor.execCommand('rowspacing', value, cmd)
  28605. }
  28606. })
  28607. editorui.buttons[cmd] = ui
  28608. editor.addListener('selectionchange', function () {
  28609. var state = editor.queryCommandState('rowspacing', cmd)
  28610. if (state == -1) {
  28611. ui.setDisabled(true)
  28612. } else {
  28613. ui.setDisabled(false)
  28614. var value = editor.queryCommandValue('rowspacing', cmd)
  28615. value && ui.setValue((value + '').replace(/%/, ''))
  28616. ui.setChecked(state)
  28617. }
  28618. })
  28619. return ui
  28620. }
  28621. })(ri)
  28622. }
  28623. //有序,无序列表
  28624. var lists = ['insertorderedlist', 'insertunorderedlist']
  28625. for (var l = 0, cl; (cl = lists[l++]); ) {
  28626. ;(function (cmd) {
  28627. editorui[cmd] = function (editor) {
  28628. var vals = editor.options[cmd],
  28629. _onMenuClick = function () {
  28630. editor.execCommand(cmd, this.value)
  28631. },
  28632. items = []
  28633. for (var i in vals) {
  28634. items.push({
  28635. label: vals[i] || editor.getLang()[cmd][i] || '',
  28636. value: i,
  28637. theme: editor.options.theme,
  28638. onclick: _onMenuClick
  28639. })
  28640. }
  28641. var ui = new editorui.MenuButton({
  28642. editor: editor,
  28643. className: 'edui-for-' + cmd,
  28644. title: editor.getLang('labelMap.' + cmd) || '',
  28645. items: items,
  28646. onbuttonclick: function () {
  28647. var value = editor.queryCommandValue(cmd) || this.value
  28648. editor.execCommand(cmd, value)
  28649. }
  28650. })
  28651. editorui.buttons[cmd] = ui
  28652. editor.addListener('selectionchange', function () {
  28653. var state = editor.queryCommandState(cmd)
  28654. if (state == -1) {
  28655. ui.setDisabled(true)
  28656. } else {
  28657. ui.setDisabled(false)
  28658. var value = editor.queryCommandValue(cmd)
  28659. ui.setValue(value)
  28660. ui.setChecked(state)
  28661. }
  28662. })
  28663. return ui
  28664. }
  28665. })(cl)
  28666. }
  28667. editorui.fullscreen = function (editor, title) {
  28668. title = editor.options.labelMap['fullscreen'] || editor.getLang('labelMap.fullscreen') || ''
  28669. var ui = new editorui.Button({
  28670. className: 'edui-for-fullscreen',
  28671. title: title,
  28672. theme: editor.options.theme,
  28673. onclick: function () {
  28674. if (editor.ui) {
  28675. editor.ui.setFullScreen(!editor.ui.isFullScreen())
  28676. }
  28677. this.setChecked(editor.ui.isFullScreen())
  28678. }
  28679. })
  28680. editorui.buttons['fullscreen'] = ui
  28681. editor.addListener('selectionchange', function () {
  28682. var state = editor.queryCommandState('fullscreen')
  28683. ui.setDisabled(state == -1)
  28684. ui.setChecked(editor.ui.isFullScreen())
  28685. })
  28686. return ui
  28687. }
  28688. // 表情
  28689. editorui['emotion'] = function (editor, iframeUrl) {
  28690. var cmd = 'emotion'
  28691. var ui = new editorui.MultiMenuPop({
  28692. title: editor.options.labelMap[cmd] || editor.getLang('labelMap.' + cmd + '') || '',
  28693. editor: editor,
  28694. className: 'edui-for-' + cmd,
  28695. iframeUrl: editor.ui.mapUrl(
  28696. iframeUrl || (editor.options.iframeUrlMap || {})[cmd] || iframeUrlMap[cmd]
  28697. )
  28698. })
  28699. editorui.buttons[cmd] = ui
  28700. editor.addListener('selectionchange', function () {
  28701. ui.setDisabled(editor.queryCommandState(cmd) == -1)
  28702. })
  28703. return ui
  28704. }
  28705. editorui.autotypeset = function (editor) {
  28706. var ui = new editorui.AutoTypeSetButton({
  28707. editor: editor,
  28708. title:
  28709. editor.options.labelMap['autotypeset'] || editor.getLang('labelMap.autotypeset') || '',
  28710. className: 'edui-for-autotypeset',
  28711. onbuttonclick: function () {
  28712. editor.execCommand('autotypeset')
  28713. }
  28714. })
  28715. editorui.buttons['autotypeset'] = ui
  28716. editor.addListener('selectionchange', function () {
  28717. ui.setDisabled(editor.queryCommandState('autotypeset') == -1)
  28718. })
  28719. return ui
  28720. }
  28721. /* 简单上传插件 */
  28722. editorui['simpleupload'] = function (editor) {
  28723. var name = 'simpleupload',
  28724. ui = new editorui.Button({
  28725. className: 'edui-for-' + name,
  28726. title: editor.options.labelMap[name] || editor.getLang('labelMap.' + name) || '',
  28727. onclick: function () {},
  28728. theme: editor.options.theme,
  28729. showText: false
  28730. })
  28731. editorui.buttons[name] = ui
  28732. editor.addListener('ready', function () {
  28733. var b = ui.getDom('body'),
  28734. iconSpan = b.children[0]
  28735. editor.fireEvent('simpleuploadbtnready', iconSpan)
  28736. })
  28737. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  28738. var state = editor.queryCommandState(name)
  28739. if (state == -1) {
  28740. ui.setDisabled(true)
  28741. ui.setChecked(false)
  28742. } else {
  28743. if (!uiReady) {
  28744. ui.setDisabled(false)
  28745. ui.setChecked(state)
  28746. }
  28747. }
  28748. })
  28749. return ui
  28750. }
  28751. })()
  28752. // adapter/editor.js
  28753. ///import core
  28754. ///commands 全屏
  28755. ///commandsName FullScreen
  28756. ///commandsTitle 全屏
  28757. ;(function () {
  28758. var utils = baidu.editor.utils,
  28759. uiUtils = baidu.editor.ui.uiUtils,
  28760. UIBase = baidu.editor.ui.UIBase,
  28761. domUtils = baidu.editor.dom.domUtils
  28762. var nodeStack = []
  28763. function EditorUI(options) {
  28764. this.initOptions(options)
  28765. this.initEditorUI()
  28766. }
  28767. EditorUI.prototype = {
  28768. uiName: 'editor',
  28769. initEditorUI: function () {
  28770. this.editor.ui = this
  28771. this._dialogs = {}
  28772. this.initUIBase()
  28773. this._initToolbars()
  28774. var editor = this.editor,
  28775. me = this
  28776. editor.addListener('ready', function () {
  28777. //提供getDialog方法
  28778. editor.getDialog = function (name) {
  28779. return editor.ui._dialogs[name + 'Dialog']
  28780. }
  28781. domUtils.on(editor.window, 'scroll', function (evt) {
  28782. baidu.editor.ui.Popup.postHide(evt)
  28783. })
  28784. //提供编辑器实时宽高(全屏时宽高不变化)
  28785. editor.ui._actualFrameWidth = editor.options.initialFrameWidth
  28786. UE.browser.ie &&
  28787. UE.browser.version === 6 &&
  28788. editor.container.ownerDocument.execCommand('BackgroundImageCache', false, true)
  28789. //display bottom-bar label based on config
  28790. if (editor.options.elementPathEnabled && editor.ui.getDom('elementpath')) {
  28791. editor.ui.getDom('elementpath').innerHTML =
  28792. '<div class="edui-editor-breadcrumb">' + editor.getLang('elementPathTip') + ':</div>'
  28793. }
  28794. if (editor.options.wordCount) {
  28795. function countFn() {
  28796. setCount(editor, me)
  28797. domUtils.un(editor.document, 'click', arguments.callee)
  28798. }
  28799. domUtils.on(editor.document, 'click', countFn)
  28800. editor.ui.getDom('wordcount').innerHTML = editor.getLang('wordCountTip')
  28801. }
  28802. editor.ui._scale()
  28803. if (editor.options.scaleEnabled) {
  28804. if (editor.autoHeightEnabled) {
  28805. editor.disableAutoHeight()
  28806. }
  28807. me.enableScale()
  28808. } else {
  28809. me.disableScale()
  28810. }
  28811. if (
  28812. !editor.options.elementPathEnabled &&
  28813. !editor.options.wordCount &&
  28814. !editor.options.scaleEnabled &&
  28815. editor.ui.getDom('elementpath')
  28816. ) {
  28817. editor.ui.getDom('elementpath').style.display = 'none'
  28818. editor.ui.getDom('wordcount').style.display = 'none'
  28819. editor.ui.getDom('scale').style.display = 'none'
  28820. }
  28821. if (!editor.selection.isFocus()) return
  28822. editor.fireEvent('selectionchange', false, true)
  28823. })
  28824. editor.addListener('mousedown', function (t, evt) {
  28825. var el = evt.target || evt.srcElement
  28826. baidu.editor.ui.Popup.postHide(evt, el)
  28827. baidu.editor.ui.ShortCutMenu.postHide(evt)
  28828. })
  28829. editor.addListener('delcells', function () {
  28830. if (UE.ui['edittip']) {
  28831. new UE.ui['edittip'](editor)
  28832. }
  28833. editor.getDialog('edittip').open()
  28834. })
  28835. var pastePop,
  28836. isPaste = false,
  28837. timer
  28838. editor.addListener('afterpaste', function () {
  28839. if (editor.queryCommandState('pasteplain')) return
  28840. if (baidu.editor.ui.PastePicker) {
  28841. pastePop = new baidu.editor.ui.Popup({
  28842. content: new baidu.editor.ui.PastePicker({ editor: editor }),
  28843. editor: editor,
  28844. className: 'edui-wordpastepop'
  28845. })
  28846. pastePop.render()
  28847. }
  28848. isPaste = true
  28849. })
  28850. editor.addListener('afterinserthtml', function () {
  28851. clearTimeout(timer)
  28852. timer = setTimeout(function () {
  28853. if (pastePop && (isPaste || editor.ui._isTransfer)) {
  28854. if (pastePop.isHidden()) {
  28855. var span = domUtils.createElement(editor.document, 'span', {
  28856. style: 'line-height:0px;',
  28857. innerHTML: '\ufeff'
  28858. }),
  28859. range = editor.selection.getRange()
  28860. range.insertNode(span)
  28861. var tmp = getDomNode(span, 'firstChild', 'previousSibling')
  28862. tmp && pastePop.showAnchor(tmp.nodeType == 3 ? tmp.parentNode : tmp)
  28863. domUtils.remove(span)
  28864. } else {
  28865. pastePop.show()
  28866. }
  28867. delete editor.ui._isTransfer
  28868. isPaste = false
  28869. }
  28870. }, 200)
  28871. })
  28872. editor.addListener('contextmenu', function (t, evt) {
  28873. baidu.editor.ui.Popup.postHide(evt)
  28874. })
  28875. editor.addListener('keydown', function (t, evt) {
  28876. if (pastePop) pastePop.dispose(evt)
  28877. var keyCode = evt.keyCode || evt.which
  28878. if (evt.altKey && keyCode == 90) {
  28879. UE.ui.buttons['fullscreen'].onclick()
  28880. }
  28881. })
  28882. editor.addListener('wordcount', function (type) {
  28883. setCount(this, me)
  28884. })
  28885. function setCount(editor, ui) {
  28886. editor.setOpt({
  28887. wordCount: true,
  28888. maximumWords: 10000,
  28889. wordCountMsg: editor.options.wordCountMsg || editor.getLang('wordCountMsg'),
  28890. wordOverFlowMsg: editor.options.wordOverFlowMsg || editor.getLang('wordOverFlowMsg')
  28891. })
  28892. var opt = editor.options,
  28893. max = opt.maximumWords,
  28894. msg = opt.wordCountMsg,
  28895. errMsg = opt.wordOverFlowMsg,
  28896. countDom = ui.getDom('wordcount')
  28897. if (!opt.wordCount) {
  28898. return
  28899. }
  28900. var count = editor.getContentLength(true)
  28901. if (count > max) {
  28902. countDom.innerHTML = errMsg
  28903. editor.fireEvent('wordcountoverflow')
  28904. } else {
  28905. countDom.innerHTML = msg.replace('{#leave}', max - count).replace('{#count}', count)
  28906. }
  28907. }
  28908. editor.addListener('selectionchange', function () {
  28909. if (editor.options.elementPathEnabled) {
  28910. me[(editor.queryCommandState('elementpath') == -1 ? 'dis' : 'en') + 'ableElementPath']()
  28911. }
  28912. if (editor.options.scaleEnabled) {
  28913. me[(editor.queryCommandState('scale') == -1 ? 'dis' : 'en') + 'ableScale']()
  28914. }
  28915. })
  28916. var popup = new baidu.editor.ui.Popup({
  28917. editor: editor,
  28918. content: '',
  28919. className: 'edui-bubble',
  28920. _onEditButtonClick: function () {
  28921. this.hide()
  28922. editor.ui._dialogs.linkDialog.open()
  28923. },
  28924. _onImgEditButtonClick: function (name) {
  28925. this.hide()
  28926. editor.ui._dialogs[name] && editor.ui._dialogs[name].open()
  28927. },
  28928. _onImgSetFloat: function (value) {
  28929. this.hide()
  28930. editor.execCommand('imagefloat', value)
  28931. },
  28932. _setIframeAlign: function (value) {
  28933. var frame = popup.anchorEl
  28934. var newFrame = frame.cloneNode(true)
  28935. switch (value) {
  28936. case -2:
  28937. newFrame.setAttribute('align', '')
  28938. break
  28939. case -1:
  28940. newFrame.setAttribute('align', 'left')
  28941. break
  28942. case 1:
  28943. newFrame.setAttribute('align', 'right')
  28944. break
  28945. }
  28946. frame.parentNode.insertBefore(newFrame, frame)
  28947. domUtils.remove(frame)
  28948. popup.anchorEl = newFrame
  28949. popup.showAnchor(popup.anchorEl)
  28950. },
  28951. _updateIframe: function () {
  28952. var frame = (editor._iframe = popup.anchorEl)
  28953. if (domUtils.hasClass(frame, 'ueditor_baidumap')) {
  28954. editor.selection.getRange().selectNode(frame).select()
  28955. editor.ui._dialogs.mapDialog.open()
  28956. popup.hide()
  28957. } else {
  28958. editor.ui._dialogs.insertframeDialog.open()
  28959. popup.hide()
  28960. }
  28961. },
  28962. _onRemoveButtonClick: function (cmdName) {
  28963. editor.execCommand(cmdName)
  28964. this.hide()
  28965. },
  28966. queryAutoHide: function (el) {
  28967. if (el && el.ownerDocument == editor.document) {
  28968. if (
  28969. el.tagName.toLowerCase() == 'img' ||
  28970. domUtils.findParentByTagName(el, 'a', true)
  28971. ) {
  28972. return el !== popup.anchorEl
  28973. }
  28974. }
  28975. return baidu.editor.ui.Popup.prototype.queryAutoHide.call(this, el)
  28976. }
  28977. })
  28978. popup.render()
  28979. if (editor.options.imagePopup) {
  28980. editor.addListener('mouseover', function (t, evt) {
  28981. evt = evt || window.event
  28982. var el = evt.target || evt.srcElement
  28983. if (editor.ui._dialogs.insertframeDialog && /iframe/gi.test(el.tagName)) {
  28984. var html = popup.formatHtml(
  28985. '<nobr>' +
  28986. editor.getLang('property') +
  28987. ': <span onclick=$$._setIframeAlign(-2) class="edui-clickable">' +
  28988. editor.getLang('default') +
  28989. '</span>&nbsp;&nbsp;<span onclick=$$._setIframeAlign(-1) class="edui-clickable">' +
  28990. editor.getLang('justifyleft') +
  28991. '</span>&nbsp;&nbsp;<span onclick=$$._setIframeAlign(1) class="edui-clickable">' +
  28992. editor.getLang('justifyright') +
  28993. '</span>&nbsp;&nbsp;' +
  28994. ' <span onclick="$$._updateIframe( this);" class="edui-clickable">' +
  28995. editor.getLang('modify') +
  28996. '</span></nobr>'
  28997. )
  28998. if (html) {
  28999. popup.getDom('content').innerHTML = html
  29000. popup.anchorEl = el
  29001. popup.showAnchor(popup.anchorEl)
  29002. } else {
  29003. popup.hide()
  29004. }
  29005. }
  29006. })
  29007. editor.addListener('selectionchange', function (t, causeByUi) {
  29008. if (!causeByUi) return
  29009. var html = '',
  29010. str = '',
  29011. img = editor.selection.getRange().getClosedNode(),
  29012. dialogs = editor.ui._dialogs
  29013. if (img && img.tagName == 'IMG') {
  29014. var dialogName = 'insertimageDialog'
  29015. if (
  29016. img.className.indexOf('edui-faked-video') != -1 ||
  29017. img.className.indexOf('edui-upload-video') != -1
  29018. ) {
  29019. dialogName = 'insertvideoDialog'
  29020. }
  29021. if (img.className.indexOf('edui-faked-webapp') != -1) {
  29022. dialogName = 'webappDialog'
  29023. }
  29024. if (img.src.indexOf('http://api.map.baidu.com') != -1) {
  29025. dialogName = 'mapDialog'
  29026. }
  29027. if (img.className.indexOf('edui-faked-music') != -1) {
  29028. dialogName = 'musicDialog'
  29029. }
  29030. if (img.src.indexOf('http://maps.google.com/maps/api/staticmap') != -1) {
  29031. dialogName = 'gmapDialog'
  29032. }
  29033. if (img.getAttribute('anchorname')) {
  29034. dialogName = 'anchorDialog'
  29035. html = popup.formatHtml(
  29036. '<nobr>' +
  29037. editor.getLang('property') +
  29038. ': <span onclick=$$._onImgEditButtonClick("anchorDialog") class="edui-clickable">' +
  29039. editor.getLang('modify') +
  29040. '</span>&nbsp;&nbsp;' +
  29041. '<span onclick=$$._onRemoveButtonClick(\'anchor\') class="edui-clickable">' +
  29042. editor.getLang('delete') +
  29043. '</span></nobr>'
  29044. )
  29045. }
  29046. if (img.getAttribute('word_img')) {
  29047. //todo 放到dialog去做查询
  29048. editor.word_img = [img.getAttribute('word_img')]
  29049. dialogName = 'wordimageDialog'
  29050. }
  29051. if (
  29052. domUtils.hasClass(img, 'loadingclass') ||
  29053. domUtils.hasClass(img, 'loaderrorclass')
  29054. ) {
  29055. dialogName = ''
  29056. }
  29057. if (!dialogs[dialogName]) {
  29058. return
  29059. }
  29060. str =
  29061. '<nobr>' +
  29062. editor.getLang('property') +
  29063. ': ' +
  29064. '<span onclick=$$._onImgSetFloat("none") class="edui-clickable">' +
  29065. editor.getLang('default') +
  29066. '</span>&nbsp;&nbsp;' +
  29067. '<span onclick=$$._onImgSetFloat("left") class="edui-clickable">' +
  29068. editor.getLang('justifyleft') +
  29069. '</span>&nbsp;&nbsp;' +
  29070. '<span onclick=$$._onImgSetFloat("right") class="edui-clickable">' +
  29071. editor.getLang('justifyright') +
  29072. '</span>&nbsp;&nbsp;' +
  29073. '<span onclick=$$._onImgSetFloat("center") class="edui-clickable">' +
  29074. editor.getLang('justifycenter') +
  29075. '</span>&nbsp;&nbsp;' +
  29076. '<span onclick="$$._onImgEditButtonClick(\'' +
  29077. dialogName +
  29078. '\');" class="edui-clickable">' +
  29079. editor.getLang('modify') +
  29080. '</span></nobr>'
  29081. !html && (html = popup.formatHtml(str))
  29082. }
  29083. if (editor.ui._dialogs.linkDialog) {
  29084. var link = editor.queryCommandValue('link')
  29085. var url
  29086. if (link && (url = link.getAttribute('_href') || link.getAttribute('href', 2))) {
  29087. var txt = url
  29088. if (url.length > 30) {
  29089. txt = url.substring(0, 20) + '...'
  29090. }
  29091. if (html) {
  29092. html += '<div style="height:5px;"></div>'
  29093. }
  29094. html += popup.formatHtml(
  29095. '<nobr>' +
  29096. editor.getLang('anthorMsg') +
  29097. ': <a target="_blank" href="' +
  29098. url +
  29099. '" title="' +
  29100. url +
  29101. '" >' +
  29102. txt +
  29103. '</a>' +
  29104. ' <span class="edui-clickable" onclick="$$._onEditButtonClick();">' +
  29105. editor.getLang('modify') +
  29106. '</span>' +
  29107. ' <span class="edui-clickable" onclick="$$._onRemoveButtonClick(\'unlink\');"> ' +
  29108. editor.getLang('clear') +
  29109. '</span></nobr>'
  29110. )
  29111. popup.showAnchor(link)
  29112. }
  29113. }
  29114. if (html) {
  29115. popup.getDom('content').innerHTML = html
  29116. popup.anchorEl = img || link
  29117. popup.showAnchor(popup.anchorEl)
  29118. } else {
  29119. popup.hide()
  29120. }
  29121. })
  29122. }
  29123. },
  29124. _initToolbars: function () {
  29125. var editor = this.editor
  29126. var toolbars = this.toolbars || []
  29127. var toolbarUis = []
  29128. for (var i = 0; i < toolbars.length; i++) {
  29129. var toolbar = toolbars[i]
  29130. var toolbarUi = new baidu.editor.ui.Toolbar({
  29131. theme: editor.options.theme
  29132. })
  29133. for (var j = 0; j < toolbar.length; j++) {
  29134. var toolbarItem = toolbar[j]
  29135. var toolbarItemUi = null
  29136. if (typeof toolbarItem == 'string') {
  29137. toolbarItem = toolbarItem.toLowerCase()
  29138. if (toolbarItem == '|') {
  29139. toolbarItem = 'Separator'
  29140. }
  29141. if (toolbarItem == '||') {
  29142. toolbarItem = 'Breakline'
  29143. }
  29144. if (baidu.editor.ui[toolbarItem]) {
  29145. toolbarItemUi = new baidu.editor.ui[toolbarItem](editor)
  29146. }
  29147. //fullscreen这里单独处理一下,放到首行去
  29148. if (toolbarItem == 'fullscreen') {
  29149. if (toolbarUis && toolbarUis[0]) {
  29150. toolbarUis[0].items.splice(0, 0, toolbarItemUi)
  29151. } else {
  29152. toolbarItemUi && toolbarUi.items.splice(0, 0, toolbarItemUi)
  29153. }
  29154. continue
  29155. }
  29156. } else {
  29157. toolbarItemUi = toolbarItem
  29158. }
  29159. if (toolbarItemUi && toolbarItemUi.id) {
  29160. toolbarUi.add(toolbarItemUi)
  29161. }
  29162. }
  29163. toolbarUis[i] = toolbarUi
  29164. }
  29165. //接受外部定制的UI(修复因 utils.each 无法准确的循环出对象的全部元素而导致的自定义 UI 不符合预期的 BUG by HaoChuan9421)
  29166. // utils.each(UE._customizeUI,function(obj,key){
  29167. // var itemUI,index;
  29168. // if(obj.id && obj.id != editor.key){
  29169. // return false;
  29170. // }
  29171. // itemUI = obj.execFn.call(editor,editor,key);
  29172. // if(itemUI){
  29173. // index = obj.index;
  29174. // if(index === undefined){
  29175. // index = toolbarUi.items.length;
  29176. // }
  29177. // toolbarUi.add(itemUI,index)
  29178. // }
  29179. // });
  29180. for (var key in UE._customizeUI) {
  29181. var obj = UE._customizeUI[key]
  29182. var itemUI, index
  29183. if (!obj.id || obj.id == editor.key) {
  29184. itemUI = obj.execFn.call(editor, editor, key)
  29185. if (itemUI) {
  29186. index = obj.index
  29187. if (index === undefined) {
  29188. index = toolbarUi.items.length
  29189. }
  29190. toolbarUi.add(itemUI, index)
  29191. }
  29192. }
  29193. }
  29194. this.toolbars = toolbarUis
  29195. },
  29196. getHtmlTpl: function () {
  29197. return (
  29198. '<div id="##" class="%%">' +
  29199. '<div id="##_toolbarbox" class="%%-toolbarbox">' +
  29200. (this.toolbars.length
  29201. ? '<div id="##_toolbarboxouter" class="%%-toolbarboxouter"><div class="%%-toolbarboxinner">' +
  29202. this.renderToolbarBoxHtml() +
  29203. '</div></div>'
  29204. : '') +
  29205. '<div id="##_toolbarmsg" class="%%-toolbarmsg" style="display:none;">' +
  29206. '<div id = "##_upload_dialog" class="%%-toolbarmsg-upload" onclick="$$.showWordImageDialog();">' +
  29207. this.editor.getLang('clickToUpload') +
  29208. '</div>' +
  29209. '<div class="%%-toolbarmsg-close" onclick="$$.hideToolbarMsg();">x</div>' +
  29210. '<div id="##_toolbarmsg_label" class="%%-toolbarmsg-label"></div>' +
  29211. '<div style="height:0;overflow:hidden;clear:both;"></div>' +
  29212. '</div>' +
  29213. '<div id="##_message_holder" class="%%-messageholder"></div>' +
  29214. '</div>' +
  29215. '<div id="##_iframeholder" class="%%-iframeholder">' +
  29216. '</div>' +
  29217. //modify wdcount by matao
  29218. // '<div id="##_bottombar" class="%%-bottomContainer"><table><tr>' +
  29219. // '<td id="##_elementpath" class="%%-bottombar"></td>' +
  29220. // '<td id="##_wordcount" class="%%-wordcount"></td>' +
  29221. '<td id="##_scale" class="%%-scale"><div class="%%-icon"></div></td>' +
  29222. '</tr></table></div>' +
  29223. '<div id="##_scalelayer"></div>' +
  29224. '</div>'
  29225. )
  29226. },
  29227. showWordImageDialog: function () {
  29228. this._dialogs['wordimageDialog'].open()
  29229. },
  29230. renderToolbarBoxHtml: function () {
  29231. var buff = []
  29232. for (var i = 0; i < this.toolbars.length; i++) {
  29233. buff.push(this.toolbars[i].renderHtml())
  29234. }
  29235. return buff.join('')
  29236. },
  29237. setFullScreen: function (fullscreen) {
  29238. var editor = this.editor,
  29239. container = editor.container.parentNode.parentNode
  29240. if (this._fullscreen != fullscreen) {
  29241. this._fullscreen = fullscreen
  29242. this.editor.fireEvent('beforefullscreenchange', fullscreen)
  29243. if (baidu.editor.browser.gecko) {
  29244. var bk = editor.selection.getRange().createBookmark()
  29245. }
  29246. if (fullscreen) {
  29247. while (container.tagName != 'BODY') {
  29248. var position = baidu.editor.dom.domUtils.getComputedStyle(container, 'position')
  29249. nodeStack.push(position)
  29250. container.style.position = 'static'
  29251. container = container.parentNode
  29252. }
  29253. this._bakHtmlOverflow = document.documentElement.style.overflow
  29254. this._bakBodyOverflow = document.body.style.overflow
  29255. this._bakAutoHeight = this.editor.autoHeightEnabled
  29256. this._bakScrollTop = Math.max(
  29257. document.documentElement.scrollTop,
  29258. document.body.scrollTop
  29259. )
  29260. this._bakEditorContaninerWidth = editor.iframe.parentNode.offsetWidth
  29261. if (this._bakAutoHeight) {
  29262. //当全屏时不能执行自动长高
  29263. editor.autoHeightEnabled = false
  29264. this.editor.disableAutoHeight()
  29265. }
  29266. document.documentElement.style.overflow = 'hidden'
  29267. //修复,滚动条不收起的问题
  29268. window.scrollTo(0, window.scrollY)
  29269. this._bakCssText = this.getDom().style.cssText
  29270. this._bakCssText1 = this.getDom('iframeholder').style.cssText
  29271. editor.iframe.parentNode.style.width = ''
  29272. this._updateFullScreen()
  29273. } else {
  29274. while (container.tagName != 'BODY') {
  29275. container.style.position = nodeStack.shift()
  29276. container = container.parentNode
  29277. }
  29278. this.getDom().style.cssText = this._bakCssText
  29279. this.getDom('iframeholder').style.cssText = this._bakCssText1
  29280. if (this._bakAutoHeight) {
  29281. editor.autoHeightEnabled = true
  29282. this.editor.enableAutoHeight()
  29283. }
  29284. document.documentElement.style.overflow = this._bakHtmlOverflow
  29285. document.body.style.overflow = this._bakBodyOverflow
  29286. editor.iframe.parentNode.style.width = this._bakEditorContaninerWidth + 'px'
  29287. window.scrollTo(0, this._bakScrollTop)
  29288. }
  29289. if (browser.gecko && editor.body.contentEditable === 'true') {
  29290. var input = document.createElement('input')
  29291. document.body.appendChild(input)
  29292. editor.body.contentEditable = false
  29293. setTimeout(function () {
  29294. input.focus()
  29295. setTimeout(function () {
  29296. editor.body.contentEditable = true
  29297. editor.fireEvent('fullscreenchanged', fullscreen)
  29298. editor.selection.getRange().moveToBookmark(bk).select(true)
  29299. baidu.editor.dom.domUtils.remove(input)
  29300. fullscreen && window.scroll(0, 0)
  29301. }, 0)
  29302. }, 0)
  29303. }
  29304. if (editor.body.contentEditable === 'true') {
  29305. this.editor.fireEvent('fullscreenchanged', fullscreen)
  29306. this.triggerLayout()
  29307. }
  29308. }
  29309. },
  29310. _updateFullScreen: function () {
  29311. if (this._fullscreen) {
  29312. var vpRect = uiUtils.getViewportRect()
  29313. this.getDom().style.cssText =
  29314. 'border:0;position:absolute;left:0;top:' +
  29315. (this.editor.options.topOffset || 0) +
  29316. 'px;width:' +
  29317. vpRect.width +
  29318. 'px;height:' +
  29319. vpRect.height +
  29320. 'px;z-index:' +
  29321. (this.getDom().style.zIndex * 1 + 100)
  29322. uiUtils.setViewportOffset(this.getDom(), {
  29323. left: 0,
  29324. top: this.editor.options.topOffset || 0
  29325. })
  29326. this.editor.setHeight(
  29327. vpRect.height -
  29328. this.getDom('toolbarbox').offsetHeight -
  29329. this.getDom('bottombar').offsetHeight -
  29330. (this.editor.options.topOffset || 0),
  29331. true
  29332. )
  29333. //不手动调一下,会导致全屏失效
  29334. if (browser.gecko) {
  29335. try {
  29336. window.onresize()
  29337. } catch (e) {}
  29338. }
  29339. }
  29340. },
  29341. _updateElementPath: function () {
  29342. var bottom = this.getDom('elementpath'),
  29343. list
  29344. if (this.elementPathEnabled && (list = this.editor.queryCommandValue('elementpath'))) {
  29345. var buff = []
  29346. for (var i = 0, ci; (ci = list[i]); i++) {
  29347. buff[i] = this.formatHtml(
  29348. '<span unselectable="on" onclick="$$.editor.execCommand(&quot;elementpath&quot;, &quot;' +
  29349. i +
  29350. '&quot;);">' +
  29351. ci +
  29352. '</span>'
  29353. )
  29354. }
  29355. bottom.innerHTML =
  29356. '<div class="edui-editor-breadcrumb" onmousedown="return false;">' +
  29357. this.editor.getLang('elementPathTip') +
  29358. ': ' +
  29359. buff.join(' &gt; ') +
  29360. '</div>'
  29361. } else {
  29362. bottom.style.display = 'none'
  29363. }
  29364. },
  29365. disableElementPath: function () {
  29366. var bottom = this.getDom('elementpath')
  29367. bottom.innerHTML = ''
  29368. bottom.style.display = 'none'
  29369. this.elementPathEnabled = false
  29370. },
  29371. enableElementPath: function () {
  29372. var bottom = this.getDom('elementpath')
  29373. bottom.style.display = ''
  29374. this.elementPathEnabled = true
  29375. this._updateElementPath()
  29376. },
  29377. _scale: function () {
  29378. var doc = document,
  29379. editor = this.editor,
  29380. editorHolder = editor.container,
  29381. editorDocument = editor.document,
  29382. toolbarBox = this.getDom('toolbarbox'),
  29383. bottombar = this.getDom('bottombar'),
  29384. scale = this.getDom('scale'),
  29385. scalelayer = this.getDom('scalelayer')
  29386. var isMouseMove = false,
  29387. position = null,
  29388. minEditorHeight = 0,
  29389. minEditorWidth = editor.options.minFrameWidth,
  29390. pageX = 0,
  29391. pageY = 0,
  29392. scaleWidth = 0,
  29393. scaleHeight = 0
  29394. function down() {
  29395. position = domUtils.getXY(editorHolder)
  29396. if (!minEditorHeight) {
  29397. minEditorHeight =
  29398. editor.options.minFrameHeight + toolbarBox.offsetHeight + bottombar.offsetHeight
  29399. }
  29400. scalelayer.style.cssText =
  29401. 'position:absolute;left:0;display:;top:0;background-color:#41ABFF;opacity:0.4;filter: Alpha(opacity=40);width:' +
  29402. editorHolder.offsetWidth +
  29403. 'px;height:' +
  29404. editorHolder.offsetHeight +
  29405. 'px;z-index:' +
  29406. (editor.options.zIndex + 1)
  29407. domUtils.on(doc, 'mousemove', move)
  29408. domUtils.on(editorDocument, 'mouseup', up)
  29409. domUtils.on(doc, 'mouseup', up)
  29410. }
  29411. var me = this
  29412. //by xuheng 全屏时关掉缩放
  29413. this.editor.addListener('fullscreenchanged', function (e, fullScreen) {
  29414. if (fullScreen) {
  29415. me.disableScale()
  29416. } else {
  29417. if (me.editor.options.scaleEnabled) {
  29418. me.enableScale()
  29419. var tmpNode = me.editor.document.createElement('span')
  29420. me.editor.body.appendChild(tmpNode)
  29421. me.editor.body.style.height =
  29422. Math.max(domUtils.getXY(tmpNode).y, me.editor.iframe.offsetHeight - 20) + 'px'
  29423. domUtils.remove(tmpNode)
  29424. }
  29425. }
  29426. })
  29427. function move(event) {
  29428. clearSelection()
  29429. var e = event || window.event
  29430. pageX = e.pageX || doc.documentElement.scrollLeft + e.clientX
  29431. pageY = e.pageY || doc.documentElement.scrollTop + e.clientY
  29432. scaleWidth = pageX - position.x
  29433. scaleHeight = pageY - position.y
  29434. if (scaleWidth >= minEditorWidth) {
  29435. isMouseMove = true
  29436. scalelayer.style.width = scaleWidth + 'px'
  29437. }
  29438. if (scaleHeight >= minEditorHeight) {
  29439. isMouseMove = true
  29440. scalelayer.style.height = scaleHeight + 'px'
  29441. }
  29442. }
  29443. function up() {
  29444. if (isMouseMove) {
  29445. isMouseMove = false
  29446. editor.ui._actualFrameWidth = scalelayer.offsetWidth - 2
  29447. editorHolder.style.width = editor.ui._actualFrameWidth + 'px'
  29448. editor.setHeight(
  29449. scalelayer.offsetHeight - bottombar.offsetHeight - toolbarBox.offsetHeight - 2,
  29450. true
  29451. )
  29452. }
  29453. if (scalelayer) {
  29454. scalelayer.style.display = 'none'
  29455. }
  29456. clearSelection()
  29457. domUtils.un(doc, 'mousemove', move)
  29458. domUtils.un(editorDocument, 'mouseup', up)
  29459. domUtils.un(doc, 'mouseup', up)
  29460. }
  29461. function clearSelection() {
  29462. if (browser.ie) doc.selection.clear()
  29463. else window.getSelection().removeAllRanges()
  29464. }
  29465. this.enableScale = function () {
  29466. //trace:2868
  29467. if (editor.queryCommandState('source') == 1) return
  29468. if (scale && scale.style) {
  29469. scale.style.display = ''
  29470. }
  29471. this.scaleEnabled = true
  29472. domUtils.on(scale, 'mousedown', down)
  29473. }
  29474. this.disableScale = function () {
  29475. if (scale && scale.style) {
  29476. scale.style.display = 'none'
  29477. }
  29478. this.scaleEnabled = false
  29479. domUtils.un(scale, 'mousedown', down)
  29480. }
  29481. },
  29482. isFullScreen: function () {
  29483. return this._fullscreen
  29484. },
  29485. postRender: function () {
  29486. UIBase.prototype.postRender.call(this)
  29487. for (var i = 0; i < this.toolbars.length; i++) {
  29488. this.toolbars[i].postRender()
  29489. }
  29490. var me = this
  29491. var timerId,
  29492. domUtils = baidu.editor.dom.domUtils,
  29493. updateFullScreenTime = function () {
  29494. clearTimeout(timerId)
  29495. timerId = setTimeout(function () {
  29496. me._updateFullScreen()
  29497. })
  29498. }
  29499. domUtils.on(window, 'resize', updateFullScreenTime)
  29500. me.addListener('destroy', function () {
  29501. domUtils.un(window, 'resize', updateFullScreenTime)
  29502. clearTimeout(timerId)
  29503. })
  29504. },
  29505. showToolbarMsg: function (msg, flag) {
  29506. this.getDom('toolbarmsg_label').innerHTML = msg
  29507. this.getDom('toolbarmsg').style.display = ''
  29508. //
  29509. if (!flag) {
  29510. var w = this.getDom('upload_dialog')
  29511. w.style.display = 'none'
  29512. }
  29513. },
  29514. hideToolbarMsg: function () {
  29515. this.getDom('toolbarmsg').style.display = 'none'
  29516. },
  29517. mapUrl: function (url) {
  29518. return url ? url.replace('~/', this.editor.options.UEDITOR_HOME_URL || '') : ''
  29519. },
  29520. triggerLayout: function () {
  29521. var dom = this.getDom()
  29522. if (dom.style.zoom == '1') {
  29523. dom.style.zoom = '100%'
  29524. } else {
  29525. dom.style.zoom = '1'
  29526. }
  29527. }
  29528. }
  29529. utils.inherits(EditorUI, baidu.editor.ui.UIBase)
  29530. var instances = {}
  29531. UE.ui.Editor = function (options) {
  29532. var editor = new UE.Editor(options)
  29533. editor.options.editor = editor
  29534. utils.loadFile(document, {
  29535. href: editor.options.themePath + editor.options.theme + '/css/ueditor.css',
  29536. tag: 'link',
  29537. type: 'text/css',
  29538. rel: 'stylesheet'
  29539. })
  29540. var oldRender = editor.render
  29541. editor.render = function (holder) {
  29542. if (holder.constructor === String) {
  29543. editor.key = holder
  29544. instances[holder] = editor
  29545. }
  29546. utils.domReady(function () {
  29547. editor.langIsReady ? renderUI() : editor.addListener('langReady', renderUI)
  29548. function renderUI() {
  29549. editor.setOpt({
  29550. labelMap: editor.options.labelMap || editor.getLang('labelMap')
  29551. })
  29552. new EditorUI(editor.options)
  29553. if (holder) {
  29554. if (holder.constructor === String) {
  29555. holder = document.getElementById(holder)
  29556. }
  29557. holder &&
  29558. holder.getAttribute('name') &&
  29559. (editor.options.textarea = holder.getAttribute('name'))
  29560. if (holder && /script|textarea/gi.test(holder.tagName)) {
  29561. var newDiv = document.createElement('div')
  29562. holder.parentNode.insertBefore(newDiv, holder)
  29563. var cont = holder.value || holder.innerHTML
  29564. editor.options.initialContent = /^[\t\r\n ]*$/.test(cont)
  29565. ? editor.options.initialContent
  29566. : cont
  29567. .replace(/>[\n\r\t]+([ ]{4})+/g, '>')
  29568. .replace(/[\n\r\t]+([ ]{4})+</g, '<')
  29569. .replace(/>[\n\r\t]+</g, '><')
  29570. holder.className && (newDiv.className = holder.className)
  29571. holder.style.cssText && (newDiv.style.cssText = holder.style.cssText)
  29572. if (/textarea/i.test(holder.tagName)) {
  29573. editor.textarea = holder
  29574. editor.textarea.style.display = 'none'
  29575. } else {
  29576. holder.parentNode.removeChild(holder)
  29577. }
  29578. if (holder.id) {
  29579. newDiv.id = holder.id
  29580. domUtils.removeAttributes(holder, 'id')
  29581. }
  29582. holder = newDiv
  29583. holder.innerHTML = ''
  29584. }
  29585. }
  29586. domUtils.addClass(holder, 'edui-' + editor.options.theme)
  29587. editor.ui.render(holder)
  29588. var opt = editor.options
  29589. //给实例添加一个编辑器的容器引用
  29590. editor.container = editor.ui.getDom()
  29591. var parents = domUtils.findParents(holder, true)
  29592. var displays = []
  29593. for (var i = 0, ci; (ci = parents[i]); i++) {
  29594. displays[i] = ci.style.display
  29595. ci.style.display = 'block'
  29596. }
  29597. if (opt.initialFrameWidth) {
  29598. opt.minFrameWidth = opt.initialFrameWidth
  29599. } else {
  29600. opt.minFrameWidth = opt.initialFrameWidth = holder.offsetWidth
  29601. var styleWidth = holder.style.width
  29602. if (/%$/.test(styleWidth)) {
  29603. opt.initialFrameWidth = styleWidth
  29604. }
  29605. }
  29606. if (opt.initialFrameHeight) {
  29607. opt.minFrameHeight = opt.initialFrameHeight
  29608. } else {
  29609. opt.initialFrameHeight = opt.minFrameHeight = holder.offsetHeight
  29610. }
  29611. for (var i = 0, ci; (ci = parents[i]); i++) {
  29612. ci.style.display = displays[i]
  29613. }
  29614. //编辑器最外容器设置了高度,会导致,编辑器不占位
  29615. //todo 先去掉,没有找到原因
  29616. if (holder.style.height) {
  29617. holder.style.height = ''
  29618. }
  29619. editor.container.style.width =
  29620. opt.initialFrameWidth + (/%$/.test(opt.initialFrameWidth) ? '' : 'px')
  29621. editor.container.style.zIndex = opt.zIndex
  29622. oldRender.call(editor, editor.ui.getDom('iframeholder'))
  29623. editor.fireEvent('afteruiready')
  29624. }
  29625. })
  29626. }
  29627. return editor
  29628. }
  29629. /**
  29630. * @file
  29631. * @name UE
  29632. * @short UE
  29633. * @desc UEditor的顶部命名空间
  29634. */
  29635. /**
  29636. * @name getEditor
  29637. * @since 1.2.4+
  29638. * @grammar UE.getEditor(id,[opt]) => Editor实例
  29639. * @desc 提供一个全局的方法得到编辑器实例
  29640. *
  29641. * * ''id'' 放置编辑器的容器id, 如果容器下的编辑器已经存在,就直接返回
  29642. * * ''opt'' 编辑器的可选参数
  29643. * @example
  29644. * UE.getEditor('containerId',{onready:function(){//创建一个编辑器实例
  29645. * this.setContent('hello')
  29646. * }});
  29647. * UE.getEditor('containerId'); //返回刚创建的实例
  29648. *
  29649. */
  29650. UE.getEditor = function (id, opt) {
  29651. var editor = instances[id]
  29652. if (!editor) {
  29653. editor = instances[id] = new UE.ui.Editor(opt)
  29654. editor.render(id)
  29655. }
  29656. return editor
  29657. }
  29658. UE.delEditor = function (id) {
  29659. var editor
  29660. if ((editor = instances[id])) {
  29661. editor.key && editor.destroy()
  29662. delete instances[id]
  29663. }
  29664. }
  29665. UE.registerUI = function (uiName, fn, index, editorId) {
  29666. utils.each(uiName.split(/\s+/), function (name) {
  29667. UE._customizeUI[name] = {
  29668. id: editorId,
  29669. execFn: fn,
  29670. index: index
  29671. }
  29672. })
  29673. }
  29674. })()
  29675. // adapter/message.js
  29676. UE.registerUI('message', function (editor) {
  29677. var editorui = baidu.editor.ui
  29678. var Message = editorui.Message
  29679. var holder
  29680. var _messageItems = []
  29681. var me = editor
  29682. me.addListener('ready', function () {
  29683. holder = document.getElementById(me.ui.id + '_message_holder')
  29684. updateHolderPos()
  29685. // HaoChuan9421
  29686. // setTimeout(function(){
  29687. // updateHolderPos();
  29688. // }, 500);
  29689. })
  29690. me.addListener('showmessage', function (type, opt) {
  29691. opt = utils.isString(opt)
  29692. ? {
  29693. content: opt
  29694. }
  29695. : opt
  29696. var message = new Message({
  29697. timeout: opt.timeout,
  29698. type: opt.type,
  29699. content: opt.content,
  29700. keepshow: opt.keepshow,
  29701. editor: me
  29702. }),
  29703. mid = opt.id || 'msg_' + (+new Date()).toString(36)
  29704. message.render(holder)
  29705. _messageItems[mid] = message
  29706. message.reset(opt)
  29707. updateHolderPos()
  29708. return mid
  29709. })
  29710. me.addListener('updatemessage', function (type, id, opt) {
  29711. opt = utils.isString(opt)
  29712. ? {
  29713. content: opt
  29714. }
  29715. : opt
  29716. var message = _messageItems[id]
  29717. message.render(holder)
  29718. message && message.reset(opt)
  29719. })
  29720. me.addListener('hidemessage', function (type, id) {
  29721. var message = _messageItems[id]
  29722. message && message.hide()
  29723. })
  29724. function updateHolderPos() {
  29725. var toolbarbox = me.ui.getDom('toolbarbox')
  29726. if (toolbarbox) {
  29727. holder.style.top = toolbarbox.offsetHeight + 3 + 'px'
  29728. }
  29729. holder.style.zIndex = Math.max(me.options.zIndex, me.iframe.style.zIndex) + 1
  29730. }
  29731. })
  29732. // adapter/autosave.js
  29733. UE.registerUI('autosave', function (editor) {
  29734. var timer = null,
  29735. uid = null
  29736. editor.on('afterautosave', function () {
  29737. clearTimeout(timer)
  29738. timer = setTimeout(function () {
  29739. if (uid) {
  29740. editor.trigger('hidemessage', uid)
  29741. }
  29742. uid = editor.trigger('showmessage', {
  29743. content: editor.getLang('autosave.success'),
  29744. timeout: 2000
  29745. })
  29746. }, 2000)
  29747. })
  29748. })
  29749. })()