editor-all.js 1.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463
  1. (function(){
  2. // js/editor/_src/editor.js
  3. UEDITOR_CONFIG = window.UEDITOR_CONFIG || {};
  4. var baidu = window.baidu || {};
  5. window.baidu = baidu;
  6. window.UE = baidu.editor = window.UE || {};
  7. UE.plugins = {};
  8. UE.commands = {};
  9. UE.instants = {};
  10. UE.I18N = {};
  11. UE._customizeUI = {};
  12. UE.version = "1.4.3";
  13. var dom = UE.dom = {};
  14. // js/editor/_src/core/browser.js
  15. /**
  16. * 浏览器判断模块
  17. * @file
  18. * @module UE.browser
  19. * @since 1.2.6.1
  20. */
  21. /**
  22. * 提供浏览器检测的模块
  23. * @unfile
  24. * @module UE.browser
  25. */
  26. var browser = UE.browser = function(){
  27. var agent = navigator.userAgent.toLowerCase(),
  28. opera = window.opera,
  29. browser = {
  30. /**
  31. * @property {boolean} ie 检测当前浏览器是否为IE
  32. * @example
  33. * ```javascript
  34. * if ( UE.browser.ie ) {
  35. * console.log( '当前浏览器是IE' );
  36. * }
  37. * ```
  38. */
  39. ie : /(msie\s|trident.*rv:)([\w.]+)/.test(agent),
  40. /**
  41. * @property {boolean} opera 检测当前浏览器是否为Opera
  42. * @example
  43. * ```javascript
  44. * if ( UE.browser.opera ) {
  45. * console.log( '当前浏览器是Opera' );
  46. * }
  47. * ```
  48. */
  49. opera : ( !!opera && opera.version ),
  50. /**
  51. * @property {boolean} webkit 检测当前浏览器是否是webkit内核的浏览器
  52. * @example
  53. * ```javascript
  54. * if ( UE.browser.webkit ) {
  55. * console.log( '当前浏览器是webkit内核浏览器' );
  56. * }
  57. * ```
  58. */
  59. webkit : ( agent.indexOf( ' applewebkit/' ) > -1 ),
  60. /**
  61. * @property {boolean} mac 检测当前浏览器是否是运行在mac平台下
  62. * @example
  63. * ```javascript
  64. * if ( UE.browser.mac ) {
  65. * console.log( '当前浏览器运行在mac平台下' );
  66. * }
  67. * ```
  68. */
  69. mac : ( agent.indexOf( 'macintosh' ) > -1 ),
  70. /**
  71. * @property {boolean} quirks 检测当前浏览器是否处于“怪异模式”下
  72. * @example
  73. * ```javascript
  74. * if ( UE.browser.quirks ) {
  75. * console.log( '当前浏览器运行处于“怪异模式”' );
  76. * }
  77. * ```
  78. */
  79. quirks : ( document.compatMode == 'BackCompat' )
  80. };
  81. /**
  82. * @property {boolean} gecko 检测当前浏览器内核是否是gecko内核
  83. * @example
  84. * ```javascript
  85. * if ( UE.browser.gecko ) {
  86. * console.log( '当前浏览器内核是gecko内核' );
  87. * }
  88. * ```
  89. */
  90. browser.gecko =( navigator.product == 'Gecko' && !browser.webkit && !browser.opera && !browser.ie);
  91. var version = 0;
  92. // Internet Explorer 6.0+
  93. if ( browser.ie ){
  94. var v1 = agent.match(/(?:msie\s([\w.]+))/);
  95. var v2 = agent.match(/(?:trident.*rv:([\w.]+))/);
  96. if(v1 && v2 && v1[1] && v2[1]){
  97. version = Math.max(v1[1]*1,v2[1]*1);
  98. }else if(v1 && v1[1]){
  99. version = v1[1]*1;
  100. }else if(v2 && v2[1]){
  101. version = v2[1]*1;
  102. }else{
  103. version = 0;
  104. }
  105. browser.ie11Compat = document.documentMode == 11;
  106. /**
  107. * @property { boolean } ie9Compat 检测浏览器模式是否为 IE9 兼容模式
  108. * @warning 如果浏览器不是IE, 则该值为undefined
  109. * @example
  110. * ```javascript
  111. * if ( UE.browser.ie9Compat ) {
  112. * console.log( '当前浏览器运行在IE9兼容模式下' );
  113. * }
  114. * ```
  115. */
  116. browser.ie9Compat = document.documentMode == 9;
  117. /**
  118. * @property { boolean } ie8 检测浏览器是否是IE8浏览器
  119. * @warning 如果浏览器不是IE, 则该值为undefined
  120. * @example
  121. * ```javascript
  122. * if ( UE.browser.ie8 ) {
  123. * console.log( '当前浏览器是IE8浏览器' );
  124. * }
  125. * ```
  126. */
  127. browser.ie8 = !!document.documentMode;
  128. /**
  129. * @property { boolean } ie8Compat 检测浏览器模式是否为 IE8 兼容模式
  130. * @warning 如果浏览器不是IE, 则该值为undefined
  131. * @example
  132. * ```javascript
  133. * if ( UE.browser.ie8Compat ) {
  134. * console.log( '当前浏览器运行在IE8兼容模式下' );
  135. * }
  136. * ```
  137. */
  138. browser.ie8Compat = document.documentMode == 8;
  139. /**
  140. * @property { boolean } ie7Compat 检测浏览器模式是否为 IE7 兼容模式
  141. * @warning 如果浏览器不是IE, 则该值为undefined
  142. * @example
  143. * ```javascript
  144. * if ( UE.browser.ie7Compat ) {
  145. * console.log( '当前浏览器运行在IE7兼容模式下' );
  146. * }
  147. * ```
  148. */
  149. browser.ie7Compat = ( ( version == 7 && !document.documentMode )
  150. || document.documentMode == 7 );
  151. /**
  152. * @property { boolean } ie6Compat 检测浏览器模式是否为 IE6 模式 或者怪异模式
  153. * @warning 如果浏览器不是IE, 则该值为undefined
  154. * @example
  155. * ```javascript
  156. * if ( UE.browser.ie6Compat ) {
  157. * console.log( '当前浏览器运行在IE6模式或者怪异模式下' );
  158. * }
  159. * ```
  160. */
  161. browser.ie6Compat = ( version < 7 || browser.quirks );
  162. browser.ie9above = version > 8;
  163. browser.ie9below = version < 9;
  164. browser.ie11above = version > 10;
  165. browser.ie11below = version < 11;
  166. }
  167. // Gecko.
  168. if ( browser.gecko ){
  169. var geckoRelease = agent.match( /rv:([\d\.]+)/ );
  170. if ( geckoRelease )
  171. {
  172. geckoRelease = geckoRelease[1].split( '.' );
  173. version = geckoRelease[0] * 10000 + ( geckoRelease[1] || 0 ) * 100 + ( geckoRelease[2] || 0 ) * 1;
  174. }
  175. }
  176. /**
  177. * @property { Number } chrome 检测当前浏览器是否为Chrome, 如果是,则返回Chrome的大版本号
  178. * @warning 如果浏览器不是chrome, 则该值为undefined
  179. * @example
  180. * ```javascript
  181. * if ( UE.browser.chrome ) {
  182. * console.log( '当前浏览器是Chrome' );
  183. * }
  184. * ```
  185. */
  186. if (/chrome\/(\d+\.\d)/i.test(agent)) {
  187. browser.chrome = + RegExp['\x241'];
  188. }
  189. /**
  190. * @property { Number } safari 检测当前浏览器是否为Safari, 如果是,则返回Safari的大版本号
  191. * @warning 如果浏览器不是safari, 则该值为undefined
  192. * @example
  193. * ```javascript
  194. * if ( UE.browser.safari ) {
  195. * console.log( '当前浏览器是Safari' );
  196. * }
  197. * ```
  198. */
  199. if(/(\d+\.\d)?(?:\.\d)?\s+safari\/?(\d+\.\d+)?/i.test(agent) && !/chrome/i.test(agent)){
  200. browser.safari = + (RegExp['\x241'] || RegExp['\x242']);
  201. }
  202. // Opera 9.50+
  203. if ( browser.opera )
  204. version = parseFloat( opera.version() );
  205. // WebKit 522+ (Safari 3+)
  206. if ( browser.webkit )
  207. version = parseFloat( agent.match( / applewebkit\/(\d+)/ )[1] );
  208. /**
  209. * @property { Number } version 检测当前浏览器版本号
  210. * @remind
  211. * <ul>
  212. * <li>IE系列返回值为5,6,7,8,9,10等</li>
  213. * <li>gecko系列会返回10900,158900等</li>
  214. * <li>webkit系列会返回其build号 (如 522等)</li>
  215. * </ul>
  216. * @example
  217. * ```javascript
  218. * console.log( '当前浏览器版本号是: ' + UE.browser.version );
  219. * ```
  220. */
  221. browser.version = version;
  222. /**
  223. * @property { boolean } isCompatible 检测当前浏览器是否能够与UEditor良好兼容
  224. * @example
  225. * ```javascript
  226. * if ( UE.browser.isCompatible ) {
  227. * console.log( '浏览器与UEditor能够良好兼容' );
  228. * }
  229. * ```
  230. */
  231. browser.isCompatible =
  232. !browser.mobile && (
  233. ( browser.ie && version >= 6 ) ||
  234. ( browser.gecko && version >= 10801 ) ||
  235. ( browser.opera && version >= 9.5 ) ||
  236. ( browser.air && version >= 1 ) ||
  237. ( browser.webkit && version >= 522 ) ||
  238. false );
  239. return browser;
  240. }();
  241. //快捷方式
  242. var ie = browser.ie,
  243. webkit = browser.webkit,
  244. gecko = browser.gecko,
  245. opera = browser.opera;
  246. // js/editor/_src/core/utils.js
  247. /**
  248. * 工具函数包
  249. * @file
  250. * @module UE.utils
  251. * @since 1.2.6.1
  252. */
  253. /**
  254. * UEditor封装使用的静态工具函数
  255. * @module UE.utils
  256. * @unfile
  257. */
  258. var utils = UE.utils = {
  259. /**
  260. * 用给定的迭代器遍历对象
  261. * @method each
  262. * @param { Object } obj 需要遍历的对象
  263. * @param { Function } iterator 迭代器, 该方法接受两个参数, 第一个参数是当前所处理的value, 第二个参数是当前遍历对象的key
  264. * @example
  265. * ```javascript
  266. * var demoObj = {
  267. * key1: 1,
  268. * key2: 2
  269. * };
  270. *
  271. * //output: key1: 1, key2: 2
  272. * UE.utils.each( demoObj, funciton ( value, key ) {
  273. *
  274. * console.log( key + ":" + value );
  275. *
  276. * } );
  277. * ```
  278. */
  279. /**
  280. * 用给定的迭代器遍历数组或类数组对象
  281. * @method each
  282. * @param { Array } array 需要遍历的数组或者类数组
  283. * @param { Function } iterator 迭代器, 该方法接受两个参数, 第一个参数是当前所处理的value, 第二个参数是当前遍历对象的key
  284. * @example
  285. * ```javascript
  286. * var divs = document.getElmentByTagNames( "div" );
  287. *
  288. * //output: 0: DIV, 1: DIV ...
  289. * UE.utils.each( divs, funciton ( value, key ) {
  290. *
  291. * console.log( key + ":" + value.tagName );
  292. *
  293. * } );
  294. * ```
  295. */
  296. each : function(obj, iterator, context) {
  297. if (obj == null) return;
  298. if (obj.length === +obj.length) {
  299. for (var i = 0, l = obj.length; i < l; i++) {
  300. if(iterator.call(context, obj[i], i, obj) === false)
  301. return false;
  302. }
  303. } else {
  304. for (var key in obj) {
  305. if (obj.hasOwnProperty(key)) {
  306. if(iterator.call(context, obj[key], key, obj) === false)
  307. return false;
  308. }
  309. }
  310. }
  311. },
  312. /**
  313. * 以给定对象作为原型创建一个新对象
  314. * @method makeInstance
  315. * @param { Object } protoObject 该对象将作为新创建对象的原型
  316. * @return { Object } 新的对象, 该对象的原型是给定的protoObject对象
  317. * @example
  318. * ```javascript
  319. *
  320. * var protoObject = { sayHello: function () { console.log('Hello UEditor!'); } };
  321. *
  322. * var newObject = UE.utils.makeInstance( protoObject );
  323. * //output: Hello UEditor!
  324. * newObject.sayHello();
  325. * ```
  326. */
  327. makeInstance:function (obj) {
  328. var noop = new Function();
  329. noop.prototype = obj;
  330. obj = new noop;
  331. noop.prototype = null;
  332. return obj;
  333. },
  334. /**
  335. * 将source对象中的属性扩展到target对象上
  336. * @method extend
  337. * @remind 该方法将强制把source对象上的属性复制到target对象上
  338. * @see UE.utils.extend(Object,Object,Boolean)
  339. * @param { Object } target 目标对象, 新的属性将附加到该对象上
  340. * @param { Object } source 源对象, 该对象的属性会被附加到target对象上
  341. * @return { Object } 返回target对象
  342. * @example
  343. * ```javascript
  344. *
  345. * var target = { name: 'target', sex: 1 },
  346. * source = { name: 'source', age: 17 };
  347. *
  348. * UE.utils.extend( target, source );
  349. *
  350. * //output: { name: 'source', sex: 1, age: 17 }
  351. * console.log( target );
  352. *
  353. * ```
  354. */
  355. /**
  356. * 将source对象中的属性扩展到target对象上, 根据指定的isKeepTarget值决定是否保留目标对象中与
  357. * 源对象属性名相同的属性值。
  358. * @method extend
  359. * @param { Object } target 目标对象, 新的属性将附加到该对象上
  360. * @param { Object } source 源对象, 该对象的属性会被附加到target对象上
  361. * @param { Boolean } isKeepTarget 是否保留目标对象中与源对象中属性名相同的属性
  362. * @return { Object } 返回target对象
  363. * @example
  364. * ```javascript
  365. *
  366. * var target = { name: 'target', sex: 1 },
  367. * source = { name: 'source', age: 17 };
  368. *
  369. * UE.utils.extend( target, source, true );
  370. *
  371. * //output: { name: 'target', sex: 1, age: 17 }
  372. * console.log( target );
  373. *
  374. * ```
  375. */
  376. extend:function (t, s, b) {
  377. if (s) {
  378. for (var k in s) {
  379. if (!b || !t.hasOwnProperty(k)) {
  380. t[k] = s[k];
  381. }
  382. }
  383. }
  384. return t;
  385. },
  386. /**
  387. * 将给定的多个对象的属性复制到目标对象target上
  388. * @method extend2
  389. * @remind 该方法将强制把源对象上的属性复制到target对象上
  390. * @remind 该方法支持两个及以上的参数, 从第二个参数开始, 其属性都会被复制到第一个参数上。 如果遇到同名的属性,
  391. * 将会覆盖掉之前的值。
  392. * @param { Object } target 目标对象, 新的属性将附加到该对象上
  393. * @param { Object... } source 源对象, 支持多个对象, 该对象的属性会被附加到target对象上
  394. * @return { Object } 返回target对象
  395. * @example
  396. * ```javascript
  397. *
  398. * var target = {},
  399. * source1 = { name: 'source', age: 17 },
  400. * source2 = { title: 'dev' };
  401. *
  402. * UE.utils.extend2( target, source1, source2 );
  403. *
  404. * //output: { name: 'source', age: 17, title: 'dev' }
  405. * console.log( target );
  406. *
  407. * ```
  408. */
  409. extend2:function (t) {
  410. var a = arguments;
  411. for (var i = 1; i < a.length; i++) {
  412. var x = a[i];
  413. for (var k in x) {
  414. if (!t.hasOwnProperty(k)) {
  415. t[k] = x[k];
  416. }
  417. }
  418. }
  419. return t;
  420. },
  421. /**
  422. * 模拟继承机制, 使得subClass继承自superClass
  423. * @method inherits
  424. * @param { Object } subClass 子类对象
  425. * @param { Object } superClass 超类对象
  426. * @warning 该方法只能让subClass继承超类的原型, subClass对象自身的属性和方法不会被继承
  427. * @return { Object } 继承superClass后的子类对象
  428. * @example
  429. * ```javascript
  430. * function SuperClass(){
  431. * this.name = "小李";
  432. * }
  433. *
  434. * SuperClass.prototype = {
  435. * hello:function(str){
  436. * console.log(this.name + str);
  437. * }
  438. * }
  439. *
  440. * function SubClass(){
  441. * this.name = "小张";
  442. * }
  443. *
  444. * UE.utils.inherits(SubClass,SuperClass);
  445. *
  446. * var sub = new SubClass();
  447. * //output: '小张早上好!
  448. * sub.hello("早上好!");
  449. * ```
  450. */
  451. inherits:function (subClass, superClass) {
  452. var oldP = subClass.prototype,
  453. newP = utils.makeInstance(superClass.prototype);
  454. utils.extend(newP, oldP, true);
  455. subClass.prototype = newP;
  456. return (newP.constructor = subClass);
  457. },
  458. /**
  459. * 用指定的context对象作为函数fn的上下文
  460. * @method bind
  461. * @param { Function } fn 需要绑定上下文的函数对象
  462. * @param { Object } content 函数fn新的上下文对象
  463. * @return { Function } 一个新的函数, 该函数作为原始函数fn的代理, 将完成fn的上下文调换工作。
  464. * @example
  465. * ```javascript
  466. *
  467. * var name = 'window',
  468. * newTest = null;
  469. *
  470. * function test () {
  471. * console.log( this.name );
  472. * }
  473. *
  474. * newTest = UE.utils.bind( test, { name: 'object' } );
  475. *
  476. * //output: object
  477. * newTest();
  478. *
  479. * //output: window
  480. * test();
  481. *
  482. * ```
  483. */
  484. bind:function (fn, context) {
  485. return function () {
  486. return fn.apply(context, arguments);
  487. };
  488. },
  489. /**
  490. * 创建延迟指定时间后执行的函数fn
  491. * @method defer
  492. * @param { Function } fn 需要延迟执行的函数对象
  493. * @param { int } delay 延迟的时间, 单位是毫秒
  494. * @warning 该方法的时间控制是不精确的,仅仅只能保证函数的执行是在给定的时间之后,
  495. * 而不能保证刚好到达延迟时间时执行。
  496. * @return { Function } 目标函数fn的代理函数, 只有执行该函数才能起到延时效果
  497. * @example
  498. * ```javascript
  499. * var start = 0;
  500. *
  501. * function test(){
  502. * console.log( new Date() - start );
  503. * }
  504. *
  505. * var testDefer = UE.utils.defer( test, 1000 );
  506. * //
  507. * start = new Date();
  508. * //output: (大约在1000毫秒之后输出) 1000
  509. * testDefer();
  510. * ```
  511. */
  512. /**
  513. * 创建延迟指定时间后执行的函数fn, 如果在延迟时间内再次执行该方法, 将会根据指定的exclusion的值,
  514. * 决定是否取消前一次函数的执行, 如果exclusion的值为true, 则取消执行,反之,将继续执行前一个方法。
  515. * @method defer
  516. * @param { Function } fn 需要延迟执行的函数对象
  517. * @param { int } delay 延迟的时间, 单位是毫秒
  518. * @param { Boolean } exclusion 如果在延迟时间内再次执行该函数,该值将决定是否取消执行前一次函数的执行,
  519. * 值为true表示取消执行, 反之则将在执行前一次函数之后才执行本次函数调用。
  520. * @warning 该方法的时间控制是不精确的,仅仅只能保证函数的执行是在给定的时间之后,
  521. * 而不能保证刚好到达延迟时间时执行。
  522. * @return { Function } 目标函数fn的代理函数, 只有执行该函数才能起到延时效果
  523. * @example
  524. * ```javascript
  525. *
  526. * function test(){
  527. * console.log(1);
  528. * }
  529. *
  530. * var testDefer = UE.utils.defer( test, 1000, true );
  531. *
  532. * //output: (两次调用仅有一次输出) 1
  533. * testDefer();
  534. * testDefer();
  535. * ```
  536. */
  537. defer:function (fn, delay, exclusion) {
  538. var timerID;
  539. return function () {
  540. if (exclusion) {
  541. clearTimeout(timerID);
  542. }
  543. timerID = setTimeout(fn, delay);
  544. };
  545. },
  546. /**
  547. * 获取元素item在数组array中首次出现的位置, 如果未找到item, 则返回-1
  548. * @method indexOf
  549. * @remind 该方法的匹配过程使用的是恒等“===”
  550. * @param { Array } array 需要查找的数组对象
  551. * @param { * } item 需要在目标数组中查找的值
  552. * @return { int } 返回item在目标数组array中首次出现的位置, 如果在数组中未找到item, 则返回-1
  553. * @example
  554. * ```javascript
  555. * var item = 1,
  556. * arr = [ 3, 4, 6, 8, 1, 1, 2 ];
  557. *
  558. * //output: 4
  559. * console.log( UE.utils.indexOf( arr, item ) );
  560. * ```
  561. */
  562. /**
  563. * 获取元素item数组array中首次出现的位置, 如果未找到item, 则返回-1。通过start的值可以指定搜索的起始位置。
  564. * @method indexOf
  565. * @remind 该方法的匹配过程使用的是恒等“===”
  566. * @param { Array } array 需要查找的数组对象
  567. * @param { * } item 需要在目标数组中查找的值
  568. * @param { int } start 搜索的起始位置
  569. * @return { int } 返回item在目标数组array中的start位置之后首次出现的位置, 如果在数组中未找到item, 则返回-1
  570. * @example
  571. * ```javascript
  572. * var item = 1,
  573. * arr = [ 3, 4, 6, 8, 1, 2, 8, 3, 2, 1, 1, 4 ];
  574. *
  575. * //output: 9
  576. * console.log( UE.utils.indexOf( arr, item, 5 ) );
  577. * ```
  578. */
  579. indexOf:function (array, item, start) {
  580. var index = -1;
  581. start = this.isNumber(start) ? start : 0;
  582. this.each(array, function (v, i) {
  583. if (i >= start && v === item) {
  584. index = i;
  585. return false;
  586. }
  587. });
  588. return index;
  589. },
  590. /**
  591. * 移除数组array中所有的元素item
  592. * @method removeItem
  593. * @param { Array } array 要移除元素的目标数组
  594. * @param { * } item 将要被移除的元素
  595. * @remind 该方法的匹配过程使用的是恒等“===”
  596. * @example
  597. * ```javascript
  598. * var arr = [ 4, 5, 7, 1, 3, 4, 6 ];
  599. *
  600. * UE.utils.removeItem( arr, 4 );
  601. * //output: [ 5, 7, 1, 3, 6 ]
  602. * console.log( arr );
  603. *
  604. * ```
  605. */
  606. removeItem:function (array, item) {
  607. for (var i = 0, l = array.length; i < l; i++) {
  608. if (array[i] === item) {
  609. array.splice(i, 1);
  610. i--;
  611. }
  612. }
  613. },
  614. /**
  615. * 删除字符串str的首尾空格
  616. * @method trim
  617. * @param { String } str 需要删除首尾空格的字符串
  618. * @return { String } 删除了首尾的空格后的字符串
  619. * @example
  620. * ```javascript
  621. *
  622. * var str = " UEdtior ";
  623. *
  624. * //output: 9
  625. * console.log( str.length );
  626. *
  627. * //output: 7
  628. * console.log( UE.utils.trim( " UEdtior " ).length );
  629. *
  630. * //output: 9
  631. * console.log( str.length );
  632. *
  633. * ```
  634. */
  635. trim:function (str) {
  636. return str.replace(/(^[ \t\n\r]+)|([ \t\n\r]+$)/g, '');
  637. },
  638. /**
  639. * 将字符串str以','分隔成数组后,将该数组转换成哈希对象, 其生成的hash对象的key为数组中的元素, value为1
  640. * @method listToMap
  641. * @warning 该方法在生成的hash对象中,会为每一个key同时生成一个另一个全大写的key。
  642. * @param { String } str 该字符串将被以','分割为数组, 然后进行转化
  643. * @return { Object } 转化之后的hash对象
  644. * @example
  645. * ```javascript
  646. *
  647. * //output: Object {UEdtior: 1, UEDTIOR: 1, Hello: 1, HELLO: 1}
  648. * console.log( UE.utils.listToMap( 'UEdtior,Hello' ) );
  649. *
  650. * ```
  651. */
  652. /**
  653. * 将字符串数组转换成哈希对象, 其生成的hash对象的key为数组中的元素, value为1
  654. * @method listToMap
  655. * @warning 该方法在生成的hash对象中,会为每一个key同时生成一个另一个全大写的key。
  656. * @param { Array } arr 字符串数组
  657. * @return { Object } 转化之后的hash对象
  658. * @example
  659. * ```javascript
  660. *
  661. * //output: Object {UEdtior: 1, UEDTIOR: 1, Hello: 1, HELLO: 1}
  662. * console.log( UE.utils.listToMap( [ 'UEdtior', 'Hello' ] ) );
  663. *
  664. * ```
  665. */
  666. listToMap:function (list) {
  667. if (!list)return {};
  668. list = utils.isArray(list) ? list : list.split(',');
  669. for (var i = 0, ci, obj = {}; ci = list[i++];) {
  670. obj[ci.toUpperCase()] = obj[ci] = 1;
  671. }
  672. return obj;
  673. },
  674. /**
  675. * 将str中的html符号转义,将转义“',&,<,",>”五个字符
  676. * @method unhtml
  677. * @param { String } str 需要转义的字符串
  678. * @return { String } 转义后的字符串
  679. * @example
  680. * ```javascript
  681. * var html = '<body>&</body>';
  682. *
  683. * //output: &lt;body&gt;&amp;&lt;/body&gt;
  684. * console.log( UE.utils.unhtml( html ) );
  685. *
  686. * ```
  687. */
  688. unhtml:function (str, reg) {
  689. return str ? str.replace(reg || /[&<">'](?:(amp|lt|quot|gt|#39|nbsp|#\d+);)?/g, function (a, b) {
  690. if (b) {
  691. return a;
  692. } else {
  693. return {
  694. '<':'&lt;',
  695. '&':'&amp;',
  696. '"':'&quot;',
  697. '>':'&gt;',
  698. "'":'&#39;'
  699. }[a]
  700. }
  701. }) : '';
  702. },
  703. /**
  704. * 将str中的转义字符还原成html字符
  705. * @see UE.utils.unhtml(String);
  706. * @method html
  707. * @param { String } str 需要逆转义的字符串
  708. * @return { String } 逆转义后的字符串
  709. * @example
  710. * ```javascript
  711. *
  712. * var str = '&lt;body&gt;&amp;&lt;/body&gt;';
  713. *
  714. * //output: <body>&</body>
  715. * console.log( UE.utils.html( str ) );
  716. *
  717. * ```
  718. */
  719. html:function (str) {
  720. return str ? str.replace(/&((g|l|quo)t|amp|#39|nbsp);/g, function (m) {
  721. return {
  722. '&lt;':'<',
  723. '&amp;':'&',
  724. '&quot;':'"',
  725. '&gt;':'>',
  726. '&#39;':"'",
  727. '&nbsp;':' '
  728. }[m]
  729. }) : '';
  730. },
  731. /**
  732. * 将css样式转换为驼峰的形式
  733. * @method cssStyleToDomStyle
  734. * @param { String } cssName 需要转换的css样式名
  735. * @return { String } 转换成驼峰形式后的css样式名
  736. * @example
  737. * ```javascript
  738. *
  739. * var str = 'border-top';
  740. *
  741. * //output: borderTop
  742. * console.log( UE.utils.cssStyleToDomStyle( str ) );
  743. *
  744. * ```
  745. */
  746. cssStyleToDomStyle:function () {
  747. var test = document.createElement('div').style,
  748. cache = {
  749. 'float':test.cssFloat != undefined ? 'cssFloat' : test.styleFloat != undefined ? 'styleFloat' : 'float'
  750. };
  751. return function (cssName) {
  752. return cache[cssName] || (cache[cssName] = cssName.toLowerCase().replace(/-./g, function (match) {
  753. return match.charAt(1).toUpperCase();
  754. }));
  755. };
  756. }(),
  757. /**
  758. * 动态加载文件到doc中
  759. * @method loadFile
  760. * @param { DomDocument } document 需要加载资源文件的文档对象
  761. * @param { Object } options 加载资源文件的属性集合, 取值请参考代码示例
  762. * @example
  763. * ```javascript
  764. *
  765. * UE.utils.loadFile( document, {
  766. * src:"test.js",
  767. * tag:"script",
  768. * type:"text/javascript",
  769. * defer:"defer"
  770. * } );
  771. *
  772. * ```
  773. */
  774. /**
  775. * 动态加载文件到doc中,加载成功后执行的回调函数fn
  776. * @method loadFile
  777. * @param { DomDocument } document 需要加载资源文件的文档对象
  778. * @param { Object } options 加载资源文件的属性集合, 该集合支持的值是script标签和style标签支持的所有属性。
  779. * @param { Function } fn 资源文件加载成功之后执行的回调
  780. * @warning 对于在同一个文档中多次加载同一URL的文件, 该方法会在第一次加载之后缓存该请求,
  781. * 在此之后的所有同一URL的请求, 将会直接触发回调。
  782. * @example
  783. * ```javascript
  784. *
  785. * UE.utils.loadFile( document, {
  786. * src:"test.js",
  787. * tag:"script",
  788. * type:"text/javascript",
  789. * defer:"defer"
  790. * }, function () {
  791. * console.log('加载成功');
  792. * } );
  793. *
  794. * ```
  795. */
  796. loadFile:function () {
  797. var tmpList = [];
  798. function getItem(doc, obj) {
  799. try {
  800. for (var i = 0, ci; ci = tmpList[i++];) {
  801. if (ci.doc === doc && ci.url == (obj.src || obj.href)) {
  802. return ci;
  803. }
  804. }
  805. } catch (e) {
  806. return null;
  807. }
  808. }
  809. return function (doc, obj, fn) {
  810. var item = getItem(doc, obj);
  811. if (item) {
  812. if (item.ready) {
  813. fn && fn();
  814. } else {
  815. item.funs.push(fn)
  816. }
  817. return;
  818. }
  819. tmpList.push({
  820. doc:doc,
  821. url:obj.src || obj.href,
  822. funs:[fn]
  823. });
  824. if (!doc.body) {
  825. var html = [];
  826. for (var p in obj) {
  827. if (p == 'tag')continue;
  828. html.push(p + '="' + obj[p] + '"')
  829. }
  830. doc.write('<' + obj.tag + ' ' + html.join(' ') + ' ></' + obj.tag + '>');
  831. return;
  832. }
  833. if (obj.id && doc.getElementById(obj.id)) {
  834. return;
  835. }
  836. var element = doc.createElement(obj.tag);
  837. delete obj.tag;
  838. for (var p in obj) {
  839. element.setAttribute(p, obj[p]);
  840. }
  841. element.onload = element.onreadystatechange = function () {
  842. if (!this.readyState || /loaded|complete/.test(this.readyState)) {
  843. item = getItem(doc, obj);
  844. if (item.funs.length > 0) {
  845. item.ready = 1;
  846. for (var fi; fi = item.funs.pop();) {
  847. fi();
  848. }
  849. }
  850. element.onload = element.onreadystatechange = null;
  851. }
  852. };
  853. element.onerror = function () {
  854. throw Error('The load ' + (obj.href || obj.src) + ' fails,check the url settings of file ueditor.config.js ')
  855. };
  856. doc.getElementsByTagName("head")[0].appendChild(element);
  857. }
  858. }(),
  859. /**
  860. * 判断obj对象是否为空
  861. * @method isEmptyObject
  862. * @param { * } obj 需要判断的对象
  863. * @remind 如果判断的对象是NULL, 将直接返回true, 如果是数组且为空, 返回true, 如果是字符串, 且字符串为空,
  864. * 返回true, 如果是普通对象, 且该对象没有任何实例属性, 返回true
  865. * @return { Boolean } 对象是否为空
  866. * @example
  867. * ```javascript
  868. *
  869. * //output: true
  870. * console.log( UE.utils.isEmptyObject( {} ) );
  871. *
  872. * //output: true
  873. * console.log( UE.utils.isEmptyObject( [] ) );
  874. *
  875. * //output: true
  876. * console.log( UE.utils.isEmptyObject( "" ) );
  877. *
  878. * //output: false
  879. * console.log( UE.utils.isEmptyObject( { key: 1 } ) );
  880. *
  881. * //output: false
  882. * console.log( UE.utils.isEmptyObject( [1] ) );
  883. *
  884. * //output: false
  885. * console.log( UE.utils.isEmptyObject( "1" ) );
  886. *
  887. * ```
  888. */
  889. isEmptyObject:function (obj) {
  890. if (obj == null) return true;
  891. if (this.isArray(obj) || this.isString(obj)) return obj.length === 0;
  892. for (var key in obj) if (obj.hasOwnProperty(key)) return false;
  893. return true;
  894. },
  895. /**
  896. * 把rgb格式的颜色值转换成16进制格式
  897. * @method fixColor
  898. * @param { String } rgb格式的颜色值
  899. * @param { String }
  900. * @example
  901. * rgb(255,255,255) => "#ffffff"
  902. */
  903. fixColor:function (name, value) {
  904. if (/color/i.test(name) && /rgba?/.test(value)) {
  905. var array = value.split(",");
  906. if (array.length > 3)
  907. return "";
  908. value = "#";
  909. for (var i = 0, color; color = array[i++];) {
  910. color = parseInt(color.replace(/[^\d]/gi, ''), 10).toString(16);
  911. value += color.length == 1 ? "0" + color : color;
  912. }
  913. value = value.toUpperCase();
  914. }
  915. return value;
  916. },
  917. /**
  918. * 只针对border,padding,margin做了处理,因为性能问题
  919. * @public
  920. * @function
  921. * @param {String} val style字符串
  922. */
  923. optCss:function (val) {
  924. var padding, margin, border;
  925. val = val.replace(/(padding|margin|border)\-([^:]+):([^;]+);?/gi, function (str, key, name, val) {
  926. if (val.split(' ').length == 1) {
  927. switch (key) {
  928. case 'padding':
  929. !padding && (padding = {});
  930. padding[name] = val;
  931. return '';
  932. case 'margin':
  933. !margin && (margin = {});
  934. margin[name] = val;
  935. return '';
  936. case 'border':
  937. return val == 'initial' ? '' : str;
  938. }
  939. }
  940. return str;
  941. });
  942. function opt(obj, name) {
  943. if (!obj) {
  944. return '';
  945. }
  946. var t = obj.top , b = obj.bottom, l = obj.left, r = obj.right, val = '';
  947. if (!t || !l || !b || !r) {
  948. for (var p in obj) {
  949. val += ';' + name + '-' + p + ':' + obj[p] + ';';
  950. }
  951. } else {
  952. val += ';' + name + ':' +
  953. (t == b && b == l && l == r ? t :
  954. t == b && l == r ? (t + ' ' + l) :
  955. l == r ? (t + ' ' + l + ' ' + b) : (t + ' ' + r + ' ' + b + ' ' + l)) + ';'
  956. }
  957. return val;
  958. }
  959. val += opt(padding, 'padding') + opt(margin, 'margin');
  960. return val.replace(/^[ \n\r\t;]*|[ \n\r\t]*$/, '').replace(/;([ \n\r\t]+)|\1;/g, ';')
  961. .replace(/(&((l|g)t|quot|#39))?;{2,}/g, function (a, b) {
  962. return b ? b + ";;" : ';'
  963. });
  964. },
  965. /**
  966. * 克隆对象
  967. * @method clone
  968. * @param { Object } source 源对象
  969. * @return { Object } source的一个副本
  970. */
  971. /**
  972. * 深度克隆对象,将source的属性克隆到target对象, 会覆盖target重名的属性。
  973. * @method clone
  974. * @param { Object } source 源对象
  975. * @param { Object } target 目标对象
  976. * @return { Object } 附加了source对象所有属性的target对象
  977. */
  978. clone:function (source, target) {
  979. var tmp;
  980. target = target || {};
  981. for (var i in source) {
  982. if (source.hasOwnProperty(i)) {
  983. tmp = source[i];
  984. if (typeof tmp == 'object') {
  985. target[i] = utils.isArray(tmp) ? [] : {};
  986. utils.clone(source[i], target[i])
  987. } else {
  988. target[i] = tmp;
  989. }
  990. }
  991. }
  992. return target;
  993. },
  994. /**
  995. * 把cm/pt为单位的值转换为px为单位的值
  996. * @method transUnitToPx
  997. * @param { String } 待转换的带单位的字符串
  998. * @return { String } 转换为px为计量单位的值的字符串
  999. * @example
  1000. * ```javascript
  1001. *
  1002. * //output: 500px
  1003. * console.log( UE.utils.transUnitToPx( '20cm' ) );
  1004. *
  1005. * //output: 27px
  1006. * console.log( UE.utils.transUnitToPx( '20pt' ) );
  1007. *
  1008. * ```
  1009. */
  1010. transUnitToPx:function (val) {
  1011. if (!/(pt|cm)/.test(val)) {
  1012. return val
  1013. }
  1014. var unit;
  1015. val.replace(/([\d.]+)(\w+)/, function (str, v, u) {
  1016. val = v;
  1017. unit = u;
  1018. });
  1019. switch (unit) {
  1020. case 'cm':
  1021. val = parseFloat(val) * 25;
  1022. break;
  1023. case 'pt':
  1024. val = Math.round(parseFloat(val) * 96 / 72);
  1025. }
  1026. return val + (val ? 'px' : '');
  1027. },
  1028. /**
  1029. * 在dom树ready之后执行给定的回调函数
  1030. * @method domReady
  1031. * @remind 如果在执行该方法的时候, dom树已经ready, 那么回调函数将立刻执行
  1032. * @param { Function } fn dom树ready之后的回调函数
  1033. * @example
  1034. * ```javascript
  1035. *
  1036. * UE.utils.domReady( function () {
  1037. *
  1038. * console.log('123');
  1039. *
  1040. * } );
  1041. *
  1042. * ```
  1043. */
  1044. domReady:function () {
  1045. var fnArr = [];
  1046. function doReady(doc) {
  1047. //确保onready只执行一次
  1048. doc.isReady = true;
  1049. for (var ci; ci = fnArr.pop(); ci()) {
  1050. }
  1051. }
  1052. return function (onready, win) {
  1053. win = win || window;
  1054. var doc = win.document;
  1055. onready && fnArr.push(onready);
  1056. if (doc.readyState === "complete") {
  1057. doReady(doc);
  1058. } else {
  1059. doc.isReady && doReady(doc);
  1060. if (browser.ie && browser.version != 11) {
  1061. (function () {
  1062. if (doc.isReady) return;
  1063. try {
  1064. doc.documentElement.doScroll("left");
  1065. } catch (error) {
  1066. setTimeout(arguments.callee, 0);
  1067. return;
  1068. }
  1069. doReady(doc);
  1070. })();
  1071. win.attachEvent('onload', function () {
  1072. doReady(doc)
  1073. });
  1074. } else {
  1075. doc.addEventListener("DOMContentLoaded", function () {
  1076. doc.removeEventListener("DOMContentLoaded", arguments.callee, false);
  1077. doReady(doc);
  1078. }, false);
  1079. win.addEventListener('load', function () {
  1080. doReady(doc)
  1081. }, false);
  1082. }
  1083. }
  1084. }
  1085. }(),
  1086. /**
  1087. * 动态添加css样式
  1088. * @method cssRule
  1089. * @param { String } 节点名称
  1090. * @grammar UE.utils.cssRule('添加的样式的节点名称',['样式','放到哪个document上'])
  1091. * @grammar UE.utils.cssRule('body','body{background:#ccc}') => null //给body添加背景颜色
  1092. * @grammar UE.utils.cssRule('body') =>样式的字符串 //取得key值为body的样式的内容,如果没有找到key值先关的样式将返回空,例如刚才那个背景颜色,将返回 body{background:#ccc}
  1093. * @grammar UE.utils.cssRule('body',document) => 返回指定key的样式,并且指定是哪个document
  1094. * @grammar UE.utils.cssRule('body','') =>null //清空给定的key值的背景颜色
  1095. */
  1096. cssRule:browser.ie && browser.version != 11 ? function (key, style, doc) {
  1097. var indexList, index;
  1098. if(style === undefined || style && style.nodeType && style.nodeType == 9){
  1099. //获取样式
  1100. doc = style && style.nodeType && style.nodeType == 9 ? style : (doc || document);
  1101. indexList = doc.indexList || (doc.indexList = {});
  1102. index = indexList[key];
  1103. if(index !== undefined){
  1104. return doc.styleSheets[index].cssText
  1105. }
  1106. return undefined;
  1107. }
  1108. doc = doc || document;
  1109. indexList = doc.indexList || (doc.indexList = {});
  1110. index = indexList[key];
  1111. //清除样式
  1112. if(style === ''){
  1113. if(index!== undefined){
  1114. doc.styleSheets[index].cssText = '';
  1115. delete indexList[key];
  1116. return true
  1117. }
  1118. return false;
  1119. }
  1120. //添加样式
  1121. if(index!== undefined){
  1122. sheetStyle = doc.styleSheets[index];
  1123. }else{
  1124. sheetStyle = doc.createStyleSheet('', index = doc.styleSheets.length);
  1125. indexList[key] = index;
  1126. }
  1127. sheetStyle.cssText = style;
  1128. }: function (key, style, doc) {
  1129. var head, node;
  1130. if(style === undefined || style && style.nodeType && style.nodeType == 9){
  1131. //获取样式
  1132. doc = style && style.nodeType && style.nodeType == 9 ? style : (doc || document);
  1133. node = doc.getElementById(key);
  1134. return node ? node.innerHTML : undefined;
  1135. }
  1136. doc = doc || document;
  1137. node = doc.getElementById(key);
  1138. //清除样式
  1139. if(style === ''){
  1140. if(node){
  1141. node.parentNode.removeChild(node);
  1142. return true
  1143. }
  1144. return false;
  1145. }
  1146. //添加样式
  1147. if(node){
  1148. node.innerHTML = style;
  1149. }else{
  1150. node = doc.createElement('style');
  1151. node.id = key;
  1152. node.innerHTML = style;
  1153. doc.getElementsByTagName('head')[0].appendChild(node);
  1154. }
  1155. },
  1156. sort:function(array,compareFn){
  1157. compareFn = compareFn || function(item1, item2){ return item1.localeCompare(item2);};
  1158. for(var i= 0,len = array.length; i<len; i++){
  1159. for(var j = i,length = array.length; j<length; j++){
  1160. if(compareFn(array[i], array[j]) > 0){
  1161. var t = array[i];
  1162. array[i] = array[j];
  1163. array[j] = t;
  1164. }
  1165. }
  1166. }
  1167. return array;
  1168. },
  1169. serializeParam:function (json) {
  1170. var strArr = [];
  1171. for (var i in json) {
  1172. //忽略默认的几个参数
  1173. if(i=="method" || i=="timeout" || i=="async") continue;
  1174. //传递过来的对象和函数不在提交之列
  1175. if (!((typeof json[i]).toLowerCase() == "function" || (typeof json[i]).toLowerCase() == "object")) {
  1176. strArr.push( encodeURIComponent(i) + "="+encodeURIComponent(json[i]) );
  1177. } else if (utils.isArray(json[i])) {
  1178. //支持传数组内容
  1179. for(var j = 0; j < json[i].length; j++) {
  1180. strArr.push( encodeURIComponent(i) + "[]="+encodeURIComponent(json[i][j]) );
  1181. }
  1182. }
  1183. }
  1184. return strArr.join("&");
  1185. },
  1186. formatUrl:function (url) {
  1187. var u = url.replace(/&&/g, '&');
  1188. u = u.replace(/\?&/g, '?');
  1189. u = u.replace(/&$/g, '');
  1190. u = u.replace(/&#/g, '#');
  1191. u = u.replace(/&+/g, '&');
  1192. return u;
  1193. },
  1194. isCrossDomainUrl:function (url) {
  1195. var a = document.createElement('a');
  1196. a.href = url;
  1197. if (browser.ie) {
  1198. a.href = a.href;
  1199. }
  1200. return !(a.protocol == location.protocol && a.hostname == location.hostname &&
  1201. (a.port == location.port || (a.port == '80' && location.port == '') || (a.port == '' && location.port == '80')));
  1202. },
  1203. clearEmptyAttrs : function(obj){
  1204. for(var p in obj){
  1205. if(obj[p] === ''){
  1206. delete obj[p]
  1207. }
  1208. }
  1209. return obj;
  1210. },
  1211. str2json : function(s){
  1212. if (!utils.isString(s)) return null;
  1213. if (window.JSON) {
  1214. return JSON.parse(s);
  1215. } else {
  1216. return (new Function("return " + utils.trim(s || '')))();
  1217. }
  1218. },
  1219. json2str : (function(){
  1220. if (window.JSON) {
  1221. return JSON.stringify;
  1222. } else {
  1223. var escapeMap = {
  1224. "\b": '\\b',
  1225. "\t": '\\t',
  1226. "\n": '\\n',
  1227. "\f": '\\f',
  1228. "\r": '\\r',
  1229. '"' : '\\"',
  1230. "\\": '\\\\'
  1231. };
  1232. function encodeString(source) {
  1233. if (/["\\\x00-\x1f]/.test(source)) {
  1234. source = source.replace(
  1235. /["\\\x00-\x1f]/g,
  1236. function (match) {
  1237. var c = escapeMap[match];
  1238. if (c) {
  1239. return c;
  1240. }
  1241. c = match.charCodeAt();
  1242. return "\\u00"
  1243. + Math.floor(c / 16).toString(16)
  1244. + (c % 16).toString(16);
  1245. });
  1246. }
  1247. return '"' + source + '"';
  1248. }
  1249. function encodeArray(source) {
  1250. var result = ["["],
  1251. l = source.length,
  1252. preComma, i, item;
  1253. for (i = 0; i < l; i++) {
  1254. item = source[i];
  1255. switch (typeof item) {
  1256. case "undefined":
  1257. case "function":
  1258. case "unknown":
  1259. break;
  1260. default:
  1261. if(preComma) {
  1262. result.push(',');
  1263. }
  1264. result.push(utils.json2str(item));
  1265. preComma = 1;
  1266. }
  1267. }
  1268. result.push("]");
  1269. return result.join("");
  1270. }
  1271. function pad(source) {
  1272. return source < 10 ? '0' + source : source;
  1273. }
  1274. function encodeDate(source){
  1275. return '"' + source.getFullYear() + "-"
  1276. + pad(source.getMonth() + 1) + "-"
  1277. + pad(source.getDate()) + "T"
  1278. + pad(source.getHours()) + ":"
  1279. + pad(source.getMinutes()) + ":"
  1280. + pad(source.getSeconds()) + '"';
  1281. }
  1282. return function (value) {
  1283. switch (typeof value) {
  1284. case 'undefined':
  1285. return 'undefined';
  1286. case 'number':
  1287. return isFinite(value) ? String(value) : "null";
  1288. case 'string':
  1289. return encodeString(value);
  1290. case 'boolean':
  1291. return String(value);
  1292. default:
  1293. if (value === null) {
  1294. return 'null';
  1295. } else if (utils.isArray(value)) {
  1296. return encodeArray(value);
  1297. } else if (utils.isDate(value)) {
  1298. return encodeDate(value);
  1299. } else {
  1300. var result = ['{'],
  1301. encode = utils.json2str,
  1302. preComma,
  1303. item;
  1304. for (var key in value) {
  1305. if (Object.prototype.hasOwnProperty.call(value, key)) {
  1306. item = value[key];
  1307. switch (typeof item) {
  1308. case 'undefined':
  1309. case 'unknown':
  1310. case 'function':
  1311. break;
  1312. default:
  1313. if (preComma) {
  1314. result.push(',');
  1315. }
  1316. preComma = 1;
  1317. result.push(encode(key) + ':' + encode(item));
  1318. }
  1319. }
  1320. }
  1321. result.push('}');
  1322. return result.join('');
  1323. }
  1324. }
  1325. };
  1326. }
  1327. })()
  1328. };
  1329. /**
  1330. * 判断给定的对象是否是字符串
  1331. * @method isString
  1332. * @param { * } object 需要判断的对象
  1333. * @return { Boolean } 给定的对象是否是字符串
  1334. */
  1335. /**
  1336. * 判断给定的对象是否是数组
  1337. * @method isArray
  1338. * @param { * } object 需要判断的对象
  1339. * @return { Boolean } 给定的对象是否是数组
  1340. */
  1341. /**
  1342. * 判断给定的对象是否是一个Function
  1343. * @method isFunction
  1344. * @param { * } object 需要判断的对象
  1345. * @return { Boolean } 给定的对象是否是Function
  1346. */
  1347. /**
  1348. * 判断给定的对象是否是Number
  1349. * @method isNumber
  1350. * @param { * } object 需要判断的对象
  1351. * @return { Boolean } 给定的对象是否是Number
  1352. */
  1353. /**
  1354. * 判断给定的对象是否是一个正则表达式
  1355. * @method isRegExp
  1356. * @param { * } object 需要判断的对象
  1357. * @return { Boolean } 给定的对象是否是正则表达式
  1358. */
  1359. /**
  1360. * 判断给定的对象是否是一个普通对象
  1361. * @method isObject
  1362. * @param { * } object 需要判断的对象
  1363. * @return { Boolean } 给定的对象是否是普通对象
  1364. */
  1365. utils.each(['String', 'Function', 'Array', 'Number', 'RegExp', 'Object', 'Date'], function (v) {
  1366. UE.utils['is' + v] = function (obj) {
  1367. return Object.prototype.toString.apply(obj) == '[object ' + v + ']';
  1368. }
  1369. });
  1370. // js/editor/_src/core/EventBase.js
  1371. /**
  1372. * UE采用的事件基类
  1373. * @file
  1374. * @module UE
  1375. * @class EventBase
  1376. * @since 1.2.6.1
  1377. */
  1378. /**
  1379. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  1380. * @unfile
  1381. * @module UE
  1382. */
  1383. /**
  1384. * UE采用的事件基类,继承此类的对应类将获取addListener,removeListener,fireEvent方法。
  1385. * 在UE中,Editor以及所有ui实例都继承了该类,故可以在对应的ui对象以及editor对象上使用上述方法。
  1386. * @unfile
  1387. * @module UE
  1388. * @class EventBase
  1389. */
  1390. /**
  1391. * 通过此构造器,子类可以继承EventBase获取事件监听的方法
  1392. * @constructor
  1393. * @example
  1394. * ```javascript
  1395. * UE.EventBase.call(editor);
  1396. * ```
  1397. */
  1398. var EventBase = UE.EventBase = function () {};
  1399. EventBase.prototype = {
  1400. /**
  1401. * 注册事件监听器
  1402. * @method addListener
  1403. * @param { String } types 监听的事件名称,同时监听多个事件使用空格分隔
  1404. * @param { Function } fn 监听的事件被触发时,会执行该回调函数
  1405. * @waining 事件被触发时,监听的函数假如返回的值恒等于true,回调函数的队列中后面的函数将不执行
  1406. * @example
  1407. * ```javascript
  1408. * editor.addListener('selectionchange',function(){
  1409. * console.log("选区已经变化!");
  1410. * })
  1411. * editor.addListener('beforegetcontent aftergetcontent',function(type){
  1412. * if(type == 'beforegetcontent'){
  1413. * //do something
  1414. * }else{
  1415. * //do something
  1416. * }
  1417. * console.log(this.getContent) // this是注册的事件的编辑器实例
  1418. * })
  1419. * ```
  1420. * @see UE.EventBase:fireEvent(String)
  1421. */
  1422. addListener:function (types, listener) {
  1423. types = utils.trim(types).split(/\s+/);
  1424. for (var i = 0, ti; ti = types[i++];) {
  1425. getListener(this, ti, true).push(listener);
  1426. }
  1427. },
  1428. on : function(types, listener){
  1429. return this.addListener(types,listener);
  1430. },
  1431. off : function(types, listener){
  1432. return this.removeListener(types, listener)
  1433. },
  1434. trigger:function(){
  1435. return this.fireEvent.apply(this,arguments);
  1436. },
  1437. /**
  1438. * 移除事件监听器
  1439. * @method removeListener
  1440. * @param { String } types 移除的事件名称,同时移除多个事件使用空格分隔
  1441. * @param { Function } fn 移除监听事件的函数引用
  1442. * @example
  1443. * ```javascript
  1444. * //changeCallback为方法体
  1445. * editor.removeListener("selectionchange",changeCallback);
  1446. * ```
  1447. */
  1448. removeListener:function (types, listener) {
  1449. types = utils.trim(types).split(/\s+/);
  1450. for (var i = 0, ti; ti = types[i++];) {
  1451. utils.removeItem(getListener(this, ti) || [], listener);
  1452. }
  1453. },
  1454. /**
  1455. * 触发事件
  1456. * @method fireEvent
  1457. * @param { String } types 触发的事件名称,同时触发多个事件使用空格分隔
  1458. * @remind 该方法会触发addListener
  1459. * @return { * } 返回触发事件的队列中,最后执行的回调函数的返回值
  1460. * @example
  1461. * ```javascript
  1462. * editor.fireEvent("selectionchange");
  1463. * ```
  1464. */
  1465. /**
  1466. * 触发事件
  1467. * @method fireEvent
  1468. * @param { String } types 触发的事件名称,同时触发多个事件使用空格分隔
  1469. * @param { *... } options 可选参数,可以传入一个或多个参数,会传给事件触发的回调函数
  1470. * @return { * } 返回触发事件的队列中,最后执行的回调函数的返回值
  1471. * @example
  1472. * ```javascript
  1473. *
  1474. * editor.addListener( "selectionchange", function ( type, arg1, arg2 ) {
  1475. *
  1476. * console.log( arg1 + " " + arg2 );
  1477. *
  1478. * } );
  1479. *
  1480. * //触发selectionchange事件, 会执行上面的事件监听器
  1481. * //output: Hello World
  1482. * editor.fireEvent("selectionchange", "Hello", "World");
  1483. * ```
  1484. */
  1485. fireEvent:function () {
  1486. var types = arguments[0];
  1487. types = utils.trim(types).split(' ');
  1488. for (var i = 0, ti; ti = types[i++];) {
  1489. var listeners = getListener(this, ti),
  1490. r, t, k;
  1491. if (listeners) {
  1492. k = listeners.length;
  1493. while (k--) {
  1494. if(!listeners[k])continue;
  1495. t = listeners[k].apply(this, arguments);
  1496. if(t === true){
  1497. return t;
  1498. }
  1499. if (t !== undefined) {
  1500. r = t;
  1501. }
  1502. }
  1503. }
  1504. if (t = this['on' + ti.toLowerCase()]) {
  1505. r = t.apply(this, arguments);
  1506. }
  1507. }
  1508. return r;
  1509. }
  1510. };
  1511. /**
  1512. * 获得对象所拥有监听类型的所有监听器
  1513. * @unfile
  1514. * @module UE
  1515. * @since 1.2.6.1
  1516. * @method getListener
  1517. * @public
  1518. * @param { Object } obj 查询监听器的对象
  1519. * @param { String } type 事件类型
  1520. * @param { Boolean } force 为true且当前所有type类型的侦听器不存在时,创建一个空监听器数组
  1521. * @return { Array } 监听器数组
  1522. */
  1523. function getListener(obj, type, force) {
  1524. var allListeners;
  1525. type = type.toLowerCase();
  1526. return ( ( allListeners = ( obj.__allListeners || force && ( obj.__allListeners = {} ) ) )
  1527. && ( allListeners[type] || force && ( allListeners[type] = [] ) ) );
  1528. }
  1529. // js/editor/_src/core/dtd.js
  1530. ///import editor.js
  1531. ///import core/dom/dom.js
  1532. ///import core/utils.js
  1533. /**
  1534. * dtd html语义化的体现类
  1535. * @constructor
  1536. * @namespace dtd
  1537. */
  1538. var dtd = dom.dtd = (function() {
  1539. function _( s ) {
  1540. for (var k in s) {
  1541. s[k.toUpperCase()] = s[k];
  1542. }
  1543. return s;
  1544. }
  1545. var X = utils.extend2;
  1546. var A = _({isindex:1,fieldset:1}),
  1547. B = _({input:1,button:1,select:1,textarea:1,label:1}),
  1548. C = X( _({a:1}), B ),
  1549. D = X( {iframe:1}, C ),
  1550. E = _({hr:1,ul:1,menu:1,div:1,blockquote:1,noscript:1,table:1,center:1,address:1,dir:1,pre:1,h5:1,dl:1,h4:1,noframes:1,h6:1,ol:1,h1:1,h3:1,h2:1}),
  1551. F = _({ins:1,del:1,script:1,style:1}),
  1552. G = X( _({b:1,acronym:1,bdo:1,'var':1,'#':1,abbr:1,code:1,br:1,i:1,cite:1,kbd:1,u:1,strike:1,s:1,tt:1,strong:1,q:1,samp:1,em:1,dfn:1,span:1}), F ),
  1553. H = X( _({sub:1,img:1,embed:1,object:1,sup:1,basefont:1,map:1,applet:1,font:1,big:1,small:1}), G ),
  1554. I = X( _({p:1}), H ),
  1555. J = X( _({iframe:1}), H, B ),
  1556. K = _({img:1,embed:1,noscript:1,br:1,kbd:1,center:1,button:1,basefont:1,h5:1,h4:1,samp:1,h6:1,ol:1,h1:1,h3:1,h2:1,form:1,font:1,'#':1,select:1,menu:1,ins:1,abbr:1,label:1,code:1,table:1,script:1,cite:1,input:1,iframe:1,strong:1,textarea:1,noframes:1,big:1,small:1,span:1,hr:1,sub:1,bdo:1,'var':1,div:1,object:1,sup:1,strike:1,dir:1,map:1,dl:1,applet:1,del:1,isindex:1,fieldset:1,ul:1,b:1,acronym:1,a:1,blockquote:1,i:1,u:1,s:1,tt:1,address:1,q:1,pre:1,p:1,em:1,dfn:1}),
  1557. L = X( _({a:0}), J ),//a不能被切开,所以把他
  1558. M = _({tr:1}),
  1559. N = _({'#':1}),
  1560. O = X( _({param:1}), K ),
  1561. P = X( _({form:1}), A, D, E, I ),
  1562. Q = _({li:1,ol:1,ul:1}),
  1563. R = _({style:1,script:1}),
  1564. S = _({base:1,link:1,meta:1,title:1}),
  1565. T = X( S, R ),
  1566. U = _({head:1,body:1}),
  1567. V = _({html:1});
  1568. var block = _({address:1,blockquote:1,center:1,dir:1,div:1,dl:1,fieldset:1,form:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,hr:1,isindex:1,menu:1,noframes:1,ol:1,p:1,pre:1,table:1,ul:1}),
  1569. empty = _({area:1,base:1,basefont:1,br:1,col:1,command:1,dialog:1,embed:1,hr:1,img:1,input:1,isindex:1,keygen:1,link:1,meta:1,param:1,source:1,track:1,wbr:1});
  1570. return _({
  1571. // $ 表示自定的属性
  1572. // body外的元素列表.
  1573. $nonBodyContent: X( V, U, S ),
  1574. //块结构元素列表
  1575. $block : block,
  1576. //内联元素列表
  1577. $inline : L,
  1578. $inlineWithA : X(_({a:1}),L),
  1579. $body : X( _({script:1,style:1}), block ),
  1580. $cdata : _({script:1,style:1}),
  1581. //自闭和元素
  1582. $empty : empty,
  1583. //不是自闭合,但不能让range选中里边
  1584. $nonChild : _({iframe:1,textarea:1}),
  1585. //列表元素列表
  1586. $listItem : _({dd:1,dt:1,li:1}),
  1587. //列表根元素列表
  1588. $list: _({ul:1,ol:1,dl:1}),
  1589. //不能认为是空的元素
  1590. $isNotEmpty : _({table:1,ul:1,ol:1,dl:1,iframe:1,area:1,base:1,col:1,hr:1,img:1,embed:1,input:1,link:1,meta:1,param:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1}),
  1591. //如果没有子节点就可以删除的元素列表,像span,a
  1592. $removeEmpty : _({a:1,abbr:1,acronym:1,address:1,b:1,bdo:1,big:1,cite:1,code:1,del:1,dfn:1,em:1,font:1,i:1,ins:1,label:1,kbd:1,q:1,s:1,samp:1,small:1,span:1,strike:1,strong:1,sub:1,sup:1,tt:1,u:1,'var':1}),
  1593. $removeEmptyBlock : _({'p':1,'div':1}),
  1594. //在table元素里的元素列表
  1595. $tableContent : _({caption:1,col:1,colgroup:1,tbody:1,td:1,tfoot:1,th:1,thead:1,tr:1,table:1}),
  1596. //不转换的标签
  1597. $notTransContent : _({pre:1,script:1,style:1,textarea:1}),
  1598. html: U,
  1599. head: T,
  1600. style: N,
  1601. script: N,
  1602. body: P,
  1603. base: {},
  1604. link: {},
  1605. meta: {},
  1606. title: N,
  1607. col : {},
  1608. tr : _({td:1,th:1}),
  1609. img : {},
  1610. embed: {},
  1611. colgroup : _({thead:1,col:1,tbody:1,tr:1,tfoot:1}),
  1612. noscript : P,
  1613. td : P,
  1614. br : {},
  1615. th : P,
  1616. center : P,
  1617. kbd : L,
  1618. button : X( I, E ),
  1619. basefont : {},
  1620. h5 : L,
  1621. h4 : L,
  1622. samp : L,
  1623. h6 : L,
  1624. ol : Q,
  1625. h1 : L,
  1626. h3 : L,
  1627. option : N,
  1628. h2 : L,
  1629. form : X( A, D, E, I ),
  1630. select : _({optgroup:1,option:1}),
  1631. font : L,
  1632. ins : L,
  1633. menu : Q,
  1634. abbr : L,
  1635. label : L,
  1636. table : _({thead:1,col:1,tbody:1,tr:1,colgroup:1,caption:1,tfoot:1}),
  1637. code : L,
  1638. tfoot : M,
  1639. cite : L,
  1640. li : P,
  1641. input : {},
  1642. iframe : P,
  1643. strong : L,
  1644. textarea : N,
  1645. noframes : P,
  1646. big : L,
  1647. small : L,
  1648. //trace:
  1649. span :_({'#':1,br:1,b:1,strong:1,u:1,i:1,em:1,sub:1,sup:1,strike:1,span:1}),
  1650. hr : L,
  1651. dt : L,
  1652. sub : L,
  1653. optgroup : _({option:1}),
  1654. param : {},
  1655. bdo : L,
  1656. 'var' : L,
  1657. div : P,
  1658. object : O,
  1659. sup : L,
  1660. dd : P,
  1661. strike : L,
  1662. area : {},
  1663. dir : Q,
  1664. map : X( _({area:1,form:1,p:1}), A, F, E ),
  1665. applet : O,
  1666. dl : _({dt:1,dd:1}),
  1667. del : L,
  1668. isindex : {},
  1669. fieldset : X( _({legend:1}), K ),
  1670. thead : M,
  1671. ul : Q,
  1672. acronym : L,
  1673. b : L,
  1674. a : X( _({a:1}), J ),
  1675. blockquote :X(_({td:1,tr:1,tbody:1,li:1}),P),
  1676. caption : L,
  1677. i : L,
  1678. u : L,
  1679. tbody : M,
  1680. s : L,
  1681. address : X( D, I ),
  1682. tt : L,
  1683. legend : L,
  1684. q : L,
  1685. pre : X( G, C ),
  1686. p : X(_({'a':1}),L),
  1687. em :L,
  1688. dfn : L
  1689. });
  1690. })();
  1691. // js/editor/_src/core/domUtils.js
  1692. /**
  1693. * Dom操作工具包
  1694. * @file
  1695. * @module UE.dom.domUtils
  1696. * @since 1.2.6.1
  1697. */
  1698. /**
  1699. * Dom操作工具包
  1700. * @unfile
  1701. * @module UE.dom.domUtils
  1702. */
  1703. function getDomNode(node, start, ltr, startFromChild, fn, guard) {
  1704. var tmpNode = startFromChild && node[start],
  1705. parent;
  1706. !tmpNode && (tmpNode = node[ltr]);
  1707. while (!tmpNode && (parent = (parent || node).parentNode)) {
  1708. if (parent.tagName == 'BODY' || guard && !guard(parent)) {
  1709. return null;
  1710. }
  1711. tmpNode = parent[ltr];
  1712. }
  1713. if (tmpNode && fn && !fn(tmpNode)) {
  1714. return getDomNode(tmpNode, start, ltr, false, fn);
  1715. }
  1716. return tmpNode;
  1717. }
  1718. var attrFix = ie && browser.version < 9 ? {
  1719. tabindex:"tabIndex",
  1720. readonly:"readOnly",
  1721. "for":"htmlFor",
  1722. "class":"className",
  1723. maxlength:"maxLength",
  1724. cellspacing:"cellSpacing",
  1725. cellpadding:"cellPadding",
  1726. rowspan:"rowSpan",
  1727. colspan:"colSpan",
  1728. usemap:"useMap",
  1729. frameborder:"frameBorder"
  1730. } : {
  1731. tabindex:"tabIndex",
  1732. readonly:"readOnly"
  1733. },
  1734. styleBlock = utils.listToMap([
  1735. '-webkit-box', '-moz-box', 'block' ,
  1736. 'list-item' , 'table' , 'table-row-group' ,
  1737. 'table-header-group', 'table-footer-group' ,
  1738. 'table-row' , 'table-column-group' , 'table-column' ,
  1739. 'table-cell' , 'table-caption'
  1740. ]);
  1741. var domUtils = dom.domUtils = {
  1742. //节点常量
  1743. NODE_ELEMENT:1,
  1744. NODE_DOCUMENT:9,
  1745. NODE_TEXT:3,
  1746. NODE_COMMENT:8,
  1747. NODE_DOCUMENT_FRAGMENT:11,
  1748. //位置关系
  1749. POSITION_IDENTICAL:0,
  1750. POSITION_DISCONNECTED:1,
  1751. POSITION_FOLLOWING:2,
  1752. POSITION_PRECEDING:4,
  1753. POSITION_IS_CONTAINED:8,
  1754. POSITION_CONTAINS:16,
  1755. //ie6使用其他的会有一段空白出现
  1756. fillChar:ie && browser.version == '6' ? '\ufeff' : '\u200B',
  1757. //-------------------------Node部分--------------------------------
  1758. keys:{
  1759. /*Backspace*/ 8:1, /*Delete*/ 46:1,
  1760. /*Shift*/ 16:1, /*Ctrl*/ 17:1, /*Alt*/ 18:1,
  1761. 37:1, 38:1, 39:1, 40:1,
  1762. 13:1 /*enter*/
  1763. },
  1764. /**
  1765. * 获取节点A相对于节点B的位置关系
  1766. * @method getPosition
  1767. * @param { Node } nodeA 需要查询位置关系的节点A
  1768. * @param { Node } nodeB 需要查询位置关系的节点B
  1769. * @return { Number } 节点A与节点B的关系
  1770. * @example
  1771. * ```javascript
  1772. * //output: 20
  1773. * var position = UE.dom.domUtils.getPosition( document.documentElement, document.body );
  1774. *
  1775. * switch ( position ) {
  1776. *
  1777. * //0
  1778. * case UE.dom.domUtils.POSITION_IDENTICAL:
  1779. * console.log('元素相同');
  1780. * break;
  1781. * //1
  1782. * case UE.dom.domUtils.POSITION_DISCONNECTED:
  1783. * console.log('两个节点在不同的文档中');
  1784. * break;
  1785. * //2
  1786. * case UE.dom.domUtils.POSITION_FOLLOWING:
  1787. * console.log('节点A在节点B之后');
  1788. * break;
  1789. * //4
  1790. * case UE.dom.domUtils.POSITION_PRECEDING;
  1791. * console.log('节点A在节点B之前');
  1792. * break;
  1793. * //8
  1794. * case UE.dom.domUtils.POSITION_IS_CONTAINED:
  1795. * console.log('节点A被节点B包含');
  1796. * break;
  1797. * case 10:
  1798. * console.log('节点A被节点B包含且节点A在节点B之后');
  1799. * break;
  1800. * //16
  1801. * case UE.dom.domUtils.POSITION_CONTAINS:
  1802. * console.log('节点A包含节点B');
  1803. * break;
  1804. * case 20:
  1805. * console.log('节点A包含节点B且节点A在节点B之前');
  1806. * break;
  1807. *
  1808. * }
  1809. * ```
  1810. */
  1811. getPosition:function (nodeA, nodeB) {
  1812. // 如果两个节点是同一个节点
  1813. if (nodeA === nodeB) {
  1814. // domUtils.POSITION_IDENTICAL
  1815. return 0;
  1816. }
  1817. var node,
  1818. parentsA = [nodeA],
  1819. parentsB = [nodeB];
  1820. node = nodeA;
  1821. while (node = node.parentNode) {
  1822. // 如果nodeB是nodeA的祖先节点
  1823. if (node === nodeB) {
  1824. // domUtils.POSITION_IS_CONTAINED + domUtils.POSITION_FOLLOWING
  1825. return 10;
  1826. }
  1827. parentsA.push(node);
  1828. }
  1829. node = nodeB;
  1830. while (node = node.parentNode) {
  1831. // 如果nodeA是nodeB的祖先节点
  1832. if (node === nodeA) {
  1833. // domUtils.POSITION_CONTAINS + domUtils.POSITION_PRECEDING
  1834. return 20;
  1835. }
  1836. parentsB.push(node);
  1837. }
  1838. parentsA.reverse();
  1839. parentsB.reverse();
  1840. if (parentsA[0] !== parentsB[0]) {
  1841. // domUtils.POSITION_DISCONNECTED
  1842. return 1;
  1843. }
  1844. var i = -1;
  1845. while (i++, parentsA[i] === parentsB[i]) {
  1846. }
  1847. nodeA = parentsA[i];
  1848. nodeB = parentsB[i];
  1849. while (nodeA = nodeA.nextSibling) {
  1850. if (nodeA === nodeB) {
  1851. // domUtils.POSITION_PRECEDING
  1852. return 4
  1853. }
  1854. }
  1855. // domUtils.POSITION_FOLLOWING
  1856. return 2;
  1857. },
  1858. /**
  1859. * 检测节点node在父节点中的索引位置
  1860. * @method getNodeIndex
  1861. * @param { Node } node 需要检测的节点对象
  1862. * @return { Number } 该节点在父节点中的位置
  1863. * @see UE.dom.domUtils.getNodeIndex(Node,Boolean)
  1864. */
  1865. /**
  1866. * 检测节点node在父节点中的索引位置, 根据给定的mergeTextNode参数决定是否要合并多个连续的文本节点为一个节点
  1867. * @method getNodeIndex
  1868. * @param { Node } node 需要检测的节点对象
  1869. * @param { Boolean } mergeTextNode 是否合并多个连续的文本节点为一个节点
  1870. * @return { Number } 该节点在父节点中的位置
  1871. * @example
  1872. * ```javascript
  1873. *
  1874. * var node = document.createElement("div");
  1875. *
  1876. * node.appendChild( document.createTextNode( "hello" ) );
  1877. * node.appendChild( document.createTextNode( "world" ) );
  1878. * node.appendChild( node = document.createElement( "div" ) );
  1879. *
  1880. * //output: 2
  1881. * console.log( UE.dom.domUtils.getNodeIndex( node ) );
  1882. *
  1883. * //output: 1
  1884. * console.log( UE.dom.domUtils.getNodeIndex( node, true ) );
  1885. *
  1886. * ```
  1887. */
  1888. getNodeIndex:function (node, ignoreTextNode) {
  1889. var preNode = node,
  1890. i = 0;
  1891. while (preNode = preNode.previousSibling) {
  1892. if (ignoreTextNode && preNode.nodeType == 3) {
  1893. if(preNode.nodeType != preNode.nextSibling.nodeType ){
  1894. i++;
  1895. }
  1896. continue;
  1897. }
  1898. i++;
  1899. }
  1900. return i;
  1901. },
  1902. /**
  1903. * 检测节点node是否在给定的document对象上
  1904. * @method inDoc
  1905. * @param { Node } node 需要检测的节点对象
  1906. * @param { DomDocument } doc 需要检测的document对象
  1907. * @return { Boolean } 该节点node是否在给定的document的dom树上
  1908. * @example
  1909. * ```javascript
  1910. *
  1911. * var node = document.createElement("div");
  1912. *
  1913. * //output: false
  1914. * console.log( UE.do.domUtils.inDoc( node, document ) );
  1915. *
  1916. * document.body.appendChild( node );
  1917. *
  1918. * //output: true
  1919. * console.log( UE.do.domUtils.inDoc( node, document ) );
  1920. *
  1921. * ```
  1922. */
  1923. inDoc:function (node, doc) {
  1924. return domUtils.getPosition(node, doc) == 10;
  1925. },
  1926. /**
  1927. * 根据给定的过滤规则filterFn, 查找符合该过滤规则的node节点的第一个祖先节点,
  1928. * 查找的起点是给定node节点的父节点。
  1929. * @method findParent
  1930. * @param { Node } node 需要查找的节点
  1931. * @param { Function } filterFn 自定义的过滤方法。
  1932. * @warning 查找的终点是到body节点为止
  1933. * @remind 自定义的过滤方法filterFn接受一个Node对象作为参数, 该对象代表当前执行检测的祖先节点。 如果该
  1934. * 节点满足过滤条件, 则要求返回true, 这时将直接返回该节点作为findParent()的结果, 否则, 请返回false。
  1935. * @return { Node | Null } 如果找到符合过滤条件的节点, 就返回该节点, 否则返回NULL
  1936. * @example
  1937. * ```javascript
  1938. * var filterNode = UE.dom.domUtils.findParent( document.body.firstChild, function ( node ) {
  1939. *
  1940. * //由于查找的终点是body节点, 所以永远也不会匹配当前过滤器的条件, 即这里永远会返回false
  1941. * return node.tagName === "HTML";
  1942. *
  1943. * } );
  1944. *
  1945. * //output: true
  1946. * console.log( filterNode === null );
  1947. * ```
  1948. */
  1949. /**
  1950. * 根据给定的过滤规则filterFn, 查找符合该过滤规则的node节点的第一个祖先节点,
  1951. * 如果includeSelf的值为true,则查找的起点是给定的节点node, 否则, 起点是node的父节点
  1952. * @method findParent
  1953. * @param { Node } node 需要查找的节点
  1954. * @param { Function } filterFn 自定义的过滤方法。
  1955. * @param { Boolean } includeSelf 查找过程是否包含自身
  1956. * @warning 查找的终点是到body节点为止
  1957. * @remind 自定义的过滤方法filterFn接受一个Node对象作为参数, 该对象代表当前执行检测的祖先节点。 如果该
  1958. * 节点满足过滤条件, 则要求返回true, 这时将直接返回该节点作为findParent()的结果, 否则, 请返回false。
  1959. * @remind 如果includeSelf为true, 则过滤器第一次执行时的参数会是节点本身。
  1960. * 反之, 过滤器第一次执行时的参数将是该节点的父节点。
  1961. * @return { Node | Null } 如果找到符合过滤条件的节点, 就返回该节点, 否则返回NULL
  1962. * @example
  1963. * ```html
  1964. * <body>
  1965. *
  1966. * <div id="test">
  1967. * </div>
  1968. *
  1969. * <script type="text/javascript">
  1970. *
  1971. * //output: DIV, BODY
  1972. * var filterNode = UE.dom.domUtils.findParent( document.getElementById( "test" ), function ( node ) {
  1973. *
  1974. * console.log( node.tagName );
  1975. * return false;
  1976. *
  1977. * }, true );
  1978. *
  1979. * </script>
  1980. * </body>
  1981. * ```
  1982. */
  1983. findParent:function (node, filterFn, includeSelf) {
  1984. if (node && !domUtils.isBody(node)) {
  1985. node = includeSelf ? node : node.parentNode;
  1986. while (node) {
  1987. if (!filterFn || filterFn(node) || domUtils.isBody(node)) {
  1988. return filterFn && !filterFn(node) && domUtils.isBody(node) ? null : node;
  1989. }
  1990. node = node.parentNode;
  1991. }
  1992. }
  1993. return null;
  1994. },
  1995. /**
  1996. * 查找node的节点名为tagName的第一个祖先节点, 查找的起点是node节点的父节点。
  1997. * @method findParentByTagName
  1998. * @param { Node } node 需要查找的节点对象
  1999. * @param { Array } tagNames 需要查找的父节点的名称数组
  2000. * @warning 查找的终点是到body节点为止
  2001. * @return { Node | NULL } 如果找到符合条件的节点, 则返回该节点, 否则返回NULL
  2002. * @example
  2003. * ```javascript
  2004. * var node = UE.dom.domUtils.findParentByTagName( document.getElementsByTagName("div")[0], [ "BODY" ] );
  2005. * //output: BODY
  2006. * console.log( node.tagName );
  2007. * ```
  2008. */
  2009. /**
  2010. * 查找node的节点名为tagName的祖先节点, 如果includeSelf的值为true,则查找的起点是给定的节点node,
  2011. * 否则, 起点是node的父节点。
  2012. * @method findParentByTagName
  2013. * @param { Node } node 需要查找的节点对象
  2014. * @param { Array } tagNames 需要查找的父节点的名称数组
  2015. * @param { Boolean } includeSelf 查找过程是否包含node节点自身
  2016. * @warning 查找的终点是到body节点为止
  2017. * @return { Node | NULL } 如果找到符合条件的节点, 则返回该节点, 否则返回NULL
  2018. * @example
  2019. * ```javascript
  2020. * var queryTarget = document.getElementsByTagName("div")[0];
  2021. * var node = UE.dom.domUtils.findParentByTagName( queryTarget, [ "DIV" ], true );
  2022. * //output: true
  2023. * console.log( queryTarget === node );
  2024. * ```
  2025. */
  2026. findParentByTagName:function (node, tagNames, includeSelf, excludeFn) {
  2027. tagNames = utils.listToMap(utils.isArray(tagNames) ? tagNames : [tagNames]);
  2028. return domUtils.findParent(node, function (node) {
  2029. return tagNames[node.tagName] && !(excludeFn && excludeFn(node));
  2030. }, includeSelf);
  2031. },
  2032. /**
  2033. * 查找节点node的祖先节点集合, 查找的起点是给定节点的父节点,结果集中不包含给定的节点。
  2034. * @method findParents
  2035. * @param { Node } node 需要查找的节点对象
  2036. * @return { Array } 给定节点的祖先节点数组
  2037. * @grammar UE.dom.domUtils.findParents(node) => Array //返回一个祖先节点数组集合,不包含自身
  2038. * @grammar UE.dom.domUtils.findParents(node,includeSelf) => Array //返回一个祖先节点数组集合,includeSelf指定是否包含自身
  2039. * @grammar UE.dom.domUtils.findParents(node,includeSelf,filterFn) => Array //返回一个祖先节点数组集合,filterFn指定过滤条件,返回true的node将被选取
  2040. * @grammar UE.dom.domUtils.findParents(node,includeSelf,filterFn,closerFirst) => Array //返回一个祖先节点数组集合,closerFirst为true的话,node的直接父亲节点是数组的第0个
  2041. */
  2042. /**
  2043. * 查找节点node的祖先节点集合, 如果includeSelf的值为true,
  2044. * 则返回的结果集中允许出现当前给定的节点, 否则, 该节点不会出现在其结果集中。
  2045. * @method findParents
  2046. * @param { Node } node 需要查找的节点对象
  2047. * @param { Boolean } includeSelf 查找的结果中是否允许包含当前查找的节点对象
  2048. * @return { Array } 给定节点的祖先节点数组
  2049. */
  2050. findParents:function (node, includeSelf, filterFn, closerFirst) {
  2051. var parents = includeSelf && ( filterFn && filterFn(node) || !filterFn ) ? [node] : [];
  2052. while (node = domUtils.findParent(node, filterFn)) {
  2053. parents.push(node);
  2054. }
  2055. return closerFirst ? parents : parents.reverse();
  2056. },
  2057. /**
  2058. * 在节点node后面插入新节点newNode
  2059. * @method insertAfter
  2060. * @param { Node } node 目标节点
  2061. * @param { Node } newNode 新插入的节点, 该节点将置于目标节点之后
  2062. * @return { Node } 新插入的节点
  2063. */
  2064. insertAfter:function (node, newNode) {
  2065. return node.nextSibling ? node.parentNode.insertBefore(newNode, node.nextSibling):
  2066. node.parentNode.appendChild(newNode);
  2067. },
  2068. /**
  2069. * 删除节点node及其下属的所有节点
  2070. * @method remove
  2071. * @param { Node } node 需要删除的节点对象
  2072. * @return { Node } 返回刚删除的节点对象
  2073. * @example
  2074. * ```html
  2075. * <div id="test">
  2076. * <div id="child">你好</div>
  2077. * </div>
  2078. * <script>
  2079. * UE.dom.domUtils.remove( document.body, false );
  2080. * //output: false
  2081. * console.log( document.getElementById( "child" ) !== null );
  2082. * </script>
  2083. * ```
  2084. */
  2085. /**
  2086. * 删除节点node,并根据keepChildren的值决定是否保留子节点
  2087. * @method remove
  2088. * @param { Node } node 需要删除的节点对象
  2089. * @param { Boolean } keepChildren 是否需要保留子节点
  2090. * @return { Node } 返回刚删除的节点对象
  2091. * @example
  2092. * ```html
  2093. * <div id="test">
  2094. * <div id="child">你好</div>
  2095. * </div>
  2096. * <script>
  2097. * UE.dom.domUtils.remove( document.body, true );
  2098. * //output: true
  2099. * console.log( document.getElementById( "child" ) !== null );
  2100. * </script>
  2101. * ```
  2102. */
  2103. remove:function (node, keepChildren) {
  2104. var parent = node.parentNode,
  2105. child;
  2106. if (parent) {
  2107. if (keepChildren && node.hasChildNodes()) {
  2108. while (child = node.firstChild) {
  2109. parent.insertBefore(child, node);
  2110. }
  2111. }
  2112. parent.removeChild(node);
  2113. }
  2114. return node;
  2115. },
  2116. /**
  2117. * 取得node节点的下一个兄弟节点, 如果该节点其后没有兄弟节点, 则递归查找其父节点之后的第一个兄弟节点,
  2118. * 直到找到满足条件的节点或者递归到BODY节点之后才会结束。
  2119. * @method getNextDomNode
  2120. * @param { Node } node 需要获取其后的兄弟节点的节点对象
  2121. * @return { Node | NULL } 如果找满足条件的节点, 则返回该节点, 否则返回NULL
  2122. * @example
  2123. * ```html
  2124. * <body>
  2125. * <div id="test">
  2126. * <span></span>
  2127. * </div>
  2128. * <i>xxx</i>
  2129. * </body>
  2130. * <script>
  2131. *
  2132. * //output: i节点
  2133. * console.log( UE.dom.domUtils.getNextDomNode( document.getElementById( "test" ) ) );
  2134. *
  2135. * </script>
  2136. * ```
  2137. * @example
  2138. * ```html
  2139. * <body>
  2140. * <div>
  2141. * <span></span>
  2142. * <i id="test">xxx</i>
  2143. * </div>
  2144. * <b>xxx</b>
  2145. * </body>
  2146. * <script>
  2147. *
  2148. * //由于id为test的i节点之后没有兄弟节点, 则查找其父节点(div)后面的兄弟节点
  2149. * //output: b节点
  2150. * console.log( UE.dom.domUtils.getNextDomNode( document.getElementById( "test" ) ) );
  2151. *
  2152. * </script>
  2153. * ```
  2154. */
  2155. /**
  2156. * 取得node节点的下一个兄弟节点, 如果startFromChild的值为ture,则先获取其子节点,
  2157. * 如果有子节点则直接返回第一个子节点;如果没有子节点或者startFromChild的值为false,
  2158. * 则执行<a href="#UE.dom.domUtils.getNextDomNode(Node)">getNextDomNode(Node node)</a>的查找过程。
  2159. * @method getNextDomNode
  2160. * @param { Node } node 需要获取其后的兄弟节点的节点对象
  2161. * @param { Boolean } startFromChild 查找过程是否从其子节点开始
  2162. * @return { Node | NULL } 如果找满足条件的节点, 则返回该节点, 否则返回NULL
  2163. * @see UE.dom.domUtils.getNextDomNode(Node)
  2164. */
  2165. getNextDomNode:function (node, startFromChild, filterFn, guard) {
  2166. return getDomNode(node, 'firstChild', 'nextSibling', startFromChild, filterFn, guard);
  2167. },
  2168. getPreDomNode:function (node, startFromChild, filterFn, guard) {
  2169. return getDomNode(node, 'lastChild', 'previousSibling', startFromChild, filterFn, guard);
  2170. },
  2171. /**
  2172. * 检测节点node是否属是UEditor定义的bookmark节点
  2173. * @method isBookmarkNode
  2174. * @private
  2175. * @param { Node } node 需要检测的节点对象
  2176. * @return { Boolean } 是否是bookmark节点
  2177. * @example
  2178. * ```html
  2179. * <span id="_baidu_bookmark_1"></span>
  2180. * <script>
  2181. * var bookmarkNode = document.getElementById("_baidu_bookmark_1");
  2182. * //output: true
  2183. * console.log( UE.dom.domUtils.isBookmarkNode( bookmarkNode ) );
  2184. * </script>
  2185. * ```
  2186. */
  2187. isBookmarkNode:function (node) {
  2188. return node.nodeType == 1 && node.id && /^_baidu_bookmark_/i.test(node.id);
  2189. },
  2190. /**
  2191. * 获取节点node所属的window对象
  2192. * @method getWindow
  2193. * @param { Node } node 节点对象
  2194. * @return { Window } 当前节点所属的window对象
  2195. * @example
  2196. * ```javascript
  2197. * //output: true
  2198. * console.log( UE.dom.domUtils.getWindow( document.body ) === window );
  2199. * ```
  2200. */
  2201. getWindow:function (node) {
  2202. var doc = node.ownerDocument || node;
  2203. return doc.defaultView || doc.parentWindow;
  2204. },
  2205. /**
  2206. * 获取离nodeA与nodeB最近的公共的祖先节点
  2207. * @method getCommonAncestor
  2208. * @param { Node } nodeA 第一个节点
  2209. * @param { Node } nodeB 第二个节点
  2210. * @remind 如果给定的两个节点是同一个节点, 将直接返回该节点。
  2211. * @return { Node | NULL } 如果未找到公共节点, 返回NULL, 否则返回最近的公共祖先节点。
  2212. * @example
  2213. * ```javascript
  2214. * var commonAncestor = UE.dom.domUtils.getCommonAncestor( document.body, document.body.firstChild );
  2215. * //output: true
  2216. * console.log( commonAncestor.tagName.toLowerCase() === 'body' );
  2217. * ```
  2218. */
  2219. getCommonAncestor:function (nodeA, nodeB) {
  2220. if (nodeA === nodeB)
  2221. return nodeA;
  2222. var parentsA = [nodeA] , parentsB = [nodeB], parent = nodeA, i = -1;
  2223. while (parent = parent.parentNode) {
  2224. if (parent === nodeB) {
  2225. return parent;
  2226. }
  2227. parentsA.push(parent);
  2228. }
  2229. parent = nodeB;
  2230. while (parent = parent.parentNode) {
  2231. if (parent === nodeA)
  2232. return parent;
  2233. parentsB.push(parent);
  2234. }
  2235. parentsA.reverse();
  2236. parentsB.reverse();
  2237. while (i++, parentsA[i] === parentsB[i]) {
  2238. }
  2239. return i == 0 ? null : parentsA[i - 1];
  2240. },
  2241. /**
  2242. * 清除node节点左右连续为空的兄弟inline节点
  2243. * @method clearEmptySibling
  2244. * @param { Node } node 执行的节点对象, 如果该节点的左右连续的兄弟节点是空的inline节点,
  2245. * 则这些兄弟节点将被删除
  2246. * @grammar UE.dom.domUtils.clearEmptySibling(node,ignoreNext) //ignoreNext指定是否忽略右边空节点
  2247. * @grammar UE.dom.domUtils.clearEmptySibling(node,ignoreNext,ignorePre) //ignorePre指定是否忽略左边空节点
  2248. * @example
  2249. * ```html
  2250. * <body>
  2251. * <div></div>
  2252. * <span id="test"></span>
  2253. * <i></i>
  2254. * <b></b>
  2255. * <em>xxx</em>
  2256. * <span></span>
  2257. * </body>
  2258. * <script>
  2259. *
  2260. * UE.dom.domUtils.clearEmptySibling( document.getElementById( "test" ) );
  2261. *
  2262. * //output: <div></div><span id="test"></span><em>xxx</em><span></span>
  2263. * console.log( document.body.innerHTML );
  2264. *
  2265. * </script>
  2266. * ```
  2267. */
  2268. /**
  2269. * 清除node节点左右连续为空的兄弟inline节点, 如果ignoreNext的值为true,
  2270. * 则忽略对右边兄弟节点的操作。
  2271. * @method clearEmptySibling
  2272. * @param { Node } node 执行的节点对象, 如果该节点的左右连续的兄弟节点是空的inline节点,
  2273. * @param { Boolean } ignoreNext 是否忽略忽略对右边的兄弟节点的操作
  2274. * 则这些兄弟节点将被删除
  2275. * @see UE.dom.domUtils.clearEmptySibling(Node)
  2276. */
  2277. /**
  2278. * 清除node节点左右连续为空的兄弟inline节点, 如果ignoreNext的值为true,
  2279. * 则忽略对右边兄弟节点的操作, 如果ignorePre的值为true,则忽略对左边兄弟节点的操作。
  2280. * @method clearEmptySibling
  2281. * @param { Node } node 执行的节点对象, 如果该节点的左右连续的兄弟节点是空的inline节点,
  2282. * @param { Boolean } ignoreNext 是否忽略忽略对右边的兄弟节点的操作
  2283. * @param { Boolean } ignorePre 是否忽略忽略对左边的兄弟节点的操作
  2284. * 则这些兄弟节点将被删除
  2285. * @see UE.dom.domUtils.clearEmptySibling(Node)
  2286. */
  2287. clearEmptySibling:function (node, ignoreNext, ignorePre) {
  2288. function clear(next, dir) {
  2289. var tmpNode;
  2290. while (next && !domUtils.isBookmarkNode(next) && (domUtils.isEmptyInlineElement(next)
  2291. //这里不能把空格算进来会吧空格干掉,出现文字间的空格丢掉了
  2292. || !new RegExp('[^\t\n\r' + domUtils.fillChar + ']').test(next.nodeValue) )) {
  2293. tmpNode = next[dir];
  2294. domUtils.remove(next);
  2295. next = tmpNode;
  2296. }
  2297. }
  2298. !ignoreNext && clear(node.nextSibling, 'nextSibling');
  2299. !ignorePre && clear(node.previousSibling, 'previousSibling');
  2300. },
  2301. /**
  2302. * 将一个文本节点textNode拆分成两个文本节点,offset指定拆分位置
  2303. * @method split
  2304. * @param { Node } textNode 需要拆分的文本节点对象
  2305. * @param { int } offset 需要拆分的位置, 位置计算从0开始
  2306. * @return { Node } 拆分后形成的新节点
  2307. * @example
  2308. * ```html
  2309. * <div id="test">abcdef</div>
  2310. * <script>
  2311. * var newNode = UE.dom.domUtils.split( document.getElementById( "test" ).firstChild, 3 );
  2312. * //output: def
  2313. * console.log( newNode.nodeValue );
  2314. * </script>
  2315. * ```
  2316. */
  2317. split:function (node, offset) {
  2318. var doc = node.ownerDocument;
  2319. if (browser.ie && offset == node.nodeValue.length) {
  2320. var next = doc.createTextNode('');
  2321. return domUtils.insertAfter(node, next);
  2322. }
  2323. var retval = node.splitText(offset);
  2324. //ie8下splitText不会跟新childNodes,我们手动触发他的更新
  2325. if (browser.ie8) {
  2326. var tmpNode = doc.createTextNode('');
  2327. domUtils.insertAfter(retval, tmpNode);
  2328. domUtils.remove(tmpNode);
  2329. }
  2330. return retval;
  2331. },
  2332. /**
  2333. * 检测文本节点textNode是否为空节点(包括空格、换行、占位符等字符)
  2334. * @method isWhitespace
  2335. * @param { Node } node 需要检测的节点对象
  2336. * @return { Boolean } 检测的节点是否为空
  2337. * @example
  2338. * ```html
  2339. * <div id="test">
  2340. *
  2341. * </div>
  2342. * <script>
  2343. * //output: true
  2344. * console.log( UE.dom.domUtils.isWhitespace( document.getElementById("test").firstChild ) );
  2345. * </script>
  2346. * ```
  2347. */
  2348. isWhitespace:function (node) {
  2349. return !new RegExp('[^ \t\n\r' + domUtils.fillChar + ']').test(node.nodeValue);
  2350. },
  2351. /**
  2352. * 获取元素element相对于viewport的位置坐标
  2353. * @method getXY
  2354. * @param { Node } element 需要计算位置的节点对象
  2355. * @return { Object } 返回形如{x:left,y:top}的一个key-value映射对象, 其中键x代表水平偏移距离,
  2356. * y代表垂直偏移距离。
  2357. *
  2358. * @example
  2359. * ```javascript
  2360. * var location = UE.dom.domUtils.getXY( document.getElementById("test") );
  2361. * //output: test的坐标为: 12, 24
  2362. * console.log( 'test的坐标为: ', location.x, ',', location.y );
  2363. * ```
  2364. */
  2365. getXY:function (element) {
  2366. var x = 0, y = 0;
  2367. while (element.offsetParent) {
  2368. y += element.offsetTop;
  2369. x += element.offsetLeft;
  2370. element = element.offsetParent;
  2371. }
  2372. return { 'x':x, 'y':y};
  2373. },
  2374. /**
  2375. * 为元素element绑定原生DOM事件,type为事件类型,handler为处理函数
  2376. * @method on
  2377. * @param { Node } element 需要绑定事件的节点对象
  2378. * @param { String } type 绑定的事件类型
  2379. * @param { Function } handler 事件处理器
  2380. * @example
  2381. * ```javascript
  2382. * UE.dom.domUtils.on(document.body,"click",function(e){
  2383. * //e为事件对象,this为被点击元素对戏那个
  2384. * });
  2385. * ```
  2386. */
  2387. /**
  2388. * 为元素element绑定原生DOM事件,type为事件类型,handler为处理函数
  2389. * @method on
  2390. * @param { Node } element 需要绑定事件的节点对象
  2391. * @param { Array } type 绑定的事件类型数组
  2392. * @param { Function } handler 事件处理器
  2393. * @example
  2394. * ```javascript
  2395. * UE.dom.domUtils.on(document.body,["click","mousedown"],function(evt){
  2396. * //evt为事件对象,this为被点击元素对象
  2397. * });
  2398. * ```
  2399. */
  2400. on:function (element, type, handler) {
  2401. var types = utils.isArray(type) ? type : utils.trim(type).split(/\s+/),
  2402. k = types.length;
  2403. if (k) while (k--) {
  2404. type = types[k];
  2405. if (element.addEventListener) {
  2406. element.addEventListener(type, handler, false);
  2407. } else {
  2408. if (!handler._d) {
  2409. handler._d = {
  2410. els : []
  2411. };
  2412. }
  2413. var key = type + handler.toString(),index = utils.indexOf(handler._d.els,element);
  2414. if (!handler._d[key] || index == -1) {
  2415. if(index == -1){
  2416. handler._d.els.push(element);
  2417. }
  2418. if(!handler._d[key]){
  2419. handler._d[key] = function (evt) {
  2420. return handler.call(evt.srcElement, evt || window.event);
  2421. };
  2422. }
  2423. element.attachEvent('on' + type, handler._d[key]);
  2424. }
  2425. }
  2426. }
  2427. element = null;
  2428. },
  2429. /**
  2430. * 解除DOM事件绑定
  2431. * @method un
  2432. * @param { Node } element 需要解除事件绑定的节点对象
  2433. * @param { String } type 需要接触绑定的事件类型
  2434. * @param { Function } handler 对应的事件处理器
  2435. * @example
  2436. * ```javascript
  2437. * UE.dom.domUtils.un(document.body,"click",function(evt){
  2438. * //evt为事件对象,this为被点击元素对象
  2439. * });
  2440. * ```
  2441. */
  2442. /**
  2443. * 解除DOM事件绑定
  2444. * @method un
  2445. * @param { Node } element 需要解除事件绑定的节点对象
  2446. * @param { Array } type 需要接触绑定的事件类型数组
  2447. * @param { Function } handler 对应的事件处理器
  2448. * @example
  2449. * ```javascript
  2450. * UE.dom.domUtils.un(document.body, ["click","mousedown"],function(evt){
  2451. * //evt为事件对象,this为被点击元素对象
  2452. * });
  2453. * ```
  2454. */
  2455. un:function (element, type, handler) {
  2456. var types = utils.isArray(type) ? type : utils.trim(type).split(/\s+/),
  2457. k = types.length;
  2458. if (k) while (k--) {
  2459. type = types[k];
  2460. if (element.removeEventListener) {
  2461. element.removeEventListener(type, handler, false);
  2462. } else {
  2463. var key = type + handler.toString();
  2464. try{
  2465. element.detachEvent('on' + type, handler._d ? handler._d[key] : handler);
  2466. }catch(e){}
  2467. if (handler._d && handler._d[key]) {
  2468. var index = utils.indexOf(handler._d.els,element);
  2469. if(index!=-1){
  2470. handler._d.els.splice(index,1);
  2471. }
  2472. handler._d.els.length == 0 && delete handler._d[key];
  2473. }
  2474. }
  2475. }
  2476. },
  2477. /**
  2478. * 比较节点nodeA与节点nodeB是否具有相同的标签名、属性名以及属性值
  2479. * @method isSameElement
  2480. * @param { Node } nodeA 需要比较的节点
  2481. * @param { Node } nodeB 需要比较的节点
  2482. * @return { Boolean } 两个节点是否具有相同的标签名、属性名以及属性值
  2483. * @example
  2484. * ```html
  2485. * <span style="font-size:12px">ssss</span>
  2486. * <span style="font-size:12px">bbbbb</span>
  2487. * <span style="font-size:13px">ssss</span>
  2488. * <span style="font-size:14px">bbbbb</span>
  2489. *
  2490. * <script>
  2491. *
  2492. * var nodes = document.getElementsByTagName( "span" );
  2493. *
  2494. * //output: true
  2495. * console.log( UE.dom.domUtils.isSameElement( nodes[0], nodes[1] ) );
  2496. *
  2497. * //output: false
  2498. * console.log( UE.dom.domUtils.isSameElement( nodes[2], nodes[3] ) );
  2499. *
  2500. * </script>
  2501. * ```
  2502. */
  2503. isSameElement:function (nodeA, nodeB) {
  2504. if (nodeA.tagName != nodeB.tagName) {
  2505. return false;
  2506. }
  2507. var thisAttrs = nodeA.attributes,
  2508. otherAttrs = nodeB.attributes;
  2509. if (!ie && thisAttrs.length != otherAttrs.length) {
  2510. return false;
  2511. }
  2512. var attrA, attrB, al = 0, bl = 0;
  2513. for (var i = 0; attrA = thisAttrs[i++];) {
  2514. if (attrA.nodeName == 'style') {
  2515. if (attrA.specified) {
  2516. al++;
  2517. }
  2518. if (domUtils.isSameStyle(nodeA, nodeB)) {
  2519. continue;
  2520. } else {
  2521. return false;
  2522. }
  2523. }
  2524. if (ie) {
  2525. if (attrA.specified) {
  2526. al++;
  2527. attrB = otherAttrs.getNamedItem(attrA.nodeName);
  2528. } else {
  2529. continue;
  2530. }
  2531. } else {
  2532. attrB = nodeB.attributes[attrA.nodeName];
  2533. }
  2534. if (!attrB.specified || attrA.nodeValue != attrB.nodeValue) {
  2535. return false;
  2536. }
  2537. }
  2538. // 有可能attrB的属性包含了attrA的属性之外还有自己的属性
  2539. if (ie) {
  2540. for (i = 0; attrB = otherAttrs[i++];) {
  2541. if (attrB.specified) {
  2542. bl++;
  2543. }
  2544. }
  2545. if (al != bl) {
  2546. return false;
  2547. }
  2548. }
  2549. return true;
  2550. },
  2551. /**
  2552. * 判断节点nodeA与节点nodeB的元素的style属性是否一致
  2553. * @method isSameStyle
  2554. * @param { Node } nodeA 需要比较的节点
  2555. * @param { Node } nodeB 需要比较的节点
  2556. * @return { Boolean } 两个节点是否具有相同的style属性值
  2557. * @example
  2558. * ```html
  2559. * <span style="font-size:12px">ssss</span>
  2560. * <span style="font-size:12px">bbbbb</span>
  2561. * <span style="font-size:13px">ssss</span>
  2562. * <span style="font-size:14px">bbbbb</span>
  2563. *
  2564. * <script>
  2565. *
  2566. * var nodes = document.getElementsByTagName( "span" );
  2567. *
  2568. * //output: true
  2569. * console.log( UE.dom.domUtils.isSameStyle( nodes[0], nodes[1] ) );
  2570. *
  2571. * //output: false
  2572. * console.log( UE.dom.domUtils.isSameStyle( nodes[2], nodes[3] ) );
  2573. *
  2574. * </script>
  2575. * ```
  2576. */
  2577. isSameStyle:function (nodeA, nodeB) {
  2578. var styleA = nodeA.style.cssText.replace(/( ?; ?)/g, ';').replace(/( ?: ?)/g, ':'),
  2579. styleB = nodeB.style.cssText.replace(/( ?; ?)/g, ';').replace(/( ?: ?)/g, ':');
  2580. if (browser.opera) {
  2581. styleA = nodeA.style;
  2582. styleB = nodeB.style;
  2583. if (styleA.length != styleB.length)
  2584. return false;
  2585. for (var p in styleA) {
  2586. if (/^(\d+|csstext)$/i.test(p)) {
  2587. continue;
  2588. }
  2589. if (styleA[p] != styleB[p]) {
  2590. return false;
  2591. }
  2592. }
  2593. return true;
  2594. }
  2595. if (!styleA || !styleB) {
  2596. return styleA == styleB;
  2597. }
  2598. styleA = styleA.split(';');
  2599. styleB = styleB.split(';');
  2600. if (styleA.length != styleB.length) {
  2601. return false;
  2602. }
  2603. for (var i = 0, ci; ci = styleA[i++];) {
  2604. if (utils.indexOf(styleB, ci) == -1) {
  2605. return false;
  2606. }
  2607. }
  2608. return true;
  2609. },
  2610. /**
  2611. * 检查节点node是否为block元素
  2612. * @method isBlockElm
  2613. * @param { Node } node 需要检测的节点对象
  2614. * @return { Boolean } 是否是block元素节点
  2615. * @warning 该方法的判断规则如下: 如果该元素原本是block元素, 则不论该元素当前的css样式是什么都会返回true;
  2616. * 否则,检测该元素的css样式, 如果该元素当前是block元素, 则返回true。 其余情况下都返回false。
  2617. * @example
  2618. * ```html
  2619. * <span id="test1" style="display: block"></span>
  2620. * <span id="test2"></span>
  2621. * <div id="test3" style="display: inline"></div>
  2622. *
  2623. * <script>
  2624. *
  2625. * //output: true
  2626. * console.log( UE.dom.domUtils.isBlockElm( document.getElementById("test1") ) );
  2627. *
  2628. * //output: false
  2629. * console.log( UE.dom.domUtils.isBlockElm( document.getElementById("test2") ) );
  2630. *
  2631. * //output: true
  2632. * console.log( UE.dom.domUtils.isBlockElm( document.getElementById("test3") ) );
  2633. *
  2634. * </script>
  2635. * ```
  2636. */
  2637. isBlockElm:function (node) {
  2638. return node.nodeType == 1 && (dtd.$block[node.tagName] || styleBlock[domUtils.getComputedStyle(node, 'display')]) && !dtd.$nonChild[node.tagName];
  2639. },
  2640. /**
  2641. * 检测node节点是否为body节点
  2642. * @method isBody
  2643. * @param { Element } node 需要检测的dom元素
  2644. * @return { Boolean } 给定的元素是否是body元素
  2645. * @example
  2646. * ```javascript
  2647. * //output: true
  2648. * console.log( UE.dom.domUtils.isBody( document.body ) );
  2649. * ```
  2650. */
  2651. isBody:function (node) {
  2652. return node && node.nodeType == 1 && node.tagName.toLowerCase() == 'body';
  2653. },
  2654. /**
  2655. * 以node节点为分界,将该节点的指定祖先节点parent拆分成两个独立的节点,
  2656. * 拆分形成的两个节点之间是node节点
  2657. * @method breakParent
  2658. * @param { Node } node 作为分界的节点对象
  2659. * @param { Node } parent 该节点必须是node节点的祖先节点, 且是block节点。
  2660. * @return { Node } 给定的node分界节点
  2661. * @example
  2662. * ```javascript
  2663. *
  2664. * var node = document.createElement("span"),
  2665. * wrapNode = document.createElement( "div" ),
  2666. * parent = document.createElement("p");
  2667. *
  2668. * parent.appendChild( node );
  2669. * wrapNode.appendChild( parent );
  2670. *
  2671. * //拆分前
  2672. * //output: <p><span></span></p>
  2673. * console.log( wrapNode.innerHTML );
  2674. *
  2675. *
  2676. * UE.dom.domUtils.breakParent( node, parent );
  2677. * //拆分后
  2678. * //output: <p></p><span></span><p></p>
  2679. * console.log( wrapNode.innerHTML );
  2680. *
  2681. * ```
  2682. */
  2683. breakParent:function (node, parent) {
  2684. var tmpNode,
  2685. parentClone = node,
  2686. clone = node,
  2687. leftNodes,
  2688. rightNodes;
  2689. do {
  2690. parentClone = parentClone.parentNode;
  2691. if (leftNodes) {
  2692. tmpNode = parentClone.cloneNode(false);
  2693. tmpNode.appendChild(leftNodes);
  2694. leftNodes = tmpNode;
  2695. tmpNode = parentClone.cloneNode(false);
  2696. tmpNode.appendChild(rightNodes);
  2697. rightNodes = tmpNode;
  2698. } else {
  2699. leftNodes = parentClone.cloneNode(false);
  2700. rightNodes = leftNodes.cloneNode(false);
  2701. }
  2702. while (tmpNode = clone.previousSibling) {
  2703. leftNodes.insertBefore(tmpNode, leftNodes.firstChild);
  2704. }
  2705. while (tmpNode = clone.nextSibling) {
  2706. rightNodes.appendChild(tmpNode);
  2707. }
  2708. clone = parentClone;
  2709. } while (parent !== parentClone);
  2710. tmpNode = parent.parentNode;
  2711. tmpNode.insertBefore(leftNodes, parent);
  2712. tmpNode.insertBefore(rightNodes, parent);
  2713. tmpNode.insertBefore(node, rightNodes);
  2714. domUtils.remove(parent);
  2715. return node;
  2716. },
  2717. /**
  2718. * 检查节点node是否是空inline节点
  2719. * @method isEmptyInlineElement
  2720. * @param { Node } node 需要检测的节点对象
  2721. * @return { Number } 如果给定的节点是空的inline节点, 则返回1, 否则返回0。
  2722. * @example
  2723. * ```html
  2724. * <b><i></i></b> => 1
  2725. * <b><i></i><u></u></b> => 1
  2726. * <b></b> => 1
  2727. * <b>xx<i></i></b> => 0
  2728. * ```
  2729. */
  2730. isEmptyInlineElement:function (node) {
  2731. if (node.nodeType != 1 || !dtd.$removeEmpty[ node.tagName ]) {
  2732. return 0;
  2733. }
  2734. node = node.firstChild;
  2735. while (node) {
  2736. //如果是创建的bookmark就跳过
  2737. if (domUtils.isBookmarkNode(node)) {
  2738. return 0;
  2739. }
  2740. if (node.nodeType == 1 && !domUtils.isEmptyInlineElement(node) ||
  2741. node.nodeType == 3 && !domUtils.isWhitespace(node)
  2742. ) {
  2743. return 0;
  2744. }
  2745. node = node.nextSibling;
  2746. }
  2747. return 1;
  2748. },
  2749. /**
  2750. * 删除node节点下首尾两端的空白文本子节点
  2751. * @method trimWhiteTextNode
  2752. * @param { Element } node 需要执行删除操作的元素对象
  2753. * @example
  2754. * ```javascript
  2755. * var node = document.createElement("div");
  2756. *
  2757. * node.appendChild( document.createTextNode( "" ) );
  2758. *
  2759. * node.appendChild( document.createElement("div") );
  2760. *
  2761. * node.appendChild( document.createTextNode( "" ) );
  2762. *
  2763. * //3
  2764. * console.log( node.childNodes.length );
  2765. *
  2766. * UE.dom.domUtils.trimWhiteTextNode( node );
  2767. *
  2768. * //1
  2769. * console.log( node.childNodes.length );
  2770. * ```
  2771. */
  2772. trimWhiteTextNode:function (node) {
  2773. function remove(dir) {
  2774. var child;
  2775. while ((child = node[dir]) && child.nodeType == 3 && domUtils.isWhitespace(child)) {
  2776. node.removeChild(child);
  2777. }
  2778. }
  2779. remove('firstChild');
  2780. remove('lastChild');
  2781. },
  2782. /**
  2783. * 合并node节点下相同的子节点
  2784. * @name mergeChild
  2785. * @desc
  2786. * UE.dom.domUtils.mergeChild(node,tagName) //tagName要合并的子节点的标签
  2787. * @example
  2788. * <p><span style="font-size:12px;">xx<span style="font-size:12px;">aa</span>xx</span></p>
  2789. * ==> UE.dom.domUtils.mergeChild(node,'span')
  2790. * <p><span style="font-size:12px;">xxaaxx</span></p>
  2791. */
  2792. mergeChild:function (node, tagName, attrs) {
  2793. var list = domUtils.getElementsByTagName(node, node.tagName.toLowerCase());
  2794. for (var i = 0, ci; ci = list[i++];) {
  2795. if (!ci.parentNode || domUtils.isBookmarkNode(ci)) {
  2796. continue;
  2797. }
  2798. //span单独处理
  2799. if (ci.tagName.toLowerCase() == 'span') {
  2800. if (node === ci.parentNode) {
  2801. domUtils.trimWhiteTextNode(node);
  2802. if (node.childNodes.length == 1) {
  2803. node.style.cssText = ci.style.cssText + ";" + node.style.cssText;
  2804. domUtils.remove(ci, true);
  2805. continue;
  2806. }
  2807. }
  2808. ci.style.cssText = node.style.cssText + ';' + ci.style.cssText;
  2809. if (attrs) {
  2810. var style = attrs.style;
  2811. if (style) {
  2812. style = style.split(';');
  2813. for (var j = 0, s; s = style[j++];) {
  2814. ci.style[utils.cssStyleToDomStyle(s.split(':')[0])] = s.split(':')[1];
  2815. }
  2816. }
  2817. }
  2818. if (domUtils.isSameStyle(ci, node)) {
  2819. domUtils.remove(ci, true);
  2820. }
  2821. continue;
  2822. }
  2823. if (domUtils.isSameElement(node, ci)) {
  2824. domUtils.remove(ci, true);
  2825. }
  2826. }
  2827. },
  2828. /**
  2829. * 原生方法getElementsByTagName的封装
  2830. * @method getElementsByTagName
  2831. * @param { Node } node 目标节点对象
  2832. * @param { String } tagName 需要查找的节点的tagName, 多个tagName以空格分割
  2833. * @return { Array } 符合条件的节点集合
  2834. */
  2835. getElementsByTagName:function (node, name,filter) {
  2836. if(filter && utils.isString(filter)){
  2837. var className = filter;
  2838. filter = function(node){return domUtils.hasClass(node,className)}
  2839. }
  2840. name = utils.trim(name).replace(/[ ]{2,}/g,' ').split(' ');
  2841. var arr = [];
  2842. for(var n = 0,ni;ni=name[n++];){
  2843. var list = node.getElementsByTagName(ni);
  2844. for (var i = 0, ci; ci = list[i++];) {
  2845. if(!filter || filter(ci))
  2846. arr.push(ci);
  2847. }
  2848. }
  2849. return arr;
  2850. },
  2851. /**
  2852. * 将节点node提取到父节点上
  2853. * @method mergeToParent
  2854. * @param { Element } node 需要提取的元素对象
  2855. * @example
  2856. * ```html
  2857. * <div id="parent">
  2858. * <div id="sub">
  2859. * <span id="child"></span>
  2860. * </div>
  2861. * </div>
  2862. *
  2863. * <script>
  2864. *
  2865. * var child = document.getElementById( "child" );
  2866. *
  2867. * //output: sub
  2868. * console.log( child.parentNode.id );
  2869. *
  2870. * UE.dom.domUtils.mergeToParent( child );
  2871. *
  2872. * //output: parent
  2873. * console.log( child.parentNode.id );
  2874. *
  2875. * </script>
  2876. * ```
  2877. */
  2878. mergeToParent:function (node) {
  2879. var parent = node.parentNode;
  2880. while (parent && dtd.$removeEmpty[parent.tagName]) {
  2881. if (parent.tagName == node.tagName || parent.tagName == 'A') {//针对a标签单独处理
  2882. domUtils.trimWhiteTextNode(parent);
  2883. //span需要特殊处理 不处理这样的情况 <span stlye="color:#fff">xxx<span style="color:#ccc">xxx</span>xxx</span>
  2884. if (parent.tagName == 'SPAN' && !domUtils.isSameStyle(parent, node)
  2885. || (parent.tagName == 'A' && node.tagName == 'SPAN')) {
  2886. if (parent.childNodes.length > 1 || parent !== node.parentNode) {
  2887. node.style.cssText = parent.style.cssText + ";" + node.style.cssText;
  2888. parent = parent.parentNode;
  2889. continue;
  2890. } else {
  2891. parent.style.cssText += ";" + node.style.cssText;
  2892. //trace:952 a标签要保持下划线
  2893. if (parent.tagName == 'A') {
  2894. parent.style.textDecoration = 'underline';
  2895. }
  2896. }
  2897. }
  2898. if (parent.tagName != 'A') {
  2899. parent === node.parentNode && domUtils.remove(node, true);
  2900. break;
  2901. }
  2902. }
  2903. parent = parent.parentNode;
  2904. }
  2905. },
  2906. /**
  2907. * 合并节点node的左右兄弟节点
  2908. * @method mergeSibling
  2909. * @param { Element } node 需要合并的目标节点
  2910. * @example
  2911. * ```html
  2912. * <b>xxxx</b><b id="test">ooo</b><b>xxxx</b>
  2913. *
  2914. * <script>
  2915. * var demoNode = document.getElementById("test");
  2916. * UE.dom.domUtils.mergeSibling( demoNode );
  2917. * //output: xxxxoooxxxx
  2918. * console.log( demoNode.innerHTML );
  2919. * </script>
  2920. * ```
  2921. */
  2922. /**
  2923. * 合并节点node的左右兄弟节点, 可以根据给定的条件选择是否忽略合并左节点。
  2924. * @method mergeSibling
  2925. * @param { Element } node 需要合并的目标节点
  2926. * @param { Boolean } ignorePre 是否忽略合并左节点
  2927. * @example
  2928. * ```html
  2929. * <b>xxxx</b><b id="test">ooo</b><b>xxxx</b>
  2930. *
  2931. * <script>
  2932. * var demoNode = document.getElementById("test");
  2933. * UE.dom.domUtils.mergeSibling( demoNode, true );
  2934. * //output: oooxxxx
  2935. * console.log( demoNode.innerHTML );
  2936. * </script>
  2937. * ```
  2938. */
  2939. /**
  2940. * 合并节点node的左右兄弟节点,可以根据给定的条件选择是否忽略合并左右节点。
  2941. * @method mergeSibling
  2942. * @param { Element } node 需要合并的目标节点
  2943. * @param { Boolean } ignorePre 是否忽略合并左节点
  2944. * @param { Boolean } ignoreNext 是否忽略合并右节点
  2945. * @remind 如果同时忽略左右节点, 则该操作什么也不会做
  2946. * @example
  2947. * ```html
  2948. * <b>xxxx</b><b id="test">ooo</b><b>xxxx</b>
  2949. *
  2950. * <script>
  2951. * var demoNode = document.getElementById("test");
  2952. * UE.dom.domUtils.mergeSibling( demoNode, false, true );
  2953. * //output: xxxxooo
  2954. * console.log( demoNode.innerHTML );
  2955. * </script>
  2956. * ```
  2957. */
  2958. mergeSibling:function (node, ignorePre, ignoreNext) {
  2959. function merge(rtl, start, node) {
  2960. var next;
  2961. if ((next = node[rtl]) && !domUtils.isBookmarkNode(next) && next.nodeType == 1 && domUtils.isSameElement(node, next)) {
  2962. while (next.firstChild) {
  2963. if (start == 'firstChild') {
  2964. node.insertBefore(next.lastChild, node.firstChild);
  2965. } else {
  2966. node.appendChild(next.firstChild);
  2967. }
  2968. }
  2969. domUtils.remove(next);
  2970. }
  2971. }
  2972. !ignorePre && merge('previousSibling', 'firstChild', node);
  2973. !ignoreNext && merge('nextSibling', 'lastChild', node);
  2974. },
  2975. /**
  2976. * 设置节点node及其子节点不会被选中
  2977. * @method unSelectable
  2978. * @param { Element } node 需要执行操作的dom元素
  2979. * @remind 执行该操作后的节点, 将不能被鼠标选中
  2980. * @example
  2981. * ```javascript
  2982. * UE.dom.domUtils.unSelectable( document.body );
  2983. * ```
  2984. */
  2985. unSelectable:ie && browser.ie9below || browser.opera ? function (node) {
  2986. //for ie9
  2987. node.onselectstart = function () {
  2988. return false;
  2989. };
  2990. node.onclick = node.onkeyup = node.onkeydown = function () {
  2991. return false;
  2992. };
  2993. node.unselectable = 'on';
  2994. node.setAttribute("unselectable", "on");
  2995. for (var i = 0, ci; ci = node.all[i++];) {
  2996. switch (ci.tagName.toLowerCase()) {
  2997. case 'iframe' :
  2998. case 'textarea' :
  2999. case 'input' :
  3000. case 'select' :
  3001. break;
  3002. default :
  3003. ci.unselectable = 'on';
  3004. node.setAttribute("unselectable", "on");
  3005. }
  3006. }
  3007. } : function (node) {
  3008. node.style.MozUserSelect =
  3009. node.style.webkitUserSelect =
  3010. node.style.msUserSelect =
  3011. node.style.KhtmlUserSelect = 'none';
  3012. },
  3013. /**
  3014. * 删除节点node上的指定属性名称的属性
  3015. * @method removeAttributes
  3016. * @param { Node } node 需要删除属性的节点对象
  3017. * @param { String } attrNames 可以是空格隔开的多个属性名称,该操作将会依次删除相应的属性
  3018. * @example
  3019. * ```html
  3020. * <div id="wrap">
  3021. * <span style="font-size:14px;" id="test" name="followMe">xxxxx</span>
  3022. * </div>
  3023. *
  3024. * <script>
  3025. *
  3026. * UE.dom.domUtils.removeAttributes( document.getElementById( "test" ), "id name" );
  3027. *
  3028. * //output: <span style="font-size:14px;">xxxxx</span>
  3029. * console.log( document.getElementById("wrap").innerHTML );
  3030. *
  3031. * </script>
  3032. * ```
  3033. */
  3034. /**
  3035. * 删除节点node上的指定属性名称的属性
  3036. * @method removeAttributes
  3037. * @param { Node } node 需要删除属性的节点对象
  3038. * @param { Array } attrNames 需要删除的属性名数组
  3039. * @example
  3040. * ```html
  3041. * <div id="wrap">
  3042. * <span style="font-size:14px;" id="test" name="followMe">xxxxx</span>
  3043. * </div>
  3044. *
  3045. * <script>
  3046. *
  3047. * UE.dom.domUtils.removeAttributes( document.getElementById( "test" ), ["id", "name"] );
  3048. *
  3049. * //output: <span style="font-size:14px;">xxxxx</span>
  3050. * console.log( document.getElementById("wrap").innerHTML );
  3051. *
  3052. * </script>
  3053. * ```
  3054. */
  3055. removeAttributes:function (node, attrNames) {
  3056. attrNames = utils.isArray(attrNames) ? attrNames : utils.trim(attrNames).replace(/[ ]{2,}/g,' ').split(' ');
  3057. for (var i = 0, ci; ci = attrNames[i++];) {
  3058. ci = attrFix[ci] || ci;
  3059. switch (ci) {
  3060. case 'className':
  3061. node[ci] = '';
  3062. break;
  3063. case 'style':
  3064. node.style.cssText = '';
  3065. var val = node.getAttributeNode('style');
  3066. !browser.ie && val && node.removeAttributeNode(val);
  3067. }
  3068. node.removeAttribute(ci);
  3069. }
  3070. },
  3071. /**
  3072. * 在doc下创建一个标签名为tag,属性为attrs的元素
  3073. * @method createElement
  3074. * @param { DomDocument } doc 新创建的元素属于该document节点创建
  3075. * @param { String } tagName 需要创建的元素的标签名
  3076. * @param { Object } attrs 新创建的元素的属性key-value集合
  3077. * @return { Element } 新创建的元素对象
  3078. * @example
  3079. * ```javascript
  3080. * var ele = UE.dom.domUtils.createElement( document, 'div', {
  3081. * id: 'test'
  3082. * } );
  3083. *
  3084. * //output: DIV
  3085. * console.log( ele.tagName );
  3086. *
  3087. * //output: test
  3088. * console.log( ele.id );
  3089. *
  3090. * ```
  3091. */
  3092. createElement:function (doc, tag, attrs) {
  3093. return domUtils.setAttributes(doc.createElement(tag), attrs)
  3094. },
  3095. /**
  3096. * 为节点node添加属性attrs,attrs为属性键值对
  3097. * @method setAttributes
  3098. * @param { Element } node 需要设置属性的元素对象
  3099. * @param { Object } attrs 需要设置的属性名-值对
  3100. * @return { Element } 设置属性的元素对象
  3101. * @example
  3102. * ```html
  3103. * <span id="test"></span>
  3104. *
  3105. * <script>
  3106. *
  3107. * var testNode = UE.dom.domUtils.setAttributes( document.getElementById( "test" ), {
  3108. * id: 'demo'
  3109. * } );
  3110. *
  3111. * //output: demo
  3112. * console.log( testNode.id );
  3113. *
  3114. * </script>
  3115. *
  3116. */
  3117. setAttributes:function (node, attrs) {
  3118. for (var attr in attrs) {
  3119. if(attrs.hasOwnProperty(attr)){
  3120. var value = attrs[attr];
  3121. switch (attr) {
  3122. case 'class':
  3123. //ie下要这样赋值,setAttribute不起作用
  3124. node.className = value;
  3125. break;
  3126. case 'style' :
  3127. node.style.cssText = node.style.cssText + ";" + value;
  3128. break;
  3129. case 'innerHTML':
  3130. node[attr] = value;
  3131. break;
  3132. case 'value':
  3133. node.value = value;
  3134. break;
  3135. default:
  3136. node.setAttribute(attrFix[attr] || attr, value);
  3137. }
  3138. }
  3139. }
  3140. return node;
  3141. },
  3142. /**
  3143. * 获取元素element经过计算后的样式值
  3144. * @method getComputedStyle
  3145. * @param { Element } element 需要获取样式的元素对象
  3146. * @param { String } styleName 需要获取的样式名
  3147. * @return { String } 获取到的样式值
  3148. * @example
  3149. * ```html
  3150. * <style type="text/css">
  3151. * #test {
  3152. * font-size: 15px;
  3153. * }
  3154. * </style>
  3155. *
  3156. * <span id="test"></span>
  3157. *
  3158. * <script>
  3159. * //output: 15px
  3160. * console.log( UE.dom.domUtils.getComputedStyle( document.getElementById( "test" ), 'font-size' ) );
  3161. * </script>
  3162. * ```
  3163. */
  3164. getComputedStyle:function (element, styleName) {
  3165. //一下的属性单独处理
  3166. var pros = 'width height top left';
  3167. if(pros.indexOf(styleName) > -1){
  3168. return element['offset' + styleName.replace(/^\w/,function(s){return s.toUpperCase()})] + 'px';
  3169. }
  3170. //忽略文本节点
  3171. if (element.nodeType == 3) {
  3172. element = element.parentNode;
  3173. }
  3174. //ie下font-size若body下定义了font-size,则从currentStyle里会取到这个font-size. 取不到实际值,故此修改.
  3175. if (browser.ie && browser.version < 9 && styleName == 'font-size' && !element.style.fontSize &&
  3176. !dtd.$empty[element.tagName] && !dtd.$nonChild[element.tagName]) {
  3177. var span = element.ownerDocument.createElement('span');
  3178. span.style.cssText = 'padding:0;border:0;font-family:simsun;';
  3179. span.innerHTML = '.';
  3180. element.appendChild(span);
  3181. var result = span.offsetHeight;
  3182. element.removeChild(span);
  3183. span = null;
  3184. return result + 'px';
  3185. }
  3186. try {
  3187. var value = domUtils.getStyle(element, styleName) ||
  3188. (window.getComputedStyle ? domUtils.getWindow(element).getComputedStyle(element, '').getPropertyValue(styleName) :
  3189. ( element.currentStyle || element.style )[utils.cssStyleToDomStyle(styleName)]);
  3190. } catch (e) {
  3191. return "";
  3192. }
  3193. return utils.transUnitToPx(utils.fixColor(styleName, value));
  3194. },
  3195. /**
  3196. * 删除元素element指定的className
  3197. * @method removeClasses
  3198. * @param { Element } ele 需要删除class的元素节点
  3199. * @param { String } classNames 需要删除的className, 多个className之间以空格分开
  3200. * @example
  3201. * ```html
  3202. * <span id="test" class="test1 test2 test3">xxx</span>
  3203. *
  3204. * <script>
  3205. *
  3206. * var testNode = document.getElementById( "test" );
  3207. * UE.dom.domUtils.removeClasses( testNode, "test1 test2" );
  3208. *
  3209. * //output: test3
  3210. * console.log( testNode.className );
  3211. *
  3212. * </script>
  3213. * ```
  3214. */
  3215. /**
  3216. * 删除元素element指定的className
  3217. * @method removeClasses
  3218. * @param { Element } ele 需要删除class的元素节点
  3219. * @param { Array } classNames 需要删除的className数组
  3220. * @example
  3221. * ```html
  3222. * <span id="test" class="test1 test2 test3">xxx</span>
  3223. *
  3224. * <script>
  3225. *
  3226. * var testNode = document.getElementById( "test" );
  3227. * UE.dom.domUtils.removeClasses( testNode, ["test1", "test2"] );
  3228. *
  3229. * //output: test3
  3230. * console.log( testNode.className );
  3231. *
  3232. * </script>
  3233. * ```
  3234. */
  3235. removeClasses:function (elm, classNames) {
  3236. classNames = utils.isArray(classNames) ? classNames :
  3237. utils.trim(classNames).replace(/[ ]{2,}/g,' ').split(' ');
  3238. for(var i = 0,ci,cls = elm.className;ci=classNames[i++];){
  3239. cls = cls.replace(new RegExp('\\b' + ci + '\\b'),'')
  3240. }
  3241. cls = utils.trim(cls).replace(/[ ]{2,}/g,' ');
  3242. if(cls){
  3243. elm.className = cls;
  3244. }else{
  3245. domUtils.removeAttributes(elm,['class']);
  3246. }
  3247. },
  3248. /**
  3249. * 给元素element添加className
  3250. * @method addClass
  3251. * @param { Node } ele 需要增加className的元素
  3252. * @param { String } classNames 需要添加的className, 多个className之间以空格分割
  3253. * @remind 相同的类名不会被重复添加
  3254. * @example
  3255. * ```html
  3256. * <span id="test" class="cls1 cls2"></span>
  3257. *
  3258. * <script>
  3259. * var testNode = document.getElementById("test");
  3260. *
  3261. * UE.dom.domUtils.addClass( testNode, "cls2 cls3 cls4" );
  3262. *
  3263. * //output: cl1 cls2 cls3 cls4
  3264. * console.log( testNode.className );
  3265. *
  3266. * <script>
  3267. * ```
  3268. */
  3269. /**
  3270. * 给元素element添加className
  3271. * @method addClass
  3272. * @param { Node } ele 需要增加className的元素
  3273. * @param { Array } classNames 需要添加的className的数组
  3274. * @remind 相同的类名不会被重复添加
  3275. * @example
  3276. * ```html
  3277. * <span id="test" class="cls1 cls2"></span>
  3278. *
  3279. * <script>
  3280. * var testNode = document.getElementById("test");
  3281. *
  3282. * UE.dom.domUtils.addClass( testNode, ["cls2", "cls3", "cls4"] );
  3283. *
  3284. * //output: cl1 cls2 cls3 cls4
  3285. * console.log( testNode.className );
  3286. *
  3287. * <script>
  3288. * ```
  3289. */
  3290. addClass:function (elm, classNames) {
  3291. if(!elm)return;
  3292. classNames = utils.trim(classNames).replace(/[ ]{2,}/g,' ').split(' ');
  3293. for(var i = 0,ci,cls = elm.className;ci=classNames[i++];){
  3294. if(!new RegExp('\\b' + ci + '\\b').test(cls)){
  3295. cls += ' ' + ci;
  3296. }
  3297. }
  3298. elm.className = utils.trim(cls);
  3299. },
  3300. /**
  3301. * 判断元素element是否包含给定的样式类名className
  3302. * @method hasClass
  3303. * @param { Node } ele 需要检测的元素
  3304. * @param { String } classNames 需要检测的className, 多个className之间用空格分割
  3305. * @return { Boolean } 元素是否包含所有给定的className
  3306. * @example
  3307. * ```html
  3308. * <span id="test1" class="cls1 cls2"></span>
  3309. *
  3310. * <script>
  3311. * var test1 = document.getElementById("test1");
  3312. *
  3313. * //output: false
  3314. * console.log( UE.dom.domUtils.hasClass( test1, "cls2 cls1 cls3" ) );
  3315. *
  3316. * //output: true
  3317. * console.log( UE.dom.domUtils.hasClass( test1, "cls2 cls1" ) );
  3318. * </script>
  3319. * ```
  3320. */
  3321. /**
  3322. * 判断元素element是否包含给定的样式类名className
  3323. * @method hasClass
  3324. * @param { Node } ele 需要检测的元素
  3325. * @param { Array } classNames 需要检测的className数组
  3326. * @return { Boolean } 元素是否包含所有给定的className
  3327. * @example
  3328. * ```html
  3329. * <span id="test1" class="cls1 cls2"></span>
  3330. *
  3331. * <script>
  3332. * var test1 = document.getElementById("test1");
  3333. *
  3334. * //output: false
  3335. * console.log( UE.dom.domUtils.hasClass( test1, [ "cls2", "cls1", "cls3" ] ) );
  3336. *
  3337. * //output: true
  3338. * console.log( UE.dom.domUtils.hasClass( test1, [ "cls2", "cls1" ]) );
  3339. * </script>
  3340. * ```
  3341. */
  3342. hasClass:function (element, className) {
  3343. if(utils.isRegExp(className)){
  3344. return className.test(element.className)
  3345. }
  3346. className = utils.trim(className).replace(/[ ]{2,}/g,' ').split(' ');
  3347. for(var i = 0,ci,cls = element.className;ci=className[i++];){
  3348. if(!new RegExp('\\b' + ci + '\\b','i').test(cls)){
  3349. return false;
  3350. }
  3351. }
  3352. return i - 1 == className.length;
  3353. },
  3354. /**
  3355. * 阻止事件默认行为
  3356. * @method preventDefault
  3357. * @param { Event } evt 需要阻止默认行为的事件对象
  3358. * @example
  3359. * ```javascript
  3360. * UE.dom.domUtils.preventDefault( evt );
  3361. * ```
  3362. */
  3363. preventDefault:function (evt) {
  3364. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  3365. },
  3366. /**
  3367. * 删除元素element指定的样式
  3368. * @method removeStyle
  3369. * @param { Element } element 需要删除样式的元素
  3370. * @param { String } styleName 需要删除的样式名
  3371. * @example
  3372. * ```html
  3373. * <span id="test" style="color: red; background: blue;"></span>
  3374. *
  3375. * <script>
  3376. *
  3377. * var testNode = document.getElementById("test");
  3378. *
  3379. * UE.dom.domUtils.removeStyle( testNode, 'color' );
  3380. *
  3381. * //output: background: blue;
  3382. * console.log( testNode.style.cssText );
  3383. *
  3384. * </script>
  3385. * ```
  3386. */
  3387. removeStyle:function (element, name) {
  3388. if(browser.ie ){
  3389. //针对color先单独处理一下
  3390. if(name == 'color'){
  3391. name = '(^|;)' + name;
  3392. }
  3393. element.style.cssText = element.style.cssText.replace(new RegExp(name + '[^:]*:[^;]+;?','ig'),'')
  3394. }else{
  3395. if (element.style.removeProperty) {
  3396. element.style.removeProperty (name);
  3397. }else {
  3398. element.style.removeAttribute (utils.cssStyleToDomStyle(name));
  3399. }
  3400. }
  3401. if (!element.style.cssText) {
  3402. domUtils.removeAttributes(element, ['style']);
  3403. }
  3404. },
  3405. /**
  3406. * 获取元素element的style属性的指定值
  3407. * @method getStyle
  3408. * @param { Element } element 需要获取属性值的元素
  3409. * @param { String } styleName 需要获取的style的名称
  3410. * @warning 该方法仅获取元素style属性中所标明的值
  3411. * @return { String } 该元素包含指定的style属性值
  3412. * @example
  3413. * ```html
  3414. * <div id="test" style="color: red;"></div>
  3415. *
  3416. * <script>
  3417. *
  3418. * var testNode = document.getElementById( "test" );
  3419. *
  3420. * //output: red
  3421. * console.log( UE.dom.domUtils.getStyle( testNode, "color" ) );
  3422. *
  3423. * //output: ""
  3424. * console.log( UE.dom.domUtils.getStyle( testNode, "background" ) );
  3425. *
  3426. * </script>
  3427. * ```
  3428. */
  3429. getStyle:function (element, name) {
  3430. var value = element.style[ utils.cssStyleToDomStyle(name) ];
  3431. return utils.fixColor(name, value);
  3432. },
  3433. /**
  3434. * 为元素element设置样式属性值
  3435. * @method setStyle
  3436. * @param { Element } element 需要设置样式的元素
  3437. * @param { String } styleName 样式名
  3438. * @param { String } styleValue 样式值
  3439. * @example
  3440. * ```html
  3441. * <div id="test"></div>
  3442. *
  3443. * <script>
  3444. *
  3445. * var testNode = document.getElementById( "test" );
  3446. *
  3447. * //output: ""
  3448. * console.log( testNode.style.color );
  3449. *
  3450. * UE.dom.domUtils.setStyle( testNode, 'color', 'red' );
  3451. * //output: "red"
  3452. * console.log( testNode.style.color );
  3453. *
  3454. * </script>
  3455. * ```
  3456. */
  3457. setStyle:function (element, name, value) {
  3458. element.style[utils.cssStyleToDomStyle(name)] = value;
  3459. if(!utils.trim(element.style.cssText)){
  3460. this.removeAttributes(element,'style')
  3461. }
  3462. },
  3463. /**
  3464. * 为元素element设置多个样式属性值
  3465. * @method setStyles
  3466. * @param { Element } element 需要设置样式的元素
  3467. * @param { Object } styles 样式名值对
  3468. * @example
  3469. * ```html
  3470. * <div id="test"></div>
  3471. *
  3472. * <script>
  3473. *
  3474. * var testNode = document.getElementById( "test" );
  3475. *
  3476. * //output: ""
  3477. * console.log( testNode.style.color );
  3478. *
  3479. * UE.dom.domUtils.setStyles( testNode, {
  3480. * 'color': 'red'
  3481. * } );
  3482. * //output: "red"
  3483. * console.log( testNode.style.color );
  3484. *
  3485. * </script>
  3486. * ```
  3487. */
  3488. setStyles:function (element, styles) {
  3489. for (var name in styles) {
  3490. if (styles.hasOwnProperty(name)) {
  3491. domUtils.setStyle(element, name, styles[name]);
  3492. }
  3493. }
  3494. },
  3495. /**
  3496. * 删除_moz_dirty属性
  3497. * @private
  3498. * @method removeDirtyAttr
  3499. */
  3500. removeDirtyAttr:function (node) {
  3501. for (var i = 0, ci, nodes = node.getElementsByTagName('*'); ci = nodes[i++];) {
  3502. ci.removeAttribute('_moz_dirty');
  3503. }
  3504. node.removeAttribute('_moz_dirty');
  3505. },
  3506. /**
  3507. * 获取子节点的数量
  3508. * @method getChildCount
  3509. * @param { Element } node 需要检测的元素
  3510. * @return { Number } 给定的node元素的子节点数量
  3511. * @example
  3512. * ```html
  3513. * <div id="test">
  3514. * <span></span>
  3515. * </div>
  3516. *
  3517. * <script>
  3518. *
  3519. * //output: 3
  3520. * console.log( UE.dom.domUtils.getChildCount( document.getElementById("test") ) );
  3521. *
  3522. * </script>
  3523. * ```
  3524. */
  3525. /**
  3526. * 根据给定的过滤规则, 获取符合条件的子节点的数量
  3527. * @method getChildCount
  3528. * @param { Element } node 需要检测的元素
  3529. * @param { Function } fn 过滤器, 要求对符合条件的子节点返回true, 反之则要求返回false
  3530. * @return { Number } 符合过滤条件的node元素的子节点数量
  3531. * @example
  3532. * ```html
  3533. * <div id="test">
  3534. * <span></span>
  3535. * </div>
  3536. *
  3537. * <script>
  3538. *
  3539. * //output: 1
  3540. * console.log( UE.dom.domUtils.getChildCount( document.getElementById("test"), function ( node ) {
  3541. *
  3542. * return node.nodeType === 1;
  3543. *
  3544. * } ) );
  3545. *
  3546. * </script>
  3547. * ```
  3548. */
  3549. getChildCount:function (node, fn) {
  3550. var count = 0, first = node.firstChild;
  3551. fn = fn || function () {
  3552. return 1;
  3553. };
  3554. while (first) {
  3555. if (fn(first)) {
  3556. count++;
  3557. }
  3558. first = first.nextSibling;
  3559. }
  3560. return count;
  3561. },
  3562. /**
  3563. * 判断给定节点是否为空节点
  3564. * @method isEmptyNode
  3565. * @param { Node } node 需要检测的节点对象
  3566. * @return { Boolean } 节点是否为空
  3567. * @example
  3568. * ```javascript
  3569. * UE.dom.domUtils.isEmptyNode( document.body );
  3570. * ```
  3571. */
  3572. isEmptyNode:function (node) {
  3573. return !node.firstChild || domUtils.getChildCount(node, function (node) {
  3574. return !domUtils.isBr(node) && !domUtils.isBookmarkNode(node) && !domUtils.isWhitespace(node)
  3575. }) == 0
  3576. },
  3577. clearSelectedArr:function (nodes) {
  3578. var node;
  3579. while (node = nodes.pop()) {
  3580. domUtils.removeAttributes(node, ['class']);
  3581. }
  3582. },
  3583. /**
  3584. * 将显示区域滚动到指定节点的位置
  3585. * @method scrollToView
  3586. * @param {Node} node 节点
  3587. * @param {window} win window对象
  3588. * @param {Number} offsetTop 距离上方的偏移量
  3589. */
  3590. scrollToView:function (node, win, offsetTop) {
  3591. var getViewPaneSize = function () {
  3592. var doc = win.document,
  3593. mode = doc.compatMode == 'CSS1Compat';
  3594. return {
  3595. width:( mode ? doc.documentElement.clientWidth : doc.body.clientWidth ) || 0,
  3596. height:( mode ? doc.documentElement.clientHeight : doc.body.clientHeight ) || 0
  3597. };
  3598. },
  3599. getScrollPosition = function (win) {
  3600. if ('pageXOffset' in win) {
  3601. return {
  3602. x:win.pageXOffset || 0,
  3603. y:win.pageYOffset || 0
  3604. };
  3605. }
  3606. else {
  3607. var doc = win.document;
  3608. return {
  3609. x:doc.documentElement.scrollLeft || doc.body.scrollLeft || 0,
  3610. y:doc.documentElement.scrollTop || doc.body.scrollTop || 0
  3611. };
  3612. }
  3613. };
  3614. var winHeight = getViewPaneSize().height, offset = winHeight * -1 + offsetTop;
  3615. offset += (node.offsetHeight || 0);
  3616. var elementPosition = domUtils.getXY(node);
  3617. offset += elementPosition.y;
  3618. var currentScroll = getScrollPosition(win).y;
  3619. // offset += 50;
  3620. if (offset > currentScroll || offset < currentScroll - winHeight) {
  3621. win.scrollTo(0, offset + (offset < 0 ? -20 : 20));
  3622. }
  3623. },
  3624. /**
  3625. * 判断给定节点是否为br
  3626. * @method isBr
  3627. * @param { Node } node 需要判断的节点对象
  3628. * @return { Boolean } 给定的节点是否是br节点
  3629. */
  3630. isBr:function (node) {
  3631. return node.nodeType == 1 && node.tagName == 'BR';
  3632. },
  3633. /**
  3634. * 判断给定的节点是否是一个“填充”节点
  3635. * @private
  3636. * @method isFillChar
  3637. * @param { Node } node 需要判断的节点
  3638. * @param { Boolean } isInStart 是否从节点内容的开始位置匹配
  3639. * @returns { Boolean } 节点是否是填充节点
  3640. */
  3641. isFillChar:function (node,isInStart) {
  3642. if(node.nodeType != 3)
  3643. return false;
  3644. var text = node.nodeValue;
  3645. if(isInStart){
  3646. return new RegExp('^' + domUtils.fillChar).test(text)
  3647. }
  3648. return !text.replace(new RegExp(domUtils.fillChar,'g'), '').length
  3649. },
  3650. isStartInblock:function (range) {
  3651. var tmpRange = range.cloneRange(),
  3652. flag = 0,
  3653. start = tmpRange.startContainer,
  3654. tmp;
  3655. if(start.nodeType == 1 && start.childNodes[tmpRange.startOffset]){
  3656. start = start.childNodes[tmpRange.startOffset];
  3657. var pre = start.previousSibling;
  3658. while(pre && domUtils.isFillChar(pre)){
  3659. start = pre;
  3660. pre = pre.previousSibling;
  3661. }
  3662. }
  3663. if(this.isFillChar(start,true) && tmpRange.startOffset == 1){
  3664. tmpRange.setStartBefore(start);
  3665. start = tmpRange.startContainer;
  3666. }
  3667. while (start && domUtils.isFillChar(start)) {
  3668. tmp = start;
  3669. start = start.previousSibling
  3670. }
  3671. if (tmp) {
  3672. tmpRange.setStartBefore(tmp);
  3673. start = tmpRange.startContainer;
  3674. }
  3675. if (start.nodeType == 1 && domUtils.isEmptyNode(start) && tmpRange.startOffset == 1) {
  3676. tmpRange.setStart(start, 0).collapse(true);
  3677. }
  3678. while (!tmpRange.startOffset) {
  3679. start = tmpRange.startContainer;
  3680. if (domUtils.isBlockElm(start) || domUtils.isBody(start)) {
  3681. flag = 1;
  3682. break;
  3683. }
  3684. var pre = tmpRange.startContainer.previousSibling,
  3685. tmpNode;
  3686. if (!pre) {
  3687. tmpRange.setStartBefore(tmpRange.startContainer);
  3688. } else {
  3689. while (pre && domUtils.isFillChar(pre)) {
  3690. tmpNode = pre;
  3691. pre = pre.previousSibling;
  3692. }
  3693. if (tmpNode) {
  3694. tmpRange.setStartBefore(tmpNode);
  3695. } else {
  3696. tmpRange.setStartBefore(tmpRange.startContainer);
  3697. }
  3698. }
  3699. }
  3700. return flag && !domUtils.isBody(tmpRange.startContainer) ? 1 : 0;
  3701. },
  3702. /**
  3703. * 判断给定的元素是否是一个空元素
  3704. * @method isEmptyBlock
  3705. * @param { Element } node 需要判断的元素
  3706. * @return { Boolean } 是否是空元素
  3707. * @example
  3708. * ```html
  3709. * <div id="test"></div>
  3710. *
  3711. * <script>
  3712. * //output: true
  3713. * console.log( UE.dom.domUtils.isEmptyBlock( document.getElementById("test") ) );
  3714. * </script>
  3715. * ```
  3716. */
  3717. /**
  3718. * 根据指定的判断规则判断给定的元素是否是一个空元素
  3719. * @method isEmptyBlock
  3720. * @param { Element } node 需要判断的元素
  3721. * @param { RegExp } reg 对内容执行判断的正则表达式对象
  3722. * @return { Boolean } 是否是空元素
  3723. */
  3724. isEmptyBlock:function (node,reg) {
  3725. if(node.nodeType != 1)
  3726. return 0;
  3727. reg = reg || new RegExp('[ \xa0\t\r\n' + domUtils.fillChar + ']', 'g');
  3728. if (node[browser.ie ? 'innerText' : 'textContent'].replace(reg, '').length > 0) {
  3729. return 0;
  3730. }
  3731. for (var n in dtd.$isNotEmpty) {
  3732. if (node.getElementsByTagName(n).length) {
  3733. return 0;
  3734. }
  3735. }
  3736. return 1;
  3737. },
  3738. /**
  3739. * 移动元素使得该元素的位置移动指定的偏移量的距离
  3740. * @method setViewportOffset
  3741. * @param { Element } element 需要设置偏移量的元素
  3742. * @param { Object } offset 偏移量, 形如{ left: 100, top: 50 }的一个键值对, 表示该元素将在
  3743. * 现有的位置上向水平方向偏移offset.left的距离, 在竖直方向上偏移
  3744. * offset.top的距离
  3745. * @example
  3746. * ```html
  3747. * <div id="test" style="top: 100px; left: 50px; position: absolute;"></div>
  3748. *
  3749. * <script>
  3750. *
  3751. * var testNode = document.getElementById("test");
  3752. *
  3753. * UE.dom.domUtils.setViewportOffset( testNode, {
  3754. * left: 200,
  3755. * top: 50
  3756. * } );
  3757. *
  3758. * //output: top: 300px; left: 100px; position: absolute;
  3759. * console.log( testNode.style.cssText );
  3760. *
  3761. * </script>
  3762. * ```
  3763. */
  3764. setViewportOffset:function (element, offset) {
  3765. var left = parseInt(element.style.left) | 0;
  3766. var top = parseInt(element.style.top) | 0;
  3767. var rect = element.getBoundingClientRect();
  3768. var offsetLeft = offset.left - rect.left;
  3769. var offsetTop = offset.top - rect.top;
  3770. if (offsetLeft) {
  3771. element.style.left = left + offsetLeft + 'px';
  3772. }
  3773. if (offsetTop) {
  3774. element.style.top = top + offsetTop + 'px';
  3775. }
  3776. },
  3777. /**
  3778. * 用“填充字符”填充节点
  3779. * @method fillNode
  3780. * @private
  3781. * @param { DomDocument } doc 填充的节点所在的docment对象
  3782. * @param { Node } node 需要填充的节点对象
  3783. * @example
  3784. * ```html
  3785. * <div id="test"></div>
  3786. *
  3787. * <script>
  3788. * var testNode = document.getElementById("test");
  3789. *
  3790. * //output: 0
  3791. * console.log( testNode.childNodes.length );
  3792. *
  3793. * UE.dom.domUtils.fillNode( document, testNode );
  3794. *
  3795. * //output: 1
  3796. * console.log( testNode.childNodes.length );
  3797. *
  3798. * </script>
  3799. * ```
  3800. */
  3801. fillNode:function (doc, node) {
  3802. var tmpNode = browser.ie ? doc.createTextNode(domUtils.fillChar) : doc.createElement('br');
  3803. node.innerHTML = '';
  3804. node.appendChild(tmpNode);
  3805. },
  3806. /**
  3807. * 把节点src的所有子节点追加到另一个节点tag上去
  3808. * @method moveChild
  3809. * @param { Node } src 源节点, 该节点下的所有子节点将被移除
  3810. * @param { Node } tag 目标节点, 从源节点移除的子节点将被追加到该节点下
  3811. * @example
  3812. * ```html
  3813. * <div id="test1">
  3814. * <span></span>
  3815. * </div>
  3816. * <div id="test2">
  3817. * <div></div>
  3818. * </div>
  3819. *
  3820. * <script>
  3821. *
  3822. * var test1 = document.getElementById("test1"),
  3823. * test2 = document.getElementById("test2");
  3824. *
  3825. * UE.dom.domUtils.moveChild( test1, test2 );
  3826. *
  3827. * //output: ""(空字符串)
  3828. * console.log( test1.innerHTML );
  3829. *
  3830. * //output: "<div></div><span></span>"
  3831. * console.log( test2.innerHTML );
  3832. *
  3833. * </script>
  3834. * ```
  3835. */
  3836. /**
  3837. * 把节点src的所有子节点移动到另一个节点tag上去, 可以通过dir参数控制附加的行为是“追加”还是“插入顶部”
  3838. * @method moveChild
  3839. * @param { Node } src 源节点, 该节点下的所有子节点将被移除
  3840. * @param { Node } tag 目标节点, 从源节点移除的子节点将被附加到该节点下
  3841. * @param { Boolean } dir 附加方式, 如果为true, 则附加进去的节点将被放到目标节点的顶部, 反之,则放到末尾
  3842. * @example
  3843. * ```html
  3844. * <div id="test1">
  3845. * <span></span>
  3846. * </div>
  3847. * <div id="test2">
  3848. * <div></div>
  3849. * </div>
  3850. *
  3851. * <script>
  3852. *
  3853. * var test1 = document.getElementById("test1"),
  3854. * test2 = document.getElementById("test2");
  3855. *
  3856. * UE.dom.domUtils.moveChild( test1, test2, true );
  3857. *
  3858. * //output: ""(空字符串)
  3859. * console.log( test1.innerHTML );
  3860. *
  3861. * //output: "<span></span><div></div>"
  3862. * console.log( test2.innerHTML );
  3863. *
  3864. * </script>
  3865. * ```
  3866. */
  3867. moveChild:function (src, tag, dir) {
  3868. while (src.firstChild) {
  3869. if (dir && tag.firstChild) {
  3870. tag.insertBefore(src.lastChild, tag.firstChild);
  3871. } else {
  3872. tag.appendChild(src.firstChild);
  3873. }
  3874. }
  3875. },
  3876. /**
  3877. * 判断节点的标签上是否不存在任何属性
  3878. * @method hasNoAttributes
  3879. * @private
  3880. * @param { Node } node 需要检测的节点对象
  3881. * @return { Boolean } 节点是否不包含任何属性
  3882. * @example
  3883. * ```html
  3884. * <div id="test"><span>xxxx</span></div>
  3885. *
  3886. * <script>
  3887. *
  3888. * //output: false
  3889. * console.log( UE.dom.domUtils.hasNoAttributes( document.getElementById("test") ) );
  3890. *
  3891. * //output: true
  3892. * console.log( UE.dom.domUtils.hasNoAttributes( document.getElementById("test").firstChild ) );
  3893. *
  3894. * </script>
  3895. * ```
  3896. */
  3897. hasNoAttributes:function (node) {
  3898. return browser.ie ? /^<\w+\s*?>/.test(node.outerHTML) : node.attributes.length == 0;
  3899. },
  3900. /**
  3901. * 检测节点是否是UEditor所使用的辅助节点
  3902. * @method isCustomeNode
  3903. * @private
  3904. * @param { Node } node 需要检测的节点
  3905. * @remind 辅助节点是指编辑器要完成工作临时添加的节点, 在输出的时候将会从编辑器内移除, 不会影响最终的结果。
  3906. * @return { Boolean } 给定的节点是否是一个辅助节点
  3907. */
  3908. isCustomeNode:function (node) {
  3909. return node.nodeType == 1 && node.getAttribute('_ue_custom_node_');
  3910. },
  3911. /**
  3912. * 检测节点的标签是否是给定的标签
  3913. * @method isTagNode
  3914. * @param { Node } node 需要检测的节点对象
  3915. * @param { String } tagName 标签
  3916. * @return { Boolean } 节点的标签是否是给定的标签
  3917. * @example
  3918. * ```html
  3919. * <div id="test"></div>
  3920. *
  3921. * <script>
  3922. *
  3923. * //output: true
  3924. * console.log( UE.dom.domUtils.isTagNode( document.getElementById("test"), "div" ) );
  3925. *
  3926. * </script>
  3927. * ```
  3928. */
  3929. isTagNode:function (node, tagNames) {
  3930. return node.nodeType == 1 && new RegExp('\\b' + node.tagName + '\\b','i').test(tagNames)
  3931. },
  3932. /**
  3933. * 给定一个节点数组,在通过指定的过滤器过滤后, 获取其中满足过滤条件的第一个节点
  3934. * @method filterNodeList
  3935. * @param { Array } nodeList 需要过滤的节点数组
  3936. * @param { Function } fn 过滤器, 对符合条件的节点, 执行结果返回true, 反之则返回false
  3937. * @return { Node | NULL } 如果找到符合过滤条件的节点, 则返回该节点, 否则返回NULL
  3938. * @example
  3939. * ```javascript
  3940. * var divNodes = document.getElementsByTagName("div");
  3941. * divNodes = [].slice.call( divNodes, 0 );
  3942. *
  3943. * //output: null
  3944. * console.log( UE.dom.domUtils.filterNodeList( divNodes, function ( node ) {
  3945. * return node.tagName.toLowerCase() !== 'div';
  3946. * } ) );
  3947. * ```
  3948. */
  3949. /**
  3950. * 给定一个节点数组nodeList和一组标签名tagNames, 获取其中能够匹配标签名的节点集合中的第一个节点
  3951. * @method filterNodeList
  3952. * @param { Array } nodeList 需要过滤的节点数组
  3953. * @param { String } tagNames 需要匹配的标签名, 多个标签名之间用空格分割
  3954. * @return { Node | NULL } 如果找到标签名匹配的节点, 则返回该节点, 否则返回NULL
  3955. * @example
  3956. * ```javascript
  3957. * var divNodes = document.getElementsByTagName("div");
  3958. * divNodes = [].slice.call( divNodes, 0 );
  3959. *
  3960. * //output: null
  3961. * console.log( UE.dom.domUtils.filterNodeList( divNodes, 'a span' ) );
  3962. * ```
  3963. */
  3964. /**
  3965. * 给定一个节点数组,在通过指定的过滤器过滤后, 如果参数forAll为true, 则会返回所有满足过滤
  3966. * 条件的节点集合, 否则, 返回满足条件的节点集合中的第一个节点
  3967. * @method filterNodeList
  3968. * @param { Array } nodeList 需要过滤的节点数组
  3969. * @param { Function } fn 过滤器, 对符合条件的节点, 执行结果返回true, 反之则返回false
  3970. * @param { Boolean } forAll 是否返回整个节点数组, 如果该参数为false, 则返回节点集合中的第一个节点
  3971. * @return { Array | Node | NULL } 如果找到符合过滤条件的节点, 则根据参数forAll的值决定返回满足
  3972. * 过滤条件的节点数组或第一个节点, 否则返回NULL
  3973. * @example
  3974. * ```javascript
  3975. * var divNodes = document.getElementsByTagName("div");
  3976. * divNodes = [].slice.call( divNodes, 0 );
  3977. *
  3978. * //output: 3(假定有3个div)
  3979. * console.log( divNodes.length );
  3980. *
  3981. * var nodes = UE.dom.domUtils.filterNodeList( divNodes, function ( node ) {
  3982. * return node.tagName.toLowerCase() === 'div';
  3983. * }, true );
  3984. *
  3985. * //output: 3
  3986. * console.log( nodes.length );
  3987. *
  3988. * var node = UE.dom.domUtils.filterNodeList( divNodes, function ( node ) {
  3989. * return node.tagName.toLowerCase() === 'div';
  3990. * }, false );
  3991. *
  3992. * //output: div
  3993. * console.log( node.nodeName );
  3994. * ```
  3995. */
  3996. filterNodeList : function(nodelist,filter,forAll){
  3997. var results = [];
  3998. if(!utils .isFunction(filter)){
  3999. var str = filter;
  4000. filter = function(n){
  4001. return utils.indexOf(utils.isArray(str) ? str:str.split(' '), n.tagName.toLowerCase()) != -1
  4002. };
  4003. }
  4004. utils.each(nodelist,function(n){
  4005. filter(n) && results.push(n)
  4006. });
  4007. return results.length == 0 ? null : results.length == 1 || !forAll ? results[0] : results
  4008. },
  4009. /**
  4010. * 查询给定的range选区是否在给定的node节点内,且在该节点的最末尾
  4011. * @method isInNodeEndBoundary
  4012. * @param { UE.dom.Range } rng 需要判断的range对象, 该对象的startContainer不能为NULL
  4013. * @param node 需要检测的节点对象
  4014. * @return { Number } 如果给定的选取range对象是在node内部的最末端, 则返回1, 否则返回0
  4015. */
  4016. isInNodeEndBoundary : function (rng,node){
  4017. var start = rng.startContainer;
  4018. if(start.nodeType == 3 && rng.startOffset != start.nodeValue.length){
  4019. return 0;
  4020. }
  4021. if(start.nodeType == 1 && rng.startOffset != start.childNodes.length){
  4022. return 0;
  4023. }
  4024. while(start !== node){
  4025. if(start.nextSibling){
  4026. return 0
  4027. };
  4028. start = start.parentNode;
  4029. }
  4030. return 1;
  4031. },
  4032. isBoundaryNode : function (node,dir){
  4033. var tmp;
  4034. while(!domUtils.isBody(node)){
  4035. tmp = node;
  4036. node = node.parentNode;
  4037. if(tmp !== node[dir]){
  4038. return false;
  4039. }
  4040. }
  4041. return true;
  4042. },
  4043. fillHtml : browser.ie11below ? '&nbsp;' : '<br/>'
  4044. };
  4045. var fillCharReg = new RegExp(domUtils.fillChar, 'g');
  4046. // js/editor/_src/core/Range.js
  4047. /**
  4048. * Range封装
  4049. * @file
  4050. * @module UE.dom
  4051. * @class Range
  4052. * @since 1.2.6.1
  4053. */
  4054. /**
  4055. * dom操作封装
  4056. * @unfile
  4057. * @module UE.dom
  4058. */
  4059. /**
  4060. * Range实现类,本类是UEditor底层核心类,封装不同浏览器之间的Range操作。
  4061. * @unfile
  4062. * @module UE.dom
  4063. * @class Range
  4064. */
  4065. (function () {
  4066. var guid = 0,
  4067. fillChar = domUtils.fillChar,
  4068. fillData;
  4069. /**
  4070. * 更新range的collapse状态
  4071. * @param {Range} range range对象
  4072. */
  4073. function updateCollapse(range) {
  4074. range.collapsed =
  4075. range.startContainer && range.endContainer &&
  4076. range.startContainer === range.endContainer &&
  4077. range.startOffset == range.endOffset;
  4078. }
  4079. function selectOneNode(rng){
  4080. return !rng.collapsed && rng.startContainer.nodeType == 1 && rng.startContainer === rng.endContainer && rng.endOffset - rng.startOffset == 1
  4081. }
  4082. function setEndPoint(toStart, node, offset, range) {
  4083. //如果node是自闭合标签要处理
  4084. if (node.nodeType == 1 && (dtd.$empty[node.tagName] || dtd.$nonChild[node.tagName])) {
  4085. offset = domUtils.getNodeIndex(node) + (toStart ? 0 : 1);
  4086. node = node.parentNode;
  4087. }
  4088. if (toStart) {
  4089. range.startContainer = node;
  4090. range.startOffset = offset;
  4091. if (!range.endContainer) {
  4092. range.collapse(true);
  4093. }
  4094. } else {
  4095. range.endContainer = node;
  4096. range.endOffset = offset;
  4097. if (!range.startContainer) {
  4098. range.collapse(false);
  4099. }
  4100. }
  4101. updateCollapse(range);
  4102. return range;
  4103. }
  4104. function execContentsAction(range, action) {
  4105. //调整边界
  4106. //range.includeBookmark();
  4107. var start = range.startContainer,
  4108. end = range.endContainer,
  4109. startOffset = range.startOffset,
  4110. endOffset = range.endOffset,
  4111. doc = range.document,
  4112. frag = doc.createDocumentFragment(),
  4113. tmpStart, tmpEnd;
  4114. if (start.nodeType == 1) {
  4115. start = start.childNodes[startOffset] || (tmpStart = start.appendChild(doc.createTextNode('')));
  4116. }
  4117. if (end.nodeType == 1) {
  4118. end = end.childNodes[endOffset] || (tmpEnd = end.appendChild(doc.createTextNode('')));
  4119. }
  4120. if (start === end && start.nodeType == 3) {
  4121. frag.appendChild(doc.createTextNode(start.substringData(startOffset, endOffset - startOffset)));
  4122. //is not clone
  4123. if (action) {
  4124. start.deleteData(startOffset, endOffset - startOffset);
  4125. range.collapse(true);
  4126. }
  4127. return frag;
  4128. }
  4129. var current, currentLevel, clone = frag,
  4130. startParents = domUtils.findParents(start, true), endParents = domUtils.findParents(end, true);
  4131. for (var i = 0; startParents[i] == endParents[i];) {
  4132. i++;
  4133. }
  4134. for (var j = i, si; si = startParents[j]; j++) {
  4135. current = si.nextSibling;
  4136. if (si == start) {
  4137. if (!tmpStart) {
  4138. if (range.startContainer.nodeType == 3) {
  4139. clone.appendChild(doc.createTextNode(start.nodeValue.slice(startOffset)));
  4140. //is not clone
  4141. if (action) {
  4142. start.deleteData(startOffset, start.nodeValue.length - startOffset);
  4143. }
  4144. } else {
  4145. clone.appendChild(!action ? start.cloneNode(true) : start);
  4146. }
  4147. }
  4148. } else {
  4149. currentLevel = si.cloneNode(false);
  4150. clone.appendChild(currentLevel);
  4151. }
  4152. while (current) {
  4153. if (current === end || current === endParents[j]) {
  4154. break;
  4155. }
  4156. si = current.nextSibling;
  4157. clone.appendChild(!action ? current.cloneNode(true) : current);
  4158. current = si;
  4159. }
  4160. clone = currentLevel;
  4161. }
  4162. clone = frag;
  4163. if (!startParents[i]) {
  4164. clone.appendChild(startParents[i - 1].cloneNode(false));
  4165. clone = clone.firstChild;
  4166. }
  4167. for (var j = i, ei; ei = endParents[j]; j++) {
  4168. current = ei.previousSibling;
  4169. if (ei == end) {
  4170. if (!tmpEnd && range.endContainer.nodeType == 3) {
  4171. clone.appendChild(doc.createTextNode(end.substringData(0, endOffset)));
  4172. //is not clone
  4173. if (action) {
  4174. end.deleteData(0, endOffset);
  4175. }
  4176. }
  4177. } else {
  4178. currentLevel = ei.cloneNode(false);
  4179. clone.appendChild(currentLevel);
  4180. }
  4181. //如果两端同级,右边第一次已经被开始做了
  4182. if (j != i || !startParents[i]) {
  4183. while (current) {
  4184. if (current === start) {
  4185. break;
  4186. }
  4187. ei = current.previousSibling;
  4188. clone.insertBefore(!action ? current.cloneNode(true) : current, clone.firstChild);
  4189. current = ei;
  4190. }
  4191. }
  4192. clone = currentLevel;
  4193. }
  4194. if (action) {
  4195. range.setStartBefore(!endParents[i] ? endParents[i - 1] : !startParents[i] ? startParents[i - 1] : endParents[i]).collapse(true);
  4196. }
  4197. tmpStart && domUtils.remove(tmpStart);
  4198. tmpEnd && domUtils.remove(tmpEnd);
  4199. return frag;
  4200. }
  4201. /**
  4202. * 创建一个跟document绑定的空的Range实例
  4203. * @constructor
  4204. * @param { Document } document 新建的选区所属的文档对象
  4205. */
  4206. /**
  4207. * @property { Node } startContainer 当前Range的开始边界的容器节点, 可以是一个元素节点或者是文本节点
  4208. */
  4209. /**
  4210. * @property { Node } startOffset 当前Range的开始边界容器节点的偏移量, 如果是元素节点,
  4211. * 该值就是childNodes中的第几个节点, 如果是文本节点就是文本内容的第几个字符
  4212. */
  4213. /**
  4214. * @property { Node } endContainer 当前Range的结束边界的容器节点, 可以是一个元素节点或者是文本节点
  4215. */
  4216. /**
  4217. * @property { Node } endOffset 当前Range的结束边界容器节点的偏移量, 如果是元素节点,
  4218. * 该值就是childNodes中的第几个节点, 如果是文本节点就是文本内容的第几个字符
  4219. */
  4220. /**
  4221. * @property { Boolean } collapsed 当前Range是否闭合
  4222. * @default true
  4223. * @remind Range是闭合的时候, startContainer === endContainer && startOffset === endOffset
  4224. */
  4225. /**
  4226. * @property { Document } document 当前Range所属的Document对象
  4227. * @remind 不同range的的document属性可以是不同的
  4228. */
  4229. var Range = dom.Range = function (document) {
  4230. var me = this;
  4231. me.startContainer =
  4232. me.startOffset =
  4233. me.endContainer =
  4234. me.endOffset = null;
  4235. me.document = document;
  4236. me.collapsed = true;
  4237. };
  4238. /**
  4239. * 删除fillData
  4240. * @param doc
  4241. * @param excludeNode
  4242. */
  4243. function removeFillData(doc, excludeNode) {
  4244. try {
  4245. if (fillData && domUtils.inDoc(fillData, doc)) {
  4246. if (!fillData.nodeValue.replace(fillCharReg, '').length) {
  4247. var tmpNode = fillData.parentNode;
  4248. domUtils.remove(fillData);
  4249. while (tmpNode && domUtils.isEmptyInlineElement(tmpNode) &&
  4250. //safari的contains有bug
  4251. (browser.safari ? !(domUtils.getPosition(tmpNode,excludeNode) & domUtils.POSITION_CONTAINS) : !tmpNode.contains(excludeNode))
  4252. ) {
  4253. fillData = tmpNode.parentNode;
  4254. domUtils.remove(tmpNode);
  4255. tmpNode = fillData;
  4256. }
  4257. } else {
  4258. fillData.nodeValue = fillData.nodeValue.replace(fillCharReg, '');
  4259. }
  4260. }
  4261. } catch (e) {
  4262. }
  4263. }
  4264. /**
  4265. * @param node
  4266. * @param dir
  4267. */
  4268. function mergeSibling(node, dir) {
  4269. var tmpNode;
  4270. node = node[dir];
  4271. while (node && domUtils.isFillChar(node)) {
  4272. tmpNode = node[dir];
  4273. domUtils.remove(node);
  4274. node = tmpNode;
  4275. }
  4276. }
  4277. Range.prototype = {
  4278. /**
  4279. * 克隆选区的内容到一个DocumentFragment里
  4280. * @method cloneContents
  4281. * @return { DocumentFragment | NULL } 如果选区是闭合的将返回null, 否则, 返回包含所clone内容的DocumentFragment元素
  4282. * @example
  4283. * ```html
  4284. * <body>
  4285. * <!-- 中括号表示选区 -->
  4286. * <b>x<i>x[x</i>xx]x</b>
  4287. *
  4288. * <script>
  4289. * //range是已选中的选区
  4290. * var fragment = range.cloneContents(),
  4291. * node = document.createElement("div");
  4292. *
  4293. * node.appendChild( fragment );
  4294. *
  4295. * //output: <i>x</i>xx
  4296. * console.log( node.innerHTML );
  4297. *
  4298. * </script>
  4299. * </body>
  4300. * ```
  4301. */
  4302. cloneContents:function () {
  4303. return this.collapsed ? null : execContentsAction(this, 0);
  4304. },
  4305. /**
  4306. * 删除当前选区范围中的所有内容
  4307. * @method deleteContents
  4308. * @remind 执行完该操作后, 当前Range对象变成了闭合状态
  4309. * @return { UE.dom.Range } 当前操作的Range对象
  4310. * @example
  4311. * ```html
  4312. * <body>
  4313. * <!-- 中括号表示选区 -->
  4314. * <b>x<i>x[x</i>xx]x</b>
  4315. *
  4316. * <script>
  4317. * //range是已选中的选区
  4318. * range.deleteContents();
  4319. *
  4320. * //竖线表示闭合后的选区位置
  4321. * //output: <b>x<i>x</i>|x</b>
  4322. * console.log( document.body.innerHTML );
  4323. *
  4324. * //此时, range的各项属性为
  4325. * //output: B
  4326. * console.log( range.startContainer.tagName );
  4327. * //output: 2
  4328. * console.log( range.startOffset );
  4329. * //output: B
  4330. * console.log( range.endContainer.tagName );
  4331. * //output: 2
  4332. * console.log( range.endOffset );
  4333. * //output: true
  4334. * console.log( range.collapsed );
  4335. *
  4336. * </script>
  4337. * </body>
  4338. * ```
  4339. */
  4340. deleteContents:function () {
  4341. var txt;
  4342. if (!this.collapsed) {
  4343. execContentsAction(this, 1);
  4344. }
  4345. if (browser.webkit) {
  4346. txt = this.startContainer;
  4347. if (txt.nodeType == 3 && !txt.nodeValue.length) {
  4348. this.setStartBefore(txt).collapse(true);
  4349. domUtils.remove(txt);
  4350. }
  4351. }
  4352. return this;
  4353. },
  4354. /**
  4355. * 将当前选区的内容提取到一个DocumentFragment里
  4356. * @method extractContents
  4357. * @remind 执行该操作后, 选区将变成闭合状态
  4358. * @warning 执行该操作后, 原来选区所选中的内容将从dom树上剥离出来
  4359. * @return { DocumentFragment } 返回包含所提取内容的DocumentFragment对象
  4360. * @example
  4361. * ```html
  4362. * <body>
  4363. * <!-- 中括号表示选区 -->
  4364. * <b>x<i>x[x</i>xx]x</b>
  4365. *
  4366. * <script>
  4367. * //range是已选中的选区
  4368. * var fragment = range.extractContents(),
  4369. * node = document.createElement( "div" );
  4370. *
  4371. * node.appendChild( fragment );
  4372. *
  4373. * //竖线表示闭合后的选区位置
  4374. *
  4375. * //output: <b>x<i>x</i>|x</b>
  4376. * console.log( document.body.innerHTML );
  4377. * //output: <i>x</i>xx
  4378. * console.log( node.innerHTML );
  4379. *
  4380. * //此时, range的各项属性为
  4381. * //output: B
  4382. * console.log( range.startContainer.tagName );
  4383. * //output: 2
  4384. * console.log( range.startOffset );
  4385. * //output: B
  4386. * console.log( range.endContainer.tagName );
  4387. * //output: 2
  4388. * console.log( range.endOffset );
  4389. * //output: true
  4390. * console.log( range.collapsed );
  4391. *
  4392. * </script>
  4393. * </body>
  4394. */
  4395. extractContents:function () {
  4396. return this.collapsed ? null : execContentsAction(this, 2);
  4397. },
  4398. /**
  4399. * 设置Range的开始容器节点和偏移量
  4400. * @method setStart
  4401. * @remind 如果给定的节点是元素节点,那么offset指的是其子元素中索引为offset的元素,
  4402. * 如果是文本节点,那么offset指的是其文本内容的第offset个字符
  4403. * @remind 如果提供的容器节点是一个不能包含子元素的节点, 则该选区的开始容器将被设置
  4404. * 为该节点的父节点, 此时, 其距离开始容器的偏移量也变成了该节点在其父节点
  4405. * 中的索引
  4406. * @param { Node } node 将被设为当前选区开始边界容器的节点对象
  4407. * @param { int } offset 选区的开始位置偏移量
  4408. * @return { UE.dom.Range } 当前range对象
  4409. * @example
  4410. * ```html
  4411. * <!-- 选区 -->
  4412. * <b>xxx<i>x<span>xx</span>xx<em>xx</em>xxx</i>[xxx]</b>
  4413. *
  4414. * <script>
  4415. *
  4416. * //执行操作
  4417. * range.setStart( document.getElementsByTagName("i")[0], 1 );
  4418. *
  4419. * //此时, 选区变成了
  4420. * //<b>xxx<i>x[<span>xx</span>xx<em>xx</em>xxx</i>xxx]</b>
  4421. *
  4422. * </script>
  4423. * ```
  4424. * @example
  4425. * ```html
  4426. * <!-- 选区 -->
  4427. * <b>xxx<img>[xx]x</b>
  4428. *
  4429. * <script>
  4430. *
  4431. * //执行操作
  4432. * range.setStart( document.getElementsByTagName("img")[0], 3 );
  4433. *
  4434. * //此时, 选区变成了
  4435. * //<b>xxx[<img>xx]x</b>
  4436. *
  4437. * </script>
  4438. * ```
  4439. */
  4440. setStart:function (node, offset) {
  4441. return setEndPoint(true, node, offset, this);
  4442. },
  4443. /**
  4444. * 设置Range的结束容器和偏移量
  4445. * @method setEnd
  4446. * @param { Node } node 作为当前选区结束边界容器的节点对象
  4447. * @param { int } offset 结束边界的偏移量
  4448. * @see UE.dom.Range:setStart(Node,int)
  4449. * @return { UE.dom.Range } 当前range对象
  4450. */
  4451. setEnd:function (node, offset) {
  4452. return setEndPoint(false, node, offset, this);
  4453. },
  4454. /**
  4455. * 将Range开始位置设置到node节点之后
  4456. * @method setStartAfter
  4457. * @remind 该操作将会把给定节点的父节点作为range的开始容器, 且偏移量是该节点在其父节点中的位置索引+1
  4458. * @param { Node } node 选区的开始边界将紧接着该节点之后
  4459. * @return { UE.dom.Range } 当前range对象
  4460. * @example
  4461. * ```html
  4462. * <!-- 选区示例 -->
  4463. * <b>xx<i>xxx</i><span>xx[x</span>xxx]</b>
  4464. *
  4465. * <script>
  4466. *
  4467. * //执行操作
  4468. * range.setStartAfter( document.getElementsByTagName("i")[0] );
  4469. *
  4470. * //结果选区
  4471. * //<b>xx<i>xxx</i>[<span>xxx</span>xxx]</b>
  4472. *
  4473. * </script>
  4474. * ```
  4475. */
  4476. setStartAfter:function (node) {
  4477. return this.setStart(node.parentNode, domUtils.getNodeIndex(node) + 1);
  4478. },
  4479. /**
  4480. * 将Range开始位置设置到node节点之前
  4481. * @method setStartBefore
  4482. * @remind 该操作将会把给定节点的父节点作为range的开始容器, 且偏移量是该节点在其父节点中的位置索引
  4483. * @param { Node } node 新的选区开始位置在该节点之前
  4484. * @see UE.dom.Range:setStartAfter(Node)
  4485. * @return { UE.dom.Range } 当前range对象
  4486. */
  4487. setStartBefore:function (node) {
  4488. return this.setStart(node.parentNode, domUtils.getNodeIndex(node));
  4489. },
  4490. /**
  4491. * 将Range结束位置设置到node节点之后
  4492. * @method setEndAfter
  4493. * @remind 该操作将会把给定节点的父节点作为range的结束容器, 且偏移量是该节点在其父节点中的位置索引+1
  4494. * @param { Node } node 目标节点
  4495. * @see UE.dom.Range:setStartAfter(Node)
  4496. * @return { UE.dom.Range } 当前range对象
  4497. * @example
  4498. * ```html
  4499. * <!-- 选区示例 -->
  4500. * <b>[xx<i>xxx</i><span>xx]x</span>xxx</b>
  4501. *
  4502. * <script>
  4503. *
  4504. * //执行操作
  4505. * range.setStartAfter( document.getElementsByTagName("span")[0] );
  4506. *
  4507. * //结果选区
  4508. * //<b>[xx<i>xxx</i><span>xxx</span>]xxx</b>
  4509. *
  4510. * </script>
  4511. * ```
  4512. */
  4513. setEndAfter:function (node) {
  4514. return this.setEnd(node.parentNode, domUtils.getNodeIndex(node) + 1);
  4515. },
  4516. /**
  4517. * 将Range结束位置设置到node节点之前
  4518. * @method setEndBefore
  4519. * @remind 该操作将会把给定节点的父节点作为range的结束容器, 且偏移量是该节点在其父节点中的位置索引
  4520. * @param { Node } node 目标节点
  4521. * @see UE.dom.Range:setEndAfter(Node)
  4522. * @return { UE.dom.Range } 当前range对象
  4523. */
  4524. setEndBefore:function (node) {
  4525. return this.setEnd(node.parentNode, domUtils.getNodeIndex(node));
  4526. },
  4527. /**
  4528. * 设置Range的开始位置到node节点内的第一个子节点之前
  4529. * @method setStartAtFirst
  4530. * @remind 选区的开始容器将变成给定的节点, 且偏移量为0
  4531. * @remind 如果给定的节点是元素节点, 则该节点必须是允许包含子节点的元素。
  4532. * @param { Node } node 目标节点
  4533. * @see UE.dom.Range:setStartBefore(Node)
  4534. * @return { UE.dom.Range } 当前range对象
  4535. * @example
  4536. * ```html
  4537. * <!-- 选区示例 -->
  4538. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  4539. *
  4540. * <script>
  4541. *
  4542. * //执行操作
  4543. * range.setStartAtFirst( document.getElementsByTagName("i")[0] );
  4544. *
  4545. * //结果选区
  4546. * //<b>xx<i>[xxx</i><span>xx]x</span>xxx</b>
  4547. *
  4548. * </script>
  4549. * ```
  4550. */
  4551. setStartAtFirst:function (node) {
  4552. return this.setStart(node, 0);
  4553. },
  4554. /**
  4555. * 设置Range的开始位置到node节点内的最后一个节点之后
  4556. * @method setStartAtLast
  4557. * @remind 选区的开始容器将变成给定的节点, 且偏移量为该节点的子节点数
  4558. * @remind 如果给定的节点是元素节点, 则该节点必须是允许包含子节点的元素。
  4559. * @param { Node } node 目标节点
  4560. * @see UE.dom.Range:setStartAtFirst(Node)
  4561. * @return { UE.dom.Range } 当前range对象
  4562. */
  4563. setStartAtLast:function (node) {
  4564. return this.setStart(node, node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length);
  4565. },
  4566. /**
  4567. * 设置Range的结束位置到node节点内的第一个节点之前
  4568. * @method setEndAtFirst
  4569. * @param { Node } node 目标节点
  4570. * @remind 选区的结束容器将变成给定的节点, 且偏移量为0
  4571. * @remind node必须是一个元素节点, 且必须是允许包含子节点的元素。
  4572. * @see UE.dom.Range:setStartAtFirst(Node)
  4573. * @return { UE.dom.Range } 当前range对象
  4574. */
  4575. setEndAtFirst:function (node) {
  4576. return this.setEnd(node, 0);
  4577. },
  4578. /**
  4579. * 设置Range的结束位置到node节点内的最后一个节点之后
  4580. * @method setEndAtLast
  4581. * @param { Node } node 目标节点
  4582. * @remind 选区的结束容器将变成给定的节点, 且偏移量为该节点的子节点数量
  4583. * @remind node必须是一个元素节点, 且必须是允许包含子节点的元素。
  4584. * @see UE.dom.Range:setStartAtFirst(Node)
  4585. * @return { UE.dom.Range } 当前range对象
  4586. */
  4587. setEndAtLast:function (node) {
  4588. return this.setEnd(node, node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length);
  4589. },
  4590. /**
  4591. * 选中给定节点
  4592. * @method selectNode
  4593. * @remind 此时, 选区的开始容器和结束容器都是该节点的父节点, 其startOffset是该节点在父节点中的位置索引,
  4594. * 而endOffset为startOffset+1
  4595. * @param { Node } node 需要选中的节点
  4596. * @return { UE.dom.Range } 当前range对象,此时的range仅包含当前给定的节点对象
  4597. * @example
  4598. * ```html
  4599. * <!-- 选区示例 -->
  4600. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  4601. *
  4602. * <script>
  4603. *
  4604. * //执行操作
  4605. * range.selectNode( document.getElementsByTagName("i")[0] );
  4606. *
  4607. * //结果选区
  4608. * //<b>xx[<i>xxx</i>]<span>xxx</span>xxx</b>
  4609. *
  4610. * </script>
  4611. * ```
  4612. */
  4613. selectNode:function (node) {
  4614. return this.setStartBefore(node).setEndAfter(node);
  4615. },
  4616. /**
  4617. * 选中给定节点内部的所有节点
  4618. * @method selectNodeContents
  4619. * @remind 此时, 选区的开始容器和结束容器都是该节点, 其startOffset为0,
  4620. * 而endOffset是该节点的子节点数。
  4621. * @param { Node } node 目标节点, 当前range将包含该节点内的所有节点
  4622. * @return { UE.dom.Range } 当前range对象, 此时range仅包含给定节点的所有子节点
  4623. * @example
  4624. * ```html
  4625. * <!-- 选区示例 -->
  4626. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  4627. *
  4628. * <script>
  4629. *
  4630. * //执行操作
  4631. * range.selectNode( document.getElementsByTagName("b")[0] );
  4632. *
  4633. * //结果选区
  4634. * //<b>[xx<i>xxx</i><span>xxx</span>xxx]</b>
  4635. *
  4636. * </script>
  4637. * ```
  4638. */
  4639. selectNodeContents:function (node) {
  4640. return this.setStart(node, 0).setEndAtLast(node);
  4641. },
  4642. /**
  4643. * clone当前Range对象
  4644. * @method cloneRange
  4645. * @remind 返回的range是一个全新的range对象, 其内部所有属性与当前被clone的range相同。
  4646. * @return { UE.dom.Range } 当前range对象的一个副本
  4647. */
  4648. cloneRange:function () {
  4649. var me = this;
  4650. return new Range(me.document).setStart(me.startContainer, me.startOffset).setEnd(me.endContainer, me.endOffset);
  4651. },
  4652. /**
  4653. * 向当前选区的结束处闭合选区
  4654. * @method collapse
  4655. * @return { UE.dom.Range } 当前range对象
  4656. * @example
  4657. * ```html
  4658. * <!-- 选区示例 -->
  4659. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  4660. *
  4661. * <script>
  4662. *
  4663. * //执行操作
  4664. * range.collapse();
  4665. *
  4666. * //结果选区
  4667. * //“|”表示选区已闭合
  4668. * //<b>xx<i>xxx</i><span>xx|x</span>xxx</b>
  4669. *
  4670. * </script>
  4671. * ```
  4672. */
  4673. /**
  4674. * 闭合当前选区,根据给定的toStart参数项决定是向当前选区开始处闭合还是向结束处闭合,
  4675. * 如果toStart的值为true,则向开始位置闭合, 反之,向结束位置闭合。
  4676. * @method collapse
  4677. * @param { Boolean } toStart 是否向选区开始处闭合
  4678. * @return { UE.dom.Range } 当前range对象,此时range对象处于闭合状态
  4679. * @see UE.dom.Range:collapse()
  4680. * @example
  4681. * ```html
  4682. * <!-- 选区示例 -->
  4683. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  4684. *
  4685. * <script>
  4686. *
  4687. * //执行操作
  4688. * range.collapse( true );
  4689. *
  4690. * //结果选区
  4691. * //“|”表示选区已闭合
  4692. * //<b>xx<i>xxx</i><span>|xxx</span>xxx</b>
  4693. *
  4694. * </script>
  4695. * ```
  4696. */
  4697. collapse:function (toStart) {
  4698. var me = this;
  4699. if (toStart) {
  4700. me.endContainer = me.startContainer;
  4701. me.endOffset = me.startOffset;
  4702. } else {
  4703. me.startContainer = me.endContainer;
  4704. me.startOffset = me.endOffset;
  4705. }
  4706. me.collapsed = true;
  4707. return me;
  4708. },
  4709. /**
  4710. * 调整range的开始位置和结束位置,使其"收缩"到最小的位置
  4711. * @method shrinkBoundary
  4712. * @return { UE.dom.Range } 当前range对象
  4713. * @example
  4714. * ```html
  4715. * <span>xx<b>xx[</b>xxxxx]</span> => <span>xx<b>xx</b>[xxxxx]</span>
  4716. * ```
  4717. *
  4718. * @example
  4719. * ```html
  4720. * <!-- 选区示例 -->
  4721. * <b>x[xx</b><i>]xxx</i>
  4722. *
  4723. * <script>
  4724. *
  4725. * //执行收缩
  4726. * range.shrinkBoundary();
  4727. *
  4728. * //结果选区
  4729. * //<b>x[xx]</b><i>xxx</i>
  4730. * </script>
  4731. * ```
  4732. *
  4733. * @example
  4734. * ```html
  4735. * [<b><i>xxxx</i>xxxxxxx</b>] => <b><i>[xxxx</i>xxxxxxx]</b>
  4736. * ```
  4737. */
  4738. /**
  4739. * 调整range的开始位置和结束位置,使其"收缩"到最小的位置,
  4740. * 如果ignoreEnd的值为true,则忽略对结束位置的调整
  4741. * @method shrinkBoundary
  4742. * @param { Boolean } ignoreEnd 是否忽略对结束位置的调整
  4743. * @return { UE.dom.Range } 当前range对象
  4744. * @see UE.dom.domUtils.Range:shrinkBoundary()
  4745. */
  4746. shrinkBoundary:function (ignoreEnd) {
  4747. var me = this, child,
  4748. collapsed = me.collapsed;
  4749. function check(node){
  4750. return node.nodeType == 1 && !domUtils.isBookmarkNode(node) && !dtd.$empty[node.tagName] && !dtd.$nonChild[node.tagName]
  4751. }
  4752. while (me.startContainer.nodeType == 1 //是element
  4753. && (child = me.startContainer.childNodes[me.startOffset]) //子节点也是element
  4754. && check(child)) {
  4755. me.setStart(child, 0);
  4756. }
  4757. if (collapsed) {
  4758. return me.collapse(true);
  4759. }
  4760. if (!ignoreEnd) {
  4761. while (me.endContainer.nodeType == 1//是element
  4762. && me.endOffset > 0 //如果是空元素就退出 endOffset=0那么endOffst-1为负值,childNodes[endOffset]报错
  4763. && (child = me.endContainer.childNodes[me.endOffset - 1]) //子节点也是element
  4764. && check(child)) {
  4765. me.setEnd(child, child.childNodes.length);
  4766. }
  4767. }
  4768. return me;
  4769. },
  4770. /**
  4771. * 获取离当前选区内包含的所有节点最近的公共祖先节点,
  4772. * @method getCommonAncestor
  4773. * @remind 返回的公共祖先节点一定不是range自身的容器节点, 但有可能是一个文本节点
  4774. * @return { Node } 当前range对象内所有节点的公共祖先节点
  4775. * @example
  4776. * ```html
  4777. * //选区示例
  4778. * <span>xxx<b>x[x<em>xx]x</em>xxx</b>xx</span>
  4779. * <script>
  4780. *
  4781. * var node = range.getCommonAncestor();
  4782. *
  4783. * //公共祖先节点是: b节点
  4784. * //输出: B
  4785. * console.log(node.tagName);
  4786. *
  4787. * </script>
  4788. * ```
  4789. */
  4790. /**
  4791. * 获取当前选区所包含的所有节点的公共祖先节点, 可以根据给定的参数 includeSelf 决定获取到
  4792. * 的公共祖先节点是否可以是当前选区的startContainer或endContainer节点, 如果 includeSelf
  4793. * 的取值为true, 则返回的节点可以是自身的容器节点, 否则, 则不能是容器节点
  4794. * @method getCommonAncestor
  4795. * @param { Boolean } includeSelf 是否允许获取到的公共祖先节点是当前range对象的容器节点
  4796. * @return { Node } 当前range对象内所有节点的公共祖先节点
  4797. * @see UE.dom.Range:getCommonAncestor()
  4798. * @example
  4799. * ```html
  4800. * <body>
  4801. *
  4802. * <!-- 选区示例 -->
  4803. * <b>xxx<i>xxxx<span>xx[x</span>xx]x</i>xxxxxxx</b>
  4804. *
  4805. * <script>
  4806. *
  4807. * var node = range.getCommonAncestor( false );
  4808. *
  4809. * //这里的公共祖先节点是B而不是I, 是因为参数限制了获取到的节点不能是容器节点
  4810. * //output: B
  4811. * console.log( node.tagName );
  4812. *
  4813. * </script>
  4814. *
  4815. * </body>
  4816. * ```
  4817. */
  4818. /**
  4819. * 获取当前选区所包含的所有节点的公共祖先节点, 可以根据给定的参数 includeSelf 决定获取到
  4820. * 的公共祖先节点是否可以是当前选区的startContainer或endContainer节点, 如果 includeSelf
  4821. * 的取值为true, 则返回的节点可以是自身的容器节点, 否则, 则不能是容器节点; 同时可以根据
  4822. * ignoreTextNode 参数的取值决定是否忽略类型为文本节点的祖先节点。
  4823. * @method getCommonAncestor
  4824. * @param { Boolean } includeSelf 是否允许获取到的公共祖先节点是当前range对象的容器节点
  4825. * @param { Boolean } ignoreTextNode 获取祖先节点的过程中是否忽略类型为文本节点的祖先节点
  4826. * @return { Node } 当前range对象内所有节点的公共祖先节点
  4827. * @see UE.dom.Range:getCommonAncestor()
  4828. * @see UE.dom.Range:getCommonAncestor(Boolean)
  4829. * @example
  4830. * ```html
  4831. * <body>
  4832. *
  4833. * <!-- 选区示例 -->
  4834. * <b>xxx<i>xxxx<span>x[x]x</span>xxx</i>xxxxxxx</b>
  4835. *
  4836. * <script>
  4837. *
  4838. * var node = range.getCommonAncestor( true, false );
  4839. *
  4840. * //output: SPAN
  4841. * console.log( node.tagName );
  4842. *
  4843. * </script>
  4844. *
  4845. * </body>
  4846. * ```
  4847. */
  4848. getCommonAncestor:function (includeSelf, ignoreTextNode) {
  4849. var me = this,
  4850. start = me.startContainer,
  4851. end = me.endContainer;
  4852. if (start === end) {
  4853. if (includeSelf && selectOneNode(this)) {
  4854. start = start.childNodes[me.startOffset];
  4855. if(start.nodeType == 1)
  4856. return start;
  4857. }
  4858. //只有在上来就相等的情况下才会出现是文本的情况
  4859. return ignoreTextNode && start.nodeType == 3 ? start.parentNode : start;
  4860. }
  4861. return domUtils.getCommonAncestor(start, end);
  4862. },
  4863. /**
  4864. * 调整当前Range的开始和结束边界容器,如果是容器节点是文本节点,就调整到包含该文本节点的父节点上
  4865. * @method trimBoundary
  4866. * @remind 该操作有可能会引起文本节点被切开
  4867. * @return { UE.dom.Range } 当前range对象
  4868. * @example
  4869. * ```html
  4870. *
  4871. * //选区示例
  4872. * <b>xxx<i>[xxxxx]</i>xxx</b>
  4873. *
  4874. * <script>
  4875. * //未调整前, 选区的开始容器和结束都是文本节点
  4876. * //执行调整
  4877. * range.trimBoundary();
  4878. *
  4879. * //调整之后, 容器节点变成了i节点
  4880. * //<b>xxx[<i>xxxxx</i>]xxx</b>
  4881. * </script>
  4882. * ```
  4883. */
  4884. /**
  4885. * 调整当前Range的开始和结束边界容器,如果是容器节点是文本节点,就调整到包含该文本节点的父节点上,
  4886. * 可以根据 ignoreEnd 参数的值决定是否调整对结束边界的调整
  4887. * @method trimBoundary
  4888. * @param { Boolean } ignoreEnd 是否忽略对结束边界的调整
  4889. * @return { UE.dom.Range } 当前range对象
  4890. * @example
  4891. * ```html
  4892. *
  4893. * //选区示例
  4894. * <b>xxx<i>[xxxxx]</i>xxx</b>
  4895. *
  4896. * <script>
  4897. * //未调整前, 选区的开始容器和结束都是文本节点
  4898. * //执行调整
  4899. * range.trimBoundary( true );
  4900. *
  4901. * //调整之后, 开始容器节点变成了i节点
  4902. * //但是, 结束容器没有发生变化
  4903. * //<b>xxx[<i>xxxxx]</i>xxx</b>
  4904. * </script>
  4905. * ```
  4906. */
  4907. trimBoundary:function (ignoreEnd) {
  4908. this.txtToElmBoundary();
  4909. var start = this.startContainer,
  4910. offset = this.startOffset,
  4911. collapsed = this.collapsed,
  4912. end = this.endContainer;
  4913. if (start.nodeType == 3) {
  4914. if (offset == 0) {
  4915. this.setStartBefore(start);
  4916. } else {
  4917. if (offset >= start.nodeValue.length) {
  4918. this.setStartAfter(start);
  4919. } else {
  4920. var textNode = domUtils.split(start, offset);
  4921. //跟新结束边界
  4922. if (start === end) {
  4923. this.setEnd(textNode, this.endOffset - offset);
  4924. } else if (start.parentNode === end) {
  4925. this.endOffset += 1;
  4926. }
  4927. this.setStartBefore(textNode);
  4928. }
  4929. }
  4930. if (collapsed) {
  4931. return this.collapse(true);
  4932. }
  4933. }
  4934. if (!ignoreEnd) {
  4935. offset = this.endOffset;
  4936. end = this.endContainer;
  4937. if (end.nodeType == 3) {
  4938. if (offset == 0) {
  4939. this.setEndBefore(end);
  4940. } else {
  4941. offset < end.nodeValue.length && domUtils.split(end, offset);
  4942. this.setEndAfter(end);
  4943. }
  4944. }
  4945. }
  4946. return this;
  4947. },
  4948. /**
  4949. * 如果选区在文本的边界上,就扩展选区到文本的父节点上, 如果当前选区是闭合的, 则什么也不做
  4950. * @method txtToElmBoundary
  4951. * @remind 该操作不会修改dom节点
  4952. * @return { UE.dom.Range } 当前range对象
  4953. */
  4954. /**
  4955. * 如果选区在文本的边界上,就扩展选区到文本的父节点上, 如果当前选区是闭合的, 则根据参数项
  4956. * ignoreCollapsed 的值决定是否执行该调整
  4957. * @method txtToElmBoundary
  4958. * @param { Boolean } ignoreCollapsed 是否忽略选区的闭合状态, 如果该参数取值为true, 则
  4959. * 不论选区是否闭合, 都会执行该操作, 反之, 则不会对闭合的选区执行该操作
  4960. * @return { UE.dom.Range } 当前range对象
  4961. */
  4962. txtToElmBoundary:function (ignoreCollapsed) {
  4963. function adjust(r, c) {
  4964. var container = r[c + 'Container'],
  4965. offset = r[c + 'Offset'];
  4966. if (container.nodeType == 3) {
  4967. if (!offset) {
  4968. r['set' + c.replace(/(\w)/, function (a) {
  4969. return a.toUpperCase();
  4970. }) + 'Before'](container);
  4971. } else if (offset >= container.nodeValue.length) {
  4972. r['set' + c.replace(/(\w)/, function (a) {
  4973. return a.toUpperCase();
  4974. }) + 'After' ](container);
  4975. }
  4976. }
  4977. }
  4978. if (ignoreCollapsed || !this.collapsed) {
  4979. adjust(this, 'start');
  4980. adjust(this, 'end');
  4981. }
  4982. return this;
  4983. },
  4984. /**
  4985. * 在当前选区的开始位置前插入节点,新插入的节点会被该range包含
  4986. * @method insertNode
  4987. * @param { Node } node 需要插入的节点
  4988. * @remind 插入的节点可以是一个DocumentFragment依次插入多个节点
  4989. * @return { UE.dom.Range } 当前range对象
  4990. */
  4991. insertNode:function (node) {
  4992. var first = node, length = 1;
  4993. if (node.nodeType == 11) {
  4994. first = node.firstChild;
  4995. length = node.childNodes.length;
  4996. }
  4997. this.trimBoundary(true);
  4998. var start = this.startContainer,
  4999. offset = this.startOffset;
  5000. var nextNode = start.childNodes[ offset ];
  5001. if (nextNode) {
  5002. start.insertBefore(node, nextNode);
  5003. } else {
  5004. start.appendChild(node);
  5005. }
  5006. if (first.parentNode === this.endContainer) {
  5007. this.endOffset = this.endOffset + length;
  5008. }
  5009. return this.setStartBefore(first);
  5010. },
  5011. /**
  5012. * 闭合选区到当前选区的开始位置, 并且定位光标到闭合后的位置
  5013. * @method setCursor
  5014. * @return { UE.dom.Range } 当前range对象
  5015. * @see UE.dom.Range:collapse()
  5016. */
  5017. /**
  5018. * 闭合选区,可以根据参数toEnd的值控制选区是向前闭合还是向后闭合, 并且定位光标到闭合后的位置。
  5019. * @method setCursor
  5020. * @param { Boolean } toEnd 是否向后闭合, 如果为true, 则闭合选区时, 将向结束容器方向闭合,
  5021. * 反之,则向开始容器方向闭合
  5022. * @return { UE.dom.Range } 当前range对象
  5023. * @see UE.dom.Range:collapse(Boolean)
  5024. */
  5025. setCursor:function (toEnd, noFillData) {
  5026. return this.collapse(!toEnd).select(noFillData);
  5027. },
  5028. /**
  5029. * 创建当前range的一个书签,记录下当前range的位置,方便当dom树改变时,还能找回原来的选区位置
  5030. * @method createBookmark
  5031. * @param { Boolean } serialize 控制返回的标记位置是对当前位置的引用还是ID,如果该值为true,则
  5032. * 返回标记位置的ID, 反之则返回标记位置节点的引用
  5033. * @return { Object } 返回一个书签记录键值对, 其包含的key有: start => 开始标记的ID或者引用,
  5034. * end => 结束标记的ID或引用, id => 当前标记的类型, 如果为true,则表示
  5035. * 返回的记录的类型为ID, 反之则为引用
  5036. */
  5037. createBookmark:function (serialize, same) {
  5038. var endNode,
  5039. startNode = this.document.createElement('span');
  5040. startNode.style.cssText = 'display:none;line-height:0px;';
  5041. startNode.appendChild(this.document.createTextNode('\u200D'));
  5042. startNode.id = '_baidu_bookmark_start_' + (same ? '' : guid++);
  5043. if (!this.collapsed) {
  5044. endNode = startNode.cloneNode(true);
  5045. endNode.id = '_baidu_bookmark_end_' + (same ? '' : guid++);
  5046. }
  5047. this.insertNode(startNode);
  5048. if (endNode) {
  5049. this.collapse().insertNode(endNode).setEndBefore(endNode);
  5050. }
  5051. this.setStartAfter(startNode);
  5052. return {
  5053. start:serialize ? startNode.id : startNode,
  5054. end:endNode ? serialize ? endNode.id : endNode : null,
  5055. id:serialize
  5056. }
  5057. },
  5058. /**
  5059. * 调整当前range的边界到书签位置,并删除该书签对象所标记的位置内的节点
  5060. * @method moveToBookmark
  5061. * @param { BookMark } bookmark createBookmark所创建的标签对象
  5062. * @return { UE.dom.Range } 当前range对象
  5063. * @see UE.dom.Range:createBookmark(Boolean)
  5064. */
  5065. moveToBookmark:function (bookmark) {
  5066. var start = bookmark.id ? this.document.getElementById(bookmark.start) : bookmark.start,
  5067. end = bookmark.end && bookmark.id ? this.document.getElementById(bookmark.end) : bookmark.end;
  5068. this.setStartBefore(start);
  5069. domUtils.remove(start);
  5070. if (end) {
  5071. this.setEndBefore(end);
  5072. domUtils.remove(end);
  5073. } else {
  5074. this.collapse(true);
  5075. }
  5076. return this;
  5077. },
  5078. /**
  5079. * 调整range的边界,使其"放大"到最近的父节点
  5080. * @method enlarge
  5081. * @remind 会引起选区的变化
  5082. * @return { UE.dom.Range } 当前range对象
  5083. */
  5084. /**
  5085. * 调整range的边界,使其"放大"到最近的父节点,根据参数 toBlock 的取值, 可以
  5086. * 要求扩大之后的父节点是block节点
  5087. * @method enlarge
  5088. * @param { Boolean } toBlock 是否要求扩大之后的父节点必须是block节点
  5089. * @return { UE.dom.Range } 当前range对象
  5090. */
  5091. enlarge:function (toBlock, stopFn) {
  5092. var isBody = domUtils.isBody,
  5093. pre, node, tmp = this.document.createTextNode('');
  5094. if (toBlock) {
  5095. node = this.startContainer;
  5096. if (node.nodeType == 1) {
  5097. if (node.childNodes[this.startOffset]) {
  5098. pre = node = node.childNodes[this.startOffset]
  5099. } else {
  5100. node.appendChild(tmp);
  5101. pre = node = tmp;
  5102. }
  5103. } else {
  5104. pre = node;
  5105. }
  5106. while (1) {
  5107. if (domUtils.isBlockElm(node)) {
  5108. node = pre;
  5109. while ((pre = node.previousSibling) && !domUtils.isBlockElm(pre)) {
  5110. node = pre;
  5111. }
  5112. this.setStartBefore(node);
  5113. break;
  5114. }
  5115. pre = node;
  5116. node = node.parentNode;
  5117. }
  5118. node = this.endContainer;
  5119. if (node.nodeType == 1) {
  5120. if (pre = node.childNodes[this.endOffset]) {
  5121. node.insertBefore(tmp, pre);
  5122. } else {
  5123. node.appendChild(tmp);
  5124. }
  5125. pre = node = tmp;
  5126. } else {
  5127. pre = node;
  5128. }
  5129. while (1) {
  5130. if (domUtils.isBlockElm(node)) {
  5131. node = pre;
  5132. while ((pre = node.nextSibling) && !domUtils.isBlockElm(pre)) {
  5133. node = pre;
  5134. }
  5135. this.setEndAfter(node);
  5136. break;
  5137. }
  5138. pre = node;
  5139. node = node.parentNode;
  5140. }
  5141. if (tmp.parentNode === this.endContainer) {
  5142. this.endOffset--;
  5143. }
  5144. domUtils.remove(tmp);
  5145. }
  5146. // 扩展边界到最大
  5147. if (!this.collapsed) {
  5148. while (this.startOffset == 0) {
  5149. if (stopFn && stopFn(this.startContainer)) {
  5150. break;
  5151. }
  5152. if (isBody(this.startContainer)) {
  5153. break;
  5154. }
  5155. this.setStartBefore(this.startContainer);
  5156. }
  5157. while (this.endOffset == (this.endContainer.nodeType == 1 ? this.endContainer.childNodes.length : this.endContainer.nodeValue.length)) {
  5158. if (stopFn && stopFn(this.endContainer)) {
  5159. break;
  5160. }
  5161. if (isBody(this.endContainer)) {
  5162. break;
  5163. }
  5164. this.setEndAfter(this.endContainer);
  5165. }
  5166. }
  5167. return this;
  5168. },
  5169. enlargeToBlockElm:function(ignoreEnd){
  5170. while(!domUtils.isBlockElm(this.startContainer)){
  5171. this.setStartBefore(this.startContainer);
  5172. }
  5173. if(!ignoreEnd){
  5174. while(!domUtils.isBlockElm(this.endContainer)){
  5175. this.setEndAfter(this.endContainer);
  5176. }
  5177. }
  5178. return this;
  5179. },
  5180. /**
  5181. * 调整Range的边界,使其"缩小"到最合适的位置
  5182. * @method adjustmentBoundary
  5183. * @return { UE.dom.Range } 当前range对象
  5184. * @see UE.dom.Range:shrinkBoundary()
  5185. */
  5186. adjustmentBoundary:function () {
  5187. if (!this.collapsed) {
  5188. while (!domUtils.isBody(this.startContainer) &&
  5189. this.startOffset == this.startContainer[this.startContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length &&
  5190. this.startContainer[this.startContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length
  5191. ) {
  5192. this.setStartAfter(this.startContainer);
  5193. }
  5194. while (!domUtils.isBody(this.endContainer) && !this.endOffset &&
  5195. this.endContainer[this.endContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length
  5196. ) {
  5197. this.setEndBefore(this.endContainer);
  5198. }
  5199. }
  5200. return this;
  5201. },
  5202. /**
  5203. * 给range选区中的内容添加给定的inline标签
  5204. * @method applyInlineStyle
  5205. * @param { String } tagName 需要添加的标签名
  5206. * @example
  5207. * ```html
  5208. * <p>xxxx[xxxx]x</p> ==> range.applyInlineStyle("strong") ==> <p>xxxx[<strong>xxxx</strong>]x</p>
  5209. * ```
  5210. */
  5211. /**
  5212. * 给range选区中的内容添加给定的inline标签, 并且为标签附加上一些初始化属性。
  5213. * @method applyInlineStyle
  5214. * @param { String } tagName 需要添加的标签名
  5215. * @param { Object } attrs 跟随新添加的标签的属性
  5216. * @return { UE.dom.Range } 当前选区
  5217. * @example
  5218. * ```html
  5219. * <p>xxxx[xxxx]x</p>
  5220. *
  5221. * ==>
  5222. *
  5223. * <!-- 执行操作 -->
  5224. * range.applyInlineStyle("strong",{"style":"font-size:12px"})
  5225. *
  5226. * ==>
  5227. *
  5228. * <p>xxxx[<strong style="font-size:12px">xxxx</strong>]x</p>
  5229. * ```
  5230. */
  5231. applyInlineStyle:function (tagName, attrs, list) {
  5232. if (this.collapsed)return this;
  5233. this.trimBoundary().enlarge(false,
  5234. function (node) {
  5235. return node.nodeType == 1 && domUtils.isBlockElm(node)
  5236. }).adjustmentBoundary();
  5237. var bookmark = this.createBookmark(),
  5238. end = bookmark.end,
  5239. filterFn = function (node) {
  5240. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' : !domUtils.isWhitespace(node);
  5241. },
  5242. current = domUtils.getNextDomNode(bookmark.start, false, filterFn),
  5243. node,
  5244. pre,
  5245. range = this.cloneRange();
  5246. while (current && (domUtils.getPosition(current, end) & domUtils.POSITION_PRECEDING)) {
  5247. if (current.nodeType == 3 || dtd[tagName][current.tagName]) {
  5248. range.setStartBefore(current);
  5249. node = current;
  5250. while (node && (node.nodeType == 3 || dtd[tagName][node.tagName]) && node !== end) {
  5251. pre = node;
  5252. node = domUtils.getNextDomNode(node, node.nodeType == 1, null, function (parent) {
  5253. return dtd[tagName][parent.tagName];
  5254. });
  5255. }
  5256. var frag = range.setEndAfter(pre).extractContents(), elm;
  5257. if (list && list.length > 0) {
  5258. var level, top;
  5259. top = level = list[0].cloneNode(false);
  5260. for (var i = 1, ci; ci = list[i++];) {
  5261. level.appendChild(ci.cloneNode(false));
  5262. level = level.firstChild;
  5263. }
  5264. elm = level;
  5265. } else {
  5266. elm = range.document.createElement(tagName);
  5267. }
  5268. if (attrs) {
  5269. domUtils.setAttributes(elm, attrs);
  5270. }
  5271. elm.appendChild(frag);
  5272. range.insertNode(list ? top : elm);
  5273. //处理下滑线在a上的情况
  5274. var aNode;
  5275. if (tagName == 'span' && attrs.style && /text\-decoration/.test(attrs.style) && (aNode = domUtils.findParentByTagName(elm, 'a', true))) {
  5276. domUtils.setAttributes(aNode, attrs);
  5277. domUtils.remove(elm, true);
  5278. elm = aNode;
  5279. } else {
  5280. domUtils.mergeSibling(elm);
  5281. domUtils.clearEmptySibling(elm);
  5282. }
  5283. //去除子节点相同的
  5284. domUtils.mergeChild(elm, attrs);
  5285. current = domUtils.getNextDomNode(elm, false, filterFn);
  5286. domUtils.mergeToParent(elm);
  5287. if (node === end) {
  5288. break;
  5289. }
  5290. } else {
  5291. current = domUtils.getNextDomNode(current, true, filterFn);
  5292. }
  5293. }
  5294. return this.moveToBookmark(bookmark);
  5295. },
  5296. /**
  5297. * 移除当前选区内指定的inline标签,但保留其中的内容
  5298. * @method removeInlineStyle
  5299. * @param { String } tagName 需要移除的标签名
  5300. * @return { UE.dom.Range } 当前的range对象
  5301. * @example
  5302. * ```html
  5303. * xx[x<span>xxx<em>yyy</em>zz]z</span> => range.removeInlineStyle(["em"]) => xx[x<span>xxxyyyzz]z</span>
  5304. * ```
  5305. */
  5306. /**
  5307. * 移除当前选区内指定的一组inline标签,但保留其中的内容
  5308. * @method removeInlineStyle
  5309. * @param { Array } tagNameArr 需要移除的标签名的数组
  5310. * @return { UE.dom.Range } 当前的range对象
  5311. * @see UE.dom.Range:removeInlineStyle(String)
  5312. */
  5313. removeInlineStyle:function (tagNames) {
  5314. if (this.collapsed)return this;
  5315. tagNames = utils.isArray(tagNames) ? tagNames : [tagNames];
  5316. this.shrinkBoundary().adjustmentBoundary();
  5317. var start = this.startContainer, end = this.endContainer;
  5318. while (1) {
  5319. if (start.nodeType == 1) {
  5320. if (utils.indexOf(tagNames, start.tagName.toLowerCase()) > -1) {
  5321. break;
  5322. }
  5323. if (start.tagName.toLowerCase() == 'body') {
  5324. start = null;
  5325. break;
  5326. }
  5327. }
  5328. start = start.parentNode;
  5329. }
  5330. while (1) {
  5331. if (end.nodeType == 1) {
  5332. if (utils.indexOf(tagNames, end.tagName.toLowerCase()) > -1) {
  5333. break;
  5334. }
  5335. if (end.tagName.toLowerCase() == 'body') {
  5336. end = null;
  5337. break;
  5338. }
  5339. }
  5340. end = end.parentNode;
  5341. }
  5342. var bookmark = this.createBookmark(),
  5343. frag,
  5344. tmpRange;
  5345. if (start) {
  5346. tmpRange = this.cloneRange().setEndBefore(bookmark.start).setStartBefore(start);
  5347. frag = tmpRange.extractContents();
  5348. tmpRange.insertNode(frag);
  5349. domUtils.clearEmptySibling(start, true);
  5350. start.parentNode.insertBefore(bookmark.start, start);
  5351. }
  5352. if (end) {
  5353. tmpRange = this.cloneRange().setStartAfter(bookmark.end).setEndAfter(end);
  5354. frag = tmpRange.extractContents();
  5355. tmpRange.insertNode(frag);
  5356. domUtils.clearEmptySibling(end, false, true);
  5357. end.parentNode.insertBefore(bookmark.end, end.nextSibling);
  5358. }
  5359. var current = domUtils.getNextDomNode(bookmark.start, false, function (node) {
  5360. return node.nodeType == 1;
  5361. }), next;
  5362. while (current && current !== bookmark.end) {
  5363. next = domUtils.getNextDomNode(current, true, function (node) {
  5364. return node.nodeType == 1;
  5365. });
  5366. if (utils.indexOf(tagNames, current.tagName.toLowerCase()) > -1) {
  5367. domUtils.remove(current, true);
  5368. }
  5369. current = next;
  5370. }
  5371. return this.moveToBookmark(bookmark);
  5372. },
  5373. /**
  5374. * 获取当前选中的自闭合的节点
  5375. * @method getClosedNode
  5376. * @return { Node | NULL } 如果当前选中的是自闭合节点, 则返回该节点, 否则返回NULL
  5377. */
  5378. getClosedNode:function () {
  5379. var node;
  5380. if (!this.collapsed) {
  5381. var range = this.cloneRange().adjustmentBoundary().shrinkBoundary();
  5382. if (selectOneNode(range)) {
  5383. var child = range.startContainer.childNodes[range.startOffset];
  5384. if (child && child.nodeType == 1 && (dtd.$empty[child.tagName] || dtd.$nonChild[child.tagName])) {
  5385. node = child;
  5386. }
  5387. }
  5388. }
  5389. return node;
  5390. },
  5391. /**
  5392. * 在页面上高亮range所表示的选区
  5393. * @method select
  5394. * @return { UE.dom.Range } 返回当前Range对象
  5395. */
  5396. //这里不区分ie9以上,trace:3824
  5397. select:browser.ie ? function (noFillData, textRange) {
  5398. var nativeRange;
  5399. if (!this.collapsed)
  5400. this.shrinkBoundary();
  5401. var node = this.getClosedNode();
  5402. if (node && !textRange) {
  5403. try {
  5404. nativeRange = this.document.body.createControlRange();
  5405. nativeRange.addElement(node);
  5406. nativeRange.select();
  5407. } catch (e) {}
  5408. return this;
  5409. }
  5410. var bookmark = this.createBookmark(),
  5411. start = bookmark.start,
  5412. end;
  5413. nativeRange = this.document.body.createTextRange();
  5414. nativeRange.moveToElementText(start);
  5415. nativeRange.moveStart('character', 1);
  5416. if (!this.collapsed) {
  5417. var nativeRangeEnd = this.document.body.createTextRange();
  5418. end = bookmark.end;
  5419. nativeRangeEnd.moveToElementText(end);
  5420. nativeRange.setEndPoint('EndToEnd', nativeRangeEnd);
  5421. } else {
  5422. if (!noFillData && this.startContainer.nodeType != 3) {
  5423. //使用<span>|x<span>固定住光标
  5424. var tmpText = this.document.createTextNode(fillChar),
  5425. tmp = this.document.createElement('span');
  5426. tmp.appendChild(this.document.createTextNode(fillChar));
  5427. start.parentNode.insertBefore(tmp, start);
  5428. start.parentNode.insertBefore(tmpText, start);
  5429. //当点b,i,u时,不能清除i上边的b
  5430. removeFillData(this.document, tmpText);
  5431. fillData = tmpText;
  5432. mergeSibling(tmp, 'previousSibling');
  5433. mergeSibling(start, 'nextSibling');
  5434. nativeRange.moveStart('character', -1);
  5435. nativeRange.collapse(true);
  5436. }
  5437. }
  5438. this.moveToBookmark(bookmark);
  5439. tmp && domUtils.remove(tmp);
  5440. //IE在隐藏状态下不支持range操作,catch一下
  5441. try {
  5442. nativeRange.select();
  5443. } catch (e) {
  5444. }
  5445. return this;
  5446. } : function (notInsertFillData) {
  5447. function checkOffset(rng){
  5448. function check(node,offset,dir){
  5449. if(node.nodeType == 3 && node.nodeValue.length < offset){
  5450. rng[dir + 'Offset'] = node.nodeValue.length
  5451. }
  5452. }
  5453. check(rng.startContainer,rng.startOffset,'start');
  5454. check(rng.endContainer,rng.endOffset,'end');
  5455. }
  5456. var win = domUtils.getWindow(this.document),
  5457. sel = win.getSelection(),
  5458. txtNode;
  5459. //FF下关闭自动长高时滚动条在关闭dialog时会跳
  5460. //ff下如果不body.focus将不能定位闭合光标到编辑器内
  5461. browser.gecko ? this.document.body.focus() : win.focus();
  5462. if (sel) {
  5463. sel.removeAllRanges();
  5464. // trace:870 chrome/safari后边是br对于闭合得range不能定位 所以去掉了判断
  5465. // this.startContainer.nodeType != 3 &&! ((child = this.startContainer.childNodes[this.startOffset]) && child.nodeType == 1 && child.tagName == 'BR'
  5466. if (this.collapsed && !notInsertFillData) {
  5467. // //opear如果没有节点接着,原生的不能够定位,不能在body的第一级插入空白节点
  5468. // if (notInsertFillData && browser.opera && !domUtils.isBody(this.startContainer) && this.startContainer.nodeType == 1) {
  5469. // var tmp = this.document.createTextNode('');
  5470. // this.insertNode(tmp).setStart(tmp, 0).collapse(true);
  5471. // }
  5472. //
  5473. //处理光标落在文本节点的情况
  5474. //处理以下的情况
  5475. //<b>|xxxx</b>
  5476. //<b>xxxx</b>|xxxx
  5477. //xxxx<b>|</b>
  5478. var start = this.startContainer,child = start;
  5479. if(start.nodeType == 1){
  5480. child = start.childNodes[this.startOffset];
  5481. }
  5482. if( !(start.nodeType == 3 && this.startOffset) &&
  5483. (child ?
  5484. (!child.previousSibling || child.previousSibling.nodeType != 3)
  5485. :
  5486. (!start.lastChild || start.lastChild.nodeType != 3)
  5487. )
  5488. ){
  5489. txtNode = this.document.createTextNode(fillChar);
  5490. //跟着前边走
  5491. this.insertNode(txtNode);
  5492. removeFillData(this.document, txtNode);
  5493. mergeSibling(txtNode, 'previousSibling');
  5494. mergeSibling(txtNode, 'nextSibling');
  5495. fillData = txtNode;
  5496. this.setStart(txtNode, browser.webkit ? 1 : 0).collapse(true);
  5497. }
  5498. }
  5499. var nativeRange = this.document.createRange();
  5500. if(this.collapsed && browser.opera && this.startContainer.nodeType == 1){
  5501. var child = this.startContainer.childNodes[this.startOffset];
  5502. if(!child){
  5503. //往前靠拢
  5504. child = this.startContainer.lastChild;
  5505. if( child && domUtils.isBr(child)){
  5506. this.setStartBefore(child).collapse(true);
  5507. }
  5508. }else{
  5509. //向后靠拢
  5510. while(child && domUtils.isBlockElm(child)){
  5511. if(child.nodeType == 1 && child.childNodes[0]){
  5512. child = child.childNodes[0]
  5513. }else{
  5514. break;
  5515. }
  5516. }
  5517. child && this.setStartBefore(child).collapse(true)
  5518. }
  5519. }
  5520. //是createAddress最后一位算的不准,现在这里进行微调
  5521. checkOffset(this);
  5522. nativeRange.setStart(this.startContainer, this.startOffset);
  5523. nativeRange.setEnd(this.endContainer, this.endOffset);
  5524. sel.addRange(nativeRange);
  5525. }
  5526. return this;
  5527. },
  5528. /**
  5529. * 滚动到当前range开始的位置
  5530. * @method scrollToView
  5531. * @param { Window } win 当前range对象所属的window对象
  5532. * @return { UE.dom.Range } 当前Range对象
  5533. */
  5534. /**
  5535. * 滚动到距离当前range开始位置 offset 的位置处
  5536. * @method scrollToView
  5537. * @param { Window } win 当前range对象所属的window对象
  5538. * @param { Number } offset 距离range开始位置处的偏移量, 如果为正数, 则向下偏移, 反之, 则向上偏移
  5539. * @return { UE.dom.Range } 当前Range对象
  5540. */
  5541. scrollToView:function (win, offset) {
  5542. win = win ? window : domUtils.getWindow(this.document);
  5543. var me = this,
  5544. span = me.document.createElement('span');
  5545. //trace:717
  5546. span.innerHTML = '&nbsp;';
  5547. me.cloneRange().insertNode(span);
  5548. domUtils.scrollToView(span, win, offset);
  5549. domUtils.remove(span);
  5550. return me;
  5551. },
  5552. /**
  5553. * 判断当前选区内容是否占位符
  5554. * @private
  5555. * @method inFillChar
  5556. * @return { Boolean } 如果是占位符返回true,否则返回false
  5557. */
  5558. inFillChar : function(){
  5559. var start = this.startContainer;
  5560. if(this.collapsed && start.nodeType == 3
  5561. && start.nodeValue.replace(new RegExp('^' + domUtils.fillChar),'').length + 1 == start.nodeValue.length
  5562. ){
  5563. return true;
  5564. }
  5565. return false;
  5566. },
  5567. /**
  5568. * 保存
  5569. * @method createAddress
  5570. * @private
  5571. * @return { Boolean } 返回开始和结束的位置
  5572. * @example
  5573. * ```html
  5574. * <body>
  5575. * <p>
  5576. * aaaa
  5577. * <em>
  5578. * <!-- 选区开始 -->
  5579. * bbbb
  5580. * <!-- 选区结束 -->
  5581. * </em>
  5582. * </p>
  5583. *
  5584. * <script>
  5585. * //output: {startAddress:[0,1,0,0],endAddress:[0,1,0,4]}
  5586. * console.log( range.createAddress() );
  5587. * </script>
  5588. * </body>
  5589. * ```
  5590. */
  5591. createAddress : function(ignoreEnd,ignoreTxt){
  5592. var addr = {},me = this;
  5593. function getAddress(isStart){
  5594. var node = isStart ? me.startContainer : me.endContainer;
  5595. var parents = domUtils.findParents(node,true,function(node){return !domUtils.isBody(node)}),
  5596. addrs = [];
  5597. for(var i = 0,ci;ci = parents[i++];){
  5598. addrs.push(domUtils.getNodeIndex(ci,ignoreTxt));
  5599. }
  5600. var firstIndex = 0;
  5601. if(ignoreTxt){
  5602. if(node.nodeType == 3){
  5603. var tmpNode = node.previousSibling;
  5604. while(tmpNode && tmpNode.nodeType == 3){
  5605. firstIndex += tmpNode.nodeValue.replace(fillCharReg,'').length;
  5606. tmpNode = tmpNode.previousSibling;
  5607. }
  5608. firstIndex += (isStart ? me.startOffset : me.endOffset)// - (fillCharReg.test(node.nodeValue) ? 1 : 0 )
  5609. }else{
  5610. node = node.childNodes[ isStart ? me.startOffset : me.endOffset];
  5611. if(node){
  5612. firstIndex = domUtils.getNodeIndex(node,ignoreTxt);
  5613. }else{
  5614. node = isStart ? me.startContainer : me.endContainer;
  5615. var first = node.firstChild;
  5616. while(first){
  5617. if(domUtils.isFillChar(first)){
  5618. first = first.nextSibling;
  5619. continue;
  5620. }
  5621. firstIndex++;
  5622. if(first.nodeType == 3){
  5623. while( first && first.nodeType == 3){
  5624. first = first.nextSibling;
  5625. }
  5626. }else{
  5627. first = first.nextSibling;
  5628. }
  5629. }
  5630. }
  5631. }
  5632. }else{
  5633. firstIndex = isStart ? domUtils.isFillChar(node) ? 0 : me.startOffset : me.endOffset
  5634. }
  5635. if(firstIndex < 0){
  5636. firstIndex = 0;
  5637. }
  5638. addrs.push(firstIndex);
  5639. return addrs;
  5640. }
  5641. addr.startAddress = getAddress(true);
  5642. if(!ignoreEnd){
  5643. addr.endAddress = me.collapsed ? [].concat(addr.startAddress) : getAddress();
  5644. }
  5645. return addr;
  5646. },
  5647. /**
  5648. * 保存
  5649. * @method createAddress
  5650. * @private
  5651. * @return { Boolean } 返回开始和结束的位置
  5652. * @example
  5653. * ```html
  5654. * <body>
  5655. * <p>
  5656. * aaaa
  5657. * <em>
  5658. * <!-- 选区开始 -->
  5659. * bbbb
  5660. * <!-- 选区结束 -->
  5661. * </em>
  5662. * </p>
  5663. *
  5664. * <script>
  5665. * var range = editor.selection.getRange();
  5666. * range.moveToAddress({startAddress:[0,1,0,0],endAddress:[0,1,0,4]});
  5667. * range.select();
  5668. * //output: 'bbbb'
  5669. * console.log(editor.selection.getText());
  5670. * </script>
  5671. * </body>
  5672. * ```
  5673. */
  5674. moveToAddress : function(addr,ignoreEnd){
  5675. var me = this;
  5676. function getNode(address,isStart){
  5677. var tmpNode = me.document.body,
  5678. parentNode,offset;
  5679. for(var i= 0,ci,l=address.length;i<l;i++){
  5680. ci = address[i];
  5681. parentNode = tmpNode;
  5682. tmpNode = tmpNode.childNodes[ci];
  5683. if(!tmpNode){
  5684. offset = ci;
  5685. break;
  5686. }
  5687. }
  5688. if(isStart){
  5689. if(tmpNode){
  5690. me.setStartBefore(tmpNode)
  5691. }else{
  5692. me.setStart(parentNode,offset)
  5693. }
  5694. }else{
  5695. if(tmpNode){
  5696. me.setEndBefore(tmpNode)
  5697. }else{
  5698. me.setEnd(parentNode,offset)
  5699. }
  5700. }
  5701. }
  5702. getNode(addr.startAddress,true);
  5703. !ignoreEnd && addr.endAddress && getNode(addr.endAddress);
  5704. return me;
  5705. },
  5706. /**
  5707. * 判断给定的Range对象是否和当前Range对象表示的是同一个选区
  5708. * @method equals
  5709. * @param { UE.dom.Range } 需要判断的Range对象
  5710. * @return { Boolean } 如果给定的Range对象与当前Range对象表示的是同一个选区, 则返回true, 否则返回false
  5711. */
  5712. equals : function(rng){
  5713. for(var p in this){
  5714. if(this.hasOwnProperty(p)){
  5715. if(this[p] !== rng[p])
  5716. return false
  5717. }
  5718. }
  5719. return true;
  5720. },
  5721. /**
  5722. * 遍历range内的节点。每当遍历一个节点时, 都会执行参数项 doFn 指定的函数, 该函数的接受当前遍历的节点
  5723. * 作为其参数。
  5724. * @method traversal
  5725. * @param { Function } doFn 对每个遍历的节点要执行的方法, 该方法接受当前遍历的节点作为其参数
  5726. * @return { UE.dom.Range } 当前range对象
  5727. * @example
  5728. * ```html
  5729. *
  5730. * <body>
  5731. *
  5732. * <!-- 选区开始 -->
  5733. * <span></span>
  5734. * <a></a>
  5735. * <!-- 选区结束 -->
  5736. * </body>
  5737. *
  5738. * <script>
  5739. *
  5740. * //output: <span></span><a></a>
  5741. * console.log( range.cloneContents() );
  5742. *
  5743. * range.traversal( function ( node ) {
  5744. *
  5745. * if ( node.nodeType === 1 ) {
  5746. * node.className = "test";
  5747. * }
  5748. *
  5749. * } );
  5750. *
  5751. * //output: <span class="test"></span><a class="test"></a>
  5752. * console.log( range.cloneContents() );
  5753. *
  5754. * </script>
  5755. * ```
  5756. */
  5757. /**
  5758. * 遍历range内的节点。
  5759. * 每当遍历一个节点时, 都会执行参数项 doFn 指定的函数, 该函数的接受当前遍历的节点
  5760. * 作为其参数。
  5761. * 可以通过参数项 filterFn 来指定一个过滤器, 只有符合该过滤器过滤规则的节点才会触
  5762. * 发doFn函数的执行
  5763. * @method traversal
  5764. * @param { Function } doFn 对每个遍历的节点要执行的方法, 该方法接受当前遍历的节点作为其参数
  5765. * @param { Function } filterFn 过滤器, 该函数接受当前遍历的节点作为参数, 如果该节点满足过滤
  5766. * 规则, 请返回true, 该节点会触发doFn, 否则, 请返回false, 则该节点不
  5767. * 会触发doFn。
  5768. * @return { UE.dom.Range } 当前range对象
  5769. * @see UE.dom.Range:traversal(Function)
  5770. * @example
  5771. * ```html
  5772. *
  5773. * <body>
  5774. *
  5775. * <!-- 选区开始 -->
  5776. * <span></span>
  5777. * <a></a>
  5778. * <!-- 选区结束 -->
  5779. * </body>
  5780. *
  5781. * <script>
  5782. *
  5783. * //output: <span></span><a></a>
  5784. * console.log( range.cloneContents() );
  5785. *
  5786. * range.traversal( function ( node ) {
  5787. *
  5788. * node.className = "test";
  5789. *
  5790. * }, function ( node ) {
  5791. * return node.nodeType === 1;
  5792. * } );
  5793. *
  5794. * //output: <span class="test"></span><a class="test"></a>
  5795. * console.log( range.cloneContents() );
  5796. *
  5797. * </script>
  5798. * ```
  5799. */
  5800. traversal:function(doFn,filterFn){
  5801. if (this.collapsed)
  5802. return this;
  5803. var bookmark = this.createBookmark(),
  5804. end = bookmark.end,
  5805. current = domUtils.getNextDomNode(bookmark.start, false, filterFn);
  5806. while (current && current !== end && (domUtils.getPosition(current, end) & domUtils.POSITION_PRECEDING)) {
  5807. var tmpNode = domUtils.getNextDomNode(current,false,filterFn);
  5808. doFn(current);
  5809. current = tmpNode;
  5810. }
  5811. return this.moveToBookmark(bookmark);
  5812. }
  5813. };
  5814. })();
  5815. // js/editor/_src/core/Selection.js
  5816. /**
  5817. * 选集
  5818. * @file
  5819. * @module UE.dom
  5820. * @class Selection
  5821. * @since 1.2.6.1
  5822. */
  5823. /**
  5824. * 选区集合
  5825. * @unfile
  5826. * @module UE.dom
  5827. * @class Selection
  5828. */
  5829. (function () {
  5830. function getBoundaryInformation( range, start ) {
  5831. var getIndex = domUtils.getNodeIndex;
  5832. range = range.duplicate();
  5833. range.collapse( start );
  5834. var parent = range.parentElement();
  5835. //如果节点里没有子节点,直接退出
  5836. if ( !parent.hasChildNodes() ) {
  5837. return {container:parent, offset:0};
  5838. }
  5839. var siblings = parent.children,
  5840. child,
  5841. testRange = range.duplicate(),
  5842. startIndex = 0, endIndex = siblings.length - 1, index = -1,
  5843. distance;
  5844. while ( startIndex <= endIndex ) {
  5845. index = Math.floor( (startIndex + endIndex) / 2 );
  5846. child = siblings[index];
  5847. testRange.moveToElementText( child );
  5848. var position = testRange.compareEndPoints( 'StartToStart', range );
  5849. if ( position > 0 ) {
  5850. endIndex = index - 1;
  5851. } else if ( position < 0 ) {
  5852. startIndex = index + 1;
  5853. } else {
  5854. //trace:1043
  5855. return {container:parent, offset:getIndex( child )};
  5856. }
  5857. }
  5858. if ( index == -1 ) {
  5859. testRange.moveToElementText( parent );
  5860. testRange.setEndPoint( 'StartToStart', range );
  5861. distance = testRange.text.replace( /(\r\n|\r)/g, '\n' ).length;
  5862. siblings = parent.childNodes;
  5863. if ( !distance ) {
  5864. child = siblings[siblings.length - 1];
  5865. return {container:child, offset:child.nodeValue.length};
  5866. }
  5867. var i = siblings.length;
  5868. while ( distance > 0 ){
  5869. distance -= siblings[ --i ].nodeValue.length;
  5870. }
  5871. return {container:siblings[i], offset:-distance};
  5872. }
  5873. testRange.collapse( position > 0 );
  5874. testRange.setEndPoint( position > 0 ? 'StartToStart' : 'EndToStart', range );
  5875. distance = testRange.text.replace( /(\r\n|\r)/g, '\n' ).length;
  5876. if ( !distance ) {
  5877. return dtd.$empty[child.tagName] || dtd.$nonChild[child.tagName] ?
  5878. {container:parent, offset:getIndex( child ) + (position > 0 ? 0 : 1)} :
  5879. {container:child, offset:position > 0 ? 0 : child.childNodes.length}
  5880. }
  5881. while ( distance > 0 ) {
  5882. try {
  5883. var pre = child;
  5884. child = child[position > 0 ? 'previousSibling' : 'nextSibling'];
  5885. distance -= child.nodeValue.length;
  5886. } catch ( e ) {
  5887. return {container:parent, offset:getIndex( pre )};
  5888. }
  5889. }
  5890. return {container:child, offset:position > 0 ? -distance : child.nodeValue.length + distance}
  5891. }
  5892. /**
  5893. * 将ieRange转换为Range对象
  5894. * @param {Range} ieRange ieRange对象
  5895. * @param {Range} range Range对象
  5896. * @return {Range} range 返回转换后的Range对象
  5897. */
  5898. function transformIERangeToRange( ieRange, range ) {
  5899. if ( ieRange.item ) {
  5900. range.selectNode( ieRange.item( 0 ) );
  5901. } else {
  5902. var bi = getBoundaryInformation( ieRange, true );
  5903. range.setStart( bi.container, bi.offset );
  5904. if ( ieRange.compareEndPoints( 'StartToEnd', ieRange ) != 0 ) {
  5905. bi = getBoundaryInformation( ieRange, false );
  5906. range.setEnd( bi.container, bi.offset );
  5907. }
  5908. }
  5909. return range;
  5910. }
  5911. /**
  5912. * 获得ieRange
  5913. * @param {Selection} sel Selection对象
  5914. * @return {ieRange} 得到ieRange
  5915. */
  5916. function _getIERange( sel ) {
  5917. var ieRange;
  5918. //ie下有可能报错
  5919. try {
  5920. ieRange = sel.getNative().createRange();
  5921. } catch ( e ) {
  5922. return null;
  5923. }
  5924. var el = ieRange.item ? ieRange.item( 0 ) : ieRange.parentElement();
  5925. if ( ( el.ownerDocument || el ) === sel.document ) {
  5926. return ieRange;
  5927. }
  5928. return null;
  5929. }
  5930. var Selection = dom.Selection = function ( doc ) {
  5931. var me = this, iframe;
  5932. me.document = doc;
  5933. if ( browser.ie9below ) {
  5934. iframe = domUtils.getWindow( doc ).frameElement;
  5935. domUtils.on( iframe, 'beforedeactivate', function () {
  5936. me._bakIERange = me.getIERange();
  5937. } );
  5938. domUtils.on( iframe, 'activate', function () {
  5939. try {
  5940. if ( !_getIERange( me ) && me._bakIERange ) {
  5941. me._bakIERange.select();
  5942. }
  5943. } catch ( ex ) {
  5944. }
  5945. me._bakIERange = null;
  5946. } );
  5947. }
  5948. iframe = doc = null;
  5949. };
  5950. Selection.prototype = {
  5951. rangeInBody : function(rng,txtRange){
  5952. var node = browser.ie9below || txtRange ? rng.item ? rng.item() : rng.parentElement() : rng.startContainer;
  5953. return node === this.document.body || domUtils.inDoc(node,this.document);
  5954. },
  5955. /**
  5956. * 获取原生seleciton对象
  5957. * @method getNative
  5958. * @return { Object } 获得selection对象
  5959. * @example
  5960. * ```javascript
  5961. * editor.selection.getNative();
  5962. * ```
  5963. */
  5964. getNative:function () {
  5965. var doc = this.document;
  5966. try {
  5967. return !doc ? null : browser.ie9below ? doc.selection : domUtils.getWindow( doc ).getSelection();
  5968. } catch ( e ) {
  5969. return null;
  5970. }
  5971. },
  5972. /**
  5973. * 获得ieRange
  5974. * @method getIERange
  5975. * @return { Object } 返回ie原生的Range
  5976. * @example
  5977. * ```javascript
  5978. * editor.selection.getIERange();
  5979. * ```
  5980. */
  5981. getIERange:function () {
  5982. var ieRange = _getIERange( this );
  5983. if ( !ieRange ) {
  5984. if ( this._bakIERange ) {
  5985. return this._bakIERange;
  5986. }
  5987. }
  5988. return ieRange;
  5989. },
  5990. /**
  5991. * 缓存当前选区的range和选区的开始节点
  5992. * @method cache
  5993. */
  5994. cache:function () {
  5995. this.clear();
  5996. this._cachedRange = this.getRange();
  5997. this._cachedStartElement = this.getStart();
  5998. this._cachedStartElementPath = this.getStartElementPath();
  5999. },
  6000. /**
  6001. * 获取选区开始位置的父节点到body
  6002. * @method getStartElementPath
  6003. * @return { Array } 返回父节点集合
  6004. * @example
  6005. * ```javascript
  6006. * editor.selection.getStartElementPath();
  6007. * ```
  6008. */
  6009. getStartElementPath:function () {
  6010. if ( this._cachedStartElementPath ) {
  6011. return this._cachedStartElementPath;
  6012. }
  6013. var start = this.getStart();
  6014. if ( start ) {
  6015. return domUtils.findParents( start, true, null, true )
  6016. }
  6017. return [];
  6018. },
  6019. /**
  6020. * 清空缓存
  6021. * @method clear
  6022. */
  6023. clear:function () {
  6024. this._cachedStartElementPath = this._cachedRange = this._cachedStartElement = null;
  6025. },
  6026. /**
  6027. * 编辑器是否得到了选区
  6028. * @method isFocus
  6029. */
  6030. isFocus:function () {
  6031. try {
  6032. if(browser.ie9below){
  6033. var nativeRange = _getIERange(this);
  6034. return !!(nativeRange && this.rangeInBody(nativeRange));
  6035. }else{
  6036. return !!this.getNative().rangeCount;
  6037. }
  6038. } catch ( e ) {
  6039. return false;
  6040. }
  6041. },
  6042. /**
  6043. * 获取选区对应的Range
  6044. * @method getRange
  6045. * @return { Object } 得到Range对象
  6046. * @example
  6047. * ```javascript
  6048. * editor.selection.getRange();
  6049. * ```
  6050. */
  6051. getRange:function () {
  6052. var me = this;
  6053. function optimze( range ) {
  6054. var child = me.document.body.firstChild,
  6055. collapsed = range.collapsed;
  6056. while ( child && child.firstChild ) {
  6057. range.setStart( child, 0 );
  6058. child = child.firstChild;
  6059. }
  6060. if ( !range.startContainer ) {
  6061. range.setStart( me.document.body, 0 )
  6062. }
  6063. if ( collapsed ) {
  6064. range.collapse( true );
  6065. }
  6066. }
  6067. if ( me._cachedRange != null ) {
  6068. return this._cachedRange;
  6069. }
  6070. var range = new baidu.editor.dom.Range( me.document );
  6071. if ( browser.ie9below ) {
  6072. var nativeRange = me.getIERange();
  6073. if ( nativeRange ) {
  6074. //备份的_bakIERange可能已经实效了,dom树发生了变化比如从源码模式切回来,所以try一下,实效就放到body开始位置
  6075. try{
  6076. transformIERangeToRange( nativeRange, range );
  6077. }catch(e){
  6078. optimze( range );
  6079. }
  6080. } else {
  6081. optimze( range );
  6082. }
  6083. } else {
  6084. var sel = me.getNative();
  6085. if ( sel && sel.rangeCount ) {
  6086. var firstRange = sel.getRangeAt( 0 );
  6087. var lastRange = sel.getRangeAt( sel.rangeCount - 1 );
  6088. range.setStart( firstRange.startContainer, firstRange.startOffset ).setEnd( lastRange.endContainer, lastRange.endOffset );
  6089. if ( range.collapsed && domUtils.isBody( range.startContainer ) && !range.startOffset ) {
  6090. optimze( range );
  6091. }
  6092. } else {
  6093. //trace:1734 有可能已经不在dom树上了,标识的节点
  6094. if ( this._bakRange && domUtils.inDoc( this._bakRange.startContainer, this.document ) ){
  6095. return this._bakRange;
  6096. }
  6097. optimze( range );
  6098. }
  6099. }
  6100. return this._bakRange = range;
  6101. },
  6102. /**
  6103. * 获取开始元素,用于状态反射
  6104. * @method getStart
  6105. * @return { Element } 获得开始元素
  6106. * @example
  6107. * ```javascript
  6108. * editor.selection.getStart();
  6109. * ```
  6110. */
  6111. getStart:function () {
  6112. if ( this._cachedStartElement ) {
  6113. return this._cachedStartElement;
  6114. }
  6115. var range = browser.ie9below ? this.getIERange() : this.getRange(),
  6116. tmpRange,
  6117. start, tmp, parent;
  6118. if ( browser.ie9below ) {
  6119. if ( !range ) {
  6120. //todo 给第一个值可能会有问题
  6121. return this.document.body.firstChild;
  6122. }
  6123. //control元素
  6124. if ( range.item ){
  6125. return range.item( 0 );
  6126. }
  6127. tmpRange = range.duplicate();
  6128. //修正ie下<b>x</b>[xx] 闭合后 <b>x|</b>xx
  6129. tmpRange.text.length > 0 && tmpRange.moveStart( 'character', 1 );
  6130. tmpRange.collapse( 1 );
  6131. start = tmpRange.parentElement();
  6132. parent = tmp = range.parentElement();
  6133. while ( tmp = tmp.parentNode ) {
  6134. if ( tmp == start ) {
  6135. start = parent;
  6136. break;
  6137. }
  6138. }
  6139. } else {
  6140. range.shrinkBoundary();
  6141. start = range.startContainer;
  6142. if ( start.nodeType == 1 && start.hasChildNodes() ){
  6143. start = start.childNodes[Math.min( start.childNodes.length - 1, range.startOffset )];
  6144. }
  6145. if ( start.nodeType == 3 ){
  6146. return start.parentNode;
  6147. }
  6148. }
  6149. return start;
  6150. },
  6151. /**
  6152. * 得到选区中的文本
  6153. * @method getText
  6154. * @return { String } 选区中包含的文本
  6155. * @example
  6156. * ```javascript
  6157. * editor.selection.getText();
  6158. * ```
  6159. */
  6160. getText:function () {
  6161. var nativeSel, nativeRange;
  6162. if ( this.isFocus() && (nativeSel = this.getNative()) ) {
  6163. nativeRange = browser.ie9below ? nativeSel.createRange() : nativeSel.getRangeAt( 0 );
  6164. return browser.ie9below ? nativeRange.text : nativeRange.toString();
  6165. }
  6166. return '';
  6167. },
  6168. /**
  6169. * 清除选区
  6170. * @method clearRange
  6171. * @example
  6172. * ```javascript
  6173. * editor.selection.clearRange();
  6174. * ```
  6175. */
  6176. clearRange : function(){
  6177. this.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']();
  6178. }
  6179. };
  6180. })();
  6181. // js/editor/_src/core/Editor.js
  6182. /**
  6183. * 编辑器主类,包含编辑器提供的大部分公用接口
  6184. * @file
  6185. * @module UE
  6186. * @class Editor
  6187. * @since 1.2.6.1
  6188. */
  6189. /**
  6190. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  6191. * @unfile
  6192. * @module UE
  6193. */
  6194. /**
  6195. * UEditor的核心类,为用户提供与编辑器交互的接口。
  6196. * @unfile
  6197. * @module UE
  6198. * @class Editor
  6199. */
  6200. (function () {
  6201. var uid = 0, _selectionChangeTimer;
  6202. /**
  6203. * 获取编辑器的html内容,赋值到编辑器所在表单的textarea文本域里面
  6204. * @private
  6205. * @method setValue
  6206. * @param { UE.Editor } editor 编辑器事例
  6207. */
  6208. function setValue(form, editor) {
  6209. var textarea;
  6210. if (editor.textarea) {
  6211. if (utils.isString(editor.textarea)) {
  6212. for (var i = 0, ti, tis = domUtils.getElementsByTagName(form, 'textarea'); ti = tis[i++];) {
  6213. if (ti.id == 'ueditor_textarea_' + editor.options.textarea) {
  6214. textarea = ti;
  6215. break;
  6216. }
  6217. }
  6218. } else {
  6219. textarea = editor.textarea;
  6220. }
  6221. }
  6222. if (!textarea) {
  6223. form.appendChild(textarea = domUtils.createElement(document, 'textarea', {
  6224. 'name': editor.options.textarea,
  6225. 'id': 'ueditor_textarea_' + editor.options.textarea,
  6226. 'style': "display:none"
  6227. }));
  6228. //不要产生多个textarea
  6229. editor.textarea = textarea;
  6230. }
  6231. !textarea.getAttribute('name') && textarea.setAttribute('name', editor.options.textarea );
  6232. textarea.value = editor.hasContents() ?
  6233. (editor.options.allHtmlEnabled ? editor.getAllHtml() : editor.getContent(null, null, true)) :
  6234. ''
  6235. }
  6236. function loadPlugins(me){
  6237. //初始化插件
  6238. for (var pi in UE.plugins) {
  6239. UE.plugins[pi].call(me);
  6240. }
  6241. }
  6242. function checkCurLang(I18N){
  6243. for(var lang in I18N){
  6244. return lang
  6245. }
  6246. }
  6247. function langReadied(me){
  6248. me.langIsReady = true;
  6249. me.fireEvent("langReady");
  6250. }
  6251. /**
  6252. * 编辑器准备就绪后会触发该事件
  6253. * @module UE
  6254. * @class Editor
  6255. * @event ready
  6256. * @remind render方法执行完成之后,会触发该事件
  6257. * @remind
  6258. * @example
  6259. * ```javascript
  6260. * editor.addListener( 'ready', function( editor ) {
  6261. * editor.execCommand( 'focus' ); //编辑器家在完成后,让编辑器拿到焦点
  6262. * } );
  6263. * ```
  6264. */
  6265. /**
  6266. * 执行destroy方法,会触发该事件
  6267. * @module UE
  6268. * @class Editor
  6269. * @event destroy
  6270. * @see UE.Editor:destroy()
  6271. */
  6272. /**
  6273. * 执行reset方法,会触发该事件
  6274. * @module UE
  6275. * @class Editor
  6276. * @event reset
  6277. * @see UE.Editor:reset()
  6278. */
  6279. /**
  6280. * 执行focus方法,会触发该事件
  6281. * @module UE
  6282. * @class Editor
  6283. * @event focus
  6284. * @see UE.Editor:focus(Boolean)
  6285. */
  6286. /**
  6287. * 语言加载完成会触发该事件
  6288. * @module UE
  6289. * @class Editor
  6290. * @event langReady
  6291. */
  6292. /**
  6293. * 运行命令之后会触发该命令
  6294. * @module UE
  6295. * @class Editor
  6296. * @event beforeExecCommand
  6297. */
  6298. /**
  6299. * 运行命令之后会触发该命令
  6300. * @module UE
  6301. * @class Editor
  6302. * @event afterExecCommand
  6303. */
  6304. /**
  6305. * 运行命令之前会触发该命令
  6306. * @module UE
  6307. * @class Editor
  6308. * @event firstBeforeExecCommand
  6309. */
  6310. /**
  6311. * 在getContent方法执行之前会触发该事件
  6312. * @module UE
  6313. * @class Editor
  6314. * @event beforeGetContent
  6315. * @see UE.Editor:getContent()
  6316. */
  6317. /**
  6318. * 在getContent方法执行之后会触发该事件
  6319. * @module UE
  6320. * @class Editor
  6321. * @event afterGetContent
  6322. * @see UE.Editor:getContent()
  6323. */
  6324. /**
  6325. * 在getAllHtml方法执行时会触发该事件
  6326. * @module UE
  6327. * @class Editor
  6328. * @event getAllHtml
  6329. * @see UE.Editor:getAllHtml()
  6330. */
  6331. /**
  6332. * 在setContent方法执行之前会触发该事件
  6333. * @module UE
  6334. * @class Editor
  6335. * @event beforeSetContent
  6336. * @see UE.Editor:setContent(String)
  6337. */
  6338. /**
  6339. * 在setContent方法执行之后会触发该事件
  6340. * @module UE
  6341. * @class Editor
  6342. * @event afterSetContent
  6343. * @see UE.Editor:setContent(String)
  6344. */
  6345. /**
  6346. * 每当编辑器内部选区发生改变时,将触发该事件
  6347. * @event selectionchange
  6348. * @warning 该事件的触发非常频繁,不建议在该事件的处理过程中做重量级的处理
  6349. * @example
  6350. * ```javascript
  6351. * editor.addListener( 'selectionchange', function( editor ) {
  6352. * console.log('选区发生改变');
  6353. * }
  6354. */
  6355. /**
  6356. * 在所有selectionchange的监听函数执行之前,会触发该事件
  6357. * @module UE
  6358. * @class Editor
  6359. * @event beforeSelectionChange
  6360. * @see UE.Editor:selectionchange
  6361. */
  6362. /**
  6363. * 在所有selectionchange的监听函数执行完之后,会触发该事件
  6364. * @module UE
  6365. * @class Editor
  6366. * @event afterSelectionChange
  6367. * @see UE.Editor:selectionchange
  6368. */
  6369. /**
  6370. * 编辑器内容发生改变时会触发该事件
  6371. * @module UE
  6372. * @class Editor
  6373. * @event contentChange
  6374. */
  6375. /**
  6376. * 以默认参数构建一个编辑器实例
  6377. * @constructor
  6378. * @remind 通过 改构造方法实例化的编辑器,不带ui层.需要render到一个容器,编辑器实例才能正常渲染到页面
  6379. * @example
  6380. * ```javascript
  6381. * var editor = new UE.Editor();
  6382. * editor.execCommand('blod');
  6383. * ```
  6384. * @see UE.Config
  6385. */
  6386. /**
  6387. * 以给定的参数集合创建一个编辑器实例,对于未指定的参数,将应用默认参数。
  6388. * @constructor
  6389. * @remind 通过 改构造方法实例化的编辑器,不带ui层.需要render到一个容器,编辑器实例才能正常渲染到页面
  6390. * @param { Object } setting 创建编辑器的参数
  6391. * @example
  6392. * ```javascript
  6393. * var editor = new UE.Editor();
  6394. * editor.execCommand('blod');
  6395. * ```
  6396. * @see UE.Config
  6397. */
  6398. var Editor = UE.Editor = function (options) {
  6399. var me = this;
  6400. me.uid = uid++;
  6401. EventBase.call(me);
  6402. me.commands = {};
  6403. me.options = utils.extend(utils.clone(options || {}), UEDITOR_CONFIG, true);
  6404. me.shortcutkeys = {};
  6405. me.inputRules = [];
  6406. me.outputRules = [];
  6407. //设置默认的常用属性
  6408. me.setOpt(Editor.defaultOptions(me));
  6409. /* 尝试异步加载后台配置 */
  6410. //me.loadServerConfig();
  6411. if(!utils.isEmptyObject(UE.I18N)){
  6412. //修改默认的语言类型
  6413. me.options.lang = checkCurLang(UE.I18N);
  6414. UE.plugin.load(me);
  6415. langReadied(me);
  6416. }else{
  6417. utils.loadFile(document, {
  6418. src: me.options.langPath + me.options.lang + "/" + me.options.lang + ".js",
  6419. tag: "script",
  6420. type: "text/javascript",
  6421. defer: "defer"
  6422. }, function () {
  6423. UE.plugin.load(me);
  6424. langReadied(me);
  6425. });
  6426. }
  6427. UE.instants['ueditorInstant' + me.uid] = me;
  6428. };
  6429. Editor.prototype = {
  6430. registerCommand : function(name,obj){
  6431. this.commands[name] = obj;
  6432. },
  6433. /**
  6434. * 编辑器对外提供的监听ready事件的接口, 通过调用该方法,达到的效果与监听ready事件是一致的
  6435. * @method ready
  6436. * @param { Function } fn 编辑器ready之后所执行的回调, 如果在注册事件之前编辑器已经ready,将会
  6437. * 立即触发该回调。
  6438. * @remind 需要等待编辑器加载完成后才能执行的代码,可以使用该方法传入
  6439. * @example
  6440. * ```javascript
  6441. * editor.ready( function( editor ) {
  6442. * editor.setContent('初始化完毕');
  6443. * } );
  6444. * ```
  6445. * @see UE.Editor.event:ready
  6446. */
  6447. ready: function (fn) {
  6448. var me = this;
  6449. if (fn) {
  6450. me.isReady ? fn.apply(me) : me.addListener('ready', fn);
  6451. }
  6452. },
  6453. /**
  6454. * 该方法是提供给插件里面使用,设置配置项默认值
  6455. * @method setOpt
  6456. * @warning 三处设置配置项的优先级: 实例化时传入参数 > setOpt()设置 > config文件里设置
  6457. * @warning 该方法仅供编辑器插件内部和编辑器初始化时调用,其他地方不能调用。
  6458. * @param { String } key 编辑器的可接受的选项名称
  6459. * @param { * } val 该选项可接受的值
  6460. * @example
  6461. * ```javascript
  6462. * editor.setOpt( 'initContent', '欢迎使用编辑器' );
  6463. * ```
  6464. */
  6465. /**
  6466. * 该方法是提供给插件里面使用,以{key:value}集合的方式设置插件内用到的配置项默认值
  6467. * @method setOpt
  6468. * @warning 三处设置配置项的优先级: 实例化时传入参数 > setOpt()设置 > config文件里设置
  6469. * @warning 该方法仅供编辑器插件内部和编辑器初始化时调用,其他地方不能调用。
  6470. * @param { Object } options 将要设置的选项的键值对对象
  6471. * @example
  6472. * ```javascript
  6473. * editor.setOpt( {
  6474. * 'initContent': '欢迎使用编辑器'
  6475. * } );
  6476. * ```
  6477. */
  6478. setOpt: function (key, val) {
  6479. var obj = {};
  6480. if (utils.isString(key)) {
  6481. obj[key] = val
  6482. } else {
  6483. obj = key;
  6484. }
  6485. utils.extend(this.options, obj, true);
  6486. },
  6487. getOpt:function(key){
  6488. return this.options[key]
  6489. },
  6490. /**
  6491. * 销毁编辑器实例,使用textarea代替
  6492. * @method destroy
  6493. * @example
  6494. * ```javascript
  6495. * editor.destroy();
  6496. * ```
  6497. */
  6498. destroy: function () {
  6499. var me = this;
  6500. me.fireEvent('destroy');
  6501. var container = me.container.parentNode;
  6502. var textarea = me.textarea;
  6503. if (!textarea) {
  6504. textarea = document.createElement('textarea');
  6505. container.parentNode.insertBefore(textarea, container);
  6506. } else {
  6507. textarea.style.display = ''
  6508. }
  6509. textarea.style.width = me.iframe.offsetWidth + 'px';
  6510. textarea.style.height = me.iframe.offsetHeight + 'px';
  6511. textarea.value = me.getContent();
  6512. textarea.id = me.key;
  6513. container.innerHTML = '';
  6514. domUtils.remove(container);
  6515. var key = me.key;
  6516. //trace:2004
  6517. for (var p in me) {
  6518. if (me.hasOwnProperty(p)) {
  6519. delete this[p];
  6520. }
  6521. }
  6522. UE.delEditor(key);
  6523. },
  6524. /**
  6525. * 渲染编辑器的DOM到指定容器
  6526. * @method render
  6527. * @param { String } containerId 指定一个容器ID
  6528. * @remind 执行该方法,会触发ready事件
  6529. * @warning 必须且只能调用一次
  6530. */
  6531. /**
  6532. * 渲染编辑器的DOM到指定容器
  6533. * @method render
  6534. * @param { Element } containerDom 直接指定容器对象
  6535. * @remind 执行该方法,会触发ready事件
  6536. * @warning 必须且只能调用一次
  6537. */
  6538. render: function (container) {
  6539. var me = this,
  6540. options = me.options,
  6541. getStyleValue=function(attr){
  6542. return parseInt(domUtils.getComputedStyle(container,attr));
  6543. };
  6544. if (utils.isString(container)) {
  6545. container = document.getElementById(container);
  6546. }
  6547. if (container) {
  6548. if(options.initialFrameWidth){
  6549. options.minFrameWidth = options.initialFrameWidth
  6550. }else{
  6551. options.minFrameWidth = options.initialFrameWidth = container.offsetWidth;
  6552. }
  6553. if(options.initialFrameHeight){
  6554. options.minFrameHeight = options.initialFrameHeight
  6555. }else{
  6556. options.initialFrameHeight = options.minFrameHeight = container.offsetHeight;
  6557. }
  6558. container.style.width = /%$/.test(options.initialFrameWidth) ? '100%' : options.initialFrameWidth-
  6559. getStyleValue("padding-left")- getStyleValue("padding-right") +'px';
  6560. container.style.height = /%$/.test(options.initialFrameHeight) ? '100%' : options.initialFrameHeight -
  6561. getStyleValue("padding-top")- getStyleValue("padding-bottom") +'px';
  6562. container.style.zIndex = options.zIndex;
  6563. var html = ( ie && browser.version < 9 ? '' : '<!DOCTYPE html>') +
  6564. '<html xmlns=\'http://www.w3.org/1999/xhtml\' class=\'view\' ><head>' +
  6565. '<style type=\'text/css\'>' +
  6566. //设置四周的留边
  6567. '.view{padding:0;word-wrap:break-word;cursor:text;height:90%;}\n' +
  6568. //设置默认字体和字号
  6569. //font-family不能呢随便改,在safari下fillchar会有解析问题
  6570. 'body{margin:8px;font-family:sans-serif;font-size:16px;}' +
  6571. //设置段落间距
  6572. 'p{margin:5px 0;}</style>' +
  6573. //( options.iframeCssUrl ? '<link rel=\'stylesheet\' type=\'text/css\' href=\'' + utils.unhtml(options.iframeCssUrl) + '\'/>' : '' ) +
  6574. (options.initialStyle ? '<style>' + options.initialStyle + '</style>' : '') +
  6575. '</head><body class=\'view\' ></body>' +
  6576. '<script type=\'text/javascript\' ' + (ie ? 'defer=\'defer\'' : '' ) +' id=\'_initialScript\'>' +
  6577. 'setTimeout(function(){editor = window.parent.UE.instants[\'ueditorInstant' + me.uid + '\'];editor._setup(document);},0);' +
  6578. 'var _tmpScript = document.getElementById(\'_initialScript\');_tmpScript.parentNode.removeChild(_tmpScript);</script></html>';
  6579. container.appendChild(domUtils.createElement(document, 'iframe', {
  6580. id: 'ueditor_' + me.uid,
  6581. width: "100%",
  6582. height: "100%",
  6583. frameborder: "0",
  6584. //先注释掉了,加的原因忘记了,但开启会直接导致全屏模式下内容多时不会出现滚动条
  6585. // scrolling :'no',
  6586. src: 'javascript:void(function(){document.open();' + (options.customDomain && document.domain != location.hostname ? 'document.domain="' + document.domain + '";' : '') +
  6587. 'document.write("' + html + '");document.close();}())'
  6588. }));
  6589. container.style.overflow = 'hidden';
  6590. //解决如果是给定的百分比,会导致高度算不对的问题
  6591. setTimeout(function(){
  6592. if( /%$/.test(options.initialFrameWidth)){
  6593. options.minFrameWidth = options.initialFrameWidth = container.offsetWidth;
  6594. //如果这里给定宽度,会导致ie在拖动窗口大小时,编辑区域不随着变化
  6595. // container.style.width = options.initialFrameWidth + 'px';
  6596. }
  6597. if(/%$/.test(options.initialFrameHeight)){
  6598. options.minFrameHeight = options.initialFrameHeight = container.offsetHeight;
  6599. container.style.height = options.initialFrameHeight + 'px';
  6600. }
  6601. })
  6602. }
  6603. },
  6604. /**
  6605. * 编辑器初始化
  6606. * @method _setup
  6607. * @private
  6608. * @param { Element } doc 编辑器Iframe中的文档对象
  6609. */
  6610. _setup: function (doc) {
  6611. var me = this,
  6612. options = me.options;
  6613. if (ie) {
  6614. doc.body.disabled = true;
  6615. doc.body.contentEditable = true;
  6616. doc.body.disabled = false;
  6617. } else {
  6618. doc.body.contentEditable = true;
  6619. }
  6620. doc.body.spellcheck = false;
  6621. me.document = doc;
  6622. me.window = doc.defaultView || doc.parentWindow;
  6623. me.iframe = me.window.frameElement;
  6624. me.body = doc.body;
  6625. me.selection = new dom.Selection(doc);
  6626. //gecko初始化就能得到range,无法判断isFocus了
  6627. var geckoSel;
  6628. if (browser.gecko && (geckoSel = this.selection.getNative())) {
  6629. geckoSel.removeAllRanges();
  6630. }
  6631. this._initEvents();
  6632. //为form提交提供一个隐藏的textarea
  6633. for (var form = this.iframe.parentNode; !domUtils.isBody(form); form = form.parentNode) {
  6634. if (form.tagName == 'FORM') {
  6635. me.form = form;
  6636. if(me.options.autoSyncData){
  6637. domUtils.on(me.window,'blur',function(){
  6638. setValue(form,me);
  6639. });
  6640. }else{
  6641. domUtils.on(form, 'submit', function () {
  6642. setValue(this, me);
  6643. });
  6644. }
  6645. break;
  6646. }
  6647. }
  6648. if (options.initialContent) {
  6649. if (options.autoClearinitialContent) {
  6650. var oldExecCommand = me.execCommand;
  6651. me.execCommand = function () {
  6652. me.fireEvent('firstBeforeExecCommand');
  6653. return oldExecCommand.apply(me, arguments);
  6654. };
  6655. this._setDefaultContent(options.initialContent);
  6656. } else
  6657. this.setContent(options.initialContent, false, true);
  6658. }
  6659. //编辑器不能为空内容
  6660. if (domUtils.isEmptyNode(me.body)) {
  6661. me.body.innerHTML = '<p>' + (browser.ie ? '' : '<br/>') + '</p>';
  6662. }
  6663. //如果要求focus, 就把光标定位到内容开始
  6664. if (options.focus) {
  6665. setTimeout(function () {
  6666. me.focus(me.options.focusInEnd);
  6667. //如果自动清除开着,就不需要做selectionchange;
  6668. !me.options.autoClearinitialContent && me._selectionChange();
  6669. }, 0);
  6670. }
  6671. if (!me.container) {
  6672. me.container = this.iframe.parentNode;
  6673. }
  6674. if (options.fullscreen && me.ui) {
  6675. me.ui.setFullScreen(true);
  6676. }
  6677. try {
  6678. me.document.execCommand('2D-position', false, false);
  6679. } catch (e) {
  6680. }
  6681. try {
  6682. me.document.execCommand('enableInlineTableEditing', false, false);
  6683. } catch (e) {
  6684. }
  6685. try {
  6686. me.document.execCommand('enableObjectResizing', false, false);
  6687. } catch (e) {
  6688. }
  6689. //挂接快捷键
  6690. me._bindshortcutKeys();
  6691. me.isReady = 1;
  6692. me.fireEvent('ready');
  6693. options.onready && options.onready.call(me);
  6694. if (!browser.ie9below) {
  6695. domUtils.on(me.window, ['blur', 'focus'], function (e) {
  6696. //chrome下会出现alt+tab切换时,导致选区位置不对
  6697. if (e.type == 'blur') {
  6698. me._bakRange = me.selection.getRange();
  6699. try {
  6700. me._bakNativeRange = me.selection.getNative().getRangeAt(0);
  6701. me.selection.getNative().removeAllRanges();
  6702. } catch (e) {
  6703. me._bakNativeRange = null;
  6704. }
  6705. } else {
  6706. try {
  6707. me._bakRange && me._bakRange.select();
  6708. } catch (e) {
  6709. }
  6710. }
  6711. });
  6712. }
  6713. //trace:1518 ff3.6body不够寛,会导致点击空白处无法获得焦点
  6714. if (browser.gecko && browser.version <= 10902) {
  6715. //修复ff3.6初始化进来,不能点击获得焦点
  6716. me.body.contentEditable = false;
  6717. setTimeout(function () {
  6718. me.body.contentEditable = true;
  6719. }, 100);
  6720. setInterval(function () {
  6721. me.body.style.height = me.iframe.offsetHeight - 20 + 'px'
  6722. }, 100)
  6723. }
  6724. !options.isShow && me.setHide();
  6725. options.readonly && me.setDisabled();
  6726. },
  6727. /**
  6728. * 同步数据到编辑器所在的form
  6729. * 从编辑器的容器节点向上查找form元素,若找到,就同步编辑内容到找到的form里,为提交数据做准备,主要用于是手动提交的情况
  6730. * 后台取得数据的键值,使用你容器上的name属性,如果没有就使用参数里的textarea项
  6731. * @method sync
  6732. * @example
  6733. * ```javascript
  6734. * editor.sync();
  6735. * form.sumbit(); //form变量已经指向了form元素
  6736. * ```
  6737. */
  6738. /**
  6739. * 根据传入的formId,在页面上查找要同步数据的表单,若找到,就同步编辑内容到找到的form里,为提交数据做准备
  6740. * 后台取得数据的键值,该键值默认使用给定的编辑器容器的name属性,如果没有name属性则使用参数项里给定的“textarea”项
  6741. * @method sync
  6742. * @param { String } formID 指定一个要同步数据的form的id,编辑器的数据会同步到你指定form下
  6743. */
  6744. sync: function (formId) {
  6745. var me = this,
  6746. form = formId ? document.getElementById(formId) :
  6747. domUtils.findParent(me.iframe.parentNode, function (node) {
  6748. return node.tagName == 'FORM'
  6749. }, true);
  6750. form && setValue(form, me);
  6751. },
  6752. /**
  6753. * 设置编辑器高度
  6754. * @method setHeight
  6755. * @remind 当配置项autoHeightEnabled为真时,该方法无效
  6756. * @param { Number } number 设置的高度值,纯数值,不带单位
  6757. * @example
  6758. * ```javascript
  6759. * editor.setHeight(number);
  6760. * ```
  6761. */
  6762. setHeight: function (height,notSetHeight) {
  6763. if (height !== parseInt(this.iframe.parentNode.style.height)) {
  6764. this.iframe.parentNode.style.height = height + 'px';
  6765. }
  6766. !notSetHeight && (this.options.minFrameHeight = this.options.initialFrameHeight = height);
  6767. this.body.style.height = height + 'px';
  6768. !notSetHeight && this.trigger('setHeight')
  6769. },
  6770. /**
  6771. * 为编辑器的编辑命令提供快捷键
  6772. * 这个接口是为插件扩展提供的接口,主要是为新添加的插件,如果需要添加快捷键,所提供的接口
  6773. * @method addshortcutkey
  6774. * @param { Object } keyset 命令名和快捷键键值对对象,多个按钮的快捷键用“+”分隔
  6775. * @example
  6776. * ```javascript
  6777. * editor.addshortcutkey({
  6778. * "Bold" : "ctrl+66",//^B
  6779. * "Italic" : "ctrl+73", //^I
  6780. * });
  6781. * ```
  6782. */
  6783. /**
  6784. * 这个接口是为插件扩展提供的接口,主要是为新添加的插件,如果需要添加快捷键,所提供的接口
  6785. * @method addshortcutkey
  6786. * @param { String } cmd 触发快捷键时,响应的命令
  6787. * @param { String } keys 快捷键的字符串,多个按钮用“+”分隔
  6788. * @example
  6789. * ```javascript
  6790. * editor.addshortcutkey("Underline", "ctrl+85"); //^U
  6791. * ```
  6792. */
  6793. addshortcutkey: function (cmd, keys) {
  6794. var obj = {};
  6795. if (keys) {
  6796. obj[cmd] = keys
  6797. } else {
  6798. obj = cmd;
  6799. }
  6800. utils.extend(this.shortcutkeys, obj)
  6801. },
  6802. /**
  6803. * 对编辑器设置keydown事件监听,绑定快捷键和命令,当快捷键组合触发成功,会响应对应的命令
  6804. * @method _bindshortcutKeys
  6805. * @private
  6806. */
  6807. _bindshortcutKeys: function () {
  6808. var me = this, shortcutkeys = this.shortcutkeys;
  6809. me.addListener('keydown', function (type, e) {
  6810. var keyCode = e.keyCode || e.which;
  6811. for (var i in shortcutkeys) {
  6812. var tmp = shortcutkeys[i].split(',');
  6813. for (var t = 0, ti; ti = tmp[t++];) {
  6814. ti = ti.split(':');
  6815. var key = ti[0], param = ti[1];
  6816. if (/^(ctrl)(\+shift)?\+(\d+)$/.test(key.toLowerCase()) || /^(\d+)$/.test(key)) {
  6817. if (( (RegExp.$1 == 'ctrl' ? (e.ctrlKey || e.metaKey) : 0)
  6818. && (RegExp.$2 != "" ? e[RegExp.$2.slice(1) + "Key"] : 1)
  6819. && keyCode == RegExp.$3
  6820. ) ||
  6821. keyCode == RegExp.$1
  6822. ) {
  6823. if (me.queryCommandState(i,param) != -1)
  6824. me.execCommand(i, param);
  6825. domUtils.preventDefault(e);
  6826. }
  6827. }
  6828. }
  6829. }
  6830. });
  6831. },
  6832. /**
  6833. * 获取编辑器的内容
  6834. * @method getContent
  6835. * @warning 该方法获取到的是经过编辑器内置的过滤规则进行过滤后得到的内容
  6836. * @return { String } 编辑器的内容字符串, 如果编辑器的内容为空,或者是空的标签内容(如:”&lt;p&gt;&lt;br/&gt;&lt;/p&gt;“), 则返回空字符串
  6837. * @example
  6838. * ```javascript
  6839. * //编辑器html内容:<p>1<strong>2<em>34</em>5</strong>6</p>
  6840. * var content = editor.getContent(); //返回值:<p>1<strong>2<em>34</em>5</strong>6</p>
  6841. * ```
  6842. */
  6843. /**
  6844. * 获取编辑器的内容。 可以通过参数定义编辑器内置的判空规则
  6845. * @method getContent
  6846. * @param { Function } fn 自定的判空规则, 要求该方法返回一个boolean类型的值,
  6847. * 代表当前编辑器的内容是否空,
  6848. * 如果返回true, 则该方法将直接返回空字符串;如果返回false,则编辑器将返回
  6849. * 经过内置过滤规则处理后的内容。
  6850. * @remind 该方法在处理包含有初始化内容的时候能起到很好的作用。
  6851. * @warning 该方法获取到的是经过编辑器内置的过滤规则进行过滤后得到的内容
  6852. * @return { String } 编辑器的内容字符串
  6853. * @example
  6854. * ```javascript
  6855. * // editor 是一个编辑器的实例
  6856. * var content = editor.getContent( function ( editor ) {
  6857. * return editor.body.innerHTML === '欢迎使用UEditor'; //返回空字符串
  6858. * } );
  6859. * ```
  6860. */
  6861. getContent: function (cmd, fn,notSetCursor,ignoreBlank,formatter) {
  6862. var me = this;
  6863. if (cmd && utils.isFunction(cmd)) {
  6864. fn = cmd;
  6865. cmd = '';
  6866. }
  6867. if (fn ? !fn() : !this.hasContents()) {
  6868. return '';
  6869. }
  6870. me.fireEvent('beforegetcontent');
  6871. var root = UE.htmlparser(me.body.innerHTML,ignoreBlank);
  6872. me.filterOutputRule(root);
  6873. me.fireEvent('aftergetcontent', cmd,root);
  6874. return root.toHtml(formatter);
  6875. },
  6876. /**
  6877. * 取得完整的html代码,可以直接显示成完整的html文档
  6878. * @method getAllHtml
  6879. * @return { String } 编辑器的内容html文档字符串
  6880. * @eaxmple
  6881. * ```javascript
  6882. * editor.getAllHtml(); //返回格式大致是: <html><head>...</head><body>...</body></html>
  6883. * ```
  6884. */
  6885. getAllHtml: function () {
  6886. var me = this,
  6887. headHtml = [],
  6888. html = '';
  6889. me.fireEvent('getAllHtml', headHtml);
  6890. if (browser.ie && browser.version > 8) {
  6891. var headHtmlForIE9 = '';
  6892. utils.each(me.document.styleSheets, function (si) {
  6893. headHtmlForIE9 += ( si.href ? '<link rel="stylesheet" type="text/css" href="' + si.href + '" />' : '<style>' + si.cssText + '</style>');
  6894. });
  6895. utils.each(me.document.getElementsByTagName('script'), function (si) {
  6896. headHtmlForIE9 += si.outerHTML;
  6897. });
  6898. }
  6899. return '<html><head>' + (me.options.charset ? '<meta http-equiv="Content-Type" content="text/html; charset=' + me.options.charset + '"/>' : '')
  6900. + (headHtmlForIE9 || me.document.getElementsByTagName('head')[0].innerHTML) + headHtml.join('\n') + '</head>'
  6901. + '<body ' + (ie && browser.version < 9 ? 'class="view"' : '') + '>' + me.getContent(null, null, true) + '</body></html>';
  6902. },
  6903. /**
  6904. * 得到编辑器的纯文本内容,但会保留段落格式
  6905. * @method getPlainTxt
  6906. * @return { String } 编辑器带段落格式的纯文本内容字符串
  6907. * @example
  6908. * ```javascript
  6909. * //编辑器html内容:<p><strong>1</strong></p><p><strong>2</strong></p>
  6910. * console.log(editor.getPlainTxt()); //输出:"1\n2\n
  6911. * ```
  6912. */
  6913. getPlainTxt: function () {
  6914. var reg = new RegExp(domUtils.fillChar, 'g'),
  6915. html = this.body.innerHTML.replace(/[\n\r]/g, '');//ie要先去了\n在处理
  6916. html = html.replace(/<(p|div)[^>]*>(<br\/?>|&nbsp;)<\/\1>/gi, '\n')
  6917. .replace(/<br\/?>/gi, '\n')
  6918. .replace(/<[^>/]+>/g, '')
  6919. .replace(/(\n)?<\/([^>]+)>/g, function (a, b, c) {
  6920. return dtd.$block[c] ? '\n' : b ? b : '';
  6921. });
  6922. //取出来的空格会有c2a0会变成乱码,处理这种情况\u00a0
  6923. return html.replace(reg, '').replace(/\u00a0/g, ' ').replace(/&nbsp;/g, ' ');
  6924. },
  6925. /**
  6926. * 获取编辑器中的纯文本内容,没有段落格式
  6927. * @method getContentTxt
  6928. * @return { String } 编辑器不带段落格式的纯文本内容字符串
  6929. * @example
  6930. * ```javascript
  6931. * //编辑器html内容:<p><strong>1</strong></p><p><strong>2</strong></p>
  6932. * console.log(editor.getPlainTxt()); //输出:"12
  6933. * ```
  6934. */
  6935. getContentTxt: function () {
  6936. var reg = new RegExp(domUtils.fillChar, 'g');
  6937. //取出来的空格会有c2a0会变成乱码,处理这种情况\u00a0
  6938. return this.body[browser.ie ? 'innerText' : 'textContent'].replace(reg, '').replace(/\u00a0/g, ' ');
  6939. },
  6940. /**
  6941. * 设置编辑器的内容,可修改编辑器当前的html内容
  6942. * @method setContent
  6943. * @warning 通过该方法插入的内容,是经过编辑器内置的过滤规则进行过滤后得到的内容
  6944. * @warning 该方法会触发selectionchange事件
  6945. * @param { String } html 要插入的html内容
  6946. * @example
  6947. * ```javascript
  6948. * editor.getContent('<p>test</p>');
  6949. * ```
  6950. */
  6951. /**
  6952. * 设置编辑器的内容,可修改编辑器当前的html内容
  6953. * @method setContent
  6954. * @warning 通过该方法插入的内容,是经过编辑器内置的过滤规则进行过滤后得到的内容
  6955. * @warning 该方法会触发selectionchange事件
  6956. * @param { String } html 要插入的html内容
  6957. * @param { Boolean } isAppendTo 若传入true,不清空原来的内容,在最后插入内容,否则,清空内容再插入
  6958. * @example
  6959. * ```javascript
  6960. * //假设设置前的编辑器内容是 <p>old text</p>
  6961. * editor.setContent('<p>new text</p>', true); //插入的结果是<p>old text</p><p>new text</p>
  6962. * ```
  6963. */
  6964. setContent: function (html, isAppendTo, notFireSelectionchange) {
  6965. var me = this;
  6966. me.fireEvent('beforesetcontent', html);
  6967. var root = UE.htmlparser(html);
  6968. me.filterInputRule(root);
  6969. html = root.toHtml();
  6970. me.body.innerHTML = (isAppendTo ? me.body.innerHTML : '') + html;
  6971. function isCdataDiv(node){
  6972. return node.tagName == 'DIV' && node.getAttribute('cdata_tag');
  6973. }
  6974. //给文本或者inline节点套p标签
  6975. if (me.options.enterTag == 'p') {
  6976. var child = this.body.firstChild, tmpNode;
  6977. if (!child || child.nodeType == 1 &&
  6978. (dtd.$cdata[child.tagName] || isCdataDiv(child) ||
  6979. domUtils.isCustomeNode(child)
  6980. )
  6981. && child === this.body.lastChild) {
  6982. this.body.innerHTML = '<p>' + (browser.ie ? '&nbsp;' : '<br/>') + '</p>' + this.body.innerHTML;
  6983. } else {
  6984. var p = me.document.createElement('p');
  6985. while (child) {
  6986. while (child && (child.nodeType == 3 || child.nodeType == 1 && dtd.p[child.tagName] && !dtd.$cdata[child.tagName])) {
  6987. tmpNode = child.nextSibling;
  6988. p.appendChild(child);
  6989. child = tmpNode;
  6990. }
  6991. if (p.firstChild) {
  6992. if (!child) {
  6993. me.body.appendChild(p);
  6994. break;
  6995. } else {
  6996. child.parentNode.insertBefore(p, child);
  6997. p = me.document.createElement('p');
  6998. }
  6999. }
  7000. child = child.nextSibling;
  7001. }
  7002. }
  7003. }
  7004. me.fireEvent('aftersetcontent');
  7005. me.fireEvent('contentchange');
  7006. !notFireSelectionchange && me._selectionChange();
  7007. //清除保存的选区
  7008. me._bakRange = me._bakIERange = me._bakNativeRange = null;
  7009. //trace:1742 setContent后gecko能得到焦点问题
  7010. var geckoSel;
  7011. if (browser.gecko && (geckoSel = this.selection.getNative())) {
  7012. geckoSel.removeAllRanges();
  7013. }
  7014. if(me.options.autoSyncData){
  7015. me.form && setValue(me.form,me);
  7016. }
  7017. },
  7018. /**
  7019. * 让编辑器获得焦点,默认focus到编辑器头部
  7020. * @method focus
  7021. * @example
  7022. * ```javascript
  7023. * editor.focus()
  7024. * ```
  7025. */
  7026. /**
  7027. * 让编辑器获得焦点,toEnd确定focus位置
  7028. * @method focus
  7029. * @param { Boolean } toEnd 默认focus到编辑器头部,toEnd为true时focus到内容尾部
  7030. * @example
  7031. * ```javascript
  7032. * editor.focus(true)
  7033. * ```
  7034. */
  7035. focus: function (toEnd) {
  7036. try {
  7037. var me = this,
  7038. rng = me.selection.getRange();
  7039. if (toEnd) {
  7040. var node = me.body.lastChild;
  7041. if(node && node.nodeType == 1 && !dtd.$empty[node.tagName]){
  7042. if(domUtils.isEmptyBlock(node)){
  7043. rng.setStartAtFirst(node)
  7044. }else{
  7045. rng.setStartAtLast(node)
  7046. }
  7047. rng.collapse(true);
  7048. }
  7049. rng.setCursor(true);
  7050. } else {
  7051. if(!rng.collapsed && domUtils.isBody(rng.startContainer) && rng.startOffset == 0){
  7052. var node = me.body.firstChild;
  7053. if(node && node.nodeType == 1 && !dtd.$empty[node.tagName]){
  7054. rng.setStartAtFirst(node).collapse(true);
  7055. }
  7056. }
  7057. rng.select(true);
  7058. }
  7059. this.fireEvent('focus selectionchange');
  7060. } catch (e) {
  7061. }
  7062. },
  7063. isFocus:function(){
  7064. return this.selection.isFocus();
  7065. },
  7066. blur:function(){
  7067. var sel = this.selection.getNative();
  7068. if(sel.empty && browser.ie){
  7069. var nativeRng = document.body.createTextRange();
  7070. nativeRng.moveToElementText(document.body);
  7071. nativeRng.collapse(true);
  7072. nativeRng.select();
  7073. sel.empty()
  7074. }else{
  7075. sel.removeAllRanges()
  7076. }
  7077. //this.fireEvent('blur selectionchange');
  7078. },
  7079. /**
  7080. * 初始化UE事件及部分事件代理
  7081. * @method _initEvents
  7082. * @private
  7083. */
  7084. _initEvents: function () {
  7085. var me = this,
  7086. doc = me.document,
  7087. win = me.window;
  7088. me._proxyDomEvent = utils.bind(me._proxyDomEvent, me);
  7089. domUtils.on(doc, ['click', 'contextmenu', 'mousedown', 'keydown', 'keyup', 'keypress', 'mouseup', 'mouseover', 'mouseout', 'selectstart'], me._proxyDomEvent);
  7090. domUtils.on(win, ['focus', 'blur'], me._proxyDomEvent);
  7091. domUtils.on(me.body,'drop',function(e){
  7092. //阻止ff下默认的弹出新页面打开图片
  7093. if(browser.gecko && e.stopPropagation) { e.stopPropagation(); }
  7094. me.fireEvent('contentchange')
  7095. });
  7096. domUtils.on(doc, ['mouseup', 'keydown'], function (evt) {
  7097. //特殊键不触发selectionchange
  7098. if (evt.type == 'keydown' && (evt.ctrlKey || evt.metaKey || evt.shiftKey || evt.altKey)) {
  7099. return;
  7100. }
  7101. if (evt.button == 2)return;
  7102. me._selectionChange(250, evt);
  7103. });
  7104. },
  7105. /**
  7106. * 触发事件代理
  7107. * @method _proxyDomEvent
  7108. * @private
  7109. * @return { * } fireEvent的返回值
  7110. * @see UE.EventBase:fireEvent(String)
  7111. */
  7112. _proxyDomEvent: function (evt) {
  7113. if(this.fireEvent('before' + evt.type.replace(/^on/, '').toLowerCase()) === false){
  7114. return false;
  7115. }
  7116. if(this.fireEvent(evt.type.replace(/^on/, ''), evt) === false){
  7117. return false;
  7118. }
  7119. return this.fireEvent('after' + evt.type.replace(/^on/, '').toLowerCase())
  7120. },
  7121. /**
  7122. * 变化选区
  7123. * @method _selectionChange
  7124. * @private
  7125. */
  7126. _selectionChange: function (delay, evt) {
  7127. var me = this;
  7128. //有光标才做selectionchange 为了解决未focus时点击source不能触发更改工具栏状态的问题(source命令notNeedUndo=1)
  7129. // if ( !me.selection.isFocus() ){
  7130. // return;
  7131. // }
  7132. var hackForMouseUp = false;
  7133. var mouseX, mouseY;
  7134. if (browser.ie && browser.version < 9 && evt && evt.type == 'mouseup') {
  7135. var range = this.selection.getRange();
  7136. if (!range.collapsed) {
  7137. hackForMouseUp = true;
  7138. mouseX = evt.clientX;
  7139. mouseY = evt.clientY;
  7140. }
  7141. }
  7142. clearTimeout(_selectionChangeTimer);
  7143. _selectionChangeTimer = setTimeout(function () {
  7144. if (!me.selection || !me.selection.getNative()) {
  7145. return;
  7146. }
  7147. //修复一个IE下的bug: 鼠标点击一段已选择的文本中间时,可能在mouseup后的一段时间内取到的range是在selection的type为None下的错误值.
  7148. //IE下如果用户是拖拽一段已选择文本,则不会触发mouseup事件,所以这里的特殊处理不会对其有影响
  7149. var ieRange;
  7150. if (hackForMouseUp && me.selection.getNative().type == 'None') {
  7151. ieRange = me.document.body.createTextRange();
  7152. try {
  7153. ieRange.moveToPoint(mouseX, mouseY);
  7154. } catch (ex) {
  7155. ieRange = null;
  7156. }
  7157. }
  7158. var bakGetIERange;
  7159. if (ieRange) {
  7160. bakGetIERange = me.selection.getIERange;
  7161. me.selection.getIERange = function () {
  7162. return ieRange;
  7163. };
  7164. }
  7165. me.selection.cache();
  7166. if (bakGetIERange) {
  7167. me.selection.getIERange = bakGetIERange;
  7168. }
  7169. if (me.selection._cachedRange && me.selection._cachedStartElement) {
  7170. me.fireEvent('beforeselectionchange');
  7171. // 第二个参数causeByUi为true代表由用户交互造成的selectionchange.
  7172. me.fireEvent('selectionchange', !!evt);
  7173. me.fireEvent('afterselectionchange');
  7174. me.selection.clear();
  7175. }
  7176. }, delay || 50);
  7177. },
  7178. /**
  7179. * 执行编辑命令
  7180. * @method _callCmdFn
  7181. * @private
  7182. * @param { String } fnName 函数名称
  7183. * @param { * } args 传给命令函数的参数
  7184. * @return { * } 返回命令函数运行的返回值
  7185. */
  7186. _callCmdFn: function (fnName, args) {
  7187. var cmdName = args[0].toLowerCase(),
  7188. cmd, cmdFn;
  7189. cmd = this.commands[cmdName] || UE.commands[cmdName];
  7190. cmdFn = cmd && cmd[fnName];
  7191. //没有querycommandstate或者没有command的都默认返回0
  7192. if ((!cmd || !cmdFn) && fnName == 'queryCommandState') {
  7193. return 0;
  7194. } else if (cmdFn) {
  7195. return cmdFn.apply(this, args);
  7196. }
  7197. },
  7198. /**
  7199. * 执行编辑命令cmdName,完成富文本编辑效果
  7200. * @method execCommand
  7201. * @param { String } cmdName 需要执行的命令
  7202. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  7203. * @return { * } 返回命令函数运行的返回值
  7204. * @example
  7205. * ```javascript
  7206. * editor.execCommand(cmdName);
  7207. * ```
  7208. */
  7209. execCommand: function (cmdName) {
  7210. cmdName = cmdName.toLowerCase();
  7211. var me = this,
  7212. result,
  7213. cmd = me.commands[cmdName] || UE.commands[cmdName];
  7214. if (!cmd || !cmd.execCommand) {
  7215. return null;
  7216. }
  7217. if (!cmd.notNeedUndo && !me.__hasEnterExecCommand) {
  7218. me.__hasEnterExecCommand = true;
  7219. if (me.queryCommandState.apply(me,arguments) != -1) {
  7220. me.fireEvent('saveScene');
  7221. me.fireEvent.apply(me, ['beforeexeccommand', cmdName].concat(arguments));
  7222. result = this._callCmdFn('execCommand', arguments);
  7223. //保存场景时,做了内容对比,再看是否进行contentchange触发,这里多触发了一次,去掉
  7224. // (!cmd.ignoreContentChange && !me._ignoreContentChange) && me.fireEvent('contentchange');
  7225. me.fireEvent.apply(me, ['afterexeccommand', cmdName].concat(arguments));
  7226. me.fireEvent('saveScene');
  7227. }
  7228. me.__hasEnterExecCommand = false;
  7229. } else {
  7230. result = this._callCmdFn('execCommand', arguments);
  7231. (!me.__hasEnterExecCommand && !cmd.ignoreContentChange && !me._ignoreContentChange) && me.fireEvent('contentchange')
  7232. }
  7233. (!me.__hasEnterExecCommand && !cmd.ignoreContentChange && !me._ignoreContentChange) && me._selectionChange();
  7234. return result;
  7235. },
  7236. /**
  7237. * 根据传入的command命令,查选编辑器当前的选区,返回命令的状态
  7238. * @method queryCommandState
  7239. * @param { String } cmdName 需要查询的命令名称
  7240. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  7241. * @return { Number } number 返回放前命令的状态,返回值三种情况:(-1|0|1)
  7242. * @example
  7243. * ```javascript
  7244. * editor.queryCommandState(cmdName) => (-1|0|1)
  7245. * ```
  7246. * @see COMMAND.LIST
  7247. */
  7248. queryCommandState: function (cmdName) {
  7249. return this._callCmdFn('queryCommandState', arguments);
  7250. },
  7251. /**
  7252. * 根据传入的command命令,查选编辑器当前的选区,根据命令返回相关的值
  7253. * @method queryCommandValue
  7254. * @param { String } cmdName 需要查询的命令名称
  7255. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  7256. * @remind 只有部分插件有此方法
  7257. * @return { * } 返回每个命令特定的当前状态值
  7258. * @grammar editor.queryCommandValue(cmdName) => {*}
  7259. * @see COMMAND.LIST
  7260. */
  7261. queryCommandValue: function (cmdName) {
  7262. return this._callCmdFn('queryCommandValue', arguments);
  7263. },
  7264. /**
  7265. * 检查编辑区域中是否有内容
  7266. * @method hasContents
  7267. * @remind 默认有文本内容,或者有以下节点都不认为是空
  7268. * table,ul,ol,dl,iframe,area,base,col,hr,img,embed,input,link,meta,param
  7269. * @return { Boolean } 检查有内容返回true,否则返回false
  7270. * @example
  7271. * ```javascript
  7272. * editor.hasContents()
  7273. * ```
  7274. */
  7275. /**
  7276. * 检查编辑区域中是否有内容,若包含参数tags中的节点类型,直接返回true
  7277. * @method hasContents
  7278. * @param { Array } tags 传入数组判断时用到的节点类型
  7279. * @return { Boolean } 若文档中包含tags数组里对应的tag,返回true,否则返回false
  7280. * @example
  7281. * ```javascript
  7282. * editor.hasContents(['span']);
  7283. * ```
  7284. */
  7285. hasContents: function (tags) {
  7286. if (tags) {
  7287. for (var i = 0, ci; ci = tags[i++];) {
  7288. if (this.document.getElementsByTagName(ci).length > 0) {
  7289. return true;
  7290. }
  7291. }
  7292. }
  7293. if (!domUtils.isEmptyBlock(this.body)) {
  7294. return true
  7295. }
  7296. //随时添加,定义的特殊标签如果存在,不能认为是空
  7297. tags = ['div'];
  7298. for (i = 0; ci = tags[i++];) {
  7299. var nodes = domUtils.getElementsByTagName(this.document, ci);
  7300. for (var n = 0, cn; cn = nodes[n++];) {
  7301. if (domUtils.isCustomeNode(cn)) {
  7302. return true;
  7303. }
  7304. }
  7305. }
  7306. return false;
  7307. },
  7308. /**
  7309. * 重置编辑器,可用来做多个tab使用同一个编辑器实例
  7310. * @method reset
  7311. * @remind 此方法会清空编辑器内容,清空回退列表,会触发reset事件
  7312. * @example
  7313. * ```javascript
  7314. * editor.reset()
  7315. * ```
  7316. */
  7317. reset: function () {
  7318. this.fireEvent('reset');
  7319. },
  7320. /**
  7321. * 设置当前编辑区域可以编辑
  7322. * @method setEnabled
  7323. * @example
  7324. * ```javascript
  7325. * editor.setEnabled()
  7326. * ```
  7327. */
  7328. setEnabled: function () {
  7329. var me = this, range;
  7330. if (me.body.contentEditable == 'false') {
  7331. me.body.contentEditable = true;
  7332. range = me.selection.getRange();
  7333. //有可能内容丢失了
  7334. try {
  7335. range.moveToBookmark(me.lastBk);
  7336. delete me.lastBk
  7337. } catch (e) {
  7338. range.setStartAtFirst(me.body).collapse(true)
  7339. }
  7340. range.select(true);
  7341. if (me.bkqueryCommandState) {
  7342. me.queryCommandState = me.bkqueryCommandState;
  7343. delete me.bkqueryCommandState;
  7344. }
  7345. if (me.bkqueryCommandValue) {
  7346. me.queryCommandValue = me.bkqueryCommandValue;
  7347. delete me.bkqueryCommandValue;
  7348. }
  7349. me.fireEvent('selectionchange');
  7350. }
  7351. },
  7352. enable: function () {
  7353. return this.setEnabled();
  7354. },
  7355. /** 设置当前编辑区域不可编辑
  7356. * @method setDisabled
  7357. */
  7358. /** 设置当前编辑区域不可编辑,except中的命令除外
  7359. * @method setDisabled
  7360. * @param { String } except 例外命令的字符串
  7361. * @remind 即使设置了disable,此处配置的例外命令仍然可以执行
  7362. * @example
  7363. * ```javascript
  7364. * editor.setDisabled('bold'); //禁用工具栏中除加粗之外的所有功能
  7365. * ```
  7366. */
  7367. /** 设置当前编辑区域不可编辑,except中的命令除外
  7368. * @method setDisabled
  7369. * @param { Array } except 例外命令的字符串数组,数组中的命令仍然可以执行
  7370. * @remind 即使设置了disable,此处配置的例外命令仍然可以执行
  7371. * @example
  7372. * ```javascript
  7373. * editor.setDisabled(['bold','insertimage']); //禁用工具栏中除加粗和插入图片之外的所有功能
  7374. * ```
  7375. */
  7376. setDisabled: function (except) {
  7377. var me = this;
  7378. except = except ? utils.isArray(except) ? except : [except] : [];
  7379. if (me.body.contentEditable == 'true') {
  7380. if (!me.lastBk) {
  7381. me.lastBk = me.selection.getRange().createBookmark(true);
  7382. }
  7383. me.body.contentEditable = false;
  7384. me.bkqueryCommandState = me.queryCommandState;
  7385. me.bkqueryCommandValue = me.queryCommandValue;
  7386. me.queryCommandState = function (type) {
  7387. if (utils.indexOf(except, type) != -1) {
  7388. return me.bkqueryCommandState.apply(me, arguments);
  7389. }
  7390. return -1;
  7391. };
  7392. me.queryCommandValue = function (type) {
  7393. if (utils.indexOf(except, type) != -1) {
  7394. return me.bkqueryCommandValue.apply(me, arguments);
  7395. }
  7396. return null;
  7397. };
  7398. me.fireEvent('selectionchange');
  7399. }
  7400. },
  7401. disable: function (except) {
  7402. return this.setDisabled(except);
  7403. },
  7404. /**
  7405. * 设置默认内容
  7406. * @method _setDefaultContent
  7407. * @private
  7408. * @param { String } cont 要存入的内容
  7409. */
  7410. _setDefaultContent: function () {
  7411. function clear() {
  7412. var me = this;
  7413. if (me.document.getElementById('initContent')) {
  7414. me.body.innerHTML = '<p>' + (ie ? '' : '<br/>') + '</p>';
  7415. me.removeListener('firstBeforeExecCommand focus', clear);
  7416. setTimeout(function () {
  7417. me.focus();
  7418. me._selectionChange();
  7419. }, 0)
  7420. }
  7421. }
  7422. return function (cont) {
  7423. var me = this;
  7424. me.body.innerHTML = '<p id="initContent">' + cont + '</p>';
  7425. me.addListener('firstBeforeExecCommand focus', clear);
  7426. }
  7427. }(),
  7428. /**
  7429. * 显示编辑器
  7430. * @method setShow
  7431. * @example
  7432. * ```javascript
  7433. * editor.setShow()
  7434. * ```
  7435. */
  7436. setShow: function () {
  7437. var me = this, range = me.selection.getRange();
  7438. if (me.container.style.display == 'none') {
  7439. //有可能内容丢失了
  7440. try {
  7441. range.moveToBookmark(me.lastBk);
  7442. delete me.lastBk
  7443. } catch (e) {
  7444. range.setStartAtFirst(me.body).collapse(true)
  7445. }
  7446. //ie下focus实效,所以做了个延迟
  7447. setTimeout(function () {
  7448. range.select(true);
  7449. }, 100);
  7450. me.container.style.display = '';
  7451. }
  7452. },
  7453. show: function () {
  7454. return this.setShow();
  7455. },
  7456. /**
  7457. * 隐藏编辑器
  7458. * @method setHide
  7459. * @example
  7460. * ```javascript
  7461. * editor.setHide()
  7462. * ```
  7463. */
  7464. setHide: function () {
  7465. var me = this;
  7466. if (!me.lastBk) {
  7467. me.lastBk = me.selection.getRange().createBookmark(true);
  7468. }
  7469. me.container.style.display = 'none'
  7470. },
  7471. hide: function () {
  7472. return this.setHide();
  7473. },
  7474. /**
  7475. * 根据指定的路径,获取对应的语言资源
  7476. * @method getLang
  7477. * @param { String } path 路径根据的是lang目录下的语言文件的路径结构
  7478. * @return { Object | String } 根据路径返回语言资源的Json格式对象或者语言字符串
  7479. * @example
  7480. * ```javascript
  7481. * editor.getLang('contextMenu.delete'); //如果当前是中文,那返回是的是'删除'
  7482. * ```
  7483. */
  7484. getLang: function (path) {
  7485. var lang = UE.I18N[this.options.lang];
  7486. if (!lang) {
  7487. throw Error("not import language file");
  7488. }
  7489. path = (path || "").split(".");
  7490. for (var i = 0, ci; ci = path[i++];) {
  7491. lang = lang[ci];
  7492. if (!lang)break;
  7493. }
  7494. return lang;
  7495. },
  7496. /**
  7497. * 计算编辑器html内容字符串的长度
  7498. * @method getContentLength
  7499. * @return { Number } 返回计算的长度
  7500. * @example
  7501. * ```javascript
  7502. * //编辑器html内容<p><strong>132</strong></p>
  7503. * editor.getContentLength() //返回27
  7504. * ```
  7505. */
  7506. /**
  7507. * 计算编辑器当前纯文本内容的长度
  7508. * @method getContentLength
  7509. * @param { Boolean } ingoneHtml 传入true时,只按照纯文本来计算
  7510. * @return { Number } 返回计算的长度,内容中有hr/img/iframe标签,长度加1
  7511. * @example
  7512. * ```javascript
  7513. * //编辑器html内容<p><strong>132</strong></p>
  7514. * editor.getContentLength() //返回3
  7515. * ```
  7516. */
  7517. getContentLength: function (ingoneHtml, tagNames) {
  7518. var count = this.getContent(false,false,true).length;
  7519. if (ingoneHtml) {
  7520. tagNames = (tagNames || []).concat([ 'hr', 'img', 'iframe']);
  7521. count = this.getContentTxt().replace(/[\t\r\n]+/g, '').length;
  7522. for (var i = 0, ci; ci = tagNames[i++];) {
  7523. count += this.document.getElementsByTagName(ci).length;
  7524. }
  7525. }
  7526. return count;
  7527. },
  7528. /**
  7529. * 注册输入过滤规则
  7530. * @method addInputRule
  7531. * @param { Function } rule 要添加的过滤规则
  7532. * @example
  7533. * ```javascript
  7534. * editor.addInputRule(function(root){
  7535. * $.each(root.getNodesByTagName('div'),function(i,node){
  7536. * node.tagName="p";
  7537. * });
  7538. * });
  7539. * ```
  7540. */
  7541. addInputRule: function (rule) {
  7542. this.inputRules.push(rule);
  7543. },
  7544. /**
  7545. * 执行注册的过滤规则
  7546. * @method filterInputRule
  7547. * @param { UE.uNode } root 要过滤的uNode节点
  7548. * @remind 执行editor.setContent方法和执行'inserthtml'命令后,会运行该过滤函数
  7549. * @example
  7550. * ```javascript
  7551. * editor.filterInputRule(editor.body);
  7552. * ```
  7553. * @see UE.Editor:addInputRule
  7554. */
  7555. filterInputRule: function (root) {
  7556. for (var i = 0, ci; ci = this.inputRules[i++];) {
  7557. ci.call(this, root)
  7558. }
  7559. },
  7560. /**
  7561. * 注册输出过滤规则
  7562. * @method addOutputRule
  7563. * @param { Function } rule 要添加的过滤规则
  7564. * @example
  7565. * ```javascript
  7566. * editor.addOutputRule(function(root){
  7567. * $.each(root.getNodesByTagName('p'),function(i,node){
  7568. * node.tagName="div";
  7569. * });
  7570. * });
  7571. * ```
  7572. */
  7573. addOutputRule: function (rule) {
  7574. this.outputRules.push(rule)
  7575. },
  7576. /**
  7577. * 根据输出过滤规则,过滤编辑器内容
  7578. * @method filterOutputRule
  7579. * @remind 执行editor.getContent方法的时候,会先运行该过滤函数
  7580. * @param { UE.uNode } root 要过滤的uNode节点
  7581. * @example
  7582. * ```javascript
  7583. * editor.filterOutputRule(editor.body);
  7584. * ```
  7585. * @see UE.Editor:addOutputRule
  7586. */
  7587. filterOutputRule: function (root) {
  7588. for (var i = 0, ci; ci = this.outputRules[i++];) {
  7589. ci.call(this, root)
  7590. }
  7591. },
  7592. /**
  7593. * 根据action名称获取请求的路径
  7594. * @method getActionUrl
  7595. * @remind 假如没有设置serverUrl,会根据imageUrl设置默认的controller路径
  7596. * @param { String } action action名称
  7597. * @example
  7598. * ```javascript
  7599. * editor.getActionUrl('config'); //返回 "/ueditor/php/controller.php?action=config"
  7600. * editor.getActionUrl('image'); //返回 "/ueditor/php/controller.php?action=uplaodimage"
  7601. * editor.getActionUrl('scrawl'); //返回 "/ueditor/php/controller.php?action=uplaodscrawl"
  7602. * editor.getActionUrl('imageManager'); //返回 "/ueditor/php/controller.php?action=listimage"
  7603. * ```
  7604. */
  7605. getActionUrl: function(action){
  7606. var actionName = this.getOpt(action) || action,
  7607. imageUrl = this.getOpt('imageUrl'),
  7608. serverUrl = this.getOpt('serverUrl');
  7609. if(!serverUrl && imageUrl) {
  7610. serverUrl = imageUrl.replace(/^(.*[\/]).+([\.].+)$/, '$1controller$2');
  7611. }
  7612. if(serverUrl) {
  7613. serverUrl = serverUrl + (serverUrl.indexOf('?') == -1 ? '?':'&') + 'action=' + (actionName || '');
  7614. return utils.formatUrl(serverUrl);
  7615. } else {
  7616. return '';
  7617. }
  7618. }
  7619. };
  7620. utils.inherits(Editor, EventBase);
  7621. })();
  7622. // js/editor/_src/core/Editor.defaultoptions.js
  7623. //维护编辑器一下默认的不在插件中的配置项
  7624. UE.Editor.defaultOptions = function(editor){
  7625. var _url = editor.options.UEDITOR_HOME_URL;
  7626. return {
  7627. isShow: true,
  7628. initialContent: '',
  7629. initialStyle:'',
  7630. autoClearinitialContent: false,
  7631. iframeCssUrl: _url + 'themes/iframe.css',
  7632. textarea: 'editorValue',
  7633. focus: false,
  7634. focusInEnd: true,
  7635. autoClearEmptyNode: true,
  7636. fullscreen: false,
  7637. readonly: false,
  7638. zIndex: 999,
  7639. imagePopup: true,
  7640. enterTag: 'p',
  7641. customDomain: false,
  7642. lang: 'zh-cn',
  7643. langPath: _url + 'lang/',
  7644. theme: 'default',
  7645. themePath: _url + 'themes/',
  7646. allHtmlEnabled: false,
  7647. scaleEnabled: false,
  7648. tableNativeEditInFF: false,
  7649. autoSyncData : true,
  7650. fileNameFormat: '{time}{rand:6}'
  7651. }
  7652. };
  7653. // js/editor/_src/core/loadconfig.js
  7654. (function(){
  7655. UE.Editor.prototype.loadServerConfig = function(){
  7656. var me = this;
  7657. setTimeout(function(){
  7658. try{
  7659. me.options.imageUrl && me.setOpt('serverUrl', me.options.imageUrl.replace(/^(.*[\/]).+([\.].+)$/, '$1controller$2'));
  7660. var configUrl = me.getActionUrl('config'),
  7661. isJsonp = utils.isCrossDomainUrl(configUrl);
  7662. /* 发出ajax请求 */
  7663. me._serverConfigLoaded = false;
  7664. configUrl && UE.ajax.request(configUrl,{
  7665. 'method': 'GET',
  7666. 'dataType': isJsonp ? 'jsonp':'',
  7667. 'onsuccess':function(r){
  7668. try {
  7669. var config = isJsonp ? r:eval("("+r.responseText+")");
  7670. utils.extend(me.options, config);
  7671. me.fireEvent('serverConfigLoaded');
  7672. me._serverConfigLoaded = true;
  7673. } catch (e) {
  7674. showErrorMsg(me.getLang('loadconfigFormatError'));
  7675. }
  7676. },
  7677. 'onerror':function(){
  7678. showErrorMsg(me.getLang('loadconfigHttpError'));
  7679. }
  7680. });
  7681. } catch(e){
  7682. showErrorMsg(me.getLang('loadconfigError'));
  7683. }
  7684. });
  7685. function showErrorMsg(msg) {
  7686. console && console.error(msg);
  7687. //me.fireEvent('showMessage', {
  7688. // 'title': msg,
  7689. // 'type': 'error'
  7690. //});
  7691. }
  7692. };
  7693. UE.Editor.prototype.isServerConfigLoaded = function(){
  7694. var me = this;
  7695. return me._serverConfigLoaded || false;
  7696. };
  7697. UE.Editor.prototype.afterConfigReady = function(handler){
  7698. if (!handler || !utils.isFunction(handler)) return;
  7699. var me = this;
  7700. var readyHandler = function(){
  7701. handler.apply(me, arguments);
  7702. me.removeListener('serverConfigLoaded', readyHandler);
  7703. };
  7704. if (me.isServerConfigLoaded()) {
  7705. handler.call(me, 'serverConfigLoaded');
  7706. } else {
  7707. me.addListener('serverConfigLoaded', readyHandler);
  7708. }
  7709. };
  7710. })();
  7711. // js/editor/_src/core/ajax.js
  7712. /**
  7713. * @file
  7714. * @module UE.ajax
  7715. * @since 1.2.6.1
  7716. */
  7717. /**
  7718. * 提供对ajax请求的支持
  7719. * @module UE.ajax
  7720. */
  7721. UE.ajax = function() {
  7722. //创建一个ajaxRequest对象
  7723. var fnStr = 'XMLHttpRequest()';
  7724. try {
  7725. new ActiveXObject("Msxml2.XMLHTTP");
  7726. fnStr = 'ActiveXObject(\'Msxml2.XMLHTTP\')';
  7727. } catch (e) {
  7728. try {
  7729. new ActiveXObject("Microsoft.XMLHTTP");
  7730. fnStr = 'ActiveXObject(\'Microsoft.XMLHTTP\')'
  7731. } catch (e) {
  7732. }
  7733. }
  7734. var creatAjaxRequest = new Function('return new ' + fnStr);
  7735. /**
  7736. * 将json参数转化成适合ajax提交的参数列表
  7737. * @param json
  7738. */
  7739. function json2str(json) {
  7740. var strArr = [];
  7741. for (var i in json) {
  7742. //忽略默认的几个参数
  7743. if(i=="method" || i=="timeout" || i=="async" || i=="dataType" || i=="callback") continue;
  7744. //忽略控制
  7745. if(json[i] == undefined || json[i] == null) continue;
  7746. //传递过来的对象和函数不在提交之列
  7747. if (!((typeof json[i]).toLowerCase() == "function" || (typeof json[i]).toLowerCase() == "object")) {
  7748. strArr.push( encodeURIComponent(i) + "="+encodeURIComponent(json[i]) );
  7749. } else if (utils.isArray(json[i])) {
  7750. //支持传数组内容
  7751. for(var j = 0; j < json[i].length; j++) {
  7752. strArr.push( encodeURIComponent(i) + "[]="+encodeURIComponent(json[i][j]) );
  7753. }
  7754. }
  7755. }
  7756. return strArr.join("&");
  7757. }
  7758. function doAjax(url, ajaxOptions) {
  7759. var xhr = creatAjaxRequest(),
  7760. //是否超时
  7761. timeIsOut = false,
  7762. //默认参数
  7763. defaultAjaxOptions = {
  7764. method:"POST",
  7765. timeout:5000,
  7766. async:true,
  7767. data:{},//需要传递对象的话只能覆盖
  7768. onsuccess:function() {
  7769. },
  7770. onerror:function() {
  7771. }
  7772. };
  7773. if (typeof url === "object") {
  7774. ajaxOptions = url;
  7775. url = ajaxOptions.url;
  7776. }
  7777. if (!xhr || !url) return;
  7778. var ajaxOpts = ajaxOptions ? utils.extend(defaultAjaxOptions,ajaxOptions) : defaultAjaxOptions;
  7779. var submitStr = json2str(ajaxOpts); // { name:"Jim",city:"Beijing" } --> "name=Jim&city=Beijing"
  7780. //如果用户直接通过data参数传递json对象过来,则也要将此json对象转化为字符串
  7781. if (!utils.isEmptyObject(ajaxOpts.data)){
  7782. submitStr += (submitStr? "&":"") + json2str(ajaxOpts.data);
  7783. }
  7784. //超时检测
  7785. var timerID = setTimeout(function() {
  7786. if (xhr.readyState != 4) {
  7787. timeIsOut = true;
  7788. xhr.abort();
  7789. clearTimeout(timerID);
  7790. }
  7791. }, ajaxOpts.timeout);
  7792. var method = ajaxOpts.method.toUpperCase();
  7793. var str = url + (url.indexOf("?")==-1?"?":"&") + (method=="POST"?"":submitStr+ "&noCache=" + +new Date);
  7794. xhr.open(method, str, ajaxOpts.async);
  7795. xhr.onreadystatechange = function() {
  7796. if (xhr.readyState == 4) {
  7797. if (!timeIsOut && xhr.status == 200) {
  7798. ajaxOpts.onsuccess(xhr);
  7799. } else {
  7800. ajaxOpts.onerror(xhr);
  7801. }
  7802. }
  7803. };
  7804. if (method == "POST") {
  7805. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  7806. xhr.send(submitStr);
  7807. } else {
  7808. xhr.send(null);
  7809. }
  7810. }
  7811. function doJsonp(url, opts) {
  7812. var successhandler = opts.onsuccess || function(){},
  7813. scr = document.createElement('SCRIPT'),
  7814. options = opts || {},
  7815. charset = options['charset'],
  7816. callbackField = options['jsonp'] || 'callback',
  7817. callbackFnName,
  7818. timeOut = options['timeOut'] || 0,
  7819. timer,
  7820. reg = new RegExp('(\\?|&)' + callbackField + '=([^&]*)'),
  7821. matches;
  7822. if (utils.isFunction(successhandler)) {
  7823. callbackFnName = 'bd__editor__' + Math.floor(Math.random() * 2147483648).toString(36);
  7824. window[callbackFnName] = getCallBack(0);
  7825. } else if(utils.isString(successhandler)){
  7826. callbackFnName = successhandler;
  7827. } else {
  7828. if (matches = reg.exec(url)) {
  7829. callbackFnName = matches[2];
  7830. }
  7831. }
  7832. url = url.replace(reg, '\x241' + callbackField + '=' + callbackFnName);
  7833. if (url.search(reg) < 0) {
  7834. url += (url.indexOf('?') < 0 ? '?' : '&') + callbackField + '=' + callbackFnName;
  7835. }
  7836. var queryStr = json2str(opts); // { name:"Jim",city:"Beijing" } --> "name=Jim&city=Beijing"
  7837. //如果用户直接通过data参数传递json对象过来,则也要将此json对象转化为字符串
  7838. if (!utils.isEmptyObject(opts.data)){
  7839. queryStr += (queryStr? "&":"") + json2str(opts.data);
  7840. }
  7841. if (queryStr) {
  7842. url = url.replace(/\?/, '?' + queryStr + '&');
  7843. }
  7844. scr.onerror = getCallBack(1);
  7845. if( timeOut ){
  7846. timer = setTimeout(getCallBack(1), timeOut);
  7847. }
  7848. createScriptTag(scr, url, charset);
  7849. function createScriptTag(scr, url, charset) {
  7850. scr.setAttribute('type', 'text/javascript');
  7851. scr.setAttribute('defer', 'defer');
  7852. charset && scr.setAttribute('charset', charset);
  7853. scr.setAttribute('src', url);
  7854. document.getElementsByTagName('head')[0].appendChild(scr);
  7855. }
  7856. function getCallBack(onTimeOut){
  7857. return function(){
  7858. try {
  7859. if(onTimeOut){
  7860. options.onerror && options.onerror();
  7861. }else{
  7862. try{
  7863. clearTimeout(timer);
  7864. successhandler.apply(window, arguments);
  7865. } catch (e){}
  7866. }
  7867. } catch (exception) {
  7868. options.onerror && options.onerror.call(window, exception);
  7869. } finally {
  7870. options.oncomplete && options.oncomplete.apply(window, arguments);
  7871. scr.parentNode && scr.parentNode.removeChild(scr);
  7872. window[callbackFnName] = null;
  7873. try {
  7874. delete window[callbackFnName];
  7875. }catch(e){}
  7876. }
  7877. }
  7878. }
  7879. }
  7880. return {
  7881. /**
  7882. * 根据给定的参数项,向指定的url发起一个ajax请求。 ajax请求完成后,会根据请求结果调用相应回调: 如果请求
  7883. * 成功, 则调用onsuccess回调, 失败则调用 onerror 回调
  7884. * @method request
  7885. * @param { URLString } url ajax请求的url地址
  7886. * @param { Object } ajaxOptions ajax请求选项的键值对,支持的选项如下:
  7887. * @example
  7888. * ```javascript
  7889. * //向sayhello.php发起一个异步的Ajax GET请求, 请求超时时间为10s, 请求完成后执行相应的回调。
  7890. * UE.ajax.requeset( 'sayhello.php', {
  7891. *
  7892. * //请求方法。可选值: 'GET', 'POST',默认值是'POST'
  7893. * method: 'GET',
  7894. *
  7895. * //超时时间。 默认为5000, 单位是ms
  7896. * timeout: 10000,
  7897. *
  7898. * //是否是异步请求。 true为异步请求, false为同步请求
  7899. * async: true,
  7900. *
  7901. * //请求携带的数据。如果请求为GET请求, data会经过stringify后附加到请求url之后。
  7902. * data: {
  7903. * name: 'ueditor'
  7904. * },
  7905. *
  7906. * //请求成功后的回调, 该回调接受当前的XMLHttpRequest对象作为参数。
  7907. * onsuccess: function ( xhr ) {
  7908. * console.log( xhr.responseText );
  7909. * },
  7910. *
  7911. * //请求失败或者超时后的回调。
  7912. * onerror: function ( xhr ) {
  7913. * alert( 'Ajax请求失败' );
  7914. * }
  7915. *
  7916. * } );
  7917. * ```
  7918. */
  7919. /**
  7920. * 根据给定的参数项发起一个ajax请求, 参数项里必须包含一个url地址。 ajax请求完成后,会根据请求结果调用相应回调: 如果请求
  7921. * 成功, 则调用onsuccess回调, 失败则调用 onerror 回调。
  7922. * @method request
  7923. * @warning 如果在参数项里未提供一个key为“url”的地址值,则该请求将直接退出。
  7924. * @param { Object } ajaxOptions ajax请求选项的键值对,支持的选项如下:
  7925. * @example
  7926. * ```javascript
  7927. *
  7928. * //向sayhello.php发起一个异步的Ajax POST请求, 请求超时时间为5s, 请求完成后不执行任何回调。
  7929. * UE.ajax.requeset( 'sayhello.php', {
  7930. *
  7931. * //请求的地址, 该项是必须的。
  7932. * url: 'sayhello.php'
  7933. *
  7934. * } );
  7935. * ```
  7936. */
  7937. request:function(url, opts) {
  7938. if (opts && opts.dataType == 'jsonp') {
  7939. doJsonp(url, opts);
  7940. } else {
  7941. doAjax(url, opts);
  7942. }
  7943. },
  7944. getJSONP:function(url, data, fn) {
  7945. var opts = {
  7946. 'data': data,
  7947. 'oncomplete': fn
  7948. };
  7949. doJsonp(url, opts);
  7950. }
  7951. };
  7952. }();
  7953. // js/editor/_src/core/filterword.js
  7954. /**
  7955. * UE过滤word的静态方法
  7956. * @file
  7957. */
  7958. /**
  7959. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  7960. * @module UE
  7961. */
  7962. /**
  7963. * 根据传入html字符串过滤word
  7964. * @module UE
  7965. * @since 1.2.6.1
  7966. * @method filterWord
  7967. * @param { String } html html字符串
  7968. * @return { String } 已过滤后的结果字符串
  7969. * @example
  7970. * ```javascript
  7971. * UE.filterWord(html);
  7972. * ```
  7973. */
  7974. var filterWord = UE.filterWord = function () {
  7975. //是否是word过来的内容
  7976. function isWordDocument( str ) {
  7977. return /(class="?Mso|style="[^"]*\bmso\-|w:WordDocument|<(v|o):|lang=)/ig.test( str );
  7978. }
  7979. //去掉小数
  7980. function transUnit( v ) {
  7981. v = v.replace( /[\d.]+\w+/g, function ( m ) {
  7982. return utils.transUnitToPx(m);
  7983. } );
  7984. return v;
  7985. }
  7986. function filterPasteWord( str ) {
  7987. return str.replace(/[\t\r\n]+/g,' ')
  7988. .replace( /<!--[\s\S]*?-->/ig, "" )
  7989. //转换图片
  7990. .replace(/<v:shape [^>]*>[\s\S]*?.<\/v:shape>/gi,function(str){
  7991. //opera能自己解析出image所这里直接返回空
  7992. if(browser.opera){
  7993. return '';
  7994. }
  7995. try{
  7996. //有可能是bitmap占为图,无用,直接过滤掉,主要体现在粘贴excel表格中
  7997. if(/Bitmap/i.test(str)){
  7998. return '';
  7999. }
  8000. var width = str.match(/width:([ \d.]*p[tx])/i)[1],
  8001. height = str.match(/height:([ \d.]*p[tx])/i)[1],
  8002. src = str.match(/src=\s*"([^"]*)"/i)[1];
  8003. return '<img width="'+ transUnit(width) +'" height="'+transUnit(height) +'" src="' + src + '" />';
  8004. } catch(e){
  8005. return '';
  8006. }
  8007. })
  8008. //针对wps添加的多余标签处理
  8009. .replace(/<\/?div[^>]*>/g,'')
  8010. //去掉多余的属性
  8011. .replace( /v:\w+=(["']?)[^'"]+\1/g, '' )
  8012. .replace( /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|xml|meta|link|style|\w+:\w+)(?=[\s\/>]))[^>]*>/gi, "" )
  8013. .replace( /<p [^>]*class="?MsoHeading"?[^>]*>(.*?)<\/p>/gi, "<p><strong>$1</strong></p>" )
  8014. //去掉多余的属性
  8015. .replace( /\s+(class|lang|align)\s*=\s*(['"]?)([\w-]+)\2/ig, function(str,name,marks,val){
  8016. //保留list的标示
  8017. return name == 'class' && val == 'MsoListParagraph' ? str : ''
  8018. })
  8019. //清除多余的font/span不能匹配&nbsp;有可能是空格
  8020. .replace( /<(font|span)[^>]*>(\s*)<\/\1>/gi, function(a,b,c){
  8021. return c.replace(/[\t\r\n ]+/g,' ')
  8022. })
  8023. //处理style的问题
  8024. .replace( /(<[a-z][^>]*)\sstyle=(["'])([^\2]*?)\2/gi, function( str, tag, tmp, style ) {
  8025. var n = [],
  8026. s = style.replace( /^\s+|\s+$/, '' )
  8027. .replace(/&#39;/g,'\'')
  8028. .replace( /&quot;/gi, "'" )
  8029. .replace(/[\d.]+(cm|pt)/g,function(str){
  8030. return utils.transUnitToPx(str)
  8031. })
  8032. .split( /;\s*/g );
  8033. for ( var i = 0,v; v = s[i];i++ ) {
  8034. var name, value,
  8035. parts = v.split( ":" );
  8036. if ( parts.length == 2 ) {
  8037. name = parts[0].toLowerCase();
  8038. value = parts[1].toLowerCase();
  8039. if(/^(background)\w*/.test(name) && value.replace(/(initial|\s)/g,'').length == 0
  8040. ||
  8041. /^(margin)\w*/.test(name) && /^0\w+$/.test(value)
  8042. ){
  8043. continue;
  8044. }
  8045. switch ( name ) {
  8046. case "mso-padding-alt":
  8047. case "mso-padding-top-alt":
  8048. case "mso-padding-right-alt":
  8049. case "mso-padding-bottom-alt":
  8050. case "mso-padding-left-alt":
  8051. case "mso-margin-alt":
  8052. case "mso-margin-top-alt":
  8053. case "mso-margin-right-alt":
  8054. case "mso-margin-bottom-alt":
  8055. case "mso-margin-left-alt":
  8056. //ie下会出现挤到一起的情况
  8057. //case "mso-table-layout-alt":
  8058. case "mso-height":
  8059. case "mso-width":
  8060. case "mso-vertical-align-alt":
  8061. //trace:1819 ff下会解析出padding在table上
  8062. if(!/<table/.test(tag))
  8063. n[i] = name.replace( /^mso-|-alt$/g, "" ) + ":" + transUnit( value );
  8064. continue;
  8065. case "horiz-align":
  8066. n[i] = "text-align:" + value;
  8067. continue;
  8068. case "vert-align":
  8069. n[i] = "vertical-align:" + value;
  8070. continue;
  8071. case "font-color":
  8072. case "mso-foreground":
  8073. n[i] = "color:" + value;
  8074. continue;
  8075. case "mso-background":
  8076. case "mso-highlight":
  8077. n[i] = "background:" + value;
  8078. continue;
  8079. case "mso-default-height":
  8080. n[i] = "min-height:" + transUnit( value );
  8081. continue;
  8082. case "mso-default-width":
  8083. n[i] = "min-width:" + transUnit( value );
  8084. continue;
  8085. case "mso-padding-between-alt":
  8086. n[i] = "border-collapse:separate;border-spacing:" + transUnit( value );
  8087. continue;
  8088. case "text-line-through":
  8089. if ( (value == "single") || (value == "double") ) {
  8090. n[i] = "text-decoration:line-through";
  8091. }
  8092. continue;
  8093. case "mso-zero-height":
  8094. if ( value == "yes" ) {
  8095. n[i] = "display:none";
  8096. }
  8097. continue;
  8098. // case 'background':
  8099. // break;
  8100. case 'margin':
  8101. if ( !/[1-9]/.test( value ) ) {
  8102. continue;
  8103. }
  8104. }
  8105. if ( /^(mso|column|font-emph|lang|layout|line-break|list-image|nav|panose|punct|row|ruby|sep|size|src|tab-|table-border|text-(?:decor|trans)|top-bar|version|vnd|word-break)/.test( name )
  8106. ||
  8107. /text\-indent|padding|margin/.test(name) && /\-[\d.]+/.test(value)
  8108. ) {
  8109. continue;
  8110. }
  8111. n[i] = name + ":" + parts[1];
  8112. }
  8113. }
  8114. return tag + (n.length ? ' style="' + n.join( ';').replace(/;{2,}/g,';') + '"' : '');
  8115. })
  8116. }
  8117. return function ( html ) {
  8118. return (isWordDocument( html ) ? filterPasteWord( html ) : html);
  8119. };
  8120. }();
  8121. // js/editor/_src/core/node.js
  8122. /**
  8123. * 编辑器模拟的节点类
  8124. * @file
  8125. * @module UE
  8126. * @class uNode
  8127. * @since 1.2.6.1
  8128. */
  8129. /**
  8130. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  8131. * @unfile
  8132. * @module UE
  8133. */
  8134. (function () {
  8135. /**
  8136. * 编辑器模拟的节点类
  8137. * @unfile
  8138. * @module UE
  8139. * @class uNode
  8140. */
  8141. /**
  8142. * 通过一个键值对,创建一个uNode对象
  8143. * @constructor
  8144. * @param { Object } attr 传入要创建的uNode的初始属性
  8145. * @example
  8146. * ```javascript
  8147. * var node = new uNode({
  8148. * type:'element',
  8149. * tagName:'span',
  8150. * attrs:{style:'font-size:14px;'}
  8151. * }
  8152. * ```
  8153. */
  8154. var uNode = UE.uNode = function (obj) {
  8155. this.type = obj.type;
  8156. this.data = obj.data;
  8157. this.tagName = obj.tagName;
  8158. this.parentNode = obj.parentNode;
  8159. this.attrs = obj.attrs || {};
  8160. this.children = obj.children;
  8161. };
  8162. var notTransAttrs = {
  8163. 'href':1,
  8164. 'src':1,
  8165. '_src':1,
  8166. '_href':1,
  8167. 'cdata_data':1
  8168. };
  8169. var notTransTagName = {
  8170. style:1,
  8171. script:1
  8172. };
  8173. var indentChar = ' ',
  8174. breakChar = '\n';
  8175. function insertLine(arr, current, begin) {
  8176. arr.push(breakChar);
  8177. return current + (begin ? 1 : -1);
  8178. }
  8179. function insertIndent(arr, current) {
  8180. //插入缩进
  8181. for (var i = 0; i < current; i++) {
  8182. arr.push(indentChar);
  8183. }
  8184. }
  8185. //创建uNode的静态方法
  8186. //支持标签和html
  8187. uNode.createElement = function (html) {
  8188. if (/[<>]/.test(html)) {
  8189. return UE.htmlparser(html).children[0]
  8190. } else {
  8191. return new uNode({
  8192. type:'element',
  8193. children:[],
  8194. tagName:html
  8195. })
  8196. }
  8197. };
  8198. uNode.createText = function (data,noTrans) {
  8199. return new UE.uNode({
  8200. type:'text',
  8201. 'data':noTrans ? data : utils.unhtml(data || '')
  8202. })
  8203. };
  8204. function nodeToHtml(node, arr, formatter, current) {
  8205. switch (node.type) {
  8206. case 'root':
  8207. for (var i = 0, ci; ci = node.children[i++];) {
  8208. //插入新行
  8209. if (formatter && ci.type == 'element' && !dtd.$inlineWithA[ci.tagName] && i > 1) {
  8210. insertLine(arr, current, true);
  8211. insertIndent(arr, current)
  8212. }
  8213. nodeToHtml(ci, arr, formatter, current)
  8214. }
  8215. break;
  8216. case 'text':
  8217. isText(node, arr);
  8218. break;
  8219. case 'element':
  8220. isElement(node, arr, formatter, current);
  8221. break;
  8222. case 'comment':
  8223. isComment(node, arr, formatter);
  8224. }
  8225. return arr;
  8226. }
  8227. function isText(node, arr) {
  8228. if(node.parentNode.tagName == 'pre'){
  8229. //源码模式下输入html标签,不能做转换处理,直接输出
  8230. arr.push(node.data)
  8231. }else{
  8232. arr.push(notTransTagName[node.parentNode.tagName] ? utils.html(node.data) : node.data.replace(/[ ]{2}/g,' &nbsp;'))
  8233. }
  8234. }
  8235. function isElement(node, arr, formatter, current) {
  8236. var attrhtml = '';
  8237. if (node.attrs) {
  8238. attrhtml = [];
  8239. var attrs = node.attrs;
  8240. for (var a in attrs) {
  8241. //这里就针对
  8242. //<p>'<img src='http://nsclick.baidu.com/u.gif?&asdf=\"sdf&asdfasdfs;asdf'></p>
  8243. //这里边的\"做转换,要不用innerHTML直接被截断了,属性src
  8244. //有可能做的不够
  8245. attrhtml.push(a + (attrs[a] !== undefined ? '="' + (notTransAttrs[a] ? utils.html(attrs[a]).replace(/["]/g, function (a) {
  8246. return '&quot;'
  8247. }) : utils.unhtml(attrs[a])) + '"' : ''))
  8248. }
  8249. attrhtml = attrhtml.join(' ');
  8250. }
  8251. arr.push('<' + node.tagName +
  8252. (attrhtml ? ' ' + attrhtml : '') +
  8253. (dtd.$empty[node.tagName] ? '\/' : '' ) + '>'
  8254. );
  8255. //插入新行
  8256. if (formatter && !dtd.$inlineWithA[node.tagName] && node.tagName != 'pre') {
  8257. if(node.children && node.children.length){
  8258. current = insertLine(arr, current, true);
  8259. insertIndent(arr, current)
  8260. }
  8261. }
  8262. if (node.children && node.children.length) {
  8263. for (var i = 0, ci; ci = node.children[i++];) {
  8264. if (formatter && ci.type == 'element' && !dtd.$inlineWithA[ci.tagName] && i > 1) {
  8265. insertLine(arr, current);
  8266. insertIndent(arr, current)
  8267. }
  8268. nodeToHtml(ci, arr, formatter, current)
  8269. }
  8270. }
  8271. if (!dtd.$empty[node.tagName]) {
  8272. if (formatter && !dtd.$inlineWithA[node.tagName] && node.tagName != 'pre') {
  8273. if(node.children && node.children.length){
  8274. current = insertLine(arr, current);
  8275. insertIndent(arr, current)
  8276. }
  8277. }
  8278. arr.push('<\/' + node.tagName + '>');
  8279. }
  8280. }
  8281. function isComment(node, arr) {
  8282. arr.push('<!--' + node.data + '-->');
  8283. }
  8284. function getNodeById(root, id) {
  8285. var node;
  8286. if (root.type == 'element' && root.getAttr('id') == id) {
  8287. return root;
  8288. }
  8289. if (root.children && root.children.length) {
  8290. for (var i = 0, ci; ci = root.children[i++];) {
  8291. if (node = getNodeById(ci, id)) {
  8292. return node;
  8293. }
  8294. }
  8295. }
  8296. }
  8297. function getNodesByTagName(node, tagName, arr) {
  8298. if (node.type == 'element' && node.tagName == tagName) {
  8299. arr.push(node);
  8300. }
  8301. if (node.children && node.children.length) {
  8302. for (var i = 0, ci; ci = node.children[i++];) {
  8303. getNodesByTagName(ci, tagName, arr)
  8304. }
  8305. }
  8306. }
  8307. function nodeTraversal(root,fn){
  8308. if(root.children && root.children.length){
  8309. for(var i= 0,ci;ci=root.children[i];){
  8310. nodeTraversal(ci,fn);
  8311. //ci被替换的情况,这里就不再走 fn了
  8312. if(ci.parentNode ){
  8313. if(ci.children && ci.children.length){
  8314. fn(ci)
  8315. }
  8316. if(ci.parentNode) i++
  8317. }
  8318. }
  8319. }else{
  8320. fn(root)
  8321. }
  8322. }
  8323. uNode.prototype = {
  8324. /**
  8325. * 当前节点对象,转换成html文本
  8326. * @method toHtml
  8327. * @return { String } 返回转换后的html字符串
  8328. * @example
  8329. * ```javascript
  8330. * node.toHtml();
  8331. * ```
  8332. */
  8333. /**
  8334. * 当前节点对象,转换成html文本
  8335. * @method toHtml
  8336. * @param { Boolean } formatter 是否格式化返回值
  8337. * @return { String } 返回转换后的html字符串
  8338. * @example
  8339. * ```javascript
  8340. * node.toHtml( true );
  8341. * ```
  8342. */
  8343. toHtml:function (formatter) {
  8344. var arr = [];
  8345. nodeToHtml(this, arr, formatter, 0);
  8346. return arr.join('')
  8347. },
  8348. /**
  8349. * 获取节点的html内容
  8350. * @method innerHTML
  8351. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  8352. * @return { String } 返回节点的html内容
  8353. * @example
  8354. * ```javascript
  8355. * var htmlstr = node.innerHTML();
  8356. * ```
  8357. */
  8358. /**
  8359. * 设置节点的html内容
  8360. * @method innerHTML
  8361. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  8362. * @param { String } htmlstr 传入要设置的html内容
  8363. * @return { UE.uNode } 返回节点本身
  8364. * @example
  8365. * ```javascript
  8366. * node.innerHTML('<span>text</span>');
  8367. * ```
  8368. */
  8369. innerHTML:function (htmlstr) {
  8370. if (this.type != 'element' || dtd.$empty[this.tagName]) {
  8371. return this;
  8372. }
  8373. if (utils.isString(htmlstr)) {
  8374. if(this.children){
  8375. for (var i = 0, ci; ci = this.children[i++];) {
  8376. ci.parentNode = null;
  8377. }
  8378. }
  8379. this.children = [];
  8380. var tmpRoot = UE.htmlparser(htmlstr);
  8381. for (var i = 0, ci; ci = tmpRoot.children[i++];) {
  8382. this.children.push(ci);
  8383. ci.parentNode = this;
  8384. }
  8385. return this;
  8386. } else {
  8387. var tmpRoot = new UE.uNode({
  8388. type:'root',
  8389. children:this.children
  8390. });
  8391. return tmpRoot.toHtml();
  8392. }
  8393. },
  8394. /**
  8395. * 获取节点的纯文本内容
  8396. * @method innerText
  8397. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  8398. * @return { String } 返回节点的存文本内容
  8399. * @example
  8400. * ```javascript
  8401. * var textStr = node.innerText();
  8402. * ```
  8403. */
  8404. /**
  8405. * 设置节点的纯文本内容
  8406. * @method innerText
  8407. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  8408. * @param { String } textStr 传入要设置的文本内容
  8409. * @return { UE.uNode } 返回节点本身
  8410. * @example
  8411. * ```javascript
  8412. * node.innerText('<span>text</span>');
  8413. * ```
  8414. */
  8415. innerText:function (textStr,noTrans) {
  8416. if (this.type != 'element' || dtd.$empty[this.tagName]) {
  8417. return this;
  8418. }
  8419. if (textStr) {
  8420. if(this.children){
  8421. for (var i = 0, ci; ci = this.children[i++];) {
  8422. ci.parentNode = null;
  8423. }
  8424. }
  8425. this.children = [];
  8426. this.appendChild(uNode.createText(textStr,noTrans));
  8427. return this;
  8428. } else {
  8429. return this.toHtml().replace(/<[^>]+>/g, '');
  8430. }
  8431. },
  8432. /**
  8433. * 获取当前对象的data属性
  8434. * @method getData
  8435. * @return { Object } 若节点的type值是elemenet,返回空字符串,否则返回节点的data属性
  8436. * @example
  8437. * ```javascript
  8438. * node.getData();
  8439. * ```
  8440. */
  8441. getData:function () {
  8442. if (this.type == 'element')
  8443. return '';
  8444. return this.data
  8445. },
  8446. /**
  8447. * 获取当前节点下的第一个子节点
  8448. * @method firstChild
  8449. * @return { UE.uNode } 返回第一个子节点
  8450. * @example
  8451. * ```javascript
  8452. * node.firstChild(); //返回第一个子节点
  8453. * ```
  8454. */
  8455. firstChild:function () {
  8456. // if (this.type != 'element' || dtd.$empty[this.tagName]) {
  8457. // return this;
  8458. // }
  8459. return this.children ? this.children[0] : null;
  8460. },
  8461. /**
  8462. * 获取当前节点下的最后一个子节点
  8463. * @method lastChild
  8464. * @return { UE.uNode } 返回最后一个子节点
  8465. * @example
  8466. * ```javascript
  8467. * node.lastChild(); //返回最后一个子节点
  8468. * ```
  8469. */
  8470. lastChild:function () {
  8471. // if (this.type != 'element' || dtd.$empty[this.tagName] ) {
  8472. // return this;
  8473. // }
  8474. return this.children ? this.children[this.children.length - 1] : null;
  8475. },
  8476. /**
  8477. * 获取和当前节点有相同父亲节点的前一个节点
  8478. * @method previousSibling
  8479. * @return { UE.uNode } 返回前一个节点
  8480. * @example
  8481. * ```javascript
  8482. * node.children[2].previousSibling(); //返回子节点node.children[1]
  8483. * ```
  8484. */
  8485. previousSibling : function(){
  8486. var parent = this.parentNode;
  8487. for (var i = 0, ci; ci = parent.children[i]; i++) {
  8488. if (ci === this) {
  8489. return i == 0 ? null : parent.children[i-1];
  8490. }
  8491. }
  8492. },
  8493. /**
  8494. * 获取和当前节点有相同父亲节点的后一个节点
  8495. * @method nextSibling
  8496. * @return { UE.uNode } 返回后一个节点,找不到返回null
  8497. * @example
  8498. * ```javascript
  8499. * node.children[2].nextSibling(); //如果有,返回子节点node.children[3]
  8500. * ```
  8501. */
  8502. nextSibling : function(){
  8503. var parent = this.parentNode;
  8504. for (var i = 0, ci; ci = parent.children[i++];) {
  8505. if (ci === this) {
  8506. return parent.children[i];
  8507. }
  8508. }
  8509. },
  8510. /**
  8511. * 用新的节点替换当前节点
  8512. * @method replaceChild
  8513. * @param { UE.uNode } target 要替换成该节点参数
  8514. * @param { UE.uNode } source 要被替换掉的节点
  8515. * @return { UE.uNode } 返回替换之后的节点对象
  8516. * @example
  8517. * ```javascript
  8518. * node.replaceChild(newNode, childNode); //用newNode替换childNode,childNode是node的子节点
  8519. * ```
  8520. */
  8521. replaceChild:function (target, source) {
  8522. if (this.children) {
  8523. if(target.parentNode){
  8524. target.parentNode.removeChild(target);
  8525. }
  8526. for (var i = 0, ci; ci = this.children[i]; i++) {
  8527. if (ci === source) {
  8528. this.children.splice(i, 1, target);
  8529. source.parentNode = null;
  8530. target.parentNode = this;
  8531. return target;
  8532. }
  8533. }
  8534. }
  8535. },
  8536. /**
  8537. * 在节点的子节点列表最后位置插入一个节点
  8538. * @method appendChild
  8539. * @param { UE.uNode } node 要插入的节点
  8540. * @return { UE.uNode } 返回刚插入的子节点
  8541. * @example
  8542. * ```javascript
  8543. * node.appendChild( newNode ); //在node内插入子节点newNode
  8544. * ```
  8545. */
  8546. appendChild:function (node) {
  8547. if (this.type == 'root' || (this.type == 'element' && !dtd.$empty[this.tagName])) {
  8548. if (!this.children) {
  8549. this.children = []
  8550. }
  8551. if(node.parentNode){
  8552. node.parentNode.removeChild(node);
  8553. }
  8554. for (var i = 0, ci; ci = this.children[i]; i++) {
  8555. if (ci === node) {
  8556. this.children.splice(i, 1);
  8557. break;
  8558. }
  8559. }
  8560. this.children.push(node);
  8561. node.parentNode = this;
  8562. return node;
  8563. }
  8564. },
  8565. /**
  8566. * 在传入节点的前面插入一个节点
  8567. * @method insertBefore
  8568. * @param { UE.uNode } target 要插入的节点
  8569. * @param { UE.uNode } source 在该参数节点前面插入
  8570. * @return { UE.uNode } 返回刚插入的子节点
  8571. * @example
  8572. * ```javascript
  8573. * node.parentNode.insertBefore(newNode, node); //在node节点后面插入newNode
  8574. * ```
  8575. */
  8576. insertBefore:function (target, source) {
  8577. if (this.children) {
  8578. if(target.parentNode){
  8579. target.parentNode.removeChild(target);
  8580. }
  8581. for (var i = 0, ci; ci = this.children[i]; i++) {
  8582. if (ci === source) {
  8583. this.children.splice(i, 0, target);
  8584. target.parentNode = this;
  8585. return target;
  8586. }
  8587. }
  8588. }
  8589. },
  8590. /**
  8591. * 在传入节点的后面插入一个节点
  8592. * @method insertAfter
  8593. * @param { UE.uNode } target 要插入的节点
  8594. * @param { UE.uNode } source 在该参数节点后面插入
  8595. * @return { UE.uNode } 返回刚插入的子节点
  8596. * @example
  8597. * ```javascript
  8598. * node.parentNode.insertAfter(newNode, node); //在node节点后面插入newNode
  8599. * ```
  8600. */
  8601. insertAfter:function (target, source) {
  8602. if (this.children) {
  8603. if(target.parentNode){
  8604. target.parentNode.removeChild(target);
  8605. }
  8606. for (var i = 0, ci; ci = this.children[i]; i++) {
  8607. if (ci === source) {
  8608. this.children.splice(i + 1, 0, target);
  8609. target.parentNode = this;
  8610. return target;
  8611. }
  8612. }
  8613. }
  8614. },
  8615. /**
  8616. * 从当前节点的子节点列表中,移除节点
  8617. * @method removeChild
  8618. * @param { UE.uNode } node 要移除的节点引用
  8619. * @param { Boolean } keepChildren 是否保留移除节点的子节点,若传入true,自动把移除节点的子节点插入到移除的位置
  8620. * @return { * } 返回刚移除的子节点
  8621. * @example
  8622. * ```javascript
  8623. * node.removeChild(childNode,true); //在node的子节点列表中移除child节点,并且吧child的子节点插入到移除的位置
  8624. * ```
  8625. */
  8626. removeChild:function (node,keepChildren) {
  8627. if (this.children) {
  8628. for (var i = 0, ci; ci = this.children[i]; i++) {
  8629. if (ci === node) {
  8630. this.children.splice(i, 1);
  8631. ci.parentNode = null;
  8632. if(keepChildren && ci.children && ci.children.length){
  8633. for(var j= 0,cj;cj=ci.children[j];j++){
  8634. this.children.splice(i+j,0,cj);
  8635. cj.parentNode = this;
  8636. }
  8637. }
  8638. return ci;
  8639. }
  8640. }
  8641. }
  8642. },
  8643. /**
  8644. * 获取当前节点所代表的元素属性,即获取attrs对象下的属性值
  8645. * @method getAttr
  8646. * @param { String } attrName 要获取的属性名称
  8647. * @return { * } 返回attrs对象下的属性值
  8648. * @example
  8649. * ```javascript
  8650. * node.getAttr('title');
  8651. * ```
  8652. */
  8653. getAttr:function (attrName) {
  8654. return this.attrs && this.attrs[attrName.toLowerCase()]
  8655. },
  8656. /**
  8657. * 设置当前节点所代表的元素属性,即设置attrs对象下的属性值
  8658. * @method setAttr
  8659. * @param { String } attrName 要设置的属性名称
  8660. * @param { * } attrVal 要设置的属性值,类型视设置的属性而定
  8661. * @return { * } 返回attrs对象下的属性值
  8662. * @example
  8663. * ```javascript
  8664. * node.setAttr('title','标题');
  8665. * ```
  8666. */
  8667. setAttr:function (attrName, attrVal) {
  8668. if (!attrName) {
  8669. delete this.attrs;
  8670. return;
  8671. }
  8672. if(!this.attrs){
  8673. this.attrs = {};
  8674. }
  8675. if (utils.isObject(attrName)) {
  8676. for (var a in attrName) {
  8677. if (!attrName[a]) {
  8678. delete this.attrs[a]
  8679. } else {
  8680. this.attrs[a.toLowerCase()] = attrName[a];
  8681. }
  8682. }
  8683. } else {
  8684. if (!attrVal) {
  8685. delete this.attrs[attrName]
  8686. } else {
  8687. this.attrs[attrName.toLowerCase()] = attrVal;
  8688. }
  8689. }
  8690. },
  8691. /**
  8692. * 获取当前节点在父节点下的位置索引
  8693. * @method getIndex
  8694. * @return { Number } 返回索引数值,如果没有父节点,返回-1
  8695. * @example
  8696. * ```javascript
  8697. * node.getIndex();
  8698. * ```
  8699. */
  8700. getIndex:function(){
  8701. var parent = this.parentNode;
  8702. for(var i= 0,ci;ci=parent.children[i];i++){
  8703. if(ci === this){
  8704. return i;
  8705. }
  8706. }
  8707. return -1;
  8708. },
  8709. /**
  8710. * 在当前节点下,根据id查找节点
  8711. * @method getNodeById
  8712. * @param { String } id 要查找的id
  8713. * @return { UE.uNode } 返回找到的节点
  8714. * @example
  8715. * ```javascript
  8716. * node.getNodeById('textId');
  8717. * ```
  8718. */
  8719. getNodeById:function (id) {
  8720. var node;
  8721. if (this.children && this.children.length) {
  8722. for (var i = 0, ci; ci = this.children[i++];) {
  8723. if (node = getNodeById(ci, id)) {
  8724. return node;
  8725. }
  8726. }
  8727. }
  8728. },
  8729. /**
  8730. * 在当前节点下,根据元素名称查找节点列表
  8731. * @method getNodesByTagName
  8732. * @param { String } tagNames 要查找的元素名称
  8733. * @return { Array } 返回找到的节点列表
  8734. * @example
  8735. * ```javascript
  8736. * node.getNodesByTagName('span');
  8737. * ```
  8738. */
  8739. getNodesByTagName:function (tagNames) {
  8740. tagNames = utils.trim(tagNames).replace(/[ ]{2,}/g, ' ').split(' ');
  8741. var arr = [], me = this;
  8742. utils.each(tagNames, function (tagName) {
  8743. if (me.children && me.children.length) {
  8744. for (var i = 0, ci; ci = me.children[i++];) {
  8745. getNodesByTagName(ci, tagName, arr)
  8746. }
  8747. }
  8748. });
  8749. return arr;
  8750. },
  8751. /**
  8752. * 根据样式名称,获取节点的样式值
  8753. * @method getStyle
  8754. * @param { String } name 要获取的样式名称
  8755. * @return { String } 返回样式值
  8756. * @example
  8757. * ```javascript
  8758. * node.getStyle('font-size');
  8759. * ```
  8760. */
  8761. getStyle:function (name) {
  8762. var cssStyle = this.getAttr('style');
  8763. if (!cssStyle) {
  8764. return ''
  8765. }
  8766. var reg = new RegExp('(^|;)\\s*' + name + ':([^;]+)','i');
  8767. var match = cssStyle.match(reg);
  8768. if (match && match[0]) {
  8769. return match[2]
  8770. }
  8771. return '';
  8772. },
  8773. /**
  8774. * 给节点设置样式
  8775. * @method setStyle
  8776. * @param { String } name 要设置的的样式名称
  8777. * @param { String } val 要设置的的样值
  8778. * @example
  8779. * ```javascript
  8780. * node.setStyle('font-size', '12px');
  8781. * ```
  8782. */
  8783. setStyle:function (name, val) {
  8784. function exec(name, val) {
  8785. var reg = new RegExp('(^|;)\\s*' + name + ':([^;]+;?)', 'gi');
  8786. cssStyle = cssStyle.replace(reg, '$1');
  8787. if (val) {
  8788. cssStyle = name + ':' + utils.unhtml(val) + ';' + cssStyle
  8789. }
  8790. }
  8791. var cssStyle = this.getAttr('style');
  8792. if (!cssStyle) {
  8793. cssStyle = '';
  8794. }
  8795. if (utils.isObject(name)) {
  8796. for (var a in name) {
  8797. exec(a, name[a])
  8798. }
  8799. } else {
  8800. exec(name, val)
  8801. }
  8802. this.setAttr('style', utils.trim(cssStyle))
  8803. },
  8804. /**
  8805. * 传入一个函数,递归遍历当前节点下的所有节点
  8806. * @method traversal
  8807. * @param { Function } fn 遍历到节点的时,传入节点作为参数,运行此函数
  8808. * @example
  8809. * ```javascript
  8810. * traversal(node, function(){
  8811. * console.log(node.type);
  8812. * });
  8813. * ```
  8814. */
  8815. traversal:function(fn){
  8816. if(this.children && this.children.length){
  8817. nodeTraversal(this,fn);
  8818. }
  8819. return this;
  8820. }
  8821. }
  8822. })();
  8823. // js/editor/_src/core/htmlparser.js
  8824. /**
  8825. * html字符串转换成uNode节点
  8826. * @file
  8827. * @module UE
  8828. * @since 1.2.6.1
  8829. */
  8830. /**
  8831. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  8832. * @unfile
  8833. * @module UE
  8834. */
  8835. /**
  8836. * html字符串转换成uNode节点的静态方法
  8837. * @method htmlparser
  8838. * @param { String } htmlstr 要转换的html代码
  8839. * @param { Boolean } ignoreBlank 若设置为true,转换的时候忽略\n\r\t等空白字符
  8840. * @return { uNode } 给定的html片段转换形成的uNode对象
  8841. * @example
  8842. * ```javascript
  8843. * var root = UE.htmlparser('<p><b>htmlparser</b></p>', true);
  8844. * ```
  8845. */
  8846. var htmlparser = UE.htmlparser = function (htmlstr,ignoreBlank) {
  8847. //todo 原来的方式 [^"'<>\/] 有\/就不能配对上 <TD vAlign=top background=../AAA.JPG> 这样的标签了
  8848. //先去掉了,加上的原因忘了,这里先记录
  8849. var re_tag = /<(?:(?:\/([^>]+)>)|(?:!--([\S|\s]*?)-->)|(?:([^\s\/<>]+)\s*((?:(?:"[^"]*")|(?:'[^']*')|[^"'<>])*)\/?>))/g,
  8850. re_attr = /([\w\-:.]+)(?:(?:\s*=\s*(?:(?:"([^"]*)")|(?:'([^']*)')|([^\s>]+)))|(?=\s|$))/g;
  8851. //ie下取得的html可能会有\n存在,要去掉,在处理replace(/[\t\r\n]*/g,'');代码高量的\n不能去除
  8852. var allowEmptyTags = {
  8853. b:1,code:1,i:1,u:1,strike:1,s:1,tt:1,strong:1,q:1,samp:1,em:1,span:1,
  8854. sub:1,img:1,sup:1,font:1,big:1,small:1,iframe:1,a:1,br:1,pre:1
  8855. };
  8856. htmlstr = htmlstr.replace(new RegExp(domUtils.fillChar, 'g'), '');
  8857. if(!ignoreBlank){
  8858. htmlstr = htmlstr.replace(new RegExp('[\\r\\t\\n'+(ignoreBlank?'':' ')+']*<\/?(\\w+)\\s*(?:[^>]*)>[\\r\\t\\n'+(ignoreBlank?'':' ')+']*','g'), function(a,b){
  8859. //br暂时单独处理
  8860. if(b && allowEmptyTags[b.toLowerCase()]){
  8861. return a.replace(/(^[\n\r]+)|([\n\r]+$)/g,'');
  8862. }
  8863. return a.replace(new RegExp('^[\\r\\n'+(ignoreBlank?'':' ')+']+'),'').replace(new RegExp('[\\r\\n'+(ignoreBlank?'':' ')+']+$'),'');
  8864. });
  8865. }
  8866. var notTransAttrs = {
  8867. 'href':1,
  8868. 'src':1
  8869. };
  8870. var uNode = UE.uNode,
  8871. needParentNode = {
  8872. 'td':'tr',
  8873. 'tr':['tbody','thead','tfoot'],
  8874. 'tbody':'table',
  8875. 'th':'tr',
  8876. 'thead':'table',
  8877. 'tfoot':'table',
  8878. 'caption':'table',
  8879. 'li':['ul', 'ol'],
  8880. 'dt':'dl',
  8881. 'dd':'dl',
  8882. 'option':'select'
  8883. },
  8884. needChild = {
  8885. 'ol':'li',
  8886. 'ul':'li'
  8887. };
  8888. function text(parent, data) {
  8889. if(needChild[parent.tagName]){
  8890. var tmpNode = uNode.createElement(needChild[parent.tagName]);
  8891. parent.appendChild(tmpNode);
  8892. tmpNode.appendChild(uNode.createText(data));
  8893. parent = tmpNode;
  8894. }else{
  8895. parent.appendChild(uNode.createText(data));
  8896. }
  8897. }
  8898. function element(parent, tagName, htmlattr) {
  8899. var needParentTag;
  8900. if (needParentTag = needParentNode[tagName]) {
  8901. var tmpParent = parent,hasParent;
  8902. while(tmpParent.type != 'root'){
  8903. if(utils.isArray(needParentTag) ? utils.indexOf(needParentTag, tmpParent.tagName) != -1 : needParentTag == tmpParent.tagName){
  8904. parent = tmpParent;
  8905. hasParent = true;
  8906. break;
  8907. }
  8908. tmpParent = tmpParent.parentNode;
  8909. }
  8910. if(!hasParent){
  8911. parent = element(parent, utils.isArray(needParentTag) ? needParentTag[0] : needParentTag)
  8912. }
  8913. }
  8914. //按dtd处理嵌套
  8915. // if(parent.type != 'root' && !dtd[parent.tagName][tagName])
  8916. // parent = parent.parentNode;
  8917. var elm = new uNode({
  8918. parentNode:parent,
  8919. type:'element',
  8920. tagName:tagName.toLowerCase(),
  8921. //是自闭合的处理一下
  8922. children:dtd.$empty[tagName] ? null : []
  8923. });
  8924. //如果属性存在,处理属性
  8925. if (htmlattr) {
  8926. var attrs = {}, match;
  8927. while (match = re_attr.exec(htmlattr)) {
  8928. attrs[match[1].toLowerCase()] = notTransAttrs[match[1].toLowerCase()] ? (match[2] || match[3] || match[4]) : utils.unhtml(match[2] || match[3] || match[4])
  8929. }
  8930. elm.attrs = attrs;
  8931. }
  8932. //trace:3970
  8933. // //如果parent下不能放elm
  8934. // if(dtd.$inline[parent.tagName] && dtd.$block[elm.tagName] && !dtd[parent.tagName][elm.tagName]){
  8935. // parent = parent.parentNode;
  8936. // elm.parentNode = parent;
  8937. // }
  8938. parent.children.push(elm);
  8939. //如果是自闭合节点返回父亲节点
  8940. return dtd.$empty[tagName] ? parent : elm
  8941. }
  8942. function comment(parent, data) {
  8943. parent.children.push(new uNode({
  8944. type:'comment',
  8945. data:data,
  8946. parentNode:parent
  8947. }));
  8948. }
  8949. var match, currentIndex = 0, nextIndex = 0;
  8950. //设置根节点
  8951. var root = new uNode({
  8952. type:'root',
  8953. children:[]
  8954. });
  8955. var currentParent = root;
  8956. while (match = re_tag.exec(htmlstr)) {
  8957. currentIndex = match.index;
  8958. try{
  8959. if (currentIndex > nextIndex) {
  8960. //text node
  8961. text(currentParent, htmlstr.slice(nextIndex, currentIndex));
  8962. }
  8963. if (match[3]) {
  8964. if(dtd.$cdata[currentParent.tagName]){
  8965. text(currentParent, match[0]);
  8966. }else{
  8967. //start tag
  8968. currentParent = element(currentParent, match[3].toLowerCase(), match[4]);
  8969. }
  8970. } else if (match[1]) {
  8971. if(currentParent.type != 'root'){
  8972. if(dtd.$cdata[currentParent.tagName] && !dtd.$cdata[match[1]]){
  8973. text(currentParent, match[0]);
  8974. }else{
  8975. var tmpParent = currentParent;
  8976. while(currentParent.type == 'element' && currentParent.tagName != match[1].toLowerCase()){
  8977. currentParent = currentParent.parentNode;
  8978. if(currentParent.type == 'root'){
  8979. currentParent = tmpParent;
  8980. throw 'break'
  8981. }
  8982. }
  8983. //end tag
  8984. currentParent = currentParent.parentNode;
  8985. }
  8986. }
  8987. } else if (match[2]) {
  8988. //comment
  8989. comment(currentParent, match[2])
  8990. }
  8991. }catch(e){}
  8992. nextIndex = re_tag.lastIndex;
  8993. }
  8994. //如果结束是文本,就有可能丢掉,所以这里手动判断一下
  8995. //例如 <li>sdfsdfsdf<li>sdfsdfsdfsdf
  8996. if (nextIndex < htmlstr.length) {
  8997. text(currentParent, htmlstr.slice(nextIndex));
  8998. }
  8999. return root;
  9000. };
  9001. // js/editor/_src/core/filternode.js
  9002. /**
  9003. * UE过滤节点的静态方法
  9004. * @file
  9005. */
  9006. /**
  9007. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  9008. * @module UE
  9009. */
  9010. /**
  9011. * 根据传入节点和过滤规则过滤相应节点
  9012. * @module UE
  9013. * @since 1.2.6.1
  9014. * @method filterNode
  9015. * @param { Object } root 指定root节点
  9016. * @param { Object } rules 过滤规则json对象
  9017. * @example
  9018. * ```javascript
  9019. * UE.filterNode(root,editor.options.filterRules);
  9020. * ```
  9021. */
  9022. var filterNode = UE.filterNode = function () {
  9023. function filterNode(node,rules){
  9024. switch (node.type) {
  9025. case 'text':
  9026. break;
  9027. case 'element':
  9028. var val;
  9029. if(val = rules[node.tagName]){
  9030. if(val === '-'){
  9031. node.parentNode.removeChild(node)
  9032. }else if(utils.isFunction(val)){
  9033. var parentNode = node.parentNode,
  9034. index = node.getIndex();
  9035. val(node);
  9036. if(node.parentNode){
  9037. if(node.children){
  9038. for(var i = 0,ci;ci=node.children[i];){
  9039. filterNode(ci,rules);
  9040. if(ci.parentNode){
  9041. i++;
  9042. }
  9043. }
  9044. }
  9045. }else{
  9046. for(var i = index,ci;ci=parentNode.children[i];){
  9047. filterNode(ci,rules);
  9048. if(ci.parentNode){
  9049. i++;
  9050. }
  9051. }
  9052. }
  9053. }else{
  9054. var attrs = val['$'];
  9055. if(attrs && node.attrs){
  9056. var tmpAttrs = {},tmpVal;
  9057. for(var a in attrs){
  9058. tmpVal = node.getAttr(a);
  9059. //todo 只先对style单独处理
  9060. if(a == 'style' && utils.isArray(attrs[a])){
  9061. var tmpCssStyle = [];
  9062. utils.each(attrs[a],function(v){
  9063. var tmp;
  9064. if(tmp = node.getStyle(v)){
  9065. tmpCssStyle.push(v + ':' + tmp);
  9066. }
  9067. });
  9068. tmpVal = tmpCssStyle.join(';')
  9069. }
  9070. if(tmpVal){
  9071. tmpAttrs[a] = tmpVal;
  9072. }
  9073. }
  9074. node.attrs = tmpAttrs;
  9075. }
  9076. if(node.children){
  9077. for(var i = 0,ci;ci=node.children[i];){
  9078. filterNode(ci,rules);
  9079. if(ci.parentNode){
  9080. i++;
  9081. }
  9082. }
  9083. }
  9084. }
  9085. }else{
  9086. //如果不在名单里扣出子节点并删除该节点,cdata除外
  9087. if(dtd.$cdata[node.tagName]){
  9088. node.parentNode.removeChild(node)
  9089. }else{
  9090. var parentNode = node.parentNode,
  9091. index = node.getIndex();
  9092. node.parentNode.removeChild(node,true);
  9093. for(var i = index,ci;ci=parentNode.children[i];){
  9094. filterNode(ci,rules);
  9095. if(ci.parentNode){
  9096. i++;
  9097. }
  9098. }
  9099. }
  9100. }
  9101. break;
  9102. case 'comment':
  9103. node.parentNode.removeChild(node)
  9104. }
  9105. }
  9106. return function(root,rules){
  9107. if(utils.isEmptyObject(rules)){
  9108. return root;
  9109. }
  9110. var val;
  9111. if(val = rules['-']){
  9112. utils.each(val.split(' '),function(k){
  9113. rules[k] = '-'
  9114. })
  9115. }
  9116. for(var i= 0,ci;ci=root.children[i];){
  9117. filterNode(ci,rules);
  9118. if(ci.parentNode){
  9119. i++;
  9120. }
  9121. }
  9122. return root;
  9123. }
  9124. }();
  9125. // js/editor/_src/core/plugin.js
  9126. /**
  9127. * Created with JetBrains PhpStorm.
  9128. * User: campaign
  9129. * Date: 10/8/13
  9130. * Time: 6:15 PM
  9131. * To change this template use File | Settings | File Templates.
  9132. */
  9133. UE.plugin = function(){
  9134. var _plugins = {};
  9135. return {
  9136. register : function(pluginName,fn,oldOptionName,afterDisabled){
  9137. if(oldOptionName && utils.isFunction(oldOptionName)){
  9138. afterDisabled = oldOptionName;
  9139. oldOptionName = null
  9140. }
  9141. _plugins[pluginName] = {
  9142. optionName : oldOptionName || pluginName,
  9143. execFn : fn,
  9144. //当插件被禁用时执行
  9145. afterDisabled : afterDisabled
  9146. }
  9147. },
  9148. load : function(editor){
  9149. utils.each(_plugins,function(plugin){
  9150. var _export = plugin.execFn.call(editor);
  9151. if(editor.options[plugin.optionName] !== false){
  9152. if(_export){
  9153. //后边需要再做扩展
  9154. utils.each(_export,function(v,k){
  9155. switch(k.toLowerCase()){
  9156. case 'shortcutkey':
  9157. editor.addshortcutkey(v);
  9158. break;
  9159. case 'bindevents':
  9160. utils.each(v,function(fn,eventName){
  9161. editor.addListener(eventName,fn);
  9162. });
  9163. break;
  9164. case 'bindmultievents':
  9165. utils.each(utils.isArray(v) ? v:[v],function(event){
  9166. var types = utils.trim(event.type).split(/\s+/);
  9167. utils.each(types,function(eventName){
  9168. editor.addListener(eventName, event.handler);
  9169. });
  9170. });
  9171. break;
  9172. case 'commands':
  9173. utils.each(v,function(execFn,execName){
  9174. editor.commands[execName] = execFn
  9175. });
  9176. break;
  9177. case 'outputrule':
  9178. editor.addOutputRule(v);
  9179. break;
  9180. case 'inputrule':
  9181. editor.addInputRule(v);
  9182. break;
  9183. case 'defaultoptions':
  9184. editor.setOpt(v)
  9185. }
  9186. })
  9187. }
  9188. }else if(plugin.afterDisabled){
  9189. plugin.afterDisabled.call(editor)
  9190. }
  9191. });
  9192. //向下兼容
  9193. utils.each(UE.plugins,function(plugin){
  9194. plugin.call(editor);
  9195. });
  9196. },
  9197. run : function(pluginName,editor){
  9198. var plugin = _plugins[pluginName];
  9199. if(plugin){
  9200. plugin.exeFn.call(editor)
  9201. }
  9202. }
  9203. }
  9204. }();
  9205. // js/editor/_src/core/keymap.js
  9206. var keymap = UE.keymap = {
  9207. 'Backspace' : 8,
  9208. 'Tab' : 9,
  9209. 'Enter' : 13,
  9210. 'Shift':16,
  9211. 'Control':17,
  9212. 'Alt':18,
  9213. 'CapsLock':20,
  9214. 'Esc':27,
  9215. 'Spacebar':32,
  9216. 'PageUp':33,
  9217. 'PageDown':34,
  9218. 'End':35,
  9219. 'Home':36,
  9220. 'Left':37,
  9221. 'Up':38,
  9222. 'Right':39,
  9223. 'Down':40,
  9224. 'Insert':45,
  9225. 'Del':46,
  9226. 'NumLock':144,
  9227. 'Cmd':91,
  9228. '=':187,
  9229. '-':189,
  9230. "b":66,
  9231. 'i':73,
  9232. //回退
  9233. 'z':90,
  9234. 'y':89,
  9235. //粘贴
  9236. 'v' : 86,
  9237. 'x' : 88,
  9238. 's' : 83,
  9239. 'n' : 78
  9240. };
  9241. // js/editor/_src/core/localstorage.js
  9242. //存储媒介封装
  9243. var LocalStorage = UE.LocalStorage = (function () {
  9244. var storage = window.localStorage || getUserData() || null,
  9245. LOCAL_FILE = 'localStorage';
  9246. return {
  9247. saveLocalData: function (key, data) {
  9248. if (storage && data) {
  9249. storage.setItem(key, data);
  9250. return true;
  9251. }
  9252. return false;
  9253. },
  9254. getLocalData: function (key) {
  9255. if (storage) {
  9256. return storage.getItem(key);
  9257. }
  9258. return null;
  9259. },
  9260. removeItem: function (key) {
  9261. storage && storage.removeItem(key);
  9262. }
  9263. };
  9264. function getUserData() {
  9265. var container = document.createElement("div");
  9266. container.style.display = "none";
  9267. if (!container.addBehavior) {
  9268. return null;
  9269. }
  9270. container.addBehavior("#default#userdata");
  9271. return {
  9272. getItem: function (key) {
  9273. var result = null;
  9274. try {
  9275. document.body.appendChild(container);
  9276. container.load(LOCAL_FILE);
  9277. result = container.getAttribute(key);
  9278. document.body.removeChild(container);
  9279. } catch (e) {
  9280. }
  9281. return result;
  9282. },
  9283. setItem: function (key, value) {
  9284. document.body.appendChild(container);
  9285. container.setAttribute(key, value);
  9286. container.save(LOCAL_FILE);
  9287. document.body.removeChild(container);
  9288. },
  9289. //// 暂时没有用到
  9290. //clear: function () {
  9291. //
  9292. // var expiresTime = new Date();
  9293. // expiresTime.setFullYear(expiresTime.getFullYear() - 1);
  9294. // document.body.appendChild(container);
  9295. // container.expires = expiresTime.toUTCString();
  9296. // container.save(LOCAL_FILE);
  9297. // document.body.removeChild(container);
  9298. //
  9299. //},
  9300. removeItem: function (key) {
  9301. document.body.appendChild(container);
  9302. container.removeAttribute(key);
  9303. container.save(LOCAL_FILE);
  9304. document.body.removeChild(container);
  9305. }
  9306. };
  9307. }
  9308. })();
  9309. (function () {
  9310. var ROOTKEY = 'ueditor_preference';
  9311. UE.Editor.prototype.setPreferences = function(key,value){
  9312. var obj = {};
  9313. if (utils.isString(key)) {
  9314. obj[ key ] = value;
  9315. } else {
  9316. obj = key;
  9317. }
  9318. var data = LocalStorage.getLocalData(ROOTKEY);
  9319. if (data && (data = utils.str2json(data))) {
  9320. utils.extend(data, obj);
  9321. } else {
  9322. data = obj;
  9323. }
  9324. data && LocalStorage.saveLocalData(ROOTKEY, utils.json2str(data));
  9325. };
  9326. UE.Editor.prototype.getPreferences = function(key){
  9327. var data = LocalStorage.getLocalData(ROOTKEY);
  9328. if (data && (data = utils.str2json(data))) {
  9329. return key ? data[key] : data
  9330. }
  9331. return null;
  9332. };
  9333. UE.Editor.prototype.removePreferences = function (key) {
  9334. var data = LocalStorage.getLocalData(ROOTKEY);
  9335. if (data && (data = utils.str2json(data))) {
  9336. data[key] = undefined;
  9337. delete data[key]
  9338. }
  9339. data && LocalStorage.saveLocalData(ROOTKEY, utils.json2str(data));
  9340. };
  9341. })();
  9342. // js/editor/_src/plugins/defaultfilter.js
  9343. ///import core
  9344. ///plugin 编辑器默认的过滤转换机制
  9345. UE.plugins['defaultfilter'] = function () {
  9346. var me = this;
  9347. me.setOpt({
  9348. 'allowDivTransToP':true,
  9349. 'disabledTableInTable':true
  9350. });
  9351. //默认的过滤处理
  9352. //进入编辑器的内容处理
  9353. me.addInputRule(function (root) {
  9354. var allowDivTransToP = this.options.allowDivTransToP;
  9355. var val;
  9356. function tdParent(node){
  9357. while(node && node.type == 'element'){
  9358. if(node.tagName == 'td'){
  9359. return true;
  9360. }
  9361. node = node.parentNode;
  9362. }
  9363. return false;
  9364. }
  9365. //进行默认的处理
  9366. root.traversal(function (node) {
  9367. if (node.type == 'element') {
  9368. if (!dtd.$cdata[node.tagName] && me.options.autoClearEmptyNode && dtd.$inline[node.tagName] && !dtd.$empty[node.tagName] && (!node.attrs || utils.isEmptyObject(node.attrs))) {
  9369. if (!node.firstChild()) node.parentNode.removeChild(node);
  9370. else if (node.tagName == 'span' && (!node.attrs || utils.isEmptyObject(node.attrs))) {
  9371. node.parentNode.removeChild(node, true)
  9372. }
  9373. return;
  9374. }
  9375. switch (node.tagName) {
  9376. case 'style':
  9377. case 'script':
  9378. node.setAttr({
  9379. cdata_tag: node.tagName,
  9380. cdata_data: (node.innerHTML() || ''),
  9381. '_ue_custom_node_':'true'
  9382. });
  9383. node.tagName = 'div';
  9384. node.innerHTML('');
  9385. break;
  9386. case 'a':
  9387. if (val = node.getAttr('href')) {
  9388. node.setAttr('_href', val)
  9389. }
  9390. break;
  9391. case 'img':
  9392. //todo base64暂时去掉,后边做远程图片上传后,干掉这个
  9393. if (val = node.getAttr('src')) {
  9394. if (/^data:/.test(val)) {
  9395. node.parentNode.removeChild(node);
  9396. break;
  9397. }
  9398. }
  9399. node.setAttr('_src', node.getAttr('src'));
  9400. break;
  9401. case 'span':
  9402. if (browser.webkit && (val = node.getStyle('white-space'))) {
  9403. if (/nowrap|normal/.test(val)) {
  9404. node.setStyle('white-space', '');
  9405. if (me.options.autoClearEmptyNode && utils.isEmptyObject(node.attrs)) {
  9406. node.parentNode.removeChild(node, true)
  9407. }
  9408. }
  9409. }
  9410. val = node.getAttr('id');
  9411. if(val && /^_baidu_bookmark_/i.test(val)){
  9412. node.parentNode.removeChild(node)
  9413. }
  9414. break;
  9415. case 'p':
  9416. if (val = node.getAttr('align')) {
  9417. node.setAttr('align');
  9418. node.setStyle('text-align', val)
  9419. }
  9420. //trace:3431
  9421. // var cssStyle = node.getAttr('style');
  9422. // if (cssStyle) {
  9423. // cssStyle = cssStyle.replace(/(margin|padding)[^;]+/g, '');
  9424. // node.setAttr('style', cssStyle)
  9425. //
  9426. // }
  9427. //p标签不允许嵌套
  9428. utils.each(node.children,function(n){
  9429. if(n.type == 'element' && n.tagName == 'p'){
  9430. var next = n.nextSibling();
  9431. node.parentNode.insertAfter(n,node);
  9432. var last = n;
  9433. while(next){
  9434. var tmp = next.nextSibling();
  9435. node.parentNode.insertAfter(next,last);
  9436. last = next;
  9437. next = tmp;
  9438. }
  9439. return false;
  9440. }
  9441. });
  9442. if (!node.firstChild()) {
  9443. node.innerHTML(browser.ie ? '&nbsp;' : '<br/>')
  9444. }
  9445. break;
  9446. case 'div':
  9447. if(node.getAttr('cdata_tag')){
  9448. break;
  9449. }
  9450. //针对代码这里不处理插入代码的div
  9451. val = node.getAttr('class');
  9452. if(val && /^line number\d+/.test(val)){
  9453. break;
  9454. }
  9455. if(!allowDivTransToP){
  9456. break;
  9457. }
  9458. var tmpNode, p = UE.uNode.createElement('p');
  9459. while (tmpNode = node.firstChild()) {
  9460. if (tmpNode.type == 'text' || !UE.dom.dtd.$block[tmpNode.tagName]) {
  9461. p.appendChild(tmpNode);
  9462. } else {
  9463. if (p.firstChild()) {
  9464. node.parentNode.insertBefore(p, node);
  9465. p = UE.uNode.createElement('p');
  9466. } else {
  9467. node.parentNode.insertBefore(tmpNode, node);
  9468. }
  9469. }
  9470. }
  9471. if (p.firstChild()) {
  9472. node.parentNode.insertBefore(p, node);
  9473. }
  9474. node.parentNode.removeChild(node);
  9475. break;
  9476. case 'dl':
  9477. node.tagName = 'ul';
  9478. break;
  9479. case 'dt':
  9480. case 'dd':
  9481. node.tagName = 'li';
  9482. break;
  9483. case 'li':
  9484. var className = node.getAttr('class');
  9485. if (!className || !/list\-/.test(className)) {
  9486. node.setAttr()
  9487. }
  9488. var tmpNodes = node.getNodesByTagName('ol ul');
  9489. UE.utils.each(tmpNodes, function (n) {
  9490. node.parentNode.insertAfter(n, node);
  9491. });
  9492. break;
  9493. case 'td':
  9494. case 'th':
  9495. case 'caption':
  9496. if(!node.children || !node.children.length){
  9497. node.appendChild(browser.ie11below ? UE.uNode.createText(' ') : UE.uNode.createElement('br'))
  9498. }
  9499. break;
  9500. case 'table':
  9501. if(me.options.disabledTableInTable && tdParent(node)){
  9502. node.parentNode.insertBefore(UE.uNode.createText(node.innerText()),node);
  9503. node.parentNode.removeChild(node)
  9504. }
  9505. }
  9506. }
  9507. // if(node.type == 'comment'){
  9508. // node.parentNode.removeChild(node);
  9509. // }
  9510. })
  9511. });
  9512. //从编辑器出去的内容处理
  9513. me.addOutputRule(function (root) {
  9514. var val;
  9515. root.traversal(function (node) {
  9516. if (node.type == 'element') {
  9517. if (me.options.autoClearEmptyNode && dtd.$inline[node.tagName] && !dtd.$empty[node.tagName] && (!node.attrs || utils.isEmptyObject(node.attrs))) {
  9518. if (!node.firstChild()) node.parentNode.removeChild(node);
  9519. else if (node.tagName == 'span' && (!node.attrs || utils.isEmptyObject(node.attrs))) {
  9520. node.parentNode.removeChild(node, true)
  9521. }
  9522. return;
  9523. }
  9524. switch (node.tagName) {
  9525. case 'div':
  9526. if (val = node.getAttr('cdata_tag')) {
  9527. node.tagName = val;
  9528. node.appendChild(UE.uNode.createText(node.getAttr('cdata_data')));
  9529. node.setAttr({cdata_tag: '', cdata_data: '','_ue_custom_node_':''});
  9530. }
  9531. break;
  9532. case 'a':
  9533. if (val = node.getAttr('_href')) {
  9534. node.setAttr({
  9535. 'href': utils.html(val),
  9536. '_href': ''
  9537. })
  9538. }
  9539. break;
  9540. break;
  9541. case 'span':
  9542. val = node.getAttr('id');
  9543. if(val && /^_baidu_bookmark_/i.test(val)){
  9544. node.parentNode.removeChild(node)
  9545. }
  9546. break;
  9547. case 'img':
  9548. if (val = node.getAttr('_src')) {
  9549. node.setAttr({
  9550. 'src': node.getAttr('_src'),
  9551. '_src': ''
  9552. })
  9553. }
  9554. }
  9555. }
  9556. })
  9557. });
  9558. };
  9559. // js/editor/_src/plugins/inserthtml.js
  9560. /**
  9561. * 插入html字符串插件
  9562. * @file
  9563. * @since 1.2.6.1
  9564. */
  9565. /**
  9566. * 插入html代码
  9567. * @command inserthtml
  9568. * @method execCommand
  9569. * @param { String } cmd 命令字符串
  9570. * @param { String } html 插入的html字符串
  9571. * @remaind 插入的标签内容是在当前的选区位置上插入,如果当前是闭合状态,那直接插入内容, 如果当前是选中状态,将先清除当前选中内容后,再做插入
  9572. * @warning 注意:该命令会对当前选区的位置,对插入的内容进行过滤转换处理。 过滤的规则遵循html语意化的原则。
  9573. * @example
  9574. * ```javascript
  9575. * //xxx[BB]xxx 当前选区为非闭合选区,选中BB这两个文本
  9576. * //执行命令,插入<b>CC</b>
  9577. * //插入后的效果 xxx<b>CC</b>xxx
  9578. * //<p>xx|xxx</p> 当前选区为闭合状态
  9579. * //插入<p>CC</p>
  9580. * //结果 <p>xx</p><p>CC</p><p>xxx</p>
  9581. * //<p>xxxx</p>|</p>xxx</p> 当前选区在两个p标签之间
  9582. * //插入 xxxx
  9583. * //结果 <p>xxxx</p><p>xxxx</p></p>xxx</p>
  9584. * ```
  9585. */
  9586. UE.commands['inserthtml'] = {
  9587. execCommand: function (command,html,notNeedFilter){
  9588. var me = this,
  9589. range,
  9590. div;
  9591. if(!html){
  9592. return;
  9593. }
  9594. if(me.fireEvent('beforeinserthtml',html) === true){
  9595. return;
  9596. }
  9597. range = me.selection.getRange();
  9598. div = range.document.createElement( 'div' );
  9599. div.style.display = 'inline';
  9600. if (!notNeedFilter) {
  9601. var root = UE.htmlparser(html);
  9602. //如果给了过滤规则就先进行过滤
  9603. if(me.options.filterRules){
  9604. UE.filterNode(root,me.options.filterRules);
  9605. }
  9606. //执行默认的处理
  9607. me.filterInputRule(root);
  9608. html = root.toHtml()
  9609. }
  9610. div.innerHTML = utils.trim( html );
  9611. if ( !range.collapsed ) {
  9612. var tmpNode = range.startContainer;
  9613. if(domUtils.isFillChar(tmpNode)){
  9614. range.setStartBefore(tmpNode)
  9615. }
  9616. tmpNode = range.endContainer;
  9617. if(domUtils.isFillChar(tmpNode)){
  9618. range.setEndAfter(tmpNode)
  9619. }
  9620. range.txtToElmBoundary();
  9621. //结束边界可能放到了br的前边,要把br包含进来
  9622. // x[xxx]<br/>
  9623. if(range.endContainer && range.endContainer.nodeType == 1){
  9624. tmpNode = range.endContainer.childNodes[range.endOffset];
  9625. if(tmpNode && domUtils.isBr(tmpNode)){
  9626. range.setEndAfter(tmpNode);
  9627. }
  9628. }
  9629. if(range.startOffset == 0){
  9630. tmpNode = range.startContainer;
  9631. if(domUtils.isBoundaryNode(tmpNode,'firstChild') ){
  9632. tmpNode = range.endContainer;
  9633. if(range.endOffset == (tmpNode.nodeType == 3 ? tmpNode.nodeValue.length : tmpNode.childNodes.length) && domUtils.isBoundaryNode(tmpNode,'lastChild')){
  9634. me.body.innerHTML = '<p>'+(browser.ie ? '' : '<br/>')+'</p>';
  9635. range.setStart(me.body.firstChild,0).collapse(true)
  9636. }
  9637. }
  9638. }
  9639. !range.collapsed && range.deleteContents();
  9640. if(range.startContainer.nodeType == 1){
  9641. var child = range.startContainer.childNodes[range.startOffset],pre;
  9642. if(child && domUtils.isBlockElm(child) && (pre = child.previousSibling) && domUtils.isBlockElm(pre)){
  9643. range.setEnd(pre,pre.childNodes.length).collapse();
  9644. while(child.firstChild){
  9645. pre.appendChild(child.firstChild);
  9646. }
  9647. domUtils.remove(child);
  9648. }
  9649. }
  9650. }
  9651. var child,parent,pre,tmp,hadBreak = 0, nextNode;
  9652. //如果当前位置选中了fillchar要干掉,要不会产生空行
  9653. if(range.inFillChar()){
  9654. child = range.startContainer;
  9655. if(domUtils.isFillChar(child)){
  9656. range.setStartBefore(child).collapse(true);
  9657. domUtils.remove(child);
  9658. }else if(domUtils.isFillChar(child,true)){
  9659. child.nodeValue = child.nodeValue.replace(fillCharReg,'');
  9660. range.startOffset--;
  9661. range.collapsed && range.collapse(true)
  9662. }
  9663. }
  9664. //列表单独处理
  9665. var li = domUtils.findParentByTagName(range.startContainer,'li',true);
  9666. if(li){
  9667. var next,last;
  9668. while(child = div.firstChild){
  9669. //针对hr单独处理一下先
  9670. while(child && (child.nodeType == 3 || !domUtils.isBlockElm(child) || child.tagName=='HR' )){
  9671. next = child.nextSibling;
  9672. range.insertNode( child).collapse();
  9673. last = child;
  9674. child = next;
  9675. }
  9676. if(child){
  9677. if(/^(ol|ul)$/i.test(child.tagName)){
  9678. while(child.firstChild){
  9679. last = child.firstChild;
  9680. domUtils.insertAfter(li,child.firstChild);
  9681. li = li.nextSibling;
  9682. }
  9683. domUtils.remove(child)
  9684. }else{
  9685. var tmpLi;
  9686. next = child.nextSibling;
  9687. tmpLi = me.document.createElement('li');
  9688. domUtils.insertAfter(li,tmpLi);
  9689. tmpLi.appendChild(child);
  9690. last = child;
  9691. child = next;
  9692. li = tmpLi;
  9693. }
  9694. }
  9695. }
  9696. li = domUtils.findParentByTagName(range.startContainer,'li',true);
  9697. if(domUtils.isEmptyBlock(li)){
  9698. domUtils.remove(li)
  9699. }
  9700. if(last){
  9701. range.setStartAfter(last).collapse(true).select(true)
  9702. }
  9703. }else{
  9704. while ( child = div.firstChild ) {
  9705. if(hadBreak){
  9706. var p = me.document.createElement('p');
  9707. while(child && (child.nodeType == 3 || !dtd.$block[child.tagName])){
  9708. nextNode = child.nextSibling;
  9709. p.appendChild(child);
  9710. child = nextNode;
  9711. }
  9712. if(p.firstChild){
  9713. child = p
  9714. }
  9715. }
  9716. range.insertNode( child );
  9717. nextNode = child.nextSibling;
  9718. if ( !hadBreak && child.nodeType == domUtils.NODE_ELEMENT && domUtils.isBlockElm( child ) ){
  9719. parent = domUtils.findParent( child,function ( node ){ return domUtils.isBlockElm( node ); } );
  9720. if ( parent && parent.tagName.toLowerCase() != 'body' && !(dtd[parent.tagName][child.nodeName] && child.parentNode === parent)){
  9721. if(!dtd[parent.tagName][child.nodeName]){
  9722. pre = parent;
  9723. }else{
  9724. tmp = child.parentNode;
  9725. while (tmp !== parent){
  9726. pre = tmp;
  9727. tmp = tmp.parentNode;
  9728. }
  9729. }
  9730. domUtils.breakParent( child, pre || tmp );
  9731. //去掉break后前一个多余的节点 <p>|<[p> ==> <p></p><div></div><p>|</p>
  9732. var pre = child.previousSibling;
  9733. domUtils.trimWhiteTextNode(pre);
  9734. if(!pre.childNodes.length){
  9735. domUtils.remove(pre);
  9736. }
  9737. //trace:2012,在非ie的情况,切开后剩下的节点有可能不能点入光标添加br占位
  9738. if(!browser.ie &&
  9739. (next = child.nextSibling) &&
  9740. domUtils.isBlockElm(next) &&
  9741. next.lastChild &&
  9742. !domUtils.isBr(next.lastChild)){
  9743. next.appendChild(me.document.createElement('br'));
  9744. }
  9745. hadBreak = 1;
  9746. }
  9747. }
  9748. var next = child.nextSibling;
  9749. if(!div.firstChild && next && domUtils.isBlockElm(next)){
  9750. range.setStart(next,0).collapse(true);
  9751. break;
  9752. }
  9753. range.setEndAfter( child ).collapse();
  9754. }
  9755. child = range.startContainer;
  9756. if(nextNode && domUtils.isBr(nextNode)){
  9757. domUtils.remove(nextNode)
  9758. }
  9759. //用chrome可能有空白展位符
  9760. if(domUtils.isBlockElm(child) && domUtils.isEmptyNode(child)){
  9761. if(nextNode = child.nextSibling){
  9762. domUtils.remove(child);
  9763. if(nextNode.nodeType == 1 && dtd.$block[nextNode.tagName]){
  9764. range.setStart(nextNode,0).collapse(true).shrinkBoundary()
  9765. }
  9766. }else{
  9767. try{
  9768. child.innerHTML = browser.ie ? domUtils.fillChar : '<br/>';
  9769. }catch(e){
  9770. range.setStartBefore(child);
  9771. domUtils.remove(child)
  9772. }
  9773. }
  9774. }
  9775. //加上true因为在删除表情等时会删两次,第一次是删的fillData
  9776. try{
  9777. range.select(true);
  9778. }catch(e){}
  9779. }
  9780. setTimeout(function(){
  9781. range = me.selection.getRange();
  9782. range.scrollToView(me.autoHeightEnabled,me.autoHeightEnabled ? domUtils.getXY(me.iframe).y:0);
  9783. me.fireEvent('afterinserthtml', html);
  9784. },200);
  9785. }
  9786. };
  9787. // js/editor/_src/plugins/autotypeset.js
  9788. /**
  9789. * 自动排版
  9790. * @file
  9791. * @since 1.2.6.1
  9792. */
  9793. /**
  9794. * 对当前编辑器的内容执行自动排版, 排版的行为根据config配置文件里的“autotypeset”选项进行控制。
  9795. * @command autotypeset
  9796. * @method execCommand
  9797. * @param { String } cmd 命令字符串
  9798. * @example
  9799. * ```javascript
  9800. * editor.execCommand( 'autotypeset' );
  9801. * ```
  9802. */
  9803. UE.plugins['autotypeset'] = function(){
  9804. this.setOpt({'autotypeset': {
  9805. mergeEmptyline: true, //合并空行
  9806. removeClass: true, //去掉冗余的class
  9807. removeEmptyline: false, //去掉空行
  9808. textAlign:"left", //段落的排版方式,可以是 left,right,center,justify 去掉这个属性表示不执行排版
  9809. imageBlockLine: 'center', //图片的浮动方式,独占一行剧中,左右浮动,默认: center,left,right,none 去掉这个属性表示不执行排版
  9810. pasteFilter: false, //根据规则过滤没事粘贴进来的内容
  9811. clearFontSize: false, //去掉所有的内嵌字号,使用编辑器默认的字号
  9812. clearFontFamily: false, //去掉所有的内嵌字体,使用编辑器默认的字体
  9813. removeEmptyNode: false, // 去掉空节点
  9814. //可以去掉的标签
  9815. removeTagNames: utils.extend({div:1},dtd.$removeEmpty),
  9816. indent: false, // 行首缩进
  9817. indentValue : '2em', //行首缩进的大小
  9818. bdc2sb: false,
  9819. tobdc: false
  9820. }});
  9821. var me = this,
  9822. opt = me.options.autotypeset,
  9823. remainClass = {
  9824. 'selectTdClass':1,
  9825. 'pagebreak':1,
  9826. 'anchorclass':1
  9827. },
  9828. remainTag = {
  9829. 'li':1
  9830. },
  9831. tags = {
  9832. div:1,
  9833. p:1,
  9834. //trace:2183 这些也认为是行
  9835. blockquote:1,center:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,
  9836. span:1
  9837. },
  9838. highlightCont;
  9839. //升级了版本,但配置项目里没有autotypeset
  9840. if(!opt){
  9841. return;
  9842. }
  9843. readLocalOpts();
  9844. function isLine(node,notEmpty){
  9845. if(!node || node.nodeType == 3)
  9846. return 0;
  9847. if(domUtils.isBr(node))
  9848. return 1;
  9849. if(node && node.parentNode && tags[node.tagName.toLowerCase()]){
  9850. if(highlightCont && highlightCont.contains(node)
  9851. ||
  9852. node.getAttribute('pagebreak')
  9853. ){
  9854. return 0;
  9855. }
  9856. return notEmpty ? !domUtils.isEmptyBlock(node) : domUtils.isEmptyBlock(node,new RegExp('[\\s'+domUtils.fillChar
  9857. +']','g'));
  9858. }
  9859. }
  9860. function removeNotAttributeSpan(node){
  9861. if(!node.style.cssText){
  9862. domUtils.removeAttributes(node,['style']);
  9863. if(node.tagName.toLowerCase() == 'span' && domUtils.hasNoAttributes(node)){
  9864. domUtils.remove(node,true);
  9865. }
  9866. }
  9867. }
  9868. function autotype(type,html){
  9869. var me = this,cont;
  9870. if(html){
  9871. if(!opt.pasteFilter){
  9872. return;
  9873. }
  9874. cont = me.document.createElement('div');
  9875. cont.innerHTML = html.html;
  9876. }else{
  9877. cont = me.document.body;
  9878. }
  9879. var nodes = domUtils.getElementsByTagName(cont,'*');
  9880. // 行首缩进,段落方向,段间距,段内间距
  9881. for(var i=0,ci;ci=nodes[i++];){
  9882. if(me.fireEvent('excludeNodeinautotype',ci) === true){
  9883. continue;
  9884. }
  9885. //font-size
  9886. if(opt.clearFontSize && ci.style.fontSize){
  9887. domUtils.removeStyle(ci,'font-size');
  9888. removeNotAttributeSpan(ci);
  9889. }
  9890. //font-family
  9891. if(opt.clearFontFamily && ci.style.fontFamily){
  9892. domUtils.removeStyle(ci,'font-family');
  9893. removeNotAttributeSpan(ci);
  9894. }
  9895. if(isLine(ci)){
  9896. //合并空行
  9897. if(opt.mergeEmptyline ){
  9898. var next = ci.nextSibling,tmpNode,isBr = domUtils.isBr(ci);
  9899. while(isLine(next)){
  9900. tmpNode = next;
  9901. next = tmpNode.nextSibling;
  9902. if(isBr && (!next || next && !domUtils.isBr(next))){
  9903. break;
  9904. }
  9905. domUtils.remove(tmpNode);
  9906. }
  9907. }
  9908. //去掉空行,保留占位的空行
  9909. if(opt.removeEmptyline && domUtils.inDoc(ci,cont) && !remainTag[ci.parentNode.tagName.toLowerCase()] ){
  9910. if(domUtils.isBr(ci)){
  9911. next = ci.nextSibling;
  9912. if(next && !domUtils.isBr(next)){
  9913. continue;
  9914. }
  9915. }
  9916. domUtils.remove(ci);
  9917. continue;
  9918. }
  9919. }
  9920. if(isLine(ci,true) && ci.tagName != 'SPAN'){
  9921. if(opt.indent){
  9922. ci.style.textIndent = opt.indentValue;
  9923. }
  9924. if(opt.textAlign){
  9925. ci.style.textAlign = opt.textAlign;
  9926. }
  9927. // if(opt.lineHeight)
  9928. // ci.style.lineHeight = opt.lineHeight + 'cm';
  9929. }
  9930. //去掉class,保留的class不去掉
  9931. if(opt.removeClass && ci.className && !remainClass[ci.className.toLowerCase()]){
  9932. if(highlightCont && highlightCont.contains(ci)){
  9933. continue;
  9934. }
  9935. domUtils.removeAttributes(ci,['class']);
  9936. }
  9937. //表情不处理
  9938. if(opt.imageBlockLine && ci.tagName.toLowerCase() == 'img' && !ci.getAttribute('emotion')){
  9939. if(html){
  9940. var img = ci;
  9941. switch (opt.imageBlockLine){
  9942. case 'left':
  9943. case 'right':
  9944. case 'none':
  9945. var pN = img.parentNode,tmpNode,pre,next;
  9946. while(dtd.$inline[pN.tagName] || pN.tagName == 'A'){
  9947. pN = pN.parentNode;
  9948. }
  9949. tmpNode = pN;
  9950. if(tmpNode.tagName == 'P' && domUtils.getStyle(tmpNode,'text-align') == 'center'){
  9951. if(!domUtils.isBody(tmpNode) && domUtils.getChildCount(tmpNode,function(node){return !domUtils.isBr(node) && !domUtils.isWhitespace(node)}) == 1){
  9952. pre = tmpNode.previousSibling;
  9953. next = tmpNode.nextSibling;
  9954. if(pre && next && pre.nodeType == 1 && next.nodeType == 1 && pre.tagName == next.tagName && domUtils.isBlockElm(pre)){
  9955. pre.appendChild(tmpNode.firstChild);
  9956. while(next.firstChild){
  9957. pre.appendChild(next.firstChild);
  9958. }
  9959. domUtils.remove(tmpNode);
  9960. domUtils.remove(next);
  9961. }else{
  9962. domUtils.setStyle(tmpNode,'text-align','');
  9963. }
  9964. }
  9965. }
  9966. domUtils.setStyle(img,'float', opt.imageBlockLine);
  9967. break;
  9968. case 'center':
  9969. if(me.queryCommandValue('imagefloat') != 'center'){
  9970. pN = img.parentNode;
  9971. domUtils.setStyle(img,'float','none');
  9972. tmpNode = img;
  9973. while(pN && domUtils.getChildCount(pN,function(node){return !domUtils.isBr(node) && !domUtils.isWhitespace(node)}) == 1
  9974. && (dtd.$inline[pN.tagName] || pN.tagName == 'A')){
  9975. tmpNode = pN;
  9976. pN = pN.parentNode;
  9977. }
  9978. var pNode = me.document.createElement('p');
  9979. domUtils.setAttributes(pNode,{
  9980. style:'text-align:center'
  9981. });
  9982. tmpNode.parentNode.insertBefore(pNode,tmpNode);
  9983. pNode.appendChild(tmpNode);
  9984. domUtils.setStyle(tmpNode,'float','');
  9985. }
  9986. }
  9987. } else {
  9988. var range = me.selection.getRange();
  9989. range.selectNode(ci).select();
  9990. me.execCommand('imagefloat', opt.imageBlockLine);
  9991. }
  9992. }
  9993. //去掉冗余的标签
  9994. if(opt.removeEmptyNode){
  9995. if(opt.removeTagNames[ci.tagName.toLowerCase()] && domUtils.hasNoAttributes(ci) && domUtils.isEmptyBlock(ci)){
  9996. domUtils.remove(ci);
  9997. }
  9998. }
  9999. }
  10000. if(opt.tobdc){
  10001. var root = UE.htmlparser(cont.innerHTML);
  10002. root.traversal(function(node){
  10003. if(node.type == 'text'){
  10004. node.data = ToDBC(node.data)
  10005. }
  10006. });
  10007. cont.innerHTML = root.toHtml()
  10008. }
  10009. if(opt.bdc2sb){
  10010. var root = UE.htmlparser(cont.innerHTML);
  10011. root.traversal(function(node){
  10012. if(node.type == 'text'){
  10013. node.data = DBC2SB(node.data)
  10014. }
  10015. });
  10016. cont.innerHTML = root.toHtml()
  10017. }
  10018. if(html){
  10019. html.html = cont.innerHTML;
  10020. }
  10021. }
  10022. if(opt.pasteFilter){
  10023. me.addListener('beforepaste',autotype);
  10024. }
  10025. function DBC2SB(str) {
  10026. var result = '';
  10027. for (var i = 0; i < str.length; i++) {
  10028. var code = str.charCodeAt(i); //获取当前字符的unicode编码
  10029. if (code >= 65281 && code <= 65373)//在这个unicode编码范围中的是所有的英文字母已经各种字符
  10030. {
  10031. result += String.fromCharCode(str.charCodeAt(i) - 65248); //把全角字符的unicode编码转换为对应半角字符的unicode码
  10032. } else if (code == 12288)//空格
  10033. {
  10034. result += String.fromCharCode(str.charCodeAt(i) - 12288 + 32);
  10035. } else {
  10036. result += str.charAt(i);
  10037. }
  10038. }
  10039. return result;
  10040. }
  10041. function ToDBC(txtstring) {
  10042. txtstring = utils.html(txtstring);
  10043. var tmp = "";
  10044. var mark = "";/*用于判断,如果是html尖括里的标记,则不进行全角的转换*/
  10045. for (var i = 0; i < txtstring.length; i++) {
  10046. if (txtstring.charCodeAt(i) == 32) {
  10047. tmp = tmp + String.fromCharCode(12288);
  10048. }
  10049. else if (txtstring.charCodeAt(i) < 127) {
  10050. tmp = tmp + String.fromCharCode(txtstring.charCodeAt(i) + 65248);
  10051. }
  10052. else {
  10053. tmp += txtstring.charAt(i);
  10054. }
  10055. }
  10056. return tmp;
  10057. }
  10058. function readLocalOpts() {
  10059. var cookieOpt = me.getPreferences('autotypeset');
  10060. utils.extend(me.options.autotypeset, cookieOpt);
  10061. }
  10062. me.commands['autotypeset'] = {
  10063. execCommand:function () {
  10064. me.removeListener('beforepaste',autotype);
  10065. if(opt.pasteFilter){
  10066. me.addListener('beforepaste',autotype);
  10067. }
  10068. autotype.call(me)
  10069. }
  10070. };
  10071. };
  10072. // js/editor/_src/plugins/autosubmit.js
  10073. /**
  10074. * 快捷键提交
  10075. * @file
  10076. * @since 1.2.6.1
  10077. */
  10078. /**
  10079. * 提交表单
  10080. * @command autosubmit
  10081. * @method execCommand
  10082. * @param { String } cmd 命令字符串
  10083. * @example
  10084. * ```javascript
  10085. * editor.execCommand( 'autosubmit' );
  10086. * ```
  10087. */
  10088. UE.plugin.register('autosubmit',function(){
  10089. return {
  10090. shortcutkey:{
  10091. "autosubmit":"ctrl+13" //手动提交
  10092. },
  10093. commands:{
  10094. 'autosubmit':{
  10095. execCommand:function () {
  10096. var me=this,
  10097. form = domUtils.findParentByTagName(me.iframe,"form", false);
  10098. if (form){
  10099. if(me.fireEvent("beforesubmit")===false){
  10100. return;
  10101. }
  10102. me.sync();
  10103. form.submit();
  10104. }
  10105. }
  10106. }
  10107. }
  10108. }
  10109. });
  10110. // js/editor/_src/plugins/background.js
  10111. /**
  10112. * 背景插件,为UEditor提供设置背景功能
  10113. * @file
  10114. * @since 1.2.6.1
  10115. */
  10116. UE.plugin.register('background', function () {
  10117. var me = this,
  10118. cssRuleId = 'editor_background',
  10119. isSetColored,
  10120. reg = new RegExp('body[\\s]*\\{(.+)\\}', 'i');
  10121. function stringToObj(str) {
  10122. var obj = {}, styles = str.split(';');
  10123. utils.each(styles, function (v) {
  10124. var index = v.indexOf(':'),
  10125. key = utils.trim(v.substr(0, index)).toLowerCase();
  10126. key && (obj[key] = utils.trim(v.substr(index + 1) || ''));
  10127. });
  10128. return obj;
  10129. }
  10130. function setBackground(obj) {
  10131. if (obj) {
  10132. var styles = [];
  10133. for (var name in obj) {
  10134. if (obj.hasOwnProperty(name)) {
  10135. styles.push(name + ":" + obj[name] + '; ');
  10136. }
  10137. }
  10138. utils.cssRule(cssRuleId, styles.length ? ('body{' + styles.join("") + '}') : '', me.document);
  10139. } else {
  10140. utils.cssRule(cssRuleId, '', me.document)
  10141. }
  10142. }
  10143. //重写editor.hasContent方法
  10144. var orgFn = me.hasContents;
  10145. me.hasContents = function(){
  10146. if(me.queryCommandValue('background')){
  10147. return true
  10148. }
  10149. return orgFn.apply(me,arguments);
  10150. };
  10151. return {
  10152. bindEvents: {
  10153. 'getAllHtml': function (type, headHtml) {
  10154. var body = this.body,
  10155. su = domUtils.getComputedStyle(body, "background-image"),
  10156. url = "";
  10157. if (su.indexOf(me.options.imagePath) > 0) {
  10158. url = su.substring(su.indexOf(me.options.imagePath), su.length - 1).replace(/"|\(|\)/ig, ""); //"
  10159. } else {
  10160. url = su != "none" ? su.replace(/url\("?|"?\)/ig, "") : "";
  10161. }
  10162. var html = '<style type="text/css">body{';
  10163. var bgObj = {
  10164. "background-color": domUtils.getComputedStyle(body, "background-color") || "#ffffff",
  10165. 'background-image': url ? 'url(' + url + ')' : '',
  10166. 'background-repeat': domUtils.getComputedStyle(body, "background-repeat") || "",
  10167. 'background-position': browser.ie ? (domUtils.getComputedStyle(body, "background-position-x") + " " + domUtils.getComputedStyle(body, "background-position-y")) : domUtils.getComputedStyle(body, "background-position"),
  10168. 'height': domUtils.getComputedStyle(body, "height")
  10169. };
  10170. for (var name in bgObj) {
  10171. if (bgObj.hasOwnProperty(name)) {
  10172. html += name + ":" + bgObj[name] + "; ";
  10173. }
  10174. }
  10175. html += '}</style> ';
  10176. headHtml.push(html);
  10177. },
  10178. 'aftersetcontent': function () {
  10179. if(isSetColored == false) setBackground();
  10180. }
  10181. },
  10182. inputRule: function (root) {
  10183. isSetColored = false;
  10184. utils.each(root.getNodesByTagName('p'), function (p) {
  10185. var styles = p.getAttr('data-background');
  10186. if (styles) {
  10187. isSetColored = true;
  10188. setBackground(stringToObj(styles));
  10189. p.parentNode.removeChild(p);
  10190. }
  10191. })
  10192. },
  10193. outputRule: function (root) {
  10194. var me = this,
  10195. styles = (utils.cssRule(cssRuleId, me.document) || '').replace(/[\n\r]+/g, '').match(reg);
  10196. if (styles) {
  10197. root.appendChild(UE.uNode.createElement('<p style="display:none;" data-background="' + utils.trim(styles[1].replace(/"/g, '').replace(/[\s]+/g, ' ')) + '"><br/></p>')); //"'
  10198. }
  10199. },
  10200. commands: {
  10201. 'background': {
  10202. execCommand: function (cmd, obj) {
  10203. setBackground(obj);
  10204. },
  10205. queryCommandValue: function () {
  10206. var me = this,
  10207. styles = (utils.cssRule(cssRuleId, me.document) || '').replace(/[\n\r]+/g, '').match(reg);
  10208. return styles ? stringToObj(styles[1]) : null;
  10209. },
  10210. notNeedUndo: true
  10211. }
  10212. }
  10213. }
  10214. });
  10215. // js/editor/_src/plugins/image.js
  10216. /**
  10217. * 图片插入、排版插件
  10218. * @file
  10219. * @since 1.2.6.1
  10220. */
  10221. /**
  10222. * 图片对齐方式
  10223. * @command imagefloat
  10224. * @method execCommand
  10225. * @remind 值center为独占一行居中
  10226. * @param { String } cmd 命令字符串
  10227. * @param { String } align 对齐方式,可传left、right、none、center
  10228. * @remaind center表示图片独占一行
  10229. * @example
  10230. * ```javascript
  10231. * editor.execCommand( 'imagefloat', 'center' );
  10232. * ```
  10233. */
  10234. /**
  10235. * 如果选区所在位置是图片区域
  10236. * @command imagefloat
  10237. * @method queryCommandValue
  10238. * @param { String } cmd 命令字符串
  10239. * @return { String } 返回图片对齐方式
  10240. * @example
  10241. * ```javascript
  10242. * editor.queryCommandValue( 'imagefloat' );
  10243. * ```
  10244. */
  10245. UE.commands['imagefloat'] = {
  10246. execCommand:function (cmd, align) {
  10247. var me = this,
  10248. range = me.selection.getRange();
  10249. if (!range.collapsed) {
  10250. var img = range.getClosedNode();
  10251. if (img && img.tagName == 'IMG') {
  10252. switch (align) {
  10253. case 'left':
  10254. case 'right':
  10255. case 'none':
  10256. var pN = img.parentNode, tmpNode, pre, next;
  10257. while (dtd.$inline[pN.tagName] || pN.tagName == 'A') {
  10258. pN = pN.parentNode;
  10259. }
  10260. tmpNode = pN;
  10261. if (tmpNode.tagName == 'P' && domUtils.getStyle(tmpNode, 'text-align') == 'center') {
  10262. if (!domUtils.isBody(tmpNode) && domUtils.getChildCount(tmpNode, function (node) {
  10263. return !domUtils.isBr(node) && !domUtils.isWhitespace(node);
  10264. }) == 1) {
  10265. pre = tmpNode.previousSibling;
  10266. next = tmpNode.nextSibling;
  10267. if (pre && next && pre.nodeType == 1 && next.nodeType == 1 && pre.tagName == next.tagName && domUtils.isBlockElm(pre)) {
  10268. pre.appendChild(tmpNode.firstChild);
  10269. while (next.firstChild) {
  10270. pre.appendChild(next.firstChild);
  10271. }
  10272. domUtils.remove(tmpNode);
  10273. domUtils.remove(next);
  10274. } else {
  10275. domUtils.setStyle(tmpNode, 'text-align', '');
  10276. }
  10277. }
  10278. range.selectNode(img).select();
  10279. }
  10280. domUtils.setStyle(img, 'float', align == 'none' ? '' : align);
  10281. if(align == 'none'){
  10282. domUtils.removeAttributes(img,'align');
  10283. }
  10284. break;
  10285. case 'center':
  10286. if (me.queryCommandValue('imagefloat') != 'center') {
  10287. pN = img.parentNode;
  10288. domUtils.setStyle(img, 'float', '');
  10289. domUtils.removeAttributes(img,'align');
  10290. tmpNode = img;
  10291. while (pN && domUtils.getChildCount(pN, function (node) {
  10292. return !domUtils.isBr(node) && !domUtils.isWhitespace(node);
  10293. }) == 1
  10294. && (dtd.$inline[pN.tagName] || pN.tagName == 'A')) {
  10295. tmpNode = pN;
  10296. pN = pN.parentNode;
  10297. }
  10298. range.setStartBefore(tmpNode).setCursor(false);
  10299. pN = me.document.createElement('div');
  10300. pN.appendChild(tmpNode);
  10301. domUtils.setStyle(tmpNode, 'float', '');
  10302. me.execCommand('insertHtml', '<p id="_img_parent_tmp" style="text-align:center">' + pN.innerHTML + '</p>');
  10303. tmpNode = me.document.getElementById('_img_parent_tmp');
  10304. tmpNode.removeAttribute('id');
  10305. tmpNode = tmpNode.firstChild;
  10306. range.selectNode(tmpNode).select();
  10307. //去掉后边多余的元素
  10308. next = tmpNode.parentNode.nextSibling;
  10309. if (next && domUtils.isEmptyNode(next)) {
  10310. domUtils.remove(next);
  10311. }
  10312. }
  10313. break;
  10314. }
  10315. }
  10316. }
  10317. },
  10318. queryCommandValue:function () {
  10319. var range = this.selection.getRange(),
  10320. startNode, floatStyle;
  10321. if (range.collapsed) {
  10322. return 'none';
  10323. }
  10324. startNode = range.getClosedNode();
  10325. if (startNode && startNode.nodeType == 1 && startNode.tagName == 'IMG') {
  10326. floatStyle = domUtils.getComputedStyle(startNode, 'float') || startNode.getAttribute('align');
  10327. if (floatStyle == 'none') {
  10328. floatStyle = domUtils.getComputedStyle(startNode.parentNode, 'text-align') == 'center' ? 'center' : floatStyle;
  10329. }
  10330. return {
  10331. left:1,
  10332. right:1,
  10333. center:1
  10334. }[floatStyle] ? floatStyle : 'none';
  10335. }
  10336. return 'none';
  10337. },
  10338. queryCommandState:function () {
  10339. var range = this.selection.getRange(),
  10340. startNode;
  10341. if (range.collapsed) return -1;
  10342. startNode = range.getClosedNode();
  10343. if (startNode && startNode.nodeType == 1 && startNode.tagName == 'IMG') {
  10344. return 0;
  10345. }
  10346. return -1;
  10347. }
  10348. };
  10349. /**
  10350. * 插入图片
  10351. * @command insertimage
  10352. * @method execCommand
  10353. * @param { String } cmd 命令字符串
  10354. * @param { Object } opt 属性键值对,这些属性都将被复制到当前插入图片
  10355. * @remind 该命令第二个参数可接受一个图片配置项对象的数组,可以插入多张图片,
  10356. * 此时数组的每一个元素都是一个Object类型的图片属性集合。
  10357. * @example
  10358. * ```javascript
  10359. * editor.execCommand( 'insertimage', {
  10360. * src:'a/b/c.jpg',
  10361. * width:'100',
  10362. * height:'100'
  10363. * } );
  10364. * ```
  10365. * @example
  10366. * ```javascript
  10367. * editor.execCommand( 'insertimage', [{
  10368. * src:'a/b/c.jpg',
  10369. * width:'100',
  10370. * height:'100'
  10371. * },{
  10372. * src:'a/b/d.jpg',
  10373. * width:'100',
  10374. * height:'100'
  10375. * }] );
  10376. * ```
  10377. */
  10378. UE.commands['insertimage'] = {
  10379. execCommand:function (cmd, opt) {
  10380. opt = utils.isArray(opt) ? opt : [opt];
  10381. if (!opt.length) {
  10382. return;
  10383. }
  10384. var me = this,
  10385. range = me.selection.getRange(),
  10386. img = range.getClosedNode();
  10387. if(me.fireEvent('beforeinsertimage', opt) === true){
  10388. return;
  10389. }
  10390. if (img && /img/i.test(img.tagName) && (img.className != "edui-faked-video" || img.className.indexOf("edui-upload-video")!=-1) && !img.getAttribute("word_img")) {
  10391. var first = opt.shift();
  10392. var floatStyle = first['floatStyle'];
  10393. delete first['floatStyle'];
  10394. //// img.style.border = (first.border||0) +"px solid #000";
  10395. //// img.style.margin = (first.margin||0) +"px";
  10396. // img.style.cssText += ';margin:' + (first.margin||0) +"px;" + 'border:' + (first.border||0) +"px solid #000";
  10397. domUtils.setAttributes(img, first);
  10398. me.execCommand('imagefloat', floatStyle);
  10399. if (opt.length > 0) {
  10400. range.setStartAfter(img).setCursor(false, true);
  10401. me.execCommand('insertimage', opt);
  10402. }
  10403. } else {
  10404. var html = [], str = '', ci;
  10405. ci = opt[0];
  10406. if (opt.length == 1) {
  10407. str = '<img src="' + ci.src + '" ' + (ci._src ? ' _src="' + ci._src + '" ' : '') +
  10408. (ci.width ? 'width="' + ci.width + '" ' : '') +
  10409. (ci.height ? ' height="' + ci.height + '" ' : '') +
  10410. (ci['floatStyle'] == 'left' || ci['floatStyle'] == 'right' ? ' style="float:' + ci['floatStyle'] + ';"' : '') +
  10411. (ci.title && ci.title != "" ? ' title="' + ci.title + '"' : '') +
  10412. (ci.border && ci.border != "0" ? ' border="' + ci.border + '"' : '') +
  10413. (ci.alt && ci.alt != "" ? ' alt="' + ci.alt + '"' : '') +
  10414. (ci.hspace && ci.hspace != "0" ? ' hspace = "' + ci.hspace + '"' : '') +
  10415. (ci.vspace && ci.vspace != "0" ? ' vspace = "' + ci.vspace + '"' : '') + '/>';
  10416. if (ci['floatStyle'] == 'center') {
  10417. str = '<p style="text-align: center">' + str + '</p>';
  10418. }
  10419. html.push(str);
  10420. } else {
  10421. for (var i = 0; ci = opt[i++];) {
  10422. str = '<p ' + (ci['floatStyle'] == 'center' ? 'style="text-align: center" ' : '') + '><img src="' + ci.src + '" ' +
  10423. (ci.width ? 'width="' + ci.width + '" ' : '') + (ci._src ? ' _src="' + ci._src + '" ' : '') +
  10424. (ci.height ? ' height="' + ci.height + '" ' : '') +
  10425. ' style="' + (ci['floatStyle'] && ci['floatStyle'] != 'center' ? 'float:' + ci['floatStyle'] + ';' : '') +
  10426. (ci.border || '') + '" ' +
  10427. (ci.title ? ' title="' + ci.title + '"' : '') + ' /></p>';
  10428. html.push(str);
  10429. }
  10430. }
  10431. me.execCommand('insertHtml', html.join(''));
  10432. }
  10433. me.fireEvent('afterinsertimage', opt)
  10434. }
  10435. };
  10436. // js/editor/_src/plugins/justify.js
  10437. /**
  10438. * 段落格式
  10439. * @file
  10440. * @since 1.2.6.1
  10441. */
  10442. /**
  10443. * 段落对齐方式
  10444. * @command justify
  10445. * @method execCommand
  10446. * @param { String } cmd 命令字符串
  10447. * @param { String } align 对齐方式:left => 居左,right => 居右,center => 居中,justify => 两端对齐
  10448. * @example
  10449. * ```javascript
  10450. * editor.execCommand( 'justify', 'center' );
  10451. * ```
  10452. */
  10453. /**
  10454. * 如果选区所在位置是段落区域,返回当前段落对齐方式
  10455. * @command justify
  10456. * @method queryCommandValue
  10457. * @param { String } cmd 命令字符串
  10458. * @return { String } 返回段落对齐方式
  10459. * @example
  10460. * ```javascript
  10461. * editor.queryCommandValue( 'justify' );
  10462. * ```
  10463. */
  10464. UE.plugins['justify']=function(){
  10465. var me=this,
  10466. block = domUtils.isBlockElm,
  10467. defaultValue = {
  10468. left:1,
  10469. right:1,
  10470. center:1,
  10471. justify:1
  10472. },
  10473. doJustify = function (range, style) {
  10474. var bookmark = range.createBookmark(),
  10475. filterFn = function (node) {
  10476. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' && !domUtils.isBookmarkNode(node) : !domUtils.isWhitespace(node);
  10477. };
  10478. range.enlarge(true);
  10479. var bookmark2 = range.createBookmark(),
  10480. current = domUtils.getNextDomNode(bookmark2.start, false, filterFn),
  10481. tmpRange = range.cloneRange(),
  10482. tmpNode;
  10483. while (current && !(domUtils.getPosition(current, bookmark2.end) & domUtils.POSITION_FOLLOWING)) {
  10484. if (current.nodeType == 3 || !block(current)) {
  10485. tmpRange.setStartBefore(current);
  10486. while (current && current !== bookmark2.end && !block(current)) {
  10487. tmpNode = current;
  10488. current = domUtils.getNextDomNode(current, false, null, function (node) {
  10489. return !block(node);
  10490. });
  10491. }
  10492. tmpRange.setEndAfter(tmpNode);
  10493. var common = tmpRange.getCommonAncestor();
  10494. if (!domUtils.isBody(common) && block(common)) {
  10495. domUtils.setStyles(common, utils.isString(style) ? {'text-align':style} : style);
  10496. current = common;
  10497. } else {
  10498. var p = range.document.createElement('p');
  10499. domUtils.setStyles(p, utils.isString(style) ? {'text-align':style} : style);
  10500. var frag = tmpRange.extractContents();
  10501. p.appendChild(frag);
  10502. tmpRange.insertNode(p);
  10503. current = p;
  10504. }
  10505. current = domUtils.getNextDomNode(current, false, filterFn);
  10506. } else {
  10507. current = domUtils.getNextDomNode(current, true, filterFn);
  10508. }
  10509. }
  10510. return range.moveToBookmark(bookmark2).moveToBookmark(bookmark);
  10511. };
  10512. UE.commands['justify'] = {
  10513. execCommand:function (cmdName, align) {
  10514. var range = this.selection.getRange(),
  10515. txt;
  10516. //闭合时单独处理
  10517. if (range.collapsed) {
  10518. txt = this.document.createTextNode('p');
  10519. range.insertNode(txt);
  10520. }
  10521. doJustify(range, align);
  10522. if (txt) {
  10523. range.setStartBefore(txt).collapse(true);
  10524. domUtils.remove(txt);
  10525. }
  10526. range.select();
  10527. return true;
  10528. },
  10529. queryCommandValue:function () {
  10530. var startNode = this.selection.getStart(),
  10531. value = domUtils.getComputedStyle(startNode, 'text-align');
  10532. return defaultValue[value] ? value : 'left';
  10533. },
  10534. queryCommandState:function () {
  10535. var start = this.selection.getStart(),
  10536. cell = start && domUtils.findParentByTagName(start, ["td", "th","caption"], true);
  10537. return cell? -1:0;
  10538. }
  10539. };
  10540. };
  10541. // js/editor/_src/plugins/font.js
  10542. /**
  10543. * 字体颜色,背景色,字号,字体,下划线,删除线
  10544. * @file
  10545. * @since 1.2.6.1
  10546. */
  10547. /**
  10548. * 字体颜色
  10549. * @command forecolor
  10550. * @method execCommand
  10551. * @param { String } cmd 命令字符串
  10552. * @param { String } value 色值(必须十六进制)
  10553. * @example
  10554. * ```javascript
  10555. * editor.execCommand( 'forecolor', '#000' );
  10556. * ```
  10557. */
  10558. /**
  10559. * 返回选区字体颜色
  10560. * @command forecolor
  10561. * @method queryCommandValue
  10562. * @param { String } cmd 命令字符串
  10563. * @return { String } 返回字体颜色
  10564. * @example
  10565. * ```javascript
  10566. * editor.queryCommandValue( 'forecolor' );
  10567. * ```
  10568. */
  10569. /**
  10570. * 字体背景颜色
  10571. * @command backcolor
  10572. * @method execCommand
  10573. * @param { String } cmd 命令字符串
  10574. * @param { String } value 色值(必须十六进制)
  10575. * @example
  10576. * ```javascript
  10577. * editor.execCommand( 'backcolor', '#000' );
  10578. * ```
  10579. */
  10580. /**
  10581. * 返回选区字体颜色
  10582. * @command backcolor
  10583. * @method queryCommandValue
  10584. * @param { String } cmd 命令字符串
  10585. * @return { String } 返回字体背景颜色
  10586. * @example
  10587. * ```javascript
  10588. * editor.queryCommandValue( 'backcolor' );
  10589. * ```
  10590. */
  10591. /**
  10592. * 字体大小
  10593. * @command fontsize
  10594. * @method execCommand
  10595. * @param { String } cmd 命令字符串
  10596. * @param { String } value 字体大小
  10597. * @example
  10598. * ```javascript
  10599. * editor.execCommand( 'fontsize', '14px' );
  10600. * ```
  10601. */
  10602. /**
  10603. * 返回选区字体大小
  10604. * @command fontsize
  10605. * @method queryCommandValue
  10606. * @param { String } cmd 命令字符串
  10607. * @return { String } 返回字体大小
  10608. * @example
  10609. * ```javascript
  10610. * editor.queryCommandValue( 'fontsize' );
  10611. * ```
  10612. */
  10613. /**
  10614. * 字体样式
  10615. * @command fontfamily
  10616. * @method execCommand
  10617. * @param { String } cmd 命令字符串
  10618. * @param { String } value 字体样式
  10619. * @example
  10620. * ```javascript
  10621. * editor.execCommand( 'fontfamily', '微软雅黑' );
  10622. * ```
  10623. */
  10624. /**
  10625. * 返回选区字体样式
  10626. * @command fontfamily
  10627. * @method queryCommandValue
  10628. * @param { String } cmd 命令字符串
  10629. * @return { String } 返回字体样式
  10630. * @example
  10631. * ```javascript
  10632. * editor.queryCommandValue( 'fontfamily' );
  10633. * ```
  10634. */
  10635. /**
  10636. * 字体下划线,与删除线互斥
  10637. * @command underline
  10638. * @method execCommand
  10639. * @param { String } cmd 命令字符串
  10640. * @example
  10641. * ```javascript
  10642. * editor.execCommand( 'underline' );
  10643. * ```
  10644. */
  10645. /**
  10646. * 字体删除线,与下划线互斥
  10647. * @command strikethrough
  10648. * @method execCommand
  10649. * @param { String } cmd 命令字符串
  10650. * @example
  10651. * ```javascript
  10652. * editor.execCommand( 'strikethrough' );
  10653. * ```
  10654. */
  10655. /**
  10656. * 字体边框
  10657. * @command fontborder
  10658. * @method execCommand
  10659. * @param { String } cmd 命令字符串
  10660. * @example
  10661. * ```javascript
  10662. * editor.execCommand( 'fontborder' );
  10663. * ```
  10664. */
  10665. UE.plugins['font'] = function () {
  10666. var me = this,
  10667. fonts = {
  10668. 'forecolor': 'color',
  10669. 'backcolor': 'background-color',
  10670. 'fontsize': 'font-size',
  10671. 'fontfamily': 'font-family',
  10672. 'underline': 'text-decoration',
  10673. 'strikethrough': 'text-decoration',
  10674. 'fontborder': 'border'
  10675. },
  10676. needCmd = {'underline': 1, 'strikethrough': 1, 'fontborder': 1},
  10677. needSetChild = {
  10678. 'forecolor': 'color',
  10679. 'backcolor': 'background-color',
  10680. 'fontsize': 'font-size',
  10681. 'fontfamily': 'font-family'
  10682. };
  10683. me.setOpt({
  10684. 'fontfamily': [
  10685. { name: 'songti', val: '宋体,SimSun'},
  10686. { name: 'yahei', val: '微软雅黑,Microsoft YaHei'},
  10687. { name: 'kaiti', val: '楷体,楷体_GB2312, SimKai'},
  10688. { name: 'heiti', val: '黑体, SimHei'},
  10689. { name: 'lishu', val: '隶书, SimLi'},
  10690. { name: 'andaleMono', val: 'andale mono'},
  10691. { name: 'arial', val: 'arial, helvetica,sans-serif'},
  10692. { name: 'arialBlack', val: 'arial black,avant garde'},
  10693. { name: 'comicSansMs', val: 'comic sans ms'},
  10694. { name: 'impact', val: 'impact,chicago'},
  10695. { name: 'timesNewRoman', val: 'times new roman'}
  10696. ],
  10697. 'fontsize': [10, 11, 12, 14, 16, 18, 20, 24, 36]
  10698. });
  10699. function mergeWithParent(node){
  10700. var parent;
  10701. while(parent = node.parentNode){
  10702. if(parent.tagName == 'SPAN' && domUtils.getChildCount(parent,function(child){
  10703. return !domUtils.isBookmarkNode(child) && !domUtils.isBr(child)
  10704. }) == 1) {
  10705. parent.style.cssText += node.style.cssText;
  10706. domUtils.remove(node,true);
  10707. node = parent;
  10708. }else{
  10709. break;
  10710. }
  10711. }
  10712. }
  10713. function mergeChild(rng,cmdName,value){
  10714. if(needSetChild[cmdName]){
  10715. rng.adjustmentBoundary();
  10716. if(!rng.collapsed && rng.startContainer.nodeType == 1){
  10717. var start = rng.startContainer.childNodes[rng.startOffset];
  10718. if(start && domUtils.isTagNode(start,'span')){
  10719. var bk = rng.createBookmark();
  10720. utils.each(domUtils.getElementsByTagName(start, 'span'), function (span) {
  10721. if (!span.parentNode || domUtils.isBookmarkNode(span))return;
  10722. if(cmdName == 'backcolor' && domUtils.getComputedStyle(span,'background-color').toLowerCase() === value){
  10723. return;
  10724. }
  10725. domUtils.removeStyle(span,needSetChild[cmdName]);
  10726. if(span.style.cssText.replace(/^\s+$/,'').length == 0){
  10727. domUtils.remove(span,true)
  10728. }
  10729. });
  10730. rng.moveToBookmark(bk)
  10731. }
  10732. }
  10733. }
  10734. }
  10735. function mergesibling(rng,cmdName,value) {
  10736. var collapsed = rng.collapsed,
  10737. bk = rng.createBookmark(), common;
  10738. if (collapsed) {
  10739. common = bk.start.parentNode;
  10740. while (dtd.$inline[common.tagName]) {
  10741. common = common.parentNode;
  10742. }
  10743. } else {
  10744. common = domUtils.getCommonAncestor(bk.start, bk.end);
  10745. }
  10746. utils.each(domUtils.getElementsByTagName(common, 'span'), function (span) {
  10747. if (!span.parentNode || domUtils.isBookmarkNode(span))return;
  10748. if (/\s*border\s*:\s*none;?\s*/i.test(span.style.cssText)) {
  10749. if(/^\s*border\s*:\s*none;?\s*$/.test(span.style.cssText)){
  10750. domUtils.remove(span, true);
  10751. }else{
  10752. domUtils.removeStyle(span,'border');
  10753. }
  10754. return
  10755. }
  10756. if (/border/i.test(span.style.cssText) && span.parentNode.tagName == 'SPAN' && /border/i.test(span.parentNode.style.cssText)) {
  10757. span.style.cssText = span.style.cssText.replace(/border[^:]*:[^;]+;?/gi, '');
  10758. }
  10759. if(!(cmdName=='fontborder' && value=='none')){
  10760. var next = span.nextSibling;
  10761. while (next && next.nodeType == 1 && next.tagName == 'SPAN' ) {
  10762. if(domUtils.isBookmarkNode(next) && cmdName == 'fontborder') {
  10763. span.appendChild(next);
  10764. next = span.nextSibling;
  10765. continue;
  10766. }
  10767. if (next.style.cssText == span.style.cssText) {
  10768. domUtils.moveChild(next, span);
  10769. domUtils.remove(next);
  10770. }
  10771. if (span.nextSibling === next)
  10772. break;
  10773. next = span.nextSibling;
  10774. }
  10775. }
  10776. mergeWithParent(span);
  10777. if(browser.ie && browser.version > 8 ){
  10778. //拷贝父亲们的特别的属性,这里只做背景颜色的处理
  10779. var parent = domUtils.findParent(span,function(n){return n.tagName == 'SPAN' && /background-color/.test(n.style.cssText)});
  10780. if(parent && !/background-color/.test(span.style.cssText)){
  10781. span.style.backgroundColor = parent.style.backgroundColor;
  10782. }
  10783. }
  10784. });
  10785. rng.moveToBookmark(bk);
  10786. mergeChild(rng,cmdName,value)
  10787. }
  10788. me.addInputRule(function (root) {
  10789. utils.each(root.getNodesByTagName('u s del font strike'), function (node) {
  10790. if (node.tagName == 'font') {
  10791. var cssStyle = [];
  10792. for (var p in node.attrs) {
  10793. switch (p) {
  10794. case 'size':
  10795. cssStyle.push('font-size:' +
  10796. ({
  10797. '1':'10',
  10798. '2':'12',
  10799. '3':'16',
  10800. '4':'18',
  10801. '5':'24',
  10802. '6':'32',
  10803. '7':'48'
  10804. }[node.attrs[p]] || node.attrs[p]) + 'px');
  10805. break;
  10806. case 'color':
  10807. cssStyle.push('color:' + node.attrs[p]);
  10808. break;
  10809. case 'face':
  10810. cssStyle.push('font-family:' + node.attrs[p]);
  10811. break;
  10812. case 'style':
  10813. cssStyle.push(node.attrs[p]);
  10814. }
  10815. }
  10816. node.attrs = {
  10817. 'style': cssStyle.join(';')
  10818. };
  10819. } else {
  10820. var val = node.tagName == 'u' ? 'underline' : 'line-through';
  10821. node.attrs = {
  10822. 'style': (node.getAttr('style') || '') + 'text-decoration:' + val + ';'
  10823. }
  10824. }
  10825. node.tagName = 'span';
  10826. });
  10827. // utils.each(root.getNodesByTagName('span'), function (node) {
  10828. // var val;
  10829. // if(val = node.getAttr('class')){
  10830. // if(/fontstrikethrough/.test(val)){
  10831. // node.setStyle('text-decoration','line-through');
  10832. // if(node.attrs['class']){
  10833. // node.attrs['class'] = node.attrs['class'].replace(/fontstrikethrough/,'');
  10834. // }else{
  10835. // node.setAttr('class')
  10836. // }
  10837. // }
  10838. // if(/fontborder/.test(val)){
  10839. // node.setStyle('border','1px solid #000');
  10840. // if(node.attrs['class']){
  10841. // node.attrs['class'] = node.attrs['class'].replace(/fontborder/,'');
  10842. // }else{
  10843. // node.setAttr('class')
  10844. // }
  10845. // }
  10846. // }
  10847. // });
  10848. });
  10849. // me.addOutputRule(function(root){
  10850. // utils.each(root.getNodesByTagName('span'), function (node) {
  10851. // var val;
  10852. // if(val = node.getStyle('text-decoration')){
  10853. // if(/line-through/.test(val)){
  10854. // if(node.attrs['class']){
  10855. // node.attrs['class'] += ' fontstrikethrough';
  10856. // }else{
  10857. // node.setAttr('class','fontstrikethrough')
  10858. // }
  10859. // }
  10860. //
  10861. // node.setStyle('text-decoration')
  10862. // }
  10863. // if(val = node.getStyle('border')){
  10864. // if(/1px/.test(val) && /solid/.test(val)){
  10865. // if(node.attrs['class']){
  10866. // node.attrs['class'] += ' fontborder';
  10867. //
  10868. // }else{
  10869. // node.setAttr('class','fontborder')
  10870. // }
  10871. // }
  10872. // node.setStyle('border')
  10873. //
  10874. // }
  10875. // });
  10876. // });
  10877. for (var p in fonts) {
  10878. (function (cmd, style) {
  10879. UE.commands[cmd] = {
  10880. execCommand: function (cmdName, value) {
  10881. value = value || (this.queryCommandState(cmdName) ? 'none' : cmdName == 'underline' ? 'underline' :
  10882. cmdName == 'fontborder' ? '1px solid #000' :
  10883. 'line-through');
  10884. var me = this,
  10885. range = this.selection.getRange(),
  10886. text;
  10887. if (value == 'default') {
  10888. if (range.collapsed) {
  10889. text = me.document.createTextNode('font');
  10890. range.insertNode(text).select();
  10891. }
  10892. me.execCommand('removeFormat', 'span,a', style);
  10893. if (text) {
  10894. range.setStartBefore(text).collapse(true);
  10895. domUtils.remove(text);
  10896. }
  10897. mergesibling(range,cmdName,value);
  10898. range.select()
  10899. } else {
  10900. if (!range.collapsed) {
  10901. if (needCmd[cmd] && me.queryCommandValue(cmd)) {
  10902. me.execCommand('removeFormat', 'span,a', style);
  10903. }
  10904. range = me.selection.getRange();
  10905. range.applyInlineStyle('span', {'style': style + ':' + value});
  10906. mergesibling(range, cmdName,value);
  10907. range.select();
  10908. } else {
  10909. var span = domUtils.findParentByTagName(range.startContainer, 'span', true);
  10910. text = me.document.createTextNode('font');
  10911. if (span && !span.children.length && !span[browser.ie ? 'innerText' : 'textContent'].replace(fillCharReg, '').length) {
  10912. //for ie hack when enter
  10913. range.insertNode(text);
  10914. if (needCmd[cmd]) {
  10915. range.selectNode(text).select();
  10916. me.execCommand('removeFormat', 'span,a', style, null);
  10917. span = domUtils.findParentByTagName(text, 'span', true);
  10918. range.setStartBefore(text);
  10919. }
  10920. span && (span.style.cssText += ';' + style + ':' + value);
  10921. range.collapse(true).select();
  10922. } else {
  10923. range.insertNode(text);
  10924. range.selectNode(text).select();
  10925. span = range.document.createElement('span');
  10926. if (needCmd[cmd]) {
  10927. //a标签内的不处理跳过
  10928. if (domUtils.findParentByTagName(text, 'a', true)) {
  10929. range.setStartBefore(text).setCursor();
  10930. domUtils.remove(text);
  10931. return;
  10932. }
  10933. me.execCommand('removeFormat', 'span,a', style);
  10934. }
  10935. span.style.cssText = style + ':' + value;
  10936. text.parentNode.insertBefore(span, text);
  10937. //修复,span套span 但样式不继承的问题
  10938. if (!browser.ie || browser.ie && browser.version == 9) {
  10939. var spanParent = span.parentNode;
  10940. while (!domUtils.isBlockElm(spanParent)) {
  10941. if (spanParent.tagName == 'SPAN') {
  10942. //opera合并style不会加入";"
  10943. span.style.cssText = spanParent.style.cssText + ";" + span.style.cssText;
  10944. }
  10945. spanParent = spanParent.parentNode;
  10946. }
  10947. }
  10948. if (opera) {
  10949. setTimeout(function () {
  10950. range.setStart(span, 0).collapse(true);
  10951. mergesibling(range, cmdName,value);
  10952. range.select();
  10953. });
  10954. } else {
  10955. range.setStart(span, 0).collapse(true);
  10956. mergesibling(range,cmdName,value);
  10957. range.select();
  10958. }
  10959. //trace:981
  10960. //domUtils.mergeToParent(span)
  10961. }
  10962. domUtils.remove(text);
  10963. }
  10964. }
  10965. return true;
  10966. },
  10967. queryCommandValue: function (cmdName) {
  10968. var startNode = this.selection.getStart();
  10969. //trace:946
  10970. if (cmdName == 'underline' || cmdName == 'strikethrough') {
  10971. var tmpNode = startNode, value;
  10972. while (tmpNode && !domUtils.isBlockElm(tmpNode) && !domUtils.isBody(tmpNode)) {
  10973. if (tmpNode.nodeType == 1) {
  10974. value = domUtils.getComputedStyle(tmpNode, style);
  10975. if (value != 'none') {
  10976. return value;
  10977. }
  10978. }
  10979. tmpNode = tmpNode.parentNode;
  10980. }
  10981. return 'none';
  10982. }
  10983. if (cmdName == 'fontborder') {
  10984. var tmp = startNode, val;
  10985. while (tmp && dtd.$inline[tmp.tagName]) {
  10986. if (val = domUtils.getComputedStyle(tmp, 'border')) {
  10987. if (/1px/.test(val) && /solid/.test(val)) {
  10988. return val;
  10989. }
  10990. }
  10991. tmp = tmp.parentNode;
  10992. }
  10993. return ''
  10994. }
  10995. if( cmdName == 'FontSize' ) {
  10996. var styleVal = domUtils.getComputedStyle(startNode, style),
  10997. tmp = /^([\d\.]+)(\w+)$/.exec( styleVal );
  10998. if( tmp ) {
  10999. return Math.floor( tmp[1] ) + tmp[2];
  11000. }
  11001. return styleVal;
  11002. }
  11003. return domUtils.getComputedStyle(startNode, style);
  11004. },
  11005. queryCommandState: function (cmdName) {
  11006. if (!needCmd[cmdName])
  11007. return 0;
  11008. var val = this.queryCommandValue(cmdName);
  11009. if (cmdName == 'fontborder') {
  11010. return /1px/.test(val) && /solid/.test(val)
  11011. } else {
  11012. return cmdName == 'underline' ? /underline/.test(val) : /line\-through/.test(val);
  11013. }
  11014. }
  11015. };
  11016. })(p, fonts[p]);
  11017. }
  11018. };
  11019. // js/editor/_src/plugins/link.js
  11020. /**
  11021. * 超链接
  11022. * @file
  11023. * @since 1.2.6.1
  11024. */
  11025. /**
  11026. * 插入超链接
  11027. * @command link
  11028. * @method execCommand
  11029. * @param { String } cmd 命令字符串
  11030. * @param { Object } options 设置自定义属性,例如:url、title、target
  11031. * @example
  11032. * ```javascript
  11033. * editor.execCommand( 'link', '{
  11034. * url:'ueditor.baidu.com',
  11035. * title:'ueditor',
  11036. * target:'_blank'
  11037. * }' );
  11038. * ```
  11039. */
  11040. /**
  11041. * 返回当前选中的第一个超链接节点
  11042. * @command link
  11043. * @method queryCommandValue
  11044. * @param { String } cmd 命令字符串
  11045. * @return { Element } 超链接节点
  11046. * @example
  11047. * ```javascript
  11048. * editor.queryCommandValue( 'link' );
  11049. * ```
  11050. */
  11051. /**
  11052. * 取消超链接
  11053. * @command unlink
  11054. * @method execCommand
  11055. * @param { String } cmd 命令字符串
  11056. * @example
  11057. * ```javascript
  11058. * editor.execCommand( 'unlink');
  11059. * ```
  11060. */
  11061. UE.plugins['link'] = function(){
  11062. function optimize( range ) {
  11063. var start = range.startContainer,end = range.endContainer;
  11064. if ( start = domUtils.findParentByTagName( start, 'a', true ) ) {
  11065. range.setStartBefore( start );
  11066. }
  11067. if ( end = domUtils.findParentByTagName( end, 'a', true ) ) {
  11068. range.setEndAfter( end );
  11069. }
  11070. }
  11071. UE.commands['unlink'] = {
  11072. execCommand : function() {
  11073. var range = this.selection.getRange(),
  11074. bookmark;
  11075. if(range.collapsed && !domUtils.findParentByTagName( range.startContainer, 'a', true )){
  11076. return;
  11077. }
  11078. bookmark = range.createBookmark();
  11079. optimize( range );
  11080. range.removeInlineStyle( 'a' ).moveToBookmark( bookmark ).select();
  11081. },
  11082. queryCommandState : function(){
  11083. return !this.highlight && this.queryCommandValue('link') ? 0 : -1;
  11084. }
  11085. };
  11086. function doLink(range,opt,me){
  11087. var rngClone = range.cloneRange(),
  11088. link = me.queryCommandValue('link');
  11089. optimize( range = range.adjustmentBoundary() );
  11090. var start = range.startContainer;
  11091. if(start.nodeType == 1 && link){
  11092. start = start.childNodes[range.startOffset];
  11093. if(start && start.nodeType == 1 && start.tagName == 'A' && /^(?:https?|ftp|file)\s*:\s*\/\//.test(start[browser.ie?'innerText':'textContent'])){
  11094. start[browser.ie ? 'innerText' : 'textContent'] = utils.html(opt.textValue||opt.href);
  11095. }
  11096. }
  11097. if( !rngClone.collapsed || link){
  11098. range.removeInlineStyle( 'a' );
  11099. rngClone = range.cloneRange();
  11100. }
  11101. if ( rngClone.collapsed ) {
  11102. var a = range.document.createElement( 'a'),
  11103. text = '';
  11104. if(opt.textValue){
  11105. text = utils.html(opt.textValue);
  11106. delete opt.textValue;
  11107. }else{
  11108. text = utils.html(opt.href);
  11109. }
  11110. domUtils.setAttributes( a, opt );
  11111. start = domUtils.findParentByTagName( rngClone.startContainer, 'a', true );
  11112. if(start && domUtils.isInNodeEndBoundary(rngClone,start)){
  11113. range.setStartAfter(start).collapse(true);
  11114. }
  11115. a[browser.ie ? 'innerText' : 'textContent'] = text;
  11116. range.insertNode(a).selectNode( a );
  11117. } else {
  11118. range.applyInlineStyle( 'a', opt );
  11119. }
  11120. }
  11121. UE.commands['link'] = {
  11122. execCommand : function( cmdName, opt ) {
  11123. var range;
  11124. opt._href && (opt._href = utils.unhtml(opt._href,/[<">]/g));
  11125. opt.href && (opt.href = utils.unhtml(opt.href,/[<">]/g));
  11126. opt.textValue && (opt.textValue = utils.unhtml(opt.textValue,/[<">]/g));
  11127. doLink(range=this.selection.getRange(),opt,this);
  11128. //闭合都不加占位符,如果加了会在a后边多个占位符节点,导致a是图片背景组成的列表,出现空白问题
  11129. range.collapse().select(true);
  11130. },
  11131. queryCommandValue : function() {
  11132. var range = this.selection.getRange(),
  11133. node;
  11134. if ( range.collapsed ) {
  11135. // node = this.selection.getStart();
  11136. //在ie下getstart()取值偏上了
  11137. node = range.startContainer;
  11138. node = node.nodeType == 1 ? node : node.parentNode;
  11139. if ( node && (node = domUtils.findParentByTagName( node, 'a', true )) && ! domUtils.isInNodeEndBoundary(range,node)) {
  11140. return node;
  11141. }
  11142. } else {
  11143. //trace:1111 如果是<p><a>xx</a></p> startContainer是p就会找不到a
  11144. range.shrinkBoundary();
  11145. var start = range.startContainer.nodeType == 3 || !range.startContainer.childNodes[range.startOffset] ? range.startContainer : range.startContainer.childNodes[range.startOffset],
  11146. end = range.endContainer.nodeType == 3 || range.endOffset == 0 ? range.endContainer : range.endContainer.childNodes[range.endOffset-1],
  11147. common = range.getCommonAncestor();
  11148. node = domUtils.findParentByTagName( common, 'a', true );
  11149. if ( !node && common.nodeType == 1){
  11150. var as = common.getElementsByTagName( 'a' ),
  11151. ps,pe;
  11152. for ( var i = 0,ci; ci = as[i++]; ) {
  11153. ps = domUtils.getPosition( ci, start ),pe = domUtils.getPosition( ci,end);
  11154. if ( (ps & domUtils.POSITION_FOLLOWING || ps & domUtils.POSITION_CONTAINS)
  11155. &&
  11156. (pe & domUtils.POSITION_PRECEDING || pe & domUtils.POSITION_CONTAINS)
  11157. ) {
  11158. node = ci;
  11159. break;
  11160. }
  11161. }
  11162. }
  11163. return node;
  11164. }
  11165. },
  11166. queryCommandState : function() {
  11167. //判断如果是视频的话连接不可用
  11168. //fix 853
  11169. var img = this.selection.getRange().getClosedNode(),
  11170. flag = img && (img.className == "edui-faked-video" || img.className.indexOf("edui-upload-video")!=-1);
  11171. return flag ? -1 : 0;
  11172. }
  11173. };
  11174. };
  11175. // js/editor/_src/plugins/iframe.js
  11176. ///import core
  11177. ///import plugins\inserthtml.js
  11178. ///commands 插入框架
  11179. ///commandsName InsertFrame
  11180. ///commandsTitle 插入Iframe
  11181. ///commandsDialog dialogs\insertframe
  11182. UE.plugins['insertframe'] = function() {
  11183. var me =this;
  11184. function deleteIframe(){
  11185. me._iframe && delete me._iframe;
  11186. }
  11187. me.addListener("selectionchange",function(){
  11188. deleteIframe();
  11189. });
  11190. };
  11191. // js/editor/_src/plugins/scrawl.js
  11192. ///import core
  11193. ///commands 涂鸦
  11194. ///commandsName Scrawl
  11195. ///commandsTitle 涂鸦
  11196. ///commandsDialog dialogs\scrawl
  11197. UE.commands['scrawl'] = {
  11198. queryCommandState : function(){
  11199. return ( browser.ie && browser.version <= 8 ) ? -1 :0;
  11200. }
  11201. };
  11202. // js/editor/_src/plugins/removeformat.js
  11203. /**
  11204. * 清除格式
  11205. * @file
  11206. * @since 1.2.6.1
  11207. */
  11208. /**
  11209. * 清除文字样式
  11210. * @command removeformat
  11211. * @method execCommand
  11212. * @param { String } cmd 命令字符串
  11213. * @param {String} tags 以逗号隔开的标签。如:strong
  11214. * @param {String} style 样式如:color
  11215. * @param {String} attrs 属性如:width
  11216. * @example
  11217. * ```javascript
  11218. * editor.execCommand( 'removeformat', 'strong','color','width' );
  11219. * ```
  11220. */
  11221. UE.plugins['removeformat'] = function(){
  11222. var me = this;
  11223. me.setOpt({
  11224. 'removeFormatTags': 'b,big,code,del,dfn,em,font,i,ins,kbd,q,samp,small,span,strike,strong,sub,sup,tt,u,var',
  11225. 'removeFormatAttributes':'class,style,lang,width,height,align,hspace,valign'
  11226. });
  11227. me.commands['removeformat'] = {
  11228. execCommand : function( cmdName, tags, style, attrs,notIncludeA ) {
  11229. var tagReg = new RegExp( '^(?:' + (tags || this.options.removeFormatTags).replace( /,/g, '|' ) + ')$', 'i' ) ,
  11230. removeFormatAttributes = style ? [] : (attrs || this.options.removeFormatAttributes).split( ',' ),
  11231. range = new dom.Range( this.document ),
  11232. bookmark,node,parent,
  11233. filter = function( node ) {
  11234. return node.nodeType == 1;
  11235. };
  11236. function isRedundantSpan (node) {
  11237. if (node.nodeType == 3 || node.tagName.toLowerCase() != 'span'){
  11238. return 0;
  11239. }
  11240. if (browser.ie) {
  11241. //ie 下判断实效,所以只能简单用style来判断
  11242. //return node.style.cssText == '' ? 1 : 0;
  11243. var attrs = node.attributes;
  11244. if ( attrs.length ) {
  11245. for ( var i = 0,l = attrs.length; i<l; i++ ) {
  11246. if ( attrs[i].specified ) {
  11247. return 0;
  11248. }
  11249. }
  11250. return 1;
  11251. }
  11252. }
  11253. return !node.attributes.length;
  11254. }
  11255. function doRemove( range ) {
  11256. var bookmark1 = range.createBookmark();
  11257. if ( range.collapsed ) {
  11258. range.enlarge( true );
  11259. }
  11260. //不能把a标签切了
  11261. if(!notIncludeA){
  11262. var aNode = domUtils.findParentByTagName(range.startContainer,'a',true);
  11263. if(aNode){
  11264. range.setStartBefore(aNode);
  11265. }
  11266. aNode = domUtils.findParentByTagName(range.endContainer,'a',true);
  11267. if(aNode){
  11268. range.setEndAfter(aNode);
  11269. }
  11270. }
  11271. bookmark = range.createBookmark();
  11272. node = bookmark.start;
  11273. //切开始
  11274. while ( (parent = node.parentNode) && !domUtils.isBlockElm( parent ) ) {
  11275. domUtils.breakParent( node, parent );
  11276. domUtils.clearEmptySibling( node );
  11277. }
  11278. if ( bookmark.end ) {
  11279. //切结束
  11280. node = bookmark.end;
  11281. while ( (parent = node.parentNode) && !domUtils.isBlockElm( parent ) ) {
  11282. domUtils.breakParent( node, parent );
  11283. domUtils.clearEmptySibling( node );
  11284. }
  11285. //开始去除样式
  11286. var current = domUtils.getNextDomNode( bookmark.start, false, filter ),
  11287. next;
  11288. while ( current ) {
  11289. if ( current == bookmark.end ) {
  11290. break;
  11291. }
  11292. next = domUtils.getNextDomNode( current, true, filter );
  11293. if ( !dtd.$empty[current.tagName.toLowerCase()] && !domUtils.isBookmarkNode( current ) ) {
  11294. if ( tagReg.test( current.tagName ) ) {
  11295. if ( style ) {
  11296. domUtils.removeStyle( current, style );
  11297. if ( isRedundantSpan( current ) && style != 'text-decoration'){
  11298. domUtils.remove( current, true );
  11299. }
  11300. } else {
  11301. domUtils.remove( current, true );
  11302. }
  11303. } else {
  11304. //trace:939 不能把list上的样式去掉
  11305. if(!dtd.$tableContent[current.tagName] && !dtd.$list[current.tagName]){
  11306. domUtils.removeAttributes( current, removeFormatAttributes );
  11307. if ( isRedundantSpan( current ) ){
  11308. domUtils.remove( current, true );
  11309. }
  11310. }
  11311. }
  11312. }
  11313. current = next;
  11314. }
  11315. }
  11316. //trace:1035
  11317. //trace:1096 不能把td上的样式去掉,比如边框
  11318. var pN = bookmark.start.parentNode;
  11319. if(domUtils.isBlockElm(pN) && !dtd.$tableContent[pN.tagName] && !dtd.$list[pN.tagName]){
  11320. domUtils.removeAttributes( pN,removeFormatAttributes );
  11321. }
  11322. pN = bookmark.end.parentNode;
  11323. if(bookmark.end && domUtils.isBlockElm(pN) && !dtd.$tableContent[pN.tagName]&& !dtd.$list[pN.tagName]){
  11324. domUtils.removeAttributes( pN,removeFormatAttributes );
  11325. }
  11326. range.moveToBookmark( bookmark ).moveToBookmark(bookmark1);
  11327. //清除冗余的代码 <b><bookmark></b>
  11328. var node = range.startContainer,
  11329. tmp,
  11330. collapsed = range.collapsed;
  11331. while(node.nodeType == 1 && domUtils.isEmptyNode(node) && dtd.$removeEmpty[node.tagName]){
  11332. tmp = node.parentNode;
  11333. range.setStartBefore(node);
  11334. //trace:937
  11335. //更新结束边界
  11336. if(range.startContainer === range.endContainer){
  11337. range.endOffset--;
  11338. }
  11339. domUtils.remove(node);
  11340. node = tmp;
  11341. }
  11342. if(!collapsed){
  11343. node = range.endContainer;
  11344. while(node.nodeType == 1 && domUtils.isEmptyNode(node) && dtd.$removeEmpty[node.tagName]){
  11345. tmp = node.parentNode;
  11346. range.setEndBefore(node);
  11347. domUtils.remove(node);
  11348. node = tmp;
  11349. }
  11350. }
  11351. }
  11352. range = this.selection.getRange();
  11353. doRemove( range );
  11354. range.select();
  11355. }
  11356. };
  11357. };
  11358. // js/editor/_src/plugins/blockquote.js
  11359. /**
  11360. * 添加引用
  11361. * @file
  11362. * @since 1.2.6.1
  11363. */
  11364. /**
  11365. * 添加引用
  11366. * @command blockquote
  11367. * @method execCommand
  11368. * @param { String } cmd 命令字符串
  11369. * @example
  11370. * ```javascript
  11371. * editor.execCommand( 'blockquote' );
  11372. * ```
  11373. */
  11374. /**
  11375. * 添加引用
  11376. * @command blockquote
  11377. * @method execCommand
  11378. * @param { String } cmd 命令字符串
  11379. * @param { Object } attrs 节点属性
  11380. * @example
  11381. * ```javascript
  11382. * editor.execCommand( 'blockquote',{
  11383. * style: "color: red;"
  11384. * } );
  11385. * ```
  11386. */
  11387. UE.plugins['blockquote'] = function(){
  11388. var me = this;
  11389. function getObj(editor){
  11390. return domUtils.filterNodeList(editor.selection.getStartElementPath(),'blockquote');
  11391. }
  11392. me.commands['blockquote'] = {
  11393. execCommand : function( cmdName, attrs ) {
  11394. var range = this.selection.getRange(),
  11395. obj = getObj(this),
  11396. blockquote = dtd.blockquote,
  11397. bookmark = range.createBookmark();
  11398. if ( obj ) {
  11399. var start = range.startContainer,
  11400. startBlock = domUtils.isBlockElm(start) ? start : domUtils.findParent(start,function(node){return domUtils.isBlockElm(node)}),
  11401. end = range.endContainer,
  11402. endBlock = domUtils.isBlockElm(end) ? end : domUtils.findParent(end,function(node){return domUtils.isBlockElm(node)});
  11403. //处理一下li
  11404. startBlock = domUtils.findParentByTagName(startBlock,'li',true) || startBlock;
  11405. endBlock = domUtils.findParentByTagName(endBlock,'li',true) || endBlock;
  11406. if(startBlock.tagName == 'LI' || startBlock.tagName == 'TD' || startBlock === obj || domUtils.isBody(startBlock)){
  11407. domUtils.remove(obj,true);
  11408. }else{
  11409. domUtils.breakParent(startBlock,obj);
  11410. }
  11411. if(startBlock !== endBlock){
  11412. obj = domUtils.findParentByTagName(endBlock,'blockquote');
  11413. if(obj){
  11414. if(endBlock.tagName == 'LI' || endBlock.tagName == 'TD'|| domUtils.isBody(endBlock)){
  11415. obj.parentNode && domUtils.remove(obj,true);
  11416. }else{
  11417. domUtils.breakParent(endBlock,obj);
  11418. }
  11419. }
  11420. }
  11421. var blockquotes = domUtils.getElementsByTagName(this.document,'blockquote');
  11422. for(var i=0,bi;bi=blockquotes[i++];){
  11423. if(!bi.childNodes.length){
  11424. domUtils.remove(bi);
  11425. }else if(domUtils.getPosition(bi,startBlock)&domUtils.POSITION_FOLLOWING && domUtils.getPosition(bi,endBlock)&domUtils.POSITION_PRECEDING){
  11426. domUtils.remove(bi,true);
  11427. }
  11428. }
  11429. } else {
  11430. var tmpRange = range.cloneRange(),
  11431. node = tmpRange.startContainer.nodeType == 1 ? tmpRange.startContainer : tmpRange.startContainer.parentNode,
  11432. preNode = node,
  11433. doEnd = 1;
  11434. //调整开始
  11435. while ( 1 ) {
  11436. if ( domUtils.isBody(node) ) {
  11437. if ( preNode !== node ) {
  11438. if ( range.collapsed ) {
  11439. tmpRange.selectNode( preNode );
  11440. doEnd = 0;
  11441. } else {
  11442. tmpRange.setStartBefore( preNode );
  11443. }
  11444. }else{
  11445. tmpRange.setStart(node,0);
  11446. }
  11447. break;
  11448. }
  11449. if ( !blockquote[node.tagName] ) {
  11450. if ( range.collapsed ) {
  11451. tmpRange.selectNode( preNode );
  11452. } else{
  11453. tmpRange.setStartBefore( preNode);
  11454. }
  11455. break;
  11456. }
  11457. preNode = node;
  11458. node = node.parentNode;
  11459. }
  11460. //调整结束
  11461. if ( doEnd ) {
  11462. preNode = node = node = tmpRange.endContainer.nodeType == 1 ? tmpRange.endContainer : tmpRange.endContainer.parentNode;
  11463. while ( 1 ) {
  11464. if ( domUtils.isBody( node ) ) {
  11465. if ( preNode !== node ) {
  11466. tmpRange.setEndAfter( preNode );
  11467. } else {
  11468. tmpRange.setEnd( node, node.childNodes.length );
  11469. }
  11470. break;
  11471. }
  11472. if ( !blockquote[node.tagName] ) {
  11473. tmpRange.setEndAfter( preNode );
  11474. break;
  11475. }
  11476. preNode = node;
  11477. node = node.parentNode;
  11478. }
  11479. }
  11480. node = range.document.createElement( 'blockquote' );
  11481. domUtils.setAttributes( node, attrs );
  11482. node.appendChild( tmpRange.extractContents() );
  11483. tmpRange.insertNode( node );
  11484. //去除重复的
  11485. var childs = domUtils.getElementsByTagName(node,'blockquote');
  11486. for(var i=0,ci;ci=childs[i++];){
  11487. if(ci.parentNode){
  11488. domUtils.remove(ci,true);
  11489. }
  11490. }
  11491. }
  11492. range.moveToBookmark( bookmark ).select();
  11493. },
  11494. queryCommandState : function() {
  11495. return getObj(this) ? 1 : 0;
  11496. }
  11497. };
  11498. };
  11499. // js/editor/_src/plugins/convertcase.js
  11500. /**
  11501. * 大小写转换
  11502. * @file
  11503. * @since 1.2.6.1
  11504. */
  11505. /**
  11506. * 把选区内文本变大写,与“tolowercase”命令互斥
  11507. * @command touppercase
  11508. * @method execCommand
  11509. * @param { String } cmd 命令字符串
  11510. * @example
  11511. * ```javascript
  11512. * editor.execCommand( 'touppercase' );
  11513. * ```
  11514. */
  11515. /**
  11516. * 把选区内文本变小写,与“touppercase”命令互斥
  11517. * @command tolowercase
  11518. * @method execCommand
  11519. * @param { String } cmd 命令字符串
  11520. * @example
  11521. * ```javascript
  11522. * editor.execCommand( 'tolowercase' );
  11523. * ```
  11524. */
  11525. UE.commands['touppercase'] =
  11526. UE.commands['tolowercase'] = {
  11527. execCommand:function (cmd) {
  11528. var me = this;
  11529. var rng = me.selection.getRange();
  11530. if(rng.collapsed){
  11531. return rng;
  11532. }
  11533. var bk = rng.createBookmark(),
  11534. bkEnd = bk.end,
  11535. filterFn = function( node ) {
  11536. return !domUtils.isBr(node) && !domUtils.isWhitespace( node );
  11537. },
  11538. curNode = domUtils.getNextDomNode( bk.start, false, filterFn );
  11539. while ( curNode && (domUtils.getPosition( curNode, bkEnd ) & domUtils.POSITION_PRECEDING) ) {
  11540. if ( curNode.nodeType == 3 ) {
  11541. curNode.nodeValue = curNode.nodeValue[cmd == 'touppercase' ? 'toUpperCase' : 'toLowerCase']();
  11542. }
  11543. curNode = domUtils.getNextDomNode( curNode, true, filterFn );
  11544. if(curNode === bkEnd){
  11545. break;
  11546. }
  11547. }
  11548. rng.moveToBookmark(bk).select();
  11549. }
  11550. };
  11551. // js/editor/_src/plugins/indent.js
  11552. /**
  11553. * 首行缩进
  11554. * @file
  11555. * @since 1.2.6.1
  11556. */
  11557. /**
  11558. * 缩进
  11559. * @command indent
  11560. * @method execCommand
  11561. * @param { String } cmd 命令字符串
  11562. * @example
  11563. * ```javascript
  11564. * editor.execCommand( 'indent' );
  11565. * ```
  11566. */
  11567. UE.commands['indent'] = {
  11568. execCommand : function() {
  11569. var me = this,value = me.queryCommandState("indent") ? "0em" : (me.options.indentValue || '2em');
  11570. me.execCommand('Paragraph','p',{style:'text-indent:'+ value});
  11571. },
  11572. queryCommandState : function() {
  11573. var pN = domUtils.filterNodeList(this.selection.getStartElementPath(),'p h1 h2 h3 h4 h5 h6');
  11574. return pN && pN.style.textIndent && parseInt(pN.style.textIndent) ? 1 : 0;
  11575. }
  11576. };
  11577. // js/editor/_src/plugins/print.js
  11578. /**
  11579. * 打印
  11580. * @file
  11581. * @since 1.2.6.1
  11582. */
  11583. /**
  11584. * 打印
  11585. * @command print
  11586. * @method execCommand
  11587. * @param { String } cmd 命令字符串
  11588. * @example
  11589. * ```javascript
  11590. * editor.execCommand( 'print' );
  11591. * ```
  11592. */
  11593. UE.commands['print'] = {
  11594. execCommand : function(){
  11595. this.window.print();
  11596. },
  11597. notNeedUndo : 1
  11598. };
  11599. // js/editor/_src/plugins/preview.js
  11600. /**
  11601. * 预览
  11602. * @file
  11603. * @since 1.2.6.1
  11604. */
  11605. /**
  11606. * 预览
  11607. * @command preview
  11608. * @method execCommand
  11609. * @param { String } cmd 命令字符串
  11610. * @example
  11611. * ```javascript
  11612. * editor.execCommand( 'preview' );
  11613. * ```
  11614. */
  11615. UE.commands['preview'] = {
  11616. execCommand : function(){
  11617. var w = window.open('', '_blank', ''),
  11618. d = w.document;
  11619. d.open();
  11620. d.write('<!DOCTYPE html><html><head><meta charset="utf-8"/><script src="'+this.options.UEDITOR_HOME_URL+'ueditor.parse.js"></script><script>' +
  11621. "setTimeout(function(){uParse('div',{rootPath: '"+ this.options.UEDITOR_HOME_URL +"'})},300)" +
  11622. '</script></head><body><div>'+this.getContent(null,null,true)+'</div></body></html>');
  11623. d.close();
  11624. },
  11625. notNeedUndo : 1
  11626. };
  11627. // js/editor/_src/plugins/selectall.js
  11628. /**
  11629. * 全选
  11630. * @file
  11631. * @since 1.2.6.1
  11632. */
  11633. /**
  11634. * 选中所有内容
  11635. * @command selectall
  11636. * @method execCommand
  11637. * @param { String } cmd 命令字符串
  11638. * @example
  11639. * ```javascript
  11640. * editor.execCommand( 'selectall' );
  11641. * ```
  11642. */
  11643. UE.plugins['selectall'] = function(){
  11644. var me = this;
  11645. me.commands['selectall'] = {
  11646. execCommand : function(){
  11647. //去掉了原生的selectAll,因为会出现报错和当内容为空时,不能出现闭合状态的光标
  11648. var me = this,body = me.body,
  11649. range = me.selection.getRange();
  11650. range.selectNodeContents(body);
  11651. if(domUtils.isEmptyBlock(body)){
  11652. //opera不能自动合并到元素的里边,要手动处理一下
  11653. if(browser.opera && body.firstChild && body.firstChild.nodeType == 1){
  11654. range.setStartAtFirst(body.firstChild);
  11655. }
  11656. range.collapse(true);
  11657. }
  11658. range.select(true);
  11659. },
  11660. notNeedUndo : 1
  11661. };
  11662. //快捷键
  11663. me.addshortcutkey({
  11664. "selectAll" : "ctrl+65"
  11665. });
  11666. };
  11667. // js/editor/_src/plugins/paragraph.js
  11668. /**
  11669. * 段落样式
  11670. * @file
  11671. * @since 1.2.6.1
  11672. */
  11673. /**
  11674. * 段落格式
  11675. * @command paragraph
  11676. * @method execCommand
  11677. * @param { String } cmd 命令字符串
  11678. * @param {String} style 标签值为:'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
  11679. * @param {Object} attrs 标签的属性
  11680. * @example
  11681. * ```javascript
  11682. * editor.execCommand( 'Paragraph','h1','{
  11683. * class:'test'
  11684. * }' );
  11685. * ```
  11686. */
  11687. /**
  11688. * 返回选区内节点标签名
  11689. * @command paragraph
  11690. * @method queryCommandValue
  11691. * @param { String } cmd 命令字符串
  11692. * @return { String } 节点标签名
  11693. * @example
  11694. * ```javascript
  11695. * editor.queryCommandValue( 'Paragraph' );
  11696. * ```
  11697. */
  11698. UE.plugins['paragraph'] = function() {
  11699. var me = this,
  11700. block = domUtils.isBlockElm,
  11701. notExchange = ['TD','LI','PRE'],
  11702. doParagraph = function(range,style,attrs,sourceCmdName){
  11703. var bookmark = range.createBookmark(),
  11704. filterFn = function( node ) {
  11705. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' && !domUtils.isBookmarkNode(node) : !domUtils.isWhitespace( node );
  11706. },
  11707. para;
  11708. range.enlarge( true );
  11709. var bookmark2 = range.createBookmark(),
  11710. current = domUtils.getNextDomNode( bookmark2.start, false, filterFn ),
  11711. tmpRange = range.cloneRange(),
  11712. tmpNode;
  11713. while ( current && !(domUtils.getPosition( current, bookmark2.end ) & domUtils.POSITION_FOLLOWING) ) {
  11714. if ( current.nodeType == 3 || !block( current ) ) {
  11715. tmpRange.setStartBefore( current );
  11716. while ( current && current !== bookmark2.end && !block( current ) ) {
  11717. tmpNode = current;
  11718. current = domUtils.getNextDomNode( current, false, null, function( node ) {
  11719. return !block( node );
  11720. } );
  11721. }
  11722. tmpRange.setEndAfter( tmpNode );
  11723. para = range.document.createElement( style );
  11724. if(attrs){
  11725. domUtils.setAttributes(para,attrs);
  11726. if(sourceCmdName && sourceCmdName == 'customstyle' && attrs.style){
  11727. para.style.cssText = attrs.style;
  11728. }
  11729. }
  11730. para.appendChild( tmpRange.extractContents() );
  11731. //需要内容占位
  11732. if(domUtils.isEmptyNode(para)){
  11733. domUtils.fillChar(range.document,para);
  11734. }
  11735. tmpRange.insertNode( para );
  11736. var parent = para.parentNode;
  11737. //如果para上一级是一个block元素且不是body,td就删除它
  11738. if ( block( parent ) && !domUtils.isBody( para.parentNode ) && utils.indexOf(notExchange,parent.tagName)==-1) {
  11739. //存储dir,style
  11740. if(!(sourceCmdName && sourceCmdName == 'customstyle')){
  11741. parent.getAttribute('dir') && para.setAttribute('dir',parent.getAttribute('dir'));
  11742. //trace:1070
  11743. parent.style.cssText && (para.style.cssText = parent.style.cssText + ';' + para.style.cssText);
  11744. //trace:1030
  11745. parent.style.textAlign && !para.style.textAlign && (para.style.textAlign = parent.style.textAlign);
  11746. parent.style.textIndent && !para.style.textIndent && (para.style.textIndent = parent.style.textIndent);
  11747. parent.style.padding && !para.style.padding && (para.style.padding = parent.style.padding);
  11748. }
  11749. //trace:1706 选择的就是h1-6要删除
  11750. if(attrs && /h\d/i.test(parent.tagName) && !/h\d/i.test(para.tagName) ){
  11751. domUtils.setAttributes(parent,attrs);
  11752. if(sourceCmdName && sourceCmdName == 'customstyle' && attrs.style){
  11753. parent.style.cssText = attrs.style;
  11754. }
  11755. domUtils.remove(para,true);
  11756. para = parent;
  11757. }else{
  11758. domUtils.remove( para.parentNode, true );
  11759. }
  11760. }
  11761. if( utils.indexOf(notExchange,parent.tagName)!=-1){
  11762. current = parent;
  11763. }else{
  11764. current = para;
  11765. }
  11766. current = domUtils.getNextDomNode( current, false, filterFn );
  11767. } else {
  11768. current = domUtils.getNextDomNode( current, true, filterFn );
  11769. }
  11770. }
  11771. return range.moveToBookmark( bookmark2 ).moveToBookmark( bookmark );
  11772. };
  11773. me.setOpt('paragraph',{'p':'', 'h1':'', 'h2':'', 'h3':'', 'h4':'', 'h5':'', 'h6':''});
  11774. me.commands['paragraph'] = {
  11775. execCommand : function( cmdName, style,attrs,sourceCmdName ) {
  11776. var range = this.selection.getRange();
  11777. //闭合时单独处理
  11778. if(range.collapsed){
  11779. var txt = this.document.createTextNode('p');
  11780. range.insertNode(txt);
  11781. //去掉冗余的fillchar
  11782. if(browser.ie){
  11783. var node = txt.previousSibling;
  11784. if(node && domUtils.isWhitespace(node)){
  11785. domUtils.remove(node);
  11786. }
  11787. node = txt.nextSibling;
  11788. if(node && domUtils.isWhitespace(node)){
  11789. domUtils.remove(node);
  11790. }
  11791. }
  11792. }
  11793. range = doParagraph(range,style,attrs,sourceCmdName);
  11794. if(txt){
  11795. range.setStartBefore(txt).collapse(true);
  11796. pN = txt.parentNode;
  11797. domUtils.remove(txt);
  11798. if(domUtils.isBlockElm(pN)&&domUtils.isEmptyNode(pN)){
  11799. domUtils.fillNode(this.document,pN);
  11800. }
  11801. }
  11802. if(browser.gecko && range.collapsed && range.startContainer.nodeType == 1){
  11803. var child = range.startContainer.childNodes[range.startOffset];
  11804. if(child && child.nodeType == 1 && child.tagName.toLowerCase() == style){
  11805. range.setStart(child,0).collapse(true);
  11806. }
  11807. }
  11808. //trace:1097 原来有true,原因忘了,但去了就不能清除多余的占位符了
  11809. range.select();
  11810. return true;
  11811. },
  11812. queryCommandValue : function() {
  11813. var node = domUtils.filterNodeList(this.selection.getStartElementPath(),'p h1 h2 h3 h4 h5 h6');
  11814. return node ? node.tagName.toLowerCase() : '';
  11815. }
  11816. };
  11817. };
  11818. // js/editor/_src/plugins/directionality.js
  11819. /**
  11820. * 设置文字输入的方向的插件
  11821. * @file
  11822. * @since 1.2.6.1
  11823. */
  11824. (function() {
  11825. var block = domUtils.isBlockElm ,
  11826. getObj = function(editor){
  11827. // var startNode = editor.selection.getStart(),
  11828. // parents;
  11829. // if ( startNode ) {
  11830. // //查找所有的是block的父亲节点
  11831. // parents = domUtils.findParents( startNode, true, block, true );
  11832. // for ( var i = 0,ci; ci = parents[i++]; ) {
  11833. // if ( ci.getAttribute( 'dir' ) ) {
  11834. // return ci;
  11835. // }
  11836. // }
  11837. // }
  11838. return domUtils.filterNodeList(editor.selection.getStartElementPath(),function(n){return n && n.nodeType == 1 && n.getAttribute('dir')});
  11839. },
  11840. doDirectionality = function(range,editor,forward){
  11841. var bookmark,
  11842. filterFn = function( node ) {
  11843. return node.nodeType == 1 ? !domUtils.isBookmarkNode(node) : !domUtils.isWhitespace(node);
  11844. },
  11845. obj = getObj( editor );
  11846. if ( obj && range.collapsed ) {
  11847. obj.setAttribute( 'dir', forward );
  11848. return range;
  11849. }
  11850. bookmark = range.createBookmark();
  11851. range.enlarge( true );
  11852. var bookmark2 = range.createBookmark(),
  11853. current = domUtils.getNextDomNode( bookmark2.start, false, filterFn ),
  11854. tmpRange = range.cloneRange(),
  11855. tmpNode;
  11856. while ( current && !(domUtils.getPosition( current, bookmark2.end ) & domUtils.POSITION_FOLLOWING) ) {
  11857. if ( current.nodeType == 3 || !block( current ) ) {
  11858. tmpRange.setStartBefore( current );
  11859. while ( current && current !== bookmark2.end && !block( current ) ) {
  11860. tmpNode = current;
  11861. current = domUtils.getNextDomNode( current, false, null, function( node ) {
  11862. return !block( node );
  11863. } );
  11864. }
  11865. tmpRange.setEndAfter( tmpNode );
  11866. var common = tmpRange.getCommonAncestor();
  11867. if ( !domUtils.isBody( common ) && block( common ) ) {
  11868. //遍历到了block节点
  11869. common.setAttribute( 'dir', forward );
  11870. current = common;
  11871. } else {
  11872. //没有遍历到,添加一个block节点
  11873. var p = range.document.createElement( 'p' );
  11874. p.setAttribute( 'dir', forward );
  11875. var frag = tmpRange.extractContents();
  11876. p.appendChild( frag );
  11877. tmpRange.insertNode( p );
  11878. current = p;
  11879. }
  11880. current = domUtils.getNextDomNode( current, false, filterFn );
  11881. } else {
  11882. current = domUtils.getNextDomNode( current, true, filterFn );
  11883. }
  11884. }
  11885. return range.moveToBookmark( bookmark2 ).moveToBookmark( bookmark );
  11886. };
  11887. /**
  11888. * 文字输入方向
  11889. * @command directionality
  11890. * @method execCommand
  11891. * @param { String } cmdName 命令字符串
  11892. * @param { String } forward 传入'ltr'表示从左向右输入,传入'rtl'表示从右向左输入
  11893. * @example
  11894. * ```javascript
  11895. * editor.execCommand( 'directionality', 'ltr');
  11896. * ```
  11897. */
  11898. /**
  11899. * 查询当前选区的文字输入方向
  11900. * @command directionality
  11901. * @method queryCommandValue
  11902. * @param { String } cmdName 命令字符串
  11903. * @return { String } 返回'ltr'表示从左向右输入,返回'rtl'表示从右向左输入
  11904. * @example
  11905. * ```javascript
  11906. * editor.queryCommandValue( 'directionality');
  11907. * ```
  11908. */
  11909. UE.commands['directionality'] = {
  11910. execCommand : function( cmdName,forward ) {
  11911. var range = this.selection.getRange();
  11912. //闭合时单独处理
  11913. if(range.collapsed){
  11914. var txt = this.document.createTextNode('d');
  11915. range.insertNode(txt);
  11916. }
  11917. doDirectionality(range,this,forward);
  11918. if(txt){
  11919. range.setStartBefore(txt).collapse(true);
  11920. domUtils.remove(txt);
  11921. }
  11922. range.select();
  11923. return true;
  11924. },
  11925. queryCommandValue : function() {
  11926. var node = getObj(this);
  11927. return node ? node.getAttribute('dir') : 'ltr';
  11928. }
  11929. };
  11930. })();
  11931. // js/editor/_src/plugins/horizontal.js
  11932. /**
  11933. * 插入分割线插件
  11934. * @file
  11935. * @since 1.2.6.1
  11936. */
  11937. /**
  11938. * 插入分割线
  11939. * @command horizontal
  11940. * @method execCommand
  11941. * @param { String } cmdName 命令字符串
  11942. * @example
  11943. * ```javascript
  11944. * editor.execCommand( 'horizontal' );
  11945. * ```
  11946. */
  11947. UE.plugins['horizontal'] = function(){
  11948. var me = this;
  11949. me.commands['horizontal'] = {
  11950. execCommand : function( cmdName ) {
  11951. var me = this;
  11952. if(me.queryCommandState(cmdName)!==-1){
  11953. me.execCommand('insertHtml','<hr>');
  11954. var range = me.selection.getRange(),
  11955. start = range.startContainer;
  11956. if(start.nodeType == 1 && !start.childNodes[range.startOffset] ){
  11957. var tmp;
  11958. if(tmp = start.childNodes[range.startOffset - 1]){
  11959. if(tmp.nodeType == 1 && tmp.tagName == 'HR'){
  11960. if(me.options.enterTag == 'p'){
  11961. tmp = me.document.createElement('p');
  11962. range.insertNode(tmp);
  11963. range.setStart(tmp,0).setCursor();
  11964. }else{
  11965. tmp = me.document.createElement('br');
  11966. range.insertNode(tmp);
  11967. range.setStartBefore(tmp).setCursor();
  11968. }
  11969. }
  11970. }
  11971. }
  11972. return true;
  11973. }
  11974. },
  11975. //边界在table里不能加分隔线
  11976. queryCommandState : function() {
  11977. return domUtils.filterNodeList(this.selection.getStartElementPath(),'table') ? -1 : 0;
  11978. }
  11979. };
  11980. // me.addListener('delkeyup',function(){
  11981. // var rng = this.selection.getRange();
  11982. // if(browser.ie && browser.version > 8){
  11983. // rng.txtToElmBoundary(true);
  11984. // if(domUtils.isStartInblock(rng)){
  11985. // var tmpNode = rng.startContainer;
  11986. // var pre = tmpNode.previousSibling;
  11987. // if(pre && domUtils.isTagNode(pre,'hr')){
  11988. // domUtils.remove(pre);
  11989. // rng.select();
  11990. // return;
  11991. // }
  11992. // }
  11993. // }
  11994. // if(domUtils.isBody(rng.startContainer)){
  11995. // var hr = rng.startContainer.childNodes[rng.startOffset -1];
  11996. // if(hr && hr.nodeName == 'HR'){
  11997. // var next = hr.nextSibling;
  11998. // if(next){
  11999. // rng.setStart(next,0)
  12000. // }else if(hr.previousSibling){
  12001. // rng.setStartAtLast(hr.previousSibling)
  12002. // }else{
  12003. // var p = this.document.createElement('p');
  12004. // hr.parentNode.insertBefore(p,hr);
  12005. // domUtils.fillNode(this.document,p);
  12006. // rng.setStart(p,0);
  12007. // }
  12008. // domUtils.remove(hr);
  12009. // rng.setCursor(false,true);
  12010. // }
  12011. // }
  12012. // })
  12013. me.addListener('delkeydown',function(name,evt){
  12014. var rng = this.selection.getRange();
  12015. rng.txtToElmBoundary(true);
  12016. if(domUtils.isStartInblock(rng)){
  12017. var tmpNode = rng.startContainer;
  12018. var pre = tmpNode.previousSibling;
  12019. if(pre && domUtils.isTagNode(pre,'hr')){
  12020. domUtils.remove(pre);
  12021. rng.select();
  12022. domUtils.preventDefault(evt);
  12023. return true;
  12024. }
  12025. }
  12026. })
  12027. };
  12028. // js/editor/_src/plugins/time.js
  12029. /**
  12030. * 插入时间和日期
  12031. * @file
  12032. * @since 1.2.6.1
  12033. */
  12034. /**
  12035. * 插入时间,默认格式:12:59:59
  12036. * @command time
  12037. * @method execCommand
  12038. * @param { String } cmd 命令字符串
  12039. * @example
  12040. * ```javascript
  12041. * editor.execCommand( 'time');
  12042. * ```
  12043. */
  12044. /**
  12045. * 插入日期,默认格式:2013-08-30
  12046. * @command date
  12047. * @method execCommand
  12048. * @param { String } cmd 命令字符串
  12049. * @example
  12050. * ```javascript
  12051. * editor.execCommand( 'date');
  12052. * ```
  12053. */
  12054. UE.commands['time'] = UE.commands["date"] = {
  12055. execCommand : function(cmd, format){
  12056. var date = new Date;
  12057. function formatTime(date, format) {
  12058. var hh = ('0' + date.getHours()).slice(-2),
  12059. ii = ('0' + date.getMinutes()).slice(-2),
  12060. ss = ('0' + date.getSeconds()).slice(-2);
  12061. format = format || 'hh:ii:ss';
  12062. return format.replace(/hh/ig, hh).replace(/ii/ig, ii).replace(/ss/ig, ss);
  12063. }
  12064. function formatDate(date, format) {
  12065. var yyyy = ('000' + date.getFullYear()).slice(-4),
  12066. yy = yyyy.slice(-2),
  12067. mm = ('0' + (date.getMonth()+1)).slice(-2),
  12068. dd = ('0' + date.getDate()).slice(-2);
  12069. format = format || 'yyyy-mm-dd';
  12070. return format.replace(/yyyy/ig, yyyy).replace(/yy/ig, yy).replace(/mm/ig, mm).replace(/dd/ig, dd);
  12071. }
  12072. this.execCommand('insertHtml',cmd == "time" ? formatTime(date, format):formatDate(date, format) );
  12073. }
  12074. };
  12075. // js/editor/_src/plugins/rowspacing.js
  12076. /**
  12077. * 段前段后间距插件
  12078. * @file
  12079. * @since 1.2.6.1
  12080. */
  12081. /**
  12082. * 设置段间距
  12083. * @command rowspacing
  12084. * @method execCommand
  12085. * @param { String } cmd 命令字符串
  12086. * @param { String } value 段间距的值,以px为单位
  12087. * @param { String } dir 间距位置,top或bottom,分别表示段前和段后
  12088. * @example
  12089. * ```javascript
  12090. * editor.execCommand( 'rowspacing', '10', 'top' );
  12091. * ```
  12092. */
  12093. UE.plugins['rowspacing'] = function(){
  12094. var me = this;
  12095. me.setOpt({
  12096. 'rowspacingtop':['5', '10', '15', '20', '25'],
  12097. 'rowspacingbottom':['5', '10', '15', '20', '25']
  12098. });
  12099. me.commands['rowspacing'] = {
  12100. execCommand : function( cmdName,value,dir ) {
  12101. this.execCommand('paragraph','p',{style:'margin-'+dir+':'+value + 'px'});
  12102. return true;
  12103. },
  12104. queryCommandValue : function(cmdName,dir) {
  12105. var pN = domUtils.filterNodeList(this.selection.getStartElementPath(),function(node){return domUtils.isBlockElm(node) }),
  12106. value;
  12107. //trace:1026
  12108. if(pN){
  12109. value = domUtils.getComputedStyle(pN,'margin-'+dir).replace(/[^\d]/g,'');
  12110. return !value ? 0 : value;
  12111. }
  12112. return 0;
  12113. }
  12114. };
  12115. };
  12116. // js/editor/_src/plugins/lineheight.js
  12117. /**
  12118. * 设置行内间距
  12119. * @file
  12120. * @since 1.2.6.1
  12121. */
  12122. UE.plugins['lineheight'] = function(){
  12123. var me = this;
  12124. me.setOpt({'lineheight':['1', '1.5','1.75','2', '3', '4', '5']});
  12125. /**
  12126. * 行距
  12127. * @command lineheight
  12128. * @method execCommand
  12129. * @param { String } cmdName 命令字符串
  12130. * @param { String } value 传入的行高值, 该值是当前字体的倍数, 例如: 1.5, 1.75
  12131. * @example
  12132. * ```javascript
  12133. * editor.execCommand( 'lineheight', 1.5);
  12134. * ```
  12135. */
  12136. /**
  12137. * 查询当前选区内容的行高大小
  12138. * @command lineheight
  12139. * @method queryCommandValue
  12140. * @param { String } cmd 命令字符串
  12141. * @return { String } 返回当前行高大小
  12142. * @example
  12143. * ```javascript
  12144. * editor.queryCommandValue( 'lineheight' );
  12145. * ```
  12146. */
  12147. me.commands['lineheight'] = {
  12148. execCommand : function( cmdName,value ) {
  12149. this.execCommand('paragraph','p',{style:'line-height:'+ (value == "1" ? "normal" : value + 'em') });
  12150. return true;
  12151. },
  12152. queryCommandValue : function() {
  12153. var pN = domUtils.filterNodeList(this.selection.getStartElementPath(),function(node){return domUtils.isBlockElm(node)});
  12154. if(pN){
  12155. var value = domUtils.getComputedStyle(pN,'line-height');
  12156. return value == 'normal' ? 1 : value.replace(/[^\d.]*/ig,"");
  12157. }
  12158. }
  12159. };
  12160. };
  12161. // js/editor/_src/plugins/insertcode.js
  12162. /**
  12163. * 插入代码插件
  12164. * @file
  12165. * @since 1.2.6.1
  12166. */
  12167. UE.plugins['insertcode'] = function() {
  12168. var me = this;
  12169. me.ready(function(){
  12170. utils.cssRule('pre','pre{margin:.5em 0;padding:.4em .6em;border-radius:8px;background:#f8f8f8;}',
  12171. me.document)
  12172. });
  12173. me.setOpt('insertcode',{
  12174. 'as3':'ActionScript3',
  12175. 'bash':'Bash/Shell',
  12176. 'cpp':'C/C++',
  12177. 'css':'Css',
  12178. 'cf':'CodeFunction',
  12179. 'c#':'C#',
  12180. 'delphi':'Delphi',
  12181. 'diff':'Diff',
  12182. 'erlang':'Erlang',
  12183. 'groovy':'Groovy',
  12184. 'html':'Html',
  12185. 'java':'Java',
  12186. 'jfx':'JavaFx',
  12187. 'js':'Javascript',
  12188. 'pl':'Perl',
  12189. 'php':'Php',
  12190. 'plain':'Plain Text',
  12191. 'ps':'PowerShell',
  12192. 'python':'Python',
  12193. 'ruby':'Ruby',
  12194. 'scala':'Scala',
  12195. 'sql':'Sql',
  12196. 'vb':'Vb',
  12197. 'xml':'Xml'
  12198. });
  12199. /**
  12200. * 插入代码
  12201. * @command insertcode
  12202. * @method execCommand
  12203. * @param { String } cmd 命令字符串
  12204. * @param { String } lang 插入代码的语言
  12205. * @example
  12206. * ```javascript
  12207. * editor.execCommand( 'insertcode', 'javascript' );
  12208. * ```
  12209. */
  12210. /**
  12211. * 如果选区所在位置是插入插入代码区域,返回代码的语言
  12212. * @command insertcode
  12213. * @method queryCommandValue
  12214. * @param { String } cmd 命令字符串
  12215. * @return { String } 返回代码的语言
  12216. * @example
  12217. * ```javascript
  12218. * editor.queryCommandValue( 'insertcode' );
  12219. * ```
  12220. */
  12221. me.commands['insertcode'] = {
  12222. execCommand : function(cmd,lang){
  12223. var me = this,
  12224. rng = me.selection.getRange(),
  12225. pre = domUtils.findParentByTagName(rng.startContainer,'pre',true);
  12226. if(pre){
  12227. pre.className = 'brush:'+lang+';toolbar:false;';
  12228. }else{
  12229. var code = '';
  12230. if(rng.collapsed){
  12231. code = browser.ie && browser.ie11below ? (browser.version <= 8 ? '&nbsp;':''):'<br/>';
  12232. }else{
  12233. var frag = rng.extractContents();
  12234. var div = me.document.createElement('div');
  12235. div.appendChild(frag);
  12236. utils.each(UE.filterNode(UE.htmlparser(div.innerHTML.replace(/[\r\t]/g,'')),me.options.filterTxtRules).children,function(node){
  12237. if(browser.ie && browser.ie11below && browser.version > 8){
  12238. if(node.type =='element'){
  12239. if(node.tagName == 'br'){
  12240. code += '\n'
  12241. }else if(!dtd.$empty[node.tagName]){
  12242. utils.each(node.children,function(cn){
  12243. if(cn.type =='element'){
  12244. if(cn.tagName == 'br'){
  12245. code += '\n'
  12246. }else if(!dtd.$empty[node.tagName]){
  12247. code += cn.innerText();
  12248. }
  12249. }else{
  12250. code += cn.data
  12251. }
  12252. })
  12253. if(!/\n$/.test(code)){
  12254. code += '\n';
  12255. }
  12256. }
  12257. }else{
  12258. code += node.data + '\n'
  12259. }
  12260. if(!node.nextSibling() && /\n$/.test(code)){
  12261. code = code.replace(/\n$/,'');
  12262. }
  12263. }else{
  12264. if(browser.ie && browser.ie11below){
  12265. if(node.type =='element'){
  12266. if(node.tagName == 'br'){
  12267. code += '<br>'
  12268. }else if(!dtd.$empty[node.tagName]){
  12269. utils.each(node.children,function(cn){
  12270. if(cn.type =='element'){
  12271. if(cn.tagName == 'br'){
  12272. code += '<br>'
  12273. }else if(!dtd.$empty[node.tagName]){
  12274. code += cn.innerText();
  12275. }
  12276. }else{
  12277. code += cn.data
  12278. }
  12279. });
  12280. if(!/br>$/.test(code)){
  12281. code += '<br>';
  12282. }
  12283. }
  12284. }else{
  12285. code += node.data + '<br>'
  12286. }
  12287. if(!node.nextSibling() && /<br>$/.test(code)){
  12288. code = code.replace(/<br>$/,'');
  12289. }
  12290. }else{
  12291. code += (node.type == 'element' ? (dtd.$empty[node.tagName] ? '' : node.innerText()) : node.data);
  12292. if(!/br\/?\s*>$/.test(code)){
  12293. if(!node.nextSibling())
  12294. return;
  12295. code += '<br>'
  12296. }
  12297. }
  12298. }
  12299. });
  12300. }
  12301. me.execCommand('inserthtml','<pre id="coder"class="brush:'+lang+';toolbar:false">'+code+'</pre>',true);
  12302. pre = me.document.getElementById('coder');
  12303. domUtils.removeAttributes(pre,'id');
  12304. var tmpNode = pre.previousSibling;
  12305. if(tmpNode && (tmpNode.nodeType == 3 && tmpNode.nodeValue.length == 1 && browser.ie && browser.version == 6 || domUtils.isEmptyBlock(tmpNode))){
  12306. domUtils.remove(tmpNode)
  12307. }
  12308. var rng = me.selection.getRange();
  12309. if(domUtils.isEmptyBlock(pre)){
  12310. rng.setStart(pre,0).setCursor(false,true)
  12311. }else{
  12312. rng.selectNodeContents(pre).select()
  12313. }
  12314. }
  12315. },
  12316. queryCommandValue : function(){
  12317. var path = this.selection.getStartElementPath();
  12318. var lang = '';
  12319. utils.each(path,function(node){
  12320. if(node.nodeName =='PRE'){
  12321. var match = node.className.match(/brush:([^;]+)/);
  12322. lang = match && match[1] ? match[1] : '';
  12323. return false;
  12324. }
  12325. });
  12326. return lang;
  12327. }
  12328. };
  12329. me.addInputRule(function(root){
  12330. utils.each(root.getNodesByTagName('pre'),function(pre){
  12331. var brs = pre.getNodesByTagName('br');
  12332. if(brs.length){
  12333. browser.ie && browser.ie11below && browser.version > 8 && utils.each(brs,function(br){
  12334. var txt = UE.uNode.createText('\n');
  12335. br.parentNode.insertBefore(txt,br);
  12336. br.parentNode.removeChild(br);
  12337. });
  12338. return;
  12339. }
  12340. if(browser.ie && browser.ie11below && browser.version > 8)
  12341. return;
  12342. var code = pre.innerText().split(/\n/);
  12343. pre.innerHTML('');
  12344. utils.each(code,function(c){
  12345. if(c.length){
  12346. pre.appendChild(UE.uNode.createText(c));
  12347. }
  12348. pre.appendChild(UE.uNode.createElement('br'))
  12349. })
  12350. })
  12351. });
  12352. me.addOutputRule(function(root){
  12353. utils.each(root.getNodesByTagName('pre'),function(pre){
  12354. var code = '';
  12355. utils.each(pre.children,function(n){
  12356. if(n.type == 'text'){
  12357. //在ie下文本内容有可能末尾带有\n要去掉
  12358. //trace:3396
  12359. code += n.data.replace(/[ ]/g,'&nbsp;').replace(/\n$/,'');
  12360. }else{
  12361. if(n.tagName == 'br'){
  12362. code += '\n'
  12363. }else{
  12364. code += (!dtd.$empty[n.tagName] ? '' : n.innerText());
  12365. }
  12366. }
  12367. });
  12368. pre.innerText(code.replace(/(&nbsp;|\n)+$/,''))
  12369. })
  12370. });
  12371. //不需要判断highlight的command列表
  12372. me.notNeedCodeQuery ={
  12373. help:1,
  12374. undo:1,
  12375. redo:1,
  12376. source:1,
  12377. print:1,
  12378. searchreplace:1,
  12379. fullscreen:1,
  12380. preview:1,
  12381. insertparagraph:1,
  12382. elementpath:1,
  12383. insertcode:1,
  12384. inserthtml:1,
  12385. selectall:1
  12386. };
  12387. //将queyCommamndState重置
  12388. var orgQuery = me.queryCommandState;
  12389. me.queryCommandState = function(cmd){
  12390. var me = this;
  12391. if(!me.notNeedCodeQuery[cmd.toLowerCase()] && me.selection && me.queryCommandValue('insertcode')){
  12392. return -1;
  12393. }
  12394. return UE.Editor.prototype.queryCommandState.apply(this,arguments)
  12395. };
  12396. me.addListener('beforeenterkeydown',function(){
  12397. var rng = me.selection.getRange();
  12398. var pre = domUtils.findParentByTagName(rng.startContainer,'pre',true);
  12399. if(pre){
  12400. me.fireEvent('saveScene');
  12401. if(!rng.collapsed){
  12402. rng.deleteContents();
  12403. }
  12404. if(!browser.ie || browser.ie9above){
  12405. var tmpNode = me.document.createElement('br'),pre;
  12406. rng.insertNode(tmpNode).setStartAfter(tmpNode).collapse(true);
  12407. var next = tmpNode.nextSibling;
  12408. if(!next && (!browser.ie || browser.version > 10)){
  12409. rng.insertNode(tmpNode.cloneNode(false));
  12410. }else{
  12411. rng.setStartAfter(tmpNode);
  12412. }
  12413. pre = tmpNode.previousSibling;
  12414. var tmp;
  12415. while(pre ){
  12416. tmp = pre;
  12417. pre = pre.previousSibling;
  12418. if(!pre || pre.nodeName == 'BR'){
  12419. pre = tmp;
  12420. break;
  12421. }
  12422. }
  12423. if(pre){
  12424. var str = '';
  12425. while(pre && pre.nodeName != 'BR' && new RegExp('^[\\s'+domUtils.fillChar+']*$').test(pre.nodeValue)){
  12426. str += pre.nodeValue;
  12427. pre = pre.nextSibling;
  12428. }
  12429. if(pre.nodeName != 'BR'){
  12430. var match = pre.nodeValue.match(new RegExp('^([\\s'+domUtils.fillChar+']+)'));
  12431. if(match && match[1]){
  12432. str += match[1]
  12433. }
  12434. }
  12435. if(str){
  12436. str = me.document.createTextNode(str);
  12437. rng.insertNode(str).setStartAfter(str);
  12438. }
  12439. }
  12440. rng.collapse(true).select(true);
  12441. }else{
  12442. if(browser.version > 8){
  12443. var txt = me.document.createTextNode('\n');
  12444. var start = rng.startContainer;
  12445. if(rng.startOffset == 0){
  12446. var preNode = start.previousSibling;
  12447. if(preNode){
  12448. rng.insertNode(txt);
  12449. var fillchar = me.document.createTextNode(' ');
  12450. rng.setStartAfter(txt).insertNode(fillchar).setStart(fillchar,0).collapse(true).select(true)
  12451. }
  12452. }else{
  12453. rng.insertNode(txt).setStartAfter(txt);
  12454. var fillchar = me.document.createTextNode(' ');
  12455. start = rng.startContainer.childNodes[rng.startOffset];
  12456. if(start && !/^\n/.test(start.nodeValue)){
  12457. rng.setStartBefore(txt)
  12458. }
  12459. rng.insertNode(fillchar).setStart(fillchar,0).collapse(true).select(true)
  12460. }
  12461. }else{
  12462. var tmpNode = me.document.createElement('br');
  12463. rng.insertNode(tmpNode);
  12464. rng.insertNode(me.document.createTextNode(domUtils.fillChar));
  12465. rng.setStartAfter(tmpNode);
  12466. pre = tmpNode.previousSibling;
  12467. var tmp;
  12468. while(pre ){
  12469. tmp = pre;
  12470. pre = pre.previousSibling;
  12471. if(!pre || pre.nodeName == 'BR'){
  12472. pre = tmp;
  12473. break;
  12474. }
  12475. }
  12476. if(pre){
  12477. var str = '';
  12478. while(pre && pre.nodeName != 'BR' && new RegExp('^[ '+domUtils.fillChar+']*$').test(pre.nodeValue)){
  12479. str += pre.nodeValue;
  12480. pre = pre.nextSibling;
  12481. }
  12482. if(pre.nodeName != 'BR'){
  12483. var match = pre.nodeValue.match(new RegExp('^([ '+domUtils.fillChar+']+)'));
  12484. if(match && match[1]){
  12485. str += match[1]
  12486. }
  12487. }
  12488. str = me.document.createTextNode(str);
  12489. rng.insertNode(str).setStartAfter(str);
  12490. }
  12491. rng.collapse(true).select();
  12492. }
  12493. }
  12494. me.fireEvent('saveScene');
  12495. return true;
  12496. }
  12497. });
  12498. me.addListener('tabkeydown',function(cmd,evt){
  12499. var rng = me.selection.getRange();
  12500. var pre = domUtils.findParentByTagName(rng.startContainer,'pre',true);
  12501. if(pre){
  12502. me.fireEvent('saveScene');
  12503. if(evt.shiftKey){
  12504. }else{
  12505. if(!rng.collapsed){
  12506. var bk = rng.createBookmark();
  12507. var start = bk.start.previousSibling;
  12508. while(start){
  12509. if(pre.firstChild === start && !domUtils.isBr(start)){
  12510. pre.insertBefore(me.document.createTextNode(' '),start);
  12511. break;
  12512. }
  12513. if(domUtils.isBr(start)){
  12514. pre.insertBefore(me.document.createTextNode(' '),start.nextSibling);
  12515. break;
  12516. }
  12517. start = start.previousSibling;
  12518. }
  12519. var end = bk.end;
  12520. start = bk.start.nextSibling;
  12521. if(pre.firstChild === bk.start){
  12522. pre.insertBefore(me.document.createTextNode(' '),start.nextSibling)
  12523. }
  12524. while(start && start !== end){
  12525. if(domUtils.isBr(start) && start.nextSibling){
  12526. if(start.nextSibling === end){
  12527. break;
  12528. }
  12529. pre.insertBefore(me.document.createTextNode(' '),start.nextSibling)
  12530. }
  12531. start = start.nextSibling;
  12532. }
  12533. rng.moveToBookmark(bk).select();
  12534. }else{
  12535. var tmpNode = me.document.createTextNode(' ');
  12536. rng.insertNode(tmpNode).setStartAfter(tmpNode).collapse(true).select(true);
  12537. }
  12538. }
  12539. me.fireEvent('saveScene');
  12540. return true;
  12541. }
  12542. });
  12543. me.addListener('beforeinserthtml',function(evtName,html){
  12544. var me = this,
  12545. rng = me.selection.getRange(),
  12546. pre = domUtils.findParentByTagName(rng.startContainer,'pre',true);
  12547. if(pre){
  12548. if(!rng.collapsed){
  12549. rng.deleteContents()
  12550. }
  12551. var htmlstr = '';
  12552. if(browser.ie && browser.version > 8){
  12553. utils.each(UE.filterNode(UE.htmlparser(html),me.options.filterTxtRules).children,function(node){
  12554. if(node.type =='element'){
  12555. if(node.tagName == 'br'){
  12556. htmlstr += '\n'
  12557. }else if(!dtd.$empty[node.tagName]){
  12558. utils.each(node.children,function(cn){
  12559. if(cn.type =='element'){
  12560. if(cn.tagName == 'br'){
  12561. htmlstr += '\n'
  12562. }else if(!dtd.$empty[node.tagName]){
  12563. htmlstr += cn.innerText();
  12564. }
  12565. }else{
  12566. htmlstr += cn.data
  12567. }
  12568. })
  12569. if(!/\n$/.test(htmlstr)){
  12570. htmlstr += '\n';
  12571. }
  12572. }
  12573. }else{
  12574. htmlstr += node.data + '\n'
  12575. }
  12576. if(!node.nextSibling() && /\n$/.test(htmlstr)){
  12577. htmlstr = htmlstr.replace(/\n$/,'');
  12578. }
  12579. });
  12580. var tmpNode = me.document.createTextNode(utils.html(htmlstr.replace(/&nbsp;/g,' ')));
  12581. rng.insertNode(tmpNode).selectNode(tmpNode).select();
  12582. }else{
  12583. var frag = me.document.createDocumentFragment();
  12584. utils.each(UE.filterNode(UE.htmlparser(html),me.options.filterTxtRules).children,function(node){
  12585. if(node.type =='element'){
  12586. if(node.tagName == 'br'){
  12587. frag.appendChild(me.document.createElement('br'))
  12588. }else if(!dtd.$empty[node.tagName]){
  12589. utils.each(node.children,function(cn){
  12590. if(cn.type =='element'){
  12591. if(cn.tagName == 'br'){
  12592. frag.appendChild(me.document.createElement('br'))
  12593. }else if(!dtd.$empty[node.tagName]){
  12594. frag.appendChild(me.document.createTextNode(utils.html(cn.innerText().replace(/&nbsp;/g,' '))));
  12595. }
  12596. }else{
  12597. frag.appendChild(me.document.createTextNode(utils.html( cn.data.replace(/&nbsp;/g,' '))));
  12598. }
  12599. })
  12600. if(frag.lastChild.nodeName != 'BR'){
  12601. frag.appendChild(me.document.createElement('br'))
  12602. }
  12603. }
  12604. }else{
  12605. frag.appendChild(me.document.createTextNode(utils.html( node.data.replace(/&nbsp;/g,' '))));
  12606. }
  12607. if(!node.nextSibling() && frag.lastChild.nodeName == 'BR'){
  12608. frag.removeChild(frag.lastChild)
  12609. }
  12610. });
  12611. rng.insertNode(frag).select();
  12612. }
  12613. return true;
  12614. }
  12615. });
  12616. //方向键的处理
  12617. me.addListener('keydown',function(cmd,evt){
  12618. var me = this,keyCode = evt.keyCode || evt.which;
  12619. if(keyCode == 40){
  12620. var rng = me.selection.getRange(),pre,start = rng.startContainer;
  12621. if(rng.collapsed && (pre = domUtils.findParentByTagName(rng.startContainer,'pre',true)) && !pre.nextSibling){
  12622. var last = pre.lastChild
  12623. while(last && last.nodeName == 'BR'){
  12624. last = last.previousSibling;
  12625. }
  12626. if(last === start || rng.startContainer === pre && rng.startOffset == pre.childNodes.length){
  12627. me.execCommand('insertparagraph');
  12628. domUtils.preventDefault(evt)
  12629. }
  12630. }
  12631. }
  12632. });
  12633. //trace:3395
  12634. me.addListener('delkeydown',function(type,evt){
  12635. var rng = this.selection.getRange();
  12636. rng.txtToElmBoundary(true);
  12637. var start = rng.startContainer;
  12638. if(domUtils.isTagNode(start,'pre') && rng.collapsed && domUtils.isStartInblock(rng)){
  12639. var p = me.document.createElement('p');
  12640. domUtils.fillNode(me.document,p);
  12641. start.parentNode.insertBefore(p,start);
  12642. domUtils.remove(start);
  12643. rng.setStart(p,0).setCursor(false,true);
  12644. domUtils.preventDefault(evt);
  12645. return true;
  12646. }
  12647. })
  12648. };
  12649. // js/editor/_src/plugins/cleardoc.js
  12650. /**
  12651. * 清空文档插件
  12652. * @file
  12653. * @since 1.2.6.1
  12654. */
  12655. /**
  12656. * 清空文档
  12657. * @command cleardoc
  12658. * @method execCommand
  12659. * @param { String } cmd 命令字符串
  12660. * @example
  12661. * ```javascript
  12662. * //editor 是编辑器实例
  12663. * editor.execCommand('cleardoc');
  12664. * ```
  12665. */
  12666. UE.commands['cleardoc'] = {
  12667. execCommand : function( cmdName) {
  12668. var me = this,
  12669. enterTag = me.options.enterTag,
  12670. range = me.selection.getRange();
  12671. if(enterTag == "br"){
  12672. me.body.innerHTML = "<br/>";
  12673. range.setStart(me.body,0).setCursor();
  12674. }else{
  12675. me.body.innerHTML = "<p>"+(ie ? "" : "<br/>")+"</p>";
  12676. range.setStart(me.body.firstChild,0).setCursor(false,true);
  12677. }
  12678. setTimeout(function(){
  12679. me.fireEvent("clearDoc");
  12680. },0);
  12681. }
  12682. };
  12683. // js/editor/_src/plugins/anchor.js
  12684. /**
  12685. * 锚点插件,为UEditor提供插入锚点支持
  12686. * @file
  12687. * @since 1.2.6.1
  12688. */
  12689. UE.plugin.register('anchor', function (){
  12690. return {
  12691. bindEvents:{
  12692. 'ready':function(){
  12693. utils.cssRule('anchor',
  12694. '.anchorclass{background: url(\''
  12695. + this.options.themePath
  12696. + this.options.theme +'/images/anchor.gif\') no-repeat scroll left center transparent;cursor: auto;display: inline-block;height: 16px;width: 15px;}',
  12697. this.document);
  12698. }
  12699. },
  12700. outputRule: function(root){
  12701. utils.each(root.getNodesByTagName('img'),function(a){
  12702. var val;
  12703. if(val = a.getAttr('anchorname')){
  12704. a.tagName = 'a';
  12705. a.setAttr({
  12706. anchorname : '',
  12707. name : val,
  12708. 'class' : ''
  12709. })
  12710. }
  12711. })
  12712. },
  12713. inputRule:function(root){
  12714. utils.each(root.getNodesByTagName('a'),function(a){
  12715. var val;
  12716. if((val = a.getAttr('name')) && !a.getAttr('href')){
  12717. a.tagName = 'img';
  12718. a.setAttr({
  12719. anchorname :a.getAttr('name'),
  12720. 'class' : 'anchorclass'
  12721. });
  12722. a.setAttr('name')
  12723. }
  12724. })
  12725. },
  12726. commands:{
  12727. /**
  12728. * 插入锚点
  12729. * @command anchor
  12730. * @method execCommand
  12731. * @param { String } cmd 命令字符串
  12732. * @param { String } name 锚点名称字符串
  12733. * @example
  12734. * ```javascript
  12735. * //editor 是编辑器实例
  12736. * editor.execCommand('anchor', 'anchor1');
  12737. * ```
  12738. */
  12739. 'anchor':{
  12740. execCommand:function (cmd, name) {
  12741. var range = this.selection.getRange(),img = range.getClosedNode();
  12742. if (img && img.getAttribute('anchorname')) {
  12743. if (name) {
  12744. img.setAttribute('anchorname', name);
  12745. } else {
  12746. range.setStartBefore(img).setCursor();
  12747. domUtils.remove(img);
  12748. }
  12749. } else {
  12750. if (name) {
  12751. //只在选区的开始插入
  12752. var anchor = this.document.createElement('img');
  12753. range.collapse(true);
  12754. domUtils.setAttributes(anchor,{
  12755. 'anchorname':name,
  12756. 'class':'anchorclass'
  12757. });
  12758. range.insertNode(anchor).setStartAfter(anchor).setCursor(false,true);
  12759. }
  12760. }
  12761. }
  12762. }
  12763. }
  12764. }
  12765. });
  12766. // js/editor/_src/plugins/wordcount.js
  12767. ///import core
  12768. ///commands 字数统计
  12769. ///commandsName WordCount,wordCount
  12770. ///commandsTitle 字数统计
  12771. /*
  12772. * Created by JetBrains WebStorm.
  12773. * User: taoqili
  12774. * Date: 11-9-7
  12775. * Time: 下午8:18
  12776. * To change this template use File | Settings | File Templates.
  12777. */
  12778. UE.plugins['wordcount'] = function(){
  12779. var me = this;
  12780. me.setOpt('wordCount',true);
  12781. me.addListener('contentchange',function(){
  12782. me.fireEvent('wordcount');
  12783. });
  12784. var timer;
  12785. me.addListener('ready',function(){
  12786. var me = this;
  12787. domUtils.on(me.body,"keyup",function(evt){
  12788. var code = evt.keyCode||evt.which,
  12789. //忽略的按键,ctr,alt,shift,方向键
  12790. ignores = {"16":1,"18":1,"20":1,"37":1,"38":1,"39":1,"40":1};
  12791. if(code in ignores) return;
  12792. clearTimeout(timer);
  12793. timer = setTimeout(function(){
  12794. me.fireEvent('wordcount');
  12795. },200)
  12796. })
  12797. });
  12798. };
  12799. // js/editor/_src/plugins/pagebreak.js
  12800. /**
  12801. * 分页功能插件
  12802. * @file
  12803. * @since 1.2.6.1
  12804. */
  12805. UE.plugins['pagebreak'] = function () {
  12806. var me = this,
  12807. notBreakTags = ['td'];
  12808. me.setOpt('pageBreakTag','_ueditor_page_break_tag_');
  12809. function fillNode(node){
  12810. if(domUtils.isEmptyBlock(node)){
  12811. var firstChild = node.firstChild,tmpNode;
  12812. while(firstChild && firstChild.nodeType == 1 && domUtils.isEmptyBlock(firstChild)){
  12813. tmpNode = firstChild;
  12814. firstChild = firstChild.firstChild;
  12815. }
  12816. !tmpNode && (tmpNode = node);
  12817. domUtils.fillNode(me.document,tmpNode);
  12818. }
  12819. }
  12820. //分页符样式添加
  12821. me.ready(function(){
  12822. utils.cssRule('pagebreak','.pagebreak{display:block;clear:both !important;cursor:default !important;width: 100% !important;margin:0;}',me.document);
  12823. });
  12824. function isHr(node){
  12825. return node && node.nodeType == 1 && node.tagName == 'HR' && node.className == 'pagebreak';
  12826. }
  12827. me.addInputRule(function(root){
  12828. root.traversal(function(node){
  12829. if(node.type == 'text' && node.data == me.options.pageBreakTag){
  12830. var hr = UE.uNode.createElement('<hr class="pagebreak" noshade="noshade" size="5" style="-webkit-user-select: none;">');
  12831. node.parentNode.insertBefore(hr,node);
  12832. node.parentNode.removeChild(node)
  12833. }
  12834. })
  12835. });
  12836. me.addOutputRule(function(node){
  12837. utils.each(node.getNodesByTagName('hr'),function(n){
  12838. if(n.getAttr('class') == 'pagebreak'){
  12839. var txt = UE.uNode.createText(me.options.pageBreakTag);
  12840. n.parentNode.insertBefore(txt,n);
  12841. n.parentNode.removeChild(n);
  12842. }
  12843. })
  12844. });
  12845. /**
  12846. * 插入分页符
  12847. * @command pagebreak
  12848. * @method execCommand
  12849. * @param { String } cmd 命令字符串
  12850. * @remind 在表格中插入分页符会把表格切分成两部分
  12851. * @remind 获取编辑器内的数据时, 编辑器会把分页符转换成“_ueditor_page_break_tag_”字符串,
  12852. * 以便于提交数据到服务器端后处理分页。
  12853. * @example
  12854. * ```javascript
  12855. * editor.execCommand( 'pagebreak'); //插入一个hr标签,带有样式类名pagebreak
  12856. * ```
  12857. */
  12858. me.commands['pagebreak'] = {
  12859. execCommand:function () {
  12860. var range = me.selection.getRange(),hr = me.document.createElement('hr');
  12861. domUtils.setAttributes(hr,{
  12862. 'class' : 'pagebreak',
  12863. noshade:"noshade",
  12864. size:"5"
  12865. });
  12866. domUtils.unSelectable(hr);
  12867. //table单独处理
  12868. var node = domUtils.findParentByTagName(range.startContainer, notBreakTags, true),
  12869. parents = [], pN;
  12870. if (node) {
  12871. switch (node.tagName) {
  12872. case 'TD':
  12873. pN = node.parentNode;
  12874. if (!pN.previousSibling) {
  12875. var table = domUtils.findParentByTagName(pN, 'table');
  12876. // var tableWrapDiv = table.parentNode;
  12877. // if(tableWrapDiv && tableWrapDiv.nodeType == 1
  12878. // && tableWrapDiv.tagName == 'DIV'
  12879. // && tableWrapDiv.getAttribute('dropdrag')
  12880. // ){
  12881. // domUtils.remove(tableWrapDiv,true);
  12882. // }
  12883. table.parentNode.insertBefore(hr, table);
  12884. parents = domUtils.findParents(hr, true);
  12885. } else {
  12886. pN.parentNode.insertBefore(hr, pN);
  12887. parents = domUtils.findParents(hr);
  12888. }
  12889. pN = parents[1];
  12890. if (hr !== pN) {
  12891. domUtils.breakParent(hr, pN);
  12892. }
  12893. //table要重写绑定一下拖拽
  12894. me.fireEvent('afteradjusttable',me.document);
  12895. }
  12896. } else {
  12897. if (!range.collapsed) {
  12898. range.deleteContents();
  12899. var start = range.startContainer;
  12900. while ( !domUtils.isBody(start) && domUtils.isBlockElm(start) && domUtils.isEmptyNode(start)) {
  12901. range.setStartBefore(start).collapse(true);
  12902. domUtils.remove(start);
  12903. start = range.startContainer;
  12904. }
  12905. }
  12906. range.insertNode(hr);
  12907. var pN = hr.parentNode, nextNode;
  12908. while (!domUtils.isBody(pN)) {
  12909. domUtils.breakParent(hr, pN);
  12910. nextNode = hr.nextSibling;
  12911. if (nextNode && domUtils.isEmptyBlock(nextNode)) {
  12912. domUtils.remove(nextNode);
  12913. }
  12914. pN = hr.parentNode;
  12915. }
  12916. nextNode = hr.nextSibling;
  12917. var pre = hr.previousSibling;
  12918. if(isHr(pre)){
  12919. domUtils.remove(pre);
  12920. }else{
  12921. pre && fillNode(pre);
  12922. }
  12923. if(!nextNode){
  12924. var p = me.document.createElement('p');
  12925. hr.parentNode.appendChild(p);
  12926. domUtils.fillNode(me.document,p);
  12927. range.setStart(p,0).collapse(true);
  12928. }else{
  12929. if(isHr(nextNode)){
  12930. domUtils.remove(nextNode);
  12931. }else{
  12932. fillNode(nextNode);
  12933. }
  12934. range.setEndAfter(hr).collapse(false);
  12935. }
  12936. range.select(true);
  12937. }
  12938. }
  12939. };
  12940. };
  12941. // js/editor/_src/plugins/wordimage.js
  12942. ///import core
  12943. ///commands 本地图片引导上传
  12944. ///commandsName WordImage
  12945. ///commandsTitle 本地图片引导上传
  12946. ///commandsDialog dialogs\wordimage
  12947. UE.plugin.register('wordimage',function(){
  12948. var me = this,
  12949. images = [];
  12950. return {
  12951. commands : {
  12952. 'wordimage':{
  12953. execCommand:function () {
  12954. var images = domUtils.getElementsByTagName(me.body, "img");
  12955. var urlList = [];
  12956. for (var i = 0, ci; ci = images[i++];) {
  12957. var url = ci.getAttribute("word_img");
  12958. url && urlList.push(url);
  12959. }
  12960. return urlList;
  12961. },
  12962. queryCommandState:function () {
  12963. images = domUtils.getElementsByTagName(me.body, "img");
  12964. for (var i = 0, ci; ci = images[i++];) {
  12965. if (ci.getAttribute("word_img")) {
  12966. return 1;
  12967. }
  12968. }
  12969. return -1;
  12970. },
  12971. notNeedUndo:true
  12972. }
  12973. },
  12974. inputRule : function (root) {
  12975. utils.each(root.getNodesByTagName('img'), function (img) {
  12976. var attrs = img.attrs,
  12977. flag = parseInt(attrs.width) < 128 || parseInt(attrs.height) < 43,
  12978. opt = me.options,
  12979. src = opt.UEDITOR_HOME_URL + 'themes/default/images/spacer.gif';
  12980. if (attrs['src'] && /^(?:(file:\/+))/.test(attrs['src'])) {
  12981. img.setAttr({
  12982. width:attrs.width,
  12983. height:attrs.height,
  12984. alt:attrs.alt,
  12985. word_img: attrs.src,
  12986. src:src,
  12987. 'style':'background:url(' + ( flag ? opt.themePath + opt.theme + '/images/word.gif' : opt.langPath + opt.lang + '/images/localimage.png') + ') no-repeat center center;border:1px solid #ddd'
  12988. })
  12989. }
  12990. })
  12991. }
  12992. }
  12993. });
  12994. // js/editor/_src/plugins/dragdrop.js
  12995. UE.plugins['dragdrop'] = function (){
  12996. var me = this;
  12997. me.ready(function(){
  12998. domUtils.on(this.body,'dragend',function(){
  12999. var rng = me.selection.getRange();
  13000. var node = rng.getClosedNode()||me.selection.getStart();
  13001. if(node && node.tagName == 'IMG'){
  13002. var pre = node.previousSibling,next;
  13003. while(next = node.nextSibling){
  13004. if(next.nodeType == 1 && next.tagName == 'SPAN' && !next.firstChild){
  13005. domUtils.remove(next)
  13006. }else{
  13007. break;
  13008. }
  13009. }
  13010. if((pre && pre.nodeType == 1 && !domUtils.isEmptyBlock(pre) || !pre) && (!next || next && !domUtils.isEmptyBlock(next))){
  13011. if(pre && pre.tagName == 'P' && !domUtils.isEmptyBlock(pre)){
  13012. pre.appendChild(node);
  13013. domUtils.moveChild(next,pre);
  13014. domUtils.remove(next);
  13015. }else if(next && next.tagName == 'P' && !domUtils.isEmptyBlock(next)){
  13016. next.insertBefore(node,next.firstChild);
  13017. }
  13018. if(pre && pre.tagName == 'P' && domUtils.isEmptyBlock(pre)){
  13019. domUtils.remove(pre)
  13020. }
  13021. if(next && next.tagName == 'P' && domUtils.isEmptyBlock(next)){
  13022. domUtils.remove(next)
  13023. }
  13024. rng.selectNode(node).select();
  13025. me.fireEvent('saveScene');
  13026. }
  13027. }
  13028. })
  13029. });
  13030. me.addListener('keyup', function(type, evt) {
  13031. var keyCode = evt.keyCode || evt.which;
  13032. if (keyCode == 13) {
  13033. var rng = me.selection.getRange(),node;
  13034. if(node = domUtils.findParentByTagName(rng.startContainer,'p',true)){
  13035. if(domUtils.getComputedStyle(node,'text-align') == 'center'){
  13036. domUtils.removeStyle(node,'text-align')
  13037. }
  13038. }
  13039. }
  13040. })
  13041. };
  13042. // js/editor/_src/plugins/undo.js
  13043. /**
  13044. * undo redo
  13045. * @file
  13046. * @since 1.2.6.1
  13047. */
  13048. /**
  13049. * 撤销上一次执行的命令
  13050. * @command undo
  13051. * @method execCommand
  13052. * @param { String } cmd 命令字符串
  13053. * @example
  13054. * ```javascript
  13055. * editor.execCommand( 'undo' );
  13056. * ```
  13057. */
  13058. /**
  13059. * 重做上一次执行的命令
  13060. * @command redo
  13061. * @method execCommand
  13062. * @param { String } cmd 命令字符串
  13063. * @example
  13064. * ```javascript
  13065. * editor.execCommand( 'redo' );
  13066. * ```
  13067. */
  13068. UE.plugins['undo'] = function () {
  13069. var saveSceneTimer;
  13070. var me = this,
  13071. maxUndoCount = me.options.maxUndoCount || 20,
  13072. maxInputCount = me.options.maxInputCount || 20,
  13073. fillchar = new RegExp(domUtils.fillChar + '|<\/hr>', 'gi');// ie会产生多余的</hr>
  13074. var noNeedFillCharTags = {
  13075. ol:1,ul:1,table:1,tbody:1,tr:1,body:1
  13076. };
  13077. var orgState = me.options.autoClearEmptyNode;
  13078. function compareAddr(indexA, indexB) {
  13079. if (indexA.length != indexB.length)
  13080. return 0;
  13081. for (var i = 0, l = indexA.length; i < l; i++) {
  13082. if (indexA[i] != indexB[i])
  13083. return 0
  13084. }
  13085. return 1;
  13086. }
  13087. function compareRangeAddress(rngAddrA, rngAddrB) {
  13088. if (rngAddrA.collapsed != rngAddrB.collapsed) {
  13089. return 0;
  13090. }
  13091. if (!compareAddr(rngAddrA.startAddress, rngAddrB.startAddress) || !compareAddr(rngAddrA.endAddress, rngAddrB.endAddress)) {
  13092. return 0;
  13093. }
  13094. return 1;
  13095. }
  13096. function UndoManager() {
  13097. this.list = [];
  13098. this.index = 0;
  13099. this.hasUndo = false;
  13100. this.hasRedo = false;
  13101. this.undo = function () {
  13102. if (this.hasUndo) {
  13103. if (!this.list[this.index - 1] && this.list.length == 1) {
  13104. this.reset();
  13105. return;
  13106. }
  13107. while (this.list[this.index].content == this.list[this.index - 1].content) {
  13108. this.index--;
  13109. if (this.index == 0) {
  13110. return this.restore(0);
  13111. }
  13112. }
  13113. this.restore(--this.index);
  13114. }
  13115. };
  13116. this.redo = function () {
  13117. if (this.hasRedo) {
  13118. while (this.list[this.index].content == this.list[this.index + 1].content) {
  13119. this.index++;
  13120. if (this.index == this.list.length - 1) {
  13121. return this.restore(this.index);
  13122. }
  13123. }
  13124. this.restore(++this.index);
  13125. }
  13126. };
  13127. this.restore = function () {
  13128. var me = this.editor;
  13129. var scene = this.list[this.index];
  13130. var root = UE.htmlparser(scene.content.replace(fillchar, ''));
  13131. me.options.autoClearEmptyNode = false;
  13132. me.filterInputRule(root);
  13133. me.options.autoClearEmptyNode = orgState;
  13134. //trace:873
  13135. //去掉展位符
  13136. me.document.body.innerHTML = root.toHtml();
  13137. me.fireEvent('afterscencerestore');
  13138. //处理undo后空格不展位的问题
  13139. if (browser.ie) {
  13140. utils.each(domUtils.getElementsByTagName(me.document,'td th caption p'),function(node){
  13141. if(domUtils.isEmptyNode(node)){
  13142. domUtils.fillNode(me.document, node);
  13143. }
  13144. })
  13145. }
  13146. try{
  13147. var rng = new dom.Range(me.document).moveToAddress(scene.address);
  13148. rng.select(noNeedFillCharTags[rng.startContainer.nodeName.toLowerCase()]);
  13149. }catch(e){}
  13150. this.update();
  13151. this.clearKey();
  13152. //不能把自己reset了
  13153. me.fireEvent('reset', true);
  13154. };
  13155. this.getScene = function () {
  13156. var me = this.editor;
  13157. var rng = me.selection.getRange(),
  13158. rngAddress = rng.createAddress(false,true);
  13159. me.fireEvent('beforegetscene');
  13160. var root = UE.htmlparser(me.body.innerHTML);
  13161. me.options.autoClearEmptyNode = false;
  13162. me.filterOutputRule(root);
  13163. me.options.autoClearEmptyNode = orgState;
  13164. var cont = root.toHtml();
  13165. //trace:3461
  13166. //这个会引起回退时导致空格丢失的情况
  13167. // browser.ie && (cont = cont.replace(/>&nbsp;</g, '><').replace(/\s*</g, '<').replace(/>\s*/g, '>'));
  13168. me.fireEvent('aftergetscene');
  13169. return {
  13170. address:rngAddress,
  13171. content:cont
  13172. }
  13173. };
  13174. this.save = function (notCompareRange,notSetCursor) {
  13175. clearTimeout(saveSceneTimer);
  13176. var currentScene = this.getScene(notSetCursor),
  13177. lastScene = this.list[this.index];
  13178. if(lastScene && lastScene.content != currentScene.content){
  13179. me.trigger('contentchange')
  13180. }
  13181. //内容相同位置相同不存
  13182. if (lastScene && lastScene.content == currentScene.content &&
  13183. ( notCompareRange ? 1 : compareRangeAddress(lastScene.address, currentScene.address) )
  13184. ) {
  13185. return;
  13186. }
  13187. this.list = this.list.slice(0, this.index + 1);
  13188. this.list.push(currentScene);
  13189. //如果大于最大数量了,就把最前的剔除
  13190. if (this.list.length > maxUndoCount) {
  13191. this.list.shift();
  13192. }
  13193. this.index = this.list.length - 1;
  13194. this.clearKey();
  13195. //跟新undo/redo状态
  13196. this.update();
  13197. };
  13198. this.update = function () {
  13199. this.hasRedo = !!this.list[this.index + 1];
  13200. this.hasUndo = !!this.list[this.index - 1];
  13201. };
  13202. this.reset = function () {
  13203. this.list = [];
  13204. this.index = 0;
  13205. this.hasUndo = false;
  13206. this.hasRedo = false;
  13207. this.clearKey();
  13208. };
  13209. this.clearKey = function () {
  13210. keycont = 0;
  13211. lastKeyCode = null;
  13212. };
  13213. }
  13214. me.undoManger = new UndoManager();
  13215. me.undoManger.editor = me;
  13216. function saveScene() {
  13217. this.undoManger.save();
  13218. }
  13219. me.addListener('saveScene', function () {
  13220. var args = Array.prototype.splice.call(arguments,1);
  13221. this.undoManger.save.apply(this.undoManger,args);
  13222. });
  13223. // me.addListener('beforeexeccommand', saveScene);
  13224. // me.addListener('afterexeccommand', saveScene);
  13225. me.addListener('reset', function (type, exclude) {
  13226. if (!exclude) {
  13227. this.undoManger.reset();
  13228. }
  13229. });
  13230. me.commands['redo'] = me.commands['undo'] = {
  13231. execCommand:function (cmdName) {
  13232. this.undoManger[cmdName]();
  13233. },
  13234. queryCommandState:function (cmdName) {
  13235. return this.undoManger['has' + (cmdName.toLowerCase() == 'undo' ? 'Undo' : 'Redo')] ? 0 : -1;
  13236. },
  13237. notNeedUndo:1
  13238. };
  13239. var keys = {
  13240. // /*Backspace*/ 8:1, /*Delete*/ 46:1,
  13241. /*Shift*/ 16:1, /*Ctrl*/ 17:1, /*Alt*/ 18:1,
  13242. 37:1, 38:1, 39:1, 40:1
  13243. },
  13244. keycont = 0,
  13245. lastKeyCode;
  13246. //输入法状态下不计算字符数
  13247. var inputType = false;
  13248. me.addListener('ready', function () {
  13249. domUtils.on(this.body, 'compositionstart', function () {
  13250. inputType = true;
  13251. });
  13252. domUtils.on(this.body, 'compositionend', function () {
  13253. inputType = false;
  13254. })
  13255. });
  13256. //快捷键
  13257. me.addshortcutkey({
  13258. "Undo":"ctrl+90", //undo
  13259. "Redo":"ctrl+89" //redo
  13260. });
  13261. var isCollapsed = true;
  13262. me.addListener('keydown', function (type, evt) {
  13263. var me = this;
  13264. var keyCode = evt.keyCode || evt.which;
  13265. if (!keys[keyCode] && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey) {
  13266. if (inputType)
  13267. return;
  13268. if(!me.selection.getRange().collapsed){
  13269. me.undoManger.save(false,true);
  13270. isCollapsed = false;
  13271. return;
  13272. }
  13273. if (me.undoManger.list.length == 0) {
  13274. me.undoManger.save(true);
  13275. }
  13276. clearTimeout(saveSceneTimer);
  13277. function save(cont){
  13278. cont.undoManger.save(false,true);
  13279. cont.fireEvent('selectionchange');
  13280. }
  13281. saveSceneTimer = setTimeout(function(){
  13282. if(inputType){
  13283. var interalTimer = setInterval(function(){
  13284. if(!inputType){
  13285. save(me);
  13286. clearInterval(interalTimer)
  13287. }
  13288. },300)
  13289. return;
  13290. }
  13291. save(me);
  13292. },200);
  13293. lastKeyCode = keyCode;
  13294. keycont++;
  13295. if (keycont >= maxInputCount ) {
  13296. save(me)
  13297. }
  13298. }
  13299. });
  13300. me.addListener('keyup', function (type, evt) {
  13301. var keyCode = evt.keyCode || evt.which;
  13302. if (!keys[keyCode] && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey) {
  13303. if (inputType)
  13304. return;
  13305. if(!isCollapsed){
  13306. this.undoManger.save(false,true);
  13307. isCollapsed = true;
  13308. }
  13309. }
  13310. });
  13311. //扩展实例,添加关闭和开启命令undo
  13312. me.stopCmdUndo = function(){
  13313. me.__hasEnterExecCommand = true;
  13314. };
  13315. me.startCmdUndo = function(){
  13316. me.__hasEnterExecCommand = false;
  13317. }
  13318. };
  13319. // js/editor/_src/plugins/copy.js
  13320. UE.plugin.register('copy', function () {
  13321. var me = this;
  13322. function initZeroClipboard() {
  13323. ZeroClipboard.config({
  13324. debug: false,
  13325. swfPath: me.options.UEDITOR_HOME_URL + 'third-party/zeroclipboard/ZeroClipboard.swf'
  13326. });
  13327. var client = me.zeroclipboard = new ZeroClipboard();
  13328. // 复制内容
  13329. client.on('copy', function (e) {
  13330. var client = e.client,
  13331. rng = me.selection.getRange(),
  13332. div = document.createElement('div');
  13333. div.appendChild(rng.cloneContents());
  13334. client.setText(div.innerText || div.textContent);
  13335. client.setHtml(div.innerHTML);
  13336. rng.select();
  13337. });
  13338. // hover事件传递到target
  13339. client.on('mouseover mouseout', function (e) {
  13340. var target = e.target;
  13341. if (e.type == 'mouseover') {
  13342. domUtils.addClass(target, 'edui-state-hover');
  13343. } else if (e.type == 'mouseout') {
  13344. domUtils.removeClasses(target, 'edui-state-hover');
  13345. }
  13346. });
  13347. // flash加载不成功
  13348. client.on('wrongflash noflash', function () {
  13349. ZeroClipboard.destroy();
  13350. });
  13351. }
  13352. return {
  13353. bindEvents: {
  13354. 'ready': function () {
  13355. if (!browser.ie) {
  13356. if (window.ZeroClipboard) {
  13357. initZeroClipboard();
  13358. } else {
  13359. utils.loadFile(document, {
  13360. src: me.options.UEDITOR_HOME_URL + "third-party/zeroclipboard/ZeroClipboard.js",
  13361. tag: "script",
  13362. type: "text/javascript",
  13363. defer: "defer"
  13364. }, function () {
  13365. initZeroClipboard();
  13366. });
  13367. }
  13368. }
  13369. }
  13370. },
  13371. commands: {
  13372. 'copy': {
  13373. execCommand: function (cmd) {
  13374. if (!me.document.execCommand('copy')) {
  13375. alert(me.getLang('copymsg'));
  13376. }
  13377. }
  13378. }
  13379. }
  13380. }
  13381. });
  13382. // js/editor/_src/plugins/paste.js
  13383. ///import core
  13384. ///import plugins/inserthtml.js
  13385. ///import plugins/undo.js
  13386. ///import plugins/serialize.js
  13387. ///commands 粘贴
  13388. ///commandsName PastePlain
  13389. ///commandsTitle 纯文本粘贴模式
  13390. /**
  13391. * @description 粘贴
  13392. * @author zhanyi
  13393. */
  13394. UE.plugins['paste'] = function () {
  13395. function getClipboardData(callback) {
  13396. var doc = this.document;
  13397. if (doc.getElementById('baidu_pastebin')) {
  13398. return;
  13399. }
  13400. var range = this.selection.getRange(),
  13401. bk = range.createBookmark(),
  13402. //创建剪贴的容器div
  13403. pastebin = doc.createElement('div');
  13404. pastebin.id = 'baidu_pastebin';
  13405. // Safari 要求div必须有内容,才能粘贴内容进来
  13406. browser.webkit && pastebin.appendChild(doc.createTextNode(domUtils.fillChar + domUtils.fillChar));
  13407. doc.body.appendChild(pastebin);
  13408. //trace:717 隐藏的span不能得到top
  13409. //bk.start.innerHTML = '&nbsp;';
  13410. bk.start.style.display = '';
  13411. pastebin.style.cssText = "position:absolute;width:1px;height:1px;overflow:hidden;left:-1000px;white-space:nowrap;top:" +
  13412. //要在现在光标平行的位置加入,否则会出现跳动的问题
  13413. domUtils.getXY(bk.start).y + 'px';
  13414. range.selectNodeContents(pastebin).select(true);
  13415. setTimeout(function () {
  13416. if (browser.webkit) {
  13417. for (var i = 0, pastebins = doc.querySelectorAll('#baidu_pastebin'), pi; pi = pastebins[i++];) {
  13418. if (domUtils.isEmptyNode(pi)) {
  13419. domUtils.remove(pi);
  13420. } else {
  13421. pastebin = pi;
  13422. break;
  13423. }
  13424. }
  13425. }
  13426. try {
  13427. pastebin.parentNode.removeChild(pastebin);
  13428. } catch (e) {
  13429. }
  13430. range.moveToBookmark(bk).select(true);
  13431. callback(pastebin);
  13432. }, 0);
  13433. }
  13434. var me = this;
  13435. me.setOpt({
  13436. retainOnlyLabelPasted : false
  13437. });
  13438. var txtContent, htmlContent, address;
  13439. function getPureHtml(html){
  13440. return html.replace(/<(\/?)([\w\-]+)([^>]*)>/gi, function (a, b, tagName, attrs) {
  13441. tagName = tagName.toLowerCase();
  13442. if ({img: 1}[tagName]) {
  13443. return a;
  13444. }
  13445. attrs = attrs.replace(/([\w\-]*?)\s*=\s*(("([^"]*)")|('([^']*)')|([^\s>]+))/gi, function (str, atr, val) {
  13446. if ({
  13447. 'src': 1,
  13448. 'href': 1,
  13449. 'name': 1
  13450. }[atr.toLowerCase()]) {
  13451. return atr + '=' + val + ' '
  13452. }
  13453. return ''
  13454. });
  13455. if ({
  13456. 'span': 1,
  13457. 'div': 1
  13458. }[tagName]) {
  13459. return ''
  13460. } else {
  13461. return '<' + b + tagName + ' ' + utils.trim(attrs) + '>'
  13462. }
  13463. });
  13464. }
  13465. function filter(div) {
  13466. var html;
  13467. if (div.firstChild) {
  13468. //去掉cut中添加的边界值
  13469. var nodes = domUtils.getElementsByTagName(div, 'span');
  13470. for (var i = 0, ni; ni = nodes[i++];) {
  13471. if (ni.id == '_baidu_cut_start' || ni.id == '_baidu_cut_end') {
  13472. domUtils.remove(ni);
  13473. }
  13474. }
  13475. if (browser.webkit) {
  13476. var brs = div.querySelectorAll('div br');
  13477. for (var i = 0, bi; bi = brs[i++];) {
  13478. var pN = bi.parentNode;
  13479. if (pN.tagName == 'DIV' && pN.childNodes.length == 1) {
  13480. pN.innerHTML = '<p><br/></p>';
  13481. domUtils.remove(pN);
  13482. }
  13483. }
  13484. var divs = div.querySelectorAll('#baidu_pastebin');
  13485. for (var i = 0, di; di = divs[i++];) {
  13486. var tmpP = me.document.createElement('p');
  13487. di.parentNode.insertBefore(tmpP, di);
  13488. while (di.firstChild) {
  13489. tmpP.appendChild(di.firstChild);
  13490. }
  13491. domUtils.remove(di);
  13492. }
  13493. var metas = div.querySelectorAll('meta');
  13494. for (var i = 0, ci; ci = metas[i++];) {
  13495. domUtils.remove(ci);
  13496. }
  13497. var brs = div.querySelectorAll('br');
  13498. for (i = 0; ci = brs[i++];) {
  13499. if (/^apple-/i.test(ci.className)) {
  13500. domUtils.remove(ci);
  13501. }
  13502. }
  13503. }
  13504. if (browser.gecko) {
  13505. var dirtyNodes = div.querySelectorAll('[_moz_dirty]');
  13506. for (i = 0; ci = dirtyNodes[i++];) {
  13507. ci.removeAttribute('_moz_dirty');
  13508. }
  13509. }
  13510. if (!browser.ie) {
  13511. var spans = div.querySelectorAll('span.Apple-style-span');
  13512. for (var i = 0, ci; ci = spans[i++];) {
  13513. domUtils.remove(ci, true);
  13514. }
  13515. }
  13516. //ie下使用innerHTML会产生多余的\r\n字符,也会产生&nbsp;这里过滤掉
  13517. html = div.innerHTML;//.replace(/>(?:(\s|&nbsp;)*?)</g,'><');
  13518. //过滤word粘贴过来的冗余属性
  13519. html = UE.filterWord(html);
  13520. //取消了忽略空白的第二个参数,粘贴过来的有些是有空白的,会被套上相关的标签
  13521. var root = UE.htmlparser(html);
  13522. //如果给了过滤规则就先进行过滤
  13523. if (me.options.filterRules) {
  13524. UE.filterNode(root, me.options.filterRules);
  13525. }
  13526. //执行默认的处理
  13527. me.filterInputRule(root);
  13528. //针对chrome的处理
  13529. if (browser.webkit) {
  13530. var br = root.lastChild();
  13531. if (br && br.type == 'element' && br.tagName == 'br') {
  13532. root.removeChild(br)
  13533. }
  13534. utils.each(me.body.querySelectorAll('div'), function (node) {
  13535. if (domUtils.isEmptyBlock(node)) {
  13536. domUtils.remove(node,true)
  13537. }
  13538. })
  13539. }
  13540. html = {'html': root.toHtml()};
  13541. me.fireEvent('beforepaste', html, root);
  13542. //抢了默认的粘贴,那后边的内容就不执行了,比如表格粘贴
  13543. if(!html.html){
  13544. return;
  13545. }
  13546. root = UE.htmlparser(html.html,true);
  13547. //如果开启了纯文本模式
  13548. if (me.queryCommandState('pasteplain') === 1) {
  13549. me.execCommand('insertHtml', UE.filterNode(root, me.options.filterTxtRules).toHtml(), true);
  13550. } else {
  13551. //文本模式
  13552. UE.filterNode(root, me.options.filterTxtRules);
  13553. txtContent = root.toHtml();
  13554. //完全模式
  13555. htmlContent = html.html;
  13556. address = me.selection.getRange().createAddress(true);
  13557. me.execCommand('insertHtml', me.getOpt('retainOnlyLabelPasted') === true ? getPureHtml(htmlContent) : htmlContent, true);
  13558. }
  13559. me.fireEvent("afterpaste", html);
  13560. }
  13561. }
  13562. me.addListener('pasteTransfer', function (cmd, plainType) {
  13563. if (address && txtContent && htmlContent && txtContent != htmlContent) {
  13564. var range = me.selection.getRange();
  13565. range.moveToAddress(address, true);
  13566. if (!range.collapsed) {
  13567. while (!domUtils.isBody(range.startContainer)
  13568. ) {
  13569. var start = range.startContainer;
  13570. if(start.nodeType == 1){
  13571. start = start.childNodes[range.startOffset];
  13572. if(!start){
  13573. range.setStartBefore(range.startContainer);
  13574. continue;
  13575. }
  13576. var pre = start.previousSibling;
  13577. if(pre && pre.nodeType == 3 && new RegExp('^[\n\r\t '+domUtils.fillChar+']*$').test(pre.nodeValue)){
  13578. range.setStartBefore(pre)
  13579. }
  13580. }
  13581. if(range.startOffset == 0){
  13582. range.setStartBefore(range.startContainer);
  13583. }else{
  13584. break;
  13585. }
  13586. }
  13587. while (!domUtils.isBody(range.endContainer)
  13588. ) {
  13589. var end = range.endContainer;
  13590. if(end.nodeType == 1){
  13591. end = end.childNodes[range.endOffset];
  13592. if(!end){
  13593. range.setEndAfter(range.endContainer);
  13594. continue;
  13595. }
  13596. var next = end.nextSibling;
  13597. if(next && next.nodeType == 3 && new RegExp('^[\n\r\t'+domUtils.fillChar+']*$').test(next.nodeValue)){
  13598. range.setEndAfter(next)
  13599. }
  13600. }
  13601. if(range.endOffset == range.endContainer[range.endContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length){
  13602. range.setEndAfter(range.endContainer);
  13603. }else{
  13604. break;
  13605. }
  13606. }
  13607. }
  13608. range.deleteContents();
  13609. range.select(true);
  13610. me.__hasEnterExecCommand = true;
  13611. var html = htmlContent;
  13612. if (plainType === 2 ) {
  13613. html = getPureHtml(html);
  13614. } else if (plainType) {
  13615. html = txtContent;
  13616. }
  13617. me.execCommand('inserthtml', html, true);
  13618. me.__hasEnterExecCommand = false;
  13619. var rng = me.selection.getRange();
  13620. while (!domUtils.isBody(rng.startContainer) && !rng.startOffset &&
  13621. rng.startContainer[rng.startContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length
  13622. ) {
  13623. rng.setStartBefore(rng.startContainer);
  13624. }
  13625. var tmpAddress = rng.createAddress(true);
  13626. address.endAddress = tmpAddress.startAddress;
  13627. }
  13628. });
  13629. me.addListener('ready', function () {
  13630. domUtils.on(me.body, 'cut', function () {
  13631. var range = me.selection.getRange();
  13632. if (!range.collapsed && me.undoManger) {
  13633. me.undoManger.save();
  13634. }
  13635. });
  13636. //ie下beforepaste在点击右键时也会触发,所以用监控键盘才处理
  13637. domUtils.on(me.body, browser.ie || browser.opera ? 'keydown' : 'paste', function (e) {
  13638. if ((browser.ie || browser.opera) && ((!e.ctrlKey && !e.metaKey) || e.keyCode != '86')) {
  13639. return;
  13640. }
  13641. getClipboardData.call(me, function (div) {
  13642. filter(div);
  13643. });
  13644. });
  13645. });
  13646. me.commands['paste'] = {
  13647. execCommand: function (cmd) {
  13648. if (browser.ie) {
  13649. getClipboardData.call(me, function (div) {
  13650. filter(div);
  13651. });
  13652. me.document.execCommand('paste');
  13653. } else {
  13654. alert(me.getLang('pastemsg'));
  13655. }
  13656. }
  13657. }
  13658. };
  13659. // js/editor/_src/plugins/puretxtpaste.js
  13660. /**
  13661. * 纯文本粘贴插件
  13662. * @file
  13663. * @since 1.2.6.1
  13664. */
  13665. UE.plugins['pasteplain'] = function(){
  13666. var me = this;
  13667. me.setOpt({
  13668. 'pasteplain':false,
  13669. 'filterTxtRules' : function(){
  13670. function transP(node){
  13671. node.tagName = 'p';
  13672. node.setStyle();
  13673. }
  13674. function removeNode(node){
  13675. node.parentNode.removeChild(node,true)
  13676. }
  13677. return {
  13678. //直接删除及其字节点内容
  13679. '-' : 'script style object iframe embed input select',
  13680. 'p': {$:{}},
  13681. 'br':{$:{}},
  13682. div: function (node) {
  13683. var tmpNode, p = UE.uNode.createElement('p');
  13684. while (tmpNode = node.firstChild()) {
  13685. if (tmpNode.type == 'text' || !UE.dom.dtd.$block[tmpNode.tagName]) {
  13686. p.appendChild(tmpNode);
  13687. } else {
  13688. if (p.firstChild()) {
  13689. node.parentNode.insertBefore(p, node);
  13690. p = UE.uNode.createElement('p');
  13691. } else {
  13692. node.parentNode.insertBefore(tmpNode, node);
  13693. }
  13694. }
  13695. }
  13696. if (p.firstChild()) {
  13697. node.parentNode.insertBefore(p, node);
  13698. }
  13699. node.parentNode.removeChild(node);
  13700. },
  13701. ol: removeNode,
  13702. ul: removeNode,
  13703. dl:removeNode,
  13704. dt:removeNode,
  13705. dd:removeNode,
  13706. 'li':removeNode,
  13707. 'caption':transP,
  13708. 'th':transP,
  13709. 'tr':transP,
  13710. 'h1':transP,'h2':transP,'h3':transP,'h4':transP,'h5':transP,'h6':transP,
  13711. 'td':function(node){
  13712. //没有内容的td直接删掉
  13713. var txt = !!node.innerText();
  13714. if(txt){
  13715. node.parentNode.insertAfter(UE.uNode.createText(' &nbsp; &nbsp;'),node);
  13716. }
  13717. node.parentNode.removeChild(node,node.innerText())
  13718. }
  13719. }
  13720. }()
  13721. });
  13722. //暂时这里支持一下老版本的属性
  13723. var pasteplain = me.options.pasteplain;
  13724. /**
  13725. * 启用或取消纯文本粘贴模式
  13726. * @command pasteplain
  13727. * @method execCommand
  13728. * @param { String } cmd 命令字符串
  13729. * @example
  13730. * ```javascript
  13731. * editor.queryCommandState( 'pasteplain' );
  13732. * ```
  13733. */
  13734. /**
  13735. * 查询当前是否处于纯文本粘贴模式
  13736. * @command pasteplain
  13737. * @method queryCommandState
  13738. * @param { String } cmd 命令字符串
  13739. * @return { int } 如果处于纯文本模式,返回1,否则,返回0
  13740. * @example
  13741. * ```javascript
  13742. * editor.queryCommandState( 'pasteplain' );
  13743. * ```
  13744. */
  13745. me.commands['pasteplain'] = {
  13746. queryCommandState: function (){
  13747. return pasteplain ? 1 : 0;
  13748. },
  13749. execCommand: function (){
  13750. pasteplain = !pasteplain|0;
  13751. },
  13752. notNeedUndo : 1
  13753. };
  13754. };
  13755. // js/editor/_src/plugins/list.js
  13756. /**
  13757. * 有序列表,无序列表插件
  13758. * @file
  13759. * @since 1.2.6.1
  13760. */
  13761. UE.plugins['list'] = function () {
  13762. var me = this,
  13763. notExchange = {
  13764. 'TD':1,
  13765. 'PRE':1,
  13766. 'BLOCKQUOTE':1
  13767. };
  13768. var customStyle = {
  13769. 'cn' : 'cn-1-',
  13770. 'cn1' : 'cn-2-',
  13771. 'cn2' : 'cn-3-',
  13772. 'num': 'num-1-',
  13773. 'num1' : 'num-2-',
  13774. 'num2' : 'num-3-',
  13775. 'dash' : 'dash',
  13776. 'dot':'dot'
  13777. };
  13778. me.setOpt( {
  13779. 'autoTransWordToList':false,
  13780. 'insertorderedlist':{
  13781. 'num':'',
  13782. 'num1':'',
  13783. 'num2':'',
  13784. 'cn':'',
  13785. 'cn1':'',
  13786. 'cn2':'',
  13787. 'decimal':'',
  13788. 'lower-alpha':'',
  13789. 'lower-roman':'',
  13790. 'upper-alpha':'',
  13791. 'upper-roman':''
  13792. },
  13793. 'insertunorderedlist':{
  13794. 'circle':'',
  13795. 'disc':'',
  13796. 'square':'',
  13797. 'dash' : '',
  13798. 'dot':''
  13799. },
  13800. listDefaultPaddingLeft : '30',
  13801. listiconpath : 'http://bs.baidu.com/listicon/',
  13802. maxListLevel : -1,//-1不限制
  13803. disablePInList:false
  13804. } );
  13805. function listToArray(list){
  13806. var arr = [];
  13807. for(var p in list){
  13808. arr.push(p)
  13809. }
  13810. return arr;
  13811. }
  13812. var listStyle = {
  13813. 'OL':listToArray(me.options.insertorderedlist),
  13814. 'UL':listToArray(me.options.insertunorderedlist)
  13815. };
  13816. var liiconpath = me.options.listiconpath;
  13817. //根据用户配置,调整customStyle
  13818. for(var s in customStyle){
  13819. if(!me.options.insertorderedlist.hasOwnProperty(s) && !me.options.insertunorderedlist.hasOwnProperty(s)){
  13820. delete customStyle[s];
  13821. }
  13822. }
  13823. me.ready(function () {
  13824. var customCss = [];
  13825. for(var p in customStyle){
  13826. if(p == 'dash' || p == 'dot'){
  13827. customCss.push('li.list-' + customStyle[p] + '{background-image:url(' + liiconpath +customStyle[p]+'.gif)}');
  13828. customCss.push('ul.custom_'+p+'{list-style:none;}ul.custom_'+p+' li{background-position:0 3px;background-repeat:no-repeat}');
  13829. }else{
  13830. for(var i= 0;i<99;i++){
  13831. customCss.push('li.list-' + customStyle[p] + i + '{background-image:url(' + liiconpath + 'list-'+customStyle[p] + i + '.gif)}')
  13832. }
  13833. customCss.push('ol.custom_'+p+'{list-style:none;}ol.custom_'+p+' li{background-position:0 3px;background-repeat:no-repeat}');
  13834. }
  13835. switch(p){
  13836. case 'cn':
  13837. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:25px}');
  13838. customCss.push('li.list-'+p+'-paddingleft-2{padding-left:40px}');
  13839. customCss.push('li.list-'+p+'-paddingleft-3{padding-left:55px}');
  13840. break;
  13841. case 'cn1':
  13842. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:30px}');
  13843. customCss.push('li.list-'+p+'-paddingleft-2{padding-left:40px}');
  13844. customCss.push('li.list-'+p+'-paddingleft-3{padding-left:55px}');
  13845. break;
  13846. case 'cn2':
  13847. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:40px}');
  13848. customCss.push('li.list-'+p+'-paddingleft-2{padding-left:55px}');
  13849. customCss.push('li.list-'+p+'-paddingleft-3{padding-left:68px}');
  13850. break;
  13851. case 'num':
  13852. case 'num1':
  13853. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:25px}');
  13854. break;
  13855. case 'num2':
  13856. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:35px}');
  13857. customCss.push('li.list-'+p+'-paddingleft-2{padding-left:40px}');
  13858. break;
  13859. case 'dash':
  13860. customCss.push('li.list-'+p+'-paddingleft{padding-left:35px}');
  13861. break;
  13862. case 'dot':
  13863. customCss.push('li.list-'+p+'-paddingleft{padding-left:20px}');
  13864. }
  13865. }
  13866. customCss.push('.list-paddingleft-1{padding-left:0}');
  13867. customCss.push('.list-paddingleft-2{padding-left:'+me.options.listDefaultPaddingLeft+'px}');
  13868. customCss.push('.list-paddingleft-3{padding-left:'+me.options.listDefaultPaddingLeft*2+'px}');
  13869. //如果不给宽度会在自定应样式里出现滚动条
  13870. utils.cssRule('list', 'ol,ul{margin:0;pading:0;'+(browser.ie ? '' : 'width:95%')+'}li{clear:both;}'+customCss.join('\n'), me.document);
  13871. });
  13872. //单独处理剪切的问题
  13873. me.ready(function(){
  13874. domUtils.on(me.body,'cut',function(){
  13875. setTimeout(function(){
  13876. var rng = me.selection.getRange(),li;
  13877. //trace:3416
  13878. if(!rng.collapsed){
  13879. if(li = domUtils.findParentByTagName(rng.startContainer,'li',true)){
  13880. if(!li.nextSibling && domUtils.isEmptyBlock(li)){
  13881. var pn = li.parentNode,node;
  13882. if(node = pn.previousSibling){
  13883. domUtils.remove(pn);
  13884. rng.setStartAtLast(node).collapse(true);
  13885. rng.select(true);
  13886. }else if(node = pn.nextSibling){
  13887. domUtils.remove(pn);
  13888. rng.setStartAtFirst(node).collapse(true);
  13889. rng.select(true);
  13890. }else{
  13891. var tmpNode = me.document.createElement('p');
  13892. domUtils.fillNode(me.document,tmpNode);
  13893. pn.parentNode.insertBefore(tmpNode,pn);
  13894. domUtils.remove(pn);
  13895. rng.setStart(tmpNode,0).collapse(true);
  13896. rng.select(true);
  13897. }
  13898. }
  13899. }
  13900. }
  13901. })
  13902. })
  13903. });
  13904. function getStyle(node){
  13905. var cls = node.className;
  13906. if(domUtils.hasClass(node,/custom_/)){
  13907. return cls.match(/custom_(\w+)/)[1]
  13908. }
  13909. return domUtils.getStyle(node, 'list-style-type')
  13910. }
  13911. me.addListener('beforepaste',function(type,html){
  13912. var me = this,
  13913. rng = me.selection.getRange(),li;
  13914. var root = UE.htmlparser(html.html,true);
  13915. if(li = domUtils.findParentByTagName(rng.startContainer,'li',true)){
  13916. var list = li.parentNode,tagName = list.tagName == 'OL' ? 'ul':'ol';
  13917. utils.each(root.getNodesByTagName(tagName),function(n){
  13918. n.tagName = list.tagName;
  13919. n.setAttr();
  13920. if(n.parentNode === root){
  13921. type = getStyle(list) || (list.tagName == 'OL' ? 'decimal' : 'disc')
  13922. }else{
  13923. var className = n.parentNode.getAttr('class');
  13924. if(className && /custom_/.test(className)){
  13925. type = className.match(/custom_(\w+)/)[1]
  13926. }else{
  13927. type = n.parentNode.getStyle('list-style-type');
  13928. }
  13929. if(!type){
  13930. type = list.tagName == 'OL' ? 'decimal' : 'disc';
  13931. }
  13932. }
  13933. var index = utils.indexOf(listStyle[list.tagName], type);
  13934. if(n.parentNode !== root)
  13935. index = index + 1 == listStyle[list.tagName].length ? 0 : index + 1;
  13936. var currentStyle = listStyle[list.tagName][index];
  13937. if(customStyle[currentStyle]){
  13938. n.setAttr('class', 'custom_' + currentStyle)
  13939. }else{
  13940. n.setStyle('list-style-type',currentStyle)
  13941. }
  13942. })
  13943. }
  13944. html.html = root.toHtml();
  13945. });
  13946. //导出时,去掉p标签
  13947. me.getOpt('disablePInList') === true && me.addOutputRule(function(root){
  13948. utils.each(root.getNodesByTagName('li'),function(li){
  13949. var newChildrens = [],index=0;
  13950. utils.each(li.children,function(n){
  13951. if(n.tagName == 'p'){
  13952. var tmpNode;
  13953. while(tmpNode = n.children.pop()) {
  13954. newChildrens.splice(index,0,tmpNode);
  13955. tmpNode.parentNode = li;
  13956. lastNode = tmpNode;
  13957. }
  13958. tmpNode = newChildrens[newChildrens.length-1];
  13959. if(!tmpNode || tmpNode.type != 'element' || tmpNode.tagName != 'br'){
  13960. var br = UE.uNode.createElement('br');
  13961. br.parentNode = li;
  13962. newChildrens.push(br);
  13963. }
  13964. index = newChildrens.length;
  13965. }
  13966. });
  13967. if(newChildrens.length){
  13968. li.children = newChildrens;
  13969. }
  13970. });
  13971. });
  13972. //进入编辑器的li要套p标签
  13973. me.addInputRule(function(root){
  13974. utils.each(root.getNodesByTagName('li'),function(li){
  13975. var tmpP = UE.uNode.createElement('p');
  13976. for(var i= 0,ci;ci=li.children[i];){
  13977. if(ci.type == 'text' || dtd.p[ci.tagName]){
  13978. tmpP.appendChild(ci);
  13979. }else{
  13980. if(tmpP.firstChild()){
  13981. li.insertBefore(tmpP,ci);
  13982. tmpP = UE.uNode.createElement('p');
  13983. i = i + 2;
  13984. }else{
  13985. i++;
  13986. }
  13987. }
  13988. }
  13989. if(tmpP.firstChild() && !tmpP.parentNode || !li.firstChild()){
  13990. li.appendChild(tmpP);
  13991. }
  13992. //trace:3357
  13993. //p不能为空
  13994. if (!tmpP.firstChild()) {
  13995. tmpP.innerHTML(browser.ie ? '&nbsp;' : '<br/>')
  13996. }
  13997. //去掉末尾的空白
  13998. var p = li.firstChild();
  13999. var lastChild = p.lastChild();
  14000. if(lastChild && lastChild.type == 'text' && /^\s*$/.test(lastChild.data)){
  14001. p.removeChild(lastChild)
  14002. }
  14003. });
  14004. if(me.options.autoTransWordToList){
  14005. var orderlisttype = {
  14006. 'num1':/^\d+\)/,
  14007. 'decimal':/^\d+\./,
  14008. 'lower-alpha':/^[a-z]+\)/,
  14009. 'upper-alpha':/^[A-Z]+\./,
  14010. 'cn':/^[\u4E00\u4E8C\u4E09\u56DB\u516d\u4e94\u4e03\u516b\u4e5d]+[\u3001]/,
  14011. 'cn2':/^\([\u4E00\u4E8C\u4E09\u56DB\u516d\u4e94\u4e03\u516b\u4e5d]+\)/
  14012. },
  14013. unorderlisttype = {
  14014. 'square':'n'
  14015. };
  14016. function checkListType(content,container){
  14017. var span = container.firstChild();
  14018. if(span && span.type == 'element' && span.tagName == 'span' && /Wingdings|Symbol/.test(span.getStyle('font-family'))){
  14019. for(var p in unorderlisttype){
  14020. if(unorderlisttype[p] == span.data){
  14021. return p
  14022. }
  14023. }
  14024. return 'disc'
  14025. }
  14026. for(var p in orderlisttype){
  14027. if(orderlisttype[p].test(content)){
  14028. return p;
  14029. }
  14030. }
  14031. }
  14032. utils.each(root.getNodesByTagName('p'),function(node){
  14033. if(node.getAttr('class') != 'MsoListParagraph'){
  14034. return
  14035. }
  14036. //word粘贴过来的会带有margin要去掉,但这样也可能会误命中一些央视
  14037. node.setStyle('margin','');
  14038. node.setStyle('margin-left','');
  14039. node.setAttr('class','');
  14040. function appendLi(list,p,type){
  14041. if(list.tagName == 'ol'){
  14042. if(browser.ie){
  14043. var first = p.firstChild();
  14044. if(first.type =='element' && first.tagName == 'span' && orderlisttype[type].test(first.innerText())){
  14045. p.removeChild(first);
  14046. }
  14047. }else{
  14048. p.innerHTML(p.innerHTML().replace(orderlisttype[type],''));
  14049. }
  14050. }else{
  14051. p.removeChild(p.firstChild())
  14052. }
  14053. var li = UE.uNode.createElement('li');
  14054. li.appendChild(p);
  14055. list.appendChild(li);
  14056. }
  14057. var tmp = node,type,cacheNode = node;
  14058. if(node.parentNode.tagName != 'li' && (type = checkListType(node.innerText(),node))){
  14059. var list = UE.uNode.createElement(me.options.insertorderedlist.hasOwnProperty(type) ? 'ol' : 'ul');
  14060. if(customStyle[type]){
  14061. list.setAttr('class','custom_'+type)
  14062. }else{
  14063. list.setStyle('list-style-type',type)
  14064. }
  14065. while(node && node.parentNode.tagName != 'li' && checkListType(node.innerText(),node)){
  14066. tmp = node.nextSibling();
  14067. if(!tmp){
  14068. node.parentNode.insertBefore(list,node)
  14069. }
  14070. appendLi(list,node,type);
  14071. node = tmp;
  14072. }
  14073. if(!list.parentNode && node && node.parentNode){
  14074. node.parentNode.insertBefore(list,node)
  14075. }
  14076. }
  14077. var span = cacheNode.firstChild();
  14078. if(span && span.type == 'element' && span.tagName == 'span' && /^\s*(&nbsp;)+\s*$/.test(span.innerText())){
  14079. span.parentNode.removeChild(span)
  14080. }
  14081. })
  14082. }
  14083. });
  14084. //调整索引标签
  14085. me.addListener('contentchange',function(){
  14086. adjustListStyle(me.document)
  14087. });
  14088. function adjustListStyle(doc,ignore){
  14089. utils.each(domUtils.getElementsByTagName(doc,'ol ul'),function(node){
  14090. if(!domUtils.inDoc(node,doc))
  14091. return;
  14092. var parent = node.parentNode;
  14093. if(parent.tagName == node.tagName){
  14094. var nodeStyleType = getStyle(node) || (node.tagName == 'OL' ? 'decimal' : 'disc'),
  14095. parentStyleType = getStyle(parent) || (parent.tagName == 'OL' ? 'decimal' : 'disc');
  14096. if(nodeStyleType == parentStyleType){
  14097. var styleIndex = utils.indexOf(listStyle[node.tagName], nodeStyleType);
  14098. styleIndex = styleIndex + 1 == listStyle[node.tagName].length ? 0 : styleIndex + 1;
  14099. setListStyle(node,listStyle[node.tagName][styleIndex])
  14100. }
  14101. }
  14102. var index = 0,type = 2;
  14103. if( domUtils.hasClass(node,/custom_/)){
  14104. if(!(/[ou]l/i.test(parent.tagName) && domUtils.hasClass(parent,/custom_/))){
  14105. type = 1;
  14106. }
  14107. }else{
  14108. if(/[ou]l/i.test(parent.tagName) && domUtils.hasClass(parent,/custom_/)){
  14109. type = 3;
  14110. }
  14111. }
  14112. var style = domUtils.getStyle(node, 'list-style-type');
  14113. style && (node.style.cssText = 'list-style-type:' + style);
  14114. node.className = utils.trim(node.className.replace(/list-paddingleft-\w+/,'')) + ' list-paddingleft-' + type;
  14115. utils.each(domUtils.getElementsByTagName(node,'li'),function(li){
  14116. li.style.cssText && (li.style.cssText = '');
  14117. if(!li.firstChild){
  14118. domUtils.remove(li);
  14119. return;
  14120. }
  14121. if(li.parentNode !== node){
  14122. return;
  14123. }
  14124. index++;
  14125. if(domUtils.hasClass(node,/custom_/) ){
  14126. var paddingLeft = 1,currentStyle = getStyle(node);
  14127. if(node.tagName == 'OL'){
  14128. if(currentStyle){
  14129. switch(currentStyle){
  14130. case 'cn' :
  14131. case 'cn1':
  14132. case 'cn2':
  14133. if(index > 10 && (index % 10 == 0 || index > 10 && index < 20)){
  14134. paddingLeft = 2
  14135. }else if(index > 20){
  14136. paddingLeft = 3
  14137. }
  14138. break;
  14139. case 'num2' :
  14140. if(index > 9){
  14141. paddingLeft = 2
  14142. }
  14143. }
  14144. }
  14145. li.className = 'list-'+customStyle[currentStyle]+ index + ' ' + 'list-'+currentStyle+'-paddingleft-' + paddingLeft;
  14146. }else{
  14147. li.className = 'list-'+customStyle[currentStyle] + ' ' + 'list-'+currentStyle+'-paddingleft';
  14148. }
  14149. }else{
  14150. li.className = li.className.replace(/list-[\w\-]+/gi,'');
  14151. }
  14152. var className = li.getAttribute('class');
  14153. if(className !== null && !className.replace(/\s/g,'')){
  14154. domUtils.removeAttributes(li,'class')
  14155. }
  14156. });
  14157. !ignore && adjustList(node,node.tagName.toLowerCase(),getStyle(node)||domUtils.getStyle(node, 'list-style-type'),true);
  14158. })
  14159. }
  14160. function adjustList(list, tag, style,ignoreEmpty) {
  14161. var nextList = list.nextSibling;
  14162. if (nextList && nextList.nodeType == 1 && nextList.tagName.toLowerCase() == tag && (getStyle(nextList) || domUtils.getStyle(nextList, 'list-style-type') || (tag == 'ol' ? 'decimal' : 'disc')) == style) {
  14163. domUtils.moveChild(nextList, list);
  14164. if (nextList.childNodes.length == 0) {
  14165. domUtils.remove(nextList);
  14166. }
  14167. }
  14168. if(nextList && domUtils.isFillChar(nextList)){
  14169. domUtils.remove(nextList);
  14170. }
  14171. var preList = list.previousSibling;
  14172. if (preList && preList.nodeType == 1 && preList.tagName.toLowerCase() == tag && (getStyle(preList) || domUtils.getStyle(preList, 'list-style-type') || (tag == 'ol' ? 'decimal' : 'disc')) == style) {
  14173. domUtils.moveChild(list, preList);
  14174. }
  14175. if(preList && domUtils.isFillChar(preList)){
  14176. domUtils.remove(preList);
  14177. }
  14178. !ignoreEmpty && domUtils.isEmptyBlock(list) && domUtils.remove(list);
  14179. if(getStyle(list)){
  14180. adjustListStyle(list.ownerDocument,true)
  14181. }
  14182. }
  14183. function setListStyle(list,style){
  14184. if(customStyle[style]){
  14185. list.className = 'custom_' + style;
  14186. }
  14187. try{
  14188. domUtils.setStyle(list, 'list-style-type', style);
  14189. }catch(e){}
  14190. }
  14191. function clearEmptySibling(node) {
  14192. var tmpNode = node.previousSibling;
  14193. if (tmpNode && domUtils.isEmptyBlock(tmpNode)) {
  14194. domUtils.remove(tmpNode);
  14195. }
  14196. tmpNode = node.nextSibling;
  14197. if (tmpNode && domUtils.isEmptyBlock(tmpNode)) {
  14198. domUtils.remove(tmpNode);
  14199. }
  14200. }
  14201. me.addListener('keydown', function (type, evt) {
  14202. function preventAndSave() {
  14203. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  14204. me.fireEvent('contentchange');
  14205. me.undoManger && me.undoManger.save();
  14206. }
  14207. function findList(node,filterFn){
  14208. while(node && !domUtils.isBody(node)){
  14209. if(filterFn(node)){
  14210. return null
  14211. }
  14212. if(node.nodeType == 1 && /[ou]l/i.test(node.tagName)){
  14213. return node;
  14214. }
  14215. node = node.parentNode;
  14216. }
  14217. return null;
  14218. }
  14219. var keyCode = evt.keyCode || evt.which;
  14220. if (keyCode == 13 && !evt.shiftKey) {//回车
  14221. var rng = me.selection.getRange(),
  14222. parent = domUtils.findParent(rng.startContainer,function(node){return domUtils.isBlockElm(node)},true),
  14223. li = domUtils.findParentByTagName(rng.startContainer,'li',true);
  14224. if(parent && parent.tagName != 'PRE' && !li){
  14225. var html = parent.innerHTML.replace(new RegExp(domUtils.fillChar, 'g'),'');
  14226. if(/^\s*1\s*\.[^\d]/.test(html)){
  14227. parent.innerHTML = html.replace(/^\s*1\s*\./,'');
  14228. rng.setStartAtLast(parent).collapse(true).select();
  14229. me.__hasEnterExecCommand = true;
  14230. me.execCommand('insertorderedlist');
  14231. me.__hasEnterExecCommand = false;
  14232. }
  14233. }
  14234. var range = me.selection.getRange(),
  14235. start = findList(range.startContainer,function (node) {
  14236. return node.tagName == 'TABLE';
  14237. }),
  14238. end = range.collapsed ? start : findList(range.endContainer,function (node) {
  14239. return node.tagName == 'TABLE';
  14240. });
  14241. if (start && end && start === end) {
  14242. if (!range.collapsed) {
  14243. start = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14244. end = domUtils.findParentByTagName(range.endContainer, 'li', true);
  14245. if (start && end && start === end) {
  14246. range.deleteContents();
  14247. li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14248. if (li && domUtils.isEmptyBlock(li)) {
  14249. pre = li.previousSibling;
  14250. next = li.nextSibling;
  14251. p = me.document.createElement('p');
  14252. domUtils.fillNode(me.document, p);
  14253. parentList = li.parentNode;
  14254. if (pre && next) {
  14255. range.setStart(next, 0).collapse(true).select(true);
  14256. domUtils.remove(li);
  14257. } else {
  14258. if (!pre && !next || !pre) {
  14259. parentList.parentNode.insertBefore(p, parentList);
  14260. } else {
  14261. li.parentNode.parentNode.insertBefore(p, parentList.nextSibling);
  14262. }
  14263. domUtils.remove(li);
  14264. if (!parentList.firstChild) {
  14265. domUtils.remove(parentList);
  14266. }
  14267. range.setStart(p, 0).setCursor();
  14268. }
  14269. preventAndSave();
  14270. return;
  14271. }
  14272. } else {
  14273. var tmpRange = range.cloneRange(),
  14274. bk = tmpRange.collapse(false).createBookmark();
  14275. range.deleteContents();
  14276. tmpRange.moveToBookmark(bk);
  14277. var li = domUtils.findParentByTagName(tmpRange.startContainer, 'li', true);
  14278. clearEmptySibling(li);
  14279. tmpRange.select();
  14280. preventAndSave();
  14281. return;
  14282. }
  14283. }
  14284. li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14285. if (li) {
  14286. if (domUtils.isEmptyBlock(li)) {
  14287. bk = range.createBookmark();
  14288. var parentList = li.parentNode;
  14289. if (li !== parentList.lastChild) {
  14290. domUtils.breakParent(li, parentList);
  14291. clearEmptySibling(li);
  14292. } else {
  14293. parentList.parentNode.insertBefore(li, parentList.nextSibling);
  14294. if (domUtils.isEmptyNode(parentList)) {
  14295. domUtils.remove(parentList);
  14296. }
  14297. }
  14298. //嵌套不处理
  14299. if (!dtd.$list[li.parentNode.tagName]) {
  14300. if (!domUtils.isBlockElm(li.firstChild)) {
  14301. p = me.document.createElement('p');
  14302. li.parentNode.insertBefore(p, li);
  14303. while (li.firstChild) {
  14304. p.appendChild(li.firstChild);
  14305. }
  14306. domUtils.remove(li);
  14307. } else {
  14308. domUtils.remove(li, true);
  14309. }
  14310. }
  14311. range.moveToBookmark(bk).select();
  14312. } else {
  14313. var first = li.firstChild;
  14314. if (!first || !domUtils.isBlockElm(first)) {
  14315. var p = me.document.createElement('p');
  14316. !li.firstChild && domUtils.fillNode(me.document, p);
  14317. while (li.firstChild) {
  14318. p.appendChild(li.firstChild);
  14319. }
  14320. li.appendChild(p);
  14321. first = p;
  14322. }
  14323. var span = me.document.createElement('span');
  14324. range.insertNode(span);
  14325. domUtils.breakParent(span, li);
  14326. var nextLi = span.nextSibling;
  14327. first = nextLi.firstChild;
  14328. if (!first) {
  14329. p = me.document.createElement('p');
  14330. domUtils.fillNode(me.document, p);
  14331. nextLi.appendChild(p);
  14332. first = p;
  14333. }
  14334. if (domUtils.isEmptyNode(first)) {
  14335. first.innerHTML = '';
  14336. domUtils.fillNode(me.document, first);
  14337. }
  14338. range.setStart(first, 0).collapse(true).shrinkBoundary().select();
  14339. domUtils.remove(span);
  14340. var pre = nextLi.previousSibling;
  14341. if (pre && domUtils.isEmptyBlock(pre)) {
  14342. pre.innerHTML = '<p></p>';
  14343. domUtils.fillNode(me.document, pre.firstChild);
  14344. }
  14345. }
  14346. // }
  14347. preventAndSave();
  14348. }
  14349. }
  14350. }
  14351. if (keyCode == 8) {
  14352. //修中ie中li下的问题
  14353. range = me.selection.getRange();
  14354. if (range.collapsed && domUtils.isStartInblock(range)) {
  14355. tmpRange = range.cloneRange().trimBoundary();
  14356. li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14357. //要在li的最左边,才能处理
  14358. if (li && domUtils.isStartInblock(tmpRange)) {
  14359. start = domUtils.findParentByTagName(range.startContainer, 'p', true);
  14360. if (start && start !== li.firstChild) {
  14361. var parentList = domUtils.findParentByTagName(start,['ol','ul']);
  14362. domUtils.breakParent(start,parentList);
  14363. clearEmptySibling(start);
  14364. me.fireEvent('contentchange');
  14365. range.setStart(start,0).setCursor(false,true);
  14366. me.fireEvent('saveScene');
  14367. domUtils.preventDefault(evt);
  14368. return;
  14369. }
  14370. if (li && (pre = li.previousSibling)) {
  14371. if (keyCode == 46 && li.childNodes.length) {
  14372. return;
  14373. }
  14374. //有可能上边的兄弟节点是个2级菜单,要追加到2级菜单的最后的li
  14375. if (dtd.$list[pre.tagName]) {
  14376. pre = pre.lastChild;
  14377. }
  14378. me.undoManger && me.undoManger.save();
  14379. first = li.firstChild;
  14380. if (domUtils.isBlockElm(first)) {
  14381. if (domUtils.isEmptyNode(first)) {
  14382. // range.setEnd(pre, pre.childNodes.length).shrinkBoundary().collapse().select(true);
  14383. pre.appendChild(first);
  14384. range.setStart(first, 0).setCursor(false, true);
  14385. //first不是唯一的节点
  14386. while (li.firstChild) {
  14387. pre.appendChild(li.firstChild);
  14388. }
  14389. } else {
  14390. span = me.document.createElement('span');
  14391. range.insertNode(span);
  14392. //判断pre是否是空的节点,如果是<p><br/></p>类型的空节点,干掉p标签防止它占位
  14393. if (domUtils.isEmptyBlock(pre)) {
  14394. pre.innerHTML = '';
  14395. }
  14396. domUtils.moveChild(li, pre);
  14397. range.setStartBefore(span).collapse(true).select(true);
  14398. domUtils.remove(span);
  14399. }
  14400. } else {
  14401. if (domUtils.isEmptyNode(li)) {
  14402. var p = me.document.createElement('p');
  14403. pre.appendChild(p);
  14404. range.setStart(p, 0).setCursor();
  14405. // range.setEnd(pre, pre.childNodes.length).shrinkBoundary().collapse().select(true);
  14406. } else {
  14407. range.setEnd(pre, pre.childNodes.length).collapse().select(true);
  14408. while (li.firstChild) {
  14409. pre.appendChild(li.firstChild);
  14410. }
  14411. }
  14412. }
  14413. domUtils.remove(li);
  14414. me.fireEvent('contentchange');
  14415. me.fireEvent('saveScene');
  14416. domUtils.preventDefault(evt);
  14417. return;
  14418. }
  14419. //trace:980
  14420. if (li && !li.previousSibling) {
  14421. var parentList = li.parentNode;
  14422. var bk = range.createBookmark();
  14423. if(domUtils.isTagNode(parentList.parentNode,'ol ul')){
  14424. parentList.parentNode.insertBefore(li,parentList);
  14425. if(domUtils.isEmptyNode(parentList)){
  14426. domUtils.remove(parentList)
  14427. }
  14428. }else{
  14429. while(li.firstChild){
  14430. parentList.parentNode.insertBefore(li.firstChild,parentList);
  14431. }
  14432. domUtils.remove(li);
  14433. if(domUtils.isEmptyNode(parentList)){
  14434. domUtils.remove(parentList)
  14435. }
  14436. }
  14437. range.moveToBookmark(bk).setCursor(false,true);
  14438. me.fireEvent('contentchange');
  14439. me.fireEvent('saveScene');
  14440. domUtils.preventDefault(evt);
  14441. return;
  14442. }
  14443. }
  14444. }
  14445. }
  14446. });
  14447. me.addListener('keyup',function(type, evt){
  14448. var keyCode = evt.keyCode || evt.which;
  14449. if (keyCode == 8) {
  14450. var rng = me.selection.getRange(),list;
  14451. if(list = domUtils.findParentByTagName(rng.startContainer,['ol', 'ul'],true)){
  14452. adjustList(list,list.tagName.toLowerCase(),getStyle(list)||domUtils.getComputedStyle(list,'list-style-type'),true)
  14453. }
  14454. }
  14455. });
  14456. //处理tab键
  14457. me.addListener('tabkeydown',function(){
  14458. var range = me.selection.getRange();
  14459. //控制级数
  14460. function checkLevel(li){
  14461. if(me.options.maxListLevel != -1){
  14462. var level = li.parentNode,levelNum = 0;
  14463. while(/[ou]l/i.test(level.tagName)){
  14464. levelNum++;
  14465. level = level.parentNode;
  14466. }
  14467. if(levelNum >= me.options.maxListLevel){
  14468. return true;
  14469. }
  14470. }
  14471. }
  14472. //只以开始为准
  14473. //todo 后续改进
  14474. var li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14475. if(li){
  14476. var bk;
  14477. if(range.collapsed){
  14478. if(checkLevel(li))
  14479. return true;
  14480. var parentLi = li.parentNode,
  14481. list = me.document.createElement(parentLi.tagName),
  14482. index = utils.indexOf(listStyle[list.tagName], getStyle(parentLi)||domUtils.getComputedStyle(parentLi, 'list-style-type'));
  14483. index = index + 1 == listStyle[list.tagName].length ? 0 : index + 1;
  14484. var currentStyle = listStyle[list.tagName][index];
  14485. setListStyle(list,currentStyle);
  14486. if(domUtils.isStartInblock(range)){
  14487. me.fireEvent('saveScene');
  14488. bk = range.createBookmark();
  14489. parentLi.insertBefore(list, li);
  14490. list.appendChild(li);
  14491. adjustList(list,list.tagName.toLowerCase(),currentStyle);
  14492. me.fireEvent('contentchange');
  14493. range.moveToBookmark(bk).select(true);
  14494. return true;
  14495. }
  14496. }else{
  14497. me.fireEvent('saveScene');
  14498. bk = range.createBookmark();
  14499. for(var i= 0,closeList,parents = domUtils.findParents(li),ci;ci=parents[i++];){
  14500. if(domUtils.isTagNode(ci,'ol ul')){
  14501. closeList = ci;
  14502. break;
  14503. }
  14504. }
  14505. var current = li;
  14506. if(bk.end){
  14507. while(current && !(domUtils.getPosition(current, bk.end) & domUtils.POSITION_FOLLOWING)){
  14508. if(checkLevel(current)){
  14509. current = domUtils.getNextDomNode(current,false,null,function(node){return node !== closeList});
  14510. continue;
  14511. }
  14512. var parentLi = current.parentNode,
  14513. list = me.document.createElement(parentLi.tagName),
  14514. index = utils.indexOf(listStyle[list.tagName], getStyle(parentLi)||domUtils.getComputedStyle(parentLi, 'list-style-type'));
  14515. var currentIndex = index + 1 == listStyle[list.tagName].length ? 0 : index + 1;
  14516. var currentStyle = listStyle[list.tagName][currentIndex];
  14517. setListStyle(list,currentStyle);
  14518. parentLi.insertBefore(list, current);
  14519. while(current && !(domUtils.getPosition(current, bk.end) & domUtils.POSITION_FOLLOWING)){
  14520. li = current.nextSibling;
  14521. list.appendChild(current);
  14522. if(!li || domUtils.isTagNode(li,'ol ul')){
  14523. if(li){
  14524. while(li = li.firstChild){
  14525. if(li.tagName == 'LI'){
  14526. break;
  14527. }
  14528. }
  14529. }else{
  14530. li = domUtils.getNextDomNode(current,false,null,function(node){return node !== closeList});
  14531. }
  14532. break;
  14533. }
  14534. current = li;
  14535. }
  14536. adjustList(list,list.tagName.toLowerCase(),currentStyle);
  14537. current = li;
  14538. }
  14539. }
  14540. me.fireEvent('contentchange');
  14541. range.moveToBookmark(bk).select();
  14542. return true;
  14543. }
  14544. }
  14545. });
  14546. function getLi(start){
  14547. while(start && !domUtils.isBody(start)){
  14548. if(start.nodeName == 'TABLE'){
  14549. return null;
  14550. }
  14551. if(start.nodeName == 'LI'){
  14552. return start
  14553. }
  14554. start = start.parentNode;
  14555. }
  14556. }
  14557. /**
  14558. * 有序列表,与“insertunorderedlist”命令互斥
  14559. * @command insertorderedlist
  14560. * @method execCommand
  14561. * @param { String } command 命令字符串
  14562. * @param { String } style 插入的有序列表类型,值为:decimal,lower-alpha,lower-roman,upper-alpha,upper-roman,cn,cn1,cn2,num,num1,num2
  14563. * @example
  14564. * ```javascript
  14565. * editor.execCommand( 'insertorderedlist','decimal');
  14566. * ```
  14567. */
  14568. /**
  14569. * 查询当前选区内容是否有序列表
  14570. * @command insertorderedlist
  14571. * @method queryCommandState
  14572. * @param { String } cmd 命令字符串
  14573. * @return { int } 如果当前选区是有序列表返回1,否则返回0
  14574. * @example
  14575. * ```javascript
  14576. * editor.queryCommandState( 'insertorderedlist' );
  14577. * ```
  14578. */
  14579. /**
  14580. * 查询当前选区内容是否有序列表
  14581. * @command insertorderedlist
  14582. * @method queryCommandValue
  14583. * @param { String } cmd 命令字符串
  14584. * @return { String } 返回当前有序列表的类型,值为null或decimal,lower-alpha,lower-roman,upper-alpha,upper-roman,cn,cn1,cn2,num,num1,num2
  14585. * @example
  14586. * ```javascript
  14587. * editor.queryCommandValue( 'insertorderedlist' );
  14588. * ```
  14589. */
  14590. /**
  14591. * 无序列表,与“insertorderedlist”命令互斥
  14592. * @command insertunorderedlist
  14593. * @method execCommand
  14594. * @param { String } command 命令字符串
  14595. * @param { String } style 插入的无序列表类型,值为:circle,disc,square,dash,dot
  14596. * @example
  14597. * ```javascript
  14598. * editor.execCommand( 'insertunorderedlist','circle');
  14599. * ```
  14600. */
  14601. /**
  14602. * 查询当前是否有word文档粘贴进来的图片
  14603. * @command insertunorderedlist
  14604. * @method insertunorderedlist
  14605. * @param { String } command 命令字符串
  14606. * @return { int } 如果当前选区是无序列表返回1,否则返回0
  14607. * @example
  14608. * ```javascript
  14609. * editor.queryCommandState( 'insertunorderedlist' );
  14610. * ```
  14611. */
  14612. /**
  14613. * 查询当前选区内容是否有序列表
  14614. * @command insertunorderedlist
  14615. * @method queryCommandValue
  14616. * @param { String } command 命令字符串
  14617. * @return { String } 返回当前无序列表的类型,值为null或circle,disc,square,dash,dot
  14618. * @example
  14619. * ```javascript
  14620. * editor.queryCommandValue( 'insertunorderedlist' );
  14621. * ```
  14622. */
  14623. me.commands['insertorderedlist'] =
  14624. me.commands['insertunorderedlist'] = {
  14625. execCommand:function (command, style) {
  14626. if (!style) {
  14627. style = command.toLowerCase() == 'insertorderedlist' ? 'decimal' : 'disc';
  14628. }
  14629. var me = this,
  14630. range = this.selection.getRange(),
  14631. filterFn = function (node) {
  14632. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' : !domUtils.isWhitespace(node);
  14633. },
  14634. tag = command.toLowerCase() == 'insertorderedlist' ? 'ol' : 'ul',
  14635. frag = me.document.createDocumentFragment();
  14636. //去掉是因为会出现选到末尾,导致adjustmentBoundary缩到ol/ul的位置
  14637. //range.shrinkBoundary();//.adjustmentBoundary();
  14638. range.adjustmentBoundary().shrinkBoundary();
  14639. var bko = range.createBookmark(true),
  14640. start = getLi(me.document.getElementById(bko.start)),
  14641. modifyStart = 0,
  14642. end = getLi(me.document.getElementById(bko.end)),
  14643. modifyEnd = 0,
  14644. startParent, endParent,
  14645. list, tmp;
  14646. if (start || end) {
  14647. start && (startParent = start.parentNode);
  14648. if (!bko.end) {
  14649. end = start;
  14650. }
  14651. end && (endParent = end.parentNode);
  14652. if (startParent === endParent) {
  14653. while (start !== end) {
  14654. tmp = start;
  14655. start = start.nextSibling;
  14656. if (!domUtils.isBlockElm(tmp.firstChild)) {
  14657. var p = me.document.createElement('p');
  14658. while (tmp.firstChild) {
  14659. p.appendChild(tmp.firstChild);
  14660. }
  14661. tmp.appendChild(p);
  14662. }
  14663. frag.appendChild(tmp);
  14664. }
  14665. tmp = me.document.createElement('span');
  14666. startParent.insertBefore(tmp, end);
  14667. if (!domUtils.isBlockElm(end.firstChild)) {
  14668. p = me.document.createElement('p');
  14669. while (end.firstChild) {
  14670. p.appendChild(end.firstChild);
  14671. }
  14672. end.appendChild(p);
  14673. }
  14674. frag.appendChild(end);
  14675. domUtils.breakParent(tmp, startParent);
  14676. if (domUtils.isEmptyNode(tmp.previousSibling)) {
  14677. domUtils.remove(tmp.previousSibling);
  14678. }
  14679. if (domUtils.isEmptyNode(tmp.nextSibling)) {
  14680. domUtils.remove(tmp.nextSibling)
  14681. }
  14682. var nodeStyle = getStyle(startParent) || domUtils.getComputedStyle(startParent, 'list-style-type') || (command.toLowerCase() == 'insertorderedlist' ? 'decimal' : 'disc');
  14683. if (startParent.tagName.toLowerCase() == tag && nodeStyle == style) {
  14684. for (var i = 0, ci, tmpFrag = me.document.createDocumentFragment(); ci = frag.firstChild;) {
  14685. if(domUtils.isTagNode(ci,'ol ul')){
  14686. // 删除时,子列表不处理
  14687. // utils.each(domUtils.getElementsByTagName(ci,'li'),function(li){
  14688. // while(li.firstChild){
  14689. // tmpFrag.appendChild(li.firstChild);
  14690. // }
  14691. //
  14692. // });
  14693. tmpFrag.appendChild(ci);
  14694. }else{
  14695. while (ci.firstChild) {
  14696. tmpFrag.appendChild(ci.firstChild);
  14697. domUtils.remove(ci);
  14698. }
  14699. }
  14700. }
  14701. tmp.parentNode.insertBefore(tmpFrag, tmp);
  14702. } else {
  14703. list = me.document.createElement(tag);
  14704. setListStyle(list,style);
  14705. list.appendChild(frag);
  14706. tmp.parentNode.insertBefore(list, tmp);
  14707. }
  14708. domUtils.remove(tmp);
  14709. list && adjustList(list, tag, style);
  14710. range.moveToBookmark(bko).select();
  14711. return;
  14712. }
  14713. //开始
  14714. if (start) {
  14715. while (start) {
  14716. tmp = start.nextSibling;
  14717. if (domUtils.isTagNode(start, 'ol ul')) {
  14718. frag.appendChild(start);
  14719. } else {
  14720. var tmpfrag = me.document.createDocumentFragment(),
  14721. hasBlock = 0;
  14722. while (start.firstChild) {
  14723. if (domUtils.isBlockElm(start.firstChild)) {
  14724. hasBlock = 1;
  14725. }
  14726. tmpfrag.appendChild(start.firstChild);
  14727. }
  14728. if (!hasBlock) {
  14729. var tmpP = me.document.createElement('p');
  14730. tmpP.appendChild(tmpfrag);
  14731. frag.appendChild(tmpP);
  14732. } else {
  14733. frag.appendChild(tmpfrag);
  14734. }
  14735. domUtils.remove(start);
  14736. }
  14737. start = tmp;
  14738. }
  14739. startParent.parentNode.insertBefore(frag, startParent.nextSibling);
  14740. if (domUtils.isEmptyNode(startParent)) {
  14741. range.setStartBefore(startParent);
  14742. domUtils.remove(startParent);
  14743. } else {
  14744. range.setStartAfter(startParent);
  14745. }
  14746. modifyStart = 1;
  14747. }
  14748. if (end && domUtils.inDoc(endParent, me.document)) {
  14749. //结束
  14750. start = endParent.firstChild;
  14751. while (start && start !== end) {
  14752. tmp = start.nextSibling;
  14753. if (domUtils.isTagNode(start, 'ol ul')) {
  14754. frag.appendChild(start);
  14755. } else {
  14756. tmpfrag = me.document.createDocumentFragment();
  14757. hasBlock = 0;
  14758. while (start.firstChild) {
  14759. if (domUtils.isBlockElm(start.firstChild)) {
  14760. hasBlock = 1;
  14761. }
  14762. tmpfrag.appendChild(start.firstChild);
  14763. }
  14764. if (!hasBlock) {
  14765. tmpP = me.document.createElement('p');
  14766. tmpP.appendChild(tmpfrag);
  14767. frag.appendChild(tmpP);
  14768. } else {
  14769. frag.appendChild(tmpfrag);
  14770. }
  14771. domUtils.remove(start);
  14772. }
  14773. start = tmp;
  14774. }
  14775. var tmpDiv = domUtils.createElement(me.document, 'div', {
  14776. 'tmpDiv':1
  14777. });
  14778. domUtils.moveChild(end, tmpDiv);
  14779. frag.appendChild(tmpDiv);
  14780. domUtils.remove(end);
  14781. endParent.parentNode.insertBefore(frag, endParent);
  14782. range.setEndBefore(endParent);
  14783. if (domUtils.isEmptyNode(endParent)) {
  14784. domUtils.remove(endParent);
  14785. }
  14786. modifyEnd = 1;
  14787. }
  14788. }
  14789. if (!modifyStart) {
  14790. range.setStartBefore(me.document.getElementById(bko.start));
  14791. }
  14792. if (bko.end && !modifyEnd) {
  14793. range.setEndAfter(me.document.getElementById(bko.end));
  14794. }
  14795. range.enlarge(true, function (node) {
  14796. return notExchange[node.tagName];
  14797. });
  14798. frag = me.document.createDocumentFragment();
  14799. var bk = range.createBookmark(),
  14800. current = domUtils.getNextDomNode(bk.start, false, filterFn),
  14801. tmpRange = range.cloneRange(),
  14802. tmpNode,
  14803. block = domUtils.isBlockElm;
  14804. while (current && current !== bk.end && (domUtils.getPosition(current, bk.end) & domUtils.POSITION_PRECEDING)) {
  14805. if (current.nodeType == 3 || dtd.li[current.tagName]) {
  14806. if (current.nodeType == 1 && dtd.$list[current.tagName]) {
  14807. while (current.firstChild) {
  14808. frag.appendChild(current.firstChild);
  14809. }
  14810. tmpNode = domUtils.getNextDomNode(current, false, filterFn);
  14811. domUtils.remove(current);
  14812. current = tmpNode;
  14813. continue;
  14814. }
  14815. tmpNode = current;
  14816. tmpRange.setStartBefore(current);
  14817. while (current && current !== bk.end && (!block(current) || domUtils.isBookmarkNode(current) )) {
  14818. tmpNode = current;
  14819. current = domUtils.getNextDomNode(current, false, null, function (node) {
  14820. return !notExchange[node.tagName];
  14821. });
  14822. }
  14823. if (current && block(current)) {
  14824. tmp = domUtils.getNextDomNode(tmpNode, false, filterFn);
  14825. if (tmp && domUtils.isBookmarkNode(tmp)) {
  14826. current = domUtils.getNextDomNode(tmp, false, filterFn);
  14827. tmpNode = tmp;
  14828. }
  14829. }
  14830. tmpRange.setEndAfter(tmpNode);
  14831. current = domUtils.getNextDomNode(tmpNode, false, filterFn);
  14832. var li = range.document.createElement('li');
  14833. li.appendChild(tmpRange.extractContents());
  14834. if(domUtils.isEmptyNode(li)){
  14835. var tmpNode = range.document.createElement('p');
  14836. while(li.firstChild){
  14837. tmpNode.appendChild(li.firstChild)
  14838. }
  14839. li.appendChild(tmpNode);
  14840. }
  14841. frag.appendChild(li);
  14842. } else {
  14843. current = domUtils.getNextDomNode(current, true, filterFn);
  14844. }
  14845. }
  14846. range.moveToBookmark(bk).collapse(true);
  14847. list = me.document.createElement(tag);
  14848. setListStyle(list,style);
  14849. list.appendChild(frag);
  14850. range.insertNode(list);
  14851. //当前list上下看能否合并
  14852. adjustList(list, tag, style);
  14853. //去掉冗余的tmpDiv
  14854. for (var i = 0, ci, tmpDivs = domUtils.getElementsByTagName(list, 'div'); ci = tmpDivs[i++];) {
  14855. if (ci.getAttribute('tmpDiv')) {
  14856. domUtils.remove(ci, true)
  14857. }
  14858. }
  14859. range.moveToBookmark(bko).select();
  14860. },
  14861. queryCommandState:function (command) {
  14862. var tag = command.toLowerCase() == 'insertorderedlist' ? 'ol' : 'ul';
  14863. var path = this.selection.getStartElementPath();
  14864. for(var i= 0,ci;ci = path[i++];){
  14865. if(ci.nodeName == 'TABLE'){
  14866. return 0
  14867. }
  14868. if(tag == ci.nodeName.toLowerCase()){
  14869. return 1
  14870. };
  14871. }
  14872. return 0;
  14873. },
  14874. queryCommandValue:function (command) {
  14875. var tag = command.toLowerCase() == 'insertorderedlist' ? 'ol' : 'ul';
  14876. var path = this.selection.getStartElementPath(),
  14877. node;
  14878. for(var i= 0,ci;ci = path[i++];){
  14879. if(ci.nodeName == 'TABLE'){
  14880. node = null;
  14881. break;
  14882. }
  14883. if(tag == ci.nodeName.toLowerCase()){
  14884. node = ci;
  14885. break;
  14886. };
  14887. }
  14888. return node ? getStyle(node) || domUtils.getComputedStyle(node, 'list-style-type') : null;
  14889. }
  14890. };
  14891. };
  14892. // js/editor/_src/plugins/source.js
  14893. /**
  14894. * 源码编辑插件
  14895. * @file
  14896. * @since 1.2.6.1
  14897. */
  14898. (function (){
  14899. var sourceEditors = {
  14900. textarea: function (editor, holder){
  14901. var textarea = holder.ownerDocument.createElement('textarea');
  14902. textarea.style.cssText = 'position:absolute;resize:none;width:100%;height:100%;border:0;padding:0;margin:0;overflow-y:auto;';
  14903. // todo: IE下只有onresize属性可用... 很纠结
  14904. if (browser.ie && browser.version < 8) {
  14905. textarea.style.width = holder.offsetWidth + 'px';
  14906. textarea.style.height = holder.offsetHeight + 'px';
  14907. holder.onresize = function (){
  14908. textarea.style.width = holder.offsetWidth + 'px';
  14909. textarea.style.height = holder.offsetHeight + 'px';
  14910. };
  14911. }
  14912. holder.appendChild(textarea);
  14913. return {
  14914. setContent: function (content){
  14915. textarea.value = content;
  14916. },
  14917. getContent: function (){
  14918. return textarea.value;
  14919. },
  14920. select: function (){
  14921. var range;
  14922. if (browser.ie) {
  14923. range = textarea.createTextRange();
  14924. range.collapse(true);
  14925. range.select();
  14926. } else {
  14927. //todo: chrome下无法设置焦点
  14928. textarea.setSelectionRange(0, 0);
  14929. textarea.focus();
  14930. }
  14931. },
  14932. dispose: function (){
  14933. holder.removeChild(textarea);
  14934. // todo
  14935. holder.onresize = null;
  14936. textarea = null;
  14937. holder = null;
  14938. }
  14939. };
  14940. },
  14941. codemirror: function (editor, holder){
  14942. var codeEditor = window.CodeMirror(holder, {
  14943. mode: "text/html",
  14944. tabMode: "indent",
  14945. lineNumbers: true,
  14946. lineWrapping:true
  14947. });
  14948. var dom = codeEditor.getWrapperElement();
  14949. dom.style.cssText = 'position:absolute;left:0;top:0;width:100%;height:100%;font-family:consolas,"Courier new",monospace;font-size:13px;';
  14950. codeEditor.getScrollerElement().style.cssText = 'position:absolute;left:0;top:0;width:100%;height:100%;';
  14951. codeEditor.refresh();
  14952. return {
  14953. getCodeMirror:function(){
  14954. return codeEditor;
  14955. },
  14956. setContent: function (content){
  14957. codeEditor.setValue(content);
  14958. },
  14959. getContent: function (){
  14960. return codeEditor.getValue();
  14961. },
  14962. select: function (){
  14963. codeEditor.focus();
  14964. },
  14965. dispose: function (){
  14966. holder.removeChild(dom);
  14967. dom = null;
  14968. codeEditor = null;
  14969. }
  14970. };
  14971. }
  14972. };
  14973. UE.plugins['source'] = function (){
  14974. var me = this;
  14975. var opt = this.options;
  14976. var sourceMode = false;
  14977. var sourceEditor;
  14978. var orgSetContent;
  14979. opt.sourceEditor = browser.ie ? 'textarea' : (opt.sourceEditor || 'codemirror');
  14980. me.setOpt({
  14981. sourceEditorFirst:false
  14982. });
  14983. function createSourceEditor(holder){
  14984. return sourceEditors[opt.sourceEditor == 'codemirror' && window.CodeMirror ? 'codemirror' : 'textarea'](me, holder);
  14985. }
  14986. var bakCssText;
  14987. //解决在源码模式下getContent不能得到最新的内容问题
  14988. var oldGetContent,
  14989. bakAddress;
  14990. /**
  14991. * 切换源码模式和编辑模式
  14992. * @command source
  14993. * @method execCommand
  14994. * @param { String } cmd 命令字符串
  14995. * @example
  14996. * ```javascript
  14997. * editor.execCommand( 'source');
  14998. * ```
  14999. */
  15000. /**
  15001. * 查询当前编辑区域的状态是源码模式还是可视化模式
  15002. * @command source
  15003. * @method queryCommandState
  15004. * @param { String } cmd 命令字符串
  15005. * @return { int } 如果当前是源码编辑模式,返回1,否则返回0
  15006. * @example
  15007. * ```javascript
  15008. * editor.queryCommandState( 'source' );
  15009. * ```
  15010. */
  15011. me.commands['source'] = {
  15012. execCommand: function (){
  15013. sourceMode = !sourceMode;
  15014. if (sourceMode) {
  15015. bakAddress = me.selection.getRange().createAddress(false,true);
  15016. me.undoManger && me.undoManger.save(true);
  15017. if(browser.gecko){
  15018. me.body.contentEditable = false;
  15019. }
  15020. bakCssText = me.iframe.style.cssText;
  15021. me.iframe.style.cssText += 'position:absolute;left:-32768px;top:-32768px;';
  15022. me.fireEvent('beforegetcontent');
  15023. var root = UE.htmlparser(me.body.innerHTML);
  15024. me.filterOutputRule(root);
  15025. root.traversal(function (node) {
  15026. if (node.type == 'element') {
  15027. switch (node.tagName) {
  15028. case 'td':
  15029. case 'th':
  15030. case 'caption':
  15031. if(node.children && node.children.length == 1){
  15032. if(node.firstChild().tagName == 'br' ){
  15033. node.removeChild(node.firstChild())
  15034. }
  15035. };
  15036. break;
  15037. case 'pre':
  15038. node.innerText(node.innerText().replace(/&nbsp;/g,' '))
  15039. }
  15040. }
  15041. });
  15042. me.fireEvent('aftergetcontent');
  15043. var content = root.toHtml(true);
  15044. sourceEditor = createSourceEditor(me.iframe.parentNode);
  15045. sourceEditor.setContent(content);
  15046. orgSetContent = me.setContent;
  15047. me.setContent = function(html){
  15048. //这里暂时不触发事件,防止报错
  15049. var root = UE.htmlparser(html);
  15050. me.filterInputRule(root);
  15051. html = root.toHtml();
  15052. sourceEditor.setContent(html);
  15053. };
  15054. setTimeout(function (){
  15055. sourceEditor.select();
  15056. me.addListener('fullscreenchanged', function(){
  15057. try{
  15058. sourceEditor.getCodeMirror().refresh()
  15059. }catch(e){}
  15060. });
  15061. });
  15062. //重置getContent,源码模式下取值也能是最新的数据
  15063. oldGetContent = me.getContent;
  15064. me.getContent = function (){
  15065. return sourceEditor.getContent() || '<p>' + (browser.ie ? '' : '<br/>')+'</p>';
  15066. };
  15067. } else {
  15068. me.iframe.style.cssText = bakCssText;
  15069. var cont = sourceEditor.getContent() || '<p>' + (browser.ie ? '' : '<br/>')+'</p>';
  15070. //处理掉block节点前后的空格,有可能会误命中,暂时不考虑
  15071. cont = cont.replace(new RegExp('[\\r\\t\\n ]*<\/?(\\w+)\\s*(?:[^>]*)>','g'), function(a,b){
  15072. if(b && !dtd.$inlineWithA[b.toLowerCase()]){
  15073. return a.replace(/(^[\n\r\t ]*)|([\n\r\t ]*$)/g,'');
  15074. }
  15075. return a.replace(/(^[\n\r\t]*)|([\n\r\t]*$)/g,'')
  15076. });
  15077. me.setContent = orgSetContent;
  15078. me.setContent(cont);
  15079. sourceEditor.dispose();
  15080. sourceEditor = null;
  15081. //还原getContent方法
  15082. me.getContent = oldGetContent;
  15083. var first = me.body.firstChild;
  15084. //trace:1106 都删除空了,下边会报错,所以补充一个p占位
  15085. if(!first){
  15086. me.body.innerHTML = '<p>'+(browser.ie?'':'<br/>')+'</p>';
  15087. first = me.body.firstChild;
  15088. }
  15089. //要在ifm为显示时ff才能取到selection,否则报错
  15090. //这里不能比较位置了
  15091. me.undoManger && me.undoManger.save(true);
  15092. if(browser.gecko){
  15093. var input = document.createElement('input');
  15094. input.style.cssText = 'position:absolute;left:0;top:-32768px';
  15095. document.body.appendChild(input);
  15096. me.body.contentEditable = false;
  15097. setTimeout(function(){
  15098. domUtils.setViewportOffset(input, { left: -32768, top: 0 });
  15099. input.focus();
  15100. setTimeout(function(){
  15101. me.body.contentEditable = true;
  15102. me.selection.getRange().moveToAddress(bakAddress).select(true);
  15103. domUtils.remove(input);
  15104. });
  15105. });
  15106. }else{
  15107. //ie下有可能报错,比如在代码顶头的情况
  15108. try{
  15109. me.selection.getRange().moveToAddress(bakAddress).select(true);
  15110. }catch(e){}
  15111. }
  15112. }
  15113. this.fireEvent('sourcemodechanged', sourceMode);
  15114. },
  15115. queryCommandState: function (){
  15116. return sourceMode|0;
  15117. },
  15118. notNeedUndo : 1
  15119. };
  15120. var oldQueryCommandState = me.queryCommandState;
  15121. me.queryCommandState = function (cmdName){
  15122. cmdName = cmdName.toLowerCase();
  15123. if (sourceMode) {
  15124. //源码模式下可以开启的命令
  15125. return cmdName in {
  15126. 'source' : 1,
  15127. 'fullscreen' : 1
  15128. } ? 1 : -1
  15129. }
  15130. return oldQueryCommandState.apply(this, arguments);
  15131. };
  15132. if(opt.sourceEditor == "codemirror"){
  15133. me.addListener("ready",function(){
  15134. utils.loadFile(document,{
  15135. src : opt.codeMirrorJsUrl || opt.UEDITOR_HOME_URL + "third-party/codemirror/codemirror.js",
  15136. tag : "script",
  15137. type : "text/javascript",
  15138. defer : "defer"
  15139. },function(){
  15140. if(opt.sourceEditorFirst){
  15141. setTimeout(function(){
  15142. me.execCommand("source");
  15143. },0);
  15144. }
  15145. });
  15146. utils.loadFile(document,{
  15147. tag : "link",
  15148. rel : "stylesheet",
  15149. type : "text/css",
  15150. href : opt.codeMirrorCssUrl || opt.UEDITOR_HOME_URL + "third-party/codemirror/codemirror.css"
  15151. });
  15152. });
  15153. }
  15154. };
  15155. })();
  15156. // js/editor/_src/plugins/enterkey.js
  15157. ///import core
  15158. ///import plugins/undo.js
  15159. ///commands 设置回车标签p或br
  15160. ///commandsName EnterKey
  15161. ///commandsTitle 设置回车标签p或br
  15162. /**
  15163. * @description 处理回车
  15164. * @author zhanyi
  15165. */
  15166. UE.plugins['enterkey'] = function() {
  15167. var hTag,
  15168. me = this,
  15169. tag = me.options.enterTag;
  15170. me.addListener('keyup', function(type, evt) {
  15171. var keyCode = evt.keyCode || evt.which;
  15172. if (keyCode == 13) {
  15173. var range = me.selection.getRange(),
  15174. start = range.startContainer,
  15175. doSave;
  15176. //修正在h1-h6里边回车后不能嵌套p的问题
  15177. if (!browser.ie) {
  15178. if (/h\d/i.test(hTag)) {
  15179. if (browser.gecko) {
  15180. var h = domUtils.findParentByTagName(start, [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6','blockquote','caption','table'], true);
  15181. if (!h) {
  15182. me.document.execCommand('formatBlock', false, '<p>');
  15183. doSave = 1;
  15184. }
  15185. } else {
  15186. //chrome remove div
  15187. if (start.nodeType == 1) {
  15188. var tmp = me.document.createTextNode(''),div;
  15189. range.insertNode(tmp);
  15190. div = domUtils.findParentByTagName(tmp, 'div', true);
  15191. if (div) {
  15192. var p = me.document.createElement('p');
  15193. while (div.firstChild) {
  15194. p.appendChild(div.firstChild);
  15195. }
  15196. div.parentNode.insertBefore(p, div);
  15197. domUtils.remove(div);
  15198. range.setStartBefore(tmp).setCursor();
  15199. doSave = 1;
  15200. }
  15201. domUtils.remove(tmp);
  15202. }
  15203. }
  15204. if (me.undoManger && doSave) {
  15205. me.undoManger.save();
  15206. }
  15207. }
  15208. //没有站位符,会出现多行的问题
  15209. browser.opera && range.select();
  15210. }else{
  15211. me.fireEvent('saveScene',true,true)
  15212. }
  15213. }
  15214. });
  15215. me.addListener('keydown', function(type, evt) {
  15216. var keyCode = evt.keyCode || evt.which;
  15217. if (keyCode == 13) {//回车
  15218. if(me.fireEvent('beforeenterkeydown')){
  15219. domUtils.preventDefault(evt);
  15220. return;
  15221. }
  15222. me.fireEvent('saveScene',true,true);
  15223. hTag = '';
  15224. var range = me.selection.getRange();
  15225. if (!range.collapsed) {
  15226. //跨td不能删
  15227. var start = range.startContainer,
  15228. end = range.endContainer,
  15229. startTd = domUtils.findParentByTagName(start, 'td', true),
  15230. endTd = domUtils.findParentByTagName(end, 'td', true);
  15231. if (startTd && endTd && startTd !== endTd || !startTd && endTd || startTd && !endTd) {
  15232. evt.preventDefault ? evt.preventDefault() : ( evt.returnValue = false);
  15233. return;
  15234. }
  15235. }
  15236. if (tag == 'p') {
  15237. if (!browser.ie) {
  15238. start = domUtils.findParentByTagName(range.startContainer, ['ol','ul','p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6','blockquote','caption'], true);
  15239. //opera下执行formatblock会在table的场景下有问题,回车在opera原生支持很好,所以暂时在opera去掉调用这个原生的command
  15240. //trace:2431
  15241. if (!start && !browser.opera) {
  15242. me.document.execCommand('formatBlock', false, '<p>');
  15243. if (browser.gecko) {
  15244. range = me.selection.getRange();
  15245. start = domUtils.findParentByTagName(range.startContainer, 'p', true);
  15246. start && domUtils.removeDirtyAttr(start);
  15247. }
  15248. } else {
  15249. hTag = start.tagName;
  15250. start.tagName.toLowerCase() == 'p' && browser.gecko && domUtils.removeDirtyAttr(start);
  15251. }
  15252. }
  15253. } else {
  15254. evt.preventDefault ? evt.preventDefault() : ( evt.returnValue = false);
  15255. if (!range.collapsed) {
  15256. range.deleteContents();
  15257. start = range.startContainer;
  15258. if (start.nodeType == 1 && (start = start.childNodes[range.startOffset])) {
  15259. while (start.nodeType == 1) {
  15260. if (dtd.$empty[start.tagName]) {
  15261. range.setStartBefore(start).setCursor();
  15262. if (me.undoManger) {
  15263. me.undoManger.save();
  15264. }
  15265. return false;
  15266. }
  15267. if (!start.firstChild) {
  15268. var br = range.document.createElement('br');
  15269. start.appendChild(br);
  15270. range.setStart(start, 0).setCursor();
  15271. if (me.undoManger) {
  15272. me.undoManger.save();
  15273. }
  15274. return false;
  15275. }
  15276. start = start.firstChild;
  15277. }
  15278. if (start === range.startContainer.childNodes[range.startOffset]) {
  15279. br = range.document.createElement('br');
  15280. range.insertNode(br).setCursor();
  15281. } else {
  15282. range.setStart(start, 0).setCursor();
  15283. }
  15284. } else {
  15285. br = range.document.createElement('br');
  15286. range.insertNode(br).setStartAfter(br).setCursor();
  15287. }
  15288. } else {
  15289. br = range.document.createElement('br');
  15290. range.insertNode(br);
  15291. var parent = br.parentNode;
  15292. if (parent.lastChild === br) {
  15293. br.parentNode.insertBefore(br.cloneNode(true), br);
  15294. range.setStartBefore(br);
  15295. } else {
  15296. range.setStartAfter(br);
  15297. }
  15298. range.setCursor();
  15299. }
  15300. }
  15301. }
  15302. });
  15303. };
  15304. // js/editor/_src/plugins/keystrokes.js
  15305. /* 处理特殊键的兼容性问题 */
  15306. UE.plugins['keystrokes'] = function() {
  15307. var me = this;
  15308. var collapsed = true;
  15309. me.addListener('keydown', function(type, evt) {
  15310. var keyCode = evt.keyCode || evt.which,
  15311. rng = me.selection.getRange();
  15312. //处理全选的情况
  15313. if(!rng.collapsed && !(evt.ctrlKey || evt.shiftKey || evt.altKey || evt.metaKey) && (keyCode >= 65 && keyCode <=90
  15314. || keyCode >= 48 && keyCode <= 57 ||
  15315. keyCode >= 96 && keyCode <= 111 || {
  15316. 13:1,
  15317. 8:1,
  15318. 46:1
  15319. }[keyCode])
  15320. ){
  15321. var tmpNode = rng.startContainer;
  15322. if(domUtils.isFillChar(tmpNode)){
  15323. rng.setStartBefore(tmpNode)
  15324. }
  15325. tmpNode = rng.endContainer;
  15326. if(domUtils.isFillChar(tmpNode)){
  15327. rng.setEndAfter(tmpNode)
  15328. }
  15329. rng.txtToElmBoundary();
  15330. //结束边界可能放到了br的前边,要把br包含进来
  15331. // x[xxx]<br/>
  15332. if(rng.endContainer && rng.endContainer.nodeType == 1){
  15333. tmpNode = rng.endContainer.childNodes[rng.endOffset];
  15334. if(tmpNode && domUtils.isBr(tmpNode)){
  15335. rng.setEndAfter(tmpNode);
  15336. }
  15337. }
  15338. if(rng.startOffset == 0){
  15339. tmpNode = rng.startContainer;
  15340. if(domUtils.isBoundaryNode(tmpNode,'firstChild') ){
  15341. tmpNode = rng.endContainer;
  15342. if(rng.endOffset == (tmpNode.nodeType == 3 ? tmpNode.nodeValue.length : tmpNode.childNodes.length) && domUtils.isBoundaryNode(tmpNode,'lastChild')){
  15343. me.fireEvent('saveScene');
  15344. me.body.innerHTML = '<p>'+(browser.ie ? '' : '<br/>')+'</p>';
  15345. rng.setStart(me.body.firstChild,0).setCursor(false,true);
  15346. me._selectionChange();
  15347. return;
  15348. }
  15349. }
  15350. }
  15351. }
  15352. //处理backspace
  15353. if (keyCode == keymap.Backspace) {
  15354. rng = me.selection.getRange();
  15355. collapsed = rng.collapsed;
  15356. if(me.fireEvent('delkeydown',evt)){
  15357. return;
  15358. }
  15359. var start,end;
  15360. //避免按两次删除才能生效的问题
  15361. if(rng.collapsed && rng.inFillChar()){
  15362. start = rng.startContainer;
  15363. if(domUtils.isFillChar(start)){
  15364. rng.setStartBefore(start).shrinkBoundary(true).collapse(true);
  15365. domUtils.remove(start)
  15366. }else{
  15367. start.nodeValue = start.nodeValue.replace(new RegExp('^' + domUtils.fillChar ),'');
  15368. rng.startOffset--;
  15369. rng.collapse(true).select(true)
  15370. }
  15371. }
  15372. //解决选中control元素不能删除的问题
  15373. if (start = rng.getClosedNode()) {
  15374. me.fireEvent('saveScene');
  15375. rng.setStartBefore(start);
  15376. domUtils.remove(start);
  15377. rng.setCursor();
  15378. me.fireEvent('saveScene');
  15379. domUtils.preventDefault(evt);
  15380. return;
  15381. }
  15382. //阻止在table上的删除
  15383. if (!browser.ie) {
  15384. start = domUtils.findParentByTagName(rng.startContainer, 'table', true);
  15385. end = domUtils.findParentByTagName(rng.endContainer, 'table', true);
  15386. if (start && !end || !start && end || start !== end) {
  15387. evt.preventDefault();
  15388. return;
  15389. }
  15390. }
  15391. }
  15392. //处理tab键的逻辑
  15393. if (keyCode == keymap.Tab) {
  15394. //不处理以下标签
  15395. var excludeTagNameForTabKey = {
  15396. 'ol' : 1,
  15397. 'ul' : 1,
  15398. 'table':1
  15399. };
  15400. //处理组件里的tab按下事件
  15401. if(me.fireEvent('tabkeydown',evt)){
  15402. domUtils.preventDefault(evt);
  15403. return;
  15404. }
  15405. var range = me.selection.getRange();
  15406. me.fireEvent('saveScene');
  15407. for (var i = 0,txt = '',tabSize = me.options.tabSize|| 4,tabNode = me.options.tabNode || '&nbsp;'; i < tabSize; i++) {
  15408. txt += tabNode;
  15409. }
  15410. var span = me.document.createElement('span');
  15411. span.innerHTML = txt + domUtils.fillChar;
  15412. if (range.collapsed) {
  15413. range.insertNode(span.cloneNode(true).firstChild).setCursor(true);
  15414. } else {
  15415. var filterFn = function(node) {
  15416. return domUtils.isBlockElm(node) && !excludeTagNameForTabKey[node.tagName.toLowerCase()]
  15417. };
  15418. //普通的情况
  15419. start = domUtils.findParent(range.startContainer, filterFn,true);
  15420. end = domUtils.findParent(range.endContainer, filterFn,true);
  15421. if (start && end && start === end) {
  15422. range.deleteContents();
  15423. range.insertNode(span.cloneNode(true).firstChild).setCursor(true);
  15424. } else {
  15425. var bookmark = range.createBookmark();
  15426. range.enlarge(true);
  15427. var bookmark2 = range.createBookmark(),
  15428. current = domUtils.getNextDomNode(bookmark2.start, false, filterFn);
  15429. while (current && !(domUtils.getPosition(current, bookmark2.end) & domUtils.POSITION_FOLLOWING)) {
  15430. current.insertBefore(span.cloneNode(true).firstChild, current.firstChild);
  15431. current = domUtils.getNextDomNode(current, false, filterFn);
  15432. }
  15433. range.moveToBookmark(bookmark2).moveToBookmark(bookmark).select();
  15434. }
  15435. }
  15436. domUtils.preventDefault(evt)
  15437. }
  15438. //trace:1634
  15439. //ff的del键在容器空的时候,也会删除
  15440. if(browser.gecko && keyCode == 46){
  15441. range = me.selection.getRange();
  15442. if(range.collapsed){
  15443. start = range.startContainer;
  15444. if(domUtils.isEmptyBlock(start)){
  15445. var parent = start.parentNode;
  15446. while(domUtils.getChildCount(parent) == 1 && !domUtils.isBody(parent)){
  15447. start = parent;
  15448. parent = parent.parentNode;
  15449. }
  15450. if(start === parent.lastChild)
  15451. evt.preventDefault();
  15452. return;
  15453. }
  15454. }
  15455. }
  15456. });
  15457. me.addListener('keyup', function(type, evt) {
  15458. var keyCode = evt.keyCode || evt.which,
  15459. rng,me = this;
  15460. if(keyCode == keymap.Backspace){
  15461. if(me.fireEvent('delkeyup')){
  15462. return;
  15463. }
  15464. rng = me.selection.getRange();
  15465. if(rng.collapsed){
  15466. var tmpNode,
  15467. autoClearTagName = ['h1','h2','h3','h4','h5','h6'];
  15468. if(tmpNode = domUtils.findParentByTagName(rng.startContainer,autoClearTagName,true)){
  15469. if(domUtils.isEmptyBlock(tmpNode)){
  15470. var pre = tmpNode.previousSibling;
  15471. if(pre && pre.nodeName != 'TABLE'){
  15472. domUtils.remove(tmpNode);
  15473. rng.setStartAtLast(pre).setCursor(false,true);
  15474. return;
  15475. }else{
  15476. var next = tmpNode.nextSibling;
  15477. if(next && next.nodeName != 'TABLE'){
  15478. domUtils.remove(tmpNode);
  15479. rng.setStartAtFirst(next).setCursor(false,true);
  15480. return;
  15481. }
  15482. }
  15483. }
  15484. }
  15485. //处理当删除到body时,要重新给p标签展位
  15486. if(domUtils.isBody(rng.startContainer)){
  15487. var tmpNode = domUtils.createElement(me.document,'p',{
  15488. 'innerHTML' : browser.ie ? domUtils.fillChar : '<br/>'
  15489. });
  15490. rng.insertNode(tmpNode).setStart(tmpNode,0).setCursor(false,true);
  15491. }
  15492. }
  15493. //chrome下如果删除了inline标签,浏览器会有记忆,在输入文字还是会套上刚才删除的标签,所以这里再选一次就不会了
  15494. if( !collapsed && (rng.startContainer.nodeType == 3 || rng.startContainer.nodeType == 1 && domUtils.isEmptyBlock(rng.startContainer))){
  15495. if(browser.ie){
  15496. var span = rng.document.createElement('span');
  15497. rng.insertNode(span).setStartBefore(span).collapse(true);
  15498. rng.select();
  15499. domUtils.remove(span)
  15500. }else{
  15501. rng.select()
  15502. }
  15503. }
  15504. }
  15505. })
  15506. };
  15507. // js/editor/_src/plugins/fiximgclick.js
  15508. ///import core
  15509. ///commands 修复chrome下图片不能点击的问题,出现八个角可改变大小
  15510. ///commandsName FixImgClick
  15511. ///commandsTitle 修复chrome下图片不能点击的问题,出现八个角可改变大小
  15512. //修复chrome下图片不能点击的问题,出现八个角可改变大小
  15513. UE.plugins['fiximgclick'] = (function () {
  15514. var elementUpdated = false;
  15515. function Scale() {
  15516. this.editor = null;
  15517. this.resizer = null;
  15518. this.cover = null;
  15519. this.doc = document;
  15520. this.prePos = {x: 0, y: 0};
  15521. this.startPos = {x: 0, y: 0};
  15522. }
  15523. (function () {
  15524. var rect = [
  15525. //[left, top, width, height]
  15526. [0, 0, -1, -1],
  15527. [0, 0, 0, -1],
  15528. [0, 0, 1, -1],
  15529. [0, 0, -1, 0],
  15530. [0, 0, 1, 0],
  15531. [0, 0, -1, 1],
  15532. [0, 0, 0, 1],
  15533. [0, 0, 1, 1]
  15534. ];
  15535. Scale.prototype = {
  15536. init: function (editor) {
  15537. var me = this;
  15538. me.editor = editor;
  15539. me.startPos = this.prePos = {x: 0, y: 0};
  15540. me.dragId = -1;
  15541. var hands = [],
  15542. cover = me.cover = document.createElement('div'),
  15543. resizer = me.resizer = document.createElement('div');
  15544. cover.id = me.editor.ui.id + '_imagescale_cover';
  15545. cover.style.cssText = 'position:absolute;display:none;z-index:' + (me.editor.options.zIndex) + ';filter:alpha(opacity=0); opacity:0;background:#CCC;';
  15546. domUtils.on(cover, 'mousedown click', function () {
  15547. me.hide();
  15548. });
  15549. for (i = 0; i < 8; i++) {
  15550. hands.push('<span class="edui-editor-imagescale-hand' + i + '"></span>');
  15551. }
  15552. resizer.id = me.editor.ui.id + '_imagescale';
  15553. resizer.className = 'edui-editor-imagescale';
  15554. resizer.innerHTML = hands.join('');
  15555. resizer.style.cssText += ';display:none;border:1px solid #3b77ff;z-index:' + (me.editor.options.zIndex) + ';';
  15556. me.editor.ui.getDom().appendChild(cover);
  15557. me.editor.ui.getDom().appendChild(resizer);
  15558. me.initStyle();
  15559. me.initEvents();
  15560. },
  15561. initStyle: function () {
  15562. utils.cssRule('imagescale', '.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;}' +
  15563. '.edui-editor-imagescale span{position:absolute;width:6px;height:6px;overflow:hidden;font-size:0px;display:block;background-color:#3C9DD0;}'
  15564. + '.edui-editor-imagescale .edui-editor-imagescale-hand0{cursor:nw-resize;top:0;margin-top:-4px;left:0;margin-left:-4px;}'
  15565. + '.edui-editor-imagescale .edui-editor-imagescale-hand1{cursor:n-resize;top:0;margin-top:-4px;left:50%;margin-left:-4px;}'
  15566. + '.edui-editor-imagescale .edui-editor-imagescale-hand2{cursor:ne-resize;top:0;margin-top:-4px;left:100%;margin-left:-3px;}'
  15567. + '.edui-editor-imagescale .edui-editor-imagescale-hand3{cursor:w-resize;top:50%;margin-top:-4px;left:0;margin-left:-4px;}'
  15568. + '.edui-editor-imagescale .edui-editor-imagescale-hand4{cursor:e-resize;top:50%;margin-top:-4px;left:100%;margin-left:-3px;}'
  15569. + '.edui-editor-imagescale .edui-editor-imagescale-hand5{cursor:sw-resize;top:100%;margin-top:-3px;left:0;margin-left:-4px;}'
  15570. + '.edui-editor-imagescale .edui-editor-imagescale-hand6{cursor:s-resize;top:100%;margin-top:-3px;left:50%;margin-left:-4px;}'
  15571. + '.edui-editor-imagescale .edui-editor-imagescale-hand7{cursor:se-resize;top:100%;margin-top:-3px;left:100%;margin-left:-3px;}');
  15572. },
  15573. initEvents: function () {
  15574. var me = this;
  15575. me.startPos.x = me.startPos.y = 0;
  15576. me.isDraging = false;
  15577. },
  15578. _eventHandler: function (e) {
  15579. var me = this;
  15580. switch (e.type) {
  15581. case 'mousedown':
  15582. var hand = e.target || e.srcElement, hand;
  15583. if (hand.className.indexOf('edui-editor-imagescale-hand') != -1 && me.dragId == -1) {
  15584. me.dragId = hand.className.slice(-1);
  15585. me.startPos.x = me.prePos.x = e.clientX;
  15586. me.startPos.y = me.prePos.y = e.clientY;
  15587. domUtils.on(me.doc,'mousemove', me.proxy(me._eventHandler, me));
  15588. }
  15589. break;
  15590. case 'mousemove':
  15591. if (me.dragId != -1) {
  15592. me.updateContainerStyle(me.dragId, {x: e.clientX - me.prePos.x, y: e.clientY - me.prePos.y});
  15593. me.prePos.x = e.clientX;
  15594. me.prePos.y = e.clientY;
  15595. elementUpdated = true;
  15596. me.updateTargetElement();
  15597. }
  15598. break;
  15599. case 'mouseup':
  15600. if (me.dragId != -1) {
  15601. me.updateContainerStyle(me.dragId, {x: e.clientX - me.prePos.x, y: e.clientY - me.prePos.y});
  15602. me.updateTargetElement();
  15603. if (me.target.parentNode) me.attachTo(me.target);
  15604. me.dragId = -1;
  15605. }
  15606. domUtils.un(me.doc,'mousemove', me.proxy(me._eventHandler, me));
  15607. //修复只是点击挪动点,但没有改变大小,不应该触发contentchange
  15608. if(elementUpdated){
  15609. elementUpdated = false;
  15610. me.editor.fireEvent('contentchange');
  15611. }
  15612. break;
  15613. default:
  15614. break;
  15615. }
  15616. },
  15617. updateTargetElement: function () {
  15618. var me = this;
  15619. domUtils.setStyles(me.target, {
  15620. 'width': me.resizer.style.width,
  15621. 'height': me.resizer.style.height
  15622. });
  15623. me.target.width = parseInt(me.resizer.style.width);
  15624. me.target.height = parseInt(me.resizer.style.height);
  15625. me.attachTo(me.target);
  15626. },
  15627. updateContainerStyle: function (dir, offset) {
  15628. var me = this,
  15629. dom = me.resizer, tmp;
  15630. if (rect[dir][0] != 0) {
  15631. tmp = parseInt(dom.style.left) + offset.x;
  15632. dom.style.left = me._validScaledProp('left', tmp) + 'px';
  15633. }
  15634. if (rect[dir][1] != 0) {
  15635. tmp = parseInt(dom.style.top) + offset.y;
  15636. dom.style.top = me._validScaledProp('top', tmp) + 'px';
  15637. }
  15638. if (rect[dir][2] != 0) {
  15639. tmp = dom.clientWidth + rect[dir][2] * offset.x;
  15640. dom.style.width = me._validScaledProp('width', tmp) + 'px';
  15641. }
  15642. if (rect[dir][3] != 0) {
  15643. tmp = dom.clientHeight + rect[dir][3] * offset.y;
  15644. dom.style.height = me._validScaledProp('height', tmp) + 'px';
  15645. }
  15646. },
  15647. _validScaledProp: function (prop, value) {
  15648. var ele = this.resizer,
  15649. wrap = document;
  15650. value = isNaN(value) ? 0 : value;
  15651. switch (prop) {
  15652. case 'left':
  15653. return value < 0 ? 0 : (value + ele.clientWidth) > wrap.clientWidth ? wrap.clientWidth - ele.clientWidth : value;
  15654. case 'top':
  15655. return value < 0 ? 0 : (value + ele.clientHeight) > wrap.clientHeight ? wrap.clientHeight - ele.clientHeight : value;
  15656. case 'width':
  15657. return value <= 0 ? 1 : (value + ele.offsetLeft) > wrap.clientWidth ? wrap.clientWidth - ele.offsetLeft : value;
  15658. case 'height':
  15659. return value <= 0 ? 1 : (value + ele.offsetTop) > wrap.clientHeight ? wrap.clientHeight - ele.offsetTop : value;
  15660. }
  15661. },
  15662. hideCover: function () {
  15663. this.cover.style.display = 'none';
  15664. },
  15665. showCover: function () {
  15666. var me = this,
  15667. editorPos = domUtils.getXY(me.editor.ui.getDom()),
  15668. iframePos = domUtils.getXY(me.editor.iframe);
  15669. domUtils.setStyles(me.cover, {
  15670. 'width': me.editor.iframe.offsetWidth + 'px',
  15671. 'height': me.editor.iframe.offsetHeight + 'px',
  15672. 'top': iframePos.y - editorPos.y + 'px',
  15673. 'left': iframePos.x - editorPos.x + 'px',
  15674. 'position': 'absolute',
  15675. 'display': ''
  15676. })
  15677. },
  15678. show: function (targetObj) {
  15679. var me = this;
  15680. me.resizer.style.display = 'block';
  15681. if(targetObj) me.attachTo(targetObj);
  15682. domUtils.on(this.resizer, 'mousedown', me.proxy(me._eventHandler, me));
  15683. domUtils.on(me.doc, 'mouseup', me.proxy(me._eventHandler, me));
  15684. me.showCover();
  15685. me.editor.fireEvent('afterscaleshow', me);
  15686. me.editor.fireEvent('saveScene');
  15687. },
  15688. hide: function () {
  15689. var me = this;
  15690. me.hideCover();
  15691. me.resizer.style.display = 'none';
  15692. domUtils.un(me.resizer, 'mousedown', me.proxy(me._eventHandler, me));
  15693. domUtils.un(me.doc, 'mouseup', me.proxy(me._eventHandler, me));
  15694. me.editor.fireEvent('afterscalehide', me);
  15695. },
  15696. proxy: function( fn, context ) {
  15697. return function(e) {
  15698. return fn.apply( context || this, arguments);
  15699. };
  15700. },
  15701. attachTo: function (targetObj) {
  15702. var me = this,
  15703. target = me.target = targetObj,
  15704. resizer = this.resizer,
  15705. imgPos = domUtils.getXY(target),
  15706. iframePos = domUtils.getXY(me.editor.iframe),
  15707. editorPos = domUtils.getXY(resizer.parentNode);
  15708. domUtils.setStyles(resizer, {
  15709. 'width': target.width + 'px',
  15710. 'height': target.height + 'px',
  15711. 'left': iframePos.x + imgPos.x - me.editor.document.body.scrollLeft - editorPos.x - parseInt(resizer.style.borderLeftWidth) + 'px',
  15712. 'top': iframePos.y + imgPos.y - me.editor.document.body.scrollTop - editorPos.y - parseInt(resizer.style.borderTopWidth) + 'px'
  15713. });
  15714. }
  15715. }
  15716. })();
  15717. return function () {
  15718. var me = this,
  15719. imageScale;
  15720. me.setOpt('imageScaleEnabled', true);
  15721. if ( !browser.ie && me.options.imageScaleEnabled) {
  15722. me.addListener('click', function (type, e) {
  15723. var range = me.selection.getRange(),
  15724. img = range.getClosedNode();
  15725. if (img && img.tagName == 'IMG' && me.body.contentEditable!="false") {
  15726. if (img.className.indexOf("edui-faked-music") != -1 ||
  15727. img.getAttribute("anchorname") ||
  15728. domUtils.hasClass(img, 'loadingclass') ||
  15729. domUtils.hasClass(img, 'loaderrorclass')) { return }
  15730. if (!imageScale) {
  15731. imageScale = new Scale();
  15732. imageScale.init(me);
  15733. me.ui.getDom().appendChild(imageScale.resizer);
  15734. var _keyDownHandler = function (e) {
  15735. imageScale.hide();
  15736. if(imageScale.target) me.selection.getRange().selectNode(imageScale.target).select();
  15737. }, _mouseDownHandler = function (e) {
  15738. var ele = e.target || e.srcElement;
  15739. if (ele && (ele.className===undefined || ele.className.indexOf('edui-editor-imagescale') == -1)) {
  15740. _keyDownHandler(e);
  15741. }
  15742. }, timer;
  15743. me.addListener('afterscaleshow', function (e) {
  15744. me.addListener('beforekeydown', _keyDownHandler);
  15745. me.addListener('beforemousedown', _mouseDownHandler);
  15746. domUtils.on(document, 'keydown', _keyDownHandler);
  15747. domUtils.on(document,'mousedown', _mouseDownHandler);
  15748. me.selection.getNative().removeAllRanges();
  15749. });
  15750. me.addListener('afterscalehide', function (e) {
  15751. me.removeListener('beforekeydown', _keyDownHandler);
  15752. me.removeListener('beforemousedown', _mouseDownHandler);
  15753. domUtils.un(document, 'keydown', _keyDownHandler);
  15754. domUtils.un(document,'mousedown', _mouseDownHandler);
  15755. var target = imageScale.target;
  15756. if (target.parentNode) {
  15757. me.selection.getRange().selectNode(target).select();
  15758. }
  15759. });
  15760. //TODO 有iframe的情况,mousedown不能往下传。。
  15761. domUtils.on(imageScale.resizer, 'mousedown', function (e) {
  15762. me.selection.getNative().removeAllRanges();
  15763. var ele = e.target || e.srcElement;
  15764. if (ele && ele.className.indexOf('edui-editor-imagescale-hand') == -1) {
  15765. timer = setTimeout(function () {
  15766. imageScale.hide();
  15767. if(imageScale.target) me.selection.getRange().selectNode(ele).select();
  15768. }, 200);
  15769. }
  15770. });
  15771. domUtils.on(imageScale.resizer, 'mouseup', function (e) {
  15772. var ele = e.target || e.srcElement;
  15773. if (ele && ele.className.indexOf('edui-editor-imagescale-hand') == -1) {
  15774. clearTimeout(timer);
  15775. }
  15776. });
  15777. }
  15778. imageScale.show(img);
  15779. } else {
  15780. if (imageScale && imageScale.resizer.style.display != 'none') imageScale.hide();
  15781. }
  15782. });
  15783. }
  15784. if (browser.webkit) {
  15785. me.addListener('click', function (type, e) {
  15786. if (e.target.tagName == 'IMG' && me.body.contentEditable!="false") {
  15787. var range = new dom.Range(me.document);
  15788. range.selectNode(e.target).select();
  15789. }
  15790. });
  15791. }
  15792. }
  15793. })();
  15794. // js/editor/_src/plugins/autolink.js
  15795. ///import core
  15796. ///commands 为非ie浏览器自动添加a标签
  15797. ///commandsName AutoLink
  15798. ///commandsTitle 自动增加链接
  15799. /**
  15800. * @description 为非ie浏览器自动添加a标签
  15801. * @author zhanyi
  15802. */
  15803. UE.plugin.register('autolink',function(){
  15804. var cont = 0;
  15805. return !browser.ie ? {
  15806. bindEvents:{
  15807. 'reset' : function(){
  15808. cont = 0;
  15809. },
  15810. 'keydown':function(type, evt) {
  15811. var me = this;
  15812. var keyCode = evt.keyCode || evt.which;
  15813. if (keyCode == 32 || keyCode == 13) {
  15814. var sel = me.selection.getNative(),
  15815. range = sel.getRangeAt(0).cloneRange(),
  15816. offset,
  15817. charCode;
  15818. var start = range.startContainer;
  15819. while (start.nodeType == 1 && range.startOffset > 0) {
  15820. start = range.startContainer.childNodes[range.startOffset - 1];
  15821. if (!start){
  15822. break;
  15823. }
  15824. range.setStart(start, start.nodeType == 1 ? start.childNodes.length : start.nodeValue.length);
  15825. range.collapse(true);
  15826. start = range.startContainer;
  15827. }
  15828. do{
  15829. if (range.startOffset == 0) {
  15830. start = range.startContainer.previousSibling;
  15831. while (start && start.nodeType == 1) {
  15832. start = start.lastChild;
  15833. }
  15834. if (!start || domUtils.isFillChar(start)){
  15835. break;
  15836. }
  15837. offset = start.nodeValue.length;
  15838. } else {
  15839. start = range.startContainer;
  15840. offset = range.startOffset;
  15841. }
  15842. range.setStart(start, offset - 1);
  15843. charCode = range.toString().charCodeAt(0);
  15844. } while (charCode != 160 && charCode != 32);
  15845. if (range.toString().replace(new RegExp(domUtils.fillChar, 'g'), '').match(/(?:https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.)/i)) {
  15846. while(range.toString().length){
  15847. if(/^(?:https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.)/i.test(range.toString())){
  15848. break;
  15849. }
  15850. try{
  15851. range.setStart(range.startContainer,range.startOffset+1);
  15852. }catch(e){
  15853. //trace:2121
  15854. var start = range.startContainer;
  15855. while(!(next = start.nextSibling)){
  15856. if(domUtils.isBody(start)){
  15857. return;
  15858. }
  15859. start = start.parentNode;
  15860. }
  15861. range.setStart(next,0);
  15862. }
  15863. }
  15864. //range的开始边界已经在a标签里的不再处理
  15865. if(domUtils.findParentByTagName(range.startContainer,'a',true)){
  15866. return;
  15867. }
  15868. var a = me.document.createElement('a'),text = me.document.createTextNode(' '),href;
  15869. me.undoManger && me.undoManger.save();
  15870. a.appendChild(range.extractContents());
  15871. a.href = a.innerHTML = a.innerHTML.replace(/<[^>]+>/g,'');
  15872. href = a.getAttribute("href").replace(new RegExp(domUtils.fillChar,'g'),'');
  15873. href = /^(?:https?:\/\/)/ig.test(href) ? href : "http://"+ href;
  15874. a.setAttribute('_src',utils.html(href));
  15875. a.href = utils.html(href);
  15876. range.insertNode(a);
  15877. a.parentNode.insertBefore(text, a.nextSibling);
  15878. range.setStart(text, 0);
  15879. range.collapse(true);
  15880. sel.removeAllRanges();
  15881. sel.addRange(range);
  15882. me.undoManger && me.undoManger.save();
  15883. }
  15884. }
  15885. }
  15886. }
  15887. }:{}
  15888. },function(){
  15889. var keyCodes = {
  15890. 37:1, 38:1, 39:1, 40:1,
  15891. 13:1,32:1
  15892. };
  15893. function checkIsCludeLink(node){
  15894. if(node.nodeType == 3){
  15895. return null
  15896. }
  15897. if(node.nodeName == 'A'){
  15898. return node;
  15899. }
  15900. var lastChild = node.lastChild;
  15901. while(lastChild){
  15902. if(lastChild.nodeName == 'A'){
  15903. return lastChild;
  15904. }
  15905. if(lastChild.nodeType == 3){
  15906. if(domUtils.isWhitespace(lastChild)){
  15907. lastChild = lastChild.previousSibling;
  15908. continue;
  15909. }
  15910. return null
  15911. }
  15912. lastChild = lastChild.lastChild;
  15913. }
  15914. }
  15915. browser.ie && this.addListener('keyup',function(cmd,evt){
  15916. var me = this,keyCode = evt.keyCode;
  15917. if(keyCodes[keyCode]){
  15918. var rng = me.selection.getRange();
  15919. var start = rng.startContainer;
  15920. if(keyCode == 13){
  15921. while(start && !domUtils.isBody(start) && !domUtils.isBlockElm(start)){
  15922. start = start.parentNode;
  15923. }
  15924. if(start && !domUtils.isBody(start) && start.nodeName == 'P'){
  15925. var pre = start.previousSibling;
  15926. if(pre && pre.nodeType == 1){
  15927. var pre = checkIsCludeLink(pre);
  15928. if(pre && !pre.getAttribute('_href')){
  15929. domUtils.remove(pre,true);
  15930. }
  15931. }
  15932. }
  15933. }else if(keyCode == 32 ){
  15934. if(start.nodeType == 3 && /^\s$/.test(start.nodeValue)){
  15935. start = start.previousSibling;
  15936. if(start && start.nodeName == 'A' && !start.getAttribute('_href')){
  15937. domUtils.remove(start,true);
  15938. }
  15939. }
  15940. }else {
  15941. start = domUtils.findParentByTagName(start,'a',true);
  15942. if(start && !start.getAttribute('_href')){
  15943. var bk = rng.createBookmark();
  15944. domUtils.remove(start,true);
  15945. rng.moveToBookmark(bk).select(true)
  15946. }
  15947. }
  15948. }
  15949. });
  15950. }
  15951. );
  15952. // js/editor/_src/plugins/autoheight.js
  15953. ///import core
  15954. ///commands 当输入内容超过编辑器高度时,编辑器自动增高
  15955. ///commandsName AutoHeight,autoHeightEnabled
  15956. ///commandsTitle 自动增高
  15957. /**
  15958. * @description 自动伸展
  15959. * @author zhanyi
  15960. */
  15961. UE.plugins['autoheight'] = function () {
  15962. var me = this;
  15963. //提供开关,就算加载也可以关闭
  15964. me.autoHeightEnabled = me.options.autoHeightEnabled !== false;
  15965. if (!me.autoHeightEnabled) {
  15966. return;
  15967. }
  15968. var bakOverflow,
  15969. lastHeight = 0,
  15970. options = me.options,
  15971. currentHeight,
  15972. timer;
  15973. function adjustHeight() {
  15974. var me = this;
  15975. clearTimeout(timer);
  15976. if(isFullscreen)return;
  15977. if (!me.queryCommandState || me.queryCommandState && me.queryCommandState('source') != 1) {
  15978. timer = setTimeout(function(){
  15979. var node = me.body.lastChild;
  15980. while(node && node.nodeType != 1){
  15981. node = node.previousSibling;
  15982. }
  15983. if(node && node.nodeType == 1){
  15984. node.style.clear = 'both';
  15985. currentHeight = Math.max(domUtils.getXY(node).y + node.offsetHeight + 25 ,Math.max(options.minFrameHeight, options.initialFrameHeight)) ;
  15986. if (currentHeight != lastHeight) {
  15987. if (currentHeight !== parseInt(me.iframe.parentNode.style.height)) {
  15988. me.iframe.parentNode.style.height = currentHeight + 'px';
  15989. }
  15990. me.body.style.height = currentHeight + 'px';
  15991. lastHeight = currentHeight;
  15992. }
  15993. domUtils.removeStyle(node,'clear');
  15994. }
  15995. },50)
  15996. }
  15997. }
  15998. var isFullscreen;
  15999. me.addListener('fullscreenchanged',function(cmd,f){
  16000. isFullscreen = f
  16001. });
  16002. me.addListener('destroy', function () {
  16003. me.removeListener('contentchange afterinserthtml keyup mouseup',adjustHeight)
  16004. });
  16005. me.enableAutoHeight = function () {
  16006. var me = this;
  16007. if (!me.autoHeightEnabled) {
  16008. return;
  16009. }
  16010. var doc = me.document;
  16011. me.autoHeightEnabled = true;
  16012. bakOverflow = doc.body.style.overflowY;
  16013. doc.body.style.overflowY = 'hidden';
  16014. me.addListener('contentchange afterinserthtml keyup mouseup',adjustHeight);
  16015. //ff不给事件算得不对
  16016. setTimeout(function () {
  16017. adjustHeight.call(me);
  16018. }, browser.gecko ? 100 : 0);
  16019. me.fireEvent('autoheightchanged', me.autoHeightEnabled);
  16020. };
  16021. me.disableAutoHeight = function () {
  16022. me.body.style.overflowY = bakOverflow || '';
  16023. me.removeListener('contentchange', adjustHeight);
  16024. me.removeListener('keyup', adjustHeight);
  16025. me.removeListener('mouseup', adjustHeight);
  16026. me.autoHeightEnabled = false;
  16027. me.fireEvent('autoheightchanged', me.autoHeightEnabled);
  16028. };
  16029. me.on('setHeight',function(){
  16030. me.disableAutoHeight()
  16031. });
  16032. me.addListener('ready', function () {
  16033. me.enableAutoHeight();
  16034. //trace:1764
  16035. var timer;
  16036. domUtils.on(browser.ie ? me.body : me.document, browser.webkit ? 'dragover' : 'drop', function () {
  16037. clearTimeout(timer);
  16038. timer = setTimeout(function () {
  16039. //trace:3681
  16040. adjustHeight.call(me);
  16041. }, 100);
  16042. });
  16043. //修复内容过多时,回到顶部,顶部内容被工具栏遮挡问题
  16044. var lastScrollY;
  16045. window.onscroll = function(){
  16046. if(lastScrollY === null){
  16047. lastScrollY = this.scrollY
  16048. }else if(this.scrollY == 0 && lastScrollY != 0){
  16049. me.window.scrollTo(0,0);
  16050. lastScrollY = null;
  16051. }
  16052. }
  16053. });
  16054. };
  16055. // js/editor/_src/plugins/autofloat.js
  16056. ///import core
  16057. ///commands 悬浮工具栏
  16058. ///commandsName AutoFloat,autoFloatEnabled
  16059. ///commandsTitle 悬浮工具栏
  16060. /**
  16061. * modified by chengchao01
  16062. * 注意: 引入此功能后,在IE6下会将body的背景图片覆盖掉!
  16063. */
  16064. UE.plugins['autofloat'] = function() {
  16065. var me = this,
  16066. lang = me.getLang();
  16067. me.setOpt({
  16068. topOffset:0
  16069. });
  16070. var optsAutoFloatEnabled = me.options.autoFloatEnabled !== false,
  16071. topOffset = me.options.topOffset;
  16072. //如果不固定toolbar的位置,则直接退出
  16073. if(!optsAutoFloatEnabled){
  16074. return;
  16075. }
  16076. var uiUtils = UE.ui.uiUtils,
  16077. LteIE6 = browser.ie && browser.version <= 6,
  16078. quirks = browser.quirks;
  16079. function checkHasUI(){
  16080. if(!UE.ui){
  16081. alert(lang.autofloatMsg);
  16082. return 0;
  16083. }
  16084. return 1;
  16085. }
  16086. function fixIE6FixedPos(){
  16087. var docStyle = document.body.style;
  16088. docStyle.backgroundImage = 'url("about:blank")';
  16089. docStyle.backgroundAttachment = 'fixed';
  16090. }
  16091. var bakCssText,
  16092. placeHolder = document.createElement('div'),
  16093. toolbarBox,orgTop,
  16094. getPosition,
  16095. flag =true; //ie7模式下需要偏移
  16096. function setFloating(){
  16097. var toobarBoxPos = domUtils.getXY(toolbarBox),
  16098. origalFloat = domUtils.getComputedStyle(toolbarBox,'position'),
  16099. origalLeft = domUtils.getComputedStyle(toolbarBox,'left');
  16100. toolbarBox.style.width = toolbarBox.offsetWidth + 'px';
  16101. toolbarBox.style.zIndex = me.options.zIndex * 1 + 1;
  16102. toolbarBox.parentNode.insertBefore(placeHolder, toolbarBox);
  16103. if (LteIE6 || (quirks && browser.ie)) {
  16104. if(toolbarBox.style.position != 'absolute'){
  16105. toolbarBox.style.position = 'absolute';
  16106. }
  16107. toolbarBox.style.top = (document.body.scrollTop||document.documentElement.scrollTop) - orgTop + topOffset + 'px';
  16108. } else {
  16109. if (browser.ie7Compat && flag) {
  16110. flag = false;
  16111. toolbarBox.style.left = domUtils.getXY(toolbarBox).x - document.documentElement.getBoundingClientRect().left+2 + 'px';
  16112. }
  16113. if(toolbarBox.style.position != 'fixed'){
  16114. toolbarBox.style.position = 'fixed';
  16115. toolbarBox.style.top = topOffset +"px";
  16116. ((origalFloat == 'absolute' || origalFloat == 'relative') && parseFloat(origalLeft)) && (toolbarBox.style.left = toobarBoxPos.x + 'px');
  16117. }
  16118. }
  16119. }
  16120. function unsetFloating(){
  16121. flag = true;
  16122. if(placeHolder.parentNode){
  16123. placeHolder.parentNode.removeChild(placeHolder);
  16124. }
  16125. toolbarBox.style.cssText = bakCssText;
  16126. }
  16127. function updateFloating(){
  16128. var rect3 = getPosition(me.container);
  16129. var offset=me.options.toolbarTopOffset||0;
  16130. if (rect3.top < 0 && rect3.bottom - toolbarBox.offsetHeight > offset) {
  16131. setFloating();
  16132. }else{
  16133. unsetFloating();
  16134. }
  16135. }
  16136. var defer_updateFloating = utils.defer(function(){
  16137. updateFloating();
  16138. },browser.ie ? 200 : 100,true);
  16139. me.addListener('destroy',function(){
  16140. domUtils.un(window, ['scroll','resize'], updateFloating);
  16141. me.removeListener('keydown', defer_updateFloating);
  16142. });
  16143. me.addListener('ready', function(){
  16144. if(checkHasUI(me)){
  16145. //加载了ui组件,但在new时,没有加载ui,导致编辑器实例上没有ui类,所以这里做判断
  16146. if(!me.ui){
  16147. return;
  16148. }
  16149. getPosition = uiUtils.getClientRect;
  16150. toolbarBox = me.ui.getDom('toolbarbox');
  16151. orgTop = getPosition(toolbarBox).top;
  16152. bakCssText = toolbarBox.style.cssText;
  16153. placeHolder.style.height = toolbarBox.offsetHeight + 'px';
  16154. if(LteIE6){
  16155. fixIE6FixedPos();
  16156. }
  16157. domUtils.on(window, ['scroll','resize'], updateFloating);
  16158. me.addListener('keydown', defer_updateFloating);
  16159. me.addListener('beforefullscreenchange', function (t, enabled){
  16160. if (enabled) {
  16161. unsetFloating();
  16162. }
  16163. });
  16164. me.addListener('fullscreenchanged', function (t, enabled){
  16165. if (!enabled) {
  16166. updateFloating();
  16167. }
  16168. });
  16169. me.addListener('sourcemodechanged', function (t, enabled){
  16170. setTimeout(function (){
  16171. updateFloating();
  16172. },0);
  16173. });
  16174. me.addListener("clearDoc",function(){
  16175. setTimeout(function(){
  16176. updateFloating();
  16177. },0);
  16178. })
  16179. }
  16180. });
  16181. };
  16182. // js/editor/_src/plugins/video.js
  16183. /**
  16184. * video插件, 为UEditor提供视频插入支持
  16185. * @file
  16186. * @since 1.2.6.1
  16187. */
  16188. UE.plugins['video'] = function (){
  16189. var me =this;
  16190. /**
  16191. * 创建插入视频字符窜
  16192. * @param url 视频地址
  16193. * @param width 视频宽度
  16194. * @param height 视频高度
  16195. * @param align 视频对齐
  16196. * @param toEmbed 是否以flash代替显示
  16197. * @param addParagraph 是否需要添加P 标签
  16198. */
  16199. function creatInsertStr(url,width,height,id,align,classname,type){
  16200. var str;
  16201. switch (type){
  16202. case 'image':
  16203. str = '<img ' + (id ? 'id="' + id+'"' : '') + ' width="'+ width +'" height="' + height + '" _url="'+url+'" class="' + classname.replace(/\bvideo-js\b/, '') + '"' +
  16204. ' src="' + me.options.UEDITOR_HOME_URL+'themes/default/images/spacer.gif" style="background:url('+me.options.UEDITOR_HOME_URL+'themes/default/images/videologo.gif) no-repeat center center; border:1px solid gray;'+(align ? 'float:' + align + ';': '')+'" />'
  16205. break;
  16206. case 'embed':
  16207. str = '<embed type="application/x-shockwave-flash" class="' + classname + '" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  16208. ' src="' + utils.html(url) + '" width="' + width + '" height="' + height + '"' + (align ? ' style="float:' + align + '"': '') +
  16209. ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >';
  16210. break;
  16211. case 'video':
  16212. var ext = url.substr(url.lastIndexOf('.') + 1);
  16213. if(ext == 'ogv') ext = 'ogg';
  16214. str = '<video' + (id ? ' id="' + id + '"' : '') + ' class="' + classname + ' video-js" ' + (align ? ' style="float:' + align + '"': '') +
  16215. ' controls preload="none" width="' + width + '" height="' + height + '" src="' + url + '" data-setup="{}">' +
  16216. '<source src="' + url + '" type="video/' + ext + '" /></video>';
  16217. break;
  16218. }
  16219. return str;
  16220. }
  16221. function switchImgAndVideo(root,img2video){
  16222. utils.each(root.getNodesByTagName(img2video ? 'img' : 'embed video'),function(node){
  16223. var className = node.getAttr('class');
  16224. if(className && className.indexOf('edui-faked-video') != -1){
  16225. var html = creatInsertStr( img2video ? node.getAttr('_url') : node.getAttr('src'),node.getAttr('width'),node.getAttr('height'),null,node.getStyle('float') || '',className,img2video ? 'embed':'image');
  16226. node.parentNode.replaceChild(UE.uNode.createElement(html),node);
  16227. }
  16228. if(className && className.indexOf('edui-upload-video') != -1){
  16229. var html = creatInsertStr( img2video ? node.getAttr('_url') : node.getAttr('src'),node.getAttr('width'),node.getAttr('height'),null,node.getStyle('float') || '',className,img2video ? 'video':'image');
  16230. node.parentNode.replaceChild(UE.uNode.createElement(html),node);
  16231. }
  16232. })
  16233. }
  16234. me.addOutputRule(function(root){
  16235. switchImgAndVideo(root,true)
  16236. });
  16237. me.addInputRule(function(root){
  16238. switchImgAndVideo(root)
  16239. });
  16240. /**
  16241. * 插入视频
  16242. * @command insertvideo
  16243. * @method execCommand
  16244. * @param { String } cmd 命令字符串
  16245. * @param { Object } videoAttr 键值对对象, 描述一个视频的所有属性
  16246. * @example
  16247. * ```javascript
  16248. *
  16249. * var videoAttr = {
  16250. * //视频地址
  16251. * url: 'http://www.youku.com/xxx',
  16252. * //视频宽高值, 单位px
  16253. * width: 200,
  16254. * height: 100
  16255. * };
  16256. *
  16257. * //editor 是编辑器实例
  16258. * //向编辑器插入单个视频
  16259. * editor.execCommand( 'insertvideo', videoAttr );
  16260. * ```
  16261. */
  16262. /**
  16263. * 插入视频
  16264. * @command insertvideo
  16265. * @method execCommand
  16266. * @param { String } cmd 命令字符串
  16267. * @param { Array } videoArr 需要插入的视频的数组, 其中的每一个元素都是一个键值对对象, 描述了一个视频的所有属性
  16268. * @example
  16269. * ```javascript
  16270. *
  16271. * var videoAttr1 = {
  16272. * //视频地址
  16273. * url: 'http://www.youku.com/xxx',
  16274. * //视频宽高值, 单位px
  16275. * width: 200,
  16276. * height: 100
  16277. * },
  16278. * videoAttr2 = {
  16279. * //视频地址
  16280. * url: 'http://www.youku.com/xxx',
  16281. * //视频宽高值, 单位px
  16282. * width: 200,
  16283. * height: 100
  16284. * }
  16285. *
  16286. * //editor 是编辑器实例
  16287. * //该方法将会向编辑器内插入两个视频
  16288. * editor.execCommand( 'insertvideo', [ videoAttr1, videoAttr2 ] );
  16289. * ```
  16290. */
  16291. /**
  16292. * 查询当前光标所在处是否是一个视频
  16293. * @command insertvideo
  16294. * @method queryCommandState
  16295. * @param { String } cmd 需要查询的命令字符串
  16296. * @return { int } 如果当前光标所在处的元素是一个视频对象, 则返回1,否则返回0
  16297. * @example
  16298. * ```javascript
  16299. *
  16300. * //editor 是编辑器实例
  16301. * editor.queryCommandState( 'insertvideo' );
  16302. * ```
  16303. */
  16304. me.commands["insertvideo"] = {
  16305. execCommand: function (cmd, videoObjs, type){
  16306. videoObjs = utils.isArray(videoObjs)?videoObjs:[videoObjs];
  16307. var html = [],id = 'tmpVedio', cl;
  16308. for(var i=0,vi,len = videoObjs.length;i<len;i++){
  16309. vi = videoObjs[i];
  16310. cl = (type == 'upload' ? 'edui-upload-video video-js vjs-default-skin':'edui-faked-video');
  16311. html.push(creatInsertStr( vi.url, vi.width || 420, vi.height || 280, id + i, null, cl, 'image'));
  16312. }
  16313. me.execCommand("inserthtml",html.join(""),true);
  16314. var rng = this.selection.getRange();
  16315. for(var i= 0,len=videoObjs.length;i<len;i++){
  16316. var img = this.document.getElementById('tmpVedio'+i);
  16317. domUtils.removeAttributes(img,'id');
  16318. rng.selectNode(img).select();
  16319. me.execCommand('imagefloat',videoObjs[i].align)
  16320. }
  16321. },
  16322. queryCommandState : function(){
  16323. var img = me.selection.getRange().getClosedNode(),
  16324. flag = img && (img.className == "edui-faked-video" || img.className.indexOf("edui-upload-video")!=-1);
  16325. return flag ? 1 : 0;
  16326. }
  16327. };
  16328. };
  16329. // js/editor/_src/plugins/table.core.js
  16330. /**
  16331. * Created with JetBrains WebStorm.
  16332. * User: taoqili
  16333. * Date: 13-1-18
  16334. * Time: 上午11:09
  16335. * To change this template use File | Settings | File Templates.
  16336. */
  16337. /**
  16338. * UE表格操作类
  16339. * @param table
  16340. * @constructor
  16341. */
  16342. (function () {
  16343. var UETable = UE.UETable = function (table) {
  16344. this.table = table;
  16345. this.indexTable = [];
  16346. this.selectedTds = [];
  16347. this.cellsRange = {};
  16348. this.update(table);
  16349. };
  16350. //===以下为静态工具方法===
  16351. UETable.removeSelectedClass = function (cells) {
  16352. utils.each(cells, function (cell) {
  16353. domUtils.removeClasses(cell, "selectTdClass");
  16354. })
  16355. };
  16356. UETable.addSelectedClass = function (cells) {
  16357. utils.each(cells, function (cell) {
  16358. domUtils.addClass(cell, "selectTdClass");
  16359. })
  16360. };
  16361. UETable.isEmptyBlock = function (node) {
  16362. var reg = new RegExp(domUtils.fillChar, 'g');
  16363. if (node[browser.ie ? 'innerText' : 'textContent'].replace(/^\s*$/, '').replace(reg, '').length > 0) {
  16364. return 0;
  16365. }
  16366. for (var i in dtd.$isNotEmpty) if (dtd.$isNotEmpty.hasOwnProperty(i)) {
  16367. if (node.getElementsByTagName(i).length) {
  16368. return 0;
  16369. }
  16370. }
  16371. return 1;
  16372. };
  16373. UETable.getWidth = function (cell) {
  16374. if (!cell)return 0;
  16375. return parseInt(domUtils.getComputedStyle(cell, "width"), 10);
  16376. };
  16377. /**
  16378. * 获取单元格或者单元格组的“对齐”状态。 如果当前的检测对象是一个单元格组, 只有在满足所有单元格的 水平和竖直 对齐属性都相同的
  16379. * 条件时才会返回其状态值,否则将返回null; 如果当前只检测了一个单元格, 则直接返回当前单元格的对齐状态;
  16380. * @param table cell or table cells , 支持单个单元格dom对象 或者 单元格dom对象数组
  16381. * @return { align: 'left' || 'right' || 'center', valign: 'top' || 'middle' || 'bottom' } 或者 null
  16382. */
  16383. UETable.getTableCellAlignState = function ( cells ) {
  16384. !utils.isArray( cells ) && ( cells = [cells] );
  16385. var result = {},
  16386. status = ['align', 'valign'],
  16387. tempStatus = null,
  16388. isSame = true;//状态是否相同
  16389. utils.each( cells, function( cellNode ){
  16390. utils.each( status, function( currentState ){
  16391. tempStatus = cellNode.getAttribute( currentState );
  16392. if( !result[ currentState ] && tempStatus ) {
  16393. result[ currentState ] = tempStatus;
  16394. } else if( !result[ currentState ] || ( tempStatus !== result[ currentState ] ) ) {
  16395. isSame = false;
  16396. return false;
  16397. }
  16398. } );
  16399. return isSame;
  16400. });
  16401. return isSame ? result : null;
  16402. };
  16403. /**
  16404. * 根据当前选区获取相关的table信息
  16405. * @return {Object}
  16406. */
  16407. UETable.getTableItemsByRange = function (editor) {
  16408. var start = editor.selection.getStart();
  16409. //ff下会选中bookmark
  16410. if( start && start.id && start.id.indexOf('_baidu_bookmark_start_') === 0 && start.nextSibling) {
  16411. start = start.nextSibling;
  16412. }
  16413. //在table或者td边缘有可能存在选中tr的情况
  16414. var cell = start && domUtils.findParentByTagName(start, ["td", "th"], true),
  16415. tr = cell && cell.parentNode,
  16416. caption = start && domUtils.findParentByTagName(start, 'caption', true),
  16417. table = caption ? caption.parentNode : tr && tr.parentNode.parentNode;
  16418. return {
  16419. cell:cell,
  16420. tr:tr,
  16421. table:table,
  16422. caption:caption
  16423. }
  16424. };
  16425. UETable.getUETableBySelected = function (editor) {
  16426. var table = UETable.getTableItemsByRange(editor).table;
  16427. if (table && table.ueTable && table.ueTable.selectedTds.length) {
  16428. return table.ueTable;
  16429. }
  16430. return null;
  16431. };
  16432. UETable.getDefaultValue = function (editor, table) {
  16433. var borderMap = {
  16434. thin:'0px',
  16435. medium:'1px',
  16436. thick:'2px'
  16437. },
  16438. tableBorder, tdPadding, tdBorder, tmpValue;
  16439. if (!table) {
  16440. table = editor.document.createElement('table');
  16441. table.insertRow(0).insertCell(0).innerHTML = 'xxx';
  16442. editor.body.appendChild(table);
  16443. var td = table.getElementsByTagName('td')[0];
  16444. tmpValue = domUtils.getComputedStyle(table, 'border-left-width');
  16445. tableBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16446. tmpValue = domUtils.getComputedStyle(td, 'padding-left');
  16447. tdPadding = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16448. tmpValue = domUtils.getComputedStyle(td, 'border-left-width');
  16449. tdBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16450. domUtils.remove(table);
  16451. return {
  16452. tableBorder:tableBorder,
  16453. tdPadding:tdPadding,
  16454. tdBorder:tdBorder
  16455. };
  16456. } else {
  16457. td = table.getElementsByTagName('td')[0];
  16458. tmpValue = domUtils.getComputedStyle(table, 'border-left-width');
  16459. tableBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16460. tmpValue = domUtils.getComputedStyle(td, 'padding-left');
  16461. tdPadding = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16462. tmpValue = domUtils.getComputedStyle(td, 'border-left-width');
  16463. tdBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16464. return {
  16465. tableBorder:tableBorder,
  16466. tdPadding:tdPadding,
  16467. tdBorder:tdBorder
  16468. };
  16469. }
  16470. };
  16471. /**
  16472. * 根据当前点击的td或者table获取索引对象
  16473. * @param tdOrTable
  16474. */
  16475. UETable.getUETable = function (tdOrTable) {
  16476. var tag = tdOrTable.tagName.toLowerCase();
  16477. tdOrTable = (tag == "td" || tag == "th" || tag == 'caption') ? domUtils.findParentByTagName(tdOrTable, "table", true) : tdOrTable;
  16478. if (!tdOrTable.ueTable) {
  16479. tdOrTable.ueTable = new UETable(tdOrTable);
  16480. }
  16481. return tdOrTable.ueTable;
  16482. };
  16483. UETable.cloneCell = function(cell,ignoreMerge,keepPro){
  16484. if (!cell || utils.isString(cell)) {
  16485. return this.table.ownerDocument.createElement(cell || 'td');
  16486. }
  16487. var flag = domUtils.hasClass(cell, "selectTdClass");
  16488. flag && domUtils.removeClasses(cell, "selectTdClass");
  16489. var tmpCell = cell.cloneNode(true);
  16490. if (ignoreMerge) {
  16491. tmpCell.rowSpan = tmpCell.colSpan = 1;
  16492. }
  16493. //去掉宽高
  16494. !keepPro && domUtils.removeAttributes(tmpCell,'width height');
  16495. !keepPro && domUtils.removeAttributes(tmpCell,'style');
  16496. tmpCell.style.borderLeftStyle = "";
  16497. tmpCell.style.borderTopStyle = "";
  16498. tmpCell.style.borderLeftColor = cell.style.borderRightColor;
  16499. tmpCell.style.borderLeftWidth = cell.style.borderRightWidth;
  16500. tmpCell.style.borderTopColor = cell.style.borderBottomColor;
  16501. tmpCell.style.borderTopWidth = cell.style.borderBottomWidth;
  16502. flag && domUtils.addClass(cell, "selectTdClass");
  16503. return tmpCell;
  16504. }
  16505. UETable.prototype = {
  16506. getMaxRows:function () {
  16507. var rows = this.table.rows, maxLen = 1;
  16508. for (var i = 0, row; row = rows[i]; i++) {
  16509. var currentMax = 1;
  16510. for (var j = 0, cj; cj = row.cells[j++];) {
  16511. currentMax = Math.max(cj.rowSpan || 1, currentMax);
  16512. }
  16513. maxLen = Math.max(currentMax + i, maxLen);
  16514. }
  16515. return maxLen;
  16516. },
  16517. /**
  16518. * 获取当前表格的最大列数
  16519. */
  16520. getMaxCols:function () {
  16521. var rows = this.table.rows, maxLen = 0, cellRows = {};
  16522. for (var i = 0, row; row = rows[i]; i++) {
  16523. var cellsNum = 0;
  16524. for (var j = 0, cj; cj = row.cells[j++];) {
  16525. cellsNum += (cj.colSpan || 1);
  16526. if (cj.rowSpan && cj.rowSpan > 1) {
  16527. for (var k = 1; k < cj.rowSpan; k++) {
  16528. if (!cellRows['row_' + (i + k)]) {
  16529. cellRows['row_' + (i + k)] = (cj.colSpan || 1);
  16530. } else {
  16531. cellRows['row_' + (i + k)]++
  16532. }
  16533. }
  16534. }
  16535. }
  16536. cellsNum += cellRows['row_' + i] || 0;
  16537. maxLen = Math.max(cellsNum, maxLen);
  16538. }
  16539. return maxLen;
  16540. },
  16541. getCellColIndex:function (cell) {
  16542. },
  16543. /**
  16544. * 获取当前cell旁边的单元格,
  16545. * @param cell
  16546. * @param right
  16547. */
  16548. getHSideCell:function (cell, right) {
  16549. try {
  16550. var cellInfo = this.getCellInfo(cell),
  16551. previewRowIndex, previewColIndex;
  16552. var len = this.selectedTds.length,
  16553. range = this.cellsRange;
  16554. //首行或者首列没有前置单元格
  16555. if ((!right && (!len ? !cellInfo.colIndex : !range.beginColIndex)) || (right && (!len ? (cellInfo.colIndex == (this.colsNum - 1)) : (range.endColIndex == this.colsNum - 1)))) return null;
  16556. previewRowIndex = !len ? cellInfo.rowIndex : range.beginRowIndex;
  16557. previewColIndex = !right ? ( !len ? (cellInfo.colIndex < 1 ? 0 : (cellInfo.colIndex - 1)) : range.beginColIndex - 1)
  16558. : ( !len ? cellInfo.colIndex + 1 : range.endColIndex + 1);
  16559. return this.getCell(this.indexTable[previewRowIndex][previewColIndex].rowIndex, this.indexTable[previewRowIndex][previewColIndex].cellIndex);
  16560. } catch (e) {
  16561. showError(e);
  16562. }
  16563. },
  16564. getTabNextCell:function (cell, preRowIndex) {
  16565. var cellInfo = this.getCellInfo(cell),
  16566. rowIndex = preRowIndex || cellInfo.rowIndex,
  16567. colIndex = cellInfo.colIndex + 1 + (cellInfo.colSpan - 1),
  16568. nextCell;
  16569. try {
  16570. nextCell = this.getCell(this.indexTable[rowIndex][colIndex].rowIndex, this.indexTable[rowIndex][colIndex].cellIndex);
  16571. } catch (e) {
  16572. try {
  16573. rowIndex = rowIndex * 1 + 1;
  16574. colIndex = 0;
  16575. nextCell = this.getCell(this.indexTable[rowIndex][colIndex].rowIndex, this.indexTable[rowIndex][colIndex].cellIndex);
  16576. } catch (e) {
  16577. }
  16578. }
  16579. return nextCell;
  16580. },
  16581. /**
  16582. * 获取视觉上的后置单元格
  16583. * @param cell
  16584. * @param bottom
  16585. */
  16586. getVSideCell:function (cell, bottom, ignoreRange) {
  16587. try {
  16588. var cellInfo = this.getCellInfo(cell),
  16589. nextRowIndex, nextColIndex;
  16590. var len = this.selectedTds.length && !ignoreRange,
  16591. range = this.cellsRange;
  16592. //末行或者末列没有后置单元格
  16593. if ((!bottom && (cellInfo.rowIndex == 0)) || (bottom && (!len ? (cellInfo.rowIndex + cellInfo.rowSpan > this.rowsNum - 1) : (range.endRowIndex == this.rowsNum - 1)))) return null;
  16594. nextRowIndex = !bottom ? ( !len ? cellInfo.rowIndex - 1 : range.beginRowIndex - 1)
  16595. : ( !len ? (cellInfo.rowIndex + cellInfo.rowSpan) : range.endRowIndex + 1);
  16596. nextColIndex = !len ? cellInfo.colIndex : range.beginColIndex;
  16597. return this.getCell(this.indexTable[nextRowIndex][nextColIndex].rowIndex, this.indexTable[nextRowIndex][nextColIndex].cellIndex);
  16598. } catch (e) {
  16599. showError(e);
  16600. }
  16601. },
  16602. /**
  16603. * 获取相同结束位置的单元格,xOrY指代了是获取x轴相同还是y轴相同
  16604. */
  16605. getSameEndPosCells:function (cell, xOrY) {
  16606. try {
  16607. var flag = (xOrY.toLowerCase() === "x"),
  16608. end = domUtils.getXY(cell)[flag ? 'x' : 'y'] + cell["offset" + (flag ? 'Width' : 'Height')],
  16609. rows = this.table.rows,
  16610. cells = null, returns = [];
  16611. for (var i = 0; i < this.rowsNum; i++) {
  16612. cells = rows[i].cells;
  16613. for (var j = 0, tmpCell; tmpCell = cells[j++];) {
  16614. var tmpEnd = domUtils.getXY(tmpCell)[flag ? 'x' : 'y'] + tmpCell["offset" + (flag ? 'Width' : 'Height')];
  16615. //对应行的td已经被上面行rowSpan了
  16616. if (tmpEnd > end && flag) break;
  16617. if (cell == tmpCell || end == tmpEnd) {
  16618. //只获取单一的单元格
  16619. //todo 仅获取单一单元格在特定情况下会造成returns为空,从而影响后续的拖拽实现,修正这个。需考虑性能
  16620. if (tmpCell[flag ? "colSpan" : "rowSpan"] == 1) {
  16621. returns.push(tmpCell);
  16622. }
  16623. if (flag) break;
  16624. }
  16625. }
  16626. }
  16627. return returns;
  16628. } catch (e) {
  16629. showError(e);
  16630. }
  16631. },
  16632. setCellContent:function (cell, content) {
  16633. cell.innerHTML = content || (browser.ie ? domUtils.fillChar : "<br />");
  16634. },
  16635. cloneCell:UETable.cloneCell,
  16636. /**
  16637. * 获取跟当前单元格的右边竖线为左边的所有未合并单元格
  16638. */
  16639. getSameStartPosXCells:function (cell) {
  16640. try {
  16641. var start = domUtils.getXY(cell).x + cell.offsetWidth,
  16642. rows = this.table.rows, cells , returns = [];
  16643. for (var i = 0; i < this.rowsNum; i++) {
  16644. cells = rows[i].cells;
  16645. for (var j = 0, tmpCell; tmpCell = cells[j++];) {
  16646. var tmpStart = domUtils.getXY(tmpCell).x;
  16647. if (tmpStart > start) break;
  16648. if (tmpStart == start && tmpCell.colSpan == 1) {
  16649. returns.push(tmpCell);
  16650. break;
  16651. }
  16652. }
  16653. }
  16654. return returns;
  16655. } catch (e) {
  16656. showError(e);
  16657. }
  16658. },
  16659. /**
  16660. * 更新table对应的索引表
  16661. */
  16662. update:function (table) {
  16663. this.table = table || this.table;
  16664. this.selectedTds = [];
  16665. this.cellsRange = {};
  16666. this.indexTable = [];
  16667. var rows = this.table.rows,
  16668. rowsNum = this.getMaxRows(),
  16669. dNum = rowsNum - rows.length,
  16670. colsNum = this.getMaxCols();
  16671. while (dNum--) {
  16672. this.table.insertRow(rows.length);
  16673. }
  16674. this.rowsNum = rowsNum;
  16675. this.colsNum = colsNum;
  16676. for (var i = 0, len = rows.length; i < len; i++) {
  16677. this.indexTable[i] = new Array(colsNum);
  16678. }
  16679. //填充索引表
  16680. for (var rowIndex = 0, row; row = rows[rowIndex]; rowIndex++) {
  16681. for (var cellIndex = 0, cell, cells = row.cells; cell = cells[cellIndex]; cellIndex++) {
  16682. //修正整行被rowSpan时导致的行数计算错误
  16683. if (cell.rowSpan > rowsNum) {
  16684. cell.rowSpan = rowsNum;
  16685. }
  16686. var colIndex = cellIndex,
  16687. rowSpan = cell.rowSpan || 1,
  16688. colSpan = cell.colSpan || 1;
  16689. //当已经被上一行rowSpan或者被前一列colSpan了,则跳到下一个单元格进行
  16690. while (this.indexTable[rowIndex][colIndex]) colIndex++;
  16691. for (var j = 0; j < rowSpan; j++) {
  16692. for (var k = 0; k < colSpan; k++) {
  16693. this.indexTable[rowIndex + j][colIndex + k] = {
  16694. rowIndex:rowIndex,
  16695. cellIndex:cellIndex,
  16696. colIndex:colIndex,
  16697. rowSpan:rowSpan,
  16698. colSpan:colSpan
  16699. }
  16700. }
  16701. }
  16702. }
  16703. }
  16704. //修复残缺td
  16705. for (j = 0; j < rowsNum; j++) {
  16706. for (k = 0; k < colsNum; k++) {
  16707. if (this.indexTable[j][k] === undefined) {
  16708. row = rows[j];
  16709. cell = row.cells[row.cells.length - 1];
  16710. cell = cell ? cell.cloneNode(true) : this.table.ownerDocument.createElement("td");
  16711. this.setCellContent(cell);
  16712. if (cell.colSpan !== 1)cell.colSpan = 1;
  16713. if (cell.rowSpan !== 1)cell.rowSpan = 1;
  16714. row.appendChild(cell);
  16715. this.indexTable[j][k] = {
  16716. rowIndex:j,
  16717. cellIndex:cell.cellIndex,
  16718. colIndex:k,
  16719. rowSpan:1,
  16720. colSpan:1
  16721. }
  16722. }
  16723. }
  16724. }
  16725. //当框选后删除行或者列后撤销,需要重建选区。
  16726. var tds = domUtils.getElementsByTagName(this.table, "td"),
  16727. selectTds = [];
  16728. utils.each(tds, function (td) {
  16729. if (domUtils.hasClass(td, "selectTdClass")) {
  16730. selectTds.push(td);
  16731. }
  16732. });
  16733. if (selectTds.length) {
  16734. var start = selectTds[0],
  16735. end = selectTds[selectTds.length - 1],
  16736. startInfo = this.getCellInfo(start),
  16737. endInfo = this.getCellInfo(end);
  16738. this.selectedTds = selectTds;
  16739. this.cellsRange = {
  16740. beginRowIndex:startInfo.rowIndex,
  16741. beginColIndex:startInfo.colIndex,
  16742. endRowIndex:endInfo.rowIndex + endInfo.rowSpan - 1,
  16743. endColIndex:endInfo.colIndex + endInfo.colSpan - 1
  16744. };
  16745. }
  16746. //给第一行设置firstRow的样式名称,在排序图标的样式上使用到
  16747. if(!domUtils.hasClass(this.table.rows[0], "firstRow")) {
  16748. domUtils.addClass(this.table.rows[0], "firstRow");
  16749. for(var i = 1; i< this.table.rows.length; i++) {
  16750. domUtils.removeClasses(this.table.rows[i], "firstRow");
  16751. }
  16752. }
  16753. },
  16754. /**
  16755. * 获取单元格的索引信息
  16756. */
  16757. getCellInfo:function (cell) {
  16758. if (!cell) return;
  16759. var cellIndex = cell.cellIndex,
  16760. rowIndex = cell.parentNode.rowIndex,
  16761. rowInfo = this.indexTable[rowIndex],
  16762. numCols = this.colsNum;
  16763. for (var colIndex = cellIndex; colIndex < numCols; colIndex++) {
  16764. var cellInfo = rowInfo[colIndex];
  16765. if (cellInfo.rowIndex === rowIndex && cellInfo.cellIndex === cellIndex) {
  16766. return cellInfo;
  16767. }
  16768. }
  16769. },
  16770. /**
  16771. * 根据行列号获取单元格
  16772. */
  16773. getCell:function (rowIndex, cellIndex) {
  16774. return rowIndex < this.rowsNum && this.table.rows[rowIndex].cells[cellIndex] || null;
  16775. },
  16776. /**
  16777. * 删除单元格
  16778. */
  16779. deleteCell:function (cell, rowIndex) {
  16780. rowIndex = typeof rowIndex == 'number' ? rowIndex : cell.parentNode.rowIndex;
  16781. var row = this.table.rows[rowIndex];
  16782. row.deleteCell(cell.cellIndex);
  16783. },
  16784. /**
  16785. * 根据始末两个单元格获取被框选的所有单元格范围
  16786. */
  16787. getCellsRange:function (cellA, cellB) {
  16788. function checkRange(beginRowIndex, beginColIndex, endRowIndex, endColIndex) {
  16789. var tmpBeginRowIndex = beginRowIndex,
  16790. tmpBeginColIndex = beginColIndex,
  16791. tmpEndRowIndex = endRowIndex,
  16792. tmpEndColIndex = endColIndex,
  16793. cellInfo, colIndex, rowIndex;
  16794. // 通过indexTable检查是否存在超出TableRange上边界的情况
  16795. if (beginRowIndex > 0) {
  16796. for (colIndex = beginColIndex; colIndex < endColIndex; colIndex++) {
  16797. cellInfo = me.indexTable[beginRowIndex][colIndex];
  16798. rowIndex = cellInfo.rowIndex;
  16799. if (rowIndex < beginRowIndex) {
  16800. tmpBeginRowIndex = Math.min(rowIndex, tmpBeginRowIndex);
  16801. }
  16802. }
  16803. }
  16804. // 通过indexTable检查是否存在超出TableRange右边界的情况
  16805. if (endColIndex < me.colsNum) {
  16806. for (rowIndex = beginRowIndex; rowIndex < endRowIndex; rowIndex++) {
  16807. cellInfo = me.indexTable[rowIndex][endColIndex];
  16808. colIndex = cellInfo.colIndex + cellInfo.colSpan - 1;
  16809. if (colIndex > endColIndex) {
  16810. tmpEndColIndex = Math.max(colIndex, tmpEndColIndex);
  16811. }
  16812. }
  16813. }
  16814. // 检查是否有超出TableRange下边界的情况
  16815. if (endRowIndex < me.rowsNum) {
  16816. for (colIndex = beginColIndex; colIndex < endColIndex; colIndex++) {
  16817. cellInfo = me.indexTable[endRowIndex][colIndex];
  16818. rowIndex = cellInfo.rowIndex + cellInfo.rowSpan - 1;
  16819. if (rowIndex > endRowIndex) {
  16820. tmpEndRowIndex = Math.max(rowIndex, tmpEndRowIndex);
  16821. }
  16822. }
  16823. }
  16824. // 检查是否有超出TableRange左边界的情况
  16825. if (beginColIndex > 0) {
  16826. for (rowIndex = beginRowIndex; rowIndex < endRowIndex; rowIndex++) {
  16827. cellInfo = me.indexTable[rowIndex][beginColIndex];
  16828. colIndex = cellInfo.colIndex;
  16829. if (colIndex < beginColIndex) {
  16830. tmpBeginColIndex = Math.min(cellInfo.colIndex, tmpBeginColIndex);
  16831. }
  16832. }
  16833. }
  16834. //递归调用直至所有完成所有框选单元格的扩展
  16835. if (tmpBeginRowIndex != beginRowIndex || tmpBeginColIndex != beginColIndex || tmpEndRowIndex != endRowIndex || tmpEndColIndex != endColIndex) {
  16836. return checkRange(tmpBeginRowIndex, tmpBeginColIndex, tmpEndRowIndex, tmpEndColIndex);
  16837. } else {
  16838. // 不需要扩展TableRange的情况
  16839. return {
  16840. beginRowIndex:beginRowIndex,
  16841. beginColIndex:beginColIndex,
  16842. endRowIndex:endRowIndex,
  16843. endColIndex:endColIndex
  16844. };
  16845. }
  16846. }
  16847. try {
  16848. var me = this,
  16849. cellAInfo = me.getCellInfo(cellA);
  16850. if (cellA === cellB) {
  16851. return {
  16852. beginRowIndex:cellAInfo.rowIndex,
  16853. beginColIndex:cellAInfo.colIndex,
  16854. endRowIndex:cellAInfo.rowIndex + cellAInfo.rowSpan - 1,
  16855. endColIndex:cellAInfo.colIndex + cellAInfo.colSpan - 1
  16856. };
  16857. }
  16858. var cellBInfo = me.getCellInfo(cellB);
  16859. // 计算TableRange的四个边
  16860. var beginRowIndex = Math.min(cellAInfo.rowIndex, cellBInfo.rowIndex),
  16861. beginColIndex = Math.min(cellAInfo.colIndex, cellBInfo.colIndex),
  16862. endRowIndex = Math.max(cellAInfo.rowIndex + cellAInfo.rowSpan - 1, cellBInfo.rowIndex + cellBInfo.rowSpan - 1),
  16863. endColIndex = Math.max(cellAInfo.colIndex + cellAInfo.colSpan - 1, cellBInfo.colIndex + cellBInfo.colSpan - 1);
  16864. return checkRange(beginRowIndex, beginColIndex, endRowIndex, endColIndex);
  16865. } catch (e) {
  16866. //throw e;
  16867. }
  16868. },
  16869. /**
  16870. * 依据cellsRange获取对应的单元格集合
  16871. */
  16872. getCells:function (range) {
  16873. //每次获取cells之前必须先清除上次的选择,否则会对后续获取操作造成影响
  16874. this.clearSelected();
  16875. var beginRowIndex = range.beginRowIndex,
  16876. beginColIndex = range.beginColIndex,
  16877. endRowIndex = range.endRowIndex,
  16878. endColIndex = range.endColIndex,
  16879. cellInfo, rowIndex, colIndex, tdHash = {}, returnTds = [];
  16880. for (var i = beginRowIndex; i <= endRowIndex; i++) {
  16881. for (var j = beginColIndex; j <= endColIndex; j++) {
  16882. cellInfo = this.indexTable[i][j];
  16883. rowIndex = cellInfo.rowIndex;
  16884. colIndex = cellInfo.colIndex;
  16885. // 如果Cells里已经包含了此Cell则跳过
  16886. var key = rowIndex + '|' + colIndex;
  16887. if (tdHash[key]) continue;
  16888. tdHash[key] = 1;
  16889. if (rowIndex < i || colIndex < j || rowIndex + cellInfo.rowSpan - 1 > endRowIndex || colIndex + cellInfo.colSpan - 1 > endColIndex) {
  16890. return null;
  16891. }
  16892. returnTds.push(this.getCell(rowIndex, cellInfo.cellIndex));
  16893. }
  16894. }
  16895. return returnTds;
  16896. },
  16897. /**
  16898. * 清理已经选中的单元格
  16899. */
  16900. clearSelected:function () {
  16901. UETable.removeSelectedClass(this.selectedTds);
  16902. this.selectedTds = [];
  16903. this.cellsRange = {};
  16904. },
  16905. /**
  16906. * 根据range设置已经选中的单元格
  16907. */
  16908. setSelected:function (range) {
  16909. var cells = this.getCells(range);
  16910. UETable.addSelectedClass(cells);
  16911. this.selectedTds = cells;
  16912. this.cellsRange = range;
  16913. },
  16914. isFullRow:function () {
  16915. var range = this.cellsRange;
  16916. return (range.endColIndex - range.beginColIndex + 1) == this.colsNum;
  16917. },
  16918. isFullCol:function () {
  16919. var range = this.cellsRange,
  16920. table = this.table,
  16921. ths = table.getElementsByTagName("th"),
  16922. rows = range.endRowIndex - range.beginRowIndex + 1;
  16923. return !ths.length ? rows == this.rowsNum : rows == this.rowsNum || (rows == this.rowsNum - 1);
  16924. },
  16925. /**
  16926. * 获取视觉上的前置单元格,默认是左边,top传入时
  16927. * @param cell
  16928. * @param top
  16929. */
  16930. getNextCell:function (cell, bottom, ignoreRange) {
  16931. try {
  16932. var cellInfo = this.getCellInfo(cell),
  16933. nextRowIndex, nextColIndex;
  16934. var len = this.selectedTds.length && !ignoreRange,
  16935. range = this.cellsRange;
  16936. //末行或者末列没有后置单元格
  16937. if ((!bottom && (cellInfo.rowIndex == 0)) || (bottom && (!len ? (cellInfo.rowIndex + cellInfo.rowSpan > this.rowsNum - 1) : (range.endRowIndex == this.rowsNum - 1)))) return null;
  16938. nextRowIndex = !bottom ? ( !len ? cellInfo.rowIndex - 1 : range.beginRowIndex - 1)
  16939. : ( !len ? (cellInfo.rowIndex + cellInfo.rowSpan) : range.endRowIndex + 1);
  16940. nextColIndex = !len ? cellInfo.colIndex : range.beginColIndex;
  16941. return this.getCell(this.indexTable[nextRowIndex][nextColIndex].rowIndex, this.indexTable[nextRowIndex][nextColIndex].cellIndex);
  16942. } catch (e) {
  16943. showError(e);
  16944. }
  16945. },
  16946. getPreviewCell:function (cell, top) {
  16947. try {
  16948. var cellInfo = this.getCellInfo(cell),
  16949. previewRowIndex, previewColIndex;
  16950. var len = this.selectedTds.length,
  16951. range = this.cellsRange;
  16952. //首行或者首列没有前置单元格
  16953. if ((!top && (!len ? !cellInfo.colIndex : !range.beginColIndex)) || (top && (!len ? (cellInfo.rowIndex > (this.colsNum - 1)) : (range.endColIndex == this.colsNum - 1)))) return null;
  16954. previewRowIndex = !top ? ( !len ? cellInfo.rowIndex : range.beginRowIndex )
  16955. : ( !len ? (cellInfo.rowIndex < 1 ? 0 : (cellInfo.rowIndex - 1)) : range.beginRowIndex);
  16956. previewColIndex = !top ? ( !len ? (cellInfo.colIndex < 1 ? 0 : (cellInfo.colIndex - 1)) : range.beginColIndex - 1)
  16957. : ( !len ? cellInfo.colIndex : range.endColIndex + 1);
  16958. return this.getCell(this.indexTable[previewRowIndex][previewColIndex].rowIndex, this.indexTable[previewRowIndex][previewColIndex].cellIndex);
  16959. } catch (e) {
  16960. showError(e);
  16961. }
  16962. },
  16963. /**
  16964. * 移动单元格中的内容
  16965. */
  16966. moveContent:function (cellTo, cellFrom) {
  16967. if (UETable.isEmptyBlock(cellFrom)) return;
  16968. if (UETable.isEmptyBlock(cellTo)) {
  16969. cellTo.innerHTML = cellFrom.innerHTML;
  16970. return;
  16971. }
  16972. var child = cellTo.lastChild;
  16973. if (child.nodeType == 3 || !dtd.$block[child.tagName]) {
  16974. cellTo.appendChild(cellTo.ownerDocument.createElement('br'))
  16975. }
  16976. while (child = cellFrom.firstChild) {
  16977. cellTo.appendChild(child);
  16978. }
  16979. },
  16980. /**
  16981. * 向右合并单元格
  16982. */
  16983. mergeRight:function (cell) {
  16984. var cellInfo = this.getCellInfo(cell),
  16985. rightColIndex = cellInfo.colIndex + cellInfo.colSpan,
  16986. rightCellInfo = this.indexTable[cellInfo.rowIndex][rightColIndex],
  16987. rightCell = this.getCell(rightCellInfo.rowIndex, rightCellInfo.cellIndex);
  16988. //合并
  16989. cell.colSpan = cellInfo.colSpan + rightCellInfo.colSpan;
  16990. //被合并的单元格不应存在宽度属性
  16991. cell.removeAttribute("width");
  16992. //移动内容
  16993. this.moveContent(cell, rightCell);
  16994. //删掉被合并的Cell
  16995. this.deleteCell(rightCell, rightCellInfo.rowIndex);
  16996. this.update();
  16997. },
  16998. /**
  16999. * 向下合并单元格
  17000. */
  17001. mergeDown:function (cell) {
  17002. var cellInfo = this.getCellInfo(cell),
  17003. downRowIndex = cellInfo.rowIndex + cellInfo.rowSpan,
  17004. downCellInfo = this.indexTable[downRowIndex][cellInfo.colIndex],
  17005. downCell = this.getCell(downCellInfo.rowIndex, downCellInfo.cellIndex);
  17006. cell.rowSpan = cellInfo.rowSpan + downCellInfo.rowSpan;
  17007. cell.removeAttribute("height");
  17008. this.moveContent(cell, downCell);
  17009. this.deleteCell(downCell, downCellInfo.rowIndex);
  17010. this.update();
  17011. },
  17012. /**
  17013. * 合并整个range中的内容
  17014. */
  17015. mergeRange:function () {
  17016. //由于合并操作可以在任意时刻进行,所以无法通过鼠标位置等信息实时生成range,只能通过缓存实例中的cellsRange对象来访问
  17017. var range = this.cellsRange,
  17018. leftTopCell = this.getCell(range.beginRowIndex, this.indexTable[range.beginRowIndex][range.beginColIndex].cellIndex);
  17019. if (leftTopCell.tagName == "TH" && range.endRowIndex !== range.beginRowIndex) {
  17020. var index = this.indexTable,
  17021. info = this.getCellInfo(leftTopCell);
  17022. leftTopCell = this.getCell(1, index[1][info.colIndex].cellIndex);
  17023. range = this.getCellsRange(leftTopCell, this.getCell(index[this.rowsNum - 1][info.colIndex].rowIndex, index[this.rowsNum - 1][info.colIndex].cellIndex));
  17024. }
  17025. // 删除剩余的Cells
  17026. var cells = this.getCells(range);
  17027. for(var i= 0,ci;ci=cells[i++];){
  17028. if (ci !== leftTopCell) {
  17029. this.moveContent(leftTopCell, ci);
  17030. this.deleteCell(ci);
  17031. }
  17032. }
  17033. // 修改左上角Cell的rowSpan和colSpan,并调整宽度属性设置
  17034. leftTopCell.rowSpan = range.endRowIndex - range.beginRowIndex + 1;
  17035. leftTopCell.rowSpan > 1 && leftTopCell.removeAttribute("height");
  17036. leftTopCell.colSpan = range.endColIndex - range.beginColIndex + 1;
  17037. leftTopCell.colSpan > 1 && leftTopCell.removeAttribute("width");
  17038. if (leftTopCell.rowSpan == this.rowsNum && leftTopCell.colSpan != 1) {
  17039. leftTopCell.colSpan = 1;
  17040. }
  17041. if (leftTopCell.colSpan == this.colsNum && leftTopCell.rowSpan != 1) {
  17042. var rowIndex = leftTopCell.parentNode.rowIndex;
  17043. //解决IE下的表格操作问题
  17044. if( this.table.deleteRow ) {
  17045. for (var i = rowIndex+ 1, curIndex=rowIndex+ 1, len=leftTopCell.rowSpan; i < len; i++) {
  17046. this.table.deleteRow(curIndex);
  17047. }
  17048. } else {
  17049. for (var i = 0, len=leftTopCell.rowSpan - 1; i < len; i++) {
  17050. var row = this.table.rows[rowIndex + 1];
  17051. row.parentNode.removeChild(row);
  17052. }
  17053. }
  17054. leftTopCell.rowSpan = 1;
  17055. }
  17056. this.update();
  17057. },
  17058. /**
  17059. * 插入一行单元格
  17060. */
  17061. insertRow:function (rowIndex, sourceCell) {
  17062. var numCols = this.colsNum,
  17063. table = this.table,
  17064. row = table.insertRow(rowIndex), cell,
  17065. isInsertTitle = typeof sourceCell == 'string' && sourceCell.toUpperCase() == 'TH';
  17066. function replaceTdToTh(colIndex, cell, tableRow) {
  17067. if (colIndex == 0) {
  17068. var tr = tableRow.nextSibling || tableRow.previousSibling,
  17069. th = tr.cells[colIndex];
  17070. if (th.tagName == 'TH') {
  17071. th = cell.ownerDocument.createElement("th");
  17072. th.appendChild(cell.firstChild);
  17073. tableRow.insertBefore(th, cell);
  17074. domUtils.remove(cell)
  17075. }
  17076. }else{
  17077. if (cell.tagName == 'TH') {
  17078. var td = cell.ownerDocument.createElement("td");
  17079. td.appendChild(cell.firstChild);
  17080. tableRow.insertBefore(td, cell);
  17081. domUtils.remove(cell)
  17082. }
  17083. }
  17084. }
  17085. //首行直接插入,无需考虑部分单元格被rowspan的情况
  17086. if (rowIndex == 0 || rowIndex == this.rowsNum) {
  17087. for (var colIndex = 0; colIndex < numCols; colIndex++) {
  17088. cell = this.cloneCell(sourceCell, true);
  17089. this.setCellContent(cell);
  17090. cell.getAttribute('vAlign') && cell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17091. row.appendChild(cell);
  17092. if(!isInsertTitle) replaceTdToTh(colIndex, cell, row);
  17093. }
  17094. } else {
  17095. var infoRow = this.indexTable[rowIndex],
  17096. cellIndex = 0;
  17097. for (colIndex = 0; colIndex < numCols; colIndex++) {
  17098. var cellInfo = infoRow[colIndex];
  17099. //如果存在某个单元格的rowspan穿过待插入行的位置,则修改该单元格的rowspan即可,无需插入单元格
  17100. if (cellInfo.rowIndex < rowIndex) {
  17101. cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  17102. cell.rowSpan = cellInfo.rowSpan + 1;
  17103. } else {
  17104. cell = this.cloneCell(sourceCell, true);
  17105. this.setCellContent(cell);
  17106. row.appendChild(cell);
  17107. }
  17108. if(!isInsertTitle) replaceTdToTh(colIndex, cell, row);
  17109. }
  17110. }
  17111. //框选时插入不触发contentchange,需要手动更新索引。
  17112. this.update();
  17113. return row;
  17114. },
  17115. /**
  17116. * 删除一行单元格
  17117. * @param rowIndex
  17118. */
  17119. deleteRow:function (rowIndex) {
  17120. var row = this.table.rows[rowIndex],
  17121. infoRow = this.indexTable[rowIndex],
  17122. colsNum = this.colsNum,
  17123. count = 0; //处理计数
  17124. for (var colIndex = 0; colIndex < colsNum;) {
  17125. var cellInfo = infoRow[colIndex],
  17126. cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  17127. if (cell.rowSpan > 1) {
  17128. if (cellInfo.rowIndex == rowIndex) {
  17129. var clone = cell.cloneNode(true);
  17130. clone.rowSpan = cell.rowSpan - 1;
  17131. clone.innerHTML = "";
  17132. cell.rowSpan = 1;
  17133. var nextRowIndex = rowIndex + 1,
  17134. nextRow = this.table.rows[nextRowIndex],
  17135. insertCellIndex,
  17136. preMerged = this.getPreviewMergedCellsNum(nextRowIndex, colIndex) - count;
  17137. if (preMerged < colIndex) {
  17138. insertCellIndex = colIndex - preMerged - 1;
  17139. //nextRow.insertCell(insertCellIndex);
  17140. domUtils.insertAfter(nextRow.cells[insertCellIndex], clone);
  17141. } else {
  17142. if (nextRow.cells.length) nextRow.insertBefore(clone, nextRow.cells[0])
  17143. }
  17144. count += 1;
  17145. //cell.parentNode.removeChild(cell);
  17146. }
  17147. }
  17148. colIndex += cell.colSpan || 1;
  17149. }
  17150. var deleteTds = [], cacheMap = {};
  17151. for (colIndex = 0; colIndex < colsNum; colIndex++) {
  17152. var tmpRowIndex = infoRow[colIndex].rowIndex,
  17153. tmpCellIndex = infoRow[colIndex].cellIndex,
  17154. key = tmpRowIndex + "_" + tmpCellIndex;
  17155. if (cacheMap[key])continue;
  17156. cacheMap[key] = 1;
  17157. cell = this.getCell(tmpRowIndex, tmpCellIndex);
  17158. deleteTds.push(cell);
  17159. }
  17160. var mergeTds = [];
  17161. utils.each(deleteTds, function (td) {
  17162. if (td.rowSpan == 1) {
  17163. td.parentNode.removeChild(td);
  17164. } else {
  17165. mergeTds.push(td);
  17166. }
  17167. });
  17168. utils.each(mergeTds, function (td) {
  17169. td.rowSpan--;
  17170. });
  17171. row.parentNode.removeChild(row);
  17172. //浏览器方法本身存在bug,采用自定义方法删除
  17173. //this.table.deleteRow(rowIndex);
  17174. this.update();
  17175. },
  17176. insertCol:function (colIndex, sourceCell, defaultValue) {
  17177. var rowsNum = this.rowsNum,
  17178. rowIndex = 0,
  17179. tableRow, cell,
  17180. backWidth = parseInt((this.table.offsetWidth - (this.colsNum + 1) * 20 - (this.colsNum + 1)) / (this.colsNum + 1), 10),
  17181. isInsertTitleCol = typeof sourceCell == 'string' && sourceCell.toUpperCase() == 'TH';
  17182. function replaceTdToTh(rowIndex, cell, tableRow) {
  17183. if (rowIndex == 0) {
  17184. var th = cell.nextSibling || cell.previousSibling;
  17185. if (th.tagName == 'TH') {
  17186. th = cell.ownerDocument.createElement("th");
  17187. th.appendChild(cell.firstChild);
  17188. tableRow.insertBefore(th, cell);
  17189. domUtils.remove(cell)
  17190. }
  17191. }else{
  17192. if (cell.tagName == 'TH') {
  17193. var td = cell.ownerDocument.createElement("td");
  17194. td.appendChild(cell.firstChild);
  17195. tableRow.insertBefore(td, cell);
  17196. domUtils.remove(cell)
  17197. }
  17198. }
  17199. }
  17200. var preCell;
  17201. if (colIndex == 0 || colIndex == this.colsNum) {
  17202. for (; rowIndex < rowsNum; rowIndex++) {
  17203. tableRow = this.table.rows[rowIndex];
  17204. preCell = tableRow.cells[colIndex == 0 ? colIndex : tableRow.cells.length];
  17205. cell = this.cloneCell(sourceCell, true); //tableRow.insertCell(colIndex == 0 ? colIndex : tableRow.cells.length);
  17206. this.setCellContent(cell);
  17207. cell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17208. preCell && cell.setAttribute('width', preCell.getAttribute('width'));
  17209. if (!colIndex) {
  17210. tableRow.insertBefore(cell, tableRow.cells[0]);
  17211. } else {
  17212. domUtils.insertAfter(tableRow.cells[tableRow.cells.length - 1], cell);
  17213. }
  17214. if(!isInsertTitleCol) replaceTdToTh(rowIndex, cell, tableRow)
  17215. }
  17216. } else {
  17217. for (; rowIndex < rowsNum; rowIndex++) {
  17218. var cellInfo = this.indexTable[rowIndex][colIndex];
  17219. if (cellInfo.colIndex < colIndex) {
  17220. cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  17221. cell.colSpan = cellInfo.colSpan + 1;
  17222. } else {
  17223. tableRow = this.table.rows[rowIndex];
  17224. preCell = tableRow.cells[cellInfo.cellIndex];
  17225. cell = this.cloneCell(sourceCell, true);//tableRow.insertCell(cellInfo.cellIndex);
  17226. this.setCellContent(cell);
  17227. cell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17228. preCell && cell.setAttribute('width', preCell.getAttribute('width'));
  17229. //防止IE下报错
  17230. preCell ? tableRow.insertBefore(cell, preCell) : tableRow.appendChild(cell);
  17231. }
  17232. if(!isInsertTitleCol) replaceTdToTh(rowIndex, cell, tableRow);
  17233. }
  17234. }
  17235. //框选时插入不触发contentchange,需要手动更新索引
  17236. this.update();
  17237. this.updateWidth(backWidth, defaultValue || {tdPadding:10, tdBorder:1});
  17238. },
  17239. updateWidth:function (width, defaultValue) {
  17240. var table = this.table,
  17241. tmpWidth = UETable.getWidth(table) - defaultValue.tdPadding * 2 - defaultValue.tdBorder + width;
  17242. if (tmpWidth < table.ownerDocument.body.offsetWidth) {
  17243. table.setAttribute("width", tmpWidth);
  17244. return;
  17245. }
  17246. var tds = domUtils.getElementsByTagName(this.table, "td th");
  17247. utils.each(tds, function (td) {
  17248. td.setAttribute("width", width);
  17249. })
  17250. },
  17251. deleteCol:function (colIndex) {
  17252. var indexTable = this.indexTable,
  17253. tableRows = this.table.rows,
  17254. backTableWidth = this.table.getAttribute("width"),
  17255. backTdWidth = 0,
  17256. rowsNum = this.rowsNum,
  17257. cacheMap = {};
  17258. for (var rowIndex = 0; rowIndex < rowsNum;) {
  17259. var infoRow = indexTable[rowIndex],
  17260. cellInfo = infoRow[colIndex],
  17261. key = cellInfo.rowIndex + '_' + cellInfo.colIndex;
  17262. // 跳过已经处理过的Cell
  17263. if (cacheMap[key])continue;
  17264. cacheMap[key] = 1;
  17265. var cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  17266. if (!backTdWidth) backTdWidth = cell && parseInt(cell.offsetWidth / cell.colSpan, 10).toFixed(0);
  17267. // 如果Cell的colSpan大于1, 就修改colSpan, 否则就删掉这个Cell
  17268. if (cell.colSpan > 1) {
  17269. cell.colSpan--;
  17270. } else {
  17271. tableRows[rowIndex].deleteCell(cellInfo.cellIndex);
  17272. }
  17273. rowIndex += cellInfo.rowSpan || 1;
  17274. }
  17275. this.table.setAttribute("width", backTableWidth - backTdWidth);
  17276. this.update();
  17277. },
  17278. splitToCells:function (cell) {
  17279. var me = this,
  17280. cells = this.splitToRows(cell);
  17281. utils.each(cells, function (cell) {
  17282. me.splitToCols(cell);
  17283. })
  17284. },
  17285. splitToRows:function (cell) {
  17286. var cellInfo = this.getCellInfo(cell),
  17287. rowIndex = cellInfo.rowIndex,
  17288. colIndex = cellInfo.colIndex,
  17289. results = [];
  17290. // 修改Cell的rowSpan
  17291. cell.rowSpan = 1;
  17292. results.push(cell);
  17293. // 补齐单元格
  17294. for (var i = rowIndex, endRow = rowIndex + cellInfo.rowSpan; i < endRow; i++) {
  17295. if (i == rowIndex)continue;
  17296. var tableRow = this.table.rows[i],
  17297. tmpCell = tableRow.insertCell(colIndex - this.getPreviewMergedCellsNum(i, colIndex));
  17298. tmpCell.colSpan = cellInfo.colSpan;
  17299. this.setCellContent(tmpCell);
  17300. tmpCell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17301. tmpCell.setAttribute('align', cell.getAttribute('align'));
  17302. if (cell.style.cssText) {
  17303. tmpCell.style.cssText = cell.style.cssText;
  17304. }
  17305. results.push(tmpCell);
  17306. }
  17307. this.update();
  17308. return results;
  17309. },
  17310. getPreviewMergedCellsNum:function (rowIndex, colIndex) {
  17311. var indexRow = this.indexTable[rowIndex],
  17312. num = 0;
  17313. for (var i = 0; i < colIndex;) {
  17314. var colSpan = indexRow[i].colSpan,
  17315. tmpRowIndex = indexRow[i].rowIndex;
  17316. num += (colSpan - (tmpRowIndex == rowIndex ? 1 : 0));
  17317. i += colSpan;
  17318. }
  17319. return num;
  17320. },
  17321. splitToCols:function (cell) {
  17322. var backWidth = (cell.offsetWidth / cell.colSpan - 22).toFixed(0),
  17323. cellInfo = this.getCellInfo(cell),
  17324. rowIndex = cellInfo.rowIndex,
  17325. colIndex = cellInfo.colIndex,
  17326. results = [];
  17327. // 修改Cell的rowSpan
  17328. cell.colSpan = 1;
  17329. cell.setAttribute("width", backWidth);
  17330. results.push(cell);
  17331. // 补齐单元格
  17332. for (var j = colIndex, endCol = colIndex + cellInfo.colSpan; j < endCol; j++) {
  17333. if (j == colIndex)continue;
  17334. var tableRow = this.table.rows[rowIndex],
  17335. tmpCell = tableRow.insertCell(this.indexTable[rowIndex][j].cellIndex + 1);
  17336. tmpCell.rowSpan = cellInfo.rowSpan;
  17337. this.setCellContent(tmpCell);
  17338. tmpCell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17339. tmpCell.setAttribute('align', cell.getAttribute('align'));
  17340. tmpCell.setAttribute('width', backWidth);
  17341. if (cell.style.cssText) {
  17342. tmpCell.style.cssText = cell.style.cssText;
  17343. }
  17344. //处理th的情况
  17345. if (cell.tagName == 'TH') {
  17346. var th = cell.ownerDocument.createElement('th');
  17347. th.appendChild(tmpCell.firstChild);
  17348. th.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17349. th.rowSpan = tmpCell.rowSpan;
  17350. tableRow.insertBefore(th, tmpCell);
  17351. domUtils.remove(tmpCell);
  17352. }
  17353. results.push(tmpCell);
  17354. }
  17355. this.update();
  17356. return results;
  17357. },
  17358. isLastCell:function (cell, rowsNum, colsNum) {
  17359. rowsNum = rowsNum || this.rowsNum;
  17360. colsNum = colsNum || this.colsNum;
  17361. var cellInfo = this.getCellInfo(cell);
  17362. return ((cellInfo.rowIndex + cellInfo.rowSpan) == rowsNum) &&
  17363. ((cellInfo.colIndex + cellInfo.colSpan) == colsNum);
  17364. },
  17365. getLastCell:function (cells) {
  17366. cells = cells || this.table.getElementsByTagName("td");
  17367. var firstInfo = this.getCellInfo(cells[0]);
  17368. var me = this, last = cells[0],
  17369. tr = last.parentNode,
  17370. cellsNum = 0, cols = 0, rows;
  17371. utils.each(cells, function (cell) {
  17372. if (cell.parentNode == tr)cols += cell.colSpan || 1;
  17373. cellsNum += cell.rowSpan * cell.colSpan || 1;
  17374. });
  17375. rows = cellsNum / cols;
  17376. utils.each(cells, function (cell) {
  17377. if (me.isLastCell(cell, rows, cols)) {
  17378. last = cell;
  17379. return false;
  17380. }
  17381. });
  17382. return last;
  17383. },
  17384. selectRow:function (rowIndex) {
  17385. var indexRow = this.indexTable[rowIndex],
  17386. start = this.getCell(indexRow[0].rowIndex, indexRow[0].cellIndex),
  17387. end = this.getCell(indexRow[this.colsNum - 1].rowIndex, indexRow[this.colsNum - 1].cellIndex),
  17388. range = this.getCellsRange(start, end);
  17389. this.setSelected(range);
  17390. },
  17391. selectTable:function () {
  17392. var tds = this.table.getElementsByTagName("td"),
  17393. range = this.getCellsRange(tds[0], tds[tds.length - 1]);
  17394. this.setSelected(range);
  17395. },
  17396. setBackground:function (cells, value) {
  17397. if (typeof value === "string") {
  17398. utils.each(cells, function (cell) {
  17399. cell.style.backgroundColor = value;
  17400. })
  17401. } else if (typeof value === "object") {
  17402. value = utils.extend({
  17403. repeat:true,
  17404. colorList:["#ddd", "#fff"]
  17405. }, value);
  17406. var rowIndex = this.getCellInfo(cells[0]).rowIndex,
  17407. count = 0,
  17408. colors = value.colorList,
  17409. getColor = function (list, index, repeat) {
  17410. return list[index] ? list[index] : repeat ? list[index % list.length] : "";
  17411. };
  17412. for (var i = 0, cell; cell = cells[i++];) {
  17413. var cellInfo = this.getCellInfo(cell);
  17414. cell.style.backgroundColor = getColor(colors, ((rowIndex + count) == cellInfo.rowIndex) ? count : ++count, value.repeat);
  17415. }
  17416. }
  17417. },
  17418. removeBackground:function (cells) {
  17419. utils.each(cells, function (cell) {
  17420. cell.style.backgroundColor = "";
  17421. })
  17422. }
  17423. };
  17424. function showError(e) {
  17425. }
  17426. })();
  17427. // js/editor/_src/plugins/table.cmds.js
  17428. /**
  17429. * Created with JetBrains PhpStorm.
  17430. * User: taoqili
  17431. * Date: 13-2-20
  17432. * Time: 下午6:25
  17433. * To change this template use File | Settings | File Templates.
  17434. */
  17435. ;
  17436. (function () {
  17437. var UT = UE.UETable,
  17438. getTableItemsByRange = function (editor) {
  17439. return UT.getTableItemsByRange(editor);
  17440. },
  17441. getUETableBySelected = function (editor) {
  17442. return UT.getUETableBySelected(editor)
  17443. },
  17444. getDefaultValue = function (editor, table) {
  17445. return UT.getDefaultValue(editor, table);
  17446. },
  17447. getUETable = function (tdOrTable) {
  17448. return UT.getUETable(tdOrTable);
  17449. };
  17450. UE.commands['inserttable'] = {
  17451. queryCommandState: function () {
  17452. return getTableItemsByRange(this).table ? -1 : 0;
  17453. },
  17454. execCommand: function (cmd, opt) {
  17455. function createTable(opt, tdWidth) {
  17456. var html = [],
  17457. rowsNum = opt.numRows,
  17458. colsNum = opt.numCols;
  17459. for (var r = 0; r < rowsNum; r++) {
  17460. html.push('<tr' + (r == 0 ? ' class="firstRow"':'') + '>');
  17461. for (var c = 0; c < colsNum; c++) {
  17462. html.push('<td width="' + tdWidth + '" vAlign="' + opt.tdvalign + '" >' + (browser.ie && browser.version < 11 ? domUtils.fillChar : '<br/>') + '</td>')
  17463. }
  17464. html.push('</tr>')
  17465. }
  17466. //禁止指定table-width
  17467. return '<table><tbody>' + html.join('') + '</tbody></table>'
  17468. }
  17469. if (!opt) {
  17470. opt = utils.extend({}, {
  17471. numCols: this.options.defaultCols,
  17472. numRows: this.options.defaultRows,
  17473. tdvalign: this.options.tdvalign
  17474. })
  17475. }
  17476. var me = this;
  17477. var range = this.selection.getRange(),
  17478. start = range.startContainer,
  17479. firstParentBlock = domUtils.findParent(start, function (node) {
  17480. return domUtils.isBlockElm(node);
  17481. }, true) || me.body;
  17482. var defaultValue = getDefaultValue(me),
  17483. tableWidth = firstParentBlock.offsetWidth,
  17484. tdWidth = Math.floor(tableWidth / opt.numCols - defaultValue.tdPadding * 2 - defaultValue.tdBorder);
  17485. //todo其他属性
  17486. !opt.tdvalign && (opt.tdvalign = me.options.tdvalign);
  17487. me.execCommand("inserthtml", createTable(opt, tdWidth));
  17488. }
  17489. };
  17490. UE.commands['insertparagraphbeforetable'] = {
  17491. queryCommandState: function () {
  17492. return getTableItemsByRange(this).cell ? 0 : -1;
  17493. },
  17494. execCommand: function () {
  17495. var table = getTableItemsByRange(this).table;
  17496. if (table) {
  17497. var p = this.document.createElement("p");
  17498. p.innerHTML = browser.ie ? '&nbsp;' : '<br />';
  17499. table.parentNode.insertBefore(p, table);
  17500. this.selection.getRange().setStart(p, 0).setCursor();
  17501. }
  17502. }
  17503. };
  17504. UE.commands['deletetable'] = {
  17505. queryCommandState: function () {
  17506. var rng = this.selection.getRange();
  17507. return domUtils.findParentByTagName(rng.startContainer, 'table', true) ? 0 : -1;
  17508. },
  17509. execCommand: function (cmd, table) {
  17510. var rng = this.selection.getRange();
  17511. table = table || domUtils.findParentByTagName(rng.startContainer, 'table', true);
  17512. if (table) {
  17513. var next = table.nextSibling;
  17514. if (!next) {
  17515. next = domUtils.createElement(this.document, 'p', {
  17516. 'innerHTML': browser.ie ? domUtils.fillChar : '<br/>'
  17517. });
  17518. table.parentNode.insertBefore(next, table);
  17519. }
  17520. domUtils.remove(table);
  17521. rng = this.selection.getRange();
  17522. if (next.nodeType == 3) {
  17523. rng.setStartBefore(next)
  17524. } else {
  17525. rng.setStart(next, 0)
  17526. }
  17527. rng.setCursor(false, true)
  17528. this.fireEvent("tablehasdeleted")
  17529. }
  17530. }
  17531. };
  17532. UE.commands['cellalign'] = {
  17533. queryCommandState: function () {
  17534. return getSelectedArr(this).length ? 0 : -1
  17535. },
  17536. execCommand: function (cmd, align) {
  17537. var selectedTds = getSelectedArr(this);
  17538. if (selectedTds.length) {
  17539. for (var i = 0, ci; ci = selectedTds[i++];) {
  17540. ci.setAttribute('align', align);
  17541. }
  17542. }
  17543. }
  17544. };
  17545. UE.commands['cellvalign'] = {
  17546. queryCommandState: function () {
  17547. return getSelectedArr(this).length ? 0 : -1;
  17548. },
  17549. execCommand: function (cmd, valign) {
  17550. var selectedTds = getSelectedArr(this);
  17551. if (selectedTds.length) {
  17552. for (var i = 0, ci; ci = selectedTds[i++];) {
  17553. ci.setAttribute('vAlign', valign);
  17554. }
  17555. }
  17556. }
  17557. };
  17558. UE.commands['insertcaption'] = {
  17559. queryCommandState: function () {
  17560. var table = getTableItemsByRange(this).table;
  17561. if (table) {
  17562. return table.getElementsByTagName('caption').length == 0 ? 1 : -1;
  17563. }
  17564. return -1;
  17565. },
  17566. execCommand: function () {
  17567. var table = getTableItemsByRange(this).table;
  17568. if (table) {
  17569. var caption = this.document.createElement('caption');
  17570. caption.innerHTML = browser.ie ? domUtils.fillChar : '<br/>';
  17571. table.insertBefore(caption, table.firstChild);
  17572. var range = this.selection.getRange();
  17573. range.setStart(caption, 0).setCursor();
  17574. }
  17575. }
  17576. };
  17577. UE.commands['deletecaption'] = {
  17578. queryCommandState: function () {
  17579. var rng = this.selection.getRange(),
  17580. table = domUtils.findParentByTagName(rng.startContainer, 'table');
  17581. if (table) {
  17582. return table.getElementsByTagName('caption').length == 0 ? -1 : 1;
  17583. }
  17584. return -1;
  17585. },
  17586. execCommand: function () {
  17587. var rng = this.selection.getRange(),
  17588. table = domUtils.findParentByTagName(rng.startContainer, 'table');
  17589. if (table) {
  17590. domUtils.remove(table.getElementsByTagName('caption')[0]);
  17591. var range = this.selection.getRange();
  17592. range.setStart(table.rows[0].cells[0], 0).setCursor();
  17593. }
  17594. }
  17595. };
  17596. UE.commands['inserttitle'] = {
  17597. queryCommandState: function () {
  17598. var table = getTableItemsByRange(this).table;
  17599. if (table) {
  17600. var firstRow = table.rows[0];
  17601. return firstRow.cells[firstRow.cells.length-1].tagName.toLowerCase() != 'th' ? 0 : -1
  17602. }
  17603. return -1;
  17604. },
  17605. execCommand: function () {
  17606. var table = getTableItemsByRange(this).table;
  17607. if (table) {
  17608. getUETable(table).insertRow(0, 'th');
  17609. }
  17610. var th = table.getElementsByTagName('th')[0];
  17611. this.selection.getRange().setStart(th, 0).setCursor(false, true);
  17612. }
  17613. };
  17614. UE.commands['deletetitle'] = {
  17615. queryCommandState: function () {
  17616. var table = getTableItemsByRange(this).table;
  17617. if (table) {
  17618. var firstRow = table.rows[0];
  17619. return firstRow.cells[firstRow.cells.length-1].tagName.toLowerCase() == 'th' ? 0 : -1
  17620. }
  17621. return -1;
  17622. },
  17623. execCommand: function () {
  17624. var table = getTableItemsByRange(this).table;
  17625. if (table) {
  17626. domUtils.remove(table.rows[0])
  17627. }
  17628. var td = table.getElementsByTagName('td')[0];
  17629. this.selection.getRange().setStart(td, 0).setCursor(false, true);
  17630. }
  17631. };
  17632. UE.commands['inserttitlecol'] = {
  17633. queryCommandState: function () {
  17634. var table = getTableItemsByRange(this).table;
  17635. if (table) {
  17636. var lastRow = table.rows[table.rows.length-1];
  17637. return lastRow.getElementsByTagName('th').length ? -1 : 0;
  17638. }
  17639. return -1;
  17640. },
  17641. execCommand: function (cmd) {
  17642. var table = getTableItemsByRange(this).table;
  17643. if (table) {
  17644. getUETable(table).insertCol(0, 'th');
  17645. }
  17646. resetTdWidth(table, this);
  17647. var th = table.getElementsByTagName('th')[0];
  17648. this.selection.getRange().setStart(th, 0).setCursor(false, true);
  17649. }
  17650. };
  17651. UE.commands['deletetitlecol'] = {
  17652. queryCommandState: function () {
  17653. var table = getTableItemsByRange(this).table;
  17654. if (table) {
  17655. var lastRow = table.rows[table.rows.length-1];
  17656. return lastRow.getElementsByTagName('th').length ? 0 : -1;
  17657. }
  17658. return -1;
  17659. },
  17660. execCommand: function () {
  17661. var table = getTableItemsByRange(this).table;
  17662. if (table) {
  17663. for(var i = 0; i< table.rows.length; i++ ){
  17664. domUtils.remove(table.rows[i].children[0])
  17665. }
  17666. }
  17667. resetTdWidth(table, this);
  17668. var td = table.getElementsByTagName('td')[0];
  17669. this.selection.getRange().setStart(td, 0).setCursor(false, true);
  17670. }
  17671. };
  17672. UE.commands["mergeright"] = {
  17673. queryCommandState: function (cmd) {
  17674. var tableItems = getTableItemsByRange(this),
  17675. table = tableItems.table,
  17676. cell = tableItems.cell;
  17677. if (!table || !cell) return -1;
  17678. var ut = getUETable(table);
  17679. if (ut.selectedTds.length) return -1;
  17680. var cellInfo = ut.getCellInfo(cell),
  17681. rightColIndex = cellInfo.colIndex + cellInfo.colSpan;
  17682. if (rightColIndex >= ut.colsNum) return -1; // 如果处于最右边则不能向右合并
  17683. var rightCellInfo = ut.indexTable[cellInfo.rowIndex][rightColIndex],
  17684. rightCell = table.rows[rightCellInfo.rowIndex].cells[rightCellInfo.cellIndex];
  17685. if (!rightCell || cell.tagName != rightCell.tagName) return -1; // TH和TD不能相互合并
  17686. // 当且仅当两个Cell的开始列号和结束列号一致时能进行合并
  17687. return (rightCellInfo.rowIndex == cellInfo.rowIndex && rightCellInfo.rowSpan == cellInfo.rowSpan) ? 0 : -1;
  17688. },
  17689. execCommand: function (cmd) {
  17690. var rng = this.selection.getRange(),
  17691. bk = rng.createBookmark(true);
  17692. var cell = getTableItemsByRange(this).cell,
  17693. ut = getUETable(cell);
  17694. ut.mergeRight(cell);
  17695. rng.moveToBookmark(bk).select();
  17696. }
  17697. };
  17698. UE.commands["mergedown"] = {
  17699. queryCommandState: function (cmd) {
  17700. var tableItems = getTableItemsByRange(this),
  17701. table = tableItems.table,
  17702. cell = tableItems.cell;
  17703. if (!table || !cell) return -1;
  17704. var ut = getUETable(table);
  17705. if (ut.selectedTds.length)return -1;
  17706. var cellInfo = ut.getCellInfo(cell),
  17707. downRowIndex = cellInfo.rowIndex + cellInfo.rowSpan;
  17708. if (downRowIndex >= ut.rowsNum) return -1; // 如果处于最下边则不能向下合并
  17709. var downCellInfo = ut.indexTable[downRowIndex][cellInfo.colIndex],
  17710. downCell = table.rows[downCellInfo.rowIndex].cells[downCellInfo.cellIndex];
  17711. if (!downCell || cell.tagName != downCell.tagName) return -1; // TH和TD不能相互合并
  17712. // 当且仅当两个Cell的开始列号和结束列号一致时能进行合并
  17713. return (downCellInfo.colIndex == cellInfo.colIndex && downCellInfo.colSpan == cellInfo.colSpan) ? 0 : -1;
  17714. },
  17715. execCommand: function () {
  17716. var rng = this.selection.getRange(),
  17717. bk = rng.createBookmark(true);
  17718. var cell = getTableItemsByRange(this).cell,
  17719. ut = getUETable(cell);
  17720. ut.mergeDown(cell);
  17721. rng.moveToBookmark(bk).select();
  17722. }
  17723. };
  17724. UE.commands["mergecells"] = {
  17725. queryCommandState: function () {
  17726. return getUETableBySelected(this) ? 0 : -1;
  17727. },
  17728. execCommand: function () {
  17729. var ut = getUETableBySelected(this);
  17730. if (ut && ut.selectedTds.length) {
  17731. var cell = ut.selectedTds[0];
  17732. ut.mergeRange();
  17733. var rng = this.selection.getRange();
  17734. if (domUtils.isEmptyBlock(cell)) {
  17735. rng.setStart(cell, 0).collapse(true)
  17736. } else {
  17737. rng.selectNodeContents(cell)
  17738. }
  17739. rng.select();
  17740. }
  17741. }
  17742. };
  17743. UE.commands["insertrow"] = {
  17744. queryCommandState: function () {
  17745. var tableItems = getTableItemsByRange(this),
  17746. cell = tableItems.cell;
  17747. return cell && (cell.tagName == "TD" || (cell.tagName == 'TH' && tableItems.tr !== tableItems.table.rows[0])) &&
  17748. getUETable(tableItems.table).rowsNum < this.options.maxRowNum ? 0 : -1;
  17749. },
  17750. execCommand: function () {
  17751. var rng = this.selection.getRange(),
  17752. bk = rng.createBookmark(true);
  17753. var tableItems = getTableItemsByRange(this),
  17754. cell = tableItems.cell,
  17755. table = tableItems.table,
  17756. ut = getUETable(table),
  17757. cellInfo = ut.getCellInfo(cell);
  17758. //ut.insertRow(!ut.selectedTds.length ? cellInfo.rowIndex:ut.cellsRange.beginRowIndex,'');
  17759. if (!ut.selectedTds.length) {
  17760. ut.insertRow(cellInfo.rowIndex, cell);
  17761. } else {
  17762. var range = ut.cellsRange;
  17763. for (var i = 0, len = range.endRowIndex - range.beginRowIndex + 1; i < len; i++) {
  17764. ut.insertRow(range.beginRowIndex, cell);
  17765. }
  17766. }
  17767. rng.moveToBookmark(bk).select();
  17768. if (table.getAttribute("interlaced") === "enabled")this.fireEvent("interlacetable", table);
  17769. }
  17770. };
  17771. //后插入行
  17772. UE.commands["insertrownext"] = {
  17773. queryCommandState: function () {
  17774. var tableItems = getTableItemsByRange(this),
  17775. cell = tableItems.cell;
  17776. return cell && (cell.tagName == "TD") && getUETable(tableItems.table).rowsNum < this.options.maxRowNum ? 0 : -1;
  17777. },
  17778. execCommand: function () {
  17779. var rng = this.selection.getRange(),
  17780. bk = rng.createBookmark(true);
  17781. var tableItems = getTableItemsByRange(this),
  17782. cell = tableItems.cell,
  17783. table = tableItems.table,
  17784. ut = getUETable(table),
  17785. cellInfo = ut.getCellInfo(cell);
  17786. //ut.insertRow(!ut.selectedTds.length? cellInfo.rowIndex + cellInfo.rowSpan : ut.cellsRange.endRowIndex + 1,'');
  17787. if (!ut.selectedTds.length) {
  17788. ut.insertRow(cellInfo.rowIndex + cellInfo.rowSpan, cell);
  17789. } else {
  17790. var range = ut.cellsRange;
  17791. for (var i = 0, len = range.endRowIndex - range.beginRowIndex + 1; i < len; i++) {
  17792. ut.insertRow(range.endRowIndex + 1, cell);
  17793. }
  17794. }
  17795. rng.moveToBookmark(bk).select();
  17796. if (table.getAttribute("interlaced") === "enabled")this.fireEvent("interlacetable", table);
  17797. }
  17798. };
  17799. UE.commands["deleterow"] = {
  17800. queryCommandState: function () {
  17801. var tableItems = getTableItemsByRange(this);
  17802. return tableItems.cell ? 0 : -1;
  17803. },
  17804. execCommand: function () {
  17805. var cell = getTableItemsByRange(this).cell,
  17806. ut = getUETable(cell),
  17807. cellsRange = ut.cellsRange,
  17808. cellInfo = ut.getCellInfo(cell),
  17809. preCell = ut.getVSideCell(cell),
  17810. nextCell = ut.getVSideCell(cell, true),
  17811. rng = this.selection.getRange();
  17812. if (utils.isEmptyObject(cellsRange)) {
  17813. ut.deleteRow(cellInfo.rowIndex);
  17814. } else {
  17815. for (var i = cellsRange.beginRowIndex; i < cellsRange.endRowIndex + 1; i++) {
  17816. ut.deleteRow(cellsRange.beginRowIndex);
  17817. }
  17818. }
  17819. var table = ut.table;
  17820. if (!table.getElementsByTagName('td').length) {
  17821. var nextSibling = table.nextSibling;
  17822. domUtils.remove(table);
  17823. if (nextSibling) {
  17824. rng.setStart(nextSibling, 0).setCursor(false, true);
  17825. }
  17826. } else {
  17827. if (cellInfo.rowSpan == 1 || cellInfo.rowSpan == cellsRange.endRowIndex - cellsRange.beginRowIndex + 1) {
  17828. if (nextCell || preCell) rng.selectNodeContents(nextCell || preCell).setCursor(false, true);
  17829. } else {
  17830. var newCell = ut.getCell(cellInfo.rowIndex, ut.indexTable[cellInfo.rowIndex][cellInfo.colIndex].cellIndex);
  17831. if (newCell) rng.selectNodeContents(newCell).setCursor(false, true);
  17832. }
  17833. }
  17834. if (table.getAttribute("interlaced") === "enabled")this.fireEvent("interlacetable", table);
  17835. }
  17836. };
  17837. UE.commands["insertcol"] = {
  17838. queryCommandState: function (cmd) {
  17839. var tableItems = getTableItemsByRange(this),
  17840. cell = tableItems.cell;
  17841. return cell && (cell.tagName == "TD" || (cell.tagName == 'TH' && cell !== tableItems.tr.cells[0])) &&
  17842. getUETable(tableItems.table).colsNum < this.options.maxColNum ? 0 : -1;
  17843. },
  17844. execCommand: function (cmd) {
  17845. var rng = this.selection.getRange(),
  17846. bk = rng.createBookmark(true);
  17847. if (this.queryCommandState(cmd) == -1)return;
  17848. var cell = getTableItemsByRange(this).cell,
  17849. ut = getUETable(cell),
  17850. cellInfo = ut.getCellInfo(cell);
  17851. //ut.insertCol(!ut.selectedTds.length ? cellInfo.colIndex:ut.cellsRange.beginColIndex);
  17852. if (!ut.selectedTds.length) {
  17853. ut.insertCol(cellInfo.colIndex, cell);
  17854. } else {
  17855. var range = ut.cellsRange;
  17856. for (var i = 0, len = range.endColIndex - range.beginColIndex + 1; i < len; i++) {
  17857. ut.insertCol(range.beginColIndex, cell);
  17858. }
  17859. }
  17860. rng.moveToBookmark(bk).select(true);
  17861. }
  17862. };
  17863. UE.commands["insertcolnext"] = {
  17864. queryCommandState: function () {
  17865. var tableItems = getTableItemsByRange(this),
  17866. cell = tableItems.cell;
  17867. return cell && getUETable(tableItems.table).colsNum < this.options.maxColNum ? 0 : -1;
  17868. },
  17869. execCommand: function () {
  17870. var rng = this.selection.getRange(),
  17871. bk = rng.createBookmark(true);
  17872. var cell = getTableItemsByRange(this).cell,
  17873. ut = getUETable(cell),
  17874. cellInfo = ut.getCellInfo(cell);
  17875. //ut.insertCol(!ut.selectedTds.length ? cellInfo.colIndex + cellInfo.colSpan:ut.cellsRange.endColIndex +1);
  17876. if (!ut.selectedTds.length) {
  17877. ut.insertCol(cellInfo.colIndex + cellInfo.colSpan, cell);
  17878. } else {
  17879. var range = ut.cellsRange;
  17880. for (var i = 0, len = range.endColIndex - range.beginColIndex + 1; i < len; i++) {
  17881. ut.insertCol(range.endColIndex + 1, cell);
  17882. }
  17883. }
  17884. rng.moveToBookmark(bk).select();
  17885. }
  17886. };
  17887. UE.commands["deletecol"] = {
  17888. queryCommandState: function () {
  17889. var tableItems = getTableItemsByRange(this);
  17890. return tableItems.cell ? 0 : -1;
  17891. },
  17892. execCommand: function () {
  17893. var cell = getTableItemsByRange(this).cell,
  17894. ut = getUETable(cell),
  17895. range = ut.cellsRange,
  17896. cellInfo = ut.getCellInfo(cell),
  17897. preCell = ut.getHSideCell(cell),
  17898. nextCell = ut.getHSideCell(cell, true);
  17899. if (utils.isEmptyObject(range)) {
  17900. ut.deleteCol(cellInfo.colIndex);
  17901. } else {
  17902. for (var i = range.beginColIndex; i < range.endColIndex + 1; i++) {
  17903. ut.deleteCol(range.beginColIndex);
  17904. }
  17905. }
  17906. var table = ut.table,
  17907. rng = this.selection.getRange();
  17908. if (!table.getElementsByTagName('td').length) {
  17909. var nextSibling = table.nextSibling;
  17910. domUtils.remove(table);
  17911. if (nextSibling) {
  17912. rng.setStart(nextSibling, 0).setCursor(false, true);
  17913. }
  17914. } else {
  17915. if (domUtils.inDoc(cell, this.document)) {
  17916. rng.setStart(cell, 0).setCursor(false, true);
  17917. } else {
  17918. if (nextCell && domUtils.inDoc(nextCell, this.document)) {
  17919. rng.selectNodeContents(nextCell).setCursor(false, true);
  17920. } else {
  17921. if (preCell && domUtils.inDoc(preCell, this.document)) {
  17922. rng.selectNodeContents(preCell).setCursor(true, true);
  17923. }
  17924. }
  17925. }
  17926. }
  17927. }
  17928. };
  17929. UE.commands["splittocells"] = {
  17930. queryCommandState: function () {
  17931. var tableItems = getTableItemsByRange(this),
  17932. cell = tableItems.cell;
  17933. if (!cell) return -1;
  17934. var ut = getUETable(tableItems.table);
  17935. if (ut.selectedTds.length > 0) return -1;
  17936. return cell && (cell.colSpan > 1 || cell.rowSpan > 1) ? 0 : -1;
  17937. },
  17938. execCommand: function () {
  17939. var rng = this.selection.getRange(),
  17940. bk = rng.createBookmark(true);
  17941. var cell = getTableItemsByRange(this).cell,
  17942. ut = getUETable(cell);
  17943. ut.splitToCells(cell);
  17944. rng.moveToBookmark(bk).select();
  17945. }
  17946. };
  17947. UE.commands["splittorows"] = {
  17948. queryCommandState: function () {
  17949. var tableItems = getTableItemsByRange(this),
  17950. cell = tableItems.cell;
  17951. if (!cell) return -1;
  17952. var ut = getUETable(tableItems.table);
  17953. if (ut.selectedTds.length > 0) return -1;
  17954. return cell && cell.rowSpan > 1 ? 0 : -1;
  17955. },
  17956. execCommand: function () {
  17957. var rng = this.selection.getRange(),
  17958. bk = rng.createBookmark(true);
  17959. var cell = getTableItemsByRange(this).cell,
  17960. ut = getUETable(cell);
  17961. ut.splitToRows(cell);
  17962. rng.moveToBookmark(bk).select();
  17963. }
  17964. };
  17965. UE.commands["splittocols"] = {
  17966. queryCommandState: function () {
  17967. var tableItems = getTableItemsByRange(this),
  17968. cell = tableItems.cell;
  17969. if (!cell) return -1;
  17970. var ut = getUETable(tableItems.table);
  17971. if (ut.selectedTds.length > 0) return -1;
  17972. return cell && cell.colSpan > 1 ? 0 : -1;
  17973. },
  17974. execCommand: function () {
  17975. var rng = this.selection.getRange(),
  17976. bk = rng.createBookmark(true);
  17977. var cell = getTableItemsByRange(this).cell,
  17978. ut = getUETable(cell);
  17979. ut.splitToCols(cell);
  17980. rng.moveToBookmark(bk).select();
  17981. }
  17982. };
  17983. UE.commands["adaptbytext"] =
  17984. UE.commands["adaptbywindow"] = {
  17985. queryCommandState: function () {
  17986. return getTableItemsByRange(this).table ? 0 : -1
  17987. },
  17988. execCommand: function (cmd) {
  17989. var tableItems = getTableItemsByRange(this),
  17990. table = tableItems.table;
  17991. if (table) {
  17992. if (cmd == 'adaptbywindow') {
  17993. resetTdWidth(table, this);
  17994. } else {
  17995. var cells = domUtils.getElementsByTagName(table, "td th");
  17996. utils.each(cells, function (cell) {
  17997. cell.removeAttribute("width");
  17998. });
  17999. table.removeAttribute("width");
  18000. }
  18001. }
  18002. }
  18003. };
  18004. //平均分配各列
  18005. UE.commands['averagedistributecol'] = {
  18006. queryCommandState: function () {
  18007. var ut = getUETableBySelected(this);
  18008. if (!ut) return -1;
  18009. return ut.isFullRow() || ut.isFullCol() ? 0 : -1;
  18010. },
  18011. execCommand: function (cmd) {
  18012. var me = this,
  18013. ut = getUETableBySelected(me);
  18014. function getAverageWidth() {
  18015. var tb = ut.table,
  18016. averageWidth, sumWidth = 0, colsNum = 0,
  18017. tbAttr = getDefaultValue(me, tb);
  18018. if (ut.isFullRow()) {
  18019. sumWidth = tb.offsetWidth;
  18020. colsNum = ut.colsNum;
  18021. } else {
  18022. var begin = ut.cellsRange.beginColIndex,
  18023. end = ut.cellsRange.endColIndex,
  18024. node;
  18025. for (var i = begin; i <= end;) {
  18026. node = ut.selectedTds[i];
  18027. sumWidth += node.offsetWidth;
  18028. i += node.colSpan;
  18029. colsNum += 1;
  18030. }
  18031. }
  18032. averageWidth = Math.ceil(sumWidth / colsNum) - tbAttr.tdBorder * 2 - tbAttr.tdPadding * 2;
  18033. return averageWidth;
  18034. }
  18035. function setAverageWidth(averageWidth) {
  18036. utils.each(domUtils.getElementsByTagName(ut.table, "th"), function (node) {
  18037. node.setAttribute("width", "");
  18038. });
  18039. var cells = ut.isFullRow() ? domUtils.getElementsByTagName(ut.table, "td") : ut.selectedTds;
  18040. utils.each(cells, function (node) {
  18041. if (node.colSpan == 1) {
  18042. node.setAttribute("width", averageWidth);
  18043. }
  18044. });
  18045. }
  18046. if (ut && ut.selectedTds.length) {
  18047. setAverageWidth(getAverageWidth());
  18048. }
  18049. }
  18050. };
  18051. //平均分配各行
  18052. UE.commands['averagedistributerow'] = {
  18053. queryCommandState: function () {
  18054. var ut = getUETableBySelected(this);
  18055. if (!ut) return -1;
  18056. if (ut.selectedTds && /th/ig.test(ut.selectedTds[0].tagName)) return -1;
  18057. return ut.isFullRow() || ut.isFullCol() ? 0 : -1;
  18058. },
  18059. execCommand: function (cmd) {
  18060. var me = this,
  18061. ut = getUETableBySelected(me);
  18062. function getAverageHeight() {
  18063. var averageHeight, rowNum, sumHeight = 0,
  18064. tb = ut.table,
  18065. tbAttr = getDefaultValue(me, tb),
  18066. tdpadding = parseInt(domUtils.getComputedStyle(tb.getElementsByTagName('td')[0], "padding-top"));
  18067. if (ut.isFullCol()) {
  18068. var captionArr = domUtils.getElementsByTagName(tb, "caption"),
  18069. thArr = domUtils.getElementsByTagName(tb, "th"),
  18070. captionHeight, thHeight;
  18071. if (captionArr.length > 0) {
  18072. captionHeight = captionArr[0].offsetHeight;
  18073. }
  18074. if (thArr.length > 0) {
  18075. thHeight = thArr[0].offsetHeight;
  18076. }
  18077. sumHeight = tb.offsetHeight - (captionHeight || 0) - (thHeight || 0);
  18078. rowNum = thArr.length == 0 ? ut.rowsNum : (ut.rowsNum - 1);
  18079. } else {
  18080. var begin = ut.cellsRange.beginRowIndex,
  18081. end = ut.cellsRange.endRowIndex,
  18082. count = 0,
  18083. trs = domUtils.getElementsByTagName(tb, "tr");
  18084. for (var i = begin; i <= end; i++) {
  18085. sumHeight += trs[i].offsetHeight;
  18086. count += 1;
  18087. }
  18088. rowNum = count;
  18089. }
  18090. //ie8下是混杂模式
  18091. if (browser.ie && browser.version < 9) {
  18092. averageHeight = Math.ceil(sumHeight / rowNum);
  18093. } else {
  18094. averageHeight = Math.ceil(sumHeight / rowNum) - tbAttr.tdBorder * 2 - tdpadding * 2;
  18095. }
  18096. return averageHeight;
  18097. }
  18098. function setAverageHeight(averageHeight) {
  18099. var cells = ut.isFullCol() ? domUtils.getElementsByTagName(ut.table, "td") : ut.selectedTds;
  18100. utils.each(cells, function (node) {
  18101. if (node.rowSpan == 1) {
  18102. node.setAttribute("height", averageHeight);
  18103. }
  18104. });
  18105. }
  18106. if (ut && ut.selectedTds.length) {
  18107. setAverageHeight(getAverageHeight());
  18108. }
  18109. }
  18110. };
  18111. //单元格对齐方式
  18112. UE.commands['cellalignment'] = {
  18113. queryCommandState: function () {
  18114. return getTableItemsByRange(this).table ? 0 : -1
  18115. },
  18116. execCommand: function (cmd, data) {
  18117. var me = this,
  18118. ut = getUETableBySelected(me);
  18119. if (!ut) {
  18120. var start = me.selection.getStart(),
  18121. cell = start && domUtils.findParentByTagName(start, ["td", "th", "caption"], true);
  18122. if (!/caption/ig.test(cell.tagName)) {
  18123. domUtils.setAttributes(cell, data);
  18124. } else {
  18125. cell.style.textAlign = data.align;
  18126. cell.style.verticalAlign = data.vAlign;
  18127. }
  18128. me.selection.getRange().setCursor(true);
  18129. } else {
  18130. utils.each(ut.selectedTds, function (cell) {
  18131. domUtils.setAttributes(cell, data);
  18132. });
  18133. }
  18134. },
  18135. /**
  18136. * 查询当前点击的单元格的对齐状态, 如果当前已经选择了多个单元格, 则会返回所有单元格经过统一协调过后的状态
  18137. * @see UE.UETable.getTableCellAlignState
  18138. */
  18139. queryCommandValue: function (cmd) {
  18140. var activeMenuCell = getTableItemsByRange( this).cell;
  18141. if( !activeMenuCell ) {
  18142. activeMenuCell = getSelectedArr(this)[0];
  18143. }
  18144. if (!activeMenuCell) {
  18145. return null;
  18146. } else {
  18147. //获取同时选中的其他单元格
  18148. var cells = UE.UETable.getUETable(activeMenuCell).selectedTds;
  18149. !cells.length && ( cells = activeMenuCell );
  18150. return UE.UETable.getTableCellAlignState(cells);
  18151. }
  18152. }
  18153. };
  18154. //表格对齐方式
  18155. UE.commands['tablealignment'] = {
  18156. queryCommandState: function () {
  18157. if (browser.ie && browser.version < 8) {
  18158. return -1;
  18159. }
  18160. return getTableItemsByRange(this).table ? 0 : -1
  18161. },
  18162. execCommand: function (cmd, value) {
  18163. var me = this,
  18164. start = me.selection.getStart(),
  18165. table = start && domUtils.findParentByTagName(start, ["table"], true);
  18166. if (table) {
  18167. table.setAttribute("align",value);
  18168. }
  18169. }
  18170. };
  18171. //表格属性
  18172. UE.commands['edittable'] = {
  18173. queryCommandState: function () {
  18174. return getTableItemsByRange(this).table ? 0 : -1
  18175. },
  18176. execCommand: function (cmd, color) {
  18177. var rng = this.selection.getRange(),
  18178. table = domUtils.findParentByTagName(rng.startContainer, 'table');
  18179. if (table) {
  18180. var arr = domUtils.getElementsByTagName(table, "td").concat(
  18181. domUtils.getElementsByTagName(table, "th"),
  18182. domUtils.getElementsByTagName(table, "caption")
  18183. );
  18184. utils.each(arr, function (node) {
  18185. node.style.borderColor = color;
  18186. });
  18187. }
  18188. }
  18189. };
  18190. //单元格属性
  18191. UE.commands['edittd'] = {
  18192. queryCommandState: function () {
  18193. return getTableItemsByRange(this).table ? 0 : -1
  18194. },
  18195. execCommand: function (cmd, bkColor) {
  18196. var me = this,
  18197. ut = getUETableBySelected(me);
  18198. if (!ut) {
  18199. var start = me.selection.getStart(),
  18200. cell = start && domUtils.findParentByTagName(start, ["td", "th", "caption"], true);
  18201. if (cell) {
  18202. cell.style.backgroundColor = bkColor;
  18203. }
  18204. } else {
  18205. utils.each(ut.selectedTds, function (cell) {
  18206. cell.style.backgroundColor = bkColor;
  18207. });
  18208. }
  18209. }
  18210. };
  18211. UE.commands["settablebackground"] = {
  18212. queryCommandState: function () {
  18213. return getSelectedArr(this).length > 1 ? 0 : -1;
  18214. },
  18215. execCommand: function (cmd, value) {
  18216. var cells, ut;
  18217. cells = getSelectedArr(this);
  18218. ut = getUETable(cells[0]);
  18219. ut.setBackground(cells, value);
  18220. }
  18221. };
  18222. UE.commands["cleartablebackground"] = {
  18223. queryCommandState: function () {
  18224. var cells = getSelectedArr(this);
  18225. if (!cells.length)return -1;
  18226. for (var i = 0, cell; cell = cells[i++];) {
  18227. if (cell.style.backgroundColor !== "") return 0;
  18228. }
  18229. return -1;
  18230. },
  18231. execCommand: function () {
  18232. var cells = getSelectedArr(this),
  18233. ut = getUETable(cells[0]);
  18234. ut.removeBackground(cells);
  18235. }
  18236. };
  18237. UE.commands["interlacetable"] = UE.commands["uninterlacetable"] = {
  18238. queryCommandState: function (cmd) {
  18239. var table = getTableItemsByRange(this).table;
  18240. if (!table) return -1;
  18241. var interlaced = table.getAttribute("interlaced");
  18242. if (cmd == "interlacetable") {
  18243. //TODO 待定
  18244. //是否需要待定,如果设置,则命令只能单次执行成功,但反射具备toggle效果;否则可以覆盖前次命令,但反射将不存在toggle效果
  18245. return (interlaced === "enabled") ? -1 : 0;
  18246. } else {
  18247. return (!interlaced || interlaced === "disabled") ? -1 : 0;
  18248. }
  18249. },
  18250. execCommand: function (cmd, classList) {
  18251. var table = getTableItemsByRange(this).table;
  18252. if (cmd == "interlacetable") {
  18253. table.setAttribute("interlaced", "enabled");
  18254. this.fireEvent("interlacetable", table, classList);
  18255. } else {
  18256. table.setAttribute("interlaced", "disabled");
  18257. this.fireEvent("uninterlacetable", table);
  18258. }
  18259. }
  18260. };
  18261. UE.commands["setbordervisible"] = {
  18262. queryCommandState: function (cmd) {
  18263. var table = getTableItemsByRange(this).table;
  18264. if (!table) return -1;
  18265. return 0;
  18266. },
  18267. execCommand: function () {
  18268. var table = getTableItemsByRange(this).table;
  18269. utils.each(domUtils.getElementsByTagName(table,'td'),function(td){
  18270. td.style.borderWidth = '1px';
  18271. td.style.borderStyle = 'solid';
  18272. })
  18273. }
  18274. };
  18275. function resetTdWidth(table, editor) {
  18276. var tds = domUtils.getElementsByTagName(table,'td th');
  18277. utils.each(tds, function (td) {
  18278. td.removeAttribute("width");
  18279. });
  18280. table.setAttribute('width', getTableWidth(editor, true, getDefaultValue(editor, table)));
  18281. var tdsWidths = [];
  18282. setTimeout(function () {
  18283. utils.each(tds, function (td) {
  18284. (td.colSpan == 1) && tdsWidths.push(td.offsetWidth)
  18285. })
  18286. utils.each(tds, function (td,i) {
  18287. (td.colSpan == 1) && td.setAttribute("width", tdsWidths[i] + "");
  18288. })
  18289. }, 0);
  18290. }
  18291. function getTableWidth(editor, needIEHack, defaultValue) {
  18292. var body = editor.body;
  18293. return body.offsetWidth - (needIEHack ? parseInt(domUtils.getComputedStyle(body, 'margin-left'), 10) * 2 : 0) - defaultValue.tableBorder * 2 - (editor.options.offsetWidth || 0);
  18294. }
  18295. function getSelectedArr(editor) {
  18296. var cell = getTableItemsByRange(editor).cell;
  18297. if (cell) {
  18298. var ut = getUETable(cell);
  18299. return ut.selectedTds.length ? ut.selectedTds : [cell];
  18300. } else {
  18301. return [];
  18302. }
  18303. }
  18304. })();
  18305. // js/editor/_src/plugins/table.action.js
  18306. /**
  18307. * Created with JetBrains PhpStorm.
  18308. * User: taoqili
  18309. * Date: 12-10-12
  18310. * Time: 上午10:05
  18311. * To change this template use File | Settings | File Templates.
  18312. */
  18313. UE.plugins['table'] = function () {
  18314. var me = this,
  18315. tabTimer = null,
  18316. //拖动计时器
  18317. tableDragTimer = null,
  18318. //双击计时器
  18319. tableResizeTimer = null,
  18320. //单元格最小宽度
  18321. cellMinWidth = 5,
  18322. isInResizeBuffer = false,
  18323. //单元格边框大小
  18324. cellBorderWidth = 5,
  18325. //鼠标偏移距离
  18326. offsetOfTableCell = 10,
  18327. //记录在有限时间内的点击状态, 共有3个取值, 0, 1, 2。 0代表未初始化, 1代表单击了1次,2代表2次
  18328. singleClickState = 0,
  18329. userActionStatus = null,
  18330. //双击允许的时间范围
  18331. dblclickTime = 360,
  18332. UT = UE.UETable,
  18333. getUETable = function (tdOrTable) {
  18334. return UT.getUETable(tdOrTable);
  18335. },
  18336. getUETableBySelected = function (editor) {
  18337. return UT.getUETableBySelected(editor);
  18338. },
  18339. getDefaultValue = function (editor, table) {
  18340. return UT.getDefaultValue(editor, table);
  18341. },
  18342. removeSelectedClass = function (cells) {
  18343. return UT.removeSelectedClass(cells);
  18344. };
  18345. function showError(e) {
  18346. // throw e;
  18347. }
  18348. me.ready(function(){
  18349. var me = this;
  18350. var orgGetText = me.selection.getText;
  18351. me.selection.getText = function(){
  18352. var table = getUETableBySelected(me);
  18353. if(table){
  18354. var str = '';
  18355. utils.each(table.selectedTds,function(td){
  18356. str += td[browser.ie?'innerText':'textContent'];
  18357. })
  18358. return str;
  18359. }else{
  18360. return orgGetText.call(me.selection)
  18361. }
  18362. }
  18363. })
  18364. //处理拖动及框选相关方法
  18365. var startTd = null, //鼠标按下时的锚点td
  18366. currentTd = null, //当前鼠标经过时的td
  18367. onDrag = "", //指示当前拖动状态,其值可为"","h","v" ,分别表示未拖动状态,横向拖动状态,纵向拖动状态,用于鼠标移动过程中的判断
  18368. onBorder = false, //检测鼠标按下时是否处在单元格边缘位置
  18369. dragButton = null,
  18370. dragOver = false,
  18371. dragLine = null, //模拟的拖动线
  18372. dragTd = null; //发生拖动的目标td
  18373. var mousedown = false,
  18374. //todo 判断混乱模式
  18375. needIEHack = true;
  18376. me.setOpt({
  18377. 'maxColNum':20,
  18378. 'maxRowNum':100,
  18379. 'defaultCols':5,
  18380. 'defaultRows':5,
  18381. 'tdvalign':'top',
  18382. 'cursorpath':me.options.UEDITOR_HOME_URL + "themes/default/images/cursor_",
  18383. 'tableDragable':false,
  18384. 'classList':["ue-table-interlace-color-single","ue-table-interlace-color-double"]
  18385. });
  18386. me.getUETable = getUETable;
  18387. var commands = {
  18388. 'deletetable':1,
  18389. 'inserttable':1,
  18390. 'cellvalign':1,
  18391. 'insertcaption':1,
  18392. 'deletecaption':1,
  18393. 'inserttitle':1,
  18394. 'deletetitle':1,
  18395. "mergeright":1,
  18396. "mergedown":1,
  18397. "mergecells":1,
  18398. "insertrow":1,
  18399. "insertrownext":1,
  18400. "deleterow":1,
  18401. "insertcol":1,
  18402. "insertcolnext":1,
  18403. "deletecol":1,
  18404. "splittocells":1,
  18405. "splittorows":1,
  18406. "splittocols":1,
  18407. "adaptbytext":1,
  18408. "adaptbywindow":1,
  18409. "adaptbycustomer":1,
  18410. "insertparagraph":1,
  18411. "insertparagraphbeforetable":1,
  18412. "averagedistributecol":1,
  18413. "averagedistributerow":1
  18414. };
  18415. me.ready(function () {
  18416. utils.cssRule('table',
  18417. //选中的td上的样式
  18418. '.selectTdClass{background-color:#edf5fa !important}' +
  18419. 'table.noBorderTable td,table.noBorderTable th,table.noBorderTable caption{border:1px dashed #ddd !important}' +
  18420. //插入的表格的默认样式
  18421. 'table{margin-bottom:10px;border-collapse:collapse;display:table;}' +
  18422. 'td,th{padding: 5px 10px;border: 1px solid #DDD;}' +
  18423. 'caption{border:1px dashed #DDD;border-bottom:0;padding:3px;text-align:center;}' +
  18424. 'th{border-top:1px solid #BBB;background-color:#F7F7F7;}' +
  18425. 'table tr.firstRow th{border-top-width:2px;}' +
  18426. '.ue-table-interlace-color-single{ background-color: #fcfcfc; } .ue-table-interlace-color-double{ background-color: #f7faff; }' +
  18427. 'td p{margin:0;padding:0;}', me.document);
  18428. var tableCopyList, isFullCol, isFullRow;
  18429. //注册del/backspace事件
  18430. me.addListener('keydown', function (cmd, evt) {
  18431. var me = this;
  18432. var keyCode = evt.keyCode || evt.which;
  18433. if (keyCode == 8) {
  18434. var ut = getUETableBySelected(me);
  18435. if (ut && ut.selectedTds.length) {
  18436. if (ut.isFullCol()) {
  18437. me.execCommand('deletecol')
  18438. } else if (ut.isFullRow()) {
  18439. me.execCommand('deleterow')
  18440. } else {
  18441. me.fireEvent('delcells');
  18442. }
  18443. domUtils.preventDefault(evt);
  18444. }
  18445. var caption = domUtils.findParentByTagName(me.selection.getStart(), 'caption', true),
  18446. range = me.selection.getRange();
  18447. if (range.collapsed && caption && isEmptyBlock(caption)) {
  18448. me.fireEvent('saveScene');
  18449. var table = caption.parentNode;
  18450. domUtils.remove(caption);
  18451. if (table) {
  18452. range.setStart(table.rows[0].cells[0], 0).setCursor(false, true);
  18453. }
  18454. me.fireEvent('saveScene');
  18455. }
  18456. }
  18457. if (keyCode == 46) {
  18458. ut = getUETableBySelected(me);
  18459. if (ut) {
  18460. me.fireEvent('saveScene');
  18461. for (var i = 0, ci; ci = ut.selectedTds[i++];) {
  18462. domUtils.fillNode(me.document, ci)
  18463. }
  18464. me.fireEvent('saveScene');
  18465. domUtils.preventDefault(evt);
  18466. }
  18467. }
  18468. if (keyCode == 13) {
  18469. var rng = me.selection.getRange(),
  18470. caption = domUtils.findParentByTagName(rng.startContainer, 'caption', true);
  18471. if (caption) {
  18472. var table = domUtils.findParentByTagName(caption, 'table');
  18473. if (!rng.collapsed) {
  18474. rng.deleteContents();
  18475. me.fireEvent('saveScene');
  18476. } else {
  18477. if (caption) {
  18478. rng.setStart(table.rows[0].cells[0], 0).setCursor(false, true);
  18479. }
  18480. }
  18481. domUtils.preventDefault(evt);
  18482. return;
  18483. }
  18484. if (rng.collapsed) {
  18485. var table = domUtils.findParentByTagName(rng.startContainer, 'table');
  18486. if (table) {
  18487. var cell = table.rows[0].cells[0],
  18488. start = domUtils.findParentByTagName(me.selection.getStart(), ['td', 'th'], true),
  18489. preNode = table.previousSibling;
  18490. if (cell === start && (!preNode || preNode.nodeType == 1 && preNode.tagName == 'TABLE' ) && domUtils.isStartInblock(rng)) {
  18491. var first = domUtils.findParent(me.selection.getStart(), function(n){return domUtils.isBlockElm(n)}, true);
  18492. if(first && ( /t(h|d)/i.test(first.tagName) || first === start.firstChild )){
  18493. me.execCommand('insertparagraphbeforetable');
  18494. domUtils.preventDefault(evt);
  18495. }
  18496. }
  18497. }
  18498. }
  18499. }
  18500. if ((evt.ctrlKey || evt.metaKey) && evt.keyCode == '67') {
  18501. tableCopyList = null;
  18502. var ut = getUETableBySelected(me);
  18503. if (ut) {
  18504. var tds = ut.selectedTds;
  18505. isFullCol = ut.isFullCol();
  18506. isFullRow = ut.isFullRow();
  18507. tableCopyList = [
  18508. [ut.cloneCell(tds[0],null,true)]
  18509. ];
  18510. for (var i = 1, ci; ci = tds[i]; i++) {
  18511. if (ci.parentNode !== tds[i - 1].parentNode) {
  18512. tableCopyList.push([ut.cloneCell(ci,null,true)]);
  18513. } else {
  18514. tableCopyList[tableCopyList.length - 1].push(ut.cloneCell(ci,null,true));
  18515. }
  18516. }
  18517. }
  18518. }
  18519. });
  18520. me.addListener("tablehasdeleted",function(){
  18521. toggleDraggableState(this, false, "", null);
  18522. if (dragButton)domUtils.remove(dragButton);
  18523. });
  18524. me.addListener('beforepaste', function (cmd, html) {
  18525. var me = this;
  18526. var rng = me.selection.getRange();
  18527. if (domUtils.findParentByTagName(rng.startContainer, 'caption', true)) {
  18528. var div = me.document.createElement("div");
  18529. div.innerHTML = html.html;
  18530. //trace:3729
  18531. html.html = div[browser.ie9below ? 'innerText' : 'textContent'];
  18532. return;
  18533. }
  18534. var table = getUETableBySelected(me);
  18535. if (tableCopyList) {
  18536. me.fireEvent('saveScene');
  18537. var rng = me.selection.getRange();
  18538. var td = domUtils.findParentByTagName(rng.startContainer, ['td', 'th'], true), tmpNode, preNode;
  18539. if (td) {
  18540. var ut = getUETable(td);
  18541. if (isFullRow) {
  18542. var rowIndex = ut.getCellInfo(td).rowIndex;
  18543. if (td.tagName == 'TH') {
  18544. rowIndex++;
  18545. }
  18546. for (var i = 0, ci; ci = tableCopyList[i++];) {
  18547. var tr = ut.insertRow(rowIndex++, "td");
  18548. for (var j = 0, cj; cj = ci[j]; j++) {
  18549. var cell = tr.cells[j];
  18550. if (!cell) {
  18551. cell = tr.insertCell(j)
  18552. }
  18553. cell.innerHTML = cj.innerHTML;
  18554. cj.getAttribute('width') && cell.setAttribute('width', cj.getAttribute('width'));
  18555. cj.getAttribute('vAlign') && cell.setAttribute('vAlign', cj.getAttribute('vAlign'));
  18556. cj.getAttribute('align') && cell.setAttribute('align', cj.getAttribute('align'));
  18557. cj.style.cssText && (cell.style.cssText = cj.style.cssText)
  18558. }
  18559. for (var j = 0, cj; cj = tr.cells[j]; j++) {
  18560. if (!ci[j])
  18561. break;
  18562. cj.innerHTML = ci[j].innerHTML;
  18563. ci[j].getAttribute('width') && cj.setAttribute('width', ci[j].getAttribute('width'));
  18564. ci[j].getAttribute('vAlign') && cj.setAttribute('vAlign', ci[j].getAttribute('vAlign'));
  18565. ci[j].getAttribute('align') && cj.setAttribute('align', ci[j].getAttribute('align'));
  18566. ci[j].style.cssText && (cj.style.cssText = ci[j].style.cssText)
  18567. }
  18568. }
  18569. } else {
  18570. if (isFullCol) {
  18571. cellInfo = ut.getCellInfo(td);
  18572. var maxColNum = 0;
  18573. for (var j = 0, ci = tableCopyList[0], cj; cj = ci[j++];) {
  18574. maxColNum += cj.colSpan || 1;
  18575. }
  18576. me.__hasEnterExecCommand = true;
  18577. for (i = 0; i < maxColNum; i++) {
  18578. me.execCommand('insertcol');
  18579. }
  18580. me.__hasEnterExecCommand = false;
  18581. td = ut.table.rows[0].cells[cellInfo.cellIndex];
  18582. if (td.tagName == 'TH') {
  18583. td = ut.table.rows[1].cells[cellInfo.cellIndex];
  18584. }
  18585. }
  18586. for (var i = 0, ci; ci = tableCopyList[i++];) {
  18587. tmpNode = td;
  18588. for (var j = 0, cj; cj = ci[j++];) {
  18589. if (td) {
  18590. td.innerHTML = cj.innerHTML;
  18591. //todo 定制处理
  18592. cj.getAttribute('width') && td.setAttribute('width', cj.getAttribute('width'));
  18593. cj.getAttribute('vAlign') && td.setAttribute('vAlign', cj.getAttribute('vAlign'));
  18594. cj.getAttribute('align') && td.setAttribute('align', cj.getAttribute('align'));
  18595. cj.style.cssText && (td.style.cssText = cj.style.cssText);
  18596. preNode = td;
  18597. td = td.nextSibling;
  18598. } else {
  18599. var cloneTd = cj.cloneNode(true);
  18600. domUtils.removeAttributes(cloneTd, ['class', 'rowSpan', 'colSpan']);
  18601. preNode.parentNode.appendChild(cloneTd)
  18602. }
  18603. }
  18604. td = ut.getNextCell(tmpNode, true, true);
  18605. if (!tableCopyList[i])
  18606. break;
  18607. if (!td) {
  18608. var cellInfo = ut.getCellInfo(tmpNode);
  18609. ut.table.insertRow(ut.table.rows.length);
  18610. ut.update();
  18611. td = ut.getVSideCell(tmpNode, true);
  18612. }
  18613. }
  18614. }
  18615. ut.update();
  18616. } else {
  18617. table = me.document.createElement('table');
  18618. for (var i = 0, ci; ci = tableCopyList[i++];) {
  18619. var tr = table.insertRow(table.rows.length);
  18620. for (var j = 0, cj; cj = ci[j++];) {
  18621. cloneTd = UT.cloneCell(cj,null,true);
  18622. domUtils.removeAttributes(cloneTd, ['class']);
  18623. tr.appendChild(cloneTd)
  18624. }
  18625. if (j == 2 && cloneTd.rowSpan > 1) {
  18626. cloneTd.rowSpan = 1;
  18627. }
  18628. }
  18629. var defaultValue = getDefaultValue(me),
  18630. width = me.body.offsetWidth -
  18631. (needIEHack ? parseInt(domUtils.getComputedStyle(me.body, 'margin-left'), 10) * 2 : 0) - defaultValue.tableBorder * 2 - (me.options.offsetWidth || 0);
  18632. me.execCommand('insertHTML', '<table ' +
  18633. ( isFullCol && isFullRow ? 'width="' + width + '"' : '') +
  18634. '>' + table.innerHTML.replace(/>\s*</g, '><').replace(/\bth\b/gi, "td") + '</table>')
  18635. }
  18636. me.fireEvent('contentchange');
  18637. me.fireEvent('saveScene');
  18638. html.html = '';
  18639. return true;
  18640. } else {
  18641. var div = me.document.createElement("div"), tables;
  18642. div.innerHTML = html.html;
  18643. tables = div.getElementsByTagName("table");
  18644. if (domUtils.findParentByTagName(me.selection.getStart(), 'table')) {
  18645. utils.each(tables, function (t) {
  18646. domUtils.remove(t)
  18647. });
  18648. if (domUtils.findParentByTagName(me.selection.getStart(), 'caption', true)) {
  18649. div.innerHTML = div[browser.ie ? 'innerText' : 'textContent'];
  18650. }
  18651. } else {
  18652. utils.each(tables, function (table) {
  18653. removeStyleSize(table, true);
  18654. domUtils.removeAttributes(table, ['style', 'border']);
  18655. utils.each(domUtils.getElementsByTagName(table, "td"), function (td) {
  18656. if (isEmptyBlock(td)) {
  18657. domUtils.fillNode(me.document, td);
  18658. }
  18659. removeStyleSize(td, true);
  18660. // domUtils.removeAttributes(td, ['style'])
  18661. });
  18662. });
  18663. }
  18664. html.html = div.innerHTML;
  18665. }
  18666. });
  18667. me.addListener('afterpaste', function () {
  18668. utils.each(domUtils.getElementsByTagName(me.body, "table"), function (table) {
  18669. if (table.offsetWidth > me.body.offsetWidth) {
  18670. var defaultValue = getDefaultValue(me, table);
  18671. table.style.width = me.body.offsetWidth - (needIEHack ? parseInt(domUtils.getComputedStyle(me.body, 'margin-left'), 10) * 2 : 0) - defaultValue.tableBorder * 2 - (me.options.offsetWidth || 0) + 'px'
  18672. }
  18673. })
  18674. });
  18675. me.addListener('blur', function () {
  18676. tableCopyList = null;
  18677. });
  18678. var timer;
  18679. me.addListener('keydown', function () {
  18680. clearTimeout(timer);
  18681. timer = setTimeout(function () {
  18682. var rng = me.selection.getRange(),
  18683. cell = domUtils.findParentByTagName(rng.startContainer, ['th', 'td'], true);
  18684. if (cell) {
  18685. var table = cell.parentNode.parentNode.parentNode;
  18686. if (table.offsetWidth > table.getAttribute("width")) {
  18687. cell.style.wordBreak = "break-all";
  18688. }
  18689. }
  18690. }, 100);
  18691. });
  18692. me.addListener("selectionchange", function () {
  18693. toggleDraggableState(me, false, "", null);
  18694. });
  18695. //内容变化时触发索引更新
  18696. //todo 可否考虑标记检测,如果不涉及表格的变化就不进行索引重建和更新
  18697. me.addListener("contentchange", function () {
  18698. var me = this;
  18699. //尽可能排除一些不需要更新的状况
  18700. hideDragLine(me);
  18701. if (getUETableBySelected(me))return;
  18702. var rng = me.selection.getRange();
  18703. var start = rng.startContainer;
  18704. start = domUtils.findParentByTagName(start, ['td', 'th'], true);
  18705. utils.each(domUtils.getElementsByTagName(me.document, 'table'), function (table) {
  18706. if (me.fireEvent("excludetable", table) === true) return;
  18707. table.ueTable = new UT(table);
  18708. //trace:3742
  18709. // utils.each(domUtils.getElementsByTagName(me.document, 'td'), function (td) {
  18710. //
  18711. // if (domUtils.isEmptyBlock(td) && td !== start) {
  18712. // domUtils.fillNode(me.document, td);
  18713. // if (browser.ie && browser.version == 6) {
  18714. // td.innerHTML = '&nbsp;'
  18715. // }
  18716. // }
  18717. // });
  18718. // utils.each(domUtils.getElementsByTagName(me.document, 'th'), function (th) {
  18719. // if (domUtils.isEmptyBlock(th) && th !== start) {
  18720. // domUtils.fillNode(me.document, th);
  18721. // if (browser.ie && browser.version == 6) {
  18722. // th.innerHTML = '&nbsp;'
  18723. // }
  18724. // }
  18725. // });
  18726. table.onmouseover = function () {
  18727. me.fireEvent('tablemouseover', table);
  18728. };
  18729. table.onmousemove = function () {
  18730. me.fireEvent('tablemousemove', table);
  18731. me.options.tableDragable && toggleDragButton(true, this, me);
  18732. utils.defer(function(){
  18733. me.fireEvent('contentchange',50)
  18734. },true)
  18735. };
  18736. table.onmouseout = function () {
  18737. me.fireEvent('tablemouseout', table);
  18738. toggleDraggableState(me, false, "", null);
  18739. hideDragLine(me);
  18740. };
  18741. table.onclick = function (evt) {
  18742. evt = me.window.event || evt;
  18743. var target = getParentTdOrTh(evt.target || evt.srcElement);
  18744. if (!target)return;
  18745. var ut = getUETable(target),
  18746. table = ut.table,
  18747. cellInfo = ut.getCellInfo(target),
  18748. cellsRange,
  18749. rng = me.selection.getRange();
  18750. // if ("topLeft" == inPosition(table, mouseCoords(evt))) {
  18751. // cellsRange = ut.getCellsRange(ut.table.rows[0].cells[0], ut.getLastCell());
  18752. // ut.setSelected(cellsRange);
  18753. // return;
  18754. // }
  18755. // if ("bottomRight" == inPosition(table, mouseCoords(evt))) {
  18756. //
  18757. // return;
  18758. // }
  18759. if (inTableSide(table, target, evt, true)) {
  18760. var endTdCol = ut.getCell(ut.indexTable[ut.rowsNum - 1][cellInfo.colIndex].rowIndex, ut.indexTable[ut.rowsNum - 1][cellInfo.colIndex].cellIndex);
  18761. if (evt.shiftKey && ut.selectedTds.length) {
  18762. if (ut.selectedTds[0] !== endTdCol) {
  18763. cellsRange = ut.getCellsRange(ut.selectedTds[0], endTdCol);
  18764. ut.setSelected(cellsRange);
  18765. } else {
  18766. rng && rng.selectNodeContents(endTdCol).select();
  18767. }
  18768. } else {
  18769. if (target !== endTdCol) {
  18770. cellsRange = ut.getCellsRange(target, endTdCol);
  18771. ut.setSelected(cellsRange);
  18772. } else {
  18773. rng && rng.selectNodeContents(endTdCol).select();
  18774. }
  18775. }
  18776. return;
  18777. }
  18778. if (inTableSide(table, target, evt)) {
  18779. var endTdRow = ut.getCell(ut.indexTable[cellInfo.rowIndex][ut.colsNum - 1].rowIndex, ut.indexTable[cellInfo.rowIndex][ut.colsNum - 1].cellIndex);
  18780. if (evt.shiftKey && ut.selectedTds.length) {
  18781. if (ut.selectedTds[0] !== endTdRow) {
  18782. cellsRange = ut.getCellsRange(ut.selectedTds[0], endTdRow);
  18783. ut.setSelected(cellsRange);
  18784. } else {
  18785. rng && rng.selectNodeContents(endTdRow).select();
  18786. }
  18787. } else {
  18788. if (target !== endTdRow) {
  18789. cellsRange = ut.getCellsRange(target, endTdRow);
  18790. ut.setSelected(cellsRange);
  18791. } else {
  18792. rng && rng.selectNodeContents(endTdRow).select();
  18793. }
  18794. }
  18795. }
  18796. };
  18797. });
  18798. switchBorderColor(me, true);
  18799. });
  18800. domUtils.on(me.document, "mousemove", mouseMoveEvent);
  18801. domUtils.on(me.document, "mouseout", function (evt) {
  18802. var target = evt.target || evt.srcElement;
  18803. if (target.tagName == "TABLE") {
  18804. toggleDraggableState(me, false, "", null);
  18805. }
  18806. });
  18807. /**
  18808. * 表格隔行变色
  18809. */
  18810. me.addListener("interlacetable",function(type,table,classList){
  18811. if(!table) return;
  18812. var me = this,
  18813. rows = table.rows,
  18814. len = rows.length,
  18815. getClass = function(list,index,repeat){
  18816. return list[index] ? list[index] : repeat ? list[index % list.length]: "";
  18817. };
  18818. for(var i = 0;i<len;i++){
  18819. rows[i].className = getClass( classList|| me.options.classList,i,true);
  18820. }
  18821. });
  18822. me.addListener("uninterlacetable",function(type,table){
  18823. if(!table) return;
  18824. var me = this,
  18825. rows = table.rows,
  18826. classList = me.options.classList,
  18827. len = rows.length;
  18828. for(var i = 0;i<len;i++){
  18829. domUtils.removeClasses( rows[i], classList );
  18830. }
  18831. });
  18832. me.addListener("mousedown", mouseDownEvent);
  18833. me.addListener("mouseup", mouseUpEvent);
  18834. //拖动的时候触发mouseup
  18835. domUtils.on( me.body, 'dragstart', function( evt ){
  18836. mouseUpEvent.call( me, 'dragstart', evt );
  18837. });
  18838. me.addOutputRule(function(root){
  18839. utils.each(root.getNodesByTagName('div'),function(n){
  18840. if (n.getAttr('id') == 'ue_tableDragLine') {
  18841. n.parentNode.removeChild(n);
  18842. }
  18843. });
  18844. });
  18845. var currentRowIndex = 0;
  18846. me.addListener("mousedown", function () {
  18847. currentRowIndex = 0;
  18848. });
  18849. me.addListener('tabkeydown', function () {
  18850. var range = this.selection.getRange(),
  18851. common = range.getCommonAncestor(true, true),
  18852. table = domUtils.findParentByTagName(common, 'table');
  18853. if (table) {
  18854. if (domUtils.findParentByTagName(common, 'caption', true)) {
  18855. var cell = domUtils.getElementsByTagName(table, 'th td');
  18856. if (cell && cell.length) {
  18857. range.setStart(cell[0], 0).setCursor(false, true)
  18858. }
  18859. } else {
  18860. var cell = domUtils.findParentByTagName(common, ['td', 'th'], true),
  18861. ua = getUETable(cell);
  18862. currentRowIndex = cell.rowSpan > 1 ? currentRowIndex : ua.getCellInfo(cell).rowIndex;
  18863. var nextCell = ua.getTabNextCell(cell, currentRowIndex);
  18864. if (nextCell) {
  18865. if (isEmptyBlock(nextCell)) {
  18866. range.setStart(nextCell, 0).setCursor(false, true)
  18867. } else {
  18868. range.selectNodeContents(nextCell).select()
  18869. }
  18870. } else {
  18871. me.fireEvent('saveScene');
  18872. me.__hasEnterExecCommand = true;
  18873. this.execCommand('insertrownext');
  18874. me.__hasEnterExecCommand = false;
  18875. range = this.selection.getRange();
  18876. range.setStart(table.rows[table.rows.length - 1].cells[0], 0).setCursor();
  18877. me.fireEvent('saveScene');
  18878. }
  18879. }
  18880. return true;
  18881. }
  18882. });
  18883. browser.ie && me.addListener('selectionchange', function () {
  18884. toggleDraggableState(this, false, "", null);
  18885. });
  18886. me.addListener("keydown", function (type, evt) {
  18887. var me = this;
  18888. //处理在表格的最后一个输入tab产生新的表格
  18889. var keyCode = evt.keyCode || evt.which;
  18890. if (keyCode == 8 || keyCode == 46) {
  18891. return;
  18892. }
  18893. var notCtrlKey = !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey;
  18894. notCtrlKey && removeSelectedClass(domUtils.getElementsByTagName(me.body, "td"));
  18895. var ut = getUETableBySelected(me);
  18896. if (!ut) return;
  18897. notCtrlKey && ut.clearSelected();
  18898. });
  18899. me.addListener("beforegetcontent", function () {
  18900. switchBorderColor(this, false);
  18901. browser.ie && utils.each(this.document.getElementsByTagName('caption'), function (ci) {
  18902. if (domUtils.isEmptyNode(ci)) {
  18903. ci.innerHTML = '&nbsp;'
  18904. }
  18905. });
  18906. });
  18907. me.addListener("aftergetcontent", function () {
  18908. switchBorderColor(this, true);
  18909. });
  18910. me.addListener("getAllHtml", function () {
  18911. removeSelectedClass(me.document.getElementsByTagName("td"));
  18912. });
  18913. //修正全屏状态下插入的表格宽度在非全屏状态下撑开编辑器的情况
  18914. me.addListener("fullscreenchanged", function (type, fullscreen) {
  18915. if (!fullscreen) {
  18916. var ratio = this.body.offsetWidth / document.body.offsetWidth,
  18917. tables = domUtils.getElementsByTagName(this.body, "table");
  18918. utils.each(tables, function (table) {
  18919. if (table.offsetWidth < me.body.offsetWidth) return false;
  18920. var tds = domUtils.getElementsByTagName(table, "td"),
  18921. backWidths = [];
  18922. utils.each(tds, function (td) {
  18923. backWidths.push(td.offsetWidth);
  18924. });
  18925. for (var i = 0, td; td = tds[i]; i++) {
  18926. td.setAttribute("width", Math.floor(backWidths[i] * ratio));
  18927. }
  18928. table.setAttribute("width", Math.floor(getTableWidth(me, needIEHack, getDefaultValue(me))))
  18929. });
  18930. }
  18931. });
  18932. //重写execCommand命令,用于处理框选时的处理
  18933. var oldExecCommand = me.execCommand;
  18934. me.execCommand = function (cmd, datatat) {
  18935. var me = this,
  18936. args = arguments;
  18937. cmd = cmd.toLowerCase();
  18938. var ut = getUETableBySelected(me), tds,
  18939. range = new dom.Range(me.document),
  18940. cmdFun = me.commands[cmd] || UE.commands[cmd],
  18941. result;
  18942. if (!cmdFun) return;
  18943. if (ut && !commands[cmd] && !cmdFun.notNeedUndo && !me.__hasEnterExecCommand) {
  18944. me.__hasEnterExecCommand = true;
  18945. me.fireEvent("beforeexeccommand", cmd);
  18946. tds = ut.selectedTds;
  18947. var lastState = -2, lastValue = -2, value, state;
  18948. for (var i = 0, td; td = tds[i]; i++) {
  18949. if (isEmptyBlock(td)) {
  18950. range.setStart(td, 0).setCursor(false, true)
  18951. } else {
  18952. range.selectNode(td).select(true);
  18953. }
  18954. state = me.queryCommandState(cmd);
  18955. value = me.queryCommandValue(cmd);
  18956. if (state != -1) {
  18957. if (lastState !== state || lastValue !== value) {
  18958. me._ignoreContentChange = true;
  18959. result = oldExecCommand.apply(me, arguments);
  18960. me._ignoreContentChange = false;
  18961. }
  18962. lastState = me.queryCommandState(cmd);
  18963. lastValue = me.queryCommandValue(cmd);
  18964. if (domUtils.isEmptyBlock(td)) {
  18965. domUtils.fillNode(me.document, td)
  18966. }
  18967. }
  18968. }
  18969. range.setStart(tds[0], 0).shrinkBoundary(true).setCursor(false, true);
  18970. me.fireEvent('contentchange');
  18971. me.fireEvent("afterexeccommand", cmd);
  18972. me.__hasEnterExecCommand = false;
  18973. me._selectionChange();
  18974. } else {
  18975. result = oldExecCommand.apply(me, arguments);
  18976. }
  18977. return result;
  18978. };
  18979. });
  18980. /**
  18981. * 删除obj的宽高style,改成属性宽高
  18982. * @param obj
  18983. * @param replaceToProperty
  18984. */
  18985. function removeStyleSize(obj, replaceToProperty) {
  18986. removeStyle(obj, "width", true);
  18987. removeStyle(obj, "height", true);
  18988. }
  18989. function removeStyle(obj, styleName, replaceToProperty) {
  18990. if (obj.style[styleName]) {
  18991. replaceToProperty && obj.setAttribute(styleName, parseInt(obj.style[styleName], 10));
  18992. obj.style[styleName] = "";
  18993. }
  18994. }
  18995. function getParentTdOrTh(ele) {
  18996. if (ele.tagName == "TD" || ele.tagName == "TH") return ele;
  18997. var td;
  18998. if (td = domUtils.findParentByTagName(ele, "td", true) || domUtils.findParentByTagName(ele, "th", true)) return td;
  18999. return null;
  19000. }
  19001. function isEmptyBlock(node) {
  19002. var reg = new RegExp(domUtils.fillChar, 'g');
  19003. if (node[browser.ie ? 'innerText' : 'textContent'].replace(/^\s*$/, '').replace(reg, '').length > 0) {
  19004. return 0;
  19005. }
  19006. for (var n in dtd.$isNotEmpty) {
  19007. if (node.getElementsByTagName(n).length) {
  19008. return 0;
  19009. }
  19010. }
  19011. return 1;
  19012. }
  19013. function mouseCoords(evt) {
  19014. if (evt.pageX || evt.pageY) {
  19015. return { x:evt.pageX, y:evt.pageY };
  19016. }
  19017. return {
  19018. x:evt.clientX + me.document.body.scrollLeft - me.document.body.clientLeft,
  19019. y:evt.clientY + me.document.body.scrollTop - me.document.body.clientTop
  19020. };
  19021. }
  19022. function mouseMoveEvent(evt) {
  19023. if( isEditorDisabled() ) {
  19024. return;
  19025. }
  19026. try {
  19027. //普通状态下鼠标移动
  19028. var target = getParentTdOrTh(evt.target || evt.srcElement),
  19029. pos;
  19030. //区分用户的行为是拖动还是双击
  19031. if( isInResizeBuffer ) {
  19032. me.body.style.webkitUserSelect = 'none';
  19033. if( Math.abs( userActionStatus.x - evt.clientX ) > offsetOfTableCell || Math.abs( userActionStatus.y - evt.clientY ) > offsetOfTableCell ) {
  19034. clearTableDragTimer();
  19035. isInResizeBuffer = false;
  19036. singleClickState = 0;
  19037. //drag action
  19038. tableBorderDrag(evt);
  19039. }
  19040. }
  19041. //修改单元格大小时的鼠标移动
  19042. if (onDrag && dragTd) {
  19043. singleClickState = 0;
  19044. me.body.style.webkitUserSelect = 'none';
  19045. me.selection.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']();
  19046. pos = mouseCoords(evt);
  19047. toggleDraggableState(me, true, onDrag, pos, target);
  19048. if (onDrag == "h") {
  19049. dragLine.style.left = getPermissionX(dragTd, evt) + "px";
  19050. } else if (onDrag == "v") {
  19051. dragLine.style.top = getPermissionY(dragTd, evt) + "px";
  19052. }
  19053. return;
  19054. }
  19055. //当鼠标处于table上时,修改移动过程中的光标状态
  19056. if (target) {
  19057. //针对使用table作为容器的组件不触发拖拽效果
  19058. if (me.fireEvent('excludetable', target) === true)
  19059. return;
  19060. pos = mouseCoords(evt);
  19061. var state = getRelation(target, pos),
  19062. table = domUtils.findParentByTagName(target, "table", true);
  19063. if (inTableSide(table, target, evt, true)) {
  19064. if (me.fireEvent("excludetable", table) === true) return;
  19065. me.body.style.cursor = "url(" + me.options.cursorpath + "h.png),pointer";
  19066. } else if (inTableSide(table, target, evt)) {
  19067. if (me.fireEvent("excludetable", table) === true) return;
  19068. me.body.style.cursor = "url(" + me.options.cursorpath + "v.png),pointer";
  19069. } else {
  19070. me.body.style.cursor = "text";
  19071. var curCell = target;
  19072. if (/\d/.test(state)) {
  19073. state = state.replace(/\d/, '');
  19074. target = getUETable(target).getPreviewCell(target, state == "v");
  19075. }
  19076. //位于第一行的顶部或者第一列的左边时不可拖动
  19077. toggleDraggableState(me, target ? !!state : false, target ? state : '', pos, target);
  19078. }
  19079. } else {
  19080. toggleDragButton(false, table, me);
  19081. }
  19082. } catch (e) {
  19083. showError(e);
  19084. }
  19085. }
  19086. var dragButtonTimer;
  19087. function toggleDragButton(show, table, editor) {
  19088. if (!show) {
  19089. if (dragOver)return;
  19090. dragButtonTimer = setTimeout(function () {
  19091. !dragOver && dragButton && dragButton.parentNode && dragButton.parentNode.removeChild(dragButton);
  19092. }, 2000);
  19093. } else {
  19094. createDragButton(table, editor);
  19095. }
  19096. }
  19097. function createDragButton(table, editor) {
  19098. var pos = domUtils.getXY(table),
  19099. doc = table.ownerDocument;
  19100. if (dragButton && dragButton.parentNode)return dragButton;
  19101. dragButton = doc.createElement("div");
  19102. dragButton.contentEditable = false;
  19103. dragButton.innerHTML = "";
  19104. dragButton.style.cssText = "width:15px;height:15px;background-image:url(" + editor.options.UEDITOR_HOME_URL + "dialogs/table/dragicon.png);position: absolute;cursor:move;top:" + (pos.y - 15) + "px;left:" + (pos.x) + "px;";
  19105. domUtils.unSelectable(dragButton);
  19106. dragButton.onmouseover = function (evt) {
  19107. dragOver = true;
  19108. };
  19109. dragButton.onmouseout = function (evt) {
  19110. dragOver = false;
  19111. };
  19112. domUtils.on(dragButton, 'click', function (type, evt) {
  19113. doClick(evt, this);
  19114. });
  19115. domUtils.on(dragButton, 'dblclick', function (type, evt) {
  19116. doDblClick(evt);
  19117. });
  19118. domUtils.on(dragButton, 'dragstart', function (type, evt) {
  19119. domUtils.preventDefault(evt);
  19120. });
  19121. var timer;
  19122. function doClick(evt, button) {
  19123. // 部分浏览器下需要清理
  19124. clearTimeout(timer);
  19125. timer = setTimeout(function () {
  19126. editor.fireEvent("tableClicked", table, button);
  19127. }, 300);
  19128. }
  19129. function doDblClick(evt) {
  19130. clearTimeout(timer);
  19131. var ut = getUETable(table),
  19132. start = table.rows[0].cells[0],
  19133. end = ut.getLastCell(),
  19134. range = ut.getCellsRange(start, end);
  19135. editor.selection.getRange().setStart(start, 0).setCursor(false, true);
  19136. ut.setSelected(range);
  19137. }
  19138. doc.body.appendChild(dragButton);
  19139. }
  19140. // function inPosition(table, pos) {
  19141. // var tablePos = domUtils.getXY(table),
  19142. // width = table.offsetWidth,
  19143. // height = table.offsetHeight;
  19144. // if (pos.x - tablePos.x < 5 && pos.y - tablePos.y < 5) {
  19145. // return "topLeft";
  19146. // } else if (tablePos.x + width - pos.x < 5 && tablePos.y + height - pos.y < 5) {
  19147. // return "bottomRight";
  19148. // }
  19149. // }
  19150. function inTableSide(table, cell, evt, top) {
  19151. var pos = mouseCoords(evt),
  19152. state = getRelation(cell, pos);
  19153. if (top) {
  19154. var caption = table.getElementsByTagName("caption")[0],
  19155. capHeight = caption ? caption.offsetHeight : 0;
  19156. return (state == "v1") && ((pos.y - domUtils.getXY(table).y - capHeight) < 8);
  19157. } else {
  19158. return (state == "h1") && ((pos.x - domUtils.getXY(table).x) < 8);
  19159. }
  19160. }
  19161. /**
  19162. * 获取拖动时允许的X轴坐标
  19163. * @param dragTd
  19164. * @param evt
  19165. */
  19166. function getPermissionX(dragTd, evt) {
  19167. var ut = getUETable(dragTd);
  19168. if (ut) {
  19169. var preTd = ut.getSameEndPosCells(dragTd, "x")[0],
  19170. nextTd = ut.getSameStartPosXCells(dragTd)[0],
  19171. mouseX = mouseCoords(evt).x,
  19172. left = (preTd ? domUtils.getXY(preTd).x : domUtils.getXY(ut.table).x) + 20 ,
  19173. right = nextTd ? domUtils.getXY(nextTd).x + nextTd.offsetWidth - 20 : (me.body.offsetWidth + 5 || parseInt(domUtils.getComputedStyle(me.body, "width"), 10));
  19174. left += cellMinWidth;
  19175. right -= cellMinWidth;
  19176. return mouseX < left ? left : mouseX > right ? right : mouseX;
  19177. }
  19178. }
  19179. /**
  19180. * 获取拖动时允许的Y轴坐标
  19181. */
  19182. function getPermissionY(dragTd, evt) {
  19183. try {
  19184. var top = domUtils.getXY(dragTd).y,
  19185. mousePosY = mouseCoords(evt).y;
  19186. return mousePosY < top ? top : mousePosY;
  19187. } catch (e) {
  19188. showError(e);
  19189. }
  19190. }
  19191. /**
  19192. * 移动状态切换
  19193. */
  19194. function toggleDraggableState(editor, draggable, dir, mousePos, cell) {
  19195. try {
  19196. editor.body.style.cursor = dir == "h" ? "col-resize" : dir == "v" ? "row-resize" : "text";
  19197. if (browser.ie) {
  19198. if (dir && !mousedown && !getUETableBySelected(editor)) {
  19199. getDragLine(editor, editor.document);
  19200. showDragLineAt(dir, cell);
  19201. } else {
  19202. hideDragLine(editor)
  19203. }
  19204. }
  19205. onBorder = draggable;
  19206. } catch (e) {
  19207. showError(e);
  19208. }
  19209. }
  19210. /**
  19211. * 获取与UETable相关的resize line
  19212. * @param uetable UETable对象
  19213. */
  19214. function getResizeLineByUETable() {
  19215. var lineId = '_UETableResizeLine',
  19216. line = this.document.getElementById( lineId );
  19217. if( !line ) {
  19218. line = this.document.createElement("div");
  19219. line.id = lineId;
  19220. line.contnetEditable = false;
  19221. line.setAttribute("unselectable", "on");
  19222. var styles = {
  19223. width: 2*cellBorderWidth + 1 + 'px',
  19224. position: 'absolute',
  19225. 'z-index': 100000,
  19226. cursor: 'col-resize',
  19227. background: 'red',
  19228. display: 'none'
  19229. };
  19230. //切换状态
  19231. line.onmouseout = function(){
  19232. this.style.display = 'none';
  19233. };
  19234. utils.extend( line.style, styles );
  19235. this.document.body.appendChild( line );
  19236. }
  19237. return line;
  19238. }
  19239. /**
  19240. * 更新resize-line
  19241. */
  19242. function updateResizeLine( cell, uetable ) {
  19243. var line = getResizeLineByUETable.call( this ),
  19244. table = uetable.table,
  19245. styles = {
  19246. top: domUtils.getXY( table ).y + 'px',
  19247. left: domUtils.getXY( cell).x + cell.offsetWidth - cellBorderWidth + 'px',
  19248. display: 'block',
  19249. height: table.offsetHeight + 'px'
  19250. };
  19251. utils.extend( line.style, styles );
  19252. }
  19253. /**
  19254. * 显示resize-line
  19255. */
  19256. function showResizeLine( cell ) {
  19257. var uetable = getUETable( cell );
  19258. updateResizeLine.call( this, cell, uetable );
  19259. }
  19260. /**
  19261. * 获取鼠标与当前单元格的相对位置
  19262. * @param ele
  19263. * @param mousePos
  19264. */
  19265. function getRelation(ele, mousePos) {
  19266. var elePos = domUtils.getXY(ele);
  19267. if( !elePos ) {
  19268. return '';
  19269. }
  19270. if (elePos.x + ele.offsetWidth - mousePos.x < cellBorderWidth) {
  19271. return "h";
  19272. }
  19273. if (mousePos.x - elePos.x < cellBorderWidth) {
  19274. return 'h1'
  19275. }
  19276. if (elePos.y + ele.offsetHeight - mousePos.y < cellBorderWidth) {
  19277. return "v";
  19278. }
  19279. if (mousePos.y - elePos.y < cellBorderWidth) {
  19280. return 'v1'
  19281. }
  19282. return '';
  19283. }
  19284. function mouseDownEvent(type, evt) {
  19285. if( isEditorDisabled() ) {
  19286. return ;
  19287. }
  19288. userActionStatus = {
  19289. x: evt.clientX,
  19290. y: evt.clientY
  19291. };
  19292. //右键菜单单独处理
  19293. if (evt.button == 2) {
  19294. var ut = getUETableBySelected(me),
  19295. flag = false;
  19296. if (ut) {
  19297. var td = getTargetTd(me, evt);
  19298. utils.each(ut.selectedTds, function (ti) {
  19299. if (ti === td) {
  19300. flag = true;
  19301. }
  19302. });
  19303. if (!flag) {
  19304. removeSelectedClass(domUtils.getElementsByTagName(me.body, "th td"));
  19305. ut.clearSelected()
  19306. } else {
  19307. td = ut.selectedTds[0];
  19308. setTimeout(function () {
  19309. me.selection.getRange().setStart(td, 0).setCursor(false, true);
  19310. }, 0);
  19311. }
  19312. }
  19313. } else {
  19314. tableClickHander( evt );
  19315. }
  19316. }
  19317. //清除表格的计时器
  19318. function clearTableTimer() {
  19319. tabTimer && clearTimeout( tabTimer );
  19320. tabTimer = null;
  19321. }
  19322. //双击收缩
  19323. function tableDbclickHandler(evt) {
  19324. singleClickState = 0;
  19325. evt = evt || me.window.event;
  19326. var target = getParentTdOrTh(evt.target || evt.srcElement);
  19327. if (target) {
  19328. var h;
  19329. if (h = getRelation(target, mouseCoords(evt))) {
  19330. hideDragLine( me );
  19331. if (h == 'h1') {
  19332. h = 'h';
  19333. if (inTableSide(domUtils.findParentByTagName(target, "table"), target, evt)) {
  19334. me.execCommand('adaptbywindow');
  19335. } else {
  19336. target = getUETable(target).getPreviewCell(target);
  19337. if (target) {
  19338. var rng = me.selection.getRange();
  19339. rng.selectNodeContents(target).setCursor(true, true)
  19340. }
  19341. }
  19342. }
  19343. if (h == 'h') {
  19344. var ut = getUETable(target),
  19345. table = ut.table,
  19346. cells = getCellsByMoveBorder( target, table, true );
  19347. cells = extractArray( cells, 'left' );
  19348. ut.width = ut.offsetWidth;
  19349. var oldWidth = [],
  19350. newWidth = [];
  19351. utils.each( cells, function( cell ){
  19352. oldWidth.push( cell.offsetWidth );
  19353. } );
  19354. utils.each( cells, function( cell ){
  19355. cell.removeAttribute("width");
  19356. } );
  19357. window.setTimeout( function(){
  19358. //是否允许改变
  19359. var changeable = true;
  19360. utils.each( cells, function( cell, index ){
  19361. var width = cell.offsetWidth;
  19362. if( width > oldWidth[index] ) {
  19363. changeable = false;
  19364. return false;
  19365. }
  19366. newWidth.push( width );
  19367. } );
  19368. var change = changeable ? newWidth : oldWidth;
  19369. utils.each( cells, function( cell, index ){
  19370. cell.width = change[index] - getTabcellSpace();
  19371. } );
  19372. }, 0 );
  19373. // minWidth -= cellMinWidth;
  19374. //
  19375. // table.removeAttribute("width");
  19376. // utils.each(cells, function (cell) {
  19377. // cell.style.width = "";
  19378. // cell.width -= minWidth;
  19379. // });
  19380. }
  19381. }
  19382. }
  19383. }
  19384. function tableClickHander( evt ) {
  19385. removeSelectedClass(domUtils.getElementsByTagName(me.body, "td th"));
  19386. //trace:3113
  19387. //选中单元格,点击table外部,不会清掉table上挂的ueTable,会引起getUETableBySelected方法返回值
  19388. utils.each(me.document.getElementsByTagName('table'), function (t) {
  19389. t.ueTable = null;
  19390. });
  19391. startTd = getTargetTd(me, evt);
  19392. if( !startTd ) return;
  19393. var table = domUtils.findParentByTagName(startTd, "table", true);
  19394. ut = getUETable(table);
  19395. ut && ut.clearSelected();
  19396. //判断当前鼠标状态
  19397. if (!onBorder) {
  19398. me.document.body.style.webkitUserSelect = '';
  19399. mousedown = true;
  19400. me.addListener('mouseover', mouseOverEvent);
  19401. } else {
  19402. //边框上的动作处理
  19403. borderActionHandler( evt );
  19404. }
  19405. }
  19406. //处理表格边框上的动作, 这里做延时处理,避免两种动作互相影响
  19407. function borderActionHandler( evt ) {
  19408. if ( browser.ie ) {
  19409. evt = reconstruct(evt );
  19410. }
  19411. clearTableDragTimer();
  19412. //是否正在等待resize的缓冲中
  19413. isInResizeBuffer = true;
  19414. tableDragTimer = setTimeout(function(){
  19415. tableBorderDrag( evt );
  19416. }, dblclickTime);
  19417. }
  19418. function extractArray( originArr, key ) {
  19419. var result = [],
  19420. tmp = null;
  19421. for( var i = 0, len = originArr.length; i<len; i++ ) {
  19422. tmp = originArr[ i ][ key ];
  19423. if( tmp ) {
  19424. result.push( tmp );
  19425. }
  19426. }
  19427. return result;
  19428. }
  19429. function clearTableDragTimer() {
  19430. tableDragTimer && clearTimeout(tableDragTimer);
  19431. tableDragTimer = null;
  19432. }
  19433. function reconstruct( obj ) {
  19434. var attrs = ['pageX', 'pageY', 'clientX', 'clientY', 'srcElement', 'target'],
  19435. newObj = {};
  19436. if( obj ) {
  19437. for( var i = 0, key, val; key = attrs[i]; i++ ) {
  19438. val=obj[ key ];
  19439. val && (newObj[ key ] = val);
  19440. }
  19441. }
  19442. return newObj;
  19443. }
  19444. //边框拖动
  19445. function tableBorderDrag( evt ) {
  19446. isInResizeBuffer = false;
  19447. startTd = evt.target || evt.srcElement;
  19448. if( !startTd ) return;
  19449. var state = getRelation(startTd, mouseCoords(evt));
  19450. if (/\d/.test(state)) {
  19451. state = state.replace(/\d/, '');
  19452. startTd = getUETable(startTd).getPreviewCell(startTd, state == 'v');
  19453. }
  19454. hideDragLine(me);
  19455. getDragLine(me, me.document);
  19456. me.fireEvent('saveScene');
  19457. showDragLineAt(state, startTd);
  19458. mousedown = true;
  19459. //拖动开始
  19460. onDrag = state;
  19461. dragTd = startTd;
  19462. }
  19463. function mouseUpEvent(type, evt) {
  19464. if( isEditorDisabled() ) {
  19465. return ;
  19466. }
  19467. clearTableDragTimer();
  19468. isInResizeBuffer = false;
  19469. if( onBorder ) {
  19470. singleClickState = ++singleClickState % 3;
  19471. userActionStatus = {
  19472. x: evt.clientX,
  19473. y: evt.clientY
  19474. };
  19475. tableResizeTimer = setTimeout(function(){
  19476. singleClickState > 0 && singleClickState--;
  19477. }, dblclickTime );
  19478. if( singleClickState === 2 ) {
  19479. singleClickState = 0;
  19480. tableDbclickHandler(evt);
  19481. return;
  19482. }
  19483. }
  19484. if (evt.button == 2)return;
  19485. var me = this;
  19486. //清除表格上原生跨选问题
  19487. var range = me.selection.getRange(),
  19488. start = domUtils.findParentByTagName(range.startContainer, 'table', true),
  19489. end = domUtils.findParentByTagName(range.endContainer, 'table', true);
  19490. if (start || end) {
  19491. if (start === end) {
  19492. start = domUtils.findParentByTagName(range.startContainer, ['td', 'th', 'caption'], true);
  19493. end = domUtils.findParentByTagName(range.endContainer, ['td', 'th', 'caption'], true);
  19494. if (start !== end) {
  19495. me.selection.clearRange()
  19496. }
  19497. } else {
  19498. me.selection.clearRange()
  19499. }
  19500. }
  19501. mousedown = false;
  19502. me.document.body.style.webkitUserSelect = '';
  19503. //拖拽状态下的mouseUP
  19504. if ( onDrag && dragTd ) {
  19505. me.selection.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']();
  19506. singleClickState = 0;
  19507. dragLine = me.document.getElementById('ue_tableDragLine');
  19508. // trace 3973
  19509. if (dragLine) {
  19510. var dragTdPos = domUtils.getXY(dragTd),
  19511. dragLinePos = domUtils.getXY(dragLine);
  19512. switch (onDrag) {
  19513. case "h":
  19514. changeColWidth(dragTd, dragLinePos.x - dragTdPos.x);
  19515. break;
  19516. case "v":
  19517. changeRowHeight(dragTd, dragLinePos.y - dragTdPos.y - dragTd.offsetHeight);
  19518. break;
  19519. default:
  19520. }
  19521. onDrag = "";
  19522. dragTd = null;
  19523. hideDragLine(me);
  19524. me.fireEvent('saveScene');
  19525. return;
  19526. }
  19527. }
  19528. //正常状态下的mouseup
  19529. if (!startTd) {
  19530. var target = domUtils.findParentByTagName(evt.target || evt.srcElement, "td", true);
  19531. if (!target) target = domUtils.findParentByTagName(evt.target || evt.srcElement, "th", true);
  19532. if (target && (target.tagName == "TD" || target.tagName == "TH")) {
  19533. if (me.fireEvent("excludetable", target) === true) return;
  19534. range = new dom.Range(me.document);
  19535. range.setStart(target, 0).setCursor(false, true);
  19536. }
  19537. } else {
  19538. var ut = getUETable(startTd),
  19539. cell = ut ? ut.selectedTds[0] : null;
  19540. if (cell) {
  19541. range = new dom.Range(me.document);
  19542. if (domUtils.isEmptyBlock(cell)) {
  19543. range.setStart(cell, 0).setCursor(false, true);
  19544. } else {
  19545. range.selectNodeContents(cell).shrinkBoundary().setCursor(false, true);
  19546. }
  19547. } else {
  19548. range = me.selection.getRange().shrinkBoundary();
  19549. if (!range.collapsed) {
  19550. var start = domUtils.findParentByTagName(range.startContainer, ['td', 'th'], true),
  19551. end = domUtils.findParentByTagName(range.endContainer, ['td', 'th'], true);
  19552. //在table里边的不能清除
  19553. if (start && !end || !start && end || start && end && start !== end) {
  19554. range.setCursor(false, true);
  19555. }
  19556. }
  19557. }
  19558. startTd = null;
  19559. me.removeListener('mouseover', mouseOverEvent);
  19560. }
  19561. me._selectionChange(250, evt);
  19562. }
  19563. function mouseOverEvent(type, evt) {
  19564. if( isEditorDisabled() ) {
  19565. return;
  19566. }
  19567. var me = this,
  19568. tar = evt.target || evt.srcElement;
  19569. currentTd = domUtils.findParentByTagName(tar, "td", true) || domUtils.findParentByTagName(tar, "th", true);
  19570. //需要判断两个TD是否位于同一个表格内
  19571. if (startTd && currentTd &&
  19572. ((startTd.tagName == "TD" && currentTd.tagName == "TD") || (startTd.tagName == "TH" && currentTd.tagName == "TH")) &&
  19573. domUtils.findParentByTagName(startTd, 'table') == domUtils.findParentByTagName(currentTd, 'table')) {
  19574. var ut = getUETable(currentTd);
  19575. if (startTd != currentTd) {
  19576. me.document.body.style.webkitUserSelect = 'none';
  19577. me.selection.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']();
  19578. var range = ut.getCellsRange(startTd, currentTd);
  19579. ut.setSelected(range);
  19580. } else {
  19581. me.document.body.style.webkitUserSelect = '';
  19582. ut.clearSelected();
  19583. }
  19584. }
  19585. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  19586. }
  19587. function setCellHeight(cell, height, backHeight) {
  19588. var lineHight = parseInt(domUtils.getComputedStyle(cell, "line-height"), 10),
  19589. tmpHeight = backHeight + height;
  19590. height = tmpHeight < lineHight ? lineHight : tmpHeight;
  19591. if (cell.style.height) cell.style.height = "";
  19592. cell.rowSpan == 1 ? cell.setAttribute("height", height) : (cell.removeAttribute && cell.removeAttribute("height"));
  19593. }
  19594. function getWidth(cell) {
  19595. if (!cell)return 0;
  19596. return parseInt(domUtils.getComputedStyle(cell, "width"), 10);
  19597. }
  19598. function changeColWidth(cell, changeValue) {
  19599. var ut = getUETable(cell);
  19600. if (ut) {
  19601. //根据当前移动的边框获取相关的单元格
  19602. var table = ut.table,
  19603. cells = getCellsByMoveBorder( cell, table );
  19604. table.style.width = "";
  19605. table.removeAttribute("width");
  19606. //修正改变量
  19607. changeValue = correctChangeValue( changeValue, cell, cells );
  19608. if (cell.nextSibling) {
  19609. var i=0;
  19610. utils.each( cells, function( cellGroup ){
  19611. cellGroup.left.width = (+cellGroup.left.width)+changeValue;
  19612. cellGroup.right && ( cellGroup.right.width = (+cellGroup.right.width)-changeValue );
  19613. } );
  19614. } else {
  19615. utils.each( cells, function( cellGroup ){
  19616. cellGroup.left.width -= -changeValue;
  19617. } );
  19618. }
  19619. }
  19620. }
  19621. function isEditorDisabled() {
  19622. return me.body.contentEditable === "false";
  19623. }
  19624. function changeRowHeight(td, changeValue) {
  19625. if (Math.abs(changeValue) < 10) return;
  19626. var ut = getUETable(td);
  19627. if (ut) {
  19628. var cells = ut.getSameEndPosCells(td, "y"),
  19629. //备份需要连带变化的td的原始高度,否则后期无法获取正确的值
  19630. backHeight = cells[0] ? cells[0].offsetHeight : 0;
  19631. for (var i = 0, cell; cell = cells[i++];) {
  19632. setCellHeight(cell, changeValue, backHeight);
  19633. }
  19634. }
  19635. }
  19636. /**
  19637. * 获取调整单元格大小的相关单元格
  19638. * @isContainMergeCell 返回的结果中是否包含发生合并后的单元格
  19639. */
  19640. function getCellsByMoveBorder( cell, table, isContainMergeCell ) {
  19641. if( !table ) {
  19642. table = domUtils.findParentByTagName( cell, 'table' );
  19643. }
  19644. if( !table ) {
  19645. return null;
  19646. }
  19647. //获取到该单元格所在行的序列号
  19648. var index = domUtils.getNodeIndex( cell ),
  19649. temp = cell,
  19650. rows = table.rows,
  19651. colIndex = 0;
  19652. while( temp ) {
  19653. //获取到当前单元格在未发生单元格合并时的序列
  19654. if( temp.nodeType === 1 ) {
  19655. colIndex += (temp.colSpan || 1);
  19656. }
  19657. temp = temp.previousSibling;
  19658. }
  19659. temp = null;
  19660. //记录想关的单元格
  19661. var borderCells = [];
  19662. utils.each(rows, function( tabRow ){
  19663. var cells = tabRow.cells,
  19664. currIndex = 0;
  19665. utils.each( cells, function( tabCell ){
  19666. currIndex += (tabCell.colSpan || 1);
  19667. if( currIndex === colIndex ) {
  19668. borderCells.push({
  19669. left: tabCell,
  19670. right: tabCell.nextSibling || null
  19671. });
  19672. return false;
  19673. } else if( currIndex > colIndex ) {
  19674. if( isContainMergeCell ) {
  19675. borderCells.push({
  19676. left: tabCell
  19677. });
  19678. }
  19679. return false;
  19680. }
  19681. } );
  19682. });
  19683. return borderCells;
  19684. }
  19685. /**
  19686. * 通过给定的单元格集合获取最小的单元格width
  19687. */
  19688. function getMinWidthByTableCells( cells ) {
  19689. var minWidth = Number.MAX_VALUE;
  19690. for( var i = 0, curCell; curCell = cells[ i ] ; i++ ) {
  19691. minWidth = Math.min( minWidth, curCell.width || getTableCellWidth( curCell ) );
  19692. }
  19693. return minWidth;
  19694. }
  19695. function correctChangeValue( changeValue, relatedCell, cells ) {
  19696. //为单元格的paading预留空间
  19697. changeValue -= getTabcellSpace();
  19698. if( changeValue < 0 ) {
  19699. return 0;
  19700. }
  19701. changeValue -= getTableCellWidth( relatedCell );
  19702. //确定方向
  19703. var direction = changeValue < 0 ? 'left':'right';
  19704. changeValue = Math.abs(changeValue);
  19705. //只关心非最后一个单元格就可以
  19706. utils.each( cells, function( cellGroup ){
  19707. var curCell = cellGroup[direction];
  19708. //为单元格保留最小空间
  19709. if( curCell ) {
  19710. changeValue = Math.min( changeValue, getTableCellWidth( curCell )-cellMinWidth );
  19711. }
  19712. } );
  19713. //修正越界
  19714. changeValue = changeValue < 0 ? 0 : changeValue;
  19715. return direction === 'left' ? -changeValue : changeValue;
  19716. }
  19717. function getTableCellWidth( cell ) {
  19718. var width = 0,
  19719. //偏移纠正量
  19720. offset = 0,
  19721. width = cell.offsetWidth - getTabcellSpace();
  19722. //最后一个节点纠正一下
  19723. if( !cell.nextSibling ) {
  19724. width -= getTableCellOffset( cell );
  19725. }
  19726. width = width < 0 ? 0 : width;
  19727. try {
  19728. cell.width = width;
  19729. } catch(e) {
  19730. }
  19731. return width;
  19732. }
  19733. /**
  19734. * 获取单元格所在表格的最末单元格的偏移量
  19735. */
  19736. function getTableCellOffset( cell ) {
  19737. tab = domUtils.findParentByTagName( cell, "table", false);
  19738. if( tab.offsetVal === undefined ) {
  19739. var prev = cell.previousSibling;
  19740. if( prev ) {
  19741. //最后一个单元格和前一个单元格的width diff结果 如果恰好为一个border width, 则条件成立
  19742. tab.offsetVal = cell.offsetWidth - prev.offsetWidth === UT.borderWidth ? UT.borderWidth : 0;
  19743. } else {
  19744. tab.offsetVal = 0;
  19745. }
  19746. }
  19747. return tab.offsetVal;
  19748. }
  19749. function getTabcellSpace() {
  19750. if( UT.tabcellSpace === undefined ) {
  19751. var cell = null,
  19752. tab = me.document.createElement("table"),
  19753. tbody = me.document.createElement("tbody"),
  19754. trow = me.document.createElement("tr"),
  19755. tabcell = me.document.createElement("td"),
  19756. mirror = null;
  19757. tabcell.style.cssText = 'border: 0;';
  19758. tabcell.width = 1;
  19759. trow.appendChild( tabcell );
  19760. trow.appendChild( mirror = tabcell.cloneNode( false ) );
  19761. tbody.appendChild( trow );
  19762. tab.appendChild( tbody );
  19763. tab.style.cssText = "visibility: hidden;";
  19764. me.body.appendChild( tab );
  19765. UT.paddingSpace = tabcell.offsetWidth - 1;
  19766. var tmpTabWidth = tab.offsetWidth;
  19767. tabcell.style.cssText = '';
  19768. mirror.style.cssText = '';
  19769. UT.borderWidth = ( tab.offsetWidth - tmpTabWidth ) / 3;
  19770. UT.tabcellSpace = UT.paddingSpace + UT.borderWidth;
  19771. me.body.removeChild( tab );
  19772. }
  19773. getTabcellSpace = function(){ return UT.tabcellSpace; };
  19774. return UT.tabcellSpace;
  19775. }
  19776. function getDragLine(editor, doc) {
  19777. if (mousedown)return;
  19778. dragLine = editor.document.createElement("div");
  19779. domUtils.setAttributes(dragLine, {
  19780. id:"ue_tableDragLine",
  19781. unselectable:'on',
  19782. contenteditable:false,
  19783. 'onresizestart':'return false',
  19784. 'ondragstart':'return false',
  19785. 'onselectstart':'return false',
  19786. style:"background-color:blue;position:absolute;padding:0;margin:0;background-image:none;border:0px none;opacity:0;filter:alpha(opacity=0)"
  19787. });
  19788. editor.body.appendChild(dragLine);
  19789. }
  19790. function hideDragLine(editor) {
  19791. if (mousedown)return;
  19792. var line;
  19793. while (line = editor.document.getElementById('ue_tableDragLine')) {
  19794. domUtils.remove(line)
  19795. }
  19796. }
  19797. /**
  19798. * 依据state(v|h)在cell位置显示横线
  19799. * @param state
  19800. * @param cell
  19801. */
  19802. function showDragLineAt(state, cell) {
  19803. if (!cell) return;
  19804. var table = domUtils.findParentByTagName(cell, "table"),
  19805. caption = table.getElementsByTagName('caption'),
  19806. width = table.offsetWidth,
  19807. height = table.offsetHeight - (caption.length > 0 ? caption[0].offsetHeight : 0),
  19808. tablePos = domUtils.getXY(table),
  19809. cellPos = domUtils.getXY(cell), css;
  19810. switch (state) {
  19811. case "h":
  19812. css = 'height:' + height + 'px;top:' + (tablePos.y + (caption.length > 0 ? caption[0].offsetHeight : 0)) + 'px;left:' + (cellPos.x + cell.offsetWidth);
  19813. dragLine.style.cssText = css + 'px;position: absolute;display:block;background-color:blue;width:1px;border:0; color:blue;opacity:.3;filter:alpha(opacity=30)';
  19814. break;
  19815. case "v":
  19816. css = 'width:' + width + 'px;left:' + tablePos.x + 'px;top:' + (cellPos.y + cell.offsetHeight );
  19817. //必须加上border:0和color:blue,否则低版ie不支持背景色显示
  19818. dragLine.style.cssText = css + 'px;overflow:hidden;position: absolute;display:block;background-color:blue;height:1px;border:0;color:blue;opacity:.2;filter:alpha(opacity=20)';
  19819. break;
  19820. default:
  19821. }
  19822. }
  19823. /**
  19824. * 当表格边框颜色为白色时设置为虚线,true为添加虚线
  19825. * @param editor
  19826. * @param flag
  19827. */
  19828. function switchBorderColor(editor, flag) {
  19829. var tableArr = domUtils.getElementsByTagName(editor.body, "table"), color;
  19830. for (var i = 0, node; node = tableArr[i++];) {
  19831. var td = domUtils.getElementsByTagName(node, "td");
  19832. if (td[0]) {
  19833. if (flag) {
  19834. color = (td[0].style.borderColor).replace(/\s/g, "");
  19835. if (/(#ffffff)|(rgb\(255,255,255\))/ig.test(color))
  19836. domUtils.addClass(node, "noBorderTable")
  19837. } else {
  19838. domUtils.removeClasses(node, "noBorderTable")
  19839. }
  19840. }
  19841. }
  19842. }
  19843. function getTableWidth(editor, needIEHack, defaultValue) {
  19844. var body = editor.body;
  19845. return body.offsetWidth - (needIEHack ? parseInt(domUtils.getComputedStyle(body, 'margin-left'), 10) * 2 : 0) - defaultValue.tableBorder * 2 - (editor.options.offsetWidth || 0);
  19846. }
  19847. /**
  19848. * 获取当前拖动的单元格
  19849. */
  19850. function getTargetTd(editor, evt) {
  19851. var target = domUtils.findParentByTagName(evt.target || evt.srcElement, ["td", "th"], true),
  19852. dir = null;
  19853. if( !target ) {
  19854. return null;
  19855. }
  19856. dir = getRelation( target, mouseCoords( evt ) );
  19857. //如果有前一个节点, 需要做一个修正, 否则可能会得到一个错误的td
  19858. if( !target ) {
  19859. return null;
  19860. }
  19861. if( dir === 'h1' && target.previousSibling ) {
  19862. var position = domUtils.getXY( target),
  19863. cellWidth = target.offsetWidth;
  19864. if( Math.abs( position.x + cellWidth - evt.clientX ) > cellWidth / 3 ) {
  19865. target = target.previousSibling;
  19866. }
  19867. } else if( dir === 'v1' && target.parentNode.previousSibling ) {
  19868. var position = domUtils.getXY( target),
  19869. cellHeight = target.offsetHeight;
  19870. if( Math.abs( position.y + cellHeight - evt.clientY ) > cellHeight / 3 ) {
  19871. target = target.parentNode.previousSibling.firstChild;
  19872. }
  19873. }
  19874. //排除了非td内部以及用于代码高亮部分的td
  19875. return target && !(editor.fireEvent("excludetable", target) === true) ? target : null;
  19876. }
  19877. };
  19878. // js/editor/_src/plugins/table.sort.js
  19879. /**
  19880. * Created with JetBrains PhpStorm.
  19881. * User: Jinqn
  19882. * Date: 13-10-12
  19883. * Time: 上午10:20
  19884. * To change this template use File | Settings | File Templates.
  19885. */
  19886. UE.UETable.prototype.sortTable = function (sortByCellIndex, compareFn) {
  19887. var table = this.table,
  19888. rows = table.rows,
  19889. trArray = [],
  19890. flag = rows[0].cells[0].tagName === "TH",
  19891. lastRowIndex = 0;
  19892. if(this.selectedTds.length){
  19893. var range = this.cellsRange,
  19894. len = range.endRowIndex + 1;
  19895. for (var i = range.beginRowIndex; i < len; i++) {
  19896. trArray[i] = rows[i];
  19897. }
  19898. trArray.splice(0,range.beginRowIndex);
  19899. lastRowIndex = (range.endRowIndex +1) === this.rowsNum ? 0 : range.endRowIndex +1;
  19900. }else{
  19901. for (var i = 0,len = rows.length; i < len; i++) {
  19902. trArray[i] = rows[i];
  19903. }
  19904. }
  19905. var Fn = {
  19906. 'reversecurrent': function(td1,td2){
  19907. return 1;
  19908. },
  19909. 'orderbyasc': function(td1,td2){
  19910. var value1 = td1.innerText||td1.textContent,
  19911. value2 = td2.innerText||td2.textContent;
  19912. return value1.localeCompare(value2);
  19913. },
  19914. 'reversebyasc': function(td1,td2){
  19915. var value1 = td1.innerHTML,
  19916. value2 = td2.innerHTML;
  19917. return value2.localeCompare(value1);
  19918. },
  19919. 'orderbynum': function(td1,td2){
  19920. var value1 = td1[browser.ie ? 'innerText':'textContent'].match(/\d+/),
  19921. value2 = td2[browser.ie ? 'innerText':'textContent'].match(/\d+/);
  19922. if(value1) value1 = +value1[0];
  19923. if(value2) value2 = +value2[0];
  19924. return (value1||0) - (value2||0);
  19925. },
  19926. 'reversebynum': function(td1,td2){
  19927. var value1 = td1[browser.ie ? 'innerText':'textContent'].match(/\d+/),
  19928. value2 = td2[browser.ie ? 'innerText':'textContent'].match(/\d+/);
  19929. if(value1) value1 = +value1[0];
  19930. if(value2) value2 = +value2[0];
  19931. return (value2||0) - (value1||0);
  19932. }
  19933. };
  19934. //对表格设置排序的标记data-sort-type
  19935. table.setAttribute('data-sort-type', compareFn && typeof compareFn === "string" && Fn[compareFn] ? compareFn:'');
  19936. //th不参与排序
  19937. flag && trArray.splice(0, 1);
  19938. trArray = utils.sort(trArray,function (tr1, tr2) {
  19939. var result;
  19940. if (compareFn && typeof compareFn === "function") {
  19941. result = compareFn.call(this, tr1.cells[sortByCellIndex], tr2.cells[sortByCellIndex]);
  19942. } else if (compareFn && typeof compareFn === "number") {
  19943. result = 1;
  19944. } else if (compareFn && typeof compareFn === "string" && Fn[compareFn]) {
  19945. result = Fn[compareFn].call(this, tr1.cells[sortByCellIndex], tr2.cells[sortByCellIndex]);
  19946. } else {
  19947. result = Fn['orderbyasc'].call(this, tr1.cells[sortByCellIndex], tr2.cells[sortByCellIndex]);
  19948. }
  19949. return result;
  19950. });
  19951. var fragment = table.ownerDocument.createDocumentFragment();
  19952. for (var j = 0, len = trArray.length; j < len; j++) {
  19953. fragment.appendChild(trArray[j]);
  19954. }
  19955. var tbody = table.getElementsByTagName("tbody")[0];
  19956. if(!lastRowIndex){
  19957. tbody.appendChild(fragment);
  19958. }else{
  19959. tbody.insertBefore(fragment,rows[lastRowIndex- range.endRowIndex + range.beginRowIndex - 1])
  19960. }
  19961. };
  19962. UE.plugins['tablesort'] = function () {
  19963. var me = this,
  19964. UT = UE.UETable,
  19965. getUETable = function (tdOrTable) {
  19966. return UT.getUETable(tdOrTable);
  19967. },
  19968. getTableItemsByRange = function (editor) {
  19969. return UT.getTableItemsByRange(editor);
  19970. };
  19971. me.ready(function () {
  19972. //添加表格可排序的样式
  19973. utils.cssRule('tablesort',
  19974. 'table.sortEnabled tr.firstRow th,table.sortEnabled tr.firstRow td{padding-right:20px;background-repeat: no-repeat;background-position: center right;' +
  19975. ' background-image:url(' + me.options.themePath + me.options.theme + '/images/sortable.png);}',
  19976. me.document);
  19977. //做单元格合并操作时,清除可排序标识
  19978. me.addListener("afterexeccommand", function (type, cmd) {
  19979. if( cmd == 'mergeright' || cmd == 'mergedown' || cmd == 'mergecells') {
  19980. this.execCommand('disablesort');
  19981. }
  19982. });
  19983. });
  19984. //表格排序
  19985. UE.commands['sorttable'] = {
  19986. queryCommandState: function () {
  19987. var me = this,
  19988. tableItems = getTableItemsByRange(me);
  19989. if (!tableItems.cell) return -1;
  19990. var table = tableItems.table,
  19991. cells = table.getElementsByTagName("td");
  19992. for (var i = 0, cell; cell = cells[i++];) {
  19993. if (cell.rowSpan != 1 || cell.colSpan != 1) return -1;
  19994. }
  19995. return 0;
  19996. },
  19997. execCommand: function (cmd, fn) {
  19998. var me = this,
  19999. range = me.selection.getRange(),
  20000. bk = range.createBookmark(true),
  20001. tableItems = getTableItemsByRange(me),
  20002. cell = tableItems.cell,
  20003. ut = getUETable(tableItems.table),
  20004. cellInfo = ut.getCellInfo(cell);
  20005. ut.sortTable(cellInfo.cellIndex, fn);
  20006. range.moveToBookmark(bk);
  20007. try{
  20008. range.select();
  20009. }catch(e){}
  20010. }
  20011. };
  20012. //设置表格可排序,清除表格可排序
  20013. UE.commands["enablesort"] = UE.commands["disablesort"] = {
  20014. queryCommandState: function (cmd) {
  20015. var table = getTableItemsByRange(this).table;
  20016. if(table && cmd=='enablesort') {
  20017. var cells = domUtils.getElementsByTagName(table, 'th td');
  20018. for(var i = 0; i<cells.length; i++) {
  20019. if(cells[i].getAttribute('colspan')>1 || cells[i].getAttribute('rowspan')>1) return -1;
  20020. }
  20021. }
  20022. return !table ? -1: cmd=='enablesort' ^ table.getAttribute('data-sort')!='sortEnabled' ? -1:0;
  20023. },
  20024. execCommand: function (cmd) {
  20025. var table = getTableItemsByRange(this).table;
  20026. table.setAttribute("data-sort", cmd == "enablesort" ? "sortEnabled" : "sortDisabled");
  20027. cmd == "enablesort" ? domUtils.addClass(table,"sortEnabled"):domUtils.removeClasses(table,"sortEnabled");
  20028. }
  20029. };
  20030. };
  20031. // js/editor/_src/plugins/contextmenu.js
  20032. ///import core
  20033. ///commands 右键菜单
  20034. ///commandsName ContextMenu
  20035. ///commandsTitle 右键菜单
  20036. /**
  20037. * 右键菜单
  20038. * @function
  20039. * @name baidu.editor.plugins.contextmenu
  20040. * @author zhanyi
  20041. */
  20042. UE.plugins['contextmenu'] = function () {
  20043. var me = this;
  20044. me.setOpt('enableContextMenu',true);
  20045. if(me.getOpt('enableContextMenu') === false){
  20046. return;
  20047. }
  20048. var lang = me.getLang( "contextMenu" ),
  20049. menu,
  20050. items = me.options.contextMenu || [
  20051. {label:lang['selectall'], cmdName:'selectall'},
  20052. {
  20053. label:lang.cleardoc,
  20054. cmdName:'cleardoc',
  20055. exec:function () {
  20056. if ( confirm( lang.confirmclear ) ) {
  20057. this.execCommand( 'cleardoc' );
  20058. }
  20059. }
  20060. },
  20061. '-',
  20062. {
  20063. label:lang.unlink,
  20064. cmdName:'unlink'
  20065. },
  20066. '-',
  20067. {
  20068. group:lang.paragraph,
  20069. icon:'justifyjustify',
  20070. subMenu:[
  20071. {
  20072. label:lang.justifyleft,
  20073. cmdName:'justify',
  20074. value:'left'
  20075. },
  20076. {
  20077. label:lang.justifyright,
  20078. cmdName:'justify',
  20079. value:'right'
  20080. },
  20081. {
  20082. label:lang.justifycenter,
  20083. cmdName:'justify',
  20084. value:'center'
  20085. },
  20086. {
  20087. label:lang.justifyjustify,
  20088. cmdName:'justify',
  20089. value:'justify'
  20090. }
  20091. ]
  20092. },
  20093. '-',
  20094. {
  20095. group:lang.table,
  20096. icon:'table',
  20097. subMenu:[
  20098. {
  20099. label:lang.inserttable,
  20100. cmdName:'inserttable'
  20101. },
  20102. {
  20103. label:lang.deletetable,
  20104. cmdName:'deletetable'
  20105. },
  20106. '-',
  20107. {
  20108. label:lang.deleterow,
  20109. cmdName:'deleterow'
  20110. },
  20111. {
  20112. label:lang.deletecol,
  20113. cmdName:'deletecol'
  20114. },
  20115. {
  20116. label:lang.insertcol,
  20117. cmdName:'insertcol'
  20118. },
  20119. {
  20120. label:lang.insertcolnext,
  20121. cmdName:'insertcolnext'
  20122. },
  20123. {
  20124. label:lang.insertrow,
  20125. cmdName:'insertrow'
  20126. },
  20127. {
  20128. label:lang.insertrownext,
  20129. cmdName:'insertrownext'
  20130. },
  20131. '-',
  20132. {
  20133. label:lang.insertcaption,
  20134. cmdName:'insertcaption'
  20135. },
  20136. {
  20137. label:lang.deletecaption,
  20138. cmdName:'deletecaption'
  20139. },
  20140. {
  20141. label:lang.inserttitle,
  20142. cmdName:'inserttitle'
  20143. },
  20144. {
  20145. label:lang.deletetitle,
  20146. cmdName:'deletetitle'
  20147. },
  20148. {
  20149. label:lang.inserttitlecol,
  20150. cmdName:'inserttitlecol'
  20151. },
  20152. {
  20153. label:lang.deletetitlecol,
  20154. cmdName:'deletetitlecol'
  20155. },
  20156. '-',
  20157. {
  20158. label:lang.mergecells,
  20159. cmdName:'mergecells'
  20160. },
  20161. {
  20162. label:lang.mergeright,
  20163. cmdName:'mergeright'
  20164. },
  20165. {
  20166. label:lang.mergedown,
  20167. cmdName:'mergedown'
  20168. },
  20169. '-',
  20170. {
  20171. label:lang.splittorows,
  20172. cmdName:'splittorows'
  20173. },
  20174. {
  20175. label:lang.splittocols,
  20176. cmdName:'splittocols'
  20177. },
  20178. {
  20179. label:lang.splittocells,
  20180. cmdName:'splittocells'
  20181. },
  20182. '-',
  20183. {
  20184. label:lang.averageDiseRow,
  20185. cmdName:'averagedistributerow'
  20186. },
  20187. {
  20188. label:lang.averageDisCol,
  20189. cmdName:'averagedistributecol'
  20190. },
  20191. '-',
  20192. {
  20193. label:lang.edittd,
  20194. cmdName:'edittd',
  20195. exec:function () {
  20196. if ( UE.ui['edittd'] ) {
  20197. new UE.ui['edittd']( this );
  20198. }
  20199. this.getDialog('edittd').open();
  20200. }
  20201. },
  20202. {
  20203. label:lang.edittable,
  20204. cmdName:'edittable',
  20205. exec:function () {
  20206. if ( UE.ui['edittable'] ) {
  20207. new UE.ui['edittable']( this );
  20208. }
  20209. this.getDialog('edittable').open();
  20210. }
  20211. },
  20212. {
  20213. label:lang.setbordervisible,
  20214. cmdName:'setbordervisible'
  20215. }
  20216. ]
  20217. },
  20218. {
  20219. group:lang.tablesort,
  20220. icon:'tablesort',
  20221. subMenu:[
  20222. {
  20223. label:lang.enablesort,
  20224. cmdName:'enablesort'
  20225. },
  20226. {
  20227. label:lang.disablesort,
  20228. cmdName:'disablesort'
  20229. },
  20230. '-',
  20231. {
  20232. label:lang.reversecurrent,
  20233. cmdName:'sorttable',
  20234. value:'reversecurrent'
  20235. },
  20236. {
  20237. label:lang.orderbyasc,
  20238. cmdName:'sorttable',
  20239. value:'orderbyasc'
  20240. },
  20241. {
  20242. label:lang.reversebyasc,
  20243. cmdName:'sorttable',
  20244. value:'reversebyasc'
  20245. },
  20246. {
  20247. label:lang.orderbynum,
  20248. cmdName:'sorttable',
  20249. value:'orderbynum'
  20250. },
  20251. {
  20252. label:lang.reversebynum,
  20253. cmdName:'sorttable',
  20254. value:'reversebynum'
  20255. }
  20256. ]
  20257. },
  20258. {
  20259. group:lang.borderbk,
  20260. icon:'borderBack',
  20261. subMenu:[
  20262. {
  20263. label:lang.setcolor,
  20264. cmdName:"interlacetable",
  20265. exec:function(){
  20266. this.execCommand("interlacetable");
  20267. }
  20268. },
  20269. {
  20270. label:lang.unsetcolor,
  20271. cmdName:"uninterlacetable",
  20272. exec:function(){
  20273. this.execCommand("uninterlacetable");
  20274. }
  20275. },
  20276. {
  20277. label:lang.setbackground,
  20278. cmdName:"settablebackground",
  20279. exec:function(){
  20280. this.execCommand("settablebackground",{repeat:true,colorList:["#bbb","#ccc"]});
  20281. }
  20282. },
  20283. {
  20284. label:lang.unsetbackground,
  20285. cmdName:"cleartablebackground",
  20286. exec:function(){
  20287. this.execCommand("cleartablebackground");
  20288. }
  20289. },
  20290. {
  20291. label:lang.redandblue,
  20292. cmdName:"settablebackground",
  20293. exec:function(){
  20294. this.execCommand("settablebackground",{repeat:true,colorList:["red","blue"]});
  20295. }
  20296. },
  20297. {
  20298. label:lang.threecolorgradient,
  20299. cmdName:"settablebackground",
  20300. exec:function(){
  20301. this.execCommand("settablebackground",{repeat:true,colorList:["#aaa","#bbb","#ccc"]});
  20302. }
  20303. }
  20304. ]
  20305. },
  20306. {
  20307. group:lang.aligntd,
  20308. icon:'aligntd',
  20309. subMenu:[
  20310. {
  20311. cmdName:'cellalignment',
  20312. value:{align:'left',vAlign:'top'}
  20313. },
  20314. {
  20315. cmdName:'cellalignment',
  20316. value:{align:'center',vAlign:'top'}
  20317. },
  20318. {
  20319. cmdName:'cellalignment',
  20320. value:{align:'right',vAlign:'top'}
  20321. },
  20322. {
  20323. cmdName:'cellalignment',
  20324. value:{align:'left',vAlign:'middle'}
  20325. },
  20326. {
  20327. cmdName:'cellalignment',
  20328. value:{align:'center',vAlign:'middle'}
  20329. },
  20330. {
  20331. cmdName:'cellalignment',
  20332. value:{align:'right',vAlign:'middle'}
  20333. },
  20334. {
  20335. cmdName:'cellalignment',
  20336. value:{align:'left',vAlign:'bottom'}
  20337. },
  20338. {
  20339. cmdName:'cellalignment',
  20340. value:{align:'center',vAlign:'bottom'}
  20341. },
  20342. {
  20343. cmdName:'cellalignment',
  20344. value:{align:'right',vAlign:'bottom'}
  20345. }
  20346. ]
  20347. },
  20348. {
  20349. group:lang.aligntable,
  20350. icon:'aligntable',
  20351. subMenu:[
  20352. {
  20353. cmdName:'tablealignment',
  20354. className: 'left',
  20355. label:lang.tableleft,
  20356. value:"left"
  20357. },
  20358. {
  20359. cmdName:'tablealignment',
  20360. className: 'center',
  20361. label:lang.tablecenter,
  20362. value:"center"
  20363. },
  20364. {
  20365. cmdName:'tablealignment',
  20366. className: 'right',
  20367. label:lang.tableright,
  20368. value:"right"
  20369. }
  20370. ]
  20371. },
  20372. '-',
  20373. {
  20374. label:lang.insertparagraphbefore,
  20375. cmdName:'insertparagraph',
  20376. value:true
  20377. },
  20378. {
  20379. label:lang.insertparagraphafter,
  20380. cmdName:'insertparagraph'
  20381. },
  20382. {
  20383. label:lang['copy'],
  20384. cmdName:'copy'
  20385. },
  20386. {
  20387. label:lang['paste'],
  20388. cmdName:'paste'
  20389. }
  20390. ];
  20391. if ( !items.length ) {
  20392. return;
  20393. }
  20394. var uiUtils = UE.ui.uiUtils;
  20395. me.addListener( 'contextmenu', function ( type, evt ) {
  20396. var offset = uiUtils.getViewportOffsetByEvent( evt );
  20397. me.fireEvent( 'beforeselectionchange' );
  20398. if ( menu ) {
  20399. menu.destroy();
  20400. }
  20401. for ( var i = 0, ti, contextItems = []; ti = items[i]; i++ ) {
  20402. var last;
  20403. (function ( item ) {
  20404. if ( item == '-' ) {
  20405. if ( (last = contextItems[contextItems.length - 1 ] ) && last !== '-' ) {
  20406. contextItems.push( '-' );
  20407. }
  20408. } else if ( item.hasOwnProperty( "group" ) ) {
  20409. for ( var j = 0, cj, subMenu = []; cj = item.subMenu[j]; j++ ) {
  20410. (function ( subItem ) {
  20411. if ( subItem == '-' ) {
  20412. if ( (last = subMenu[subMenu.length - 1 ] ) && last !== '-' ) {
  20413. subMenu.push( '-' );
  20414. }else{
  20415. subMenu.splice(subMenu.length-1);
  20416. }
  20417. } else {
  20418. if ( (me.commands[subItem.cmdName] || UE.commands[subItem.cmdName] || subItem.query) &&
  20419. (subItem.query ? subItem.query() : me.queryCommandState( subItem.cmdName )) > -1 ) {
  20420. subMenu.push( {
  20421. 'label':subItem.label || me.getLang( "contextMenu." + subItem.cmdName + (subItem.value || '') )||"",
  20422. 'className':'edui-for-' +subItem.cmdName + ( subItem.className ? ( ' edui-for-' + subItem.cmdName + '-' + subItem.className ) : '' ),
  20423. onclick:subItem.exec ? function () {
  20424. subItem.exec.call( me );
  20425. } : function () {
  20426. me.execCommand( subItem.cmdName, subItem.value );
  20427. }
  20428. } );
  20429. }
  20430. }
  20431. })( cj );
  20432. }
  20433. if ( subMenu.length ) {
  20434. function getLabel(){
  20435. switch (item.icon){
  20436. case "table":
  20437. return me.getLang( "contextMenu.table" );
  20438. case "justifyjustify":
  20439. return me.getLang( "contextMenu.paragraph" );
  20440. case "aligntd":
  20441. return me.getLang("contextMenu.aligntd");
  20442. case "aligntable":
  20443. return me.getLang("contextMenu.aligntable");
  20444. case "tablesort":
  20445. return lang.tablesort;
  20446. case "borderBack":
  20447. return lang.borderbk;
  20448. default :
  20449. return '';
  20450. }
  20451. }
  20452. contextItems.push( {
  20453. //todo 修正成自动获取方式
  20454. 'label':getLabel(),
  20455. className:'edui-for-' + item.icon,
  20456. 'subMenu':{
  20457. items:subMenu,
  20458. editor:me
  20459. }
  20460. } );
  20461. }
  20462. } else {
  20463. //有可能commmand没有加载右键不能出来,或者没有command也想能展示出来添加query方法
  20464. if ( (me.commands[item.cmdName] || UE.commands[item.cmdName] || item.query) &&
  20465. (item.query ? item.query.call(me) : me.queryCommandState( item.cmdName )) > -1 ) {
  20466. contextItems.push( {
  20467. 'label':item.label || me.getLang( "contextMenu." + item.cmdName ),
  20468. className:'edui-for-' + (item.icon ? item.icon : item.cmdName + (item.value || '')),
  20469. onclick:item.exec ? function () {
  20470. item.exec.call( me );
  20471. } : function () {
  20472. me.execCommand( item.cmdName, item.value );
  20473. }
  20474. } );
  20475. }
  20476. }
  20477. })( ti );
  20478. }
  20479. if ( contextItems[contextItems.length - 1] == '-' ) {
  20480. contextItems.pop();
  20481. }
  20482. menu = new UE.ui.Menu( {
  20483. items:contextItems,
  20484. className:"edui-contextmenu",
  20485. editor:me
  20486. } );
  20487. menu.render();
  20488. menu.showAt( offset );
  20489. me.fireEvent("aftershowcontextmenu",menu);
  20490. domUtils.preventDefault( evt );
  20491. if ( browser.ie ) {
  20492. var ieRange;
  20493. try {
  20494. ieRange = me.selection.getNative().createRange();
  20495. } catch ( e ) {
  20496. return;
  20497. }
  20498. if ( ieRange.item ) {
  20499. var range = new dom.Range( me.document );
  20500. range.selectNode( ieRange.item( 0 ) ).select( true, true );
  20501. }
  20502. }
  20503. });
  20504. // 添加复制的flash按钮
  20505. me.addListener('aftershowcontextmenu', function(type, menu) {
  20506. if (me.zeroclipboard) {
  20507. var items = menu.items;
  20508. for (var key in items) {
  20509. if (items[key].className == 'edui-for-copy') {
  20510. me.zeroclipboard.clip(items[key].getDom());
  20511. }
  20512. }
  20513. }
  20514. });
  20515. };
  20516. // js/editor/_src/plugins/shortcutmenu.js
  20517. ///import core
  20518. ///commands 弹出菜单
  20519. // commandsName popupmenu
  20520. ///commandsTitle 弹出菜单
  20521. /**
  20522. * 弹出菜单
  20523. * @function
  20524. * @name baidu.editor.plugins.popupmenu
  20525. * @author xuheng
  20526. */
  20527. UE.plugins['shortcutmenu'] = function () {
  20528. var me = this,
  20529. menu,
  20530. items = me.options.shortcutMenu || [];
  20531. if (!items.length) {
  20532. return;
  20533. }
  20534. me.addListener ('contextmenu mouseup' , function (type , e) {
  20535. var me = this,
  20536. customEvt = {
  20537. type : type ,
  20538. target : e.target || e.srcElement ,
  20539. screenX : e.screenX ,
  20540. screenY : e.screenY ,
  20541. clientX : e.clientX ,
  20542. clientY : e.clientY
  20543. };
  20544. setTimeout (function () {
  20545. var rng = me.selection.getRange ();
  20546. if (rng.collapsed === false || type == "contextmenu") {
  20547. if (!menu) {
  20548. menu = new baidu.editor.ui.ShortCutMenu ({
  20549. editor : me ,
  20550. items : items ,
  20551. theme : me.options.theme ,
  20552. className : 'edui-shortcutmenu'
  20553. });
  20554. menu.render ();
  20555. me.fireEvent ("afterrendershortcutmenu" , menu);
  20556. }
  20557. menu.show (customEvt , !!UE.plugins['contextmenu']);
  20558. }
  20559. });
  20560. if (type == 'contextmenu') {
  20561. domUtils.preventDefault (e);
  20562. if (browser.ie9below) {
  20563. var ieRange;
  20564. try {
  20565. ieRange = me.selection.getNative().createRange();
  20566. } catch (e) {
  20567. return;
  20568. }
  20569. if (ieRange.item) {
  20570. var range = new dom.Range (me.document);
  20571. range.selectNode (ieRange.item (0)).select (true , true);
  20572. }
  20573. }
  20574. }
  20575. });
  20576. me.addListener ('keydown' , function (type) {
  20577. if (type == "keydown") {
  20578. menu && !menu.isHidden && menu.hide ();
  20579. }
  20580. });
  20581. };
  20582. // js/editor/_src/plugins/basestyle.js
  20583. /**
  20584. * B、I、sub、super命令支持
  20585. * @file
  20586. * @since 1.2.6.1
  20587. */
  20588. UE.plugins['basestyle'] = function(){
  20589. /**
  20590. * 字体加粗
  20591. * @command bold
  20592. * @param { String } cmd 命令字符串
  20593. * @remind 对已加粗的文本内容执行该命令, 将取消加粗
  20594. * @method execCommand
  20595. * @example
  20596. * ```javascript
  20597. * //editor是编辑器实例
  20598. * //对当前选中的文本内容执行加粗操作
  20599. * //第一次执行, 文本内容加粗
  20600. * editor.execCommand( 'bold' );
  20601. *
  20602. * //第二次执行, 文本内容取消加粗
  20603. * editor.execCommand( 'bold' );
  20604. * ```
  20605. */
  20606. /**
  20607. * 字体倾斜
  20608. * @command italic
  20609. * @method execCommand
  20610. * @param { String } cmd 命令字符串
  20611. * @remind 对已倾斜的文本内容执行该命令, 将取消倾斜
  20612. * @example
  20613. * ```javascript
  20614. * //editor是编辑器实例
  20615. * //对当前选中的文本内容执行斜体操作
  20616. * //第一次操作, 文本内容将变成斜体
  20617. * editor.execCommand( 'italic' );
  20618. *
  20619. * //再次对同一文本内容执行, 则文本内容将恢复正常
  20620. * editor.execCommand( 'italic' );
  20621. * ```
  20622. */
  20623. /**
  20624. * 下标文本,与“superscript”命令互斥
  20625. * @command subscript
  20626. * @method execCommand
  20627. * @remind 把选中的文本内容切换成下标文本, 如果当前选中的文本已经是下标, 则该操作会把文本内容还原成正常文本
  20628. * @param { String } cmd 命令字符串
  20629. * @example
  20630. * ```javascript
  20631. * //editor是编辑器实例
  20632. * //对当前选中的文本内容执行下标操作
  20633. * //第一次操作, 文本内容将变成下标文本
  20634. * editor.execCommand( 'subscript' );
  20635. *
  20636. * //再次对同一文本内容执行, 则文本内容将恢复正常
  20637. * editor.execCommand( 'subscript' );
  20638. * ```
  20639. */
  20640. /**
  20641. * 上标文本,与“subscript”命令互斥
  20642. * @command superscript
  20643. * @method execCommand
  20644. * @remind 把选中的文本内容切换成上标文本, 如果当前选中的文本已经是上标, 则该操作会把文本内容还原成正常文本
  20645. * @param { String } cmd 命令字符串
  20646. * @example
  20647. * ```javascript
  20648. * //editor是编辑器实例
  20649. * //对当前选中的文本内容执行上标操作
  20650. * //第一次操作, 文本内容将变成上标文本
  20651. * editor.execCommand( 'superscript' );
  20652. *
  20653. * //再次对同一文本内容执行, 则文本内容将恢复正常
  20654. * editor.execCommand( 'superscript' );
  20655. * ```
  20656. */
  20657. var basestyles = {
  20658. 'bold':['strong','b'],
  20659. 'italic':['em','i'],
  20660. 'subscript':['sub'],
  20661. 'superscript':['sup']
  20662. },
  20663. getObj = function(editor,tagNames){
  20664. return domUtils.filterNodeList(editor.selection.getStartElementPath(),tagNames);
  20665. },
  20666. me = this;
  20667. //添加快捷键
  20668. me.addshortcutkey({
  20669. "Bold" : "ctrl+66",//^B
  20670. "Italic" : "ctrl+73", //^I
  20671. "Underline" : "ctrl+85"//^U
  20672. });
  20673. me.addInputRule(function(root){
  20674. utils.each(root.getNodesByTagName('b i'),function(node){
  20675. switch (node.tagName){
  20676. case 'b':
  20677. node.tagName = 'strong';
  20678. break;
  20679. case 'i':
  20680. node.tagName = 'em';
  20681. }
  20682. });
  20683. });
  20684. for ( var style in basestyles ) {
  20685. (function( cmd, tagNames ) {
  20686. me.commands[cmd] = {
  20687. execCommand : function( cmdName ) {
  20688. var range = me.selection.getRange(),obj = getObj(this,tagNames);
  20689. if ( range.collapsed ) {
  20690. if ( obj ) {
  20691. var tmpText = me.document.createTextNode('');
  20692. range.insertNode( tmpText ).removeInlineStyle( tagNames );
  20693. range.setStartBefore(tmpText);
  20694. domUtils.remove(tmpText);
  20695. } else {
  20696. var tmpNode = range.document.createElement( tagNames[0] );
  20697. if(cmdName == 'superscript' || cmdName == 'subscript'){
  20698. tmpText = me.document.createTextNode('');
  20699. range.insertNode(tmpText)
  20700. .removeInlineStyle(['sub','sup'])
  20701. .setStartBefore(tmpText)
  20702. .collapse(true);
  20703. }
  20704. range.insertNode( tmpNode ).setStart( tmpNode, 0 );
  20705. }
  20706. range.collapse( true );
  20707. } else {
  20708. if(cmdName == 'superscript' || cmdName == 'subscript'){
  20709. if(!obj || obj.tagName.toLowerCase() != cmdName){
  20710. range.removeInlineStyle(['sub','sup']);
  20711. }
  20712. }
  20713. obj ? range.removeInlineStyle( tagNames ) : range.applyInlineStyle( tagNames[0] );
  20714. }
  20715. range.select();
  20716. },
  20717. queryCommandState : function() {
  20718. return getObj(this,tagNames) ? 1 : 0;
  20719. }
  20720. };
  20721. })( style, basestyles[style] );
  20722. }
  20723. };
  20724. // js/editor/_src/plugins/elementpath.js
  20725. /**
  20726. * 选取路径命令
  20727. * @file
  20728. */
  20729. UE.plugins['elementpath'] = function(){
  20730. var currentLevel,
  20731. tagNames,
  20732. me = this;
  20733. me.setOpt('elementPathEnabled',true);
  20734. if(!me.options.elementPathEnabled){
  20735. return;
  20736. }
  20737. me.commands['elementpath'] = {
  20738. execCommand : function( cmdName, level ) {
  20739. var start = tagNames[level],
  20740. range = me.selection.getRange();
  20741. currentLevel = level*1;
  20742. range.selectNode(start).select();
  20743. },
  20744. queryCommandValue : function() {
  20745. //产生一个副本,不能修改原来的startElementPath;
  20746. var parents = [].concat(this.selection.getStartElementPath()).reverse(),
  20747. names = [];
  20748. tagNames = parents;
  20749. for(var i=0,ci;ci=parents[i];i++){
  20750. if(ci.nodeType == 3) {
  20751. continue;
  20752. }
  20753. var name = ci.tagName.toLowerCase();
  20754. if(name == 'img' && ci.getAttribute('anchorname')){
  20755. name = 'anchor';
  20756. }
  20757. names[i] = name;
  20758. if(currentLevel == i){
  20759. currentLevel = -1;
  20760. break;
  20761. }
  20762. }
  20763. return names;
  20764. }
  20765. };
  20766. };
  20767. // js/editor/_src/plugins/formatmatch.js
  20768. /**
  20769. * 格式刷,只格式inline的
  20770. * @file
  20771. * @since 1.2.6.1
  20772. */
  20773. /**
  20774. * 格式刷
  20775. * @command formatmatch
  20776. * @method execCommand
  20777. * @remind 该操作不能复制段落格式
  20778. * @param { String } cmd 命令字符串
  20779. * @example
  20780. * ```javascript
  20781. * //editor是编辑器实例
  20782. * //获取格式刷
  20783. * editor.execCommand( 'formatmatch' );
  20784. * ```
  20785. */
  20786. UE.plugins['formatmatch'] = function(){
  20787. var me = this,
  20788. list = [],img,
  20789. flag = 0;
  20790. me.addListener('reset',function(){
  20791. list = [];
  20792. flag = 0;
  20793. });
  20794. function addList(type,evt){
  20795. if(browser.webkit){
  20796. var target = evt.target.tagName == 'IMG' ? evt.target : null;
  20797. }
  20798. function addFormat(range){
  20799. if(text){
  20800. range.selectNode(text);
  20801. }
  20802. return range.applyInlineStyle(list[list.length-1].tagName,null,list);
  20803. }
  20804. me.undoManger && me.undoManger.save();
  20805. var range = me.selection.getRange(),
  20806. imgT = target || range.getClosedNode();
  20807. if(img && imgT && imgT.tagName == 'IMG'){
  20808. //trace:964
  20809. imgT.style.cssText += ';float:' + (img.style.cssFloat || img.style.styleFloat ||'none') + ';display:' + (img.style.display||'inline');
  20810. img = null;
  20811. }else{
  20812. if(!img){
  20813. var collapsed = range.collapsed;
  20814. if(collapsed){
  20815. var text = me.document.createTextNode('match');
  20816. range.insertNode(text).select();
  20817. }
  20818. me.__hasEnterExecCommand = true;
  20819. //不能把block上的属性干掉
  20820. //trace:1553
  20821. var removeFormatAttributes = me.options.removeFormatAttributes;
  20822. me.options.removeFormatAttributes = '';
  20823. me.execCommand('removeformat');
  20824. me.options.removeFormatAttributes = removeFormatAttributes;
  20825. me.__hasEnterExecCommand = false;
  20826. //trace:969
  20827. range = me.selection.getRange();
  20828. if(list.length){
  20829. addFormat(range);
  20830. }
  20831. if(text){
  20832. range.setStartBefore(text).collapse(true);
  20833. }
  20834. range.select();
  20835. text && domUtils.remove(text);
  20836. }
  20837. }
  20838. me.undoManger && me.undoManger.save();
  20839. me.removeListener('mouseup',addList);
  20840. flag = 0;
  20841. }
  20842. me.commands['formatmatch'] = {
  20843. execCommand : function( cmdName ) {
  20844. if(flag){
  20845. flag = 0;
  20846. list = [];
  20847. me.removeListener('mouseup',addList);
  20848. return;
  20849. }
  20850. var range = me.selection.getRange();
  20851. img = range.getClosedNode();
  20852. if(!img || img.tagName != 'IMG'){
  20853. range.collapse(true).shrinkBoundary();
  20854. var start = range.startContainer;
  20855. list = domUtils.findParents(start,true,function(node){
  20856. return !domUtils.isBlockElm(node) && node.nodeType == 1;
  20857. });
  20858. //a不能加入格式刷, 并且克隆节点
  20859. for(var i=0,ci;ci=list[i];i++){
  20860. if(ci.tagName == 'A'){
  20861. list.splice(i,1);
  20862. break;
  20863. }
  20864. }
  20865. }
  20866. me.addListener('mouseup',addList);
  20867. flag = 1;
  20868. },
  20869. queryCommandState : function() {
  20870. return flag;
  20871. },
  20872. notNeedUndo : 1
  20873. };
  20874. };
  20875. // js/editor/_src/plugins/searchreplace.js
  20876. ///import core
  20877. ///commands 查找替换
  20878. ///commandsName SearchReplace
  20879. ///commandsTitle 查询替换
  20880. ///commandsDialog dialogs\searchreplace
  20881. /**
  20882. * @description 查找替换
  20883. * @author zhanyi
  20884. */
  20885. UE.plugin.register('searchreplace',function(){
  20886. var me = this;
  20887. var _blockElm = {'table':1,'tbody':1,'tr':1,'ol':1,'ul':1};
  20888. function findTextInString(textContent,opt,currentIndex){
  20889. var str = opt.searchStr;
  20890. if(opt.dir == -1){
  20891. textContent = textContent.split('').reverse().join('');
  20892. str = str.split('').reverse().join('');
  20893. currentIndex = textContent.length - currentIndex;
  20894. }
  20895. var reg = new RegExp(str,'g' + (opt.casesensitive ? '' : 'i')),match;
  20896. while(match = reg.exec(textContent)){
  20897. if(match.index >= currentIndex){
  20898. return opt.dir == -1 ? textContent.length - match.index - opt.searchStr.length : match.index;
  20899. }
  20900. }
  20901. return -1
  20902. }
  20903. function findTextBlockElm(node,currentIndex,opt){
  20904. var textContent,index,methodName = opt.all || opt.dir == 1 ? 'getNextDomNode' : 'getPreDomNode';
  20905. if(domUtils.isBody(node)){
  20906. node = node.firstChild;
  20907. }
  20908. var first = 1;
  20909. while(node){
  20910. textContent = node.nodeType == 3 ? node.nodeValue : node[browser.ie ? 'innerText' : 'textContent'];
  20911. index = findTextInString(textContent,opt,currentIndex );
  20912. first = 0;
  20913. if(index!=-1){
  20914. return {
  20915. 'node':node,
  20916. 'index':index
  20917. }
  20918. }
  20919. node = domUtils[methodName](node);
  20920. while(node && _blockElm[node.nodeName.toLowerCase()]){
  20921. node = domUtils[methodName](node,true);
  20922. }
  20923. if(node){
  20924. currentIndex = opt.dir == -1 ? (node.nodeType == 3 ? node.nodeValue : node[browser.ie ? 'innerText' : 'textContent']).length : 0;
  20925. }
  20926. }
  20927. }
  20928. function findNTextInBlockElm(node,index,str){
  20929. var currentIndex = 0,
  20930. currentNode = node.firstChild,
  20931. currentNodeLength = 0,
  20932. result;
  20933. while(currentNode){
  20934. if(currentNode.nodeType == 3){
  20935. currentNodeLength = currentNode.nodeValue.replace(/(^[\t\r\n]+)|([\t\r\n]+$)/,'').length;
  20936. currentIndex += currentNodeLength;
  20937. if(currentIndex >= index){
  20938. return {
  20939. 'node':currentNode,
  20940. 'index': currentNodeLength - (currentIndex - index)
  20941. }
  20942. }
  20943. }else if(!dtd.$empty[currentNode.tagName]){
  20944. currentNodeLength = currentNode[browser.ie ? 'innerText' : 'textContent'].replace(/(^[\t\r\n]+)|([\t\r\n]+$)/,'').length
  20945. currentIndex += currentNodeLength;
  20946. if(currentIndex >= index){
  20947. result = findNTextInBlockElm(currentNode,currentNodeLength - (currentIndex - index),str);
  20948. if(result){
  20949. return result;
  20950. }
  20951. }
  20952. }
  20953. currentNode = domUtils.getNextDomNode(currentNode);
  20954. }
  20955. }
  20956. function searchReplace(me,opt){
  20957. var rng = me.selection.getRange(),
  20958. startBlockNode,
  20959. searchStr = opt.searchStr,
  20960. span = me.document.createElement('span');
  20961. span.innerHTML = '$$ueditor_searchreplace_key$$';
  20962. rng.shrinkBoundary(true);
  20963. //判断是不是第一次选中
  20964. if(!rng.collapsed){
  20965. rng.select();
  20966. var rngText = me.selection.getText();
  20967. if(new RegExp('^' + opt.searchStr + '$',(opt.casesensitive ? '' : 'i')).test(rngText)){
  20968. if(opt.replaceStr != undefined){
  20969. replaceText(rng,opt.replaceStr);
  20970. rng.select();
  20971. return true;
  20972. }else{
  20973. rng.collapse(opt.dir == -1)
  20974. }
  20975. }
  20976. }
  20977. rng.insertNode(span);
  20978. rng.enlargeToBlockElm(true);
  20979. startBlockNode = rng.startContainer;
  20980. var currentIndex = startBlockNode[browser.ie ? 'innerText' : 'textContent'].indexOf('$$ueditor_searchreplace_key$$');
  20981. rng.setStartBefore(span);
  20982. domUtils.remove(span);
  20983. var result = findTextBlockElm(startBlockNode,currentIndex,opt);
  20984. if(result){
  20985. var rngStart = findNTextInBlockElm(result.node,result.index,searchStr);
  20986. var rngEnd = findNTextInBlockElm(result.node,result.index + searchStr.length,searchStr);
  20987. rng.setStart(rngStart.node,rngStart.index).setEnd(rngEnd.node,rngEnd.index);
  20988. if(opt.replaceStr !== undefined){
  20989. replaceText(rng,opt.replaceStr)
  20990. }
  20991. rng.select();
  20992. return true;
  20993. }else{
  20994. rng.setCursor()
  20995. }
  20996. }
  20997. function replaceText(rng,str){
  20998. str = me.document.createTextNode(str);
  20999. rng.deleteContents().insertNode(str);
  21000. }
  21001. return {
  21002. commands:{
  21003. 'searchreplace':{
  21004. execCommand:function(cmdName,opt){
  21005. utils.extend(opt,{
  21006. all : false,
  21007. casesensitive : false,
  21008. dir : 1
  21009. },true);
  21010. var num = 0;
  21011. if(opt.all){
  21012. var rng = me.selection.getRange(),
  21013. first = me.body.firstChild;
  21014. if(first && first.nodeType == 1){
  21015. rng.setStart(first,0);
  21016. rng.shrinkBoundary(true);
  21017. }else if(first.nodeType == 3){
  21018. rng.setStartBefore(first)
  21019. }
  21020. rng.collapse(true).select(true);
  21021. if(opt.replaceStr !== undefined){
  21022. me.fireEvent('saveScene');
  21023. }
  21024. while(searchReplace(this,opt)){
  21025. num++;
  21026. }
  21027. if(num){
  21028. me.fireEvent('saveScene');
  21029. }
  21030. }else{
  21031. if(opt.replaceStr !== undefined){
  21032. me.fireEvent('saveScene');
  21033. }
  21034. if(searchReplace(this,opt)){
  21035. num++
  21036. }
  21037. if(num){
  21038. me.fireEvent('saveScene');
  21039. }
  21040. }
  21041. return num;
  21042. },
  21043. notNeedUndo:1
  21044. }
  21045. }
  21046. }
  21047. });
  21048. // js/editor/_src/plugins/customstyle.js
  21049. /**
  21050. * 自定义样式
  21051. * @file
  21052. * @since 1.2.6.1
  21053. */
  21054. /**
  21055. * 根据config配置文件里“customstyle”选项的值对匹配的标签执行样式替换。
  21056. * @command customstyle
  21057. * @method execCommand
  21058. * @param { String } cmd 命令字符串
  21059. * @example
  21060. * ```javascript
  21061. * editor.execCommand( 'customstyle' );
  21062. * ```
  21063. */
  21064. UE.plugins['customstyle'] = function() {
  21065. var me = this;
  21066. me.setOpt({ 'customstyle':[
  21067. {tag:'h1',name:'tc', style:'font-size:32px;font-weight:bold;border-bottom:#ccc 2px solid;padding:0 4px 0 0;text-align:center;margin:0 0 20px 0;'},
  21068. {tag:'h1',name:'tl', style:'font-size:32px;font-weight:bold;border-bottom:#ccc 2px solid;padding:0 4px 0 0;text-align:left;margin:0 0 10px 0;'},
  21069. {tag:'span',name:'im', style:'font-size:16px;font-style:italic;font-weight:bold;line-height:18px;'},
  21070. {tag:'span',name:'hi', style:'font-size:16px;font-style:italic;font-weight:bold;color:rgb(51, 153, 204);line-height:18px;'}
  21071. ]});
  21072. me.commands['customstyle'] = {
  21073. execCommand : function(cmdName, obj) {
  21074. var me = this,
  21075. tagName = obj.tag,
  21076. node = domUtils.findParent(me.selection.getStart(), function(node) {
  21077. return node.getAttribute('label');
  21078. }, true),
  21079. range,bk,tmpObj = {};
  21080. for (var p in obj) {
  21081. if(obj[p]!==undefined)
  21082. tmpObj[p] = obj[p];
  21083. }
  21084. delete tmpObj.tag;
  21085. if (node && node.getAttribute('label') == obj.label) {
  21086. range = this.selection.getRange();
  21087. bk = range.createBookmark();
  21088. if (range.collapsed) {
  21089. //trace:1732 删掉自定义标签,要有p来回填站位
  21090. if(dtd.$block[node.tagName]){
  21091. var fillNode = me.document.createElement('p');
  21092. domUtils.moveChild(node, fillNode);
  21093. node.parentNode.insertBefore(fillNode, node);
  21094. domUtils.remove(node);
  21095. }else{
  21096. domUtils.remove(node,true);
  21097. }
  21098. } else {
  21099. var common = domUtils.getCommonAncestor(bk.start, bk.end),
  21100. nodes = domUtils.getElementsByTagName(common, tagName);
  21101. if(new RegExp(tagName,'i').test(common.tagName)){
  21102. nodes.push(common);
  21103. }
  21104. for (var i = 0,ni; ni = nodes[i++];) {
  21105. if (ni.getAttribute('label') == obj.label) {
  21106. var ps = domUtils.getPosition(ni, bk.start),pe = domUtils.getPosition(ni, bk.end);
  21107. if ((ps & domUtils.POSITION_FOLLOWING || ps & domUtils.POSITION_CONTAINS)
  21108. &&
  21109. (pe & domUtils.POSITION_PRECEDING || pe & domUtils.POSITION_CONTAINS)
  21110. )
  21111. if (dtd.$block[tagName]) {
  21112. var fillNode = me.document.createElement('p');
  21113. domUtils.moveChild(ni, fillNode);
  21114. ni.parentNode.insertBefore(fillNode, ni);
  21115. }
  21116. domUtils.remove(ni, true);
  21117. }
  21118. }
  21119. node = domUtils.findParent(common, function(node) {
  21120. return node.getAttribute('label') == obj.label;
  21121. }, true);
  21122. if (node) {
  21123. domUtils.remove(node, true);
  21124. }
  21125. }
  21126. range.moveToBookmark(bk).select();
  21127. } else {
  21128. if (dtd.$block[tagName]) {
  21129. this.execCommand('paragraph', tagName, tmpObj,'customstyle');
  21130. range = me.selection.getRange();
  21131. if (!range.collapsed) {
  21132. range.collapse();
  21133. node = domUtils.findParent(me.selection.getStart(), function(node) {
  21134. return node.getAttribute('label') == obj.label;
  21135. }, true);
  21136. var pNode = me.document.createElement('p');
  21137. domUtils.insertAfter(node, pNode);
  21138. domUtils.fillNode(me.document, pNode);
  21139. range.setStart(pNode, 0).setCursor();
  21140. }
  21141. } else {
  21142. range = me.selection.getRange();
  21143. if (range.collapsed) {
  21144. node = me.document.createElement(tagName);
  21145. domUtils.setAttributes(node, tmpObj);
  21146. range.insertNode(node).setStart(node, 0).setCursor();
  21147. return;
  21148. }
  21149. bk = range.createBookmark();
  21150. range.applyInlineStyle(tagName, tmpObj).moveToBookmark(bk).select();
  21151. }
  21152. }
  21153. },
  21154. queryCommandValue : function() {
  21155. var parent = domUtils.filterNodeList(
  21156. this.selection.getStartElementPath(),
  21157. function(node){return node.getAttribute('label')}
  21158. );
  21159. return parent ? parent.getAttribute('label') : '';
  21160. }
  21161. };
  21162. //当去掉customstyle是,如果是块元素,用p代替
  21163. me.addListener('keyup', function(type, evt) {
  21164. var keyCode = evt.keyCode || evt.which;
  21165. if (keyCode == 32 || keyCode == 13) {
  21166. var range = me.selection.getRange();
  21167. if (range.collapsed) {
  21168. var node = domUtils.findParent(me.selection.getStart(), function(node) {
  21169. return node.getAttribute('label');
  21170. }, true);
  21171. if (node && dtd.$block[node.tagName] && domUtils.isEmptyNode(node)) {
  21172. var p = me.document.createElement('p');
  21173. domUtils.insertAfter(node, p);
  21174. domUtils.fillNode(me.document, p);
  21175. domUtils.remove(node);
  21176. range.setStart(p, 0).setCursor();
  21177. }
  21178. }
  21179. }
  21180. });
  21181. };
  21182. // js/editor/_src/plugins/catchremoteimage.js
  21183. ///import core
  21184. ///commands 远程图片抓取
  21185. ///commandsName catchRemoteImage,catchremoteimageenable
  21186. ///commandsTitle 远程图片抓取
  21187. /**
  21188. * 远程图片抓取,当开启本插件时所有不符合本地域名的图片都将被抓取成为本地服务器上的图片
  21189. */
  21190. UE.plugins['catchremoteimage'] = function () {
  21191. var me = this,
  21192. ajax = UE.ajax;
  21193. /* 设置默认值 */
  21194. if (me.options.catchRemoteImageEnable === false) return;
  21195. me.setOpt({
  21196. catchRemoteImageEnable: false
  21197. });
  21198. me.addListener("afterpaste", function () {
  21199. me.fireEvent("catchRemoteImage");
  21200. });
  21201. me.addListener("catchRemoteImage", function () {
  21202. var catcherLocalDomain = me.getOpt('catcherLocalDomain'),
  21203. catcherActionUrl = me.getActionUrl(me.getOpt('catcherActionName')),
  21204. catcherUrlPrefix = me.getOpt('catcherUrlPrefix'),
  21205. catcherFieldName = me.getOpt('catcherFieldName');
  21206. var remoteImages = [],
  21207. imgs = domUtils.getElementsByTagName(me.document, "img"),
  21208. test = function (src, urls) {
  21209. if (src.indexOf(location.host) != -1 || /(^\.)|(^\/)/.test(src)) {
  21210. return true;
  21211. }
  21212. if (urls) {
  21213. for (var j = 0, url; url = urls[j++];) {
  21214. if (src.indexOf(url) !== -1) {
  21215. return true;
  21216. }
  21217. }
  21218. }
  21219. return false;
  21220. };
  21221. for (var i = 0, ci; ci = imgs[i++];) {
  21222. if (ci.getAttribute("word_img")) {
  21223. continue;
  21224. }
  21225. var src = ci.getAttribute("_src") || ci.src || "";
  21226. if (/^(https?|ftp):/i.test(src) && !test(src, catcherLocalDomain)) {
  21227. remoteImages.push(src);
  21228. }
  21229. }
  21230. if (remoteImages.length) {
  21231. catchremoteimage(remoteImages, {
  21232. //成功抓取
  21233. success: function (r) {
  21234. try {
  21235. var info = r.state !== undefined ? r:eval("(" + r.responseText + ")");
  21236. } catch (e) {
  21237. return;
  21238. }
  21239. /* 获取源路径和新路径 */
  21240. var i, j, ci, cj, oldSrc, newSrc, list = info.list;
  21241. for (i = 0; ci = imgs[i++];) {
  21242. oldSrc = ci.getAttribute("_src") || ci.src || "";
  21243. for (j = 0; cj = list[j++];) {
  21244. if (oldSrc == cj.source && cj.state == "SUCCESS") { //抓取失败时不做替换处理
  21245. newSrc = catcherUrlPrefix + cj.url;
  21246. domUtils.setAttributes(ci, {
  21247. "src": newSrc,
  21248. "_src": newSrc
  21249. });
  21250. break;
  21251. }
  21252. }
  21253. }
  21254. me.fireEvent('catchremotesuccess')
  21255. },
  21256. //回调失败,本次请求超时
  21257. error: function () {
  21258. me.fireEvent("catchremoteerror");
  21259. }
  21260. });
  21261. }
  21262. function catchremoteimage(imgs, callbacks) {
  21263. var params = utils.serializeParam(me.queryCommandValue('serverparam')) || '',
  21264. url = utils.formatUrl(catcherActionUrl + (catcherActionUrl.indexOf('?') == -1 ? '?':'&') + params),
  21265. isJsonp = utils.isCrossDomainUrl(url),
  21266. opt = {
  21267. 'method': 'POST',
  21268. 'dataType': isJsonp ? 'jsonp':'',
  21269. 'timeout': 60000, //单位:毫秒,回调请求超时设置。目标用户如果网速不是很快的话此处建议设置一个较大的数值
  21270. 'onsuccess': callbacks["success"],
  21271. 'onerror': callbacks["error"]
  21272. };
  21273. opt[catcherFieldName] = imgs;
  21274. ajax.request(url, opt);
  21275. }
  21276. });
  21277. };
  21278. // js/editor/_src/plugins/snapscreen.js
  21279. /**
  21280. * 截屏插件,为UEditor提供插入支持
  21281. * @file
  21282. * @since 1.4.2
  21283. */
  21284. UE.plugin.register('snapscreen', function (){
  21285. var me = this;
  21286. var snapplugin;
  21287. function getLocation(url){
  21288. var search,
  21289. a = document.createElement('a'),
  21290. params = utils.serializeParam(me.queryCommandValue('serverparam')) || '';
  21291. a.href = url;
  21292. if (browser.ie) {
  21293. a.href = a.href;
  21294. }
  21295. search = a.search;
  21296. if (params) {
  21297. search = search + (search.indexOf('?') == -1 ? '?':'&')+ params;
  21298. search = search.replace(/[&]+/ig, '&');
  21299. }
  21300. return {
  21301. 'port': a.port,
  21302. 'hostname': a.hostname,
  21303. 'path': a.pathname + search || + a.hash
  21304. }
  21305. }
  21306. return {
  21307. commands:{
  21308. /**
  21309. * 字体背景颜色
  21310. * @command snapscreen
  21311. * @method execCommand
  21312. * @param { String } cmd 命令字符串
  21313. * @example
  21314. * ```javascript
  21315. * editor.execCommand('snapscreen');
  21316. * ```
  21317. */
  21318. 'snapscreen':{
  21319. execCommand:function (cmd) {
  21320. var url, local, res;
  21321. var lang = me.getLang("snapScreen_plugin");
  21322. if(!snapplugin){
  21323. var container = me.container;
  21324. var doc = me.container.ownerDocument || me.container.document;
  21325. snapplugin = doc.createElement("object");
  21326. try{snapplugin.type = "application/x-pluginbaidusnap";}catch(e){
  21327. return;
  21328. }
  21329. snapplugin.style.cssText = "position:absolute;left:-9999px;width:0;height:0;";
  21330. snapplugin.setAttribute("width","0");
  21331. snapplugin.setAttribute("height","0");
  21332. container.appendChild(snapplugin);
  21333. }
  21334. function onSuccess(rs){
  21335. try{
  21336. rs = eval("("+ rs +")");
  21337. if(rs.state == 'SUCCESS'){
  21338. var opt = me.options;
  21339. me.execCommand('insertimage', {
  21340. src: opt.snapscreenUrlPrefix + rs.url,
  21341. _src: opt.snapscreenUrlPrefix + rs.url,
  21342. alt: rs.title || '',
  21343. floatStyle: opt.snapscreenImgAlign
  21344. });
  21345. } else {
  21346. alert(rs.state);
  21347. }
  21348. }catch(e){
  21349. alert(lang.callBackErrorMsg);
  21350. }
  21351. }
  21352. url = me.getActionUrl(me.getOpt('snapscreenActionName'));
  21353. local = getLocation(url);
  21354. setTimeout(function () {
  21355. try{
  21356. res =snapplugin.saveSnapshot(local.hostname, local.path, local.port);
  21357. }catch(e){
  21358. me.ui._dialogs['snapscreenDialog'].open();
  21359. return;
  21360. }
  21361. onSuccess(res);
  21362. }, 50);
  21363. },
  21364. queryCommandState: function(){
  21365. return (navigator.userAgent.indexOf("Windows",0) != -1) ? 0:-1;
  21366. }
  21367. }
  21368. }
  21369. }
  21370. });
  21371. // js/editor/_src/plugins/insertparagraph.js
  21372. /**
  21373. * 插入段落
  21374. * @file
  21375. * @since 1.2.6.1
  21376. */
  21377. /**
  21378. * 插入段落
  21379. * @command insertparagraph
  21380. * @method execCommand
  21381. * @param { String } cmd 命令字符串
  21382. * @example
  21383. * ```javascript
  21384. * //editor是编辑器实例
  21385. * editor.execCommand( 'insertparagraph' );
  21386. * ```
  21387. */
  21388. UE.commands['insertparagraph'] = {
  21389. execCommand : function( cmdName,front) {
  21390. var me = this,
  21391. range = me.selection.getRange(),
  21392. start = range.startContainer,tmpNode;
  21393. while(start ){
  21394. if(domUtils.isBody(start)){
  21395. break;
  21396. }
  21397. tmpNode = start;
  21398. start = start.parentNode;
  21399. }
  21400. if(tmpNode){
  21401. var p = me.document.createElement('p');
  21402. if(front){
  21403. tmpNode.parentNode.insertBefore(p,tmpNode)
  21404. }else{
  21405. tmpNode.parentNode.insertBefore(p,tmpNode.nextSibling)
  21406. }
  21407. domUtils.fillNode(me.document,p);
  21408. range.setStart(p,0).setCursor(false,true);
  21409. }
  21410. }
  21411. };
  21412. // js/editor/_src/plugins/webapp.js
  21413. /**
  21414. * 百度应用
  21415. * @file
  21416. * @since 1.2.6.1
  21417. */
  21418. /**
  21419. * 插入百度应用
  21420. * @command webapp
  21421. * @method execCommand
  21422. * @remind 需要百度APPKey
  21423. * @remind 百度应用主页: <a href="http://app.baidu.com/" target="_blank">http://app.baidu.com/</a>
  21424. * @param { Object } appOptions 应用所需的参数项, 支持的key有: title=>应用标题, width=>应用容器宽度,
  21425. * height=>应用容器高度,logo=>应用logo,url=>应用地址
  21426. * @example
  21427. * ```javascript
  21428. * //editor是编辑器实例
  21429. * //在编辑器里插入一个“植物大战僵尸”的APP
  21430. * editor.execCommand( 'webapp' , {
  21431. * title: '植物大战僵尸',
  21432. * width: 560,
  21433. * height: 465,
  21434. * logo: '应用展示的图片',
  21435. * url: '百度应用的地址'
  21436. * } );
  21437. * ```
  21438. */
  21439. //UE.plugins['webapp'] = function () {
  21440. // var me = this;
  21441. // function createInsertStr( obj, toIframe, addParagraph ) {
  21442. // return !toIframe ?
  21443. // (addParagraph ? '<p>' : '') + '<img title="'+obj.title+'" width="' + obj.width + '" height="' + obj.height + '"' +
  21444. // ' 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 + '" />' +
  21445. // (addParagraph ? '</p>' : '')
  21446. // :
  21447. // '<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>';
  21448. // }
  21449. //
  21450. // function switchImgAndIframe( img2frame ) {
  21451. // var tmpdiv,
  21452. // nodes = domUtils.getElementsByTagName( me.document, !img2frame ? "iframe" : "img" );
  21453. // for ( var i = 0, node; node = nodes[i++]; ) {
  21454. // if ( node.className != "edui-faked-webapp" ){
  21455. // continue;
  21456. // }
  21457. // tmpdiv = me.document.createElement( "div" );
  21458. // 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 );
  21459. // node.parentNode.replaceChild( tmpdiv.firstChild, node );
  21460. // }
  21461. // }
  21462. //
  21463. // me.addListener( "beforegetcontent", function () {
  21464. // switchImgAndIframe( true );
  21465. // } );
  21466. // me.addListener( 'aftersetcontent', function () {
  21467. // switchImgAndIframe( false );
  21468. // } );
  21469. // me.addListener( 'aftergetcontent', function ( cmdName ) {
  21470. // if ( cmdName == 'aftergetcontent' && me.queryCommandState( 'source' ) ){
  21471. // return;
  21472. // }
  21473. // switchImgAndIframe( false );
  21474. // } );
  21475. //
  21476. // me.commands['webapp'] = {
  21477. // execCommand:function ( cmd, obj ) {
  21478. // me.execCommand( "inserthtml", createInsertStr( obj, false,true ) );
  21479. // }
  21480. // };
  21481. //};
  21482. UE.plugin.register('webapp', function (){
  21483. var me = this;
  21484. function createInsertStr(obj,toEmbed){
  21485. return !toEmbed ?
  21486. '<img title="'+obj.title+'" width="' + obj.width + '" height="' + obj.height + '"' +
  21487. ' src="' + me.options.UEDITOR_HOME_URL + 'themes/default/images/spacer.gif" _logo_url="'+obj.logo+'" style="background:url(' + obj.logo
  21488. +') no-repeat center center; border:1px solid gray;" class="edui-faked-webapp" _url="' + obj.url + '" ' +
  21489. (obj.align && !obj.cssfloat? 'align="' + obj.align + '"' : '') +
  21490. (obj.cssfloat ? 'style="float:' + obj.cssfloat + '"' : '') +
  21491. '/>'
  21492. :
  21493. '<iframe class="edui-faked-webapp" title="'+obj.title+'" ' +
  21494. (obj.align && !obj.cssfloat? 'align="' + obj.align + '"' : '') +
  21495. (obj.cssfloat ? 'style="float:' + obj.cssfloat + '"' : '') +
  21496. 'width="' + obj.width + '" height="' + obj.height + '" scrolling="no" frameborder="0" src="' + obj.url + '" logo_url = "'+obj.logo+'"></iframe>'
  21497. }
  21498. return {
  21499. outputRule: function(root){
  21500. utils.each(root.getNodesByTagName('img'),function(node){
  21501. var html;
  21502. if(node.getAttr('class') == 'edui-faked-webapp'){
  21503. html = createInsertStr({
  21504. title:node.getAttr('title'),
  21505. 'width':node.getAttr('width'),
  21506. 'height':node.getAttr('height'),
  21507. 'align':node.getAttr('align'),
  21508. 'cssfloat':node.getStyle('float'),
  21509. 'url':node.getAttr("_url"),
  21510. 'logo':node.getAttr('_logo_url')
  21511. },true);
  21512. var embed = UE.uNode.createElement(html);
  21513. node.parentNode.replaceChild(embed,node);
  21514. }
  21515. })
  21516. },
  21517. inputRule:function(root){
  21518. utils.each(root.getNodesByTagName('iframe'),function(node){
  21519. if(node.getAttr('class') == 'edui-faked-webapp'){
  21520. var img = UE.uNode.createElement(createInsertStr({
  21521. title:node.getAttr('title'),
  21522. 'width':node.getAttr('width'),
  21523. 'height':node.getAttr('height'),
  21524. 'align':node.getAttr('align'),
  21525. 'cssfloat':node.getStyle('float'),
  21526. 'url':node.getAttr("src"),
  21527. 'logo':node.getAttr('logo_url')
  21528. }));
  21529. node.parentNode.replaceChild(img,node);
  21530. }
  21531. })
  21532. },
  21533. commands:{
  21534. /**
  21535. * 插入百度应用
  21536. * @command webapp
  21537. * @method execCommand
  21538. * @remind 需要百度APPKey
  21539. * @remind 百度应用主页: <a href="http://app.baidu.com/" target="_blank">http://app.baidu.com/</a>
  21540. * @param { Object } appOptions 应用所需的参数项, 支持的key有: title=>应用标题, width=>应用容器宽度,
  21541. * height=>应用容器高度,logo=>应用logo,url=>应用地址
  21542. * @example
  21543. * ```javascript
  21544. * //editor是编辑器实例
  21545. * //在编辑器里插入一个“植物大战僵尸”的APP
  21546. * editor.execCommand( 'webapp' , {
  21547. * title: '植物大战僵尸',
  21548. * width: 560,
  21549. * height: 465,
  21550. * logo: '应用展示的图片',
  21551. * url: '百度应用的地址'
  21552. * } );
  21553. * ```
  21554. */
  21555. 'webapp':{
  21556. execCommand:function (cmd, obj) {
  21557. var me = this,
  21558. str = createInsertStr(utils.extend(obj,{
  21559. align:'none'
  21560. }), false);
  21561. me.execCommand("inserthtml",str);
  21562. },
  21563. queryCommandState:function () {
  21564. var me = this,
  21565. img = me.selection.getRange().getClosedNode(),
  21566. flag = img && (img.className == "edui-faked-webapp");
  21567. return flag ? 1 : 0;
  21568. }
  21569. }
  21570. }
  21571. }
  21572. });
  21573. // js/editor/_src/plugins/template.js
  21574. ///import core
  21575. ///import plugins\inserthtml.js
  21576. ///import plugins\cleardoc.js
  21577. ///commands 模板
  21578. ///commandsName template
  21579. ///commandsTitle 模板
  21580. ///commandsDialog dialogs\template
  21581. UE.plugins['template'] = function () {
  21582. UE.commands['template'] = {
  21583. execCommand:function (cmd, obj) {
  21584. obj.html && this.execCommand("inserthtml", obj.html);
  21585. }
  21586. };
  21587. this.addListener("click", function (type, evt) {
  21588. var el = evt.target || evt.srcElement,
  21589. range = this.selection.getRange();
  21590. var tnode = domUtils.findParent(el, function (node) {
  21591. if (node.className && domUtils.hasClass(node, "ue_t")) {
  21592. return node;
  21593. }
  21594. }, true);
  21595. tnode && range.selectNode(tnode).shrinkBoundary().select();
  21596. });
  21597. this.addListener("keydown", function (type, evt) {
  21598. var range = this.selection.getRange();
  21599. if (!range.collapsed) {
  21600. if (!evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey) {
  21601. var tnode = domUtils.findParent(range.startContainer, function (node) {
  21602. if (node.className && domUtils.hasClass(node, "ue_t")) {
  21603. return node;
  21604. }
  21605. }, true);
  21606. if (tnode) {
  21607. domUtils.removeClasses(tnode, ["ue_t"]);
  21608. }
  21609. }
  21610. }
  21611. });
  21612. };
  21613. // js/editor/_src/plugins/music.js
  21614. /**
  21615. * 插入音乐命令
  21616. * @file
  21617. */
  21618. UE.plugin.register('music', function (){
  21619. var me = this;
  21620. function creatInsertStr(url,width,height,align,cssfloat,toEmbed){
  21621. return !toEmbed ?
  21622. '<img ' +
  21623. (align && !cssfloat? 'align="' + align + '"' : '') +
  21624. (cssfloat ? 'style="float:' + cssfloat + '"' : '') +
  21625. ' width="'+ width +'" height="' + height + '" _url="'+url+'" class="edui-faked-music"' +
  21626. ' src="'+me.options.langPath+me.options.lang+'/images/music.png" />'
  21627. :
  21628. '<embed type="application/x-shockwave-flash" class="edui-faked-music" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  21629. ' src="' + url + '" width="' + width + '" height="' + height + '" '+ (align && !cssfloat? 'align="' + align + '"' : '') +
  21630. (cssfloat ? 'style="float:' + cssfloat + '"' : '') +
  21631. ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >';
  21632. }
  21633. return {
  21634. outputRule: function(root){
  21635. utils.each(root.getNodesByTagName('img'),function(node){
  21636. var html;
  21637. if(node.getAttr('class') == 'edui-faked-music'){
  21638. var cssfloat = node.getStyle('float');
  21639. var align = node.getAttr('align');
  21640. html = creatInsertStr(node.getAttr("_url"), node.getAttr('width'), node.getAttr('height'), align, cssfloat, true);
  21641. var embed = UE.uNode.createElement(html);
  21642. node.parentNode.replaceChild(embed,node);
  21643. }
  21644. })
  21645. },
  21646. inputRule:function(root){
  21647. utils.each(root.getNodesByTagName('embed'),function(node){
  21648. if(node.getAttr('class') == 'edui-faked-music'){
  21649. var cssfloat = node.getStyle('float');
  21650. var align = node.getAttr('align');
  21651. html = creatInsertStr(node.getAttr("src"), node.getAttr('width'), node.getAttr('height'), align, cssfloat,false);
  21652. var img = UE.uNode.createElement(html);
  21653. node.parentNode.replaceChild(img,node);
  21654. }
  21655. })
  21656. },
  21657. commands:{
  21658. /**
  21659. * 插入音乐
  21660. * @command music
  21661. * @method execCommand
  21662. * @param { Object } musicOptions 插入音乐的参数项, 支持的key有: url=>音乐地址;
  21663. * width=>音乐容器宽度;height=>音乐容器高度;align=>音乐文件的对齐方式, 可选值有: left, center, right, none
  21664. * @example
  21665. * ```javascript
  21666. * //editor是编辑器实例
  21667. * //在编辑器里插入一个“植物大战僵尸”的APP
  21668. * editor.execCommand( 'music' , {
  21669. * width: 400,
  21670. * height: 95,
  21671. * align: "center",
  21672. * url: "音乐地址"
  21673. * } );
  21674. * ```
  21675. */
  21676. 'music':{
  21677. execCommand:function (cmd, musicObj) {
  21678. var me = this,
  21679. str = creatInsertStr(musicObj.url, musicObj.width || 400, musicObj.height || 95, "none", false);
  21680. me.execCommand("inserthtml",str);
  21681. },
  21682. queryCommandState:function () {
  21683. var me = this,
  21684. img = me.selection.getRange().getClosedNode(),
  21685. flag = img && (img.className == "edui-faked-music");
  21686. return flag ? 1 : 0;
  21687. }
  21688. }
  21689. }
  21690. }
  21691. });
  21692. // js/editor/_src/plugins/autoupload.js
  21693. /**
  21694. * @description
  21695. * 1.拖放文件到编辑区域,自动上传并插入到选区
  21696. * 2.插入粘贴板的图片,自动上传并插入到选区
  21697. * @author Jinqn
  21698. * @date 2013-10-14
  21699. */
  21700. UE.plugin.register('autoupload', function (){
  21701. function sendAndInsertFile(file, editor) {
  21702. var me = editor;
  21703. //模拟数据
  21704. var fieldName, urlPrefix, maxSize, allowFiles, actionUrl,
  21705. loadingHtml, errorHandler, successHandler,
  21706. filetype = /image\/\w+/i.test(file.type) ? 'image':'file',
  21707. loadingId = 'loading_' + (+new Date()).toString(36);
  21708. fieldName = me.getOpt(filetype + 'FieldName');
  21709. urlPrefix = me.getOpt(filetype + 'UrlPrefix');
  21710. maxSize = me.getOpt(filetype + 'MaxSize');
  21711. allowFiles = me.getOpt(filetype + 'AllowFiles');
  21712. actionUrl = me.getActionUrl(me.getOpt(filetype + 'ActionName'));
  21713. errorHandler = function(title) {
  21714. var loader = me.document.getElementById(loadingId);
  21715. loader && domUtils.remove(loader);
  21716. me.fireEvent('showmessage', {
  21717. 'id': loadingId,
  21718. 'content': title,
  21719. 'type': 'error',
  21720. 'timeout': 4000
  21721. });
  21722. };
  21723. if (filetype == 'image') {
  21724. loadingHtml = '<img class="loadingclass" id="' + loadingId + '" src="' +
  21725. me.options.themePath + me.options.theme +
  21726. '/images/spacer.gif" title="' + (me.getLang('autoupload.loading') || '') + '" >';
  21727. successHandler = function(data) {
  21728. var link = urlPrefix + data.url,
  21729. loader = me.document.getElementById(loadingId);
  21730. if (loader) {
  21731. loader.setAttribute('src', link);
  21732. loader.setAttribute('_src', link);
  21733. loader.setAttribute('title', data.title || '');
  21734. loader.setAttribute('alt', data.original || '');
  21735. loader.removeAttribute('id');
  21736. domUtils.removeClasses(loader, 'loadingclass');
  21737. }
  21738. };
  21739. } else {
  21740. loadingHtml = '<p>' +
  21741. '<img class="loadingclass" id="' + loadingId + '" src="' +
  21742. me.options.themePath + me.options.theme +
  21743. '/images/spacer.gif" title="' + (me.getLang('autoupload.loading') || '') + '" >' +
  21744. '</p>';
  21745. successHandler = function(data) {
  21746. var link = urlPrefix + data.url,
  21747. loader = me.document.getElementById(loadingId);
  21748. var rng = me.selection.getRange(),
  21749. bk = rng.createBookmark();
  21750. rng.selectNode(loader).select();
  21751. me.execCommand('insertfile', {'url': link});
  21752. rng.moveToBookmark(bk).select();
  21753. };
  21754. }
  21755. /* 插入loading的占位符 */
  21756. me.execCommand('inserthtml', loadingHtml);
  21757. /* 判断后端配置是否没有加载成功 */
  21758. if (!me.getOpt(filetype + 'ActionName')) {
  21759. errorHandler(me.getLang('autoupload.errorLoadConfig'));
  21760. return;
  21761. }
  21762. /* 判断文件大小是否超出限制 */
  21763. if(file.size > maxSize) {
  21764. errorHandler(me.getLang('autoupload.exceedSizeError'));
  21765. return;
  21766. }
  21767. /* 判断文件格式是否超出允许 */
  21768. var fileext = file.name ? file.name.substr(file.name.lastIndexOf('.')):'';
  21769. if ((fileext && filetype != 'image') || (allowFiles && (allowFiles.join('') + '.').indexOf(fileext.toLowerCase() + '.') == -1)) {
  21770. errorHandler(me.getLang('autoupload.exceedTypeError'));
  21771. return;
  21772. }
  21773. /* 创建Ajax并提交 */
  21774. var xhr = new XMLHttpRequest(),
  21775. fd = new FormData(),
  21776. params = utils.serializeParam(me.queryCommandValue('serverparam')) || '',
  21777. url = utils.formatUrl(actionUrl + (actionUrl.indexOf('?') == -1 ? '?':'&') + params);
  21778. fd.append(fieldName, file, file.name || ('blob.' + file.type.substr('image/'.length)));
  21779. fd.append('type', 'ajax');
  21780. xhr.open("post", url, true);
  21781. xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  21782. xhr.addEventListener('load', function (e) {
  21783. try{
  21784. var json = (new Function("return " + utils.trim(e.target.response)))();
  21785. if (json.state == 'SUCCESS' && json.url) {
  21786. successHandler(json);
  21787. } else {
  21788. errorHandler(json.state);
  21789. }
  21790. }catch(er){
  21791. errorHandler(me.getLang('autoupload.loadError'));
  21792. }
  21793. });
  21794. xhr.send(fd);
  21795. }
  21796. function getPasteImage(e){
  21797. return e.clipboardData && e.clipboardData.items && e.clipboardData.items.length == 1 && /^image\//.test(e.clipboardData.items[0].type) ? e.clipboardData.items:null;
  21798. }
  21799. function getDropImage(e){
  21800. return e.dataTransfer && e.dataTransfer.files ? e.dataTransfer.files:null;
  21801. }
  21802. return {
  21803. outputRule: function(root){
  21804. utils.each(root.getNodesByTagName('img'),function(n){
  21805. if (/\b(loaderrorclass)|(bloaderrorclass)\b/.test(n.getAttr('class'))) {
  21806. n.parentNode.removeChild(n);
  21807. }
  21808. });
  21809. utils.each(root.getNodesByTagName('p'),function(n){
  21810. if (/\bloadpara\b/.test(n.getAttr('class'))) {
  21811. n.parentNode.removeChild(n);
  21812. }
  21813. });
  21814. },
  21815. bindEvents:{
  21816. //插入粘贴板的图片,拖放插入图片
  21817. 'ready':function(e){
  21818. var me = this;
  21819. if(window.FormData && window.FileReader) {
  21820. domUtils.on(me.body, 'paste drop', function(e){
  21821. var hasImg = false,
  21822. items;
  21823. //获取粘贴板文件列表或者拖放文件列表
  21824. items = e.type == 'paste' ? getPasteImage(e):getDropImage(e);
  21825. if(items){
  21826. var len = items.length,
  21827. file;
  21828. while (len--){
  21829. file = items[len];
  21830. if(file.getAsFile) file = file.getAsFile();
  21831. if(file && file.size > 0) {
  21832. sendAndInsertFile(file, me);
  21833. hasImg = true;
  21834. }
  21835. }
  21836. hasImg && e.preventDefault();
  21837. }
  21838. });
  21839. //取消拖放图片时出现的文字光标位置提示
  21840. domUtils.on(me.body, 'dragover', function (e) {
  21841. if(e.dataTransfer.types[0] == 'Files') {
  21842. e.preventDefault();
  21843. }
  21844. });
  21845. //设置loading的样式
  21846. utils.cssRule('loading',
  21847. '.loadingclass{display:inline-block;cursor:default;background: url(\''
  21848. + this.options.themePath
  21849. + this.options.theme +'/images/loading.gif\') no-repeat center center transparent;border:1px solid #cccccc;margin-left:1px;height: 22px;width: 22px;}\n' +
  21850. '.loaderrorclass{display:inline-block;cursor:default;background: url(\''
  21851. + this.options.themePath
  21852. + this.options.theme +'/images/loaderror.png\') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;' +
  21853. '}',
  21854. this.document);
  21855. }
  21856. }
  21857. }
  21858. }
  21859. });
  21860. // js/editor/_src/plugins/autosave.js
  21861. UE.plugin.register('autosave', function (){
  21862. var me = this,
  21863. //无限循环保护
  21864. lastSaveTime = new Date(),
  21865. //最小保存间隔时间
  21866. MIN_TIME = 20,
  21867. //auto save key
  21868. saveKey = null;
  21869. function save ( editor ) {
  21870. var saveData;
  21871. if ( new Date() - lastSaveTime < MIN_TIME ) {
  21872. return;
  21873. }
  21874. if ( !editor.hasContents() ) {
  21875. //这里不能调用命令来删除, 会造成事件死循环
  21876. saveKey && me.removePreferences( saveKey );
  21877. return;
  21878. }
  21879. lastSaveTime = new Date();
  21880. editor._saveFlag = null;
  21881. saveData = me.body.innerHTML;
  21882. if ( editor.fireEvent( "beforeautosave", {
  21883. content: saveData
  21884. } ) === false ) {
  21885. return;
  21886. }
  21887. me.setPreferences( saveKey, saveData );
  21888. editor.fireEvent( "afterautosave", {
  21889. content: saveData
  21890. } );
  21891. }
  21892. return {
  21893. defaultOptions: {
  21894. //默认间隔时间
  21895. saveInterval: 500
  21896. },
  21897. bindEvents:{
  21898. 'ready':function(){
  21899. var _suffix = "-drafts-data",
  21900. key = null;
  21901. if ( me.key ) {
  21902. key = me.key + _suffix;
  21903. } else {
  21904. key = ( me.container.parentNode.id || 'ue-common' ) + _suffix;
  21905. }
  21906. //页面地址+编辑器ID 保持唯一
  21907. saveKey = ( location.protocol + location.host + location.pathname ).replace( /[.:\/]/g, '_' ) + key;
  21908. },
  21909. 'contentchange': function () {
  21910. if ( !saveKey ) {
  21911. return;
  21912. }
  21913. if ( me._saveFlag ) {
  21914. window.clearTimeout( me._saveFlag );
  21915. }
  21916. if ( me.options.saveInterval > 0 ) {
  21917. me._saveFlag = window.setTimeout( function () {
  21918. save( me );
  21919. }, me.options.saveInterval );
  21920. } else {
  21921. save(me);
  21922. }
  21923. }
  21924. },
  21925. commands:{
  21926. 'clearlocaldata':{
  21927. execCommand:function (cmd, name) {
  21928. if ( saveKey && me.getPreferences( saveKey ) ) {
  21929. me.removePreferences( saveKey )
  21930. }
  21931. },
  21932. notNeedUndo: true,
  21933. ignoreContentChange:true
  21934. },
  21935. 'getlocaldata':{
  21936. execCommand:function (cmd, name) {
  21937. return saveKey ? me.getPreferences( saveKey ) || '' : '';
  21938. },
  21939. notNeedUndo: true,
  21940. ignoreContentChange:true
  21941. },
  21942. 'drafts':{
  21943. execCommand:function (cmd, name) {
  21944. if ( saveKey ) {
  21945. me.body.innerHTML = me.getPreferences( saveKey ) || '<p>'+domUtils.fillHtml+'</p>';
  21946. me.focus(true);
  21947. }
  21948. },
  21949. queryCommandState: function () {
  21950. return saveKey ? ( me.getPreferences( saveKey ) === null ? -1 : 0 ) : -1;
  21951. },
  21952. notNeedUndo: true,
  21953. ignoreContentChange:true
  21954. }
  21955. }
  21956. }
  21957. });
  21958. // js/editor/_src/plugins/charts.js
  21959. UE.plugin.register('charts', function (){
  21960. var me = this;
  21961. return {
  21962. bindEvents: {
  21963. 'chartserror': function () {
  21964. }
  21965. },
  21966. commands:{
  21967. 'charts': {
  21968. execCommand: function ( cmd, data ) {
  21969. var tableNode = domUtils.findParentByTagName(this.selection.getRange().startContainer, 'table', true),
  21970. flagText = [],
  21971. config = {};
  21972. if ( !tableNode ) {
  21973. return false;
  21974. }
  21975. if ( !validData( tableNode ) ) {
  21976. me.fireEvent( "chartserror" );
  21977. return false;
  21978. }
  21979. config.title = data.title || '';
  21980. config.subTitle = data.subTitle || '';
  21981. config.xTitle = data.xTitle || '';
  21982. config.yTitle = data.yTitle || '';
  21983. config.suffix = data.suffix || '';
  21984. config.tip = data.tip || '';
  21985. //数据对齐方式
  21986. config.dataFormat = data.tableDataFormat || '';
  21987. //图表类型
  21988. config.chartType = data.chartType || 0;
  21989. for ( var key in config ) {
  21990. if ( !config.hasOwnProperty( key ) ) {
  21991. continue;
  21992. }
  21993. flagText.push( key+":"+config[ key ] );
  21994. }
  21995. tableNode.setAttribute( "data-chart", flagText.join( ";" ) );
  21996. domUtils.addClass( tableNode, "edui-charts-table" );
  21997. },
  21998. queryCommandState: function ( cmd, name ) {
  21999. var tableNode = domUtils.findParentByTagName(this.selection.getRange().startContainer, 'table', true);
  22000. return tableNode && validData( tableNode ) ? 0 : -1;
  22001. }
  22002. }
  22003. },
  22004. inputRule:function(root){
  22005. utils.each(root.getNodesByTagName('table'),function( tableNode ){
  22006. if ( tableNode.getAttr("data-chart") !== undefined ) {
  22007. tableNode.setAttr("style");
  22008. }
  22009. })
  22010. },
  22011. outputRule:function(root){
  22012. utils.each(root.getNodesByTagName('table'),function( tableNode ){
  22013. if ( tableNode.getAttr("data-chart") !== undefined ) {
  22014. tableNode.setAttr("style", "display: none;");
  22015. }
  22016. })
  22017. }
  22018. }
  22019. function validData ( table ) {
  22020. var firstRows = null,
  22021. cellCount = 0;
  22022. //行数不够
  22023. if ( table.rows.length < 2 ) {
  22024. return false;
  22025. }
  22026. //列数不够
  22027. if ( table.rows[0].cells.length < 2 ) {
  22028. return false;
  22029. }
  22030. //第一行所有cell必须是th
  22031. firstRows = table.rows[ 0 ].cells;
  22032. cellCount = firstRows.length;
  22033. for ( var i = 0, cell; cell = firstRows[ i ]; i++ ) {
  22034. if ( cell.tagName.toLowerCase() !== 'th' ) {
  22035. return false;
  22036. }
  22037. }
  22038. for ( var i = 1, row; row = table.rows[ i ]; i++ ) {
  22039. //每行单元格数不匹配, 返回false
  22040. if ( row.cells.length != cellCount ) {
  22041. return false;
  22042. }
  22043. //第一列不是th也返回false
  22044. if ( row.cells[0].tagName.toLowerCase() !== 'th' ) {
  22045. return false;
  22046. }
  22047. for ( var j = 1, cell; cell = row.cells[ j ]; j++ ) {
  22048. var value = utils.trim( ( cell.innerText || cell.textContent || '' ) );
  22049. value = value.replace( new RegExp( UE.dom.domUtils.fillChar, 'g' ), '' ).replace( /^\s+|\s+$/g, '' );
  22050. //必须是数字
  22051. if ( !/^\d*\.?\d+$/.test( value ) ) {
  22052. return false;
  22053. }
  22054. }
  22055. }
  22056. return true;
  22057. }
  22058. });
  22059. // js/editor/_src/plugins/section.js
  22060. /**
  22061. * 目录大纲支持插件
  22062. * @file
  22063. * @since 1.3.0
  22064. */
  22065. UE.plugin.register('section', function (){
  22066. /* 目录节点对象 */
  22067. function Section(option){
  22068. this.tag = '';
  22069. this.level = -1,
  22070. this.dom = null;
  22071. this.nextSection = null;
  22072. this.previousSection = null;
  22073. this.parentSection = null;
  22074. this.startAddress = [];
  22075. this.endAddress = [];
  22076. this.children = [];
  22077. }
  22078. function getSection(option) {
  22079. var section = new Section();
  22080. return utils.extend(section, option);
  22081. }
  22082. function getNodeFromAddress(startAddress, root) {
  22083. var current = root;
  22084. for(var i = 0;i < startAddress.length; i++) {
  22085. if(!current.childNodes) return null;
  22086. current = current.childNodes[startAddress[i]];
  22087. }
  22088. return current;
  22089. }
  22090. var me = this;
  22091. return {
  22092. bindMultiEvents:{
  22093. type: 'aftersetcontent afterscencerestore',
  22094. handler: function(){
  22095. me.fireEvent('updateSections');
  22096. }
  22097. },
  22098. bindEvents:{
  22099. /* 初始化、拖拽、粘贴、执行setcontent之后 */
  22100. 'ready': function (){
  22101. me.fireEvent('updateSections');
  22102. domUtils.on(me.body, 'drop paste', function(){
  22103. me.fireEvent('updateSections');
  22104. });
  22105. },
  22106. /* 执行paragraph命令之后 */
  22107. 'afterexeccommand': function (type, cmd) {
  22108. if(cmd == 'paragraph') {
  22109. me.fireEvent('updateSections');
  22110. }
  22111. },
  22112. /* 部分键盘操作,触发updateSections事件 */
  22113. 'keyup': function (type, e) {
  22114. var me = this,
  22115. range = me.selection.getRange();
  22116. if(range.collapsed != true) {
  22117. me.fireEvent('updateSections');
  22118. } else {
  22119. var keyCode = e.keyCode || e.which;
  22120. if(keyCode == 13 || keyCode == 8 || keyCode == 46) {
  22121. me.fireEvent('updateSections');
  22122. }
  22123. }
  22124. }
  22125. },
  22126. commands:{
  22127. 'getsections': {
  22128. execCommand: function (cmd, levels) {
  22129. var levelFn = levels || ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
  22130. for (var i = 0; i < levelFn.length; i++) {
  22131. if (typeof levelFn[i] == 'string') {
  22132. levelFn[i] = function(fn){
  22133. return function(node){
  22134. return node.tagName == fn.toUpperCase()
  22135. };
  22136. }(levelFn[i]);
  22137. } else if (typeof levelFn[i] != 'function') {
  22138. levelFn[i] = function (node) {
  22139. return null;
  22140. }
  22141. }
  22142. }
  22143. function getSectionLevel(node) {
  22144. for (var i = 0; i < levelFn.length; i++) {
  22145. if (levelFn[i](node)) return i;
  22146. }
  22147. return -1;
  22148. }
  22149. var me = this,
  22150. Directory = getSection({'level':-1, 'title':'root'}),
  22151. previous = Directory;
  22152. function traversal(node, Directory) {
  22153. var level,
  22154. tmpSection = null,
  22155. parent,
  22156. child,
  22157. children = node.childNodes;
  22158. for (var i = 0, len = children.length; i < len; i++) {
  22159. child = children[i];
  22160. level = getSectionLevel(child);
  22161. if (level >= 0) {
  22162. var address = me.selection.getRange().selectNode(child).createAddress(true).startAddress,
  22163. current = getSection({
  22164. 'tag': child.tagName,
  22165. 'title': child.innerText || child.textContent || '',
  22166. 'level': level,
  22167. 'dom': child,
  22168. 'startAddress': utils.clone(address, []),
  22169. 'endAddress': utils.clone(address, []),
  22170. 'children': []
  22171. });
  22172. previous.nextSection = current;
  22173. current.previousSection = previous;
  22174. parent = previous;
  22175. while(level <= parent.level){
  22176. parent = parent.parentSection;
  22177. }
  22178. current.parentSection = parent;
  22179. parent.children.push(current);
  22180. tmpSection = previous = current;
  22181. } else {
  22182. child.nodeType === 1 && traversal(child, Directory);
  22183. tmpSection && tmpSection.endAddress[tmpSection.endAddress.length - 1] ++;
  22184. }
  22185. }
  22186. }
  22187. traversal(me.body, Directory);
  22188. return Directory;
  22189. },
  22190. notNeedUndo: true
  22191. },
  22192. 'movesection': {
  22193. execCommand: function (cmd, sourceSection, targetSection, isAfter) {
  22194. var me = this,
  22195. targetAddress,
  22196. target;
  22197. if(!sourceSection || !targetSection || targetSection.level == -1) return;
  22198. targetAddress = isAfter ? targetSection.endAddress:targetSection.startAddress;
  22199. target = getNodeFromAddress(targetAddress, me.body);
  22200. /* 判断目标地址是否被源章节包含 */
  22201. if(!targetAddress || !target || isContainsAddress(sourceSection.startAddress, sourceSection.endAddress, targetAddress)) return;
  22202. var startNode = getNodeFromAddress(sourceSection.startAddress, me.body),
  22203. endNode = getNodeFromAddress(sourceSection.endAddress, me.body),
  22204. current,
  22205. nextNode;
  22206. if(isAfter) {
  22207. current = endNode;
  22208. while ( current && !(domUtils.getPosition( startNode, current ) & domUtils.POSITION_FOLLOWING) ) {
  22209. nextNode = current.previousSibling;
  22210. domUtils.insertAfter(target, current);
  22211. if(current == startNode) break;
  22212. current = nextNode;
  22213. }
  22214. } else {
  22215. current = startNode;
  22216. while ( current && !(domUtils.getPosition( current, endNode ) & domUtils.POSITION_FOLLOWING) ) {
  22217. nextNode = current.nextSibling;
  22218. target.parentNode.insertBefore(current, target);
  22219. if(current == endNode) break;
  22220. current = nextNode;
  22221. }
  22222. }
  22223. me.fireEvent('updateSections');
  22224. /* 获取地址的包含关系 */
  22225. function isContainsAddress(startAddress, endAddress, addressTarget){
  22226. var isAfterStartAddress = false,
  22227. isBeforeEndAddress = false;
  22228. for(var i = 0; i< startAddress.length; i++){
  22229. if(i >= addressTarget.length) break;
  22230. if(addressTarget[i] > startAddress[i]) {
  22231. isAfterStartAddress = true;
  22232. break;
  22233. } else if(addressTarget[i] < startAddress[i]) {
  22234. break;
  22235. }
  22236. }
  22237. for(var i = 0; i< endAddress.length; i++){
  22238. if(i >= addressTarget.length) break;
  22239. if(addressTarget[i] < startAddress[i]) {
  22240. isBeforeEndAddress = true;
  22241. break;
  22242. } else if(addressTarget[i] > startAddress[i]) {
  22243. break;
  22244. }
  22245. }
  22246. return isAfterStartAddress && isBeforeEndAddress;
  22247. }
  22248. }
  22249. },
  22250. 'deletesection': {
  22251. execCommand: function (cmd, section, keepChildren) {
  22252. var me = this;
  22253. if(!section) return;
  22254. function getNodeFromAddress(startAddress) {
  22255. var current = me.body;
  22256. for(var i = 0;i < startAddress.length; i++) {
  22257. if(!current.childNodes) return null;
  22258. current = current.childNodes[startAddress[i]];
  22259. }
  22260. return current;
  22261. }
  22262. var startNode = getNodeFromAddress(section.startAddress),
  22263. endNode = getNodeFromAddress(section.endAddress),
  22264. current = startNode,
  22265. nextNode;
  22266. if(!keepChildren) {
  22267. while ( current && domUtils.inDoc(endNode, me.document) && !(domUtils.getPosition( current, endNode ) & domUtils.POSITION_FOLLOWING) ) {
  22268. nextNode = current.nextSibling;
  22269. domUtils.remove(current);
  22270. current = nextNode;
  22271. }
  22272. } else {
  22273. domUtils.remove(current);
  22274. }
  22275. me.fireEvent('updateSections');
  22276. }
  22277. },
  22278. 'selectsection': {
  22279. execCommand: function (cmd, section) {
  22280. if(!section && !section.dom) return false;
  22281. var me = this,
  22282. range = me.selection.getRange(),
  22283. address = {
  22284. 'startAddress':utils.clone(section.startAddress, []),
  22285. 'endAddress':utils.clone(section.endAddress, [])
  22286. };
  22287. address.endAddress[address.endAddress.length - 1]++;
  22288. range.moveToAddress(address).select().scrollToView();
  22289. return true;
  22290. },
  22291. notNeedUndo: true
  22292. },
  22293. 'scrolltosection': {
  22294. execCommand: function (cmd, section) {
  22295. if(!section && !section.dom) return false;
  22296. var me = this,
  22297. range = me.selection.getRange(),
  22298. address = {
  22299. 'startAddress':section.startAddress,
  22300. 'endAddress':section.endAddress
  22301. };
  22302. address.endAddress[address.endAddress.length - 1]++;
  22303. range.moveToAddress(address).scrollToView();
  22304. return true;
  22305. },
  22306. notNeedUndo: true
  22307. }
  22308. }
  22309. }
  22310. });
  22311. // js/editor/_src/plugins/simpleupload.js
  22312. /**
  22313. * @description
  22314. * 简单上传:点击按钮,直接选择文件上传
  22315. * @author Jinqn
  22316. * @date 2014-03-31
  22317. */
  22318. UE.plugin.register('simpleupload', function (){
  22319. var me = this,
  22320. isLoaded = false,
  22321. containerBtn;
  22322. function initUploadBtn(){
  22323. var w = containerBtn.offsetWidth || 20,
  22324. h = containerBtn.offsetHeight || 20,
  22325. btnIframe = document.createElement('iframe'),
  22326. btnStyle = 'display:block;width:' + w + 'px;height:' + h + '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;';
  22327. domUtils.on(btnIframe, 'load', function(){
  22328. var timestrap = (+new Date()).toString(36),
  22329. wrapper,
  22330. btnIframeDoc,
  22331. btnIframeBody;
  22332. btnIframeDoc = (btnIframe.contentDocument || btnIframe.contentWindow.document);
  22333. btnIframeBody = btnIframeDoc.body;
  22334. wrapper = btnIframeDoc.createElement('div');
  22335. wrapper.innerHTML = '<form id="edui_form_' + timestrap + '" target="edui_iframe_' + timestrap + '" method="POST" enctype="multipart/form-data" action="' + me.getOpt('serverUrl') + '" ' +
  22336. 'style="' + btnStyle + '">' +
  22337. '<input id="edui_input_' + timestrap + '" type="file" accept="image/*" name="' + me.options.imageFieldName + '" ' +
  22338. 'style="' + btnStyle + '">' +
  22339. '</form>' +
  22340. '<iframe id="edui_iframe_' + timestrap + '" name="edui_iframe_' + timestrap + '" style="display:none;width:0;height:0;border:0;margin:0;padding:0;position:absolute;"></iframe>';
  22341. wrapper.className = 'edui-' + me.options.theme;
  22342. wrapper.id = me.ui.id + '_iframeupload';
  22343. btnIframeBody.style.cssText = btnStyle;
  22344. btnIframeBody.style.width = w + 'px';
  22345. btnIframeBody.style.height = h + 'px';
  22346. btnIframeBody.appendChild(wrapper);
  22347. if (btnIframeBody.parentNode) {
  22348. btnIframeBody.parentNode.style.width = w + 'px';
  22349. btnIframeBody.parentNode.style.height = w + 'px';
  22350. }
  22351. var form = btnIframeDoc.getElementById('edui_form_' + timestrap);
  22352. var input = btnIframeDoc.getElementById('edui_input_' + timestrap);
  22353. var iframe = btnIframeDoc.getElementById('edui_iframe_' + timestrap);
  22354. domUtils.on(input, 'change', function(){
  22355. if(!input.value) return;
  22356. var loadingId = 'loading_' + (+new Date()).toString(36);
  22357. var params = utils.serializeParam(me.queryCommandValue('serverparam')) || '';
  22358. var imageActionUrl = me.getActionUrl(me.getOpt('imageActionName'));
  22359. var allowFiles = me.getOpt('imageAllowFiles');
  22360. me.focus();
  22361. me.execCommand('inserthtml', '<img class="loadingclass" id="' + loadingId + '" src="' + me.options.themePath + me.options.theme +'/images/spacer.gif" title="' + (me.getLang('simpleupload.loading') || '') + '" >');
  22362. function callback(){
  22363. try{
  22364. var link, json, loader,
  22365. body = (iframe.contentDocument || iframe.contentWindow.document).body,
  22366. result = body.innerText || body.textContent || '';
  22367. json = (new Function("return " + result))();
  22368. link = me.options.imageUrlPrefix + json.url;
  22369. if(json.state == 'SUCCESS' && json.url) {
  22370. loader = me.document.getElementById(loadingId);
  22371. loader.setAttribute('src', link);
  22372. loader.setAttribute('_src', link);
  22373. loader.setAttribute('title', json.title || '');
  22374. loader.setAttribute('alt', json.original || '');
  22375. loader.removeAttribute('id');
  22376. domUtils.removeClasses(loader, 'loadingclass');
  22377. } else {
  22378. showErrorLoader && showErrorLoader(json.state);
  22379. }
  22380. }catch(er){
  22381. showErrorLoader && showErrorLoader(me.getLang('simpleupload.loadError'));
  22382. }
  22383. form.reset();
  22384. domUtils.un(iframe, 'load', callback);
  22385. }
  22386. function showErrorLoader(title){
  22387. if(loadingId) {
  22388. var loader = me.document.getElementById(loadingId);
  22389. loader && domUtils.remove(loader);
  22390. me.fireEvent('showmessage', {
  22391. 'id': loadingId,
  22392. 'content': title,
  22393. 'type': 'error',
  22394. 'timeout': 4000
  22395. });
  22396. }
  22397. }
  22398. /* 判断后端配置是否没有加载成功 */
  22399. if (!me.getOpt('imageActionName')) {
  22400. errorHandler(me.getLang('autoupload.errorLoadConfig'));
  22401. return;
  22402. }
  22403. // 判断文件格式是否错误
  22404. var filename = input.value,
  22405. fileext = filename ? filename.substr(filename.lastIndexOf('.')):'';
  22406. if (!fileext || (allowFiles && (allowFiles.join('') + '.').indexOf(fileext.toLowerCase() + '.') == -1)) {
  22407. showErrorLoader(me.getLang('simpleupload.exceedTypeError'));
  22408. return;
  22409. }
  22410. domUtils.on(iframe, 'load', callback);
  22411. form.action = utils.formatUrl(imageActionUrl + (imageActionUrl.indexOf('?') == -1 ? '?':'&') + params);
  22412. form.submit();
  22413. });
  22414. var stateTimer;
  22415. me.addListener('selectionchange', function () {
  22416. clearTimeout(stateTimer);
  22417. stateTimer = setTimeout(function() {
  22418. var state = me.queryCommandState('simpleupload');
  22419. if (state == -1) {
  22420. input.disabled = 'disabled';
  22421. } else {
  22422. input.disabled = false;
  22423. }
  22424. }, 400);
  22425. });
  22426. isLoaded = true;
  22427. });
  22428. btnIframe.style.cssText = btnStyle;
  22429. containerBtn.appendChild(btnIframe);
  22430. }
  22431. return {
  22432. bindEvents:{
  22433. 'ready': function() {
  22434. //设置loading的样式
  22435. utils.cssRule('loading',
  22436. '.loadingclass{display:inline-block;cursor:default;background: url(\''
  22437. + this.options.themePath
  22438. + this.options.theme +'/images/loading.gif\') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;}\n' +
  22439. '.loaderrorclass{display:inline-block;cursor:default;background: url(\''
  22440. + this.options.themePath
  22441. + this.options.theme +'/images/loaderror.png\') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;' +
  22442. '}',
  22443. this.document);
  22444. },
  22445. /* 初始化简单上传按钮 */
  22446. 'simpleuploadbtnready': function(type, container) {
  22447. containerBtn = container;
  22448. me.afterConfigReady(initUploadBtn);
  22449. }
  22450. },
  22451. outputRule: function(root){
  22452. utils.each(root.getNodesByTagName('img'),function(n){
  22453. if (/\b(loaderrorclass)|(bloaderrorclass)\b/.test(n.getAttr('class'))) {
  22454. n.parentNode.removeChild(n);
  22455. }
  22456. });
  22457. },
  22458. commands: {
  22459. 'simpleupload': {
  22460. queryCommandState: function () {
  22461. return isLoaded ? 0:-1;
  22462. }
  22463. }
  22464. }
  22465. }
  22466. });
  22467. // js/editor/_src/plugins/serverparam.js
  22468. /**
  22469. * 服务器提交的额外参数列表设置插件
  22470. * @file
  22471. * @since 1.2.6.1
  22472. */
  22473. UE.plugin.register('serverparam', function (){
  22474. var me = this,
  22475. serverParam = {};
  22476. return {
  22477. commands:{
  22478. /**
  22479. * 修改服务器提交的额外参数列表,清除所有项
  22480. * @command serverparam
  22481. * @method execCommand
  22482. * @param { String } cmd 命令字符串
  22483. * @example
  22484. * ```javascript
  22485. * editor.execCommand('serverparam');
  22486. * editor.queryCommandValue('serverparam'); //返回空
  22487. * ```
  22488. */
  22489. /**
  22490. * 修改服务器提交的额外参数列表,删除指定项
  22491. * @command serverparam
  22492. * @method execCommand
  22493. * @param { String } cmd 命令字符串
  22494. * @param { String } key 要清除的属性
  22495. * @example
  22496. * ```javascript
  22497. * editor.execCommand('serverparam', 'name'); //删除属性name
  22498. * ```
  22499. */
  22500. /**
  22501. * 修改服务器提交的额外参数列表,使用键值添加项
  22502. * @command serverparam
  22503. * @method execCommand
  22504. * @param { String } cmd 命令字符串
  22505. * @param { String } key 要添加的属性
  22506. * @param { String } value 要添加属性的值
  22507. * @example
  22508. * ```javascript
  22509. * editor.execCommand('serverparam', 'name', 'hello');
  22510. * editor.queryCommandValue('serverparam'); //返回对象 {'name': 'hello'}
  22511. * ```
  22512. */
  22513. /**
  22514. * 修改服务器提交的额外参数列表,传入键值对对象添加多项
  22515. * @command serverparam
  22516. * @method execCommand
  22517. * @param { String } cmd 命令字符串
  22518. * @param { Object } key 传入的键值对对象
  22519. * @example
  22520. * ```javascript
  22521. * editor.execCommand('serverparam', {'name': 'hello'});
  22522. * editor.queryCommandValue('serverparam'); //返回对象 {'name': 'hello'}
  22523. * ```
  22524. */
  22525. /**
  22526. * 修改服务器提交的额外参数列表,使用自定义函数添加多项
  22527. * @command serverparam
  22528. * @method execCommand
  22529. * @param { String } cmd 命令字符串
  22530. * @param { Function } key 自定义获取参数的函数
  22531. * @example
  22532. * ```javascript
  22533. * editor.execCommand('serverparam', function(editor){
  22534. * return {'key': 'value'};
  22535. * });
  22536. * editor.queryCommandValue('serverparam'); //返回对象 {'key': 'value'}
  22537. * ```
  22538. */
  22539. /**
  22540. * 获取服务器提交的额外参数列表
  22541. * @command serverparam
  22542. * @method queryCommandValue
  22543. * @param { String } cmd 命令字符串
  22544. * @example
  22545. * ```javascript
  22546. * editor.queryCommandValue( 'serverparam' ); //返回对象 {'key': 'value'}
  22547. * ```
  22548. */
  22549. 'serverparam':{
  22550. execCommand:function (cmd, key, value) {
  22551. if (key === undefined || key === null) { //不传参数,清空列表
  22552. serverParam = {};
  22553. } else if (utils.isString(key)) { //传入键值
  22554. if(value === undefined || value === null) {
  22555. delete serverParam[key];
  22556. } else {
  22557. serverParam[key] = value;
  22558. }
  22559. } else if (utils.isObject(key)) { //传入对象,覆盖列表项
  22560. utils.extend(serverParam, key, true);
  22561. } else if (utils.isFunction(key)){ //传入函数,添加列表项
  22562. utils.extend(serverParam, key(), true);
  22563. }
  22564. },
  22565. queryCommandValue: function(){
  22566. return serverParam || {};
  22567. }
  22568. }
  22569. }
  22570. }
  22571. });
  22572. // js/editor/_src/plugins/insertfile.js
  22573. /**
  22574. * 插入附件
  22575. */
  22576. UE.plugin.register('insertfile', function (){
  22577. var me = this;
  22578. function getFileIcon(url){
  22579. var ext = url.substr(url.lastIndexOf('.') + 1).toLowerCase(),
  22580. maps = {
  22581. "rar":"icon_rar.gif",
  22582. "zip":"icon_rar.gif",
  22583. "tar":"icon_rar.gif",
  22584. "gz":"icon_rar.gif",
  22585. "bz2":"icon_rar.gif",
  22586. "doc":"icon_doc.gif",
  22587. "docx":"icon_doc.gif",
  22588. "pdf":"icon_pdf.gif",
  22589. "mp3":"icon_mp3.gif",
  22590. "xls":"icon_xls.gif",
  22591. "chm":"icon_chm.gif",
  22592. "ppt":"icon_ppt.gif",
  22593. "pptx":"icon_ppt.gif",
  22594. "avi":"icon_mv.gif",
  22595. "rmvb":"icon_mv.gif",
  22596. "wmv":"icon_mv.gif",
  22597. "flv":"icon_mv.gif",
  22598. "swf":"icon_mv.gif",
  22599. "rm":"icon_mv.gif",
  22600. "exe":"icon_exe.gif",
  22601. "psd":"icon_psd.gif",
  22602. "txt":"icon_txt.gif",
  22603. "jpg":"icon_jpg.gif",
  22604. "png":"icon_jpg.gif",
  22605. "jpeg":"icon_jpg.gif",
  22606. "gif":"icon_jpg.gif",
  22607. "ico":"icon_jpg.gif",
  22608. "bmp":"icon_jpg.gif"
  22609. };
  22610. return maps[ext] ? maps[ext]:maps['txt'];
  22611. }
  22612. return {
  22613. commands:{
  22614. 'insertfile': {
  22615. execCommand: function (command, filelist){
  22616. filelist = utils.isArray(filelist) ? filelist : [filelist];
  22617. var i, item, icon, title,
  22618. html = '',
  22619. URL = me.getOpt('UEDITOR_HOME_URL'),
  22620. iconDir = URL + (URL.substr(URL.length - 1) == '/' ? '':'/') + 'dialogs/attachment/fileTypeImages/';
  22621. for (i = 0; i < filelist.length; i++) {
  22622. item = filelist[i];
  22623. icon = iconDir + getFileIcon(item.url);
  22624. title = item.title || item.url.substr(item.url.lastIndexOf('/') + 1);
  22625. html += '<p style="line-height: 16px;">' +
  22626. '<img style="vertical-align: middle; margin-right: 2px;" src="'+ icon + '" _src="' + icon + '" />' +
  22627. '<a style="font-size:12px; color:#0066cc;" href="' + item.url +'" title="' + title + '">' + title + '</a>' +
  22628. '</p>';
  22629. }
  22630. me.execCommand('insertHtml', html);
  22631. }
  22632. }
  22633. }
  22634. }
  22635. });
  22636. // js/editor/_src/ui/ui.js
  22637. var baidu = baidu || {};
  22638. baidu.editor = baidu.editor || {};
  22639. UE.ui = baidu.editor.ui = {};
  22640. // js/editor/_src/ui/uiutils.js
  22641. (function (){
  22642. var browser = baidu.editor.browser,
  22643. domUtils = baidu.editor.dom.domUtils;
  22644. var magic = '$EDITORUI';
  22645. var root = window[magic] = {};
  22646. var uidMagic = 'ID' + magic;
  22647. var uidCount = 0;
  22648. var uiUtils = baidu.editor.ui.uiUtils = {
  22649. uid: function (obj){
  22650. return (obj ? obj[uidMagic] || (obj[uidMagic] = ++ uidCount) : ++ uidCount);
  22651. },
  22652. hook: function ( fn, callback ) {
  22653. var dg;
  22654. if (fn && fn._callbacks) {
  22655. dg = fn;
  22656. } else {
  22657. dg = function (){
  22658. var q;
  22659. if (fn) {
  22660. q = fn.apply(this, arguments);
  22661. }
  22662. var callbacks = dg._callbacks;
  22663. var k = callbacks.length;
  22664. while (k --) {
  22665. var r = callbacks[k].apply(this, arguments);
  22666. if (q === undefined) {
  22667. q = r;
  22668. }
  22669. }
  22670. return q;
  22671. };
  22672. dg._callbacks = [];
  22673. }
  22674. dg._callbacks.push(callback);
  22675. return dg;
  22676. },
  22677. createElementByHtml: function (html){
  22678. var el = document.createElement('div');
  22679. el.innerHTML = html;
  22680. el = el.firstChild;
  22681. el.parentNode.removeChild(el);
  22682. return el;
  22683. },
  22684. getViewportElement: function (){
  22685. return (browser.ie && browser.quirks) ?
  22686. document.body : document.documentElement;
  22687. },
  22688. getClientRect: function (element){
  22689. var bcr;
  22690. //trace IE6下在控制编辑器显隐时可能会报错,catch一下
  22691. try{
  22692. bcr = element.getBoundingClientRect();
  22693. }catch(e){
  22694. bcr={left:0,top:0,height:0,width:0}
  22695. }
  22696. var rect = {
  22697. left: Math.round(bcr.left),
  22698. top: Math.round(bcr.top),
  22699. height: Math.round(bcr.bottom - bcr.top),
  22700. width: Math.round(bcr.right - bcr.left)
  22701. };
  22702. var doc;
  22703. while ((doc = element.ownerDocument) !== document &&
  22704. (element = domUtils.getWindow(doc).frameElement)) {
  22705. bcr = element.getBoundingClientRect();
  22706. rect.left += bcr.left;
  22707. rect.top += bcr.top;
  22708. }
  22709. rect.bottom = rect.top + rect.height;
  22710. rect.right = rect.left + rect.width;
  22711. return rect;
  22712. },
  22713. getViewportRect: function (){
  22714. var viewportEl = uiUtils.getViewportElement();
  22715. var width = (window.innerWidth || viewportEl.clientWidth) | 0;
  22716. var height = (window.innerHeight ||viewportEl.clientHeight) | 0;
  22717. return {
  22718. left: 0,
  22719. top: 0,
  22720. height: height,
  22721. width: width,
  22722. bottom: height,
  22723. right: width
  22724. };
  22725. },
  22726. setViewportOffset: function (element, offset){
  22727. var rect;
  22728. var fixedLayer = uiUtils.getFixedLayer();
  22729. if (element.parentNode === fixedLayer) {
  22730. element.style.left = offset.left + 'px';
  22731. element.style.top = offset.top + 'px';
  22732. } else {
  22733. domUtils.setViewportOffset(element, offset);
  22734. }
  22735. },
  22736. getEventOffset: function (evt){
  22737. var el = evt.target || evt.srcElement;
  22738. var rect = uiUtils.getClientRect(el);
  22739. var offset = uiUtils.getViewportOffsetByEvent(evt);
  22740. return {
  22741. left: offset.left - rect.left,
  22742. top: offset.top - rect.top
  22743. };
  22744. },
  22745. getViewportOffsetByEvent: function (evt){
  22746. var el = evt.target || evt.srcElement;
  22747. var frameEl = domUtils.getWindow(el).frameElement;
  22748. var offset = {
  22749. left: evt.clientX,
  22750. top: evt.clientY
  22751. };
  22752. if (frameEl && el.ownerDocument !== document) {
  22753. var rect = uiUtils.getClientRect(frameEl);
  22754. offset.left += rect.left;
  22755. offset.top += rect.top;
  22756. }
  22757. return offset;
  22758. },
  22759. setGlobal: function (id, obj){
  22760. root[id] = obj;
  22761. return magic + '["' + id + '"]';
  22762. },
  22763. unsetGlobal: function (id){
  22764. delete root[id];
  22765. },
  22766. copyAttributes: function (tgt, src){
  22767. var attributes = src.attributes;
  22768. var k = attributes.length;
  22769. while (k --) {
  22770. var attrNode = attributes[k];
  22771. if ( attrNode.nodeName != 'style' && attrNode.nodeName != 'class' && (!browser.ie || attrNode.specified) ) {
  22772. tgt.setAttribute(attrNode.nodeName, attrNode.nodeValue);
  22773. }
  22774. }
  22775. if (src.className) {
  22776. domUtils.addClass(tgt,src.className);
  22777. }
  22778. if (src.style.cssText) {
  22779. tgt.style.cssText += ';' + src.style.cssText;
  22780. }
  22781. },
  22782. removeStyle: function (el, styleName){
  22783. if (el.style.removeProperty) {
  22784. el.style.removeProperty(styleName);
  22785. } else if (el.style.removeAttribute) {
  22786. el.style.removeAttribute(styleName);
  22787. } else throw '';
  22788. },
  22789. contains: function (elA, elB){
  22790. return elA && elB && (elA === elB ? false : (
  22791. elA.contains ? elA.contains(elB) :
  22792. elA.compareDocumentPosition(elB) & 16
  22793. ));
  22794. },
  22795. startDrag: function (evt, callbacks,doc){
  22796. var doc = doc || document;
  22797. var startX = evt.clientX;
  22798. var startY = evt.clientY;
  22799. function handleMouseMove(evt){
  22800. var x = evt.clientX - startX;
  22801. var y = evt.clientY - startY;
  22802. callbacks.ondragmove(x, y,evt);
  22803. if (evt.stopPropagation) {
  22804. evt.stopPropagation();
  22805. } else {
  22806. evt.cancelBubble = true;
  22807. }
  22808. }
  22809. if (doc.addEventListener) {
  22810. function handleMouseUp(evt){
  22811. doc.removeEventListener('mousemove', handleMouseMove, true);
  22812. doc.removeEventListener('mouseup', handleMouseUp, true);
  22813. window.removeEventListener('mouseup', handleMouseUp, true);
  22814. callbacks.ondragstop();
  22815. }
  22816. doc.addEventListener('mousemove', handleMouseMove, true);
  22817. doc.addEventListener('mouseup', handleMouseUp, true);
  22818. window.addEventListener('mouseup', handleMouseUp, true);
  22819. evt.preventDefault();
  22820. } else {
  22821. var elm = evt.srcElement;
  22822. elm.setCapture();
  22823. function releaseCaptrue(){
  22824. elm.releaseCapture();
  22825. elm.detachEvent('onmousemove', handleMouseMove);
  22826. elm.detachEvent('onmouseup', releaseCaptrue);
  22827. elm.detachEvent('onlosecaptrue', releaseCaptrue);
  22828. callbacks.ondragstop();
  22829. }
  22830. elm.attachEvent('onmousemove', handleMouseMove);
  22831. elm.attachEvent('onmouseup', releaseCaptrue);
  22832. elm.attachEvent('onlosecaptrue', releaseCaptrue);
  22833. evt.returnValue = false;
  22834. }
  22835. callbacks.ondragstart();
  22836. },
  22837. getFixedLayer: function (){
  22838. var layer = document.getElementById('edui_fixedlayer');
  22839. if (layer == null) {
  22840. layer = document.createElement('div');
  22841. layer.id = 'edui_fixedlayer';
  22842. document.body.appendChild(layer);
  22843. if (browser.ie && browser.version <= 8) {
  22844. layer.style.position = 'absolute';
  22845. bindFixedLayer();
  22846. setTimeout(updateFixedOffset);
  22847. } else {
  22848. layer.style.position = 'fixed';
  22849. }
  22850. layer.style.left = '0';
  22851. layer.style.top = '0';
  22852. layer.style.width = '0';
  22853. layer.style.height = '0';
  22854. }
  22855. return layer;
  22856. },
  22857. makeUnselectable: function (element){
  22858. if (browser.opera || (browser.ie && browser.version < 9)) {
  22859. element.unselectable = 'on';
  22860. if (element.hasChildNodes()) {
  22861. for (var i=0; i<element.childNodes.length; i++) {
  22862. if (element.childNodes[i].nodeType == 1) {
  22863. uiUtils.makeUnselectable(element.childNodes[i]);
  22864. }
  22865. }
  22866. }
  22867. } else {
  22868. if (element.style.MozUserSelect !== undefined) {
  22869. element.style.MozUserSelect = 'none';
  22870. } else if (element.style.WebkitUserSelect !== undefined) {
  22871. element.style.WebkitUserSelect = 'none';
  22872. } else if (element.style.KhtmlUserSelect !== undefined) {
  22873. element.style.KhtmlUserSelect = 'none';
  22874. }
  22875. }
  22876. }
  22877. };
  22878. function updateFixedOffset(){
  22879. var layer = document.getElementById('edui_fixedlayer');
  22880. uiUtils.setViewportOffset(layer, {
  22881. left: 0,
  22882. top: 0
  22883. });
  22884. // layer.style.display = 'none';
  22885. // layer.style.display = 'block';
  22886. //#trace: 1354
  22887. // setTimeout(updateFixedOffset);
  22888. }
  22889. function bindFixedLayer(adjOffset){
  22890. domUtils.on(window, 'scroll', updateFixedOffset);
  22891. domUtils.on(window, 'resize', baidu.editor.utils.defer(updateFixedOffset, 0, true));
  22892. }
  22893. })();
  22894. // js/editor/_src/ui/uibase.js
  22895. (function () {
  22896. var utils = baidu.editor.utils,
  22897. uiUtils = baidu.editor.ui.uiUtils,
  22898. EventBase = baidu.editor.EventBase,
  22899. UIBase = baidu.editor.ui.UIBase = function () {
  22900. };
  22901. UIBase.prototype = {
  22902. className:'',
  22903. uiName:'',
  22904. initOptions:function (options) {
  22905. var me = this;
  22906. for (var k in options) {
  22907. me[k] = options[k];
  22908. }
  22909. this.id = this.id || 'edui' + uiUtils.uid();
  22910. },
  22911. initUIBase:function () {
  22912. this._globalKey = utils.unhtml(uiUtils.setGlobal(this.id, this));
  22913. },
  22914. render:function (holder) {
  22915. var html = this.renderHtml();
  22916. var el = uiUtils.createElementByHtml(html);
  22917. //by xuheng 给每个node添加class
  22918. var list = domUtils.getElementsByTagName(el, "*");
  22919. var theme = "edui-" + (this.theme || this.editor.options.theme);
  22920. var layer = document.getElementById('edui_fixedlayer');
  22921. for (var i = 0, node; node = list[i++];) {
  22922. domUtils.addClass(node, theme);
  22923. }
  22924. domUtils.addClass(el, theme);
  22925. if(layer){
  22926. layer.className="";
  22927. domUtils.addClass(layer,theme);
  22928. }
  22929. var seatEl = this.getDom();
  22930. if (seatEl != null) {
  22931. seatEl.parentNode.replaceChild(el, seatEl);
  22932. uiUtils.copyAttributes(el, seatEl);
  22933. } else {
  22934. if (typeof holder == 'string') {
  22935. holder = document.getElementById(holder);
  22936. }
  22937. holder = holder || uiUtils.getFixedLayer();
  22938. domUtils.addClass(holder, theme);
  22939. holder.appendChild(el);
  22940. }
  22941. this.postRender();
  22942. },
  22943. getDom:function (name) {
  22944. if (!name) {
  22945. return document.getElementById(this.id);
  22946. } else {
  22947. return document.getElementById(this.id + '_' + name);
  22948. }
  22949. },
  22950. postRender:function () {
  22951. this.fireEvent('postrender');
  22952. },
  22953. getHtmlTpl:function () {
  22954. return '';
  22955. },
  22956. formatHtml:function (tpl) {
  22957. var prefix = 'edui-' + this.uiName;
  22958. return (tpl
  22959. .replace(/##/g, this.id)
  22960. .replace(/%%-/g, this.uiName ? prefix + '-' : '')
  22961. .replace(/%%/g, (this.uiName ? prefix : '') + ' ' + this.className)
  22962. .replace(/\$\$/g, this._globalKey));
  22963. },
  22964. renderHtml:function () {
  22965. return this.formatHtml(this.getHtmlTpl());
  22966. },
  22967. dispose:function () {
  22968. var box = this.getDom();
  22969. if (box) baidu.editor.dom.domUtils.remove(box);
  22970. uiUtils.unsetGlobal(this.id);
  22971. }
  22972. };
  22973. utils.inherits(UIBase, EventBase);
  22974. })();
  22975. // js/editor/_src/ui/separator.js
  22976. (function (){
  22977. var utils = baidu.editor.utils,
  22978. UIBase = baidu.editor.ui.UIBase,
  22979. Separator = baidu.editor.ui.Separator = function (options){
  22980. this.initOptions(options);
  22981. this.initSeparator();
  22982. };
  22983. Separator.prototype = {
  22984. uiName: 'separator',
  22985. initSeparator: function (){
  22986. this.initUIBase();
  22987. },
  22988. getHtmlTpl: function (){
  22989. return '<div id="##" class="edui-box %%"></div>';
  22990. }
  22991. };
  22992. utils.inherits(Separator, UIBase);
  22993. })();
  22994. // js/editor/_src/ui/mask.js
  22995. ///import core
  22996. ///import uicore
  22997. (function (){
  22998. var utils = baidu.editor.utils,
  22999. domUtils = baidu.editor.dom.domUtils,
  23000. UIBase = baidu.editor.ui.UIBase,
  23001. uiUtils = baidu.editor.ui.uiUtils;
  23002. var Mask = baidu.editor.ui.Mask = function (options){
  23003. this.initOptions(options);
  23004. this.initUIBase();
  23005. };
  23006. Mask.prototype = {
  23007. getHtmlTpl: function (){
  23008. return '<div id="##" class="edui-mask %%" onclick="return $$._onClick(event, this);" onmousedown="return $$._onMouseDown(event, this);"></div>';
  23009. },
  23010. postRender: function (){
  23011. var me = this;
  23012. domUtils.on(window, 'resize', function (){
  23013. setTimeout(function (){
  23014. if (!me.isHidden()) {
  23015. me._fill();
  23016. }
  23017. });
  23018. });
  23019. },
  23020. show: function (zIndex){
  23021. this._fill();
  23022. this.getDom().style.display = '';
  23023. this.getDom().style.zIndex = zIndex;
  23024. },
  23025. hide: function (){
  23026. this.getDom().style.display = 'none';
  23027. this.getDom().style.zIndex = '';
  23028. },
  23029. isHidden: function (){
  23030. return this.getDom().style.display == 'none';
  23031. },
  23032. _onMouseDown: function (){
  23033. return false;
  23034. },
  23035. _onClick: function (e, target){
  23036. this.fireEvent('click', e, target);
  23037. },
  23038. _fill: function (){
  23039. var el = this.getDom();
  23040. var vpRect = uiUtils.getViewportRect();
  23041. el.style.width = vpRect.width + 'px';
  23042. el.style.height = vpRect.height + 'px';
  23043. }
  23044. };
  23045. utils.inherits(Mask, UIBase);
  23046. })();
  23047. // js/editor/_src/ui/popup.js
  23048. ///import core
  23049. ///import uicore
  23050. (function () {
  23051. var utils = baidu.editor.utils,
  23052. uiUtils = baidu.editor.ui.uiUtils,
  23053. domUtils = baidu.editor.dom.domUtils,
  23054. UIBase = baidu.editor.ui.UIBase,
  23055. Popup = baidu.editor.ui.Popup = function (options){
  23056. this.initOptions(options);
  23057. this.initPopup();
  23058. };
  23059. var allPopups = [];
  23060. function closeAllPopup( evt,el ){
  23061. for ( var i = 0; i < allPopups.length; i++ ) {
  23062. var pop = allPopups[i];
  23063. if (!pop.isHidden()) {
  23064. if (pop.queryAutoHide(el) !== false) {
  23065. if(evt&&/scroll/ig.test(evt.type)&&pop.className=="edui-wordpastepop") return;
  23066. pop.hide();
  23067. }
  23068. }
  23069. }
  23070. if(allPopups.length)
  23071. pop.editor.fireEvent("afterhidepop");
  23072. }
  23073. Popup.postHide = closeAllPopup;
  23074. var ANCHOR_CLASSES = ['edui-anchor-topleft','edui-anchor-topright',
  23075. 'edui-anchor-bottomleft','edui-anchor-bottomright'];
  23076. Popup.prototype = {
  23077. SHADOW_RADIUS: 5,
  23078. content: null,
  23079. _hidden: false,
  23080. autoRender: true,
  23081. canSideLeft: true,
  23082. canSideUp: true,
  23083. initPopup: function (){
  23084. this.initUIBase();
  23085. allPopups.push( this );
  23086. },
  23087. getHtmlTpl: function (){
  23088. return '<div id="##" class="edui-popup %%" onmousedown="return false;">' +
  23089. ' <div id="##_body" class="edui-popup-body">' +
  23090. ' <iframe style="position:absolute;z-index:-1;left:0;top:0;background-color: transparent;" frameborder="0" width="100%" height="100%" src="about:blank"></iframe>' +
  23091. ' <div class="edui-shadow"></div>' +
  23092. ' <div id="##_content" class="edui-popup-content">' +
  23093. this.getContentHtmlTpl() +
  23094. ' </div>' +
  23095. ' </div>' +
  23096. '</div>';
  23097. },
  23098. getContentHtmlTpl: function (){
  23099. if(this.content){
  23100. if (typeof this.content == 'string') {
  23101. return this.content;
  23102. }
  23103. return this.content.renderHtml();
  23104. }else{
  23105. return ''
  23106. }
  23107. },
  23108. _UIBase_postRender: UIBase.prototype.postRender,
  23109. postRender: function (){
  23110. if (this.content instanceof UIBase) {
  23111. this.content.postRender();
  23112. }
  23113. //捕获鼠标滚轮
  23114. if( this.captureWheel && !this.captured ) {
  23115. this.captured = true;
  23116. var winHeight = ( document.documentElement.clientHeight || document.body.clientHeight ) - 80,
  23117. _height = this.getDom().offsetHeight,
  23118. _top = uiUtils.getClientRect( this.combox.getDom() ).top,
  23119. content = this.getDom('content'),
  23120. ifr = this.getDom('body').getElementsByTagName('iframe'),
  23121. me = this;
  23122. ifr.length && ( ifr = ifr[0] );
  23123. while( _top + _height > winHeight ) {
  23124. _height -= 30;
  23125. }
  23126. content.style.height = _height + 'px';
  23127. //同步更改iframe高度
  23128. ifr && ( ifr.style.height = _height + 'px' );
  23129. //阻止在combox上的鼠标滚轮事件, 防止用户的正常操作被误解
  23130. if( window.XMLHttpRequest ) {
  23131. domUtils.on( content, ( 'onmousewheel' in document.body ) ? 'mousewheel' :'DOMMouseScroll' , function(e){
  23132. if(e.preventDefault) {
  23133. e.preventDefault();
  23134. } else {
  23135. e.returnValue = false;
  23136. }
  23137. if( e.wheelDelta ) {
  23138. content.scrollTop -= ( e.wheelDelta / 120 )*60;
  23139. } else {
  23140. content.scrollTop -= ( e.detail / -3 )*60;
  23141. }
  23142. });
  23143. } else {
  23144. //ie6
  23145. domUtils.on( this.getDom(), 'mousewheel' , function(e){
  23146. e.returnValue = false;
  23147. me.getDom('content').scrollTop -= ( e.wheelDelta / 120 )*60;
  23148. });
  23149. }
  23150. }
  23151. this.fireEvent('postRenderAfter');
  23152. this.hide(true);
  23153. this._UIBase_postRender();
  23154. },
  23155. _doAutoRender: function (){
  23156. if (!this.getDom() && this.autoRender) {
  23157. this.render();
  23158. }
  23159. },
  23160. mesureSize: function (){
  23161. var box = this.getDom('content');
  23162. return uiUtils.getClientRect(box);
  23163. },
  23164. fitSize: function (){
  23165. if( this.captureWheel && this.sized ) {
  23166. return this.__size;
  23167. }
  23168. this.sized = true;
  23169. var popBodyEl = this.getDom('body');
  23170. popBodyEl.style.width = '';
  23171. popBodyEl.style.height = '';
  23172. var size = this.mesureSize();
  23173. if( this.captureWheel ) {
  23174. popBodyEl.style.width = -(-20 -size.width) + 'px';
  23175. var height = parseInt( this.getDom('content').style.height, 10 );
  23176. !window.isNaN( height ) && ( size.height = height );
  23177. } else {
  23178. popBodyEl.style.width = size.width + 'px';
  23179. }
  23180. popBodyEl.style.height = size.height + 'px';
  23181. this.__size = size;
  23182. this.captureWheel && (this.getDom('content').style.overflow = 'auto');
  23183. return size;
  23184. },
  23185. showAnchor: function ( element, hoz ){
  23186. this.showAnchorRect( uiUtils.getClientRect( element ), hoz );
  23187. },
  23188. showAnchorRect: function ( rect, hoz, adj ){
  23189. this._doAutoRender();
  23190. var vpRect = uiUtils.getViewportRect();
  23191. this.getDom().style.visibility = 'hidden';
  23192. this._show();
  23193. var popSize = this.fitSize();
  23194. var sideLeft, sideUp, left, top;
  23195. if (hoz) {
  23196. sideLeft = this.canSideLeft && (rect.right + popSize.width > vpRect.right && rect.left > popSize.width);
  23197. sideUp = this.canSideUp && (rect.top + popSize.height > vpRect.bottom && rect.bottom > popSize.height);
  23198. left = (sideLeft ? rect.left - popSize.width : rect.right);
  23199. top = (sideUp ? rect.bottom - popSize.height : rect.top);
  23200. } else {
  23201. sideLeft = this.canSideLeft && (rect.right + popSize.width > vpRect.right && rect.left > popSize.width);
  23202. sideUp = this.canSideUp && (rect.top + popSize.height > vpRect.bottom && rect.bottom > popSize.height);
  23203. left = (sideLeft ? rect.right - popSize.width : rect.left);
  23204. top = (sideUp ? rect.top - popSize.height : rect.bottom);
  23205. }
  23206. var popEl = this.getDom();
  23207. uiUtils.setViewportOffset(popEl, {
  23208. left: left,
  23209. top: top
  23210. });
  23211. domUtils.removeClasses(popEl, ANCHOR_CLASSES);
  23212. popEl.className += ' ' + ANCHOR_CLASSES[(sideUp ? 1 : 0) * 2 + (sideLeft ? 1 : 0)];
  23213. if(this.editor){
  23214. popEl.style.zIndex = this.editor.container.style.zIndex * 1 + 10;
  23215. baidu.editor.ui.uiUtils.getFixedLayer().style.zIndex = popEl.style.zIndex - 1;
  23216. }
  23217. this.getDom().style.visibility = 'visible';
  23218. },
  23219. showAt: function (offset) {
  23220. var left = offset.left;
  23221. var top = offset.top;
  23222. var rect = {
  23223. left: left,
  23224. top: top,
  23225. right: left,
  23226. bottom: top,
  23227. height: 0,
  23228. width: 0
  23229. };
  23230. this.showAnchorRect(rect, false, true);
  23231. },
  23232. _show: function (){
  23233. if (this._hidden) {
  23234. var box = this.getDom();
  23235. box.style.display = '';
  23236. this._hidden = false;
  23237. // if (box.setActive) {
  23238. // box.setActive();
  23239. // }
  23240. this.fireEvent('show');
  23241. }
  23242. },
  23243. isHidden: function (){
  23244. return this._hidden;
  23245. },
  23246. show: function (){
  23247. this._doAutoRender();
  23248. this._show();
  23249. },
  23250. hide: function (notNofity){
  23251. if (!this._hidden && this.getDom()) {
  23252. this.getDom().style.display = 'none';
  23253. this._hidden = true;
  23254. if (!notNofity) {
  23255. this.fireEvent('hide');
  23256. }
  23257. }
  23258. },
  23259. queryAutoHide: function (el){
  23260. return !el || !uiUtils.contains(this.getDom(), el);
  23261. }
  23262. };
  23263. utils.inherits(Popup, UIBase);
  23264. domUtils.on( document, 'mousedown', function ( evt ) {
  23265. var el = evt.target || evt.srcElement;
  23266. closeAllPopup( evt,el );
  23267. } );
  23268. domUtils.on( window, 'scroll', function (evt,el) {
  23269. closeAllPopup( evt,el );
  23270. } );
  23271. })();
  23272. // js/editor/_src/ui/colorpicker.js
  23273. ///import core
  23274. ///import uicore
  23275. (function (){
  23276. var utils = baidu.editor.utils,
  23277. UIBase = baidu.editor.ui.UIBase,
  23278. ColorPicker = baidu.editor.ui.ColorPicker = function (options){
  23279. this.initOptions(options);
  23280. this.noColorText = this.noColorText || this.editor.getLang("clearColor");
  23281. this.initUIBase();
  23282. };
  23283. ColorPicker.prototype = {
  23284. getHtmlTpl: function (){
  23285. return genColorPicker(this.noColorText,this.editor);
  23286. },
  23287. _onTableClick: function (evt){
  23288. var tgt = evt.target || evt.srcElement;
  23289. var color = tgt.getAttribute('data-color');
  23290. if (color) {
  23291. this.fireEvent('pickcolor', color);
  23292. }
  23293. },
  23294. _onTableOver: function (evt){
  23295. var tgt = evt.target || evt.srcElement;
  23296. var color = tgt.getAttribute('data-color');
  23297. if (color) {
  23298. this.getDom('preview').style.backgroundColor = color;
  23299. }
  23300. },
  23301. _onTableOut: function (){
  23302. this.getDom('preview').style.backgroundColor = '';
  23303. },
  23304. _onPickNoColor: function (){
  23305. this.fireEvent('picknocolor');
  23306. }
  23307. };
  23308. utils.inherits(ColorPicker, UIBase);
  23309. var COLORS = (
  23310. 'ffffff,000000,eeece1,1f497d,4f81bd,c0504d,9bbb59,8064a2,4bacc6,f79646,' +
  23311. 'f2f2f2,7f7f7f,ddd9c3,c6d9f0,dbe5f1,f2dcdb,ebf1dd,e5e0ec,dbeef3,fdeada,' +
  23312. 'd8d8d8,595959,c4bd97,8db3e2,b8cce4,e5b9b7,d7e3bc,ccc1d9,b7dde8,fbd5b5,' +
  23313. 'bfbfbf,3f3f3f,938953,548dd4,95b3d7,d99694,c3d69b,b2a2c7,92cddc,fac08f,' +
  23314. 'a5a5a5,262626,494429,17365d,366092,953734,76923c,5f497a,31859b,e36c09,' +
  23315. '7f7f7f,0c0c0c,1d1b10,0f243e,244061,632423,4f6128,3f3151,205867,974806,' +
  23316. 'c00000,ff0000,ffc000,ffff00,92d050,00b050,00b0f0,0070c0,002060,7030a0,').split(',');
  23317. function genColorPicker(noColorText,editor){
  23318. var html = '<div id="##" class="edui-colorpicker %%">' +
  23319. '<div class="edui-colorpicker-topbar edui-clearfix">' +
  23320. '<div unselectable="on" id="##_preview" class="edui-colorpicker-preview"></div>' +
  23321. '<div unselectable="on" class="edui-colorpicker-nocolor" onclick="$$._onPickNoColor(event, this);">'+ noColorText +'</div>' +
  23322. '</div>' +
  23323. '<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">' +
  23324. '<tr style="border-bottom: 1px solid #ddd;font-size: 13px;line-height: 25px;color:#39C;padding-top: 2px"><td colspan="10">'+editor.getLang("themeColor")+'</td> </tr>'+
  23325. '<tr class="edui-colorpicker-tablefirstrow" >';
  23326. for (var i=0; i<COLORS.length; i++) {
  23327. if (i && i%10 === 0) {
  23328. html += '</tr>'+(i==60?'<tr style="border-bottom: 1px solid #ddd;font-size: 13px;line-height: 25px;color:#39C;"><td colspan="10">'+editor.getLang("standardColor")+'</td></tr>':'')+'<tr'+(i==60?' class="edui-colorpicker-tablefirstrow"':'')+'>';
  23329. }
  23330. html += i<70 ? '<td style="padding: 0 2px;"><a hidefocus title="'+COLORS[i]+'" onclick="return false;" href="javascript:" unselectable="on" class="edui-box edui-colorpicker-colorcell"' +
  23331. ' data-color="#'+ COLORS[i] +'"'+
  23332. ' style="background-color:#'+ COLORS[i] +';border:solid #ccc;'+
  23333. (i<10 || i>=60?'border-width:1px;':
  23334. i>=10&&i<20?'border-width:1px 1px 0 1px;':
  23335. 'border-width:0 1px 0 1px;')+
  23336. '"' +
  23337. '></a></td>':'';
  23338. }
  23339. html += '</tr></table></div>';
  23340. return html;
  23341. }
  23342. })();
  23343. // js/editor/_src/ui/tablepicker.js
  23344. ///import core
  23345. ///import uicore
  23346. (function (){
  23347. var utils = baidu.editor.utils,
  23348. uiUtils = baidu.editor.ui.uiUtils,
  23349. UIBase = baidu.editor.ui.UIBase;
  23350. var TablePicker = baidu.editor.ui.TablePicker = function (options){
  23351. this.initOptions(options);
  23352. this.initTablePicker();
  23353. };
  23354. TablePicker.prototype = {
  23355. defaultNumRows: 10,
  23356. defaultNumCols: 10,
  23357. maxNumRows: 20,
  23358. maxNumCols: 20,
  23359. numRows: 10,
  23360. numCols: 10,
  23361. lengthOfCellSide: 22,
  23362. initTablePicker: function (){
  23363. this.initUIBase();
  23364. },
  23365. getHtmlTpl: function (){
  23366. var me = this;
  23367. return '<div id="##" class="edui-tablepicker %%">' +
  23368. '<div class="edui-tablepicker-body">' +
  23369. '<div class="edui-infoarea">' +
  23370. '<span id="##_label" class="edui-label"></span>' +
  23371. '</div>' +
  23372. '<div class="edui-pickarea"' +
  23373. ' onmousemove="$$._onMouseMove(event, this);"' +
  23374. ' onmouseover="$$._onMouseOver(event, this);"' +
  23375. ' onmouseout="$$._onMouseOut(event, this);"' +
  23376. ' onclick="$$._onClick(event, this);"' +
  23377. '>' +
  23378. '<div id="##_overlay" class="edui-overlay"></div>' +
  23379. '</div>' +
  23380. '</div>' +
  23381. '</div>';
  23382. },
  23383. _UIBase_render: UIBase.prototype.render,
  23384. render: function (holder){
  23385. this._UIBase_render(holder);
  23386. this.getDom('label').innerHTML = '0'+this.editor.getLang("t_row")+' x 0'+this.editor.getLang("t_col");
  23387. },
  23388. _track: function (numCols, numRows){
  23389. var style = this.getDom('overlay').style;
  23390. var sideLen = this.lengthOfCellSide;
  23391. style.width = numCols * sideLen + 'px';
  23392. style.height = numRows * sideLen + 'px';
  23393. var label = this.getDom('label');
  23394. label.innerHTML = numCols +this.editor.getLang("t_col")+' x ' + numRows + this.editor.getLang("t_row");
  23395. this.numCols = numCols;
  23396. this.numRows = numRows;
  23397. },
  23398. _onMouseOver: function (evt, el){
  23399. var rel = evt.relatedTarget || evt.fromElement;
  23400. if (!uiUtils.contains(el, rel) && el !== rel) {
  23401. this.getDom('label').innerHTML = '0'+this.editor.getLang("t_col")+' x 0'+this.editor.getLang("t_row");
  23402. this.getDom('overlay').style.visibility = '';
  23403. }
  23404. },
  23405. _onMouseOut: function (evt, el){
  23406. var rel = evt.relatedTarget || evt.toElement;
  23407. if (!uiUtils.contains(el, rel) && el !== rel) {
  23408. this.getDom('label').innerHTML = '0'+this.editor.getLang("t_col")+' x 0'+this.editor.getLang("t_row");
  23409. this.getDom('overlay').style.visibility = 'hidden';
  23410. }
  23411. },
  23412. _onMouseMove: function (evt, el){
  23413. var style = this.getDom('overlay').style;
  23414. var offset = uiUtils.getEventOffset(evt);
  23415. var sideLen = this.lengthOfCellSide;
  23416. var numCols = Math.ceil(offset.left / sideLen);
  23417. var numRows = Math.ceil(offset.top / sideLen);
  23418. this._track(numCols, numRows);
  23419. },
  23420. _onClick: function (){
  23421. this.fireEvent('picktable', this.numCols, this.numRows);
  23422. }
  23423. };
  23424. utils.inherits(TablePicker, UIBase);
  23425. })();
  23426. // js/editor/_src/ui/stateful.js
  23427. (function (){
  23428. var browser = baidu.editor.browser,
  23429. domUtils = baidu.editor.dom.domUtils,
  23430. uiUtils = baidu.editor.ui.uiUtils;
  23431. var TPL_STATEFUL = 'onmousedown="$$.Stateful_onMouseDown(event, this);"' +
  23432. ' onmouseup="$$.Stateful_onMouseUp(event, this);"' +
  23433. ( browser.ie ? (
  23434. ' onmouseenter="$$.Stateful_onMouseEnter(event, this);"' +
  23435. ' onmouseleave="$$.Stateful_onMouseLeave(event, this);"' )
  23436. : (
  23437. ' onmouseover="$$.Stateful_onMouseOver(event, this);"' +
  23438. ' onmouseout="$$.Stateful_onMouseOut(event, this);"' ));
  23439. baidu.editor.ui.Stateful = {
  23440. alwalysHoverable: false,
  23441. target:null,//目标元素和this指向dom不一样
  23442. Stateful_init: function (){
  23443. this._Stateful_dGetHtmlTpl = this.getHtmlTpl;
  23444. this.getHtmlTpl = this.Stateful_getHtmlTpl;
  23445. },
  23446. Stateful_getHtmlTpl: function (){
  23447. var tpl = this._Stateful_dGetHtmlTpl();
  23448. // 使用function避免$转义
  23449. return tpl.replace(/stateful/g, function (){ return TPL_STATEFUL; });
  23450. },
  23451. Stateful_onMouseEnter: function (evt, el){
  23452. this.target=el;
  23453. if (!this.isDisabled() || this.alwalysHoverable) {
  23454. this.addState('hover');
  23455. this.fireEvent('over');
  23456. }
  23457. },
  23458. Stateful_onMouseLeave: function (evt, el){
  23459. if (!this.isDisabled() || this.alwalysHoverable) {
  23460. this.removeState('hover');
  23461. this.removeState('active');
  23462. this.fireEvent('out');
  23463. }
  23464. },
  23465. Stateful_onMouseOver: function (evt, el){
  23466. var rel = evt.relatedTarget;
  23467. if (!uiUtils.contains(el, rel) && el !== rel) {
  23468. this.Stateful_onMouseEnter(evt, el);
  23469. }
  23470. },
  23471. Stateful_onMouseOut: function (evt, el){
  23472. var rel = evt.relatedTarget;
  23473. if (!uiUtils.contains(el, rel) && el !== rel) {
  23474. this.Stateful_onMouseLeave(evt, el);
  23475. }
  23476. },
  23477. Stateful_onMouseDown: function (evt, el){
  23478. if (!this.isDisabled()) {
  23479. this.addState('active');
  23480. }
  23481. },
  23482. Stateful_onMouseUp: function (evt, el){
  23483. if (!this.isDisabled()) {
  23484. this.removeState('active');
  23485. }
  23486. },
  23487. Stateful_postRender: function (){
  23488. if (this.disabled && !this.hasState('disabled')) {
  23489. this.addState('disabled');
  23490. }
  23491. },
  23492. hasState: function (state){
  23493. return domUtils.hasClass(this.getStateDom(), 'edui-state-' + state);
  23494. },
  23495. addState: function (state){
  23496. if (!this.hasState(state)) {
  23497. this.getStateDom().className += ' edui-state-' + state;
  23498. }
  23499. },
  23500. removeState: function (state){
  23501. if (this.hasState(state)) {
  23502. domUtils.removeClasses(this.getStateDom(), ['edui-state-' + state]);
  23503. }
  23504. },
  23505. getStateDom: function (){
  23506. return this.getDom('state');
  23507. },
  23508. isChecked: function (){
  23509. return this.hasState('checked');
  23510. },
  23511. setChecked: function (checked){
  23512. if (!this.isDisabled() && checked) {
  23513. this.addState('checked');
  23514. } else {
  23515. this.removeState('checked');
  23516. }
  23517. },
  23518. isDisabled: function (){
  23519. return this.hasState('disabled');
  23520. },
  23521. setDisabled: function (disabled){
  23522. if (disabled) {
  23523. this.removeState('hover');
  23524. this.removeState('checked');
  23525. this.removeState('active');
  23526. this.addState('disabled');
  23527. } else {
  23528. this.removeState('disabled');
  23529. }
  23530. }
  23531. };
  23532. })();
  23533. // js/editor/_src/ui/button.js
  23534. ///import core
  23535. ///import uicore
  23536. ///import ui/stateful.js
  23537. (function (){
  23538. var utils = baidu.editor.utils,
  23539. UIBase = baidu.editor.ui.UIBase,
  23540. Stateful = baidu.editor.ui.Stateful,
  23541. Button = baidu.editor.ui.Button = function (options){
  23542. if(options.name){
  23543. var btnName = options.name;
  23544. var cssRules = options.cssRules;
  23545. if(!options.className){
  23546. options.className = 'edui-for-' + btnName;
  23547. }
  23548. options.cssRules = '.edui-default .edui-for-'+ btnName +' .edui-icon {'+ cssRules +'}'
  23549. }
  23550. this.initOptions(options);
  23551. this.initButton();
  23552. };
  23553. Button.prototype = {
  23554. uiName: 'button',
  23555. label: '',
  23556. title: '',
  23557. showIcon: true,
  23558. showText: true,
  23559. cssRules:'',
  23560. initButton: function (){
  23561. this.initUIBase();
  23562. this.Stateful_init();
  23563. if(this.cssRules){
  23564. utils.cssRule('edui-customize-'+this.name+'-style',this.cssRules);
  23565. }
  23566. },
  23567. getHtmlTpl: function (){
  23568. return '<div id="##" class="edui-box %%">' +
  23569. '<div id="##_state" stateful>' +
  23570. '<div class="%%-wrap"><div id="##_body" unselectable="on" ' + (this.title ? 'title="' + this.title + '"' : '') +
  23571. ' class="%%-body" onmousedown="return $$._onMouseDown(event, this);" onclick="return $$._onClick(event, this);">' +
  23572. (this.showIcon ? '<div class="edui-box edui-icon"></div>' : '') +
  23573. (this.showText ? '<div class="edui-box edui-label">' + this.label + '</div>' : '') +
  23574. '</div>' +
  23575. '</div>' +
  23576. '</div></div>';
  23577. },
  23578. postRender: function (){
  23579. this.Stateful_postRender();
  23580. this.setDisabled(this.disabled)
  23581. },
  23582. _onMouseDown: function (e){
  23583. var target = e.target || e.srcElement,
  23584. tagName = target && target.tagName && target.tagName.toLowerCase();
  23585. if (tagName == 'input' || tagName == 'object' || tagName == 'object') {
  23586. return false;
  23587. }
  23588. },
  23589. _onClick: function (){
  23590. if (!this.isDisabled()) {
  23591. this.fireEvent('click');
  23592. }
  23593. },
  23594. setTitle: function(text){
  23595. var label = this.getDom('label');
  23596. label.innerHTML = text;
  23597. }
  23598. };
  23599. utils.inherits(Button, UIBase);
  23600. utils.extend(Button.prototype, Stateful);
  23601. })();
  23602. // js/editor/_src/ui/splitbutton.js
  23603. ///import core
  23604. ///import uicore
  23605. ///import ui/stateful.js
  23606. (function (){
  23607. var utils = baidu.editor.utils,
  23608. uiUtils = baidu.editor.ui.uiUtils,
  23609. domUtils = baidu.editor.dom.domUtils,
  23610. UIBase = baidu.editor.ui.UIBase,
  23611. Stateful = baidu.editor.ui.Stateful,
  23612. SplitButton = baidu.editor.ui.SplitButton = function (options){
  23613. this.initOptions(options);
  23614. this.initSplitButton();
  23615. };
  23616. SplitButton.prototype = {
  23617. popup: null,
  23618. uiName: 'splitbutton',
  23619. title: '',
  23620. initSplitButton: function (){
  23621. this.initUIBase();
  23622. this.Stateful_init();
  23623. var me = this;
  23624. if (this.popup != null) {
  23625. var popup = this.popup;
  23626. this.popup = null;
  23627. this.setPopup(popup);
  23628. }
  23629. },
  23630. _UIBase_postRender: UIBase.prototype.postRender,
  23631. postRender: function (){
  23632. this.Stateful_postRender();
  23633. this._UIBase_postRender();
  23634. },
  23635. setPopup: function (popup){
  23636. if (this.popup === popup) return;
  23637. if (this.popup != null) {
  23638. this.popup.dispose();
  23639. }
  23640. popup.addListener('show', utils.bind(this._onPopupShow, this));
  23641. popup.addListener('hide', utils.bind(this._onPopupHide, this));
  23642. popup.addListener('postrender', utils.bind(function (){
  23643. popup.getDom('body').appendChild(
  23644. uiUtils.createElementByHtml('<div id="' +
  23645. this.popup.id + '_bordereraser" class="edui-bordereraser edui-background" style="width:' +
  23646. (uiUtils.getClientRect(this.getDom()).width + 20) + 'px"></div>')
  23647. );
  23648. popup.getDom().className += ' ' + this.className;
  23649. }, this));
  23650. this.popup = popup;
  23651. },
  23652. _onPopupShow: function (){
  23653. this.addState('opened');
  23654. },
  23655. _onPopupHide: function (){
  23656. this.removeState('opened');
  23657. },
  23658. getHtmlTpl: function (){
  23659. return '<div id="##" class="edui-box %%">' +
  23660. '<div '+ (this.title ? 'title="' + this.title + '"' : '') +' id="##_state" stateful><div class="%%-body">' +
  23661. '<div id="##_button_body" class="edui-box edui-button-body" onclick="$$._onButtonClick(event, this);">' +
  23662. '<div class="edui-box edui-icon"></div>' +
  23663. '</div>' +
  23664. '<div class="edui-box edui-splitborder"></div>' +
  23665. '<div class="edui-box edui-arrow" onclick="$$._onArrowClick();"></div>' +
  23666. '</div></div></div>';
  23667. },
  23668. showPopup: function (){
  23669. // 当popup往上弹出的时候,做特殊处理
  23670. var rect = uiUtils.getClientRect(this.getDom());
  23671. rect.top -= this.popup.SHADOW_RADIUS;
  23672. rect.height += this.popup.SHADOW_RADIUS;
  23673. this.popup.showAnchorRect(rect);
  23674. },
  23675. _onArrowClick: function (event, el){
  23676. if (!this.isDisabled()) {
  23677. this.showPopup();
  23678. }
  23679. },
  23680. _onButtonClick: function (){
  23681. if (!this.isDisabled()) {
  23682. this.fireEvent('buttonclick');
  23683. }
  23684. }
  23685. };
  23686. utils.inherits(SplitButton, UIBase);
  23687. utils.extend(SplitButton.prototype, Stateful, true);
  23688. })();
  23689. // js/editor/_src/ui/colorbutton.js
  23690. ///import core
  23691. ///import uicore
  23692. ///import ui/colorpicker.js
  23693. ///import ui/popup.js
  23694. ///import ui/splitbutton.js
  23695. (function (){
  23696. var utils = baidu.editor.utils,
  23697. uiUtils = baidu.editor.ui.uiUtils,
  23698. ColorPicker = baidu.editor.ui.ColorPicker,
  23699. Popup = baidu.editor.ui.Popup,
  23700. SplitButton = baidu.editor.ui.SplitButton,
  23701. ColorButton = baidu.editor.ui.ColorButton = function (options){
  23702. this.initOptions(options);
  23703. this.initColorButton();
  23704. };
  23705. ColorButton.prototype = {
  23706. initColorButton: function (){
  23707. var me = this;
  23708. this.popup = new Popup({
  23709. content: new ColorPicker({
  23710. noColorText: me.editor.getLang("clearColor"),
  23711. editor:me.editor,
  23712. onpickcolor: function (t, color){
  23713. me._onPickColor(color);
  23714. },
  23715. onpicknocolor: function (t, color){
  23716. me._onPickNoColor(color);
  23717. }
  23718. }),
  23719. editor:me.editor
  23720. });
  23721. this.initSplitButton();
  23722. },
  23723. _SplitButton_postRender: SplitButton.prototype.postRender,
  23724. postRender: function (){
  23725. this._SplitButton_postRender();
  23726. this.getDom('button_body').appendChild(
  23727. uiUtils.createElementByHtml('<div id="' + this.id + '_colorlump" class="edui-colorlump"></div>')
  23728. );
  23729. this.getDom().className += ' edui-colorbutton';
  23730. },
  23731. setColor: function (color){
  23732. this.getDom('colorlump').style.backgroundColor = color;
  23733. this.color = color;
  23734. },
  23735. _onPickColor: function (color){
  23736. if (this.fireEvent('pickcolor', color) !== false) {
  23737. this.setColor(color);
  23738. this.popup.hide();
  23739. }
  23740. },
  23741. _onPickNoColor: function (color){
  23742. if (this.fireEvent('picknocolor') !== false) {
  23743. this.popup.hide();
  23744. }
  23745. }
  23746. };
  23747. utils.inherits(ColorButton, SplitButton);
  23748. })();
  23749. // js/editor/_src/ui/tablebutton.js
  23750. ///import core
  23751. ///import uicore
  23752. ///import ui/popup.js
  23753. ///import ui/tablepicker.js
  23754. ///import ui/splitbutton.js
  23755. (function (){
  23756. var utils = baidu.editor.utils,
  23757. Popup = baidu.editor.ui.Popup,
  23758. TablePicker = baidu.editor.ui.TablePicker,
  23759. SplitButton = baidu.editor.ui.SplitButton,
  23760. TableButton = baidu.editor.ui.TableButton = function (options){
  23761. this.initOptions(options);
  23762. this.initTableButton();
  23763. };
  23764. TableButton.prototype = {
  23765. initTableButton: function (){
  23766. var me = this;
  23767. this.popup = new Popup({
  23768. content: new TablePicker({
  23769. editor:me.editor,
  23770. onpicktable: function (t, numCols, numRows){
  23771. me._onPickTable(numCols, numRows);
  23772. }
  23773. }),
  23774. 'editor':me.editor
  23775. });
  23776. this.initSplitButton();
  23777. },
  23778. _onPickTable: function (numCols, numRows){
  23779. if (this.fireEvent('picktable', numCols, numRows) !== false) {
  23780. this.popup.hide();
  23781. }
  23782. }
  23783. };
  23784. utils.inherits(TableButton, SplitButton);
  23785. })();
  23786. // js/editor/_src/ui/autotypesetpicker.js
  23787. ///import core
  23788. ///import uicore
  23789. (function () {
  23790. var utils = baidu.editor.utils,
  23791. UIBase = baidu.editor.ui.UIBase;
  23792. var AutoTypeSetPicker = baidu.editor.ui.AutoTypeSetPicker = function (options) {
  23793. this.initOptions(options);
  23794. this.initAutoTypeSetPicker();
  23795. };
  23796. AutoTypeSetPicker.prototype = {
  23797. initAutoTypeSetPicker:function () {
  23798. this.initUIBase();
  23799. },
  23800. getHtmlTpl:function () {
  23801. var me = this.editor,
  23802. opt = me.options.autotypeset,
  23803. lang = me.getLang("autoTypeSet");
  23804. var textAlignInputName = 'textAlignValue' + me.uid,
  23805. imageBlockInputName = 'imageBlockLineValue' + me.uid,
  23806. symbolConverInputName = 'symbolConverValue' + me.uid;
  23807. return '<div id="##" class="edui-autotypesetpicker %%">' +
  23808. '<div class="edui-autotypesetpicker-body">' +
  23809. '<table >' +
  23810. '<tr><td nowrap><input type="checkbox" name="mergeEmptyline" ' + (opt["mergeEmptyline"] ? "checked" : "" ) + '>' + lang.mergeLine + '</td><td colspan="2"><input type="checkbox" name="removeEmptyline" ' + (opt["removeEmptyline"] ? "checked" : "" ) + '>' + lang.delLine + '</td></tr>' +
  23811. '<tr><td nowrap><input type="checkbox" name="removeClass" ' + (opt["removeClass"] ? "checked" : "" ) + '>' + lang.removeFormat + '</td><td colspan="2"><input type="checkbox" name="indent" ' + (opt["indent"] ? "checked" : "" ) + '>' + lang.indent + '</td></tr>' +
  23812. '<tr>' +
  23813. '<td nowrap><input type="checkbox" name="textAlign" ' + (opt["textAlign"] ? "checked" : "" ) + '>' + lang.alignment + '</td>' +
  23814. '<td colspan="2" id="' + textAlignInputName + '">' +
  23815. '<input type="radio" name="'+ textAlignInputName +'" value="left" ' + ((opt["textAlign"] && opt["textAlign"] == "left") ? "checked" : "") + '>' + me.getLang("justifyleft") +
  23816. '<input type="radio" name="'+ textAlignInputName +'" value="center" ' + ((opt["textAlign"] && opt["textAlign"] == "center") ? "checked" : "") + '>' + me.getLang("justifycenter") +
  23817. '<input type="radio" name="'+ textAlignInputName +'" value="right" ' + ((opt["textAlign"] && opt["textAlign"] == "right") ? "checked" : "") + '>' + me.getLang("justifyright") +
  23818. '</td>' +
  23819. '</tr>' +
  23820. '<tr>' +
  23821. '<td nowrap><input type="checkbox" name="imageBlockLine" ' + (opt["imageBlockLine"] ? "checked" : "" ) + '>' + lang.imageFloat + '</td>' +
  23822. '<td nowrap id="'+ imageBlockInputName +'">' +
  23823. '<input type="radio" name="'+ imageBlockInputName +'" value="none" ' + ((opt["imageBlockLine"] && opt["imageBlockLine"] == "none") ? "checked" : "") + '>' + me.getLang("default") +
  23824. '<input type="radio" name="'+ imageBlockInputName +'" value="left" ' + ((opt["imageBlockLine"] && opt["imageBlockLine"] == "left") ? "checked" : "") + '>' + me.getLang("justifyleft") +
  23825. '<input type="radio" name="'+ imageBlockInputName +'" value="center" ' + ((opt["imageBlockLine"] && opt["imageBlockLine"] == "center") ? "checked" : "") + '>' + me.getLang("justifycenter") +
  23826. '<input type="radio" name="'+ imageBlockInputName +'" value="right" ' + ((opt["imageBlockLine"] && opt["imageBlockLine"] == "right") ? "checked" : "") + '>' + me.getLang("justifyright") +
  23827. '</td>' +
  23828. '</tr>' +
  23829. '<tr><td nowrap><input type="checkbox" name="clearFontSize" ' + (opt["clearFontSize"] ? "checked" : "" ) + '>' + lang.removeFontsize + '</td><td colspan="2"><input type="checkbox" name="clearFontFamily" ' + (opt["clearFontFamily"] ? "checked" : "" ) + '>' + lang.removeFontFamily + '</td></tr>' +
  23830. '<tr><td nowrap colspan="3"><input type="checkbox" name="removeEmptyNode" ' + (opt["removeEmptyNode"] ? "checked" : "" ) + '>' + lang.removeHtml + '</td></tr>' +
  23831. '<tr><td nowrap colspan="3"><input type="checkbox" name="pasteFilter" ' + (opt["pasteFilter"] ? "checked" : "" ) + '>' + lang.pasteFilter + '</td></tr>' +
  23832. '<tr>' +
  23833. '<td nowrap><input type="checkbox" name="symbolConver" ' + (opt["bdc2sb"] || opt["tobdc"] ? "checked" : "" ) + '>' + lang.symbol + '</td>' +
  23834. '<td id="' + symbolConverInputName + '">' +
  23835. '<input type="radio" name="bdc" value="bdc2sb" ' + (opt["bdc2sb"] ? "checked" : "" ) + '>' + lang.bdc2sb +
  23836. '<input type="radio" name="bdc" value="tobdc" ' + (opt["tobdc"] ? "checked" : "" ) + '>' + lang.tobdc + '' +
  23837. '</td>' +
  23838. '<td nowrap align="right"><button >' + lang.run + '</button></td>' +
  23839. '</tr>' +
  23840. '</table>' +
  23841. '</div>' +
  23842. '</div>';
  23843. },
  23844. _UIBase_render:UIBase.prototype.render
  23845. };
  23846. utils.inherits(AutoTypeSetPicker, UIBase);
  23847. })();
  23848. // js/editor/_src/ui/autotypesetbutton.js
  23849. ///import core
  23850. ///import uicore
  23851. ///import ui/popup.js
  23852. ///import ui/autotypesetpicker.js
  23853. ///import ui/splitbutton.js
  23854. (function (){
  23855. var utils = baidu.editor.utils,
  23856. Popup = baidu.editor.ui.Popup,
  23857. AutoTypeSetPicker = baidu.editor.ui.AutoTypeSetPicker,
  23858. SplitButton = baidu.editor.ui.SplitButton,
  23859. AutoTypeSetButton = baidu.editor.ui.AutoTypeSetButton = function (options){
  23860. this.initOptions(options);
  23861. this.initAutoTypeSetButton();
  23862. };
  23863. function getPara(me){
  23864. var opt = {},
  23865. cont = me.getDom(),
  23866. editorId = me.editor.uid,
  23867. inputType = null,
  23868. attrName = null,
  23869. ipts = domUtils.getElementsByTagName(cont,"input");
  23870. for(var i=ipts.length-1,ipt;ipt=ipts[i--];){
  23871. inputType = ipt.getAttribute("type");
  23872. if(inputType=="checkbox"){
  23873. attrName = ipt.getAttribute("name");
  23874. opt[attrName] && delete opt[attrName];
  23875. if(ipt.checked){
  23876. var attrValue = document.getElementById( attrName + "Value" + editorId );
  23877. if(attrValue){
  23878. if(/input/ig.test(attrValue.tagName)){
  23879. opt[attrName] = attrValue.value;
  23880. } else {
  23881. var iptChilds = attrValue.getElementsByTagName("input");
  23882. for(var j=iptChilds.length-1,iptchild;iptchild=iptChilds[j--];){
  23883. if(iptchild.checked){
  23884. opt[attrName] = iptchild.value;
  23885. break;
  23886. }
  23887. }
  23888. }
  23889. } else {
  23890. opt[attrName] = true;
  23891. }
  23892. } else {
  23893. opt[attrName] = false;
  23894. }
  23895. } else {
  23896. opt[ipt.getAttribute("value")] = ipt.checked;
  23897. }
  23898. }
  23899. var selects = domUtils.getElementsByTagName(cont,"select");
  23900. for(var i=0,si;si=selects[i++];){
  23901. var attr = si.getAttribute('name');
  23902. opt[attr] = opt[attr] ? si.value : '';
  23903. }
  23904. utils.extend(me.editor.options.autotypeset,opt);
  23905. me.editor.setPreferences('autotypeset', opt);
  23906. }
  23907. AutoTypeSetButton.prototype = {
  23908. initAutoTypeSetButton: function (){
  23909. var me = this;
  23910. this.popup = new Popup({
  23911. //传入配置参数
  23912. content: new AutoTypeSetPicker({editor:me.editor}),
  23913. 'editor':me.editor,
  23914. hide : function(){
  23915. if (!this._hidden && this.getDom()) {
  23916. getPara(this);
  23917. this.getDom().style.display = 'none';
  23918. this._hidden = true;
  23919. this.fireEvent('hide');
  23920. }
  23921. }
  23922. });
  23923. var flag = 0;
  23924. this.popup.addListener('postRenderAfter',function(){
  23925. var popupUI = this;
  23926. if(flag)return;
  23927. var cont = this.getDom(),
  23928. btn = cont.getElementsByTagName('button')[0];
  23929. btn.onclick = function(){
  23930. getPara(popupUI);
  23931. me.editor.execCommand('autotypeset');
  23932. popupUI.hide()
  23933. };
  23934. domUtils.on(cont, 'click', function(e) {
  23935. var target = e.target || e.srcElement,
  23936. editorId = me.editor.uid;
  23937. if (target && target.tagName == 'INPUT') {
  23938. // 点击图片浮动的checkbox,去除对应的radio
  23939. if (target.name == 'imageBlockLine' || target.name == 'textAlign' || target.name == 'symbolConver') {
  23940. var checked = target.checked,
  23941. radioTd = document.getElementById( target.name + 'Value' + editorId),
  23942. radios = radioTd.getElementsByTagName('input'),
  23943. defalutSelect = {
  23944. 'imageBlockLine': 'none',
  23945. 'textAlign': 'left',
  23946. 'symbolConver': 'tobdc'
  23947. };
  23948. for (var i = 0; i < radios.length; i++) {
  23949. if (checked) {
  23950. if (radios[i].value == defalutSelect[target.name]) {
  23951. radios[i].checked = 'checked';
  23952. }
  23953. } else {
  23954. radios[i].checked = false;
  23955. }
  23956. }
  23957. }
  23958. // 点击radio,选中对应的checkbox
  23959. if (target.name == ('imageBlockLineValue' + editorId) || target.name == ('textAlignValue' + editorId) || target.name == 'bdc') {
  23960. var checkboxs = target.parentNode.previousSibling.getElementsByTagName('input');
  23961. checkboxs && (checkboxs[0].checked = true);
  23962. }
  23963. getPara(popupUI);
  23964. }
  23965. });
  23966. flag = 1;
  23967. });
  23968. this.initSplitButton();
  23969. }
  23970. };
  23971. utils.inherits(AutoTypeSetButton, SplitButton);
  23972. })();
  23973. // js/editor/_src/ui/cellalignpicker.js
  23974. ///import core
  23975. ///import uicore
  23976. (function () {
  23977. var utils = baidu.editor.utils,
  23978. Popup = baidu.editor.ui.Popup,
  23979. Stateful = baidu.editor.ui.Stateful,
  23980. UIBase = baidu.editor.ui.UIBase;
  23981. /**
  23982. * 该参数将新增一个参数: selected, 参数类型为一个Object, 形如{ 'align': 'center', 'valign': 'top' }, 表示单元格的初始
  23983. * 对齐状态为: 竖直居上,水平居中; 其中 align的取值为:'center', 'left', 'right'; valign的取值为: 'top', 'middle', 'bottom'
  23984. * @update 2013/4/2 hancong03@baidu.com
  23985. */
  23986. var CellAlignPicker = baidu.editor.ui.CellAlignPicker = function (options) {
  23987. this.initOptions(options);
  23988. this.initSelected();
  23989. this.initCellAlignPicker();
  23990. };
  23991. CellAlignPicker.prototype = {
  23992. //初始化选中状态, 该方法将根据传递进来的参数获取到应该选中的对齐方式图标的索引
  23993. initSelected: function(){
  23994. var status = {
  23995. valign: {
  23996. top: 0,
  23997. middle: 1,
  23998. bottom: 2
  23999. },
  24000. align: {
  24001. left: 0,
  24002. center: 1,
  24003. right: 2
  24004. },
  24005. count: 3
  24006. },
  24007. result = -1;
  24008. if( this.selected ) {
  24009. this.selectedIndex = status.valign[ this.selected.valign ] * status.count + status.align[ this.selected.align ];
  24010. }
  24011. },
  24012. initCellAlignPicker:function () {
  24013. this.initUIBase();
  24014. this.Stateful_init();
  24015. },
  24016. getHtmlTpl:function () {
  24017. var alignType = [ 'left', 'center', 'right' ],
  24018. COUNT = 9,
  24019. tempClassName = null,
  24020. tempIndex = -1,
  24021. tmpl = [];
  24022. for( var i= 0; i<COUNT; i++ ) {
  24023. tempClassName = this.selectedIndex === i ? ' class="edui-cellalign-selected" ' : '';
  24024. tempIndex = i % 3;
  24025. tempIndex === 0 && tmpl.push('<tr>');
  24026. tmpl.push( '<td index="'+ i +'" ' + tempClassName + ' stateful><div class="edui-icon edui-'+ alignType[ tempIndex ] +'"></div></td>' );
  24027. tempIndex === 2 && tmpl.push('</tr>');
  24028. }
  24029. return '<div id="##" class="edui-cellalignpicker %%">' +
  24030. '<div class="edui-cellalignpicker-body">' +
  24031. '<table onclick="$$._onClick(event);">' +
  24032. tmpl.join('') +
  24033. '</table>' +
  24034. '</div>' +
  24035. '</div>';
  24036. },
  24037. getStateDom: function (){
  24038. return this.target;
  24039. },
  24040. _onClick: function (evt){
  24041. var target= evt.target || evt.srcElement;
  24042. if(/icon/.test(target.className)){
  24043. this.items[target.parentNode.getAttribute("index")].onclick();
  24044. Popup.postHide(evt);
  24045. }
  24046. },
  24047. _UIBase_render:UIBase.prototype.render
  24048. };
  24049. utils.inherits(CellAlignPicker, UIBase);
  24050. utils.extend(CellAlignPicker.prototype, Stateful,true);
  24051. })();
  24052. // js/editor/_src/ui/pastepicker.js
  24053. ///import core
  24054. ///import uicore
  24055. (function () {
  24056. var utils = baidu.editor.utils,
  24057. Stateful = baidu.editor.ui.Stateful,
  24058. uiUtils = baidu.editor.ui.uiUtils,
  24059. UIBase = baidu.editor.ui.UIBase;
  24060. var PastePicker = baidu.editor.ui.PastePicker = function (options) {
  24061. this.initOptions(options);
  24062. this.initPastePicker();
  24063. };
  24064. PastePicker.prototype = {
  24065. initPastePicker:function () {
  24066. this.initUIBase();
  24067. this.Stateful_init();
  24068. },
  24069. getHtmlTpl:function () {
  24070. return '<div class="edui-pasteicon" onclick="$$._onClick(this)"></div>' +
  24071. '<div class="edui-pastecontainer">' +
  24072. '<div class="edui-title">' + this.editor.getLang("pasteOpt") + '</div>' +
  24073. '<div class="edui-button">' +
  24074. '<div title="' + this.editor.getLang("pasteSourceFormat") + '" onclick="$$.format(false)" stateful>' +
  24075. '<div class="edui-richtxticon"></div></div>' +
  24076. '<div title="' + this.editor.getLang("tagFormat") + '" onclick="$$.format(2)" stateful>' +
  24077. '<div class="edui-tagicon"></div></div>' +
  24078. '<div title="' + this.editor.getLang("pasteTextFormat") + '" onclick="$$.format(true)" stateful>' +
  24079. '<div class="edui-plaintxticon"></div></div>' +
  24080. '</div>' +
  24081. '</div>' +
  24082. '</div>'
  24083. },
  24084. getStateDom:function () {
  24085. return this.target;
  24086. },
  24087. format:function (param) {
  24088. this.editor.ui._isTransfer = true;
  24089. this.editor.fireEvent('pasteTransfer', param);
  24090. },
  24091. _onClick:function (cur) {
  24092. var node = domUtils.getNextDomNode(cur),
  24093. screenHt = uiUtils.getViewportRect().height,
  24094. subPop = uiUtils.getClientRect(node);
  24095. if ((subPop.top + subPop.height) > screenHt)
  24096. node.style.top = (-subPop.height - cur.offsetHeight) + "px";
  24097. else
  24098. node.style.top = "";
  24099. if (/hidden/ig.test(domUtils.getComputedStyle(node, "visibility"))) {
  24100. node.style.visibility = "visible";
  24101. domUtils.addClass(cur, "edui-state-opened");
  24102. } else {
  24103. node.style.visibility = "hidden";
  24104. domUtils.removeClasses(cur, "edui-state-opened")
  24105. }
  24106. },
  24107. _UIBase_render:UIBase.prototype.render
  24108. };
  24109. utils.inherits(PastePicker, UIBase);
  24110. utils.extend(PastePicker.prototype, Stateful, true);
  24111. })();
  24112. // js/editor/_src/ui/toolbar.js
  24113. (function (){
  24114. var utils = baidu.editor.utils,
  24115. uiUtils = baidu.editor.ui.uiUtils,
  24116. UIBase = baidu.editor.ui.UIBase,
  24117. Toolbar = baidu.editor.ui.Toolbar = function (options){
  24118. this.initOptions(options);
  24119. this.initToolbar();
  24120. };
  24121. Toolbar.prototype = {
  24122. items: null,
  24123. initToolbar: function (){
  24124. this.items = this.items || [];
  24125. this.initUIBase();
  24126. },
  24127. add: function (item,index){
  24128. if(index === undefined){
  24129. this.items.push(item);
  24130. }else{
  24131. this.items.splice(index,0,item)
  24132. }
  24133. },
  24134. getHtmlTpl: function (){
  24135. var buff = [];
  24136. for (var i=0; i<this.items.length; i++) {
  24137. buff[i] = this.items[i].renderHtml();
  24138. }
  24139. return '<div id="##" class="edui-toolbar %%" onselectstart="return false;" onmousedown="return $$._onMouseDown(event, this);">' +
  24140. buff.join('') +
  24141. '</div>'
  24142. },
  24143. postRender: function (){
  24144. var box = this.getDom();
  24145. for (var i=0; i<this.items.length; i++) {
  24146. this.items[i].postRender();
  24147. }
  24148. uiUtils.makeUnselectable(box);
  24149. },
  24150. _onMouseDown: function (e){
  24151. var target = e.target || e.srcElement,
  24152. tagName = target && target.tagName && target.tagName.toLowerCase();
  24153. if (tagName == 'input' || tagName == 'object' || tagName == 'object') {
  24154. return false;
  24155. }
  24156. }
  24157. };
  24158. utils.inherits(Toolbar, UIBase);
  24159. })();
  24160. // js/editor/_src/ui/menu.js
  24161. ///import core
  24162. ///import uicore
  24163. ///import ui\popup.js
  24164. ///import ui\stateful.js
  24165. (function () {
  24166. var utils = baidu.editor.utils,
  24167. domUtils = baidu.editor.dom.domUtils,
  24168. uiUtils = baidu.editor.ui.uiUtils,
  24169. UIBase = baidu.editor.ui.UIBase,
  24170. Popup = baidu.editor.ui.Popup,
  24171. Stateful = baidu.editor.ui.Stateful,
  24172. CellAlignPicker = baidu.editor.ui.CellAlignPicker,
  24173. Menu = baidu.editor.ui.Menu = function (options) {
  24174. this.initOptions(options);
  24175. this.initMenu();
  24176. };
  24177. var menuSeparator = {
  24178. renderHtml:function () {
  24179. return '<div class="edui-menuitem edui-menuseparator"><div class="edui-menuseparator-inner"></div></div>';
  24180. },
  24181. postRender:function () {
  24182. },
  24183. queryAutoHide:function () {
  24184. return true;
  24185. }
  24186. };
  24187. Menu.prototype = {
  24188. items:null,
  24189. uiName:'menu',
  24190. initMenu:function () {
  24191. this.items = this.items || [];
  24192. this.initPopup();
  24193. this.initItems();
  24194. },
  24195. initItems:function () {
  24196. for (var i = 0; i < this.items.length; i++) {
  24197. var item = this.items[i];
  24198. if (item == '-') {
  24199. this.items[i] = this.getSeparator();
  24200. } else if (!(item instanceof MenuItem)) {
  24201. item.editor = this.editor;
  24202. item.theme = this.editor.options.theme;
  24203. this.items[i] = this.createItem(item);
  24204. }
  24205. }
  24206. },
  24207. getSeparator:function () {
  24208. return menuSeparator;
  24209. },
  24210. createItem:function (item) {
  24211. //新增一个参数menu, 该参数存储了menuItem所对应的menu引用
  24212. item.menu = this;
  24213. return new MenuItem(item);
  24214. },
  24215. _Popup_getContentHtmlTpl:Popup.prototype.getContentHtmlTpl,
  24216. getContentHtmlTpl:function () {
  24217. if (this.items.length == 0) {
  24218. return this._Popup_getContentHtmlTpl();
  24219. }
  24220. var buff = [];
  24221. for (var i = 0; i < this.items.length; i++) {
  24222. var item = this.items[i];
  24223. buff[i] = item.renderHtml();
  24224. }
  24225. return ('<div class="%%-body">' + buff.join('') + '</div>');
  24226. },
  24227. _Popup_postRender:Popup.prototype.postRender,
  24228. postRender:function () {
  24229. var me = this;
  24230. for (var i = 0; i < this.items.length; i++) {
  24231. var item = this.items[i];
  24232. item.ownerMenu = this;
  24233. item.postRender();
  24234. }
  24235. domUtils.on(this.getDom(), 'mouseover', function (evt) {
  24236. evt = evt || event;
  24237. var rel = evt.relatedTarget || evt.fromElement;
  24238. var el = me.getDom();
  24239. if (!uiUtils.contains(el, rel) && el !== rel) {
  24240. me.fireEvent('over');
  24241. }
  24242. });
  24243. this._Popup_postRender();
  24244. },
  24245. queryAutoHide:function (el) {
  24246. if (el) {
  24247. if (uiUtils.contains(this.getDom(), el)) {
  24248. return false;
  24249. }
  24250. for (var i = 0; i < this.items.length; i++) {
  24251. var item = this.items[i];
  24252. if (item.queryAutoHide(el) === false) {
  24253. return false;
  24254. }
  24255. }
  24256. }
  24257. },
  24258. clearItems:function () {
  24259. for (var i = 0; i < this.items.length; i++) {
  24260. var item = this.items[i];
  24261. clearTimeout(item._showingTimer);
  24262. clearTimeout(item._closingTimer);
  24263. if (item.subMenu) {
  24264. item.subMenu.destroy();
  24265. }
  24266. }
  24267. this.items = [];
  24268. },
  24269. destroy:function () {
  24270. if (this.getDom()) {
  24271. domUtils.remove(this.getDom());
  24272. }
  24273. this.clearItems();
  24274. },
  24275. dispose:function () {
  24276. this.destroy();
  24277. }
  24278. };
  24279. utils.inherits(Menu, Popup);
  24280. /**
  24281. * @update 2013/04/03 hancong03 新增一个参数menu, 该参数存储了menuItem所对应的menu引用
  24282. * @type {Function}
  24283. */
  24284. var MenuItem = baidu.editor.ui.MenuItem = function (options) {
  24285. this.initOptions(options);
  24286. this.initUIBase();
  24287. this.Stateful_init();
  24288. if (this.subMenu && !(this.subMenu instanceof Menu)) {
  24289. if (options.className && options.className.indexOf("aligntd") != -1) {
  24290. var me = this;
  24291. //获取单元格对齐初始状态
  24292. this.subMenu.selected = this.editor.queryCommandValue( 'cellalignment' );
  24293. this.subMenu = new Popup({
  24294. content:new CellAlignPicker(this.subMenu),
  24295. parentMenu:me,
  24296. editor:me.editor,
  24297. destroy:function () {
  24298. if (this.getDom()) {
  24299. domUtils.remove(this.getDom());
  24300. }
  24301. }
  24302. });
  24303. this.subMenu.addListener("postRenderAfter", function () {
  24304. domUtils.on(this.getDom(), "mouseover", function () {
  24305. me.addState('opened');
  24306. });
  24307. });
  24308. } else {
  24309. this.subMenu = new Menu(this.subMenu);
  24310. }
  24311. }
  24312. };
  24313. MenuItem.prototype = {
  24314. label:'',
  24315. subMenu:null,
  24316. ownerMenu:null,
  24317. uiName:'menuitem',
  24318. alwalysHoverable:true,
  24319. getHtmlTpl:function () {
  24320. return '<div id="##" class="%%" stateful onclick="$$._onClick(event, this);">' +
  24321. '<div class="%%-body">' +
  24322. this.renderLabelHtml() +
  24323. '</div>' +
  24324. '</div>';
  24325. },
  24326. postRender:function () {
  24327. var me = this;
  24328. this.addListener('over', function () {
  24329. me.ownerMenu.fireEvent('submenuover', me);
  24330. if (me.subMenu) {
  24331. me.delayShowSubMenu();
  24332. }
  24333. });
  24334. if (this.subMenu) {
  24335. this.getDom().className += ' edui-hassubmenu';
  24336. this.subMenu.render();
  24337. this.addListener('out', function () {
  24338. me.delayHideSubMenu();
  24339. });
  24340. this.subMenu.addListener('over', function () {
  24341. clearTimeout(me._closingTimer);
  24342. me._closingTimer = null;
  24343. me.addState('opened');
  24344. });
  24345. this.ownerMenu.addListener('hide', function () {
  24346. me.hideSubMenu();
  24347. });
  24348. this.ownerMenu.addListener('submenuover', function (t, subMenu) {
  24349. if (subMenu !== me) {
  24350. me.delayHideSubMenu();
  24351. }
  24352. });
  24353. this.subMenu._bakQueryAutoHide = this.subMenu.queryAutoHide;
  24354. this.subMenu.queryAutoHide = function (el) {
  24355. if (el && uiUtils.contains(me.getDom(), el)) {
  24356. return false;
  24357. }
  24358. return this._bakQueryAutoHide(el);
  24359. };
  24360. }
  24361. this.getDom().style.tabIndex = '-1';
  24362. uiUtils.makeUnselectable(this.getDom());
  24363. this.Stateful_postRender();
  24364. },
  24365. delayShowSubMenu:function () {
  24366. var me = this;
  24367. if (!me.isDisabled()) {
  24368. me.addState('opened');
  24369. clearTimeout(me._showingTimer);
  24370. clearTimeout(me._closingTimer);
  24371. me._closingTimer = null;
  24372. me._showingTimer = setTimeout(function () {
  24373. me.showSubMenu();
  24374. }, 250);
  24375. }
  24376. },
  24377. delayHideSubMenu:function () {
  24378. var me = this;
  24379. if (!me.isDisabled()) {
  24380. me.removeState('opened');
  24381. clearTimeout(me._showingTimer);
  24382. if (!me._closingTimer) {
  24383. me._closingTimer = setTimeout(function () {
  24384. if (!me.hasState('opened')) {
  24385. me.hideSubMenu();
  24386. }
  24387. me._closingTimer = null;
  24388. }, 400);
  24389. }
  24390. }
  24391. },
  24392. renderLabelHtml:function () {
  24393. return '<div class="edui-arrow"></div>' +
  24394. '<div class="edui-box edui-icon"></div>' +
  24395. '<div class="edui-box edui-label %%-label">' + (this.label || '') + '</div>';
  24396. },
  24397. getStateDom:function () {
  24398. return this.getDom();
  24399. },
  24400. queryAutoHide:function (el) {
  24401. if (this.subMenu && this.hasState('opened')) {
  24402. return this.subMenu.queryAutoHide(el);
  24403. }
  24404. },
  24405. _onClick:function (event, this_) {
  24406. if (this.hasState('disabled')) return;
  24407. if (this.fireEvent('click', event, this_) !== false) {
  24408. if (this.subMenu) {
  24409. this.showSubMenu();
  24410. } else {
  24411. Popup.postHide(event);
  24412. }
  24413. }
  24414. },
  24415. showSubMenu:function () {
  24416. var rect = uiUtils.getClientRect(this.getDom());
  24417. rect.right -= 5;
  24418. rect.left += 2;
  24419. rect.width -= 7;
  24420. rect.top -= 4;
  24421. rect.bottom += 4;
  24422. rect.height += 8;
  24423. this.subMenu.showAnchorRect(rect, true, true);
  24424. },
  24425. hideSubMenu:function () {
  24426. this.subMenu.hide();
  24427. }
  24428. };
  24429. utils.inherits(MenuItem, UIBase);
  24430. utils.extend(MenuItem.prototype, Stateful, true);
  24431. })();
  24432. // js/editor/_src/ui/combox.js
  24433. ///import core
  24434. ///import uicore
  24435. ///import ui/menu.js
  24436. ///import ui/splitbutton.js
  24437. (function (){
  24438. // todo: menu和item提成通用list
  24439. var utils = baidu.editor.utils,
  24440. uiUtils = baidu.editor.ui.uiUtils,
  24441. Menu = baidu.editor.ui.Menu,
  24442. SplitButton = baidu.editor.ui.SplitButton,
  24443. Combox = baidu.editor.ui.Combox = function (options){
  24444. this.initOptions(options);
  24445. this.initCombox();
  24446. };
  24447. Combox.prototype = {
  24448. uiName: 'combox',
  24449. onbuttonclick:function () {
  24450. this.showPopup();
  24451. },
  24452. initCombox: function (){
  24453. var me = this;
  24454. this.items = this.items || [];
  24455. for (var i=0; i<this.items.length; i++) {
  24456. var item = this.items[i];
  24457. item.uiName = 'listitem';
  24458. item.index = i;
  24459. item.onclick = function (){
  24460. me.selectByIndex(this.index);
  24461. };
  24462. }
  24463. this.popup = new Menu({
  24464. items: this.items,
  24465. uiName: 'list',
  24466. editor:this.editor,
  24467. captureWheel: true,
  24468. combox: this
  24469. });
  24470. this.initSplitButton();
  24471. },
  24472. _SplitButton_postRender: SplitButton.prototype.postRender,
  24473. postRender: function (){
  24474. this._SplitButton_postRender();
  24475. this.setLabel(this.label || '');
  24476. this.setValue(this.initValue || '');
  24477. },
  24478. showPopup: function (){
  24479. var rect = uiUtils.getClientRect(this.getDom());
  24480. rect.top += 1;
  24481. rect.bottom -= 1;
  24482. rect.height -= 2;
  24483. this.popup.showAnchorRect(rect);
  24484. },
  24485. getValue: function (){
  24486. return this.value;
  24487. },
  24488. setValue: function (value){
  24489. var index = this.indexByValue(value);
  24490. if (index != -1) {
  24491. this.selectedIndex = index;
  24492. this.setLabel(this.items[index].label);
  24493. this.value = this.items[index].value;
  24494. } else {
  24495. this.selectedIndex = -1;
  24496. this.setLabel(this.getLabelForUnknowValue(value));
  24497. this.value = value;
  24498. }
  24499. },
  24500. setLabel: function (label){
  24501. this.getDom('button_body').innerHTML = label;
  24502. this.label = label;
  24503. },
  24504. getLabelForUnknowValue: function (value){
  24505. return value;
  24506. },
  24507. indexByValue: function (value){
  24508. for (var i=0; i<this.items.length; i++) {
  24509. if (value == this.items[i].value) {
  24510. return i;
  24511. }
  24512. }
  24513. return -1;
  24514. },
  24515. getItem: function (index){
  24516. return this.items[index];
  24517. },
  24518. selectByIndex: function (index){
  24519. if (index < this.items.length && this.fireEvent('select', index) !== false) {
  24520. this.selectedIndex = index;
  24521. this.value = this.items[index].value;
  24522. this.setLabel(this.items[index].label);
  24523. }
  24524. }
  24525. };
  24526. utils.inherits(Combox, SplitButton);
  24527. })();
  24528. // js/editor/_src/ui/dialog.js
  24529. ///import core
  24530. ///import uicore
  24531. ///import ui/mask.js
  24532. ///import ui/button.js
  24533. (function (){
  24534. var utils = baidu.editor.utils,
  24535. domUtils = baidu.editor.dom.domUtils,
  24536. uiUtils = baidu.editor.ui.uiUtils,
  24537. Mask = baidu.editor.ui.Mask,
  24538. UIBase = baidu.editor.ui.UIBase,
  24539. Button = baidu.editor.ui.Button,
  24540. Dialog = baidu.editor.ui.Dialog = function (options){
  24541. if(options.name){
  24542. var name = options.name;
  24543. var cssRules = options.cssRules;
  24544. if(!options.className){
  24545. options.className = 'edui-for-' + name;
  24546. }
  24547. if(cssRules){
  24548. options.cssRules = '.edui-default .edui-for-'+ name +' .edui-dialog-content {'+ cssRules +'}'
  24549. }
  24550. }
  24551. this.initOptions(utils.extend({
  24552. autoReset: true,
  24553. draggable: true,
  24554. onok: function (){},
  24555. oncancel: function (){},
  24556. onclose: function (t, ok){
  24557. return ok ? this.onok() : this.oncancel();
  24558. },
  24559. //是否控制dialog中的scroll事件, 默认为不阻止
  24560. holdScroll: false
  24561. },options));
  24562. this.initDialog();
  24563. };
  24564. var modalMask;
  24565. var dragMask;
  24566. var activeDialog;
  24567. Dialog.prototype = {
  24568. draggable: false,
  24569. uiName: 'dialog',
  24570. initDialog: function (){
  24571. var me = this,
  24572. theme=this.editor.options.theme;
  24573. if(this.cssRules){
  24574. utils.cssRule('edui-customize-'+this.name+'-style',this.cssRules);
  24575. }
  24576. this.initUIBase();
  24577. this.modalMask = (modalMask || (modalMask = new Mask({
  24578. className: 'edui-dialog-modalmask',
  24579. theme:theme,
  24580. onclick: function (){
  24581. activeDialog && activeDialog.close(false);
  24582. }
  24583. })));
  24584. this.dragMask = (dragMask || (dragMask = new Mask({
  24585. className: 'edui-dialog-dragmask',
  24586. theme:theme
  24587. })));
  24588. this.closeButton = new Button({
  24589. className: 'edui-dialog-closebutton',
  24590. title: me.closeDialog,
  24591. theme:theme,
  24592. onclick: function (){
  24593. me.close(false);
  24594. }
  24595. });
  24596. this.fullscreen && this.initResizeEvent();
  24597. if (this.buttons) {
  24598. for (var i=0; i<this.buttons.length; i++) {
  24599. if (!(this.buttons[i] instanceof Button)) {
  24600. this.buttons[i] = new Button(utils.extend(this.buttons[i],{
  24601. editor : this.editor
  24602. },true));
  24603. }
  24604. }
  24605. }
  24606. },
  24607. initResizeEvent: function () {
  24608. var me = this;
  24609. domUtils.on( window, "resize", function () {
  24610. if ( me._hidden || me._hidden === undefined ) {
  24611. return;
  24612. }
  24613. if ( me.__resizeTimer ) {
  24614. window.clearTimeout( me.__resizeTimer );
  24615. }
  24616. me.__resizeTimer = window.setTimeout( function () {
  24617. me.__resizeTimer = null;
  24618. var dialogWrapNode = me.getDom(),
  24619. contentNode = me.getDom('content'),
  24620. wrapRect = UE.ui.uiUtils.getClientRect( dialogWrapNode ),
  24621. contentRect = UE.ui.uiUtils.getClientRect( contentNode ),
  24622. vpRect = uiUtils.getViewportRect();
  24623. contentNode.style.width = ( vpRect.width - wrapRect.width + contentRect.width ) + "px";
  24624. contentNode.style.height = ( vpRect.height - wrapRect.height + contentRect.height ) + "px";
  24625. dialogWrapNode.style.width = vpRect.width + "px";
  24626. dialogWrapNode.style.height = vpRect.height + "px";
  24627. me.fireEvent( "resize" );
  24628. }, 100 );
  24629. } );
  24630. },
  24631. fitSize: function (){
  24632. var popBodyEl = this.getDom('body');
  24633. // if (!(baidu.editor.browser.ie && baidu.editor.browser.version == 7)) {
  24634. // uiUtils.removeStyle(popBodyEl, 'width');
  24635. // uiUtils.removeStyle(popBodyEl, 'height');
  24636. // }
  24637. var size = this.mesureSize();
  24638. popBodyEl.style.width = size.width + 'px';
  24639. popBodyEl.style.height = size.height + 'px';
  24640. return size;
  24641. },
  24642. safeSetOffset: function (offset){
  24643. var me = this;
  24644. var el = me.getDom();
  24645. var vpRect = uiUtils.getViewportRect();
  24646. var rect = uiUtils.getClientRect(el);
  24647. var left = offset.left;
  24648. if (left + rect.width > vpRect.right) {
  24649. left = vpRect.right - rect.width;
  24650. }
  24651. var top = offset.top;
  24652. if (top + rect.height > vpRect.bottom) {
  24653. top = vpRect.bottom - rect.height;
  24654. }
  24655. el.style.left = Math.max(left, 0) + 'px';
  24656. el.style.top = Math.max(top, 0) + 'px';
  24657. },
  24658. showAtCenter: function (){
  24659. var vpRect = uiUtils.getViewportRect();
  24660. if ( !this.fullscreen ) {
  24661. this.getDom().style.display = '';
  24662. var popSize = this.fitSize();
  24663. var titleHeight = this.getDom('titlebar').offsetHeight | 0;
  24664. var left = vpRect.width / 2 - popSize.width / 2;
  24665. var top = vpRect.height / 2 - (popSize.height - titleHeight) / 2 - titleHeight;
  24666. var popEl = this.getDom();
  24667. this.safeSetOffset({
  24668. left: Math.max(left | 0, 0),
  24669. top: Math.max(top | 0, 0)
  24670. });
  24671. if (!domUtils.hasClass(popEl, 'edui-state-centered')) {
  24672. popEl.className += ' edui-state-centered';
  24673. }
  24674. } else {
  24675. var dialogWrapNode = this.getDom(),
  24676. contentNode = this.getDom('content');
  24677. dialogWrapNode.style.display = "block";
  24678. var wrapRect = UE.ui.uiUtils.getClientRect( dialogWrapNode ),
  24679. contentRect = UE.ui.uiUtils.getClientRect( contentNode );
  24680. dialogWrapNode.style.left = "-100000px";
  24681. contentNode.style.width = ( vpRect.width - wrapRect.width + contentRect.width ) + "px";
  24682. contentNode.style.height = ( vpRect.height - wrapRect.height + contentRect.height ) + "px";
  24683. dialogWrapNode.style.width = vpRect.width + "px";
  24684. dialogWrapNode.style.height = vpRect.height + "px";
  24685. dialogWrapNode.style.left = 0;
  24686. //保存环境的overflow值
  24687. this._originalContext = {
  24688. html: {
  24689. overflowX: document.documentElement.style.overflowX,
  24690. overflowY: document.documentElement.style.overflowY
  24691. },
  24692. body: {
  24693. overflowX: document.body.style.overflowX,
  24694. overflowY: document.body.style.overflowY
  24695. }
  24696. };
  24697. document.documentElement.style.overflowX = 'hidden';
  24698. document.documentElement.style.overflowY = 'hidden';
  24699. document.body.style.overflowX = 'hidden';
  24700. document.body.style.overflowY = 'hidden';
  24701. }
  24702. this._show();
  24703. },
  24704. getContentHtml: function (){
  24705. var contentHtml = '';
  24706. if (typeof this.content == 'string') {
  24707. contentHtml = this.content;
  24708. } else if (this.iframeUrl) {
  24709. contentHtml = '<span id="'+ this.id +'_contmask" class="dialogcontmask"></span><iframe id="'+ this.id +
  24710. '_iframe" class="%%-iframe" height="100%" width="100%" frameborder="0" src="'+ this.iframeUrl +'"></iframe>';
  24711. }
  24712. return contentHtml;
  24713. },
  24714. getHtmlTpl: function (){
  24715. var footHtml = '';
  24716. if (this.buttons) {
  24717. var buff = [];
  24718. for (var i=0; i<this.buttons.length; i++) {
  24719. buff[i] = this.buttons[i].renderHtml();
  24720. }
  24721. footHtml = '<div class="%%-foot">' +
  24722. '<div id="##_buttons" class="%%-buttons">' + buff.join('') + '</div>' +
  24723. '</div>';
  24724. }
  24725. return '<div id="##" class="%%"><div '+ ( !this.fullscreen ? 'class="%%"' : 'class="%%-wrap edui-dialog-fullscreen-flag"' ) +'><div id="##_body" class="%%-body">' +
  24726. '<div class="%%-shadow"></div>' +
  24727. '<div id="##_titlebar" class="%%-titlebar">' +
  24728. '<div class="%%-draghandle" onmousedown="$$._onTitlebarMouseDown(event, this);">' +
  24729. '<span class="%%-caption">' + (this.title || '') + '</span>' +
  24730. '</div>' +
  24731. this.closeButton.renderHtml() +
  24732. '</div>' +
  24733. '<div id="##_content" class="%%-content">'+ ( this.autoReset ? '' : this.getContentHtml()) +'</div>' +
  24734. footHtml +
  24735. '</div></div></div>';
  24736. },
  24737. postRender: function (){
  24738. // todo: 保持居中/记住上次关闭位置选项
  24739. if (!this.modalMask.getDom()) {
  24740. this.modalMask.render();
  24741. this.modalMask.hide();
  24742. }
  24743. if (!this.dragMask.getDom()) {
  24744. this.dragMask.render();
  24745. this.dragMask.hide();
  24746. }
  24747. var me = this;
  24748. this.addListener('show', function (){
  24749. me.modalMask.show(this.getDom().style.zIndex - 2);
  24750. });
  24751. this.addListener('hide', function (){
  24752. me.modalMask.hide();
  24753. });
  24754. if (this.buttons) {
  24755. for (var i=0; i<this.buttons.length; i++) {
  24756. this.buttons[i].postRender();
  24757. }
  24758. }
  24759. domUtils.on(window, 'resize', function (){
  24760. setTimeout(function (){
  24761. if (!me.isHidden()) {
  24762. me.safeSetOffset(uiUtils.getClientRect(me.getDom()));
  24763. }
  24764. });
  24765. });
  24766. //hold住scroll事件,防止dialog的滚动影响页面
  24767. // if( this.holdScroll ) {
  24768. //
  24769. // if( !me.iframeUrl ) {
  24770. // domUtils.on( document.getElementById( me.id + "_iframe"), !browser.gecko ? "mousewheel" : "DOMMouseScroll", function(e){
  24771. // domUtils.preventDefault(e);
  24772. // } );
  24773. // } else {
  24774. // me.addListener('dialogafterreset', function(){
  24775. // window.setTimeout(function(){
  24776. // var iframeWindow = document.getElementById( me.id + "_iframe").contentWindow;
  24777. //
  24778. // if( browser.ie ) {
  24779. //
  24780. // var timer = window.setInterval(function(){
  24781. //
  24782. // if( iframeWindow.document && iframeWindow.document.body ) {
  24783. // window.clearInterval( timer );
  24784. // timer = null;
  24785. // domUtils.on( iframeWindow.document.body, !browser.gecko ? "mousewheel" : "DOMMouseScroll", function(e){
  24786. // domUtils.preventDefault(e);
  24787. // } );
  24788. // }
  24789. //
  24790. // }, 100);
  24791. //
  24792. // } else {
  24793. // domUtils.on( iframeWindow, !browser.gecko ? "mousewheel" : "DOMMouseScroll", function(e){
  24794. // domUtils.preventDefault(e);
  24795. // } );
  24796. // }
  24797. //
  24798. // }, 1);
  24799. // });
  24800. // }
  24801. //
  24802. // }
  24803. this._hide();
  24804. },
  24805. mesureSize: function (){
  24806. var body = this.getDom('body');
  24807. var width = uiUtils.getClientRect(this.getDom('content')).width;
  24808. var dialogBodyStyle = body.style;
  24809. dialogBodyStyle.width = width;
  24810. return uiUtils.getClientRect(body);
  24811. },
  24812. _onTitlebarMouseDown: function (evt, el){
  24813. if (this.draggable) {
  24814. var rect;
  24815. var vpRect = uiUtils.getViewportRect();
  24816. var me = this;
  24817. uiUtils.startDrag(evt, {
  24818. ondragstart: function (){
  24819. rect = uiUtils.getClientRect(me.getDom());
  24820. me.getDom('contmask').style.visibility = 'visible';
  24821. me.dragMask.show(me.getDom().style.zIndex - 1);
  24822. },
  24823. ondragmove: function (x, y){
  24824. var left = rect.left + x;
  24825. var top = rect.top + y;
  24826. me.safeSetOffset({
  24827. left: left,
  24828. top: top
  24829. });
  24830. },
  24831. ondragstop: function (){
  24832. me.getDom('contmask').style.visibility = 'hidden';
  24833. domUtils.removeClasses(me.getDom(), ['edui-state-centered']);
  24834. me.dragMask.hide();
  24835. }
  24836. });
  24837. }
  24838. },
  24839. reset: function (){
  24840. this.getDom('content').innerHTML = this.getContentHtml();
  24841. this.fireEvent('dialogafterreset');
  24842. },
  24843. _show: function (){
  24844. if (this._hidden) {
  24845. this.getDom().style.display = '';
  24846. //要高过编辑器的zindxe
  24847. this.editor.container.style.zIndex && (this.getDom().style.zIndex = this.editor.container.style.zIndex * 1 + 10);
  24848. this._hidden = false;
  24849. this.fireEvent('show');
  24850. baidu.editor.ui.uiUtils.getFixedLayer().style.zIndex = this.getDom().style.zIndex - 4;
  24851. }
  24852. },
  24853. isHidden: function (){
  24854. return this._hidden;
  24855. },
  24856. _hide: function (){
  24857. if (!this._hidden) {
  24858. var wrapNode = this.getDom();
  24859. wrapNode.style.display = 'none';
  24860. wrapNode.style.zIndex = '';
  24861. wrapNode.style.width = '';
  24862. wrapNode.style.height = '';
  24863. this._hidden = true;
  24864. this.fireEvent('hide');
  24865. }
  24866. },
  24867. open: function (){
  24868. if (this.autoReset) {
  24869. //有可能还没有渲染
  24870. try{
  24871. this.reset();
  24872. }catch(e){
  24873. this.render();
  24874. this.open()
  24875. }
  24876. }
  24877. this.showAtCenter();
  24878. if (this.iframeUrl) {
  24879. try {
  24880. this.getDom('iframe').focus();
  24881. } catch(ex){}
  24882. }
  24883. activeDialog = this;
  24884. },
  24885. _onCloseButtonClick: function (evt, el){
  24886. this.close(false);
  24887. },
  24888. close: function (ok){
  24889. if (this.fireEvent('close', ok) !== false) {
  24890. //还原环境
  24891. if ( this.fullscreen ) {
  24892. document.documentElement.style.overflowX = this._originalContext.html.overflowX;
  24893. document.documentElement.style.overflowY = this._originalContext.html.overflowY;
  24894. document.body.style.overflowX = this._originalContext.body.overflowX;
  24895. document.body.style.overflowY = this._originalContext.body.overflowY;
  24896. delete this._originalContext;
  24897. }
  24898. this._hide();
  24899. //销毁content
  24900. var content = this.getDom('content');
  24901. var iframe = this.getDom('iframe');
  24902. if (content && iframe) {
  24903. var doc = iframe.contentDocument || iframe.contentWindow.document;
  24904. doc && (doc.body.innerHTML = '');
  24905. domUtils.remove(content);
  24906. }
  24907. }
  24908. }
  24909. };
  24910. utils.inherits(Dialog, UIBase);
  24911. })();
  24912. // js/editor/_src/ui/menubutton.js
  24913. ///import core
  24914. ///import uicore
  24915. ///import ui/menu.js
  24916. ///import ui/splitbutton.js
  24917. (function (){
  24918. var utils = baidu.editor.utils,
  24919. Menu = baidu.editor.ui.Menu,
  24920. SplitButton = baidu.editor.ui.SplitButton,
  24921. MenuButton = baidu.editor.ui.MenuButton = function (options){
  24922. this.initOptions(options);
  24923. this.initMenuButton();
  24924. };
  24925. MenuButton.prototype = {
  24926. initMenuButton: function (){
  24927. var me = this;
  24928. this.uiName = "menubutton";
  24929. this.popup = new Menu({
  24930. items: me.items,
  24931. className: me.className,
  24932. editor:me.editor
  24933. });
  24934. this.popup.addListener('show', function (){
  24935. var list = this;
  24936. for (var i=0; i<list.items.length; i++) {
  24937. list.items[i].removeState('checked');
  24938. if (list.items[i].value == me._value) {
  24939. list.items[i].addState('checked');
  24940. this.value = me._value;
  24941. }
  24942. }
  24943. });
  24944. this.initSplitButton();
  24945. },
  24946. setValue : function(value){
  24947. this._value = value;
  24948. }
  24949. };
  24950. utils.inherits(MenuButton, SplitButton);
  24951. })();
  24952. // js/editor/_src/ui/multiMenu.js
  24953. ///import core
  24954. ///import uicore
  24955. ///commands 表情
  24956. (function(){
  24957. var utils = baidu.editor.utils,
  24958. Popup = baidu.editor.ui.Popup,
  24959. SplitButton = baidu.editor.ui.SplitButton,
  24960. MultiMenuPop = baidu.editor.ui.MultiMenuPop = function(options){
  24961. this.initOptions(options);
  24962. this.initMultiMenu();
  24963. };
  24964. MultiMenuPop.prototype = {
  24965. initMultiMenu: function (){
  24966. var me = this;
  24967. this.popup = new Popup({
  24968. content: '',
  24969. editor : me.editor,
  24970. iframe_rendered: false,
  24971. onshow: function (){
  24972. if (!this.iframe_rendered) {
  24973. this.iframe_rendered = true;
  24974. this.getDom('content').innerHTML = '<iframe id="'+me.id+'_iframe" src="'+ me.iframeUrl +'" frameborder="0"></iframe>';
  24975. me.editor.container.style.zIndex && (this.getDom().style.zIndex = me.editor.container.style.zIndex * 1 + 1);
  24976. }
  24977. }
  24978. // canSideUp:false,
  24979. // canSideLeft:false
  24980. });
  24981. this.onbuttonclick = function(){
  24982. this.showPopup();
  24983. };
  24984. this.initSplitButton();
  24985. }
  24986. };
  24987. utils.inherits(MultiMenuPop, SplitButton);
  24988. })();
  24989. // js/editor/_src/ui/shortcutmenu.js
  24990. (function () {
  24991. var UI = baidu.editor.ui,
  24992. UIBase = UI.UIBase,
  24993. uiUtils = UI.uiUtils,
  24994. utils = baidu.editor.utils,
  24995. domUtils = baidu.editor.dom.domUtils;
  24996. var allMenus = [],//存储所有快捷菜单
  24997. timeID,
  24998. isSubMenuShow = false;//是否有子pop显示
  24999. var ShortCutMenu = UI.ShortCutMenu = function (options) {
  25000. this.initOptions (options);
  25001. this.initShortCutMenu ();
  25002. };
  25003. ShortCutMenu.postHide = hideAllMenu;
  25004. ShortCutMenu.prototype = {
  25005. isHidden : true ,
  25006. SPACE : 5 ,
  25007. initShortCutMenu : function () {
  25008. this.items = this.items || [];
  25009. this.initUIBase ();
  25010. this.initItems ();
  25011. this.initEvent ();
  25012. allMenus.push (this);
  25013. } ,
  25014. initEvent : function () {
  25015. var me = this,
  25016. doc = me.editor.document;
  25017. domUtils.on (doc , "mousemove" , function (e) {
  25018. if (me.isHidden === false) {
  25019. //有pop显示就不隐藏快捷菜单
  25020. if (me.getSubMenuMark () || me.eventType == "contextmenu") return;
  25021. var flag = true,
  25022. el = me.getDom (),
  25023. wt = el.offsetWidth,
  25024. ht = el.offsetHeight,
  25025. distanceX = wt / 2 + me.SPACE,//距离中心X标准
  25026. distanceY = ht / 2,//距离中心Y标准
  25027. x = Math.abs (e.screenX - me.left),//离中心距离横坐标
  25028. y = Math.abs (e.screenY - me.top);//离中心距离纵坐标
  25029. clearTimeout (timeID);
  25030. timeID = setTimeout (function () {
  25031. if (y > 0 && y < distanceY) {
  25032. me.setOpacity (el , "1");
  25033. } else if (y > distanceY && y < distanceY + 70) {
  25034. me.setOpacity (el , "0.5");
  25035. flag = false;
  25036. } else if (y > distanceY + 70 && y < distanceY + 140) {
  25037. me.hide ();
  25038. }
  25039. if (flag && x > 0 && x < distanceX) {
  25040. me.setOpacity (el , "1")
  25041. } else if (x > distanceX && x < distanceX + 70) {
  25042. me.setOpacity (el , "0.5")
  25043. } else if (x > distanceX + 70 && x < distanceX + 140) {
  25044. me.hide ();
  25045. }
  25046. });
  25047. }
  25048. });
  25049. //ie\ff下 mouseout不准
  25050. if (browser.chrome) {
  25051. domUtils.on (doc , "mouseout" , function (e) {
  25052. var relatedTgt = e.relatedTarget || e.toElement;
  25053. if (relatedTgt == null || relatedTgt.tagName == "HTML") {
  25054. me.hide ();
  25055. }
  25056. });
  25057. }
  25058. me.editor.addListener ("afterhidepop" , function () {
  25059. if (!me.isHidden) {
  25060. isSubMenuShow = true;
  25061. }
  25062. });
  25063. } ,
  25064. initItems : function () {
  25065. if (utils.isArray (this.items)) {
  25066. for (var i = 0, len = this.items.length ; i < len ; i++) {
  25067. var item = this.items[i].toLowerCase ();
  25068. if (UI[item]) {
  25069. this.items[i] = new UI[item] (this.editor);
  25070. this.items[i].className += " edui-shortcutsubmenu ";
  25071. }
  25072. }
  25073. }
  25074. } ,
  25075. setOpacity : function (el , value) {
  25076. if (browser.ie && browser.version < 9) {
  25077. el.style.filter = "alpha(opacity = " + parseFloat (value) * 100 + ");"
  25078. } else {
  25079. el.style.opacity = value;
  25080. }
  25081. } ,
  25082. getSubMenuMark : function () {
  25083. isSubMenuShow = false;
  25084. var layerEle = uiUtils.getFixedLayer ();
  25085. var list = domUtils.getElementsByTagName (layerEle , "div" , function (node) {
  25086. return domUtils.hasClass (node , "edui-shortcutsubmenu edui-popup")
  25087. });
  25088. for (var i = 0, node ; node = list[i++] ;) {
  25089. if (node.style.display != "none") {
  25090. isSubMenuShow = true;
  25091. }
  25092. }
  25093. return isSubMenuShow;
  25094. } ,
  25095. show : function (e , hasContextmenu) {
  25096. var me = this,
  25097. offset = {},
  25098. el = this.getDom (),
  25099. fixedlayer = uiUtils.getFixedLayer ();
  25100. function setPos (offset) {
  25101. if (offset.left < 0) {
  25102. offset.left = 0;
  25103. }
  25104. if (offset.top < 0) {
  25105. offset.top = 0;
  25106. }
  25107. el.style.cssText = "position:absolute;left:" + offset.left + "px;top:" + offset.top + "px;";
  25108. }
  25109. function setPosByCxtMenu (menu) {
  25110. if (!menu.tagName) {
  25111. menu = menu.getDom ();
  25112. }
  25113. offset.left = parseInt (menu.style.left);
  25114. offset.top = parseInt (menu.style.top);
  25115. offset.top -= el.offsetHeight + 15;
  25116. setPos (offset);
  25117. }
  25118. me.eventType = e.type;
  25119. el.style.cssText = "display:block;left:-9999px";
  25120. if (e.type == "contextmenu" && hasContextmenu) {
  25121. var menu = domUtils.getElementsByTagName (fixedlayer , "div" , "edui-contextmenu")[0];
  25122. if (menu) {
  25123. setPosByCxtMenu (menu)
  25124. } else {
  25125. me.editor.addListener ("aftershowcontextmenu" , function (type , menu) {
  25126. setPosByCxtMenu (menu);
  25127. });
  25128. }
  25129. } else {
  25130. offset = uiUtils.getViewportOffsetByEvent (e);
  25131. offset.top -= el.offsetHeight + me.SPACE;
  25132. offset.left += me.SPACE + 20;
  25133. setPos (offset);
  25134. me.setOpacity (el , 0.2);
  25135. }
  25136. me.isHidden = false;
  25137. me.left = e.screenX + el.offsetWidth / 2 - me.SPACE;
  25138. me.top = e.screenY - (el.offsetHeight / 2) - me.SPACE;
  25139. if (me.editor) {
  25140. el.style.zIndex = me.editor.container.style.zIndex * 1 + 10;
  25141. fixedlayer.style.zIndex = el.style.zIndex - 1;
  25142. }
  25143. } ,
  25144. hide : function () {
  25145. if (this.getDom ()) {
  25146. this.getDom ().style.display = "none";
  25147. }
  25148. this.isHidden = true;
  25149. } ,
  25150. postRender : function () {
  25151. if (utils.isArray (this.items)) {
  25152. for (var i = 0, item ; item = this.items[i++] ;) {
  25153. item.postRender ();
  25154. }
  25155. }
  25156. } ,
  25157. getHtmlTpl : function () {
  25158. var buff;
  25159. if (utils.isArray (this.items)) {
  25160. buff = [];
  25161. for (var i = 0 ; i < this.items.length ; i++) {
  25162. buff[i] = this.items[i].renderHtml ();
  25163. }
  25164. buff = buff.join ("");
  25165. } else {
  25166. buff = this.items;
  25167. }
  25168. return '<div id="##" class="%% edui-toolbar" data-src="shortcutmenu" onmousedown="return false;" onselectstart="return false;" >' +
  25169. buff +
  25170. '</div>';
  25171. }
  25172. };
  25173. utils.inherits (ShortCutMenu , UIBase);
  25174. function hideAllMenu (e) {
  25175. var tgt = e.target || e.srcElement,
  25176. cur = domUtils.findParent (tgt , function (node) {
  25177. return domUtils.hasClass (node , "edui-shortcutmenu") || domUtils.hasClass (node , "edui-popup");
  25178. } , true);
  25179. if (!cur) {
  25180. for (var i = 0, menu ; menu = allMenus[i++] ;) {
  25181. menu.hide ()
  25182. }
  25183. }
  25184. }
  25185. domUtils.on (document , 'mousedown' , function (e) {
  25186. hideAllMenu (e);
  25187. });
  25188. domUtils.on (window , 'scroll' , function (e) {
  25189. hideAllMenu (e);
  25190. });
  25191. }) ();
  25192. // js/editor/_src/ui/breakline.js
  25193. (function (){
  25194. var utils = baidu.editor.utils,
  25195. UIBase = baidu.editor.ui.UIBase,
  25196. Breakline = baidu.editor.ui.Breakline = function (options){
  25197. this.initOptions(options);
  25198. this.initSeparator();
  25199. };
  25200. Breakline.prototype = {
  25201. uiName: 'Breakline',
  25202. initSeparator: function (){
  25203. this.initUIBase();
  25204. },
  25205. getHtmlTpl: function (){
  25206. return '<br/>';
  25207. }
  25208. };
  25209. utils.inherits(Breakline, UIBase);
  25210. })();
  25211. // js/editor/_src/ui/message.js
  25212. ///import core
  25213. ///import uicore
  25214. (function () {
  25215. var utils = baidu.editor.utils,
  25216. domUtils = baidu.editor.dom.domUtils,
  25217. UIBase = baidu.editor.ui.UIBase,
  25218. Message = baidu.editor.ui.Message = function (options){
  25219. this.initOptions(options);
  25220. this.initMessage();
  25221. };
  25222. Message.prototype = {
  25223. initMessage: function (){
  25224. this.initUIBase();
  25225. },
  25226. getHtmlTpl: function (){
  25227. return '<div id="##" class="edui-message %%">' +
  25228. ' <div id="##_closer" class="edui-message-closer">×</div>' +
  25229. ' <div id="##_body" class="edui-message-body edui-message-type-info">' +
  25230. ' <iframe style="position:absolute;z-index:-1;left:0;top:0;background-color: transparent;" frameborder="0" width="100%" height="100%" src="about:blank"></iframe>' +
  25231. ' <div class="edui-shadow"></div>' +
  25232. ' <div id="##_content" class="edui-message-content">' +
  25233. ' </div>' +
  25234. ' </div>' +
  25235. '</div>';
  25236. },
  25237. reset: function(opt){
  25238. var me = this;
  25239. if (!opt.keepshow) {
  25240. clearTimeout(this.timer);
  25241. me.timer = setTimeout(function(){
  25242. me.hide();
  25243. }, opt.timeout || 4000);
  25244. }
  25245. opt.content !== undefined && me.setContent(opt.content);
  25246. opt.type !== undefined && me.setType(opt.type);
  25247. me.show();
  25248. },
  25249. postRender: function(){
  25250. var me = this,
  25251. closer = this.getDom('closer');
  25252. closer && domUtils.on(closer, 'click', function(){
  25253. me.hide();
  25254. });
  25255. },
  25256. setContent: function(content){
  25257. this.getDom('content').innerHTML = content;
  25258. },
  25259. setType: function(type){
  25260. type = type || 'info';
  25261. var body = this.getDom('body');
  25262. body.className = body.className.replace(/edui-message-type-[\w-]+/, 'edui-message-type-' + type);
  25263. },
  25264. getContent: function(){
  25265. return this.getDom('content').innerHTML;
  25266. },
  25267. getType: function(){
  25268. var arr = this.getDom('body').match(/edui-message-type-([\w-]+)/);
  25269. return arr ? arr[1]:'';
  25270. },
  25271. show: function (){
  25272. this.getDom().style.display = 'block';
  25273. },
  25274. hide: function (){
  25275. var dom = this.getDom();
  25276. if (dom) {
  25277. dom.style.display = 'none';
  25278. dom.parentNode && dom.parentNode.removeChild(dom);
  25279. }
  25280. }
  25281. };
  25282. utils.inherits(Message, UIBase);
  25283. })();
  25284. // js/editor/_src/adapter/editorui.js
  25285. //ui跟编辑器的适配層
  25286. //那个按钮弹出是dialog,是下拉筐等都是在这个js中配置
  25287. //自己写的ui也要在这里配置,放到baidu.editor.ui下边,当编辑器实例化的时候会根据ueditor.config中的toolbars找到相应的进行实例化
  25288. (function () {
  25289. var utils = baidu.editor.utils;
  25290. var editorui = baidu.editor.ui;
  25291. var _Dialog = editorui.Dialog;
  25292. editorui.buttons = {};
  25293. editorui.Dialog = function (options) {
  25294. var dialog = new _Dialog(options);
  25295. dialog.addListener('hide', function () {
  25296. if (dialog.editor) {
  25297. var editor = dialog.editor;
  25298. try {
  25299. if (browser.gecko) {
  25300. var y = editor.window.scrollY,
  25301. x = editor.window.scrollX;
  25302. editor.body.focus();
  25303. editor.window.scrollTo(x, y);
  25304. } else {
  25305. editor.focus();
  25306. }
  25307. } catch (ex) {
  25308. }
  25309. }
  25310. });
  25311. return dialog;
  25312. };
  25313. var iframeUrlMap = {
  25314. 'anchor':'~/dialogs/anchor/anchor.html',
  25315. 'insertimage':'~/dialogs/image/image.html',
  25316. 'link':'~/dialogs/link/link.html',
  25317. 'spechars':'~/dialogs/spechars/spechars.html',
  25318. 'searchreplace':'~/dialogs/searchreplace/searchreplace.html',
  25319. 'map':'~/dialogs/map/map.html',
  25320. 'gmap':'~/dialogs/gmap/gmap.html',
  25321. 'insertvideo':'~/dialogs/video/video.html',
  25322. 'help':'~/dialogs/help/help.html',
  25323. 'preview':'~/dialogs/preview/preview.html',
  25324. 'emotion':'~/dialogs/emotion/emotion.html',
  25325. 'wordimage':'~/dialogs/wordimage/wordimage.html',
  25326. 'attachment':'~/dialogs/attachment/attachment.html',
  25327. 'insertframe':'~/dialogs/insertframe/insertframe.html',
  25328. 'edittip':'~/dialogs/table/edittip.html',
  25329. 'edittable':'~/dialogs/table/edittable.html',
  25330. 'edittd':'~/dialogs/table/edittd.html',
  25331. 'webapp':'~/dialogs/webapp/webapp.html',
  25332. 'snapscreen':'~/dialogs/snapscreen/snapscreen.html',
  25333. 'scrawl':'~/dialogs/scrawl/scrawl.html',
  25334. 'music':'~/dialogs/music/music.html',
  25335. 'template':'~/dialogs/template/template.html',
  25336. 'background':'~/dialogs/background/background.html',
  25337. 'charts': '~/dialogs/charts/charts.html'
  25338. };
  25339. //为工具栏添加按钮,以下都是统一的按钮触发命令,所以写在一起
  25340. var btnCmds = ['undo', 'redo', 'formatmatch',
  25341. 'bold', 'italic', 'underline', 'fontborder', 'touppercase', 'tolowercase',
  25342. 'strikethrough', 'subscript', 'superscript', 'source', 'indent', 'outdent',
  25343. 'blockquote', 'pasteplain', 'pagebreak',
  25344. 'selectall', 'print','horizontal', 'removeformat', 'time', 'date', 'unlink',
  25345. 'insertparagraphbeforetable', 'insertrow', 'insertcol', 'mergeright', 'mergedown', 'deleterow',
  25346. 'deletecol', 'splittorows', 'splittocols', 'splittocells', 'mergecells', 'deletetable', 'drafts'];
  25347. for (var i = 0, ci; ci = btnCmds[i++];) {
  25348. ci = ci.toLowerCase();
  25349. editorui[ci] = function (cmd) {
  25350. return function (editor) {
  25351. var ui = new editorui.Button({
  25352. className:'edui-for-' + cmd,
  25353. title:editor.options.labelMap[cmd] || editor.getLang("labelMap." + cmd) || '',
  25354. onclick:function () {
  25355. editor.execCommand(cmd);
  25356. },
  25357. theme:editor.options.theme,
  25358. showText:false
  25359. });
  25360. editorui.buttons[cmd] = ui;
  25361. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25362. var state = editor.queryCommandState(cmd);
  25363. if (state == -1) {
  25364. ui.setDisabled(true);
  25365. ui.setChecked(false);
  25366. } else {
  25367. if (!uiReady) {
  25368. ui.setDisabled(false);
  25369. ui.setChecked(state);
  25370. }
  25371. }
  25372. });
  25373. return ui;
  25374. };
  25375. }(ci);
  25376. }
  25377. //清除文档
  25378. editorui.cleardoc = function (editor) {
  25379. var ui = new editorui.Button({
  25380. className:'edui-for-cleardoc',
  25381. title:editor.options.labelMap.cleardoc || editor.getLang("labelMap.cleardoc") || '',
  25382. theme:editor.options.theme,
  25383. onclick:function () {
  25384. if (confirm(editor.getLang("confirmClear"))) {
  25385. editor.execCommand('cleardoc');
  25386. }
  25387. }
  25388. });
  25389. editorui.buttons["cleardoc"] = ui;
  25390. editor.addListener('selectionchange', function () {
  25391. ui.setDisabled(editor.queryCommandState('cleardoc') == -1);
  25392. });
  25393. return ui;
  25394. };
  25395. //排版,图片排版,文字方向
  25396. var typeset = {
  25397. 'justify':['left', 'right', 'center', 'justify'],
  25398. 'imagefloat':['none', 'left', 'center', 'right'],
  25399. 'directionality':['ltr', 'rtl']
  25400. };
  25401. for (var p in typeset) {
  25402. (function (cmd, val) {
  25403. for (var i = 0, ci; ci = val[i++];) {
  25404. (function (cmd2) {
  25405. editorui[cmd.replace('float', '') + cmd2] = function (editor) {
  25406. var ui = new editorui.Button({
  25407. className:'edui-for-' + cmd.replace('float', '') + cmd2,
  25408. title:editor.options.labelMap[cmd.replace('float', '') + cmd2] || editor.getLang("labelMap." + cmd.replace('float', '') + cmd2) || '',
  25409. theme:editor.options.theme,
  25410. onclick:function () {
  25411. editor.execCommand(cmd, cmd2);
  25412. }
  25413. });
  25414. editorui.buttons[cmd] = ui;
  25415. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25416. ui.setDisabled(editor.queryCommandState(cmd) == -1);
  25417. ui.setChecked(editor.queryCommandValue(cmd) == cmd2 && !uiReady);
  25418. });
  25419. return ui;
  25420. };
  25421. })(ci)
  25422. }
  25423. })(p, typeset[p])
  25424. }
  25425. //字体颜色和背景颜色
  25426. for (var i = 0, ci; ci = ['backcolor', 'forecolor'][i++];) {
  25427. editorui[ci] = function (cmd) {
  25428. return function (editor) {
  25429. var ui = new editorui.ColorButton({
  25430. className:'edui-for-' + cmd,
  25431. color:'default',
  25432. title:editor.options.labelMap[cmd] || editor.getLang("labelMap." + cmd) || '',
  25433. editor:editor,
  25434. onpickcolor:function (t, color) {
  25435. editor.execCommand(cmd, color);
  25436. },
  25437. onpicknocolor:function () {
  25438. editor.execCommand(cmd, 'default');
  25439. this.setColor('transparent');
  25440. this.color = 'default';
  25441. },
  25442. onbuttonclick:function () {
  25443. editor.execCommand(cmd, this.color);
  25444. }
  25445. });
  25446. editorui.buttons[cmd] = ui;
  25447. editor.addListener('selectionchange', function () {
  25448. ui.setDisabled(editor.queryCommandState(cmd) == -1);
  25449. });
  25450. return ui;
  25451. };
  25452. }(ci);
  25453. }
  25454. var dialogBtns = {
  25455. noOk:['searchreplace', 'help', 'spechars', 'webapp','preview'],
  25456. ok:['attachment', 'anchor', 'link', 'insertimage', 'map', 'gmap', 'insertframe', 'wordimage',
  25457. 'insertvideo', 'insertframe', 'edittip', 'edittable', 'edittd', 'scrawl', 'template', 'music', 'background', 'charts']
  25458. };
  25459. for (var p in dialogBtns) {
  25460. (function (type, vals) {
  25461. for (var i = 0, ci; ci = vals[i++];) {
  25462. //todo opera下存在问题
  25463. if (browser.opera && ci === "searchreplace") {
  25464. continue;
  25465. }
  25466. (function (cmd) {
  25467. editorui[cmd] = function (editor, iframeUrl, title) {
  25468. iframeUrl = iframeUrl || (editor.options.iframeUrlMap || {})[cmd] || iframeUrlMap[cmd];
  25469. title = editor.options.labelMap[cmd] || editor.getLang("labelMap." + cmd) || '';
  25470. var dialog;
  25471. //没有iframeUrl不创建dialog
  25472. if (iframeUrl) {
  25473. dialog = new editorui.Dialog(utils.extend({
  25474. iframeUrl:editor.ui.mapUrl(iframeUrl),
  25475. editor:editor,
  25476. className:'edui-for-' + cmd,
  25477. title:title,
  25478. holdScroll: cmd === 'insertimage',
  25479. fullscreen: /charts|preview/.test(cmd),
  25480. closeDialog:editor.getLang("closeDialog")
  25481. }, type == 'ok' ? {
  25482. buttons:[
  25483. {
  25484. className:'edui-okbutton',
  25485. label:editor.getLang("ok"),
  25486. editor:editor,
  25487. onclick:function () {
  25488. dialog.close(true);
  25489. }
  25490. },
  25491. {
  25492. className:'edui-cancelbutton',
  25493. label:editor.getLang("cancel"),
  25494. editor:editor,
  25495. onclick:function () {
  25496. dialog.close(false);
  25497. }
  25498. }
  25499. ]
  25500. } : {}));
  25501. editor.ui._dialogs[cmd + "Dialog"] = dialog;
  25502. }
  25503. var ui = new editorui.Button({
  25504. className:'edui-for-' + cmd,
  25505. title:title,
  25506. onclick:function () {
  25507. if (dialog) {
  25508. switch (cmd) {
  25509. case "wordimage":
  25510. var images = editor.execCommand("wordimage");
  25511. if (images && images.length) {
  25512. dialog.render();
  25513. dialog.open();
  25514. }
  25515. break;
  25516. case "scrawl":
  25517. if (editor.queryCommandState("scrawl") != -1) {
  25518. dialog.render();
  25519. dialog.open();
  25520. }
  25521. break;
  25522. default:
  25523. dialog.render();
  25524. dialog.open();
  25525. }
  25526. }
  25527. },
  25528. theme:editor.options.theme,
  25529. disabled:(cmd == 'scrawl' && editor.queryCommandState("scrawl") == -1) || ( cmd == 'charts' )
  25530. });
  25531. editorui.buttons[cmd] = ui;
  25532. editor.addListener('selectionchange', function () {
  25533. //只存在于右键菜单而无工具栏按钮的ui不需要检测状态
  25534. var unNeedCheckState = {'edittable':1};
  25535. if (cmd in unNeedCheckState)return;
  25536. var state = editor.queryCommandState(cmd);
  25537. if (ui.getDom()) {
  25538. ui.setDisabled(state == -1);
  25539. ui.setChecked(state);
  25540. }
  25541. });
  25542. return ui;
  25543. };
  25544. })(ci.toLowerCase())
  25545. }
  25546. })(p, dialogBtns[p]);
  25547. }
  25548. editorui.snapscreen = function (editor, iframeUrl, title) {
  25549. title = editor.options.labelMap['snapscreen'] || editor.getLang("labelMap.snapscreen") || '';
  25550. var ui = new editorui.Button({
  25551. className:'edui-for-snapscreen',
  25552. title:title,
  25553. onclick:function () {
  25554. editor.execCommand("snapscreen");
  25555. },
  25556. theme:editor.options.theme
  25557. });
  25558. editorui.buttons['snapscreen'] = ui;
  25559. iframeUrl = iframeUrl || (editor.options.iframeUrlMap || {})["snapscreen"] || iframeUrlMap["snapscreen"];
  25560. if (iframeUrl) {
  25561. var dialog = new editorui.Dialog({
  25562. iframeUrl:editor.ui.mapUrl(iframeUrl),
  25563. editor:editor,
  25564. className:'edui-for-snapscreen',
  25565. title:title,
  25566. buttons:[
  25567. {
  25568. className:'edui-okbutton',
  25569. label:editor.getLang("ok"),
  25570. editor:editor,
  25571. onclick:function () {
  25572. dialog.close(true);
  25573. }
  25574. },
  25575. {
  25576. className:'edui-cancelbutton',
  25577. label:editor.getLang("cancel"),
  25578. editor:editor,
  25579. onclick:function () {
  25580. dialog.close(false);
  25581. }
  25582. }
  25583. ]
  25584. });
  25585. dialog.render();
  25586. editor.ui._dialogs["snapscreenDialog"] = dialog;
  25587. }
  25588. editor.addListener('selectionchange', function () {
  25589. ui.setDisabled(editor.queryCommandState('snapscreen') == -1);
  25590. });
  25591. return ui;
  25592. };
  25593. editorui.insertcode = function (editor, list, title) {
  25594. list = editor.options['insertcode'] || [];
  25595. title = editor.options.labelMap['insertcode'] || editor.getLang("labelMap.insertcode") || '';
  25596. // if (!list.length) return;
  25597. var items = [];
  25598. utils.each(list,function(key,val){
  25599. items.push({
  25600. label:key,
  25601. value:val,
  25602. theme:editor.options.theme,
  25603. renderLabelHtml:function () {
  25604. return '<div class="edui-label %%-label" >' + (this.label || '') + '</div>';
  25605. }
  25606. });
  25607. });
  25608. var ui = new editorui.Combox({
  25609. editor:editor,
  25610. items:items,
  25611. onselect:function (t, index) {
  25612. editor.execCommand('insertcode', this.items[index].value);
  25613. },
  25614. onbuttonclick:function () {
  25615. this.showPopup();
  25616. },
  25617. title:title,
  25618. initValue:title,
  25619. className:'edui-for-insertcode',
  25620. indexByValue:function (value) {
  25621. if (value) {
  25622. for (var i = 0, ci; ci = this.items[i]; i++) {
  25623. if (ci.value.indexOf(value) != -1)
  25624. return i;
  25625. }
  25626. }
  25627. return -1;
  25628. }
  25629. });
  25630. editorui.buttons['insertcode'] = ui;
  25631. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25632. if (!uiReady) {
  25633. var state = editor.queryCommandState('insertcode');
  25634. if (state == -1) {
  25635. ui.setDisabled(true);
  25636. } else {
  25637. ui.setDisabled(false);
  25638. var value = editor.queryCommandValue('insertcode');
  25639. if(!value){
  25640. ui.setValue(title);
  25641. return;
  25642. }
  25643. //trace:1871 ie下从源码模式切换回来时,字体会带单引号,而且会有逗号
  25644. value && (value = value.replace(/['"]/g, '').split(',')[0]);
  25645. ui.setValue(value);
  25646. }
  25647. }
  25648. });
  25649. return ui;
  25650. };
  25651. editorui.fontfamily = function (editor, list, title) {
  25652. list = editor.options['fontfamily'] || [];
  25653. title = editor.options.labelMap['fontfamily'] || editor.getLang("labelMap.fontfamily") || '';
  25654. if (!list.length) return;
  25655. for (var i = 0, ci, items = []; ci = list[i]; i++) {
  25656. var langLabel = editor.getLang('fontfamily')[ci.name] || "";
  25657. (function (key, val) {
  25658. items.push({
  25659. label:key,
  25660. value:val,
  25661. theme:editor.options.theme,
  25662. renderLabelHtml:function () {
  25663. return '<div class="edui-label %%-label" style="font-family:' +
  25664. utils.unhtml(this.value) + '">' + (this.label || '') + '</div>';
  25665. }
  25666. });
  25667. })(ci.label || langLabel, ci.val)
  25668. }
  25669. var ui = new editorui.Combox({
  25670. editor:editor,
  25671. items:items,
  25672. onselect:function (t, index) {
  25673. editor.execCommand('FontFamily', this.items[index].value);
  25674. },
  25675. onbuttonclick:function () {
  25676. this.showPopup();
  25677. },
  25678. title:title,
  25679. initValue:title,
  25680. className:'edui-for-fontfamily',
  25681. indexByValue:function (value) {
  25682. if (value) {
  25683. for (var i = 0, ci; ci = this.items[i]; i++) {
  25684. if (ci.value.indexOf(value) != -1)
  25685. return i;
  25686. }
  25687. }
  25688. return -1;
  25689. }
  25690. });
  25691. editorui.buttons['fontfamily'] = ui;
  25692. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25693. if (!uiReady) {
  25694. var state = editor.queryCommandState('FontFamily');
  25695. if (state == -1) {
  25696. ui.setDisabled(true);
  25697. } else {
  25698. ui.setDisabled(false);
  25699. var value = editor.queryCommandValue('FontFamily');
  25700. //trace:1871 ie下从源码模式切换回来时,字体会带单引号,而且会有逗号
  25701. value && (value = value.replace(/['"]/g, '').split(',')[0]);
  25702. ui.setValue(value);
  25703. }
  25704. }
  25705. });
  25706. return ui;
  25707. };
  25708. editorui.fontsize = function (editor, list, title) {
  25709. title = editor.options.labelMap['fontsize'] || editor.getLang("labelMap.fontsize") || '';
  25710. list = list || editor.options['fontsize'] || [];
  25711. if (!list.length) return;
  25712. var items = [];
  25713. for (var i = 0; i < list.length; i++) {
  25714. var size = list[i] + 'px';
  25715. items.push({
  25716. label:size,
  25717. value:size,
  25718. theme:editor.options.theme,
  25719. renderLabelHtml:function () {
  25720. return '<div class="edui-label %%-label" style="line-height:1;font-size:' +
  25721. this.value + '">' + (this.label || '') + '</div>';
  25722. }
  25723. });
  25724. }
  25725. var ui = new editorui.Combox({
  25726. editor:editor,
  25727. items:items,
  25728. title:title,
  25729. initValue:title,
  25730. onselect:function (t, index) {
  25731. editor.execCommand('FontSize', this.items[index].value);
  25732. },
  25733. onbuttonclick:function () {
  25734. this.showPopup();
  25735. },
  25736. className:'edui-for-fontsize'
  25737. });
  25738. editorui.buttons['fontsize'] = ui;
  25739. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25740. if (!uiReady) {
  25741. var state = editor.queryCommandState('FontSize');
  25742. if (state == -1) {
  25743. ui.setDisabled(true);
  25744. } else {
  25745. ui.setDisabled(false);
  25746. ui.setValue(editor.queryCommandValue('FontSize'));
  25747. }
  25748. }
  25749. });
  25750. return ui;
  25751. };
  25752. editorui.paragraph = function (editor, list, title) {
  25753. title = editor.options.labelMap['paragraph'] || editor.getLang("labelMap.paragraph") || '';
  25754. list = editor.options['paragraph'] || [];
  25755. if (utils.isEmptyObject(list)) return;
  25756. var items = [];
  25757. for (var i in list) {
  25758. items.push({
  25759. value:i,
  25760. label:list[i] || editor.getLang("paragraph")[i],
  25761. theme:editor.options.theme,
  25762. renderLabelHtml:function () {
  25763. return '<div class="edui-label %%-label"><span class="edui-for-' + this.value + '">' + (this.label || '') + '</span></div>';
  25764. }
  25765. })
  25766. }
  25767. var ui = new editorui.Combox({
  25768. editor:editor,
  25769. items:items,
  25770. title:title,
  25771. initValue:title,
  25772. className:'edui-for-paragraph',
  25773. onselect:function (t, index) {
  25774. editor.execCommand('Paragraph', this.items[index].value);
  25775. },
  25776. onbuttonclick:function () {
  25777. this.showPopup();
  25778. }
  25779. });
  25780. editorui.buttons['paragraph'] = ui;
  25781. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25782. if (!uiReady) {
  25783. var state = editor.queryCommandState('Paragraph');
  25784. if (state == -1) {
  25785. ui.setDisabled(true);
  25786. } else {
  25787. ui.setDisabled(false);
  25788. var value = editor.queryCommandValue('Paragraph');
  25789. var index = ui.indexByValue(value);
  25790. if (index != -1) {
  25791. ui.setValue(value);
  25792. } else {
  25793. ui.setValue(ui.initValue);
  25794. }
  25795. }
  25796. }
  25797. });
  25798. return ui;
  25799. };
  25800. //自定义标题
  25801. editorui.customstyle = function (editor) {
  25802. var list = editor.options['customstyle'] || [],
  25803. title = editor.options.labelMap['customstyle'] || editor.getLang("labelMap.customstyle") || '';
  25804. if (!list.length)return;
  25805. var langCs = editor.getLang('customstyle');
  25806. for (var i = 0, items = [], t; t = list[i++];) {
  25807. (function (t) {
  25808. var ck = {};
  25809. ck.label = t.label ? t.label : langCs[t.name];
  25810. ck.style = t.style;
  25811. ck.className = t.className;
  25812. ck.tag = t.tag;
  25813. items.push({
  25814. label:ck.label,
  25815. value:ck,
  25816. theme:editor.options.theme,
  25817. renderLabelHtml:function () {
  25818. return '<div class="edui-label %%-label">' + '<' + ck.tag + ' ' + (ck.className ? ' class="' + ck.className + '"' : "")
  25819. + (ck.style ? ' style="' + ck.style + '"' : "") + '>' + ck.label + "<\/" + ck.tag + ">"
  25820. + '</div>';
  25821. }
  25822. });
  25823. })(t);
  25824. }
  25825. var ui = new editorui.Combox({
  25826. editor:editor,
  25827. items:items,
  25828. title:title,
  25829. initValue:title,
  25830. className:'edui-for-customstyle',
  25831. onselect:function (t, index) {
  25832. editor.execCommand('customstyle', this.items[index].value);
  25833. },
  25834. onbuttonclick:function () {
  25835. this.showPopup();
  25836. },
  25837. indexByValue:function (value) {
  25838. for (var i = 0, ti; ti = this.items[i++];) {
  25839. if (ti.label == value) {
  25840. return i - 1
  25841. }
  25842. }
  25843. return -1;
  25844. }
  25845. });
  25846. editorui.buttons['customstyle'] = ui;
  25847. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25848. if (!uiReady) {
  25849. var state = editor.queryCommandState('customstyle');
  25850. if (state == -1) {
  25851. ui.setDisabled(true);
  25852. } else {
  25853. ui.setDisabled(false);
  25854. var value = editor.queryCommandValue('customstyle');
  25855. var index = ui.indexByValue(value);
  25856. if (index != -1) {
  25857. ui.setValue(value);
  25858. } else {
  25859. ui.setValue(ui.initValue);
  25860. }
  25861. }
  25862. }
  25863. });
  25864. return ui;
  25865. };
  25866. editorui.inserttable = function (editor, iframeUrl, title) {
  25867. title = editor.options.labelMap['inserttable'] || editor.getLang("labelMap.inserttable") || '';
  25868. var ui = new editorui.TableButton({
  25869. editor:editor,
  25870. title:title,
  25871. className:'edui-for-inserttable',
  25872. onpicktable:function (t, numCols, numRows) {
  25873. editor.execCommand('InsertTable', {numRows:numRows, numCols:numCols, border:1});
  25874. },
  25875. onbuttonclick:function () {
  25876. this.showPopup();
  25877. }
  25878. });
  25879. editorui.buttons['inserttable'] = ui;
  25880. editor.addListener('selectionchange', function () {
  25881. ui.setDisabled(editor.queryCommandState('inserttable') == -1);
  25882. });
  25883. return ui;
  25884. };
  25885. editorui.lineheight = function (editor) {
  25886. var val = editor.options.lineheight || [];
  25887. if (!val.length)return;
  25888. for (var i = 0, ci, items = []; ci = val[i++];) {
  25889. items.push({
  25890. //todo:写死了
  25891. label:ci,
  25892. value:ci,
  25893. theme:editor.options.theme,
  25894. onclick:function () {
  25895. editor.execCommand("lineheight", this.value);
  25896. }
  25897. })
  25898. }
  25899. var ui = new editorui.MenuButton({
  25900. editor:editor,
  25901. className:'edui-for-lineheight',
  25902. title:editor.options.labelMap['lineheight'] || editor.getLang("labelMap.lineheight") || '',
  25903. items:items,
  25904. onbuttonclick:function () {
  25905. var value = editor.queryCommandValue('LineHeight') || this.value;
  25906. editor.execCommand("LineHeight", value);
  25907. }
  25908. });
  25909. editorui.buttons['lineheight'] = ui;
  25910. editor.addListener('selectionchange', function () {
  25911. var state = editor.queryCommandState('LineHeight');
  25912. if (state == -1) {
  25913. ui.setDisabled(true);
  25914. } else {
  25915. ui.setDisabled(false);
  25916. var value = editor.queryCommandValue('LineHeight');
  25917. value && ui.setValue((value + '').replace(/cm/, ''));
  25918. ui.setChecked(state)
  25919. }
  25920. });
  25921. return ui;
  25922. };
  25923. var rowspacings = ['top', 'bottom'];
  25924. for (var r = 0, ri; ri = rowspacings[r++];) {
  25925. (function (cmd) {
  25926. editorui['rowspacing' + cmd] = function (editor) {
  25927. var val = editor.options['rowspacing' + cmd] || [];
  25928. if (!val.length) return null;
  25929. for (var i = 0, ci, items = []; ci = val[i++];) {
  25930. items.push({
  25931. label:ci,
  25932. value:ci,
  25933. theme:editor.options.theme,
  25934. onclick:function () {
  25935. editor.execCommand("rowspacing", this.value, cmd);
  25936. }
  25937. })
  25938. }
  25939. var ui = new editorui.MenuButton({
  25940. editor:editor,
  25941. className:'edui-for-rowspacing' + cmd,
  25942. title:editor.options.labelMap['rowspacing' + cmd] || editor.getLang("labelMap.rowspacing" + cmd) || '',
  25943. items:items,
  25944. onbuttonclick:function () {
  25945. var value = editor.queryCommandValue('rowspacing', cmd) || this.value;
  25946. editor.execCommand("rowspacing", value, cmd);
  25947. }
  25948. });
  25949. editorui.buttons[cmd] = ui;
  25950. editor.addListener('selectionchange', function () {
  25951. var state = editor.queryCommandState('rowspacing', cmd);
  25952. if (state == -1) {
  25953. ui.setDisabled(true);
  25954. } else {
  25955. ui.setDisabled(false);
  25956. var value = editor.queryCommandValue('rowspacing', cmd);
  25957. value && ui.setValue((value + '').replace(/%/, ''));
  25958. ui.setChecked(state)
  25959. }
  25960. });
  25961. return ui;
  25962. }
  25963. })(ri)
  25964. }
  25965. //有序,无序列表
  25966. var lists = ['insertorderedlist', 'insertunorderedlist'];
  25967. for (var l = 0, cl; cl = lists[l++];) {
  25968. (function (cmd) {
  25969. editorui[cmd] = function (editor) {
  25970. var vals = editor.options[cmd],
  25971. _onMenuClick = function () {
  25972. editor.execCommand(cmd, this.value);
  25973. }, items = [];
  25974. for (var i in vals) {
  25975. items.push({
  25976. label:vals[i] || editor.getLang()[cmd][i] || "",
  25977. value:i,
  25978. theme:editor.options.theme,
  25979. onclick:_onMenuClick
  25980. })
  25981. }
  25982. var ui = new editorui.MenuButton({
  25983. editor:editor,
  25984. className:'edui-for-' + cmd,
  25985. title:editor.getLang("labelMap." + cmd) || '',
  25986. 'items':items,
  25987. onbuttonclick:function () {
  25988. var value = editor.queryCommandValue(cmd) || this.value;
  25989. editor.execCommand(cmd, value);
  25990. }
  25991. });
  25992. editorui.buttons[cmd] = ui;
  25993. editor.addListener('selectionchange', function () {
  25994. var state = editor.queryCommandState(cmd);
  25995. if (state == -1) {
  25996. ui.setDisabled(true);
  25997. } else {
  25998. ui.setDisabled(false);
  25999. var value = editor.queryCommandValue(cmd);
  26000. ui.setValue(value);
  26001. ui.setChecked(state)
  26002. }
  26003. });
  26004. return ui;
  26005. };
  26006. })(cl)
  26007. }
  26008. editorui.fullscreen = function (editor, title) {
  26009. title = editor.options.labelMap['fullscreen'] || editor.getLang("labelMap.fullscreen") || '';
  26010. var ui = new editorui.Button({
  26011. className:'edui-for-fullscreen',
  26012. title:title,
  26013. theme:editor.options.theme,
  26014. onclick:function () {
  26015. if (editor.ui) {
  26016. editor.ui.setFullScreen(!editor.ui.isFullScreen());
  26017. }
  26018. this.setChecked(editor.ui.isFullScreen());
  26019. }
  26020. });
  26021. editorui.buttons['fullscreen'] = ui;
  26022. editor.addListener('selectionchange', function () {
  26023. var state = editor.queryCommandState('fullscreen');
  26024. ui.setDisabled(state == -1);
  26025. ui.setChecked(editor.ui.isFullScreen());
  26026. });
  26027. return ui;
  26028. };
  26029. // 表情
  26030. editorui["emotion"] = function (editor, iframeUrl) {
  26031. var cmd = "emotion";
  26032. var ui = new editorui.MultiMenuPop({
  26033. title:editor.options.labelMap[cmd] || editor.getLang("labelMap." + cmd + "") || '',
  26034. editor:editor,
  26035. className:'edui-for-' + cmd,
  26036. iframeUrl:editor.ui.mapUrl(iframeUrl || (editor.options.iframeUrlMap || {})[cmd] || iframeUrlMap[cmd])
  26037. });
  26038. editorui.buttons[cmd] = ui;
  26039. editor.addListener('selectionchange', function () {
  26040. ui.setDisabled(editor.queryCommandState(cmd) == -1)
  26041. });
  26042. return ui;
  26043. };
  26044. editorui.autotypeset = function (editor) {
  26045. var ui = new editorui.AutoTypeSetButton({
  26046. editor:editor,
  26047. title:editor.options.labelMap['autotypeset'] || editor.getLang("labelMap.autotypeset") || '',
  26048. className:'edui-for-autotypeset',
  26049. onbuttonclick:function () {
  26050. editor.execCommand('autotypeset')
  26051. }
  26052. });
  26053. editorui.buttons['autotypeset'] = ui;
  26054. editor.addListener('selectionchange', function () {
  26055. ui.setDisabled(editor.queryCommandState('autotypeset') == -1);
  26056. });
  26057. return ui;
  26058. };
  26059. /* 简单上传插件 */
  26060. editorui["simpleupload"] = function (editor) {
  26061. var name = 'simpleupload',
  26062. ui = new editorui.Button({
  26063. className:'edui-for-' + name,
  26064. title:editor.options.labelMap[name] || editor.getLang("labelMap." + name) || '',
  26065. onclick:function () {},
  26066. theme:editor.options.theme,
  26067. showText:false
  26068. });
  26069. editorui.buttons[name] = ui;
  26070. editor.addListener('ready', function() {
  26071. var b = ui.getDom('body'),
  26072. iconSpan = b.children[0];
  26073. editor.fireEvent('simpleuploadbtnready', iconSpan);
  26074. });
  26075. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  26076. var state = editor.queryCommandState(name);
  26077. if (state == -1) {
  26078. ui.setDisabled(true);
  26079. ui.setChecked(false);
  26080. } else {
  26081. if (!uiReady) {
  26082. ui.setDisabled(false);
  26083. ui.setChecked(state);
  26084. }
  26085. }
  26086. });
  26087. return ui;
  26088. };
  26089. })();
  26090. // js/editor/_src/adapter/editor.js
  26091. ///import core
  26092. ///commands 全屏
  26093. ///commandsName FullScreen
  26094. ///commandsTitle 全屏
  26095. (function () {
  26096. var utils = baidu.editor.utils,
  26097. uiUtils = baidu.editor.ui.uiUtils,
  26098. UIBase = baidu.editor.ui.UIBase,
  26099. domUtils = baidu.editor.dom.domUtils;
  26100. var nodeStack = [];
  26101. function EditorUI(options) {
  26102. this.initOptions(options);
  26103. this.initEditorUI();
  26104. }
  26105. EditorUI.prototype = {
  26106. uiName:'editor',
  26107. initEditorUI:function () {
  26108. this.editor.ui = this;
  26109. this._dialogs = {};
  26110. this.initUIBase();
  26111. this._initToolbars();
  26112. var editor = this.editor,
  26113. me = this;
  26114. editor.addListener('ready', function () {
  26115. //提供getDialog方法
  26116. editor.getDialog = function (name) {
  26117. return editor.ui._dialogs[name + "Dialog"];
  26118. };
  26119. domUtils.on(editor.window, 'scroll', function (evt) {
  26120. baidu.editor.ui.Popup.postHide(evt);
  26121. });
  26122. //提供编辑器实时宽高(全屏时宽高不变化)
  26123. editor.ui._actualFrameWidth = editor.options.initialFrameWidth;
  26124. UE.browser.ie && UE.browser.version === 6 && editor.container.ownerDocument.execCommand("BackgroundImageCache", false, true);
  26125. //display bottom-bar label based on config
  26126. if (editor.options.elementPathEnabled) {
  26127. editor.ui.getDom('elementpath').innerHTML = '<div class="edui-editor-breadcrumb">' + editor.getLang("elementPathTip") + ':</div>';
  26128. }
  26129. if (editor.options.wordCount) {
  26130. function countFn() {
  26131. setCount(editor,me);
  26132. domUtils.un(editor.document, "click", arguments.callee);
  26133. }
  26134. domUtils.on(editor.document, "click", countFn);
  26135. editor.ui.getDom('wordcount').innerHTML = editor.getLang("wordCountTip");
  26136. }
  26137. editor.ui._scale();
  26138. if (editor.options.scaleEnabled) {
  26139. if (editor.autoHeightEnabled) {
  26140. editor.disableAutoHeight();
  26141. }
  26142. me.enableScale();
  26143. } else {
  26144. me.disableScale();
  26145. }
  26146. if (!editor.options.elementPathEnabled && !editor.options.wordCount && !editor.options.scaleEnabled) {
  26147. editor.ui.getDom('elementpath').style.display = "none";
  26148. editor.ui.getDom('wordcount').style.display = "none";
  26149. editor.ui.getDom('scale').style.display = "none";
  26150. }
  26151. if (!editor.selection.isFocus())return;
  26152. editor.fireEvent('selectionchange', false, true);
  26153. });
  26154. editor.addListener('mousedown', function (t, evt) {
  26155. var el = evt.target || evt.srcElement;
  26156. baidu.editor.ui.Popup.postHide(evt, el);
  26157. baidu.editor.ui.ShortCutMenu.postHide(evt);
  26158. });
  26159. editor.addListener("delcells", function () {
  26160. if (UE.ui['edittip']) {
  26161. new UE.ui['edittip'](editor);
  26162. }
  26163. editor.getDialog('edittip').open();
  26164. });
  26165. var pastePop, isPaste = false, timer;
  26166. editor.addListener("afterpaste", function () {
  26167. if(editor.queryCommandState('pasteplain'))
  26168. return;
  26169. if(baidu.editor.ui.PastePicker){
  26170. pastePop = new baidu.editor.ui.Popup({
  26171. content:new baidu.editor.ui.PastePicker({editor:editor}),
  26172. editor:editor,
  26173. className:'edui-wordpastepop'
  26174. });
  26175. pastePop.render();
  26176. }
  26177. isPaste = true;
  26178. });
  26179. editor.addListener("afterinserthtml", function () {
  26180. clearTimeout(timer);
  26181. timer = setTimeout(function () {
  26182. if (pastePop && (isPaste || editor.ui._isTransfer)) {
  26183. if(pastePop.isHidden()){
  26184. var span = domUtils.createElement(editor.document, 'span', {
  26185. 'style':"line-height:0px;",
  26186. 'innerHTML':'\ufeff'
  26187. }),
  26188. range = editor.selection.getRange();
  26189. range.insertNode(span);
  26190. var tmp= getDomNode(span, 'firstChild', 'previousSibling');
  26191. tmp && pastePop.showAnchor(tmp.nodeType == 3 ? tmp.parentNode : tmp);
  26192. domUtils.remove(span);
  26193. }else{
  26194. pastePop.show();
  26195. }
  26196. delete editor.ui._isTransfer;
  26197. isPaste = false;
  26198. }
  26199. }, 200)
  26200. });
  26201. editor.addListener('contextmenu', function (t, evt) {
  26202. baidu.editor.ui.Popup.postHide(evt);
  26203. });
  26204. editor.addListener('keydown', function (t, evt) {
  26205. if (pastePop) pastePop.dispose(evt);
  26206. var keyCode = evt.keyCode || evt.which;
  26207. if(evt.altKey&&keyCode==90){
  26208. UE.ui.buttons['fullscreen'].onclick();
  26209. }
  26210. });
  26211. editor.addListener('wordcount', function (type) {
  26212. setCount(this,me);
  26213. });
  26214. function setCount(editor,ui) {
  26215. editor.setOpt({
  26216. wordCount:true,
  26217. maximumWords:10000,
  26218. wordCountMsg:editor.options.wordCountMsg || editor.getLang("wordCountMsg"),
  26219. wordOverFlowMsg:editor.options.wordOverFlowMsg || editor.getLang("wordOverFlowMsg")
  26220. });
  26221. var opt = editor.options,
  26222. max = opt.maximumWords,
  26223. msg = opt.wordCountMsg ,
  26224. errMsg = opt.wordOverFlowMsg,
  26225. countDom = ui.getDom('wordcount');
  26226. if (!opt.wordCount) {
  26227. return;
  26228. }
  26229. var count = editor.getContentLength(true);
  26230. if (count > max) {
  26231. countDom.innerHTML = errMsg;
  26232. editor.fireEvent("wordcountoverflow");
  26233. } else {
  26234. countDom.innerHTML = msg.replace("{#leave}", max - count).replace("{#count}", count);
  26235. }
  26236. }
  26237. editor.addListener('selectionchange', function () {
  26238. if (editor.options.elementPathEnabled) {
  26239. me[(editor.queryCommandState('elementpath') == -1 ? 'dis' : 'en') + 'ableElementPath']()
  26240. }
  26241. if (editor.options.scaleEnabled) {
  26242. me[(editor.queryCommandState('scale') == -1 ? 'dis' : 'en') + 'ableScale']();
  26243. }
  26244. });
  26245. var popup = new baidu.editor.ui.Popup({
  26246. editor:editor,
  26247. content:'',
  26248. className:'edui-bubble',
  26249. _onEditButtonClick:function () {
  26250. this.hide();
  26251. editor.ui._dialogs.linkDialog.open();
  26252. },
  26253. _onImgEditButtonClick:function (name) {
  26254. this.hide();
  26255. editor.ui._dialogs[name] && editor.ui._dialogs[name].open();
  26256. },
  26257. _onImgSetFloat:function (value) {
  26258. this.hide();
  26259. editor.execCommand("imagefloat", value);
  26260. },
  26261. _setIframeAlign:function (value) {
  26262. var frame = popup.anchorEl;
  26263. var newFrame = frame.cloneNode(true);
  26264. switch (value) {
  26265. case -2:
  26266. newFrame.setAttribute("align", "");
  26267. break;
  26268. case -1:
  26269. newFrame.setAttribute("align", "left");
  26270. break;
  26271. case 1:
  26272. newFrame.setAttribute("align", "right");
  26273. break;
  26274. }
  26275. frame.parentNode.insertBefore(newFrame, frame);
  26276. domUtils.remove(frame);
  26277. popup.anchorEl = newFrame;
  26278. popup.showAnchor(popup.anchorEl);
  26279. },
  26280. _updateIframe:function () {
  26281. var frame = editor._iframe = popup.anchorEl;
  26282. if(domUtils.hasClass(frame, 'ueditor_baidumap')) {
  26283. editor.selection.getRange().selectNode(frame).select();
  26284. editor.ui._dialogs.mapDialog.open();
  26285. popup.hide();
  26286. } else {
  26287. editor.ui._dialogs.insertframeDialog.open();
  26288. popup.hide();
  26289. }
  26290. },
  26291. _onRemoveButtonClick:function (cmdName) {
  26292. editor.execCommand(cmdName);
  26293. this.hide();
  26294. },
  26295. queryAutoHide:function (el) {
  26296. if (el && el.ownerDocument == editor.document) {
  26297. if (el.tagName.toLowerCase() == 'img' || domUtils.findParentByTagName(el, 'a', true)) {
  26298. return el !== popup.anchorEl;
  26299. }
  26300. }
  26301. return baidu.editor.ui.Popup.prototype.queryAutoHide.call(this, el);
  26302. }
  26303. });
  26304. popup.render();
  26305. if (editor.options.imagePopup) {
  26306. editor.addListener('mouseover', function (t, evt) {
  26307. evt = evt || window.event;
  26308. var el = evt.target || evt.srcElement;
  26309. if (editor.ui._dialogs.insertframeDialog && /iframe/ig.test(el.tagName)) {
  26310. var html = popup.formatHtml(
  26311. '<nobr>' + editor.getLang("property") + ': <span onclick=$$._setIframeAlign(-2) class="edui-clickable">' + editor.getLang("default") + '</span>&nbsp;&nbsp;<span onclick=$$._setIframeAlign(-1) class="edui-clickable">' + editor.getLang("justifyleft") + '</span>&nbsp;&nbsp;<span onclick=$$._setIframeAlign(1) class="edui-clickable">' + editor.getLang("justifyright") + '</span>&nbsp;&nbsp;' +
  26312. ' <span onclick="$$._updateIframe( this);" class="edui-clickable">' + editor.getLang("modify") + '</span></nobr>');
  26313. if (html) {
  26314. popup.getDom('content').innerHTML = html;
  26315. popup.anchorEl = el;
  26316. popup.showAnchor(popup.anchorEl);
  26317. } else {
  26318. popup.hide();
  26319. }
  26320. }
  26321. });
  26322. editor.addListener('selectionchange', function (t, causeByUi) {
  26323. if (!causeByUi) return;
  26324. var html = '', str = "",
  26325. img = editor.selection.getRange().getClosedNode(),
  26326. dialogs = editor.ui._dialogs;
  26327. if (img && img.tagName == 'IMG') {
  26328. var dialogName = 'insertimageDialog';
  26329. if (img.className.indexOf("edui-faked-video") != -1 || img.className.indexOf("edui-upload-video") != -1) {
  26330. dialogName = "insertvideoDialog"
  26331. }
  26332. if (img.className.indexOf("edui-faked-webapp") != -1) {
  26333. dialogName = "webappDialog"
  26334. }
  26335. if (img.src.indexOf("http://api.map.baidu.com") != -1) {
  26336. dialogName = "mapDialog"
  26337. }
  26338. if (img.className.indexOf("edui-faked-music") != -1) {
  26339. dialogName = "musicDialog"
  26340. }
  26341. if (img.src.indexOf("http://maps.google.com/maps/api/staticmap") != -1) {
  26342. dialogName = "gmapDialog"
  26343. }
  26344. if (img.getAttribute("anchorname")) {
  26345. dialogName = "anchorDialog";
  26346. html = popup.formatHtml(
  26347. '<nobr>' + editor.getLang("property") + ': <span onclick=$$._onImgEditButtonClick("anchorDialog") class="edui-clickable">' + editor.getLang("modify") + '</span>&nbsp;&nbsp;' +
  26348. '<span onclick=$$._onRemoveButtonClick(\'anchor\') class="edui-clickable">' + editor.getLang("delete") + '</span></nobr>');
  26349. }
  26350. if (img.getAttribute("word_img")) {
  26351. //todo 放到dialog去做查询
  26352. editor.word_img = [img.getAttribute("word_img")];
  26353. dialogName = "wordimageDialog"
  26354. }
  26355. if(domUtils.hasClass(img, 'loadingclass') || domUtils.hasClass(img, 'loaderrorclass')) {
  26356. dialogName = "";
  26357. }
  26358. if (!dialogs[dialogName]) {
  26359. return;
  26360. }
  26361. str = '<nobr>' + editor.getLang("property") + ': '+
  26362. '<span onclick=$$._onImgSetFloat("none") class="edui-clickable">' + editor.getLang("default") + '</span>&nbsp;&nbsp;' +
  26363. '<span onclick=$$._onImgSetFloat("left") class="edui-clickable">' + editor.getLang("justifyleft") + '</span>&nbsp;&nbsp;' +
  26364. '<span onclick=$$._onImgSetFloat("right") class="edui-clickable">' + editor.getLang("justifyright") + '</span>&nbsp;&nbsp;' +
  26365. '<span onclick=$$._onImgSetFloat("center") class="edui-clickable">' + editor.getLang("justifycenter") + '</span>&nbsp;&nbsp;'+
  26366. '<span onclick="$$._onImgEditButtonClick(\'' + dialogName + '\');" class="edui-clickable">' + editor.getLang("modify") + '</span></nobr>';
  26367. !html && (html = popup.formatHtml(str))
  26368. }
  26369. if (editor.ui._dialogs.linkDialog) {
  26370. var link = editor.queryCommandValue('link');
  26371. var url;
  26372. if (link && (url = (link.getAttribute('_href') || link.getAttribute('href', 2)))) {
  26373. var txt = url;
  26374. if (url.length > 30) {
  26375. txt = url.substring(0, 20) + "...";
  26376. }
  26377. if (html) {
  26378. html += '<div style="height:5px;"></div>'
  26379. }
  26380. html += popup.formatHtml(
  26381. '<nobr>' + editor.getLang("anthorMsg") + ': <a target="_blank" href="' + url + '" title="' + url + '" >' + txt + '</a>' +
  26382. ' <span class="edui-clickable" onclick="$$._onEditButtonClick();">' + editor.getLang("modify") + '</span>' +
  26383. ' <span class="edui-clickable" onclick="$$._onRemoveButtonClick(\'unlink\');"> ' + editor.getLang("clear") + '</span></nobr>');
  26384. popup.showAnchor(link);
  26385. }
  26386. }
  26387. if (html) {
  26388. popup.getDom('content').innerHTML = html;
  26389. popup.anchorEl = img || link;
  26390. popup.showAnchor(popup.anchorEl);
  26391. } else {
  26392. popup.hide();
  26393. }
  26394. });
  26395. }
  26396. },
  26397. _initToolbars:function () {
  26398. var editor = this.editor;
  26399. var toolbars = this.toolbars || [];
  26400. var toolbarUis = [];
  26401. for (var i = 0; i < toolbars.length; i++) {
  26402. var toolbar = toolbars[i];
  26403. var toolbarUi = new baidu.editor.ui.Toolbar({theme:editor.options.theme});
  26404. for (var j = 0; j < toolbar.length; j++) {
  26405. var toolbarItem = toolbar[j];
  26406. var toolbarItemUi = null;
  26407. if (typeof toolbarItem == 'string') {
  26408. toolbarItem = toolbarItem.toLowerCase();
  26409. if (toolbarItem == '|') {
  26410. toolbarItem = 'Separator';
  26411. }
  26412. if(toolbarItem == '||'){
  26413. toolbarItem = 'Breakline';
  26414. }
  26415. if (baidu.editor.ui[toolbarItem]) {
  26416. toolbarItemUi = new baidu.editor.ui[toolbarItem](editor);
  26417. }
  26418. //fullscreen这里单独处理一下,放到首行去
  26419. if (toolbarItem == 'fullscreen') {
  26420. if (toolbarUis && toolbarUis[0]) {
  26421. toolbarUis[0].items.splice(0, 0, toolbarItemUi);
  26422. } else {
  26423. toolbarItemUi && toolbarUi.items.splice(0, 0, toolbarItemUi);
  26424. }
  26425. continue;
  26426. }
  26427. } else {
  26428. toolbarItemUi = toolbarItem;
  26429. }
  26430. if (toolbarItemUi && toolbarItemUi.id) {
  26431. toolbarUi.add(toolbarItemUi);
  26432. }
  26433. }
  26434. toolbarUis[i] = toolbarUi;
  26435. }
  26436. //接受外部定制的UI
  26437. utils.each(UE._customizeUI,function(obj,key){
  26438. var itemUI,index;
  26439. if(obj.id && obj.id != editor.key){
  26440. return false;
  26441. }
  26442. itemUI = obj.execFn.call(editor,editor,key);
  26443. if(itemUI){
  26444. index = obj.index;
  26445. if(index === undefined){
  26446. index = toolbarUi.items.length;
  26447. }
  26448. toolbarUi.add(itemUI,index)
  26449. }
  26450. });
  26451. this.toolbars = toolbarUis;
  26452. },
  26453. getHtmlTpl:function () {
  26454. return '<div id="##" class="%%">' +
  26455. '<div id="##_toolbarbox" class="%%-toolbarbox">' +
  26456. (this.toolbars.length ?
  26457. '<div id="##_toolbarboxouter" class="%%-toolbarboxouter"><div class="%%-toolbarboxinner">' +
  26458. this.renderToolbarBoxHtml() +
  26459. '</div></div>' : '') +
  26460. '<div id="##_toolbarmsg" class="%%-toolbarmsg" style="display:none;">' +
  26461. '<div id = "##_upload_dialog" class="%%-toolbarmsg-upload" onclick="$$.showWordImageDialog();">' + this.editor.getLang("clickToUpload") + '</div>' +
  26462. '<div class="%%-toolbarmsg-close" onclick="$$.hideToolbarMsg();">x</div>' +
  26463. '<div id="##_toolbarmsg_label" class="%%-toolbarmsg-label"></div>' +
  26464. '<div style="height:0;overflow:hidden;clear:both;"></div>' +
  26465. '</div>' +
  26466. '<div id="##_message_holder" class="%%-messageholder"></div>' +
  26467. '</div>' +
  26468. '<div id="##_iframeholder" class="%%-iframeholder">' +
  26469. '</div>' +
  26470. //modify wdcount by matao
  26471. '<div id="##_bottombar" class="%%-bottomContainer"><table><tr>' +
  26472. '<td id="##_elementpath" class="%%-bottombar"></td>' +
  26473. '<td id="##_wordcount" class="%%-wordcount"></td>' +
  26474. '<td id="##_scale" class="%%-scale"><div class="%%-icon"></div></td>' +
  26475. '</tr></table></div>' +
  26476. '<div id="##_scalelayer"></div>' +
  26477. '</div>';
  26478. },
  26479. showWordImageDialog:function () {
  26480. this._dialogs['wordimageDialog'].open();
  26481. },
  26482. renderToolbarBoxHtml:function () {
  26483. var buff = [];
  26484. for (var i = 0; i < this.toolbars.length; i++) {
  26485. buff.push(this.toolbars[i].renderHtml());
  26486. }
  26487. return buff.join('');
  26488. },
  26489. setFullScreen:function (fullscreen) {
  26490. var editor = this.editor,
  26491. container = editor.container.parentNode.parentNode;
  26492. if (this._fullscreen != fullscreen) {
  26493. this._fullscreen = fullscreen;
  26494. this.editor.fireEvent('beforefullscreenchange', fullscreen);
  26495. if (baidu.editor.browser.gecko) {
  26496. var bk = editor.selection.getRange().createBookmark();
  26497. }
  26498. if (fullscreen) {
  26499. while (container.tagName != "BODY") {
  26500. var position = baidu.editor.dom.domUtils.getComputedStyle(container, "position");
  26501. nodeStack.push(position);
  26502. container.style.position = "static";
  26503. container = container.parentNode;
  26504. }
  26505. this._bakHtmlOverflow = document.documentElement.style.overflow;
  26506. this._bakBodyOverflow = document.body.style.overflow;
  26507. this._bakAutoHeight = this.editor.autoHeightEnabled;
  26508. this._bakScrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
  26509. this._bakEditorContaninerWidth = editor.iframe.parentNode.offsetWidth;
  26510. if (this._bakAutoHeight) {
  26511. //当全屏时不能执行自动长高
  26512. editor.autoHeightEnabled = false;
  26513. this.editor.disableAutoHeight();
  26514. }
  26515. document.documentElement.style.overflow = 'hidden';
  26516. //修复,滚动条不收起的问题
  26517. window.scrollTo(0,window.scrollY);
  26518. this._bakCssText = this.getDom().style.cssText;
  26519. this._bakCssText1 = this.getDom('iframeholder').style.cssText;
  26520. editor.iframe.parentNode.style.width = '';
  26521. this._updateFullScreen();
  26522. } else {
  26523. while (container.tagName != "BODY") {
  26524. container.style.position = nodeStack.shift();
  26525. container = container.parentNode;
  26526. }
  26527. this.getDom().style.cssText = this._bakCssText;
  26528. this.getDom('iframeholder').style.cssText = this._bakCssText1;
  26529. if (this._bakAutoHeight) {
  26530. editor.autoHeightEnabled = true;
  26531. this.editor.enableAutoHeight();
  26532. }
  26533. document.documentElement.style.overflow = this._bakHtmlOverflow;
  26534. document.body.style.overflow = this._bakBodyOverflow;
  26535. editor.iframe.parentNode.style.width = this._bakEditorContaninerWidth + 'px';
  26536. window.scrollTo(0, this._bakScrollTop);
  26537. }
  26538. if (browser.gecko && editor.body.contentEditable === 'true') {
  26539. var input = document.createElement('input');
  26540. document.body.appendChild(input);
  26541. editor.body.contentEditable = false;
  26542. setTimeout(function () {
  26543. input.focus();
  26544. setTimeout(function () {
  26545. editor.body.contentEditable = true;
  26546. editor.fireEvent('fullscreenchanged', fullscreen);
  26547. editor.selection.getRange().moveToBookmark(bk).select(true);
  26548. baidu.editor.dom.domUtils.remove(input);
  26549. fullscreen && window.scroll(0, 0);
  26550. }, 0)
  26551. }, 0)
  26552. }
  26553. if(editor.body.contentEditable === 'true'){
  26554. this.editor.fireEvent('fullscreenchanged', fullscreen);
  26555. this.triggerLayout();
  26556. }
  26557. }
  26558. },
  26559. _updateFullScreen:function () {
  26560. if (this._fullscreen) {
  26561. var vpRect = uiUtils.getViewportRect();
  26562. this.getDom().style.cssText = 'border:0;position:absolute;left:0;top:' + (this.editor.options.topOffset || 0) + 'px;width:' + vpRect.width + 'px;height:' + vpRect.height + 'px;z-index:' + (this.getDom().style.zIndex * 1 + 100);
  26563. uiUtils.setViewportOffset(this.getDom(), { left:0, top:this.editor.options.topOffset || 0 });
  26564. this.editor.setHeight(vpRect.height - this.getDom('toolbarbox').offsetHeight - this.getDom('bottombar').offsetHeight - (this.editor.options.topOffset || 0),true);
  26565. //不手动调一下,会导致全屏失效
  26566. if(browser.gecko){
  26567. try{
  26568. window.onresize();
  26569. }catch(e){
  26570. }
  26571. }
  26572. }
  26573. },
  26574. _updateElementPath:function () {
  26575. var bottom = this.getDom('elementpath'), list;
  26576. if (this.elementPathEnabled && (list = this.editor.queryCommandValue('elementpath'))) {
  26577. var buff = [];
  26578. for (var i = 0, ci; ci = list[i]; i++) {
  26579. buff[i] = this.formatHtml('<span unselectable="on" onclick="$$.editor.execCommand(&quot;elementpath&quot;, &quot;' + i + '&quot;);">' + ci + '</span>');
  26580. }
  26581. bottom.innerHTML = '<div class="edui-editor-breadcrumb" onmousedown="return false;">' + this.editor.getLang("elementPathTip") + ': ' + buff.join(' &gt; ') + '</div>';
  26582. } else {
  26583. bottom.style.display = 'none'
  26584. }
  26585. },
  26586. disableElementPath:function () {
  26587. var bottom = this.getDom('elementpath');
  26588. bottom.innerHTML = '';
  26589. bottom.style.display = 'none';
  26590. this.elementPathEnabled = false;
  26591. },
  26592. enableElementPath:function () {
  26593. var bottom = this.getDom('elementpath');
  26594. bottom.style.display = '';
  26595. this.elementPathEnabled = true;
  26596. this._updateElementPath();
  26597. },
  26598. _scale:function () {
  26599. var doc = document,
  26600. editor = this.editor,
  26601. editorHolder = editor.container,
  26602. editorDocument = editor.document,
  26603. toolbarBox = this.getDom("toolbarbox"),
  26604. bottombar = this.getDom("bottombar"),
  26605. scale = this.getDom("scale"),
  26606. scalelayer = this.getDom("scalelayer");
  26607. var isMouseMove = false,
  26608. position = null,
  26609. minEditorHeight = 0,
  26610. minEditorWidth = editor.options.minFrameWidth,
  26611. pageX = 0,
  26612. pageY = 0,
  26613. scaleWidth = 0,
  26614. scaleHeight = 0;
  26615. function down() {
  26616. position = domUtils.getXY(editorHolder);
  26617. if (!minEditorHeight) {
  26618. minEditorHeight = editor.options.minFrameHeight + toolbarBox.offsetHeight + bottombar.offsetHeight;
  26619. }
  26620. scalelayer.style.cssText = "position:absolute;left:0;display:;top:0;background-color:#41ABFF;opacity:0.4;filter: Alpha(opacity=40);width:" + editorHolder.offsetWidth + "px;height:"
  26621. + editorHolder.offsetHeight + "px;z-index:" + (editor.options.zIndex + 1);
  26622. domUtils.on(doc, "mousemove", move);
  26623. domUtils.on(editorDocument, "mouseup", up);
  26624. domUtils.on(doc, "mouseup", up);
  26625. }
  26626. var me = this;
  26627. //by xuheng 全屏时关掉缩放
  26628. this.editor.addListener('fullscreenchanged', function (e, fullScreen) {
  26629. if (fullScreen) {
  26630. me.disableScale();
  26631. } else {
  26632. if (me.editor.options.scaleEnabled) {
  26633. me.enableScale();
  26634. var tmpNode = me.editor.document.createElement('span');
  26635. me.editor.body.appendChild(tmpNode);
  26636. me.editor.body.style.height = Math.max(domUtils.getXY(tmpNode).y, me.editor.iframe.offsetHeight - 20) + 'px';
  26637. domUtils.remove(tmpNode)
  26638. }
  26639. }
  26640. });
  26641. function move(event) {
  26642. clearSelection();
  26643. var e = event || window.event;
  26644. pageX = e.pageX || (doc.documentElement.scrollLeft + e.clientX);
  26645. pageY = e.pageY || (doc.documentElement.scrollTop + e.clientY);
  26646. scaleWidth = pageX - position.x;
  26647. scaleHeight = pageY - position.y;
  26648. if (scaleWidth >= minEditorWidth) {
  26649. isMouseMove = true;
  26650. scalelayer.style.width = scaleWidth + 'px';
  26651. }
  26652. if (scaleHeight >= minEditorHeight) {
  26653. isMouseMove = true;
  26654. scalelayer.style.height = scaleHeight + "px";
  26655. }
  26656. }
  26657. function up() {
  26658. if (isMouseMove) {
  26659. isMouseMove = false;
  26660. editor.ui._actualFrameWidth = scalelayer.offsetWidth - 2;
  26661. editorHolder.style.width = editor.ui._actualFrameWidth + 'px';
  26662. editor.setHeight(scalelayer.offsetHeight - bottombar.offsetHeight - toolbarBox.offsetHeight - 2,true);
  26663. }
  26664. if (scalelayer) {
  26665. scalelayer.style.display = "none";
  26666. }
  26667. clearSelection();
  26668. domUtils.un(doc, "mousemove", move);
  26669. domUtils.un(editorDocument, "mouseup", up);
  26670. domUtils.un(doc, "mouseup", up);
  26671. }
  26672. function clearSelection() {
  26673. if (browser.ie)
  26674. doc.selection.clear();
  26675. else
  26676. window.getSelection().removeAllRanges();
  26677. }
  26678. this.enableScale = function () {
  26679. //trace:2868
  26680. if (editor.queryCommandState("source") == 1) return;
  26681. scale.style.display = "";
  26682. this.scaleEnabled = true;
  26683. domUtils.on(scale, "mousedown", down);
  26684. };
  26685. this.disableScale = function () {
  26686. scale.style.display = "none";
  26687. this.scaleEnabled = false;
  26688. domUtils.un(scale, "mousedown", down);
  26689. };
  26690. },
  26691. isFullScreen:function () {
  26692. return this._fullscreen;
  26693. },
  26694. postRender:function () {
  26695. UIBase.prototype.postRender.call(this);
  26696. for (var i = 0; i < this.toolbars.length; i++) {
  26697. this.toolbars[i].postRender();
  26698. }
  26699. var me = this;
  26700. var timerId,
  26701. domUtils = baidu.editor.dom.domUtils,
  26702. updateFullScreenTime = function () {
  26703. clearTimeout(timerId);
  26704. timerId = setTimeout(function () {
  26705. me._updateFullScreen();
  26706. });
  26707. };
  26708. domUtils.on(window, 'resize', updateFullScreenTime);
  26709. me.addListener('destroy', function () {
  26710. domUtils.un(window, 'resize', updateFullScreenTime);
  26711. clearTimeout(timerId);
  26712. })
  26713. },
  26714. showToolbarMsg:function (msg, flag) {
  26715. this.getDom('toolbarmsg_label').innerHTML = msg;
  26716. this.getDom('toolbarmsg').style.display = '';
  26717. //
  26718. if (!flag) {
  26719. var w = this.getDom('upload_dialog');
  26720. w.style.display = 'none';
  26721. }
  26722. },
  26723. hideToolbarMsg:function () {
  26724. this.getDom('toolbarmsg').style.display = 'none';
  26725. },
  26726. mapUrl:function (url) {
  26727. return url ? url.replace('~/', this.editor.options.UEDITOR_HOME_URL || '') : ''
  26728. },
  26729. triggerLayout:function () {
  26730. var dom = this.getDom();
  26731. if (dom.style.zoom == '1') {
  26732. dom.style.zoom = '100%';
  26733. } else {
  26734. dom.style.zoom = '1';
  26735. }
  26736. }
  26737. };
  26738. utils.inherits(EditorUI, baidu.editor.ui.UIBase);
  26739. var instances = {};
  26740. UE.ui.Editor = function (options) {
  26741. var editor = new UE.Editor(options);
  26742. editor.options.editor = editor;
  26743. utils.loadFile(document, {
  26744. href:editor.options.themePath + editor.options.theme + "/css/editor.css",
  26745. tag:"link",
  26746. type:"text/css",
  26747. rel:"stylesheet"
  26748. });
  26749. var oldRender = editor.render;
  26750. editor.render = function (holder) {
  26751. if (holder.constructor === String) {
  26752. editor.key = holder;
  26753. instances[holder] = editor;
  26754. }
  26755. utils.domReady(function () {
  26756. editor.langIsReady ? renderUI() : editor.addListener("langReady", renderUI);
  26757. function renderUI() {
  26758. editor.setOpt({
  26759. labelMap:editor.options.labelMap || editor.getLang('labelMap')
  26760. });
  26761. new EditorUI(editor.options);
  26762. if (holder) {
  26763. if (holder.constructor === String) {
  26764. holder = document.getElementById(holder);
  26765. }
  26766. holder && holder.getAttribute('name') && ( editor.options.textarea = holder.getAttribute('name'));
  26767. if (holder && /script|textarea/ig.test(holder.tagName)) {
  26768. var newDiv = document.createElement('div');
  26769. holder.parentNode.insertBefore(newDiv, holder);
  26770. var cont = holder.value || holder.innerHTML;
  26771. editor.options.initialContent = /^[\t\r\n ]*$/.test(cont) ? editor.options.initialContent :
  26772. cont.replace(/>[\n\r\t]+([ ]{4})+/g, '>')
  26773. .replace(/[\n\r\t]+([ ]{4})+</g, '<')
  26774. .replace(/>[\n\r\t]+</g, '><');
  26775. holder.className && (newDiv.className = holder.className);
  26776. holder.style.cssText && (newDiv.style.cssText = holder.style.cssText);
  26777. if (/textarea/i.test(holder.tagName)) {
  26778. editor.textarea = holder;
  26779. editor.textarea.style.display = 'none';
  26780. } else {
  26781. holder.parentNode.removeChild(holder);
  26782. }
  26783. if(holder.id){
  26784. newDiv.id = holder.id;
  26785. domUtils.removeAttributes(holder,'id');
  26786. }
  26787. holder = newDiv;
  26788. holder.innerHTML = '';
  26789. }
  26790. }
  26791. domUtils.addClass(holder, "edui-" + editor.options.theme);
  26792. editor.ui.render(holder);
  26793. var opt = editor.options;
  26794. //给实例添加一个编辑器的容器引用
  26795. editor.container = editor.ui.getDom();
  26796. var parents = domUtils.findParents(holder,true);
  26797. var displays = [];
  26798. for(var i = 0 ,ci;ci=parents[i];i++){
  26799. displays[i] = ci.style.display;
  26800. ci.style.display = 'block'
  26801. }
  26802. if (opt.initialFrameWidth) {
  26803. opt.minFrameWidth = opt.initialFrameWidth;
  26804. } else {
  26805. opt.minFrameWidth = opt.initialFrameWidth = holder.offsetWidth;
  26806. var styleWidth = holder.style.width;
  26807. if(/%$/.test(styleWidth)) {
  26808. opt.initialFrameWidth = styleWidth;
  26809. }
  26810. }
  26811. if (opt.initialFrameHeight) {
  26812. opt.minFrameHeight = opt.initialFrameHeight;
  26813. } else {
  26814. opt.initialFrameHeight = opt.minFrameHeight = holder.offsetHeight;
  26815. }
  26816. for(var i = 0 ,ci;ci=parents[i];i++){
  26817. ci.style.display = displays[i]
  26818. }
  26819. //编辑器最外容器设置了高度,会导致,编辑器不占位
  26820. //todo 先去掉,没有找到原因
  26821. if(holder.style.height){
  26822. holder.style.height = ''
  26823. }
  26824. editor.container.style.width = opt.initialFrameWidth + (/%$/.test(opt.initialFrameWidth) ? '' : 'px');
  26825. editor.container.style.zIndex = opt.zIndex;
  26826. oldRender.call(editor, editor.ui.getDom('iframeholder'));
  26827. editor.fireEvent("afteruiready");
  26828. }
  26829. })
  26830. };
  26831. return editor;
  26832. };
  26833. /**
  26834. * @file
  26835. * @name UE
  26836. * @short UE
  26837. * @desc UEditor的顶部命名空间
  26838. */
  26839. /**
  26840. * @name getEditor
  26841. * @since 1.2.4+
  26842. * @grammar UE.getEditor(id,[opt]) => Editor实例
  26843. * @desc 提供一个全局的方法得到编辑器实例
  26844. *
  26845. * * ''id'' 放置编辑器的容器id, 如果容器下的编辑器已经存在,就直接返回
  26846. * * ''opt'' 编辑器的可选参数
  26847. * @example
  26848. * UE.getEditor('containerId',{onready:function(){//创建一个编辑器实例
  26849. * this.setContent('hello')
  26850. * }});
  26851. * UE.getEditor('containerId'); //返回刚创建的实例
  26852. *
  26853. */
  26854. UE.getEditor = function (id, opt) {
  26855. var editor = instances[id];
  26856. if (!editor) {
  26857. editor = instances[id] = new UE.ui.Editor(opt);
  26858. editor.render(id);
  26859. }
  26860. return editor;
  26861. };
  26862. UE.delEditor = function (id) {
  26863. var editor;
  26864. if (editor = instances[id]) {
  26865. editor.key && editor.destroy();
  26866. delete instances[id]
  26867. }
  26868. };
  26869. UE.registerUI = function(uiName,fn,index,editorId){
  26870. utils.each(uiName.split(/\s+/), function (name) {
  26871. UE._customizeUI[name] = {
  26872. id : editorId,
  26873. execFn:fn,
  26874. index:index
  26875. };
  26876. })
  26877. }
  26878. // 使用jquery风格的接口
  26879. // 目前只能操作一个
  26880. $.fn.extend({
  26881. editor: function(cmd) {
  26882. if(this.length===0){
  26883. return;
  26884. }
  26885. var args = Array.prototype.splice.call(arguments, 1), self = this;
  26886. var result = '';
  26887. var $this = $(this[0]);
  26888. var id = $this.attr("id");
  26889. if(!id) {
  26890. id = 'editor-' + parseInt(Math.random() * 1000000000)
  26891. $this.attr("id", id);
  26892. }
  26893. if($.isPlainObject(cmd)){
  26894. var editor = UE.getEditor(id,cmd);
  26895. }else{
  26896. var editor = UE.getEditor(id);
  26897. if (typeof cmd == 'string') {
  26898. result = editor[cmd].apply(editor, args);
  26899. }
  26900. }
  26901. editor.addListener('afteruiready', function() {
  26902. self[0] = $("#" + id)[0];
  26903. });
  26904. if(!cmd) {
  26905. return this
  26906. }
  26907. return result;
  26908. }
  26909. })
  26910. //自动加载
  26911. $(function() {
  26912. $(".sui-editor").editor();
  26913. })
  26914. })();
  26915. // js/editor/_src/adapter/message.js
  26916. UE.registerUI('message', function(editor) {
  26917. var editorui = baidu.editor.ui;
  26918. var Message = editorui.Message;
  26919. var holder;
  26920. var _messageItems = [];
  26921. var me = editor;
  26922. me.addListener('ready', function(){
  26923. holder = document.getElementById(me.ui.id + '_message_holder');
  26924. updateHolderPos();
  26925. setTimeout(function(){
  26926. updateHolderPos();
  26927. }, 500);
  26928. });
  26929. me.addListener('showmessage', function(type, opt){
  26930. opt = utils.isString(opt) ? {
  26931. 'content': opt
  26932. } : opt;
  26933. var message = new Message({
  26934. 'timeout': opt.timeout,
  26935. 'type': opt.type,
  26936. 'content': opt.content,
  26937. 'keepshow': opt.keepshow,
  26938. 'editor': me
  26939. }),
  26940. mid = opt.id || ('msg_' + (+new Date()).toString(36));
  26941. message.render(holder);
  26942. _messageItems[mid] = message;
  26943. message.reset(opt);
  26944. updateHolderPos();
  26945. return mid;
  26946. });
  26947. me.addListener('updatemessage',function(type, id, opt){
  26948. opt = utils.isString(opt) ? {
  26949. 'content': opt
  26950. } : opt;
  26951. var message = _messageItems[id];
  26952. message.render(holder);
  26953. message && message.reset(opt);
  26954. });
  26955. me.addListener('hidemessage',function(type, id){
  26956. var message = _messageItems[id];
  26957. message && message.hide();
  26958. });
  26959. function updateHolderPos(){
  26960. var toolbarbox = me.ui.getDom('toolbarbox');
  26961. if (toolbarbox) {
  26962. holder.style.top = toolbarbox.offsetHeight + 3 + 'px';
  26963. }
  26964. holder.style.zIndex = Math.max(me.options.zIndex, me.iframe.style.zIndex) + 1;
  26965. }
  26966. });
  26967. // js/editor/_src/adapter/autosave.js
  26968. UE.registerUI('autosave', function(editor) {
  26969. var timer = null,uid = null;
  26970. editor.on('afterautosave',function(){
  26971. clearTimeout(timer);
  26972. timer = setTimeout(function(){
  26973. if(uid){
  26974. editor.trigger('hidemessage',uid);
  26975. }
  26976. uid = editor.trigger('showmessage',{
  26977. content : editor.getLang('autosave.success'),
  26978. timeout : 2000
  26979. });
  26980. },2000)
  26981. })
  26982. });
  26983. })();