血透系统PC前端

neditor.all.js 1.0MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077
  1. /*!
  2. * neditor
  3. * version: 2.1.18
  4. * build: Wed May 22 2019 09:16:49 GMT+0000 (UTC)
  5. */
  6. (function(){
  7. // editor.js
  8. UEDITOR_CONFIG = window.UEDITOR_CONFIG || {};
  9. var baidu = window.baidu || {};
  10. window.baidu = baidu;
  11. window.UE = baidu.editor = {
  12. plugins: {},
  13. commands: {},
  14. instants: {},
  15. I18N: {},
  16. _customizeUI: {},
  17. version: "1.5.0"
  18. };
  19. var dom = (UE.dom = {});
  20. // core/browser.js
  21. /**
  22. * 浏览器判断模块
  23. * @file
  24. * @module UE.browser
  25. * @since 1.2.6.1
  26. */
  27. /**
  28. * 提供浏览器检测的模块
  29. * @unfile
  30. * @module UE.browser
  31. */
  32. var browser = (UE.browser = (function() {
  33. var agent = navigator.userAgent.toLowerCase(),
  34. opera = window.opera,
  35. browser = {
  36. /**
  37. * @property {boolean} ie 检测当前浏览器是否为IE
  38. * @example
  39. * ```javascript
  40. * if ( UE.browser.ie ) {
  41. * console.log( '当前浏览器是IE' );
  42. * }
  43. * ```
  44. */
  45. ie: /(msie\s|trident.*rv:)([\w.]+)/i.test(agent),
  46. /**
  47. * @property {boolean} opera 检测当前浏览器是否为Opera
  48. * @example
  49. * ```javascript
  50. * if ( UE.browser.opera ) {
  51. * console.log( '当前浏览器是Opera' );
  52. * }
  53. * ```
  54. */
  55. opera: !!opera && opera.version,
  56. /**
  57. * @property {boolean} webkit 检测当前浏览器是否是webkit内核的浏览器
  58. * @example
  59. * ```javascript
  60. * if ( UE.browser.webkit ) {
  61. * console.log( '当前浏览器是webkit内核浏览器' );
  62. * }
  63. * ```
  64. */
  65. webkit: agent.indexOf(" applewebkit/") > -1,
  66. /**
  67. * @property {boolean} mac 检测当前浏览器是否是运行在mac平台下
  68. * @example
  69. * ```javascript
  70. * if ( UE.browser.mac ) {
  71. * console.log( '当前浏览器运行在mac平台下' );
  72. * }
  73. * ```
  74. */
  75. mac: agent.indexOf("macintosh") > -1,
  76. /**
  77. * @property {boolean} quirks 检测当前浏览器是否处于“怪异模式”下
  78. * @example
  79. * ```javascript
  80. * if ( UE.browser.quirks ) {
  81. * console.log( '当前浏览器运行处于“怪异模式”' );
  82. * }
  83. * ```
  84. */
  85. quirks: document.compatMode == "BackCompat"
  86. };
  87. /**
  88. * @property {boolean} gecko 检测当前浏览器内核是否是gecko内核
  89. * @example
  90. * ```javascript
  91. * if ( UE.browser.gecko ) {
  92. * console.log( '当前浏览器内核是gecko内核' );
  93. * }
  94. * ```
  95. */
  96. browser.gecko =
  97. navigator.product == "Gecko" &&
  98. !browser.webkit &&
  99. !browser.opera &&
  100. !browser.ie;
  101. var version = 0;
  102. // Internet Explorer 6.0+
  103. if (browser.ie) {
  104. var v1 = agent.match(/(?:msie\s([\w.]+))/);
  105. var v2 = agent.match(/(?:trident.*rv:([\w.]+))/);
  106. if (v1 && v2 && v1[1] && v2[1]) {
  107. version = Math.max(v1[1] * 1, v2[1] * 1);
  108. } else if (v1 && v1[1]) {
  109. version = v1[1] * 1;
  110. } else if (v2 && v2[1]) {
  111. version = v2[1] * 1;
  112. } else {
  113. version = 0;
  114. }
  115. browser.ie11Compat = document.documentMode == 11;
  116. /**
  117. * @property { boolean } ie9Compat 检测浏览器模式是否为 IE9 兼容模式
  118. * @warning 如果浏览器不是IE, 则该值为undefined
  119. * @example
  120. * ```javascript
  121. * if ( UE.browser.ie9Compat ) {
  122. * console.log( '当前浏览器运行在IE9兼容模式下' );
  123. * }
  124. * ```
  125. */
  126. browser.ie9Compat = document.documentMode == 9;
  127. /**
  128. * @property { boolean } ie8 检测浏览器是否是IE8浏览器
  129. * @warning 如果浏览器不是IE, 则该值为undefined
  130. * @example
  131. * ```javascript
  132. * if ( UE.browser.ie8 ) {
  133. * console.log( '当前浏览器是IE8浏览器' );
  134. * }
  135. * ```
  136. */
  137. browser.ie8 = !!document.documentMode;
  138. /**
  139. * @property { boolean } ie8Compat 检测浏览器模式是否为 IE8 兼容模式
  140. * @warning 如果浏览器不是IE, 则该值为undefined
  141. * @example
  142. * ```javascript
  143. * if ( UE.browser.ie8Compat ) {
  144. * console.log( '当前浏览器运行在IE8兼容模式下' );
  145. * }
  146. * ```
  147. */
  148. browser.ie8Compat = document.documentMode == 8;
  149. /**
  150. * @property { boolean } ie7Compat 检测浏览器模式是否为 IE7 兼容模式
  151. * @warning 如果浏览器不是IE, 则该值为undefined
  152. * @example
  153. * ```javascript
  154. * if ( UE.browser.ie7Compat ) {
  155. * console.log( '当前浏览器运行在IE7兼容模式下' );
  156. * }
  157. * ```
  158. */
  159. browser.ie7Compat =
  160. (version == 7 && !document.documentMode) || document.documentMode == 7;
  161. /**
  162. * @property { boolean } ie6Compat 检测浏览器模式是否为 IE6 模式 或者怪异模式
  163. * @warning 如果浏览器不是IE, 则该值为undefined
  164. * @example
  165. * ```javascript
  166. * if ( UE.browser.ie6Compat ) {
  167. * console.log( '当前浏览器运行在IE6模式或者怪异模式下' );
  168. * }
  169. * ```
  170. */
  171. browser.ie6Compat = version < 7 || browser.quirks;
  172. browser.ie9above = version > 8;
  173. browser.ie9below = version < 9;
  174. browser.ie11above = version > 10;
  175. browser.ie11below = version < 11;
  176. }
  177. // Gecko.
  178. if (browser.gecko) {
  179. var geckoRelease = agent.match(/rv:([\d\.]+)/);
  180. if (geckoRelease) {
  181. geckoRelease = geckoRelease[1].split(".");
  182. version =
  183. geckoRelease[0] * 10000 +
  184. (geckoRelease[1] || 0) * 100 +
  185. (geckoRelease[2] || 0) * 1;
  186. }
  187. }
  188. /**
  189. * @property { Number } chrome 检测当前浏览器是否为Chrome, 如果是,则返回Chrome的大版本号
  190. * @warning 如果浏览器不是chrome, 则该值为undefined
  191. * @example
  192. * ```javascript
  193. * if ( UE.browser.chrome ) {
  194. * console.log( '当前浏览器是Chrome' );
  195. * }
  196. * ```
  197. */
  198. if (/chrome\/(\d+\.\d)/i.test(agent)) {
  199. browser.chrome = +RegExp["\x241"];
  200. }
  201. /**
  202. * @property { Number } safari 检测当前浏览器是否为Safari, 如果是,则返回Safari的大版本号
  203. * @warning 如果浏览器不是safari, 则该值为undefined
  204. * @example
  205. * ```javascript
  206. * if ( UE.browser.safari ) {
  207. * console.log( '当前浏览器是Safari' );
  208. * }
  209. * ```
  210. */
  211. if (
  212. /(\d+\.\d)?(?:\.\d)?\s+safari\/?(\d+\.\d+)?/i.test(agent) &&
  213. !/chrome/i.test(agent)
  214. ) {
  215. browser.safari = +(RegExp["\x241"] || RegExp["\x242"]);
  216. }
  217. // Opera 9.50+
  218. if (browser.opera) version = parseFloat(opera.version());
  219. // WebKit 522+ (Safari 3+)
  220. if (browser.webkit)
  221. version = parseFloat(agent.match(/ applewebkit\/(\d+)/)[1]);
  222. /**
  223. * @property { Number } version 检测当前浏览器版本号
  224. * @remind
  225. * <ul>
  226. * <li>IE系列返回值为5,6,7,8,9,10等</li>
  227. * <li>gecko系列会返回10900,158900等</li>
  228. * <li>webkit系列会返回其build号 (如 522等)</li>
  229. * </ul>
  230. * @example
  231. * ```javascript
  232. * console.log( '当前浏览器版本号是: ' + UE.browser.version );
  233. * ```
  234. */
  235. browser.version = version;
  236. /**
  237. * @property { boolean } isCompatible 检测当前浏览器是否能够与UEditor良好兼容
  238. * @example
  239. * ```javascript
  240. * if ( UE.browser.isCompatible ) {
  241. * console.log( '浏览器与UEditor能够良好兼容' );
  242. * }
  243. * ```
  244. */
  245. browser.isCompatible =
  246. !browser.mobile &&
  247. ((browser.ie && version >= 6) ||
  248. (browser.gecko && version >= 10801) ||
  249. (browser.opera && version >= 9.5) ||
  250. (browser.air && version >= 1) ||
  251. (browser.webkit && version >= 522) ||
  252. false);
  253. return browser;
  254. })());
  255. //快捷方式
  256. var ie = browser.ie,
  257. webkit = browser.webkit,
  258. gecko = browser.gecko,
  259. opera = browser.opera;
  260. // core/utils.js
  261. /**
  262. * 工具函数包
  263. * @file
  264. * @module UE.utils
  265. * @since 1.2.6.1
  266. */
  267. /**
  268. * UEditor封装使用的静态工具函数
  269. * @module UE.utils
  270. * @unfile
  271. */
  272. var utils = (UE.utils = {
  273. /**
  274. * 用给定的迭代器遍历对象
  275. * @method each
  276. * @param { Object } obj 需要遍历的对象
  277. * @param { Function } iterator 迭代器, 该方法接受两个参数, 第一个参数是当前所处理的value, 第二个参数是当前遍历对象的key
  278. * @example
  279. * ```javascript
  280. * var demoObj = {
  281. * key1: 1,
  282. * key2: 2
  283. * };
  284. *
  285. * //output: key1: 1, key2: 2
  286. * UE.utils.each( demoObj, funciton ( value, key ) {
  287. *
  288. * console.log( key + ":" + value );
  289. *
  290. * } );
  291. * ```
  292. */
  293. /**
  294. * 用给定的迭代器遍历数组或类数组对象
  295. * @method each
  296. * @param { Array } array 需要遍历的数组或者类数组
  297. * @param { Function } iterator 迭代器, 该方法接受两个参数, 第一个参数是当前所处理的value, 第二个参数是当前遍历对象的key
  298. * @example
  299. * ```javascript
  300. * var divs = document.getElmentByTagNames( "div" );
  301. *
  302. * //output: 0: DIV, 1: DIV ...
  303. * UE.utils.each( divs, funciton ( value, key ) {
  304. *
  305. * console.log( key + ":" + value.tagName );
  306. *
  307. * } );
  308. * ```
  309. */
  310. each: function(obj, iterator, context) {
  311. if (obj == null) return;
  312. if (obj.length === +obj.length) {
  313. for (var i = 0, l = obj.length; i < l; i++) {
  314. if (iterator.call(context, obj[i], i, obj) === false) return false;
  315. }
  316. } else {
  317. for (var key in obj) {
  318. if (obj.hasOwnProperty(key)) {
  319. if (iterator.call(context, obj[key], key, obj) === false)
  320. return false;
  321. }
  322. }
  323. }
  324. },
  325. /**
  326. * 以给定对象作为原型创建一个新对象
  327. * @method makeInstance
  328. * @param { Object } protoObject 该对象将作为新创建对象的原型
  329. * @return { Object } 新的对象, 该对象的原型是给定的protoObject对象
  330. * @example
  331. * ```javascript
  332. *
  333. * var protoObject = { sayHello: function () { console.log('Hello UEditor!'); } };
  334. *
  335. * var newObject = UE.utils.makeInstance( protoObject );
  336. * //output: Hello UEditor!
  337. * newObject.sayHello();
  338. * ```
  339. */
  340. makeInstance: function(obj) {
  341. var noop = new Function();
  342. noop.prototype = obj;
  343. obj = new noop();
  344. noop.prototype = null;
  345. return obj;
  346. },
  347. /**
  348. * 将source对象中的属性扩展到target对象上
  349. * @method extend
  350. * @remind 该方法将强制把source对象上的属性复制到target对象上
  351. * @see UE.utils.extend(Object,Object,Boolean)
  352. * @param { Object } target 目标对象, 新的属性将附加到该对象上
  353. * @param { Object } source 源对象, 该对象的属性会被附加到target对象上
  354. * @return { Object } 返回target对象
  355. * @example
  356. * ```javascript
  357. *
  358. * var target = { name: 'target', sex: 1 },
  359. * source = { name: 'source', age: 17 };
  360. *
  361. * UE.utils.extend( target, source );
  362. *
  363. * //output: { name: 'source', sex: 1, age: 17 }
  364. * console.log( target );
  365. *
  366. * ```
  367. */
  368. /**
  369. * 将source对象中的属性扩展到target对象上, 根据指定的isKeepTarget值决定是否保留目标对象中与
  370. * 源对象属性名相同的属性值。
  371. * @method extend
  372. * @param { Object } target 目标对象, 新的属性将附加到该对象上
  373. * @param { Object } source 源对象, 该对象的属性会被附加到target对象上
  374. * @param { Boolean } isKeepTarget 是否保留目标对象中与源对象中属性名相同的属性
  375. * @return { Object } 返回target对象
  376. * @example
  377. * ```javascript
  378. *
  379. * var target = { name: 'target', sex: 1 },
  380. * source = { name: 'source', age: 17 };
  381. *
  382. * UE.utils.extend( target, source, true );
  383. *
  384. * //output: { name: 'target', sex: 1, age: 17 }
  385. * console.log( target );
  386. *
  387. * ```
  388. */
  389. extend: function(t, s, b) {
  390. if (s) {
  391. for (var k in s) {
  392. if (!b || !t.hasOwnProperty(k)) {
  393. t[k] = s[k];
  394. }
  395. }
  396. }
  397. return t;
  398. },
  399. /**
  400. * 将给定的多个对象的属性复制到目标对象target上
  401. * @method extend2
  402. * @remind 该方法将强制把源对象上的属性复制到target对象上
  403. * @remind 该方法支持两个及以上的参数, 从第二个参数开始, 其属性都会被复制到第一个参数上。 如果遇到同名的属性,
  404. * 将会覆盖掉之前的值。
  405. * @param { Object } target 目标对象, 新的属性将附加到该对象上
  406. * @param { Object... } source 源对象, 支持多个对象, 该对象的属性会被附加到target对象上
  407. * @return { Object } 返回target对象
  408. * @example
  409. * ```javascript
  410. *
  411. * var target = {},
  412. * source1 = { name: 'source', age: 17 },
  413. * source2 = { title: 'dev' };
  414. *
  415. * UE.utils.extend2( target, source1, source2 );
  416. *
  417. * //output: { name: 'source', age: 17, title: 'dev' }
  418. * console.log( target );
  419. *
  420. * ```
  421. */
  422. extend2: function(t) {
  423. var a = arguments;
  424. for (var i = 1; i < a.length; i++) {
  425. var x = a[i];
  426. for (var k in x) {
  427. if (!t.hasOwnProperty(k)) {
  428. t[k] = x[k];
  429. }
  430. }
  431. }
  432. return t;
  433. },
  434. /**
  435. * 模拟继承机制, 使得subClass继承自superClass
  436. * @method inherits
  437. * @param { Object } subClass 子类对象
  438. * @param { Object } superClass 超类对象
  439. * @warning 该方法只能让subClass继承超类的原型, subClass对象自身的属性和方法不会被继承
  440. * @return { Object } 继承superClass后的子类对象
  441. * @example
  442. * ```javascript
  443. * function SuperClass(){
  444. * this.name = "小李";
  445. * }
  446. *
  447. * SuperClass.prototype = {
  448. * hello:function(str){
  449. * console.log(this.name + str);
  450. * }
  451. * }
  452. *
  453. * function SubClass(){
  454. * this.name = "小张";
  455. * }
  456. *
  457. * UE.utils.inherits(SubClass,SuperClass);
  458. *
  459. * var sub = new SubClass();
  460. * //output: '小张早上好!
  461. * sub.hello("早上好!");
  462. * ```
  463. */
  464. inherits: function(subClass, superClass) {
  465. var oldP = subClass.prototype,
  466. newP = utils.makeInstance(superClass.prototype);
  467. utils.extend(newP, oldP, true);
  468. subClass.prototype = newP;
  469. return (newP.constructor = subClass);
  470. },
  471. /**
  472. * 用指定的context对象作为函数fn的上下文
  473. * @method bind
  474. * @param { Function } fn 需要绑定上下文的函数对象
  475. * @param { Object } content 函数fn新的上下文对象
  476. * @return { Function } 一个新的函数, 该函数作为原始函数fn的代理, 将完成fn的上下文调换工作。
  477. * @example
  478. * ```javascript
  479. *
  480. * var name = 'window',
  481. * newTest = null;
  482. *
  483. * function test () {
  484. * console.log( this.name );
  485. * }
  486. *
  487. * newTest = UE.utils.bind( test, { name: 'object' } );
  488. *
  489. * //output: object
  490. * newTest();
  491. *
  492. * //output: window
  493. * test();
  494. *
  495. * ```
  496. */
  497. bind: function(fn, context) {
  498. return function() {
  499. return fn.apply(context, arguments);
  500. };
  501. },
  502. /**
  503. * 创建延迟指定时间后执行的函数fn
  504. * @method defer
  505. * @param { Function } fn 需要延迟执行的函数对象
  506. * @param { int } delay 延迟的时间, 单位是毫秒
  507. * @warning 该方法的时间控制是不精确的,仅仅只能保证函数的执行是在给定的时间之后,
  508. * 而不能保证刚好到达延迟时间时执行。
  509. * @return { Function } 目标函数fn的代理函数, 只有执行该函数才能起到延时效果
  510. * @example
  511. * ```javascript
  512. * var start = 0;
  513. *
  514. * function test(){
  515. * console.log( new Date() - start );
  516. * }
  517. *
  518. * var testDefer = UE.utils.defer( test, 1000 );
  519. * //
  520. * start = new Date();
  521. * //output: (大约在1000毫秒之后输出) 1000
  522. * testDefer();
  523. * ```
  524. */
  525. /**
  526. * 创建延迟指定时间后执行的函数fn, 如果在延迟时间内再次执行该方法, 将会根据指定的exclusion的值,
  527. * 决定是否取消前一次函数的执行, 如果exclusion的值为true, 则取消执行,反之,将继续执行前一个方法。
  528. * @method defer
  529. * @param { Function } fn 需要延迟执行的函数对象
  530. * @param { int } delay 延迟的时间, 单位是毫秒
  531. * @param { Boolean } exclusion 如果在延迟时间内再次执行该函数,该值将决定是否取消执行前一次函数的执行,
  532. * 值为true表示取消执行, 反之则将在执行前一次函数之后才执行本次函数调用。
  533. * @warning 该方法的时间控制是不精确的,仅仅只能保证函数的执行是在给定的时间之后,
  534. * 而不能保证刚好到达延迟时间时执行。
  535. * @return { Function } 目标函数fn的代理函数, 只有执行该函数才能起到延时效果
  536. * @example
  537. * ```javascript
  538. *
  539. * function test(){
  540. * console.log(1);
  541. * }
  542. *
  543. * var testDefer = UE.utils.defer( test, 1000, true );
  544. *
  545. * //output: (两次调用仅有一次输出) 1
  546. * testDefer();
  547. * testDefer();
  548. * ```
  549. */
  550. defer: function(fn, delay, exclusion) {
  551. var timerID;
  552. return function() {
  553. if (exclusion) {
  554. clearTimeout(timerID);
  555. }
  556. timerID = setTimeout(fn, delay);
  557. };
  558. },
  559. /**
  560. * 获取元素item在数组array中首次出现的位置, 如果未找到item, 则返回-1
  561. * @method indexOf
  562. * @remind 该方法的匹配过程使用的是恒等“===”
  563. * @param { Array } array 需要查找的数组对象
  564. * @param { * } item 需要在目标数组中查找的值
  565. * @return { int } 返回item在目标数组array中首次出现的位置, 如果在数组中未找到item, 则返回-1
  566. * @example
  567. * ```javascript
  568. * var item = 1,
  569. * arr = [ 3, 4, 6, 8, 1, 1, 2 ];
  570. *
  571. * //output: 4
  572. * console.log( UE.utils.indexOf( arr, item ) );
  573. * ```
  574. */
  575. /**
  576. * 获取元素item数组array中首次出现的位置, 如果未找到item, 则返回-1。通过start的值可以指定搜索的起始位置。
  577. * @method indexOf
  578. * @remind 该方法的匹配过程使用的是恒等“===”
  579. * @param { Array } array 需要查找的数组对象
  580. * @param { * } item 需要在目标数组中查找的值
  581. * @param { int } start 搜索的起始位置
  582. * @return { int } 返回item在目标数组array中的start位置之后首次出现的位置, 如果在数组中未找到item, 则返回-1
  583. * @example
  584. * ```javascript
  585. * var item = 1,
  586. * arr = [ 3, 4, 6, 8, 1, 2, 8, 3, 2, 1, 1, 4 ];
  587. *
  588. * //output: 9
  589. * console.log( UE.utils.indexOf( arr, item, 5 ) );
  590. * ```
  591. */
  592. indexOf: function(array, item, start) {
  593. var index = -1;
  594. start = this.isNumber(start) ? start : 0;
  595. this.each(array, function(v, i) {
  596. if (i >= start && v === item) {
  597. index = i;
  598. return false;
  599. }
  600. });
  601. return index;
  602. },
  603. /**
  604. * 移除数组array中所有的元素item
  605. * @method removeItem
  606. * @param { Array } array 要移除元素的目标数组
  607. * @param { * } item 将要被移除的元素
  608. * @remind 该方法的匹配过程使用的是恒等“===”
  609. * @example
  610. * ```javascript
  611. * var arr = [ 4, 5, 7, 1, 3, 4, 6 ];
  612. *
  613. * UE.utils.removeItem( arr, 4 );
  614. * //output: [ 5, 7, 1, 3, 6 ]
  615. * console.log( arr );
  616. *
  617. * ```
  618. */
  619. removeItem: function(array, item) {
  620. for (var i = 0, l = array.length; i < l; i++) {
  621. if (array[i] === item) {
  622. array.splice(i, 1);
  623. i--;
  624. }
  625. }
  626. },
  627. /**
  628. * 删除字符串str的首尾空格
  629. * @method trim
  630. * @param { String } str 需要删除首尾空格的字符串
  631. * @return { String } 删除了首尾的空格后的字符串
  632. * @example
  633. * ```javascript
  634. *
  635. * var str = " UEdtior ";
  636. *
  637. * //output: 9
  638. * console.log( str.length );
  639. *
  640. * //output: 7
  641. * console.log( UE.utils.trim( " UEdtior " ).length );
  642. *
  643. * //output: 9
  644. * console.log( str.length );
  645. *
  646. * ```
  647. */
  648. trim: function(str) {
  649. return str.replace(/(^[ \t\n\r]+)|([ \t\n\r]+$)/g, "");
  650. },
  651. /**
  652. * 将字符串str以','分隔成数组后,将该数组转换成哈希对象, 其生成的hash对象的key为数组中的元素, value为1
  653. * @method listToMap
  654. * @warning 该方法在生成的hash对象中,会为每一个key同时生成一个另一个全大写的key。
  655. * @param { String } str 该字符串将被以','分割为数组, 然后进行转化
  656. * @return { Object } 转化之后的hash对象
  657. * @example
  658. * ```javascript
  659. *
  660. * //output: Object {UEdtior: 1, UEDTIOR: 1, Hello: 1, HELLO: 1}
  661. * console.log( UE.utils.listToMap( 'UEdtior,Hello' ) );
  662. *
  663. * ```
  664. */
  665. /**
  666. * 将字符串数组转换成哈希对象, 其生成的hash对象的key为数组中的元素, value为1
  667. * @method listToMap
  668. * @warning 该方法在生成的hash对象中,会为每一个key同时生成一个另一个全大写的key。
  669. * @param { Array } arr 字符串数组
  670. * @return { Object } 转化之后的hash对象
  671. * @example
  672. * ```javascript
  673. *
  674. * //output: Object {UEdtior: 1, UEDTIOR: 1, Hello: 1, HELLO: 1}
  675. * console.log( UE.utils.listToMap( [ 'UEdtior', 'Hello' ] ) );
  676. *
  677. * ```
  678. */
  679. listToMap: function(list) {
  680. if (!list) return {};
  681. list = utils.isArray(list) ? list : list.split(",");
  682. for (var i = 0, ci, obj = {}; (ci = list[i++]); ) {
  683. obj[ci.toUpperCase()] = obj[ci] = 1;
  684. }
  685. return obj;
  686. },
  687. /**
  688. * 将str中的html符号转义,将转义“',&,<,",>,”,“”七个字符
  689. * @method unhtml
  690. * @param { String } str 需要转义的字符串
  691. * @return { String } 转义后的字符串
  692. * @example
  693. * ```javascript
  694. * var html = '<body>&</body>';
  695. *
  696. * //output: &lt;body&gt;&amp;&lt;/body&gt;
  697. * console.log( UE.utils.unhtml( html ) );
  698. *
  699. * ```
  700. */
  701. unhtml: function(str, reg) {
  702. return str
  703. ? str.replace(
  704. reg || /[&<">'](?:(amp|lt|ldquo|rdquo|quot|gt|#39|nbsp|#\d+);)?/g,
  705. function(a, b) {
  706. if (b) {
  707. return a;
  708. } else {
  709. return {
  710. "<": "&lt;",
  711. "&": "&amp;",
  712. '"': "&quot;",
  713. "“": "&ldquo;",
  714. "”": "&rdquo;",
  715. ">": "&gt;",
  716. "'": "&#39;"
  717. }[a];
  718. }
  719. }
  720. )
  721. : "";
  722. },
  723. /**
  724. * 将str中的转义字符还原成html字符
  725. * @see UE.utils.unhtml(String);
  726. * @method html
  727. * @param { String } str 需要逆转义的字符串
  728. * @return { String } 逆转义后的字符串
  729. * @example
  730. * ```javascript
  731. *
  732. * var str = '&lt;body&gt;&amp;&lt;/body&gt;';
  733. *
  734. * //output: <body>&</body>
  735. * console.log( UE.utils.html( str ) );
  736. *
  737. * ```
  738. */
  739. html: function(str) {
  740. return str
  741. ? str.replace(/&((g|l|quo|ldquo|rdquo)t|amp|#39|nbsp);/g, function(m) {
  742. return {
  743. "&lt;": "<",
  744. "&amp;": "&",
  745. "&quot;": '"',
  746. "&ldquo;": "“",
  747. "&rdquo;": "”",
  748. "&gt;": ">",
  749. "&#39;": "'",
  750. "&nbsp;": " "
  751. }[m];
  752. })
  753. : "";
  754. },
  755. /**
  756. * 将css样式转换为驼峰的形式
  757. * @method cssStyleToDomStyle
  758. * @param { String } cssName 需要转换的css样式名
  759. * @return { String } 转换成驼峰形式后的css样式名
  760. * @example
  761. * ```javascript
  762. *
  763. * var str = 'border-top';
  764. *
  765. * //output: borderTop
  766. * console.log( UE.utils.cssStyleToDomStyle( str ) );
  767. *
  768. * ```
  769. */
  770. cssStyleToDomStyle: (function() {
  771. var test = document.createElement("div").style,
  772. cache = {
  773. float: test.cssFloat != undefined
  774. ? "cssFloat"
  775. : test.styleFloat != undefined ? "styleFloat" : "float"
  776. };
  777. return function(cssName) {
  778. return (
  779. cache[cssName] ||
  780. (cache[cssName] = cssName.toLowerCase().replace(/-./g, function(match) {
  781. return match.charAt(1).toUpperCase();
  782. }))
  783. );
  784. };
  785. })(),
  786. /**
  787. * 动态加载文件到doc中
  788. * @method loadFile
  789. * @param { DomDocument } document 需要加载资源文件的文档对象
  790. * @param { Object } options 加载资源文件的属性集合, 取值请参考代码示例
  791. * @example
  792. * ```javascript
  793. *
  794. * UE.utils.loadFile( document, {
  795. * src:"test.js",
  796. * tag:"script",
  797. * type:"text/javascript",
  798. * defer:"defer"
  799. * } );
  800. *
  801. * ```
  802. */
  803. /**
  804. * 动态加载文件到doc中,加载成功后执行的回调函数fn
  805. * @method loadFile
  806. * @param { DomDocument } document 需要加载资源文件的文档对象
  807. * @param { Object } options 加载资源文件的属性集合, 该集合支持的值是script标签和style标签支持的所有属性。
  808. * @param { Function } fn 资源文件加载成功之后执行的回调
  809. * @warning 对于在同一个文档中多次加载同一URL的文件, 该方法会在第一次加载之后缓存该请求,
  810. * 在此之后的所有同一URL的请求, 将会直接触发回调。
  811. * @example
  812. * ```javascript
  813. *
  814. * UE.utils.loadFile( document, {
  815. * src:"test.js",
  816. * tag:"script",
  817. * type:"text/javascript",
  818. * defer:"defer"
  819. * }, function () {
  820. * console.log('加载成功');
  821. * } );
  822. *
  823. * ```
  824. */
  825. loadFile: (function() {
  826. var tmpList = [];
  827. function getItem(doc, obj) {
  828. try {
  829. for (var i = 0, ci; (ci = tmpList[i++]); ) {
  830. if (ci.doc === doc && ci.url == (obj.src || obj.href)) {
  831. return ci;
  832. }
  833. }
  834. } catch (e) {
  835. return null;
  836. }
  837. }
  838. return function(doc, obj, fn) {
  839. var item = getItem(doc, obj);
  840. if (item) {
  841. if (item.ready) {
  842. fn && fn();
  843. } else {
  844. item.funs.push(fn);
  845. }
  846. return;
  847. }
  848. tmpList.push({
  849. doc: doc,
  850. url: obj.src || obj.href,
  851. funs: [fn]
  852. });
  853. if (!doc.body) {
  854. var html = [];
  855. for (var p in obj) {
  856. if (p == "tag") continue;
  857. html.push(p + '="' + obj[p] + '"');
  858. }
  859. doc.write(
  860. "<" + obj.tag + " " + html.join(" ") + " ></" + obj.tag + ">"
  861. );
  862. return;
  863. }
  864. if (obj.id && doc.getElementById(obj.id)) {
  865. return;
  866. }
  867. var element = doc.createElement(obj.tag);
  868. delete obj.tag;
  869. for (var p in obj) {
  870. element.setAttribute(p, obj[p]);
  871. }
  872. element.onload = element.onreadystatechange = function() {
  873. if (!this.readyState || /loaded|complete/.test(this.readyState)) {
  874. item = getItem(doc, obj);
  875. if (item.funs.length > 0) {
  876. item.ready = 1;
  877. for (var fi; (fi = item.funs.pop()); ) {
  878. fi();
  879. }
  880. }
  881. element.onload = element.onreadystatechange = null;
  882. }
  883. };
  884. element.onerror = function() {
  885. throw Error(
  886. "The load " +
  887. (obj.href || obj.src) +
  888. " fails,check the url settings of file neditor.config.js "
  889. );
  890. };
  891. doc.getElementsByTagName("head")[0].appendChild(element);
  892. };
  893. })(),
  894. /**
  895. * 判断obj对象是否为空
  896. * @method isEmptyObject
  897. * @param { * } obj 需要判断的对象
  898. * @remind 如果判断的对象是NULL, 将直接返回true, 如果是数组且为空, 返回true, 如果是字符串, 且字符串为空,
  899. * 返回true, 如果是普通对象, 且该对象没有任何实例属性, 返回true
  900. * @return { Boolean } 对象是否为空
  901. * @example
  902. * ```javascript
  903. *
  904. * //output: true
  905. * console.log( UE.utils.isEmptyObject( {} ) );
  906. *
  907. * //output: true
  908. * console.log( UE.utils.isEmptyObject( [] ) );
  909. *
  910. * //output: true
  911. * console.log( UE.utils.isEmptyObject( "" ) );
  912. *
  913. * //output: false
  914. * console.log( UE.utils.isEmptyObject( { key: 1 } ) );
  915. *
  916. * //output: false
  917. * console.log( UE.utils.isEmptyObject( [1] ) );
  918. *
  919. * //output: false
  920. * console.log( UE.utils.isEmptyObject( "1" ) );
  921. *
  922. * ```
  923. */
  924. isEmptyObject: function(obj) {
  925. if (obj == null) return true;
  926. if (this.isArray(obj) || this.isString(obj)) return obj.length === 0;
  927. for (var key in obj) if (obj.hasOwnProperty(key)) return false;
  928. return true;
  929. },
  930. /**
  931. * 把rgb格式的颜色值转换成16进制格式
  932. * @method fixColor
  933. * @param { String } rgb格式的颜色值
  934. * @param { String }
  935. * @example
  936. * rgb(255,255,255) => "#ffffff"
  937. */
  938. fixColor: function(name, value) {
  939. if (/color/i.test(name) && /rgba?/.test(value)) {
  940. var array = value.split(",");
  941. if (array.length > 3) return "";
  942. value = "#";
  943. for (var i = 0, color; (color = array[i++]); ) {
  944. color = parseInt(color.replace(/[^\d]/gi, ""), 10).toString(16);
  945. value += color.length == 1 ? "0" + color : color;
  946. }
  947. value = value.toUpperCase();
  948. }
  949. return value;
  950. },
  951. /**
  952. * 只针对border,padding,margin做了处理,因为性能问题
  953. * @public
  954. * @function
  955. * @param {String} val style字符串
  956. */
  957. optCss: function(val) {
  958. var padding, margin, border;
  959. val = val.replace(/(padding|margin|border)\-([^:]+):([^;]+);?/gi, function(
  960. str,
  961. key,
  962. name,
  963. val
  964. ) {
  965. if (val.split(" ").length == 1) {
  966. switch (key) {
  967. case "padding":
  968. !padding && (padding = {});
  969. padding[name] = val;
  970. return "";
  971. case "margin":
  972. !margin && (margin = {});
  973. margin[name] = val;
  974. return "";
  975. case "border":
  976. return val == "initial" ? "" : str;
  977. }
  978. }
  979. return str;
  980. });
  981. function opt(obj, name) {
  982. if (!obj) {
  983. return "";
  984. }
  985. var t = obj.top,
  986. b = obj.bottom,
  987. l = obj.left,
  988. r = obj.right,
  989. val = "";
  990. if (!t || !l || !b || !r) {
  991. for (var p in obj) {
  992. val += ";" + name + "-" + p + ":" + obj[p] + ";";
  993. }
  994. } else {
  995. val +=
  996. ";" +
  997. name +
  998. ":" +
  999. (t == b && b == l && l == r
  1000. ? t
  1001. : t == b && l == r
  1002. ? t + " " + l
  1003. : l == r
  1004. ? t + " " + l + " " + b
  1005. : t + " " + r + " " + b + " " + l) +
  1006. ";";
  1007. }
  1008. return val;
  1009. }
  1010. val += opt(padding, "padding") + opt(margin, "margin");
  1011. return val
  1012. .replace(/^[ \n\r\t;]*|[ \n\r\t]*$/, "")
  1013. .replace(/;([ \n\r\t]+)|\1;/g, ";")
  1014. .replace(/(&((l|g)t|quot|#39))?;{2,}/g, function(a, b) {
  1015. return b ? b + ";;" : ";";
  1016. });
  1017. },
  1018. /**
  1019. * 克隆对象
  1020. * @method clone
  1021. * @param { Object } source 源对象
  1022. * @return { Object } source的一个副本
  1023. */
  1024. /**
  1025. * 深度克隆对象,将source的属性克隆到target对象, 会覆盖target重名的属性。
  1026. * @method clone
  1027. * @param { Object } source 源对象
  1028. * @param { Object } target 目标对象
  1029. * @return { Object } 附加了source对象所有属性的target对象
  1030. */
  1031. clone: function(source, target) {
  1032. var tmp;
  1033. target = target || {};
  1034. for (var i in source) {
  1035. if (source.hasOwnProperty(i)) {
  1036. tmp = source[i];
  1037. if (typeof tmp == "object") {
  1038. target[i] = utils.isArray(tmp) ? [] : {};
  1039. utils.clone(source[i], target[i]);
  1040. } else {
  1041. target[i] = tmp;
  1042. }
  1043. }
  1044. }
  1045. return target;
  1046. },
  1047. /**
  1048. * 把cm/pt为单位的值转换为px为单位的值
  1049. * @method transUnitToPx
  1050. * @param { String } 待转换的带单位的字符串
  1051. * @return { String } 转换为px为计量单位的值的字符串
  1052. * @example
  1053. * ```javascript
  1054. *
  1055. * //output: 500px
  1056. * console.log( UE.utils.transUnitToPx( '20cm' ) );
  1057. *
  1058. * //output: 27px
  1059. * console.log( UE.utils.transUnitToPx( '20pt' ) );
  1060. *
  1061. * ```
  1062. */
  1063. transUnitToPx: function(val) {
  1064. if (!/(pt|cm)/.test(val)) {
  1065. return val;
  1066. }
  1067. var unit;
  1068. val.replace(/([\d.]+)(\w+)/, function(str, v, u) {
  1069. val = v;
  1070. unit = u;
  1071. });
  1072. switch (unit) {
  1073. case "cm":
  1074. val = parseFloat(val) * 25;
  1075. break;
  1076. case "pt":
  1077. val = Math.round(parseFloat(val) * 96 / 72);
  1078. }
  1079. return val + (val ? "px" : "");
  1080. },
  1081. /**
  1082. * 在dom树ready之后执行给定的回调函数
  1083. * @method domReady
  1084. * @remind 如果在执行该方法的时候, dom树已经ready, 那么回调函数将立刻执行
  1085. * @param { Function } fn dom树ready之后的回调函数
  1086. * @example
  1087. * ```javascript
  1088. *
  1089. * UE.utils.domReady( function () {
  1090. *
  1091. * console.log('123');
  1092. *
  1093. * } );
  1094. *
  1095. * ```
  1096. */
  1097. domReady: (function() {
  1098. var fnArr = [];
  1099. function doReady(doc) {
  1100. //确保onready只执行一次
  1101. doc.isReady = true;
  1102. for (var ci; (ci = fnArr.pop()); ci()) {}
  1103. }
  1104. return function(onready, win) {
  1105. win = win || window;
  1106. var doc = win.document;
  1107. onready && fnArr.push(onready);
  1108. if (doc.readyState === "complete") {
  1109. doReady(doc);
  1110. } else {
  1111. doc.isReady && doReady(doc);
  1112. if (browser.ie && browser.version != 11) {
  1113. (function() {
  1114. if (doc.isReady) return;
  1115. try {
  1116. doc.documentElement.doScroll("left");
  1117. } catch (error) {
  1118. setTimeout(arguments.callee, 0);
  1119. return;
  1120. }
  1121. doReady(doc);
  1122. })();
  1123. win.attachEvent("onload", function() {
  1124. doReady(doc);
  1125. });
  1126. } else {
  1127. doc.addEventListener(
  1128. "DOMContentLoaded",
  1129. function() {
  1130. doc.removeEventListener(
  1131. "DOMContentLoaded",
  1132. arguments.callee,
  1133. false
  1134. );
  1135. doReady(doc);
  1136. },
  1137. false
  1138. );
  1139. win.addEventListener(
  1140. "load",
  1141. function() {
  1142. doReady(doc);
  1143. },
  1144. false
  1145. );
  1146. }
  1147. }
  1148. };
  1149. })(),
  1150. /**
  1151. * 动态添加css样式
  1152. * @method cssRule
  1153. * @param { String } 节点名称
  1154. * @grammar UE.utils.cssRule('添加的样式的节点名称',['样式','放到哪个document上'])
  1155. * @grammar UE.utils.cssRule('body','body{background:#ccc}') => null //给body添加背景颜色
  1156. * @grammar UE.utils.cssRule('body') =>样式的字符串 //取得key值为body的样式的内容,如果没有找到key值先关的样式将返回空,例如刚才那个背景颜色,将返回 body{background:#ccc}
  1157. * @grammar UE.utils.cssRule('body',document) => 返回指定key的样式,并且指定是哪个document
  1158. * @grammar UE.utils.cssRule('body','') =>null //清空给定的key值的背景颜色
  1159. */
  1160. cssRule: browser.ie && browser.version != 11
  1161. ? function(key, style, doc) {
  1162. var indexList, index;
  1163. if (
  1164. style === undefined ||
  1165. (style && style.nodeType && style.nodeType == 9)
  1166. ) {
  1167. //获取样式
  1168. doc = style && style.nodeType && style.nodeType == 9
  1169. ? style
  1170. : doc || document;
  1171. indexList = doc.indexList || (doc.indexList = {});
  1172. index = indexList[key];
  1173. if (index !== undefined) {
  1174. return doc.styleSheets[index].cssText;
  1175. }
  1176. return undefined;
  1177. }
  1178. doc = doc || document;
  1179. indexList = doc.indexList || (doc.indexList = {});
  1180. index = indexList[key];
  1181. //清除样式
  1182. if (style === "") {
  1183. if (index !== undefined) {
  1184. doc.styleSheets[index].cssText = "";
  1185. delete indexList[key];
  1186. return true;
  1187. }
  1188. return false;
  1189. }
  1190. //添加样式
  1191. if (index !== undefined) {
  1192. sheetStyle = doc.styleSheets[index];
  1193. } else {
  1194. sheetStyle = doc.createStyleSheet(
  1195. "",
  1196. (index = doc.styleSheets.length)
  1197. );
  1198. indexList[key] = index;
  1199. }
  1200. sheetStyle.cssText = style;
  1201. }
  1202. : function(key, style, doc) {
  1203. var head, node;
  1204. if (
  1205. style === undefined ||
  1206. (style && style.nodeType && style.nodeType == 9)
  1207. ) {
  1208. //获取样式
  1209. doc = style && style.nodeType && style.nodeType == 9
  1210. ? style
  1211. : doc || document;
  1212. node = doc.getElementById(key);
  1213. return node ? node.innerHTML : undefined;
  1214. }
  1215. doc = doc || document;
  1216. node = doc.getElementById(key);
  1217. //清除样式
  1218. if (style === "") {
  1219. if (node) {
  1220. node.parentNode.removeChild(node);
  1221. return true;
  1222. }
  1223. return false;
  1224. }
  1225. //添加样式
  1226. if (node) {
  1227. node.innerHTML = style;
  1228. } else {
  1229. node = doc.createElement("style");
  1230. node.id = key;
  1231. node.innerHTML = style;
  1232. doc.getElementsByTagName("head")[0].appendChild(node);
  1233. }
  1234. },
  1235. sort: function(array, compareFn) {
  1236. compareFn =
  1237. compareFn ||
  1238. function(item1, item2) {
  1239. return item1.localeCompare(item2);
  1240. };
  1241. for (var i = 0, len = array.length; i < len; i++) {
  1242. for (var j = i, length = array.length; j < length; j++) {
  1243. if (compareFn(array[i], array[j]) > 0) {
  1244. var t = array[i];
  1245. array[i] = array[j];
  1246. array[j] = t;
  1247. }
  1248. }
  1249. }
  1250. return array;
  1251. },
  1252. serializeParam: function(json) {
  1253. var strArr = [];
  1254. for (var i in json) {
  1255. //忽略默认的几个参数
  1256. if (i == "method" || i == "timeout" || i == "async") continue;
  1257. //传递过来的对象和函数不在提交之列
  1258. if (
  1259. !(
  1260. (typeof json[i]).toLowerCase() == "function" ||
  1261. (typeof json[i]).toLowerCase() == "object"
  1262. )
  1263. ) {
  1264. strArr.push(encodeURIComponent(i) + "=" + encodeURIComponent(json[i]));
  1265. } else if (utils.isArray(json[i])) {
  1266. //支持传数组内容
  1267. for (var j = 0; j < json[i].length; j++) {
  1268. strArr.push(
  1269. encodeURIComponent(i) + "[]=" + encodeURIComponent(json[i][j])
  1270. );
  1271. }
  1272. }
  1273. }
  1274. return strArr.join("&");
  1275. },
  1276. formatUrl: function(url) {
  1277. var u = url.replace(/&&/g, "&");
  1278. u = u.replace(/\?&/g, "?");
  1279. u = u.replace(/&$/g, "");
  1280. u = u.replace(/&#/g, "#");
  1281. u = u.replace(/&+/g, "&");
  1282. return u;
  1283. },
  1284. isCrossDomainUrl: function(url) {
  1285. var a = document.createElement("a");
  1286. a.href = url;
  1287. if (browser.ie) {
  1288. a.href = a.href;
  1289. }
  1290. return !(
  1291. a.protocol == location.protocol &&
  1292. a.hostname == location.hostname &&
  1293. (a.port == location.port ||
  1294. (a.port == "80" && location.port == "") ||
  1295. (a.port == "" && location.port == "80"))
  1296. );
  1297. },
  1298. clearEmptyAttrs: function(obj) {
  1299. for (var p in obj) {
  1300. if (obj[p] === "") {
  1301. delete obj[p];
  1302. }
  1303. }
  1304. return obj;
  1305. },
  1306. str2json: function(s) {
  1307. if (!utils.isString(s)) return null;
  1308. if (window.JSON) {
  1309. return JSON.parse(s);
  1310. } else {
  1311. return new Function("return " + utils.trim(s || ""))();
  1312. }
  1313. },
  1314. json2str: (function() {
  1315. if (window.JSON) {
  1316. return JSON.stringify;
  1317. } else {
  1318. var escapeMap = {
  1319. "\b": "\\b",
  1320. "\t": "\\t",
  1321. "\n": "\\n",
  1322. "\f": "\\f",
  1323. "\r": "\\r",
  1324. '"': '\\"',
  1325. "\\": "\\\\"
  1326. };
  1327. function encodeString(source) {
  1328. if (/["\\\x00-\x1f]/.test(source)) {
  1329. source = source.replace(/["\\\x00-\x1f]/g, function(match) {
  1330. var c = escapeMap[match];
  1331. if (c) {
  1332. return c;
  1333. }
  1334. c = match.charCodeAt();
  1335. return (
  1336. "\\u00" + Math.floor(c / 16).toString(16) + (c % 16).toString(16)
  1337. );
  1338. });
  1339. }
  1340. return '"' + source + '"';
  1341. }
  1342. function encodeArray(source) {
  1343. var result = ["["],
  1344. l = source.length,
  1345. preComma,
  1346. i,
  1347. item;
  1348. for (i = 0; i < l; i++) {
  1349. item = source[i];
  1350. switch (typeof item) {
  1351. case "undefined":
  1352. case "function":
  1353. case "unknown":
  1354. break;
  1355. default:
  1356. if (preComma) {
  1357. result.push(",");
  1358. }
  1359. result.push(utils.json2str(item));
  1360. preComma = 1;
  1361. }
  1362. }
  1363. result.push("]");
  1364. return result.join("");
  1365. }
  1366. function pad(source) {
  1367. return source < 10 ? "0" + source : source;
  1368. }
  1369. function encodeDate(source) {
  1370. return (
  1371. '"' +
  1372. source.getFullYear() +
  1373. "-" +
  1374. pad(source.getMonth() + 1) +
  1375. "-" +
  1376. pad(source.getDate()) +
  1377. "T" +
  1378. pad(source.getHours()) +
  1379. ":" +
  1380. pad(source.getMinutes()) +
  1381. ":" +
  1382. pad(source.getSeconds()) +
  1383. '"'
  1384. );
  1385. }
  1386. return function(value) {
  1387. switch (typeof value) {
  1388. case "undefined":
  1389. return "undefined";
  1390. case "number":
  1391. return isFinite(value) ? String(value) : "null";
  1392. case "string":
  1393. return encodeString(value);
  1394. case "boolean":
  1395. return String(value);
  1396. default:
  1397. if (value === null) {
  1398. return "null";
  1399. } else if (utils.isArray(value)) {
  1400. return encodeArray(value);
  1401. } else if (utils.isDate(value)) {
  1402. return encodeDate(value);
  1403. } else {
  1404. var result = ["{"],
  1405. encode = utils.json2str,
  1406. preComma,
  1407. item;
  1408. for (var key in value) {
  1409. if (Object.prototype.hasOwnProperty.call(value, key)) {
  1410. item = value[key];
  1411. switch (typeof item) {
  1412. case "undefined":
  1413. case "unknown":
  1414. case "function":
  1415. break;
  1416. default:
  1417. if (preComma) {
  1418. result.push(",");
  1419. }
  1420. preComma = 1;
  1421. result.push(encode(key) + ":" + encode(item));
  1422. }
  1423. }
  1424. }
  1425. result.push("}");
  1426. return result.join("");
  1427. }
  1428. }
  1429. };
  1430. }
  1431. })(),
  1432. renderTplstr: function(tpl, data) {
  1433. return tpl.replace(/\$\{\s*(\w*?)\s*\}/g, function (match, variable) {
  1434. if (data.hasOwnProperty(variable)) {
  1435. return data[variable];
  1436. }
  1437. });
  1438. }
  1439. });
  1440. /**
  1441. * 判断给定的对象是否是字符串
  1442. * @method isString
  1443. * @param { * } object 需要判断的对象
  1444. * @return { Boolean } 给定的对象是否是字符串
  1445. */
  1446. /**
  1447. * 判断给定的对象是否是数组
  1448. * @method isArray
  1449. * @param { * } object 需要判断的对象
  1450. * @return { Boolean } 给定的对象是否是数组
  1451. */
  1452. /**
  1453. * 判断给定的对象是否是一个Function
  1454. * @method isFunction
  1455. * @param { * } object 需要判断的对象
  1456. * @return { Boolean } 给定的对象是否是Function
  1457. */
  1458. /**
  1459. * 判断给定的对象是否是Number
  1460. * @method isNumber
  1461. * @param { * } object 需要判断的对象
  1462. * @return { Boolean } 给定的对象是否是Number
  1463. */
  1464. /**
  1465. * 判断给定的对象是否是一个正则表达式
  1466. * @method isRegExp
  1467. * @param { * } object 需要判断的对象
  1468. * @return { Boolean } 给定的对象是否是正则表达式
  1469. */
  1470. /**
  1471. * 判断给定的对象是否是一个普通对象
  1472. * @method isObject
  1473. * @param { * } object 需要判断的对象
  1474. * @return { Boolean } 给定的对象是否是普通对象
  1475. */
  1476. utils.each(
  1477. ["String", "Function", "Array", "Number", "RegExp", "Object", "Date"],
  1478. function(v) {
  1479. UE.utils["is" + v] = function(obj) {
  1480. return Object.prototype.toString.apply(obj) == "[object " + v + "]";
  1481. };
  1482. }
  1483. );
  1484. // core/EventBase.js
  1485. /**
  1486. * UE采用的事件基类
  1487. * @file
  1488. * @module UE
  1489. * @class EventBase
  1490. * @since 1.2.6.1
  1491. */
  1492. /**
  1493. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  1494. * @unfile
  1495. * @module UE
  1496. */
  1497. /**
  1498. * UE采用的事件基类,继承此类的对应类将获取addListener,removeListener,fireEvent方法。
  1499. * 在UE中,Editor以及所有ui实例都继承了该类,故可以在对应的ui对象以及editor对象上使用上述方法。
  1500. * @unfile
  1501. * @module UE
  1502. * @class EventBase
  1503. */
  1504. /**
  1505. * 通过此构造器,子类可以继承EventBase获取事件监听的方法
  1506. * @constructor
  1507. * @example
  1508. * ```javascript
  1509. * UE.EventBase.call(editor);
  1510. * ```
  1511. */
  1512. var EventBase = (UE.EventBase = function() {});
  1513. EventBase.prototype = {
  1514. /**
  1515. * 注册事件监听器
  1516. * @method addListener
  1517. * @param { String } types 监听的事件名称,同时监听多个事件使用空格分隔
  1518. * @param { Function } fn 监听的事件被触发时,会执行该回调函数
  1519. * @waining 事件被触发时,监听的函数假如返回的值恒等于true,回调函数的队列中后面的函数将不执行
  1520. * @example
  1521. * ```javascript
  1522. * editor.addListener('selectionchange',function(){
  1523. * console.log("选区已经变化!");
  1524. * })
  1525. * editor.addListener('beforegetcontent aftergetcontent',function(type){
  1526. * if(type == 'beforegetcontent'){
  1527. * //do something
  1528. * }else{
  1529. * //do something
  1530. * }
  1531. * console.log(this.getContent) // this是注册的事件的编辑器实例
  1532. * })
  1533. * ```
  1534. * @see UE.EventBase:fireEvent(String)
  1535. */
  1536. addListener: function(types, listener) {
  1537. types = utils.trim(types).split(/\s+/);
  1538. for (var i = 0, ti; (ti = types[i++]); ) {
  1539. getListener(this, ti, true).push(listener);
  1540. }
  1541. },
  1542. on: function(types, listener) {
  1543. return this.addListener(types, listener);
  1544. },
  1545. off: function(types, listener) {
  1546. return this.removeListener(types, listener);
  1547. },
  1548. trigger: function() {
  1549. return this.fireEvent.apply(this, arguments);
  1550. },
  1551. /**
  1552. * 移除事件监听器
  1553. * @method removeListener
  1554. * @param { String } types 移除的事件名称,同时移除多个事件使用空格分隔
  1555. * @param { Function } fn 移除监听事件的函数引用
  1556. * @example
  1557. * ```javascript
  1558. * //changeCallback为方法体
  1559. * editor.removeListener("selectionchange",changeCallback);
  1560. * ```
  1561. */
  1562. removeListener: function(types, listener) {
  1563. types = utils.trim(types).split(/\s+/);
  1564. for (var i = 0, ti; (ti = types[i++]); ) {
  1565. utils.removeItem(getListener(this, ti) || [], listener);
  1566. }
  1567. },
  1568. /**
  1569. * 触发事件
  1570. * @method fireEvent
  1571. * @param { String } types 触发的事件名称,同时触发多个事件使用空格分隔
  1572. * @remind 该方法会触发addListener
  1573. * @return { * } 返回触发事件的队列中,最后执行的回调函数的返回值
  1574. * @example
  1575. * ```javascript
  1576. * editor.fireEvent("selectionchange");
  1577. * ```
  1578. */
  1579. /**
  1580. * 触发事件
  1581. * @method fireEvent
  1582. * @param { String } types 触发的事件名称,同时触发多个事件使用空格分隔
  1583. * @param { *... } options 可选参数,可以传入一个或多个参数,会传给事件触发的回调函数
  1584. * @return { * } 返回触发事件的队列中,最后执行的回调函数的返回值
  1585. * @example
  1586. * ```javascript
  1587. *
  1588. * editor.addListener( "selectionchange", function ( type, arg1, arg2 ) {
  1589. *
  1590. * console.log( arg1 + " " + arg2 );
  1591. *
  1592. * } );
  1593. *
  1594. * //触发selectionchange事件, 会执行上面的事件监听器
  1595. * //output: Hello World
  1596. * editor.fireEvent("selectionchange", "Hello", "World");
  1597. * ```
  1598. */
  1599. fireEvent: function() {
  1600. var types = arguments[0];
  1601. types = utils.trim(types).split(" ");
  1602. for (var i = 0, ti; (ti = types[i++]); ) {
  1603. var listeners = getListener(this, ti),
  1604. r,
  1605. t,
  1606. k;
  1607. if (listeners) {
  1608. k = listeners.length;
  1609. while (k--) {
  1610. if (!listeners[k]) continue;
  1611. t = listeners[k].apply(this, arguments);
  1612. if (t === true) {
  1613. return t;
  1614. }
  1615. if (t !== undefined) {
  1616. r = t;
  1617. }
  1618. }
  1619. }
  1620. if ((t = this["on" + ti.toLowerCase()])) {
  1621. r = t.apply(this, arguments);
  1622. }
  1623. }
  1624. return r;
  1625. }
  1626. };
  1627. /**
  1628. * 获得对象所拥有监听类型的所有监听器
  1629. * @unfile
  1630. * @module UE
  1631. * @since 1.2.6.1
  1632. * @method getListener
  1633. * @public
  1634. * @param { Object } obj 查询监听器的对象
  1635. * @param { String } type 事件类型
  1636. * @param { Boolean } force 为true且当前所有type类型的侦听器不存在时,创建一个空监听器数组
  1637. * @return { Array } 监听器数组
  1638. */
  1639. function getListener(obj, type, force) {
  1640. var allListeners;
  1641. type = type.toLowerCase();
  1642. return (
  1643. (allListeners =
  1644. obj.__allListeners || (force && (obj.__allListeners = {}))) &&
  1645. (allListeners[type] || (force && (allListeners[type] = [])))
  1646. );
  1647. }
  1648. // core/dtd.js
  1649. ///import editor.js
  1650. ///import core/dom/dom.js
  1651. ///import core/utils.js
  1652. /**
  1653. * dtd html语义化的体现类
  1654. * @constructor
  1655. * @namespace dtd
  1656. */
  1657. var dtd = (dom.dtd = (function() {
  1658. function _(s) {
  1659. for (var k in s) {
  1660. s[k.toUpperCase()] = s[k];
  1661. }
  1662. return s;
  1663. }
  1664. var X = utils.extend2;
  1665. var A = _({ isindex: 1, fieldset: 1 }),
  1666. B = _({ input: 1, button: 1, select: 1, textarea: 1, label: 1 }),
  1667. C = X(_({ a: 1 }), B),
  1668. D = X({ iframe: 1 }, C),
  1669. E = _({
  1670. hr: 1,
  1671. ul: 1,
  1672. menu: 1,
  1673. div: 1,
  1674. blockquote: 1,
  1675. noscript: 1,
  1676. table: 1,
  1677. center: 1,
  1678. address: 1,
  1679. dir: 1,
  1680. pre: 1,
  1681. h5: 1,
  1682. dl: 1,
  1683. h4: 1,
  1684. noframes: 1,
  1685. h6: 1,
  1686. ol: 1,
  1687. h1: 1,
  1688. h3: 1,
  1689. h2: 1
  1690. }),
  1691. F = _({ ins: 1, del: 1, script: 1, style: 1 }),
  1692. G = X(
  1693. _({
  1694. mark: 1,
  1695. b: 1,
  1696. acronym: 1,
  1697. bdo: 1,
  1698. var: 1,
  1699. "#": 1,
  1700. abbr: 1,
  1701. code: 1,
  1702. br: 1,
  1703. i: 1,
  1704. cite: 1,
  1705. kbd: 1,
  1706. u: 1,
  1707. strike: 1,
  1708. s: 1,
  1709. tt: 1,
  1710. strong: 1,
  1711. q: 1,
  1712. samp: 1,
  1713. em: 1,
  1714. dfn: 1,
  1715. span: 1
  1716. }),
  1717. F
  1718. ),
  1719. H = X(
  1720. _({
  1721. sub: 1,
  1722. img: 1,
  1723. embed: 1,
  1724. object: 1,
  1725. sup: 1,
  1726. basefont: 1,
  1727. map: 1,
  1728. applet: 1,
  1729. font: 1,
  1730. big: 1,
  1731. small: 1
  1732. }),
  1733. G
  1734. ),
  1735. I = X(_({ p: 1 }), H),
  1736. J = X(_({ iframe: 1 }), H, B),
  1737. K = _({
  1738. img: 1,
  1739. embed: 1,
  1740. noscript: 1,
  1741. br: 1,
  1742. kbd: 1,
  1743. center: 1,
  1744. button: 1,
  1745. basefont: 1,
  1746. h5: 1,
  1747. h4: 1,
  1748. samp: 1,
  1749. h6: 1,
  1750. ol: 1,
  1751. h1: 1,
  1752. h3: 1,
  1753. h2: 1,
  1754. form: 1,
  1755. font: 1,
  1756. "#": 1,
  1757. select: 1,
  1758. menu: 1,
  1759. ins: 1,
  1760. abbr: 1,
  1761. label: 1,
  1762. code: 1,
  1763. table: 1,
  1764. script: 1,
  1765. cite: 1,
  1766. input: 1,
  1767. iframe: 1,
  1768. strong: 1,
  1769. textarea: 1,
  1770. noframes: 1,
  1771. big: 1,
  1772. small: 1,
  1773. span: 1,
  1774. hr: 1,
  1775. sub: 1,
  1776. bdo: 1,
  1777. var: 1,
  1778. div: 1,
  1779. object: 1,
  1780. sup: 1,
  1781. strike: 1,
  1782. dir: 1,
  1783. map: 1,
  1784. dl: 1,
  1785. applet: 1,
  1786. del: 1,
  1787. isindex: 1,
  1788. fieldset: 1,
  1789. ul: 1,
  1790. b: 1,
  1791. acronym: 1,
  1792. a: 1,
  1793. blockquote: 1,
  1794. i: 1,
  1795. u: 1,
  1796. s: 1,
  1797. tt: 1,
  1798. address: 1,
  1799. q: 1,
  1800. pre: 1,
  1801. p: 1,
  1802. em: 1,
  1803. dfn: 1
  1804. }),
  1805. L = X(_({ a: 0 }), J), //a不能被切开,所以把他
  1806. M = _({ tr: 1 }),
  1807. N = _({ "#": 1 }),
  1808. O = X(_({ param: 1 }), K),
  1809. P = X(_({ form: 1 }), A, D, E, I),
  1810. Q = _({ li: 1, ol: 1, ul: 1 }),
  1811. R = _({ style: 1, script: 1 }),
  1812. S = _({ base: 1, link: 1, meta: 1, title: 1 }),
  1813. T = X(S, R),
  1814. U = _({ head: 1, body: 1 }),
  1815. V = _({ html: 1 });
  1816. var block = _({
  1817. address: 1,
  1818. blockquote: 1,
  1819. center: 1,
  1820. dir: 1,
  1821. div: 1,
  1822. dl: 1,
  1823. fieldset: 1,
  1824. form: 1,
  1825. h1: 1,
  1826. h2: 1,
  1827. h3: 1,
  1828. h4: 1,
  1829. h5: 1,
  1830. h6: 1,
  1831. hr: 1,
  1832. isindex: 1,
  1833. menu: 1,
  1834. noframes: 1,
  1835. ol: 1,
  1836. p: 1,
  1837. pre: 1,
  1838. table: 1,
  1839. ul: 1
  1840. }),
  1841. empty = _({
  1842. area: 1,
  1843. base: 1,
  1844. basefont: 1,
  1845. br: 1,
  1846. col: 1,
  1847. command: 1,
  1848. dialog: 1,
  1849. embed: 1,
  1850. hr: 1,
  1851. img: 1,
  1852. input: 1,
  1853. isindex: 1,
  1854. keygen: 1,
  1855. link: 1,
  1856. meta: 1,
  1857. param: 1,
  1858. source: 1,
  1859. track: 1,
  1860. wbr: 1
  1861. });
  1862. return _({
  1863. // $ 表示自定的属性
  1864. // body外的元素列表.
  1865. $nonBodyContent: X(V, U, S),
  1866. //块结构元素列表
  1867. $block: block,
  1868. //内联元素列表
  1869. $inline: L,
  1870. $inlineWithA: X(_({ a: 1 }), L),
  1871. $body: X(_({ script: 1, style: 1 }), block),
  1872. $cdata: _({ script: 1, style: 1 }),
  1873. //自闭和元素
  1874. $empty: empty,
  1875. //不是自闭合,但不能让range选中里边
  1876. $nonChild: _({ iframe: 1, textarea: 1 }),
  1877. //列表元素列表
  1878. $listItem: _({ dd: 1, dt: 1, li: 1 }),
  1879. //列表根元素列表
  1880. $list: _({ ul: 1, ol: 1, dl: 1 }),
  1881. //不能认为是空的元素
  1882. $isNotEmpty: _({
  1883. table: 1,
  1884. ul: 1,
  1885. ol: 1,
  1886. dl: 1,
  1887. iframe: 1,
  1888. area: 1,
  1889. base: 1,
  1890. col: 1,
  1891. hr: 1,
  1892. img: 1,
  1893. embed: 1,
  1894. input: 1,
  1895. textarea: 1,
  1896. link: 1,
  1897. meta: 1,
  1898. param: 1,
  1899. h1: 1,
  1900. h2: 1,
  1901. h3: 1,
  1902. h4: 1,
  1903. h5: 1,
  1904. h6: 1
  1905. }),
  1906. //如果没有子节点就可以删除的元素列表,像span,a
  1907. $removeEmpty: _({
  1908. a: 1,
  1909. abbr: 1,
  1910. acronym: 1,
  1911. address: 1,
  1912. b: 1,
  1913. bdo: 1,
  1914. big: 1,
  1915. cite: 1,
  1916. code: 1,
  1917. del: 1,
  1918. dfn: 1,
  1919. em: 1,
  1920. font: 1,
  1921. i: 1,
  1922. ins: 1,
  1923. label: 1,
  1924. kbd: 1,
  1925. q: 1,
  1926. s: 1,
  1927. samp: 1,
  1928. small: 1,
  1929. span: 1,
  1930. strike: 1,
  1931. strong: 1,
  1932. sub: 1,
  1933. sup: 1,
  1934. tt: 1,
  1935. u: 1,
  1936. var: 1
  1937. }),
  1938. $removeEmptyBlock: _({ p: 1, div: 1 }),
  1939. //在table元素里的元素列表
  1940. $tableContent: _({
  1941. caption: 1,
  1942. col: 1,
  1943. colgroup: 1,
  1944. tbody: 1,
  1945. td: 1,
  1946. tfoot: 1,
  1947. th: 1,
  1948. thead: 1,
  1949. tr: 1,
  1950. table: 1
  1951. }),
  1952. //不转换的标签
  1953. $notTransContent: _({ pre: 1, script: 1, style: 1, textarea: 1 }),
  1954. html: U,
  1955. head: T,
  1956. style: N,
  1957. script: N,
  1958. body: P,
  1959. base: {},
  1960. link: {},
  1961. meta: {},
  1962. title: N,
  1963. col: {},
  1964. tr: _({ td: 1, th: 1 }),
  1965. img: {},
  1966. embed: {},
  1967. colgroup: _({ thead: 1, col: 1, tbody: 1, tr: 1, tfoot: 1 }),
  1968. noscript: P,
  1969. td: P,
  1970. br: {},
  1971. th: P,
  1972. center: P,
  1973. kbd: L,
  1974. button: X(I, E),
  1975. basefont: {},
  1976. h5: L,
  1977. h4: L,
  1978. samp: L,
  1979. h6: L,
  1980. ol: Q,
  1981. h1: L,
  1982. h3: L,
  1983. option: N,
  1984. h2: L,
  1985. form: X(A, D, E, I),
  1986. select: _({ optgroup: 1, option: 1 }),
  1987. font: L,
  1988. ins: L,
  1989. menu: Q,
  1990. abbr: L,
  1991. label: L,
  1992. table: _({
  1993. thead: 1,
  1994. col: 1,
  1995. tbody: 1,
  1996. tr: 1,
  1997. colgroup: 1,
  1998. caption: 1,
  1999. tfoot: 1
  2000. }),
  2001. code: L,
  2002. tfoot: M,
  2003. cite: L,
  2004. li: P,
  2005. input: {},
  2006. iframe: P,
  2007. strong: L,
  2008. textarea: N,
  2009. noframes: P,
  2010. big: L,
  2011. small: L,
  2012. //trace:
  2013. span: _({
  2014. "#": 1,
  2015. br: 1,
  2016. b: 1,
  2017. strong: 1,
  2018. u: 1,
  2019. i: 1,
  2020. em: 1,
  2021. sub: 1,
  2022. sup: 1,
  2023. strike: 1,
  2024. span: 1
  2025. }),
  2026. hr: L,
  2027. dt: L,
  2028. sub: L,
  2029. optgroup: _({ option: 1 }),
  2030. param: {},
  2031. bdo: L,
  2032. var: L,
  2033. div: P,
  2034. object: O,
  2035. sup: L,
  2036. dd: P,
  2037. strike: L,
  2038. area: {},
  2039. dir: Q,
  2040. map: X(_({ area: 1, form: 1, p: 1 }), A, F, E),
  2041. applet: O,
  2042. dl: _({ dt: 1, dd: 1 }),
  2043. del: L,
  2044. isindex: {},
  2045. fieldset: X(_({ legend: 1 }), K),
  2046. thead: M,
  2047. ul: Q,
  2048. acronym: L,
  2049. b: L,
  2050. a: X(_({ a: 1 }), J),
  2051. blockquote: X(_({ td: 1, tr: 1, tbody: 1, li: 1 }), P),
  2052. caption: L,
  2053. i: L,
  2054. u: L,
  2055. tbody: M,
  2056. s: L,
  2057. address: X(D, I),
  2058. tt: L,
  2059. legend: L,
  2060. q: L,
  2061. pre: X(G, C),
  2062. p: X(_({ a: 1 }), L),
  2063. em: L,
  2064. dfn: L,
  2065. mark: L
  2066. });
  2067. })());
  2068. // core/domUtils.js
  2069. /**
  2070. * Dom操作工具包
  2071. * @file
  2072. * @module UE.dom.domUtils
  2073. * @since 1.2.6.1
  2074. */
  2075. /**
  2076. * Dom操作工具包
  2077. * @unfile
  2078. * @module UE.dom.domUtils
  2079. */
  2080. function getDomNode(node, start, ltr, startFromChild, fn, guard) {
  2081. var tmpNode = startFromChild && node[start],
  2082. parent;
  2083. !tmpNode && (tmpNode = node[ltr]);
  2084. while (!tmpNode && (parent = (parent || node).parentNode)) {
  2085. if (parent.tagName == "BODY" || (guard && !guard(parent))) {
  2086. return null;
  2087. }
  2088. tmpNode = parent[ltr];
  2089. }
  2090. if (tmpNode && fn && !fn(tmpNode)) {
  2091. return getDomNode(tmpNode, start, ltr, false, fn);
  2092. }
  2093. return tmpNode;
  2094. }
  2095. var attrFix = ie && browser.version < 9
  2096. ? {
  2097. tabindex: "tabIndex",
  2098. readonly: "readOnly",
  2099. for: "htmlFor",
  2100. class: "className",
  2101. maxlength: "maxLength",
  2102. cellspacing: "cellSpacing",
  2103. cellpadding: "cellPadding",
  2104. rowspan: "rowSpan",
  2105. colspan: "colSpan",
  2106. usemap: "useMap",
  2107. frameborder: "frameBorder"
  2108. }
  2109. : {
  2110. tabindex: "tabIndex",
  2111. readonly: "readOnly"
  2112. },
  2113. styleBlock = utils.listToMap([
  2114. "-webkit-box",
  2115. "-moz-box",
  2116. "block",
  2117. "list-item",
  2118. "table",
  2119. "table-row-group",
  2120. "table-header-group",
  2121. "table-footer-group",
  2122. "table-row",
  2123. "table-column-group",
  2124. "table-column",
  2125. "table-cell",
  2126. "table-caption"
  2127. ]);
  2128. var domUtils = (dom.domUtils = {
  2129. //节点常量
  2130. NODE_ELEMENT: 1,
  2131. NODE_DOCUMENT: 9,
  2132. NODE_TEXT: 3,
  2133. NODE_COMMENT: 8,
  2134. NODE_DOCUMENT_FRAGMENT: 11,
  2135. //位置关系
  2136. POSITION_IDENTICAL: 0,
  2137. POSITION_DISCONNECTED: 1,
  2138. POSITION_FOLLOWING: 2,
  2139. POSITION_PRECEDING: 4,
  2140. POSITION_IS_CONTAINED: 8,
  2141. POSITION_CONTAINS: 16,
  2142. //ie6使用其他的会有一段空白出现
  2143. fillChar: ie && browser.version == "6" ? "\ufeff" : "\u200B",
  2144. //-------------------------Node部分--------------------------------
  2145. keys: {
  2146. /*Backspace*/ 8: 1,
  2147. /*Delete*/ 46: 1,
  2148. /*Shift*/ 16: 1,
  2149. /*Ctrl*/ 17: 1,
  2150. /*Alt*/ 18: 1,
  2151. 37: 1,
  2152. 38: 1,
  2153. 39: 1,
  2154. 40: 1,
  2155. 13: 1 /*enter*/
  2156. },
  2157. /**
  2158. * 获取节点A相对于节点B的位置关系
  2159. * @method getPosition
  2160. * @param { Node } nodeA 需要查询位置关系的节点A
  2161. * @param { Node } nodeB 需要查询位置关系的节点B
  2162. * @return { Number } 节点A与节点B的关系
  2163. * @example
  2164. * ```javascript
  2165. * //output: 20
  2166. * var position = UE.dom.domUtils.getPosition( document.documentElement, document.body );
  2167. *
  2168. * switch ( position ) {
  2169. *
  2170. * //0
  2171. * case UE.dom.domUtils.POSITION_IDENTICAL:
  2172. * console.log('元素相同');
  2173. * break;
  2174. * //1
  2175. * case UE.dom.domUtils.POSITION_DISCONNECTED:
  2176. * console.log('两个节点在不同的文档中');
  2177. * break;
  2178. * //2
  2179. * case UE.dom.domUtils.POSITION_FOLLOWING:
  2180. * console.log('节点A在节点B之后');
  2181. * break;
  2182. * //4
  2183. * case UE.dom.domUtils.POSITION_PRECEDING;
  2184. * console.log('节点A在节点B之前');
  2185. * break;
  2186. * //8
  2187. * case UE.dom.domUtils.POSITION_IS_CONTAINED:
  2188. * console.log('节点A被节点B包含');
  2189. * break;
  2190. * case 10:
  2191. * console.log('节点A被节点B包含且节点A在节点B之后');
  2192. * break;
  2193. * //16
  2194. * case UE.dom.domUtils.POSITION_CONTAINS:
  2195. * console.log('节点A包含节点B');
  2196. * break;
  2197. * case 20:
  2198. * console.log('节点A包含节点B且节点A在节点B之前');
  2199. * break;
  2200. *
  2201. * }
  2202. * ```
  2203. */
  2204. getPosition: function(nodeA, nodeB) {
  2205. // 如果两个节点是同一个节点
  2206. if (nodeA === nodeB) {
  2207. // domUtils.POSITION_IDENTICAL
  2208. return 0;
  2209. }
  2210. var node,
  2211. parentsA = [nodeA],
  2212. parentsB = [nodeB];
  2213. node = nodeA;
  2214. while ((node = node.parentNode)) {
  2215. // 如果nodeB是nodeA的祖先节点
  2216. if (node === nodeB) {
  2217. // domUtils.POSITION_IS_CONTAINED + domUtils.POSITION_FOLLOWING
  2218. return 10;
  2219. }
  2220. parentsA.push(node);
  2221. }
  2222. node = nodeB;
  2223. while ((node = node.parentNode)) {
  2224. // 如果nodeA是nodeB的祖先节点
  2225. if (node === nodeA) {
  2226. // domUtils.POSITION_CONTAINS + domUtils.POSITION_PRECEDING
  2227. return 20;
  2228. }
  2229. parentsB.push(node);
  2230. }
  2231. parentsA.reverse();
  2232. parentsB.reverse();
  2233. if (parentsA[0] !== parentsB[0]) {
  2234. // domUtils.POSITION_DISCONNECTED
  2235. return 1;
  2236. }
  2237. var i = -1;
  2238. while ((i++, parentsA[i] === parentsB[i])) {}
  2239. nodeA = parentsA[i];
  2240. nodeB = parentsB[i];
  2241. while ((nodeA = nodeA.nextSibling)) {
  2242. if (nodeA === nodeB) {
  2243. // domUtils.POSITION_PRECEDING
  2244. return 4;
  2245. }
  2246. }
  2247. // domUtils.POSITION_FOLLOWING
  2248. return 2;
  2249. },
  2250. /**
  2251. * 检测节点node在父节点中的索引位置
  2252. * @method getNodeIndex
  2253. * @param { Node } node 需要检测的节点对象
  2254. * @return { Number } 该节点在父节点中的位置
  2255. * @see UE.dom.domUtils.getNodeIndex(Node,Boolean)
  2256. */
  2257. /**
  2258. * 检测节点node在父节点中的索引位置, 根据给定的mergeTextNode参数决定是否要合并多个连续的文本节点为一个节点
  2259. * @method getNodeIndex
  2260. * @param { Node } node 需要检测的节点对象
  2261. * @param { Boolean } mergeTextNode 是否合并多个连续的文本节点为一个节点
  2262. * @return { Number } 该节点在父节点中的位置
  2263. * @example
  2264. * ```javascript
  2265. *
  2266. * var node = document.createElement("div");
  2267. *
  2268. * node.appendChild( document.createTextNode( "hello" ) );
  2269. * node.appendChild( document.createTextNode( "world" ) );
  2270. * node.appendChild( node = document.createElement( "div" ) );
  2271. *
  2272. * //output: 2
  2273. * console.log( UE.dom.domUtils.getNodeIndex( node ) );
  2274. *
  2275. * //output: 1
  2276. * console.log( UE.dom.domUtils.getNodeIndex( node, true ) );
  2277. *
  2278. * ```
  2279. */
  2280. getNodeIndex: function(node, ignoreTextNode) {
  2281. var preNode = node,
  2282. i = 0;
  2283. while ((preNode = preNode.previousSibling)) {
  2284. if (ignoreTextNode && preNode.nodeType == 3) {
  2285. if (preNode.nodeType != preNode.nextSibling.nodeType) {
  2286. i++;
  2287. }
  2288. continue;
  2289. }
  2290. i++;
  2291. }
  2292. return i;
  2293. },
  2294. /**
  2295. * 检测节点node是否在给定的document对象上
  2296. * @method inDoc
  2297. * @param { Node } node 需要检测的节点对象
  2298. * @param { DomDocument } doc 需要检测的document对象
  2299. * @return { Boolean } 该节点node是否在给定的document的dom树上
  2300. * @example
  2301. * ```javascript
  2302. *
  2303. * var node = document.createElement("div");
  2304. *
  2305. * //output: false
  2306. * console.log( UE.do.domUtils.inDoc( node, document ) );
  2307. *
  2308. * document.body.appendChild( node );
  2309. *
  2310. * //output: true
  2311. * console.log( UE.do.domUtils.inDoc( node, document ) );
  2312. *
  2313. * ```
  2314. */
  2315. inDoc: function(node, doc) {
  2316. return domUtils.getPosition(node, doc) == 10;
  2317. },
  2318. /**
  2319. * 根据给定的过滤规则filterFn, 查找符合该过滤规则的node节点的第一个祖先节点,
  2320. * 查找的起点是给定node节点的父节点。
  2321. * @method findParent
  2322. * @param { Node } node 需要查找的节点
  2323. * @param { Function } filterFn 自定义的过滤方法。
  2324. * @warning 查找的终点是到body节点为止
  2325. * @remind 自定义的过滤方法filterFn接受一个Node对象作为参数, 该对象代表当前执行检测的祖先节点。 如果该
  2326. * 节点满足过滤条件, 则要求返回true, 这时将直接返回该节点作为findParent()的结果, 否则, 请返回false。
  2327. * @return { Node | Null } 如果找到符合过滤条件的节点, 就返回该节点, 否则返回NULL
  2328. * @example
  2329. * ```javascript
  2330. * var filterNode = UE.dom.domUtils.findParent( document.body.firstChild, function ( node ) {
  2331. *
  2332. * //由于查找的终点是body节点, 所以永远也不会匹配当前过滤器的条件, 即这里永远会返回false
  2333. * return node.tagName === "HTML";
  2334. *
  2335. * } );
  2336. *
  2337. * //output: true
  2338. * console.log( filterNode === null );
  2339. * ```
  2340. */
  2341. /**
  2342. * 根据给定的过滤规则filterFn, 查找符合该过滤规则的node节点的第一个祖先节点,
  2343. * 如果includeSelf的值为true,则查找的起点是给定的节点node, 否则, 起点是node的父节点
  2344. * @method findParent
  2345. * @param { Node } node 需要查找的节点
  2346. * @param { Function } filterFn 自定义的过滤方法。
  2347. * @param { Boolean } includeSelf 查找过程是否包含自身
  2348. * @warning 查找的终点是到body节点为止
  2349. * @remind 自定义的过滤方法filterFn接受一个Node对象作为参数, 该对象代表当前执行检测的祖先节点。 如果该
  2350. * 节点满足过滤条件, 则要求返回true, 这时将直接返回该节点作为findParent()的结果, 否则, 请返回false。
  2351. * @remind 如果includeSelf为true, 则过滤器第一次执行时的参数会是节点本身。
  2352. * 反之, 过滤器第一次执行时的参数将是该节点的父节点。
  2353. * @return { Node | Null } 如果找到符合过滤条件的节点, 就返回该节点, 否则返回NULL
  2354. * @example
  2355. * ```html
  2356. * <body>
  2357. *
  2358. * <div id="test">
  2359. * </div>
  2360. *
  2361. * <script type="text/javascript">
  2362. *
  2363. * //output: DIV, BODY
  2364. * var filterNode = UE.dom.domUtils.findParent( document.getElementById( "test" ), function ( node ) {
  2365. *
  2366. * console.log( node.tagName );
  2367. * return false;
  2368. *
  2369. * }, true );
  2370. *
  2371. * </script>
  2372. * </body>
  2373. * ```
  2374. */
  2375. findParent: function(node, filterFn, includeSelf) {
  2376. if (node && !domUtils.isBody(node)) {
  2377. node = includeSelf ? node : node.parentNode;
  2378. while (node) {
  2379. if (!filterFn || filterFn(node) || domUtils.isBody(node)) {
  2380. return filterFn && !filterFn(node) && domUtils.isBody(node)
  2381. ? null
  2382. : node;
  2383. }
  2384. node = node.parentNode;
  2385. }
  2386. }
  2387. return null;
  2388. },
  2389. /**
  2390. * 查找node的节点名为tagName的第一个祖先节点, 查找的起点是node节点的父节点。
  2391. * @method findParentByTagName
  2392. * @param { Node } node 需要查找的节点对象
  2393. * @param { Array } tagNames 需要查找的父节点的名称数组
  2394. * @warning 查找的终点是到body节点为止
  2395. * @return { Node | NULL } 如果找到符合条件的节点, 则返回该节点, 否则返回NULL
  2396. * @example
  2397. * ```javascript
  2398. * var node = UE.dom.domUtils.findParentByTagName( document.getElementsByTagName("div")[0], [ "BODY" ] );
  2399. * //output: BODY
  2400. * console.log( node.tagName );
  2401. * ```
  2402. */
  2403. /**
  2404. * 查找node的节点名为tagName的祖先节点, 如果includeSelf的值为true,则查找的起点是给定的节点node,
  2405. * 否则, 起点是node的父节点。
  2406. * @method findParentByTagName
  2407. * @param { Node } node 需要查找的节点对象
  2408. * @param { Array } tagNames 需要查找的父节点的名称数组
  2409. * @param { Boolean } includeSelf 查找过程是否包含node节点自身
  2410. * @warning 查找的终点是到body节点为止
  2411. * @return { Node | NULL } 如果找到符合条件的节点, 则返回该节点, 否则返回NULL
  2412. * @example
  2413. * ```javascript
  2414. * var queryTarget = document.getElementsByTagName("div")[0];
  2415. * var node = UE.dom.domUtils.findParentByTagName( queryTarget, [ "DIV" ], true );
  2416. * //output: true
  2417. * console.log( queryTarget === node );
  2418. * ```
  2419. */
  2420. findParentByTagName: function(node, tagNames, includeSelf, excludeFn) {
  2421. tagNames = utils.listToMap(utils.isArray(tagNames) ? tagNames : [tagNames]);
  2422. return domUtils.findParent(
  2423. node,
  2424. function(node) {
  2425. return tagNames[node.tagName] && !(excludeFn && excludeFn(node));
  2426. },
  2427. includeSelf
  2428. );
  2429. },
  2430. /**
  2431. * 查找节点node的祖先节点集合, 查找的起点是给定节点的父节点,结果集中不包含给定的节点。
  2432. * @method findParents
  2433. * @param { Node } node 需要查找的节点对象
  2434. * @return { Array } 给定节点的祖先节点数组
  2435. * @grammar UE.dom.domUtils.findParents(node) => Array //返回一个祖先节点数组集合,不包含自身
  2436. * @grammar UE.dom.domUtils.findParents(node,includeSelf) => Array //返回一个祖先节点数组集合,includeSelf指定是否包含自身
  2437. * @grammar UE.dom.domUtils.findParents(node,includeSelf,filterFn) => Array //返回一个祖先节点数组集合,filterFn指定过滤条件,返回true的node将被选取
  2438. * @grammar UE.dom.domUtils.findParents(node,includeSelf,filterFn,closerFirst) => Array //返回一个祖先节点数组集合,closerFirst为true的话,node的直接父亲节点是数组的第0个
  2439. */
  2440. /**
  2441. * 查找节点node的祖先节点集合, 如果includeSelf的值为true,
  2442. * 则返回的结果集中允许出现当前给定的节点, 否则, 该节点不会出现在其结果集中。
  2443. * @method findParents
  2444. * @param { Node } node 需要查找的节点对象
  2445. * @param { Boolean } includeSelf 查找的结果中是否允许包含当前查找的节点对象
  2446. * @return { Array } 给定节点的祖先节点数组
  2447. */
  2448. findParents: function(node, includeSelf, filterFn, closerFirst) {
  2449. var parents = includeSelf && ((filterFn && filterFn(node)) || !filterFn)
  2450. ? [node]
  2451. : [];
  2452. while ((node = domUtils.findParent(node, filterFn))) {
  2453. parents.push(node);
  2454. }
  2455. return closerFirst ? parents : parents.reverse();
  2456. },
  2457. /**
  2458. * 在节点node后面插入新节点newNode
  2459. * @method insertAfter
  2460. * @param { Node } node 目标节点
  2461. * @param { Node } newNode 新插入的节点, 该节点将置于目标节点之后
  2462. * @return { Node } 新插入的节点
  2463. */
  2464. insertAfter: function(node, newNode) {
  2465. return node.nextSibling
  2466. ? node.parentNode.insertBefore(newNode, node.nextSibling)
  2467. : node.parentNode.appendChild(newNode);
  2468. },
  2469. /**
  2470. * 删除节点node及其下属的所有节点
  2471. * @method remove
  2472. * @param { Node } node 需要删除的节点对象
  2473. * @return { Node } 返回刚删除的节点对象
  2474. * @example
  2475. * ```html
  2476. * <div id="test">
  2477. * <div id="child">你好</div>
  2478. * </div>
  2479. * <script>
  2480. * UE.dom.domUtils.remove( document.body, false );
  2481. * //output: false
  2482. * console.log( document.getElementById( "child" ) !== null );
  2483. * </script>
  2484. * ```
  2485. */
  2486. /**
  2487. * 删除节点node,并根据keepChildren的值决定是否保留子节点
  2488. * @method remove
  2489. * @param { Node } node 需要删除的节点对象
  2490. * @param { Boolean } keepChildren 是否需要保留子节点
  2491. * @return { Node } 返回刚删除的节点对象
  2492. * @example
  2493. * ```html
  2494. * <div id="test">
  2495. * <div id="child">你好</div>
  2496. * </div>
  2497. * <script>
  2498. * UE.dom.domUtils.remove( document.body, true );
  2499. * //output: true
  2500. * console.log( document.getElementById( "child" ) !== null );
  2501. * </script>
  2502. * ```
  2503. */
  2504. remove: function(node, keepChildren) {
  2505. var parent = node.parentNode,
  2506. child;
  2507. if (parent) {
  2508. if (keepChildren && node.hasChildNodes()) {
  2509. while ((child = node.firstChild)) {
  2510. parent.insertBefore(child, node);
  2511. }
  2512. }
  2513. parent.removeChild(node);
  2514. }
  2515. return node;
  2516. },
  2517. /**
  2518. * 取得node节点的下一个兄弟节点, 如果该节点其后没有兄弟节点, 则递归查找其父节点之后的第一个兄弟节点,
  2519. * 直到找到满足条件的节点或者递归到BODY节点之后才会结束。
  2520. * @method getNextDomNode
  2521. * @param { Node } node 需要获取其后的兄弟节点的节点对象
  2522. * @return { Node | NULL } 如果找满足条件的节点, 则返回该节点, 否则返回NULL
  2523. * @example
  2524. * ```html
  2525. * <body>
  2526. * <div id="test">
  2527. * <span></span>
  2528. * </div>
  2529. * <i>xxx</i>
  2530. * </body>
  2531. * <script>
  2532. *
  2533. * //output: i节点
  2534. * console.log( UE.dom.domUtils.getNextDomNode( document.getElementById( "test" ) ) );
  2535. *
  2536. * </script>
  2537. * ```
  2538. * @example
  2539. * ```html
  2540. * <body>
  2541. * <div>
  2542. * <span></span>
  2543. * <i id="test">xxx</i>
  2544. * </div>
  2545. * <b>xxx</b>
  2546. * </body>
  2547. * <script>
  2548. *
  2549. * //由于id为test的i节点之后没有兄弟节点, 则查找其父节点(div)后面的兄弟节点
  2550. * //output: b节点
  2551. * console.log( UE.dom.domUtils.getNextDomNode( document.getElementById( "test" ) ) );
  2552. *
  2553. * </script>
  2554. * ```
  2555. */
  2556. /**
  2557. * 取得node节点的下一个兄弟节点, 如果startFromChild的值为ture,则先获取其子节点,
  2558. * 如果有子节点则直接返回第一个子节点;如果没有子节点或者startFromChild的值为false,
  2559. * 则执行<a href="#UE.dom.domUtils.getNextDomNode(Node)">getNextDomNode(Node node)</a>的查找过程。
  2560. * @method getNextDomNode
  2561. * @param { Node } node 需要获取其后的兄弟节点的节点对象
  2562. * @param { Boolean } startFromChild 查找过程是否从其子节点开始
  2563. * @return { Node | NULL } 如果找满足条件的节点, 则返回该节点, 否则返回NULL
  2564. * @see UE.dom.domUtils.getNextDomNode(Node)
  2565. */
  2566. getNextDomNode: function(node, startFromChild, filterFn, guard) {
  2567. return getDomNode(
  2568. node,
  2569. "firstChild",
  2570. "nextSibling",
  2571. startFromChild,
  2572. filterFn,
  2573. guard
  2574. );
  2575. },
  2576. getPreDomNode: function(node, startFromChild, filterFn, guard) {
  2577. return getDomNode(
  2578. node,
  2579. "lastChild",
  2580. "previousSibling",
  2581. startFromChild,
  2582. filterFn,
  2583. guard
  2584. );
  2585. },
  2586. /**
  2587. * 检测节点node是否属是UEditor定义的bookmark节点
  2588. * @method isBookmarkNode
  2589. * @private
  2590. * @param { Node } node 需要检测的节点对象
  2591. * @return { Boolean } 是否是bookmark节点
  2592. * @example
  2593. * ```html
  2594. * <span id="_baidu_bookmark_1"></span>
  2595. * <script>
  2596. * var bookmarkNode = document.getElementById("_baidu_bookmark_1");
  2597. * //output: true
  2598. * console.log( UE.dom.domUtils.isBookmarkNode( bookmarkNode ) );
  2599. * </script>
  2600. * ```
  2601. */
  2602. isBookmarkNode: function(node) {
  2603. return node.nodeType == 1 && node.id && /^_baidu_bookmark_/i.test(node.id);
  2604. },
  2605. /**
  2606. * 获取节点node所属的window对象
  2607. * @method getWindow
  2608. * @param { Node } node 节点对象
  2609. * @return { Window } 当前节点所属的window对象
  2610. * @example
  2611. * ```javascript
  2612. * //output: true
  2613. * console.log( UE.dom.domUtils.getWindow( document.body ) === window );
  2614. * ```
  2615. */
  2616. getWindow: function(node) {
  2617. var doc = node.ownerDocument || node;
  2618. return doc.defaultView || doc.parentWindow;
  2619. },
  2620. /**
  2621. * 获取离nodeA与nodeB最近的公共的祖先节点
  2622. * @method getCommonAncestor
  2623. * @param { Node } nodeA 第一个节点
  2624. * @param { Node } nodeB 第二个节点
  2625. * @remind 如果给定的两个节点是同一个节点, 将直接返回该节点。
  2626. * @return { Node | NULL } 如果未找到公共节点, 返回NULL, 否则返回最近的公共祖先节点。
  2627. * @example
  2628. * ```javascript
  2629. * var commonAncestor = UE.dom.domUtils.getCommonAncestor( document.body, document.body.firstChild );
  2630. * //output: true
  2631. * console.log( commonAncestor.tagName.toLowerCase() === 'body' );
  2632. * ```
  2633. */
  2634. getCommonAncestor: function(nodeA, nodeB) {
  2635. if (nodeA === nodeB) return nodeA;
  2636. var parentsA = [nodeA],
  2637. parentsB = [nodeB],
  2638. parent = nodeA,
  2639. i = -1;
  2640. while ((parent = parent.parentNode)) {
  2641. if (parent === nodeB) {
  2642. return parent;
  2643. }
  2644. parentsA.push(parent);
  2645. }
  2646. parent = nodeB;
  2647. while ((parent = parent.parentNode)) {
  2648. if (parent === nodeA) return parent;
  2649. parentsB.push(parent);
  2650. }
  2651. parentsA.reverse();
  2652. parentsB.reverse();
  2653. while ((i++, parentsA[i] === parentsB[i])) {}
  2654. return i == 0 ? null : parentsA[i - 1];
  2655. },
  2656. /**
  2657. * 清除node节点左右连续为空的兄弟inline节点
  2658. * @method clearEmptySibling
  2659. * @param { Node } node 执行的节点对象, 如果该节点的左右连续的兄弟节点是空的inline节点,
  2660. * 则这些兄弟节点将被删除
  2661. * @grammar UE.dom.domUtils.clearEmptySibling(node,ignoreNext) //ignoreNext指定是否忽略右边空节点
  2662. * @grammar UE.dom.domUtils.clearEmptySibling(node,ignoreNext,ignorePre) //ignorePre指定是否忽略左边空节点
  2663. * @example
  2664. * ```html
  2665. * <body>
  2666. * <div></div>
  2667. * <span id="test"></span>
  2668. * <i></i>
  2669. * <b></b>
  2670. * <em>xxx</em>
  2671. * <span></span>
  2672. * </body>
  2673. * <script>
  2674. *
  2675. * UE.dom.domUtils.clearEmptySibling( document.getElementById( "test" ) );
  2676. *
  2677. * //output: <div></div><span id="test"></span><em>xxx</em><span></span>
  2678. * console.log( document.body.innerHTML );
  2679. *
  2680. * </script>
  2681. * ```
  2682. */
  2683. /**
  2684. * 清除node节点左右连续为空的兄弟inline节点, 如果ignoreNext的值为true,
  2685. * 则忽略对右边兄弟节点的操作。
  2686. * @method clearEmptySibling
  2687. * @param { Node } node 执行的节点对象, 如果该节点的左右连续的兄弟节点是空的inline节点,
  2688. * @param { Boolean } ignoreNext 是否忽略忽略对右边的兄弟节点的操作
  2689. * 则这些兄弟节点将被删除
  2690. * @see UE.dom.domUtils.clearEmptySibling(Node)
  2691. */
  2692. /**
  2693. * 清除node节点左右连续为空的兄弟inline节点, 如果ignoreNext的值为true,
  2694. * 则忽略对右边兄弟节点的操作, 如果ignorePre的值为true,则忽略对左边兄弟节点的操作。
  2695. * @method clearEmptySibling
  2696. * @param { Node } node 执行的节点对象, 如果该节点的左右连续的兄弟节点是空的inline节点,
  2697. * @param { Boolean } ignoreNext 是否忽略忽略对右边的兄弟节点的操作
  2698. * @param { Boolean } ignorePre 是否忽略忽略对左边的兄弟节点的操作
  2699. * 则这些兄弟节点将被删除
  2700. * @see UE.dom.domUtils.clearEmptySibling(Node)
  2701. */
  2702. clearEmptySibling: function(node, ignoreNext, ignorePre) {
  2703. function clear(next, dir) {
  2704. var tmpNode;
  2705. while (
  2706. next &&
  2707. !domUtils.isBookmarkNode(next) &&
  2708. (domUtils.isEmptyInlineElement(next) ||
  2709. //这里不能把空格算进来会吧空格干掉,出现文字间的空格丢掉了
  2710. !new RegExp("[^\t\n\r" + domUtils.fillChar + "]").test(
  2711. next.nodeValue
  2712. ))
  2713. ) {
  2714. tmpNode = next[dir];
  2715. domUtils.remove(next);
  2716. next = tmpNode;
  2717. }
  2718. }
  2719. !ignoreNext && clear(node.nextSibling, "nextSibling");
  2720. !ignorePre && clear(node.previousSibling, "previousSibling");
  2721. },
  2722. /**
  2723. * 将一个文本节点textNode拆分成两个文本节点,offset指定拆分位置
  2724. * @method split
  2725. * @param { Node } textNode 需要拆分的文本节点对象
  2726. * @param { int } offset 需要拆分的位置, 位置计算从0开始
  2727. * @return { Node } 拆分后形成的新节点
  2728. * @example
  2729. * ```html
  2730. * <div id="test">abcdef</div>
  2731. * <script>
  2732. * var newNode = UE.dom.domUtils.split( document.getElementById( "test" ).firstChild, 3 );
  2733. * //output: def
  2734. * console.log( newNode.nodeValue );
  2735. * </script>
  2736. * ```
  2737. */
  2738. split: function(node, offset) {
  2739. var doc = node.ownerDocument;
  2740. if (browser.ie && offset == node.nodeValue.length) {
  2741. var next = doc.createTextNode("");
  2742. return domUtils.insertAfter(node, next);
  2743. }
  2744. var retval = node.splitText(offset);
  2745. //ie8下splitText不会跟新childNodes,我们手动触发他的更新
  2746. if (browser.ie8) {
  2747. var tmpNode = doc.createTextNode("");
  2748. domUtils.insertAfter(retval, tmpNode);
  2749. domUtils.remove(tmpNode);
  2750. }
  2751. return retval;
  2752. },
  2753. /**
  2754. * 检测文本节点textNode是否为空节点(包括空格、换行、占位符等字符)
  2755. * @method isWhitespace
  2756. * @param { Node } node 需要检测的节点对象
  2757. * @return { Boolean } 检测的节点是否为空
  2758. * @example
  2759. * ```html
  2760. * <div id="test">
  2761. *
  2762. * </div>
  2763. * <script>
  2764. * //output: true
  2765. * console.log( UE.dom.domUtils.isWhitespace( document.getElementById("test").firstChild ) );
  2766. * </script>
  2767. * ```
  2768. */
  2769. isWhitespace: function(node) {
  2770. return !new RegExp("[^ \t\n\r" + domUtils.fillChar + "]").test(
  2771. node.nodeValue
  2772. );
  2773. },
  2774. /**
  2775. * 获取元素element相对于viewport的位置坐标
  2776. * @method getXY
  2777. * @param { Node } element 需要计算位置的节点对象
  2778. * @return { Object } 返回形如{x:left,y:top}的一个key-value映射对象, 其中键x代表水平偏移距离,
  2779. * y代表垂直偏移距离。
  2780. *
  2781. * @example
  2782. * ```javascript
  2783. * var location = UE.dom.domUtils.getXY( document.getElementById("test") );
  2784. * //output: test的坐标为: 12, 24
  2785. * console.log( 'test的坐标为: ', location.x, ',', location.y );
  2786. * ```
  2787. */
  2788. getXY: function(element) {
  2789. var x = 0,
  2790. y = 0;
  2791. while (element.offsetParent) {
  2792. y += element.offsetTop;
  2793. x += element.offsetLeft;
  2794. element = element.offsetParent;
  2795. }
  2796. return { x: x, y: y };
  2797. },
  2798. /**
  2799. * 为元素element绑定原生DOM事件,type为事件类型,handler为处理函数
  2800. * @method on
  2801. * @param { Node } element 需要绑定事件的节点对象
  2802. * @param { String } type 绑定的事件类型
  2803. * @param { Function } handler 事件处理器
  2804. * @example
  2805. * ```javascript
  2806. * UE.dom.domUtils.on(document.body,"click",function(e){
  2807. * //e为事件对象,this为被点击元素对戏那个
  2808. * });
  2809. * ```
  2810. */
  2811. /**
  2812. * 为元素element绑定原生DOM事件,type为事件类型,handler为处理函数
  2813. * @method on
  2814. * @param { Node } element 需要绑定事件的节点对象
  2815. * @param { Array } type 绑定的事件类型数组
  2816. * @param { Function } handler 事件处理器
  2817. * @example
  2818. * ```javascript
  2819. * UE.dom.domUtils.on(document.body,["click","mousedown"],function(evt){
  2820. * //evt为事件对象,this为被点击元素对象
  2821. * });
  2822. * ```
  2823. */
  2824. on: function(element, type, handler) {
  2825. var types = utils.isArray(type) ? type : utils.trim(type).split(/\s+/),
  2826. k = types.length;
  2827. if (k)
  2828. while (k--) {
  2829. type = types[k];
  2830. if (element.addEventListener) {
  2831. element.addEventListener(type, handler, false);
  2832. } else {
  2833. if (!handler._d) {
  2834. handler._d = {
  2835. els: []
  2836. };
  2837. }
  2838. var key = type + handler.toString(),
  2839. index = utils.indexOf(handler._d.els, element);
  2840. if (!handler._d[key] || index == -1) {
  2841. if (index == -1) {
  2842. handler._d.els.push(element);
  2843. }
  2844. if (!handler._d[key]) {
  2845. handler._d[key] = function(evt) {
  2846. return handler.call(evt.srcElement, evt || window.event);
  2847. };
  2848. }
  2849. element.attachEvent("on" + type, handler._d[key]);
  2850. }
  2851. }
  2852. }
  2853. element = null;
  2854. },
  2855. /**
  2856. * 解除DOM事件绑定
  2857. * @method un
  2858. * @param { Node } element 需要解除事件绑定的节点对象
  2859. * @param { String } type 需要接触绑定的事件类型
  2860. * @param { Function } handler 对应的事件处理器
  2861. * @example
  2862. * ```javascript
  2863. * UE.dom.domUtils.un(document.body,"click",function(evt){
  2864. * //evt为事件对象,this为被点击元素对象
  2865. * });
  2866. * ```
  2867. */
  2868. /**
  2869. * 解除DOM事件绑定
  2870. * @method un
  2871. * @param { Node } element 需要解除事件绑定的节点对象
  2872. * @param { Array } type 需要接触绑定的事件类型数组
  2873. * @param { Function } handler 对应的事件处理器
  2874. * @example
  2875. * ```javascript
  2876. * UE.dom.domUtils.un(document.body, ["click","mousedown"],function(evt){
  2877. * //evt为事件对象,this为被点击元素对象
  2878. * });
  2879. * ```
  2880. */
  2881. un: function(element, type, handler) {
  2882. var types = utils.isArray(type) ? type : utils.trim(type).split(/\s+/),
  2883. k = types.length;
  2884. if (k)
  2885. while (k--) {
  2886. type = types[k];
  2887. if (element.removeEventListener) {
  2888. element.removeEventListener(type, handler, false);
  2889. } else {
  2890. var key = type + handler.toString();
  2891. try {
  2892. element.detachEvent(
  2893. "on" + type,
  2894. handler._d ? handler._d[key] : handler
  2895. );
  2896. } catch (e) {}
  2897. if (handler._d && handler._d[key]) {
  2898. var index = utils.indexOf(handler._d.els, element);
  2899. if (index != -1) {
  2900. handler._d.els.splice(index, 1);
  2901. }
  2902. handler._d.els.length == 0 && delete handler._d[key];
  2903. }
  2904. }
  2905. }
  2906. },
  2907. /**
  2908. * 比较节点nodeA与节点nodeB是否具有相同的标签名、属性名以及属性值
  2909. * @method isSameElement
  2910. * @param { Node } nodeA 需要比较的节点
  2911. * @param { Node } nodeB 需要比较的节点
  2912. * @return { Boolean } 两个节点是否具有相同的标签名、属性名以及属性值
  2913. * @example
  2914. * ```html
  2915. * <span style="font-size:12px">ssss</span>
  2916. * <span style="font-size:12px">bbbbb</span>
  2917. * <span style="font-size:13px">ssss</span>
  2918. * <span style="font-size:14px">bbbbb</span>
  2919. *
  2920. * <script>
  2921. *
  2922. * var nodes = document.getElementsByTagName( "span" );
  2923. *
  2924. * //output: true
  2925. * console.log( UE.dom.domUtils.isSameElement( nodes[0], nodes[1] ) );
  2926. *
  2927. * //output: false
  2928. * console.log( UE.dom.domUtils.isSameElement( nodes[2], nodes[3] ) );
  2929. *
  2930. * </script>
  2931. * ```
  2932. */
  2933. isSameElement: function(nodeA, nodeB) {
  2934. if (nodeA.tagName != nodeB.tagName) {
  2935. return false;
  2936. }
  2937. var thisAttrs = nodeA.attributes,
  2938. otherAttrs = nodeB.attributes;
  2939. if (!ie && thisAttrs.length != otherAttrs.length) {
  2940. return false;
  2941. }
  2942. var attrA,
  2943. attrB,
  2944. al = 0,
  2945. bl = 0;
  2946. for (var i = 0; (attrA = thisAttrs[i++]); ) {
  2947. if (attrA.nodeName == "style") {
  2948. if (attrA.specified) {
  2949. al++;
  2950. }
  2951. if (domUtils.isSameStyle(nodeA, nodeB)) {
  2952. continue;
  2953. } else {
  2954. return false;
  2955. }
  2956. }
  2957. if (ie) {
  2958. if (attrA.specified) {
  2959. al++;
  2960. attrB = otherAttrs.getNamedItem(attrA.nodeName);
  2961. } else {
  2962. continue;
  2963. }
  2964. } else {
  2965. attrB = nodeB.attributes[attrA.nodeName];
  2966. }
  2967. if (!attrB.specified || attrA.nodeValue != attrB.nodeValue) {
  2968. return false;
  2969. }
  2970. }
  2971. // 有可能attrB的属性包含了attrA的属性之外还有自己的属性
  2972. if (ie) {
  2973. for (i = 0; (attrB = otherAttrs[i++]); ) {
  2974. if (attrB.specified) {
  2975. bl++;
  2976. }
  2977. }
  2978. if (al != bl) {
  2979. return false;
  2980. }
  2981. }
  2982. return true;
  2983. },
  2984. /**
  2985. * 判断节点nodeA与节点nodeB的元素的style属性是否一致
  2986. * @method isSameStyle
  2987. * @param { Node } nodeA 需要比较的节点
  2988. * @param { Node } nodeB 需要比较的节点
  2989. * @return { Boolean } 两个节点是否具有相同的style属性值
  2990. * @example
  2991. * ```html
  2992. * <span style="font-size:12px">ssss</span>
  2993. * <span style="font-size:12px">bbbbb</span>
  2994. * <span style="font-size:13px">ssss</span>
  2995. * <span style="font-size:14px">bbbbb</span>
  2996. *
  2997. * <script>
  2998. *
  2999. * var nodes = document.getElementsByTagName( "span" );
  3000. *
  3001. * //output: true
  3002. * console.log( UE.dom.domUtils.isSameStyle( nodes[0], nodes[1] ) );
  3003. *
  3004. * //output: false
  3005. * console.log( UE.dom.domUtils.isSameStyle( nodes[2], nodes[3] ) );
  3006. *
  3007. * </script>
  3008. * ```
  3009. */
  3010. isSameStyle: function(nodeA, nodeB) {
  3011. var styleA = nodeA.style.cssText
  3012. .replace(/( ?; ?)/g, ";")
  3013. .replace(/( ?: ?)/g, ":"),
  3014. styleB = nodeB.style.cssText
  3015. .replace(/( ?; ?)/g, ";")
  3016. .replace(/( ?: ?)/g, ":");
  3017. if (browser.opera) {
  3018. styleA = nodeA.style;
  3019. styleB = nodeB.style;
  3020. if (styleA.length != styleB.length) return false;
  3021. for (var p in styleA) {
  3022. if (/^(\d+|csstext)$/i.test(p)) {
  3023. continue;
  3024. }
  3025. if (styleA[p] != styleB[p]) {
  3026. return false;
  3027. }
  3028. }
  3029. return true;
  3030. }
  3031. if (!styleA || !styleB) {
  3032. return styleA == styleB;
  3033. }
  3034. styleA = styleA.split(";");
  3035. styleB = styleB.split(";");
  3036. if (styleA.length != styleB.length) {
  3037. return false;
  3038. }
  3039. for (var i = 0, ci; (ci = styleA[i++]); ) {
  3040. if (utils.indexOf(styleB, ci) == -1) {
  3041. return false;
  3042. }
  3043. }
  3044. return true;
  3045. },
  3046. /**
  3047. * 检查节点node是否为block元素
  3048. * @method isBlockElm
  3049. * @param { Node } node 需要检测的节点对象
  3050. * @return { Boolean } 是否是block元素节点
  3051. * @warning 该方法的判断规则如下: 如果该元素原本是block元素, 则不论该元素当前的css样式是什么都会返回true;
  3052. * 否则,检测该元素的css样式, 如果该元素当前是block元素, 则返回true。 其余情况下都返回false。
  3053. * @example
  3054. * ```html
  3055. * <span id="test1" style="display: block"></span>
  3056. * <span id="test2"></span>
  3057. * <div id="test3" style="display: inline"></div>
  3058. *
  3059. * <script>
  3060. *
  3061. * //output: true
  3062. * console.log( UE.dom.domUtils.isBlockElm( document.getElementById("test1") ) );
  3063. *
  3064. * //output: false
  3065. * console.log( UE.dom.domUtils.isBlockElm( document.getElementById("test2") ) );
  3066. *
  3067. * //output: true
  3068. * console.log( UE.dom.domUtils.isBlockElm( document.getElementById("test3") ) );
  3069. *
  3070. * </script>
  3071. * ```
  3072. */
  3073. isBlockElm: function(node) {
  3074. return (
  3075. node.nodeType == 1 &&
  3076. (dtd.$block[node.tagName] ||
  3077. styleBlock[domUtils.getComputedStyle(node, "display")]) &&
  3078. !dtd.$nonChild[node.tagName]
  3079. );
  3080. },
  3081. /**
  3082. * 检测node节点是否为body节点
  3083. * @method isBody
  3084. * @param { Element } node 需要检测的dom元素
  3085. * @return { Boolean } 给定的元素是否是body元素
  3086. * @example
  3087. * ```javascript
  3088. * //output: true
  3089. * console.log( UE.dom.domUtils.isBody( document.body ) );
  3090. * ```
  3091. */
  3092. isBody: function(node) {
  3093. return node && node.nodeType == 1 && node.tagName.toLowerCase() == "body";
  3094. },
  3095. /**
  3096. * 以node节点为分界,将该节点的指定祖先节点parent拆分成两个独立的节点,
  3097. * 拆分形成的两个节点之间是node节点
  3098. * @method breakParent
  3099. * @param { Node } node 作为分界的节点对象
  3100. * @param { Node } parent 该节点必须是node节点的祖先节点, 且是block节点。
  3101. * @return { Node } 给定的node分界节点
  3102. * @example
  3103. * ```javascript
  3104. *
  3105. * var node = document.createElement("span"),
  3106. * wrapNode = document.createElement( "div" ),
  3107. * parent = document.createElement("p");
  3108. *
  3109. * parent.appendChild( node );
  3110. * wrapNode.appendChild( parent );
  3111. *
  3112. * //拆分前
  3113. * //output: <p><span></span></p>
  3114. * console.log( wrapNode.innerHTML );
  3115. *
  3116. *
  3117. * UE.dom.domUtils.breakParent( node, parent );
  3118. * //拆分后
  3119. * //output: <p></p><span></span><p></p>
  3120. * console.log( wrapNode.innerHTML );
  3121. *
  3122. * ```
  3123. */
  3124. breakParent: function(node, parent) {
  3125. var tmpNode,
  3126. parentClone = node,
  3127. clone = node,
  3128. leftNodes,
  3129. rightNodes;
  3130. do {
  3131. parentClone = parentClone.parentNode;
  3132. if (leftNodes) {
  3133. tmpNode = parentClone.cloneNode(false);
  3134. tmpNode.appendChild(leftNodes);
  3135. leftNodes = tmpNode;
  3136. tmpNode = parentClone.cloneNode(false);
  3137. tmpNode.appendChild(rightNodes);
  3138. rightNodes = tmpNode;
  3139. } else {
  3140. leftNodes = parentClone.cloneNode(false);
  3141. rightNodes = leftNodes.cloneNode(false);
  3142. }
  3143. while ((tmpNode = clone.previousSibling)) {
  3144. leftNodes.insertBefore(tmpNode, leftNodes.firstChild);
  3145. }
  3146. while ((tmpNode = clone.nextSibling)) {
  3147. rightNodes.appendChild(tmpNode);
  3148. }
  3149. clone = parentClone;
  3150. } while (parent !== parentClone);
  3151. tmpNode = parent.parentNode;
  3152. tmpNode.insertBefore(leftNodes, parent);
  3153. tmpNode.insertBefore(rightNodes, parent);
  3154. tmpNode.insertBefore(node, rightNodes);
  3155. domUtils.remove(parent);
  3156. return node;
  3157. },
  3158. /**
  3159. * 检查节点node是否是空inline节点
  3160. * @method isEmptyInlineElement
  3161. * @param { Node } node 需要检测的节点对象
  3162. * @return { Number } 如果给定的节点是空的inline节点, 则返回1, 否则返回0。
  3163. * @example
  3164. * ```html
  3165. * <b><i></i></b> => 1
  3166. * <b><i></i><u></u></b> => 1
  3167. * <b></b> => 1
  3168. * <b>xx<i></i></b> => 0
  3169. * ```
  3170. */
  3171. isEmptyInlineElement: function(node) {
  3172. if (node.nodeType != 1 || !dtd.$removeEmpty[node.tagName]) {
  3173. return 0;
  3174. }
  3175. node = node.firstChild;
  3176. while (node) {
  3177. //如果是创建的bookmark就跳过
  3178. if (domUtils.isBookmarkNode(node)) {
  3179. return 0;
  3180. }
  3181. if (
  3182. (node.nodeType == 1 && !domUtils.isEmptyInlineElement(node)) ||
  3183. (node.nodeType == 3 && !domUtils.isWhitespace(node))
  3184. ) {
  3185. return 0;
  3186. }
  3187. node = node.nextSibling;
  3188. }
  3189. return 1;
  3190. },
  3191. /**
  3192. * 删除node节点下首尾两端的空白文本子节点
  3193. * @method trimWhiteTextNode
  3194. * @param { Element } node 需要执行删除操作的元素对象
  3195. * @example
  3196. * ```javascript
  3197. * var node = document.createElement("div");
  3198. *
  3199. * node.appendChild( document.createTextNode( "" ) );
  3200. *
  3201. * node.appendChild( document.createElement("div") );
  3202. *
  3203. * node.appendChild( document.createTextNode( "" ) );
  3204. *
  3205. * //3
  3206. * console.log( node.childNodes.length );
  3207. *
  3208. * UE.dom.domUtils.trimWhiteTextNode( node );
  3209. *
  3210. * //1
  3211. * console.log( node.childNodes.length );
  3212. * ```
  3213. */
  3214. trimWhiteTextNode: function(node) {
  3215. function remove(dir) {
  3216. var child;
  3217. while (
  3218. (child = node[dir]) &&
  3219. child.nodeType == 3 &&
  3220. domUtils.isWhitespace(child)
  3221. ) {
  3222. node.removeChild(child);
  3223. }
  3224. }
  3225. remove("firstChild");
  3226. remove("lastChild");
  3227. },
  3228. /**
  3229. * 合并node节点下相同的子节点
  3230. * @name mergeChild
  3231. * @desc
  3232. * UE.dom.domUtils.mergeChild(node,tagName) //tagName要合并的子节点的标签
  3233. * @example
  3234. * <p><span style="font-size:12px;">xx<span style="font-size:12px;">aa</span>xx</span></p>
  3235. * ==> UE.dom.domUtils.mergeChild(node,'span')
  3236. * <p><span style="font-size:12px;">xxaaxx</span></p>
  3237. */
  3238. mergeChild: function(node, tagName, attrs) {
  3239. var list = domUtils.getElementsByTagName(node, node.tagName.toLowerCase());
  3240. for (var i = 0, ci; (ci = list[i++]); ) {
  3241. if (!ci.parentNode || domUtils.isBookmarkNode(ci)) {
  3242. continue;
  3243. }
  3244. //span单独处理
  3245. if (ci.tagName.toLowerCase() == "span") {
  3246. if (node === ci.parentNode) {
  3247. domUtils.trimWhiteTextNode(node);
  3248. if (node.childNodes.length == 1) {
  3249. node.style.cssText = ci.style.cssText + ";" + node.style.cssText;
  3250. domUtils.remove(ci, true);
  3251. continue;
  3252. }
  3253. }
  3254. ci.style.cssText = node.style.cssText + ";" + ci.style.cssText;
  3255. if (attrs) {
  3256. var style = attrs.style;
  3257. if (style) {
  3258. style = style.split(";");
  3259. for (var j = 0, s; (s = style[j++]); ) {
  3260. ci.style[utils.cssStyleToDomStyle(s.split(":")[0])] = s.split(
  3261. ":"
  3262. )[1];
  3263. }
  3264. }
  3265. }
  3266. if (domUtils.isSameStyle(ci, node)) {
  3267. domUtils.remove(ci, true);
  3268. }
  3269. continue;
  3270. }
  3271. if (domUtils.isSameElement(node, ci)) {
  3272. domUtils.remove(ci, true);
  3273. }
  3274. }
  3275. },
  3276. /**
  3277. * 原生方法getElementsByTagName的封装
  3278. * @method getElementsByTagName
  3279. * @param { Node } node 目标节点对象
  3280. * @param { String } tagName 需要查找的节点的tagName, 多个tagName以空格分割
  3281. * @return { Array } 符合条件的节点集合
  3282. */
  3283. getElementsByTagName: function(node, name, filter) {
  3284. if (filter && utils.isString(filter)) {
  3285. var className = filter;
  3286. filter = function(node) {
  3287. return domUtils.hasClass(node, className);
  3288. };
  3289. }
  3290. name = utils.trim(name).replace(/[ ]{2,}/g, " ").split(" ");
  3291. var arr = [];
  3292. for (var n = 0, ni; (ni = name[n++]); ) {
  3293. var list = node.getElementsByTagName(ni);
  3294. for (var i = 0, ci; (ci = list[i++]); ) {
  3295. if (!filter || filter(ci)) arr.push(ci);
  3296. }
  3297. }
  3298. return arr;
  3299. },
  3300. /**
  3301. * 将节点node提取到父节点上
  3302. * @method mergeToParent
  3303. * @param { Element } node 需要提取的元素对象
  3304. * @example
  3305. * ```html
  3306. * <div id="parent">
  3307. * <div id="sub">
  3308. * <span id="child"></span>
  3309. * </div>
  3310. * </div>
  3311. *
  3312. * <script>
  3313. *
  3314. * var child = document.getElementById( "child" );
  3315. *
  3316. * //output: sub
  3317. * console.log( child.parentNode.id );
  3318. *
  3319. * UE.dom.domUtils.mergeToParent( child );
  3320. *
  3321. * //output: parent
  3322. * console.log( child.parentNode.id );
  3323. *
  3324. * </script>
  3325. * ```
  3326. */
  3327. mergeToParent: function(node) {
  3328. var parent = node.parentNode;
  3329. while (parent && dtd.$removeEmpty[parent.tagName]) {
  3330. if (parent.tagName == node.tagName || parent.tagName == "A") {
  3331. //针对a标签单独处理
  3332. domUtils.trimWhiteTextNode(parent);
  3333. //span需要特殊处理 不处理这样的情况 <span stlye="color:#fff">xxx<span style="color:#ccc">xxx</span>xxx</span>
  3334. if (
  3335. (parent.tagName == "SPAN" && !domUtils.isSameStyle(parent, node)) ||
  3336. (parent.tagName == "A" && node.tagName == "SPAN")
  3337. ) {
  3338. if (parent.childNodes.length > 1 || parent !== node.parentNode) {
  3339. node.style.cssText =
  3340. parent.style.cssText + ";" + node.style.cssText;
  3341. parent = parent.parentNode;
  3342. continue;
  3343. } else {
  3344. parent.style.cssText += ";" + node.style.cssText;
  3345. //trace:952 a标签要保持下划线
  3346. if (parent.tagName == "A") {
  3347. parent.style.textDecoration = "underline";
  3348. }
  3349. }
  3350. }
  3351. if (parent.tagName != "A") {
  3352. parent === node.parentNode && domUtils.remove(node, true);
  3353. break;
  3354. }
  3355. }
  3356. parent = parent.parentNode;
  3357. }
  3358. },
  3359. /**
  3360. * 合并节点node的左右兄弟节点
  3361. * @method mergeSibling
  3362. * @param { Element } node 需要合并的目标节点
  3363. * @example
  3364. * ```html
  3365. * <b>xxxx</b><b id="test">ooo</b><b>xxxx</b>
  3366. *
  3367. * <script>
  3368. * var demoNode = document.getElementById("test");
  3369. * UE.dom.domUtils.mergeSibling( demoNode );
  3370. * //output: xxxxoooxxxx
  3371. * console.log( demoNode.innerHTML );
  3372. * </script>
  3373. * ```
  3374. */
  3375. /**
  3376. * 合并节点node的左右兄弟节点, 可以根据给定的条件选择是否忽略合并左节点。
  3377. * @method mergeSibling
  3378. * @param { Element } node 需要合并的目标节点
  3379. * @param { Boolean } ignorePre 是否忽略合并左节点
  3380. * @example
  3381. * ```html
  3382. * <b>xxxx</b><b id="test">ooo</b><b>xxxx</b>
  3383. *
  3384. * <script>
  3385. * var demoNode = document.getElementById("test");
  3386. * UE.dom.domUtils.mergeSibling( demoNode, true );
  3387. * //output: oooxxxx
  3388. * console.log( demoNode.innerHTML );
  3389. * </script>
  3390. * ```
  3391. */
  3392. /**
  3393. * 合并节点node的左右兄弟节点,可以根据给定的条件选择是否忽略合并左右节点。
  3394. * @method mergeSibling
  3395. * @param { Element } node 需要合并的目标节点
  3396. * @param { Boolean } ignorePre 是否忽略合并左节点
  3397. * @param { Boolean } ignoreNext 是否忽略合并右节点
  3398. * @remind 如果同时忽略左右节点, 则该操作什么也不会做
  3399. * @example
  3400. * ```html
  3401. * <b>xxxx</b><b id="test">ooo</b><b>xxxx</b>
  3402. *
  3403. * <script>
  3404. * var demoNode = document.getElementById("test");
  3405. * UE.dom.domUtils.mergeSibling( demoNode, false, true );
  3406. * //output: xxxxooo
  3407. * console.log( demoNode.innerHTML );
  3408. * </script>
  3409. * ```
  3410. */
  3411. mergeSibling: function(node, ignorePre, ignoreNext) {
  3412. function merge(rtl, start, node) {
  3413. var next;
  3414. if (
  3415. (next = node[rtl]) &&
  3416. !domUtils.isBookmarkNode(next) &&
  3417. next.nodeType == 1 &&
  3418. domUtils.isSameElement(node, next)
  3419. ) {
  3420. while (next.firstChild) {
  3421. if (start == "firstChild") {
  3422. node.insertBefore(next.lastChild, node.firstChild);
  3423. } else {
  3424. node.appendChild(next.firstChild);
  3425. }
  3426. }
  3427. domUtils.remove(next);
  3428. }
  3429. }
  3430. !ignorePre && merge("previousSibling", "firstChild", node);
  3431. !ignoreNext && merge("nextSibling", "lastChild", node);
  3432. },
  3433. /**
  3434. * 设置节点node及其子节点不会被选中
  3435. * @method unSelectable
  3436. * @param { Element } node 需要执行操作的dom元素
  3437. * @remind 执行该操作后的节点, 将不能被鼠标选中
  3438. * @example
  3439. * ```javascript
  3440. * UE.dom.domUtils.unSelectable( document.body );
  3441. * ```
  3442. */
  3443. unSelectable: (ie && browser.ie9below) || browser.opera
  3444. ? function(node) {
  3445. //for ie9
  3446. node.onselectstart = function() {
  3447. return false;
  3448. };
  3449. node.onclick = node.onkeyup = node.onkeydown = function() {
  3450. return false;
  3451. };
  3452. node.unselectable = "on";
  3453. node.setAttribute("unselectable", "on");
  3454. for (var i = 0, ci; (ci = node.all[i++]); ) {
  3455. switch (ci.tagName.toLowerCase()) {
  3456. case "iframe":
  3457. case "textarea":
  3458. case "input":
  3459. case "select":
  3460. break;
  3461. default:
  3462. ci.unselectable = "on";
  3463. node.setAttribute("unselectable", "on");
  3464. }
  3465. }
  3466. }
  3467. : function(node) {
  3468. node.style.MozUserSelect = node.style.webkitUserSelect = node.style.msUserSelect = node.style.KhtmlUserSelect =
  3469. "none";
  3470. },
  3471. /**
  3472. * 删除节点node上的指定属性名称的属性
  3473. * @method removeAttributes
  3474. * @param { Node } node 需要删除属性的节点对象
  3475. * @param { String } attrNames 可以是空格隔开的多个属性名称,该操作将会依次删除相应的属性
  3476. * @example
  3477. * ```html
  3478. * <div id="wrap">
  3479. * <span style="font-size:14px;" id="test" name="followMe">xxxxx</span>
  3480. * </div>
  3481. *
  3482. * <script>
  3483. *
  3484. * UE.dom.domUtils.removeAttributes( document.getElementById( "test" ), "id name" );
  3485. *
  3486. * //output: <span style="font-size:14px;">xxxxx</span>
  3487. * console.log( document.getElementById("wrap").innerHTML );
  3488. *
  3489. * </script>
  3490. * ```
  3491. */
  3492. /**
  3493. * 删除节点node上的指定属性名称的属性
  3494. * @method removeAttributes
  3495. * @param { Node } node 需要删除属性的节点对象
  3496. * @param { Array } attrNames 需要删除的属性名数组
  3497. * @example
  3498. * ```html
  3499. * <div id="wrap">
  3500. * <span style="font-size:14px;" id="test" name="followMe">xxxxx</span>
  3501. * </div>
  3502. *
  3503. * <script>
  3504. *
  3505. * UE.dom.domUtils.removeAttributes( document.getElementById( "test" ), ["id", "name"] );
  3506. *
  3507. * //output: <span style="font-size:14px;">xxxxx</span>
  3508. * console.log( document.getElementById("wrap").innerHTML );
  3509. *
  3510. * </script>
  3511. * ```
  3512. */
  3513. removeAttributes: function(node, attrNames) {
  3514. attrNames = utils.isArray(attrNames)
  3515. ? attrNames
  3516. : utils.trim(attrNames).replace(/[ ]{2,}/g, " ").split(" ");
  3517. for (var i = 0, ci; (ci = attrNames[i++]); ) {
  3518. ci = attrFix[ci] || ci;
  3519. switch (ci) {
  3520. case "className":
  3521. node[ci] = "";
  3522. break;
  3523. case "style":
  3524. node.style.cssText = "";
  3525. var val = node.getAttributeNode("style");
  3526. !browser.ie && val && node.removeAttributeNode(val);
  3527. }
  3528. node.removeAttribute(ci);
  3529. }
  3530. },
  3531. /**
  3532. * 在doc下创建一个标签名为tag,属性为attrs的元素
  3533. * @method createElement
  3534. * @param { DomDocument } doc 新创建的元素属于该document节点创建
  3535. * @param { String } tagName 需要创建的元素的标签名
  3536. * @param { Object } attrs 新创建的元素的属性key-value集合
  3537. * @return { Element } 新创建的元素对象
  3538. * @example
  3539. * ```javascript
  3540. * var ele = UE.dom.domUtils.createElement( document, 'div', {
  3541. * id: 'test'
  3542. * } );
  3543. *
  3544. * //output: DIV
  3545. * console.log( ele.tagName );
  3546. *
  3547. * //output: test
  3548. * console.log( ele.id );
  3549. *
  3550. * ```
  3551. */
  3552. createElement: function(doc, tag, attrs) {
  3553. return domUtils.setAttributes(doc.createElement(tag), attrs);
  3554. },
  3555. /**
  3556. * 为节点node添加属性attrs,attrs为属性键值对
  3557. * @method setAttributes
  3558. * @param { Element } node 需要设置属性的元素对象
  3559. * @param { Object } attrs 需要设置的属性名-值对
  3560. * @return { Element } 设置属性的元素对象
  3561. * @example
  3562. * ```html
  3563. * <span id="test"></span>
  3564. *
  3565. * <script>
  3566. *
  3567. * var testNode = UE.dom.domUtils.setAttributes( document.getElementById( "test" ), {
  3568. * id: 'demo'
  3569. * } );
  3570. *
  3571. * //output: demo
  3572. * console.log( testNode.id );
  3573. *
  3574. * </script>
  3575. *
  3576. */
  3577. setAttributes: function(node, attrs) {
  3578. for (var attr in attrs) {
  3579. if (attrs.hasOwnProperty(attr)) {
  3580. var value = attrs[attr];
  3581. switch (attr) {
  3582. case "class":
  3583. //ie下要这样赋值,setAttribute不起作用
  3584. node.className = value;
  3585. break;
  3586. case "style":
  3587. node.style.cssText = node.style.cssText + ";" + value;
  3588. break;
  3589. case "innerHTML":
  3590. node[attr] = value;
  3591. break;
  3592. case "value":
  3593. node.value = value;
  3594. break;
  3595. default:
  3596. node.setAttribute(attrFix[attr] || attr, value);
  3597. }
  3598. }
  3599. }
  3600. return node;
  3601. },
  3602. /**
  3603. * 获取元素element经过计算后的样式值
  3604. * @method getComputedStyle
  3605. * @param { Element } element 需要获取样式的元素对象
  3606. * @param { String } styleName 需要获取的样式名
  3607. * @return { String } 获取到的样式值
  3608. * @example
  3609. * ```html
  3610. * <style type="text/css">
  3611. * #test {
  3612. * font-size: 15px;
  3613. * }
  3614. * </style>
  3615. *
  3616. * <span id="test"></span>
  3617. *
  3618. * <script>
  3619. * //output: 15px
  3620. * console.log( UE.dom.domUtils.getComputedStyle( document.getElementById( "test" ), 'font-size' ) );
  3621. * </script>
  3622. * ```
  3623. */
  3624. getComputedStyle: function(element, styleName) {
  3625. //一下的属性单独处理
  3626. var pros = "width height top left";
  3627. if (pros.indexOf(styleName) > -1) {
  3628. return (
  3629. element[
  3630. "offset" +
  3631. styleName.replace(/^\w/, function(s) {
  3632. return s.toUpperCase();
  3633. })
  3634. ] + "px"
  3635. );
  3636. }
  3637. //忽略文本节点
  3638. if (element.nodeType == 3) {
  3639. element = element.parentNode;
  3640. }
  3641. //ie下font-size若body下定义了font-size,则从currentStyle里会取到这个font-size. 取不到实际值,故此修改.
  3642. if (
  3643. browser.ie &&
  3644. browser.version < 9 &&
  3645. styleName == "font-size" &&
  3646. !element.style.fontSize &&
  3647. !dtd.$empty[element.tagName] &&
  3648. !dtd.$nonChild[element.tagName]
  3649. ) {
  3650. var span = element.ownerDocument.createElement("span");
  3651. span.style.cssText = "padding:0;border:0;font-family:simsun;";
  3652. span.innerHTML = ".";
  3653. element.appendChild(span);
  3654. var result = span.offsetHeight;
  3655. element.removeChild(span);
  3656. span = null;
  3657. return result + "px";
  3658. }
  3659. try {
  3660. var value = domUtils.getStyle(element, styleName) ||
  3661. (window.getComputedStyle
  3662. ? domUtils.getWindow(element).getComputedStyle(element, "").getPropertyValue(styleName)
  3663. : (element.currentStyle || element.style)[utils.cssStyleToDomStyle(styleName)]);
  3664. } catch (e) {
  3665. return "";
  3666. }
  3667. return utils.transUnitToPx(utils.fixColor(styleName, value));
  3668. },
  3669. /**
  3670. * 删除元素element指定的className
  3671. * @method removeClasses
  3672. * @param { Element } ele 需要删除class的元素节点
  3673. * @param { String } classNames 需要删除的className, 多个className之间以空格分开
  3674. * @example
  3675. * ```html
  3676. * <span id="test" class="test1 test2 test3">xxx</span>
  3677. *
  3678. * <script>
  3679. *
  3680. * var testNode = document.getElementById( "test" );
  3681. * UE.dom.domUtils.removeClasses( testNode, "test1 test2" );
  3682. *
  3683. * //output: test3
  3684. * console.log( testNode.className );
  3685. *
  3686. * </script>
  3687. * ```
  3688. */
  3689. /**
  3690. * 删除元素element指定的className
  3691. * @method removeClasses
  3692. * @param { Element } ele 需要删除class的元素节点
  3693. * @param { Array } classNames 需要删除的className数组
  3694. * @example
  3695. * ```html
  3696. * <span id="test" class="test1 test2 test3">xxx</span>
  3697. *
  3698. * <script>
  3699. *
  3700. * var testNode = document.getElementById( "test" );
  3701. * UE.dom.domUtils.removeClasses( testNode, ["test1", "test2"] );
  3702. *
  3703. * //output: test3
  3704. * console.log( testNode.className );
  3705. *
  3706. * </script>
  3707. * ```
  3708. */
  3709. removeClasses: function(elm, classNames) {
  3710. classNames = utils.isArray(classNames)
  3711. ? classNames
  3712. : utils.trim(classNames).replace(/[ ]{2,}/g, " ").split(" ");
  3713. for (var i = 0, ci, cls = elm.className; (ci = classNames[i++]); ) {
  3714. cls = cls.replace(new RegExp("\\b" + ci + "\\b"), "");
  3715. }
  3716. cls = utils.trim(cls).replace(/[ ]{2,}/g, " ");
  3717. if (cls) {
  3718. elm.className = cls;
  3719. } else {
  3720. domUtils.removeAttributes(elm, ["class"]);
  3721. }
  3722. },
  3723. /**
  3724. * 给元素element添加className
  3725. * @method addClass
  3726. * @param { Node } ele 需要增加className的元素
  3727. * @param { String } classNames 需要添加的className, 多个className之间以空格分割
  3728. * @remind 相同的类名不会被重复添加
  3729. * @example
  3730. * ```html
  3731. * <span id="test" class="cls1 cls2"></span>
  3732. *
  3733. * <script>
  3734. * var testNode = document.getElementById("test");
  3735. *
  3736. * UE.dom.domUtils.addClass( testNode, "cls2 cls3 cls4" );
  3737. *
  3738. * //output: cl1 cls2 cls3 cls4
  3739. * console.log( testNode.className );
  3740. *
  3741. * <script>
  3742. * ```
  3743. */
  3744. /**
  3745. * 给元素element添加className
  3746. * @method addClass
  3747. * @param { Node } ele 需要增加className的元素
  3748. * @param { Array } classNames 需要添加的className的数组
  3749. * @remind 相同的类名不会被重复添加
  3750. * @example
  3751. * ```html
  3752. * <span id="test" class="cls1 cls2"></span>
  3753. *
  3754. * <script>
  3755. * var testNode = document.getElementById("test");
  3756. *
  3757. * UE.dom.domUtils.addClass( testNode, ["cls2", "cls3", "cls4"] );
  3758. *
  3759. * //output: cl1 cls2 cls3 cls4
  3760. * console.log( testNode.className );
  3761. *
  3762. * <script>
  3763. * ```
  3764. */
  3765. addClass: function(elm, classNames) {
  3766. if (!elm) return;
  3767. classNames = utils.trim(classNames).replace(/[ ]{2,}/g, " ").split(" ");
  3768. for (var i = 0, ci, cls = elm.className; (ci = classNames[i++]); ) {
  3769. if (!new RegExp("\\b" + ci + "\\b").test(cls)) {
  3770. cls += " " + ci;
  3771. }
  3772. }
  3773. elm.className = utils.trim(cls);
  3774. },
  3775. /**
  3776. * 判断元素element是否包含给定的样式类名className
  3777. * @method hasClass
  3778. * @param { Node } ele 需要检测的元素
  3779. * @param { String } classNames 需要检测的className, 多个className之间用空格分割
  3780. * @return { Boolean } 元素是否包含所有给定的className
  3781. * @example
  3782. * ```html
  3783. * <span id="test1" class="cls1 cls2"></span>
  3784. *
  3785. * <script>
  3786. * var test1 = document.getElementById("test1");
  3787. *
  3788. * //output: false
  3789. * console.log( UE.dom.domUtils.hasClass( test1, "cls2 cls1 cls3" ) );
  3790. *
  3791. * //output: true
  3792. * console.log( UE.dom.domUtils.hasClass( test1, "cls2 cls1" ) );
  3793. * </script>
  3794. * ```
  3795. */
  3796. /**
  3797. * 判断元素element是否包含给定的样式类名className
  3798. * @method hasClass
  3799. * @param { Node } ele 需要检测的元素
  3800. * @param { Array } classNames 需要检测的className数组
  3801. * @return { Boolean } 元素是否包含所有给定的className
  3802. * @example
  3803. * ```html
  3804. * <span id="test1" class="cls1 cls2"></span>
  3805. *
  3806. * <script>
  3807. * var test1 = document.getElementById("test1");
  3808. *
  3809. * //output: false
  3810. * console.log( UE.dom.domUtils.hasClass( test1, [ "cls2", "cls1", "cls3" ] ) );
  3811. *
  3812. * //output: true
  3813. * console.log( UE.dom.domUtils.hasClass( test1, [ "cls2", "cls1" ]) );
  3814. * </script>
  3815. * ```
  3816. */
  3817. hasClass: function(element, className) {
  3818. if (utils.isRegExp(className)) {
  3819. return className.test(element.className);
  3820. }
  3821. className = utils.trim(className).replace(/[ ]{2,}/g, " ").split(" ");
  3822. for (var i = 0, ci, cls = element.className; (ci = className[i++]); ) {
  3823. if (!new RegExp("\\b" + ci + "\\b", "i").test(cls)) {
  3824. return false;
  3825. }
  3826. }
  3827. return i - 1 == className.length;
  3828. },
  3829. /**
  3830. * 阻止事件默认行为
  3831. * @method preventDefault
  3832. * @param { Event } evt 需要阻止默认行为的事件对象
  3833. * @example
  3834. * ```javascript
  3835. * UE.dom.domUtils.preventDefault( evt );
  3836. * ```
  3837. */
  3838. preventDefault: function(evt) {
  3839. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  3840. },
  3841. /**
  3842. * 删除元素element指定的样式
  3843. * @method removeStyle
  3844. * @param { Element } element 需要删除样式的元素
  3845. * @param { String } styleName 需要删除的样式名
  3846. * @example
  3847. * ```html
  3848. * <span id="test" style="color: red; background: blue;"></span>
  3849. *
  3850. * <script>
  3851. *
  3852. * var testNode = document.getElementById("test");
  3853. *
  3854. * UE.dom.domUtils.removeStyle( testNode, 'color' );
  3855. *
  3856. * //output: background: blue;
  3857. * console.log( testNode.style.cssText );
  3858. *
  3859. * </script>
  3860. * ```
  3861. */
  3862. removeStyle: function(element, name) {
  3863. if (browser.ie) {
  3864. //针对color先单独处理一下
  3865. if (name == "color") {
  3866. name = "(^|;)" + name;
  3867. }
  3868. element.style.cssText = element.style.cssText.replace(
  3869. new RegExp(name + "[^:]*:[^;]+;?", "ig"),
  3870. ""
  3871. );
  3872. } else {
  3873. if (element.style.removeProperty) {
  3874. element.style.removeProperty(name);
  3875. } else {
  3876. element.style.removeAttribute(utils.cssStyleToDomStyle(name));
  3877. }
  3878. }
  3879. if (!element.style.cssText) {
  3880. domUtils.removeAttributes(element, ["style"]);
  3881. }
  3882. },
  3883. /**
  3884. * 获取元素element的style属性的指定值
  3885. * @method getStyle
  3886. * @param { Element } element 需要获取属性值的元素
  3887. * @param { String } styleName 需要获取的style的名称
  3888. * @warning 该方法仅获取元素style属性中所标明的值
  3889. * @return { String } 该元素包含指定的style属性值
  3890. * @example
  3891. * ```html
  3892. * <div id="test" style="color: red;"></div>
  3893. *
  3894. * <script>
  3895. *
  3896. * var testNode = document.getElementById( "test" );
  3897. *
  3898. * //output: red
  3899. * console.log( UE.dom.domUtils.getStyle( testNode, "color" ) );
  3900. *
  3901. * //output: ""
  3902. * console.log( UE.dom.domUtils.getStyle( testNode, "background" ) );
  3903. *
  3904. * </script>
  3905. * ```
  3906. */
  3907. getStyle: function(element, name) {
  3908. var value = element.style[utils.cssStyleToDomStyle(name)];
  3909. return utils.fixColor(name, value);
  3910. },
  3911. /**
  3912. * 为元素element设置样式属性值
  3913. * @method setStyle
  3914. * @param { Element } element 需要设置样式的元素
  3915. * @param { String } styleName 样式名
  3916. * @param { String } styleValue 样式值
  3917. * @example
  3918. * ```html
  3919. * <div id="test"></div>
  3920. *
  3921. * <script>
  3922. *
  3923. * var testNode = document.getElementById( "test" );
  3924. *
  3925. * //output: ""
  3926. * console.log( testNode.style.color );
  3927. *
  3928. * UE.dom.domUtils.setStyle( testNode, 'color', 'red' );
  3929. * //output: "red"
  3930. * console.log( testNode.style.color );
  3931. *
  3932. * </script>
  3933. * ```
  3934. */
  3935. setStyle: function(element, name, value) {
  3936. element.style[utils.cssStyleToDomStyle(name)] = value;
  3937. if (!utils.trim(element.style.cssText)) {
  3938. this.removeAttributes(element, "style");
  3939. }
  3940. },
  3941. /**
  3942. * 为元素element设置多个样式属性值
  3943. * @method setStyles
  3944. * @param { Element } element 需要设置样式的元素
  3945. * @param { Object } styles 样式名值对
  3946. * @example
  3947. * ```html
  3948. * <div id="test"></div>
  3949. *
  3950. * <script>
  3951. *
  3952. * var testNode = document.getElementById( "test" );
  3953. *
  3954. * //output: ""
  3955. * console.log( testNode.style.color );
  3956. *
  3957. * UE.dom.domUtils.setStyles( testNode, {
  3958. * 'color': 'red'
  3959. * } );
  3960. * //output: "red"
  3961. * console.log( testNode.style.color );
  3962. *
  3963. * </script>
  3964. * ```
  3965. */
  3966. setStyles: function(element, styles) {
  3967. for (var name in styles) {
  3968. if (styles.hasOwnProperty(name)) {
  3969. domUtils.setStyle(element, name, styles[name]);
  3970. }
  3971. }
  3972. },
  3973. /**
  3974. * 删除_moz_dirty属性
  3975. * @private
  3976. * @method removeDirtyAttr
  3977. */
  3978. removeDirtyAttr: function(node) {
  3979. for (
  3980. var i = 0, ci, nodes = node.getElementsByTagName("*");
  3981. (ci = nodes[i++]);
  3982. ) {
  3983. ci.removeAttribute("_moz_dirty");
  3984. }
  3985. node.removeAttribute("_moz_dirty");
  3986. },
  3987. /**
  3988. * 获取子节点的数量
  3989. * @method getChildCount
  3990. * @param { Element } node 需要检测的元素
  3991. * @return { Number } 给定的node元素的子节点数量
  3992. * @example
  3993. * ```html
  3994. * <div id="test">
  3995. * <span></span>
  3996. * </div>
  3997. *
  3998. * <script>
  3999. *
  4000. * //output: 3
  4001. * console.log( UE.dom.domUtils.getChildCount( document.getElementById("test") ) );
  4002. *
  4003. * </script>
  4004. * ```
  4005. */
  4006. /**
  4007. * 根据给定的过滤规则, 获取符合条件的子节点的数量
  4008. * @method getChildCount
  4009. * @param { Element } node 需要检测的元素
  4010. * @param { Function } fn 过滤器, 要求对符合条件的子节点返回true, 反之则要求返回false
  4011. * @return { Number } 符合过滤条件的node元素的子节点数量
  4012. * @example
  4013. * ```html
  4014. * <div id="test">
  4015. * <span></span>
  4016. * </div>
  4017. *
  4018. * <script>
  4019. *
  4020. * //output: 1
  4021. * console.log( UE.dom.domUtils.getChildCount( document.getElementById("test"), function ( node ) {
  4022. *
  4023. * return node.nodeType === 1;
  4024. *
  4025. * } ) );
  4026. *
  4027. * </script>
  4028. * ```
  4029. */
  4030. getChildCount: function(node, fn) {
  4031. var count = 0,
  4032. first = node.firstChild;
  4033. fn =
  4034. fn ||
  4035. function() {
  4036. return 1;
  4037. };
  4038. while (first) {
  4039. if (fn(first)) {
  4040. count++;
  4041. }
  4042. first = first.nextSibling;
  4043. }
  4044. return count;
  4045. },
  4046. /**
  4047. * 判断给定节点是否为空节点
  4048. * @method isEmptyNode
  4049. * @param { Node } node 需要检测的节点对象
  4050. * @return { Boolean } 节点是否为空
  4051. * @example
  4052. * ```javascript
  4053. * UE.dom.domUtils.isEmptyNode( document.body );
  4054. * ```
  4055. */
  4056. isEmptyNode: function(node) {
  4057. return (
  4058. !node.firstChild ||
  4059. domUtils.getChildCount(node, function(node) {
  4060. return (
  4061. !domUtils.isBr(node) &&
  4062. !domUtils.isBookmarkNode(node) &&
  4063. !domUtils.isWhitespace(node)
  4064. );
  4065. }) == 0
  4066. );
  4067. },
  4068. clearSelectedArr: function(nodes) {
  4069. var node;
  4070. while ((node = nodes.pop())) {
  4071. domUtils.removeAttributes(node, ["class"]);
  4072. }
  4073. },
  4074. /**
  4075. * 将显示区域滚动到指定节点的位置
  4076. * @method scrollToView
  4077. * @param {Node} node 节点
  4078. * @param {window} win window对象
  4079. * @param {Number} offsetTop 距离上方的偏移量
  4080. */
  4081. scrollToView: function(node, win, offsetTop) {
  4082. var getViewPaneSize = function() {
  4083. var doc = win.document,
  4084. mode = doc.compatMode == "CSS1Compat";
  4085. return {
  4086. width:
  4087. (mode ? doc.documentElement.clientWidth : doc.body.clientWidth) || 0,
  4088. height:
  4089. (mode ? doc.documentElement.clientHeight : doc.body.clientHeight) || 0
  4090. };
  4091. },
  4092. getScrollPosition = function(win) {
  4093. if ("pageXOffset" in win) {
  4094. return {
  4095. x: win.pageXOffset || 0,
  4096. y: win.pageYOffset || 0
  4097. };
  4098. } else {
  4099. var doc = win.document;
  4100. return {
  4101. x: doc.documentElement.scrollLeft || doc.body.scrollLeft || 0,
  4102. y: doc.documentElement.scrollTop || doc.body.scrollTop || 0
  4103. };
  4104. }
  4105. };
  4106. var winHeight = getViewPaneSize().height,
  4107. offset = winHeight * -1 + offsetTop;
  4108. offset += node.offsetHeight || 0;
  4109. var elementPosition = domUtils.getXY(node);
  4110. offset += elementPosition.y;
  4111. var currentScroll = getScrollPosition(win).y;
  4112. // offset += 50;
  4113. if (offset > currentScroll || offset < currentScroll - winHeight) {
  4114. win.scrollTo(0, offset + (offset < 0 ? -20 : 20));
  4115. }
  4116. },
  4117. /**
  4118. * 判断给定节点是否为br
  4119. * @method isBr
  4120. * @param { Node } node 需要判断的节点对象
  4121. * @return { Boolean } 给定的节点是否是br节点
  4122. */
  4123. isBr: function(node) {
  4124. return node.nodeType == 1 && node.tagName == "BR";
  4125. },
  4126. /**
  4127. * 判断给定的节点是否是一个“填充”节点
  4128. * @private
  4129. * @method isFillChar
  4130. * @param { Node } node 需要判断的节点
  4131. * @param { Boolean } isInStart 是否从节点内容的开始位置匹配
  4132. * @returns { Boolean } 节点是否是填充节点
  4133. */
  4134. isFillChar: function(node, isInStart) {
  4135. if (node.nodeType != 3) return false;
  4136. var text = node.nodeValue;
  4137. if (isInStart) {
  4138. return new RegExp("^" + domUtils.fillChar).test(text);
  4139. }
  4140. return !text.replace(new RegExp(domUtils.fillChar, "g"), "").length;
  4141. },
  4142. isStartInblock: function(range) {
  4143. var tmpRange = range.cloneRange(),
  4144. flag = 0,
  4145. start = tmpRange.startContainer,
  4146. tmp;
  4147. if (start.nodeType == 1 && start.childNodes[tmpRange.startOffset]) {
  4148. start = start.childNodes[tmpRange.startOffset];
  4149. var pre = start.previousSibling;
  4150. while (pre && domUtils.isFillChar(pre)) {
  4151. start = pre;
  4152. pre = pre.previousSibling;
  4153. }
  4154. }
  4155. if (this.isFillChar(start, true) && tmpRange.startOffset == 1) {
  4156. tmpRange.setStartBefore(start);
  4157. start = tmpRange.startContainer;
  4158. }
  4159. while (start && domUtils.isFillChar(start)) {
  4160. tmp = start;
  4161. start = start.previousSibling;
  4162. }
  4163. if (tmp) {
  4164. tmpRange.setStartBefore(tmp);
  4165. start = tmpRange.startContainer;
  4166. }
  4167. if (
  4168. start.nodeType == 1 &&
  4169. domUtils.isEmptyNode(start) &&
  4170. tmpRange.startOffset == 1
  4171. ) {
  4172. tmpRange.setStart(start, 0).collapse(true);
  4173. }
  4174. while (!tmpRange.startOffset) {
  4175. start = tmpRange.startContainer;
  4176. if (domUtils.isBlockElm(start) || domUtils.isBody(start)) {
  4177. flag = 1;
  4178. break;
  4179. }
  4180. var pre = tmpRange.startContainer.previousSibling,
  4181. tmpNode;
  4182. if (!pre) {
  4183. tmpRange.setStartBefore(tmpRange.startContainer);
  4184. } else {
  4185. while (pre && domUtils.isFillChar(pre)) {
  4186. tmpNode = pre;
  4187. pre = pre.previousSibling;
  4188. }
  4189. if (tmpNode) {
  4190. tmpRange.setStartBefore(tmpNode);
  4191. } else {
  4192. tmpRange.setStartBefore(tmpRange.startContainer);
  4193. }
  4194. }
  4195. }
  4196. return flag && !domUtils.isBody(tmpRange.startContainer) ? 1 : 0;
  4197. },
  4198. /**
  4199. * 判断给定的元素是否是一个空元素
  4200. * @method isEmptyBlock
  4201. * @param { Element } node 需要判断的元素
  4202. * @return { Boolean } 是否是空元素
  4203. * @example
  4204. * ```html
  4205. * <div id="test"></div>
  4206. *
  4207. * <script>
  4208. * //output: true
  4209. * console.log( UE.dom.domUtils.isEmptyBlock( document.getElementById("test") ) );
  4210. * </script>
  4211. * ```
  4212. */
  4213. /**
  4214. * 根据指定的判断规则判断给定的元素是否是一个空元素
  4215. * @method isEmptyBlock
  4216. * @param { Element } node 需要判断的元素
  4217. * @param { RegExp } reg 对内容执行判断的正则表达式对象
  4218. * @return { Boolean } 是否是空元素
  4219. */
  4220. isEmptyBlock: function(node, reg) {
  4221. if (node.nodeType != 1) return 0;
  4222. reg = reg || new RegExp("[ \xa0\t\r\n" + domUtils.fillChar + "]", "g");
  4223. if (
  4224. node[browser.ie ? "innerText" : "textContent"].replace(reg, "").length > 0
  4225. ) {
  4226. return 0;
  4227. }
  4228. for (var n in dtd.$isNotEmpty) {
  4229. if (node.getElementsByTagName(n).length) {
  4230. return 0;
  4231. }
  4232. }
  4233. return 1;
  4234. },
  4235. /**
  4236. * 移动元素使得该元素的位置移动指定的偏移量的距离
  4237. * @method setViewportOffset
  4238. * @param { Element } element 需要设置偏移量的元素
  4239. * @param { Object } offset 偏移量, 形如{ left: 100, top: 50 }的一个键值对, 表示该元素将在
  4240. * 现有的位置上向水平方向偏移offset.left的距离, 在竖直方向上偏移
  4241. * offset.top的距离
  4242. * @example
  4243. * ```html
  4244. * <div id="test" style="top: 100px; left: 50px; position: absolute;"></div>
  4245. *
  4246. * <script>
  4247. *
  4248. * var testNode = document.getElementById("test");
  4249. *
  4250. * UE.dom.domUtils.setViewportOffset( testNode, {
  4251. * left: 200,
  4252. * top: 50
  4253. * } );
  4254. *
  4255. * //output: top: 300px; left: 100px; position: absolute;
  4256. * console.log( testNode.style.cssText );
  4257. *
  4258. * </script>
  4259. * ```
  4260. */
  4261. setViewportOffset: function(element, offset) {
  4262. var left = parseInt(element.style.left) | 0;
  4263. var top = parseInt(element.style.top) | 0;
  4264. var rect = element.getBoundingClientRect();
  4265. var offsetLeft = offset.left - rect.left;
  4266. var offsetTop = offset.top - rect.top;
  4267. if (offsetLeft) {
  4268. element.style.left = left + offsetLeft + "px";
  4269. }
  4270. if (offsetTop) {
  4271. element.style.top = top + offsetTop + "px";
  4272. }
  4273. },
  4274. /**
  4275. * 用“填充字符”填充节点
  4276. * @method fillNode
  4277. * @private
  4278. * @param { DomDocument } doc 填充的节点所在的docment对象
  4279. * @param { Node } node 需要填充的节点对象
  4280. * @example
  4281. * ```html
  4282. * <div id="test"></div>
  4283. *
  4284. * <script>
  4285. * var testNode = document.getElementById("test");
  4286. *
  4287. * //output: 0
  4288. * console.log( testNode.childNodes.length );
  4289. *
  4290. * UE.dom.domUtils.fillNode( document, testNode );
  4291. *
  4292. * //output: 1
  4293. * console.log( testNode.childNodes.length );
  4294. *
  4295. * </script>
  4296. * ```
  4297. */
  4298. fillNode: function(doc, node) {
  4299. var tmpNode = browser.ie
  4300. ? doc.createTextNode(domUtils.fillChar)
  4301. : doc.createElement("br");
  4302. node.innerHTML = "";
  4303. node.appendChild(tmpNode);
  4304. },
  4305. /**
  4306. * 把节点src的所有子节点追加到另一个节点tag上去
  4307. * @method moveChild
  4308. * @param { Node } src 源节点, 该节点下的所有子节点将被移除
  4309. * @param { Node } tag 目标节点, 从源节点移除的子节点将被追加到该节点下
  4310. * @example
  4311. * ```html
  4312. * <div id="test1">
  4313. * <span></span>
  4314. * </div>
  4315. * <div id="test2">
  4316. * <div></div>
  4317. * </div>
  4318. *
  4319. * <script>
  4320. *
  4321. * var test1 = document.getElementById("test1"),
  4322. * test2 = document.getElementById("test2");
  4323. *
  4324. * UE.dom.domUtils.moveChild( test1, test2 );
  4325. *
  4326. * //output: ""(空字符串)
  4327. * console.log( test1.innerHTML );
  4328. *
  4329. * //output: "<div></div><span></span>"
  4330. * console.log( test2.innerHTML );
  4331. *
  4332. * </script>
  4333. * ```
  4334. */
  4335. /**
  4336. * 把节点src的所有子节点移动到另一个节点tag上去, 可以通过dir参数控制附加的行为是“追加”还是“插入顶部”
  4337. * @method moveChild
  4338. * @param { Node } src 源节点, 该节点下的所有子节点将被移除
  4339. * @param { Node } tag 目标节点, 从源节点移除的子节点将被附加到该节点下
  4340. * @param { Boolean } dir 附加方式, 如果为true, 则附加进去的节点将被放到目标节点的顶部, 反之,则放到末尾
  4341. * @example
  4342. * ```html
  4343. * <div id="test1">
  4344. * <span></span>
  4345. * </div>
  4346. * <div id="test2">
  4347. * <div></div>
  4348. * </div>
  4349. *
  4350. * <script>
  4351. *
  4352. * var test1 = document.getElementById("test1"),
  4353. * test2 = document.getElementById("test2");
  4354. *
  4355. * UE.dom.domUtils.moveChild( test1, test2, true );
  4356. *
  4357. * //output: ""(空字符串)
  4358. * console.log( test1.innerHTML );
  4359. *
  4360. * //output: "<span></span><div></div>"
  4361. * console.log( test2.innerHTML );
  4362. *
  4363. * </script>
  4364. * ```
  4365. */
  4366. moveChild: function(src, tag, dir) {
  4367. while (src.firstChild) {
  4368. if (dir && tag.firstChild) {
  4369. tag.insertBefore(src.lastChild, tag.firstChild);
  4370. } else {
  4371. tag.appendChild(src.firstChild);
  4372. }
  4373. }
  4374. },
  4375. /**
  4376. * 判断节点的标签上是否不存在任何属性
  4377. * @method hasNoAttributes
  4378. * @private
  4379. * @param { Node } node 需要检测的节点对象
  4380. * @return { Boolean } 节点是否不包含任何属性
  4381. * @example
  4382. * ```html
  4383. * <div id="test"><span>xxxx</span></div>
  4384. *
  4385. * <script>
  4386. *
  4387. * //output: false
  4388. * console.log( UE.dom.domUtils.hasNoAttributes( document.getElementById("test") ) );
  4389. *
  4390. * //output: true
  4391. * console.log( UE.dom.domUtils.hasNoAttributes( document.getElementById("test").firstChild ) );
  4392. *
  4393. * </script>
  4394. * ```
  4395. */
  4396. hasNoAttributes: function(node) {
  4397. return browser.ie
  4398. ? /^<\w+\s*?>/.test(node.outerHTML)
  4399. : node.attributes.length == 0;
  4400. },
  4401. /**
  4402. * 检测节点是否是UEditor所使用的辅助节点
  4403. * @method isCustomeNode
  4404. * @private
  4405. * @param { Node } node 需要检测的节点
  4406. * @remind 辅助节点是指编辑器要完成工作临时添加的节点, 在输出的时候将会从编辑器内移除, 不会影响最终的结果。
  4407. * @return { Boolean } 给定的节点是否是一个辅助节点
  4408. */
  4409. isCustomeNode: function(node) {
  4410. return node.nodeType == 1 && node.getAttribute("_ue_custom_node_");
  4411. },
  4412. /**
  4413. * 检测节点的标签是否是给定的标签
  4414. * @method isTagNode
  4415. * @param { Node } node 需要检测的节点对象
  4416. * @param { String } tagName 标签
  4417. * @return { Boolean } 节点的标签是否是给定的标签
  4418. * @example
  4419. * ```html
  4420. * <div id="test"></div>
  4421. *
  4422. * <script>
  4423. *
  4424. * //output: true
  4425. * console.log( UE.dom.domUtils.isTagNode( document.getElementById("test"), "div" ) );
  4426. *
  4427. * </script>
  4428. * ```
  4429. */
  4430. isTagNode: function(node, tagNames) {
  4431. return (
  4432. node.nodeType == 1 &&
  4433. new RegExp("\\b" + node.tagName + "\\b", "i").test(tagNames)
  4434. );
  4435. },
  4436. /**
  4437. * 给定一个节点数组,在通过指定的过滤器过滤后, 获取其中满足过滤条件的第一个节点
  4438. * @method filterNodeList
  4439. * @param { Array } nodeList 需要过滤的节点数组
  4440. * @param { Function } fn 过滤器, 对符合条件的节点, 执行结果返回true, 反之则返回false
  4441. * @return { Node | NULL } 如果找到符合过滤条件的节点, 则返回该节点, 否则返回NULL
  4442. * @example
  4443. * ```javascript
  4444. * var divNodes = document.getElementsByTagName("div");
  4445. * divNodes = [].slice.call( divNodes, 0 );
  4446. *
  4447. * //output: null
  4448. * console.log( UE.dom.domUtils.filterNodeList( divNodes, function ( node ) {
  4449. * return node.tagName.toLowerCase() !== 'div';
  4450. * } ) );
  4451. * ```
  4452. */
  4453. /**
  4454. * 给定一个节点数组nodeList和一组标签名tagNames, 获取其中能够匹配标签名的节点集合中的第一个节点
  4455. * @method filterNodeList
  4456. * @param { Array } nodeList 需要过滤的节点数组
  4457. * @param { String } tagNames 需要匹配的标签名, 多个标签名之间用空格分割
  4458. * @return { Node | NULL } 如果找到标签名匹配的节点, 则返回该节点, 否则返回NULL
  4459. * @example
  4460. * ```javascript
  4461. * var divNodes = document.getElementsByTagName("div");
  4462. * divNodes = [].slice.call( divNodes, 0 );
  4463. *
  4464. * //output: null
  4465. * console.log( UE.dom.domUtils.filterNodeList( divNodes, 'a span' ) );
  4466. * ```
  4467. */
  4468. /**
  4469. * 给定一个节点数组,在通过指定的过滤器过滤后, 如果参数forAll为true, 则会返回所有满足过滤
  4470. * 条件的节点集合, 否则, 返回满足条件的节点集合中的第一个节点
  4471. * @method filterNodeList
  4472. * @param { Array } nodeList 需要过滤的节点数组
  4473. * @param { Function } fn 过滤器, 对符合条件的节点, 执行结果返回true, 反之则返回false
  4474. * @param { Boolean } forAll 是否返回整个节点数组, 如果该参数为false, 则返回节点集合中的第一个节点
  4475. * @return { Array | Node | NULL } 如果找到符合过滤条件的节点, 则根据参数forAll的值决定返回满足
  4476. * 过滤条件的节点数组或第一个节点, 否则返回NULL
  4477. * @example
  4478. * ```javascript
  4479. * var divNodes = document.getElementsByTagName("div");
  4480. * divNodes = [].slice.call( divNodes, 0 );
  4481. *
  4482. * //output: 3(假定有3个div)
  4483. * console.log( divNodes.length );
  4484. *
  4485. * var nodes = UE.dom.domUtils.filterNodeList( divNodes, function ( node ) {
  4486. * return node.tagName.toLowerCase() === 'div';
  4487. * }, true );
  4488. *
  4489. * //output: 3
  4490. * console.log( nodes.length );
  4491. *
  4492. * var node = UE.dom.domUtils.filterNodeList( divNodes, function ( node ) {
  4493. * return node.tagName.toLowerCase() === 'div';
  4494. * }, false );
  4495. *
  4496. * //output: div
  4497. * console.log( node.nodeName );
  4498. * ```
  4499. */
  4500. filterNodeList: function(nodelist, filter, forAll) {
  4501. var results = [];
  4502. if (!utils.isFunction(filter)) {
  4503. var str = filter;
  4504. filter = function(n) {
  4505. return (
  4506. utils.indexOf(
  4507. utils.isArray(str) ? str : str.split(" "),
  4508. n.tagName.toLowerCase()
  4509. ) != -1
  4510. );
  4511. };
  4512. }
  4513. utils.each(nodelist, function(n) {
  4514. filter(n) && results.push(n);
  4515. });
  4516. return results.length == 0
  4517. ? null
  4518. : results.length == 1 || !forAll ? results[0] : results;
  4519. },
  4520. /**
  4521. * 查询给定的range选区是否在给定的node节点内,且在该节点的最末尾
  4522. * @method isInNodeEndBoundary
  4523. * @param { UE.dom.Range } rng 需要判断的range对象, 该对象的startContainer不能为NULL
  4524. * @param node 需要检测的节点对象
  4525. * @return { Number } 如果给定的选取range对象是在node内部的最末端, 则返回1, 否则返回0
  4526. */
  4527. isInNodeEndBoundary: function(rng, node) {
  4528. var start = rng.startContainer;
  4529. if (start.nodeType == 3 && rng.startOffset != start.nodeValue.length) {
  4530. return 0;
  4531. }
  4532. if (start.nodeType == 1 && rng.startOffset != start.childNodes.length) {
  4533. return 0;
  4534. }
  4535. while (start !== node) {
  4536. if (start.nextSibling) {
  4537. return 0;
  4538. }
  4539. start = start.parentNode;
  4540. }
  4541. return 1;
  4542. },
  4543. isBoundaryNode: function(node, dir) {
  4544. var tmp;
  4545. while (!domUtils.isBody(node)) {
  4546. tmp = node;
  4547. node = node.parentNode;
  4548. if (tmp !== node[dir]) {
  4549. return false;
  4550. }
  4551. }
  4552. return true;
  4553. },
  4554. fillHtml: browser.ie11below ? "&nbsp;" : "<br/>"
  4555. });
  4556. var fillCharReg = new RegExp(domUtils.fillChar, "g");
  4557. // core/Range.js
  4558. /**
  4559. * Range封装
  4560. * @file
  4561. * @module UE.dom
  4562. * @class Range
  4563. * @since 1.2.6.1
  4564. */
  4565. /**
  4566. * dom操作封装
  4567. * @unfile
  4568. * @module UE.dom
  4569. */
  4570. /**
  4571. * Range实现类,本类是UEditor底层核心类,封装不同浏览器之间的Range操作。
  4572. * @unfile
  4573. * @module UE.dom
  4574. * @class Range
  4575. */
  4576. ;(function() {
  4577. var guid = 0,
  4578. fillChar = domUtils.fillChar,
  4579. fillData;
  4580. /**
  4581. * 更新range的collapse状态
  4582. * @param {Range} range range对象
  4583. */
  4584. function updateCollapse(range) {
  4585. range.collapsed =
  4586. range.startContainer &&
  4587. range.endContainer &&
  4588. range.startContainer === range.endContainer &&
  4589. range.startOffset == range.endOffset;
  4590. }
  4591. function selectOneNode(rng) {
  4592. return (
  4593. !rng.collapsed &&
  4594. rng.startContainer.nodeType == 1 &&
  4595. rng.startContainer === rng.endContainer &&
  4596. rng.endOffset - rng.startOffset == 1
  4597. );
  4598. }
  4599. function setEndPoint(toStart, node, offset, range) {
  4600. //如果node是自闭合标签要处理
  4601. if (
  4602. node.nodeType == 1 &&
  4603. (dtd.$empty[node.tagName] || dtd.$nonChild[node.tagName])
  4604. ) {
  4605. offset = domUtils.getNodeIndex(node) + (toStart ? 0 : 1);
  4606. node = node.parentNode;
  4607. }
  4608. if (toStart) {
  4609. range.startContainer = node;
  4610. range.startOffset = offset;
  4611. if (!range.endContainer) {
  4612. range.collapse(true);
  4613. }
  4614. } else {
  4615. range.endContainer = node;
  4616. range.endOffset = offset;
  4617. if (!range.startContainer) {
  4618. range.collapse(false);
  4619. }
  4620. }
  4621. updateCollapse(range);
  4622. return range;
  4623. }
  4624. function execContentsAction(range, action) {
  4625. //调整边界
  4626. //range.includeBookmark();
  4627. var start = range.startContainer,
  4628. end = range.endContainer,
  4629. startOffset = range.startOffset,
  4630. endOffset = range.endOffset,
  4631. doc = range.document,
  4632. frag = doc.createDocumentFragment(),
  4633. tmpStart,
  4634. tmpEnd;
  4635. if (start.nodeType == 1) {
  4636. start =
  4637. start.childNodes[startOffset] ||
  4638. (tmpStart = start.appendChild(doc.createTextNode("")));
  4639. }
  4640. if (end.nodeType == 1) {
  4641. end =
  4642. end.childNodes[endOffset] ||
  4643. (tmpEnd = end.appendChild(doc.createTextNode("")));
  4644. }
  4645. if (start === end && start.nodeType == 3) {
  4646. frag.appendChild(
  4647. doc.createTextNode(
  4648. start.substringData(startOffset, endOffset - startOffset)
  4649. )
  4650. );
  4651. //is not clone
  4652. if (action) {
  4653. start.deleteData(startOffset, endOffset - startOffset);
  4654. range.collapse(true);
  4655. }
  4656. return frag;
  4657. }
  4658. var current,
  4659. currentLevel,
  4660. clone = frag,
  4661. startParents = domUtils.findParents(start, true),
  4662. endParents = domUtils.findParents(end, true);
  4663. for (var i = 0; startParents[i] == endParents[i]; ) {
  4664. i++;
  4665. }
  4666. for (var j = i, si; (si = startParents[j]); j++) {
  4667. current = si.nextSibling;
  4668. if (si == start) {
  4669. if (!tmpStart) {
  4670. if (range.startContainer.nodeType == 3) {
  4671. clone.appendChild(
  4672. doc.createTextNode(start.nodeValue.slice(startOffset))
  4673. );
  4674. //is not clone
  4675. if (action) {
  4676. start.deleteData(
  4677. startOffset,
  4678. start.nodeValue.length - startOffset
  4679. );
  4680. }
  4681. } else {
  4682. clone.appendChild(!action ? start.cloneNode(true) : start);
  4683. }
  4684. }
  4685. } else {
  4686. currentLevel = si.cloneNode(false);
  4687. clone.appendChild(currentLevel);
  4688. }
  4689. while (current) {
  4690. if (current === end || current === endParents[j]) {
  4691. break;
  4692. }
  4693. si = current.nextSibling;
  4694. clone.appendChild(!action ? current.cloneNode(true) : current);
  4695. current = si;
  4696. }
  4697. clone = currentLevel;
  4698. }
  4699. clone = frag;
  4700. if (!startParents[i]) {
  4701. clone.appendChild(startParents[i - 1].cloneNode(false));
  4702. clone = clone.firstChild;
  4703. }
  4704. for (var j = i, ei; (ei = endParents[j]); j++) {
  4705. current = ei.previousSibling;
  4706. if (ei == end) {
  4707. if (!tmpEnd && range.endContainer.nodeType == 3) {
  4708. clone.appendChild(
  4709. doc.createTextNode(end.substringData(0, endOffset))
  4710. );
  4711. //is not clone
  4712. if (action) {
  4713. end.deleteData(0, endOffset);
  4714. }
  4715. }
  4716. } else {
  4717. currentLevel = ei.cloneNode(false);
  4718. clone.appendChild(currentLevel);
  4719. }
  4720. //如果两端同级,右边第一次已经被开始做了
  4721. if (j != i || !startParents[i]) {
  4722. while (current) {
  4723. if (current === start) {
  4724. break;
  4725. }
  4726. ei = current.previousSibling;
  4727. clone.insertBefore(
  4728. !action ? current.cloneNode(true) : current,
  4729. clone.firstChild
  4730. );
  4731. current = ei;
  4732. }
  4733. }
  4734. clone = currentLevel;
  4735. }
  4736. if (action) {
  4737. range
  4738. .setStartBefore(
  4739. !endParents[i]
  4740. ? endParents[i - 1]
  4741. : !startParents[i] ? startParents[i - 1] : endParents[i]
  4742. )
  4743. .collapse(true);
  4744. }
  4745. tmpStart && domUtils.remove(tmpStart);
  4746. tmpEnd && domUtils.remove(tmpEnd);
  4747. return frag;
  4748. }
  4749. /**
  4750. * 创建一个跟document绑定的空的Range实例
  4751. * @constructor
  4752. * @param { Document } document 新建的选区所属的文档对象
  4753. */
  4754. /**
  4755. * @property { Node } startContainer 当前Range的开始边界的容器节点, 可以是一个元素节点或者是文本节点
  4756. */
  4757. /**
  4758. * @property { Node } startOffset 当前Range的开始边界容器节点的偏移量, 如果是元素节点,
  4759. * 该值就是childNodes中的第几个节点, 如果是文本节点就是文本内容的第几个字符
  4760. */
  4761. /**
  4762. * @property { Node } endContainer 当前Range的结束边界的容器节点, 可以是一个元素节点或者是文本节点
  4763. */
  4764. /**
  4765. * @property { Node } endOffset 当前Range的结束边界容器节点的偏移量, 如果是元素节点,
  4766. * 该值就是childNodes中的第几个节点, 如果是文本节点就是文本内容的第几个字符
  4767. */
  4768. /**
  4769. * @property { Boolean } collapsed 当前Range是否闭合
  4770. * @default true
  4771. * @remind Range是闭合的时候, startContainer === endContainer && startOffset === endOffset
  4772. */
  4773. /**
  4774. * @property { Document } document 当前Range所属的Document对象
  4775. * @remind 不同range的的document属性可以是不同的
  4776. */
  4777. var Range = (dom.Range = function(document) {
  4778. var me = this;
  4779. me.startContainer = me.startOffset = me.endContainer = me.endOffset = null;
  4780. me.document = document;
  4781. me.collapsed = true;
  4782. });
  4783. /**
  4784. * 删除fillData
  4785. * @param doc
  4786. * @param excludeNode
  4787. */
  4788. function removeFillData(doc, excludeNode) {
  4789. try {
  4790. if (fillData && domUtils.inDoc(fillData, doc)) {
  4791. if (!fillData.nodeValue.replace(fillCharReg, "").length) {
  4792. var tmpNode = fillData.parentNode;
  4793. domUtils.remove(fillData);
  4794. while (
  4795. tmpNode &&
  4796. domUtils.isEmptyInlineElement(tmpNode) &&
  4797. //safari的contains有bug
  4798. (browser.safari
  4799. ? !(
  4800. domUtils.getPosition(tmpNode, excludeNode) &
  4801. domUtils.POSITION_CONTAINS
  4802. )
  4803. : !tmpNode.contains(excludeNode))
  4804. ) {
  4805. fillData = tmpNode.parentNode;
  4806. domUtils.remove(tmpNode);
  4807. tmpNode = fillData;
  4808. }
  4809. } else {
  4810. fillData.nodeValue = fillData.nodeValue.replace(fillCharReg, "");
  4811. }
  4812. }
  4813. } catch (e) {}
  4814. }
  4815. /**
  4816. * @param node
  4817. * @param dir
  4818. */
  4819. function mergeSibling(node, dir) {
  4820. var tmpNode;
  4821. node = node[dir];
  4822. while (node && domUtils.isFillChar(node)) {
  4823. tmpNode = node[dir];
  4824. domUtils.remove(node);
  4825. node = tmpNode;
  4826. }
  4827. }
  4828. Range.prototype = {
  4829. /**
  4830. * 克隆选区的内容到一个DocumentFragment里
  4831. * @method cloneContents
  4832. * @return { DocumentFragment | NULL } 如果选区是闭合的将返回null, 否则, 返回包含所clone内容的DocumentFragment元素
  4833. * @example
  4834. * ```html
  4835. * <body>
  4836. * <!-- 中括号表示选区 -->
  4837. * <b>x<i>x[x</i>xx]x</b>
  4838. *
  4839. * <script>
  4840. * //range是已选中的选区
  4841. * var fragment = range.cloneContents(),
  4842. * node = document.createElement("div");
  4843. *
  4844. * node.appendChild( fragment );
  4845. *
  4846. * //output: <i>x</i>xx
  4847. * console.log( node.innerHTML );
  4848. *
  4849. * </script>
  4850. * </body>
  4851. * ```
  4852. */
  4853. cloneContents: function() {
  4854. return this.collapsed ? null : execContentsAction(this, 0);
  4855. },
  4856. /**
  4857. * 删除当前选区范围中的所有内容
  4858. * @method deleteContents
  4859. * @remind 执行完该操作后, 当前Range对象变成了闭合状态
  4860. * @return { UE.dom.Range } 当前操作的Range对象
  4861. * @example
  4862. * ```html
  4863. * <body>
  4864. * <!-- 中括号表示选区 -->
  4865. * <b>x<i>x[x</i>xx]x</b>
  4866. *
  4867. * <script>
  4868. * //range是已选中的选区
  4869. * range.deleteContents();
  4870. *
  4871. * //竖线表示闭合后的选区位置
  4872. * //output: <b>x<i>x</i>|x</b>
  4873. * console.log( document.body.innerHTML );
  4874. *
  4875. * //此时, range的各项属性为
  4876. * //output: B
  4877. * console.log( range.startContainer.tagName );
  4878. * //output: 2
  4879. * console.log( range.startOffset );
  4880. * //output: B
  4881. * console.log( range.endContainer.tagName );
  4882. * //output: 2
  4883. * console.log( range.endOffset );
  4884. * //output: true
  4885. * console.log( range.collapsed );
  4886. *
  4887. * </script>
  4888. * </body>
  4889. * ```
  4890. */
  4891. deleteContents: function() {
  4892. var txt;
  4893. if (!this.collapsed) {
  4894. execContentsAction(this, 1);
  4895. }
  4896. if (browser.webkit) {
  4897. txt = this.startContainer;
  4898. if (txt.nodeType == 3 && !txt.nodeValue.length) {
  4899. this.setStartBefore(txt).collapse(true);
  4900. domUtils.remove(txt);
  4901. }
  4902. }
  4903. return this;
  4904. },
  4905. /**
  4906. * 将当前选区的内容提取到一个DocumentFragment里
  4907. * @method extractContents
  4908. * @remind 执行该操作后, 选区将变成闭合状态
  4909. * @warning 执行该操作后, 原来选区所选中的内容将从dom树上剥离出来
  4910. * @return { DocumentFragment } 返回包含所提取内容的DocumentFragment对象
  4911. * @example
  4912. * ```html
  4913. * <body>
  4914. * <!-- 中括号表示选区 -->
  4915. * <b>x<i>x[x</i>xx]x</b>
  4916. *
  4917. * <script>
  4918. * //range是已选中的选区
  4919. * var fragment = range.extractContents(),
  4920. * node = document.createElement( "div" );
  4921. *
  4922. * node.appendChild( fragment );
  4923. *
  4924. * //竖线表示闭合后的选区位置
  4925. *
  4926. * //output: <b>x<i>x</i>|x</b>
  4927. * console.log( document.body.innerHTML );
  4928. * //output: <i>x</i>xx
  4929. * console.log( node.innerHTML );
  4930. *
  4931. * //此时, range的各项属性为
  4932. * //output: B
  4933. * console.log( range.startContainer.tagName );
  4934. * //output: 2
  4935. * console.log( range.startOffset );
  4936. * //output: B
  4937. * console.log( range.endContainer.tagName );
  4938. * //output: 2
  4939. * console.log( range.endOffset );
  4940. * //output: true
  4941. * console.log( range.collapsed );
  4942. *
  4943. * </script>
  4944. * </body>
  4945. */
  4946. extractContents: function() {
  4947. return this.collapsed ? null : execContentsAction(this, 2);
  4948. },
  4949. /**
  4950. * 设置Range的开始容器节点和偏移量
  4951. * @method setStart
  4952. * @remind 如果给定的节点是元素节点,那么offset指的是其子元素中索引为offset的元素,
  4953. * 如果是文本节点,那么offset指的是其文本内容的第offset个字符
  4954. * @remind 如果提供的容器节点是一个不能包含子元素的节点, 则该选区的开始容器将被设置
  4955. * 为该节点的父节点, 此时, 其距离开始容器的偏移量也变成了该节点在其父节点
  4956. * 中的索引
  4957. * @param { Node } node 将被设为当前选区开始边界容器的节点对象
  4958. * @param { int } offset 选区的开始位置偏移量
  4959. * @return { UE.dom.Range } 当前range对象
  4960. * @example
  4961. * ```html
  4962. * <!-- 选区 -->
  4963. * <b>xxx<i>x<span>xx</span>xx<em>xx</em>xxx</i>[xxx]</b>
  4964. *
  4965. * <script>
  4966. *
  4967. * //执行操作
  4968. * range.setStart( document.getElementsByTagName("i")[0], 1 );
  4969. *
  4970. * //此时, 选区变成了
  4971. * //<b>xxx<i>x[<span>xx</span>xx<em>xx</em>xxx</i>xxx]</b>
  4972. *
  4973. * </script>
  4974. * ```
  4975. * @example
  4976. * ```html
  4977. * <!-- 选区 -->
  4978. * <b>xxx<img>[xx]x</b>
  4979. *
  4980. * <script>
  4981. *
  4982. * //执行操作
  4983. * range.setStart( document.getElementsByTagName("img")[0], 3 );
  4984. *
  4985. * //此时, 选区变成了
  4986. * //<b>xxx[<img>xx]x</b>
  4987. *
  4988. * </script>
  4989. * ```
  4990. */
  4991. setStart: function(node, offset) {
  4992. return setEndPoint(true, node, offset, this);
  4993. },
  4994. /**
  4995. * 设置Range的结束容器和偏移量
  4996. * @method setEnd
  4997. * @param { Node } node 作为当前选区结束边界容器的节点对象
  4998. * @param { int } offset 结束边界的偏移量
  4999. * @see UE.dom.Range:setStart(Node,int)
  5000. * @return { UE.dom.Range } 当前range对象
  5001. */
  5002. setEnd: function(node, offset) {
  5003. return setEndPoint(false, node, offset, this);
  5004. },
  5005. /**
  5006. * 将Range开始位置设置到node节点之后
  5007. * @method setStartAfter
  5008. * @remind 该操作将会把给定节点的父节点作为range的开始容器, 且偏移量是该节点在其父节点中的位置索引+1
  5009. * @param { Node } node 选区的开始边界将紧接着该节点之后
  5010. * @return { UE.dom.Range } 当前range对象
  5011. * @example
  5012. * ```html
  5013. * <!-- 选区示例 -->
  5014. * <b>xx<i>xxx</i><span>xx[x</span>xxx]</b>
  5015. *
  5016. * <script>
  5017. *
  5018. * //执行操作
  5019. * range.setStartAfter( document.getElementsByTagName("i")[0] );
  5020. *
  5021. * //结果选区
  5022. * //<b>xx<i>xxx</i>[<span>xxx</span>xxx]</b>
  5023. *
  5024. * </script>
  5025. * ```
  5026. */
  5027. setStartAfter: function(node) {
  5028. return this.setStart(node.parentNode, domUtils.getNodeIndex(node) + 1);
  5029. },
  5030. /**
  5031. * 将Range开始位置设置到node节点之前
  5032. * @method setStartBefore
  5033. * @remind 该操作将会把给定节点的父节点作为range的开始容器, 且偏移量是该节点在其父节点中的位置索引
  5034. * @param { Node } node 新的选区开始位置在该节点之前
  5035. * @see UE.dom.Range:setStartAfter(Node)
  5036. * @return { UE.dom.Range } 当前range对象
  5037. */
  5038. setStartBefore: function(node) {
  5039. return this.setStart(node.parentNode, domUtils.getNodeIndex(node));
  5040. },
  5041. /**
  5042. * 将Range结束位置设置到node节点之后
  5043. * @method setEndAfter
  5044. * @remind 该操作将会把给定节点的父节点作为range的结束容器, 且偏移量是该节点在其父节点中的位置索引+1
  5045. * @param { Node } node 目标节点
  5046. * @see UE.dom.Range:setStartAfter(Node)
  5047. * @return { UE.dom.Range } 当前range对象
  5048. * @example
  5049. * ```html
  5050. * <!-- 选区示例 -->
  5051. * <b>[xx<i>xxx</i><span>xx]x</span>xxx</b>
  5052. *
  5053. * <script>
  5054. *
  5055. * //执行操作
  5056. * range.setStartAfter( document.getElementsByTagName("span")[0] );
  5057. *
  5058. * //结果选区
  5059. * //<b>[xx<i>xxx</i><span>xxx</span>]xxx</b>
  5060. *
  5061. * </script>
  5062. * ```
  5063. */
  5064. setEndAfter: function(node) {
  5065. return this.setEnd(node.parentNode, domUtils.getNodeIndex(node) + 1);
  5066. },
  5067. /**
  5068. * 将Range结束位置设置到node节点之前
  5069. * @method setEndBefore
  5070. * @remind 该操作将会把给定节点的父节点作为range的结束容器, 且偏移量是该节点在其父节点中的位置索引
  5071. * @param { Node } node 目标节点
  5072. * @see UE.dom.Range:setEndAfter(Node)
  5073. * @return { UE.dom.Range } 当前range对象
  5074. */
  5075. setEndBefore: function(node) {
  5076. return this.setEnd(node.parentNode, domUtils.getNodeIndex(node));
  5077. },
  5078. /**
  5079. * 设置Range的开始位置到node节点内的第一个子节点之前
  5080. * @method setStartAtFirst
  5081. * @remind 选区的开始容器将变成给定的节点, 且偏移量为0
  5082. * @remind 如果给定的节点是元素节点, 则该节点必须是允许包含子节点的元素。
  5083. * @param { Node } node 目标节点
  5084. * @see UE.dom.Range:setStartBefore(Node)
  5085. * @return { UE.dom.Range } 当前range对象
  5086. * @example
  5087. * ```html
  5088. * <!-- 选区示例 -->
  5089. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  5090. *
  5091. * <script>
  5092. *
  5093. * //执行操作
  5094. * range.setStartAtFirst( document.getElementsByTagName("i")[0] );
  5095. *
  5096. * //结果选区
  5097. * //<b>xx<i>[xxx</i><span>xx]x</span>xxx</b>
  5098. *
  5099. * </script>
  5100. * ```
  5101. */
  5102. setStartAtFirst: function(node) {
  5103. return this.setStart(node, 0);
  5104. },
  5105. /**
  5106. * 设置Range的开始位置到node节点内的最后一个节点之后
  5107. * @method setStartAtLast
  5108. * @remind 选区的开始容器将变成给定的节点, 且偏移量为该节点的子节点数
  5109. * @remind 如果给定的节点是元素节点, 则该节点必须是允许包含子节点的元素。
  5110. * @param { Node } node 目标节点
  5111. * @see UE.dom.Range:setStartAtFirst(Node)
  5112. * @return { UE.dom.Range } 当前range对象
  5113. */
  5114. setStartAtLast: function(node) {
  5115. return this.setStart(
  5116. node,
  5117. node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length
  5118. );
  5119. },
  5120. /**
  5121. * 设置Range的结束位置到node节点内的第一个节点之前
  5122. * @method setEndAtFirst
  5123. * @param { Node } node 目标节点
  5124. * @remind 选区的结束容器将变成给定的节点, 且偏移量为0
  5125. * @remind node必须是一个元素节点, 且必须是允许包含子节点的元素。
  5126. * @see UE.dom.Range:setStartAtFirst(Node)
  5127. * @return { UE.dom.Range } 当前range对象
  5128. */
  5129. setEndAtFirst: function(node) {
  5130. return this.setEnd(node, 0);
  5131. },
  5132. /**
  5133. * 设置Range的结束位置到node节点内的最后一个节点之后
  5134. * @method setEndAtLast
  5135. * @param { Node } node 目标节点
  5136. * @remind 选区的结束容器将变成给定的节点, 且偏移量为该节点的子节点数量
  5137. * @remind node必须是一个元素节点, 且必须是允许包含子节点的元素。
  5138. * @see UE.dom.Range:setStartAtFirst(Node)
  5139. * @return { UE.dom.Range } 当前range对象
  5140. */
  5141. setEndAtLast: function(node) {
  5142. return this.setEnd(
  5143. node,
  5144. node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length
  5145. );
  5146. },
  5147. /**
  5148. * 选中给定节点
  5149. * @method selectNode
  5150. * @remind 此时, 选区的开始容器和结束容器都是该节点的父节点, 其startOffset是该节点在父节点中的位置索引,
  5151. * 而endOffset为startOffset+1
  5152. * @param { Node } node 需要选中的节点
  5153. * @return { UE.dom.Range } 当前range对象,此时的range仅包含当前给定的节点对象
  5154. * @example
  5155. * ```html
  5156. * <!-- 选区示例 -->
  5157. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  5158. *
  5159. * <script>
  5160. *
  5161. * //执行操作
  5162. * range.selectNode( document.getElementsByTagName("i")[0] );
  5163. *
  5164. * //结果选区
  5165. * //<b>xx[<i>xxx</i>]<span>xxx</span>xxx</b>
  5166. *
  5167. * </script>
  5168. * ```
  5169. */
  5170. selectNode: function(node) {
  5171. return this.setStartBefore(node).setEndAfter(node);
  5172. },
  5173. /**
  5174. * 选中给定节点内部的所有节点
  5175. * @method selectNodeContents
  5176. * @remind 此时, 选区的开始容器和结束容器都是该节点, 其startOffset为0,
  5177. * 而endOffset是该节点的子节点数。
  5178. * @param { Node } node 目标节点, 当前range将包含该节点内的所有节点
  5179. * @return { UE.dom.Range } 当前range对象, 此时range仅包含给定节点的所有子节点
  5180. * @example
  5181. * ```html
  5182. * <!-- 选区示例 -->
  5183. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  5184. *
  5185. * <script>
  5186. *
  5187. * //执行操作
  5188. * range.selectNode( document.getElementsByTagName("b")[0] );
  5189. *
  5190. * //结果选区
  5191. * //<b>[xx<i>xxx</i><span>xxx</span>xxx]</b>
  5192. *
  5193. * </script>
  5194. * ```
  5195. */
  5196. selectNodeContents: function(node) {
  5197. return this.setStart(node, 0).setEndAtLast(node);
  5198. },
  5199. /**
  5200. * clone当前Range对象
  5201. * @method cloneRange
  5202. * @remind 返回的range是一个全新的range对象, 其内部所有属性与当前被clone的range相同。
  5203. * @return { UE.dom.Range } 当前range对象的一个副本
  5204. */
  5205. cloneRange: function() {
  5206. var me = this;
  5207. return new Range(me.document)
  5208. .setStart(me.startContainer, me.startOffset)
  5209. .setEnd(me.endContainer, me.endOffset);
  5210. },
  5211. /**
  5212. * 向当前选区的结束处闭合选区
  5213. * @method collapse
  5214. * @return { UE.dom.Range } 当前range对象
  5215. * @example
  5216. * ```html
  5217. * <!-- 选区示例 -->
  5218. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  5219. *
  5220. * <script>
  5221. *
  5222. * //执行操作
  5223. * range.collapse();
  5224. *
  5225. * //结果选区
  5226. * //“|”表示选区已闭合
  5227. * //<b>xx<i>xxx</i><span>xx|x</span>xxx</b>
  5228. *
  5229. * </script>
  5230. * ```
  5231. */
  5232. /**
  5233. * 闭合当前选区,根据给定的toStart参数项决定是向当前选区开始处闭合还是向结束处闭合,
  5234. * 如果toStart的值为true,则向开始位置闭合, 反之,向结束位置闭合。
  5235. * @method collapse
  5236. * @param { Boolean } toStart 是否向选区开始处闭合
  5237. * @return { UE.dom.Range } 当前range对象,此时range对象处于闭合状态
  5238. * @see UE.dom.Range:collapse()
  5239. * @example
  5240. * ```html
  5241. * <!-- 选区示例 -->
  5242. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  5243. *
  5244. * <script>
  5245. *
  5246. * //执行操作
  5247. * range.collapse( true );
  5248. *
  5249. * //结果选区
  5250. * //“|”表示选区已闭合
  5251. * //<b>xx<i>xxx</i><span>|xxx</span>xxx</b>
  5252. *
  5253. * </script>
  5254. * ```
  5255. */
  5256. collapse: function(toStart) {
  5257. var me = this;
  5258. if (toStart) {
  5259. me.endContainer = me.startContainer;
  5260. me.endOffset = me.startOffset;
  5261. } else {
  5262. me.startContainer = me.endContainer;
  5263. me.startOffset = me.endOffset;
  5264. }
  5265. me.collapsed = true;
  5266. return me;
  5267. },
  5268. /**
  5269. * 调整range的开始位置和结束位置,使其"收缩"到最小的位置
  5270. * @method shrinkBoundary
  5271. * @return { UE.dom.Range } 当前range对象
  5272. * @example
  5273. * ```html
  5274. * <span>xx<b>xx[</b>xxxxx]</span> => <span>xx<b>xx</b>[xxxxx]</span>
  5275. * ```
  5276. *
  5277. * @example
  5278. * ```html
  5279. * <!-- 选区示例 -->
  5280. * <b>x[xx</b><i>]xxx</i>
  5281. *
  5282. * <script>
  5283. *
  5284. * //执行收缩
  5285. * range.shrinkBoundary();
  5286. *
  5287. * //结果选区
  5288. * //<b>x[xx]</b><i>xxx</i>
  5289. * </script>
  5290. * ```
  5291. *
  5292. * @example
  5293. * ```html
  5294. * [<b><i>xxxx</i>xxxxxxx</b>] => <b><i>[xxxx</i>xxxxxxx]</b>
  5295. * ```
  5296. */
  5297. /**
  5298. * 调整range的开始位置和结束位置,使其"收缩"到最小的位置,
  5299. * 如果ignoreEnd的值为true,则忽略对结束位置的调整
  5300. * @method shrinkBoundary
  5301. * @param { Boolean } ignoreEnd 是否忽略对结束位置的调整
  5302. * @return { UE.dom.Range } 当前range对象
  5303. * @see UE.dom.domUtils.Range:shrinkBoundary()
  5304. */
  5305. shrinkBoundary: function(ignoreEnd) {
  5306. var me = this,
  5307. child,
  5308. collapsed = me.collapsed;
  5309. function check(node) {
  5310. return (
  5311. node.nodeType == 1 &&
  5312. !domUtils.isBookmarkNode(node) &&
  5313. !dtd.$empty[node.tagName] &&
  5314. !dtd.$nonChild[node.tagName]
  5315. );
  5316. }
  5317. while (
  5318. me.startContainer.nodeType == 1 && //是element
  5319. (child = me.startContainer.childNodes[me.startOffset]) && //子节点也是element
  5320. check(child)
  5321. ) {
  5322. me.setStart(child, 0);
  5323. }
  5324. if (collapsed) {
  5325. return me.collapse(true);
  5326. }
  5327. if (!ignoreEnd) {
  5328. while (
  5329. me.endContainer.nodeType == 1 && //是element
  5330. me.endOffset > 0 && //如果是空元素就退出 endOffset=0那么endOffst-1为负值,childNodes[endOffset]报错
  5331. (child = me.endContainer.childNodes[me.endOffset - 1]) && //子节点也是element
  5332. check(child)
  5333. ) {
  5334. me.setEnd(child, child.childNodes.length);
  5335. }
  5336. }
  5337. return me;
  5338. },
  5339. /**
  5340. * 获取离当前选区内包含的所有节点最近的公共祖先节点,
  5341. * @method getCommonAncestor
  5342. * @remind 返回的公共祖先节点一定不是range自身的容器节点, 但有可能是一个文本节点
  5343. * @return { Node } 当前range对象内所有节点的公共祖先节点
  5344. * @example
  5345. * ```html
  5346. * //选区示例
  5347. * <span>xxx<b>x[x<em>xx]x</em>xxx</b>xx</span>
  5348. * <script>
  5349. *
  5350. * var node = range.getCommonAncestor();
  5351. *
  5352. * //公共祖先节点是: b节点
  5353. * //输出: B
  5354. * console.log(node.tagName);
  5355. *
  5356. * </script>
  5357. * ```
  5358. */
  5359. /**
  5360. * 获取当前选区所包含的所有节点的公共祖先节点, 可以根据给定的参数 includeSelf 决定获取到
  5361. * 的公共祖先节点是否可以是当前选区的startContainer或endContainer节点, 如果 includeSelf
  5362. * 的取值为true, 则返回的节点可以是自身的容器节点, 否则, 则不能是容器节点
  5363. * @method getCommonAncestor
  5364. * @param { Boolean } includeSelf 是否允许获取到的公共祖先节点是当前range对象的容器节点
  5365. * @return { Node } 当前range对象内所有节点的公共祖先节点
  5366. * @see UE.dom.Range:getCommonAncestor()
  5367. * @example
  5368. * ```html
  5369. * <body>
  5370. *
  5371. * <!-- 选区示例 -->
  5372. * <b>xxx<i>xxxx<span>xx[x</span>xx]x</i>xxxxxxx</b>
  5373. *
  5374. * <script>
  5375. *
  5376. * var node = range.getCommonAncestor( false );
  5377. *
  5378. * //这里的公共祖先节点是B而不是I, 是因为参数限制了获取到的节点不能是容器节点
  5379. * //output: B
  5380. * console.log( node.tagName );
  5381. *
  5382. * </script>
  5383. *
  5384. * </body>
  5385. * ```
  5386. */
  5387. /**
  5388. * 获取当前选区所包含的所有节点的公共祖先节点, 可以根据给定的参数 includeSelf 决定获取到
  5389. * 的公共祖先节点是否可以是当前选区的startContainer或endContainer节点, 如果 includeSelf
  5390. * 的取值为true, 则返回的节点可以是自身的容器节点, 否则, 则不能是容器节点; 同时可以根据
  5391. * ignoreTextNode 参数的取值决定是否忽略类型为文本节点的祖先节点。
  5392. * @method getCommonAncestor
  5393. * @param { Boolean } includeSelf 是否允许获取到的公共祖先节点是当前range对象的容器节点
  5394. * @param { Boolean } ignoreTextNode 获取祖先节点的过程中是否忽略类型为文本节点的祖先节点
  5395. * @return { Node } 当前range对象内所有节点的公共祖先节点
  5396. * @see UE.dom.Range:getCommonAncestor()
  5397. * @see UE.dom.Range:getCommonAncestor(Boolean)
  5398. * @example
  5399. * ```html
  5400. * <body>
  5401. *
  5402. * <!-- 选区示例 -->
  5403. * <b>xxx<i>xxxx<span>x[x]x</span>xxx</i>xxxxxxx</b>
  5404. *
  5405. * <script>
  5406. *
  5407. * var node = range.getCommonAncestor( true, false );
  5408. *
  5409. * //output: SPAN
  5410. * console.log( node.tagName );
  5411. *
  5412. * </script>
  5413. *
  5414. * </body>
  5415. * ```
  5416. */
  5417. getCommonAncestor: function(includeSelf, ignoreTextNode) {
  5418. var me = this,
  5419. start = me.startContainer,
  5420. end = me.endContainer;
  5421. if (start === end) {
  5422. if (includeSelf && selectOneNode(this)) {
  5423. start = start.childNodes[me.startOffset];
  5424. if (start.nodeType == 1) return start;
  5425. }
  5426. //只有在上来就相等的情况下才会出现是文本的情况
  5427. return ignoreTextNode && start.nodeType == 3 ? start.parentNode : start;
  5428. }
  5429. return domUtils.getCommonAncestor(start, end);
  5430. },
  5431. /**
  5432. * 调整当前Range的开始和结束边界容器,如果是容器节点是文本节点,就调整到包含该文本节点的父节点上
  5433. * @method trimBoundary
  5434. * @remind 该操作有可能会引起文本节点被切开
  5435. * @return { UE.dom.Range } 当前range对象
  5436. * @example
  5437. * ```html
  5438. *
  5439. * //选区示例
  5440. * <b>xxx<i>[xxxxx]</i>xxx</b>
  5441. *
  5442. * <script>
  5443. * //未调整前, 选区的开始容器和结束都是文本节点
  5444. * //执行调整
  5445. * range.trimBoundary();
  5446. *
  5447. * //调整之后, 容器节点变成了i节点
  5448. * //<b>xxx[<i>xxxxx</i>]xxx</b>
  5449. * </script>
  5450. * ```
  5451. */
  5452. /**
  5453. * 调整当前Range的开始和结束边界容器,如果是容器节点是文本节点,就调整到包含该文本节点的父节点上,
  5454. * 可以根据 ignoreEnd 参数的值决定是否调整对结束边界的调整
  5455. * @method trimBoundary
  5456. * @param { Boolean } ignoreEnd 是否忽略对结束边界的调整
  5457. * @return { UE.dom.Range } 当前range对象
  5458. * @example
  5459. * ```html
  5460. *
  5461. * //选区示例
  5462. * <b>xxx<i>[xxxxx]</i>xxx</b>
  5463. *
  5464. * <script>
  5465. * //未调整前, 选区的开始容器和结束都是文本节点
  5466. * //执行调整
  5467. * range.trimBoundary( true );
  5468. *
  5469. * //调整之后, 开始容器节点变成了i节点
  5470. * //但是, 结束容器没有发生变化
  5471. * //<b>xxx[<i>xxxxx]</i>xxx</b>
  5472. * </script>
  5473. * ```
  5474. */
  5475. trimBoundary: function(ignoreEnd) {
  5476. this.txtToElmBoundary();
  5477. var start = this.startContainer,
  5478. offset = this.startOffset,
  5479. collapsed = this.collapsed,
  5480. end = this.endContainer;
  5481. if (start.nodeType == 3) {
  5482. if (offset == 0) {
  5483. this.setStartBefore(start);
  5484. } else {
  5485. if (offset >= start.nodeValue.length) {
  5486. this.setStartAfter(start);
  5487. } else {
  5488. var textNode = domUtils.split(start, offset);
  5489. //跟新结束边界
  5490. if (start === end) {
  5491. this.setEnd(textNode, this.endOffset - offset);
  5492. } else if (start.parentNode === end) {
  5493. this.endOffset += 1;
  5494. }
  5495. this.setStartBefore(textNode);
  5496. }
  5497. }
  5498. if (collapsed) {
  5499. return this.collapse(true);
  5500. }
  5501. }
  5502. if (!ignoreEnd) {
  5503. offset = this.endOffset;
  5504. end = this.endContainer;
  5505. if (end.nodeType == 3) {
  5506. if (offset == 0) {
  5507. this.setEndBefore(end);
  5508. } else {
  5509. offset < end.nodeValue.length && domUtils.split(end, offset);
  5510. this.setEndAfter(end);
  5511. }
  5512. }
  5513. }
  5514. return this;
  5515. },
  5516. /**
  5517. * 如果选区在文本的边界上,就扩展选区到文本的父节点上, 如果当前选区是闭合的, 则什么也不做
  5518. * @method txtToElmBoundary
  5519. * @remind 该操作不会修改dom节点
  5520. * @return { UE.dom.Range } 当前range对象
  5521. */
  5522. /**
  5523. * 如果选区在文本的边界上,就扩展选区到文本的父节点上, 如果当前选区是闭合的, 则根据参数项
  5524. * ignoreCollapsed 的值决定是否执行该调整
  5525. * @method txtToElmBoundary
  5526. * @param { Boolean } ignoreCollapsed 是否忽略选区的闭合状态, 如果该参数取值为true, 则
  5527. * 不论选区是否闭合, 都会执行该操作, 反之, 则不会对闭合的选区执行该操作
  5528. * @return { UE.dom.Range } 当前range对象
  5529. */
  5530. txtToElmBoundary: function(ignoreCollapsed) {
  5531. function adjust(r, c) {
  5532. var container = r[c + "Container"],
  5533. offset = r[c + "Offset"];
  5534. if (container.nodeType == 3) {
  5535. if (!offset) {
  5536. r[
  5537. "set" +
  5538. c.replace(/(\w)/, function(a) {
  5539. return a.toUpperCase();
  5540. }) +
  5541. "Before"
  5542. ](container);
  5543. } else if (offset >= container.nodeValue.length) {
  5544. r[
  5545. "set" +
  5546. c.replace(/(\w)/, function(a) {
  5547. return a.toUpperCase();
  5548. }) +
  5549. "After"
  5550. ](container);
  5551. }
  5552. }
  5553. }
  5554. if (ignoreCollapsed || !this.collapsed) {
  5555. adjust(this, "start");
  5556. adjust(this, "end");
  5557. }
  5558. return this;
  5559. },
  5560. /**
  5561. * 在当前选区的开始位置前插入节点,新插入的节点会被该range包含
  5562. * @method insertNode
  5563. * @param { Node } node 需要插入的节点
  5564. * @remind 插入的节点可以是一个DocumentFragment依次插入多个节点
  5565. * @return { UE.dom.Range } 当前range对象
  5566. */
  5567. insertNode: function(node) {
  5568. var first = node,
  5569. length = 1;
  5570. if (node.nodeType == 11) {
  5571. first = node.firstChild;
  5572. length = node.childNodes.length;
  5573. }
  5574. this.trimBoundary(true);
  5575. var start = this.startContainer,
  5576. offset = this.startOffset;
  5577. var nextNode = start.childNodes[offset];
  5578. if (nextNode) {
  5579. start.insertBefore(node, nextNode);
  5580. } else {
  5581. start.appendChild(node);
  5582. }
  5583. if (first.parentNode === this.endContainer) {
  5584. this.endOffset = this.endOffset + length;
  5585. }
  5586. return this.setStartBefore(first);
  5587. },
  5588. /**
  5589. * 闭合选区到当前选区的开始位置, 并且定位光标到闭合后的位置
  5590. * @method setCursor
  5591. * @return { UE.dom.Range } 当前range对象
  5592. * @see UE.dom.Range:collapse()
  5593. */
  5594. /**
  5595. * 闭合选区,可以根据参数toEnd的值控制选区是向前闭合还是向后闭合, 并且定位光标到闭合后的位置。
  5596. * @method setCursor
  5597. * @param { Boolean } toEnd 是否向后闭合, 如果为true, 则闭合选区时, 将向结束容器方向闭合,
  5598. * 反之,则向开始容器方向闭合
  5599. * @return { UE.dom.Range } 当前range对象
  5600. * @see UE.dom.Range:collapse(Boolean)
  5601. */
  5602. setCursor: function(toEnd, noFillData) {
  5603. return this.collapse(!toEnd).select(noFillData);
  5604. },
  5605. /**
  5606. * 创建当前range的一个书签,记录下当前range的位置,方便当dom树改变时,还能找回原来的选区位置
  5607. * @method createBookmark
  5608. * @param { Boolean } serialize 控制返回的标记位置是对当前位置的引用还是ID,如果该值为true,则
  5609. * 返回标记位置的ID, 反之则返回标记位置节点的引用
  5610. * @return { Object } 返回一个书签记录键值对, 其包含的key有: start => 开始标记的ID或者引用,
  5611. * end => 结束标记的ID或引用, id => 当前标记的类型, 如果为true,则表示
  5612. * 返回的记录的类型为ID, 反之则为引用
  5613. */
  5614. createBookmark: function(serialize, same) {
  5615. var endNode,
  5616. startNode = this.document.createElement("span");
  5617. startNode.style.cssText = "display:none;line-height:0px;";
  5618. startNode.appendChild(this.document.createTextNode("\u200D"));
  5619. startNode.id = "_baidu_bookmark_start_" + (same ? "" : guid++);
  5620. if (!this.collapsed) {
  5621. endNode = startNode.cloneNode(true);
  5622. endNode.id = "_baidu_bookmark_end_" + (same ? "" : guid++);
  5623. }
  5624. this.insertNode(startNode);
  5625. if (endNode) {
  5626. this.collapse().insertNode(endNode).setEndBefore(endNode);
  5627. }
  5628. this.setStartAfter(startNode);
  5629. return {
  5630. start: serialize ? startNode.id : startNode,
  5631. end: endNode ? (serialize ? endNode.id : endNode) : null,
  5632. id: serialize
  5633. };
  5634. },
  5635. /**
  5636. * 调整当前range的边界到书签位置,并删除该书签对象所标记的位置内的节点
  5637. * @method moveToBookmark
  5638. * @param { BookMark } bookmark createBookmark所创建的标签对象
  5639. * @return { UE.dom.Range } 当前range对象
  5640. * @see UE.dom.Range:createBookmark(Boolean)
  5641. */
  5642. moveToBookmark: function(bookmark) {
  5643. var start = bookmark.id
  5644. ? this.document.getElementById(bookmark.start)
  5645. : bookmark.start,
  5646. end = bookmark.end && bookmark.id
  5647. ? this.document.getElementById(bookmark.end)
  5648. : bookmark.end;
  5649. this.setStartBefore(start);
  5650. domUtils.remove(start);
  5651. if (end) {
  5652. this.setEndBefore(end);
  5653. domUtils.remove(end);
  5654. } else {
  5655. this.collapse(true);
  5656. }
  5657. return this;
  5658. },
  5659. /**
  5660. * 调整range的边界,使其"放大"到最近的父节点
  5661. * @method enlarge
  5662. * @remind 会引起选区的变化
  5663. * @return { UE.dom.Range } 当前range对象
  5664. */
  5665. /**
  5666. * 调整range的边界,使其"放大"到最近的父节点,根据参数 toBlock 的取值, 可以
  5667. * 要求扩大之后的父节点是block节点
  5668. * @method enlarge
  5669. * @param { Boolean } toBlock 是否要求扩大之后的父节点必须是block节点
  5670. * @return { UE.dom.Range } 当前range对象
  5671. */
  5672. enlarge: function(toBlock, stopFn) {
  5673. var isBody = domUtils.isBody,
  5674. pre,
  5675. node,
  5676. tmp = this.document.createTextNode("");
  5677. if (toBlock) {
  5678. node = this.startContainer;
  5679. if (node.nodeType == 1) {
  5680. if (node.childNodes[this.startOffset]) {
  5681. pre = node = node.childNodes[this.startOffset];
  5682. } else {
  5683. node.appendChild(tmp);
  5684. pre = node = tmp;
  5685. }
  5686. } else {
  5687. pre = node;
  5688. }
  5689. while (1) {
  5690. if (domUtils.isBlockElm(node)) {
  5691. node = pre;
  5692. while ((pre = node.previousSibling) && !domUtils.isBlockElm(pre)) {
  5693. node = pre;
  5694. }
  5695. this.setStartBefore(node);
  5696. break;
  5697. }
  5698. pre = node;
  5699. node = node.parentNode;
  5700. }
  5701. node = this.endContainer;
  5702. if (node.nodeType == 1) {
  5703. if ((pre = node.childNodes[this.endOffset])) {
  5704. node.insertBefore(tmp, pre);
  5705. } else {
  5706. node.appendChild(tmp);
  5707. }
  5708. pre = node = tmp;
  5709. } else {
  5710. pre = node;
  5711. }
  5712. while (1) {
  5713. if (domUtils.isBlockElm(node)) {
  5714. node = pre;
  5715. while ((pre = node.nextSibling) && !domUtils.isBlockElm(pre)) {
  5716. node = pre;
  5717. }
  5718. this.setEndAfter(node);
  5719. break;
  5720. }
  5721. pre = node;
  5722. node = node.parentNode;
  5723. }
  5724. if (tmp.parentNode === this.endContainer) {
  5725. this.endOffset--;
  5726. }
  5727. domUtils.remove(tmp);
  5728. }
  5729. // 扩展边界到最大
  5730. if (!this.collapsed) {
  5731. while (this.startOffset == 0) {
  5732. if (stopFn && stopFn(this.startContainer)) {
  5733. break;
  5734. }
  5735. if (isBody(this.startContainer)) {
  5736. break;
  5737. }
  5738. this.setStartBefore(this.startContainer);
  5739. }
  5740. while (
  5741. this.endOffset ==
  5742. (this.endContainer.nodeType == 1
  5743. ? this.endContainer.childNodes.length
  5744. : this.endContainer.nodeValue.length)
  5745. ) {
  5746. if (stopFn && stopFn(this.endContainer)) {
  5747. break;
  5748. }
  5749. if (isBody(this.endContainer)) {
  5750. break;
  5751. }
  5752. this.setEndAfter(this.endContainer);
  5753. }
  5754. }
  5755. return this;
  5756. },
  5757. enlargeToBlockElm: function(ignoreEnd) {
  5758. while (!domUtils.isBlockElm(this.startContainer)) {
  5759. this.setStartBefore(this.startContainer);
  5760. }
  5761. if (!ignoreEnd) {
  5762. while (!domUtils.isBlockElm(this.endContainer)) {
  5763. this.setEndAfter(this.endContainer);
  5764. }
  5765. }
  5766. return this;
  5767. },
  5768. /**
  5769. * 调整Range的边界,使其"缩小"到最合适的位置
  5770. * @method adjustmentBoundary
  5771. * @return { UE.dom.Range } 当前range对象
  5772. * @see UE.dom.Range:shrinkBoundary()
  5773. */
  5774. adjustmentBoundary: function() {
  5775. if (!this.collapsed) {
  5776. while (
  5777. !domUtils.isBody(this.startContainer) &&
  5778. this.startOffset ==
  5779. this.startContainer[
  5780. this.startContainer.nodeType == 3 ? "nodeValue" : "childNodes"
  5781. ].length &&
  5782. this.startContainer[
  5783. this.startContainer.nodeType == 3 ? "nodeValue" : "childNodes"
  5784. ].length
  5785. ) {
  5786. this.setStartAfter(this.startContainer);
  5787. }
  5788. while (
  5789. !domUtils.isBody(this.endContainer) &&
  5790. !this.endOffset &&
  5791. this.endContainer[
  5792. this.endContainer.nodeType == 3 ? "nodeValue" : "childNodes"
  5793. ].length
  5794. ) {
  5795. this.setEndBefore(this.endContainer);
  5796. }
  5797. }
  5798. return this;
  5799. },
  5800. /**
  5801. * 给range选区中的内容添加给定的inline标签
  5802. * @method applyInlineStyle
  5803. * @param { String } tagName 需要添加的标签名
  5804. * @example
  5805. * ```html
  5806. * <p>xxxx[xxxx]x</p> ==> range.applyInlineStyle("strong") ==> <p>xxxx[<strong>xxxx</strong>]x</p>
  5807. * ```
  5808. */
  5809. /**
  5810. * 给range选区中的内容添加给定的inline标签, 并且为标签附加上一些初始化属性。
  5811. * @method applyInlineStyle
  5812. * @param { String } tagName 需要添加的标签名
  5813. * @param { Object } attrs 跟随新添加的标签的属性
  5814. * @return { UE.dom.Range } 当前选区
  5815. * @example
  5816. * ```html
  5817. * <p>xxxx[xxxx]x</p>
  5818. *
  5819. * ==>
  5820. *
  5821. * <!-- 执行操作 -->
  5822. * range.applyInlineStyle("strong",{"style":"font-size:12px"})
  5823. *
  5824. * ==>
  5825. *
  5826. * <p>xxxx[<strong style="font-size:12px">xxxx</strong>]x</p>
  5827. * ```
  5828. */
  5829. applyInlineStyle: function(tagName, attrs, list) {
  5830. if (this.collapsed) return this;
  5831. this.trimBoundary()
  5832. .enlarge(false, function(node) {
  5833. return node.nodeType == 1 && domUtils.isBlockElm(node);
  5834. })
  5835. .adjustmentBoundary();
  5836. var bookmark = this.createBookmark(),
  5837. end = bookmark.end,
  5838. filterFn = function(node) {
  5839. return node.nodeType == 1
  5840. ? node.tagName.toLowerCase() != "br"
  5841. : !domUtils.isWhitespace(node);
  5842. },
  5843. current = domUtils.getNextDomNode(bookmark.start, false, filterFn),
  5844. node,
  5845. pre,
  5846. range = this.cloneRange();
  5847. while (
  5848. current &&
  5849. domUtils.getPosition(current, end) & domUtils.POSITION_PRECEDING
  5850. ) {
  5851. if (current.nodeType == 3 || dtd[tagName][current.tagName]) {
  5852. range.setStartBefore(current);
  5853. node = current;
  5854. while (
  5855. node &&
  5856. (node.nodeType == 3 || dtd[tagName][node.tagName]) &&
  5857. node !== end
  5858. ) {
  5859. pre = node;
  5860. node = domUtils.getNextDomNode(
  5861. node,
  5862. node.nodeType == 1,
  5863. null,
  5864. function(parent) {
  5865. return dtd[tagName][parent.tagName];
  5866. }
  5867. );
  5868. }
  5869. var frag = range.setEndAfter(pre).extractContents(),
  5870. elm;
  5871. if (list && list.length > 0) {
  5872. var level, top;
  5873. top = level = list[0].cloneNode(false);
  5874. for (var i = 1, ci; (ci = list[i++]); ) {
  5875. level.appendChild(ci.cloneNode(false));
  5876. level = level.firstChild;
  5877. }
  5878. elm = level;
  5879. } else {
  5880. elm = range.document.createElement(tagName);
  5881. }
  5882. if (attrs) {
  5883. domUtils.setAttributes(elm, attrs);
  5884. }
  5885. elm.appendChild(frag);
  5886. //针对嵌套span的全局样式指定,做容错处理
  5887. if (elm.tagName == "SPAN" && attrs && attrs.style) {
  5888. utils.each(elm.getElementsByTagName("span"), function(s) {
  5889. s.style.cssText = s.style.cssText + ";" + attrs.style;
  5890. });
  5891. }
  5892. range.insertNode(list ? top : elm);
  5893. //处理下滑线在a上的情况
  5894. var aNode;
  5895. if (
  5896. tagName == "span" &&
  5897. attrs.style &&
  5898. /text\-decoration/.test(attrs.style) &&
  5899. (aNode = domUtils.findParentByTagName(elm, "a", true))
  5900. ) {
  5901. domUtils.setAttributes(aNode, attrs);
  5902. domUtils.remove(elm, true);
  5903. elm = aNode;
  5904. } else {
  5905. domUtils.mergeSibling(elm);
  5906. domUtils.clearEmptySibling(elm);
  5907. }
  5908. //去除子节点相同的
  5909. domUtils.mergeChild(elm, attrs);
  5910. current = domUtils.getNextDomNode(elm, false, filterFn);
  5911. domUtils.mergeToParent(elm);
  5912. if (node === end) {
  5913. break;
  5914. }
  5915. } else {
  5916. current = domUtils.getNextDomNode(current, true, filterFn);
  5917. }
  5918. }
  5919. return this.moveToBookmark(bookmark);
  5920. },
  5921. /**
  5922. * 移除当前选区内指定的inline标签,但保留其中的内容
  5923. * @method removeInlineStyle
  5924. * @param { String } tagName 需要移除的标签名
  5925. * @return { UE.dom.Range } 当前的range对象
  5926. * @example
  5927. * ```html
  5928. * xx[x<span>xxx<em>yyy</em>zz]z</span> => range.removeInlineStyle(["em"]) => xx[x<span>xxxyyyzz]z</span>
  5929. * ```
  5930. */
  5931. /**
  5932. * 移除当前选区内指定的一组inline标签,但保留其中的内容
  5933. * @method removeInlineStyle
  5934. * @param { Array } tagNameArr 需要移除的标签名的数组
  5935. * @return { UE.dom.Range } 当前的range对象
  5936. * @see UE.dom.Range:removeInlineStyle(String)
  5937. */
  5938. removeInlineStyle: function(tagNames) {
  5939. if (this.collapsed) return this;
  5940. tagNames = utils.isArray(tagNames) ? tagNames : [tagNames];
  5941. this.shrinkBoundary().adjustmentBoundary();
  5942. var start = this.startContainer,
  5943. end = this.endContainer;
  5944. while (1) {
  5945. if (start.nodeType == 1) {
  5946. if (utils.indexOf(tagNames, start.tagName.toLowerCase()) > -1) {
  5947. break;
  5948. }
  5949. if (start.tagName.toLowerCase() == "body") {
  5950. start = null;
  5951. break;
  5952. }
  5953. }
  5954. start = start.parentNode;
  5955. }
  5956. while (1) {
  5957. if (end.nodeType == 1) {
  5958. if (utils.indexOf(tagNames, end.tagName.toLowerCase()) > -1) {
  5959. break;
  5960. }
  5961. if (end.tagName.toLowerCase() == "body") {
  5962. end = null;
  5963. break;
  5964. }
  5965. }
  5966. end = end.parentNode;
  5967. }
  5968. var bookmark = this.createBookmark(),
  5969. frag,
  5970. tmpRange;
  5971. if (start) {
  5972. tmpRange = this.cloneRange()
  5973. .setEndBefore(bookmark.start)
  5974. .setStartBefore(start);
  5975. frag = tmpRange.extractContents();
  5976. tmpRange.insertNode(frag);
  5977. domUtils.clearEmptySibling(start, true);
  5978. start.parentNode.insertBefore(bookmark.start, start);
  5979. }
  5980. if (end) {
  5981. tmpRange = this.cloneRange()
  5982. .setStartAfter(bookmark.end)
  5983. .setEndAfter(end);
  5984. frag = tmpRange.extractContents();
  5985. tmpRange.insertNode(frag);
  5986. domUtils.clearEmptySibling(end, false, true);
  5987. end.parentNode.insertBefore(bookmark.end, end.nextSibling);
  5988. }
  5989. var current = domUtils.getNextDomNode(bookmark.start, false, function(
  5990. node
  5991. ) {
  5992. return node.nodeType == 1;
  5993. }),
  5994. next;
  5995. while (current && current !== bookmark.end) {
  5996. next = domUtils.getNextDomNode(current, true, function(node) {
  5997. return node.nodeType == 1;
  5998. });
  5999. if (utils.indexOf(tagNames, current.tagName.toLowerCase()) > -1) {
  6000. domUtils.remove(current, true);
  6001. }
  6002. current = next;
  6003. }
  6004. return this.moveToBookmark(bookmark);
  6005. },
  6006. /**
  6007. * 获取当前选中的自闭合的节点
  6008. * @method getClosedNode
  6009. * @return { Node | NULL } 如果当前选中的是自闭合节点, 则返回该节点, 否则返回NULL
  6010. */
  6011. getClosedNode: function() {
  6012. var node;
  6013. if (!this.collapsed) {
  6014. var range = this.cloneRange().adjustmentBoundary().shrinkBoundary();
  6015. if (selectOneNode(range)) {
  6016. var child = range.startContainer.childNodes[range.startOffset];
  6017. if (
  6018. child &&
  6019. child.nodeType == 1 &&
  6020. (dtd.$empty[child.tagName] || dtd.$nonChild[child.tagName])
  6021. ) {
  6022. node = child;
  6023. }
  6024. }
  6025. }
  6026. return node;
  6027. },
  6028. /**
  6029. * 在页面上高亮range所表示的选区
  6030. * @method select
  6031. * @return { UE.dom.Range } 返回当前Range对象
  6032. */
  6033. //这里不区分ie9以上,trace:3824
  6034. select: browser.ie
  6035. ? function(noFillData, textRange) {
  6036. var nativeRange;
  6037. if (!this.collapsed) this.shrinkBoundary();
  6038. var node = this.getClosedNode();
  6039. if (node && !textRange) {
  6040. try {
  6041. nativeRange = this.document.body.createControlRange();
  6042. nativeRange.addElement(node);
  6043. nativeRange.select();
  6044. } catch (e) {}
  6045. return this;
  6046. }
  6047. var bookmark = this.createBookmark(),
  6048. start = bookmark.start,
  6049. end;
  6050. nativeRange = this.document.body.createTextRange();
  6051. nativeRange.moveToElementText(start);
  6052. nativeRange.moveStart("character", 1);
  6053. if (!this.collapsed) {
  6054. var nativeRangeEnd = this.document.body.createTextRange();
  6055. end = bookmark.end;
  6056. nativeRangeEnd.moveToElementText(end);
  6057. nativeRange.setEndPoint("EndToEnd", nativeRangeEnd);
  6058. } else {
  6059. if (!noFillData && this.startContainer.nodeType != 3) {
  6060. //使用<span>|x<span>固定住光标
  6061. var tmpText = this.document.createTextNode(fillChar),
  6062. tmp = this.document.createElement("span");
  6063. tmp.appendChild(this.document.createTextNode(fillChar));
  6064. start.parentNode.insertBefore(tmp, start);
  6065. start.parentNode.insertBefore(tmpText, start);
  6066. //当点b,i,u时,不能清除i上边的b
  6067. removeFillData(this.document, tmpText);
  6068. fillData = tmpText;
  6069. mergeSibling(tmp, "previousSibling");
  6070. mergeSibling(start, "nextSibling");
  6071. nativeRange.moveStart("character", -1);
  6072. nativeRange.collapse(true);
  6073. }
  6074. }
  6075. this.moveToBookmark(bookmark);
  6076. tmp && domUtils.remove(tmp);
  6077. //IE在隐藏状态下不支持range操作,catch一下
  6078. try {
  6079. nativeRange.select();
  6080. } catch (e) {}
  6081. return this;
  6082. }
  6083. : function(notInsertFillData) {
  6084. function checkOffset(rng) {
  6085. function check(node, offset, dir) {
  6086. if (node.nodeType == 3 && node.nodeValue.length < offset) {
  6087. rng[dir + "Offset"] = node.nodeValue.length;
  6088. }
  6089. }
  6090. check(rng.startContainer, rng.startOffset, "start");
  6091. check(rng.endContainer, rng.endOffset, "end");
  6092. }
  6093. var win = domUtils.getWindow(this.document),
  6094. sel = win.getSelection(),
  6095. txtNode;
  6096. //FF下关闭自动长高时滚动条在关闭dialog时会跳
  6097. //ff下如果不body.focus将不能定位闭合光标到编辑器内
  6098. browser.gecko ? this.document.body.focus() : win.focus();
  6099. if (sel) {
  6100. sel.removeAllRanges();
  6101. // trace:870 chrome/safari后边是br对于闭合得range不能定位 所以去掉了判断
  6102. // this.startContainer.nodeType != 3 &&! ((child = this.startContainer.childNodes[this.startOffset]) && child.nodeType == 1 && child.tagName == 'BR'
  6103. if (this.collapsed && !notInsertFillData) {
  6104. // //opear如果没有节点接着,原生的不能够定位,不能在body的第一级插入空白节点
  6105. // if (notInsertFillData && browser.opera && !domUtils.isBody(this.startContainer) && this.startContainer.nodeType == 1) {
  6106. // var tmp = this.document.createTextNode('');
  6107. // this.insertNode(tmp).setStart(tmp, 0).collapse(true);
  6108. // }
  6109. //
  6110. //处理光标落在文本节点的情况
  6111. //处理以下的情况
  6112. //<b>|xxxx</b>
  6113. //<b>xxxx</b>|xxxx
  6114. //xxxx<b>|</b>
  6115. var start = this.startContainer,
  6116. child = start;
  6117. if (start.nodeType == 1) {
  6118. child = start.childNodes[this.startOffset];
  6119. }
  6120. if (
  6121. !(start.nodeType == 3 && this.startOffset) &&
  6122. (child
  6123. ? !child.previousSibling ||
  6124. child.previousSibling.nodeType != 3
  6125. : !start.lastChild || start.lastChild.nodeType != 3)
  6126. ) {
  6127. txtNode = this.document.createTextNode(fillChar);
  6128. //跟着前边走
  6129. this.insertNode(txtNode);
  6130. removeFillData(this.document, txtNode);
  6131. mergeSibling(txtNode, "previousSibling");
  6132. mergeSibling(txtNode, "nextSibling");
  6133. fillData = txtNode;
  6134. this.setStart(txtNode, browser.webkit ? 1 : 0).collapse(true);
  6135. }
  6136. }
  6137. var nativeRange = this.document.createRange();
  6138. if (
  6139. this.collapsed &&
  6140. browser.opera &&
  6141. this.startContainer.nodeType == 1
  6142. ) {
  6143. var child = this.startContainer.childNodes[this.startOffset];
  6144. if (!child) {
  6145. //往前靠拢
  6146. child = this.startContainer.lastChild;
  6147. if (child && domUtils.isBr(child)) {
  6148. this.setStartBefore(child).collapse(true);
  6149. }
  6150. } else {
  6151. //向后靠拢
  6152. while (child && domUtils.isBlockElm(child)) {
  6153. if (child.nodeType == 1 && child.childNodes[0]) {
  6154. child = child.childNodes[0];
  6155. } else {
  6156. break;
  6157. }
  6158. }
  6159. child && this.setStartBefore(child).collapse(true);
  6160. }
  6161. }
  6162. //是createAddress最后一位算的不准,现在这里进行微调
  6163. checkOffset(this);
  6164. nativeRange.setStart(this.startContainer, this.startOffset);
  6165. nativeRange.setEnd(this.endContainer, this.endOffset);
  6166. sel.addRange(nativeRange);
  6167. }
  6168. return this;
  6169. },
  6170. /**
  6171. * 滚动到当前range开始的位置
  6172. * @method scrollToView
  6173. * @param { Window } win 当前range对象所属的window对象
  6174. * @return { UE.dom.Range } 当前Range对象
  6175. */
  6176. /**
  6177. * 滚动到距离当前range开始位置 offset 的位置处
  6178. * @method scrollToView
  6179. * @param { Window } win 当前range对象所属的window对象
  6180. * @param { Number } offset 距离range开始位置处的偏移量, 如果为正数, 则向下偏移, 反之, 则向上偏移
  6181. * @return { UE.dom.Range } 当前Range对象
  6182. */
  6183. scrollToView: function(win, offset) {
  6184. win = win ? window : domUtils.getWindow(this.document);
  6185. var me = this,
  6186. span = me.document.createElement("span");
  6187. //trace:717
  6188. span.innerHTML = "&nbsp;";
  6189. me.cloneRange().insertNode(span);
  6190. domUtils.scrollToView(span, win, offset);
  6191. domUtils.remove(span);
  6192. return me;
  6193. },
  6194. /**
  6195. * 判断当前选区内容是否占位符
  6196. * @private
  6197. * @method inFillChar
  6198. * @return { Boolean } 如果是占位符返回true,否则返回false
  6199. */
  6200. inFillChar: function() {
  6201. var start = this.startContainer;
  6202. if (
  6203. this.collapsed &&
  6204. start.nodeType == 3 &&
  6205. start.nodeValue.replace(new RegExp("^" + domUtils.fillChar), "")
  6206. .length +
  6207. 1 ==
  6208. start.nodeValue.length
  6209. ) {
  6210. return true;
  6211. }
  6212. return false;
  6213. },
  6214. /**
  6215. * 保存
  6216. * @method createAddress
  6217. * @private
  6218. * @return { Boolean } 返回开始和结束的位置
  6219. * @example
  6220. * ```html
  6221. * <body>
  6222. * <p>
  6223. * aaaa
  6224. * <em>
  6225. * <!-- 选区开始 -->
  6226. * bbbb
  6227. * <!-- 选区结束 -->
  6228. * </em>
  6229. * </p>
  6230. *
  6231. * <script>
  6232. * //output: {startAddress:[0,1,0,0],endAddress:[0,1,0,4]}
  6233. * console.log( range.createAddress() );
  6234. * </script>
  6235. * </body>
  6236. * ```
  6237. */
  6238. createAddress: function(ignoreEnd, ignoreTxt) {
  6239. var addr = {},
  6240. me = this;
  6241. function getAddress(isStart) {
  6242. var node = isStart ? me.startContainer : me.endContainer;
  6243. var parents = domUtils.findParents(node, true, function(node) {
  6244. return !domUtils.isBody(node);
  6245. }),
  6246. addrs = [];
  6247. for (var i = 0, ci; (ci = parents[i++]); ) {
  6248. addrs.push(domUtils.getNodeIndex(ci, ignoreTxt));
  6249. }
  6250. var firstIndex = 0;
  6251. if (ignoreTxt) {
  6252. if (node.nodeType == 3) {
  6253. var tmpNode = node.previousSibling;
  6254. while (tmpNode && tmpNode.nodeType == 3) {
  6255. firstIndex += tmpNode.nodeValue.replace(fillCharReg, "").length;
  6256. tmpNode = tmpNode.previousSibling;
  6257. }
  6258. firstIndex += isStart ? me.startOffset : me.endOffset; // - (fillCharReg.test(node.nodeValue) ? 1 : 0 )
  6259. } else {
  6260. node = node.childNodes[isStart ? me.startOffset : me.endOffset];
  6261. if (node) {
  6262. firstIndex = domUtils.getNodeIndex(node, ignoreTxt);
  6263. } else {
  6264. node = isStart ? me.startContainer : me.endContainer;
  6265. var first = node.firstChild;
  6266. while (first) {
  6267. if (domUtils.isFillChar(first)) {
  6268. first = first.nextSibling;
  6269. continue;
  6270. }
  6271. firstIndex++;
  6272. if (first.nodeType == 3) {
  6273. while (first && first.nodeType == 3) {
  6274. first = first.nextSibling;
  6275. }
  6276. } else {
  6277. first = first.nextSibling;
  6278. }
  6279. }
  6280. }
  6281. }
  6282. } else {
  6283. firstIndex = isStart
  6284. ? domUtils.isFillChar(node) ? 0 : me.startOffset
  6285. : me.endOffset;
  6286. }
  6287. if (firstIndex < 0) {
  6288. firstIndex = 0;
  6289. }
  6290. addrs.push(firstIndex);
  6291. return addrs;
  6292. }
  6293. addr.startAddress = getAddress(true);
  6294. if (!ignoreEnd) {
  6295. addr.endAddress = me.collapsed
  6296. ? [].concat(addr.startAddress)
  6297. : getAddress();
  6298. }
  6299. return addr;
  6300. },
  6301. /**
  6302. * 保存
  6303. * @method createAddress
  6304. * @private
  6305. * @return { Boolean } 返回开始和结束的位置
  6306. * @example
  6307. * ```html
  6308. * <body>
  6309. * <p>
  6310. * aaaa
  6311. * <em>
  6312. * <!-- 选区开始 -->
  6313. * bbbb
  6314. * <!-- 选区结束 -->
  6315. * </em>
  6316. * </p>
  6317. *
  6318. * <script>
  6319. * var range = editor.selection.getRange();
  6320. * range.moveToAddress({startAddress:[0,1,0,0],endAddress:[0,1,0,4]});
  6321. * range.select();
  6322. * //output: 'bbbb'
  6323. * console.log(editor.selection.getText());
  6324. * </script>
  6325. * </body>
  6326. * ```
  6327. */
  6328. moveToAddress: function(addr, ignoreEnd) {
  6329. var me = this;
  6330. function getNode(address, isStart) {
  6331. var tmpNode = me.document.body,
  6332. parentNode,
  6333. offset;
  6334. for (var i = 0, ci, l = address.length; i < l; i++) {
  6335. ci = address[i];
  6336. parentNode = tmpNode;
  6337. tmpNode = tmpNode.childNodes[ci];
  6338. if (!tmpNode) {
  6339. offset = ci;
  6340. break;
  6341. }
  6342. }
  6343. if (isStart) {
  6344. if (tmpNode) {
  6345. me.setStartBefore(tmpNode);
  6346. } else {
  6347. me.setStart(parentNode, offset);
  6348. }
  6349. } else {
  6350. if (tmpNode) {
  6351. me.setEndBefore(tmpNode);
  6352. } else {
  6353. me.setEnd(parentNode, offset);
  6354. }
  6355. }
  6356. }
  6357. getNode(addr.startAddress, true);
  6358. !ignoreEnd && addr.endAddress && getNode(addr.endAddress);
  6359. return me;
  6360. },
  6361. /**
  6362. * 判断给定的Range对象是否和当前Range对象表示的是同一个选区
  6363. * @method equals
  6364. * @param { UE.dom.Range } 需要判断的Range对象
  6365. * @return { Boolean } 如果给定的Range对象与当前Range对象表示的是同一个选区, 则返回true, 否则返回false
  6366. */
  6367. equals: function(rng) {
  6368. for (var p in this) {
  6369. if (this.hasOwnProperty(p)) {
  6370. if (this[p] !== rng[p]) return false;
  6371. }
  6372. }
  6373. return true;
  6374. },
  6375. /**
  6376. * 遍历range内的节点。每当遍历一个节点时, 都会执行参数项 doFn 指定的函数, 该函数的接受当前遍历的节点
  6377. * 作为其参数。
  6378. * @method traversal
  6379. * @param { Function } doFn 对每个遍历的节点要执行的方法, 该方法接受当前遍历的节点作为其参数
  6380. * @return { UE.dom.Range } 当前range对象
  6381. * @example
  6382. * ```html
  6383. *
  6384. * <body>
  6385. *
  6386. * <!-- 选区开始 -->
  6387. * <span></span>
  6388. * <a></a>
  6389. * <!-- 选区结束 -->
  6390. * </body>
  6391. *
  6392. * <script>
  6393. *
  6394. * //output: <span></span><a></a>
  6395. * console.log( range.cloneContents() );
  6396. *
  6397. * range.traversal( function ( node ) {
  6398. *
  6399. * if ( node.nodeType === 1 ) {
  6400. * node.className = "test";
  6401. * }
  6402. *
  6403. * } );
  6404. *
  6405. * //output: <span class="test"></span><a class="test"></a>
  6406. * console.log( range.cloneContents() );
  6407. *
  6408. * </script>
  6409. * ```
  6410. */
  6411. /**
  6412. * 遍历range内的节点。
  6413. * 每当遍历一个节点时, 都会执行参数项 doFn 指定的函数, 该函数的接受当前遍历的节点
  6414. * 作为其参数。
  6415. * 可以通过参数项 filterFn 来指定一个过滤器, 只有符合该过滤器过滤规则的节点才会触
  6416. * 发doFn函数的执行
  6417. * @method traversal
  6418. * @param { Function } doFn 对每个遍历的节点要执行的方法, 该方法接受当前遍历的节点作为其参数
  6419. * @param { Function } filterFn 过滤器, 该函数接受当前遍历的节点作为参数, 如果该节点满足过滤
  6420. * 规则, 请返回true, 该节点会触发doFn, 否则, 请返回false, 则该节点不
  6421. * 会触发doFn。
  6422. * @return { UE.dom.Range } 当前range对象
  6423. * @see UE.dom.Range:traversal(Function)
  6424. * @example
  6425. * ```html
  6426. *
  6427. * <body>
  6428. *
  6429. * <!-- 选区开始 -->
  6430. * <span></span>
  6431. * <a></a>
  6432. * <!-- 选区结束 -->
  6433. * </body>
  6434. *
  6435. * <script>
  6436. *
  6437. * //output: <span></span><a></a>
  6438. * console.log( range.cloneContents() );
  6439. *
  6440. * range.traversal( function ( node ) {
  6441. *
  6442. * node.className = "test";
  6443. *
  6444. * }, function ( node ) {
  6445. * return node.nodeType === 1;
  6446. * } );
  6447. *
  6448. * //output: <span class="test"></span><a class="test"></a>
  6449. * console.log( range.cloneContents() );
  6450. *
  6451. * </script>
  6452. * ```
  6453. */
  6454. traversal: function(doFn, filterFn) {
  6455. if (this.collapsed) return this;
  6456. var bookmark = this.createBookmark(),
  6457. end = bookmark.end,
  6458. current = domUtils.getNextDomNode(bookmark.start, false, filterFn);
  6459. while (
  6460. current &&
  6461. current !== end &&
  6462. domUtils.getPosition(current, end) & domUtils.POSITION_PRECEDING
  6463. ) {
  6464. var tmpNode = domUtils.getNextDomNode(current, false, filterFn);
  6465. doFn(current);
  6466. current = tmpNode;
  6467. }
  6468. return this.moveToBookmark(bookmark);
  6469. }
  6470. };
  6471. })();
  6472. // core/Selection.js
  6473. /**
  6474. * 选集
  6475. * @file
  6476. * @module UE.dom
  6477. * @class Selection
  6478. * @since 1.2.6.1
  6479. */
  6480. /**
  6481. * 选区集合
  6482. * @unfile
  6483. * @module UE.dom
  6484. * @class Selection
  6485. */
  6486. ;(function() {
  6487. function getBoundaryInformation(range, start) {
  6488. var getIndex = domUtils.getNodeIndex;
  6489. range = range.duplicate();
  6490. range.collapse(start);
  6491. var parent = range.parentElement();
  6492. //如果节点里没有子节点,直接退出
  6493. if (!parent.hasChildNodes()) {
  6494. return { container: parent, offset: 0 };
  6495. }
  6496. var siblings = parent.children,
  6497. child,
  6498. testRange = range.duplicate(),
  6499. startIndex = 0,
  6500. endIndex = siblings.length - 1,
  6501. index = -1,
  6502. distance;
  6503. while (startIndex <= endIndex) {
  6504. index = Math.floor((startIndex + endIndex) / 2);
  6505. child = siblings[index];
  6506. testRange.moveToElementText(child);
  6507. var position = testRange.compareEndPoints("StartToStart", range);
  6508. if (position > 0) {
  6509. endIndex = index - 1;
  6510. } else if (position < 0) {
  6511. startIndex = index + 1;
  6512. } else {
  6513. //trace:1043
  6514. return { container: parent, offset: getIndex(child) };
  6515. }
  6516. }
  6517. if (index == -1) {
  6518. testRange.moveToElementText(parent);
  6519. testRange.setEndPoint("StartToStart", range);
  6520. distance = testRange.text.replace(/(\r\n|\r)/g, "\n").length;
  6521. siblings = parent.childNodes;
  6522. if (!distance) {
  6523. child = siblings[siblings.length - 1];
  6524. return { container: child, offset: child.nodeValue.length };
  6525. }
  6526. var i = siblings.length;
  6527. while (distance > 0) {
  6528. distance -= siblings[--i].nodeValue.length;
  6529. }
  6530. return { container: siblings[i], offset: -distance };
  6531. }
  6532. testRange.collapse(position > 0);
  6533. testRange.setEndPoint(position > 0 ? "StartToStart" : "EndToStart", range);
  6534. distance = testRange.text.replace(/(\r\n|\r)/g, "\n").length;
  6535. if (!distance) {
  6536. return dtd.$empty[child.tagName] || dtd.$nonChild[child.tagName]
  6537. ? {
  6538. container: parent,
  6539. offset: getIndex(child) + (position > 0 ? 0 : 1)
  6540. }
  6541. : {
  6542. container: child,
  6543. offset: position > 0 ? 0 : child.childNodes.length
  6544. };
  6545. }
  6546. while (distance > 0) {
  6547. try {
  6548. var pre = child;
  6549. child = child[position > 0 ? "previousSibling" : "nextSibling"];
  6550. distance -= child.nodeValue.length;
  6551. } catch (e) {
  6552. return { container: parent, offset: getIndex(pre) };
  6553. }
  6554. }
  6555. return {
  6556. container: child,
  6557. offset: position > 0 ? -distance : child.nodeValue.length + distance
  6558. };
  6559. }
  6560. /**
  6561. * 将ieRange转换为Range对象
  6562. * @param {Range} ieRange ieRange对象
  6563. * @param {Range} range Range对象
  6564. * @return {Range} range 返回转换后的Range对象
  6565. */
  6566. function transformIERangeToRange(ieRange, range) {
  6567. if (ieRange.item) {
  6568. range.selectNode(ieRange.item(0));
  6569. } else {
  6570. var bi = getBoundaryInformation(ieRange, true);
  6571. range.setStart(bi.container, bi.offset);
  6572. if (ieRange.compareEndPoints("StartToEnd", ieRange) != 0) {
  6573. bi = getBoundaryInformation(ieRange, false);
  6574. range.setEnd(bi.container, bi.offset);
  6575. }
  6576. }
  6577. return range;
  6578. }
  6579. /**
  6580. * 获得ieRange
  6581. * @param {Selection} sel Selection对象
  6582. * @return {ieRange} 得到ieRange
  6583. */
  6584. function _getIERange(sel) {
  6585. var ieRange;
  6586. //ie下有可能报错
  6587. try {
  6588. ieRange = sel.getNative().createRange();
  6589. } catch (e) {
  6590. return null;
  6591. }
  6592. var el = ieRange.item ? ieRange.item(0) : ieRange.parentElement();
  6593. if ((el.ownerDocument || el) === sel.document) {
  6594. return ieRange;
  6595. }
  6596. return null;
  6597. }
  6598. var Selection = (dom.Selection = function(doc) {
  6599. var me = this,
  6600. iframe;
  6601. me.document = doc;
  6602. if (browser.ie9below) {
  6603. iframe = domUtils.getWindow(doc).frameElement;
  6604. domUtils.on(iframe, "beforedeactivate", function() {
  6605. me._bakIERange = me.getIERange();
  6606. });
  6607. domUtils.on(iframe, "activate", function() {
  6608. try {
  6609. if (!_getIERange(me) && me._bakIERange) {
  6610. me._bakIERange.select();
  6611. }
  6612. } catch (ex) {}
  6613. me._bakIERange = null;
  6614. });
  6615. }
  6616. iframe = doc = null;
  6617. });
  6618. Selection.prototype = {
  6619. rangeInBody: function(rng, txtRange) {
  6620. var node = browser.ie9below || txtRange
  6621. ? rng.item ? rng.item() : rng.parentElement()
  6622. : rng.startContainer;
  6623. return node === this.document.body || domUtils.inDoc(node, this.document);
  6624. },
  6625. /**
  6626. * 获取原生seleciton对象
  6627. * @method getNative
  6628. * @return { Object } 获得selection对象
  6629. * @example
  6630. * ```javascript
  6631. * editor.selection.getNative();
  6632. * ```
  6633. */
  6634. getNative: function() {
  6635. var doc = this.document;
  6636. try {
  6637. return !doc
  6638. ? null
  6639. : browser.ie9below
  6640. ? doc.selection
  6641. : domUtils.getWindow(doc).getSelection();
  6642. } catch (e) {
  6643. return null;
  6644. }
  6645. },
  6646. /**
  6647. * 获得ieRange
  6648. * @method getIERange
  6649. * @return { Object } 返回ie原生的Range
  6650. * @example
  6651. * ```javascript
  6652. * editor.selection.getIERange();
  6653. * ```
  6654. */
  6655. getIERange: function() {
  6656. var ieRange = _getIERange(this);
  6657. if (!ieRange) {
  6658. if (this._bakIERange) {
  6659. return this._bakIERange;
  6660. }
  6661. }
  6662. return ieRange;
  6663. },
  6664. /**
  6665. * 缓存当前选区的range和选区的开始节点
  6666. * @method cache
  6667. */
  6668. cache: function() {
  6669. this.clear();
  6670. this._cachedRange = this.getRange();
  6671. this._cachedStartElement = this.getStart();
  6672. this._cachedStartElementPath = this.getStartElementPath();
  6673. },
  6674. /**
  6675. * 获取选区开始位置的父节点到body
  6676. * @method getStartElementPath
  6677. * @return { Array } 返回父节点集合
  6678. * @example
  6679. * ```javascript
  6680. * editor.selection.getStartElementPath();
  6681. * ```
  6682. */
  6683. getStartElementPath: function() {
  6684. if (this._cachedStartElementPath) {
  6685. return this._cachedStartElementPath;
  6686. }
  6687. var start = this.getStart();
  6688. if (start) {
  6689. return domUtils.findParents(start, true, null, true);
  6690. }
  6691. return [];
  6692. },
  6693. /**
  6694. * 清空缓存
  6695. * @method clear
  6696. */
  6697. clear: function() {
  6698. this._cachedStartElementPath = this._cachedRange = this._cachedStartElement = null;
  6699. },
  6700. /**
  6701. * 编辑器是否得到了选区
  6702. * @method isFocus
  6703. */
  6704. isFocus: function() {
  6705. try {
  6706. if (browser.ie9below) {
  6707. var nativeRange = _getIERange(this);
  6708. return !!(nativeRange && this.rangeInBody(nativeRange));
  6709. } else {
  6710. return !!this.getNative().rangeCount;
  6711. }
  6712. } catch (e) {
  6713. return false;
  6714. }
  6715. },
  6716. /**
  6717. * 获取选区对应的Range
  6718. * @method getRange
  6719. * @return { Object } 得到Range对象
  6720. * @example
  6721. * ```javascript
  6722. * editor.selection.getRange();
  6723. * ```
  6724. */
  6725. getRange: function() {
  6726. var me = this;
  6727. function optimze(range) {
  6728. var child = me.document.body.firstChild,
  6729. collapsed = range.collapsed;
  6730. while (child && child.firstChild) {
  6731. range.setStart(child, 0);
  6732. child = child.firstChild;
  6733. }
  6734. if (!range.startContainer) {
  6735. range.setStart(me.document.body, 0);
  6736. }
  6737. if (collapsed) {
  6738. range.collapse(true);
  6739. }
  6740. }
  6741. if (me._cachedRange != null) {
  6742. return this._cachedRange;
  6743. }
  6744. var range = new baidu.editor.dom.Range(me.document);
  6745. if (browser.ie9below) {
  6746. var nativeRange = me.getIERange();
  6747. if (nativeRange) {
  6748. //备份的_bakIERange可能已经实效了,dom树发生了变化比如从源码模式切回来,所以try一下,实效就放到body开始位置
  6749. try {
  6750. transformIERangeToRange(nativeRange, range);
  6751. } catch (e) {
  6752. optimze(range);
  6753. }
  6754. } else {
  6755. optimze(range);
  6756. }
  6757. } else {
  6758. var sel = me.getNative();
  6759. if (sel && sel.rangeCount) {
  6760. var firstRange = sel.getRangeAt(0);
  6761. var lastRange = sel.getRangeAt(sel.rangeCount - 1);
  6762. range
  6763. .setStart(firstRange.startContainer, firstRange.startOffset)
  6764. .setEnd(lastRange.endContainer, lastRange.endOffset);
  6765. if (
  6766. range.collapsed &&
  6767. domUtils.isBody(range.startContainer) &&
  6768. !range.startOffset
  6769. ) {
  6770. optimze(range);
  6771. }
  6772. } else {
  6773. //trace:1734 有可能已经不在dom树上了,标识的节点
  6774. if (
  6775. this._bakRange &&
  6776. domUtils.inDoc(this._bakRange.startContainer, this.document)
  6777. ) {
  6778. return this._bakRange;
  6779. }
  6780. optimze(range);
  6781. }
  6782. }
  6783. return (this._bakRange = range);
  6784. },
  6785. /**
  6786. * 获取开始元素,用于状态反射
  6787. * @method getStart
  6788. * @return { Element } 获得开始元素
  6789. * @example
  6790. * ```javascript
  6791. * editor.selection.getStart();
  6792. * ```
  6793. */
  6794. getStart: function() {
  6795. if (this._cachedStartElement) {
  6796. return this._cachedStartElement;
  6797. }
  6798. var range = browser.ie9below ? this.getIERange() : this.getRange(),
  6799. tmpRange,
  6800. start,
  6801. tmp,
  6802. parent;
  6803. if (browser.ie9below) {
  6804. if (!range) {
  6805. //todo 给第一个值可能会有问题
  6806. return this.document.body.firstChild;
  6807. }
  6808. //control元素
  6809. if (range.item) {
  6810. return range.item(0);
  6811. }
  6812. tmpRange = range.duplicate();
  6813. //修正ie下<b>x</b>[xx] 闭合后 <b>x|</b>xx
  6814. tmpRange.text.length > 0 && tmpRange.moveStart("character", 1);
  6815. tmpRange.collapse(1);
  6816. start = tmpRange.parentElement();
  6817. parent = tmp = range.parentElement();
  6818. while ((tmp = tmp.parentNode)) {
  6819. if (tmp == start) {
  6820. start = parent;
  6821. break;
  6822. }
  6823. }
  6824. } else {
  6825. range.shrinkBoundary();
  6826. start = range.startContainer;
  6827. if (start.nodeType == 1 && start.hasChildNodes()) {
  6828. start =
  6829. start.childNodes[
  6830. Math.min(start.childNodes.length - 1, range.startOffset)
  6831. ];
  6832. }
  6833. if (start.nodeType == 3) {
  6834. return start.parentNode;
  6835. }
  6836. }
  6837. return start;
  6838. },
  6839. /**
  6840. * 得到选区中的文本
  6841. * @method getText
  6842. * @return { String } 选区中包含的文本
  6843. * @example
  6844. * ```javascript
  6845. * editor.selection.getText();
  6846. * ```
  6847. */
  6848. getText: function() {
  6849. var nativeSel, nativeRange;
  6850. if (this.isFocus() && (nativeSel = this.getNative())) {
  6851. nativeRange = browser.ie9below
  6852. ? nativeSel.createRange()
  6853. : nativeSel.getRangeAt(0);
  6854. return browser.ie9below ? nativeRange.text : nativeRange.toString();
  6855. }
  6856. return "";
  6857. },
  6858. /**
  6859. * 清除选区
  6860. * @method clearRange
  6861. * @example
  6862. * ```javascript
  6863. * editor.selection.clearRange();
  6864. * ```
  6865. */
  6866. clearRange: function() {
  6867. this.getNative()[browser.ie9below ? "empty" : "removeAllRanges"]();
  6868. }
  6869. };
  6870. })();
  6871. // core/Editor.js
  6872. /**
  6873. * 编辑器主类,包含编辑器提供的大部分公用接口
  6874. * @file
  6875. * @module UE
  6876. * @class Editor
  6877. * @since 1.2.6.1
  6878. */
  6879. /**
  6880. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  6881. * @unfile
  6882. * @module UE
  6883. */
  6884. /**
  6885. * UEditor的核心类,为用户提供与编辑器交互的接口。
  6886. * @unfile
  6887. * @module UE
  6888. * @class Editor
  6889. */
  6890. ;(function() {
  6891. var uid = 0,
  6892. _selectionChangeTimer;
  6893. /**
  6894. * 获取编辑器的html内容,赋值到编辑器所在表单的textarea文本域里面
  6895. * @private
  6896. * @method setValue
  6897. * @param { UE.Editor } editor 编辑器事例
  6898. */
  6899. function setValue(form, editor) {
  6900. var textarea;
  6901. if (editor.options.textarea) {
  6902. if (utils.isString(editor.options.textarea)) {
  6903. for (
  6904. var i = 0, ti, tis = domUtils.getElementsByTagName(form, "textarea");
  6905. (ti = tis[i++]);
  6906. ) {
  6907. if (ti.id == "ueditor_textarea_" + editor.options.textarea) {
  6908. textarea = ti;
  6909. break;
  6910. }
  6911. }
  6912. } else {
  6913. textarea = editor.textarea;
  6914. }
  6915. }
  6916. if (!textarea) {
  6917. form.appendChild(
  6918. (textarea = domUtils.createElement(document, "textarea", {
  6919. name: editor.options.textarea,
  6920. id: "ueditor_textarea_" + editor.options.textarea,
  6921. style: "display:none"
  6922. }))
  6923. );
  6924. //不要产生多个textarea
  6925. editor.textarea = textarea;
  6926. }
  6927. !textarea.getAttribute("name") &&
  6928. textarea.setAttribute("name", editor.options.textarea);
  6929. textarea.value = editor.hasContents()
  6930. ? editor.options.allHtmlEnabled
  6931. ? editor.getAllHtml()
  6932. : editor.getContent(null, null, true)
  6933. : "";
  6934. }
  6935. function loadPlugins(me) {
  6936. //初始化插件
  6937. for (var pi in UE.plugins) {
  6938. UE.plugins[pi].call(me);
  6939. }
  6940. }
  6941. function checkCurLang(I18N) {
  6942. for (var lang in I18N) {
  6943. return lang;
  6944. }
  6945. }
  6946. function langReadied(me) {
  6947. me.langIsReady = true;
  6948. me.fireEvent("langReady");
  6949. }
  6950. /**
  6951. * 编辑器准备就绪后会触发该事件
  6952. * @module UE
  6953. * @class Editor
  6954. * @event ready
  6955. * @remind render方法执行完成之后,会触发该事件
  6956. * @remind
  6957. * @example
  6958. * ```javascript
  6959. * editor.addListener( 'ready', function( editor ) {
  6960. * editor.execCommand( 'focus' ); //编辑器家在完成后,让编辑器拿到焦点
  6961. * } );
  6962. * ```
  6963. */
  6964. /**
  6965. * 执行destroy方法,会触发该事件
  6966. * @module UE
  6967. * @class Editor
  6968. * @event destroy
  6969. * @see UE.Editor:destroy()
  6970. */
  6971. /**
  6972. * 执行reset方法,会触发该事件
  6973. * @module UE
  6974. * @class Editor
  6975. * @event reset
  6976. * @see UE.Editor:reset()
  6977. */
  6978. /**
  6979. * 执行focus方法,会触发该事件
  6980. * @module UE
  6981. * @class Editor
  6982. * @event focus
  6983. * @see UE.Editor:focus(Boolean)
  6984. */
  6985. /**
  6986. * 语言加载完成会触发该事件
  6987. * @module UE
  6988. * @class Editor
  6989. * @event langReady
  6990. */
  6991. /**
  6992. * 运行命令之后会触发该命令
  6993. * @module UE
  6994. * @class Editor
  6995. * @event beforeExecCommand
  6996. */
  6997. /**
  6998. * 运行命令之后会触发该命令
  6999. * @module UE
  7000. * @class Editor
  7001. * @event afterExecCommand
  7002. */
  7003. /**
  7004. * 运行命令之前会触发该命令
  7005. * @module UE
  7006. * @class Editor
  7007. * @event firstBeforeExecCommand
  7008. */
  7009. /**
  7010. * 在getContent方法执行之前会触发该事件
  7011. * @module UE
  7012. * @class Editor
  7013. * @event beforeGetContent
  7014. * @see UE.Editor:getContent()
  7015. */
  7016. /**
  7017. * 在getContent方法执行之后会触发该事件
  7018. * @module UE
  7019. * @class Editor
  7020. * @event afterGetContent
  7021. * @see UE.Editor:getContent()
  7022. */
  7023. /**
  7024. * 在getAllHtml方法执行时会触发该事件
  7025. * @module UE
  7026. * @class Editor
  7027. * @event getAllHtml
  7028. * @see UE.Editor:getAllHtml()
  7029. */
  7030. /**
  7031. * 在setContent方法执行之前会触发该事件
  7032. * @module UE
  7033. * @class Editor
  7034. * @event beforeSetContent
  7035. * @see UE.Editor:setContent(String)
  7036. */
  7037. /**
  7038. * 在setContent方法执行之后会触发该事件
  7039. * @module UE
  7040. * @class Editor
  7041. * @event afterSetContent
  7042. * @see UE.Editor:setContent(String)
  7043. */
  7044. /**
  7045. * 每当编辑器内部选区发生改变时,将触发该事件
  7046. * @event selectionchange
  7047. * @warning 该事件的触发非常频繁,不建议在该事件的处理过程中做重量级的处理
  7048. * @example
  7049. * ```javascript
  7050. * editor.addListener( 'selectionchange', function( editor ) {
  7051. * console.log('选区发生改变');
  7052. * }
  7053. */
  7054. /**
  7055. * 在所有selectionchange的监听函数执行之前,会触发该事件
  7056. * @module UE
  7057. * @class Editor
  7058. * @event beforeSelectionChange
  7059. * @see UE.Editor:selectionchange
  7060. */
  7061. /**
  7062. * 在所有selectionchange的监听函数执行完之后,会触发该事件
  7063. * @module UE
  7064. * @class Editor
  7065. * @event afterSelectionChange
  7066. * @see UE.Editor:selectionchange
  7067. */
  7068. /**
  7069. * 编辑器内容发生改变时会触发该事件
  7070. * @module UE
  7071. * @class Editor
  7072. * @event contentChange
  7073. */
  7074. /**
  7075. * 以默认参数构建一个编辑器实例
  7076. * @constructor
  7077. * @remind 通过 改构造方法实例化的编辑器,不带ui层.需要render到一个容器,编辑器实例才能正常渲染到页面
  7078. * @example
  7079. * ```javascript
  7080. * var editor = new UE.Editor();
  7081. * editor.execCommand('blod');
  7082. * ```
  7083. * @see UE.Config
  7084. */
  7085. /**
  7086. * 以给定的参数集合创建一个编辑器实例,对于未指定的参数,将应用默认参数。
  7087. * @constructor
  7088. * @remind 通过 改构造方法实例化的编辑器,不带ui层.需要render到一个容器,编辑器实例才能正常渲染到页面
  7089. * @param { Object } setting 创建编辑器的参数
  7090. * @example
  7091. * ```javascript
  7092. * var editor = new UE.Editor();
  7093. * editor.execCommand('blod');
  7094. * ```
  7095. * @see UE.Config
  7096. */
  7097. var Editor = (UE.Editor = function(options) {
  7098. var me = this;
  7099. me.uid = uid++;
  7100. EventBase.call(me);
  7101. me.commands = {};
  7102. me.options = utils.extend(utils.clone(options || {}), UEDITOR_CONFIG, true);
  7103. me.shortcutkeys = {};
  7104. me.inputRules = [];
  7105. me.outputRules = [];
  7106. //设置默认的常用属性
  7107. me.setOpt(Editor.defaultOptions(me));
  7108. /* 尝试异步加载后台配置 */
  7109. //me.loadServerConfig();
  7110. if (!utils.isEmptyObject(UE.I18N)) {
  7111. //修改默认的语言类型
  7112. me.options.lang = checkCurLang(UE.I18N);
  7113. UE.plugin.load(me);
  7114. langReadied(me);
  7115. } else {
  7116. utils.loadFile(
  7117. document,
  7118. {
  7119. src:
  7120. me.options.langPath +
  7121. me.options.lang +
  7122. "/" +
  7123. me.options.lang +
  7124. ".js",
  7125. tag: "script",
  7126. type: "text/javascript",
  7127. defer: "defer"
  7128. },
  7129. function() {
  7130. UE.plugin.load(me);
  7131. langReadied(me);
  7132. }
  7133. );
  7134. }
  7135. UE.instants["ueditorInstant" + me.uid] = me;
  7136. });
  7137. Editor.prototype = {
  7138. registerCommand: function(name, obj) {
  7139. this.commands[name] = obj;
  7140. },
  7141. /**
  7142. * 编辑器对外提供的监听ready事件的接口, 通过调用该方法,达到的效果与监听ready事件是一致的
  7143. * @method ready
  7144. * @param { Function } fn 编辑器ready之后所执行的回调, 如果在注册事件之前编辑器已经ready,将会
  7145. * 立即触发该回调。
  7146. * @remind 需要等待编辑器加载完成后才能执行的代码,可以使用该方法传入
  7147. * @example
  7148. * ```javascript
  7149. * editor.ready( function( editor ) {
  7150. * editor.setContent('初始化完毕');
  7151. * } );
  7152. * ```
  7153. * @see UE.Editor.event:ready
  7154. */
  7155. ready: function(fn) {
  7156. var me = this;
  7157. if (fn) {
  7158. me.isReady ? fn.apply(me) : me.addListener("ready", fn);
  7159. }
  7160. },
  7161. /**
  7162. * 该方法用于设置placeholder
  7163. * @method setPlaceholder
  7164. * @param { String } placeholder 编辑器的placeholder文案
  7165. * @example
  7166. * ```javascript
  7167. * editor.setPlaceholder('请输入内容');
  7168. * ```
  7169. */
  7170. setPlaceholder: function(){
  7171. function contentChange(){
  7172. var localHtml = this.getPlainTxt();
  7173. if(!localHtml.trim()){
  7174. UE.dom.domUtils.addClass( this.body, 'empty' );
  7175. }else{
  7176. UE.dom.domUtils.removeClasses( this.body, 'empty' );
  7177. }
  7178. }
  7179. return function(placeholder){
  7180. var _editor = this;
  7181. _editor.ready(function () {
  7182. contentChange.call(_editor);
  7183. _editor.body.setAttribute('placeholder', placeholder);
  7184. });
  7185. _editor.removeListener('keyup contentchange', contentChange);
  7186. _editor.addListener('keyup contentchange', contentChange);
  7187. }
  7188. }(),
  7189. /**
  7190. * 该方法是提供给插件里面使用,设置配置项默认值
  7191. * @method setOpt
  7192. * @warning 三处设置配置项的优先级: 实例化时传入参数 > setOpt()设置 > config文件里设置
  7193. * @warning 该方法仅供编辑器插件内部和编辑器初始化时调用,其他地方不能调用。
  7194. * @param { String } key 编辑器的可接受的选项名称
  7195. * @param { * } val 该选项可接受的值
  7196. * @example
  7197. * ```javascript
  7198. * editor.setOpt( 'initContent', '欢迎使用编辑器' );
  7199. * ```
  7200. */
  7201. /**
  7202. * 该方法是提供给插件里面使用,以{key:value}集合的方式设置插件内用到的配置项默认值
  7203. * @method setOpt
  7204. * @warning 三处设置配置项的优先级: 实例化时传入参数 > setOpt()设置 > config文件里设置
  7205. * @warning 该方法仅供编辑器插件内部和编辑器初始化时调用,其他地方不能调用。
  7206. * @param { Object } options 将要设置的选项的键值对对象
  7207. * @example
  7208. * ```javascript
  7209. * editor.setOpt( {
  7210. * 'initContent': '欢迎使用编辑器'
  7211. * } );
  7212. * ```
  7213. */
  7214. setOpt: function(key, val) {
  7215. var obj = {};
  7216. if (utils.isString(key)) {
  7217. obj[key] = val;
  7218. } else {
  7219. obj = key;
  7220. }
  7221. utils.extend(this.options, obj, true);
  7222. },
  7223. getOpt: function(key) {
  7224. return this.options[key];
  7225. },
  7226. /**
  7227. * 销毁编辑器实例,使用textarea代替
  7228. * @method destroy
  7229. * @example
  7230. * ```javascript
  7231. * editor.destroy();
  7232. * ```
  7233. */
  7234. destroy: function() {
  7235. var me = this;
  7236. me.fireEvent("destroy");
  7237. var container = me.container.parentNode;
  7238. var textarea = me.textarea;
  7239. if (!textarea) {
  7240. textarea = document.createElement("textarea");
  7241. container.parentNode.insertBefore(textarea, container);
  7242. } else {
  7243. textarea.style.display = "";
  7244. }
  7245. textarea.style.width = me.iframe.offsetWidth + "px";
  7246. textarea.style.height = me.iframe.offsetHeight + "px";
  7247. textarea.value = me.getContent();
  7248. textarea.id = me.key;
  7249. container.innerHTML = "";
  7250. domUtils.remove(container);
  7251. var key = me.key;
  7252. //trace:2004
  7253. for (var p in me) {
  7254. if (me.hasOwnProperty(p)) {
  7255. delete this[p];
  7256. }
  7257. }
  7258. UE.delEditor(key);
  7259. },
  7260. /**
  7261. * 渲染编辑器的DOM到指定容器
  7262. * @method render
  7263. * @param { String } containerId 指定一个容器ID
  7264. * @remind 执行该方法,会触发ready事件
  7265. * @warning 必须且只能调用一次
  7266. */
  7267. /**
  7268. * 渲染编辑器的DOM到指定容器
  7269. * @method render
  7270. * @param { Element } containerDom 直接指定容器对象
  7271. * @remind 执行该方法,会触发ready事件
  7272. * @warning 必须且只能调用一次
  7273. */
  7274. render: function(container) {
  7275. var me = this,
  7276. options = me.options,
  7277. getStyleValue = function(attr) {
  7278. return parseInt(domUtils.getComputedStyle(container, attr));
  7279. };
  7280. if (utils.isString(container)) {
  7281. container = document.getElementById(container);
  7282. }
  7283. if (container) {
  7284. if (options.initialFrameWidth) {
  7285. options.minFrameWidth = options.initialFrameWidth;
  7286. } else {
  7287. options.minFrameWidth = options.initialFrameWidth =
  7288. container.offsetWidth;
  7289. }
  7290. if (options.initialFrameHeight) {
  7291. options.minFrameHeight = options.initialFrameHeight;
  7292. } else {
  7293. options.initialFrameHeight = options.minFrameHeight =
  7294. container.offsetHeight;
  7295. }
  7296. container.style.width = /%$/.test(options.initialFrameWidth)
  7297. ? "100%"
  7298. : options.initialFrameWidth -
  7299. getStyleValue("padding-left") -
  7300. getStyleValue("padding-right") +
  7301. "px";
  7302. container.style.height = /%$/.test(options.initialFrameHeight)
  7303. ? "100%"
  7304. : options.initialFrameHeight -
  7305. getStyleValue("padding-top") -
  7306. getStyleValue("padding-bottom") +
  7307. "px";
  7308. container.style.zIndex = options.zIndex;
  7309. var html =
  7310. (ie && browser.version < 9 ? "" : "<!DOCTYPE html>") +
  7311. "<html xmlns='http://www.w3.org/1999/xhtml' class='view' >" +
  7312. "<head>" +
  7313. "<style type='text/css'>" +
  7314. //设置四周的留边
  7315. ".view{padding:0;word-wrap:break-word;cursor:text;height:90%;}\n" +
  7316. //设置默认字体和字号
  7317. //font-family不能呢随便改,在safari下fillchar会有解析问题
  7318. "body{margin:8px;font-family:sans-serif;font-size:16px;}" +
  7319. //设置placeholder
  7320. "body.empty:before{content:attr(placeholder);position:absolute;color:#999;}"+
  7321. //设置段落间距
  7322. "p{margin:5px 0;}</style>" +
  7323. (options.iframeCssUrl
  7324. ? "<link rel='stylesheet' type='text/css' href='" +
  7325. utils.unhtml(options.iframeCssUrl) +
  7326. "'/>"
  7327. : "") +
  7328. (options.initialStyle
  7329. ? "<style>" + options.initialStyle + "</style>"
  7330. : "") +
  7331. "</head>" +
  7332. "<body class='view' ></body>" +
  7333. "<script type='text/javascript' " +
  7334. (ie ? "defer='defer'" : "") +
  7335. " id='_initialScript'>" +
  7336. "setTimeout(function(){editor = window.parent.UE.instants['ueditorInstant" +
  7337. me.uid +
  7338. "'];editor._setup(document);},0);" +
  7339. "var _tmpScript = document.getElementById('_initialScript');_tmpScript.parentNode.removeChild(_tmpScript);" +
  7340. "</script>" +
  7341. (options.iframeJsUrl
  7342. ? "<script type='text/javascript' src='" +
  7343. utils.unhtml(options.iframeJsUrl) +
  7344. "'></script>"
  7345. : "") +
  7346. "</html>";
  7347. container.appendChild(
  7348. domUtils.createElement(document, "iframe", {
  7349. id: "ueditor_" + me.uid,
  7350. width: "100%",
  7351. height: "100%",
  7352. frameborder: "0",
  7353. //先注释掉了,加的原因忘记了,但开启会直接导致全屏模式下内容多时不会出现滚动条
  7354. // scrolling :'no',
  7355. src:
  7356. "javascript:void(function(){document.open();" +
  7357. (options.customDomain && document.domain != location.hostname
  7358. ? 'document.domain="' + document.domain + '";'
  7359. : "") +
  7360. 'document.write("' +
  7361. html +
  7362. '");document.close();}())'
  7363. })
  7364. );
  7365. container.style.overflow = "hidden";
  7366. //解决如果是给定的百分比,会导致高度算不对的问题
  7367. setTimeout(function() {
  7368. if (/%$/.test(options.initialFrameWidth)) {
  7369. options.minFrameWidth = options.initialFrameWidth =
  7370. container.offsetWidth;
  7371. //如果这里给定宽度,会导致ie在拖动窗口大小时,编辑区域不随着变化
  7372. // container.style.width = options.initialFrameWidth + 'px';
  7373. }
  7374. if (/%$/.test(options.initialFrameHeight)) {
  7375. options.minFrameHeight = options.initialFrameHeight =
  7376. container.offsetHeight;
  7377. container.style.height = options.initialFrameHeight + "px";
  7378. }
  7379. });
  7380. }
  7381. },
  7382. /**
  7383. * 编辑器初始化
  7384. * @method _setup
  7385. * @private
  7386. * @param { Element } doc 编辑器Iframe中的文档对象
  7387. */
  7388. _setup: function(doc) {
  7389. var me = this,
  7390. options = me.options;
  7391. if (ie) {
  7392. doc.body.disabled = true;
  7393. doc.body.contentEditable = true;
  7394. doc.body.disabled = false;
  7395. } else {
  7396. doc.body.contentEditable = true;
  7397. }
  7398. doc.body.spellcheck = false;
  7399. me.document = doc;
  7400. me.window = doc.defaultView || doc.parentWindow;
  7401. me.iframe = me.window.frameElement;
  7402. me.body = doc.body;
  7403. me.selection = new dom.Selection(doc);
  7404. //gecko初始化就能得到range,无法判断isFocus了
  7405. var geckoSel;
  7406. if (browser.gecko && (geckoSel = this.selection.getNative())) {
  7407. geckoSel.removeAllRanges();
  7408. }
  7409. this._initEvents();
  7410. //为form提交提供一个隐藏的textarea
  7411. for (
  7412. var form = this.iframe.parentNode;
  7413. !domUtils.isBody(form);
  7414. form = form.parentNode
  7415. ) {
  7416. if (form.tagName == "FORM") {
  7417. me.form = form;
  7418. if (me.options.autoSyncData) {
  7419. domUtils.on(me.window, "blur", function() {
  7420. setValue(form, me);
  7421. });
  7422. } else {
  7423. domUtils.on(form, "submit", function() {
  7424. setValue(this, me);
  7425. });
  7426. }
  7427. break;
  7428. }
  7429. }
  7430. if (options.initialContent) {
  7431. if (options.autoClearinitialContent) {
  7432. var oldExecCommand = me.execCommand;
  7433. me.execCommand = function() {
  7434. me.fireEvent("firstBeforeExecCommand");
  7435. return oldExecCommand.apply(me, arguments);
  7436. };
  7437. this._setDefaultContent(options.initialContent);
  7438. } else this.setContent(options.initialContent, false, true);
  7439. }
  7440. //编辑器不能为空内容
  7441. if (domUtils.isEmptyNode(me.body)) {
  7442. me.body.innerHTML = "<p>" + (browser.ie ? "" : "<br/>") + "</p>";
  7443. }
  7444. //如果要求focus, 就把光标定位到内容开始
  7445. if (options.focus) {
  7446. setTimeout(function() {
  7447. me.focus(me.options.focusInEnd);
  7448. //如果自动清除开着,就不需要做selectionchange;
  7449. !me.options.autoClearinitialContent && me._selectionChange();
  7450. }, 0);
  7451. }
  7452. if (!me.container) {
  7453. me.container = this.iframe.parentNode;
  7454. }
  7455. if (options.fullscreen && me.ui) {
  7456. me.ui.setFullScreen(true);
  7457. }
  7458. try {
  7459. me.document.execCommand("2D-position", false, false);
  7460. } catch (e) {}
  7461. try {
  7462. me.document.execCommand("enableInlineTableEditing", false, false);
  7463. } catch (e) {}
  7464. try {
  7465. me.document.execCommand("enableObjectResizing", false, false);
  7466. } catch (e) {}
  7467. //挂接快捷键
  7468. me._bindshortcutKeys();
  7469. me.isReady = 1;
  7470. me.fireEvent("ready");
  7471. options.onready && options.onready.call(me);
  7472. if (!browser.ie9below) {
  7473. domUtils.on(me.window, ["blur", "focus"], function(e) {
  7474. //chrome下会出现alt+tab切换时,导致选区位置不对
  7475. if (e.type == "blur") {
  7476. me._bakRange = me.selection.getRange();
  7477. try {
  7478. me._bakNativeRange = me.selection.getNative().getRangeAt(0);
  7479. me.selection.getNative().removeAllRanges();
  7480. } catch (e) {
  7481. me._bakNativeRange = null;
  7482. }
  7483. } else {
  7484. try {
  7485. me._bakRange && me._bakRange.select();
  7486. } catch (e) {}
  7487. }
  7488. });
  7489. }
  7490. //trace:1518 ff3.6body不够寛,会导致点击空白处无法获得焦点
  7491. if (browser.gecko && browser.version <= 10902) {
  7492. //修复ff3.6初始化进来,不能点击获得焦点
  7493. me.body.contentEditable = false;
  7494. setTimeout(function() {
  7495. me.body.contentEditable = true;
  7496. }, 100);
  7497. setInterval(function() {
  7498. me.body.style.height = me.iframe.offsetHeight - 20 + "px";
  7499. }, 100);
  7500. }
  7501. !options.isShow && me.setHide();
  7502. options.readonly && me.setDisabled();
  7503. },
  7504. /**
  7505. * 同步数据到编辑器所在的form
  7506. * 从编辑器的容器节点向上查找form元素,若找到,就同步编辑内容到找到的form里,为提交数据做准备,主要用于是手动提交的情况
  7507. * 后台取得数据的键值,使用你容器上的name属性,如果没有就使用参数里的textarea项
  7508. * @method sync
  7509. * @example
  7510. * ```javascript
  7511. * editor.sync();
  7512. * form.sumbit(); //form变量已经指向了form元素
  7513. * ```
  7514. */
  7515. /**
  7516. * 根据传入的formId,在页面上查找要同步数据的表单,若找到,就同步编辑内容到找到的form里,为提交数据做准备
  7517. * 后台取得数据的键值,该键值默认使用给定的编辑器容器的name属性,如果没有name属性则使用参数项里给定的“textarea”项
  7518. * @method sync
  7519. * @param { String } formID 指定一个要同步数据的form的id,编辑器的数据会同步到你指定form下
  7520. */
  7521. sync: function(formId) {
  7522. var me = this,
  7523. form = formId
  7524. ? document.getElementById(formId)
  7525. : domUtils.findParent(
  7526. me.iframe.parentNode,
  7527. function(node) {
  7528. return node.tagName == "FORM";
  7529. },
  7530. true
  7531. );
  7532. form && setValue(form, me);
  7533. },
  7534. /**
  7535. * 设置编辑器高度
  7536. * @method setHeight
  7537. * @remind 当配置项autoHeightEnabled为真时,该方法无效
  7538. * @param { Number } number 设置的高度值,纯数值,不带单位
  7539. * @example
  7540. * ```javascript
  7541. * editor.setHeight(number);
  7542. * ```
  7543. */
  7544. setHeight: function(height, notSetHeight) {
  7545. if (height !== parseInt(this.iframe.parentNode.style.height)) {
  7546. this.iframe.parentNode.style.height = height + "px";
  7547. }
  7548. !notSetHeight &&
  7549. (this.options.minFrameHeight = this.options.initialFrameHeight = height);
  7550. this.body.style.height = height + "px";
  7551. !notSetHeight && this.trigger("setHeight");
  7552. },
  7553. /**
  7554. * 为编辑器的编辑命令提供快捷键
  7555. * 这个接口是为插件扩展提供的接口,主要是为新添加的插件,如果需要添加快捷键,所提供的接口
  7556. * @method addshortcutkey
  7557. * @param { Object } keyset 命令名和快捷键键值对对象,多个按钮的快捷键用“+”分隔
  7558. * @example
  7559. * ```javascript
  7560. * editor.addshortcutkey({
  7561. * "Bold" : "ctrl+66",//^B
  7562. * "Italic" : "ctrl+73", //^I
  7563. * });
  7564. * ```
  7565. */
  7566. /**
  7567. * 这个接口是为插件扩展提供的接口,主要是为新添加的插件,如果需要添加快捷键,所提供的接口
  7568. * @method addshortcutkey
  7569. * @param { String } cmd 触发快捷键时,响应的命令
  7570. * @param { String } keys 快捷键的字符串,多个按钮用“+”分隔
  7571. * @example
  7572. * ```javascript
  7573. * editor.addshortcutkey("Underline", "ctrl+85"); //^U
  7574. * ```
  7575. */
  7576. addshortcutkey: function(cmd, keys) {
  7577. var obj = {};
  7578. if (keys) {
  7579. obj[cmd] = keys;
  7580. } else {
  7581. obj = cmd;
  7582. }
  7583. utils.extend(this.shortcutkeys, obj);
  7584. },
  7585. /**
  7586. * 对编辑器设置keydown事件监听,绑定快捷键和命令,当快捷键组合触发成功,会响应对应的命令
  7587. * @method _bindshortcutKeys
  7588. * @private
  7589. */
  7590. _bindshortcutKeys: function() {
  7591. var me = this,
  7592. shortcutkeys = this.shortcutkeys;
  7593. me.addListener("keydown", function(type, e) {
  7594. var keyCode = e.keyCode || e.which;
  7595. for (var i in shortcutkeys) {
  7596. var tmp = shortcutkeys[i].split(",");
  7597. for (var t = 0, ti; (ti = tmp[t++]); ) {
  7598. ti = ti.split(":");
  7599. var key = ti[0],
  7600. param = ti[1];
  7601. if (
  7602. /^(ctrl)(\+shift)?\+(\d+)$/.test(key.toLowerCase()) ||
  7603. /^(\d+)$/.test(key)
  7604. ) {
  7605. if (
  7606. ((RegExp.$1 == "ctrl" ? e.ctrlKey || e.metaKey : 0) &&
  7607. (RegExp.$2 != "" ? e[RegExp.$2.slice(1) + "Key"] : 1) &&
  7608. keyCode == RegExp.$3) ||
  7609. keyCode == RegExp.$1
  7610. ) {
  7611. if (me.queryCommandState(i, param) != -1)
  7612. me.execCommand(i, param);
  7613. domUtils.preventDefault(e);
  7614. }
  7615. }
  7616. }
  7617. }
  7618. });
  7619. },
  7620. /**
  7621. * 获取编辑器的内容
  7622. * @method getContent
  7623. * @warning 该方法获取到的是经过编辑器内置的过滤规则进行过滤后得到的内容
  7624. * @return { String } 编辑器的内容字符串, 如果编辑器的内容为空,或者是空的标签内容(如:”&lt;p&gt;&lt;br/&gt;&lt;/p&gt;“), 则返回空字符串
  7625. * @example
  7626. * ```javascript
  7627. * //编辑器html内容:<p>1<strong>2<em>34</em>5</strong>6</p>
  7628. * var content = editor.getContent(); //返回值:<p>1<strong>2<em>34</em>5</strong>6</p>
  7629. * ```
  7630. */
  7631. /**
  7632. * 获取编辑器的内容。 可以通过参数定义编辑器内置的判空规则
  7633. * @method getContent
  7634. * @param { Function } fn 自定的判空规则, 要求该方法返回一个boolean类型的值,
  7635. * 代表当前编辑器的内容是否空,
  7636. * 如果返回true, 则该方法将直接返回空字符串;如果返回false,则编辑器将返回
  7637. * 经过内置过滤规则处理后的内容。
  7638. * @remind 该方法在处理包含有初始化内容的时候能起到很好的作用。
  7639. * @warning 该方法获取到的是经过编辑器内置的过滤规则进行过滤后得到的内容
  7640. * @return { String } 编辑器的内容字符串
  7641. * @example
  7642. * ```javascript
  7643. * // editor 是一个编辑器的实例
  7644. * var content = editor.getContent( function ( editor ) {
  7645. * return editor.body.innerHTML === '欢迎使用UEditor'; //返回空字符串
  7646. * } );
  7647. * ```
  7648. */
  7649. getContent: function(cmd, fn, notSetCursor, ignoreBlank, formatter) {
  7650. var me = this;
  7651. if (cmd && utils.isFunction(cmd)) {
  7652. fn = cmd;
  7653. cmd = "";
  7654. }
  7655. if (fn ? !fn() : !this.hasContents()) {
  7656. return "";
  7657. }
  7658. me.fireEvent("beforegetcontent");
  7659. var root = UE.htmlparser(me.body.innerHTML, ignoreBlank);
  7660. me.filterOutputRule(root);
  7661. me.fireEvent("aftergetcontent", cmd, root);
  7662. return root.toHtml(formatter);
  7663. },
  7664. /**
  7665. * 取得完整的html代码,可以直接显示成完整的html文档
  7666. * @method getAllHtml
  7667. * @return { String } 编辑器的内容html文档字符串
  7668. * @eaxmple
  7669. * ```javascript
  7670. * editor.getAllHtml(); //返回格式大致是: <html><head>...</head><body>...</body></html>
  7671. * ```
  7672. */
  7673. getAllHtml: function() {
  7674. var me = this,
  7675. headHtml = [],
  7676. html = "";
  7677. me.fireEvent("getAllHtml", headHtml);
  7678. if (browser.ie && browser.version > 8) {
  7679. var headHtmlForIE9 = "";
  7680. utils.each(me.document.styleSheets, function(si) {
  7681. headHtmlForIE9 += si.href
  7682. ? '<link rel="stylesheet" type="text/css" href="' + si.href + '" />'
  7683. : "<style>" + si.cssText + "</style>";
  7684. });
  7685. utils.each(me.document.getElementsByTagName("script"), function(si) {
  7686. headHtmlForIE9 += si.outerHTML;
  7687. });
  7688. }
  7689. return (
  7690. "<html><head>" +
  7691. (me.options.charset
  7692. ? '<meta http-equiv="Content-Type" content="text/html; charset=' +
  7693. me.options.charset +
  7694. '"/>'
  7695. : "") +
  7696. (headHtmlForIE9 ||
  7697. me.document.getElementsByTagName("head")[0].innerHTML) +
  7698. headHtml.join("\n") +
  7699. "</head>" +
  7700. "<body " +
  7701. (ie && browser.version < 9 ? 'class="view"' : "") +
  7702. ">" +
  7703. me.getContent(null, null, true) +
  7704. "</body></html>"
  7705. );
  7706. },
  7707. /**
  7708. * 得到编辑器的纯文本内容,但会保留段落格式
  7709. * @method getPlainTxt
  7710. * @return { String } 编辑器带段落格式的纯文本内容字符串
  7711. * @example
  7712. * ```javascript
  7713. * //编辑器html内容:<p><strong>1</strong></p><p><strong>2</strong></p>
  7714. * console.log(editor.getPlainTxt()); //输出:"1\n2\n
  7715. * ```
  7716. */
  7717. getPlainTxt: function() {
  7718. var reg = new RegExp(domUtils.fillChar, "g"),
  7719. html = this.body.innerHTML.replace(/[\n\r]/g, ""); //ie要先去了\n在处理
  7720. html = html
  7721. .replace(/<(p|div)[^>]*>(<br\/?>|&nbsp;)<\/\1>/gi, "\n")
  7722. .replace(/<br\/?>/gi, "\n")
  7723. .replace(/<[^>/]+>/g, "")
  7724. .replace(/(\n)?<\/([^>]+)>/g, function(a, b, c) {
  7725. return dtd.$block[c] ? "\n" : b ? b : "";
  7726. });
  7727. //取出来的空格会有c2a0会变成乱码,处理这种情况\u00a0
  7728. return html
  7729. .replace(reg, "")
  7730. .replace(/\u00a0/g, " ")
  7731. .replace(/&nbsp;/g, " ");
  7732. },
  7733. /**
  7734. * 获取编辑器中的纯文本内容,没有段落格式
  7735. * @method getContentTxt
  7736. * @return { String } 编辑器不带段落格式的纯文本内容字符串
  7737. * @example
  7738. * ```javascript
  7739. * //编辑器html内容:<p><strong>1</strong></p><p><strong>2</strong></p>
  7740. * console.log(editor.getPlainTxt()); //输出:"12
  7741. * ```
  7742. */
  7743. getContentTxt: function() {
  7744. var reg = new RegExp(domUtils.fillChar, "g");
  7745. //取出来的空格会有c2a0会变成乱码,处理这种情况\u00a0
  7746. return this.body[browser.ie ? "innerText" : "textContent"]
  7747. .replace(reg, "")
  7748. .replace(/\u00a0/g, " ");
  7749. },
  7750. /**
  7751. * 设置编辑器的内容,可修改编辑器当前的html内容
  7752. * @method setContent
  7753. * @warning 通过该方法插入的内容,是经过编辑器内置的过滤规则进行过滤后得到的内容
  7754. * @warning 该方法会触发selectionchange事件
  7755. * @param { String } html 要插入的html内容
  7756. * @example
  7757. * ```javascript
  7758. * editor.getContent('<p>test</p>');
  7759. * ```
  7760. */
  7761. /**
  7762. * 设置编辑器的内容,可修改编辑器当前的html内容
  7763. * @method setContent
  7764. * @warning 通过该方法插入的内容,是经过编辑器内置的过滤规则进行过滤后得到的内容
  7765. * @warning 该方法会触发selectionchange事件
  7766. * @param { String } html 要插入的html内容
  7767. * @param { Boolean } isAppendTo 若传入true,不清空原来的内容,在最后插入内容,否则,清空内容再插入
  7768. * @example
  7769. * ```javascript
  7770. * //假设设置前的编辑器内容是 <p>old text</p>
  7771. * editor.setContent('<p>new text</p>', true); //插入的结果是<p>old text</p><p>new text</p>
  7772. * ```
  7773. */
  7774. setContent: function(html, isAppendTo, notFireSelectionchange) {
  7775. var me = this;
  7776. me.fireEvent("beforesetcontent", html);
  7777. var root = UE.htmlparser(html);
  7778. me.filterInputRule(root);
  7779. html = root.toHtml();
  7780. me.body.innerHTML = (isAppendTo ? me.body.innerHTML : "") + html;
  7781. function isCdataDiv(node) {
  7782. return node.tagName == "DIV" && node.getAttribute("cdata_tag");
  7783. }
  7784. //给文本或者inline节点套p标签
  7785. if (me.options.enterTag == "p") {
  7786. var child = this.body.firstChild,
  7787. tmpNode;
  7788. if (
  7789. !child ||
  7790. (child.nodeType == 1 &&
  7791. (dtd.$cdata[child.tagName] ||
  7792. isCdataDiv(child) ||
  7793. domUtils.isCustomeNode(child)) &&
  7794. child === this.body.lastChild)
  7795. ) {
  7796. this.body.innerHTML =
  7797. "<p>" +
  7798. (browser.ie ? "&nbsp;" : "<br/>") +
  7799. "</p>" +
  7800. this.body.innerHTML;
  7801. } else {
  7802. var p = me.document.createElement("p");
  7803. while (child) {
  7804. while (
  7805. child &&
  7806. (child.nodeType == 3 ||
  7807. (child.nodeType == 1 &&
  7808. dtd.p[child.tagName] &&
  7809. !dtd.$cdata[child.tagName]))
  7810. ) {
  7811. tmpNode = child.nextSibling;
  7812. p.appendChild(child);
  7813. child = tmpNode;
  7814. }
  7815. if (p.firstChild) {
  7816. if (!child) {
  7817. me.body.appendChild(p);
  7818. break;
  7819. } else {
  7820. child.parentNode.insertBefore(p, child);
  7821. p = me.document.createElement("p");
  7822. }
  7823. }
  7824. child = child.nextSibling;
  7825. }
  7826. }
  7827. }
  7828. me.fireEvent("aftersetcontent");
  7829. me.fireEvent("contentchange");
  7830. !notFireSelectionchange && me._selectionChange();
  7831. //清除保存的选区
  7832. me._bakRange = me._bakIERange = me._bakNativeRange = null;
  7833. //trace:1742 setContent后gecko能得到焦点问题
  7834. var geckoSel;
  7835. if (browser.gecko && (geckoSel = this.selection.getNative())) {
  7836. geckoSel.removeAllRanges();
  7837. }
  7838. if (me.options.autoSyncData) {
  7839. me.form && setValue(me.form, me);
  7840. }
  7841. },
  7842. /**
  7843. * 让编辑器获得焦点,默认focus到编辑器头部
  7844. * @method focus
  7845. * @example
  7846. * ```javascript
  7847. * editor.focus()
  7848. * ```
  7849. */
  7850. /**
  7851. * 让编辑器获得焦点,toEnd确定focus位置
  7852. * @method focus
  7853. * @param { Boolean } toEnd 默认focus到编辑器头部,toEnd为true时focus到内容尾部
  7854. * @example
  7855. * ```javascript
  7856. * editor.focus(true)
  7857. * ```
  7858. */
  7859. focus: function(toEnd) {
  7860. try {
  7861. var me = this,
  7862. rng = me.selection.getRange();
  7863. if (toEnd) {
  7864. var node = me.body.lastChild;
  7865. if (node && node.nodeType == 1 && !dtd.$empty[node.tagName]) {
  7866. if (domUtils.isEmptyBlock(node)) {
  7867. rng.setStartAtFirst(node);
  7868. } else {
  7869. rng.setStartAtLast(node);
  7870. }
  7871. rng.collapse(true);
  7872. }
  7873. rng.setCursor(true);
  7874. } else {
  7875. if (
  7876. !rng.collapsed &&
  7877. domUtils.isBody(rng.startContainer) &&
  7878. rng.startOffset == 0
  7879. ) {
  7880. var node = me.body.firstChild;
  7881. if (node && node.nodeType == 1 && !dtd.$empty[node.tagName]) {
  7882. rng.setStartAtFirst(node).collapse(true);
  7883. }
  7884. }
  7885. rng.select(true);
  7886. }
  7887. this.fireEvent("focus selectionchange");
  7888. } catch (e) {}
  7889. },
  7890. isFocus: function() {
  7891. return this.selection.isFocus();
  7892. },
  7893. blur: function() {
  7894. var sel = this.selection.getNative();
  7895. if (sel.empty && browser.ie) {
  7896. var nativeRng = document.body.createTextRange();
  7897. nativeRng.moveToElementText(document.body);
  7898. nativeRng.collapse(true);
  7899. nativeRng.select();
  7900. sel.empty();
  7901. } else {
  7902. sel.removeAllRanges();
  7903. }
  7904. //this.fireEvent('blur selectionchange');
  7905. },
  7906. /**
  7907. * 初始化UE事件及部分事件代理
  7908. * @method _initEvents
  7909. * @private
  7910. */
  7911. _initEvents: function() {
  7912. var me = this,
  7913. doc = me.document,
  7914. win = me.window;
  7915. me._proxyDomEvent = utils.bind(me._proxyDomEvent, me);
  7916. domUtils.on(
  7917. doc,
  7918. [
  7919. "click",
  7920. "contextmenu",
  7921. "mousedown",
  7922. "keydown",
  7923. "keyup",
  7924. "keypress",
  7925. "mouseup",
  7926. "mouseover",
  7927. "mouseout",
  7928. "selectstart"
  7929. ],
  7930. me._proxyDomEvent
  7931. );
  7932. domUtils.on(win, ["focus", "blur"], me._proxyDomEvent);
  7933. domUtils.on(me.body, "drop", function(e) {
  7934. //阻止ff下默认的弹出新页面打开图片
  7935. if (browser.gecko && e.stopPropagation) {
  7936. e.stopPropagation();
  7937. }
  7938. me.fireEvent("contentchange");
  7939. });
  7940. domUtils.on(doc, ["mouseup", "keydown"], function(evt) {
  7941. //特殊键不触发selectionchange
  7942. if (
  7943. evt.type == "keydown" &&
  7944. (evt.ctrlKey || evt.metaKey || evt.shiftKey || evt.altKey)
  7945. ) {
  7946. return;
  7947. }
  7948. if (evt.button == 2) return;
  7949. me._selectionChange(250, evt);
  7950. });
  7951. },
  7952. /**
  7953. * 触发事件代理
  7954. * @method _proxyDomEvent
  7955. * @private
  7956. * @return { * } fireEvent的返回值
  7957. * @see UE.EventBase:fireEvent(String)
  7958. */
  7959. _proxyDomEvent: function(evt) {
  7960. if (
  7961. this.fireEvent("before" + evt.type.replace(/^on/, "").toLowerCase()) ===
  7962. false
  7963. ) {
  7964. return false;
  7965. }
  7966. if (this.fireEvent(evt.type.replace(/^on/, ""), evt) === false) {
  7967. return false;
  7968. }
  7969. return this.fireEvent(
  7970. "after" + evt.type.replace(/^on/, "").toLowerCase()
  7971. );
  7972. },
  7973. /**
  7974. * 变化选区
  7975. * @method _selectionChange
  7976. * @private
  7977. */
  7978. _selectionChange: function(delay, evt) {
  7979. var me = this;
  7980. //有光标才做selectionchange 为了解决未focus时点击source不能触发更改工具栏状态的问题(source命令notNeedUndo=1)
  7981. // if ( !me.selection.isFocus() ){
  7982. // return;
  7983. // }
  7984. var hackForMouseUp = false;
  7985. var mouseX, mouseY;
  7986. if (browser.ie && browser.version < 9 && evt && evt.type == "mouseup") {
  7987. var range = this.selection.getRange();
  7988. if (!range.collapsed) {
  7989. hackForMouseUp = true;
  7990. mouseX = evt.clientX;
  7991. mouseY = evt.clientY;
  7992. }
  7993. }
  7994. clearTimeout(_selectionChangeTimer);
  7995. _selectionChangeTimer = setTimeout(function() {
  7996. if (!me.selection || !me.selection.getNative()) {
  7997. return;
  7998. }
  7999. //修复一个IE下的bug: 鼠标点击一段已选择的文本中间时,可能在mouseup后的一段时间内取到的range是在selection的type为None下的错误值.
  8000. //IE下如果用户是拖拽一段已选择文本,则不会触发mouseup事件,所以这里的特殊处理不会对其有影响
  8001. var ieRange;
  8002. if (hackForMouseUp && me.selection.getNative().type == "None") {
  8003. ieRange = me.document.body.createTextRange();
  8004. try {
  8005. ieRange.moveToPoint(mouseX, mouseY);
  8006. } catch (ex) {
  8007. ieRange = null;
  8008. }
  8009. }
  8010. var bakGetIERange;
  8011. if (ieRange) {
  8012. bakGetIERange = me.selection.getIERange;
  8013. me.selection.getIERange = function() {
  8014. return ieRange;
  8015. };
  8016. }
  8017. me.selection.cache();
  8018. if (bakGetIERange) {
  8019. me.selection.getIERange = bakGetIERange;
  8020. }
  8021. if (me.selection._cachedRange && me.selection._cachedStartElement) {
  8022. me.fireEvent("beforeselectionchange");
  8023. // 第二个参数causeByUi为true代表由用户交互造成的selectionchange.
  8024. me.fireEvent("selectionchange", !!evt);
  8025. me.fireEvent("afterselectionchange");
  8026. me.selection.clear();
  8027. }
  8028. }, delay || 50);
  8029. },
  8030. /**
  8031. * 执行编辑命令
  8032. * @method _callCmdFn
  8033. * @private
  8034. * @param { String } fnName 函数名称
  8035. * @param { * } args 传给命令函数的参数
  8036. * @return { * } 返回命令函数运行的返回值
  8037. */
  8038. _callCmdFn: function(fnName, args) {
  8039. var cmdName = args[0].toLowerCase(),
  8040. cmd,
  8041. cmdFn;
  8042. cmd = this.commands[cmdName] || UE.commands[cmdName];
  8043. cmdFn = cmd && cmd[fnName];
  8044. //没有querycommandstate或者没有command的都默认返回0
  8045. if ((!cmd || !cmdFn) && fnName == "queryCommandState") {
  8046. return 0;
  8047. } else if (cmdFn) {
  8048. return cmdFn.apply(this, args);
  8049. }
  8050. },
  8051. /**
  8052. * 执行编辑命令cmdName,完成富文本编辑效果
  8053. * @method execCommand
  8054. * @param { String } cmdName 需要执行的命令
  8055. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  8056. * @return { * } 返回命令函数运行的返回值
  8057. * @example
  8058. * ```javascript
  8059. * editor.execCommand(cmdName);
  8060. * ```
  8061. */
  8062. execCommand: function(cmdName) {
  8063. cmdName = cmdName.toLowerCase();
  8064. var me = this;
  8065. var result;
  8066. var cmd = me.commands[cmdName] || UE.commands[cmdName];
  8067. if (!cmd || !cmd.execCommand) {
  8068. return null;
  8069. }
  8070. if (!cmd.notNeedUndo && !me.__hasEnterExecCommand) {
  8071. me.__hasEnterExecCommand = true;
  8072. if (me.queryCommandState.apply(me, arguments) != -1) {
  8073. me.fireEvent("saveScene");
  8074. me.fireEvent.apply(
  8075. me,
  8076. ["beforeexeccommand", cmdName].concat(arguments)
  8077. );
  8078. result = this._callCmdFn("execCommand", arguments);
  8079. //保存场景时,做了内容对比,再看是否进行contentchange触发,这里多触发了一次,去掉
  8080. // (!cmd.ignoreContentChange && !me._ignoreContentChange) && me.fireEvent('contentchange');
  8081. me.fireEvent.apply(
  8082. me,
  8083. ["afterexeccommand", cmdName].concat(arguments)
  8084. );
  8085. me.fireEvent("saveScene");
  8086. }
  8087. me.__hasEnterExecCommand = false;
  8088. } else {
  8089. result = this._callCmdFn("execCommand", arguments);
  8090. !me.__hasEnterExecCommand &&
  8091. !cmd.ignoreContentChange &&
  8092. !me._ignoreContentChange &&
  8093. me.fireEvent("contentchange");
  8094. }
  8095. !me.__hasEnterExecCommand &&
  8096. !cmd.ignoreContentChange &&
  8097. !me._ignoreContentChange &&
  8098. me._selectionChange();
  8099. return result;
  8100. },
  8101. /**
  8102. * 根据传入的command命令,查选编辑器当前的选区,返回命令的状态
  8103. * @method queryCommandState
  8104. * @param { String } cmdName 需要查询的命令名称
  8105. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  8106. * @return { Number } number 返回放前命令的状态,返回值三种情况:(-1|0|1)
  8107. * @example
  8108. * ```javascript
  8109. * editor.queryCommandState(cmdName) => (-1|0|1)
  8110. * ```
  8111. * @see COMMAND.LIST
  8112. */
  8113. queryCommandState: function(cmdName) {
  8114. return this._callCmdFn("queryCommandState", arguments);
  8115. },
  8116. /**
  8117. * 根据传入的command命令,查选编辑器当前的选区,根据命令返回相关的值
  8118. * @method queryCommandValue
  8119. * @param { String } cmdName 需要查询的命令名称
  8120. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  8121. * @remind 只有部分插件有此方法
  8122. * @return { * } 返回每个命令特定的当前状态值
  8123. * @grammar editor.queryCommandValue(cmdName) => {*}
  8124. * @see COMMAND.LIST
  8125. */
  8126. queryCommandValue: function(cmdName) {
  8127. return this._callCmdFn("queryCommandValue", arguments);
  8128. },
  8129. /**
  8130. * 检查编辑区域中是否有内容
  8131. * @method hasContents
  8132. * @remind 默认有文本内容,或者有以下节点都不认为是空
  8133. * table,ul,ol,dl,iframe,area,base,col,hr,img,embed,input,link,meta,param
  8134. * @return { Boolean } 检查有内容返回true,否则返回false
  8135. * @example
  8136. * ```javascript
  8137. * editor.hasContents()
  8138. * ```
  8139. */
  8140. /**
  8141. * 检查编辑区域中是否有内容,若包含参数tags中的节点类型,直接返回true
  8142. * @method hasContents
  8143. * @param { Array } tags 传入数组判断时用到的节点类型
  8144. * @return { Boolean } 若文档中包含tags数组里对应的tag,返回true,否则返回false
  8145. * @example
  8146. * ```javascript
  8147. * editor.hasContents(['span']);
  8148. * ```
  8149. */
  8150. hasContents: function(tags) {
  8151. if (tags) {
  8152. for (var i = 0, ci; (ci = tags[i++]); ) {
  8153. if (this.document.getElementsByTagName(ci).length > 0) {
  8154. return true;
  8155. }
  8156. }
  8157. }
  8158. if (!domUtils.isEmptyBlock(this.body)) {
  8159. return true;
  8160. }
  8161. //随时添加,定义的特殊标签如果存在,不能认为是空
  8162. tags = ["div"];
  8163. for (i = 0; (ci = tags[i++]); ) {
  8164. var nodes = domUtils.getElementsByTagName(this.document, ci);
  8165. for (var n = 0, cn; (cn = nodes[n++]); ) {
  8166. if (domUtils.isCustomeNode(cn)) {
  8167. return true;
  8168. }
  8169. }
  8170. }
  8171. return false;
  8172. },
  8173. /**
  8174. * 重置编辑器,可用来做多个tab使用同一个编辑器实例
  8175. * @method reset
  8176. * @remind 此方法会清空编辑器内容,清空回退列表,会触发reset事件
  8177. * @example
  8178. * ```javascript
  8179. * editor.reset()
  8180. * ```
  8181. */
  8182. reset: function() {
  8183. this.fireEvent("reset");
  8184. },
  8185. /**
  8186. * 设置当前编辑区域可以编辑
  8187. * @method setEnabled
  8188. * @example
  8189. * ```javascript
  8190. * editor.setEnabled()
  8191. * ```
  8192. */
  8193. setEnabled: function() {
  8194. var me = this,
  8195. range;
  8196. if (me.body.contentEditable == "false") {
  8197. me.body.contentEditable = true;
  8198. range = me.selection.getRange();
  8199. //有可能内容丢失了
  8200. try {
  8201. range.moveToBookmark(me.lastBk);
  8202. delete me.lastBk;
  8203. } catch (e) {
  8204. range.setStartAtFirst(me.body).collapse(true);
  8205. }
  8206. range.select(true);
  8207. if (me.bkqueryCommandState) {
  8208. me.queryCommandState = me.bkqueryCommandState;
  8209. delete me.bkqueryCommandState;
  8210. }
  8211. if (me.bkqueryCommandValue) {
  8212. me.queryCommandValue = me.bkqueryCommandValue;
  8213. delete me.bkqueryCommandValue;
  8214. }
  8215. me.fireEvent("selectionchange");
  8216. }
  8217. },
  8218. enable: function() {
  8219. return this.setEnabled();
  8220. },
  8221. /** 设置当前编辑区域不可编辑
  8222. * @method setDisabled
  8223. */
  8224. /** 设置当前编辑区域不可编辑,except中的命令除外
  8225. * @method setDisabled
  8226. * @param { String } except 例外命令的字符串
  8227. * @remind 即使设置了disable,此处配置的例外命令仍然可以执行
  8228. * @example
  8229. * ```javascript
  8230. * editor.setDisabled('bold'); //禁用工具栏中除加粗之外的所有功能
  8231. * ```
  8232. */
  8233. /** 设置当前编辑区域不可编辑,except中的命令除外
  8234. * @method setDisabled
  8235. * @param { Array } except 例外命令的字符串数组,数组中的命令仍然可以执行
  8236. * @remind 即使设置了disable,此处配置的例外命令仍然可以执行
  8237. * @example
  8238. * ```javascript
  8239. * editor.setDisabled(['bold','insertimage']); //禁用工具栏中除加粗和插入图片之外的所有功能
  8240. * ```
  8241. */
  8242. setDisabled: function(except) {
  8243. var me = this;
  8244. except = except ? (utils.isArray(except) ? except : [except]) : [];
  8245. if (me.body.contentEditable == "true") {
  8246. if (!me.lastBk) {
  8247. me.lastBk = me.selection.getRange().createBookmark(true);
  8248. }
  8249. me.body.contentEditable = false;
  8250. me.bkqueryCommandState = me.queryCommandState;
  8251. me.bkqueryCommandValue = me.queryCommandValue;
  8252. me.queryCommandState = function(type) {
  8253. if (utils.indexOf(except, type) != -1) {
  8254. return me.bkqueryCommandState.apply(me, arguments);
  8255. }
  8256. return -1;
  8257. };
  8258. me.queryCommandValue = function(type) {
  8259. if (utils.indexOf(except, type) != -1) {
  8260. return me.bkqueryCommandValue.apply(me, arguments);
  8261. }
  8262. return null;
  8263. };
  8264. me.fireEvent("selectionchange");
  8265. }
  8266. },
  8267. disable: function(except) {
  8268. return this.setDisabled(except);
  8269. },
  8270. /**
  8271. * 设置默认内容
  8272. * @method _setDefaultContent
  8273. * @private
  8274. * @param { String } cont 要存入的内容
  8275. */
  8276. _setDefaultContent: (function() {
  8277. function clear() {
  8278. var me = this;
  8279. if (me.document.getElementById("initContent")) {
  8280. me.body.innerHTML = "<p>" + (ie ? "" : "<br/>") + "</p>";
  8281. me.removeListener("firstBeforeExecCommand focus", clear);
  8282. setTimeout(function() {
  8283. me.focus();
  8284. me._selectionChange();
  8285. }, 0);
  8286. }
  8287. }
  8288. return function(cont) {
  8289. var me = this;
  8290. me.body.innerHTML = '<p id="initContent">' + cont + "</p>";
  8291. me.addListener("firstBeforeExecCommand focus", clear);
  8292. };
  8293. })(),
  8294. /**
  8295. * 显示编辑器
  8296. * @method setShow
  8297. * @example
  8298. * ```javascript
  8299. * editor.setShow()
  8300. * ```
  8301. */
  8302. setShow: function() {
  8303. var me = this,
  8304. range = me.selection.getRange();
  8305. if (me.container.style.display == "none") {
  8306. //有可能内容丢失了
  8307. try {
  8308. range.moveToBookmark(me.lastBk);
  8309. delete me.lastBk;
  8310. } catch (e) {
  8311. range.setStartAtFirst(me.body).collapse(true);
  8312. }
  8313. //ie下focus实效,所以做了个延迟
  8314. setTimeout(function() {
  8315. range.select(true);
  8316. }, 100);
  8317. me.container.style.display = "";
  8318. }
  8319. },
  8320. show: function() {
  8321. return this.setShow();
  8322. },
  8323. /**
  8324. * 隐藏编辑器
  8325. * @method setHide
  8326. * @example
  8327. * ```javascript
  8328. * editor.setHide()
  8329. * ```
  8330. */
  8331. setHide: function() {
  8332. var me = this;
  8333. if (!me.lastBk) {
  8334. me.lastBk = me.selection.getRange().createBookmark(true);
  8335. }
  8336. me.container.style.display = "none";
  8337. },
  8338. hide: function() {
  8339. return this.setHide();
  8340. },
  8341. /**
  8342. * 根据指定的路径,获取对应的语言资源
  8343. * @method getLang
  8344. * @param { String } path 路径根据的是lang目录下的语言文件的路径结构
  8345. * @return { Object | String } 根据路径返回语言资源的Json格式对象或者语言字符串
  8346. * @example
  8347. * ```javascript
  8348. * editor.getLang('contextMenu.delete'); //如果当前是中文,那返回是的是'删除'
  8349. * ```
  8350. */
  8351. getLang: function(path) {
  8352. var lang = UE.I18N[this.options.lang];
  8353. if (!lang) {
  8354. throw Error("not import language file");
  8355. }
  8356. path = (path || "").split(".");
  8357. for (var i = 0, ci; (ci = path[i++]); ) {
  8358. lang = lang[ci];
  8359. if (!lang) break;
  8360. }
  8361. return lang;
  8362. },
  8363. /**
  8364. * 计算编辑器html内容字符串的长度
  8365. * @method getContentLength
  8366. * @return { Number } 返回计算的长度
  8367. * @example
  8368. * ```javascript
  8369. * //编辑器html内容<p><strong>132</strong></p>
  8370. * editor.getContentLength() //返回27
  8371. * ```
  8372. */
  8373. /**
  8374. * 计算编辑器当前纯文本内容的长度
  8375. * @method getContentLength
  8376. * @param { Boolean } ingoneHtml 传入true时,只按照纯文本来计算
  8377. * @return { Number } 返回计算的长度,内容中有hr/img/iframe标签,长度加1
  8378. * @example
  8379. * ```javascript
  8380. * //编辑器html内容<p><strong>132</strong></p>
  8381. * editor.getContentLength() //返回3
  8382. * ```
  8383. */
  8384. getContentLength: function(ingoneHtml, tagNames) {
  8385. var count = this.getContent(false, false, true).length;
  8386. if (ingoneHtml) {
  8387. tagNames = (tagNames || []).concat(["hr", "img", "iframe"]);
  8388. count = this.getContentTxt().replace(/[\t\r\n]+/g, "").length;
  8389. for (var i = 0, ci; (ci = tagNames[i++]); ) {
  8390. count += this.document.getElementsByTagName(ci).length;
  8391. }
  8392. }
  8393. return count;
  8394. },
  8395. /**
  8396. * 注册输入过滤规则
  8397. * @method addInputRule
  8398. * @param { Function } rule 要添加的过滤规则
  8399. * @example
  8400. * ```javascript
  8401. * editor.addInputRule(function(root){
  8402. * $.each(root.getNodesByTagName('div'),function(i,node){
  8403. * node.tagName="p";
  8404. * });
  8405. * });
  8406. * ```
  8407. */
  8408. addInputRule: function(rule) {
  8409. this.inputRules.push(rule);
  8410. },
  8411. /**
  8412. * 执行注册的过滤规则
  8413. * @method filterInputRule
  8414. * @param { UE.uNode } root 要过滤的uNode节点
  8415. * @remind 执行editor.setContent方法和执行'inserthtml'命令后,会运行该过滤函数
  8416. * @example
  8417. * ```javascript
  8418. * editor.filterInputRule(editor.body);
  8419. * ```
  8420. * @see UE.Editor:addInputRule
  8421. */
  8422. filterInputRule: function(root) {
  8423. for (var i = 0, ci; (ci = this.inputRules[i++]); ) {
  8424. ci.call(this, root);
  8425. }
  8426. },
  8427. /**
  8428. * 注册输出过滤规则
  8429. * @method addOutputRule
  8430. * @param { Function } rule 要添加的过滤规则
  8431. * @example
  8432. * ```javascript
  8433. * editor.addOutputRule(function(root){
  8434. * $.each(root.getNodesByTagName('p'),function(i,node){
  8435. * node.tagName="div";
  8436. * });
  8437. * });
  8438. * ```
  8439. */
  8440. addOutputRule: function(rule) {
  8441. this.outputRules.push(rule);
  8442. },
  8443. /**
  8444. * 根据输出过滤规则,过滤编辑器内容
  8445. * @method filterOutputRule
  8446. * @remind 执行editor.getContent方法的时候,会先运行该过滤函数
  8447. * @param { UE.uNode } root 要过滤的uNode节点
  8448. * @example
  8449. * ```javascript
  8450. * editor.filterOutputRule(editor.body);
  8451. * ```
  8452. * @see UE.Editor:addOutputRule
  8453. */
  8454. filterOutputRule: function(root) {
  8455. for (var i = 0, ci; (ci = this.outputRules[i++]); ) {
  8456. ci.call(this, root);
  8457. }
  8458. },
  8459. /**
  8460. * 根据action名称获取请求的路径
  8461. * @method getActionUrl
  8462. * @remind 假如没有设置serverUrl,会根据imageUrl设置默认的controller路径
  8463. * @param { String } action action名称
  8464. * @example
  8465. * ```javascript
  8466. * editor.getActionUrl('config'); //返回 "/ueditor/php/controller.php?action=config"
  8467. * editor.getActionUrl('image'); //返回 "/ueditor/php/controller.php?action=uplaodimage"
  8468. * editor.getActionUrl('scrawl'); //返回 "/ueditor/php/controller.php?action=uplaodscrawl"
  8469. * editor.getActionUrl('imageManager'); //返回 "/ueditor/php/controller.php?action=listimage"
  8470. * ```
  8471. */
  8472. getActionUrl: function(action) {
  8473. var actionName = this.getOpt(action) || action,
  8474. imageUrl = this.getOpt("imageUrl"),
  8475. serverUrl = this.getOpt("serverUrl");
  8476. /* if (!serverUrl && imageUrl) {
  8477. serverUrl = imageUrl.replace(/^(.*[\/]).+([\.].+)$/, "$1controller$2");
  8478. }
  8479. if (serverUrl) {
  8480. serverUrl =
  8481. serverUrl +
  8482. (serverUrl.indexOf("?") == -1 ? "?" : "&") +
  8483. "action=" +
  8484. (actionName || "");
  8485. return utils.formatUrl(serverUrl);
  8486. } else {
  8487. return "";
  8488. } */
  8489. if (serverUrl) {
  8490. serverUrl = serverUrl + "?";
  8491. return utils.formatUrl(serverUrl);
  8492. } else {
  8493. return "";
  8494. }
  8495. }
  8496. };
  8497. utils.inherits(Editor, EventBase);
  8498. })();
  8499. // core/Editor.defaultoptions.js
  8500. //维护编辑器一下默认的不在插件中的配置项
  8501. UE.Editor.defaultOptions = function(editor) {
  8502. var _url = editor.options.UEDITOR_HOME_URL;
  8503. return {
  8504. isShow: true,
  8505. initialContent: "",
  8506. initialStyle: "",
  8507. autoClearinitialContent: false,
  8508. iframeCssUrl: _url + "themes/iframe.css",
  8509. textarea: "editorValue",
  8510. focus: false,
  8511. focusInEnd: true,
  8512. autoClearEmptyNode: true,
  8513. fullscreen: false,
  8514. readonly: false,
  8515. zIndex: 999,
  8516. imagePopup: true,
  8517. enterTag: "p",
  8518. customDomain: false,
  8519. lang: "zh-cn",
  8520. langPath: _url + "i18n/",
  8521. theme: "default",
  8522. themePath: _url + "themes/",
  8523. allHtmlEnabled: false,
  8524. scaleEnabled: false,
  8525. tableNativeEditInFF: false,
  8526. autoSyncData: true,
  8527. fileNameFormat: "{time}{rand:6}"
  8528. };
  8529. };
  8530. // core/loadconfig.js
  8531. ;(function() {
  8532. UE.Editor.prototype.loadServerConfig = function() {
  8533. var me = this;
  8534. setTimeout(function() {
  8535. try {
  8536. me.options.imageUrl &&
  8537. me.setOpt(
  8538. "serverUrl",
  8539. me.options.imageUrl.replace(
  8540. /^(.*[\/]).+([\.].+)$/,
  8541. "$1controller$2"
  8542. )
  8543. );
  8544. var configUrl = me.getActionUrl("config"),
  8545. isJsonp = utils.isCrossDomainUrl(configUrl);
  8546. /* 发出ajax请求 */
  8547. me._serverConfigLoaded = false;
  8548. configUrl &&
  8549. UE.ajax.request(configUrl, {
  8550. method: "GET",
  8551. dataType: isJsonp ? "jsonp" : "",
  8552. onsuccess: function(r) {
  8553. try {
  8554. var config = isJsonp ? r : eval("(" + r.responseText + ")");
  8555. utils.extend(me.options, config);
  8556. me.fireEvent("serverConfigLoaded");
  8557. me._serverConfigLoaded = true;
  8558. } catch (e) {
  8559. showErrorMsg(me.getLang("loadconfigFormatError"));
  8560. }
  8561. },
  8562. onerror: function() {
  8563. showErrorMsg(me.getLang("loadconfigHttpError"));
  8564. }
  8565. });
  8566. } catch (e) {
  8567. showErrorMsg(me.getLang("loadconfigError"));
  8568. }
  8569. });
  8570. function showErrorMsg(msg) {
  8571. console && console.error(msg);
  8572. //me.fireEvent('showMessage', {
  8573. // 'title': msg,
  8574. // 'type': 'error'
  8575. //});
  8576. }
  8577. };
  8578. UE.Editor.prototype.isServerConfigLoaded = function() {
  8579. var me = this;
  8580. return me._serverConfigLoaded || false;
  8581. };
  8582. UE.Editor.prototype.afterConfigReady = function(handler) {
  8583. if (!handler || !utils.isFunction(handler)) return;
  8584. var me = this;
  8585. var readyHandler = function() {
  8586. handler.apply(me, arguments);
  8587. me.removeListener("serverConfigLoaded", readyHandler);
  8588. };
  8589. if (me.isServerConfigLoaded()) {
  8590. handler.call(me, "serverConfigLoaded");
  8591. } else {
  8592. me.addListener("serverConfigLoaded", readyHandler);
  8593. }
  8594. };
  8595. })();
  8596. // core/ajax.js
  8597. /**
  8598. * @file
  8599. * @module UE.ajax
  8600. * @since 1.2.6.1
  8601. */
  8602. /**
  8603. * 提供对ajax请求的支持
  8604. * @module UE.ajax
  8605. */
  8606. UE.ajax = (function() {
  8607. //创建一个ajaxRequest对象
  8608. var fnStr = "XMLHttpRequest()";
  8609. try {
  8610. new ActiveXObject("Msxml2.XMLHTTP");
  8611. fnStr = "ActiveXObject('Msxml2.XMLHTTP')";
  8612. } catch (e) {
  8613. try {
  8614. new ActiveXObject("Microsoft.XMLHTTP");
  8615. fnStr = "ActiveXObject('Microsoft.XMLHTTP')";
  8616. } catch (e) {}
  8617. }
  8618. var creatAjaxRequest = new Function("return new " + fnStr);
  8619. /**
  8620. * 将json参数转化成适合ajax提交的参数列表
  8621. * @param json
  8622. */
  8623. function json2str(json) {
  8624. var strArr = [];
  8625. for (var i in json) {
  8626. //忽略默认的几个参数
  8627. if (
  8628. i == "method" ||
  8629. i == "timeout" ||
  8630. i == "async" ||
  8631. i == "dataType" ||
  8632. i == "callback"
  8633. )
  8634. continue;
  8635. //忽略控制
  8636. if (json[i] == undefined || json[i] == null) continue;
  8637. //传递过来的对象和函数不在提交之列
  8638. if (
  8639. !(
  8640. (typeof json[i]).toLowerCase() == "function" ||
  8641. (typeof json[i]).toLowerCase() == "object"
  8642. )
  8643. ) {
  8644. strArr.push(encodeURIComponent(i) + "=" + encodeURIComponent(json[i]));
  8645. } else if (utils.isArray(json[i])) {
  8646. //支持传数组内容
  8647. for (var j = 0; j < json[i].length; j++) {
  8648. strArr.push(
  8649. encodeURIComponent(i) + "[]=" + encodeURIComponent(json[i][j])
  8650. );
  8651. }
  8652. }
  8653. }
  8654. return strArr.join("&");
  8655. }
  8656. function doAjax(url, ajaxOptions) {
  8657. var xhr = creatAjaxRequest(),
  8658. //是否超时
  8659. timeIsOut = false,
  8660. //默认参数
  8661. defaultAjaxOptions = {
  8662. method: "POST",
  8663. timeout: 5000,
  8664. async: true,
  8665. data: {}, //需要传递对象的话只能覆盖
  8666. onsuccess: function() {},
  8667. onerror: function() {}
  8668. };
  8669. if (typeof url === "object") {
  8670. ajaxOptions = url;
  8671. url = ajaxOptions.url;
  8672. }
  8673. if (!xhr || !url) return;
  8674. var ajaxOpts = ajaxOptions
  8675. ? utils.extend(defaultAjaxOptions, ajaxOptions)
  8676. : defaultAjaxOptions;
  8677. var submitStr = json2str(ajaxOpts); // { name:"Jim",city:"Beijing" } --> "name=Jim&city=Beijing"
  8678. //如果用户直接通过data参数传递json对象过来,则也要将此json对象转化为字符串
  8679. if (!utils.isEmptyObject(ajaxOpts.data)) {
  8680. submitStr += (submitStr ? "&" : "") + json2str(ajaxOpts.data);
  8681. }
  8682. //超时检测
  8683. var timerID = setTimeout(function() {
  8684. if (xhr.readyState != 4) {
  8685. timeIsOut = true;
  8686. xhr.abort();
  8687. clearTimeout(timerID);
  8688. }
  8689. }, ajaxOpts.timeout);
  8690. var method = ajaxOpts.method.toUpperCase();
  8691. var str =
  8692. url +
  8693. (url.indexOf("?") == -1 ? "?" : "&") +
  8694. (method == "POST" ? "" : submitStr + "&noCache=" + +new Date());
  8695. xhr.open(method, str, ajaxOpts.async);
  8696. xhr.onreadystatechange = function() {
  8697. if (xhr.readyState == 4) {
  8698. if (!timeIsOut && xhr.status == 200) {
  8699. ajaxOpts.onsuccess(xhr);
  8700. } else {
  8701. ajaxOpts.onerror(xhr);
  8702. }
  8703. }
  8704. };
  8705. if (method == "POST") {
  8706. xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  8707. xhr.send(submitStr);
  8708. } else {
  8709. xhr.send(null);
  8710. }
  8711. }
  8712. function doJsonp(url, opts) {
  8713. var successhandler = opts.onsuccess || function() {},
  8714. scr = document.createElement("SCRIPT"),
  8715. options = opts || {},
  8716. charset = options["charset"],
  8717. callbackField = options["jsonp"] || "callback",
  8718. callbackFnName,
  8719. timeOut = options["timeOut"] || 0,
  8720. timer,
  8721. reg = new RegExp("(\\?|&)" + callbackField + "=([^&]*)"),
  8722. matches;
  8723. if (utils.isFunction(successhandler)) {
  8724. callbackFnName =
  8725. "bd__editor__" + Math.floor(Math.random() * 2147483648).toString(36);
  8726. window[callbackFnName] = getCallBack(0);
  8727. } else if (utils.isString(successhandler)) {
  8728. callbackFnName = successhandler;
  8729. } else {
  8730. if ((matches = reg.exec(url))) {
  8731. callbackFnName = matches[2];
  8732. }
  8733. }
  8734. url = url.replace(reg, "\x241" + callbackField + "=" + callbackFnName);
  8735. if (url.search(reg) < 0) {
  8736. url +=
  8737. (url.indexOf("?") < 0 ? "?" : "&") +
  8738. callbackField +
  8739. "=" +
  8740. callbackFnName;
  8741. }
  8742. var queryStr = json2str(opts); // { name:"Jim",city:"Beijing" } --> "name=Jim&city=Beijing"
  8743. //如果用户直接通过data参数传递json对象过来,则也要将此json对象转化为字符串
  8744. if (!utils.isEmptyObject(opts.data)) {
  8745. queryStr += (queryStr ? "&" : "") + json2str(opts.data);
  8746. }
  8747. if (queryStr) {
  8748. url = url.replace(/\?/, "?" + queryStr + "&");
  8749. }
  8750. scr.onerror = getCallBack(1);
  8751. if (timeOut) {
  8752. timer = setTimeout(getCallBack(1), timeOut);
  8753. }
  8754. createScriptTag(scr, url, charset);
  8755. function createScriptTag(scr, url, charset) {
  8756. scr.setAttribute("type", "text/javascript");
  8757. scr.setAttribute("defer", "defer");
  8758. charset && scr.setAttribute("charset", charset);
  8759. scr.setAttribute("src", url);
  8760. document.getElementsByTagName("head")[0].appendChild(scr);
  8761. }
  8762. function getCallBack(onTimeOut) {
  8763. return function() {
  8764. try {
  8765. if (onTimeOut) {
  8766. options.onerror && options.onerror();
  8767. } else {
  8768. try {
  8769. clearTimeout(timer);
  8770. successhandler.apply(window, arguments);
  8771. } catch (e) {}
  8772. }
  8773. } catch (exception) {
  8774. options.onerror && options.onerror.call(window, exception);
  8775. } finally {
  8776. options.oncomplete && options.oncomplete.apply(window, arguments);
  8777. scr.parentNode && scr.parentNode.removeChild(scr);
  8778. window[callbackFnName] = null;
  8779. try {
  8780. delete window[callbackFnName];
  8781. } catch (e) {}
  8782. }
  8783. };
  8784. }
  8785. }
  8786. return {
  8787. /**
  8788. * 根据给定的参数项,向指定的url发起一个ajax请求。 ajax请求完成后,会根据请求结果调用相应回调: 如果请求
  8789. * 成功, 则调用onsuccess回调, 失败则调用 onerror 回调
  8790. * @method request
  8791. * @param { URLString } url ajax请求的url地址
  8792. * @param { Object } ajaxOptions ajax请求选项的键值对,支持的选项如下:
  8793. * @example
  8794. * ```javascript
  8795. * //向sayhello.php发起一个异步的Ajax GET请求, 请求超时时间为10s, 请求完成后执行相应的回调。
  8796. * UE.ajax.requeset( 'sayhello.php', {
  8797. *
  8798. * //请求方法。可选值: 'GET', 'POST',默认值是'POST'
  8799. * method: 'GET',
  8800. *
  8801. * //超时时间。 默认为5000, 单位是ms
  8802. * timeout: 10000,
  8803. *
  8804. * //是否是异步请求。 true为异步请求, false为同步请求
  8805. * async: true,
  8806. *
  8807. * //请求携带的数据。如果请求为GET请求, data会经过stringify后附加到请求url之后。
  8808. * data: {
  8809. * name: 'neditor'
  8810. * },
  8811. *
  8812. * //请求成功后的回调, 该回调接受当前的XMLHttpRequest对象作为参数。
  8813. * onsuccess: function ( xhr ) {
  8814. * console.log( xhr.responseText );
  8815. * },
  8816. *
  8817. * //请求失败或者超时后的回调。
  8818. * onerror: function ( xhr ) {
  8819. * alert( 'Ajax请求失败' );
  8820. * }
  8821. *
  8822. * } );
  8823. * ```
  8824. */
  8825. /**
  8826. * 根据给定的参数项发起一个ajax请求, 参数项里必须包含一个url地址。 ajax请求完成后,会根据请求结果调用相应回调: 如果请求
  8827. * 成功, 则调用onsuccess回调, 失败则调用 onerror 回调。
  8828. * @method request
  8829. * @warning 如果在参数项里未提供一个key为“url”的地址值,则该请求将直接退出。
  8830. * @param { Object } ajaxOptions ajax请求选项的键值对,支持的选项如下:
  8831. * @example
  8832. * ```javascript
  8833. *
  8834. * //向sayhello.php发起一个异步的Ajax POST请求, 请求超时时间为5s, 请求完成后不执行任何回调。
  8835. * UE.ajax.requeset( 'sayhello.php', {
  8836. *
  8837. * //请求的地址, 该项是必须的。
  8838. * url: 'sayhello.php'
  8839. *
  8840. * } );
  8841. * ```
  8842. */
  8843. request: function(url, opts) {
  8844. if (opts && opts.dataType == "jsonp") {
  8845. doJsonp(url, opts);
  8846. } else {
  8847. doAjax(url, opts);
  8848. }
  8849. },
  8850. getJSONP: function(url, data, fn) {
  8851. var opts = {
  8852. data: data,
  8853. oncomplete: fn
  8854. };
  8855. doJsonp(url, opts);
  8856. }
  8857. };
  8858. })();
  8859. // core/filterword.js
  8860. /**
  8861. * UE过滤word的静态方法
  8862. * @file
  8863. */
  8864. /**
  8865. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  8866. * @module UE
  8867. */
  8868. /**
  8869. * 根据传入html字符串过滤word
  8870. * @module UE
  8871. * @since 1.2.6.1
  8872. * @method filterWord
  8873. * @param { String } html html字符串
  8874. * @return { String } 已过滤后的结果字符串
  8875. * @example
  8876. * ```javascript
  8877. * UE.filterWord(html);
  8878. * ```
  8879. */
  8880. var filterWord = (UE.filterWord = (function() {
  8881. //是否是word过来的内容
  8882. function isWordDocument(str) {
  8883. return /(class="?Mso|style="[^"]*\bmso\-|w:WordDocument|<(v|o):|lang=)/gi.test(
  8884. str
  8885. );
  8886. }
  8887. //去掉小数
  8888. function transUnit(v) {
  8889. v = v.replace(/[\d.]+\w+/g, function(m) {
  8890. return utils.transUnitToPx(m);
  8891. });
  8892. return v;
  8893. }
  8894. function filterPasteWord(str) {
  8895. return (
  8896. str
  8897. .replace(/[\t\r\n]+/g, " ")
  8898. .replace(/<!--[\s\S]*?-->/gi, "")
  8899. //转换图片
  8900. .replace(/<v:shape [^>]*>[\s\S]*?.<\/v:shape>/gi, function(str) {
  8901. //opera能自己解析出image所这里直接返回空
  8902. if (browser.opera) {
  8903. return "";
  8904. }
  8905. try {
  8906. //有可能是bitmap占为图,无用,直接过滤掉,主要体现在粘贴excel表格中
  8907. if (/Bitmap/i.test(str)) {
  8908. return "";
  8909. }
  8910. var width = str.match(/width:([ \d.]*p[tx])/i)[1],
  8911. height = str.match(/height:([ \d.]*p[tx])/i)[1],
  8912. src = str.match(/src=\s*"([^"]*)"/i)[1];
  8913. return (
  8914. '<img width="' +
  8915. transUnit(width) +
  8916. '" height="' +
  8917. transUnit(height) +
  8918. '" src="' +
  8919. src +
  8920. '" />'
  8921. );
  8922. } catch (e) {
  8923. return "";
  8924. }
  8925. })
  8926. //针对wps添加的多余标签处理
  8927. .replace(/<\/?div[^>]*>/g, "")
  8928. //去掉多余的属性
  8929. .replace(/v:\w+=(["']?)[^'"]+\1/g, "")
  8930. .replace(
  8931. /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|xml|meta|link|style|\w+:\w+)(?=[\s\/>]))[^>]*>/gi,
  8932. ""
  8933. )
  8934. .replace(
  8935. /<p [^>]*class="?MsoHeading"?[^>]*>(.*?)<\/p>/gi,
  8936. "<p><strong>$1</strong></p>"
  8937. )
  8938. //去掉多余的属性
  8939. .replace(/\s+(class|lang|align)\s*=\s*(['"]?)([\w-]+)\2/gi, function(
  8940. str,
  8941. name,
  8942. marks,
  8943. val
  8944. ) {
  8945. //保留list的标示
  8946. return name == "class" && val == "MsoListParagraph" ? str : "";
  8947. })
  8948. //清除多余的font/span不能匹配&nbsp;有可能是空格
  8949. .replace(/<(font|span)[^>]*>(\s*)<\/\1>/gi, function(a, b, c) {
  8950. return c.replace(/[\t\r\n ]+/g, " ");
  8951. })
  8952. //处理style的问题
  8953. .replace(/(<[a-z][^>]*)\sstyle=(["'])([^\2]*?)\2/gi, function(
  8954. str,
  8955. tag,
  8956. tmp,
  8957. style
  8958. ) {
  8959. var n = [],
  8960. s = style
  8961. .replace(/^\s+|\s+$/, "")
  8962. .replace(/&#39;/g, "'")
  8963. .replace(/&quot;/gi, "'")
  8964. .replace(/[\d.]+(cm|pt)/g, function(str) {
  8965. return utils.transUnitToPx(str);
  8966. })
  8967. .split(/;\s*/g);
  8968. for (var i = 0, v; (v = s[i]); i++) {
  8969. var name,
  8970. value,
  8971. parts = v.split(":");
  8972. if (parts.length == 2) {
  8973. name = parts[0].toLowerCase();
  8974. value = parts[1].toLowerCase();
  8975. if (
  8976. (/^(background)\w*/.test(name) &&
  8977. value.replace(/(initial|\s)/g, "").length == 0) ||
  8978. (/^(margin)\w*/.test(name) && /^0\w+$/.test(value))
  8979. ) {
  8980. continue;
  8981. }
  8982. switch (name) {
  8983. case "mso-padding-alt":
  8984. case "mso-padding-top-alt":
  8985. case "mso-padding-right-alt":
  8986. case "mso-padding-bottom-alt":
  8987. case "mso-padding-left-alt":
  8988. case "mso-margin-alt":
  8989. case "mso-margin-top-alt":
  8990. case "mso-margin-right-alt":
  8991. case "mso-margin-bottom-alt":
  8992. case "mso-margin-left-alt":
  8993. //ie下会出现挤到一起的情况
  8994. //case "mso-table-layout-alt":
  8995. case "mso-height":
  8996. case "mso-width":
  8997. case "mso-vertical-align-alt":
  8998. //trace:1819 ff下会解析出padding在table上
  8999. if (!/<table/.test(tag))
  9000. n[i] =
  9001. name.replace(/^mso-|-alt$/g, "") + ":" + transUnit(value);
  9002. continue;
  9003. case "horiz-align":
  9004. n[i] = "text-align:" + value;
  9005. continue;
  9006. case "vert-align":
  9007. n[i] = "vertical-align:" + value;
  9008. continue;
  9009. case "font-color":
  9010. case "mso-foreground":
  9011. n[i] = "color:" + value;
  9012. continue;
  9013. case "mso-background":
  9014. case "mso-highlight":
  9015. n[i] = "background:" + value;
  9016. continue;
  9017. case "mso-default-height":
  9018. n[i] = "min-height:" + transUnit(value);
  9019. continue;
  9020. case "mso-default-width":
  9021. n[i] = "min-width:" + transUnit(value);
  9022. continue;
  9023. case "mso-padding-between-alt":
  9024. n[i] =
  9025. "border-collapse:separate;border-spacing:" +
  9026. transUnit(value);
  9027. continue;
  9028. case "text-line-through":
  9029. if (value == "single" || value == "double") {
  9030. n[i] = "text-decoration:line-through";
  9031. }
  9032. continue;
  9033. case "mso-zero-height":
  9034. if (value == "yes") {
  9035. n[i] = "display:none";
  9036. }
  9037. continue;
  9038. // case 'background':
  9039. // break;
  9040. case "margin":
  9041. if (!/[1-9]/.test(value)) {
  9042. continue;
  9043. }
  9044. }
  9045. if (
  9046. /^(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(
  9047. name
  9048. ) ||
  9049. (/text\-indent|padding|margin/.test(name) &&
  9050. /\-[\d.]+/.test(value))
  9051. ) {
  9052. continue;
  9053. }
  9054. n[i] = name + ":" + parts[1];
  9055. }
  9056. }
  9057. return (
  9058. tag +
  9059. (n.length
  9060. ? ' style="' + n.join(";").replace(/;{2,}/g, ";") + '"'
  9061. : "")
  9062. );
  9063. })
  9064. );
  9065. }
  9066. return function(html) {
  9067. return isWordDocument(html) ? filterPasteWord(html) : html;
  9068. };
  9069. })());
  9070. // core/node.js
  9071. /**
  9072. * 编辑器模拟的节点类
  9073. * @file
  9074. * @module UE
  9075. * @class uNode
  9076. * @since 1.2.6.1
  9077. */
  9078. /**
  9079. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  9080. * @unfile
  9081. * @module UE
  9082. */
  9083. ;(function() {
  9084. /**
  9085. * 编辑器模拟的节点类
  9086. * @unfile
  9087. * @module UE
  9088. * @class uNode
  9089. */
  9090. /**
  9091. * 通过一个键值对,创建一个uNode对象
  9092. * @constructor
  9093. * @param { Object } attr 传入要创建的uNode的初始属性
  9094. * @example
  9095. * ```javascript
  9096. * var node = new uNode({
  9097. * type:'element',
  9098. * tagName:'span',
  9099. * attrs:{style:'font-size:14px;'}
  9100. * })
  9101. * ```
  9102. */
  9103. var uNode = (UE.uNode = function(obj) {
  9104. this.type = obj.type;
  9105. this.data = obj.data;
  9106. this.tagName = obj.tagName;
  9107. this.parentNode = obj.parentNode;
  9108. this.attrs = obj.attrs || {};
  9109. this.children = obj.children;
  9110. });
  9111. var notTransAttrs = {
  9112. href: 1,
  9113. src: 1,
  9114. _src: 1,
  9115. _href: 1,
  9116. cdata_data: 1
  9117. };
  9118. var notTransTagName = {
  9119. style: 1,
  9120. script: 1
  9121. };
  9122. var indentChar = " ",
  9123. breakChar = "\n";
  9124. function insertLine(arr, current, begin) {
  9125. arr.push(breakChar);
  9126. return current + (begin ? 1 : -1);
  9127. }
  9128. function insertIndent(arr, current) {
  9129. //插入缩进
  9130. for (var i = 0; i < current; i++) {
  9131. arr.push(indentChar);
  9132. }
  9133. }
  9134. //创建uNode的静态方法
  9135. //支持标签和html
  9136. uNode.createElement = function(html) {
  9137. if (/[<>]/.test(html)) {
  9138. return UE.htmlparser(html).children[0];
  9139. } else {
  9140. return new uNode({
  9141. type: "element",
  9142. children: [],
  9143. tagName: html
  9144. });
  9145. }
  9146. };
  9147. uNode.createText = function(data, noTrans) {
  9148. return new UE.uNode({
  9149. type: "text",
  9150. data: noTrans ? data : utils.unhtml(data || "")
  9151. });
  9152. };
  9153. function nodeToHtml(node, arr, formatter, current) {
  9154. switch (node.type) {
  9155. case "root":
  9156. for (var i = 0, ci; (ci = node.children[i++]); ) {
  9157. //插入新行
  9158. if (
  9159. formatter &&
  9160. ci.type == "element" &&
  9161. !dtd.$inlineWithA[ci.tagName] &&
  9162. i > 1
  9163. ) {
  9164. insertLine(arr, current, true);
  9165. insertIndent(arr, current);
  9166. }
  9167. nodeToHtml(ci, arr, formatter, current);
  9168. }
  9169. break;
  9170. case "text":
  9171. isText(node, arr);
  9172. break;
  9173. case "element":
  9174. isElement(node, arr, formatter, current);
  9175. break;
  9176. case "comment":
  9177. isComment(node, arr, formatter);
  9178. }
  9179. return arr;
  9180. }
  9181. function isText(node, arr) {
  9182. if (node.parentNode.tagName == "pre") {
  9183. //源码模式下输入html标签,不能做转换处理,直接输出
  9184. arr.push(node.data);
  9185. } else {
  9186. arr.push(
  9187. notTransTagName[node.parentNode.tagName]
  9188. ? utils.html(node.data)
  9189. : node.data.replace(/[ ]{2}/g, " &nbsp;")
  9190. );
  9191. }
  9192. }
  9193. function isElement(node, arr, formatter, current) {
  9194. var attrhtml = "";
  9195. if (node.attrs) {
  9196. attrhtml = [];
  9197. var attrs = node.attrs;
  9198. for (var a in attrs) {
  9199. //这里就针对
  9200. //<p>'<img src='http://nsclick.baidu.com/u.gif?&asdf=\"sdf&asdfasdfs;asdf'></p>
  9201. //这里边的\"做转换,要不用innerHTML直接被截断了,属性src
  9202. //有可能做的不够
  9203. attrhtml.push(
  9204. a +
  9205. (attrs[a] !== undefined
  9206. ? '="' +
  9207. (notTransAttrs[a]
  9208. ? utils.html(attrs[a]).replace(/["]/g, function(a) {
  9209. return "&quot;";
  9210. })
  9211. : utils.unhtml(attrs[a])) +
  9212. '"'
  9213. : "")
  9214. );
  9215. }
  9216. attrhtml = attrhtml.join(" ");
  9217. }
  9218. arr.push(
  9219. "<" +
  9220. node.tagName +
  9221. (attrhtml ? " " + attrhtml : "") +
  9222. (dtd.$empty[node.tagName] ? "/" : "") +
  9223. ">"
  9224. );
  9225. //插入新行
  9226. if (formatter && !dtd.$inlineWithA[node.tagName] && node.tagName != "pre") {
  9227. if (node.children && node.children.length) {
  9228. current = insertLine(arr, current, true);
  9229. insertIndent(arr, current);
  9230. }
  9231. }
  9232. if (node.children && node.children.length) {
  9233. for (var i = 0, ci; (ci = node.children[i++]); ) {
  9234. if (
  9235. formatter &&
  9236. ci.type == "element" &&
  9237. !dtd.$inlineWithA[ci.tagName] &&
  9238. i > 1
  9239. ) {
  9240. insertLine(arr, current);
  9241. insertIndent(arr, current);
  9242. }
  9243. nodeToHtml(ci, arr, formatter, current);
  9244. }
  9245. }
  9246. if (!dtd.$empty[node.tagName]) {
  9247. if (
  9248. formatter &&
  9249. !dtd.$inlineWithA[node.tagName] &&
  9250. node.tagName != "pre"
  9251. ) {
  9252. if (node.children && node.children.length) {
  9253. current = insertLine(arr, current);
  9254. insertIndent(arr, current);
  9255. }
  9256. }
  9257. arr.push("</" + node.tagName + ">");
  9258. }
  9259. }
  9260. function isComment(node, arr) {
  9261. arr.push("<!--" + node.data + "-->");
  9262. }
  9263. function getNodeById(root, id) {
  9264. var node;
  9265. if (root.type == "element" && root.getAttr("id") == id) {
  9266. return root;
  9267. }
  9268. if (root.children && root.children.length) {
  9269. for (var i = 0, ci; (ci = root.children[i++]); ) {
  9270. if ((node = getNodeById(ci, id))) {
  9271. return node;
  9272. }
  9273. }
  9274. }
  9275. }
  9276. function getNodesByTagName(node, tagName, arr) {
  9277. if (node.type == "element" && node.tagName == tagName) {
  9278. arr.push(node);
  9279. }
  9280. if (node.children && node.children.length) {
  9281. for (var i = 0, ci; (ci = node.children[i++]); ) {
  9282. getNodesByTagName(ci, tagName, arr);
  9283. }
  9284. }
  9285. }
  9286. function nodeTraversal(root, fn) {
  9287. if (root.children && root.children.length) {
  9288. for (var i = 0, ci; (ci = root.children[i]); ) {
  9289. nodeTraversal(ci, fn);
  9290. //ci被替换的情况,这里就不再走 fn了
  9291. if (ci.parentNode) {
  9292. if (ci.children && ci.children.length) {
  9293. fn(ci);
  9294. }
  9295. if (ci.parentNode) i++;
  9296. }
  9297. }
  9298. } else {
  9299. fn(root);
  9300. }
  9301. }
  9302. uNode.prototype = {
  9303. /**
  9304. * 当前节点对象,转换成html文本
  9305. * @method toHtml
  9306. * @return { String } 返回转换后的html字符串
  9307. * @example
  9308. * ```javascript
  9309. * node.toHtml();
  9310. * ```
  9311. */
  9312. /**
  9313. * 当前节点对象,转换成html文本
  9314. * @method toHtml
  9315. * @param { Boolean } formatter 是否格式化返回值
  9316. * @return { String } 返回转换后的html字符串
  9317. * @example
  9318. * ```javascript
  9319. * node.toHtml( true );
  9320. * ```
  9321. */
  9322. toHtml: function(formatter) {
  9323. var arr = [];
  9324. nodeToHtml(this, arr, formatter, 0);
  9325. return arr.join("");
  9326. },
  9327. /**
  9328. * 获取节点的html内容
  9329. * @method innerHTML
  9330. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  9331. * @return { String } 返回节点的html内容
  9332. * @example
  9333. * ```javascript
  9334. * var htmlstr = node.innerHTML();
  9335. * ```
  9336. */
  9337. /**
  9338. * 设置节点的html内容
  9339. * @method innerHTML
  9340. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  9341. * @param { String } htmlstr 传入要设置的html内容
  9342. * @return { UE.uNode } 返回节点本身
  9343. * @example
  9344. * ```javascript
  9345. * node.innerHTML('<span>text</span>');
  9346. * ```
  9347. */
  9348. innerHTML: function(htmlstr) {
  9349. if (this.type != "element" || dtd.$empty[this.tagName]) {
  9350. return this;
  9351. }
  9352. if (utils.isString(htmlstr)) {
  9353. if (this.children) {
  9354. for (var i = 0, ci; (ci = this.children[i++]); ) {
  9355. ci.parentNode = null;
  9356. }
  9357. }
  9358. this.children = [];
  9359. var tmpRoot = UE.htmlparser(htmlstr);
  9360. for (var i = 0, ci; (ci = tmpRoot.children[i++]); ) {
  9361. this.children.push(ci);
  9362. ci.parentNode = this;
  9363. }
  9364. return this;
  9365. } else {
  9366. var tmpRoot = new UE.uNode({
  9367. type: "root",
  9368. children: this.children
  9369. });
  9370. return tmpRoot.toHtml();
  9371. }
  9372. },
  9373. /**
  9374. * 获取节点的纯文本内容
  9375. * @method innerText
  9376. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  9377. * @return { String } 返回节点的存文本内容
  9378. * @example
  9379. * ```javascript
  9380. * var textStr = node.innerText();
  9381. * ```
  9382. */
  9383. /**
  9384. * 设置节点的纯文本内容
  9385. * @method innerText
  9386. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  9387. * @param { String } textStr 传入要设置的文本内容
  9388. * @return { UE.uNode } 返回节点本身
  9389. * @example
  9390. * ```javascript
  9391. * node.innerText('<span>text</span>');
  9392. * ```
  9393. */
  9394. innerText: function(textStr, noTrans) {
  9395. if (this.type != "element" || dtd.$empty[this.tagName]) {
  9396. return this;
  9397. }
  9398. if (textStr) {
  9399. if (this.children) {
  9400. for (var i = 0, ci; (ci = this.children[i++]); ) {
  9401. ci.parentNode = null;
  9402. }
  9403. }
  9404. this.children = [];
  9405. this.appendChild(uNode.createText(textStr, noTrans));
  9406. return this;
  9407. } else {
  9408. return this.toHtml().replace(/<[^>]+>/g, "");
  9409. }
  9410. },
  9411. /**
  9412. * 获取当前对象的data属性
  9413. * @method getData
  9414. * @return { Object } 若节点的type值是elemenet,返回空字符串,否则返回节点的data属性
  9415. * @example
  9416. * ```javascript
  9417. * node.getData();
  9418. * ```
  9419. */
  9420. getData: function() {
  9421. if (this.type == "element") return "";
  9422. return this.data;
  9423. },
  9424. /**
  9425. * 获取当前节点下的第一个子节点
  9426. * @method firstChild
  9427. * @return { UE.uNode } 返回第一个子节点
  9428. * @example
  9429. * ```javascript
  9430. * node.firstChild(); //返回第一个子节点
  9431. * ```
  9432. */
  9433. firstChild: function() {
  9434. // if (this.type != 'element' || dtd.$empty[this.tagName]) {
  9435. // return this;
  9436. // }
  9437. return this.children ? this.children[0] : null;
  9438. },
  9439. /**
  9440. * 获取当前节点下的最后一个子节点
  9441. * @method lastChild
  9442. * @return { UE.uNode } 返回最后一个子节点
  9443. * @example
  9444. * ```javascript
  9445. * node.lastChild(); //返回最后一个子节点
  9446. * ```
  9447. */
  9448. lastChild: function() {
  9449. // if (this.type != 'element' || dtd.$empty[this.tagName] ) {
  9450. // return this;
  9451. // }
  9452. return this.children ? this.children[this.children.length - 1] : null;
  9453. },
  9454. /**
  9455. * 获取和当前节点有相同父亲节点的前一个节点
  9456. * @method previousSibling
  9457. * @return { UE.uNode } 返回前一个节点
  9458. * @example
  9459. * ```javascript
  9460. * node.children[2].previousSibling(); //返回子节点node.children[1]
  9461. * ```
  9462. */
  9463. previousSibling: function() {
  9464. var parent = this.parentNode;
  9465. for (var i = 0, ci; (ci = parent.children[i]); i++) {
  9466. if (ci === this) {
  9467. return i == 0 ? null : parent.children[i - 1];
  9468. }
  9469. }
  9470. },
  9471. /**
  9472. * 获取和当前节点有相同父亲节点的后一个节点
  9473. * @method nextSibling
  9474. * @return { UE.uNode } 返回后一个节点,找不到返回null
  9475. * @example
  9476. * ```javascript
  9477. * node.children[2].nextSibling(); //如果有,返回子节点node.children[3]
  9478. * ```
  9479. */
  9480. nextSibling: function() {
  9481. var parent = this.parentNode;
  9482. for (var i = 0, ci; (ci = parent.children[i++]); ) {
  9483. if (ci === this) {
  9484. return parent.children[i];
  9485. }
  9486. }
  9487. },
  9488. /**
  9489. * 用新的节点替换当前节点
  9490. * @method replaceChild
  9491. * @param { UE.uNode } target 要替换成该节点参数
  9492. * @param { UE.uNode } source 要被替换掉的节点
  9493. * @return { UE.uNode } 返回替换之后的节点对象
  9494. * @example
  9495. * ```javascript
  9496. * node.replaceChild(newNode, childNode); //用newNode替换childNode,childNode是node的子节点
  9497. * ```
  9498. */
  9499. replaceChild: function(target, source) {
  9500. if (this.children) {
  9501. if (target.parentNode) {
  9502. target.parentNode.removeChild(target);
  9503. }
  9504. for (var i = 0, ci; (ci = this.children[i]); i++) {
  9505. if (ci === source) {
  9506. this.children.splice(i, 1, target);
  9507. source.parentNode = null;
  9508. target.parentNode = this;
  9509. return target;
  9510. }
  9511. }
  9512. }
  9513. },
  9514. /**
  9515. * 在节点的子节点列表最后位置插入一个节点
  9516. * @method appendChild
  9517. * @param { UE.uNode } node 要插入的节点
  9518. * @return { UE.uNode } 返回刚插入的子节点
  9519. * @example
  9520. * ```javascript
  9521. * node.appendChild( newNode ); //在node内插入子节点newNode
  9522. * ```
  9523. */
  9524. appendChild: function(node) {
  9525. if (
  9526. this.type == "root" ||
  9527. (this.type == "element" && !dtd.$empty[this.tagName])
  9528. ) {
  9529. if (!this.children) {
  9530. this.children = [];
  9531. }
  9532. if (node.parentNode) {
  9533. node.parentNode.removeChild(node);
  9534. }
  9535. for (var i = 0, ci; (ci = this.children[i]); i++) {
  9536. if (ci === node) {
  9537. this.children.splice(i, 1);
  9538. break;
  9539. }
  9540. }
  9541. this.children.push(node);
  9542. node.parentNode = this;
  9543. return node;
  9544. }
  9545. },
  9546. /**
  9547. * 在传入节点的前面插入一个节点
  9548. * @method insertBefore
  9549. * @param { UE.uNode } target 要插入的节点
  9550. * @param { UE.uNode } source 在该参数节点前面插入
  9551. * @return { UE.uNode } 返回刚插入的子节点
  9552. * @example
  9553. * ```javascript
  9554. * node.parentNode.insertBefore(newNode, node); //在node节点后面插入newNode
  9555. * ```
  9556. */
  9557. insertBefore: function(target, source) {
  9558. if (this.children) {
  9559. if (target.parentNode) {
  9560. target.parentNode.removeChild(target);
  9561. }
  9562. for (var i = 0, ci; (ci = this.children[i]); i++) {
  9563. if (ci === source) {
  9564. this.children.splice(i, 0, target);
  9565. target.parentNode = this;
  9566. return target;
  9567. }
  9568. }
  9569. }
  9570. },
  9571. /**
  9572. * 在传入节点的后面插入一个节点
  9573. * @method insertAfter
  9574. * @param { UE.uNode } target 要插入的节点
  9575. * @param { UE.uNode } source 在该参数节点后面插入
  9576. * @return { UE.uNode } 返回刚插入的子节点
  9577. * @example
  9578. * ```javascript
  9579. * node.parentNode.insertAfter(newNode, node); //在node节点后面插入newNode
  9580. * ```
  9581. */
  9582. insertAfter: function(target, source) {
  9583. if (this.children) {
  9584. if (target.parentNode) {
  9585. target.parentNode.removeChild(target);
  9586. }
  9587. for (var i = 0, ci; (ci = this.children[i]); i++) {
  9588. if (ci === source) {
  9589. this.children.splice(i + 1, 0, target);
  9590. target.parentNode = this;
  9591. return target;
  9592. }
  9593. }
  9594. }
  9595. },
  9596. /**
  9597. * 从当前节点的子节点列表中,移除节点
  9598. * @method removeChild
  9599. * @param { UE.uNode } node 要移除的节点引用
  9600. * @param { Boolean } keepChildren 是否保留移除节点的子节点,若传入true,自动把移除节点的子节点插入到移除的位置
  9601. * @return { * } 返回刚移除的子节点
  9602. * @example
  9603. * ```javascript
  9604. * node.removeChild(childNode,true); //在node的子节点列表中移除child节点,并且吧child的子节点插入到移除的位置
  9605. * ```
  9606. */
  9607. removeChild: function(node, keepChildren) {
  9608. if (this.children) {
  9609. for (var i = 0, ci; (ci = this.children[i]); i++) {
  9610. if (ci === node) {
  9611. this.children.splice(i, 1);
  9612. ci.parentNode = null;
  9613. if (keepChildren && ci.children && ci.children.length) {
  9614. for (var j = 0, cj; (cj = ci.children[j]); j++) {
  9615. this.children.splice(i + j, 0, cj);
  9616. cj.parentNode = this;
  9617. }
  9618. }
  9619. return ci;
  9620. }
  9621. }
  9622. }
  9623. },
  9624. /**
  9625. * 获取当前节点所代表的元素属性,即获取attrs对象下的属性值
  9626. * @method getAttr
  9627. * @param { String } attrName 要获取的属性名称
  9628. * @return { * } 返回attrs对象下的属性值
  9629. * @example
  9630. * ```javascript
  9631. * node.getAttr('title');
  9632. * ```
  9633. */
  9634. getAttr: function(attrName) {
  9635. return this.attrs && this.attrs[attrName.toLowerCase()];
  9636. },
  9637. /**
  9638. * 设置当前节点所代表的元素属性,即设置attrs对象下的属性值
  9639. * @method setAttr
  9640. * @param { String } attrName 要设置的属性名称
  9641. * @param { * } attrVal 要设置的属性值,类型视设置的属性而定
  9642. * @return { * } 返回attrs对象下的属性值
  9643. * @example
  9644. * ```javascript
  9645. * node.setAttr('title','标题');
  9646. * ```
  9647. */
  9648. setAttr: function(attrName, attrVal) {
  9649. if (!attrName) {
  9650. delete this.attrs;
  9651. return;
  9652. }
  9653. if (!this.attrs) {
  9654. this.attrs = {};
  9655. }
  9656. if (utils.isObject(attrName)) {
  9657. for (var a in attrName) {
  9658. if (!attrName[a]) {
  9659. delete this.attrs[a];
  9660. } else {
  9661. this.attrs[a.toLowerCase()] = attrName[a];
  9662. }
  9663. }
  9664. } else {
  9665. if (!attrVal) {
  9666. delete this.attrs[attrName];
  9667. } else {
  9668. this.attrs[attrName.toLowerCase()] = attrVal;
  9669. }
  9670. }
  9671. },
  9672. /**
  9673. * 获取当前节点在父节点下的位置索引
  9674. * @method getIndex
  9675. * @return { Number } 返回索引数值,如果没有父节点,返回-1
  9676. * @example
  9677. * ```javascript
  9678. * node.getIndex();
  9679. * ```
  9680. */
  9681. getIndex: function() {
  9682. var parent = this.parentNode;
  9683. for (var i = 0, ci; (ci = parent.children[i]); i++) {
  9684. if (ci === this) {
  9685. return i;
  9686. }
  9687. }
  9688. return -1;
  9689. },
  9690. /**
  9691. * 在当前节点下,根据id查找节点
  9692. * @method getNodeById
  9693. * @param { String } id 要查找的id
  9694. * @return { UE.uNode } 返回找到的节点
  9695. * @example
  9696. * ```javascript
  9697. * node.getNodeById('textId');
  9698. * ```
  9699. */
  9700. getNodeById: function(id) {
  9701. var node;
  9702. if (this.children && this.children.length) {
  9703. for (var i = 0, ci; (ci = this.children[i++]); ) {
  9704. if ((node = getNodeById(ci, id))) {
  9705. return node;
  9706. }
  9707. }
  9708. }
  9709. },
  9710. /**
  9711. * 在当前节点下,根据元素名称查找节点列表
  9712. * @method getNodesByTagName
  9713. * @param { String } tagNames 要查找的元素名称
  9714. * @return { Array } 返回找到的节点列表
  9715. * @example
  9716. * ```javascript
  9717. * node.getNodesByTagName('span');
  9718. * ```
  9719. */
  9720. getNodesByTagName: function(tagNames) {
  9721. tagNames = utils.trim(tagNames).replace(/[ ]{2,}/g, " ").split(" ");
  9722. var arr = [],
  9723. me = this;
  9724. utils.each(tagNames, function(tagName) {
  9725. if (me.children && me.children.length) {
  9726. for (var i = 0, ci; (ci = me.children[i++]); ) {
  9727. getNodesByTagName(ci, tagName, arr);
  9728. }
  9729. }
  9730. });
  9731. return arr;
  9732. },
  9733. /**
  9734. * 根据样式名称,获取节点的样式值
  9735. * @method getStyle
  9736. * @param { String } name 要获取的样式名称
  9737. * @return { String } 返回样式值
  9738. * @example
  9739. * ```javascript
  9740. * node.getStyle('font-size');
  9741. * ```
  9742. */
  9743. getStyle: function(name) {
  9744. var cssStyle = this.getAttr("style");
  9745. if (!cssStyle) {
  9746. return "";
  9747. }
  9748. var reg = new RegExp("(^|;)\\s*" + name + ":([^;]+)", "i");
  9749. var match = cssStyle.match(reg);
  9750. if (match && match[0]) {
  9751. return match[2];
  9752. }
  9753. return "";
  9754. },
  9755. /**
  9756. * 给节点设置样式
  9757. * @method setStyle
  9758. * @param { String } name 要设置的的样式名称
  9759. * @param { String } val 要设置的的样值
  9760. * @example
  9761. * ```javascript
  9762. * node.setStyle('font-size', '12px');
  9763. * ```
  9764. */
  9765. setStyle: function(name, val) {
  9766. function exec(name, val) {
  9767. var reg = new RegExp("(^|;)\\s*" + name + ":([^;]+;?)", "gi");
  9768. cssStyle = cssStyle.replace(reg, "$1");
  9769. if (val) {
  9770. cssStyle = name + ":" + utils.unhtml(val) + ";" + cssStyle;
  9771. }
  9772. }
  9773. var cssStyle = this.getAttr("style");
  9774. if (!cssStyle) {
  9775. cssStyle = "";
  9776. }
  9777. if (utils.isObject(name)) {
  9778. for (var a in name) {
  9779. exec(a, name[a]);
  9780. }
  9781. } else {
  9782. exec(name, val);
  9783. }
  9784. this.setAttr("style", utils.trim(cssStyle));
  9785. },
  9786. /**
  9787. * 传入一个函数,递归遍历当前节点下的所有节点
  9788. * @method traversal
  9789. * @param { Function } fn 遍历到节点的时,传入节点作为参数,运行此函数
  9790. * @example
  9791. * ```javascript
  9792. * traversal(node, function(){
  9793. * console.log(node.type);
  9794. * });
  9795. * ```
  9796. */
  9797. traversal: function(fn) {
  9798. if (this.children && this.children.length) {
  9799. nodeTraversal(this, fn);
  9800. }
  9801. return this;
  9802. }
  9803. };
  9804. })();
  9805. // core/htmlparser.js
  9806. /**
  9807. * html字符串转换成uNode节点
  9808. * @file
  9809. * @module UE
  9810. * @since 1.2.6.1
  9811. */
  9812. /**
  9813. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  9814. * @unfile
  9815. * @module UE
  9816. */
  9817. /**
  9818. * html字符串转换成uNode节点的静态方法
  9819. * @method htmlparser
  9820. * @param { String } htmlstr 要转换的html代码
  9821. * @param { Boolean } ignoreBlank 若设置为true,转换的时候忽略\n\r\t等空白字符
  9822. * @return { uNode } 给定的html片段转换形成的uNode对象
  9823. * @example
  9824. * ```javascript
  9825. * var root = UE.htmlparser('<p><b>htmlparser</b></p>', true);
  9826. * ```
  9827. */
  9828. var htmlparser = (UE.htmlparser = function(htmlstr, ignoreBlank) {
  9829. //todo 原来的方式 [^"'<>\/] 有\/就不能配对上 <TD vAlign=top background=../AAA.JPG> 这样的标签了
  9830. //先去掉了,加上的原因忘了,这里先记录
  9831. //var re_tag = /<(?:(?:\/([^>]+)>)|(?:!--([\S|\s]*?)-->)|(?:([^\s\/<>]+)\s*((?:(?:"[^"]*")|(?:'[^']*')|[^"'<>])*)\/?>))/g,
  9832. //以上的正则表达式无法匹配:<div style="text-align:center;font-family:" font-size:14px;"=""><img src="http://hs-album.oss.aliyuncs.com/static/27/78/35/image/20161206/20161206174331_41105.gif" alt="" /><br /></div>
  9833. //修改为如下正则表达式:
  9834. var re_tag = /<(?:(?:\/([^>]+)>)|(?:!--([\S|\s]*?)-->)|(?:([^\/\s>]+)((?:\s+[\w\-:.]+(?:\s*=\s*?(?:(?:"[^"]*")|(?:'[^']*')|[^\s"'\/>]+))?)*)[\S\s]*?(\/?)>))/g,
  9835. re_attr = /([\w\-:.]+)(?:(?:\s*=\s*(?:(?:"([^"]*)")|(?:'([^']*)')|([^\s>]+)))|(?=\s|$))/g;
  9836. //ie下取得的html可能会有\n存在,要去掉,在处理replace(/[\t\r\n]*/g,'');代码高量的\n不能去除
  9837. var allowEmptyTags = {
  9838. b: 1,
  9839. code: 1,
  9840. i: 1,
  9841. u: 1,
  9842. strike: 1,
  9843. s: 1,
  9844. tt: 1,
  9845. strong: 1,
  9846. q: 1,
  9847. samp: 1,
  9848. em: 1,
  9849. span: 1,
  9850. sub: 1,
  9851. img: 1,
  9852. sup: 1,
  9853. font: 1,
  9854. big: 1,
  9855. small: 1,
  9856. iframe: 1,
  9857. a: 1,
  9858. br: 1,
  9859. pre: 1
  9860. };
  9861. htmlstr = htmlstr.replace(new RegExp(domUtils.fillChar, "g"), "");
  9862. if (!ignoreBlank) {
  9863. htmlstr = htmlstr.replace(
  9864. new RegExp(
  9865. "[\\r\\t\\n" +
  9866. (ignoreBlank ? "" : " ") +
  9867. "]*</?(\\w+)\\s*(?:[^>]*)>[\\r\\t\\n" +
  9868. (ignoreBlank ? "" : " ") +
  9869. "]*",
  9870. "g"
  9871. ),
  9872. function(a, b) {
  9873. //br暂时单独处理
  9874. if (b && allowEmptyTags[b.toLowerCase()]) {
  9875. return a.replace(/(^[\n\r]+)|([\n\r]+$)/g, "");
  9876. }
  9877. return a
  9878. .replace(new RegExp("^[\\r\\n" + (ignoreBlank ? "" : " ") + "]+"), "")
  9879. .replace(
  9880. new RegExp("[\\r\\n" + (ignoreBlank ? "" : " ") + "]+$"),
  9881. ""
  9882. );
  9883. }
  9884. );
  9885. }
  9886. var notTransAttrs = {
  9887. href: 1,
  9888. src: 1
  9889. };
  9890. var uNode = UE.uNode,
  9891. needParentNode = {
  9892. td: "tr",
  9893. tr: ["tbody", "thead", "tfoot"],
  9894. tbody: "table",
  9895. th: "tr",
  9896. thead: "table",
  9897. tfoot: "table",
  9898. caption: "table",
  9899. li: ["ul", "ol"],
  9900. dt: "dl",
  9901. dd: "dl",
  9902. option: "select"
  9903. },
  9904. needChild = {
  9905. ol: "li",
  9906. ul: "li"
  9907. };
  9908. function text(parent, data) {
  9909. if (needChild[parent.tagName]) {
  9910. var tmpNode = uNode.createElement(needChild[parent.tagName]);
  9911. parent.appendChild(tmpNode);
  9912. tmpNode.appendChild(uNode.createText(data));
  9913. parent = tmpNode;
  9914. } else {
  9915. parent.appendChild(uNode.createText(data));
  9916. }
  9917. }
  9918. function element(parent, tagName, htmlattr) {
  9919. var needParentTag;
  9920. if ((needParentTag = needParentNode[tagName])) {
  9921. var tmpParent = parent,
  9922. hasParent;
  9923. while (tmpParent.type != "root") {
  9924. if (
  9925. utils.isArray(needParentTag)
  9926. ? utils.indexOf(needParentTag, tmpParent.tagName) != -1
  9927. : needParentTag == tmpParent.tagName
  9928. ) {
  9929. parent = tmpParent;
  9930. hasParent = true;
  9931. break;
  9932. }
  9933. tmpParent = tmpParent.parentNode;
  9934. }
  9935. if (!hasParent) {
  9936. parent = element(
  9937. parent,
  9938. utils.isArray(needParentTag) ? needParentTag[0] : needParentTag
  9939. );
  9940. }
  9941. }
  9942. //按dtd处理嵌套
  9943. // if(parent.type != 'root' && !dtd[parent.tagName][tagName])
  9944. // parent = parent.parentNode;
  9945. var elm = new uNode({
  9946. parentNode: parent,
  9947. type: "element",
  9948. tagName: tagName.toLowerCase(),
  9949. //是自闭合的处理一下
  9950. children: dtd.$empty[tagName] ? null : []
  9951. });
  9952. //如果属性存在,处理属性
  9953. if (htmlattr) {
  9954. var attrs = {},
  9955. match;
  9956. while ((match = re_attr.exec(htmlattr))) {
  9957. attrs[match[1].toLowerCase()] = notTransAttrs[match[1].toLowerCase()]
  9958. ? match[2] || match[3] || match[4]
  9959. : utils.unhtml(match[2] || match[3] || match[4]);
  9960. }
  9961. elm.attrs = attrs;
  9962. }
  9963. //trace:3970
  9964. // //如果parent下不能放elm
  9965. // if(dtd.$inline[parent.tagName] && dtd.$block[elm.tagName] && !dtd[parent.tagName][elm.tagName]){
  9966. // parent = parent.parentNode;
  9967. // elm.parentNode = parent;
  9968. // }
  9969. parent.children.push(elm);
  9970. //如果是自闭合节点返回父亲节点
  9971. return dtd.$empty[tagName] ? parent : elm;
  9972. }
  9973. function comment(parent, data) {
  9974. parent.children.push(
  9975. new uNode({
  9976. type: "comment",
  9977. data: data,
  9978. parentNode: parent
  9979. })
  9980. );
  9981. }
  9982. var match,
  9983. currentIndex = 0,
  9984. nextIndex = 0;
  9985. //设置根节点
  9986. var root = new uNode({
  9987. type: "root",
  9988. children: []
  9989. });
  9990. var currentParent = root;
  9991. while ((match = re_tag.exec(htmlstr))) {
  9992. currentIndex = match.index;
  9993. try {
  9994. if (currentIndex > nextIndex) {
  9995. //text node
  9996. text(currentParent, htmlstr.slice(nextIndex, currentIndex));
  9997. }
  9998. if (match[3]) {
  9999. if (dtd.$cdata[currentParent.tagName]) {
  10000. text(currentParent, match[0]);
  10001. } else {
  10002. //start tag
  10003. currentParent = element(
  10004. currentParent,
  10005. match[3].toLowerCase(),
  10006. match[4]
  10007. );
  10008. }
  10009. } else if (match[1]) {
  10010. if (currentParent.type != "root") {
  10011. if (dtd.$cdata[currentParent.tagName] && !dtd.$cdata[match[1]]) {
  10012. text(currentParent, match[0]);
  10013. } else {
  10014. var tmpParent = currentParent;
  10015. while (
  10016. currentParent.type == "element" &&
  10017. currentParent.tagName != match[1].toLowerCase()
  10018. ) {
  10019. currentParent = currentParent.parentNode;
  10020. if (currentParent.type == "root") {
  10021. currentParent = tmpParent;
  10022. throw "break";
  10023. }
  10024. }
  10025. //end tag
  10026. currentParent = currentParent.parentNode;
  10027. }
  10028. }
  10029. } else if (match[2]) {
  10030. //comment
  10031. comment(currentParent, match[2]);
  10032. }
  10033. } catch (e) {}
  10034. nextIndex = re_tag.lastIndex;
  10035. }
  10036. //如果结束是文本,就有可能丢掉,所以这里手动判断一下
  10037. //例如 <li>sdfsdfsdf<li>sdfsdfsdfsdf
  10038. if (nextIndex < htmlstr.length) {
  10039. text(currentParent, htmlstr.slice(nextIndex));
  10040. }
  10041. return root;
  10042. });
  10043. // core/filternode.js
  10044. /**
  10045. * UE过滤节点的静态方法
  10046. * @file
  10047. */
  10048. /**
  10049. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  10050. * @module UE
  10051. */
  10052. /**
  10053. * 根据传入节点和过滤规则过滤相应节点
  10054. * @module UE
  10055. * @since 1.2.6.1
  10056. * @method filterNode
  10057. * @param { Object } root 指定root节点
  10058. * @param { Object } rules 过滤规则json对象
  10059. * @example
  10060. * ```javascript
  10061. * UE.filterNode(root,editor.options.filterRules);
  10062. * ```
  10063. */
  10064. var filterNode = (UE.filterNode = (function() {
  10065. function filterNode(node, rules) {
  10066. switch (node.type) {
  10067. case "text":
  10068. break;
  10069. case "element":
  10070. var val;
  10071. if ((val = rules[node.tagName])) {
  10072. if (val === "-") {
  10073. node.parentNode.removeChild(node);
  10074. } else if (utils.isFunction(val)) {
  10075. var parentNode = node.parentNode,
  10076. index = node.getIndex();
  10077. val(node);
  10078. if (node.parentNode) {
  10079. if (node.children) {
  10080. for (var i = 0, ci; (ci = node.children[i]); ) {
  10081. filterNode(ci, rules);
  10082. if (ci.parentNode) {
  10083. i++;
  10084. }
  10085. }
  10086. }
  10087. } else {
  10088. for (var i = index, ci; (ci = parentNode.children[i]); ) {
  10089. filterNode(ci, rules);
  10090. if (ci.parentNode) {
  10091. i++;
  10092. }
  10093. }
  10094. }
  10095. } else {
  10096. var attrs = val["$"];
  10097. if (attrs && node.attrs) {
  10098. var tmpAttrs = {},
  10099. tmpVal;
  10100. for (var a in attrs) {
  10101. tmpVal = node.getAttr(a);
  10102. //todo 只先对style单独处理
  10103. if (a == "style" && utils.isArray(attrs[a])) {
  10104. var tmpCssStyle = [];
  10105. utils.each(attrs[a], function(v) {
  10106. var tmp;
  10107. if ((tmp = node.getStyle(v))) {
  10108. tmpCssStyle.push(v + ":" + tmp);
  10109. }
  10110. });
  10111. tmpVal = tmpCssStyle.join(";");
  10112. }
  10113. if (tmpVal) {
  10114. tmpAttrs[a] = tmpVal;
  10115. }
  10116. }
  10117. node.attrs = tmpAttrs;
  10118. }
  10119. if (node.children) {
  10120. for (var i = 0, ci; (ci = node.children[i]); ) {
  10121. filterNode(ci, rules);
  10122. if (ci.parentNode) {
  10123. i++;
  10124. }
  10125. }
  10126. }
  10127. }
  10128. } else {
  10129. //如果不在名单里扣出子节点并删除该节点,cdata除外
  10130. if (dtd.$cdata[node.tagName]) {
  10131. node.parentNode.removeChild(node);
  10132. } else {
  10133. var parentNode = node.parentNode,
  10134. index = node.getIndex();
  10135. node.parentNode.removeChild(node, true);
  10136. for (var i = index, ci; (ci = parentNode.children[i]); ) {
  10137. filterNode(ci, rules);
  10138. if (ci.parentNode) {
  10139. i++;
  10140. }
  10141. }
  10142. }
  10143. }
  10144. break;
  10145. case "comment":
  10146. node.parentNode.removeChild(node);
  10147. }
  10148. }
  10149. return function(root, rules) {
  10150. if (utils.isEmptyObject(rules)) {
  10151. return root;
  10152. }
  10153. var val;
  10154. if ((val = rules["-"])) {
  10155. utils.each(val.split(" "), function(k) {
  10156. rules[k] = "-";
  10157. });
  10158. }
  10159. for (var i = 0, ci; (ci = root.children[i]); ) {
  10160. filterNode(ci, rules);
  10161. if (ci.parentNode) {
  10162. i++;
  10163. }
  10164. }
  10165. return root;
  10166. };
  10167. })());
  10168. // core/plugin.js
  10169. /**
  10170. * Created with JetBrains PhpStorm.
  10171. * User: campaign
  10172. * Date: 10/8/13
  10173. * Time: 6:15 PM
  10174. * To change this template use File | Settings | File Templates.
  10175. */
  10176. UE.plugin = (function() {
  10177. var _plugins = {};
  10178. return {
  10179. register: function(pluginName, fn, oldOptionName, afterDisabled) {
  10180. if (oldOptionName && utils.isFunction(oldOptionName)) {
  10181. afterDisabled = oldOptionName;
  10182. oldOptionName = null;
  10183. }
  10184. _plugins[pluginName] = {
  10185. optionName: oldOptionName || pluginName,
  10186. execFn: fn,
  10187. //当插件被禁用时执行
  10188. afterDisabled: afterDisabled
  10189. };
  10190. },
  10191. load: function(editor) {
  10192. utils.each(_plugins, function(plugin) {
  10193. var _export = plugin.execFn.call(editor);
  10194. if (editor.options[plugin.optionName] !== false) {
  10195. if (_export) {
  10196. //后边需要再做扩展
  10197. utils.each(_export, function(v, k) {
  10198. switch (k.toLowerCase()) {
  10199. case "shortcutkey":
  10200. editor.addshortcutkey(v);
  10201. break;
  10202. case "bindevents":
  10203. utils.each(v, function(fn, eventName) {
  10204. editor.addListener(eventName, fn);
  10205. });
  10206. break;
  10207. case "bindmultievents":
  10208. utils.each(utils.isArray(v) ? v : [v], function(event) {
  10209. var types = utils.trim(event.type).split(/\s+/);
  10210. utils.each(types, function(eventName) {
  10211. editor.addListener(eventName, event.handler);
  10212. });
  10213. });
  10214. break;
  10215. case "commands":
  10216. utils.each(v, function(execFn, execName) {
  10217. editor.commands[execName] = execFn;
  10218. });
  10219. break;
  10220. case "outputrule":
  10221. editor.addOutputRule(v);
  10222. break;
  10223. case "inputrule":
  10224. editor.addInputRule(v);
  10225. break;
  10226. case "defaultoptions":
  10227. editor.setOpt(v);
  10228. }
  10229. });
  10230. }
  10231. } else if (plugin.afterDisabled) {
  10232. plugin.afterDisabled.call(editor);
  10233. }
  10234. });
  10235. //向下兼容
  10236. utils.each(UE.plugins, function(plugin) {
  10237. plugin.call(editor);
  10238. });
  10239. },
  10240. run: function(pluginName, editor) {
  10241. var plugin = _plugins[pluginName];
  10242. if (plugin) {
  10243. plugin.exeFn.call(editor);
  10244. }
  10245. }
  10246. };
  10247. })();
  10248. // core/keymap.js
  10249. var keymap = (UE.keymap = {
  10250. Backspace: 8,
  10251. Tab: 9,
  10252. Enter: 13,
  10253. Shift: 16,
  10254. Control: 17,
  10255. Alt: 18,
  10256. CapsLock: 20,
  10257. Esc: 27,
  10258. Spacebar: 32,
  10259. PageUp: 33,
  10260. PageDown: 34,
  10261. End: 35,
  10262. Home: 36,
  10263. Left: 37,
  10264. Up: 38,
  10265. Right: 39,
  10266. Down: 40,
  10267. Insert: 45,
  10268. Del: 46,
  10269. NumLock: 144,
  10270. Cmd: 91,
  10271. "=": 187,
  10272. "-": 189,
  10273. b: 66,
  10274. i: 73,
  10275. //回退
  10276. z: 90,
  10277. y: 89,
  10278. //粘贴
  10279. v: 86,
  10280. x: 88,
  10281. s: 83,
  10282. n: 78
  10283. });
  10284. // core/localstorage.js
  10285. //存储媒介封装
  10286. var LocalStorage = (UE.LocalStorage = (function() {
  10287. var storage = window.localStorage || getUserData() || null,
  10288. LOCAL_FILE = "localStorage";
  10289. return {
  10290. saveLocalData: function(key, data) {
  10291. if (storage && data) {
  10292. storage.setItem(key, data);
  10293. return true;
  10294. }
  10295. return false;
  10296. },
  10297. getLocalData: function(key) {
  10298. if (storage) {
  10299. return storage.getItem(key);
  10300. }
  10301. return null;
  10302. },
  10303. removeItem: function(key) {
  10304. storage && storage.removeItem(key);
  10305. }
  10306. };
  10307. function getUserData() {
  10308. var container = document.createElement("div");
  10309. container.style.display = "none";
  10310. if (!container.addBehavior) {
  10311. return null;
  10312. }
  10313. container.addBehavior("#default#userdata");
  10314. return {
  10315. getItem: function(key) {
  10316. var result = null;
  10317. try {
  10318. document.body.appendChild(container);
  10319. container.load(LOCAL_FILE);
  10320. result = container.getAttribute(key);
  10321. document.body.removeChild(container);
  10322. } catch (e) {}
  10323. return result;
  10324. },
  10325. setItem: function(key, value) {
  10326. document.body.appendChild(container);
  10327. container.setAttribute(key, value);
  10328. container.save(LOCAL_FILE);
  10329. document.body.removeChild(container);
  10330. },
  10331. //// 暂时没有用到
  10332. //clear: function () {
  10333. //
  10334. // var expiresTime = new Date();
  10335. // expiresTime.setFullYear(expiresTime.getFullYear() - 1);
  10336. // document.body.appendChild(container);
  10337. // container.expires = expiresTime.toUTCString();
  10338. // container.save(LOCAL_FILE);
  10339. // document.body.removeChild(container);
  10340. //
  10341. //},
  10342. removeItem: function(key) {
  10343. document.body.appendChild(container);
  10344. container.removeAttribute(key);
  10345. container.save(LOCAL_FILE);
  10346. document.body.removeChild(container);
  10347. }
  10348. };
  10349. }
  10350. })());
  10351. ;(function() {
  10352. var ROOTKEY = "ueditor_preference";
  10353. UE.Editor.prototype.setPreferences = function(key, value) {
  10354. var obj = {};
  10355. if (utils.isString(key)) {
  10356. obj[key] = value;
  10357. } else {
  10358. obj = key;
  10359. }
  10360. var data = LocalStorage.getLocalData(ROOTKEY);
  10361. if (data && (data = utils.str2json(data))) {
  10362. utils.extend(data, obj);
  10363. } else {
  10364. data = obj;
  10365. }
  10366. data && LocalStorage.saveLocalData(ROOTKEY, utils.json2str(data));
  10367. };
  10368. UE.Editor.prototype.getPreferences = function(key) {
  10369. var data = LocalStorage.getLocalData(ROOTKEY);
  10370. if (data && (data = utils.str2json(data))) {
  10371. return key ? data[key] : data;
  10372. }
  10373. return null;
  10374. };
  10375. UE.Editor.prototype.removePreferences = function(key) {
  10376. var data = LocalStorage.getLocalData(ROOTKEY);
  10377. if (data && (data = utils.str2json(data))) {
  10378. data[key] = undefined;
  10379. delete data[key];
  10380. }
  10381. data && LocalStorage.saveLocalData(ROOTKEY, utils.json2str(data));
  10382. };
  10383. })();
  10384. // plugins/defaultfilter.js
  10385. ///import core
  10386. ///plugin 编辑器默认的过滤转换机制
  10387. UE.plugins["defaultfilter"] = function() {
  10388. var me = this;
  10389. me.setOpt({
  10390. allowDivTransToP: true,
  10391. disabledTableInTable: true,
  10392. rgb2Hex: true
  10393. });
  10394. //默认的过滤处理
  10395. //进入编辑器的内容处理
  10396. me.addInputRule(function(root) {
  10397. var allowDivTransToP = this.options.allowDivTransToP;
  10398. var val;
  10399. function tdParent(node) {
  10400. while (node && node.type == "element") {
  10401. if (node.tagName == "td") {
  10402. return true;
  10403. }
  10404. node = node.parentNode;
  10405. }
  10406. return false;
  10407. }
  10408. //进行默认的处理
  10409. root.traversal(function(node) {
  10410. if (node.type == "element") {
  10411. if (
  10412. !dtd.$cdata[node.tagName] &&
  10413. me.options.autoClearEmptyNode &&
  10414. dtd.$inline[node.tagName] &&
  10415. !dtd.$empty[node.tagName] &&
  10416. (!node.attrs || utils.isEmptyObject(node.attrs))
  10417. ) {
  10418. if (!node.firstChild()) node.parentNode.removeChild(node);
  10419. else if (
  10420. node.tagName == "span" &&
  10421. (!node.attrs || utils.isEmptyObject(node.attrs))
  10422. ) {
  10423. node.parentNode.removeChild(node, true);
  10424. }
  10425. return;
  10426. }
  10427. switch (node.tagName) {
  10428. case "style":
  10429. case "script":
  10430. node.setAttr({
  10431. cdata_tag: node.tagName,
  10432. cdata_data: node.innerHTML() || "",
  10433. _ue_custom_node_: "true"
  10434. });
  10435. node.tagName = "div";
  10436. node.innerHTML("");
  10437. break;
  10438. case "a":
  10439. if ((val = node.getAttr("href"))) {
  10440. node.setAttr("_href", val);
  10441. }
  10442. break;
  10443. case "img":
  10444. //todo base64暂时去掉,后边做远程图片上传后,干掉这个
  10445. if ((val = node.getAttr("src"))) {
  10446. if (/^data:/.test(val)) {
  10447. node.parentNode.removeChild(node);
  10448. break;
  10449. }
  10450. }
  10451. node.setAttr("_src", node.getAttr("src"));
  10452. break;
  10453. case "span":
  10454. if (browser.webkit && (val = node.getStyle("white-space"))) {
  10455. if (/nowrap|normal/.test(val)) {
  10456. node.setStyle("white-space", "");
  10457. if (
  10458. me.options.autoClearEmptyNode &&
  10459. utils.isEmptyObject(node.attrs)
  10460. ) {
  10461. node.parentNode.removeChild(node, true);
  10462. }
  10463. }
  10464. }
  10465. val = node.getAttr("id");
  10466. if (val && /^_baidu_bookmark_/i.test(val)) {
  10467. node.parentNode.removeChild(node);
  10468. }
  10469. break;
  10470. case "p":
  10471. if ((val = node.getAttr("align"))) {
  10472. node.setAttr("align");
  10473. node.setStyle("text-align", val);
  10474. }
  10475. //trace:3431
  10476. // var cssStyle = node.getAttr('style');
  10477. // if (cssStyle) {
  10478. // cssStyle = cssStyle.replace(/(margin|padding)[^;]+/g, '');
  10479. // node.setAttr('style', cssStyle)
  10480. //
  10481. // }
  10482. //p标签不允许嵌套
  10483. utils.each(node.children, function(n) {
  10484. if (n.type == "element" && n.tagName == "p") {
  10485. var next = n.nextSibling();
  10486. node.parentNode.insertAfter(n, node);
  10487. var last = n;
  10488. while (next) {
  10489. var tmp = next.nextSibling();
  10490. node.parentNode.insertAfter(next, last);
  10491. last = next;
  10492. next = tmp;
  10493. }
  10494. return false;
  10495. }
  10496. });
  10497. if (!node.firstChild()) {
  10498. node.innerHTML(browser.ie ? "&nbsp;" : "<br/>");
  10499. }
  10500. break;
  10501. case "div":
  10502. if (node.getAttr("cdata_tag")) {
  10503. break;
  10504. }
  10505. //针对代码这里不处理插入代码的div
  10506. val = node.getAttr("class");
  10507. if (val && /^line number\d+/.test(val)) {
  10508. break;
  10509. }
  10510. if (!allowDivTransToP) {
  10511. break;
  10512. }
  10513. var tmpNode,
  10514. p = UE.uNode.createElement("p");
  10515. while ((tmpNode = node.firstChild())) {
  10516. if (
  10517. tmpNode.type == "text" ||
  10518. !UE.dom.dtd.$block[tmpNode.tagName]
  10519. ) {
  10520. p.appendChild(tmpNode);
  10521. } else {
  10522. if (p.firstChild()) {
  10523. node.parentNode.insertBefore(p, node);
  10524. p = UE.uNode.createElement("p");
  10525. } else {
  10526. node.parentNode.insertBefore(tmpNode, node);
  10527. }
  10528. }
  10529. }
  10530. if (p.firstChild()) {
  10531. node.parentNode.insertBefore(p, node);
  10532. }
  10533. node.parentNode.removeChild(node);
  10534. break;
  10535. case "dl":
  10536. node.tagName = "ul";
  10537. break;
  10538. case "dt":
  10539. case "dd":
  10540. node.tagName = "li";
  10541. break;
  10542. case "li":
  10543. var className = node.getAttr("class");
  10544. if (!className || !/list\-/.test(className)) {
  10545. node.setAttr();
  10546. }
  10547. var tmpNodes = node.getNodesByTagName("ol ul");
  10548. UE.utils.each(tmpNodes, function(n) {
  10549. node.parentNode.insertAfter(n, node);
  10550. });
  10551. break;
  10552. case "td":
  10553. case "th":
  10554. case "caption":
  10555. if (!node.children || !node.children.length) {
  10556. node.appendChild(
  10557. browser.ie11below
  10558. ? UE.uNode.createText(" ")
  10559. : UE.uNode.createElement("br")
  10560. );
  10561. }
  10562. break;
  10563. case "table":
  10564. if (me.options.disabledTableInTable && tdParent(node)) {
  10565. node.parentNode.insertBefore(
  10566. UE.uNode.createText(node.innerText()),
  10567. node
  10568. );
  10569. node.parentNode.removeChild(node);
  10570. }
  10571. }
  10572. }
  10573. // if(node.type == 'comment'){
  10574. // node.parentNode.removeChild(node);
  10575. // }
  10576. });
  10577. });
  10578. //从编辑器出去的内容处理
  10579. me.addOutputRule(function(root) {
  10580. var val;
  10581. root.traversal(function(node) {
  10582. if (node.type == "element") {
  10583. if (
  10584. me.options.autoClearEmptyNode &&
  10585. dtd.$inline[node.tagName] &&
  10586. !dtd.$empty[node.tagName] &&
  10587. (!node.attrs || utils.isEmptyObject(node.attrs))
  10588. ) {
  10589. if (!node.firstChild()) node.parentNode.removeChild(node);
  10590. else if (
  10591. node.tagName == "span" &&
  10592. (!node.attrs || utils.isEmptyObject(node.attrs))
  10593. ) {
  10594. node.parentNode.removeChild(node, true);
  10595. }
  10596. return;
  10597. }
  10598. switch (node.tagName) {
  10599. case "div":
  10600. if ((val = node.getAttr("cdata_tag"))) {
  10601. node.tagName = val;
  10602. node.appendChild(UE.uNode.createText(node.getAttr("cdata_data")));
  10603. node.setAttr({
  10604. cdata_tag: "",
  10605. cdata_data: "",
  10606. _ue_custom_node_: ""
  10607. });
  10608. }
  10609. break;
  10610. case "a":
  10611. if ((val = node.getAttr("_href"))) {
  10612. node.setAttr({
  10613. href: utils.html(val),
  10614. _href: ""
  10615. });
  10616. }
  10617. break;
  10618. break;
  10619. case "span":
  10620. val = node.getAttr("id");
  10621. if (val && /^_baidu_bookmark_/i.test(val)) {
  10622. node.parentNode.removeChild(node);
  10623. }
  10624. //将color的rgb格式转换为#16进制格式
  10625. if (me.getOpt("rgb2Hex")) {
  10626. var cssStyle = node.getAttr("style");
  10627. if (cssStyle) {
  10628. node.setAttr(
  10629. "style",
  10630. cssStyle.replace(/rgba?\(([\d,\s]+)\)/g, function(a, value) {
  10631. var array = value.split(",");
  10632. if (array.length > 3) return "";
  10633. value = "#";
  10634. for (var i = 0, color; (color = array[i++]); ) {
  10635. color = parseInt(
  10636. color.replace(/[^\d]/gi, ""),
  10637. 10
  10638. ).toString(16);
  10639. value += color.length == 1 ? "0" + color : color;
  10640. }
  10641. return value.toUpperCase();
  10642. })
  10643. );
  10644. }
  10645. }
  10646. break;
  10647. case "img":
  10648. if ((val = node.getAttr("_src"))) {
  10649. node.setAttr({
  10650. src: node.getAttr("_src"),
  10651. _src: ""
  10652. });
  10653. }
  10654. }
  10655. }
  10656. });
  10657. });
  10658. };
  10659. // plugins/inserthtml.js
  10660. /**
  10661. * 插入html字符串插件
  10662. * @file
  10663. * @since 1.2.6.1
  10664. */
  10665. /**
  10666. * 插入html代码
  10667. * @command inserthtml
  10668. * @method execCommand
  10669. * @param { String } cmd 命令字符串
  10670. * @param { String } html 插入的html字符串
  10671. * @remaind 插入的标签内容是在当前的选区位置上插入,如果当前是闭合状态,那直接插入内容, 如果当前是选中状态,将先清除当前选中内容后,再做插入
  10672. * @warning 注意:该命令会对当前选区的位置,对插入的内容进行过滤转换处理。 过滤的规则遵循html语意化的原则。
  10673. * @example
  10674. * ```javascript
  10675. * //xxx[BB]xxx 当前选区为非闭合选区,选中BB这两个文本
  10676. * //执行命令,插入<b>CC</b>
  10677. * //插入后的效果 xxx<b>CC</b>xxx
  10678. * //<p>xx|xxx</p> 当前选区为闭合状态
  10679. * //插入<p>CC</p>
  10680. * //结果 <p>xx</p><p>CC</p><p>xxx</p>
  10681. * //<p>xxxx</p>|</p>xxx</p> 当前选区在两个p标签之间
  10682. * //插入 xxxx
  10683. * //结果 <p>xxxx</p><p>xxxx</p></p>xxx</p>
  10684. * ```
  10685. */
  10686. UE.commands["inserthtml"] = {
  10687. execCommand: function(command, html, notNeedFilter) {
  10688. var me = this,
  10689. range,
  10690. div;
  10691. if (!html) {
  10692. return;
  10693. }
  10694. if (me.fireEvent("beforeinserthtml", html) === true) {
  10695. return;
  10696. }
  10697. range = me.selection.getRange();
  10698. div = range.document.createElement("div");
  10699. div.style.display = "inline";
  10700. if (!notNeedFilter) {
  10701. var root = UE.htmlparser(html);
  10702. //如果给了过滤规则就先进行过滤
  10703. if (me.options.filterRules) {
  10704. UE.filterNode(root, me.options.filterRules);
  10705. }
  10706. //执行默认的处理
  10707. me.filterInputRule(root);
  10708. html = root.toHtml();
  10709. }
  10710. div.innerHTML = utils.trim(html);
  10711. if (!range.collapsed) {
  10712. var tmpNode = range.startContainer;
  10713. if (domUtils.isFillChar(tmpNode)) {
  10714. range.setStartBefore(tmpNode);
  10715. }
  10716. tmpNode = range.endContainer;
  10717. if (domUtils.isFillChar(tmpNode)) {
  10718. range.setEndAfter(tmpNode);
  10719. }
  10720. range.txtToElmBoundary();
  10721. //结束边界可能放到了br的前边,要把br包含进来
  10722. // x[xxx]<br/>
  10723. if (range.endContainer && range.endContainer.nodeType == 1) {
  10724. tmpNode = range.endContainer.childNodes[range.endOffset];
  10725. if (tmpNode && domUtils.isBr(tmpNode)) {
  10726. range.setEndAfter(tmpNode);
  10727. }
  10728. }
  10729. if (range.startOffset == 0) {
  10730. tmpNode = range.startContainer;
  10731. if (domUtils.isBoundaryNode(tmpNode, "firstChild")) {
  10732. tmpNode = range.endContainer;
  10733. if (
  10734. range.endOffset ==
  10735. (tmpNode.nodeType == 3
  10736. ? tmpNode.nodeValue.length
  10737. : tmpNode.childNodes.length) &&
  10738. domUtils.isBoundaryNode(tmpNode, "lastChild")
  10739. ) {
  10740. me.body.innerHTML = "<p>" + (browser.ie ? "" : "<br/>") + "</p>";
  10741. range.setStart(me.body.firstChild, 0).collapse(true);
  10742. }
  10743. }
  10744. }
  10745. !range.collapsed && range.deleteContents();
  10746. if (range.startContainer.nodeType == 1) {
  10747. var child = range.startContainer.childNodes[range.startOffset],
  10748. pre;
  10749. if (
  10750. child &&
  10751. domUtils.isBlockElm(child) &&
  10752. (pre = child.previousSibling) &&
  10753. domUtils.isBlockElm(pre)
  10754. ) {
  10755. range.setEnd(pre, pre.childNodes.length).collapse();
  10756. while (child.firstChild) {
  10757. pre.appendChild(child.firstChild);
  10758. }
  10759. domUtils.remove(child);
  10760. }
  10761. }
  10762. }
  10763. var child,
  10764. parent,
  10765. pre,
  10766. tmp,
  10767. hadBreak = 0,
  10768. nextNode;
  10769. //如果当前位置选中了fillchar要干掉,要不会产生空行
  10770. if (range.inFillChar()) {
  10771. child = range.startContainer;
  10772. if (domUtils.isFillChar(child)) {
  10773. range.setStartBefore(child).collapse(true);
  10774. domUtils.remove(child);
  10775. } else if (domUtils.isFillChar(child, true)) {
  10776. child.nodeValue = child.nodeValue.replace(fillCharReg, "");
  10777. range.startOffset--;
  10778. range.collapsed && range.collapse(true);
  10779. }
  10780. }
  10781. //列表单独处理
  10782. var li = domUtils.findParentByTagName(range.startContainer, "li", true);
  10783. if (li) {
  10784. var next, last;
  10785. while ((child = div.firstChild)) {
  10786. //针对hr单独处理一下先
  10787. while (
  10788. child &&
  10789. (child.nodeType == 3 ||
  10790. !domUtils.isBlockElm(child) ||
  10791. child.tagName == "HR")
  10792. ) {
  10793. next = child.nextSibling;
  10794. range.insertNode(child).collapse();
  10795. last = child;
  10796. child = next;
  10797. }
  10798. if (child) {
  10799. if (/^(ol|ul)$/i.test(child.tagName)) {
  10800. while (child.firstChild) {
  10801. last = child.firstChild;
  10802. domUtils.insertAfter(li, child.firstChild);
  10803. li = li.nextSibling;
  10804. }
  10805. domUtils.remove(child);
  10806. } else {
  10807. var tmpLi;
  10808. next = child.nextSibling;
  10809. tmpLi = me.document.createElement("li");
  10810. domUtils.insertAfter(li, tmpLi);
  10811. tmpLi.appendChild(child);
  10812. last = child;
  10813. child = next;
  10814. li = tmpLi;
  10815. }
  10816. }
  10817. }
  10818. li = domUtils.findParentByTagName(range.startContainer, "li", true);
  10819. if (domUtils.isEmptyBlock(li)) {
  10820. domUtils.remove(li);
  10821. }
  10822. if (last) {
  10823. range.setStartAfter(last).collapse(true).select(true);
  10824. }
  10825. } else {
  10826. while ((child = div.firstChild)) {
  10827. if (hadBreak) {
  10828. var p = me.document.createElement("p");
  10829. while (child && (child.nodeType == 3 || !dtd.$block[child.tagName])) {
  10830. nextNode = child.nextSibling;
  10831. p.appendChild(child);
  10832. child = nextNode;
  10833. }
  10834. if (p.firstChild) {
  10835. child = p;
  10836. }
  10837. }
  10838. range.insertNode(child);
  10839. nextNode = child.nextSibling;
  10840. if (
  10841. !hadBreak &&
  10842. child.nodeType == domUtils.NODE_ELEMENT &&
  10843. domUtils.isBlockElm(child)
  10844. ) {
  10845. parent = domUtils.findParent(child, function(node) {
  10846. return domUtils.isBlockElm(node);
  10847. });
  10848. if (
  10849. parent &&
  10850. parent.tagName.toLowerCase() != "body" &&
  10851. !(
  10852. dtd[parent.tagName][child.nodeName] && child.parentNode === parent
  10853. )
  10854. ) {
  10855. if (!dtd[parent.tagName][child.nodeName]) {
  10856. pre = parent;
  10857. } else {
  10858. tmp = child.parentNode;
  10859. while (tmp !== parent) {
  10860. pre = tmp;
  10861. tmp = tmp.parentNode;
  10862. }
  10863. }
  10864. domUtils.breakParent(child, pre || tmp);
  10865. //去掉break后前一个多余的节点 <p>|<[p> ==> <p></p><div></div><p>|</p>
  10866. var pre = child.previousSibling;
  10867. domUtils.trimWhiteTextNode(pre);
  10868. if (!pre.childNodes.length) {
  10869. domUtils.remove(pre);
  10870. }
  10871. //trace:2012,在非ie的情况,切开后剩下的节点有可能不能点入光标添加br占位
  10872. if (
  10873. !browser.ie &&
  10874. (next = child.nextSibling) &&
  10875. domUtils.isBlockElm(next) &&
  10876. next.lastChild &&
  10877. !domUtils.isBr(next.lastChild)
  10878. ) {
  10879. next.appendChild(me.document.createElement("br"));
  10880. }
  10881. hadBreak = 1;
  10882. }
  10883. }
  10884. var next = child.nextSibling;
  10885. if (!div.firstChild && next && domUtils.isBlockElm(next)) {
  10886. range.setStart(next, 0).collapse(true);
  10887. break;
  10888. }
  10889. range.setEndAfter(child).collapse();
  10890. }
  10891. child = range.startContainer;
  10892. if (nextNode && domUtils.isBr(nextNode)) {
  10893. domUtils.remove(nextNode);
  10894. }
  10895. //用chrome可能有空白展位符
  10896. if (domUtils.isBlockElm(child) && domUtils.isEmptyNode(child)) {
  10897. if ((nextNode = child.nextSibling)) {
  10898. domUtils.remove(child);
  10899. if (nextNode.nodeType == 1 && dtd.$block[nextNode.tagName]) {
  10900. range.setStart(nextNode, 0).collapse(true).shrinkBoundary();
  10901. }
  10902. } else {
  10903. try {
  10904. child.innerHTML = browser.ie ? domUtils.fillChar : "<br/>";
  10905. } catch (e) {
  10906. range.setStartBefore(child);
  10907. domUtils.remove(child);
  10908. }
  10909. }
  10910. }
  10911. //加上true因为在删除表情等时会删两次,第一次是删的fillData
  10912. try {
  10913. range.select(true);
  10914. } catch (e) {}
  10915. }
  10916. setTimeout(function() {
  10917. range = me.selection.getRange();
  10918. range.scrollToView(
  10919. me.autoHeightEnabled,
  10920. me.autoHeightEnabled ? domUtils.getXY(me.iframe).y : 0
  10921. );
  10922. me.fireEvent("afterinserthtml", html);
  10923. }, 200);
  10924. }
  10925. };
  10926. // plugins/autotypeset.js
  10927. /**
  10928. * 自动排版
  10929. * @file
  10930. * @since 1.2.6.1
  10931. */
  10932. /**
  10933. * 对当前编辑器的内容执行自动排版, 排版的行为根据config配置文件里的“autotypeset”选项进行控制。
  10934. * @command autotypeset
  10935. * @method execCommand
  10936. * @param { String } cmd 命令字符串
  10937. * @example
  10938. * ```javascript
  10939. * editor.execCommand( 'autotypeset' );
  10940. * ```
  10941. */
  10942. UE.plugins["autotypeset"] = function() {
  10943. this.setOpt({
  10944. autotypeset: {
  10945. mergeEmptyline: true, //合并空行
  10946. removeClass: true, //去掉冗余的class
  10947. removeEmptyline: false, //去掉空行
  10948. textAlign: "left", //段落的排版方式,可以是 left,right,center,justify 去掉这个属性表示不执行排版
  10949. imageBlockLine: "center", //图片的浮动方式,独占一行剧中,左右浮动,默认: center,left,right,none 去掉这个属性表示不执行排版
  10950. pasteFilter: false, //根据规则过滤没事粘贴进来的内容
  10951. clearFontSize: false, //去掉所有的内嵌字号,使用编辑器默认的字号
  10952. clearFontFamily: false, //去掉所有的内嵌字体,使用编辑器默认的字体
  10953. removeEmptyNode: false, // 去掉空节点
  10954. //可以去掉的标签
  10955. removeTagNames: utils.extend({ div: 1 }, dtd.$removeEmpty),
  10956. indent: false, // 行首缩进
  10957. indentValue: "2em", //行首缩进的大小
  10958. bdc2sb: false,
  10959. tobdc: false
  10960. }
  10961. });
  10962. var me = this,
  10963. opt = me.options.autotypeset,
  10964. remainClass = {
  10965. selectTdClass: 1,
  10966. pagebreak: 1,
  10967. anchorclass: 1
  10968. },
  10969. remainTag = {
  10970. li: 1
  10971. },
  10972. tags = {
  10973. div: 1,
  10974. p: 1,
  10975. //trace:2183 这些也认为是行
  10976. blockquote: 1,
  10977. center: 1,
  10978. h1: 1,
  10979. h2: 1,
  10980. h3: 1,
  10981. h4: 1,
  10982. h5: 1,
  10983. h6: 1,
  10984. span: 1
  10985. },
  10986. highlightCont;
  10987. //升级了版本,但配置项目里没有autotypeset
  10988. if (!opt) {
  10989. return;
  10990. }
  10991. readLocalOpts();
  10992. function isLine(node, notEmpty) {
  10993. if (!node || node.nodeType == 3) return 0;
  10994. if (domUtils.isBr(node)) return 1;
  10995. if (node && node.parentNode && tags[node.tagName.toLowerCase()]) {
  10996. if (
  10997. (highlightCont && highlightCont.contains(node)) ||
  10998. node.getAttribute("pagebreak")
  10999. ) {
  11000. return 0;
  11001. }
  11002. return notEmpty
  11003. ? !domUtils.isEmptyBlock(node)
  11004. : domUtils.isEmptyBlock(
  11005. node,
  11006. new RegExp("[\\s" + domUtils.fillChar + "]", "g")
  11007. );
  11008. }
  11009. }
  11010. function removeNotAttributeSpan(node) {
  11011. if (!node.style.cssText) {
  11012. domUtils.removeAttributes(node, ["style"]);
  11013. if (
  11014. node.tagName.toLowerCase() == "span" &&
  11015. domUtils.hasNoAttributes(node)
  11016. ) {
  11017. domUtils.remove(node, true);
  11018. }
  11019. }
  11020. }
  11021. function autotype(type, html) {
  11022. var me = this,
  11023. cont;
  11024. if (html) {
  11025. if (!opt.pasteFilter) {
  11026. return;
  11027. }
  11028. cont = me.document.createElement("div");
  11029. cont.innerHTML = html.html;
  11030. } else {
  11031. cont = me.document.body;
  11032. }
  11033. var nodes = domUtils.getElementsByTagName(cont, "*");
  11034. // 行首缩进,段落方向,段间距,段内间距
  11035. for (var i = 0, ci; (ci = nodes[i++]); ) {
  11036. if (me.fireEvent("excludeNodeinautotype", ci) === true) {
  11037. continue;
  11038. }
  11039. //font-size
  11040. if (opt.clearFontSize && ci.style.fontSize) {
  11041. domUtils.removeStyle(ci, "font-size");
  11042. removeNotAttributeSpan(ci);
  11043. }
  11044. //font-family
  11045. if (opt.clearFontFamily && ci.style.fontFamily) {
  11046. domUtils.removeStyle(ci, "font-family");
  11047. removeNotAttributeSpan(ci);
  11048. }
  11049. if (isLine(ci)) {
  11050. //合并空行
  11051. if (opt.mergeEmptyline) {
  11052. var next = ci.nextSibling,
  11053. tmpNode,
  11054. isBr = domUtils.isBr(ci);
  11055. while (isLine(next)) {
  11056. tmpNode = next;
  11057. next = tmpNode.nextSibling;
  11058. if (isBr && (!next || (next && !domUtils.isBr(next)))) {
  11059. break;
  11060. }
  11061. domUtils.remove(tmpNode);
  11062. }
  11063. }
  11064. //去掉空行,保留占位的空行
  11065. if (
  11066. opt.removeEmptyline &&
  11067. domUtils.inDoc(ci, cont) &&
  11068. !remainTag[ci.parentNode.tagName.toLowerCase()]
  11069. ) {
  11070. if (domUtils.isBr(ci)) {
  11071. next = ci.nextSibling;
  11072. if (next && !domUtils.isBr(next)) {
  11073. continue;
  11074. }
  11075. }
  11076. domUtils.remove(ci);
  11077. continue;
  11078. }
  11079. }
  11080. if (isLine(ci, true) && ci.tagName != "SPAN") {
  11081. if (opt.indent) {
  11082. ci.style.textIndent = opt.indentValue;
  11083. }
  11084. if (opt.textAlign) {
  11085. ci.style.textAlign = opt.textAlign;
  11086. }
  11087. // if(opt.lineHeight)
  11088. // ci.style.lineHeight = opt.lineHeight + 'cm';
  11089. }
  11090. //去掉class,保留的class不去掉
  11091. if (
  11092. opt.removeClass &&
  11093. ci.className &&
  11094. !remainClass[ci.className.toLowerCase()]
  11095. ) {
  11096. if (highlightCont && highlightCont.contains(ci)) {
  11097. continue;
  11098. }
  11099. domUtils.removeAttributes(ci, ["class"]);
  11100. }
  11101. //表情不处理
  11102. if (
  11103. opt.imageBlockLine &&
  11104. ci.tagName.toLowerCase() == "img" &&
  11105. !ci.getAttribute("emotion")
  11106. ) {
  11107. if (html) {
  11108. var img = ci;
  11109. switch (opt.imageBlockLine) {
  11110. case "left":
  11111. case "right":
  11112. case "none":
  11113. var pN = img.parentNode,
  11114. tmpNode,
  11115. pre,
  11116. next;
  11117. while (dtd.$inline[pN.tagName] || pN.tagName == "A") {
  11118. pN = pN.parentNode;
  11119. }
  11120. tmpNode = pN;
  11121. if (
  11122. tmpNode.tagName == "P" &&
  11123. domUtils.getStyle(tmpNode, "text-align") == "center"
  11124. ) {
  11125. if (
  11126. !domUtils.isBody(tmpNode) &&
  11127. domUtils.getChildCount(tmpNode, function(node) {
  11128. return !domUtils.isBr(node) && !domUtils.isWhitespace(node);
  11129. }) == 1
  11130. ) {
  11131. pre = tmpNode.previousSibling;
  11132. next = tmpNode.nextSibling;
  11133. if (
  11134. pre &&
  11135. next &&
  11136. pre.nodeType == 1 &&
  11137. next.nodeType == 1 &&
  11138. pre.tagName == next.tagName &&
  11139. domUtils.isBlockElm(pre)
  11140. ) {
  11141. pre.appendChild(tmpNode.firstChild);
  11142. while (next.firstChild) {
  11143. pre.appendChild(next.firstChild);
  11144. }
  11145. domUtils.remove(tmpNode);
  11146. domUtils.remove(next);
  11147. } else {
  11148. domUtils.setStyle(tmpNode, "text-align", "");
  11149. }
  11150. }
  11151. }
  11152. domUtils.setStyle(img, "float", opt.imageBlockLine);
  11153. break;
  11154. case "center":
  11155. if (me.queryCommandValue("imagefloat") != "center") {
  11156. pN = img.parentNode;
  11157. domUtils.setStyle(img, "float", "none");
  11158. tmpNode = img;
  11159. while (
  11160. pN &&
  11161. domUtils.getChildCount(pN, function(node) {
  11162. return !domUtils.isBr(node) && !domUtils.isWhitespace(node);
  11163. }) == 1 &&
  11164. (dtd.$inline[pN.tagName] || pN.tagName == "A")
  11165. ) {
  11166. tmpNode = pN;
  11167. pN = pN.parentNode;
  11168. }
  11169. var pNode = me.document.createElement("p");
  11170. domUtils.setAttributes(pNode, {
  11171. style: "text-align:center"
  11172. });
  11173. tmpNode.parentNode.insertBefore(pNode, tmpNode);
  11174. pNode.appendChild(tmpNode);
  11175. domUtils.setStyle(tmpNode, "float", "");
  11176. }
  11177. }
  11178. } else {
  11179. var range = me.selection.getRange();
  11180. range.selectNode(ci).select();
  11181. me.execCommand("imagefloat", opt.imageBlockLine);
  11182. }
  11183. }
  11184. //去掉冗余的标签
  11185. if (opt.removeEmptyNode) {
  11186. if (
  11187. opt.removeTagNames[ci.tagName.toLowerCase()] &&
  11188. domUtils.hasNoAttributes(ci) &&
  11189. domUtils.isEmptyBlock(ci)
  11190. ) {
  11191. domUtils.remove(ci);
  11192. }
  11193. }
  11194. }
  11195. if (opt.tobdc) {
  11196. var root = UE.htmlparser(cont.innerHTML);
  11197. root.traversal(function(node) {
  11198. if (node.type == "text") {
  11199. node.data = ToDBC(node.data);
  11200. }
  11201. });
  11202. cont.innerHTML = root.toHtml();
  11203. }
  11204. if (opt.bdc2sb) {
  11205. var root = UE.htmlparser(cont.innerHTML);
  11206. root.traversal(function(node) {
  11207. if (node.type == "text") {
  11208. node.data = DBC2SB(node.data);
  11209. }
  11210. });
  11211. cont.innerHTML = root.toHtml();
  11212. }
  11213. if (html) {
  11214. html.html = cont.innerHTML;
  11215. }
  11216. }
  11217. if (opt.pasteFilter) {
  11218. me.addListener("beforepaste", autotype);
  11219. }
  11220. function DBC2SB(str) {
  11221. var result = "";
  11222. for (var i = 0; i < str.length; i++) {
  11223. var code = str.charCodeAt(i); //获取当前字符的unicode编码
  11224. if (code >= 65281 && code <= 65373) {
  11225. //在这个unicode编码范围中的是所有的英文字母已经各种字符
  11226. result += String.fromCharCode(str.charCodeAt(i) - 65248); //把全角字符的unicode编码转换为对应半角字符的unicode码
  11227. } else if (code == 12288) {
  11228. //空格
  11229. result += String.fromCharCode(str.charCodeAt(i) - 12288 + 32);
  11230. } else {
  11231. result += str.charAt(i);
  11232. }
  11233. }
  11234. return result;
  11235. }
  11236. function ToDBC(txtstring) {
  11237. txtstring = utils.html(txtstring);
  11238. var tmp = "";
  11239. var mark = ""; /*用于判断,如果是html尖括里的标记,则不进行全角的转换*/
  11240. for (var i = 0; i < txtstring.length; i++) {
  11241. if (txtstring.charCodeAt(i) == 32) {
  11242. tmp = tmp + String.fromCharCode(12288);
  11243. } else if (txtstring.charCodeAt(i) < 127) {
  11244. tmp = tmp + String.fromCharCode(txtstring.charCodeAt(i) + 65248);
  11245. } else {
  11246. tmp += txtstring.charAt(i);
  11247. }
  11248. }
  11249. return tmp;
  11250. }
  11251. function readLocalOpts() {
  11252. var cookieOpt = me.getPreferences("autotypeset");
  11253. utils.extend(me.options.autotypeset, cookieOpt);
  11254. }
  11255. me.commands["autotypeset"] = {
  11256. execCommand: function() {
  11257. me.removeListener("beforepaste", autotype);
  11258. if (opt.pasteFilter) {
  11259. me.addListener("beforepaste", autotype);
  11260. }
  11261. autotype.call(me);
  11262. }
  11263. };
  11264. };
  11265. // plugins/autosubmit.js
  11266. /**
  11267. * 快捷键提交
  11268. * @file
  11269. * @since 1.2.6.1
  11270. */
  11271. /**
  11272. * 提交表单
  11273. * @command autosubmit
  11274. * @method execCommand
  11275. * @param { String } cmd 命令字符串
  11276. * @example
  11277. * ```javascript
  11278. * editor.execCommand( 'autosubmit' );
  11279. * ```
  11280. */
  11281. UE.plugin.register("autosubmit", function() {
  11282. return {
  11283. shortcutkey: {
  11284. autosubmit: "ctrl+13" //手动提交
  11285. },
  11286. commands: {
  11287. autosubmit: {
  11288. execCommand: function() {
  11289. var me = this,
  11290. form = domUtils.findParentByTagName(me.iframe, "form", false);
  11291. if (form) {
  11292. if (me.fireEvent("beforesubmit") === false) {
  11293. return;
  11294. }
  11295. me.sync();
  11296. form.submit();
  11297. }
  11298. }
  11299. }
  11300. }
  11301. };
  11302. });
  11303. // plugins/background.js
  11304. /**
  11305. * 背景插件,为UEditor提供设置背景功能
  11306. * @file
  11307. * @since 1.2.6.1
  11308. */
  11309. UE.plugin.register("background", function() {
  11310. var me = this,
  11311. cssRuleId = "editor_background",
  11312. isSetColored,
  11313. reg = new RegExp("body[\\s]*\\{(.+)\\}", "i");
  11314. function stringToObj(str) {
  11315. var obj = {},
  11316. styles = str.split(";");
  11317. utils.each(styles, function(v) {
  11318. var index = v.indexOf(":"),
  11319. key = utils.trim(v.substr(0, index)).toLowerCase();
  11320. key && (obj[key] = utils.trim(v.substr(index + 1) || ""));
  11321. });
  11322. return obj;
  11323. }
  11324. function setBackground(obj) {
  11325. if (obj) {
  11326. var styles = [];
  11327. for (var name in obj) {
  11328. if (obj.hasOwnProperty(name)) {
  11329. styles.push(name + ":" + obj[name] + "; ");
  11330. }
  11331. }
  11332. utils.cssRule(
  11333. cssRuleId,
  11334. styles.length ? "body{" + styles.join("") + "}" : "",
  11335. me.document
  11336. );
  11337. } else {
  11338. utils.cssRule(cssRuleId, "", me.document);
  11339. }
  11340. }
  11341. //重写editor.hasContent方法
  11342. var orgFn = me.hasContents;
  11343. me.hasContents = function() {
  11344. if (me.queryCommandValue("background")) {
  11345. return true;
  11346. }
  11347. return orgFn.apply(me, arguments);
  11348. };
  11349. return {
  11350. bindEvents: {
  11351. getAllHtml: function(type, headHtml) {
  11352. var body = this.body,
  11353. su = domUtils.getComputedStyle(body, "background-image"),
  11354. url = "";
  11355. if (su.indexOf(me.options.imagePath) > 0) {
  11356. url = su
  11357. .substring(su.indexOf(me.options.imagePath), su.length - 1)
  11358. .replace(/"|\(|\)/gi, "");
  11359. } else {
  11360. url = su != "none" ? su.replace(/url\("?|"?\)/gi, "") : "";
  11361. }
  11362. var html = '<style type="text/css">body{';
  11363. var bgObj = {
  11364. "background-color":
  11365. domUtils.getComputedStyle(body, "background-color") || "#ffffff",
  11366. "background-image": url ? "url(" + url + ")" : "",
  11367. "background-repeat":
  11368. domUtils.getComputedStyle(body, "background-repeat") || "",
  11369. "background-position": browser.ie
  11370. ? domUtils.getComputedStyle(body, "background-position-x") +
  11371. " " +
  11372. domUtils.getComputedStyle(body, "background-position-y")
  11373. : domUtils.getComputedStyle(body, "background-position"),
  11374. height: domUtils.getComputedStyle(body, "height")
  11375. };
  11376. for (var name in bgObj) {
  11377. if (bgObj.hasOwnProperty(name)) {
  11378. html += name + ":" + bgObj[name] + "; ";
  11379. }
  11380. }
  11381. html += "}</style> ";
  11382. headHtml.push(html);
  11383. },
  11384. aftersetcontent: function() {
  11385. if (isSetColored == false) setBackground();
  11386. }
  11387. },
  11388. inputRule: function(root) {
  11389. isSetColored = false;
  11390. utils.each(root.getNodesByTagName("p"), function(p) {
  11391. var styles = p.getAttr("data-background");
  11392. if (styles) {
  11393. isSetColored = true;
  11394. setBackground(stringToObj(styles));
  11395. p.parentNode.removeChild(p);
  11396. }
  11397. });
  11398. },
  11399. outputRule: function(root) {
  11400. var me = this,
  11401. styles = (utils.cssRule(cssRuleId, me.document) || "")
  11402. .replace(/[\n\r]+/g, "")
  11403. .match(reg);
  11404. if (styles) {
  11405. root.appendChild(
  11406. UE.uNode.createElement(
  11407. '<p style="display:none;" data-background="' +
  11408. utils.trim(styles[1].replace(/"/g, "").replace(/[\s]+/g, " ")) +
  11409. '"><br/></p>'
  11410. )
  11411. );
  11412. }
  11413. },
  11414. commands: {
  11415. background: {
  11416. execCommand: function(cmd, obj) {
  11417. setBackground(obj);
  11418. },
  11419. queryCommandValue: function() {
  11420. var me = this,
  11421. styles = (utils.cssRule(cssRuleId, me.document) || "")
  11422. .replace(/[\n\r]+/g, "")
  11423. .match(reg);
  11424. return styles ? stringToObj(styles[1]) : null;
  11425. },
  11426. notNeedUndo: true
  11427. }
  11428. }
  11429. };
  11430. });
  11431. // plugins/image.js
  11432. /**
  11433. * 图片插入、排版插件
  11434. * @file
  11435. * @since 1.2.6.1
  11436. */
  11437. /**
  11438. * 图片对齐方式
  11439. * @command imagefloat
  11440. * @method execCommand
  11441. * @remind 值center为独占一行居中
  11442. * @param { String } cmd 命令字符串
  11443. * @param { String } align 对齐方式,可传left、right、none、center
  11444. * @remaind center表示图片独占一行
  11445. * @example
  11446. * ```javascript
  11447. * editor.execCommand( 'imagefloat', 'center' );
  11448. * ```
  11449. */
  11450. /**
  11451. * 如果选区所在位置是图片区域
  11452. * @command imagefloat
  11453. * @method queryCommandValue
  11454. * @param { String } cmd 命令字符串
  11455. * @return { String } 返回图片对齐方式
  11456. * @example
  11457. * ```javascript
  11458. * editor.queryCommandValue( 'imagefloat' );
  11459. * ```
  11460. */
  11461. UE.commands["imagefloat"] = {
  11462. execCommand: function(cmd, align) {
  11463. var me = this,
  11464. range = me.selection.getRange();
  11465. if (!range.collapsed) {
  11466. var img = range.getClosedNode();
  11467. if (img && img.tagName == "IMG") {
  11468. switch (align) {
  11469. case "left":
  11470. case "right":
  11471. case "none":
  11472. var pN = img.parentNode,
  11473. tmpNode,
  11474. pre,
  11475. next;
  11476. while (dtd.$inline[pN.tagName] || pN.tagName == "A") {
  11477. pN = pN.parentNode;
  11478. }
  11479. tmpNode = pN;
  11480. if (
  11481. tmpNode.tagName == "P" &&
  11482. domUtils.getStyle(tmpNode, "text-align") == "center"
  11483. ) {
  11484. if (
  11485. !domUtils.isBody(tmpNode) &&
  11486. domUtils.getChildCount(tmpNode, function(node) {
  11487. return !domUtils.isBr(node) && !domUtils.isWhitespace(node);
  11488. }) == 1
  11489. ) {
  11490. pre = tmpNode.previousSibling;
  11491. next = tmpNode.nextSibling;
  11492. if (
  11493. pre &&
  11494. next &&
  11495. pre.nodeType == 1 &&
  11496. next.nodeType == 1 &&
  11497. pre.tagName == next.tagName &&
  11498. domUtils.isBlockElm(pre)
  11499. ) {
  11500. pre.appendChild(tmpNode.firstChild);
  11501. while (next.firstChild) {
  11502. pre.appendChild(next.firstChild);
  11503. }
  11504. domUtils.remove(tmpNode);
  11505. domUtils.remove(next);
  11506. } else {
  11507. domUtils.setStyle(tmpNode, "text-align", "");
  11508. }
  11509. }
  11510. range.selectNode(img).select();
  11511. }
  11512. domUtils.setStyle(img, "float", align == "none" ? "" : align);
  11513. if (align == "none") {
  11514. domUtils.removeAttributes(img, "align");
  11515. }
  11516. break;
  11517. case "center":
  11518. if (me.queryCommandValue("imagefloat") != "center") {
  11519. var pN = img.parentNode;
  11520. domUtils.setStyle(img, "float", "");
  11521. domUtils.removeAttributes(img, "align");
  11522. tmpNode = img;
  11523. while (
  11524. pN &&
  11525. domUtils.getChildCount(pN, function(node) {
  11526. return !domUtils.isBr(node) && !domUtils.isWhitespace(node);
  11527. }) == 1 &&
  11528. (dtd.$inline[pN.tagName] || pN.tagName == "A")
  11529. ) {
  11530. tmpNode = pN;
  11531. pN = pN.parentNode;
  11532. }
  11533. range.setStartBefore(tmpNode).setCursor(false);
  11534. pN = me.document.createElement("div");
  11535. pN.appendChild(tmpNode);
  11536. domUtils.setStyle(tmpNode, "float", "");
  11537. me.execCommand(
  11538. "insertHtml",
  11539. '<p class="_img_parent_tmp" style="text-align:center">' +
  11540. pN.innerHTML +
  11541. "</p>"
  11542. );
  11543. tmpNode = me.document.getElementsByClassName("_img_parent_tmp")[0];
  11544. tmpNode.removeAttribute("class");
  11545. tmpNode = tmpNode.firstChild;
  11546. range.selectNode(tmpNode).select();
  11547. //去掉后边多余的元素
  11548. next = tmpNode.parentNode.nextSibling;
  11549. if (next && domUtils.isEmptyNode(next)) {
  11550. domUtils.remove(next);
  11551. }
  11552. }
  11553. break;
  11554. }
  11555. }
  11556. }
  11557. },
  11558. queryCommandValue: function() {
  11559. var range = this.selection.getRange(),
  11560. startNode,
  11561. floatStyle;
  11562. if (range.collapsed) {
  11563. return "none";
  11564. }
  11565. startNode = range.getClosedNode();
  11566. if (startNode && startNode.nodeType == 1 && startNode.tagName == "IMG") {
  11567. floatStyle =
  11568. domUtils.getComputedStyle(startNode, "float") ||
  11569. startNode.getAttribute("align");
  11570. if (floatStyle == "none") {
  11571. floatStyle = domUtils.getComputedStyle(
  11572. startNode.parentNode,
  11573. "text-align"
  11574. ) == "center"
  11575. ? "center"
  11576. : floatStyle;
  11577. }
  11578. return {
  11579. left: 1,
  11580. right: 1,
  11581. center: 1
  11582. }[floatStyle]
  11583. ? floatStyle
  11584. : "none";
  11585. }
  11586. return "none";
  11587. },
  11588. queryCommandState: function() {
  11589. var range = this.selection.getRange(),
  11590. startNode;
  11591. if (range.collapsed) return -1;
  11592. startNode = range.getClosedNode();
  11593. if (startNode && startNode.nodeType == 1 && startNode.tagName == "IMG") {
  11594. return 0;
  11595. }
  11596. return -1;
  11597. }
  11598. };
  11599. /**
  11600. * 插入图片
  11601. * @command insertimage
  11602. * @method execCommand
  11603. * @param { String } cmd 命令字符串
  11604. * @param { Object } opt 属性键值对,这些属性都将被复制到当前插入图片
  11605. * @remind 该命令第二个参数可接受一个图片配置项对象的数组,可以插入多张图片,
  11606. * 此时数组的每一个元素都是一个Object类型的图片属性集合。
  11607. * @example
  11608. * ```javascript
  11609. * editor.execCommand( 'insertimage', {
  11610. * src:'a/b/c.jpg',
  11611. * width:'100',
  11612. * height:'100'
  11613. * } );
  11614. * ```
  11615. * @example
  11616. * ```javascript
  11617. * editor.execCommand( 'insertimage', [{
  11618. * src:'a/b/c.jpg',
  11619. * width:'100',
  11620. * height:'100'
  11621. * },{
  11622. * src:'a/b/d.jpg',
  11623. * width:'100',
  11624. * height:'100'
  11625. * }] );
  11626. * ```
  11627. */
  11628. UE.commands["insertimage"] = {
  11629. execCommand: function(cmd, opt) {
  11630. opt = utils.isArray(opt) ? opt : [opt];
  11631. if (!opt.length) {
  11632. return;
  11633. }
  11634. var me = this,
  11635. range = me.selection.getRange(),
  11636. img = range.getClosedNode();
  11637. if (me.fireEvent("beforeinsertimage", opt) === true) {
  11638. return;
  11639. }
  11640. if (
  11641. img &&
  11642. /img/i.test(img.tagName) &&
  11643. (img.className != "edui-faked-video" ||
  11644. img.className.indexOf("edui-upload-video") != -1) &&
  11645. !img.getAttribute("word_img")
  11646. ) {
  11647. var first = opt.shift();
  11648. var floatStyle = first["floatStyle"];
  11649. delete first["floatStyle"];
  11650. //// img.style.border = (first.border||0) +"px solid #000";
  11651. //// img.style.margin = (first.margin||0) +"px";
  11652. // img.style.cssText += ';margin:' + (first.margin||0) +"px;" + 'border:' + (first.border||0) +"px solid #000";
  11653. domUtils.setAttributes(img, first);
  11654. me.execCommand("imagefloat", floatStyle);
  11655. if (opt.length > 0) {
  11656. range.setStartAfter(img).setCursor(false, true);
  11657. me.execCommand("insertimage", opt);
  11658. }
  11659. } else {
  11660. var html = [],
  11661. str = "",
  11662. ci;
  11663. ci = opt[0];
  11664. if (opt.length == 1) {
  11665. str =
  11666. '<img src="' +
  11667. ci.src +
  11668. '" ' +
  11669. (ci._src ? ' _src="' + ci._src + '" ' : "") +
  11670. (ci.width ? 'width="' + ci.width + '" ' : "") +
  11671. (ci.height ? ' height="' + ci.height + '" ' : "") +
  11672. (ci["floatStyle"] == "left" || ci["floatStyle"] == "right"
  11673. ? ' style="float:' + ci["floatStyle"] + ';"'
  11674. : "") +
  11675. (ci.title && ci.title != "" ? ' title="' + ci.title + '"' : "") +
  11676. (ci.border && ci.border != "0" ? ' border="' + ci.border + '"' : "") +
  11677. (ci.alt && ci.alt != "" ? ' alt="' + ci.alt + '"' : "") +
  11678. (ci.hspace && ci.hspace != "0"
  11679. ? ' hspace = "' + ci.hspace + '"'
  11680. : "") +
  11681. (ci.vspace && ci.vspace != "0"
  11682. ? ' vspace = "' + ci.vspace + '"'
  11683. : "") +
  11684. "/>";
  11685. if (ci["floatStyle"] == "center") {
  11686. str = '<p style="text-align: center">' + str + "</p>";
  11687. }
  11688. html.push(str);
  11689. } else {
  11690. for (var i = 0; (ci = opt[i++]); ) {
  11691. str =
  11692. "<p " +
  11693. (ci["floatStyle"] == "center"
  11694. ? 'style="text-align: center" '
  11695. : "") +
  11696. '><img src="' +
  11697. ci.src +
  11698. '" ' +
  11699. (ci.width ? 'width="' + ci.width + '" ' : "") +
  11700. (ci._src ? ' _src="' + ci._src + '" ' : "") +
  11701. (ci.height ? ' height="' + ci.height + '" ' : "") +
  11702. ' style="' +
  11703. (ci["floatStyle"] && ci["floatStyle"] != "center"
  11704. ? "float:" + ci["floatStyle"] + ";"
  11705. : "") +
  11706. (ci.border || "") +
  11707. '" ' +
  11708. (ci.title ? ' title="' + ci.title + '"' : "") +
  11709. " /></p>";
  11710. html.push(str);
  11711. }
  11712. }
  11713. me.execCommand("insertHtml", html.join(""));
  11714. }
  11715. me.fireEvent("afterinsertimage", opt);
  11716. }
  11717. };
  11718. // plugins/justify.js
  11719. /**
  11720. * 段落格式
  11721. * @file
  11722. * @since 1.2.6.1
  11723. */
  11724. /**
  11725. * 段落对齐方式
  11726. * @command justify
  11727. * @method execCommand
  11728. * @param { String } cmd 命令字符串
  11729. * @param { String } align 对齐方式:left => 居左,right => 居右,center => 居中,justify => 两端对齐
  11730. * @example
  11731. * ```javascript
  11732. * editor.execCommand( 'justify', 'center' );
  11733. * ```
  11734. */
  11735. /**
  11736. * 如果选区所在位置是段落区域,返回当前段落对齐方式
  11737. * @command justify
  11738. * @method queryCommandValue
  11739. * @param { String } cmd 命令字符串
  11740. * @return { String } 返回段落对齐方式
  11741. * @example
  11742. * ```javascript
  11743. * editor.queryCommandValue( 'justify' );
  11744. * ```
  11745. */
  11746. UE.plugins["justify"] = function() {
  11747. var me = this,
  11748. block = domUtils.isBlockElm,
  11749. defaultValue = {
  11750. left: 1,
  11751. right: 1,
  11752. center: 1,
  11753. justify: 1
  11754. },
  11755. doJustify = function(range, style) {
  11756. var bookmark = range.createBookmark(),
  11757. filterFn = function(node) {
  11758. return node.nodeType == 1
  11759. ? node.tagName.toLowerCase() != "br" &&
  11760. !domUtils.isBookmarkNode(node)
  11761. : !domUtils.isWhitespace(node);
  11762. };
  11763. range.enlarge(true);
  11764. var bookmark2 = range.createBookmark(),
  11765. current = domUtils.getNextDomNode(bookmark2.start, false, filterFn),
  11766. tmpRange = range.cloneRange(),
  11767. tmpNode;
  11768. while (
  11769. current &&
  11770. !(
  11771. domUtils.getPosition(current, bookmark2.end) &
  11772. domUtils.POSITION_FOLLOWING
  11773. )
  11774. ) {
  11775. if (current.nodeType == 3 || !block(current)) {
  11776. tmpRange.setStartBefore(current);
  11777. while (current && current !== bookmark2.end && !block(current)) {
  11778. tmpNode = current;
  11779. current = domUtils.getNextDomNode(current, false, null, function(
  11780. node
  11781. ) {
  11782. return !block(node);
  11783. });
  11784. }
  11785. tmpRange.setEndAfter(tmpNode);
  11786. var common = tmpRange.getCommonAncestor();
  11787. if (!domUtils.isBody(common) && block(common)) {
  11788. domUtils.setStyles(
  11789. common,
  11790. utils.isString(style) ? { "text-align": style } : style
  11791. );
  11792. current = common;
  11793. } else {
  11794. var p = range.document.createElement("p");
  11795. domUtils.setStyles(
  11796. p,
  11797. utils.isString(style) ? { "text-align": style } : style
  11798. );
  11799. var frag = tmpRange.extractContents();
  11800. p.appendChild(frag);
  11801. tmpRange.insertNode(p);
  11802. current = p;
  11803. }
  11804. current = domUtils.getNextDomNode(current, false, filterFn);
  11805. } else {
  11806. current = domUtils.getNextDomNode(current, true, filterFn);
  11807. }
  11808. }
  11809. return range.moveToBookmark(bookmark2).moveToBookmark(bookmark);
  11810. };
  11811. UE.commands["justify"] = {
  11812. execCommand: function(cmdName, align) {
  11813. var range = this.selection.getRange(),
  11814. txt;
  11815. //闭合时单独处理
  11816. if (range.collapsed) {
  11817. txt = this.document.createTextNode("p");
  11818. range.insertNode(txt);
  11819. }
  11820. doJustify(range, align);
  11821. if (txt) {
  11822. range.setStartBefore(txt).collapse(true);
  11823. domUtils.remove(txt);
  11824. }
  11825. range.select();
  11826. return true;
  11827. },
  11828. queryCommandValue: function() {
  11829. var startNode = this.selection.getStart(),
  11830. value = domUtils.getComputedStyle(startNode, "text-align");
  11831. return defaultValue[value] ? value : "left";
  11832. },
  11833. queryCommandState: function() {
  11834. var start = this.selection.getStart(),
  11835. cell =
  11836. start &&
  11837. domUtils.findParentByTagName(start, ["td", "th", "caption"], true);
  11838. return cell ? -1 : 0;
  11839. }
  11840. };
  11841. };
  11842. // plugins/font.js
  11843. /**
  11844. * 字体颜色,背景色,字号,字体,下划线,删除线
  11845. * @file
  11846. * @since 1.2.6.1
  11847. */
  11848. /**
  11849. * 字体颜色
  11850. * @command forecolor
  11851. * @method execCommand
  11852. * @param { String } cmd 命令字符串
  11853. * @param { String } value 色值(必须十六进制)
  11854. * @example
  11855. * ```javascript
  11856. * editor.execCommand( 'forecolor', '#000' );
  11857. * ```
  11858. */
  11859. /**
  11860. * 返回选区字体颜色
  11861. * @command forecolor
  11862. * @method queryCommandValue
  11863. * @param { String } cmd 命令字符串
  11864. * @return { String } 返回字体颜色
  11865. * @example
  11866. * ```javascript
  11867. * editor.queryCommandValue( 'forecolor' );
  11868. * ```
  11869. */
  11870. /**
  11871. * 字体背景颜色
  11872. * @command backcolor
  11873. * @method execCommand
  11874. * @param { String } cmd 命令字符串
  11875. * @param { String } value 色值(必须十六进制)
  11876. * @example
  11877. * ```javascript
  11878. * editor.execCommand( 'backcolor', '#000' );
  11879. * ```
  11880. */
  11881. /**
  11882. * 返回选区字体颜色
  11883. * @command backcolor
  11884. * @method queryCommandValue
  11885. * @param { String } cmd 命令字符串
  11886. * @return { String } 返回字体背景颜色
  11887. * @example
  11888. * ```javascript
  11889. * editor.queryCommandValue( 'backcolor' );
  11890. * ```
  11891. */
  11892. /**
  11893. * 字体大小
  11894. * @command fontsize
  11895. * @method execCommand
  11896. * @param { String } cmd 命令字符串
  11897. * @param { String } value 字体大小
  11898. * @example
  11899. * ```javascript
  11900. * editor.execCommand( 'fontsize', '14px' );
  11901. * ```
  11902. */
  11903. /**
  11904. * 返回选区字体大小
  11905. * @command fontsize
  11906. * @method queryCommandValue
  11907. * @param { String } cmd 命令字符串
  11908. * @return { String } 返回字体大小
  11909. * @example
  11910. * ```javascript
  11911. * editor.queryCommandValue( 'fontsize' );
  11912. * ```
  11913. */
  11914. /**
  11915. * 字体样式
  11916. * @command fontfamily
  11917. * @method execCommand
  11918. * @param { String } cmd 命令字符串
  11919. * @param { String } value 字体样式
  11920. * @example
  11921. * ```javascript
  11922. * editor.execCommand( 'fontfamily', '微软雅黑' );
  11923. * ```
  11924. */
  11925. /**
  11926. * 返回选区字体样式
  11927. * @command fontfamily
  11928. * @method queryCommandValue
  11929. * @param { String } cmd 命令字符串
  11930. * @return { String } 返回字体样式
  11931. * @example
  11932. * ```javascript
  11933. * editor.queryCommandValue( 'fontfamily' );
  11934. * ```
  11935. */
  11936. /**
  11937. * 字体下划线,与删除线互斥
  11938. * @command underline
  11939. * @method execCommand
  11940. * @param { String } cmd 命令字符串
  11941. * @example
  11942. * ```javascript
  11943. * editor.execCommand( 'underline' );
  11944. * ```
  11945. */
  11946. /**
  11947. * 字体删除线,与下划线互斥
  11948. * @command strikethrough
  11949. * @method execCommand
  11950. * @param { String } cmd 命令字符串
  11951. * @example
  11952. * ```javascript
  11953. * editor.execCommand( 'strikethrough' );
  11954. * ```
  11955. */
  11956. /**
  11957. * 字体边框
  11958. * @command fontborder
  11959. * @method execCommand
  11960. * @param { String } cmd 命令字符串
  11961. * @example
  11962. * ```javascript
  11963. * editor.execCommand( 'fontborder' );
  11964. * ```
  11965. */
  11966. UE.plugins["font"] = function() {
  11967. var me = this,
  11968. fonts = {
  11969. forecolor: "color",
  11970. backcolor: "background-color",
  11971. fontsize: "font-size",
  11972. fontfamily: "font-family",
  11973. underline: "text-decoration",
  11974. strikethrough: "text-decoration",
  11975. fontborder: "border"
  11976. },
  11977. needCmd = { underline: 1, strikethrough: 1, fontborder: 1 },
  11978. needSetChild = {
  11979. forecolor: "color",
  11980. backcolor: "background-color",
  11981. fontsize: "font-size",
  11982. fontfamily: "font-family"
  11983. };
  11984. me.setOpt({
  11985. fontfamily: [
  11986. { name: "songti", val: "宋体,SimSun" },
  11987. { name: "yahei", val: "微软雅黑,Microsoft YaHei" },
  11988. { name: "kaiti", val: "楷体,楷体_GB2312, SimKai" },
  11989. { name: "heiti", val: "黑体, SimHei" },
  11990. { name: "lishu", val: "隶书, SimLi" },
  11991. { name: "andaleMono", val: "andale mono" },
  11992. { name: "arial", val: "arial, helvetica,sans-serif" },
  11993. { name: "arialBlack", val: "arial black,avant garde" },
  11994. { name: "comicSansMs", val: "comic sans ms" },
  11995. { name: "impact", val: "impact,chicago" },
  11996. { name: "timesNewRoman", val: "times new roman" }
  11997. ],
  11998. fontsize: [10, 11, 12, 14, 16, 18, 20, 24, 36]
  11999. });
  12000. function mergeWithParent(node) {
  12001. var parent;
  12002. while ((parent = node.parentNode)) {
  12003. if (
  12004. parent.tagName == "SPAN" &&
  12005. domUtils.getChildCount(parent, function(child) {
  12006. return !domUtils.isBookmarkNode(child) && !domUtils.isBr(child);
  12007. }) == 1
  12008. ) {
  12009. parent.style.cssText += node.style.cssText;
  12010. domUtils.remove(node, true);
  12011. node = parent;
  12012. } else {
  12013. break;
  12014. }
  12015. }
  12016. }
  12017. function mergeChild(rng, cmdName, value) {
  12018. if (needSetChild[cmdName]) {
  12019. rng.adjustmentBoundary();
  12020. if (!rng.collapsed && rng.startContainer.nodeType == 1) {
  12021. rng.traversal(function(node){
  12022. var start;
  12023. if(domUtils.isTagNode(node,'span')){
  12024. start = node;
  12025. }else{
  12026. start = domUtils.getElementsByTagName(node,'span')[0];
  12027. }
  12028. if (start && domUtils.isTagNode(start, "span")) {
  12029. var bk = rng.createBookmark();
  12030. utils.each(domUtils.getElementsByTagName(start, "span"), function(
  12031. span
  12032. ) {
  12033. if (!span.parentNode || domUtils.isBookmarkNode(span)) return;
  12034. if (
  12035. cmdName == "backcolor" &&
  12036. domUtils
  12037. .getComputedStyle(span, "background-color")
  12038. .toLowerCase() === value
  12039. ) {
  12040. return;
  12041. }
  12042. domUtils.removeStyle(span, needSetChild[cmdName]);
  12043. if (span.style.cssText.replace(/^\s+$/, "").length == 0) {
  12044. domUtils.remove(span, true);
  12045. }
  12046. });
  12047. rng.moveToBookmark(bk);
  12048. }
  12049. });
  12050. }
  12051. }
  12052. }
  12053. function mergesibling(rng, cmdName, value) {
  12054. var collapsed = rng.collapsed,
  12055. bk = rng.createBookmark(),
  12056. common;
  12057. if (collapsed) {
  12058. common = bk.start.parentNode;
  12059. while (dtd.$inline[common.tagName]) {
  12060. common = common.parentNode;
  12061. }
  12062. } else {
  12063. common = domUtils.getCommonAncestor(bk.start, bk.end);
  12064. }
  12065. utils.each(domUtils.getElementsByTagName(common, "span"), function(span) {
  12066. if (!span.parentNode || domUtils.isBookmarkNode(span)) return;
  12067. if (/\s*border\s*:\s*none;?\s*/i.test(span.style.cssText)) {
  12068. if (/^\s*border\s*:\s*none;?\s*$/.test(span.style.cssText)) {
  12069. domUtils.remove(span, true);
  12070. } else {
  12071. domUtils.removeStyle(span, "border");
  12072. }
  12073. return;
  12074. }
  12075. if (
  12076. /border/i.test(span.style.cssText) &&
  12077. span.parentNode.tagName == "SPAN" &&
  12078. /border/i.test(span.parentNode.style.cssText)
  12079. ) {
  12080. span.style.cssText = span.style.cssText.replace(
  12081. /border[^:]*:[^;]+;?/gi,
  12082. ""
  12083. );
  12084. }
  12085. if (!(cmdName == "fontborder" && value == "none")) {
  12086. var next = span.nextSibling;
  12087. while (next && next.nodeType == 1 && next.tagName == "SPAN") {
  12088. if (domUtils.isBookmarkNode(next) && cmdName == "fontborder") {
  12089. span.appendChild(next);
  12090. next = span.nextSibling;
  12091. continue;
  12092. }
  12093. if (next.style.cssText == span.style.cssText) {
  12094. domUtils.moveChild(next, span);
  12095. domUtils.remove(next);
  12096. }
  12097. if (span.nextSibling === next) break;
  12098. next = span.nextSibling;
  12099. }
  12100. }
  12101. mergeWithParent(span);
  12102. if (browser.ie && browser.version > 8) {
  12103. //拷贝父亲们的特别的属性,这里只做背景颜色的处理
  12104. var parent = domUtils.findParent(span, function(n) {
  12105. return (
  12106. n.tagName == "SPAN" && /background-color/.test(n.style.cssText)
  12107. );
  12108. });
  12109. if (parent && !/background-color/.test(span.style.cssText)) {
  12110. span.style.backgroundColor = parent.style.backgroundColor;
  12111. }
  12112. }
  12113. });
  12114. rng.moveToBookmark(bk);
  12115. mergeChild(rng, cmdName, value);
  12116. }
  12117. me.addInputRule(function(root) {
  12118. utils.each(root.getNodesByTagName("u s del font strike"), function(node) {
  12119. if (node.tagName == "font") {
  12120. var cssStyle = [];
  12121. for (var p in node.attrs) {
  12122. switch (p) {
  12123. case "size":
  12124. cssStyle.push(
  12125. "font-size:" +
  12126. ({
  12127. "1": "10",
  12128. "2": "12",
  12129. "3": "16",
  12130. "4": "18",
  12131. "5": "24",
  12132. "6": "32",
  12133. "7": "48"
  12134. }[node.attrs[p]] || node.attrs[p]) +
  12135. "px"
  12136. );
  12137. break;
  12138. case "color":
  12139. cssStyle.push("color:" + node.attrs[p]);
  12140. break;
  12141. case "face":
  12142. cssStyle.push("font-family:" + node.attrs[p]);
  12143. break;
  12144. case "style":
  12145. cssStyle.push(node.attrs[p]);
  12146. }
  12147. }
  12148. node.attrs = {
  12149. style: cssStyle.join(";")
  12150. };
  12151. } else {
  12152. var val = node.tagName == "u" ? "underline" : "line-through";
  12153. node.attrs = {
  12154. style: (node.getAttr("style") || "") + "text-decoration:" + val + ";"
  12155. };
  12156. }
  12157. node.tagName = "span";
  12158. });
  12159. // utils.each(root.getNodesByTagName('span'), function (node) {
  12160. // var val;
  12161. // if(val = node.getAttr('class')){
  12162. // if(/fontstrikethrough/.test(val)){
  12163. // node.setStyle('text-decoration','line-through');
  12164. // if(node.attrs['class']){
  12165. // node.attrs['class'] = node.attrs['class'].replace(/fontstrikethrough/,'');
  12166. // }else{
  12167. // node.setAttr('class')
  12168. // }
  12169. // }
  12170. // if(/fontborder/.test(val)){
  12171. // node.setStyle('border','1px solid #000');
  12172. // if(node.attrs['class']){
  12173. // node.attrs['class'] = node.attrs['class'].replace(/fontborder/,'');
  12174. // }else{
  12175. // node.setAttr('class')
  12176. // }
  12177. // }
  12178. // }
  12179. // });
  12180. });
  12181. // me.addOutputRule(function(root){
  12182. // utils.each(root.getNodesByTagName('span'), function (node) {
  12183. // var val;
  12184. // if(val = node.getStyle('text-decoration')){
  12185. // if(/line-through/.test(val)){
  12186. // if(node.attrs['class']){
  12187. // node.attrs['class'] += ' fontstrikethrough';
  12188. // }else{
  12189. // node.setAttr('class','fontstrikethrough')
  12190. // }
  12191. // }
  12192. //
  12193. // node.setStyle('text-decoration')
  12194. // }
  12195. // if(val = node.getStyle('border')){
  12196. // if(/1px/.test(val) && /solid/.test(val)){
  12197. // if(node.attrs['class']){
  12198. // node.attrs['class'] += ' fontborder';
  12199. //
  12200. // }else{
  12201. // node.setAttr('class','fontborder')
  12202. // }
  12203. // }
  12204. // node.setStyle('border')
  12205. //
  12206. // }
  12207. // });
  12208. // });
  12209. for (var p in fonts) {
  12210. (function(cmd, style) {
  12211. UE.commands[cmd] = {
  12212. execCommand: function(cmdName, value) {
  12213. value =
  12214. value ||
  12215. (this.queryCommandState(cmdName)
  12216. ? "none"
  12217. : cmdName == "underline"
  12218. ? "underline"
  12219. : cmdName == "fontborder" ? "1px solid #000" : "line-through");
  12220. var me = this,
  12221. range = this.selection.getRange(),
  12222. text;
  12223. if (value == "default") {
  12224. if (range.collapsed) {
  12225. text = me.document.createTextNode("font");
  12226. range.insertNode(text).select();
  12227. }
  12228. me.execCommand("removeFormat", "span,a", style);
  12229. if (text) {
  12230. range.setStartBefore(text).collapse(true);
  12231. domUtils.remove(text);
  12232. }
  12233. mergesibling(range, cmdName, value);
  12234. range.select();
  12235. } else {
  12236. if (!range.collapsed) {
  12237. if (needCmd[cmd] && me.queryCommandValue(cmd)) {
  12238. me.execCommand("removeFormat", "span,a", style);
  12239. }
  12240. range = me.selection.getRange();
  12241. range.applyInlineStyle("span", { style: style + ":" + value });
  12242. mergesibling(range, cmdName, value);
  12243. range.select();
  12244. } else {
  12245. var span = domUtils.findParentByTagName(
  12246. range.startContainer,
  12247. "span",
  12248. true
  12249. );
  12250. text = me.document.createTextNode("font");
  12251. if (
  12252. span &&
  12253. !span.children.length &&
  12254. !span[browser.ie ? "innerText" : "textContent"].replace(
  12255. fillCharReg,
  12256. ""
  12257. ).length
  12258. ) {
  12259. //for ie hack when enter
  12260. range.insertNode(text);
  12261. if (needCmd[cmd]) {
  12262. range.selectNode(text).select();
  12263. me.execCommand("removeFormat", "span,a", style, null);
  12264. span = domUtils.findParentByTagName(text, "span", true);
  12265. range.setStartBefore(text);
  12266. }
  12267. span && (span.style.cssText += ";" + style + ":" + value);
  12268. range.collapse(true).select();
  12269. } else {
  12270. range.insertNode(text);
  12271. range.selectNode(text).select();
  12272. span = range.document.createElement("span");
  12273. if (needCmd[cmd]) {
  12274. //a标签内的不处理跳过
  12275. if (domUtils.findParentByTagName(text, "a", true)) {
  12276. range.setStartBefore(text).setCursor();
  12277. domUtils.remove(text);
  12278. return;
  12279. }
  12280. me.execCommand("removeFormat", "span,a", style);
  12281. }
  12282. span.style.cssText = style + ":" + value;
  12283. text.parentNode.insertBefore(span, text);
  12284. //修复,span套span 但样式不继承的问题
  12285. if (!browser.ie || (browser.ie && browser.version == 9)) {
  12286. var spanParent = span.parentNode;
  12287. while (!domUtils.isBlockElm(spanParent)) {
  12288. if (spanParent.tagName == "SPAN") {
  12289. //opera合并style不会加入";"
  12290. span.style.cssText =
  12291. spanParent.style.cssText + ";" + span.style.cssText;
  12292. }
  12293. spanParent = spanParent.parentNode;
  12294. }
  12295. }
  12296. if (opera) {
  12297. setTimeout(function() {
  12298. range.setStart(span, 0).collapse(true);
  12299. mergesibling(range, cmdName, value);
  12300. range.select();
  12301. });
  12302. } else {
  12303. range.setStart(span, 0).collapse(true);
  12304. mergesibling(range, cmdName, value);
  12305. range.select();
  12306. }
  12307. //trace:981
  12308. //domUtils.mergeToParent(span)
  12309. }
  12310. domUtils.remove(text);
  12311. }
  12312. }
  12313. return true;
  12314. },
  12315. queryCommandValue: function(cmdName) {
  12316. var startNode = this.selection.getStart();
  12317. //trace:946
  12318. if (cmdName == "underline" || cmdName == "strikethrough") {
  12319. var tmpNode = startNode,
  12320. value;
  12321. while (
  12322. tmpNode &&
  12323. !domUtils.isBlockElm(tmpNode) &&
  12324. !domUtils.isBody(tmpNode)
  12325. ) {
  12326. if (tmpNode.nodeType == 1) {
  12327. value = domUtils.getComputedStyle(tmpNode, style);
  12328. if (value != "none") {
  12329. return value;
  12330. }
  12331. }
  12332. tmpNode = tmpNode.parentNode;
  12333. }
  12334. return "none";
  12335. }
  12336. if (cmdName == "fontborder") {
  12337. var tmp = startNode,
  12338. val;
  12339. while (tmp && dtd.$inline[tmp.tagName]) {
  12340. if ((val = domUtils.getComputedStyle(tmp, "border"))) {
  12341. if (/1px/.test(val) && /solid/.test(val)) {
  12342. return val;
  12343. }
  12344. }
  12345. tmp = tmp.parentNode;
  12346. }
  12347. return "";
  12348. }
  12349. if (cmdName == "FontSize") {
  12350. var styleVal = domUtils.getComputedStyle(startNode, style),
  12351. tmp = /^([\d\.]+)(\w+)$/.exec(styleVal);
  12352. if (tmp) {
  12353. return Math.floor(tmp[1]) + tmp[2];
  12354. }
  12355. return styleVal;
  12356. }
  12357. return domUtils.getComputedStyle(startNode, style);
  12358. },
  12359. queryCommandState: function(cmdName) {
  12360. if (!needCmd[cmdName]) return 0;
  12361. var val = this.queryCommandValue(cmdName);
  12362. if (cmdName == "fontborder") {
  12363. return /1px/.test(val) && /solid/.test(val);
  12364. } else {
  12365. return cmdName == "underline"
  12366. ? /underline/.test(val)
  12367. : /line\-through/.test(val);
  12368. }
  12369. }
  12370. };
  12371. })(p, fonts[p]);
  12372. }
  12373. };
  12374. // plugins/link.js
  12375. /**
  12376. * 超链接
  12377. * @file
  12378. * @since 1.2.6.1
  12379. */
  12380. /**
  12381. * 插入超链接
  12382. * @command link
  12383. * @method execCommand
  12384. * @param { String } cmd 命令字符串
  12385. * @param { Object } options 设置自定义属性,例如:url、title、target
  12386. * @example
  12387. * ```javascript
  12388. * editor.execCommand( 'link', '{
  12389. * url:'neditor.baidu.com',
  12390. * title:'neditor',
  12391. * target:'_blank'
  12392. * }' );
  12393. * ```
  12394. */
  12395. /**
  12396. * 返回当前选中的第一个超链接节点
  12397. * @command link
  12398. * @method queryCommandValue
  12399. * @param { String } cmd 命令字符串
  12400. * @return { Element } 超链接节点
  12401. * @example
  12402. * ```javascript
  12403. * editor.queryCommandValue( 'link' );
  12404. * ```
  12405. */
  12406. /**
  12407. * 取消超链接
  12408. * @command unlink
  12409. * @method execCommand
  12410. * @param { String } cmd 命令字符串
  12411. * @example
  12412. * ```javascript
  12413. * editor.execCommand( 'unlink');
  12414. * ```
  12415. */
  12416. UE.plugins["link"] = function() {
  12417. function optimize(range) {
  12418. var start = range.startContainer,
  12419. end = range.endContainer;
  12420. if ((start = domUtils.findParentByTagName(start, "a", true))) {
  12421. range.setStartBefore(start);
  12422. }
  12423. if ((end = domUtils.findParentByTagName(end, "a", true))) {
  12424. range.setEndAfter(end);
  12425. }
  12426. }
  12427. UE.commands["unlink"] = {
  12428. execCommand: function() {
  12429. var range = this.selection.getRange(),
  12430. bookmark;
  12431. if (
  12432. range.collapsed &&
  12433. !domUtils.findParentByTagName(range.startContainer, "a", true)
  12434. ) {
  12435. return;
  12436. }
  12437. bookmark = range.createBookmark();
  12438. optimize(range);
  12439. range.removeInlineStyle("a").moveToBookmark(bookmark).select();
  12440. },
  12441. queryCommandState: function() {
  12442. return !this.highlight && this.queryCommandValue("link") ? 0 : -1;
  12443. }
  12444. };
  12445. function doLink(range, opt, me) {
  12446. var rngClone = range.cloneRange(),
  12447. link = me.queryCommandValue("link");
  12448. optimize((range = range.adjustmentBoundary()));
  12449. var start = range.startContainer;
  12450. if (start.nodeType == 1 && link) {
  12451. start = start.childNodes[range.startOffset];
  12452. if (
  12453. start &&
  12454. start.nodeType == 1 &&
  12455. start.tagName == "A" &&
  12456. /^(?:https?|ftp|file)\s*:\s*\/\//.test(
  12457. start[browser.ie ? "innerText" : "textContent"]
  12458. )
  12459. ) {
  12460. start[browser.ie ? "innerText" : "textContent"] = utils.html(
  12461. opt.textValue || opt.href
  12462. );
  12463. }
  12464. }
  12465. if (!rngClone.collapsed || link) {
  12466. range.removeInlineStyle("a");
  12467. rngClone = range.cloneRange();
  12468. }
  12469. if (rngClone.collapsed) {
  12470. var a = range.document.createElement("a"),
  12471. text = "";
  12472. if (opt.textValue) {
  12473. text = utils.html(opt.textValue);
  12474. delete opt.textValue;
  12475. } else {
  12476. text = utils.html(opt.href);
  12477. }
  12478. domUtils.setAttributes(a, opt);
  12479. start = domUtils.findParentByTagName(rngClone.startContainer, "a", true);
  12480. if (start && domUtils.isInNodeEndBoundary(rngClone, start)) {
  12481. range.setStartAfter(start).collapse(true);
  12482. }
  12483. a[browser.ie ? "innerText" : "textContent"] = text;
  12484. range.insertNode(a).selectNode(a);
  12485. } else {
  12486. range.applyInlineStyle("a", opt);
  12487. }
  12488. }
  12489. UE.commands["link"] = {
  12490. execCommand: function(cmdName, opt) {
  12491. var range;
  12492. opt._href && (opt._href = utils.unhtml(opt._href, /[<">]/g));
  12493. opt.href && (opt.href = utils.unhtml(opt.href, /[<">]/g));
  12494. opt.textValue && (opt.textValue = utils.unhtml(opt.textValue, /[<">]/g));
  12495. doLink((range = this.selection.getRange()), opt, this);
  12496. //闭合都不加占位符,如果加了会在a后边多个占位符节点,导致a是图片背景组成的列表,出现空白问题
  12497. range.collapse().select(true);
  12498. },
  12499. queryCommandValue: function() {
  12500. var range = this.selection.getRange(),
  12501. node;
  12502. if (range.collapsed) {
  12503. // node = this.selection.getStart();
  12504. //在ie下getstart()取值偏上了
  12505. node = range.startContainer;
  12506. node = node.nodeType == 1 ? node : node.parentNode;
  12507. if (
  12508. node &&
  12509. (node = domUtils.findParentByTagName(node, "a", true)) &&
  12510. !domUtils.isInNodeEndBoundary(range, node)
  12511. ) {
  12512. return node;
  12513. }
  12514. } else {
  12515. //trace:1111 如果是<p><a>xx</a></p> startContainer是p就会找不到a
  12516. range.shrinkBoundary();
  12517. var start = range.startContainer.nodeType == 3 ||
  12518. !range.startContainer.childNodes[range.startOffset]
  12519. ? range.startContainer
  12520. : range.startContainer.childNodes[range.startOffset],
  12521. end = range.endContainer.nodeType == 3 || range.endOffset == 0
  12522. ? range.endContainer
  12523. : range.endContainer.childNodes[range.endOffset - 1],
  12524. common = range.getCommonAncestor();
  12525. node = domUtils.findParentByTagName(common, "a", true);
  12526. if (!node && common.nodeType == 1) {
  12527. var as = common.getElementsByTagName("a"),
  12528. ps,
  12529. pe;
  12530. for (var i = 0, ci; (ci = as[i++]); ) {
  12531. (ps = domUtils.getPosition(ci, start)), (pe = domUtils.getPosition(
  12532. ci,
  12533. end
  12534. ));
  12535. if (
  12536. (ps & domUtils.POSITION_FOLLOWING ||
  12537. ps & domUtils.POSITION_CONTAINS) &&
  12538. (pe & domUtils.POSITION_PRECEDING ||
  12539. pe & domUtils.POSITION_CONTAINS)
  12540. ) {
  12541. node = ci;
  12542. break;
  12543. }
  12544. }
  12545. }
  12546. return node;
  12547. }
  12548. },
  12549. queryCommandState: function() {
  12550. //判断如果是视频的话连接不可用
  12551. //fix 853
  12552. var img = this.selection.getRange().getClosedNode(),
  12553. flag =
  12554. img &&
  12555. (img.className == "edui-faked-video" ||
  12556. img.className.indexOf("edui-upload-video") != -1);
  12557. return flag ? -1 : 0;
  12558. }
  12559. };
  12560. };
  12561. // plugins/iframe.js
  12562. ///import core
  12563. ///import plugins\inserthtml.js
  12564. ///commands 插入框架
  12565. ///commandsName InsertFrame
  12566. ///commandsTitle 插入Iframe
  12567. ///commandsDialog dialogs\insertframe
  12568. UE.plugins["insertframe"] = function() {
  12569. var me = this;
  12570. function deleteIframe() {
  12571. me._iframe && delete me._iframe;
  12572. }
  12573. me.addListener("selectionchange", function() {
  12574. deleteIframe();
  12575. });
  12576. };
  12577. // plugins/scrawl.js
  12578. ///import core
  12579. ///commands 涂鸦
  12580. ///commandsName Scrawl
  12581. ///commandsTitle 涂鸦
  12582. ///commandsDialog dialogs\scrawl
  12583. UE.commands["scrawl"] = {
  12584. queryCommandState: function() {
  12585. return browser.ie && browser.version <= 8 ? -1 : 0;
  12586. }
  12587. };
  12588. // plugins/removeformat.js
  12589. /**
  12590. * 清除格式
  12591. * @file
  12592. * @since 1.2.6.1
  12593. */
  12594. /**
  12595. * 清除文字样式
  12596. * @command removeformat
  12597. * @method execCommand
  12598. * @param { String } cmd 命令字符串
  12599. * @param {String} tags 以逗号隔开的标签。如:strong
  12600. * @param {String} style 样式如:color
  12601. * @param {String} attrs 属性如:width
  12602. * @example
  12603. * ```javascript
  12604. * editor.execCommand( 'removeformat', 'strong','color','width' );
  12605. * ```
  12606. */
  12607. UE.plugins["removeformat"] = function() {
  12608. var me = this;
  12609. me.setOpt({
  12610. removeFormatTags:
  12611. "b,big,code,del,dfn,em,font,i,ins,kbd,q,samp,small,span,strike,strong,sub,sup,tt,u,var",
  12612. removeFormatAttributes: "class,style,lang,width,height,align,hspace,valign"
  12613. });
  12614. me.commands["removeformat"] = {
  12615. execCommand: function(cmdName, tags, style, attrs, notIncludeA) {
  12616. var tagReg = new RegExp(
  12617. "^(?:" +
  12618. (tags || this.options.removeFormatTags).replace(/,/g, "|") +
  12619. ")$",
  12620. "i"
  12621. ),
  12622. removeFormatAttributes = style
  12623. ? []
  12624. : (attrs || this.options.removeFormatAttributes).split(","),
  12625. range = new dom.Range(this.document),
  12626. bookmark,
  12627. node,
  12628. parent,
  12629. filter = function(node) {
  12630. return node.nodeType == 1;
  12631. };
  12632. function isRedundantSpan(node) {
  12633. if (node.nodeType == 3 || node.tagName.toLowerCase() != "span") {
  12634. return 0;
  12635. }
  12636. if (browser.ie) {
  12637. //ie 下判断实效,所以只能简单用style来判断
  12638. //return node.style.cssText == '' ? 1 : 0;
  12639. var attrs = node.attributes;
  12640. if (attrs.length) {
  12641. for (var i = 0, l = attrs.length; i < l; i++) {
  12642. if (attrs[i].specified) {
  12643. return 0;
  12644. }
  12645. }
  12646. return 1;
  12647. }
  12648. }
  12649. return !node.attributes.length;
  12650. }
  12651. function doRemove(range) {
  12652. var bookmark1 = range.createBookmark();
  12653. if (range.collapsed) {
  12654. range.enlarge(true);
  12655. }
  12656. //不能把a标签切了
  12657. if (!notIncludeA) {
  12658. var aNode = domUtils.findParentByTagName(
  12659. range.startContainer,
  12660. "a",
  12661. true
  12662. );
  12663. if (aNode) {
  12664. range.setStartBefore(aNode);
  12665. }
  12666. aNode = domUtils.findParentByTagName(range.endContainer, "a", true);
  12667. if (aNode) {
  12668. range.setEndAfter(aNode);
  12669. }
  12670. }
  12671. bookmark = range.createBookmark();
  12672. node = bookmark.start;
  12673. //切开始
  12674. while ((parent = node.parentNode) && !domUtils.isBlockElm(parent)) {
  12675. domUtils.breakParent(node, parent);
  12676. domUtils.clearEmptySibling(node);
  12677. }
  12678. if (bookmark.end) {
  12679. //切结束
  12680. node = bookmark.end;
  12681. while ((parent = node.parentNode) && !domUtils.isBlockElm(parent)) {
  12682. domUtils.breakParent(node, parent);
  12683. domUtils.clearEmptySibling(node);
  12684. }
  12685. //开始去除样式
  12686. var current = domUtils.getNextDomNode(bookmark.start, false, filter),
  12687. next;
  12688. while (current) {
  12689. if (current == bookmark.end) {
  12690. break;
  12691. }
  12692. next = domUtils.getNextDomNode(current, true, filter);
  12693. if (
  12694. !dtd.$empty[current.tagName.toLowerCase()] &&
  12695. !domUtils.isBookmarkNode(current)
  12696. ) {
  12697. if (tagReg.test(current.tagName)) {
  12698. if (style) {
  12699. domUtils.removeStyle(current, style);
  12700. if (isRedundantSpan(current) && style != "text-decoration") {
  12701. domUtils.remove(current, true);
  12702. }
  12703. } else {
  12704. domUtils.remove(current, true);
  12705. }
  12706. } else {
  12707. //trace:939 不能把list上的样式去掉
  12708. if (
  12709. !dtd.$tableContent[current.tagName] &&
  12710. !dtd.$list[current.tagName]
  12711. ) {
  12712. domUtils.removeAttributes(current, removeFormatAttributes);
  12713. if (isRedundantSpan(current)) {
  12714. domUtils.remove(current, true);
  12715. }
  12716. }
  12717. }
  12718. }
  12719. current = next;
  12720. }
  12721. }
  12722. //trace:1035
  12723. //trace:1096 不能把td上的样式去掉,比如边框
  12724. var pN = bookmark.start.parentNode;
  12725. if (
  12726. domUtils.isBlockElm(pN) &&
  12727. !dtd.$tableContent[pN.tagName] &&
  12728. !dtd.$list[pN.tagName]
  12729. ) {
  12730. domUtils.removeAttributes(pN, removeFormatAttributes);
  12731. }
  12732. pN = bookmark.end.parentNode;
  12733. if (
  12734. bookmark.end &&
  12735. domUtils.isBlockElm(pN) &&
  12736. !dtd.$tableContent[pN.tagName] &&
  12737. !dtd.$list[pN.tagName]
  12738. ) {
  12739. domUtils.removeAttributes(pN, removeFormatAttributes);
  12740. }
  12741. range.moveToBookmark(bookmark).moveToBookmark(bookmark1);
  12742. //清除冗余的代码 <b><bookmark></b>
  12743. var node = range.startContainer,
  12744. tmp,
  12745. collapsed = range.collapsed;
  12746. while (
  12747. node.nodeType == 1 &&
  12748. domUtils.isEmptyNode(node) &&
  12749. dtd.$removeEmpty[node.tagName]
  12750. ) {
  12751. tmp = node.parentNode;
  12752. range.setStartBefore(node);
  12753. //trace:937
  12754. //更新结束边界
  12755. if (range.startContainer === range.endContainer) {
  12756. range.endOffset--;
  12757. }
  12758. domUtils.remove(node);
  12759. node = tmp;
  12760. }
  12761. if (!collapsed) {
  12762. node = range.endContainer;
  12763. while (
  12764. node.nodeType == 1 &&
  12765. domUtils.isEmptyNode(node) &&
  12766. dtd.$removeEmpty[node.tagName]
  12767. ) {
  12768. tmp = node.parentNode;
  12769. range.setEndBefore(node);
  12770. domUtils.remove(node);
  12771. node = tmp;
  12772. }
  12773. }
  12774. }
  12775. range = this.selection.getRange();
  12776. doRemove(range);
  12777. range.select();
  12778. }
  12779. };
  12780. };
  12781. // plugins/blockquote.js
  12782. /**
  12783. * 添加引用
  12784. * @file
  12785. * @since 1.2.6.1
  12786. */
  12787. /**
  12788. * 添加引用
  12789. * @command blockquote
  12790. * @method execCommand
  12791. * @param { String } cmd 命令字符串
  12792. * @example
  12793. * ```javascript
  12794. * editor.execCommand( 'blockquote' );
  12795. * ```
  12796. */
  12797. /**
  12798. * 添加引用
  12799. * @command blockquote
  12800. * @method execCommand
  12801. * @param { String } cmd 命令字符串
  12802. * @param { Object } attrs 节点属性
  12803. * @example
  12804. * ```javascript
  12805. * editor.execCommand( 'blockquote',{
  12806. * style: "color: red;"
  12807. * } );
  12808. * ```
  12809. */
  12810. UE.plugins["blockquote"] = function() {
  12811. var me = this;
  12812. function getObj(editor) {
  12813. return domUtils.filterNodeList(
  12814. editor.selection.getStartElementPath(),
  12815. "blockquote"
  12816. );
  12817. }
  12818. me.commands["blockquote"] = {
  12819. execCommand: function(cmdName, attrs) {
  12820. var range = this.selection.getRange(),
  12821. obj = getObj(this),
  12822. blockquote = dtd.blockquote,
  12823. bookmark = range.createBookmark();
  12824. if (obj) {
  12825. var start = range.startContainer,
  12826. startBlock = domUtils.isBlockElm(start)
  12827. ? start
  12828. : domUtils.findParent(start, function(node) {
  12829. return domUtils.isBlockElm(node);
  12830. }),
  12831. end = range.endContainer,
  12832. endBlock = domUtils.isBlockElm(end)
  12833. ? end
  12834. : domUtils.findParent(end, function(node) {
  12835. return domUtils.isBlockElm(node);
  12836. });
  12837. //处理一下li
  12838. startBlock =
  12839. domUtils.findParentByTagName(startBlock, "li", true) || startBlock;
  12840. endBlock =
  12841. domUtils.findParentByTagName(endBlock, "li", true) || endBlock;
  12842. if (
  12843. startBlock.tagName == "LI" ||
  12844. startBlock.tagName == "TD" ||
  12845. startBlock === obj ||
  12846. domUtils.isBody(startBlock)
  12847. ) {
  12848. domUtils.remove(obj, true);
  12849. } else {
  12850. domUtils.breakParent(startBlock, obj);
  12851. }
  12852. if (startBlock !== endBlock) {
  12853. obj = domUtils.findParentByTagName(endBlock, "blockquote");
  12854. if (obj) {
  12855. if (
  12856. endBlock.tagName == "LI" ||
  12857. endBlock.tagName == "TD" ||
  12858. domUtils.isBody(endBlock)
  12859. ) {
  12860. obj.parentNode && domUtils.remove(obj, true);
  12861. } else {
  12862. domUtils.breakParent(endBlock, obj);
  12863. }
  12864. }
  12865. }
  12866. var blockquotes = domUtils.getElementsByTagName(
  12867. this.document,
  12868. "blockquote"
  12869. );
  12870. for (var i = 0, bi; (bi = blockquotes[i++]); ) {
  12871. if (!bi.childNodes.length) {
  12872. domUtils.remove(bi);
  12873. } else if (
  12874. domUtils.getPosition(bi, startBlock) &
  12875. domUtils.POSITION_FOLLOWING &&
  12876. domUtils.getPosition(bi, endBlock) & domUtils.POSITION_PRECEDING
  12877. ) {
  12878. domUtils.remove(bi, true);
  12879. }
  12880. }
  12881. } else {
  12882. var tmpRange = range.cloneRange(),
  12883. node = tmpRange.startContainer.nodeType == 1
  12884. ? tmpRange.startContainer
  12885. : tmpRange.startContainer.parentNode,
  12886. preNode = node,
  12887. doEnd = 1;
  12888. //调整开始
  12889. while (1) {
  12890. if (domUtils.isBody(node)) {
  12891. if (preNode !== node) {
  12892. if (range.collapsed) {
  12893. tmpRange.selectNode(preNode);
  12894. doEnd = 0;
  12895. } else {
  12896. tmpRange.setStartBefore(preNode);
  12897. }
  12898. } else {
  12899. tmpRange.setStart(node, 0);
  12900. }
  12901. break;
  12902. }
  12903. if (!blockquote[node.tagName]) {
  12904. if (range.collapsed) {
  12905. tmpRange.selectNode(preNode);
  12906. } else {
  12907. tmpRange.setStartBefore(preNode);
  12908. }
  12909. break;
  12910. }
  12911. preNode = node;
  12912. node = node.parentNode;
  12913. }
  12914. //调整结束
  12915. if (doEnd) {
  12916. preNode = node = node = tmpRange.endContainer.nodeType == 1
  12917. ? tmpRange.endContainer
  12918. : tmpRange.endContainer.parentNode;
  12919. while (1) {
  12920. if (domUtils.isBody(node)) {
  12921. if (preNode !== node) {
  12922. tmpRange.setEndAfter(preNode);
  12923. } else {
  12924. tmpRange.setEnd(node, node.childNodes.length);
  12925. }
  12926. break;
  12927. }
  12928. if (!blockquote[node.tagName]) {
  12929. tmpRange.setEndAfter(preNode);
  12930. break;
  12931. }
  12932. preNode = node;
  12933. node = node.parentNode;
  12934. }
  12935. }
  12936. node = range.document.createElement("blockquote");
  12937. domUtils.setAttributes(node, attrs);
  12938. node.appendChild(tmpRange.extractContents());
  12939. tmpRange.insertNode(node);
  12940. //去除重复的
  12941. var childs = domUtils.getElementsByTagName(node, "blockquote");
  12942. for (var i = 0, ci; (ci = childs[i++]); ) {
  12943. if (ci.parentNode) {
  12944. domUtils.remove(ci, true);
  12945. }
  12946. }
  12947. }
  12948. range.moveToBookmark(bookmark).select();
  12949. },
  12950. queryCommandState: function() {
  12951. return getObj(this) ? 1 : 0;
  12952. }
  12953. };
  12954. };
  12955. // plugins/convertcase.js
  12956. /**
  12957. * 大小写转换
  12958. * @file
  12959. * @since 1.2.6.1
  12960. */
  12961. /**
  12962. * 把选区内文本变大写,与“tolowercase”命令互斥
  12963. * @command touppercase
  12964. * @method execCommand
  12965. * @param { String } cmd 命令字符串
  12966. * @example
  12967. * ```javascript
  12968. * editor.execCommand( 'touppercase' );
  12969. * ```
  12970. */
  12971. /**
  12972. * 把选区内文本变小写,与“touppercase”命令互斥
  12973. * @command tolowercase
  12974. * @method execCommand
  12975. * @param { String } cmd 命令字符串
  12976. * @example
  12977. * ```javascript
  12978. * editor.execCommand( 'tolowercase' );
  12979. * ```
  12980. */
  12981. UE.commands["touppercase"] = UE.commands["tolowercase"] = {
  12982. execCommand: function(cmd) {
  12983. var me = this;
  12984. var rng = me.selection.getRange();
  12985. if (rng.collapsed) {
  12986. return rng;
  12987. }
  12988. var bk = rng.createBookmark(),
  12989. bkEnd = bk.end,
  12990. filterFn = function(node) {
  12991. return !domUtils.isBr(node) && !domUtils.isWhitespace(node);
  12992. },
  12993. curNode = domUtils.getNextDomNode(bk.start, false, filterFn);
  12994. while (
  12995. curNode &&
  12996. domUtils.getPosition(curNode, bkEnd) & domUtils.POSITION_PRECEDING
  12997. ) {
  12998. if (curNode.nodeType == 3) {
  12999. curNode.nodeValue = curNode.nodeValue[
  13000. cmd == "touppercase" ? "toUpperCase" : "toLowerCase"
  13001. ]();
  13002. }
  13003. curNode = domUtils.getNextDomNode(curNode, true, filterFn);
  13004. if (curNode === bkEnd) {
  13005. break;
  13006. }
  13007. }
  13008. rng.moveToBookmark(bk).select();
  13009. }
  13010. };
  13011. // plugins/indent.js
  13012. /**
  13013. * 首行缩进
  13014. * @file
  13015. * @since 1.2.6.1
  13016. */
  13017. /**
  13018. * 缩进
  13019. * @command indent
  13020. * @method execCommand
  13021. * @param { String } cmd 命令字符串
  13022. * @example
  13023. * ```javascript
  13024. * editor.execCommand( 'indent' );
  13025. * ```
  13026. */
  13027. UE.commands["indent"] = {
  13028. execCommand: function() {
  13029. var me = this,
  13030. value = me.queryCommandState("indent")
  13031. ? "0em"
  13032. : me.options.indentValue || "2em";
  13033. me.execCommand("Paragraph", "p", { style: "text-indent:" + value });
  13034. },
  13035. queryCommandState: function() {
  13036. var pN = domUtils.filterNodeList(
  13037. this.selection.getStartElementPath(),
  13038. "p h1 h2 h3 h4 h5 h6"
  13039. );
  13040. return pN && pN.style.textIndent && parseInt(pN.style.textIndent) ? 1 : 0;
  13041. }
  13042. };
  13043. // plugins/print.js
  13044. /**
  13045. * 打印
  13046. * @file
  13047. * @since 1.2.6.1
  13048. */
  13049. /**
  13050. * 打印
  13051. * @command print
  13052. * @method execCommand
  13053. * @param { String } cmd 命令字符串
  13054. * @example
  13055. * ```javascript
  13056. * editor.execCommand( 'print' );
  13057. * ```
  13058. */
  13059. UE.commands["print"] = {
  13060. execCommand: function() {
  13061. this.window.print();
  13062. },
  13063. notNeedUndo: 1
  13064. };
  13065. // plugins/preview.js
  13066. /**
  13067. * 预览
  13068. * @file
  13069. * @since 1.2.6.1
  13070. */
  13071. /**
  13072. * 预览
  13073. * @command preview
  13074. * @method execCommand
  13075. * @param { String } cmd 命令字符串
  13076. * @example
  13077. * ```javascript
  13078. * editor.execCommand( 'preview' );
  13079. * ```
  13080. */
  13081. UE.commands["preview"] = {
  13082. execCommand: function() {
  13083. var w = window.open("", "_blank", ""),
  13084. d = w.document;
  13085. d.open();
  13086. d.write(
  13087. '<!DOCTYPE html><html><head><meta charset="utf-8"/><script src="' +
  13088. this.options.UEDITOR_HOME_URL +
  13089. 'neditor.parse.js"></script><script>' +
  13090. "setTimeout(function(){uParse('div',{rootPath: '" +
  13091. this.options.UEDITOR_HOME_URL +
  13092. "'})},300)" +
  13093. "</script></head><body><div>" +
  13094. this.getContent(null, null, true) +
  13095. "</div></body></html>"
  13096. );
  13097. d.close();
  13098. },
  13099. notNeedUndo: 1
  13100. };
  13101. // plugins/selectall.js
  13102. /**
  13103. * 全选
  13104. * @file
  13105. * @since 1.2.6.1
  13106. */
  13107. /**
  13108. * 选中所有内容
  13109. * @command selectall
  13110. * @method execCommand
  13111. * @param { String } cmd 命令字符串
  13112. * @example
  13113. * ```javascript
  13114. * editor.execCommand( 'selectall' );
  13115. * ```
  13116. */
  13117. UE.plugins["selectall"] = function() {
  13118. var me = this;
  13119. me.commands["selectall"] = {
  13120. execCommand: function() {
  13121. //去掉了原生的selectAll,因为会出现报错和当内容为空时,不能出现闭合状态的光标
  13122. var me = this,
  13123. body = me.body,
  13124. range = me.selection.getRange();
  13125. range.selectNodeContents(body);
  13126. if (domUtils.isEmptyBlock(body)) {
  13127. //opera不能自动合并到元素的里边,要手动处理一下
  13128. if (browser.opera && body.firstChild && body.firstChild.nodeType == 1) {
  13129. range.setStartAtFirst(body.firstChild);
  13130. }
  13131. range.collapse(true);
  13132. }
  13133. range.select(true);
  13134. },
  13135. notNeedUndo: 1
  13136. };
  13137. //快捷键
  13138. me.addshortcutkey({
  13139. selectAll: "ctrl+65"
  13140. });
  13141. };
  13142. // plugins/paragraph.js
  13143. /**
  13144. * 段落样式
  13145. * @file
  13146. * @since 1.2.6.1
  13147. */
  13148. /**
  13149. * 段落格式
  13150. * @command paragraph
  13151. * @method execCommand
  13152. * @param { String } cmd 命令字符串
  13153. * @param {String} style 标签值为:'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
  13154. * @param {Object} attrs 标签的属性
  13155. * @example
  13156. * ```javascript
  13157. * editor.execCommand( 'Paragraph','h1','{
  13158. * class:'test'
  13159. * }' );
  13160. * ```
  13161. */
  13162. /**
  13163. * 返回选区内节点标签名
  13164. * @command paragraph
  13165. * @method queryCommandValue
  13166. * @param { String } cmd 命令字符串
  13167. * @return { String } 节点标签名
  13168. * @example
  13169. * ```javascript
  13170. * editor.queryCommandValue( 'Paragraph' );
  13171. * ```
  13172. */
  13173. UE.plugins["paragraph"] = function () {
  13174. var me = this,
  13175. block = domUtils.isBlockElm,
  13176. notExchange = ["TD", "LI", "PRE"],
  13177. doParagraph = function (range, style, attrs, sourceCmdName) {
  13178. var bookmark = range.createBookmark(),
  13179. filterFn = function (node) {
  13180. return node.nodeType == 1
  13181. ? node.tagName.toLowerCase() != "br" &&
  13182. !domUtils.isBookmarkNode(node)
  13183. : !domUtils.isWhitespace(node);
  13184. },
  13185. para;
  13186. range.enlarge(true);
  13187. var bookmark2 = range.createBookmark(),
  13188. current = domUtils.getNextDomNode(bookmark2.start, false, filterFn),
  13189. tmpRange = range.cloneRange(),
  13190. tmpNode;
  13191. while (
  13192. current &&
  13193. !(
  13194. domUtils.getPosition(current, bookmark2.end) &
  13195. domUtils.POSITION_FOLLOWING
  13196. )
  13197. ) {
  13198. if (current.nodeType == 3 || !block(current)) {
  13199. tmpRange.setStartBefore(current);
  13200. while (current && current !== bookmark2.end && !block(current)) {
  13201. tmpNode = current;
  13202. current = domUtils.getNextDomNode(current, false, null, function (
  13203. node
  13204. ) {
  13205. return !block(node);
  13206. });
  13207. }
  13208. tmpRange.setEndAfter(tmpNode);
  13209. para = range.document.createElement(style);
  13210. if (attrs) {
  13211. domUtils.setAttributes(para, attrs);
  13212. if (
  13213. sourceCmdName &&
  13214. sourceCmdName == "customstyle" &&
  13215. attrs.style
  13216. ) {
  13217. para.style.cssText = attrs.style;
  13218. }
  13219. }
  13220. para.appendChild(tmpRange.extractContents());
  13221. //需要内容占位
  13222. if (domUtils.isEmptyNode(para)) {
  13223. domUtils.fillChar(range.document, para);
  13224. }
  13225. tmpRange.insertNode(para);
  13226. var parent = para.parentNode;
  13227. //如果para上一级是一个block元素且不是body,td就删除它
  13228. if (
  13229. block(parent) &&
  13230. !domUtils.isBody(para.parentNode) &&
  13231. utils.indexOf(notExchange, parent.tagName) == -1
  13232. ) {
  13233. //存储dir,style
  13234. if (!(sourceCmdName && sourceCmdName == "customstyle")) {
  13235. parent.getAttribute("dir") &&
  13236. para.setAttribute("dir", parent.getAttribute("dir"));
  13237. //trace:1070
  13238. parent.style.cssText &&
  13239. (para.style.cssText =
  13240. parent.style.cssText + ";" + para.style.cssText);
  13241. //trace:1030
  13242. parent.style.textAlign &&
  13243. !para.style.textAlign &&
  13244. (para.style.textAlign = parent.style.textAlign);
  13245. parent.style.textIndent &&
  13246. !para.style.textIndent &&
  13247. (para.style.textIndent = parent.style.textIndent);
  13248. parent.style.padding &&
  13249. !para.style.padding &&
  13250. (para.style.padding = parent.style.padding);
  13251. }
  13252. //trace:1706 选择的就是h1-6要删除
  13253. if (
  13254. attrs &&
  13255. /h\d/i.test(parent.tagName) &&
  13256. !/h\d/i.test(para.tagName)
  13257. ) {
  13258. domUtils.setAttributes(parent, attrs);
  13259. if (
  13260. sourceCmdName &&
  13261. sourceCmdName == "customstyle" &&
  13262. attrs.style
  13263. ) {
  13264. parent.style.cssText = attrs.style;
  13265. }
  13266. domUtils.remove(para, true);
  13267. para = parent;
  13268. } else {
  13269. domUtils.remove(para.parentNode, true);
  13270. }
  13271. }
  13272. if (utils.indexOf(notExchange, parent.tagName) != -1) {
  13273. current = parent;
  13274. } else {
  13275. current = para;
  13276. }
  13277. current = domUtils.getNextDomNode(current, false, filterFn);
  13278. } else {
  13279. current = domUtils.getNextDomNode(current, true, filterFn);
  13280. }
  13281. }
  13282. return range.moveToBookmark(bookmark2).moveToBookmark(bookmark);
  13283. };
  13284. me.setOpt("paragraph", {
  13285. p: "",
  13286. h1: "",
  13287. h2: "",
  13288. h3: "",
  13289. h4: "",
  13290. h5: "",
  13291. h6: ""
  13292. });
  13293. me.commands["paragraph"] = {
  13294. execCommand: function (cmdName, style, attrs, sourceCmdName) {
  13295. var range = this.selection.getRange();
  13296. //闭合时单独处理
  13297. if (range.collapsed) {
  13298. var txt = this.document.createTextNode("p");
  13299. range.insertNode(txt);
  13300. //去掉冗余的fillchar
  13301. if (browser.ie) {
  13302. var node = txt.previousSibling;
  13303. if (node && domUtils.isWhitespace(node)) {
  13304. domUtils.remove(node);
  13305. }
  13306. node = txt.nextSibling;
  13307. if (node && domUtils.isWhitespace(node)) {
  13308. domUtils.remove(node);
  13309. }
  13310. }
  13311. }
  13312. range = doParagraph(range, style, attrs, sourceCmdName);
  13313. if (txt) {
  13314. range.setStartBefore(txt).collapse(true);
  13315. pN = txt.parentNode;
  13316. domUtils.remove(txt);
  13317. if (domUtils.isBlockElm(pN) && domUtils.isEmptyNode(pN)) {
  13318. domUtils.fillNode(this.document, pN);
  13319. }
  13320. }
  13321. if (
  13322. browser.gecko &&
  13323. range.collapsed &&
  13324. range.startContainer.nodeType == 1
  13325. ) {
  13326. var child = range.startContainer.childNodes[range.startOffset];
  13327. if (
  13328. child &&
  13329. child.nodeType == 1 &&
  13330. child.tagName.toLowerCase() == style
  13331. ) {
  13332. range.setStart(child, 0).collapse(true);
  13333. }
  13334. }
  13335. //trace:1097 原来有true,原因忘了,但去了就不能清除多余的占位符了
  13336. range.select();
  13337. return true;
  13338. },
  13339. queryCommandValue: function () {
  13340. var node = domUtils.filterNodeList(
  13341. this.selection.getStartElementPath(),
  13342. "p h1 h2 h3 h4 h5 h6"
  13343. );
  13344. return node ? node.tagName.toLowerCase() : "";
  13345. }
  13346. };
  13347. };
  13348. // plugins/directionality.js
  13349. /**
  13350. * 设置文字输入的方向的插件
  13351. * @file
  13352. * @since 1.2.6.1
  13353. */
  13354. ;(function() {
  13355. var block = domUtils.isBlockElm,
  13356. getObj = function(editor) {
  13357. // var startNode = editor.selection.getStart(),
  13358. // parents;
  13359. // if ( startNode ) {
  13360. // //查找所有的是block的父亲节点
  13361. // parents = domUtils.findParents( startNode, true, block, true );
  13362. // for ( var i = 0,ci; ci = parents[i++]; ) {
  13363. // if ( ci.getAttribute( 'dir' ) ) {
  13364. // return ci;
  13365. // }
  13366. // }
  13367. // }
  13368. return domUtils.filterNodeList(
  13369. editor.selection.getStartElementPath(),
  13370. function(n) {
  13371. return n && n.nodeType == 1 && n.getAttribute("dir");
  13372. }
  13373. );
  13374. },
  13375. doDirectionality = function(range, editor, forward) {
  13376. var bookmark,
  13377. filterFn = function(node) {
  13378. return node.nodeType == 1
  13379. ? !domUtils.isBookmarkNode(node)
  13380. : !domUtils.isWhitespace(node);
  13381. },
  13382. obj = getObj(editor);
  13383. if (obj && range.collapsed) {
  13384. obj.setAttribute("dir", forward);
  13385. return range;
  13386. }
  13387. bookmark = range.createBookmark();
  13388. range.enlarge(true);
  13389. var bookmark2 = range.createBookmark(),
  13390. current = domUtils.getNextDomNode(bookmark2.start, false, filterFn),
  13391. tmpRange = range.cloneRange(),
  13392. tmpNode;
  13393. while (
  13394. current &&
  13395. !(
  13396. domUtils.getPosition(current, bookmark2.end) &
  13397. domUtils.POSITION_FOLLOWING
  13398. )
  13399. ) {
  13400. if (current.nodeType == 3 || !block(current)) {
  13401. tmpRange.setStartBefore(current);
  13402. while (current && current !== bookmark2.end && !block(current)) {
  13403. tmpNode = current;
  13404. current = domUtils.getNextDomNode(current, false, null, function(
  13405. node
  13406. ) {
  13407. return !block(node);
  13408. });
  13409. }
  13410. tmpRange.setEndAfter(tmpNode);
  13411. var common = tmpRange.getCommonAncestor();
  13412. if (!domUtils.isBody(common) && block(common)) {
  13413. //遍历到了block节点
  13414. common.setAttribute("dir", forward);
  13415. current = common;
  13416. } else {
  13417. //没有遍历到,添加一个block节点
  13418. var p = range.document.createElement("p");
  13419. p.setAttribute("dir", forward);
  13420. var frag = tmpRange.extractContents();
  13421. p.appendChild(frag);
  13422. tmpRange.insertNode(p);
  13423. current = p;
  13424. }
  13425. current = domUtils.getNextDomNode(current, false, filterFn);
  13426. } else {
  13427. current = domUtils.getNextDomNode(current, true, filterFn);
  13428. }
  13429. }
  13430. return range.moveToBookmark(bookmark2).moveToBookmark(bookmark);
  13431. };
  13432. /**
  13433. * 文字输入方向
  13434. * @command directionality
  13435. * @method execCommand
  13436. * @param { String } cmdName 命令字符串
  13437. * @param { String } forward 传入'ltr'表示从左向右输入,传入'rtl'表示从右向左输入
  13438. * @example
  13439. * ```javascript
  13440. * editor.execCommand( 'directionality', 'ltr');
  13441. * ```
  13442. */
  13443. /**
  13444. * 查询当前选区的文字输入方向
  13445. * @command directionality
  13446. * @method queryCommandValue
  13447. * @param { String } cmdName 命令字符串
  13448. * @return { String } 返回'ltr'表示从左向右输入,返回'rtl'表示从右向左输入
  13449. * @example
  13450. * ```javascript
  13451. * editor.queryCommandValue( 'directionality');
  13452. * ```
  13453. */
  13454. UE.commands["directionality"] = {
  13455. execCommand: function(cmdName, forward) {
  13456. var range = this.selection.getRange();
  13457. //闭合时单独处理
  13458. if (range.collapsed) {
  13459. var txt = this.document.createTextNode("d");
  13460. range.insertNode(txt);
  13461. }
  13462. doDirectionality(range, this, forward);
  13463. if (txt) {
  13464. range.setStartBefore(txt).collapse(true);
  13465. domUtils.remove(txt);
  13466. }
  13467. range.select();
  13468. return true;
  13469. },
  13470. queryCommandValue: function() {
  13471. var node = getObj(this);
  13472. return node ? node.getAttribute("dir") : "ltr";
  13473. }
  13474. };
  13475. })();
  13476. // plugins/horizontal.js
  13477. /**
  13478. * 插入分割线插件
  13479. * @file
  13480. * @since 1.2.6.1
  13481. */
  13482. /**
  13483. * 插入分割线
  13484. * @command horizontal
  13485. * @method execCommand
  13486. * @param { String } cmdName 命令字符串
  13487. * @example
  13488. * ```javascript
  13489. * editor.execCommand( 'horizontal' );
  13490. * ```
  13491. */
  13492. UE.plugins["horizontal"] = function() {
  13493. var me = this;
  13494. me.commands["horizontal"] = {
  13495. execCommand: function(cmdName) {
  13496. var me = this;
  13497. if (me.queryCommandState(cmdName) !== -1) {
  13498. me.execCommand("insertHtml", "<hr>");
  13499. var range = me.selection.getRange(),
  13500. start = range.startContainer;
  13501. if (start.nodeType == 1 && !start.childNodes[range.startOffset]) {
  13502. var tmp;
  13503. if ((tmp = start.childNodes[range.startOffset - 1])) {
  13504. if (tmp.nodeType == 1 && tmp.tagName == "HR") {
  13505. if (me.options.enterTag == "p") {
  13506. tmp = me.document.createElement("p");
  13507. range.insertNode(tmp);
  13508. range.setStart(tmp, 0).setCursor();
  13509. } else {
  13510. tmp = me.document.createElement("br");
  13511. range.insertNode(tmp);
  13512. range.setStartBefore(tmp).setCursor();
  13513. }
  13514. }
  13515. }
  13516. }
  13517. return true;
  13518. }
  13519. },
  13520. //边界在table里不能加分隔线
  13521. queryCommandState: function() {
  13522. return domUtils.filterNodeList(
  13523. this.selection.getStartElementPath(),
  13524. "table"
  13525. )
  13526. ? -1
  13527. : 0;
  13528. }
  13529. };
  13530. // me.addListener('delkeyup',function(){
  13531. // var rng = this.selection.getRange();
  13532. // if(browser.ie && browser.version > 8){
  13533. // rng.txtToElmBoundary(true);
  13534. // if(domUtils.isStartInblock(rng)){
  13535. // var tmpNode = rng.startContainer;
  13536. // var pre = tmpNode.previousSibling;
  13537. // if(pre && domUtils.isTagNode(pre,'hr')){
  13538. // domUtils.remove(pre);
  13539. // rng.select();
  13540. // return;
  13541. // }
  13542. // }
  13543. // }
  13544. // if(domUtils.isBody(rng.startContainer)){
  13545. // var hr = rng.startContainer.childNodes[rng.startOffset -1];
  13546. // if(hr && hr.nodeName == 'HR'){
  13547. // var next = hr.nextSibling;
  13548. // if(next){
  13549. // rng.setStart(next,0)
  13550. // }else if(hr.previousSibling){
  13551. // rng.setStartAtLast(hr.previousSibling)
  13552. // }else{
  13553. // var p = this.document.createElement('p');
  13554. // hr.parentNode.insertBefore(p,hr);
  13555. // domUtils.fillNode(this.document,p);
  13556. // rng.setStart(p,0);
  13557. // }
  13558. // domUtils.remove(hr);
  13559. // rng.setCursor(false,true);
  13560. // }
  13561. // }
  13562. // })
  13563. me.addListener("delkeydown", function(name, evt) {
  13564. var rng = this.selection.getRange();
  13565. rng.txtToElmBoundary(true);
  13566. if (domUtils.isStartInblock(rng)) {
  13567. var tmpNode = rng.startContainer;
  13568. var pre = tmpNode.previousSibling;
  13569. if (pre && domUtils.isTagNode(pre, "hr")) {
  13570. domUtils.remove(pre);
  13571. rng.select();
  13572. domUtils.preventDefault(evt);
  13573. return true;
  13574. }
  13575. }
  13576. });
  13577. };
  13578. // plugins/time.js
  13579. /**
  13580. * 插入时间和日期
  13581. * @file
  13582. * @since 1.2.6.1
  13583. */
  13584. /**
  13585. * 插入时间,默认格式:12:59:59
  13586. * @command time
  13587. * @method execCommand
  13588. * @param { String } cmd 命令字符串
  13589. * @example
  13590. * ```javascript
  13591. * editor.execCommand( 'time');
  13592. * ```
  13593. */
  13594. /**
  13595. * 插入日期,默认格式:2013-08-30
  13596. * @command date
  13597. * @method execCommand
  13598. * @param { String } cmd 命令字符串
  13599. * @example
  13600. * ```javascript
  13601. * editor.execCommand( 'date');
  13602. * ```
  13603. */
  13604. UE.commands["time"] = UE.commands["date"] = {
  13605. execCommand: function(cmd, format) {
  13606. var date = new Date();
  13607. function formatTime(date, format) {
  13608. var hh = ("0" + date.getHours()).slice(-2),
  13609. ii = ("0" + date.getMinutes()).slice(-2),
  13610. ss = ("0" + date.getSeconds()).slice(-2);
  13611. format = format || "hh:ii:ss";
  13612. return format.replace(/hh/gi, hh).replace(/ii/gi, ii).replace(/ss/gi, ss);
  13613. }
  13614. function formatDate(date, format) {
  13615. var yyyy = ("000" + date.getFullYear()).slice(-4),
  13616. yy = yyyy.slice(-2),
  13617. mm = ("0" + (date.getMonth() + 1)).slice(-2),
  13618. dd = ("0" + date.getDate()).slice(-2);
  13619. format = format || "yyyy-mm-dd";
  13620. return format
  13621. .replace(/yyyy/gi, yyyy)
  13622. .replace(/yy/gi, yy)
  13623. .replace(/mm/gi, mm)
  13624. .replace(/dd/gi, dd);
  13625. }
  13626. this.execCommand(
  13627. "insertHtml",
  13628. cmd == "time" ? formatTime(date, format) : formatDate(date, format)
  13629. );
  13630. }
  13631. };
  13632. // plugins/rowspacing.js
  13633. /**
  13634. * 段前段后间距插件
  13635. * @file
  13636. * @since 1.2.6.1
  13637. */
  13638. /**
  13639. * 设置段间距
  13640. * @command rowspacing
  13641. * @method execCommand
  13642. * @param { String } cmd 命令字符串
  13643. * @param { String } value 段间距的值,以px为单位
  13644. * @param { String } dir 间距位置,top或bottom,分别表示段前和段后
  13645. * @example
  13646. * ```javascript
  13647. * editor.execCommand( 'rowspacing', '10', 'top' );
  13648. * ```
  13649. */
  13650. UE.plugins["rowspacing"] = function() {
  13651. var me = this;
  13652. me.setOpt({
  13653. rowspacingtop: ["5", "10", "15", "20", "25"],
  13654. rowspacingbottom: ["5", "10", "15", "20", "25"]
  13655. });
  13656. me.commands["rowspacing"] = {
  13657. execCommand: function(cmdName, value, dir) {
  13658. this.execCommand("paragraph", "p", {
  13659. style: "margin-" + dir + ":" + value + "px"
  13660. });
  13661. return true;
  13662. },
  13663. queryCommandValue: function(cmdName, dir) {
  13664. var pN = domUtils.filterNodeList(
  13665. this.selection.getStartElementPath(),
  13666. function(node) {
  13667. return domUtils.isBlockElm(node);
  13668. }
  13669. ),
  13670. value;
  13671. //trace:1026
  13672. if (pN) {
  13673. value = domUtils
  13674. .getComputedStyle(pN, "margin-" + dir)
  13675. .replace(/[^\d]/g, "");
  13676. return !value ? 0 : value;
  13677. }
  13678. return 0;
  13679. }
  13680. };
  13681. };
  13682. // plugins/lineheight.js
  13683. /**
  13684. * 设置行内间距
  13685. * @file
  13686. * @since 1.2.6.1
  13687. */
  13688. UE.plugins["lineheight"] = function() {
  13689. var me = this;
  13690. me.setOpt({ lineheight: ["1", "1.5", "1.75", "2", "3", "4", "5"] });
  13691. /**
  13692. * 行距
  13693. * @command lineheight
  13694. * @method execCommand
  13695. * @param { String } cmdName 命令字符串
  13696. * @param { String } value 传入的行高值, 该值是当前字体的倍数, 例如: 1.5, 1.75
  13697. * @example
  13698. * ```javascript
  13699. * editor.execCommand( 'lineheight', 1.5);
  13700. * ```
  13701. */
  13702. /**
  13703. * 查询当前选区内容的行高大小
  13704. * @command lineheight
  13705. * @method queryCommandValue
  13706. * @param { String } cmd 命令字符串
  13707. * @return { String } 返回当前行高大小
  13708. * @example
  13709. * ```javascript
  13710. * editor.queryCommandValue( 'lineheight' );
  13711. * ```
  13712. */
  13713. me.commands["lineheight"] = {
  13714. execCommand: function(cmdName, value) {
  13715. this.execCommand("paragraph", "p", {
  13716. style: "line-height:" + (value == "1" ? "normal" : value + "em")
  13717. });
  13718. return true;
  13719. },
  13720. queryCommandValue: function() {
  13721. var pN = domUtils.filterNodeList(
  13722. this.selection.getStartElementPath(),
  13723. function(node) {
  13724. return domUtils.isBlockElm(node);
  13725. }
  13726. );
  13727. if (pN) {
  13728. var value = domUtils.getComputedStyle(pN, "line-height");
  13729. return value == "normal" ? 1 : value.replace(/[^\d.]*/gi, "");
  13730. }
  13731. }
  13732. };
  13733. };
  13734. // plugins/insertcode.js
  13735. /**
  13736. * 插入代码插件
  13737. * @file
  13738. * @since 1.2.6.1
  13739. */
  13740. UE.plugins["insertcode"] = function() {
  13741. var me = this;
  13742. me.ready(function() {
  13743. utils.cssRule(
  13744. "pre",
  13745. "pre{margin:.5em 0;padding:.4em .6em;border-radius:8px;background:#f8f8f8;}",
  13746. me.document
  13747. );
  13748. });
  13749. me.setOpt("insertcode", {
  13750. as3: "ActionScript3",
  13751. bash: "Bash/Shell",
  13752. cpp: "C/C++",
  13753. css: "Css",
  13754. cf: "CodeFunction",
  13755. "c#": "C#",
  13756. delphi: "Delphi",
  13757. diff: "Diff",
  13758. erlang: "Erlang",
  13759. groovy: "Groovy",
  13760. html: "Html",
  13761. java: "Java",
  13762. jfx: "JavaFx",
  13763. js: "Javascript",
  13764. pl: "Perl",
  13765. php: "Php",
  13766. plain: "Plain Text",
  13767. ps: "PowerShell",
  13768. python: "Python",
  13769. ruby: "Ruby",
  13770. scala: "Scala",
  13771. sql: "Sql",
  13772. vb: "Vb",
  13773. xml: "Xml"
  13774. });
  13775. /**
  13776. * 插入代码
  13777. * @command insertcode
  13778. * @method execCommand
  13779. * @param { String } cmd 命令字符串
  13780. * @param { String } lang 插入代码的语言
  13781. * @example
  13782. * ```javascript
  13783. * editor.execCommand( 'insertcode', 'javascript' );
  13784. * ```
  13785. */
  13786. /**
  13787. * 如果选区所在位置是插入插入代码区域,返回代码的语言
  13788. * @command insertcode
  13789. * @method queryCommandValue
  13790. * @param { String } cmd 命令字符串
  13791. * @return { String } 返回代码的语言
  13792. * @example
  13793. * ```javascript
  13794. * editor.queryCommandValue( 'insertcode' );
  13795. * ```
  13796. */
  13797. me.commands["insertcode"] = {
  13798. execCommand: function(cmd, lang) {
  13799. var me = this,
  13800. rng = me.selection.getRange(),
  13801. pre = domUtils.findParentByTagName(rng.startContainer, "pre", true);
  13802. if (pre) {
  13803. pre.className = "brush:" + lang + ";toolbar:false;";
  13804. } else {
  13805. var code = "";
  13806. if (rng.collapsed) {
  13807. code = browser.ie && browser.ie11below
  13808. ? browser.version <= 8 ? "&nbsp;" : ""
  13809. : "<br/>";
  13810. } else {
  13811. var frag = rng.extractContents();
  13812. var div = me.document.createElement("div");
  13813. div.appendChild(frag);
  13814. utils.each(
  13815. UE.filterNode(
  13816. UE.htmlparser(div.innerHTML.replace(/[\r\t]/g, "")),
  13817. me.options.filterTxtRules
  13818. ).children,
  13819. function(node) {
  13820. if (browser.ie && browser.ie11below && browser.version > 8) {
  13821. if (node.type == "element") {
  13822. if (node.tagName == "br") {
  13823. code += "\n";
  13824. } else if (!dtd.$empty[node.tagName]) {
  13825. utils.each(node.children, function(cn) {
  13826. if (cn.type == "element") {
  13827. if (cn.tagName == "br") {
  13828. code += "\n";
  13829. } else if (!dtd.$empty[node.tagName]) {
  13830. code += cn.innerText();
  13831. }
  13832. } else {
  13833. code += cn.data;
  13834. }
  13835. });
  13836. if (!/\n$/.test(code)) {
  13837. code += "\n";
  13838. }
  13839. }
  13840. } else {
  13841. code += node.data + "\n";
  13842. }
  13843. if (!node.nextSibling() && /\n$/.test(code)) {
  13844. code = code.replace(/\n$/, "");
  13845. }
  13846. } else {
  13847. if (browser.ie && browser.ie11below) {
  13848. if (node.type == "element") {
  13849. if (node.tagName == "br") {
  13850. code += "<br>";
  13851. } else if (!dtd.$empty[node.tagName]) {
  13852. utils.each(node.children, function(cn) {
  13853. if (cn.type == "element") {
  13854. if (cn.tagName == "br") {
  13855. code += "<br>";
  13856. } else if (!dtd.$empty[node.tagName]) {
  13857. code += cn.innerText();
  13858. }
  13859. } else {
  13860. code += cn.data;
  13861. }
  13862. });
  13863. if (!/br>$/.test(code)) {
  13864. code += "<br>";
  13865. }
  13866. }
  13867. } else {
  13868. code += node.data + "<br>";
  13869. }
  13870. if (!node.nextSibling() && /<br>$/.test(code)) {
  13871. code = code.replace(/<br>$/, "");
  13872. }
  13873. } else {
  13874. code += node.type == "element"
  13875. ? dtd.$empty[node.tagName] ? "" : node.innerText()
  13876. : node.data;
  13877. if (!/br\/?\s*>$/.test(code)) {
  13878. if (!node.nextSibling()) return;
  13879. code += "<br>";
  13880. }
  13881. }
  13882. }
  13883. }
  13884. );
  13885. }
  13886. me.execCommand(
  13887. "inserthtml",
  13888. '<pre id="coder"class="brush:' +
  13889. lang +
  13890. ';toolbar:false">' +
  13891. code +
  13892. "</pre>",
  13893. true
  13894. );
  13895. pre = me.document.getElementById("coder");
  13896. domUtils.removeAttributes(pre, "id");
  13897. var tmpNode = pre.previousSibling;
  13898. if (
  13899. tmpNode &&
  13900. ((tmpNode.nodeType == 3 &&
  13901. tmpNode.nodeValue.length == 1 &&
  13902. browser.ie &&
  13903. browser.version == 6) ||
  13904. domUtils.isEmptyBlock(tmpNode))
  13905. ) {
  13906. domUtils.remove(tmpNode);
  13907. }
  13908. var rng = me.selection.getRange();
  13909. if (domUtils.isEmptyBlock(pre)) {
  13910. rng.setStart(pre, 0).setCursor(false, true);
  13911. } else {
  13912. rng.selectNodeContents(pre).select();
  13913. }
  13914. }
  13915. },
  13916. queryCommandValue: function() {
  13917. var path = this.selection.getStartElementPath();
  13918. var lang = "";
  13919. utils.each(path, function(node) {
  13920. if (node.nodeName == "PRE") {
  13921. var match = node.className.match(/brush:([^;]+)/);
  13922. lang = match && match[1] ? match[1] : "";
  13923. return false;
  13924. }
  13925. });
  13926. return lang;
  13927. }
  13928. };
  13929. me.addInputRule(function(root) {
  13930. utils.each(root.getNodesByTagName("pre"), function(pre) {
  13931. var brs = pre.getNodesByTagName("br");
  13932. if (brs.length) {
  13933. browser.ie &&
  13934. browser.ie11below &&
  13935. browser.version > 8 &&
  13936. utils.each(brs, function(br) {
  13937. var txt = UE.uNode.createText("\n");
  13938. br.parentNode.insertBefore(txt, br);
  13939. br.parentNode.removeChild(br);
  13940. });
  13941. return;
  13942. }
  13943. if (browser.ie && browser.ie11below && browser.version > 8) return;
  13944. var code = pre.innerText().split(/\n/);
  13945. pre.innerHTML("");
  13946. utils.each(code, function(c) {
  13947. if (c.length) {
  13948. pre.appendChild(UE.uNode.createText(c));
  13949. }
  13950. pre.appendChild(UE.uNode.createElement("br"));
  13951. });
  13952. });
  13953. });
  13954. me.addOutputRule(function(root) {
  13955. utils.each(root.getNodesByTagName("pre"), function(pre) {
  13956. var code = "";
  13957. utils.each(pre.children, function(n) {
  13958. if (n.type == "text") {
  13959. //在ie下文本内容有可能末尾带有\n要去掉
  13960. //trace:3396
  13961. code += n.data.replace(/[ ]/g, "&nbsp;").replace(/\n$/, "");
  13962. } else {
  13963. if (n.tagName == "br") {
  13964. code += "\n";
  13965. } else {
  13966. code += !dtd.$empty[n.tagName] ? "" : n.innerText();
  13967. }
  13968. }
  13969. });
  13970. pre.innerText(code.replace(/(&nbsp;|\n)+$/, ""));
  13971. });
  13972. });
  13973. //不需要判断highlight的command列表
  13974. me.notNeedCodeQuery = {
  13975. help: 1,
  13976. undo: 1,
  13977. redo: 1,
  13978. source: 1,
  13979. print: 1,
  13980. searchreplace: 1,
  13981. fullscreen: 1,
  13982. preview: 1,
  13983. insertparagraph: 1,
  13984. elementpath: 1,
  13985. insertcode: 1,
  13986. inserthtml: 1,
  13987. selectall: 1
  13988. };
  13989. //将queyCommamndState重置
  13990. var orgQuery = me.queryCommandState;
  13991. me.queryCommandState = function(cmd) {
  13992. var me = this;
  13993. if (
  13994. !me.notNeedCodeQuery[cmd.toLowerCase()] &&
  13995. me.selection &&
  13996. me.queryCommandValue("insertcode")
  13997. ) {
  13998. return -1;
  13999. }
  14000. return UE.Editor.prototype.queryCommandState.apply(this, arguments);
  14001. };
  14002. me.addListener("beforeenterkeydown", function() {
  14003. var rng = me.selection.getRange();
  14004. var pre = domUtils.findParentByTagName(rng.startContainer, "pre", true);
  14005. if (pre) {
  14006. me.fireEvent("saveScene");
  14007. if (!rng.collapsed) {
  14008. rng.deleteContents();
  14009. }
  14010. if (!browser.ie || browser.ie9above) {
  14011. var tmpNode = me.document.createElement("br"),
  14012. pre;
  14013. rng.insertNode(tmpNode).setStartAfter(tmpNode).collapse(true);
  14014. var next = tmpNode.nextSibling;
  14015. if (!next && (!browser.ie || browser.version > 10)) {
  14016. rng.insertNode(tmpNode.cloneNode(false));
  14017. } else {
  14018. rng.setStartAfter(tmpNode);
  14019. }
  14020. pre = tmpNode.previousSibling;
  14021. var tmp;
  14022. while (pre) {
  14023. tmp = pre;
  14024. pre = pre.previousSibling;
  14025. if (!pre || pre.nodeName == "BR") {
  14026. pre = tmp;
  14027. break;
  14028. }
  14029. }
  14030. if (pre) {
  14031. var str = "";
  14032. while (
  14033. pre &&
  14034. pre.nodeName != "BR" &&
  14035. new RegExp("^[\\s" + domUtils.fillChar + "]*$").test(pre.nodeValue)
  14036. ) {
  14037. str += pre.nodeValue;
  14038. pre = pre.nextSibling;
  14039. }
  14040. if (pre.nodeName != "BR") {
  14041. var match = pre.nodeValue.match(
  14042. new RegExp("^([\\s" + domUtils.fillChar + "]+)")
  14043. );
  14044. if (match && match[1]) {
  14045. str += match[1];
  14046. }
  14047. }
  14048. if (str) {
  14049. str = me.document.createTextNode(str);
  14050. rng.insertNode(str).setStartAfter(str);
  14051. }
  14052. }
  14053. rng.collapse(true).select(true);
  14054. } else {
  14055. if (browser.version > 8) {
  14056. var txt = me.document.createTextNode("\n");
  14057. var start = rng.startContainer;
  14058. if (rng.startOffset == 0) {
  14059. var preNode = start.previousSibling;
  14060. if (preNode) {
  14061. rng.insertNode(txt);
  14062. var fillchar = me.document.createTextNode(" ");
  14063. rng
  14064. .setStartAfter(txt)
  14065. .insertNode(fillchar)
  14066. .setStart(fillchar, 0)
  14067. .collapse(true)
  14068. .select(true);
  14069. }
  14070. } else {
  14071. rng.insertNode(txt).setStartAfter(txt);
  14072. var fillchar = me.document.createTextNode(" ");
  14073. start = rng.startContainer.childNodes[rng.startOffset];
  14074. if (start && !/^\n/.test(start.nodeValue)) {
  14075. rng.setStartBefore(txt);
  14076. }
  14077. rng
  14078. .insertNode(fillchar)
  14079. .setStart(fillchar, 0)
  14080. .collapse(true)
  14081. .select(true);
  14082. }
  14083. } else {
  14084. var tmpNode = me.document.createElement("br");
  14085. rng.insertNode(tmpNode);
  14086. rng.insertNode(me.document.createTextNode(domUtils.fillChar));
  14087. rng.setStartAfter(tmpNode);
  14088. pre = tmpNode.previousSibling;
  14089. var tmp;
  14090. while (pre) {
  14091. tmp = pre;
  14092. pre = pre.previousSibling;
  14093. if (!pre || pre.nodeName == "BR") {
  14094. pre = tmp;
  14095. break;
  14096. }
  14097. }
  14098. if (pre) {
  14099. var str = "";
  14100. while (
  14101. pre &&
  14102. pre.nodeName != "BR" &&
  14103. new RegExp("^[ " + domUtils.fillChar + "]*$").test(pre.nodeValue)
  14104. ) {
  14105. str += pre.nodeValue;
  14106. pre = pre.nextSibling;
  14107. }
  14108. if (pre.nodeName != "BR") {
  14109. var match = pre.nodeValue.match(
  14110. new RegExp("^([ " + domUtils.fillChar + "]+)")
  14111. );
  14112. if (match && match[1]) {
  14113. str += match[1];
  14114. }
  14115. }
  14116. str = me.document.createTextNode(str);
  14117. rng.insertNode(str).setStartAfter(str);
  14118. }
  14119. rng.collapse(true).select();
  14120. }
  14121. }
  14122. me.fireEvent("saveScene");
  14123. return true;
  14124. }
  14125. });
  14126. me.addListener("tabkeydown", function(cmd, evt) {
  14127. var rng = me.selection.getRange();
  14128. var pre = domUtils.findParentByTagName(rng.startContainer, "pre", true);
  14129. if (pre) {
  14130. me.fireEvent("saveScene");
  14131. if (evt.shiftKey) {
  14132. } else {
  14133. if (!rng.collapsed) {
  14134. var bk = rng.createBookmark();
  14135. var start = bk.start.previousSibling;
  14136. while (start) {
  14137. if (pre.firstChild === start && !domUtils.isBr(start)) {
  14138. pre.insertBefore(me.document.createTextNode(" "), start);
  14139. break;
  14140. }
  14141. if (domUtils.isBr(start)) {
  14142. pre.insertBefore(
  14143. me.document.createTextNode(" "),
  14144. start.nextSibling
  14145. );
  14146. break;
  14147. }
  14148. start = start.previousSibling;
  14149. }
  14150. var end = bk.end;
  14151. start = bk.start.nextSibling;
  14152. if (pre.firstChild === bk.start) {
  14153. pre.insertBefore(
  14154. me.document.createTextNode(" "),
  14155. start.nextSibling
  14156. );
  14157. }
  14158. while (start && start !== end) {
  14159. if (domUtils.isBr(start) && start.nextSibling) {
  14160. if (start.nextSibling === end) {
  14161. break;
  14162. }
  14163. pre.insertBefore(
  14164. me.document.createTextNode(" "),
  14165. start.nextSibling
  14166. );
  14167. }
  14168. start = start.nextSibling;
  14169. }
  14170. rng.moveToBookmark(bk).select();
  14171. } else {
  14172. var tmpNode = me.document.createTextNode(" ");
  14173. rng
  14174. .insertNode(tmpNode)
  14175. .setStartAfter(tmpNode)
  14176. .collapse(true)
  14177. .select(true);
  14178. }
  14179. }
  14180. me.fireEvent("saveScene");
  14181. return true;
  14182. }
  14183. });
  14184. me.addListener("beforeinserthtml", function(evtName, html) {
  14185. var me = this,
  14186. rng = me.selection.getRange(),
  14187. pre = domUtils.findParentByTagName(rng.startContainer, "pre", true);
  14188. if (pre) {
  14189. if (!rng.collapsed) {
  14190. rng.deleteContents();
  14191. }
  14192. var htmlstr = "";
  14193. if (browser.ie && browser.version > 8) {
  14194. utils.each(
  14195. UE.filterNode(UE.htmlparser(html), me.options.filterTxtRules)
  14196. .children,
  14197. function(node) {
  14198. if (node.type == "element") {
  14199. if (node.tagName == "br") {
  14200. htmlstr += "\n";
  14201. } else if (!dtd.$empty[node.tagName]) {
  14202. utils.each(node.children, function(cn) {
  14203. if (cn.type == "element") {
  14204. if (cn.tagName == "br") {
  14205. htmlstr += "\n";
  14206. } else if (!dtd.$empty[node.tagName]) {
  14207. htmlstr += cn.innerText();
  14208. }
  14209. } else {
  14210. htmlstr += cn.data;
  14211. }
  14212. });
  14213. if (!/\n$/.test(htmlstr)) {
  14214. htmlstr += "\n";
  14215. }
  14216. }
  14217. } else {
  14218. htmlstr += node.data + "\n";
  14219. }
  14220. if (!node.nextSibling() && /\n$/.test(htmlstr)) {
  14221. htmlstr = htmlstr.replace(/\n$/, "");
  14222. }
  14223. }
  14224. );
  14225. var tmpNode = me.document.createTextNode(
  14226. utils.html(htmlstr.replace(/&nbsp;/g, " "))
  14227. );
  14228. rng.insertNode(tmpNode).selectNode(tmpNode).select();
  14229. } else {
  14230. var frag = me.document.createDocumentFragment();
  14231. utils.each(
  14232. UE.filterNode(UE.htmlparser(html), me.options.filterTxtRules)
  14233. .children,
  14234. function(node) {
  14235. if (node.type == "element") {
  14236. if (node.tagName == "br") {
  14237. frag.appendChild(me.document.createElement("br"));
  14238. } else if (!dtd.$empty[node.tagName]) {
  14239. utils.each(node.children, function(cn) {
  14240. if (cn.type == "element") {
  14241. if (cn.tagName == "br") {
  14242. frag.appendChild(me.document.createElement("br"));
  14243. } else if (!dtd.$empty[node.tagName]) {
  14244. frag.appendChild(
  14245. me.document.createTextNode(
  14246. utils.html(cn.innerText().replace(/&nbsp;/g, " "))
  14247. )
  14248. );
  14249. }
  14250. } else {
  14251. frag.appendChild(
  14252. me.document.createTextNode(
  14253. utils.html(cn.data.replace(/&nbsp;/g, " "))
  14254. )
  14255. );
  14256. }
  14257. });
  14258. if (frag.lastChild.nodeName != "BR") {
  14259. frag.appendChild(me.document.createElement("br"));
  14260. }
  14261. }
  14262. } else {
  14263. frag.appendChild(
  14264. me.document.createTextNode(
  14265. utils.html(node.data.replace(/&nbsp;/g, " "))
  14266. )
  14267. );
  14268. }
  14269. if (!node.nextSibling() && frag.lastChild.nodeName == "BR") {
  14270. frag.removeChild(frag.lastChild);
  14271. }
  14272. }
  14273. );
  14274. rng.insertNode(frag).select();
  14275. }
  14276. return true;
  14277. }
  14278. });
  14279. //方向键的处理
  14280. me.addListener("keydown", function(cmd, evt) {
  14281. var me = this,
  14282. keyCode = evt.keyCode || evt.which;
  14283. if (keyCode == 40) {
  14284. var rng = me.selection.getRange(),
  14285. pre,
  14286. start = rng.startContainer;
  14287. if (
  14288. rng.collapsed &&
  14289. (pre = domUtils.findParentByTagName(rng.startContainer, "pre", true)) &&
  14290. !pre.nextSibling
  14291. ) {
  14292. var last = pre.lastChild;
  14293. while (last && last.nodeName == "BR") {
  14294. last = last.previousSibling;
  14295. }
  14296. if (
  14297. last === start ||
  14298. (rng.startContainer === pre &&
  14299. rng.startOffset == pre.childNodes.length)
  14300. ) {
  14301. me.execCommand("insertparagraph");
  14302. domUtils.preventDefault(evt);
  14303. }
  14304. }
  14305. }
  14306. });
  14307. //trace:3395
  14308. me.addListener("delkeydown", function(type, evt) {
  14309. var rng = this.selection.getRange();
  14310. rng.txtToElmBoundary(true);
  14311. var start = rng.startContainer;
  14312. if (
  14313. domUtils.isTagNode(start, "pre") &&
  14314. rng.collapsed &&
  14315. domUtils.isStartInblock(rng)
  14316. ) {
  14317. var p = me.document.createElement("p");
  14318. domUtils.fillNode(me.document, p);
  14319. start.parentNode.insertBefore(p, start);
  14320. domUtils.remove(start);
  14321. rng.setStart(p, 0).setCursor(false, true);
  14322. domUtils.preventDefault(evt);
  14323. return true;
  14324. }
  14325. });
  14326. };
  14327. // plugins/cleardoc.js
  14328. /**
  14329. * 清空文档插件
  14330. * @file
  14331. * @since 1.2.6.1
  14332. */
  14333. /**
  14334. * 清空文档
  14335. * @command cleardoc
  14336. * @method execCommand
  14337. * @param { String } cmd 命令字符串
  14338. * @example
  14339. * ```javascript
  14340. * //editor 是编辑器实例
  14341. * editor.execCommand('cleardoc');
  14342. * ```
  14343. */
  14344. UE.commands["cleardoc"] = {
  14345. execCommand: function(cmdName) {
  14346. var me = this,
  14347. enterTag = me.options.enterTag,
  14348. range = me.selection.getRange();
  14349. if (enterTag == "br") {
  14350. me.body.innerHTML = "<br/>";
  14351. range.setStart(me.body, 0).setCursor();
  14352. } else {
  14353. me.body.innerHTML = "<p>" + (ie ? "" : "<br/>") + "</p>";
  14354. range.setStart(me.body.firstChild, 0).setCursor(false, true);
  14355. }
  14356. setTimeout(function() {
  14357. me.fireEvent("clearDoc");
  14358. }, 0);
  14359. }
  14360. };
  14361. // plugins/anchor.js
  14362. /**
  14363. * 锚点插件,为UEditor提供插入锚点支持
  14364. * @file
  14365. * @since 1.2.6.1
  14366. */
  14367. UE.plugin.register("anchor", function () {
  14368. var me = this;
  14369. return {
  14370. bindEvents: {
  14371. ready: function () {
  14372. utils.cssRule(
  14373. "anchor",
  14374. ".anchorclass{background: url('" +
  14375. this.options.themePath +
  14376. this.options.theme +
  14377. "/images/anchor.gif') no-repeat scroll left center transparent;cursor: auto;display: inline-block;height: 16px;width: 16px;}",
  14378. this.document
  14379. );
  14380. }
  14381. },
  14382. outputRule: function (root) {
  14383. utils.each(root.getNodesByTagName("img"), function (a) {
  14384. var val;
  14385. if ((val = a.getAttr("anchorname"))) {
  14386. a.tagName = "a";
  14387. a.setAttr({
  14388. anchorname: "",
  14389. name: val,
  14390. class: ""
  14391. });
  14392. }
  14393. });
  14394. },
  14395. inputRule: function (root) {
  14396. utils.each(root.getNodesByTagName("a"), function (a) {
  14397. var val;
  14398. if ((val = a.getAttr("name")) && !a.getAttr("href")) {
  14399. //过滤掉word冗余标签
  14400. //_Toc\d+有可能勿命中
  14401. if (/^\_Toc\d+$/.test(val)) {
  14402. a.parentNode.removeChild(a);
  14403. return;
  14404. }
  14405. a.tagName = "img";
  14406. a.setAttr({
  14407. anchorname: a.getAttr("name"),
  14408. class: "anchorclass"
  14409. });
  14410. a.setAttr("name");
  14411. }
  14412. });
  14413. },
  14414. commands: {
  14415. /**
  14416. * 插入锚点
  14417. * @command anchor
  14418. * @method execCommand
  14419. * @param { String } cmd 命令字符串
  14420. * @param { String } name 锚点名称字符串
  14421. * @example
  14422. * ```javascript
  14423. * //editor 是编辑器实例
  14424. * editor.execCommand('anchor', 'anchor1');
  14425. * ```
  14426. */
  14427. anchor: {
  14428. execCommand: function (cmd, name) {
  14429. var range = this.selection.getRange(),
  14430. img = range.getClosedNode();
  14431. if (img && img.getAttribute("anchorname")) {
  14432. if (name) {
  14433. img.setAttribute("anchorname", name);
  14434. } else {
  14435. range.setStartBefore(img).setCursor();
  14436. domUtils.remove(img);
  14437. }
  14438. } else {
  14439. if (name) {
  14440. //只在选区的开始插入
  14441. var anchor = utils.renderTplstr('<img anchorname="${name}" class="anchorclass"></img>', {
  14442. name: name
  14443. });
  14444. me.execCommand("inserthtml", anchor, true);
  14445. }
  14446. }
  14447. }
  14448. }
  14449. }
  14450. };
  14451. });
  14452. // plugins/wordcount.js
  14453. ///import core
  14454. ///commands 字数统计
  14455. ///commandsName WordCount,wordCount
  14456. ///commandsTitle 字数统计
  14457. /*
  14458. * Created by JetBrains WebStorm.
  14459. * User: taoqili
  14460. * Date: 11-9-7
  14461. * Time: 下午8:18
  14462. * To change this template use File | Settings | File Templates.
  14463. */
  14464. UE.plugins["wordcount"] = function() {
  14465. var me = this;
  14466. me.setOpt("wordCount", true);
  14467. me.addListener("contentchange", function() {
  14468. me.fireEvent("wordcount");
  14469. });
  14470. var timer;
  14471. me.addListener("ready", function() {
  14472. var me = this;
  14473. domUtils.on(me.body, "keyup", function(evt) {
  14474. var code = evt.keyCode || evt.which,
  14475. //忽略的按键,ctr,alt,shift,方向键
  14476. ignores = {
  14477. "16": 1,
  14478. "18": 1,
  14479. "20": 1,
  14480. "37": 1,
  14481. "38": 1,
  14482. "39": 1,
  14483. "40": 1
  14484. };
  14485. if (code in ignores) return;
  14486. clearTimeout(timer);
  14487. timer = setTimeout(function() {
  14488. me.fireEvent("wordcount");
  14489. }, 200);
  14490. });
  14491. });
  14492. };
  14493. // plugins/pagebreak.js
  14494. /**
  14495. * 分页功能插件
  14496. * @file
  14497. * @since 1.2.6.1
  14498. */
  14499. UE.plugins["pagebreak"] = function() {
  14500. var me = this,
  14501. notBreakTags = ["td"];
  14502. me.setOpt("pageBreakTag", "_ueditor_page_break_tag_");
  14503. function fillNode(node) {
  14504. if (domUtils.isEmptyBlock(node)) {
  14505. var firstChild = node.firstChild,
  14506. tmpNode;
  14507. while (
  14508. firstChild &&
  14509. firstChild.nodeType == 1 &&
  14510. domUtils.isEmptyBlock(firstChild)
  14511. ) {
  14512. tmpNode = firstChild;
  14513. firstChild = firstChild.firstChild;
  14514. }
  14515. !tmpNode && (tmpNode = node);
  14516. domUtils.fillNode(me.document, tmpNode);
  14517. }
  14518. }
  14519. //分页符样式添加
  14520. me.ready(function() {
  14521. utils.cssRule(
  14522. "pagebreak",
  14523. ".pagebreak{display:block;clear:both !important;cursor:default !important;width: 100% !important;margin:0;}",
  14524. me.document
  14525. );
  14526. });
  14527. function isHr(node) {
  14528. return (
  14529. node &&
  14530. node.nodeType == 1 &&
  14531. node.tagName == "HR" &&
  14532. node.className == "pagebreak"
  14533. );
  14534. }
  14535. me.addInputRule(function(root) {
  14536. root.traversal(function(node) {
  14537. if (node.type == "text" && node.data == me.options.pageBreakTag) {
  14538. var hr = UE.uNode.createElement(
  14539. '<hr class="pagebreak" noshade="noshade" size="5" style="-webkit-user-select: none;">'
  14540. );
  14541. node.parentNode.insertBefore(hr, node);
  14542. node.parentNode.removeChild(node);
  14543. }
  14544. });
  14545. });
  14546. me.addOutputRule(function(node) {
  14547. utils.each(node.getNodesByTagName("hr"), function(n) {
  14548. if (n.getAttr("class") == "pagebreak") {
  14549. var txt = UE.uNode.createText(me.options.pageBreakTag);
  14550. n.parentNode.insertBefore(txt, n);
  14551. n.parentNode.removeChild(n);
  14552. }
  14553. });
  14554. });
  14555. /**
  14556. * 插入分页符
  14557. * @command pagebreak
  14558. * @method execCommand
  14559. * @param { String } cmd 命令字符串
  14560. * @remind 在表格中插入分页符会把表格切分成两部分
  14561. * @remind 获取编辑器内的数据时, 编辑器会把分页符转换成“_ueditor_page_break_tag_”字符串,
  14562. * 以便于提交数据到服务器端后处理分页。
  14563. * @example
  14564. * ```javascript
  14565. * editor.execCommand( 'pagebreak'); //插入一个hr标签,带有样式类名pagebreak
  14566. * ```
  14567. */
  14568. me.commands["pagebreak"] = {
  14569. execCommand: function() {
  14570. var range = me.selection.getRange(),
  14571. hr = me.document.createElement("hr");
  14572. domUtils.setAttributes(hr, {
  14573. class: "pagebreak",
  14574. noshade: "noshade",
  14575. size: "5"
  14576. });
  14577. domUtils.unSelectable(hr);
  14578. //table单独处理
  14579. var node = domUtils.findParentByTagName(
  14580. range.startContainer,
  14581. notBreakTags,
  14582. true
  14583. ),
  14584. parents = [],
  14585. pN;
  14586. if (node) {
  14587. switch (node.tagName) {
  14588. case "TD":
  14589. pN = node.parentNode;
  14590. if (!pN.previousSibling) {
  14591. var table = domUtils.findParentByTagName(pN, "table");
  14592. // var tableWrapDiv = table.parentNode;
  14593. // if(tableWrapDiv && tableWrapDiv.nodeType == 1
  14594. // && tableWrapDiv.tagName == 'DIV'
  14595. // && tableWrapDiv.getAttribute('dropdrag')
  14596. // ){
  14597. // domUtils.remove(tableWrapDiv,true);
  14598. // }
  14599. table.parentNode.insertBefore(hr, table);
  14600. parents = domUtils.findParents(hr, true);
  14601. } else {
  14602. pN.parentNode.insertBefore(hr, pN);
  14603. parents = domUtils.findParents(hr);
  14604. }
  14605. pN = parents[1];
  14606. if (hr !== pN) {
  14607. domUtils.breakParent(hr, pN);
  14608. }
  14609. //table要重写绑定一下拖拽
  14610. me.fireEvent("afteradjusttable", me.document);
  14611. }
  14612. } else {
  14613. if (!range.collapsed) {
  14614. range.deleteContents();
  14615. var start = range.startContainer;
  14616. while (
  14617. !domUtils.isBody(start) &&
  14618. domUtils.isBlockElm(start) &&
  14619. domUtils.isEmptyNode(start)
  14620. ) {
  14621. range.setStartBefore(start).collapse(true);
  14622. domUtils.remove(start);
  14623. start = range.startContainer;
  14624. }
  14625. }
  14626. range.insertNode(hr);
  14627. var pN = hr.parentNode,
  14628. nextNode;
  14629. while (!domUtils.isBody(pN)) {
  14630. domUtils.breakParent(hr, pN);
  14631. nextNode = hr.nextSibling;
  14632. if (nextNode && domUtils.isEmptyBlock(nextNode)) {
  14633. domUtils.remove(nextNode);
  14634. }
  14635. pN = hr.parentNode;
  14636. }
  14637. nextNode = hr.nextSibling;
  14638. var pre = hr.previousSibling;
  14639. if (isHr(pre)) {
  14640. domUtils.remove(pre);
  14641. } else {
  14642. pre && fillNode(pre);
  14643. }
  14644. if (!nextNode) {
  14645. var p = me.document.createElement("p");
  14646. hr.parentNode.appendChild(p);
  14647. domUtils.fillNode(me.document, p);
  14648. range.setStart(p, 0).collapse(true);
  14649. } else {
  14650. if (isHr(nextNode)) {
  14651. domUtils.remove(nextNode);
  14652. } else {
  14653. fillNode(nextNode);
  14654. }
  14655. range.setEndAfter(hr).collapse(false);
  14656. }
  14657. range.select(true);
  14658. }
  14659. }
  14660. };
  14661. };
  14662. // plugins/wordimage.js
  14663. ///import core
  14664. ///commands 本地图片引导上传
  14665. ///commandsName WordImage
  14666. ///commandsTitle 本地图片引导上传
  14667. ///commandsDialog dialogs\wordimage
  14668. UE.plugin.register("wordimage", function() {
  14669. var me = this,
  14670. images = [];
  14671. return {
  14672. commands: {
  14673. wordimage: {
  14674. execCommand: function() {
  14675. var images = domUtils.getElementsByTagName(me.body, "img");
  14676. var urlList = [];
  14677. for (var i = 0, ci; (ci = images[i++]); ) {
  14678. var url = ci.getAttribute("word_img");
  14679. url && urlList.push(url);
  14680. }
  14681. return urlList;
  14682. },
  14683. queryCommandState: function() {
  14684. images = domUtils.getElementsByTagName(me.body, "img");
  14685. for (var i = 0, ci; (ci = images[i++]); ) {
  14686. if (ci.getAttribute("word_img")) {
  14687. return 1;
  14688. }
  14689. }
  14690. return -1;
  14691. },
  14692. notNeedUndo: true
  14693. }
  14694. },
  14695. inputRule: function(root) {
  14696. utils.each(root.getNodesByTagName("img"), function(img) {
  14697. var attrs = img.attrs,
  14698. flag = parseInt(attrs.width) < 128 || parseInt(attrs.height) < 43,
  14699. opt = me.options,
  14700. src = opt.UEDITOR_HOME_URL + "themes/notadd/images/spacer.gif";
  14701. if (attrs["src"] && /^(?:(file:\/+))/.test(attrs["src"])) {
  14702. img.setAttr({
  14703. width: attrs.width,
  14704. height: attrs.height,
  14705. alt: attrs.alt,
  14706. word_img: attrs.src,
  14707. src: src,
  14708. style:
  14709. "background:url(" +
  14710. (flag
  14711. ? opt.themePath + opt.theme + "/images/word.gif"
  14712. : opt.langPath + opt.lang + "/images/localimage.png") +
  14713. ") no-repeat center center;border:1px solid #ddd"
  14714. });
  14715. }
  14716. });
  14717. }
  14718. };
  14719. });
  14720. // plugins/dragdrop.js
  14721. UE.plugins["dragdrop"] = function() {
  14722. var me = this;
  14723. me.ready(function() {
  14724. domUtils.on(this.body, "dragend", function() {
  14725. var rng = me.selection.getRange();
  14726. var node = rng.getClosedNode() || me.selection.getStart();
  14727. if (node && node.tagName == "IMG") {
  14728. var pre = node.previousSibling,
  14729. next;
  14730. while ((next = node.nextSibling)) {
  14731. if (
  14732. next.nodeType == 1 &&
  14733. next.tagName == "SPAN" &&
  14734. !next.firstChild
  14735. ) {
  14736. domUtils.remove(next);
  14737. } else {
  14738. break;
  14739. }
  14740. }
  14741. if (
  14742. ((pre && pre.nodeType == 1 && !domUtils.isEmptyBlock(pre)) || !pre) &&
  14743. (!next || (next && !domUtils.isEmptyBlock(next)))
  14744. ) {
  14745. if (pre && pre.tagName == "P" && !domUtils.isEmptyBlock(pre)) {
  14746. pre.appendChild(node);
  14747. domUtils.moveChild(next, pre);
  14748. domUtils.remove(next);
  14749. } else if (
  14750. next &&
  14751. next.tagName == "P" &&
  14752. !domUtils.isEmptyBlock(next)
  14753. ) {
  14754. next.insertBefore(node, next.firstChild);
  14755. }
  14756. if (pre && pre.tagName == "P" && domUtils.isEmptyBlock(pre)) {
  14757. domUtils.remove(pre);
  14758. }
  14759. if (next && next.tagName == "P" && domUtils.isEmptyBlock(next)) {
  14760. domUtils.remove(next);
  14761. }
  14762. rng.selectNode(node).select();
  14763. me.fireEvent("saveScene");
  14764. }
  14765. }
  14766. });
  14767. });
  14768. me.addListener("keyup", function(type, evt) {
  14769. var keyCode = evt.keyCode || evt.which;
  14770. if (keyCode == 13) {
  14771. var rng = me.selection.getRange(),
  14772. node;
  14773. if (
  14774. (node = domUtils.findParentByTagName(rng.startContainer, "p", true))
  14775. ) {
  14776. if (domUtils.getComputedStyle(node, "text-align") == "center") {
  14777. domUtils.removeStyle(node, "text-align");
  14778. }
  14779. }
  14780. }
  14781. });
  14782. };
  14783. // plugins/undo.js
  14784. /**
  14785. * undo redo
  14786. * @file
  14787. * @since 1.2.6.1
  14788. */
  14789. /**
  14790. * 撤销上一次执行的命令
  14791. * @command undo
  14792. * @method execCommand
  14793. * @param { String } cmd 命令字符串
  14794. * @example
  14795. * ```javascript
  14796. * editor.execCommand( 'undo' );
  14797. * ```
  14798. */
  14799. /**
  14800. * 重做上一次执行的命令
  14801. * @command redo
  14802. * @method execCommand
  14803. * @param { String } cmd 命令字符串
  14804. * @example
  14805. * ```javascript
  14806. * editor.execCommand( 'redo' );
  14807. * ```
  14808. */
  14809. UE.plugins["undo"] = function() {
  14810. var saveSceneTimer;
  14811. var me = this,
  14812. maxUndoCount = me.options.maxUndoCount || 20,
  14813. maxInputCount = me.options.maxInputCount || 20,
  14814. fillchar = new RegExp(domUtils.fillChar + "|</hr>", "gi"); // ie会产生多余的</hr>
  14815. var noNeedFillCharTags = {
  14816. ol: 1,
  14817. ul: 1,
  14818. table: 1,
  14819. tbody: 1,
  14820. tr: 1,
  14821. body: 1
  14822. };
  14823. var orgState = me.options.autoClearEmptyNode;
  14824. function compareAddr(indexA, indexB) {
  14825. if (indexA.length != indexB.length) return 0;
  14826. for (var i = 0, l = indexA.length; i < l; i++) {
  14827. if (indexA[i] != indexB[i]) return 0;
  14828. }
  14829. return 1;
  14830. }
  14831. function compareRangeAddress(rngAddrA, rngAddrB) {
  14832. if (rngAddrA.collapsed != rngAddrB.collapsed) {
  14833. return 0;
  14834. }
  14835. if (
  14836. !compareAddr(rngAddrA.startAddress, rngAddrB.startAddress) ||
  14837. !compareAddr(rngAddrA.endAddress, rngAddrB.endAddress)
  14838. ) {
  14839. return 0;
  14840. }
  14841. return 1;
  14842. }
  14843. function UndoManager() {
  14844. this.list = [];
  14845. this.index = 0;
  14846. this.hasUndo = false;
  14847. this.hasRedo = false;
  14848. this.undo = function() {
  14849. if (this.hasUndo) {
  14850. if (!this.list[this.index - 1] && this.list.length == 1) {
  14851. this.reset();
  14852. return;
  14853. }
  14854. while (
  14855. this.list[this.index].content == this.list[this.index - 1].content
  14856. ) {
  14857. this.index--;
  14858. if (this.index == 0) {
  14859. return this.restore(0);
  14860. }
  14861. }
  14862. this.restore(--this.index);
  14863. }
  14864. };
  14865. this.redo = function() {
  14866. if (this.hasRedo) {
  14867. while (
  14868. this.list[this.index].content == this.list[this.index + 1].content
  14869. ) {
  14870. this.index++;
  14871. if (this.index == this.list.length - 1) {
  14872. return this.restore(this.index);
  14873. }
  14874. }
  14875. this.restore(++this.index);
  14876. }
  14877. };
  14878. this.restore = function() {
  14879. var me = this.editor;
  14880. var scene = this.list[this.index];
  14881. var root = UE.htmlparser(scene.content.replace(fillchar, ""));
  14882. me.options.autoClearEmptyNode = false;
  14883. me.filterInputRule(root);
  14884. me.options.autoClearEmptyNode = orgState;
  14885. //trace:873
  14886. //去掉展位符
  14887. me.document.body.innerHTML = root.toHtml();
  14888. me.fireEvent("afterscencerestore");
  14889. //处理undo后空格不展位的问题
  14890. if (browser.ie) {
  14891. utils.each(
  14892. domUtils.getElementsByTagName(me.document, "td th caption p"),
  14893. function(node) {
  14894. if (domUtils.isEmptyNode(node)) {
  14895. domUtils.fillNode(me.document, node);
  14896. }
  14897. }
  14898. );
  14899. }
  14900. try {
  14901. var rng = new dom.Range(me.document).moveToAddress(scene.address);
  14902. rng.select(
  14903. noNeedFillCharTags[rng.startContainer.nodeName.toLowerCase()]
  14904. );
  14905. } catch (e) {}
  14906. this.update();
  14907. this.clearKey();
  14908. //不能把自己reset了
  14909. me.fireEvent("reset", true);
  14910. };
  14911. this.getScene = function() {
  14912. var me = this.editor;
  14913. var rng = me.selection.getRange(),
  14914. rngAddress = rng.createAddress(false, true);
  14915. me.fireEvent("beforegetscene");
  14916. var root = UE.htmlparser(me.body.innerHTML);
  14917. me.options.autoClearEmptyNode = false;
  14918. me.filterOutputRule(root);
  14919. me.options.autoClearEmptyNode = orgState;
  14920. var cont = root.toHtml();
  14921. //trace:3461
  14922. //这个会引起回退时导致空格丢失的情况
  14923. // browser.ie && (cont = cont.replace(/>&nbsp;</g, '><').replace(/\s*</g, '<').replace(/>\s*/g, '>'));
  14924. me.fireEvent("aftergetscene");
  14925. return {
  14926. address: rngAddress,
  14927. content: cont
  14928. };
  14929. };
  14930. this.save = function(notCompareRange, notSetCursor) {
  14931. clearTimeout(saveSceneTimer);
  14932. var currentScene = this.getScene(notSetCursor),
  14933. lastScene = this.list[this.index];
  14934. if (lastScene && lastScene.content != currentScene.content) {
  14935. me.trigger("contentchange");
  14936. }
  14937. //内容相同位置相同不存
  14938. if (
  14939. lastScene &&
  14940. lastScene.content == currentScene.content &&
  14941. (notCompareRange
  14942. ? 1
  14943. : compareRangeAddress(lastScene.address, currentScene.address))
  14944. ) {
  14945. return;
  14946. }
  14947. this.list = this.list.slice(0, this.index + 1);
  14948. this.list.push(currentScene);
  14949. //如果大于最大数量了,就把最前的剔除
  14950. if (this.list.length > maxUndoCount) {
  14951. this.list.shift();
  14952. }
  14953. this.index = this.list.length - 1;
  14954. this.clearKey();
  14955. //跟新undo/redo状态
  14956. this.update();
  14957. };
  14958. this.update = function() {
  14959. this.hasRedo = !!this.list[this.index + 1];
  14960. this.hasUndo = !!this.list[this.index - 1];
  14961. };
  14962. this.reset = function() {
  14963. this.list = [];
  14964. this.index = 0;
  14965. this.hasUndo = false;
  14966. this.hasRedo = false;
  14967. this.clearKey();
  14968. };
  14969. this.clearKey = function() {
  14970. keycont = 0;
  14971. lastKeyCode = null;
  14972. };
  14973. }
  14974. me.undoManger = new UndoManager();
  14975. me.undoManger.editor = me;
  14976. function saveScene() {
  14977. this.undoManger.save();
  14978. }
  14979. me.addListener("saveScene", function() {
  14980. var args = Array.prototype.splice.call(arguments, 1);
  14981. this.undoManger.save.apply(this.undoManger, args);
  14982. });
  14983. // me.addListener('beforeexeccommand', saveScene);
  14984. // me.addListener('afterexeccommand', saveScene);
  14985. me.addListener("reset", function(type, exclude) {
  14986. if (!exclude) {
  14987. this.undoManger.reset();
  14988. }
  14989. });
  14990. me.commands["redo"] = me.commands["undo"] = {
  14991. execCommand: function(cmdName) {
  14992. this.undoManger[cmdName]();
  14993. },
  14994. queryCommandState: function(cmdName) {
  14995. return this.undoManger[
  14996. "has" + (cmdName.toLowerCase() == "undo" ? "Undo" : "Redo")
  14997. ]
  14998. ? 0
  14999. : -1;
  15000. },
  15001. notNeedUndo: 1
  15002. };
  15003. var keys = {
  15004. // /*Backspace*/ 8:1, /*Delete*/ 46:1,
  15005. /*Shift*/ 16: 1,
  15006. /*Ctrl*/ 17: 1,
  15007. /*Alt*/ 18: 1,
  15008. 37: 1,
  15009. 38: 1,
  15010. 39: 1,
  15011. 40: 1
  15012. },
  15013. keycont = 0,
  15014. lastKeyCode;
  15015. //输入法状态下不计算字符数
  15016. var inputType = false;
  15017. me.addListener("ready", function() {
  15018. domUtils.on(this.body, "compositionstart", function() {
  15019. inputType = true;
  15020. });
  15021. domUtils.on(this.body, "compositionend", function() {
  15022. inputType = false;
  15023. });
  15024. });
  15025. //快捷键
  15026. me.addshortcutkey({
  15027. Undo: "ctrl+90", //undo
  15028. Redo: "ctrl+89" //redo
  15029. });
  15030. var isCollapsed = true;
  15031. me.addListener("keydown", function(type, evt) {
  15032. var me = this;
  15033. var keyCode = evt.keyCode || evt.which;
  15034. if (
  15035. !keys[keyCode] &&
  15036. !evt.ctrlKey &&
  15037. !evt.metaKey &&
  15038. !evt.shiftKey &&
  15039. !evt.altKey
  15040. ) {
  15041. if (inputType) return;
  15042. if (!me.selection.getRange().collapsed) {
  15043. me.undoManger.save(false, true);
  15044. isCollapsed = false;
  15045. return;
  15046. }
  15047. if (me.undoManger.list.length == 0) {
  15048. me.undoManger.save(true);
  15049. }
  15050. clearTimeout(saveSceneTimer);
  15051. function save(cont) {
  15052. cont.undoManger.save(false, true);
  15053. cont.fireEvent("selectionchange");
  15054. }
  15055. saveSceneTimer = setTimeout(function() {
  15056. if (inputType) {
  15057. var interalTimer = setInterval(function() {
  15058. if (!inputType) {
  15059. save(me);
  15060. clearInterval(interalTimer);
  15061. }
  15062. }, 300);
  15063. return;
  15064. }
  15065. save(me);
  15066. }, 200);
  15067. lastKeyCode = keyCode;
  15068. keycont++;
  15069. if (keycont >= maxInputCount) {
  15070. save(me);
  15071. }
  15072. }
  15073. });
  15074. me.addListener("keyup", function(type, evt) {
  15075. var keyCode = evt.keyCode || evt.which;
  15076. if (
  15077. !keys[keyCode] &&
  15078. !evt.ctrlKey &&
  15079. !evt.metaKey &&
  15080. !evt.shiftKey &&
  15081. !evt.altKey
  15082. ) {
  15083. if (inputType) return;
  15084. if (!isCollapsed) {
  15085. this.undoManger.save(false, true);
  15086. isCollapsed = true;
  15087. }
  15088. }
  15089. });
  15090. //扩展实例,添加关闭和开启命令undo
  15091. me.stopCmdUndo = function() {
  15092. me.__hasEnterExecCommand = true;
  15093. };
  15094. me.startCmdUndo = function() {
  15095. me.__hasEnterExecCommand = false;
  15096. };
  15097. };
  15098. // plugins/copy.js
  15099. UE.plugin.register("copy", function() {
  15100. var me = this;
  15101. function initZeroClipboard() {
  15102. ZeroClipboard.config({
  15103. debug: false,
  15104. swfPath:
  15105. me.options.UEDITOR_HOME_URL +
  15106. "third-party/zeroclipboard/ZeroClipboard.swf"
  15107. });
  15108. var client = (me.zeroclipboard = new ZeroClipboard());
  15109. // 复制内容
  15110. client.on("copy", function(e) {
  15111. var client = e.client,
  15112. rng = me.selection.getRange(),
  15113. div = document.createElement("div");
  15114. div.appendChild(rng.cloneContents());
  15115. client.setText(div.innerText || div.textContent);
  15116. client.setHtml(div.innerHTML);
  15117. rng.select();
  15118. });
  15119. // hover事件传递到target
  15120. client.on("mouseover mouseout", function(e) {
  15121. var target = e.target;
  15122. if (target) {
  15123. if (e.type == "mouseover") {
  15124. domUtils.addClass(target, "edui-state-hover");
  15125. } else if (e.type == "mouseout") {
  15126. domUtils.removeClasses(target, "edui-state-hover");
  15127. }
  15128. }
  15129. });
  15130. // flash加载不成功
  15131. client.on("wrongflash noflash", function() {
  15132. ZeroClipboard.destroy();
  15133. });
  15134. // 触发事件
  15135. me.fireEvent("zeroclipboardready", client);
  15136. }
  15137. return {
  15138. bindEvents: {
  15139. ready: function() {
  15140. if (!browser.ie) {
  15141. if (window.ZeroClipboard) {
  15142. initZeroClipboard();
  15143. } else {
  15144. utils.loadFile(
  15145. document,
  15146. {
  15147. src:
  15148. me.options.UEDITOR_HOME_URL +
  15149. "third-party/zeroclipboard/ZeroClipboard.js",
  15150. tag: "script",
  15151. type: "text/javascript",
  15152. defer: "defer"
  15153. },
  15154. function() {
  15155. initZeroClipboard();
  15156. }
  15157. );
  15158. }
  15159. }
  15160. }
  15161. },
  15162. commands: {
  15163. copy: {
  15164. execCommand: function(cmd) {
  15165. if (!me.document.execCommand("copy")) {
  15166. alert(me.getLang("copymsg"));
  15167. }
  15168. }
  15169. }
  15170. }
  15171. };
  15172. });
  15173. // plugins/paste.js
  15174. ///import core
  15175. ///import plugins/inserthtml.js
  15176. ///import plugins/undo.js
  15177. ///import plugins/serialize.js
  15178. ///commands 粘贴
  15179. ///commandsName PastePlain
  15180. ///commandsTitle 纯文本粘贴模式
  15181. /**
  15182. * @description 粘贴
  15183. * @author zhanyi
  15184. */
  15185. UE.plugins["paste"] = function() {
  15186. function getClipboardData(callback) {
  15187. var doc = this.document;
  15188. if (doc.getElementById("baidu_pastebin")) {
  15189. return;
  15190. }
  15191. var range = this.selection.getRange(),
  15192. bk = range.createBookmark(),
  15193. //创建剪贴的容器div
  15194. pastebin = doc.createElement("div");
  15195. pastebin.id = "baidu_pastebin";
  15196. // Safari 要求div必须有内容,才能粘贴内容进来
  15197. browser.webkit &&
  15198. pastebin.appendChild(
  15199. doc.createTextNode(domUtils.fillChar + domUtils.fillChar)
  15200. );
  15201. doc.body.appendChild(pastebin);
  15202. //trace:717 隐藏的span不能得到top
  15203. //bk.start.innerHTML = '&nbsp;';
  15204. bk.start.style.display = "";
  15205. pastebin.style.cssText =
  15206. "position:absolute;width:1px;height:1px;overflow:hidden;left:-1000px;white-space:nowrap;top:" +
  15207. //要在现在光标平行的位置加入,否则会出现跳动的问题
  15208. domUtils.getXY(bk.start).y +
  15209. "px";
  15210. range.selectNodeContents(pastebin).select(true);
  15211. setTimeout(function() {
  15212. if (browser.webkit) {
  15213. for (
  15214. var i = 0, pastebins = doc.querySelectorAll("#baidu_pastebin"), pi;
  15215. (pi = pastebins[i++]);
  15216. ) {
  15217. if (domUtils.isEmptyNode(pi)) {
  15218. domUtils.remove(pi);
  15219. } else {
  15220. pastebin = pi;
  15221. break;
  15222. }
  15223. }
  15224. }
  15225. try {
  15226. pastebin.parentNode.removeChild(pastebin);
  15227. } catch (e) {}
  15228. range.moveToBookmark(bk).select(true);
  15229. callback(pastebin);
  15230. }, 0);
  15231. }
  15232. var me = this;
  15233. me.setOpt({
  15234. retainOnlyLabelPasted: false
  15235. });
  15236. var txtContent, htmlContent, address;
  15237. function getPureHtml(html) {
  15238. return html.replace(/<(\/?)([\w\-]+)([^>]*)>/gi, function(
  15239. a,
  15240. b,
  15241. tagName,
  15242. attrs
  15243. ) {
  15244. tagName = tagName.toLowerCase();
  15245. if ({ img: 1 }[tagName]) {
  15246. return a;
  15247. }
  15248. attrs = attrs.replace(
  15249. /([\w\-]*?)\s*=\s*(("([^"]*)")|('([^']*)')|([^\s>]+))/gi,
  15250. function(str, atr, val) {
  15251. if (
  15252. {
  15253. src: 1,
  15254. href: 1,
  15255. name: 1
  15256. }[atr.toLowerCase()]
  15257. ) {
  15258. return atr + "=" + val + " ";
  15259. }
  15260. return "";
  15261. }
  15262. );
  15263. if (
  15264. {
  15265. span: 1,
  15266. div: 1
  15267. }[tagName]
  15268. ) {
  15269. return "";
  15270. } else {
  15271. return "<" + b + tagName + " " + utils.trim(attrs) + ">";
  15272. }
  15273. });
  15274. }
  15275. function filter(div) {
  15276. var html;
  15277. if (div.firstChild) {
  15278. //去掉cut中添加的边界值
  15279. var nodes = domUtils.getElementsByTagName(div, "span");
  15280. for (var i = 0, ni; (ni = nodes[i++]); ) {
  15281. if (ni.id == "_baidu_cut_start" || ni.id == "_baidu_cut_end") {
  15282. domUtils.remove(ni);
  15283. }
  15284. }
  15285. if (browser.webkit) {
  15286. var brs = div.querySelectorAll("div br");
  15287. for (var i = 0, bi; (bi = brs[i++]); ) {
  15288. var pN = bi.parentNode;
  15289. if (pN.tagName == "DIV" && pN.childNodes.length == 1) {
  15290. pN.innerHTML = "<p><br/></p>";
  15291. domUtils.remove(pN);
  15292. }
  15293. }
  15294. var divs = div.querySelectorAll("#baidu_pastebin");
  15295. for (var i = 0, di; (di = divs[i++]); ) {
  15296. var tmpP = me.document.createElement("p");
  15297. di.parentNode.insertBefore(tmpP, di);
  15298. while (di.firstChild) {
  15299. tmpP.appendChild(di.firstChild);
  15300. }
  15301. domUtils.remove(di);
  15302. }
  15303. var metas = div.querySelectorAll("meta");
  15304. for (var i = 0, ci; (ci = metas[i++]); ) {
  15305. domUtils.remove(ci);
  15306. }
  15307. var brs = div.querySelectorAll("br");
  15308. for (i = 0; (ci = brs[i++]); ) {
  15309. if (/^apple-/i.test(ci.className)) {
  15310. domUtils.remove(ci);
  15311. }
  15312. }
  15313. }
  15314. if (browser.gecko) {
  15315. var dirtyNodes = div.querySelectorAll("[_moz_dirty]");
  15316. for (i = 0; (ci = dirtyNodes[i++]); ) {
  15317. ci.removeAttribute("_moz_dirty");
  15318. }
  15319. }
  15320. if (!browser.ie) {
  15321. var spans = div.querySelectorAll("span.Apple-style-span");
  15322. for (var i = 0, ci; (ci = spans[i++]); ) {
  15323. domUtils.remove(ci, true);
  15324. }
  15325. }
  15326. //ie下使用innerHTML会产生多余的\r\n字符,也会产生&nbsp;这里过滤掉
  15327. html = div.innerHTML; //.replace(/>(?:(\s|&nbsp;)*?)</g,'><');
  15328. //过滤word粘贴过来的冗余属性
  15329. html = UE.filterWord(html);
  15330. //取消了忽略空白的第二个参数,粘贴过来的有些是有空白的,会被套上相关的标签
  15331. var root = UE.htmlparser(html);
  15332. //如果给了过滤规则就先进行过滤
  15333. if (me.options.filterRules) {
  15334. UE.filterNode(root, me.options.filterRules);
  15335. }
  15336. //执行默认的处理
  15337. me.filterInputRule(root);
  15338. //针对chrome的处理
  15339. if (browser.webkit) {
  15340. var br = root.lastChild();
  15341. if (br && br.type == "element" && br.tagName == "br") {
  15342. root.removeChild(br);
  15343. }
  15344. utils.each(me.body.querySelectorAll("div"), function(node) {
  15345. if (domUtils.isEmptyBlock(node)) {
  15346. domUtils.remove(node, true);
  15347. }
  15348. });
  15349. }
  15350. html = { html: root.toHtml() };
  15351. me.fireEvent("beforepaste", html, root);
  15352. //抢了默认的粘贴,那后边的内容就不执行了,比如表格粘贴
  15353. if (!html.html) {
  15354. return;
  15355. }
  15356. root = UE.htmlparser(html.html, true);
  15357. //如果开启了纯文本模式
  15358. if (me.queryCommandState("pasteplain") === 1) {
  15359. me.execCommand(
  15360. "insertHtml",
  15361. UE.filterNode(root, me.options.filterTxtRules).toHtml(),
  15362. true
  15363. );
  15364. } else {
  15365. //文本模式
  15366. UE.filterNode(root, me.options.filterTxtRules);
  15367. txtContent = root.toHtml();
  15368. //完全模式
  15369. htmlContent = html.html;
  15370. address = me.selection.getRange().createAddress(true);
  15371. me.execCommand(
  15372. "insertHtml",
  15373. me.getOpt("retainOnlyLabelPasted") === true
  15374. ? getPureHtml(htmlContent)
  15375. : htmlContent,
  15376. true
  15377. );
  15378. }
  15379. me.fireEvent("afterpaste", html);
  15380. }
  15381. }
  15382. me.addListener("pasteTransfer", function(cmd, plainType) {
  15383. if (address && txtContent && htmlContent && txtContent != htmlContent) {
  15384. var range = me.selection.getRange();
  15385. range.moveToAddress(address, true);
  15386. if (!range.collapsed) {
  15387. while (!domUtils.isBody(range.startContainer)) {
  15388. var start = range.startContainer;
  15389. if (start.nodeType == 1) {
  15390. start = start.childNodes[range.startOffset];
  15391. if (!start) {
  15392. range.setStartBefore(range.startContainer);
  15393. continue;
  15394. }
  15395. var pre = start.previousSibling;
  15396. if (
  15397. pre &&
  15398. pre.nodeType == 3 &&
  15399. new RegExp("^[\n\r\t " + domUtils.fillChar + "]*$").test(
  15400. pre.nodeValue
  15401. )
  15402. ) {
  15403. range.setStartBefore(pre);
  15404. }
  15405. }
  15406. if (range.startOffset == 0) {
  15407. range.setStartBefore(range.startContainer);
  15408. } else {
  15409. break;
  15410. }
  15411. }
  15412. while (!domUtils.isBody(range.endContainer)) {
  15413. var end = range.endContainer;
  15414. if (end.nodeType == 1) {
  15415. end = end.childNodes[range.endOffset];
  15416. if (!end) {
  15417. range.setEndAfter(range.endContainer);
  15418. continue;
  15419. }
  15420. var next = end.nextSibling;
  15421. if (
  15422. next &&
  15423. next.nodeType == 3 &&
  15424. new RegExp("^[\n\r\t" + domUtils.fillChar + "]*$").test(
  15425. next.nodeValue
  15426. )
  15427. ) {
  15428. range.setEndAfter(next);
  15429. }
  15430. }
  15431. if (
  15432. range.endOffset ==
  15433. range.endContainer[
  15434. range.endContainer.nodeType == 3 ? "nodeValue" : "childNodes"
  15435. ].length
  15436. ) {
  15437. range.setEndAfter(range.endContainer);
  15438. } else {
  15439. break;
  15440. }
  15441. }
  15442. }
  15443. range.deleteContents();
  15444. range.select(true);
  15445. me.__hasEnterExecCommand = true;
  15446. var html = htmlContent;
  15447. if (plainType === 2) {
  15448. html = getPureHtml(html);
  15449. } else if (plainType) {
  15450. html = txtContent;
  15451. }
  15452. me.execCommand("inserthtml", html, true);
  15453. me.__hasEnterExecCommand = false;
  15454. var rng = me.selection.getRange();
  15455. while (
  15456. !domUtils.isBody(rng.startContainer) &&
  15457. !rng.startOffset &&
  15458. rng.startContainer[
  15459. rng.startContainer.nodeType == 3 ? "nodeValue" : "childNodes"
  15460. ].length
  15461. ) {
  15462. rng.setStartBefore(rng.startContainer);
  15463. }
  15464. var tmpAddress = rng.createAddress(true);
  15465. address.endAddress = tmpAddress.startAddress;
  15466. }
  15467. });
  15468. me.addListener("ready", function() {
  15469. domUtils.on(me.body, "cut", function() {
  15470. var range = me.selection.getRange();
  15471. if (!range.collapsed && me.undoManger) {
  15472. if (me.undoManger.list.length < 1) me.undoManger.save();
  15473. setTimeout(function() {
  15474. me.undoManger.save();
  15475. });
  15476. }
  15477. });
  15478. //ie下beforepaste在点击右键时也会触发,所以用监控键盘才处理
  15479. domUtils.on(
  15480. me.body,
  15481. browser.ie || browser.opera ? "keydown" : "paste",
  15482. function(e) {
  15483. if (
  15484. (browser.ie || browser.opera) &&
  15485. ((!e.ctrlKey && !e.metaKey) || e.keyCode != "86")
  15486. ) {
  15487. return;
  15488. }
  15489. getClipboardData.call(me, function(div) {
  15490. filter(div);
  15491. });
  15492. }
  15493. );
  15494. });
  15495. me.commands["paste"] = {
  15496. execCommand: function(cmd) {
  15497. if (browser.ie) {
  15498. getClipboardData.call(me, function(div) {
  15499. filter(div);
  15500. });
  15501. me.document.execCommand("paste");
  15502. } else {
  15503. alert(me.getLang("pastemsg"));
  15504. }
  15505. }
  15506. };
  15507. };
  15508. // plugins/puretxtpaste.js
  15509. /**
  15510. * 纯文本粘贴插件
  15511. * @file
  15512. * @since 1.2.6.1
  15513. */
  15514. UE.plugins["pasteplain"] = function() {
  15515. var me = this;
  15516. me.setOpt({
  15517. pasteplain: false,
  15518. filterTxtRules: (function() {
  15519. function transP(node) {
  15520. node.tagName = "p";
  15521. node.setStyle();
  15522. }
  15523. function removeNode(node) {
  15524. node.parentNode.removeChild(node, true);
  15525. }
  15526. return {
  15527. //直接删除及其字节点内容
  15528. "-": "script style object iframe embed input select",
  15529. p: { $: {} },
  15530. br: { $: {} },
  15531. div: function(node) {
  15532. var tmpNode,
  15533. p = UE.uNode.createElement("p");
  15534. while ((tmpNode = node.firstChild())) {
  15535. if (tmpNode.type == "text" || !UE.dom.dtd.$block[tmpNode.tagName]) {
  15536. p.appendChild(tmpNode);
  15537. } else {
  15538. if (p.firstChild()) {
  15539. node.parentNode.insertBefore(p, node);
  15540. p = UE.uNode.createElement("p");
  15541. } else {
  15542. node.parentNode.insertBefore(tmpNode, node);
  15543. }
  15544. }
  15545. }
  15546. if (p.firstChild()) {
  15547. node.parentNode.insertBefore(p, node);
  15548. }
  15549. node.parentNode.removeChild(node);
  15550. },
  15551. ol: removeNode,
  15552. ul: removeNode,
  15553. dl: removeNode,
  15554. dt: removeNode,
  15555. dd: removeNode,
  15556. li: removeNode,
  15557. caption: transP,
  15558. th: transP,
  15559. tr: transP,
  15560. h1: transP,
  15561. h2: transP,
  15562. h3: transP,
  15563. h4: transP,
  15564. h5: transP,
  15565. h6: transP,
  15566. td: function(node) {
  15567. //没有内容的td直接删掉
  15568. var txt = !!node.innerText();
  15569. if (txt) {
  15570. node.parentNode.insertAfter(
  15571. UE.uNode.createText(" &nbsp; &nbsp;"),
  15572. node
  15573. );
  15574. }
  15575. node.parentNode.removeChild(node, node.innerText());
  15576. }
  15577. };
  15578. })()
  15579. });
  15580. //暂时这里支持一下老版本的属性
  15581. var pasteplain = me.options.pasteplain;
  15582. /**
  15583. * 启用或取消纯文本粘贴模式
  15584. * @command pasteplain
  15585. * @method execCommand
  15586. * @param { String } cmd 命令字符串
  15587. * @example
  15588. * ```javascript
  15589. * editor.queryCommandState( 'pasteplain' );
  15590. * ```
  15591. */
  15592. /**
  15593. * 查询当前是否处于纯文本粘贴模式
  15594. * @command pasteplain
  15595. * @method queryCommandState
  15596. * @param { String } cmd 命令字符串
  15597. * @return { int } 如果处于纯文本模式,返回1,否则,返回0
  15598. * @example
  15599. * ```javascript
  15600. * editor.queryCommandState( 'pasteplain' );
  15601. * ```
  15602. */
  15603. me.commands["pasteplain"] = {
  15604. queryCommandState: function() {
  15605. return pasteplain ? 1 : 0;
  15606. },
  15607. execCommand: function() {
  15608. pasteplain = !pasteplain | 0;
  15609. },
  15610. notNeedUndo: 1
  15611. };
  15612. };
  15613. // plugins/list.js
  15614. /**
  15615. * 有序列表,无序列表插件
  15616. * @file
  15617. * @since 1.2.6.1
  15618. */
  15619. UE.plugins["list"] = function() {
  15620. var me = this,
  15621. notExchange = {
  15622. TD: 1,
  15623. PRE: 1,
  15624. BLOCKQUOTE: 1
  15625. };
  15626. var customStyle = {
  15627. cn: "cn-1-",
  15628. cn1: "cn-2-",
  15629. cn2: "cn-3-",
  15630. num: "num-1-",
  15631. num1: "num-2-",
  15632. num2: "num-3-",
  15633. dash: "dash",
  15634. dot: "dot"
  15635. };
  15636. me.setOpt({
  15637. autoTransWordToList: false,
  15638. insertorderedlist: {
  15639. num: "",
  15640. num1: "",
  15641. num2: "",
  15642. cn: "",
  15643. cn1: "",
  15644. cn2: "",
  15645. decimal: "",
  15646. "lower-alpha": "",
  15647. "lower-roman": "",
  15648. "upper-alpha": "",
  15649. "upper-roman": ""
  15650. },
  15651. insertunorderedlist: {
  15652. circle: "",
  15653. disc: "",
  15654. square: "",
  15655. dash: "",
  15656. dot: ""
  15657. },
  15658. listDefaultPaddingLeft: "30",
  15659. listiconpath: me.options.UEDITOR_HOME_URL + "themes/ueditor-list/",
  15660. maxListLevel: -1, //-1不限制
  15661. disablePInList: false
  15662. });
  15663. function listToArray(list) {
  15664. var arr = [];
  15665. for (var p in list) {
  15666. arr.push(p);
  15667. }
  15668. return arr;
  15669. }
  15670. var listStyle = {
  15671. OL: listToArray(me.options.insertorderedlist),
  15672. UL: listToArray(me.options.insertunorderedlist)
  15673. };
  15674. var liiconpath = me.options.listiconpath;
  15675. //根据用户配置,调整customStyle
  15676. for (var s in customStyle) {
  15677. if (
  15678. !me.options.insertorderedlist.hasOwnProperty(s) &&
  15679. !me.options.insertunorderedlist.hasOwnProperty(s)
  15680. ) {
  15681. delete customStyle[s];
  15682. }
  15683. }
  15684. me.ready(function() {
  15685. var customCss = [];
  15686. for (var p in customStyle) {
  15687. if (p == "dash" || p == "dot") {
  15688. customCss.push(
  15689. "li.list-" +
  15690. customStyle[p] +
  15691. "{background-image:url(" +
  15692. liiconpath +
  15693. customStyle[p] +
  15694. ".gif)}"
  15695. );
  15696. customCss.push(
  15697. "ul.custom_" +
  15698. p +
  15699. "{list-style:none;}ul.custom_" +
  15700. p +
  15701. " li{background-position:0 3px;background-repeat:no-repeat}"
  15702. );
  15703. } else {
  15704. for (var i = 0; i < 99; i++) {
  15705. customCss.push(
  15706. "li.list-" +
  15707. customStyle[p] +
  15708. i +
  15709. "{background-image:url(" +
  15710. liiconpath +
  15711. "list-" +
  15712. customStyle[p] +
  15713. i +
  15714. ".gif)}"
  15715. );
  15716. }
  15717. customCss.push(
  15718. "ol.custom_" +
  15719. p +
  15720. "{list-style:none;}ol.custom_" +
  15721. p +
  15722. " li{background-position:0 3px;background-repeat:no-repeat}"
  15723. );
  15724. }
  15725. switch (p) {
  15726. case "cn":
  15727. customCss.push("li.list-" + p + "-paddingleft-1{padding-left:25px}");
  15728. customCss.push("li.list-" + p + "-paddingleft-2{padding-left:40px}");
  15729. customCss.push("li.list-" + p + "-paddingleft-3{padding-left:55px}");
  15730. break;
  15731. case "cn1":
  15732. customCss.push("li.list-" + p + "-paddingleft-1{padding-left:30px}");
  15733. customCss.push("li.list-" + p + "-paddingleft-2{padding-left:40px}");
  15734. customCss.push("li.list-" + p + "-paddingleft-3{padding-left:55px}");
  15735. break;
  15736. case "cn2":
  15737. customCss.push("li.list-" + p + "-paddingleft-1{padding-left:40px}");
  15738. customCss.push("li.list-" + p + "-paddingleft-2{padding-left:55px}");
  15739. customCss.push("li.list-" + p + "-paddingleft-3{padding-left:68px}");
  15740. break;
  15741. case "num":
  15742. case "num1":
  15743. customCss.push("li.list-" + p + "-paddingleft-1{padding-left:25px}");
  15744. break;
  15745. case "num2":
  15746. customCss.push("li.list-" + p + "-paddingleft-1{padding-left:35px}");
  15747. customCss.push("li.list-" + p + "-paddingleft-2{padding-left:40px}");
  15748. break;
  15749. case "dash":
  15750. customCss.push("li.list-" + p + "-paddingleft{padding-left:35px}");
  15751. break;
  15752. case "dot":
  15753. customCss.push("li.list-" + p + "-paddingleft{padding-left:20px}");
  15754. }
  15755. }
  15756. customCss.push(".list-paddingleft-1{padding-left:0}");
  15757. customCss.push(
  15758. ".list-paddingleft-2{padding-left:" +
  15759. me.options.listDefaultPaddingLeft +
  15760. "px}"
  15761. );
  15762. customCss.push(
  15763. ".list-paddingleft-3{padding-left:" +
  15764. me.options.listDefaultPaddingLeft * 2 +
  15765. "px}"
  15766. );
  15767. //如果不给宽度会在自定应样式里出现滚动条
  15768. utils.cssRule(
  15769. "list",
  15770. "ol,ul{margin:0;pading:0;" +
  15771. (browser.ie ? "" : "width:95%") +
  15772. "}li{clear:both;}" +
  15773. customCss.join("\n"),
  15774. me.document
  15775. );
  15776. });
  15777. //单独处理剪切的问题
  15778. me.ready(function() {
  15779. domUtils.on(me.body, "cut", function() {
  15780. setTimeout(function() {
  15781. var rng = me.selection.getRange(),
  15782. li;
  15783. //trace:3416
  15784. if (!rng.collapsed) {
  15785. if (
  15786. (li = domUtils.findParentByTagName(rng.startContainer, "li", true))
  15787. ) {
  15788. if (!li.nextSibling && domUtils.isEmptyBlock(li)) {
  15789. var pn = li.parentNode,
  15790. node;
  15791. if ((node = pn.previousSibling)) {
  15792. domUtils.remove(pn);
  15793. rng.setStartAtLast(node).collapse(true);
  15794. rng.select(true);
  15795. } else if ((node = pn.nextSibling)) {
  15796. domUtils.remove(pn);
  15797. rng.setStartAtFirst(node).collapse(true);
  15798. rng.select(true);
  15799. } else {
  15800. var tmpNode = me.document.createElement("p");
  15801. domUtils.fillNode(me.document, tmpNode);
  15802. pn.parentNode.insertBefore(tmpNode, pn);
  15803. domUtils.remove(pn);
  15804. rng.setStart(tmpNode, 0).collapse(true);
  15805. rng.select(true);
  15806. }
  15807. }
  15808. }
  15809. }
  15810. });
  15811. });
  15812. });
  15813. function getStyle(node) {
  15814. var cls = node.className;
  15815. if (domUtils.hasClass(node, /custom_/)) {
  15816. return cls.match(/custom_(\w+)/)[1];
  15817. }
  15818. return domUtils.getStyle(node, "list-style-type");
  15819. }
  15820. me.addListener("beforepaste", function(type, html) {
  15821. var me = this,
  15822. rng = me.selection.getRange(),
  15823. li;
  15824. var root = UE.htmlparser(html.html, true);
  15825. if ((li = domUtils.findParentByTagName(rng.startContainer, "li", true))) {
  15826. var list = li.parentNode,
  15827. tagName = list.tagName == "OL" ? "ul" : "ol";
  15828. utils.each(root.getNodesByTagName(tagName), function(n) {
  15829. n.tagName = list.tagName;
  15830. n.setAttr();
  15831. if (n.parentNode === root) {
  15832. type = getStyle(list) || (list.tagName == "OL" ? "decimal" : "disc");
  15833. } else {
  15834. var className = n.parentNode.getAttr("class");
  15835. if (className && /custom_/.test(className)) {
  15836. type = className.match(/custom_(\w+)/)[1];
  15837. } else {
  15838. type = n.parentNode.getStyle("list-style-type");
  15839. }
  15840. if (!type) {
  15841. type = list.tagName == "OL" ? "decimal" : "disc";
  15842. }
  15843. }
  15844. var index = utils.indexOf(listStyle[list.tagName], type);
  15845. if (n.parentNode !== root)
  15846. index = index + 1 == listStyle[list.tagName].length ? 0 : index + 1;
  15847. var currentStyle = listStyle[list.tagName][index];
  15848. if (customStyle[currentStyle]) {
  15849. n.setAttr("class", "custom_" + currentStyle);
  15850. } else {
  15851. n.setStyle("list-style-type", currentStyle);
  15852. }
  15853. });
  15854. }
  15855. html.html = root.toHtml();
  15856. });
  15857. //导出时,去掉p标签
  15858. me.getOpt("disablePInList") === true &&
  15859. me.addOutputRule(function(root) {
  15860. utils.each(root.getNodesByTagName("li"), function(li) {
  15861. var newChildrens = [],
  15862. index = 0;
  15863. utils.each(li.children, function(n) {
  15864. if (n.tagName == "p") {
  15865. var tmpNode;
  15866. while ((tmpNode = n.children.pop())) {
  15867. newChildrens.splice(index, 0, tmpNode);
  15868. tmpNode.parentNode = li;
  15869. lastNode = tmpNode;
  15870. }
  15871. tmpNode = newChildrens[newChildrens.length - 1];
  15872. if (
  15873. !tmpNode ||
  15874. tmpNode.type != "element" ||
  15875. tmpNode.tagName != "br"
  15876. ) {
  15877. var br = UE.uNode.createElement("br");
  15878. br.parentNode = li;
  15879. newChildrens.push(br);
  15880. }
  15881. index = newChildrens.length;
  15882. }
  15883. });
  15884. if (newChildrens.length) {
  15885. li.children = newChildrens;
  15886. }
  15887. });
  15888. });
  15889. //进入编辑器的li要套p标签
  15890. me.addInputRule(function(root) {
  15891. utils.each(root.getNodesByTagName("li"), function(li) {
  15892. var tmpP = UE.uNode.createElement("p");
  15893. for (var i = 0, ci; (ci = li.children[i]); ) {
  15894. if (ci.type == "text" || dtd.p[ci.tagName]) {
  15895. tmpP.appendChild(ci);
  15896. } else {
  15897. if (tmpP.firstChild()) {
  15898. li.insertBefore(tmpP, ci);
  15899. tmpP = UE.uNode.createElement("p");
  15900. i = i + 2;
  15901. } else {
  15902. i++;
  15903. }
  15904. }
  15905. }
  15906. if ((tmpP.firstChild() && !tmpP.parentNode) || !li.firstChild()) {
  15907. li.appendChild(tmpP);
  15908. }
  15909. //trace:3357
  15910. //p不能为空
  15911. if (!tmpP.firstChild()) {
  15912. tmpP.innerHTML(browser.ie ? "&nbsp;" : "<br/>");
  15913. }
  15914. //去掉末尾的空白
  15915. var p = li.firstChild();
  15916. var lastChild = p.lastChild();
  15917. if (
  15918. lastChild &&
  15919. lastChild.type == "text" &&
  15920. /^\s*$/.test(lastChild.data)
  15921. ) {
  15922. p.removeChild(lastChild);
  15923. }
  15924. });
  15925. if (me.options.autoTransWordToList) {
  15926. var orderlisttype = {
  15927. num1: /^\d+\)/,
  15928. decimal: /^\d+\./,
  15929. "lower-alpha": /^[a-z]+\)/,
  15930. "upper-alpha": /^[A-Z]+\./,
  15931. cn: /^[\u4E00\u4E8C\u4E09\u56DB\u516d\u4e94\u4e03\u516b\u4e5d]+[\u3001]/,
  15932. cn2: /^\([\u4E00\u4E8C\u4E09\u56DB\u516d\u4e94\u4e03\u516b\u4e5d]+\)/
  15933. },
  15934. unorderlisttype = {
  15935. square: "n"
  15936. };
  15937. function checkListType(content, container) {
  15938. var span = container.firstChild();
  15939. if (
  15940. span &&
  15941. span.type == "element" &&
  15942. span.tagName == "span" &&
  15943. /Wingdings|Symbol/.test(span.getStyle("font-family"))
  15944. ) {
  15945. for (var p in unorderlisttype) {
  15946. if (unorderlisttype[p] == span.data) {
  15947. return p;
  15948. }
  15949. }
  15950. return "disc";
  15951. }
  15952. for (var p in orderlisttype) {
  15953. if (orderlisttype[p].test(content)) {
  15954. return p;
  15955. }
  15956. }
  15957. }
  15958. utils.each(root.getNodesByTagName("p"), function(node) {
  15959. if (node.getAttr("class") != "MsoListParagraph") {
  15960. return;
  15961. }
  15962. //word粘贴过来的会带有margin要去掉,但这样也可能会误命中一些央视
  15963. node.setStyle("margin", "");
  15964. node.setStyle("margin-left", "");
  15965. node.setAttr("class", "");
  15966. function appendLi(list, p, type) {
  15967. if (list.tagName == "ol") {
  15968. if (browser.ie) {
  15969. var first = p.firstChild();
  15970. if (
  15971. first.type == "element" &&
  15972. first.tagName == "span" &&
  15973. orderlisttype[type].test(first.innerText())
  15974. ) {
  15975. p.removeChild(first);
  15976. }
  15977. } else {
  15978. p.innerHTML(p.innerHTML().replace(orderlisttype[type], ""));
  15979. }
  15980. } else {
  15981. p.removeChild(p.firstChild());
  15982. }
  15983. var li = UE.uNode.createElement("li");
  15984. li.appendChild(p);
  15985. list.appendChild(li);
  15986. }
  15987. var tmp = node,
  15988. type,
  15989. cacheNode = node;
  15990. if (
  15991. node.parentNode.tagName != "li" &&
  15992. (type = checkListType(node.innerText(), node))
  15993. ) {
  15994. var list = UE.uNode.createElement(
  15995. me.options.insertorderedlist.hasOwnProperty(type) ? "ol" : "ul"
  15996. );
  15997. if (customStyle[type]) {
  15998. list.setAttr("class", "custom_" + type);
  15999. } else {
  16000. list.setStyle("list-style-type", type);
  16001. }
  16002. while (
  16003. node &&
  16004. node.parentNode.tagName != "li" &&
  16005. checkListType(node.innerText(), node)
  16006. ) {
  16007. tmp = node.nextSibling();
  16008. if (!tmp) {
  16009. node.parentNode.insertBefore(list, node);
  16010. }
  16011. appendLi(list, node, type);
  16012. node = tmp;
  16013. }
  16014. if (!list.parentNode && node && node.parentNode) {
  16015. node.parentNode.insertBefore(list, node);
  16016. }
  16017. }
  16018. var span = cacheNode.firstChild();
  16019. if (
  16020. span &&
  16021. span.type == "element" &&
  16022. span.tagName == "span" &&
  16023. /^\s*(&nbsp;)+\s*$/.test(span.innerText())
  16024. ) {
  16025. span.parentNode.removeChild(span);
  16026. }
  16027. });
  16028. }
  16029. });
  16030. //调整索引标签
  16031. me.addListener("contentchange", function() {
  16032. adjustListStyle(me.document);
  16033. });
  16034. function adjustListStyle(doc, ignore) {
  16035. utils.each(domUtils.getElementsByTagName(doc, "ol ul"), function(node) {
  16036. if (!domUtils.inDoc(node, doc)) return;
  16037. var parent = node.parentNode;
  16038. if (parent.tagName == node.tagName) {
  16039. var nodeStyleType =
  16040. getStyle(node) || (node.tagName == "OL" ? "decimal" : "disc"),
  16041. parentStyleType =
  16042. getStyle(parent) || (parent.tagName == "OL" ? "decimal" : "disc");
  16043. if (nodeStyleType == parentStyleType) {
  16044. var styleIndex = utils.indexOf(
  16045. listStyle[node.tagName],
  16046. nodeStyleType
  16047. );
  16048. styleIndex = styleIndex + 1 == listStyle[node.tagName].length
  16049. ? 0
  16050. : styleIndex + 1;
  16051. setListStyle(node, listStyle[node.tagName][styleIndex]);
  16052. }
  16053. }
  16054. var index = 0,
  16055. type = 2;
  16056. if (domUtils.hasClass(node, /custom_/)) {
  16057. if (
  16058. !(
  16059. /[ou]l/i.test(parent.tagName) &&
  16060. domUtils.hasClass(parent, /custom_/)
  16061. )
  16062. ) {
  16063. type = 1;
  16064. }
  16065. } else {
  16066. if (
  16067. /[ou]l/i.test(parent.tagName) &&
  16068. domUtils.hasClass(parent, /custom_/)
  16069. ) {
  16070. type = 3;
  16071. }
  16072. }
  16073. var style = domUtils.getStyle(node, "list-style-type");
  16074. style && (node.style.cssText = "list-style-type:" + style);
  16075. node.className =
  16076. utils.trim(node.className.replace(/list-paddingleft-\w+/, "")) +
  16077. " list-paddingleft-" +
  16078. type;
  16079. utils.each(domUtils.getElementsByTagName(node, "li"), function(li) {
  16080. li.style.cssText && (li.style.cssText = "");
  16081. if (!li.firstChild) {
  16082. domUtils.remove(li);
  16083. return;
  16084. }
  16085. if (li.parentNode !== node) {
  16086. return;
  16087. }
  16088. index++;
  16089. if (domUtils.hasClass(node, /custom_/)) {
  16090. var paddingLeft = 1,
  16091. currentStyle = getStyle(node);
  16092. if (node.tagName == "OL") {
  16093. if (currentStyle) {
  16094. switch (currentStyle) {
  16095. case "cn":
  16096. case "cn1":
  16097. case "cn2":
  16098. if (
  16099. index > 10 &&
  16100. (index % 10 == 0 || (index > 10 && index < 20))
  16101. ) {
  16102. paddingLeft = 2;
  16103. } else if (index > 20) {
  16104. paddingLeft = 3;
  16105. }
  16106. break;
  16107. case "num2":
  16108. if (index > 9) {
  16109. paddingLeft = 2;
  16110. }
  16111. }
  16112. }
  16113. li.className =
  16114. "list-" +
  16115. customStyle[currentStyle] +
  16116. index +
  16117. " " +
  16118. "list-" +
  16119. currentStyle +
  16120. "-paddingleft-" +
  16121. paddingLeft;
  16122. } else {
  16123. li.className =
  16124. "list-" +
  16125. customStyle[currentStyle] +
  16126. " " +
  16127. "list-" +
  16128. currentStyle +
  16129. "-paddingleft";
  16130. }
  16131. } else {
  16132. li.className = li.className.replace(/list-[\w\-]+/gi, "");
  16133. }
  16134. var className = li.getAttribute("class");
  16135. if (className !== null && !className.replace(/\s/g, "")) {
  16136. domUtils.removeAttributes(li, "class");
  16137. }
  16138. });
  16139. !ignore &&
  16140. adjustList(
  16141. node,
  16142. node.tagName.toLowerCase(),
  16143. getStyle(node) || domUtils.getStyle(node, "list-style-type"),
  16144. true
  16145. );
  16146. });
  16147. }
  16148. function adjustList(list, tag, style, ignoreEmpty) {
  16149. var nextList = list.nextSibling;
  16150. if (
  16151. nextList &&
  16152. nextList.nodeType == 1 &&
  16153. nextList.tagName.toLowerCase() == tag &&
  16154. (getStyle(nextList) ||
  16155. domUtils.getStyle(nextList, "list-style-type") ||
  16156. (tag == "ol" ? "decimal" : "disc")) == style
  16157. ) {
  16158. domUtils.moveChild(nextList, list);
  16159. if (nextList.childNodes.length == 0) {
  16160. domUtils.remove(nextList);
  16161. }
  16162. }
  16163. if (nextList && domUtils.isFillChar(nextList)) {
  16164. domUtils.remove(nextList);
  16165. }
  16166. var preList = list.previousSibling;
  16167. if (
  16168. preList &&
  16169. preList.nodeType == 1 &&
  16170. preList.tagName.toLowerCase() == tag &&
  16171. (getStyle(preList) ||
  16172. domUtils.getStyle(preList, "list-style-type") ||
  16173. (tag == "ol" ? "decimal" : "disc")) == style
  16174. ) {
  16175. domUtils.moveChild(list, preList);
  16176. }
  16177. if (preList && domUtils.isFillChar(preList)) {
  16178. domUtils.remove(preList);
  16179. }
  16180. !ignoreEmpty && domUtils.isEmptyBlock(list) && domUtils.remove(list);
  16181. if (getStyle(list)) {
  16182. adjustListStyle(list.ownerDocument, true);
  16183. }
  16184. }
  16185. function setListStyle(list, style) {
  16186. if (customStyle[style]) {
  16187. list.className = "custom_" + style;
  16188. }
  16189. try {
  16190. domUtils.setStyle(list, "list-style-type", style);
  16191. } catch (e) {}
  16192. }
  16193. function clearEmptySibling(node) {
  16194. var tmpNode = node.previousSibling;
  16195. if (tmpNode && domUtils.isEmptyBlock(tmpNode)) {
  16196. domUtils.remove(tmpNode);
  16197. }
  16198. tmpNode = node.nextSibling;
  16199. if (tmpNode && domUtils.isEmptyBlock(tmpNode)) {
  16200. domUtils.remove(tmpNode);
  16201. }
  16202. }
  16203. me.addListener("keydown", function(type, evt) {
  16204. function preventAndSave() {
  16205. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  16206. me.fireEvent("contentchange");
  16207. me.undoManger && me.undoManger.save();
  16208. }
  16209. function findList(node, filterFn) {
  16210. while (node && !domUtils.isBody(node)) {
  16211. if (filterFn(node)) {
  16212. return null;
  16213. }
  16214. if (node.nodeType == 1 && /[ou]l/i.test(node.tagName)) {
  16215. return node;
  16216. }
  16217. node = node.parentNode;
  16218. }
  16219. return null;
  16220. }
  16221. var keyCode = evt.keyCode || evt.which;
  16222. if (keyCode == 13 && !evt.shiftKey) {
  16223. //回车
  16224. var rng = me.selection.getRange(),
  16225. parent = domUtils.findParent(
  16226. rng.startContainer,
  16227. function(node) {
  16228. return domUtils.isBlockElm(node);
  16229. },
  16230. true
  16231. ),
  16232. li = domUtils.findParentByTagName(rng.startContainer, "li", true);
  16233. if (parent && parent.tagName != "PRE" && !li) {
  16234. var html = parent.innerHTML.replace(
  16235. new RegExp(domUtils.fillChar, "g"),
  16236. ""
  16237. );
  16238. if (/^\s*1\s*\.[^\d]/.test(html)) {
  16239. parent.innerHTML = html.replace(/^\s*1\s*\./, "");
  16240. rng.setStartAtLast(parent).collapse(true).select();
  16241. me.__hasEnterExecCommand = true;
  16242. me.execCommand("insertorderedlist");
  16243. me.__hasEnterExecCommand = false;
  16244. }
  16245. }
  16246. var range = me.selection.getRange(),
  16247. start = findList(range.startContainer, function(node) {
  16248. return node.tagName == "TABLE";
  16249. }),
  16250. end = range.collapsed
  16251. ? start
  16252. : findList(range.endContainer, function(node) {
  16253. return node.tagName == "TABLE";
  16254. });
  16255. if (start && end && start === end) {
  16256. if (!range.collapsed) {
  16257. start = domUtils.findParentByTagName(
  16258. range.startContainer,
  16259. "li",
  16260. true
  16261. );
  16262. end = domUtils.findParentByTagName(range.endContainer, "li", true);
  16263. if (start && end && start === end) {
  16264. range.deleteContents();
  16265. li = domUtils.findParentByTagName(range.startContainer, "li", true);
  16266. if (li && domUtils.isEmptyBlock(li)) {
  16267. pre = li.previousSibling;
  16268. next = li.nextSibling;
  16269. p = me.document.createElement("p");
  16270. domUtils.fillNode(me.document, p);
  16271. parentList = li.parentNode;
  16272. if (pre && next) {
  16273. range.setStart(next, 0).collapse(true).select(true);
  16274. domUtils.remove(li);
  16275. } else {
  16276. if ((!pre && !next) || !pre) {
  16277. parentList.parentNode.insertBefore(p, parentList);
  16278. } else {
  16279. li.parentNode.parentNode.insertBefore(
  16280. p,
  16281. parentList.nextSibling
  16282. );
  16283. }
  16284. domUtils.remove(li);
  16285. if (!parentList.firstChild) {
  16286. domUtils.remove(parentList);
  16287. }
  16288. range.setStart(p, 0).setCursor();
  16289. }
  16290. preventAndSave();
  16291. return;
  16292. }
  16293. } else {
  16294. var tmpRange = range.cloneRange(),
  16295. bk = tmpRange.collapse(false).createBookmark();
  16296. range.deleteContents();
  16297. tmpRange.moveToBookmark(bk);
  16298. var li = domUtils.findParentByTagName(
  16299. tmpRange.startContainer,
  16300. "li",
  16301. true
  16302. );
  16303. clearEmptySibling(li);
  16304. tmpRange.select();
  16305. preventAndSave();
  16306. return;
  16307. }
  16308. }
  16309. li = domUtils.findParentByTagName(range.startContainer, "li", true);
  16310. if (li) {
  16311. if (domUtils.isEmptyBlock(li)) {
  16312. bk = range.createBookmark();
  16313. var parentList = li.parentNode;
  16314. if (li !== parentList.lastChild) {
  16315. domUtils.breakParent(li, parentList);
  16316. clearEmptySibling(li);
  16317. } else {
  16318. parentList.parentNode.insertBefore(li, parentList.nextSibling);
  16319. if (domUtils.isEmptyNode(parentList)) {
  16320. domUtils.remove(parentList);
  16321. }
  16322. }
  16323. //嵌套不处理
  16324. if (!dtd.$list[li.parentNode.tagName]) {
  16325. if (!domUtils.isBlockElm(li.firstChild)) {
  16326. p = me.document.createElement("p");
  16327. li.parentNode.insertBefore(p, li);
  16328. while (li.firstChild) {
  16329. p.appendChild(li.firstChild);
  16330. }
  16331. domUtils.remove(li);
  16332. } else {
  16333. domUtils.remove(li, true);
  16334. }
  16335. }
  16336. range.moveToBookmark(bk).select();
  16337. } else {
  16338. var first = li.firstChild;
  16339. if (!first || !domUtils.isBlockElm(first)) {
  16340. var p = me.document.createElement("p");
  16341. !li.firstChild && domUtils.fillNode(me.document, p);
  16342. while (li.firstChild) {
  16343. p.appendChild(li.firstChild);
  16344. }
  16345. li.appendChild(p);
  16346. first = p;
  16347. }
  16348. var span = me.document.createElement("span");
  16349. range.insertNode(span);
  16350. domUtils.breakParent(span, li);
  16351. var nextLi = span.nextSibling;
  16352. first = nextLi.firstChild;
  16353. if (!first) {
  16354. p = me.document.createElement("p");
  16355. domUtils.fillNode(me.document, p);
  16356. nextLi.appendChild(p);
  16357. first = p;
  16358. }
  16359. if (domUtils.isEmptyNode(first)) {
  16360. first.innerHTML = "";
  16361. domUtils.fillNode(me.document, first);
  16362. }
  16363. range.setStart(first, 0).collapse(true).shrinkBoundary().select();
  16364. domUtils.remove(span);
  16365. var pre = nextLi.previousSibling;
  16366. if (pre && domUtils.isEmptyBlock(pre)) {
  16367. pre.innerHTML = "<p></p>";
  16368. domUtils.fillNode(me.document, pre.firstChild);
  16369. }
  16370. }
  16371. // }
  16372. preventAndSave();
  16373. }
  16374. }
  16375. }
  16376. if (keyCode == 8) {
  16377. //修中ie中li下的问题
  16378. range = me.selection.getRange();
  16379. if (range.collapsed && domUtils.isStartInblock(range)) {
  16380. tmpRange = range.cloneRange().trimBoundary();
  16381. li = domUtils.findParentByTagName(range.startContainer, "li", true);
  16382. //要在li的最左边,才能处理
  16383. if (li && domUtils.isStartInblock(tmpRange)) {
  16384. start = domUtils.findParentByTagName(range.startContainer, "p", true);
  16385. if (start && start !== li.firstChild) {
  16386. var parentList = domUtils.findParentByTagName(start, ["ol", "ul"]);
  16387. domUtils.breakParent(start, parentList);
  16388. clearEmptySibling(start);
  16389. me.fireEvent("contentchange");
  16390. range.setStart(start, 0).setCursor(false, true);
  16391. me.fireEvent("saveScene");
  16392. domUtils.preventDefault(evt);
  16393. return;
  16394. }
  16395. if (li && (pre = li.previousSibling)) {
  16396. if (keyCode == 46 && li.childNodes.length) {
  16397. return;
  16398. }
  16399. //有可能上边的兄弟节点是个2级菜单,要追加到2级菜单的最后的li
  16400. if (dtd.$list[pre.tagName]) {
  16401. pre = pre.lastChild;
  16402. }
  16403. me.undoManger && me.undoManger.save();
  16404. first = li.firstChild;
  16405. if (domUtils.isBlockElm(first)) {
  16406. if (domUtils.isEmptyNode(first)) {
  16407. // range.setEnd(pre, pre.childNodes.length).shrinkBoundary().collapse().select(true);
  16408. pre.appendChild(first);
  16409. range.setStart(first, 0).setCursor(false, true);
  16410. //first不是唯一的节点
  16411. while (li.firstChild) {
  16412. pre.appendChild(li.firstChild);
  16413. }
  16414. } else {
  16415. span = me.document.createElement("span");
  16416. range.insertNode(span);
  16417. //判断pre是否是空的节点,如果是<p><br/></p>类型的空节点,干掉p标签防止它占位
  16418. if (domUtils.isEmptyBlock(pre)) {
  16419. pre.innerHTML = "";
  16420. }
  16421. domUtils.moveChild(li, pre);
  16422. range.setStartBefore(span).collapse(true).select(true);
  16423. domUtils.remove(span);
  16424. }
  16425. } else {
  16426. if (domUtils.isEmptyNode(li)) {
  16427. var p = me.document.createElement("p");
  16428. pre.appendChild(p);
  16429. range.setStart(p, 0).setCursor();
  16430. // range.setEnd(pre, pre.childNodes.length).shrinkBoundary().collapse().select(true);
  16431. } else {
  16432. range
  16433. .setEnd(pre, pre.childNodes.length)
  16434. .collapse()
  16435. .select(true);
  16436. while (li.firstChild) {
  16437. pre.appendChild(li.firstChild);
  16438. }
  16439. }
  16440. }
  16441. domUtils.remove(li);
  16442. me.fireEvent("contentchange");
  16443. me.fireEvent("saveScene");
  16444. domUtils.preventDefault(evt);
  16445. return;
  16446. }
  16447. //trace:980
  16448. if (li && !li.previousSibling) {
  16449. var parentList = li.parentNode;
  16450. var bk = range.createBookmark();
  16451. if (domUtils.isTagNode(parentList.parentNode, "ol ul")) {
  16452. parentList.parentNode.insertBefore(li, parentList);
  16453. if (domUtils.isEmptyNode(parentList)) {
  16454. domUtils.remove(parentList);
  16455. }
  16456. } else {
  16457. while (li.firstChild) {
  16458. parentList.parentNode.insertBefore(li.firstChild, parentList);
  16459. }
  16460. domUtils.remove(li);
  16461. if (domUtils.isEmptyNode(parentList)) {
  16462. domUtils.remove(parentList);
  16463. }
  16464. }
  16465. range.moveToBookmark(bk).setCursor(false, true);
  16466. me.fireEvent("contentchange");
  16467. me.fireEvent("saveScene");
  16468. domUtils.preventDefault(evt);
  16469. return;
  16470. }
  16471. }
  16472. }
  16473. }
  16474. });
  16475. me.addListener("keyup", function(type, evt) {
  16476. var keyCode = evt.keyCode || evt.which;
  16477. if (keyCode == 8) {
  16478. var rng = me.selection.getRange(),
  16479. list;
  16480. if (
  16481. (list = domUtils.findParentByTagName(
  16482. rng.startContainer,
  16483. ["ol", "ul"],
  16484. true
  16485. ))
  16486. ) {
  16487. adjustList(
  16488. list,
  16489. list.tagName.toLowerCase(),
  16490. getStyle(list) || domUtils.getComputedStyle(list, "list-style-type"),
  16491. true
  16492. );
  16493. }
  16494. }
  16495. });
  16496. //处理tab键
  16497. me.addListener("tabkeydown", function() {
  16498. var range = me.selection.getRange();
  16499. //控制级数
  16500. function checkLevel(li) {
  16501. if (me.options.maxListLevel != -1) {
  16502. var level = li.parentNode,
  16503. levelNum = 0;
  16504. while (/[ou]l/i.test(level.tagName)) {
  16505. levelNum++;
  16506. level = level.parentNode;
  16507. }
  16508. if (levelNum >= me.options.maxListLevel) {
  16509. return true;
  16510. }
  16511. }
  16512. }
  16513. //只以开始为准
  16514. //todo 后续改进
  16515. var li = domUtils.findParentByTagName(range.startContainer, "li", true);
  16516. if (li) {
  16517. var bk;
  16518. if (range.collapsed) {
  16519. if (checkLevel(li)) return true;
  16520. var parentLi = li.parentNode,
  16521. list = me.document.createElement(parentLi.tagName),
  16522. index = utils.indexOf(
  16523. listStyle[list.tagName],
  16524. getStyle(parentLi) ||
  16525. domUtils.getComputedStyle(parentLi, "list-style-type")
  16526. );
  16527. index = index + 1 == listStyle[list.tagName].length ? 0 : index + 1;
  16528. var currentStyle = listStyle[list.tagName][index];
  16529. setListStyle(list, currentStyle);
  16530. if (domUtils.isStartInblock(range)) {
  16531. me.fireEvent("saveScene");
  16532. bk = range.createBookmark();
  16533. parentLi.insertBefore(list, li);
  16534. list.appendChild(li);
  16535. adjustList(list, list.tagName.toLowerCase(), currentStyle);
  16536. me.fireEvent("contentchange");
  16537. range.moveToBookmark(bk).select(true);
  16538. return true;
  16539. }
  16540. } else {
  16541. me.fireEvent("saveScene");
  16542. bk = range.createBookmark();
  16543. for (
  16544. var i = 0, closeList, parents = domUtils.findParents(li), ci;
  16545. (ci = parents[i++]);
  16546. ) {
  16547. if (domUtils.isTagNode(ci, "ol ul")) {
  16548. closeList = ci;
  16549. break;
  16550. }
  16551. }
  16552. var current = li;
  16553. if (bk.end) {
  16554. while (
  16555. current &&
  16556. !(
  16557. domUtils.getPosition(current, bk.end) &
  16558. domUtils.POSITION_FOLLOWING
  16559. )
  16560. ) {
  16561. if (checkLevel(current)) {
  16562. current = domUtils.getNextDomNode(current, false, null, function(
  16563. node
  16564. ) {
  16565. return node !== closeList;
  16566. });
  16567. continue;
  16568. }
  16569. var parentLi = current.parentNode,
  16570. list = me.document.createElement(parentLi.tagName),
  16571. index = utils.indexOf(
  16572. listStyle[list.tagName],
  16573. getStyle(parentLi) ||
  16574. domUtils.getComputedStyle(parentLi, "list-style-type")
  16575. );
  16576. var currentIndex = index + 1 == listStyle[list.tagName].length
  16577. ? 0
  16578. : index + 1;
  16579. var currentStyle = listStyle[list.tagName][currentIndex];
  16580. setListStyle(list, currentStyle);
  16581. parentLi.insertBefore(list, current);
  16582. while (
  16583. current &&
  16584. !(
  16585. domUtils.getPosition(current, bk.end) &
  16586. domUtils.POSITION_FOLLOWING
  16587. )
  16588. ) {
  16589. li = current.nextSibling;
  16590. list.appendChild(current);
  16591. if (!li || domUtils.isTagNode(li, "ol ul")) {
  16592. if (li) {
  16593. while ((li = li.firstChild)) {
  16594. if (li.tagName == "LI") {
  16595. break;
  16596. }
  16597. }
  16598. } else {
  16599. li = domUtils.getNextDomNode(current, false, null, function(
  16600. node
  16601. ) {
  16602. return node !== closeList;
  16603. });
  16604. }
  16605. break;
  16606. }
  16607. current = li;
  16608. }
  16609. adjustList(list, list.tagName.toLowerCase(), currentStyle);
  16610. current = li;
  16611. }
  16612. }
  16613. me.fireEvent("contentchange");
  16614. range.moveToBookmark(bk).select();
  16615. return true;
  16616. }
  16617. }
  16618. });
  16619. function getLi(start) {
  16620. while (start && !domUtils.isBody(start)) {
  16621. if (start.nodeName == "TABLE") {
  16622. return null;
  16623. }
  16624. if (start.nodeName == "LI") {
  16625. return start;
  16626. }
  16627. start = start.parentNode;
  16628. }
  16629. }
  16630. /**
  16631. * 有序列表,与“insertunorderedlist”命令互斥
  16632. * @command insertorderedlist
  16633. * @method execCommand
  16634. * @param { String } command 命令字符串
  16635. * @param { String } style 插入的有序列表类型,值为:decimal,lower-alpha,lower-roman,upper-alpha,upper-roman,cn,cn1,cn2,num,num1,num2
  16636. * @example
  16637. * ```javascript
  16638. * editor.execCommand( 'insertorderedlist','decimal');
  16639. * ```
  16640. */
  16641. /**
  16642. * 查询当前选区内容是否有序列表
  16643. * @command insertorderedlist
  16644. * @method queryCommandState
  16645. * @param { String } cmd 命令字符串
  16646. * @return { int } 如果当前选区是有序列表返回1,否则返回0
  16647. * @example
  16648. * ```javascript
  16649. * editor.queryCommandState( 'insertorderedlist' );
  16650. * ```
  16651. */
  16652. /**
  16653. * 查询当前选区内容是否有序列表
  16654. * @command insertorderedlist
  16655. * @method queryCommandValue
  16656. * @param { String } cmd 命令字符串
  16657. * @return { String } 返回当前有序列表的类型,值为null或decimal,lower-alpha,lower-roman,upper-alpha,upper-roman,cn,cn1,cn2,num,num1,num2
  16658. * @example
  16659. * ```javascript
  16660. * editor.queryCommandValue( 'insertorderedlist' );
  16661. * ```
  16662. */
  16663. /**
  16664. * 无序列表,与“insertorderedlist”命令互斥
  16665. * @command insertunorderedlist
  16666. * @method execCommand
  16667. * @param { String } command 命令字符串
  16668. * @param { String } style 插入的无序列表类型,值为:circle,disc,square,dash,dot
  16669. * @example
  16670. * ```javascript
  16671. * editor.execCommand( 'insertunorderedlist','circle');
  16672. * ```
  16673. */
  16674. /**
  16675. * 查询当前是否有word文档粘贴进来的图片
  16676. * @command insertunorderedlist
  16677. * @method insertunorderedlist
  16678. * @param { String } command 命令字符串
  16679. * @return { int } 如果当前选区是无序列表返回1,否则返回0
  16680. * @example
  16681. * ```javascript
  16682. * editor.queryCommandState( 'insertunorderedlist' );
  16683. * ```
  16684. */
  16685. /**
  16686. * 查询当前选区内容是否有序列表
  16687. * @command insertunorderedlist
  16688. * @method queryCommandValue
  16689. * @param { String } command 命令字符串
  16690. * @return { String } 返回当前无序列表的类型,值为null或circle,disc,square,dash,dot
  16691. * @example
  16692. * ```javascript
  16693. * editor.queryCommandValue( 'insertunorderedlist' );
  16694. * ```
  16695. */
  16696. me.commands["insertorderedlist"] = me.commands["insertunorderedlist"] = {
  16697. execCommand: function(command, style) {
  16698. if (!style) {
  16699. style = command.toLowerCase() == "insertorderedlist"
  16700. ? "decimal"
  16701. : "disc";
  16702. }
  16703. var me = this,
  16704. range = this.selection.getRange(),
  16705. filterFn = function(node) {
  16706. return node.nodeType == 1
  16707. ? node.tagName.toLowerCase() != "br"
  16708. : !domUtils.isWhitespace(node);
  16709. },
  16710. tag = command.toLowerCase() == "insertorderedlist" ? "ol" : "ul",
  16711. frag = me.document.createDocumentFragment();
  16712. //去掉是因为会出现选到末尾,导致adjustmentBoundary缩到ol/ul的位置
  16713. //range.shrinkBoundary();//.adjustmentBoundary();
  16714. range.adjustmentBoundary().shrinkBoundary();
  16715. var bko = range.createBookmark(true),
  16716. start = getLi(me.document.getElementById(bko.start)),
  16717. modifyStart = 0,
  16718. end = getLi(me.document.getElementById(bko.end)),
  16719. modifyEnd = 0,
  16720. startParent,
  16721. endParent,
  16722. list,
  16723. tmp;
  16724. if (start || end) {
  16725. start && (startParent = start.parentNode);
  16726. if (!bko.end) {
  16727. end = start;
  16728. }
  16729. end && (endParent = end.parentNode);
  16730. if (startParent === endParent) {
  16731. while (start !== end) {
  16732. tmp = start;
  16733. start = start.nextSibling;
  16734. if (!domUtils.isBlockElm(tmp.firstChild)) {
  16735. var p = me.document.createElement("p");
  16736. while (tmp.firstChild) {
  16737. p.appendChild(tmp.firstChild);
  16738. }
  16739. tmp.appendChild(p);
  16740. }
  16741. frag.appendChild(tmp);
  16742. }
  16743. tmp = me.document.createElement("span");
  16744. startParent.insertBefore(tmp, end);
  16745. if (!domUtils.isBlockElm(end.firstChild)) {
  16746. p = me.document.createElement("p");
  16747. while (end.firstChild) {
  16748. p.appendChild(end.firstChild);
  16749. }
  16750. end.appendChild(p);
  16751. }
  16752. frag.appendChild(end);
  16753. domUtils.breakParent(tmp, startParent);
  16754. if (domUtils.isEmptyNode(tmp.previousSibling)) {
  16755. domUtils.remove(tmp.previousSibling);
  16756. }
  16757. if (domUtils.isEmptyNode(tmp.nextSibling)) {
  16758. domUtils.remove(tmp.nextSibling);
  16759. }
  16760. var nodeStyle =
  16761. getStyle(startParent) ||
  16762. domUtils.getComputedStyle(startParent, "list-style-type") ||
  16763. (command.toLowerCase() == "insertorderedlist" ? "decimal" : "disc");
  16764. if (startParent.tagName.toLowerCase() == tag && nodeStyle == style) {
  16765. for (
  16766. var i = 0, ci, tmpFrag = me.document.createDocumentFragment();
  16767. (ci = frag.firstChild);
  16768. ) {
  16769. if (domUtils.isTagNode(ci, "ol ul")) {
  16770. // 删除时,子列表不处理
  16771. // utils.each(domUtils.getElementsByTagName(ci,'li'),function(li){
  16772. // while(li.firstChild){
  16773. // tmpFrag.appendChild(li.firstChild);
  16774. // }
  16775. //
  16776. // });
  16777. tmpFrag.appendChild(ci);
  16778. } else {
  16779. while (ci.firstChild) {
  16780. tmpFrag.appendChild(ci.firstChild);
  16781. domUtils.remove(ci);
  16782. }
  16783. }
  16784. }
  16785. tmp.parentNode.insertBefore(tmpFrag, tmp);
  16786. } else {
  16787. list = me.document.createElement(tag);
  16788. setListStyle(list, style);
  16789. list.appendChild(frag);
  16790. tmp.parentNode.insertBefore(list, tmp);
  16791. }
  16792. domUtils.remove(tmp);
  16793. list && adjustList(list, tag, style);
  16794. range.moveToBookmark(bko).select();
  16795. return;
  16796. }
  16797. //开始
  16798. if (start) {
  16799. while (start) {
  16800. tmp = start.nextSibling;
  16801. if (domUtils.isTagNode(start, "ol ul")) {
  16802. frag.appendChild(start);
  16803. } else {
  16804. var tmpfrag = me.document.createDocumentFragment(),
  16805. hasBlock = 0;
  16806. while (start.firstChild) {
  16807. if (domUtils.isBlockElm(start.firstChild)) {
  16808. hasBlock = 1;
  16809. }
  16810. tmpfrag.appendChild(start.firstChild);
  16811. }
  16812. if (!hasBlock) {
  16813. var tmpP = me.document.createElement("p");
  16814. tmpP.appendChild(tmpfrag);
  16815. frag.appendChild(tmpP);
  16816. } else {
  16817. frag.appendChild(tmpfrag);
  16818. }
  16819. domUtils.remove(start);
  16820. }
  16821. start = tmp;
  16822. }
  16823. startParent.parentNode.insertBefore(frag, startParent.nextSibling);
  16824. if (domUtils.isEmptyNode(startParent)) {
  16825. range.setStartBefore(startParent);
  16826. domUtils.remove(startParent);
  16827. } else {
  16828. range.setStartAfter(startParent);
  16829. }
  16830. modifyStart = 1;
  16831. }
  16832. if (end && domUtils.inDoc(endParent, me.document)) {
  16833. //结束
  16834. start = endParent.firstChild;
  16835. while (start && start !== end) {
  16836. tmp = start.nextSibling;
  16837. if (domUtils.isTagNode(start, "ol ul")) {
  16838. frag.appendChild(start);
  16839. } else {
  16840. tmpfrag = me.document.createDocumentFragment();
  16841. hasBlock = 0;
  16842. while (start.firstChild) {
  16843. if (domUtils.isBlockElm(start.firstChild)) {
  16844. hasBlock = 1;
  16845. }
  16846. tmpfrag.appendChild(start.firstChild);
  16847. }
  16848. if (!hasBlock) {
  16849. tmpP = me.document.createElement("p");
  16850. tmpP.appendChild(tmpfrag);
  16851. frag.appendChild(tmpP);
  16852. } else {
  16853. frag.appendChild(tmpfrag);
  16854. }
  16855. domUtils.remove(start);
  16856. }
  16857. start = tmp;
  16858. }
  16859. var tmpDiv = domUtils.createElement(me.document, "div", {
  16860. tmpDiv: 1
  16861. });
  16862. domUtils.moveChild(end, tmpDiv);
  16863. frag.appendChild(tmpDiv);
  16864. domUtils.remove(end);
  16865. endParent.parentNode.insertBefore(frag, endParent);
  16866. range.setEndBefore(endParent);
  16867. if (domUtils.isEmptyNode(endParent)) {
  16868. domUtils.remove(endParent);
  16869. }
  16870. modifyEnd = 1;
  16871. }
  16872. }
  16873. if (!modifyStart) {
  16874. range.setStartBefore(me.document.getElementById(bko.start));
  16875. }
  16876. if (bko.end && !modifyEnd) {
  16877. range.setEndAfter(me.document.getElementById(bko.end));
  16878. }
  16879. range.enlarge(true, function(node) {
  16880. return notExchange[node.tagName];
  16881. });
  16882. frag = me.document.createDocumentFragment();
  16883. var bk = range.createBookmark(),
  16884. current = domUtils.getNextDomNode(bk.start, false, filterFn),
  16885. tmpRange = range.cloneRange(),
  16886. tmpNode,
  16887. block = domUtils.isBlockElm;
  16888. while (
  16889. current &&
  16890. current !== bk.end &&
  16891. domUtils.getPosition(current, bk.end) & domUtils.POSITION_PRECEDING
  16892. ) {
  16893. if (current.nodeType == 3 || dtd.li[current.tagName]) {
  16894. if (current.nodeType == 1 && dtd.$list[current.tagName]) {
  16895. while (current.firstChild) {
  16896. frag.appendChild(current.firstChild);
  16897. }
  16898. tmpNode = domUtils.getNextDomNode(current, false, filterFn);
  16899. domUtils.remove(current);
  16900. current = tmpNode;
  16901. continue;
  16902. }
  16903. tmpNode = current;
  16904. tmpRange.setStartBefore(current);
  16905. while (
  16906. current &&
  16907. current !== bk.end &&
  16908. (!block(current) || domUtils.isBookmarkNode(current))
  16909. ) {
  16910. tmpNode = current;
  16911. current = domUtils.getNextDomNode(current, false, null, function(
  16912. node
  16913. ) {
  16914. return !notExchange[node.tagName];
  16915. });
  16916. }
  16917. if (current && block(current)) {
  16918. tmp = domUtils.getNextDomNode(tmpNode, false, filterFn);
  16919. if (tmp && domUtils.isBookmarkNode(tmp)) {
  16920. current = domUtils.getNextDomNode(tmp, false, filterFn);
  16921. tmpNode = tmp;
  16922. }
  16923. }
  16924. tmpRange.setEndAfter(tmpNode);
  16925. current = domUtils.getNextDomNode(tmpNode, false, filterFn);
  16926. var li = range.document.createElement("li");
  16927. li.appendChild(tmpRange.extractContents());
  16928. if (domUtils.isEmptyNode(li)) {
  16929. var tmpNode = range.document.createElement("p");
  16930. while (li.firstChild) {
  16931. tmpNode.appendChild(li.firstChild);
  16932. }
  16933. li.appendChild(tmpNode);
  16934. }
  16935. frag.appendChild(li);
  16936. } else {
  16937. current = domUtils.getNextDomNode(current, true, filterFn);
  16938. }
  16939. }
  16940. range.moveToBookmark(bk).collapse(true);
  16941. list = me.document.createElement(tag);
  16942. setListStyle(list, style);
  16943. list.appendChild(frag);
  16944. range.insertNode(list);
  16945. //当前list上下看能否合并
  16946. adjustList(list, tag, style);
  16947. //去掉冗余的tmpDiv
  16948. for (
  16949. var i = 0, ci, tmpDivs = domUtils.getElementsByTagName(list, "div");
  16950. (ci = tmpDivs[i++]);
  16951. ) {
  16952. if (ci.getAttribute("tmpDiv")) {
  16953. domUtils.remove(ci, true);
  16954. }
  16955. }
  16956. range.moveToBookmark(bko).select();
  16957. },
  16958. queryCommandState: function(command) {
  16959. var tag = command.toLowerCase() == "insertorderedlist" ? "ol" : "ul";
  16960. var path = this.selection.getStartElementPath();
  16961. for (var i = 0, ci; (ci = path[i++]); ) {
  16962. if (ci.nodeName == "TABLE") {
  16963. return 0;
  16964. }
  16965. if (tag == ci.nodeName.toLowerCase()) {
  16966. return 1;
  16967. }
  16968. }
  16969. return 0;
  16970. },
  16971. queryCommandValue: function(command) {
  16972. var tag = command.toLowerCase() == "insertorderedlist" ? "ol" : "ul";
  16973. var path = this.selection.getStartElementPath(),
  16974. node;
  16975. for (var i = 0, ci; (ci = path[i++]); ) {
  16976. if (ci.nodeName == "TABLE") {
  16977. node = null;
  16978. break;
  16979. }
  16980. if (tag == ci.nodeName.toLowerCase()) {
  16981. node = ci;
  16982. break;
  16983. }
  16984. }
  16985. return node
  16986. ? getStyle(node) || domUtils.getComputedStyle(node, "list-style-type")
  16987. : null;
  16988. }
  16989. };
  16990. };
  16991. // plugins/source.js
  16992. /**
  16993. * 源码编辑插件
  16994. * @file
  16995. * @since 1.2.6.1
  16996. */
  16997. ;(function() {
  16998. var sourceEditors = {
  16999. textarea: function(editor, holder) {
  17000. var textarea = holder.ownerDocument.createElement("textarea");
  17001. textarea.style.cssText =
  17002. "position:absolute;resize:none;width:100%;height:100%;border:0;padding:0;margin:0;overflow-y:auto;";
  17003. // todo: IE下只有onresize属性可用... 很纠结
  17004. if (browser.ie && browser.version < 8) {
  17005. textarea.style.width = holder.offsetWidth + "px";
  17006. textarea.style.height = holder.offsetHeight + "px";
  17007. holder.onresize = function() {
  17008. textarea.style.width = holder.offsetWidth + "px";
  17009. textarea.style.height = holder.offsetHeight + "px";
  17010. };
  17011. }
  17012. holder.appendChild(textarea);
  17013. return {
  17014. setContent: function(content) {
  17015. textarea.value = content;
  17016. },
  17017. getContent: function() {
  17018. return textarea.value;
  17019. },
  17020. select: function() {
  17021. var range;
  17022. if (browser.ie) {
  17023. range = textarea.createTextRange();
  17024. range.collapse(true);
  17025. range.select();
  17026. } else {
  17027. //todo: chrome下无法设置焦点
  17028. textarea.setSelectionRange(0, 0);
  17029. textarea.focus();
  17030. }
  17031. },
  17032. dispose: function() {
  17033. holder.removeChild(textarea);
  17034. // todo
  17035. holder.onresize = null;
  17036. textarea = null;
  17037. holder = null;
  17038. },
  17039. focus: function (){
  17040. textarea.focus();
  17041. },
  17042. blur: function (){
  17043. textarea.blur();
  17044. }
  17045. };
  17046. },
  17047. codemirror: function(editor, holder) {
  17048. var codeEditor = window.CodeMirror(holder, {
  17049. mode: "text/html",
  17050. tabMode: "indent",
  17051. lineNumbers: true,
  17052. lineWrapping: true
  17053. });
  17054. var dom = codeEditor.getWrapperElement();
  17055. dom.style.cssText =
  17056. 'position:absolute;left:0;top:0;width:100%;height:100%;font-family:consolas,"Courier new",monospace;font-size:13px;';
  17057. codeEditor.getScrollerElement().style.cssText =
  17058. "position:absolute;left:0;top:0;width:100%;height:100%;";
  17059. codeEditor.refresh();
  17060. return {
  17061. getCodeMirror: function() {
  17062. return codeEditor;
  17063. },
  17064. setContent: function(content) {
  17065. codeEditor.setValue(content);
  17066. },
  17067. getContent: function() {
  17068. return codeEditor.getValue();
  17069. },
  17070. select: function() {
  17071. codeEditor.focus();
  17072. },
  17073. dispose: function() {
  17074. holder.removeChild(dom);
  17075. dom = null;
  17076. codeEditor = null;
  17077. },
  17078. focus: function (){
  17079. codeEditor.focus();
  17080. },
  17081. blur: function (){
  17082. // codeEditor.blur();
  17083. // since codemirror not support blur()
  17084. codeEditor.setOption('readOnly', true);
  17085. codeEditor.setOption('readOnly', false);
  17086. }
  17087. };
  17088. }
  17089. };
  17090. UE.plugins["source"] = function() {
  17091. var me = this;
  17092. var opt = this.options;
  17093. var sourceMode = false;
  17094. var sourceEditor;
  17095. var orgSetContent;
  17096. var orgFocus;
  17097. var orgBlur;
  17098. opt.sourceEditor = browser.ie
  17099. ? "textarea"
  17100. : opt.sourceEditor || "codemirror";
  17101. me.setOpt({
  17102. sourceEditorFirst: false
  17103. });
  17104. function createSourceEditor(holder) {
  17105. return sourceEditors[
  17106. opt.sourceEditor == "codemirror" && window.CodeMirror
  17107. ? "codemirror"
  17108. : "textarea"
  17109. ](me, holder);
  17110. }
  17111. var bakCssText;
  17112. //解决在源码模式下getContent不能得到最新的内容问题
  17113. var oldGetContent, bakAddress;
  17114. /**
  17115. * 切换源码模式和编辑模式
  17116. * @command source
  17117. * @method execCommand
  17118. * @param { String } cmd 命令字符串
  17119. * @example
  17120. * ```javascript
  17121. * editor.execCommand( 'source');
  17122. * ```
  17123. */
  17124. /**
  17125. * 查询当前编辑区域的状态是源码模式还是可视化模式
  17126. * @command source
  17127. * @method queryCommandState
  17128. * @param { String } cmd 命令字符串
  17129. * @return { int } 如果当前是源码编辑模式,返回1,否则返回0
  17130. * @example
  17131. * ```javascript
  17132. * editor.queryCommandState( 'source' );
  17133. * ```
  17134. */
  17135. me.commands["source"] = {
  17136. execCommand: function() {
  17137. sourceMode = !sourceMode;
  17138. if (sourceMode) {
  17139. bakAddress = me.selection.getRange().createAddress(false, true);
  17140. me.undoManger && me.undoManger.save(true);
  17141. if (browser.gecko) {
  17142. me.body.contentEditable = false;
  17143. }
  17144. bakCssText = me.iframe.style.cssText;
  17145. me.iframe.style.cssText +=
  17146. "position:absolute;left:-32768px;top:-32768px;";
  17147. me.fireEvent("beforegetcontent");
  17148. var root = UE.htmlparser(me.body.innerHTML);
  17149. me.filterOutputRule(root);
  17150. root.traversal(function(node) {
  17151. if (node.type == "element") {
  17152. switch (node.tagName) {
  17153. case "td":
  17154. case "th":
  17155. case "caption":
  17156. if (node.children && node.children.length == 1) {
  17157. if (node.firstChild().tagName == "br") {
  17158. node.removeChild(node.firstChild());
  17159. }
  17160. }
  17161. break;
  17162. case "pre":
  17163. node.innerText(node.innerText().replace(/&nbsp;/g, " "));
  17164. }
  17165. }
  17166. });
  17167. me.fireEvent("aftergetcontent");
  17168. var content = root.toHtml(true);
  17169. sourceEditor = createSourceEditor(me.iframe.parentNode);
  17170. sourceEditor.setContent(content);
  17171. orgSetContent = me.setContent;
  17172. me.setContent = function(html) {
  17173. //这里暂时不触发事件,防止报错
  17174. var root = UE.htmlparser(html);
  17175. me.filterInputRule(root);
  17176. html = root.toHtml();
  17177. sourceEditor.setContent(html);
  17178. };
  17179. setTimeout(function() {
  17180. sourceEditor.select();
  17181. me.addListener("fullscreenchanged", function() {
  17182. try {
  17183. sourceEditor.getCodeMirror().refresh();
  17184. } catch (e) {}
  17185. });
  17186. });
  17187. //重置getContent,源码模式下取值也能是最新的数据
  17188. oldGetContent = me.getContent;
  17189. me.getContent = function() {
  17190. return (
  17191. sourceEditor.getContent() ||
  17192. "<p>" + (browser.ie ? "" : "<br/>") + "</p>"
  17193. );
  17194. };
  17195. orgFocus = me.focus;
  17196. orgBlur = me.blur;
  17197. me.focus = function(){
  17198. sourceEditor.focus();
  17199. };
  17200. me.blur = function(){
  17201. orgBlur.call(me);
  17202. sourceEditor.blur();
  17203. };
  17204. } else {
  17205. me.iframe.style.cssText = bakCssText;
  17206. var cont =
  17207. sourceEditor.getContent() ||
  17208. "<p>" + (browser.ie ? "" : "<br/>") + "</p>";
  17209. //处理掉block节点前后的空格,有可能会误命中,暂时不考虑
  17210. cont = cont.replace(
  17211. new RegExp("[\\r\\t\\n ]*</?(\\w+)\\s*(?:[^>]*)>", "g"),
  17212. function(a, b) {
  17213. if (b && !dtd.$inlineWithA[b.toLowerCase()]) {
  17214. return a.replace(/(^[\n\r\t ]*)|([\n\r\t ]*$)/g, "");
  17215. }
  17216. return a.replace(/(^[\n\r\t]*)|([\n\r\t]*$)/g, "");
  17217. }
  17218. );
  17219. me.setContent = orgSetContent;
  17220. me.setContent(cont);
  17221. sourceEditor.dispose();
  17222. sourceEditor = null;
  17223. //还原getContent方法
  17224. me.getContent = oldGetContent;
  17225. me.focus = orgFocus;
  17226. me.blur = orgBlur;
  17227. var first = me.body.firstChild;
  17228. //trace:1106 都删除空了,下边会报错,所以补充一个p占位
  17229. if (!first) {
  17230. me.body.innerHTML = "<p>" + (browser.ie ? "" : "<br/>") + "</p>";
  17231. first = me.body.firstChild;
  17232. }
  17233. //要在ifm为显示时ff才能取到selection,否则报错
  17234. //这里不能比较位置了
  17235. me.undoManger && me.undoManger.save(true);
  17236. if (browser.gecko) {
  17237. var input = document.createElement("input");
  17238. input.style.cssText = "position:absolute;left:0;top:-32768px";
  17239. document.body.appendChild(input);
  17240. me.body.contentEditable = false;
  17241. setTimeout(function() {
  17242. domUtils.setViewportOffset(input, { left: -32768, top: 0 });
  17243. input.focus();
  17244. setTimeout(function() {
  17245. me.body.contentEditable = true;
  17246. me.selection.getRange().moveToAddress(bakAddress).select(true);
  17247. domUtils.remove(input);
  17248. });
  17249. });
  17250. } else {
  17251. //ie下有可能报错,比如在代码顶头的情况
  17252. try {
  17253. me.selection.getRange().moveToAddress(bakAddress).select(true);
  17254. } catch (e) {}
  17255. }
  17256. }
  17257. this.fireEvent("sourcemodechanged", sourceMode);
  17258. },
  17259. queryCommandState: function() {
  17260. return sourceMode | 0;
  17261. },
  17262. notNeedUndo: 1
  17263. };
  17264. var oldQueryCommandState = me.queryCommandState;
  17265. me.queryCommandState = function(cmdName) {
  17266. cmdName = cmdName.toLowerCase();
  17267. if (sourceMode) {
  17268. //源码模式下可以开启的命令
  17269. return cmdName in
  17270. {
  17271. source: 1,
  17272. fullscreen: 1
  17273. }
  17274. ? 1
  17275. : -1;
  17276. }
  17277. return oldQueryCommandState.apply(this, arguments);
  17278. };
  17279. if (opt.sourceEditor == "codemirror") {
  17280. me.addListener("ready", function() {
  17281. utils.loadFile(
  17282. document,
  17283. {
  17284. src:
  17285. opt.codeMirrorJsUrl ||
  17286. opt.UEDITOR_HOME_URL + "third-party/codemirror/codemirror.js",
  17287. tag: "script",
  17288. type: "text/javascript",
  17289. defer: "defer"
  17290. },
  17291. function() {
  17292. if (opt.sourceEditorFirst) {
  17293. setTimeout(function() {
  17294. me.execCommand("source");
  17295. }, 0);
  17296. }
  17297. }
  17298. );
  17299. utils.loadFile(document, {
  17300. tag: "link",
  17301. rel: "stylesheet",
  17302. type: "text/css",
  17303. href:
  17304. opt.codeMirrorCssUrl ||
  17305. opt.UEDITOR_HOME_URL + "third-party/codemirror/codemirror.css"
  17306. });
  17307. });
  17308. }
  17309. };
  17310. })();
  17311. // plugins/enterkey.js
  17312. ///import core
  17313. ///import plugins/undo.js
  17314. ///commands 设置回车标签p或br
  17315. ///commandsName EnterKey
  17316. ///commandsTitle 设置回车标签p或br
  17317. /**
  17318. * @description 处理回车
  17319. * @author zhanyi
  17320. */
  17321. UE.plugins["enterkey"] = function() {
  17322. var hTag,
  17323. me = this,
  17324. tag = me.options.enterTag;
  17325. me.addListener("keyup", function(type, evt) {
  17326. var keyCode = evt.keyCode || evt.which;
  17327. if (keyCode == 13) {
  17328. var range = me.selection.getRange(),
  17329. start = range.startContainer,
  17330. doSave;
  17331. //修正在h1-h6里边回车后不能嵌套p的问题
  17332. if (!browser.ie) {
  17333. if (/h\d/i.test(hTag)) {
  17334. if (browser.gecko) {
  17335. var h = domUtils.findParentByTagName(
  17336. start,
  17337. [
  17338. "h1",
  17339. "h2",
  17340. "h3",
  17341. "h4",
  17342. "h5",
  17343. "h6",
  17344. "blockquote",
  17345. "caption",
  17346. "table"
  17347. ],
  17348. true
  17349. );
  17350. if (!h) {
  17351. me.document.execCommand("formatBlock", false, "<p>");
  17352. doSave = 1;
  17353. }
  17354. } else {
  17355. //chrome remove div
  17356. if (start.nodeType == 1) {
  17357. var tmp = me.document.createTextNode(""),
  17358. div;
  17359. range.insertNode(tmp);
  17360. div = domUtils.findParentByTagName(tmp, "div", true);
  17361. if (div) {
  17362. var p = me.document.createElement("p");
  17363. while (div.firstChild) {
  17364. p.appendChild(div.firstChild);
  17365. }
  17366. div.parentNode.insertBefore(p, div);
  17367. domUtils.remove(div);
  17368. range.setStartBefore(tmp).setCursor();
  17369. doSave = 1;
  17370. }
  17371. domUtils.remove(tmp);
  17372. }
  17373. }
  17374. if (me.undoManger && doSave) {
  17375. me.undoManger.save();
  17376. }
  17377. }
  17378. //没有站位符,会出现多行的问题
  17379. browser.opera && range.select();
  17380. } else {
  17381. me.fireEvent("saveScene", true, true);
  17382. }
  17383. }
  17384. });
  17385. me.addListener("keydown", function(type, evt) {
  17386. var keyCode = evt.keyCode || evt.which;
  17387. if (keyCode == 13) {
  17388. //回车
  17389. if (me.fireEvent("beforeenterkeydown")) {
  17390. domUtils.preventDefault(evt);
  17391. return;
  17392. }
  17393. me.fireEvent("saveScene", true, true);
  17394. hTag = "";
  17395. var range = me.selection.getRange();
  17396. if (!range.collapsed) {
  17397. //跨td不能删
  17398. var start = range.startContainer,
  17399. end = range.endContainer,
  17400. startTd = domUtils.findParentByTagName(start, "td", true),
  17401. endTd = domUtils.findParentByTagName(end, "td", true);
  17402. if (
  17403. (startTd && endTd && startTd !== endTd) ||
  17404. (!startTd && endTd) ||
  17405. (startTd && !endTd)
  17406. ) {
  17407. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  17408. return;
  17409. }
  17410. }
  17411. if (tag == "p") {
  17412. if (!browser.ie) {
  17413. start = domUtils.findParentByTagName(
  17414. range.startContainer,
  17415. [
  17416. "ol",
  17417. "ul",
  17418. "p",
  17419. "h1",
  17420. "h2",
  17421. "h3",
  17422. "h4",
  17423. "h5",
  17424. "h6",
  17425. "blockquote",
  17426. "caption"
  17427. ],
  17428. true
  17429. );
  17430. //opera下执行formatblock会在table的场景下有问题,回车在opera原生支持很好,所以暂时在opera去掉调用这个原生的command
  17431. //trace:2431
  17432. if (!start && !browser.opera) {
  17433. me.document.execCommand("formatBlock", false, "<p>");
  17434. if (browser.gecko) {
  17435. range = me.selection.getRange();
  17436. start = domUtils.findParentByTagName(
  17437. range.startContainer,
  17438. "p",
  17439. true
  17440. );
  17441. start && domUtils.removeDirtyAttr(start);
  17442. }
  17443. } else {
  17444. hTag = start.tagName;
  17445. start.tagName.toLowerCase() == "p" &&
  17446. browser.gecko &&
  17447. domUtils.removeDirtyAttr(start);
  17448. }
  17449. }
  17450. } else {
  17451. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  17452. if (!range.collapsed) {
  17453. range.deleteContents();
  17454. start = range.startContainer;
  17455. if (
  17456. start.nodeType == 1 &&
  17457. (start = start.childNodes[range.startOffset])
  17458. ) {
  17459. while (start.nodeType == 1) {
  17460. if (dtd.$empty[start.tagName]) {
  17461. range.setStartBefore(start).setCursor();
  17462. if (me.undoManger) {
  17463. me.undoManger.save();
  17464. }
  17465. return false;
  17466. }
  17467. if (!start.firstChild) {
  17468. var br = range.document.createElement("br");
  17469. start.appendChild(br);
  17470. range.setStart(start, 0).setCursor();
  17471. if (me.undoManger) {
  17472. me.undoManger.save();
  17473. }
  17474. return false;
  17475. }
  17476. start = start.firstChild;
  17477. }
  17478. if (start === range.startContainer.childNodes[range.startOffset]) {
  17479. br = range.document.createElement("br");
  17480. range.insertNode(br).setCursor();
  17481. } else {
  17482. range.setStart(start, 0).setCursor();
  17483. }
  17484. } else {
  17485. br = range.document.createElement("br");
  17486. range.insertNode(br).setStartAfter(br).setCursor();
  17487. }
  17488. } else {
  17489. br = range.document.createElement("br");
  17490. range.insertNode(br);
  17491. var parent = br.parentNode;
  17492. if (parent.lastChild === br) {
  17493. br.parentNode.insertBefore(br.cloneNode(true), br);
  17494. range.setStartBefore(br);
  17495. } else {
  17496. range.setStartAfter(br);
  17497. }
  17498. range.setCursor();
  17499. }
  17500. }
  17501. }
  17502. });
  17503. };
  17504. // plugins/keystrokes.js
  17505. /* 处理特殊键的兼容性问题 */
  17506. UE.plugins["keystrokes"] = function() {
  17507. var me = this;
  17508. var collapsed = true;
  17509. me.addListener("keydown", function(type, evt) {
  17510. var keyCode = evt.keyCode || evt.which,
  17511. rng = me.selection.getRange();
  17512. //处理全选的情况
  17513. if (
  17514. !rng.collapsed &&
  17515. !(evt.ctrlKey || evt.shiftKey || evt.altKey || evt.metaKey) &&
  17516. ((keyCode >= 65 && keyCode <= 90) ||
  17517. (keyCode >= 48 && keyCode <= 57) ||
  17518. (keyCode >= 96 && keyCode <= 111) ||
  17519. {
  17520. 13: 1,
  17521. 8: 1,
  17522. 46: 1
  17523. }[keyCode])
  17524. ) {
  17525. var tmpNode = rng.startContainer;
  17526. if (domUtils.isFillChar(tmpNode)) {
  17527. rng.setStartBefore(tmpNode);
  17528. }
  17529. tmpNode = rng.endContainer;
  17530. if (domUtils.isFillChar(tmpNode)) {
  17531. rng.setEndAfter(tmpNode);
  17532. }
  17533. rng.txtToElmBoundary();
  17534. //结束边界可能放到了br的前边,要把br包含进来
  17535. // x[xxx]<br/>
  17536. if (rng.endContainer && rng.endContainer.nodeType == 1) {
  17537. tmpNode = rng.endContainer.childNodes[rng.endOffset];
  17538. if (tmpNode && domUtils.isBr(tmpNode)) {
  17539. rng.setEndAfter(tmpNode);
  17540. }
  17541. }
  17542. if (rng.startOffset == 0) {
  17543. tmpNode = rng.startContainer;
  17544. if (domUtils.isBoundaryNode(tmpNode, "firstChild")) {
  17545. tmpNode = rng.endContainer;
  17546. if (
  17547. rng.endOffset ==
  17548. (tmpNode.nodeType == 3
  17549. ? tmpNode.nodeValue.length
  17550. : tmpNode.childNodes.length) &&
  17551. domUtils.isBoundaryNode(tmpNode, "lastChild")
  17552. ) {
  17553. me.fireEvent("saveScene");
  17554. me.body.innerHTML = "<p>" + (browser.ie ? "" : "<br/>") + "</p>";
  17555. rng.setStart(me.body.firstChild, 0).setCursor(false, true);
  17556. me._selectionChange();
  17557. return;
  17558. }
  17559. }
  17560. }
  17561. }
  17562. //处理backspace
  17563. if (keyCode == keymap.Backspace) {
  17564. rng = me.selection.getRange();
  17565. collapsed = rng.collapsed;
  17566. if (me.fireEvent("delkeydown", evt)) {
  17567. return;
  17568. }
  17569. var start, end;
  17570. //避免按两次删除才能生效的问题
  17571. if (rng.collapsed && rng.inFillChar()) {
  17572. start = rng.startContainer;
  17573. if (domUtils.isFillChar(start)) {
  17574. rng.setStartBefore(start).shrinkBoundary(true).collapse(true);
  17575. domUtils.remove(start);
  17576. } else {
  17577. start.nodeValue = start.nodeValue.replace(
  17578. new RegExp("^" + domUtils.fillChar),
  17579. ""
  17580. );
  17581. rng.startOffset--;
  17582. rng.collapse(true).select(true);
  17583. }
  17584. }
  17585. //解决选中control元素不能删除的问题
  17586. if ((start = rng.getClosedNode())) {
  17587. me.fireEvent("saveScene");
  17588. rng.setStartBefore(start);
  17589. domUtils.remove(start);
  17590. rng.setCursor();
  17591. me.fireEvent("saveScene");
  17592. domUtils.preventDefault(evt);
  17593. return;
  17594. }
  17595. //阻止在table上的删除
  17596. if (!browser.ie) {
  17597. start = domUtils.findParentByTagName(rng.startContainer, "table", true);
  17598. end = domUtils.findParentByTagName(rng.endContainer, "table", true);
  17599. if ((start && !end) || (!start && end) || start !== end) {
  17600. evt.preventDefault();
  17601. return;
  17602. }
  17603. }
  17604. }
  17605. //处理tab键的逻辑
  17606. if (keyCode == keymap.Tab) {
  17607. //不处理以下标签
  17608. var excludeTagNameForTabKey = {
  17609. ol: 1,
  17610. ul: 1,
  17611. table: 1
  17612. };
  17613. //处理组件里的tab按下事件
  17614. if (me.fireEvent("tabkeydown", evt)) {
  17615. domUtils.preventDefault(evt);
  17616. return;
  17617. }
  17618. var range = me.selection.getRange();
  17619. me.fireEvent("saveScene");
  17620. for (
  17621. var i = 0,
  17622. txt = "",
  17623. tabSize = me.options.tabSize || 4,
  17624. tabNode = me.options.tabNode || "&nbsp;";
  17625. i < tabSize;
  17626. i++
  17627. ) {
  17628. txt += tabNode;
  17629. }
  17630. var span = me.document.createElement("span");
  17631. span.innerHTML = txt + domUtils.fillChar;
  17632. if (range.collapsed) {
  17633. range.insertNode(span.cloneNode(true).firstChild).setCursor(true);
  17634. } else {
  17635. var filterFn = function(node) {
  17636. return (
  17637. domUtils.isBlockElm(node) &&
  17638. !excludeTagNameForTabKey[node.tagName.toLowerCase()]
  17639. );
  17640. };
  17641. //普通的情况
  17642. start = domUtils.findParent(range.startContainer, filterFn, true);
  17643. end = domUtils.findParent(range.endContainer, filterFn, true);
  17644. if (start && end && start === end) {
  17645. range.deleteContents();
  17646. range.insertNode(span.cloneNode(true).firstChild).setCursor(true);
  17647. } else {
  17648. var bookmark = range.createBookmark();
  17649. range.enlarge(true);
  17650. var bookmark2 = range.createBookmark(),
  17651. current = domUtils.getNextDomNode(bookmark2.start, false, filterFn);
  17652. while (
  17653. current &&
  17654. !(
  17655. domUtils.getPosition(current, bookmark2.end) &
  17656. domUtils.POSITION_FOLLOWING
  17657. )
  17658. ) {
  17659. current.insertBefore(
  17660. span.cloneNode(true).firstChild,
  17661. current.firstChild
  17662. );
  17663. current = domUtils.getNextDomNode(current, false, filterFn);
  17664. }
  17665. range.moveToBookmark(bookmark2).moveToBookmark(bookmark).select();
  17666. }
  17667. }
  17668. domUtils.preventDefault(evt);
  17669. }
  17670. //trace:1634
  17671. //ff的del键在容器空的时候,也会删除
  17672. if (browser.gecko && keyCode == 46) {
  17673. range = me.selection.getRange();
  17674. if (range.collapsed) {
  17675. start = range.startContainer;
  17676. if (domUtils.isEmptyBlock(start)) {
  17677. var parent = start.parentNode;
  17678. while (
  17679. domUtils.getChildCount(parent) == 1 &&
  17680. !domUtils.isBody(parent)
  17681. ) {
  17682. start = parent;
  17683. parent = parent.parentNode;
  17684. }
  17685. if (start === parent.lastChild) evt.preventDefault();
  17686. return;
  17687. }
  17688. }
  17689. }
  17690. /* 修复在编辑区域快捷键 (Mac:meta+alt+I; Win:ctrl+shift+I) 打不开 chrome 控制台的问题 */
  17691. browser.chrome &&
  17692. me.on("keydown", function(type, e) {
  17693. var keyCode = e.keyCode || e.which;
  17694. if (
  17695. ((e.metaKey && e.altKey) || (e.ctrlKey && e.shiftKey)) &&
  17696. keyCode == 73
  17697. ) {
  17698. return true;
  17699. }
  17700. });
  17701. });
  17702. me.addListener("keyup", function(type, evt) {
  17703. var keyCode = evt.keyCode || evt.which,
  17704. rng,
  17705. me = this;
  17706. if (keyCode == keymap.Backspace) {
  17707. if (me.fireEvent("delkeyup")) {
  17708. return;
  17709. }
  17710. rng = me.selection.getRange();
  17711. if (rng.collapsed) {
  17712. var tmpNode,
  17713. autoClearTagName = ["h1", "h2", "h3", "h4", "h5", "h6"];
  17714. if (
  17715. (tmpNode = domUtils.findParentByTagName(
  17716. rng.startContainer,
  17717. autoClearTagName,
  17718. true
  17719. ))
  17720. ) {
  17721. if (domUtils.isEmptyBlock(tmpNode)) {
  17722. var pre = tmpNode.previousSibling;
  17723. if (pre && pre.nodeName != "TABLE") {
  17724. domUtils.remove(tmpNode);
  17725. rng.setStartAtLast(pre).setCursor(false, true);
  17726. return;
  17727. } else {
  17728. var next = tmpNode.nextSibling;
  17729. if (next && next.nodeName != "TABLE") {
  17730. domUtils.remove(tmpNode);
  17731. rng.setStartAtFirst(next).setCursor(false, true);
  17732. return;
  17733. }
  17734. }
  17735. }
  17736. }
  17737. //处理当删除到body时,要重新给p标签展位
  17738. if (domUtils.isBody(rng.startContainer)) {
  17739. var tmpNode = domUtils.createElement(me.document, "p", {
  17740. innerHTML: browser.ie ? domUtils.fillChar : "<br/>"
  17741. });
  17742. rng.insertNode(tmpNode).setStart(tmpNode, 0).setCursor(false, true);
  17743. }
  17744. }
  17745. //chrome下如果删除了inline标签,浏览器会有记忆,在输入文字还是会套上刚才删除的标签,所以这里再选一次就不会了
  17746. if (
  17747. !collapsed &&
  17748. (rng.startContainer.nodeType == 3 ||
  17749. (rng.startContainer.nodeType == 1 &&
  17750. domUtils.isEmptyBlock(rng.startContainer)))
  17751. ) {
  17752. if (browser.ie) {
  17753. var span = rng.document.createElement("span");
  17754. rng.insertNode(span).setStartBefore(span).collapse(true);
  17755. rng.select();
  17756. domUtils.remove(span);
  17757. } else {
  17758. rng.select();
  17759. }
  17760. }
  17761. }
  17762. });
  17763. };
  17764. // plugins/fiximgclick.js
  17765. ///import core
  17766. ///commands 修复chrome下图片不能点击的问题,出现八个角可改变大小
  17767. ///commandsName FixImgClick
  17768. ///commandsTitle 修复chrome下图片不能点击的问题,出现八个角可改变大小
  17769. //修复chrome下图片不能点击的问题,出现八个角可改变大小
  17770. UE.plugins["fiximgclick"] = (function() {
  17771. var elementUpdated = false;
  17772. function Scale() {
  17773. this.editor = null;
  17774. this.resizer = null;
  17775. this.cover = null;
  17776. this.doc = document;
  17777. this.prePos = { x: 0, y: 0 };
  17778. this.startPos = { x: 0, y: 0 };
  17779. }
  17780. (function() {
  17781. var rect = [
  17782. //[left, top, width, height]
  17783. [0, 0, -1, -1],
  17784. [0, 0, 0, -1],
  17785. [0, 0, 1, -1],
  17786. [0, 0, -1, 0],
  17787. [0, 0, 1, 0],
  17788. [0, 0, -1, 1],
  17789. [0, 0, 0, 1],
  17790. [0, 0, 1, 1]
  17791. ];
  17792. Scale.prototype = {
  17793. init: function(editor) {
  17794. var me = this;
  17795. me.editor = editor;
  17796. me.startPos = this.prePos = { x: 0, y: 0 };
  17797. me.dragId = -1;
  17798. var hands = [],
  17799. cover = (me.cover = document.createElement("div")),
  17800. resizer = (me.resizer = document.createElement("div"));
  17801. cover.id = me.editor.ui.id + "_imagescale_cover";
  17802. cover.style.cssText =
  17803. "position:absolute;display:none;z-index:" +
  17804. me.editor.options.zIndex +
  17805. ";filter:alpha(opacity=0); opacity:0;background:#CCC;";
  17806. domUtils.on(cover, "mousedown click", function() {
  17807. me.hide();
  17808. });
  17809. for (i = 0; i < 8; i++) {
  17810. hands.push(
  17811. '<span class="edui-editor-imagescale-hand' + i + '"></span>'
  17812. );
  17813. }
  17814. resizer.id = me.editor.ui.id + "_imagescale";
  17815. resizer.className = "edui-editor-imagescale";
  17816. resizer.innerHTML = hands.join("");
  17817. resizer.style.cssText +=
  17818. ";display:none;border:1px solid #3b77ff;z-index:" +
  17819. me.editor.options.zIndex +
  17820. ";";
  17821. me.editor.ui.getDom().appendChild(cover);
  17822. me.editor.ui.getDom().appendChild(resizer);
  17823. me.initStyle();
  17824. me.initEvents();
  17825. },
  17826. initStyle: function() {
  17827. utils.cssRule(
  17828. "imagescale",
  17829. ".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;}" +
  17830. ".edui-editor-imagescale span{position:absolute;width:6px;height:6px;overflow:hidden;font-size:0px;display:block;background-color:#3C9DD0;}" +
  17831. ".edui-editor-imagescale .edui-editor-imagescale-hand0{cursor:nw-resize;top:0;margin-top:-4px;left:0;margin-left:-4px;}" +
  17832. ".edui-editor-imagescale .edui-editor-imagescale-hand1{cursor:n-resize;top:0;margin-top:-4px;left:50%;margin-left:-4px;}" +
  17833. ".edui-editor-imagescale .edui-editor-imagescale-hand2{cursor:ne-resize;top:0;margin-top:-4px;left:100%;margin-left:-3px;}" +
  17834. ".edui-editor-imagescale .edui-editor-imagescale-hand3{cursor:w-resize;top:50%;margin-top:-4px;left:0;margin-left:-4px;}" +
  17835. ".edui-editor-imagescale .edui-editor-imagescale-hand4{cursor:e-resize;top:50%;margin-top:-4px;left:100%;margin-left:-3px;}" +
  17836. ".edui-editor-imagescale .edui-editor-imagescale-hand5{cursor:sw-resize;top:100%;margin-top:-3px;left:0;margin-left:-4px;}" +
  17837. ".edui-editor-imagescale .edui-editor-imagescale-hand6{cursor:s-resize;top:100%;margin-top:-3px;left:50%;margin-left:-4px;}" +
  17838. ".edui-editor-imagescale .edui-editor-imagescale-hand7{cursor:se-resize;top:100%;margin-top:-3px;left:100%;margin-left:-3px;}"
  17839. );
  17840. },
  17841. initEvents: function() {
  17842. var me = this;
  17843. me.startPos.x = me.startPos.y = 0;
  17844. me.isDraging = false;
  17845. },
  17846. _eventHandler: function(e) {
  17847. var me = this,
  17848. pressMouseLeft = e.buttons === undefined ? e.which === 1 : e.buttons === 1;
  17849. switch (e.type) {
  17850. case "mousedown":
  17851. var hand = e.target || e.srcElement,
  17852. hand;
  17853. if (
  17854. hand.className.indexOf("edui-editor-imagescale-hand") != -1 &&
  17855. me.dragId == -1
  17856. ) {
  17857. me.dragId = hand.className.slice(-1);
  17858. me.startPos.x = me.prePos.x = e.clientX;
  17859. me.startPos.y = me.prePos.y = e.clientY;
  17860. domUtils.on(me.doc, "mousemove", me.proxy(me._eventHandler, me));
  17861. }
  17862. break;
  17863. case "mousemove":
  17864. if (me.dragId != -1 && pressMouseLeft) {
  17865. me.updateContainerStyle(me.dragId, {
  17866. x: e.clientX - me.prePos.x,
  17867. y: e.clientY - me.prePos.y
  17868. });
  17869. me.prePos.x = e.clientX;
  17870. me.prePos.y = e.clientY;
  17871. elementUpdated = true;
  17872. me.updateTargetElement();
  17873. }
  17874. break;
  17875. case "mouseup":
  17876. if (me.dragId != -1) {
  17877. me.updateContainerStyle(me.dragId, {
  17878. x: e.clientX - me.prePos.x,
  17879. y: e.clientY - me.prePos.y
  17880. });
  17881. me.updateTargetElement();
  17882. if (me.target.parentNode) me.attachTo(me.target);
  17883. me.dragId = -1;
  17884. }
  17885. domUtils.un(me.doc, "mousemove", me.proxy(me._eventHandler, me));
  17886. //修复只是点击挪动点,但没有改变大小,不应该触发contentchange
  17887. if (elementUpdated) {
  17888. elementUpdated = false;
  17889. me.editor.fireEvent("contentchange");
  17890. }
  17891. break;
  17892. default:
  17893. break;
  17894. }
  17895. },
  17896. updateTargetElement: function() {
  17897. var me = this;
  17898. domUtils.setStyles(me.target, {
  17899. width: me.resizer.style.width,
  17900. height: me.resizer.style.height
  17901. });
  17902. me.target.width = parseInt(me.resizer.style.width);
  17903. me.target.height = parseInt(me.resizer.style.height);
  17904. me.attachTo(me.target);
  17905. },
  17906. updateContainerStyle: function(dir, offset) {
  17907. var me = this,
  17908. dom = me.resizer,
  17909. tmp;
  17910. if (rect[dir][0] != 0) {
  17911. tmp = parseInt(dom.style.left) + offset.x;
  17912. dom.style.left = me._validScaledProp("left", tmp) + "px";
  17913. }
  17914. if (rect[dir][1] != 0) {
  17915. tmp = parseInt(dom.style.top) + offset.y;
  17916. dom.style.top = me._validScaledProp("top", tmp) + "px";
  17917. }
  17918. if (rect[dir][2] != 0) {
  17919. tmp = dom.clientWidth + rect[dir][2] * offset.x;
  17920. dom.style.width = me._validScaledProp("width", tmp) + "px";
  17921. }
  17922. if (rect[dir][3] != 0) {
  17923. tmp = dom.clientHeight + rect[dir][3] * offset.y;
  17924. dom.style.height = me._validScaledProp("height", tmp) + "px";
  17925. }
  17926. },
  17927. _validScaledProp: function(prop, value) {
  17928. var ele = this.resizer,
  17929. wrap = document;
  17930. value = isNaN(value) ? 0 : value;
  17931. switch (prop) {
  17932. case "left":
  17933. return value < 0
  17934. ? 0
  17935. : value + ele.clientWidth > wrap.clientWidth
  17936. ? wrap.clientWidth - ele.clientWidth
  17937. : value;
  17938. case "top":
  17939. return value < 0
  17940. ? 0
  17941. : value + ele.clientHeight > wrap.clientHeight
  17942. ? wrap.clientHeight - ele.clientHeight
  17943. : value;
  17944. case "width":
  17945. return value <= 0
  17946. ? 1
  17947. : value + ele.offsetLeft > wrap.clientWidth
  17948. ? wrap.clientWidth - ele.offsetLeft
  17949. : value;
  17950. case "height":
  17951. return value <= 0
  17952. ? 1
  17953. : value + ele.offsetTop > wrap.clientHeight
  17954. ? wrap.clientHeight - ele.offsetTop
  17955. : value;
  17956. }
  17957. },
  17958. hideCover: function() {
  17959. this.cover.style.display = "none";
  17960. },
  17961. showCover: function() {
  17962. var me = this,
  17963. editorPos = domUtils.getXY(me.editor.ui.getDom()),
  17964. iframePos = domUtils.getXY(me.editor.iframe);
  17965. domUtils.setStyles(me.cover, {
  17966. width: me.editor.iframe.offsetWidth + "px",
  17967. height: me.editor.iframe.offsetHeight + "px",
  17968. top: iframePos.y - editorPos.y + "px",
  17969. left: iframePos.x - editorPos.x + "px",
  17970. position: "absolute",
  17971. display: ""
  17972. });
  17973. },
  17974. show: function(targetObj) {
  17975. var me = this;
  17976. me.resizer.style.display = "block";
  17977. if (targetObj) me.attachTo(targetObj);
  17978. domUtils.on(this.resizer, "mousedown", me.proxy(me._eventHandler, me));
  17979. domUtils.on(me.doc, "mouseup", me.proxy(me._eventHandler, me));
  17980. me.showCover();
  17981. me.editor.fireEvent("afterscaleshow", me);
  17982. me.editor.fireEvent("saveScene");
  17983. },
  17984. hide: function() {
  17985. var me = this;
  17986. me.hideCover();
  17987. me.resizer.style.display = "none";
  17988. domUtils.un(me.resizer, "mousedown", me.proxy(me._eventHandler, me));
  17989. domUtils.un(me.doc, "mouseup", me.proxy(me._eventHandler, me));
  17990. me.editor.fireEvent("afterscalehide", me);
  17991. },
  17992. proxy: function(fn, context) {
  17993. return function(e) {
  17994. return fn.apply(context || this, arguments);
  17995. };
  17996. },
  17997. attachTo: function(targetObj) {
  17998. var me = this,
  17999. target = (me.target = targetObj),
  18000. resizer = this.resizer,
  18001. imgPos = domUtils.getXY(target),
  18002. iframePos = domUtils.getXY(me.editor.iframe),
  18003. editorPos = domUtils.getXY(resizer.parentNode);
  18004. var doc = me.editor.document;
  18005. domUtils.setStyles(resizer, {
  18006. width: target.width + "px",
  18007. height: target.height + "px",
  18008. left:
  18009. iframePos.x +
  18010. imgPos.x -
  18011. (doc.documentElement.scrollLeft || doc.body.scrollLeft || 0) -
  18012. editorPos.x -
  18013. parseInt(resizer.style.borderLeftWidth) +
  18014. "px",
  18015. top:
  18016. iframePos.y +
  18017. imgPos.y -
  18018. (doc.documentElement.scrollTop || doc.body.scrollTop || 0) -
  18019. editorPos.y -
  18020. parseInt(resizer.style.borderTopWidth) +
  18021. "px"
  18022. });
  18023. }
  18024. };
  18025. })();
  18026. return function() {
  18027. var me = this,
  18028. imageScale;
  18029. me.setOpt("imageScaleEnabled", true);
  18030. if (!browser.ie && me.options.imageScaleEnabled) {
  18031. me.addListener("click", function(type, e) {
  18032. var range = me.selection.getRange(),
  18033. img = range.getClosedNode();
  18034. if (img && img.tagName == "IMG" && me.body.contentEditable != "false") {
  18035. if (
  18036. img.className.indexOf("edui-faked-music") != -1 ||
  18037. img.getAttribute("anchorname") ||
  18038. domUtils.hasClass(img, "loadingclass") ||
  18039. domUtils.hasClass(img, "loaderrorclass")
  18040. ) {
  18041. return;
  18042. }
  18043. if (!imageScale) {
  18044. imageScale = new Scale();
  18045. imageScale.init(me);
  18046. me.ui.getDom().appendChild(imageScale.resizer);
  18047. var _keyDownHandler = function(e) {
  18048. imageScale.hide();
  18049. if (imageScale.target)
  18050. me.selection.getRange().selectNode(imageScale.target).select();
  18051. },
  18052. _mouseDownHandler = function(e) {
  18053. var ele = e.target || e.srcElement;
  18054. if (
  18055. ele &&
  18056. (ele.className === undefined ||
  18057. ele.className.indexOf("edui-editor-imagescale") == -1)
  18058. ) {
  18059. _keyDownHandler(e);
  18060. }
  18061. },
  18062. timer;
  18063. me.addListener("afterscaleshow", function(e) {
  18064. me.addListener("beforekeydown", _keyDownHandler);
  18065. me.addListener("beforemousedown", _mouseDownHandler);
  18066. domUtils.on(document, "keydown", _keyDownHandler);
  18067. domUtils.on(document, "mousedown", _mouseDownHandler);
  18068. me.selection.getNative().removeAllRanges();
  18069. });
  18070. me.addListener("afterscalehide", function(e) {
  18071. me.removeListener("beforekeydown", _keyDownHandler);
  18072. me.removeListener("beforemousedown", _mouseDownHandler);
  18073. domUtils.un(document, "keydown", _keyDownHandler);
  18074. domUtils.un(document, "mousedown", _mouseDownHandler);
  18075. var target = imageScale.target;
  18076. if (target.parentNode) {
  18077. me.selection.getRange().selectNode(target).select();
  18078. }
  18079. });
  18080. //TODO 有iframe的情况,mousedown不能往下传。。
  18081. domUtils.on(imageScale.resizer, "mousedown", function(e) {
  18082. me.selection.getNative().removeAllRanges();
  18083. var ele = e.target || e.srcElement;
  18084. if (
  18085. ele &&
  18086. ele.className.indexOf("edui-editor-imagescale-hand") == -1
  18087. ) {
  18088. timer = setTimeout(function() {
  18089. imageScale.hide();
  18090. if (imageScale.target)
  18091. me.selection.getRange().selectNode(ele).select();
  18092. }, 200);
  18093. }
  18094. });
  18095. domUtils.on(imageScale.resizer, "mouseup", function(e) {
  18096. var ele = e.target || e.srcElement;
  18097. if (
  18098. ele &&
  18099. ele.className.indexOf("edui-editor-imagescale-hand") == -1
  18100. ) {
  18101. clearTimeout(timer);
  18102. }
  18103. });
  18104. }
  18105. imageScale.show(img);
  18106. } else {
  18107. if (imageScale && imageScale.resizer.style.display != "none")
  18108. imageScale.hide();
  18109. }
  18110. });
  18111. }
  18112. if (browser.webkit) {
  18113. me.addListener("click", function(type, e) {
  18114. if (e.target.tagName == "IMG" && me.body.contentEditable != "false") {
  18115. var range = new dom.Range(me.document);
  18116. range.selectNode(e.target).select();
  18117. }
  18118. });
  18119. }
  18120. };
  18121. })();
  18122. // plugins/autolink.js
  18123. ///import core
  18124. ///commands 为非ie浏览器自动添加a标签
  18125. ///commandsName AutoLink
  18126. ///commandsTitle 自动增加链接
  18127. /**
  18128. * @description 为非ie浏览器自动添加a标签
  18129. * @author zhanyi
  18130. */
  18131. UE.plugin.register(
  18132. "autolink",
  18133. function() {
  18134. var cont = 0;
  18135. return !browser.ie
  18136. ? {
  18137. bindEvents: {
  18138. reset: function() {
  18139. cont = 0;
  18140. },
  18141. keydown: function(type, evt) {
  18142. var me = this;
  18143. var keyCode = evt.keyCode || evt.which;
  18144. if (keyCode == 32 || keyCode == 13) {
  18145. var sel = me.selection.getNative(),
  18146. range = sel.getRangeAt(0).cloneRange(),
  18147. offset,
  18148. charCode;
  18149. var start = range.startContainer;
  18150. while (start.nodeType == 1 && range.startOffset > 0) {
  18151. start =
  18152. range.startContainer.childNodes[range.startOffset - 1];
  18153. if (!start) {
  18154. break;
  18155. }
  18156. range.setStart(
  18157. start,
  18158. start.nodeType == 1
  18159. ? start.childNodes.length
  18160. : start.nodeValue.length
  18161. );
  18162. range.collapse(true);
  18163. start = range.startContainer;
  18164. }
  18165. do {
  18166. if (range.startOffset == 0) {
  18167. start = range.startContainer.previousSibling;
  18168. while (start && start.nodeType == 1) {
  18169. start = start.lastChild;
  18170. }
  18171. if (!start || domUtils.isFillChar(start)) {
  18172. break;
  18173. }
  18174. offset = start.nodeValue.length;
  18175. } else {
  18176. start = range.startContainer;
  18177. offset = range.startOffset;
  18178. }
  18179. range.setStart(start, offset - 1);
  18180. charCode = range.toString().charCodeAt(0);
  18181. } while (charCode != 160 && charCode != 32);
  18182. if (
  18183. range
  18184. .toString()
  18185. .replace(new RegExp(domUtils.fillChar, "g"), "")
  18186. .match(/(?:https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.)/i)
  18187. ) {
  18188. while (range.toString().length) {
  18189. if (
  18190. /^(?:https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.)/i.test(
  18191. range.toString()
  18192. )
  18193. ) {
  18194. break;
  18195. }
  18196. try {
  18197. range.setStart(
  18198. range.startContainer,
  18199. range.startOffset + 1
  18200. );
  18201. } catch (e) {
  18202. //trace:2121
  18203. var start = range.startContainer;
  18204. while (!(next = start.nextSibling)) {
  18205. if (domUtils.isBody(start)) {
  18206. return;
  18207. }
  18208. start = start.parentNode;
  18209. }
  18210. range.setStart(next, 0);
  18211. }
  18212. }
  18213. //range的开始边界已经在a标签里的不再处理
  18214. if (
  18215. domUtils.findParentByTagName(
  18216. range.startContainer,
  18217. "a",
  18218. true
  18219. )
  18220. ) {
  18221. return;
  18222. }
  18223. var a = me.document.createElement("a"),
  18224. text = me.document.createTextNode(" "),
  18225. href;
  18226. me.undoManger && me.undoManger.save();
  18227. a.appendChild(range.extractContents());
  18228. a.href = a.innerHTML = a.innerHTML.replace(/<[^>]+>/g, "");
  18229. href = a
  18230. .getAttribute("href")
  18231. .replace(new RegExp(domUtils.fillChar, "g"), "");
  18232. href = /^(?:https?:\/\/)/gi.test(href)
  18233. ? href
  18234. : "http://" + href;
  18235. a.setAttribute("_src", utils.html(href));
  18236. a.href = utils.html(href);
  18237. range.insertNode(a);
  18238. a.parentNode.insertBefore(text, a.nextSibling);
  18239. range.setStart(text, 0);
  18240. range.collapse(true);
  18241. sel.removeAllRanges();
  18242. sel.addRange(range);
  18243. me.undoManger && me.undoManger.save();
  18244. }
  18245. }
  18246. }
  18247. }
  18248. }
  18249. : {};
  18250. },
  18251. function() {
  18252. var keyCodes = {
  18253. 37: 1,
  18254. 38: 1,
  18255. 39: 1,
  18256. 40: 1,
  18257. 13: 1,
  18258. 32: 1
  18259. };
  18260. function checkIsCludeLink(node) {
  18261. if (node.nodeType == 3) {
  18262. return null;
  18263. }
  18264. if (node.nodeName == "A") {
  18265. return node;
  18266. }
  18267. var lastChild = node.lastChild;
  18268. while (lastChild) {
  18269. if (lastChild.nodeName == "A") {
  18270. return lastChild;
  18271. }
  18272. if (lastChild.nodeType == 3) {
  18273. if (domUtils.isWhitespace(lastChild)) {
  18274. lastChild = lastChild.previousSibling;
  18275. continue;
  18276. }
  18277. return null;
  18278. }
  18279. lastChild = lastChild.lastChild;
  18280. }
  18281. }
  18282. browser.ie &&
  18283. this.addListener("keyup", function(cmd, evt) {
  18284. var me = this,
  18285. keyCode = evt.keyCode;
  18286. if (keyCodes[keyCode]) {
  18287. var rng = me.selection.getRange();
  18288. var start = rng.startContainer;
  18289. if (keyCode == 13) {
  18290. while (
  18291. start &&
  18292. !domUtils.isBody(start) &&
  18293. !domUtils.isBlockElm(start)
  18294. ) {
  18295. start = start.parentNode;
  18296. }
  18297. if (start && !domUtils.isBody(start) && start.nodeName == "P") {
  18298. var pre = start.previousSibling;
  18299. if (pre && pre.nodeType == 1) {
  18300. var pre = checkIsCludeLink(pre);
  18301. if (pre && !pre.getAttribute("_href")) {
  18302. domUtils.remove(pre, true);
  18303. }
  18304. }
  18305. }
  18306. } else if (keyCode == 32) {
  18307. if (start.nodeType == 3 && /^\s$/.test(start.nodeValue)) {
  18308. start = start.previousSibling;
  18309. if (
  18310. start &&
  18311. start.nodeName == "A" &&
  18312. !start.getAttribute("_href")
  18313. ) {
  18314. domUtils.remove(start, true);
  18315. }
  18316. }
  18317. } else {
  18318. start = domUtils.findParentByTagName(start, "a", true);
  18319. if (start && !start.getAttribute("_href")) {
  18320. var bk = rng.createBookmark();
  18321. domUtils.remove(start, true);
  18322. rng.moveToBookmark(bk).select(true);
  18323. }
  18324. }
  18325. }
  18326. });
  18327. }
  18328. );
  18329. // plugins/autoheight.js
  18330. ///import core
  18331. ///commands 当输入内容超过编辑器高度时,编辑器自动增高
  18332. ///commandsName AutoHeight,autoHeightEnabled
  18333. ///commandsTitle 自动增高
  18334. /**
  18335. * @description 自动伸展
  18336. * @author zhanyi
  18337. */
  18338. UE.plugins["autoheight"] = function() {
  18339. var me = this;
  18340. //提供开关,就算加载也可以关闭
  18341. me.autoHeightEnabled = me.options.autoHeightEnabled !== false;
  18342. if (!me.autoHeightEnabled) {
  18343. return;
  18344. }
  18345. var bakOverflow,
  18346. lastHeight = 0,
  18347. options = me.options,
  18348. currentHeight,
  18349. timer;
  18350. function adjustHeight() {
  18351. var me = this;
  18352. clearTimeout(timer);
  18353. if (isFullscreen) return;
  18354. if (
  18355. !me.queryCommandState ||
  18356. (me.queryCommandState && me.queryCommandState("source") != 1)
  18357. ) {
  18358. timer = setTimeout(function() {
  18359. var node = me.body.lastChild;
  18360. while (node && node.nodeType != 1) {
  18361. node = node.previousSibling;
  18362. }
  18363. if (node && node.nodeType == 1) {
  18364. node.style.clear = "both";
  18365. currentHeight = Math.max(
  18366. domUtils.getXY(node).y + node.offsetHeight + 25,
  18367. Math.max(options.minFrameHeight, options.initialFrameHeight)
  18368. );
  18369. if (currentHeight != lastHeight) {
  18370. if (currentHeight !== parseInt(me.iframe.parentNode.style.height)) {
  18371. me.iframe.parentNode.style.height = currentHeight + "px";
  18372. }
  18373. me.body.style.height = currentHeight + "px";
  18374. lastHeight = currentHeight;
  18375. }
  18376. domUtils.removeStyle(node, "clear");
  18377. }
  18378. }, 50);
  18379. }
  18380. }
  18381. var isFullscreen;
  18382. me.addListener("fullscreenchanged", function(cmd, f) {
  18383. isFullscreen = f;
  18384. });
  18385. me.addListener("destroy", function() {
  18386. domUtils.un(me.window, "scroll", fixedScrollTop);
  18387. me.removeListener(
  18388. "contentchange afterinserthtml keyup mouseup",
  18389. adjustHeight
  18390. );
  18391. });
  18392. me.enableAutoHeight = function() {
  18393. var me = this;
  18394. if (!me.autoHeightEnabled) {
  18395. return;
  18396. }
  18397. var doc = me.document;
  18398. me.autoHeightEnabled = true;
  18399. bakOverflow = doc.body.style.overflowY;
  18400. doc.body.style.overflowY = "hidden";
  18401. me.addListener("contentchange afterinserthtml keyup mouseup", adjustHeight);
  18402. //ff不给事件算得不对
  18403. setTimeout(function() {
  18404. adjustHeight.call(me);
  18405. }, browser.gecko ? 100 : 0);
  18406. me.fireEvent("autoheightchanged", me.autoHeightEnabled);
  18407. };
  18408. me.disableAutoHeight = function() {
  18409. me.body.style.overflowY = bakOverflow || "";
  18410. me.removeListener("contentchange", adjustHeight);
  18411. me.removeListener("keyup", adjustHeight);
  18412. me.removeListener("mouseup", adjustHeight);
  18413. me.autoHeightEnabled = false;
  18414. me.fireEvent("autoheightchanged", me.autoHeightEnabled);
  18415. };
  18416. me.on("setHeight", function() {
  18417. me.disableAutoHeight();
  18418. });
  18419. me.addListener("ready", function() {
  18420. me.enableAutoHeight();
  18421. //trace:1764
  18422. var timer;
  18423. domUtils.on(
  18424. browser.ie ? me.body : me.document,
  18425. browser.webkit ? "dragover" : "drop",
  18426. function() {
  18427. clearTimeout(timer);
  18428. timer = setTimeout(function() {
  18429. //trace:3681
  18430. adjustHeight.call(me);
  18431. }, 100);
  18432. }
  18433. );
  18434. //修复内容过多时,回到顶部,顶部内容被工具栏遮挡问题
  18435. domUtils.on(me.window, "scroll", fixedScrollTop);
  18436. });
  18437. var lastScrollY;
  18438. function fixedScrollTop() {
  18439. if (!me.window) return;
  18440. if (lastScrollY === null) {
  18441. lastScrollY = me.window.scrollY;
  18442. } else if (me.window.scrollY == 0 && lastScrollY != 0) {
  18443. me.window.scrollTo(0, 0);
  18444. lastScrollY = null;
  18445. }
  18446. }
  18447. };
  18448. // plugins/autofloat.js
  18449. ///import core
  18450. ///commands 悬浮工具栏
  18451. ///commandsName AutoFloat,autoFloatEnabled
  18452. ///commandsTitle 悬浮工具栏
  18453. /**
  18454. * modified by chengchao01
  18455. * 注意: 引入此功能后,在IE6下会将body的背景图片覆盖掉!
  18456. */
  18457. UE.plugins["autofloat"] = function() {
  18458. var me = this,
  18459. lang = me.getLang();
  18460. me.setOpt({
  18461. topOffset: 0
  18462. });
  18463. var optsAutoFloatEnabled = me.options.autoFloatEnabled !== false,
  18464. topOffset = me.options.topOffset;
  18465. //如果不固定toolbar的位置,则直接退出
  18466. if (!optsAutoFloatEnabled) {
  18467. return;
  18468. }
  18469. var uiUtils = UE.ui.uiUtils,
  18470. LteIE6 = browser.ie && browser.version <= 6,
  18471. quirks = browser.quirks;
  18472. function checkHasUI() {
  18473. if (!UE.ui) {
  18474. alert(lang.autofloatMsg);
  18475. return 0;
  18476. }
  18477. return 1;
  18478. }
  18479. function fixIE6FixedPos() {
  18480. var docStyle = document.body.style;
  18481. docStyle.backgroundImage = 'url("about:blank")';
  18482. docStyle.backgroundAttachment = "fixed";
  18483. }
  18484. var bakCssText,
  18485. placeHolder = document.createElement("div"),
  18486. toolbarBox,
  18487. orgTop,
  18488. getPosition,
  18489. flag = true; //ie7模式下需要偏移
  18490. function setFloating() {
  18491. var toobarBoxPos = domUtils.getXY(toolbarBox),
  18492. origalFloat = domUtils.getComputedStyle(toolbarBox, "position"),
  18493. origalLeft = domUtils.getComputedStyle(toolbarBox, "left");
  18494. toolbarBox.style.width = toolbarBox.offsetWidth + "px";
  18495. toolbarBox.style.zIndex = me.options.zIndex * 1 + 1;
  18496. toolbarBox.parentNode.insertBefore(placeHolder, toolbarBox);
  18497. if (LteIE6 || (quirks && browser.ie)) {
  18498. if (toolbarBox.style.position != "absolute") {
  18499. toolbarBox.style.position = "absolute";
  18500. }
  18501. toolbarBox.style.top =
  18502. (document.body.scrollTop || document.documentElement.scrollTop) -
  18503. orgTop +
  18504. topOffset +
  18505. "px";
  18506. } else {
  18507. if (browser.ie7Compat && flag) {
  18508. flag = false;
  18509. toolbarBox.style.left =
  18510. domUtils.getXY(toolbarBox).x -
  18511. document.documentElement.getBoundingClientRect().left +
  18512. 2 +
  18513. "px";
  18514. }
  18515. if (toolbarBox.style.position != "fixed") {
  18516. toolbarBox.style.position = "fixed";
  18517. toolbarBox.style.top = topOffset + "px";
  18518. (origalFloat == "absolute" || origalFloat == "relative") &&
  18519. parseFloat(origalLeft) &&
  18520. (toolbarBox.style.left = toobarBoxPos.x + "px");
  18521. }
  18522. }
  18523. }
  18524. function unsetFloating() {
  18525. flag = true;
  18526. if (placeHolder.parentNode) {
  18527. placeHolder.parentNode.removeChild(placeHolder);
  18528. }
  18529. toolbarBox.style.cssText = bakCssText;
  18530. }
  18531. function updateFloating() {
  18532. var rect3 = getPosition(me.container);
  18533. var offset = me.options.toolbarTopOffset || 0;
  18534. if (rect3.top < 0 && rect3.bottom - toolbarBox.offsetHeight > offset) {
  18535. setFloating();
  18536. } else {
  18537. unsetFloating();
  18538. }
  18539. }
  18540. var defer_updateFloating = utils.defer(
  18541. function() {
  18542. updateFloating();
  18543. },
  18544. browser.ie ? 200 : 100,
  18545. true
  18546. );
  18547. me.addListener("destroy", function() {
  18548. domUtils.un(window, ["scroll", "resize"], updateFloating);
  18549. me.removeListener("keydown", defer_updateFloating);
  18550. //适用于在DIV scrollbox中滚动,但页面不滚动的浮动toolbar
  18551. var scrollBox = document.getElementById("scrollBox");
  18552. if (scrollBox) {
  18553. domUtils.un(scrollBox, ['scroll','resize'], updateFloating);
  18554. }
  18555. });
  18556. me.addListener("ready", function() {
  18557. if (checkHasUI(me)) {
  18558. //加载了ui组件,但在new时,没有加载ui,导致编辑器实例上没有ui类,所以这里做判断
  18559. if (!me.ui) {
  18560. return;
  18561. }
  18562. getPosition = uiUtils.getClientRect;
  18563. toolbarBox = me.ui.getDom("toolbarbox");
  18564. orgTop = getPosition(toolbarBox).top;
  18565. bakCssText = toolbarBox.style.cssText;
  18566. placeHolder.style.height = me.ui.getDom("iframeholder").offsetHeight + "px";
  18567. if (LteIE6) {
  18568. fixIE6FixedPos();
  18569. }
  18570. domUtils.on(window, ["scroll", "resize"], updateFloating);
  18571. me.addListener("keydown", defer_updateFloating);
  18572. //适用于在DIV scrollbox中滚动,但页面不滚动的浮动toolbar
  18573. var scrollBox = document.getElementById("scrollBox");
  18574. if (scrollBox) {
  18575. domUtils.on(scrollBox, ['scroll','resize'], updateFloating);
  18576. }
  18577. me.addListener("beforefullscreenchange", function(t, enabled) {
  18578. if (enabled) {
  18579. unsetFloating();
  18580. }
  18581. });
  18582. me.addListener("fullscreenchanged", function(t, enabled) {
  18583. if (!enabled) {
  18584. updateFloating();
  18585. }
  18586. });
  18587. me.addListener("sourcemodechanged", function(t, enabled) {
  18588. setTimeout(function() {
  18589. updateFloating();
  18590. }, 0);
  18591. });
  18592. me.addListener("clearDoc", function() {
  18593. setTimeout(function() {
  18594. updateFloating();
  18595. }, 0);
  18596. });
  18597. }
  18598. });
  18599. };
  18600. // plugins/video.js
  18601. /**
  18602. * video插件, 为UEditor提供视频插入支持
  18603. * @file
  18604. * @since 1.2.6.1
  18605. */
  18606. UE.plugins["video"] = function() {
  18607. var me = this;
  18608. /**
  18609. * 创建插入视频字符窜
  18610. * @param url 视频地址
  18611. * @param width 视频宽度
  18612. * @param height 视频高度
  18613. * @param align 视频对齐
  18614. * @param toEmbed 是否以flash代替显示
  18615. * @param addParagraph 是否需要添加P 标签
  18616. */
  18617. function creatInsertStr(url, width, height, id, align, classname, type) {
  18618. var str;
  18619. switch (type) {
  18620. case "image":
  18621. str =
  18622. "<img " +
  18623. (id ? 'id="' + id + '"' : "") +
  18624. ' width="' +
  18625. width +
  18626. '" height="' +
  18627. height +
  18628. '" _url="' +
  18629. url +
  18630. '" class="' +
  18631. classname.replace(/\bvideo-js\b/, "") +
  18632. '"' +
  18633. ' src="' +
  18634. me.options.UEDITOR_HOME_URL +
  18635. 'themes/notadd/images/spacer.gif" style="background:url(' +
  18636. me.options.UEDITOR_HOME_URL +
  18637. "themes/notadd/images/videologo.gif) no-repeat center center; border:1px solid gray;" +
  18638. (align ? "float:" + align + ";" : "") +
  18639. '" data-ad="1234567890"/>';
  18640. break;
  18641. case "embed":
  18642. str =
  18643. '<embed type="application/x-shockwave-flash" class="' +
  18644. classname +
  18645. '" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  18646. ' src="' +
  18647. utils.html(url) +
  18648. '" width="' +
  18649. width +
  18650. '" height="' +
  18651. height +
  18652. '"' +
  18653. (align ? ' style="float:' + align + '"' : "") +
  18654. ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >';
  18655. break;
  18656. case "video":
  18657. var ext = url.substr(url.lastIndexOf(".") + 1);
  18658. if (ext == "ogv") ext = "ogg";
  18659. str =
  18660. "<video" +
  18661. (id ? ' id="' + id + '"' : "") +
  18662. ' class="' +
  18663. classname +
  18664. ' video-js" ' +
  18665. (align ? ' style="float:' + align + '"' : "") +
  18666. ' controls preload="none" width="' +
  18667. width +
  18668. '" height="' +
  18669. height +
  18670. '" src="' +
  18671. url +
  18672. '" data-setup="{}">' +
  18673. '<source src="' +
  18674. url +
  18675. '" type="video/' +
  18676. ext +
  18677. '" /></video>';
  18678. break;
  18679. }
  18680. return str;
  18681. }
  18682. function switchImgAndVideo(root, img2video) {
  18683. utils.each(
  18684. root.getNodesByTagName(img2video ? "img" : "embed video"),
  18685. function(node) {
  18686. var className = node.getAttr("class");
  18687. if (className && className.indexOf("edui-faked-video") != -1) {
  18688. var html = creatInsertStr(
  18689. img2video ? node.getAttr("_url") : node.getAttr("src"),
  18690. node.getAttr("width"),
  18691. node.getAttr("height"),
  18692. null,
  18693. node.getStyle("float") || "",
  18694. className,
  18695. img2video ? "embed" : "image"
  18696. );
  18697. node.parentNode.replaceChild(UE.uNode.createElement(html), node);
  18698. }
  18699. if (className && className.indexOf("edui-upload-video") != -1) {
  18700. var html = creatInsertStr(
  18701. img2video ? node.getAttr("_url") : node.getAttr("src"),
  18702. node.getAttr("width"),
  18703. node.getAttr("height"),
  18704. null,
  18705. node.getStyle("float") || "",
  18706. className,
  18707. img2video ? "video" : "image"
  18708. );
  18709. node.parentNode.replaceChild(UE.uNode.createElement(html), node);
  18710. }
  18711. }
  18712. );
  18713. }
  18714. me.addOutputRule(function(root) {
  18715. switchImgAndVideo(root, true);
  18716. });
  18717. me.addInputRule(function(root) {
  18718. switchImgAndVideo(root);
  18719. });
  18720. /**
  18721. * 插入视频
  18722. * @command insertvideo
  18723. * @method execCommand
  18724. * @param { String } cmd 命令字符串
  18725. * @param { Object } videoAttr 键值对对象, 描述一个视频的所有属性
  18726. * @example
  18727. * ```javascript
  18728. *
  18729. * var videoAttr = {
  18730. * //视频地址
  18731. * url: 'http://www.youku.com/xxx',
  18732. * //视频宽高值, 单位px
  18733. * width: 200,
  18734. * height: 100
  18735. * };
  18736. *
  18737. * //editor 是编辑器实例
  18738. * //向编辑器插入单个视频
  18739. * editor.execCommand( 'insertvideo', videoAttr );
  18740. * ```
  18741. */
  18742. /**
  18743. * 插入视频
  18744. * @command insertvideo
  18745. * @method execCommand
  18746. * @param { String } cmd 命令字符串
  18747. * @param { Array } videoArr 需要插入的视频的数组, 其中的每一个元素都是一个键值对对象, 描述了一个视频的所有属性
  18748. * @example
  18749. * ```javascript
  18750. *
  18751. * var videoAttr1 = {
  18752. * //视频地址
  18753. * url: 'http://www.youku.com/xxx',
  18754. * //视频宽高值, 单位px
  18755. * width: 200,
  18756. * height: 100
  18757. * },
  18758. * videoAttr2 = {
  18759. * //视频地址
  18760. * url: 'http://www.youku.com/xxx',
  18761. * //视频宽高值, 单位px
  18762. * width: 200,
  18763. * height: 100
  18764. * }
  18765. *
  18766. * //editor 是编辑器实例
  18767. * //该方法将会向编辑器内插入两个视频
  18768. * editor.execCommand( 'insertvideo', [ videoAttr1, videoAttr2 ] );
  18769. * ```
  18770. */
  18771. /**
  18772. * 查询当前光标所在处是否是一个视频
  18773. * @command insertvideo
  18774. * @method queryCommandState
  18775. * @param { String } cmd 需要查询的命令字符串
  18776. * @return { int } 如果当前光标所在处的元素是一个视频对象, 则返回1,否则返回0
  18777. * @example
  18778. * ```javascript
  18779. *
  18780. * //editor 是编辑器实例
  18781. * editor.queryCommandState( 'insertvideo' );
  18782. * ```
  18783. */
  18784. me.commands["insertvideo"] = {
  18785. execCommand: function(cmd, videoObjs, type) {
  18786. videoObjs = utils.isArray(videoObjs) ? videoObjs : [videoObjs];
  18787. if (me.fireEvent("beforeinsertvideo", videoObjs) === true) {
  18788. return;
  18789. }
  18790. var html = [],
  18791. id = "tmpVedio",
  18792. cl;
  18793. for (var i = 0, vi, len = videoObjs.length; i < len; i++) {
  18794. vi = videoObjs[i];
  18795. cl = type == "upload"
  18796. ? "edui-upload-video video-js vjs-default-skin"
  18797. : "edui-faked-video";
  18798. html.push(
  18799. creatInsertStr(
  18800. vi.url,
  18801. vi.width || 420,
  18802. vi.height || 280,
  18803. id + i,
  18804. null,
  18805. cl,
  18806. "image"
  18807. )
  18808. );
  18809. }
  18810. me.execCommand("inserthtml", html.join(""), true);
  18811. var rng = this.selection.getRange();
  18812. for (var i = 0, len = videoObjs.length; i < len; i++) {
  18813. var img = this.document.getElementById("tmpVedio" + i);
  18814. domUtils.removeAttributes(img, "id");
  18815. rng.selectNode(img).select();
  18816. me.execCommand("imagefloat", videoObjs[i].align);
  18817. }
  18818. me.fireEvent("afterinsertvideo", videoObjs);
  18819. },
  18820. queryCommandState: function() {
  18821. var img = me.selection.getRange().getClosedNode(),
  18822. flag =
  18823. img &&
  18824. (img.className == "edui-faked-video" ||
  18825. img.className.indexOf("edui-upload-video") != -1);
  18826. return flag ? 1 : 0;
  18827. }
  18828. };
  18829. };
  18830. // plugins/table.core.js
  18831. /**
  18832. * Created with JetBrains WebStorm.
  18833. * User: taoqili
  18834. * Date: 13-1-18
  18835. * Time: 上午11:09
  18836. * To change this template use File | Settings | File Templates.
  18837. */
  18838. /**
  18839. * UE表格操作类
  18840. * @param table
  18841. * @constructor
  18842. */
  18843. ;(function() {
  18844. var UETable = (UE.UETable = function(table) {
  18845. this.table = table;
  18846. this.indexTable = [];
  18847. this.selectedTds = [];
  18848. this.cellsRange = {};
  18849. this.update(table);
  18850. });
  18851. //===以下为静态工具方法===
  18852. UETable.removeSelectedClass = function(cells) {
  18853. utils.each(cells, function(cell) {
  18854. domUtils.removeClasses(cell, "selectTdClass");
  18855. });
  18856. };
  18857. UETable.addSelectedClass = function(cells) {
  18858. utils.each(cells, function(cell) {
  18859. domUtils.addClass(cell, "selectTdClass");
  18860. });
  18861. };
  18862. UETable.isEmptyBlock = function(node) {
  18863. var reg = new RegExp(domUtils.fillChar, "g");
  18864. if (
  18865. node[browser.ie ? "innerText" : "textContent"]
  18866. .replace(/^\s*$/, "")
  18867. .replace(reg, "").length > 0
  18868. ) {
  18869. return 0;
  18870. }
  18871. for (var i in dtd.$isNotEmpty)
  18872. if (dtd.$isNotEmpty.hasOwnProperty(i)) {
  18873. if (node.getElementsByTagName(i).length) {
  18874. return 0;
  18875. }
  18876. }
  18877. return 1;
  18878. };
  18879. UETable.getWidth = function(cell) {
  18880. if (!cell) return 0;
  18881. return parseInt(domUtils.getComputedStyle(cell, "width"), 10);
  18882. };
  18883. /**
  18884. * 获取单元格或者单元格组的“对齐”状态。 如果当前的检测对象是一个单元格组, 只有在满足所有单元格的 水平和竖直 对齐属性都相同的
  18885. * 条件时才会返回其状态值,否则将返回null; 如果当前只检测了一个单元格, 则直接返回当前单元格的对齐状态;
  18886. * @param table cell or table cells , 支持单个单元格dom对象 或者 单元格dom对象数组
  18887. * @return { align: 'left' || 'right' || 'center', valign: 'top' || 'middle' || 'bottom' } 或者 null
  18888. */
  18889. UETable.getTableCellAlignState = function(cells) {
  18890. !utils.isArray(cells) && (cells = [cells]);
  18891. var result = {},
  18892. status = ["align", "valign"],
  18893. tempStatus = null,
  18894. isSame = true; //状态是否相同
  18895. utils.each(cells, function(cellNode) {
  18896. utils.each(status, function(currentState) {
  18897. tempStatus = cellNode.getAttribute(currentState);
  18898. if (!result[currentState] && tempStatus) {
  18899. result[currentState] = tempStatus;
  18900. } else if (
  18901. !result[currentState] ||
  18902. tempStatus !== result[currentState]
  18903. ) {
  18904. isSame = false;
  18905. return false;
  18906. }
  18907. });
  18908. return isSame;
  18909. });
  18910. return isSame ? result : null;
  18911. };
  18912. /**
  18913. * 根据当前选区获取相关的table信息
  18914. * @return {Object}
  18915. */
  18916. UETable.getTableItemsByRange = function(editor) {
  18917. var start = editor.selection.getStart();
  18918. //ff下会选中bookmark
  18919. if (
  18920. start &&
  18921. start.id &&
  18922. start.id.indexOf("_baidu_bookmark_start_") === 0 &&
  18923. start.nextSibling
  18924. ) {
  18925. start = start.nextSibling;
  18926. }
  18927. //在table或者td边缘有可能存在选中tr的情况
  18928. var cell = start && domUtils.findParentByTagName(start, ["td", "th"], true),
  18929. tr = cell && cell.parentNode,
  18930. table = tr && domUtils.findParentByTagName(tr, ["table"]),
  18931. caption = table && table.getElementsByTagName("caption")[0];
  18932. return {
  18933. cell: cell,
  18934. tr: tr,
  18935. table: table,
  18936. caption: caption
  18937. };
  18938. };
  18939. UETable.getUETableBySelected = function(editor) {
  18940. var table = UETable.getTableItemsByRange(editor).table;
  18941. if (table && table.ueTable && table.ueTable.selectedTds.length) {
  18942. return table.ueTable;
  18943. }
  18944. return null;
  18945. };
  18946. UETable.getDefaultValue = function(editor, table) {
  18947. var borderMap = {
  18948. thin: "0px",
  18949. medium: "1px",
  18950. thick: "2px"
  18951. },
  18952. tableBorder,
  18953. tdPadding,
  18954. tdBorder,
  18955. tmpValue;
  18956. if (!table) {
  18957. table = editor.document.createElement("table");
  18958. table.insertRow(0).insertCell(0).innerHTML = "xxx";
  18959. editor.body.appendChild(table);
  18960. var td = table.getElementsByTagName("td")[0];
  18961. tmpValue = domUtils.getComputedStyle(table, "border-left-width");
  18962. tableBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  18963. tmpValue = domUtils.getComputedStyle(td, "padding-left");
  18964. tdPadding = parseInt(borderMap[tmpValue] || tmpValue, 10);
  18965. tmpValue = domUtils.getComputedStyle(td, "border-left-width");
  18966. tdBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  18967. domUtils.remove(table);
  18968. return {
  18969. tableBorder: tableBorder,
  18970. tdPadding: tdPadding,
  18971. tdBorder: tdBorder
  18972. };
  18973. } else {
  18974. td = table.getElementsByTagName("td")[0];
  18975. tmpValue = domUtils.getComputedStyle(table, "border-left-width");
  18976. tableBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  18977. tmpValue = domUtils.getComputedStyle(td, "padding-left");
  18978. tdPadding = parseInt(borderMap[tmpValue] || tmpValue, 10);
  18979. tmpValue = domUtils.getComputedStyle(td, "border-left-width");
  18980. tdBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  18981. return {
  18982. tableBorder: tableBorder,
  18983. tdPadding: tdPadding,
  18984. tdBorder: tdBorder
  18985. };
  18986. }
  18987. };
  18988. /**
  18989. * 根据当前点击的td或者table获取索引对象
  18990. * @param tdOrTable
  18991. */
  18992. UETable.getUETable = function(tdOrTable) {
  18993. var tag = tdOrTable.tagName.toLowerCase();
  18994. tdOrTable = tag == "td" || tag == "th" || tag == "caption"
  18995. ? domUtils.findParentByTagName(tdOrTable, "table", true)
  18996. : tdOrTable;
  18997. if (!tdOrTable.ueTable) {
  18998. tdOrTable.ueTable = new UETable(tdOrTable);
  18999. }
  19000. return tdOrTable.ueTable;
  19001. };
  19002. UETable.cloneCell = function(cell, ignoreMerge, keepPro) {
  19003. if (!cell || utils.isString(cell)) {
  19004. return this.table.ownerDocument.createElement(cell || "td");
  19005. }
  19006. var flag = domUtils.hasClass(cell, "selectTdClass");
  19007. flag && domUtils.removeClasses(cell, "selectTdClass");
  19008. var tmpCell = cell.cloneNode(true);
  19009. if (ignoreMerge) {
  19010. tmpCell.rowSpan = tmpCell.colSpan = 1;
  19011. }
  19012. //去掉宽高
  19013. !keepPro && domUtils.removeAttributes(tmpCell, "width height");
  19014. !keepPro && domUtils.removeAttributes(tmpCell, "style");
  19015. tmpCell.style.borderLeftStyle = "";
  19016. tmpCell.style.borderTopStyle = "";
  19017. tmpCell.style.borderLeftColor = cell.style.borderRightColor;
  19018. tmpCell.style.borderLeftWidth = cell.style.borderRightWidth;
  19019. tmpCell.style.borderTopColor = cell.style.borderBottomColor;
  19020. tmpCell.style.borderTopWidth = cell.style.borderBottomWidth;
  19021. flag && domUtils.addClass(cell, "selectTdClass");
  19022. return tmpCell;
  19023. };
  19024. UETable.prototype = {
  19025. getMaxRows: function() {
  19026. var rows = this.table.rows,
  19027. maxLen = 1;
  19028. for (var i = 0, row; (row = rows[i]); i++) {
  19029. var currentMax = 1;
  19030. for (var j = 0, cj; (cj = row.cells[j++]); ) {
  19031. currentMax = Math.max(cj.rowSpan || 1, currentMax);
  19032. }
  19033. maxLen = Math.max(currentMax + i, maxLen);
  19034. }
  19035. return maxLen;
  19036. },
  19037. /**
  19038. * 获取当前表格的最大列数
  19039. */
  19040. getMaxCols: function() {
  19041. var rows = this.table.rows,
  19042. maxLen = 0,
  19043. cellRows = {};
  19044. for (var i = 0, row; (row = rows[i]); i++) {
  19045. var cellsNum = 0;
  19046. for (var j = 0, cj; (cj = row.cells[j++]); ) {
  19047. cellsNum += cj.colSpan || 1;
  19048. if (cj.rowSpan && cj.rowSpan > 1) {
  19049. for (var k = 1; k < cj.rowSpan; k++) {
  19050. if (!cellRows["row_" + (i + k)]) {
  19051. cellRows["row_" + (i + k)] = cj.colSpan || 1;
  19052. } else {
  19053. cellRows["row_" + (i + k)]++;
  19054. }
  19055. }
  19056. }
  19057. }
  19058. cellsNum += cellRows["row_" + i] || 0;
  19059. maxLen = Math.max(cellsNum, maxLen);
  19060. }
  19061. return maxLen;
  19062. },
  19063. getCellColIndex: function(cell) {},
  19064. /**
  19065. * 获取当前cell旁边的单元格,
  19066. * @param cell
  19067. * @param right
  19068. */
  19069. getHSideCell: function(cell, right) {
  19070. try {
  19071. var cellInfo = this.getCellInfo(cell),
  19072. previewRowIndex,
  19073. previewColIndex;
  19074. var len = this.selectedTds.length,
  19075. range = this.cellsRange;
  19076. //首行或者首列没有前置单元格
  19077. if (
  19078. (!right && (!len ? !cellInfo.colIndex : !range.beginColIndex)) ||
  19079. (right &&
  19080. (!len
  19081. ? cellInfo.colIndex == this.colsNum - 1
  19082. : range.endColIndex == this.colsNum - 1))
  19083. )
  19084. return null;
  19085. previewRowIndex = !len ? cellInfo.rowIndex : range.beginRowIndex;
  19086. previewColIndex = !right
  19087. ? !len
  19088. ? cellInfo.colIndex < 1 ? 0 : cellInfo.colIndex - 1
  19089. : range.beginColIndex - 1
  19090. : !len ? cellInfo.colIndex + 1 : range.endColIndex + 1;
  19091. return this.getCell(
  19092. this.indexTable[previewRowIndex][previewColIndex].rowIndex,
  19093. this.indexTable[previewRowIndex][previewColIndex].cellIndex
  19094. );
  19095. } catch (e) {
  19096. showError(e);
  19097. }
  19098. },
  19099. getTabNextCell: function(cell, preRowIndex) {
  19100. var cellInfo = this.getCellInfo(cell),
  19101. rowIndex = preRowIndex || cellInfo.rowIndex,
  19102. colIndex = cellInfo.colIndex + 1 + (cellInfo.colSpan - 1),
  19103. nextCell;
  19104. try {
  19105. nextCell = this.getCell(
  19106. this.indexTable[rowIndex][colIndex].rowIndex,
  19107. this.indexTable[rowIndex][colIndex].cellIndex
  19108. );
  19109. } catch (e) {
  19110. try {
  19111. rowIndex = rowIndex * 1 + 1;
  19112. colIndex = 0;
  19113. nextCell = this.getCell(
  19114. this.indexTable[rowIndex][colIndex].rowIndex,
  19115. this.indexTable[rowIndex][colIndex].cellIndex
  19116. );
  19117. } catch (e) {}
  19118. }
  19119. return nextCell;
  19120. },
  19121. /**
  19122. * 获取视觉上的后置单元格
  19123. * @param cell
  19124. * @param bottom
  19125. */
  19126. getVSideCell: function(cell, bottom, ignoreRange) {
  19127. try {
  19128. var cellInfo = this.getCellInfo(cell),
  19129. nextRowIndex,
  19130. nextColIndex;
  19131. var len = this.selectedTds.length && !ignoreRange,
  19132. range = this.cellsRange;
  19133. //末行或者末列没有后置单元格
  19134. if (
  19135. (!bottom && cellInfo.rowIndex == 0) ||
  19136. (bottom &&
  19137. (!len
  19138. ? cellInfo.rowIndex + cellInfo.rowSpan > this.rowsNum - 1
  19139. : range.endRowIndex == this.rowsNum - 1))
  19140. )
  19141. return null;
  19142. nextRowIndex = !bottom
  19143. ? !len ? cellInfo.rowIndex - 1 : range.beginRowIndex - 1
  19144. : !len ? cellInfo.rowIndex + cellInfo.rowSpan : range.endRowIndex + 1;
  19145. nextColIndex = !len ? cellInfo.colIndex : range.beginColIndex;
  19146. return this.getCell(
  19147. this.indexTable[nextRowIndex][nextColIndex].rowIndex,
  19148. this.indexTable[nextRowIndex][nextColIndex].cellIndex
  19149. );
  19150. } catch (e) {
  19151. showError(e);
  19152. }
  19153. },
  19154. /**
  19155. * 获取相同结束位置的单元格,xOrY指代了是获取x轴相同还是y轴相同
  19156. */
  19157. getSameEndPosCells: function(cell, xOrY) {
  19158. try {
  19159. var flag = xOrY.toLowerCase() === "x",
  19160. end =
  19161. domUtils.getXY(cell)[flag ? "x" : "y"] +
  19162. cell["offset" + (flag ? "Width" : "Height")],
  19163. rows = this.table.rows,
  19164. cells = null,
  19165. returns = [];
  19166. for (var i = 0; i < this.rowsNum; i++) {
  19167. cells = rows[i].cells;
  19168. for (var j = 0, tmpCell; (tmpCell = cells[j++]); ) {
  19169. var tmpEnd =
  19170. domUtils.getXY(tmpCell)[flag ? "x" : "y"] +
  19171. tmpCell["offset" + (flag ? "Width" : "Height")];
  19172. //对应行的td已经被上面行rowSpan了
  19173. if (tmpEnd > end && flag) break;
  19174. if (cell == tmpCell || end == tmpEnd) {
  19175. //只获取单一的单元格
  19176. //todo 仅获取单一单元格在特定情况下会造成returns为空,从而影响后续的拖拽实现,修正这个。需考虑性能
  19177. if (tmpCell[flag ? "colSpan" : "rowSpan"] == 1) {
  19178. returns.push(tmpCell);
  19179. }
  19180. if (flag) break;
  19181. }
  19182. }
  19183. }
  19184. return returns;
  19185. } catch (e) {
  19186. showError(e);
  19187. }
  19188. },
  19189. setCellContent: function(cell, content) {
  19190. cell.innerHTML = content || (browser.ie ? domUtils.fillChar : "<br />");
  19191. },
  19192. cloneCell: UETable.cloneCell,
  19193. /**
  19194. * 获取跟当前单元格的右边竖线为左边的所有未合并单元格
  19195. */
  19196. getSameStartPosXCells: function(cell) {
  19197. try {
  19198. var start = domUtils.getXY(cell).x + cell.offsetWidth,
  19199. rows = this.table.rows,
  19200. cells,
  19201. returns = [];
  19202. for (var i = 0; i < this.rowsNum; i++) {
  19203. cells = rows[i].cells;
  19204. for (var j = 0, tmpCell; (tmpCell = cells[j++]); ) {
  19205. var tmpStart = domUtils.getXY(tmpCell).x;
  19206. if (tmpStart > start) break;
  19207. if (tmpStart == start && tmpCell.colSpan == 1) {
  19208. returns.push(tmpCell);
  19209. break;
  19210. }
  19211. }
  19212. }
  19213. return returns;
  19214. } catch (e) {
  19215. showError(e);
  19216. }
  19217. },
  19218. /**
  19219. * 更新table对应的索引表
  19220. */
  19221. update: function(table) {
  19222. this.table = table || this.table;
  19223. this.selectedTds = [];
  19224. this.cellsRange = {};
  19225. this.indexTable = [];
  19226. var rows = this.table.rows,
  19227. rowsNum = this.getMaxRows(),
  19228. dNum = rowsNum - rows.length,
  19229. colsNum = this.getMaxCols();
  19230. while (dNum--) {
  19231. this.table.insertRow(rows.length);
  19232. }
  19233. this.rowsNum = rowsNum;
  19234. this.colsNum = colsNum;
  19235. for (var i = 0, len = rows.length; i < len; i++) {
  19236. this.indexTable[i] = new Array(colsNum);
  19237. }
  19238. //填充索引表
  19239. for (var rowIndex = 0, row; (row = rows[rowIndex]); rowIndex++) {
  19240. for (
  19241. var cellIndex = 0, cell, cells = row.cells;
  19242. (cell = cells[cellIndex]);
  19243. cellIndex++
  19244. ) {
  19245. //修正整行被rowSpan时导致的行数计算错误
  19246. if (cell.rowSpan > rowsNum) {
  19247. cell.rowSpan = rowsNum;
  19248. }
  19249. var colIndex = cellIndex,
  19250. rowSpan = cell.rowSpan || 1,
  19251. colSpan = cell.colSpan || 1;
  19252. //当已经被上一行rowSpan或者被前一列colSpan了,则跳到下一个单元格进行
  19253. while (this.indexTable[rowIndex][colIndex]) colIndex++;
  19254. for (var j = 0; j < rowSpan; j++) {
  19255. for (var k = 0; k < colSpan; k++) {
  19256. this.indexTable[rowIndex + j][colIndex + k] = {
  19257. rowIndex: rowIndex,
  19258. cellIndex: cellIndex,
  19259. colIndex: colIndex,
  19260. rowSpan: rowSpan,
  19261. colSpan: colSpan
  19262. };
  19263. }
  19264. }
  19265. }
  19266. }
  19267. //修复残缺td
  19268. for (j = 0; j < rowsNum; j++) {
  19269. for (k = 0; k < colsNum; k++) {
  19270. if (this.indexTable[j][k] === undefined) {
  19271. row = rows[j];
  19272. cell = row.cells[row.cells.length - 1];
  19273. cell = cell
  19274. ? cell.cloneNode(true)
  19275. : this.table.ownerDocument.createElement("td");
  19276. this.setCellContent(cell);
  19277. if (cell.colSpan !== 1) cell.colSpan = 1;
  19278. if (cell.rowSpan !== 1) cell.rowSpan = 1;
  19279. row.appendChild(cell);
  19280. this.indexTable[j][k] = {
  19281. rowIndex: j,
  19282. cellIndex: cell.cellIndex,
  19283. colIndex: k,
  19284. rowSpan: 1,
  19285. colSpan: 1
  19286. };
  19287. }
  19288. }
  19289. }
  19290. //当框选后删除行或者列后撤销,需要重建选区。
  19291. var tds = domUtils.getElementsByTagName(this.table, "td"),
  19292. selectTds = [];
  19293. utils.each(tds, function(td) {
  19294. if (domUtils.hasClass(td, "selectTdClass")) {
  19295. selectTds.push(td);
  19296. }
  19297. });
  19298. if (selectTds.length) {
  19299. var start = selectTds[0],
  19300. end = selectTds[selectTds.length - 1],
  19301. startInfo = this.getCellInfo(start),
  19302. endInfo = this.getCellInfo(end);
  19303. this.selectedTds = selectTds;
  19304. this.cellsRange = {
  19305. beginRowIndex: startInfo.rowIndex,
  19306. beginColIndex: startInfo.colIndex,
  19307. endRowIndex: endInfo.rowIndex + endInfo.rowSpan - 1,
  19308. endColIndex: endInfo.colIndex + endInfo.colSpan - 1
  19309. };
  19310. }
  19311. //给第一行设置firstRow的样式名称,在排序图标的样式上使用到
  19312. if (!domUtils.hasClass(this.table.rows[0], "firstRow")) {
  19313. domUtils.addClass(this.table.rows[0], "firstRow");
  19314. for (var i = 1; i < this.table.rows.length; i++) {
  19315. domUtils.removeClasses(this.table.rows[i], "firstRow");
  19316. }
  19317. }
  19318. },
  19319. /**
  19320. * 获取单元格的索引信息
  19321. */
  19322. getCellInfo: function(cell) {
  19323. if (!cell) return;
  19324. var cellIndex = cell.cellIndex,
  19325. rowIndex = cell.parentNode.rowIndex,
  19326. rowInfo = this.indexTable[rowIndex],
  19327. numCols = this.colsNum;
  19328. for (var colIndex = cellIndex; colIndex < numCols; colIndex++) {
  19329. var cellInfo = rowInfo[colIndex];
  19330. if (
  19331. cellInfo.rowIndex === rowIndex &&
  19332. cellInfo.cellIndex === cellIndex
  19333. ) {
  19334. return cellInfo;
  19335. }
  19336. }
  19337. },
  19338. /**
  19339. * 根据行列号获取单元格
  19340. */
  19341. getCell: function(rowIndex, cellIndex) {
  19342. return (
  19343. (rowIndex < this.rowsNum &&
  19344. this.table.rows[rowIndex].cells[cellIndex]) ||
  19345. null
  19346. );
  19347. },
  19348. /**
  19349. * 删除单元格
  19350. */
  19351. deleteCell: function(cell, rowIndex) {
  19352. rowIndex = typeof rowIndex == "number"
  19353. ? rowIndex
  19354. : cell.parentNode.rowIndex;
  19355. var row = this.table.rows[rowIndex];
  19356. row.deleteCell(cell.cellIndex);
  19357. },
  19358. /**
  19359. * 根据始末两个单元格获取被框选的所有单元格范围
  19360. */
  19361. getCellsRange: function(cellA, cellB) {
  19362. function checkRange(
  19363. beginRowIndex,
  19364. beginColIndex,
  19365. endRowIndex,
  19366. endColIndex
  19367. ) {
  19368. var tmpBeginRowIndex = beginRowIndex,
  19369. tmpBeginColIndex = beginColIndex,
  19370. tmpEndRowIndex = endRowIndex,
  19371. tmpEndColIndex = endColIndex,
  19372. cellInfo,
  19373. colIndex,
  19374. rowIndex;
  19375. // 通过indexTable检查是否存在超出TableRange上边界的情况
  19376. if (beginRowIndex > 0) {
  19377. for (colIndex = beginColIndex; colIndex < endColIndex; colIndex++) {
  19378. cellInfo = me.indexTable[beginRowIndex][colIndex];
  19379. rowIndex = cellInfo.rowIndex;
  19380. if (rowIndex < beginRowIndex) {
  19381. tmpBeginRowIndex = Math.min(rowIndex, tmpBeginRowIndex);
  19382. }
  19383. }
  19384. }
  19385. // 通过indexTable检查是否存在超出TableRange右边界的情况
  19386. if (endColIndex < me.colsNum) {
  19387. for (rowIndex = beginRowIndex; rowIndex < endRowIndex; rowIndex++) {
  19388. cellInfo = me.indexTable[rowIndex][endColIndex];
  19389. colIndex = cellInfo.colIndex + cellInfo.colSpan - 1;
  19390. if (colIndex > endColIndex) {
  19391. tmpEndColIndex = Math.max(colIndex, tmpEndColIndex);
  19392. }
  19393. }
  19394. }
  19395. // 检查是否有超出TableRange下边界的情况
  19396. if (endRowIndex < me.rowsNum) {
  19397. for (colIndex = beginColIndex; colIndex < endColIndex; colIndex++) {
  19398. cellInfo = me.indexTable[endRowIndex][colIndex];
  19399. rowIndex = cellInfo.rowIndex + cellInfo.rowSpan - 1;
  19400. if (rowIndex > endRowIndex) {
  19401. tmpEndRowIndex = Math.max(rowIndex, tmpEndRowIndex);
  19402. }
  19403. }
  19404. }
  19405. // 检查是否有超出TableRange左边界的情况
  19406. if (beginColIndex > 0) {
  19407. for (rowIndex = beginRowIndex; rowIndex < endRowIndex; rowIndex++) {
  19408. cellInfo = me.indexTable[rowIndex][beginColIndex];
  19409. colIndex = cellInfo.colIndex;
  19410. if (colIndex < beginColIndex) {
  19411. tmpBeginColIndex = Math.min(cellInfo.colIndex, tmpBeginColIndex);
  19412. }
  19413. }
  19414. }
  19415. //递归调用直至所有完成所有框选单元格的扩展
  19416. if (
  19417. tmpBeginRowIndex != beginRowIndex ||
  19418. tmpBeginColIndex != beginColIndex ||
  19419. tmpEndRowIndex != endRowIndex ||
  19420. tmpEndColIndex != endColIndex
  19421. ) {
  19422. return checkRange(
  19423. tmpBeginRowIndex,
  19424. tmpBeginColIndex,
  19425. tmpEndRowIndex,
  19426. tmpEndColIndex
  19427. );
  19428. } else {
  19429. // 不需要扩展TableRange的情况
  19430. return {
  19431. beginRowIndex: beginRowIndex,
  19432. beginColIndex: beginColIndex,
  19433. endRowIndex: endRowIndex,
  19434. endColIndex: endColIndex
  19435. };
  19436. }
  19437. }
  19438. try {
  19439. var me = this,
  19440. cellAInfo = me.getCellInfo(cellA);
  19441. if (cellA === cellB) {
  19442. return {
  19443. beginRowIndex: cellAInfo.rowIndex,
  19444. beginColIndex: cellAInfo.colIndex,
  19445. endRowIndex: cellAInfo.rowIndex + cellAInfo.rowSpan - 1,
  19446. endColIndex: cellAInfo.colIndex + cellAInfo.colSpan - 1
  19447. };
  19448. }
  19449. var cellBInfo = me.getCellInfo(cellB);
  19450. // 计算TableRange的四个边
  19451. var beginRowIndex = Math.min(cellAInfo.rowIndex, cellBInfo.rowIndex),
  19452. beginColIndex = Math.min(cellAInfo.colIndex, cellBInfo.colIndex),
  19453. endRowIndex = Math.max(
  19454. cellAInfo.rowIndex + cellAInfo.rowSpan - 1,
  19455. cellBInfo.rowIndex + cellBInfo.rowSpan - 1
  19456. ),
  19457. endColIndex = Math.max(
  19458. cellAInfo.colIndex + cellAInfo.colSpan - 1,
  19459. cellBInfo.colIndex + cellBInfo.colSpan - 1
  19460. );
  19461. return checkRange(
  19462. beginRowIndex,
  19463. beginColIndex,
  19464. endRowIndex,
  19465. endColIndex
  19466. );
  19467. } catch (e) {
  19468. //throw e;
  19469. }
  19470. },
  19471. /**
  19472. * 依据cellsRange获取对应的单元格集合
  19473. */
  19474. getCells: function(range) {
  19475. //每次获取cells之前必须先清除上次的选择,否则会对后续获取操作造成影响
  19476. this.clearSelected();
  19477. var beginRowIndex = range.beginRowIndex,
  19478. beginColIndex = range.beginColIndex,
  19479. endRowIndex = range.endRowIndex,
  19480. endColIndex = range.endColIndex,
  19481. cellInfo,
  19482. rowIndex,
  19483. colIndex,
  19484. tdHash = {},
  19485. returnTds = [];
  19486. for (var i = beginRowIndex; i <= endRowIndex; i++) {
  19487. for (var j = beginColIndex; j <= endColIndex; j++) {
  19488. cellInfo = this.indexTable[i][j];
  19489. rowIndex = cellInfo.rowIndex;
  19490. colIndex = cellInfo.colIndex;
  19491. // 如果Cells里已经包含了此Cell则跳过
  19492. var key = rowIndex + "|" + colIndex;
  19493. if (tdHash[key]) continue;
  19494. tdHash[key] = 1;
  19495. if (
  19496. rowIndex < i ||
  19497. colIndex < j ||
  19498. rowIndex + cellInfo.rowSpan - 1 > endRowIndex ||
  19499. colIndex + cellInfo.colSpan - 1 > endColIndex
  19500. ) {
  19501. return null;
  19502. }
  19503. returnTds.push(this.getCell(rowIndex, cellInfo.cellIndex));
  19504. }
  19505. }
  19506. return returnTds;
  19507. },
  19508. /**
  19509. * 清理已经选中的单元格
  19510. */
  19511. clearSelected: function() {
  19512. UETable.removeSelectedClass(this.selectedTds);
  19513. this.selectedTds = [];
  19514. this.cellsRange = {};
  19515. },
  19516. /**
  19517. * 根据range设置已经选中的单元格
  19518. */
  19519. setSelected: function(range) {
  19520. var cells = this.getCells(range);
  19521. UETable.addSelectedClass(cells);
  19522. this.selectedTds = cells;
  19523. this.cellsRange = range;
  19524. },
  19525. isFullRow: function() {
  19526. var range = this.cellsRange;
  19527. return range.endColIndex - range.beginColIndex + 1 == this.colsNum;
  19528. },
  19529. isFullCol: function() {
  19530. var range = this.cellsRange,
  19531. table = this.table,
  19532. ths = table.getElementsByTagName("th"),
  19533. rows = range.endRowIndex - range.beginRowIndex + 1;
  19534. return !ths.length
  19535. ? rows == this.rowsNum
  19536. : rows == this.rowsNum || rows == this.rowsNum - 1;
  19537. },
  19538. /**
  19539. * 获取视觉上的前置单元格,默认是左边,top传入时
  19540. * @param cell
  19541. * @param top
  19542. */
  19543. getNextCell: function(cell, bottom, ignoreRange) {
  19544. try {
  19545. var cellInfo = this.getCellInfo(cell),
  19546. nextRowIndex,
  19547. nextColIndex;
  19548. var len = this.selectedTds.length && !ignoreRange,
  19549. range = this.cellsRange;
  19550. //末行或者末列没有后置单元格
  19551. if (
  19552. (!bottom && cellInfo.rowIndex == 0) ||
  19553. (bottom &&
  19554. (!len
  19555. ? cellInfo.rowIndex + cellInfo.rowSpan > this.rowsNum - 1
  19556. : range.endRowIndex == this.rowsNum - 1))
  19557. )
  19558. return null;
  19559. nextRowIndex = !bottom
  19560. ? !len ? cellInfo.rowIndex - 1 : range.beginRowIndex - 1
  19561. : !len ? cellInfo.rowIndex + cellInfo.rowSpan : range.endRowIndex + 1;
  19562. nextColIndex = !len ? cellInfo.colIndex : range.beginColIndex;
  19563. return this.getCell(
  19564. this.indexTable[nextRowIndex][nextColIndex].rowIndex,
  19565. this.indexTable[nextRowIndex][nextColIndex].cellIndex
  19566. );
  19567. } catch (e) {
  19568. showError(e);
  19569. }
  19570. },
  19571. getPreviewCell: function(cell, top) {
  19572. try {
  19573. var cellInfo = this.getCellInfo(cell),
  19574. previewRowIndex,
  19575. previewColIndex;
  19576. var len = this.selectedTds.length,
  19577. range = this.cellsRange;
  19578. //首行或者首列没有前置单元格
  19579. if (
  19580. (!top && (!len ? !cellInfo.colIndex : !range.beginColIndex)) ||
  19581. (top &&
  19582. (!len
  19583. ? cellInfo.rowIndex > this.colsNum - 1
  19584. : range.endColIndex == this.colsNum - 1))
  19585. )
  19586. return null;
  19587. previewRowIndex = !top
  19588. ? !len ? cellInfo.rowIndex : range.beginRowIndex
  19589. : !len
  19590. ? cellInfo.rowIndex < 1 ? 0 : cellInfo.rowIndex - 1
  19591. : range.beginRowIndex;
  19592. previewColIndex = !top
  19593. ? !len
  19594. ? cellInfo.colIndex < 1 ? 0 : cellInfo.colIndex - 1
  19595. : range.beginColIndex - 1
  19596. : !len ? cellInfo.colIndex : range.endColIndex + 1;
  19597. return this.getCell(
  19598. this.indexTable[previewRowIndex][previewColIndex].rowIndex,
  19599. this.indexTable[previewRowIndex][previewColIndex].cellIndex
  19600. );
  19601. } catch (e) {
  19602. showError(e);
  19603. }
  19604. },
  19605. /**
  19606. * 移动单元格中的内容
  19607. */
  19608. moveContent: function(cellTo, cellFrom) {
  19609. if (UETable.isEmptyBlock(cellFrom)) return;
  19610. if (UETable.isEmptyBlock(cellTo)) {
  19611. cellTo.innerHTML = cellFrom.innerHTML;
  19612. return;
  19613. }
  19614. var child = cellTo.lastChild;
  19615. if (child.nodeType == 3 || !dtd.$block[child.tagName]) {
  19616. cellTo.appendChild(cellTo.ownerDocument.createElement("br"));
  19617. }
  19618. while ((child = cellFrom.firstChild)) {
  19619. cellTo.appendChild(child);
  19620. }
  19621. },
  19622. /**
  19623. * 向右合并单元格
  19624. */
  19625. mergeRight: function(cell) {
  19626. var cellInfo = this.getCellInfo(cell),
  19627. rightColIndex = cellInfo.colIndex + cellInfo.colSpan,
  19628. rightCellInfo = this.indexTable[cellInfo.rowIndex][rightColIndex],
  19629. rightCell = this.getCell(
  19630. rightCellInfo.rowIndex,
  19631. rightCellInfo.cellIndex
  19632. );
  19633. //合并
  19634. cell.colSpan = cellInfo.colSpan + rightCellInfo.colSpan;
  19635. //被合并的单元格不应存在宽度属性
  19636. cell.removeAttribute("width");
  19637. //移动内容
  19638. this.moveContent(cell, rightCell);
  19639. //删掉被合并的Cell
  19640. this.deleteCell(rightCell, rightCellInfo.rowIndex);
  19641. this.update();
  19642. },
  19643. /**
  19644. * 向下合并单元格
  19645. */
  19646. mergeDown: function(cell) {
  19647. var cellInfo = this.getCellInfo(cell),
  19648. downRowIndex = cellInfo.rowIndex + cellInfo.rowSpan,
  19649. downCellInfo = this.indexTable[downRowIndex][cellInfo.colIndex],
  19650. downCell = this.getCell(downCellInfo.rowIndex, downCellInfo.cellIndex);
  19651. cell.rowSpan = cellInfo.rowSpan + downCellInfo.rowSpan;
  19652. cell.removeAttribute("height");
  19653. this.moveContent(cell, downCell);
  19654. this.deleteCell(downCell, downCellInfo.rowIndex);
  19655. this.update();
  19656. },
  19657. /**
  19658. * 合并整个range中的内容
  19659. */
  19660. mergeRange: function() {
  19661. //由于合并操作可以在任意时刻进行,所以无法通过鼠标位置等信息实时生成range,只能通过缓存实例中的cellsRange对象来访问
  19662. var range = this.cellsRange,
  19663. leftTopCell = this.getCell(
  19664. range.beginRowIndex,
  19665. this.indexTable[range.beginRowIndex][range.beginColIndex].cellIndex
  19666. );
  19667. // 这段关于行表头或者列表头的特殊处理会导致表头合并范围错误
  19668. // 为什么有这段代码的原因未明,暂且注释掉,希望原作者看到后出面说明下
  19669. // if (
  19670. // leftTopCell.tagName == "TH" &&
  19671. // range.endRowIndex !== range.beginRowIndex
  19672. // ) {
  19673. // var index = this.indexTable,
  19674. // info = this.getCellInfo(leftTopCell);
  19675. // leftTopCell = this.getCell(1, index[1][info.colIndex].cellIndex);
  19676. // range = this.getCellsRange(
  19677. // leftTopCell,
  19678. // this.getCell(
  19679. // index[this.rowsNum - 1][info.colIndex].rowIndex,
  19680. // index[this.rowsNum - 1][info.colIndex].cellIndex
  19681. // )
  19682. // );
  19683. // }
  19684. // 删除剩余的Cells
  19685. var cells = this.getCells(range);
  19686. for (var i = 0, ci; (ci = cells[i++]); ) {
  19687. if (ci !== leftTopCell) {
  19688. this.moveContent(leftTopCell, ci);
  19689. this.deleteCell(ci);
  19690. }
  19691. }
  19692. // 修改左上角Cell的rowSpan和colSpan,并调整宽度属性设置
  19693. leftTopCell.rowSpan = range.endRowIndex - range.beginRowIndex + 1;
  19694. leftTopCell.rowSpan > 1 && leftTopCell.removeAttribute("height");
  19695. leftTopCell.colSpan = range.endColIndex - range.beginColIndex + 1;
  19696. leftTopCell.colSpan > 1 && leftTopCell.removeAttribute("width");
  19697. if (leftTopCell.rowSpan == this.rowsNum && leftTopCell.colSpan != 1) {
  19698. leftTopCell.colSpan = 1;
  19699. }
  19700. if (leftTopCell.colSpan == this.colsNum && leftTopCell.rowSpan != 1) {
  19701. var rowIndex = leftTopCell.parentNode.rowIndex;
  19702. //解决IE下的表格操作问题
  19703. if (this.table.deleteRow) {
  19704. for (
  19705. var i = rowIndex + 1,
  19706. curIndex = rowIndex + 1,
  19707. len = leftTopCell.rowSpan;
  19708. i < len;
  19709. i++
  19710. ) {
  19711. this.table.deleteRow(curIndex);
  19712. }
  19713. } else {
  19714. for (var i = 0, len = leftTopCell.rowSpan - 1; i < len; i++) {
  19715. var row = this.table.rows[rowIndex + 1];
  19716. row.parentNode.removeChild(row);
  19717. }
  19718. }
  19719. leftTopCell.rowSpan = 1;
  19720. }
  19721. this.update();
  19722. },
  19723. /**
  19724. * 插入一行单元格
  19725. */
  19726. insertRow: function(rowIndex, sourceCell) {
  19727. var numCols = this.colsNum,
  19728. table = this.table,
  19729. row = table.insertRow(rowIndex),
  19730. cell,
  19731. thead = null,
  19732. isInsertTitle =
  19733. typeof sourceCell == "string" && sourceCell.toUpperCase() == "TH";
  19734. function replaceTdToTh(colIndex, cell, tableRow) {
  19735. if (colIndex == 0) {
  19736. var tr = tableRow.nextSibling || tableRow.previousSibling,
  19737. th = tr.cells[colIndex];
  19738. if (th.tagName == "TH") {
  19739. th = cell.ownerDocument.createElement("th");
  19740. th.appendChild(cell.firstChild);
  19741. tableRow.insertBefore(th, cell);
  19742. domUtils.remove(cell);
  19743. }
  19744. } else {
  19745. if (cell.tagName == "TH") {
  19746. var td = cell.ownerDocument.createElement("td");
  19747. td.appendChild(cell.firstChild);
  19748. tableRow.insertBefore(td, cell);
  19749. domUtils.remove(cell);
  19750. }
  19751. }
  19752. }
  19753. //首行直接插入,无需考虑部分单元格被rowspan的情况
  19754. if (rowIndex == 0 || rowIndex == this.rowsNum) {
  19755. for (var colIndex = 0; colIndex < numCols; colIndex++) {
  19756. cell = this.cloneCell(sourceCell, true);
  19757. this.setCellContent(cell);
  19758. cell.getAttribute("vAlign") &&
  19759. cell.setAttribute("vAlign", cell.getAttribute("vAlign"));
  19760. row.appendChild(cell);
  19761. if (!isInsertTitle) replaceTdToTh(colIndex, cell, row);
  19762. }
  19763. if (isInsertTitle) {
  19764. thead = table.createTHead();
  19765. thead.insertBefore(row, thead.firstChild);
  19766. }
  19767. } else {
  19768. var infoRow = this.indexTable[rowIndex],
  19769. cellIndex = 0;
  19770. for (colIndex = 0; colIndex < numCols; colIndex++) {
  19771. var cellInfo = infoRow[colIndex];
  19772. //如果存在某个单元格的rowspan穿过待插入行的位置,则修改该单元格的rowspan即可,无需插入单元格
  19773. if (cellInfo.rowIndex < rowIndex) {
  19774. cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  19775. cell.rowSpan = cellInfo.rowSpan + 1;
  19776. } else {
  19777. cell = this.cloneCell(sourceCell, true);
  19778. this.setCellContent(cell);
  19779. row.appendChild(cell);
  19780. }
  19781. if (!isInsertTitle) replaceTdToTh(colIndex, cell, row);
  19782. }
  19783. }
  19784. //框选时插入不触发contentchange,需要手动更新索引。
  19785. this.update();
  19786. return row;
  19787. },
  19788. /**
  19789. * 删除一行单元格
  19790. * @param rowIndex
  19791. */
  19792. deleteRow: function(rowIndex) {
  19793. var row = this.table.rows[rowIndex],
  19794. infoRow = this.indexTable[rowIndex],
  19795. colsNum = this.colsNum,
  19796. count = 0; //处理计数
  19797. for (var colIndex = 0; colIndex < colsNum; ) {
  19798. var cellInfo = infoRow[colIndex],
  19799. cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  19800. if (cell.rowSpan > 1) {
  19801. if (cellInfo.rowIndex == rowIndex) {
  19802. var clone = cell.cloneNode(true);
  19803. clone.rowSpan = cell.rowSpan - 1;
  19804. clone.innerHTML = "";
  19805. cell.rowSpan = 1;
  19806. var nextRowIndex = rowIndex + 1,
  19807. nextRow = this.table.rows[nextRowIndex],
  19808. insertCellIndex,
  19809. preMerged =
  19810. this.getPreviewMergedCellsNum(nextRowIndex, colIndex) - count;
  19811. if (preMerged < colIndex) {
  19812. insertCellIndex = colIndex - preMerged - 1;
  19813. //nextRow.insertCell(insertCellIndex);
  19814. domUtils.insertAfter(nextRow.cells[insertCellIndex], clone);
  19815. } else {
  19816. if (nextRow.cells.length)
  19817. nextRow.insertBefore(clone, nextRow.cells[0]);
  19818. }
  19819. count += 1;
  19820. //cell.parentNode.removeChild(cell);
  19821. }
  19822. }
  19823. colIndex += cell.colSpan || 1;
  19824. }
  19825. var deleteTds = [],
  19826. cacheMap = {};
  19827. for (colIndex = 0; colIndex < colsNum; colIndex++) {
  19828. var tmpRowIndex = infoRow[colIndex].rowIndex,
  19829. tmpCellIndex = infoRow[colIndex].cellIndex,
  19830. key = tmpRowIndex + "_" + tmpCellIndex;
  19831. if (cacheMap[key]) continue;
  19832. cacheMap[key] = 1;
  19833. cell = this.getCell(tmpRowIndex, tmpCellIndex);
  19834. deleteTds.push(cell);
  19835. }
  19836. var mergeTds = [];
  19837. utils.each(deleteTds, function(td) {
  19838. if (td.rowSpan == 1) {
  19839. td.parentNode.removeChild(td);
  19840. } else {
  19841. mergeTds.push(td);
  19842. }
  19843. });
  19844. utils.each(mergeTds, function(td) {
  19845. td.rowSpan--;
  19846. });
  19847. row.parentNode.removeChild(row);
  19848. //浏览器方法本身存在bug,采用自定义方法删除
  19849. //this.table.deleteRow(rowIndex);
  19850. this.update();
  19851. },
  19852. insertCol: function(colIndex, sourceCell, defaultValue) {
  19853. var rowsNum = this.rowsNum,
  19854. rowIndex = 0,
  19855. tableRow,
  19856. cell,
  19857. backWidth = parseInt(
  19858. (this.table.offsetWidth -
  19859. (this.colsNum + 1) * 20 -
  19860. (this.colsNum + 1)) /
  19861. (this.colsNum + 1),
  19862. 10
  19863. ),
  19864. isInsertTitleCol =
  19865. typeof sourceCell == "string" && sourceCell.toUpperCase() == "TH";
  19866. function replaceTdToTh(rowIndex, cell, tableRow) {
  19867. if (rowIndex == 0) {
  19868. var th = cell.nextSibling || cell.previousSibling;
  19869. if (th.tagName == "TH") {
  19870. th = cell.ownerDocument.createElement("th");
  19871. th.appendChild(cell.firstChild);
  19872. tableRow.insertBefore(th, cell);
  19873. domUtils.remove(cell);
  19874. }
  19875. } else {
  19876. if (cell.tagName == "TH") {
  19877. var td = cell.ownerDocument.createElement("td");
  19878. td.appendChild(cell.firstChild);
  19879. tableRow.insertBefore(td, cell);
  19880. domUtils.remove(cell);
  19881. }
  19882. }
  19883. }
  19884. var preCell;
  19885. if (colIndex == 0 || colIndex == this.colsNum) {
  19886. for (; rowIndex < rowsNum; rowIndex++) {
  19887. tableRow = this.table.rows[rowIndex];
  19888. preCell =
  19889. tableRow.cells[colIndex == 0 ? colIndex : tableRow.cells.length];
  19890. cell = this.cloneCell(sourceCell, true); //tableRow.insertCell(colIndex == 0 ? colIndex : tableRow.cells.length);
  19891. this.setCellContent(cell);
  19892. cell.setAttribute("vAlign", cell.getAttribute("vAlign"));
  19893. preCell && cell.setAttribute("width", preCell.getAttribute("width"));
  19894. if (!colIndex) {
  19895. tableRow.insertBefore(cell, tableRow.cells[0]);
  19896. } else {
  19897. domUtils.insertAfter(
  19898. tableRow.cells[tableRow.cells.length - 1],
  19899. cell
  19900. );
  19901. }
  19902. if (!isInsertTitleCol) replaceTdToTh(rowIndex, cell, tableRow);
  19903. }
  19904. } else {
  19905. for (; rowIndex < rowsNum; rowIndex++) {
  19906. var cellInfo = this.indexTable[rowIndex][colIndex];
  19907. if (cellInfo.colIndex < colIndex) {
  19908. cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  19909. cell.colSpan = cellInfo.colSpan + 1;
  19910. } else {
  19911. tableRow = this.table.rows[rowIndex];
  19912. preCell = tableRow.cells[cellInfo.cellIndex];
  19913. cell = this.cloneCell(sourceCell, true); //tableRow.insertCell(cellInfo.cellIndex);
  19914. this.setCellContent(cell);
  19915. cell.setAttribute("vAlign", cell.getAttribute("vAlign"));
  19916. preCell &&
  19917. cell.setAttribute("width", preCell.getAttribute("width"));
  19918. //防止IE下报错
  19919. preCell
  19920. ? tableRow.insertBefore(cell, preCell)
  19921. : tableRow.appendChild(cell);
  19922. }
  19923. if (!isInsertTitleCol) replaceTdToTh(rowIndex, cell, tableRow);
  19924. }
  19925. }
  19926. //框选时插入不触发contentchange,需要手动更新索引
  19927. this.update();
  19928. this.updateWidth(
  19929. backWidth,
  19930. defaultValue || { tdPadding: 10, tdBorder: 1 }
  19931. );
  19932. },
  19933. updateWidth: function(width, defaultValue) {
  19934. var table = this.table,
  19935. tmpWidth =
  19936. UETable.getWidth(table) -
  19937. defaultValue.tdPadding * 2 -
  19938. defaultValue.tdBorder +
  19939. width;
  19940. if (tmpWidth < table.ownerDocument.body.offsetWidth) {
  19941. table.setAttribute("width", tmpWidth);
  19942. return;
  19943. }
  19944. var tds = domUtils.getElementsByTagName(this.table, "td th");
  19945. utils.each(tds, function(td) {
  19946. td.setAttribute("width", width);
  19947. });
  19948. },
  19949. deleteCol: function(colIndex) {
  19950. var indexTable = this.indexTable,
  19951. tableRows = this.table.rows,
  19952. backTableWidth = this.table.getAttribute("width"),
  19953. backTdWidth = 0,
  19954. rowsNum = this.rowsNum,
  19955. cacheMap = {};
  19956. for (var rowIndex = 0; rowIndex < rowsNum; ) {
  19957. var infoRow = indexTable[rowIndex],
  19958. cellInfo = infoRow[colIndex],
  19959. key = cellInfo.rowIndex + "_" + cellInfo.colIndex;
  19960. // 跳过已经处理过的Cell
  19961. if (cacheMap[key]) continue;
  19962. cacheMap[key] = 1;
  19963. var cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  19964. if (!backTdWidth)
  19965. backTdWidth =
  19966. cell && parseInt(cell.offsetWidth / cell.colSpan, 10).toFixed(0);
  19967. // 如果Cell的colSpan大于1, 就修改colSpan, 否则就删掉这个Cell
  19968. if (cell.colSpan > 1) {
  19969. cell.colSpan--;
  19970. } else {
  19971. tableRows[rowIndex].deleteCell(cellInfo.cellIndex);
  19972. }
  19973. rowIndex += cellInfo.rowSpan || 1;
  19974. }
  19975. this.table.setAttribute("width", backTableWidth - backTdWidth);
  19976. this.update();
  19977. },
  19978. splitToCells: function(cell) {
  19979. var me = this,
  19980. cells = this.splitToRows(cell);
  19981. utils.each(cells, function(cell) {
  19982. me.splitToCols(cell);
  19983. });
  19984. },
  19985. splitToRows: function(cell) {
  19986. var cellInfo = this.getCellInfo(cell),
  19987. rowIndex = cellInfo.rowIndex,
  19988. colIndex = cellInfo.colIndex,
  19989. results = [];
  19990. // 修改Cell的rowSpan
  19991. cell.rowSpan = 1;
  19992. results.push(cell);
  19993. // 补齐单元格
  19994. for (
  19995. var i = rowIndex, endRow = rowIndex + cellInfo.rowSpan;
  19996. i < endRow;
  19997. i++
  19998. ) {
  19999. if (i == rowIndex) continue;
  20000. var tableRow = this.table.rows[i],
  20001. tmpCell = tableRow.insertCell(
  20002. colIndex - this.getPreviewMergedCellsNum(i, colIndex)
  20003. );
  20004. tmpCell.colSpan = cellInfo.colSpan;
  20005. this.setCellContent(tmpCell);
  20006. tmpCell.setAttribute("vAlign", cell.getAttribute("vAlign"));
  20007. tmpCell.setAttribute("align", cell.getAttribute("align"));
  20008. if (cell.style.cssText) {
  20009. tmpCell.style.cssText = cell.style.cssText;
  20010. }
  20011. results.push(tmpCell);
  20012. }
  20013. this.update();
  20014. return results;
  20015. },
  20016. getPreviewMergedCellsNum: function(rowIndex, colIndex) {
  20017. var indexRow = this.indexTable[rowIndex],
  20018. num = 0;
  20019. for (var i = 0; i < colIndex; ) {
  20020. var colSpan = indexRow[i].colSpan,
  20021. tmpRowIndex = indexRow[i].rowIndex;
  20022. num += colSpan - (tmpRowIndex == rowIndex ? 1 : 0);
  20023. i += colSpan;
  20024. }
  20025. return num;
  20026. },
  20027. splitToCols: function(cell) {
  20028. var backWidth = (cell.offsetWidth / cell.colSpan - 22).toFixed(0),
  20029. cellInfo = this.getCellInfo(cell),
  20030. rowIndex = cellInfo.rowIndex,
  20031. colIndex = cellInfo.colIndex,
  20032. results = [];
  20033. // 修改Cell的rowSpan
  20034. cell.colSpan = 1;
  20035. cell.setAttribute("width", backWidth);
  20036. results.push(cell);
  20037. // 补齐单元格
  20038. for (
  20039. var j = colIndex, endCol = colIndex + cellInfo.colSpan;
  20040. j < endCol;
  20041. j++
  20042. ) {
  20043. if (j == colIndex) continue;
  20044. var tableRow = this.table.rows[rowIndex],
  20045. tmpCell = tableRow.insertCell(
  20046. this.indexTable[rowIndex][j].cellIndex + 1
  20047. );
  20048. tmpCell.rowSpan = cellInfo.rowSpan;
  20049. this.setCellContent(tmpCell);
  20050. tmpCell.setAttribute("vAlign", cell.getAttribute("vAlign"));
  20051. tmpCell.setAttribute("align", cell.getAttribute("align"));
  20052. tmpCell.setAttribute("width", backWidth);
  20053. if (cell.style.cssText) {
  20054. tmpCell.style.cssText = cell.style.cssText;
  20055. }
  20056. //处理th的情况
  20057. if (cell.tagName == "TH") {
  20058. var th = cell.ownerDocument.createElement("th");
  20059. th.appendChild(tmpCell.firstChild);
  20060. th.setAttribute("vAlign", cell.getAttribute("vAlign"));
  20061. th.rowSpan = tmpCell.rowSpan;
  20062. tableRow.insertBefore(th, tmpCell);
  20063. domUtils.remove(tmpCell);
  20064. }
  20065. results.push(tmpCell);
  20066. }
  20067. this.update();
  20068. return results;
  20069. },
  20070. isLastCell: function(cell, rowsNum, colsNum) {
  20071. rowsNum = rowsNum || this.rowsNum;
  20072. colsNum = colsNum || this.colsNum;
  20073. var cellInfo = this.getCellInfo(cell);
  20074. return (
  20075. cellInfo.rowIndex + cellInfo.rowSpan == rowsNum &&
  20076. cellInfo.colIndex + cellInfo.colSpan == colsNum
  20077. );
  20078. },
  20079. getLastCell: function(cells) {
  20080. cells = cells || this.table.getElementsByTagName("td");
  20081. var firstInfo = this.getCellInfo(cells[0]);
  20082. var me = this,
  20083. last = cells[0],
  20084. tr = last.parentNode,
  20085. cellsNum = 0,
  20086. cols = 0,
  20087. rows;
  20088. utils.each(cells, function(cell) {
  20089. if (cell.parentNode == tr) cols += cell.colSpan || 1;
  20090. cellsNum += cell.rowSpan * cell.colSpan || 1;
  20091. });
  20092. rows = cellsNum / cols;
  20093. utils.each(cells, function(cell) {
  20094. if (me.isLastCell(cell, rows, cols)) {
  20095. last = cell;
  20096. return false;
  20097. }
  20098. });
  20099. return last;
  20100. },
  20101. selectRow: function(rowIndex) {
  20102. var indexRow = this.indexTable[rowIndex],
  20103. start = this.getCell(indexRow[0].rowIndex, indexRow[0].cellIndex),
  20104. end = this.getCell(
  20105. indexRow[this.colsNum - 1].rowIndex,
  20106. indexRow[this.colsNum - 1].cellIndex
  20107. ),
  20108. range = this.getCellsRange(start, end);
  20109. this.setSelected(range);
  20110. },
  20111. selectTable: function() {
  20112. var tds = this.table.getElementsByTagName("td"),
  20113. range = this.getCellsRange(tds[0], tds[tds.length - 1]);
  20114. this.setSelected(range);
  20115. },
  20116. setBackground: function(cells, value) {
  20117. if (typeof value === "string") {
  20118. utils.each(cells, function(cell) {
  20119. cell.style.backgroundColor = value;
  20120. });
  20121. } else if (typeof value === "object") {
  20122. value = utils.extend(
  20123. {
  20124. repeat: true,
  20125. colorList: ["#ddd", "#fff"]
  20126. },
  20127. value
  20128. );
  20129. var rowIndex = this.getCellInfo(cells[0]).rowIndex,
  20130. count = 0,
  20131. colors = value.colorList,
  20132. getColor = function(list, index, repeat) {
  20133. return list[index]
  20134. ? list[index]
  20135. : repeat ? list[index % list.length] : "";
  20136. };
  20137. for (var i = 0, cell; (cell = cells[i++]); ) {
  20138. var cellInfo = this.getCellInfo(cell);
  20139. cell.style.backgroundColor = getColor(
  20140. colors,
  20141. rowIndex + count == cellInfo.rowIndex ? count : ++count,
  20142. value.repeat
  20143. );
  20144. }
  20145. }
  20146. },
  20147. removeBackground: function(cells) {
  20148. utils.each(cells, function(cell) {
  20149. cell.style.backgroundColor = "";
  20150. });
  20151. }
  20152. };
  20153. function showError(e) {}
  20154. })();
  20155. // plugins/table.cmds.js
  20156. /**
  20157. * Created with JetBrains PhpStorm.
  20158. * User: taoqili
  20159. * Date: 13-2-20
  20160. * Time: 下午6:25
  20161. * To change this template use File | Settings | File Templates.
  20162. */
  20163. ;(function() {
  20164. var UT = UE.UETable,
  20165. getTableItemsByRange = function(editor) {
  20166. return UT.getTableItemsByRange(editor);
  20167. },
  20168. getUETableBySelected = function(editor) {
  20169. return UT.getUETableBySelected(editor);
  20170. },
  20171. getDefaultValue = function(editor, table) {
  20172. return UT.getDefaultValue(editor, table);
  20173. },
  20174. getUETable = function(tdOrTable) {
  20175. return UT.getUETable(tdOrTable);
  20176. };
  20177. UE.commands["inserttable"] = {
  20178. queryCommandState: function() {
  20179. return getTableItemsByRange(this).table ? -1 : 0;
  20180. },
  20181. execCommand: function(cmd, opt) {
  20182. function createTable(opt, tdWidth) {
  20183. var html = [],
  20184. rowsNum = opt.numRows,
  20185. colsNum = opt.numCols;
  20186. for (var r = 0; r < rowsNum; r++) {
  20187. html.push("<tr" + (r == 0 ? ' class="firstRow"' : "") + ">");
  20188. for (var c = 0; c < colsNum; c++) {
  20189. html.push(
  20190. '<td width="' +
  20191. tdWidth +
  20192. '" vAlign="' +
  20193. opt.tdvalign +
  20194. '" >' +
  20195. (browser.ie && browser.version < 11
  20196. ? domUtils.fillChar
  20197. : "<br/>") +
  20198. "</td>"
  20199. );
  20200. }
  20201. html.push("</tr>");
  20202. }
  20203. //禁止指定table-width
  20204. return "<table><tbody>" + html.join("") + "</tbody></table>";
  20205. }
  20206. if (!opt) {
  20207. opt = utils.extend(
  20208. {},
  20209. {
  20210. numCols: this.options.defaultCols,
  20211. numRows: this.options.defaultRows,
  20212. tdvalign: this.options.tdvalign
  20213. }
  20214. );
  20215. }
  20216. var me = this;
  20217. var range = this.selection.getRange(),
  20218. start = range.startContainer,
  20219. firstParentBlock =
  20220. domUtils.findParent(
  20221. start,
  20222. function(node) {
  20223. return domUtils.isBlockElm(node);
  20224. },
  20225. true
  20226. ) || me.body;
  20227. var defaultValue = getDefaultValue(me),
  20228. tableWidth = firstParentBlock.offsetWidth,
  20229. tdWidth = Math.floor(
  20230. tableWidth / opt.numCols -
  20231. defaultValue.tdPadding * 2 -
  20232. defaultValue.tdBorder
  20233. );
  20234. //todo其他属性
  20235. !opt.tdvalign && (opt.tdvalign = me.options.tdvalign);
  20236. me.execCommand("inserthtml", createTable(opt, tdWidth));
  20237. }
  20238. };
  20239. UE.commands["insertparagraphbeforetable"] = {
  20240. queryCommandState: function() {
  20241. return getTableItemsByRange(this).cell ? 0 : -1;
  20242. },
  20243. execCommand: function() {
  20244. var table = getTableItemsByRange(this).table;
  20245. if (table) {
  20246. var p = this.document.createElement("p");
  20247. p.innerHTML = browser.ie ? "&nbsp;" : "<br />";
  20248. table.parentNode.insertBefore(p, table);
  20249. this.selection.getRange().setStart(p, 0).setCursor();
  20250. }
  20251. }
  20252. };
  20253. UE.commands["deletetable"] = {
  20254. queryCommandState: function() {
  20255. var rng = this.selection.getRange();
  20256. return domUtils.findParentByTagName(rng.startContainer, "table", true)
  20257. ? 0
  20258. : -1;
  20259. },
  20260. execCommand: function(cmd, table) {
  20261. var rng = this.selection.getRange();
  20262. table =
  20263. table ||
  20264. domUtils.findParentByTagName(rng.startContainer, "table", true);
  20265. if (table) {
  20266. var next = table.nextSibling;
  20267. if (!next) {
  20268. next = domUtils.createElement(this.document, "p", {
  20269. innerHTML: browser.ie ? domUtils.fillChar : "<br/>"
  20270. });
  20271. table.parentNode.insertBefore(next, table);
  20272. }
  20273. domUtils.remove(table);
  20274. rng = this.selection.getRange();
  20275. if (next.nodeType == 3) {
  20276. rng.setStartBefore(next);
  20277. } else {
  20278. rng.setStart(next, 0);
  20279. }
  20280. rng.setCursor(false, true);
  20281. this.fireEvent("tablehasdeleted");
  20282. }
  20283. }
  20284. };
  20285. UE.commands["cellalign"] = {
  20286. queryCommandState: function() {
  20287. return getSelectedArr(this).length ? 0 : -1;
  20288. },
  20289. execCommand: function(cmd, align) {
  20290. var selectedTds = getSelectedArr(this);
  20291. if (selectedTds.length) {
  20292. for (var i = 0, ci; (ci = selectedTds[i++]); ) {
  20293. ci.setAttribute("align", align);
  20294. }
  20295. }
  20296. }
  20297. };
  20298. UE.commands["cellvalign"] = {
  20299. queryCommandState: function() {
  20300. return getSelectedArr(this).length ? 0 : -1;
  20301. },
  20302. execCommand: function(cmd, valign) {
  20303. var selectedTds = getSelectedArr(this);
  20304. if (selectedTds.length) {
  20305. for (var i = 0, ci; (ci = selectedTds[i++]); ) {
  20306. ci.setAttribute("vAlign", valign);
  20307. }
  20308. }
  20309. }
  20310. };
  20311. UE.commands["insertcaption"] = {
  20312. queryCommandState: function() {
  20313. var table = getTableItemsByRange(this).table;
  20314. if (table) {
  20315. return table.getElementsByTagName("caption").length == 0 ? 1 : -1;
  20316. }
  20317. return -1;
  20318. },
  20319. execCommand: function() {
  20320. var table = getTableItemsByRange(this).table;
  20321. if (table) {
  20322. var caption = this.document.createElement("caption");
  20323. caption.innerHTML = browser.ie ? domUtils.fillChar : "<br/>";
  20324. table.insertBefore(caption, table.firstChild);
  20325. var range = this.selection.getRange();
  20326. range.setStart(caption, 0).setCursor();
  20327. }
  20328. }
  20329. };
  20330. UE.commands["deletecaption"] = {
  20331. queryCommandState: function() {
  20332. var rng = this.selection.getRange(),
  20333. table = domUtils.findParentByTagName(rng.startContainer, "table");
  20334. if (table) {
  20335. return table.getElementsByTagName("caption").length == 0 ? -1 : 1;
  20336. }
  20337. return -1;
  20338. },
  20339. execCommand: function() {
  20340. var rng = this.selection.getRange(),
  20341. table = domUtils.findParentByTagName(rng.startContainer, "table");
  20342. if (table) {
  20343. domUtils.remove(table.getElementsByTagName("caption")[0]);
  20344. var range = this.selection.getRange();
  20345. range.setStart(table.rows[0].cells[0], 0).setCursor();
  20346. }
  20347. }
  20348. };
  20349. UE.commands["inserttitle"] = {
  20350. queryCommandState: function() {
  20351. var table = getTableItemsByRange(this).table;
  20352. if (table) {
  20353. var firstRow = table.rows[0];
  20354. return firstRow.cells[
  20355. firstRow.cells.length - 1
  20356. ].tagName.toLowerCase() != "th"
  20357. ? 0
  20358. : -1;
  20359. }
  20360. return -1;
  20361. },
  20362. execCommand: function() {
  20363. var table = getTableItemsByRange(this).table;
  20364. if (table) {
  20365. getUETable(table).insertRow(0, "th");
  20366. }
  20367. var th = table.getElementsByTagName("th")[0];
  20368. this.selection.getRange().setStart(th, 0).setCursor(false, true);
  20369. }
  20370. };
  20371. UE.commands["deletetitle"] = {
  20372. queryCommandState: function() {
  20373. var table = getTableItemsByRange(this).table;
  20374. if (table) {
  20375. var firstRow = table.rows[0];
  20376. return firstRow.cells[
  20377. firstRow.cells.length - 1
  20378. ].tagName.toLowerCase() == "th"
  20379. ? 0
  20380. : -1;
  20381. }
  20382. return -1;
  20383. },
  20384. execCommand: function() {
  20385. var table = getTableItemsByRange(this).table;
  20386. if (table) {
  20387. domUtils.remove(table.rows[0]);
  20388. }
  20389. var td = table.getElementsByTagName("td")[0];
  20390. this.selection.getRange().setStart(td, 0).setCursor(false, true);
  20391. }
  20392. };
  20393. UE.commands["inserttitlecol"] = {
  20394. queryCommandState: function() {
  20395. var table = getTableItemsByRange(this).table;
  20396. if (table) {
  20397. var lastRow = table.rows[table.rows.length - 1];
  20398. return lastRow.getElementsByTagName("th").length ? -1 : 0;
  20399. }
  20400. return -1;
  20401. },
  20402. execCommand: function(cmd) {
  20403. var table = getTableItemsByRange(this).table;
  20404. if (table) {
  20405. getUETable(table).insertCol(0, "th");
  20406. }
  20407. resetTdWidth(table, this);
  20408. var th = table.getElementsByTagName("th")[0];
  20409. this.selection.getRange().setStart(th, 0).setCursor(false, true);
  20410. }
  20411. };
  20412. UE.commands["deletetitlecol"] = {
  20413. queryCommandState: function() {
  20414. var table = getTableItemsByRange(this).table;
  20415. if (table) {
  20416. var lastRow = table.rows[table.rows.length - 1];
  20417. return lastRow.getElementsByTagName("th").length ? 0 : -1;
  20418. }
  20419. return -1;
  20420. },
  20421. execCommand: function() {
  20422. var table = getTableItemsByRange(this).table;
  20423. if (table) {
  20424. for (var i = 0; i < table.rows.length; i++) {
  20425. domUtils.remove(table.rows[i].children[0]);
  20426. }
  20427. }
  20428. resetTdWidth(table, this);
  20429. var td = table.getElementsByTagName("td")[0];
  20430. this.selection.getRange().setStart(td, 0).setCursor(false, true);
  20431. }
  20432. };
  20433. UE.commands["mergeright"] = {
  20434. queryCommandState: function(cmd) {
  20435. var tableItems = getTableItemsByRange(this),
  20436. table = tableItems.table,
  20437. cell = tableItems.cell;
  20438. if (!table || !cell) return -1;
  20439. var ut = getUETable(table);
  20440. if (ut.selectedTds.length) return -1;
  20441. var cellInfo = ut.getCellInfo(cell),
  20442. rightColIndex = cellInfo.colIndex + cellInfo.colSpan;
  20443. if (rightColIndex >= ut.colsNum) return -1; // 如果处于最右边则不能向右合并
  20444. var rightCellInfo = ut.indexTable[cellInfo.rowIndex][rightColIndex],
  20445. rightCell =
  20446. table.rows[rightCellInfo.rowIndex].cells[rightCellInfo.cellIndex];
  20447. if (!rightCell || cell.tagName != rightCell.tagName) return -1; // TH和TD不能相互合并
  20448. // 当且仅当两个Cell的开始列号和结束列号一致时能进行合并
  20449. return rightCellInfo.rowIndex == cellInfo.rowIndex &&
  20450. rightCellInfo.rowSpan == cellInfo.rowSpan
  20451. ? 0
  20452. : -1;
  20453. },
  20454. execCommand: function(cmd) {
  20455. var rng = this.selection.getRange(),
  20456. bk = rng.createBookmark(true);
  20457. var cell = getTableItemsByRange(this).cell,
  20458. ut = getUETable(cell);
  20459. ut.mergeRight(cell);
  20460. rng.moveToBookmark(bk).select();
  20461. }
  20462. };
  20463. UE.commands["mergedown"] = {
  20464. queryCommandState: function(cmd) {
  20465. var tableItems = getTableItemsByRange(this),
  20466. table = tableItems.table,
  20467. cell = tableItems.cell;
  20468. if (!table || !cell) return -1;
  20469. var ut = getUETable(table);
  20470. if (ut.selectedTds.length) return -1;
  20471. var cellInfo = ut.getCellInfo(cell),
  20472. downRowIndex = cellInfo.rowIndex + cellInfo.rowSpan;
  20473. if (downRowIndex >= ut.rowsNum) return -1; // 如果处于最下边则不能向下合并
  20474. var downCellInfo = ut.indexTable[downRowIndex][cellInfo.colIndex],
  20475. downCell =
  20476. table.rows[downCellInfo.rowIndex].cells[downCellInfo.cellIndex];
  20477. if (!downCell || cell.tagName != downCell.tagName) return -1; // TH和TD不能相互合并
  20478. // 当且仅当两个Cell的开始列号和结束列号一致时能进行合并
  20479. return downCellInfo.colIndex == cellInfo.colIndex &&
  20480. downCellInfo.colSpan == cellInfo.colSpan
  20481. ? 0
  20482. : -1;
  20483. },
  20484. execCommand: function() {
  20485. var rng = this.selection.getRange(),
  20486. bk = rng.createBookmark(true);
  20487. var cell = getTableItemsByRange(this).cell,
  20488. ut = getUETable(cell);
  20489. ut.mergeDown(cell);
  20490. rng.moveToBookmark(bk).select();
  20491. }
  20492. };
  20493. UE.commands["mergecells"] = {
  20494. queryCommandState: function() {
  20495. return getUETableBySelected(this) ? 0 : -1;
  20496. },
  20497. execCommand: function() {
  20498. var ut = getUETableBySelected(this);
  20499. if (ut && ut.selectedTds.length) {
  20500. var cell = ut.selectedTds[0];
  20501. ut.mergeRange();
  20502. var rng = this.selection.getRange();
  20503. if (domUtils.isEmptyBlock(cell)) {
  20504. rng.setStart(cell, 0).collapse(true);
  20505. } else {
  20506. rng.selectNodeContents(cell);
  20507. }
  20508. rng.select();
  20509. }
  20510. }
  20511. };
  20512. UE.commands["insertrow"] = {
  20513. queryCommandState: function() {
  20514. var tableItems = getTableItemsByRange(this),
  20515. cell = tableItems.cell;
  20516. return cell &&
  20517. (cell.tagName == "TD" ||
  20518. (cell.tagName == "TH" &&
  20519. tableItems.tr !== tableItems.table.rows[0])) &&
  20520. getUETable(tableItems.table).rowsNum < this.options.maxRowNum
  20521. ? 0
  20522. : -1;
  20523. },
  20524. execCommand: function() {
  20525. var rng = this.selection.getRange(),
  20526. bk = rng.createBookmark(true);
  20527. var tableItems = getTableItemsByRange(this),
  20528. cell = tableItems.cell,
  20529. table = tableItems.table,
  20530. ut = getUETable(table),
  20531. cellInfo = ut.getCellInfo(cell);
  20532. //ut.insertRow(!ut.selectedTds.length ? cellInfo.rowIndex:ut.cellsRange.beginRowIndex,'');
  20533. if (!ut.selectedTds.length) {
  20534. ut.insertRow(cellInfo.rowIndex, cell);
  20535. } else {
  20536. var range = ut.cellsRange;
  20537. for (
  20538. var i = 0, len = range.endRowIndex - range.beginRowIndex + 1;
  20539. i < len;
  20540. i++
  20541. ) {
  20542. ut.insertRow(range.beginRowIndex, cell);
  20543. }
  20544. }
  20545. rng.moveToBookmark(bk).select();
  20546. if (table.getAttribute("interlaced") === "enabled")
  20547. this.fireEvent("interlacetable", table);
  20548. }
  20549. };
  20550. //后插入行
  20551. UE.commands["insertrownext"] = {
  20552. queryCommandState: function() {
  20553. var tableItems = getTableItemsByRange(this),
  20554. cell = tableItems.cell;
  20555. return cell &&
  20556. cell.tagName == "TD" &&
  20557. getUETable(tableItems.table).rowsNum < this.options.maxRowNum
  20558. ? 0
  20559. : -1;
  20560. },
  20561. execCommand: function() {
  20562. var rng = this.selection.getRange(),
  20563. bk = rng.createBookmark(true);
  20564. var tableItems = getTableItemsByRange(this),
  20565. cell = tableItems.cell,
  20566. table = tableItems.table,
  20567. ut = getUETable(table),
  20568. cellInfo = ut.getCellInfo(cell);
  20569. //ut.insertRow(!ut.selectedTds.length? cellInfo.rowIndex + cellInfo.rowSpan : ut.cellsRange.endRowIndex + 1,'');
  20570. if (!ut.selectedTds.length) {
  20571. ut.insertRow(cellInfo.rowIndex + cellInfo.rowSpan, cell);
  20572. } else {
  20573. var range = ut.cellsRange;
  20574. for (
  20575. var i = 0, len = range.endRowIndex - range.beginRowIndex + 1;
  20576. i < len;
  20577. i++
  20578. ) {
  20579. ut.insertRow(range.endRowIndex + 1, cell);
  20580. }
  20581. }
  20582. rng.moveToBookmark(bk).select();
  20583. if (table.getAttribute("interlaced") === "enabled")
  20584. this.fireEvent("interlacetable", table);
  20585. }
  20586. };
  20587. UE.commands["deleterow"] = {
  20588. queryCommandState: function() {
  20589. var tableItems = getTableItemsByRange(this);
  20590. return tableItems.cell ? 0 : -1;
  20591. },
  20592. execCommand: function() {
  20593. var cell = getTableItemsByRange(this).cell,
  20594. ut = getUETable(cell),
  20595. cellsRange = ut.cellsRange,
  20596. cellInfo = ut.getCellInfo(cell),
  20597. preCell = ut.getVSideCell(cell),
  20598. nextCell = ut.getVSideCell(cell, true),
  20599. rng = this.selection.getRange();
  20600. if (utils.isEmptyObject(cellsRange)) {
  20601. ut.deleteRow(cellInfo.rowIndex);
  20602. } else {
  20603. for (
  20604. var i = cellsRange.beginRowIndex;
  20605. i < cellsRange.endRowIndex + 1;
  20606. i++
  20607. ) {
  20608. ut.deleteRow(cellsRange.beginRowIndex);
  20609. }
  20610. }
  20611. var table = ut.table;
  20612. if (!table.getElementsByTagName("td").length) {
  20613. var nextSibling = table.nextSibling;
  20614. domUtils.remove(table);
  20615. if (nextSibling) {
  20616. rng.setStart(nextSibling, 0).setCursor(false, true);
  20617. }
  20618. } else {
  20619. if (
  20620. cellInfo.rowSpan == 1 ||
  20621. cellInfo.rowSpan ==
  20622. cellsRange.endRowIndex - cellsRange.beginRowIndex + 1
  20623. ) {
  20624. if (nextCell || preCell)
  20625. rng.selectNodeContents(nextCell || preCell).setCursor(false, true);
  20626. } else {
  20627. var newCell = ut.getCell(
  20628. cellInfo.rowIndex,
  20629. ut.indexTable[cellInfo.rowIndex][cellInfo.colIndex].cellIndex
  20630. );
  20631. if (newCell) rng.selectNodeContents(newCell).setCursor(false, true);
  20632. }
  20633. }
  20634. if (table.getAttribute("interlaced") === "enabled")
  20635. this.fireEvent("interlacetable", table);
  20636. }
  20637. };
  20638. UE.commands["insertcol"] = {
  20639. queryCommandState: function(cmd) {
  20640. var tableItems = getTableItemsByRange(this),
  20641. cell = tableItems.cell;
  20642. return cell &&
  20643. (cell.tagName == "TD" ||
  20644. (cell.tagName == "TH" && cell !== tableItems.tr.cells[0])) &&
  20645. getUETable(tableItems.table).colsNum < this.options.maxColNum
  20646. ? 0
  20647. : -1;
  20648. },
  20649. execCommand: function(cmd) {
  20650. var rng = this.selection.getRange(),
  20651. bk = rng.createBookmark(true);
  20652. if (this.queryCommandState(cmd) == -1) return;
  20653. var cell = getTableItemsByRange(this).cell,
  20654. ut = getUETable(cell),
  20655. cellInfo = ut.getCellInfo(cell);
  20656. //ut.insertCol(!ut.selectedTds.length ? cellInfo.colIndex:ut.cellsRange.beginColIndex);
  20657. if (!ut.selectedTds.length) {
  20658. ut.insertCol(cellInfo.colIndex, cell);
  20659. } else {
  20660. var range = ut.cellsRange;
  20661. for (
  20662. var i = 0, len = range.endColIndex - range.beginColIndex + 1;
  20663. i < len;
  20664. i++
  20665. ) {
  20666. ut.insertCol(range.beginColIndex, cell);
  20667. }
  20668. }
  20669. rng.moveToBookmark(bk).select(true);
  20670. }
  20671. };
  20672. UE.commands["insertcolnext"] = {
  20673. queryCommandState: function() {
  20674. var tableItems = getTableItemsByRange(this),
  20675. cell = tableItems.cell;
  20676. return cell &&
  20677. getUETable(tableItems.table).colsNum < this.options.maxColNum
  20678. ? 0
  20679. : -1;
  20680. },
  20681. execCommand: function() {
  20682. var rng = this.selection.getRange(),
  20683. bk = rng.createBookmark(true);
  20684. var cell = getTableItemsByRange(this).cell,
  20685. ut = getUETable(cell),
  20686. cellInfo = ut.getCellInfo(cell);
  20687. //ut.insertCol(!ut.selectedTds.length ? cellInfo.colIndex + cellInfo.colSpan:ut.cellsRange.endColIndex +1);
  20688. if (!ut.selectedTds.length) {
  20689. ut.insertCol(cellInfo.colIndex + cellInfo.colSpan, cell);
  20690. } else {
  20691. var range = ut.cellsRange;
  20692. for (
  20693. var i = 0, len = range.endColIndex - range.beginColIndex + 1;
  20694. i < len;
  20695. i++
  20696. ) {
  20697. ut.insertCol(range.endColIndex + 1, cell);
  20698. }
  20699. }
  20700. rng.moveToBookmark(bk).select();
  20701. }
  20702. };
  20703. UE.commands["deletecol"] = {
  20704. queryCommandState: function() {
  20705. var tableItems = getTableItemsByRange(this);
  20706. return tableItems.cell ? 0 : -1;
  20707. },
  20708. execCommand: function() {
  20709. var cell = getTableItemsByRange(this).cell,
  20710. ut = getUETable(cell),
  20711. range = ut.cellsRange,
  20712. cellInfo = ut.getCellInfo(cell),
  20713. preCell = ut.getHSideCell(cell),
  20714. nextCell = ut.getHSideCell(cell, true);
  20715. if (utils.isEmptyObject(range)) {
  20716. ut.deleteCol(cellInfo.colIndex);
  20717. } else {
  20718. for (var i = range.beginColIndex; i < range.endColIndex + 1; i++) {
  20719. ut.deleteCol(range.beginColIndex);
  20720. }
  20721. }
  20722. var table = ut.table,
  20723. rng = this.selection.getRange();
  20724. if (!table.getElementsByTagName("td").length) {
  20725. var nextSibling = table.nextSibling;
  20726. domUtils.remove(table);
  20727. if (nextSibling) {
  20728. rng.setStart(nextSibling, 0).setCursor(false, true);
  20729. }
  20730. } else {
  20731. if (domUtils.inDoc(cell, this.document)) {
  20732. rng.setStart(cell, 0).setCursor(false, true);
  20733. } else {
  20734. if (nextCell && domUtils.inDoc(nextCell, this.document)) {
  20735. rng.selectNodeContents(nextCell).setCursor(false, true);
  20736. } else {
  20737. if (preCell && domUtils.inDoc(preCell, this.document)) {
  20738. rng.selectNodeContents(preCell).setCursor(true, true);
  20739. }
  20740. }
  20741. }
  20742. }
  20743. }
  20744. };
  20745. UE.commands["splittocells"] = {
  20746. queryCommandState: function() {
  20747. var tableItems = getTableItemsByRange(this),
  20748. cell = tableItems.cell;
  20749. if (!cell) return -1;
  20750. var ut = getUETable(tableItems.table);
  20751. if (ut.selectedTds.length > 0) return -1;
  20752. return cell && (cell.colSpan > 1 || cell.rowSpan > 1) ? 0 : -1;
  20753. },
  20754. execCommand: function() {
  20755. var rng = this.selection.getRange(),
  20756. bk = rng.createBookmark(true);
  20757. var cell = getTableItemsByRange(this).cell,
  20758. ut = getUETable(cell);
  20759. ut.splitToCells(cell);
  20760. rng.moveToBookmark(bk).select();
  20761. }
  20762. };
  20763. UE.commands["splittorows"] = {
  20764. queryCommandState: function() {
  20765. var tableItems = getTableItemsByRange(this),
  20766. cell = tableItems.cell;
  20767. if (!cell) return -1;
  20768. var ut = getUETable(tableItems.table);
  20769. if (ut.selectedTds.length > 0) return -1;
  20770. return cell && cell.rowSpan > 1 ? 0 : -1;
  20771. },
  20772. execCommand: function() {
  20773. var rng = this.selection.getRange(),
  20774. bk = rng.createBookmark(true);
  20775. var cell = getTableItemsByRange(this).cell,
  20776. ut = getUETable(cell);
  20777. ut.splitToRows(cell);
  20778. rng.moveToBookmark(bk).select();
  20779. }
  20780. };
  20781. UE.commands["splittocols"] = {
  20782. queryCommandState: function() {
  20783. var tableItems = getTableItemsByRange(this),
  20784. cell = tableItems.cell;
  20785. if (!cell) return -1;
  20786. var ut = getUETable(tableItems.table);
  20787. if (ut.selectedTds.length > 0) return -1;
  20788. return cell && cell.colSpan > 1 ? 0 : -1;
  20789. },
  20790. execCommand: function() {
  20791. var rng = this.selection.getRange(),
  20792. bk = rng.createBookmark(true);
  20793. var cell = getTableItemsByRange(this).cell,
  20794. ut = getUETable(cell);
  20795. ut.splitToCols(cell);
  20796. rng.moveToBookmark(bk).select();
  20797. }
  20798. };
  20799. UE.commands["adaptbytext"] = UE.commands["adaptbywindow"] = {
  20800. queryCommandState: function() {
  20801. return getTableItemsByRange(this).table ? 0 : -1;
  20802. },
  20803. execCommand: function(cmd) {
  20804. var tableItems = getTableItemsByRange(this),
  20805. table = tableItems.table;
  20806. if (table) {
  20807. if (cmd == "adaptbywindow") {
  20808. resetTdWidth(table, this);
  20809. } else {
  20810. var cells = domUtils.getElementsByTagName(table, "td th");
  20811. utils.each(cells, function(cell) {
  20812. cell.removeAttribute("width");
  20813. });
  20814. table.removeAttribute("width");
  20815. }
  20816. }
  20817. }
  20818. };
  20819. //平均分配各列
  20820. UE.commands["averagedistributecol"] = {
  20821. queryCommandState: function() {
  20822. var ut = getUETableBySelected(this);
  20823. if (!ut) return -1;
  20824. return ut.isFullRow() || ut.isFullCol() ? 0 : -1;
  20825. },
  20826. execCommand: function(cmd) {
  20827. var me = this,
  20828. ut = getUETableBySelected(me);
  20829. function getAverageWidth() {
  20830. var tb = ut.table,
  20831. averageWidth,
  20832. sumWidth = 0,
  20833. colsNum = 0,
  20834. tbAttr = getDefaultValue(me, tb);
  20835. if (ut.isFullRow()) {
  20836. sumWidth = tb.offsetWidth;
  20837. colsNum = ut.colsNum;
  20838. } else {
  20839. var begin = ut.cellsRange.beginColIndex,
  20840. end = ut.cellsRange.endColIndex,
  20841. node;
  20842. for (var i = begin; i <= end; ) {
  20843. node = ut.selectedTds[i];
  20844. sumWidth += node.offsetWidth;
  20845. i += node.colSpan;
  20846. colsNum += 1;
  20847. }
  20848. }
  20849. averageWidth =
  20850. Math.ceil(sumWidth / colsNum) -
  20851. tbAttr.tdBorder * 2 -
  20852. tbAttr.tdPadding * 2;
  20853. return averageWidth;
  20854. }
  20855. function setAverageWidth(averageWidth) {
  20856. utils.each(domUtils.getElementsByTagName(ut.table, "th"), function(
  20857. node
  20858. ) {
  20859. node.setAttribute("width", "");
  20860. });
  20861. var cells = ut.isFullRow()
  20862. ? domUtils.getElementsByTagName(ut.table, "td")
  20863. : ut.selectedTds;
  20864. utils.each(cells, function(node) {
  20865. if (node.colSpan == 1) {
  20866. node.setAttribute("width", averageWidth);
  20867. }
  20868. });
  20869. }
  20870. if (ut && ut.selectedTds.length) {
  20871. setAverageWidth(getAverageWidth());
  20872. }
  20873. }
  20874. };
  20875. //平均分配各行
  20876. UE.commands["averagedistributerow"] = {
  20877. queryCommandState: function() {
  20878. var ut = getUETableBySelected(this);
  20879. if (!ut) return -1;
  20880. if (ut.selectedTds && /th/gi.test(ut.selectedTds[0].tagName)) return -1;
  20881. return ut.isFullRow() || ut.isFullCol() ? 0 : -1;
  20882. },
  20883. execCommand: function(cmd) {
  20884. var me = this,
  20885. ut = getUETableBySelected(me);
  20886. function getAverageHeight() {
  20887. var averageHeight,
  20888. rowNum,
  20889. sumHeight = 0,
  20890. tb = ut.table,
  20891. tbAttr = getDefaultValue(me, tb),
  20892. tdpadding = parseInt(
  20893. domUtils.getComputedStyle(
  20894. tb.getElementsByTagName("td")[0],
  20895. "padding-top"
  20896. )
  20897. );
  20898. if (ut.isFullCol()) {
  20899. var captionArr = domUtils.getElementsByTagName(tb, "caption"),
  20900. thArr = domUtils.getElementsByTagName(tb, "th"),
  20901. captionHeight,
  20902. thHeight;
  20903. if (captionArr.length > 0) {
  20904. captionHeight = captionArr[0].offsetHeight;
  20905. }
  20906. if (thArr.length > 0) {
  20907. thHeight = thArr[0].offsetHeight;
  20908. }
  20909. sumHeight = tb.offsetHeight - (captionHeight || 0) - (thHeight || 0);
  20910. rowNum = thArr.length == 0 ? ut.rowsNum : ut.rowsNum - 1;
  20911. } else {
  20912. var begin = ut.cellsRange.beginRowIndex,
  20913. end = ut.cellsRange.endRowIndex,
  20914. count = 0,
  20915. trs = domUtils.getElementsByTagName(tb, "tr");
  20916. for (var i = begin; i <= end; i++) {
  20917. sumHeight += trs[i].offsetHeight;
  20918. count += 1;
  20919. }
  20920. rowNum = count;
  20921. }
  20922. //ie8下是混杂模式
  20923. if (browser.ie && browser.version < 9) {
  20924. averageHeight = Math.ceil(sumHeight / rowNum);
  20925. } else {
  20926. averageHeight =
  20927. Math.ceil(sumHeight / rowNum) - tbAttr.tdBorder * 2 - tdpadding * 2;
  20928. }
  20929. return averageHeight;
  20930. }
  20931. function setAverageHeight(averageHeight) {
  20932. var cells = ut.isFullCol()
  20933. ? domUtils.getElementsByTagName(ut.table, "td")
  20934. : ut.selectedTds;
  20935. utils.each(cells, function(node) {
  20936. if (node.rowSpan == 1) {
  20937. node.setAttribute("height", averageHeight);
  20938. }
  20939. });
  20940. }
  20941. if (ut && ut.selectedTds.length) {
  20942. setAverageHeight(getAverageHeight());
  20943. }
  20944. }
  20945. };
  20946. //单元格对齐方式
  20947. UE.commands["cellalignment"] = {
  20948. queryCommandState: function() {
  20949. return getTableItemsByRange(this).table ? 0 : -1;
  20950. },
  20951. execCommand: function(cmd, data) {
  20952. var me = this,
  20953. ut = getUETableBySelected(me);
  20954. if (!ut) {
  20955. var start = me.selection.getStart(),
  20956. cell =
  20957. start &&
  20958. domUtils.findParentByTagName(start, ["td", "th", "caption"], true);
  20959. if (!/caption/gi.test(cell.tagName)) {
  20960. domUtils.setAttributes(cell, data);
  20961. } else {
  20962. cell.style.textAlign = data.align;
  20963. cell.style.verticalAlign = data.vAlign;
  20964. }
  20965. me.selection.getRange().setCursor(true);
  20966. } else {
  20967. utils.each(ut.selectedTds, function(cell) {
  20968. domUtils.setAttributes(cell, data);
  20969. });
  20970. }
  20971. },
  20972. /**
  20973. * 查询当前点击的单元格的对齐状态, 如果当前已经选择了多个单元格, 则会返回所有单元格经过统一协调过后的状态
  20974. * @see UE.UETable.getTableCellAlignState
  20975. */
  20976. queryCommandValue: function(cmd) {
  20977. var activeMenuCell = getTableItemsByRange(this).cell;
  20978. if (!activeMenuCell) {
  20979. activeMenuCell = getSelectedArr(this)[0];
  20980. }
  20981. if (!activeMenuCell) {
  20982. return null;
  20983. } else {
  20984. //获取同时选中的其他单元格
  20985. var cells = UE.UETable.getUETable(activeMenuCell).selectedTds;
  20986. !cells.length && (cells = activeMenuCell);
  20987. return UE.UETable.getTableCellAlignState(cells);
  20988. }
  20989. }
  20990. };
  20991. //表格对齐方式
  20992. UE.commands["tablealignment"] = {
  20993. queryCommandState: function() {
  20994. if (browser.ie && browser.version < 8) {
  20995. return -1;
  20996. }
  20997. return getTableItemsByRange(this).table ? 0 : -1;
  20998. },
  20999. execCommand: function(cmd, value) {
  21000. var me = this,
  21001. start = me.selection.getStart(),
  21002. table = start && domUtils.findParentByTagName(start, ["table"], true);
  21003. if (table) {
  21004. table.setAttribute("align", value);
  21005. }
  21006. }
  21007. };
  21008. //表格属性
  21009. UE.commands["edittable"] = {
  21010. queryCommandState: function() {
  21011. return getTableItemsByRange(this).table ? 0 : -1;
  21012. },
  21013. execCommand: function(cmd, color) {
  21014. var rng = this.selection.getRange(),
  21015. table = domUtils.findParentByTagName(rng.startContainer, "table");
  21016. if (table) {
  21017. var arr = domUtils
  21018. .getElementsByTagName(table, "td")
  21019. .concat(
  21020. domUtils.getElementsByTagName(table, "th"),
  21021. domUtils.getElementsByTagName(table, "caption")
  21022. );
  21023. utils.each(arr, function(node) {
  21024. node.style.borderColor = color;
  21025. });
  21026. }
  21027. }
  21028. };
  21029. //单元格属性
  21030. UE.commands["edittd"] = {
  21031. queryCommandState: function() {
  21032. return getTableItemsByRange(this).table ? 0 : -1;
  21033. },
  21034. execCommand: function(cmd, bkColor) {
  21035. var me = this,
  21036. ut = getUETableBySelected(me);
  21037. if (!ut) {
  21038. var start = me.selection.getStart(),
  21039. cell =
  21040. start &&
  21041. domUtils.findParentByTagName(start, ["td", "th", "caption"], true);
  21042. if (cell) {
  21043. cell.style.backgroundColor = bkColor;
  21044. }
  21045. } else {
  21046. utils.each(ut.selectedTds, function(cell) {
  21047. cell.style.backgroundColor = bkColor;
  21048. });
  21049. }
  21050. }
  21051. };
  21052. UE.commands["settablebackground"] = {
  21053. queryCommandState: function() {
  21054. return getSelectedArr(this).length > 1 ? 0 : -1;
  21055. },
  21056. execCommand: function(cmd, value) {
  21057. var cells, ut;
  21058. cells = getSelectedArr(this);
  21059. ut = getUETable(cells[0]);
  21060. ut.setBackground(cells, value);
  21061. }
  21062. };
  21063. UE.commands["cleartablebackground"] = {
  21064. queryCommandState: function() {
  21065. var cells = getSelectedArr(this);
  21066. if (!cells.length) return -1;
  21067. for (var i = 0, cell; (cell = cells[i++]); ) {
  21068. if (cell.style.backgroundColor !== "") return 0;
  21069. }
  21070. return -1;
  21071. },
  21072. execCommand: function() {
  21073. var cells = getSelectedArr(this),
  21074. ut = getUETable(cells[0]);
  21075. ut.removeBackground(cells);
  21076. }
  21077. };
  21078. UE.commands["interlacetable"] = UE.commands["uninterlacetable"] = {
  21079. queryCommandState: function(cmd) {
  21080. var table = getTableItemsByRange(this).table;
  21081. if (!table) return -1;
  21082. var interlaced = table.getAttribute("interlaced");
  21083. if (cmd == "interlacetable") {
  21084. //TODO 待定
  21085. //是否需要待定,如果设置,则命令只能单次执行成功,但反射具备toggle效果;否则可以覆盖前次命令,但反射将不存在toggle效果
  21086. return interlaced === "enabled" ? -1 : 0;
  21087. } else {
  21088. return !interlaced || interlaced === "disabled" ? -1 : 0;
  21089. }
  21090. },
  21091. execCommand: function(cmd, classList) {
  21092. var table = getTableItemsByRange(this).table;
  21093. if (cmd == "interlacetable") {
  21094. table.setAttribute("interlaced", "enabled");
  21095. this.fireEvent("interlacetable", table, classList);
  21096. } else {
  21097. table.setAttribute("interlaced", "disabled");
  21098. this.fireEvent("uninterlacetable", table);
  21099. }
  21100. }
  21101. };
  21102. UE.commands["setbordervisible"] = {
  21103. queryCommandState: function(cmd) {
  21104. var table = getTableItemsByRange(this).table;
  21105. if (!table) return -1;
  21106. return 0;
  21107. },
  21108. execCommand: function() {
  21109. var table = getTableItemsByRange(this).table;
  21110. utils.each(domUtils.getElementsByTagName(table, "td"), function(td) {
  21111. td.style.borderWidth = "1px";
  21112. td.style.borderStyle = "solid";
  21113. });
  21114. }
  21115. };
  21116. function resetTdWidth(table, editor) {
  21117. var tds = domUtils.getElementsByTagName(table, "td th");
  21118. utils.each(tds, function(td) {
  21119. td.removeAttribute("width");
  21120. });
  21121. table.setAttribute(
  21122. "width",
  21123. getTableWidth(editor, true, getDefaultValue(editor, table))
  21124. );
  21125. var tdsWidths = [];
  21126. setTimeout(function() {
  21127. utils.each(tds, function(td) {
  21128. td.colSpan == 1 && tdsWidths.push(td.offsetWidth);
  21129. });
  21130. utils.each(tds, function(td, i) {
  21131. td.colSpan == 1 && td.setAttribute("width", tdsWidths[i] + "");
  21132. });
  21133. }, 0);
  21134. }
  21135. function getTableWidth(editor, needIEHack, defaultValue) {
  21136. var body = editor.body;
  21137. return (
  21138. body.offsetWidth -
  21139. (needIEHack
  21140. ? parseInt(domUtils.getComputedStyle(body, "margin-left"), 10) * 2
  21141. : 0) -
  21142. defaultValue.tableBorder * 2 -
  21143. (editor.options.offsetWidth || 0)
  21144. );
  21145. }
  21146. function getSelectedArr(editor) {
  21147. var cell = getTableItemsByRange(editor).cell;
  21148. if (cell) {
  21149. var ut = getUETable(cell);
  21150. return ut.selectedTds.length ? ut.selectedTds : [cell];
  21151. } else {
  21152. return [];
  21153. }
  21154. }
  21155. })();
  21156. // plugins/table.action.js
  21157. /**
  21158. * Created with JetBrains PhpStorm.
  21159. * User: taoqili
  21160. * Date: 12-10-12
  21161. * Time: 上午10:05
  21162. * To change this template use File | Settings | File Templates.
  21163. */
  21164. UE.plugins["table"] = function() {
  21165. var me = this,
  21166. tabTimer = null,
  21167. //拖动计时器
  21168. tableDragTimer = null,
  21169. //双击计时器
  21170. tableResizeTimer = null,
  21171. //单元格最小宽度
  21172. cellMinWidth = 5,
  21173. isInResizeBuffer = false,
  21174. //单元格边框大小
  21175. cellBorderWidth = 5,
  21176. //鼠标偏移距离
  21177. offsetOfTableCell = 10,
  21178. //记录在有限时间内的点击状态, 共有3个取值, 0, 1, 2。 0代表未初始化, 1代表单击了1次,2代表2次
  21179. singleClickState = 0,
  21180. userActionStatus = null,
  21181. //双击允许的时间范围
  21182. dblclickTime = 360,
  21183. UT = UE.UETable,
  21184. getUETable = function(tdOrTable) {
  21185. return UT.getUETable(tdOrTable);
  21186. },
  21187. getUETableBySelected = function(editor) {
  21188. return UT.getUETableBySelected(editor);
  21189. },
  21190. getDefaultValue = function(editor, table) {
  21191. return UT.getDefaultValue(editor, table);
  21192. },
  21193. removeSelectedClass = function(cells) {
  21194. return UT.removeSelectedClass(cells);
  21195. };
  21196. function showError(e) {
  21197. // throw e;
  21198. }
  21199. me.ready(function() {
  21200. var me = this;
  21201. var orgGetText = me.selection.getText;
  21202. me.selection.getText = function() {
  21203. var table = getUETableBySelected(me);
  21204. if (table) {
  21205. var str = "";
  21206. utils.each(table.selectedTds, function(td) {
  21207. str += td[browser.ie ? "innerText" : "textContent"];
  21208. });
  21209. return str;
  21210. } else {
  21211. return orgGetText.call(me.selection);
  21212. }
  21213. };
  21214. });
  21215. //处理拖动及框选相关方法
  21216. var startTd = null, //鼠标按下时的锚点td
  21217. currentTd = null, //当前鼠标经过时的td
  21218. onDrag = "", //指示当前拖动状态,其值可为"","h","v" ,分别表示未拖动状态,横向拖动状态,纵向拖动状态,用于鼠标移动过程中的判断
  21219. onBorder = false, //检测鼠标按下时是否处在单元格边缘位置
  21220. dragButton = null,
  21221. dragOver = false,
  21222. dragLine = null, //模拟的拖动线
  21223. dragTd = null; //发生拖动的目标td
  21224. var mousedown = false,
  21225. //todo 判断混乱模式
  21226. needIEHack = true;
  21227. me.setOpt({
  21228. maxColNum: 20,
  21229. maxRowNum: 100,
  21230. defaultCols: 5,
  21231. defaultRows: 5,
  21232. tdvalign: "top",
  21233. cursorpath: me.options.UEDITOR_HOME_URL + "themes/" + me.options.theme + "/images/cursor_",
  21234. tableDragable: false,
  21235. classList: [
  21236. "ue-table-interlace-color-single",
  21237. "ue-table-interlace-color-double"
  21238. ]
  21239. });
  21240. me.getUETable = getUETable;
  21241. var commands = {
  21242. deletetable: 1,
  21243. inserttable: 1,
  21244. cellvalign: 1,
  21245. insertcaption: 1,
  21246. deletecaption: 1,
  21247. inserttitle: 1,
  21248. deletetitle: 1,
  21249. mergeright: 1,
  21250. mergedown: 1,
  21251. mergecells: 1,
  21252. insertrow: 1,
  21253. insertrownext: 1,
  21254. deleterow: 1,
  21255. insertcol: 1,
  21256. insertcolnext: 1,
  21257. deletecol: 1,
  21258. splittocells: 1,
  21259. splittorows: 1,
  21260. splittocols: 1,
  21261. adaptbytext: 1,
  21262. adaptbywindow: 1,
  21263. adaptbycustomer: 1,
  21264. insertparagraph: 1,
  21265. insertparagraphbeforetable: 1,
  21266. averagedistributecol: 1,
  21267. averagedistributerow: 1
  21268. };
  21269. me.ready(function() {
  21270. utils.cssRule(
  21271. "table",
  21272. //选中的td上的样式
  21273. ".selectTdClass{background-color:#edf5fa !important}" +
  21274. "table.noBorderTable td,table.noBorderTable th,table.noBorderTable caption{border:1px dashed #ddd !important}" +
  21275. //插入的表格的默认样式
  21276. "table{margin-bottom:10px;border-collapse:collapse;display:table;}" +
  21277. "td,th{padding: 5px 10px;border: 1px solid #DDD;}" +
  21278. "caption{border:1px dashed #DDD;border-bottom:0;padding:3px;text-align:center;}" +
  21279. "th{border-top:1px solid #BBB;background-color:#F7F7F7;}" +
  21280. "table tr.firstRow th{border-top-width:2px;}" +
  21281. ".ue-table-interlace-color-single{ background-color: #fcfcfc; } .ue-table-interlace-color-double{ background-color: #f7faff; }" +
  21282. "td p{margin:0;padding:0;}",
  21283. me.document
  21284. );
  21285. var tableCopyList, isFullCol, isFullRow;
  21286. //注册del/backspace事件
  21287. me.addListener("keydown", function(cmd, evt) {
  21288. var me = this;
  21289. var keyCode = evt.keyCode || evt.which;
  21290. if (keyCode == 8) {
  21291. var ut = getUETableBySelected(me);
  21292. if (ut && ut.selectedTds.length) {
  21293. if (ut.isFullCol()) {
  21294. me.execCommand("deletecol");
  21295. } else if (ut.isFullRow()) {
  21296. me.execCommand("deleterow");
  21297. } else {
  21298. me.fireEvent("delcells");
  21299. }
  21300. domUtils.preventDefault(evt);
  21301. }
  21302. var caption = domUtils.findParentByTagName(
  21303. me.selection.getStart(),
  21304. "caption",
  21305. true
  21306. ),
  21307. range = me.selection.getRange();
  21308. if (range.collapsed && caption && isEmptyBlock(caption)) {
  21309. me.fireEvent("saveScene");
  21310. var table = caption.parentNode;
  21311. domUtils.remove(caption);
  21312. if (table) {
  21313. range.setStart(table.rows[0].cells[0], 0).setCursor(false, true);
  21314. }
  21315. me.fireEvent("saveScene");
  21316. }
  21317. }
  21318. if (keyCode == 46) {
  21319. ut = getUETableBySelected(me);
  21320. if (ut) {
  21321. me.fireEvent("saveScene");
  21322. for (var i = 0, ci; (ci = ut.selectedTds[i++]); ) {
  21323. domUtils.fillNode(me.document, ci);
  21324. }
  21325. me.fireEvent("saveScene");
  21326. domUtils.preventDefault(evt);
  21327. }
  21328. }
  21329. if (keyCode == 13) {
  21330. var rng = me.selection.getRange(),
  21331. caption = domUtils.findParentByTagName(
  21332. rng.startContainer,
  21333. "caption",
  21334. true
  21335. );
  21336. if (caption) {
  21337. var table = domUtils.findParentByTagName(caption, "table");
  21338. if (!rng.collapsed) {
  21339. rng.deleteContents();
  21340. me.fireEvent("saveScene");
  21341. } else {
  21342. if (caption) {
  21343. rng.setStart(table.rows[0].cells[0], 0).setCursor(false, true);
  21344. }
  21345. }
  21346. domUtils.preventDefault(evt);
  21347. return;
  21348. }
  21349. if (rng.collapsed) {
  21350. var table = domUtils.findParentByTagName(rng.startContainer, "table");
  21351. if (table) {
  21352. var cell = table.rows[0].cells[0],
  21353. start = domUtils.findParentByTagName(
  21354. me.selection.getStart(),
  21355. ["td", "th"],
  21356. true
  21357. ),
  21358. preNode = table.previousSibling;
  21359. if (
  21360. cell === start &&
  21361. (!preNode ||
  21362. (preNode.nodeType == 1 && preNode.tagName == "TABLE")) &&
  21363. domUtils.isStartInblock(rng)
  21364. ) {
  21365. var first = domUtils.findParent(
  21366. me.selection.getStart(),
  21367. function(n) {
  21368. return domUtils.isBlockElm(n);
  21369. },
  21370. true
  21371. );
  21372. if (
  21373. first &&
  21374. (/t(h|d)/i.test(first.tagName) || first === start.firstChild)
  21375. ) {
  21376. me.execCommand("insertparagraphbeforetable");
  21377. domUtils.preventDefault(evt);
  21378. }
  21379. }
  21380. }
  21381. }
  21382. }
  21383. if ((evt.ctrlKey || evt.metaKey) && evt.keyCode == "67") {
  21384. tableCopyList = null;
  21385. var ut = getUETableBySelected(me);
  21386. if (ut) {
  21387. var tds = ut.selectedTds;
  21388. isFullCol = ut.isFullCol();
  21389. isFullRow = ut.isFullRow();
  21390. tableCopyList = [[ut.cloneCell(tds[0], null, true)]];
  21391. for (var i = 1, ci; (ci = tds[i]); i++) {
  21392. if (ci.parentNode !== tds[i - 1].parentNode) {
  21393. tableCopyList.push([ut.cloneCell(ci, null, true)]);
  21394. } else {
  21395. tableCopyList[tableCopyList.length - 1].push(
  21396. ut.cloneCell(ci, null, true)
  21397. );
  21398. }
  21399. }
  21400. }
  21401. }
  21402. });
  21403. me.addListener("tablehasdeleted", function() {
  21404. toggleDraggableState(this, false, "", null);
  21405. if (dragButton) domUtils.remove(dragButton);
  21406. });
  21407. me.addListener("beforepaste", function(cmd, html) {
  21408. var me = this;
  21409. var rng = me.selection.getRange();
  21410. if (domUtils.findParentByTagName(rng.startContainer, "caption", true)) {
  21411. var div = me.document.createElement("div");
  21412. div.innerHTML = html.html;
  21413. //trace:3729
  21414. html.html = div[browser.ie9below ? "innerText" : "textContent"];
  21415. return;
  21416. }
  21417. var table = getUETableBySelected(me);
  21418. if (tableCopyList) {
  21419. me.fireEvent("saveScene");
  21420. var rng = me.selection.getRange();
  21421. var td = domUtils.findParentByTagName(
  21422. rng.startContainer,
  21423. ["td", "th"],
  21424. true
  21425. ),
  21426. tmpNode,
  21427. preNode;
  21428. if (td) {
  21429. var ut = getUETable(td);
  21430. if (isFullRow) {
  21431. var rowIndex = ut.getCellInfo(td).rowIndex;
  21432. if (td.tagName == "TH") {
  21433. rowIndex++;
  21434. }
  21435. for (var i = 0, ci; (ci = tableCopyList[i++]); ) {
  21436. var tr = ut.insertRow(rowIndex++, "td");
  21437. for (var j = 0, cj; (cj = ci[j]); j++) {
  21438. var cell = tr.cells[j];
  21439. if (!cell) {
  21440. cell = tr.insertCell(j);
  21441. }
  21442. cell.innerHTML = cj.innerHTML;
  21443. cj.getAttribute("width") &&
  21444. cell.setAttribute("width", cj.getAttribute("width"));
  21445. cj.getAttribute("vAlign") &&
  21446. cell.setAttribute("vAlign", cj.getAttribute("vAlign"));
  21447. cj.getAttribute("align") &&
  21448. cell.setAttribute("align", cj.getAttribute("align"));
  21449. cj.style.cssText && (cell.style.cssText = cj.style.cssText);
  21450. }
  21451. for (var j = 0, cj; (cj = tr.cells[j]); j++) {
  21452. if (!ci[j]) break;
  21453. cj.innerHTML = ci[j].innerHTML;
  21454. ci[j].getAttribute("width") &&
  21455. cj.setAttribute("width", ci[j].getAttribute("width"));
  21456. ci[j].getAttribute("vAlign") &&
  21457. cj.setAttribute("vAlign", ci[j].getAttribute("vAlign"));
  21458. ci[j].getAttribute("align") &&
  21459. cj.setAttribute("align", ci[j].getAttribute("align"));
  21460. ci[j].style.cssText && (cj.style.cssText = ci[j].style.cssText);
  21461. }
  21462. }
  21463. } else {
  21464. if (isFullCol) {
  21465. cellInfo = ut.getCellInfo(td);
  21466. var maxColNum = 0;
  21467. for (var j = 0, ci = tableCopyList[0], cj; (cj = ci[j++]); ) {
  21468. maxColNum += cj.colSpan || 1;
  21469. }
  21470. me.__hasEnterExecCommand = true;
  21471. for (i = 0; i < maxColNum; i++) {
  21472. me.execCommand("insertcol");
  21473. }
  21474. me.__hasEnterExecCommand = false;
  21475. td = ut.table.rows[0].cells[cellInfo.cellIndex];
  21476. if (td.tagName == "TH") {
  21477. td = ut.table.rows[1].cells[cellInfo.cellIndex];
  21478. }
  21479. }
  21480. for (var i = 0, ci; (ci = tableCopyList[i++]); ) {
  21481. tmpNode = td;
  21482. for (var j = 0, cj; (cj = ci[j++]); ) {
  21483. if (td) {
  21484. td.innerHTML = cj.innerHTML;
  21485. //todo 定制处理
  21486. cj.getAttribute("width") &&
  21487. td.setAttribute("width", cj.getAttribute("width"));
  21488. cj.getAttribute("vAlign") &&
  21489. td.setAttribute("vAlign", cj.getAttribute("vAlign"));
  21490. cj.getAttribute("align") &&
  21491. td.setAttribute("align", cj.getAttribute("align"));
  21492. cj.style.cssText && (td.style.cssText = cj.style.cssText);
  21493. preNode = td;
  21494. td = td.nextSibling;
  21495. } else {
  21496. var cloneTd = cj.cloneNode(true);
  21497. domUtils.removeAttributes(cloneTd, [
  21498. "class",
  21499. "rowSpan",
  21500. "colSpan"
  21501. ]);
  21502. preNode.parentNode.appendChild(cloneTd);
  21503. }
  21504. }
  21505. td = ut.getNextCell(tmpNode, true, true);
  21506. if (!tableCopyList[i]) break;
  21507. if (!td) {
  21508. var cellInfo = ut.getCellInfo(tmpNode);
  21509. ut.table.insertRow(ut.table.rows.length);
  21510. ut.update();
  21511. td = ut.getVSideCell(tmpNode, true);
  21512. }
  21513. }
  21514. }
  21515. ut.update();
  21516. } else {
  21517. table = me.document.createElement("table");
  21518. for (var i = 0, ci; (ci = tableCopyList[i++]); ) {
  21519. var tr = table.insertRow(table.rows.length);
  21520. for (var j = 0, cj; (cj = ci[j++]); ) {
  21521. cloneTd = UT.cloneCell(cj, null, true);
  21522. domUtils.removeAttributes(cloneTd, ["class"]);
  21523. tr.appendChild(cloneTd);
  21524. }
  21525. if (j == 2 && cloneTd.rowSpan > 1) {
  21526. cloneTd.rowSpan = 1;
  21527. }
  21528. }
  21529. var defaultValue = getDefaultValue(me),
  21530. width =
  21531. me.body.offsetWidth -
  21532. (needIEHack
  21533. ? parseInt(
  21534. domUtils.getComputedStyle(me.body, "margin-left"),
  21535. 10
  21536. ) * 2
  21537. : 0) -
  21538. defaultValue.tableBorder * 2 -
  21539. (me.options.offsetWidth || 0);
  21540. me.execCommand(
  21541. "insertHTML",
  21542. "<table " +
  21543. (isFullCol && isFullRow ? 'width="' + width + '"' : "") +
  21544. ">" +
  21545. table.innerHTML
  21546. .replace(/>\s*</g, "><")
  21547. .replace(/\bth\b/gi, "td") +
  21548. "</table>"
  21549. );
  21550. }
  21551. me.fireEvent("contentchange");
  21552. me.fireEvent("saveScene");
  21553. html.html = "";
  21554. return true;
  21555. } else {
  21556. var div = me.document.createElement("div"),
  21557. tables;
  21558. div.innerHTML = html.html;
  21559. tables = div.getElementsByTagName("table");
  21560. if (domUtils.findParentByTagName(me.selection.getStart(), "table")) {
  21561. utils.each(tables, function(t) {
  21562. domUtils.remove(t);
  21563. });
  21564. if (
  21565. domUtils.findParentByTagName(
  21566. me.selection.getStart(),
  21567. "caption",
  21568. true
  21569. )
  21570. ) {
  21571. div.innerHTML = div[browser.ie ? "innerText" : "textContent"];
  21572. }
  21573. } else {
  21574. utils.each(tables, function(table) {
  21575. removeStyleSize(table, true);
  21576. domUtils.removeAttributes(table, ["style", "border"]);
  21577. utils.each(domUtils.getElementsByTagName(table, "td"), function(
  21578. td
  21579. ) {
  21580. if (isEmptyBlock(td)) {
  21581. domUtils.fillNode(me.document, td);
  21582. }
  21583. removeStyleSize(td, true);
  21584. // domUtils.removeAttributes(td, ['style'])
  21585. });
  21586. });
  21587. }
  21588. html.html = div.innerHTML;
  21589. }
  21590. });
  21591. me.addListener("afterpaste", function() {
  21592. utils.each(domUtils.getElementsByTagName(me.body, "table"), function(
  21593. table
  21594. ) {
  21595. if (table.offsetWidth > me.body.offsetWidth) {
  21596. var defaultValue = getDefaultValue(me, table);
  21597. table.style.width =
  21598. me.body.offsetWidth -
  21599. (needIEHack
  21600. ? parseInt(
  21601. domUtils.getComputedStyle(me.body, "margin-left"),
  21602. 10
  21603. ) * 2
  21604. : 0) -
  21605. defaultValue.tableBorder * 2 -
  21606. (me.options.offsetWidth || 0) +
  21607. "px";
  21608. }
  21609. });
  21610. });
  21611. me.addListener("blur", function() {
  21612. tableCopyList = null;
  21613. });
  21614. var timer;
  21615. me.addListener("keydown", function() {
  21616. clearTimeout(timer);
  21617. timer = setTimeout(function() {
  21618. var rng = me.selection.getRange(),
  21619. cell = domUtils.findParentByTagName(
  21620. rng.startContainer,
  21621. ["th", "td"],
  21622. true
  21623. );
  21624. if (cell) {
  21625. var table = cell.parentNode.parentNode.parentNode;
  21626. if (table.offsetWidth > table.getAttribute("width")) {
  21627. cell.style.wordBreak = "break-all";
  21628. }
  21629. }
  21630. }, 100);
  21631. });
  21632. me.addListener("selectionchange", function() {
  21633. toggleDraggableState(me, false, "", null);
  21634. });
  21635. //内容变化时触发索引更新
  21636. //todo 可否考虑标记检测,如果不涉及表格的变化就不进行索引重建和更新
  21637. me.addListener("contentchange", function() {
  21638. var me = this;
  21639. //尽可能排除一些不需要更新的状况
  21640. hideDragLine(me);
  21641. if (getUETableBySelected(me)) return;
  21642. var rng = me.selection.getRange();
  21643. var start = rng.startContainer;
  21644. start = domUtils.findParentByTagName(start, ["td", "th"], true);
  21645. utils.each(domUtils.getElementsByTagName(me.document, "table"), function(
  21646. table
  21647. ) {
  21648. if (me.fireEvent("excludetable", table) === true) return;
  21649. table.ueTable = new UT(table);
  21650. //trace:3742
  21651. // utils.each(domUtils.getElementsByTagName(me.document, 'td'), function (td) {
  21652. //
  21653. // if (domUtils.isEmptyBlock(td) && td !== start) {
  21654. // domUtils.fillNode(me.document, td);
  21655. // if (browser.ie && browser.version == 6) {
  21656. // td.innerHTML = '&nbsp;'
  21657. // }
  21658. // }
  21659. // });
  21660. // utils.each(domUtils.getElementsByTagName(me.document, 'th'), function (th) {
  21661. // if (domUtils.isEmptyBlock(th) && th !== start) {
  21662. // domUtils.fillNode(me.document, th);
  21663. // if (browser.ie && browser.version == 6) {
  21664. // th.innerHTML = '&nbsp;'
  21665. // }
  21666. // }
  21667. // });
  21668. table.onmouseover = function() {
  21669. me.fireEvent("tablemouseover", table);
  21670. };
  21671. table.onmousemove = function() {
  21672. me.fireEvent("tablemousemove", table);
  21673. me.options.tableDragable && toggleDragButton(true, this, me);
  21674. utils.defer(function() {
  21675. me.fireEvent("contentchange", 50);
  21676. }, true);
  21677. };
  21678. table.onmouseout = function() {
  21679. me.fireEvent("tablemouseout", table);
  21680. toggleDraggableState(me, false, "", null);
  21681. hideDragLine(me);
  21682. };
  21683. table.onclick = function(evt) {
  21684. evt = me.window.event || evt;
  21685. var target = getParentTdOrTh(evt.target || evt.srcElement);
  21686. if (!target) return;
  21687. var ut = getUETable(target),
  21688. table = ut.table,
  21689. cellInfo = ut.getCellInfo(target),
  21690. cellsRange,
  21691. rng = me.selection.getRange();
  21692. // if ("topLeft" == inPosition(table, mouseCoords(evt))) {
  21693. // cellsRange = ut.getCellsRange(ut.table.rows[0].cells[0], ut.getLastCell());
  21694. // ut.setSelected(cellsRange);
  21695. // return;
  21696. // }
  21697. // if ("bottomRight" == inPosition(table, mouseCoords(evt))) {
  21698. //
  21699. // return;
  21700. // }
  21701. if (inTableSide(table, target, evt, true)) {
  21702. var endTdCol = ut.getCell(
  21703. ut.indexTable[ut.rowsNum - 1][cellInfo.colIndex].rowIndex,
  21704. ut.indexTable[ut.rowsNum - 1][cellInfo.colIndex].cellIndex
  21705. );
  21706. if (evt.shiftKey && ut.selectedTds.length) {
  21707. if (ut.selectedTds[0] !== endTdCol) {
  21708. cellsRange = ut.getCellsRange(ut.selectedTds[0], endTdCol);
  21709. ut.setSelected(cellsRange);
  21710. } else {
  21711. rng && rng.selectNodeContents(endTdCol).select();
  21712. }
  21713. } else {
  21714. if (target !== endTdCol) {
  21715. cellsRange = ut.getCellsRange(target, endTdCol);
  21716. ut.setSelected(cellsRange);
  21717. } else {
  21718. rng && rng.selectNodeContents(endTdCol).select();
  21719. }
  21720. }
  21721. return;
  21722. }
  21723. if (inTableSide(table, target, evt)) {
  21724. var endTdRow = ut.getCell(
  21725. ut.indexTable[cellInfo.rowIndex][ut.colsNum - 1].rowIndex,
  21726. ut.indexTable[cellInfo.rowIndex][ut.colsNum - 1].cellIndex
  21727. );
  21728. if (evt.shiftKey && ut.selectedTds.length) {
  21729. if (ut.selectedTds[0] !== endTdRow) {
  21730. cellsRange = ut.getCellsRange(ut.selectedTds[0], endTdRow);
  21731. ut.setSelected(cellsRange);
  21732. } else {
  21733. rng && rng.selectNodeContents(endTdRow).select();
  21734. }
  21735. } else {
  21736. if (target !== endTdRow) {
  21737. cellsRange = ut.getCellsRange(target, endTdRow);
  21738. ut.setSelected(cellsRange);
  21739. } else {
  21740. rng && rng.selectNodeContents(endTdRow).select();
  21741. }
  21742. }
  21743. }
  21744. };
  21745. });
  21746. switchBorderColor(me, true);
  21747. });
  21748. domUtils.on(me.document, "mousemove", mouseMoveEvent);
  21749. domUtils.on(me.document, "mouseout", function(evt) {
  21750. var target = evt.target || evt.srcElement;
  21751. if (target.tagName == "TABLE") {
  21752. toggleDraggableState(me, false, "", null);
  21753. }
  21754. });
  21755. /**
  21756. * 表格隔行变色
  21757. */
  21758. me.addListener("interlacetable", function(type, table, classList) {
  21759. if (!table) return;
  21760. var me = this,
  21761. rows = table.rows,
  21762. len = rows.length,
  21763. getClass = function(list, index, repeat) {
  21764. return list[index]
  21765. ? list[index]
  21766. : repeat ? list[index % list.length] : "";
  21767. };
  21768. for (var i = 0; i < len; i++) {
  21769. rows[i].className = getClass(
  21770. classList || me.options.classList,
  21771. i,
  21772. true
  21773. );
  21774. }
  21775. });
  21776. me.addListener("uninterlacetable", function(type, table) {
  21777. if (!table) return;
  21778. var me = this,
  21779. rows = table.rows,
  21780. classList = me.options.classList,
  21781. len = rows.length;
  21782. for (var i = 0; i < len; i++) {
  21783. domUtils.removeClasses(rows[i], classList);
  21784. }
  21785. });
  21786. me.addListener("mousedown", mouseDownEvent);
  21787. me.addListener("mouseup", mouseUpEvent);
  21788. //拖动的时候触发mouseup
  21789. domUtils.on(me.body, "dragstart", function(evt) {
  21790. mouseUpEvent.call(me, "dragstart", evt);
  21791. });
  21792. me.addOutputRule(function(root) {
  21793. utils.each(root.getNodesByTagName("div"), function(n) {
  21794. if (n.getAttr("id") == "ue_tableDragLine") {
  21795. n.parentNode.removeChild(n);
  21796. }
  21797. });
  21798. });
  21799. var currentRowIndex = 0;
  21800. me.addListener("mousedown", function() {
  21801. currentRowIndex = 0;
  21802. });
  21803. me.addListener("tabkeydown", function() {
  21804. var range = this.selection.getRange(),
  21805. common = range.getCommonAncestor(true, true),
  21806. table = domUtils.findParentByTagName(common, "table");
  21807. if (table) {
  21808. if (domUtils.findParentByTagName(common, "caption", true)) {
  21809. var cell = domUtils.getElementsByTagName(table, "th td");
  21810. if (cell && cell.length) {
  21811. range.setStart(cell[0], 0).setCursor(false, true);
  21812. }
  21813. } else {
  21814. var cell = domUtils.findParentByTagName(common, ["td", "th"], true),
  21815. ua = getUETable(cell);
  21816. currentRowIndex = cell.rowSpan > 1
  21817. ? currentRowIndex
  21818. : ua.getCellInfo(cell).rowIndex;
  21819. var nextCell = ua.getTabNextCell(cell, currentRowIndex);
  21820. if (nextCell) {
  21821. if (isEmptyBlock(nextCell)) {
  21822. range.setStart(nextCell, 0).setCursor(false, true);
  21823. } else {
  21824. range.selectNodeContents(nextCell).select();
  21825. }
  21826. } else {
  21827. me.fireEvent("saveScene");
  21828. me.__hasEnterExecCommand = true;
  21829. this.execCommand("insertrownext");
  21830. me.__hasEnterExecCommand = false;
  21831. range = this.selection.getRange();
  21832. range
  21833. .setStart(table.rows[table.rows.length - 1].cells[0], 0)
  21834. .setCursor();
  21835. me.fireEvent("saveScene");
  21836. }
  21837. }
  21838. return true;
  21839. }
  21840. });
  21841. browser.ie &&
  21842. me.addListener("selectionchange", function() {
  21843. toggleDraggableState(this, false, "", null);
  21844. });
  21845. me.addListener("keydown", function(type, evt) {
  21846. var me = this;
  21847. //处理在表格的最后一个输入tab产生新的表格
  21848. var keyCode = evt.keyCode || evt.which;
  21849. if (keyCode == 8 || keyCode == 46) {
  21850. return;
  21851. }
  21852. var notCtrlKey =
  21853. !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey;
  21854. notCtrlKey &&
  21855. removeSelectedClass(domUtils.getElementsByTagName(me.body, "td"));
  21856. var ut = getUETableBySelected(me);
  21857. if (!ut) return;
  21858. notCtrlKey && ut.clearSelected();
  21859. });
  21860. me.addListener("beforegetcontent", function() {
  21861. switchBorderColor(this, false);
  21862. browser.ie &&
  21863. utils.each(this.document.getElementsByTagName("caption"), function(ci) {
  21864. if (domUtils.isEmptyNode(ci)) {
  21865. ci.innerHTML = "&nbsp;";
  21866. }
  21867. });
  21868. });
  21869. me.addListener("aftergetcontent", function() {
  21870. switchBorderColor(this, true);
  21871. });
  21872. me.addListener("getAllHtml", function() {
  21873. removeSelectedClass(me.document.getElementsByTagName("td"));
  21874. });
  21875. //修正全屏状态下插入的表格宽度在非全屏状态下撑开编辑器的情况
  21876. me.addListener("fullscreenchanged", function(type, fullscreen) {
  21877. if (!fullscreen) {
  21878. var ratio = this.body.offsetWidth / document.body.offsetWidth,
  21879. tables = domUtils.getElementsByTagName(this.body, "table");
  21880. utils.each(tables, function(table) {
  21881. if (table.offsetWidth < me.body.offsetWidth) return false;
  21882. var tds = domUtils.getElementsByTagName(table, "td"),
  21883. backWidths = [];
  21884. utils.each(tds, function(td) {
  21885. backWidths.push(td.offsetWidth);
  21886. });
  21887. for (var i = 0, td; (td = tds[i]); i++) {
  21888. td.setAttribute("width", Math.floor(backWidths[i] * ratio));
  21889. }
  21890. table.setAttribute(
  21891. "width",
  21892. Math.floor(getTableWidth(me, needIEHack, getDefaultValue(me)))
  21893. );
  21894. });
  21895. }
  21896. });
  21897. //重写execCommand命令,用于处理框选时的处理
  21898. var oldExecCommand = me.execCommand;
  21899. me.execCommand = function(cmd, datatat) {
  21900. var me = this,
  21901. args = arguments;
  21902. cmd = cmd.toLowerCase();
  21903. var ut = getUETableBySelected(me),
  21904. tds,
  21905. range = new dom.Range(me.document),
  21906. cmdFun = me.commands[cmd] || UE.commands[cmd],
  21907. result;
  21908. if (!cmdFun) return;
  21909. if (
  21910. ut &&
  21911. !commands[cmd] &&
  21912. !cmdFun.notNeedUndo &&
  21913. !me.__hasEnterExecCommand
  21914. ) {
  21915. me.__hasEnterExecCommand = true;
  21916. me.fireEvent("beforeexeccommand", cmd);
  21917. tds = ut.selectedTds;
  21918. var lastState = -2,
  21919. lastValue = -2,
  21920. value,
  21921. state;
  21922. for (var i = 0, td; (td = tds[i]); i++) {
  21923. if (isEmptyBlock(td)) {
  21924. range.setStart(td, 0).setCursor(false, true);
  21925. } else {
  21926. range.selectNode(td).select(true);
  21927. }
  21928. state = me.queryCommandState(cmd);
  21929. value = me.queryCommandValue(cmd);
  21930. if (state != -1) {
  21931. if (lastState !== state || lastValue !== value) {
  21932. me._ignoreContentChange = true;
  21933. result = oldExecCommand.apply(me, arguments);
  21934. me._ignoreContentChange = false;
  21935. }
  21936. lastState = me.queryCommandState(cmd);
  21937. lastValue = me.queryCommandValue(cmd);
  21938. if (domUtils.isEmptyBlock(td)) {
  21939. domUtils.fillNode(me.document, td);
  21940. }
  21941. }
  21942. }
  21943. range.setStart(tds[0], 0).shrinkBoundary(true).setCursor(false, true);
  21944. me.fireEvent("contentchange");
  21945. me.fireEvent("afterexeccommand", cmd);
  21946. me.__hasEnterExecCommand = false;
  21947. me._selectionChange();
  21948. } else {
  21949. result = oldExecCommand.apply(me, arguments);
  21950. }
  21951. return result;
  21952. };
  21953. });
  21954. /**
  21955. * 删除obj的宽高style,改成属性宽高
  21956. * @param obj
  21957. * @param replaceToProperty
  21958. */
  21959. function removeStyleSize(obj, replaceToProperty) {
  21960. removeStyle(obj, "width", true);
  21961. removeStyle(obj, "height", true);
  21962. }
  21963. function removeStyle(obj, styleName, replaceToProperty) {
  21964. if (obj.style[styleName]) {
  21965. replaceToProperty &&
  21966. obj.setAttribute(styleName, parseInt(obj.style[styleName], 10));
  21967. obj.style[styleName] = "";
  21968. }
  21969. }
  21970. function getParentTdOrTh(ele) {
  21971. if (ele.tagName == "TD" || ele.tagName == "TH") return ele;
  21972. var td;
  21973. if (
  21974. (td =
  21975. domUtils.findParentByTagName(ele, "td", true) ||
  21976. domUtils.findParentByTagName(ele, "th", true))
  21977. )
  21978. return td;
  21979. return null;
  21980. }
  21981. function isEmptyBlock(node) {
  21982. var reg = new RegExp(domUtils.fillChar, "g");
  21983. if (
  21984. node[browser.ie ? "innerText" : "textContent"]
  21985. .replace(/^\s*$/, "")
  21986. .replace(reg, "").length > 0
  21987. ) {
  21988. return 0;
  21989. }
  21990. for (var n in dtd.$isNotEmpty) {
  21991. if (node.getElementsByTagName(n).length) {
  21992. return 0;
  21993. }
  21994. }
  21995. return 1;
  21996. }
  21997. function mouseCoords(evt) {
  21998. if (evt.pageX || evt.pageY) {
  21999. return { x: evt.pageX, y: evt.pageY };
  22000. }
  22001. return {
  22002. x:
  22003. evt.clientX + me.document.body.scrollLeft - me.document.body.clientLeft,
  22004. y: evt.clientY + me.document.body.scrollTop - me.document.body.clientTop
  22005. };
  22006. }
  22007. function mouseMoveEvent(evt) {
  22008. if (isEditorDisabled()) {
  22009. return;
  22010. }
  22011. try {
  22012. //普通状态下鼠标移动
  22013. var target = getParentTdOrTh(evt.target || evt.srcElement),
  22014. pos;
  22015. //区分用户的行为是拖动还是双击
  22016. if (isInResizeBuffer) {
  22017. me.body.style.webkitUserSelect = "none";
  22018. if (
  22019. Math.abs(userActionStatus.x - evt.clientX) > offsetOfTableCell ||
  22020. Math.abs(userActionStatus.y - evt.clientY) > offsetOfTableCell
  22021. ) {
  22022. clearTableDragTimer();
  22023. isInResizeBuffer = false;
  22024. singleClickState = 0;
  22025. //drag action
  22026. tableBorderDrag(evt);
  22027. }
  22028. }
  22029. //修改单元格大小时的鼠标移动
  22030. if (onDrag && dragTd) {
  22031. singleClickState = 0;
  22032. me.body.style.webkitUserSelect = "none";
  22033. me.selection.getNative()[
  22034. browser.ie9below ? "empty" : "removeAllRanges"
  22035. ]();
  22036. pos = mouseCoords(evt);
  22037. toggleDraggableState(me, true, onDrag, pos, target);
  22038. if (onDrag == "h") {
  22039. dragLine.style.left = getPermissionX(dragTd, evt) + "px";
  22040. } else if (onDrag == "v") {
  22041. dragLine.style.top = getPermissionY(dragTd, evt) + "px";
  22042. }
  22043. return;
  22044. }
  22045. //当鼠标处于table上时,修改移动过程中的光标状态
  22046. if (target) {
  22047. //针对使用table作为容器的组件不触发拖拽效果
  22048. if (me.fireEvent("excludetable", target) === true) return;
  22049. pos = mouseCoords(evt);
  22050. var state = getRelation(target, pos),
  22051. table = domUtils.findParentByTagName(target, "table", true);
  22052. if (inTableSide(table, target, evt, true)) {
  22053. if (me.fireEvent("excludetable", table) === true) return;
  22054. me.body.style.cursor =
  22055. "url(" + me.options.cursorpath + "h.png),pointer";
  22056. } else if (inTableSide(table, target, evt)) {
  22057. if (me.fireEvent("excludetable", table) === true) return;
  22058. me.body.style.cursor =
  22059. "url(" + me.options.cursorpath + "v.png),pointer";
  22060. } else {
  22061. me.body.style.cursor = "text";
  22062. var curCell = target;
  22063. if (/\d/.test(state)) {
  22064. state = state.replace(/\d/, "");
  22065. target = getUETable(target).getPreviewCell(target, state == "v");
  22066. }
  22067. //位于第一行的顶部或者第一列的左边时不可拖动
  22068. toggleDraggableState(
  22069. me,
  22070. target ? !!state : false,
  22071. target ? state : "",
  22072. pos,
  22073. target
  22074. );
  22075. }
  22076. } else {
  22077. toggleDragButton(false, table, me);
  22078. }
  22079. } catch (e) {
  22080. showError(e);
  22081. }
  22082. }
  22083. var dragButtonTimer;
  22084. function toggleDragButton(show, table, editor) {
  22085. if (!show) {
  22086. if (dragOver) return;
  22087. dragButtonTimer = setTimeout(function() {
  22088. !dragOver &&
  22089. dragButton &&
  22090. dragButton.parentNode &&
  22091. dragButton.parentNode.removeChild(dragButton);
  22092. }, 2000);
  22093. } else {
  22094. createDragButton(table, editor);
  22095. }
  22096. }
  22097. function createDragButton(table, editor) {
  22098. var pos = domUtils.getXY(table),
  22099. doc = table.ownerDocument;
  22100. if (dragButton && dragButton.parentNode) return dragButton;
  22101. dragButton = doc.createElement("div");
  22102. dragButton.contentEditable = false;
  22103. dragButton.innerHTML = "";
  22104. dragButton.style.cssText =
  22105. "width:15px;height:15px;background-image:url(" +
  22106. editor.options.UEDITOR_HOME_URL +
  22107. "dialogs/table/dragicon.png);position: absolute;cursor:move;top:" +
  22108. (pos.y - 15) +
  22109. "px;left:" +
  22110. pos.x +
  22111. "px;";
  22112. domUtils.unSelectable(dragButton);
  22113. dragButton.onmouseover = function(evt) {
  22114. dragOver = true;
  22115. };
  22116. dragButton.onmouseout = function(evt) {
  22117. dragOver = false;
  22118. };
  22119. domUtils.on(dragButton, "click", function(type, evt) {
  22120. doClick(evt, this);
  22121. });
  22122. domUtils.on(dragButton, "dblclick", function(type, evt) {
  22123. doDblClick(evt);
  22124. });
  22125. domUtils.on(dragButton, "dragstart", function(type, evt) {
  22126. domUtils.preventDefault(evt);
  22127. });
  22128. var timer;
  22129. function doClick(evt, button) {
  22130. // 部分浏览器下需要清理
  22131. clearTimeout(timer);
  22132. timer = setTimeout(function() {
  22133. editor.fireEvent("tableClicked", table, button);
  22134. }, 300);
  22135. }
  22136. function doDblClick(evt) {
  22137. clearTimeout(timer);
  22138. var ut = getUETable(table),
  22139. start = table.rows[0].cells[0],
  22140. end = ut.getLastCell(),
  22141. range = ut.getCellsRange(start, end);
  22142. editor.selection.getRange().setStart(start, 0).setCursor(false, true);
  22143. ut.setSelected(range);
  22144. }
  22145. doc.body.appendChild(dragButton);
  22146. }
  22147. // function inPosition(table, pos) {
  22148. // var tablePos = domUtils.getXY(table),
  22149. // width = table.offsetWidth,
  22150. // height = table.offsetHeight;
  22151. // if (pos.x - tablePos.x < 5 && pos.y - tablePos.y < 5) {
  22152. // return "topLeft";
  22153. // } else if (tablePos.x + width - pos.x < 5 && tablePos.y + height - pos.y < 5) {
  22154. // return "bottomRight";
  22155. // }
  22156. // }
  22157. function inTableSide(table, cell, evt, top) {
  22158. var pos = mouseCoords(evt),
  22159. state = getRelation(cell, pos);
  22160. if (top) {
  22161. var caption = table.getElementsByTagName("caption")[0],
  22162. capHeight = caption ? caption.offsetHeight : 0;
  22163. return state == "v1" && pos.y - domUtils.getXY(table).y - capHeight < 8;
  22164. } else {
  22165. return state == "h1" && pos.x - domUtils.getXY(table).x < 8;
  22166. }
  22167. }
  22168. /**
  22169. * 获取拖动时允许的X轴坐标
  22170. * @param dragTd
  22171. * @param evt
  22172. */
  22173. function getPermissionX(dragTd, evt) {
  22174. var ut = getUETable(dragTd);
  22175. if (ut) {
  22176. var preTd = ut.getSameEndPosCells(dragTd, "x")[0],
  22177. nextTd = ut.getSameStartPosXCells(dragTd)[0],
  22178. mouseX = mouseCoords(evt).x,
  22179. left =
  22180. (preTd ? domUtils.getXY(preTd).x : domUtils.getXY(ut.table).x) + 20,
  22181. right = nextTd
  22182. ? domUtils.getXY(nextTd).x + nextTd.offsetWidth - 20
  22183. : me.body.offsetWidth + 5 ||
  22184. parseInt(domUtils.getComputedStyle(me.body, "width"), 10);
  22185. left += cellMinWidth;
  22186. right -= cellMinWidth;
  22187. return mouseX < left ? left : mouseX > right ? right : mouseX;
  22188. }
  22189. }
  22190. /**
  22191. * 获取拖动时允许的Y轴坐标
  22192. */
  22193. function getPermissionY(dragTd, evt) {
  22194. try {
  22195. var top = domUtils.getXY(dragTd).y,
  22196. mousePosY = mouseCoords(evt).y;
  22197. return mousePosY < top ? top : mousePosY;
  22198. } catch (e) {
  22199. showError(e);
  22200. }
  22201. }
  22202. /**
  22203. * 移动状态切换
  22204. */
  22205. function toggleDraggableState(editor, draggable, dir, mousePos, cell) {
  22206. try {
  22207. editor.body.style.cursor = dir == "h"
  22208. ? "col-resize"
  22209. : dir == "v" ? "row-resize" : "text";
  22210. if (browser.ie) {
  22211. if (dir && !mousedown && !getUETableBySelected(editor)) {
  22212. getDragLine(editor, editor.document);
  22213. showDragLineAt(dir, cell);
  22214. } else {
  22215. hideDragLine(editor);
  22216. }
  22217. }
  22218. onBorder = draggable;
  22219. } catch (e) {
  22220. showError(e);
  22221. }
  22222. }
  22223. /**
  22224. * 获取与UETable相关的resize line
  22225. * @param uetable UETable对象
  22226. */
  22227. function getResizeLineByUETable() {
  22228. var lineId = "_UETableResizeLine",
  22229. line = this.document.getElementById(lineId);
  22230. if (!line) {
  22231. line = this.document.createElement("div");
  22232. line.id = lineId;
  22233. line.contnetEditable = false;
  22234. line.setAttribute("unselectable", "on");
  22235. var styles = {
  22236. width: 2 * cellBorderWidth + 1 + "px",
  22237. position: "absolute",
  22238. "z-index": 100000,
  22239. cursor: "col-resize",
  22240. background: "red",
  22241. display: "none"
  22242. };
  22243. //切换状态
  22244. line.onmouseout = function() {
  22245. this.style.display = "none";
  22246. };
  22247. utils.extend(line.style, styles);
  22248. this.document.body.appendChild(line);
  22249. }
  22250. return line;
  22251. }
  22252. /**
  22253. * 更新resize-line
  22254. */
  22255. function updateResizeLine(cell, uetable) {
  22256. var line = getResizeLineByUETable.call(this),
  22257. table = uetable.table,
  22258. styles = {
  22259. top: domUtils.getXY(table).y + "px",
  22260. left:
  22261. domUtils.getXY(cell).x + cell.offsetWidth - cellBorderWidth + "px",
  22262. display: "block",
  22263. height: table.offsetHeight + "px"
  22264. };
  22265. utils.extend(line.style, styles);
  22266. }
  22267. /**
  22268. * 显示resize-line
  22269. */
  22270. function showResizeLine(cell) {
  22271. var uetable = getUETable(cell);
  22272. updateResizeLine.call(this, cell, uetable);
  22273. }
  22274. /**
  22275. * 获取鼠标与当前单元格的相对位置
  22276. * @param ele
  22277. * @param mousePos
  22278. */
  22279. function getRelation(ele, mousePos) {
  22280. var elePos = domUtils.getXY(ele);
  22281. if (!elePos) {
  22282. return "";
  22283. }
  22284. if (elePos.x + ele.offsetWidth - mousePos.x < cellBorderWidth) {
  22285. return "h";
  22286. }
  22287. if (mousePos.x - elePos.x < cellBorderWidth) {
  22288. return "h1";
  22289. }
  22290. if (elePos.y + ele.offsetHeight - mousePos.y < cellBorderWidth) {
  22291. return "v";
  22292. }
  22293. if (mousePos.y - elePos.y < cellBorderWidth) {
  22294. return "v1";
  22295. }
  22296. return "";
  22297. }
  22298. function mouseDownEvent(type, evt) {
  22299. if (isEditorDisabled()) {
  22300. return;
  22301. }
  22302. userActionStatus = {
  22303. x: evt.clientX,
  22304. y: evt.clientY
  22305. };
  22306. //右键菜单单独处理
  22307. if (evt.button == 2) {
  22308. var ut = getUETableBySelected(me),
  22309. flag = false;
  22310. if (ut) {
  22311. var td = getTargetTd(me, evt);
  22312. utils.each(ut.selectedTds, function(ti) {
  22313. if (ti === td) {
  22314. flag = true;
  22315. }
  22316. });
  22317. if (!flag) {
  22318. removeSelectedClass(domUtils.getElementsByTagName(me.body, "th td"));
  22319. ut.clearSelected();
  22320. } else {
  22321. td = ut.selectedTds[0];
  22322. setTimeout(function() {
  22323. me.selection.getRange().setStart(td, 0).setCursor(false, true);
  22324. }, 0);
  22325. }
  22326. }
  22327. } else {
  22328. tableClickHander(evt);
  22329. }
  22330. }
  22331. //清除表格的计时器
  22332. function clearTableTimer() {
  22333. tabTimer && clearTimeout(tabTimer);
  22334. tabTimer = null;
  22335. }
  22336. //双击收缩
  22337. function tableDbclickHandler(evt) {
  22338. singleClickState = 0;
  22339. evt = evt || me.window.event;
  22340. var target = getParentTdOrTh(evt.target || evt.srcElement);
  22341. if (target) {
  22342. var h;
  22343. if ((h = getRelation(target, mouseCoords(evt)))) {
  22344. hideDragLine(me);
  22345. if (h == "h1") {
  22346. h = "h";
  22347. if (
  22348. inTableSide(
  22349. domUtils.findParentByTagName(target, "table"),
  22350. target,
  22351. evt
  22352. )
  22353. ) {
  22354. me.execCommand("adaptbywindow");
  22355. } else {
  22356. target = getUETable(target).getPreviewCell(target);
  22357. if (target) {
  22358. var rng = me.selection.getRange();
  22359. rng.selectNodeContents(target).setCursor(true, true);
  22360. }
  22361. }
  22362. }
  22363. if (h == "h") {
  22364. var ut = getUETable(target),
  22365. table = ut.table,
  22366. cells = getCellsByMoveBorder(target, table, true);
  22367. cells = extractArray(cells, "left");
  22368. ut.width = ut.offsetWidth;
  22369. var oldWidth = [],
  22370. newWidth = [];
  22371. utils.each(cells, function(cell) {
  22372. oldWidth.push(cell.offsetWidth);
  22373. });
  22374. utils.each(cells, function(cell) {
  22375. cell.removeAttribute("width");
  22376. });
  22377. window.setTimeout(function() {
  22378. //是否允许改变
  22379. var changeable = true;
  22380. utils.each(cells, function(cell, index) {
  22381. var width = cell.offsetWidth;
  22382. if (width > oldWidth[index]) {
  22383. changeable = false;
  22384. return false;
  22385. }
  22386. newWidth.push(width);
  22387. });
  22388. var change = changeable ? newWidth : oldWidth;
  22389. utils.each(cells, function(cell, index) {
  22390. cell.width = change[index] - getTabcellSpace();
  22391. });
  22392. }, 0);
  22393. // minWidth -= cellMinWidth;
  22394. //
  22395. // table.removeAttribute("width");
  22396. // utils.each(cells, function (cell) {
  22397. // cell.style.width = "";
  22398. // cell.width -= minWidth;
  22399. // });
  22400. }
  22401. }
  22402. }
  22403. }
  22404. function tableClickHander(evt) {
  22405. removeSelectedClass(domUtils.getElementsByTagName(me.body, "td th"));
  22406. //trace:3113
  22407. //选中单元格,点击table外部,不会清掉table上挂的ueTable,会引起getUETableBySelected方法返回值
  22408. utils.each(me.document.getElementsByTagName("table"), function(t) {
  22409. t.ueTable = null;
  22410. });
  22411. startTd = getTargetTd(me, evt);
  22412. if (!startTd) return;
  22413. var table = domUtils.findParentByTagName(startTd, "table", true);
  22414. ut = getUETable(table);
  22415. ut && ut.clearSelected();
  22416. //判断当前鼠标状态
  22417. if (!onBorder) {
  22418. me.document.body.style.webkitUserSelect = "";
  22419. mousedown = true;
  22420. me.addListener("mouseover", mouseOverEvent);
  22421. } else {
  22422. //边框上的动作处理
  22423. borderActionHandler(evt);
  22424. }
  22425. }
  22426. //处理表格边框上的动作, 这里做延时处理,避免两种动作互相影响
  22427. function borderActionHandler(evt) {
  22428. if (browser.ie) {
  22429. evt = reconstruct(evt);
  22430. }
  22431. clearTableDragTimer();
  22432. //是否正在等待resize的缓冲中
  22433. isInResizeBuffer = true;
  22434. tableDragTimer = setTimeout(function() {
  22435. tableBorderDrag(evt);
  22436. }, dblclickTime);
  22437. }
  22438. function extractArray(originArr, key) {
  22439. var result = [],
  22440. tmp = null;
  22441. for (var i = 0, len = originArr.length; i < len; i++) {
  22442. tmp = originArr[i][key];
  22443. if (tmp) {
  22444. result.push(tmp);
  22445. }
  22446. }
  22447. return result;
  22448. }
  22449. function clearTableDragTimer() {
  22450. tableDragTimer && clearTimeout(tableDragTimer);
  22451. tableDragTimer = null;
  22452. }
  22453. function reconstruct(obj) {
  22454. var attrs = [
  22455. "pageX",
  22456. "pageY",
  22457. "clientX",
  22458. "clientY",
  22459. "srcElement",
  22460. "target"
  22461. ],
  22462. newObj = {};
  22463. if (obj) {
  22464. for (var i = 0, key, val; (key = attrs[i]); i++) {
  22465. val = obj[key];
  22466. val && (newObj[key] = val);
  22467. }
  22468. }
  22469. return newObj;
  22470. }
  22471. //边框拖动
  22472. function tableBorderDrag(evt) {
  22473. isInResizeBuffer = false;
  22474. startTd = evt.target || evt.srcElement;
  22475. if (!startTd) return;
  22476. var state = getRelation(startTd, mouseCoords(evt));
  22477. if (/\d/.test(state)) {
  22478. state = state.replace(/\d/, "");
  22479. startTd = getUETable(startTd).getPreviewCell(startTd, state == "v");
  22480. }
  22481. hideDragLine(me);
  22482. getDragLine(me, me.document);
  22483. me.fireEvent("saveScene");
  22484. showDragLineAt(state, startTd);
  22485. mousedown = true;
  22486. //拖动开始
  22487. onDrag = state;
  22488. dragTd = startTd;
  22489. }
  22490. function mouseUpEvent(type, evt) {
  22491. if (isEditorDisabled()) {
  22492. return;
  22493. }
  22494. clearTableDragTimer();
  22495. isInResizeBuffer = false;
  22496. if (onBorder) {
  22497. singleClickState = ++singleClickState % 3;
  22498. userActionStatus = {
  22499. x: evt.clientX,
  22500. y: evt.clientY
  22501. };
  22502. tableResizeTimer = setTimeout(function() {
  22503. singleClickState > 0 && singleClickState--;
  22504. }, dblclickTime);
  22505. if (singleClickState === 2) {
  22506. singleClickState = 0;
  22507. tableDbclickHandler(evt);
  22508. return;
  22509. }
  22510. }
  22511. if (evt.button == 2) return;
  22512. var me = this;
  22513. //清除表格上原生跨选问题
  22514. var range = me.selection.getRange(),
  22515. start = domUtils.findParentByTagName(range.startContainer, "table", true),
  22516. end = domUtils.findParentByTagName(range.endContainer, "table", true);
  22517. if (start || end) {
  22518. if (start === end) {
  22519. start = domUtils.findParentByTagName(
  22520. range.startContainer,
  22521. ["td", "th", "caption"],
  22522. true
  22523. );
  22524. end = domUtils.findParentByTagName(
  22525. range.endContainer,
  22526. ["td", "th", "caption"],
  22527. true
  22528. );
  22529. if (start !== end) {
  22530. me.selection.clearRange();
  22531. }
  22532. } else {
  22533. me.selection.clearRange();
  22534. }
  22535. }
  22536. mousedown = false;
  22537. me.document.body.style.webkitUserSelect = "";
  22538. //拖拽状态下的mouseUP
  22539. if (onDrag && dragTd) {
  22540. me.selection.getNative()[
  22541. browser.ie9below ? "empty" : "removeAllRanges"
  22542. ]();
  22543. singleClickState = 0;
  22544. dragLine = me.document.getElementById("ue_tableDragLine");
  22545. // trace 3973
  22546. if (dragLine) {
  22547. var dragTdPos = domUtils.getXY(dragTd),
  22548. dragLinePos = domUtils.getXY(dragLine);
  22549. switch (onDrag) {
  22550. case "h":
  22551. changeColWidth(dragTd, dragLinePos.x - dragTdPos.x);
  22552. break;
  22553. case "v":
  22554. changeRowHeight(
  22555. dragTd,
  22556. dragLinePos.y - dragTdPos.y - dragTd.offsetHeight
  22557. );
  22558. break;
  22559. default:
  22560. }
  22561. onDrag = "";
  22562. dragTd = null;
  22563. hideDragLine(me);
  22564. me.fireEvent("saveScene");
  22565. return;
  22566. }
  22567. }
  22568. //正常状态下的mouseup
  22569. if (!startTd) {
  22570. var target = domUtils.findParentByTagName(
  22571. evt.target || evt.srcElement,
  22572. "td",
  22573. true
  22574. );
  22575. if (!target)
  22576. target = domUtils.findParentByTagName(
  22577. evt.target || evt.srcElement,
  22578. "th",
  22579. true
  22580. );
  22581. if (target && (target.tagName == "TD" || target.tagName == "TH")) {
  22582. if (me.fireEvent("excludetable", target) === true) return;
  22583. range = new dom.Range(me.document);
  22584. range.setStart(target, 0).setCursor(false, true);
  22585. }
  22586. } else {
  22587. var ut = getUETable(startTd),
  22588. cell = ut ? ut.selectedTds[0] : null;
  22589. if (cell) {
  22590. range = new dom.Range(me.document);
  22591. if (domUtils.isEmptyBlock(cell)) {
  22592. range.setStart(cell, 0).setCursor(false, true);
  22593. } else {
  22594. range
  22595. .selectNodeContents(cell)
  22596. .shrinkBoundary()
  22597. .setCursor(false, true);
  22598. }
  22599. } else {
  22600. range = me.selection.getRange().shrinkBoundary();
  22601. if (!range.collapsed) {
  22602. var start = domUtils.findParentByTagName(
  22603. range.startContainer,
  22604. ["td", "th"],
  22605. true
  22606. ),
  22607. end = domUtils.findParentByTagName(
  22608. range.endContainer,
  22609. ["td", "th"],
  22610. true
  22611. );
  22612. //在table里边的不能清除
  22613. if (
  22614. (start && !end) ||
  22615. (!start && end) ||
  22616. (start && end && start !== end)
  22617. ) {
  22618. range.setCursor(false, true);
  22619. }
  22620. }
  22621. }
  22622. startTd = null;
  22623. me.removeListener("mouseover", mouseOverEvent);
  22624. }
  22625. me._selectionChange(250, evt);
  22626. }
  22627. function mouseOverEvent(type, evt) {
  22628. if (isEditorDisabled()) {
  22629. return;
  22630. }
  22631. var me = this,
  22632. tar = evt.target || evt.srcElement;
  22633. currentTd =
  22634. domUtils.findParentByTagName(tar, "td", true) ||
  22635. domUtils.findParentByTagName(tar, "th", true);
  22636. //需要判断两个TD是否位于同一个表格内
  22637. if (
  22638. startTd &&
  22639. currentTd &&
  22640. ((startTd.tagName == "TD" && currentTd.tagName == "TD") ||
  22641. (startTd.tagName == "TH" && currentTd.tagName == "TH")) &&
  22642. domUtils.findParentByTagName(startTd, "table") ==
  22643. domUtils.findParentByTagName(currentTd, "table")
  22644. ) {
  22645. var ut = getUETable(currentTd);
  22646. if (startTd != currentTd) {
  22647. me.document.body.style.webkitUserSelect = "none";
  22648. me.selection.getNative()[
  22649. browser.ie9below ? "empty" : "removeAllRanges"
  22650. ]();
  22651. var range = ut.getCellsRange(startTd, currentTd);
  22652. ut.setSelected(range);
  22653. } else {
  22654. me.document.body.style.webkitUserSelect = "";
  22655. ut.clearSelected();
  22656. }
  22657. }
  22658. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  22659. }
  22660. function setCellHeight(cell, height, backHeight) {
  22661. var lineHight = parseInt(
  22662. domUtils.getComputedStyle(cell, "line-height"),
  22663. 10
  22664. ),
  22665. tmpHeight = backHeight + height;
  22666. height = tmpHeight < lineHight ? lineHight : tmpHeight;
  22667. if (cell.style.height) cell.style.height = "";
  22668. cell.rowSpan == 1
  22669. ? cell.setAttribute("height", height)
  22670. : cell.removeAttribute && cell.removeAttribute("height");
  22671. }
  22672. function getWidth(cell) {
  22673. if (!cell) return 0;
  22674. return parseInt(domUtils.getComputedStyle(cell, "width"), 10);
  22675. }
  22676. function changeColWidth(cell, changeValue) {
  22677. var ut = getUETable(cell);
  22678. if (ut) {
  22679. //根据当前移动的边框获取相关的单元格
  22680. var table = ut.table,
  22681. cells = getCellsByMoveBorder(cell, table);
  22682. table.style.width = "";
  22683. table.removeAttribute("width");
  22684. //修正改变量
  22685. changeValue = correctChangeValue(changeValue, cell, cells);
  22686. if (cell.nextSibling) {
  22687. var i = 0;
  22688. utils.each(cells, function(cellGroup) {
  22689. cellGroup.left.width = +cellGroup.left.width + changeValue;
  22690. cellGroup.right &&
  22691. (cellGroup.right.width = +cellGroup.right.width - changeValue);
  22692. });
  22693. } else {
  22694. utils.each(cells, function(cellGroup) {
  22695. cellGroup.left.width -= -changeValue;
  22696. });
  22697. }
  22698. }
  22699. }
  22700. function isEditorDisabled() {
  22701. return me.body.contentEditable === "false";
  22702. }
  22703. function changeRowHeight(td, changeValue) {
  22704. if (Math.abs(changeValue) < 10) return;
  22705. var ut = getUETable(td);
  22706. if (ut) {
  22707. var cells = ut.getSameEndPosCells(td, "y"),
  22708. //备份需要连带变化的td的原始高度,否则后期无法获取正确的值
  22709. backHeight = cells[0] ? cells[0].offsetHeight : 0;
  22710. for (var i = 0, cell; (cell = cells[i++]); ) {
  22711. setCellHeight(cell, changeValue, backHeight);
  22712. }
  22713. }
  22714. }
  22715. /**
  22716. * 获取调整单元格大小的相关单元格
  22717. * @isContainMergeCell 返回的结果中是否包含发生合并后的单元格
  22718. */
  22719. function getCellsByMoveBorder(cell, table, isContainMergeCell) {
  22720. if (!table) {
  22721. table = domUtils.findParentByTagName(cell, "table");
  22722. }
  22723. if (!table) {
  22724. return null;
  22725. }
  22726. //获取到该单元格所在行的序列号
  22727. var index = domUtils.getNodeIndex(cell),
  22728. temp = cell,
  22729. rows = table.rows,
  22730. colIndex = 0;
  22731. while (temp) {
  22732. //获取到当前单元格在未发生单元格合并时的序列
  22733. if (temp.nodeType === 1) {
  22734. colIndex += temp.colSpan || 1;
  22735. }
  22736. temp = temp.previousSibling;
  22737. }
  22738. temp = null;
  22739. //记录想关的单元格
  22740. var borderCells = [];
  22741. utils.each(rows, function(tabRow) {
  22742. var cells = tabRow.cells,
  22743. currIndex = 0;
  22744. utils.each(cells, function(tabCell) {
  22745. currIndex += tabCell.colSpan || 1;
  22746. if (currIndex === colIndex) {
  22747. borderCells.push({
  22748. left: tabCell,
  22749. right: tabCell.nextSibling || null
  22750. });
  22751. return false;
  22752. } else if (currIndex > colIndex) {
  22753. if (isContainMergeCell) {
  22754. borderCells.push({
  22755. left: tabCell
  22756. });
  22757. }
  22758. return false;
  22759. }
  22760. });
  22761. });
  22762. return borderCells;
  22763. }
  22764. /**
  22765. * 通过给定的单元格集合获取最小的单元格width
  22766. */
  22767. function getMinWidthByTableCells(cells) {
  22768. var minWidth = Number.MAX_VALUE;
  22769. for (var i = 0, curCell; (curCell = cells[i]); i++) {
  22770. minWidth = Math.min(
  22771. minWidth,
  22772. curCell.width || getTableCellWidth(curCell)
  22773. );
  22774. }
  22775. return minWidth;
  22776. }
  22777. function correctChangeValue(changeValue, relatedCell, cells) {
  22778. //为单元格的paading预留空间
  22779. changeValue -= getTabcellSpace();
  22780. if (changeValue < 0) {
  22781. return 0;
  22782. }
  22783. changeValue -= getTableCellWidth(relatedCell);
  22784. //确定方向
  22785. var direction = changeValue < 0 ? "left" : "right";
  22786. changeValue = Math.abs(changeValue);
  22787. //只关心非最后一个单元格就可以
  22788. utils.each(cells, function(cellGroup) {
  22789. var curCell = cellGroup[direction];
  22790. //为单元格保留最小空间
  22791. if (curCell) {
  22792. changeValue = Math.min(
  22793. changeValue,
  22794. getTableCellWidth(curCell) - cellMinWidth
  22795. );
  22796. }
  22797. });
  22798. //修正越界
  22799. changeValue = changeValue < 0 ? 0 : changeValue;
  22800. return direction === "left" ? -changeValue : changeValue;
  22801. }
  22802. function getTableCellWidth(cell) {
  22803. var width = 0,
  22804. //偏移纠正量
  22805. offset = 0,
  22806. width = cell.offsetWidth - getTabcellSpace();
  22807. //最后一个节点纠正一下
  22808. if (!cell.nextSibling) {
  22809. width -= getTableCellOffset(cell);
  22810. }
  22811. width = width < 0 ? 0 : width;
  22812. try {
  22813. cell.width = width;
  22814. } catch (e) {}
  22815. return width;
  22816. }
  22817. /**
  22818. * 获取单元格所在表格的最末单元格的偏移量
  22819. */
  22820. function getTableCellOffset(cell) {
  22821. tab = domUtils.findParentByTagName(cell, "table", false);
  22822. if (tab.offsetVal === undefined) {
  22823. var prev = cell.previousSibling;
  22824. if (prev) {
  22825. //最后一个单元格和前一个单元格的width diff结果 如果恰好为一个border width, 则条件成立
  22826. tab.offsetVal = cell.offsetWidth - prev.offsetWidth === UT.borderWidth
  22827. ? UT.borderWidth
  22828. : 0;
  22829. } else {
  22830. tab.offsetVal = 0;
  22831. }
  22832. }
  22833. return tab.offsetVal;
  22834. }
  22835. function getTabcellSpace() {
  22836. if (UT.tabcellSpace === undefined) {
  22837. var cell = null,
  22838. tab = me.document.createElement("table"),
  22839. tbody = me.document.createElement("tbody"),
  22840. trow = me.document.createElement("tr"),
  22841. tabcell = me.document.createElement("td"),
  22842. mirror = null;
  22843. tabcell.style.cssText = "border: 0;";
  22844. tabcell.width = 1;
  22845. trow.appendChild(tabcell);
  22846. trow.appendChild((mirror = tabcell.cloneNode(false)));
  22847. tbody.appendChild(trow);
  22848. tab.appendChild(tbody);
  22849. tab.style.cssText = "visibility: hidden;";
  22850. me.body.appendChild(tab);
  22851. UT.paddingSpace = tabcell.offsetWidth - 1;
  22852. var tmpTabWidth = tab.offsetWidth;
  22853. tabcell.style.cssText = "";
  22854. mirror.style.cssText = "";
  22855. UT.borderWidth = (tab.offsetWidth - tmpTabWidth) / 3;
  22856. UT.tabcellSpace = UT.paddingSpace + UT.borderWidth;
  22857. me.body.removeChild(tab);
  22858. }
  22859. getTabcellSpace = function() {
  22860. return UT.tabcellSpace;
  22861. };
  22862. return UT.tabcellSpace;
  22863. }
  22864. function getDragLine(editor, doc) {
  22865. if (mousedown) return;
  22866. dragLine = editor.document.createElement("div");
  22867. domUtils.setAttributes(dragLine, {
  22868. id: "ue_tableDragLine",
  22869. unselectable: "on",
  22870. contenteditable: false,
  22871. onresizestart: "return false",
  22872. ondragstart: "return false",
  22873. onselectstart: "return false",
  22874. style:
  22875. "background-color:blue;position:absolute;padding:0;margin:0;background-image:none;border:0px none;opacity:0;filter:alpha(opacity=0)"
  22876. });
  22877. editor.body.appendChild(dragLine);
  22878. }
  22879. function hideDragLine(editor) {
  22880. if (mousedown) return;
  22881. var line;
  22882. while ((line = editor.document.getElementById("ue_tableDragLine"))) {
  22883. domUtils.remove(line);
  22884. }
  22885. }
  22886. /**
  22887. * 依据state(v|h)在cell位置显示横线
  22888. * @param state
  22889. * @param cell
  22890. */
  22891. function showDragLineAt(state, cell) {
  22892. if (!cell) return;
  22893. var table = domUtils.findParentByTagName(cell, "table"),
  22894. caption = table.getElementsByTagName("caption"),
  22895. width = table.offsetWidth,
  22896. height =
  22897. table.offsetHeight - (caption.length > 0 ? caption[0].offsetHeight : 0),
  22898. tablePos = domUtils.getXY(table),
  22899. cellPos = domUtils.getXY(cell),
  22900. css;
  22901. switch (state) {
  22902. case "h":
  22903. css =
  22904. "height:" +
  22905. height +
  22906. "px;top:" +
  22907. (tablePos.y + (caption.length > 0 ? caption[0].offsetHeight : 0)) +
  22908. "px;left:" +
  22909. (cellPos.x + cell.offsetWidth);
  22910. dragLine.style.cssText =
  22911. css +
  22912. "px;position: absolute;display:block;background-color:blue;width:1px;border:0; color:blue;opacity:.3;filter:alpha(opacity=30)";
  22913. break;
  22914. case "v":
  22915. css =
  22916. "width:" +
  22917. width +
  22918. "px;left:" +
  22919. tablePos.x +
  22920. "px;top:" +
  22921. (cellPos.y + cell.offsetHeight);
  22922. //必须加上border:0和color:blue,否则低版ie不支持背景色显示
  22923. dragLine.style.cssText =
  22924. css +
  22925. "px;overflow:hidden;position: absolute;display:block;background-color:blue;height:1px;border:0;color:blue;opacity:.2;filter:alpha(opacity=20)";
  22926. break;
  22927. default:
  22928. }
  22929. }
  22930. /**
  22931. * 当表格边框颜色为白色时设置为虚线,true为添加虚线
  22932. * @param editor
  22933. * @param flag
  22934. */
  22935. function switchBorderColor(editor, flag) {
  22936. var tableArr = domUtils.getElementsByTagName(editor.body, "table"),
  22937. color;
  22938. for (var i = 0, node; (node = tableArr[i++]); ) {
  22939. var td = domUtils.getElementsByTagName(node, "td");
  22940. if (td[0]) {
  22941. if (flag) {
  22942. color = td[0].style.borderColor.replace(/\s/g, "");
  22943. if (/(#ffffff)|(rgb\(255,255,255\))/gi.test(color))
  22944. domUtils.addClass(node, "noBorderTable");
  22945. } else {
  22946. domUtils.removeClasses(node, "noBorderTable");
  22947. }
  22948. }
  22949. }
  22950. }
  22951. function getTableWidth(editor, needIEHack, defaultValue) {
  22952. var body = editor.body;
  22953. return (
  22954. body.offsetWidth -
  22955. (needIEHack
  22956. ? parseInt(domUtils.getComputedStyle(body, "margin-left"), 10) * 2
  22957. : 0) -
  22958. defaultValue.tableBorder * 2 -
  22959. (editor.options.offsetWidth || 0)
  22960. );
  22961. }
  22962. /**
  22963. * 获取当前拖动的单元格
  22964. */
  22965. function getTargetTd(editor, evt) {
  22966. var target = domUtils.findParentByTagName(
  22967. evt.target || evt.srcElement,
  22968. ["td", "th"],
  22969. true
  22970. ),
  22971. dir = null;
  22972. if (!target) {
  22973. return null;
  22974. }
  22975. dir = getRelation(target, mouseCoords(evt));
  22976. //如果有前一个节点, 需要做一个修正, 否则可能会得到一个错误的td
  22977. if (!target) {
  22978. return null;
  22979. }
  22980. if (dir === "h1" && target.previousSibling) {
  22981. var position = domUtils.getXY(target),
  22982. cellWidth = target.offsetWidth;
  22983. if (Math.abs(position.x + cellWidth - evt.clientX) > cellWidth / 3) {
  22984. target = target.previousSibling;
  22985. }
  22986. } else if (dir === "v1" && target.parentNode.previousSibling) {
  22987. var position = domUtils.getXY(target),
  22988. cellHeight = target.offsetHeight;
  22989. if (Math.abs(position.y + cellHeight - evt.clientY) > cellHeight / 3) {
  22990. target = target.parentNode.previousSibling.firstChild;
  22991. }
  22992. }
  22993. //排除了非td内部以及用于代码高亮部分的td
  22994. return target && !(editor.fireEvent("excludetable", target) === true)
  22995. ? target
  22996. : null;
  22997. }
  22998. };
  22999. // plugins/table.sort.js
  23000. /**
  23001. * Created with JetBrains PhpStorm.
  23002. * User: Jinqn
  23003. * Date: 13-10-12
  23004. * Time: 上午10:20
  23005. * To change this template use File | Settings | File Templates.
  23006. */
  23007. UE.UETable.prototype.sortTable = function(sortByCellIndex, compareFn) {
  23008. var table = this.table,
  23009. rows = table.rows,
  23010. trArray = [],
  23011. flag = rows[0].cells[0].tagName === "TH",
  23012. lastRowIndex = 0;
  23013. if (this.selectedTds.length) {
  23014. var range = this.cellsRange,
  23015. len = range.endRowIndex + 1;
  23016. for (var i = range.beginRowIndex; i < len; i++) {
  23017. trArray[i] = rows[i];
  23018. }
  23019. trArray.splice(0, range.beginRowIndex);
  23020. lastRowIndex = range.endRowIndex + 1 === this.rowsNum
  23021. ? 0
  23022. : range.endRowIndex + 1;
  23023. } else {
  23024. for (var i = 0, len = rows.length; i < len; i++) {
  23025. trArray[i] = rows[i];
  23026. }
  23027. }
  23028. var Fn = {
  23029. reversecurrent: function(td1, td2) {
  23030. return 1;
  23031. },
  23032. orderbyasc: function(td1, td2) {
  23033. var value1 = td1.innerText || td1.textContent,
  23034. value2 = td2.innerText || td2.textContent;
  23035. return value1.localeCompare(value2);
  23036. },
  23037. reversebyasc: function(td1, td2) {
  23038. var value1 = td1.innerHTML,
  23039. value2 = td2.innerHTML;
  23040. return value2.localeCompare(value1);
  23041. },
  23042. orderbynum: function(td1, td2) {
  23043. var value1 = td1[browser.ie ? "innerText" : "textContent"].match(/\d+/),
  23044. value2 = td2[browser.ie ? "innerText" : "textContent"].match(/\d+/);
  23045. if (value1) value1 = +value1[0];
  23046. if (value2) value2 = +value2[0];
  23047. return (value1 || 0) - (value2 || 0);
  23048. },
  23049. reversebynum: function(td1, td2) {
  23050. var value1 = td1[browser.ie ? "innerText" : "textContent"].match(/\d+/),
  23051. value2 = td2[browser.ie ? "innerText" : "textContent"].match(/\d+/);
  23052. if (value1) value1 = +value1[0];
  23053. if (value2) value2 = +value2[0];
  23054. return (value2 || 0) - (value1 || 0);
  23055. }
  23056. };
  23057. //对表格设置排序的标记data-sort-type
  23058. table.setAttribute(
  23059. "data-sort-type",
  23060. compareFn && typeof compareFn === "string" && Fn[compareFn] ? compareFn : ""
  23061. );
  23062. //th不参与排序
  23063. flag && trArray.splice(0, 1);
  23064. trArray = utils.sort(trArray, function(tr1, tr2) {
  23065. var result;
  23066. if (compareFn && typeof compareFn === "function") {
  23067. result = compareFn.call(
  23068. this,
  23069. tr1.cells[sortByCellIndex],
  23070. tr2.cells[sortByCellIndex]
  23071. );
  23072. } else if (compareFn && typeof compareFn === "number") {
  23073. result = 1;
  23074. } else if (compareFn && typeof compareFn === "string" && Fn[compareFn]) {
  23075. result = Fn[compareFn].call(
  23076. this,
  23077. tr1.cells[sortByCellIndex],
  23078. tr2.cells[sortByCellIndex]
  23079. );
  23080. } else {
  23081. result = Fn["orderbyasc"].call(
  23082. this,
  23083. tr1.cells[sortByCellIndex],
  23084. tr2.cells[sortByCellIndex]
  23085. );
  23086. }
  23087. return result;
  23088. });
  23089. var fragment = table.ownerDocument.createDocumentFragment();
  23090. for (var j = 0, len = trArray.length; j < len; j++) {
  23091. fragment.appendChild(trArray[j]);
  23092. }
  23093. var tbody = table.getElementsByTagName("tbody")[0];
  23094. if (!lastRowIndex) {
  23095. tbody.appendChild(fragment);
  23096. } else {
  23097. tbody.insertBefore(
  23098. fragment,
  23099. rows[lastRowIndex - range.endRowIndex + range.beginRowIndex - 1]
  23100. );
  23101. }
  23102. };
  23103. UE.plugins["tablesort"] = function() {
  23104. var me = this,
  23105. UT = UE.UETable,
  23106. getUETable = function(tdOrTable) {
  23107. return UT.getUETable(tdOrTable);
  23108. },
  23109. getTableItemsByRange = function(editor) {
  23110. return UT.getTableItemsByRange(editor);
  23111. };
  23112. me.ready(function() {
  23113. //添加表格可排序的样式
  23114. utils.cssRule(
  23115. "tablesort",
  23116. "table.sortEnabled tr.firstRow th,table.sortEnabled tr.firstRow td{padding-right:20px;background-repeat: no-repeat;background-position: center right;" +
  23117. " background-image:url(" +
  23118. me.options.themePath +
  23119. me.options.theme +
  23120. "/images/sortable.png);}",
  23121. me.document
  23122. );
  23123. //做单元格合并操作时,清除可排序标识
  23124. me.addListener("afterexeccommand", function(type, cmd) {
  23125. if (cmd == "mergeright" || cmd == "mergedown" || cmd == "mergecells") {
  23126. this.execCommand("disablesort");
  23127. }
  23128. });
  23129. });
  23130. //表格排序
  23131. UE.commands["sorttable"] = {
  23132. queryCommandState: function() {
  23133. var me = this,
  23134. tableItems = getTableItemsByRange(me);
  23135. if (!tableItems.cell) return -1;
  23136. var table = tableItems.table,
  23137. cells = table.getElementsByTagName("td");
  23138. for (var i = 0, cell; (cell = cells[i++]); ) {
  23139. if (cell.rowSpan != 1 || cell.colSpan != 1) return -1;
  23140. }
  23141. return 0;
  23142. },
  23143. execCommand: function(cmd, fn) {
  23144. var me = this,
  23145. range = me.selection.getRange(),
  23146. bk = range.createBookmark(true),
  23147. tableItems = getTableItemsByRange(me),
  23148. cell = tableItems.cell,
  23149. ut = getUETable(tableItems.table),
  23150. cellInfo = ut.getCellInfo(cell);
  23151. ut.sortTable(cellInfo.cellIndex, fn);
  23152. range.moveToBookmark(bk);
  23153. try {
  23154. range.select();
  23155. } catch (e) {}
  23156. }
  23157. };
  23158. //设置表格可排序,清除表格可排序
  23159. UE.commands["enablesort"] = UE.commands["disablesort"] = {
  23160. queryCommandState: function(cmd) {
  23161. var table = getTableItemsByRange(this).table;
  23162. if (table && cmd == "enablesort") {
  23163. var cells = domUtils.getElementsByTagName(table, "th td");
  23164. for (var i = 0; i < cells.length; i++) {
  23165. if (
  23166. cells[i].getAttribute("colspan") > 1 ||
  23167. cells[i].getAttribute("rowspan") > 1
  23168. )
  23169. return -1;
  23170. }
  23171. }
  23172. return !table
  23173. ? -1
  23174. : (cmd == "enablesort") ^
  23175. (table.getAttribute("data-sort") != "sortEnabled")
  23176. ? -1
  23177. : 0;
  23178. },
  23179. execCommand: function(cmd) {
  23180. var table = getTableItemsByRange(this).table;
  23181. table.setAttribute(
  23182. "data-sort",
  23183. cmd == "enablesort" ? "sortEnabled" : "sortDisabled"
  23184. );
  23185. cmd == "enablesort"
  23186. ? domUtils.addClass(table, "sortEnabled")
  23187. : domUtils.removeClasses(table, "sortEnabled");
  23188. }
  23189. };
  23190. };
  23191. // plugins/contextmenu.js
  23192. ///import core
  23193. ///commands 右键菜单
  23194. ///commandsName ContextMenu
  23195. ///commandsTitle 右键菜单
  23196. /**
  23197. * 右键菜单
  23198. * @function
  23199. * @name baidu.editor.plugins.contextmenu
  23200. * @author zhanyi
  23201. */
  23202. UE.plugins["contextmenu"] = function() {
  23203. var me = this;
  23204. me.setOpt("enableContextMenu", me.getOpt("enableContextMenu") || true);
  23205. if (me.getOpt("enableContextMenu") === false) {
  23206. return;
  23207. }
  23208. var lang = me.getLang("contextMenu"),
  23209. menu,
  23210. items = me.options.contextMenu || [
  23211. { label: lang["selectall"], cmdName: "selectall" },
  23212. {
  23213. label: lang.cleardoc,
  23214. cmdName: "cleardoc",
  23215. exec: function() {
  23216. if (confirm(lang.confirmclear)) {
  23217. this.execCommand("cleardoc");
  23218. }
  23219. }
  23220. },
  23221. "-",
  23222. {
  23223. label: lang.unlink,
  23224. cmdName: "unlink"
  23225. },
  23226. "-",
  23227. {
  23228. group: lang.paragraph,
  23229. icon: "justifyjustify",
  23230. subMenu: [
  23231. {
  23232. label: lang.justifyleft,
  23233. cmdName: "justify",
  23234. value: "left"
  23235. },
  23236. {
  23237. label: lang.justifyright,
  23238. cmdName: "justify",
  23239. value: "right"
  23240. },
  23241. {
  23242. label: lang.justifycenter,
  23243. cmdName: "justify",
  23244. value: "center"
  23245. },
  23246. {
  23247. label: lang.justifyjustify,
  23248. cmdName: "justify",
  23249. value: "justify"
  23250. }
  23251. ]
  23252. },
  23253. "-",
  23254. {
  23255. group: lang.table,
  23256. icon: "table",
  23257. subMenu: [
  23258. {
  23259. label: lang.inserttable,
  23260. cmdName: "inserttable"
  23261. },
  23262. {
  23263. label: lang.deletetable,
  23264. cmdName: "deletetable"
  23265. },
  23266. "-",
  23267. {
  23268. label: lang.deleterow,
  23269. cmdName: "deleterow"
  23270. },
  23271. {
  23272. label: lang.deletecol,
  23273. cmdName: "deletecol"
  23274. },
  23275. {
  23276. label: lang.insertcol,
  23277. cmdName: "insertcol"
  23278. },
  23279. {
  23280. label: lang.insertcolnext,
  23281. cmdName: "insertcolnext"
  23282. },
  23283. {
  23284. label: lang.insertrow,
  23285. cmdName: "insertrow"
  23286. },
  23287. {
  23288. label: lang.insertrownext,
  23289. cmdName: "insertrownext"
  23290. },
  23291. "-",
  23292. {
  23293. label: lang.insertcaption,
  23294. cmdName: "insertcaption"
  23295. },
  23296. {
  23297. label: lang.deletecaption,
  23298. cmdName: "deletecaption"
  23299. },
  23300. {
  23301. label: lang.inserttitle,
  23302. cmdName: "inserttitle"
  23303. },
  23304. {
  23305. label: lang.deletetitle,
  23306. cmdName: "deletetitle"
  23307. },
  23308. {
  23309. label: lang.inserttitlecol,
  23310. cmdName: "inserttitlecol"
  23311. },
  23312. {
  23313. label: lang.deletetitlecol,
  23314. cmdName: "deletetitlecol"
  23315. },
  23316. "-",
  23317. {
  23318. label: lang.mergecells,
  23319. cmdName: "mergecells"
  23320. },
  23321. {
  23322. label: lang.mergeright,
  23323. cmdName: "mergeright"
  23324. },
  23325. {
  23326. label: lang.mergedown,
  23327. cmdName: "mergedown"
  23328. },
  23329. "-",
  23330. {
  23331. label: lang.splittorows,
  23332. cmdName: "splittorows"
  23333. },
  23334. {
  23335. label: lang.splittocols,
  23336. cmdName: "splittocols"
  23337. },
  23338. {
  23339. label: lang.splittocells,
  23340. cmdName: "splittocells"
  23341. },
  23342. "-",
  23343. {
  23344. label: lang.averageDiseRow,
  23345. cmdName: "averagedistributerow"
  23346. },
  23347. {
  23348. label: lang.averageDisCol,
  23349. cmdName: "averagedistributecol"
  23350. },
  23351. "-",
  23352. {
  23353. label: lang.edittd,
  23354. cmdName: "edittd",
  23355. exec: function() {
  23356. if (UE.ui["edittd"]) {
  23357. new UE.ui["edittd"](this);
  23358. }
  23359. this.getDialog("edittd").open();
  23360. }
  23361. },
  23362. {
  23363. label: lang.edittable,
  23364. cmdName: "edittable",
  23365. exec: function() {
  23366. if (UE.ui["edittable"]) {
  23367. new UE.ui["edittable"](this);
  23368. }
  23369. this.getDialog("edittable").open();
  23370. }
  23371. },
  23372. {
  23373. label: lang.setbordervisible,
  23374. cmdName: "setbordervisible"
  23375. }
  23376. ]
  23377. },
  23378. {
  23379. group: lang.tablesort,
  23380. icon: "tablesort",
  23381. subMenu: [
  23382. {
  23383. label: lang.enablesort,
  23384. cmdName: "enablesort"
  23385. },
  23386. {
  23387. label: lang.disablesort,
  23388. cmdName: "disablesort"
  23389. },
  23390. "-",
  23391. {
  23392. label: lang.reversecurrent,
  23393. cmdName: "sorttable",
  23394. value: "reversecurrent"
  23395. },
  23396. {
  23397. label: lang.orderbyasc,
  23398. cmdName: "sorttable",
  23399. value: "orderbyasc"
  23400. },
  23401. {
  23402. label: lang.reversebyasc,
  23403. cmdName: "sorttable",
  23404. value: "reversebyasc"
  23405. },
  23406. {
  23407. label: lang.orderbynum,
  23408. cmdName: "sorttable",
  23409. value: "orderbynum"
  23410. },
  23411. {
  23412. label: lang.reversebynum,
  23413. cmdName: "sorttable",
  23414. value: "reversebynum"
  23415. }
  23416. ]
  23417. },
  23418. {
  23419. group: lang.borderbk,
  23420. icon: "borderBack",
  23421. subMenu: [
  23422. {
  23423. label: lang.setcolor,
  23424. cmdName: "interlacetable",
  23425. exec: function() {
  23426. this.execCommand("interlacetable");
  23427. }
  23428. },
  23429. {
  23430. label: lang.unsetcolor,
  23431. cmdName: "uninterlacetable",
  23432. exec: function() {
  23433. this.execCommand("uninterlacetable");
  23434. }
  23435. },
  23436. {
  23437. label: lang.setbackground,
  23438. cmdName: "settablebackground",
  23439. exec: function() {
  23440. this.execCommand("settablebackground", {
  23441. repeat: true,
  23442. colorList: ["#bbb", "#ccc"]
  23443. });
  23444. }
  23445. },
  23446. {
  23447. label: lang.unsetbackground,
  23448. cmdName: "cleartablebackground",
  23449. exec: function() {
  23450. this.execCommand("cleartablebackground");
  23451. }
  23452. },
  23453. {
  23454. label: lang.redandblue,
  23455. cmdName: "settablebackground",
  23456. exec: function() {
  23457. this.execCommand("settablebackground", {
  23458. repeat: true,
  23459. colorList: ["red", "blue"]
  23460. });
  23461. }
  23462. },
  23463. {
  23464. label: lang.threecolorgradient,
  23465. cmdName: "settablebackground",
  23466. exec: function() {
  23467. this.execCommand("settablebackground", {
  23468. repeat: true,
  23469. colorList: ["#aaa", "#bbb", "#ccc"]
  23470. });
  23471. }
  23472. }
  23473. ]
  23474. },
  23475. {
  23476. group: lang.aligntd,
  23477. icon: "aligntd",
  23478. subMenu: [
  23479. {
  23480. cmdName: "cellalignment",
  23481. value: { align: "left", vAlign: "top" }
  23482. },
  23483. {
  23484. cmdName: "cellalignment",
  23485. value: { align: "center", vAlign: "top" }
  23486. },
  23487. {
  23488. cmdName: "cellalignment",
  23489. value: { align: "right", vAlign: "top" }
  23490. },
  23491. {
  23492. cmdName: "cellalignment",
  23493. value: { align: "left", vAlign: "middle" }
  23494. },
  23495. {
  23496. cmdName: "cellalignment",
  23497. value: { align: "center", vAlign: "middle" }
  23498. },
  23499. {
  23500. cmdName: "cellalignment",
  23501. value: { align: "right", vAlign: "middle" }
  23502. },
  23503. {
  23504. cmdName: "cellalignment",
  23505. value: { align: "left", vAlign: "bottom" }
  23506. },
  23507. {
  23508. cmdName: "cellalignment",
  23509. value: { align: "center", vAlign: "bottom" }
  23510. },
  23511. {
  23512. cmdName: "cellalignment",
  23513. value: { align: "right", vAlign: "bottom" }
  23514. }
  23515. ]
  23516. },
  23517. {
  23518. group: lang.aligntable,
  23519. icon: "aligntable",
  23520. subMenu: [
  23521. {
  23522. cmdName: "tablealignment",
  23523. className: "left",
  23524. label: lang.tableleft,
  23525. value: "left"
  23526. },
  23527. {
  23528. cmdName: "tablealignment",
  23529. className: "center",
  23530. label: lang.tablecenter,
  23531. value: "center"
  23532. },
  23533. {
  23534. cmdName: "tablealignment",
  23535. className: "right",
  23536. label: lang.tableright,
  23537. value: "right"
  23538. }
  23539. ]
  23540. },
  23541. "-",
  23542. {
  23543. label: lang.insertparagraphbefore,
  23544. cmdName: "insertparagraph",
  23545. value: true
  23546. },
  23547. {
  23548. label: lang.insertparagraphafter,
  23549. cmdName: "insertparagraph"
  23550. },
  23551. {
  23552. label: lang["copy"],
  23553. cmdName: "copy"
  23554. },
  23555. {
  23556. label: lang["paste"],
  23557. cmdName: "paste"
  23558. }
  23559. ];
  23560. if (!items.length) {
  23561. return;
  23562. }
  23563. var uiUtils = UE.ui.uiUtils;
  23564. me.addListener("contextmenu", function(type, evt) {
  23565. var offset = uiUtils.getViewportOffsetByEvent(evt);
  23566. me.fireEvent("beforeselectionchange");
  23567. if (menu) {
  23568. menu.destroy();
  23569. }
  23570. for (var i = 0, ti, contextItems = []; (ti = items[i]); i++) {
  23571. var last;
  23572. (function(item) {
  23573. if (item == "-") {
  23574. if ((last = contextItems[contextItems.length - 1]) && last !== "-") {
  23575. contextItems.push("-");
  23576. }
  23577. } else if (item.hasOwnProperty("group")) {
  23578. for (var j = 0, cj, subMenu = []; (cj = item.subMenu[j]); j++) {
  23579. (function(subItem) {
  23580. if (subItem == "-") {
  23581. if ((last = subMenu[subMenu.length - 1]) && last !== "-") {
  23582. subMenu.push("-");
  23583. } else {
  23584. subMenu.splice(subMenu.length - 1);
  23585. }
  23586. } else {
  23587. if (
  23588. (me.commands[subItem.cmdName] ||
  23589. UE.commands[subItem.cmdName] ||
  23590. subItem.query) &&
  23591. (subItem.query
  23592. ? subItem.query()
  23593. : me.queryCommandState(subItem.cmdName)) > -1
  23594. ) {
  23595. subMenu.push({
  23596. label:
  23597. subItem.label ||
  23598. me.getLang(
  23599. "contextMenu." +
  23600. subItem.cmdName +
  23601. (subItem.value || "")
  23602. ) ||
  23603. "",
  23604. className:
  23605. "edui-for-" +
  23606. subItem.cmdName +
  23607. (subItem.className
  23608. ? " edui-for-" +
  23609. subItem.cmdName +
  23610. "-" +
  23611. subItem.className
  23612. : ""),
  23613. onclick: subItem.exec
  23614. ? function() {
  23615. subItem.exec.call(me);
  23616. }
  23617. : function() {
  23618. me.execCommand(subItem.cmdName, subItem.value);
  23619. }
  23620. });
  23621. }
  23622. }
  23623. })(cj);
  23624. }
  23625. if (subMenu.length) {
  23626. function getLabel() {
  23627. switch (item.icon) {
  23628. case "table":
  23629. return me.getLang("contextMenu.table");
  23630. case "justifyjustify":
  23631. return me.getLang("contextMenu.paragraph");
  23632. case "aligntd":
  23633. return me.getLang("contextMenu.aligntd");
  23634. case "aligntable":
  23635. return me.getLang("contextMenu.aligntable");
  23636. case "tablesort":
  23637. return lang.tablesort;
  23638. case "borderBack":
  23639. return lang.borderbk;
  23640. default:
  23641. return "";
  23642. }
  23643. }
  23644. contextItems.push({
  23645. //todo 修正成自动获取方式
  23646. label: getLabel(),
  23647. className: "edui-for-" + item.icon,
  23648. subMenu: {
  23649. items: subMenu,
  23650. editor: me
  23651. }
  23652. });
  23653. }
  23654. } else {
  23655. //有可能commmand没有加载右键不能出来,或者没有command也想能展示出来添加query方法
  23656. if (
  23657. (me.commands[item.cmdName] ||
  23658. UE.commands[item.cmdName] ||
  23659. item.query) &&
  23660. (item.query
  23661. ? item.query.call(me)
  23662. : me.queryCommandState(item.cmdName)) > -1
  23663. ) {
  23664. contextItems.push({
  23665. label: item.label || me.getLang("contextMenu." + item.cmdName),
  23666. className:
  23667. "edui-for-" +
  23668. (item.icon ? item.icon : item.cmdName + (item.value || "")),
  23669. onclick: item.exec
  23670. ? function() {
  23671. item.exec.call(me);
  23672. }
  23673. : function() {
  23674. me.execCommand(item.cmdName, item.value);
  23675. }
  23676. });
  23677. }
  23678. }
  23679. })(ti);
  23680. }
  23681. if (contextItems[contextItems.length - 1] == "-") {
  23682. contextItems.pop();
  23683. }
  23684. menu = new UE.ui.Menu({
  23685. items: contextItems,
  23686. className: "edui-contextmenu",
  23687. editor: me
  23688. });
  23689. menu.render();
  23690. menu.showAt(offset);
  23691. me.fireEvent("aftershowcontextmenu", menu);
  23692. domUtils.preventDefault(evt);
  23693. if (browser.ie) {
  23694. var ieRange;
  23695. try {
  23696. ieRange = me.selection.getNative().createRange();
  23697. } catch (e) {
  23698. return;
  23699. }
  23700. if (ieRange.item) {
  23701. var range = new dom.Range(me.document);
  23702. range.selectNode(ieRange.item(0)).select(true, true);
  23703. }
  23704. }
  23705. });
  23706. // 添加复制的flash按钮
  23707. me.addListener("aftershowcontextmenu", function(type, menu) {
  23708. if (me.zeroclipboard) {
  23709. var items = menu.items;
  23710. for (var key in items) {
  23711. if (items[key].className == "edui-for-copy") {
  23712. me.zeroclipboard.clip(items[key].getDom());
  23713. }
  23714. }
  23715. }
  23716. });
  23717. };
  23718. // plugins/shortcutmenu.js
  23719. ///import core
  23720. ///commands 弹出菜单
  23721. // commandsName popupmenu
  23722. ///commandsTitle 弹出菜单
  23723. /**
  23724. * 弹出菜单
  23725. * @function
  23726. * @name baidu.editor.plugins.popupmenu
  23727. * @author xuheng
  23728. */
  23729. UE.plugins["shortcutmenu"] = function() {
  23730. var me = this,
  23731. menu,
  23732. items = me.options.shortcutMenu || [];
  23733. if (!items.length) {
  23734. return;
  23735. }
  23736. me.addListener("contextmenu mouseup", function(type, e) {
  23737. var me = this,
  23738. customEvt = {
  23739. type: type,
  23740. target: e.target || e.srcElement,
  23741. screenX: e.screenX,
  23742. screenY: e.screenY,
  23743. clientX: e.clientX,
  23744. clientY: e.clientY
  23745. };
  23746. setTimeout(function() {
  23747. var rng = me.selection.getRange();
  23748. if (rng.collapsed === false || type == "contextmenu") {
  23749. if (!menu) {
  23750. menu = new baidu.editor.ui.ShortCutMenu({
  23751. editor: me,
  23752. items: items,
  23753. theme: me.options.theme,
  23754. className: "edui-shortcutmenu"
  23755. });
  23756. menu.render();
  23757. me.fireEvent("afterrendershortcutmenu", menu);
  23758. }
  23759. menu.show(customEvt, !!UE.plugins["contextmenu"]);
  23760. }
  23761. });
  23762. if (type == "contextmenu") {
  23763. domUtils.preventDefault(e);
  23764. if (browser.ie9below) {
  23765. var ieRange;
  23766. try {
  23767. ieRange = me.selection.getNative().createRange();
  23768. } catch (e) {
  23769. return;
  23770. }
  23771. if (ieRange.item) {
  23772. var range = new dom.Range(me.document);
  23773. range.selectNode(ieRange.item(0)).select(true, true);
  23774. }
  23775. }
  23776. }
  23777. });
  23778. me.addListener("keydown", function(type) {
  23779. if (type == "keydown") {
  23780. menu && !menu.isHidden && menu.hide();
  23781. }
  23782. });
  23783. };
  23784. // plugins/basestyle.js
  23785. /**
  23786. * B、I、sub、super命令支持
  23787. * @file
  23788. * @since 1.2.6.1
  23789. */
  23790. UE.plugins["basestyle"] = function() {
  23791. /**
  23792. * 字体加粗
  23793. * @command bold
  23794. * @param { String } cmd 命令字符串
  23795. * @remind 对已加粗的文本内容执行该命令, 将取消加粗
  23796. * @method execCommand
  23797. * @example
  23798. * ```javascript
  23799. * //editor是编辑器实例
  23800. * //对当前选中的文本内容执行加粗操作
  23801. * //第一次执行, 文本内容加粗
  23802. * editor.execCommand( 'bold' );
  23803. *
  23804. * //第二次执行, 文本内容取消加粗
  23805. * editor.execCommand( 'bold' );
  23806. * ```
  23807. */
  23808. /**
  23809. * 字体倾斜
  23810. * @command italic
  23811. * @method execCommand
  23812. * @param { String } cmd 命令字符串
  23813. * @remind 对已倾斜的文本内容执行该命令, 将取消倾斜
  23814. * @example
  23815. * ```javascript
  23816. * //editor是编辑器实例
  23817. * //对当前选中的文本内容执行斜体操作
  23818. * //第一次操作, 文本内容将变成斜体
  23819. * editor.execCommand( 'italic' );
  23820. *
  23821. * //再次对同一文本内容执行, 则文本内容将恢复正常
  23822. * editor.execCommand( 'italic' );
  23823. * ```
  23824. */
  23825. /**
  23826. * 下标文本,与“superscript”命令互斥
  23827. * @command subscript
  23828. * @method execCommand
  23829. * @remind 把选中的文本内容切换成下标文本, 如果当前选中的文本已经是下标, 则该操作会把文本内容还原成正常文本
  23830. * @param { String } cmd 命令字符串
  23831. * @example
  23832. * ```javascript
  23833. * //editor是编辑器实例
  23834. * //对当前选中的文本内容执行下标操作
  23835. * //第一次操作, 文本内容将变成下标文本
  23836. * editor.execCommand( 'subscript' );
  23837. *
  23838. * //再次对同一文本内容执行, 则文本内容将恢复正常
  23839. * editor.execCommand( 'subscript' );
  23840. * ```
  23841. */
  23842. /**
  23843. * 上标文本,与“subscript”命令互斥
  23844. * @command superscript
  23845. * @method execCommand
  23846. * @remind 把选中的文本内容切换成上标文本, 如果当前选中的文本已经是上标, 则该操作会把文本内容还原成正常文本
  23847. * @param { String } cmd 命令字符串
  23848. * @example
  23849. * ```javascript
  23850. * //editor是编辑器实例
  23851. * //对当前选中的文本内容执行上标操作
  23852. * //第一次操作, 文本内容将变成上标文本
  23853. * editor.execCommand( 'superscript' );
  23854. *
  23855. * //再次对同一文本内容执行, 则文本内容将恢复正常
  23856. * editor.execCommand( 'superscript' );
  23857. * ```
  23858. */
  23859. var basestyles = {
  23860. bold: ["strong", "b"],
  23861. italic: ["em", "i"],
  23862. subscript: ["sub"],
  23863. superscript: ["sup"]
  23864. },
  23865. getObj = function(editor, tagNames) {
  23866. return domUtils.filterNodeList(
  23867. editor.selection.getStartElementPath(),
  23868. tagNames
  23869. );
  23870. },
  23871. me = this;
  23872. //添加快捷键
  23873. me.addshortcutkey({
  23874. Bold: "ctrl+66", //^B
  23875. Italic: "ctrl+73", //^I
  23876. Underline: "ctrl+85" //^U
  23877. });
  23878. me.addInputRule(function(root) {
  23879. utils.each(root.getNodesByTagName("b i"), function(node) {
  23880. switch (node.tagName) {
  23881. case "b":
  23882. node.tagName = "strong";
  23883. break;
  23884. case "i":
  23885. node.tagName = "em";
  23886. }
  23887. });
  23888. });
  23889. for (var style in basestyles) {
  23890. (function(cmd, tagNames) {
  23891. me.commands[cmd] = {
  23892. execCommand: function(cmdName) {
  23893. var range = me.selection.getRange(),
  23894. obj = getObj(this, tagNames);
  23895. if (range.collapsed) {
  23896. if (obj) {
  23897. var tmpText = me.document.createTextNode("");
  23898. range.insertNode(tmpText).removeInlineStyle(tagNames);
  23899. range.setStartBefore(tmpText);
  23900. domUtils.remove(tmpText);
  23901. } else {
  23902. var tmpNode = range.document.createElement(tagNames[0]);
  23903. if (cmdName == "superscript" || cmdName == "subscript") {
  23904. tmpText = me.document.createTextNode("");
  23905. range
  23906. .insertNode(tmpText)
  23907. .removeInlineStyle(["sub", "sup"])
  23908. .setStartBefore(tmpText)
  23909. .collapse(true);
  23910. }
  23911. range.insertNode(tmpNode).setStart(tmpNode, 0);
  23912. }
  23913. range.collapse(true);
  23914. } else {
  23915. if (cmdName == "superscript" || cmdName == "subscript") {
  23916. if (!obj || obj.tagName.toLowerCase() != cmdName) {
  23917. range.removeInlineStyle(["sub", "sup"]);
  23918. }
  23919. }
  23920. obj
  23921. ? range.removeInlineStyle(tagNames)
  23922. : range.applyInlineStyle(tagNames[0]);
  23923. }
  23924. range.select();
  23925. },
  23926. queryCommandState: function() {
  23927. return getObj(this, tagNames) ? 1 : 0;
  23928. }
  23929. };
  23930. })(style, basestyles[style]);
  23931. }
  23932. };
  23933. // plugins/elementpath.js
  23934. /**
  23935. * 选取路径命令
  23936. * @file
  23937. */
  23938. UE.plugins["elementpath"] = function() {
  23939. var currentLevel,
  23940. tagNames,
  23941. me = this;
  23942. me.setOpt("elementPathEnabled", true);
  23943. if (!me.options.elementPathEnabled) {
  23944. return;
  23945. }
  23946. me.commands["elementpath"] = {
  23947. execCommand: function(cmdName, level) {
  23948. var start = tagNames[level],
  23949. range = me.selection.getRange();
  23950. currentLevel = level * 1;
  23951. range.selectNode(start).select();
  23952. },
  23953. queryCommandValue: function() {
  23954. //产生一个副本,不能修改原来的startElementPath;
  23955. var parents = [].concat(this.selection.getStartElementPath()).reverse(),
  23956. names = [];
  23957. tagNames = parents;
  23958. for (var i = 0, ci; (ci = parents[i]); i++) {
  23959. if (ci.nodeType == 3) {
  23960. continue;
  23961. }
  23962. var name = ci.tagName.toLowerCase();
  23963. if (name == "img" && ci.getAttribute("anchorname")) {
  23964. name = "anchor";
  23965. }
  23966. names[i] = name;
  23967. if (currentLevel == i) {
  23968. currentLevel = -1;
  23969. break;
  23970. }
  23971. }
  23972. return names;
  23973. }
  23974. };
  23975. };
  23976. // plugins/formatmatch.js
  23977. /**
  23978. * 格式刷,只格式inline的
  23979. * @file
  23980. * @since 1.2.6.1
  23981. */
  23982. /**
  23983. * 格式刷
  23984. * @command formatmatch
  23985. * @method execCommand
  23986. * @remind 该操作不能复制段落格式
  23987. * @param { String } cmd 命令字符串
  23988. * @example
  23989. * ```javascript
  23990. * //editor是编辑器实例
  23991. * //获取格式刷
  23992. * editor.execCommand( 'formatmatch' );
  23993. * ```
  23994. */
  23995. UE.plugins["formatmatch"] = function() {
  23996. var me = this,
  23997. list = [],
  23998. img,
  23999. flag = 0;
  24000. me.addListener("reset", function() {
  24001. list = [];
  24002. flag = 0;
  24003. });
  24004. function addList(type, evt) {
  24005. if (browser.webkit) {
  24006. var target = evt.target.tagName == "IMG" ? evt.target : null;
  24007. }
  24008. function addFormat(range) {
  24009. if (text) {
  24010. range.selectNode(text);
  24011. }
  24012. return range.applyInlineStyle(list[list.length - 1].tagName, null, list);
  24013. }
  24014. me.undoManger && me.undoManger.save();
  24015. var range = me.selection.getRange(),
  24016. imgT = target || range.getClosedNode();
  24017. if (img && imgT && imgT.tagName == "IMG") {
  24018. //trace:964
  24019. imgT.style.cssText +=
  24020. ";float:" +
  24021. (img.style.cssFloat || img.style.styleFloat || "none") +
  24022. ";display:" +
  24023. (img.style.display || "inline");
  24024. img = null;
  24025. } else {
  24026. if (!img) {
  24027. var collapsed = range.collapsed;
  24028. if (collapsed) {
  24029. var text = me.document.createTextNode("match");
  24030. range.insertNode(text).select();
  24031. }
  24032. me.__hasEnterExecCommand = true;
  24033. //不能把block上的属性干掉
  24034. //trace:1553
  24035. var removeFormatAttributes = me.options.removeFormatAttributes;
  24036. me.options.removeFormatAttributes = "";
  24037. me.execCommand("removeformat");
  24038. me.options.removeFormatAttributes = removeFormatAttributes;
  24039. me.__hasEnterExecCommand = false;
  24040. //trace:969
  24041. range = me.selection.getRange();
  24042. if (list.length) {
  24043. addFormat(range);
  24044. }
  24045. if (text) {
  24046. range.setStartBefore(text).collapse(true);
  24047. }
  24048. range.select();
  24049. text && domUtils.remove(text);
  24050. }
  24051. }
  24052. me.undoManger && me.undoManger.save();
  24053. me.removeListener("mouseup", addList);
  24054. flag = 0;
  24055. }
  24056. me.commands["formatmatch"] = {
  24057. execCommand: function(cmdName) {
  24058. if (flag) {
  24059. flag = 0;
  24060. list = [];
  24061. me.removeListener("mouseup", addList);
  24062. return;
  24063. }
  24064. var range = me.selection.getRange();
  24065. img = range.getClosedNode();
  24066. if (!img || img.tagName != "IMG") {
  24067. range.collapse(true).shrinkBoundary();
  24068. var start = range.startContainer;
  24069. list = domUtils.findParents(start, true, function(node) {
  24070. return !domUtils.isBlockElm(node) && node.nodeType == 1;
  24071. });
  24072. //a不能加入格式刷, 并且克隆节点
  24073. for (var i = 0, ci; (ci = list[i]); i++) {
  24074. if (ci.tagName == "A") {
  24075. list.splice(i, 1);
  24076. break;
  24077. }
  24078. }
  24079. }
  24080. me.addListener("mouseup", addList);
  24081. flag = 1;
  24082. },
  24083. queryCommandState: function() {
  24084. return flag;
  24085. },
  24086. notNeedUndo: 1
  24087. };
  24088. };
  24089. // plugins/searchreplace.js
  24090. ///import core
  24091. ///commands 查找替换
  24092. ///commandsName SearchReplace
  24093. ///commandsTitle 查询替换
  24094. ///commandsDialog dialogs\searchreplace
  24095. /**
  24096. * @description 查找替换
  24097. * @author zhanyi
  24098. */
  24099. UE.plugin.register("searchreplace", function() {
  24100. var me = this;
  24101. var _blockElm = { table: 1, tbody: 1, tr: 1, ol: 1, ul: 1 };
  24102. var lastRng = null;
  24103. function getText(node) {
  24104. var text = node.nodeType == 3
  24105. ? node.nodeValue
  24106. : node[browser.ie ? "innerText" : "textContent"];
  24107. return text.replace(domUtils.fillChar, "");
  24108. }
  24109. function findTextInString(textContent, opt, currentIndex) {
  24110. var str = opt.searchStr;
  24111. var reg = new RegExp(str, "g" + (opt.casesensitive ? "" : "i")),
  24112. match;
  24113. if (opt.dir == -1) {
  24114. textContent = textContent.substr(0, currentIndex);
  24115. textContent = textContent.split("").reverse().join("");
  24116. str = str.split("").reverse().join("");
  24117. match = reg.exec(textContent);
  24118. if (match) {
  24119. return currentIndex - match.index - str.length;
  24120. }
  24121. } else {
  24122. textContent = textContent.substr(currentIndex);
  24123. match = reg.exec(textContent);
  24124. if (match) {
  24125. return match.index + currentIndex;
  24126. }
  24127. }
  24128. return -1;
  24129. }
  24130. function findTextBlockElm(node, currentIndex, opt) {
  24131. var textContent,
  24132. index,
  24133. methodName = opt.all || opt.dir == 1 ? "getNextDomNode" : "getPreDomNode";
  24134. if (domUtils.isBody(node)) {
  24135. node = node.firstChild;
  24136. }
  24137. var first = 1;
  24138. while (node) {
  24139. textContent = getText(node);
  24140. index = findTextInString(textContent, opt, currentIndex);
  24141. first = 0;
  24142. if (index != -1) {
  24143. return {
  24144. node: node,
  24145. index: index
  24146. };
  24147. }
  24148. node = domUtils[methodName](node);
  24149. while (node && _blockElm[node.nodeName.toLowerCase()]) {
  24150. node = domUtils[methodName](node, true);
  24151. }
  24152. if (node) {
  24153. currentIndex = opt.dir == -1 ? getText(node).length : 0;
  24154. }
  24155. }
  24156. }
  24157. function findNTextInBlockElm(node, index, str) {
  24158. var currentIndex = 0,
  24159. currentNode = node.firstChild,
  24160. currentNodeLength = 0,
  24161. result;
  24162. while (currentNode) {
  24163. if (currentNode.nodeType == 3) {
  24164. currentNodeLength = getText(currentNode).replace(
  24165. /(^[\t\r\n]+)|([\t\r\n]+$)/,
  24166. ""
  24167. ).length;
  24168. currentIndex += currentNodeLength;
  24169. if (currentIndex >= index) {
  24170. return {
  24171. node: currentNode,
  24172. index: currentNodeLength - (currentIndex - index)
  24173. };
  24174. }
  24175. } else if (!dtd.$empty[currentNode.tagName]) {
  24176. currentNodeLength = getText(currentNode).replace(
  24177. /(^[\t\r\n]+)|([\t\r\n]+$)/,
  24178. ""
  24179. ).length;
  24180. currentIndex += currentNodeLength;
  24181. if (currentIndex >= index) {
  24182. result = findNTextInBlockElm(
  24183. currentNode,
  24184. currentNodeLength - (currentIndex - index),
  24185. str
  24186. );
  24187. if (result) {
  24188. return result;
  24189. }
  24190. }
  24191. }
  24192. currentNode = domUtils.getNextDomNode(currentNode);
  24193. }
  24194. }
  24195. function searchReplace(me, opt) {
  24196. var rng = lastRng || me.selection.getRange(),
  24197. startBlockNode,
  24198. searchStr = opt.searchStr,
  24199. span = me.document.createElement("span");
  24200. span.innerHTML = "$$ueditor_searchreplace_key$$";
  24201. rng.shrinkBoundary(true);
  24202. //判断是不是第一次选中
  24203. if (!rng.collapsed) {
  24204. rng.select();
  24205. var rngText = me.selection.getText();
  24206. if (
  24207. new RegExp(
  24208. "^" + opt.searchStr + "$",
  24209. opt.casesensitive ? "" : "i"
  24210. ).test(rngText)
  24211. ) {
  24212. if (opt.replaceStr != undefined) {
  24213. replaceText(rng, opt.replaceStr);
  24214. rng.select();
  24215. return true;
  24216. } else {
  24217. rng.collapse(opt.dir == -1);
  24218. }
  24219. }
  24220. }
  24221. rng.insertNode(span);
  24222. rng.enlargeToBlockElm(true);
  24223. startBlockNode = rng.startContainer;
  24224. var currentIndex = getText(startBlockNode).indexOf(
  24225. "$$ueditor_searchreplace_key$$"
  24226. );
  24227. rng.setStartBefore(span);
  24228. domUtils.remove(span);
  24229. var result = findTextBlockElm(startBlockNode, currentIndex, opt);
  24230. if (result) {
  24231. var rngStart = findNTextInBlockElm(result.node, result.index, searchStr);
  24232. var rngEnd = findNTextInBlockElm(
  24233. result.node,
  24234. result.index + searchStr.length,
  24235. searchStr
  24236. );
  24237. rng
  24238. .setStart(rngStart.node, rngStart.index)
  24239. .setEnd(rngEnd.node, rngEnd.index);
  24240. if (opt.replaceStr !== undefined) {
  24241. replaceText(rng, opt.replaceStr);
  24242. }
  24243. rng.select();
  24244. return true;
  24245. } else {
  24246. rng.setCursor();
  24247. }
  24248. }
  24249. function replaceText(rng, str) {
  24250. str = me.document.createTextNode(str);
  24251. rng.deleteContents().insertNode(str);
  24252. }
  24253. return {
  24254. commands: {
  24255. searchreplace: {
  24256. execCommand: function(cmdName, opt) {
  24257. utils.extend(
  24258. opt,
  24259. {
  24260. all: false,
  24261. casesensitive: false,
  24262. dir: 1
  24263. },
  24264. true
  24265. );
  24266. var num = 0;
  24267. if (opt.all) {
  24268. lastRng = null;
  24269. var rng = me.selection.getRange(),
  24270. first = me.body.firstChild;
  24271. if (first && first.nodeType == 1) {
  24272. rng.setStart(first, 0);
  24273. rng.shrinkBoundary(true);
  24274. } else if (first.nodeType == 3) {
  24275. rng.setStartBefore(first);
  24276. }
  24277. rng.collapse(true).select(true);
  24278. if (opt.replaceStr !== undefined) {
  24279. me.fireEvent("saveScene");
  24280. }
  24281. while (searchReplace(this, opt)) {
  24282. num++;
  24283. lastRng = me.selection.getRange();
  24284. lastRng.collapse(opt.dir == -1);
  24285. }
  24286. if (num) {
  24287. me.fireEvent("saveScene");
  24288. }
  24289. } else {
  24290. if (opt.replaceStr !== undefined) {
  24291. me.fireEvent("saveScene");
  24292. }
  24293. if (searchReplace(this, opt)) {
  24294. num++;
  24295. lastRng = me.selection.getRange();
  24296. lastRng.collapse(opt.dir == -1);
  24297. }
  24298. if (num) {
  24299. me.fireEvent("saveScene");
  24300. }
  24301. }
  24302. return num;
  24303. },
  24304. notNeedUndo: 1
  24305. }
  24306. },
  24307. bindEvents: {
  24308. clearlastSearchResult: function() {
  24309. lastRng = null;
  24310. }
  24311. }
  24312. };
  24313. });
  24314. // plugins/customstyle.js
  24315. /**
  24316. * 自定义样式
  24317. * @file
  24318. * @since 1.2.6.1
  24319. */
  24320. /**
  24321. * 根据config配置文件里“customstyle”选项的值对匹配的标签执行样式替换。
  24322. * @command customstyle
  24323. * @method execCommand
  24324. * @param { String } cmd 命令字符串
  24325. * @example
  24326. * ```javascript
  24327. * editor.execCommand( 'customstyle' );
  24328. * ```
  24329. */
  24330. UE.plugins["customstyle"] = function() {
  24331. var me = this;
  24332. me.setOpt({
  24333. customstyle: [
  24334. {
  24335. tag: "h1",
  24336. name: "tc",
  24337. style:
  24338. "font-size:32px;font-weight:bold;border-bottom:#ccc 2px solid;padding:0 4px 0 0;text-align:center;margin:0 0 20px 0;"
  24339. },
  24340. {
  24341. tag: "h1",
  24342. name: "tl",
  24343. style:
  24344. "font-size:32px;font-weight:bold;border-bottom:#ccc 2px solid;padding:0 4px 0 0;text-align:left;margin:0 0 10px 0;"
  24345. },
  24346. {
  24347. tag: "span",
  24348. name: "im",
  24349. style:
  24350. "font-size:16px;font-style:italic;font-weight:bold;line-height:18px;"
  24351. },
  24352. {
  24353. tag: "span",
  24354. name: "hi",
  24355. style:
  24356. "font-size:16px;font-style:italic;font-weight:bold;color:rgb(51, 153, 204);line-height:18px;"
  24357. }
  24358. ]
  24359. });
  24360. me.commands["customstyle"] = {
  24361. execCommand: function(cmdName, obj) {
  24362. var me = this,
  24363. tagName = obj.tag,
  24364. node = domUtils.findParent(
  24365. me.selection.getStart(),
  24366. function(node) {
  24367. return node.getAttribute("label");
  24368. },
  24369. true
  24370. ),
  24371. range,
  24372. bk,
  24373. tmpObj = {};
  24374. for (var p in obj) {
  24375. if (obj[p] !== undefined) tmpObj[p] = obj[p];
  24376. }
  24377. delete tmpObj.tag;
  24378. if (node && node.getAttribute("label") == obj.label) {
  24379. range = this.selection.getRange();
  24380. bk = range.createBookmark();
  24381. if (range.collapsed) {
  24382. //trace:1732 删掉自定义标签,要有p来回填站位
  24383. if (dtd.$block[node.tagName]) {
  24384. var fillNode = me.document.createElement("p");
  24385. domUtils.moveChild(node, fillNode);
  24386. node.parentNode.insertBefore(fillNode, node);
  24387. domUtils.remove(node);
  24388. } else {
  24389. domUtils.remove(node, true);
  24390. }
  24391. } else {
  24392. var common = domUtils.getCommonAncestor(bk.start, bk.end),
  24393. nodes = domUtils.getElementsByTagName(common, tagName);
  24394. if (new RegExp(tagName, "i").test(common.tagName)) {
  24395. nodes.push(common);
  24396. }
  24397. for (var i = 0, ni; (ni = nodes[i++]); ) {
  24398. if (ni.getAttribute("label") == obj.label) {
  24399. var ps = domUtils.getPosition(ni, bk.start),
  24400. pe = domUtils.getPosition(ni, bk.end);
  24401. if (
  24402. (ps & domUtils.POSITION_FOLLOWING ||
  24403. ps & domUtils.POSITION_CONTAINS) &&
  24404. (pe & domUtils.POSITION_PRECEDING ||
  24405. pe & domUtils.POSITION_CONTAINS)
  24406. )
  24407. if (dtd.$block[tagName]) {
  24408. var fillNode = me.document.createElement("p");
  24409. domUtils.moveChild(ni, fillNode);
  24410. ni.parentNode.insertBefore(fillNode, ni);
  24411. }
  24412. domUtils.remove(ni, true);
  24413. }
  24414. }
  24415. node = domUtils.findParent(
  24416. common,
  24417. function(node) {
  24418. return node.getAttribute("label") == obj.label;
  24419. },
  24420. true
  24421. );
  24422. if (node) {
  24423. domUtils.remove(node, true);
  24424. }
  24425. }
  24426. range.moveToBookmark(bk).select();
  24427. } else {
  24428. if (dtd.$block[tagName]) {
  24429. this.execCommand("paragraph", tagName, tmpObj, "customstyle");
  24430. range = me.selection.getRange();
  24431. if (!range.collapsed) {
  24432. range.collapse();
  24433. node = domUtils.findParent(
  24434. me.selection.getStart(),
  24435. function(node) {
  24436. return node.getAttribute("label") == obj.label;
  24437. },
  24438. true
  24439. );
  24440. var pNode = me.document.createElement("p");
  24441. domUtils.insertAfter(node, pNode);
  24442. domUtils.fillNode(me.document, pNode);
  24443. range.setStart(pNode, 0).setCursor();
  24444. }
  24445. } else {
  24446. range = me.selection.getRange();
  24447. if (range.collapsed) {
  24448. node = me.document.createElement(tagName);
  24449. domUtils.setAttributes(node, tmpObj);
  24450. range.insertNode(node).setStart(node, 0).setCursor();
  24451. return;
  24452. }
  24453. bk = range.createBookmark();
  24454. range.applyInlineStyle(tagName, tmpObj).moveToBookmark(bk).select();
  24455. }
  24456. }
  24457. },
  24458. queryCommandValue: function() {
  24459. var parent = domUtils.filterNodeList(
  24460. this.selection.getStartElementPath(),
  24461. function(node) {
  24462. return node.getAttribute("label");
  24463. }
  24464. );
  24465. return parent ? parent.getAttribute("label") : "";
  24466. }
  24467. };
  24468. //当去掉customstyle是,如果是块元素,用p代替
  24469. me.addListener("keyup", function(type, evt) {
  24470. var keyCode = evt.keyCode || evt.which;
  24471. if (keyCode == 32 || keyCode == 13) {
  24472. var range = me.selection.getRange();
  24473. if (range.collapsed) {
  24474. var node = domUtils.findParent(
  24475. me.selection.getStart(),
  24476. function(node) {
  24477. return node.getAttribute("label");
  24478. },
  24479. true
  24480. );
  24481. if (node && dtd.$block[node.tagName] && domUtils.isEmptyNode(node)) {
  24482. var p = me.document.createElement("p");
  24483. domUtils.insertAfter(node, p);
  24484. domUtils.fillNode(me.document, p);
  24485. domUtils.remove(node);
  24486. range.setStart(p, 0).setCursor();
  24487. }
  24488. }
  24489. }
  24490. });
  24491. };
  24492. // plugins/catchremoteimage.js
  24493. ///import core
  24494. ///commands 远程图片抓取
  24495. ///commandsName catchRemoteImage,catchremoteimageenable
  24496. ///commandsTitle 远程图片抓取
  24497. /**
  24498. * 远程图片抓取,当开启本插件时所有不符合本地域名的图片都将被抓取成为本地服务器上的图片
  24499. */
  24500. UE.plugins["catchremoteimage"] = function() {
  24501. var me = this,
  24502. ajax = UE.ajax;
  24503. /* 设置默认值 */
  24504. if (me.options.catchRemoteImageEnable === false) return;
  24505. me.setOpt({
  24506. catchRemoteImageEnable: false
  24507. });
  24508. me.addListener("afterpaste", function() {
  24509. me.fireEvent("catchRemoteImage");
  24510. });
  24511. me.addListener("catchRemoteImage", function() {
  24512. var catcherLocalDomain = me.getOpt("catcherLocalDomain"),
  24513. catcherActionUrl = me.getActionUrl(me.getOpt("catcherActionName")),
  24514. catcherUrlPrefix = me.getOpt("catcherUrlPrefix"),
  24515. catcherFieldName = me.getOpt("catcherFieldName");
  24516. var remoteImages = [],
  24517. loadingIMG = me.options.themePath + me.options.theme + '/images/spacer.gif',
  24518. imgs = me.document.querySelectorAll('[style*="url"],img'),
  24519. test = function(src, urls) {
  24520. if (src.indexOf(location.host) != -1 || /(^\.)|(^\/)/.test(src)) {
  24521. return true;
  24522. }
  24523. if (urls) {
  24524. for (var j = 0, url; (url = urls[j++]); ) {
  24525. if (src.indexOf(url) !== -1) {
  24526. return true;
  24527. }
  24528. }
  24529. }
  24530. return false;
  24531. };
  24532. for (var i = 0, ci; (ci = imgs[i++]); ) {
  24533. if (ci.getAttribute("word_img")) {
  24534. continue;
  24535. }
  24536. if(ci.nodeName == "IMG"){
  24537. var src = ci.getAttribute("_src") || ci.src || "";
  24538. if (/^(https?|ftp):/i.test(src) && !test(src, catcherLocalDomain)) {
  24539. remoteImages.push(src);
  24540. // 添加上传时的uploading动画
  24541. domUtils.setAttributes(ci, {
  24542. class: "loadingclass",
  24543. _src: src,
  24544. src: loadingIMG
  24545. })
  24546. }
  24547. } else {
  24548. // 获取背景图片url
  24549. var backgroundImageurl = ci.style.cssText.replace(/.*\s?url\([\'\"]?/, '').replace(/[\'\"]?\).*/, '');
  24550. if (/^(https?|ftp):/i.test(backgroundImageurl) && !test(backgroundImageurl, catcherLocalDomain)) {
  24551. remoteImages.push(backgroundImageurl);
  24552. ci.style.cssText = ci.style.cssText.replace(backgroundImageurl, loadingIMG);
  24553. domUtils.setAttributes(ci, {
  24554. "data-background": backgroundImageurl
  24555. })
  24556. }
  24557. }
  24558. }
  24559. if (remoteImages.length) {
  24560. catchremoteimage(remoteImages, {
  24561. //成功抓取
  24562. success: function(r) {
  24563. try {
  24564. var info = r.state !== undefined
  24565. ? r
  24566. : eval("(" + r.responseText + ")");
  24567. } catch (e) {
  24568. return;
  24569. }
  24570. /* 获取源路径和新路径 */
  24571. var i,
  24572. j,
  24573. ci,
  24574. cj,
  24575. oldSrc,
  24576. newSrc,
  24577. list = info.list;
  24578. /* 抓取失败统计 */
  24579. var catchFailList = [];
  24580. /* 抓取成功统计 */
  24581. var catchSuccessList = [];
  24582. /* 抓取失败时显示的图片 */
  24583. var failIMG = me.options.themePath + me.options.theme + '/images/img-cracked.png';
  24584. for (i = 0; ci = imgs[i++];) {
  24585. oldSrc = ci.getAttribute("_src") || ci.src || "";
  24586. oldBgIMG = ci.getAttribute("data-background") || "";
  24587. for (j = 0; cj = list[j++];) {
  24588. if (oldSrc == cj.source && cj.state == "SUCCESS") {
  24589. newSrc = catcherUrlPrefix + cj.url;
  24590. // 上传成功是删除uploading动画
  24591. domUtils.removeClasses( ci, "loadingclass" );
  24592. domUtils.setAttributes(ci, {
  24593. "src": newSrc,
  24594. "_src": newSrc,
  24595. "data-catchResult":"img_catchSuccess" // 添加catch成功标记
  24596. });
  24597. catchSuccessList.push(ci);
  24598. break;
  24599. } else if (oldSrc == cj.source && cj.state == "FAIL") {
  24600. // 替换成统一的失败图片
  24601. domUtils.removeClasses( ci, "loadingclass" );
  24602. domUtils.setAttributes(ci, {
  24603. "src": failIMG,
  24604. "_src": failIMG,
  24605. "data-catchResult":"img_catchFail" // 添加catch失败标记
  24606. });
  24607. catchFailList.push(ci);
  24608. break;
  24609. } else if (oldBgIMG == cj.source && cj.state == "SUCCESS") {
  24610. newBgIMG = catcherUrlPrefix + cj.url;
  24611. ci.style.cssText = ci.style.cssText.replace(loadingIMG, newBgIMG);
  24612. domUtils.removeAttributes(ci,"data-background");
  24613. domUtils.setAttributes(ci, {
  24614. "data-catchResult":"img_catchSuccess" // 添加catch成功标记
  24615. });
  24616. catchSuccessList.push(ci);
  24617. break;
  24618. } else if (oldBgIMG == cj.source && cj.state == "FAIL"){
  24619. ci.style.cssText = ci.style.cssText.replace(loadingIMG, failIMG);
  24620. domUtils.removeAttributes(ci,"data-background");
  24621. domUtils.setAttributes(ci, {
  24622. "data-catchResult":"img_catchFail" // 添加catch失败标记
  24623. });
  24624. catchFailList.push(ci);
  24625. break;
  24626. }
  24627. }
  24628. }
  24629. // 监听事件添加成功抓取和抓取失败的dom列表参数
  24630. me.fireEvent('catchremotesuccess',catchSuccessList,catchFailList);
  24631. },
  24632. //回调失败,本次请求超时
  24633. error: function() {
  24634. me.fireEvent("catchremoteerror");
  24635. }
  24636. });
  24637. }
  24638. function catchremoteimage(imgs, callbacks) {
  24639. var params =
  24640. utils.serializeParam(me.queryCommandValue("serverparam")) || "",
  24641. url = utils.formatUrl(
  24642. catcherActionUrl +
  24643. (catcherActionUrl.indexOf("?") == -1 ? "?" : "&") +
  24644. params
  24645. ),
  24646. isJsonp = utils.isCrossDomainUrl(url),
  24647. opt = {
  24648. method: "POST",
  24649. dataType: isJsonp ? "jsonp" : "",
  24650. timeout: 60000, //单位:毫秒,回调请求超时设置。目标用户如果网速不是很快的话此处建议设置一个较大的数值
  24651. onsuccess: callbacks["success"],
  24652. onerror: callbacks["error"]
  24653. };
  24654. opt[catcherFieldName] = imgs;
  24655. ajax.request(url, opt);
  24656. }
  24657. });
  24658. };
  24659. // plugins/snapscreen.js
  24660. /**
  24661. * 截屏插件,为UEditor提供插入支持
  24662. * @file
  24663. * @since 1.4.2
  24664. */
  24665. UE.plugin.register("snapscreen", function() {
  24666. var me = this;
  24667. var snapplugin;
  24668. function getLocation(url) {
  24669. var search,
  24670. a = document.createElement("a"),
  24671. params = utils.serializeParam(me.queryCommandValue("serverparam")) || "";
  24672. a.href = url;
  24673. if (browser.ie) {
  24674. a.href = a.href;
  24675. }
  24676. search = a.search;
  24677. if (params) {
  24678. search = search + (search.indexOf("?") == -1 ? "?" : "&") + params;
  24679. search = search.replace(/[&]+/gi, "&");
  24680. }
  24681. return {
  24682. port: a.port,
  24683. hostname: a.hostname,
  24684. path: a.pathname + search || +a.hash
  24685. };
  24686. }
  24687. return {
  24688. commands: {
  24689. /**
  24690. * 字体背景颜色
  24691. * @command snapscreen
  24692. * @method execCommand
  24693. * @param { String } cmd 命令字符串
  24694. * @example
  24695. * ```javascript
  24696. * editor.execCommand('snapscreen');
  24697. * ```
  24698. */
  24699. snapscreen: {
  24700. execCommand: function(cmd) {
  24701. var url, local, res;
  24702. var lang = me.getLang("snapScreen_plugin");
  24703. if (!snapplugin) {
  24704. var container = me.container;
  24705. var doc = me.container.ownerDocument || me.container.document;
  24706. snapplugin = doc.createElement("object");
  24707. try {
  24708. snapplugin.type = "application/x-pluginbaidusnap";
  24709. } catch (e) {
  24710. return;
  24711. }
  24712. snapplugin.style.cssText =
  24713. "position:absolute;left:-9999px;width:0;height:0;";
  24714. snapplugin.setAttribute("width", "0");
  24715. snapplugin.setAttribute("height", "0");
  24716. container.appendChild(snapplugin);
  24717. }
  24718. function onSuccess(rs) {
  24719. try {
  24720. rs = eval("(" + rs + ")");
  24721. if (rs.state == "SUCCESS") {
  24722. var opt = me.options;
  24723. me.execCommand("insertimage", {
  24724. src: opt.snapscreenUrlPrefix + rs.url,
  24725. _src: opt.snapscreenUrlPrefix + rs.url,
  24726. alt: rs.title || "",
  24727. floatStyle: opt.snapscreenImgAlign
  24728. });
  24729. } else {
  24730. alert(rs.state);
  24731. }
  24732. } catch (e) {
  24733. alert(lang.callBackErrorMsg);
  24734. }
  24735. }
  24736. url = me.getActionUrl(me.getOpt("snapscreenActionName"));
  24737. local = getLocation(url);
  24738. setTimeout(function() {
  24739. try {
  24740. res = snapplugin.saveSnapshot(
  24741. local.hostname,
  24742. local.path,
  24743. local.port
  24744. );
  24745. } catch (e) {
  24746. me.ui._dialogs["snapscreenDialog"].open();
  24747. return;
  24748. }
  24749. onSuccess(res);
  24750. }, 50);
  24751. },
  24752. queryCommandState: function() {
  24753. return navigator.userAgent.indexOf("Windows", 0) != -1 ? 0 : -1;
  24754. }
  24755. }
  24756. }
  24757. };
  24758. });
  24759. // plugins/insertparagraph.js
  24760. /**
  24761. * 插入段落
  24762. * @file
  24763. * @since 1.2.6.1
  24764. */
  24765. /**
  24766. * 插入段落
  24767. * @command insertparagraph
  24768. * @method execCommand
  24769. * @param { String } cmd 命令字符串
  24770. * @example
  24771. * ```javascript
  24772. * //editor是编辑器实例
  24773. * editor.execCommand( 'insertparagraph' );
  24774. * ```
  24775. */
  24776. UE.commands["insertparagraph"] = {
  24777. execCommand: function(cmdName, front) {
  24778. var me = this,
  24779. range = me.selection.getRange(),
  24780. start = range.startContainer,
  24781. tmpNode;
  24782. while (start) {
  24783. if (domUtils.isBody(start)) {
  24784. break;
  24785. }
  24786. tmpNode = start;
  24787. start = start.parentNode;
  24788. }
  24789. if (tmpNode) {
  24790. var p = me.document.createElement("p");
  24791. if (front) {
  24792. tmpNode.parentNode.insertBefore(p, tmpNode);
  24793. } else {
  24794. tmpNode.parentNode.insertBefore(p, tmpNode.nextSibling);
  24795. }
  24796. domUtils.fillNode(me.document, p);
  24797. range.setStart(p, 0).setCursor(false, true);
  24798. }
  24799. }
  24800. };
  24801. // plugins/webapp.js
  24802. /**
  24803. * 百度应用
  24804. * @file
  24805. * @since 1.2.6.1
  24806. */
  24807. /**
  24808. * 插入百度应用
  24809. * @command webapp
  24810. * @method execCommand
  24811. * @remind 需要百度APPKey
  24812. * @remind 百度应用主页: <a href="http://app.baidu.com/" target="_blank">http://app.baidu.com/</a>
  24813. * @param { Object } appOptions 应用所需的参数项, 支持的key有: title=>应用标题, width=>应用容器宽度,
  24814. * height=>应用容器高度,logo=>应用logo,url=>应用地址
  24815. * @example
  24816. * ```javascript
  24817. * //editor是编辑器实例
  24818. * //在编辑器里插入一个“植物大战僵尸”的APP
  24819. * editor.execCommand( 'webapp' , {
  24820. * title: '植物大战僵尸',
  24821. * width: 560,
  24822. * height: 465,
  24823. * logo: '应用展示的图片',
  24824. * url: '百度应用的地址'
  24825. * } );
  24826. * ```
  24827. */
  24828. //UE.plugins['webapp'] = function () {
  24829. // var me = this;
  24830. // function createInsertStr( obj, toIframe, addParagraph ) {
  24831. // return !toIframe ?
  24832. // (addParagraph ? '<p>' : '') + '<img title="'+obj.title+'" width="' + obj.width + '" height="' + obj.height + '"' +
  24833. // ' 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 + '" />' +
  24834. // (addParagraph ? '</p>' : '')
  24835. // :
  24836. // '<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>';
  24837. // }
  24838. //
  24839. // function switchImgAndIframe( img2frame ) {
  24840. // var tmpdiv,
  24841. // nodes = domUtils.getElementsByTagName( me.document, !img2frame ? "iframe" : "img" );
  24842. // for ( var i = 0, node; node = nodes[i++]; ) {
  24843. // if ( node.className != "edui-faked-webapp" ){
  24844. // continue;
  24845. // }
  24846. // tmpdiv = me.document.createElement( "div" );
  24847. // 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 );
  24848. // node.parentNode.replaceChild( tmpdiv.firstChild, node );
  24849. // }
  24850. // }
  24851. //
  24852. // me.addListener( "beforegetcontent", function () {
  24853. // switchImgAndIframe( true );
  24854. // } );
  24855. // me.addListener( 'aftersetcontent', function () {
  24856. // switchImgAndIframe( false );
  24857. // } );
  24858. // me.addListener( 'aftergetcontent', function ( cmdName ) {
  24859. // if ( cmdName == 'aftergetcontent' && me.queryCommandState( 'source' ) ){
  24860. // return;
  24861. // }
  24862. // switchImgAndIframe( false );
  24863. // } );
  24864. //
  24865. // me.commands['webapp'] = {
  24866. // execCommand:function ( cmd, obj ) {
  24867. // me.execCommand( "inserthtml", createInsertStr( obj, false,true ) );
  24868. // }
  24869. // };
  24870. //};
  24871. UE.plugin.register("webapp", function() {
  24872. var me = this;
  24873. function createInsertStr(obj, toEmbed) {
  24874. return !toEmbed
  24875. ? '<img title="' +
  24876. obj.title +
  24877. '" width="' +
  24878. obj.width +
  24879. '" height="' +
  24880. obj.height +
  24881. '"' +
  24882. ' src="' +
  24883. me.options.UEDITOR_HOME_URL +
  24884. 'themes/notadd/images/spacer.gif" _logo_url="' +
  24885. obj.logo +
  24886. '" style="background:url(' +
  24887. obj.logo +
  24888. ') no-repeat center center; border:1px solid gray;" class="edui-faked-webapp" _url="' +
  24889. obj.url +
  24890. '" ' +
  24891. (obj.align && !obj.cssfloat ? 'align="' + obj.align + '"' : "") +
  24892. (obj.cssfloat ? 'style="float:' + obj.cssfloat + '"' : "") +
  24893. "/>"
  24894. : '<iframe class="edui-faked-webapp" title="' +
  24895. obj.title +
  24896. '" ' +
  24897. (obj.align && !obj.cssfloat ? 'align="' + obj.align + '"' : "") +
  24898. (obj.cssfloat ? 'style="float:' + obj.cssfloat + '"' : "") +
  24899. 'width="' +
  24900. obj.width +
  24901. '" height="' +
  24902. obj.height +
  24903. '" scrolling="no" frameborder="0" src="' +
  24904. obj.url +
  24905. '" logo_url = "' +
  24906. obj.logo +
  24907. '"></iframe>';
  24908. }
  24909. return {
  24910. outputRule: function(root) {
  24911. utils.each(root.getNodesByTagName("img"), function(node) {
  24912. var html;
  24913. if (node.getAttr("class") == "edui-faked-webapp") {
  24914. html = createInsertStr(
  24915. {
  24916. title: node.getAttr("title"),
  24917. width: node.getAttr("width"),
  24918. height: node.getAttr("height"),
  24919. align: node.getAttr("align"),
  24920. cssfloat: node.getStyle("float"),
  24921. url: node.getAttr("_url"),
  24922. logo: node.getAttr("_logo_url")
  24923. },
  24924. true
  24925. );
  24926. var embed = UE.uNode.createElement(html);
  24927. node.parentNode.replaceChild(embed, node);
  24928. }
  24929. });
  24930. },
  24931. inputRule: function(root) {
  24932. utils.each(root.getNodesByTagName("iframe"), function(node) {
  24933. if (node.getAttr("class") == "edui-faked-webapp") {
  24934. var img = UE.uNode.createElement(
  24935. createInsertStr({
  24936. title: node.getAttr("title"),
  24937. width: node.getAttr("width"),
  24938. height: node.getAttr("height"),
  24939. align: node.getAttr("align"),
  24940. cssfloat: node.getStyle("float"),
  24941. url: node.getAttr("src"),
  24942. logo: node.getAttr("logo_url")
  24943. })
  24944. );
  24945. node.parentNode.replaceChild(img, node);
  24946. }
  24947. });
  24948. },
  24949. commands: {
  24950. /**
  24951. * 插入百度应用
  24952. * @command webapp
  24953. * @method execCommand
  24954. * @remind 需要百度APPKey
  24955. * @remind 百度应用主页: <a href="http://app.baidu.com/" target="_blank">http://app.baidu.com/</a>
  24956. * @param { Object } appOptions 应用所需的参数项, 支持的key有: title=>应用标题, width=>应用容器宽度,
  24957. * height=>应用容器高度,logo=>应用logo,url=>应用地址
  24958. * @example
  24959. * ```javascript
  24960. * //editor是编辑器实例
  24961. * //在编辑器里插入一个“植物大战僵尸”的APP
  24962. * editor.execCommand( 'webapp' , {
  24963. * title: '植物大战僵尸',
  24964. * width: 560,
  24965. * height: 465,
  24966. * logo: '应用展示的图片',
  24967. * url: '百度应用的地址'
  24968. * } );
  24969. * ```
  24970. */
  24971. webapp: {
  24972. execCommand: function(cmd, obj) {
  24973. var me = this,
  24974. str = createInsertStr(
  24975. utils.extend(obj, {
  24976. align: "none"
  24977. }),
  24978. false
  24979. );
  24980. me.execCommand("inserthtml", str);
  24981. },
  24982. queryCommandState: function() {
  24983. var me = this,
  24984. img = me.selection.getRange().getClosedNode(),
  24985. flag = img && img.className == "edui-faked-webapp";
  24986. return flag ? 1 : 0;
  24987. }
  24988. }
  24989. }
  24990. };
  24991. });
  24992. // plugins/template.js
  24993. ///import core
  24994. ///import plugins\inserthtml.js
  24995. ///import plugins\cleardoc.js
  24996. ///commands 模板
  24997. ///commandsName template
  24998. ///commandsTitle 模板
  24999. ///commandsDialog dialogs\template
  25000. UE.plugins["template"] = function() {
  25001. UE.commands["template"] = {
  25002. execCommand: function(cmd, obj) {
  25003. obj.html && this.execCommand("inserthtml", obj.html);
  25004. }
  25005. };
  25006. this.addListener("click", function(type, evt) {
  25007. var el = evt.target || evt.srcElement,
  25008. range = this.selection.getRange();
  25009. var tnode = domUtils.findParent(
  25010. el,
  25011. function(node) {
  25012. if (node.className && domUtils.hasClass(node, "ue_t")) {
  25013. return node;
  25014. }
  25015. },
  25016. true
  25017. );
  25018. tnode && range.selectNode(tnode).shrinkBoundary().select();
  25019. });
  25020. this.addListener("keydown", function(type, evt) {
  25021. var range = this.selection.getRange();
  25022. if (!range.collapsed) {
  25023. if (!evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey) {
  25024. var tnode = domUtils.findParent(
  25025. range.startContainer,
  25026. function(node) {
  25027. if (node.className && domUtils.hasClass(node, "ue_t")) {
  25028. return node;
  25029. }
  25030. },
  25031. true
  25032. );
  25033. if (tnode) {
  25034. domUtils.removeClasses(tnode, ["ue_t"]);
  25035. }
  25036. }
  25037. }
  25038. });
  25039. };
  25040. // plugins/music.js
  25041. /**
  25042. * 插入音乐命令
  25043. * @file
  25044. */
  25045. UE.plugin.register("music", function() {
  25046. var me = this;
  25047. function creatInsertStr(url, width, height, align, cssfloat, toEmbed) {
  25048. return !toEmbed
  25049. ? "<img " +
  25050. (align && !cssfloat ? 'align="' + align + '"' : "") +
  25051. (cssfloat ? 'style="float:' + cssfloat + '"' : "") +
  25052. ' width="' +
  25053. width +
  25054. '" height="' +
  25055. height +
  25056. '" _url="' +
  25057. url +
  25058. '" class="edui-faked-music"' +
  25059. ' src="' +
  25060. me.options.langPath +
  25061. me.options.lang +
  25062. '/images/music.png" />'
  25063. : '<embed type="application/x-shockwave-flash" class="edui-faked-music" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  25064. ' src="' +
  25065. url +
  25066. '" width="' +
  25067. width +
  25068. '" height="' +
  25069. height +
  25070. '" ' +
  25071. (align && !cssfloat ? 'align="' + align + '"' : "") +
  25072. (cssfloat ? 'style="float:' + cssfloat + '"' : "") +
  25073. ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >';
  25074. }
  25075. return {
  25076. outputRule: function(root) {
  25077. utils.each(root.getNodesByTagName("img"), function(node) {
  25078. var html;
  25079. if (node.getAttr("class") == "edui-faked-music") {
  25080. var cssfloat = node.getStyle("float");
  25081. var align = node.getAttr("align");
  25082. html = creatInsertStr(
  25083. node.getAttr("_url"),
  25084. node.getAttr("width"),
  25085. node.getAttr("height"),
  25086. align,
  25087. cssfloat,
  25088. true
  25089. );
  25090. var embed = UE.uNode.createElement(html);
  25091. node.parentNode.replaceChild(embed, node);
  25092. }
  25093. });
  25094. },
  25095. inputRule: function(root) {
  25096. utils.each(root.getNodesByTagName("embed"), function(node) {
  25097. if (node.getAttr("class") == "edui-faked-music") {
  25098. var cssfloat = node.getStyle("float");
  25099. var align = node.getAttr("align");
  25100. html = creatInsertStr(
  25101. node.getAttr("src"),
  25102. node.getAttr("width"),
  25103. node.getAttr("height"),
  25104. align,
  25105. cssfloat,
  25106. false
  25107. );
  25108. var img = UE.uNode.createElement(html);
  25109. node.parentNode.replaceChild(img, node);
  25110. }
  25111. });
  25112. },
  25113. commands: {
  25114. /**
  25115. * 插入音乐
  25116. * @command music
  25117. * @method execCommand
  25118. * @param { Object } musicOptions 插入音乐的参数项, 支持的key有: url=>音乐地址;
  25119. * width=>音乐容器宽度;height=>音乐容器高度;align=>音乐文件的对齐方式, 可选值有: left, center, right, none
  25120. * @example
  25121. * ```javascript
  25122. * //editor是编辑器实例
  25123. * //在编辑器里插入一个“植物大战僵尸”的APP
  25124. * editor.execCommand( 'music' , {
  25125. * width: 400,
  25126. * height: 95,
  25127. * align: "center",
  25128. * url: "音乐地址"
  25129. * } );
  25130. * ```
  25131. */
  25132. music: {
  25133. execCommand: function(cmd, musicObj) {
  25134. var me = this,
  25135. str = creatInsertStr(
  25136. musicObj.url,
  25137. musicObj.width || 400,
  25138. musicObj.height || 95,
  25139. "none",
  25140. false
  25141. );
  25142. me.execCommand("inserthtml", str);
  25143. },
  25144. queryCommandState: function() {
  25145. var me = this,
  25146. img = me.selection.getRange().getClosedNode(),
  25147. flag = img && img.className == "edui-faked-music";
  25148. return flag ? 1 : 0;
  25149. }
  25150. }
  25151. }
  25152. };
  25153. });
  25154. // plugins/autoupload.js
  25155. /**
  25156. * @description
  25157. * 1.拖放文件到编辑区域,自动上传并插入到选区
  25158. * 2.插入粘贴板的图片,自动上传并插入到选区
  25159. * @author Jinqn
  25160. * @date 2013-10-14
  25161. */
  25162. UE.plugin.register("autoupload", function() {
  25163. function sendAndInsertFile(file, editor) {
  25164. var me = editor;
  25165. //模拟数据
  25166. var fieldName,
  25167. urlPrefix,
  25168. maxSize,
  25169. allowFiles,
  25170. actionUrl,
  25171. loadingHtml,
  25172. errorHandler,
  25173. successHandler,
  25174. filetype = /image\/\w+/i.test(file.type) ? "image" : "file",
  25175. loadingId = "loading_" + (+new Date()).toString(36);
  25176. fieldName = me.getOpt(filetype + "FieldName");
  25177. urlPrefix = me.getOpt(filetype + "UrlPrefix");
  25178. maxSize = me.getOpt(filetype + "MaxSize");
  25179. allowFiles = me.getOpt(filetype + "AllowFiles");
  25180. actionUrl = me.getActionUrl(me.getOpt(filetype + "ActionName"));
  25181. errorHandler = function(title) {
  25182. var loader = me.document.getElementById(loadingId);
  25183. loader && domUtils.remove(loader);
  25184. me.fireEvent("showmessage", {
  25185. id: loadingId,
  25186. content: title,
  25187. type: "error",
  25188. timeout: 4000
  25189. });
  25190. };
  25191. if (filetype == "image") {
  25192. loadingHtml =
  25193. '<img class="loadingclass" id="' +
  25194. loadingId +
  25195. '" src="' +
  25196. me.options.themePath +
  25197. me.options.theme +
  25198. '/images/spacer.gif">';
  25199. successHandler = function(data) {
  25200. var link = urlPrefix + data.url,
  25201. loader = me.document.getElementById(loadingId);
  25202. if (loader) {
  25203. domUtils.removeClasses(loader, "loadingclass");
  25204. loader.setAttribute("src", link);
  25205. loader.setAttribute("_src", link);
  25206. loader.setAttribute("alt", data.original || "");
  25207. loader.removeAttribute("id");
  25208. me.trigger("contentchange", loader);
  25209. }
  25210. };
  25211. } else {
  25212. loadingHtml =
  25213. "<p>" +
  25214. '<img class="loadingclass" id="' +
  25215. loadingId +
  25216. '" src="' +
  25217. me.options.themePath +
  25218. me.options.theme +
  25219. '/images/spacer.gif">' +
  25220. "</p>";
  25221. successHandler = function(data) {
  25222. var link = urlPrefix + data.url,
  25223. loader = me.document.getElementById(loadingId);
  25224. var rng = me.selection.getRange(),
  25225. bk = rng.createBookmark();
  25226. rng.selectNode(loader).select();
  25227. me.execCommand("insertfile", { url: link });
  25228. rng.moveToBookmark(bk).select();
  25229. };
  25230. }
  25231. /* 插入loading的占位符 */
  25232. me.execCommand("inserthtml", loadingHtml);
  25233. /* 判断后端配置是否没有加载成功 */
  25234. if (!me.getOpt(filetype + "ActionName")) {
  25235. errorHandler(me.getLang("autoupload.errorLoadConfig"));
  25236. return;
  25237. }
  25238. /* 判断文件大小是否超出限制 */
  25239. if (file.size > maxSize) {
  25240. errorHandler(me.getLang("autoupload.exceedSizeError"));
  25241. return;
  25242. }
  25243. /* 判断文件格式是否超出允许 */
  25244. var fileext = file.name ? file.name.substr(file.name.lastIndexOf(".")) : "";
  25245. if (
  25246. (fileext && filetype != "image") ||
  25247. (allowFiles &&
  25248. (allowFiles.join("") + ".").indexOf(fileext.toLowerCase() + ".") == -1)
  25249. ) {
  25250. errorHandler(me.getLang("autoupload.exceedTypeError"));
  25251. return;
  25252. }
  25253. /* 创建Ajax并提交 */
  25254. var xhr = new XMLHttpRequest(),
  25255. fd = new FormData(),
  25256. params = utils.serializeParam(me.queryCommandValue("serverparam")) || "",
  25257. url = utils.formatUrl(
  25258. actionUrl + (actionUrl.indexOf("?") == -1 ? "?" : "&") + params
  25259. );
  25260. fd.append(
  25261. fieldName,
  25262. file,
  25263. file.name || "blob." + file.type.substr("image/".length)
  25264. );
  25265. fd.append("type", "ajax");
  25266. xhr.open("post", url, true);
  25267. xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  25268. xhr.addEventListener("load", function(e) {
  25269. try {
  25270. var json = new Function("return " + utils.trim(e.target.response))();
  25271. if (json.state == "SUCCESS" && json.url) {
  25272. successHandler(json);
  25273. } else {
  25274. errorHandler(json.state);
  25275. }
  25276. } catch (er) {
  25277. errorHandler(me.getLang("autoupload.loadError"));
  25278. }
  25279. });
  25280. xhr.send(fd);
  25281. }
  25282. function getPasteImage(e) {
  25283. return e.clipboardData &&
  25284. e.clipboardData.items &&
  25285. e.clipboardData.items.length == 1 &&
  25286. /^image\//.test(e.clipboardData.items[0].type)
  25287. ? e.clipboardData.items
  25288. : null;
  25289. }
  25290. function getDropImage(e) {
  25291. return e.dataTransfer && e.dataTransfer.files ? e.dataTransfer.files : null;
  25292. }
  25293. return {
  25294. outputRule: function(root) {
  25295. utils.each(root.getNodesByTagName("img"), function(n) {
  25296. if (/\b(loaderrorclass)|(bloaderrorclass)\b/.test(n.getAttr("class"))) {
  25297. n.parentNode.removeChild(n);
  25298. }
  25299. });
  25300. utils.each(root.getNodesByTagName("p"), function(n) {
  25301. if (/\bloadpara\b/.test(n.getAttr("class"))) {
  25302. n.parentNode.removeChild(n);
  25303. }
  25304. });
  25305. },
  25306. bindEvents: {
  25307. defaultOptions: {
  25308. //默认间隔时间
  25309. enableDragUpload: true,
  25310. enablePasteUpload: true
  25311. },
  25312. //插入粘贴板的图片,拖放插入图片
  25313. ready: function(e) {
  25314. var me = this;
  25315. if (window.FormData && window.FileReader) {
  25316. var handler = function(e) {
  25317. var hasImg = false,
  25318. items;
  25319. //获取粘贴板文件列表或者拖放文件列表
  25320. items = e.type == "paste" ? getPasteImage(e) : getDropImage(e);
  25321. if (items) {
  25322. var len = items.length,
  25323. file;
  25324. while (len--) {
  25325. file = items[len];
  25326. if (file.getAsFile) file = file.getAsFile();
  25327. if (file && file.size > 0) {
  25328. sendAndInsertFile(file, me);
  25329. hasImg = true;
  25330. }
  25331. }
  25332. hasImg && e.preventDefault();
  25333. }
  25334. };
  25335. if (me.getOpt("enablePasteUpload") !== false) {
  25336. domUtils.on(me.body, "paste ", handler);
  25337. }
  25338. if (me.getOpt("enableDragUpload") !== false) {
  25339. domUtils.on(me.body, "drop", handler);
  25340. //取消拖放图片时出现的文字光标位置提示
  25341. domUtils.on(me.body, "dragover", function(e) {
  25342. if (e.dataTransfer.types[0] == "Files") {
  25343. e.preventDefault();
  25344. }
  25345. });
  25346. } else {
  25347. if (browser.gecko) {
  25348. domUtils.on(me.body, "drop", function(e) {
  25349. if (getDropImage(e)) {
  25350. e.preventDefault();
  25351. }
  25352. });
  25353. }
  25354. }
  25355. //设置loading的样式
  25356. utils.cssRule(
  25357. "loading",
  25358. ".loadingclass{display:inline-block;cursor:default;background: url('" +
  25359. this.options.themePath +
  25360. this.options.theme +
  25361. "/images/loading.gif') no-repeat center center transparent;border:1px solid #cccccc;margin-left:1px;height: 22px;width: 22px;}\n" +
  25362. ".loaderrorclass{display:inline-block;cursor:default;background: url('" +
  25363. this.options.themePath +
  25364. this.options.theme +
  25365. "/images/loaderror.png') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;" +
  25366. "}",
  25367. this.document
  25368. );
  25369. }
  25370. }
  25371. }
  25372. };
  25373. });
  25374. // plugins/autosave.js
  25375. UE.plugin.register("autosave", function() {
  25376. var me = this,
  25377. //无限循环保护
  25378. lastSaveTime = new Date(),
  25379. //最小保存间隔时间
  25380. MIN_TIME = 20,
  25381. //auto save key
  25382. saveKey = null;
  25383. function save(editor) {
  25384. var saveData;
  25385. if (new Date() - lastSaveTime < MIN_TIME) {
  25386. return;
  25387. }
  25388. if (!editor.hasContents()) {
  25389. //这里不能调用命令来删除, 会造成事件死循环
  25390. saveKey && me.removePreferences(saveKey);
  25391. return;
  25392. }
  25393. lastSaveTime = new Date();
  25394. editor._saveFlag = null;
  25395. saveData = me.body.innerHTML;
  25396. if (
  25397. editor.fireEvent("beforeautosave", {
  25398. content: saveData
  25399. }) === false
  25400. ) {
  25401. return;
  25402. }
  25403. me.setPreferences(saveKey, saveData);
  25404. editor.fireEvent("afterautosave", {
  25405. content: saveData
  25406. });
  25407. }
  25408. return {
  25409. defaultOptions: {
  25410. //默认间隔时间
  25411. saveInterval: 500,
  25412. enableAutoSave: true
  25413. },
  25414. bindEvents: {
  25415. ready: function() {
  25416. var _suffix = "-drafts-data",
  25417. key = null;
  25418. if (me.key) {
  25419. key = me.key + _suffix;
  25420. } else {
  25421. key = (me.container.parentNode.id || "ue-common") + _suffix;
  25422. }
  25423. //页面地址+编辑器ID 保持唯一
  25424. saveKey =
  25425. (location.protocol + location.host + location.pathname).replace(
  25426. /[.:\/]/g,
  25427. "_"
  25428. ) + key;
  25429. },
  25430. contentchange: function() {
  25431. if (!me.getOpt("enableAutoSave")) {
  25432. return;
  25433. }
  25434. if (!saveKey) {
  25435. return;
  25436. }
  25437. if (me._saveFlag) {
  25438. window.clearTimeout(me._saveFlag);
  25439. }
  25440. if (me.options.saveInterval > 0) {
  25441. me._saveFlag = window.setTimeout(function() {
  25442. save(me);
  25443. }, me.options.saveInterval);
  25444. } else {
  25445. save(me);
  25446. }
  25447. }
  25448. },
  25449. commands: {
  25450. clearlocaldata: {
  25451. execCommand: function(cmd, name) {
  25452. if (saveKey && me.getPreferences(saveKey)) {
  25453. me.removePreferences(saveKey);
  25454. }
  25455. },
  25456. notNeedUndo: true,
  25457. ignoreContentChange: true
  25458. },
  25459. getlocaldata: {
  25460. execCommand: function(cmd, name) {
  25461. return saveKey ? me.getPreferences(saveKey) || "" : "";
  25462. },
  25463. notNeedUndo: true,
  25464. ignoreContentChange: true
  25465. },
  25466. drafts: {
  25467. execCommand: function(cmd, name) {
  25468. if (saveKey) {
  25469. window.setTimeout(function(){
  25470. me.body.innerHTML =
  25471. me.getPreferences(saveKey) || "<p>" + domUtils.fillHtml + "</p>";
  25472. // me.focus(true);
  25473. }, 0);
  25474. }
  25475. },
  25476. queryCommandState: function() {
  25477. return saveKey ? (me.getPreferences(saveKey) === null ? -1 : 0) : -1;
  25478. },
  25479. notNeedUndo: true,
  25480. ignoreContentChange: true
  25481. }
  25482. }
  25483. };
  25484. });
  25485. // plugins/charts.js
  25486. UE.plugin.register("charts", function() {
  25487. var me = this;
  25488. return {
  25489. bindEvents: {
  25490. chartserror: function() {}
  25491. },
  25492. commands: {
  25493. charts: {
  25494. execCommand: function(cmd, data) {
  25495. var tableNode = domUtils.findParentByTagName(
  25496. this.selection.getRange().startContainer,
  25497. "table",
  25498. true
  25499. ),
  25500. flagText = [],
  25501. config = {};
  25502. if (!tableNode) {
  25503. return false;
  25504. }
  25505. if (!validData(tableNode)) {
  25506. me.fireEvent("chartserror");
  25507. return false;
  25508. }
  25509. config.title = data.title || "";
  25510. config.subTitle = data.subTitle || "";
  25511. config.xTitle = data.xTitle || "";
  25512. config.yTitle = data.yTitle || "";
  25513. config.suffix = data.suffix || "";
  25514. config.tip = data.tip || "";
  25515. //数据对齐方式
  25516. config.dataFormat = data.tableDataFormat || "";
  25517. //图表类型
  25518. config.chartType = data.chartType || 0;
  25519. for (var key in config) {
  25520. if (!config.hasOwnProperty(key)) {
  25521. continue;
  25522. }
  25523. flagText.push(key + ":" + config[key]);
  25524. }
  25525. tableNode.setAttribute("data-chart", flagText.join(";"));
  25526. domUtils.addClass(tableNode, "edui-charts-table");
  25527. },
  25528. queryCommandState: function(cmd, name) {
  25529. var tableNode = domUtils.findParentByTagName(
  25530. this.selection.getRange().startContainer,
  25531. "table",
  25532. true
  25533. );
  25534. return tableNode && validData(tableNode) ? 0 : -1;
  25535. }
  25536. }
  25537. },
  25538. inputRule: function(root) {
  25539. utils.each(root.getNodesByTagName("table"), function(tableNode) {
  25540. if (tableNode.getAttr("data-chart") !== undefined) {
  25541. tableNode.setAttr("style");
  25542. }
  25543. });
  25544. },
  25545. outputRule: function(root) {
  25546. utils.each(root.getNodesByTagName("table"), function(tableNode) {
  25547. if (tableNode.getAttr("data-chart") !== undefined) {
  25548. tableNode.setAttr("style", "display: none;");
  25549. }
  25550. });
  25551. }
  25552. };
  25553. function validData(table) {
  25554. var firstRows = null,
  25555. cellCount = 0;
  25556. //行数不够
  25557. if (table.rows.length < 2) {
  25558. return false;
  25559. }
  25560. //列数不够
  25561. if (table.rows[0].cells.length < 2) {
  25562. return false;
  25563. }
  25564. //第一行所有cell必须是th
  25565. firstRows = table.rows[0].cells;
  25566. cellCount = firstRows.length;
  25567. for (var i = 0, cell; (cell = firstRows[i]); i++) {
  25568. if (cell.tagName.toLowerCase() !== "th") {
  25569. return false;
  25570. }
  25571. }
  25572. for (var i = 1, row; (row = table.rows[i]); i++) {
  25573. //每行单元格数不匹配, 返回false
  25574. if (row.cells.length != cellCount) {
  25575. return false;
  25576. }
  25577. //第一列不是th也返回false
  25578. if (row.cells[0].tagName.toLowerCase() !== "th") {
  25579. return false;
  25580. }
  25581. for (var j = 1, cell; (cell = row.cells[j]); j++) {
  25582. var value = utils.trim(cell.innerText || cell.textContent || "");
  25583. value = value
  25584. .replace(new RegExp(UE.dom.domUtils.fillChar, "g"), "")
  25585. .replace(/^\s+|\s+$/g, "");
  25586. //必须是数字
  25587. if (!/^\d*\.?\d+$/.test(value)) {
  25588. return false;
  25589. }
  25590. }
  25591. }
  25592. return true;
  25593. }
  25594. });
  25595. // plugins/section.js
  25596. /**
  25597. * 目录大纲支持插件
  25598. * @file
  25599. * @since 1.3.0
  25600. */
  25601. UE.plugin.register("section", function() {
  25602. /* 目录节点对象 */
  25603. function Section(option) {
  25604. this.tag = "";
  25605. (this.level = -1), (this.dom = null);
  25606. this.nextSection = null;
  25607. this.previousSection = null;
  25608. this.parentSection = null;
  25609. this.startAddress = [];
  25610. this.endAddress = [];
  25611. this.children = [];
  25612. }
  25613. function getSection(option) {
  25614. var section = new Section();
  25615. return utils.extend(section, option);
  25616. }
  25617. function getNodeFromAddress(startAddress, root) {
  25618. var current = root;
  25619. for (var i = 0; i < startAddress.length; i++) {
  25620. if (!current.childNodes) return null;
  25621. current = current.childNodes[startAddress[i]];
  25622. }
  25623. return current;
  25624. }
  25625. var me = this;
  25626. return {
  25627. bindMultiEvents: {
  25628. type: "aftersetcontent afterscencerestore",
  25629. handler: function() {
  25630. me.fireEvent("updateSections");
  25631. }
  25632. },
  25633. bindEvents: {
  25634. /* 初始化、拖拽、粘贴、执行setcontent之后 */
  25635. ready: function() {
  25636. me.fireEvent("updateSections");
  25637. domUtils.on(me.body, "drop paste", function() {
  25638. me.fireEvent("updateSections");
  25639. });
  25640. },
  25641. /* 执行paragraph命令之后 */
  25642. afterexeccommand: function(type, cmd) {
  25643. if (cmd == "paragraph") {
  25644. me.fireEvent("updateSections");
  25645. }
  25646. },
  25647. /* 部分键盘操作,触发updateSections事件 */
  25648. keyup: function(type, e) {
  25649. var me = this,
  25650. range = me.selection.getRange();
  25651. if (range.collapsed != true) {
  25652. me.fireEvent("updateSections");
  25653. } else {
  25654. var keyCode = e.keyCode || e.which;
  25655. if (keyCode == 13 || keyCode == 8 || keyCode == 46) {
  25656. me.fireEvent("updateSections");
  25657. }
  25658. }
  25659. }
  25660. },
  25661. commands: {
  25662. getsections: {
  25663. execCommand: function(cmd, levels) {
  25664. var levelFn = levels || ["h1", "h2", "h3", "h4", "h5", "h6"];
  25665. for (var i = 0; i < levelFn.length; i++) {
  25666. if (typeof levelFn[i] == "string") {
  25667. levelFn[i] = (function(fn) {
  25668. return function(node) {
  25669. return node.tagName == fn.toUpperCase();
  25670. };
  25671. })(levelFn[i]);
  25672. } else if (typeof levelFn[i] != "function") {
  25673. levelFn[i] = function(node) {
  25674. return null;
  25675. };
  25676. }
  25677. }
  25678. function getSectionLevel(node) {
  25679. for (var i = 0; i < levelFn.length; i++) {
  25680. if (levelFn[i](node)) return i;
  25681. }
  25682. return -1;
  25683. }
  25684. var me = this,
  25685. Directory = getSection({ level: -1, title: "root" }),
  25686. previous = Directory;
  25687. function traversal(node, Directory) {
  25688. var level,
  25689. tmpSection = null,
  25690. parent,
  25691. child,
  25692. children = node.childNodes;
  25693. for (var i = 0, len = children.length; i < len; i++) {
  25694. child = children[i];
  25695. level = getSectionLevel(child);
  25696. if (level >= 0) {
  25697. var address = me.selection
  25698. .getRange()
  25699. .selectNode(child)
  25700. .createAddress(true).startAddress,
  25701. current = getSection({
  25702. tag: child.tagName,
  25703. title: child.innerText || child.textContent || "",
  25704. level: level,
  25705. dom: child,
  25706. startAddress: utils.clone(address, []),
  25707. endAddress: utils.clone(address, []),
  25708. children: []
  25709. });
  25710. previous.nextSection = current;
  25711. current.previousSection = previous;
  25712. parent = previous;
  25713. while (level <= parent.level) {
  25714. parent = parent.parentSection;
  25715. }
  25716. current.parentSection = parent;
  25717. parent.children.push(current);
  25718. tmpSection = previous = current;
  25719. } else {
  25720. child.nodeType === 1 && traversal(child, Directory);
  25721. tmpSection &&
  25722. tmpSection.endAddress[tmpSection.endAddress.length - 1]++;
  25723. }
  25724. }
  25725. }
  25726. traversal(me.body, Directory);
  25727. return Directory;
  25728. },
  25729. notNeedUndo: true
  25730. },
  25731. movesection: {
  25732. execCommand: function(cmd, sourceSection, targetSection, isAfter) {
  25733. var me = this,
  25734. targetAddress,
  25735. target;
  25736. if (!sourceSection || !targetSection || targetSection.level == -1)
  25737. return;
  25738. targetAddress = isAfter
  25739. ? targetSection.endAddress
  25740. : targetSection.startAddress;
  25741. target = getNodeFromAddress(targetAddress, me.body);
  25742. /* 判断目标地址是否被源章节包含 */
  25743. if (
  25744. !targetAddress ||
  25745. !target ||
  25746. isContainsAddress(
  25747. sourceSection.startAddress,
  25748. sourceSection.endAddress,
  25749. targetAddress
  25750. )
  25751. )
  25752. return;
  25753. var startNode = getNodeFromAddress(
  25754. sourceSection.startAddress,
  25755. me.body
  25756. ),
  25757. endNode = getNodeFromAddress(sourceSection.endAddress, me.body),
  25758. current,
  25759. nextNode;
  25760. if (isAfter) {
  25761. current = endNode;
  25762. while (
  25763. current &&
  25764. !(
  25765. domUtils.getPosition(startNode, current) &
  25766. domUtils.POSITION_FOLLOWING
  25767. )
  25768. ) {
  25769. nextNode = current.previousSibling;
  25770. domUtils.insertAfter(target, current);
  25771. if (current == startNode) break;
  25772. current = nextNode;
  25773. }
  25774. } else {
  25775. current = startNode;
  25776. while (
  25777. current &&
  25778. !(
  25779. domUtils.getPosition(current, endNode) &
  25780. domUtils.POSITION_FOLLOWING
  25781. )
  25782. ) {
  25783. nextNode = current.nextSibling;
  25784. target.parentNode.insertBefore(current, target);
  25785. if (current == endNode) break;
  25786. current = nextNode;
  25787. }
  25788. }
  25789. me.fireEvent("updateSections");
  25790. /* 获取地址的包含关系 */
  25791. function isContainsAddress(startAddress, endAddress, addressTarget) {
  25792. var isAfterStartAddress = false,
  25793. isBeforeEndAddress = false;
  25794. for (var i = 0; i < startAddress.length; i++) {
  25795. if (i >= addressTarget.length) break;
  25796. if (addressTarget[i] > startAddress[i]) {
  25797. isAfterStartAddress = true;
  25798. break;
  25799. } else if (addressTarget[i] < startAddress[i]) {
  25800. break;
  25801. }
  25802. }
  25803. for (var i = 0; i < endAddress.length; i++) {
  25804. if (i >= addressTarget.length) break;
  25805. if (addressTarget[i] < startAddress[i]) {
  25806. isBeforeEndAddress = true;
  25807. break;
  25808. } else if (addressTarget[i] > startAddress[i]) {
  25809. break;
  25810. }
  25811. }
  25812. return isAfterStartAddress && isBeforeEndAddress;
  25813. }
  25814. }
  25815. },
  25816. deletesection: {
  25817. execCommand: function(cmd, section, keepChildren) {
  25818. var me = this;
  25819. if (!section) return;
  25820. function getNodeFromAddress(startAddress) {
  25821. var current = me.body;
  25822. for (var i = 0; i < startAddress.length; i++) {
  25823. if (!current.childNodes) return null;
  25824. current = current.childNodes[startAddress[i]];
  25825. }
  25826. return current;
  25827. }
  25828. var startNode = getNodeFromAddress(section.startAddress),
  25829. endNode = getNodeFromAddress(section.endAddress),
  25830. current = startNode,
  25831. nextNode;
  25832. if (!keepChildren) {
  25833. while (
  25834. current &&
  25835. domUtils.inDoc(endNode, me.document) &&
  25836. !(
  25837. domUtils.getPosition(current, endNode) &
  25838. domUtils.POSITION_FOLLOWING
  25839. )
  25840. ) {
  25841. nextNode = current.nextSibling;
  25842. domUtils.remove(current);
  25843. current = nextNode;
  25844. }
  25845. } else {
  25846. domUtils.remove(current);
  25847. }
  25848. me.fireEvent("updateSections");
  25849. }
  25850. },
  25851. selectsection: {
  25852. execCommand: function(cmd, section) {
  25853. if (!section && !section.dom) return false;
  25854. var me = this,
  25855. range = me.selection.getRange(),
  25856. address = {
  25857. startAddress: utils.clone(section.startAddress, []),
  25858. endAddress: utils.clone(section.endAddress, [])
  25859. };
  25860. address.endAddress[address.endAddress.length - 1]++;
  25861. range.moveToAddress(address).select().scrollToView();
  25862. return true;
  25863. },
  25864. notNeedUndo: true
  25865. },
  25866. scrolltosection: {
  25867. execCommand: function(cmd, section) {
  25868. if (!section && !section.dom) return false;
  25869. var me = this,
  25870. range = me.selection.getRange(),
  25871. address = {
  25872. startAddress: section.startAddress,
  25873. endAddress: section.endAddress
  25874. };
  25875. address.endAddress[address.endAddress.length - 1]++;
  25876. range.moveToAddress(address).scrollToView();
  25877. return true;
  25878. },
  25879. notNeedUndo: true
  25880. }
  25881. }
  25882. };
  25883. });
  25884. // plugins/simpleupload.js
  25885. /**
  25886. * @description
  25887. * 简单上传:点击按钮,直接选择文件上传
  25888. * @author Jinqn
  25889. * @date 2014-03-31
  25890. */
  25891. UE.plugin.register("simpleupload", function() {
  25892. var me = this,
  25893. isLoaded = false,
  25894. containerBtn;
  25895. function initUploadBtn() {
  25896. var w = containerBtn.offsetWidth || 20,
  25897. h = containerBtn.offsetHeight || 20,
  25898. btnIframe = document.createElement("iframe"),
  25899. btnStyle =
  25900. "display:block;width:" +
  25901. w +
  25902. "px;height:" +
  25903. h +
  25904. "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;";
  25905. domUtils.on(btnIframe, "load", function() {
  25906. var timestrap = (+new Date()).toString(36),
  25907. wrapper,
  25908. btnIframeDoc,
  25909. btnIframeBody;
  25910. btnIframeDoc =
  25911. btnIframe.contentDocument || btnIframe.contentWindow.document;
  25912. btnIframeBody = btnIframeDoc.body;
  25913. wrapper = btnIframeDoc.createElement("div");
  25914. wrapper.innerHTML =
  25915. '<form id="edui_form_' +
  25916. timestrap +
  25917. '" target="edui_iframe_' +
  25918. timestrap +
  25919. '" method="POST" enctype="multipart/form-data" action="' +
  25920. me.getOpt("serverUrl") +
  25921. '" ' +
  25922. 'style="' +
  25923. btnStyle +
  25924. '">' +
  25925. '<input id="edui_input_' +
  25926. timestrap +
  25927. '" type="file" accept="image/*" name="' +
  25928. me.options.imageFieldName +
  25929. '" ' +
  25930. 'style="' +
  25931. btnStyle +
  25932. '">' +
  25933. "</form>" +
  25934. '<iframe id="edui_iframe_' +
  25935. timestrap +
  25936. '" name="edui_iframe_' +
  25937. timestrap +
  25938. '" style="display:none;width:0;height:0;border:0;margin:0;padding:0;position:absolute;"></iframe>';
  25939. wrapper.className = "edui-" + me.options.theme;
  25940. wrapper.id = me.ui.id + "_iframeupload";
  25941. btnIframeBody.style.cssText = btnStyle;
  25942. btnIframeBody.style.width = w + "px";
  25943. btnIframeBody.style.height = h + "px";
  25944. btnIframeBody.appendChild(wrapper);
  25945. if (btnIframeBody.parentNode) {
  25946. btnIframeBody.parentNode.style.width = w + "px";
  25947. btnIframeBody.parentNode.style.height = w + "px";
  25948. }
  25949. var form = btnIframeDoc.getElementById("edui_form_" + timestrap);
  25950. var input = btnIframeDoc.getElementById("edui_input_" + timestrap);
  25951. var iframe = btnIframeDoc.getElementById("edui_iframe_" + timestrap);
  25952. domUtils.on(input, "change", function() {
  25953. if (!input.value) return;
  25954. var loadingId = "loading_" + (+new Date()).toString(36);
  25955. var params =
  25956. utils.serializeParam(me.queryCommandValue("serverparam")) || "";
  25957. var imageActionUrl = me.getActionUrl(me.getOpt("imageActionName"));
  25958. var allowFiles = me.getOpt("imageAllowFiles");
  25959. me.focus();
  25960. me.execCommand(
  25961. "inserthtml",
  25962. '<img class="loadingclass" id="' +
  25963. loadingId +
  25964. '" src="' +
  25965. me.options.themePath +
  25966. me.options.theme +
  25967. '/images/spacer.gif">'
  25968. );
  25969. function callback() {
  25970. try {
  25971. var link,
  25972. json,
  25973. loader,
  25974. body = (iframe.contentDocument || iframe.contentWindow.document)
  25975. .body,
  25976. result = body.innerText || body.textContent || "";
  25977. json = new Function("return " + result)();
  25978. link = me.options.imageUrlPrefix + json.url;
  25979. if (json.state == "SUCCESS" && json.url) {
  25980. loader = me.document.getElementById(loadingId);
  25981. domUtils.removeClasses(loader, "loadingclass");
  25982. domUtils.on(loader,'load',function(){
  25983. me.fireEvent('contentchange');
  25984. });
  25985. loader.setAttribute("src", link);
  25986. loader.setAttribute("_src", link);
  25987. loader.setAttribute("alt", json.original || "");
  25988. loader.removeAttribute("id");
  25989. } else {
  25990. showErrorLoader && showErrorLoader(json.state);
  25991. }
  25992. } catch (er) {
  25993. showErrorLoader &&
  25994. showErrorLoader(me.getLang("simpleupload.loadError"));
  25995. }
  25996. form.reset();
  25997. domUtils.un(iframe, "load", callback);
  25998. }
  25999. function showErrorLoader(title) {
  26000. if (loadingId) {
  26001. var loader = me.document.getElementById(loadingId);
  26002. loader && domUtils.remove(loader);
  26003. me.fireEvent("showmessage", {
  26004. id: loadingId,
  26005. content: title,
  26006. type: "error",
  26007. timeout: 4000
  26008. });
  26009. }
  26010. }
  26011. /* 判断后端配置是否没有加载成功 */
  26012. if (!me.getOpt("imageActionName")) {
  26013. errorHandler(me.getLang("autoupload.errorLoadConfig"));
  26014. return;
  26015. }
  26016. // 判断文件格式是否错误
  26017. var filename = input.value,
  26018. fileext = filename ? filename.substr(filename.lastIndexOf(".")) : "";
  26019. if (
  26020. !fileext ||
  26021. (allowFiles &&
  26022. (allowFiles.join("") + ".").indexOf(fileext.toLowerCase() + ".") ==
  26023. -1)
  26024. ) {
  26025. showErrorLoader(me.getLang("simpleupload.exceedTypeError"));
  26026. return;
  26027. }
  26028. domUtils.on(iframe, "load", callback);
  26029. form.action = utils.formatUrl(
  26030. imageActionUrl +
  26031. (imageActionUrl.indexOf("?") == -1 ? "?" : "&") +
  26032. params
  26033. );
  26034. form.submit();
  26035. });
  26036. var stateTimer;
  26037. me.addListener("selectionchange", function() {
  26038. clearTimeout(stateTimer);
  26039. stateTimer = setTimeout(function() {
  26040. var state = me.queryCommandState("simpleupload");
  26041. if (state == -1) {
  26042. input.disabled = "disabled";
  26043. } else {
  26044. input.disabled = false;
  26045. }
  26046. }, 400);
  26047. });
  26048. isLoaded = true;
  26049. });
  26050. btnIframe.style.cssText = btnStyle;
  26051. containerBtn.appendChild(btnIframe);
  26052. }
  26053. return {
  26054. bindEvents: {
  26055. ready: function() {
  26056. //设置loading的样式
  26057. utils.cssRule(
  26058. "loading",
  26059. ".loadingclass{display:inline-block;cursor:default;background: url('" +
  26060. this.options.themePath +
  26061. this.options.theme +
  26062. "/images/loading.gif') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;}\n" +
  26063. ".loaderrorclass{display:inline-block;cursor:default;background: url('" +
  26064. this.options.themePath +
  26065. this.options.theme +
  26066. "/images/loaderror.png') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;" +
  26067. "}",
  26068. this.document
  26069. );
  26070. },
  26071. /* 初始化简单上传按钮 */
  26072. simpleuploadbtnready: function(type, container) {
  26073. containerBtn = container;
  26074. me.afterConfigReady(initUploadBtn);
  26075. }
  26076. },
  26077. outputRule: function(root) {
  26078. utils.each(root.getNodesByTagName("img"), function(n) {
  26079. if (/\b(loaderrorclass)|(bloaderrorclass)\b/.test(n.getAttr("class"))) {
  26080. n.parentNode.removeChild(n);
  26081. }
  26082. });
  26083. },
  26084. commands: {
  26085. simpleupload: {
  26086. queryCommandState: function() {
  26087. return isLoaded ? 0 : -1;
  26088. }
  26089. }
  26090. }
  26091. };
  26092. });
  26093. // plugins/serverparam.js
  26094. /**
  26095. * 服务器提交的额外参数列表设置插件
  26096. * @file
  26097. * @since 1.2.6.1
  26098. */
  26099. UE.plugin.register("serverparam", function() {
  26100. var me = this,
  26101. serverParam = {};
  26102. return {
  26103. commands: {
  26104. /**
  26105. * 修改服务器提交的额外参数列表,清除所有项
  26106. * @command serverparam
  26107. * @method execCommand
  26108. * @param { String } cmd 命令字符串
  26109. * @example
  26110. * ```javascript
  26111. * editor.execCommand('serverparam');
  26112. * editor.queryCommandValue('serverparam'); //返回空
  26113. * ```
  26114. */
  26115. /**
  26116. * 修改服务器提交的额外参数列表,删除指定项
  26117. * @command serverparam
  26118. * @method execCommand
  26119. * @param { String } cmd 命令字符串
  26120. * @param { String } key 要清除的属性
  26121. * @example
  26122. * ```javascript
  26123. * editor.execCommand('serverparam', 'name'); //删除属性name
  26124. * ```
  26125. */
  26126. /**
  26127. * 修改服务器提交的额外参数列表,使用键值添加项
  26128. * @command serverparam
  26129. * @method execCommand
  26130. * @param { String } cmd 命令字符串
  26131. * @param { String } key 要添加的属性
  26132. * @param { String } value 要添加属性的值
  26133. * @example
  26134. * ```javascript
  26135. * editor.execCommand('serverparam', 'name', 'hello');
  26136. * editor.queryCommandValue('serverparam'); //返回对象 {'name': 'hello'}
  26137. * ```
  26138. */
  26139. /**
  26140. * 修改服务器提交的额外参数列表,传入键值对对象添加多项
  26141. * @command serverparam
  26142. * @method execCommand
  26143. * @param { String } cmd 命令字符串
  26144. * @param { Object } key 传入的键值对对象
  26145. * @example
  26146. * ```javascript
  26147. * editor.execCommand('serverparam', {'name': 'hello'});
  26148. * editor.queryCommandValue('serverparam'); //返回对象 {'name': 'hello'}
  26149. * ```
  26150. */
  26151. /**
  26152. * 修改服务器提交的额外参数列表,使用自定义函数添加多项
  26153. * @command serverparam
  26154. * @method execCommand
  26155. * @param { String } cmd 命令字符串
  26156. * @param { Function } key 自定义获取参数的函数
  26157. * @example
  26158. * ```javascript
  26159. * editor.execCommand('serverparam', function(editor){
  26160. * return {'key': 'value'};
  26161. * });
  26162. * editor.queryCommandValue('serverparam'); //返回对象 {'key': 'value'}
  26163. * ```
  26164. */
  26165. /**
  26166. * 获取服务器提交的额外参数列表
  26167. * @command serverparam
  26168. * @method queryCommandValue
  26169. * @param { String } cmd 命令字符串
  26170. * @example
  26171. * ```javascript
  26172. * editor.queryCommandValue( 'serverparam' ); //返回对象 {'key': 'value'}
  26173. * ```
  26174. */
  26175. serverparam: {
  26176. execCommand: function(cmd, key, value) {
  26177. if (key === undefined || key === null) {
  26178. //不传参数,清空列表
  26179. serverParam = {};
  26180. } else if (utils.isString(key)) {
  26181. //传入键值
  26182. if (value === undefined || value === null) {
  26183. delete serverParam[key];
  26184. } else {
  26185. serverParam[key] = value;
  26186. }
  26187. } else if (utils.isObject(key)) {
  26188. //传入对象,覆盖列表项
  26189. utils.extend(serverParam, key, false);
  26190. } else if (utils.isFunction(key)) {
  26191. //传入函数,添加列表项
  26192. utils.extend(serverParam, key(), false);
  26193. }
  26194. },
  26195. queryCommandValue: function() {
  26196. return serverParam || {};
  26197. }
  26198. }
  26199. }
  26200. };
  26201. });
  26202. // plugins/insertfile.js
  26203. /**
  26204. * 插入附件
  26205. */
  26206. UE.plugin.register("insertfile", function() {
  26207. var me = this;
  26208. function getFileIcon(url) {
  26209. var ext = url.substr(url.lastIndexOf(".") + 1).toLowerCase(),
  26210. maps = {
  26211. rar: "icon_rar.gif",
  26212. zip: "icon_rar.gif",
  26213. tar: "icon_rar.gif",
  26214. gz: "icon_rar.gif",
  26215. bz2: "icon_rar.gif",
  26216. doc: "icon_doc.gif",
  26217. docx: "icon_doc.gif",
  26218. pdf: "icon_pdf.gif",
  26219. mp3: "icon_mp3.gif",
  26220. xls: "icon_xls.gif",
  26221. chm: "icon_chm.gif",
  26222. ppt: "icon_ppt.gif",
  26223. pptx: "icon_ppt.gif",
  26224. avi: "icon_mv.gif",
  26225. rmvb: "icon_mv.gif",
  26226. wmv: "icon_mv.gif",
  26227. flv: "icon_mv.gif",
  26228. swf: "icon_mv.gif",
  26229. rm: "icon_mv.gif",
  26230. exe: "icon_exe.gif",
  26231. psd: "icon_psd.gif",
  26232. txt: "icon_txt.gif",
  26233. jpg: "icon_jpg.gif",
  26234. png: "icon_jpg.gif",
  26235. jpeg: "icon_jpg.gif",
  26236. gif: "icon_jpg.gif",
  26237. ico: "icon_jpg.gif",
  26238. bmp: "icon_jpg.gif"
  26239. };
  26240. return maps[ext] ? maps[ext] : maps["txt"];
  26241. }
  26242. return {
  26243. commands: {
  26244. insertfile: {
  26245. execCommand: function(command, filelist) {
  26246. filelist = utils.isArray(filelist) ? filelist : [filelist];
  26247. if (me.fireEvent("beforeinsertfile", filelist) === true) {
  26248. return;
  26249. }
  26250. var i,
  26251. item,
  26252. icon,
  26253. title,
  26254. html = "",
  26255. URL = me.getOpt("UEDITOR_HOME_URL"),
  26256. iconDir =
  26257. URL +
  26258. (URL.substr(URL.length - 1) == "/" ? "" : "/") +
  26259. "dialogs/attachment/fileTypeImages/";
  26260. for (i = 0; i < filelist.length; i++) {
  26261. item = filelist[i];
  26262. icon = iconDir + getFileIcon(item.url);
  26263. title =
  26264. item.title || item.url.substr(item.url.lastIndexOf("/") + 1);
  26265. html +=
  26266. '<p style="line-height: 16px;">' +
  26267. '<img style="vertical-align: middle; margin-right: 2px;" src="' +
  26268. icon +
  26269. '" _src="' +
  26270. icon +
  26271. '" />' +
  26272. '<a style="font-size:12px; color:#0066cc;" href="' +
  26273. item.url +
  26274. '" title="' +
  26275. title +
  26276. '">' +
  26277. title +
  26278. "</a>" +
  26279. "</p>";
  26280. }
  26281. me.execCommand("insertHtml", html);
  26282. me.fireEvent("afterinsertfile", filelist);
  26283. }
  26284. }
  26285. }
  26286. };
  26287. });
  26288. // plugins/xssFilter.js
  26289. /**
  26290. * @file xssFilter.js
  26291. * @desc xss过滤器
  26292. * @author robbenmu
  26293. */
  26294. UE.plugins.xssFilter = function() {
  26295. var config = UEDITOR_CONFIG;
  26296. var whitList = config.whitList;
  26297. function filter(node) {
  26298. var tagName = node.tagName;
  26299. var attrs = node.attrs;
  26300. if (!whitList.hasOwnProperty(tagName)) {
  26301. node.parentNode.removeChild(node);
  26302. return false;
  26303. }
  26304. UE.utils.each(attrs, function (val, key) {
  26305. if (whitList[tagName].indexOf(key) === -1) {
  26306. node.setAttr(key);
  26307. }
  26308. });
  26309. }
  26310. // 添加inserthtml\paste等操作用的过滤规则
  26311. if (whitList && config.xssFilterRules) {
  26312. this.options.filterRules = function () {
  26313. var result = {};
  26314. UE.utils.each(whitList, function(val, key) {
  26315. result[key] = function (node) {
  26316. return filter(node);
  26317. };
  26318. });
  26319. return result;
  26320. }();
  26321. }
  26322. var tagList = [];
  26323. UE.utils.each(whitList, function (val, key) {
  26324. tagList.push(key);
  26325. });
  26326. // 添加input过滤规则
  26327. //
  26328. if (whitList && config.inputXssFilter) {
  26329. this.addInputRule(function (root) {
  26330. root.traversal(function(node) {
  26331. if (node.type !== 'element') {
  26332. return false;
  26333. }
  26334. filter(node);
  26335. });
  26336. });
  26337. }
  26338. // 添加output过滤规则
  26339. //
  26340. if (whitList && config.outputXssFilter) {
  26341. this.addOutputRule(function (root) {
  26342. root.traversal(function(node) {
  26343. if (node.type !== 'element') {
  26344. return false;
  26345. }
  26346. filter(node);
  26347. });
  26348. });
  26349. }
  26350. };
  26351. // ui/ui.js
  26352. var baidu = baidu || {};
  26353. baidu.editor = baidu.editor || {};
  26354. UE.ui = baidu.editor.ui = {};
  26355. // ui/uiutils.js
  26356. ;(function() {
  26357. var browser = baidu.editor.browser,
  26358. domUtils = baidu.editor.dom.domUtils;
  26359. var magic = "$EDITORUI";
  26360. var root = (window[magic] = {});
  26361. var uidMagic = "ID" + magic;
  26362. var uidCount = 0;
  26363. var uiUtils = (baidu.editor.ui.uiUtils = {
  26364. uid: function(obj) {
  26365. return obj ? obj[uidMagic] || (obj[uidMagic] = ++uidCount) : ++uidCount;
  26366. },
  26367. hook: function(fn, callback) {
  26368. var dg;
  26369. if (fn && fn._callbacks) {
  26370. dg = fn;
  26371. } else {
  26372. dg = function() {
  26373. var q;
  26374. if (fn) {
  26375. q = fn.apply(this, arguments);
  26376. }
  26377. var callbacks = dg._callbacks;
  26378. var k = callbacks.length;
  26379. while (k--) {
  26380. var r = callbacks[k].apply(this, arguments);
  26381. if (q === undefined) {
  26382. q = r;
  26383. }
  26384. }
  26385. return q;
  26386. };
  26387. dg._callbacks = [];
  26388. }
  26389. dg._callbacks.push(callback);
  26390. return dg;
  26391. },
  26392. createElementByHtml: function(html) {
  26393. var el = document.createElement("div");
  26394. el.innerHTML = html;
  26395. el = el.firstChild;
  26396. el.parentNode.removeChild(el);
  26397. return el;
  26398. },
  26399. getViewportElement: function() {
  26400. return browser.ie && browser.quirks
  26401. ? document.body
  26402. : document.documentElement;
  26403. },
  26404. getClientRect: function(element) {
  26405. var bcr;
  26406. //trace IE6下在控制编辑器显隐时可能会报错,catch一下
  26407. try {
  26408. bcr = element.getBoundingClientRect();
  26409. } catch (e) {
  26410. bcr = { left: 0, top: 0, height: 0, width: 0 };
  26411. }
  26412. var rect = {
  26413. left: Math.round(bcr.left),
  26414. top: Math.round(bcr.top),
  26415. height: Math.round(bcr.bottom - bcr.top),
  26416. width: Math.round(bcr.right - bcr.left)
  26417. };
  26418. var doc;
  26419. while (
  26420. (doc = element.ownerDocument) !== document &&
  26421. (element = domUtils.getWindow(doc).frameElement)
  26422. ) {
  26423. bcr = element.getBoundingClientRect();
  26424. rect.left += bcr.left;
  26425. rect.top += bcr.top;
  26426. }
  26427. rect.bottom = rect.top + rect.height;
  26428. rect.right = rect.left + rect.width;
  26429. return rect;
  26430. },
  26431. getViewportRect: function() {
  26432. var viewportEl = uiUtils.getViewportElement();
  26433. var width = (window.innerWidth || viewportEl.clientWidth) | 0;
  26434. var height = (window.innerHeight || viewportEl.clientHeight) | 0;
  26435. return {
  26436. left: 0,
  26437. top: 0,
  26438. height: height,
  26439. width: width,
  26440. bottom: height,
  26441. right: width
  26442. };
  26443. },
  26444. setViewportOffset: function(element, offset) {
  26445. var rect;
  26446. var fixedLayer = uiUtils.getFixedLayer();
  26447. if (element.parentNode === fixedLayer) {
  26448. element.style.left = offset.left + "px";
  26449. element.style.top = offset.top + "px";
  26450. } else {
  26451. domUtils.setViewportOffset(element, offset);
  26452. }
  26453. },
  26454. getEventOffset: function(evt) {
  26455. var el = evt.target || evt.srcElement;
  26456. var rect = uiUtils.getClientRect(el);
  26457. var offset = uiUtils.getViewportOffsetByEvent(evt);
  26458. return {
  26459. left: offset.left - rect.left,
  26460. top: offset.top - rect.top
  26461. };
  26462. },
  26463. getViewportOffsetByEvent: function(evt) {
  26464. var el = evt.target || evt.srcElement;
  26465. var frameEl = domUtils.getWindow(el).frameElement;
  26466. var offset = {
  26467. left: evt.clientX,
  26468. top: evt.clientY
  26469. };
  26470. if (frameEl && el.ownerDocument !== document) {
  26471. var rect = uiUtils.getClientRect(frameEl);
  26472. offset.left += rect.left;
  26473. offset.top += rect.top;
  26474. }
  26475. return offset;
  26476. },
  26477. setGlobal: function(id, obj) {
  26478. root[id] = obj;
  26479. return magic + '["' + id + '"]';
  26480. },
  26481. unsetGlobal: function(id) {
  26482. delete root[id];
  26483. },
  26484. copyAttributes: function(tgt, src) {
  26485. var attributes = src.attributes;
  26486. var k = attributes.length;
  26487. while (k--) {
  26488. var attrNode = attributes[k];
  26489. if (
  26490. attrNode.nodeName != "style" &&
  26491. attrNode.nodeName != "class" &&
  26492. (!browser.ie || attrNode.specified)
  26493. ) {
  26494. tgt.setAttribute(attrNode.nodeName, attrNode.nodeValue);
  26495. }
  26496. }
  26497. if (src.className) {
  26498. domUtils.addClass(tgt, src.className);
  26499. }
  26500. if (src.style.cssText) {
  26501. tgt.style.cssText += ";" + src.style.cssText;
  26502. }
  26503. },
  26504. removeStyle: function(el, styleName) {
  26505. if (el.style.removeProperty) {
  26506. el.style.removeProperty(styleName);
  26507. } else if (el.style.removeAttribute) {
  26508. el.style.removeAttribute(styleName);
  26509. } else throw "";
  26510. },
  26511. contains: function(elA, elB) {
  26512. return (
  26513. elA &&
  26514. elB &&
  26515. (elA === elB
  26516. ? false
  26517. : elA.contains
  26518. ? elA.contains(elB)
  26519. : elA.compareDocumentPosition(elB) & 16)
  26520. );
  26521. },
  26522. startDrag: function(evt, callbacks, doc) {
  26523. var doc = doc || document;
  26524. var startX = evt.clientX;
  26525. var startY = evt.clientY;
  26526. function handleMouseMove(evt) {
  26527. var x = evt.clientX - startX;
  26528. var y = evt.clientY - startY;
  26529. callbacks.ondragmove(x, y, evt);
  26530. if (evt.stopPropagation) {
  26531. evt.stopPropagation();
  26532. } else {
  26533. evt.cancelBubble = true;
  26534. }
  26535. }
  26536. if (doc.addEventListener) {
  26537. function handleMouseUp(evt) {
  26538. doc.removeEventListener("mousemove", handleMouseMove, true);
  26539. doc.removeEventListener("mouseup", handleMouseUp, true);
  26540. window.removeEventListener("mouseup", handleMouseUp, true);
  26541. callbacks.ondragstop();
  26542. }
  26543. doc.addEventListener("mousemove", handleMouseMove, true);
  26544. doc.addEventListener("mouseup", handleMouseUp, true);
  26545. window.addEventListener("mouseup", handleMouseUp, true);
  26546. evt.preventDefault();
  26547. } else {
  26548. var elm = evt.srcElement;
  26549. elm.setCapture();
  26550. function releaseCaptrue() {
  26551. elm.releaseCapture();
  26552. elm.detachEvent("onmousemove", handleMouseMove);
  26553. elm.detachEvent("onmouseup", releaseCaptrue);
  26554. elm.detachEvent("onlosecaptrue", releaseCaptrue);
  26555. callbacks.ondragstop();
  26556. }
  26557. elm.attachEvent("onmousemove", handleMouseMove);
  26558. elm.attachEvent("onmouseup", releaseCaptrue);
  26559. elm.attachEvent("onlosecaptrue", releaseCaptrue);
  26560. evt.returnValue = false;
  26561. }
  26562. callbacks.ondragstart();
  26563. },
  26564. getFixedLayer: function() {
  26565. var layer = document.getElementById("edui_fixedlayer");
  26566. if (layer == null) {
  26567. layer = document.createElement("div");
  26568. layer.id = "edui_fixedlayer";
  26569. document.body.appendChild(layer);
  26570. if (browser.ie && browser.version <= 8) {
  26571. layer.style.position = "absolute";
  26572. bindFixedLayer();
  26573. setTimeout(updateFixedOffset);
  26574. } else {
  26575. layer.style.position = "fixed";
  26576. }
  26577. layer.style.left = "0";
  26578. layer.style.top = "0";
  26579. layer.style.width = "0";
  26580. layer.style.height = "0";
  26581. }
  26582. return layer;
  26583. },
  26584. makeUnselectable: function(element) {
  26585. if (browser.opera || (browser.ie && browser.version < 9)) {
  26586. element.unselectable = "on";
  26587. if (element.hasChildNodes()) {
  26588. for (var i = 0; i < element.childNodes.length; i++) {
  26589. if (element.childNodes[i].nodeType == 1) {
  26590. uiUtils.makeUnselectable(element.childNodes[i]);
  26591. }
  26592. }
  26593. }
  26594. } else {
  26595. if (element.style.MozUserSelect !== undefined) {
  26596. element.style.MozUserSelect = "none";
  26597. } else if (element.style.WebkitUserSelect !== undefined) {
  26598. element.style.WebkitUserSelect = "none";
  26599. } else if (element.style.KhtmlUserSelect !== undefined) {
  26600. element.style.KhtmlUserSelect = "none";
  26601. }
  26602. }
  26603. }
  26604. });
  26605. function updateFixedOffset() {
  26606. var layer = document.getElementById("edui_fixedlayer");
  26607. uiUtils.setViewportOffset(layer, {
  26608. left: 0,
  26609. top: 0
  26610. });
  26611. // layer.style.display = 'none';
  26612. // layer.style.display = 'block';
  26613. //#trace: 1354
  26614. // setTimeout(updateFixedOffset);
  26615. }
  26616. function bindFixedLayer(adjOffset) {
  26617. domUtils.on(window, "scroll", updateFixedOffset);
  26618. domUtils.on(
  26619. window,
  26620. "resize",
  26621. baidu.editor.utils.defer(updateFixedOffset, 0, true)
  26622. );
  26623. }
  26624. })();
  26625. // ui/uibase.js
  26626. ;(function() {
  26627. var utils = baidu.editor.utils,
  26628. uiUtils = baidu.editor.ui.uiUtils,
  26629. EventBase = baidu.editor.EventBase,
  26630. UIBase = (baidu.editor.ui.UIBase = function() {});
  26631. UIBase.prototype = {
  26632. className: "",
  26633. uiName: "",
  26634. initOptions: function(options) {
  26635. var me = this;
  26636. for (var k in options) {
  26637. me[k] = options[k];
  26638. }
  26639. this.id = this.id || "edui" + uiUtils.uid();
  26640. },
  26641. initUIBase: function() {
  26642. this._globalKey = utils.unhtml(uiUtils.setGlobal(this.id, this));
  26643. },
  26644. render: function(holder) {
  26645. var html = this.renderHtml();
  26646. var el = uiUtils.createElementByHtml(html);
  26647. //by xuheng 给每个node添加class
  26648. var list = domUtils.getElementsByTagName(el, "*");
  26649. var theme = "edui-" + (this.theme || this.editor.options.theme);
  26650. var layer = document.getElementById("edui_fixedlayer");
  26651. for (var i = 0, node; (node = list[i++]); ) {
  26652. domUtils.addClass(node, theme);
  26653. }
  26654. domUtils.addClass(el, theme);
  26655. if (layer) {
  26656. layer.className = "";
  26657. domUtils.addClass(layer, theme);
  26658. }
  26659. var seatEl = this.getDom();
  26660. if (seatEl != null) {
  26661. seatEl.parentNode.replaceChild(el, seatEl);
  26662. uiUtils.copyAttributes(el, seatEl);
  26663. } else {
  26664. if (typeof holder == "string") {
  26665. holder = document.getElementById(holder);
  26666. }
  26667. holder = holder || uiUtils.getFixedLayer();
  26668. domUtils.addClass(holder, theme);
  26669. holder.appendChild(el);
  26670. }
  26671. this.postRender();
  26672. },
  26673. getDom: function(name) {
  26674. if (!name) {
  26675. return document.getElementById(this.id);
  26676. } else {
  26677. return document.getElementById(this.id + "_" + name);
  26678. }
  26679. },
  26680. postRender: function() {
  26681. this.fireEvent("postrender");
  26682. },
  26683. getHtmlTpl: function() {
  26684. return "";
  26685. },
  26686. formatHtml: function(tpl) {
  26687. var prefix = "edui-" + this.uiName;
  26688. return tpl
  26689. .replace(/##/g, this.id)
  26690. .replace(/%%-/g, this.uiName ? prefix + "-" : "")
  26691. .replace(/%%/g, (this.uiName ? prefix : "") + " " + this.className)
  26692. .replace(/\$\$/g, this._globalKey);
  26693. },
  26694. renderHtml: function() {
  26695. return this.formatHtml(this.getHtmlTpl());
  26696. },
  26697. dispose: function() {
  26698. var box = this.getDom();
  26699. if (box) baidu.editor.dom.domUtils.remove(box);
  26700. uiUtils.unsetGlobal(this.id);
  26701. }
  26702. };
  26703. utils.inherits(UIBase, EventBase);
  26704. })();
  26705. // ui/separator.js
  26706. ;(function() {
  26707. var utils = baidu.editor.utils,
  26708. UIBase = baidu.editor.ui.UIBase,
  26709. Separator = (baidu.editor.ui.Separator = function(options) {
  26710. this.initOptions(options);
  26711. this.initSeparator();
  26712. });
  26713. Separator.prototype = {
  26714. uiName: "separator",
  26715. initSeparator: function() {
  26716. this.initUIBase();
  26717. },
  26718. getHtmlTpl: function() {
  26719. return '<div id="##" class="edui-box %%"></div>';
  26720. }
  26721. };
  26722. utils.inherits(Separator, UIBase);
  26723. })();
  26724. // ui/mask.js
  26725. ///import core
  26726. ///import uicore
  26727. ;(function() {
  26728. var utils = baidu.editor.utils,
  26729. domUtils = baidu.editor.dom.domUtils,
  26730. UIBase = baidu.editor.ui.UIBase,
  26731. uiUtils = baidu.editor.ui.uiUtils;
  26732. var Mask = (baidu.editor.ui.Mask = function(options) {
  26733. this.initOptions(options);
  26734. this.initUIBase();
  26735. });
  26736. Mask.prototype = {
  26737. getHtmlTpl: function() {
  26738. return '<div id="##" class="edui-mask %%" onclick="return $$._onClick(event, this);" onmousedown="return $$._onMouseDown(event, this);"></div>';
  26739. },
  26740. postRender: function() {
  26741. var me = this;
  26742. domUtils.on(window, "resize", function() {
  26743. setTimeout(function() {
  26744. if (!me.isHidden()) {
  26745. me._fill();
  26746. }
  26747. });
  26748. });
  26749. },
  26750. show: function(zIndex) {
  26751. this._fill();
  26752. this.getDom().style.display = "";
  26753. this.getDom().style.zIndex = zIndex;
  26754. },
  26755. hide: function() {
  26756. this.getDom().style.display = "none";
  26757. this.getDom().style.zIndex = "";
  26758. },
  26759. isHidden: function() {
  26760. return this.getDom().style.display == "none";
  26761. },
  26762. _onMouseDown: function() {
  26763. return false;
  26764. },
  26765. _onClick: function(e, target) {
  26766. this.fireEvent("click", e, target);
  26767. },
  26768. _fill: function() {
  26769. var el = this.getDom();
  26770. var vpRect = uiUtils.getViewportRect();
  26771. el.style.width = vpRect.width + "px";
  26772. el.style.height = vpRect.height + "px";
  26773. }
  26774. };
  26775. utils.inherits(Mask, UIBase);
  26776. })();
  26777. // ui/popup.js
  26778. ///import core
  26779. ///import uicore
  26780. ;(function() {
  26781. var utils = baidu.editor.utils,
  26782. uiUtils = baidu.editor.ui.uiUtils,
  26783. domUtils = baidu.editor.dom.domUtils,
  26784. UIBase = baidu.editor.ui.UIBase,
  26785. Popup = (baidu.editor.ui.Popup = function(options) {
  26786. this.initOptions(options);
  26787. this.initPopup();
  26788. });
  26789. var allPopups = [];
  26790. function closeAllPopup(evt, el) {
  26791. for (var i = 0; i < allPopups.length; i++) {
  26792. var pop = allPopups[i];
  26793. if (!pop.isHidden()) {
  26794. if (pop.queryAutoHide(el) !== false) {
  26795. if (
  26796. evt &&
  26797. /scroll/gi.test(evt.type) &&
  26798. pop.className == "edui-wordpastepop"
  26799. )
  26800. return;
  26801. pop.hide();
  26802. }
  26803. }
  26804. }
  26805. if (allPopups.length) pop.editor.fireEvent("afterhidepop");
  26806. }
  26807. Popup.postHide = closeAllPopup;
  26808. var ANCHOR_CLASSES = [
  26809. "edui-anchor-topleft",
  26810. "edui-anchor-topright",
  26811. "edui-anchor-bottomleft",
  26812. "edui-anchor-bottomright"
  26813. ];
  26814. Popup.prototype = {
  26815. SHADOW_RADIUS: 5,
  26816. content: null,
  26817. _hidden: false,
  26818. autoRender: true,
  26819. canSideLeft: true,
  26820. canSideUp: true,
  26821. initPopup: function() {
  26822. this.initUIBase();
  26823. allPopups.push(this);
  26824. },
  26825. getHtmlTpl: function() {
  26826. return (
  26827. '<div id="##" class="edui-popup %%" onmousedown="return false;">' +
  26828. ' <div id="##_body" class="edui-popup-body">' +
  26829. ' <iframe style="position:absolute;z-index:-1;left:0;top:0;background-color: transparent;" frameborder="0" width="100%" height="100%" src="about:blank"></iframe>' +
  26830. ' <div class="edui-shadow"></div>' +
  26831. ' <div id="##_content" class="edui-popup-content">' +
  26832. this.getContentHtmlTpl() +
  26833. " </div>" +
  26834. " </div>" +
  26835. "</div>"
  26836. );
  26837. },
  26838. getContentHtmlTpl: function() {
  26839. if (this.content) {
  26840. if (typeof this.content == "string") {
  26841. return this.content;
  26842. }
  26843. return this.content.renderHtml();
  26844. } else {
  26845. return "";
  26846. }
  26847. },
  26848. _UIBase_postRender: UIBase.prototype.postRender,
  26849. postRender: function() {
  26850. if (this.content instanceof UIBase) {
  26851. this.content.postRender();
  26852. }
  26853. //捕获鼠标滚轮
  26854. if (this.captureWheel && !this.captured) {
  26855. this.captured = true;
  26856. var winHeight =
  26857. (document.documentElement.clientHeight ||
  26858. document.body.clientHeight) - 80,
  26859. _height = this.getDom().offsetHeight,
  26860. _top = uiUtils.getClientRect(this.combox.getDom()).top,
  26861. content = this.getDom("content"),
  26862. ifr = this.getDom("body").getElementsByTagName("iframe"),
  26863. me = this;
  26864. ifr.length && (ifr = ifr[0]);
  26865. while (_top + _height > winHeight) {
  26866. _height -= 30;
  26867. }
  26868. content.style.height = _height + "px";
  26869. //同步更改iframe高度
  26870. ifr && (ifr.style.height = _height + "px");
  26871. //阻止在combox上的鼠标滚轮事件, 防止用户的正常操作被误解
  26872. if (window.XMLHttpRequest) {
  26873. domUtils.on(
  26874. content,
  26875. "onmousewheel" in document.body ? "mousewheel" : "DOMMouseScroll",
  26876. function(e) {
  26877. if (e.preventDefault) {
  26878. e.preventDefault();
  26879. } else {
  26880. e.returnValue = false;
  26881. }
  26882. if (e.wheelDelta) {
  26883. content.scrollTop -= e.wheelDelta / 120 * 60;
  26884. } else {
  26885. content.scrollTop -= e.detail / -3 * 60;
  26886. }
  26887. }
  26888. );
  26889. } else {
  26890. //ie6
  26891. domUtils.on(this.getDom(), "mousewheel", function(e) {
  26892. e.returnValue = false;
  26893. me.getDom("content").scrollTop -= e.wheelDelta / 120 * 60;
  26894. });
  26895. }
  26896. }
  26897. this.fireEvent("postRenderAfter");
  26898. this.hide(true);
  26899. this._UIBase_postRender();
  26900. },
  26901. _doAutoRender: function() {
  26902. if (!this.getDom() && this.autoRender) {
  26903. this.render();
  26904. }
  26905. },
  26906. mesureSize: function() {
  26907. var box = this.getDom("content");
  26908. return uiUtils.getClientRect(box);
  26909. },
  26910. fitSize: function() {
  26911. if (this.captureWheel && this.sized) {
  26912. return this.__size;
  26913. }
  26914. this.sized = true;
  26915. var popBodyEl = this.getDom("body");
  26916. popBodyEl.style.width = "";
  26917. popBodyEl.style.height = "";
  26918. var size = this.mesureSize();
  26919. if (this.captureWheel) {
  26920. popBodyEl.style.width = -(-20 - size.width) + "px";
  26921. var height = parseInt(this.getDom("content").style.height, 10);
  26922. !window.isNaN(height) && (size.height = height);
  26923. } else {
  26924. popBodyEl.style.width = size.width + "px";
  26925. }
  26926. popBodyEl.style.height = size.height + "px";
  26927. this.__size = size;
  26928. this.captureWheel && (this.getDom("content").style.overflow = "auto");
  26929. return size;
  26930. },
  26931. showAnchor: function(element, hoz) {
  26932. this.showAnchorRect(uiUtils.getClientRect(element), hoz);
  26933. },
  26934. showAnchorRect: function(rect, hoz, adj) {
  26935. this._doAutoRender();
  26936. var vpRect = uiUtils.getViewportRect();
  26937. this.getDom().style.visibility = "hidden";
  26938. this._show();
  26939. var popSize = this.fitSize();
  26940. var sideLeft, sideUp, left, top;
  26941. if (hoz) {
  26942. sideLeft =
  26943. this.canSideLeft &&
  26944. (rect.right + popSize.width > vpRect.right &&
  26945. rect.left > popSize.width);
  26946. sideUp =
  26947. this.canSideUp &&
  26948. (rect.top + popSize.height > vpRect.bottom &&
  26949. rect.bottom > popSize.height);
  26950. left = sideLeft ? rect.left - popSize.width : rect.right;
  26951. top = sideUp ? rect.bottom - popSize.height : rect.top;
  26952. } else {
  26953. sideLeft =
  26954. this.canSideLeft &&
  26955. (rect.right + popSize.width > vpRect.right &&
  26956. rect.left > popSize.width);
  26957. sideUp =
  26958. this.canSideUp &&
  26959. (rect.top + popSize.height > vpRect.bottom &&
  26960. rect.bottom > popSize.height);
  26961. left = sideLeft ? rect.right - popSize.width : rect.left;
  26962. top = sideUp ? rect.top - popSize.height : rect.bottom;
  26963. }
  26964. var popEl = this.getDom();
  26965. uiUtils.setViewportOffset(popEl, {
  26966. left: left,
  26967. top: top
  26968. });
  26969. domUtils.removeClasses(popEl, ANCHOR_CLASSES);
  26970. popEl.className +=
  26971. " " + ANCHOR_CLASSES[(sideUp ? 1 : 0) * 2 + (sideLeft ? 1 : 0)];
  26972. if (this.editor) {
  26973. popEl.style.zIndex = this.editor.container.style.zIndex * 1 + 10;
  26974. baidu.editor.ui.uiUtils.getFixedLayer().style.zIndex =
  26975. popEl.style.zIndex - 1;
  26976. }
  26977. this.getDom().style.visibility = "visible";
  26978. },
  26979. showAt: function(offset) {
  26980. var left = offset.left;
  26981. var top = offset.top;
  26982. var rect = {
  26983. left: left,
  26984. top: top,
  26985. right: left,
  26986. bottom: top,
  26987. height: 0,
  26988. width: 0
  26989. };
  26990. this.showAnchorRect(rect, false, true);
  26991. },
  26992. _show: function() {
  26993. if (this._hidden) {
  26994. var box = this.getDom();
  26995. box.style.display = "";
  26996. this._hidden = false;
  26997. // if (box.setActive) {
  26998. // box.setActive();
  26999. // }
  27000. this.fireEvent("show");
  27001. }
  27002. },
  27003. isHidden: function() {
  27004. return this._hidden;
  27005. },
  27006. show: function() {
  27007. this._doAutoRender();
  27008. this._show();
  27009. },
  27010. hide: function(notNofity) {
  27011. if (!this._hidden && this.getDom()) {
  27012. this.getDom().style.display = "none";
  27013. this._hidden = true;
  27014. if (!notNofity) {
  27015. this.fireEvent("hide");
  27016. }
  27017. }
  27018. },
  27019. queryAutoHide: function(el) {
  27020. return !el || !uiUtils.contains(this.getDom(), el);
  27021. }
  27022. };
  27023. utils.inherits(Popup, UIBase);
  27024. domUtils.on(document, "mousedown", function(evt) {
  27025. var el = evt.target || evt.srcElement;
  27026. closeAllPopup(evt, el);
  27027. });
  27028. domUtils.on(window, "scroll", function(evt, el) {
  27029. closeAllPopup(evt, el);
  27030. });
  27031. })();
  27032. // ui/colorpicker.js
  27033. ///import core
  27034. ///import uicore
  27035. ;(function() {
  27036. var utils = baidu.editor.utils,
  27037. UIBase = baidu.editor.ui.UIBase,
  27038. ColorPicker = (baidu.editor.ui.ColorPicker = function(options) {
  27039. this.initOptions(options);
  27040. this.noColorText = this.noColorText || this.editor.getLang("clearColor");
  27041. this.initUIBase();
  27042. });
  27043. ColorPicker.prototype = {
  27044. getHtmlTpl: function() {
  27045. return genColorPicker(this.noColorText, this.editor);
  27046. },
  27047. _onTableClick: function(evt) {
  27048. var tgt = evt.target || evt.srcElement;
  27049. var color = tgt.getAttribute("data-color");
  27050. if (color) {
  27051. this.fireEvent("pickcolor", color);
  27052. }
  27053. },
  27054. _onTableOver: function(evt) {
  27055. var tgt = evt.target || evt.srcElement;
  27056. var color = tgt.getAttribute("data-color");
  27057. if (color) {
  27058. this.getDom("preview").style.backgroundColor = color;
  27059. }
  27060. },
  27061. _onTableOut: function() {
  27062. this.getDom("preview").style.backgroundColor = "";
  27063. },
  27064. _onPickNoColor: function() {
  27065. this.fireEvent("picknocolor");
  27066. }
  27067. };
  27068. utils.inherits(ColorPicker, UIBase);
  27069. var COLORS = ("ffffff,000000,eeece1,1f497d,4f81bd,c0504d,9bbb59,8064a2,4bacc6,f79646," +
  27070. "f2f2f2,7f7f7f,ddd9c3,c6d9f0,dbe5f1,f2dcdb,ebf1dd,e5e0ec,dbeef3,fdeada," +
  27071. "d8d8d8,595959,c4bd97,8db3e2,b8cce4,e5b9b7,d7e3bc,ccc1d9,b7dde8,fbd5b5," +
  27072. "bfbfbf,3f3f3f,938953,548dd4,95b3d7,d99694,c3d69b,b2a2c7,92cddc,fac08f," +
  27073. "a5a5a5,262626,494429,17365d,366092,953734,76923c,5f497a,31859b,e36c09," +
  27074. "7f7f7f,0c0c0c,1d1b10,0f243e,244061,632423,4f6128,3f3151,205867,974806," +
  27075. "c00000,ff0000,ffc000,ffff00,92d050,00b050,00b0f0,0070c0,002060,7030a0,").split(
  27076. ","
  27077. );
  27078. function genColorPicker(noColorText, editor) {
  27079. var html =
  27080. '<div id="##" class="edui-colorpicker %%">' +
  27081. '<div class="edui-colorpicker-topbar edui-clearfix">' +
  27082. '<div unselectable="on" id="##_preview" class="edui-colorpicker-preview"></div>' +
  27083. '<div unselectable="on" class="edui-colorpicker-nocolor" onclick="$$._onPickNoColor(event, this);">' +
  27084. noColorText +
  27085. "</div>" +
  27086. "</div>" +
  27087. '<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">' +
  27088. '<tr style="border-bottom: 1px solid #ddd;font-size: 13px;line-height: 25px;color:#39C;padding-top: 2px"><td colspan="10">' +
  27089. editor.getLang("themeColor") +
  27090. "</td> </tr>" +
  27091. '<tr class="edui-colorpicker-tablefirstrow" >';
  27092. for (var i = 0; i < COLORS.length; i++) {
  27093. if (i && i % 10 === 0) {
  27094. html +=
  27095. "</tr>" +
  27096. (i == 60
  27097. ? '<tr style="border-bottom: 1px solid #ddd;font-size: 13px;line-height: 25px;color:#39C;"><td colspan="10">' +
  27098. editor.getLang("standardColor") +
  27099. "</td></tr>"
  27100. : "") +
  27101. "<tr" +
  27102. (i == 60 ? ' class="edui-colorpicker-tablefirstrow"' : "") +
  27103. ">";
  27104. }
  27105. html += i < 70
  27106. ? '<td style="padding: 0 2px;"><a hidefocus title="' +
  27107. COLORS[i] +
  27108. '" onclick="return false;" href="javascript:" unselectable="on" class="edui-box edui-colorpicker-colorcell"' +
  27109. ' data-color="#' +
  27110. COLORS[i] +
  27111. '"' +
  27112. ' style="background-color:#' +
  27113. COLORS[i] +
  27114. ";border:solid #ccc;" +
  27115. (i < 10 || i >= 60
  27116. ? "border-width:1px;"
  27117. : i >= 10 && i < 20
  27118. ? "border-width:1px 1px 0 1px;"
  27119. : "border-width:0 1px 0 1px;") +
  27120. '"' +
  27121. "></a></td>"
  27122. : "";
  27123. }
  27124. html += "</tr></table></div>";
  27125. return html;
  27126. }
  27127. })();
  27128. // ui/tablepicker.js
  27129. ///import core
  27130. ///import uicore
  27131. ;(function() {
  27132. var utils = baidu.editor.utils,
  27133. uiUtils = baidu.editor.ui.uiUtils,
  27134. UIBase = baidu.editor.ui.UIBase;
  27135. var TablePicker = (baidu.editor.ui.TablePicker = function(options) {
  27136. this.initOptions(options);
  27137. this.initTablePicker();
  27138. });
  27139. TablePicker.prototype = {
  27140. defaultNumRows: 10,
  27141. defaultNumCols: 10,
  27142. maxNumRows: 20,
  27143. maxNumCols: 20,
  27144. numRows: 10,
  27145. numCols: 10,
  27146. lengthOfCellSide: 22,
  27147. initTablePicker: function() {
  27148. this.initUIBase();
  27149. },
  27150. getHtmlTpl: function() {
  27151. var me = this;
  27152. return (
  27153. '<div id="##" class="edui-tablepicker %%">' +
  27154. '<div class="edui-tablepicker-body">' +
  27155. '<div class="edui-infoarea">' +
  27156. '<span id="##_label" class="edui-label"></span>' +
  27157. "</div>" +
  27158. '<div class="edui-pickarea"' +
  27159. ' onmousemove="$$._onMouseMove(event, this);"' +
  27160. ' onmouseover="$$._onMouseOver(event, this);"' +
  27161. ' onmouseout="$$._onMouseOut(event, this);"' +
  27162. ' onclick="$$._onClick(event, this);"' +
  27163. ">" +
  27164. '<div id="##_overlay" class="edui-overlay"></div>' +
  27165. "</div>" +
  27166. "</div>" +
  27167. "</div>"
  27168. );
  27169. },
  27170. _UIBase_render: UIBase.prototype.render,
  27171. render: function(holder) {
  27172. this._UIBase_render(holder);
  27173. this.getDom("label").innerHTML =
  27174. "0" +
  27175. this.editor.getLang("t_row") +
  27176. " x 0" +
  27177. this.editor.getLang("t_col");
  27178. },
  27179. _track: function(numCols, numRows) {
  27180. var style = this.getDom("overlay").style;
  27181. var sideLen = this.lengthOfCellSide;
  27182. style.width = numCols * sideLen + "px";
  27183. style.height = numRows * sideLen + "px";
  27184. var label = this.getDom("label");
  27185. label.innerHTML =
  27186. numCols +
  27187. this.editor.getLang("t_col") +
  27188. " x " +
  27189. numRows +
  27190. this.editor.getLang("t_row");
  27191. this.numCols = numCols;
  27192. this.numRows = numRows;
  27193. },
  27194. _onMouseOver: function(evt, el) {
  27195. var rel = evt.relatedTarget || evt.fromElement;
  27196. if (!uiUtils.contains(el, rel) && el !== rel) {
  27197. this.getDom("label").innerHTML =
  27198. "0" +
  27199. this.editor.getLang("t_col") +
  27200. " x 0" +
  27201. this.editor.getLang("t_row");
  27202. this.getDom("overlay").style.visibility = "";
  27203. }
  27204. },
  27205. _onMouseOut: function(evt, el) {
  27206. var rel = evt.relatedTarget || evt.toElement;
  27207. if (!uiUtils.contains(el, rel) && el !== rel) {
  27208. this.getDom("label").innerHTML =
  27209. "0" +
  27210. this.editor.getLang("t_col") +
  27211. " x 0" +
  27212. this.editor.getLang("t_row");
  27213. this.getDom("overlay").style.visibility = "hidden";
  27214. }
  27215. },
  27216. _onMouseMove: function(evt, el) {
  27217. var style = this.getDom("overlay").style;
  27218. var offset = uiUtils.getEventOffset(evt);
  27219. var sideLen = this.lengthOfCellSide;
  27220. var numCols = Math.ceil(offset.left / sideLen);
  27221. var numRows = Math.ceil(offset.top / sideLen);
  27222. this._track(numCols, numRows);
  27223. },
  27224. _onClick: function() {
  27225. this.fireEvent("picktable", this.numCols, this.numRows);
  27226. }
  27227. };
  27228. utils.inherits(TablePicker, UIBase);
  27229. })();
  27230. // ui/stateful.js
  27231. ;(function() {
  27232. var browser = baidu.editor.browser,
  27233. domUtils = baidu.editor.dom.domUtils,
  27234. uiUtils = baidu.editor.ui.uiUtils;
  27235. var TPL_STATEFUL =
  27236. 'onmousedown="$$.Stateful_onMouseDown(event, this);"' +
  27237. ' onmouseup="$$.Stateful_onMouseUp(event, this);"' +
  27238. (browser.ie
  27239. ? ' onmouseenter="$$.Stateful_onMouseEnter(event, this);"' +
  27240. ' onmouseleave="$$.Stateful_onMouseLeave(event, this);"'
  27241. : ' onmouseover="$$.Stateful_onMouseOver(event, this);"' +
  27242. ' onmouseout="$$.Stateful_onMouseOut(event, this);"');
  27243. baidu.editor.ui.Stateful = {
  27244. alwalysHoverable: false,
  27245. target: null, //目标元素和this指向dom不一样
  27246. Stateful_init: function() {
  27247. this._Stateful_dGetHtmlTpl = this.getHtmlTpl;
  27248. this.getHtmlTpl = this.Stateful_getHtmlTpl;
  27249. },
  27250. Stateful_getHtmlTpl: function() {
  27251. var tpl = this._Stateful_dGetHtmlTpl();
  27252. // 使用function避免$转义
  27253. return tpl.replace(/stateful/g, function() {
  27254. return TPL_STATEFUL;
  27255. });
  27256. },
  27257. Stateful_onMouseEnter: function(evt, el) {
  27258. this.target = el;
  27259. if (!this.isDisabled() || this.alwalysHoverable) {
  27260. this.addState("hover");
  27261. this.fireEvent("over");
  27262. }
  27263. },
  27264. Stateful_onMouseLeave: function(evt, el) {
  27265. if (!this.isDisabled() || this.alwalysHoverable) {
  27266. this.removeState("hover");
  27267. this.removeState("active");
  27268. this.fireEvent("out");
  27269. }
  27270. },
  27271. Stateful_onMouseOver: function(evt, el) {
  27272. var rel = evt.relatedTarget;
  27273. if (!uiUtils.contains(el, rel) && el !== rel) {
  27274. this.Stateful_onMouseEnter(evt, el);
  27275. }
  27276. },
  27277. Stateful_onMouseOut: function(evt, el) {
  27278. var rel = evt.relatedTarget;
  27279. if (!uiUtils.contains(el, rel) && el !== rel) {
  27280. this.Stateful_onMouseLeave(evt, el);
  27281. }
  27282. },
  27283. Stateful_onMouseDown: function(evt, el) {
  27284. if (!this.isDisabled()) {
  27285. this.addState("active");
  27286. }
  27287. },
  27288. Stateful_onMouseUp: function(evt, el) {
  27289. if (!this.isDisabled()) {
  27290. this.removeState("active");
  27291. }
  27292. },
  27293. Stateful_postRender: function() {
  27294. if (this.disabled && !this.hasState("disabled")) {
  27295. this.addState("disabled");
  27296. }
  27297. },
  27298. hasState: function(state) {
  27299. return domUtils.hasClass(this.getStateDom(), "edui-state-" + state);
  27300. },
  27301. addState: function(state) {
  27302. if (!this.hasState(state)) {
  27303. this.getStateDom().className += " edui-state-" + state;
  27304. }
  27305. },
  27306. removeState: function(state) {
  27307. if (this.hasState(state)) {
  27308. domUtils.removeClasses(this.getStateDom(), ["edui-state-" + state]);
  27309. }
  27310. },
  27311. getStateDom: function() {
  27312. return this.getDom("state");
  27313. },
  27314. isChecked: function() {
  27315. return this.hasState("checked");
  27316. },
  27317. setChecked: function(checked) {
  27318. if (!this.isDisabled() && checked) {
  27319. this.addState("checked");
  27320. } else {
  27321. this.removeState("checked");
  27322. }
  27323. },
  27324. isDisabled: function() {
  27325. return this.hasState("disabled");
  27326. },
  27327. setDisabled: function(disabled) {
  27328. if (disabled) {
  27329. this.removeState("hover");
  27330. this.removeState("checked");
  27331. this.removeState("active");
  27332. this.addState("disabled");
  27333. } else {
  27334. this.removeState("disabled");
  27335. }
  27336. }
  27337. };
  27338. })();
  27339. // ui/button.js
  27340. ///import core
  27341. ///import uicore
  27342. ///import ui/stateful.js
  27343. ;(function() {
  27344. var utils = baidu.editor.utils,
  27345. UIBase = baidu.editor.ui.UIBase,
  27346. Stateful = baidu.editor.ui.Stateful,
  27347. Button = (baidu.editor.ui.Button = function(options) {
  27348. if (options.name) {
  27349. var btnName = options.name;
  27350. var cssRules = options.cssRules;
  27351. if (!options.className) {
  27352. options.className = "edui-for-" + btnName;
  27353. }
  27354. options.cssRules =
  27355. ".edui-" +
  27356. (options.theme || "default") +
  27357. " .edui-toolbar .edui-button.edui-for-" +
  27358. btnName +
  27359. " .edui-icon {" +
  27360. cssRules +
  27361. "}";
  27362. }
  27363. this.initOptions(options);
  27364. this.initButton();
  27365. });
  27366. Button.prototype = {
  27367. uiName: "button",
  27368. label: "",
  27369. title: "",
  27370. showIcon: true,
  27371. showText: true,
  27372. cssRules: "",
  27373. initButton: function() {
  27374. this.initUIBase();
  27375. this.Stateful_init();
  27376. if (this.cssRules) {
  27377. utils.cssRule("edui-customize-" + this.name + "-style", this.cssRules);
  27378. }
  27379. },
  27380. getHtmlTpl: function() {
  27381. return (
  27382. '<div id="##" class="edui-box %%">' +
  27383. '<div id="##_state" stateful>' +
  27384. '<div class="%%-wrap"><div id="##_body" unselectable="on" ' +
  27385. (this.title ? 'title="' + this.title + '"' : "") +
  27386. ' class="%%-body" onmousedown="return $$._onMouseDown(event, this);" onclick="return $$._onClick(event, this);">' +
  27387. (this.showIcon ? '<div class="edui-box edui-icon"><svg class="edui-iconfont"><use xlink:href="#' + this.className + '"></use></svg></div>' : "") +
  27388. (this.showText
  27389. ? '<div class="edui-box edui-label">' + this.label + "</div>"
  27390. : "") +
  27391. "</div>" +
  27392. "</div>" +
  27393. "</div></div>"
  27394. );
  27395. },
  27396. postRender: function() {
  27397. this.Stateful_postRender();
  27398. this.setDisabled(this.disabled);
  27399. },
  27400. _onMouseDown: function(e) {
  27401. var target = e.target || e.srcElement,
  27402. tagName = target && target.tagName && target.tagName.toLowerCase();
  27403. if (tagName == "input" || tagName == "object" || tagName == "object") {
  27404. return false;
  27405. }
  27406. },
  27407. _onClick: function() {
  27408. if (!this.isDisabled()) {
  27409. this.fireEvent("click");
  27410. }
  27411. },
  27412. setTitle: function(text) {
  27413. var label = this.getDom("label");
  27414. label.innerHTML = text;
  27415. }
  27416. };
  27417. utils.inherits(Button, UIBase);
  27418. utils.extend(Button.prototype, Stateful);
  27419. })();
  27420. // ui/splitbutton.js
  27421. ///import core
  27422. ///import uicore
  27423. ///import ui/stateful.js
  27424. ;(function() {
  27425. var utils = baidu.editor.utils,
  27426. uiUtils = baidu.editor.ui.uiUtils,
  27427. domUtils = baidu.editor.dom.domUtils,
  27428. UIBase = baidu.editor.ui.UIBase,
  27429. Stateful = baidu.editor.ui.Stateful,
  27430. SplitButton = (baidu.editor.ui.SplitButton = function(options) {
  27431. this.initOptions(options);
  27432. this.initSplitButton();
  27433. });
  27434. SplitButton.prototype = {
  27435. popup: null,
  27436. uiName: "splitbutton",
  27437. title: "",
  27438. initSplitButton: function() {
  27439. this.initUIBase();
  27440. this.Stateful_init();
  27441. var me = this;
  27442. if (this.popup != null) {
  27443. var popup = this.popup;
  27444. this.popup = null;
  27445. this.setPopup(popup);
  27446. }
  27447. },
  27448. _UIBase_postRender: UIBase.prototype.postRender,
  27449. postRender: function() {
  27450. this.Stateful_postRender();
  27451. this._UIBase_postRender();
  27452. },
  27453. setPopup: function(popup) {
  27454. if (this.popup === popup) return;
  27455. if (this.popup != null) {
  27456. this.popup.dispose();
  27457. }
  27458. popup.addListener("show", utils.bind(this._onPopupShow, this));
  27459. popup.addListener("hide", utils.bind(this._onPopupHide, this));
  27460. popup.addListener(
  27461. "postrender",
  27462. utils.bind(function() {
  27463. popup
  27464. .getDom("body")
  27465. .appendChild(
  27466. uiUtils.createElementByHtml(
  27467. '<div id="' +
  27468. this.popup.id +
  27469. '_bordereraser" class="edui-bordereraser edui-background" style="width:' +
  27470. (uiUtils.getClientRect(this.getDom()).width + 20) +
  27471. 'px"></div>'
  27472. )
  27473. );
  27474. popup.getDom().className += " " + this.className;
  27475. }, this)
  27476. );
  27477. this.popup = popup;
  27478. },
  27479. _onPopupShow: function() {
  27480. this.addState("opened");
  27481. },
  27482. _onPopupHide: function() {
  27483. this.removeState("opened");
  27484. },
  27485. getHtmlTpl: function() {
  27486. return (
  27487. '<div id="##" class="edui-box %%">' +
  27488. "<div " +
  27489. (this.title ? 'title="' + this.title + '"' : "") +
  27490. ' id="##_state" stateful><div class="%%-body">' +
  27491. '<div id="##_button_body" class="edui-box edui-button-body" onclick="$$._onButtonClick(event, this);">' +
  27492. '<div class="edui-box edui-icon"><svg class="edui-iconfont"><use xlink:href="#' + this.className + '"></use></svg></div>' +
  27493. "</div>" +
  27494. '<div class="edui-box edui-splitborder"></div>' +
  27495. '<div class="edui-box edui-arrow" onclick="$$._onArrowClick();"></div>' +
  27496. "</div></div></div>"
  27497. );
  27498. },
  27499. showPopup: function() {
  27500. // 当popup往上弹出的时候,做特殊处理
  27501. var rect = uiUtils.getClientRect(this.getDom());
  27502. rect.top -= this.popup.SHADOW_RADIUS;
  27503. rect.height += this.popup.SHADOW_RADIUS;
  27504. this.popup.showAnchorRect(rect);
  27505. },
  27506. _onArrowClick: function(event, el) {
  27507. if (!this.isDisabled()) {
  27508. this.showPopup();
  27509. }
  27510. },
  27511. _onButtonClick: function() {
  27512. if (!this.isDisabled()) {
  27513. this.fireEvent("buttonclick");
  27514. }
  27515. }
  27516. };
  27517. utils.inherits(SplitButton, UIBase);
  27518. utils.extend(SplitButton.prototype, Stateful, true);
  27519. })();
  27520. // ui/colorbutton.js
  27521. ///import core
  27522. ///import uicore
  27523. ///import ui/colorpicker.js
  27524. ///import ui/popup.js
  27525. ///import ui/splitbutton.js
  27526. ;(function() {
  27527. var utils = baidu.editor.utils,
  27528. uiUtils = baidu.editor.ui.uiUtils,
  27529. ColorPicker = baidu.editor.ui.ColorPicker,
  27530. Popup = baidu.editor.ui.Popup,
  27531. SplitButton = baidu.editor.ui.SplitButton,
  27532. ColorButton = (baidu.editor.ui.ColorButton = function(options) {
  27533. this.initOptions(options);
  27534. this.initColorButton();
  27535. });
  27536. ColorButton.prototype = {
  27537. initColorButton: function() {
  27538. var me = this;
  27539. this.popup = new Popup({
  27540. content: new ColorPicker({
  27541. noColorText: me.editor.getLang("clearColor"),
  27542. editor: me.editor,
  27543. onpickcolor: function(t, color) {
  27544. me._onPickColor(color);
  27545. },
  27546. onpicknocolor: function(t, color) {
  27547. me._onPickNoColor(color);
  27548. }
  27549. }),
  27550. editor: me.editor
  27551. });
  27552. this.initSplitButton();
  27553. },
  27554. _SplitButton_postRender: SplitButton.prototype.postRender,
  27555. postRender: function() {
  27556. this._SplitButton_postRender();
  27557. this.getDom("button_body").appendChild(
  27558. uiUtils.createElementByHtml(
  27559. '<div id="' + this.id + '_colorlump" class="edui-colorlump"></div>'
  27560. )
  27561. );
  27562. this.getDom().className += " edui-colorbutton";
  27563. },
  27564. setColor: function(color) {
  27565. this.getDom("colorlump").style.backgroundColor = color;
  27566. this.color = color;
  27567. },
  27568. _onPickColor: function(color) {
  27569. if (this.fireEvent("pickcolor", color) !== false) {
  27570. this.setColor(color);
  27571. this.popup.hide();
  27572. }
  27573. },
  27574. _onPickNoColor: function(color) {
  27575. if (this.fireEvent("picknocolor") !== false) {
  27576. this.popup.hide();
  27577. }
  27578. }
  27579. };
  27580. utils.inherits(ColorButton, SplitButton);
  27581. })();
  27582. // ui/tablebutton.js
  27583. ///import core
  27584. ///import uicore
  27585. ///import ui/popup.js
  27586. ///import ui/tablepicker.js
  27587. ///import ui/splitbutton.js
  27588. ;(function() {
  27589. var utils = baidu.editor.utils,
  27590. Popup = baidu.editor.ui.Popup,
  27591. TablePicker = baidu.editor.ui.TablePicker,
  27592. SplitButton = baidu.editor.ui.SplitButton,
  27593. TableButton = (baidu.editor.ui.TableButton = function(options) {
  27594. this.initOptions(options);
  27595. this.initTableButton();
  27596. });
  27597. TableButton.prototype = {
  27598. initTableButton: function() {
  27599. var me = this;
  27600. this.popup = new Popup({
  27601. content: new TablePicker({
  27602. editor: me.editor,
  27603. onpicktable: function(t, numCols, numRows) {
  27604. me._onPickTable(numCols, numRows);
  27605. }
  27606. }),
  27607. editor: me.editor
  27608. });
  27609. this.initSplitButton();
  27610. },
  27611. _onPickTable: function(numCols, numRows) {
  27612. if (this.fireEvent("picktable", numCols, numRows) !== false) {
  27613. this.popup.hide();
  27614. }
  27615. }
  27616. };
  27617. utils.inherits(TableButton, SplitButton);
  27618. })();
  27619. // ui/autotypesetpicker.js
  27620. ///import core
  27621. ///import uicore
  27622. ;(function() {
  27623. var utils = baidu.editor.utils,
  27624. UIBase = baidu.editor.ui.UIBase;
  27625. var AutoTypeSetPicker = (baidu.editor.ui.AutoTypeSetPicker = function(
  27626. options
  27627. ) {
  27628. this.initOptions(options);
  27629. this.initAutoTypeSetPicker();
  27630. });
  27631. AutoTypeSetPicker.prototype = {
  27632. initAutoTypeSetPicker: function() {
  27633. this.initUIBase();
  27634. },
  27635. getHtmlTpl: function() {
  27636. var me = this.editor,
  27637. opt = me.options.autotypeset,
  27638. lang = me.getLang("autoTypeSet");
  27639. var textAlignInputName = "textAlignValue" + me.uid,
  27640. imageBlockInputName = "imageBlockLineValue" + me.uid,
  27641. symbolConverInputName = "symbolConverValue" + me.uid;
  27642. return (
  27643. '<div id="##" class="edui-autotypesetpicker %%">' +
  27644. '<div class="edui-autotypesetpicker-body">' +
  27645. "<table >" +
  27646. '<tr><td nowrap><input type="checkbox" name="mergeEmptyline" ' +
  27647. (opt["mergeEmptyline"] ? "checked" : "") +
  27648. ">" +
  27649. lang.mergeLine +
  27650. '</td><td colspan="2"><input type="checkbox" name="removeEmptyline" ' +
  27651. (opt["removeEmptyline"] ? "checked" : "") +
  27652. ">" +
  27653. lang.delLine +
  27654. "</td></tr>" +
  27655. '<tr><td nowrap><input type="checkbox" name="removeClass" ' +
  27656. (opt["removeClass"] ? "checked" : "") +
  27657. ">" +
  27658. lang.removeFormat +
  27659. '</td><td colspan="2"><input type="checkbox" name="indent" ' +
  27660. (opt["indent"] ? "checked" : "") +
  27661. ">" +
  27662. lang.indent +
  27663. "</td></tr>" +
  27664. "<tr>" +
  27665. '<td nowrap><input type="checkbox" name="textAlign" ' +
  27666. (opt["textAlign"] ? "checked" : "") +
  27667. ">" +
  27668. lang.alignment +
  27669. "</td>" +
  27670. '<td colspan="2" id="' +
  27671. textAlignInputName +
  27672. '">' +
  27673. '<input type="radio" name="' +
  27674. textAlignInputName +
  27675. '" value="left" ' +
  27676. (opt["textAlign"] && opt["textAlign"] == "left" ? "checked" : "") +
  27677. ">" +
  27678. me.getLang("justifyleft") +
  27679. '<input type="radio" name="' +
  27680. textAlignInputName +
  27681. '" value="center" ' +
  27682. (opt["textAlign"] && opt["textAlign"] == "center" ? "checked" : "") +
  27683. ">" +
  27684. me.getLang("justifycenter") +
  27685. '<input type="radio" name="' +
  27686. textAlignInputName +
  27687. '" value="right" ' +
  27688. (opt["textAlign"] && opt["textAlign"] == "right" ? "checked" : "") +
  27689. ">" +
  27690. me.getLang("justifyright") +
  27691. "</td>" +
  27692. "</tr>" +
  27693. "<tr>" +
  27694. '<td nowrap><input type="checkbox" name="imageBlockLine" ' +
  27695. (opt["imageBlockLine"] ? "checked" : "") +
  27696. ">" +
  27697. lang.imageFloat +
  27698. "</td>" +
  27699. '<td nowrap id="' +
  27700. imageBlockInputName +
  27701. '">' +
  27702. '<input type="radio" name="' +
  27703. imageBlockInputName +
  27704. '" value="none" ' +
  27705. (opt["imageBlockLine"] && opt["imageBlockLine"] == "none"
  27706. ? "checked"
  27707. : "") +
  27708. ">" +
  27709. me.getLang("default") +
  27710. '<input type="radio" name="' +
  27711. imageBlockInputName +
  27712. '" value="left" ' +
  27713. (opt["imageBlockLine"] && opt["imageBlockLine"] == "left"
  27714. ? "checked"
  27715. : "") +
  27716. ">" +
  27717. me.getLang("justifyleft") +
  27718. '<input type="radio" name="' +
  27719. imageBlockInputName +
  27720. '" value="center" ' +
  27721. (opt["imageBlockLine"] && opt["imageBlockLine"] == "center"
  27722. ? "checked"
  27723. : "") +
  27724. ">" +
  27725. me.getLang("justifycenter") +
  27726. '<input type="radio" name="' +
  27727. imageBlockInputName +
  27728. '" value="right" ' +
  27729. (opt["imageBlockLine"] && opt["imageBlockLine"] == "right"
  27730. ? "checked"
  27731. : "") +
  27732. ">" +
  27733. me.getLang("justifyright") +
  27734. "</td>" +
  27735. "</tr>" +
  27736. '<tr><td nowrap><input type="checkbox" name="clearFontSize" ' +
  27737. (opt["clearFontSize"] ? "checked" : "") +
  27738. ">" +
  27739. lang.removeFontsize +
  27740. '</td><td colspan="2"><input type="checkbox" name="clearFontFamily" ' +
  27741. (opt["clearFontFamily"] ? "checked" : "") +
  27742. ">" +
  27743. lang.removeFontFamily +
  27744. "</td></tr>" +
  27745. '<tr><td nowrap colspan="3"><input type="checkbox" name="removeEmptyNode" ' +
  27746. (opt["removeEmptyNode"] ? "checked" : "") +
  27747. ">" +
  27748. lang.removeHtml +
  27749. "</td></tr>" +
  27750. '<tr><td nowrap colspan="3"><input type="checkbox" name="pasteFilter" ' +
  27751. (opt["pasteFilter"] ? "checked" : "") +
  27752. ">" +
  27753. lang.pasteFilter +
  27754. "</td></tr>" +
  27755. "<tr>" +
  27756. '<td nowrap><input type="checkbox" name="symbolConver" ' +
  27757. (opt["bdc2sb"] || opt["tobdc"] ? "checked" : "") +
  27758. ">" +
  27759. lang.symbol +
  27760. "</td>" +
  27761. '<td id="' +
  27762. symbolConverInputName +
  27763. '">' +
  27764. '<input type="radio" name="bdc" value="bdc2sb" ' +
  27765. (opt["bdc2sb"] ? "checked" : "") +
  27766. ">" +
  27767. lang.bdc2sb +
  27768. '<input type="radio" name="bdc" value="tobdc" ' +
  27769. (opt["tobdc"] ? "checked" : "") +
  27770. ">" +
  27771. lang.tobdc +
  27772. "" +
  27773. "</td>" +
  27774. '<td nowrap align="right"><button >' +
  27775. lang.run +
  27776. "</button></td>" +
  27777. "</tr>" +
  27778. "</table>" +
  27779. "</div>" +
  27780. "</div>"
  27781. );
  27782. },
  27783. _UIBase_render: UIBase.prototype.render
  27784. };
  27785. utils.inherits(AutoTypeSetPicker, UIBase);
  27786. })();
  27787. // ui/autotypesetbutton.js
  27788. ///import core
  27789. ///import uicore
  27790. ///import ui/popup.js
  27791. ///import ui/autotypesetpicker.js
  27792. ///import ui/splitbutton.js
  27793. ;(function() {
  27794. var utils = baidu.editor.utils,
  27795. Popup = baidu.editor.ui.Popup,
  27796. AutoTypeSetPicker = baidu.editor.ui.AutoTypeSetPicker,
  27797. SplitButton = baidu.editor.ui.SplitButton,
  27798. AutoTypeSetButton = (baidu.editor.ui.AutoTypeSetButton = function(options) {
  27799. this.initOptions(options);
  27800. this.initAutoTypeSetButton();
  27801. });
  27802. function getPara(me) {
  27803. var opt = {},
  27804. cont = me.getDom(),
  27805. editorId = me.editor.uid,
  27806. inputType = null,
  27807. attrName = null,
  27808. ipts = domUtils.getElementsByTagName(cont, "input");
  27809. for (var i = ipts.length - 1, ipt; (ipt = ipts[i--]); ) {
  27810. inputType = ipt.getAttribute("type");
  27811. if (inputType == "checkbox") {
  27812. attrName = ipt.getAttribute("name");
  27813. opt[attrName] && delete opt[attrName];
  27814. if (ipt.checked) {
  27815. var attrValue = document.getElementById(
  27816. attrName + "Value" + editorId
  27817. );
  27818. if (attrValue) {
  27819. if (/input/gi.test(attrValue.tagName)) {
  27820. opt[attrName] = attrValue.value;
  27821. } else {
  27822. var iptChilds = attrValue.getElementsByTagName("input");
  27823. for (
  27824. var j = iptChilds.length - 1, iptchild;
  27825. (iptchild = iptChilds[j--]);
  27826. ) {
  27827. if (iptchild.checked) {
  27828. opt[attrName] = iptchild.value;
  27829. break;
  27830. }
  27831. }
  27832. }
  27833. } else {
  27834. opt[attrName] = true;
  27835. }
  27836. } else {
  27837. opt[attrName] = false;
  27838. }
  27839. } else {
  27840. opt[ipt.getAttribute("value")] = ipt.checked;
  27841. }
  27842. }
  27843. var selects = domUtils.getElementsByTagName(cont, "select");
  27844. for (var i = 0, si; (si = selects[i++]); ) {
  27845. var attr = si.getAttribute("name");
  27846. opt[attr] = opt[attr] ? si.value : "";
  27847. }
  27848. utils.extend(me.editor.options.autotypeset, opt);
  27849. me.editor.setPreferences("autotypeset", opt);
  27850. }
  27851. AutoTypeSetButton.prototype = {
  27852. initAutoTypeSetButton: function() {
  27853. var me = this;
  27854. this.popup = new Popup({
  27855. //传入配置参数
  27856. content: new AutoTypeSetPicker({ editor: me.editor }),
  27857. editor: me.editor,
  27858. hide: function() {
  27859. if (!this._hidden && this.getDom()) {
  27860. getPara(this);
  27861. this.getDom().style.display = "none";
  27862. this._hidden = true;
  27863. this.fireEvent("hide");
  27864. }
  27865. }
  27866. });
  27867. var flag = 0;
  27868. this.popup.addListener("postRenderAfter", function() {
  27869. var popupUI = this;
  27870. if (flag) return;
  27871. var cont = this.getDom(),
  27872. btn = cont.getElementsByTagName("button")[0];
  27873. btn.onclick = function() {
  27874. getPara(popupUI);
  27875. me.editor.execCommand("autotypeset");
  27876. popupUI.hide();
  27877. };
  27878. domUtils.on(cont, "click", function(e) {
  27879. var target = e.target || e.srcElement,
  27880. editorId = me.editor.uid;
  27881. if (target && target.tagName == "INPUT") {
  27882. // 点击图片浮动的checkbox,去除对应的radio
  27883. if (
  27884. target.name == "imageBlockLine" ||
  27885. target.name == "textAlign" ||
  27886. target.name == "symbolConver"
  27887. ) {
  27888. var checked = target.checked,
  27889. radioTd = document.getElementById(
  27890. target.name + "Value" + editorId
  27891. ),
  27892. radios = radioTd.getElementsByTagName("input"),
  27893. defalutSelect = {
  27894. imageBlockLine: "none",
  27895. textAlign: "left",
  27896. symbolConver: "tobdc"
  27897. };
  27898. for (var i = 0; i < radios.length; i++) {
  27899. if (checked) {
  27900. if (radios[i].value == defalutSelect[target.name]) {
  27901. radios[i].checked = "checked";
  27902. }
  27903. } else {
  27904. radios[i].checked = false;
  27905. }
  27906. }
  27907. }
  27908. // 点击radio,选中对应的checkbox
  27909. if (
  27910. target.name == "imageBlockLineValue" + editorId ||
  27911. target.name == "textAlignValue" + editorId ||
  27912. target.name == "bdc"
  27913. ) {
  27914. var checkboxs = target.parentNode.previousSibling.getElementsByTagName(
  27915. "input"
  27916. );
  27917. checkboxs && (checkboxs[0].checked = true);
  27918. }
  27919. getPara(popupUI);
  27920. }
  27921. });
  27922. flag = 1;
  27923. });
  27924. this.initSplitButton();
  27925. }
  27926. };
  27927. utils.inherits(AutoTypeSetButton, SplitButton);
  27928. })();
  27929. // ui/cellalignpicker.js
  27930. ///import core
  27931. ///import uicore
  27932. ;(function() {
  27933. var utils = baidu.editor.utils,
  27934. Popup = baidu.editor.ui.Popup,
  27935. Stateful = baidu.editor.ui.Stateful,
  27936. UIBase = baidu.editor.ui.UIBase;
  27937. /**
  27938. * 该参数将新增一个参数: selected, 参数类型为一个Object, 形如{ 'align': 'center', 'valign': 'top' }, 表示单元格的初始
  27939. * 对齐状态为: 竖直居上,水平居中; 其中 align的取值为:'center', 'left', 'right'; valign的取值为: 'top', 'middle', 'bottom'
  27940. * @update 2013/4/2 hancong03@baidu.com
  27941. */
  27942. var CellAlignPicker = (baidu.editor.ui.CellAlignPicker = function(options) {
  27943. this.initOptions(options);
  27944. this.initSelected();
  27945. this.initCellAlignPicker();
  27946. });
  27947. CellAlignPicker.prototype = {
  27948. //初始化选中状态, 该方法将根据传递进来的参数获取到应该选中的对齐方式图标的索引
  27949. initSelected: function() {
  27950. var status = {
  27951. valign: {
  27952. top: 0,
  27953. middle: 1,
  27954. bottom: 2
  27955. },
  27956. align: {
  27957. left: 0,
  27958. center: 1,
  27959. right: 2
  27960. },
  27961. count: 3
  27962. },
  27963. result = -1;
  27964. if (this.selected) {
  27965. this.selectedIndex =
  27966. status.valign[this.selected.valign] * status.count +
  27967. status.align[this.selected.align];
  27968. }
  27969. },
  27970. initCellAlignPicker: function() {
  27971. this.initUIBase();
  27972. this.Stateful_init();
  27973. },
  27974. getHtmlTpl: function() {
  27975. var alignType = ["left", "center", "right"],
  27976. COUNT = 9,
  27977. tempClassName = null,
  27978. tempIndex = -1,
  27979. tmpl = [];
  27980. for (var i = 0; i < COUNT; i++) {
  27981. tempClassName = this.selectedIndex === i
  27982. ? ' class="edui-cellalign-selected" '
  27983. : "";
  27984. tempIndex = i % 3;
  27985. tempIndex === 0 && tmpl.push("<tr>");
  27986. tmpl.push(
  27987. '<td index="' +
  27988. i +
  27989. '" ' +
  27990. tempClassName +
  27991. ' stateful><div class="edui-icon edui-' +
  27992. alignType[tempIndex] +
  27993. '"></div></td>'
  27994. );
  27995. tempIndex === 2 && tmpl.push("</tr>");
  27996. }
  27997. return (
  27998. '<div id="##" class="edui-cellalignpicker %%">' +
  27999. '<div class="edui-cellalignpicker-body">' +
  28000. '<table onclick="$$._onClick(event);">' +
  28001. tmpl.join("") +
  28002. "</table>" +
  28003. "</div>" +
  28004. "</div>"
  28005. );
  28006. },
  28007. getStateDom: function() {
  28008. return this.target;
  28009. },
  28010. _onClick: function(evt) {
  28011. var target = evt.target || evt.srcElement;
  28012. if (/icon/.test(target.className)) {
  28013. this.items[target.parentNode.getAttribute("index")].onclick();
  28014. Popup.postHide(evt);
  28015. }
  28016. },
  28017. _UIBase_render: UIBase.prototype.render
  28018. };
  28019. utils.inherits(CellAlignPicker, UIBase);
  28020. utils.extend(CellAlignPicker.prototype, Stateful, true);
  28021. })();
  28022. // ui/pastepicker.js
  28023. ///import core
  28024. ///import uicore
  28025. ;(function() {
  28026. var utils = baidu.editor.utils,
  28027. Stateful = baidu.editor.ui.Stateful,
  28028. uiUtils = baidu.editor.ui.uiUtils,
  28029. UIBase = baidu.editor.ui.UIBase;
  28030. var PastePicker = (baidu.editor.ui.PastePicker = function(options) {
  28031. this.initOptions(options);
  28032. this.initPastePicker();
  28033. });
  28034. PastePicker.prototype = {
  28035. initPastePicker: function() {
  28036. this.initUIBase();
  28037. this.Stateful_init();
  28038. },
  28039. getHtmlTpl: function() {
  28040. return (
  28041. '<div class="edui-pasteicon" onclick="$$._onClick(this)"></div>' +
  28042. '<div class="edui-pastecontainer">' +
  28043. '<div class="edui-title">' +
  28044. this.editor.getLang("pasteOpt") +
  28045. "</div>" +
  28046. '<div class="edui-button">' +
  28047. '<div title="' +
  28048. this.editor.getLang("pasteSourceFormat") +
  28049. '" onclick="$$.format(false)" stateful>' +
  28050. '<div class="edui-richtxticon"></div></div>' +
  28051. '<div title="' +
  28052. this.editor.getLang("tagFormat") +
  28053. '" onclick="$$.format(2)" stateful>' +
  28054. '<div class="edui-tagicon"></div></div>' +
  28055. '<div title="' +
  28056. this.editor.getLang("pasteTextFormat") +
  28057. '" onclick="$$.format(true)" stateful>' +
  28058. '<div class="edui-plaintxticon"></div></div>' +
  28059. "</div>" +
  28060. "</div>" +
  28061. "</div>"
  28062. );
  28063. },
  28064. getStateDom: function() {
  28065. return this.target;
  28066. },
  28067. format: function(param) {
  28068. this.editor.ui._isTransfer = true;
  28069. this.editor.fireEvent("pasteTransfer", param);
  28070. },
  28071. _onClick: function(cur) {
  28072. var node = domUtils.getNextDomNode(cur),
  28073. screenHt = uiUtils.getViewportRect().height,
  28074. subPop = uiUtils.getClientRect(node);
  28075. if (subPop.top + subPop.height > screenHt)
  28076. node.style.top = -subPop.height - cur.offsetHeight + "px";
  28077. else node.style.top = "";
  28078. if (/hidden/gi.test(domUtils.getComputedStyle(node, "visibility"))) {
  28079. node.style.visibility = "visible";
  28080. domUtils.addClass(cur, "edui-state-opened");
  28081. } else {
  28082. node.style.visibility = "hidden";
  28083. domUtils.removeClasses(cur, "edui-state-opened");
  28084. }
  28085. },
  28086. _UIBase_render: UIBase.prototype.render
  28087. };
  28088. utils.inherits(PastePicker, UIBase);
  28089. utils.extend(PastePicker.prototype, Stateful, true);
  28090. })();
  28091. // ui/toolbar.js
  28092. ;(function() {
  28093. var utils = baidu.editor.utils,
  28094. uiUtils = baidu.editor.ui.uiUtils,
  28095. UIBase = baidu.editor.ui.UIBase,
  28096. Toolbar = (baidu.editor.ui.Toolbar = function(options) {
  28097. this.initOptions(options);
  28098. this.initToolbar();
  28099. });
  28100. Toolbar.prototype = {
  28101. items: null,
  28102. initToolbar: function() {
  28103. this.items = this.items || [];
  28104. this.initUIBase();
  28105. },
  28106. add: function(item, index) {
  28107. if (index === undefined) {
  28108. this.items.push(item);
  28109. } else {
  28110. this.items.splice(index, 0, item);
  28111. }
  28112. },
  28113. getHtmlTpl: function() {
  28114. var buff = [];
  28115. for (var i = 0; i < this.items.length; i++) {
  28116. buff[i] = this.items[i].renderHtml();
  28117. }
  28118. return (
  28119. '<div id="##" class="edui-toolbar %%" onselectstart="return false;" onmousedown="return $$._onMouseDown(event, this);">' +
  28120. buff.join("") +
  28121. "</div>"
  28122. );
  28123. },
  28124. postRender: function() {
  28125. var box = this.getDom();
  28126. for (var i = 0; i < this.items.length; i++) {
  28127. this.items[i].postRender();
  28128. }
  28129. uiUtils.makeUnselectable(box);
  28130. },
  28131. _onMouseDown: function(e) {
  28132. var target = e.target || e.srcElement,
  28133. tagName = target && target.tagName && target.tagName.toLowerCase();
  28134. if (tagName == "input" || tagName == "object" || tagName == "object") {
  28135. return false;
  28136. }
  28137. }
  28138. };
  28139. utils.inherits(Toolbar, UIBase);
  28140. })();
  28141. // ui/menu.js
  28142. ///import core
  28143. ///import uicore
  28144. ///import ui\popup.js
  28145. ///import ui\stateful.js
  28146. ;(function() {
  28147. var utils = baidu.editor.utils,
  28148. domUtils = baidu.editor.dom.domUtils,
  28149. uiUtils = baidu.editor.ui.uiUtils,
  28150. UIBase = baidu.editor.ui.UIBase,
  28151. Popup = baidu.editor.ui.Popup,
  28152. Stateful = baidu.editor.ui.Stateful,
  28153. CellAlignPicker = baidu.editor.ui.CellAlignPicker,
  28154. Menu = (baidu.editor.ui.Menu = function(options) {
  28155. this.initOptions(options);
  28156. this.initMenu();
  28157. });
  28158. var menuSeparator = {
  28159. renderHtml: function() {
  28160. return '<div class="edui-menuitem edui-menuseparator"><div class="edui-menuseparator-inner"></div></div>';
  28161. },
  28162. postRender: function() {},
  28163. queryAutoHide: function() {
  28164. return true;
  28165. }
  28166. };
  28167. Menu.prototype = {
  28168. items: null,
  28169. uiName: "menu",
  28170. initMenu: function() {
  28171. this.items = this.items || [];
  28172. this.initPopup();
  28173. this.initItems();
  28174. },
  28175. initItems: function() {
  28176. for (var i = 0; i < this.items.length; i++) {
  28177. var item = this.items[i];
  28178. if (item == "-") {
  28179. this.items[i] = this.getSeparator();
  28180. } else if (!(item instanceof MenuItem)) {
  28181. item.editor = this.editor;
  28182. item.theme = this.editor.options.theme;
  28183. this.items[i] = this.createItem(item);
  28184. }
  28185. }
  28186. },
  28187. getSeparator: function() {
  28188. return menuSeparator;
  28189. },
  28190. createItem: function(item) {
  28191. //新增一个参数menu, 该参数存储了menuItem所对应的menu引用
  28192. item.menu = this;
  28193. return new MenuItem(item);
  28194. },
  28195. _Popup_getContentHtmlTpl: Popup.prototype.getContentHtmlTpl,
  28196. getContentHtmlTpl: function() {
  28197. if (this.items.length == 0) {
  28198. return this._Popup_getContentHtmlTpl();
  28199. }
  28200. var buff = [];
  28201. for (var i = 0; i < this.items.length; i++) {
  28202. var item = this.items[i];
  28203. buff[i] = item.renderHtml();
  28204. }
  28205. return '<div class="%%-body">' + buff.join("") + "</div>";
  28206. },
  28207. _Popup_postRender: Popup.prototype.postRender,
  28208. postRender: function() {
  28209. var me = this;
  28210. for (var i = 0; i < this.items.length; i++) {
  28211. var item = this.items[i];
  28212. item.ownerMenu = this;
  28213. item.postRender();
  28214. }
  28215. domUtils.on(this.getDom(), "mouseover", function(evt) {
  28216. evt = evt || event;
  28217. var rel = evt.relatedTarget || evt.fromElement;
  28218. var el = me.getDom();
  28219. if (!uiUtils.contains(el, rel) && el !== rel) {
  28220. me.fireEvent("over");
  28221. }
  28222. });
  28223. this._Popup_postRender();
  28224. },
  28225. queryAutoHide: function(el) {
  28226. if (el) {
  28227. if (uiUtils.contains(this.getDom(), el)) {
  28228. return false;
  28229. }
  28230. for (var i = 0; i < this.items.length; i++) {
  28231. var item = this.items[i];
  28232. if (item.queryAutoHide(el) === false) {
  28233. return false;
  28234. }
  28235. }
  28236. }
  28237. },
  28238. clearItems: function() {
  28239. for (var i = 0; i < this.items.length; i++) {
  28240. var item = this.items[i];
  28241. clearTimeout(item._showingTimer);
  28242. clearTimeout(item._closingTimer);
  28243. if (item.subMenu) {
  28244. item.subMenu.destroy();
  28245. }
  28246. }
  28247. this.items = [];
  28248. },
  28249. destroy: function() {
  28250. if (this.getDom()) {
  28251. domUtils.remove(this.getDom());
  28252. }
  28253. this.clearItems();
  28254. },
  28255. dispose: function() {
  28256. this.destroy();
  28257. }
  28258. };
  28259. utils.inherits(Menu, Popup);
  28260. /**
  28261. * @update 2013/04/03 hancong03 新增一个参数menu, 该参数存储了menuItem所对应的menu引用
  28262. * @type {Function}
  28263. */
  28264. var MenuItem = (baidu.editor.ui.MenuItem = function(options) {
  28265. this.initOptions(options);
  28266. this.initUIBase();
  28267. this.Stateful_init();
  28268. if (this.subMenu && !(this.subMenu instanceof Menu)) {
  28269. if (options.className && options.className.indexOf("aligntd") != -1) {
  28270. var me = this;
  28271. //获取单元格对齐初始状态
  28272. this.subMenu.selected = this.editor.queryCommandValue("cellalignment");
  28273. this.subMenu = new Popup({
  28274. content: new CellAlignPicker(this.subMenu),
  28275. parentMenu: me,
  28276. editor: me.editor,
  28277. destroy: function() {
  28278. if (this.getDom()) {
  28279. domUtils.remove(this.getDom());
  28280. }
  28281. }
  28282. });
  28283. this.subMenu.addListener("postRenderAfter", function() {
  28284. domUtils.on(this.getDom(), "mouseover", function() {
  28285. me.addState("opened");
  28286. });
  28287. });
  28288. } else {
  28289. this.subMenu = new Menu(this.subMenu);
  28290. }
  28291. }
  28292. });
  28293. MenuItem.prototype = {
  28294. label: "",
  28295. subMenu: null,
  28296. ownerMenu: null,
  28297. uiName: "menuitem",
  28298. alwalysHoverable: true,
  28299. getHtmlTpl: function() {
  28300. return (
  28301. '<div id="##" class="%%" stateful onclick="$$._onClick(event, this);">' +
  28302. '<div class="%%-body">' +
  28303. this.renderLabelHtml() +
  28304. "</div>" +
  28305. "</div>"
  28306. );
  28307. },
  28308. postRender: function() {
  28309. var me = this;
  28310. this.addListener("over", function() {
  28311. me.ownerMenu.fireEvent("submenuover", me);
  28312. if (me.subMenu) {
  28313. me.delayShowSubMenu();
  28314. }
  28315. });
  28316. if (this.subMenu) {
  28317. this.getDom().className += " edui-hassubmenu";
  28318. this.subMenu.render();
  28319. this.addListener("out", function() {
  28320. me.delayHideSubMenu();
  28321. });
  28322. this.subMenu.addListener("over", function() {
  28323. clearTimeout(me._closingTimer);
  28324. me._closingTimer = null;
  28325. me.addState("opened");
  28326. });
  28327. this.ownerMenu.addListener("hide", function() {
  28328. me.hideSubMenu();
  28329. });
  28330. this.ownerMenu.addListener("submenuover", function(t, subMenu) {
  28331. if (subMenu !== me) {
  28332. me.delayHideSubMenu();
  28333. }
  28334. });
  28335. this.subMenu._bakQueryAutoHide = this.subMenu.queryAutoHide;
  28336. this.subMenu.queryAutoHide = function(el) {
  28337. if (el && uiUtils.contains(me.getDom(), el)) {
  28338. return false;
  28339. }
  28340. return this._bakQueryAutoHide(el);
  28341. };
  28342. }
  28343. this.getDom().style.tabIndex = "-1";
  28344. uiUtils.makeUnselectable(this.getDom());
  28345. this.Stateful_postRender();
  28346. },
  28347. delayShowSubMenu: function() {
  28348. var me = this;
  28349. if (!me.isDisabled()) {
  28350. me.addState("opened");
  28351. clearTimeout(me._showingTimer);
  28352. clearTimeout(me._closingTimer);
  28353. me._closingTimer = null;
  28354. me._showingTimer = setTimeout(function() {
  28355. me.showSubMenu();
  28356. }, 250);
  28357. }
  28358. },
  28359. delayHideSubMenu: function() {
  28360. var me = this;
  28361. if (!me.isDisabled()) {
  28362. me.removeState("opened");
  28363. clearTimeout(me._showingTimer);
  28364. if (!me._closingTimer) {
  28365. me._closingTimer = setTimeout(function() {
  28366. if (!me.hasState("opened")) {
  28367. me.hideSubMenu();
  28368. }
  28369. me._closingTimer = null;
  28370. }, 400);
  28371. }
  28372. }
  28373. },
  28374. renderLabelHtml: function() {
  28375. return (
  28376. '<div class="edui-arrow"></div>' +
  28377. '<div class="edui-box edui-icon"></div>' +
  28378. '<div class="edui-box edui-label %%-label">' +
  28379. (this.label || "") +
  28380. "</div>"
  28381. );
  28382. },
  28383. getStateDom: function() {
  28384. return this.getDom();
  28385. },
  28386. queryAutoHide: function(el) {
  28387. if (this.subMenu && this.hasState("opened")) {
  28388. return this.subMenu.queryAutoHide(el);
  28389. }
  28390. },
  28391. _onClick: function(event, this_) {
  28392. if (this.hasState("disabled")) return;
  28393. if (this.fireEvent("click", event, this_) !== false) {
  28394. if (this.subMenu) {
  28395. this.showSubMenu();
  28396. } else {
  28397. Popup.postHide(event);
  28398. }
  28399. }
  28400. },
  28401. showSubMenu: function() {
  28402. var rect = uiUtils.getClientRect(this.getDom());
  28403. rect.right -= 5;
  28404. rect.left += 2;
  28405. rect.width -= 7;
  28406. rect.top -= 4;
  28407. rect.bottom += 4;
  28408. rect.height += 8;
  28409. this.subMenu.showAnchorRect(rect, true, true);
  28410. },
  28411. hideSubMenu: function() {
  28412. this.subMenu.hide();
  28413. }
  28414. };
  28415. utils.inherits(MenuItem, UIBase);
  28416. utils.extend(MenuItem.prototype, Stateful, true);
  28417. })();
  28418. // ui/combox.js
  28419. ///import core
  28420. ///import uicore
  28421. ///import ui/menu.js
  28422. ///import ui/splitbutton.js
  28423. ;(function() {
  28424. // todo: menu和item提成通用list
  28425. var utils = baidu.editor.utils,
  28426. uiUtils = baidu.editor.ui.uiUtils,
  28427. Menu = baidu.editor.ui.Menu,
  28428. SplitButton = baidu.editor.ui.SplitButton,
  28429. Combox = (baidu.editor.ui.Combox = function(options) {
  28430. this.initOptions(options);
  28431. this.initCombox();
  28432. });
  28433. Combox.prototype = {
  28434. uiName: "combox",
  28435. onbuttonclick: function() {
  28436. this.showPopup();
  28437. },
  28438. initCombox: function() {
  28439. var me = this;
  28440. this.items = this.items || [];
  28441. for (var i = 0; i < this.items.length; i++) {
  28442. var item = this.items[i];
  28443. item.uiName = "listitem";
  28444. item.index = i;
  28445. item.onclick = function() {
  28446. me.selectByIndex(this.index);
  28447. };
  28448. }
  28449. this.popup = new Menu({
  28450. items: this.items,
  28451. uiName: "list",
  28452. editor: this.editor,
  28453. captureWheel: true,
  28454. combox: this
  28455. });
  28456. this.initSplitButton();
  28457. },
  28458. _SplitButton_postRender: SplitButton.prototype.postRender,
  28459. postRender: function() {
  28460. this._SplitButton_postRender();
  28461. this.setLabel(this.label || "");
  28462. this.setValue(this.initValue || "");
  28463. },
  28464. showPopup: function() {
  28465. var rect = uiUtils.getClientRect(this.getDom());
  28466. rect.top += 1;
  28467. rect.bottom -= 1;
  28468. rect.height -= 2;
  28469. this.popup.showAnchorRect(rect);
  28470. },
  28471. getValue: function() {
  28472. return this.value;
  28473. },
  28474. setValue: function(value) {
  28475. var index = this.indexByValue(value);
  28476. if (index != -1) {
  28477. this.selectedIndex = index;
  28478. this.setLabel(this.items[index].label);
  28479. this.value = this.items[index].value;
  28480. } else {
  28481. this.selectedIndex = -1;
  28482. this.setLabel(this.getLabelForUnknowValue(value));
  28483. this.value = value;
  28484. }
  28485. },
  28486. setLabel: function(label) {
  28487. this.getDom("button_body").innerHTML = label;
  28488. this.label = label;
  28489. },
  28490. getLabelForUnknowValue: function(value) {
  28491. return value;
  28492. },
  28493. indexByValue: function(value) {
  28494. for (var i = 0; i < this.items.length; i++) {
  28495. if (value == this.items[i].value) {
  28496. return i;
  28497. }
  28498. }
  28499. return -1;
  28500. },
  28501. getItem: function(index) {
  28502. return this.items[index];
  28503. },
  28504. selectByIndex: function(index) {
  28505. if (
  28506. index < this.items.length &&
  28507. this.fireEvent("select", index) !== false
  28508. ) {
  28509. this.selectedIndex = index;
  28510. this.value = this.items[index].value;
  28511. this.setLabel(this.items[index].label);
  28512. }
  28513. }
  28514. };
  28515. utils.inherits(Combox, SplitButton);
  28516. })();
  28517. // ui/dialog.js
  28518. ///import core
  28519. ///import uicore
  28520. ///import ui/mask.js
  28521. ///import ui/button.js
  28522. ;(function() {
  28523. var utils = baidu.editor.utils,
  28524. domUtils = baidu.editor.dom.domUtils,
  28525. uiUtils = baidu.editor.ui.uiUtils,
  28526. Mask = baidu.editor.ui.Mask,
  28527. UIBase = baidu.editor.ui.UIBase,
  28528. Button = baidu.editor.ui.Button,
  28529. Dialog = (baidu.editor.ui.Dialog = function(options) {
  28530. if (options.name) {
  28531. var name = options.name;
  28532. var cssRules = options.cssRules;
  28533. if (!options.className) {
  28534. options.className = "edui-for-" + name;
  28535. }
  28536. if (cssRules) {
  28537. options.cssRules =
  28538. ".edui-for-" + name + " .edui-dialog-content {" + cssRules + "}";
  28539. }
  28540. }
  28541. this.initOptions(
  28542. utils.extend(
  28543. {
  28544. autoReset: true,
  28545. draggable: true,
  28546. onok: function() {},
  28547. oncancel: function() {},
  28548. onclose: function(t, ok) {
  28549. return ok ? this.onok() : this.oncancel();
  28550. },
  28551. //是否控制dialog中的scroll事件, 默认为不阻止
  28552. holdScroll: false
  28553. },
  28554. options
  28555. )
  28556. );
  28557. this.initDialog();
  28558. });
  28559. var modalMask;
  28560. var dragMask;
  28561. var activeDialog;
  28562. Dialog.prototype = {
  28563. draggable: false,
  28564. uiName: "dialog",
  28565. initDialog: function() {
  28566. var me = this,
  28567. theme = this.editor.options.theme;
  28568. if (this.cssRules) {
  28569. this.cssRules = ".edui-" + theme + " " + this.cssRules;
  28570. utils.cssRule("edui-customize-" + this.name + "-style", this.cssRules);
  28571. }
  28572. this.initUIBase();
  28573. this.modalMask =
  28574. modalMask ||
  28575. (modalMask = new Mask({
  28576. className: "edui-dialog-modalmask",
  28577. theme: theme,
  28578. onclick: function() {
  28579. activeDialog && activeDialog.close(false);
  28580. }
  28581. }));
  28582. this.dragMask =
  28583. dragMask ||
  28584. (dragMask = new Mask({
  28585. className: "edui-dialog-dragmask",
  28586. theme: theme
  28587. }));
  28588. this.closeButton = new Button({
  28589. className: "edui-dialog-closebutton",
  28590. title: me.closeDialog,
  28591. theme: theme,
  28592. onclick: function() {
  28593. me.close(false);
  28594. }
  28595. });
  28596. this.fullscreen && this.initResizeEvent();
  28597. if (this.buttons) {
  28598. for (var i = 0; i < this.buttons.length; i++) {
  28599. if (!(this.buttons[i] instanceof Button)) {
  28600. this.buttons[i] = new Button(
  28601. utils.extend(
  28602. this.buttons[i],
  28603. {
  28604. editor: this.editor
  28605. },
  28606. true
  28607. )
  28608. );
  28609. }
  28610. }
  28611. }
  28612. },
  28613. initResizeEvent: function() {
  28614. var me = this;
  28615. domUtils.on(window, "resize", function() {
  28616. if (me._hidden || me._hidden === undefined) {
  28617. return;
  28618. }
  28619. if (me.__resizeTimer) {
  28620. window.clearTimeout(me.__resizeTimer);
  28621. }
  28622. me.__resizeTimer = window.setTimeout(function() {
  28623. me.__resizeTimer = null;
  28624. var dialogWrapNode = me.getDom(),
  28625. contentNode = me.getDom("content"),
  28626. wrapRect = UE.ui.uiUtils.getClientRect(dialogWrapNode),
  28627. contentRect = UE.ui.uiUtils.getClientRect(contentNode),
  28628. vpRect = uiUtils.getViewportRect();
  28629. contentNode.style.width =
  28630. vpRect.width - wrapRect.width + contentRect.width + "px";
  28631. contentNode.style.height =
  28632. vpRect.height - wrapRect.height + contentRect.height + "px";
  28633. dialogWrapNode.style.width = vpRect.width + "px";
  28634. dialogWrapNode.style.height = vpRect.height + "px";
  28635. me.fireEvent("resize");
  28636. }, 100);
  28637. });
  28638. },
  28639. fitSize: function() {
  28640. var popBodyEl = this.getDom("body");
  28641. // if (!(baidu.editor.browser.ie && baidu.editor.browser.version == 7)) {
  28642. // uiUtils.removeStyle(popBodyEl, 'width');
  28643. // uiUtils.removeStyle(popBodyEl, 'height');
  28644. // }
  28645. var size = this.mesureSize();
  28646. popBodyEl.style.width = size.width + "px";
  28647. popBodyEl.style.height = size.height + "px";
  28648. return size;
  28649. },
  28650. safeSetOffset: function(offset) {
  28651. var me = this;
  28652. var el = me.getDom();
  28653. var vpRect = uiUtils.getViewportRect();
  28654. var rect = uiUtils.getClientRect(el);
  28655. var left = offset.left;
  28656. if (left + rect.width > vpRect.right) {
  28657. left = vpRect.right - rect.width;
  28658. }
  28659. var top = offset.top;
  28660. if (top + rect.height > vpRect.bottom) {
  28661. top = vpRect.bottom - rect.height;
  28662. }
  28663. el.style.left = Math.max(left, 0) + "px";
  28664. el.style.top = Math.max(top, 0) + "px";
  28665. },
  28666. showAtCenter: function() {
  28667. var vpRect = uiUtils.getViewportRect();
  28668. if (!this.fullscreen) {
  28669. this.getDom().style.display = "";
  28670. var popSize = this.fitSize();
  28671. var titleHeight = this.getDom("titlebar").offsetHeight | 0;
  28672. var left = vpRect.width / 2 - popSize.width / 2;
  28673. var top =
  28674. vpRect.height / 2 - (popSize.height - titleHeight) / 2 - titleHeight;
  28675. var popEl = this.getDom();
  28676. this.safeSetOffset({
  28677. left: Math.max(left | 0, 0),
  28678. top: Math.max(top | 0, 0)
  28679. });
  28680. if (!domUtils.hasClass(popEl, "edui-state-centered")) {
  28681. popEl.className += " edui-state-centered";
  28682. }
  28683. } else {
  28684. var dialogWrapNode = this.getDom(),
  28685. contentNode = this.getDom("content");
  28686. dialogWrapNode.style.display = "block";
  28687. var wrapRect = UE.ui.uiUtils.getClientRect(dialogWrapNode),
  28688. contentRect = UE.ui.uiUtils.getClientRect(contentNode);
  28689. dialogWrapNode.style.left = "-100000px";
  28690. contentNode.style.width =
  28691. vpRect.width - wrapRect.width + contentRect.width + "px";
  28692. contentNode.style.height =
  28693. vpRect.height - wrapRect.height + contentRect.height + "px";
  28694. dialogWrapNode.style.width = vpRect.width + "px";
  28695. dialogWrapNode.style.height = vpRect.height + "px";
  28696. dialogWrapNode.style.left = 0;
  28697. //保存环境的overflow值
  28698. this._originalContext = {
  28699. html: {
  28700. overflowX: document.documentElement.style.overflowX,
  28701. overflowY: document.documentElement.style.overflowY
  28702. },
  28703. body: {
  28704. overflowX: document.body.style.overflowX,
  28705. overflowY: document.body.style.overflowY
  28706. }
  28707. };
  28708. document.documentElement.style.overflowX = "hidden";
  28709. document.documentElement.style.overflowY = "hidden";
  28710. document.body.style.overflowX = "hidden";
  28711. document.body.style.overflowY = "hidden";
  28712. }
  28713. this._show();
  28714. },
  28715. getContentHtml: function() {
  28716. var contentHtml = "";
  28717. if (typeof this.content == "string") {
  28718. contentHtml = this.content;
  28719. } else if (this.iframeUrl) {
  28720. contentHtml =
  28721. '<span id="' +
  28722. this.id +
  28723. '_contmask" class="dialogcontmask"></span><iframe id="' +
  28724. this.id +
  28725. '_iframe" class="%%-iframe" height="100%" width="100%" frameborder="0" src="' +
  28726. this.iframeUrl +
  28727. '"></iframe>';
  28728. }
  28729. return contentHtml;
  28730. },
  28731. getHtmlTpl: function() {
  28732. var footHtml = "";
  28733. if (this.buttons) {
  28734. var buff = [];
  28735. for (var i = 0; i < this.buttons.length; i++) {
  28736. buff[i] = this.buttons[i].renderHtml();
  28737. }
  28738. footHtml =
  28739. '<div class="%%-foot">' +
  28740. '<div id="##_buttons" class="%%-buttons">' +
  28741. buff.join("") +
  28742. "</div>" +
  28743. "</div>";
  28744. }
  28745. return (
  28746. '<div id="##" class="%%"><div ' +
  28747. (!this.fullscreen
  28748. ? 'class="%%"'
  28749. : 'class="%%-wrap edui-dialog-fullscreen-flag"') +
  28750. '><div id="##_body" class="%%-body">' +
  28751. '<div class="%%-shadow"></div>' +
  28752. '<div id="##_titlebar" class="%%-titlebar">' +
  28753. '<div class="%%-draghandle" onmousedown="$$._onTitlebarMouseDown(event, this);">' +
  28754. '<span class="%%-caption">' +
  28755. (this.title || "") +
  28756. "</span>" +
  28757. "</div>" +
  28758. this.closeButton.renderHtml() +
  28759. "</div>" +
  28760. '<div id="##_content" class="%%-content">' +
  28761. (this.autoReset ? "" : this.getContentHtml()) +
  28762. "</div>" +
  28763. footHtml +
  28764. "</div></div></div>"
  28765. );
  28766. },
  28767. postRender: function() {
  28768. // todo: 保持居中/记住上次关闭位置选项
  28769. if (!this.modalMask.getDom()) {
  28770. this.modalMask.render();
  28771. this.modalMask.hide();
  28772. }
  28773. if (!this.dragMask.getDom()) {
  28774. this.dragMask.render();
  28775. this.dragMask.hide();
  28776. }
  28777. var me = this;
  28778. this.addListener("show", function() {
  28779. me.modalMask.show(this.getDom().style.zIndex - 2);
  28780. });
  28781. this.addListener("hide", function() {
  28782. me.modalMask.hide();
  28783. });
  28784. if (this.buttons) {
  28785. for (var i = 0; i < this.buttons.length; i++) {
  28786. this.buttons[i].postRender();
  28787. }
  28788. }
  28789. domUtils.on(window, "resize", function() {
  28790. setTimeout(function() {
  28791. if (!me.isHidden()) {
  28792. me.safeSetOffset(uiUtils.getClientRect(me.getDom()));
  28793. }
  28794. });
  28795. });
  28796. //hold住scroll事件,防止dialog的滚动影响页面
  28797. // if( this.holdScroll ) {
  28798. //
  28799. // if( !me.iframeUrl ) {
  28800. // domUtils.on( document.getElementById( me.id + "_iframe"), !browser.gecko ? "mousewheel" : "DOMMouseScroll", function(e){
  28801. // domUtils.preventDefault(e);
  28802. // } );
  28803. // } else {
  28804. // me.addListener('dialogafterreset', function(){
  28805. // window.setTimeout(function(){
  28806. // var iframeWindow = document.getElementById( me.id + "_iframe").contentWindow;
  28807. //
  28808. // if( browser.ie ) {
  28809. //
  28810. // var timer = window.setInterval(function(){
  28811. //
  28812. // if( iframeWindow.document && iframeWindow.document.body ) {
  28813. // window.clearInterval( timer );
  28814. // timer = null;
  28815. // domUtils.on( iframeWindow.document.body, !browser.gecko ? "mousewheel" : "DOMMouseScroll", function(e){
  28816. // domUtils.preventDefault(e);
  28817. // } );
  28818. // }
  28819. //
  28820. // }, 100);
  28821. //
  28822. // } else {
  28823. // domUtils.on( iframeWindow, !browser.gecko ? "mousewheel" : "DOMMouseScroll", function(e){
  28824. // domUtils.preventDefault(e);
  28825. // } );
  28826. // }
  28827. //
  28828. // }, 1);
  28829. // });
  28830. // }
  28831. //
  28832. // }
  28833. this._hide();
  28834. },
  28835. mesureSize: function() {
  28836. var body = this.getDom("body");
  28837. var width = uiUtils.getClientRect(this.getDom("content")).width;
  28838. var dialogBodyStyle = body.style;
  28839. dialogBodyStyle.width = width;
  28840. return uiUtils.getClientRect(body);
  28841. },
  28842. _onTitlebarMouseDown: function(evt, el) {
  28843. if (this.draggable) {
  28844. var rect;
  28845. var vpRect = uiUtils.getViewportRect();
  28846. var me = this;
  28847. uiUtils.startDrag(evt, {
  28848. ondragstart: function() {
  28849. rect = uiUtils.getClientRect(me.getDom());
  28850. me.getDom("contmask").style.visibility = "visible";
  28851. me.dragMask.show(me.getDom().style.zIndex - 1);
  28852. },
  28853. ondragmove: function(x, y) {
  28854. var left = rect.left + x;
  28855. var top = rect.top + y;
  28856. me.safeSetOffset({
  28857. left: left,
  28858. top: top
  28859. });
  28860. },
  28861. ondragstop: function() {
  28862. me.getDom("contmask").style.visibility = "hidden";
  28863. domUtils.removeClasses(me.getDom(), ["edui-state-centered"]);
  28864. me.dragMask.hide();
  28865. }
  28866. });
  28867. }
  28868. },
  28869. reset: function() {
  28870. this.getDom("content").innerHTML = this.getContentHtml();
  28871. this.fireEvent("dialogafterreset");
  28872. },
  28873. _show: function() {
  28874. if (this._hidden) {
  28875. this.getDom().style.display = "";
  28876. //要高过编辑器的zindxe
  28877. this.editor.container.style.zIndex &&
  28878. (this.getDom().style.zIndex =
  28879. this.editor.container.style.zIndex * 1 + 10);
  28880. this._hidden = false;
  28881. this.fireEvent("show");
  28882. baidu.editor.ui.uiUtils.getFixedLayer().style.zIndex =
  28883. this.getDom().style.zIndex - 4;
  28884. }
  28885. },
  28886. isHidden: function() {
  28887. return this._hidden;
  28888. },
  28889. _hide: function() {
  28890. if (!this._hidden) {
  28891. var wrapNode = this.getDom();
  28892. wrapNode.style.display = "none";
  28893. wrapNode.style.zIndex = "";
  28894. wrapNode.style.width = "";
  28895. wrapNode.style.height = "";
  28896. this._hidden = true;
  28897. this.fireEvent("hide");
  28898. }
  28899. },
  28900. open: function() {
  28901. if (this.autoReset) {
  28902. //有可能还没有渲染
  28903. try {
  28904. this.reset();
  28905. } catch (e) {
  28906. this.render();
  28907. this.open();
  28908. }
  28909. }
  28910. this.showAtCenter();
  28911. if (this.iframeUrl) {
  28912. try {
  28913. this.getDom("iframe").focus();
  28914. } catch (ex) {}
  28915. }
  28916. activeDialog = this;
  28917. },
  28918. _onCloseButtonClick: function(evt, el) {
  28919. this.close(false);
  28920. },
  28921. close: function(ok) {
  28922. if (this.fireEvent("close", ok) !== false) {
  28923. //还原环境
  28924. if (this.fullscreen) {
  28925. document.documentElement.style.overflowX = this._originalContext.html.overflowX;
  28926. document.documentElement.style.overflowY = this._originalContext.html.overflowY;
  28927. document.body.style.overflowX = this._originalContext.body.overflowX;
  28928. document.body.style.overflowY = this._originalContext.body.overflowY;
  28929. delete this._originalContext;
  28930. }
  28931. this._hide();
  28932. //销毁content
  28933. var content = this.getDom("content");
  28934. var iframe = this.getDom("iframe");
  28935. if (content && iframe) {
  28936. var doc = iframe.contentDocument || iframe.contentWindow.document;
  28937. doc && (doc.body.innerHTML = "");
  28938. domUtils.remove(content);
  28939. }
  28940. }
  28941. }
  28942. };
  28943. utils.inherits(Dialog, UIBase);
  28944. })();
  28945. // ui/menubutton.js
  28946. ///import core
  28947. ///import uicore
  28948. ///import ui/menu.js
  28949. ///import ui/splitbutton.js
  28950. ;(function() {
  28951. var utils = baidu.editor.utils,
  28952. Menu = baidu.editor.ui.Menu,
  28953. SplitButton = baidu.editor.ui.SplitButton,
  28954. MenuButton = (baidu.editor.ui.MenuButton = function(options) {
  28955. this.initOptions(options);
  28956. this.initMenuButton();
  28957. });
  28958. MenuButton.prototype = {
  28959. initMenuButton: function() {
  28960. var me = this;
  28961. this.uiName = "menubutton";
  28962. this.popup = new Menu({
  28963. items: me.items,
  28964. className: me.className,
  28965. editor: me.editor
  28966. });
  28967. this.popup.addListener("show", function() {
  28968. var list = this;
  28969. for (var i = 0; i < list.items.length; i++) {
  28970. list.items[i].removeState("checked");
  28971. if (list.items[i].value == me._value) {
  28972. list.items[i].addState("checked");
  28973. this.value = me._value;
  28974. }
  28975. }
  28976. });
  28977. this.initSplitButton();
  28978. },
  28979. setValue: function(value) {
  28980. this._value = value;
  28981. }
  28982. };
  28983. utils.inherits(MenuButton, SplitButton);
  28984. })();
  28985. // ui/multiMenu.js
  28986. ///import core
  28987. ///import uicore
  28988. ///commands 表情
  28989. ;(function() {
  28990. var utils = baidu.editor.utils,
  28991. Popup = baidu.editor.ui.Popup,
  28992. SplitButton = baidu.editor.ui.SplitButton,
  28993. MultiMenuPop = (baidu.editor.ui.MultiMenuPop = function(options) {
  28994. this.initOptions(options);
  28995. this.initMultiMenu();
  28996. });
  28997. MultiMenuPop.prototype = {
  28998. initMultiMenu: function() {
  28999. var me = this;
  29000. this.popup = new Popup({
  29001. content: "",
  29002. editor: me.editor,
  29003. iframe_rendered: false,
  29004. onshow: function() {
  29005. if (!this.iframe_rendered) {
  29006. this.iframe_rendered = true;
  29007. this.getDom("content").innerHTML =
  29008. '<iframe id="' +
  29009. me.id +
  29010. '_iframe" src="' +
  29011. me.iframeUrl +
  29012. '" frameborder="0"></iframe>';
  29013. me.editor.container.style.zIndex &&
  29014. (this.getDom().style.zIndex =
  29015. me.editor.container.style.zIndex * 1 + 1);
  29016. }
  29017. }
  29018. // canSideUp:false,
  29019. // canSideLeft:false
  29020. });
  29021. this.onbuttonclick = function() {
  29022. this.showPopup();
  29023. };
  29024. this.initSplitButton();
  29025. }
  29026. };
  29027. utils.inherits(MultiMenuPop, SplitButton);
  29028. })();
  29029. // ui/shortcutmenu.js
  29030. ;(function() {
  29031. var UI = baidu.editor.ui,
  29032. UIBase = UI.UIBase,
  29033. uiUtils = UI.uiUtils,
  29034. utils = baidu.editor.utils,
  29035. domUtils = baidu.editor.dom.domUtils;
  29036. var allMenus = [], //存储所有快捷菜单
  29037. timeID,
  29038. isSubMenuShow = false; //是否有子pop显示
  29039. var ShortCutMenu = (UI.ShortCutMenu = function(options) {
  29040. this.initOptions(options);
  29041. this.initShortCutMenu();
  29042. });
  29043. ShortCutMenu.postHide = hideAllMenu;
  29044. ShortCutMenu.prototype = {
  29045. isHidden: true,
  29046. SPACE: 5,
  29047. initShortCutMenu: function() {
  29048. this.items = this.items || [];
  29049. this.initUIBase();
  29050. this.initItems();
  29051. this.initEvent();
  29052. allMenus.push(this);
  29053. },
  29054. initEvent: function() {
  29055. var me = this,
  29056. doc = me.editor.document;
  29057. domUtils.on(doc, "mousemove", function(e) {
  29058. if (me.isHidden === false) {
  29059. //有pop显示就不隐藏快捷菜单
  29060. if (me.getSubMenuMark() || me.eventType == "contextmenu") return;
  29061. var flag = true,
  29062. el = me.getDom(),
  29063. wt = el.offsetWidth,
  29064. ht = el.offsetHeight,
  29065. distanceX = wt / 2 + me.SPACE, //距离中心X标准
  29066. distanceY = ht / 2, //距离中心Y标准
  29067. x = Math.abs(e.screenX - me.left), //离中心距离横坐标
  29068. y = Math.abs(e.screenY - me.top); //离中心距离纵坐标
  29069. clearTimeout(timeID);
  29070. timeID = setTimeout(function() {
  29071. if (y > 0 && y < distanceY) {
  29072. me.setOpacity(el, "1");
  29073. } else if (y > distanceY && y < distanceY + 70) {
  29074. me.setOpacity(el, "0.5");
  29075. flag = false;
  29076. } else if (y > distanceY + 70 && y < distanceY + 140) {
  29077. me.hide();
  29078. }
  29079. if (flag && x > 0 && x < distanceX) {
  29080. me.setOpacity(el, "1");
  29081. } else if (x > distanceX && x < distanceX + 70) {
  29082. me.setOpacity(el, "0.5");
  29083. } else if (x > distanceX + 70 && x < distanceX + 140) {
  29084. me.hide();
  29085. }
  29086. });
  29087. }
  29088. });
  29089. //ie\ff下 mouseout不准
  29090. if (browser.chrome) {
  29091. domUtils.on(doc, "mouseout", function(e) {
  29092. var relatedTgt = e.relatedTarget || e.toElement;
  29093. if (relatedTgt == null || relatedTgt.tagName == "HTML") {
  29094. me.hide();
  29095. }
  29096. });
  29097. }
  29098. me.editor.addListener("afterhidepop", function() {
  29099. if (!me.isHidden) {
  29100. isSubMenuShow = true;
  29101. }
  29102. });
  29103. },
  29104. initItems: function() {
  29105. if (utils.isArray(this.items)) {
  29106. for (var i = 0, len = this.items.length; i < len; i++) {
  29107. var item = this.items[i].toLowerCase();
  29108. if (UI[item]) {
  29109. this.items[i] = new UI[item](this.editor);
  29110. this.items[i].className += " edui-shortcutsubmenu ";
  29111. }
  29112. }
  29113. }
  29114. },
  29115. setOpacity: function(el, value) {
  29116. if (browser.ie && browser.version < 9) {
  29117. el.style.filter = "alpha(opacity = " + parseFloat(value) * 100 + ");";
  29118. } else {
  29119. el.style.opacity = value;
  29120. }
  29121. },
  29122. getSubMenuMark: function() {
  29123. isSubMenuShow = false;
  29124. var layerEle = uiUtils.getFixedLayer();
  29125. var list = domUtils.getElementsByTagName(layerEle, "div", function(node) {
  29126. return domUtils.hasClass(node, "edui-shortcutsubmenu edui-popup");
  29127. });
  29128. for (var i = 0, node; (node = list[i++]); ) {
  29129. if (node.style.display != "none") {
  29130. isSubMenuShow = true;
  29131. }
  29132. }
  29133. return isSubMenuShow;
  29134. },
  29135. show: function(e, hasContextmenu) {
  29136. var me = this,
  29137. offset = {},
  29138. el = this.getDom(),
  29139. fixedlayer = uiUtils.getFixedLayer();
  29140. function setPos(offset) {
  29141. if (offset.left < 0) {
  29142. offset.left = 0;
  29143. }
  29144. if (offset.top < 0) {
  29145. offset.top = 0;
  29146. }
  29147. el.style.cssText =
  29148. "position:absolute;left:" +
  29149. offset.left +
  29150. "px;top:" +
  29151. offset.top +
  29152. "px;";
  29153. }
  29154. function setPosByCxtMenu(menu) {
  29155. if (!menu.tagName) {
  29156. menu = menu.getDom();
  29157. }
  29158. offset.left = parseInt(menu.style.left);
  29159. offset.top = parseInt(menu.style.top);
  29160. offset.top -= el.offsetHeight + 15;
  29161. setPos(offset);
  29162. }
  29163. me.eventType = e.type;
  29164. el.style.cssText = "display:block;left:-9999px";
  29165. if (e.type == "contextmenu" && hasContextmenu) {
  29166. var menu = domUtils.getElementsByTagName(
  29167. fixedlayer,
  29168. "div",
  29169. "edui-contextmenu"
  29170. )[0];
  29171. if (menu) {
  29172. setPosByCxtMenu(menu);
  29173. } else {
  29174. me.editor.addListener("aftershowcontextmenu", function(type, menu) {
  29175. setPosByCxtMenu(menu);
  29176. });
  29177. }
  29178. } else {
  29179. offset = uiUtils.getViewportOffsetByEvent(e);
  29180. offset.top -= el.offsetHeight + me.SPACE;
  29181. offset.left += me.SPACE + 20;
  29182. setPos(offset);
  29183. me.setOpacity(el, 0.2);
  29184. }
  29185. me.isHidden = false;
  29186. me.left = e.screenX + el.offsetWidth / 2 - me.SPACE;
  29187. me.top = e.screenY - el.offsetHeight / 2 - me.SPACE;
  29188. if (me.editor) {
  29189. el.style.zIndex = me.editor.container.style.zIndex * 1 + 10;
  29190. fixedlayer.style.zIndex = el.style.zIndex - 1;
  29191. }
  29192. },
  29193. hide: function() {
  29194. if (this.getDom()) {
  29195. this.getDom().style.display = "none";
  29196. }
  29197. this.isHidden = true;
  29198. },
  29199. postRender: function() {
  29200. if (utils.isArray(this.items)) {
  29201. for (var i = 0, item; (item = this.items[i++]); ) {
  29202. item.postRender();
  29203. }
  29204. }
  29205. },
  29206. getHtmlTpl: function() {
  29207. var buff;
  29208. if (utils.isArray(this.items)) {
  29209. buff = [];
  29210. for (var i = 0; i < this.items.length; i++) {
  29211. buff[i] = this.items[i].renderHtml();
  29212. }
  29213. buff = buff.join("");
  29214. } else {
  29215. buff = this.items;
  29216. }
  29217. return (
  29218. '<div id="##" class="%% edui-toolbar" data-src="shortcutmenu" onmousedown="return false;" onselectstart="return false;" >' +
  29219. buff +
  29220. "</div>"
  29221. );
  29222. }
  29223. };
  29224. utils.inherits(ShortCutMenu, UIBase);
  29225. function hideAllMenu(e) {
  29226. var tgt = e.target || e.srcElement,
  29227. cur = domUtils.findParent(
  29228. tgt,
  29229. function(node) {
  29230. return (
  29231. domUtils.hasClass(node, "edui-shortcutmenu") ||
  29232. domUtils.hasClass(node, "edui-popup")
  29233. );
  29234. },
  29235. true
  29236. );
  29237. if (!cur) {
  29238. for (var i = 0, menu; (menu = allMenus[i++]); ) {
  29239. menu.hide();
  29240. }
  29241. }
  29242. }
  29243. domUtils.on(document, "mousedown", function(e) {
  29244. hideAllMenu(e);
  29245. });
  29246. domUtils.on(window, "scroll", function(e) {
  29247. hideAllMenu(e);
  29248. });
  29249. })();
  29250. // ui/breakline.js
  29251. ;(function() {
  29252. var utils = baidu.editor.utils,
  29253. UIBase = baidu.editor.ui.UIBase,
  29254. Breakline = (baidu.editor.ui.Breakline = function(options) {
  29255. this.initOptions(options);
  29256. this.initSeparator();
  29257. });
  29258. Breakline.prototype = {
  29259. uiName: "Breakline",
  29260. initSeparator: function() {
  29261. this.initUIBase();
  29262. },
  29263. getHtmlTpl: function() {
  29264. return "<br/>";
  29265. }
  29266. };
  29267. utils.inherits(Breakline, UIBase);
  29268. })();
  29269. // ui/message.js
  29270. ///import core
  29271. ///import uicore
  29272. ;(function() {
  29273. var utils = baidu.editor.utils,
  29274. domUtils = baidu.editor.dom.domUtils,
  29275. UIBase = baidu.editor.ui.UIBase,
  29276. Message = (baidu.editor.ui.Message = function(options) {
  29277. this.initOptions(options);
  29278. this.initMessage();
  29279. });
  29280. Message.prototype = {
  29281. initMessage: function() {
  29282. this.initUIBase();
  29283. },
  29284. getHtmlTpl: function() {
  29285. return (
  29286. '<div id="##" class="edui-message %%">' +
  29287. ' <div id="##_closer" class="edui-message-closer">×</div>' +
  29288. ' <div id="##_body" class="edui-message-body edui-message-type-info">' +
  29289. ' <iframe style="position:absolute;z-index:-1;left:0;top:0;background-color: transparent;" frameborder="0" width="100%" height="100%" src="about:blank"></iframe>' +
  29290. ' <div class="edui-shadow"></div>' +
  29291. ' <div id="##_content" class="edui-message-content">' +
  29292. " </div>" +
  29293. " </div>" +
  29294. "</div>"
  29295. );
  29296. },
  29297. reset: function(opt) {
  29298. var me = this;
  29299. if (!opt.keepshow) {
  29300. clearTimeout(this.timer);
  29301. me.timer = setTimeout(function() {
  29302. me.hide();
  29303. }, opt.timeout || 4000);
  29304. }
  29305. opt.content !== undefined && me.setContent(opt.content);
  29306. opt.type !== undefined && me.setType(opt.type);
  29307. me.show();
  29308. },
  29309. postRender: function() {
  29310. var me = this,
  29311. closer = this.getDom("closer");
  29312. closer &&
  29313. domUtils.on(closer, "click", function() {
  29314. me.hide();
  29315. });
  29316. },
  29317. setContent: function(content) {
  29318. this.getDom("content").innerHTML = content;
  29319. },
  29320. setType: function(type) {
  29321. type = type || "info";
  29322. var body = this.getDom("body");
  29323. body.className = body.className.replace(
  29324. /edui-message-type-[\w-]+/,
  29325. "edui-message-type-" + type
  29326. );
  29327. },
  29328. getContent: function() {
  29329. return this.getDom("content").innerHTML;
  29330. },
  29331. getType: function() {
  29332. var arr = this.getDom("body").match(/edui-message-type-([\w-]+)/);
  29333. return arr ? arr[1] : "";
  29334. },
  29335. show: function() {
  29336. this.getDom().style.display = "block";
  29337. },
  29338. hide: function() {
  29339. var dom = this.getDom();
  29340. if (dom) {
  29341. dom.style.display = "none";
  29342. dom.parentNode && dom.parentNode.removeChild(dom);
  29343. }
  29344. }
  29345. };
  29346. utils.inherits(Message, UIBase);
  29347. })();
  29348. // ui/iconfont.js
  29349. !function(o){var h,p='<svg><symbol id="edui-for-close" viewBox="0 0 1024 1024"><path d="M960 153.6L870.4 64 512 422.4 153.6 64 64 153.6 422.4 512 64 870.4 153.6 960 512 601.6l358.4 358.4 89.6-89.6L601.6 512 960 153.6z" fill="#666666" ></path></symbol><symbol id="edui-for-searchreplace" viewBox="0 0 1024 1024"><path d="M437.771654 578.9811h82.93098L299.553354 0H219.181972L0.080371 578.9811h80.883302L136.762912 419.774095h241.626065zM160.823135 354.248383l87.026337-241.114145A222.173119 222.173119 0 0 0 256.040186 72.692587a274.388921 274.388921 0 0 0 9.214553 40.441651l90.097855 241.114145h-194.529459z m825.214441 403.904587a146.920933 146.920933 0 0 0-94.705131-44.537008 145.897094 145.897094 0 0 0 74.740266-51.191963 138.730219 138.730219 0 0 0 27.13174-84.466738 117.741515 117.741515 0 0 0-45.560847-96.75281 189.922182 189.922182 0 0 0-122.348791-36.346294h-170.469237V1023.839257h175.076513a204.767851 204.767851 0 0 0 137.70638-46.072766 153.575889 153.575889 0 0 0 53.751561-121.324952 136.170621 136.170621 0 0 0-35.322454-98.288569z m-255.959814-250.840618h74.740266q109.550801 0 109.5508 81.907141a91.121694 91.121694 0 0 1-30.715178 73.204506 126.956068 126.956068 0 0 1-84.978658 26.619821h-68.59723V507.312352z m180.707629 421.821774a136.682541 136.682541 0 0 1-90.609775 27.13174h-90.097854v-204.767851h77.299864q135.146782 0 135.146782 99.824327a93.681292 93.681292 0 0 1-31.739017 78.323704zM460.808037 801.666138a176.100352 176.100352 0 0 1-85.490578-40.95357 178.148031 178.148031 0 0 1-38.905892-219.613521L282.148087 511.919629A241.114145 241.114145 0 0 0 460.808037 866.679931v42.489329l112.110399-77.811783L460.808037 753.033774v51.191963z" fill="#666666" ></path></symbol><symbol id="edui-for-italic" viewBox="0 0 1024 1024"><path d="M384 64v64h128L384 896H256v64h384v-64H512l128-768h128V64z" fill="#666666" ></path></symbol><symbol id="edui-for-insertcaption" viewBox="0 0 1024 1024"><path d="M568.25 62v393.75h393.75V62z m337.5 225h-112.5v112.5h-56.25V287h-112.5V230.75h112.5V118.25h56.25v112.5h112.5z" fill="#1C7C59" ></path><path d="M938.375 455.75H62v506.25h900V455.75zM114.875 905.75v-225H343.25v225z m423.5625 0H399.5v-225h225v225z m370.6875 0H680.75v-225h228.375zM455.75 62H62v56.25h168.75v337.5h56.25V118.25h168.75V62z" fill="#666666" ></path></symbol><symbol id="edui-for-insertparagraph" viewBox="0 0 1024 1024"><path d="M997.12 0H0v576h1024V0zM60.16 512V256H320v256z m481.92 0H384V256h256v256z m421.76 0H704V256h259.84zM448 576H0v64h192v384h64v-384h192V576z" fill="#666666" ></path></symbol><symbol id="edui-for-inserttitlecol" viewBox="0 0 1024 1024"><path d="M64 960v-128H0v192h192v-64H64zM448 1024h576V0H448z m512-320v256h-192v-256z m-256 0v256H512v-256z m256-320v256h-192V384z m-256 0v256H512V384z m256-320v256h-192V64z m-256 0v256H512V64zM64 512h128V448H0v192h64V512zM384 512v128h64V448H256v64h128zM384 960H256v64h192v-192H384v128z" fill="#666666" ></path><path d="M64 960v-128H0v192h192v-64H64zM448 1024h576V0H448z m512-320v256h-192v-256z m-256 0v256H512v-256z m256-320v256h-192V384z m-256 0v256H512V384z m256-320v256h-192V64z m-256 0v256H512V64zM64 512h128V448H0v192h64V512zM384 512v128h64V448H256v64h128zM384 960H256v64h192v-192H384v128z" fill="#666666" ></path><path d="M0 448h448V0H0z m256-384v128h128v64H256v128H192V256H64V192h128V64z" fill="#1C7C59" ></path></symbol><symbol id="edui-for-insertimage" viewBox="0 0 1024 1024"><path d="M350.08 535.04l128 192 263.68-430.08 156.16 256V576h64V117.12a53.12 53.12 0 0 0-55.04-53.12H53.12a53.12 53.12 0 0 0-53.12 53.12v727.04a51.84 51.84 0 0 0 51.84 51.84H640v-64H154.88z m-53.12-350.72a119.04 119.04 0 1 1-118.4 118.4 119.04 119.04 0 0 1 118.4-118.4z" fill="#666666" ></path><path d="M1024 704h-192V512h-64v192H576v64h192v192h64v-192h192v-64z" fill="#666666" ></path></symbol><symbol id="edui-for-previousstep" viewBox="0 0 1024 1024"><path d="M483.84 896a53.76 53.76 0 0 1-24.96-6.4h-3.84L87.04 556.8A55.04 55.04 0 0 1 64 517.76a56.96 56.96 0 0 1 22.4-48.64l371.2-328.32a46.08 46.08 0 0 1 30.72-12.8 40.96 40.96 0 0 1 35.84 21.12 60.16 60.16 0 0 1 7.04 28.16v192h29.44a400 400 0 0 1 97.28 12.16 363.52 363.52 0 0 1 120.32 54.4A384 384 0 0 1 889.6 556.8 602.88 602.88 0 0 1 960 768a60.16 60.16 0 0 1-10.24 53.12 39.68 39.68 0 0 1-29.44 13.44 55.04 55.04 0 0 1-42.24-26.24 229.12 229.12 0 0 0-64-68.48 314.24 314.24 0 0 0-89.6-47.36 437.76 437.76 0 0 0-141.44-21.76h-48.64V832a68.48 68.48 0 0 1-12.8 51.2 43.52 43.52 0 0 1-37.76 12.8zM145.28 512l312.96 281.6v-148.48a64 64 0 0 1 68.48-48h53.12a507.52 507.52 0 0 1 167.68 26.88 384 384 0 0 1 110.72 60.16l9.6 7.68a354.56 354.56 0 0 0-128-197.76 312.32 312.32 0 0 0-176-53.12 240 240 0 0 0-33.92 0h-12.8a56.96 56.96 0 0 1-49.28-24.96 55.04 55.04 0 0 1-8.96-26.24V234.88z" fill="#666666" ></path></symbol><symbol id="edui-for-nextstep" viewBox="0 0 1024 1024"><path d="M506.88 880.64a68.48 68.48 0 0 1-12.8-51.2v-160h-48.64a437.76 437.76 0 0 0-141.44 21.76 314.24 314.24 0 0 0-89.6 47.36 229.12 229.12 0 0 0-64 68.48 55.04 55.04 0 0 1-42.24 26.24 39.68 39.68 0 0 1-29.44-13.44A60.16 60.16 0 0 1 64 768a602.88 602.88 0 0 1 70.4-211.2 384 384 0 0 1 111.36-124.16 363.52 363.52 0 0 1 120.32-54.4 400 400 0 0 1 97.28-12.16h29.44v-192a60.16 60.16 0 0 1 7.04-28.16 40.96 40.96 0 0 1 35.84-17.92 46.08 46.08 0 0 1 30.72 12.8l370.56 328.32a56.96 56.96 0 0 1 22.4 48.64 55.04 55.04 0 0 1-22.4 39.68l-368 330.24h-3.84a53.76 53.76 0 0 1-24.96 6.4 43.52 43.52 0 0 1-33.28-13.44z m58.24-645.76v154.24a55.04 55.04 0 0 1-8.96 26.24 56.96 56.96 0 0 1-49.28 24.96h-9.6a240 240 0 0 0-33.92 0 312.32 312.32 0 0 0-176 53.12 354.56 354.56 0 0 0-128 197.76l9.6-7.68a384 384 0 0 1 110.72-60.16 507.52 507.52 0 0 1 163.84-28.16h53.12a64 64 0 0 1 68.48 48v150.4l313.6-281.6z" fill="#666666" ></path></symbol><symbol id="edui-for-scaleboard" viewBox="0 0 1024 1024"><path d="M374.935252 651.624033a35.190169 35.190169 0 0 0-26.872492-11.516783H39.029096a40.308739 40.308739 0 0 0-39.029096 39.668918V704.089375a41.588381 41.588381 0 0 0 43.507845 37.749454h163.154419L19.834459 932.505561a53.105164 53.105164 0 0 0 0 74.859087 51.825521 51.825521 0 0 0 73.579443 0l186.827805-188.107448v165.073883a37.749454 37.749454 0 0 0 37.109633 39.029096h26.872492a36.469811 36.469811 0 0 0 39.668918-33.910526v-309.673485a36.469811 36.469811 0 0 0-8.957498-26.872493zM383.89275 325.955016V34.196526A35.82999 35.82999 0 0 0 343.584011 0.286h-28.152135a37.109632 37.109632 0 0 0-37.109632 39.029096v166.353525L94.053724 21.400101a51.1857 51.1857 0 0 0-72.939623 0 52.465342 52.465342 0 0 0 0 73.579444l184.26852 184.26852H43.507845A42.228202 42.228202 0 0 0 0 320.196625v26.872493A40.308739 40.308739 0 0 0 38.389275 384.17875h310.313306a35.190169 35.190169 0 0 0 26.232671-10.876961A35.82999 35.82999 0 0 0 383.89275 345.789475v-19.194637zM648.778747 372.661968a35.190169 35.190169 0 0 0 26.872493 10.876961H984.684904a40.308739 40.308739 0 0 0 39.029096-39.029096V320.196625a41.588381 41.588381 0 0 0-43.507845-37.749454h-163.154419l186.827805-187.467626a53.105164 53.105164 0 0 0 0-74.859086 51.825521 51.825521 0 0 0-73.579444 0L743.472292 205.0288V39.954918a37.749454 37.749454 0 0 0-36.469811-39.668918h-26.872492a36.469811 36.469811 0 0 0-40.308739 34.550348v309.673485a36.469811 36.469811 0 0 0 8.957497 26.872492zM639.82125 698.330984v291.118669a35.82999 35.82999 0 0 0 38.389275 33.910526h28.152135a37.109632 37.109632 0 0 0 37.109632-39.029096v-166.353525l185.548163 184.26852a51.1857 51.1857 0 0 0 72.939622 0 52.465342 52.465342 0 0 0 0-73.579444l-183.628698-183.628699h161.874776A42.228202 42.228202 0 0 0 1023.714 704.089375v-26.872492a40.308739 40.308739 0 0 0-38.389275-39.029097h-309.673485a35.190169 35.190169 0 0 0-26.232671 10.876962 35.82999 35.82999 0 0 0-8.957498 26.872492v19.194638z" fill="#666666" ></path></symbol><symbol id="edui-for-brush" viewBox="0 0 1024 1024"><path d="M986.878764 284.789854L739.847564 35.198746a122.875623 122.875623 0 0 0-172.153867 0L92.830614 511.981761a87.676877 87.676877 0 0 0-32.638837 56.317993L0.03392 915.807374a119.675737 119.675737 0 0 0 28.158997 79.99715 94.076649 94.076649 0 0 0 69.757515 28.158997h14.079498l344.307734-63.99772a86.396922 86.396922 0 0 0 55.678017-30.078928l474.863083-475.50306a115.195896 115.195896 0 0 0 0-169.593959zM448.017961 868.449062l-348.787575 63.99772 60.797834-348.147598 347.50762-351.347483 288.629718 287.349763z m474.863083-479.982901l-63.997721 70.397492-291.189626-286.709786 63.99772-63.99772a34.558769 34.558769 0 0 1 41.598518 0l246.391223 249.591108a35.838723 35.838723 0 0 1 9.599658 18.559339c1.919932 2.559909-3.199886 7.679726-7.679727 12.159567z" fill="#666666" ></path></symbol><symbol id="edui-for-background" viewBox="0 0 1024 1024"><path d="M988.16 448H419.84a35.84 35.84 0 0 0-35.84 35.84v504.32a35.84 35.84 0 0 0 35.84 35.84h568.96a35.84 35.84 0 0 0 35.84-35.84V483.84a35.84 35.84 0 0 0-36.48-35.84z m-323.84 164.48a80 80 0 1 1-80-81.92 81.28 81.28 0 0 1 80 81.92zM929.28 960H461.44l131.2-205.44 85.12 133.12 177.28-298.24L960 768v163.2a30.72 30.72 0 0 1-30.72 28.8z" fill="#666666" ></path><path d="M320 832H224a32 32 0 0 0 0 64H320zM320 640H128a64 64 0 0 1-64-64V128a64 64 0 0 1 64-64h640a64 64 0 0 1 64 64v256h64V64a64 64 0 0 0-64-64H64a64 64 0 0 0-64 64v576a64 64 0 0 0 64 64h256z" fill="#666666" ></path></symbol><symbol id="edui-for-strikethrough" viewBox="0 0 1024 1024"><path d="M994.56 672a128 128 0 0 1-98.56 48.64c-74.24 0-122.88-57.6-128-150.4h236.8v-52.48H768c7.68-92.8 58.24-150.4 132.48-150.4a115.84 115.84 0 0 1 87.04 40.96l28.8-35.2A156.8 156.8 0 0 0 896 320c-100.48 0-176.64 74.24-186.88 197.76H608.64a96.64 96.64 0 0 0 44.16-83.84c0-76.16-59.52-105.6-146.56-105.6h-128v192H267.52l-64-192h-58.88l-64 192H22.4v52.48H64l-64 192h54.4l41.6-136.32h155.52l40.32 131.84h56.96l-64-192h95.36v192h135.68c95.36 0 161.28-41.6 161.28-128a103.04 103.04 0 0 0-19.84-64h52.48C719.36 694.4 794.24 768 896 768a163.84 163.84 0 0 0 128-64zM433.92 371.2h64c64 0 100.48 18.56 100.48 69.76S570.24 512 497.28 512h-64z m-261.76 0c14.08 49.92 26.88 96.64 42.88 145.28H128c17.28-47.36 31.36-93.44 44.16-144z m64 212.48h-128l4.48-14.72h120.96z m384 47.36c0 58.24-42.88 85.12-115.84 85.12h-70.4V570.24H588.8a64 64 0 0 1 35.2 61.44z" fill="#666666" ></path></symbol><symbol id="edui-for-spechars" viewBox="0 0 1024 1024"><path d="M954.24 1024l-158.72-160A434.56 434.56 0 0 1 512 965.76a421.12 421.12 0 0 1-283.52-101.76L69.76 1024 0 951.68l160.64-155.52A477.44 477.44 0 0 1 64 512a426.88 426.88 0 0 1 96.64-282.24L0 72.32 69.76 0l158.72 160A464 464 0 0 1 512 60.16a432 432 0 0 1 281.6 99.84L954.24 0 1024 72.32l-161.92 157.44A430.08 430.08 0 0 1 960 512a448 448 0 0 1-99.2 283.52L1024 951.68zM512 160a337.28 337.28 0 0 0-250.24 103.68A342.4 342.4 0 0 0 160.64 512a343.04 343.04 0 0 0 104.96 249.6 339.84 339.84 0 0 0 492.16 0A344.32 344.32 0 0 0 862.08 512a332.8 332.8 0 0 0-105.6-250.24A339.84 339.84 0 0 0 512 160z" fill="#666666" ></path></symbol><symbol id="edui-for-clearboard" viewBox="0 0 1024 1024"><path d="M704 128V0H320v128H0v64h64v832h896V192h64V128zM384 64h256v64H384zM320 960H128V384h192z m320 0H384V384h256z m256 0h-192V384h192z m0-640H128V192h768z" fill="#666666" ></path></symbol><symbol id="edui-for-bold" viewBox="0 0 1024 1024"><path d="M876.8 710.4c-6.4-51.2-25.6-102.4-57.6-140.8-32-38.4-83.2-70.4-128-76.8 44.8-12.8 76.8-38.4 102.4-76.8 32-38.4 38.4-83.2 38.4-134.4 0-57.6-25.6-121.6-70.4-166.4C710.4 76.8 640 64 576 64H192v896h384c76.8 6.4 140.8-12.8 211.2-51.2 57.6-44.8 96-121.6 89.6-198.4zM288 153.6h262.4c44.8 0 96 6.4 134.4 38.4 32 25.6 51.2 57.6 44.8 96 0 44.8-12.8 83.2-44.8 115.2-38.4 32-89.6 44.8-134.4 38.4H288V153.6zM768 704c0 51.2-25.6 102.4-70.4 134.4-44.8 25.6-89.6 38.4-140.8 38.4H288V544h275.2c51.2 0 102.4 6.4 147.2 38.4 44.8 25.6 64 76.8 57.6 121.6z" fill="#666666" ></path></symbol><symbol id="edui-for-fullscreen" viewBox="0 0 1024 1024"><path d="M960 0H64a64 64 0 0 0-64 64v704a64 64 0 0 0 64 64h320v128H288a32 32 0 0 0 0 64h448a32 32 0 0 0 0-64H640v-128h320a64 64 0 0 0 64-64V64a64 64 0 0 0-64-64zM576 960H448v-128h128z m384-256a64 64 0 0 1-64 64H128a64 64 0 0 1-64-64V128a64 64 0 0 1 64-64h768a64 64 0 0 1 64 64z" fill="#666666" ></path></symbol><symbol id="edui-for-formatmatch" viewBox="0 0 1024 1024"><path d="M128 448v448l108.8-300.8L396.8 896H896V448zM128 256h768v64H128zM384 128h256v128H384z" fill="#666666" ></path></symbol><symbol id="edui-for-underline" viewBox="0 0 1024 1024"><path d="M192 896h640v64H192zM704 64v384c0 102.4-83.2 192-192 192-102.4 0-192-83.2-192-192V64H192v384c0 179.2 147.2 320 320 320s320-147.2 320-320V64h-128z" fill="#666666" ></path></symbol><symbol id="edui-for-removeformat" viewBox="0 0 1024 1024"><path d="M682.88 64L0 768l170.88 192h398.08L1024 448zM528 832h-288L192 775.04l192-227.2 192 227.84z" fill="#666666" ></path></symbol><symbol id="edui-for-blockquote" viewBox="0 0 1024 1024"><path d="M401.92 894.272v-292.48H248.064c-7.36-187.392 65.92-344.96 219.648-472.448L401.856 61.888C218.88 189.44 127.36 384.384 127.36 646.72v247.552h274.56z m428.16 0v-292.48h-153.728c-7.36-187.392 65.92-344.96 219.648-472.448L830.08 61.888c-182.976 127.616-274.432 322.496-274.432 584.832v247.552h274.496z" fill="#666666" ></path></symbol><symbol id="edui-for-anchor" viewBox="0 0 1024 1024"><path d="M722.56 668.16l76.8 72.32A438.4 438.4 0 0 1 576 837.76V436.48a192 192 0 1 0-128 0v400a448 448 0 0 1-231.68-90.88l82.56-77.44L0 625.28l45.44 280.96L124.8 832a618.88 618.88 0 0 0 384 128 597.12 597.12 0 0 0 384-133.12l87.04 81.92 44.16-283.52zM384 256a128 128 0 1 1 128 128 128 128 0 0 1-128-128z" fill="#666666" ></path></symbol><symbol id="edui-for-help" viewBox="0 0 1024 1024"><path d="M512 0a512 512 0 1 0 512 512 512 512 0 0 0-512-512z m0 960a448 448 0 1 1 448-448 448 448 0 0 1-448 448z" fill="#666666" ></path><path d="M512 640H448v-27.52a151.68 151.68 0 0 1 75.52-117.76q64-47.36 64-90.24a64 64 0 0 0-64-57.6q-76.8 0-95.36 87.68L320 414.08A192 192 0 0 1 536.96 256q153.6 7.68 167.04 135.68a156.16 156.16 0 0 1-90.24 140.8A544 544 0 0 0 512 620.16zM448 704h128v128H448z" fill="#666666" ></path></symbol><symbol id="edui-for-horizontal" viewBox="0 0 1024 1024"><path d="M0 448h1024v128H0z" fill="#666666" ></path></symbol><symbol id="edui-for-simpleupload" viewBox="0 0 1024 1024"><path d="M128 832l160-320L448 832H128zM514.56 832l254.72-512L1024 832H514.56z" fill="#666666" ></path><path d="M960 64H64a64 64 0 0 0-64 64v768a64 64 0 0 0 64 64h896a64 64 0 0 0 64-64V128a64 64 0 0 0-64-64z m0 768a64 64 0 0 1-64 64H128a64 64 0 0 1-64-64V192a64 64 0 0 1 64-64h768a64 64 0 0 1 64 64z" fill="#666666" ></path></symbol><symbol id="edui-for-indent" viewBox="0 0 1024 1024"><path d="M896 416L768 320v384l128-96L1024 512zM32 128h960c19.2 0 32-12.8 32-32s-12.8-32-32-32H32c-19.2 0-32 12.8-32 32s12.8 32 32 32zM32 960h960c19.2 0 32-12.8 32-32s-12.8-32-32-32H32c-19.2 0-32 12.8-32 32s12.8 32 32 32zM64 448h512c32 0 64-25.6 64-64 0-32-25.6-64-64-64H64c-38.4 0-64 25.6-64 64s25.6 64 64 64zM64 704h512c32 0 64-25.6 64-64 0-32-25.6-64-64-64H64c-32 0-64 25.6-64 64s25.6 64 64 64z" fill="#666666" ></path></symbol><symbol id="edui-for-justifycenter" viewBox="0 0 1024 1024"><path d="M992 64H32C12.8 64 0 51.2 0 32S12.8 0 32 0h960c19.2 0 32 12.8 32 32s-12.8 32-32 32zM800 256h-576c-19.2 0-32-12.8-32-32s12.8-32 32-32h576c19.2 0 32 12.8 32 32s-12.8 32-32 32zM992 448H32C12.8 448 0 435.2 0 416S12.8 384 32 384h960c19.2 0 32 12.8 32 32s-12.8 32-32 32zM800 640h-576c-19.2 0-32-12.8-32-32s12.8-32 32-32h576c19.2 0 32 12.8 32 32s-12.8 32-32 32zM992 832H32c-19.2 0-32-12.8-32-32s12.8-32 32-32h960c19.2 0 32 12.8 32 32s-12.8 32-32 32zM800 1024h-576c-19.2 0-32-12.8-32-32s12.8-32 32-32h576c19.2 0 32 12.8 32 32s-12.8 32-32 32z" fill="#666666" ></path><path d="M992 448H32C12.8 448 0 435.2 0 416S12.8 384 32 384h960c19.2 0 32 12.8 32 32s-12.8 32-32 32zM800 640h-576c-19.2 0-32-12.8-32-32s12.8-32 32-32h576c19.2 0 32 12.8 32 32s-12.8 32-32 32z" fill="#666666" ></path></symbol><symbol id="edui-for-justifyleft" viewBox="0 0 1024 1024"><path d="M992 64H32C12.8 64 0 51.2 0 32S12.8 0 32 0h960c19.2 0 32 12.8 32 32s-12.8 32-32 32zM608 256h-576C12.8 256 0 243.2 0 224S12.8 192 32 192h576c19.2 0 32 12.8 32 32s-12.8 32-32 32zM992 448H32C12.8 448 0 435.2 0 416S12.8 384 32 384h960c19.2 0 32 12.8 32 32s-12.8 32-32 32zM992 832H32c-19.2 0-32-12.8-32-32s12.8-32 32-32h960c19.2 0 32 12.8 32 32s-12.8 32-32 32zM608 1024h-576c-19.2 0-32-12.8-32-32s12.8-32 32-32h576c19.2 0 32 12.8 32 32s-12.8 32-32 32z" fill="#666666" ></path><path d="M992 448H32C12.8 448 0 435.2 0 416S12.8 384 32 384h960c19.2 0 32 12.8 32 32s-12.8 32-32 32zM608 640h-576c-19.2 0-32-12.8-32-32S12.8 576 32 576h576c19.2 0 32 12.8 32 32s-12.8 32-32 32z" fill="#666666" ></path></symbol><symbol id="edui-for-justifyjustify" viewBox="0 0 1024 1024"><path d="M992 64H32C12.8 64 0 51.2 0 32S12.8 0 32 0h960c19.2 0 32 12.8 32 32s-12.8 32-32 32zM992 256H32C12.8 256 0 243.2 0 224S12.8 192 32 192h960c19.2 0 32 12.8 32 32s-12.8 32-32 32zM992 448H32C12.8 448 0 435.2 0 416S12.8 384 32 384h960c19.2 0 32 12.8 32 32s-12.8 32-32 32zM992 832H32c-19.2 0-32-12.8-32-32s12.8-32 32-32h960c19.2 0 32 12.8 32 32s-12.8 32-32 32zM992 1024H32c-19.2 0-32-12.8-32-32s12.8-32 32-32h960c19.2 0 32 12.8 32 32s-12.8 32-32 32z" fill="#666666" ></path><path d="M992 448H32C12.8 448 0 435.2 0 416S12.8 384 32 384h960c19.2 0 32 12.8 32 32s-12.8 32-32 32zM992 640H32c-19.2 0-32-12.8-32-32S12.8 576 32 576h960c19.2 0 32 12.8 32 32s-12.8 32-32 32z" fill="#666666" ></path></symbol><symbol id="edui-for-justifyright" viewBox="0 0 1024 1024"><path d="M992 64H32C12.8 64 0 51.2 0 32S12.8 0 32 0h960c19.2 0 32 12.8 32 32s-12.8 32-32 32zM992 256h-576c-19.2 0-32-12.8-32-32s12.8-32 32-32h576c19.2 0 32 12.8 32 32s-12.8 32-32 32zM992 448H32C12.8 448 0 435.2 0 416S12.8 384 32 384h960c19.2 0 32 12.8 32 32s-12.8 32-32 32zM992 832H32c-19.2 0-32-12.8-32-32s12.8-32 32-32h960c19.2 0 32 12.8 32 32s-12.8 32-32 32zM992 1024h-576c-19.2 0-32-12.8-32-32s12.8-32 32-32h576c19.2 0 32 12.8 32 32s-12.8 32-32 32z" fill="#666666" ></path><path d="M992 448H32C12.8 448 0 435.2 0 416S12.8 384 32 384h960c19.2 0 32 12.8 32 32s-12.8 32-32 32zM992 640h-576c-19.2 0-32-12.8-32-32s12.8-32 32-32h576c19.2 0 32 12.8 32 32s-12.8 32-32 32z" fill="#666666" ></path></symbol><symbol id="edui-for-link" viewBox="0 0 1024 1024"><path d="M759.04 768v-124.16a132.48 132.48 0 1 0 0-264.96H608.64A135.04 135.04 0 0 0 472.32 512h-128a261.12 261.12 0 0 1 264.32-256h150.4A261.12 261.12 0 0 1 1024 512a261.12 261.12 0 0 1-264.96 256z" fill="#666666" ></path><path d="M415.36 768H264.96A261.12 261.12 0 0 1 0 512a261.12 261.12 0 0 1 264.96-256v124.16a132.48 132.48 0 1 0 0 264.96h150.4A135.04 135.04 0 0 0 552.32 512h128a261.12 261.12 0 0 1-264.96 256z" fill="#666666" ></path></symbol><symbol id="edui-for-cleardoc" viewBox="0 0 1024 1024"><path d="M895.909541 256.060626h-191.95477V56.427664A63.984924 63.984924 0 0 0 639.969847 0.120932H137.688197A69.743567 69.743567 0 0 0 64.105535 64.105855v895.78893a69.743567 69.743567 0 0 0 73.582662 63.984923h748.623606A69.743567 69.743567 0 0 0 959.894465 959.894785V313.007208A63.984924 63.984924 0 0 0 895.909541 256.060626z m0 695.516119a8.31804 8.31804 0 0 1-8.31804 8.31804H137.688197a9.597739 9.597739 0 0 1-9.597738-9.597739V72.423895A8.31804 8.31804 0 0 1 136.408499 64.105855h491.404213a11.517286 11.517286 0 0 1 12.157135 10.877437v191.954771A60.145828 60.145828 0 0 0 703.954771 320.045549h180.437484a11.517286 11.517286 0 0 1 12.157136 10.877437v620.653759z" fill="#666666" ></path></symbol><symbol id="edui-for-drafts" viewBox="0 0 1024 1024"><path d="M832 320V160a32 32 0 0 0-32-32H576V64a64 64 0 0 0-64-64H384a64 64 0 0 0-64 64v64H96a32 32 0 0 0-32 32v640a32 32 0 0 0 32 32H384v192h448l192-192V320zM384 64h128v64H384zM192 192h512v64H192z m640 741.76V832h101.76zM960 768h-192v192H448V384h512z" fill="#666666" ></path></symbol><symbol id="edui-for-subscript" viewBox="0 0 1024 1024"><path d="M716.8 819.2v-29.696c0-99.328 160.256-135.68 160.256-179.2 0-16.896-10.752-27.136-32.768-27.136a116.736 116.736 0 0 0-74.24 35.84l-47.104-51.2A170.496 170.496 0 0 1 852.992 512c76.288 0 119.808 40.448 119.808 93.184 0 74.752-95.232 94.72-142.848 141.312H972.8V819.2zM72.192 720.384l494.592-494.592a56.832 56.832 0 0 1 78.848-8.704l7.68 7.68a56.832 56.832 0 0 1-8.704 78.848l-494.592 494.592a56.832 56.832 0 0 1-78.848 8.704l-7.68-7.68a56.832 56.832 0 0 1 8.704-78.848z" fill="#666666" ></path><path d="M566.784 798.208L72.192 303.616a56.832 56.832 0 0 1-8.704-78.848l7.68-7.68a56.832 56.832 0 0 1 78.848 8.704l494.592 494.592a56.832 56.832 0 0 1 8.704 78.848l-7.68 7.68a56.832 56.832 0 0 1-78.848-8.704z" fill="#666666" ></path></symbol><symbol id="edui-for-unlink" viewBox="0 0 1024 1024"><path d="M539.416837 448.012238V320.036713A95.341766 95.341766 0 0 0 639.877623 233.653234v-19.196329A95.341766 95.341766 0 0 0 539.416837 128.073426H228.436312A95.341766 95.341766 0 0 0 127.975525 214.456905v18.556451A95.341766 95.341766 0 0 0 228.436312 320.036713v127.975525A222.037535 222.037535 0 0 1 0 233.653234v-19.196329A222.037535 222.037535 0 0 1 228.436312 0.097901h310.980525A222.037535 222.037535 0 0 1 767.853148 214.456905v18.556451A222.037535 222.037535 0 0 1 539.416837 448.012238zM795.367886 1023.902099H484.387361A222.037535 222.037535 0 0 1 255.951049 809.543095v-18.556451A222.037535 222.037535 0 0 1 484.387361 575.987762v127.975525A95.341766 95.341766 0 0 0 383.926574 790.346766v18.556451A95.341766 95.341766 0 0 0 484.387361 895.926574h311.620403A95.341766 95.341766 0 0 0 895.828673 809.543095v-18.556451A95.341766 95.341766 0 0 0 795.367886 703.963287V575.987762A222.037535 222.037535 0 0 1 1023.804197 790.346766v18.556451A222.037535 222.037535 0 0 1 795.367886 1023.902099z" fill="#666666" ></path></symbol><symbol id="edui-for-superscript" viewBox="0 0 1024 1024"><path d="M716.8 512v-29.696c0-99.328 160.256-135.68 160.256-179.2 0-16.896-10.752-27.136-32.768-27.136a116.736 116.736 0 0 0-74.24 35.84l-47.104-51.2A170.496 170.496 0 0 1 852.992 204.8C929.28 204.8 972.8 245.248 972.8 297.984c0 74.752-95.232 94.72-142.848 141.312H972.8V512zM72.192 720.384l494.592-494.592a56.832 56.832 0 0 1 78.848-8.704l7.68 7.68a56.832 56.832 0 0 1-8.704 78.848l-494.592 494.592a56.832 56.832 0 0 1-78.848 8.704l-7.68-7.68a56.832 56.832 0 0 1 8.704-78.848z" fill="#666666" ></path><path d="M566.784 798.208L72.192 303.616a56.832 56.832 0 0 1-8.704-78.848l7.68-7.68a56.832 56.832 0 0 1 78.848 8.704l494.592 494.592a56.832 56.832 0 0 1 8.704 78.848l-7.68 7.68a56.832 56.832 0 0 1-78.848-8.704z" fill="#666666" ></path></symbol><symbol id="edui-for-forecolor" viewBox="0 0 1024 1024"><path d="M588.8 64H428.8L192 768h108.8l57.6-166.4h275.2l57.6 166.4H832L588.8 64zM390.4 499.2l102.4-313.6 102.4 313.6H390.4zM192 896h640v64H192z" fill="#666666" ></path></symbol><symbol id="edui-for-backcolor" viewBox="0 0 1024 1024"><path d="M910.593777 663.461622s-105.39199 190.467451-105.39199 246.972795a105.39199 105.39199 0 1 0 210.149088 0c0.634892-59.04491-104.757098-246.972795-104.757098-246.972795zM412.838838 100.947749L388.712961 126.978301 266.813792 0 169.675392 100.312858l121.899168 126.978301L0.15936 526.325057 412.838838 952.337256 825.518316 526.325057z m-274.27313 425.377308l275.542913-283.796502 274.908021 283.796502z" fill="#666666" ></path></symbol><symbol id="edui-for-touppercase" viewBox="0 0 1024 1024"><path d="M295.68 128L0 896h113.28l74.24-192h328.96l71.04 192H704L408.32 128z m-53.12 448l92.16-250.88A245.76 245.76 0 0 0 353.28 256a225.92 225.92 0 0 0 16 69.12L461.44 576zM996.48 812.16v-115.84Q998.4 576 865.28 576t-152.32 92.16l67.84 17.92q8.32-55.68 82.56-51.84t64 53.76a224.64 224.64 0 0 1-97.28 19.84q-122.88 12.16-128 101.76T820.48 896a139.52 139.52 0 0 0 114.56-44.16 48.64 48.64 0 0 0 19.2 37.76H1024a102.4 102.4 0 0 1-27.52-77.44zM926.72 768q-6.4 64-95.36 71.68-56.96 0-55.04-32t67.84-44.16a149.76 149.76 0 0 0 82.56-23.68zM949.76 384H1024c-15.36-106.88-232.32-128-311.04-128V128L512 288 712.32 448V327.04a488.96 488.96 0 0 1 237.44 56.96z" fill="#666666" ></path></symbol><symbol id="edui-for-tolowercase" viewBox="0 0 1024 1024"><path d="M295.68 128L0 896h113.28l74.24-192h328.96l71.04 192H704L408.32 128z m-53.12 448l92.16-250.88A245.76 245.76 0 0 0 353.28 256a225.92 225.92 0 0 0 16 69.12L461.44 576zM996.48 812.16v-115.84Q998.4 576 865.28 576t-152.32 92.16l67.84 17.92q8.32-55.68 82.56-51.84t64 53.76a224.64 224.64 0 0 1-97.28 19.84q-122.88 12.16-128 101.76T820.48 896a139.52 139.52 0 0 0 114.56-44.16 48.64 48.64 0 0 0 19.2 37.76H1024a102.4 102.4 0 0 1-27.52-77.44zM926.72 768q-6.4 64-95.36 71.68-56.96 0-55.04-32t67.84-44.16a149.76 149.76 0 0 0 82.56-23.68zM586.24 384H512c15.36-106.88 232.32-128 311.04-128V128L1024 288 823.04 448V327.04a488.96 488.96 0 0 0-236.8 56.96z" fill="#666666" ></path></symbol><symbol id="edui-for-insertvideo" viewBox="0 0 1024 1024"><path d="M384 768l256-256-256-256v512z" fill="#666666" ></path><path d="M960 64H64a64 64 0 0 0-64 64v768a64 64 0 0 0 64 64h896a64 64 0 0 0 64-64V128a64 64 0 0 0-64-64z m0 832H64V128h896z" fill="#666666" ></path></symbol><symbol id="edui-for-emotion" viewBox="0 0 1024 1024"><path d="M512 0a512 512 0 1 0 512 512 512 512 0 0 0-512-512z m0 960a448 448 0 1 1 448-448 448 448 0 0 1-448 448z" fill="#666666" ></path><path d="M320 384m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0Z" fill="#666666" ></path><path d="M704 384m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0Z" fill="#666666" ></path><path d="M512 832a256 256 0 0 0 256-256H256a256 256 0 0 0 256 256z" fill="#666666" ></path></symbol><symbol id="edui-for-pasteplain" viewBox="0 0 1024 1024"><path d="M640 256V128H576V64a64 64 0 0 0-64-64H320a64 64 0 0 0-64 64v64H192v128zM320 64h192v64H320z" fill="#666666" ></path><path d="M832 384V160a33.28 33.28 0 0 0-33.92-32H704v64h64v64h-64v64H128V128H33.92a33.28 33.28 0 0 0-33.92 32V896h384v128h640V384z m-384 576V448h512v512z" fill="#666666" ></path><path d="M576 576h320v64H576zM704 640h64v256h-64zM704 192h64v128h-64z" fill="#666666" ></path></symbol><symbol id="edui-for-preview" viewBox="0 0 1024 1024"><path d="M895.909541 256.060626h-191.95477V56.427664A63.984924 63.984924 0 0 0 639.969847 0.120932H137.688197A69.743567 69.743567 0 0 0 64.105535 64.105855v895.78893a69.743567 69.743567 0 0 0 73.582662 63.984923h748.623606A69.743567 69.743567 0 0 0 959.894465 959.894785V313.007208A63.984924 63.984924 0 0 0 895.909541 256.060626z m0 695.516119a8.31804 8.31804 0 0 1-8.31804 8.31804H137.688197a9.597739 9.597739 0 0 1-9.597738-9.597739V72.423895A8.31804 8.31804 0 0 1 136.408499 64.105855h491.404213a11.517286 11.517286 0 0 1 12.157135 10.877437v191.954771A60.145828 60.145828 0 0 0 703.954771 320.045549h180.437484a11.517286 11.517286 0 0 1 12.157136 10.877437v620.653759z" fill="#666666" ></path><path d="M767.939694 850.480566l-173.399143-172.759294a225.86678 225.86678 0 1 0-45.429295 45.429296l173.399142 172.759293zM256.060306 543.992782A159.962309 159.962309 0 1 1 416.022615 703.955091 159.962309 159.962309 0 0 1 256.060306 543.992782z" fill="#666666" ></path></symbol><symbol id="edui-for-print" viewBox="0 0 1024 1024"><path d="M320.00576 448h384v64H320.00576zM320.00576 576h384v64H320.00576z" fill="#666666" ></path><path d="M988.80576 179.2H832.00576V0H192.00576v179.2H35.20576a35.2 35.2 0 0 0-35.2 35.84v443.52h192V704l256 256h384v-301.44h192V346.88a36.48 36.48 0 0 0 0-3.84v-128a35.2 35.2 0 0 0-35.2-35.84zM256.00576 64h512v115.2H256.00576z m640 512h-56.96V455.68H768.00576V896H471.04576v-199.04H256.00576V455.68H187.52576V576H128.00576V384h768z m32-274.56a32.64 32.64 0 1 1 32-32.64 32 32 0 0 1-32 32.64z" fill="#666666" ></path></symbol><symbol id="edui-for-selectall" viewBox="0 0 1024 1024"><path d="M184.32 113.92L298.24 0h-40.32L144 113.92h40.32zM113.92 144L0 257.92v40.32l113.92-113.92v-40.32zM144 0L0 144v40.32L184.32 0h-40.32zM30.72 0L0 30.72v40.32L71.04 0H30.72zM527.36 113.92L641.28 0h-40.32L487.68 113.92h39.68zM113.92 487.68L0 600.96v40.32l113.92-113.92v-39.68zM113.92 373.76L0 487.68v39.68l113.92-113.28v-40.32zM414.08 113.92L527.36 0h-39.68L373.76 113.92h40.32zM300.16 113.92L414.08 0h-40.32L259.84 113.92h40.32zM113.92 259.84L0 373.76v40.32l113.92-113.92v-40.32zM113.92 835.2L0 948.48v40.32l113.92-113.28v-40.32zM875.52 113.92L988.8 0h-40.32l-113.28 113.92h40.32zM113.92 721.28L0 835.2v40.32l113.92-113.92v-40.32zM761.6 113.92L875.52 0h-40.32l-113.92 113.92h40.32zM113.92 607.36L0 721.28v40.32l113.92-113.92v-40.32zM647.68 113.92L761.6 0h-40.32L607.36 113.92h40.32zM910.08 419.2L1024 305.28v-40.32l-113.92 113.92v40.32zM378.88 910.08L264.96 1024h40.32l113.92-113.92h-40.32zM910.08 305.28L1024 192v-40.32l-113.92 113.28v40.32zM264.96 910.08L151.68 1024H192l113.28-113.92h-40.32zM151.68 910.08L37.76 1024h40.32L192 910.08h-40.32zM910.08 151.68V192L1024 78.08V37.76l-113.92 113.92zM910.08 759.04L1024 645.12v-40.32l-113.92 113.92v40.32zM718.72 910.08L604.8 1024h40.32l113.92-113.92h-40.32zM910.08 645.12L1024 531.2v-40.32l-113.92 113.92v40.32zM604.8 910.08L490.88 1024h40.32l113.92-113.92h-40.32zM490.88 910.08L376.96 1024h40.32l113.92-113.92h-40.32zM910.08 531.2L1024 417.28v-40.32l-113.92 113.92v40.32zM988.16 1024l35.84-35.84v-40.32L947.84 1024h40.32zM874.24 1024L1024 874.24v-40.32L833.92 1024h40.32zM833.92 910.08L720.64 1024h39.68l113.92-113.92h-40.32zM910.08 874.24L1024 760.32v-39.68l-113.92 113.28v40.32zM256 630.4Q263.04 768 442.24 768a223.36 223.36 0 0 0 183.04-70.4 77.44 77.44 0 0 0 30.72 60.8H768a163.84 163.84 0 0 1-44.16-124.8V448Q727.04 256 512 256T269.44 403.2l108.8 28.8q13.44-89.6 133.76-83.2 112-6.4 101.76 86.4a359.68 359.68 0 0 1-156.16 32Q259.2 486.4 256 630.4zM611.84 518.4v44.8q-10.24 105.6-152.32 115.2-91.52 0-88.32-51.2-6.4-60.8 108.8-70.4a240 240 0 0 0 131.84-38.4z" fill="#666666" ></path></symbol><symbol id="edui-for-mergecells" viewBox="0 0 1024 1024"><path d="M0 0v1024h1024V0z m320 960H64v-256h256z m0-320H64V384h256z m0-320H64V64h256z m64-256h256v256H384z m576 896H384V384h576z m0-640h-256V64h256z" fill="#666666" ></path></symbol><symbol id="edui-for-deletecol" viewBox="0 0 1024 1024"><path d="M1024 307.84V0h-256v576h256zM832 256V64h128v192z m0 256V320h128v192zM448 307.84V0H0v576h448zM64 256V64h128v192z m192 0V64h128v192zM64 512V320h128v192z m192 0V320h128v192zM640 704V635.52L570.24 704H640zM593.28 708.48z" fill="#666666" ></path><path d="M640 512v136.32l64-34.56V256H512v352l64 32V512zM576 448V320h64v128z" fill="#666666" ></path><path d="M734.72 1024l96.64-92.8L704 808.96l128-122.88-96-92.16-32 19.84V768H512V608l-32-14.08L384 686.08l128 122.88-127.36 122.24L480.64 1024l127.36-122.24L734.72 1024z" fill="#666666" ></path><path d="M512 704h76.8L512 629.76V704z" fill="#666666" ></path></symbol><symbol id="edui-for-deleterow" viewBox="0 0 1024 1024"><path d="M307.84 0H0v256h576V0zM256 192H64V64h192z m256 0H320V64h192zM307.84 576H0v448h576V576zM256 960H64v-128h192z m0-192H64v-128h192z m256 192H320v-128h192z m0-192H320v-128h192zM716.8 360.32h-68.48l68.48 70.4v-70.4zM708.48 430.72zM520.96 344.96h128l-34.56-35.84H256v219.52h352l32-35.84H520.96zM448 448H316.16V384H448z" fill="#666666" ></path><path d="M1024 288.64l-92.8-96L808.96 320l-122.88-128-92.16 96 19.84 21.12h137.6V528.64H608l-14.08 15.36 92.16 96 122.88-128 122.24 127.36L1024 542.72 901.76 416 1024 288.64z" fill="#666666" ></path><path d="M716.8 492.8V416l-74.24 76.8h74.24z" fill="#666666" ></path></symbol><symbol id="edui-for-attachment" viewBox="0 0 1024 1024"><path d="M972.16 372.48l-520.32 512a222.72 222.72 0 0 1-312.32 0A216.32 216.32 0 0 1 138.88 576l468.48-460.8a148.48 148.48 0 0 1 208 0 144.64 144.64 0 0 1 0 206.08l-467.84 463.36a74.24 74.24 0 0 1-104.32 0 72.32 72.32 0 0 1 0-103.04l416.64-411.52-51.84-51.2L192 630.4a144.64 144.64 0 0 0 0 206.08 148.48 148.48 0 0 0 208 0l468.48-463.36a216.96 216.96 0 0 0 0-308.48A222.72 222.72 0 0 0 555.52 64L64 552.96a291.2 291.2 0 0 0 26.24 384 296.96 296.96 0 0 0 385.28 23.04L1024 424.32l-51.84-51.2z" fill="#666666" ></path></symbol><symbol id="edui-for-music" viewBox="0 0 1024 1024"><path d="M991.140186 0.88755h-7.673343a36.448381 36.448381 0 0 0-15.986133 0L219.969177 135.810504a31.972264 31.972264 0 0 0-28.135593 30.693374 30.053928 30.053928 0 0 0 0 3.197226v616.425251A127.889056 127.889056 0 0 0 127.889056 768.221888a127.889056 127.889056 0 1 0 127.889056 127.889056V384.554719a36.448381 36.448381 0 0 0 17.904468 0L959.167922 260.502334v457.203376a127.889056 127.889056 0 0 0-63.944528-17.904468A127.889056 127.889056 0 1 0 1023.11245 832.166416V32.859814a31.972264 31.972264 0 0 0-31.972264-31.972264z" fill="#666666" ></path></symbol><symbol id="edui-for-gmap" viewBox="0 0 1024 1024"><path d="M543.36 572.16h128v144.64a170.24 170.24 0 0 1-103.68 30.08c-135.68 0-208-89.6-208-236.8s83.84-233.6 206.08-233.6a183.04 183.04 0 0 1 138.24 55.68l56.32-64A270.72 270.72 0 0 0 562.56 192 298.24 298.24 0 0 0 256 512c0 202.24 128 320 304 320A306.56 306.56 0 0 0 768 759.68V492.16H543.36z" fill="#1C7C59" ></path><path d="M896 0H128a64 64 0 0 0-64 64v896a64 64 0 0 0 64 64h768a64 64 0 0 0 64-64V64a64 64 0 0 0-64-64z m0 896a64 64 0 0 1-64 64H192a64 64 0 0 1-64-64V128a64 64 0 0 1 64-64h640a64 64 0 0 1 64 64z" fill="#1C7C59" ></path></symbol><symbol id="edui-for-insertframe" viewBox="0 0 1024 1024"><path d="M448 384a256 256 0 1 0 256 256 256 256 0 0 0-256-256z m195.84 170.88a213.76 213.76 0 0 1 0 170.88H547.2a504.32 504.32 0 0 0 0-170.88zM384 640a527.36 527.36 0 0 1 6.4-85.12h115.2A527.36 527.36 0 0 1 512 640a527.36 527.36 0 0 1-6.4 85.12H390.4A527.36 527.36 0 0 1 384 640z m234.88-128H537.6a218.88 218.88 0 0 0-39.68-79.36A213.76 213.76 0 0 1 618.88 512zM448 448c19.2 0 35.84 24.96 48 64h-96c12.16-39.04 28.8-64 48-64z m-49.92-15.36A218.88 218.88 0 0 0 358.4 512H277.12a213.76 213.76 0 0 1 120.96-79.36zM252.16 554.88h96a504.32 504.32 0 0 0 0 170.88h-96a213.76 213.76 0 0 1 0-170.88zM277.12 768H358.4a218.88 218.88 0 0 0 39.68 79.36A213.76 213.76 0 0 1 277.12 768zM448 832c-19.2 0-35.84-24.96-48-64h96c-12.16 39.04-28.8 64-48 64z m49.92 15.36A218.88 218.88 0 0 0 537.6 768h81.28a213.76 213.76 0 0 1-120.96 79.36z" fill="#666666" ></path><path d="M597.76 0H64v1024h896V330.24zM896 355.84V960H128V64h448v256h320z" fill="#666666" ></path></symbol><symbol id="edui-for-pdfformat" viewBox="0 0 1024 1024"><path d="M597.76 0H64v1024h896V330.24zM896 960H128V64h448v291.2h320z" fill="#EF4848" ></path><path d="M213.76 615.68H166.4v133.12h49.28c58.24 0 85.76-21.76 85.76-69.76s-30.72-63.36-87.68-63.36zM486.4 622.08h-32.64v268.8h32.64c77.44 0 119.04-45.44 119.04-135.68S564.48 622.08 486.4 622.08z" fill="#EF4848" ></path><path d="M64 448v576h874.24V448z m175.36 352.64h-54.4v136.96H128V576h109.44c82.56 0 138.24 27.52 138.24 108.8S320 800.64 239.36 800.64z m256 136.96H396.8V576h93.44a159.36 159.36 0 0 1 174.72 179.2 160.64 160.64 0 0 1-171.52 182.4z m411.52-313.6h-158.72v110.72h133.76v48h-133.76v155.52h-56.96V576h214.4z" fill="#EF4848" ></path></symbol><symbol id="edui-for-word" viewBox="0 0 1024 1024"><path d="M718.08 545.92c-12.16 60.16-21.12 117.76-32 177.28h-3.84c-12.8-58.88-23.68-117.12-36.48-177.28L567.68 208H461.44L384 545.92c-12.8 58.88-23.68 117.76-35.84 177.28H345.6c-9.6-58.88-18.56-117.12-29.44-177.28L243.2 208H128L275.84 832h131.84l64-307.2c14.08-58.88 23.68-117.12 34.56-181.76H512c12.16 64 21.76 121.6 34.56 180.48L618.24 832h136.96L896 208h-106.88z" fill="#4972AD" ></path><path d="M960 0H64a64 64 0 0 0-64 64v896a64 64 0 0 0 64 64h896a64 64 0 0 0 64-64V64a64 64 0 0 0-64-64z m0 896a64 64 0 0 1-64 64H128a64 64 0 0 1-64-64V128a64 64 0 0 1 64-64h768a64 64 0 0 1 64 64z" fill="#4972AD" ></path></symbol><symbol id="edui-for-excel" viewBox="0 0 1024 1024"><path d="M960 0H64a64 64 0 0 0-64 64v896a64 64 0 0 0 64 64h896a64 64 0 0 0 64-64V64a64 64 0 0 0-64-64z m0 896a64 64 0 0 1-64 64H128a64 64 0 0 1-64-64V128a64 64 0 0 1 64-64h768a64 64 0 0 1 64 64z" fill="#60BF6B" ></path><path d="M816.64 128h-155.52L586.24 282.88c-19.2 41.6-40.32 85.12-59.52 128h-5.12c-23.04-43.52-46.72-86.4-67.2-128L369.28 128H208.64L422.4 495.36 192 896h156.16l82.56-161.92c21.76-47.36 44.16-93.44 64-136.96h6.4c25.6 43.52 50.56 90.88 73.6 136.96l96 161.92H832L602.88 512z" fill="#60BF6B" ></path></symbol><symbol id="edui-for-time" viewBox="0 0 1024 1024"><path d="M839.710352 230.607611l21.719276-21.719277 43.438553 43.438553 54.298191-53.659389-127.760449-127.760449-54.936993 54.298191 43.438552 43.438553-21.719276 21.719276A477.82408 477.82408 0 0 0 556.720957 74.739863a76.656269 76.656269 0 0 0-152.673737 0 472.713662 472.713662 0 0 0-87.515907 23.635683l51.104179 79.211478a383.281347 383.281347 0 0 1 112.429196-17.24766 383.281347 383.281347 0 1 1-383.281348 383.281347 383.281347 383.281347 0 0 1 47.271366-184.613849L64.843228 304.708671a472.07486 472.07486 0 0 0-63.880225 240.189645 479.101684 479.101684 0 0 0 958.203369 0 473.352464 473.352464 0 0 0-119.45602-314.290705z" fill="#666666" ></path><path d="M480.064688 255.520898a46.632564 46.632564 0 0 0-46.632564 45.993762v182.05864a76.017467 76.017467 0 0 0 0 122.650031v63.880225a46.632564 46.632564 0 0 0 92.626325 0v-63.880225a76.017467 76.017467 0 0 0 0-122.650031V298.959451A46.632564 46.632564 0 0 0 480.064688 255.520898zM252.651088 0L143.415904 251.049283l274.684966 5.110418-50.465378-77.933874-51.104179-79.850281-63.880225-98.375546z" fill="#666666" ></path></symbol><symbol id="edui-for-snapscreen" viewBox="0 0 1024 1024"><path d="M665.6 392.96L460.8 548.48 256 314.88V704h512V548.48l-102.4-155.52z" fill="#666666" ></path><path d="M1024 832h-128V128H192V0H128v128H0v64h128v704h704v128h64v-128h128zM192 832V192h640v640z" fill="#666666" ></path></symbol><symbol id="edui-for-wordimage" viewBox="0 0 1024 1024"><path d="M988.16 448H419.84a35.84 35.84 0 0 0-35.84 35.84v504.32a35.84 35.84 0 0 0 35.84 35.84h568.96a35.84 35.84 0 0 0 35.84-35.84V483.84a35.84 35.84 0 0 0-36.48-35.84z m-323.84 164.48a80 80 0 1 1-80-81.92 81.28 81.28 0 0 1 80 81.92zM929.28 960H461.44l131.2-205.44 85.12 133.12 177.28-298.24L960 768v163.2a30.72 30.72 0 0 1-30.72 28.8z" fill="#666666" ></path><path d="M960 0H64a64 64 0 0 0-64 64v896a64 64 0 0 0 64 64h256v-64H128a64 64 0 0 1-64-64V128a64 64 0 0 1 64-64h768a64 64 0 0 1 64 64v256h64V64a64 64 0 0 0-64-64z" fill="#4972AD" ></path><path d="M320 554.24L241.28 192H122.88l151.68 640H320V565.76zM858.88 384l43.52-192h-116.48l-40.32 192h113.28zM501.76 384c0-26.88 4.48-40.32 7.04-64H512c0 23.68 7.68 64 7.68 64h97.28l-44.8-192H456.32l-42.88 192z" fill="#4972AD" ></path></symbol><symbol id="edui-for-edittd" viewBox="0 0 1024 1024"><path d="M768 768m-192 0a192 192 0 1 0 384 0 192 192 0 1 0-384 0Z" fill="#666666" ></path><path d="M448 768a320 320 0 0 1 448-293.12V128H128v768h346.88A320 320 0 0 1 448 768z" fill="#666666" ></path><path d="M0 0v1024h576a320 320 0 0 1-64-64H64V64h896v448a320 320 0 0 1 64 64V0z" fill="#666666" ></path></symbol><symbol id="edui-for-lineheight" viewBox="0 0 1024 1024"><path d="M380.8 768H0l190.72 254.72L380.8 768z" fill="#666666" ></path><path d="M512 768l512 0 0 64-512 0 0-64Z" fill="#666666" ></path><path d="M512 576l512 0 0 64-512 0 0-64Z" fill="#666666" ></path><path d="M512 384l512 0 0 64-512 0 0-64Z" fill="#666666" ></path><path d="M512 192l512 0 0 64-512 0 0-64Z" fill="#666666" ></path><path d="M2.56 256h380.8L193.28 1.28 2.56 256z" fill="#666666" ></path></symbol><symbol id="edui-for-rowspacingbottom" viewBox="0 0 1024 1024"><path d="M704 768H320l192 256zM672 640H32c-19.2 0-32-12.8-32-32S12.8 576 32 576h640c19.2 0 32 12.8 32 32s-12.8 32-32 32zM864 448H32C12.8 448 0 435.2 0 416S12.8 384 32 384h832c19.2 0 32 12.8 32 32s-12.8 32-32 32zM480 256h-448C12.8 256 0 243.2 0 224S12.8 192 32 192h448c19.2 0 32 12.8 32 32s-12.8 32-32 32zM992 64H32C12.8 64 0 51.2 0 32S12.8 0 32 0h960c19.2 0 32 12.8 32 32s-12.8 32-32 32z" fill="#666666" ></path></symbol><symbol id="edui-for-rowspacingtop" viewBox="0 0 1024 1024"><path d="M320 256h384L512 0zM352 384h640c19.2 0 32 12.8 32 32s-12.8 32-32 32h-640c-19.2 0-32-12.8-32-32s12.8-32 32-32zM160 576h832c19.2 0 32 12.8 32 32s-12.8 32-32 32h-832c-19.2 0-32-12.8-32-32s12.8-32 32-32zM544 768h448c19.2 0 32 12.8 32 32s-12.8 32-32 32h-448c-19.2 0-32-12.8-32-32s12.8-32 32-32zM32 960h960c19.2 0 32 12.8 32 32s-12.8 32-32 32H32c-19.2 0-32-12.8-32-32s12.8-32 32-32z" fill="#666666" ></path></symbol><symbol id="edui-for-scrawl" viewBox="0 0 1024 1024"><path d="M1018.28352 277.12a20.48 20.48 0 0 0-15.36-6.4 68.48 68.48 0 0 0-40.96 23.68l-390.4 389.12a1234.56 1234.56 0 0 0-69.12 105.6l-8.32 14.08 14.08-8.96c3.84 0 90.24-56.96 104.96-71.04l390.4-389.12c16.64-14.08 29.44-41.6 14.72-56.96z m-243.84 120.96a56.96 56.96 0 1 1-56.96-58.88 58.24 58.24 0 0 1 56.96 58.88zM173.48352 603.52a58.88 58.88 0 1 1 56.96-58.88 58.24 58.24 0 0 1-56.96 58.88zM256.68352 398.08a56.96 56.96 0 1 1 56.96 58.88 58.24 58.24 0 0 1-56.96-58.88z m202.88-58.88a56.96 56.96 0 1 1 56.96 58.88 58.24 58.24 0 0 1-56.96-58.88z m442.88 199.04a415.36 415.36 0 0 1-402.56 352.64 335.36 335.36 0 0 1-122.88-23.68c-38.4-16-55.68-34.56-59.52-46.72s-3.84-13.44-5.12-20.48a250.24 250.24 0 0 0-23.04-64 81.28 81.28 0 0 0-72.96-43.52 114.56 114.56 0 0 0-26.24 0 187.52 187.52 0 0 1-42.24 5.12c-28.8 0-77.44-7.68-78.72-60.16-8.32-266.88 206.08-412.16 421.76-437.76a419.2 419.2 0 0 1 48.64 0 500.48 500.48 0 0 1 174.72 30.72c10.88 4.48 16.64 7.04 44.8 21.12a260.48 260.48 0 0 1 73.6 53.76l34.56-64a314.88 314.88 0 0 0-76.8-55.68c-28.8-14.08-36.48-17.92-49.92-23.68A570.24 570.24 0 0 0 539.56352 128a485.12 485.12 0 0 0-56.32 0 592 592 0 0 0-339.2 151.68A462.08 462.08 0 0 0 0.68352 640a122.88 122.88 0 0 0 46.72 97.28 159.36 159.36 0 0 0 99.84 30.72 256 256 0 0 0 57.6-7.04h10.88c13.44 0 19.2 11.52 30.72 57.6 0 7.68 3.84 15.36 5.76 23.04a154.88 154.88 0 0 0 99.2 91.52A403.84 403.84 0 0 0 499.88352 960a460.16 460.16 0 0 0 177.92-35.2A471.04 471.04 0 0 0 821.80352 832a496 496 0 0 0 100.48-135.04 476.8 476.8 0 0 0 48.64-158.72V519.04z" fill="#666666" ></path></symbol><symbol id="edui-for-redo" viewBox="0 0 1024 1024"><path d="M900.608 474.112c-51.2-51.2-260.608-261.632-291.84-292.352a68.096 68.096 0 0 0-91.648 3.072 73.216 73.216 0 0 0-14.336 76.288c12.288 18.432 187.904 199.68 187.904 199.68H169.984A61.952 61.952 0 0 0 102.4 525.312a71.168 71.168 0 0 0 68.096 67.584h517.632l-173.056 172.032a68.096 68.096 0 0 0 0 93.184 65.536 65.536 0 0 0 90.624 7.168c25.088-23.04 256-252.928 297.984-296.448s-3.072-94.72-3.072-94.72z" fill="#666666" ></path></symbol><symbol id="edui-for-undo" viewBox="0 0 1024 1024"><path d="M128.512 476.16c51.2-51.2 260.608-261.632 291.84-292.352a68.096 68.096 0 0 1 91.648 3.072 73.216 73.216 0 0 1 13.824 76.288C512 281.6 338.432 460.8 338.432 460.8h520.192a61.952 61.952 0 0 1 65.536 66.56 71.168 71.168 0 0 1-68.096 67.584H338.432L512 768a68.096 68.096 0 0 1 0 93.184 65.536 65.536 0 0 1-90.624 7.168c-25.088-23.04-256-252.928-297.984-296.448s5.12-95.744 5.12-95.744z" fill="#666666" ></path></symbol><symbol id="edui-for-inserttitle" viewBox="0 0 1024 1024"><path d="M512 516.096v-153.6H460.8v102.4H358.4v51.2H204.8v-51.2H102.4v-102.4H51.2v614.4h921.6v-460.8z m-173.056 409.6h-240.64V757.76h238.592z m0-219.136h-240.64v-139.264h238.592z m297.472 219.136H388.096V757.76h246.272z m0-219.136H388.096v-139.264h246.272z m283.136 219.136h-233.984V757.76h231.936z m0-219.136h-233.984v-139.264h231.936z" fill="#666666" ></path><path d="M512 465.408v51.2h460.8V51.2h-460.8v307.2z m51.2-204.8h153.6v-153.6h51.2v153.6h153.6v51.2h-153.6v153.6h-51.2v-153.6h-153.6z" fill="#1C7C59" ></path><path d="M99.328 108.032h102.4v-51.2h-153.6v153.6h51.2v-102.4zM512.512 104.96v-51.2h-153.6v51.2h102.4v102.4h51.2v-102.4z" fill="#666666" ></path></symbol><symbol id="edui-for-insertparagraphtrue" viewBox="0 0 1024 1024"><path d="M997.12 448H0v576h1024V448zM60.16 960v-256H320v256z m481.92 0H384v-256h256v256z m421.76 0H704v-256h259.84zM448 0H0v64h192v384h64V64h192V0z" fill="#666666" ></path></symbol><symbol id="edui-for-aligntable" viewBox="0 0 1024 1024"><path d="M992 64H32C12.8 64 0 51.2 0 32S12.8 0 32 0h960c19.2 0 32 12.8 32 32s-12.8 32-32 32z m0 192H32C12.8 256 0 243.2 0 224S12.8 192 32 192h960c19.2 0 32 12.8 32 32s-12.8 32-32 32z m0 192H32C12.8 448 0 435.2 0 416S12.8 384 32 384h960c19.2 0 32 12.8 32 32s-12.8 32-32 32z m0 384H32c-19.2 0-32-12.8-32-32s12.8-32 32-32h960c19.2 0 32 12.8 32 32s-12.8 32-32 32z m0 192H32c-19.2 0-32-12.8-32-32s12.8-32 32-32h960c19.2 0 32 12.8 32 32s-12.8 32-32 32z" fill="#666666" ></path><path d="M992 448H32C12.8 448 0 435.2 0 416S12.8 384 32 384h960c19.2 0 32 12.8 32 32s-12.8 32-32 32z m0 192H32c-19.2 0-32-12.8-32-32S12.8 576 32 576h960c19.2 0 32 12.8 32 32s-12.8 32-32 32z" fill="#666666" ></path></symbol><symbol id="edui-for-table" viewBox="0 0 1024 1024"><path d="M0 0v1024h1024V0z m320 960H64v-256h256z m0-320H64V384h256z m320 320H384v-256h256z m0-320H384V384h256z m320 320h-256v-256h256z m0-320h-256V384h256z m0-320H64V64h896z" fill="#666666" ></path></symbol><symbol id="edui-for-tablealignment-left" viewBox="0 0 1024 1024"><path d="M51.2 102.4l921.6 0 0 51.2-921.6 0 0-51.2Z" fill="#666666" ></path><path d="M51.2 256l614.4 0 0 51.2-614.4 0 0-51.2Z" fill="#666666" ></path><path d="M51.2 409.6l921.6 0 0 51.2-921.6 0 0-51.2Z" fill="#666666" ></path><path d="M51.2 563.2l614.4 0 0 51.2-614.4 0 0-51.2Z" fill="#666666" ></path><path d="M51.2 716.8l921.6 0 0 51.2-921.6 0 0-51.2Z" fill="#666666" ></path><path d="M51.2 870.4l614.4 0 0 51.2-614.4 0 0-51.2Z" fill="#666666" ></path></symbol><symbol id="edui-for-tablealignment-center" viewBox="0 0 1024 1024"><path d="M51.2 102.4l921.6 0 0 51.2-921.6 0 0-51.2Z" fill="#666666" ></path><path d="M51.2 409.6l921.6 0 0 51.2-921.6 0 0-51.2Z" fill="#666666" ></path><path d="M51.2 716.8l921.6 0 0 51.2-921.6 0 0-51.2Z" fill="#666666" ></path><path d="M51.2 256l921.6 0 0 51.2-921.6 0 0-51.2Z" fill="#666666" ></path><path d="M51.2 563.2l921.6 0 0 51.2-921.6 0 0-51.2Z" fill="#666666" ></path><path d="M51.2 870.4l921.6 0 0 51.2-921.6 0 0-51.2Z" fill="#666666" ></path><path d="M51.2 102.4l921.6 0 0 51.2-921.6 0 0-51.2Z" fill="#666666" ></path><path d="M51.2 409.6l921.6 0 0 51.2-921.6 0 0-51.2Z" fill="#666666" ></path><path d="M51.2 716.8l921.6 0 0 51.2-921.6 0 0-51.2Z" fill="#666666" ></path></symbol><symbol id="edui-for-tablealignment-right" viewBox="0 0 1024 1024"><path d="M51.2 102.4l921.6 0 0 51.2-921.6 0 0-51.2Z" fill="#666666" ></path><path d="M358.4 256l614.4 0 0 51.2-614.4 0 0-51.2Z" fill="#666666" ></path><path d="M51.2 409.6l921.6 0 0 51.2-921.6 0 0-51.2Z" fill="#666666" ></path><path d="M358.4 563.2l614.4 0 0 51.2-614.4 0 0-51.2Z" fill="#666666" ></path><path d="M51.2 716.8l921.6 0 0 51.2-921.6 0 0-51.2Z" fill="#666666" ></path><path d="M358.4 870.4l614.4 0 0 51.2-614.4 0 0-51.2Z" fill="#666666" ></path></symbol><symbol id="edui-for-paste" viewBox="0 0 1024 1024"><path d="M832 320V160a32 32 0 0 0-32-32H576V64a64 64 0 0 0-64-64H384a64 64 0 0 0-64 64v64H96a32 32 0 0 0-32 32v640a32 32 0 0 0 32 32H384v192h448l192-192V320zM384 64h128v64H384zM192 192h512v64H192z m640 741.76V832h101.76zM960 768h-192v192H448V384h512z" fill="#666666" ></path></symbol><symbol id="edui-for-map" viewBox="0 0 1024 1024"><path d="M375.424 331.824c-2.432 6.96-7.856 24.704-3.152 40.208 9.232 34.672 39.424 36.24 39.424 36.24h43.264V302.368h-46.4c-20.864 6.24-30.944 22.432-33.136 29.456z m129.072 119.072H397.008c-46.448-9.28-64.896-40.992-67.28-46.368-2.288-5.456-15.504-30.944-8.464-74.256 20.032-64.976 77.28-69.616 77.28-69.616h57.248v-70.368l48.704 0.8v259.808z m200.272-0.768H581.04c-47.92-12.368-50.176-46.496-50.176-46.496V266.816L581.04 266v123.024c3.008 13.024 19.376 15.44 19.376 15.44h50.912V266.768h53.456v183.36h-0.016z" fill="" ></path><path d="M512 1021.45c-11.203 0-21.563-6-27.172-15.688L208.375 527.726c-30.803-53.1-47.11-113.662-47.11-175.084 0-193.047 157.35-350.094 350.75-350.094 193.391 0 350.72 157.047 350.72 350.094 0 61.421-16.298 121.975-47.126 175.115l-276.437 478.007c-5.61 9.687-15.953 15.687-27.172 15.687z m0.016-956.138c-158.788 0-287.985 128.907-287.985 287.329 0 50.375 13.375 100.037 38.663 143.615l249.303 431.1 249.297-431.062c25.297-43.616 38.656-93.281 38.656-143.656 0-158.42-129.172-287.325-287.934-287.325z" fill="" ></path></symbol><symbol id="edui-for-directionalityrtl" viewBox="0 0 1024 1024"><path d="M960 833.92l-384-320 384-320.64v640.64zM64 192V128h448v64H320v640h192v64H64v-64h192V192H64z" fill="#666666" ></path></symbol><symbol id="edui-for-imagecenter" viewBox="0 0 1024 1024"><path d="M0 0h1024v64H0z" fill="#666666" ></path><path d="M128 192l768 0 0 448-768 0 0-448Z" fill="#66BBBF" ></path><path d="M0 768h1024v64H0zM0 960h1024v64H0z" fill="#666666" ></path></symbol><symbol id="edui-for-imagenone" viewBox="0 0 1024 1024"><path d="M52.736 107.008l921.6 0 0 51.2-921.6 0 0-51.2Z" fill="#666666" ></path><path d="M52.736 260.608l409.6 0 0 512-409.6 0 0-512Z" fill="#66BBBF" ></path><path d="M564.736 721.408l409.6 0 0 51.2-409.6 0 0-51.2Z" fill="#666666" ></path><path d="M54.784 875.008l921.6 0 0 51.2-921.6 0 0-51.2Z" fill="#666666" ></path><path d="M564.736 567.808l409.6 0 0 51.2-409.6 0 0-51.2Z" fill="#666666" ></path></symbol><symbol id="edui-for-fontborder" viewBox="0 0 1024 1024"><path d="M345.6 832l44.8-153.6h224l44.8 153.6H768L576 192H448L256 832h89.6z m153.6-531.2l83.2 288H416l83.2-288z" fill="#666666" ></path><path d="M896 64H64v896h896V64h-64z m0 832H128V128h768v768z" fill="#666666" ></path></symbol><symbol id="edui-for-edittable" viewBox="0 0 1024 1024"><path d="M993.92 848.64L849.92 704a240 240 0 0 0-320-300.8L512 410.24v2.56a12.16 12.16 0 0 0 0 17.28l134.4 134.4-81.92 80.64L432.64 512a14.08 14.08 0 0 0-23.68 5.12l-4.48 10.24a240 240 0 0 0 300.8 320l144 144a102.4 102.4 0 0 0 72.96 30.08 103.04 103.04 0 0 0 72.96-175.36zM960 960a56.96 56.96 0 0 1-40.32 16.64 56.96 56.96 0 0 1-40.32-16.64l-165.12-165.12-14.08 6.4a192 192 0 0 1-265.6-220.8L555.52 704a14.08 14.08 0 0 0 17.28 0l128-128a14.08 14.08 0 0 0 0-18.56L580.48 434.56A192 192 0 0 1 802.56 704l-6.4 14.08L960 880.64A56.96 56.96 0 0 1 960 960z" fill="#666666" ></path><path d="M832 0H0v832h320V320h512zM256 768H64V576h192z m0-256H64V320h192z m0-256H64V64h192z m256 0H320V64h192z m64 0V64h192v192z" fill="#666666" ></path></symbol><symbol id="edui-for-imageleft" viewBox="0 0 1024 1024"><path d="M50.688 101.376l921.6 0 0 51.2-921.6 0 0-51.2Z" fill="#666666" ></path><path d="M50.688 254.976l409.6 0 0 512-409.6 0 0-512Z" fill="#66BBBF" ></path><path d="M562.688 715.776l409.6 0 0 51.2-409.6 0 0-51.2Z" fill="#666666" ></path><path d="M52.736 869.376l921.6 0 0 51.2-921.6 0 0-51.2Z" fill="#666666" ></path><path d="M562.688 562.176l409.6 0 0 51.2-409.6 0 0-51.2Z" fill="#666666" ></path><path d="M562.688 408.576l409.6 0 0 51.2-409.6 0 0-51.2Z" fill="#666666" ></path><path d="M562.688 254.976l409.6 0 0 51.2-409.6 0 0-51.2Z" fill="#666666" ></path></symbol><symbol id="edui-for-imageright" viewBox="0 0 1024 1024"><path d="M0 0h1024v64H0z" fill="#666666" ></path><path d="M512 192l512 0 0 640-512 0 0-640Z" fill="#66BBBF" ></path><path d="M0 768h448v64H0zM0 960h1024v64H0zM0 576h448v64H0zM0 384h448v64H0zM0 192h448v64H0z" fill="#666666" ></path></symbol><symbol id="edui-for-insertcol" viewBox="0 0 1024 1024"><path d="M256 256L0 512l256 256V256zM1024 1024V0H384v1024zM768 64h192v256h-192z m0 320h192v256h-192z m0 320h192v256h-192zM448 64h192v256H448z m0 320h192v256H448z m0 320h192v256H448z" fill="#666666" ></path></symbol><symbol id="edui-for-insertcolnext" viewBox="0 0 1024 1024"><path d="M768 768l256-256-256-256v512zM0 0v1024h640V0z m256 960H64v-256h192z m0-320H64V384h192z m0-320H64V64h192z m320 640H384v-256h192z m0-320H384V384h192z m0-320H384V64h192z" fill="#666666" ></path></symbol><symbol id="edui-for-insertorderedlist" viewBox="0 0 1024 1024"><path d="M319.955606 63.991121l703.902334 0 0 127.982243-703.902334 0 0-127.982243Z" fill="#666666" ></path><path d="M319.955606 447.937849l703.902334 0 0 127.982242-703.902334 0 0-127.982242Z" fill="#666666" ></path><path d="M319.955606 831.884576l703.902334 0 0 127.982242-703.902334 0 0-127.982242Z" fill="#666666" ></path><path d="M191.973364 0v255.964485H63.991121V0zM0 639.911212v-30.715738C0 505.529858 159.977803 467.775096 159.977803 422.3414c0-17.917514-10.878491-28.156093-33.275383-28.156093a114.544107 114.544107 0 0 0-74.229701 37.11485l-46.713518-54.392453a167.656738 167.656738 0 0 1 127.982242-56.952098C212.450522 319.955606 255.964485 362.189746 255.964485 417.22211c0 78.069168-95.346771 98.546327-142.7002 147.179579H255.964485V639.911212zM127.982242 1023.85794a165.737004 165.737004 0 0 1-127.982242-52.47272l48.633252-49.273163a106.865172 106.865172 0 0 0 69.750322 30.075827c28.156093 0 41.594229-14.078047 41.594229-33.275383 0-17.277603-12.158313-26.23636-36.474939-26.23636h-24.316626v-52.472719h24.956537c23.036804 0 36.474939-6.399112 36.474939-26.876271 0-19.837248-12.798224-31.355649-38.394672-31.35565a85.748102 85.748102 0 0 0-63.991122 31.35565l-47.993341-48.633252a158.058069 158.058069 0 0 1 127.982243-55.032365C211.1707 703.902334 255.964485 745.496562 255.964485 792.210081v5.11929a63.991121 63.991121 0 0 1-67.830589 63.991121c50.552986 7.039023 70.390233 33.275383 70.390234 67.190677v3.839467C255.964485 985.463267 204.131677 1023.85794 127.982242 1023.85794z" fill="#666666" ></path></symbol><symbol id="edui-for-insertparagraphbeforetable" viewBox="0 0 1024 1024"><path d="M256 384v640h768V384z m256 576H320V448h192z m448 0H576v-128h384z m0-192H576v-128h384z m0-192H576V448h384z" fill="#666666" ></path><path d="M384 576h64v256H384zM0 0v64h128v384h64V64h128V0H0z" fill="#666666" ></path></symbol><symbol id="edui-for-insertrow" viewBox="0 0 1024 1024"><path d="M768 256L512 0 256 256h512zM0 1024h1024V384H0z m960-256v192h-256v-192z m-320 0v192H384v-192z m-320 0v192H64v-192z m640-320v192h-256V448z m-320 0v192H384V448zM320 448v192H64V448z" fill="#666666" ></path></symbol><symbol id="edui-for-insertrownext" viewBox="0 0 1024 1024"><path d="M256 768l256 256 256-256H256zM1024 0H0v640h1024zM64 256V64h256v192z m320 0V64h256v192z m320 0V64h256v192zM64 576V384h256v192z m320 0V384h256v192z m320 0V384h256v192z" fill="#666666" ></path></symbol><symbol id="edui-for-insertunorderedlist" viewBox="0 0 1024 1024"><path d="M960 192H256c-38.4 0-64-25.6-64-64s25.6-64 64-64h704c38.4 0 64 25.6 64 64s-25.6 64-64 64zM64 192c-38.4 0-64-25.6-64-64s25.6-64 64-64 64 25.6 64 64-25.6 64-64 64zM960 576H256c-38.4 0-64-25.6-64-64s25.6-64 64-64h704c38.4 0 64 25.6 64 64s-25.6 64-64 64zM64 576c-38.4 0-64-25.6-64-64s25.6-64 64-64 64 25.6 64 64-25.6 64-64 64zM960 960H256c-38.4 0-64-25.6-64-64s25.6-64 64-64h704c38.4 0 64 25.6 64 64s-25.6 64-64 64zM64 960c-38.4 0-64-25.6-64-64s25.6-64 64-64 64 25.6 64 64-25.6 64-64 64z" fill="#666666" ></path></symbol><symbol id="edui-for-mergeright" viewBox="0 0 1024 1024"><path d="M0 0v1024h1024V0z m384 64h256v256H384z m0 384h320V384l192 128-192 128V576H384z m-64 512H64v-256h256z m0-320H64V384h256z m0-320H64V64h256z m320 640H384v-256h256z m320 0h-256v-256h256z m0-640h-256V64h256z" fill="#666666" ></path></symbol><symbol id="edui-for-mergedown" viewBox="0 0 1024 1024"><path d="M0 0v1024h1024V0z m320 960H64v-256h256z m0-320H64V384h256z m0-320H64V64h256z m192 576l-128-192h64V384h128v320h64z m128-576H384V64h256z m320 640h-256v-256h256z m0-320h-256V384h256z m0-320h-256V64h256z" fill="#666666" ></path></symbol><symbol id="edui-for-inserttable" viewBox="0 0 1024 1024"><path d="M0 0v1024h1024V0z m320 960H64v-256h256z m0-320H64V384h256z m320 320H384v-256h256z m0-320H384V384h256z m320 320h-256v-256h256z m0-320h-256V384h256z m0-320H64V64h896z" fill="#666666" ></path></symbol><symbol id="edui-for-pagebreak" viewBox="0 0 1024 1024"><path d="M384 960h512v64H384zM0 320v384l256-192-256-192zM320 128h576v64H320zM384 832h256v64H384z" fill="#666666" ></path><path d="M192 704v320h64v-256h704v256h64v-320H192zM1022.72 0H960v256H256V0H192v320h832V0h-1.28z" fill="#666666" ></path></symbol><symbol id="edui-for-source" viewBox="0 0 1024 1024"><path d="M170.88 512H56.96V384H0v320h56.96V576h113.92v128h56.96V384h-56.96v128zM284.16 448h56.96v256h56.96V448h56.96V384H284.16v64zM738.56 385.28l-84.48 250.24L569.6 384l-2.56 1.28H512v316.8h56.96V561.92l47.36 140.8h72.96l2.56 1.28 48-140.8v139.52h56.32V385.92h-55.04l-2.56-0.64zM910.08 640V384h-56.96v320H1024v-64h-113.92z" fill="#666666" ></path></symbol><symbol id="edui-for-splittorows" viewBox="0 0 1024 1024"><path d="M0 0h1024v64H0z" fill="#666666" ></path><path d="M960 0v320h-128V0h-64v320H256V0H192v320H64V0H0v1024h1024V0z m-192 384v256H256V384zM64 384h128v256H64z m0 576v-256h128v256z m192 0v-256h512v256z m704 0h-128v-256h128z m0-320h-128V384h128z" fill="#666666" ></path></symbol><symbol id="edui-for-splittocols" viewBox="0 0 1024 1024"><path d="M1024 0H0v1024h1024z m-64 384v256h-128V384z m0-320v256h-128V64zM64 320V64h128v256z m0 320V384h128v256z m0 320v-256h128v256z m192 0V64h128v896z m192 0V64h128v896z m192 0V64h128v896z m192 0v-256h128v256z" fill="#666666" ></path></symbol><symbol id="edui-for-splittocells" viewBox="0 0 1024 1024"><path d="M0 0v1024h1024V0z m320 960H64V384h256z m320 0H384v-256h256z m0-320H384V384h256z m320 320h-256v-256h256z m0-320h-256V384h256z m0-320H384V64h576z" fill="#666666" ></path></symbol><symbol id="edui-for-arrow" viewBox="0 0 1024 1024"><path d="M513.024 665.6l204.8-204.8h-409.6l204.8 204.8z" fill="" ></path></symbol><symbol id="edui-for-aligntd" viewBox="0 0 1024 1024"><path d="M256.061265 767.939055l511.87747 0 0 63.984683-511.87747 0 0-63.984683Z" fill="#666666" ></path><path d="M256.061265 575.985004l511.87747 0 0 63.984683-511.87747 0 0-63.984683Z" fill="#666666" ></path><path d="M256.061265 384.030953l511.87747 0 0 63.984683-511.87747 0 0-63.984683Z" fill="#666666" ></path><path d="M256.061265 192.076902l511.87747 0 0 63.984683-511.87747 0 0-63.984683Z" fill="#666666" ></path><path d="M863.91576 1023.877789h-703.83152A91.498098 91.498098 0 0 1 64.107214 938.77816V85.22248A91.498098 91.498098 0 0 1 160.08424 0.122851h703.83152A91.498098 91.498098 0 0 1 959.892786 85.22248v853.55568A91.498098 91.498098 0 0 1 863.91576 1023.877789zM160.08424 64.107534a30.072801 30.072801 0 0 0-31.992342 28.153261v839.47905a30.072801 30.072801 0 0 0 31.992342 28.153261h703.83152a30.072801 30.072801 0 0 0 31.992342-28.153261V92.260795a30.072801 30.072801 0 0 0-31.992342-28.153261z" fill="#666666" ></path></symbol><symbol id="edui-for-autotypeset" viewBox="0 0 1024 1024"><path d="M192 192l384 0 0 320-384 0 0-320Z" fill="#66BBBF" ></path><path d="M640 192l192 0 0 64-192 0 0-64Z" fill="#666666" ></path><path d="M640 384l192 0 0 64-192 0 0-64Z" fill="#666666" ></path><path d="M192 576l640 0 0 64-640 0 0-64Z" fill="#666666" ></path><path d="M192 768l640 0 0 64-640 0 0-64Z" fill="#666666" ></path><path d="M960 0H64a64 64 0 0 0-64 64v896a64 64 0 0 0 64 64h896a64 64 0 0 0 64-64V64a64 64 0 0 0-64-64z m0 896a64 64 0 0 1-64 64H128a64 64 0 0 1-64-64V128a64 64 0 0 1 64-64h768a64 64 0 0 1 64 64z" fill="#666666" ></path></symbol><symbol id="edui-for-charts" viewBox="0 0 1024 1024"><path d="M0 64v896h1024V64z m960 832H64V128h896z" fill="#666666" ></path><path d="M704 256h128v512h-128zM448 576h128v192H448zM192 384h128v384H192z" fill="#666666" ></path></symbol><symbol id="edui-for-closeerror" viewBox="0 0 1024 1024"><path d="M512 0a512 512 0 1 0 512 512 512 512 0 0 0-512-512z m284.16 670.08l-128 128L512 640l-158.08 156.16-128-128L384 512 227.84 353.92l128-128L512 384l158.08-158.08 128 128L640 512z" fill="#EF4848" ></path></symbol><symbol id="edui-for-copy" viewBox="0 0 1024 1024"><path d="M256.060306 384.030473l511.879388 0 0 63.984923-511.879388 0 0-63.984923Z" fill="#666666" ></path><path d="M256.060306 575.985243l511.879388 0 0 63.984924-511.879388 0 0-63.984924Z" fill="#666666" ></path><path d="M256.060306 767.940014l511.879388 0 0 63.984924-511.879388 0 0-63.984924Z" fill="#666666" ></path><path d="M256.060306 192.075702l255.939694 0 0 63.984924-255.939694 0 0-63.984924Z" fill="#666666" ></path><path d="M895.909541 256.060626h-191.95477V56.427664A63.984924 63.984924 0 0 0 639.969847 0.120932H137.688197A69.743567 69.743567 0 0 0 64.105535 64.105855v895.78893a69.743567 69.743567 0 0 0 73.582662 63.984923h748.623606A69.743567 69.743567 0 0 0 959.894465 959.894785V313.007208A63.984924 63.984924 0 0 0 895.909541 256.060626z m0 695.516119a8.31804 8.31804 0 0 1-8.31804 8.31804H137.688197a9.597739 9.597739 0 0 1-9.597738-9.597739V72.423895A8.31804 8.31804 0 0 1 136.408499 64.105855h491.404213a11.517286 11.517286 0 0 1 12.157135 10.877437v191.954771A60.145828 60.145828 0 0 0 703.954771 320.045549h180.437484a11.517286 11.517286 0 0 1 12.157136 10.877437v620.653759z" fill="#666666" ></path></symbol><symbol id="edui-for-date" viewBox="0 0 1024 1024"><path d="M896 128v64h64v704H64V192h64V128H0v832h1024V128h-128z" fill="#666666" ></path><path d="M832 64h-192v255.36L832 320V64z" fill="#EF4848" ></path><path d="M576 704h256v64H576zM576 512h256v64H576zM448 128h128v64H448zM192 704h256v64H192zM192 512h256v64H192z" fill="#666666" ></path><path d="M384 64H192v256l192-0.64V64z" fill="#EF4848" ></path></symbol><symbol id="edui-for-deletetable" viewBox="0 0 1024 1024"><path d="M576 0v448h448V0z m427.52 337.28l-90.24 90.24-113.28-113.28-113.28 113.28-90.24-90.24 113.28-113.28-113.28-113.28L686.72 20.48l113.28 113.28L913.28 20.48l90.88 90.88-113.92 112.64z" fill="#EF4848" ></path><path d="M960 640h-256V448h-64v192H384V384h192V320H64V64h512V0H0v1024h1024V448h-64zM320 960H64v-256h256z m0-320H64V384h256z m320 320H384v-256h256z m320 0h-256v-256h256z" fill="#666666" ></path></symbol><symbol id="edui-for-directionalityltr" viewBox="0 0 1024 1024"><path d="M64 832l384-320-384-320v640zM960 192V128H512v64h192v640H512v64h448v-64h-192V192h192z" fill="#666666" ></path></symbol><symbol id="edui-for-arrowright" viewBox="0 0 1024 1024"><path d="M615.424 512l-204.8-204.8v409.6l204.8-204.8z" fill="" ></path></symbol><symbol id="edui-for-tableleft" viewBox="0 0 1024 1024"><path d="M960 64v896H64V64h896m64-64H0v1024h1024V0z" fill="" ></path><path d="M192 192h640v64H192zM192 384h640v64H192zM192 576h256v64H192z" fill="" ></path></symbol><symbol id="edui-for-tableright" viewBox="0 0 1024 1024"><path d="M960 64v896H64V64h896m64-64H0v1024h1024V0z" fill="" ></path><path d="M188.8 191.36h640v64h-640zM188.8 383.36h640v64h-640zM576 575.36h256v64H576z" fill="" ></path></symbol><symbol id="edui-for-tablecenter" viewBox="0 0 1024 1024"><path d="M960 64v896H64V64h896m64-64H0v1024h1024V0z" fill="" ></path><path d="M188.8 192.64h640v64h-640zM188.8 384.64h640v64h-640zM383.36 576.64h256v64h-256z" fill="" ></path></symbol><symbol id="edui-for-videoleft" viewBox="0 0 1024 1024"><path d="M96 96l832 0 0 32-832 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 192l832 0 0 32-832 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 800l832 0 0 32-832 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 896l399.36 0 0 32-399.36 0 0-32Z" fill="#3FBEE0" ></path><path d="M704 704l224 0 0 32-224 0 0-32Z" fill="#3FBEE0" ></path><path d="M704 608l224 0 0 32-224 0 0-32Z" fill="#3FBEE0" ></path><path d="M704 512l224 0 0 32-224 0 0-32Z" fill="#3FBEE0" ></path><path d="M704 416l224 0 0 32-224 0 0-32Z" fill="#3FBEE0" ></path><path d="M704 320l224 0 0 32-224 0 0-32Z" fill="#3FBEE0" ></path><path d="M256 480m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0Z" fill="#3FBEE0" ></path><path d="M640 320H128a32 32 0 0 0-32 32v352a32 32 0 0 0 32 32h512a32 32 0 0 0 32-32V352a32 32 0 0 0-32-32z m0 251.52L544 448l-162.24 208.64L304 563.2 186.56 704H160a32 32 0 0 1-32-32v-288a32 32 0 0 1 32-32h448a32 32 0 0 1 32 32z" fill="#3FBEE0" ></path><path d="M992 32v960H32V32h960m0-32H32a32 32 0 0 0-32 32v960a32 32 0 0 0 32 32h960a32 32 0 0 0 32-32V32a32 32 0 0 0-32-32z" fill="#3FBEE0" ></path></symbol><symbol id="edui-for-videocenter" viewBox="0 0 1024 1024"><path d="M96 96l832 0 0 32-832 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 192l832 0 0 32-832 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 800l832 0 0 32-832 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 896l399.36 0 0 32-399.36 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 704l96 0 0 32-96 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 608l96 0 0 32-96 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 512l96 0 0 32-96 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 416l96 0 0 32-96 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 320l96 0 0 32-96 0 0-32Z" fill="#3FBEE0" ></path><path d="M832 608l96 0 0 32-96 0 0-32Z" fill="#3FBEE0" ></path><path d="M832 704l96 0 0 32-96 0 0-32Z" fill="#3FBEE0" ></path><path d="M832 512l96 0 0 32-96 0 0-32Z" fill="#3FBEE0" ></path><path d="M832 416l96 0 0 32-96 0 0-32Z" fill="#3FBEE0" ></path><path d="M832 320l96 0 0 32-96 0 0-32Z" fill="#3FBEE0" ></path><path d="M384 480m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0Z" fill="#3FBEE0" ></path><path d="M768 320H256a32 32 0 0 0-32 32v352a32 32 0 0 0 32 32h512a32 32 0 0 0 32-32V352a32 32 0 0 0-32-32z m0 251.52L672 448l-162.24 208.64-77.76-93.44L314.56 704H288a32 32 0 0 1-32-32v-288a32 32 0 0 1 32-32h448a32 32 0 0 1 32 32z" fill="#3FBEE0" ></path><path d="M992 32v960H32V32h960m0-32H32a32 32 0 0 0-32 32v960a32 32 0 0 0 32 32h960a32 32 0 0 0 32-32V32a32 32 0 0 0-32-32z" fill="#3FBEE0" ></path></symbol><symbol id="edui-for-videonone" viewBox="0 0 1024 1024"><path d="M96 96l832 0 0 32-832 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 192l832 0 0 32-832 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 800l832 0 0 32-832 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 896l399.36 0 0 32-399.36 0 0-32Z" fill="#3FBEE0" ></path><path d="M704 704l224 0 0 32-224 0 0-32Z" fill="#3FBEE0" ></path><path d="M704 608l224 0 0 32-224 0 0-32Z" fill="#3FBEE0" ></path><path d="M256 480m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0Z" fill="#3FBEE0" ></path><path d="M640 320H128a32 32 0 0 0-32 32v352a32 32 0 0 0 32 32h512a32 32 0 0 0 32-32V352a32 32 0 0 0-32-32z m0 251.52L544 448l-162.24 208.64L304 563.2 186.56 704H160a32 32 0 0 1-32-32v-288a32 32 0 0 1 32-32h448a32 32 0 0 1 32 32z" fill="#3FBEE0" ></path><path d="M992 32v960H32V32h960m0-32H32a32 32 0 0 0-32 32v960a32 32 0 0 0 32 32h960a32 32 0 0 0 32-32V32a32 32 0 0 0-32-32z" fill="#3FBEE0" ></path></symbol><symbol id="edui-for-videoright" viewBox="0 0 1024 1024"><path d="M96 96l832 0 0 32-832 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 192l832 0 0 32-832 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 800l832 0 0 32-832 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 896l399.36 0 0 32-399.36 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 704l224 0 0 32-224 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 608l224 0 0 32-224 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 512l224 0 0 32-224 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 416l224 0 0 32-224 0 0-32Z" fill="#3FBEE0" ></path><path d="M96 320l224 0 0 32-224 0 0-32Z" fill="#3FBEE0" ></path><path d="M512 480m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0Z" fill="#3FBEE0" ></path><path d="M896 320H384a32 32 0 0 0-32 32v352a32 32 0 0 0 32 32h512a32 32 0 0 0 32-32V352a32 32 0 0 0-32-32z m0 251.52L800 448l-162.24 208.64-77.76-93.44-117.44 140.8H416a32 32 0 0 1-32-32v-288a32 32 0 0 1 32-32h448a32 32 0 0 1 32 32z" fill="#3FBEE0" ></path><path d="M992 32v960H32V32h960m0-32H32a32 32 0 0 0-32 32v960a32 32 0 0 0 32 32h960a32 32 0 0 0 32-32V32a32 32 0 0 0-32-32z" fill="#3FBEE0" ></path></symbol><symbol id="edui-for-template" viewBox="0 0 1024 1024"><path d="M0 64v896h1024V64z m960 832H64V128h896z" fill="#666666" ></path><path d="M192 256h320v192H192zM640 256h192v512h-192zM192 576h320v192H192z" fill="#666666" ></path></symbol><symbol id="edui-for-addfile" viewBox="0 0 1024 1024"><path d="M1024 480H544V0h-64v480H0v64h480v480h64V544h480v-64z" fill="#E5E5E5" ></path></symbol><symbol id="edui-for-selected" viewBox="0 0 1024 1024"><path d="M914.24 617.28a32 32 0 0 0-45.12 0l-221.44 221.12-112.96-112.96a32 32 0 1 0-45.12 45.12l135.68 135.68a32 32 0 0 0 45.44 0l243.52-243.52a32 32 0 0 0 0-45.44z" fill="#FFFFFF" ></path><path d="M0 1024h1024V0z m914.24-361.28L672 906.24a32 32 0 0 1-45.44 0l-135.68-135.68a32 32 0 1 1 45.12-45.12l112.96 112.96 221.12-221.12a32 32 0 1 1 45.12 45.12z" fill="#1094FA" ></path></symbol><symbol id="edui-for-pickarea" viewBox="0 0 1024 1024"><path d="M977.454545 93.090909h-46.545454v791.272727a46.545455 46.545455 0 0 1-46.545455 46.545455H93.090909v46.545454a46.545455 46.545455 0 0 0 46.545455 46.545455h837.818181a46.545455 46.545455 0 0 0 46.545455-46.545455V139.636364a46.545455 46.545455 0 0 0-46.545455-46.545455z" fill="#E5E5E5" ></path><path d="M46.545455 46.545455l837.818181 0 0 837.818181-837.818181 0 0-837.818181Z" fill="#FFFFFF" ></path><path d="M884.363636 0H46.545455a46.545455 46.545455 0 0 0-46.545455 46.545455v837.818181a46.545455 46.545455 0 0 0 46.545455 46.545455h837.818181a46.545455 46.545455 0 0 0 46.545455-46.545455V46.545455a46.545455 46.545455 0 0 0-46.545455-46.545455z m0 837.818182a46.545455 46.545455 0 0 1-46.545454 46.545454H93.090909a46.545455 46.545455 0 0 1-46.545454-46.545454V93.090909a46.545455 46.545455 0 0 1 46.545454-46.545454h744.727273a46.545455 46.545455 0 0 1 46.545454 46.545454z" fill="#CCCCCC" ></path></symbol><symbol id="edui-for-overlay" viewBox="0 0 1024 1024"><path d="M977.454545 93.090909h-46.545454v791.272727a46.545455 46.545455 0 0 1-46.545455 46.545455H93.090909v46.545454a46.545455 46.545455 0 0 0 46.545455 46.545455h837.818181a46.545455 46.545455 0 0 0 46.545455-46.545455V139.636364a46.545455 46.545455 0 0 0-46.545455-46.545455z" fill="#E3F6FF" ></path><path d="M46.545455 46.545455l837.818181 0 0 837.818181-837.818181 0 0-837.818181Z" fill="#E3F6FF" ></path><path d="M884.363636 0H46.545455a46.545455 46.545455 0 0 0-46.545455 46.545455v837.818181a46.545455 46.545455 0 0 0 46.545455 46.545455h837.818181a46.545455 46.545455 0 0 0 46.545455-46.545455V46.545455a46.545455 46.545455 0 0 0-46.545455-46.545455z m0 837.818182a46.545455 46.545455 0 0 1-46.545454 46.545454H93.090909a46.545455 46.545455 0 0 1-46.545454-46.545454V93.090909a46.545455 46.545455 0 0 1 46.545454-46.545454h744.727273a46.545455 46.545455 0 0 1 46.545454 46.545454z" fill="#45A7EF" ></path></symbol><symbol id="edui-for-preitem" viewBox="0 0 1462 1024"><path d="M0 0v1024h1462.857143V0z m1433.6 994.742857H29.257143V29.257143h1404.342857z" fill="#CCCCCC" ></path><path d="M175.542857 131.657143h497.371429v58.514286H175.542857zM175.542857 512h438.857143v29.257143H175.542857zM175.542857 394.971429h906.971429v29.257142H175.542857zM175.542857 277.942857h234.057143v29.257143H175.542857zM175.542857 629.028571h1111.771429v29.257143H175.542857zM175.542857 746.057143h292.571429v29.257143H175.542857zM175.542857 863.085714h760.685714v29.257143H175.542857z" fill="#666666" ></path></symbol><symbol id="edui-for-preitem1" viewBox="0 0 1462 1024"><path d="M0 0v1024h1462.857143V0z m1433.6 994.742857H29.257143V29.257143h1404.342857z" fill="#CCCCCC" ></path><path d="M117.028571 175.542857h351.085715v29.257143H117.028571z" fill="#666666" ></path></symbol><symbol id="edui-for-preitem2" viewBox="0 0 1462 1024"><path d="M0 0v1024h1462.857143V0z m1433.6 994.742857H29.257143V29.257143h1404.342857z" fill="#CCCCCC" ></path><path d="M175.542857 117.028571h497.371429v58.514286H175.542857zM848.457143 555.885714h438.857143v29.257143H848.457143zM848.457143 438.857143h438.857143v29.257143H848.457143zM848.457143 321.828571h438.857143v29.257143H848.457143zM175.542857 672.914286h1111.771429v29.257143H175.542857zM175.542857 789.942857h702.171429v29.257143H175.542857zM175.542857 906.971429h702.171429v29.257142H175.542857zM731.428571 351.085714v204.8H204.8V351.085714h526.628571m29.257143-29.257143H175.542857v263.314286h585.142857V321.828571zM1258.057143 789.942857v117.028572H994.742857v-117.028572h263.314286m29.257143-29.257143H965.485714v175.542857h321.828572V760.685714z" fill="#666666" ></path></symbol><symbol id="edui-for-preitem3" viewBox="0 0 1462 1024"><path d="M0 0v1024h1462.857143V0z m1433.6 994.742857H29.257143V29.257143h1404.342857z" fill="#CCCCCC" ></path><path d="M482.742857 175.542857h497.371429v58.514286H482.742857zM643.657143 292.571429h175.542857v29.257142H643.657143zM175.542857 468.114286h1111.771429v29.257143H175.542857zM175.542857 585.142857h1111.771429v29.257143H175.542857zM175.542857 702.171429h1111.771429v29.257142H175.542857zM175.542857 819.2h1111.771429v29.257143H175.542857z" fill="#666666" ></path></symbol><symbol id="edui-for-preitem4" viewBox="0 0 1462 1024"><path d="M1258.057143 263.314286v204.8H204.8V263.314286h1053.257143m29.257143-29.257143H175.542857v263.314286h1111.771429V234.057143z" fill="#666666" ></path><path d="M0 0v1024h1462.857143V0z m1433.6 994.742857H29.257143V29.257143h1404.342857z" fill="#CCCCCC" ></path><path d="M175.542857 117.028571h497.371429v58.514286H175.542857zM175.542857 555.885714h351.085714v29.257143H175.542857zM175.542857 672.914286h1111.771429v29.257143H175.542857zM175.542857 789.942857h702.171429v29.257143H175.542857zM175.542857 906.971429h1111.771429v29.257142H175.542857z" fill="#666666" ></path></symbol></svg>',l=(h=document.getElementsByTagName("script"))[h.length-1].getAttribute("data-injectcss");if(l&&!o.__iconfont__svg__cssinject__){o.__iconfont__svg__cssinject__=!0;try{document.write("<style>.svgfont {display: inline-block;width: 1em;height: 1em;fill: currentColor;vertical-align: -0.1em;font-size:16px;}</style>")}catch(h){console&&console.log(h)}}!function(h){if(document.addEventListener)if(~["complete","loaded","interactive"].indexOf(document.readyState))setTimeout(h,0);else{var l=function(){document.removeEventListener("DOMContentLoaded",l,!1),h()};document.addEventListener("DOMContentLoaded",l,!1)}else document.attachEvent&&(a=h,t=o.document,i=!1,v=function(){i||(i=!0,a())},(p=function(){try{t.documentElement.doScroll("left")}catch(h){return void setTimeout(p,50)}v()})(),t.onreadystatechange=function(){"complete"==t.readyState&&(t.onreadystatechange=null,v())});var a,t,i,v,p}(function(){var h,l,a,t,i,v;(h=document.createElement("div")).innerHTML=p,p=null,(l=h.getElementsByTagName("svg")[0])&&(l.setAttribute("aria-hidden","true"),l.style.position="absolute",l.style.width=0,l.style.height=0,l.style.overflow="hidden",a=l,(t=document.body).firstChild?(i=a,(v=t.firstChild).parentNode.insertBefore(i,v)):t.appendChild(a))})}(window);
  29350. // adapter/editorui.js
  29351. //ui跟编辑器的适配層
  29352. //那个按钮弹出是dialog,是下拉筐等都是在这个js中配置
  29353. //自己写的ui也要在这里配置,放到baidu.editor.ui下边,当编辑器实例化的时候会根据neditor.config中的toolbars找到相应的进行实例化
  29354. ;(function() {
  29355. var utils = baidu.editor.utils;
  29356. var editorui = baidu.editor.ui;
  29357. var _Dialog = editorui.Dialog;
  29358. editorui.buttons = {};
  29359. editorui.Dialog = function(options) {
  29360. var dialog = new _Dialog(options);
  29361. dialog.addListener("hide", function() {
  29362. if (dialog.editor) {
  29363. var editor = dialog.editor;
  29364. try {
  29365. if (browser.gecko) {
  29366. var y = editor.window.scrollY,
  29367. x = editor.window.scrollX;
  29368. editor.body.focus();
  29369. editor.window.scrollTo(x, y);
  29370. } else {
  29371. editor.focus();
  29372. }
  29373. } catch (ex) {}
  29374. }
  29375. });
  29376. return dialog;
  29377. };
  29378. var iframeUrlMap = {
  29379. anchor: "~/dialogs/anchor/anchor.html",
  29380. insertimage: "~/dialogs/image/image.html",
  29381. link: "~/dialogs/link/link.html",
  29382. spechars: "~/dialogs/spechars/spechars.html",
  29383. searchreplace: "~/dialogs/searchreplace/searchreplace.html",
  29384. map: "~/dialogs/map/map.html",
  29385. gmap: "~/dialogs/gmap/gmap.html",
  29386. insertvideo: "~/dialogs/video/video.html",
  29387. help: "~/dialogs/help/help.html",
  29388. preview: "~/dialogs/preview/preview.html",
  29389. emotion: "~/dialogs/emotion/emotion.html",
  29390. wordimage: "~/dialogs/wordimage/wordimage.html",
  29391. attachment: "~/dialogs/attachment/attachment.html",
  29392. insertframe: "~/dialogs/insertframe/insertframe.html",
  29393. edittip: "~/dialogs/table/edittip.html",
  29394. edittable: "~/dialogs/table/edittable.html",
  29395. edittd: "~/dialogs/table/edittd.html",
  29396. webapp: "~/dialogs/webapp/webapp.html",
  29397. snapscreen: "~/dialogs/snapscreen/snapscreen.html",
  29398. scrawl: "~/dialogs/scrawl/scrawl.html",
  29399. music: "~/dialogs/music/music.html",
  29400. template: "~/dialogs/template/template.html",
  29401. background: "~/dialogs/background/background.html",
  29402. charts: "~/dialogs/charts/charts.html"
  29403. };
  29404. //为工具栏添加按钮,以下都是统一的按钮触发命令,所以写在一起
  29405. var btnCmds = [
  29406. "undo",
  29407. "redo",
  29408. "formatmatch",
  29409. "bold",
  29410. "italic",
  29411. "underline",
  29412. "fontborder",
  29413. "touppercase",
  29414. "tolowercase",
  29415. "strikethrough",
  29416. "subscript",
  29417. "superscript",
  29418. "source",
  29419. "indent",
  29420. "outdent",
  29421. "blockquote",
  29422. "pasteplain",
  29423. "pagebreak",
  29424. "selectall",
  29425. "print",
  29426. "horizontal",
  29427. "removeformat",
  29428. "time",
  29429. "date",
  29430. "unlink",
  29431. "insertparagraphbeforetable",
  29432. "insertrow",
  29433. "insertcol",
  29434. "mergeright",
  29435. "mergedown",
  29436. "deleterow",
  29437. "deletecol",
  29438. "splittorows",
  29439. "splittocols",
  29440. "splittocells",
  29441. "mergecells",
  29442. "deletetable",
  29443. "drafts"
  29444. ];
  29445. for (var i = 0, ci; (ci = btnCmds[i++]); ) {
  29446. ci = ci.toLowerCase();
  29447. editorui[ci] = (function(cmd) {
  29448. return function(editor) {
  29449. var ui = new editorui.Button({
  29450. className: "edui-for-" + cmd,
  29451. title:
  29452. editor.options.labelMap[cmd] ||
  29453. editor.getLang("labelMap." + cmd) ||
  29454. "",
  29455. onclick: function() {
  29456. editor.execCommand(cmd);
  29457. },
  29458. theme: editor.options.theme,
  29459. showText: false
  29460. });
  29461. editorui.buttons[cmd] = ui;
  29462. editor.addListener("selectionchange", function(
  29463. type,
  29464. causeByUi,
  29465. uiReady
  29466. ) {
  29467. var state = editor.queryCommandState(cmd);
  29468. if (state == -1) {
  29469. ui.setDisabled(true);
  29470. ui.setChecked(false);
  29471. } else {
  29472. if (!uiReady) {
  29473. ui.setDisabled(false);
  29474. ui.setChecked(state);
  29475. }
  29476. }
  29477. });
  29478. return ui;
  29479. };
  29480. })(ci);
  29481. }
  29482. //清除文档
  29483. editorui.cleardoc = function(editor) {
  29484. var ui = new editorui.Button({
  29485. className: "edui-for-cleardoc",
  29486. title:
  29487. editor.options.labelMap.cleardoc ||
  29488. editor.getLang("labelMap.cleardoc") ||
  29489. "",
  29490. theme: editor.options.theme,
  29491. onclick: function() {
  29492. if (confirm(editor.getLang("confirmClear"))) {
  29493. editor.execCommand("cleardoc");
  29494. }
  29495. }
  29496. });
  29497. editorui.buttons["cleardoc"] = ui;
  29498. editor.addListener("selectionchange", function() {
  29499. ui.setDisabled(editor.queryCommandState("cleardoc") == -1);
  29500. });
  29501. return ui;
  29502. };
  29503. //排版,图片排版,文字方向
  29504. var typeset = {
  29505. justify: ["left", "right", "center", "justify"],
  29506. imagefloat: ["none", "left", "center", "right"],
  29507. directionality: ["ltr", "rtl"]
  29508. };
  29509. for (var p in typeset) {
  29510. (function(cmd, val) {
  29511. for (var i = 0, ci; (ci = val[i++]); ) {
  29512. (function(cmd2) {
  29513. editorui[cmd.replace("float", "") + cmd2] = function(editor) {
  29514. var ui = new editorui.Button({
  29515. className: "edui-for-" + cmd.replace("float", "") + cmd2,
  29516. title:
  29517. editor.options.labelMap[cmd.replace("float", "") + cmd2] ||
  29518. editor.getLang(
  29519. "labelMap." + cmd.replace("float", "") + cmd2
  29520. ) ||
  29521. "",
  29522. theme: editor.options.theme,
  29523. onclick: function() {
  29524. editor.execCommand(cmd, cmd2);
  29525. }
  29526. });
  29527. editorui.buttons[cmd] = ui;
  29528. editor.addListener("selectionchange", function(
  29529. type,
  29530. causeByUi,
  29531. uiReady
  29532. ) {
  29533. ui.setDisabled(editor.queryCommandState(cmd) == -1);
  29534. ui.setChecked(editor.queryCommandValue(cmd) == cmd2 && !uiReady);
  29535. });
  29536. return ui;
  29537. };
  29538. })(ci);
  29539. }
  29540. })(p, typeset[p]);
  29541. }
  29542. //字体颜色和背景颜色
  29543. for (var i = 0, ci; (ci = ["backcolor", "forecolor"][i++]); ) {
  29544. editorui[ci] = (function(cmd) {
  29545. return function(editor) {
  29546. var ui = new editorui.ColorButton({
  29547. className: "edui-for-" + cmd,
  29548. color: "default",
  29549. title:
  29550. editor.options.labelMap[cmd] ||
  29551. editor.getLang("labelMap." + cmd) ||
  29552. "",
  29553. editor: editor,
  29554. onpickcolor: function(t, color) {
  29555. editor.execCommand(cmd, color);
  29556. },
  29557. onpicknocolor: function() {
  29558. editor.execCommand(cmd, "default");
  29559. this.setColor("transparent");
  29560. this.color = "default";
  29561. },
  29562. onbuttonclick: function() {
  29563. editor.execCommand(cmd, this.color);
  29564. }
  29565. });
  29566. editorui.buttons[cmd] = ui;
  29567. editor.addListener("selectionchange", function() {
  29568. ui.setDisabled(editor.queryCommandState(cmd) == -1);
  29569. });
  29570. return ui;
  29571. };
  29572. })(ci);
  29573. }
  29574. var dialogBtns = {
  29575. noOk: ["searchreplace", "help", "spechars", "webapp", "preview"],
  29576. ok: [
  29577. "attachment",
  29578. "anchor",
  29579. "link",
  29580. "insertimage",
  29581. "map",
  29582. "gmap",
  29583. "insertframe",
  29584. "wordimage",
  29585. "insertvideo",
  29586. "insertframe",
  29587. "edittip",
  29588. "edittable",
  29589. "edittd",
  29590. "scrawl",
  29591. "template",
  29592. "music",
  29593. "background",
  29594. "charts"
  29595. ]
  29596. };
  29597. for (var p in dialogBtns) {
  29598. (function(type, vals) {
  29599. for (var i = 0, ci; (ci = vals[i++]); ) {
  29600. //todo opera下存在问题
  29601. if (browser.opera && ci === "searchreplace") {
  29602. continue;
  29603. }
  29604. (function(cmd) {
  29605. editorui[cmd] = function(editor, iframeUrl, title) {
  29606. iframeUrl =
  29607. iframeUrl ||
  29608. (editor.options.iframeUrlMap || {})[cmd] ||
  29609. iframeUrlMap[cmd];
  29610. title =
  29611. editor.options.labelMap[cmd] ||
  29612. editor.getLang("labelMap." + cmd) ||
  29613. "";
  29614. var dialog;
  29615. //没有iframeUrl不创建dialog
  29616. if (iframeUrl) {
  29617. dialog = new editorui.Dialog(
  29618. utils.extend(
  29619. {
  29620. iframeUrl: editor.ui.mapUrl(iframeUrl),
  29621. editor: editor,
  29622. className: "edui-for-" + cmd,
  29623. title: title,
  29624. holdScroll: cmd === "insertimage",
  29625. fullscreen: /charts|preview/.test(cmd),
  29626. closeDialog: editor.getLang("closeDialog")
  29627. },
  29628. type == "ok"
  29629. ? {
  29630. buttons: [
  29631. {
  29632. className: "edui-okbutton",
  29633. label: editor.getLang("ok"),
  29634. editor: editor,
  29635. onclick: function() {
  29636. dialog.close(true);
  29637. }
  29638. },
  29639. {
  29640. className: "edui-cancelbutton",
  29641. label: editor.getLang("cancel"),
  29642. editor: editor,
  29643. onclick: function() {
  29644. dialog.close(false);
  29645. }
  29646. }
  29647. ]
  29648. }
  29649. : {}
  29650. )
  29651. );
  29652. editor.ui._dialogs[cmd + "Dialog"] = dialog;
  29653. }
  29654. var ui = new editorui.Button({
  29655. className: "edui-for-" + cmd,
  29656. title: title,
  29657. onclick: function() {
  29658. if (dialog) {
  29659. switch (cmd) {
  29660. case "wordimage":
  29661. var images = editor.execCommand("wordimage");
  29662. if (images && images.length) {
  29663. dialog.render();
  29664. dialog.open();
  29665. }
  29666. break;
  29667. case "scrawl":
  29668. if (editor.queryCommandState("scrawl") != -1) {
  29669. dialog.render();
  29670. dialog.open();
  29671. }
  29672. break;
  29673. default:
  29674. dialog.render();
  29675. dialog.open();
  29676. }
  29677. }
  29678. },
  29679. theme: editor.options.theme,
  29680. disabled:
  29681. (cmd == "scrawl" && editor.queryCommandState("scrawl") == -1) ||
  29682. cmd == "charts"
  29683. });
  29684. editorui.buttons[cmd] = ui;
  29685. editor.addListener("selectionchange", function() {
  29686. //只存在于右键菜单而无工具栏按钮的ui不需要检测状态
  29687. var unNeedCheckState = { edittable: 1 };
  29688. if (cmd in unNeedCheckState) return;
  29689. var state = editor.queryCommandState(cmd);
  29690. if (ui.getDom()) {
  29691. ui.setDisabled(state == -1);
  29692. ui.setChecked(state);
  29693. }
  29694. });
  29695. return ui;
  29696. };
  29697. })(ci.toLowerCase());
  29698. }
  29699. })(p, dialogBtns[p]);
  29700. }
  29701. editorui.snapscreen = function(editor, iframeUrl, title) {
  29702. title =
  29703. editor.options.labelMap["snapscreen"] ||
  29704. editor.getLang("labelMap.snapscreen") ||
  29705. "";
  29706. var ui = new editorui.Button({
  29707. className: "edui-for-snapscreen",
  29708. title: title,
  29709. onclick: function() {
  29710. editor.execCommand("snapscreen");
  29711. },
  29712. theme: editor.options.theme
  29713. });
  29714. editorui.buttons["snapscreen"] = ui;
  29715. iframeUrl =
  29716. iframeUrl ||
  29717. (editor.options.iframeUrlMap || {})["snapscreen"] ||
  29718. iframeUrlMap["snapscreen"];
  29719. if (iframeUrl) {
  29720. var dialog = new editorui.Dialog({
  29721. iframeUrl: editor.ui.mapUrl(iframeUrl),
  29722. editor: editor,
  29723. className: "edui-for-snapscreen",
  29724. title: title,
  29725. buttons: [
  29726. {
  29727. className: "edui-okbutton",
  29728. label: editor.getLang("ok"),
  29729. editor: editor,
  29730. onclick: function() {
  29731. dialog.close(true);
  29732. }
  29733. },
  29734. {
  29735. className: "edui-cancelbutton",
  29736. label: editor.getLang("cancel"),
  29737. editor: editor,
  29738. onclick: function() {
  29739. dialog.close(false);
  29740. }
  29741. }
  29742. ]
  29743. });
  29744. dialog.render();
  29745. editor.ui._dialogs["snapscreenDialog"] = dialog;
  29746. }
  29747. editor.addListener("selectionchange", function() {
  29748. ui.setDisabled(editor.queryCommandState("snapscreen") == -1);
  29749. });
  29750. return ui;
  29751. };
  29752. editorui.insertcode = function(editor, list, title) {
  29753. list = editor.options["insertcode"] || [];
  29754. title =
  29755. editor.options.labelMap["insertcode"] ||
  29756. editor.getLang("labelMap.insertcode") ||
  29757. "";
  29758. // if (!list.length) return;
  29759. var items = [];
  29760. utils.each(list, function(key, val) {
  29761. items.push({
  29762. label: key,
  29763. value: val,
  29764. theme: editor.options.theme,
  29765. renderLabelHtml: function() {
  29766. return (
  29767. '<div class="edui-label %%-label" >' + (this.label || "") + "</div>"
  29768. );
  29769. }
  29770. });
  29771. });
  29772. var ui = new editorui.Combox({
  29773. editor: editor,
  29774. items: items,
  29775. onselect: function(t, index) {
  29776. editor.execCommand("insertcode", this.items[index].value);
  29777. },
  29778. onbuttonclick: function() {
  29779. this.showPopup();
  29780. },
  29781. title: title,
  29782. initValue: title,
  29783. className: "edui-for-insertcode",
  29784. indexByValue: function(value) {
  29785. if (value) {
  29786. for (var i = 0, ci; (ci = this.items[i]); i++) {
  29787. if (ci.value.indexOf(value) != -1) return i;
  29788. }
  29789. }
  29790. return -1;
  29791. }
  29792. });
  29793. editorui.buttons["insertcode"] = ui;
  29794. editor.addListener("selectionchange", function(type, causeByUi, uiReady) {
  29795. if (!uiReady) {
  29796. var state = editor.queryCommandState("insertcode");
  29797. if (state == -1) {
  29798. ui.setDisabled(true);
  29799. } else {
  29800. ui.setDisabled(false);
  29801. var value = editor.queryCommandValue("insertcode");
  29802. if (!value) {
  29803. ui.setValue(title);
  29804. return;
  29805. }
  29806. //trace:1871 ie下从源码模式切换回来时,字体会带单引号,而且会有逗号
  29807. value && (value = value.replace(/['"]/g, "").split(",")[0]);
  29808. ui.setValue(value);
  29809. }
  29810. }
  29811. });
  29812. return ui;
  29813. };
  29814. editorui.fontfamily = function(editor, list, title) {
  29815. list = editor.options["fontfamily"] || [];
  29816. title =
  29817. editor.options.labelMap["fontfamily"] ||
  29818. editor.getLang("labelMap.fontfamily") ||
  29819. "";
  29820. if (!list.length) return;
  29821. for (var i = 0, ci, items = []; (ci = list[i]); i++) {
  29822. var langLabel = editor.getLang("fontfamily")[ci.name] || "";
  29823. (function(key, val) {
  29824. items.push({
  29825. label: key,
  29826. value: val,
  29827. theme: editor.options.theme,
  29828. renderLabelHtml: function() {
  29829. return (
  29830. '<div class="edui-label %%-label" style="font-family:' +
  29831. utils.unhtml(this.value) +
  29832. '">' +
  29833. (this.label || "") +
  29834. "</div>"
  29835. );
  29836. }
  29837. });
  29838. })(ci.label || langLabel, ci.val);
  29839. }
  29840. var ui = new editorui.Combox({
  29841. editor: editor,
  29842. items: items,
  29843. onselect: function(t, index) {
  29844. editor.execCommand("FontFamily", this.items[index].value);
  29845. },
  29846. onbuttonclick: function() {
  29847. this.showPopup();
  29848. },
  29849. title: title,
  29850. initValue: title,
  29851. className: "edui-for-fontfamily",
  29852. indexByValue: function(value) {
  29853. if (value) {
  29854. for (var i = 0, ci; (ci = this.items[i]); i++) {
  29855. if (ci.value.indexOf(value) != -1) return i;
  29856. }
  29857. }
  29858. return -1;
  29859. }
  29860. });
  29861. editorui.buttons["fontfamily"] = ui;
  29862. editor.addListener("selectionchange", function(type, causeByUi, uiReady) {
  29863. if (!uiReady) {
  29864. var state = editor.queryCommandState("FontFamily");
  29865. if (state == -1) {
  29866. ui.setDisabled(true);
  29867. } else {
  29868. ui.setDisabled(false);
  29869. var value = editor.queryCommandValue("FontFamily");
  29870. //trace:1871 ie下从源码模式切换回来时,字体会带单引号,而且会有逗号
  29871. value && (value = value.replace(/['"]/g, "").split(",")[0]);
  29872. ui.setValue(value);
  29873. }
  29874. }
  29875. });
  29876. return ui;
  29877. };
  29878. editorui.fontsize = function(editor, list, title) {
  29879. title =
  29880. editor.options.labelMap["fontsize"] ||
  29881. editor.getLang("labelMap.fontsize") ||
  29882. "";
  29883. list = list || editor.options["fontsize"] || [];
  29884. if (!list.length) return;
  29885. var items = [];
  29886. for (var i = 0; i < list.length; i++) {
  29887. var size = list[i] + "px";
  29888. items.push({
  29889. label: size,
  29890. value: size,
  29891. theme: editor.options.theme,
  29892. renderLabelHtml: function() {
  29893. return (
  29894. '<div class="edui-label %%-label" style="line-height:1;font-size:' +
  29895. this.value +
  29896. '">' +
  29897. (this.label || "") +
  29898. "</div>"
  29899. );
  29900. }
  29901. });
  29902. }
  29903. var ui = new editorui.Combox({
  29904. editor: editor,
  29905. items: items,
  29906. title: title,
  29907. initValue: title,
  29908. onselect: function(t, index) {
  29909. editor.execCommand("FontSize", this.items[index].value);
  29910. },
  29911. onbuttonclick: function() {
  29912. this.showPopup();
  29913. },
  29914. className: "edui-for-fontsize"
  29915. });
  29916. editorui.buttons["fontsize"] = ui;
  29917. editor.addListener("selectionchange", function(type, causeByUi, uiReady) {
  29918. if (!uiReady) {
  29919. var state = editor.queryCommandState("FontSize");
  29920. if (state == -1) {
  29921. ui.setDisabled(true);
  29922. } else {
  29923. ui.setDisabled(false);
  29924. ui.setValue(editor.queryCommandValue("FontSize"));
  29925. }
  29926. }
  29927. });
  29928. return ui;
  29929. };
  29930. editorui.paragraph = function(editor, list, title) {
  29931. title =
  29932. editor.options.labelMap["paragraph"] ||
  29933. editor.getLang("labelMap.paragraph") ||
  29934. "";
  29935. list = editor.options["paragraph"] || [];
  29936. if (utils.isEmptyObject(list)) return;
  29937. var items = [];
  29938. for (var i in list) {
  29939. items.push({
  29940. value: i,
  29941. label: list[i] || editor.getLang("paragraph")[i],
  29942. theme: editor.options.theme,
  29943. renderLabelHtml: function() {
  29944. return (
  29945. '<div class="edui-label %%-label"><span class="edui-for-' +
  29946. this.value +
  29947. '">' +
  29948. (this.label || "") +
  29949. "</span></div>"
  29950. );
  29951. }
  29952. });
  29953. }
  29954. var ui = new editorui.Combox({
  29955. editor: editor,
  29956. items: items,
  29957. title: title,
  29958. initValue: title,
  29959. className: "edui-for-paragraph",
  29960. onselect: function(t, index) {
  29961. editor.execCommand("Paragraph", this.items[index].value);
  29962. },
  29963. onbuttonclick: function() {
  29964. this.showPopup();
  29965. }
  29966. });
  29967. editorui.buttons["paragraph"] = ui;
  29968. editor.addListener("selectionchange", function(type, causeByUi, uiReady) {
  29969. if (!uiReady) {
  29970. var state = editor.queryCommandState("Paragraph");
  29971. if (state == -1) {
  29972. ui.setDisabled(true);
  29973. } else {
  29974. ui.setDisabled(false);
  29975. var value = editor.queryCommandValue("Paragraph");
  29976. var index = ui.indexByValue(value);
  29977. if (index != -1) {
  29978. ui.setValue(value);
  29979. } else {
  29980. ui.setValue(ui.initValue);
  29981. }
  29982. }
  29983. }
  29984. });
  29985. return ui;
  29986. };
  29987. //自定义标题
  29988. editorui.customstyle = function(editor) {
  29989. var list = editor.options["customstyle"] || [],
  29990. title =
  29991. editor.options.labelMap["customstyle"] ||
  29992. editor.getLang("labelMap.customstyle") ||
  29993. "";
  29994. if (!list.length) return;
  29995. var langCs = editor.getLang("customstyle");
  29996. for (var i = 0, items = [], t; (t = list[i++]); ) {
  29997. (function(t) {
  29998. var ck = {};
  29999. ck.label = t.label ? t.label : langCs[t.name];
  30000. ck.style = t.style;
  30001. ck.className = t.className;
  30002. ck.tag = t.tag;
  30003. items.push({
  30004. label: ck.label,
  30005. value: ck,
  30006. theme: editor.options.theme,
  30007. renderLabelHtml: function() {
  30008. return (
  30009. '<div class="edui-label %%-label">' +
  30010. "<" +
  30011. ck.tag +
  30012. " " +
  30013. (ck.className ? ' class="' + ck.className + '"' : "") +
  30014. (ck.style ? ' style="' + ck.style + '"' : "") +
  30015. ">" +
  30016. ck.label +
  30017. "</" +
  30018. ck.tag +
  30019. ">" +
  30020. "</div>"
  30021. );
  30022. }
  30023. });
  30024. })(t);
  30025. }
  30026. var ui = new editorui.Combox({
  30027. editor: editor,
  30028. items: items,
  30029. title: title,
  30030. initValue: title,
  30031. className: "edui-for-customstyle",
  30032. onselect: function(t, index) {
  30033. editor.execCommand("customstyle", this.items[index].value);
  30034. },
  30035. onbuttonclick: function() {
  30036. this.showPopup();
  30037. },
  30038. indexByValue: function(value) {
  30039. for (var i = 0, ti; (ti = this.items[i++]); ) {
  30040. if (ti.label == value) {
  30041. return i - 1;
  30042. }
  30043. }
  30044. return -1;
  30045. }
  30046. });
  30047. editorui.buttons["customstyle"] = ui;
  30048. editor.addListener("selectionchange", function(type, causeByUi, uiReady) {
  30049. if (!uiReady) {
  30050. var state = editor.queryCommandState("customstyle");
  30051. if (state == -1) {
  30052. ui.setDisabled(true);
  30053. } else {
  30054. ui.setDisabled(false);
  30055. var value = editor.queryCommandValue("customstyle");
  30056. var index = ui.indexByValue(value);
  30057. if (index != -1) {
  30058. ui.setValue(value);
  30059. } else {
  30060. ui.setValue(ui.initValue);
  30061. }
  30062. }
  30063. }
  30064. });
  30065. return ui;
  30066. };
  30067. editorui.inserttable = function(editor, iframeUrl, title) {
  30068. title =
  30069. editor.options.labelMap["inserttable"] ||
  30070. editor.getLang("labelMap.inserttable") ||
  30071. "";
  30072. var ui = new editorui.TableButton({
  30073. editor: editor,
  30074. title: title,
  30075. className: "edui-for-inserttable",
  30076. onpicktable: function(t, numCols, numRows) {
  30077. editor.execCommand("InsertTable", {
  30078. numRows: numRows,
  30079. numCols: numCols,
  30080. border: 1
  30081. });
  30082. },
  30083. onbuttonclick: function() {
  30084. this.showPopup();
  30085. }
  30086. });
  30087. editorui.buttons["inserttable"] = ui;
  30088. editor.addListener("selectionchange", function() {
  30089. ui.setDisabled(editor.queryCommandState("inserttable") == -1);
  30090. });
  30091. return ui;
  30092. };
  30093. editorui.lineheight = function(editor) {
  30094. var val = editor.options.lineheight || [];
  30095. if (!val.length) return;
  30096. for (var i = 0, ci, items = []; (ci = val[i++]); ) {
  30097. items.push({
  30098. //todo:写死了
  30099. label: ci,
  30100. value: ci,
  30101. theme: editor.options.theme,
  30102. onclick: function() {
  30103. editor.execCommand("lineheight", this.value);
  30104. }
  30105. });
  30106. }
  30107. var ui = new editorui.MenuButton({
  30108. editor: editor,
  30109. className: "edui-for-lineheight",
  30110. title:
  30111. editor.options.labelMap["lineheight"] ||
  30112. editor.getLang("labelMap.lineheight") ||
  30113. "",
  30114. items: items,
  30115. onbuttonclick: function() {
  30116. var value = editor.queryCommandValue("LineHeight") || this.value;
  30117. editor.execCommand("LineHeight", value);
  30118. }
  30119. });
  30120. editorui.buttons["lineheight"] = ui;
  30121. editor.addListener("selectionchange", function() {
  30122. var state = editor.queryCommandState("LineHeight");
  30123. if (state == -1) {
  30124. ui.setDisabled(true);
  30125. } else {
  30126. ui.setDisabled(false);
  30127. var value = editor.queryCommandValue("LineHeight");
  30128. value && ui.setValue((value + "").replace(/cm/, ""));
  30129. ui.setChecked(state);
  30130. }
  30131. });
  30132. return ui;
  30133. };
  30134. var rowspacings = ["top", "bottom"];
  30135. for (var r = 0, ri; (ri = rowspacings[r++]); ) {
  30136. (function(cmd) {
  30137. editorui["rowspacing" + cmd] = function(editor) {
  30138. var val = editor.options["rowspacing" + cmd] || [];
  30139. if (!val.length) return null;
  30140. for (var i = 0, ci, items = []; (ci = val[i++]); ) {
  30141. items.push({
  30142. label: ci,
  30143. value: ci,
  30144. theme: editor.options.theme,
  30145. onclick: function() {
  30146. editor.execCommand("rowspacing", this.value, cmd);
  30147. }
  30148. });
  30149. }
  30150. var ui = new editorui.MenuButton({
  30151. editor: editor,
  30152. className: "edui-for-rowspacing" + cmd,
  30153. title:
  30154. editor.options.labelMap["rowspacing" + cmd] ||
  30155. editor.getLang("labelMap.rowspacing" + cmd) ||
  30156. "",
  30157. items: items,
  30158. onbuttonclick: function() {
  30159. var value =
  30160. editor.queryCommandValue("rowspacing", cmd) || this.value;
  30161. editor.execCommand("rowspacing", value, cmd);
  30162. }
  30163. });
  30164. editorui.buttons[cmd] = ui;
  30165. editor.addListener("selectionchange", function() {
  30166. var state = editor.queryCommandState("rowspacing", cmd);
  30167. if (state == -1) {
  30168. ui.setDisabled(true);
  30169. } else {
  30170. ui.setDisabled(false);
  30171. var value = editor.queryCommandValue("rowspacing", cmd);
  30172. value && ui.setValue((value + "").replace(/%/, ""));
  30173. ui.setChecked(state);
  30174. }
  30175. });
  30176. return ui;
  30177. };
  30178. })(ri);
  30179. }
  30180. //有序,无序列表
  30181. var lists = ["insertorderedlist", "insertunorderedlist"];
  30182. for (var l = 0, cl; (cl = lists[l++]); ) {
  30183. (function(cmd) {
  30184. editorui[cmd] = function(editor) {
  30185. var vals = editor.options[cmd],
  30186. _onMenuClick = function() {
  30187. editor.execCommand(cmd, this.value);
  30188. },
  30189. items = [];
  30190. for (var i in vals) {
  30191. items.push({
  30192. label: vals[i] || editor.getLang()[cmd][i] || "",
  30193. value: i,
  30194. theme: editor.options.theme,
  30195. onclick: _onMenuClick
  30196. });
  30197. }
  30198. var ui = new editorui.MenuButton({
  30199. editor: editor,
  30200. className: "edui-for-" + cmd,
  30201. title: editor.getLang("labelMap." + cmd) || "",
  30202. items: items,
  30203. onbuttonclick: function() {
  30204. var value = editor.queryCommandValue(cmd) || this.value;
  30205. editor.execCommand(cmd, value);
  30206. }
  30207. });
  30208. editorui.buttons[cmd] = ui;
  30209. editor.addListener("selectionchange", function() {
  30210. var state = editor.queryCommandState(cmd);
  30211. if (state == -1) {
  30212. ui.setDisabled(true);
  30213. } else {
  30214. ui.setDisabled(false);
  30215. var value = editor.queryCommandValue(cmd);
  30216. ui.setValue(value);
  30217. ui.setChecked(state);
  30218. }
  30219. });
  30220. return ui;
  30221. };
  30222. })(cl);
  30223. }
  30224. editorui.fullscreen = function(editor, title) {
  30225. title =
  30226. editor.options.labelMap["fullscreen"] ||
  30227. editor.getLang("labelMap.fullscreen") ||
  30228. "";
  30229. var ui = new editorui.Button({
  30230. className: "edui-for-fullscreen",
  30231. title: title,
  30232. theme: editor.options.theme,
  30233. onclick: function() {
  30234. if (editor.ui) {
  30235. editor.ui.setFullScreen(!editor.ui.isFullScreen());
  30236. }
  30237. this.setChecked(editor.ui.isFullScreen());
  30238. }
  30239. });
  30240. editorui.buttons["fullscreen"] = ui;
  30241. editor.addListener("selectionchange", function() {
  30242. var state = editor.queryCommandState("fullscreen");
  30243. ui.setDisabled(state == -1);
  30244. ui.setChecked(editor.ui.isFullScreen());
  30245. });
  30246. return ui;
  30247. };
  30248. // 表情
  30249. editorui["emotion"] = function(editor, iframeUrl) {
  30250. var cmd = "emotion";
  30251. var ui = new editorui.MultiMenuPop({
  30252. title:
  30253. editor.options.labelMap[cmd] ||
  30254. editor.getLang("labelMap." + cmd + "") ||
  30255. "",
  30256. editor: editor,
  30257. className: "edui-for-" + cmd,
  30258. iframeUrl: editor.ui.mapUrl(
  30259. iframeUrl ||
  30260. (editor.options.iframeUrlMap || {})[cmd] ||
  30261. iframeUrlMap[cmd]
  30262. )
  30263. });
  30264. editorui.buttons[cmd] = ui;
  30265. editor.addListener("selectionchange", function() {
  30266. ui.setDisabled(editor.queryCommandState(cmd) == -1);
  30267. });
  30268. return ui;
  30269. };
  30270. editorui.autotypeset = function(editor) {
  30271. var ui = new editorui.AutoTypeSetButton({
  30272. editor: editor,
  30273. title:
  30274. editor.options.labelMap["autotypeset"] ||
  30275. editor.getLang("labelMap.autotypeset") ||
  30276. "",
  30277. className: "edui-for-autotypeset",
  30278. onbuttonclick: function() {
  30279. editor.execCommand("autotypeset");
  30280. }
  30281. });
  30282. editorui.buttons["autotypeset"] = ui;
  30283. editor.addListener("selectionchange", function() {
  30284. ui.setDisabled(editor.queryCommandState("autotypeset") == -1);
  30285. });
  30286. return ui;
  30287. };
  30288. /* 简单上传插件 */
  30289. editorui["simpleupload"] = function(editor) {
  30290. var name = "simpleupload",
  30291. ui = new editorui.Button({
  30292. className: "edui-for-" + name,
  30293. title:
  30294. editor.options.labelMap[name] ||
  30295. editor.getLang("labelMap." + name) ||
  30296. "",
  30297. onclick: function() {},
  30298. theme: editor.options.theme,
  30299. showText: false
  30300. });
  30301. editorui.buttons[name] = ui;
  30302. editor.addListener("ready", function() {
  30303. var b = ui.getDom("body"),
  30304. iconSpan = b.children[0];
  30305. editor.fireEvent("simpleuploadbtnready", iconSpan);
  30306. });
  30307. editor.addListener("selectionchange", function(type, causeByUi, uiReady) {
  30308. var state = editor.queryCommandState(name);
  30309. if (state == -1) {
  30310. ui.setDisabled(true);
  30311. ui.setChecked(false);
  30312. } else {
  30313. if (!uiReady) {
  30314. ui.setDisabled(false);
  30315. ui.setChecked(state);
  30316. }
  30317. }
  30318. });
  30319. return ui;
  30320. };
  30321. })();
  30322. // adapter/editor.js
  30323. ///import core
  30324. ///commands 全屏
  30325. ///commandsName FullScreen
  30326. ///commandsTitle 全屏
  30327. ;(function() {
  30328. var utils = baidu.editor.utils,
  30329. uiUtils = baidu.editor.ui.uiUtils,
  30330. UIBase = baidu.editor.ui.UIBase,
  30331. domUtils = baidu.editor.dom.domUtils;
  30332. var nodeStack = [];
  30333. function EditorUI(options) {
  30334. this.initOptions(options);
  30335. this.initEditorUI();
  30336. }
  30337. EditorUI.prototype = {
  30338. uiName: "editor",
  30339. initEditorUI: function() {
  30340. this.editor.ui = this;
  30341. this._dialogs = {};
  30342. this.initUIBase();
  30343. this._initToolbars();
  30344. var editor = this.editor,
  30345. me = this;
  30346. editor.addListener("ready", function() {
  30347. //提供getDialog方法
  30348. editor.getDialog = function(name) {
  30349. return editor.ui._dialogs[name + "Dialog"];
  30350. };
  30351. domUtils.on(editor.window, "scroll", function(evt) {
  30352. baidu.editor.ui.Popup.postHide(evt);
  30353. });
  30354. //提供编辑器实时宽高(全屏时宽高不变化)
  30355. editor.ui._actualFrameWidth = editor.options.initialFrameWidth;
  30356. UE.browser.ie &&
  30357. UE.browser.version === 6 &&
  30358. editor.container.ownerDocument.execCommand(
  30359. "BackgroundImageCache",
  30360. false,
  30361. true
  30362. );
  30363. //display bottom-bar label based on config
  30364. if (editor.options.elementPathEnabled) {
  30365. editor.ui.getDom("elementpath").innerHTML =
  30366. '<div class="edui-editor-breadcrumb">' +
  30367. editor.getLang("elementPathTip") +
  30368. ":</div>";
  30369. }
  30370. if (editor.options.wordCount) {
  30371. function countFn() {
  30372. setCount(editor, me);
  30373. domUtils.un(editor.document, "click", arguments.callee);
  30374. }
  30375. domUtils.on(editor.document, "click", countFn);
  30376. editor.ui.getDom("wordcount").innerHTML = editor.getLang(
  30377. "wordCountTip"
  30378. );
  30379. }
  30380. editor.ui._scale();
  30381. if (editor.options.scaleEnabled) {
  30382. if (editor.autoHeightEnabled) {
  30383. editor.disableAutoHeight();
  30384. }
  30385. me.enableScale();
  30386. } else {
  30387. me.disableScale();
  30388. }
  30389. if (
  30390. !editor.options.elementPathEnabled &&
  30391. !editor.options.wordCount &&
  30392. !editor.options.scaleEnabled
  30393. ) {
  30394. editor.ui.getDom("elementpath").style.display = "none";
  30395. editor.ui.getDom("wordcount").style.display = "none";
  30396. editor.ui.getDom("scale").style.display = "none";
  30397. }
  30398. if (!editor.selection.isFocus()) return;
  30399. editor.fireEvent("selectionchange", false, true);
  30400. });
  30401. editor.addListener("mousedown", function(t, evt) {
  30402. var el = evt.target || evt.srcElement;
  30403. baidu.editor.ui.Popup.postHide(evt, el);
  30404. baidu.editor.ui.ShortCutMenu.postHide(evt);
  30405. });
  30406. editor.addListener("delcells", function() {
  30407. if (UE.ui["edittip"]) {
  30408. new UE.ui["edittip"](editor);
  30409. }
  30410. editor.getDialog("edittip").open();
  30411. });
  30412. var pastePop,
  30413. isPaste = false,
  30414. timer;
  30415. editor.addListener("afterpaste", function() {
  30416. if (editor.queryCommandState("pasteplain")) return;
  30417. if (baidu.editor.ui.PastePicker) {
  30418. pastePop = new baidu.editor.ui.Popup({
  30419. content: new baidu.editor.ui.PastePicker({ editor: editor }),
  30420. editor: editor,
  30421. className: "edui-wordpastepop"
  30422. });
  30423. pastePop.render();
  30424. }
  30425. isPaste = true;
  30426. });
  30427. editor.addListener("afterinserthtml", function() {
  30428. clearTimeout(timer);
  30429. timer = setTimeout(function() {
  30430. if (pastePop && (isPaste || editor.ui._isTransfer)) {
  30431. if (pastePop.isHidden()) {
  30432. var span = domUtils.createElement(editor.document, "span", {
  30433. style: "line-height:0px;",
  30434. innerHTML: "\ufeff"
  30435. }),
  30436. range = editor.selection.getRange();
  30437. range.insertNode(span);
  30438. var tmp = getDomNode(span, "firstChild", "previousSibling");
  30439. tmp &&
  30440. pastePop.showAnchor(tmp.nodeType == 3 ? tmp.parentNode : tmp);
  30441. domUtils.remove(span);
  30442. } else {
  30443. pastePop.show();
  30444. }
  30445. delete editor.ui._isTransfer;
  30446. isPaste = false;
  30447. }
  30448. }, 200);
  30449. });
  30450. editor.addListener("contextmenu", function(t, evt) {
  30451. baidu.editor.ui.Popup.postHide(evt);
  30452. });
  30453. editor.addListener("keydown", function(t, evt) {
  30454. if (pastePop) pastePop.dispose(evt);
  30455. var keyCode = evt.keyCode || evt.which;
  30456. if (evt.altKey && keyCode == 90) {
  30457. UE.ui.buttons["fullscreen"].onclick();
  30458. }
  30459. });
  30460. editor.addListener("wordcount", function(type) {
  30461. setCount(this, me);
  30462. });
  30463. function setCount(editor, ui) {
  30464. editor.setOpt({
  30465. wordCount: true,
  30466. maximumWords: 10000,
  30467. wordCountMsg:
  30468. editor.options.wordCountMsg || editor.getLang("wordCountMsg"),
  30469. wordOverFlowMsg:
  30470. editor.options.wordOverFlowMsg || editor.getLang("wordOverFlowMsg")
  30471. });
  30472. var opt = editor.options,
  30473. max = opt.maximumWords,
  30474. msg = opt.wordCountMsg,
  30475. errMsg = opt.wordOverFlowMsg,
  30476. countDom = ui.getDom("wordcount");
  30477. if (!opt.wordCount) {
  30478. return;
  30479. }
  30480. var count = editor.getContentLength(true);
  30481. if (count > max) {
  30482. countDom.innerHTML = errMsg;
  30483. editor.fireEvent("wordcountoverflow");
  30484. } else {
  30485. countDom.innerHTML = msg
  30486. .replace("{#leave}", max - count)
  30487. .replace("{#count}", count);
  30488. }
  30489. }
  30490. editor.addListener("selectionchange", function() {
  30491. if (editor.options.elementPathEnabled) {
  30492. me[
  30493. (editor.queryCommandState("elementpath") == -1 ? "dis" : "en") +
  30494. "ableElementPath"
  30495. ]();
  30496. }
  30497. if (editor.options.scaleEnabled) {
  30498. me[
  30499. (editor.queryCommandState("scale") == -1 ? "dis" : "en") +
  30500. "ableScale"
  30501. ]();
  30502. }
  30503. });
  30504. var popup = new baidu.editor.ui.Popup({
  30505. editor: editor,
  30506. content: "",
  30507. className: "edui-bubble",
  30508. _onEditButtonClick: function() {
  30509. this.hide();
  30510. editor.ui._dialogs.linkDialog.open();
  30511. },
  30512. _onImgEditButtonClick: function(name) {
  30513. this.hide();
  30514. editor.ui._dialogs[name] && editor.ui._dialogs[name].open();
  30515. },
  30516. _onImgSetFloat: function(value) {
  30517. this.hide();
  30518. editor.execCommand("imagefloat", value);
  30519. },
  30520. _setIframeAlign: function(value) {
  30521. var frame = popup.anchorEl;
  30522. var newFrame = frame.cloneNode(true);
  30523. switch (value) {
  30524. case -2:
  30525. newFrame.setAttribute("align", "");
  30526. break;
  30527. case -1:
  30528. newFrame.setAttribute("align", "left");
  30529. break;
  30530. case 1:
  30531. newFrame.setAttribute("align", "right");
  30532. break;
  30533. }
  30534. frame.parentNode.insertBefore(newFrame, frame);
  30535. domUtils.remove(frame);
  30536. popup.anchorEl = newFrame;
  30537. popup.showAnchor(popup.anchorEl);
  30538. },
  30539. _updateIframe: function() {
  30540. var frame = (editor._iframe = popup.anchorEl);
  30541. if (domUtils.hasClass(frame, "ueditor_baidumap")) {
  30542. editor.selection.getRange().selectNode(frame).select();
  30543. editor.ui._dialogs.mapDialog.open();
  30544. popup.hide();
  30545. } else {
  30546. editor.ui._dialogs.insertframeDialog.open();
  30547. popup.hide();
  30548. }
  30549. },
  30550. _onRemoveButtonClick: function(cmdName) {
  30551. editor.execCommand(cmdName);
  30552. this.hide();
  30553. },
  30554. queryAutoHide: function(el) {
  30555. if (el && el.ownerDocument == editor.document) {
  30556. if (
  30557. el.tagName.toLowerCase() == "img" ||
  30558. domUtils.findParentByTagName(el, "a", true)
  30559. ) {
  30560. return el !== popup.anchorEl;
  30561. }
  30562. }
  30563. return baidu.editor.ui.Popup.prototype.queryAutoHide.call(this, el);
  30564. }
  30565. });
  30566. popup.render();
  30567. if (editor.options.imagePopup) {
  30568. editor.addListener("mouseover", function(t, evt) {
  30569. evt = evt || window.event;
  30570. var el = evt.target || evt.srcElement;
  30571. if (
  30572. editor.ui._dialogs.insertframeDialog &&
  30573. /iframe/gi.test(el.tagName)
  30574. ) {
  30575. var html = popup.formatHtml(
  30576. "<nobr>" +
  30577. editor.getLang("property") +
  30578. ': <span onclick=$$._setIframeAlign(-2) class="edui-clickable">' +
  30579. editor.getLang("default") +
  30580. '</span>&nbsp;&nbsp;<span onclick=$$._setIframeAlign(-1) class="edui-clickable">' +
  30581. editor.getLang("justifyleft") +
  30582. '</span>&nbsp;&nbsp;<span onclick=$$._setIframeAlign(1) class="edui-clickable">' +
  30583. editor.getLang("justifyright") +
  30584. "</span>&nbsp;&nbsp;" +
  30585. ' <span onclick="$$._updateIframe( this);" class="edui-clickable">' +
  30586. editor.getLang("modify") +
  30587. "</span></nobr>"
  30588. );
  30589. if (html) {
  30590. popup.getDom("content").innerHTML = html;
  30591. popup.anchorEl = el;
  30592. popup.showAnchor(popup.anchorEl);
  30593. } else {
  30594. popup.hide();
  30595. }
  30596. }
  30597. });
  30598. editor.addListener("selectionchange", function(t, causeByUi) {
  30599. if (!causeByUi) return;
  30600. var html = "",
  30601. str = "",
  30602. img = editor.selection.getRange().getClosedNode(),
  30603. dialogs = editor.ui._dialogs;
  30604. if (img && img.tagName == "IMG") {
  30605. var dialogName = "insertimageDialog";
  30606. if (
  30607. img.className.indexOf("edui-faked-video") != -1 ||
  30608. img.className.indexOf("edui-upload-video") != -1
  30609. ) {
  30610. dialogName = "insertvideoDialog";
  30611. }
  30612. if (img.className.indexOf("edui-faked-webapp") != -1) {
  30613. dialogName = "webappDialog";
  30614. }
  30615. if (img.src.indexOf("https://api.map.baidu.com") != -1) {
  30616. dialogName = "mapDialog";
  30617. }
  30618. if (img.className.indexOf("edui-faked-music") != -1) {
  30619. dialogName = "musicDialog";
  30620. }
  30621. if (
  30622. img.src.indexOf("http://maps.google.com/maps/api/staticmap") != -1
  30623. ) {
  30624. dialogName = "gmapDialog";
  30625. }
  30626. if (img.getAttribute("anchorname")) {
  30627. dialogName = "anchorDialog";
  30628. html = popup.formatHtml(
  30629. "<nobr>" +
  30630. editor.getLang("property") +
  30631. ': <span onclick=$$._onImgEditButtonClick("anchorDialog") class="edui-clickable">' +
  30632. editor.getLang("modify") +
  30633. "</span>&nbsp;&nbsp;" +
  30634. "<span onclick=$$._onRemoveButtonClick('anchor') class=\"edui-clickable\">" +
  30635. editor.getLang("delete") +
  30636. "</span></nobr>"
  30637. );
  30638. }
  30639. if (img.getAttribute("word_img")) {
  30640. //todo 放到dialog去做查询
  30641. editor.word_img = [img.getAttribute("word_img")];
  30642. dialogName = "wordimageDialog";
  30643. }
  30644. if (
  30645. domUtils.hasClass(img, "loadingclass") ||
  30646. domUtils.hasClass(img, "loaderrorclass")
  30647. ) {
  30648. dialogName = "";
  30649. }
  30650. if (!dialogs[dialogName]) {
  30651. return;
  30652. }
  30653. str =
  30654. "<nobr>" +
  30655. editor.getLang("property") +
  30656. ": " +
  30657. '<span onclick=$$._onImgSetFloat("none") class="edui-clickable">' +
  30658. editor.getLang("default") +
  30659. "</span>&nbsp;&nbsp;" +
  30660. '<span onclick=$$._onImgSetFloat("left") class="edui-clickable">' +
  30661. editor.getLang("justifyleft") +
  30662. "</span>&nbsp;&nbsp;" +
  30663. '<span onclick=$$._onImgSetFloat("right") class="edui-clickable">' +
  30664. editor.getLang("justifyright") +
  30665. "</span>&nbsp;&nbsp;" +
  30666. '<span onclick=$$._onImgSetFloat("center") class="edui-clickable">' +
  30667. editor.getLang("justifycenter") +
  30668. "</span>&nbsp;&nbsp;" +
  30669. "<span onclick=\"$$._onImgEditButtonClick('" +
  30670. dialogName +
  30671. '\');" class="edui-clickable">' +
  30672. editor.getLang("modify") +
  30673. "</span></nobr>";
  30674. !html && (html = popup.formatHtml(str));
  30675. }
  30676. if (editor.ui._dialogs.linkDialog) {
  30677. var link = editor.queryCommandValue("link");
  30678. var url;
  30679. if (
  30680. link &&
  30681. (url = link.getAttribute("_href") || link.getAttribute("href", 2))
  30682. ) {
  30683. var txt = url;
  30684. if (url.length > 30) {
  30685. txt = url.substring(0, 20) + "...";
  30686. }
  30687. if (html) {
  30688. html += '<div style="height:5px;"></div>';
  30689. }
  30690. html += popup.formatHtml(
  30691. "<nobr>" +
  30692. editor.getLang("anthorMsg") +
  30693. ': <a target="_blank" href="' +
  30694. url +
  30695. '" title="' +
  30696. url +
  30697. '" >' +
  30698. txt +
  30699. "</a>" +
  30700. ' <span class="edui-clickable" onclick="$$._onEditButtonClick();">' +
  30701. editor.getLang("modify") +
  30702. "</span>" +
  30703. ' <span class="edui-clickable" onclick="$$._onRemoveButtonClick(\'unlink\');"> ' +
  30704. editor.getLang("clear") +
  30705. "</span></nobr>"
  30706. );
  30707. popup.showAnchor(link);
  30708. }
  30709. }
  30710. if (html) {
  30711. popup.getDom("content").innerHTML = html;
  30712. popup.anchorEl = img || link;
  30713. popup.showAnchor(popup.anchorEl);
  30714. } else {
  30715. popup.hide();
  30716. }
  30717. });
  30718. }
  30719. },
  30720. _initToolbars: function() {
  30721. var editor = this.editor;
  30722. var toolbars = this.toolbars || [];
  30723. var toolbarUis = [];
  30724. var extraUIs = [];
  30725. for (var i = 0; i < toolbars.length; i++) {
  30726. var toolbar = toolbars[i];
  30727. var toolbarUi = new baidu.editor.ui.Toolbar({
  30728. theme: editor.options.theme
  30729. });
  30730. for (var j = 0; j < toolbar.length; j++) {
  30731. var toolbarItem = toolbar[j];
  30732. var toolbarItemUi = null;
  30733. if (typeof toolbarItem == "string") {
  30734. toolbarItem = toolbarItem.toLowerCase();
  30735. if (toolbarItem == "|") {
  30736. toolbarItem = "Separator";
  30737. }
  30738. if (toolbarItem == "||") {
  30739. toolbarItem = "Breakline";
  30740. }
  30741. var ui = baidu.editor.ui[toolbarItem];
  30742. if (ui) {
  30743. if (utils.isFunction(ui)) {
  30744. toolbarItemUi = new baidu.editor.ui[toolbarItem](editor);
  30745. } else {
  30746. if (ui.id && ui.id != editor.key) {
  30747. continue;
  30748. }
  30749. var itemUI = ui.execFn.call(editor, editor, toolbarItem);
  30750. if (itemUI) {
  30751. if (ui.index === undefined) {
  30752. toolbarUi.add(itemUI);
  30753. continue;
  30754. } else {
  30755. extraUIs.push({
  30756. index: ui.index,
  30757. itemUI: itemUI
  30758. });
  30759. }
  30760. }
  30761. }
  30762. }
  30763. //fullscreen这里单独处理一下,放到首行去
  30764. if (toolbarItem == "fullscreen") {
  30765. if (toolbarUis && toolbarUis[0]) {
  30766. toolbarUis[0].items.splice(0, 0, toolbarItemUi);
  30767. } else {
  30768. toolbarItemUi && toolbarUi.items.splice(0, 0, toolbarItemUi);
  30769. }
  30770. continue;
  30771. }
  30772. } else {
  30773. toolbarItemUi = toolbarItem;
  30774. }
  30775. if (toolbarItemUi && toolbarItemUi.id) {
  30776. toolbarUi.add(toolbarItemUi);
  30777. }
  30778. }
  30779. toolbarUis[i] = toolbarUi;
  30780. }
  30781. //接受外部定制的UI
  30782. utils.each(extraUIs, function(obj) {
  30783. toolbarUi.add(obj.itemUI, obj.index);
  30784. });
  30785. this.toolbars = toolbarUis;
  30786. },
  30787. getHtmlTpl: function() {
  30788. return (
  30789. '<div id="##" class="%%">' +
  30790. '<div id="##_toolbarbox" class="%%-toolbarbox">' +
  30791. (this.toolbars.length
  30792. ? '<div id="##_toolbarboxouter" class="%%-toolbarboxouter"><div class="%%-toolbarboxinner">' +
  30793. this.renderToolbarBoxHtml() +
  30794. "</div></div>"
  30795. : "") +
  30796. '<div id="##_toolbarmsg" class="%%-toolbarmsg" style="display:none;">' +
  30797. '<div id = "##_upload_dialog" class="%%-toolbarmsg-upload" onclick="$$.showWordImageDialog();">' +
  30798. this.editor.getLang("clickToUpload") +
  30799. "</div>" +
  30800. '<div class="%%-toolbarmsg-close" onclick="$$.hideToolbarMsg();">x</div>' +
  30801. '<div id="##_toolbarmsg_label" class="%%-toolbarmsg-label"></div>' +
  30802. '<div style="height:0;overflow:hidden;clear:both;"></div>' +
  30803. "</div>" +
  30804. '<div id="##_message_holder" class="%%-messageholder"></div>' +
  30805. "</div>" +
  30806. '<div id="##_iframeholder" class="%%-iframeholder">' +
  30807. "</div>" +
  30808. //modify wdcount by matao
  30809. '<div id="##_bottombar" class="%%-bottomContainer"><table><tr>' +
  30810. '<td id="##_elementpath" class="%%-bottombar"></td>' +
  30811. '<td id="##_wordcount" class="%%-wordcount"></td>' +
  30812. '<td id="##_scale" class="%%-scale"><div class="%%-icon"></div></td>' +
  30813. "</tr></table></div>" +
  30814. '<div id="##_scalelayer"></div>' +
  30815. "</div>"
  30816. );
  30817. },
  30818. showWordImageDialog: function() {
  30819. this._dialogs["wordimageDialog"].open();
  30820. },
  30821. renderToolbarBoxHtml: function() {
  30822. var buff = [];
  30823. for (var i = 0; i < this.toolbars.length; i++) {
  30824. buff.push(this.toolbars[i].renderHtml());
  30825. }
  30826. return buff.join("");
  30827. },
  30828. setFullScreen: function(fullscreen) {
  30829. var editor = this.editor,
  30830. container = editor.container.parentNode.parentNode;
  30831. if (this._fullscreen != fullscreen) {
  30832. this._fullscreen = fullscreen;
  30833. this.editor.fireEvent("beforefullscreenchange", fullscreen);
  30834. if (baidu.editor.browser.gecko) {
  30835. var bk = editor.selection.getRange().createBookmark();
  30836. }
  30837. if (fullscreen) {
  30838. while (container.tagName != "BODY") {
  30839. var position = baidu.editor.dom.domUtils.getComputedStyle(
  30840. container,
  30841. "position"
  30842. );
  30843. nodeStack.push(position);
  30844. container.style.position = "static";
  30845. container = container.parentNode;
  30846. }
  30847. this._bakHtmlOverflow = document.documentElement.style.overflow;
  30848. this._bakBodyOverflow = document.body.style.overflow;
  30849. this._bakAutoHeight = this.editor.autoHeightEnabled;
  30850. this._bakScrollTop = Math.max(
  30851. document.documentElement.scrollTop,
  30852. document.body.scrollTop
  30853. );
  30854. this._bakEditorContaninerWidth = editor.iframe.parentNode.offsetWidth;
  30855. if (this._bakAutoHeight) {
  30856. //当全屏时不能执行自动长高
  30857. editor.autoHeightEnabled = false;
  30858. this.editor.disableAutoHeight();
  30859. }
  30860. document.documentElement.style.overflow = "hidden";
  30861. //修复,滚动条不收起的问题
  30862. window.scrollTo(0, window.scrollY);
  30863. this._bakCssText = this.getDom().style.cssText;
  30864. this._bakCssText1 = this.getDom("iframeholder").style.cssText;
  30865. editor.iframe.parentNode.style.width = "";
  30866. this._updateFullScreen();
  30867. } else {
  30868. while (container.tagName != "BODY") {
  30869. container.style.position = nodeStack.shift();
  30870. container = container.parentNode;
  30871. }
  30872. this.getDom().style.cssText = this._bakCssText;
  30873. this.getDom("iframeholder").style.cssText = this._bakCssText1;
  30874. if (this._bakAutoHeight) {
  30875. editor.autoHeightEnabled = true;
  30876. this.editor.enableAutoHeight();
  30877. }
  30878. document.documentElement.style.overflow = this._bakHtmlOverflow;
  30879. document.body.style.overflow = this._bakBodyOverflow;
  30880. editor.iframe.parentNode.style.width =
  30881. this._bakEditorContaninerWidth + "px";
  30882. window.scrollTo(0, this._bakScrollTop);
  30883. }
  30884. if (browser.gecko && editor.body.contentEditable === "true") {
  30885. var input = document.createElement("input");
  30886. document.body.appendChild(input);
  30887. editor.body.contentEditable = false;
  30888. setTimeout(function() {
  30889. input.focus();
  30890. setTimeout(function() {
  30891. editor.body.contentEditable = true;
  30892. editor.fireEvent("fullscreenchanged", fullscreen);
  30893. editor.selection.getRange().moveToBookmark(bk).select(true);
  30894. baidu.editor.dom.domUtils.remove(input);
  30895. fullscreen && window.scroll(0, 0);
  30896. }, 0);
  30897. }, 0);
  30898. }
  30899. if (editor.body.contentEditable === "true") {
  30900. this.editor.fireEvent("fullscreenchanged", fullscreen);
  30901. this.triggerLayout();
  30902. }
  30903. }
  30904. },
  30905. _updateFullScreen: function() {
  30906. if (this._fullscreen) {
  30907. var vpRect = uiUtils.getViewportRect();
  30908. this.getDom().style.cssText =
  30909. "border:0;position:absolute;left:0;top:" +
  30910. (this.editor.options.topOffset || 0) +
  30911. "px;width:" +
  30912. vpRect.width +
  30913. "px;height:" +
  30914. vpRect.height +
  30915. "px;z-index:" +
  30916. (this.getDom().style.zIndex * 1 + 100);
  30917. uiUtils.setViewportOffset(this.getDom(), {
  30918. left: 0,
  30919. top: this.editor.options.topOffset || 0
  30920. });
  30921. this.editor.setHeight(
  30922. vpRect.height -
  30923. this.getDom("toolbarbox").offsetHeight -
  30924. this.getDom("bottombar").offsetHeight -
  30925. (this.editor.options.topOffset || 0),
  30926. true
  30927. );
  30928. //不手动调一下,会导致全屏失效
  30929. if (browser.gecko) {
  30930. try {
  30931. window.onresize();
  30932. } catch (e) {}
  30933. }
  30934. }
  30935. },
  30936. _updateElementPath: function() {
  30937. var bottom = this.getDom("elementpath"),
  30938. list;
  30939. if (
  30940. this.elementPathEnabled &&
  30941. (list = this.editor.queryCommandValue("elementpath"))
  30942. ) {
  30943. var buff = [];
  30944. for (var i = 0, ci; (ci = list[i]); i++) {
  30945. buff[i] = this.formatHtml(
  30946. '<span unselectable="on" onclick="$$.editor.execCommand(&quot;elementpath&quot;, &quot;' +
  30947. i +
  30948. '&quot;);">' +
  30949. ci +
  30950. "</span>"
  30951. );
  30952. }
  30953. bottom.innerHTML =
  30954. '<div class="edui-editor-breadcrumb" onmousedown="return false;">' +
  30955. this.editor.getLang("elementPathTip") +
  30956. ": " +
  30957. buff.join(" &gt; ") +
  30958. "</div>";
  30959. } else {
  30960. bottom.style.display = "none";
  30961. }
  30962. },
  30963. disableElementPath: function() {
  30964. var bottom = this.getDom("elementpath");
  30965. bottom.innerHTML = "";
  30966. bottom.style.display = "none";
  30967. this.elementPathEnabled = false;
  30968. },
  30969. enableElementPath: function() {
  30970. var bottom = this.getDom("elementpath");
  30971. bottom.style.display = "";
  30972. this.elementPathEnabled = true;
  30973. this._updateElementPath();
  30974. },
  30975. _scale: function() {
  30976. var doc = document,
  30977. editor = this.editor,
  30978. editorHolder = editor.container,
  30979. editorDocument = editor.document,
  30980. toolbarBox = this.getDom("toolbarbox"),
  30981. bottombar = this.getDom("bottombar"),
  30982. scale = this.getDom("scale"),
  30983. scalelayer = this.getDom("scalelayer");
  30984. var isMouseMove = false,
  30985. position = null,
  30986. minEditorHeight = 0,
  30987. minEditorWidth = editor.options.minFrameWidth,
  30988. pageX = 0,
  30989. pageY = 0,
  30990. scaleWidth = 0,
  30991. scaleHeight = 0;
  30992. function down() {
  30993. position = domUtils.getXY(editorHolder);
  30994. if (!minEditorHeight) {
  30995. minEditorHeight =
  30996. editor.options.minFrameHeight +
  30997. toolbarBox.offsetHeight +
  30998. bottombar.offsetHeight;
  30999. }
  31000. scalelayer.style.cssText =
  31001. "position:absolute;left:0;display:;top:0;background-color:#41ABFF;opacity:0.4;filter: Alpha(opacity=40);width:" +
  31002. editorHolder.offsetWidth +
  31003. "px;height:" +
  31004. editorHolder.offsetHeight +
  31005. "px;z-index:" +
  31006. (editor.options.zIndex + 1);
  31007. domUtils.on(doc, "mousemove", move);
  31008. domUtils.on(editorDocument, "mouseup", up);
  31009. domUtils.on(doc, "mouseup", up);
  31010. }
  31011. var me = this;
  31012. //by xuheng 全屏时关掉缩放
  31013. this.editor.addListener("fullscreenchanged", function(e, fullScreen) {
  31014. if (fullScreen) {
  31015. me.disableScale();
  31016. } else {
  31017. if (me.editor.options.scaleEnabled) {
  31018. me.enableScale();
  31019. var tmpNode = me.editor.document.createElement("span");
  31020. me.editor.body.appendChild(tmpNode);
  31021. me.editor.body.style.height =
  31022. Math.max(
  31023. domUtils.getXY(tmpNode).y,
  31024. me.editor.iframe.offsetHeight - 20
  31025. ) + "px";
  31026. domUtils.remove(tmpNode);
  31027. }
  31028. }
  31029. });
  31030. function move(event) {
  31031. clearSelection();
  31032. var e = event || window.event;
  31033. pageX = e.pageX || doc.documentElement.scrollLeft + e.clientX;
  31034. pageY = e.pageY || doc.documentElement.scrollTop + e.clientY;
  31035. scaleWidth = pageX - position.x;
  31036. scaleHeight = pageY - position.y;
  31037. if (scaleWidth >= minEditorWidth) {
  31038. isMouseMove = true;
  31039. scalelayer.style.width = scaleWidth + "px";
  31040. }
  31041. if (scaleHeight >= minEditorHeight) {
  31042. isMouseMove = true;
  31043. scalelayer.style.height = scaleHeight + "px";
  31044. }
  31045. }
  31046. function up() {
  31047. if (isMouseMove) {
  31048. isMouseMove = false;
  31049. editor.ui._actualFrameWidth = scalelayer.offsetWidth - 2;
  31050. editorHolder.style.width = editor.ui._actualFrameWidth + "px";
  31051. editor.setHeight(
  31052. scalelayer.offsetHeight -
  31053. bottombar.offsetHeight -
  31054. toolbarBox.offsetHeight -
  31055. 2,
  31056. true
  31057. );
  31058. }
  31059. if (scalelayer) {
  31060. scalelayer.style.display = "none";
  31061. }
  31062. clearSelection();
  31063. domUtils.un(doc, "mousemove", move);
  31064. domUtils.un(editorDocument, "mouseup", up);
  31065. domUtils.un(doc, "mouseup", up);
  31066. }
  31067. function clearSelection() {
  31068. if (browser.ie) doc.selection.clear();
  31069. else window.getSelection().removeAllRanges();
  31070. }
  31071. this.enableScale = function() {
  31072. //trace:2868
  31073. if (editor.queryCommandState("source") == 1) return;
  31074. scale.style.display = "";
  31075. this.scaleEnabled = true;
  31076. domUtils.on(scale, "mousedown", down);
  31077. };
  31078. this.disableScale = function() {
  31079. scale.style.display = "none";
  31080. this.scaleEnabled = false;
  31081. domUtils.un(scale, "mousedown", down);
  31082. };
  31083. },
  31084. isFullScreen: function() {
  31085. return this._fullscreen;
  31086. },
  31087. postRender: function() {
  31088. UIBase.prototype.postRender.call(this);
  31089. for (var i = 0; i < this.toolbars.length; i++) {
  31090. this.toolbars[i].postRender();
  31091. }
  31092. var me = this;
  31093. var timerId,
  31094. domUtils = baidu.editor.dom.domUtils,
  31095. updateFullScreenTime = function() {
  31096. clearTimeout(timerId);
  31097. timerId = setTimeout(function() {
  31098. me._updateFullScreen();
  31099. });
  31100. };
  31101. domUtils.on(window, "resize", updateFullScreenTime);
  31102. me.addListener("destroy", function() {
  31103. domUtils.un(window, "resize", updateFullScreenTime);
  31104. clearTimeout(timerId);
  31105. });
  31106. },
  31107. showToolbarMsg: function(msg, flag) {
  31108. this.getDom("toolbarmsg_label").innerHTML = msg;
  31109. this.getDom("toolbarmsg").style.display = "";
  31110. //
  31111. if (!flag) {
  31112. var w = this.getDom("upload_dialog");
  31113. w.style.display = "none";
  31114. }
  31115. },
  31116. hideToolbarMsg: function() {
  31117. this.getDom("toolbarmsg").style.display = "none";
  31118. },
  31119. mapUrl: function(url) {
  31120. return url
  31121. ? url.replace("~/", this.editor.options.UEDITOR_HOME_URL || "")
  31122. : "";
  31123. },
  31124. triggerLayout: function() {
  31125. var dom = this.getDom();
  31126. if (dom.style.zoom == "1") {
  31127. dom.style.zoom = "100%";
  31128. } else {
  31129. dom.style.zoom = "1";
  31130. }
  31131. }
  31132. };
  31133. utils.inherits(EditorUI, baidu.editor.ui.UIBase);
  31134. var instances = {};
  31135. UE.ui.Editor = function(options) {
  31136. var editor = new UE.Editor(options);
  31137. editor.options.editor = editor;
  31138. utils.loadFile(document, {
  31139. href:
  31140. editor.options.themePath + editor.options.theme + "/css/neditor.css",
  31141. tag: "link",
  31142. type: "text/css",
  31143. rel: "stylesheet"
  31144. });
  31145. var oldRender = editor.render;
  31146. editor.render = function(holder) {
  31147. if (holder.constructor === String) {
  31148. editor.key = holder;
  31149. instances[holder] = editor;
  31150. }
  31151. utils.domReady(function() {
  31152. editor.langIsReady
  31153. ? renderUI()
  31154. : editor.addListener("langReady", renderUI);
  31155. function renderUI() {
  31156. editor.setOpt({
  31157. labelMap: editor.options.labelMap || editor.getLang("labelMap")
  31158. });
  31159. new EditorUI(editor.options);
  31160. if (holder) {
  31161. if (holder.constructor === String) {
  31162. holder = document.getElementById(holder);
  31163. }
  31164. holder &&
  31165. holder.getAttribute("name") &&
  31166. (editor.options.textarea = holder.getAttribute("name"));
  31167. if (holder && /script|textarea/gi.test(holder.tagName)) {
  31168. var newDiv = document.createElement("div");
  31169. holder.parentNode.insertBefore(newDiv, holder);
  31170. var cont = holder.value || holder.innerHTML;
  31171. editor.options.initialContent = /^[\t\r\n ]*$/.test(cont)
  31172. ? editor.options.initialContent
  31173. : cont
  31174. .replace(/>[\n\r\t]+([ ]{4})+/g, ">")
  31175. .replace(/[\n\r\t]+([ ]{4})+</g, "<")
  31176. .replace(/>[\n\r\t]+</g, "><");
  31177. holder.className && (newDiv.className = holder.className);
  31178. holder.style.cssText &&
  31179. (newDiv.style.cssText = holder.style.cssText);
  31180. if (/textarea/i.test(holder.tagName)) {
  31181. editor.textarea = holder;
  31182. editor.textarea.style.display = "none";
  31183. } else {
  31184. holder.parentNode.removeChild(holder);
  31185. }
  31186. if (holder.id) {
  31187. newDiv.id = holder.id;
  31188. domUtils.removeAttributes(holder, "id");
  31189. }
  31190. holder = newDiv;
  31191. holder.innerHTML = "";
  31192. }
  31193. }
  31194. domUtils.addClass(holder, "edui-" + editor.options.theme);
  31195. editor.ui.render(holder);
  31196. var opt = editor.options;
  31197. //给实例添加一个编辑器的容器引用
  31198. editor.container = editor.ui.getDom();
  31199. var parents = domUtils.findParents(holder, true);
  31200. var displays = [];
  31201. for (var i = 0, ci; (ci = parents[i]); i++) {
  31202. displays[i] = ci.style.display;
  31203. ci.style.display = "block";
  31204. }
  31205. if (opt.initialFrameWidth) {
  31206. opt.minFrameWidth = opt.initialFrameWidth;
  31207. } else {
  31208. opt.minFrameWidth = opt.initialFrameWidth = holder.offsetWidth;
  31209. var styleWidth = holder.style.width;
  31210. if (/%$/.test(styleWidth)) {
  31211. opt.initialFrameWidth = styleWidth;
  31212. }
  31213. }
  31214. if (opt.initialFrameHeight) {
  31215. opt.minFrameHeight = opt.initialFrameHeight;
  31216. } else {
  31217. opt.initialFrameHeight = opt.minFrameHeight = holder.offsetHeight;
  31218. }
  31219. for (var i = 0, ci; (ci = parents[i]); i++) {
  31220. ci.style.display = displays[i];
  31221. }
  31222. //编辑器最外容器设置了高度,会导致,编辑器不占位
  31223. //todo 先去掉,没有找到原因
  31224. if (holder.style.height) {
  31225. holder.style.height = "";
  31226. }
  31227. editor.container.style.width =
  31228. opt.initialFrameWidth +
  31229. (/%$/.test(opt.initialFrameWidth) ? "" : "px");
  31230. editor.container.style.zIndex = opt.zIndex;
  31231. oldRender.call(editor, editor.ui.getDom("iframeholder"));
  31232. editor.fireEvent("afteruiready");
  31233. }
  31234. });
  31235. };
  31236. return editor;
  31237. };
  31238. /**
  31239. * @file
  31240. * @name UE
  31241. * @short UE
  31242. * @desc UEditor的顶部命名空间
  31243. */
  31244. /**
  31245. * @name getEditor
  31246. * @since 1.2.4+
  31247. * @grammar UE.getEditor(id,[opt]) => Editor实例
  31248. * @desc 提供一个全局的方法得到编辑器实例
  31249. *
  31250. * * ''id'' 放置编辑器的容器id, 如果容器下的编辑器已经存在,就直接返回
  31251. * * ''opt'' 编辑器的可选参数
  31252. * @example
  31253. * UE.getEditor('containerId',{onready:function(){//创建一个编辑器实例
  31254. * this.setContent('hello')
  31255. * }});
  31256. * UE.getEditor('containerId'); //返回刚创建的实例
  31257. *
  31258. */
  31259. UE.getEditor = function(id, opt) {
  31260. var editor = instances[id];
  31261. if (!editor) {
  31262. editor = instances[id] = new UE.ui.Editor(opt);
  31263. editor.render(id);
  31264. }
  31265. return editor;
  31266. };
  31267. UE.delEditor = function(id) {
  31268. var editor;
  31269. if ((editor = instances[id])) {
  31270. editor.key && editor.destroy();
  31271. delete instances[id];
  31272. }
  31273. };
  31274. UE.registerUI = function(uiName, fn, index, editorId) {
  31275. utils.each(uiName.split(/\s+/), function(name) {
  31276. baidu.editor.ui[name] = {
  31277. id: editorId,
  31278. execFn: fn,
  31279. index: index
  31280. };
  31281. });
  31282. };
  31283. })();
  31284. // adapter/message.js
  31285. UE.registerUI("message", function(editor) {
  31286. var editorui = baidu.editor.ui;
  31287. var Message = editorui.Message;
  31288. var holder;
  31289. var _messageItems = [];
  31290. var me = editor;
  31291. me.setOpt("enableMessageShow", true);
  31292. if (me.getOpt("enableMessageShow") === false) {
  31293. return;
  31294. }
  31295. me.addListener("ready", function() {
  31296. holder = document.getElementById(me.ui.id + "_message_holder");
  31297. updateHolderPos();
  31298. setTimeout(function() {
  31299. updateHolderPos();
  31300. }, 500);
  31301. });
  31302. me.addListener("showmessage", function(type, opt) {
  31303. opt = utils.isString(opt)
  31304. ? {
  31305. content: opt
  31306. }
  31307. : opt;
  31308. var message = new Message({
  31309. timeout: opt.timeout,
  31310. type: opt.type,
  31311. content: opt.content,
  31312. keepshow: opt.keepshow,
  31313. editor: me
  31314. }),
  31315. mid = opt.id || "msg_" + (+new Date()).toString(36);
  31316. message.render(holder);
  31317. _messageItems[mid] = message;
  31318. message.reset(opt);
  31319. updateHolderPos();
  31320. return mid;
  31321. });
  31322. me.addListener("updatemessage", function(type, id, opt) {
  31323. opt = utils.isString(opt)
  31324. ? {
  31325. content: opt
  31326. }
  31327. : opt;
  31328. var message = _messageItems[id];
  31329. message.render(holder);
  31330. message && message.reset(opt);
  31331. });
  31332. me.addListener("hidemessage", function(type, id) {
  31333. var message = _messageItems[id];
  31334. message && message.hide();
  31335. });
  31336. function updateHolderPos() {
  31337. if (!holder || !me.ui) return;
  31338. var toolbarbox = me.ui.getDom("toolbarbox");
  31339. if (toolbarbox) {
  31340. holder.style.top = toolbarbox.offsetHeight + 3 + "px";
  31341. }
  31342. holder.style.zIndex =
  31343. Math.max(me.options.zIndex, me.iframe.style.zIndex) + 1;
  31344. }
  31345. });
  31346. // adapter/autosave.js
  31347. UE.registerUI("autosave", function(editor) {
  31348. var timer = null,
  31349. uid = null;
  31350. editor.on("afterautosave", function() {
  31351. clearTimeout(timer);
  31352. timer = setTimeout(function() {
  31353. if (uid) {
  31354. editor.trigger("hidemessage", uid);
  31355. }
  31356. uid = editor.trigger("showmessage", {
  31357. content: editor.getLang("autosave.success"),
  31358. timeout: 2000
  31359. });
  31360. }, 2000);
  31361. });
  31362. });
  31363. })();