ueditor.all.min.js 1004 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318
  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. })()